Operating System...Beautiful

검색 :
RSS 구독 : 글 / 댓글 / 트랙백 / 글+트랙백

Apache2 소스 컴파일

2008/08/15 21:48, 글쓴이 ruo91

준비물

1. 아파치2 소스 파일

2. SSH 클라이언트 (필자는 한글 Putty를 이용하여 접속)


아파치2 소스파일을 아래 사이트에서 다운받습니다.

http://ftp.kaist.ac.kr/pub/Apache/httpd/ 이 글에선 2.2.6 버전으로 설치 하겠습니다.

필자는 SSH 로 wget 명령어를 써서 /usr/local/ 디렉토리로 다운 받겠습니다.

cd /usr/local 를 사용하여 디렉토리로 이동 후 아래와 같이 입력하신후 엔터눌러주시면 다운 됩니다.

wget http://ftp.kaist.ac.kr/pub/Apache/httpd/httpd-2.2.6.tar.gz

*아래는 /usr/local 디렉토리로 이동후에 wget 으로 다운받는 방법까지 상세하게 적어놨습니다


root@ruo91:~# cd /usr/local
root@ruo91:/usr/local# wget http://ftp.kaist.ac.kr/pub/Apache/httpd/httpd-2.2.6.tar.gz
--21:54:56--  http://ftp.kaist.ac.kr/pub/Apache/httpd/httpd-2.2.6.tar.gz
           => `httpd-2.2.6.tar.gz'
Resolving ftp.kaist.ac.kr... 143.248.234.110
Connecting to ftp.kaist.ac.kr|143.248.234.110|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6,028,951 (5.7M) [application/x-gzip]
100%[============================================>] 6,028,951 1.60M/s ETA 00:00
21:55:00 (1.50 MB/s) - `httpd-2.2.6.tar.gz' saved [6028951/6028951]

소스파일을 다운받았으니까 이제는 압축을 풀어줍니다.

압축 푸는 명령어는 "tar -xzvf 파일명모든이름" 입니다.

즉, "tar -xzvf httpd-2.2.6.tar.gz" 가 되겠지요~

========================================================================================

x : tar파일을 풉니다.

z : tar 파일을 사용할 때 gzip을 필터로 사용, gzip을 통해 tar 압축과 풀기가 가능

v : 명령에 대한 파일의 정보를 보여줍니다.

f :  작업 대상이 되는 tar 파일의 이름을 지정합니다.

=======================================================================================

root@ruo91:/usr/local# tar -xzvf httpd-2.2.6.tar.gz
......
......
httpd-2.2.6/test/test-writev.c
httpd-2.2.6/test/test_find.c
httpd-2.2.6/test/test_limits.c
httpd-2.2.6/test/test_parser.c
httpd-2.2.6/test/test_select.c
httpd-2.2.6/test/time-sem.c
httpd-2.2.6/test/zb.c
httpd-2.2.6/VERSIONING
root@ruo91:/usr/local#

... 은 압축풀때 파일이 많아 생략했다는 것입니다. 이제 /usr/local 디렉토리안에

httpd-2.2.6 이라는 디렉토리가 하나 생성 되었습니다. 이제...컴파일을 해보도록 하죠~ㅋ

컴파일 하기 위하여 httpd-2.2.6 디렉토리로 이동후에 아래처럼 하시면됩니다.

하기전에 먼저 /usr/local 디렉토리안에 apache 라는 디렉토리를 만듭니다.

mkdir 은 디렉토리를 만들때 사용되는 명령어 입니다.

mkdir /usr/local/apache 엔터 쳐서 /usr/local 디렉토리에 apache라는 디렉토리를 생성하고

cd .. 으로 상위로 올라가서 ls -a 명령어로 apache 폴더가 만들어 졌음을 확인 하는 방법입니다.


root@ruo91:/usr/local/httpd-2.2.6# mkdir /usr/local/apache
root@ruo91:/usr/local/httpd-2.2.6# cd ..
root@ruo91:/usr/local# ls -a
.           etc                 man                                        php4.4
..          games               mysql                                      sbin
apache      httpd-2.2.6         mysql-max-4.0.25-pc-linux-gnu-i686.tar.gz  share
apache2     httpd-2.2.6.tar.gz  mysql4.0                                   src
apache2_so  include             php
bin         lib                 php-4.4.7.tar.tar
root@ruo91:/usr/local#

apache 폴더를 만들었으니 이제 configure 를 이용하여 컴파일시 저장될 디렉토리를 지정 해줍니다.

./configure --prefix=/usr/local/apache/       Enter

root@ruo91:/usr/local/httpd-2.2.6# ./configure --prefix=/usr/local/apache/
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu

Configuring Apache Portable Runtime library ...

checking for APR... yes
  setting CC to "i486-linux-gnu-gcc"
  setting CPP to "i486-linux-gnu-gcc -E"
  setting CFLAGS to " -pipe -Wall -g -O2 -pthread"
  setting CPPFLAGS to " -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE"
  setting LDFLAGS to " "

Configuring Apache Portable Runtime Utility library...

checking for APR-util... yes
checking for gcc... i486-linux-gnu-gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether i486-linux-gnu-gcc accepts -g... yes
checking for i486-linux-gnu-gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... i486-linux-gnu-gcc -E
configure: Configuring PCRE regular expression library
configuring package in srclib/pcre now
checking for gcc... i486-linux-gnu-gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether i486-linux-gnu-gcc accepts -g... yes
checking for i486-linux-gnu-gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... i486-linux-gnu-gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
root@ruo91:/usr/local/httpd-2.2.6#

=============================================================================

--prefix=/usr/local/apache

컴파일해서 나올 파일들을 복사할 경로


--enable-so 

DSO(동적 공유 객체)사용 옵션으로 설치시 정적 객체들은 정적으로, 이후 동적 객체를 httpd.conf에 추가 함으로서 동적 사용이 가능하게 된다.


 동적 방식(DSO)과 정적(static) 방식의 차이

static 방식 : 아파치가 실행 될 때 모든 모듈을 메모리에 적재한다. 때문에 dso 방식보다 빠르지만   사용하지 않는 모듈도 메모리에 올라가기 때문에 쓸대없는 자원을 낭비 할 수 있다.

또한 운영중에 필요한 third-part 모듈이 있을 경우 아파치를 재컴파일 해야 한다.


DSO 방식 : 아파치가 실행되는 도중에 모듈이 필요할 경우면 따로 읽어서 시스템에 적재하는 방식   필요할 때만 메모리에 올리기 때문에 자원 이용이 효율적이지만 매번 읽어와야 하기 때문에 static에 비해 속도가 느리다. 실제로 아파치 DSO 관련 문서인 Advantage & Disadvantage 를 읽어 보면 DSO 방식의 운영은 아파치는 약 20% 서버 실행속도는 약 5% 정도 저하 된다고 나와 있다.

때문에 자주 사용하는 기본 모듈, 확장 모듈, third-part 모듈은 컴파일 시 정적으로 컴파일을 해 놓고자주 사용하지 않는 것들은 동적으로 설정하여 운영하면 효율이 좋다. 요즘은 서버가 좋아져서 대부분DSO 방식을 채택하며 그 속도의 차이는 매우 미미하여 느끼지 못할 정도이다.


--enable-rewrite : .htaccess 파일을 이용하여 정규표현식을 이용 URI 를 포워딩 해주는 것으로 파라미터등을 숨겨서 깔끔하게 표현 해 줄 수 있다.

=============================================================================

방금 환경 설정으로 /usr/local/apache 디렉토리로 복사할경로를 지정 해줬습니다.

이제 make 명령을 써서 apache 폴더에 복사를 하고 실행될 파일을 설치합니다.

root@ruo91:/usr/local/httpd-2.2.6# make
Making all in srclib
make[1]: Entering directory `/usr/local/httpd-2.2.6/srclib'
Making all in pcre
make[2]: Entering directory `/usr/local/httpd-2.2.6/srclib/pcre'
make[3]: Entering directory `/usr/local/httpd-2.2.6/srclib/pcre'
/usr/share/apr-1.0/build/libtool --silent --mode=compile i486-linux-gnu-gcc -pipe -Wall -g -O2 -pthread    -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE    -I/usr/local/httpd-2.2.6/srclib/pcre -I. -I/usr/local/httpd-2.2.6/os/unix -I/usr/local/httpd-2.2.6/server/mpm/prefork -I/usr/local/httpd-2.2.6/modules/http -I/usr/local/httpd-2.2.6/modules/filters -I/usr/local/httpd-2.2.6/modules/proxy -I/usr/local/httpd-2.2.6/include -I/usr/local/httpd-2.2.6/modules/generators -I/usr/local/httpd-2.2.6/modules/mappers -I/usr/local/httpd-2.2.6/modules/database -I/usr/include/apr-1.0 -I/usr/include/postgresql -I/usr/local/httpd-2.2.6/modules/proxy/../generators -I/usr/local/httpd-2.2.6/modules/ssl -I/usr/local/httpd-2.2.6/modules/dav/main  -prefer-non-pic -static -c pcre.c && touch pcre.lo
........
........
........
make[1]: Leaving directory `/usr/local/httpd-2.2.6'
root@ruo91:/usr/local/httpd-2.2.6#

make 할시에 컴파일 시간이 서버 사양에 따라 다소 시간이 지체될수 있습니다.

/usr/local/apache 디렉토리에 make 사용하여 파일을 복사 하였으니 이제 복사한 파일을 컴파일하여 실행 가능한 파일을 만들기위해 make install 을 사용합니다.

root@ruo91:/usr/local/httpd-2.2.6# make install
Making install in srclib
make[1]: Entering directory `/usr/local/httpd-2.2.6/srclib'
Making install in pcre
make[2]: Entering directory `/usr/local/httpd-2.2.6/srclib/pcre'
make[3]: Entering directory `/usr/local/httpd-2.2.6/srclib/pcre'
make[3]: Leaving directory `/usr/local/httpd-2.2.6/srclib/pcre'
make[2]: Leaving directory `/usr/local/httpd-2.2.6/srclib/pcre'
make[2]: Entering directory `/usr/local/httpd-2.2.6/srclib'
make[2]: Leaving directory `/usr/local/httpd-2.2.6/srclib'
make[1]: Leaving directory `/usr/local/httpd-2.2.6/srclib'
Making install in os
make[1]: Entering directory `/usr/local/httpd-2.2.6/os'
Making install in unix
............
............
Installing header files
Installing build system files
mkdir /usr/local/apache/build
Installing man pages and online manual
mkdir /usr/local/apache/man
mkdir /usr/local/apache/man/man1
mkdir /usr/local/apache/man/man8
mkdir /usr/local/apache/manual
make[1]: Leaving directory `/usr/local/httpd-2.2.6'
root@ruo91:/usr/local/httpd-2.2.6#

성공적으로 컴파일을 완료 하였습니다.

아파치를 가동 하기 위한 방법은 아래와 같습니다.

/usr/local/apache/bin 디렉토리 안에 apachectl 이라는 파일을 가동시키면 아파치가 가동됨

사용방법

/usr/local/apache/bin/apachectl start       <<<< 아파치를 최초로 가동한다.

/usr/local/apache/bin/apachectl stop       <<<< 아파치를 종료 한다.

/usr/local/apache/bin/apachectl restart    <<<< 아파치를 재시작 해준다.

아파치 설정파일은 /usr/local/apache/conf 디렉토리 안에 httpd.conf 를 수정하시면 됩니다.

크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
2008/08/15 21:48 2008/08/15 21:48

맨 위로