반응형

-설치파일 다운로드(https://www.apachelounge.com/download/)

httpd-2.4.43-win64-VS16.zip

 

-압축 해제 후 설치경로로 이동 또는 복사
 > httpd-2.4.43-win64-VS16.zip 압축해제 후 하위의 Apache24 폴더 설치 경로로 복사

-관리자 권한 CMD 접속

-기본 설치
cd D:\Apache24\bin
httpd.exe -k install 

-이름 및 환경파일 지정
httpd.exe -k install -n apache-test -f D:\Apache24\conf\test-httpd.conf

패키지 설지

yum -y install gcc*
yum -y install libtool*
yum -y install expat-devel

1.pcre 설치
cd /FILES/apache
wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
tar -zxvf /FILES/apache/pcre-8.43.tar.gz
cd pcre-8.43
./configure --prefix=/SW/package/pcre-8.43
make && make install

2.apr 설치
cd /FILES/apache
wget http://archive.apache.org/dist/apr/apr-1.6.5.tar.gz
tar -zxvf apr-1.6.5.tar.gz
cd apr-1.6.5
./configure --prefix=/SW/package/apr-1.6.5
make && make install

3.apr-util 설치
cd /FILES/apache
wget http://archive.apache.org/dist/apr/apr-util-1.6.1.tar.gz
tar -zxvf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1
./configure --prefix=/SW/package/apr-util-1.6.1 --with-apr=/SW/package/apr-1.6.5
make && make install

4.openssl 설치
cd /FILES/apache
wget https://www.openssl.org/source/openssl-1.1.1b.tar.gz
tar -zxvf openssl-1.1.1b.tar.gz
cd openssl-1.1.1b
./config--prefix=/SW/package/openssl-1.1.1b
make && make install

5.apache 설치
cd /FILES/apache
wget http://mirror.apache-kr.org/httpd/httpd-2.4.39.tar.gz
tar -zxvf httpd/httpd-2.4.39.tar.gz
cd httpd-2.4.39
----------------------------------------------------------------
# prefork(Process 방식) 설치 #
"./configure" \
"--prefix=/SW/apache/apache-2.4.39" \
"--with-apr=/SW/package/apr-1.6.5" \
"--with-apr-util=/SW/package/apr-util-1.6.1" \
"--with-pcre=/SW/package/pcre-8.43" \
"--with-ssl=/SW/package/openssl-1.1.1b" \
"--with-expat" \
"--enable-ssl" \
"--enable-sockets" \
"--enable-mods-shared=all" \
"--enable-module=so" \
"--enable-shared=max" \
"--enable-rewrite"

# mpm(Thread 방식) 설치 #
"./configure" \
"--prefix=/SW/apache/apache-2.4.39" \
"--with-apr=/SW/package/apr-1.6.5" \
"--with-apr-util=/SW/package/apr-util-1.6.1" \
"--with-pcre=/SW/package/pcre-8.43" \
"--with-ssl=/SW/package/openssl-1.1.1b" \
"--with-expat" \
"--with-mpm=MPM" \ 
"--enable-ssl" \
"--enable-sockets" \
"--enable-mods-shared=all" \
"--enable-module=so" \
"--enable-shared=max" \
"--enable-rewrite"
----------------------------------------------------------------
make && make install

6.tomcat connector 설치
yum -y install perl
cd /FILES/apache
wget http://apache.tt.co.kr/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.46-src.tar.gz
tar -zxvf tomcat-connectors-1.2.46-src.tar.gz
./configure --with-apxs=/SW/apache/apache-2.4.39/bin/apxs
make && make install

wokers..properties에 worker.xxx.fail_on_status=503 설정 추가

각 node에 설정하거나, templete에 설정

workers.properties
#worker.list=jk-status
#worker.jk-status.type=status
#worker.jk-status.read_only=true
 
#worker.list=jk-manager
#worker.jk-manager.type=status
 
worker.list=balancer
worker.balancer.type=lb
worker.balancer.balance_workers=node1,node2
worker.balancer.error_escalation_time=0
worker.balancer.max_reply_timeouts=10
worker.balancer.sticky_session=true
#worker.balancer.method=Session
 
worker.node1.reference=worker.template
worker.node1.host=192.168.0.112
worker.node1.port=9109
worker.node1.route=test_server11
worker.node1.activation=A
worker.node1.fail_on_status=503
 
worker.node2.reference=worker.template
worker.node2.host=192.168.0.112
worker.node2.port=9209
worker.node2.route=test_server12
worker.node2.activation=A
worker.node2.fail_on_status=503
 
worker.template.type=ajp13
worker.template.socket_connect_timeout=5000
worker.template.socket_keepalive=true
worker.template.ping_mode=A
worker.template.ping_timeout=10000
worker.template.connection_pool_minsize=0
worker.template.connection_pool_timeout=600
worker.template.reply_timeout=300000
worker.template.recovery_options=3
#worker.template.fail_on_status=503

 

Wildfly, Jboss 연동 시 세션 중복처리가 가능한 상태로 설정해야 한다.

 

standalone-ha.xml

(변경 전)

standalone-ha.xml
<subsystem xmlns="urn:jboss:domain:infinispan:7.0">
   <cache-container name="web" default-cache="dist" module="org.wildfly.clustering.web.infinispan">
        <transport lock-timeout="60000"/>
        <distributed-cache name="dist">
            <locking isolation="REPEATABLE_READ"/>
            <transaction mode="BATCH"/>
            <file-store/>
        </distributed-cache>
    </cache-container>

 

(변경 후 - locking isolation, transaction mode 태그 삭제)

standalone-ha.xml
<subsystem xmlns="urn:jboss:domain:infinispan:7.0">
    <cache-container name="web" default-cache="dist" module="org.wildfly.clustering.web.infinispan">
        <transport lock-timeout="60000"/>
        <distributed-cache name="dist">
            <file-store/>
        </distributed-cache>
    </cache-container>

 

'IT기술노트 > WEB' 카테고리의 다른 글

Windows Apache 설치  (4) 2024.10.31
Linux Apache 컴파일 설치(CentOS7)  (2) 2024.10.31
Apache/Jbcs 서버 헤더 변경 방법  (3) 2024.10.31
Nginx 설치 테스트(ubuntu20.04)  (2) 2024.10.29
Nginx SSL 인증서 설정 방법  (2) 2024.10.29

Apache 설정

1)httpd.conf 파일 수정
 -mod_security2.so 모듈이 존재해야 한다
 -SecServerSignature의 설정 값 _ 으로 server 헤더가 표시된다

conf/httpd.conf
LoadModule security2_module modules/mod_security2.so
<IfModule security2_module>
  SecRuleEngine on
  ServerTokens Full
  ServerSignature Off
  SecServerSignature "_"
</IfModule>

 

Jbcs 설정

1)conf.modules.d/10-mod_security.conf 파일에 security2_module 설정 확인

conf.modules.d/10-mod_security.conf
LoadModule security2_module modules/mod_security2.so


2)httpd.conf 파일 수정
 -Include conf.modules.d/*.conf 태그 아래에 설정해야 한다.

conf/httpd.conf
Include conf.modules.d/*.conf
...
<IfModule security2_module>
   SecRuleEngine on
   ServerTokens Full
   ServerSignature Off
   SecServerSignature "_"
</IfModule>

 -ServerTokens Prod 설정 시 SecServerSignature 설정에 공백("abc test")이 포함되면 정상적으로 동작하지 않는다 (ServerTokens Prod의 기본 결과값으로 출력됨)

1.yum 설치

# yum -y install haproxy

(낮은 버젼으로 설치됨 haproxy-1.5.18-9.el7_9.1.x86_64)

 

서비스 시작
# systemctl start haproxy

 

기본 프로세스

[root@test /SW/haproxy/haproxy-2.7.1]# ps -ef | grep haproxy
root     29915     1  0 10:16 ?        00:00:00 /usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
haproxy  29919 29915  0 10:16 ?        00:00:00 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
haproxy  29922 29919  0 10:16 ?        00:00:00 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds

 

서비스 종료
# systemctl stop haproxy

 

재부팅 시 자동으로 서비스 시작
# systemctl enable haproxy

 

기본 환경파일(/etc/haproxy/haproxy.cfg)

/etc/haproxy/haproxy.cfg
#---------------------------------------------------------------------
# Example configuration for a possible web application.  See the
# full configuration options online.
#
#
#---------------------------------------------------------------------
 
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
    # to have these messages end up in /var/log/haproxy.log you will
    # need to:
    #
    # 1) configure syslog to accept network log events.  This is done
    #    by adding the '-r' option to the SYSLOGD_OPTIONS in
    #    /etc/sysconfig/syslog
    #
    # 2) configure local2 events to go to the /var/log/haproxy.log
    #   file. A line like the following can be added to
    #   /etc/sysconfig/syslog
    #
    #    local2.*                       /var/log/haproxy.log
    #
    log         127.0.0.1 local2
 
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon
 
    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats
 
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000
 
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend  main *:5000
    acl url_static       path_beg       -i /static /images /javascript /stylesheets
    acl url_static       path_end       -i .jpg .gif .png .css .js
 
    use_backend static          if url_static
    default_backend             app
 
#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
    balance     roundrobin
    server      static 127.0.0.1:4331 check
 
#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
    balance     roundrobin
    server  app1 127.0.0.1:5001 check
    server  app2 127.0.0.1:5002 check
    server  app3 127.0.0.1:5003 check
    server  app4 127.0.0.1:5004 check

 

2.컴파일 설치

1)패키지 설치
 -기본: sudo yum -y install gcc pcre-devel tar make
 -추가 옵션 적용: sudo yum -y gcc openssl openssl-devel pcre-static pcre-devel systemd-devel

2)다운로드 및 묶음 해제
다운로드 페이지: http://www.haproxy.org/#down
# wget 
http://www.haproxy.org/download/2.7/src/haproxy-2.7.1.tar.gz# tar -zxvf haproxy-2.7.1.tar.gz

management.txt 파일에서 설치 옵션(USE_XXX) 및 기동 방법 대한 정보를 확인 할 수 있다.

 

기본 설치
# make TARGET=linux-glibc

옵션 추가
# make TARGET=linux-glibc USE_OPENSSL=1 USE_PCRE=1 USE_ZLIB=1 USE_SYSTEMD=1

# 싱글 스레드
make TARGET=linux-glibc \
USE_LUA=1 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 \
USE_SYSTEMD=1 USE_PROMEX=1

# 병렬 스레드
make -j 4 TARGET=linux-glibc \
USE_LUA=1 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 \
USE_SYSTEMD=1 USE_PROMEX=1

 

# make install

 

설치 화면
[root@test /SW/haproxy/haproxy-2.7.1]# make TARGET=linux-glibc USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_SYSTEMD=1 USE_PROMEX=1
  CC      src/ev_poll.o
  CC      src/ev_epoll.o
  CC      src/cpuset.o
  CC      src/ssl_sock.o
  CC      src/ssl_ckch.o
  CC      src/ssl_sample.o
  CC      src/ssl_crtlist.o
  CC      src/cfgparse-ssl.o
  CC      src/ssl_utils.o
  CC      src/jwt.o
  CC      addons/promex/service-prometheus.o
  CC      src/namespace.o
  CC      src/mux_h2.o
  CC      src/mux_fcgi.o
  CC      src/mux_h1.o
  CC      src/tcpcheck.o
  CC      src/stream.o
  CC      src/stats.o
  CC      src/http_ana.o
  CC      src/server.o
  CC      src/stick_table.o
  CC      src/sample.o
  CC      src/flt_spoe.o
  CC      src/tools.o
  CC      src/log.o
  CC      src/cfgparse.o
  CC      src/peers.o
  CC      src/backend.o
  CC      src/resolvers.o
  CC      src/cli.o
  CC      src/connection.o
  CC      src/proxy.o
  CC      src/http_htx.o
  CC      src/cfgparse-listen.o
  CC      src/pattern.o
  CC      src/check.o
  CC      src/haproxy.o
  CC      src/cache.o
  CC      src/stconn.o
  CC      src/http_act.o
  CC      src/http_fetch.o
  CC      src/http_client.o
  CC      src/listener.o
  CC      src/dns.o
  CC      src/vars.o
  CC      src/debug.o
  CC      src/tcp_rules.o
  CC      src/sink.o
  CC      src/h1_htx.o
  CC      src/task.o
  CC      src/mjson.o
  CC      src/h2.o
  CC      src/filters.o
  CC      src/server_state.o
  CC      src/payload.o
  CC      src/fcgi-app.o
  CC      src/map.o
  CC      src/htx.o
  CC      src/h1.o
  CC      src/pool.o
  CC      src/cfgparse-global.o
  CC      src/trace.o
  CC      src/tcp_sample.o
  CC      src/flt_http_comp.o
  CC      src/mux_pt.o
  CC      src/flt_trace.o
  CC      src/mqtt.o
  CC      src/acl.o
  CC      src/sock.o
  CC      src/mworker.o
  CC      src/tcp_act.o
  CC      src/ring.o
  CC      src/session.o
  CC      src/proto_tcp.o
  CC      src/fd.o
  CC      src/channel.o
  CC      src/activity.o
  CC      src/queue.o
  CC      src/lb_fas.o
  CC      src/http_rules.o
  CC      src/extcheck.o
  CC      src/flt_bwlim.o
  CC      src/thread.o
  CC      src/http.o
  CC      src/lb_chash.o
  CC      src/applet.o
  CC      src/compression.o
  CC      src/raw_sock.o
  CC      src/ncbuf.o
  CC      src/frontend.o
  CC      src/errors.o
  CC      src/uri_normalizer.o
  CC      src/http_conv.o
  CC      src/lb_fwrr.o
  CC      src/sha1.o
  CC      src/proto_sockpair.o
  CC      src/mailers.o
  CC      src/lb_fwlc.o
  CC      src/ebmbtree.o
  CC      src/cfgcond.o
  CC      src/action.o
  CC      src/xprt_handshake.o
  CC      src/protocol.o
  CC      src/proto_uxst.o
  CC      src/proto_udp.o
  CC      src/lb_map.o
  CC      src/fix.o
  CC      src/ev_select.o
  CC      src/arg.o
  CC      src/sock_inet.o
  CC      src/mworker-prog.o
  CC      src/hpack-dec.o
  CC      src/cfgparse-tcp.o
  CC      src/sock_unix.o
  CC      src/shctx.o
  CC      src/proto_uxdg.o
  CC      src/fcgi.o
  CC      src/eb64tree.o
  CC      src/clock.o
  CC      src/chunk.o
  CC      src/cfgdiag.o
  CC      src/signal.o
  CC      src/regex.o
  CC      src/lru.o
  CC      src/eb32tree.o
  CC      src/eb32sctree.o
  CC      src/cfgparse-unix.o
  CC      src/hpack-tbl.o
  CC      src/ebsttree.o
  CC      src/ebimtree.o
  CC      src/base64.o
  CC      src/auth.o
  CC      src/uri_auth.o
  CC      src/time.o
  CC      src/ebistree.o
  CC      src/dynbuf.o
  CC      src/wdt.o
  CC      src/pipe.o
  CC      src/init.o
  CC      src/http_acl.o
  CC      src/hpack-huff.o
  CC      src/hpack-enc.o
  CC      src/dict.o
  CC      src/freq_ctr.o
  CC      src/ebtree.o
  CC      src/hash.o
  CC      src/dgram.o
  CC      src/version.o
  LD      haproxy
  CC      dev/flags/flags.o
  LD      dev/flags/flags
 
 
[root@test /SW/haproxy/haproxy-2.7.1]# make install

 

※  make 오류 발생시: sudo yum -y install openssl-devel or "openssl*"

[root@test /SW/haproxy/haproxy-2.7.1]# make TARGET=linux-glibc USE_OPENSSL=1 USE_PCRE=1 USE_ZLIB=1 USE_SYSTEMD=1
CC src/ssl_sock.o
In file included from src/ssl_sock.c:62:0:
include/haproxy/openssl-compat.h:10:24: fatal error: openssl/bn.h: 그런 파일이나 디렉터리가 없습니다
#include <openssl/bn.h>
^
compilation terminated.
make: *** [src/ssl_sock.o] 오류 1

 

3)haproxy 복사 or 링크 설정
 -> /usr/local/sbin/haproxy를 /usr/sbin으로 복제하거나 소프트 링크를 설정한다

# cp -p /usr/local/sbin/haproxy /usr/sbin/
# ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy


서비스 시작

# haproxy -f 환경파일명.cfg
haproxy  -D -f 환경파일명.cfg  (데몬으로 실행: 콘솔 끊어져도 프로세스 유지됨)
# haproxy -f /etc/haproxy.cfg \ -D -p /var/run/haproxy.pid -sf $(cat /var/run/haproxy.pid)  (권장)

 

-init 파일에서 HAProxy를 시작하는 안전한 방법은 데몬 모드를 강제 실행하고, 기존 pid값은를 pid 파일에 저장하고,
이 pid 파일을 사용하여 이전 프로세스를 종료하기 전에 종료하도록 알리는 것입니다.

# haproxy -f /etc/haproxy.cfg \ -D -p /var/run/haproxy.pid -sf $(cat /var/run/haproxy.pid)

 

-구성이 몇 개의 특정 파일로 분할된 경우(예: tcp vs http) 

# haproxy -f /etc/haproxy/global.cfg -f /etc/haproxy/stats.cfg \ 
          -f /etc/haproxy/default-tcp.cfg -f /etc/haproxy/tcp.cfg \ 
          -f /etc/haproxy/default-http.cfg -f /etc/haproxy/http.cfg \ 
          -D -p /var/run/haproxy.pid -sf $(cat /var/run/haproxy.pid)

 

-고객별 파일과 같이 알 수 없는 수의 파일이 예상되는 경우 고정 크기 시퀀스 번호로 시작하는 이름을 지정하고 "--"를 사용하여 일부 기본값을 로드한 후 로드하는 것이 좋습니다.

#  haproxy -f /etc/haproxy/global.cfg -f /etc/haproxy/stats.cfg \
                  -f /etc/haproxy/default-tcp.cfg -f /etc/haproxy/tcp.cfg \
                  -f /etc/haproxy/default-http.cfg -f /etc/haproxy/http.cfg \
                  -D -p /var/run/haproxy.pid -sf $(cat /var/run/haproxy.pid) \
                  -f /etc/haproxy/default-customers.cfg -- /etc/haproxy/customers/*

 

서비스 등록 방법

1)haproxy.init 파일 복사
# cp -p /SW/haproxy/haproxy-2.7.1/examples/haproxy.init /etc/init.d/haproxy
# chmod 755 /etc/init.d/haproxy

2)haproxy 환경파일 생성
경로: /etc/haproxy/haproxy.cfg

3)데몬 리로드
# systemctl daemon-reload

K8S 환경에서 prometheus 모니터링이 가능하도록 하려면 아래와 같이 리버스 프록시를 설정해야 한다.
http 포트 8080의 /metrics 호출 시 management 9990의 /metrics 로 전달

Source url Target url
http://$HOSTNAME:8080/metrics http://$HOSTNAME:9990/metrics

 

standalone-ha.xml

...
        <subsystem xmlns="urn:jboss:domain:undertow:12.0" default-server="default-server" default-virtual-host="default-host" default-servlet-container="default" default-security-domain="other" statistics-enabled="true">
            <buffer-cache name="default"/>
            <server name="default-server">
                <ajp-listener name="ajp" socket-binding="ajp" worker="ajp-worker"/>
                <http-listener name="default" socket-binding="http" no-request-timeout="10000" disallowed-methods="PUT DELETE TRACE OPTIONS" redirect-socket="https" enable-http2="true"/>
                <https-listener name="https" socket-binding="https" ssl-context="applicationSSC" enable-http2="true"/>
                <host name="default-host" alias="localhost">
                    <location name="/" handler="welcome-content"/>
                    <!-- metric url 설정 -->
                    <location name="/metrics" handler="management_proxy"/>
                    <access-log pattern="%{i,X-Forwarded-For} %t %m %s %T %b %D %u %r" directory="${jboss.server.log.dir}" prefix="access_log" suffix=".log"/>
                    <filter-ref name="server-header"/>
                    <filter-ref name="x-powered-by-header"/>
                    <filter-ref name="stuck"/>
                    <http-invoker http-authentication-factory="application-http-authentication"/>
                </host>
            </server>
            <servlet-container name="default">
                <jsp-config x-powered-by="false"/>
                <websockets/>
            </servlet-container>
            <handlers>
                <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
                <!-- reverse proxy hander 설정 -->
                <reverse-proxy name="management_proxy">
                    <host name="metrics" outbound-socket-binding="management" scheme="http" path="/metrics"/>
                </reverse-proxy>
            </handlers>
            <filters>
                <response-header name="server-header" header-name="Server" header-value="_"/>
                <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="_"/>
                <expression-filter name="stuck" expression="blocking; stuck-thread-detector(600)"/>
            </filters>
            <application-security-domains>
                <application-security-domain name="other" security-domain="ApplicationDomain"/>
            </application-security-domains>
        </subsystem>


...
    <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
        <socket-binding name="ajp" port="${jboss.ajp.port:8009}"/>
        <socket-binding name="http" port="${jboss.http.port:8080}"/>
        <socket-binding name="https" port="${jboss.https.port:8443}"/>
        <socket-binding name="jgroups-mping" multicast-address="${jboss.default.multicast.address:230.0.0.4}" multicast-port="45700"/>
        <socket-binding name="jgroups-tcp" port="7600"/>
        <socket-binding name="jgroups-tcp-fd" interface="private" port="57600"/>
        <socket-binding name="jgroups-udp" port="55200" multicast-address="${jboss.default.multicast.address:230.0.0.4}" multicast-port="45688"/>
        <socket-binding name="jgroups-udp-fd" interface="private" port="54200"/>
        <socket-binding name="management-http" interface="management" port="${jboss.management.http.port:9990}"/>
        <socket-binding name="management-https" interface="management" port="${jboss.management.https.port:9993}"/>
        <socket-binding name="modcluster" multicast-address="${jboss.modcluster.multicast.address:224.0.1.105}" multicast-port="23364"/>
        <socket-binding name="txn-recovery-environment" port="4712"/>
        <socket-binding name="txn-status-manager" port="4713"/>
        <outbound-socket-binding name="mail-smtp">
            <remote-destination host="${jboss.mail.server.host:localhost}" port="${jboss.mail.server.port:25}"/>
        </outbound-socket-binding>
        <!-- management socket 설정 -->
        <outbound-socket-binding name="management">
            <remote-destination host="${jboss.bind.address.management}" port="9990"/>
        </outbound-socket-binding>
    </socket-binding-group>​

 

+ Recent posts