由於將jupyter裝在了服務器,想在本地訪問jupyter的kernel。
不知道是不是必須要在同一網段,由於學校訪問問題,目前是必須確認在同一網段下。
開始配置:
- 生成配置文件
(我這裏是使用root用戶進行配置的,但是建議最好使用普通用戶)
[root@localhost Python-3.6.5]# jupyter notebook --generate-config
Writing default config to: /root/.jupyter/jupyter_notebook_config.py
- 生成密碼文件
如果你想遠程訪問jupyter時,需要使用密碼登入,就可以有這一步,自己使用的話,嗯最好還是弄一個吧。
## Hashed password to use for web authentication.
#
# To generate, type in a python/IPython shell:
#
# from notebook.auth import passwd; passwd()
#
# The string should be of the form type:salt:hashed-password.
#c.NotebookApp.password = ''
可以看到文件中給出瞭如何生成密碼文件的方法:
[root@localhost Python-3.6.5]# python3
Python 3.6.5 (default, Jan 10 2019, 04:19:43)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from notebook.auth import passwd;passwd()
Enter password:
Verify password:
'sha1:ac5012e9f4***********706f19ee9938bef6'
一定記得複製一下這串sha1碼。
- 修改配置文件,實現遠程訪問
打開我們在第一步生成的配置文件,
## The IP address the notebook server will listen on. c.NotebookApp.ip = '0.0.0.0'
204行將localhost
改爲*
,意爲允許任何ip訪問。
c.NotebookApp.open_browser = False
267行將True改爲False。並將句前的#
去掉。防止主動打開瀏覽器。
c.NotebookApp.password = 'sha1:ac5012e9f4ce:bdfdd4b96f6d5cf59aa484a1706f19ee9938bef6‘
276行同去掉#
,將上一步中生成的sha碼,複製到這裏。
c.NotebookApp.port = 8855
287行的將端口前的#
去掉,端口可以修改可以不改,自己順心就好。
保存,退出。
我在安裝的時候出現了很多鬧心的問題,一個一個來解決吧
系統,centos7,python3.6.5,jupyter最新的。
socket.gaierror: [Errno -2] Name or service not known
OSError: [Errno 99] Cannot assign requested address
首先確認你的防火牆是否關閉
centos7的命令如下:
firewall-cmd --state#查看防火牆狀態
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機啓動
有網友說,在/etc/hostname中加入
127.0.0.1 localhost
我沒發現有什麼區別。
然後就是我用的root用戶啓動需要加--allow-root
參數。
jupyter notebook --allow-root
然後在本地電腦輸入服務器的ip:端口號就可以訪問啦。