CentOS7系統(tǒng)部署Jupyter全流程解析
環(huán)境準(zhǔn)備與依賴安裝
1. 更新系統(tǒng)組件:sudo yum update -y
2. 安裝EPEL擴(kuò)展源:sudo yum install epel-release -y
3. 安裝Python3開發(fā)套件:sudo yum install python3-devel -y
Python虛擬環(huán)境配置
創(chuàng)建隔離環(huán)境:python3 -m venv ~/jupyter_env
激活虛擬環(huán)境:source ~/jupyter_env/bin/activate
Jupyter核心組件安裝
升級(jí)pip工具:pip install --upgrade pip
安裝JupyterLab:pip install jupyterlab
安裝Notebook擴(kuò)展:pip install notebook
SSL安全證書生成
創(chuàng)建證書目錄:mkdir ~/ssl && cd ~/ssl
生成密鑰文件:openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout jupyter.key -out jupyter.pem
配置文件定制
生成初始配置:jupyter notebook --generate-config
修改關(guān)鍵參數(shù):
c.NotebookApp.certfile = '/home/username/ssl/jupyter.pem' c.NotebookApp.keyfile = '/home/username/ssl/jupyter.key' c.NotebookApp.ip = 'localhost' c.NotebookApp.open_browser = False c.NotebookApp.port = 8888
系統(tǒng)服務(wù)配置
創(chuàng)建服務(wù)文件:sudo vi /etc/systemd/system/jupyter.service
[Unit] Description=Jupyter Notebook [Service] User=username WorkingDirectory=/home/username ExecStart=/home/username/jupyter_env/bin/jupyter-lab --config=/home/username/.jupyter/jupyter_notebook_config.py Restart=always [Install] WantedBy=multi-user.target
防火墻配置與啟動(dòng)驗(yàn)證
開放指定端口:sudo firewall-cmd --permanent --add-port=8888/tcp
重載防火墻規(guī)則:sudo firewall-cmd --reload
啟動(dòng)服務(wù):sudo systemctl enable --now jupyter.service
驗(yàn)證狀態(tài):sudo systemctl status jupyter.service
訪問與安全強(qiáng)化
瀏覽器訪問:https://服務(wù)器IP:8888
設(shè)置訪問密碼:jupyter notebook password
建議配置Nginx反向代理提升安全性