Monday, November 11, 2024
Apache Tomcat Debian DevOps Ubuntu

Cara Install Tomcat 9 pada Ubuntu 20.04 / Debian 11

tomcat

“Cara Install Tomcat 9 pada Ubuntu 20.04 / Debian 11”

Pendahuluan

Apache Tomcat adalah server web sumber terbuka dan wadah servlet Java. Ini adalah salah satu pilihan paling populer untuk membangun situs web dan aplikasi berbasis Java. Tomcat ringan, mudah digunakan, dan memiliki ekosistem add-on yang kuat.

Install Java

sudo apt updat
sudo apt install openjdk-11-jdk
  • Cek Java Version
java -version

Membuat User Tomcat

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

Download Tomcat

wget https://www-eu.apache.org/dist/tomcat/tomcat-9/v${VERSION}/bin/apache-tomcat-${VERSION}.tar.gz -P /tmp
  • Ektract File
sudo tar -xf /tmp/apache-tomcat-${VERSION}.tar.gz -C /opt/tomcat/
  • Buat Symlink
sudo ln -s /opt/tomcat/apache-tomcat-${VERSION} /opt/tomcat/latest
  • Buat Owner file
sudo chown -R tomcat: /opt/tomcat
  • Buat permission file
sudo sh -c 'chmod +x /opt/tomcat/latest/bin/*.sh'

Membuat Systemd service

  • Buat file
sudo nano /etc/systemd/system/tomcat.service
  • Isi file
[Unit]
Description=Tomcat 9 servlet container
After=network.target

[Service]
Type=forking

User=tomcat
Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom -Djava.awt.headless=true"

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
  • Reload service
sudo systemctl daemon-reload
  • Enable service
sudo systemctl enable --now tomcat
  • Cek status
sudo systemctl status tomcat

Konfigurasi Firewall

sudo ufw allow 8080/tcp

Konfigurasi Tomcat Web Management Interface

sudo nano /opt/tomcat/latest/conf/tomcat-users.xml
<tomcat-users>
<!--
    Comments
-->
   <role rolename="admin-gui"/>
   <role rolename="manager-gui"/>
   <user username="admin" password="admin_password" roles="admin-gui,manager-gui"/>
</tomcat-users>
sudo nano /opt/tomcat/latest/webapps/manager/META-INF/context.xml
<Context antiResourceLocking="false" privileged="true" >
<!--
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->
</Context>
  • Restart service
sudo systemctl restart tomcat

Akses GUI via web

http://<your_domain_or_IP_address>:8080

http://<your_domain_or_IP_address>:8080/manager/html
http://<your_domain_or_IP_address>:8080/host-manager/html

Penutup

Sahabat Blog Learning & Doing demikianlah penjelasan mengenai Cara Install Tomcat 9 pada Ubuntu 20.04 / Debian 11. Semoga Bermanfaat . Sampai ketemu lagi di postingan berikut nya.

(Visited 477 times, 1 visits today)

Similar Posts