茄子的个人空间

jupyter notebook 本地服务器搭建

字数统计: 335阅读时长: 1 min
2021/06/21
loading

今天在实验室的服务器主机上面搭建了jupyter notebook服务器,记录一下搭建步骤,方便以后查看。

服务器端操作

生成Jupyter Notebook配置文件
1
$ jupyter notebook --generate-config
设置登录密码
1
2
3
4
5
6
7
# 在命令行输入python命令,进入python交互界面,输入如下命令
from notebook.auth import passwd
passwd()
Enter password:
Verify password:
Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'

将生成的代码添加到配置文件中

1
c.NotebookApp.password = u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
修改配置文件
1
$ vim ~/.jupyter/jupyter_notebook_config.py

在配置文件中添加如下内容

1
2
3
4
5
6
7
8
9
c.NotebookApp.allow_origin = '*'
c.NotebookApp.ip = '0.0.0.0' #所有绑定服务器的IP都能访问,若想只在特定ip访问,输入ip地址即可
c.NotebookApp.port = 2021 #将端口设置为自己喜欢的吧,默认是8888
c.NotebookApp.open_browser = False #我们并不想在服务器上直接打开Jupyter Notebook,所以设置成False
c.NotebookApp.notebook_dir = '/home/jupyter_projects' #这里是设置Jupyter的根目录,若不设置将默认root的根目录,不安全
c.NotebookApp.allow_root = True # 为了安全,Jupyter默认不允许以root权限启动jupyter
c.NotebookApp.allow_remote_access = True
c.NotebookApp.password = u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'

启动jupyter notebook

在终端输入如下命令启动jupyter notebook:

1
jupyter notebook

客服端电脑操作

1
2

ssh username@ipaddress -L 2021:127.0.0.1:2021

最后在本地浏览器输入地址:127.0.0.1:2021 访问

CATALOG
  1. 1. 服务器端操作
    1. 1.1. 生成Jupyter Notebook配置文件
    2. 1.2. 设置登录密码
    3. 1.3. 修改配置文件
    4. 1.4. 启动jupyter notebook
  2. 2. 客服端电脑操作