Centos – Tomcat and Jenkins separately on the same server

centoscentos7Jenkinstomcat

I have never installed Jenkins as package on CentOS, but now I tried and it doesn't seem to work correctly side-by-side with standalone Tomcat server.

First of all, I installed tomcat by yum install tomcat (I'm using CentOS 7).

Next, I added Jenkins repo and ran yum install jenkins. It didn't start from scratch as Tomcat was running and the port was binded. I've set port in /ect/sysconfig/jenkins to 8081.

Now it seems to work fine, Jenkins up and running.

However, I can't start Tomcat as Caused by: java.net.BindException: Address already in use <null>:8009.

The same goes if I first start tomcat and then start jenkins: jenkins fails with Failed to start Jetty. How can I manage the both, not installing Jenkins manually into tomcat by jenkins.war?

Best Answer

Port 8009 is typically used for the AJP Connector in Tomcat. It is often used to communicate between Apache and Tomcat.

It sounds like both Jenkins and Tomcat are setting up an AJP Connector to listen on port 8009. The server.xml file for Tomcat will have it listed as:

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

Change it to listen on another port, and change whatever is talking to it (probably httpd) to use that other port. Or get rid of the Connector entirely in one or both of the servers if you aren't using it.

If Jenkins is using another copy of Tomcat itself, that instance will have it's own server.xml somewhere. If Jenkins is using it's own container (e.g, Winstone), there might be a similar configuration file somewhere.

That will get rid of the java.net.BindException.

In Tomcat, the default HTTP Connector port is 8080. If Jenkins was using 8080 by default, then the HTTP Connector port is probably what you changed to 8081 in /etc/sysconfig/jenkins.