jupyter远程服务器配置以及服务器开机自启

一、anaconda安装

1、下载anaconda安装包
[清华镜像网](https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/)`
2、命令安装
bash Anaconda3-5.2.0-Linux-x86_64.sh
pip install jupyterlab

二、配置jupyter

1、生成配置文件
a.  jupyter --paths
  查看.jupyter目录下是否有jupyter_notebook_config.py,
  如果没有,shell运行
  jupyter notebook --generate-config(生成jupyter_notebook_config.py,该命令执行之后会显示对应的文件路径)
  
b.  vim jupyter_notebook_config.py(修改配置)
2、配置文件修改
2.1 password生成
# ipython进入代码行,输入一下两行代码以及对应的密码生成秘闻
(dev37) mashunda@ip-192-168-0-35 project % ipython
Python 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 05:59:23) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.33.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from notebook.auth import passwd
   ...: passwd()
Enter password: 
Verify password: 
Out[1]: 'argon2:$argon2id$v=19$m=10240,t=10,p=8$RPFTJPYMgIgpj9OaLZQ9Dg$81axqbnxoIBCwgxy2SGqdPp7nBM+0ab16oBJkp1bA/A'

2.2 jupyter_notebook_config.py中修改的相关的内容
# Nginx访问时会出现跨域访问,需要在这里允许
c.NotebookApp.allow_origin = '*'
# 禁止随意修改密码
c.NotebookApp.allow_password_change = False
# 是否允许远程访问
c.NotebookApp.allow_remote_access = True
# IP
c.NotebookApp.ip = '0.0.0.0'
# 端口
c.NotebookApp.port = 9820
# 工作目录
c.NotebookApp.notebook_dir = '/jupyter/'
# 启动Jupyter Notebook之后是否打开浏览器
c.NotebookApp.open_browser = False
# 客户端打开Jupyter Notebook的密码哈希值
c.NotebookApp.password = 'sha1:7e9d8d4722c3:aa0a16fcf06b44ecbf208a3172af65f4d57163da'

3、启动
# 指定配置文件路径: /home/ubuntu/.jupyter/jupyter_lab_config.py: 改为自己的配置文件路径
nohup jupyter-lab --config /home/ubuntu/.jupyter/jupyter_lab_config.py --allow-root>/mnt/sdma/jupyter/develop37.txt>/mnt/sdma/jupyter/develop37_jupyter.txt 2>&1 &

三、配置开机自启

1、编写自启脚本
#!/bin/bash
nohup /home/ubuntu/anaconda3/envs/develop37/bin/jupyter-lab --config /home/ubuntu/.jupyter/jupyter_lab_config.py --allow-root>/mnt/sdma/jupyter/develop37.txt>/mnt/sdma/jupyter/develop37_jupyter.txt 2>&1 &
2、开发自启服务(自启服务的路径: linux服务器一般都是该路径:/etc/systemd/system/)
[Unit]
Description=jupyter-lab
After=network.target


[Service]
ExecStart=/opt/jupyter.sh 


[Install]
WantedBy=multi-user.target

(三.1中的自启脚本已经加了#!/bin/bash,所有ExecStart直接文件全路径就可以启动)

2.1 自启服务内容解释:
[Unit]:服务的说明
Description:描述服务
After:描述服务类别

[Service]服务运行参数的设置
Type=forking            是后台运行的形式
ExecStart               为服务的具体运行命令
ExecReload              为服务的重启命令
ExecStop                为服务的停止命令
PrivateTmp=True         表示给服务分配独立的临时空间

注意:启动、重启、停止命令全部要求使用绝对路径

3、启动并查看状态
systemctl enable rc-local
systemctl start rc-local.service  #启动服务
systemctl stop rc-local.service  #暂停服务
systemctl status rc-local.service #查看状态
systemctl daemon-reload # 重新加载自启服务

执行成功的话会如下显示
在这里插入图片描述

4、如果状态不是success,则说明自启服务有bug,大概率是ExecStart启动命令有问题
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
配置Jupyter远程连接服务器,你可以按照以下步骤进行操作: 1. 在服务器上安装AnacondaJupyter Notebook。你可以使用引用中提供的方法来安装Anaconda。 2. 在服务器启动Jupyter Notebook服务。你可以在终端中运行命令"jupyter notebook"来启动服务。 3. 在服务器上设置密码。运行命令"jupyter notebook password",然后按照提示输入密码并确认。 4. 在服务器配置Jupyter Notebook的配置文件。运行命令"jupyter notebook --generate-config"来生成配置文件。然后,使用编辑器打开配置文件并进行相应的配置。 5. 在服务器配置Jupyter Notebook允许远程访问。在配置文件中找到并修改"c.NotebookApp.ip"和"c.NotebookApp.port"的值,将其改为服务器的IP地址和希望使用的端口号。 6. 在服务器启动Jupyter Notebook服务,并确保防火墙允许该端口的访问。 7. 在本地浏览器中输入服务器的IP地址和端口号,然后按下回车键。 8. 输入之前设置的密码,然后登录到Jupyter Notebook。 现在,你可以在本地浏览器中通过Jupyter Notebook来远程连接服务器了。请记住,确保服务器和本地机器在同一网络中,并且你具有服务器的访问权限。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [jupyter配置远程访问服务器](https://blog.csdn.net/jokerxsy/article/details/107594369)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [Jupyter 远程连接服务器](https://blog.csdn.net/weixin_43913261/article/details/124648150)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值