#0. 开启yum下载缓存
sed -i '3c keepcache=1' /etc/yum.conf
#1.安装插件
yum install -y yum-plugin-downloadonly createrepo rsync
#2.创建仓库目录
mkdir -p /mirrors/centos
#3.下载文件或上传文件
yum install nginx -y --downloadonly --downloaddir=/mirrors/centos #只下载不安装
#也可以自行下载rpm包到/mirrors/centos
#4.创建repo
createrepo /mirrors/centos
#5.安装nginx,先添加nginx官方YUM源
[root@web01 ~]# cat /etc/yum.repos.d/nginx-stable.repo
[nginx-stable]
baseurl = http://nginx.org/packages/centos/$releasever/$basearch/
enabled = 1
gpgcheck = 0
gpgkey = https://nginx.org/keys/nginx_signing.key
name = nginx stable repo
yum -y install nginx
cd /etc/nginx/conf.d
# vim mirrors.conf
server {
listen 88;
server_name localhost;
root /mirrors/;
location / {
autoindex on; #开启目录列表显示
autoindex_exact_size off; #显示大小
autoindex_localtime on; #按本地时间显示
}
}
#6.启服务
systemctl enable nginx --now
systemctl status nginx
#7.配置repo
#vim /etc/yum.repos.d/mirrors.repo
[yumbase]
name=yumbase-local-repository
baseurl=http://xxx:88/centos/
enabled=1
gpgcheck=0
yum clean all && yum makecache
yum repoinfo webank-local-repository
#8.验证
yum -y install 软件名.版本号
#9.当自定义软件仓库的rpm包有变动时(增加或减少),要对 yum 仓库的数据文件做更新,才能重新识别变动后的 yum 仓库中的软件包
[root@server ~]# mv /mirrors/centos/sl-5.02-1.el7.x86_64.rpm /root #在仓库中移走一个rpm包到root下
[root@server ~]# createrepo --update /mirrors/centos/ # 更新仓库数据文件
[root@server ~]# yum makecache # 更新缓存数据
[root@server ~]# yum repolist # 查询发现仓库中rpm包数量比之前少一个
=========================================================生产环境做===================================================
#同步清华大学源(最少也就几百个G吧)
#!/bin/bash
/usr/bin/rsync -avz rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/centosplus/x86_64/Packages/ /mirrors/centos
/usr/bin/rsync -avz rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/extras/x86_64/Packages/ /mirrors/centos
/usr/bin/rsync -avz rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/Packages/ /mirrors/centos
/usr/bin/rsync -avz rsync://mirrors.tuna.tsinghua.edu.cn/centos/7/updates/x86_64/Packages/ /mirrors/centos
/usr/bin/rsync -avz rsync://mirrors.tuna.tsinghua.edu.cn/epel/7Server/x86_64/Packages/ /mirrors/centos
标签:rsync,CentOS,centos,mirrors,nginx,yum,YUM,root From: https://www.cnblogs.com/boradviews/p/18523685