페이지

2014년 2월 26일 수요일

[linux]apache install with APR and setting

1. apache 표준 환경설정


WEB HOME/svc/spi/web/
APACHE HOME${WAS HOME}/apache


2. 디렉토리 생성 및 압축 풀기

디렉토리 생성
[root@tpdb /]# mkdir -p /svc/spi/web
압축파일 카피
[root@tpdb spidb]# pwd
/home/spi
[root@tpdb spidb]# cp ./httpd-2.4.6.tar.gz /svc/spi/web           
[root@tpdb spidb]# cd /svc/spi/web
압축파일 해제
[root@tpdb web]# tar zxvf httpd-2.4.6.tar.gz 


3. 설치 환경설정
Apache mpm 방식으로 설치를 하며 설치파일의 httpd-2.2.22/server/mpm/worker 에서 worker.c 85 line #define DEFAULT_SERVER_LIMIT 16 -> 128로 변경후 install 진행

[root@tpdb worker]# pwd
/svc/spi/web/httpd-2.4.6/server/mpm/worker
[root@tpdb worker]# ll
합계 136
-rw-r--r--. 1 tempuser games    40 2009-11-03 23:36 Makefile.in
-rw-r--r--. 1 tempuser games   457 2009-04-23 14:17 config.m4
-rw-r--r--. 1 tempuser games   180 2011-11-30 19:21 config3.m4
-rw-r--r--. 1 tempuser games 13133 2011-01-28 04:34 fdqueue.c
-rw-r--r--. 1 tempuser games  2543 2011-01-28 04:34 fdqueue.h
-rw-r--r--. 1 tempuser games  1634 2012-01-31 21:02 mpm_default.h
-rw-r--r--. 1 tempuser games  3031 2011-12-05 09:08 pod.c
-rw-r--r--. 1 tempuser games  1810 2009-03-25 00:43 pod.h
-rw-r--r--. 1 tempuser games 90502 2013-05-12 19:38 worker.c
[root@tpdb worker]# vi worker.c 
84 #ifndef DEFAULT_SERVER_LIMIT
85 #define DEFAULT_SERVER_LIMIT 16 <--수정할 것*(32,64,128 등)
86 #endif

그다음 configure실행, 그러나 실행하면 다음 APR에러가 발생할 것이다
먼저 

-apache configure
[root@tpdb httpd-2.4.6]# ./configure --prefix=/svc/spi/web/apache  --enable-so --enable-ssl --with-mpm=worker
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... no
configure: error: APR not found.  Please read the documentation.


- APR install
다음 명령어를 실행하여 apr 다운로드 실행
(혹시 파일이 없으면 버전이 없는 것이니 http://apr.apache.org/download.cgi 서 확인하고 파일명만 바꾸어주면 됨
다운로드 및 컴파일
[root@tpdb web]# wget http://mirror.apache-kr.org/apr/apr-1.5.0.tar.gz
[root@tpdb web]# tar zxvf apr-1.5.0.tar.gz
[root@tpdb web]# cd apr-1.5.0
[root@tpdb apr-1.5.0]# ./configure 

여기서 gcc에러가 나면 별도 설치해야 함 
설치해야 할게 많기 때문에 별도로 다른 페이지에 설명 예정
다음 링크 참조
http://stoplulker.blogspot.com/2014/02/linux-gcc.html

- 그리고 apr-util다운로드 후 컴파일 진행
[root@tpdb web]# wget http://mirror.apache-kr.org/apr/apr-util-1.5.3.tar.gz
[root@tpdb web]# tar zxvf apr-util-1.5.3.tar.gz
[root@tpdb spidb]# cd apr-util-1.5.3
[root@tpdb apr-util-1.5.3]# ./configure --with-apr=/usr/local/apr
[root@tpdb apr-util-1.5.3]# make; make install

- pcre 설치
다 진행되면 다시 apache configure시작
그러나 다시 할려면  pcre에러가 날 수도 있다
이럴경우 다음 설치
[root@SPIWEB spiweb]# rpm -ivh pcre-devel-7.8-6.el6.x86_64.rpm 

--ssl 에러
이젠 다시 ssl에러가 날 수도 있을 것이다
일단 시간이 없으니 담에 하기로 하고 일단 옵션에 ssl을 생략한다
./configure --prefix=/svc/spi/web/apache  --enable-so  --with-mpm=worker

마지막으로 make;make install을 해준다


이제 ${APACHE_MOE}/bin/apachectl start를 하여 아파치를 실행시킨다
아마 실행시키면 다음과 같이 에러가 날텐데 이것은 httpd.conf파일을 열어 다음 ServerName을 localhost로 바꿔준다

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message

#ServerName www.example.com:80

ServerName localhost





4. mpm 설정 수정
 - conf/httpd.conf 파일에 httpd-mpm.conf, httpd-default.conf 주석해제 및 설정 변경
[root@uplus conf]# vi httpd.conf
Include conf/extra/httpd-mpm.conf
Include conf/extra/httpd-default.conf



[root@uplus conf]#vi extra/httpd-mpm.conf
# worker MPM
# StartServers: initial number of server processes to start
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestWorkers: maximum number of worker threads
# MaxConnectionsPerChild: maximum number of connections a server process serves
#                         before terminating
<IfModule mpm_worker_module>
    StartServers            10
    MinSpareThreads         75
    MaxSpareThreads        250
    ThreadsPerChild         25
    MaxRequestWorkers      400
    MaxConnectionsPerChild   0
</IfModule>


5. root디렉토리 잡기
 httpd.conf파일을 열어서 documentRoot를 바꿔준다
필요시  useradd명령어를 사용하여 user를 만들어 준다

[root@SPIWEB conf]# pwd
/svc/spi/web/apache/conf
[root@SPIWEB conf]# ll
ÇÕ°è 96
drwxr-xr-x. 2 root root  4096 2014-02-27 15:26 extra
-rw-r--r--. 1 root root 18093 2014-02-27 15:33 httpd.conf
-rw-r--r--. 1 root root 13077 2014-02-27 15:26 magic
-rw-r--r--. 1 root root 53011 2014-02-27 15:26 mime.types
drwxr-xr-x. 3 root root  4096 2014-02-27 15:26 original
[root@SPIWEB conf]# vi httpd.conf 
DocumentRoot "/home/spiweb/documentRoot"
<Directory "/home/spiweb/documentRoot">

이제 index.html파일을 root에 만들어 테스트 하면 되는데 가끔 403 에러가 날 때가 있다
이럴땐 다음을 실행
sudo chown -R $USER:$USER /var/www/folder-name 
sudo chmod -R 755 /var/www



6. log 설정에 cookie추가

<IfModule log_config_module>
    #
    # The following directives define some format nicknames for use with
    # a CustomLog directive (see below).
    #
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{Cookie}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common


6. log경로 바꿔주기
Apache log의 기본 디렉토리는 ${apache설치디렉토리}/logs 이며  /log/${서비스명}/web/logs에 심볼릭 링크가 되어야함
[root@ bin]# mkdir -p /logs/spi/web/logs
[root@ bin]# cd /logs/spi/web/logs
[root@ logs]# mkdir {access-log,error-log}
[root@ logs]# ls
access-log  error-log
[root@ logs]#

[root@ apache]# rm –rf logs
[root@ apache]# ln -s /logs/spi/web/logs logs
[root@ apache]# ll
total 52
drwxr-xr-x  2 root root  4096 Jun  5 10:25 bin
drwxr-xr-x  2 root root  4096 Jun  5 10:25 build
drwxr-xr-x  2 root root  4096 Jun  5 10:25 cgi-bin
drwxr-xr-x  4 root root  4096 Jun  5 10:30 conf
drwxr-xr-x  3 root root  4096 Jun  5 10:25 error
drwxr-xr-x  2 root root  4096 Jan 26 07:24 htdocs
drwxr-xr-x  3 root root  4096 Jun  5 10:25 icons
drwxr-xr-x  2 root root  4096 Jun  5 10:25 include
lrwxrwxrwx  1 root root    19 Jun  5 10:54 logs -> /log/spi/web/logs
drwxr-xr-x  4 root root  4096 Jun  5 10:25 man
drwxr-xr-x 14 root root 12288 Jan 26 07:26 manual
drwxr-xr-x  2 root root  4096 Jun  5 10:25 modules

[root@uplus apache]# vi conf/httpd.conf
#ErrorLog "logs/error_log"
ErrorLog "|/svc/spi/web/apache/bin/rotatelogs -l /svc/spi/web/apache/logs/error-log/error.%Y%m%d 86400"

#CustomLog "logs/access_log" common
CustomLog "|/svc/spi/web/apache/bin/rotatelogs -l /svc/spi/web/apache/logs/access-log/access.%Y%m%d 86400" combined



7. apache sudo 설정
apache권한이 root일경우 서비스 계정(test)으로 실행하기 위해 sudo 설정을 한다.
아래설정은 서비스계정이 apachectl cat, tail, rm, mv 을 서비스계정으로 실행할 수 있게 해주는 설정이다
[root@ apache]# vi /etc/sudoers 
root    ALL=(ALL)       ALL
test      ALL=/svc/spi/web/apache/bin/apachectl 
test      ALL=/bin/cat /log/spi/web/*
test      ALL=/usr/bin/tail /log/spi/web/*
test      ALL=/bin/rm /log/spi/web/*
test      ALL=/bin/mv /log/spi/web/*


8. 디렉토리 옵션 설정
기존의 웹 문서외에 다른 파일 시스템에 접근 가능하기 때문에 수정

<Directory>지시자의 Options Option None으로 변경(2군데)
#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other 
# <Directory> blocks below.
#
<Directory />
    AllowOverride none
    Require all denied

</Directory>


<Directory "/home/spiweb/documentRoot">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
AllowOverride FileInfo AuthConfig Limit
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
<Limit OPTIONS PROPFIND>
        Order allow,deny                                                                                          
        Allow from all                                                                                            
</Limit>
    <LimitExcept GET POST>
        Order deny,allow                                                                                          
        Deny from all                                                                                             
    </LimitExcept>


    #                                                                                                             
    # Controls who can get stuff from this server.                                                                
    #                                                                                                             
    Require all granted

</Directory>



9. 디렉토리 권한 변경
[root@spiwba1 apache]# chmod -R 740 conf
[root@spiwba1 conf]# chmod -R 600 *.conf



댓글 없음:

댓글 쓰기

image

image