linux部署YUM仓库服务

本文介绍了如何将CentOS系统的YUM源更换为阿里云源,以提高软件下载速度。同时,详细阐述了如何设置本地光盘源和内网FTP源,并通过清理缓存、建立元数据缓存来确保源的有效性。此外,还展示了如何在FTP仓库中添加新软件并更新客户机的元数据,以实现软件安装。
摘要由CSDN通过智能技术生成

1.更换YUM源为aliyun的源

可以直接复制执行

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

yum clean all  //清理缓存数据

yum makecache    //重建元数据缓存

2.更换YUM源为本地源

2.1 准备软件仓库

[root@localhost ~]# mount /dev/sr0 /mnt   //挂载光盘充当yum仓库
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# ls /mnt    //查看挂载后的目录有哪些内容(Packages内为rpm软件包)
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL
[root@localhost ~]# 

2.2 配置软件仓库位置

[root@localhost ~]# vim /etc/yum.repos.d/local.repo     //yum软件仓库载此目录下,在创建一个

[local]            //表示仓库类别
name=local             //仓库名称(说明)
baseurl=file:///mnt     //访问路径
enable=1       //启用此仓库
gpgcheck=0     //不验证软件包的签名
            

2.3 清缓存,建立元数据缓存

[root@localhost ~]# yum clean all    //清除缓存
已加载插件:fastestmirror, langpacks
正在清理软件源: FTP local
Cleaning up list of fastest mirrors
Other repos take up 401 M of disk space (use --verbose for details)

[root@localhost ~]# yum makecache     //建立元数据缓存
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
FTP                                                                                          | 2.9 kB  00:00:00     
local                                                                                        | 3.6 kB  00:00:00     
(1/7): FTP/filelists_db                                                                      | 3.2 MB  00:00:00     
(2/7): FTP/primary_db                                                                        | 3.2 MB  00:00:00     
(3/7): local/group_gz                                                                        | 166 kB  00:00:00     
(4/7): FTP/other_db                                                                          | 1.3 MB  00:00:00     
(5/7): local/filelists_db                                                                    | 3.2 MB  00:00:00     
(6/7): local/primary_db                                                                      | 3.1 MB  00:00:00     
(7/7): local/other_db                                                                        | 1.3 MB  00:00:00     
元数据缓存已建立
[root@localhost ~]# 

2.4 查看软件源

[root@localhost ~]# yum repolist 
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
源标识                                                  源名称                                                 状态
local                                                   local                                                  4,021
repolist: 4,021
[root@localhost ~]# 

2.5 测试安装httpd

[root@localhost ~]# yum -y install httpd
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 httpd.x86_64.0.2.4.6-88.el7.centos 将被 安装
--> 解决依赖关系完成

依赖关系解决

====================================================================================================================
 Package                架构                    版本                                   源                      大小
====================================================================================================================
正在安装:
 httpd                  x86_64                  2.4.6-88.el7.centos                    local                  2.7 M

事务概要
====================================================================================================================
安装  1 软件包

总下载量:2.7 M
安装大小:9.4 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : httpd-2.4.6-88.el7.centos.x86_64                                                                1/1 
  验证中      : httpd-2.4.6-88.el7.centos.x86_64                                                                1/1 

已安装:
  httpd.x86_64 0:2.4.6-88.el7.centos                                                                                

完毕!
[root@localhost ~]# 

3.更换源为内网FTP发布的YUM源

3.1 安装启用vsftpd服务

[root@localhost ~]# yum -y install vsftpd    //下载安装
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                         | 3.6 kB  00:00:00     
epel                                                                                         | 4.7 kB  00:00:00     
extras                                                                                       | 2.9 kB  00:00:00     
updates                                                                                      | 2.9 kB  00:00:00     
。。。

已安装:
  vsftpd.x86_64 0:3.0.2-28.el7                                                                                      

完毕!
[root@localhost ~]# systemctl start vsftpd   //启用vsftpd服务

3.2 配置软件仓库

[root@localhost ~]# mount /dev/sr0 /mnt   //挂载光盘
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# mkdir /var/ftp/ftp     //创建挂载目录
[root@localhost ~]# cp -a /mnt/* /var/ftp/ftp/    //将光盘内容复制到该文件夹,充当软件仓库

3.3 配置软件仓库位置(客户机)

[root@localhost ~]# vim /etc/yum.repos.d/ftp.repo
[root@localhost ~]# cat /etc/yum.repos.d/ftp.repo
[FTP]      //标识仓库类别
name=FTP    //仓库名称
baseurl=ftp://192.168.30.4/ftp    //访问路径
enable=1             //启用此仓库
gpgcheck=0          //不验证软件包的签名

[root@localhost ~]# 

3.4 清缓存,建立元数据缓存(客户机)

[root@localhost ~]# yum clean all     //清除缓存
已加载插件:fastestmirror, langpacks
正在清理软件源: FTP
Cleaning up list of fastest mirrors
Other repos take up 401 M of disk space (use --verbose for details)
[root@localhost ~]# yum makecache    //建立元数据缓存
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
FTP                                                                                          | 3.6 kB  00:00:00     
(1/4): FTP/group_gz                                                                          | 166 kB  00:00:00     
(2/4): FTP/primary_db                                                                        | 3.1 MB  00:00:00     
(3/4): FTP/filelists_db                                                                      | 3.2 MB  00:00:00     
(4/4): FTP/other_db                                                                          | 1.3 MB  00:00:00     
元数据缓存已建立
[root@localhost ~]# yum repolist    //显示软件源
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
源标识                                                   源名称                                                状态
FTP                                                      FTP                                                   4,021
repolist: 4,021
[root@localhost ~]# 

3.5 测试安装httpd(客户机)

[root@localhost ~]# yum -y install httpd    //安装httpd
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 httpd.x86_64.0.2.4.6-88.el7.centos 将被 安装
--> 正在处理依赖关系 httpd-tools = 2.4.6-88.el7.centos,它被软件包 httpd-2.4.6-88.el7.centos.x86_64 需要

====================================================================================================================
 Package                     架构                   版本                                  源                   大小
====================================================================================================================
正在安装:
 httpd                       x86_64                 2.4.6-88.el7.centos                   FTP                 2.7 M
为依赖而安装:
 httpd-tools                 x86_64                 2.4.6-88.el7.centos                   FTP                  90 k
 mailcap                     noarch                 2.1.41-2.el7                          FTP                  31 k
。。。
已安装:
  httpd.x86_64 0:2.4.6-88.el7.centos                                                                                

作为依赖被安装:
  httpd-tools.x86_64 0:2.4.6-88.el7.centos                       mailcap.noarch 0:2.1.41-2.el7                      

完毕!
[root@localhost ~]# 

3.6 FTP软件仓库增加软件时,需更新yum源的元数据信息

[root@localhost data]# ls
nginx-1.16.1-3.el7.x86_64.rpm                        nginx-mod-http-xslt-filter-1.16.1-3.el7.x86_64.rpm
nginx-all-modules-1.16.1-3.el7.noarch.rpm            nginx-mod-mail-1.16.1-3.el7.x86_64.rpm
nginx-filesystem-1.16.1-3.el7.noarch.rpm             nginx-mod-stream-1.16.1-3.el7.x86_64.rpm
nginx-mod-http-image-filter-1.16.1-3.el7.x86_64.rpm  openssl11-libs-1.1.1g-3.el7.x86_64.rpm
nginx-mod-http-perl-1.16.1-3.el7.x86_64.rpm

[root@localhost data]# cp * /var/ftp/ftp/Packages/     //将rpm包放到软件仓库中

[root@localhost data]# createrepo --update /var/ftp/ftp/Packages/    //手动更新依赖关系
Could not find valid repo at: /var/ftp/ftp/Packages/
Spawning worker 0 with 2015 pkgs
Spawning worker 1 with 2015 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@localhost data]# 

3.7 更新客户机软件仓库位置

[root@localhost ~]# vim /etc/yum.repos.d/ftp.repo  

[FTP]
name=FTP
baseurl=ftp://192.168.30.4/ftp/Packages    //手动更新Packages目录
enable=1
gpgcheck=0

3.8 查看可安装软件数量

[root@localhost ~]# yum repolist     //4021没变化
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
源标识                                                   源名称                                                状态
FTP                                                      FTP                                                   4,021
repolist: 4,021
[root@localhost ~]# 

3.9 清除缓存,重建元数据信息

[root@localhost ~]# yum clean all
已加载插件:fastestmirror, langpacks
正在清理软件源: FTP
Cleaning up list of fastest mirrors
Other repos take up 401 M of disk space (use --verbose for details)
[root@localhost ~]# yum makecache 
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
FTP                                                                                          | 2.9 kB  00:00:00     
(1/3): FTP/filelists_db                                                                      | 3.2 MB  00:00:00     
(2/3): FTP/other_db                                                                          | 1.3 MB  00:00:00     
(3/3): FTP/primary_db                                                                        | 3.2 MB  00:00:00     
元数据缓存已建立
[root@localhost ~]# yum repolist    //变为4030
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
源标识                                                   源名称                                                状态
FTP                                                      FTP                                                   4,030
repolist: 4,030
[root@localhost ~]#

测试安装nginx(此前无此rpm包)

[root@localhost ~]# yum -y install nginx
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
。。。

====================================================================================================================
 Package                                  架构                版本                           源                大小
====================================================================================================================
正在安装:
 nginx                                    x86_64              1:1.16.1-3.el7                 FTP              563 k
为依赖而安装:
 nginx-all-modules                        noarch              1:1.16.1-3.el7                 FTP               20 k
 nginx-filesystem                         noarch              1:1.16.1-3.el7                 FTP               21 k
 nginx-mod-http-image-filter              x86_64              1:1.16.1-3.el7                 FTP               30 k
 nginx-mod-http-perl                      x86_64              1:1.16.1-3.el7                 FTP               39 k
 nginx-mod-http-xslt-filter               x86_64              1:1.16.1-3.el7                 FTP               29 k
 nginx-mod-mail                           x86_64              1:1.16.1-3.el7                 FTP               57 k
 nginx-mod-stream                         x86_64              1:1.16.1-3.el7                 FTP               85 k
 openssl11-libs                           x86_64              1:1.1.1g-3.el7                 FTP              1.5 M


。。。。
已安装:
  nginx.x86_64 1:1.16.1-3.el7                                                                                       

作为依赖被安装:
  nginx-all-modules.noarch 1:1.16.1-3.el7                      nginx-filesystem.noarch 1:1.16.1-3.el7              
  nginx-mod-http-image-filter.x86_64 1:1.16.1-3.el7            nginx-mod-http-perl.x86_64 1:1.16.1-3.el7           
  nginx-mod-http-xslt-filter.x86_64 1:1.16.1-3.el7             nginx-mod-mail.x86_64 1:1.16.1-3.el7                
  nginx-mod-stream.x86_64 1:1.16.1-3.el7                       openssl11-libs.x86_64 1:1.1.1g-3.el7                

完毕!
[root@localhost ~]# 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值