Site icon Learning & Doing

Install Apache Tomcat pada Rocky Linux

tomcat

Pada kesempatan kali ini saya akan membahas Cara Install Apache Tomcat pada Rocky Linux.

ya langsung saja kita mulai :

1. Install OpenJDK

dnf install java-11-openjdk wget tar

- cek version

java -version

2. download apache tomcat

wget https://downloads.apache.org/tomcat/tomcat-10/v10.0.8/bin/apache-tomcat-10.0.8.tar.gz

3. install apache tomcat

mkdir /opt/tomcat

tar xzf apache-tomcat-10.0.8.tar.gz -C /opt/tomcat --strip-components=1

4. Setting Apache Tomcat 

- set Catalina Home

echo 'export CATALINA_HOME="/opt/tomcat"' > /etc/profile.d/tomcat.sh

- set java home

alternatives --list | grep java

echo 'export JAVA_HOME="/usr/lib/jvm/java-11-openjdk-11.0.12.0.7-0.el8_4.x86_64"' >> /etc/profile.d/tomcat.sh

- reload config

source /etc/profile.d/tomcat.sh

5. Create Apache Tomcat System User

useradd -r -d /opt/tomcat/ -s /bin/false -c "Apach Tomcat User" tomcat
chown -R tomcat: /opt/tomcat/

6. Configure Tomcat Web Management Accounts

nano /opt/tomcat/conf/tomcat-users.xml

- edit bagian

  <role rolename="admin-gui"/>
  <role rolename="manager-gui"/>
  <user username="admin" password="admin123" roles="admin-gui,manager-gui"/>

- allow IP

nano /opt/tomcat/webapps/manager/META-INF/context.xml

allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.168.3.4" />

nano /opt/tomcat/webapps/host-manager/META-INF/context.xml

allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.168.3.4" />

7. Setting Firewall

firewall-cmd --add-port=8080/tcp --permanent
firewall-cmd --reload

8. Running Tomcat

/opt/tomcat/bin/startup.sh

- cek log

tail /opt/tomcat/logs/catalina.out

9. akses web

http://server-hostname-or-ip:8080

10. membuat service

cat > /etc/systemd/system/tomcat.service << 'EOL'
[Unit]
Description=Apache Tomcat Server
After=syslog.target network.target

[Service]
Type=forking
User=tomcat
Group=tomcat

Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat

ExecStart=/opt/tomcat/bin/catalina.sh start
ExecStop=/opt/tomcat/bin/catalina.sh stop

RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target
EOL

- reaload system

systemctl daemon-reload

- kill process

ps aux | grep tomcat | grep -v grep | awk '{print $2}' | xargs -I {} kill -9 {}

- set owner log

chown -R tomcat: /opt/tomcat/logs/

- up service

systemctl enable --now tomcat
systemctl status tomcat
Exit mobile version