这个问题纠结了很久,现已解决,问题记录在:http://pmghong.blog.51cto.com/3221425/1201533


   最近在VMware上搭建lvs+keepalive,总是不成功,试了N多次,看了N多视频和资料,也换过不同版本的包,但结果还是那样,想请教高手帮忙看看到底是哪里出问题了。


我总共开启了4台虚拟机(2台Director,2台Real Server),用真机当客户端,下面是我的IP分配

IP分配

192.168.30.105            DR(主)

192.168.30.106            DR(从)

192.168.30.113            RS1

192.168.30.114            RS2

192.168.30.254            VIP


一、安装ipvsadm

# yum install popt popt-devel popt-static openssl-devel kernel-devel libnl libnl-devel

# tar xf ipvsadm-1.26.tar.gz

# cd ipvsadm-1.26

# make && make install

# ipvsadm


二、安装keepalive

# tar xf keepalived-1.2.7.tar.gz

# cd keepalived-1.2.7

# ./configure --prefix=/usr/local/keepalive --with-kernel-dir=/usr/src/kernels/2.6.32-279.el6.x86_64/

# cd /usr/local/keepalive/

# make && make install


# cd /usr/local/keepalive/

# cp etc/rc.d/init.d/keepalived  /etc/rc.d/init.d/

# cp etc/sysconfig/keepalived /etc/sysconfig/

# cp sbin/keepalived /usr/sbin/

# cp etc/keepalived/keepalived.conf etc/keepalived/keepalived.conf.bk

# vim etc/keepalived/keepalived.conf

! Configuration File for keepalived


global_defs {

  notification_email {

    [email protected]

    [email protected]

    [email protected]

  }

  notification_email_from [email protected]

  smtp_server 128.0.0.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.254

   }

}

virtual_server 192.168.30.254 80 {

   delay_loop 6

   lb_algo wlc

   lb_kind DR

   nat_mask 255.255.255.0

   persistence_timeout 50

   protocol TCP


   real_server 192.168.30.113 80 {

       weight 1

       TCP_CHECK {

       connect_timeout 10

       nb_get_retry 3

       connect_port 80

       }

   }

   real_server 192.168.30.114 80 {

       weight 1

       TCP_CHECK {

       connect_timeout 10

       nb_get_retry 3

       connect_port 80

       }

   }

}

配置完成后,启动keepalive

[root@server keepalive]# service keepalived start
Starting keepalived:                                       [  OK  ]


正常来说,到这里之后,查看lvs应该可以看到VIP在本机了,可是我的就是看不到:

[root@server ~]# ip addr show

1: lo: 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: mtu 1500 qdisc pfifo_fast state UP qlen 1000

   link/ether 00:0c:29:5f:bb:08 brd ff:ff:ff:ff:ff:ff

   inet 192.168.30.105/24 brd 192.168.30.255 scope global eth0

   inet6 fe80::20c:29ff:fe5f:bb08/64 scope link

      valid_lft forever preferred_lft forever


从上面输出信息看出VIP并不在本机上


查看日志,似乎也没有报错

[root@server ipvsadm-1.26]# tailf /var/log/messages
Mar  4 00:59:46 server Keepalived_healthcheckers[4525]: Registering Kernel netlink command channel
Mar  4 00:59:46 server Keepalived_vrrp[4526]: Netlink reflector reports IP 192.168.30.105 added
Mar  4 00:59:46 server Keepalived_vrrp[4526]: Netlink reflector reports IP fe80::20c:29ff:fe5f:bb08 added
Mar  4 00:59:46 server Keepalived_vrrp[4526]: Registering Kernel netlink reflector
Mar  4 00:59:46 server Keepalived_vrrp[4526]: Registering Kernel netlink command channel
Mar  4 00:59:46 server Keepalived_vrrp[4526]: Registering gratuitous ARP shared channel
Mar  4 00:59:46 server Keepalived_vrrp[4526]: Configuration is using : 55324 Bytes
Mar  4 00:59:46 server Keepalived_vrrp[4526]: Using LinkWatch kernel netlink reflector...
Mar  4 00:59:46 server Keepalived_healthcheckers[4525]: Configuration is using : 3180 Bytes
Mar  4 00:59:46 server Keepalived_healthcheckers[4525]: Using LinkWatch kernel netlink reflector...


不知道什么原因,求高手指点迷津,万分感谢!