服务器
服务器环境
Ubuntu 20.04
软件安装和配置
安装 jupyter, jupyter-notebook
pip install jupyter jupyter-book
修改 jupyter_notebook_config.py
vi ~/.jupyter/jupyter_notebook_config.py
在文件最后,添加上下面语句
# 允许通过任意绑定服务器的ip访问
c.NotebookApp.ip = '*'
# 用于访问的端口
c.NotebookApp.port = 8888 #注意这里与前面开出的容器端口要一致
# 不自动打开浏览器
c.NotebookApp.open_browser = False
#允许远程访问
c.NotebookApp.allow_remote_access = True
# 登录密码获得的乱序秘钥复制到‘’内
c.NotebookApp.password = u''
启动 jupyter
jupyter notebook -ip 0.0.0.0 --allow-root --port 8888 --no-browser
这样,远程服务器安装和配置就已经完成。
To access the notebook, open this file in a browser:
file:///home/xxxx/.local/share/jupyter/runtime/nbserver-3325393-open.html
Or copy and paste one of these URLs:
http://AAAAAA:8888/?token=89aaf793f990d127dd958c9a6f8a42a10185331d694cae75
or http://127.0.0.1:8888/?token=89aaf793f990d127dd958c9a6f8a42a10185331d694cae75
注意上面的 token,这个就是访问远程服务器的密码。
本机
命令行运行
ssh -L 8887:localhost:8888 服务器用户名@服务器ip地址
注意:
- 8888:是远程服务器 jupyter 的端口,为缺省端口。
- 8887:是本机访问远程服务器 jupyter 的端口。
- 服务器用户名:可以登录到远程服务器的 id。
- 服务器 ip 地址:远程服务器的 IP。
成功登录远程服务器后。
浏览器访问 jupyter
打开浏览器,地址栏中输入
localhost:8887
出现的界面中,需要我们输入登录的 token。
回去查看服务器的 Log 中显示的 token,如上面的记录。拷贝输入对应的 token,点 log in 即可。
或者,在地址栏中直接输入 token
localhost:8887/?token=89aaf793f990d127dd958c9a6f8a42a10185331d694cae75
这样,我们就可以直接访问远程服务器的 jupyter notebook。