ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • tomcat connector
    과거...../리눅스 2011. 12. 28. 19:42
    출처 :  http://antop.tistory.com/38 
    jdk 1.6


    # apt-get install sun-java6-jdk

    테스트

    # javac -version
    javac 1.6.0_15

    # java -version
    java version "1.6.0_15"
    Java(TM) SE Runtime Environment (build 1.6.0_15-b03)
    Java HotSpot(TM) Client VM (build 14.1-b02, mixed mode, sharing)




    apache2 - http://antop.tistory.com/37


    tomcat6

    # apt-get install tomcat6

    환경 설정

    # vi /etc/tomcat6/server.xml

    <!-- URIEncoding="UTF-8" 추가 -->
    <Connector port="8080" protocol="HTTP/1.1" URIEncoding="UTF-8"
               connectionTimeout="20000"
               redirectPort="8443" />

    <!-- 주석을 제가하고 URIEncoding="UTF-8" enableLookups="false" 추가 -->
    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8" enableLookups="false" />

    # vi /etc/init.d/tomcat6

    # 추가
    JAVA_OPTS="$JAVA_OPTS -Djava.endorsed.dirs=$CATALINA_HOME/endorsed -Dcatalina.base=$CATALINA_BASE -Dcatalina.home=$CATALINA_HOME -Djava.io.tmpdir=$JVM_TMP -Dfile.encoding=8859_1 -Dfile.client.encoding=8859_1 -Dclient.encoding.override=8859_1"

    tomcat6 재시작

    # /etc/init.d/tomcat6 restart

    테스트





    tomcat connecter

    # apt-get install libapache2-mod-jk

    # vi /etc/apache2/mods-enabled/jk.conf

    # 생성
    # ServerName nerv-team.co.kr
    JkWorkersFile   /etc/apache2/mods-enabled/workers.properties
    JkShmFile       /var/log/apache2/mod_jk.shm
    JkLogFile       /var/log/apache2/mod_jk.log
    JkLogLevel      debug
    JkLogStampFormat   "[%a %b %d %H:%M:%S %Y] "
    JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
    JkRequestLogFormat "%w %V %T"

    # vi /etc/apache2/mods-enabled/jk_mount.conf

    # 생성
    # Apache Tomcat에서 처리할 URL 패턴을 등록
    JkMount /*.jsp          worker1
    JkMount /servlet/*      worker1
    JkMount /*.do           worker1
    JkMount /*.action       worker1

    # vi /etc/apache2/mods-enabled/workers.properties

    # 생성
    workers.tomcat_home=/usr/share/tomcat6
    workers.java_home=/usr/lib/jvm/java-6-sun
    ps=/

    worker.list=worker1
    worker.worker1.host=localhost
    worker.worker1.port=8009
    worker.worker1.type=ajp13
    worker.worker1.lbfactor=50
    worker.worker1.socket_keepalive=1
    worker.worker1.socket_timeout=60

    # vi /etc/apache2/sites-enabled/000-default

    # 원하는 호스트 부분에 추가
    # www.nerv-team.co.kr
    <VirtualHost *:80>
            ServerAdmin antop@nerv-team.co.kr
            ServerName www.nerv-team.co.kr
            ServerAlias nerv-team.co.kr
            DocumentRoot /var/www
            # tomcat connecter
            Include /etc/apache2/mods-enabled/jk_mount.conf
    ...
    </VirtualHost>

    # vi /etc/tomcat6/server.xml

    <Host name="www.nerv-team.co.kr" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
      <Context path="/" docBase="/var/www" reloadable="true" />
    </Host>

    tomcat6 재시작

    # /etc/init.d/tomcat6 restart

    apache2 재시작 (tomcat6 부터 재시작 한다)

    # /etc/init.d/apache2 restart

    테스트

    # echo '<%="Hello World"%>' > /var/www/jspinfo.jsp







    java.security.AccessControlException: access denied

    예) test.jsp

    <%=System.getProperty("java.class.path") %>

    에서 에러가 났다면 "/etc/java-6-sun/security/java.policy" 파일에서 접근 권한이 있는지 확인한다.

    // 추가
    permission java.util.PropertyPermission "java.class.path", "read";



    WEB-INF/lib 참조 못하는 에러 해결(권한 문제)

    # vi /etc/tomcat6/policy.d/04webapps.policy

    // 추가
    grant codeBase "file:/home/-" {
            permission java.security.AllPermission;
    };


    그래도 안되면 수동으로 하는 수밖에...

    ※ 웹어플 하나 추가할때마다 서버 재시작해줘야 할지도... -0- 비추..

    # vi /etc/init.d/tomcat6

    # tomcat 라이브러리 등록
    JSVC_CLASSPATH=$JSVC_CLASSPATH:.:`echo $CATALINA_HOME/lib/*.jar | tr ' ' ':'`
    # 가상 호스팅 classes, lib 등록
    home_root="/home"
    public_html="public_html"
    for home_name in $(ls "$home_root")
      do
        if [ -d "$home_root/$home_name/$public_html" ]; then
          for context_name in $(ls "$home_root/$home_name/$public_html")
            do
              if [ -d "$home_root/$home_name/$public_html/$context_name/WEB-INF" ]; then
                # classes 폴더 등록
                if [ -d "$home_root/$home_name/$public_html/$context_name/WEB-INF/classes" ]; then
                  JSVC_CLASSPATH="$JSVC_CLASSPATH:$home_root/$home_name/$public_html/$context_name/WEB-INF/classes"
                fi
                # lib 폴더안의 jar 파일 전부 등록
                if [ -d "$home_root/$home_name/$public_html/$context_name/WEB-INF/lib" ]; then
                  for jar_file in $(ls "$home_root/$home_name/$public_html/$context_name/WEB-INF/lib")
                    do
                      JSVC_CLASSPATH="$JSVC_CLASSPATH:$home_root/$home_name/$public_html/$context_name/WEB-INF/lib/$jar_file"
                    # end for
                  done
                fi
              fi
            # end for
          done
        fi
      # end for
    done
Designed by Tistory.