文章目录
前言
在远程服务器上开启jupyter notebook。
一、打开防火墙端口
首先查看服务器的操作系统版本(开端口的代码会有所不同):
1.简单判断linux版本
通过输入 yum (CentOS)和 apt(ubuntu) 看是否有输出。
发现yum可以用则是CentOS。
2.确定CentOS版本
cat /etc/redhat-release
显示为
CentOS Linux release 8.5.2111
3.打开防火墙端口
找到CentOS8的开端口代码
firewall-cmd --zone=public --add-port=XXXX/tcp --permanent
注意:要管理员权限。
别忘记重启防火墙
systemctl restart firewalld
二、配置jupyter notebook
1.安装 jupyter notebook
2. 修改配置
生成配置文件
jupyter notebook --generate-config
进入配置文件
/home/username/.jupyter/jupyter_notebook_config.py
在配置里找到注释的两行,修改并删掉前面的井号和空格!
c.NotebookApp.ip = '*'
c.NotebookApp.allow_remote_access = True
可以指定默认使用的端口
c.NotebookApp.port =xxxxx
完成配置。
此外,可以对jupyter设置一个远程访问的密码,在终端输入:
jupyter notebook password
此时设置密码:
Enter password:
Verify password:
[NotebookPasswordApp] Wrote hashed password to /home/ljz/.jupyter/jupyter_notebook_config.json
三、 远程登录
可以在本地浏览器通过ip:port的形式进入 jupyter了。
解决占用一个终端的问题:可以让jupyter 在后台运行,并且关掉终端后不会退出,同时日志记录默认存在当前目录的 nohup.out。
nohup jupyter notebook &