How to set up a jupyterlab in vps


I’m very sad that i left my laptop at school,but I can’t have fun all the time,So I rent a vps which have high performance than I have and set up a jupyterlab on it,It’s very nice that I can play some funny things on it.I have tried to use a Cloud Studio on Tencent,it will let us thought is my data safe enough?


install jupyterlab

pip3 install jupyterlab

setup login password

  • create a python document named,write as follows:

    from notebook.auth import passwd
  • you will get a hash password when you input your password as the runs

  • generate a config,your will get the config address when it finished

    jupyter notebook --generate-config
  • change the value in config as follows,you can ingore the run script –allow-root If you set allow_root up is true there;

    c.NotebookApp.allow_root = True
    c.NotebookApp.open_browser = False
    c.NotebookApp.password = 'your hash password you generate!'

config nginx

You can ignore this steps if you wanna use ip to access your service,I just show the important things here,for my vps security!

    location / {
        proxy_pass; # you can change your port if it was used by another service !
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_http_version 1.1;
        proxy_redirect off;
        proxy_buffering off;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_read_timeout 86400;


You can change some value if you don’t wanna use in your run shell.

value function
ip run in localhost
port same with nginx config
allow-root run with root authority
nohup jupyter lab --ip= --port=999 --allow-root >> jupyter.log  2>&1 &

protect process

It’s very nice if you need to ensure jupyterlab is always run in vps

#Process Name

while true ; do
    #get process informatinon if some wrong happens!you can put it into a log for your check!
    Process=`ps -ef | grep "${PRO_NAME}" | grep -v grep | grep -v '' | grep -v '[${PRO_NAME}]'`
#     echo "$T : $Process"
#get the running process number 
    NUM=`ps -ef | grep  "${PRO_NAME}" | grep -v grep | grep -v '' | grep -v '[${PRO_NAME}]' | wc -l `
#    echo "$T : It has started !"
#      echo "${NUM}"
    #It will start if it small than 1
    if [ "${NUM}" -lt "1" ];then
        echo "$T : $Process"
        echo "$T : ${PRO_NAME} was killed"
        # jupyterlab running DIR
        cd /home/lab
        # you should change for your condition
        nohup jupyter lab --ip= --port=999 --allow-root >> jupyter.log  2>&1 &
        echo "$T : ${PRO_NAME} restart ! "
        sleep 10s
    #it will kill all same process and restart if it lager than 1
    elif [ "${NUM}" -gt "1" ];then
        echo "$T : $Process"
        echo "$T : more than 1 ${PRO_NAME},killall ${PRO_NAME}"
        ps -ef | grep $PRO_NAME | grep -v grep | grep -v '' | cut -c 9-15 | xargs kill -9
        cd /home/lab
        nohup jupyter lab --ip= --port=999 --allow-root >> jupyter.log  2>&1 &
        echo "$T : killall and restart!"
        sleep 10s
# it will take some time to run jupyterlab,so we shoud deny time to get right number
    sleep 30s
exit 0

除非特别说明,本博客所有作品均采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可。转载请注明转自-

No comments yet.

Write a comment:

April 2020