(3). Jboss의 부하분산 및 세션공유 설정 상세(mod_jk + mod_cluster)
1. Jboss 운영 방식 (domain, standalone)
- 1. standalone
- 2. domain
- 3. Node 분리 : standalone를 복사해사 만듬(파생) -> 가장 직관적인 설정 방식이다.
2. Jboss설정 전체 플로우
3. standalone디랙토리를 복사해서 SERVER11 노드 서버를 만든다
[root@localhost EAP-7.1.0]
[root@localhost EAP-7.1.0]
[root@localhost SERVER11]
[root@localhost SERVER11]
합계 48
drwxrwxr-x. 9 jboss jboss 240 4월 4 07:05 .
drwxr-xr-x. 16 jboss jboss 4096 5월 27 2018 ..
drwxrwxr-x. 3 jboss jboss 4096 4월 2 15:25 configuration
drwxrwxr-x. 8 jboss jboss 118 5월 25 2018 data
drwxrwxr-x. 4 jboss jboss 128 4월 2 15:56 deployments
drwxrwxr-x. 3 jboss jboss 17 5월 4 2018 lib
drwxrwxr-x. 4 jboss jboss 4096 4월 3 00:19 log
drwxrwxr-x. 2 jboss jboss 4096 4월 2 15:56 nohup
drwxrwxr-x. 4 jboss jboss 29 4월 3 02:17 tmp
[root@localhost SERVER11]
4. 쉘 스크립트 작성
- 노드 별로 수정이 필요한 파일 (노드ID, Offset 포트만 수정해서 사용)
env.sh
- 모든 노드를 동일하게 사용하는 파일 (한반만 작성해서 모든 노드에 복사해서 사용)
env.properties
Shutdown.sh
Start.sh
jboss-cli.sh
jboss-jconsole.sh
- instance-id 속성 (동적 변수로 변경) : standalone-full-ha.xml
변경 전 : <subsystem xmlns="urn:jboss:domain:undertow:4.0" instance-id="S01-Node01">
변경 후 : <subsystem xmlns="urn:jboss:domain:undertow:4.0" instance-id="${jboss.node.name}">
5. env 쉘 스크립트(env.sh)
[root@localhost SERVER11]
DATE=`date +%Y%m%d%H%M%S`
export JBOSS_HOME=/home/jboss/EAP-7.1.0
export DOMAIN_BASE=/home/jboss/EAP-7.1.0
export CONFIG_FILE=standalone-full-ha.xml
export HOST_NAME=myweb
export JBOSS_USER=jboss
export HOST_IP=192.168.20.1
export SERVER_NAME=SERVER11
export NODE_NAME=S02-Node01
export PORT_OFFSET=0
export BIND_ADDR=$HOST_IP
export MULTICAST_ADDR=230.0.0.4
export JMS_MULTICAST_ADDR=231.7.7.7
export MODCLUSTER_MULTICAST_ADDR=224.0.1.105
export JGROUPS_BIND_ADDR=$HOST_IP
export MGMT_ADDR=$HOST_IP
export CONTROLLER_IP=$MGMT_ADDR
let JBOSS_CONTROLLER_PORT=9990+$PORT_OFFSET
export JBOSS_CONTROLLER_PORT
export LAUNCH_JBOSS_IN_BACKGROUND=true
export JBOSS_MANAGEMENT_ADDR=$HOST_IP
export JBOSS_CONTROLLER_IP=$JBOSS_MANAGEMENT_ADDR
export JBOSS_MODULEPATH=$JBOSS_HOME/modules:$JBOSS_HOME/modules.ext
export JAVA_OPTS="-server $JAVA_OPTS"
export JAVA_OPTS=" $JAVA_OPTS -Xms1024m -Xmx4096m "
export JAVA_OPTS=" $JAVA_OPTS -XX:+UseParallelGC "
export JAVA_OPTS=" $JAVA_OPTS -XX:+ExplicitGCInvokesConcurrent "
export JAVA_OPTS=" $JAVA_OPTS -XX:-HeapDumpOnOutOfMemoryError "
export JAVA_OPTS=" $JAVA_OPTS -Djava.net.preferIPv4Stack=true"
export JAVA_OPTS=" $JAVA_OPTS -Dorg.jboss.resolver.warning=true"
export JAVA_OPTS=" $JAVA_OPTS -Dsun.rmi.dgc.client.gcInterval=3600000 "
export JAVA_OPTS=" $JAVA_OPTS -Dsun.rmi.dgc.server.gcInterval=3600000"
export JAVA_OPTS=" $JAVA_OPTS -Djboss.modules.system.pkgs=org.jboss.byteman"
export JAVA_OPTS=" $JAVA_OPTS -Djava.awt.headless=true"
export JAVA_OPTS=" $JAVA_OPTS -Djboss.server.base.dir=$DOMAIN_BASE/$SERVER_NAME"
export JAVA_OPTS=" $JAVA_OPTS -Djboss.socket.binding.port-offset=$PORT_OFFSET"
export JAVA_OPTS=" $JAVA_OPTS -Djboss.node.name=$NODE_NAME"
export JAVA_OPTS=" $JAVA_OPTS -Djgroups.bind_addr=$JGROUPS_BIND_ADDR"
export JAVA_OPTS=" $JAVA_OPTS -Djboss.bind.address.management=$MGMT_ADDR"
export JAVA_OPTS=" $JAVA_OPTS -Djboss.bind.address=$BIND_ADDR"
export JAVA_OPTS=" $JAVA_OPTS -Djboss.bind_addr=$MULTICAST_ADDR"
export JAVA_OPTS=" $JAVA_OPTS -Djboss.default.multicast.address=$MULTICAST_ADDR"
export JAVA_OPTS=" $JAVA_OPTS -Djboss.messaging.group.address=$JMS_MULTICAST_ADDR"
export JAVA_OPTS=" $JAVA_OPTS -Djboss.modcluster.multicast.address=$MODCLUSTER_MULTICAST_ADDR"
export JAVA_OPTS=" $JAVA_OPTS -Dorg.jboss.as.logging.per-deployment=false"
export JAVA_OPTS=" $JAVA_OPTS -Dserver.mode=local"
echo "================================================"
echo "JBOSS_HOME=$JBOSS_HOME"
echo "DOMAIN_BASE=$DOMAIN_BASE"
echo "SERVER_NAME=$SERVER_NAME"
echo "CONFIG_FILE=$CONFIG_FILE"
echo "BIND_ADDR=$BIND_ADDR"
echo "PORT_OFFSET=$PORT_OFFSET"
echo "MULTICAST_ADDR=$MULTICAST_ADDR"
echo "CONTROLLER=$JBOSS_CONTROLLER_IP:$JBOSS_CONTROLLER_PORT"
echo "================================================"
노드별 설정에서 변경 해야하는 속성
- node1 : env.sh
export HOST_IP=192.168.20.1
export SERVER_NAME=SERVER11
export NODE_NAME=S01-Node01
export PORT_OFFSET=0
- node2 : env.sh
export HOST_IP=192.168.20.1
export SERVER_NAME=SERVER12
export NODE_NAME=S01-Node02
export PORT_OFFSET=100
6. env속성 파일 (env.properties)
[root@localhost SERVER11]
UseJK=true
org.apache.coyote.http11.Http11Protocol.SERVER="MyTest-WS"
7. 시작 쉘 스크립트(Start.sh)
[root@localhost SERVER11]
DATE=`date +%Y%m%d%H%M%S`
. ./env.sh
PID=`ps -ef | grep java | grep "=$SERVER_NAME " | awk '{print $2}'`
echo $PID
if [ e$PID != "e" ]
then
echo "JBoss SERVER - $SERVER_NAME is already RUNNING..."
exit;
fi
UNAME=`id -u -n`
if [ e$UNAME != "e$JBOSS_USER" ]
then
echo "Use $JBOSS_USER account to start JBoss SERVER - $SERVER_NAME..."
exit;
fi
echo $JAVA_OPTS
if [ ! -d "./nohup" ];
then
mkdir nohup
fi
mv $SERVER_NAME.out ./nohup/$SERVER_NAME.out.$DATE
nohup $JBOSS_HOME/bin/standalone.sh -DSERVER=$SERVER_NAME -b $BIND_ADDR -bmanagement $MGMT_ADDR -u $MULTICAST_ADDR -P=$DOMAIN_BASE/$SERVER_NAME/env.properties -c $CONFIG_FILE >> $SERVER_NAME.out &
if [ e$1 = "enotail" ]
then
echo "Starting..... $SERVER_NAME"
exit;
fi
if [ "$1" = "NoTail" ]; then
echo ""
else
tail -f $SERVER_NAME.out
fi
8. 종료 쉘 스크립트(Shutdown.sh)
[root@localhost SERVER11]
. ./env.sh
PID=`ps -ef | grep java | grep "=$SERVER_NAME " | awk '{print $2}'`
echo $PID
if [ e$PID == "e" ]; then
echo "JBoss SERVER $SERVER_NAME is Not RUNNING..."
exit;
fi
$JBOSS_HOME/bin/jboss-cli.sh --connect --controller=$CONTROLLER_IP:$JBOSS_CONTROLLER_PORT --command=:shutdown
9. CLI관리콘솔 쉘 스크립트(jboss-cli.sh)
[root@localhost SERVER11]
BASE_DIR=$(dirname $0)
. $BASE_DIR/env.sh
export JAVA_OPTS=" -Djava.awt.headless=false $JAVA_OPTS"
$JBOSS_HOME/bin/jboss-cli.sh --controller=$JBOSS_CONTROLLER_IP:$JBOSS_CONTROLLER_PORT --connect $@
10. Jconsole 쉘 스크립트(jboss-jconsole.sh)
[root@localhost SERVER11]
BASE_DIR=$(dirname $0)
. $BASE_DIR/env.sh
echo "======================================================="
echo " JMX URL : service:jmx:remoting-jmx://$JBOSS_MANAGEMENT_ADDR:$JBOSS_CONTROLLER_PORT"
echo "======================================================="
$JBOSS_HOME/bin/jconsole.sh
11. 배포 설정 (Jboss Deploy Host)
<subsystem xmlns="urn:jboss:domain:undertow:4.0" instance-id="${jboss.node.name}">
<buffer-cache name="default"/>
<server name="default-server">
<ajp-listener name="ajp" socket-binding="ajp" max-post-size="2147483648"/>
<http-listener name="default" socket-binding="http" max-post-size="2147483648" redirect-socket="https" enable-http2="true"/>
<https-listener name="https" socket-binding="https" max-post-size="2147483648" security-realm="ApplicationRealm" enable-http2="true"/>
<host name="default-host" alias="localhost">
<location name="/" handler="welcome-content"/>
<filter-ref name="server-header"/>
<filter-ref name="x-powered-by-header"/>
</host>
<host name="MyWeb2-Host" alias="myweb2.co.kr" default-web-module="myweb2.war" disable-console-redirect="false"/>
<host name="MyWeb-Host" alias="myweb.co.kr" default-web-module="myweb.war" disable-console-redirect="false"/>
</server>
<servlet-container name="default">
<jsp-config development="true" check-interval="1" modification-test-interval="1" recompile-on-fail="true"/>
<websockets/>
</servlet-container>
<handlers>
<file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
</handlers>
<filters>
<response-header name="server-header" header-name="Server" header-value="JBoss-EAP/7"/>
<response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>
</filters>
</subsystem>
- 배포를 위한 설정1 (standalone-full-ha.xm)
- node1 : /home/jboss/EAP-7.1.0/SERVER11/configuration/standalone-full-ha.xml
- node2 : /home/jboss/EAP-7.1.0/SERVER12/configuration/standalone-full-ha.xml
- host 연결 이름 : <host name="MyWeb-Host" alias="myweb.co.kr" default-web-module="myweb.war" disable-console-redirect="false"/>
- 배포를 위한 설정2 (myweb.war/WEB-INF/jboss.xml)
- Virtual Host : <virtual-host>MyWeb-Host</virtual-host>
12. 방화벽 설정
- 방화벽 구성(열기)
[root@localhost sysconfig]# cd /etc/sysconfig/
[root@localhost sysconfig]# vi iptables
- 방화벽 구성(편집)
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -d 224.0.1.0/24 -p udp -m comment --comment "mod_cluster traffic" -j ACCEPT
-A INPUT -d 224.0.0.0/4 -p udp -m comment --comment "JBoss Cluster traffic" -j ACCEPT
-A INPUT -s 192.168.10.0/24 -p udp -m comment --comment "cluster subnet for inter-node communication" -j ACCEPT
-A INPUT -s 192.168.10.0/24 -p tcp -m comment --comment "cluster subnet for inter-node communication" -j ACCEPT
-A INPUT -s 230.0.0.4/32 -p udp -m udp --dport 45688 -m comment --comment "jgroups-udp (multicast-port:4-j ACCEPT 5688)" -j ACCEPT
-A INPUT -s 230.0.0.4/32 -p udp -m udp --dport 45700 -m comment --comment "jgroups-mping(multicast-port:4-j ACCEPT 5700)" -j ACCEPT
-A INPUT -s 231.7.7.7/32 -p udp -m udp --dport 9876 -m comment --comment "hornetq (multicast-port:9-j ACCEPT 876)" -j ACCEPT
-A INPUT -s 224.0.1.105/32 -p udp -m udp --dport 23364 -m comment --comment "224.0.1.105 (multicast-port(2-j ACCEPT 3364)" -j ACCEPT
-A INPUT -m iprange --src-range 192.168.20.1-192.168.20.4 -p tcp -m tcp --dport 3528 -j ACCEPT
-A INPUT -m iprange --src-range 192.168.20.1-192.168.20.4 -p tcp -m tcp --dport 3529 -j ACCEPT
-A INPUT -m iprange --src-range 192.168.20.1-192.168.20.4 -p tcp -m tcp --dport 7600 -j ACCEPT
-A INPUT -m iprange --src-range 192.168.20.1-192.168.20.4 -p tcp -m tcp --dport 54200 -j ACCEPT
-A INPUT -m iprange --src-range 192.168.20.1-192.168.20.4 -p tcp -m tcp --dport 57600 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
- 방화벽 구성(네트웍크 재시작)
[root@localhost sysconfig]# /etc/rc.d/init.d/network restart
13. 실행 권한 부여
[root@localhost SERVER11]# cd /home/jboss/EAP-7.1.0/SERVER11
[root@localhost SERVER11]# chmod +x *.sh
[root@localhost SERVER12]# cd /home/jboss/EAP-7.1.0/SERVER12
[root@localhost SERVER12]# chmod +x *.sh
14. Jboss 시작/종료
- Node1 시작
[root@localhost SERVER11]# su - jboss
[root@localhost SERVER11]# cd /home/jboss/EAP-7.1.0/SERVER11
[root@localhost SERVER11]# ./Start.sh
- Node2 시작
[root@localhost SERVER12]# su - jboss
[root@localhost SERVER12]# cd /home/jboss/EAP-7.1.0/SERVER12
[root@localhost SERVER12]# ./Start.sh
- Node1 종료
[root@localhost SERVER11]# su - jboss
[root@localhost SERVER11]# cd /home/jboss/EAP-7.1.0/SERVER11
[root@localhost SERVER11]# ./Shutdown.sh
- Node2 종료
[root@localhost SERVER12]# su - jboss
[root@localhost SERVER12]# cd /home/jboss/EAP-7.1.0/SERVER12
[root@localhost SERVER12]# ./Shutdown.sh