目录
一、安装Anaconda
1.下载
wget https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh
2.安装
bash Anaconda3-2020.02-Linux-x86_64.sh



3.注意
安装完成后,重新进行ssh连接,会发现主机名前面多了(base)如果想取消,有以下两种方法:
- 一次性取消:
进入终端后输入conda deactivate 退出虚拟环境
- 永久取消:
- 输入vim ~/.bashrc
② 然后将下图中,除export PATH=”/root/anaconda3/bin:$PATH”一行外的其他行都加#注释掉,按Esc,输入:wq回车保存退出,再次进入终端后就不会有(base)

二 、安装jupyter notebook
1.创建环境,并进入
环境名称自拟,也可以不创建直接下载安装
conda create -n jupyter_notebook python==3.7
进入创建的环境
conda activate jupyter_notebook
2.下载
下载
conda install jupyter notebook
生成默认配置文件
jupyter notebook --generate-config
3.生成秘钥
输入ipython,进入ipython命令行
In [1]: from notebook.auth import passwd
In [2]: passwd()
设置登录密码(Enter password:)
确认密码(Verify password:)
#生成秘钥,将以下秘钥复制保存
Out[2]: 'sha1:......'
退出
In[3]:exit
4.修改配置文件
vim /root/.jupyter/jupyter_notebook_config.py
打开后将下面几项修改后复制在最后
c.NotebookApp.ip='*'
c.NotebookApp.open_browser = False
c.NotebookApp.password = 'sha1:......'
c.NotebookApp.port = xxxx
其中:
ip:设为*或0.0.0.0,允许任何ip访问
open_browser:设为禁止自动打开浏览器
password:为上一步生成的秘钥
port:自己设置一个端口,然后在阿里控制台安全组规则中添加,步骤:(左侧)实例,进入实例列表 –>(右侧)管理 –>(左侧)本实例安全组 –>(右侧)配置规则 –> 入方向添加规则,如下图,其中,优先级我这里是110,端口与c.NotebookApp.port参数设置一致,源为0.0.0.0/0,表示给所有IP开放
5.启动jupyter notebook
使用root用户启动
jupyter notebook --allow-root
6.访问
windows端浏览器输入
IP:port
IP为服务器的IP,port为前面设置的端口号
7.jupyter后台运行
如果不使用本条命令,操作上述步骤后,也能访问,但在ssh断开连接后,将停止访问!
把jupyter挂在后台运行,使用起来会非常方便
推荐使用下面这条!!!
nohup jupyter notebook --allow-root > jupyter.log 2>&1 &
nohup表示no hang up不挂起,这个命令执行后即使终端退出,,也不会停止运行。
如果报错,可以使用命令
nohup jupyter notebook --ip=0.0.0.0 -allow-root > jupyter.log 2>&1 &
8.关闭后台常驻
查看进程 (ps a)
ps -aux | grep jupyter
输出内容类似:

杀死进程(进程号在不同机器是不一样的)
kill -9 21955
此时浏览器中无法访问
9.多用户使用Jupyter
1.暂停jupyter进程,看上一步
2. 复制jupyter默认配置文件,生成:jupyter_notebook_config_222.py
cp /root/.jupyter/jupyter_notebook_config.py /root/.jupyter/jupyter_notebook_config_222.py
3.在jupyter_notebook_config_222.py里进行配置
c.NotebookApp.ip='*'
c.NotebookApp.open_browser = False
c.NotebookApp.password = 'sha1:......'
c.NotebookApp.port = xxxx
c.NotebookApp.notebook_dir = '/home/hs/ipython'
最后三条里边的参数需要和之前的文件不一样
启动服务
jupyter note book --config /root/.jupyter/jupyter_note_book_config_2222.py &
客户端在浏览器上 通过 <ip地址>:xxxx 访问
至此,该服务器就可以给多个端口、密码不同的 jupyter notebook 用户使用了
三、可能出现的错误
1.安装时报错

安装bunzip2
yum install bzip2
2.建议安装前,添加快照,以免出错难以恢复!
参考链接
2.阿里云服务器上搭建Anaconda3环境,并后台运行jupyter作为显示界面