安装http
#yum-yinstallhttpd-y
安装软件包
#yum-yinstallrsynccreaterepo
创建目录
#mkdir-p/var/www/repos/centos/7/{os,updates,extras}/x86_64
设置权限
#chmod-R755/var/www/repos
从清华官方源同步
#rsync-avz--delete--exclude='repodata'\ rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/\ /var/www/repos/centos/7/os/x86_64/
#rsync-avz--delete--exclude='repodata'\ rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/updates/x86_64/\ /var/www/repos/centos/7/updates/x86_64/
#rsync-avz--delete--exclude='repodata'\ rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/extras/x86_64/\ /var/www/repos/centos/7/extras/x86_64/
创建 Metadata repositories
#createrepo/var/www/repos/centos/7/os/x86_64/ #createrepo/var/www/repos/centos/7/updates/x86_64/ #createrepo/var/www/repos/centos/7/extras/x86_64/
设置定时任务,每天同步
# vi /etc/cron.daily/update-repo
#!/bin/bash VER='7' ARCH='x86_64' REPOS=(osupdatesextras) forREPOin${REPOS[@]} do rsync-avz--delete--exclude='repodata'\ rsync://mirrors.tuna.tsinghua.edu.cn/centos/${VER}/${REPO}/${ARCH}//var/www/repos/centos/${VER}/${REPO}/${ARCH}/ createrepo/var/www/repos/centos/${VER}/${REPO}/${ARCH}/ done
赋予权限
#chmod755/etc/cron.daily/update-repo
配置httpd主机使其他客户端访问
# vi /etc/httpd/conf.d/repos.conf
Alias/repos/var/www/repos <directory/var/www/repos> Options+Indexes Requireallgranted </directory>
重启服务
#systemctlrestarthttpd
配置防火墙
#firewall-cmd--add-service=http--permanent #firewall-cmd--reload
客户端的配置文件,其中172.16.8.100是源服务器地址
# vi /etc/yum.repos.d/CentOS-Base.repo
[base] name=CentOS-$releasever-Base #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra baseurl=http://172.16.8.100/repos/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 [updates] name=CentOS-$releasever-Updates #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra baseurl=http://172.16.8.100/repos/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 [extras] name=CentOS-$releasever-Extras #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra baseurl=http://172.16.8.100/repos/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7原文链接:/bash/390202.html