保存 yum 下载的软件包并制作成本地 yum 源
实验对象
- CentOS 7
- yum 安装 nginx (nginx必须使用第三源才能安装;redhat8版本的则不需要,官网源自带nginx软件包)
一、配置第三方源
- 使用centos7自带的官方源查看是否有nginx安装包
[root@localhost ~]# ls /etc/yum.repos.d/
CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo CentOS-Vault.repo
[root@localhost ~]# yum list nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
Error: No matching Packages to list #没有这个包
- 移除本地仓库
[root@localhost ~]# mv /etc/yum.repos.d/* /mnt/
[root@localhost ~]# ls /etc/yum.repos.d/
[root@localhost ~]#
- 配置第三方源
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@localhost ~]# ls /etc/yum.repos.d/
CentOS-Base.repo epel.repo
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache
二、安装 nginx
- 查看是否有 nginx 安装包
[root@localhost ~]# yum list nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Packages
nginx.x86_64 1:1.16.1-3.el7 epel
- 开启 yum 缓存
[root@localhost ~]# vim /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1 #修改为1 1表示开启缓存,执行 yum 安装会把软件包下载到本地,路径在 /var/cache/yum目录下。
debuglevel=2
logfile=/var/log/yum.log
......
保存退出
- 查找以 rpm 结尾的安装包,有就清除缓存,确保等会安装 nginx 完成后只有 nginx 以及相关的依赖包
[root@localhost ~]# find /var/cache/yum -name *.rpm
[root@localhost ~]#
- 安装 nginx
[root@localhost ~]# yum install -y nginx
三、制作本地 yum 源
- 安装完成后,查找以rpm结尾的软件包
[root@localhost ~]# find /var/cache/yum -name *.rpm
/var/cache/yum/x86_64/7/base/packages/centos-indexhtml-7-9.el7.centos.noarch.rpm
/var/cache/yum/x86_64/7/base/packages/dejavu-fonts-common-2.33-6.el7.noarch.rpm
/var/cache/yum/x86_64/7/base/packages/dejavu-sans-fonts-2.33-6.el7.noarch.rpm
/var/cache/yum/x86_64/7/base/packages/fontconfig-2.13.0-4.3.el7.x86_64.rpm
/var/cache/yum/x86_64/7/base/packages/fontpackages-filesystem-1.44-8.el7.noarch.rpm
/var/cache/yum/x86_64/7/base/packages/gperftools-libs-2.6.1-1.el7.x86_64.rpm
/var/cache/yum/x86_64/7/base/packages/libXau-1.0.8-2.1.el7.x86_64.rpm
/var/cache/yum/x86_64/7/base/packages/libXpm-3.5.12-1.el7.x86_64.rpm
/var/cache/yum/x86_64/7/base/packages/libjpeg-turbo-1.2.90-8.el7.x86_64.rpm
/var/cache/yum/x86_64/7/base/packages/libpng-1.5.13-8.el7.x86_64.rpm
/var/cache/yum/x86_64/7/base/packages/libxcb-1.13-1.el7.x86_64.rpm
/var/cache/yum/x86_64/7/updates/packages/freetype-2.8-14.el7_9.1.x86_64.rpm
/var/cache/yum/x86_64/7/updates/packages/gd-2.0.35-27.el7_9.x86_64.rpm
/var/cache/yum/x86_64/7/updates/packages/libX11-1.6.7-3.el7_9.x86_64.rpm
/var/cache/yum/x86_64/7/updates/packages/libX11-common-1.6.7-3.el7_9.noarch.rpm
/var/cache/yum/x86_64/7/epel/packages/nginx-1.16.1-3.el7.x86_64.rpm
/var/cache/yum/x86_64/7/epel/packages/nginx-all-modules-1.16.1-3.el7.noarch.rpm
/var/cache/yum/x86_64/7/epel/packages/nginx-filesystem-1.16.1-3.el7.noarch.rpm
/var/cache/yum/x86_64/7/epel/packages/nginx-mod-http-image-filter-1.16.1-3.el7.x86_64.rpm
/var/cache/yum/x86_64/7/epel/packages/nginx-mod-http-perl-1.16.1-3.el7.x86_64.rpm
/var/cache/yum/x86_64/7/epel/packages/nginx-mod-http-xslt-filter-1.16.1-3.el7.x86_64.rpm
/var/cache/yum/x86_64/7/epel/packages/nginx-mod-mail-1.16.1-3.el7.x86_64.rpm
/var/cache/yum/x86_64/7/epel/packages/nginx-mod-stream-1.16.1-3.el7.x86_64.rpm
/var/cache/yum/x86_64/7/epel/packages/openssl11-libs-1.1.1g-2.el7.x86_64.rpm
- 以上这些包就是刚刚安装 nginx 以及相关的依赖包
- 将这些包复制到其他的空文件夹中
[root@localhost ~]# mkdir /opt/nginx
[root@localhost ~]# find /var/cache/yum -name *.rpm -exec cp -a {} /opt/nginx \;
[root@localhost ~]# ls /opt/nginx/
centos-indexhtml-7-9.el7.centos.noarch.rpm gd-2.0.35-27.el7_9.x86_64.rpm libXau-1.0.8-2.1.el7.x86_64.rpm nginx-mod-http-image-filter-1.16.1-3.el7.x86_64.rpm
dejavu-fonts-common-2.33-6.el7.noarch.rpm gperftools-libs-2.6.1-1.el7.x86_64.rpm libxcb-1.13-1.el7.x86_64.rpm nginx-mod-http-perl-1.16.1-3.el7.x86_64.rpm
dejavu-sans-fonts-2.33-6.el7.noarch.rpm libjpeg-turbo-1.2.90-8.el7.x86_64.rpm libXpm-3.5.12-1.el7.x86_64.rpm nginx-mod-http-xslt-filter-1.16.1-3.el7.x86_64.rpm
fontconfig-2.13.0-4.3.el7.x86_64.rpm libpng-1.5.13-8.el7.x86_64.rpm nginx-1.16.1-3.el7.x86_64.rpm nginx-mod-mail-1.16.1-3.el7.x86_64.rpm
fontpackages-filesystem-1.44-8.el7.noarch.rpm libX11-1.6.7-3.el7_9.x86_64.rpm nginx-all-modules-1.16.1-3.el7.noarch.rpm nginx-mod-stream-1.16.1-3.el7.x86_64.rpm
freetype-2.8-14.el7_9.1.x86_64.rpm libX11-common-1.6.7-3.el7_9.noarch.rpm nginx-filesystem-1.16.1-3.el7.noarch.rpm openssl11-libs-1.1.1g-2.el7.x86_64.rpm
- 使用 createrepo 命令制作本地yum源
[root@localhost ~]# yum install -y createrepo
[root@localhost ~]# cd /opt/nginx/
[root@localhost nginx]# createrepo ./
Spawning worker 0 with 12 pkgs
Spawning worker 1 with 12 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
- 打包
[root@localhost ~]# tar -zcf nginx.tar.gz /opt/nginx
[root@localhost ~]# ls
anaconda-ks.cfg nginx.tar.gz
- 将刚刚打包好的下载到本地,过程略
四、配置本地 nginx 源
- 测试是有 nignx 软件包
[root@localhost ~]# yum list nginx
Loaded plugins: fastestmirror
Error: No matching Packages to list
- 上传刚刚压缩的 nginx 压缩包,然后解压
[root@localhost ~]# ls
anaconda-ks.cfg nginx.tar.gz
[root@localhost ~]# tar -zxf nginx.tar.gz -C /opt/
[root@localhost ~]# ls /opt/
nginx
- 创建 yum 仓库
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# vim nginx.repo
[nginx]
name=nginx repo
baseurl=file:///opt/nginx
gpgcheck=0
enabled=1
保存退出
- 安装 nginx
[root@localhost ~]# yum list nginx
Loaded plugins: fastestmirror
nginx | 2.9 kB 00:00:00
nginx/primary_db | 19 kB 00:00:00
Determining fastest mirrors
Available Packages
nginx.x86_64 1:1.16.1-3.el7 nginx
[root@localhost ~]# yum install -y nginx
[root@localhost ~]# rpm -qa nginx
nginx-1.16.1-3.el7.x86_64