使用公有云快速搭建jupyter实验环境

9 篇文章 2 订阅

安装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 &
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值