centos利用conda搭建jupyter
@ 晚风 · Thursday, Mar 24, 2022 · 2 分钟阅读 · 更新于 3月 24, 2022

centos利用conda搭建jupyter

1、官网下载conda安装包

2、上传云服务器(腾讯云直接scp)

3、sh Anaconda3-xxxx-Linux-x86_64.sh

4、重新加载环境变量

# 如果profile没有export PATH=/usr/anaconda3/bin:$PATH则添加

source /etc/profile

5、conda –version或conda -V 查看是否安装成功

6、conda安装jupyter-nootbook

conda install jupyter notebook

7、生成配置文件

jupyter notebook --generate-config # 建立配置文件

8、修改配置

# 上一步生成的配置文件一般在 /root/.jupyter/jupyter_notebook_config.py
vim jupyter_notebook_config.py

注意去掉前面的#
c.NotebookApp.port = 20001 # 自定义端口
c.NotebookApp.ip = '你的服务器公网IP' #或填”*”允许ip访问
c.NotebookApp.open_browser = False
修改Jupyter文件默认存储路径
c.NotebookApp.notebook_dir = '/data/'

9、为jupyter生成密码

jupyter notebook password

10、修改云服务器安全策略

​ 创建安全组/防火墙规则

​ 自定义规则-开放你自定义的jupyter端口 网段应是你出口网段

11、测试jupyter运行

jupyter notebook --allow-root --ip=0.0.0.0
# 然后 服务器ip:port 访问 密码登陆查看是否成功

12、jupyter启动脚本并增加权限

#!/bin/bash
jupyter notebook --allow-root --ip=0.0.0.0

​ chmod +x run-jupyter-notebook.sh

12、下载supervisor并配置jupyter启动程序

yum install -y supervisor
pip3 install supervisor

vim /etc/supervisord.d/run-jupyter-notebook.ini

[program:jupyter-notebook]
directory= directory-path # 这个是你配置的 c.NotebookApp.notebook_dir 路径
command=/bin/bash -E -c shell-path/run-jupyter-notebook.sh # 上一步配置的启动脚本路径
autostart=true
autorestart=true
stopsignal=INT
stopasgroup=true
killasgroup=true
user=root

13、启动supervisor并测试

>> supervisord
>> supervisorctl status

访问查看是否正常

14、利用nginx代理jupyter服务

server {
       listen      443 ssl ;
        server_name jupyter.starrye.com;
       index index.html index.htm index.jsp ;

       access_log  off;

       ssl_certificate      /etc/nginx/cert/jupyter.starrye.com.pem; # 证书地址
       ssl_certificate_key /etc/nginx/cert/jupyter.starrye.com.key; # 证书地址
       ssl_session_timeout  5m ;
       ssl_protocols  TLSv1 TLSv1.1 TLSv1.2 ;
       ssl_ciphers  HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM ;
       ssl_prefer_server_ciphers   on ;
       add_header Content-Security-Policy upgrade-insecure-requests;

        location / {
            proxy_pass http://127.0.0.1:20001;
            access_log off;
	    proxy_http_version 1.1;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            client_max_body_size 100m;
            proxy_connect_timeout 500s;
            proxy_read_timeout 500s;
            proxy_send_timeout 500s;
            proxy_redirect off;
        }
	location ~ /api/kernels/ {
            proxy_pass            http://127.0.0.1:20001;
            proxy_set_header      Host $host;
            # websocket support
            proxy_http_version    1.1;
            proxy_set_header      Upgrade "websocket";
            proxy_set_header      Connection "Upgrade";
            proxy_read_timeout    86400;
        }
        location ~ /terminals/ {
            proxy_pass            http://127.0.0.1:20001;
            proxy_set_header      Host $host;
            # websocket support
            proxy_http_version    1.1;
            proxy_set_header      Upgrade "websocket";
            proxy_set_header      Connection "Upgrade";
            proxy_read_timeout    86400;
        }
}

关于我

❤️

姓名: lwz


性别: 男


年龄: 29


星座: 摩羯座


职业: python工程师


爱好: 秋、ps5、运动


主要的技术栈是:

  • python
  • 自动驾驶仿真验证

学习网站: leetcode


公司: 国科础石


– 2025 年 2 月 25 日更新

我的一些开源项目

等等?项目呢?不会没有吧??

其他

如果你喜欢我的开源项目或者它们可以给你带来帮助,可以赏一杯咖啡 ☕ 给我。~

It is better to attach some information or leave a message so that I can record the donation 📝, thank you very much 🙏.

社交链接