날짜별 글 목록: 2015년 6월 26일

RPM 패키지 만들기 실습

사전 작업

프로그램 작성

실습을 위해 world를 출력하는 hello 스크립트를 작성해보자.

mkdir hello-1.0.0
cat <<EOF > hello-1.0.0/hello
#!/bin/bash
echo world
EOF
sh hello-1.0.0/hello
[builduser@jmnote ~]$ mkdir hello-1.0.0
[builduser@jmnote ~]$ cat <<EOF > hello-1.0.0/hello
> #!/bin/bash
> echo world
> EOF
[builduser@jmnote ~]$ sh hello-1.0.0/hello
world

압축

[builduser@jmnote ~]$ tar czvf hello-1.0.0.tar.gz hello-1.0.0/
hello-1.0.0/
hello-1.0.0/hello

SPEC 파일 작성

 hello.spec 문서를 참고하십시오.

hello.spec 파일(새파일)을 열어서 hello.spec의 내용으로 채우고 저장.

[builduser@jmnote ~]$ vi hello.spec

rpm 빌드

[builduser@jmnote ~]$ rpmbuild hello.spec
error: File /home/builduser/rpmbuild/SOURCES/hello-1.0.0.tar.gz: No such file or directory
→ 빌드를 위한 폴더 구조를 만들기 위해 rpmbuild를 실행 (오류 발생하지만 무시)
[builduser@jmnote ~]$ cp hello-1.0.0.tar.gz rpmbuild/SOURCES/
[builduser@jmnote ~]$ cp hello.spec rpmbuild/SPECS/
[builduser@jmnote ~]$ cd rpmbuild/SPECS/
[builduser@jmnote SPECS]$ rpmbuild --sign -ba hello.spec
Enter pass phrase:
 rpm-build를 위한 GPG Key 생성에서 입력했던 Passphrase 값 입력
Pass phrase is good.
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.hUcv0F
+ umask 022
+ cd /home/builduser/rpmbuild/BUILD
+ cd /home/builduser/rpmbuild/BUILD
... (생략)
+ cd hello-1.0.0
+ rm -rf /home/builduser/rpmbuild/BUILDROOT/hello-1.0.0-1.el6.x86_64
+ exit 0
[builduser@jmnote SPECS]$ cd ../RPMS/x86_64/
[builduser@jmnote x86_64]$ ll
total 4
-rw-rw-r--. 1 builduser builduser 2546 May 17 02:24 hello-1.0.0-1.el6.x86_64.rpm
→ 그럴싸한 rpm 파일이 생성되었다.

rpm 설치 및 확인

  • root 계정에서 진행
[root@zetawiki ~]# rpm --import /home/builduser/RPM-GPG-KEY-builduser
[root@zetawiki ~]# cp /home/builduser/rpmbuild/RPMS/x86_64/hello-1.0.0-1.el6.x86_64.rpm ~
[root@zetawiki ~]# rpm -ivh hello-1.0.0-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:hello                  ########################################### [100%]
[root@zetawiki ~]# rpm -qa hello
hello-1.0.0-1.el6.x86_64
[root@zetawiki ~]# which hello
/usr/local/bin/hello
[root@zetawiki ~]# rpm -qf /usr/local/bin/hello
hello-1.0.0-1.el6.x86_64
[root@zetawiki ~]# hello
world

같이 보기

YUM 저장소 만들기 실습

사전 작업

긴 실습 (rpm 만들기 포함)
짧은 실습 (rpm 만들기 미포함)[1]

저장소 생성

  • DOCUMENT_ROOT 아래에 /repo/Packages 폴더를 만든다.
[root@zetawiki ~]# mkdir -p /var/www/html/repo/Packages
[root@zetawiki ~]# cp hello-1.0.0-1.el6.x86_64.rpm /var/www/html/repo/Packages/
[root@zetawiki ~]# createrepo -v /var/www/html/repo/
Spawning worker 0 with 1 pkgs
Worker 0: reading Packages/hello-1.0.0-1.el6.x86_64.rpm
Workers Finished
Gathering worker results
 
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Starting other db creation: Sun Jun  8 14:39:05 2014
Ending other db creation: Sun Jun  8 14:39:05 2014
Starting filelists db creation: Sun Jun  8 14:39:05 2014
Ending filelists db creation: Sun Jun  8 14:39:05 2014
Starting primary db creation: Sun Jun  8 14:39:05 2014
Ending primary db creation: Sun Jun  8 14:39:05 2014
Sqlite DBs complete
[root@zetawiki ~]# cp /home/builduser/RPM-GPG-KEY-builduser /var/www/html/repo/
[root@zetawiki ~]# curl http://127.0.0.1/repo/RPM-GPG-KEY-builduser
-----BEGIN PGP PUBLIC KEY BLOCK-----
... (생략)
-----END PGP PUBLIC KEY BLOCK-----

다른 컴퓨터에서 테스트

접속 확인

[root@CentOS63 ~]# nc -z 135.79.246.80 80
Connection to 135.79.246.80 80 port [tcp/http] succeeded!
[root@CentOS63 ~]# curl http://135.79.246.80/repo/RPM-GPG-KEY-builduser
-----BEGIN PGP PUBLIC KEY BLOCK-----
... (생략)
-----END PGP PUBLIC KEY BLOCK-----

repo 등록

echo '[my-first-repo]
name=My First Repo
baseurl=http://서버주소/repo
gpgkey=http://서버주소/repo/RPM-GPG-KEY-builduser
enabled=1
gpgcheck=1' > /etc/yum.repos.d/my-first-repo.repo
yum repolist
[root@CentOS63 ~]# echo '[my-first-repo]
> name=My First Repo
> baseurl=http://135.79.246.80/repo
> gpgkey=http://135.79.246.80/repo/RPM-GPG-KEY-builduser
> enabled=1
> gpgcheck=1' > /etc/yum.repos.d/my-first-repo.repo
[root@CentOS63 ~]# yum repolist
... (생략)
repo id        repo name                                        status
base           CentOS-6 - Base                                   6,367
epel           Extra Packages for Enterprise Linux 6 - x86_64   10,899
extras         CentOS-6 - Extras                                    14
my-first-repo  My First Repo                                         1
updates        CentOS-6 - Updates                                1,009
repolist: 18,290
→ 패키지를 1개 가진 my-first-repo가 보인다.

hello 패키지 설치

======================================================================
 Package     Arch         Version           Repository           Size
======================================================================
Installing:
 hello       x86_64       1.0.0-1.el6       my-first-repo       2.5 k
 
Transaction Summary
======================================================================
Install       1 Package(s)
 
Total download size: 2.5 k
Installed size: 23  
Is this ok [y/N]: y
... (생략)
Installed:
  hello.x86_64 0:1.0.0-1.el6                                          
 
Complete!
[root@zetawiki ~]# rpm -qa hello
hello-1.0.0-1.el6.x86_64
[root@zetawiki ~]# hello
world

같이 보기