본문 바로가기

개발 개발

Yum httpd 에 mod_jk 설치 하기

출처 :  http://www.openscope.net/2010/01/02/install-mod_jk/ 

Use mod_jk to bridge apache and Jboss

mod_jk is an apache extension that you can use to redirect incoming http requests to an application server. It lets you configure multiple applications servers by virtual host urls, and provides a means of setting up load balancing preferences between application servers. It’s very useful because it lets apache do what it does best – serve up http requests. Well, its good at serving up html too but apache will usually do a much better job of handling load balancing that most application servers. Let the web server handle http, and let the application server handle the business logic number crunching.

mod_jk 1.2.x is supposedly better than 2.0. Why? Ok, now that I understand why, on with installing mod_jk 1.2.x

Build/Install mod_jk

To start, make sure apache and mod_jk are installed. you can use the yum installer to make sure you have apache 2 installed. you might need to also make sure you have the http-devel package installed if you are going to build mod_jk binaries.

[root@bedrock native]# yum install httpd-devel

This should install the current version of apache. We’re going to also have to download the connectors and build them since there are no binary distributions available for fedora.Download the source code here.

Once its downloaded, untar and gunzip the file:

[root@bedrock native]# tar -zxvf tomcat-connectors-1.2.28-src.tar.gz

cd into the uncompressed folder, and compile the package

[root@bedrock native]# cd native
[root@bedrock native]# ./configure –with-apxs=/usr/sbin/apxs (or where ever the apxs/apxs2 is)
[root@bedrock native]# make
[root@bedrock native]# make install

Configure mod_jk

Now that it’s built, we can set up apache to use mod_jk. We’ll need to add/modify the mod-jk.conf file first:

[root@bedrock conf]# vi /etc/httpd/conf.d/mod-jk.conf

You an get the full text file from the jboss wiki. Normally, declarations like these go in the http.conf file, but apache these days has a felxible configuration architecture that allows you to break up configuration as long as its listed in the “/etc/httpd/conf.d/” directory. If you have that mod-jk.conf file in there, you’ll want to edit this mod-jk.conf file in order to configure the exact way you want mod_jk to handle your hosts/ip/port setup.

# Load mod_jk module
# Specify the filename of the mod_jk lib
LoadModule jk_module modules/mod_jk.so

# Where to find workers.properties
JkWorkersFile conf/workers.properties
...
...
...

<Location /jkstatus>
	JkMount status
	Order deny,allow
	#Deny from all
	Allow from .domain.com
</Location>

# for virtual hosts, specify the alias by ip
NameVirtualHost 192.168.1.253

# and map them to domains to listen for
# the JKAutoAlias maps an alias you can map in uriworkermap.properties
<VirtualHost 192.168.1.253>
  ServerName first.domain.com

	JkMount               /* myapp1
	JkAutoAlias           /myapp1
</VirtualHost>

<VirtualHost 192.168.1.253>
  ServerName second.domain.com

	JkMount               /* myapp2
	kAutoAlias           /myapp2
</VirtualHost>

You will also want to configure your workers and uriworkermap property files:

[root@bedrock conf]# vi /etc/httpd/conf.d/workers.properties

# Define the list of workers that will be used
worker.list=myapp1,myapp2,status

# Define myapp1
# modify the host as your host IP or DNS name.
# more info here: http://tomcat.apache.org/connectors-doc/reference/workers.html
worker.myapp1.port=8009
worker.myapp1.host=192.168.1.253
worker.myapp1.type=ajp13
worker.myapp1.prepost_timeout=10000 #Not required if using ping_mode=A
worker.myapp1.connect_timeout=10000 #Not required if using ping_mode=A
worker.myapp1.ping_mode=A #As of mod_jk 1.2.27

# Define myapp2
# modify the host as your host IP or DNS name.
worker.myapp2.port=8009
worker.myapp2.host=192.168.1.253
worker.myapp2.type=ajp13
worker.myapp2.prepost_timeout=10000 #Not required if using ping_mode=A
worker.myapp2.connect_timeout=10000 #Not required if using ping_mode=A
worker.myapp2.ping_mode=A #As of mod_jk 1.2.27

You will want to fine tune this to your particular setup. The full connector property reference can be found on the apache connectors website.

Next you’ll want to map the host contexts for your particular configuration. Remember the JKAutoAlias we configured earlier in the VirtualHost config? We’ll want to map those virtual aliases to actual contexts, and worker nodes in uriworkermap.properties:

# Simple uriworkers.properties config
# Mount the Servlet context to the ajp13 worker

/myapp1=myapp1
/myapp1/*=myapp1

/myapp2=myapp2
/myapp2/*=myapp2

In this notation we have to add each context twice, one to map the root of the context, and a second one to map everything underneath – that’s what the * at the end of the second mapping refers to.

Don’t forget that you can debug the mod_jk setup by tailing the apache logs:

[root@bedrock conf.d]# tail -500 /var/log/httpd/mod_jk.log

or

[root@bedrock conf.d]# tail -500 /var/log/httpd/error.log

Complete files


References
Download Tomcat-Apache Mod_jk connectors
how to untar/build mod_jk src distributions
documentation on how to configure mod_jk to work with jboss
the Apache connector property reference guid
the apache workers.property reference guide



하기 종합판 : 출처 :
http://pstory.tistory.com/58 

Apache 2.2.x + Tomcat 6 or 7 + mod_jk on CentOS5.5
1. JAVA jdk 설치
    1.1 웹에서 다운로드후 FTP로 전송할경우
         
http://www.oracle.com/technetwork/java/javase/downloads/jdk6-jsp-136632.html
    1.2 리눅스에서 바로 받을경우 (링크주소복사이용)
         위 경로에서 진행하여 jdk-6uxx-linux-i586.bin 링크주소를 복사
         
        위 파일이 다운로드가 되면 파일명이 매우 깁니다. 간단히 mv명으로 jdk-6u21-linux-i586.bin 으로 변경!
       # chmod 555 jdk-6u21-linux-i586.bin
       # cp jdk-6u21-linux-i586.bin /usr/local
       # ./jdk-6u21-linux-i586.bin

                 
    1.3 자바 환경설정
         /etc/profile을 이용하여 환경설정을 합니다.
         /etc/profile 상단이나 하단 아무곳에나 export JAVA_HOME=/usr/local/jdk1.6.0 입력
         # vi /etc/profile
         export JAVA_HOME=/usr/local/jdk1.6.0
         (esc) :wq (vi 편집기상에서 ESC키를 누른후 :wq)
         # source /etc/profile
         /etc/profile 적용여부 확인 방법 (두개 모두 해보세요 ㅎㅎ 아직 PATH는 설정하지 않았습니다.)
         # echo $JAVA_HOME
         # java -version 


2. Apache2 설치여부확인 (설치되어 있다면 이부분 패스하세요)
    # rpm -qa| grep httpd
    yum(rpm방식)으로 설치할 경우와 소스컴파일로 설치할 경우 디렉토리와 mod_jk연동에 차이점이 있습니다.
   우선 현재 설치되어 있는 http의 경로를 확인하세요
   rpm으로 설치된경우 /etc/httpd 에 파일들이 존재합니다.
   설치가 안되어 있다면 아래를 참고하여 설치해주세요

   2-1. Apache2가 yum이나 rpm으로 설치되어 있는경우 -> yum이나 rpm으로 설치된경우
         또는 yum이나 rpm으로 설치하시고자하는경우
         2-1-1. yum 설치방법 (httpd와 httpd-devle(데몬) 을 같이 인스톨합니다.)
                  # yum install httpd httpd-devel
         2-1-2. rpm 설치방법
                  http://httpd.apache.org/download.cgi 에 download페이지 최신버전항목하단에 other version참고
                  http://apache.tt.co.kr//httpd/binaries/rpm/i386/ 에서 httpd-2.2.x 최신 rpm을 링크 주소 복사
                  # wget http://apache.tt.co.kr//httpd/binaries/rpm/i386/httpd-2.2.3-1.i386.rpm
                  # rpm -ivh httpd-2.2.3-1.i386.rpm

   2-2. Apache2가 소스컴파일설치되어 있거나 설치되지 않은경우 -> 소스컴파일로 설치된경우
         또는 소스컴파일로 설치할경우
         http://httpd.apache.org/download.cgi   최신버전 tar.gz형식 다운로드
         # wget http://apache.tt.co.kr//httpd/httpd-2.2.16.tar.gz
         # tar zxvf httpd-2.2.16.tar.gz
         # cd httpd-2.2.16
         소스컴파일시 module을 수동으로 사용할수 있도록 옵션을 주어야 합니다.
       # ./configure --prefix=/usr/local/apache2 \
                         --enable-module=so \
                         --enable-mods-shared=all \
                         --enable-so

         # make
         # make install

   2-3. Apache 실행후 확인
         2-3-1. (2-1)의 rpm 으로 설치된경우 
                   # service httpd start 
         2-3-2. (2-2)의 소스컴파일로 설치된경우 (데몬을 만들어 실행하실 경우 위 방법으로 실행가능)
                   # /usr/local/apache2/bin/apachectl start
     
  2-3-3. http://localhost 로 확인하세요


3. Tomcat 설치
    http://tomcat.apache.org 에서 tomcat 6 또는 7 버전을 다운로드하여 압축을 푼뒤 경로를 정합니다.
    # wget http://mirror.khlug.org/apache//tomcat/tomcat-7/v7.0.2-beta/bin/apache-tomcat-7.0.2.tar.gz
    # tar zxvf apache-tomcat-7.0.2.tar.gz
    # mv apache-tomcat-7.0.2 /usr/local/tomcat
   
    데몬설정 (/etc/init.d/tomcat)
    # vi /etc/init.d/tomcat
  
#!/bin/sh
#
# Tomcat7 auto-start
#
# chkconfig: 2345 90 90
# description: Auto-starts tomcat7
# processname: tomcat7
# pidfile: /var/run/tomcat7.pid
export JAVA_HOME=/usr/local/jdk1.6.0
case $1 in
start)
    sh /usr/local/tomcat/bin/startup.sh
    ;;
stop)
    sh /usr/local/tomcat/bin/shutdown.sh
    ;;
restart)
    sh /usr/local/tomcat/bin/shutdown.sh
    sh /usr/local/tomcat/bin/startup.sh
    ;;
esac
exit 0

    3-1. 서비스 구동후 확인
          # service tomcat start
          http://localhost:8080 으로 확인하세요

4. mod_jk 설치
    
http://tomcat.apache.org/download-connectors.cgi 에 접속
    mod_jk.so 또는 tomcat-connectors-1.2.30-src.tar.gz 를 다운로드합니다.
    mod_jk 설치방법에는 두가지 설치방법이 있습니다.
    위 두파일을 가지고 하는건데요 일단 mod_jk.so를 직접 다운로드하여 바로 모듈에 연결시켜보도록 하겠습니다.
    경로는 http://apache.tt.co.kr//tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.30/i586/ 에
    가시면 현재 설치된 httpd(Apache)버전에 맞는 버전을 다운로드합니다. 위에서 2.2.3을 설치하였으므로
    mod_jk-1.2.30-httpd-2.2.X.so  를 다운로드하여 mod_jk.so 로 이름을 변경합니다.
    # wget http://apache.tt.co.kr//tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.30/i586/mod_jk-1.2.30-httpd-2.2.X.so
    # mv mod_jk-1.2.30-httpd-2.2.X.so mod_jk.so
    mod_jk.so를 httpd의  module 디렉토리에 복사합니다.
    # cp mod_jk.so /usr/local/apache2/modules/
    또는 
    # cp mod_jk.so /etc/httpd/modules/

    httpd.conf 를 vi편집기를 이용해서 LoadModules 맨 끝 라인에
    LoadModule jk_module modules/mod_jk.so  를 입력해줍니다.

    다음은 tar.gz를 이용한 방법입니다.
    # wget http://mirror.apache-kr.org//tomcat/tomcat-connectors/jk/source/jk-1.2.30/tomcat-connectors-1.2.30-src.tar.gz
    # tar zxvf tomcat-connectors-12.30-src.tar.gz
    # cd tomcat-connectors-12.30-src
   컴파일 바이너리를 이용할 경우 apxs를 이용하는데요 경로는 소스컴파일 하신경우 /usr/local/apache2/apxs 일껍니다.
    # ./configure --with-apxs=/usr/local/apache2/apxs --enable-EAPI
    # make
    # cd apache-2.0
    # ls mod_jk.so
    # cp mod_jk.so /etc/httpd/modules
5. Apache, Tomcat, mod_jk 환경설정
     5-1. Apache 의 httpd.conf 에 추가
           LoadModule jk_module modules/mod_jk.so
           include conf/mod_jk.conf
           DirectoryIndex index.html index.php index.php3 index.jsp index.html.var
           
           <VirtualHost *:80>
                  ServerAdmin 관리자메일주소
                  DocumentRoot /home/계정명/public_html
                  ServerName 호스트명

                  JkMount /*.jsp jspLoader

                  ErrorLog logs/localhost-error_log
                  CustomLog logs/localhost-access_log common
           </VirtualHost>


           - 변경 -------------------------------------------
           User daemon -> nobody 로 변경
           Group daemon -> nobody 로 변경
           ServerName localhost (주석제거)
           <Directory /home/*/public_html> 찾아서 </Directory>까지 주석제거
           AddDefaultCharset UTF-8 -> EUC-KR 로 변경

     5-2. Apache의 mod_jk.conf 에 추가
           <IfModule jk_module>
               JkWorkersFile /etc/httpd/conf/workers.properties
               JkShmFile /etc/httpd/logs/mod_jk.shm
               JkLogFile /etc/httpd/logs/mod_jk.log
               JkLogLevel info
               JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
           </ifModule>

     5-3. Apache의 workers.properties 에 추가
           worker.list=jspLoader
           worker.jspLoader.port=8009
           worker.jspLoader.host=localhost
           worker.jspLoader.type=ajp13
           worker.jspLoader.lbfactor=20

     5-4. Tomcat의 server.xml 에 appBase의 경로를 httpd.conf에서 설정한 virtualhost 의 document_root와 동일하게 변경
           <Host name="localhost"  appBase="/home/test/public_html"
            unpackWARs="true" autoDeploy="true">

     5-5. Tomcat의 Root.xml
           톰캣설치디렉토리의 conf/Catalina/localhost에 ROOT.xml 생성 후 아래 내용 추가
           경로를 역시 server.xml과 httpd.conf의 웹루트 경로와 동일하게 정의한다.
           # vi /usr/local/tomcat/conf/Catalina/localhost/ROOT.xml
           <?xml version='1.0' encoding='euc-kr'?>
           <Context crossContext="true" docBase="/home/test/public_html" path="" reloadable="true">
           </Context>
           
     5-6. 마무리
           # service tomcat restart
           # service httpd restart

6. 최종구동
    웹에서 확인해보세요^^
 

'개발 개발' 카테고리의 다른 글

[OpenSSL 프로그래밍]  (0) 2012.05.11
HG ( Mercurial ) 한글 파일 문제 해결  (0) 2012.02.07
fails sanity check 에러가 날때  (0) 2012.01.04
[C++] Google의 C++ 라이브러리  (0) 2011.11.14
블루투스 개발 관련 싸이트  (0) 2011.10.14