zl程序教程

您现在的位置是:首页 >  大数据

当前栏目

阿里云ECS 配置jupyter notebook及远程连接

配置阿里连接 远程 Jupyter ECS Notebook
2023-09-11 14:21:24 时间

注意如果是从docker启动的jupyter,需要docker启动容器时添加-p 6008:6008参数做好端口映射。
首先在服务器上创建配置:

jupyter notebook --generate-config

#可以看到如下信息
Writing default config to: /root/.jupyter/jupyter_notebook_config.py

然后更改配置文件/root/.jupyter/jupyter_notebook_config.py,添加如下内容保存退出:

c = get_config()
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 6008
c.NotebookApp.allow_remote_access = True

输入jupyter notebook password设置访问密码:

root@040bc8af4c78:/# jupyter notebook password
Enter password:
Verify password:
[NotebookPasswordApp] Wrote hashed password to /root/.jupyter/jupyter_notebook_config.json

访问方法1:

使用ssh端口转发,无需开放主机web端口。

  1. 首先启动jupyter notebook
jupyter notebook --allow-root
  1. 本地ssh命令实现端口转发:
ssh -N -f -L localhost:8818:localhost:6008 remote_user@remote_host

如果mac在~/.ssh/config中配置了远程主机名和证书访问,例如

Host aliyun
        HostName        118.118.118.118
        User root
        Port 22
        IdentityFile ~/.ssh/id_rsa

那么上述命令可以简化为:

ssh -N -f -L 127.0.0.1:8818:127.0.0.1:6008 aliyun

参数解释: -N 告诉SSH没有命令要被远程执行; -f 告诉SSH在后台执行; -L 是指定port forwarding的配置,远端端口是6008,本地的端口号的8818

然后浏览器访问:
http://localhost:8818
or
http://127.0.0.1:8818
就会出现jupyter登录界面,输入密码即可登录。
在这里插入图片描述

访问方法2:

配置阿里云安全组,防火墙开启6008端口。
在这里插入图片描述
启动jupyter

jupyter notebook --allow-root

客户端浏览器访问服务器域名或者IP:

hostname:6008
ip:6008

就会出现jupyter登录界面,输入密码即可登录。
在这里插入图片描述