生產環境使用 Fedora 28, 並且需要搭建一個 Jupyter 的notebook 方便使用,所搭建的Jupyter 支持單人遠程 密碼訪問 1. 安裝 安裝 Jupyter , 出錯 安裝 redhat-rpm-config 安裝 python-devel 安裝 notebook 2. 運行 ...
生產環境使用 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/
保持更新,轉載請註明出處。