Tomcat installation configuration, tomcat

Source: Internet
Author: User
Tags apache tomcat

Tomcat installation configuration, tomcat

I am now learning about Tomcat. I have learned some of Tomcat's experience and experience on the Internet and wrote it here as a record and memo.

1. First, get and install Tomcat.

Download from Apache's official website. It is open-source and free, and the bandwidth is sufficient. The download will be fast.

  

There are two different download Methods: A common installation version and a decompressed installation version. The usage is the same, but there are some interfaces in the common installation version that can provide quick settings for Tomcat.

Tomcat is registered as a system service.

2. Set up the Tomcat runtime environment.

A: (decompress version) after installation (that is, decompress) is completed as follows:

  

B: Configure Tomcat

Tomcat is started as a bat file (in Windows). In the bin directory, double-click it.

If it fails to be started, the console disappears immediately after it comes out, indicating that Tomcat does not find the Java Runtime Environment.

Simply put, it means that Tomcat cannot find JDK and cannot run.

Let's "tell" the JDK installation path. Create JAVA_HOME (case-insensitive) in the environment variable and point to the JDK installation directory. As follows:

  

In this way, Tomcat is configured and started.

Start Tomcat and enter http: // localhost: 8080/in the address bar of the browser. If you see a messy introduction to Tomcat, the configuration is successful.

C: register the Tomcat Service

First, modify service. bat: REM in the bin directory and add the following row of rem set CATALINA_HOME = C: \ Program Files \ Java \ jdk1.8.0 _ 20.
If you have never installed Tomcat, or make sure that Services. msc starts the Service Manager to check that there is no Apache Tomcat System Service, you can go to step 2. Otherwise, move on to REM and modify the following lines according to the description:

Set SERVICE_NAME = atat5 REM in the previous line, Tomcat5 is changed to the service name you need. This will be the service name that will be operated later using net start/stop.

Set PR_DISPLAYNAME = in the previous line of Apache Tomcat REM, change Apache Tomcat to the service name you need. This will be displayed in the Service Manager.

Set PR_DESCRIPTION = Apache Tomcat Server-http://jakarta.apache.org/tomcat REM this line does not change does not matter, is the service description, according to your own preference to decide.

2. Run cmd to open the console, enter the Tomat directory/bin folder, and enter the following command to run.

Service. bat install


Program prompt: The service 'tomcat 5 (or SERVICE_NAME after you modify it) 'has been installed indicates that The service Tomcat has been installed successfully.


By the way, running service. bat remove can remove the service.

Third: start or stop the service


Use the console to control the service commands (input in Win + R)


Start Service net Start service name

Disable the service. net stop service name

Note: The service name can be SERVICE_NAME or PR_DISPLAYNAME;
If the service name contains spaces or Chinese characters, enclose the service name in double quotation marks.

 

3. Tomcat directory structure introduction.

Bin: Directory stores executable programs and related content for starting and running Tomcat.

Conf: stores the global configuration of the Tomcat server.

Lib: Directory stores the jar packages required for Tomcat running or site running. All the sites on Tomcat share these jar packages.

Logs: stores log files temp: stores temporary files

Wabapps: the default site root directory, which can be changed.

Work: A directory is used to store excessive resources during server running. In short, it is to store jsp, servlet translation, and compiled results.

Other directories and files are not described at the moment.

4. Default Tomcat behavior.

If a browser request arrives at Tomcat and the request is correct, Tomcat usually responds to the request in the form of a static page (that is, an html file), which is the default behavior of the http server.

A complete resource request includes:

Protocol (such as http)

Host Name (domain name, such as localhost and www.baidu.com)

Port Number (the default http protocol is 80, so we generally do not enter a request to a website)

Site

Resource location (for example, http: // localhost: 8080/ROOT/index. jsp)

In the second step, we only enter the domain name (or host name) to access a specific page. What is the problem ?.

First, the request will arrive at the requested host address in some ways and be obtained by the http server program on the server (hardware, such as our local computer. This step is difficult to explain. We will not repeat it here. I will introduce it in other sections.

For example, enter http: // localhost: 8080 in the browser. Tomcat found.

Now it gets the request and analyzes the requested resources. Because we didn't specify it, it will go to the default site to get the default page for us.

Now let's go through the process again:

Server: Tomcat listens to port 8080. always pay attention to the request.

The client browser sends a request to the server. Due to port allocation, the request is finally obtained by Tomcat.

Tomcat parses the requested resource and finds that no resource is specified for the site.

Tomcat returns the default page to the client browser as a response under the default site.

5. Change the default Tomcat configuration.

① Modify the Tomcat listening port.

We have all experienced Website access. We generally only enter the domain name, right? If we are now a network service provider and want to publish a website to the outside world, how can we let users only enter our domain name to see it?

What about the webpage we have prepared for him/her?

First, we need to set the listening port to 80. The principle is very simple. The user will not enter 8080 in the browser to access the website, and the browser will not automatically send the request to port 8080 on the server.

Modify it in the server. xml file in the conf directory of % atat_home % (which is the installation path of Tomcat.

There are a lot of things in this file, so you don't have to worry about it. Why? After deleting the comment, you can regard the entire xml as an object. Right? each node is an attribute, and this attribute may be an object,

It has attributes ...... To understand this, or directly think That Tomcat configuration information is correct.

In this way, you do not need to enter 8080.

② Modify the default site.

First, the site is a folder with a specific structure. This is extremely clear in Tomcat.

Websites must be stored and managed using folders (directory structure) on the server. However, it is different from a common folder. In Tomcat, folders that can be used as sites must have the following features:

Has a subfolders named WEB-INF that must have a file named web. xml that must be constrained with a specific DTD.

We first configure or create a site, and then set it as the default site.

Configure site: Create folder, create WEB-INF subfolders, create web. xml, complete. For web. xml content, see webapps/ROOT/WEB-INF/web. xml.

Set it to the default site (two steps are required here ):

Tell Tomcat which site to request (or what name is followed by the domain name) and you will come to me.

Tell Tomcat where I am.

We have configured the two steps (in fact, Tomcat adds the code to point the empty site to the ROOT by default), our d:/myweb.

If your website is stored in the webapps directory, you can use the relative path. For example, we copied d:/myweb to % atat_home %/webapps, obviously, you do not need to add d.

I wrote a few words in index.html and the result came out:

③ Modify the default page.

In fact, we are still in a regular fashion. As usual, we thanked index.html. So what if it is not written? What Will Tomcat do?

Find conf/web. xml. This file sets the common attributes of all sites. For example, you can see at the end of the file:

This is called the welcome page. When the resource address is not entered, it will be searched from top to bottom, get the page, and respond.

You can change it clearly, but it is not recommended to change it here. It will be a change in the settings of all sites. You should copy it to the web under the site you want to change. xml.

6. Configure the VM.

The so-called virtual host is to bind one or more host names (Domain Names) to the server where Tomcat is located. Since one IP Address can help with multiple domain names, we can direct different domain names to the server

Files), resulting in a server (or an IP address) of multiple hosts "virtual host" effect.

This implementation is quite simple. You only need to create a Host node in the server. xml file and set its attributes differently.

1 # Your host name (domain name) 1 2 <Host name = "localhost" appBase = "webapps" 3 unpackWARs = "true" autoDeploy = "true" 4 xmlValidation = "false" xmlNamespaceAware = "false"> 5 </ host> 6 # your domain name 2 7 <Host name = "www.coderecord.org" appBase = "Host space address" 8 unpackWARs = "true" autoDeploy = "true" 9 xmlValidation = "false" xmlNamespaceAware = "false"> 10 # Domain Name 3 can share a host space with domain name 2 11 <alias> coderecord.org </alias> 12 <Context path = "" docBase = "site address" debug = "1" reloadable = "true" allowLinking = "true"/> 13 </Host>

 

The above configuration information varies depending on the Tomcat version.

This article gives you some simple insights on Tomcat installation, Environment setup, virtual directory, and virtual host configuration.

We should have some faith. Only in this way can our creations assume the responsibilities assigned to them! Note: Re-printed http://www.cnblogs.com/Johness/archive/2012/07/20/2600937.html
Tomcat installation and configuration

Ii. installation and configuration of Tomcat server
1. Unzip the tomcat6.0.20.rar file to complete installation.
2. tomcat is a java program and jre will be used.
Therefore, you must configure the environment variable java_home to the jdk installation directory c: \ jdk1.6.
Tomcat is started through the startup. bat file. In fact, startup. bat calls
The catalina. bat file is located through % catalina_home % \ bin \ catalina. bat.
To ensure normal server startup, You need to configure the catalina_home environment variable as the tomcat installation directory.
3. tomcat directory structure
Bin: stores some execution files.
Conf: stores the server configuration file.
Lib: stores the jar files that tomcat depends on.
Logs: stores log files.
Temp: stores temporary files
Webapps: web applications store all web applications (web Resources)
Work: tomcat's working directory. The Servlet translated by jsp is under this directory.
4. web Applications
Multiple web resources are stored in one directory as a web application (web application, web Project)
Directory structure of web Applications
Put static web resources directly under the Directory
Put the java class under the classes directory
The web. xml file is used to manage all web resources under the web application.
Put all jar packages in the lib directory

How to configure and install the tomcat server

Install JDK first and install TOMCAT. In the current version, you do not need to set environment variables as long as the version is installed, for a non-installed version, right-click my computer and choose Properties> advanced> environment variable> system variable to create a new variable named JAVA_HOME variable value C: \ Program Files \ Java \ jdk1.6.0 _ 12 is where your JDK is installed.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.