由于将jupyter装在了服务器,想在本地访问jupyter的kernel。

不知道是不是必须要在同一网段,由于学校访问问题,目前是必须确认在同一网段下。

开始配置:

  1. 生成配置文件
    (我这里是使用root用户进行配置的,但是建议最好使用普通用户)
[root@localhost Python-3.6.5]# jupyter notebook --generate-config
Writing default config to: /root/.jupyter/jupyter_notebook_config.py
  1. 生成密码文件
    如果你想远程访问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码。

  1. 修改配置文件,实现远程访问
    打开我们在第一步生成的配置文件,
    ## 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:端口号就可以访问啦。