DEV Community

kunzhu0710
kunzhu0710

Posted on

How to install Tomcat on Tencent Cloud CVM

introduce

Tomcat is a servlet container developed by the Jakarta project under the Apache Software Foundation. According to the technical specifications provided by Sun Microsystems, Tomcat implements support for Servlet and JavaServer Page (JSP), and provides some unique functions as a Web server, such as Tomcat management and control platform, security domain management and Tomcat valve, etc. Since Tomcat itself also includes an HTTPserver , it can also be regarded as a separate Web server . If you develop Java applications, Tomcat is a quick and easy way to serve them in a complete server environment designed specifically for this purpose.
In this tutorial, we will install Tomcat and do some basic configuration on a Debian 7 VPS .To complete this tutorial, you must have a normal user with sudo privileges.

Install Apache Tomcat

In this tutorial, we will install Tomcat and its related packages. These are included in the default Debian repositories.
To get the base repository, we can update the sources list and then install the package:

sudo apt-get update
sudo apt-get install tomcat7
Enter fullscreen mode Exit fullscreen mode

That's all we need to do to get to the default Tomcat page. Our installation is not complete, but you can log in to your server's 8080 port to view the default Tomcat page in your browser:

your_domain_or_ip:8080
Enter fullscreen mode Exit fullscreen mode

undefined

To take advantage of more of Tomcat's capabilities, we'll install some additional Tomcat packages.
These will allow us to control Tomcat using the web interface. It will install some documentation and examples, which we can also view through the website interface.

 sudo apt-get install tomcat7-admin tomcat7-examples tomcat7-docs
Enter fullscreen mode Exit fullscreen mode

## Install Java Development Tools

In order to develop Java applications on your server using Tomcat, you need to download and install a few things.
The first thing we need to do is install a compatible Java Development Kit. We can install it with the following command:

 sudo apt-get install default-jdk
Enter fullscreen mode Exit fullscreen mode

The version installed here is openjdk-6-jdk , at present, this version is the most stable version running on Debian
The Tomcat documentation also recommends that you install Apache Ant, a build tool for Java applications. The Tomcat documentation also recommends that you install a version control system, here we recommend installing git:

 sudo apt-get install ant git
Enter fullscreen mode Exit fullscreen mode

## Configure the Tomcat website

Before we can start using some of the features we installed, we need to configure our server with a user and password.
Configuration is very simple. We need to edit a file called tomcat-users.xml. Open it with an editor:

 sudo nano /etc/tomcat7/tomcat-users.xml
Enter fullscreen mode Exit fullscreen mode

Inside, you'll find a bunch of annotation configuration files. In fact, the only uncommented part of the file is:

<tomcat-users>
</tomcat-users>
Enter fullscreen mode Exit fullscreen mode

We need to define the user between these two lines. We will grant this user access to the web interface. The configuration is as follows:

<tomcat-users>
    <user username="admin" password="password" roles="manager-gui,admin-gui"/>
</tomcat-users>
Enter fullscreen mode Exit fullscreen mode

Set username and password. Save and close the file when done.
Restart Tomcat to implement the changes:

 sudo service tomcat7 restart
Enter fullscreen mode Exit fullscreen mode

## Test the website interface

Once Tomcat is installed and user login is configured, the main page can be accessed by going to the server IP address or domain name ending in :8080 as follows:

 your_domain_or_ip:8080
Enter fullscreen mode Exit fullscreen mode

You will see the same default Tomcat page you saw before:
undefinedHowever, since we have already installed and configured the components, we have access to more functionality. You can access the Tomcat documentation in your browser by clicking the link shown on the page or by visiting this page:

your_domain_or_ip:8080/docs


When you have questions about how to do something with Tomcat, check out the Q&amp;A on this page.
We also now have access to some different sample programs. These can be accessed via links on the same initial login page, or by visiting:
your_domain_or_ip:8080/examples
Enter fullscreen mode Exit fullscreen mode

undefinedClicking on these items gives us an idea of ​​how the different functions are implemented in this environment. The main functions you want to access are the manager webapp and the host-manager webapp .
Again, you can access these from the initial login page, or visit:

 your_domain_or_ip:8080/manager/html
Enter fullscreen mode Exit fullscreen mode

and:

 your_domain_or_ip:8080/host-manager/html
Enter fullscreen mode Exit fullscreen mode

You can manage Java applications at the first site. It allows you to easily start, stop, deploy and reload your application. It can also find the cause of memory leaks caused by running applications:
undefined
In another page, you can test, tune, and add virtual hosts to serve your application. This allows you to easily set up access to deployed applications:
undefined

in conclusion

Tomcat provides an excellent platform for controlling and serving Java applications in a website environment. You can easily deploy .war files and have them up and running in a fraction of the time. Did you learn it? Buy a CVM and try it out!

Top comments (0)