본문 바로가기

IT 기술/코드샘플

mod_jk로 아파치 톰캣 연동

아파치와 톰캣이 설치된 서버는 다르며, 로컬에 연결되어 있다.

1. 아파치 설정

1.1 vi /etc/httpd/conf.d/httpd-jk.conf

LoadModule jk_module modules/mod_jk.so

Listen 8081
<VirtualHost *:8081>
        ServerName localhost
        JkMount /* instance1
        JkMount /* instance4
</VirtualHost>

Listen 8083
<VirtualHost *:8083>
        ServerName localhost
        JkMount /* instance2
        JkMount /* instance5
</VirtualHost>

Listen 8085
<VirtualHost *:8085>
        ServerName localhost
        JkMount /* instance3
        JkMount /* instance6
</VirtualHost>

<Directory />
        Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    #Deny from all
    Allow from all
</Directory>


<IfModule jk_module>

    # We need a workers file exactly once
    # and in the global server
    JkWorkersFile /etc/httpd/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

</IfModule>

mod_jk는 설치 하면 아파치 경로의 modules에 위치한다.

포트를 개방하며 가상 호스트를 통해 아파치와 톰캣을 연동한다.

 

1.2 /etc/httpd/conf.d/workers.properties

 

worker.list=instance1,instance2,instance3,instance4,instance5,instance6


worker.instance1.port=8009
worker.instance1.host=172.16.36.253
worker.instance1.type=ajp13
worker.instance1.lbfactor=1

worker.instance2.port=8010
worker.instance2.host=172.16.36.253
worker.instance2.type=ajp13
worker.instance2.lbfactor=1

worker.instance3.port=8011
worker.instance3.host=172.16.36.253
worker.instance3.type=ajp13
worker.instance3.lbfactor=1

worker.instance4.port=8009
worker.instance4.host=172.16.36.251
worker.instance4.type=ajp13
worker.instance4.lbfactor=1

worker.instance5.port=8010
worker.instance5.host=172.16.36.251
worker.instance5.type=ajp13
worker.instance5.lbfactor=1

worker.instance6.port=8011
worker.instance6.host=172.16.36.251
worker.instance6.type=ajp13
worker.instance6.lbfactor=1

톰캣에서 jvmRoute로 전달받은 값을 활용해 worker완성

 

1.3 /아파치설치경로/conf/httpd.conf 

Include /etc/httpd/conf.d/httpd-jk.conf

해당 코드를 추가해 설정파일을 불러와 아파치에 적용한다.

 

/아파치경로/bin/apachectl start

모든사항 적용후 아파치 구동

2. 톰캣 설정

2.1 /톰캣설치경로/conf/server.xml

<Connector protocol="AJP/1.3" port="8009" redirectPort="8443"
        address="0.0.0.0"
        secretRequired="false" />

AJP의 주석을 해제하고 다음과 같이 포트를 개방한다.

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

아파치로 보낼 jvmRoute의 이름을 설정한다.

 

/bin/startup.sh

톰캣 구동

localhost:8085/index.jsp가 다운로드 되면 연동 성공

아파치(8085)가 톰캣의 index.jsp를 가져온다.

'IT 기술 > 코드샘플' 카테고리의 다른 글

JS 체크 2가지  (0) 2021.01.19
Docker mysql Import  (0) 2020.11.11
mod_jk CentOS 설치  (0) 2020.10.06
CentOS7, Tomcat8 자동실행  (0) 2020.09.22
Doker_oracle  (0) 2020.07.06