'''yum 사용하기''' '''문태준''' [[DateTime(2006-10-22T08:56:37)]] http://tunelinux.pe.kr http://database.sarang.net [[TableOfContents]] == yum 개략 == yum을 이용하여 보안업데이트를 자동화하는 내용. yum 사용시 주의사항, 자체 저장소 마련하기 등 * 문서변경사항 : [[DateTime(2006-10-22T08:56:37)]] yum 레퍼지토리 별도 생성한 실제 내용 추가 == 별도 rpm 제작시 주의상황 == {{{ [root@intranet log]# grep yum messages Sep 21 04:31:39 intranet yum: Updated: gzip.i386 1.3.3-16.rhel4 Sep 22 05:14:13 intranet yum: Installed: mysql.i386 4.1.20-1.RHEL4.1 Sep 22 05:14:14 intranet yum: Updated: php-mysql.i386 4.3.9-3.18 Sep 22 05:14:15 intranet yum: Updated: php-pear.i386 4.3.9-3.18 Sep 22 05:14:15 intranet yum: Updated: php.i386 4.3.9-3.18 Sep 22 05:14:20 intranet yum: Erased: MySQL-server-standard Sep 22 05:14:21 intranet yum: Erased: MySQL-client-standard Sep 22 09:04:42 intranet yum: Installed: mx.i386 2.0.5-3 Sep 22 09:04:42 intranet yum: Installed: mysqlclient10.i386 3.23.58-4.RHEL4.1 Sep 22 09:04:42 intranet yum: Installed: MySQL-python.i386 1.0.0-1.RHEL4.1 Sep 22 09:07:47 intranet yum: Installed: php-mysql.i386 4.3.9-3.18 Sep 22 09:09:43 intranet yum: Erased: MySQL-python Sep 22 09:09:44 intranet yum: Erased: MySQL-shared-standard Sep 22 09:09:44 intranet yum: Erased: MySQL-devel-standard Sep 22 09:09:44 intranet yum: Erased: MySQL-server-standard Sep 22 09:13:13 intranet yum: Installed: mysql.i386 4.1.20-1.RHEL4.1 Sep 22 09:20:24 intranet yum: Disabling nightly yum update: Sep 22 09:20:24 intranet yum: succeeded Sep 22 09:20:24 intranet yum: Sep 22 09:20:24 intranet yum: Sep 22 09:20:24 intranet rc: Stopping yum: succeeded Sep 22 09:25:07 intranet yum: Installed: mysql.i386 4.1.20-1.RHEL4.1 Sep 22 09:25:07 intranet yum: Installed: php-mysql.i386 4.3.9-3.18 Sep 22 09:25:10 intranet yum: Erased: MySQL-server-standard Sep 22 09:25:11 intranet yum: Erased: MySQL-client-standard Sep 22 09:30:31 intranet yum: Installed: mysql.i386 4.1.20-1.RHEL4.1 Sep 22 09:32:00 intranet yum: Erased: php-pear Sep 22 09:32:01 intranet yum: Erased: php }}} /etc/init.d/yum 이 활성화되어 있으면 자동으로 yum update를 실행함. php가 업데이트가 되면서 기존에 5.x에 맞게 빌드한 php 관련 rpm을 자동 삭제하고 mysql도 자동으로 재설치하면서 문제가 발생하였음. 임시조치로 해당 rpm을 재설치하고 서비스를 복구한 후 yum 자동업데이트를 비활성화하고 yum 에서 관련패키지는 자동업데이트를 하지 않도록 조정하였음. == yum 구조 == {{{ # cat /etc/init.d/yum lockfile=/var/lock/subsys/yum RETVAL=0 start() { echo -n $"Enabling nightly yum update: " touch "$lockfile" && success || failure RETVAL=$? echo } stop() { echo -n $"Disabling nightly yum update: " rm -f "$lockfile" && success || failure RETVAL=$? echo } }}} 여기 스크립트에서 lockfile 을 검사하여 스크립트를 실행한다. {{{ [root@intranet cron.daily]# cat /etc/cron.daily/yum.cron #!/bin/sh if [ -f /var/lock/subsys/yum ]; then /usr/bin/yum -R 120 -e 0 -d 0 -y update yum /usr/bin/yum -R 10 -e 0 -d 0 -y shell /etc/yum/yum-daily.yum fi }}} 하루에 한번씩 자동으로 yum update 를 수행하는 것이다. {{{ [root@intranet cron.daily]# cat /etc/yum/yum-daily.yum update ts run exit [root@intranet cron.daily]# cat /etc/cron.weekly/yum.cron #!/bin/sh if [ -f /var/lock/subsys/yum ]; then /usr/bin/yum -e 0 -d 0 clean packages fi }}} 일주일에 한번씩 yum 캐쉬 디렉토리를 정리해준다. yum 과 관련한 log는 /var/log/yum.log 에 남는다. {{{ [root@intranet cron.daily]# cat /etc/logrotate.d/yum /var/log/yum.log { missingok notifempty size 30k create 0600 root root } }}} 위와 같이 logrotate 설정에 따라 주기적으로 로그를 순환시켜준다. yum 의 설정파일은 /etc/yum.conf 이다. {{{ [root@intranet moniwiki]# cat /etc/yum.conf [main] cachedir=/var/cache/yum debuglevel=2 logfile=/var/log/yum.log pkgpolicy=newest distroverpkg=centos-release tolerant=1 exactarch=1 retries=20 obsoletes=1 gpgcheck=1 # PUT YOUR REPOS HERE OR IN separate files named file.repo # in /etc/yum.repos.d }}} 위에서 만약 특정 패키지를 제외하려면 exclude 옵션을 쓰면 된다. {{{ exclude=http* MySQL* mysql* php* kernel* }}} 대소문자 구별을 하는지 몰라서 혹시나 생길 문제에 대비하여 모두 넣었다. == yum의 update 구조 == === 클라이언트 설정파일 === /etc/yum.conf 가 yum 클라이언트 설정파일이며 /etc/yum.repos.d 디렉토리에 저장소에 대한 정보를 넣는다. {{{ # cat /etc/yum.conf [main] cachedir=/var/cache/yum debuglevel=2 logfile=/var/log/yum.log pkgpolicy=newest distroverpkg=centos-release tolerant=1 exactarch=1 retries=20 obsoletes=1 gpgcheck=1 # PUT YOUR REPOS HERE OR IN separate files named file.repo # in /etc/yum.repos.d }}} {{{[main]}}} 에 주요 옵션이 들어간다. main 은 전체적으로 적용이 된다. distroverpkg 에서 사용중인 패키지의 배포판의 버전을 알아내기 위해 필요한 것으로 여기서 지정한 패키지의 버전을 이용한다. 위에서도 설명을 했지만 특정 패키지를 제외하려면 exclude를 이용하며 특정 레퍼지토리에만 적용할 수 있다. {{{ # ls /etc/yum.repos.d/ CentOS-Base.repo CentOS-Media.repo [root@mytest yum]# cat /etc/yum.repos.d/CentOS-Base.repo # CentOS-Base.repo # # This file uses a new mirrorlist system developed by Lance Davis for CentOS. # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-$releasever - Base mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4 #released updates [update] name=CentOS-$releasever - Updates mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4 #packages used/produced in the build but not released [addons] name=CentOS-$releasever - Addons mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons #baseurl=http://mirror.centos.org/centos/$releasever/addons/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras #baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus #baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4 #contrib - packages by Centos Users [contrib] name=CentOS-$releasever - Contrib mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib #baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4 [root@mytest yum]# cat /etc/yum.repos.d/CentOS-Media.repo # CentOS-Media.repo # # This repo is used to mount the default locations for a CDROM / DVD on # CentOS-4. You can use this repo and yum to install items directly off the # DVD ISO that we release. # # To use this repo, put in your DVD and use it with the other repos too: # yum --enablerepo=c4-media [command] # # or for ONLY the media repo, do this: # # yum --disablerepo=\* --enablerepo=c4-media [command] [c4-media] name=CentOS-$releasever - Media baseurl=file:///media/cdrom/ file:///media/cdrecorder/ gpgcheck=1 enabled=0 gpgkey=file:///usr/share/doc/centos-release-4/RPM-GPG-KEY-centos4 }}} {{{[repositoryid]}}} repositoryid 각 레포리토리마다 유일한 이름이다. name 은 name 는 사람이 읽기 쉽도록 설명을 단 것이다. {{{ [repositoryid] name=Some name for this repository baseurl=url://server1/path/to/repository/ url://server2/path/to/repository/ url://server3/path/to/repository/ }}} baseurl 은 yum 레파지토리의 repodata 디렉토리가 있는 URL이다. baseurl을 여러개 두면 앞의 것은 무시가 되므로 이런 방식으로 사용하지 말고 위와 같이 url을 여러개 사용하면 된다. 기본적으로 failovermethod 가 roundrobin 으로 되어있는데(기본값임) priority 로 바꾸면 위에 있는 것부터 조회를 하게 된다. 가까운 네트워크의 서버를 강제로 지정하는 것도 좋은 방식일 것이다. gpgcheck 는 gpg 체크여부이다. enabled 는 해당 레포지터리를 활성화할 것인지에 대한 여부이며 centosplus, contrib 은 비활성화되어 있다. 참고로 cetosplus 레퍼지토리에는 mysql 5.0, php 5.x 등의 최근 패키지가 들어있다. $releasever 는 distroverpkg 에서 지정한 패키지의 버전을 담는 변수이다. $basearch 는 기본아키텍처로 $arch 가 i686 일 경우 i386이 된다. === 데이터 미러링 하기 === 처음 설치시 레파지토리 설정은 mirrorlist를 이용한다. mirrorlist.centos.org 의 사이트를 이용하여 미러사이트를 자동으로 찾고 그 사이트를 이용하여 업데이트를 하는 것이다. baseurl은 직접 특정 url을 지정하는 것이다. mirrorlist 실행을 수동으로 해서 확인해보면 아래와 같다. yum 에서 자동으로 가까운 지역사이트의 미러리스트를 찾아준다. 결과를 보면 한국, 중국, 일본사이트이다. {{{ http://mirrorlist.centos.org/?release=4.4&arch=i386&repo=os http://mirror.tini4u.net/centos/4.4/os/i386/ http://mirror.secuidc.com/centos/4.4/os/i386/ http://rsync.atworks.co.jp/centos/4.4/os/i386/ http://ftp.nara.wide.ad.jp/pub/Linux/centos/4.4/os/i386/ http://ftp.riken.jp/Linux/centos/4.4/os/i386/ http://ftp.yz.yamagata-u.ac.jp/pub/linux/centos/4.4/os/i386/ http://ftp.iij.ad.jp/pub/linux/centos/4.4/os/i386/ http://mirror.vmmatrix.net/CentOS/4.4/os/i386/ http://mirror.be10.com/centos/4.4/os/i386/ http://centos.hostlink.com.hk/4.4/os/i386/ http://mirrorlist.centos.org/?release=4.3&arch=i386&repo=os 4.3 is not a valid release or hasnt been released yet }}} 현재 공식미러사이트에서 한국은 두가지가 있다. http://mirror.secuidc.com/centos/ http://mirror.tini4u.net/centos/ === 레퍼지토리 로컬로 바꾸기 === 레파지토리를 로컬네트워크로 바꾸기 위해서 centos 4.3 의 os, updates 를 rsync를 이용하여 로컬에 미러링하였다. 미러링은 ftp.sayclub.com 등 다른 사이트를 이용할 수도 있다. {{{ * 4.3 대 ftp.sayclub.com # rsync -avH --delete ftp.sayclub.com::ftp/pub/linux/centos/4.3/os/i386 /data/centos/4.3/os # rsync -avH --delete ftp.sayclub.com::ftp/pub/linux/centos/4.3/updates/i386 /data/centos/4.3/updates * 4.4 대 ftp.sayclub.com # rsync -avH --delete ftp.sayclub.com::ftp/pub/linux/centos/4.4/os/i386 /data/centos/4.4/os # rsync -avH --delete ftp.sayclub.com::ftp/pub/linux/centos/4.4/updates/i386 /data/centos/4.4/updates }}} 아래와 같이 바꾸어 처리를 하려고 했는데 이상하게도 releasever 가 4.3이 아니라 4로 나와서 에러가 생겼다. {{{ # cat j2.repo [base] name=CentOS-$releasever - Base #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os baseurl=http://222.112.137.162/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4 #released updates [update] name=CentOS-$releasever - Updates #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates baseurl=http://222.112.137.162/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4 }}} 그래서 아래와 갈이 $releasever 를 4.3으로 바꾸어 실행하면 실행은 되지만 실제 업데이트는 되지 않았다. {{{ [base] name=CentOS-4.3 - Base #mirrorlist=http://mirrorlist.centos.org/?release=4.3&arch=$basearch&repo=os baseurl=http://222.112.137.162/centos/4.3/os/$basearch/ gpgcheck=0 gpgkey=http://222.112.137.162/centos/RPM-GPG-KEY-centos4 #released updates [update] name=CentOS-4.3 - Updates #mirrorlist=http://mirrorlist.centos.org/?release=4.3&arch=$basearch&repo=updates baseurl=http://222.112.137.162/centos/4.3/updates/$basearch/ gpgcheck=0 gpgkey=http://222.112.137.162/centos/RPM-GPG-KEY-centos4 }}} ip를 변경하는 것만으로 달라지는 것은 소스와는 상관없는 문제일듯하였는데 4.4, 4.3 디렉토리에서 4 가 4.4 로 심볼릭 링크가 되어있었다. releasever 가 4로 되어있는 듯하였다. 이렇게 심볼릭 링크를 걸어주고 나서는 정상적으로 업데이트가 되었다. {{{ # ls -alF 합계 20 drwxr-xr-x 4 root root 4096 9월 27 19:36 ./ drwxr-xr-x 3 root root 4096 9월 27 19:26 ../ lrwxrwxrwx 1 root root 3 9월 27 19:36 4 -> 4.4/ drwxr-xr-x 4 root root 4096 9월 26 20:43 4.3/ drwxr-xr-x 4 root root 4096 9월 27 16:15 4.4/ -rw-r--r-- 1 root root 1795 2월 27 2005 RPM-GPG-KEY-centos4 }}} 주기적으로 cron 으로 os 및 업데이트를 동기화하고 내부적으로 이 사이트를 이용하여 설치 및 보안업데이트를 이용하면 불필요한 트래픽을 줄이고 속도도 개선이 될 것이다. === 별도의 저장소 생성하기 === 예전 yum-arch 가 했던 역할이 createrepo 로 바뀌었다. yum-arch 가 하는 일은 디렉토리에 들어있는 rpm을 간추리고 각각의 rpm을 위한 헤더를 만들어낸다. 해당 디렉토리에 headers 라는 디렉토리가 이에 해당한다. 그런데 언제부터인지는 모르지만 cent os 4.4 현재는 headers 라는 디렉토리를 쓰지 않고 repodata 를 이용한다. 그래서 yum-arch 를 실행하면 다음 메시지가 나온다. {{{ THIS PROGRAM IS DEPRECATED! You should be generating xml metadata instead. Please see http://linux.duke.edu/metadata }}} 현재는 createrepo 라는 프로그램을 이용하여 xml 형태로 rpm 정보를 만들어낸다. createrepo 프로그램을 이용하여 원하는 디렉토리에서 실행을 하면 repodata 란 디렉토리가 생기면서 정보가 생긴다. http://linux.duke.edu/projects/metadata/ {{{ # yum-arch /data/centos/joon/i386 }}} 명령실행후 /data/centos/joon/i386/headers 디렉토리를 생성한다. 이제 createrepo 프로그램에 대해 알아보자. 먼저 createrepo 프로그램을 설치한다. {{{ # yum -y install createrepo }}} createrepo 프로그램을 이용하여 rpm 정보를 만든다. {{{ # createrepo /data/centos/joon/i386 [root@mytest i386]# ls repodata/ filelists.xml.gz other.xml.gz primary.xml.gz repomd.xml }}} headers 라는 디렉토리는 실제 없어도 되는 디렉토리라 볼 수 있다. yum install 등을 하면 이때 repodata 에서 패키지 정보를 읽어서 자기 로컬의 /var/cache/yum 의 해당하는 항목에 headers 를 생성하는 것이다. 위에서 만든 저장소를 이용하려면 클라이언트의 /etc/yum.repos.d 의 레포지토리 설정파일을 수정해야 한다. 기본파일명은 CentOS-Base.repo 이지만 다른 파일명으로 바꾸어도 상관없다. {{{ [joon] name=CentOS-joon baseurl=http://cent.tunelinux.pe.kr/centos/joon/i386 gpgcheck=0 enabled=1 }}} 만약 저장소(rpm 있는 yum 서버)에서 패키지 변경이 생긴 경우에는 rpm 저장소가 있는 서버에서는 createrepo 프로그램을 다시 실행해주면 되는데 저장소를 이용하려는 쪽에서는 캐쉬를 지워주어야 한다. clean 에서 packages 는 다운받은 rpm을 지워주고 headers 는 다운받은 헤더파일을 지워주는데 이상하게도 clean all 을 해야 바뀐 부분이 반영이 되었다. {{{ yum clean packages Eliminate any cached packages from the system. Note that packages are not automatically deleted after they are downloaded. yum clean headers Eliminate all of the files which yum uses to determine the remote availability of packages. Using this option will force yum to download all the headers the next time it is run. yum clean all Runs yum clean packages and yum clean headers as above. }}} 물론 CentOS 배포판에서는 RPM 목록이 바뀔일이 없지만 자체적으로 저장소를 만들어 운영하는 경우에는 빈번한 변경이 생길 수가 있다. 이때문에 자체 저장소를 만들어 이용하는 경우에는 각 yum client 에서 캐쉬를 정기적으로 지워주는 것이 필요할 것이다. == yum 레퍼지토리 별도 생성한 실제 내용 == yum 서버를 mirror.direct.co.kr 로 지정한 경우이다. 웹서버에서 /var/www/html/data 를 /data 디렉토리로 심볼릭 링크시킨 경우이다. centos 디렉토리는 centos 4.4 에 대한 미러사이트로 i386/x86_64 아키텍쳐에 대한 os, updates 를 미러링하고 있다. samjung 디렉토리는 자체적으로 사용하는 rpm을 올려놓은 곳으로 현재 mysql 5.x 와 mysq 5.x에 맞춘 php rpm을 사용하고 있다. {{{ [root@mirrot data]# pwd /data [root@mirrot data]# tree -d . |-- centos | |-- 4 -> 4.4/ | `-- 4.4 | |-- os | | |-- i386 | | | |-- CentOS | | | | |-- RPMS | | | | `-- base | | | |-- NOTES | | | |-- headers | | | |-- images | | | | `-- pxeboot | | | |-- isolinux | | | `-- repodata | | `-- x86_64 | | |-- CentOS | | | |-- RPMS | | | `-- base | | |-- NOTES | | |-- headers | | |-- images | | | `-- pxeboot | | |-- isolinux | | `-- repodata | `-- updates | |-- i386 | | |-- RPMS | | |-- headers | | `-- repodata | `-- x86_64 | |-- RPMS | |-- headers | `-- repodata `-- samjung |-- 4 -> 4.4 `-- 4.4 |-- SRPMS |-- i386 | |-- RPMS | `-- repodata `-- x86_64 |-- RPMS `-- repodata }}} 위에서 php, mysql 5.x 패키지는 /data/samjung/4.4/i386 에 있다. 여기서 이 디렉토리를 yum 클라이언트에서 이용하기 위해서는 아래와 갈이 세팅을 한다. RPMS_DIR=/data/samjung/4.4 # /usr/bin/createrepo $RPMS_DIR/i386/ /data/samjung/4.4/i386/repodata 는 rpm 정보에 대한 메타디렉토이다. 이제 아래와 같이 해서 yum client 에서 사용을 하면 된다. 주목할 옵션은 아래와 같다. baseurl 을 여러개 지정했으며 failovermethod=priority 로 해두면 baseurl에 지정한 순서대로 서버를 찾는다. 기본은 random이다. base, update 에서 exclude 를 지정하여 mysql, php 는 samjung repository 에서 이용하도록 해두었다. {{{ [root@localhost yum.repos.d]# cat /etc/yum.repos.d/samjung.repo [base] name=CentOS-$releasever - Base baseurl=http://mirror.direct.co.kr/centos/$releasever/os/$basearch/ http://mirror.secuidc.com/centos/$releasever/os/$basearch/ http://mirror.tini4u.net/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4 failovermethod=priority exclude=MySQL* mysql* php* #released updates [update] name=CentOS-$releasever - Updates baseurl=http://mirror.direct.co.kr/centos/$releasever/updates/$basearch/ http://mirror.secuidc.com/centos/$releasever/updates/$basearch/ http://mirror.tini4u.net/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4 failovermethod=priority exclude=MySQL* mysql* php* [samjung] name=CentOS-samjung baseurl=http://mirror.direct.co.kr/samjung/$releasever/$basearch/ gpgcheck=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4 enabled=1 }}} See also: [Yum-HOWTO]