Wednesday, September 8, 2021

Tomcat 9 install on centos 7 and aws linux 2

 Tomcat9 install on centos 7 and aws linux 2


sudo yum install java-1.8.0-openjdk-devel


java –version


Create Tomcat User and Group

Tomcat should not be run as root. Create a new user and group by entering:


sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat

Download Tomcat 9

Tomcat 9.0.20 is the latest version at the time this was written. A later release may be available on the official download page. Alternately, enter the following:


cd /tmp

wget http://apache.cs.utah.edu/tomcat/tomcat-9/v9.0.20/bin/apache-tomcat-9.0.20.tar.gz

Extract the .tar.gz File

To extract the Tomcat tar.gz file, enter the following:


tar -xf apache-tomcat-9.0.20.tar.gz

Move the files to the /opt/tomcat directory:


sudo mv apache-tomcat-9.0.20 /opt/tomcat/

(Optional) Create a symbolic link for updates:


sudo ln -s /opt/tomcat/apache-tomcat-9.0.20 /opt/tomcat/latest

Modify Tomcat User Permissions

The new users needs to execute privileges over the directory.


Enter the following:


sudo chown -R tomcat:tomcat /opt/tomcat

sudo sh -c 'chmod +x /opt/tomcat/latest/bin/*.sh'

Create a System Unit File

Creating a systems unit file allows Tomcat to run as a service.


1. To create a tomcat.service file, use the command:


sudo nano /etc/systemd/system/tomcat.service

2. In the file, enter the following:


[Unit]

Description=Tomcat 9 servlet container

After=network.target

[Service]

Type=forking

User=tomcat

Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/jre"

Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"

Environment="CATALINA_BASE=/opt/tomcat/latest"

Environment="CATALINA_HOME=/opt/tomcat/latest"

Environment="CATALINA_PID=/opt/tomcat/latest/temp/tomcat.pid"

Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/opt/tomcat/latest/bin/startup.sh

ExecStop=/opt/tomcat/latest/bin/shutdown.sh

[Install]

WantedBy=multi-user.target


3. Save and close the file.


4. Refresh the system:


sudo systemctl daemon-reload

5. Set the Tomcat service to start on boot:


sudo systemctl enable tomcat

6. Start the Tomcat service:


sudo systemctl start tomcat

7. Verify that the Tomcat service is installed and running:


sudo systemctl status tomcat



Adjust the Firewall

The Tomcat service needs access to Port 8080.


Allow traffic by entering the commands:


firewall-cmd --zone=public --permanent --add-port=8080/tcp

firewall-cmd -reload

You should be able to see the Tomcat server in a web browser.


Input this web address into a browser window:


http://server_ip:8080

No comments:

Post a Comment

How to give privilege for access of single aws bucket ..

 {     "Version": "2012-10-17",     "Statement": [         {             "Effect": "Allow"...