[root@yum-server ~]# cat /etc/centos-release
CentOS Linux release 7.3.1611 (Core)
[root@yum-server ~]# uname -r
3.10.0-514.el7.x86_64
[root@yum-server ~]# ip a |awk 'NR==9{print $2}'|awk -F '/' '{print $1}'
10.0.7.190
[root@yum-server ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 10G 0 rom /mnt
sr1 11:1 1 484K 0 rom
vda 253:0 0 20G 0 disk
└─vda1 253:1 0 20G 0 part /
vdb 253:16 0 500G 0 disk
└─yumvg-yumlv 252:0 0 500G 0 lvm /yum //yum仓库存储位置,一般实际生产中建议容量设置较大
由于网络环境复杂,yum源服务
有多种来源
base源
、epel源
、zabbix源
、grafana源
源类型 | 版本 | repoid | 来源 | 使用者 |
---|---|---|---|---|
base源-ISO | Centos-7 | Centos-7-media.repo | CentOS-7-x86_64-Everything-1810.iso | 服务端 |
media.repo | http://10.0.7.190/repository/c7 | 客户端 | ||
base源-云 | Centos-7 | Centos-base-7.repo | http://mirrors.aliyun.com/repo/Centos-7.repo | 服务端 |
base-7.repo | http://10.0.7.190/repository/base-7 | 客户端 | ||
Centos-6 | Centos-base-6.repo | http://mirrors.aliyun.com/repo/Centos-6.repo | 服务端 | |
base-6.repo | http://10.0.7.190/repository/base-6 | 客户端 | ||
epel源 | Centos-7 | Centos-epel-7.repo | http://mirrors.aliyun.com/repo/epel-7.repo | 服务端 |
epel-7.repo | http://10.0.7.190/repository/epel-7 | 客户端 | ||
Centos-6 | Centos-epel-6.repo | http://mirrors.aliyun.com/repo/epel-6.repo | 服务端 | |
epel-6.repo | http://10.0.7.190/repository/epel-6 | 客户端 | ||
zabbix源 | Centos-7 | Centos-zabbix-7.repo | http://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/ | 服务端 |
zabbix-7.repo | http://10.0.7.190/repository/zabbix-7 | 客户端 | ||
Centos-6 | Centos-zabbix-6.repo | http://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/6/x86_64/ | 服务端 | |
epel-6.repo | http://10.0.7.190/repository/epel-6 | 客户端 | ||
grafana源 | Centos-6/7 | grafana.repo | https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/rpm | 服务端 |
grafana.repo | http://10.0.7.190/repository/grafana | 客户端 |
应用程序 | 作用 | 替代程序 |
---|---|---|
httpd | baseurl | nginx/vsftp |
yum-utils | repository的管理工具,提供reporsync服务 | |
createrepo | 编辑yum库工具 | |
plugin-priorities | 控制yum源更新优先级工具 |
[root@yum-server yum.repos.d]# cd
[root@yum-server ~]# cd /etc/yum.repos.d/
[root@yum-server yum.repos.d]# tar czvf repo-bk.tar.gz CentOS-*
CentOS-Base.repo
CentOS-CR.repo
CentOS-Debuginfo.repo
CentOS-fasttrack.repo
CentOS-Media.repo
CentOS-Sources.repo
CentOS-Vault.repo
[root@yum-server yum.repos.d]# rm -rf *.repo
[root@yum-server yum.repos.d]# ls
repo-bk.tar.gz
[root@yum-server yum.repos.d]# mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only
[root@yum-server yum.repos.d]# vim media.repo
[c7-media]
name=CentOS-$releasever-media
baseurl=file:///mnt
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
注:配置repo路径、关闭gbg校验、启用ISO镜像仓库
[root@yum-server yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id repo name status
c7-media CentOS-7-Media 10,019
repolist: 10,019
[root@yum-server yum.repos.d]# mkdir -p /yum/repository/c7
[root@yum-server yum.repos.d]# cp -ra /mnt/* /yum/repository/c7/
或者使用reposync同步
[root@yum-server yum.repos.d]#reposync -r c7-media -p /yum/repository/c7/
[root@yum-server ~]# createrepo -po /yum/repository/c7 /yum/repository/c7
[root@yum-server ~]# cd /etc/yum.repos.d/
[root@yum-server yum.repos.d]# mv CentOS-Media.repo CentOS-Media.repobak
[root@yum-server yum.repos.d]# ls
CentOS-Media.repobak repo-bk.tar.gz
[root@yum-server yum.repos.d]# wget -O /etc/yum.repos.d/Centos-base-7.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@yum-server yum.repos.d]# ls
backup Centos-base-7.repo
将所有的源增加`-7`,$releasever更换为`7`
[root@yum-server yum.repos.d]# vim Centos-7-base.repo
# CentOS-Base-7.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base-7]
name=CentOS-7 - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/os/$basearch/
http://mirrors.aliyuncs.com/centos/7/os/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/7/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates-7]
name=CentOS-7 - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/updates/$basearch/
http://mirrors.aliyuncs.com/centos/7/updates/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras-7]
name=CentOS-7 - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/extras/$basearch/
http://mirrors.aliyuncs.com/centos/7/extras/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/7/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus-7]
name=CentOS-7 - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/centosplus/$basearch/
http://mirrors.aliyuncs.com/centos/7/centosplus/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/7/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib-7]
name=CentOS-7 - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/contrib/$basearch/
http://mirrors.aliyuncs.com/centos/7/contrib/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/7/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[root@yum-server yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base-7: mirrors.aliyun.com
* extras-7: mirrors.aliyun.com
* updates-7: mirrors.aliyun.com
repo id repo name status
base-7/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,097
extras-7/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 341
updates-7/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 1,787
repolist: 12,225
创建本地仓库目录:
[root@yum-server ~]# mkdir /yum/repository/
同步阿里base源到本地base目录:
[root@yum-server ~]# reposync -r base-7 -p /yum/repository/
注:不用担心没有创建相关目录,系统自动创建相关目录,并下载,时间较长请耐心等待。
[root@yum-server ~]# createrepo -po /yum/repository/base-7 /yum/repository/base-7
[root@yum-server ~]# reposync -r base-7 -np /yum/repository/
注:时间同样较长,请耐心等待。
[root@yum-server ~]# createrepo --update /yum/repository/base-7
[root@yum-server yum.repos.d]# vim /yum/script-reposync/yum-update-base-7.sh
#!/bin/bash
echo 'Updating Base Aliyum Source'
DATETIME=`date +%F_%T`
exec > /var/log/repo/update-base-7.repo_$DATETIME.log
reposync -r base-7 -np /yum/repository/
if [ $? -eq 0 ];then
createrepo --update /yum/repository/base-7
echo "SUCESS: $DATETIME base.repo update successful"
else
echo "ERROR: $DATETIME base.repo update failed"
fi
[root@yum-server script-reposync]# crontab -e
# Updating Aliyum Source
00 06 * * 6 [ $(date +%d) -eq $(cal | awk 'NR==3{print $NF}') ] && /bin/bash /yum/script-reposync/yum-update-base-7.sh
每月第一个周六的06点更新阿里云base yum源
[root@yum-server ~]# cd /etc/yum.repos.d/
[root@yum-server yum.repos.d]# mv CentOS-Media.repo CentOS-Media.repobak
[root@yum-server yum.repos.d]# ls
CentOS-Media.repobak repo-bk.tar.gz
[root@yum-server yum.repos.d]# wget -O /etc/yum.repos.d/Centos-base-6.repo http://mirrors.aliyun.com/repo/Centos-6.repo
[root@yum-server yum.repos.d]# ls
backup Centos-base-7.repo
将所有的源增加`-6`,$releasever更换为`6`
[root@yum-server yum.repos.d]# vim Centos-base-6.repo
# CentOS-Base-6.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base-6]
name=CentOS-6 - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/6/os/$basearch/
http://mirrors.aliyuncs.com/centos/6/os/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/6/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
#released updates
[updates-6]
name=CentOS-6 - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/6/updates/$basearch/
http://mirrors.aliyuncs.com/centos/6/updates/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/6/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras-6]
name=CentOS-6 - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/6/extras/$basearch/
http://mirrors.aliyuncs.com/centos/6/extras/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/6/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages
[centosplus-6]
name=CentOS-6 - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/6/centosplus/$basearch/
http://mirrors.aliyuncs.com/centos/6/centosplus/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/6/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
#contrib - packages by Centos Users
[contrib-6]
name=CentOS-6 - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/6/contrib/$basearch/
http://mirrors.aliyuncs.com/centos/6/contrib/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/6/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
[root@yum-server yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base-6: mirrors.aliyun.com
* extras-6: mirrors.aliyun.com
* updates-6: mirrors.aliyun.com
repo id repo name status
base-6/x86_64 CentOS-6 - Base - mirrors.aliyun.com 6713
extras-6/x86_64 CentOS-6 - Extras - mirrors.aliyun.com 341
updates-6/x86_64 CentOS-6 - Updates - mirrors.aliyun.com 1,787
repolist: 12,225
创建本地仓库目录:
[root@yum-server ~]# mkdir /yum/repository/
同步阿里base源到本地base目录:
[root@yum-server ~]# reposync -r base-6 -p /yum/repository/
注:不用担心没有创建相关目录,系统自动创建相关目录,并下载,时间较长请耐心等待。
[root@yum-server ~]# createrepo -po /yum/repository/base-6 /yum/repository/base-6
[root@yum-server ~]# reposync -r base-6 -np /yum/repository/
注:时间同样较长,请耐心等待。
[root@yum-server ~]# createrepo --update /yum/repository/base-6
[root@yum-server yum.repos.d]# vim /yum/script-reposync/yum-update-base-6.sh
#!/bin/bash
echo 'Updating Base Aliyum Source'
DATETIME=`date +%F_%T`
exec > /var/log/repo/update-base-6.repo_$DATETIME.log
reposync -r base-6 -np /yum/repository/
if [ $? -eq 0 ];then
createrepo --update /yum/repository/base-6
echo "SUCESS: $DATETIME base.repo update successful"
else
echo "ERROR: $DATETIME base.repo update failed"
fi
[root@yum-server script-reposync]# crontab -e
# Updating Aliyum Source
00 06 * * 6 [ $(date +%d) -eq $(cal | awk 'NR==3{print $NF}') ] && /bin/bash /yum/script-reposync/yum-update-base-6.sh
每月第一个周六的06点更新阿里云base yum源
[root@yum-server ~]# cd /etc/yum.repos.d/
[root@yum-server yum.repos.d]# mv CentOS-Media.repo CentOS-Media.repobak
[root@yum-server yum.repos.d]# ls
CentOS-Media.repobak repo-bk.tar.gz
[root@yum-server yum.repos.d]# wget -O /etc/yum.repos.d/Centos-epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@yum-server yum.repos.d]# ls
CentOS-Media.repobak Centos-epel-6.repo repo-bk.tar.gz
将所有的源增加`-7`
[root@yum-server yum.repos.d]# vim Centos-epel-7.repo
[epel-7]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[epel-7-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
[epel-7-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
~
[root@yum-server yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id repo name status
epel-7/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,249
repolist: 13,249
创建本地仓库目录:
[root@yum-server ~]# mkdir /yum/repository/
同步阿里epel源到本地epel目录:
[root@yum-server ~]# reposync -r epel-7 -p /yum/repository/
注:不用担心没有创建相关目录,系统自动创建相关目录,并下载,时间较长请耐心等待。
[root@yum-server ~]# createrepo -po /yum/repository/epel-7 /yum/repository/epel-7
[root@yum-server ~]# reposync -r epel-7 -np /yum/repository/
注:时间同样较长,请耐心等待。
[root@yum-server ~]# createrepo --update /yum/repository/epel-7
[root@yum-server yum.repos.d]# vim /yum/script-reposync/yum-update-epel-7.sh
#!/bin/bash
echo 'Updating Epel Aliyum Source'
DATETIME=`date +%F_%T`
exec > /var/log/repo/update-epel-7.repo_$DATETIME.log
reposync -r epel-7 -np /yum/repository/
if [ $? -eq 0 ];then
createrepo --update /yum/repository/epel-7
echo "SUCESS: $DATETIME epel.repo update successful"
else
echo "ERROR: $DATETIME epel.repo update failed"
fi
[root@yum-server script-reposync]# crontab -e
# Updating Aliyum Source
00 06 * * 6 [ $(date +%d) -eq $(cal | awk 'NR==4{print $NF}') ] && /bin/bash /yum/script-reposync/yum-update-epel-7.sh
每月第2️个周六的06点更新阿里云epel-7 yum源
[root@yum-server ~]# cd /etc/yum.repos.d/
[root@yum-server yum.repos.d]# mv CentOS-Media.repo CentOS-Media.repobak
[root@yum-server yum.repos.d]# ls
CentOS-Media.repobak repo-bk.tar.gz
[root@yum-server yum.repos.d]# wget -O /etc/yum.repos.d/Centos-epel-6.repo http://mirrors.aliyun.com/repo/epel-6.repo
[root@yum-server yum.repos.d]# ls
CentOS-Media.repobak Centos-epel-6.repo repo-bk.tar.gz
将所有的源增加`-6`
[root@yum-server yum.repos.d]# vim Centos-epel-6.repo
[epel-6]
name=Extra Packages for Enterprise Linux 6 - $basearch
baseurl=http://mirrors.aliyun.com/epel/6/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
[epel-debuginfo-6]
name=Extra Packages for Enterprise Linux 6 - $basearch - Debug
baseurl=http://mirrors.aliyun.com/epel/6/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=0
[epel-source-6]
name=Extra Packages for Enterprise Linux 6 - $basearch - Source
baseurl=http://mirrors.aliyun.com/epel/6/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=0
~
[root@yum-server yum.repos.d]# yum repolist
Centos-7-Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id repo name status
epel-6/x86_64 Extra Packages for Enterprise Linux 6 - x86_64 12,587
repolist: 12,587
创建本地epel目录:
[root@yum-server ~]# mkdir /yum/repository/
同步阿里epel源到本地epel目录:
[root@yum-server ~]# reposync -r epel-6 -p /yum/repository/
注:不用担心没有创建相关目录,系统自动创建相关目录,并下载,时间较长请耐心等待。
[root@yum-server ~]# createrepo -po /yum/repository/epel-6 /yum/repository/epel-6
[root@yum-server ~]# reposync -r epel-6 -np /yum/repository/
注:时间同样较长,请耐心等待。
[root@yum-server ~]# createrepo --update /yum/repository/epel-6
[root@yum-server yum.repos.d]# vim /yum/script-reposync/yum-update-epel-6.sh
#!/bin/bash
echo 'Updating Epel Aliyum Source'
DATETIME=`date +%F_%T`
exec > /var/log/repo/update-epel-6.repo_$DATETIME.log
reposync -r epel-6 -np /yum/repository/
if [ $? -eq 0 ];then
createrepo --update /yum/repository/epel-6
echo "SUCESS: $DATETIME epel.repo update successful"
else
echo "ERROR: $DATETIME epel.repo update failed"
fi
[root@yum-server script-reposync]# crontab -e
# Updating Aliyum Source
00 06 * * 6 [ $(date +%d) -eq $(cal | awk 'NR==4{print $NF}') ] && /bin/bash /yum/script-reposync/yum-update-epel-6.sh
每月第2️个周六的06点更新阿里云epel-6 yum源
[root@yum-server ~]# cd /etc/yum.repos.d/
[root@yum-server yum.repos.d]# ls
CentOS-Media.repo repo-bk.tar.gz
[root@yum-server yum.repos.d]# mkdir backup
[root@yum-server yum.repos.d]# mv *.repo backup/
[root@yum-server yum.repos.d]# ls
backup repo-bk.tar.gz
[root@yum-server yum.repos.d]# vim Centos-zabbix-7.repo
[zabbix-7]
name=Zabbix Official Repository - \$basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/\$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
[zabbix-non-supported-7]
name=Zabbix Official Repository non-supported - \$basearch
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/\$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
~
[root@yum-server yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id repo name status
zabbix-7/x86_64 Zabbix Official Repository - \x86_64 289
zabbix-non-supported-7/x86_64 Zabbix Official Repository non-supported - \x86_64 4
repolist: 293
创建本地zabbix目录:
[root@yum-server ~]# mkdir /yum/repository/
同步阿里zabbix源到本地zabbix目录:
[root@yum-server ~]# reposync -r zabbix-7 -p /yum/repository/
注:不用担心没有创建相关目录,系统自动创建相关目录,并下载,时间较长请耐心等待。
[root@yum-server ~]# createrepo -po /yum/repository/zabbix-7 /yum/repository/zabbix-7
[root@yum-server ~]# reposync -r zabbix-7 -np /yum/repository/
[root@yum-server ~]# createrepo --update /yum/repository/zabbix-7
[root@yum-server yum.repos.d]# vim /yum/script-reposync/yum-update-zabbix-7.sh
#!/bin/bash
echo 'Updating Zabbix Aliyum Source'
DATETIME=`date +%F_%T`
exec > /var/log/repo/update-zabbix-7.repo_$DATETIME.log
reposync -r zabbix-7 -np /yum/repository/
if [ $? -eq 0 ];then
createrepo --update /yum/repository/zabbix-7
echo "SUCESS: $DATETIME zabbix.repo update successful"
else
echo "ERROR: $DATETIME zabbix.repo update failed"
fi
[root@yum-server script-reposync]# crontab -e
# Updating Aliyum Source
00 06 * * 6 [ $(date +%d) -eq $(cal | awk 'NR==5{print $NF}') ] && /bin/bash /yum/script-reposync/yum-update-zabbix-7.sh
每月第三个周六的06点更新阿里云zabbix-7 yum源
[root@yum-server ~]# cd /etc/yum.repos.d/
[root@yum-server yum.repos.d]# ls
CentOS-Media.repo repo-bk.tar.gz
[root@yum-server yum.repos.d]# mkdir backup
[root@yum-server yum.repos.d]# mv *.repo backup/
[root@yum-server yum.repos.d]# ls
backup repo-bk.tar.gz
[root@yum-server yum.repos.d]# vim Centos-zabbix-6.repo
[zabbix-6]
name=Zabbix Official Repository - \$basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/6/\$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
[zabbix-non-supported-6]
name=Zabbix Official Repository non-supported - \$basearch
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/6/\$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
~
[root@yum-server yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id repo name status
zabbix-6/x86_64 Zabbix Official Repository - \x86_64 157
zabbix-non-supported-6/x86_64 Zabbix Official Repository non-supported - \x86_64 15
repolist: 172
创建本地zabbix目录:
[root@yum-server ~]# mkdir /yum/repository/
同步阿里zabbix源到本地zabbix目录:
[root@yum-server ~]# reposync -r zabbix-6 -p /yum/repository/
注:不用担心没有创建相关目录,系统自动创建相关目录,并下载,时间较长请耐心等待。
[root@yum-server ~]# createrepo -po /yum/repository/zabbix-6 /yum/repository/zabbix-6
[root@yum-server ~]# reposync -r zabbix-6 -np /yum/repository/
[root@yum-server ~]# createrepo --update /yum/repository/zabbix-6
[root@yum-server yum.repos.d]# vim /yum/script-reposync/yum-update-zabbix-6.sh
#!/bin/bash
echo 'Updating Zabbix Aliyum Source'
DATETIME=`date +%F_%T`
exec > /var/log/repo/update-zabbix-6.repo_$DATETIME.log
reposync -r zabbix-6 -np /yum/repository/
if [ $? -eq 0 ];then
createrepo --update /yum/repository/zabbix-6
echo "SUCESS: $DATETIME zabbix.repo update successful"
else
echo "ERROR: $DATETIME zabbix.repo update failed"
fi
[root@yum-server script-reposync]# crontab -e
# Updating Aliyum Source
00 06 * * 6 [ $(date +%d) -eq $(cal | awk 'NR==5{print $NF}') ] && /bin/bash /yum/script-reposync/yum-update-zabbix-6.sh
每月第三个周六的06点更新阿里云zabbix-6 yum源
grafana镜像源目前国内只有清华大学镜像站
效果好一点,本次搭建使用清华grafana源
[root@yum-server ~]# cd /etc/yum.repos.d/
[root@yum-server yum.repos.d]# mv CentOS-Media.repo CentOS-Media.repobak
[root@yum-server yum.repos.d]# ls
CentOS-Media.repobak repo-bk.tar.gz
[root@yum-server yum.repos.d]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@yum-server yum.repos.d]# ls
CentOS-Media.repobak epel.repo repo-bk.tar.gz
[root@yum-server yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Loading mirror speeds from cached hostfile
repo id repo name status
grafana grafana 96
repolist: 96
创建本地epel目录:
[root@yum-server ~]# mkdir /yum/repository/
同步清华grafana源到本地grafana目录:
[root@yum-server ~]# reposync -r grafana -p /yum/repository/
注:不用担心没有创建相关目录,系统自动创建相关目录,并下载,时间较长请耐心等待。
[root@yum-server ~]# createrepo -po /yum/repository/grafana /yum/repository/grafana
[root@yum-server ~]# reposync -r grafana -np /yum/repository/
注:时间同样较长,请耐心等待。
[root@yum-server ~]# createrepo --update /yum/repository/grafana
[root@yum-server yum.repos.d]# vim /yum/script-reposync/yum-update-grafana.sh
#!/bin/bash
echo 'Updating Grafana Tsinghua Source'
DATETIME=`date +%F_%T`
exec > /var/log/repo/update-grafana.repo_$DATETIME.log
reposync -r grafana -np /yum/repository/
if [ $? -eq 0 ];then
createrepo --update /yum/repository/grafana
echo "SUCESS: $DATETIME grafana.repo update successful"
else
echo "ERROR: $DATETIME grafana.repo update failed"
fi
[root@yum-server script-reposync]# crontab -e
# Updating Tsinghua Source
00 06 * * 6 [ $(date +%d) -eq $(cal | awk 'NR==6{print $NF}') ] && /bin/bash /yum/script-reposync/yum-update-grafana.sh
每月第四个周六的06点更新清华云grafana yum源
NR==3 第一周、NR==4 第二周、NR==5 第三周、NR==6第四周
打开httpd服务程序的主配置文件/etc/httpd/conf/httpd.conf
,将约第119行用于定义网站数据保存路径的参数DocumentRoot
修改为/yum/
,同时还需要将约第124行用于定义目录权限的参数Directory
后面的路径也修改为/yum/
,配置文件修改完毕后即可保存并退出。
[root@yum-server yum.repos.d]yum install -y httpd
[root@yum-server yum.repos.d]firewall-cmd --add-service=httpd --permanent
[root@yum-server conf]# vim /etc/httpd/conf/httpd.conf
………………省略部分输出信息………………
113
114 #
115 # DocumentRoot: The directory out of which you will serve your
116 # documents. By default, all requests are taken from this directory, bu t
117 # symbolic links and aliases may be used to point to other locations.
118 #
119 DocumentRoot "/yum"
120
121 #
122 # Relax access to content within /var/www.
123 #
124 <Directory "/yum">
125 AllowOverride None
126 # Allow open access:
127 Require all granted
128 </Directory>
………………省略部分输出信息………………
[root@yum-server ~]# systemctl restart httpd && systemctl enable httpd
repo汇总:http://10.0.7.190/repository/
base-ISO-yum源: http://10.0.7.190/repository/c7/
base-7-yum云源: http://10.0.7.190/repository/base-7/
base-6-yum云源: http://10.0.7.190/repository/base-6/
eple-7-yum源: http://10.0.7.190/repository/epel-7/
eple-6-yum源: http://10.0.7.190/repository/epel-6/
zabbix-7-yum源: http://10.0.7.190/repository/zabbix-7/
zabbix-6-yum源: http://10.0.7.190/repository/zabbix-6/
grafana-yum源: http://10.0.7.190/repository/grafana/
[root@centos73_test /etc/yum.repos.d]# vim /etc/yum.repos.d/media.repo
[media]
name=media
baseurl=http://10.0.7.190/repository/c7
enabled=1
gpgcheck=0
[root@centos73_test /etc/yum.repos.d]# yum clean all
[root@centos73_test /etc/yum.repos.d]# yum makecache
[root@centos73_test /etc/yum.repos.d]# yum install httpd
Loaded plugins: langpacks, product-id, subscription-manager
………………省略部分输出信息………………
Dependencies Resolved
===================================================================================================================================================================
Package Arch Version Repository Size
===================================================================================================================================================================
Installing:
httpd x86_64 2.4.6-88.el7.centos media 2.7 M
Transaction Summary
===================================================================================================================================================================
Install 1 Package
Total download size: 2.7 M
Installed size: 9.4 M
Is this ok [y/d/N]:
………………省略部分输出信息………………
Complete!
[root@centos73_test /etc/yum.repos.d]# vim /etc/yum.repos.d/base-7.repo
[base-7]
name=base
baseurl=http://10.0.7.190/repository/base-7
enabled=1
gpgcheck=0
[root@centos73_test /etc/yum.repos.d]# yum clean all
[root@centos73_test /etc/yum.repos.d]# yum makecache
[root@centos73_test /etc/yum.repos.d]# yum install httpd
………………省略部分输出信息………………
Dependencies Resolved
===================================================================================================================================================================
Package Arch Version Repository Size
===================================================================================================================================================================
Installing:
httpd x86_64 2.4.6-90.el7.centos base 2.7 M
Updating for dependencies:
httpd-tools x86_64 2.4.6-90.el7.centos base 91 k
Transaction Summary
===================================================================================================================================================================
Install 1 Package
Upgrade ( 1 Dependent package)
Total download size: 2.8 M
Is this ok [y/d/N]:
………………省略部分输出信息………………
[root@centos63_test /etc/yum.repos.d]# vim /etc/yum.repos.d/base-6.repo
[base-6]
name=base
baseurl=http://10.0.7.190/repository/base-6
enabled=1
gpgcheck=0
[root@centos63_test /etc/yum.repos.d]# yum clean all
[root@centos63_test /etc/yum.repos.d]# yum makecache
[root@centos63_test /etc/yum.repos.d]# yum install acl
………………省略部分输出信息………………
Resolving Dependencies
--> Running transaction check
---> Package acl.x86_64 0:2.2.49-6.el6 will be updated
---> Package acl.x86_64 0:2.2.51-14.el7 will be an update
--> Processing Dependency: libacl = 2.2.51-14.el7 for package: acl-2.2.51-14.el6.x86_64
--> Processing Dependency: libc.so.6(GLIBC_2.14)(64bit) for package: acl-2.2.51-14.el6.x86_64
--> Finished Dependency Resolution
Total download size: 15 k
Installed size: 24 k
Is this ok [y/d/N]: y
………………省略部分输出信息………………
[root@centos73_test /etc/yum.repos.d]# vim /etc/yum.repos.d/epel-7.repo
[epel-7]
name=base
baseurl=http://10.0.7.190/repository/epel-7
enabled=1
gpgcheck=0
[root@centos73_test /etc/yum.repos.d]# yum clean all
[root@centos73_test /etc/yum.repos.d]# yum makecache
[root@centos73_test /etc/yum.repos.d]# yum install 2ping
………………省略部分输出信息………………
Dependencies Resolved
===================================================================================================================================================================
Package Arch Version Repository Size
===================================================================================================================================================================
Installing:
2ping noarch 3.2.1-2.el7 epel-7 62 k
Transaction Summary
===================================================================================================================================================================
Install 1 Package
Total download size: 62 k
Installed size: 204 k
Is this ok [y/d/N]:
………………省略部分输出信息………………
[root@centos63_test /etc/yum.repos.d]# vim /etc/yum.repos.d/epel-6.repo
[epel-6]
name=base
baseurl=http://10.0.7.190/repository/epel-6
enabled=1
gpgcheck=0
[root@centos63_test /etc/yum.repos.d]# yum clean all
[root@centos63_test /etc/yum.repos.d]# yum makecache
[root@centos63_test /etc/yum.repos.d]# yum install 2ping
………………省略部分输出信息………………
Dependencies Resolved
===================================================================================================================================================================
Package Arch Version Repository Size
===================================================================================================================================================================
Installing:
2ping noarch 3.2.1-2.el6 epel-6 62 k
Transaction Summary
===================================================================================================================================================================
Install 1 Package(s)
Total download size: 62 k
Installed size: 205 k
Is this ok [y/N]:
………………省略部分输出信息………………
[root@centos73_test /etc/yum.repos.d]# vim etc/yum.repos.d/zabbix-7.repo
[zabbix-7]
name=zabbix-7
baseurl=http://10.0.7.190/repository/zabbix-7
enabled=1
gpgcheck=0
[root@centos73_test /etc/yum.repos.d]yum clean all
[root@centos73_test /etc/yum.repos.d]yum makecache
[root@centos73_test /etc/yum.repos.d]# yum install zabbix-get
………………省略部分输出信息………………
Dependencies Resolved
===================================================================================================================================================================
Package Arch Version Repository Size
===================================================================================================================================================================
Installing:
zabbix-get x86_64 4.0.19-1.el7 zabbix-7 294 k
Transaction Summary
===================================================================================================================================================================
Install 1 Package
Total download size: 294 k
Installed size: 1.2 M
Is this ok [y/d/N]:
………………省略部分输出信息………………
[root@centos63_test /etc/yum.repos.d]# vim etc/yum.repos.d/zabbix-6.repo
[zabbix-6]
name=zabbix-6
baseurl=http://10.0.7.190/repository/zabbix-6
enabled=1
gpgcheck=0
[root@centos63_test /etc/yum.repos.d]yum clean all
[root@centos63_test /etc/yum.repos.d]yum makecache
[root@centos63_test /etc/yum.repos.d]# yum install zabbix-agent
………………省略部分输出信息………………
Dependencies Resolved
===================================================================================================================================================================
Package Arch Version Repository Size
===================================================================================================================================================================
Updating:
zabbix-agent x86_64 4.0.19-1.el6 zabbix-6 418 k
Transaction Summary
===================================================================================================================================================================
Upgrade 1 Package(s)
Total download size: 418 k
Is this ok [y/N]:
………………省略部分输出信息………………
[root@centos73_test /etc/yum.repos.d]# vim etc/yum.repos.d/grafana.repo
[grafana]
name=grafana
baseurl=http://10.0.7.190/repository/grafana
enabled=1
gpgcheck=0
[root@centos73_test /etc/yum.repos.d]# yum clean all
Loaded plugins: aliases, changelog, fastestmirror, langpacks, tmprepo, verify, versionlock
Cleaning repos: grafana
Cleaning up everything
[root@centos73_test /etc/yum.repos.d]# yum makecache
Loaded plugins: aliases, changelog, fastestmirror, langpacks, tmprepo, verify, versionlock
grafana | 2.9 kB 00:00:00
(1/3): grafana/filelists_db | 553 kB 00:00:00
(2/3): grafana/primary_db | 29 kB 00:00:00
(3/3): grafana/other_db | 6.0 kB 00:00:00
[root@centos73_test /etc/yum.repos.d]# yum install grafana
………………省略部分输出信息………………
Dependencies Resolved
===================================================================================================================================================================
Package Arch Version Repository Size
===================================================================================================================================================================
Installing:
grafana x86_64 6.7.2-1 grafana 61 M
Transaction Summary
===================================================================================================================================================================
Install 1 Package (+37 Dependent packages)
Upgrade ( 1 Dependent package)
Total download size: 72 M
Is this ok [y/d/N]: y
Downloading packages:
grafana-6.7.2-1.x86_64.rpm
--------------------------------------------------------------------------------
………………省略部分输出信息………………
Complete!
yum源服务器搭建根据来源不同,有多种方式,以上述实验为例,搭建步骤如下:
1. 规划好yum仓库存储容量(/yum/repository/,500G)
2. 采用国内源(阿里云、华为云、各大高校镜像库等)
3. 光盘镜像采用everything,确保rpm包尽可能完整
4. centos6和centos7采用同一台服务器部署时,注意更改base.repo文件中`$releasever`变量
5. 根据来源准备服务器端repo配置文件(repo编写方式大同小异,除epel源、base源外其他的均需手动编写配置)
6. 对外提供服务可采用web(apache、nginx)、ftp(vsftp)等方式,注意服务器安全,尽可能开启防火墙,通过放行服务端口策略确保网络安全
7. 其他yum源更新脚本可根据实际情况参考编写
服务器端计划任务:
[root@yum-server yum.repos.d]# crontab -l
# Updating Aliyum Source
#00 06 * * 6 [ $(date +%d) -eq $(cal | awk 'NR==3{print $NF}') ] && /bin/bash /yum/script-reposync/yum-update-epel.sh
#00 06 * * 6 [ $(date +%d) -eq $(cal | awk 'NR==4{print $NF}') ] && /bin/bash /yum/script-reposync/yum-update-zabbix.sh
#00 06 * * 6 [ $(date +%d) -eq $(cal | awk 'NR==5{print $NF}') ] && /bin/bash /yum/script-reposync/yum-update-base.sh
#00 06 * * 6 [ $(date +%d) -eq $(cal | awk 'NR==6{print $NF}') ] && /bin/bash /yum/script-reposync/yum-update-grafana.sh
00 00 25 * * /bin/bash /yum/script-reposync/yum-update-base-7.sh
00 00 26 * * /bin/bash /yum/script-reposync/yum-update-base-6.sh
00 01 * * * /bin/bash /yum/script-reposync/yum-update-epel-7.sh
00 02 * * * /bin/bash /yum/script-reposync/yum-update-epel-6.sh
00 04 * * * /bin/bash /yum/script-reposync/yum-update-zabbix-7.sh
00 05 * * * /bin/bash /yum/script-reposync/yum-update-zabbix-6.sh
00 06 * * * /bin/bash /yum/script-reposync/yum-update-grafana.sh
服务端repo:
[root@yum-server yum.repos.d]# ls
Centos-7-media.repo Centos-base-6.repo Centos-base-7.repo Centos-epel-6.repo Centos-epel-7.repo Centos-zabbix-6.repo Centos-zabbix-7.repo grafana.repo
客户端repo:
[root@centos73_test /etc/yum.repos.d]#ls
base-7.repo base-6.repo epel-7.repo epel-6.repo media.repo zabbix-7.repo zabbix-6.repo grafana.repo
客户端repo配置文件:
[root@centos73_test /etc/yum.repos.d]#cat /etc/yum.repos.d/centos-7.repo
[base-7]
name=base
baseurl=http://10.0.7.190/repository/base-7
enabled=1
gpgcheck=0
[epel-7]
name=epel-7
baseurl=http://10.0.7.190/repository/epel-7
enabled=1
gpgcheck=0
[zabbix-7]
name=zabbix-7
baseurl=http://10.0.7.190/repository/zabbix-7
enabled=1
gpgcheck=0
[root@centos73_test /etc/yum.repos.d]#cat /etc/yum.repos.d/centos-6.repo
[base-6]
name=base
baseurl=http://10.0.7.190/repository/base-6
enabled=1
gpgcheck=0
[epel-6]
name=epel-6
baseurl=http://10.0.7.190/repository/epel-6
enabled=1
gpgcheck=0
[zabbix-6]
name=zabbix-6
baseurl=http://10.0.7.190/repository/zabbix-6
enabled=1
gpgcheck=0