利用jupyterlab远程连接linux服务器使用python

1、首先需要在终端安装python,自己搜索一个教程安装以下python3即可;

2、$ pip install nbclassic==0.2.8

3、$ pip install jupyterlab==3

4、生成配置文件
$ jupyter lab --generate-config

5、设置密码
$ ipython
Python 3.9.12 (main, Apr 5 2022, 06:56:58)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.17.2 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from notebook.auth import passwd

In [2]: passwd()
Enter password: ##设置密码
Verify password: ##确认密码

‘argon2:argon2idv=19m=10240,t=10,p=8sfFNt20VAaBB7c+apueKUw$5QPCtac96sS+CZr3PUApVaQgWc’

复制下来,后边要用

In [3]: exit()

6、修改配置文件
vi ~/.jupyter/jupyter_lab_config.py c.ServerApp.allow_remote_access = True #远程访问 c.ServerApp.allow_root = True #使用root运行 c.ServerApp.ip = '*' #监听地址 c.ServerApp.port = 8989 #端口,随便设置 c.ServerApp.root_dir = '/XXX/pythonWorkspace/' #jupyterlab工作目录 c.ServerApp.password = 'argon2:argon2idv=19m=10240,t=10,p=8sfFNt20VAaBB7c+apueKUw5QPCtac96sS+CZr3PQgWc' #密码
c.ServerApp.open_browser = False #不打开浏览器

按ESC,:,wq保存退出
7、后台运行
nohup jupyter lab --allow-root > jupyter.log 2>&1 &

8、配置防火墙规则:

$ firewalld

$ firewall-cmd --permanent --add-port=8989/tcp

$ firewall-cmd --permanent --add-port=8989/udp

$ firewall-cmd --reload

这将打开 8989 端口,允许通过该端口访问 jupyter lab,这一步我觉得有点点重要,不然就不能在浏览器打开。
http://<服务器ip>:8989

参考:
1、基于jupyterlab远程连接linux服务器及使用screen后台运行python程序_哔哩哔哩_bilibili
2、linux服务器搭建之(三):在服务器上配置jupyter lab_jupyter lab服务器部署_李子树下mini的博客-CSDN博客

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

推荐阅读更多精彩内容