机器学习环境配置系列六之jupyter notebook远程访问

安装Jupyter后,在不进行如下第2和第3两步配置的话就可以满足本地运行的需要了。

但如果部署在服务器上,希望可以远程录入Jupyter,这篇文章就是解决这个远程访问的问题。几个基本的命令就可以搞定,然后就可以愉快的玩耍了。

1、安装jupytetr

conda install jupyter

2、远程访问配置

jupyter notebook --generate-config
jupass = 'python -c"from notebook.auth
import passwd; print(passwd())"'

echo "c.NotebookApp.password = u'"$jupass"'" >> .jupyter/jupyter_notebook_config.py

echo "c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = Flase
c.NotebookApp.port = 端口号">> .jupyter/jupyter_notebook_config.py

  注:如果服务器是固定ip地址,c.NotebookApp.ip 也可以指定固定的ip更稳定

3、开启linux端口命令

/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT #开启80端口 
/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT #开启22端口 
/etc/rc.d/init.d/iptables save #保存配置 
/etc/rc.d/init.d/iptables restart #重启服务 
查看已开放端口 
/etc/init.d/iptables status 

4、启动jupyter

jupyter notebook

  启动信息如下:

[I 18:52:57.324 NotebookApp] Serving notebooks from local directory: /home/用户名
[I 18:52:57.324 NotebookApp] The Jupyter Notebook is running at:
[I 18:52:57.324 NotebookApp] http://ip:port/
[I 18:52:57.324 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[I 19:17:27.484 NotebookApp] Kernel started: 78d6fb00-dadd-4cfa-91d8-7102d7907599
[I 19:17:31.084 NotebookApp] Adapting to protocol v5.1 for kernel 78d6fb00-dadd-4cfa-91d8-7102d7907599
[W 19:17:47.801 NotebookApp] 404 GET /nbextensions/widgets/notebook/js/extension.js?v=20181024185257 10.92ms re

5、字符集问题

如果linux用的是中文字符集jupyter启动很容易出现问题,如果出现类似问题,把linux改为英文,包治百病。

上述只是jupyter的简单配置,复杂的参数配置请大家自行研究,这个内容可以满足基本的使用需求了。

posted @ 2018-10-24 21:58  Jaww  阅读(1809)  评论(0编辑  收藏  举报