创建本地或者网络yum仓库源
mkdir /usr/share/nginx/html/yum.repo #创建存放yum包地址
yum -y install createrepo yum-utils #安装索引命令
yum -y install epel-release.noarch #nginx需要epel源
yum -y install nginx 安装nginx
vim /etc/nginx/nginx.conf
#在location /{
}加入
autoindex on; # 表示:自动在html的索引打开
autoindex_exact_size on; # 表示:如果有文件,则显示文件的大小
autoindex_localtime on; # 表示:显示更改时间,以当前系统的时间为准
#修改网页地址
root /usr/share/nginx/html/yum.repo
systemctl enable nginx --now #启动nginx
createrepo -pdo /usr/share/nginx/html/yum.repo /usr/share/nginx/html/yum.repo #建立yum仓库服务索引
createrepo --update /usr/share/nginx/html/yum.repo #有新rpm包更新索引
#同步官方yum源
rsync -av rsync://mirrors.ustc.edu.cn/centos/7/os/x86_64/ /usr/share/nginx/html/yum.repo
rsync -av rsync://mirrors.ustc.edu.cn/centos/7/extras/x86_64/ /usr/share/nginx/html/yum.repo
rsync -av rsync://mirrors.ustc.edu.cn/centos/7/updates/x86_64/ /usr/share/nginx/html/yum.repo
rsync -av --exclude=debug rsync://mirrors.ustc.edu.cn/epel/7/x86_64/ /usr/share/nginx/html/yum.repo
#也可以使用脚本自动下载更新yum源
yum -y install inotify-tools
yum -y install rsync
systemctl restart rsyncd
systemctl enable rsyncdvim inotify.sh
#!/bin/bash
#This is rsync script on inotify.
export PATH=/bin:/usr/bin:/usr/local/bin
Desdir=rsync://mirrors.ustc.edu.cn/centos/7/os/x86_64/
Localdir=/usr/share/nginx/html/yum.repo
inotifywait -mrq --timefmt '%y-%m-%d %H:%M' --format '%T %w%f %e' --event modify,create,move,delete,attrib, $Localdir | while read line
do
echo "$line" > /var/log/inotify.log 2>&1
/usr/bin/rsync -avz --delete --progress $Desdir $Localdir >>/var/log/sync.log 2>&1
done &