安装npm和nodejs

apt install npm nodejs
npm install -g n
n stable
pip install jupyterhub
sudo npm install -g configurable-http-proxy 
pip install notebook
pip install jupyterhub-dummyauthenticator

测试是否安装成功

jupyterhub -h
configurable-http-proxy -h

安装jupyterlab

pip install jupyterlab

配置Jupyterhub

生成配置文件

mkdir -p /etc/jupyterhub
cd /etc/jupyterhub
jupyterhub --generate-config
nano jupyterhub_config.py

nano打开之后,在文件开头加入如下内容

###jupyterhub_config.py
# 新增配置属性,建议直接加在文件开头就好
## 启用JupyterLab
c.Spawner.default_url = '/lab'
## 所有IP都可以访问
c.JupyterHub.ip = '*'
c.JupyterHub.port = 8888
c.Spawner.ip = '127.0.0.1'
c.PAMAuthenticator.encoding = 'utf8'
## 指定可以访问的Ubuntu用户
c.Authenticator.whitelist = {'root','user1','user2'}
c.LocalAuthenticator.create_system_users = True
## 指定管理员用户
c.Authenticator.admin_users = {'root'}
c.JupyterHub.authenticator_class = 'dummyauthenticator.DummyAuthenticator'
c.JupyterHub.statsd_prefix = 'jupyterhub'

保存并退出

搜索spawn.py并在get_args处新增如下一行

(base) root@iZj6c49ru1twji7lz73oe1Z:/etc/jupyterhub# find / -name spawner.py
/root/anaconda3/lib/python3.7/site-packages/jupyterhub/spawner.py
 def get_args(self):
        """Return the arguments to be passed after self.cmd

        Doesn't expect shell expansion to happen.
        """
        args = []
        args.append('--allow-root')
        if self.ip:
            args.append('--ip=%s' % _quote_safe(self.ip))

启动jupyter

jupyterhub --config=/etc/jupyterhub/jupyterhub_config.py --no-ssl

在本地机器开启转发

ssh -N -f -L localhost:9999:localhost:8888 -p 22 xxx@ip

然后在本地9999端口即可正常使用

nohup jupyter notebook &
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐