2017년 4월 2일

CentOS 7.0 에서 아파치 & 톰켓 환경 구축하기

1. 아파치 설치

yum 명령를 사용하여 httpd, httpd-devel 패키지를 설치한다. httpd-devel는 httpd 와 tomcat 연결을 위한 Tomcat Connectors 빌드 & 배포를 위하여 필요한다.

1
yum install httpd

1
yum install httpd-devel


2. 톰켓 설치

톰켓 설치에 앞서 http://www.oracle.com/technetwork/java/javase/downloads/index.html 에서 설치파일을 다운로드하여 JAVA 를 설치한다. 문서에서는 JDK 1.8.0.121 64비트을 사용하였다.

1
2
3
chmod +x jdk-8u121-linux-x64.bin
 
./jdk-8u121-linux-x64.bin
톰켓 설치파일은 http://tomcat.apache.org 에서 최신 소스를 다운로드한다. 설치는 특별한 것을 요구하지 않으며 압축을 풀는 것으로 기본적은 설치는 완료된다. 문서에서는 /app 경로에 압축을 풀었으며 편의상 실재 설치된 경로를 /app/tomcat 경로로 심볼릭 링크를 생성하여 /app/tomcat 경로로 접근이 가능하도하였다. (tomcat 버전을 업데이트하는 경우에 유용하게 사용된다.)

1
2
3
tar -xvf apache-tomcat-8.5.12.tar.gz
mv apache-tomcat-8.5.12/   /app
ln -s /app/apache-tomcat-8.5.12 /app/tomcat

이제 톰켓 실행을 위하여 계정의 프로파일(.bash_profile)을 수정한다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#자바설치위치
export JAVA_HOME= /app/jdk1.8.9_121
 
#톰켓설치 위치
export TOMCAT_HOME=/app/apache-tomcat-8.5.12
 
#자바실행옵션
export JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1024m -Xmx2048m -XX:NewSize=512m -XX:MaxNewSize=512m -XX:+DisableExplicitGC
 
export PATH=$JAVA_HOME/bin:$TOMCAT_HOME/bin:$PATH
 
#편의성을 위한 alias 설정
 
alias tboot='$TOMCAT_HOME/bin/startup.sh'
alias tdown='$TOMCAT_HOME/bin/shutdown.sh'
alias tlog='tail -f $TOMCAT/logs/catalina.out'


프로파일(.bash_profile)을 수정한 다음에는 반듯이 재로그인 또는 . .bash_profile 명령을 사용하여 적용한다.
이제 tboot 명령을 사용하여 tomcat 를 시작한다.

3. 웹 서버 연결을 위한 Tomcat Connectors 설치하기

Tomcat Connector 설치는 컴파일이 필요하며 소스는 http://tomcat.apache.org 에서 다운로한다. 컴파일을 진행하려면 Apr 라이브러리가 필요하며 이런 이유에서 앞서 httpd-devel 패키지를 설치하였다. 컴파일을 위하여 필요한 패키지들은 아래와 같다.


  • httpd
  • httpd-devel
  • gcc
  • libtool


참고로 CentOS 7.6.* 의 경우 apxs 파일이 /usr/bin/apxs 에 있다.

1
2
3
4
5
cd /app/source/tomcat-connectors-1.2.42-src/native
./configure --with-apxs=/usr/sbin/apxs
 
make
make install

정상적으로 설치가 완료되었다면 /etc/httpd/modules 경로에 mod_jk.so 파일이 존재한다.

4. 아파치 웹서버 설정하기

/etc/httpd/conf.d/tomcat.conf 과 workers.properties 파일 만들어 준다.

/etc/httpd/conf.d/tomcat.conf
1
2
3
4
5
LoadModule jk_module modules/mod_jk.so
JkShmFile "run/mod_jk.shm"
JkWorkersFile conf/workers.properties
JkLogFile "logs/mod_jk.log"
JkLogLevel info

/etc/httpd/conf/workers.properties
1
2
3
4
5
worker.list=worker1
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.worker1.lbfactor=1

/etc/httpd/conf.d/vhost.conf 파일 만들어 준다. 본인에 환경에 맞게 수정하여 사용.

/etc/httpd/conf.d/vhost.conf
1
2
3
4
5
6
7
8
NameVirtualHost *:80
 
<virtualhost>
ServerName 서버 아이피 또는 도메인
DocumentRoot 웹 프로그램 루트
JkMountFile conf/uriworkermap.properties
DirectoryIndex index.html index.jsp
</virtualhost>
어떤 요청들을 톰켓으로 전달할 것인가를 정의한는 uriworkermap.properties 생성한다.
/etc/httpd/conf/uriworkermap.properties
1
2
3
/*.do=worker1
/*.jsp=worker1
/logout=worker1

5. 서비스 시작하기

CentOS 7 부터는 서비스 관리를 위하여 Sys V init 를 버리고 Systemd 를 사용한다. 이러한 이유에서 기존 서비스 제어를 위하여 사용되었는 service 명령 대신에 systemctl 을 사용한다. (참고로 service 명령을 사용하면 자동으로 systemctl 명령으로 변경되어 처리됨)

1
systemctl start httpd.service

1
systemctl status httpd.service



httpd 서비스를 자동으로 시작하게 하려면 아래의 명령어를 사용한다.

1
systemctl enable httpd.service

서비스 확인은 아래의 명령을 사용한다.

1
systemctl list-unit-files --type=service | grep httpd



참고자료
How to Install Apache on CentOS 7

댓글 없음:

댓글 쓰기