Linuxhotel Wiki

Wie ging das nochmal?

Benutzer-Werkzeuge

Webseiten-Werkzeuge


tomcat_administration:mod_jk

Vorraussetzung

Einfache Paket Installation (NICHT NUTZEN)

WARNUNG: Hiermit bekommt man meist eine veraltete Version der mod_jk vom Distributor installiert!

sudo apt-get install libapache2-mod-jk
sudo apt-get remove libapache2-mod-jk

Aktuell gibt es ein Problem mit den mod_jk Release >1.2.32 - Dort wird das shared Memory Segment für den Austausch der mod_jk state nicht mehr korrekt behandelt. (Aktivation, Stopp einzelner Worker klappt nicht!!)

Mit diesem Patch und dem nächsten Release 1.2.38 wird das Problem behoben sein:

http://marc.info/?t=137086793500004&r=1&w=2 http://svn.apache.org/viewvc?view=revision&revision=1354021

Installation Apache httpd Development

sudo aptitude install apache2-dev

– evtl.

apt-get install apache2-mpm-worker
apt-get install apache2-threaded-dev

Installation aus Quellen

cd ~/workshop
wget http://192.168.1.171:2280/downloads/TomcatContributions_files/tomcat-connectors-1.2.40-src.tar.gz
tar xzf tomcat-connectors-1.2.40-src.tar.gz
cd tomcat-connectors-1.2.40-src/native
dpkg -S apxs | grep bin/
./configure --with-apxs=/usr/bin/apxs2
make
sudo make install
sudo -i

Konfiguration Apache

cd /etc/apache2

mods-available/jk.load :

LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so

mods-available/jk.conf

JkShmFile "/var/log/apache2/mod_jk.shm"

JkLogFile "/var/log/apache2/mod_jk.log"
JkLogLevel info

JKWorkerProperty worker.list=loadbalancer,jkstatus

JKWorkerProperty worker.node73.port=7309
JKWorkerProperty worker.node73.host=localhost
JKWorkerProperty worker.node73.type=ajp13

JKWorkerProperty worker.loadbalancer.type=lb
JKWorkerProperty worker.loadbalancer.balance_workers=node73

JKWorkerProperty worker.jkstatus.type=status

sites-available/default :

    JkMount /jkstatus jkstatus
    JkMount /hello* loadbalancer
a2enmod jk
apache2ctl -M | grep jk
apache2ctl restart
firefox http://localhost/jkstatus

workshop/node74/conf/server.xml

<Executor name="Catalina-Exe" namePrefix="Tomcat-Threads" maxThreads="200" />

Connector AJP Java IO Stack

<Connector port="${port.prefix}09"
           executor="Catalina-Exe"
           protocol="org.apache.coyote.ajp.AjpProtocol" />

jkstatus Seite absichern

sites-available/default :

    <Location /jkstatus>
    	AuthType Basic
	AuthName "By Invitation Only"
	AuthBasicProvider file
	AuthUserFile /etc/apache2/passwords
	Require valid-user 
    </Location>
htpasswd -c /etc/apache2/passwords admin

Read Only status worker

mods-available/jk.conf :

JKWorkerProperty worker.list=loadbalancer,jkstatus,jkread
...
JKWorkerProperty worker.jkread.user=radmin
JKWorkerProperty worker.jkread.type=status
JkWorkerProperty worker.jkread.read_only=true

sites-available/default :

    <Location /jkread>
        AuthType Basic
        AuthName "By Invitation Only"
        AuthBasicProvider file
        AuthUserFile /etc/apache2/passwords
        Require valid-user
    </Location>

    JkMount /jkread jkread

Neuen Tomcat Node einfügen

mods-available/jk.conf :

JKWorkerProperty worker.node74.port=7409
JKWorkerProperty worker.node74.host=localhost
JKWorkerProperty worker.node74.type=ajp13
..
JKWorkerProperty worker.loadbalancer.balance_workers=node73,node74

webapps/hello/id.jsp :

<%=session.getId()%>

Vergleich der Webserver Apache httpd und Apache Tomcat

Erzeugen einiger Binär Dateien

dd if=/dev/urandom of=webapps/last/8k.bin bs=8k count=1
dd if=/dev/urandom of=webapps/last/25k.bin bs=25k count=1
dd if=/dev/urandom of=webapps/last/100k.bin bs=100k count=1
dd if=/dev/urandom of=webapps/last/250k.bin bs=250k count=1

Erzeugen einer Textdatei

dd if=/dev/urandom | grep -ao "[A-Z,a-z]" | tr -d "\n" | dd of=webapps/last/64k.txt bs=1024 count=64

/etc/apache2/sites-avialable/default

    JkMount /last* loadbalancer

    Alias /static/ "/home/nutzer28/workshop/node74/webapps/last/"

Ausführen der Last

ab -c 5 -n 1000000 -k http://localhost/last/100k.bin
Tomcat 6.0.32 JIO
ab -c 10 -n 50000 http://localhost:7480/last/100k.bin

Requests per second:    1668.56 [#/sec] (mean)
Time per request:       5.993 [ms] (mean)
Time per request:       0.599 [ms] (mean, across all concurrent requests)
Transfer rate:          167289.32 [Kbytes/sec] received

Apache 2.2.14 + mod_jk 1.2.32 via AJP (AjpProtocol)
ab -c 10 -n 50000 http://localhost/last/100k.bin

Requests per second:    861.88 [#/sec] (mean)
Time per request:       11.603 [ms] (mean)
Time per request:       1.160 [ms] (mean, across all concurrent requests)
Transfer rate:          86424.88 [Kbytes/sec] received

Apache 2.2.14 direkt ubuntu 10.04
ab -c 10 -n 50000 http://localhost/alast/100k.bin
Requests per second:    2019.10 [#/sec] (mean)
Time per request:       4.953 [ms] (mean)
Time per request:       0.495 [ms] (mean, across all concurrent requests)
Transfer rate:          202464.63 [Kbytes/sec] received

Tomcat 6.0.32 APR
ab -c 10 -n 50000 http://localhost:7470/last/100k.bin
Requests per second:    2480.71 [#/sec] (mean)
Time per request:       4.031 [ms] (mean)
Time per request:       0.403 [ms] (mean, across all concurrent requests)
Transfer rate:          248720.55 [Kbytes/sec] received

Tomcat 6.0.32 NIO
ab -c 10 -n 50000 http://localhost:7490/last/100k.bin
Requests per second:    1613.26 [#/sec] (mean)
Time per request:       6.199 [ms] (mean)
Time per request:       0.620 [ms] (mean, across all concurrent requests)
Transfer rate:          161744.72 [Kbytes/sec] received

Tomcat 6.0.32 NIO (with keepalive)
ab -c 10 -n 50000 -k http://localhost:7490/last/100k.bin
Requests per second:    2292.71 [#/sec] (mean)
Time per request:       4.362 [ms] (mean)
Time per request:       0.436 [ms] (mean, across all concurrent requests)
Transfer rate:          229897.96 [Kbytes/sec] received

Apache 2.2.14 direkt ubuntu 10.04 (with keepalive)
ab -c 10 -n 50000 -k http://localhost/alast/100k.bin
Requests per second:    3030.16 [#/sec] (mean)
Time per request:       3.300 [ms] (mean)
Time per request:       0.330 [ms] (mean, across all concurrent requests)
Transfer rate:          303974.78 [Kbytes/sec] received

Tomcat 6.0.32 APR (with keepalive)
ab -c 10 -n 50000 -k http://localhost:7470/last/100k.bin
Requests per second:    3220.51 [#/sec] (mean)
Time per request:       3.105 [ms] (mean)
Time per request:       0.311 [ms] (mean, across all concurrent requests)
Transfer rate:          322931.23 [Kbytes/sec] received

The Winner is: Apache Tomcat 6.0.32 with APR and KeepAlive :-)

Beim überschreiten der File Limits:

/etc/security/limits.conf

* soft files 0
* hard files 0
kill -HUP 1

Templates für mehrere nodes

JkShmFile "/var/log/apache2/mod_jk.shm"

JkLogFile "/var/log/apache2/mod_jk.log"
JkLogLevel info

JKWorkerProperty worker.list=loadbalancer,jkstatus

JKWatchDogInterval 30
# template worker mod_jk apache
JkWorkerProperty worker.template.type=ajp13
# used for MPM worker mode with CPING/CPONG
JkWorkerProperty worker.template.connection_pool_timeout=300
JkWorkerProperty worker.template.connection_pool_minsize=0
#JkWorkerProperty worker.template.socket_keepalive=1
#JkWorkerProperty worker.template.socket_timeout=300
JkWorkerProperty worker.template.ping_mode=A
JkWorkerProperty worker.template.ping_timeout=10000
#JkWorkerProperty worker.template.max_reply_timeouts=10
#JkWorkerProperty worker.template.reply_timeout=300000
JkWorkerProperty worker.template.lbfactor=1
JkWorkerProperty worker.template.retries=2
JkWorkerProperty worker.template.activation=A
JkWorkerProperty worker.template.recovery_options=7

JKWorkerProperty worker.list=loadbalancer,jkstatus

JKWorkerProperty worker.node73.port=7309
JKWorkerProperty worker.node73.host=localhost
JKWorkerProperty worker.node73.reference=worker.template

JKWorkerProperty worker.node74.port=7409
JKWorkerProperty worker.node74.host=localhost
JKWorkerProperty worker.node74.reference=worker.template

JKWorkerProperty worker.loadbalancer.type=lb
JKWorkerProperty worker.loadbalancer.error_escalation_time=0
JKWorkerProperty worker.loadbalancer.balance_workers=node73,node74

JKWorkerProperty worker.jkstatus.type=status

AccessLogging

/etc/apache2/sites-avialable/default

   LogFormat     "%h %l %u %t \"%r\" %>s %b %D %{pid}P %{tid}P %{JK_WORKER_NAME}n %{JK_LB_FIRST_NAME}n \
%{JK_LB_FIRST_BUSY}n %{JK_LB_FIRST_STATE}n %{JK_LB_LAST_NAME}n \
%{JK_LB_LAST_BUSY}n %{JK_LB_LAST_STATE}n %{UNIQUE_ID}e %{JSESSIONID}C" mod_jk_log
   CustomLog     /var/log/apache2/access_jk.log     mod_jk_log

    JkEnvVar UNIQUE_ID
    JkEnvVar APACHE notebook14
sudo a2enmod unique_id
sudo apache2ctl restart

Links

Tomcat AccessLog

node73/conf/server.xml

  <Engine ..>
  ..

  <Valve className="org.apache.catalina.valves.AccessLogValve"
             directory="logs"
             prefix="access-"
             suffix=".log"
             pattern="%h %l %u %t &quot;%r&quot; %s %b %D %S %{UNIQUE_ID}r %{APACHE}r"
      />

  ..
  <Host ..>

Log4J Ausgabe mit Unique ID

Vorbereitung in webapps

mkdir -p logging/WEB-INF/classes/filters
mkdir -p logging/WEB-INF/lib

WEB-INF/classes/filters/ApacheUniqueIDFilter.java

package filters;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.log4j.MDC;

public final class ApacheUniqueIDFilter implements Filter {
    private String uniqueID = "UNIQUE_ID";
    private String apache = "APACHE";
    
    private FilterConfig filterConfig = null;
   
    public void destroy() {

        this.uniqueID = null;
        this.apache = null ;
        this.filterConfig = null;

    }
    public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain)
	throws IOException, ServletException {

	   String uidvalue =(String) request.getAttribute(uniqueID);
	   String apachevalue = (String)request.getAttribute(apache);
	    
	   try {
	      MDC.put("UNIQUE_ID", uidvalue + "-" + apachevalue) ;
          chain.doFilter(request, response);
	   } finally {
	      MDC.remove("UNIQUE_ID") ;
	   }
    }

    public void init(FilterConfig filterConfig) throws ServletException {
		this.filterConfig = filterConfig;
        //this.uniqueID = filterConfig.getInitParameter("UNIQUE_ID");
        //this.apache = filterConfig.getInitParameter("APACHE");
    }


}

WEB-INF/classes/log4j.properties

log4j.rootLogger=INFO, CATALINA

# Define all the appenders
log4j.appender.CATALINA=org.apache.log4j.DailyRollingFileAppender
log4j.appender.CATALINA.file=${catalina.base}/logs/logging.log
log4j.appender.CATALINA.encoding=UTF-8
# Roll-over the log once per day
log4j.appender.CATALINA.datePattern='.'yyyy-MM-dd
log4j.appender.CATALINA.layout=org.apache.log4j.PatternLayout
log4j.appender.CATALINA.layout.conversionPattern = %d [%t] %-5p %X{UNIQUE_ID} %c- %m%n
log4j.appender.CATALINA.append=true

WEB-INF/web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   version="2.5"> 
<filter>
                <filter-name>uniqueid</filter-name>
                <filter-class>filters.ApacheUniqueIDFilter</filter-class>
   </filter>
   <filter-mapping>
                <filter-name>uniqueid</filter-name>
                <url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

log.jsp

<%@ page import="org.apache.log4j.*" %>
<%

Logger logger = Logger.getRootLogger();
logger.info("Info");
logger.debug("Fine");
application.log("context log");
System.out.println("system.out");
System.err.println("system.err");
%>
s.h Logging Handler

download und kompilieren

cd workshop
wget http://archive.apache.org/dist/logging/log4j/1.2.16/apache-log4j-1.2.16.tar.gz
tar xzf apache-log4j-1.2.16.tar.gz
cp apache-log4j-1.2.16/log4j-1.2.16.jar node74/webapps/logging/WEB-INF/lib
cd node74/webapps/logging/WEB-INF/classes/filters
javac -cp ~/workshop/apache-tomcat-6.0.32/lib/servlet-api.jar:../../lib/log4j-1.2.16.jar *.java
cd ../..
touch web.xml
sudo -i
cd /etc/apache2
vi sites-available/default
JkMount /logging* loadbalancer
apache2ctl restart
Access log.jsp via apache (http://localhost/logging/log.jsp;jsessionid=sdada.node74
Nachschauen in node74/logs/logging.log

logging.log

2011-07-14 16:48:40,060 [ajp-7409-1] INFO  Th8Bx38AAQEAAHWhAP4AAAAQ-notebook24 root- Info

tomcat access.log

192.168.1.189 - "-" [14/Jul/2011:16:48:45 +0200] "GET /last/log.jsp;jesssionid=sdsad.node74 HTTP/1.1" 200 22 473 756A0329E5BD1CDFF8CC93DF777B5BC7.node74 Th8Bx38AAQEAAHWhAP4AAAAQ notebook24

apache access_jk.log

192.168.1.189 - - [14/Jul/2011:16:48:39 +0200] "GET /last/log.jsp;jsessionid=sda.node74 HTTP/1.1" 200 42 131179 30113 2900253552 loadbalancer node74 0 OK node74 0 OK Th8Bx38AAQEAAHWhAP4AAAAQ 756A0329E5BD1CDFF8CC93DF777B5BC7.node74

* http://www.torsten-horn.de/techdocs/java-log4j.htm

Dokumentation

Distance

mods-available/jk.conf

JKWorkerProperty worker.node73.port=7309
JKWorkerProperty worker.node73.host=localhost
JKWorkerProperty worker.node73.reference=worker.template
JKWorkerProperty worker.node73.distance=0

JKWorkerProperty worker.node74.port=7409
JKWorkerProperty worker.node74.host=localhost
JKWorkerProperty worker.node74.reference=worker.template
JkWorkerProperty worker.node74.distance=0

JKWorkerProperty worker.node75.port=7509
JKWorkerProperty worker.node75.host=notebook05
JKWorkerProperty worker.node75.reference=worker.template
JkWorkerProperty worker.node75.distance=1

JKWorkerProperty worker.node76.port=7609
JKWorkerProperty worker.node76.host=notebook05
JKWorkerProperty worker.node76.reference=worker.template
JKWorkerProperty worker.node76.distance=1

JKWorkerProperty worker.list=loadbalancer,jkstatus,jkread

JKWorkerProperty worker.loadbalancer.type=lb
JKWorkerProperty worker.loadbalancer.error_escalation_time=0
JKWorkerProperty worker.loadbalancer.balance_workers=node73
JKWorkerProperty worker.loadbalancer.balance_workers=node74
JKWorkerProperty worker.loadbalancer.balance_workers=node75
JKWorkerProperty worker.loadbalancer.balance_workers=node76

More Loadbalancer uri.map

mods-available/jk.conf

JKWorkerProperty worker.node73.port=7309
JKWorkerProperty worker.node73.host=localhost
JKWorkerProperty worker.node73.reference=worker.template
JKWorkerProperty worker.node73.distance=0

JKWorkerProperty worker.node74.port=7409
JKWorkerProperty worker.node74.host=localhost
JKWorkerProperty worker.node74.reference=worker.template
JkWorkerProperty worker.node74.distance=0

JKWorkerProperty worker.node75.port=7509
JKWorkerProperty worker.node75.host=notebook05
JKWorkerProperty worker.node75.reference=worker.template
JkWorkerProperty worker.node75.distance=1

JKWorkerProperty worker.node76.port=7609
JKWorkerProperty worker.node76.host=notebook05
JKWorkerProperty worker.node76.reference=worker.template
JKWorkerProperty worker.node76.distance=1

JKWorkerProperty worker.list=loadbalancer,jkstatus,jkread, lb2

JKWorkerProperty worker.loadbalancer.type=lb
JKWorkerProperty worker.loadbalancer.error_escalation_time=0
JKWorkerProperty worker.loadbalancer.balance_workers=node73
JKWorkerProperty worker.loadbalancer.balance_workers=node74

JKWorkerProperty worker.lb2.type=lb
JKWorkerProperty worker.lb2.error_escalation_time=0

JKWorkerProperty worker.lb2.balance_workers=node75
JKWorkerProperty worker.lb2.balance_workers=node76

sites-avaialble/default

JkMountFile /etc/apache2/uriworkermap.properties

uriworkermap.properties

/nutzer*=loadbalancer

Wechsel auf einen anderen Loadbalancer ohne Restart auf lb2(node75/node76) uriworkermap.properties

/nutzer*=lb2

Mod_proxy

/etc/apache2/sites-available/default

<Proxy balancer://mycluster>
    BalancerMember ajp://localhost:7409 route=node74
    BalancerMember ajp://localhost:7509 route=node75
    ProxySet stickysession=JSESSIONID
</Proxy>

ProxyPass /lllast balancer://mycluster/last
ProxyPassReverse /lllast balancer://mycluster/last
ProxyPass /llhello balancer://mycluster/hello
ProxyPassReverse /llhello balancer://mycluster/hello

mods-available/proxy.conf

<IfModule mod_proxy.c>
        #turning ProxyRequests on and allowing proxying from all may allow
        #spammers to use your proxy to send email.

        ProxyRequests Off 

        <Proxy *>
                AddDefaultCharset off
                Order deny,allow
                #Deny from all
                ### Erlaubnis erteilen ###
                Allow from all 
                #Allow from .example.com
        </Proxy>

        # Enable/disable the handling of HTTP/1.1 "Via:" headers.
        # ("Full" adds the server version; "Block" removes all outgoing Via: headers)
        # Set to one of: Off | On | Full | Block

        ProxyVia On
</IfModule>
#a2dismod jk
a2enmod proxy
a2enmod proxy_balancer
a2enmod proxy_ajp
apache2ctl restart

sites-available/default

<Location /balancer-manager>
   SetHandler balancer-manager
 
   Order deny,allow
   Allow from all

   AuthType Basic
   AuthName "By Invitation Only"
   AuthBasicProvider file
   AuthUserFile /etc/apache2/passwords
   Require valid-user

</Location>
tomcat_administration/mod_jk.txt · Zuletzt geändert: 2015/08/20 12:44 von peter_rossbach1