Centos上安装 Jupyter NoteBook

//本文参考多位网友文
参考文献:

 https://blog.csdn.net/calorand/article/details/83243227
https://blog.csdn.net/liangpingguo/article/details/106098907?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.channel_param
https://zhuanlan.zhihu.com/p/44405596

感谢以上网友!

1、安装Jupyter Notebook库
$ pip3 install jupyter   #或pip install jupyter


2、生成Jupyter Notebook配置文件
$ jupyter notebook --generate-config   #注意配置文件位置,等会儿要用

3、设置jupyter notebook密码,用于登录Jupyter。

$ python3    #打开python终端,输入以下:

>> from IPython.lib import passwd
>>passwd()
Enter password: 
Verify password: 

'sha1:5486ada2011b:2106e8bf94c8eXXXXXXXXX'   #这是加密的密码复制下来  


4、设置服务器配置文件

$ vim   root/.jupyter/jupyter_notebook_config.py   #就是上一次指出的配置文件位置
####修改以下,前的#要删除

c.NotebookApp.ip = '*'  #所有IP都能访问
c.NotebookApp.port = 8888 #端口
c.NotebookApp.open_browser = False #不在服务器上直接打开浏览器
c.NotebookApp.password = 'sha1:5486ada2011b:2106e8bf94c8eXXXXXXXXX'  #就是上面提到的密码
c.NotebookApp.notebook_dir = '/root/jupyter_projects'     #这里是设置Jupyter的根目录
c.NotebookApp.allow_root = True   #允许以root权限启动jupyter 


5、手动启动Jupyter 远程服务器

$ jupyter notebook --allow-root   #没有后面的参数不成功启动  Ctrl+C 关闭服务

6、设置jupyter服务(开机重启)

(1)进入目录   cd /usr/lib/systemd/system/
(2)新建文件   vi myjupyter.service
(3)文件内容以下

 

#chmod a+x jupyter.service
#systemctl daemon-reload
#systemctl start jupyter.service
#开启此服务后,kill杀不死,因为Restar开启了;
#关闭时用systemctl stop jupyter.service
#ExecStart后的脚本要加/bin/bash,参考https://stackoverflow.com/questions/45776003/fixing-a-systemd-service-203-exec-failure-no-such-file-or-directory

[Unit]
Description = Start jupyter notebook server

[Service]
Type=simple 
#参考https://unix.stackexchange.com/questions/442575/how-do-i-figure-out-why-my-systemctl-service-didnt-start-on-centos-7
#Type=forking  开启这个会卡

#脚本在/home/chend/script/下
## !/bin/bash
## 开机自动启动jupyter脚本
## nohup /home/chend/bin/jupyter notebook --allow-root --notebook-dir="/home/chend" --config="/home/chend/.jupyter/jupyter_notebook_config.py" --certfile ##/home/chend/jupyter_cert/jupyter/certs/ssl.cert.pem --keyfile /home/chend/jupyter_cert/jupyter/private/ssl.key.pem  --port=8000 >/home/chend/jupyter.log 2>&1 &
##ExecStart=/bin/bash /home/chend/script/start_jupyter
ExecStart=/usr/local/bin/jupyter notebook --allow-root   ##使用绝对目录
Restart=always
StandardOutput=syslog
StandardError=inherit

[Install]
WantedBy=multi-user.target

(4)重载系统服务
    systemctl daemon-reload
(5) 设置开机启动
    systemctl enable myjupyter.service
(6)启动服务
     system start myjupyter.service
     停止服务
    systemctl stop myjupyter.service

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值