Ans: Here is the step by step installation process of tomcat 9:
Launch an Linux EC2 instance with the port 22, 80, 8080, 9050. Connect it via any SSH client such PuTTY or MobaXterm or Command prompt terminal or Git Bash or VS code.
After connecting to SSH, paste the following commands and follow the instructions mentioned below.
-> sudo yum install java-17-openjdk-devel -y
[ Not working? Click here ]
#If you were using Redhat and if you get error about redhat server subscription, then you can either sign in to Redhat server and subscribe and use the same in ssh. Or else you can manually download Java Jdk and install it using below commands:
sudo yum update -y
sudo yum install wget -y
sudo mkdir /opt/java-17
wget https://download.java.net/java/GA/jdk17/0d483333a00540d886896bac774ff48b/35/GPL/openjdk-17_linux-x64_bin.tar.gz
sudo tar xf openjdk-17_linux-x64_bin.tar.gz -C /opt/java-17/ --strip-components=1
export JAVA_HOME=/opt/java-17
export PATH=$JAVA_HOME/bin:$PATH
java --version
Note: If you're using amazon Linux or cent OS, then java command might change, please check it online and java home path in tomcat.service file may also change. Instead you can just install it manually by clicking on above link
[Click here]
#If you were using Redhat and if you get error about redhat server subscription, then you can either sign in to Redhat server and subscribe and use the same in ssh. Or else you can manually download Java Jdk and install it using below commands:
sudo yum update -y
sudo yum install wget -y
sudo mkdir /opt/java-17
wget https://download.java.net/java/GA/jdk17/0d483333a00540d886896bac774ff48b/35/GPL/openjdk-17_linux-x64_bin.tar.gz
sudo tar xf openjdk-17_linux-x64_bin.tar.gz -C /opt/java-17/ --strip-components=1
export JAVA_HOME=/opt/java-17
export PATH=$JAVA_HOME/bin:$PATH
java --version
-> sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat
-> cd /tmp
-> wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.105/bin/apache-tomcat-9.0.105.tar.gz
-> sudo tar xf /tmp/apache-tomcat-9.0.105.tar.gz -C /opt/tomcat --strip-components=1
-> sudo chown -R tomcat: /opt/tomcat
-> sudo chmod -R 755 /opt/tomcat
-> sudo vi /etc/systemd/system/tomcat.service
[Unit]Description=Apache Tomcat Web Application ContainerAfter=network.target
[Service]Type=forking
User=tomcatGroup=tomcat
Environment="JAVA_HOME=/opt/java-17"Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"Environment="CATALINA_HOME=/opt/tomcat"Environment="CATALINA_BASE=/opt/tomcat"Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"Environment="JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom"
ExecStart=/opt/tomcat/bin/startup.shExecStop=/opt/tomcat/bin/shutdown.sh
[Install]WantedBy=multi-user.target
-> :wq
-> sudo systemctl daemon-reload
-> sudo systemctl start tomcat
-> sudo systemctl enable tomcat
If you have made any changes or shutdown instance, you need to restart tomcat.
-> sudo systemctl restart tomcat
-> sudo systemctl status tomcat - -> to check status of tomcat
Output: Access the Tomcat dashboard using public IP with port 8080:
http://Server_IP:8080/ - -> (do not use https, it won’t work. Use http) (You can run this command to get public IP: curl ifconfig.me)
Enable the manager and host manager:
-> sudo vi /opt/tomcat/conf/tomcat-users.xml
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<user username="admin" password="admin" roles="manager-gui,admin-gui"/>
copy and paste the above lines at the bottom of he file.
-> :wq
Note: (# manager-gui,admin-gui - Roles assigned to the user, allowing access to both Manager and Host Manager interfaces )
(#you can change the password from "admin" to anything of your choice.)
# comment on the Valve className …. line.
i.e., Before commenting the code, it looks like:
i.e., Before commenting the code, it looks like:
<Context antiResourceLocking="false" privileged="true" ><CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"sameSiteCookies="strict" /><Valve className="org.apache.catalina.valves.RemoteAddrValve"allow="\127\.d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/></Context>
After:
<Context antiResourceLocking="false" privileged="true" ><CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"sameSiteCookies="strict" /><!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve"allow="\127\.d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />--><Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/></Context>
-> :wq
-> sudo vi /opt/tomcat/webapps/host-manager/META-INF/context.xml
Repeat the previous step for host-manager:
After:
<Context antiResourceLocking="false" privileged="true" ><CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"sameSiteCookies="strict" /><!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="\127\.d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />allow="\127\.d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />--><Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>
-> :wq
-> sudo systemctl restart tomcat
Output: Now you can access http://Server_IP:8080/ and click on manager app and host-manager app button or else use: http://Server_IP:8080/manager/html and http://Server_IP:8080/host-manager/html
Enter user: admin
Password: admin
Screenshot of manager:
Change the default Tomcat port to 9050:
-> sudo vi /opt/tomcat/conf/server.xmlUpdate the port number as shown in below line:
Before:
Before:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
After:
<Connector port="9050" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-> :wq
-> sudo systemctl restart tomcat
Output: Access the tomcat using http://Server_IP:9050/
THANK YOU FOR VISITING!
No comments:
Post a Comment
If you have any doubt or question, you can post comment and I will check it.