# Apache2 Tomcat5 and mod_jk problem.

## kaarol

I read most of all post with "tomcat" in title but I didn't find answer. 

I readthis howto  because I had worked apache on my Server. 

I emerge tomcat next I add 

```
echo "www-apache/mod_jk ~amd64" >> /etc/portage/package.keywords
```

. I used "~md64" because I have Intel Celeron 64 bit. 

Next I emerged mod_jk before I had made Use="apache2". I add -D JK to my apache2 config file. 

I restart apache2 and start tomcat, but I only saw the error site 

```
Service Temporarily Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

Apache Server at 192.168.0.1 Port 80
```

next I unhash this line in mod_jk file " #jkMount /*.jsp ajp13"

I add my jkmount to my vhost default file and restart server. Every think started fine, but yes but. 

when put 192.168.0.1/index.jsp in my www browser I only see the error page. 

When I make ps aux I can't see tomcat process. Only when It's start I see:

```
apache     459  0.0  0.7  81908  3920 ?        S    16:42   0:00 /usr/sbin/apache2 -D DEFAULT_VHOST -D PHP5 -D USERDIR

apache     460  0.0  0.7  81908  3920 ?        S    16:42   0:00 /usr/sbin/apache2 -D DEFAULT_VHOST -D PHP5 -D USERDIR

tomcat     753 73.7  7.2 333552 36752 ?        Rsl  17:35   0:02 /opt/sun-jdk-1.5.0.10/bin/java -Djava.util.logging.man

```

4 second later the tomcat process disappeared.

In /var/log/mod_jk I only see:

```

[Wed Feb 14 17:22:19 2007] [0457:38928] [info]  ajp_connect_to_endpoint::jk_ajp_common.c (873): Failed opening socket to (127.0.0.1:8009) with (errno=111)

[Wed Feb 14 17:22:19 2007] [0457:38928] [info]  ajp_send_request::jk_ajp_common.c (1259): (ajp13) error connecting to the backend server (errno=111)

[Wed Feb 14 17:22:19 2007] [0457:38928] [info]  ajp_service::jk_ajp_common.c (1916): (ajp13) sending request to tomcat failed,  recoverable operation attempt=1

[Wed Feb 14 17:22:19 2007] [0457:38928] [info]  jk_open_socket::jk_connect.c (451): connect to 127.0.0.1:8009 failed with errno=111

[Wed Feb 14 17:22:19 2007] [0457:38928] [info]  ajp_connect_to_endpoint::jk_ajp_common.c (873): Failed opening socket to (127.0.0.1:8009) with (errno=111)

[Wed Feb 14 17:22:19 2007] [0457:38928] [info]  ajp_send_request::jk_ajp_common.c (1259): (ajp13) error connecting to the backend server (errno=111)

[Wed Feb 14 17:22:19 2007] [0457:38928] [info]  ajp_service::jk_ajp_common.c (1916): (ajp13) sending request to tomcat failed,  recoverable operation attempt=2

[Wed Feb 14 17:22:19 2007] [0457:38928] [error] ajp_service::jk_ajp_common.c (1928): (ajp13) Connecting to tomcat failed. Tomcat is probably not started or is listening on the wrong port

[Wed Feb 14 17:22:19 2007] ajp13 192.168.0.1 0.000843

[Wed Feb 14 17:22:19 2007] [0457:38928] [info]  jk_handler::mod_jk.c (2142): Service error=0 for worker=ajp13

```

First I was thinking about my iptables:

```

#Global variable

IPTABLES='/sbin/iptables'

##Iside Interface

LAN='eth0'

##IP and NETMASK Address

LANIP='192.168.0.0'

LANMAS='255.255.255.0'

##Outside Interface

NET='ppp0'

##Server port

SPORT='20 21 22 80 443 445 8009 8080 8192 8443'

UPORT=' '

#Enable ip forwarding in the kernel

echo 1 >/proc/sys/net/ipv4/ip_forward

#Flush rules

$IPTABLES -F

$IPTABLES -X

##Start firewall

echo "!!!Firewall Starting!!!"

$IPTABLES -P INPUT DROP

$IPTABLES -P FORWARD DROP

$IPTABLES -P OUTPUT ACCEPT

$IPTABLES -A INPUT -i $LAN -j ACCEPT

$IPTABLES -A INPUT -i lo -j ACCEPT

$IPTABLES -A OUTPUT -o lo -j ACCEPT

$IPTABLES -A INPUT -i $NET -m state --state ESTABLISHED,RELATED -j ACCEPT

$IPTABLES -A FORWARD -i $NET -o $LAN -m state --state ESTABLISHED,RELATED -j ACCEPT

$IPTABLES -A FORWARD -i $LAN -o $NET -j ACCEPT

#Server open port

for i in $SPORT

  do 

  $IPTABLES -A INPUT -i $NET -p tcp --dport $i -m state --state NEW,ESTABLISHED -j ACCEPT

  $IPTABLES -A OUTPUT -p tcp --dport $i -m state --state NEW,ESTABLISHED -j ACCEPT

  done

#FTP active

$IPTABLES -A INPUT -p tcp --sport 20 --dport 1024:1050 -m state --state ESTABLISHED,RELATED -j ACCEPT

$IPTABLES -A OUTPUT -p tcp --dport 20 --sport 1024:1050 -m state --state ESTABLISHED -j ACCEPT

#FTP  passive

$IPTABLES -A INPUT -p tcp  --sport 1024:2000 --dport 1024:1050 -m state --state ESTABLISHED -j ACCEPT

$IPTABLES -A OUTPUT -p tcp --sport 1024:2000 --dport 1024:1050 -m state --state ESTABLISHED,RELATED -j ACCEPT

#Masquarade 

$IPTABLES -t nat -A POSTROUTING -o $NET -j MASQUERADE

```

But I disabled it and start Input output forwarded accept and masquerade. 

My start site didn't start. 

When I use netstat -a I don't know why I can't see tomcat listening on 8009 port??

On the end this is my config file :

88_mod_jk

```

<IfDefine JK>

LoadModule jk_module    modules/mod_jk.so

JkWorkersFile   conf/jk-workers.properties

JkLogFile       logs/mod_jk.log

JkLogLevel      info

#I have tomcat 5.5.20-r8 and in this place it has got index.jsp

JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

JkRequestLogFormat "%w %V %T"

jkAutoAlias /var/lib/tomcat-5.5/webapps/ROOT/

jkMount /*.jsp ajp13

</IfDefine>

```

00_default_vhost...

```

NameVirtualHost *:80

<IfDefine DEFAULT_VHOST>

<VirtualHost *:80>

    DocumentRoot "/var/www/localhost/htdocs"

    <Directory "/var/www/localhost/htdocs">

        Options Indexes FollowSymLinks

        AllowOverride None

        Order allow,deny

        Allow from all

    </Directory>

        #TOMCAT 5.5 vhost

        jkMount /*.jsp ajp13

        jkMount /servlet/* ajp13

    <IfModule peruser.c>

        # this must match a Processor

        ServerEnvironment apache apache

        # these are optional - defaults to the values specified in httpd.conf

        MinSpareProcessors 4

        MaxProcessors 20

    </IfModule>

    <IfModule itk.c>

        AssignUserID apache apache

        MaxClientsVHost 50

    </IfModule>

</VirtualHost>

</IfDefine>

```

In tomcat log only catalina.2007-02-14.log isn't empty.

```

Feb 14, 2007 4:35:21 PM org.apache.coyote.http11.Http11BaseProtocol init

INFO: Initializing Coyote HTTP/1.1 on http-8080

Feb 14, 2007 4:35:21 PM org.apache.catalina.startup.Catalina load

INFO: Initialization processed in 2668 ms

Feb 14, 2007 4:35:21 PM org.apache.catalina.core.StandardService start

INFO: Starting service Catalina

Feb 14, 2007 4:35:21 PM org.apache.catalina.core.StandardEngine start

INFO: Starting Servlet Engine: Apache Tomcat/5.5

Feb 14, 2007 4:35:21 PM org.apache.catalina.core.StandardHost start

INFO: XML validation disabled

```

Do you know what I do wrong?? 

Do you know how can I check tomcat running??

----------

## kaarol

Do you know person who successful run tomcat??

Ok I make ps aux >>> start.txt 

and I see:

```
 /opt/sun-jdk-1.5.0.10/bin/java -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/var/lib/tomcat-5.5//conf/logging.properties -Djava.endorsed.dirs=/usr/share/tomcat-5.5//common/endorsed -classpath /usr/share/tomcat-5.5/server/lib/:/usr/share/tomcat-5.5//server/lib:/opt/sun-jdk-1.5.0.10/lib/tools.jar:/usr/share/tomcat-5.5//bin/bootstrap.jar:/usr/share/tomcat-5.5//bin/commons-logging-api.jar -Dcatalina.base=/var/lib/tomcat-5.5/ -Dcatalina.home=/usr/share/tomcat-5.5/ -Djava.io.tmpdir=/var/tmp/tomcat-5.5/ org.apache.catalina.startup.Bootstrap start

```

I put this in my console and Tomcat start runing. I see apache/tomacat-5.5. Ok. But why ?? when i use /etc/init.d/tomcat-5.5 It didn't start??

catalina.2007-02-14.log  hmmm??

```
INFO: XML validation disabled

Feb 14, 2007 8:46:00 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent

INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /opt/sun-jdk-1.5.0.10/jre/lib/amd64/server:/opt/sun-jdk-1.5.0.10/jre/lib/amd64:/opt/sun-jdk-1.5.0.10/jre/../lib/amd64

Feb 14, 2007 8:46:01 PM org.apache.coyote.http11.Http11BaseProtocol init

INFO: Initializing Coyote HTTP/1.1 on http-8080

Feb 14, 2007 8:46:01 PM org.apache.catalina.startup.Catalina load

INFO: Initialization processed in 2485 ms

Feb 14, 2007 8:46:01 PM org.apache.catalina.core.StandardService start

INFO: Starting service Catalina

Feb 14, 2007 8:46:01 PM org.apache.catalina.core.StandardEngine start

INFO: Starting Servlet Engine: Apache Tomcat/5.5

Feb 14, 2007 8:46:01 PM org.apache.catalina.core.StandardHost start

INFO: XML validation disabled

~                                  
```

----------

## kaarol

When I change user in /etc/conf.d/tomcat-5.5 from tomcat to root every thing start nice, but this isn't the best idea.

----------

## wltjr

Sounds like a file was modified or something is owner/group of root instead of Tomcat. Thus changing to root user in /etc/conf.d/tomat-5.5 resolve the problem. I would revert back to the tomcat user/group. Then I would double check all files in /etc/tomcat-5.5 /usr/share/tomcat-5.5 /var/lib/tomcat-5.5 /var/run/tomcat-5.5 and /var/log/tomcat-5.5 are all tomcat:tomcat.

----------

