对于突发情况的断网或因为网络安全原因,不允许连接外网;以及方便服务版本统一,通过搭建本地yum缓存,能够很好的解决以上问题。
1、启动yum缓存
[root@yum-server ~]# vim /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1
[root@yum-server ~]# yum clean all
[root@yum-server ~]# yum -y update
2、安装配置 vsftp 服务
[root@yum-server ~]# yum -y install vsftpd
[root@yum-server ~]# mv /etc/vsftpd/vsftpd.conf{,.bak}
[root@yum-server ~]# vim /etc/vsftpd/vsftpd.conf
# 开启匿名用户登录
anon_upload_enable=YES
anon_mkdir_write_enable=YES
[root@yum-server ~]# systemctl restart vsftpd
# 测试 ftp 服务器
[root@yum-server ~]# yum -y install lftp
[root@yum-server ~]# lftp 12.168.152.133
lftp 192.168.152.133:~> ls
drwxr-xr-x 3 0 0 19 Jun 26 06:50 pub
lftp 192.168.152.133:/> cd pub/
lftp 192.168.152.133:/pub> ls
drwxr-xr-x 3 0 0 4096 Jun 26 06:48 redis
lftp 192.168.152.133:/pub> cd redis/
lftp 192.168.152.133:/pub/redis> get libgfortran-4.8.5-39.el7.x86_64.rpm
307596 bytes transferred
lftp 192.168.152.133:/pub/redis> bye
[root@yum-server ~]#
3、执行安装缓存软件包
[root@yum-server ~]# yum -y install update
[root@yum-server ~]# mkdir /var/ftp/update
[root@yum-server ~]# find /var/cache/yum/x86_64/7/ -iname "*.rpm" -exec cp -rf {} /var/ftp/update \;
4、生成 yum 依赖数据库
[root@yum-server ~]# yum -y install createrepo
[root@yum-server ~]# createrepo /var/ftp/update
5、Yum client 测试
[root@yum-client ~]# mv /etc/yum.repos.d/CentOS-Base.repo{,.bak}
[root@yum-client ~]# vim /etc/yum.repos.d/update.repo
[update]
name=centos update
baseurl=ftp://192.168.152.133/update
gpgcheck=0
enabled=1
[root@yum-client ~]# yum repolist
Loaded plugins: fastestmirror
repo id repo name status
update centos update 75
repolist: 75
[root@yum-client ~]# yum -y update