制作CentOS7yum源

制作CentOS7.7 内网yum源

如果CentOS服务器处在内网环境中时,如果缺少依赖手动安装那么会非常麻烦,要花费很多时间来寻找rpm包,现在如果搭建本地的yum源,就非常方便了,如果搭建http的,那么局域网内其他服务器就都可以使用了,使用yum源首先需要一个CentOS安装镜像

IP 主机名 用途
192.168.200.27 yum 内网yum源服务器
192.168.200.29 web web服务器

1. 安装http服务

[root@yum ~]# yum -y install httpd
[root@yum ~]# systemctl start httpd
[root@yum ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

2. 挂在本地源

[root@yum ~]# mount /dev/sr0 /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@yum ~]# df -h | tail -1
/dev/sr0                     4.2G  4.2G     0  100% /mnt

[root@yum ~]# ll /mnt/
总用量 678
-rw-rw-r-- 1 root root     14 5月   2 2018 CentOS_BuildTag
drwxr-xr-x 3 root root   2048 5月   4 2018 EFI
-rw-rw-r-- 1 root root    227 8月  30 2017 EULA
-rw-rw-r-- 1 root root  18009 12月 10 2015 GPL
drwxr-xr-x 3 root root   2048 5月   4 2018 images
drwxr-xr-x 2 root root   2048 5月   4 2018 isolinux
drwxr-xr-x 2 root root   2048 5月   4 2018 LiveOS
drwxrwxr-x 2 root root 655360 5月   4 2018 Packages
drwxrwxr-x 2 root root   4096 5月   4 2018 repodata
-rw-rw-r-- 1 root root   1690 12月 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r-- 1 root root   1690 12月 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r-- 1 root root   2883 5月   4 2018 TRANS.TBL

3. 把本地源拷贝到httpd的静态资源路径下

[root@yum ~]# cd /var/www/html/
[root@yum html]# cp -a /mnt ./centos
[root@yum html]# ll -d centos
drwxr-xr-x 8 root root 254 5月   4 2018 centos
[root@yum html]# ll centos/
总用量 320
-rw-rw-r-- 1 root root     14 5月   2 2018 CentOS_BuildTag
drwxr-xr-x 3 root root     35 5月   4 2018 EFI
-rw-rw-r-- 1 root root    227 8月  30 2017 EULA
-rw-rw-r-- 1 root root  18009 12月 10 2015 GPL
drwxr-xr-x 3 root root     57 5月   4 2018 images
drwxr-xr-x 2 root root    198 5月   4 2018 isolinux
drwxr-xr-x 2 root root     43 5月   4 2018 LiveOS
drwxrwxr-x 2 root root 221184 5月   4 2018 Packages
drwxrwxr-x 2 root root   4096 5月   4 2018 repodata
-rw-rw-r-- 1 root root   1690 12月 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r-- 1 root root   1690 12月 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r-- 1 root root   2883 5月   4 2018 TRANS.TBL

4. 网页访问测试

image.png-208.1kB

5. 修改yum源的配置

[root@yum html]# cd /etc/yum.repos.d/
[root@yum yum.repos.d]# mkdir bak
[root@yum yum.repos.d]# mv CentOS-* bak/
[root@yum yum.repos.d]# vim Centos.repo
[root@yum yum.repos.d]# cat Centos.repo
[base]
name=CentOS7.7-base
baseurl=file:///var/www/html/centos/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

6. 卸载本地镜像进行本地测试

[root@yum yum.repos.d]# umount /dev/sr0 
[root@yum yum.repos.d]# yum -y clean all
[root@yum yum.repos.d]# yum makecache

[root@yum yum.repos.d]# rpm -qa|grep lsof
[root@yum yum.repos.d]# yum -y install lsof
[root@yum yum.repos.d]# rpm -qa|grep lsof
lsof-4.87-5.el7.x86_64

7.远程进行网络测试

[root@web ~]# cd /etc/yum.repos.d/
[root@web yum.repos.d]# mkdir bak
[root@web yum.repos.d]# mv CentOS-* bak/
[root@web yum.repos.d]# vim Centos.repo
[root@web yum.repos.d]# cat Centos.repo
[base]
name=CentOS7.7-base
baseurl=http://192.168.200.27/centos/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@web yum.repos.d]# yum -y clean all
[root@web yum.repos.d]# yum makecache
[root@web yum.repos.d]# rpm -qa|grep lsof
[root@web yum.repos.d]# yum -y install lsof
[root@web yum.repos.d]# rpm -qa|grep lsof
lsof-4.87-5.el7.x86_64

8. 下载7.7.1908增量的repo数据

[root@yum yum.repos.d]# mkdir -p /var/www/html/updates/repodata
[root@yum yum.repos.d]# cd /var/www/html/updates/repodata
[root@yum repodata]# wget http://mirrors.163.com/centos/7.7.1908/updates/x86_64/repodata/
[root@yum repodata]# wget -nc -B http://mirrors.163.com/centos/7.7.1908/updates/x86_64/repodata/ -F -nH --cut-dirs=3 -i index.html

9. 下载7.7.1908增量的更新软件集

[root@yum repodata]# mkdir -p /var/www/html/updates/Packages
[root@yum repodata]# cd /var/www/html/updates/Packages
[root@yum Packages]# wget http://mirrors.163.com/centos/7.7.1908/updates/x86_64/Packages/
[root@yum Packages]# wget -nc -B http://mirrors.163.com/centos/7.7.1908/updates/x86_64/Packages/ -F -nH --cut-dirs=3 -i index.html

10.远程进行网络升级测试

[root@web yum.repos.d]# vim Centos.repo 
[root@web yum.repos.d]# cat Centos.repo 
[base]
name=CentOS7.7-base
baseurl=http://192.168.200.27/centos/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-7.7-Updates
baseurl=http://192.168.200.27/updates/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@web yum.repos.d]# yum -y clean all
[root@web yum.repos.d]# yum makecache
[root@web yum.repos.d]# rpm -qa|grep sudo
sudo-1.8.23-3.el7.x86_64
[root@web yum.repos.d]# yum update sudo
[root@web yum.repos.d]# rpm -qa|grep sudo
sudo-1.8.23-4.el7_7.1.x86_64

如果包源更新失败,请参考 http://www.path8.net/tn/archives/6098

猜你喜欢

转载自www.cnblogs.com/ywb123/p/12199763.html