In this post we will walk through how to install Apache Tomcat 9 on Ubuntu Server 17.10.
This will be a quick post on installing Apache Tomcat 9. I have several articles (and a book or two) that deal with automating deploying Tomcat applications to a Tomcat server using Puppet and other automation. If you don’t have a Tomcat server setup then this post will get you started.
First we need to install Java and some building tools that will definitely need later.
# apt install openjdk-9-jdk # apt install build-essential
Installing Apache Tomcat 9
Lets begin by downloading the binaries for Ubuntu and moving them to a good location.
wget http://mirror.olnevhost.net/pub/apache/tomcat/tomcat-9/v9.0.4/bin/apache-tomcat-9.0.4.tar.gz # tar -xzvf apache-tomcat-9.0.4.tar.gz # mkdir /usr/local/bin/tomcat # cp -aR apache-tomcat-9.0.4/* /usr/local/bin/tomcat
Now we need to make sure the permissions are good.
chown -R tomcat:tomcat /usr/local/bin/tomcat
SystemD Service Management
Now we need to configure SystemD to be able to manage our Tomcat service for us. Create a new file /etc/systemd/system/tomcat.service and enter the following contents:
# Systemd unit file for tomcat [Unit] Description=Apache Tomcat Web Application Container After=syslog.target network.target [Service] Type=forking Environment=JAVA_HOME=/usr/lib/jvm/java-9-openjdk-amd64 Environment=CATALINA_PID=/usr/local/bin/tomcat/temp/tomcat.pid Environment=CATALINA_HOME=/usr/local/bin/tomcat Environment=CATALINA_BASE=/usr/local/bin/tomcat Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC' Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom' ExecStart=/usr/local/bin/tomcat/bin/startup.sh ExecStop=/bin/kill -15 $MAINPID User=tomcat Group=tomcat UMask=0007 RestartSec=10 Restart=always [Install] WantedBy=multi-user.target
Reload SystemD configurations and start our new Tomcat service.
# systemctl daemon-reload # systemctl start tomcat # systemctl enable tomcat
Fixing Tomcat Security
Now that we have Tomcat installed we have to configure access to the management applications. First we will create an admin user that we can use to login to the management applications.
In the tomcat-users section add a line for our new user.
<tomcat-users> <user username="admin" password="topsecret" roles="manager-gui,admin-gui"/> </tomcat-users>
Next we need to allow access to the management applications from any server because by default it only allows access from localhost.
# vim /usr/local/bin/tomcat/webapps/manager/META-INF/context.xml
Delete this line:
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
And do the same for this file:
# vim /usr/local/bin/tomcat/webapps/host-manager/META-INF/context.xml
Finally, restart tomcat.
# systemctl restart tomcat
You can now access the web interface and login with your information.
We now know how to install Apache Tomcat 9 on Ubuntu 17.10
I hope you have enjoyed this article, if so please leave a comment below. For more articles, please signup for the AdminTome Blog below. Also please feel free to share the article to your friends using the buttons to the left. Thanks again for reading this post.