Goal
This page presents the Tomcat 8.5 installation procedure.
Contents
Prerequisite
To carry out the installation, it is necessary to have previously installed Java 1.8 (see 1) Starting with basic installation: Java-Maven-Solr-GIT)
Procedures
1- Installing Tomcat
Step | Action |
---|---|
1) Creating the Tomcat directory | sudo mkdir -p /opt/tomcat |
2) Create the group and user 'tomcat'. | sudo groupadd tomcat sudo useradd -s /bin/bash -g tomcat -d /opt/tomcat tomcat |
3) Changing the tomcat password | sudo passwd tomcat Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully |
4) Download Tomcat 8.5The download version of tomcat is currently being updated. Check here to get the latest version (https://www-us.apache.org/dist/tomcat/tomcat-8) | cd /opt/Download sudo wget http://archive.apache.org/dist/tomcat/tomcat-8/v8.5.51/bin/apache-tomcat-8.5.51.zip -P /opt/Download |
5) Installing the tomcat 8.5 distribution in /opt/tomcat | sudo apt install unzip sudo unzip apache-tomcat-8.5.51.zip sudo mv apache-tomcat-8.5.51/* /opt/tomcat sudo chown -R tomcat:tomcat /opt/tomcat sudo chmod +x /opt/tomcat/bin/*.sh sudo usermod -aG sudo tomcat # adding tomcat as sudo-user |
6) Configuring environment variablesAdd CATALINA_HOME="/opt/tomcat" | /etc/environment sudo vi /etc/environment /etc/environment PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/current/bin:/usr/lib/jvm/current/db/bin:/usr/lib/jvm/current/jre/bin:/opt/apache-maven-3.6.3/bin" J2SDKDIR="/usr/lib/jvm/current" J2REDIR="/usr/lib/jvm/current/jre" JAVA_HOME="/usr/lib/jvm/current" MAVEN_HOME=/opt/apache-maven-3.6.3 CATALINA_HOME="/opt/tomcat" |
7) Create the service file to start tomcat | sudo vi /etc/systemd/system/tomcat.service /etc/systemd/system/tomcat.service [Unit] Description=Tomcat 8.5 servlet container After=network.target [Service] Type=forking User=tomcat Group=tomcat Environment="JAVA_HOME=/usr/lib/jvm/current" Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom" Environment="CATALINA_BASE=/opt/tomcat" Environment="CATALINA_HOME=/opt/tomcat" Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid" Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC" ExecStart=/opt/tomcat/bin/startup.sh ExecStop=/opt/tomcat/bin/shutdown.sh [Install] WantedBy=multi-user.target |
8) Operating the tomcat service | sudo systemctl daemon-reload sudo systemctl start tomcat sudo systemctl status tomcat Result ● tomcat.service - Tomcat 8.5 servlet container Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; vendor preset: enabled) Active: active (running) since Wed 2019-11-27 21:58:03 UTC; 4s ago Process: 2258 ExecStart=/opt/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS) Main PID: 2270 (java) Tasks: 52 (limit: 9246) CGroup: /system.slice/tomcat.service └─2270 /usr/lib/jvm/jdk1.8.0_231/bin/java -Djava.util.logging.config.file=/opt/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLog nov. 27 21:58:03 vivo-uqam systemd[1]: Starting Tomcat 8.5 servlet container... nov. 27 21:58:03 vivo-uqam startup.sh[2258]: Tomcat started. nov. 27 21:58:03 vivo-uqam systemd[1]: Started Tomcat 8.5 servlet container. # if there is no error activate tomcat for a boot on server startup sudo systemctl enable tomcat Created symlink /etc/systemd/system/multi-user.target.wants/tomcat.service → /etc/systemd/system/tomcat.service. |
9) Adjusting the firewall | sudo ufw allow 8080/tcp |
10) Test installationDisplay the start page from the server's IP address (Ex.: 192.168.7.144) | sudo reboot -f |
2- Configuring access to Tomcat
Step | Action |
---|---|
1) connect as Tomcat user | sudo -s -u tomcat cd /opt/tomcat |
2) Configure tomcat user accountChanging <must-be-changed> by your password | vi conf/tomcat-users.xml conf/tomcat-users.xml <?xml version="1.0" encoding="UTF-8"?> <tomcat-users xmlns="http://tomcat.apache.org/xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd" version="1.0"> <role rolename="manager-gui"/> <role rolename="tomcat"/> <user username="vivo" password="<must-be-changed>" roles="manager-gui,tomcat"/> </tomcat-users> |
3) Configure for management in remote access mode | vi ./webapps/manager/META-INF/context.xml Replace the text with this one ./webapps/manager/META-INF/context.xml <?xml version="1.0" encoding="UTF-8"?> <Context antiResourceLocking="false" privileged="true" > <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow=".*"/> </Context> |
4) Restart tomcat and manage | systemctl restart tomcat Click on the "Manager App" Enter the user's name and password as defined in step 2) |
TOMCAT IS NOW READY