前言:本文假设你已经在CentOS上已安装好Jupyter Notebook而待配置
一、生成密码并获取对应密钥(sha1:…)
# 假设你已经进入了python
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password: # 可直接按Enter回车键
Verify password: # 可直接按Enter回车键
Out[2]: 'sha1:f704b702aea2:01e2bd991f9c7208ba177b46f4d10b6907810927'
二、生成并配置Jupyter配置文件
jupyter notebook --generate-config
生成的config file在/root/.jupyter/jupyter_notebook_config.py
vim /root/.jupyter/jupyter_notebook_config.py
配置内容如下,可在vim命令模式下输入类似/App.ip来定位到该配置项的位置
# 将ip设置为*,允许任何IP访问
c.NotebookApp.ip = '*'
c.NotebookApp.allow_root = True
# 这里的密码填写上面生成的密钥
c.NotebookApp.password = 'sha1:f704b702aea2:01e2bd991f9c7208ba177b46f4d10b6907810927'
# 禁止用host的浏览器打开jupyter
c.NotebookApp.open_browser = False
# 监听端口设置为8888或其他
c.NotebookApp.port = 8888
# 允许远程访问
c.NotebookApp.allow_remote_access = True
# jupyter notebook工作目录
c.ContentsManager.root_dir = '/root/notebook/'
最后在CentOS上直接运行一下命令即可开启Jupyter notebook
jupyter notebook --allow-root
然后在自己电脑浏览器输入如下IP即可访问 http://<ip>:8888/

三、后台运行Jupyter(不挂起)
$ nohup jupyter notebook --allow-root > jupyter.log 2>&1 &
&表示后台运行, 并把标准输出写入jupyter.log中nohup命令表示no hang up, 就是不挂起, 即使终端退出, 也不会停止运行.

注意:远程不挂起jupyter的命令为
nohup <运行Jupyter句柄> > jupyter.log 2>&1 &
因此,有其他设置需求可替换中间句柄即可,如
nohup xvfb-run -s "-screen 0 1400x900x24" jupyter notebook > jupyter.log 2>&1 &
如果想要退出该进程,则先打印出进程id,然后kill掉即可
ps -aux | grep jupyter
kill -9 <id> # 此处id是 24203

下面指令可以查看每2秒GPU使用情况:
watch -n 2 nvidia-smi

本文详述了在CentOS系统中配置Jupyter Notebook的过程,包括生成密码密钥、配置文件设置、后台运行及远程访问等关键步骤,帮助读者实现安全且高效的Jupyter环境搭建。
3577

被折叠的 条评论
为什么被折叠?



