본문 바로가기
WAS/JBOSS_WILDFLY

1.1. JBoss 스크립트

by coldplayer83 2023. 2. 17.
728x90

env.sh (start.sh에 아래 내용이 작성되어 있다면 별도로 필요x)

#!/bin/sh
DATE=`date +%Y%m%d%H%M%S`
##### JBoss Directory Setup #####
export JBOSS_HOME=/sw/was/jboss/jboss-eap-7.4       # 설치된 JBOSS EAP 버전에 맞는 디렉터리 설정
export JAVA_HOME=/usr/java/jdk1.8.0_202        # 사용하는 JDK 버전에 맞게 설정
export DOMAIN_BASE=/sw/was/jboss/jboss-eap-7.4/domains                # 도메인 베이스 디렉터리 설정
export SERVER_NAME=node10                            # 생성한 노드명 설정
export HOST_NAME=`hostname`                            # 호스트네임을 서버에 정의된 HOSTNAME으로 자동인식 처리
 
##### Configuration File #####
export CONFIG_FILE=standalone-full-ha.xml                # 환경 설정 파일 등록
export PORT_OFFSET=0                                # 포트 OFFSET 값 등록
export JBOSS_USER=jboss                                # jboss 유저 등록
 
##### Bind Address #####
export BIND_ADDR=`hostname -i`                        # 시스템에 설정된 etho0의 네트워크 IP 값을 자동으로 인식
export MGMT_ADDR=$BIND_ADDR                            # 관리 주소 등록
export CONTROLLER_IP=$MGMT_ADDR                        # 관리자 IP 등록
let CONTROLLER_PORT=9999+$PORT_OFFSET                # 관리자 포트 값 연산
export CONTROLLER_PORT                                # 관리자 포트 등록
export LAUNCH_JBOSS_IN_BACKGROUND=true
 
# Multicast IP for stndalone-ha.xml #####
##### MIP, change Please #####
#export MULTICAST_ADDR=192.168.56.101                    # 멀티 캐스트 ip 설정(같은 클러스터간 동일값)
#export JMS_MULTICAST_ADDR=192.168.56.101                # JMS 멀티 캐스트 IP 설정(같은 클러스터간 동일값)
#export MODCLUSTER_MULTICAST_ADDR=192.168.56.101
#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"
 
# LOG 디렉터리 위치 설정
export LOG_HOME=$DOMAIN_BASE/$SERVER_NAME/log
#export LOG_HOME=$DOMAIN_BASE/$SERVER_NAME/log
 
# Jboss System module and User module directory #####
export JBOSS_MODULEPATH=$JBOSS_HOME/modules
 
# JVM Options : Server
export JAVA_OPTS="-server $JAVA_OPTS"
 
# JVM Options : Memory
export JAVA_OPTS="$JAVA_OPTS -Xms2048m -Xmx2048m -XX:MaxMetaspaceSize=512m"
export JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCTimeStamps"
export JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDetails"
export JAVA_OPTS="$JAVA_OPTS -Xloggc:$LOG_HOME/gclog/gc_$DATE.log"
export JAVA_OPTS="$JAVA_OPTS -XX:+UseParallelGC"
#export JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMaskSweepGC"
export JAVA_OPTS="$JAVA_OPTS -XX:+ExplicitGCInvokesConcurrent"
export JAVA_OPTS="$JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError"      # OOME 발생 시 힘덤프 자동 생성
export JAVA_OPTS="$JAVA_OPTS -XX:HeapDumpPath=$LOG_HOME/gclog/java_pid_$DATE.hprof"   # 힙덤프 파일명에 생성일 추가
 
# Linux Large Page Setting
# export JAVA_OPTS="$JAVA_OPTS -XX:+UseLargePages"
export JAVA_OPTS="$JAVA_OPTS -verbose:gc"
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=${SERVER_NAME}"
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 -Dserver.mode=local"
 
# Use log4j in application
export JAVA_OPTS="$JAVA_OPTS -Dorg.jboss.as.logging.per-deployment=false"
export JAVA_OPTS="$JAVA_OPTS -Djboss.server.log.dir=$LOG_HOME"
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 "CONTROLLER=$CONTROLLER_IP:$CONTROLLER_PORT"
echo "jboss.node.name=${SERVER_NAME}"
echo "================================================="

 

env.properties

org.apache.catalina.connector.URI_ENCODING=UTF-8
org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING=true
org.apache.coyote.http11.Http11Protocol.MAX_HEADER_SIZE=8192
org.apache.coyote.ajp.DEFAULT_CONNECTION_TIME=60000
org.apache.coyote.http11.DEFAULT_CONNECTION_TIMEOUT=60000
org.apache.tomcat.util.http.Parameters.MAX_COUNT=10000
file.encoding=UTF-8
#jvmRoute=AP_name10
UseJK=true

 

start.sh (ver1)

#!/bin/sh
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`                    # username이 app(jboss용 linux 계정)이 아니면 서버가 기동되지 않도록 설정
if [ $UNAME != "app" ]
then
     echo "Use $JBOSS_USER account to start JBoss SERVER -$SERVER_NAME..."
     exit;
fi

#UNAME=`id -u -n`                    # username과 추가한 jboss 계정 이름이 같지 않으면 서버가 기동이 되지 않음
#  
#if [ e$UNAME != "e$JBOSS_USER" ]
#then
#     echo "Use $JBOSS_USER account to start JBoss SERVER -$SERVER_NAME..."
#     exit;
#fi


echo $JAVA_OPTS
#mv $LOG_HOME/nohup/$SERVER_NAME.out $LOG_HOME/nohup/$SERVER_NAME.out.$DATE
#mv $LOG_HOME/gclog/gc.log $LOG_HOME/gclog/gc.log.$DATE
# nohup log 이동 관련 제거, nohup log 파일명에 생성일 추가
nohup $JBOSS_HOME/bin/standalone.sh -DSERVER=$SERVER_NAME -P=$DOMAIN_BASE/$SERVER_NAME/bin/env.properties -c $CONFIG_FILE >> $LOG_HOME/nohup/${SERVER_NAME}_${DATE}.out &
#nohup $JBOSS_HOME/bin/standalone.sh -DSERVER=$SERVER_NAME -b $BIND_ADDR -u $MULTICAST_ADDR -P=$DOMAIN_BASE/$SERVER_NAME/env.properties -c $CONFIG_FILE >> $SERVER_NAME.out &
if [ $1 ="enotail" ]
then
     echo "Starting... $SERVER_NAME"
     exit;
fi
tail -f $LOG_HOME/server.log    # tail을 nohup 로그에서 server.log로 변경
#tail -f $SERVER_NAME.out
#tail -f $LOG_HOME/nohup/$SERVER_NAME.out

 

start.sh (ver2)

##### JAVA HOME #####
export JAVA_HOME=/usr/java/jdk1.8.0_281-amd64


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


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


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


#config_file
CONFIG_FILE=standalone-full.xml


#address_settings
export BIND_ADDR=192.168.56.101
xport MGMT_ADDR=${BIND_ADDR}


#port_settings
MGMT_PORT=7000
HTTP_PORT=7001
AJP_PORT=7002
PORT_OFFSET=0


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


##### log_directory #####
LOG_TIME=$(date +"%Y%m%d_%H_%M")
LOG_DIR=/logs/jboss/jboss-eap-7.4/standalone/${SERVER_NAME}


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


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


#export MULTICAST_ADDR=230.20.16.1
#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} -Xms2048m -Xmx2048m -XX:MaxMetaspaceSize=512m"


#gc
JAVA_OPTS="${JAVA_OPTS} -verbose:gc"
JAVA_OPTS="${JAVA_OPTS} -Xlog:gc:${LOG_DIR}/gc/gc_${SERVER_NAME}.log"

#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"


export JAVA_OPTS


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


##### Server Start #####
mv ${LOG_DIR}/${SERVER_NAME}.out ${LOG_DIR}/${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}/${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 "================================================="

 

stop.sh (ver1)

#JAVA_HOME
export JAVA_HOME=/usr/java/jdk1.8.0_281-amd64


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


#server_properties
JBOSS_HOME=/sw/was/jboss/jboss-eap-7.4
IP_ADDRESS=192.168.56.101
MANAGEMENT_PORT=7000


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


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

 

stop.sh (ver2)

#!/bin/sh
. ./env.sh
$JBOSS_HOME/bin/jboss-cli.sh --connect --controller=$CONTROLLER_IP:$CONTROLLER_PORT --command=:shutdown
tail -f $LOG_HOME/nohup/$SERVER_NAME.out

 

status.sh

#!/bin/sh
. ./env.sh
ps -ef | grep java | grep "SERVER=$SERVER_NAME"

 

tail.sh

#!/bin/sh
. ./env.sh
tail -f $LOG_HOME/server.log

 

log.sh

SERVER_NAME=server1
tail -100f /logs/jboss/jboss-eap-7.4/standalone/${SERVER_NAME}/serverlog/server.log

 

add_user.sh (ver1)

#JAVA_HOME
export JAVA_HOME=/usr/java/jdk1.8.0_281-amd64


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


JBOSS_HOME=/sw/was/jboss/jboss-eap-7.4
SERVER_NAME=server1


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


$JBOSS_HOME/bin/add-user.sh
cp $JBOSS_HOME/standalone/configuration/mgmt-users.properties $JBOSS_HOME/servers/$SERVER_NAME/configuration/mgmt-users.properties

 

add_user.sh (ver2)

#!/bin/sh
. ./env.sh
JAVA_OPTS="$JAVA_OPTS -Djboss.server.config.user.dir=$DOMAIN_BASE/$SERVER_NAME/configuration"
$JBOSS_HOME/bin/add-user.sh $@

 

jboss-cli.sh

#!/bin/sh
. ./env.sh
export JAVA_OPTS=" -Djava.awt.headless=false $JAVA_OPTS"
$JBOSS_HOME/bin/jboss-cli.sh  --controller=$CONTROLLER_IP:$CONTROLLER_PORT --connect $@

 

kill.sh

#!/bin/sh
. ./env.sh
ps -ef | grep java | grep "SERVER=$SERVER_NAME " | awk {'print "kill -9 " $2'} | sh -x

'WAS > JBOSS_WILDFLY' 카테고리의 다른 글

4. [standalone] 패치  (0) 2023.05.22
3. [standalone] 다른 장비에 이중화하기  (0) 2023.05.22
2. [standalone] 인스턴스 추가  (0) 2023.05.22
1. [standalone] 설치  (0) 2023.02.17
0. wildfly / jboss  (0) 2023.02.17