DL01 远程启动jupyterlab详细教程

安装jupyterlab并远程启动

# 前提:已经安装好mamba
mamba create -n deepl python=3.9
mamba activate deepl
mamba install -c conda-forge jupyterlab

# 上面安装完成后,在环境中启动python,生成 hash 密码
$ python
>>> from jupyter_server.auth import passwd
>>> passwd()
# 依据提示输入两遍设置的密码:test1(自行设置并记住)

# 从而会得到一个类似于下面的密钥
# 'argon2:$argon2ixxxxxxxxxxxxxxvRPQTxxxxU'

# 退出python界面,生成配置文件
jupyter-lab --generate-config

# 修改 ~/.jupyter/jupyter_lab_config.py 中的以下内容:
c.ServerApp.allow_remote_access = True
c.ServerApp.ip = '*'
# 启动时不自动打开浏览器
c.ServerApp.open_browser = False
c.LabServerApp.open_browser = False
c.ExtensionApp.open_browser = False
c.LabApp.open_browser = False
# 添加刚刚生成的密钥
c.ServerApp.password = 'argon2:$argon2ixxxxxxxxxxxxxxvRPQTxxxxU'
# 根据个人需要修改端口号(默认 8888)
c.ServerApp.port = 8888

上述修改完成后,可以在后台窗口启动jupyterlab

# 启动后台窗口
screen -S jupyter
jupyter lab --no-browser --ip=0.0.0.0 --port=8888 --allow-root
# 启动后会生成两个链接
'''
    To access the server, open this file in a browser:
        file:///home/username/.local/share/jupyter/runtime/jpserver-7703-open.html
    Or copy and paste one of these URLs:
        http://manager:8888/lab?token=a225xxxa2f5d98ba77a21d0
        http://127.0.0.1:8888/lab?token=a225xxxa2f5d98ba77a21d0
'''
# token就在后面:a225xxxa2f5d98ba77a21d0

使用Mobaxterm的Tunneling功能进行端口隧道转发(假设服务器ip为127.0.0.1)


或者cmd / powershell窗口运行ssh进行端口转发(注意8989在本地未被占用),窗口需保持运行

ssh -N -L localhost:8989:localhost:8888 username@127.0.0.1
# username和IP需要更换为你实际使用的

打开本地浏览器,地址框输入以下网址

http://localhost:8989/lab
# 需要输入token进入(上述的a225xxxa2f5d98ba77a21d0)

# 或者直接输入以下命令,可直接登录
http://localhost:8989/lab?token=a225xxxa2f5d98ba77a21d0
无法远程启动可能原因
  • 服务器端8888入口tcp或防火墙未开放
  • 本地8989端口被占用

其余报错可以询问AI如Deepseek、Kimi等


end~

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。