参考:How to Setup Local HTTP Yum Repository on CentOS 7
实验环境
CentOS7 1804
步骤一:安装Nginx Web Server
最小化安装后替换Yum源为163源:http://mirrors.163.com/.help/centos.html
yum clean all
yum makecache
安装epel和nginx
yum install epel-release
yum install nginx
启用Nginx并设置开机自动启动
systemctl start nginx
systemctl enable nginx
systemctl status nginx
设置防火墙,允许http,https
firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --zone=public --permanent --add-service=https
firewall-cmd --reload
步骤二:创建本地Yum仓库
安装必要包,用于创建、配置、管理本地仓库
yum install createrepo yum-utils
创建存储rpm包的目录
mkdir -p /var/www/html/repos/{base,centosplus,extras,updates}
同部远程yum仓库的包到本地yum仓库
reposync -g -l -d -m --repoid=base --newest-only --download-metadata --download_path=/var/www/html/repos/ reposync -g -l -d -m --repoid=centosplus --newest-only --download-metadata --download_path=/var/www/html/repos/ reposync -g -l -d -m --repoid=extras --newest-only --download-metadata --download_path=/var/www/html/repos/ reposync -g -l -d -m --repoid=updates --newest-only --download-metadata --download_path=/var/www/html/repos/
为本地存放rpm包的目录创建repodata
createrepo -g comps.xml /var/www/html/repos/base/
createrepo comps.xml /var/www/html/repos/centosplus/
createrepo comps.xml /var/www/html/repos/extras/
createrepo comps.xml /var/www/html/repos/updates/
修改/etc/nginx/nginx.conf文件server段
server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { root /var/www/html/repos; index index.php index.html index.htm; autoindex on; #enable listing of directory index } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
保存并重启Nginx
步骤三:检查本地Yum仓库
但是进入到具体目录看不到rpm包