Load balancing using haproxy

Source: Internet
Author: User
Tags haproxy
Recently, a company's business has been growing fast, resulting in heavy pressure on front-end servers. in order to solve this problem as soon as possible, I submitted a request for purchasing servers to the company. soon the company approved the request and the servers were in place. how can we reasonably utilize the resources of newly purchased servers (originally a front-end server)? First, we thought that using nginx for load was a recent rapid development of a company's business, the pressure on front-end servers is very high. in order to solve this problem as soon as possible, I submitted a request for purchasing servers to the company. soon the company approved the request and the servers were in place. how can we reasonably utilize the resources of the newly purchased server (originally a front-end server )? NginxDo It Server load balancerEveryone knows NginxOkay, but the session cannot be synchronized. Is there any way? There are some solutions. HAProxy can be used to fill in the nginx deficiency.



I. install HAProxy
[Root @ xutest src] cd/usr/local/
[Root @ xutest src] wget
Http://www.dbasky.net/tool/haproxy-1.3.15.7.tar.gz
[Root @ xutest src] tar-zxvf haproxy-1.3.15.7.tar.gz
[Root @ xutest src] haproxy-1.3.15.7 cd
[Root @ xutest src] make TARGET = linux26 USE_STATIC_PCRE = 1
[Root @ xutest src] make install
PREFIX =/home

II. configuration 1) create a haproxy user group and User:
[Root @ xutest src] groupadd haproxy
[Root @ xutest src] useradd haproxy-g haproxy
2) view the user ID: [root @ xutest src] vi/etc/passwd
Haproxy: x: 500: 500:/home/haproxy:/bin/bash
3) create the HAProxy Directory: [root @ xutest opt] # mkdir/opt/haproxy
[Root @ xutest opt] # touch/opt/haproxy. cfg
4) configure haproxy. cfg [root @ xutest opt] # vi
/Opt/haproxy. cfg
Global
Log
127.0.0.1 local0
Maxconn 4096
Chroot/opt/haproxy
Uid 500
Gid 500
Daemon
Nbproc 1
# Pidfile
/Home/haproxy/logs/haproxy. pid
# Debug
# Quiet
ULTS
Log
127.0.0.1 local3
Mode
Http
Option httplog
Option
Httpclose
Option
Dontlognull
Option
Forwardfor
Option
Redispatch
Retries 2
Maxconn 2000
Balance roundrobin
Stats
Uri/haproxy-stats
Contimeout 5000
Clitimeout 50000
Srvtimeout 50000
Listen web_proxy 0.0.0.0: 8888
Option httpchk
Server web1
192.168.1.250: 8080 weight 3 check
Server web2
192.168.1.238: 8080 weight 3 check

3. start the main HAProxy process:
[Root @ xutest haproxy] #/usr/local/sbin/haproxy-f
/Opt/haproxy. cfg
Stop HAProxy: [root @ xutest haproxy] # ps aux | grep haproxy
[Root @ xutest haproxy] # kill-9 + process ID
After HAProxy is configured, you can view it in the browser: http: // 192.168.1.6: 8888/haproxy-stats/


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.