新建自定义yum源
手动创建repo文件
[test]
# yum仓库名称
name=test
# 源挂载的路径,注意本地是file:///(三斜杠) http:// ftp://
baseurl=file:///media/cdrom
# 1启用yum仓库,0不启用
enabled=1
# 0不器用自检,1启用自检
gpgcheck=0
使用yum-config-manager配置yum源
安装yum-utils
# 安装yum-utils
yum install yum-utils createrepo -y
## yum-utils:reposync同步工具
## createrepo:编辑yum库工具
手工指定yum源
# 添加北外的openstack-train源
yum-config-manager --add-repo=https://mirrors.bfsu.edu.cn/centos/8.4.2105/cloud/x86_64/openstack-train/
将gpgcheck设置为0
vim mirrors.bfsu.edu.cn_centos_8.4.2105_cloud_x86_64_openstack-train_.repo
# 将gpgcheck设置为0,如果不设置需要导入gpg
gpgcheck=0
RHEL8搭建内网yum源
如果很多台服务器,访问外网yum源时,会受限于带宽瓶颈,或安全问题,此时可以将repo同步到本地,再通过内网发布,通过内网访问,提高了安全性,yum下载包时也会非常快.
同步repo
# 创建yum同步目录
mkdir -p /data/repocache
# 查看repolist
yum repolist
[rhel8 root /etc/yum.repos.d]# yum repolist
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
仓库 id 仓库名称
AppStream AppStream
BaseOS BaseOS
epel Extra Packages for Enterprise Linux 8 - x86_64
openstack-train openstack-train
# 这个repolist就是repo文件中的[]和name中的信息
## 这个信息可以自行修改为便于识别的[]和name信息
[rhel8 root /etc/yum.repos.d]# cat openstack-train.repo
[openstack-train]
name=openstack-train
baseurl=https://mirrors.bfsu.edu.cn/centos/8.4.2105/cloud/x86_64/openstack-train/
enabled=1
gpgcheck=0
# 同步repo
# reposync --repo repo id(仓库id) -p 要存储在哪个目录
reposync --repo openstack-train -p /data/repocache
## 开始同步,会下载所有的rpm包
[rhel8 root ~]# reposync --repo openstack-train -p /data/openstack-train/
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
openstack-train 13 kB/s | 3.0 kB 00:00
(1/2229): MUMPS-devel-5.2.1-4.el8.x86_64.rpm 1.4 MB/s | 755 kB 00:00
(2/2229): MUMPS-common-5.2.1-4.el8.noarch.rpm 1.3 MB/s | 791 kB 00:00
(3/2229): MUMPS-5.2.1-4.el8.x86_64.rpm 4.4 MB/s | 3.3 MB 00:00
(4/2229): MUMPS-openmp-devel-5.2.1-4.el8.x86_64.rpm 1.7 MB/s | 774 kB 00:00
(5/2229): MUMPS-examples-5.2.1-4.el8.x86_64.rpm
# 查看下载好的rpm包
[rhel8 root ~]# ls -la /data/repocache/openstack-train/Packages/m
总用量 16640
drwxr-xr-x. 2 root root 4096 10月 7 05:29 .
drwxr-xr-x. 27 root root 231 10月 7 05:29 ..
-rw-r--r--. 1 root root 3480196 10月 7 05:29 MUMPS-5.2.1-4.el8.x86_64.rpm
-rw-r--r--. 1 root root 809844 10月 7 05:29 MUMPS-common-5.2.1-4.el8.noarch.rpm
-rw-r--r--. 1 root root 772716 10月 7 05:29 MUMPS-devel-5.2.1-4.el8.x86_64.rpm
-rw-r--r--. 1 root root 3735800 10月 7 05:29 MUMPS-examples-5.2.1-4.el8.x86_64.rpm
-rw-r--r--. 1 root root 3586568 10月 7 05:29 MUMPS-openmp-5.2.1-4.el8.x86_64.rpm
-rw-r--r--. 1 root root 792476 10月 7 05:29 MUMPS-openmp-devel-5.2.1-4.el8.x86_64.rpm
-rw-r--r--. 1 root root 3842224 10月 7 05:29 MUMPS-openmp-examples-5.2.1-4.el8.x86_64.rpm
根据rpm包创建repodata
# 将所有rpm移动到一起
find ./ -name *rpm -exec mv {} . \;
##
[rhel8 root ~]# cd /data/repocache/openstack-train
[rhel8 root /data/repocache/openstack-train]# find ./ -name *rpm -exec mv {} . \;
[rhel8 root /data/repocache/openstack-train]# ls
MUMPS-5.2.1-4.el8.x86_64.rpm MUMPS-openmp-devel-5.2.1-4.el8.x86_64.rpm
MUMPS-common-5.2.1-4.el8.noarch.rpm MUMPS-openmp-examples-5.2.1-4.el8.x86_64.rpm
MUMPS-devel-5.2.1-4.el8.x86_64.rpm Packages
MUMPS-examples-5.2.1-4.el8.x86_64.rpm XStatic-Angular-common-1.5.8.0-10.el8.noarch.rpm
MUMPS-openmp-5.2.1-4.el8.x86_64.rpm XStatic-Magic-Search-common-0.2.5.1-12.el8.noarch.rpm
# 根据rpm包创建repodata
[rhel8 root /data/repocache/openstack-train]# createrepo -v /data/repocache/openstack-train/
05:58:13: Version: 0.16.2 (Features: DeltaRPM LegacyWeakdeps )
05:58:13: Signal handler setup
05:58:13: Thread pool ready
# 目录下已经生成repodata
[rhel8 root /data/repocache/openstack-train]# ls -la
总用量 17120
drwxr-xr-x. 4 root root 4096 10月 7 05:58 .
drwxr-xr-x. 3 root root 29 10月 7 05:29 ..
-rw-r--r--. 1 root root 3480196 10月 7 05:29 MUMPS-5.2.1-4.el8.x86_64.rpm
-rw-r--r--. 1 root root 809844 10月 7 05:29 MUMPS-common-5.2.1-4.el8.noarch.rpm
-rw-r--r--. 1 root root 772716 10月 7 05:29 MUMPS-devel-5.2.1-4.el8.x86_64.rpm
-rw-r--r--. 1 root root 3735800 10月 7 05:29 MUMPS-examples-5.2.1-4.el8.x86_64.rpm
-rw-r--r--. 1 root root 3586568 10月 7 05:29 MUMPS-openmp-5.2.1-4.el8.x86_64.rpm
-rw-r--r--. 1 root root 792476 10月 7 05:29 MUMPS-openmp-devel-5.2.1-4.el8.x86_64.rpm
-rw-r--r--. 1 root root 3842224 10月 7 05:29 MUMPS-openmp-examples-5.2.1-4.el8.x86_64.rpm
drwxr-xr-x. 27 root root 231 10月 7 05:29 Packages
drwxr-xr-x. 2 root root 4096 10月 7 05:58 repodata
将yum源发布到web
# 关闭SELinux
# 关闭防火墙或者放行80端口
# 安装httpd
yum install httpd -y
# 添加一个虚拟主机的配置
vim /etc/httpd/conf.d/repo.conf
# 添加repo.conf配置信息
<VirtualHost *:80>
# 此处是服务器的内网ip地址
Servername 192.168.32.128
DocumentRoot /data/repocache/openstack-train
<Directory /data/repocache/openstack-train>
Require all granted
Options Indexes FollowSymLinks
</Directory>
</VirtualHost>
# 关闭httpd的welcome页面
mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.bak
# 重启httpd
systemctl restart httpd
# 将httpd服务设为开机自启
systemctl enable httpd
# 局域网访问下http://192.168.32.128
访问效果
在其他内网主机上添加该yum源
# 新建repo
vim /etc/yum.repos.d/openstack-train.conf
# 添加repo配置
[openstack-train]
# yum仓库名称
name=openstack-train
# 源挂载的路径
baseurl=http://192.168.32.128
# 1启用yum仓库,0不启用
enabled=1
# 0不器用自检,1启用自检
gpgcheck=0
# 查看repolist
yum repolist