Two types of Web simplest load-balancing configurations (nginx haproxy)

Source: Internet
Author: User
Tags file copy node server haproxy

--------------------------------------------------------------

Centos 6.6 Environment PHP http://lampol.blog.51cto.com/11662628/1851016

--------------------------------------------------------------

Load balancing, The English name is load Balance, which means that it is distributed across multiple operating units for execution, such as Web servers, FTP servers, Enterprise Critical application servers, and other mission-critical servers, to work together to accomplish tasks.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/87/30/wKioL1fXY8SQknFKAABKKdRHZ24794.png "title=" Load balancer. png "alt=" wkiol1fxy8sqknfkaabkkdrhz24794.png "/>

Prepare 3 Servers

A server ip:192.168.1.121 (responsible for distribution to 149 and 142)

b Server ip:192.168.1.149

C Server ip:192.168.5.142

(i) nginx Configuration Load Balancer

Ngnix:

1, work in the network on the 7 layer, can be targeted for HTTP applications to do some diversion strategy, such as for the domain name, directory structure;

2, nginx dependence on the network is relatively small, in theory can ping through the load function;

3, Nginx Installation and configuration is relatively simple, testing more convenient;

4, can also bear high load pressure and stability, generally can support more than 10,000 times the concurrency;

5, the Back-end server health check, only support through the port to detect, not supported by the URL to Detect.

6, Nginx to the request of asynchronous processing can help the node server to reduce the load;

7, Nginx can only support http, HTTPS and email protocol, so that the scope of application is Small.

8, does not support the session of the direct hold, but can be resolved through the Ip_hash. , the support for big request header is not very good,

9. Support Load Balancing algorithm: round-robin (round robin), weight-round-robin (with weighted round), ip-hash (Ip hash)

10, Nginx can also do the Web server is the cache Function.


Configure nginx.conf Add the following configuration

Upstream 192.168.1.121 {
Server 192.168.1.149:80;
Server 192.168.1.142:80;
}

Server
{
Listen default_server;
server_name test.com;
location/{
Proxy_pass http://192.168.1.121;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
}

}

After configuration restart Nginx can browser input 192.168.1.121

And then refresh the page and distribute it to different ips.

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M01/87/33/wKiom1fXZxaRPZYIAABOe_lDfzQ138.png "style=" float: none; "title=" 1.png "alt=" wkiom1fxzxarpzyiaaboe_ldfzq138.png "/>

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M00/87/30/wKioL1fXZxfRmJzDAABSGCESIlM938.png "style=" float: none; "title=" qq20160913103429.png "alt=" wkiol1fxzxfrmjzdaabsgcesilm938.png "/>

(b) Haproxy installation Please refer to (http://lampol.blog.51cto.com/11662628/1852226)

1 Copy configuration file to Haproxy installed examples original file copy

CP haproxy.cfg/usr/local/haproxy/

Start configuration file

# This config needs haproxy-1.1.28 or haproxy-1.2.1
Global
Log 127.0.0.1 Local0
Log 127.0.0.1 Local1 Notice
#log Loghost local0 Info
Maxconn 4096
Chroot/usr/local/haproxy
UID 99
GID 99
Daemon
#debug
#quiet

Defaults
Log Global
Mode http
Option Httplog
Option Dontlognull
Retries 3
Timeout Connect 5000ms
Timeout Client 50000ms
Timeout Server 50000ms
Maxconn 2000

Frontend Http-front
Bind *:8080
Mode http
Option Httplog
Log Global
Default_backend Htmlbackend
Backend Htmlbackend
Balance Roundrobin
Server Web1 192.168.1.142:80 Cookie 1 weight 5 check Inter rise 2 Fall 3
Server web2 192.168.1.157:80 Cookie 2 weight 3 check Inter rise 2 Fall 3

Configuring the Haproxy startup script

#! /bin/sh
Set-e
Path=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/haproxy/sbin
Progdir=/usr/local/haproxy
Progname=haproxy
daemon= $PROGDIR/sbin/$PROGNAME
config= $PROGDIR/$PROGNAME. conf
pidfile= $PROGDIR/$PROGNAME. PID
desc= "HAProxy daemon"
Scriptname=/etc/init.d/$PROGNAME

# Gracefully Exit If the package has been removed.
Test-x $DAEMON | | Exit 0

Start ()
{
Echo-n "starting $DESC: $PROGNAME"
$DAEMON-f $CONFIG-p $PIDFILE
Echo "."
}

Stop ()
{
Echo-n "stopping $DESC: $PROGNAME"
Kill ' Cat $PIDFILE '
Rm-f $PIDFILE
Echo "."
}

Restart ()
{
Echo-n "restarting $DESC: $PROGNAME"
$DAEMON-f $CONFIG-p $PIDFILE-SF $ (cat $PIDFILE)
Echo "."
}

Case "$" in
Start
Start
;;
Stop
Stop
;;
Restart
Restart
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2
Exit 1
;;
Esac

Exit 0

Restart Haproxy Access 192.168.1.121:8080

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M01/87/35/wKioL1fXyKWyUynlAABO4vtR5Js692.png "style=" float: none; "title=" 11.png "alt=" wkiol1fxykwyuynlaabo4vtr5js692.png "/>

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M00/87/35/wKioL1fXyKXBvvfZAABAAgOHbd0146.png "style=" float: none; "title=" 22.png "alt=" wkiol1fxykxbvvfzaabaagohbd0146.png "/>

The load balancing configuration of the two methods is not perfect. later on, there is also a session sharing problem in Distribution. next article


This article is from the "ideal for life" blog, Please be sure to keep this source http://lampol.blog.51cto.com/11662628/1852214

Two types of Web simplest load-balancing configurations (nginx haproxy)

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.