Anaconda集成的jupyterlab设置远程访问

2021-01-28  本文已影响0人  惜鸟

概述

我有一台远程linux服务器,资源比较丰富,想用来做一些机器学习的实验,所以打算在远程Linux服务器上面安装Anaconda,Anaconda集成了许多python库并且集成了jupyter ,使用比较方便,并且实现jupyterlabde 远程访问。

一、下载Anaconda

这里推荐使用清华镜像站下载,在国内下载速度比较快。
清华镜像站地址:https://mirrors.tuna.tsinghua.edu.cn/

image.png image.png

复制下载地址,在linux系统使用wget命令下载到当前目录:

wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2020.11-Linux-x86_64.sh

下载成功后,通过sh命令安装Anaconda:

sh Anaconda3-2020.11-Linux-x86_64.sh

可以根据提示进行一些自定义配置,我这里全部选择的默认配置。
安装完成之后,输入conda,如果提示找不到命令,则需要在/etc/profile文件中配置conda的路径:

# 打开配置文件
vim /etc/profile
# 在末尾添加如下内容
export CONDA_HOME=/root/anaconda3
export PATH=$PATH:$CONDA_HOME/bin

# 运行如下命令是配置生效
source /etc/profile

二、配置jupyterlab

使用如下命令生成jupyter配置文件/root/.jupyter/jupyter_notebook_config.py:

jupyter lab --generate-config

修改配置文件:

vim /root/.jupyter/jupyter_notebook_config.py

更改内容如下:

## The directory to use for notebooks and kernels.
#  Default: ''
# notebooks 和 内核使用的目录,默认为空,如果自定义目录,需要先创建该目录
c.NotebookApp.notebook_dir = '/root/jupyterproject'

## The IP address the notebook server will listen on.
#  Default: 'localhost'
# notebook 服务端监听的ip地址,默认监听本机,设置为 “*”,表示监听所有地址
c.NotebookApp.ip = '*'

## Whether to open in a browser after starting. The specific browser used is
#  platform dependent and determined by the python standard library `webbrowser`
#  module, unless it is overridden using the --browser (NotebookApp.browser)
#  configuration option.
#  Default: True
# notebook 启动时是否打开浏览器,默认为 True ,这里设置为 False
c.NotebookApp.open_browser = False

## Hashed password to use for web authentication.
#  
#  To generate, type in a python/IPython shell:
#  
#    from notebook.auth import passwd; passwd()
#  
#  The string should be of the form type:salt:hashed-password.
#  Default: ''
# 设置登录密码
c.NotebookApp.password = ''

#  Local IP addresses (such as 127.0.0.1 and ::1) are allowed as local, along
#  with hostnames configured in local_hostnames.
#  Default: False
# 是否允许远程访问
c.NotebookApp.allow_remote_access = True

创建修改内容中的自定义目录:

mkdir /root/jupyterproject

通过如下命令在后台启动jupyter notebook:

nohup jupyter lab --allow-root &

通过如下命令查看启动日志

tail -100f nohup.out

输出日志如下:

[W 10:43:30.339 LabApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 10:43:30.340 LabApp] The port 8888 is already in use, trying another port.
[I 10:43:30.344 LabApp] JupyterLab extension loaded from /root/anaconda3/lib/python3.8/site-packages/jupyterlab
[I 10:43:30.344 LabApp] JupyterLab application directory is /root/anaconda3/share/jupyter/lab
[I 10:43:30.346 LabApp] Serving notebooks from local directory: /root/jupyterproject
[I 10:43:30.346 LabApp] Jupyter Notebook 6.1.4 is running at:
[I 10:43:30.346 LabApp] http://node5:8888/?token=4221ab1097810c1b1e23ccf5c5ac22a9f36295c1c0057b00
[I 10:43:30.346 LabApp]  or http://127.0.0.1:8888/?token=4221ab1097810c1b1e23ccf5c5ac22a9f36295c1c0057b00
[I 10:43:30.346 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 10:43:30.349 LabApp] 

通过浏览器即可访问登录:


image.png
上一篇下一篇

猜你喜欢

热点阅读