step1:安裝
首先檢查本地環境:
[root@67 ~]# pip3 --version pip 19.1.1 from /usr/local/python3/lib/python3.6/site-packages/pip (python 3.6)
升級PIP至最新版本
[root@67 ~]# pip3 install --upgrade pip
使用yum -y groupinstall "Development Tools"安裝多種開發者工具
yum -y groupinstall "Development Tools"
新建虛擬環境
mkvirtualenv pd_test
安裝jupyter notebook
pip3 install jupyter Notebook
step2:配置
在/user/local/目錄下創建一個jupyter文件夾,用來存放Jupyter notebook文件
cd /usr/local mkdir jupyter
生成配置文件
(pd_test) [root@67 jupyter]# jupyter notebook --generate-config Writing default config to: /root/.jupyter/jupyter_notebook_config.py
以上將會在 ~/.jupyter/ 下創建默認config 文件: jupyter_notebook_config.py
修改這個 py 文件
c.NotebookApp.port = 8080 c.NotebookApp.ip = '你的服務器公網IP' c.NotebookApp.open_browser = False
c.NotebookApp.notebook_dir = '你的jupyter文件存放位置'
保存配置文件
設置登錄密碼
(pd_test) [root@67 .jupyter]# jupyter notebook password Enter password: Verify password: [NotebookPasswordApp] Wrote hashed password to /root/.jupyter/jupyter_notebook_config.json
step3:在服務器手動 啟動 notebook
jupyter notebook --ip=0.0.0.0 --no-browser --allow-root
出現如下信息說明安裝成功(注意先激活 安裝了jupyter的虛擬環境 再運行)
(pd_test) [root@67 .jupyter]# jupyter notebook --ip=0.0.0.0 --no-browser --allow-root [I 06:56:36.098 NotebookApp] 把notebook 服務cookie密碼寫入 /root/.local/share/jupyter/runtime/notebook_cookie_secret [I 06:56:36.499 NotebookApp] 啟動notebooks 在本地路徑: /usr/local/jupyter [I 06:56:36.499 NotebookApp] 本程序運行在: http://67.59.247.60.static.bjtelecom.net:8888/
[I 06:56:36.499 NotebookApp] 使用control-c停止此服務器並關閉所有內核(兩次跳過確認).
打開瀏覽器,輸入CentOS所在服務器的ip和端口號,輸入密碼,即可進入
輸入配置的密碼,就登錄進來了
step4:通過supervisord管理jupyter進程
使用step3的方式雖然可以訪問服務器的jupyter,但是只要一關閉啟動jupyter的終端窗口,jupyter就會關掉。
如果希望Jupyter長久運行,可以使用supervisord管理jupyter進程后台運行(或者nohup命令)。
沒有安裝過supervisord需要先安裝,我這里已經安裝過了,所以直接查看一下supervisord.conf現在的所在目錄
[root@67 ~]# find / -name supervisord.conf /etc/supervisord.conf
查看配置文件:
cat /etc/supervisord.conf
進入 cd /etc 目錄 找到supervisord.conf 配置文件 和 supervisord.d 文件夾,使用vim編輯supervisord.conf文件,拉到最底部我們可以看到

files = supervisord.d/*.ini 這句代碼說明它會加載supervisord.d文件夾中的所有.ini配置文件
在supervisord.d文件夾下新建文件jupyter.ini:
nano jupyter.ini
文件內容如下:
[program:jupyter] command=/root/.virtualenvs/pd_test/bin/jupyter notebook --ip=0.0.0.0 --no-browser --allow-root ; supervisor啟動命令,注意前面加上jupyter所在的python環境 directory=/usr/local/jupyter/ ; 項目的文件夾路徑 startsecs=10 ; 啟動時間 stopwaitsecs=60 ; 終止等待時間 autostart=true ; 是否自動啟動 autorestart=true ; 是否自動重啟 stdout_logfile=/usr/local/jupyter/logs/log.log ; log 日志 注意先在jupyter文件夾下新建好logs目錄 stderr_logfile=/usr/local/jupyter/logs/log.err ; 錯誤日志
保存文件:
[root@67 supervisord.d]# ls gotest.ini jupyter.ini
配置完成后,重新加載supervisor服務
[root@67 supervisord.d]# supervisorctl reload Restarted supervisord
啟動所有服務:
supervisorctl start all
或者:
supervisord -c /etc/supervisord.conf
接下來就可以訪問服務器上的jupyter了
參考文檔: