/ Installation  

The secret of successful installing Tomcat

Hi there AppWorks fans,

Welcome to a new installment of AppWorks tips.

This guide will help you installing the Tomcat application server on our Java supported RHEL VM image. The instance of Tomcat is used to host the OpenText Directory Services that will handle the authentication for our AppWorks platform.


Let get right into it…

Start the Oracle VM VirtualBox tooling and start-up our image. Leave the image as is and make a connection with PuTTY.

Our VM already has a supported java version installed.

tomcat_001

You can check with java --version. Also, Tomcat must be a specific version as the documentation (OTDS release notes) will tell us.

FYI: Since OTDS 22.1.X, we see an upgrade in Tomcat support to version 10 (10.0.20 in my case), and a move to a database to save data. Keep the installation manual ready on this one. Here some notes from my experience (during an AWP 22.2 installation):

  • Database name: otds_db
  • Make connection (you require that hostname!): psql -U postgres -W -h appworks-22-2.mydomain.com otds_db
  • Database JDBC connection string: jdbc:postgresql://appworks-22-2.mydomain.com:5432/otds_db
  • NO OpenDJ service since 22.1

tomcat_002

Next, we need the URL from where we can download Tomcat. This can be found here (for the version 8.5 that is required for our image): Tomcat 8.5.43

wget https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.43/bin/apache-tomcat-8.5.43.tar.gz

After the download is done, we need to extract the file: tar xvf apache-tomcat-8.5.43.tar.gz

Let’s move it all to a nice location with a service to start/stop it:

  • Create a directory: sudo mkdir /opt/tomcat

  • Move the extracted folder: sudo mv apache-tomcat-8.5.43/ /opt/tomcat/

  • Own the new folder by the ‘sysadmin’ user: sudo chown -R sysadmin:sysadmin /opt/tomcat/

    Don’t be smart like me to use the ‘tomcat’ user as we did for the TomEE instance. OTDS is handling things differently!

  • Make a nice link to it: sudo ln -s /opt/tomcat/apache-tomcat-8.5.43/ /opt/tomcat/latest

    Don’t use this link in any other configuration file like the tomcat.service or the system variables like the CLASSPATH as it fails in the OTDS installation…My own experience!

  • Create a cool service for it: sudo vi /usr/lib/systemd/system/tomcat.service

Add this content to the new file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[Unit]
Description=Tomcat 8.5 servlet container
After=network.target

[Service]
Type=forking

User=sysadmin
Group=sysadmin

Environment="JAVA_HOME=/usr/lib/jvm/java-11-openjdk"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"

Environment="CATALINA_BASE=/opt/tomcat/apache-tomcat-8.5.43"
Environment="CATALINA_HOME=/opt/tomcat/apache-tomcat-8.5.43"
Environment="CATALINA_PID=/opt/tomcat/apache-tomcat-8.5.43/temp/tomee.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/opt/tomcat/apache-tomcat-8.5.43/bin/startup.sh
ExecStop=/opt/tomcat/apache-tomcat-8.5.43/bin/shutdown.sh

[Install]
WantedBy=multi-user.target

Now save the file :w and quit vi with :q


Next step is to change the default port numbers as we also have TomEE running on the already in use port 8080.

Edit the server.xml sudo vi /opt/tomcat/latest/conf/server.xml

Change the next port numbers:

1
2
3
4
5
6
7
<Server port="8006" shutdown="SHUTDOWN"> <!-- was 8005 -->
...
<Connector port="8181" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8444" /> <!-- was 8080 and 8443 -->
...
<Connector port="8444" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150" SSLEnabled="true"> <!-- was 8443 -->
...
<Connector port="8010" protocol="AJP/1.3" redirectPort="8444" /> <!-- was 8009 and 8443 -->

Save and quit the file :wq


Last steps…

  • Reload the services daemon as we changed it with a new service: systemctl daemon-reload
  • Enable the tomee service: systemctl enable tomcat.service
  • Now the big moment where we all waited for: systemctl start tomcat.service

Check if it’s all running fine by browsing with your local machine to the URL: http://192.168.56.107:8181

For log file monitoring use the tail command: sudo tail -f /opt/tomcat/latest/logs/catalina.out


Now let’s add tomcat users

Edit the tomcat-users.xml file: sudo vi /opt/tomcat/latest/conf/tomcat-users.xml

Add these lines just before the last end-tag </tomcat-users>

1
<user username="tomcat" password="tomcat" roles="admin-gui,manager-gui,tomee-admin" />

Make sure the role names are is typed in correctly with the ‘-‘ in between


Make the ‘manager’ and ‘host-manager’ apps available for remote users (like our local machine!)

Create and edit a new file with the name ‘manager.xml’

sudo vi /opt/tomcat/latest/conf/Catalina/localhost/manager.xml

Add this content to it

1
2
3
<Context privileged="true" antiResourceLocking="false" docBase="${catalina.home}/webapps/manager">
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
</Context>

Create and edit a new file with the name ‘host-manager.xml’

sudo vi /opt/tomcat/latest/conf/Catalina/localhost/host-manager.xml

Add this content to it

1
2
3
<Context privileged="true" antiResourceLocking="false" docBase="${catalina.home}/webapps/host-manager">
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
</Context>

Restart tomcat systemctl restart tomcat.service and check the result on these URL’s. They should both give a pop-up for ‘HTTP Basic authentication’ where you can use the credentials as described in the tomcat-users.xml

http://192.168.56.107:8181/host-manager/html

http://192.168.56.107:8181/manager/html


As a final step is the proper way to add the correct environment variables for the Tomcat instance.

Edit the ~/.bash_profile again for the ‘sysadmin’ user: vi ~/.bash_profile

The final version should look like this for now:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

CLASSPATH=$CLASSPATH:/opt/tomee/apache-tomee-plus-8.0.0-M2/lib/postgresql-42.2.5.jar:/opt/opentext/AppWorksPlatform/defaultInst/cordyscp.jar
export CLASSPATH

JAVA_HOME=/usr/lib/jvm/java-11-openjdk
export JAVA_HOME

PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH

LIB_PATH=/usr/lib/jvm/java-11-openjdk/lib/server/

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIB_PATH:/opt/opentext/AppWorksPlatform/defaultInst/lib:/opt/documentum/product/16.4/bin
export LD_LIBRARY_PATH

CATALINA_HOME=/opt/tomee/apache-tomee-plus-8.0.0-M2
export CATALINA_HOME

TOMCAT_HOME=/opt/tomcat/apache-tomcat-8.5.43
export TOMCAT_HOME

When done reload your profile via the command: source ~/.bash_profile

Check if it’s all OK via: env | grep tomcat


And that’s a big ‘DONE’ for this installment of AppWorks tips where we installed Tomcat. This instance can now be used for hosting the OTDS instance we will install in the next post.

Let me know what you think in the comments and have a good one for today…See U next time!

Don’t forget to subscribe to get updates on the activities happening on this site.