본문 바로가기

리눅스

[리눅스] CentOS Yum Repository 서버 구축

728x90

CentOS 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

ContentDir="centos"
ReleaseVer="7"
#BaseList="os updates extras centosplus virt"
BaseList="os updates extras isos"
BaseArch="x86_64"
LocalDirectory=/apps/repo_root/repo/centos

RSYNC="/usr/bin/rsync -aqHz --delete"
MirrorUrl="rsync://ftp.kaist.ac.kr/CentOS"

for ver in $ReleaseVer
do
  for arch in $BaseArch
  do
    for base in $BaseList
    do
      ${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

ContentDir="epel"
ReleaseVer="7"
BaseList=""
BaseArch="x86_64"
LocalDirectory="/apps/repo_root/repo"

RSYNC="/usr/bin/rsync -aqHz --delete"
MirrorUrl="dl.fedoraproject.org::fedora-epel"

for ver in $ReleaseVer
do
  for arch in $BaseArch
  do
    #/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

ContentDir="centos"
ReleaseVer="8"
BaseList="AppStream BaseOS extras"
#BaseList="BaseOS"
BaseArch="x86_64"
LocalDirectory=/apps/repo_root/repo

for REPO in ${BaseList[@]}
do
  #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

ContentDir="epel"
ReleaseVer="8"
BaseList="Everything"
BaseArch="x86_64"
LocalDirectory="/apps/repo_root/repo"

RSYNC="/usr/bin/rsync -aqHz --delete"
MirrorUrl="dl.fedoraproject.org::fedora-epel"

for ver in ${ReleaseVer}
do
  for arch in ${BaseArch}
  do
    #/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

ContentDir="zabbix"
ReleaseVer="7 8"
BaseList="rhel"
BaseArch="x86_64"
LocalDirectory="/apps/repo_root/repo"

RSYNC="/usr/bin/rsync -aqHz --delete"
MirrorUrl="rsync://repo.zabbix.com/mirror"

for REPO in ${ReleaseVer[@]}
do
  #/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

크론잡

$ 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]

CentOS7-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

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

CentOS7-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]

CentOS8-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

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

CentOS8-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