Integration of CentOS 6.2Web with Apache and Tomcat

Source: Internet
Author: User
Tags url forwarding

I have previously written the establishment of the LAMP platform, including the integration of the LAMP platform later. However, due to the fact that I have published too few entertaining articles, my article is reprinted, I am helpless in this regard. writing a blog only records and helps people who need it, so I will continue to publish my own blog post in this style later ), this article further introduces the integration of Apache server and Tomcat to support JSP. All we know is that Apache supports static pages and Tomcat supports dynamic pages. We can use Apache + Tomcat to combine their advantages. Apache is responsible for forwarding, jsp processing is handled by Tomcat. That is to say, Apache provides HTTP services and related configurations such as virtual hosts and URL forwarding. Tomcat is a JSP server developed by Apache under the JSP and Servlet standards of J2EE. Since Apache and Tomcat are both Web servers, we know that Tomcat supports Servlet and JSP and can be used as Web servers instead of using the Tomcat Server, however, when processing a large number of static pages, Tomacat is not as good as Apache and not as strong as Apache. However, Apache, as the most popular Web server, can efficiently process static pages, but does not support JSP and Servlet. Therefore, the common practice is to combine them into one, let Apache process static pages and send dynamic page requests to Tomcat for processing. By loading and setting the integration module in Apache, Apache can forward requests that do not belong to itself to Tomcat Based on the URL. To make Apache and Tomcat work together, you also need a connector to connect them. Connector has an important impact on the performance and ease of configuration. Currently, there are three types of tools: JK1.x, JK2, and mod_webapp. JK is widely used.
Preparations for Tomcat and Apache Integration Note:This environment continues after Apache compilation is complete. ) JDK JDK is an essential software for installation and testing in the tomcat runtime environment. Because tomcat is only a Servlet/JSP Container, the underlying operations must be completed by JDK)
[root@chenyi software]# chmod a+x jdk-6u7-linux-i586.bin [root@chenyi software]# ./jdk-6u7-linux-i586.bin
Set environment variables. Tomcat will find the jdk installation path at startup)
[root@chenyi software]# vi /etc/profile.d/java.sh   export JAVA_HOME=/software/jdk1.6.0_07   export JRE_HOME=$JAVA_HOME/jre   export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar   export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
[root@chenyi software]# chmod 755 /etc/profile.d/java.sh [root@chenyi software]# . /etc/profile
You can test whether java works normally.
[root@chenyi software]# java -versionjava version "1.6.0_07"Java(TM) SE Runtime Environment (build 1.6.0_07-b06)Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)
Test JAVA program
[root@chenyi software]# vi test.javapublic class test {    public static void main(String args[]) {        System.out.println("Hello World!");    }}[root@chenyi software]# javac test.java [root@chenyi software]# java testHello World!
To install Tomcat, you only need to decompress the package and change the name to a proper place to complete the installation)
[root@chenyi lamp]# tar zxf apache-tomcat-6.0.14.tar.gz[root@chenyi lamp]# mv apache-tomcat-6.0.14 /software/tomcat
Compile and generate mod_jk. Here, we want to use the mod_jk connector more flexibly, so we need to specify the apache apxs path for compiling the required JK module in the source code mode ))
[root@chenyi lamp]# tar zxf jakarta-tomcat-connectors-1.2.15-src.tar.gz [root@chenyi lamp]# cd jakarta-tomcat-connectors-1.2.15-src[root@chenyi jakarta-tomcat-connectors-1.2.15-src]# ./configure --with-apxs=/software/apache2/bin/apxs && make && make install[root@chenyi native]# ls /software/apache2/modules/mod_jk.so /software/apache2/modules/mod_jk.so
Create mod_jk.conf and pay attention to my path)
[Root @ chenyi httpd] # vi mod_jk.conf loadModule jk_module "/software/apache2/modules/mod_jk.so" # specify mod_jk.soJkWorkersFile "/etc/httpd/workers. properties "# setting JkLogFile for JK connector properties"/software/tomcat/logs/mod_jk.log "JkLogLevel emergServerName localhostJkmount /*. jsp ajp13
Create workers. properties
Workers. tomcat_home =/software/tomcatworkers. java_home =/software/jdk1.6.0 _ 07 ps =/workers. list = ajp13 # worker. list is used to define the Workers list. When apache is started, workers. properties will be initialized in worker as a plug-in. workers in the list. Workers. ajp13.port = 8009 # tomcat worker host listening port. By default, tomcat uses the 8009workers port in the ajp13 protocol. ajp13.host = 127.0.0.1 # tomcat worker host address for listening to ajp13 requests. ajp13.type = ajp13 # define a worker named "ajp13". It uses the ajp13 protocol to communicate with the tomcat process workers. ajp13.lbfactor = 1 # When tomcat is used as a server Load balancer instance, this attribute is used, indicating the Server Load balancer weight of this tomcat worker node.
Configure Apache
[root@chenyi httpd]#vi httpd.conf
Add the following statement
Include /etc/httpd/mod_jk.conf
Restart Apache and Tomcat after saving AND EXITING
[root@chenyi ~]# /software/apache2/bin/apachectl stop[root@chenyi ~]# /software/apache2/bin/apachectl start[root@chenyi ~]# /software/tomcat/bin/shutdown.sh Using CATALINA_BASE:   /software/tomcatUsing CATALINA_HOME:   /software/tomcatUsing CATALINA_TMPDIR: /software/tomcat/tempUsing JRE_HOME:       /software/jdk1.6.0_07/jre[root@chenyi ~]# /software/tomcat/bin/startup.sh Using CATALINA_BASE:   /software/tomcatUsing CATALINA_HOME:   /software/tomcatUsing CATALINA_TMPDIR: /software/tomcat/tempUsing JRE_HOME:       /software/jdk1.6.0_07/jre
View service status through netstat
[root@chenyi ~]# netstat -pant | grep 80tcp        0      0 127.0.0.1:42442             127.0.0.1:8009              TIME_WAIT   -                   tcp        0      0 127.0.0.1:42441             127.0.0.1:8009              TIME_WAIT   -                   tcp        0      0 127.0.0.1:42438             127.0.0.1:8009              TIME_WAIT   -                   tcp        0      0 127.0.0.1:42439             127.0.0.1:8009              TIME_WAIT   -                   tcp        0      0 127.0.0.1:42446             127.0.0.1:8009              TIME_WAIT   -                   tcp        0      0 127.0.0.1:42440             127.0.0.1:8009              TIME_WAIT   -                   tcp        0      0 127.0.0.1:42437             127.0.0.1:8009              TIME_WAIT   -                   tcp        0      0 127.0.0.1:42443             127.0.0.1:8009              TIME_WAIT   -                   tcp        0      0 127.0.0.1:42445             127.0.0.1:8009              TIME_WAIT   -                   tcp        0      0 :::8080                     :::*                        LISTEN      4434/java           tcp        0      0 :::80                       :::*                        LISTEN      4399/httpd          tcp        0      0 ::ffff:127.0.0.1:8005       :::*                        LISTEN      4434/java           tcp        0      0 :::8009                     :::*                        LISTEN      4434/java           tcp        0      0 ::ffff:127.0.0.1:58570      ::ffff:127.0.0.1:8005       TIME_WAIT   -                   tcp        0      0 ::ffff:127.0.0.1:43053      ::ffff:127.0.0.1:8080       TIME_WAIT   -
Access through http: // IP: 8080 for testing650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131227/1930245605-0.jpg "alt =" "border =" 0 "/>
Set Tomcat Login Password
[Root @ chenyi ~] # Vi/software/tomcat/conf/tomcat-users.xml? Xml version = '1. 0' encoding = 'utf-8'?> <Tomcat-users> <role rolename = "manager"/> <role rolename = "admin"/> <user username = "itchenyi" password = "123456" roles = "manager, admin "/> # newly added </tomcat-users>
Write a simple jsp page for testing[Root @ chenyi ~] # Vi/software/tomcat/webapps/ROOT/test. jsp
<%@ page language="java" %><%@ page import="java.util.*" %>
 Access650) this. width = 650; "src =" ../attachment/201304/155222570 .jpg" alt = "" border = "0"/> tomcatjsp Test
 
QQ chat group: 41405569

This article from the "IT Chen Yi" blog, please be sure to keep this source http://itchenyi.blog.51cto.com/4745638/1169267

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.