步骤1:安装jupyter notebook
$ pip install --user /g3/vfy_xp/liuch/whl/ipython-7.6.1-py3-none-any.whl
$ pip install --user /g3/vfy_xp/liuch/whl/ipykernel-4.8.2-py3-none-any.whl
$ pip install --user /g3/vfy_xp/liuch/whl/jupyter-1.0.0-py2.py3-none-any.whl
步骤2:生成配置文件
安装jupyter后续通过以下命令生成配置文件$jupyter notebook --generate-config
生成的配置文件位于 ./jupyter/jupyter_notebook_config.py
步骤3:生成访问密码
运行命令
$jupyter notebook password
会让你填写密码和确认密码,并且生成含有密码的hash的./jupyter/jupyter_notebook_config.json在配置文件中
jupyter notebook password
Enter password:
Verify password:
[NotebookPasswordApp] Wrote hashed password to /home/coke/snap/jupyter/6/.jupyter/jupyter_notebook_config.json
接下来 输入 $ python
进入python之后
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
记录下上面输出的hash码
步骤4:修改默认配置文件
使用vim对配置文件进行修改,配置文件目录以本机为准
$cd
$vim .jupyter/jupyter_notebook_config.py
主要对以下几条进行修改
c.NotebookApp.ip='*' # 任意内网ip都可以访问jupyter提供的服务
c.NotebookApp.password = u'sha:ce...刚才复制的那个密文'
c.NotebookApp.open_browser = False #避免服务器端浏览器自动打开
c.NotebookApp.port =8888 #指定一个端口
c.NotebookApp.notebook_dir = u'/g3/vfy_xp/xxx/code' # 指定后期jupyter脚本存放根目录(个人有权限修改的一个文件夹)
步骤5: 运行jupyter
$ cd /g3/vfy_xp/xxx/code
$ nohup jupyter notebook --allow-root --ip 10.40.141.18 --no-browser > jupyter.log 2>&1 &
上述命令运行后,jupyter notebook 在后台开启执行,执行的进程号为:
[1] 224471
# 上面的ip 为shell的登录ip,可以通过$ ip addr 查看
步骤6: 查看生成的服务器网址
$ cat jupyter.log
[I 02:00:39.714 NotebookApp] Running the core application with no additional extensions or settings
[I 02:00:39.735 NotebookApp] Serving notebooks from local directory: /g3/vfy_xp/liuch/code
[I 02:00:39.735 NotebookApp] The Jupyter Notebook is running at:
[I 02:00:39.735 NotebookApp] http://XX.XX.XXX.XXX:8888/
[I 02:00:39.735 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
上面输出内容中包含的http:开头的部分就是jupyter服务的网址
步骤7: 登录和使用jupyter
将上述网址拷贝至内网的浏览器(可以是windows下)中,打开网页,输入之前设置的密码,开始使用。
步骤8:关闭和重启jupyter服务
默认情况下,jupyter服务可以一直开启,但如果涉及到python库更新时,需要关闭和重启jupyter服务。
$kill -9 224471 # jupyter进程
如果忘记了jupyter的进程号,可以通过端口查看jupyter 进程号
[vfy_xp@login_a06 code]$ lsof -i:8888
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
jupyter-n 224471vfy_xp 5u IPv4 179968629 0t0 TCP 10.40.141.18:ddi-tcp-1 (LISTEN)
关闭后 输入$nohup jupyter notebook --allow-root --ip 10.40.141.18 --no-browser > jupyter.log 2>&1 & 可重启jupyter服务。