Keepalived high-availability servers and Haproxy load balancing

Source: Internet
Author: User

Keepalived high-availability servers and Haproxy load balancing keepalive operating principle
Keepalived检测每个服务节点状态当服务器节点异常或工作出现故障,keepalived将故障节点从集群从集群系统中踢除故障节点恢复后,自动将其加入使用keepalived软件配置HA集群
Configuring HA clusters with keepalived software 1. Hosts that provide services need to install keepalived and Web services
yum -y install httpd keepalived
2. Modify the keepalived configuration file for the host that provides the service
35行以后是做调度器的高可用配置
Planning master, standby server, set VIP (public IP)
这里的主备是抢占式的global_defs {   notification_email {     [email protected]   //设置报警收件人邮箱  }  notification_email_from [email protected] //发件人邮箱  smtp_server 192.168.200.1   //邮件服务器地址  smtp_connect_timeout 30  //邮件超时时间  router_id LVS_DEVEL      //设置路由ID  #vrrp_strict    //这条需要注释掉,不然下面的VIP就会不通}vrrp_instance webha {  //webha 集群名称  state MASTER    //描述名,  interface eth0   //与集群内服务主机之间通信使用网卡  virtual_router_id 51    priority 100     //优先级,数值越高,越优先,主的优先级高,默认100                          优先级最大255,超过失效  advert_int 1    //集群内服务主机之间的通信时间间隔,单位秒 authentication {      auth_type PASS  //认证类型     auth_pass 1111  //使用密码  }  virtual_ipaddress {    //设置VIP地址       192.168.200.16 }}
When the Web service is down, the dispatch master of the highly available cluster does not float the VIP
vim /root/check_80.sh#!/bin/bashnetstat -ntulp | grep 80 if [ $? -ne 0 ];thensystemctl stop keepaloved.serviceif
Comprehensive application: Keepalived+lvs configuration of the LVS scheduler ha cluster requirements: Host A is configured as the main LVS scheduler, b host for the standby LVS Scheduler, when the dispatcher a down, b host immediately enable
Install keepalived software on 1.A, B, ipvsadm software yum-y install keepalived ipvsadm2. Modify/etc/keepalived/keepalived.conf Modify priority partition Master standby (AB) Service host modify authentication password Master standby (AB) server password must be consistent modified IPV (virtual_ipaddress) to 192.168.4.253 The following configuration A, B consistent virtual_server 192.168.4 .253 80 {//define virtual Dispatch machine Delay_loop 6 Lb_algo RR//scheduling algorithm Lb_kind DR//working mode, working with background realserver Pattern consistent Persistence_timeout Protocol TCP connect_timeout 3 nb_get_retry 3 Delay_before_retry 3 R Eal_server 192.168.4.52 80 {///Background Web service Host weight 1} This step is to set a, B as the keepalived master, plus LVS (IPVSADM) for high Availability (HA) and load Balancing (LB) Comprehensive application of 3. Start and set power on (keepalived) systemctl restart Keepalived.service systemctl enable on a, b Keepalived.service4. Testing on the client, Curl http://192.168.4.253 premise: The machine that provides the Web service in the background must work correctly echo 1 >/proc/sys/net/ipv4/conf/lo    /arp_ignore echo 2 >/proc/sys/net/ipv4/conf/lo/arp_announce echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore Echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce ifconfig lo:1 192.168.4.253/32 
Extension: After the above configuration is done, keepalived does not perform a health check on the backend httpd service, and if necessary, a TCP connection check is required
real_server 192.168.4.52 80 {     weight 1       TCP_CHECK {           connect_timeout 3           nb_get_retry 3           delay_before_retry 3       }  }
configuring LB clusters with Haproxy software
工作模式 1.mode http        2.mode tcp    3.mode htalth
Mode http
1.http close   每次响应请求后立即断开连接2.keep-alive   每一连接可以发起多个请求,但是多个请求需要服务器按顺序一个一个响应不能一次性作出响应3.pipelining      一次连接可以发起多次请求,这些请求服务器并行进行响应,同时处理请求,减少了延迟,但是   对服务器的要求比较高,
Configuration:
1.装包   Yum -y install haproxy2.配置文件及介绍  Vim /etc/haproxy/haproxy.cfg    default:为后续的其他部分设置默认参数,缺省参数可以被后续部分覆盖    frontend:描述接收客户端侦听套接紫集    backend:描述转发连接的服务器集    listen:把frontend和backend结合到一起的完整声明//这里为/etc/haproxy/haproxy.cfg的配置    default   stats uri  /admin     #以友好的页面展示LB集群实际状况   listen webla 192.168.4.56:80cookie SERVERID rewritebalance roundrobinserver weba 192.168.4.55:80 cookie app1inst1 check inter 2000 rise 2 fall 5server webb 192.168.4.57:80 cookie app2inst2 check inter 2000 rise 2 fall 53.启动服务及查看状态   Systemctl restart haproxy   Systemctl status haproxy4.有好页面的访问   http://192.168.4.56/admin

Keepalived high-availability servers and Haproxy load balancing

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.