The tomct of the Nginx reverse band and the httpd load are all horizontal

Source: Internet
Author: User
Tags failover


Installation of Nginx

TAR-ZXVF pcre-8.30.tar.gz

CD pcre-8.30

Ntpdate time.windows.com

./configure

Make

Make install

Groupadd www


Useradd www-g www


Yum Install-y openssl-devel


TAR-ZXVF nginx-1.2.0.tar.gz


./configure--prefix=/usr/local/nginx--user=www--group=www--with-http_stub_status_module--with-http_ssl_module


Make


Make install



NGINX configuration file


User www www;


Worker_processes 8;


Pid/usr/local/nginx/logs/nginx.pid;


Worker_rlimit_nofile 51200;


Events


{


Use Epoll;


Worker_connections 51200;

}


http


{

Include Mime.types;


Default_type Application/octet-stream;


Server_names_hash_bucket_size 128;


Client_header_buffer_size 32k;


Large_client_header_buffers 4 32k;


Client_max_body_size 8m;


Sendfile on;


Tcp_nopush on;


Keepalive_timeout 60;


Tcp_nodelay on;


Fastcgi_connect_timeout 300;


Fastcgi_send_timeout 300;


Fastcgi_read_timeout 300;


Fastcgi_buffer_size 64k;


Fastcgi_buffers 4 64k;


Fastcgi_busy_buffers_size 128k;


Fastcgi_temp_file_write_size 128k;


gzip on;


Gzip_min_length 1k;


Gzip_buffers 4 16;


Gzip_http_version 1.0;


Gzip_comp_level 2;


Gzip_types text/plain application/x-javascript text/css application/xml;


Gzip_vary on;


Server


{


Listen 80;


server_name 192.168.88.145;


root/usr/local/nginx/html;


Index index.html index.htm index.php index.jsp index.do;


Location ~ \. (JSP|JSPDX|DO)? $ {#所有的jsp页面转交由tomcat处理


Proxy_set_header Host $host;


Proxy_set_header X-real-ip $remote _addr;


Proxy_pass http://127.0.0.1:8080; #转向tomcat处理

}

location~. *\. (htm|html|gif|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma) $ {#设置静态网页直接由nginx进行处理


Expires 30d;

}

Location ~. *\. (JS|CSS)? $ {


Expires 1h;

}

Log_format access ' $remote _addr-$remote _user [$time _local] "$request"


' $status $body _bytes_sent ' $http _referer '


' "$http _user_agent" $http _x_forwarded_for ';


Access_log/data/logs/access.log access;


}


}


Integration with Tomcat:

Package:

Jdk-7-linux-i586-rpm.bin

Apr-util-1.3.12.tar.gz

Apache-tomcat-7.0.27.tar.gz

Apr-1.4.5.tar.gz

TAR–ZXVF apr-1.4.5.tar.gz

CD apr-1.4.5

./configur

Make

Make install

TAR–ZXVF apr-util-1.3.12.tar.gz

./configure--WITH-APR=/USR/LOCAL/APR

Make

Make install

./Jdk-7-linux-i586-rpm.bin


RPM–IVH jdk-7-linux-i586-rpm

TAR–ZXVF apache-tomcat-7.0.27.tar.gz


Cp–a Apache-tomcat-7.0.27/usr/local/tomcat


Vi/etc/profile


At the end add:


Export Java_home= "/usr/java/jdk1.7.0/"


Export path= "$PATH: $JAVA _home/bin: $JAVA _home/jre/bin"


Export classpath= "$JAVA _home/lib: $JAVA _home/jre/lib"


Export Catalina_home= "/usr/local/tomcat"


Save exit

Export/etc/profile

Tomcat configuration file


Find the content below and change to


Unpackwars= "true" autodeploy= "true" >


<context path= "" docbase= "/usr/local/nginx/html/"/>

Then directly access: http://192.168.88.145/jsp.jsp, you can see the JSP Web page

HTTPD Load Balancing

Get ready:

1:apache, after downloading the direct installation, after the installation can access the local http://localhost/, on behalf of the installation completed. This time use the Apache2.2 version.

2:tomcat, after downloading the direct installation, after the installation can access the local http://localhost:8080, on behalf of the installation completed. This time use the Tomcat6.0 version.

3:jk,apache/iis is used to connect the backend Tomcat module to support cluster and load balancing. This time use the mod_jk-1.2.31-httpd-2.2.3.so version.

Method One:-----------------------------------------------------

Configure Apache:

1: Modify httpd.conf

My installation path: E:\Program Files\apache software foundation\apache2.2\conf\httpd.conf

Add include conf/mod_jk.conf at the end

2: New mod_jk.conf

Create a new mod_jk.conf configuration file under the Conf directory, as follows:

[Plain] View plaincopy

# Load MOD_JK Module

# Update This path to the match your modules location

LoadModule Jk_module modules/mod_jk-1.2.31-httpd-2.2.3.so

# Where to find Workers.properties

# Update This path to the match your Conf directory location (Put workers.properties next to httpd.conf)

Jkworkersfile conf/workers.properties

# Where to put JK shared memory

# Update This path to the match your local state directory or logs directory

Jkshmfile LOGS/MOD_JK.SHM

# Where to put JK logs

# Update This path to the match your logs directory location (Put Mod_jk.log next to Access_log)

Jklogfile Logs/mod_jk.log

# Set the JK log level [Debug/error/info]

Jkloglevel Info

# Select the timestamp log format

Jklogstampformat "[%a%b%d%h:%m:%s%Y]"

# Send everything for context/examples to worker named Worker1 (AJP13)

Jkmount/* Controller

3: Create a new workers.properties configuration file with the following content:

[Plain] View plaincopy

#server

Worker.list = Controller

#========tomcat1========

worker.tomcat1.port=8009

worker.tomcat1.host=172.23.49.131

Worker.tomcat1.type=ajp13

Worker.tomcat1.lbfactor = 1

# Define preferred failover node for TOMCAT1

#worker. tomcat1.redirect=tomcat2# #如果tomcat1宕机, call TOMCAT2 to handle the request.

#========tomcat2========

worker.tomcat2.port=9009

worker.tomcat2.host=127.0.0.1

Worker.tomcat2.type=ajp13

Worker.tomcat2.lbfactor = 1

# Disable Tomcat2for all requests except failover

#worker. tomcat2.activation=disabled # #当tomcat1正常工作时, tomcat2 "Rest"

#========controller, Load Balancer controller ========

Worker.controller.type=lb

Worker.controller.balanced_workers=tomcat1,tomcat2

Worker.controller.sticky_session=false

Worker.controller.sticky_session_force=1

#worker. controller.sticky_session=1


4: Add File

Copy the mod_jk-1.2.31-httpd-2.2.3.so you just downloaded to the E:\Program files\apache software foundation\apache2.2\modules directory.


Here the Apache configuration is basically done ————————————————————————————————————————

To configure Tomcat:

1: Copy the tomcat that you just downloaded to two copies of Apache-tomcat-01,apache-tomcat-02.

If 2 tomcat is on the same machine, we need to modify some of the ports. Open the Server.xml under the apache-tomcat-02 conf directory.

2: Modify the tomcat02 shutdown port to remain unchanged for 9005,tomcat01 8005.

3: Modify the TOMCAT02 connector port to remain unchanged for 9080,tomcat01 8080.

4: Modify the port of ajp/1,3 to 9009,tomcat01 8009 remains unchanged.

5: Modify <engine name= "Catalina" defaulthost= "localhost" jvmroute= "tomcat1" > tag contents, plus jvmroute= "tomcat1" property, Note: Both tomcat01 and tomcat02 are to be modified.


6: Enable <cluster classname= "Org.apache.catalina.ha.tcp.SimpleTcpCluster"/> Tag, note: Both tomcat01 and tomcat02 are enabled.


Here the Tomcat configuration is basically complete ————————————————————————————————————————


Method Two:-----------------------------------------------------

Configure Apache:

1: Modify httpd.conf

My installation path: E:\Program Files\apache software foundation\apache2.2\conf\httpd.conf

At the end add:

[Plain] View plaincopy

Proxyrequests OFF

Proxypass/balancer://abc/stickysession=jsessionid Nofailover=on

<proxy balancer://abc/>

Balancermember ajp://127.0.0.1:8009 loadfactor=1 ROUTE=TOMCAT1

Balancermember ajp://localhost:9009 loadfactor=1 ROUTE=TOMCAT2

</Proxy>



To configure Tomcat:

Same Method one

Here to configure the basic completion ————————————————————————————————————————


Test results:

Add the folder test to the tomcat01 and tomcat02 WebApps, add the folder Web-inf and test.jsp under test, and the Web. XML configuration file in Web-inf.

The Web. XML configuration file reads as follows:

[Plain] View plaincopy

<?xml version= "1.0" encoding= "Iso-8859-1"?>

<web-app xmlns= "Http://java.sun.com/xml/ns/j2ee" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation= "Http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd" version= "2.5" >

<distributable/>

</web-app>




The test.jsp configuration is as follows:

[Plain] View plaincopy

<%@ page contenttype= "text/html; CHARSET=GBK "%>

<%@ page import= "java.util.*"%>

<body>

Server Info:

<%

Out.println (REQUEST.GETLOCALADDR () + ":" + request.getlocalport () + "<br>");%>

<%

Out.println ("<br> ID" + session.getid () + "<br>");

String dataname = Request.getparameter ("Dataname");

if (dataname! = null && dataname.length () > 0) {

String DataValue = Request.getparameter ("DataValue");

Session.setattribute (Dataname, DataValue);

}

Out.print ("<b>session list </b>");

Enumeration E = Session.getattributenames ();

while (E.hasmoreelements ()) {

String name = (string) e.nextelement ();

String value = Session.getattribute (name). toString ();

OUT.PRINTLN (name + "=" + value+ "<br>");

SYSTEM.OUT.PRINTLN (name + "=" + value);

}

%>

<form action= "test.jsp" method= "POST" >

Name: <input type=text size=20 name= "Dataname" >

<br>

Value: <input type=text size=20 name= "DataValue" >

<br>

<input type=submit>

</form>

</body>



Here to test the content configuration is basically complete

Access address http://127.0.0.1/test/test.jsp, display page


F5 after refreshing the page


Refresh the page multiple times, where SessionID is the same ID, indicating that the session has been replicated.

Input content View


F5 Refresh Page


You can see that when you copy a session, the variables in the session are also duplicated.


This article is from the "Hanye" blog, make sure to keep this source http://9025736.blog.51cto.com/9015736/1590143

The tomct of the Nginx reverse band and the httpd load are all horizontal

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.