Install and Configure Tomcat Server and Web Interface
KodeKloud Engineer —DevOps Engineer Task
In this task, proposed here, We need to install and configure Tomcat server for our JAVA web app The full prompt goes as follows:
Question : The Nautilus application development team recently finished the beta version of one of their Java-based applications, which they are planning to deploy on one of the app servers in Stratos DC. After an internal team meeting, they have decided to use the tomcat application server. Based on the requirements mentioned below complete the task:
a. Install tomcat server on App Server 2 using yum.
b. Configure it to run on port 5001.
c. There is a ROOT.war file on Jump host at location /tmp. Deploy it on this tomcat server and make sure the webpage works directly on base URL i.e without specifying any sub-directory anything like this http://URL/ROOT .
Note :- Perform commands based on your question ie server, user name & other details might be different so modify the commands accordingly
1. You will be on jump server you need to Login on App server as per the task given “ ssh steve@stapp02 ” and become sudo user with “ sudo su ” command (you can find out the architecture and wiki in side bar )
2. Check is package is present already with “sudo yum list — installed | grep tomcat” if not then install Tomcat with command “yum install tomcat -y” and verify installed version with “rpm -qa |grep tomcat” and then check the current status of tomcat with “systemctl status tomcat”
3.Edit the config file of the tomcat server and change the Connector port of non-ssl as per mentioned in the task
“vi /usr/share/tomcat/conf/server.xml”
4. copy war file from tmp to tomcat root directory with the command
“cp /tmp/ROOT.war /usr/share/tomcat/webapps” check the file is copied successfully with “ ll /usr/share/tomcat/webapps/”
5. Start the tomcat service “ systemctl start tomcat” & check the status “systemctl status tomcat”
6. Validate the task with command “ curl -i http://stapp02:5001” if you mange to get the HTML page as a response that means the above configuration is successful.
7. After configuring and verifying click on Finish & Confirm to complete the task successful
Configure & Manage the Apache Tomcat with Tomcat Web Management Interface
Tomcat can be managed through the web-manager and we can Deploy new application, deploy application on specified context, list the active or in active applications, start and stop the web applications.
Web manager is password protected, requires user name and password to access. Only the user with the “manager-gui” role is allowed to access, these users and roles are defined in tomcat-users.xml. By default “manager-gui” role not defined that file, we need to add it manually
At this point Tomcat installation is completed, and we can access it with a web browser, but we can not access the web management interface because we have not created a user yet. Tomcat users and their roles are defined in “vi /opt/tomcat/latest/conf/tomcat-users.xml” file.
You will see that it is filled with comments and examples describing how to configure the file. To add a new user which will able to access the tomcat web interface (manager-gui and admin-gui) you need to mention in this file.
By default Tomcat web management interface is configured to allow access only from the localhost. If you want to be able to access the web interface from a remote IP or from anywhere ( its a security risk ) then you can edit the file called “vi /opt/tomcat/latest/webapps/manager/META-INF/context.xml” with this command and remove or comment Valve block
If you want to configure web interface which can be access only from a specific IP add your public IP to the list. Let’s assume your public IP is 10.10.10.10 and you want to allow access only from that IP then make the changes as below in the file
Once finish restart Tomcat service for changes to take effect with command “sudo systemctl restart tomcat”
Open your browser and type: http://<your_domain_or_IP_address>:PORT