Keepalived高可用群集

Keepalived采用VRRP热备份协议,以软件的方式实现linux服务器的多机热备功能,当一方故障时,自动切换备份服务器进行工作。

Keepalived部署环境:一台主调度服务器,一台从调度服务器,多台节点服务器

Keepalived部署步骤:

安装支持组件

#yum -y install kernel-devel openssl-devel popt-devel  ipvsadm

源码安装keepalived工具

#tar xzvf keepalived-1.2.13.tar.gz

#cd keepalived-1.2.13

#./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-431.e16.x86_64

#make && make install

配置主调度器

#vim /etc/keepalived/keepalived.conf

修改相关内容:

global_defs {

   router_id R1                 主调度器的名称

}

vrrp_instance VI_1 {

    state MASTER               主调度器的热备状态

    interface eth0               主调度器的下接口

    virtual_router_id 1           组号

    priority 100                 优先级

    advert_int 1                 

    authentication {             主从热备认证信息

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {          群集虚拟IP地址

        1.1.1.100

 

}

virtual_server 1.1.1.100 80 {       虚拟服务地址端口

    delay_loop 6               健康检查的间隔时间

    lb_algo rr                  轮询的调度算法

    lb_kind DR                 直接路由的群集工作模式

!    persistence_timeout 50      保持时间

    protocol TCP                协议

   real_server 1.1.1.1 80 {        真实服务器地址端口

        weight 1               权重

        TCP_CHECK {           健康检查方式

            connect_port 80    检查目标端口

            connect_timeout 3  连接超时

            nb_get_retry 3      重试次数

            delay_before_retry 3 重试间隔

        }

    }

}

重启keepalived服务

#Service keepalived restart

验证配置文件是否生效

#ip addr 查看是否自动创建了虚拟群集IP

配置从调度器

#vim /etc/keepalived/keepalived.conf

修改内容:

global_defs {

   router_id R2                 从调度器的名称

}

vrrp_instance VI_1 {

    state BACKUP               从调度器的热备状态

    interface eth0               从调度器的下接口

    virtual_router_id 1           组号

    priority 99                  优先级

........其他内容相同

重启keepalived服务

#Service keepalived restart

配置节点服务器

#ifconfig lo:0 1.1.1.100/32

#route add -host 1.1.1.100 dev lo:0

#vim /etc/sysctl.conf

添加内容:

net.ipv4.conf.all.arp_ignore = 1

net.ipv4.conf.all.arp_announce = 2

net.ipv4.conf.lo.arp_ignore = 1

net.ipv4.conf.lo.arp_announce = 2

net.ipv4.conf.default.arp_ignore = 1

net.ipv4.conf.default.arp_announce = 2

#sysctl -p