Linux under Tomcat and Apache Web server consolidation

Source: Internet
Author: User
Tags chmod http authentication http request connect variables version access mysql database
Apache|web|web Service |web Server 1. Introduction

Internet/intranet based on web technology has been widely used in recent years, Intranet is based on TCP/IP protocol, the web as the core intranet, the user through Low-cost, An Easy-to-use client browser can access the data you need on the corporate web site anytime, anywhere. The consistency of the browser client interface avoids the diversity of C/S mode client programs, while the Open and standards-based connection schemes on the server side make it easy for enterprises to connect with the outside world through the Internet, and the dynamic and interactive publishing methods of Web information fundamentally change the service quality of the enterprise. Increased business opportunities for businesses.

In the view of many users, the success or failure of a Web site depends primarily on the content and functionality it provides, and the Web servers that support the content and functionality play a very important role.

2. Tomcat Container

Tomcat is a free open source Serlvet container, a core project in the Apache Foundation's Jakarta Project, developed by Apache,sun and other companies and individuals. Thanks to Sun's involvement and support, the latest servlet and JSP specifications are always reflected in Tomcat.

Tomcat is a solid stand-alone Web server and Servlet Container, but its Web server is not as complete as many of the more robust Web servers, such as the Apache Web server (for example, Tomcat does not have a large number of optional modules). However, Tomcat is free Open-source software, and many experts are committed to its development.

Install Tomcat under 2.1 Linux

You need to install J2SDK (Java 2 Software Development Kit) before installing Tomcat, and the steps to install J2SDK are as follows:

1) to http://www.java.sun.com download j2sdk, such as J2sdk-1_4_2_04-linux-i586-rpm.bin.

2 in the terminal to the directory where the J2sdk-1_4_2_04-linux-i586-rpm.bin, enter the command chmod +x j2sdk-1_4_2_04-linux-i586-rpm.bin, add the permissions to execute.

3 Execute the command./j2sdk-1_4_2_04-linux-i586-rpm.bin, generate j2sdk-1_4_2_04-linux-i586.rpm files.

4 Execute the command chmod +x j2sdk-1_4_2_04-linux-i586.rpm and add the execution permissions to j2sdk-1_4_2_04-linux-i586.rpm.

5 Execute command RPM–IVH j2sdk-1_4_2_04-linux-i586.rpm, install J2SDK.

6 The installation interface will appear authorization agreement, press ENTER to accept, the J2SD installed in/usr/java/j2sdk1.4.2_04.

7 Set the environment variable, in the/etc/profile.d/directory to establish a file java.sh, the contents of the document are as follows:
#set Java Environment
Export Java_home=/usr/java/j2sdk1.4.2_04
Export classpath=.: $JAVA _home/lib: $JAVA _home/jre/lib:/usr/java/jdbc
Export path= $JAVA _home/bin: $JAVA _home/jre/bin: $PATH

8 Execute command chmod 755/etc/profile.d/java.sh, assign permissions to java.sh.

9 in the terminal to execute the command javac–help and java–version respectively, if you see the information, it means that J2SDK has been successfully installed.

Next, install Tomcat, and the following steps are to install Tomcat:

1 visit http://jakarta.apache.org/tomcat/index.html, download the binary sedan tomcat, such as jakarta-tomcat-5.5.10.tar.gz, extract to the/usr/local directory:
Cd/usr/local
GZIP–ZXVF jakarta-tomcat-5.5.10.tar.gz

2) Modify $tomcat/bin/startup.sh and shutdown.sh files,
Export Java_home=/usr/java/j2sdk1.4.2_04
Export catalina_home=/usr/local/tomcat-5.5.10
Export classpath=.: $JAVA _home/lib: $JAVA _home/jre/lib:/usr/java/jdbc
Export path= $JAVA _home/bin: $JAVA _home/jre/bin: $PATH

3 Execute startup.sh to access the default face page of Tomcat in http://localhost:8080/.

2.2 Advantages of running Tomcat alone

1) Easy erection. Download Tomcat, set some configuration, and it's done. It does not take time to consolidate the Web server's connectors into other Web servers.

2 Do not need to worry about connectors. You never need to exclude any performance or online problems between other Web servers and tomcat.

3 has better safety protection. Compared to other Web servers written in C and C + +, Tomcat can tolerate remote buffer overflow attacks. Because Tomcat's Java Virtual machine is located between the network and the operating system, it protects against almost any type of buffer overflow attack. You can specify access to individual resources by using Tomcat's security protection domain.

4) easy to transplant. You can migrate Tomcat servers (and applications) to different servers, operating systems, and even architectures. Because Tomcat is written in Java, it is possible to replicate the contents of its entire directory structure to other computers without any change whatsoever, even if the new computer's architecture is different from the original.

2.3 The disadvantage of running Tomcat alone

1 Tomcat has less support software. Tomcat's built-in Web server has fewer support software than Apache httpd Web servers.

2 Tomcat's Web server features less. The Apache httpd server has more complete functionality than the Tomcat Web server.

3 Although Tomcat runs fast, it's not as fast as Apache httpd. The tomcat server is slower than the Apache httpd, but it's still improving, and it's still very fast, fast enough to run most of today's corporate web sites, but not Apache fast in providing static page content.

3. Apache Web server

Apache is based on NCSA's servers, NCSA is one of the first Web server programs to emerge, developed by the National Center for Supercomputing Applications at the University of Illinois at Urbana-champaign. In the early stages of development, Apache was primarily a UNIX-based server, and its mission was to build a UNIX-enabled, more powerful, more efficient, and faster WWW server, which made it evolve from other servers, And added a large number of patches to enhance its performance on one side, so it is named "Apa+chy Server (a patch composed of servers)." To this day, Apache has been ported to many platforms.
The development of Apache follows the GPL protocol and is developed and maintained by volunteers worldwide. It is still free and exposes the source code while maintaining strong functionality and constant updates.

3.1 Installing the Apache server

You can install the Apache server in the following three ways.

1 if installed in the Linux version with Apache, in the selection of the server to be installed, will httpd this service selected, Linux installer will automatically complete the installation of Apache, and do a basic configuration.

2 Use an executable package, which is more suitable for beginners who are not too familiar with the compilation work, because it is relatively simple. Download Package apache_1.2.4.e.tar.gz, execute the command tar xvzf apache_1.2.4.e.tar.gz complete the installation work. If you are using Redhat Linux, you can also download the APACHE_1.2.4.RPM Software installation package and install it using the RPM–IVH apache_1.2.4.rpm command.

3 If you want to make the Apache server fully utilized, you must compile Apache to customize its functions. Download the package apache_1.2.4 containing the Apache source code. tar.gz; then use the tar command to untie it; change the current directory to the SRC directory of the Apache source release, copy the configuration sample file (Configuration.tmpl) to the Configuration file, and edit the configuration options in the Configuration file:
Makefile Configuration options: Some compilation options:
. The "cc=" line specifies what compiler software compiles with, generally "CC=GCC", and if additional flags (parameters) need to be assigned to the C compilation software, you can use:
extra_cflags=
extra_lflags=
If your system requires special libraries and include files, you can specify them here:
extra_libs=
extra_includes=
If you want to change the code optimization settings, you must remove the annotation from the following sentence and change it to the desired value:
#OPTIM =-o2

Rule configuration options: Used to determine what functionality is required, generally without change.

Module configuration: The module is an Apache component that adds new functionality to the Apache kernel. By using the module configuration, you can customize what functionality is required on the Apache server, and this part is also the performance of Apache agility. The module configuration line looks like this:

Addmodule MODULES/STANDARD/MOD_ENV.O
If you need any functionality from the Apache server, add that module to the configuration file configuration with the Addmodule statement.
The following is a list of Apache module features:

Module Name feature Default
Mod_access provides host-based access control command y
Mod_actions can run a CGI script based on MIME type or HTTP request method y
Mod_alias can perform URL redirection service y
Mod_asis enables documents to be sent to client Y without HTTP headers
Mod_auth supports the use of user names stored in text files, passwords to implement authentication Y
MOD_AUTH_DBM supports using dbm file to store basic HTTP authentication n
Mod_auth_mysql supports using MySQL database for basic HTTP authentication n
Mod_auth_anon allows anonymous access to areas that require authentication Y
Mod_auth_external supports the use of third party authentication n
Mod_autoindex dynamically catalog list y when the index file is missing
Mod_cern_meta provides support for meta information n
mod_cgi support for CGI y
Mod_dir is able to redirect any request to a command that does not include trailing slash characters
MOD_ENV enables you to pass environment variables to CGI or SSI scripts n
Mod_expires let you determine how Apache handles expires y when the server responds to the request
Mod_headers can manipulate HTTP answer header y
MOD_IMAP provides graphical mapping support n
Mod_include enables SSI N to support
Mod_info provides a comprehensive description of the server configuration y
Mod_log_agent allows the user agent's information to be stored in a separate log file n
Mod_log_config Support Log Y
Mod_log_referer provides the ability to write Referer headers in a request to the log
Mod_mime is used to provide the client with meta information about the document Y
Mod_negotiation provides support for content negotiation y
MOD_SETENVIF enables you to create custom environment variables Y
Mod_speling enables you to handle URL requests that contain misspellings or capitalization errors
Mod_status allows administrators to manage Apache y through the web
MOD_UNIQUE_ID provides a unique identifier for each request under very special conditions n
Execute in the SRC directory: ". /configure ";
Compile Apache: Execute command "make";

Copy the compiled executable httpd to the/etc/httpd/bin directory, and copy the Apache distribution profile: access.conf, httpd.conf, Mime.types, srm.conf files to/etc/httpd/ Conf directory. So far, the installation is complete.

3.1 Advantages of running Apache httpd alone

1 Apache httpd is faster than Tomcat built Web servers.
2) more software support. Apache HTTPD has a large support software link library.
3 Start and stop fast. In general, the Apache httpd start and stop times are shorter than Tomcat.

3.2 Run the disadvantages of Apache httpd alone

   1) are difficult to erect. It's much more complicated than running Tomcat alone, installing the Apache Web server and making it work in collaboration with Tomcat.
   2) will slow down the service of dynamic Web content.
   3) security vulnerabilities. Apache httpd are more susceptible to buffer overflow attacks.
   4) Upgrades are more complex.

4, Tomcat and Apache integration

There are several ways to integrate Tomcat into the Apache httpd Web server:

1) The frame uses different port numbers to share the load.

This is the easiest way to do this, only if the URL is connected to a Tomcat Web server port on the same Web server machine (for example, 8080) in a ready-made Web page directory. In fact, there are two complete Web server programs that do not really integrate with each other.

2 Send the request from Apache to Tomcat's proxy server.

This method uses the proxy mechanism of HTTP on the primary server. The agent mechanism is often used to reroute Web traffic from Web servers running from the gateway to Web sites on the external Internet. However, you can also use to redirect the information flow of a site area or directory to a Tomcat Web server.

3 Use MOD_JK2 connector.

This method uses a connector module (such as MOD_JK) that runs within the existing Apache httpd Web server and quickly forwards the request to Tomcat via a specific protocol. This is the standard way to connect Tomcat to the Apache httpd.

4 execute two programs in a single process.

This method provides a "full integration" function by letting the JVM run in the process space of the Apache httpd. This is the most efficient approach, but it is also most dependent on the implementation of the server.

"References"
[1] Jason Brittain,ian F. darwin,tomcat:the Definitive Guide,2003
[2] Jason Brittain,ian F. Darwin, O ' Reilly Taiwan, June from the adaptation, Tomcat Authority guide, 2004
[3]http://www.apache.org
[4]http://www.bb.gilet.edu.cn

Related Article

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.