Terry : Upgrade Tomcat for Confluence

Upgrade Tomcat For Confluence

Upgrade history: 6.0.18, 6.0.20, 6.0.36, 6.0.37, 6.0.39, 6.0.41.

To be able to use Tomcat 7, Confluence version needs to be updated ;-D

The process is similar to initial installation.

Install / Upgrade Confluence

Steps to Install/Upgrade

1. Download the latest version from http://tomcat.apache.org

2. Extract the tarball, for example /opt/tomcat, change ownership recursively to www-data user (the user which is used to run apache, nginx and tomcat)

chown www-data:www-data /opt/tomcat/ -R

3. Download MySQL Connector/J, place mysql-connector-java-<version>.jar in $CATALINA_HOME/lib

4. Edit $CATALINA_HOME/bin/catalina.sh, search for JAVA_OPTS block and increase initial heap size and run JVM in server mode -server -Xms256m -Xmx512m

if [ -z "$LOGGING_MANAGER" ]; then
  JAVA_OPTS="$JAVA_OPTS -server -Xms256m -Xmx512m -XX:MaxPermSize=256m -Dhttp.proxyHost=proxy.company.com -Dhttp.proxyPort=80 -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
else
  JAVA_OPTS="$JAVA_OPTS $LOGGING_MANAGER"
fi

5. Extract confluence tar ball to /opt/confluence, edit confluence-init.properties

confluence.home=/opt/wiki/data
confluence.backup.path.set.allowed=true

6. Configure context and data source for Confluence

mkdir -pv /opt/tomcat/conf/Catalina/localhost
chown www-data:www-data /opt/tomcat/conf/Catalina/localhost/ -R

Create /opt/tomcat/conf/Catalina/localhost/confluence.xml

confluence.xml
<Context path="/confluence" docBase="/opt/confluence/confluence" debug="0" reloadable="true">
<Resource name="jdbc/confluence" auth="Container" type="javax.sql.DataSource"
         username="confluenceuser"
         password="confluenceuser_password"
         driverClassName="com.mysql.jdbc.Driver"
         url="jdbc:mysql://localhost:3306/confluence?autoReconnect=true"
         maxActive="15"
         maxIdle="7"
         validationQuery="Select 1" />
</Context> 

7. Configure Tomcat for front-end reverse proxy

Backup and edit $CATALINA_HOME/conf/server.xml

cp /opt/tomcat/conf/server.xml{,.bak} 

Find Connector port="8080" block and make it look like below, proxyName is the FQDN of the front-end reverse proxy (apache or nginx)

    <Connector port="8080" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true"
               proxyName="tux.apac.lab" proxyPort="80"
               URIEncoding="UTF-8" />

9. Configure MySQL for READ-COMMITTED transaction-isolation and UTF-8 charsets

/etc/mysql/conf.d/confluence.cnf
# Required by confluence 3.5 and above
[mysqld]
transaction-isolation = READ-COMMITTED 

Charset

/etc/mysql/conf.d/charset.cnf
[client]
default-character-set = utf8
[mysql]
default-character-set = utf8
[mysqld]
# default-character-set = utf8
collation-server = utf8_unicode_ci
init-connect = 'SET NAMES utf8'
character-set-server = utf8 

10. Use mysql or phpMyAdmin to create user, allow only local connection (loopback), run mysql_secure_installation to secure MySQL if necessary

11. Create schema, grant privilege to user

12. Run installer if it's a new installation, otherwise it's done!

Shell script to start and stop Tomcat

Bash script

tomcat.sh
#!/bin/bash
#
# tomcat.sh
#
# Description: Start or stop tomcat for confluence 
# Short-Description: start or stop tomcat
# Set JAVA_HOME
source /opt/java.sh
echo `java -version`
case "$1" in
    start)
        echo "Starting tomcat..."
        su -c '/opt/tomcat-6.0.36/bin/./startup.sh' www-data
        echo "Done."
    ;;
    stop)
        echo "Stopping tomcat..."
        su -c '/opt/tomcat-6.0.36/bin/./shutdown.sh' www-data
        echo "Done."
    ;;
    *)
        echo "Usage: tomcat.sh {start|stop}"
        exit 1
esac 

A better Tomcat startup script from Ansible examples - tomcat-initscript.sh

Start Tomcat during boot

  1. Write a tomcat startup script in /etc/init.d/tomcat
  2. Invoke update-rc.d to run Tomcat as service (sysv-rc-conf is an alternative)

    update-rc.d tomcat enable
    update-rc.d tomcat defaults

    Or manually create symbolic links to the startup script in corresponding /etc/rcX.d/ directory.

    RHEL, OEL or CentOS equivalent

    chkconfig --level 345 tomcat on

    systemd (Arch Linux, Fedora, openSUSE) way is different. Need to create a unit file for Tomcat and enable it.

NOTE: Keep the old version of Tomcat for a while until you make sure the new version works well with current Confluence version.

Reference

Configuring a MySQL Datasource in Apache Tomcat

Configure Web Proxy Support for Confluence