目录
1. 服务端搭建
1.1. 安装相关软件包
1.2. 加载几个常用的yum源
1.3. 创建文件保存目录
1.4. 把各仓库同步到本地
1.5. 生成仓库信息
1.6. 定时任务更新仓库
1.7. nginx配置下载服务
1.8. 内网测试nginx服务配置是否正确
2. 客户端配置
前言:之前使用rsync同步官方源没问题,但是同步国内的yum源时出现了同步不起的问题,所以改用reposync的方式。
操作系统:centos7.2 x64,2c4G,100G系统盘,500G数据盘。
1. 服务端搭建
1.1. 安装相关软件包
#1 安装相关软件包
yum install nginx yum-utils createrepo -y
systemctl start nginx
1.2. 加载几个常用的yum源
#备份原先的yum源
mkdir -p /etc/yum.repos.d/back && mv /etc/yum.repos.d/* /etc/yum.repos.d/back#下载centos7源
wget -O /etc/yum.repos.d/Centos-7.repo https://mirrors.aliyun.com/repo/Centos-7.repo#下载epel源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo#下载k8s源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF#下载docker源
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo#使用yum repolist验证
yum repolist
1.3. 创建文件保存目录
mkdir -p /usr/share/nginx/html/yum
1.4. 把各仓库同步到本地
reposync -r base -p /usr/share/nginx/html/yum
reposync -r docker-ce-stable -p /usr/share/nginx/html/yum
reposync -r epel -p /usr/share/nginx/html/yum
reposync -r extras -p /usr/share/nginx/html/yum
reposync -r updates -p /usr/share/nginx/html/yum
1.5. 生成仓库信息
createrepo /usr/share/nginx/html/yum/base
createrepo /usr/share/nginx/html/yum/docker-ce-stable
createrepo /usr/share/nginx/html/yum/epel
createrepo /usr/share/nginx/html/yum/extras
createrepo /usr/share/nginx/html/yum/updates
1.6. 定时任务更新仓库
cat <<EOF> /data/yum-update.sh
#!/bin/bash#同步数据
reposync -r base -p /usr/share/nginx/html/yum
reposync -r docker-ce-stable -p /usr/share/nginx/html/yum
reposync -r epel -p /usr/share/nginx/html/yum
reposync -r extras -p /usr/share/nginx/html/yum
reposync -r updates -p /usr/share/nginx/html/yum#更新元数据
createrepo --update /usr/share/nginx/html/yum/base
createrepo --update /usr/share/nginx/html/yum/docker-ce-stable
createrepo --update /usr/share/nginx/html/yum/epel
createrepo --update /usr/share/nginx/html/yum/extras
createrepo --update /usr/share/nginx/html/yum/updates
EOF#crontab -e
grep yum-update.sh /var/spool/cron/root || echo "0 6 * * * 0 6 * * * /bin/bash /data/yum-update.sh" >> /var/spool/cron/root
1.7. nginx配置下载服务
cat <<EOF> /etc/nginx/conf.d/yum.tom.com.conf
server {listen 80;server_name yum.tom.com;location / {# 启用目录浏览autoindex on;root /usr/share/nginx/html/yum/;# 可选项: 不显示文件的确切大小,而是使用KB, MB等单位autoindex_exact_size off;# 可选项: 使用服务器本地时间显示文件时间autoindex_localtime on;}
}
EOFnginx -t
systemctl restart nginxcurl -H host:yum.tom.com localhost
1.8. 内网测试nginx服务配置是否正确
[root@yum conf.d]# curl -H host:yum.tom.com 10.0.0.81
<html>
<head><title>Index of /</title></head>
<body>
<h1>Index of /</h1><hr><pre><a href="../">../</a>
<a href="base/">base/</a> 02-Sep-2024 19:11 -
</pre><hr></body>
</html>
2. 客户端配置
#备份原先的yum源
mkdir -p /etc/yum.repos.d/back && mv /etc/yum.repos.d/* /etc/yum.repos.d/back#配置yum源为自建地址
cat <<EOF> /etc/yum.repos.d/centos7.repo
[base]
name=CentOS-$releasever - Base
baseurl=http://10.0.0.81/base
enabled=1
gpgcheck=0[base-ex]
name=CentOS-$releasever - Base-ex
baseurl=http://10.0.0.81/extras
enabled=1
gpgcheck=0[epel]
name=epel
baseurl=http://10.0.0.81/epel
enabled=1
gpgcheck=0[docker]
name=docker-ce
baseurl=http://10.0.0.81/docker-ce-stable
enabled=1
gpgcheck=0[k8s]
name=docker-ce
baseurl=http://10.0.0.81/kubernetes
enabled=1
gpgcheck=0EOF#使用yum repolist验证
yum repolist