You've successfully subscribed to ムえのBLOG
Great! Next, complete checkout for full access to ムえのBLOG
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Jupyter Notebook服务器端安装与配置记录

Jupyter Notebook服务器端安装与配置记录

. 2 min read

最近入了一台阿里云学生机,1核 2G 5M带宽,还算不错,部署jupyter notebook跑跑简单的数据分析什么的还是可以的。

环境配置

9.9包邮,就是便宜

CPU model Intel(R) Xeon(R) CPU E5-2682 v4 @ 2.50GHz
Number of cores 1
CPU frequency 2494.224 MHz
Total size of Disk 40.0 GB (7.7 GB Used)
Total amount of Mem 1993 MB (1301 MB Used)
Total amount of Swap 947 MB (7 MB Used)
System uptime 3 days, 16 hour 22 min
Load average 0.10, 0.07, 0.02
OS Ubuntu 18.04.4 LTS
Arch x86_64 (64 Bit)
Kernel 4.15.0-48-generic

安装过程

安装pip3和jupyter note book

sudo apt install python3-pip
pip3 install jupyter

如果没有安装成功可能是缺少其他的库,可以用下面的命令安装或者去找轮子

sudo pip3 install pyzmq
sudo pip3 install tornado
sudo pip3 install jinja2
sudo pip3 install jsonschema
sudo pip3 install jupyter

配置

为了在服务器上使用顺畅,我们需要调教一下x

生成配置文件

jupyter notebook --generate-config

配置文件会出现在 ~/.jupter/jupyter_notebook_config.py

另外,还需要配置一个密钥,为了登录jupyter服务器

生成密钥

In [1]: from IPython.lib import passwd
In [2]: passwd()
Enter password: 
Verify password: 
Out[2]: 'sha1:xxx:xxx' 

在配置文件中,需要写入下面的

c.NotebookApp.ip = '*'									#允许所有ip访问
c.NotebookApp.port = 9999								#登录端口
c.NotebookApp.open_browser = False						#禁止启动时弹出浏览器
c.NotebookApp.notebook_dir = '/root/jupyter_projects'	#文件目录
c.NotebookApp.allow_root = True							#允许root用户权限
c.NotebookApp.terminals_enabled = False					#不显示终端
c.NotebookApp.password = u'sha1:xxx:xxx'				#生成的密钥
c.IPKernelApp.pylab = 'inline'
c.NotebookApp.enable_mathjax = True

启动

服务器命令就可以启动了

jupyter notebook

ubuntu 系统服务设置

配置文件会出现在 /etc/systemd/system/ 下,可以添加一个服务文件如 jupyter.service ,用systemctl去控制jupyter的开启

配置详情如

[Unit]
Description=jupyter notebook
After=network.target
[Service]
Tpye=forking
EnvironmentFile=/usr/local/bin/jupyter-notebook
ExecStart=/usr/local/bin/jupyter-notebook
#ExecStop=/usr/bin/pkill jupyter-notebook
KillMode=process
Restart=on-failure
RestartSec=30s
[Install]
WantedBy=multi-user.target

随后把它添加到服务中去

systemctl daemon-reload
systemctl enable jupyter
systemctl start jupyter

就🆗了

可以登录你的ip:你设置的端口号开始愉快的jupyter服务了

进阶——jupyter插件开启

安装nbextensions


pip3 install jupyter_contrib_nbextensions -i https://pypi.mirrors.ustc.edu.cn/simple
jupyter contrib nbextension install --user

安装nbextensions_configurator

pip3 install --user jupyter_nbextensions_configurator 
jupyter nbextensions_configurator enable --user

重启jupyter

这时候登录你的jupyter就可以在导航栏里发现增加了一个Nbextensions标签页
在这个页面里,勾选Hinterland即启用了代码自动补全,打开一个notebook感受一下吧。



本站总访问量