需求背景:
一般线上服务器都是不能连接外网,服务器安装好系统之后就需要部署相关软件,此时因为无法联网导致无法下载软件,所以都会做一个本地的离线软件源,本文简单介绍如何快速利用已经下载好的rpm包,制作一个软件源。
操作方法:
1, 保存rpm包
利用能够联网的机器,比如虚拟机,安装好openEuler,配置好网络和软件网络源,配置yum,保证下载之后能保存rpm文件。
cat /etc/yum.conf
[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=False
best=True
skip_if_unavailable=False
keepcache=True
2,安装createreo,并测试rpm是否能够保存
yum install -y vim createrepo
find /var/cache | grep rpm$
/var/cache/dnf/everything-faab61b70984c770/packages/gpm-libs-1.20.7-
22.ctl2.x86_64.rpm
/var/cache/dnf/everything-faab61b70984c770/packages/createrepo_c-0.16.0-
1.ctl2.x86_64.rpm
/var/cache/dnf/everything-faab61b70984c770/packages/drpm-0.5.0-1.ctl2.x86_64.rpm
/var/cache/dnf/update-957bde591a0344ed/packages/vim-common-9.0-14.ctl2.x86_64.rpm
/var/cache/dnf/update-957bde591a0344ed/packages/vim-enhanced-9.0-
14.ctl2.x86_64.rpm
/var/cache/dnf/update-957bde591a0344ed/packages/vim-filesystem-9.0-
14.ctl2.noarch.rpm
3,下载所有需要用到的软件(根据自己的需求)
yum -y install glx-utils initial-setup-gui mesa-dri-drivers plymouth-system-theme spice-vdagent xorg-x11-drivers xorg-x11-server-Xorg xorg-x11-utils xorg-x11-xauth xorg-x11-xinit xvattr gdm tmux
yum -y install java-1.8.0-openjdk librbd1 openssl-devel gperftools-devel libva-devel celt051-devel
4,将所有rpm包归总在一个目录
mkdir -p /root/rpms && find /var/cache | grep rpm$ | xargs -I % cp % /root/rpms/
5,创建离线仓库,可以看到createrepo会创建相关元数据
# cd /root/rpms
# createrepo .
Directory walk started
Directory walk done - 6 packages
Temporary output repo path: ./.repodata/
Preparing sqlite DBs
Pool started (with 5 workers)
Pool finished
# ls
createrepo_c-0.16.0-1.ctl2.x86_64.rpm gpm-libs-1.20.7-22.ctl2.x86_64.rpm vimcommon-9.0-14.ctl2.x86_64.rpm vim-filesystem-9.0-14.ctl2.noarch.rpm
drpm-0.5.0-1.ctl2.x86_64.rpm repodata vimenhanced-9.0-14.ctl2.x86_64.rpm
6, 将/root/rpms打包
# cd /root/
# tar -czvf rpms.tgz rpms/
7, 将rpms压缩包拷贝至不能联网的机器上的/root/目录,配置软件源
#mkdir /etc/yum.repos.d/bak
#mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/
# vi /etc/yum.repos.d/local.repo
[LocalRepo]
name=LocalRepository
baseurl=file:///root/rpms
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-openEuler
8, 构建yum缓存
yum makecache
9,安装离线包
yum install vim