Linux-centos/Linux-centos__폐쇄망

yum local repository

말하는감자 2020. 10. 13. 10:56

yum local repository 생성

1. repo 설치 및 설정

생성 및 설정을 위한 패키지 설치

yum install createrepo yum-utils

패키지 정보를 저장할 디렉토리 생성

mkdir -p /home/www/html/repos/{base, centosplus, extras, updates, python35}

local repository 와 centos yum repository 동기화

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

원하는 패키지 목록이 별도로 있다면 추가 작성

sudo yum -y install --downloadonly --installroot=/home/packages-ins --releasever=7 --downloaddir=/home/www/html/repos/python35 python35u python35u-debug python35u-devel python35u-libs python35u-lxml python35u-tools python35u-setuptools gcc gcc-c++ libxslt-devel libffi-devel mariadb-devel openssl-devel openssl openssl-libs libevent libevent-devel mariadb-libs MySQL-python nginx
rm -rf /home/packages-ins

repo data 생성

createrepo -g comps.xml /home/www/html/repos/base/
createrepo /home/www/html/repos/centosplus/
createrepo /home/www/html/repos/extras/
createrepo /home/www/html/repos/updates/
createrepo /home/www/html/repos/python35/

2. nginx 설치 및 설정

repo 추가

vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

설치

yum install epel-release
yum install nginx

nginx 설정 추가

vim /etc/nginx/conf.d/default.conf
server {
        listen   80;
        server_name  localhost;
        root   /home/www/html/repos;
        location / {
                index  index.php index.html index.htm;
                autoindex on; #enable listing of directory index
        }
}

3. 패키지 동기화

스크립트 작성 및 권한 부여

vim /home/cron-script/update-localrepos
#!/bin/bash
LOCAL_REPOS="base centosplus extras updates"
for REPO in ${LOCAL_REPOS}; do
reposync -g -l -d -m --repoid=$REPO --newest-only --download-metadata --download_path=/home/www/html/repos/
createrepo /var/www/html/repos/$REPO/  
done
chmod 755 /home/cron-script/update-localrepos

크론탭에 등록

crontab -e
0 0 * * * * /home/cron-script/update-localrepos

원격 서버

local 에 repo 추가

vim /etc/yum.repos.d/local-repos.repo
[local-base]
name=CentOS Base
baseurl=http://<SERVER_IP>/base/
gpgcheck=0
enabled=1

[local-centosplus]
name=CentOS CentOSPlus
baseurl=http://<SERVER_IP>/centosplus/
gpgcheck=0
enabled=1

[local-extras]
name=CentOS Extras
baseurl=http://<SERVER_IP>/extras/
gpgcheck=0
enabled=1

[local-updates]
name=CentOS Updates
baseurl=http://<SERVER_IP>/updates/
gpgcheck=0
enabled=1

[local-python35]
name=CentOS Updates
baseurl=http://<SERVER_IP>/python35/
gpgcheck=0
enabled=1

사용하지 않는 repo 삭제

cd /etc/yum.repos.d/
rm -rf CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo CentOS-Vault.repo

확인 및 업데이트

yum repolist
yum --disablerepo=\* --enablerepo-local-* update yum
yum clean all

필요한 패키지 설치

yum install --disablerepo=\* --enablerepo=local-repos 설치할패키지이름
pip install --no-index --find-links=. 패키지이름