본문 바로가기
Operating System/Linux Server

[Linux] CentOS | Local Repository Mirrors 만들기

by 인프라보이 2021. 7. 20.

회사 방화벽에서 rsync (TCP/UDP 873)을 막는 것 같아, 귀찮지만 wget(HTTP)로 Repository Mirror 사이트를 만들었습니다. 구글링에는 전부 rsync만 있어 많이 헤매서 정리하게 되었습니다. 
=> 정정 : wget으로 일단 구성은 했었는데 createrepo 하는 과정에서 일단 앞이 캄캄해지는 와중, reposync라는게 있어 이걸로 전환하였음. 
=> rsync는 outbound TCP 873을 사용하여 회사 방화벽에서 막힘.. 
=> wget은 80,443 이지만 다운받고 설정해야 되는게 많아서 일단 홀딩... (버전별 관리할땐 사용할 수도...)_
=> reposync도 80, 443 이라 제약이 없고, 동기화까지 되니까 뭐 일단 급한불은 이걸로 사용할 것. 

이번 포스팅은 CentOS 7버전에 대한 Repository 만들기만 구성합니다. 
구성하다가 생긴 고민거리는 아래와 같습니다.. 

   - CentOS7말고 OS버전별로 YUM을 사용할 수 있게 하면 좋을텐데, 일단 holding..
   - 1개 OS에서 CentOS와 Redhat 등 OS종류 별로 Repo를 만들면 좋을텐데... 일단 holing.. 그래서 Redhat은 별도 OS로 동일 구성하기로 함. 

 

1. 파일시스템 구성

 아래 그림과 같이 /repodata 라는 폴더에 처음 100GB를 주었고, wget으로 미러사이트 repo들 다운로드할 때 100GB가 넘어 200GB로 증설하였습니다. 이후 reposync명령어로 repository가져왔는데 base, extras, updates, centosplus 가져왔는데 전체 25GB 정도 사용하였습니다. 

설치 전 CentOS 기본 설정

2. Nginx를 통한 HTTP Open

$ yum install epel-release -y
$ yum install nginx -y

$ systemctl enable --now nginx
$ systemctl status nginx

Start nginx service

/etc/nginx/nginx.conf 에 HTTP접속 시 루트 경로로 /repodata 를 지정합니다.

    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80;
        listen       [::]:80;
        server_name  _;
       # root         /usr/share/nginx/html;
        root            /repodata/;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
                allow all;
                sendfile on;
                sendfile_max_chunk 1m;
                autoindex on;
                autoindex_exact_size off;
                autoindex_format html;
                autoindex_localtime on;
        }

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }

위에 수정하고 nginx restart

 

3. reposync를 통한 repository 동기화 수행

yum install -y createrepo yum-utils
reposync -g -l -d -m --repoid=base \ --newest-only --download-metadata --download_path=/repodata/
reposync -g -l -d -m --repoid=centosplus \ --newest-only --download-metadata --download_path=/repodata/
reposync -g -l -d -m --repoid=extras \ --newest-only --download-metadata --download_path=/repodata/
reposync -g -l -d -m --repoid=updates \ --newest-only --download-metadata --download_path=/repodata/

createrepo /repodata/base
createrepo /repodata/extras
createrepo /repodata/updates
createrepo /repodata/centosplus

 

4. 자동 업데이트 동기화 

vi /repomgmt/mgmt/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=/repodata/
        createrepo -g comps.xml /repos/$REPO/
done

crontab에 스케줄 등록 (매주 일요일 새벽 5시 수행)

crontab -e

-----------------------------------------------------------------------
0 5 * * sun     /repomgmt/mgmt/update-localrepos
-----------------------------------------------------------------------

crontab -l

 

5. Client의 새로 만든 Repo 구성

vi /etc/yum.repo.d/new-repo.repo

### New repository Update 

[Local-base]
name=centos-$releasever - Base
baseurl=http://REPO_IPv4/base/
enabled=1
gpgcheck=0

[Local-updates]
name=centos-$releasever - Updates
baseurl=http://REPO_IPv4/updates/
enabled=1
gpgcheck=0

[Local-extras]
name=centos-$releasever - Extras
baseurl=http://REPO_IPv4/extras/
enabled=1
gpgcheck=0
yum clean all
yum repolist

 

 

 

 

※ wget으로 kaist미러의 데이터 가져오는 스크립트 (참고용)

#!/bin/bash
repos_base_dir="/repodata/repos"

# Start sync if base repo directory exist
if [[ -d "$repos_base_dir" ]] ; then
 # Start Sync
 # rsync  -avSHP --delete rsync://ftp.kaist.ac.kr/CentOS/8/  "$repos_base_dir"
 wget -r -N -np -nH -R "index.*,*.iso" -P $repos_base_dir  http://ftp.kaist.ac.kr/CentOS/8/
 # Download CentOS 8 repository key
 wget -P $repos_base_dir wget https://www.centos.org/keys/RPM-GPG-KEY-CentOS-Official
fi

Downloading RPM packages...

 

728x90

댓글