c4rt1y

Jupyter notebook 线上部署

0x01 介绍

Jupyter notebook是由ipython notebook演变而来,jupyter notebook在数据分析时使用非常的方便,主要看中其在线调试的功能,因为公司线上服务器不允许远程登录操作。

0x02 基础环境安装

服务器ip
10.10.10.10   master

#关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service

#关闭selinux,需要重启
sed -i 's:SELINUX=enforcing:SELINUX=disabled:g' /etc/selinux/config

#临时关闭seLinux
setenforce 0

#重启
reboot

0x03 python3安装

# 考虑到一些包的丢失问题,所以直接安装了Anaconda3版本
wget https://repo.anaconda.com/archive/Anaconda3-2019.07-Linux-x86_64.sh -P /usr/src/

# 安装(全部回车也可以,可以自定义路径)
sh /usr/src/Anaconda3-2019.07-Linux-x86_64.sh

# 设置为环境变量
cat > /etc/profile.d/anacoda.sh << EOF
#!/bin/bash
export PATH=/root/anaconda3/bin/:\$PATH
EOF

# 使其生效
source /etc/profile

# 默认centos7.3是没有python3的,查看是否存在
python3


# 因为需要后台驻存,所以安装screen
yum install screen -y

0x04 jupyter 配置

# 打开ipython , 设置密码,这个为jupyter的登录密码,因为线上服务器,所以需要安全验证
python3 -c "from IPython.lib import passwd;print(passwd())"
Enter password:
Verify password:
sha1:1c9edb3ed822:6024f1cfb7d120d2382d06d9e64b591b0ebdb416

# 创建jupyter配置文件
jupyter notebook --generate-config
Writing default config to: /root/.jupyter/jupyter_notebook_config.py

# 配置文件修改如下
grep -Ev '^$|^#' .jupyter/jupyter_notebook_config.py
c.NotebookApp.allow_remote_access = True
c.NotebookApp.allow_root = True
c.NotebookApp.ip = ''
c.NotebookApp.notebook_dir = '/opt/'
c.NotebookApp.open_browser = False
c.NotebookApp.password = 'sha1:1c9edb3ed822:6024f1cfb7d120d2382d06d9e64b591b0ebdb416'
c.NotebookApp.password_required = False
c.NotebookApp.port = 8888

# 启动 screen
screen

jupyter-notebook
[W 08:58:57.869 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 08:58:57.893 NotebookApp] JupyterLab extension loaded from /opt/xd/anaconda3/lib/python3.7/site-packages/jupyterlab
[I 08:58:57.893 NotebookApp] JupyterLab application directory is /opt/xd/anaconda3/share/jupyter/lab
[I 08:58:57.895 NotebookApp] Serving notebooks from local directory: /opt
[I 08:58:57.895 NotebookApp] The Jupyter Notebook is running at:
[I 08:58:57.895 NotebookApp] http://master:8888/
[I 08:58:57.895 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

# 网页测试访问

login-jupyter-notebook

# 输入密码,访问

jupyter-notebook

# 以上代表访问成果,现在我们返回终端,对隐藏终端,键盘命令 ctrl+a+d 

# 为了方便调试,我们同时可以开启(若8888端口占用,自动+1)
jupyter-lab
[W 09:08:38.449 LabApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 09:08:38.455 LabApp] JupyterLab extension loaded from /opt/xd/anaconda3/lib/python3.7/site-packages/jupyterlab
[I 09:08:38.455 LabApp] JupyterLab application directory is /opt/xd/anaconda3/share/jupyter/lab
[I 09:08:38.456 LabApp] Serving notebooks from local directory: /opt
[I 09:08:38.456 LabApp] The Jupyter Notebook is running at:
[I 09:08:38.456 LabApp] http://master:8889/
[I 09:08:38.456 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

# 网页测试访问

login-jupyter-lab

# 输入密码,访问

jupyter-lab

# 以上代表访问成果,现在我们返回终端,对隐藏终端,键盘命令 ctrl+a+d 

# 至此,数据分析的基础环境就搭建好了

0x05 资料来源

https://blog.csdn.net/SA14023053/article/details/51725580  Jupyter notebook 服务器端部署
GoTop