# Jupyter Notebook 本教程包含Scientific Linux 7(Centos 7)中Jupyter Notebook的配置使用 ## 安装 按照教程安装好 - python2/3 - nodejs - npm - configurable-http-proxy - pip2/pip3 - jupyter metakernel zmq - Markdown - jupyterthemes - jupyter_nbextensions_configurator - jupyter_contrib_nbextensions - jupyterhub - sudospawner - rise ```bash pip install -i http://pypi.douban.com/simple --trusted-host pypi.douban.com xxx ``` ## 远程访问Jupyter Notebook 生成配置文件 ```shell jupyter notebook --generate-config ``` 生成密码 打开ipython, 创建一个密文密码 ```python In [1]: from notebook.auth import passwd In [2]: passwd() Enter password: Verify password: Out[2]: 'sha1:ecff44b879cd:35b5b64072d286b66f0d8f84a41dbf7515d21755' ``` **把生成的密文‘sha:ec…’复制下来** 修改默认配置文件 ```shell emacs ~/.jupyter/jupyter_notebook_config.py `` 进行以下的修改 ```python #根据需要进行修改 c.NotebookApp.ip = '*' # 就是设置所有ip皆可访问 c.NotebookApp.password = u'sha1:ec...刚才复制的那个密文' c.NotebookApp.open_browser = False # 禁止自动打开浏览器 c.NotebookApp.port = 8888 #随便指定一个端口 c.NotebookApp.notebook_dir = u'/home/wuhongyi/jupyter' #设置目录,存放创建的ipython notebook文件 ``` 参考网页 > http://jupyter-notebook.readthedocs.io/en/stable/index.html 启动jupyter notebook ```shell jupyter notebook #如果需要指定配置 jupyter notebook --config=jupyter_notebook_config.py ``` ## 防火墙 ```shell emacs /etc/sysconfig/iptables ``` 在最后一行之前添加如下,其中8888替换成你指定的端口即可 ```shell -A INPUT -p tcp -m state --state NEW -m tcp --dport 8888 -j ACCEPT ``` 最后让配置生效 ```bash systemctl restart iptables.service #最后重启防火墙使配置生效 systemctl enable iptables.service #设置防火墙开机启动 ``` ## 日志和后台进程 ```bash nohup jupyter notebook >/dev/null 2>&1 & ``` ## 停止jupyter notebook jupyter notebook作为后台进程启动后,如果想要停止它,可以先找到进程ID,然后kill。 ## 更换主题 > https://github.com/dunovank/jupyter-themes 安装完成后,jupyterthemes 以别名 jt 存在于 python 环境中。 ```bash jt -l ``` 查看当前支持的主题。 比如我想换 grade3,那么输入 ```bash jt -t -grade3 ``` ## 扩展插件 ```bash #哪个用户开启服务进程就哪个用户执行 jupyter contrib nbextension install --user #插件使用 jupyter nbextensions_configurator enable --user #插件使用 jupyter-nbextension install rise --py --sys-prefix jupyter-nbextension enable rise --py --sys-prefix ``` ## SSL加密配置 自己建一个文件夹或者干脆在~/.jupyter/ 文件夹下面执行下面命令: ```bash openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mycert.pem -out mycert.pem ``` 同时编辑 jupyter_notebook_config.py ```bash # browser auto-opening c.NotebookApp.certfile = u'路径名/mycert.pem' ``` ## jupyterhub配置 > https://jupyterhub.readthedocs.io/en/latest/index.html > https://www.cnblogs.com/crxis/p/9078278.html 创建配置文件 ```bash jupyterhub --generate-config ``` 生成一个默认的配置文件 jupyterhub_config.py 开启jupyterhub服务 ```bash jupyterhub --no-ssl ``` ---- > https://blog.csdn.net/baidu_26550817/article/details/52032566 > https://blog.csdn.net/baidu_26550817/article/details/52955435 > https://www.cnblogs.com/bregman/p/5744109.html > https://wenku.baidu.com/view/c3d478034a35eefdc8d376eeaeaad1f34693117d.html