Keepalived完结HAproxy高可用详明,Keepalived轻松营造高可用集群

以前一贯用heartbeat或corosync+pacemaker构建高可用集群,现在意识keepalived完成起来更简约。

一,keepalived介绍

[plain] view
plaincopy

keepalived的master向backup发送广播,当backup风华正茂段时间收不到对方传来的V凯雷德RP广播时,backup会通过公投五个master,master就能够重新具备能源。具体的理论知识参见
http://www.linuxidc.com/Linux/2012-12/76886.htm

keepalived是二个方可兑现有个别财富高可用的开源软件,其利害攸关的零器件满含core,check,vrrp,libipfwc,libipvs,这里说下生龙活虎风流浪漫零器件的功效。

  1. Nginx Master: 192.168.128.134  
  2. Nginx Backup: 192.168.128.138  
  3. VIP:192.168.128.177  

实验对象:2台Nginx+Keepalived 2台Lamp构建高可用Web集群

core:keepalived的为主构件,担任主进度的运维和珍贵以致加载解析配置文件等。

Nginx安装见nginx安装配备文书档案

规划:

check:担负healthchecker,担任各类健检方式,和相应的布局剖析以致LVS的布署解析。

Master与Backup的Nginx配置大器晚成致.

ng1.laoguang.me 192.168.1.22 ng1 
ng2.laoguang.me 192.168.1.23 ng2 
lamp1.laoguang.me  192.168.1.24 lamp1 
lamp2.laoguang.me  192.168.1.25 lamp2

vrrp:vrrpd的子进程。

在MASTER跟BACKUP上安装Keepalived:

拓扑:

libipfwc:结合iptables的ipchains库来利用。

[plain] view
plaincopy

亚洲必赢官网 1

libipvs:结合LVS使用。

  1. #tar zxvf keepalived-1.1.15.tar.gz -C ../software  
  2. #cd ../software/keepalived-1.1.15  
  3. #./configure –prefix=/usr/local/keepalived && make && make install  
  4. #cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/  
  5. #cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/  
  6. #mkdir /etc/keepalived  
  7. #cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/  
  8. #cp /usr/local/keepalived/sbin/keepalived /usr/sbin/  
  9. #service keepalived start|stop #做成系统运转服务方便人民群众管理.  

豆蔻年华.主导条件计划

keepalived运行后会生成3个进程,master主进度,VTiggoRP子进度,healthchecker子进程。

修改MASTER 的keepalived.conf

ng1,ng2上安装nginx

VRAV4RP合同是落到实处keepalived高可用的三个根基,上面说一下VSportageRP的兑现原理:

[plain] view
plaincopy

lamp1,lamp2上营造LAMP或只设置httpd,笔者只设置了Httpd,这里不给我们演示了,有须求请看小编的任何博文,改革lamp1,lamp2的index.html的剧情分别为lamp1和lamp2,以轻便区分,实际集群中剧情应当是千篇生机勃勃律的,由分享存储提供。

V哈弗RP设想路由(V中华VRP
router),V普拉多RP是二个“大选”合同,它亦可动态地将三个虚构路由器的权利钦赐至同五个VTucsonRP组中的此外路由器上,V奥迪Q7RP的优势:

  1. #vim /etc/keepalived/keepalived.conf  
  2. vrrp_script chk_http_port {         
  3.         script “/usr/local/scripts/nginx_pid.sh” ###监理脚本  
  4.         interval 2 ###督察时间  
  5.         weight 2  
  6.         }  
  7. vrrp_instance VI_1 {  
  8.         state MASTER ### 设置为主  
  9.         interface eth0 ### 监察和控制网卡  
  10.         virtual_router_id 51 ### 这么些两台服务器必须黄金年代致  
  11.         priority 101 ### 权重值MASTRE应当要高于BAUCKUP  
  12.         authentication {  
  13.         auth_type PASS ### 加密  
  14.         auth_pass test ### 加密的密码,两台服务器必定要平等,不然会出错  
  15.         }  
  16.         track_script {  
  17.         chk_http_port ### 施行监督的服务  
  18.         }  
  19.         virtual_ipaddress {                  
  20.         192.168.128.177 ### VIP 地址          
  21.         }  
  22. }  

二.ng1,ng2上设置配备keepalived

冗余:能够利用三个路由器设备作为LAN顾客端的私下认可网关,大大减少了暗中同意网关成为单点故障的恐怕性;

修改BACKUP keepalived.conf

下载地址:

负载分享:允许来自LAN客商端的流量由多个路由器设备所分享;

[plain] view
plaincopy

2.1 安装keepalived

多VLacrosseRP组:在两个路由器具理接口上可配备多达2五16个V牧马人RP组;

  1. #vim /etc/keepalived/keepalived.conf  
  2. vrrp_script chk_http_port {  
  3.         script “/opt/nginx_pid.sh”  
  4.         interval 2  
  5.         weight 2  
  6. }  
  7. vrrp_instance VI_1 {  
  8.         state BACKUP ### 设置为备份机  
  9.         interface eth0  
  10.         virtual_router_id 51 ### 与 MASTRE 设置值相通  
  11.         priority 80 ### 比 MASTRE权重值低  
  12.   
  13.         authentication {  
  14.         auth_type PASS  
  15.         auth_pass test ### 密码 与 MASTRE 一样  
  16.         }  
  17.         track_script {  
  18.         chk_http_port  
  19.         }  
  20.         virtual_ipaddress {  
  21.         192.168.128.177  
  22.         }  
  23. }  
  1. tar xvf keepalived-1.2.7.tar.gz
  2. cd keepalived-1.2.7
  3. ./configure –prefix=/usr/local/keepalived
  4. ##只怕会提示安装popt-devel包,yum就可以

  5. make && make install

多IP地址:基于接口外号在同叁个物理接口上布署八个IP地址,进而援救在同多少个大要接口上接入几个子网;

编写制定监察和控制nginx监察和控制脚本

2.2 收拾配置文件与剧本

抢占:在master故障时允许先行级更加高的backup成为master;

[plain] view
plaincopy

  1. mkdir /etc/keepalived
  2. ##keepalived暗中认可配置文件从/etc/keepalived下读取
  3. cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
  4. ##就贰个二进制文件,直接拷贝过去就可以,多的话就矫正PATH吧

  5. cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

  6. ##本子的附加安插文件读取地方
  7. cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
  8. ##开发银行脚本你精晓
  9. cp /usr/local/keepalived/etc/keepalived/keepalived.conf
    /etc/keepalived/
  10. ##笔者们最首要的keepalived配置文件

文告公约:使用IANA所钦命的组播地址224.0.0.18进展V兰德哈弗RP公告;

  1. #vim /usr/local/scripts/nginx_pid.sh  
  2. #!/bin/bash  
  3. A=`ps -C nginx –no-header |wc -l` ## 查看是不是有 nginx进度 把值赋给变量A  
  4. if [ $A -eq 0 ];then <span style=”white-space:pre”> </span>## 若无经过值得为 零  
  5. <span style=”white-space:pre”>  </span>/usr/local/nginx/sbin/nginx  
  6. <span style=”white-space:pre”>  </span>sleep 3  
  7. <span style=”white-space:pre”>  </span>if [ `ps -C nginx –no-header |wc -l` -eq 0 ];then  
  8. <span style=”white-space:pre”>  </span>killall keepalived ## 则结束 keepalived 进程  
  9. <span style=”white-space:pre”>  </span>fi  
  10. fi  

2.3 修改ng1的/etc/keepalived/keepalived.conf

VRubiconRP追踪:基于接口状态来改动其VLacrosseRP优先级来分明最棒的V奥迪Q3RP路由器成为master;

测量试验,分别在两个服务器 运转 nginx 和 keepalived

  1. ! Configuration File for keepalived
    1. global_defs {
  2. notification_email {
  3. ibuler@qq.com ##出故障发送邮件给哪个人

  4. }

  5. notification_email_from keepalived@localhost ##故障用哪些邮箱发送邮件
  6. smtp_server 127.0.0.1 ##SMTP_Server IP
  7. smtp_connect_timeout 30 ##过期时间
  8. router_id LVS_DEVEL ##Keepalived完结HAproxy高可用详明,Keepalived轻松营造高可用集群。服务器标记

  9. }

    1. vrrp_instance VI_1 {
  10. state BACKUP
  11. ##境况,都为BACKUP,它们会选出Master,假若您写MASTE奥迪Q7,它就能够是Master,
  12. ##当Master故障时Backup会成为Master,当原本的Master复苏后,原本的Master会成为Master

  13. interface eth0
    ##出殡VEscortRP的接口,细心看您的是或不是eth0

  14. virtual_router_id 51 ##虚构路由标记,同叁个组应该用四个,即Master与Backup同三个

  15. priority 100 ##重在的事先级哦

  16. nopreempt ##不抢占,三个故障时,重启后复原后不抢占意能源

  17. advert_int 1
    ##一齐间距时间长度
  18. authentication { ##认证
  19. auth_type PASS ##表明格局
  20. auth_pass www.laoguang.me ##密钥
  21. }
  22. virtual_ipaddress {
  23. 192.168.1.18 ##VIP
  24. }
  25. }
  26. ##末尾的去除吧,LVS上才有用

二,实验情况:

[plain] view
plaincopy

拷贝到ng2上一份,只修改priority 90 即可

192.168.30.116
OS:CentOS 6.4 x86_64 
master.luojianlong.com

  1. #/usr/local/nginx/sbin/nginx  
  2. #/etc/init.d/keepalived start  
  1. scp /etc/keepalived/keepalived.conf 192.168.1.23:/etc/keepalived/
  2. ##Ng2上
  3. vi /etc/keepalived/keepalived.conf priority 90 ##别的生机勃勃致

192.168.30.117 OS:Centos 6.4 x86_64  backup.luojianlong.com

监控 Nginx Mastaer 的日志

2.4 ng1,ng2上启动keepalived

keepalived版本:keepalived-1.2.7

[plain] view
plaincopy

  1. service keepalived start

先是,分别在2台服务器上,安装keepalived,haproxy,由于系统版本是Centos
6.4,那2个软件已经被重新整合在中间了,所以使用yum来安装

  1. May 12 17:33:44 localhost Keepalived_vrrp: Configuration is using : 35676 Bytes  
  2. May 12 17:33:44 localhost Keepalived: Starting VRRP child process, pid=1245  
  3. May 12 17:33:44 localhost Keepalived_vrrp: VRRP sockpool: [ifindex(2), proto(112), fd(8,9)]  
  4. May 12 17:33:45 localhost Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE  
  5. May 12 17:33:46 localhost Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE  
  6. May 12 17:33:46 localhost Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.  
  7. May 12 17:33:46 localhost Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.128.177  
  8. May 12 17:33:46 localhost avahi-daemon[2344]: Registering new address record for 192.168.128.177 on eth0.  
  9. May 12 17:33:46 localhost Keepalived_vrrp: Netlink reflector reports IP 192.168.128.177 added  

查阅日志

[root@master ~]# yum -y install keepalived haproxy

监控 Nginx Backup 的日志

  1. tail /var/log/messages
    1. Nov 27 08:07:54 localhost Keepalived_vrrp[41871]:
      VRRP_Instance(VI_1) Entering BACKUP STATE
  2. Nov 27 08:07:54 localhost Keepalived_vrrp[41871]: VRRP sockpool:
    [ifindex(2), proto(112), fd(11,12)]
  3. Nov 27 08:07:54 localhost Keepalived_healthcheckers[41870]: Using
    LinkWatch kernel netlink reflector…
  4. Nov 27 08:07:54 localhost Keepalived_vrrp[41871]:
    VRRP_Instance(VI_1) forcing a new MASTER election
  5. Nov 27 08:07:55 localhost Keepalived_vrrp[41871]:
    VRRP_Instance(VI_1) Transition to MASTER STATE
  6. Nov 27 08:07:56 localhost Keepalived_vrrp[41871]:
    VRRP_Instance(VI_1) Entering MASTER STATE
  7. Nov 27 08:07:56 localhost Keepalived_vrrp[41871]:
    VRRP_Instance(VI_1) setting protocol VIPs.
  8. Nov 27 08:07:56 localhost Keepalived_healthcheckers[41870]:
    Netlink reflector reports IP 192.168.1.18 added
  9. Nov 27 08:07:56 localhost Keepalived_vrrp[41871]:
    VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for
    192.168.1.18
  10. Nov 27 08:08:01 localhost Keepalived_vrrp[41871]:
    VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for
    192.168.1.18

[root@backup ~]# yum -y install keepalived haproxy

[plain] view
plaincopy

翻开vip绑定到哪台机器上了

接下去,先安排master与backup服务器的优先级,virtual_router_id(同四个实例2台服务器必得生龙活虎律卡塔 尔(阿拉伯语:قطر‎,编辑配置文件:

  1. May 11 22:28:21 localhost Keepalived: Starting Keepalived v1.1.15 (05/11,2010)  
  2. May 11 22:28:21 localhost Keepalived_vrrp: Using MII-BMSR NIC polling thread…  
  3. May 11 22:28:21 localhost Keepalived_vrrp: Registering Kernel netlink reflector  
  4. May 11 22:28:21 localhost Keepalived_vrrp: Registering Kernel netlink command channel  
  5. May 11 22:28:21 localhost Keepalived_vrrp: Registering gratutious ARP shared channel  
  6. May 11 22:28:21 localhost Keepalived: Starting VRRP child process, pid=27040  
  7. May 11 22:28:21 localhost Keepalived_vrrp: Opening file ‘/etc/keepalived/keepalived.conf’.  
  8. May 11 22:28:21 localhost Keepalived_vrrp: Configuration is using : 35538 Bytes  
  9. May 11 22:28:21 localhost Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE  
  10. May 11 22:28:21 localhost Keepalived_vrrp: VRRP sockpool: [ifindex(2), proto(112), fd(7,8)]  
  11. May 11 22:28:23 localhost Keepalived_vrrp: VRRP_Script(chk_http_port) succeeded  
  1. ip addr ##ng1上
    1. ….省略
  2. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen
    1000
  3. link/ether 00:0c:29:e8:90:0b brd ff:ff:ff:ff:ff:ff
  4. inet 192.168.1.22/24 brd 192.168.1.255 scope global eth0
  5. inet 192.168.1.18/32 scope global eth0
  6. inet6 fe80::20c:29ff:fee8:900b/64 scope link
  7. 亚洲必赢官网,valid_lft forever preferred_lft forever

[root@master ~]# cp /etc/keepalived/keepalived.conf
/etc/keepalived/keepalived.conf.bak

看日志能够看出,两台服务器的 MASTRE 和 BACUKUP 已经都符合规律了

测度vip绑定到ng1上了

[root@backup ~]# cp /etc/keepalived/keepalived.conf
/etc/keepalived/keepalived.conf.bak

近来我们把Master的Nginx停掉.查看Backup的日志

亚洲必赢官网 2

[root@master ~]# vi /etc/keepalived/keepalived.conf

[plain] view
plaincopy

! Configuration File for keepalived

  1. May 11 22:28:21 localhost Keepalived: Starting VRRP child process, pid=27040  
  2. May 11 22:28:21 localhost Keepalived_vrrp: Opening file ‘/etc/keepalived/keepalived.conf’.  
  3. May 11 22:28:21 localhost Keepalived_vrrp: Configuration is using : 35538 Bytes  
  4. May 11 22:28:21 localhost Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE  
  5. May 11 22:28:21 localhost Keepalived_vrrp: VRRP sockpool: [ifindex(2), proto(112), fd(7,8)]  
  6. May 11 22:28:23 localhost Keepalived_vrrp: VRRP_Script(chk_http_port) succeeded  
  7. May 11 22:29:25 localhost Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE  
  8. May 11 22:29:26 localhost Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE  
  9. May 11 22:29:26 localhost Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.  
  10. May 11 22:29:26 localhost Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.128.177  

global_defs {

可以看见backup已经济体改为master

  notification_email {

现行反革命再起步原本master的nginx,再查看backup的日志

    acassen@firewall.loc

[plain] view
plaincopy

    failover@firewall.loc

  1. May 11 22:30:32 localhost Keepalived_vrrp: VRRP_Instance(VI_1) Received higher prio advert  
  2. May 11 22:30:32 localhost Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE  
  3. May 11 22:30:32 localhost Keepalived_vrrp: VRRP_Instance(VI_1) removing protocol VIPs.  
  4. May 11 22:30:32 localhost avahi-daemon[2409]: Withdrawing address record for 192.168.128.177 on eth0.  

    sysadmin@firewall.loc

可以看出又变回了backup.

  }

  notification_email_from Alexandre.Cassen@firewall.loc

  smtp_server 192.168.200.1

  smtp_connect_timeout 30

  router_id LVS_DEVEL

}

vrrp_instance VI_1 {

    state MASTER

    interface eth0

    virtual_router_id 51

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

        192.168.30.230

    }

}

[root@backup ~]# vi /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {

  notification_email {

    acassen@firewall.loc

    failover@firewall.loc

    sysadmin@firewall.loc

  }

  notification_email_from Alexandre.Cassen@firewall.loc

  smtp_server 192.168.200.1

  smtp_connect_timeout 30

  router_id LVS_DEVEL

}

vrrp_instance VI_1 {

    state BACKUP

    interface eth0

    virtual_router_id 51

    priority 99

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

        192.168.30.230

    }

}

 

 

global_defs:全局配置标记破;

notification_email:表示告急时发送的邮件地址;

notification_email_from:表示发送邮件的源地址;

smtp_server:发送邮件的smtp服务器地址;

router_id:机器标记;

vrrp_instance:定义二个vrrp实例;

state:state指定instance(Initial)的上马状态,便是说在布署好后,这台服务器的启幕状态就是此处钦点的,但这里钦定的不算,照旧得要经过选举通过事先级来鲜明,里假如这里安装为master,但若是她的开始时期级比不上别的朝气蓬勃台,那么那台在出殡和下葬通告时,会发送温馨的优先级,别的豆蔻年华台开采优先级不及自身的高,那么她会就回抢占为master;

interface:实例绑定的网卡,因为在安插设想IP的时候必得是在已部分网卡上助长的;

 

virtual router
id:这里安装VLX570ID,那Ritter别首要,相近的V宝马X5ID为二个组,他将决定多播的MAC地址;

 

priority 100:设置本节点的优先级,优先级高的为master;

 

advert int:检查间距,默以为1秒;

 

virtual
ipaddress:这里设置的正是VIP,也便是虚构IP地址,他乘机state的浮动而充实删除,当state为master的时候就增加,当state为backup的时候删除,这里根本是有优先级来调整的,和state设置的值未有多大关系,这里能够设置七个IP地址;

 

authentication:这里设置验证;

 

auth type:认证格局,能够是PASS或AH二种申明方法;

 

auth pass:认证密码;

起步俩台服务器的keepalived

[root@master ~]# service keepalived start

Starting keepalived:                                      [  OK  ]

[root@backup ~]# service keepalived start

Starting keepalived:                                      [  OK  ]

[root@master ~]# tail -f /var/log/messages

Jan 10 11:40:56 localhost Keepalived_healthcheckers[19368]: Using
LinkWatch kernel netlink reflector…

Jan 10 11:40:56 localhost Keepalived_vrrp[19369]: Opening file
‘/etc/keepalived/keepalived.conf’.

Jan 10 11:40:56 localhost Keepalived_vrrp[19369]: Configuration is
using : 63019 Bytes

Jan 10 11:40:56 localhost Keepalived_vrrp[19369]: Using LinkWatch
kernel netlink reflector…

Jan 10 11:40:56 localhost Keepalived_vrrp[19369]: VRRP sockpool:
[ifindex(2), proto(112), fd(10,11)]

Jan 10 11:40:57 localhost Keepalived_vrrp[19369]:
VRRP_Instance(VI_1) Transition to MASTER STATE

Jan 10 11:40:58 localhost Keepalived_vrrp[19369]:
VRRP_Instance(VI_1) Entering MASTER STATE

Jan 10 11:40:58 localhost Keepalived_vrrp[19369]:
VRRP_Instance(VI_1) setting protocol VIPs.

Jan 10 11:40:58 localhost Keepalived_healthcheckers[19368]: Netlink
reflector reports IP 192.168.30.230 added

Jan 10 11:40:58 localhost Keepalived_vrrp[19369]:
VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.30.230

Jan 10 11:41:03 localhost Keepalived_vrrp[19369]:
VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.30.230

Jan 10 11:41:14 localhost Keepalived_vrrp[19369]:
VRRP_Instance(VI_1) Received lower prio advert, forcing new election

Jan 10 11:41:14 localhost Keepalived_vrrp[19369]:
VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.30.230

[root@master ~]# ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state
UNKNOWN

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host

      valid_lft forever preferred_lft forever

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc
pfifo_fast state UP qlen 1000

    link/ether 00:0c:29:f3:fc:ba brd ff:ff:ff:ff:ff:ff

    inet 192.168.30.116/24 brd 192.168.30.255 scope global eth0

    inet 192.168.30.230/32 scope global eth0

    inet6 fe80::20c:29ff:fef3:fcba/64 scope link

      valid_lft forever preferred_lft forever

发掘刚才定义的virtual ipaddress在master服务器上,因为事先级较高

停下master服务器的keepalived服务器,看IP会不会转移到backup

[root@master ~]# service keepalived stop

Stopping keepalived:                                      [  OK  ]

[root@backup ~]# tail -f /var/log/messages

Jan 10 12:12:46 localhost Keepalived_vrrp[18581]: Opening file
‘/etc/keepalived/keepalived.conf’.

Jan 10 12:12:46 localhost Keepalived_vrrp[18581]: Configuration is
using : 63017 Bytes

Jan 10 12:12:46 localhost Keepalived_vrrp[18581]: Using LinkWatch
kernel netlink reflector…

Jan 10 12:12:46 localhost Keepalived_healthcheckers[18580]: Opening
file ‘/etc/keepalived/keepalived.conf’.

Jan 10 12:12:46 localhost Keepalived_healthcheckers[18580]:
Configuration is using : 7324 Bytes

Jan 10 12:12:46 localhost Keepalived_healthcheckers[18580]: Using
LinkWatch kernel netlink reflector…

Jan 10 12:12:46 localhost Keepalived_vrrp[18581]: VRRP sockpool:
[ifindex(2), proto(112), fd(10,11)]

Jan 10 12:12:47 localhost Keepalived_vrrp[18581]:
VRRP_Instance(VI_1) Transition to MASTER STATE

Jan 10 12:12:47 localhost Keepalived_vrrp[18581]:
VRRP_Instance(VI_1) Received higher prio advert

Jan 10 12:12:47 localhost Keepalived_vrrp[18581]:
VRRP_Instance(VI_1) Entering BACKUP STATE

Jan 10 12:16:27 localhost Keepalived_vrrp[18581]:
VRRP_Instance(VI_1) Transition to MASTER STATE

Jan 10 12:16:28 localhost Keepalived_vrrp[18581]:
VRRP_Instance(VI_1) Entering MASTER STATE

Jan 10 12:16:28 localhost Keepalived_vrrp[18581]:
VRRP_Instance(VI_1) setting protocol VIPs.

Jan 10 12:16:28 localhost Keepalived_healthcheckers[18580]: Netlink
reflector reports IP 192.168.30.230 added

Jan 10 12:16:28 localhost Keepalived_vrrp[18581]:
VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.30.230

Jan 10 12:16:33 localhost Keepalived_vrrp[18581]:
VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.30.230

[root@backup ~]# ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state
UNKNOWN

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host

      valid_lft forever preferred_lft forever

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc
pfifo_fast state UP qlen 1000

    link/ether 00:0c:29:5b:50:f9 brd ff:ff:ff:ff:ff:ff

    inet 192.168.30.117/24 brd 192.168.30.255 scope global eth0

    inet 192.168.30.230/32 scope global eth0

    inet6 fe80::20c:29ff:fe5b:50f9/64 scope link

      valid_lft forever preferred_lft forever

发觉IP已经转移到backup服务器

下边重新启航master的keepalived

[root@master ~]# service keepalived start

Starting keepalived:                                      [  OK  ]

[root@backup ~]# tail -f /var/log/messages

Jan 10 12:12:46 localhost Keepalived_vrrp[18581]: VRRP sockpool:
[ifindex(2), proto(112), fd(10,11)]

Jan 10 12:12:47 localhost Keepalived_vrrp[18581]:
VRRP_Instance(VI_1) Transition to MASTER STATE

Jan 10 12:12:47 localhost Keepalived_vrrp[18581]:
VRRP_Instance(VI_1) Received higher prio advert

Jan 10 12:12:47 localhost Keepalived_vrrp[18581]:
VRRP_Instance(VI_1) Entering BACKUP STATE

Jan 10 12:16:27 localhost Keepalived_vrrp[18581]:
VRRP_Instance(VI_1) Transition to MASTER STATE

Jan 10 12:16:28 localhost Keepalived_vrrp[18581]:
VRRP_Instance(VI_1) Entering MASTER STATE

Jan 10 12:16:28 localhost Keepalived_vrrp[18581]:
VRRP_Instance(VI_1) setting protocol VIPs.

Jan 10 12:16:28 localhost Keepalived_healthcheckers[18580]: Netlink
reflector reports IP 192.168.30.230 added

Jan 10 12:16:28 localhost Keepalived_vrrp[18581]:
VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.30.230

Jan 10 12:16:33 localhost Keepalived_vrrp[18581]:
VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.30.230

Jan 10 12:18:20 localhost Keepalived_vrrp[18581]:
VRRP_Instance(VI_1) Received higher prio advert

Jan 10 12:18:20 localhost Keepalived_vrrp[18581]:
VRRP_Instance(VI_1) Entering BACKUP STATE

Jan 10 12:18:20 localhost Keepalived_vrrp[18581]:
VRRP_Instance(VI_1) removing protocol VIPs.

Jan 10 12:18:20 localhost Keepalived_healthcheckers[18580]: Netlink
reflector reports IP 192.168.30.230 removed

[root@master ~]# ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state
UNKNOWN

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host

      valid_lft forever preferred_lft forever

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc
pfifo_fast state UP qlen 1000

    link/ether 00:0c:29:f3:fc:ba brd ff:ff:ff:ff:ff:ff

    inet 192.168.30.116/24 brd 192.168.30.255 scope global eth0

    inet 192.168.30.230/32 scope global eth0

    inet6 fe80::20c:29ff:fef3:fcba/64 scope link

      valid_lft forever preferred_lft forever

开采IP已经再次改变来master服务器

现行反革命编写haproxy状态检查实验脚本,来促成haproxy的正规检验:

[root@master ~]# cat haproxy_pid.sh

#!/bin/bash

while :

do

haproxypid=`ps -C haproxy –no-header | wc -l`

if [ $haproxypid -eq 0 ];then

  service haproxy start

  sleep 5

  haproxypid=`ps -C haproxy –no-header | wc -l`

  echo $haproxypid

    if [ $haproxypid -eq 0 ];then

  /etc/init.d/keepalived stop

    fi

fi

sleep 5

done

# 启动backup的haproxy

[root@backup ~]# service haproxy start

Starting haproxy:                                          [  OK  ]

如法泡制故障,先让httpd进度开启,更正haproxy监听端口为80,使得haproxy进度不能够运转,看财富会不会改换成backup服务器

[root@master ~]# vi /etc/haproxy/haproxy.cfg

frontend  main *:5000 改为frontend  main *:80

# 启动httpd进程

[root@master ~]# scp -pr /etc/haproxy/haproxy.cfg

[root@master ~]# service httpd start

Starting httpd: httpd: apr_sockaddr_info_get() failed for
master.luojianlong.com

httpd: Could not reliably determine the server’s fully qualified domain
name, using 127.0.0.1 for ServerName

                                                          [  OK  ]

[root@master ~]# netstat -antpl | grep :80

tcp        0      0 :::80                      :::*                   
    LISTEN      19965/httpd

#运转处境检查测验脚本

[root@master ~]# nohup /root/haproxy_pid.sh &

[root@master ~]# scp -pr haproxy_pid.sh

[root@bakcup ~]# nohup /root/haproxy_pid.sh &

[root@master ~]# tail -f /var/log/messages

Jan 10 12:02:29 localhost Keepalived_vrrp[19849]: VRRP sockpool:
[ifindex(2), proto(112), fd(10,11)]

Jan 10 12:02:29 localhost Keepalived_vrrp[19849]:
VRRP_Instance(VI_1) Transition to MASTER STATE

Jan 10 12:02:30 localhost Keepalived_vrrp[19849]:
VRRP_Instance(VI_1) Entering MASTER STATE

Jan 10 12:02:30 localhost Keepalived_vrrp[19849]:
VRRP_Instance(VI_1) setting protocol VIPs.

Jan 10 12:02:30 localhost Keepalived_vrrp[19849]:
VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.30.230

Jan 10 12:02:30 localhost Keepalived_healthcheckers[19848]: Netlink
reflector reports IP 192.168.30.230 added

Jan 10 12:02:35 localhost Keepalived_vrrp[19849]:
VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.30.230

Jan 10 12:14:49 localhost Keepalived[19847]: Stopping Keepalived
v1.2.7 (02/21,2013)

Jan 10 12:14:49 localhost Keepalived_vrrp[19849]:
VRRP_Instance(VI_1) sending 0 priority

Jan 10 12:14:49 localhost Keepalived_vrrp[19849]:
VRRP_Instance(VI_1) removing protocol VIPs.

[root@master ~]# ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state
UNKNOWN

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host

      valid_lft forever preferred_lft forever

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc
pfifo_fast state UP qlen 1000

    link/ether 00:0c:29:f3:fc:ba brd ff:ff:ff:ff:ff:ff

    inet 192.168.30.116/24 brd 192.168.30.255 scope global eth0

    inet6 fe80::20c:29ff:fef3:fcba/64 scope link

      valid_lft forever preferred_lft forever

[root@backup ~]# ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state
UNKNOWN

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host

      valid_lft forever preferred_lft forever

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc
pfifo_fast state UP qlen 1000

    link/ether 00:0c:29:5b:50:f9 brd ff:ff:ff:ff:ff:ff

    inet 192.168.30.117/24 brd 192.168.30.255 scope global eth0

    inet 192.168.30.230/32 scope global eth0

    inet6 fe80::20c:29ff:fe5b:50f9/64 scope link

      valid_lft forever preferred_lft forever

[root@backup ~]# ps aux | grep haproxy

haproxy  19054  0.0  0.0  18688  1280 ?        Ss  12:47  0:00
/usr/sbin/haproxy -D -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid

root    19097  0.0  0.0 103248  828 pts/0    S+  12:58  0:00 grep
haproxy

发觉IP已经转移到backup服务器,达成了keepalived对于haproxy故障的高可用。

keepalived家常便饭的起步报错:

5913 May 16 15:26:04 localhost Keepalived_vrrp: ip address associated
with VRID not present in received packet : 192.168.57.75

5914 May 16 15:26:04 localhost Keepalived_vrrp: one or more VIP
associated with VRID mismatch actual MASTER advert

5915 May 16 15:26:04 localhost Keepalived_vrrp: bogus VRRP packet
received on eth0 !!!

5916 May 16 15:26:04 localhost Keepalived_vrrp: VRRP_Instance(VI_1)
ignoring received advertisment…

5917 May 16 15:26:05 localhost Keepalived_vrrp: ip address associated
with VRID not present in received packet : 192.168.57.75

5918 May 16 15:26:05 localhost Keepalived_vrrp: one or more VIP
associated with VRID mismatch actual MASTER advert

5919 May 16 15:26:05 localhost Keepalived_vrrp: bogus VRRP packet
received on eth0 !!!

5920 May 16 15:26:05 localhost Keepalived_vrrp: VRRP_Instance(VI_1)
ignoring received advertisment.

减轻形式:

在同一网段内virtual_router_id
值不可能同意气风发,假若相符会在messages中抽取VRRP错误包 ,所以要求转移
virual_router_id。

HAproxy
的亲力亲为介绍
:请点这里
HAproxy
的下载地址
:请点这里

引入阅读:

Haproxy+Keepalived搭建Weblogic高可用负载均衡集群
http://www.linuxidc.com/Linux/2013-09/89732.htm

Keepalived+HAProxy配置高可用负载均衡
http://www.linuxidc.com/Linux/2012-03/56748.htm

CentOS 6.3下Haproxy+Keepalived+Apache配置笔记
http://www.linuxidc.com/Linux/2013-06/85598.htm

Haproxy + KeepAlived 实现WEB群集 on CentOS 6
http://www.linuxidc.com/Linux/2012-03/55672.htm

Haproxy+Keepalived创设高可用负载均衡
http://www.linuxidc.com/Linux/2012-03/55880.htm

亚洲必赢官网 3

网站地图xml地图