CentOS7搭建Jupyter | 服务器开发环境配置指南

CentOS7系统部署Jupyter全流程解析

环境准备与依赖安装

1. 更新系统组件:sudo yum update -y

2. 安装EPEL扩展源:sudo yum install epel-release -y

3. 安装Python3开发套件:sudo yum install python3-devel -y

Python虚拟环境配置

创建隔离环境:python3 -m venv ~/jupyter_env

激活虚拟环境:source ~/jupyter_env/bin/activate

Jupyter核心组件安装

升级pip工具:pip install --upgrade pip

安装JupyterLab:pip install jupyterlab

安装Notebook扩展:pip install notebook

SSL安全证书生成

创建证书目录:mkdir ~/ssl && cd ~/ssl

生成密钥文件:openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout jupyter.key -out jupyter.pem

配置文件定制

生成初始配置:jupyter notebook --generate-config

修改关键参数:

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

系统服务配置

创建服务文件: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

防火墙配置与启动验证

开放指定端口:sudo firewall-cmd --permanent --add-port=8888/tcp

重载防火墙规则:sudo firewall-cmd --reload

启动服务:sudo systemctl enable --now jupyter.service

验证状态:sudo systemctl status jupyter.service

访问与安全强化

浏览器访问:https://服务器IP:8888

设置访问密码:jupyter notebook password

建议配置Nginx反向代理提升安全性

寰宇互联服务器4核4G云服务器1元/月,网络稳定、抗DDos、国际BGP、性能强劲,十年服务经验QQ:97295700 微信:huanidc

阅读剩余
THE END