How to Install and Customize AWS EC2 for Apache Tomcat
Introduction:
Java-based web applications can be executed using the well-liked open-source web server and servlet container Apache Tomcat. Installing and configuring Apache Tomcat on a server running on AWS EC2 is explained in this blog post. We'll also walk you through accessing the Tomcat web interface and managing Tomcat using command-line tools.
Step 1: Install Java on the Computer
SSH into your EC2 instance.
Install Java using the amazon-linux-extras command.
#sudo amazon-linux-extras install java-openjdk11 -y
Step 2: Install Apache Tomcat
Switch to the root user.
#sudo su -
Navigate to the /opt directory.
#cd /opt
Download the Apache Tomcat binary.
wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.11/bin/apache-tomcat-10.1.11.tar.gz
Unzip the Tomcat binary.
tar -xvzf apache-tomcat-10.1.11.tar.gz
Step 3: Include Execute Permission to Startup and Shutdown Scripts
Change the current directory to the Tomcat bin folder.
cd apache-tomcat-10.1.11/bin
Add execute permission to the ' startup. sh' and ‘shutdown. sh,' scripts.
chmod +x startup.sh chmod +x shutdown.sh
Step 4: Create Links for Tomcat Server Start and Stop
Create symbolic links for easy Tomcat server startup and shutdown.
ln -s /opt/apache-tomcat-10.1.11/bin/startup.sh /usr/local/bin/tomcatup ln -s /opt/apache-tomcat-10.1.11/bin/shutdown.sh /usr/local/bin/tomcatdown
Step 5: Configure Tomcat
Find all the ‘context.xml’ files within the Tomcat directory.
cd /opt/apache-tomcat-10.1.11 find -name context.xml
Open each context.xml file using a text editor (vim) and comment the line with the RemoteAddrValve.
For Example:
<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> -->
Step 6: Update User Information in tomcat-users.xml
Open the ‘tomcat-users.xml’ file for editing.
cd /opt/apache-tomcat-10.1.11/conf vi tomcat-users.xml
Add the following lines between the <tomcat-users> tags to set up user roles.
<role rolename="manager-gui"/> <role rolename="manager-script"/> <role rolename="manager-jmx"/> <role rolename="manager-status"/> <user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status"/> <user username="deployer" password="deployer" roles="manager-script"/> <user username="tomcat" password="s3cret" roles="manager-gui"/>
Save the file and exit the text editor.
Step 7: Start the Tomcat Server
Start the Tomcat server using the symbolic link.
tomcatup
Step 8: Access the Tomcat Web Interface
Open your web browser and navigate to <http://<your_server_public_ip>:8080.>
You will see the Tomcat web interface, and you can log in using the credentials you set up in the Tomcat-users.xml file.
Conclusion:
Best wishes! Your Amazon Web Services (AWS) EC2 instance now has Apache Tomcat installed and configured successfully. You may now begin deploying Java-based web apps and monitoring and controlling them with the Tomcat management interface.
Website: https://cloudzenix.in/
Contact us: +91 8867891407
Comments
Post a Comment