Skip to content

Instantly share code, notes, and snippets.

@ilbunilcho
Last active November 1, 2018 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilbunilcho/7bc84d6a6874a4719182483faf88d3fb to your computer and use it in GitHub Desktop.
Save ilbunilcho/7bc84d6a6874a4719182483faf88d3fb to your computer and use it in GitHub Desktop.
Tomcat7+jenkins on CentOS

install Tomcat7

$ su -
$ wget http://apache.tt.co.kr/tomcat/tomcat-7/v7.0.42/bin/apache-tomcat-7.0.42.tar.gz
$ tar xvzf apache-tomcat-7.0.42.tar.gz
$ mv apache-tomcat-7.0.42 /usr/local/
$ ln -s apache-tomcat-7.0.42 tomcat7
$ useradd tomcat
$ chown -R tomcat.tomcat tomcat7
$ touch /etc/init.d/tomcat7
$ chmod 755 /etc/init.d/tomcat7
$ chkconfig --level 2345 --add tomcat7
$ chkconfig --list tomcat7

tomcat7 init script

#!/bin/sh

JAVA_HOME=/usr/local/java
CATALINA_HOME=/usr/local/tomcat7
export JAVA_HOME CATALINA_HOME

CATALINA_BASE=$CATALINA_HOME
CATALINA_TMPDIR=$CATALINA_HOME/temp

# chkconfig: 2345 99 99
# description: Tomcat7 servlet engine
#
### BEGIN INIT INFO
# Provides: Tomcat7
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Description:
### END INIT INFO

set -e

NAME=tomcat7
DESC="Tomcat servlet engine"

if [ `id -u` -ne 0 ]; then
    echo "You need root privileges to run this script"
    exit 1
fi

case $1 in
	start)
		$CATALINA_HOME/bin/startup.sh
    ;;
    stop)
        $CATALINA_HOME/bin/shutdown.sh
	;;
	restart)
		$CATALINA_HOME/bin/shutdown.sh
        $CATALINA_HOME/bin/startup.sh
    ;;
esac

exit 0

tomcat-users.xml

/conf/tomcat-users.xml
<tomcat-users>
    <role rolename="admin-gui" />
    <role rolename="manager-gui" />
    <role rolename="manager-jmx" />
    <user username="tomcat" password="tomcat" roles="admin-gui, manager-gui" />
    <user username="manager" password="manager" roles="manager-jmx" />
</tomcat-users>

check manual: http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html The HTML interface is protected against CSRF but the text and JMX interfaces are not. To maintain the CSRF protection:

Users with the manager-gui role should not be granted either the manager-script or manager-jmx roles. If the text or jmx interfaces are accessed through a browser (e.g. for testing since these interfaces are intended for tools not humans) then the browser must be closed afterwards to terminate the session.

using nio

/conf/server.xml

<Connector executor="tomcatThreadPool"
port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" connectionTimeout="20000" redirectPort="8443" />

<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" keystoreFile="/usr/local/tomcat7/conf/keystore" keystorePass="tomcat7" />

make keystore file

$ keytool -genkey -alias tomcat7 -keyalg RSA -keystore /usr/local/tomcat7/conf/keystore

apr

sudo ./configure --with-apr=/usr/bin/apr-1-config --with-java-home=/usr/local/java/ --with-ssl=/usr/lib64/openssl/

sudo make

sudo make install

/conf/server.xml

  • before: <Connector protocol="HTTP/1.1" .. />
  • after: <Connector protocol="org.apache.coyote.http11.Http11AprProtocol" .. />

/bin/setenv.sh

CATALINA_OPTS="$CATALINA_OPTS -Djava.library.path=/usr/local/apr/lib/"

jenkins

https://wiki.jenkins-ci.org/display/JENKINS/Tomcat

$ wget http://mirrors.jenkins-ci.org/war/latest/jenkins.war
$ mv jenkins.war /usr/local/tomcat7/webapps/
$ useradd -g tomcat jenkins

/bin/setenv.sh

CATALINA_OPTS="$CATALINA_OPTS -Djava.library.path=/usr/local/apr/lib/ -DJENKINS_HOME=/home/jenkins/"

/conf/tomcat-users.xml

    <role rolename="admin" />
    <role rolename="admin-gui" />
    <role rolename="manager-gui" />
    <role rolename="manager-jmx" />
    <user username="tomcat" password="tomcat" roles="admin, admin-gui,manager-gui" />
    <user username="manager" password="manager" roles="manager-jmx" />

resolving startup errors in VM

"Could not intialize the host network interface on nullbecause of an error"

/bin/setenv.sh

CATALINA_OPTS="$CATALINA_OPTS -Djava.library.path=/usr/local/apr/lib/ -DJENKINS_HOME=/home/jenkins/ -Dhudson.DNSMultiCast.disabled=true"

turn off DNSMultiCast

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment