0
点赞
收藏
分享

微信扫一扫

How to Setup Local HTTP Yum Repository on CentOS 7

大雁f 2023-02-22 阅读 98

Step 1: Install Nginx Web Server:

# yum install epel-release

# yum install nginx 

# systemctl start nginx

# systemctl enable nginx

# systemctl status nginx

# firewall-cmd --zone=public --permanent --add-service=http

# firewall-cmd --zone=public --permanent --add-service=https

# firewall-cmd --reload

Step 2: Create a Yum Local Repository:

# yum install createrepo  yum-utils

# mkdir -p /var/www/html/centos/{base,centosplus,extras,updates}

# reposync -g -l -d -m --repoid=base --newest-only --download-metadata --download_path=/var/www/html/centos/

# reposync -g -l -d -m --repoid=centosplus --newest-only --download-metadata --download_path=/var/www/html/centos/

# reposync -g -l -d -m --repoid=extras --newest-only --download-metadata --download_path=/var/www/html/centos/

# reposync -g -l -d -m --repoid=updates --newest-only --download-metadata --download_path=/var/www/html/centos/

# createrepo -g comps.xml /var/www/html/centos/base/  

# createrepo -g comps.xml /var/www/html/centos/centosplus/  

# createrepo -g comps.xml /var/www/html/centos/extras/  

# createrepo -g comps.xml /var/www/html/centos/updates/

# vim /etc/nginx/conf.d/repos.conf 

server {
listen 80;
server_name repos.afd.ink; #change test.lab to your real domain
root /var/www/html/centos;
location / {
index index.php index.html index.htm;
autoindex on; #enable listing of directory index
}
}


Step 3: Create a Cron Job to Synchronize and Create Repositories:

# vim /etc/cron.daily/update-localrepos

#!/bin/bash
##specify all local repositories in a single variable
LOCAL_REPOS=”base centosplus extras updates”
##a loop to update repos one at a time
for REPO in ${LOCAL_REPOS}; do
reposync -g -l -d -m --repoid=$REPO --newest-only --download-metadata --download_path=/var/www/html/centos/
createrepo -g comps.xml /var/www/html/centos/$REPO/
done

# chmod 755 /etc/cron.daily/update-localrepos

[local-base]
name=CentOS Base
baseurl=http://repos.afd.ink/base/
gpgcheck=0
enabled=1

[local-centosplus]
name=CentOS CentOSPlus
baseurl=http://repos.afd.ink/centosplus/
gpgcheck=0
enabled=1

[local-extras]
name=CentOS Extras
baseurl=http://repos.afd.ink/extras/
gpgcheck=0
enabled=1

[local-updates]
name=CentOS Updates
baseurl=http://repos.afd.ink/updates/
gpgcheck=0
enabled=1

#  yum repolist

# yum repolist all

举报

相关推荐

0 条评论