Apache Web Server

Install httpd 2.4.46 on CentOS 7.9 (Apache Web Server)

L’Etranger 2021. 4. 18. 22:06

Apache 설치를 위한 구성요소 파악

# 설치파일 버전정보

   - httpd(apache web server): httpd-2.4.46

   - ajp_connector: tomcat-connectors-1.2.48-src

   - pcre: pcre-8.44

   - apr: apr-1.7.0

   - aprutil: apr-util-1.6.1

   

  ※ 2021.04.18 현재 각 최신버전

 

# prce(Perl Compatible Regular Expressions)

   - 홈페이지: https://www.pcre.org 

   - PCRE 라이브러리 (Perl 호환 정규 표현식, 정규식 패턴 일치를 구련하는 함수 집합)

     . PCRE 라이브러리는 독점 소프트웨어를 구축하는 경우에도 무료

     . Apache, PHP, KDE, Postfix 및 Nmap등  유명 오픈소스 프로젝트에서 사용 (apple safari 등 상용소프트웨어도 사용)

   - 다운로드 사이트

     ftp://ftp.pcre.org/pub/pcre/

     https://ftp.pcre.org/pub/pcre/

     https://sourceforge.net/projects/pcre/files/

 

# APR(Apache Portable Runtime)

   - 홈페이지: apr.apache.org

   - Apache HTTP 서버 2.x 버전 휴대용 라이브러리

   - IO(예: sendfile, epoll, openssl등) 접근 포함 OS 수준 기능(난수 생성, 시스템 상태) 제공

   - 기본 프로세스 처리(공유 메모리, 파이프, 유닉스 소켓) 등 용도로 사용

   - 다운로드 사이트

     https://downloads.apache.org/apr/apr-1.7.0.tar.gz

     https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz

 

# AJP Connector (Apache JServ Protocol Connector)

   - 웹서버로 인입된 요청(request) 를 WAS로 전달해주는 프로토콜

   - Apache, Tomcat, Weblogic, Jeus, WebtoB 등에서 지원됨.

   - 다운로드 사이트

      https://tomcat.apache.org/download-connectors.cgi 

 

HTTPD 2.4.46 설치

# 디렉토리 생성

$ su -

$ mkdir /apache
$ umask 0077
$ mkdir /apache /ap_log /apache/src
$ mkdir -p /ap_log/jk /shm
$ mkdir -p /ap_log/ssl
$ mkdir /apache/apache24/ssl_private
$ mkdir /apache/apache24/ssl_public

# 설치파일 다운로드

$ su - 

$ cd /apache/src

$ wget  https://downloads.apache.org/httpd/httpd-2.4.46.tar.gz

$ wget  https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz

$ wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz

$ wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz

$ wget https://downloads.apache.org/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.48-src.tar.gz

$ ls -la 

drwxr-xr-x. 2 root root    4096  4 18 18:58 .

drwxr-xr-x. 3 root root    4096  4 18 18:57 ..

-rw-r--r--. 1 root root 1093896  7  7  2020 apr-1.7.0.tar.gz

-rw-r--r--. 1 root root  554301  7  7  2020 apr-util-1.6.1.tar.gz

-rw-r--r--. 1 root root 9363314  8  5  2020 httpd-2.4.46.tar.gz

-rw-r--r--. 1 root root 2090750  2 13  2020 pcre-8.44.tar.gz

-rw-r--r--.  1 root   root   3665280  7  3  2020 tomcat-connectors-1.2.48-src.tar.gz

# apache 계정 생성 (with no login - running httpd daemon only)

$ su -

$ useradd -s /sbin/nologin apache

 

# 설치 도구 구성

대상: openssl-level, gcc, gcc-c++, perl, expat-devel

확인: yum list installed | grep openssl-level(예시)

$ yum install openssl-devel gcc gcc-c++ perl expat-devel -y

# 설치파일 압축해제

$ cd /apache/src/

$ tar -zxvf apr-1.7.0.tar.gz

$ tar -zxvf apr-util-1.6.1.tar.gz

 

$ cp -rp /apache/src/apr-1.7.0 /apache/src/httpd-2.4.46/srclib/apr

$ cp -rp /apache/src/apr-util-1.6.1 /apache/src/httpd-2.4.46/srclib/apr-util

 

$ tar -zxvf httpd-2.4.46.tar.gz

$ tar -zxvf pcre-8.44.tar.gz

$ mkdir orig ; mv *.tar.gz orig/

# pcre-8.44

$ cd /apache/src/pcre-8.44

$ ./configure --prefix=/apache/src/httpd-2.4.46/srclib/pcre

$ make

$ make install

$ make clean

$ ls /apache/src/httpd-2.4.46/srclib | grep prce

# httpd 2.4.46

$ cd /apache/src/httpd-2.4.46

$ ./configure -C --prefix=/apache/apache24 --with-included-apr --with-included-apr-util  --with-pcre=/apache/src/httpd-2.4.46/srclib/pcre --enable-mpms-shared=all

    configure: summary of build options:

 

    Server Version: 2.4.46

    Install prefix: /apache/apache24

    C compiler:     gcc -std=gnu99

    CFLAGS:          -g -O2 -pthread

    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE

    LDFLAGS:

    LIBS:

    C preprocessor: gcc -E

 

$ make

make[4]: Leaving directory `/apache/src/httpd-2.4.46/modules/mappers'

make[3]: Leaving directory `/apache/src/httpd-2.4.46/modules/mappers'

make[2]: Leaving directory `/apache/src/httpd-2.4.46/modules'

make[2]: Entering directory `/apache/src/httpd-2.4.46/support'

make[2]: Leaving directory `/apache/src/httpd-2.4.46/support'

make[1]: Leaving directory `/apache/src/httpd-2.4.46'

 

$ make install

$ make clean

# ajp-connector 1.2.48

$ cd /apache/src/tomcat-connectors-1.2.48-src/native

$ ./configure --with-apxs=/apache/apache24/bin/apxs

 

make[1]: Leaving directory `/apache/src/tomcat-connectors-1.2.48-src/native/apache-2.0'

make[1]: Entering directory `/apache/src/tomcat-connectors-1.2.48-src/native'

make[1]: `all-am' 위해  일이 없습니다

make[1]: Leaving directory `/apache/src/tomcat-connectors-1.2.48-src/native'

target="all"; \

list='common apache-2.0'; \

for i in $list; do \

    echo "Making $target in $i"; \

    if test "$i" != "."; then \

       (cd $i && make $target) || exit 1; \

    fi; \

done;

Making all in common

make[1]: Entering directory `/apache/src/tomcat-connectors-1.2.48-src/native/common'

make[1]: `all' 위해  일이 없습니다

make[1]: Leaving directory `/apache/src/tomcat-connectors-1.2.48-src/native/common'

Making all in apache-2.0

make[1]: Entering directory `/apache/src/tomcat-connectors-1.2.48-src/native/apache-2.0'

../scripts/build/instdso.sh SH_LIBTOOL='/apache/apache24/build/libtool --silent' mod_jk.la `pwd`

/apache/apache24/build/libtool --silent --mode=install cp mod_jk.la /apache/src/tomcat-connectors-1.2.48-src/native/apache-2.0/

libtool: warning: remember to run 'libtool --finish /apache/apache24/modules'

make[1]: Leaving directory `/apache/src/tomcat-connectors-1.2.48-src/native/apache-2.0'

 

$ make

$ make install

 

make[1]: Leaving directory `/apache/src/tomcat-connectors-1.2.48-src/native/apache-2.0'

make[1]: Entering directory `/apache/src/tomcat-connectors-1.2.48-src/native'

make[2]: Entering directory `/apache/src/tomcat-connectors-1.2.48-src/native'

make[2]: `install-exec-am' 위해  일이 없습니다

make[2]: `install-data-am' 위해  일이 없습니다

make[2]: Leaving directory `/apache/src/tomcat-connectors-1.2.48-src/native'

make[1]: Leaving directory `/apache/src/tomcat-connectors-1.2.48-src/native

 

$ make clean

# apache 설치 디렉토리 확인

$ ls -la /apache/apache24

합계 68

drwxr-xr-x. 15 root root  4096  4월 18 20:07 .

drwxr-xr-x.  4 root root  4096  4월 18 20:07 ..

drwxr-xr-x.  2 root root  4096  4월 18 20:07 bin

drwxr-xr-x.  2 root root  4096  4월 18 20:07 build

drwxr-xr-x.  2 root root  4096  4월 18 20:07 cgi-bin

drwxr-xr-x.  4 root root  4096  4월 18 20:07 conf

drwxr-xr-x.  3 root root  4096  4월 18 20:07 error

drwxr-xr-x.  2 root root  4096  4월 18 20:07 htdocs

drwxr-xr-x.  3 root root  4096  4월 18 20:07 icons

drwxr-xr-x.  2 root root  4096  4월 18 20:07 include

drwxr-xr-x.  3 root root  4096  4월 18 20:07 lib

drwxr-xr-x.  2 root root  4096  4월 18 20:07 logs

drwxr-xr-x.  4 root root  4096  4월 18 20:07 man

drwxr-xr-x. 14 root root 12288  4월 18 20:07 manual

drwxr-xr-x.  2 root root  4096  4월 18 20:20 modules

# docs 변경, 미사용 설정 삭제

$ mv /apache/apache24/htdocs /apache/apache24/www
$ rm -r /apache/apache24/manual
$ rm -r /apache/apache24/cgi-bin

 

주요 설정파일 적용

# 설정파일 백업

$ su - 

$ cp /apache/apache24/conf/httpd.conf /apache/apache24/conf/httpd.conf.orig

$ cp /apache/apache24/conf/extra/httpd-ssl.conf  /apache/apache24/conf/extra/httpd-ssl.conf.orig

$ cp /apache/apache24/conf/extra/httpd-vhosts.conf  /apache/apache24/conf/extra/httpd-vhosts.conf.orig

$ cp /apache/apache24/conf/extra/httpd-mpm.conf  /apache/apache24/conf/extra/httpd-mpm.conf.orig

- 다음과 같이 변경

$ vi /apache/apache24/conf/httpd.conf

LoadModule rewrite_module modules/mod_rewrite.so   # 주석 해제

User apache   # daemon -> apache

Group apache  # dae,om -> apache

ServerName localhost

ServerName www.example.com:80  # 주석 해제

 

DocumentRoot "/apache/apache24/www”  # htdocs -> www

<Directory "/apache/apache24/www”>       # htdocs -> www

    #Options Indexes FollowSymLinks         # 주석처리

    AllowOverride AuthConfig # None -> AuthConfig

 

<IfModule dir_module>

    DirectoryIndex index.html index.jsp index.do

</IfModule>

 

ErrorLog "|/apache/apache24/bin/rotatelogs /ap_log/error.%Y%m%d.log 86400 +540"

 

<IfModule log_config_module>

    #CustomLog "logs/access_log" common

    SetEnvIf Request_URI "favicon.ico" do_not_log

    CustomLog "|/apache/apache24/bin/rotatelogs /ap_log/access.%Y%m%d.log 86400 +540" combined env=!do_not_log

 

<IfModule alias_module>

    #ScriptAlias /cgi-bin/ "/apache/apache24/cgi-bin/"

</IfModule>

 

#<Directory "/apache/apache24/cgi-bin">

#    AllowOverride None

#    Options None

#    Require all granted

#</Directory>

 

ErrorDocument 400 /error/error_page.html

ErrorDocument 401 /error/error_page.html

ErrorDocument 403 /error/error_page.html

ErrorDocument 500 /error/error_page.html

 

Include conf/extra/httpd-mpm.conf

Include conf/extra/httpd-vhosts.conf

 

<IfModule proxy_html_module>

#Include conf/extra/proxy-html.conf

</IfModule>

 

Redirect 404 /favicon.ico

 

<Location /favicon.ico>

   ErrorDocument 404 "No favicon"

</Location>

 

TraceEnable Off

LimitRequestBody 5000000

Include conf/mod_jk.conf

ServerTokens Prod

 

# httpd-mpm.conf

$ vi /apache/apache24/conf/extra/httpd-mpm.conf
<IfModule !mpm_netware_module>

    PidFile "logs/httpd.pid"

</IfModule>

 

<IfModule mpm_prefork_module>

    StartServers            16

    ServerLimit           2048

    MinSpareServers         32

    MaxSpareServers       1024

    MaxRequestWorkers     2048

    MaxConnectionsPerChild   0

</IfModule>

 

<IfModule mpm_worker_module>

    StartServers             4

    ServerLimit             32

    MinSpareThreads        256

    MaxSpareThreads       1024

    ThreadsPerChild         64

    MaxRequestWorkers     2048

    MaxConnectionsPerChild   0

</IfModule>

 

<IfModule mpm_event_module>

    StartServers             4

    ServerLimit             32

    MinSpareThreads        256

    MaxSpareThreads       1024

    ThreadsPerChild         64

    MaxRequestWorkers     2048

    MaxConnectionsPerChild   0

</IfModule>

 

<IfModule mpm_netware_module>

    ThreadStackSize      65536

    StartThreads           250

    MinSpareThreads         25

    MaxSpareThreads        250

    MaxThreads            1000

    MaxConnectionsPerChild   0

</IfModule>

 

<IfModule mpm_mpmt_os2_module>

    StartServers             2

    MinSpareThreads          5

    MaxSpareThreads         10

    MaxConnectionsPerChild   0

</IfModule>

 

<IfModule mpm_winnt_module>

    ThreadsPerChild        150

    MaxConnectionsPerChild   0

</IfModule>

 

<IfModule !mpm_netware_module>

    MaxMemFree            2048

</IfModule>

<IfModule mpm_netware_module>

    MaxMemFree             100

</IfModule>

 

# httpd-ssl.conf

$ vi /apache/apache24/conf/extra/httpd-ssl.conf
# Virtual Hosts

#

# Required modules: mod_log_config

 

# If you want to maintain multiple domains/hostnames on your

# machine you can setup VirtualHost containers for them. Most configurations

# use only name-based virtual hosts so the server doesn't need to worry about

# IP addresses. This is indicated by the asterisks in the directives below.

#

# Please see the documentation at

# <url:http://httpd.apache.org/docs/2.4/vhosts/>

# for further details before you try to setup virtual hosts.

#

# You may use the command line option '-S' to verify your virtual host

# configuration.

 

#

# VirtualHost example:

# Almost any Apache directive may go into a VirtualHost container.

# The first VirtualHost section is used for all requests that do not

# match a ServerName or ServerAlias in any <VirtualHost> block.

#

<VirtualHost *:80>

    ServerAdmin webmaster@dummy-host.example.com

    DocumentRoot "/apache/apache24/www"

    ServerName dummy-host.example.com

    ServerAlias www.dummy-host.example.com

    ErrorLog "|/apache/apache24/bin/rotatelogs /ap_log/error.%Y%m%d.log 86400 +540"

    CustomLog "|/apache/apache24/bin/rotatelogs /ap_log/access.%Y%m%d.log 86400 +540" combined

    #RewriteEngine on

    #RewriteCond %{REQUEST_METHOD} !=GET

    #RewriteCond %{REQUEST_METHOD} !=POST

    #RewriteRule (.*) - [R=405,L]

 

    <Directory "/apache/apache24/www">

        Options -Indexes -FollowSymLinks

        AllowOverride AuthConfig

        Require all granted

       #<LimitExcept GET POST>

       #    Order deny,allow

       #    Deny from all

       #</LimitExcept>

 

    </Directory>

    JkMount /*.jsp wlb

    JkMount /*.do wlb

</VirtualHost>

# mod_jk.conf

$ vi /apache/apache24/conf/mod_jk.conf

 

# mod_jk.conf

LoadModule jk_module modules/mod_jk.so

 

JkShmFile /ap_log/jk/shm/mod_jk.shm

JkLogFile "|/apache/apache24/bin/rotatelogs /ap_log/jk/mod_jk.%Y%m%d.log 86400 +540"

 

JkLogLevel info

JkLogStampFormat "[%Y %a %b %d %H:%M:%S] "

JkRequestLogFormat "%w %R %V %U %s %T"

JkMountFile conf/uriworkermap.properties

JkWorkersFile conf/workers.properties

 

# mod_jk uriworkermap.properties

$ vi /apache/apache24/conf/uriworkermap.properties
/*.jsp=wlb
/*.do=wlb

 

# mod_jk workers.properties

$ vi /apache/apache24/conf/workers.properties
worker.wlb.type=lb
worker.wlb.balance_workers=portal11, portal21
worker.list=wlb

 

# Node Configure

worker.template.type=ajp13

worker.template.socket_timeout=300

worker.template.socket_keepalive=true

worker.template.recovery_options=7

worker.template.ping_mode=A

worker.template.ping_timeout=10000

worker.template.connection_pool_size=500

worker.template.connection_pool_minsize=300

worker.template.connection_pool_timeout=60

 

# Node Configure START

worker.portal11.reference=worker.template

worker.portal11.port=8009

worker.portal11.host=192.168.56.200

worker.portal11.lbfactor=1

 

worker.portal21.reference=worker.template

worker.portal21.port=8009

worker.portal21.host=192.168.56.201

worker.portal21.lbfactor=1

 

# Session Cluster Configure

#worker.wlb.method=Session

#worker.wlb.sticky_session=True

Start, Stop 스크립트 

$ vi /apache/apache24/bin/startweb.sh
#!/bin/sh

/apache/apache24/bin/apachectl start

 

$ vi /apache/apache24/bin/stopweb.sh

 

#!/bin/sh

/apache/apache24/bin/apachectl stop

 

# 권한 변경

$ chown -R apache.apache /ap_log /apache

$ chown root:apache /apache/apache24/bin/httpd

$ chmod 4750 /apache/apache24/bin/httpd

$ chmod 4750 /apache/apache24/bin/rotatelogs

$ chown -R root:root /apache/lost+found /ap_log/lost+found  2>/dev/null

 

# alias 설정

$ su - 

$ vi .bash_profile

alias web=“cd /apache/apache24

alias logd=“cd /ap_log”

alias alog=“tail -100f /ap_log/access.log

alias slog=“tail -100f /ap_log/ssl/request.log

alias jklog=“tail -100f /ap_log/jk/

 

# 구문오류 확인

$ su - 

$ cd /apache/apache24/bin

$ ./httpd -t

 

# 시작

$ su -

$ cd /apache/apache24/bin

$ ./startweb.sh
$ ps -ef | grep httpd 
$ netstat -tnlp | egrep "80|443"

# 중지

$ su -

$ cd /apache/apache24/bin

$ ./stopweb.sh
$ ps -ef | grep httpd
$ netstat -tnlp | egrep "80|443"