- Install java
sudo apt -y install openjdk-8-jdk && sudo apt -y install openjdk-8-jre
- Configure date America/Lima
sudo timedatectl set-timezone America/Lima
- Download tomcat
wget https://dlcdn.apache.org/tomcat/tomcat-8/v8.5.94/bin/apache-tomcat-8.5.94.tar.gz -O /tmp/tomcat-8.5.94.tar.gz
wget https://ftp.unicamp.br/pub/apache/tomcat/tomcat-8/v8.5.94/bin/apache-tomcat-8.5.94.tar.gz -O /tmp/tomcat-8.5.94.tar.gz
- Create User Tomcat
sudo useradd -m -d /opt/tomcat -U -s /bin/false tomcat
- Install Tomcat
sudo -u tomcat tar -xzvf /tmp/tomcat-8.5.94.tar.gz --strip-components=1 -C /opt/tomcat
- create file
nano /etc/systemd/system/tomcat.service
- put content:
[Unit]
Description=Apache Tomcat
After=network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
Environment=CATALINA_PID=/opt/tomcat/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
ExecReload=/bin/kill $MAINPID
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
- Run the following command to reload the systemd manager configuration
- To run Tomcat now and make the service run upon reboot, we can run this command:
systemctl enable --now tomcat
- route trafic 80 and 443
sudo /sbin/iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
sudo /sbin/iptables -t nat -I PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 8443
- stop and start Tomcat
sudo service tomcat stop
sudo service tomcat start
- 403 Access Denied /usr/local/tomcat/webapps/manager/META-INF/context.xml comment
<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />-->
- enable user access to manager in /opt/tomcat/conf/tomcat-users.xml
<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<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">
<!--
NOTE: By default, no user is included in the "manager-gui" role required
to operate the "/manager/html" web application. If you wish to use this app,
you must define such a user - the username and password are arbitrary.
-->
<!--
NOTE: The sample user and role entries below are wrapped in a comment
and thus are ignored when reading this file. Do not forget to remove
<!.. ..> that surrounds them.
-->
<user username="myUser" password="myPassword" roles="manager-gui"/>
</tomcat-users>
sudo service tomcat restart