一、安装 openEuler 20.03 LTS SP1
1.1 Hyper-V 虚拟化环境设置
本次安装,OS采用Windows Server 2016。
在 Hyper-V 中设置虚拟机时,应注意选择版本为 “第一代”
有文献显示,选择第二代会出现重启后无法进入系统的情况
1.2 安装配置:
分区分为三个:swap、boot、根目录
采用最小化安装
仅配置root账户
二、升级 Python 到 3.9.1
2.1 安装开发包
一次性安装所有所需要的包
[root@localhost ~]# yum -y install zlib zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel wget xz-devel gcc kernel-devel make bzip2 libffi libffi-devel expat-devel e2fsprogs-devel libuuid-devel tcl gdbm-devel tcl-devel tk-devel uuid-devel
2.2 安装 LibreSSL 替代 OpenSSL(非必要)
[root@localhost ~]# wget http://ftp.jaist.ac.jp/pub/OpenBSD/LibreSSL/libressl-3.2.2.tar.gz
[root@localhost ~]# tar xzvf libressl-3.2.2.tar.gz
[root@localhost ~]# cd libressl-3.2.2
[root@localhost ~]# ./configure --prefix=/usr/local/ssl
[root@localhost ~]# make && make install
注意:此处可选择最新版本 libressl
2.3 安装 Python 3.9.1
[root@localhost ~]# wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz
[root@localhost ~]# tar -zxvf Python-3.9.1.tgz
[root@localhost ~]# cd Python-3.9.1.tgz
[root@localhost ~]# ./configure --enable-optimizations
[root@localhost ~]# make && make install
2.4 建立软连接
[root@localhost ~]# rm -f /usr/bin/python3
[root@localhost ~]# rm -f /usr/bin/pip3
[root@localhost ~]# ln -s /usr/local/bin/python3.9 /usr/bin/python3
[root@localhost ~]# ln -s /usr/local/bin/pip3.9 /usr/bin/pip3
三、安装 JupyterLab
3.1 升级 pip
[root@localhost ~]# /usr/local/bin/python3.9 -m pip install --upgrade pip
3.2 修改 pip 源为豆瓣源
[root@localhost ~]# mkdir /root/.pip
[root@localhost ~]# cat > /root/.pip/pip.conf << EOF
[global]
index-url = http://pypi.douban.com/simple/
trusted-host = pypi.douban.com
timeout = 120
EOF
3.3 安装 Jupyter 与 JupyterLab
[root@localhost ~]# pip3 install jupyter jupyterlab
3.4 建立 Jupyter Notebook 文件存放文件夹
[root@localhost ~]# mkdir Notebook
3.5 配置 Jupyter
[root@localhost ~]# jupyter notebook --generate-config
[root@localhost ~]# vi ~/.jupyter/jupyter_notebook_config.py
进入vim后取消如下几行的注释(可以通过 /关键字 来定位行)
c.NotebookApp.allow_remote_access = True # 这一步不修改貌似也可以
刚刚保存下来的hash码
c.NotebookApp.password = ''
允许所有IP访问,需要时可以自定义
c.NotebookApp.ip='*'
不启动浏览器
c.NotebookApp.open_browser = False
root用户可以访问,没有设置该项之后启动时需要jupyter lab后加 --allow-root
c.NotebookApp.allow_root = True
可以选择更改jupterlab默认启动路径(此步可忽略)
c.NotebookApp.notebook_dir = '/root/Notebook/'
四、使用 JupyterLab
4.1 配置防火墙:
关闭防火墙命令:systemctl stop firewalld.service
开启防火墙:systemctl start firewalld.service
关闭开机自启动:systemctl disable firewalld.service
开启开机启动:systemctl enable firewalld.service
4.2 启动 JupyterLab
[root@localhost ~]# jupyter lab
复制token,设置密码,进入 JupyterLab
4.3 后台挂起 与 终止进程
4.3.1 后台挂起
[root@localhost ~]# nohup jupyter notebook --allow-root > jupyter.log 2>&1 &
4.3.2 终止进程
[root@localhost ~]# ps -a #查看进程pid
[root@localhost ~]# kill -9 pid # 终止进程
五、问题处理
5.1 更新了 Python 3.9.1,Firewalld 防火墙无法打开的问题
输入:systemctl start firewalld.service
,提示
6月 13 23:47:40 localhost.localdomain systemd[1]: Failed to start firewalld - dynamic firewall daemon.
在网上查了资料,说是由于系统里面安装的python版本原因。/usr/sbin/firewalld文件头部的python版本和安装的python版本不一致导致的。
查看firewalld在那个路径下
[root@localhost ~]# which firewalld
/usr/sbin/firewalld
查看firewalld文件和firewalld-cmd文件头是否一致且与Python一致,如果不一致,需要改成与Python版本一致。
[root@localhost ~]# head -n 10 /usr/sbin/firewalld
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2010-2016 Red Hat, Inc.
# Authors:
# Thomas Woerner <twoerner@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
而此时python的版本为 python 3 =====> python 3.9,不再是以前的 python 3.7
因此,需要将文件中 #!/usr/bin/python3 改为 #!/usr/bin/python3.7 问题即可解决。
同理,/usr/bin/firewall-cmd 文件的开头 #!/usr/bin/python3 也要改为 #!/usr/bin/python3.7