![](https://t1.daumcdn.net/cfile/tistory/999A253F5BFB420016)
Apache - Tomcat 연동 설명해 드리겠습니다.
환경 : CentOS
Linux release 7.5.1804 (Core)
1. 환경을 구성하자.
일단 Apache Tomcat 연동을 위하여
설치 툴들을 linux환경에 적용하기 위하여 yum을 이용하겠습니다.
명령어는 아래와 같습니다.
:
yum install -y gcc gcc-c++ httpd-devel
wget libtool make
java도 설치하자 .
https://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html
들어가서 Linux버전 다운로드 한 뒤에
파일질라 이용해서 특정 경로에다가 설치
2. Tomcat8 설치
: http://tomcat.apache.org/에 접속하셔서 톰캣 8 최신버전 다운로드
아래 명령어로 실행
mv apache-tomcat-8.5.24.tar.gz ${
설치경로
}
tar zxvf apache-tomcat-8.5.24.tar.gz
3. 톰캣 서비스 파일 생성
vim /etc/systemd/system/tomcat.service
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target
[Service]
Type=forking
Environment=JAVA_HOME=${자바설치경로}
Environment=CATALINA_PID=${톰캣설치경로}/tomcat.pid
Environment=CATALINA_HOME=${톰캣설치경로}
Environment=CATALINA_BASE=${톰캣설치경로}
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true '
ExecStart=${톰캣설치경로}/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID
User=${계정이름}
Group=${계정그룹}
UMask=0007
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target
$로 표시되는 것은 설치할 서버의 상대적인 값입니다.
4. Apache - tomcat 연동 (mod_jk)
: 아파치와 톰캣
연동은 mod_jk를 이용 (tomcat-connectors의 버전이 상이 할수 있음.)
wget http://apache.mirror.cdnetworks.com/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.44-src.tar.gz
tar zxvf tomcat-connectors-1.2.44-src.tar.gz
cd tomcat-connectors-1.2.44-src/native/
./buildconf.sh
./configure --with-apxs=/usr/bin/apxs
make
make install
리눅스 버전에 따라 apxs의 위치가 다를 수 있음.
5. 연동 설정
cd /etc/httpd/conf.modules.d/
vim 00-jk.conf
여기서 아래 코드를 추가해주면 됩니다.
LoadModule jk_module modules/mod_jk.so
설정파일을 만듭시다.
cd /etc/httpd/conf.d/
vim httpd-jk.conf
--------------------------------------------------------------------
<IfModule jk_module>
# We need a workers file exactly once
# and in the global server
JkWorkersFile conf.d/workers.properties
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# Our JK error log
# You can (and should) use rotatelogs here
JkLogFile logs/mod_jk.log
# Our JK log level (trace,debug,info,warn,error)
JkLogLevel info
# Our JK shared memory file
JkShmFile logs/mod_jk.shm
# If you want to put all mounts into an external file
# that gets reloaded automatically after changes
# (with a default latency of 1 minute),
# you can define the name of the file here.
JkMountFile conf.d/uriworkermap.properties
JkMount /* instance1
</IfModule>
----------------------------------------------------------------------
worker를 만듭시다.
cd /etc/httpd/conf.d/
vim workers.properties
Ex)
worker.list=instance1
worker.instance1.port=8009
worker.instance1.host=localhost
worker.instance1.type=ajp13
worker.instance1.lbfactor=1
특정파일에 대한 톰캣처리를 하여 톰캣설정 변경을 위해 재시작하지 않아도 됨.
vim uriworkermap.properties
/*.jsp=instance1
/*.png=instance1
/*.css=instance1
6. 서비스 재시작
service httpd restart
service tomcat restart
7. 서비스 확인
http://${서버IP주소}/로 접속하였을 때 apache index페이지가 아닌 톰캣 index페이지가 나오면 완료!
아파치의 포트는 80, 톰캣의 포트는 8080입니다. 두 서버를 연동하였기 때문에
http://localhost 를 입력하였을때 톰캣 웹루트의 index.jsp가 떠야 합니다.
톰캣의 웹루트가 떴으면, 일단 apache-tomcat연동은 완료된 것입니다.
8. 서비스 종료/시작/재시작
service httpd stop/start/restart
service tomcat stop/start/restart
9. 소스 Deploy
: 저는 인텔리제이를 IDE로 쓰고, maven에서 install 시에 war파일로 배포하도록 설정했습니다.
![](https://t1.daumcdn.net/cfile/tistory/99BFC2395BFB487526)
배포된 war파일을 개발서버 특정경로에 푼뒤
tomcat폴더에 conf에 있는 server.xml에 해당 context를 추가해줍니다.
<Context docBase="${application 경로}"
path="/" reloadable="true"/>
그런뒤 톰캣을 재기동하고 웹 소스를 확인하면 됩니다.