Linux System Environment
[root@yumserver ~]cat /etc/redhat-release #==》系统版本
CentOS Linux release 7.5.1804 (Core)
[root@yumserver ~]uname –r #==》内核版本
3.10.0-862.el7.x86_64
[root@yumserver ~] uname -m #==》系统架构
x86_64
[root@yumserver ~]echo $LANG #==》系统字符集
en_US.UTF-8
实验环境:
Yum源仓库服务器IP地址 10.10.10.20
Yum源测试客户端IP地址 10.10.10.21
说明:
搭建内部yum源仓库有许多种类,例如file、ftp、http、https,本教程以http进行搭建内部yum源仓库
一、复制一份CentOS 7.5镜像安装包到本地目录(虚拟机已经读取了CentOS 7.5镜像)
[root@yumserver ~]# mount /dev/sr0 /media/
[root@yumserver ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 72G 1.9G 70G 3% /
devtmpfs 981M 0 981M 0% /dev
tmpfs 992M 0 992M 0% /dev/shm
tmpfs 992M 9.5M 982M 1% /run
tmpfs 992M 0 992M 0% /sys/fs/cgroup
/dev/sda1 497M 117M 380M 24% /boot
tmpfs 199M 0 199M 0% /run/user/0
/dev/sr0 4.2G 4.2G 0 100% /media
[root@yumserver ~]# ls -l /media/
total 678
-rw-rw-r-- 1 root root 14 May 2 2018 CentOS_BuildTag
drwxr-xr-x 3 root root 2048 May 4 2018 EFI
-rw-rw-r-- 1 root root 227 Aug 30 2017 EULA
-rw-rw-r-- 1 root root 18009 Dec 10 2015 GPL
drwxr-xr-x 3 root root 2048 May 4 2018 images
drwxr-xr-x 2 root root 2048 May 4 2018 isolinux
drwxr-xr-x 2 root root 2048 May 4 2018 LiveOS
drwxrwxr-x 2 root root 655360 May 4 2018 Packages
drwxrwxr-x 2 root root 4096 May 4 2018 repodata
-rw-rw-r-- 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r-- 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r-- 1 root root 2883 May 4 2018 TRANS.TBL
[root@yumserver ~]# mkdir -p /mnt/yumserver
[root@yumserver ~]# cp -rp /media/* /mnt/yumserver/
[root@yumserver ~]# ls -l /mnt/yumserver/
total 320
-rw-rw-r-- 1 root root 14 May 2 2018 CentOS_BuildTag
drwxr-xr-x 3 root root 35 May 4 2018 EFI
-rw-rw-r-- 1 root root 227 Aug 30 2017 EULA
-rw-rw-r-- 1 root root 18009 Dec 10 2015 GPL
drwxr-xr-x 3 root root 57 May 4 2018 images
drwxr-xr-x 2 root root 198 May 4 2018 isolinux
drwxr-xr-x 2 root root 43 May 4 2018 LiveOS
drwxrwxr-x 2 root root 221184 May 4 2018 Packages
drwxrwxr-x 2 root root 4096 May 4 2018 repodata
-rw-rw-r-- 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r-- 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r-- 1 root root 2883 May 4 2018 TRANS.TBL
二、配置本地yum源安装Apache服务
###清除本地主机所有的yum源配置文件,此步骤为了方便测试
[root@yumserver ~]# mv /etc/yum.repos.d/* /tmp/
###创建本地yum源仓库配置文件Localhost_Yum.repo,一定要以.repo结尾
[root@yumserver ~]# vim /etc/yum.repos.d/Localhost_Yum.repo
[localhost_yum]
name=CentOS-$releasever - localhost_yum
baseurl=file:///mnt/yumserver/ ###指定本地的yum源仓库软件包
gpgcheck=0 ###关闭密钥验证
enabled=1 ###开启
[root@yumserver ~]# yum repolist all ###查看所有yum源信息
[root@yumserver ~]# yum makecache ###缓存配置的yum源
[root@yumserver ~]# yum list all | grep httpd ###查找Apache安装包
[root@yumserver ~]# yum -y install httpd
[root@yumserver ~]# rpm -qa | grep httpd
httpd-tools-2.4.6-80.el7.centos.x86_64
httpd-2.4.6-80.el7.centos.x86_64
[root@yumserver ~]# systemctl start httpd
[root@yumserver ~]# systemctl enable httpd
[root@yumserver ~]# systemctl status httpd
三、复制一份CentOS 7.5镜像文件到Apache默认web访问路径
[root@yumserver ~]# mkdir -p /var/www/html/centos/7/os/x86_64/
[root@yumserver ~]# cp -rp /mnt/yumserver/* /var/www/html/centos/7/os/x86_64/
四、yum客户端配置yum源为10.10.10.20并测试安装lrzsz软件
##清空yum源配置文件,为了方便测试
[root@centos7 ~]# mv /etc/yum.repos.d/* /tmp/
[root@centos7 ~]# vim /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base - 10.10.10.20
failovermethod=priority
baseurl=http://10.10.10.20/centos/$releasever/os/$basearch/
gpgcheck=1
enable=1
gpgkey=http://10.10.10.20/centos/$releasever/os/$basearch/RPM-GPG-KEY-CentOS-7
[root@centos7 ~]# yum makecache
[root@centos7 ~]# yum repolist all
[root@centos7 ~]# yum list all | grep lrzsz
lrzsz.x86_64 0.12.20-36.el7 base
[root@centos7 ~]# yum -y install lrzsz
[root@centos7 ~]# rpm -qa | grep lrzsz
lrzsz-0.12.20-36.el7.x86_64
五、下载的yum-utils工具软件包存放到yum源仓库并更新
###需要安装两个工具包createrepo(创建/更新yum源仓库RPM软件包)和yum-utils(辅助工具),方便后期更新yum源仓库,如果没有网络可以单独下载RPM软件进行安装
[root@yumserver 7]# yum -y install yum-utils createrepo
##复制yum-utils软件包和相关的依赖包
[root@yumserver ~]# cp -rp python-chardet-2.2.1-3.el7.noarch.rpm python-kitchen-1.1.1-5.el7.noarch.rpm yum-utils-1.1.31-54.el7_8.noarch.rpm /var/www/html/centos/7/os/x86_64/Packages/
###创建yum源仓库并更新
[root@yumserver ~]# createrepo /var/www/html/centos/7/os/x86_64/
Spawning worker 0 with 1987 pkgs
Spawning worker 1 with 1986 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
六、yum客户端更新yum缓存并安装yum-utils工具
[root@centos7 ~]# yum makecache
[root@centos7 ~]# rpm -qa | grep yum-utils
[root@centos7 ~]# yum list all | grep yum-utils
yum-utils.noarch 1.1.31-54.el7_8 base
[root@centos7 ~]# yum -y install yum-utils
[root@centos7 ~]# rpm -qa | grep yum-utils
yum-utils-1.1.31-54.el7_8.noarch
特殊操作:
为了方法yum源客户端一健获取yum源配置文件,可以上传一份yum源配置文件到yum源仓库服务器
Yum源仓库服务器操作:
[root@yumserver ~]# mkdir -p /var/www/html/repo/
[root@yumserver ~]# vim /var/www/html/repo/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base - 10.10.10.20
failovermethod=priority
baseurl=http://10.10.10.20/centos/$releasever/os/$basearch/
gpgcheck=1
enable=1
gpgkey=http://10.10.10.20/centos/$releasever/os/$basearch/RPM-GPG-KEY-CentOS-7
yum源客户端操作:
[root@centos7 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://10.10.10.20/repo/CentOS-Base.repo
[root@centos7 ~]# yum makecache