一、CentOS6/7 yum源搭建
1、 本地yum源搭建
1.1 将系统镜像复制到空间较大的目录
[root@simonlinux smb]# ls
CentOS-7-x86_64-DVD-1810.iso
1.2 创建挂载目录并挂载系统镜像
[root@simonlinux smb]# mkdir /local-yum
[root@simonlinux smb]# mount -o loop CentOS-7-x86_64-DVD-1810.iso /local-yum
mount: /dev/loop0 is write-protected, mounting read-only
[root@simonlinux smb]# ls /local-yum
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
1.3 修改yum配置文件,把原先的配置先备份了
[root@simonlinux smb]# cd /etc/yum.repos.d
[root@simonlinux yum.repos.d]# mkdir bak
[root@simonlinux yum.repos.d]# mv *.repo ./bak
1.4 新建local.repo
[root@simonlinux yum.repos.d]# vim /etc/yum.repos.d/local.repo
[base]
name=CentOS76
baseurl=file:///local-yum
enabled=1
gpgcheck=0
1.4 清除下yum 原有的信息,载入新的缓存
[root@simonlinux yum.repos.d]# yum clean all
[root@simonlinux yum.repos.d]# yum makecache
1.5 验证yum源
[root@simonlinux yum.repos.d]# yum repolist
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
repo id repo name status
base CentOS76 5,152
repolist: 5,152
2、 搭建局域网yum源
2.1、 安装Http服务和xml生成工具,由于安装系统时已经顺便安装了相应的安装包,所以此处无须再进行安装。
[root@simonlinux ~]# yum install httpd createrepo
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Repository base is listed more than once in the configuration
Package httpd-2.4.6-88.el7.x86_64 already installed and latest version
Package createrepo-0.9.9-28.el7.noarch already installed and latest version
Nothing to do
2.2、 新建存放yum源文件的目录并将相关文件复制进去
[root@simonlinux smb]# ls
CentOS-7-x86_64-DVD-1810.iso
[root@simonlinux smb]# mkdir /mnt
[root@simonlinux smb]# mount -o loop CentOS-7-x86_64-DVD-1810.iso /mnt
mount: /dev/loop0 is write-protected, mounting read-only
[root@simonlinux smb]# ls /mnt
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 ~]# mkdir -p /var/www/html/yum.repo/centos/76
[root@localhost ~]# cp -R /mnt/* /var/www/html/yum.repo/centos/76/
2.3、启动http服务
[root@simonlinux ~]# systemctl restart httpd
[root@simonlinux ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2023-04-19 22:26:29 CST; 7s ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 15983 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
Main PID: 15989 (httpd)
Status: "Processing requests..."
Tasks: 8
CGroup: /system.slice/httpd.service
├─15989 /usr/sbin/httpd -DFOREGROUND
├─15990 /usr/libexec/nss_pcache 491523 off
├─15994 /usr/sbin/httpd -DFOREGROUND
├─15995 /usr/sbin/httpd -DFOREGROUND
├─15996 /usr/sbin/httpd -DFOREGROUND
├─15997 /usr/sbin/httpd -DFOREGROUND
└─15998 /usr/sbin/httpd -DFOREGROUND
Apr 19 22:26:29 simonlinux.com systemd[1]: Starting The Apache HTTP Server...
Apr 19 22:26:29 simonlinux.com systemd[1]: Started The Apache HTTP Server.
发现网页端无法打开,将网站端口添加到防火墙规则里并重启防火墙
[root@simonlinux ~]# firewall-cmd --add-port=80/tcp --permanent
success
[root@simonlinux ~]# systemctl restart firewalld.service
[root@simonlinux ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: eno1
sources:
services: dhcpv6-client ssh
ports: 5901-5905/tcp 80/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
设置http服务开机启动
[root@simonlinux ~]# systemctl enable httpd
2.4、配置客户端yum源配置
[root@localhost home]# cd /etc/yum.repos.d/
[root@localhost home]# mkdir bak
[root@localhost yum.repos.d]# cp *.repo bak/
[root@localhost yum.repos.d]# vim CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
baseurl=http://192.168.15.10/yum.repo/centos/76
gpgcheck=0
enabled=1
清除下yum 原有的信息,载入新的缓存
[root@simonlinux yum.repos.d]# yum clean all
[root@simonlinux yum.repos.d]# yum makecache
验证yum源
[root@simonlinux yum.repos.d]# yum repolist
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
repo id repo name status
base CentOS76 5,152
repolist: 5,152
二、CentOS8 yum源搭建
1、本地yum源搭建
1.1 将系统镜像复制到空间较大的目录
[root@simonlinux smb]# ls
CentOS-7-x86_64-DVD-1810.iso
1.2 创建挂载目录并挂载系统镜像
[root@simonlinux smb]# mkdir /local-yum
[root@simonlinux smb]# mount -o loop CentOS-7-x86_64-DVD-1810.iso /local-yum
mount: /dev/loop0 is write-protected, mounting read-only
[root@simonlinux smb]# ls /local-yum
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
1.3 修改yum配置文件,把原先的配置先备份了
[root@simonlinux smb]# cd /etc/yum.repos.d
[root@simonlinux yum.repos.d]# mkdir bak
[root@simonlinux yum.repos.d]# mv *.repo ./bak
1.4 新建local.repo
[root@simonlinux yum.repos.d]# vim /etc/yum.repos.d/local.repo
[base]
name=CentOS76
baseurl=file:///local-yum
enabled=1
gpgcheck=0
1.4 清除下yum 原有的信息,载入新的缓存
[root@simonlinux yum.repos.d]# yum clean all
[root@simonlinux yum.repos.d]# yum makecache
1.5 验证yum源
[root@simonlinux yum.repos.d]# yum repolist
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
repo id repo name status
base CentOS76 5,152
repolist: 5,152
2、 搭建局域网yum源
2.1、 安装Http服务和xml生成工具,由于安装系统时已经顺便安装了相应的安装包,所以此处无须再进行安装。
[root@simonlinux ~]# yum install httpd createrepo
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Repository base is listed more than once in the configuration
Package httpd-2.4.6-88.el7.x86_64 already installed and latest version
Package createrepo-0.9.9-28.el7.noarch already installed and latest version
Nothing to do
2.2、新建存放yum源文件的目录并将相关文件复制进去
[root@simonlinux smb]# ls
CentOS-7-x86_64-DVD-1810.iso
[root@simonlinux smb]# mkdir /mnt
[root@simonlinux smb]# mount -o loop CentOS-7-x86_64-DVD-1810.iso /mnt
mount: /dev/loop0 is write-protected, mounting read-only
[root@simonlinux smb]# ls /mnt
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 ~]# mkdir -p /var/www/html/yum.repo/centos/76
[root@localhost ~]# cp -R /mnt/* /var/www/html/yum.repo/centos/76/
2.3、启动http服务
[root@simonlinux ~]# systemctl restart httpd
[root@simonlinux ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2023-04-19 22:26:29 CST; 7s ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 15983 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
Main PID: 15989 (httpd)
Status: "Processing requests..."
Tasks: 8
CGroup: /system.slice/httpd.service
├─15989 /usr/sbin/httpd -DFOREGROUND
├─15990 /usr/libexec/nss_pcache 491523 off
├─15994 /usr/sbin/httpd -DFOREGROUND
├─15995 /usr/sbin/httpd -DFOREGROUND
├─15996 /usr/sbin/httpd -DFOREGROUND
├─15997 /usr/sbin/httpd -DFOREGROUND
└─15998 /usr/sbin/httpd -DFOREGROUND
Apr 19 22:26:29 simonlinux.com systemd[1]: Starting The Apache HTTP Server...
Apr 19 22:26:29 simonlinux.com systemd[1]: Started The Apache HTTP Server.
发现网页端无法打开,将网站端口添加到防火墙规则里并重启防火墙
[root@simonlinux ~]# firewall-cmd --add-port=80/tcp --permanent
success
[root@simonlinux ~]# systemctl restart firewalld.service
[root@simonlinux ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: eno1
sources:
services: dhcpv6-client ssh
ports: 5901-5905/tcp 80/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
设置http服务开机启动
[root@simonlinux ~]# systemctl enable httpd
2.4、配置客户端yum源配置
[root@localhost home]# cd /etc/yum.repos.d/
[root@localhost home]# mkdir bak
[root@localhost yum.repos.d]# cp *.repo bak/192.168.15.10
[root@localhost yum.repos.d]# vim CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
baseurl=http://192.168.15.10/yum.repo/centos/76
gpgcheck=0
enabled=1
清除下yum 原有的信息,载入新的缓存
[root@simonlinux yum.repos.d]# yum clean all
[root@simonlinux yum.repos.d]# yum makecache
验证yum源
[root@simonlinux yum.repos.d]# yum repolist
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
repo id repo name status
base CentOS76 5,152
repolist: 5,152