如何在Linux服务器上构建Jupyter Notebook

@(Copyright: Steven.W)[SakuraRainS]

I use English in my writing, this is a translated version with Google Translator. Don't mind the minor error. Thanks!
我在写作中使用英语,这是Google Translator的翻译版本。如有错误,多多包涵,谢谢!

[TOC]

First, be sure you have a server and you have already installed CentOS 7.x+. Python3 is necessary for installation in my case.
首先,请确保您有一台服务器并且已经安装了CentOS 7.x +。在我的情况下,安装Python3是必需的。

安装环境

Login to your CentOS 7 VPS via SSH as a root sudo user, (Aliyun example: ssh root@ip_address), port number may not be needed:
以root用户sudo用户的身份通过SSH登录到CentOS 7 VPS(Aliyun示例:ssh root @ ip_address),可能不需要端口号:

ssh account@IP_Address (-p Port_number)

Then check that all installed packages on the server are updated to the latest version, by running the following command:
然后,通过运行以下命令来检查服务器上所有已安装的软件包是否已更新为最新版本:

sudo yum update

If needed, install bzip2 package with the following command line:
如果需要,请使用以下命令行安装bzip2软件包:

sudo yum install bzip2

Typically, you don't need this anymore since the lates version contained bzip2
通常,您不再需要此功能,因为最新版本包含bzip2
CentOS 7.x has the default python version 2.7. Please check!
CentOS 7.x具有默认的python版本2.7。请检查!

Anaconda 安装

Anaconda is recommended to install Python and Jupyter Notebook. Since it contained not only these popular software but some famous data science and machine learning packages.
建议Anaconda安装Python和Jupyter Notebook。由于它不仅包含这些流行的软件,还包含一些著名的数据科学和机器学习包。
Download the latest version of Anaconda, please check the version online https://repo.anaconda.com/archive/:
下载最新版本的Anaconda,请在线检查版本https://repo.anaconda.com/archive/:

wget https://repo.anaconda.com/archive/Anaconda3-2021.04-Linux-x86_64.sh

If you didn't ever install wget before, please use the following command line:
如果您以前从未安装过wget,请使用以下命令行:

yum -y install wget

After that, start Anaconda installation by running the script, the command line is:
之后,通过运行脚本开始Anaconda安装,命令行为:

bash Anaconda3-2021.04-Linux-x86_64.sh

You will get the information looks like:
您将获得如下信息:

Welcome to Anaconda3-2021.04

In order to continue the installation, press the " Enter" , and this process may take you a few minutes since you should scroll down or review the license agreement. Please answer "Yes" after you scroll through the license. There will show you the default Anaconda installation path, for example(My server returns):
为了继续安装,请按“ Enter”键,此过程可能需要几分钟,因为您应该向下滚动或查看许可协议。滚动浏览许可证后,请回答“是”。例如,将显示默认的Anaconda安装路径(我的服务器返回):

/root/ anaconda3

Once the Anaconda installation is complete, to active your Anaconda installation, type the following command line:
Anaconda安装完成后,要激活Anaconda安装,请键入以下命令行:

source ~/.bashrc

Check if the installation was successful, run the following command line:
检查安装是否成功,运行以下命令行:

conda --version

Jupyter Notebook安装

Be sure you have pip3 before you install the Jupyter Notebook
在安装Jupyter Notebook之前,请确保您拥有pip3

pip install Jupyter

To generate Jupyter Notebook configuration file:
生成Jupyter Notebook配置文件:

jupyter notebook --generate-config

Jupyter Notebook password setting:
Jupyter Notebook密码设置:

1   Open Ipython, command line:  打开Ipython,命令行:

ipython

2

from notebook.auth import passwd

3

passwd()

make sure you had copied a list of letters which is your password. We will modify some configuration and it will be used.
确保您已复制字母列表作为密码。我们将修改一些配置并将其使用。
Modify your configuration file by using vim text editor after you generated your password successfully:
成功生成密码后,使用vim文本编辑器修改配置文件:

vim ~/.jupyter/jupyter_notebook_config.py

Find following information and change them:
查找以下信息并进行更改:

c.NotebookApp.ip = 'server_ip' # you could try 0.0.0.0 or your ip , some times '' doesn't work
c.NotebookApp.port = 8889
c.NotebookApp.open_browser = False
c.NotebookApp.password = u'argon2:
yourcode *'
c.NotebookApp.allow_root = True

If you are root user, please make sure add "--allow-root" at the end of command line:
如果您是root用户,请确保在命令行末尾添加“ --allow-root”:

jupyter notebook --allow-root

Error may occur since you set the firewall in the serever, do following steps to address this problem. Open local terminal prompt and type in: (Check the port if it is avaliable.)
由于您在服务器中设置了防火墙,因此可能会发生错误,请执行以下步骤来解决此问题。打开本地终端提示,然后输入:(检查端口是否可用。)

Screen Shot 2021-05-12 at 00.14.45.png

ssh -N -f -L localhost:8878:localhost:8889 root@server_ip

Then you can open remotely as localhost:8878.
After fix this issue, run the command line beyond again.
然后,您可以以localhost:8878远程打开。
解决此问题后,再次运行命令行。

Screen Shot 2021-05-11 at 20.28.16.png
Screen Shot 2021-05-11 at 20.29.18.png

Please attach the link or claim the authorship, No reproduction without permission. Please indicate the source if authorized.
请附加链接或声明作者身份,未经允许不得转载。如果授权,请注明出处。
@[Copyright: Steven.W/ SakuraRainS]

你可能感兴趣的:(如何在Linux服务器上构建Jupyter Notebook)