JupyterLab远程访问配置方法

准备环境

  • Ubuntu 18.Ubuntu 18.04.3 LTS
  1. 下载 Anaconda3-2020.11-Linux-x86_64.sh 安装包,并执行安装命令:
chmod u+x Anaconda3-2020.11-Linux-x86_64.sh #加可执行权限
bash Anaconda3-2020.11-Linux-x86_64.sh

确定安装并初始化:

Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]
[no] >>> yes
  1. 启动 指定虚拟环境
conda activate nlp_venv
  1. 安装 jupyterlab 和 ipython:
# 下载jupyterlab
pip install jupyterlab
# 安装ipython
pip install ipython
  1. 需要用ipython命令生成秘钥,启动ipython:
ipython

执行命令生成秘钥:

In [1]: from notebook.auth import passwd
In [2]: passwd() 
Enter password: 
Verify password: 
Out[2]: 'sha1:f704b702aea2:01e2bd991f9c720812345607810927'
  1. 产生jupyterlab配置文件:
jupyter lab --generate-config

修改配置文件:

vi /root/.jupyter/jupyter_notebook_config.py

更改内容如下:

# 将ip设置为*,意味允许任何IP访问
c.NotebookApp.ip = '*'
# 这里的密码就是上边生成的字符串
c.NotebookApp.password = 'sha1:f704b702aea2:01e2bd991f9c720812345607810927'
# 服务器上并没有浏览器可以供Jupyter打开 
c.NotebookApp.open_browser = False 
# 监听端口设置为8888或其他自己喜欢的端口 
c.NotebookApp.port = 8888
# 允许远程访问 
c.NotebookApp.allow_remote_access = True
  1. 接下来输入jupyter lab启动jupyter服务即可:
jupyter lab --allow-root

# 后台运行
nohup jupyter lab --allow-root &
[W 22:51:10.568 LabApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 22:51:10.589 LabApp] [jupyter_nbextensions_configurator] enabled 0.4.1
[I 22:51:10.592 LabApp] JupyterLab extension loaded from /home/root/.conda/envs/nlp_venv/lib/python3.6/site-packages/jupyterlab
[I 22:51:10.592 LabApp] JupyterLab application directory is /home/root/.conda/envs/nlp_venv/share/jupyter/lab
[I 22:51:10.594 LabApp] Serving notebooks from local directory: /home/hejing/py_project
[I 22:51:10.595 LabApp] Jupyter Notebook 6.1.4 is running at:
[I 22:51:10.595 LabApp] http://example.com:8888/
[I 22:51:10.595 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
  1. 打开登录页面


    jupyterlab login

你可能感兴趣的:(JupyterLab远程访问配置方法)