环境:Centos7
[root@RepoServer ~]# fdisk -l
[root@RepoServer ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xe31034ab.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-419430399, default 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-419430399, default 419430399): 419430399
Partition 1 of type Linux and of size 200 GiB is set
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@RepoServer ~]# mkfs.ext4 /dev/sdb1
[root@RepoServer ~]# mkdir /reposource
[root@RepoServer ~]# mount /dev/sdb1 /reposource/
现在阿里云镜像源repo文件到本地:
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
安装httpd服务,用于提供存放yum源:
yum install httpd -y
service httpd start
setenforce 0
reboot
安装yum-utils提供reporsync服务:
yum install yum-utils -y
vi /etc/httpd/conf/httpd.conf
DocumentRoot "/var/www/html"改为DocumentRoot "/reposource" <下面目录也要>
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
改为Allow from all
选择指定仓库标识作为本地yum源:
执行yum repolist命令查看yum仓库标识
[root@RepoServer ~]# reposync -r base -p /reposource/
[root@RepoServer ~]# reposync -r updates -p /reposource/
[root@RepoServer ~]# reposync -r extras -p /reposource/
[root@RepoServer ~]# yum -y install createrepo
createrepo -pdo /reposource/base /reposource/base
createrepo -pdo /reposource/updates /reposource/updates
createrepo -pdo /reposource/extras /reposource/extras
reposync -n -r ol6_UEKR4 -p /reposource/
reposync -n -r ol6_latest -p /reposource/
登录其他内网其他服务器,要能与yum源服务器通信;编写repo文件:
[base]
name=local base
baseurl=http://132.113.64.239/base
enabled=1
gpgcheck=0
[extras]
name=local extras
baseurl=http://132.113.64.239/extras
enabled=1
gpgcheck=0
#[updates]
#name=local updates
#baseurl=http://132.113.64.239/updates
#enabled=1
#gpgcheck=0
备份其他repo文件至/etc/yum.repos.d/repobak目录下,以防影响测试:
执行yum clean all、yum makecache:
复制代码
[root@localhost yum.repos.d]# yum clean all
[root@localhost yum.repos.d]# yum makecache
为保证本地yum源能和阿里云镜像源同步,可以通过脚本定时任务实现:
reposync -d -r extras -p /reposource/extras/ #同步镜像源
if [ $? -eq 0 ];then
createrepo --update /reposource/extras #每次添加新的rpm时,必须更新epel索引信息
echo "SUCESS: $datetime extras update successful"else
echo "ERROR: $datetime extras update failed"fi
复制代码
vim /root/yum-update.sh
#!/bin/bash
datetime=`date +"%Y-%m-%d"`
exec > /var/log/yum-update.log
reposync -d -r base -p /reposource/base/
if [ $? -eq 0 ];then
createrepo --update /reposource/base
echo "SUCESS: $datetime base update successful"else
echo "ERROR: $datetime base update failed"fi
reposync -d -r updates -p /reposource/updates/
if [ $? -eq 0 ];then
createrepo --update /reposource/updates
echo "SUCESS: $datetime updates update successful"else
echo "ERROR: $datetime updates update failed"fi
reposync -d -r extras -p /reposource/extras/
if [ $? -eq 0 ];then
createrepo --update /reposource/extras
echo "SUCESS: $datetime extras update successful"else
echo "ERROR: $datetime extras update failed"fi
#定时任务:每周六凌晨三点同步yum源
crontab -e
0 3 * * * /bin/bash /root/yum-update.sh
ps:oracle
[ol6_latest]
name=Oracle Linux $releasever Latest ($basearch)
baseurl=http://yum.oracle.com/repo/OracleLinux/OL6/latest/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=1
[ol6_u9_base]
name=Oracle Linux $releasever Update 9 installation media copy ($basearch)
baseurl=http://yum.oracle.com/repo/OracleLinux/OL6/9/base/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=1
[ol6_UEKR4]
name=Latest Unbreakable Enterprise Kernel Release 4 for Oracle Linux $releasever ($basearch)
baseurl=http://yum.oracle.com/repo/OracleLinux/OL6/UEKR4/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=1