2022/07/11

如何建立 CentOS 7 Local Repo

安裝 httpd

yum install httpd

建立 local repo

yum install createrepo yum-utils

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

用 reposync 同步 packages

reposync -g -l -d -m --repoid=base --newest-only --download-metadata --download_path=/var/www/html/repos/centos/
reposync -g -l -d -m --repoid=centosplus --newest-only --download-metadata --download_path=/var/www/html/repos/centos/
reposync -g -l -d -m --repoid=extras --newest-only --download-metadata --download_path=/var/www/html/repos/centos/
reposync -g -l -d -m --repoid=updates --newest-only --download-metadata --download_path=/var/www/html/repos/centos/

vi /etc/cron.weekly/update-centos-repo

#!/bin/bash
##specify all local repositories in a single variable
LOCAL_REPOS="base centosplus extras updates epel"
##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/repos/centos/
    #createrepo -g comps.xml /var/www/html/repos/centos/$REPO/
    createrepo --update /var/www/html/repos/centos/$REPO/
done

啟動 script

chmod 755 /etc/cron.weekly/update-centos-repo

設定 Local Repo

vim /etc/yum.repos.d/local-repos.repo

[local-base]
name=CentOS Base
baseurl=http://repos.server.ip/repos/centos/base/
gpgcheck=0
enabled=1

[local-centosplus]
name=CentOS CentOSPlus
baseurl=http://repos.server.ip/repos/centos/centosplus/
gpgcheck=0
enabled=1

[local-extras]
name=CentOS Extras
baseurl=http://repos.server.ip/repos/centos/extras/
gpgcheck=0
enabled=1

[local-updates]
name=CentOS Updates
baseurl=http://repos.server.ip/repos/centos/updates/
gpgcheck=0
enabled=1

測試

yum repolist

References

How to Setup Local HTTP Yum Repository on CentOS 7

建立 local http yum repository on Centos 7

Setup local YUM/DNF repo server Rocky Linux 8 [Step-by-Step] | GoLinuxCloud

Create a Centos Repository Mirror – UNIX fu

沒有留言:

張貼留言