본문 바로가기
시스템/wildfly

우분투22.04 아파치 + wildfly 연동 설정

by cbwstar 2024. 2. 27.
728x90
반응형

1. 우분투 22.04 도커 설치

vim Dockfile

FROM ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Seoul
RUN sed -i 's/kr.archive.ubuntu.com/mirror.kakao.com/g' /etc/apt/sources.list

RUN apt update \
  && apt install -qq -y init systemd \
  && apt install -qq -y build-essential \
  && apt install -qq -y tzdata \
  && apt install -qq -y vim curl telnet net-tools tzdata openssh-server \
  && apt-get clean autoclean \
  && apt-get autoremove -y \
  && rm -rf /var/lib/{apt,dpkg,cache,log}

CMD ["/sbin/init"]

도커 실행 파일 생성

vi docker-build.sh

docker build --tag cbwstar/ubuntu-init:22.04 .
chmod 777 docker-build.sh
./docker-build.sh

 

도커 컨테이너 실행

docker network create --subnet 10.10.0.0/24 --gateway 10.10.0.1 net-cbw


/* 1. 톰캣설치 */
docker run -d --name tomcat9-1 -p 8080:8080 -e TZ=Asia/Seoul -it --privileged=true --hostname tomcat1 --restart no --net net-cbw --ip 10.10.0.10 -v /app/tomcat/webapps:/usr/local/tomcat/webapps tomcat:9.0.76-jdk8-corretto-al2

/* 아파치기동 */
docker run -d --name apache2.4.57 -p 80:80 -it --privileged=true --hostname apache --restart no --net net-cbw --ip 10.10.0.20 -v /app/apache/web:/app/apache/web  cbwstar/apache2:2.4.57 /sbin/init

/* 2. 톰캣설치 */
docker run -d --name tomcat9-2 -p 8081:8080 -e TZ=Asia/Seoul -it --privileged=true --hostname tomcat2 --restart no --net net-cbw --ip 10.10.0.11 -v /app/tomcat/webapps:/usr/local/tomcat/webapps tomcat:9.0.76-jdk8-corretto-al2


/* 톰캣1번서버 */
<Cluster channelSendOptions="8" channelStartOptions="3" className="org.apache.catalina.ha.tcp.SimpleTcpCluster">
  <Manager className="org.apache.catalina.ha.session.DeltaManager" expireSessionsOnShutdown="false" notifyListenersOnReplication="true"/>
 <Channel className="org.apache.catalina.tribes.group.GroupChannel">
  <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
 <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
 </Sender>
 <Receiver
       address="10.10.0.10"           
       autoBind="0" 
                    className="org.apache.catalina.tribes.transport.nio.NioReceiver"
 maxThreads="6" 
 port="4102" 
 selectorTimeout="5000"
  /> <!-- server1 information -->
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor" staticOnly="true"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector" />
<Interceptor className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor">
 <Member                        className="org.apache.catalina.tribes.membership.StaticMember"
    port="4102" 
    host="10.10.0.11"           
    uniqueId="{0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2}"
 /> <!-- tomcat2 connection -->
 </Interceptor>
 <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor" />
  </Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve"                 filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"
   />  
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" />
 </Cluster>

/* 톰캣2번서버 */
<Cluster channelSendOptions="8" channelStartOptions="3" className="org.apache.catalina.ha.tcp.SimpleTcpCluster">
  <Manager className="org.apache.catalina.ha.session.DeltaManager" expireSessionsOnShutdown="false" notifyListenersOnReplication="true" />
 <Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
 <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
  </Sender>
  <Receiver
    address="10.10.0.11"            
    autoBind="0"                           
    className="org.apache.catalina.tribes.transport.nio.NioReceiver"
    maxThreads="6"
    port="4102" 
    selectorTimeout="5000"
  /> <!-- tomcat server2 information -->
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor" staticOnly="true"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector" />
<Interceptor className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor">
<Member                          className="org.apache.catalina.tribes.membership.StaticMember"
  port="4102"
  host="10.10.0.10"           
  uniqueId="{0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,1}"
 /> <!-- tomcat1 server -->
 </Interceptor>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor" />
 </Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"
   />    
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" />
  </Cluster>

 

도커 Wildfly설치

/* 도커 Wildfly 설치 */

docker run -d --name wildfly24.0.1-1 -p 8088:8088 -p 9990:9998 -it --privileged=true --hostname wildfly1 --restart no --net net-cbw --ip 10.10.0.31 -v /app/wildfly/was:/app/wildfly/was  cbwstar/ubuntu-init:22.04 /sbin/init

wget https://download.jboss.org/wildfly/24.0.1.Final/wildfly-24.0.1.Final.tar.gz

/* 자바 1.8설치 */
 apt-get install openjdk-8-jdk
 java -version
 
 which java
 
 readlink -f $(which java)

/* 압축해제 */
 tar xvf wildfly-24.0.1.Final.tar.gz

/app/wildfly-24.0.1.Final/bin/add-user.sh


mkdir sample
cd sample

/* 
cp -r /app/wildfly-24.0.1.Final/standalone/configuration/ ./configuration

docker run -d --name wildfly24.0.1-2 -p 8089:8088 -p 9998:9998 -it --privileged=true --hostname wildfly2 --restart no --net net-cbw --ip 10.10.0.32 -v /app/wildfly/was:/app/wildfly/was  wildfly:24.0.1 /sbin/init

도커 접속

docker ps -a

docker exec -it ubuntu22.04 bash

 

- root 사용자 원격 ssh 접속 허용

vi /etc/ssh/sshd_config

PermitRootLogin yes  # yes로 변경

 

2. 자바 1.8 버전 설치

 apt-get install openjdk-8-jdk
 
 java -version
 
 which java
 
 readlink -f $(which java)

 

3. 아파치 설치 준비

wget http://apache.mirror.cdnetworks.com/apr/apr-1.7.4.tar.gz
wget http://apache.mirror.cdnetworks.com/apr/apr-util-1.6.3.tar.gz
wget https://sourceforge.net/projects/pcre/files/pcre/8.45/pcre-8.45.tar.gz

tar -zxvf apr-1.7.4.tar.gz
tar -zxvf apr-util-1.6.3.tar.gz
tar -zxvf pcre-8.45.tar.gz

apt install build-essential
apt install libexpat1-dev

cd /app/pcre-8.45
./configure --prefix=/usr/local/pcre
make && make install

/* 생성확인 */
ls -al /usr/local/pcre

 

4. 아파치 2.4.57 다운로드

wget https://dlcdn.apache.org/httpd/httpd-2.4.58.tar.gz
tar xvzf httpd-2.4.58.tar.gz

cd httpd-2.4.58
cp -r /app/apr-1.7.4 /app/httpd-2.4.58/srclib/apr
cp -r /app/apr-util-1.6.3 /app/httpd-2.4.58/srclib/apr-util

/* configure 환경 설정 */
./configure --prefix=/usr/local/apache2.4.58 --enable-mods-shared=all --enable-so --enable-rewrite --enable-auth-digest --with-included-apr --with-pcre=/usr/local/pcre/bin/pcre-config

/* 아파치 컴파일 */
make && make install

 

5. 아파치 서버 기동

cd /usr/local/apache2.4.58/conf

vi httpd.conf
206라인 ServerName 127.0.0.1 로 수정후 저장

cd /usr/local/apache2.4.58/bin

/* 아파치 서버기동 */
./apachectl start

기동 확인 
ps -ef |grep httpd

 

6. wildfly 26.1.3.Final  버전설치

wget https://github.com/wildfly/wildfly/releases/download/26.1.3.Final/wildfly-26.1.3.Final.tar.gz

tar xvf wildfly-26.1.3.Final.tar.gz

mkdir domains

관리자 계정 암호를 설정한다.
/app/wildfly-26.1.3.Final/bin/add-user.sh

mkdir sample
cd sample

/* 환경설정 파일 복사 */
cp -r /app/wildfly-26.1.3.Final/standalone/configuration/ ./configuration

vi env.sh

#!/bin/bash

DATE=`date +%Y%m%d%H%M%S`

##### JBOSS Directory Setup #####
export JBOSS_HOME=/app/wildfly-26.1.3.Final
export SERVER_NAME=sample
export DOMAIN_BASE=/app/domains/$SERVER_NAME

export JBOSS_LOG_DIR=$DOMAIN_BASE/logs
export GCLOG=$JBOSS_LOG_DIR/gclog/$SERVER_NAME-gc.log.$DATE
##### Configration File #####
export CONFIG_FILE=standalone-ha.xml

export NODE_NAME=$SERVER_NAME
export PORT_OFFSET=0
CONTROLLER_OFFSET=$PORT_OFFSET
export JBOSS_USER=root

##### Bind Address 서버아이피 입력#####
export BIND_ADDR=192.168.0.2

export MGMT_ADDR=127.0.0.1

export CONTROLLER_IP=$MGMT_ADDR
CONTROLLER_PORT=`expr 9990 + $CONTROLLER_OFFSET`

export CONTROLLER_PORT

export LAUNCH_JBOSS_IN_BACKGROUND=true

##### JBoss System module and User module directory #####
export JBOSS_MODULEPATH=$JBOSS_HOME/modules:$JBOSS_HOME/modules.ext

# 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:+UseParallelGC "
#export JAVA_OPTS=" $JAVA_OPTS -XX:+UseParallelOldGC "
export JAVA_OPTS=" $JAVA_OPTS -XX:+DisableExplicitGC"
export JAVA_OPTS="$JAVA_OPTS -verbose:gc -Xlog:gc:$GCLOG"
export JAVA_OPTS="$JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError"
export JAVA_OPTS="$JAVA_OPTS

-XX:HeapDumpPath=$CATALINA_HOME/$SERVER_NAME-Heapdump.$DATE"
export JAVA_OPTS="$JAVA_OPTS -DjvmRoute=$SERVER_NAME"
export JAVA_OPTS="$JAVA_OPTS -Djava.security.egd=file:/dev/./urandom"

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,com.javaservice"
export JAVA_OPTS=" $JAVA_OPTS -Djava.awt.headless=true"

export JBOSS_BASE_DIR="$DOMAIN_BASE_DIR"

export JAVA_OPTS=" $JAVA_OPTS -Djboss.server.base.dir=$DOMAIN_BASE"
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 -Djboss.bind.address.management=$MGMT_ADDR"
export JAVA_OPTS=" $JAVA_OPTS -Djboss.bind.address=$BIND_ADDR"
export JAVA_OPTS=" $JAVA_OPTS -Djboss.server.log.dir=$JBOSS_LOG_DIR"


# Encoding Setting
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_IP=$CONTROLLER_IP"
echo "CONTROLLER=$CONTROLLER_IP:$CONTROLLER_PORT"
echo "JBOSS_LOG_DIR=$JBOSS_LOG_DIR"
echo "================================================"

 

vi start.sh

#!/bin/bash

DATE=`date +%Y%m%d%H%M%S`

. /app/domains/sample/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 "$JBOSS_LOG_DIR/nohup" ];
then
    echo "nohup log-------------------------------------------"
    mkdir -p $JBOSS_LOG_DIR/nohup
fi

if [ ! -d "$JBOSS_LOG_DIR/gclog" ];
then
    mkdir -p $JBOSS_LOG_DIR/gclog
fi

if [ ! -d "$JBOSS_LOG_DIR/heapdump" ];
then
    mkdir -p $JBOSS_LOG_DIR/heapdump
fi

mv $JBOSS_LOG_DIR/nohup/$SERVER_NAME.out $JBOSS_LOG_DIR/nohup/$SERVER_NAME.out.$DATE

nohup $JBOSS_HOME/bin/standalone.sh -DSERVER=$SERVER_NAME -c $CONFIG_FILE >> $JBOSS_LOG_DIR/nohup/$SERVER_NAME.out &

if [ e$1 = "enotail" ]
then
    echo "Starting... $SERVER_NAME"
    exit;
fi
sleep 3
tail -f $JBOSS_LOG_DIR/server.log

 

vi stop.sh

#!/bin/bash

. /app/domains/sample/env.sh

UNAME=`id -u -n`
if [ e$UNAME != "e$JBOSS_USER" ]
then
    echo "Use $JBOSS_USER account to stop JBoss SERVER - $SERVER_NAME..."

exit;
fi

JPID="`ps -ef | grep java | grep "\-DSERVER=$SERVER_NAME" | awk '{print $2}'`"

if [ -z "$JPID" ]; then
        echo "====================================="
        echo "$SERVER_NAME is not running"
        echo "====================================="
else
#ps -ef | grep java | grep "\-DSERVER=$SERVER_NAME" | awk {'print "kill -9 " $2'} | sh -x

$JBOSS_HOME/bin/jboss-cli.sh  --controller=$CONTROLLER_IP:$CONTROLLER_PORT --connect --commands=shutdown $@

echo "====================================="
echo "$SERVER_NAME is shutdown by $UNAME"
echo "====================================="
fi

 

vi kill.sh

kill -9 `ps -ef|grep sample|grep -v grep|cut -c10-16`

 

vi cli.sh

#!/bin/bash

. /app/domains/sample/env.sh

export JAVA_OPTS=" -Djava.awt.headless=false $JAVA_OPTS"

$JBOSS_HOME/bin/jboss-cli.sh  --controller=$CONTROLLER_IP:$CONTROLLER_PORT --connect $@

실행권한 부여

chmod 777 *.sh

소스배포 경로 지정

cd /app/domains/sample/configuration

vi standalone-ha.xml
529 라인정도
파일업로드 사이즈 1기가로 설정
<server name="default-server">
529                 <ajp-listener name="ajp" max-post-size="1073741824" socket-binding="ajp"/>
530                 <http-listener name="default" socket-binding="http" max-post-size="1073741824" redirect-socket="https" enable-http2="true"/>
531                 <https-listener name="https" socket-binding="https" max-post-size="1073741824" ssl-context="applicationSSC" enable-http2="true"/>
532                 <host name="default-host" alias="localhost">
533                     <location name="/" handler="welcome-content"/>
534                     <http-invoker http-authentication-factory="application-http-authentication"/>
535                 </host>
536             </server>

/* was가 설치된 서버 아이피로 변경하여 준다 */
 <interfaces>
        <interface name="management">
            <inet-address value="${jboss.bind.address.management:192.168.0.2}"/>
        </interface>
        <interface name="private">
            <inet-address value="${jboss.bind.address.private:192.168.0.2}"/>
        </interface>
        <interface name="public">
            <inet-address value="${jboss.bind.address:192.168.0.2}"/>
        </interface>
    </interfaces>


맨아래 소스배포경로 추가

 <deployments>
    <deployment name="sample.war" runtime-name="sample.war">
         <fs-archive path="/app/wildfly/was"/>
     </deployment>
  </deployments>
  <!--이것 바로 위에 -->
  </server>

소스 배포 폴더 생성

mkdir -p /app/wildfly/was
cd /app/wildfly/was

vi index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>index</title>
</head>
<body>
  wildfly web1 테스트
</body>
</html>


vi session.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="java.net.InetAddress" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>SessionTest1</title>
</head>

<body>
<%
     String color = "";
     Integer count = (Integer)session.getAttribute("count");
     if(session.getAttribute("count")==null){
         count = new Integer(1);
     }else{
          count = new Integer(count.intValue()+1);
     }
%>
SessionTest1
<%
session.setAttribute("count",count);
InetAddress iadr = InetAddress.getLocalHost();
out.println("Connect count : "+count+"<BR>");
out.println("<P>");
out.println("<H3>Session Information :</H3>");
out.println("<b>HostName</b> : "+iadr.getHostName()+"<BR>");
out.println("<b>Session ID</b> : "+session.getId() + "<BR>");
out.println("<b>Session Is New</b> : "+session.isNew() + "<BR>");
out.println("<b>Session CreationTime</b> : "+new Date(session.getCreationTime()) + "<BR>");
out.println("<b>Session LastAccessedTime</b> : "+new Date(session.getLastAccessedTime()) + "<BR>");
out.println("<b>Session MaxInactiveInterval(s)</b> : "+session.getMaxInactiveInterval() + "<BR>");
%>
</body>
</html>

mkdir WEB-INF

vi web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd"
        id="WebApp_ID" version="4.0">
        <display-name>test</display-name>
<welcome-file-list>
                <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>


    <error-page>
                <exception-type>java.lang.Throwable</exception-type>
                <location>/common/error.jsp</location>
        </error-page>
        <error-page>
                <error-code>404</error-code>
                <location>/common/error.jsp</location>
        </error-page>
        <error-page>
                <error-code>500</error-code>
                <location>/common/error.jsp</location>
        </error-page>


        <session-config>
        <session-timeout>70</session-timeout>
        <tracking-mode>COOKIE</tracking-mode>
    </session-config>

        <!-- session clustering -->
   <distributable/>
</web-app>

vi jboss-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="
http://www.jboss.com/xml/ns/javaee
      http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
    <context-root>/</context-root>

    <replication-config>
        <replication-trigger>SET</replication-trigger>
        <replication-granularity>SESSION</replication-granularity>
                <use-jk>false</use-jk>
    </replication-config>

</jboss-web>

vi jboss-deployment-structure.xml


<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
        <deployment>
            <exclude-subsystems>
                <subsystem name="logging" />
                <subsystem name="jaxrs" />
                <subsystem name="webservices" />
            </exclude-subsystems>

            <dependencies>
                <module name="javax.xml.ws.api" />
                <module name="javax.jws.api"/>
            </dependencies>

             <exclusions>
               <module name="org.slf4j" />
                <module name="org.slf4j.impl" />
                <module name="org.slf4j.jcl-over-slf4j"/>
                <module name="org.apache.log4j" />
                <module name="org.apache.commons.logging" />
             </exclusions>
        </deployment>
</jboss-deployment-structure>

 

wildfly 환경설정이 끝났다 포트를 8080으로 변경후 재기동한다.

cd /app/domains/sample

vi env.sh

export PORT_OFFSET=8  #8로변경

/* 서버 기동 */
./start.sh

 

7. 아파치 Wildfly 연동

cd /usr/local/apache2.4.58/conf/extra

 

 

 

728x90
반응형

댓글



"이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다."

loading