Wednesday, November 13, 2024
Apache Tomcat Centos Centos 8 DevOps

Cara Install Tomcat 9 pada CentOS 8

tomcat

“Cara Install Tomcat 9 pada CentOS 8”

Apache Tomcat adalah implementasi open-source dari Java Servlet, JavaServer Pages, Java Expression Language, dan teknologi Java WebSocket. Ini adalah salah satu aplikasi dan server web yang paling banyak diadopsi di dunia saat ini. Tomcat mudah digunakan dan memiliki ekosistem add-on yang kuat.

Cara Install Tomcat 9 pada CentOS 8

1. Install Java

  • Install
sudo dnf install java-11-openjdk-devel
java -version

2. Buat User untu tomcat

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

3. Download Tomcat

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

4. Buat service systemd

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

[Service]
Type=forking

User=tomcat
Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/jre"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"

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
systemctl daemon-reload
systemctl enable --now tomcat
systemctl status tomcat

5. Tambahkan rule Firewall

sudo firewall-cmd --permanent --zone=public --add-port=8080/tcp
sudo firewall-cmd --reload

6. Konfigurasi Web UI tomcat

  • Buat user
nano /opt/tomcat/latest/conf/tomcat-users.xml
Edit bagian berikut :

<tomcat-users>
<!--
    Comments
-->
   <role rolename="admin-gui"/>
   <role rolename="manager-gui"/>
   <user username="admin" password="admin_password" roles="admin-gui,manager-gui"/>
</tomcat-users>
  • Allow akses dari mana saja
nano /opt/tomcat/latest/webapps/manager/META-INF/context.xml
Remove file :

<!--
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->

dan


<!--
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->
  • Allow akses dari IP tertentu misal 111.68.77.66
<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|111.68.77.66" />
</Context>

dan

<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|111.68.77.66" />
</Context>
sudo systemctl restart tomcat

7. Testing akses 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

Sahabat Blog Learning & Doing demikianlah penjelasan mengenai Cara Install Tomcat 9 pada CentOS 8. Semoga Bermanfaat . Sampai ketemu lagi di postingan berikut nya.

(Visited 280 times, 1 visits today)

Similar Posts