[Info] Hướng dẫn cài đặt Tomcat 8 trên Ubuntu 18.04

Apache Tomcat provides an HTTP server for the Java language. In this article, HOSTVN will guide you to install Tomcat 8 on Ubuntu 18.

Installing Tomcat 8 on Ubuntu 18.04 – Apache Tomcat is a Java Servlet developed by the Apache Software Foundation. Tomcat implements the Java Servlet and JavaServer Pages applications from Sun Microsystems, and provides an HTTP server for the Java language to execute commands written in the Java language.

In this post HOSTVN will guide you to install Tomcat 8 on Ubuntu 18.04.

Install Tomcat 8 on Ubuntu 18.04

1. Install OpenJDK

OpenJDK is the default Java platform in Ubuntu 18.04. Installing the OpenJDK package is quite simple with the following command:

sudo apt install default-jdk -y

2. Create Tomcat user

You will need to create a new system user and group with the home directory /opt/tomcat will run the tomcat service:

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

3. Download Tomcat

HOSTVN will use wget to download tomcat and unzip to unzip tomcat. If you don’t have wget installed, unzip install them with the following command:

sudo apt install unzip wget nano -y

Download the latest version of Tomcat 8.5.x from the Tomcat download page. At the time of writing, the latest version is 8.5.55. Before proceeding to the next step, you should check the download page to check for the latest version.

Move to folder /tmp and download the zip file with the following wget command:

cd /tmp
wget https://downloads.apache.org/tomcat/tomcat-8/v8.5.55/bin/apache-tomcat-8.5.55.zip

Screenshot_4

Once the download is complete, extract the file and move it to the folder /opt/tomcat:

unzip apache-tomcat-*.zip
sudo mkdir -p /opt/tomcat
sudo mv apache-tomcat-8.5.55 /opt/tomcat/

For easier management HOSTVN will create a symlink pointing to the tomcat installation directory:

sudo ln -s /opt/tomcat/apache-tomcat-8.5.55 /opt/tomcat/latest

The tomcat user you created earlier needs to have access to the tomcat directory, so you need to change the directory ownership to the tomcat user and group:

sudo chown -R tomcat: /opt/tomcat

Set execute permission for scripts inside directory bin by running the following chmod command:

sudo sh -c 'chmod +x /opt/tomcat/latest/bin/*.sh'

4. Create systemd unit

To be able to run Tomcat as a service, create the file tomcat.service in folder /etc/systemd/system/

sudo nano /etc/systemd/system/tomcat.service

Paste the following in it

[Unit]
Description=Tomcat 8.5 servlet container
After=network.target

[Service]
Type=forking

User=tomcat
Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/default-java"
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

Screenshot_5

Press Ctrl + o and press Enter to save files, Ctrl + x to get rid of nano. Then you start Tomcat with the following commands:

sudo systemctl daemon-reload
sudo systemctl enable tomcat
sudo systemctl start tomcat

You can check the service status with the following command:

sudo systemctl status tomcat

Screenshot_6

5. Firewall configuration

If your server is protected by the UFW firewall and you want to access the tomcat interface, you will need to open the port 8080. To allow traffic on port 8080use the following command:

sudo ufw allow 8080/tcp

Screenshot_7

6. Tomcat Web Management Interface Configuration

So we have completed the installation of Tomcat on the Ubuntu server, the next step is to create a user that is allowed to access the web management interface (manager-gui and admin-gui). User is allowed to access admin-gui and manager-gui of Tomcat is defined in the file tomcat-users.xml.

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

To add users who can access the interface manager-gui and admin-guiyou add the following configuration

Remember instead username and password with the information you want to create

<tomcat-users>
<!--
    Comments
-->
   <role rolename="admin-gui"/>
   <role rolename="manager-gui"/>
   <user username="admin" password="admin_password" roles="admin-gui,manager-gui"/>
</tomcat-users>

Screenshot_8

By default, manager-gui and admin-gui only allow access from localhost, if you want access manager-gui and admin-gui from the outside you can open the following files and make the necessary changes.

If you need access to manager-gui and admin-gui from anywhere, open the following files and comment the following lines:

  • /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>

Screenshot_9

  • /opt/tomcat/latest/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>

Screenshot_10

If you want to allow only specific IPs to be accessed manager-gui and admin-gui, instead of commenting blocks, add your network IP to the list. In this post HOSTVN would for example network IP is 123.45.67.89:

  • /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|123.45.67.89" />
</Context>

Screenshot_12 - install Tomcat 8 on Ubuntu 18

  • /opt/tomcat/latest/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|123.45.67.89" />
</Context>

Screenshot_11 - install Tomcat 8 on Ubuntu 18

The list of allowed IP addresses is a character-separated list |. Restart the Tomcat service for the changes to take effect:

sudo systemctl restart tomcat

7. Check the settings

Open your browser and go to: http://:8080. If the installation is successful, a screen similar to the following will appear:

Screenshot_14 - install Tomcat 8 on Ubuntu 18

To access the Tomcat Web Application Manager Console visit the following link: http://:8080/manager/html. Here you can deploy, de-deploy, start, stop and reload your applications.

Screenshot_15 - install Tomcat 8 on Ubuntu 18

The Tomcat virtual host manager console can be accessed via the link http://:8080/host-manager/html. Here you can create, delete and manage Tomcat virtual servers.

Screenshot_16 - install Tomcat 8 on Ubuntu 18

8. Conclusion

In this post HOSTVN I have guided you to install Tomcat 8 on Ubuntu 18.04. You can visit the official Apache Tomcat 8 Documentation page and learn more about the features of Apache Tomcat. If you have any suggestions, you can leave a comment below. In addition, you can see more Instructions for installing LEMP on Ubuntu 18.

Viết một bình luận

bahis10bets.com betvole1.com casinomaxi-giris.com interbahis-giris1.com klasbahis1.com mobilbahisguncelgiris1.com piabetgiris1.com tipobettgiris.com tumbetgiris1.com betboro 1xbet giriş
bahis10bets.com betvole1.com casinomaxi-giris.com interbahis-giris1.com klasbahis1.com mobilbahisguncelgiris1.com piabetgiris1.com tipobettgiris.com tumbetgiris1.com betboro 1xbet giriş
antalya bayan escort
antalya bayan escort
antalya bayan escort