部署前准备:

iptables和selinux没配置,关掉

挂载系统镜像作为本地yum源,修改yum文件

源码包准备keepalived-1.2.13.tar.gz


环境介绍:

主服务器ip:192.168.100.157(keeplived+lvs)

从服务器ip:192.168.100.156(keeplived+lvs)

节点服务器ip:192.168.100.153-192.168.100.155(httpd)

集群vip:192.168.100.95


1.安装keepalived(在两台调度服务器上安装,192.168.100.157,192.168.100.156)

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

tar zxvf keepalived-1.2.13.tar.gz -C /usr/src/

cd /usr/src/keepalived-1.2.13/

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

make &&make install

cd

[root@localhost ~]# ls /etc/keepalived/

keepalived.conf  samples


chkconfig --add keepalived

chkconfig keepalived on


2.配置调度器(主:192.168.100.157,备:192.168.100.156,漂移ip:192.168.100.95)web服务器池(节点1:192.168.100.153、节点2:192.168.100.154、节点3:192.168.100.155)

1)、配置主HA调度服务器

cd /etc/keepalived/

mv keepalived.conf keepalived.conf.bak

vi /etc/keepalived/keepalived.conf

global_defs {

    router_id HA_TEST_R1 ##本服务器的名称

}

vrrp_instance VI_1 { ##定义VRRP热备实例

    state MASTER ##MASTER表示主服务器

    interface eth0 ##承载VIP地址的物理接口

    virtual_router_id 1 ##虚拟路由器的ID号

    priority 100 ##优先级,数值越大优先级越高

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

    authentication { ##认证信息

        auth_type PASS ##认证类型

        auth_pass 123456 ##密码字串

    }

    virtual_ipaddress {

  192.168.100.95 ##指定漂移地址(VIP)

    }

virtual_server 192.168.100.95 80 {

        delay_loop 15

        lb_algo rr

        lb_kind DR

        protocol TCP

real_server 192.168.100.153 80 {

        weight 1

        TCP_CHECK {

                connect_port 80

                connect_timeout 3

                nb_get_retry 3

                delay_before_retry 4

                }

        }

real_server 192.168.100.154 80 {

        weight 1

        TCP_CHECK {

                connect_port 80

                connect_timeout 3

                nb_get_retry 3

                delay_before_retry 4

                }

        }

real_server 192.168.100.155 80 {

        weight 1

        TCP_CHECK {

                connect_port 80

                connect_timeout 3

                nb_get_retry 3

                delay_before_retry 4

                }

        }

}

:wq

modprobe ip_vs

lsmod |grep ip_vs

echo "modprobe ip_vs" >>/etc/rc.local

/etc/init.d/keepalived restart

chkconfig ipvsadm off

ip addr show dev eth0


2)、配置HA从调度服务器

cd /etc/keepalived/

mv keepalived.conf keepalived.conf.bak

vi /etc/keepalived/keepalived.conf

global_defs {

    router_id HA_TEST_R2 ##本服务器的名称

}

vrrp_instance VI_1 { ##定义VRRP热备实例

    state BACKUP ##BACKUP表示主服务器

    interface eth0 ##承载VIP地址的物理接口

    virtual_router_id 1 ##虚拟路由器的ID号

    priority 99 ##优先级,数值越大优先级越高

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

    authentication { ##认证信息

        auth_type PASS ##认证类型

        auth_pass 123456 ##密码字串

    }

    virtual_ipaddress {

  192.168.100.95 ##指定漂移地址(VIP)

    }

virtual_server 192.168.100.95 80 {

        delay_loop 15

        lb_algo rr

        lb_kind DR

        protocol TCP

real_server 192.168.100.153 80 {

        weight 1

        TCP_CHECK {

                connect_port 80

                connect_timeout 3

                nb_get_retry 3

                delay_before_retry 4

                }

        }

real_server 192.168.100.154 80 {

        weight 1

        TCP_CHECK {

                connect_port 80

                connect_timeout 3

                nb_get_retry 3

                delay_before_retry 4

                }

        }

real_server 192.168.100.155 80 {

        weight 1

        TCP_CHECK {

                connect_port 80

                connect_timeout 3

                nb_get_retry 3

                delay_before_retry 4

                }

        }

}

:wq


modprobe ip_vs

lsmod |grep ip_vs

echo "modprobe ip_vs" >>/etc/rc.local

/etc/init.d/keepalived restart

chkconfig ipvsadm off

ip addr show dev eth0


3.配置Web节点服务器(DR工作模式的配置,分别在节点服务器上做如下设置)

cd /etc/sysconfig/network-script/

cp ifcfg-lo ifcfg-lo:0

vi ifcfg-lo:0

DEVICE=lo:0

IPADDR=192.168.100.95

NETMASK=255.255.255.255

ONBOOT=yes

:wq

/etc/init.d/network restart

echo "route add -host 192.168.100.95 dev lo:0" >>/etc/rc.local

route add -host 192.168.100.95 dev lo:0

ip addr show dev lo


vi /etc/sysctl.conf

net.ipv4.conf.all.arp_ignore = 1

net.ipv4.conf.all.arp_announce = 2

net.ipv4.conf.default.arp_ignore = 1

net.ipv4.conf.default.arp_announce = 2

net.ipv4.conf.lo.arp_ignore = 1

net.ipv4.conf.lo.arp_announce = 2

:wq

sysctl -p

yum -y install httpd

vi /var/www/html/index.html

test page 192.168.100.153!!!!

:wq

/etc/init.d/httpd start

chkconfig httpd on


4.测试lvs+Keepalived高可用集群

在客户机浏览器访问192.168.100.95,调度服务器可用坏一个,节点服务器至少要有一个是好的。

通过/var/log/message日志文件,跟踪故障切换过程。使用ipvsadm -Ln查看LVS。