반응형

## 환경

# Linux 7

# Tomcat 8

# Java 1.8

# Apache 2.2

 

##Tomcat Server.xml 설정

## 경로 : /usr/local/src/tomcat/conf/server.xml

## Port 설정 

# 1. shutdown Port

# 2. connect Port

# 3. ajp Port (세션 공유를 위해 필요) 기본 8009 (방화벽 열려 있음)

# [ajp Port 다른 포트 사용시 SELinux port 개방]

# SELinux Port 명령어 : ./semanage port -a -t http_port_t -p tcp [추가할 포트]

# 방화벽 Port 명령어 :

#[Linux 7] firewall-cmd --permanent --zone=public --add-port=45564/tcp

#[Linux 7] firewall-cmd --permanent --zone=public --add-port=45564/udp

#[Linux 7] firewall-cmd --reload     // 변경

#[Linux 7] firewall-cmd --list-ports // 방화벽 개방 포트 리스트 

#[Linux 7] firewall-cmd --zone=public --list-service // 방화벽 개방 서비스 리스트 

 

# 4. Apach 설치가 되어있음 서비스 및 Port 개방이 되어있음

# HTTP Port (80)

# HTTPS Port (443)

 

# 5. 톰캣 세션 클러스터 Port 개방 명령어

# firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source

# address="xx.xx.xx.xx"   // 현재 서버 IP 주소

# port protocol="tcp"

# port="4001" accept"   // 클러스터 Port 

 

<Engine name="Catalina" defaultHost="localhost" jvmRoute="worker1">

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="6">

<Manager className="org.apache.catalina.ha.session.DeltaManager" expireSessionsOnShutdown="false" notifyListenersOnReplication="true"/>

<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.McastService"
                            address="228.0.0.4"   // 
                               port="45564"       //공유 포트 udp  port 로 개방
                          frequency="500"
                           dropTime="3000"/>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                          address="xx.xx.xx.x"    // 현재 서버 IP 주소
                             port="4001"          // 특정 port 각 서버별 달라야함 (4001 ~ 4010) 보통 처리
                         autoBind="100"
                  selectorTimeout="5000"
                       maxThreads="6"/>
<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>              

<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor"/>
</Channel>          

<Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/>
<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>

<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
                      tempDir="/tmp/war-temp/"
                    deployDir="/tmp/war-deploy/"
                     watchDir="/tmp/war-listen/"
                 watchEnabled="false"/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
      

<Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="false">
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />

<Context path="/" crossContext="true" docBase="/usr/local/src/kpta_client/webapps/ROOT" reloadable="false" sessionCookieDomain=".xxxx.co.kr" // 도메인 설정 .xxxx.co.kr

>
</Context>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t "%r" %s %b" />
</Host>
      

 

 

## HTTP 설정

# 경로 : /etc/httpd/conf/

# 1. httpd.conf 

# httpd.conf backup
# 복사 명령어 : cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.original

## LoadModule foo_module modules/mod_foo.so 주석 밑에 붙여 넣기

# Include conf.modules.d/*.conf                         // 기본으로 작성 되어있음
# LoadModule jk_module modules/mod_jk.so       // 추가 mod_jk 
# Include conf/mod_jk.conf                               // 추가 mod_jk 
# Include conf/extra/httpd-vhosts.conf                // 추가 vhosts 

 

# 2. mod_jk.conf

# 우선 mod_jk.so 파일 /etc/httpd/modules 경로에 파일 추가 

# conf 경로에 vi mod_jk.conf 파일 추가 

<IfModule mod_jk.c>
        JkWorkersFile conf/workers.properties
        JkLogFile /etc/httpd/logs/mod_jk.log
        JkLogLevel info
#        JkAutoAlias "/usr/local/src/tomcat/webapps"
        JkMount /* ajp13
        JkMount /*.jsp ajp13
        JkMount /servlet/* ajp13
        JkMount /examples/*.jsp ajp13
        JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
        JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
        JkRequestLogFormat "%w %V %T"
        JkMountFile conf/uri.properties
</IfModule mod_jk.c>

 

# 3. uri.properties

# conf 경로에 uri.properties 파일 추가 

/*=worker1 

# 4. workers.propertis

# conf 경로에 workers.properties 파일 추가 

worker.list=lb1, jkstatus

 

#현재 서버 정보 

#ajp Port/ host 설정
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.worker1.lbfactor=1
#다른 서버 정보 
worker.worker3.port=8009
worker.worker3.host=xx.xx.xx.xx
worker.worker3.type=ajp13
worker.worker3.lbfactor=1
worker.lb1.type=lb
worker.lb1.balance_workers=worker1,worker3

## status worker
worker.jkstatus.type=status

 

# 5. extra/httpd-vhosts.conf

# conf/extra 경로 httpd-vhosts.conf 파일 생성

 

#Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any  block.
#
#NameVirtualHost *:80

 

 

# 현재 서버 tomcat 

<VirtualHost *:80>
#   ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/usr/local/src/tomcat/webapps"
    ServerName www.xxx.co.kr
    ServerAlias www.xxx.co.kr
    ErrorLog /etc/httpd/logs/centerhost.error_logs
#   CustomLog "logs/dummy-host.example.com-access_log" common
    JkMount /* lb1
    <Directory "/usr/local/src/tomcat/webapps">
        AllowOverride None
        Require all granted
</VirtualHost *:80>  

 

# 다른 서버 tomcat 

<VirtualHost *:80>
#   ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/usr/local/src/tomcat/webapps"
    ServerName xxx.co.kr
    ServerAlias xxx.co.kr
    ErrorLog /etc/httpd/logs/centerhost.error_logs
#   CustomLog "logs/dummy-host.example.com-access_log" common
    JkMount /*
lb1
    <Directory "/usr/local/src/tomcat/webapps">
        AllowOverride None
        Require all granted
</VirtualHost *:80>     


 

 

 

 

반응형

서비스 파일 경로

/etc/init.d

 

서비스 등록할 파일 생성

vi xxxxx

 

서비스 등록

#!/bin/bash
#
# tomcat
#
# chkconfig: 345 96 30
# description:  Start up the Tomcat servlet engine.
#
# processname: java
# pidfile: /var/run/tomcat.pid
#
### BEGIN INIT INFO
# Provides: tomcat
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Should-Start: distcache
# Short-Description: start and stop Apache HTTP Server
# Description: implementation for Servlet 2.5 and JSP 2.1
## END INIT INFO
 
# Source function library.
. /etc/init.d/functions
 
## tomcat installation directory

##프로세스 명
PROCESS_NAME=tomcat

## 등록할 서비스 경로
CATALINA_HOME="/usr/local/usr/tomcat/"
 
## run as a diffent user
#TOMCAT_USER=root
 
##  Path to the pid, runnning info file
pidfile=${PIDFILE-/var/run/${PROCESS_NAME}.pid};
lockfile=${LOCKFILE-/var/lock/subsys/${PROCESS_NAME}};
 
RETVAL=0
 
case "$1" in
 start)
        PID=`pidofproc -p ${pidfile} ${PROCESS_NAME}`
        if [[ (-n ${PID}) && ($PID -gt 0) ]]; then
                logger -s "${PROCESS_NAME}(pid ${PID}) is  already running."
                exit;
        fi
        if [ -f $CATALINA_HOME/bin/startup.sh ];
          then
            logger -s "Starting Tomcat"
            /bin/su -l ${TOMCAT_USER} -c "$CATALINA_HOME/bin/startup.sh -Dprocessname=${PROCESS_NAME}"
            PID=`ps -eaf|grep processname=${PROCESS_NAME}|grep -v grep|awk '{print $2}'`
            RETVAL=$?
            [ $RETVAL = 0 ] && touch ${lockfile}
            [ $RETVAL = 0 ] && echo "${PID}" > ${pidfile}
        fi
        ;;
 stop)
        PID=`pidofproc -p ${pidfile} ${PROCESS_NAME}`
        ## if PID valid run shutdown.sh
        if [[ -z ${PID} ]];then
            logger -s "${PROCESS_NAME} is not running."
            exit;
        fi
 
        if [[ (${PID} -gt 0) && (-f $CATALINA_HOME/bin/shutdown.sh) ]];
          then
            logger -s "Stopping Tomcat"
            /bin/su -l ${TOMCAT_USER} -c "$CATALINA_HOME/bin/shutdown.sh"
            RETVAL=$?
            [ $RETVAL = 0 ] && rm -f ${lockfile}
            [ $RETVAL = 0 ] && rm -f ${pidfile}
        fi
        ;;
 status)
        status -p ${pidfile} ${PROCESS_NAME}
        RETVAL=$?
        ;;
 restart)
         $0 stop
         $0 start
         ;;
version)
        if [ -f $CATALINA_HOME/bin/version.sh ];
          then
            logger -s "Display Tomcat Version"
            /bin/su -l ${TOMCAT_USER} -c "$CATALINA_HOME/bin/version.sh"
            RETVAL=$?
        fi
        ;;
 *)
         echo $"Usage: $0 {start|stop|restart|status|version}"
        exit 1
        ;;
esac
exit $RETVAL

 

 

 

#서비스 명령어

#서비스 등록

service xxxxx start

#서비스 재시작

service xxxxx restart

#서비스 중지

service xxxxx stop

#서비스 변경

service xxxxx reload

#서비스 상태

service xxxxx status

#서비스 자동시작 활성화

chkconfig xxxxx on

#서비스 자동시작 비활성화

chkconfig sshd off

#서비스 자동시작 활성화 여부

chkconfig --list xxxxx

'Linux' 카테고리의 다른 글

Linux 7.x 서비스 등록  (0) 2019.12.30
WAS & APACHE & open PORT  (0) 2019.11.22
포트 및 방화벽  (0) 2018.07.09
리눅스 find 명령어  (0) 2018.07.09
반응형

서비스 파일 경로 

/usr/lib/systemd/system

 

서비스 등록할 파일 생성

vi xxxx.service 

 

서비스 등록

[Unit]
Description=kpta_client
After=network.target syslog.target

[Service]
Type=forking
#자바 설치 경로 
Environment="JAVA_HOME=/usr/local/java/jdk1.8.0_111/"

#유저 계정/그룹 계정 
User=root
Group=root

UMask=0007
RestartSec=10
Restart=always

SuccessExitStatus=143
#Start/Shutdown Shell 파일 경로
ExecStart=/usr/local/src/tomcat/bin/startup.sh
ExecStop=/usr/local/src/tomcat/bin/shutdown.sh

[Install]
WantedBy=multi-user.target

 

 

 

서비스 등록 명령어

#서비스 파일 명

 

#서비스 활성화(부팅시 자동 구동)

systemctl enable center.service 

#서비스 비활성화

systemctl disable center.service 

#서비스 활성화 여부

systemctl status xxxxxx.service

#서비스 시작

systemctl start xxxxxx.service

#서비스 중지

systemctl stop xxxxxx.service

#서비스 재구동

systemctl reload xxxxxx.service

 

#서비스 자동 활성화 여부

systemctl is-enabled xxxxx

 

#프로세스 확인

ps -ef | grep xxxxx

 

 

 

 

 

 

'Linux' 카테고리의 다른 글

Linux 6.x 서비스 등록  (0) 2019.12.30
WAS & APACHE & open PORT  (0) 2019.11.22
포트 및 방화벽  (0) 2018.07.09
리눅스 find 명령어  (0) 2018.07.09

+ Recent posts