镜像组件安装
为了适配AIStation平台,本文档主要介绍openssh、JupyterLab和python组件的安装。若需要安装或更新相关组件版本,请参考本文的示例。如果基础镜像(FROM所用镜像)中已安装python3,可忽略文档中python3的安装内容。 注意:JupyterLab必须使用python3及以上版本,文档中的Dockerfile只支持python3的JupyterLab安装,不支持python2。
1.Centos7系统
1.1 Dockerfile安装组件
1.1.1 Dockerfile下载链接:
https://github.com/wjyzzu/inpsur-dockerfile/tree/main/base/centos 请下载Dockerfile文件,此文件包含openssh、python3和JupyterLab组件安装的命令。
1.1.2 制作步骤
(1)根据需要,修改FROM中的基础镜像;建议基础镜像提前上传到AIStation中。
(2)修改好Dockerfile,请上传到个人用户目录下。
(3)通过镜像管理-创建功能,制作新镜像。
(4)基于制作的镜像,创建开发环境测试。
(5)注意:上述Dockerfile文件默认python版本为3.6.11;若需指定Jupyterlab版本,请按如下示例修改: pip --no-cache-dir install jupyterlab==2.2.9
1.2 手动安装组件
1.2.1 在线安装
(1)将基础镜像上传至AIStation。
(2)选择基础镜像创建开发环境,参考1.1部分Dockerfile文件,执行安装命令,完成组件安装。
(3)保存镜像。
1.2.2 离线安装
若AIStation平台无法连接外网,可以参考以下方式:
(1)将相关软件安装包或依赖下载完成,上传到用户目录,基于基础镜像创建开发环境,在开发环境中进行组件的离线安装,最后保存镜像,通过AIStation平台完成镜像制作。
(2)直接在网络正常的环境中,在线安装组件,以docker save 的方式保存成tar包,通过AIStation-镜像管理--内部导入的功能导入到AIStation中。
下面主要介绍如何下载及安装组件:
1.2.2.1 安装openssh和openssl
(1)下载安装包和依赖包到指定目录 需要安装的组件:
openssh-7.4p1-21.el7.x86_64.rpm
openssh-clients-7.4p1-21.el7.x86_64.rpm
openssh-server-7.4p1-21.el7.x86_64.rpm
基于基础镜像,挂载本地目录,创建容器,下载各类组件,示例:
docker run -it -v /home/inspur/image_components/centos7.4:/home/inspur/image_components /centos7.4 centos:centos7.4.1708 /bin/bash
可以使用如下命令,查看需要yum安装的组件包
yum list | grep 包名
下载离线环境使用的组件:
## openssh
yum install --downloadonly --downloaddir=/home/inspur/image_components/centos7.4/openssh openssh-7.4p1-21.el7.x86_64
## openssl
yum install --downloadonly --downloaddir=/home/inspur/image_components/centos7.4/openssl openssl
(2) 安装openssh和openssl组件
# 进入安装包目录安装openssh
cd /home/wjy/image_components/centos7.4/openssh
rpm -ivh *.rpm --force --nodeps
# 安装openssl
cd /home/wjy/image_components/centos7.4/openssh
rpm -ivh *.rpm --force --nodeps
# --nodeps就是安装时不检查依赖关系
# --force就是强制安装
(3)openssh配置
# 先新建目录,如果存在,不需要新建
mkdir -p /run/sshd
# 执行ssh-keygen
/usr/bin/ssh-keygen -A
# 执行配置:
cat /etc/ssh/ssh_config | grep -v StrictHostKeyChecking > /etc/ssh/ssh_config.new && \
echo " StrictHostKeyChecking no" >> /etc/ssh/ssh_config.new && \
cat /etc/ssh/sshd_config | grep -v PermitRootLogin > /etc/ssh/sshd_config.new && \
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config.new && \
mv -f /etc/ssh/ssh_config.new /etc/ssh/ssh_config && \
mv -f /etc/ssh/sshd_config.new /etc/ssh/sshd_config > /dev/null 2>&1;
1.2.2.2 安装JupyterLab
安装jupyterlab,必须安装python3和pip。 (1) 安装python3
yum install --downloadonly --downloaddir=/home/wjy/image_components/centos7.4/python_depends make zlib zlib-devel bzip2-devel openssl-devel sqlite-devel readline-devel gdbm-devel gcc libffi-devel
# 进入到下载的依赖包目录,安装依赖包:
cd /home/wjy/image_components/centos7.4/python_depends
rpm -ivh *.rpm --force --nodeps
# 下载python tgz包,解压进入目录
cd /home/wjy/image_components/python
wget https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tgz
tar -zxvf Python-3.7.6.tgz
cd Python-3.7.6
./configure
make && make install
# 修改配置
mv /usr/bin/python /usr/bin/python27
mv /usr/bin/pip /usr/bin/pip27
ln -s /usr/local/bin/python3 /usr/bin/python
ln -s /usr/local/bin/pip3 /usr/bin/pip
sed -i "s## /usr/bin/python## /usr/bin/python2.7## " /usr/bin/yum
sed -i "s## /usr/bin/python## /usr/bin/python2.7## " /usr/libexec/urlgrabber-ext-down
(2) centos7安装pip3(若没有安装pip3再安装)
# 下载get-pip.py,安装pip
cd /home/wjy/image_components
wget https://bootstrap.pypa.io/get-pip.py
# 安装pip
python get-pip.py
(3) 安装JupyterLab
pip install jupyterlab # 在线安装
cd /home/inspur/image_components/jupyterlab
pip3 install --no-index --find-links=/home/inspur/install_packages/jupyterlab jupyterlab-1.2.3-py2.py3-none-any.whl # 离线安装
jupyter lab --ip=0.0.0.0 --no-browser --allow-root # 运行测试,是否安装成功
(4) jupyter配置
# 下载配置文件
wget -P /home/inspur/image_components/jupyter_configure https://raw.githubusercontent.com/Winowang/jupyter_gpu/master/jupyter_notebook_config.py && wget -P /home/inspur/image_components/jupyter_configure https://raw.githubusercontent.com/Winowang/jupyter_gpu/master/custom.js
# 拷贝配置文件
mkdir /etc/jupyter && cp -rf /home/inspur/image_components/jupyter_configure/* /etc/jupyter
2.Ubuntu系统
2.1 Dockerfile安装组件
2.1.1 Dockerfile文件内容
Dockerfile下载链接: https://github.com/wjyzzu/inpsur-dockerfile/tree/main/base/ubuntu
2.1.2 制作步骤
(1)根据需要,修改FROM中的基础镜像;建议基础镜像提前上传到AIStation中。
(2)修改好Dockerfile,请上传到个人用户目录下。
(3)通过镜像管理-创建功能,制作新镜像。 (4)基于制作的镜像,创建开发环境测试。
(5)注意:上述Dockerfile文件默认python版本为3.6.11;
若需指定jupyterlab版本,请按如下示例修改:
pip --no-cache-dir install jupyterlab==2.2.9
2.2 手动安装组件
2.2.1 在线安装
(1)将基础镜像上传至AIStation。
(2)选择基础镜像创建开发环境,参考上述Dockerfile文件,执行安装命令,完成组件安装。
(3)保存镜像。
2.2.2 离线安装
若AIStation平台无法连接外网,可以参考以下方式:
(1)将相关软件安装包或依赖下载完成,上传到用户目录,基于基础镜像创建开发环境,在开发环境中进行组件的离线安装,最后保存镜像,通过AIStation平台完成镜像制作。
(2)直接在网络正常的环境中,在线安装组件,以docker save 的方式保存成tar包,通过AIStation-镜像管理--内部导入的功能导入到AIStation中。
下面主要介绍如何下载及安装组件:
2.2.2.1 安装openssh和openssl
(1)依赖包存放目录(ubuntu离线安装包存放路径,在线安装忽略)
/var/cache/apt/archives
(2)查看依赖包
apt-get update
apt-cache depends packname
(3)查看安装包版本
sudo apt-cache madison openssh-client
(4)下载安装包和依赖包,进入一个干净的镜像中 进入ubuntu镜像/var/cache/apt/archives移除不需要的文件, 然后下载所有依赖文件,下载完后,拷贝到自己的组件目录/home/inspur/image_components/ubuntu18.04/openssh (根据需要修改)
apt-get install -d apt-cache depends openssh-server=1:7.2p2-4 | grep Depends | grep -v debconf-2.0 | cut -d: -f2 |tr -d "<>"
(5)安装openssh和openssl组件
# 进入目录
cd /home/inspur/image_components/ubuntu18.04/openssh
# 进行安装
dpkg -i *deb
(6)修复安装依赖问题(出问题执行)
apt-get -f install
(7)openssh配置
# 先新建目录,如果存在,不需要新建
mkdir -p /run/sshd
# 执行ssh-keygen
/usr/bin/ssh-keygen -A
# 执行配置:
cat /etc/ssh/ssh_config | grep -v StrictHostKeyChecking > /etc/ssh/ssh_config.new && \
echo " StrictHostKeyChecking no" >> /etc/ssh/ssh_config.new && \
cat /etc/ssh/sshd_config | grep -v PermitRootLogin > /etc/ssh/sshd_config.new && \
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config.new && \
mv -f /etc/ssh/ssh_config.new /etc/ssh/ssh_config && \
mv -f /etc/ssh/sshd_config.new /etc/ssh/sshd_config > /dev/null 2>&1;
2.2.2.2 安装jupyter
(1)安装python3
# 进入干净镜像,下载依赖包
apt-get install -y build-essential libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev zlib1g-dev libsqlite3-dev
# 安装所有依赖包:
cd /home/wjy/image_components/ubuntu18.04/python_depends
dpkg -i *deb
# 下载python tgz包(如下为3.7.6版本),解压进入
cd /home/wjy/image_components/python
wget https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tgz
tar -zxvf Python-3.7.6.tgz
cd Python-3.7.6
./configure
make && make install
# 修改配置 mv /usr/bin/python /usr/bin/python27
mv /usr/bin/pip /usr/bin/pip27
ln -s /usr/local/bin/python3 /usr/bin/python
ln -s /usr/local/bin/pip3 /usr/bin/pip
(2)安装pip 离线安装:
# 下载get-pip.py,安装pip
cd /home/wjy/image_components
wget https://bootstrap.pypa.io/get-pip.py
# 安装pip
python get-pip.py
(3)安装jupyter
pip install jupyterlab(在线安装)
cd /home/inspur/image_components/jupyterlab # 进入该目录,离线安装,如果需要最新,就联网下载最新离线包
pip3 install --no-index --find-links=/home/wjy/install_packages/jupyterlab jupyterlab-1.2.3-py2.py3-none-any.whl # 离线安装
jupyter lab --ip=0.0.0.0 --no-browser --allow-root # 运行测试,是否安装成功
(4)jupyter配置
#离线配置:
# 下载配置文件 wget -P /home/inspur/image_components/jupyter_configure https://raw.githubusercontent.com/Winowang/jupyter_gpu/master/jupyter_notebook_config.py && wget -P /home/inspur/image_components/jupyter_configure https://raw.githubusercontent.com/Winowang/jupyter_gpu/master/custom.js
# 拷贝配置文件
mkdir /etc/jupyter && cp -rf /home/inspur/image_components/jupyter_configure/* /etc/jupyter