Linux 服务器配置Jupyter notebook, 并支持在win的浏览器上面打开
安装步骤:
1. 安装jupyter:
pip install jupyter
2. 生成notebook配置文件:
jupyter notebook --generate-config
执行后会在/home/usename 目录下生成 .jupyter目录,里面包含几个文件:
3. 配置jupyter notebook密码:
$ jupyter notebook password
执行后会输入两次密码,设置了jupyter notebook的密码
4. 设置允许win远程访问(学会使用vim编辑文件,点击vim使用参考博客):
vim ~/.jupyter/jupyter_notebook_config.py
# 然后在里面修改的内容有:
# 1. 第82行,False 改为 True, 允许远程访问
c.NotebookApp.allow_remote_access = True
# 2. 第204行,'localhost'改为'*',允许任意ip地址访问
c.NotebookApp.ip = '*'
# 3. 第272行,True 改为 False, 关闭启动后自动打开浏览器
c.NotebookApp.open_browser = False
5. 启动jupyter
jupyter notebook
# 然后就可以看到
[W 16:30:17.129 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 16:30:17.129 NotebookApp] The port 8888 is already in use, trying another port.
[I 16:30:17.133 NotebookApp] Serving notebooks from local directory: /home/chenbaoying/.jupyter
[I 16:30:17.133 NotebookApp] The Jupyter Notebook is running at:
[I 16:30:17.133 NotebookApp] http://gtx1080gpu2:8889/
[I 16:30:17.133 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
6. win 浏览器打开, 把http://gtx1080gpu2:8889/ 替换为 http://ip:8889/ , 比如我的服务器的ip是 172.31.2.2, 那我再浏览器中输入的url是; http://172.31.2.2:8889/ ,每次重新启动jupyter需要输入前面设置的密码。
7. 有时候启动后,在win上仍然访问不了,主要原因是指定的端口在Liunx上面没有开放,这时候需要手动开放指定的端口
sudo /sbin/iptables -I INPUT -p tcp --dport 8889 -j ACCEPT
参考博客: