CentOS7 搭建本地yum和EPEL仓库
CentOS7下搭建CentOS7、EPEL的局域网下使用的本地YUM仓库,因为在生产环境中由于安全的限制,某些服务器不允许访问公网。
如果需要使用yum安装包或update只能通过在本地自建yum源来解决。
yum源可以通过http、ftp、nfs等方式去访问使用,不过由于nfs由于自身的安全性问题并不推荐用。而ftp有主动/被动模式的问题,配置不当也会造成有无法访问。所以推荐使用http web方式提供yum源
安装nginx
rpm -Uvh http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.16.1-1.el7.ngx.x86_64.rpm
设置host
echo "192.168.0.1 server1" >>/etc/hosts tail -1 /etc/hosts
修改nginx配置
vim /etc/nginx/conf.d/repos.conf 添加 server { listen 80; server_name server1; root /u01/repos; location / { autoindex on; autoindex_exact_size off; autoindex_localtime on; } ##EPEL virtual directory location /epel/ { alias /u01/epel/; } }
开启服务
systemctl start nginx && systemctl enable nginx firewall-cmd --zone=public --permanent --add-service={http,https} firewall-cmd --reload reboot curl -s 127.0.0.1
安装yum组件
yum-utils提供reposync服务,可以将远程的源同步到本地。createrepo可以将rpm包创建为Yum仓库,生成repodata目录
yum install -y yum-utils createrepo
创建文件保存目录
mkdir -p /u01/repos/{base,centosplus,extras,updates} mkdir -p /u01/epel/
备份系统自带源
cd /etc/yum.repos.d mkdir -p backuprepo && mv * backuprepo
修改本地源改为阿里云
wget -O CentOS-aliyun7.repo http://mirrors.aliyun.com/repo/Centos-7.repo wget -O epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
查看本地存在的镜像
yum repolist
同步镜像到本地http根目录
reposync -g -l -d -m --repoid=base --newest-only --download-metadata --download_path=/u01/repos/ reposync -g -l -d -m --repoid=centosplus --newest-only --download-metadata --download_path=/u01/repos/ reposync -g -l -d -m --repoid=extras --newest-only --download-metadata --download_path=/u01/repos/ reposync -g -l -d -m --repoid=updates --newest-only --download-metadata --download_path=/u01/repos/ reposync -g -l -d -m --repoid=epel --newest-only --download-metadata --download_path=/u01/epel/
创建rpm包目录索引信息
createrepo -pdo /u01/repos/base /u01/repos/base createrepo -pdo /u01/repos/centosplus /u01/repos/centosplus createrepo -pdo /u01/repos/extras /u01/repos/extras createrepo -pdo /u01/repos/updates /u01/repos/updates createrepo -pdo /u01/epel /u01/epel/
创建定时同步任务
vim /etc/cron.daily/localrepos-update 添加 # Sync CentOS and EPEL repos reposync -g -l -d -m --repoid=base --newest-only --download-metadata --download_path=/u01/repos/ reposync -g -l -d -m --repoid=centosplus --newest-only --download-metadata --download_path=/u01/repos/ reposync -g -l -d -m --repoid=extras --newest-only --download-metadata --download_path=/u01/repos/ reposync -g -l -d -m --repoid=updates --newest-only --download-metadata --download_path=/u01/repos/ reposync -g -l -d -m --repoid=epel --newest-only --download-metadata --download_path=/u01/epel/ # Build CentOS repo metadata createrepo --update --workers=4 /u01/repos/base/ createrepo --update --workers=4 /u01/repos/centosplus/ createrepo --update --workers=4 /u01/repos/extras/ createrepo --update --workers=4 /u01/repos/updates createrepo --update --workers=4 /u01/epel/
添加权限
chmod 755 /etc/cron.daily/localrepos-update
局域网其他服务器设置
备份本地源
echo "192.168.0.1 server1" >>/etc/hosts cd /etc/yum.repos.d mkdir -p backuprepo && mv * backuprepo
修改为新源
vim /etc/yum.repos.d/local.repo 添加 [base] name=CentOS-7-base.local baseurl=http://server1/base enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 [centosplus] name=Centos-7-plus.local baseurl=http://server1/centosplus/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 [updates] name=CentOS-7-updates.local baseurl=http://server1/updates enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 [extras] name=CentOS-7-extras.local baseurl=http://server1/extras enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 [epel] name=CentOS-7-epel.local baseurl=http://server1/epel enabled=1 gpgcheck=0
测试
yum clean all yum repolist all yum install -y yum-plugin-fastestmirror
本站所有文章均可随意转载,转载时请保留原文链接及作者。