关于jupyter 的设置
官方的设置请参考Jupyter官方文档。
jupyter 设置
生成登录密码
可以进入jupyter ,或者Ipython,输入以下代码
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:#如'passwd' 输入自己的密码
Verify password:#再次输入'passwd'
Out[2]: 'sha1:9ffede0825894254b2e042ea597d7711aad'
生成jupyter 的配置文件
$ jupyter notebook --generate-config
编辑jupyter 配置文件
$ vim ~/.jupyter/jupyter_notebook_config.py
在里面添加如下信息
# Set options for certfile, ip, password, and toggle off
# browser auto-opening
#c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem'
#c.NotebookApp.keyfile = u'/absolute/path/to/your/certificate/mykey.key'
# Set ip to '*' to bind on all interfaces (ips) for the public server
#上面的感觉没有用,注释了
c.NotebookApp.ip = '*'
c.NotebookApp.password = u'sha1:9ffede0825894e042ea597d771089edf11aad'
#发现更方便的方法,直接用上面的明文会简单,当然可能不安全
#c.NotebookApp.password = u'sha1:bcd259ccf...<就是刚刚上面的密码,替换冒号里面的值>'
c.NotebookApp.open_browser = False
# It is a good idea to set a known, fixed port for server access,设置端口
c.NotebookApp.port = 8888
上周停电,服务器现在重启,以后密码总是不对,按照配置文件中的修改也不行,最后查询文档,又用了另外一种方法:
[centos@localhost ~]$ jupyter notebook password
Enter password: "mima"
Verify password: "mima"
[NotebookPasswordApp] Wrote hashed password to /home/centos/.jupyter/jupyter_notebook_config.json
[centos@localhost ~]$ jupyter notebook
[W 09:56:03.592 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 09:56:03.650 NotebookApp] JupyterLab alpha preview extension loaded from /home/centos/anaconda3/lib/python3.6/site-packages/jupyterlab
JupyterLab v0.27.0
Known labextensions:
[I 09:56:03.653 NotebookApp] Running the core application with no additional extensions or settings
[I 09:56:03.663 NotebookApp] Serving notebooks from local directory: /home/centos
[I 09:56:03.663 NotebookApp] 0 active kernels
[I 09:56:03.663 NotebookApp] The Jupyter Notebook is running at: http://[all ip addresses on your system]:8888/
[I 09:56:03.663 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
最后进入网页,输入在上面的配置好的密码 :’mima’,就可以进入了
配置防火墙端口
直接在服务器运行命令
$ jupyter notebook
我用的是CentOS7.3,不过我在客户端连接不反应,一查是防火墙的问题
于是就在防火墙添加 8888 端口
#添加8888端口
$ firewall-cmd --zone=public --add-port=8888/tcp --permanent
#重启防火墙
$ systemctl restart firewalld.service
好的,在输入启动,
$ jupyter notebook
[centos@localhost ~]$ jupyter notebook
[W 09:50:16.385 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not usin
[I 09:50:16.390 NotebookApp] The port 8888 is already in use, trying another port.
[I 09:50:16.455 NotebookApp] JupyterLab alpha preview extension loaded from /home/centos/anaconda3/lib/
JupyterLab v0.27.0
Known labextensions:
[I 09:50:16.460 NotebookApp] Running the core application with no additional extensions or settings
[I 09:50:16.472 NotebookApp] Serving notebooks from local directory: /home/centos
[I 09:50:16.472 NotebookApp] 0 active kernels
[I 09:50:16.472 NotebookApp] The Jupyter Notebook is running at: http://[all ip addresses on your syste
[I 09:50:16.472 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip
不过看启动文档是不是8888,如果被占用就是8889,
查看那个进程在占用这个端口,没用就删除了,
[root@localhost centos]$ netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1980/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1598/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1601/cupsd
tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 18997/python
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1874/master
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::22 :::* LISTEN 1598/sshd
tcp6 0 0 ::1:631 :::* LISTEN 1601/cupsd
tcp6 0 0 :::8888 :::* LISTEN 18997/python
tcp6 0 0 ::1:25 :::* LISTEN 1874/master
以前后台启动了jupyter ,所以删除了,
kill -9 18997
这下就好了
后面再等了,让输入密码,我一直输入 ‘sha1:9ffede0825894254b2e042ea597d771089e11aad’
不过一直报错,所以我估计是’sha1:’ 不需要输入,只需要冒号后面的。
最后没有问题后,让这个Server一直后台运行,即使关了ssh 也不用停服务
$ nohup jupyter notebook &
#项查询日志,可以输入
$ cat nohup.out
其中看到这篇文章也写得不错,推荐一下
在服务器端升级python并安装Jupyter