Use Jupyter notebook on Fedora 28

2018-07-11 03:29:56来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

生产环境使用 Fedora 28, 并且需要搭建一个 Jupyter 的notebook 方便使用,所搭建的Jupyter 支持单人远程 密码访问

1. 安装

安装 Jupyter , 出错

[root@dhcp-65-15 ~]# pip install jupyter
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip install --user` instead.
.
.
.
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-2.7
    copying scandir.py -> build/lib.linux-x86_64-2.7
    running build_ext
    building '_scandir' extension
    creating build/temp.linux-x86_64-2.7
    gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.7 -c _scandir.c -o build/temp.linux-x86_64-2.7/_scandir.o
    gcc: error: /usr/lib/rpm/redhat/redhat-hardened-cc1: No such file or directory
    error: command 'gcc' failed with exit status 1
    
    ----------------------------------------
Command "/usr/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-8KqVrv/scandir/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-IrivkV-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-8KqVrv/scandir/
You are using pip version 9.0.3, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

安装 redhat-rpm-config

[root@dhcp-65-15 ~]# yum install redhat-rpm-config

安装 python-devel

[root@dhcp-65-15 ~]# yum install python-devel

安装 notebook

[root@dhcp-65-15 ~]# pip install notebook

2. 运行

生成token 运行:

[root@dhcp-65-15 ~]# jupyter notebook --allow-root
[I 03:45:13.108 NotebookApp] Serving notebooks from local directory: /root
[I 03:45:13.108 NotebookApp] 0 active kernels
[I 03:45:13.108 NotebookApp] The Jupyter Notebook is running at:
[I 03:45:13.108 NotebookApp] http://localhost:8888/?token=60bbeb5c2ef4a8c0e15cfcb85588e265a185b46949e051e7

生成配置文件:

[root@dhcp-65-15 ~]# jupyter notebook --generate-config
Writing default config to: /root/.jupyter/jupyter_notebook_config.py

3. 配置

(1)在配置文件中配置密码:

c.NotebookApp.password = u'sha1:12a39cedb875:c97d0285f90cec397fffe96f11e5ef5e56e90fa2'

其中:加密使用 

from notebook.auth import passwd  中 password 方法进行加密
可以在 python shell 中生成

或者直接使用:
[root@dhcp-65-15 ~]# jupyter notebook password

设置密码,并直接写到配置文件中

如果没有设置密码 可以使用 jupyter notebook list 命令来查看 token 从而进行访问。

(2)允许所有ip地址访问 

# Set ip to '*' to bind on all interfaces (ips) for the public server
c.NotebookApp.ip = '*'
c.NotebookApp.password = u'sha1:bcd259ccf...<your hashed password here>'
c.NotebookApp.open_browser = False

# It is a good idea to set a known, fixed port for server access
c.NotebookApp.port = 8888

  (3)  保证 IPython Clusters 运行

[root@dhcp-65-15 ~]# pip install ipyparallel

 

具体对 notebook 外观的修改,可以从源代码角度进行修改,进行定制,这里就不多讲了。

如果 需要添加 防火墙规则,可以根据实际需要的端口进行添加。

更多配置请参考:

https://jupyter-notebook.readthedocs.io/en/stable/public_server.html#securing-a-notebook-server

https://github.com/ipython/ipyparallel

https://jupyterhub.readthedocs.io/en/latest/

保持更新,转载请注明出处。

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:/etc/postfix下 main.cf 配置文件详解

下一篇:linux 常用命令