본문으로 바로가기

Software 관리_Source file

category Linux/Linux Server 2017. 9. 1. 15:11
  • 소스 ( Source ) 파일로 설치하기

시스템을 관리하는데 있어서 간편한 RPM 패키지 설치보다는, 경우에 따라서 소스 코드를 직접 컴파일하여 설치해야하는 경우도 적지 않다. 특히 프로그램 버그에 대한 패치를 적용하기 위해서는 소스 코드가 있어야 하며, 소스 코드에 패치를 가하여 컴파일하여 설치하므로써 프로그램의 버그를 고칠 수 있다. 


- 소스 형태로 소프트웨어를 설치하는 이유

1) 최신 버전의 오픈 소스 소프트웨어(최신 기능)를 사용하기 위해서 

rpm이나 exe 같이 설치 패키지로 나오기까지 검증기간이 오래 걸려 빨리 사용하려면 스스로 다운받아서 사용해야 한다.

2) 오픈 소스 소프트웨어의 크기를 줄이기 위해서

여러 기능중 자신이 사용하는 기능의 소스만을 컴파일해서 용량을 줄인다 ->속도 증가

3 )고객이 낮은 버전의 S/W를 요청 -> 낮은 버전의 Library (X)

필요한 낮은 버전의 소스를 다른 파일에 따로 독립적으로 구성해서 사용한다. 

4) 보안장비의 보안 S/W가 Open Source를 설치하는 경우에는 소스형태로 컴파일 한다.



[예] Apache 2.X 소스 컴파일 

과정)

소스파일 다운로드

압축 해제

configure

make

make install

웹서비스 시작 및 확인


설정)

소스파일 다운로드 디렉토리 : /test

프로그램 소스 디렉토리       : /usr/local/src

프로그램 설치 디렉토리       : /usr/local/apache2


1) 소스 다운로드 

http://httpd.apache.org/download.cgi#apache22


[참고] pgp md5 sha1

소스 파일 옆에 있는 pgp, md5, sha1 은 해쉬 암호 알고리즘으로 암호화 되어있다.

이러한 파일은 소스파일을 다운 받았을때 그 소스가 원작자가 만들어놓은 소스와 같은지 비교를 하는 것이다. 

오픈 소스는 누구나 받아서 자신들의 소스를 추가해 사용할 수 있다. 만약 악의적인 목적을 가진 소스를 추가하고 다시 배포를 한다면 위험할 가능성이 있다.  이러한 것을 방지하기 위해 처음 배포할때 해쉬 알고리즘을 통해 암호를 만들어놓고 다운 받을때 이 암호화 비교를 해서 다르면 추가된 소스나 설치가 덜 되었음을 알수 있다.


# cd /test

# wget http://mirror.navercorp.com/apache//httpd/httpd-2.2.34.tar.gz

# ls

httpd-2.2.34.tar.gz


2) 압축해제 
# tar xvzf httpd-2.2.34.tar.gz -C /usr/local/src    /* -C : change directory 압축해제할 곳을 바꾼다. */

# cd /usr/local/src
# ls -l
drwxr-xr-x 11 1001 1001 4.0K  7월  7 04:19 httpd-2.2.34

-문서 확인
# cd httpd-2.2.34
# ls
ABOUT_APACHE    LAYOUT         README-win32.txt  config.layout  httpd.mak     os/
Apache.dsw      LICENSE        README.platforms  configure*     httpd.spec    server/
BuildAll.dsp    Makefile.in    ROADMAP           configure.in   include/      srclib/
BuildBin.dsp    Makefile.win   VERSIONING        docs/          libhttpd.dep  support/
CHANGES         NOTICE         acinclude.m4      emacs-style    libhttpd.dsp  test/
INSTALL         NWGNUmakefile  build/            httpd.dep      libhttpd.mak
InstallBin.dsp  README         buildconf*        httpd.dsp      modules/

소스 코드에 어떤 옵션을 부여해서 어떻게 컴파일해야 하는지 컴파일 방법에 대한 자세한 정보가 있는 설치 문서인 README 또는 INSTALL 파일이 소스 파일내에 포함되어 있으므로, 컴파일하기 전에 이러한 문서를 잘 읽어 보고 컴파일하는 것이 좋다. 소스 코드의 컴파일 순서는 대부분 소스의 경우에는 동일하지만, 약간의 차이가 있는 경우도 있으므로, 항상 설치 문서를 참고하는 습관을 갖는 것이 현명하다.

3) configure
configure 작업은 컴파일을 하는데 있어서 컴파일러 존재 여부 확인,  컴파일 환경 옵션 지정,  컴파일에 필요한 라이브러리 검색 등 컴파일 환경을 준비하는 과정으로, configure 명령에 의해서 Makefile 파일이 준비되는 과정이다. Makefile 파일은 make 명령으로 컴파일될 때 이용되는 파일로 이 파일이 생성되지 않으면 컴파일될 수 없으며,컴파일 환경 설정 작업에 잘못 되었거나 수정해야 할 경우 configure 명령을 재실행하지 않고서도 이 파일의 설정값을 에디터로 수정하여 할 수 있다.

소스 컴파일 시 configure  명령에 가장 많이 사용되는 옵션중의 하나가 --prefix= 옵션이다.  이 옵션을 이용하면 소스 컴파일 후 컴파일된 프로그램이 설치될 경로를 지정해 줄 수 있고, 컴파일된 프로그램을 제거할 때 --prefix= 옵션으로 명시한 디렉토리를 통째로 삭제해 줌으로써 쉽게 프로그램을 제거할 수 있는 이점이 있다.

# ./configure --prefix=/usr/local/apache2
[참고] 컴파일 과정이므로 gcc 패키지가 없으면 안된다.
# rpm -qa | grep gcc
# yum -y install gcc

# ls     /* configure 과정 다음 Makefile 이 만들어졌다 */
ABOUT_APACHE    Makefile          VERSIONING     configure.in  libhttpd.dsp
Apache.dsw      Makefile.in       acinclude.m4   docs          libhttpd.mak
BuildAll.dsp    Makefile.win      build          emacs-style   modules
BuildBin.dsp    NOTICE            buildconf      httpd.dep     modules.c
CHANGES         NWGNUmakefile     config.layout  httpd.dsp     os
INSTALL         README            config.log     httpd.mak     server
InstallBin.dsp  README-win32.txt  config.nice    httpd.spec    srclib
LAYOUT          README.platforms  config.status  include       support
LICENSE         ROADMAP           configure      libhttpd.dep  test

4) make
다음은 아파치 소스를 make로 컴파일 한다.
# make

5) make install 
make로 컴파일된 소스 프로그램은 --prefix 로 지정된 경로로 설치된다.
# make install
-> apache2 가 생겼다.
# cd /usr/local/apache2
# ls
bin    cgi-bin  error   icons    lib   man     modules
build  conf     htdocs  include  logs  manual

6) 서비스 시작 및 확인
# cd /usr/local/apache2/bin
# ./apachectl start        /* 소스로 받은 httpd 를 실행한다. */
# pgrep -lf httpd        /* 확인 */
32211 /usr/local/apache2/bin/httpd -k start
32212 /usr/local/apache2/bin/httpd -k start
32213 /usr/local/apache2/bin/httpd -k start
32214 /usr/local/apache2/bin/httpd -k start
32215 /usr/local/apache2/bin/httpd -k start
32216 /usr/local/apache2/bin/httpd -k start

# firefox http://IP    /* 자신의 IP 쓰시면 됩니다. */

/* 잘 동작 하는걸로 보입니다. */ 
# cat /usr/local/apache2/htdocs/index.html    /* 변경하려면 이 파일을 건들여 주시면 됩니다. */
<html><body><h1>It works!</h1></body></html>

-제거
# cd /usr/local/apache2/bin 
# ./apachectl stop 
# pgrep –lf httpd 

# cd 
# rm -rf /usr/local/apache2

[알아두기]
소스 형태로 설치한 프로그램(EX: apache2)은 "rpm -qa | grep apache" 확인이 가능한가?
가능하지 않다. 소스는 따로 검색되지 않기 때문에 만든 사람이 아니면 찾기가 어려워 잘 알아둬야한다.
"rm -rf /usr/local/apache2" 디렉토리 삭제 후 다시 만들고 싶다면? 
다른건 건들이지 않고 --prefix의 디렉토리만 지웠다면 압축을 해제한 곳에서 # make install 만 입력하면 다시 만들어진다.
소스 디렉토리(EX: /usr/local/src)에서 configure/make/make install를 다시 실행하고 싶다면?
# cd /usr/local/src
# make clean


[연습하기] 
APM(Apache + PHP + MySQL) 설치
ATJO(Apache + Tomcat + JAVA(JDK/SDK) + Oracle) 설치A



  • 소스파일로 설치한 프로그램을 rpm 파일로 만들기
rpm  패키지 생성 절차
(ㄱ) 소스 프로그램 개발 
(ㄴ) 소스.tar.gz 파일 생성
(ㄷ) SPEC 파일 생성
(ㄹ) rpm build
(ㅁ) GPG Key 생성
(ㅂ) 패키지 sign
(ㅅ) Yum Repository 구성
(ㅇ) 테스트

(ㄱ) 소스 프로그램 개발
# cd /test
# mkdir -p hello-1.0
# vi hello-1.0/hello.sh

#!/bin/bash

echo 'This is a test.'

(ㄴ) 소스.tar.gz 파일 생성
[선수] # ls /usr/src/redhat /*  없다면 */
# yum -y install rpm-build

# ls /usr/src/redhat
# tar cvzf /usr/src/redhat/SOURCES/hello-1.0-1.tar.gz hello-1.0

(ㄷ) SPEC 파일 생성
# vi /usr/src/redhat/SPECS/hello.spec
(참고) spec 파일 만들기
spec 파일을 만드는 과정이 가장 중요하면 다음과 같은 사이트를 참고 하여 적당한 spec 파일을 만들어 보자.
http://kthan.tistory.com/entry/리눅스Linux-RPM-만드는-방법과-spec파일-작성법
http://onecellboy.tistory.com/267
------------------------------
%define name hello
%define version 1.0
%define release 1
/* hello-1.0-1....*/

Name:           hello
Version:        1.0
Release:        1
Summary:        Hello
Group:          CentOS
License:        GPL
URL:            http://www.example.com
Source0:        %{name}-%{version}-%{release}.tar.gz
BuildRoot:      /var/tmp/%{name}-buildroot

%description
Installs        /root/bin/hello.sh

%prep
%setup -q -n %{name}-%{version}

%build

%install 
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/root/bin
install -m 755 hello.sh $RPM_BUILD_ROOT/root/bin/hello.sh

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root,-)
/root/bin/hello.sh

%changelog
----------------------------

(ㄹ) rpm build
# yum -y install rpm-build
# rpmbuild -ba /usr/src/redhat/SPECS/hello.spec

# tree /usr/src/redhat
 -> hello-1.0-1.i386.rpm 이 생긴것을 알수 있다.

# cd /usr/src/redhat/RPMS/i386 
# rpm -Uvh hello-1.0-1.i386.rpm 
# hello.sh

# rpm -qa | grep hello 
# rpm -qi hello

# rpm -e hello
# rpm -qa | grep hello

(ㅁ) GPG Key 생성
# cd
# gpg --gen-key

gpg (GnuPG) 1.4.5; Copyright (C) 2006 Free Software Foundation, Inc.

This program comes with ABSOLUTELY NO WARRANTY.

This is free software, and you are welcome to redistribute it

under certain conditions. See the file COPYING for details.


gpg: directory `/root/.gnupg' created

gpg: new configuration file `/root/.gnupg/gpg.conf' created

gpg: WARNING: options in `/root/.gnupg/gpg.conf' are not yet active during this run

gpg: keyring `/root/.gnupg/secring.gpg' created

gpg: keyring `/root/.gnupg/pubring.gpg' created

Please select what kind of key you want:

   (1) DSA and Elgamal (default)  /* 패키지는 보통 DSA */

   (2) DSA (sign only)

   (5) RSA (sign only)

Your selection? <ENTER>

DSA keypair will have 1024 bits.

ELG-E keys may be between 1024 and 4096 bits long.

What keysize do you want? (2048) <ENTER> /* 키 길이 */

Please specify how long the key should be valid.

         0 = key does not expire

      <n>  = key expires in n days

      <n>w = key expires in n weeks

      <n>m = key expires in n months

      <n>y = key expires in n years

Key is valid for? (0) <ENTER> /* 유효기간 1년이면 1년후 키 다시 받아야함*/

Key does not expire at all

Is this correct? (y/N) y


You need a user ID to identify your key; the software constructs the user ID

from the Real Name, Comment and Email Address in this form:

    "Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"


Real name: Baik, SeoungChan

Email address: jang4sc@hanmail.net

Comment: <ENTER>

You selected this USER-ID:

    "Baik, SeoungChan <jang4sc@hanmail.net>"


Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o

You need a Passphrase to protect your secret key.


Passphrase: testing123

Repeat passphrase: testing123

We need to generate a lot of random bytes. It is a good idea to perform

some other action (type on the keyboard, move the mouse, utilize the

disks) during the prime generation; this gives the random number

generator a better chance to gain enough entropy.

++++++++++..++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++.+++++++++++++++.+++++.+++++..++++++++++..>+++++.....................................................+++++


Not enough random bytes available.  Please do some other work to give

the OS a chance to collect more entropy! (Need 283 more bytes)

We need to generate a lot of random bytes. It is a good idea to perform

some other action (type on the keyboard, move the mouse, utilize the

disks) during the prime generation; this gives the random number

generator a better chance to gain enough entropy.

.+++++++++++++++++++++++++.++++++++++.+++++.++++++++++......+++++++++++++++..+++++++++++++++..+++++.+++++++++++++++.+++++++++++++++++++++++++.+++++.++++++++++.+++++>.+++++.+++++...>+++++..................................................................................+++++^^^

gpg: /root/.gnupg/trustdb.gpg: trustdb created /* 꼭 적어두어야한다. */

gpg: key ACD89B3E marked as ultimately trusted

public and secret key created and signed.


gpg: checking the trustdb

gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model

gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u

pub   1024D/ACD89B3E 2014-01-23

      Key fingerprint = 98A1 E2A6 AE47 FE97 BFE8  6DC4 BCAB 0ADE ACD8 9B3E

uid                  Baik, SeoungChan <jang4sc@hanmail.net>

sub   2048g/CA2DE316 2014-01-23 




# cd
# cd .gnupg

(ㅂ) 패키지 sign
# gpg -a -o ~/RPM-GPG-KEY-test --export ACD89B3E
# ls RPM*

# cat RPM-GPG-KEY-test

# vi ~/.rpmmacros
%_gpg_name ACD89B3E

# rpm --resign /usr/src/redhat/RPMS/i386/hello-1.0-1.i386.rpm

(ㅅ) YUM Repository 구성
# mkdir /var/www/html/packages 
# cp /usr/src/redhat/RPMS/i386/hello*.rpm /var/www/html/packages 
# cp RPM-GPG-KEY-test /var/www/html/packages 
# tree /var/www/html 

# yum -y install createrepo 
# createrepo /var/www/html/packages

# tree /var/www/html
# service httpd restart 

(ㅇ) 테스트
# vi /etc/yum.repos.d/hello.repo 
[hello]
name=hello
description=Test Yum Repository
baseurl=http://IP/packages
enabled=1
gpgcheck=1
gpgkey=http://IP/packages/RPM-GPG-KEY-test

 







'Linux > Linux Server' 카테고리의 다른 글

사용자 그룹 관리  (0) 2017.09.05
부팅과정  (0) 2017.09.04
Software 관리_YUM  (0) 2017.09.01
Software 관리_RPM  (0) 2017.08.31
SWAP  (0) 2017.08.31