아파치+wildfly 연동
- mod_jk 컴파일
apxs 모듈설치 확인
find / -name "*apxs*"
미 설치시, 아래 명령어로 설치
yum install httpd-devel
Apache Connector 설치
//wget http://apache.mirror.cdnetworks.com/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.41-src.tar.gz
wget http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.46-src.tar.gz
gcc 가 설치 안되어 있으면 설치 컴파일러
yum install gcc
압축을 푼다
tar xvzf tomcat-connector-1.2.46.-src.tar.gz
컴파일 진행
- cd tomcat-connector-1.2.46-src/native
2. ./configure --with-apxs=/usr/bin/apxs
3. make
- make install
컴파일이 정상적으로 완료 되면 아래 경로에 mod_jk.so 파일 생성
cd /etc/httpd/modules
==================================================
/* 환경설정 파일 수정 */
vi /etc/httpd/conf/httpd.conf
내용은 아래와 같음
# Include mod_jk configuration file
Include conf/mod-jk.conf
ServerName 127.0.1.1 ---> [이부분은 실행할때마다 서버네임에 관한 메세지가 뜨는 것을 없애줌]
======================================================
mod-jk.conf 파일생성 APAHCE_HOME/conf 밑에 있다고 했으니까
mod-jk.conf 파일을 만들어서 APACHE_HOM/conf 밑에 갖다 두어야 함.
mod-jk.conf 파일을 만들어야 하는데 이 파일은 mod-jk 모듈에 대한 메타정보를 갖고 있음.
파일명: APACHE_HOME/conf/mod-jk.conf
내용은 아래와 같음
vi mod-jk.conf
LoadModule jk_module /etc/httpd/modules/mod_jk.so
JkWorkersFile /etc/httpd/conf/workers.properties
JkShmFile run/mod_jk.shm
JkLogFile /etc/httpd/logs/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
JkOptions +ForwardKeySize +ForwardURICompatUnparsed -ForwardDirectories
JkRequestLogFormat "%w %V %T"
#JkMount /* loadbalancer
#JkMount /jkmanager/* jkstatus
<Location /jkmanager >
# JkMount statusmanager
Order deny,allow
# Require all denied
Deny from all
# Allow from 127.0.0.1
Allow from all
</Location>
# JkMount /* loadbalancer
JkMountFile /etc/httpd/conf/uriworkermap.properties
====================================================
worker config 작성
파일명: APACHE_HOME/conf/workers.properties
vi workers.properties
=========================================== workers.properties ===========================================
################################################################################################
# dynamic mapping (load balance)
################################################################################################
worker.list=loadbalancer
# define invako2
worker.invako2.host=192.168.0.223
worker.invako2.port=18009
worker.invako2.type=ajp13
worker.invako2.lbfactor=1
# define invako3
worker.invako3.host=192.168.0.226
worker.invako3.port=18009
worker.invako3.type=ajp13
worker.invako3.lbfactor=1
# Load-balancing
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=invako2,invako3
Worker.loadbalancer.sticky_session=1
# Status worker for managing load balancer
worker.list=jkstatus
worker.jkstatus.type=status
=========================================== workers.properties ===========================================
아파치로 요청오는 URI를 worker랑 매핑시키는 파일 작성해야함
파일명: APACHE_HOME/conf/uriworkermap.properties
vi uriworkermap.properties
=========================================== uriworkermap.properties ===========================================
/jmx-console=loadbalancer
/jmx-console/*=loadbalancer
/web-console=loadbalancer
/web-console/*=loadbalancer
/*.do=loadbalancer
/*.jsp=loadbalancer
/jkmanager=jkstatus
#/=loadbalancer
#/*=loadbalancer
/* 여기까지 위에꺼만 적용 아래는 참조 */
/* 확장자 별로 세부 설정 참조 */
# 확장자가 .jsp, .do 파일 node1 worker 로 매핑
/*.jsp=node1
/*.do=node1
# 경로가 /helloworld, /helloworld 하위 경로를 node2 worker 로 매핑
/helloworld=node2
/helloworld/*=node2
# 경로가 /high, /high 하위 경로를 wlb worker 로 매핑
/high=wlb
/high/*=wlb
=========================================== uriworkermap.properties ===========================================
# 아래 예와 같이 <VirtualHost></VirtualHost> 내에 worker 를 지정하는 방법도 있음
# VirtualHost Worker 지정
<VirtualHost *:80>
<ServerName> test.com
<ServerAlias> www.test.com
…
JkMount /*.jsp invako2
</VirtlaHost>
<VirtualHost *:80>
ServerAdmin id@mail.com <= 메일주소
DocumentRoot "D:/webapp1" <= 웹소스 경로
ServerName www.mydomain1.com <= 도메인
ServerAlias mydomain1.com <= 도메인 Alias (생략가능)
ErrorLog "logs/.mydomain1.com-error.log"
CustomLog "logs/.mydomain1.com-access.log" common
JkMount /*.jsp worker1 <= mod_jk.conf 에 있던 Mount정보
JkMount /*.do worker1 <= mod_jk.conf 에 있던 Mount정보
</VirtualHost>
<VirtualHost *:80>
ServerAdmin id@mail.com <= 메일주소
DocumentRoot "D:/webapp2" <= 웹소스 경로
ServerName www.mydomain2.com
ServerAlias mydomain2.com
ErrorLog "logs/.mydomain2.com-error.log"
CustomLog "logs/.mydomain2.com-access.log" common
JkMount /*.jsp worker2
JkMount /*.do worker2
</VirtualHost>
======================================================
적용후 아파치 서버 재기동
systemctl stop httpd
systemctl start httpd
/* 아파치 loadbalance 모니터링 jkmanager 실행 */
=========================================================
Jboss 환경설정 (jboss-web.xml )
================================================
<use-jk>true</use-jk> 옵션 설정 (default 는 true)
파일 : jboss-web.xml
<jboss-web>
<context-root>/</context-root>
<replication-config>
<replication-trigger>SET</replication-trigger>
<use-jk>false</use-jk>
</replication-config>
</jboss-web>
<!--use-jk element 가 true 라면 sticky session 정보가 설정되어 한번 연결이 되었던 인스턴스로 계속 요청을 보내게 됩니다.
로드밸런싱을 위해서는 false 로 설정하는 것이 좋습니다.
-->
web.xml 안에는 distributable 설정되야 합니다.
<web-app>
<distributable/>
... ...
</web-app>
위와 같이 sticky_session 세션을 사용하기 위해서는 3가지를 명심해야 합니다. (꼭 설정이 되있어야지 인식이 됩니다)
==========================================================
Wildfly 설정
=========================================================
/* 세션클러스터 tcp로 설정 */
<subsystem xmlns="urn:jboss:domain:jgroups:7.0">
<channels default="ee">
<channel name="ee" stack="tcp" cluster="ejb"/>
</channels>
<stacks>
<stack name="tcp">
<transport type="TCP" socket-binding="jgroups-tcp"/>
<protocol type="org.jgroups.protocols.TCPPING">
<property name="initial_hosts">10.10.10.61[7600],10.10.10.62[7600]</property>
<property name="timeout">3000</property>
</protocol>
<protocol type="MERGE3"/>
<socket-protocol type="FD_SOCK" socket-binding="jgroups-tcp-fd"/>
<protocol type="FD_ALL"/>
<protocol type="VERIFY_SUSPECT"/>
<protocol type="pbcast.NAKACK2"/>
<protocol type="UNICAST3"/>
<protocol type="pbcast.STABLE"/>
<protocol type="pbcast.GMS"/>
<protocol type="MFC"/>
<protocol type="FRAG3"/>
</stack>
</stacks>
</subsystem>
<interfaces>
<interface name="any">
<any-address/>
</interface>
<interface name="management">
<inet-address value="${jboss.bind.address.private:10.10.10.61}"/>
</interface>
<interface name="private">
<inet-address value="${jboss.bind.address.private:10.10.10.61}"/>
</interface>
<interface name="public">
<inet-address value="${jboss.bind.address:10.10.10.61}"/>
</interface>
</interfaces>
<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:18009}"/>
<socket-binding name="http" port="${jboss.http.port:18090}"/>
<socket-binding name="https" port="${jboss.https.port:18443}"/>
<socket-binding name="jgroups-mping" interface="private" multicast-address="${jboss.default.multicast.address:230.0.0.4}" multicast-port="45700"/>
<socket-binding name="jgroups-tcp" interface="private" port="7600"/>
<socket-binding name="jgroups-tcp-fd" interface="private" port="57600"/>
<socket-binding name="jgroups-udp" interface="private" 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:19990}"/>
<socket-binding name="management-https" interface="management" port="${jboss.management.https.port:19993}"/>
<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="localhost" port="25"/>
</outbound-socket-binding>
</socket-binding-group>
설정후 jboss 기동
nohup /home/jboss/wildfly-19.0.0.Final/bin/standalone.sh -c standalone-ha.xml 1>/dev/null 2>&1 &
/home/jboss/wildfly-19.0.0.Final/bin/jboss-cli.sh --controller=192.168.0.223:19990 -c command=":shutdown"
vi .bash_profile
#Alias Set
alias jboot='nohup /home/jboss/wildfly-19.0.0.Final/bin/standalone.sh -c standalone-ha.xml 1>/dev/null 2>&1 &'
alias jdown='/home/jboss/wildfly-19.0.0.Final/bin/jboss-cli.sh --controller=192.168.0.223:19990 -c command=":shutdown"'
/* wildfly 관리자모드 셋팅 */
Add-user.sh 실행하여 사용자와 패스워드를 셋팅한다.
/home/jboss/wildfly-19.0.0.Final/bin/add-user.sh
Url 접속
Id : wildfly
pw : wildfly