问题描述:近日在本地服务器配置jupyter nptebook,但是按照优快云中一些内容的教程一直配置失败,直到看到知乎上某位网友的解答,非常详细,有兴趣的网友可以移步至该博文(https://zhuanlan.zhihu.com/p/64524822)查看。
本文只记录如何快速的配置远程jupyter notebook
假设你之前从来没有配置过,那么按照我如下的方法来就行了。
(base)[amax@localhost ~]$ jupyter notebook --generate-config
输出如下:Writing default config to: /home/amax/.jupyter/jupyter_notebook_config.py
1,为了安全性,需设置jupyter notebook密码。
(base) [amax@localhost ~]$ jupyter notebook password
Enter password: ****
Verify password: ****
[NotebookPasswordApp] Wrote hashed password to /home/amax/.jupyter/jupyter_notebook_config.json
2,使用Ipython生成hash密钥
(base) [amax@localhost ~]$ ipython
Python 3.8.3 (default, Jul 2 2020, 16:21:59)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:756f5e132786:cd353731d66574fd3665b7bf8f7af743ee18d2f1'
3,拷贝上面的sha1:xxxx ,后面能用到。 然后键入 exit() 退出ipython
4,接着配置jupyter_notebook_config.py文件
(base) [amax@localhost ~]$ sudo vim ~/.jupyter/jupyter_notebook_config.py
5,打开后文件末尾添加以下几行代码:(进入后按 "i"进入可编辑文本模式,随后使用鼠标下拉到文件末尾加入下方的代码, 完成后按"esc"推出编辑模式,然后按“caps”键,随后连续按两下"Z"键即可退出)
c.NotebookApp.password = u'sha1:756f5e132786:cd353731d66574fd3665b7bf8f7af743ee18d2f1'
c.NotebookApp.allow_remote_access = True
c.NotebookApp.open_browser = False
c.NotebookApp.port = 9999 #这个9999可以根据自己喜欢随便定义
6,开放linux防火墙端口
(base) [amax@localhost ~]$ sudo firewall-cmd --zone=public --add-port=9999/tcp --permanent
[sudo] amax 的密码:****
Success
7,重新启动防火墙
(base) [amax@localhost ~]$ sudo systemctl restart firewalld
8,随后在自己的电脑上使用ssh登录服务器jupyter。在登陆之前需要弄清楚自己服务器的ip。
可通过ifconfig命令查询,类似于 inet 192.168.xx.xx 这个就是
(我自己的电脑是win10操作系统)
PS C:\Windows\system32> ssh amax@192.168.xx.xx
9,输入服务其密码登录成功之后,在自己的电脑上输入以下命令:
(base) [amax@localhost ~]$ nohup jupyter notebook &
OK,至此已经完成1