如何在Ubuntu 16.04服务器实例上安装Jupyter Notebook
Tianye
・4 分钟阅读
使用不同的系统?
介绍
Jupyter Notebook源于IPython,是一个广泛使用的交互式数据科学Web应用程序,可用于创建和共享科学计算相关文档。
本文会向你展示如何在Ubuntu 16.04服务器实例上安装 Jupyter Notebook ,以便使用python3和
pip进行远程访问。
前提条件
在开始之前,你需要:
- 部署新的Ubuntu 16.04服务器实例,
- 从SSH终端作为非根sudo用户登录,假设用户名为"
juser
",你应该遵循Debian指令,执行/etc/init.d/ssh restart而不是/etc/init.d/sshd restart ,
更新系统并安装PIP
使用以下命令更新系统:
sudo apt-get update -y
sudo apt-get install python3-pip -y
pip3 install --upgrade pip
安装 Jupyter Notebook
安装 Jupyter Notebook 。
sudo apt-get install python3-setuptools -y
sudo pip3 install jupyter
配置Jupyter
在配置 Jupyter Notebook 之前,我们需要创建一个配置文件,为此,我们先转到我们的主目录,并且创建一个新的主目录。
cd ~
jupyter notebook --generate-config
接下来,让我们为服务器创建一个散列密码,执行以下命令,并且按照指示执行。
jupyter notebook password
在本教程中,我们假设密码是"jupyter
",这将创建哈希并将它保存在你的jupyter_notebook_config.json
中,它将位于,~/.jupyter/jupyter_notebook_config.json
。
既然我们希望至少有一些安全性,让我们在.jupyter/cert
目录下建立一个SSL证书。
cd .jupyter
mkdir cert
cd cert
openssl req -x509 -nodes -days 365 -newkey rsa:4096 -keyout jkey.key -out jcert.pem
现在我们来编辑jupter_notebook_config.py
,用你喜欢的文本编辑器打开它,找到下列行,取消注释,如下所示。
编辑前。
#c.NotebookApp.password = ''
#c.NotebookApp.port = 8888
#c.NotebookApp.ip = 'localhost'
#c.NotebookApp.open_browser = False
#c.NotebookApp.certfile = ''
#c.NotebookApp.keyfile = ''
编辑后。
c.NotebookApp.password = 'sha1:<your sha hashed password>'
c.NotebookApp.port = 8888
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.certfile = '/home/juser/.jupyter/cert/jcert.pem'
c.NotebookApp.keyfile = '/home/juser/.jupyter/cert/jkey.key'
注意:记住你的散列密码保存在 ~/.jupyter/jupyter_notebook_config.json
。
修改防火墙
修改防火墙规则。
sudo apt-get install firewalld -y
sudo firewall-cmd --zone=public --add-port=8888/tcp --permanent
sudo systemctl restart firewalld.service
结束语
使用命令运行Jupyter Notebook,然后访问 https://<your server ip>:8888
忽略安全警告,并且使用前面设置的密码。
如果你想注销,并且保持运行,请记住,你可以使用nohup运行它。
nohup jupyter notebook &