Skip to content

Repository(YUM) Server Setup

1. Package install

  • Install package

Rsync: Efficient synchronization and backup of files and directories

createrepo: Create metadata for the YUM/DNF software repository for RPM software packages

dnf install -y rsync createrepo

image-20260315171340663

  • Install web service

refer to Web-Service-Setup

2. Rsync repository

  • Sync repository from Rsync source

寻找提供RSYNC服务的Repository.

这里以Rocky南京大学源为例:rsync://mirrors.nju.edu.cn/rocky/

  • Prepare local storage and create rsync script
mkdir /data/www
vim /data/sync_rocky.sh

add below content

#!/bin/gash
YUM_SITE="rsync://mirrors.nju.edu.cn/rocky/"
LOCAL_PATH="/data/www/rocky/"
LOCAL_VER='./'
#BW_limit=204800
LOCK_FILE="/var/log/yum_server.pid"
RSYNC_PATH=""

#check update centos pid
MY_PID=$$
if [ -f $LOCK_FILE ]; then
get_pid=`/bin/cat $LOCK_FILE`
get_system_pid=`/bin/ps -ef|grep -v grep|grep $get_pid|wc -l`
if [ $get_system_pid -eq 0 ] ; then
echo $MY_PID>$LOCK_FILE
else
echo "Have update rocky server now!"
exit 1
fi
else
echo $MY_PID>$LOCK_FILE
fi

#check rsync tool
if [ -z $RSYNC_PATH ]; then
RSYNC_PATH=`/usr/bin/whereis rsync|awk ' ''{print $2}'`
if [ -z $RSYNC_PATH ]; then
echo 'Not find rsync tool.'
echo 'use comm: yum install -y rsync'
fi
fi

# sync centos source
for VER in $LOCAL_VER;
do
# Check whether there are local directory
if [ ! -d "$LOCAL_PATH$VER" ] ; then
echo "Create dir $LOCAL_PATH$VER"
`/bin/mkdir -p $LOCAL_PATH$VER`
fi
# sync centos source
echo "Start sync $LOCAL_PATH$VER"
$RSYNC_PATH -avrtH --delete --exclude "isos" --exclude "images" $YUM_SITE$VER $LOCAL_PATH
done

# clean lock file
`/bin/rm -f $LOCK_FILE`

echo "rsync end $(date +%Y-%m-%d_%k:%M:%S)" >> /data/www/rocky/rocky_rsync_is_end.txt

chown -R root.root /data/www/rocky
createrepo /data/www/rocky
exit 1
  • Execute repository sync script
sh /data/sync_rocky.sh

3. Web service release

Reference: Web-Service-Setup to publish the yum directory.