자바 웹 애플리케이션에 대한 로깅은 중요한 일이다. 웹 애플리케이션이 어떻게 동자하는지를 잘 알아야 하는데, 그 방법이 로깅이기 때문이다. 하지만 웹 애플리케이션의 로깅을 변경할 경우에 대부분 웹 애플리케이션을 배포한다. 물론 배포를 하지 않고도 가능하지만, 대부분 배포를 다시 하게 된다. JBoss 에서는 배포를 하지 않고 jboss-cli 를 통해서 런타임으로 설정이 가능하다. ]$ /app/wildfly/bin/jboss-cli.sh –connect –controller=192.168.96.7:8080 [standalone@192.168.96.7:8080 /] 만일, 인증을 설정했다면 ID/Password 를 입력해야 한다. logging Subsystem Jboss 는 JEE 스펙을 구현한 서버이다. JEE 스펙을 각각 Subsystem 으로 구현해놨다. Subsystem 으로 모듈화를 해놨기 […]
JBOSS EAP 6 Standalone 환경 구성하기
JBOSS EAP 6 설치를 끝내고 나면 Standalone 이나 Domain 모드로 운영하기 위한 환경 구성을 해야 한다. JBOSS EAP 6 Standalone 환경 구성은 설치한 JBOSS 에서 Standalone 디렉토리를 복사해서 구성하게 된다. JBOSS 를 설치는 JBOSS_HOME 을 설치하는 것이다. 이것 자체로 서버를 운영할수 있지만 이것을 GLOBAL 로 하고 각각의 운영위한 서버는 JBOSS_HOME 에 Standalone, Domain 디렉토리를 복사하고 Localize 해서 만들어진다. 이는 마치 Tomcat 의 Multi Instance 구성하기와 유사하다. 기본환경 먼저 기본적인 환경을 체크하고 넘어가자. 다음과 같다. Linux: CentOS 6, 7 JAVA_HOME: /opt/jdk1.8.0_91 JBOSS_HOME: […]
JBoss EAP 6.4 설치
JBoss EAP 6.4 설치 JBoss EAP 6.4 설치에 대해 다룬다. JBoss EAP 6.4 설치는 GUI와 Text 기반 설치 두가지를 지원 한다. 여기서는 Linux 터미널에서 Text 기반 설치에 대해서 다룬다. 사전준비 JBoss EAP 6.4 를 설치하기 위해서는 JDK 1.7 이상 필요하다. JDK 1.6도 지원한다고 되어 있지만 현시점(2016. 06) 에서 1.6은 너무나 구형이라 권장하지 않는다. 설치를 위해서는 설치 파일이 필요한데, zip 파일과 installer 파일 형태로 제공된다. zip 파일은 그냥 압축해제하면 되지만 installer 는 인스톨 과정을 거쳐야 한다. 여기서는 installer를 이용한 설치에 대해서만 […]
JBoss 5 MySQL Replication 접속
만일 MySQL 이 Replication 되어 있다고 한다면 Master 는 read/write 를 Slave 는 read Only 만 하도록 접속을 하고 싶을 것이다. MySQL Connector/J 의 최신버전은 이러한 접속을 지원 한다. 다음은 MySQL Replication 접속을 위한 mysql-ds.xml 예제다.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<?xml version="1.0" encoding="UTF-8"?> <!-- $Id: mysql-ds.xml 41017 2006-02-07 14:26:14Z acoliver $ --> <!-- Datasource config for MySQL using 3.0.9 available from: http://www.mysql.com/downloads/api-jdbc-stable.html --> <datasources> <!-- mysql DS --> <local-tx-datasource> <jndi-name>MySQLDS</jndi-name> <connection-url>jdbc:mysql:replication://address=(protocol=tcp)(host=192.168.96.31)(port=3306)(type=master),address=(protocol=tcp)(host=192.168.96.30)(port=3306)(type=slave)/spring?useUnicode=true&characterEncoding=UTF-8&autoReconnect=false&useSSL=false&failOverReadOnly=true&loadBalanceStrategy=random&readFormMasterNoSlaves=true</connection-url> <driver-class>com.mysql.jdbc.ReplicationDriver</driver-class> <user-name>spring</user-name> <password>12345</password> <min-pool-size>5</min-pool-size> <max-pool-size>50</max-pool-size> <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name> <!-- should only be used on drivers after 3.22.1 with "ping" support --> <!-- <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name> --> <!-- sql to call when connection is created <new-connection-sql>some arbitrary sql</new-connection-sql> --> <!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql> --> <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) --> <metadata> <type-mapping>mySQL</type-mapping> </metadata> </local-tx-datasource> </datasources> |
‘connection-url’, ‘driver-class’ 을 유심히 봐야 한다. mysql-ds 에서의 설정은 MySQL 의 접속을 이중으로 하도록만하고 실제 쿼리를 분기하기 위해서는 DAO 에서 @Transactional(readOnly=true) 를 주어야 한다. 이 어노테이션은 읽기만을 하다는 것을 알려주고 이는 MySQL Slave 에 접속하게 된다. 각 메소드마다 어노테이션을 주기 싫다면 AOP 를 […]
JBoss EAP 5 MySQL JNDI 설정
JNDI 는 자바 애플리케이션 서버라면 거의 다 지원하는 기능이다. 이는 특정한 자원의 접근을 디렉토리 접근하듯이 하도록 해준다. 여기서 자원이라면 대부분 외부 서버에 있는 저장소들을 말한다. MySQL, PostgreSQL, Oracle, MS SQL 등 외부 저장소에 접속할때마다 저수준의 드라이버를 올리고 인증을 넣는게 아니라 자바 애플리케이션이 구동되면서 접속하을 해놓고 이것을 디렉토리화해서 올려놓으면 자바 애플리케이션에서는 이 디렉토리에 접근하는 것만으로 외부자원에 접속이 끝이 나게 되어 간편해진다. 이 글은 JBoss EAP 5 MySQL JNDI 설정에 관한 글이다. MySQL Connector/j MySQL에서는 자바 애플리케이션을 위해서 접속 드라이버를 제공한다. jar […]
Ubuntu 14.04 의 JBoss EAP 5.2 init 스크립트
JBoss EAP 5.2 를 Ubuntu 14.04 에서 운영할 경우에 서비스 시작을 init 에 등록하기 위한 스크립트. Wildfly 에 내용을 가지고 와서 마이그레이션 했다.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
#!/bin/bash # # /etc/init.d/jboss-SvrAPI01 -- startup script for jboss of SvrAPI01 # # NAME="systemV" DEFAULT="/opt/jboss/domains/${NAME}/jboss-env.sh" DESC="Jboss EAP 5.2 Application Server for $NAME" # clear work and tmp dirs? CLEAR_WORK_TMP="Y" HOST_NAME=`/sbin/ifconfig ens3|grep 'inet addr:'|awk '{print $2}'|awk -F : '{print $2}'` # Check privilege if [ `id -u` -ne 0 ]; then echo "You need root privileges to run this script" exit 1 fi # Make sure wildfly is started with system locale if [ -r /etc/default/locale ]; then . /etc/default/locale export LANG fi . /lib/lsb/init-functions if [ -r /etc/default/rcS ]; then . /etc/default/rcS fi # Overwrite settings from default file if [ -f "$DEFAULT" ]; then . "$DEFAULT" fi # Setup the JVM if [ -z "$JAVA" ]; then if [ -n "$JAVA_HOME" ]; then JAVA="$JAVA_HOME/bin/java" else JAVA="java" fi fi # Check if wildfly is installed if [ ! -f "$JBOSS_HOME/bin/run.jar" ]; then log_failure_msg "$NAME is not installed in \"$JBOSS_HOME\"" exit 1 fi # Run as wildfly user # Example of user creation for Debian based: # adduser --system --group --no-create-home --home $JBOSS_HOME --disabled-login wildfly if [ -z "$JBOSS_USER" ]; then JBOSS_USER=sbhyun fi # Check wildfly user id $JBOSS_USER > /dev/null 2>&1 if [ $? -ne 0 -o -z "$JBOSS_USER" ]; then log_failure_msg "User \"$JBOSS_USER\" does not exist..." exit 1 fi # Check owner of JBOSS_HOME if [ ! $(stat -L -c "%U" "$JBOSS_HOME") = $JBOSS_USER ]; then log_failure_msg "The user \"$JBOSS_USER\" is not owner of \"$JBOSS_HOME\"" exit 1 fi # The amount of time to wait for startup if [ -z "$STARTUP_WAIT" ]; then STARTUP_WAIT=120 fi # The amount of time to wait for shutdown if [ -z "$SHUTDOWN_WAIT" ]; then SHUTDOWN_WAIT=120 fi # Location to keep the console log if [ -z "$JBOSS_CONSOLE_LOG" ]; then JBOSS_CONSOLE_LOG="$SERVER_HOME/$SERVER_NAME/log/console.log" fi export JBOSS_CONSOLE_LOG touch $JBOSS_CONSOLE_LOG chown $JBOSS_USER $JBOSS_CONSOLE_LOG # Location to set the pid file JBOSS_PIDFILE="$SERVER_HOME/$SERVER_NAME/run/$SERVER_NAME.pid" export JBOSS_PIDFILE # Launch Jboss in background LAUNCH_JBOSS_IN_BACKGROUND=1 export LAUNCH_JBOSS_IN_BACKGROUND function cleanWorkTmp() { # clean tmp and work dirs echo "clean work and tmp dirs from ${SERVER_NAME}..." rm -Rf "${SERVER_HOME}/${SERVER_NAME}/work" rm -Rf "${SERVER_HOME}/${SERVER_NAME}/tmp" } function jbossPID() { # try get the JVM PID local jbossPID="x" jbossPID=$(ps -eo pid,cmd | grep "org.jboss.Main" | grep "${DOMAIN_IP}" | grep "${SERVER_NAME}" | grep -v grep | cut -c1-6) echo "$jbossPID" } # Helper function to check status of Jboss service check_status() { pidofproc -p "$JBOSS_PIDFILE" "$JAVA" >/dev/null 2>&1 } START_SCRIPT="$JBOSS_HOME/bin/run.sh" SHUTDOWN_SCRIPT="$JAVA -classpath $JBOSS_HOME/bin/shutdown.jar:$JBOSS_HOME/client/jnet.jar org.jboss.Shutdown --shutdown -s jnp://$DOMAIN_IP:$JNP_PORT -u $JBOSS_ADMIN_USER -p $JBOSS_ADMIN_PWD" case "$1" in start) log_daemon_msg "Starting $DESC" log_daemon_msg "instance $SERVER_NAME at $DOMAIN_IP ..." check_status status_start=$? if [ $status_start -eq 3 ]; then mkdir -p $(dirname "$JBOSS_PIDFILE") mkdir -p $(dirname "$JBOSS_CONSOLE_LOG") cat /dev/null > "$JBOSS_CONSOLE_LOG" su -l $JBOSS_USER -c "source $DEFAULT; $START_SCRIPT $JBOSS_OPTS --host $HOST_NAME -c $SERVER_NAME -b $DOMAIN_IP > ${JBOSS_CONSOLE_LOG} 2>&1 &" count=0 launched=0 until [ $count -gt $STARTUP_WAIT ] do grep 'Started in' "$JBOSS_CONSOLE_LOG" > /dev/null if [ $? -eq 0 ] ; then launched=1 break fi sleep 1 count=$((count + 1)); done if [ $launched -eq 1 ] ; then echo `jbossPID` > $JBOSS_PIDFILE chown $JBOSS_USER $(dirname "$JBOSS_PIDFILE") || true fi if check_status; then log_end_msg 0 else log_end_msg 1 fi if [ $launched -eq 0 ]; then log_warning_msg "$DESC hasn't started within the timeout allowed" log_warning_msg "please review file \"$JBOSS_CONSOLE_LOG\" to see the status of the service" fi elif [ $status_start -eq 1 ]; then log_failure_msg "$DESC is not running but the pid file exists" exit 1 elif [ $status_start -eq 0 ]; then log_success_msg "$DESC (already running)" fi ;; stop) check_status status_stop=$? if [ $status_stop -eq 0 ]; then read kpid < "$JBOSS_PIDFILE" log_daemon_msg "Stopping $DESC" su -l $JBOSS_USER -c "source $DEFAULT; $SHUTDOWN_SCRIPT" count=0 until [ $count -gt $SHUTDOWN_WAIT ] do if ! check_status; then break fi sleep 1 count=$((count + 1)); done if check_status; then kill -9 $kpid fi if [ "$CLEAR_WORK_TMP" = "Y" ]; then cleanWorkTmp fi rm "$JBOSS_PIDFILE" log_end_msg 0 elif [ $status_stop -eq 1 ]; then log_action_msg "$DESC is not running but the pid file exists, cleaning up" rm -f $JBOSS_PIDFILE elif [ $status_stop -eq 3 ]; then log_action_msg "$DESC is not running" fi ;; restart) check_status status_restart=$? if [ $status_restart -eq 0 ]; then $0 stop fi $0 start ;; status) check_status status=$? if [ $status -eq 0 ]; then read pid < $JBOSS_PIDFILE log_action_msg "$DESC is running with pid $pid" exit 0 elif [ $status -eq 1 ]; then log_action_msg "$DESC is not running and the pid file exists" exit 1 elif [ $status -eq 3 ]; then log_action_msg "$DESC is not running" exit 3 else log_action_msg "Unable to determine $NAME status" exit 4 fi ;; *) log_action_msg "Usage: $0 {start|stop|restart|reload|force-reload|status}" exit 2 ;; esac exit 0 |
아래는 jboss-env.sh 의 내용.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
#!/bin/sh # jboss-env.sh - starts a new shell with instance variables set ## set jboss base env export JBOSS_HOME="/opt/jboss/jboss-as" export SERVER_HOME="/opt/jboss/domains" export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/jboss/lib" export JBOSS_USER=sbhyun export SERVER_NAME=systemV export DOMAIN_IP=0.0.0.0 export JNP_PORT=1199 export JAVA_HOME=/opt/java export CLASSPATH=.:/opt/java/jre/lib export PATH=$JAVA_HOME/bin:$JBOSS_HOME/bin:$PATH # JMX Credentials JMX_CREDETIALS_FILE="$SERVER_HOME/$SERVER_NAME/conf/props/jmx-console-users.properties" JMX_USER=$(cat $JMX_CREDETIALS_FILE | grep -v '#' | cut -d '=' -f 1 | head -n 1) JMX_PWD="$(cat $JMX_CREDETIALS_FILE | grep -v '#' | cut -d '=' -f 2 | head -n 1 | tr -d '\r')" JBOSS_ADMIN_USER=${JMX_USER:-"admin"} JBOSS_ADMIN_PWD=${JMX_PWD:-"admin"} if [ "x$JBOSS_OPTS" = "x" ]; then JBOSS_OPTS="-Dserver=$SERVER_NAME" JBOSS_OPTS="$JBOSS_OPTS -Djboss.server.base.dir=$SERVER_HOME" JBOSS_OPTS="$JBOSS_OPTS -Djboss.server.base.url=file://$SERVER_HOME" JBOSS_OPTS="$JBOSS_OPTS -Djboss.server.log.dir=$SERVER_HOME/$SERVER_NAME/log" #JBOSS_OPTS="$JBOSS_OPTS -Djboss.server.log.threshold=DEBUG" JBOSS_OPTS="$JBOSS_OPTS -Djboss.messaging.ServerPeerID=2" JBOSS_OPTS="$JBOSS_OPTS -Djboss.service.binding.set=ports-01" JBOSS_OPTS="$JBOSS_OPTS -Djboss.partition.name=systemV" JBOSS_OPTS="$JBOSS_OPTS -Djboss.default.jgroups.stack=tcp" JBOSS_OPTS="$JBOSS_OPTS -Djboss.jgroups.tcp.tcpping.initial_hosts=192.168.96.30[7700],192.168.96.31[7701]" JBOSS_OPTS="$JBOSS_OPTS -Djboss.jgroups.tcp.tcp_port=7600" JBOSS_OPTS="$JBOSS_OPTS -Djboss.jgroups.bind.address=192.168.96.30" #JBOSS_OPTS="$JBOSS_OPTS -Djgroups.bind_addr=228.2.2.2" #JBOSS_OPTS="$JBOSS_OPTS -Djboss.jgroups.tcp.tcp_port=7600" #JBOSS_OPTS="$JBOSS_OPTS -Djboss.partition.udpGroup=228.2.2.2" #JBOSS_OPTS="$JBOSS_OPTS -Djboss.hapartition.mcast_port=44552" fi if [ "x$JAVA_OPTS" = "x" ]; then JAVA_OPTS="-server" JAVA_OPTS="$JAVA_OPTS -noverify" JAVA_OPTS="$JAVA_OPTS -Xms512m" JAVA_OPTS="$JAVA_OPTS -Xmx512m" JAVA_OPTS="$JAVA_OPTS -XX:PermSize=128m" JAVA_OPTS="$JAVA_OPTS -XX:MaxPermSize=128m" #JAVA_OPTS="$JAVA_OPTS -Xss128k" JAVA_OPTS="$JAVA_OPTS -verbose:gc" JAVA_OPTS="$JAVA_OPTS -Xloggc:$SERVER_HOME/$SERVER_NAME/gclog/gc.log" JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDetails" JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCTimeStamps" JAVA_OPTS="$JAVA_OPTS -XX:+PrintHeapAtGC" JAVA_OPTS="$JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError" JAVA_OPTS="$JAVA_OPTS -XX:HeapDumpPath=$SERVER_HOME/$SERVER_NAME/gclog/java_pid.hprof" # JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote" # JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=8286" # JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false" # JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=false" JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true" JAVA_OPTS="$JAVA_OPTS -Dsun.rmi.dgc.client.gcInterval=3600000" JAVA_OPTS="$JAVA_OPTS -Dsun.rmi.dgc.server.gcInterval=3600000" JAVA_OPTS="$JAVA_OPTS -Dsun.lang.ClassLoader.allowArraySyntax=true " fi export JBOSS_OPTS JAVA_OPTS |
TCP 기반 JBoss 5 Clustering 하기
AWS EC2 에서 JBoss EAP 5.2 를 설치하고 운영할때에 보통 클러스터링을 설정하게 된다. 문제는 JBoss EAP 5.2 에서 클러스터링은 JGroup 을 기반으로 작성되어 있다. 중요한 것은 클러스터링을 할때에 Multicast UDP 를 사용한다는 것인데, AWS EC2 에서는 Multicast 자체를 지원하지 않는다. 따라서 JBoss EAP 5.2 를 AWS EC2 에서 운영하면서 클러스터링을 기본 설정값으로 설정하고 실행시키면 클러스터링이 되지 않는다. 이럴때 TCP 를 이용하면 가능해진다. 이 포스트는 AWS EC2 에서 TCP 기반 JBoss Clustering 에 관련된 내용이다. MPING을 TCPPING으로 바꾸기 Cluster 의 프로토콜 […]