云服务器搭建在线jupyter notebook

1.在浏览器中使用jupyter

1.安装jupyter notebook

pip install jupyter 

2.生成Jupyter Notebook配置文件

jupyter notebook --generate-config

执行成功:

	[root@iZbp173czfyjpvvdm6k4amZ ~]# jupyter notebook --generate-config
	Writing default config to: /root/.jupyter/jupyter_notebook_config.py

3.设置Jupyter Notebook密码

[root@iZbp173czfyjpvvdm6k4amZ ~]# python3
Python 3.9.0 (default, Nov  4 2021, 16:08:45) 
[GCC 8.4.1 20200928 (Red Hat 8.4.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from IPython.lib import passwd
>>> passwd()
Enter password: 
Verity password:
'这里是密码'
[root@iZbp173czfyjpvvdm6k4amZ ~]# python3.8
Python 3.8.8 (default, Nov  9 2021, 13:31:34) 
[GCC 8.5.0 20210514 (Red Hat 8.5.0-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from IPython.lib import passwd
>>> passwd()
Enter password: 
Verify password: 
'sha1:2e243ced0c53:c0555926e8472d76c14998ee1b4dd08af78b70e'
### 4、设置服务器配置文件
```bash
vim ~/.jupyter/jupyter_notebook_config.py

在文件尾添加

c.NotebookApp.ip = '*' #所有绑定服务器的IP都能访问,若想只在特定ip访问,输入ip地址即可
c.NotebookApp.port = 88 #将端口设置为自己喜欢的吧,默认是8888
c.NotebookApp.open_browser = False #我们并不想在服务器上直接打开Jupyter Notebook,所以设置成False
c.NotebookApp.notebook_dir = '/root/jupyter_projects' #这里是设置Jupyter的根目录,若不设置将默认root的根目录
,不安全
c.NotebookApp.allow_root = True # 为了安全,Jupyter默认不允许以root权限启动jupyter
c.NotebookApp.password='刚才设置密码输出的sha1:'
#c.NotebookApp.password='sha1:a0f6e1593c68:6526f830d8bc41b19fa9232780a1d898231c3ff8'
c.NotebookApp.terminals_enabled = False # 关闭terminal
c.NotebookApp.allow_remote_access=True  #不加这个可能会出现无法启动服务

5.启动Jupyter 远程服务器

jupyter notebook

在浏览器中输入浏览器服务器Ip+端口即可打开,输入设置的密码即可使用。

2.在vscode中使用jupyter

1.在jupyter 配置文件中将password那行注释掉

c.NotebookApp.ip = '*' #所有绑定服务器的IP都能访问,若想只在特定ip访问,输入ip地址即可
c.NotebookApp.port = 88 #将端口设置为自己喜欢的吧,默认是8888
c.NotebookApp.open_browser = False #我们并不想在服务器上直接打开Jupyter Notebook,所以设置成False
c.NotebookApp.notebook_dir = '/root/jupyter_projects' #这里是设置Jupyter的根目录,若不设置将默认root的根目录
,不安全
c.NotebookApp.allow_root = True # 为了安全,Jupyter默认不允许以root权限启动jupyter
#c.NotebookApp.password='sha1:a0f6e1593c68:6526f830d8bc41b19fa9232780a1d898231c3ff8'
c.NotebookApp.terminals_enabled = False # 关闭terminal
c.NotebookApp.allow_remote_access=True  #不加这个可能会出现无法启动服务

2.启动jupyter,赋值带token的链接

如:

http://localhost:88/?token=81380592170cee1076a340614977dc4a62de1765c604157f 

将localhost改为自己的IP地址,复制到vcode中图片所示位置
在这里插入图片描述
crtl +shift+p打开命令面板,搜素jupyter
在这里插入图片描述

#3.拓展

1.jupyter 后台运行

在云服务器中搭建好jupyter并运行后,关闭服务器终端,Jupyter停止运行,其占用当前终端,因此需要将Jupyter在后台运行,
命令1:

jupyter notebook --allow-root > jupyter.log 2>&1 &

命令2:

nohup jupyter notebook --allow-root > jupyter.log 2>&1 &

用&让命令后台运行, 并把标准输出写入jupyter.log中

nohup表示no hang up, 就是不挂起, 这个命令执行后即使终端退出, Jupyter也不会停止运行.

2.关闭jupyter

ps -ef | grep jupyter   #ps -ef : 查看本机所有的进程;
						#grep xxxx代表过滤找到条件xxxx的进程

root      202646  199407  0 21:16 pts/1    00:00:02 /bin/python3 /usr/local/bin/jupyter-notebook --allow-root
root      202921  202646  0 21:20 ?        00:00:01 /bin/python3 -m ipykernel_launcher -f /root/.local/share/jupyter/runtime/kernel-0c4a8126-da32-4cdd-8488-60bd18d61293.json
root      203310  199407  0 21:26 pts/1    00:00:00 grep --color=auto jupyter

kill -9 202646  #kill -9 具体的进程的PID

3.忘记密码:

1.生成秘钥

先是用python终端获得秘钥
from IPython.lib import passwd
passwd()
与设置密钥过程相同

2.在jupyter 配置文件中修改新生成的sha1

4.查看jupyter notebook当前运行服务列表

jupyter notebook list
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值