jupyterhub 安裝配置

安裝

  • 安裝 anaconda3, 國內有代理,見這裏
  • 安裝 sudo /opt/anaconda3/bin/pip install jupyterhub
  • 參考github上jupyterhub的說明, 在/opt/nodejs 目錄中安裝 npm install configurable-http-proxy

配置

  • jupyterhub配置文件
sed '/^#/d;/^$/d' /etc/jupyterhub/jupyterhub.py     
c.JupyterHub.port=8888
c.JupyterHub.proxy_cmd = ['/opt/nodejs/bin/configurable-http-proxy',]
c.Authenticator.admin_users =['zkk','xyq']
c.JupyterHub.base_url = '/jupyter'
  • 啓動腳本,注意添加路徑
xyq@xyq-linux ~/.jupyter $ cat  run_hub          
#!/bin/bash
export PATH=/opt/anaconda3/bin:/usr/lib/rstudio-server/bin/pandoc:$PATH
cd /home/xyq/.jupyter
#nohup  jupyterhub --config=/etc/jupyterhub/jupyterhub.py --no-ssl > run_hub.log 2>&1 &
jupyterhub --config=/etc/jupyterhub/jupyterhub.py --no-ssl
  • 開機啓動配置
sudo cat  /etc/systemd/system/jupyterhub.service  
[Unit]
Description=Jupyterhub
After=syslog.target network.target

[Service]
User=root
ExecStart=/home/xyq/.jupyter/run_hub

[Install]
WantedBy=multi-user.target
  • 啓動
sudo systemctl enable jupyterhub # 開機自啓動
sudo systemctl daemon-reload     # 加載配置文件
sudo systemctl start jupyterhub  # 啓動
sudo journalctl -u jupyterhub    # 查看log
  • log操做, 更多命令html

    sudo journalctl --since yesterday -u jupyterhub
      sudo journalctl --vacuum-size=1G
      sudo journalctl --vacuum-time=1days

nginx 配置

sed '/ *#/d;/^$/d' /etc/nginx/sites-enabled/default    
 upstream  ipython_server  {
     server  127.0.0.1:8888;
 }
 upstream  r_server  {
     server  127.0.0.1:800;
 }
server {
        listen 80 default_server;
        listen [::]:80 default_server;
        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;
        server_name _;
        location / {
                try_files $uri $uri/ =404;
        }
        location /jupyter/ {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $host;
    
            proxy_pass http://ipython_server;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
      location  /r/  {
              rewrite  ^/r/(.*)$  /$1  break;
              proxy_pass  http://127.0.0.1:800;
              proxy_redirect  http://127.0.0.1:800/  $scheme://$host/r/;
              proxy_set_header  X-Real-IP  $remote_addr;
              proxy_http_version  1.1;
              proxy_set_header  Upgrade  $http_upgrade;
              proxy_set_header  Connection  "upgrade";
      }
}
相關文章
相關標籤/搜索