Jupyter Notebook(此前被称为 IPython notebook)是一个交互式笔记本,支持运行 40 多种编程语言。Jupyter Notebook 的本质是一个 Web 应用程序,便于创建和共享文学化程序文档,支持实时代码,数学方程,可视化和 markdown。 用途包括:数据清理和转换,数值模拟,统计建模,机器学习等等
快速搭建
使用C-S架构的形式进行搭建, 采用ubuntu 18.04 搭建服务端
Anaconda 安装
# 官网地址 https://www.anaconda.com/products/individual
wget https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh
# 按照提示安装即可
bash Anaconda3-2020.02-Linux-x86_64.sh
用户设置
# 最好新建一个用户
groupadd jupyter
useradd jupyter -m -g jupyter -s /bin/bash
su jupyter
# 通过查看/root/.bashrc anaconda的环境部分复制到新用户/home/jupyter/.bashrc中
# /root/.bashrc >>
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/usr/local/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/usr/local/anaconda3/etc/profile.d/conda.sh" ]; then
. "/usr/local/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/usr/local/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
配置文件
su jupyter
jupyter notebook --generate-config
# vim ~/.jupyter/
c.NotebookApp.allow_remote_access = True
c.NotebookApp.ip = '*'
c.NotebookApp.notebook_dir = '/home/jupyter/workspace'
c.NotebookApp.open_browser = False
# (base) jupyter@aliyun:~/.jupyter$ python
# Python 3.7.6 (default, Jan 8 2020, 19:59:22)
# [GCC 7.3.0] :: Anaconda, Inc. on linux
# Type "help", "copyright", "credits" or "license" for more information.
# >>> from notebook.auth import passwd
# >>> passwd()
# Enter password:
# Verify password:
# 'sha1:df09e4b2aa29:6713e02459a2058a49706651cdb2bbd252dfa3bb'
# >>>
c.NotebookApp.password = 'sha1:05879eabedc7:fe9d0d381b82a4cd88a4528310f8e3f7c41e0bf1'
c.NotebookApp.port = 8001
脚本编写
# vim /etc/systemd/system/jupyter.service
[Unit]
Description=jupyter notebook
After=network.target
[Service]
User=jupyter
Group=jupyter
WorkingDirectory=/home/jupyter
PIDFile=/var/run/jupyter/jupyter.pid
EnvironmentFile=-/usr/local/anaconda3/bin/jupyter
ExecStart=/usr/local/anaconda3/bin/jupyter notebook
# ExecStop=/usr/bin/pkill /usr/local/anaconda3/bin/jupyter
KillMode=process
Restart=on-failure
RestartSec=30s
[Install]
WantedBy=multi-user.target
开启服务
systemctl enable jupyter.service
systemctl start jupyter.service
# 重导配置文件
systemctl daemon-reload