Centos6.0
HAProxy provides high availability, Server Load balancer, and TCP and HTTP application-based proxy. It supports Virtual Hosts and is a free, fast, and reliable solution. HAProxy is especially suitable for websites with extremely high loads, which usually require session persistence or layer-7 processing. HAProxy runs on the current hardware and supports tens of thousands of concurrent connections. In addition, its running mode enables it to be easily and securely integrated into your current architecture, while protecting your web servers from being exposed to the network.
Here, two Haproxy servers are responsible for backend control. keepalived is used for hot backup. The following is the question:
The figure is too disgusting, it will be next 650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/012R3I60-0.jpg "title =" 1.jpg"/>
Role; host name; ip address;
Haproxy1; node1 192.168.244.147
Haproxy2; node2 192.168.244.148
S1 (web1); lv1 192.168.244.149
S2 (web2); lv2 192.168.244.150
The two servers of Haproxy provide Vip: 192.168.244.200
1. First deploy httpd on lv1 and lv2
[root@lv1 ~]# yum install -y httpd
[root@lv2 ~]# yum install -y httpd
Mark all the index.html files;
Lv1 and lv2
Access test is normal
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/012R343E-1.jpg "title =" 1.jpg"/>
2. Deploy haproxy and keepalived on node1 and node2 respectively.
[root@node1 ~]# yum install -y keepalived haproxy
[root@node2 ~]# yum install -y keepalived haproxy
Configure haproxy
Node1:
#################### Global configuration ################# ####### global log 127.0.0.1 local0 # [err warning info debug] chroot/var/lib/haproxy # chroot running path pidfile/var/run/haproxy. pid # Storage path of the haproxy pid, the user who starts the process must have the permission to access this file maxconn 4000 # default maximum number of connections user haproxy # running user group nbproc 1 # Number of processes (you can set multiple process to improve performance) daemon # Run haproxy ######################## default global settings ######## ############### these parameters can be configured to frontend, backend, listen component # defaults mode http # type of processing (# Layer 7 http; Layer 4 tcp) log global option httplog # log Type http log format option dontlognull # do not record the Health Check log information option httpclose # automatically disable the http channel option forwardfor # If the backend server needs to obtain the client after each request is completed parameters to be configured for real ip addresses, you can obtain the Client ip option redispatch from the Http Header # After the server corresponding to the serverId fails, it is forcibly directed to another healthy server retries 3 # When the connection fails three times, the service is considered unavailable, you can also set stats refresh 20 # statistics page refresh Interval timeout connect 10 s # connection timeout client 5000 # client timeout server 50000 # server timeout maxconn 3000 balance roundrobin # default Load balanced, polling mode stats uri/haproxy-stats # monitoring Page's urllisten proxy *: 8080 option httpchk HEAD/index.html # Heartbeat detection File server server1 192.168.244.149: 80 cookie server1 check inter 1500 rise 3 fall 3 # server definition, cookie 1 indicates serverid is web1, check inter 1500 is the heartbeat detection frequency rise 3 is three times correctly think the server is available # fall 3 is three times failed think the server is unavailable, weight stands for the weight server server2 192.168.244.150: 80 cookie server2 check inter 1500 rise 3 fall 3
The haproxy configuration of node2 is the same, and copy is enough.
3. Configure keepalived on node1 and node2.
Node1:
! Configuration File for login {icationication_email {sysadmin@firewall.loc} login Alexandre.Cassen@firewall.loc smtp_server 192.168.200.1 route 30 router_id LVS_DEVEL} vrrp_script chk_http_port {script "/etc/keepalived/login" interval 2 # script execution interval weight-20 # priority changes caused by script results: 20 indicates priority + 20; -20 indicates priority-20} vrrp_instance VI_1 {state MASTER interface eth0 virtual_router_id 51 priority 100 advert_int 1 authentication {auth_type PASS auth_pass 1111} track_script {chk_http_port} virtual_ipaddress {192.168.244.200 }}
Edit script:
[Root @ node1 ~] # Cat/etc/keepalived/check_haproxy.sh #! /Bin/bashA = 'ps-C haproxy -- no-header | wc-l' if [$ A-eq 0]; then/etc/init. d/haproxy restartecho "Start haproxy" &>/dev/nullsleep 3if ['ps-C haproxy -- no-header | wc-l'-eq 0]; then/etc/init. d/keepalived stopecho "Disable keepalived" &>/dev/nullfifi
Node2 is the same as above,
priority
Change to 90;
Change state to BACKUP;
4. Start keepalived and haproxy respectively.
[Root @ node1 ~] #/Etc/init. d/haproxy start is starting haproxy: [root @ node1 ~] #/Etc/init. d/keepalived start is starting keepalived: [OK]
5. Test
node2:
[root@node2 ~]# tcpdump vrrp
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/012R3O13-2.jpg "title =" 1.jpg"/>
It indicates that the current vip address is node1, which provides services.
When you stop keepalived on node1, you will find that
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/012R32935-3.jpg "title =" 1.jpg"/>
Node2 replaced
Test web now
Http: // 192.168.244.200: 8080
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/012R31340-4.jpg "title =" 1.jpg"/> two browsers browse and discover that different machines are serving
Now open http: // 192.168.244.200: 8080/haproxy-stats
650) this. width = 650; "src =" http://img1.51cto.com/attachment/201305/193432970.jpg "title =" 1.jpg"/>
After you stop httpd on lv1:
[Root @ lv1 ~] #/Etc/init. d/httpd stop httpd: [OK]
You will find:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/012R353B-6.jpg "title =" 1.jpg"/>
Haproxy performs automatic removal. When restored, it automatically goes down;
The simple application is written here ~~ You are welcome to make a brick ~~
This article is from the Coffee _ Blue Mountains blog, please be sure to keep this source http://lansgg.blog.51cto.com/5675165/1212859