jupyterhub 安装配置

安装

  • 安装 anaconda3, 从https://www.anaconda.com/distribution/下载. 国内有代理,见这里 但不如官网新.
  • 安装 sudo /opt/anaconda3/bin/pip install jupyterhub
  • 参考github上jupyterhub的说明, 在/opt/nodejs 目录中安装 npm install configurable-http-proxy

配置

  • 以下前两个配置更新为:
xyq@xyq-linux:~/.jupyter$ sed '/^#/d;/^$/d' /etc/jupyterhub/jupyterhub_config.py
c.JupyterHub.base_url = '/jupyter'
c.Authenticator.admin_users = set(['zkk','xyq'])

xyq@xyq-linux:~/.jupyter$ cat run_hub
#!/bin/bash
export PATH=/opt/anaconda3/bin:/opt/nodejs/node_modules/.bin:$PATH
cd /home/xyq/.jupyter
jupyterhub --config=/etc/jupyterhub/jupyterhub_config.py --port=8888 --no-ssl


  • 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操作, 更多命令

      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;
        root /opt/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";
      }
}
posted @ 2016-08-06 14:54  bregman  阅读(10474)  评论(3编辑  收藏  举报