My linux world » srv-tomcat

srv-tomcat


Prerequiste

I assume that you have a Centos installation.

Installation

You can copy/paste this script and use it to configure automatically your server.

  1. #!/bin/bash
  2.  
  3. ##################################################
  4. # PARAMETERS
  5. ##################################################
  6.  
  7. tomcat_version=8.5.16
  8.  
  9. ##################################################
  10. # INSTALLATION SCRIPT
  11. ##################################################
  12.  
  13. echo "install java"
  14. dnf -y install java-1.8.0-openjdk
  15.  
  16. echo "create user and group tomcat"
  17. groupadd tomcat
  18. useradd -s /bin/false -g tomcat -d /opt/java/apache-tomcat tomcat
  19.  
  20. echo "install tomcat"
  21. mkdir -p /opt/java
  22. wget -O /opt/java/apache-tomcat-$tomcat_version.tar.gz http://apache.crihan.fr/dist/tomcat/tomcat-8/v$tomcat_version/bin/apache-tomcat-$tomcat_version.tar.gz
  23. cd /opt/java
  24. tar xvfz apache-tomcat-$tomcat_version.tar.gz
  25.  
  26. ln -s -f /opt/java/apache-tomcat-$tomcat_version /opt/java/apache-tomcat
  27. chown -R -L tomcat:tomcat /opt/java/apache-tomcat
  28.  
  29. echo "create service /etc/systemd/system/tomcat.service"
  30. cat > /etc/systemd/system/tomcat.service << "EOF"
  31. [Unit]
  32. Description=Apache Tomcat
  33.  
  34. [Install]
  35. WantedBy=multi-user.target
  36.  
  37. [Service]
  38. User=tomcat
  39. Group=tomcat
  40. Type=forking
  41. Environment=CATALINA_PID=/opt/java/apache-tomcat/tomcat.pid
  42. Environment=CATALINA_HOME=/opt/java/apache-tomcat
  43. Environment=CATALINA_BASE=/opt/java/apache-tomcat
  44. ExecStart=/opt/java/apache-tomcat/bin/startup.sh
  45. ExecStop=/opt/java/apache-tomcat/bin/shutdown.sh
  46. Restart=on-failure
  47. EOF
  48.  
  49. systemctl daemon-reload
  50.  
  51. echo "launch tomcat service at startup"
  52. systemctl enable tomcat.service
  53.  
  54. echo "add service tomcat (port 8080) to firewall"
  55. cat > /etc/firewalld/services/tomcat.xml << "EOF"
  56. <?xml version="1.0" encoding="utf-8"?>
  57. <service>
  58. <short>tomcat</short>
  59. <description>tomcat server</description>
  60. <port protocol="tcp" port="8080"/>
  61. </service>
  62. EOF
  63. firewall-cmd --permanent --add-service tomcat
  64.  
  65. echo "launch tomcat"
  66. systemctl start tomcat
  67.  
  68. myip=`hostname -I`
  69. echo "Now meet you there: http://$myip:8080"
  70.  

That’s all 🙂


Copyright © 2024 My linux world - by Marc RABAHI
Design by Marc RABAHI and encelades.