Integration of apahe and tomcat in Linux

Source: Internet
Author: User
Tags zts apache tomcat

This article is my 2nd article on building a Web server that integrates apache and tomcat in linux. Compared with the integration of apahe and tomcat in Linux (the first version), the GD library, Zend, and eaccelerator acceleration are added, and some well-known open-source PHP and JSP programs are tested, sablog, shopex, phpcms, discuz, ucenter_home, and lybbs can all run normally.

Apache and Tomcat are two projects under the Apache Foundation.

One is the http web server, and the other is the servlet container ). In our production environment, Apache is often used as the front-end server and Tomcat as the back-end server. In this case, we need a connector that transfers all Servlet/JSP requests to Tomcat for processing. Before Apache2.2, there are generally two components available: mod_jk and mod_jk2. Later, mod_jk2 was not updated, but mod_jk was updated. Therefore, mod_jk is usually used for Apache and Tomcat connectors.
However, since Apache2.2 came out, you have another option, that is, proxy-ajp. We all know that the proxy module in Apache can implement two-way proxy functions, which are very powerful. In fact, it is natural to use the proxy module to implement the connector. The proxy module sends the relevant requests to a specific host and then returns the results. The functional requirement of the connector is to transfer all requests to Servlet/JSP to the backend Tomcat.

Installation Steps

System Requirements: Linux 2.6 + kernel. In this article, the Linux operating system is CentOS 4.7, and RedHat AS4 is also installed successfully.

1. Obtain relevant open-source programs:
Required Software: Reference:

Eaccelerator-0.9.5.2.tar.bz2
Gd-2.0.35.tar.gz
Httpd-2.2.9.tar.gz
Mysql-5.0.67.tar.gz
Php-5.2.6.tar.gz
ZendOptimizer-3.3.0a-linux-glibc21-i386.tar.gz
Jdk-6u7-linux-i586-rpm.bin
Apache-tomcat-6.0.14.tar.gz
Apr-1.3.3.tar.gz
Apr-util-1.3.4.tar.gz
Eaccelerator-0.9.5.2.tar.bz2
Bytes -----------------------------------------------------------------------------------------------------------------------
Before installation, make sure that the following packages are installed in the system.
We can use rpm-qa | grep to check whether the system has been installed and referenced:
Bzip2-devel
Zlib-devel
Libjpeg-devel
Libpng-devel
Libtiff-devel
Freetype-devel
Openssl-devel
Libxml2-devel
Gettext-devel
These packages are generally installed. Except for the last one, we can find them on the CD and install them with rpm-ivh.

Ii. Install JDK reference:
# Pwd
/Usr/local
# Chmod a + x jdk-6u7-linux-i586-rpm.bin
#./Jdk-6u7-linux-i586-rpm.bin
# Ln-s/usr/java/jdk1.6.0 _ 07/usr/local/java
Set Environment Variables

# Vi profile
Add the following reference content at the end:
JAVA_HOME =/usr/java/jdk1.6.0 _ 07
CLASSPATH =/usr/java/jdk1.6.0 _ 07/lib/dt. jar:/usr/java/jdk1.6.0 _ 07/lib/tools. jar
PATH =/usr/java/jdk1.6.0 _ 07/bin: $ PATH
Export PATH JAVA_HOME CLASSPATH
Save and exit the reference:
# Source/etc/profile
Verification: Reference:
# Java-version
Iii. Install MYSQL reference:

# Tar-zxvf mysql-5.0.67.tar.gz
# Cd mysql-5.0.67
# Groupadd mysql
# Useradd-g mysql-s/sbin/nologin-M mysql
#./Configure -- prefix =/usr/local/mysql -- with-charset = gbk -- with-extra-charset = all -- enable-thread-safe-client
# Make & make install
# Cp support-files/my-medium.cnf/etc/my. cnf
# Chown-R mysql. mysql/usr/local/mysql/
#/Usr/local/mysql/bin/mysql_install_db -- user = mysql
# Chown-R root. root/usr/local/mysql/
# Chown-R mysql. mysql/usr/local/mysql/var/
Start the Database Service and add it to the auto-start reference:
#/Usr/local/mysql/bin/mysqld_safe -- user = mysql &
# Netstat-ant check port 3306
Add to auto start service queue: Reference:
# Cp support-files/mysql. server/etc/rc. d/init. d/mysqld
# Chmod 755/etc/rc. d/init. d/mysqld
# Chkconfig -- add mysqld
# Chkconfig -- level 345 mysqld on
Add a root password reference:
#/Usr/local/mysql/bin/mysqladmin-u root password "123456"
Test: Reference:
#/Usr/local/mysql/bin/mysql-u root-p
Enter the password 123456 to check whether the database can be accessed.

Configure library file search path reference:
# Echo "/usr/local/mysql/lib/mysql">/etc/ld. so. conf
# Ldconfig
# Ldconfig-v
# Echo "export PATH = $ PATH:/usr/local/mysql/bin">/etc/profile
# Source/etc/profile
4. Install Apr and Apr-util reference:
# Tar-zxvf apr-1.3.6.tar.gz
# Cd apr-1.3.6
#./Configure -- prefix =/usr/local/apr
# Make
# Make install
# Tar-zxvf apr-util-1.3.8.tar.gz
# Cd apr-util-1.3.8
#./Configure -- prefix =/usr/local/apr-util -- with-apr =/usr/local/apr
# Make
# Make install
V. Install GD2 reference:

# Tar-jxvf gd-2.0.35.tar.bz2
# Cd gd-2.0.35
#./Configure -- prefix =/usr/local/gd -- with-png -- with-freetype -- with-jpeg -- with-zlib -- with-fontconfig
# Make
# If GD reports an error: configure. ac: 64: warning: macro 'am _ ICONV 'not found in library
Make clean and then make
# Make install
6. install Apache reference:
# Tar xzvf httpd-2.2.9.tar.gz
# Cd httpd-2.2.9
#. /Configure -- prefix =/usr/local/apache -- enable-so -- enable-rewrite -- enable-proxy-ajp -- enable-proxy-balancer -- enable-proxy- connect -- enable-proxy-http -- with-mpm = worker -- with-apr =/usr/local/apr -- with-apr-util =/usr/local/apr-util
# Make
# Make install
#/Usr/local/apache/bin/apachectl start
Add to auto-start reference:
# Cp/usr/local/www/bin/apachectl/etc/rc. d/init. d/httpd
Then add vi/etc/rc. d/init. d/httpd (#! /Bin/sh)
# Chkconfig: 2345 10 90
# Description: Activates/Deactivates Apache Web Server
Finally, run chkconfig to add Apache to the startup Service Group of the system:
# Chkconfig -- add httpd
# Chkconfig httpd on
7. install Tomcat reference:
# Cp apache-tomcat-6.0.20.tar.gz/usr/local/
# Cd/usr/local/
# Tar xzvf apache-tomcat-6.0.20.tar.gz
# Ln-s apache-tomcat-6.0.20 tomcat
# Vi/usr/local/tomcat/bin/catalina. sh
Add a row: Reference:
JAVA_HOME =/usr/java/jdk1.6.0 _ 14
#/Usr/local/tomcat/bin/startup. sh

After the service is started, access the local port 8080 to view the corresponding apache tomcat page.

Add Tomcat to auto-start:
Vi/etc/rc. d/rc. local
Add the following code: Reference:
Export JDK_HOME =/usr/java/jdk1.6.0 _ 14
Export JAVA_HOME =/usr/java/jdk1.6.0 _ 14
/Usr/local/tomcat/bin/startup. sh
8. install PHP reference:

# Tar zxvf php-5.2.5.tar.gz
# Cd php-5.2.5
#. /Configure -- prefix =/usr/local/php -- with-apxs2 =/usr/local/apache/bin/apxs -- with-mysql =/usr/local/mysql -- with-gd = /usr/local/gd -- with-config-file-path =/usr/local/php -- enable-mbstring = all
# Make
# Make install
# Cp php. ini-recommended/usr/local/php. ini
Integrate apache with php
# Vi/usr/local/apache/conf/httpd. conf

Find AddType application/x-gzip. gz. tgz and reference the following content:
AddType application/x-httpd-php. php
Search: (set the WEB default file)
DirectoryIndex index.html
Changed to: Reference:
DirectoryIndex index. php index. jsp index.html index.htm
Save and exit the reference:
Service httpd restart
Create a file in the directory to test the php situation.
Create a test page reference under the htdocs directory:

Vi index. php
<? Php
Phpinfo ();
?>
Save and exit
Restart apache

IX. Install Zend reference:

# Tar zxvf ZendOptimizer-3.3.0a-linux-glibc21-i386.tar.gz
# Cd ZendOptimizer-3.3.0a-linux-glibc21-i386
#./Install. sh
An interface appears
OK, press Enter.
Enter the installation protocol directly
YES press ENTER

Then ask you about the php configuration file. We already know that it is under/etc, so press Enter.
If you use an apache server, select YES.
Ask where the control command of apche is/usr/local/apache/bin/apachectl
Then start to mount the progress bar but soon, and then select OK on a page with/etc/php. ini-zend_optimizer.bak backup
Go on "OK"
Ask if you want to restart apache and select YES
Prompt "OK" for apache startup success"
Installation Complete
Enter IE to check whether the test page Zend is successfully loaded.
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
With Zend Extension Manager v1.2.2, Copyright (c) 2003-2007, by Zend Technologies
With Zend Optimizer v3.3.0, Copyright (c) 1998-2007, by Zend Technologies
Before zend, it is like this:
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies.

10. Install the eaccelerator acceleration Software

Eaccelerator is a php acceleration software, which greatly improves the execution efficiency of php. Currently, eaccelerator0.9.5.2 is basically compatible with ZendOptimizer-3.3.0. Reference:

# Tar jxvf eaccelerator-0.9.5.2.tar.bz2
# Cd eaccelerator-0.9.5.2
#/Usr/local/php/bin/phpize
#./Configure -- enable-eaccelerator = shared -- with-php-config =/usr/local/php/bin/php-config
# Make
# Make install
After compilation and installation, we will see the eaccelerator on the screen. so directory, php5.2.x series is in/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/, remember this path, will be used later.

Modify php. ini (after zend is installed, php. ini is stored in/usr/local/Zend/etc)

# Vi/usr/local/zend/etc/php. ini

Install php Extension
At the end of the file, before [zend], note that this part of content must be placed before [zend], otherwise unexpected server problems may occur. Add the following information: Reference:
[Eaccelerator]
Extension = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator. so"
Eaccelerator. shm_size = "32"
Eaccelerator. cache_dir = "/tmp/eaccelerator"
Eaccelerator. enable = "1"
Eaccelerator. optimizer = "1"
Eaccelerator. check_mtime = "1"
Eaccelerator. debug = "0"
Eaccelerator. filter = ""
Eaccelerator. shm_max = "0"
Eaccelerator. shm_ttl = "0"
Eaccelerator. shm_prune_period = "0"
Eaccelerator. shm_only = "0"
Eaccelerator. compress = "1"
Eaccelerator. compress_level = "9"
Restart apache and go to the IE or php test page. If zend does not change, it means this method is useless.
Then mkdir/tmp/eaccelerator
# Chmod 777/tmp/eaccelerator

Open the phpinfo () test page in the browser. If the following content appears, it indicates that the installation is successful! Reference:
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
With eAccelerator v0.9.5.2, Copyright (c) 2004-2006 eAccelerator, by eAccelerator
With Zend Extension Manager v1.2.2, Copyright (c) 2003-2007, by Zend Technologies
With Zend Optimizer v3.3.0, Copyright (c) 1998-2007, by Zend Technologies
Finally, you can test the website project in the/usr/local/htdocs directory.
OK ~~ All ends !!!!


11. Integration of Tomcat and Apache

# Vi httpd. conf
Add the following two lines at the end of the file:
ProxyPass/ajp: // 127.0.0.1: 8009/
ProxyPassReverse/ajp: // 127.0.0.1: 8009/
Note that if there is no Vm, add the above two lines in http. conf without adding them.
For a VM, if it is a JSP, add others without adding
Example:
Vi/usr/local/apache/conf/http. conf
Put:
# Include conf/extra/httpd-vhosts.conf
Save without comments
Then vi/usr/local/apache/conf/extra/httpd-vhosts.conf

Reference:

NameVirtualHost: 80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# Match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost: 80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/usr/local/apache/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "log/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>
<VirtualHost: 80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/usr/local/apache/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "log/dummy-host2.example.com-error_log"
CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>
Changed to: Reference:

NameVirtualHost 192.168.1.100: 80
<VirtualHost 192.168.1.100: 80>
ServerName bbs.yahunet.com
DocumentRoot "/usr/local/apache/htdocs/bbs"
ErrorLog/usr/local/apache/htdocs/yahunet/error_log
CustomLog/usr/local/apache/htdocs/yahunet/access_log common
</VirtualHost>
<VirtualHost 192.168.1.100: 80>
ServerName www.syitren.com
DocumentRoot "/usr/local/apache/htdocs/syitren"
ErrorLog/usr/local/apache/htdocs/syitren/error_log
CustomLog/usr/local/apache/htdocs/syitren/access_log common
</VirtualHost>
Note: to add these two lines of logs, you must create
ServerAlias is the alias that is the domain name here need to note that in not JSP project when the virtual host only change the httpd-vhosts.conf plus can and JSP project not only in this need to add but also in the server. in xml, you must add the following methods.
The above is PHP, but if it is JSP reference:
<VirtualHost 192.168.1.100: 80>
ServerName bbs.syitren.com
DocumentRoot "/usr/local/tomcat/webapps/wz"
ErrorLog/usr/local/apache/htdocs/syitrenbbs/error_log
CustomLog/usr/local/apache/htdocs/syitrenbbs/access_log common
ProxyPass/ajp: // 127.0.0.1: 8009/
ProxyPassReverse/ajp: // 127.0.0.1: 8009/
</VirtualHost>
Here we need to add these two lines and make the virtual host directory consistent with this in the tomcat configuration file server. xml.
In server. xml, add: Reference:
<Host name = "www.syitren.com" debug = "0" appBase = "webapps" unpackWARs = "true" autoDeploy = "true" xmlValidation = "false" xmlNamespaceAware = "false">
<Context path = "" docBase = "/usr/local/apache/htdocs/syitren/" debug = "0" reloadable = "true" crossC/>
<Logger className = "org. apache. catalina. logger. FileLogger" directory = "logs" prefix = "www_5sai_log." suffix = ". txt"
Timestamp = "true"/>
</Host>
OK, and finally it is tested by engineering.

This is a success !!!

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.