Instalación Tomcat 8 en máquina vagrant

Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "debian/stretch64"
  config.vm.synced_folder "./data","/vagrant"
  config.vm.network "forwarded_port", guest: 8080, host: 8080
 
  config.vm.provider "virtualbox" do |vb|
    vb.name = "tomcat8"
    vb.memory = 1024
    vb.cpus = 1
    vb.linked_clone = true
  end
end

/vía: https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-ubuntu-16-04

  1. actualización del sistema:
    sudo apt-get update
  2. instalación Java:
    sudo apt-get install default-jdk
  3. creación usuario/grupo para tomcat:
    sudo groupadd tomcat
    sudo useradd -s /bin/false/ -g tomcat -d /opt/tomcat tomcat
  4. instalar tomcat (http://tomcat.apache.org/download-80.cgi):
    cd /tmp
    curl -O <url_descarga_tomcat>
    sudo mkdir /opt/tomcat
    sudo tar xzvf <fichero_tomcat> -C /opt/tomcat --strip-components=1
    cd /opt/tomcat
    sudo chgrp -R tomcat /opt/tomcat
    sudo chmod -R g+r conf
    sudo chmod g+x conf
    sudo chown -R tomcat webapps/ work/ temp/ logs/
  5. automatizar arranque:
    1. obtener el path del ejecutable de Java:
       sudo update-java-alternatives -l
    2. crear el servicio en /etc/systemd/system/tomcat.service:
      [Unit]
      Description=Apache Tomcat Web Application Container
      After=network.target
      
      [Service]
      Type=forking
      
      Environment=JAVA_HOME=<path_obtenido_anteriormente>/jre
      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.sh
      ExecStop=/opt/tomcat/bin/shutdown.sh
      
      User=tomcat
      Group=tomcat
      UMask=0007
      RestartSec=10
      Restart=always
      
      [Install]
      WantedBy=multi-user.target
    3. recargar el demonio systemd para que reconozca el servicio:
      sudo systemctl daemon-reload
    4. cargar el servicio y comprobar que está OK:
      sudo systemctl start tomcat
      sudo systemctl status tomcat
  6. ajustar el firewall:
    sudo apt-get install ufw
    sudo ufw allow 8080
  7. si se puede acceder a la pantalla de inicio (http://<ip>:8080) de Tomcat, activar su inicio automático:
    sudo systemctl enable tomcat
  8. configurar acceso a la interfaz web en Tomcat, editando el fichero /opt/tomcat/conf/tomcat-users.xml, y añadiendo un usuario en la sección correspondiente:
    <tomcat-users ...>
        <user username="admin" password="password" roles=manager-gui, admin-gui" />
    </tomcat-users>
  9. si hubiera que modificar las IPs que tienen acceso al interfaz web (por defecto, localhost), habría que modificar:
    • /opt/tomcat/webapps/manager/META-INF/context.xml
    • /opt/tomcat/webapps/host-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>
  • y reiniciar el servicio:
    sudo systemctl restart tomcat

otra guía: https://www.digitalocean.com/community/tutorials/how-to-encrypt-tomcat-8-connections-with-apache-or-nginx-on-ubuntu-16-04

  • linux/tomcat/install.txt
  • Darrera modificació: 27/09/2018 01:55
  • per mate