LVS+Keepalived构建高可用负载均衡群集(DR)(2)

二、Load Balancer2(LVS-Slave)配置(RHEL6)

1) 设置网卡IP地址

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]

DEVICE=eth0

BOOTPROTO=static

HWADDR=00:0C:29:AB:B0:02

ONBOOT=yes

IPADDR=192.168.1.197

NETMASK=255.255.255.0

GATEWAY=192.168.1.1

2)安装支持软件

[root@localhost ~]# mount /dev/cdrom /media/

mount: block device /dev/sr0 is write-protected, mounting read-only

[root@localhost media]# vim /etc/yum.repos.d/rhel-source.repo

[rhel-source]

name=Red Hat Enterprise Linux $releasever - $basearch - Source

baseurl=file:///media/Server

enabled=1

gpgcheck=0

[root@localhost media]# yum -y install kernel-devel openssl-devel popt-devel ipvsadm

3) 安装keepalived所需软件

[root@localhost ~]# tar zxf keepalived-1.2.2.tar.gz

[root@localhost ~]# cd keepalived-1.2.2

[root@localhost keepalived-1.2.2]# ./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.18-194.el5-i686 ;make ;make install //此内核是RHEL6上的,若使用其它RHEL版本则会报错

4)使用keepalived服务

[root@localhost ~]# ls -l /etc/init.d/keepalived

-rwxr-xr-x. 1 root root 1288 5月 10 14:27 /etc/init.d/keepalived

[root@localhost ~]# chkconfig --add keepalived

[root@localhost ~]# chkconfig keepalived

5)配置/etc/keepalived/keepalived.conf主配置文档,LVS-Master上的配置文件拷过来修改如下三个参数即可

[root@localhost keepalived]# scp keepalived.conf root@192.168.1.197:/etc/keepalived/此步骤在LVS-Master上做,向197辅助服务器拷贝 //

[root@localhost ~]# cd /etc/keepalived/  //回到LVS-Slave上编辑

[root@localhost keepalived]# cp keepalived.conf keepalived.conf.bak

[root@localhost keepalived]# vi keepalived.conf

global_defs {

   router_id LVS_DEVEL_2 //本路由器(服务器)的名称

}

vrrp_instance VI_1 {      //定义vrrp热备实例

    state SLAVE       //热本状态,MASTER表示主服务器

    interface eth0       //承载vip的物理端口

    virtual_router_id 51   //虚拟路由器的ID号,每个热备组保持一致

    priority 100          //优先级,数值越大优先级越高,这里应该主服务器高于辅助的

    advert_int 1         //通告间隔秒数(心跳频率)

    authentication {      //认证信息,每个热备组保持一致

        auth_type PASS   //认证类型

        auth_pass 1111   //认证密码

    }

    virtual_ipaddress {     //指定漂移地址(vip),可以有多个

        192.168.1.198

    }

}

virtual_server 192.168.1.198 80 {    //虚拟服务器地址(vip)、端口

    delay_loop 6                 //健康检查间隔时间

    lb_algo rr                     //轮询(rr)调度算法

    lb_kind DR                   //直接路由模式(DR)

protocol TCP                  //应用服务采用的模式是TCP模式

 

    real_server 192.168.1.191 80 {     //第一个Web节点的地址、端口

        weight 1                    //节点的权重

        TCP-CHECK {                 //健康检查方式

            connect_timeout 3        //连接超时(秒)

            nb_get_retry 3            //重试次数

            delay_before_retry 3       //重试间隔(秒)

            connect_port 80          //检查的目标端口

    }

}

    real_server 192.168.1.192 80 {       //第二个Web节点

        weight 1

        TCP-CHECK {

            connect_timeout 3

            nb_get_retry 3

            delay_before_retry 3

            connect_port 80

    }

}

}

6)重新启动keepalived服务

[root@localhost keepalived]# service keepalived restart

停止 keepalived:                                          [失败]

正在启动 keepalived:                                      [确定]

[root@localhost keepalived]#ip add show dev eth0

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/ace5fe73e11633be09054fddf780c30f.html