开发生涯

linux部署Jupyter notebook

一、安装python环境

1.下载python3

wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz

2.解压文件

tar -xvf Python-3.6.0.tgz

3.创建安装文件的路径

mkdir /usr/local/python3

4.编译

./configure --prefix=/usr/local/python3

5.安装

make
make install

二、安装配置Jupyter

1.安装Jupyter notebook

pip install jupyter notebook

2.生成配置文件

jupyter notebook --generate-config
# 生成了配置文件:jupyter_notebook_config.py

3.创建登录密码

ipython
from notebook.auth import passwd
passwd()
Enter password: 输入自己的密码
Verify password: 再输入一遍刚刚的密码
# 输出密钥格式类似:
'sha1:a473fe94f96c:15eac26accdff8e0946d9121de8e309603581056'
# 然后退出ipython

4.修改配置文件

# 打开上面步骤生成的文件(jupyter_notebook_config.py),最好先备份一下
vi jupyter_notebook_config.py
# 设置所有ip皆可访问
c.NotebookApp.ip = '*'

# 禁止自动打开浏览器
c.NotebookApp.open_browser = False

# 添加生成的密钥
c.NotebookApp.password = 'sha1:a473fe94f96c:15eac26accdff8e0946d9121de8e309603581056'

#访问端口
c.NotebookApp.port = 8888

三、防火墙开放端口

我的服务器使用的阿里云的ECS实例,所以直接从上面新添加一个安全组规则就行了
添加安全组规则

四、后台进程启动Jupyter notebook

如果使用jupyter notebook启动Jupyter notebook,则会在退出服务器连接时,停止该进程。
使用后台进程可以完美的解决这一问题

nohup jupyter notebook --allow-root >/dev/null 2>&1 &

其中>/dev/null 2>&1 &是将输出日志重定向,这样可以防止将来日志文件占用内存越来越大。如果想输出日志,就可以不用输入这段命令。

五、停止进程

在上一步操作后,如果想停止它,可以找到进程ID,然后停止该进程

# 查看进程
ps -ef | grep 'jupyter notebook'
# 输出内容类似:
# root      9120  9100  0 00:01 pts/1    00:00:00 grep --color=auto jupyter notebook
# 杀死进程
kill -9 9100
# 此时浏览器中无法访问

参考:
1. linux下配置安装python3
2. linux安装远程ipython notebook

你可能也会喜欢...

发表评论

邮箱地址不会被公开。 必填项已用*标注