0%

CentOS安装Jupyter-Notebook

安装依赖

1
sudo yum install openssl* bzip2 expat zlib* sqlite* libffi* libssl* wget gcc make cmake automake -y

下载、编译、安装Python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# download python source
wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
# untar
tar xf Python-3.7.4.tgz
cd Python-3.7.4
# make
.configure --prefix=/opt/python3 --with-ssl
vi setup.py
## add
sqlite_inc_path=['/usr/bin/sqlite3',]
## make
make -j20
# install
make install
# configure profile
vi /etc/profile
## add
export PATH=${PATH}:/opt/python3/bin
source /etc/profile

安装、配置Jupyter Notebook

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# install jupyter by pip
pip3 install jupyter
# configure jupyter
## get passwd sha1
python3
>>> from notebook.auth import passwd
>>> passwd()
## copy passwd sha1
## get jupyter configure location
jupyter notebook --generate-config
## create certfile and keyfile
mkdir ~/key && cd ~/key
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout j.key -out j.pem
## configure jupyter
vi ~/.jupyter/jupyter_notebook_conf.py
### change passwd use paste
c.NotebookApp.password='passwd'
### change certfile and keyfile
.NotebookApp.certfile = '/home/user/key/j.pem'
c.NotebookApp.keyfile = '/home/user/key/j.key'
### change listen ip
c.NotebookApp.ip = '192.168.0.230'
### disable open_browser
c.NotebookApp.open_browser=False
### change llisten port
c.NotebookApp.port = 9088

添加开机启动

1
2
3
4
5
6
7
8
9
---jupyter.sh---
#!/bin/bash
# function: onboot start jupyter
cd /home/user/code && jupyter notebook > /dev/null 2>&1 &

---rc.local---
# add
su - user -c "sh /home/user/jupyter.sh"
chmod +x rc.local

添加防火墙端口

1
2
3
su
firewall-cmd --zone=public --add-port=9088/tcp --permanent
firewall-cmd --reload

测试

打开浏览器,输入服务器地址https://jupyter:9088
jupyter