Jupyter远程访问配置及使用
Jupyter Notebook是基于网页的用于交互计算的应用程序。其可被应用于全过程计算:开发、文档编写、运行代码和展示结果。
当涉及到基于Python的工作时,我发现使用Jupyter来管理工具代码、处理过程和测试用例等非常方便。我在这篇文档中记录了在阿里云服务器(Ubuntu)上配置Jupyter的过程,并成功地将Jupyter绑定到一个域名上,这样我就可以通过网络访问我的笔记了。这种设置让我的工作变得非常便捷。
参考链接:
Jupyter Notebook 7.0 更新远程访问配置_no module named 'notebook.auth-CSDN博客 (opens new window)
Ubuntu与windows下配置安装jupyter-notebook以及其开机自启、后台运行与远程访问-CSDN博客 (opens new window)
# 1、安装
# pip3 install jupyter
# 2、生成配置文件
# jupyter notebook --generate-config
# 3、修改配置文件(根据生成的配置文件修改路径)
# sudo nano /root/.jupyter/jupyter_notebook_config.py
# jupyter_notebook_config.py 末尾添加如下配置文件
c.ServerApp.ip = '0.0.0.0'
c.ServerApp.password = '' # 密码留空
c.ServerApp.open_browser = False
c.ServerApp.port = XXXX # 端口
c.ServerApp.allow_remote_access = True
c.NotebookApp.notebook_dir = 'notebook的文档路径'
2
3
4
5
6
7
8
# 4、运行软件
# jupyter notebook --allow-root &
# 5、域名绑定
服务器运行在阿里云上,域名解析中添加 note 的二级域名,用于访问 jupyter
# 6、登录
网站是http协议的,端口是配置参数中的端口
http://note.domain.com:9100/
首次登录可以在网页上输入token,密码来设置;
# 7、修改密码
终端中输入命令,输入两次密码,密码就改了
jupyter notebook password
# 8、做成服务开机启动
找到jupyter-notebook的安装路径,root用户为 /usr/local/bin/jupyter-notebook 普通用户为/home/$USER/.local/bin/jupyter-notebook
# whereis jupyter-notebook
#新建服务文件
# sudo nano /lib/systemd/system/jupyter.service
[Unit]
Description=jupyter notebook
After=network.target
[Service]
Type=simple
# 这里填用户名,下同
User=root
EnvironmentFile= /usr/local/bin/jupyter-notebook
ExecStart= /usr/local/bin/jupyter-notebook --allow-root
ExecStop= /usr/local/bin/jupyter-notebook
KillMode=process
Restart=on-failure
RestartSec=30s
[Install]
WantedBy=multi-user.target
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
保存后终端依次输入以下代码
sudo systemctl daemon-reload sudo systemctl enable jupyter.service sudo systemctl start jupyter.service
输入以下代码观察有无报错信息
systemctl status jupyter
其他常用控制jupyter命令
#移除jupyter服务 sudo systemctl disable jupyter.service #重启jupyter服务 sudo systemctl restart jupyter.service #停止jupyter服务 sudo systemctl stop jupyter.service