본문 바로가기

리눅스

CentOS 8에서 Yum Repository 서버를 구축하는 방법

728x90

CentOS 8에서 Yum Repository 서버를 구축하는 방법

테스트 환경

$ cat /etc/redhat-release
CentOS Linux release 8.4.2105

Repository 서버 구축

epel 패키지 설치

yum install -y epel-release

createrepo 패키지 설치

yum install -y yum-utils createrepo

웹 서버(apache) 패키지 설치

yum install -y httpd mod_ssl

리포지토리 디렉터리 만들기(yum 저장소)

mkdir -p /apps/repo_root/repo
mkdir -p /apps/repo_root/repo/centos/7/{extras,isos,os,updates}
mkdir -p /apps/repo_root/repo/centos/8/{AppStream,BaseOS,extras,isos}

YUM/DNF 미러 서버 구성

  • CentOS YUM 저장소를 로컬 디렉토리에 동기화(CentOS 공식 리포지토리에서 데이터를 복사)
  • centos7_mirror.sh 스크립트 작성
vim centos7_mirror.sh
#!/bin/bash

# Yum Repository를 구축하기 위한 스크립트

# 설정값들
ContentDir="centos"
ReleaseVer="7"
BaseList="os updates extras isos"
BaseArch="x86_64"
LocalDirectory="/apps/repo_root/repo/centos"

# RSYNC 명령
RSYNC="/usr/bin/rsync -aqHz --delete"

# CentOS 미러 주소
MirrorUrl="rsync://ftp.kaist.ac.kr/CentOS"

# 버전, 아키텍처, 기본 그룹을 반복하여 처리
for ver in $ReleaseVer
do
  for arch in $BaseArch
  do
    for base in $BaseList
    do
      # RSYNC를 사용하여 미러로부터 패키지 다운로드
      ${RSYNC} ${MirrorUrl}/${ver}/${base}/${arch} ${LocalDirectory}/${ver}/${base}/

      # 다운로드한 패키지들로 메타데이터 생성
      createrepo ${LocalDirectory}/${ver}/${base}/${arch}/
    done
  done
done
  • epel7_mirror.sh 스크립트 작성
vim epel_mirror.sh
#!/bin/bash

# EPEL Yum Repository를 구축하기 위한 스크립트

# 설정값들
ContentDir="epel"
ReleaseVer="7"
BaseList=""
BaseArch="x86_64"
LocalDirectory="/apps/repo_root/repo"

# RSYNC 명령
RSYNC="/usr/bin/rsync -aqHz --delete"

# EPEL 미러 주소
MirrorUrl="dl.fedoraproject.org::fedora-epel"

# 버전, 아키텍처, 그룹을 반복하여 처리
for ver in $ReleaseVer
do
  for arch in $BaseArch
  do
    # RSYNC를 사용하여 미러로부터 패키지 다운로드
    # /usr/bin/rsync -aqHz --delete dl.fedoraproject.org::fedora-epel/7/x86_64/ /app/repo_root/repo/epel/7/x86_64/
    ${RSYNC} ${MirrorUrl}/${ver}/${arch}/ ${LocalDirectory}/${ContentDir}/${ver}/${arch}

    # 다운로드한 패키지들로 메타데이터 생성
    createrepo ${LocalDirectory}/${ContentDir}/${ver}/${arch}/
  done
done
  • centos8_mirror.sh 스크립트 작성
vim centos8_mirror.sh
#!/bin/bash

# CentOS 8 Yum Repository를 구축하기 위한 스크립트

# 설정값들
ContentDir="centos"
ReleaseVer="8"
BaseList=("AppStream" "BaseOS" "extras")
BaseArch="x86_64"
LocalDirectory="/apps/repo_root/repo"

# CentOS 미러 주소
MirrorUrl="http://mirror.centos.org/centos/${ReleaseVer}/"

# 버전, 아키텍처, 그룹을 반복하여 처리
for REPO in "${BaseList[@]}"
do
  # reposync를 사용하여 미러로부터 패키지 다운로드
  # reposync -p /app/repo_root/repo/centos/8 --repoid=BaseOS --download-metadata --newest-only
  # reposync -p /app/repo_root/repo/centos/8 --repoid=AppStream --download-metadata --newest-only
  reposync -p "${LocalDirectory}/${ContentDir}/${ReleaseVer}" --repoid="${REPO}" --download-metadata --newest-only

  # 다운로드한 패키지들로 메타데이터 생성
  createrepo "${LocalDirectory}/${ContentDir}/${ReleaseVer}/${REPO}/${BaseArch}/os/"
done
  • epel8_mirror.sh 스크립트 작성
vim epel8_mirror.sh
#!/bin/bash

# EPEL 8 Yum Repository를 구축하기 위한 스크립트

# 설정값들
ContentDir="epel"
ReleaseVer="8"
BaseList="Everything"
BaseArch="x86_64"
LocalDirectory="/apps/repo_root/repo"

# RSYNC 명령
RSYNC="/usr/bin/rsync -aqHz --delete"

# EPEL 미러 주소
MirrorUrl="dl.fedoraproject.org::fedora-epel"

# 버전, 아키텍처, 그룹을 반복하여 처리
for ver in ${ReleaseVer}
do
  for arch in ${BaseArch}
  do
    # RSYNC를 사용하여 미러로부터 패키지 다운로드
     # /usr/bin/rsync -aqHz --delete dl.fedoraproject.org::fedora-epel/8/Everything/x86_64/ /app/repo_root/repo/epel/8/Everything/x86_64
    ${RSYNC} ${MirrorUrl}/${ver}/${BaseList}/${arch}/ ${LocalDirectory}/${ContentDir}/${ver}/${BaseList}/${BaseArch}

    # 다운로드한 패키지들로 메타데이터 생성
    createrepo ${LocalDirectory}/${ContentDir}/${ver}/${arch}/
  done
done
  • zabbix_mirror.sh 스크립트 작성
vim zabbix_mirror.sh
#!/bin/bash

# Zabbix Yum Repository를 구축하기 위한 스크립트

# 설정값들
ContentDir="zabbix"
ReleaseVer="7 8"
BaseList="rhel"
BaseArch="x86_64"
LocalDirectory="/apps/repo_root/repo"

# RSYNC 명령
RSYNC="/usr/bin/rsync -aqHz --delete"

# Zabbix 미러 주소
MirrorUrl="rsync://repo.zabbix.com/mirror"

# 버전, 아키텍처, 그룹을 반복하여 처리
for REPO in ${ReleaseVer[@]}
do
  # RSYNC를 사용하여 미러로부터 패키지 다운로드
  # /usr/bin/rsync -aqHz --delete rsync://repo.zabbix.com/mirror/zabbix/5.0/rhel/7/x86_64 /app/repo_root/repo/zabbix/5.0/rhel/7/
  # /usr/bin/rsync -aqHz --delete rsync://repo.zabbix.com/mirror/zabbix/5.0/rhel/8/x86_64 /app/repo_root/repo/zabbix/5.0/rhel/8/
  ${RSYNC} ${MirrorUrl}/${ContentDir}/5.0/${BaseList}/${REPO}/${BaseArch} ${LocalDirectory}/${ContentDir}/5.0/${BaseList}/${REPO}/

  # 로컬 디렉토리 권한 변경
  chmod 755 -R ${LocalDirectory}/${ContentDir}/5.0/${BaseList}/${REPO}
done
728x90

크론잡

crontab -e
#repository sync
01 03 * * *     /bin/bash /home/aman/iscript/centos7_mirror.sh > /dev/null 2>&1
01 04 * * *     /bin/bash /home/aman/iscript/epel7_mirror.sh > /dev/null 2>&1
01 05 * * *     /bin/bash /home/aman/iscript/centos8_mirror.sh > /dev/null 2>&1
01 06 * * *     /bin/bash /home/aman/iscript/epel8_mirror.sh > /dev/null 2>&1
01 07 * * *     /bin/bash /home/aman/iscript/zabbix_mirror.sh > /dev/null 2>&1
$ crontab -l
...
#repository sync
01 03 * * *     /bin/bash /home/aman/iscript/centos7_mirror.sh > /dev/null 2>&1
01 04 * * *     /bin/bash /home/aman/iscript/epel7_mirror.sh > /dev/null 2>&1
01 05 * * *     /bin/bash /home/aman/iscript/centos8_mirror.sh > /dev/null 2>&1
01 06 * * *     /bin/bash /home/aman/iscript/epel8_mirror.sh > /dev/null 2>&1
01 07 * * *     /bin/bash /home/aman/iscript/zabbix_mirror.sh > /dev/null 2>&1

로컬 리포지토리에 새 리포지토리 생성 후 패키지 그룹 정보를 업데이트

createrepo -g comps.xml /apps/repo_root/repo/centos/8/appstream
createrepo -g comps.xml /apps/repo_root/repo/centos/8/baseos
createrepo -g comps.xml /apps/repo_root/repo/centos/8/extras
createrepo -g comps.xml /apps/repo_root/repo/centos/8/isos

CentOS 클라이언트 구성

  • repo 파일을 웹서버에 업로드시켜놓고 다운로드받아서 사용합니다.
  • CentOS 7 - Base.repo
# CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
baseurl=http://pkg.4wxyz.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=http://pkg.4wxyz.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=http://pkg.4wxyz.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://pkg.4wxyz.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
  • CentOS 7 - epel7.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://pkg.4wxyz.com/pub/epel/7/$basearch
failovermethod=priority
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://pkg.4wxyz.com/pub/epel/7/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://pkg.4wxyz.com/pub/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
  • CentOS 7 - zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=http://pkg.4wxyz.com/zabbix/5.0/rhel/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
  • CentOS 8 - Base.repo
# CentOS-Base.repo
[BaseOS]
name=CentOS-$releasever - Base
baseurl=http://pkg.4wxyz.com/$contentdir/$releasever/BaseOS
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

[AppStream]
name=CentOS-$releasever - AppStream
baseurl=http://pkg.4wxyz.com/$contentdir/$releasever/AppStream
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
  • CentOS 8 - epel8.repo
[epel]
name=Extra Packages for Enterprise Linux $releasever - $basearch
baseurl=http://pkg.4wxyz.com/pub/epel/$releasever/Everything/$basearch
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8

[epel-debuginfo]
name=Extra Packages for Enterprise Linux $releasever - $basearch - Debug
baseurl=http://pkg.4wxyz.com/pub/epel/$releasever/Everything/$basearch/debug
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux $releasever - $basearch - Source
baseurl=http://pkg.4wxyz.com/pub/epel/$releasever/Everything/SRPMS
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
gpgcheck=1
  • CentOS 8 - zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=http://pkg.4wxyz.com/zabbix/5.0/rhel/8/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

 

curl 명령을 사용하여 repo 파일을 내려받는다.

 

  • CentOS 7
curl -Ssf http://pkg.4wxyz.com/pub/dl/repo/CentOS7-Base.repo -o /etc/yum.repos.d/CentOS-Base.repo
curl -Ssf http://pkg.4wxyz.com/pub/dl/repo/epel7.repo -o /etc/yum.repos.d/epel.repo
curl -Ssf http://pkg.4wxyz.com/pub/dl/repo/CentOS7-zabbix.repo -o /etc/yum.repos.d/zabbix.repo
  • CentOS 8
curl -Ssf http://pkg.4wxyz.com/pub/dl/repo/CentOS8-Base.repo -o /etc/yum.repos.d/CentOS-Base.repo
curl -Ssf http://pkg.4wxyz.com/pub/dl/repo/epel8.repo -o /etc/yum.repos.d/epel.repo
curl -Ssf http://pkg.4wxyz.com/pub/dl/repo/CentOS8-zabbix.repo -o /etc/yum.repos.d/zabbix.repo

CentOS 공식 리포지토리 Mirror 서버

mirror.kakao.com - https://mirror.kakao.com/centos/

dl.fedoraproject.org - https://dl.fedoraproject.org/pub/epel/

 

728x90