레이블이 apache인 게시물을 표시합니다. 모든 게시물 표시
레이블이 apache인 게시물을 표시합니다. 모든 게시물 표시

2012-09-14

FreeBSD] 아파치 서버과부하 해결책 - lingerd 설치법

작성 : 구자열 by webhost (danda@nate.com)

1. lingerd란 무엇일까?


아파치에서 갑작스런 libhttpd.ep 혹은 httpd가 상승하여 cpu혹은 메모리를 과도하게 점유할 경우, 일정 튜닝으로 이를 막을 순 있지만, Dos상당의공격에서는 데먼은 저절로 죽어버린다.

이때, lingerd라는 엑셀레이트를 설치하면, 아파치는 해당 과부하 프로쎄서를 죽이면서 서버가 죽는 것을 방지할 수 있다.

2. lingerd 구하기


http://www.iagora.com/about/software/lingerd/

3. 설치하기


mkdir -p /var/run/lingerd/
chown nobody.nobody /var/run/lingerd/
chmod 700 /var/run/lingerd/

tar xvzf lingerd-xxx.gz
cd lingerd-xxx
make
이렇게 하면 lingerd란 바이너리가 생긴다.

cp lingerd /usr/local/sbin
cp extra/lingerd.rc /etc/rc.d/init.d/lingerd
chkconfig --level 3 lingerd on
이렇게 해서 부트로더에 올린다.

/etc/rc.d/init.d/lingerd start


    cp apache-1.3/ap_lingerd.c li_config.h $APACHE/src/main/
    patch -p0 -d $APACHE/src/ < apache-1.3/aplinger.diff

이 과정은 아파치를 위한 과정이다.
아파치소스가 있는 폴더가 $APACHE라고 가정해서 입력하라.
즉 $APACHE는 님의 환경에 맞는 절대경로를 입력하면 된다.

이제 패치가 완료되면, APM설치과정과 같이

apache> ./configure --prefix=/usr/local/apache
apache> cd ../php-4.0.24
php> ...설치과정진행
php> cd ../apache
apache> 설치과정진행 ./configure....-> make -> make install

이렇게 하여 설치를 완료한다.

apache 재구동한다.

설치완료
- 이제부터 /var/log/messages 에 로그가 생성된다.
- /var/run/lingerd/에는 프로쎄서가 동작한다.
- /usr/local/apache/logs/error_log에는 문제발생시, 에러로그가 기록된다.

이렇게함으로써 아파치에 대한 안전한 운영이 가능해진다.

FreeBSD] ab (아파치 응답속도를 측정하는 툴)


ab
ab는 “Apache HTTP server Benchmarking tool”의 약어로서  아파치서버의 응답속도를 측정하는 밴치마킹툴입니다.
ab라는 툴을 이용하여 아파치의 응답속도를 테스트하고 그 결과를 다양한 방면으로 확인할 수 있습니다.  

사용형식
ab [ -k ] [ -i ] [ -n 요청수 ] [ -t 시간제한 ] [ -c 동시접속 ] [ -p POST file ] [ -A 인증 유저이름:패스워드 ] [ -P 프락시인증 유저이름:패스워드 ] [ -H Custom header ] [ -C Cookie name=value ] [ -T content-type ] [ -v verbosity ] ] [ -w HTML 출력 ] ] [ -x 속성 ] ] [ -y  속성 ] ] [ -z  속성 ] [http://]서버이름[:port]/path 

ab [ -V ] [ -h ]

사용예 #1
V를 사용하시면 설치되어 있는 ab의 버전을 확인하실 수있습니다. 아래 결과는 현재 필자가 사용하고 있는 ab의 버전이 2.0.40이라는 것을 표시하고 있습니다. 
[root@host3 bin]# ab -VThis is ApacheBench, Version 2.0.40-dev <$Revision: 1.116 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
[root@host3 bin]#
사 용예 #2
수퍼유저코리아(www.superuser.co.kr)의 응답속도를 측정한 것입니다. 참고로 사이트URL의 마지막에는 반드시 "/"가 들어가야함에 주의하시기 바랍니다.  여기서 사용한 옵션 -n은 측정을 위한 웹페이지 요청수를 의미합니다. 즉 "-n 1"이라고 한 것은 지정한 URL을 한번의 요청만으로 결과를 표시한다는 의미입니다.
[root@host3 bin]# ab -n 1 http://www.superuser.co.kr/
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.116 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
Benchmarking www.superuser.co.kr (be patient).....done

Server Software:        Apache/2.0
Server Hostname:        www.superuser.co.kr
Server Port:            80
Document Path:          /
Document Length:        458 bytes
Concurrency Level:      1
Time taken for tests:   1.499567 seconds
Complete requests:      1
Failed requests:        0
Write errors:           0
Total transferred:      700 bytes
HTML transferred:       458 bytes
Requests per second:    0.67 [#/sec] (mean)
Time per request:       1499.567 [ms] (mean)
Time per request:       1499.567 [ms] (mean, across all concurrent requests)
Transfer rate:          0.00 [Kbytes/sec] received
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       17   17   0.0     17      17
Processing:  1482 1482   0.0   1482    1482
Waiting:     1481 1481   0.0   1481    1481
Total:       1499 1499   0.0   1499    1499
[root@host3 bin]#
사 용예 #3
다음과 같이 -c옵션을 사용하면 한번에 수행할 다중 요구수를 지정할 수 있습니다.  지정하지 않는다면 기본값은 1이 됩니다.  테스트시에 c 30이라고 주었으며, 결과를 보시면 concurrency Level30이라는 것을 보실 수 있을 것입니다. 즉, 동시에 다중세션을 테스트한 것이며 그 결과를 확인 할 수 있습니다. 결과값의 분석은 앞에 설명된 내용과 비교하면서 보시기 바랍니다.
[root@host3 bin]# ab -c 30 http://www.yahoo.com/
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.116 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
Benchmarking www.yahoo.com (be patient).....done

Server Software:       
Server Hostname:        www.yahoo.com
Server Port:            80
Document Path:          /
Document Length:        32247 bytes
Concurrency Level:      30
Time taken for tests:   1.75287 seconds
Complete requests:      1
Failed requests:        0
Write errors:           0
Total transferred:      32600 bytes
HTML transferred:       32247 bytes
Requests per second:    0.93 [#/sec] (mean)
Time per request:       32258.610 [ms] (mean)
Time per request:       1075.287 [ms] (mean, across all concurrent requests)
Transfer rate:          28.83 [Kbytes/sec] received
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:      208  208   0.0    208     208
Processing:   866  866   0.0    866     866
Waiting:      219  219   0.0    219     219
Total:       1074 1074   0.0   1074    1074
root@host3 bin]#

저작권:수퍼유저코리아(www.superuser.co.kr), 무단 재배포및 복사를 금합니다.

2012-09-10

FreeBSD]apache2+php5 설치



(2005년 01월 13일 오후 03:00)

아파치2와 php5 포트에서 설치하기.

** make show-options

   |--> 위의 명령으로 해당 포트를 make하기전 사용가능한 옵션을 볼 수 있다고  하네요..



먼저 mysql server를 설치합니다.

# cd /usr/ports/www/apache2
# make install clean

***********************************************

/usr/local/etc/rc.d/apache2.sh 에 시동파일이 복사됩니다.


아파치를 데몬으로 기동하기 위해서는 /etc/rc.conf 에 apache2_enable="YES"를 추가한다.

***********************************************

# cd /usr/ports/www/mod_php5
====> # cd /usr/ports/lang/php5-extension


테 스트중 php5 가 불안한 경우가 있다.

그럴경우

    # cd /usr/ports/lang/php4-extension

에서 작업을 하면된다. 쉽게 말해 php4를 깔면 된다는 얘기 ^^

    # make install clean

(컴파일하고 인스톨하면서 /usr/ports/lang/php5-extension 에서 빌드를 하니깐 옵션선택 메뉴가 나오네요... ^^ (1주일간 헤매다가 찾았네요... ㅠ__ㅠ)

옵션설정 이 메뉴가 나오네요...
필요한 옵션을 설정합니다.

세션과 mbstring pcre_regex는 기본

** make install clean 시에 에러 발생하고 설치가 중단이 되면

make deinstall 을 하면 설치가 지워진다. 그후 다시 make install 을 해도 옵션 선택창이 보이지 않는데 이럴 경우 make config install 이라고 하면 옵션 선택 창이 나오고 설치 작업이 계속 이어지게 된다.

)



# vi /usr/local/etc/apache2/httpd.conf

*********************************************

확인사항

LoadModule php5_module        libexec/apache2/libphp5.so


추가사항

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

DirectoryIndex index.php index.html index.html.var

AddDefaultCharset ISO-8859-1 =>  AddDefaultCharset ISO-2002-KR

*********************************************



# mv /usr/local/etc/php.ini-recommended /usr/local/etc/php.ini
# vi /usr/local/etc/php.ini

*********************************************

register_globals = Off => On
file_upload = On

session.auto_start = 0 => 1 로 변경

*********************************************

2012-09-09

FreeBSD]apache 잔잔한 팁들 모음

출처: Unix.co.kr

브라우징 제거

아파치의 디폴트세팅은 브라우징이 enable되어 있다.
브라우징이란 웹브라우저에서 URL입력시 index.html과 같은 정확한 파일명을
생략하고 디렉토리만 적었을 경우, 디렉토리내 파일목록이 출력되는 현상을 말한다.
http.conf의 디렉토리 디렉티브내 다음줄 추가

Options -Indexes


아파치 인증창 사용

http.conf에서 인증을 걸 디렉토리 디렉티브내 다음줄 추가

AllowOverride AuthConfig


해당 디렉토리에 다음과 같이 .htaccess파일(텍스트파일) 생성
[root@ns mrtg]# cat .htaccess
AuthName "MRTG를 위한 인증"
AuthType Basic
AuthUserFile /webhosting/mrtg/.auth
require valid-user

AuthName: 인증창 타이틀
AuthType: 인증형태
AuthUserFile: 인증자들의 리스트를 가진 파일(htpasswd명령어로 생성)

-c(create)는 처음 파일을 생성할때 필요하다.
[root@ns mrtg]# htpasswd -c .auth kang
New password:
Re-type new password:
Adding password for user kang
[root@ns mrtg]# ls -l .auth
-rw-r--r-- 1 root root 19 May 3 16:54 .auth


외부 IP접근제어

http.conf의 디렉토리 디렉티브내 다음줄 추가

AllowOverride AuthConfig
Order Allow,Deny
Deny from 211.43.134.128/24 xxx.xxx.xxx.xxx/24
Allow from all

Deny from 에 접근차단할 ip대를 입력.
슬 래쉬(/)뒤의 숫자들은 net mask지정(생략하면 single ip에 대한 차단)


위의 내용을 종합한 예는 다음과 같다.


Options -Indexes FollowSymLinks MultiViews

AllowOverride AuthConfig

Order allow,deny
Allow from all
Deny from 211.43.134.128/24 xxx.xxx.xxx.xxx/24




가상호스트 /Redirect

아래의 예는 dbakorea.pe.kr로 오면, www.dbakorea.pe.kr로 redirect시킨다.
본인은 아파치말고, packet filtering으로 처리하려했으나 실력부족과 게으름으로 인해 그만두었다.

ServerName dbakorea.pe.kr
Redirect / http://www.dbakorea.pe.kr


가상호스트의 전형적인예

ServerAdmin kang@dbakorea.pe.kr
DocumentRoot /webhosting/dbakorea-mobile
ServerName mobile.dbakorea.pe.kr
ErrorLog /usr/local/apache/logs/mobile.dbakorea.pe.kr-error_log
CustomLog /usr/local/apache/logs/mobile.dbakorea.pe.kr-access_log common
ScriptAlias /cgi-bin/ /webhosting/dbakorea-mobile/cgi-bin/
DirectoryIndex login.html


아파치 정보출력제어
80포트로 telnet후 get / http/1.0하면 나오는 정보제어

ServerTokens Prod[uctOnly]
: Apache 만 보여줌
ServerTokens Min[imal]
: Apache 버젼만 보여줌
ServerTokens OS
: 아파치 버젼과 운영체제를 보여줌
ServerTokens Full (또는 지시하지 않았을때)
: 모두 보여줌


Offline Browser서비스 거부
(출처: http://www.apache.kr.net)
WebZip만 테스트해봤지만 %{User-agent} 라는 변수에 'MSIE 6.0b'와 같이 찍힌다.
한마디로 안된다. 다른 용도로 사용될 지 몰라도,..

<Directory />
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
Deny from env=go_out
</Directory>

#CustomLog /usr/local/apache/logs/access_log common
#CustomLog /usr/local/apache/logs/referer_log referer
#CustomLog /usr/local/apache/logs/agent_log agent
CustomLog /usr/local/apache/logs/access_log combined

<IfModule mod_setenvif.c>
BrowserMatch "Mozilla/2" nokeepalive
BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
BrowserMatch "RealPlayer 4\.0" force-response-1.0
BrowserMatch "Java/1\.0" force-response-1.0
BrowserMatch "JDK/1\.0" force-response-1.0
BrowserMatch "WebZIP" go_out
BrowserMatch "Teleport" go_out
BrowserMatch "GetRight" go_out
BrowserMatch "WebCopier" go_out
</IfModule>

<VirtualHost *>
ServerAdmin kang@dbakorea.pe.kr
DocumentRoot /webhosting/dbakorea
ServerName www.dbakorea.pe.kr
ServerAlias dbakorea.pe.kr
ErrorLog /usr/local/apache/logs/www.dbakorea.pe.kr-error_log
CustomLog /usr/local/apache/logs/www.dbakorea.pe.kr-access_log combined
</VirtualHost>



아파치 로그 rotate

디폴트로 아파치로그는 wtmp, lastlog등과 같이 일정 시간, 크기..등등에 따라 로그의 순환이 이루어지지 않는다.
logrotate로 3개의 로그를 1달단위로 순환하려면 /etc/logrotate.conf파일의 마지막에 다음과 같이 추가한다.

# system-specific logs may be configured here
/usr/local/apache/log/www.dbakorea.pe.kr-access_log {
monthly
rotate 2
}


바이러스등에 대한 아파치로그 제거

# CodeRed Worm등의 로그제거
SetEnvIf Request_URI default\.ida CodeRed
SetEnvIf Referer \.ida CodeRed
SetEnvIf Request_URI cmd\.exe CodeRed
SetEnvIf Referer cmd\.exe CodeRed
SetEnvIf Request_URI root\.exe CodeRed
SetEnvIf Referer root\.exe CodeRed


ServerAdmin kang@dbakorea.pe.kr
DocumentRoot /webhosting/dbakorea
ServerName www.dbakorea.pe.kr
ServerAlias dbakorea.pe.kr
ErrorLog /usr/local/apache/logs/www.dbakorea.pe.kr-error_log
CustomLog /usr/local/apache/logs/www.dbakorea.pe.kr-access_log combined env=!CodeRed