Tomcat도 단독으로 서비스를 할 수 있으나 Apache와 연동하여 사용하는 경우가 많다.
Apache와 연동하여 사용하는 이유
- 정적 콘텐츠의 서비스 속도(이미지 동영상의 경우 Apache가 빠름)
- 여러 대의 Apache와 Tomcat서버의 클러스터링 구성
- Apache 웹서버의 다양한 모듈 확장
- 보안 강화
1. mod_jk 설치
- c 컴파일러 설치 안 돼있을 경우
$ yum install gcc gcc-c++ httpd-devel
위 명령어를 사용하여 3가지 패키지를 모두 설치
tomcat.apache.org/download-connectors.cgi
Apache Tomcat® - Tomcat Connectors (mod_jk) Downloads
You must verify the integrity of the downloaded files. We provide OpenPGP signatures for every release file. This signature should be matched against the KEYS file which contains the OpenPGP keys of Tomcat's Release Managers. We also provide SHA512 checksu
tomcat.apache.org
위 주소에서 최신 다운로드 파일 링크 확인
링크 주소 복사 후
$ wget -c [링크주소]
위 명령어 실행
ex) wget -c apache.tt.co.kr/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.46-src.tar.gz
받고 나서 압축 풀기
$ tar zxvf tomcat-connectors-1.2.46-src.tar.gz
native 경로로 이동
$ cd tomcat-connectors-1.2.46-src/native
Apache확장 기능 설치를 도와주는 유틸리티 확인
apxs 경로를 찾는다(설치되어있는지 확인)
$ find / -name 'apxs'
없을 경우
$ yum install httpd=devel
Makefile을 생성하기 위해 아래 명령어 실행
위에서 나온 경로를 입력한다
$ ./configure --with-apxs=/usr/bin/apxs
native 폴더에서
$ make
컴파일 완료 후
$ make install
- install 후 /etc/httpd/modules/ 경로의 파일 안에 mod_jk.so 파일이 생성된다
- Selinux 보안 관련 설정 변경
$ chcon -u system_u -r object_r -t httpd_modules_t /etc/httpd/modules/mod_jk.so
- 제대로 적용 안될 경우
$ sestatus selinux //selinux 확인
//비활성화 되어 있음 disabled
$ vi /etc/sysconfig/selinux
disabled -> enforcing 으로 변경
재부팅 reboot
$ vi /etc/httpd/conf/httpd.conf
보안 추가
ServerTokens Prod
ServerSignature Off
TraceEnable Off
2. Apache 설정
- httpd.conf 파일 수정
$ vi /etc/httpd/conf/httpd.conf
...
LoadModule jk_module modules/mod_jk.so
Include conf.modules.d/*.conf
<VirtualHost *:80>
DocumentRoot "[설정할 tomcat 프로젝트 경로]"
ServerName localhost
DirectoryIndex index.jsp
JkMount /*.jsp tomcat
JkMount /*.do tomcat
</VirtualHost>
...
- 새로운 설정 파일 추가
$ vi /etc/httpd/conf.modules.d/mod_jk.conf
<IfModule mod_jk.c>
JkWorkersFile conf/workers.properties
JkShmFile run/mod_jk.shm
JkLogFile logs/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%y %m %d %H:%M:%S] "
</IfModule>
- mod_jk.conf 에서 설정한 워커 설정파일 추가
$ vi /etc/httpd/conf/workers.properties
workers.tomcat_home=/usr/local/tomcat
worker.list=worker1
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.worker1.lbfactor=1
- httpd.conf 디렉터리 권한 추가
DocumentRoot "[설정할 tomcat 프로젝트 경로]"
<Directory "[설정할 tomcat 프로젝트 경로]">
AllowOverride none
Require all granted
</Directory>
- selinux 설정 추가
$ chcon -R --type=httpd_sys_rw_content_t [설정할 tomcat 프로젝트 경로]
설정 후 http://아이피/index.jsp로 들어갔을 때 8080 포트로 들어간 것과 같이 Tomcat 화면이 뜬다면 제대로 연동 작업이 완료된 것이다.
'Linux > Linux(CentOS)' 카테고리의 다른 글
[Linux] rsync 사용하여 원격 파일, 디렉토리 복사하기 (0) | 2021.07.20 |
---|---|
[Linux] Apache Reverse Proxy 사용 포트포워딩 설정하기 (0) | 2021.04.26 |
[Linux] telnet 사용 접속 가능한지 확인 (0) | 2021.02.18 |
[Linux] CentOS 7 X-window 설치 (0) | 2020.11.30 |
[Linux] Apache HTTP/HTTPS 리다이렉트 (0) | 2020.11.26 |