본문 바로가기

WAS - JBoss,WildFly/설치

[JBoss_WildFly] 서버 기동/정지 스크립트 (Standalone & Domain Mode)

테스트 환경

WildFly 23, 26

JBoss 7.4.*

 


 

User Check & Process Check (Standalone Mode & Domain Mode 공통)

root 계정으로 서버가 기동되거나

프로세스가 중복 기동되는 것을 방지하기 위해 아래 내용을 추가하였다.

##### user & process check #####

#user check
USER=`whoami`

if [ "${USER}" != "${JBOSS_USER}" ]
then
        echo =============================================
        echo You are not jboss user, Please change user
        echo =============================================
        exit
fi

#process running check
PID=`ps -ef|grep java|grep ${SERVER_NAME}|awk '{print $2}'`

if [ "$PID" != "" ]
then
	echo ""
        echo ==================================================================
        echo "[ServerName:${SERVER_NAME}]"_[pid:"${PID}"] Process Is Already Running !!!
        echo ==================================================================
	echo ""
        exit
fi

 

 


 

Standalone Mode

샘플 파일

수정 날짜 : 2023-03-13

shell_scripts_standalone.tar
0.01MB

 

각 스크립트 별 자세한 내용은 아래 내용 참고

 


 

#. 서버 기동 스크립트

##### JAVA HOME #####
export JAVA_HOME=/usr/jdk/jdk1.8.0_202

#----------------------------------------------------------------------------

##### Server Settings #####

#server_info
SERVER_NAME=server1
JBOSS_HOME=/app/jboss/jboss-eap-7.4
JBOSS_MODULEPATH=${JBOSS_HOME}/modules
DOMAIN_HOME=${JBOSS_HOME}/servers/${SERVER_NAME}

#config_file
CONFIG_FILE=standalone-full-ha.xml

#address_settings
export BIND_ADDR=1.1.1.1
export MGMT_ADDR=${BIND_ADDR}

#port_settings
MGMT_PORT=9100
HTTP_PORT=7010
AJP_PORT=7020
PORT_OFFSET=0

#----------------------------------------------------------------------------

##### log_directory #####
LOG_TIME=$(date +"%Y%m%d_%H_%M")
LOG_DIR=/applog/jboss/jboss_74/standalone/${SERVER_NAME}

#----------------------------------------------------------------------------

##### Multicast IP for stndalone-ha.xml #####

export MULTICAST_ADDR=230.0.0.5
#export JMS_MULTICAST_ADDR=231.20.16.1
#export MODCLUSTER_MULTICAST_ADDR=224.20.16.100

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"

#----------------------------------------------------------------------------

##### JVM Options #####

#server_properties
JAVA_OPTS="${JAVA_OPTS} -Dserver.mode=local"
JAVA_OPTS="${JAVA_OPTS} -Djava.net.preferIPv4Stack=true"
JAVA_OPTS="${JAVA_OPTS} -Djboss.host.name=${HOSTNAME}_${SERVER_NAME}"
JAVA_OPTS="${JAVA_OPTS} -Djboss.node.name=${SERVER_NAME}"
JAVA_OPTS="${JAVA_OPTS} -Djboss.server.base.dir=${DOMAIN_HOME}"
JAVA_OPTS="${JAVA_OPTS} -Djboss.server.log.dir=${LOG_DIR}/serverlog"
JAVA_OPTS="${JAVA_OPTS} -Djboss.bind.address=${BIND_ADDR}"
JAVA_OPTS="${JAVA_OPTS} -Djboss.bind.address.management=${MGMT_ADDR}"
JAVA_OPTS="${JAVA_OPTS} -Djboss.ajp.port=${AJP_PORT}"
JAVA_OPTS="${JAVA_OPTS} -Djboss.http.port=${HTTP_PORT}"
#JAVA_OPTS="${JAVA_OPTS} -Djboss.https.port=${HTTPS_PORT}"
JAVA_OPTS="${JAVA_OPTS} -Djboss.socket.binding.port-offset=${PORT_OFFSET}"

#Djboss.modules.system.pkgs
JAVA_OPTS="${JAVA_OPTS} -Djboss.modules.system.pkgs=org.jboss.byteman"

#heap_memory
JAVA_OPTS="${JAVA_OPTS} -Xms1024m -Xmx1024m -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=512m"

#gc
JAVA_OPTS="${JAVA_OPTS} -verbose:gc"
JAVA_OPTS="${JAVA_OPTS} -Xloggc:${LOG_DIR}/gc/gc_${SERVER_NAME}.log"
JAVA_OPTS="${JAVA_OPTS} -XX:+PrintGCTimeStamps -XX:+PrintGCDetails -XX:+PrintHeapAtGC"
#disable_default_gc
GC_LOG=false

#heap_dump
JAVA_OPTS="${JAVA_OPTS} -XX:+HeapDumpOnOutOfMemoryError"
JAVA_OPTS="${JAVA_OPTS} -XX:HeapDumpPath=${LOG_DIR}/dump_files/heapdump_${SERVER_NAME}.hprof"

#----------------------------------------------------------------------------

#jennifer5
#JAVA_OPTS="${JAVA_OPTS} -Djennifer.config=/app/jennifer/agent/5.5.2.12/agent.java/conf/jboss74.conf"
#JAVA_OPTS="${JAVA_OPTS} -javaagent:/app/jennifer/agent/5.5.2.12/agent.java/jennifer.jar"
#JAVA_OPTS="${JAVA_OPTS} -Djboss.modules.system.pkgs=org.jboss.byteman,aries,javax.naming,javax.sql,java.sql,java.rmi"

#----------------------------------------------------------------------------

##### user & process check #####

#user running jboss server
JBOSS_USER=midadm

#user check
USER=`whoami`

if [ "${USER}" != "${JBOSS_USER}" ]
then
        echo =============================================
        echo You are not jboss user, Please change user
        echo =============================================
        exit
fi

#process running check
PID=`ps -ef|grep java|grep ${SERVER_NAME}|awk '{print $2}'`

if [ "$PID" != "" ]
then
	echo ""
        echo ==================================================================
        echo "[ServerName:${SERVER_NAME}]"_[pid:"${PID}"] Process Is Already Running !!!
        echo ==================================================================
	echo ""
        exit
fi

#----------------------------------------------------------------------------

##### Server Start #####
export JAVA_OPTS

mv ${LOG_DIR}/stdout/${SERVER_NAME}.out ${LOG_DIR}/stdout/${SERVER_NAME}.out_${LOG_TIME}
mv ${LOG_DIR}/gc/gc_${SERVER_NAME}.log ${LOG_DIR}/gc/gc_${SERVER_NAME}.log_${LOG_TIME}
nohup ${JBOSS_HOME}/bin/standalone.sh --server-config=${CONFIG_FILE} -Djboss.management.http.port=${MGMT_PORT} >> ${LOG_DIR}/stdout/${SERVER_NAME}.out 2>&1 &

echo "================================================="
echo ""
echo "##### Server Startup #####"
echo ""
echo "JBOSS_HOME=${JBOSS_HOME}"
echo "DOMAIN_HOME=${DOMAIN_HOME}"
echo "SERVER_NAME=${SERVER_NAME}"
echo "CONFIG_FILE=${CONFIG_FILE}"
echo "BIND_ADDR=${BIND_ADDR}"
echo "PORT_OFFSET=${PORT_OFFSET}"
echo "MANAGEMENT_CONSOLE=http://${MGMT_ADDR}:${MGMT_PORT}"
echo ""
echo "================================================="

 

 

#. 서버 정지 스크립트

#JAVA_HOME
export JAVA_HOME=/usr/jdk/jdk1.8.0_202

#---------------------------------------------------------------------------

#server_properties
JBOSS_HOME=/app/jboss/jboss-eap-7.4
IP_ADDRESS=1.1.1.1
MANAGEMENT_PORT=9100

#---------------------------------------------------------------------------

#server_shutdown
$JBOSS_HOME/bin/jboss-cli.sh --connect --controller=$IP_ADDRESS:$MANAGEMENT_PORT --command=shutdown

 

 

#. 서버 로그 tail 프로세스

SERVER_NAME=server1
tail -100f /applog/jboss/jboss_74/standalone/${SERVER_NAME}/serverlog/server.log

 

 


 

Domain Mode

샘플 파일 - Master Host, Slave Host, 서버 인스턴스의 기동/정지 스크립트 포함

수정 날짜 : 2023-03-13

shell_scripts_domain.tar
0.03MB

 

각 스크립트 별 자세한 내용은 아래 내용 참고

 


 

#. 서버 인스턴스 기동/정지 관련 주의사항 (blocking=true 옵션)

(참고 글)

https://docs.jboss.org/author/display/WFLY8/Starting%20&%20stopping%20Servers%20in%20a%20Managed%20Domain.html

 

standalone 모드와 달리 domain 모드의 경우

서버 인스턴스 start, stop, restart 등을 실행하면

해당 커맨드가 완전히 종료되기 전에 starting, stopping, restarting 등의 메시지가 출력된다.

 

기동/정지가 완전히 끝난 이후에 메시지를 출력하도록 하는 것이 

해당 커맨드 실행이 완전히 종료된 이후에 메시지가 출력되도록 하려면 아래와 같이

blocking=true 옵션을 추가해 주어야 한다.

 


 

#. Master Host 기동/정지

 

01. Master Host Controller 기동

#java home
export JAVA_HOME=/usr/jdk/jdk1.8/jdk1.8.0_202

#---------------------------------------------------------------------------

#log_directory
LOG_DIR=/applogs/jboss/jboss_74/domain

#---------------------------------------------------------------------------

#server_properties
JBOSS_HOME=/app/jboss/jboss-eap-7.4
DOMAIN_HOME=$JBOSS_HOME/domain
SERVER_HOME=/applogs/jboss/jboss_74/domain
CONFIG_FILE=host-master.xml
HOST_NAME=master

IP_ADDRESS=192.168.55.169
MANAGEMENT_PORT=7000

PC_PORT=7001

#---------------------------------------------------------------------------

#heap_memory
JAVA_OPTS="$JAVA_OPTS -Xms1024m -Xmx1024m"
export JAVA_OPTS

#---------------------------------------------------------------------------

##### user & process check #####

#user running wildfly server
JBOSS_USER=midadm

#user check
USER=`whoami`

if [ "${USER}" != "${JBOSS_USER}" ]
then
        echo =============================================
        echo You are not jboss user, Please change user
        echo =============================================
        exit
fi

#process running check
PID=`ps -ef|grep java|grep Djboss.host.name=${HOST_NAME}|awk '{print $2}'`

if [ "$PID" != "" ]
then
	echo ""
        echo ========================================================
        echo "[HostName:${HOST_NAME}]" Process Is Already Running !!!
        echo ========================================================
	echo ""
        exit
fi

#---------------------------------------------------------------------------

#log_backup
LOG_TIME=$(date +"%Y%m%d_%H%M")
mv $LOG_DIR/$HOST_NAME.out ${LOG_DIR}/$HOST_NAME.out_${LOG_TIME}

#server_start
nohup $JBOSS_HOME/bin/domain.sh -Djboss.host.name=$HOST_NAME -Djboss.domain.base.dir=$DOMAIN_HOME -Djboss.domain.servers.dir=$SERVER_HOME --host-config=$CONFIG_FILE -Djboss.management.http.port=$MANAGEMENT_PORT -bmanagement=$IP_ADDRESS -b $IP_ADDRESS --pc-address=$IP_ADDRESS --pc-port=$PC_PORT>> $LOG_DIR/$HOST_NAME.out 2>&1 &

 

 

02. Master Host Controller 정지

#java home
export JAVA_HOME=/usr/jdk/jdk1.8/jdk1.8.0_202

#---------------------------------------------------------------------------

#server_properties
JBOSS_HOME=/app/jboss/jboss-eap-7.4
IP_ADDRESS=192.168.55.169
MANAGEMENT_PORT=7000
HOST_NAME=master

#---------------------------------------------------------------------------

#master_host_shutdown
$JBOSS_HOME/bin/jboss-cli.sh --connect --controller=$IP_ADDRESS:$MANAGEMENT_PORT --command=/host=$HOST_NAME:shutdown

 

 

03. Master Host Controller 로그 tail 프로세스

HOST_NAME=master
tail -100f /applogs/jboss/jboss_74/domain/$HOST_NAME.out

 

 


 

#. Slave Host 기동/정지

 

01. Slave Host Controller 기동

#java home
export JAVA_HOME=/usr/jdk/jdk1.8/jdk1.8.0_202

#---------------------------------------------------------------------------

#log_directory
LOG_DIR=/applog/jboss/jboss_74

#---------------------------------------------------------------------------

#server_properties
JBOSS_HOME=/app/wildfly/wildfly_2612
DOMAIN_HOME=$JBOSS_HOME/domain
SERVER_HOME=/applog/jboss/jboss_74
CONFIG_FILE=host-slave.xml
HOST_NAME=slave

IP_ADDRESS=192.168.55.169
MANAGEMENT_PORT=9102
MASTER_IP=192.168.55.169
MASTER_PORT=9100

PC_PORT=9103

#---------------------------------------------------------------------------

#heap_memory
JAVA_OPTS="$JAVA_OPTS -Xms1024m -Xmx1024m"
export JAVA_OPTS

#---------------------------------------------------------------------------

##### user & process check #####

#user running jboss server
JBOSS_USER=midadm

#user check
USER=`whoami`

if [ "${USER}" != "${JBOSS_USER}" ]
then
        echo =============================================
        echo You are not jboss user, Please change user
        echo =============================================
        exit
fi

#process running check
PID=`ps -ef|grep java|grep Djboss.host.name=${HOST_NAME}|awk '{print $2}'`

if [ "$PID" != "" ]
then
	echo ""
        echo ========================================================
        echo "[HostName:${HOST_NAME}]" Process Is Already Running !!!
        echo ========================================================
	echo ""
        exit
fi

#---------------------------------------------------------------------------

#log_backup
LOG_TIME=$(date +"%Y%m%d_%H%M")
mv $LOG_DIR/$HOST_NAME.out ${LOG_DIR}/$HOST_NAME.out_${LOG_TIME}

#server_start
nohup $JBOSS_HOME/bin/domain.sh -Djboss.host.name=$HOST_NAME -Djboss.domain.base.dir=$DOMAIN_HOME -Djboss.domain.servers.dir=$SERVER_HOME --host-config=$CONFIG_FILE -Djboss.domain.master.address=$MASTER_IP -Djboss.domain.master.port=$MASTER_PORT -Djboss.management.http.port=$MANAGEMENT_PORT -bmanagement=$IP_ADDRESS -b $IP_ADDRESS --pc-address=$IP_ADDRESS --pc-port=$PC_PORT --backup --cached-dc >> $LOG_DIR/$HOST_NAME.out 2>&1 &

 

 

02. Slave Host Controller 정지

#java home
export JAVA_HOME=/usr/jdk/jdk1.8/jdk1.8.0_202

#---------------------------------------------------------------------------

#server_properties
JBOSS_HOME=/app/jboss/jboss-eap-7.4
IP_ADDRESS=192.168.55.169
MANAGEMENT_PORT=7002
HOST_NAME=slave

#---------------------------------------------------------------------------

#master_host_shutdown
$JBOSS_HOME/bin/jboss-cli.sh --connect --controller=$IP_ADDRESS:$MANAGEMENT_PORT --command=/host=$HOST_NAME:shutdown

 

 

03. Slave Host Controller 로그 tail 프로세스

HOST_NAME=master
tail -100f /applogs/jboss/jboss_74/domain/$HOST_NAME.out

 

 


 

#. 서버 인스턴스 기동/정지

 

01. 서버 인스턴스 기동

#java home
export JAVA_HOME=/usr/jdk/jdk1.8/jdk1.8.0_202

#---------------------------------------------------------------------------

#server_properties
JBOSS_HOME=/app/jboss/jboss-eap-7.4
IP_ADDRESS=192.168.55.169
MANAGEMENT_PORT=7002
HOST_NAME=slave
SERVER_NAME=server-one

#---------------------------------------------------------------------------

##### user & process check #####

#user running wildfly server
JBOSS_USER=midadm

#user check
USER=`whoami`

if [ "${USER}" != "${JBOSS_USER}" ]
then
        echo =============================================
        echo You are not jboss user, Please change user
        echo =============================================
        exit
fi

#process running check
PID=`ps -ef|grep java|grep ${SERVER_NAME}|awk '{print $2}'`

if [ "$PID" != "" ]
then
	echo ""
        echo ==================================================================
        echo "[ServerName:${HOST_NAME}:${SERVER_NAME}]"_[pid:"${PID}"] Process Is Already Running !!!
        echo ==================================================================
	echo ""
        exit
fi

#---------------------------------------------------------------------------

#gclog_backup
#LOG_TIME=$(date +"%Y%m%d_%H%M")
#GC_LOG_DIR=/applogs/jboss/jboss_74/domain/server-one/gclog
#mv $GC_LOG_DIR/gclog.txt $GC_LOG_DIR/gclog.txt_$LOG_TIME

#---------------------------------------------------------------------------

#server_start
$JBOSS_HOME/bin/jboss-cli.sh --connect --controller=$IP_ADDRESS:$MANAGEMENT_PORT --command="/host=$HOST_NAME/server-config=$SERVER_NAME:start(blocking=true)"

 

 

02. 서버 인스턴스 정지

#java home
export JAVA_HOME=/usr/jdk/jdk1.8/jdk1.8.0_202

#---------------------------------------------------------------------------

#server_properties
JBOSS_HOME=/app/jboss/jboss-eap-7.4
IP_ADDRESS=192.168.55.169
MANAGEMENT_PORT=7002
HOST_NAME=slave
SERVER_NAME=server-one

#---------------------------------------------------------------------------

#gclog_backup
LOG_TIME=$(date +"%Y%m%d_%H%M")
GC_LOG_DIR=/applogs/jboss/jboss_74/domain/$SERVER_NAME/gclog
mv $GC_LOG_DIR/gclog.txt $GC_LOG_DIR/gclog.txt_$LOG_TIME

#---------------------------------------------------------------------------

#server_stop
$JBOSS_HOME/bin/jboss-cli.sh --connect --controller=$IP_ADDRESS:$MANAGEMENT_PORT --command="/host=$HOST_NAME/server-config=$SERVER_NAME:stop(blocking=true)"

 

 

03. 서버 인스턴스 로그 tail 프로세스

SERVER_NAME=m1
tail -100f /applog/jboss/jboss_74/$SERVER_NAME/serverlog/server.log

 

 

#. 그 외 서버 인스턴스 기동/정지 관련 옵션

graceful 정지가 필요할 경우

stop 커맨드에 timeout 옵션 추가

#server_stop
$JBOSS_HOME/bin/jboss-cli.sh --connect --controller=$IP_ADDRESS:$MANAGEMENT_PORT --command="/host=$HOST_NAME/server-config=$SERVER_NAME:stop(blocking=true,timeout=60)"