当前位置: 代码迷 >> 综合 >> Linux 环境下配置远程jupyter notebook server
  详细解决方案

Linux 环境下配置远程jupyter notebook server

热度:4   发布时间:2023-11-30 17:03:54.0

XShell配置Linux服务器jupyter notebook

参考:

  • https://www.aisun.org/2018/08/linux+jupyter/
  • https://jupyter-notebook.readthedocs.io/en/stable/public_server.html
  • http://blog.lerner.co.il/five-minute-guide-setting-jupyter-notebook-server/
  • https://www.aisun.org/2018/08/linux+jupyter/

 jupyter相关命令

sudo start jupyter              # 启动 jupyter
sudo stop/restart jupyter       # 停止/重启 jupyter
sudo status jupyter             # 查看 jupyter 的状态

向jupyter中添加Kernel

1.查看kernel列表

jupyter kernelspec list

2.进入新环境添加kernel安装ipykernel库

Jupyter Notebook 增加kernel的方法:https://blog.csdn.net/wj1066/article/details/72891667

conda activate tensorflow
which python #查看python位置
sudo /home/zhoudengji/anaconda3/envs/tensorflow/bin/python -m ipykernel install --name tensorflow
conda install ipykernel  #若报错则在该python环境安装ipykernel包

3.删除kernel

jupyter kernelspec remove kernelname

配置jupyter notebook server

1.生成config文件

jupyter notebook --generate-config

2.生成密码

In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'#复制下来等会用

3.编辑配置文件,修改https/ip/openbroswer/port/password等属性

vi /home/xxxxxxx/.jupyter/jupyter_notebook_config.py

 

c.NotebookApp.allow_origin = '*'
c.NotebookApp.allow_remote_access = True
c.NotebookApp.allow_root = True
c.NotebookApp.ip='*'
c.NotebookApp.open_browser = False
c.NotebookApp.password = u'sha1:3XXXXXXXXXXXXXXXX5'
c.NotebookApp.port =8888

3.防火墙设置,关闭防火墙

sudo firewall-cmd --zone=public --add-port=8888/tcp --permanent
sudo systemctl restart firewalld
systemctl stop firewalld.service--
# 用这个
sudo iptables -I INPUT -p tcp --dport 8888 -j ACCEPT
iptables-save
--

4.后台启动

nohup jupyter notebook   # 我使用的是这个
nohup jupyter notebook >/dev/null 2>&1 &
nohup jupyter notebook -config /home/zhoudengji/.jupyter/jupyter_notebook_config.py --allow-root >/dev/null 2>&1 &

5.关闭远程jupyter notebook

# 查看进程
ps -ef | grep 'jupyter notebook'
# 输出如下,这里的21983即为进程id,
# hadoop    22136  21983  0 09:10 pts/1    00:00:00 grep jupyter notebook
# 杀死进程
kill -9 21983

下次启动jupyter notebook步骤

1.conda activate tensorflow
2.# 设置了防火墙之后,再次再进去启动jupyter不需要这一步
sudo firewall-cmd --zone=public --add-port=8888/tcp --permanent
sudo systemctl restart firewalld
systemctl stop firewalld.service
3.nohup jupyter notebook

 

  相关解决方案