CentOS7.6 设置Jupyter Lab(anaconda)远程访问,以系统服务运行

安装jupyter lab过程不再赘述。

测试

设置所有本机所有IP均可访问,服务端口为8080,设置启动目录为/root/ipynbs

由于当前用户为root,出于安全考虑,jupyter lab需要设置--allow-root才能运行。

(base) [root@ecs-9e76 ~]# jupyter lab --ip=0.0.0.0 --port=8080 --notebook-dir='/root/ipynbs' --allow-root
[I 22:49:45.533 LabApp] JupyterLab extension loaded from /root/anaconda3/lib/python3.7/site-packages/jupyterlab
[I 22:49:45.533 LabApp] JupyterLab application directory is /root/anaconda3/share/jupyter/lab
[I 22:49:45.535 LabApp] Serving notebooks from local directory: /root/ipynbs
[I 22:49:45.535 LabApp] The Jupyter Notebook is running at:
[I 22:49:45.535 LabApp] http://ecs-9e76:8080/?token=5c5548b668f5eb1a3c188e9f2c047af3e0fccb111686801d
[I 22:49:45.535 LabApp]  or http://127.0.0.1:8080/?token=5c5548b668f5eb1a3c188e9f2c047af3e0fccb111686801d
[I 22:49:45.535 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 22:49:45.538 LabApp] No web browser found: could not locate runnable browser.
[C 22:49:45.538 LabApp] 
    To access the notebook, open this file in a browser:
        file:///root/.local/share/jupyter/runtime/nbserver-13713-open.html
    Or copy and paste one of these URLs:
        http://ecs-9e76:8080/?token=5c5548b668f5eb1a3c188e9f2c047af3e0fccb111686801d
     or http://127.0.0.1:8080/?token=5c5548b668f5eb1a3c188e9f2c047af3e0fccb111686801d

访问http://xx.xx.xx.xx:8080/?token=5c5548b668f5eb1a3c188e9f2c047af3e0fccb111686801d即可访问Jupyter Lab

设置密码访问

jupyter lab默认采用token访问,不够方便,设置采用密码访问。

输入jupyter notebook password,按提示输入密码。

密码文件保存在配置文件/root/.jupyter/jupyter_notebook_config.json中。

(base) [root@ecs-9e76 ~]# jupyter notebook password
Enter password: 
Verify password: 
[NotebookPasswordApp] Wrote hashed password to /root/.jupyter/jupyter_notebook_config.json
(base) [root@ecs-9e76 ~]# vi /root/.jupyter/jupyter_notebook_config.json
{
  "NotebookApp": {
    "password": "sha1:d933b9053eb0:55de430361c7686fdc3ce5462af9804637ead074"
  }
}

修改配置文件

前面测试中直接用参数配置IP、端口等信息,为了便于使用,可在配置文件中做相关配置。

jupyter lab的配置文件有两种:jupyter_notebook_config.pyjupyter_notebook_config.json

两个配置文件选择其一即可。

1. 通过jupyter_notebook_config.py文件

  • 生成配置文件jupyter_notebook_config.py
    输入jupyter notebook --generate-config命令,生成jupyter_notebook_config.py文件。
(base) [root@ecs-9e76 ~]# jupyter notebook --generate-config
Writing default config to: /root/.jupyter/jupyter_notebook_config.py
  • 修改配置文件
(base) [root@ecs-9e76 ~]# vi  /root/.jupyter/jupyter_notebook_config.py

修改配置文件,确保以下选项为未注释状态:

c.NotebookApp.ip = '*' 
c.NotebookApp.port = 8080
c.NotebookApp.open_browser = False 
c.NotebookApp.notebook_dir = '/root/ipynbs' 
c.NotebookApp.allow_root = True

2. 通过jupyter_notebook_config.json文件

注意,jupyter_notebook_config.json文件原始内容为:

{
  "NotebookApp": {
    "password": "sha1:d933b9053eb0:55de430361c7686fdc3ce5462af9804637ead074"
  }
}

修改上述配置后,对应的jupyter_notebook_config.json文件内容如下:

(base) [root@ecs-9e76 ~]# vi /root/.jupyter/jupyter_notebook_config.json
{
  "NotebookApp": {
    "password": "sha1:d933b9053eb0:55de430361c7686fdc3ce5462af9804637ead074",
    "ip" : "*" ,
    "port" : 8080,
    "open_browser" : false ,
    "notebook_dir" : "/root/ipynbs" ,
    "allow_root": true
  }
}

运行效果如下:

(base) [root@ecs-9e76 ~]# jupyter lab
[W 00:47:39.022 LabApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 00:47:39.028 LabApp] JupyterLab extension loaded from /root/anaconda3/lib/python3.7/site-packages/jupyterlab
[I 00:47:39.028 LabApp] JupyterLab application directory is /root/anaconda3/share/jupyter/lab
[I 00:47:39.030 LabApp] Serving notebooks from local directory: /root/ipynbs
[I 00:47:39.030 LabApp] The Jupyter Notebook is running at:
[I 00:47:39.030 LabApp] http://ecs-9e76:8080/
[I 00:47:39.030 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

以系统服务形式运行jupyter lab

创建/etc/systemd/system/jupyter.service文件,文件内容如下:

[root@ecs-9e76 ~]# vi /etc/systemd/system/jupyter.service
[Unit]
Description=jupyterlab
After=network.service

[Service]
ExecStart=/root/anaconda3/bin/jupyter lab 

[Install]
WantedBy=default.target

启动服务:systemctl start jupyter

[root@ecs-9e76 ~]# systemctl start jupyter

开机启动:systemctl enable jupyter

[root@ecs-9e76 ~]# systemctl enable jupyter
Created symlink from /etc/systemd/system/default.target.wants/jupyter.service to /etc/systemd/system/jupyter.service.
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在CentOS 7.6上设置NTP服务器,您可以按照以下步骤进行操作: 1. 编辑NTP配置文件:使用命令`vim /etc/ntp.conf`打开NTP配置文件。 2. 添加以下内容到配置文件中: ``` restrict 172.25.10.6 nomodify notrap nopeer noquery restrict 172.25.10.1 mask 255.255.255.0 nomodify notrap server 127.127.1.0 fudge 127.127.1.0 stratum 10 ``` 其中,172.25.10.6是本机IP地址,172.25.10.1是网关地址。 3. 保存并关闭文件。 4. 重启NTP服务并开启相关端口:使用命令`systemctl restart ntpd`重启NTP服务。由于NTP服务使用UDP协议,需要开启123端口,可以使用以下命令添加防火墙规则: ``` firewall-cmd --permanent --zone=public --add-port=123/udp firewall-cmd --reload ``` 5. 设置NTP服务自启动:使用命令`systemctl enable ntpd`设置NTP服务系统启动时自动启动。 6. 进行NTP服务器测试:可以使用命令`ntpq -p`检查NTP服务器是否正常工作。您应该会看到一些关于时间同步源的输出。 通过以上步骤,您就可以在CentOS 7.6上成功设置NTP服务器了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [CentOS7.6搭建NTP服务器](https://blog.csdn.net/weixin_38467835/article/details/106194413)[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_2"}}] [.reference_item style="max-width: 50%"] - *3* [如何在CentOS设置NTP服务器](https://download.csdn.net/download/weixin_38619207/14065557)[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_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值