配置jupyter
jupyter notebook --generate-config --allow-root
(该文件路径默认为: ~/.jupyter/jupyter_notebook_config.py)
进入python3环境:
from notebook.auth import passwd
passwd()
exit()
python环境中的完整操作过程如下:
[root@python ~]
Python 3.9.6 (default, Aug 3 2021, 14:59:02)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from notebook.auth import passwd
>>> passwd()
Enter password: ********
Verify password: ********
'argon2:$argon2id$v=19$m=10240,t=10,p=8$28jw9sbYGlMey75R1198xw$/PbuQsPktKk/7ctO37BQIA'
>>> exit()
编辑配置文件
vim ~/.jupyter/jupyter_notebook_config.py
在文件中第1行直接复制粘贴下面内容:(当然,也可以在文件中找到对应的配置项取消注释后修改,那样确实更规范些,但是这里为了方便后续修改配置,直接在第1行加了)
c.NotebookApp.ip='*'
c.NotebookApp.password ='argon2:...'
c.NotebookApp.open_browser = False
c.NotebookApp.port =8888
c.NotebookApp.notebook_dir = '/home/xxx'
保存退出
启动jupyter notebook
jupyter notebook --allow-root
[root@python ~]
[I 16:19:46.118 NotebookApp] Serving notebooks from local directory: /root
[I 16:19:46.118 NotebookApp] Jupyter Notebook 6.4.0 is running at:
[I 16:19:46.118 NotebookApp] http://python:8888/
[I 16:19:46.118 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[I 16:19:59.147 NotebookApp] 302 GET / (60.179.177.253) 0.640000ms
[I 16:19:59.175 NotebookApp] 302 GET /tree? (60.179.177.253) 1.030000ms
[I 16:20:10.560 NotebookApp] 302 POST /login?next=%2Ftree%3F (60.179.177.253) 125.340000ms
然后我们就可以在自己的设备上浏览器地址栏输入服务器ip:8888 就可以访问了
但这时候如果关闭了终端,那么jupyter就停了,所以可以用下面这条命令后台启动它
nohup jupyter notebook --ip 0.0.0.0 --allow-root > jupyter.log 2>&1 &