Apache Consolidates Tomcat Connection database

Source: Internet
Author: User
Tags tomcat server

1.Apache comparison with Tomcat

Apache supports static pages, and Tomcat supports dynamic, such as Servlets.

For general use of Apache+tomcat, Apache is just a forwarding, and the processing of JSPs is handled by Tomcat.

Apache can support Php\cgi\perl, but to use Java, you need Tomcat to support Apache in the background and transfer Java requests from Apache to Tomcat processing.

Apache is a Web server , Tomcat is an application (Java) server, which is just a servlet (JSP also translated into a servlet) container, which can be considered Apache extension, but can be independent of the Apache run.

2. The benefits of consolidation are:
if the client is requesting a static page, only the Apache server responds to the request
If the client requests a dynamic page, the Tomcat server responds to the request
because JSP is a server-side interpretation code, consolidation can reduce the service overhead of Tomcat

Install lamp environment First Slightly

Implementing the Environment:

linux:centos6.5

Apache:httpd-2.2.16.tar.gz

Cmake:cmake-2.8.10.2.tar.gz

Mylsq:mysql-5.6.10.tar.gz

Php:php-5.3.28.tar.gz

Software used:

Tomcat:apache-tomcat-7.0.64.tar.gz

Tomcat connector: tomcat-connectors-1.2.32-src.tar.gz

Jdk:jdk-7u67-linux-x64.tar.gz

Tomcat Connection database: Mysql-connector-java 5.1.17

1. Installing the JDK

• Unzip and move the JDK

Tar zxvf jdk-8u31-linux-i586.tar.gz mv JDK1.8.0_31/USR/LOCAL/JDK

• Modify Environment variables

vim/etc/profile.d/java.sh

JAVA_HOME=/USR/LOCAL/JDK java_bin=/usr/local/jdk/binjre_home=/usr/local/jdk/jrepath= $PATH:/usr/local/jdk/bin:/ Usr/local/jdk/jre/binclasspath=/usr/local/jdk/jre/lib:/usr/local/jdk/lib:/usr/local/jdk/jre/lib/charsets.jar

· Initialize

. /etc/profile.d/java.sh

· test is configured successfully

Java-version

2. Install Tomcat

• Unzip and move

Tar zxvf apache-tomcat-7.0.57.tar.gz mv Apache-tomcat-7.0.57/usr/local/tomcat

• Start Tomcat

cd/usr/local/tomcat/bin./shutdown.sh #停止tomcat./startup.sh #启动tomcat

• Test Tomcat

Web site input ip:8080 The Tomcat default page appears

3. Integrating Tomcat and Apache Connectors for #需要借助apache-tomcat

• Unzip the Tomcat connector

Tar zxvf tomcat-connectors-1.2.32-src.tar.gz

• Specify Apache's APXS path

CD Tomcat-connectors-1.2.32-src/native./configure--with-apxs=/usr/local/apache2/bin/apxsmake

• Add MOD_JK Module

Tar zxvf jakarta-tomcat-connectors-1.2.15-src.tar.gzcd jakarta-tomcat-connectors-1.2.15-src./configure--with-apxs =/USR/LOCAL/APACHE2/BIN/APXSMAKECP./apache-2.0/mod_jk.so/usr/local/apache2/modules/

· Apache Integrated Tomcat

vim/usr/local/apache2/conf/httpd.conf add Nindex.jsp<ifmodule dir_module> DirectoryIndex on DirectoryIndex index.jsp index.php index.html</ifmodule>

• Add statements about loading MOD_JK

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/73/31/wKiom1X3jQOwmtLMAACzR6khj1g844.jpg "title=" 2@g3 ( 8ad[$F 3 (KT5 (]jqo4k.png "alt=" Wkiom1x3jqowmtlmaaczr6khj1g844.jpg "/>

• Create a configuration file under/usr/local/apache2/conf mod_jk.conf

Point out the MOD_JK module work required work file workers.properties location, JK Log where, JK log level, select the log format, Jkoptions send SSL key size display, Jkrequestlogformat set the required format , send all servlet and JSP requests through the AJP13 protocol to Tomcat for Tomcat to handle

vim /usr/local/apache2/conf/mod_jk.confjkworkersfile /usr/local /apache2/conf/workers.properties ###### where to put jk logsjklogfile /usr/ Local/apache2/logs/mod_jk.log ###### set the jk log level [debug/error/info ]jkloglevel info ###### select the log formatjklogstampformat  "[%a %b  %d %h:%m:%s %y] " ###### jkoptions indicate to send ssl key  SIZE,JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories ######  jkrequestlogformat set the request formatjkrequestlogformat  "%w %V %T"  ######  send all servlet  and JSP requests via AJP13 protocol to Tomcat for Tomcat to handle jkmount /servlet/*  Worker1jkmount /*.jsp worker1jkmount /*.do worker1 

• Create a configuration file under/usr/local/apache2/conf workers.properties

Define a worker called Worker1 ajp13 and type

vim/usr/local/apache2/conf/workers.propertiesworker.list=worker1worker.worker1.type=ajp13worker.worker1.host= Localhostworker.worker1.prot=8009worker.worker1.lbfactor=50worker.worker1.cachesize=10worker.worker1.cache_ timeout=600worker.worker1.socket_keepalive=1worker.worker1.socket_timeout=300

• Locate the Tomcat configuration file path and edit the Server.xml

Vim/usr/local/tomcat/conf/server.xml

• Added in

<context path= "" docbase= "/usr/local/apache2/htdocs" debug= "0" reloadable= "ture" crosscontext= "Ture"/>

• Edit a index.jsp web page

vim/usr/local/apache2/htdocs/index.jsp<% out.println ("Hello Tomcat"); %>

• Restart Tomcat and Apache

/usr/local/apache2/bin/apachectl restartcd/usr/local/tomcat/bin./shutdown.sh./startup.sh

• Integration complete, testing

Enter the IP address that appears hello Tomcat

4. Connect to the database

JSP using Mysql-connector-java 5.1.17 to connect MySQL

• Unzip the ZIP package

Unzip Mysql-connector-java 5.1.17.zip

• Put the Mysql-connector-java 5.1.17-bin.jar into the Lib directory under the Tomcat directory

CP mysql-connector-java-5.1.17-bin.jar/usr/local/tomcat/lib/

• Write a test page test_mysql. JSP To indicate that you can connect to the database if the page displays OK

vim /usr/local/apache2/htdocs/test_mysql.jsp<%@ page  Language= "java"  %><%@ page import= "Com.mysql.jdbc.Driver"  %><%@ page  import= "java.sql.*"  %><%string drivername= "Com.mysql.jdbc.Driver"; String username= "Root"; String userpasswd= "123"; String dbname= "Test"; String url= "jdbc:mysql://localhost/" +dbname+ "user=" +username+ "&password=" +USERPASSWD; Class.forName ("Com.mysql.jdbc.Driver"). Newinstance ();try{         Connection connection=drivermanager.getconnection (URL);         Out.println (" o k !");         connection.close ();} catch ( Exception e ) {        out.println (  connent  mysql error: " + e );} %> 

• Reboot Tomact and Apache, belong to ip/test_mysql.jsp OK is connected successfully

This article is from the "Ming Linux blog" blog, be sure to keep this source http://zhaijunming5.blog.51cto.com/10668883/1694887

Apache Consolidates Tomcat Connection database

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.