1. wget http://www.keepalived.org/software/keepalived-1.2.1.tar.gz

  2. tar zxf keepalived-1.2.1.tar.gz cd keepalived-1.2.1

  3. ./configure--with-kernel-dir=/usr/src/kernels/2.6.18-164.el5-i686 &&make&& make install 

    内核需要查看,,,如果是32位的自行修改

  4. keepalived 解决configure: error: Popt libraries is required  需要安

    yum install popt-devel

  5. 修改keepalived为系统服务:


  6. DIR=/usr/local/ ;cp $DIR/etc/rc.d/init.d/keepalived  /etc/rc.d/init.d/

  7. cp $DIR/etc/sysconfig/keepalived/etc/sysconfig/ && mkdir -p /etc/keepalived

  8. cp $DIR/sbin/keepalived /usr/sbin/

  9. 修改配置文件/etc/keepalived/keepalived.conf为一下内容:服务端配置

  10. ! Configuration File for keepalived
    global_defs {
       notification_email {
    woshitieren@gmail.com
       }
       notification_email_from wgkgood@139.com
       smtp_server 127.0.0.1
       smtp_connect_timeout 30
       router_id LVS_DEVEL
    }
    # VIP1
    vrrp_instance VI_1 {
        state MASTER
        interface eth0
        lvs_sync_daemon_inteface eth0
        virtual_router_id 151
        priority 100
        advert_int 5
       #nopreempt   
        authentication {
            auth_type PASS
            auth_pass 2222
        }
        virtual_ipaddress {
            192.168.77.144
        }
    }
    virtual_server 192.168.77.144 3306 {
        delay_loop 6
        lb_algo wrr

     lb_kind DR
        persistence_timeout 60
        protocol TCP
        real_server 192.168.77.133 3306 {
            weight 100
            notify_down /data/sh/mysql.sh
            TCP_CHECK {
            connect_timeout 10
            nb_get_retry 3
            delay_before_retry 3
            connect_port 3306
            }
        }
    }

  11. 查看日志tail -fn 100 /var/log/message 日志一直在滚动没有加载ip_vs模块

  12. modprobe ip_vs     然后lsmod | grep ip_vs查看模块

  13. 同样客户端也需要安装keepalived安装同样配置文件改一下上面几个地方MASTER要改成BACKUP,mysql.sh脚本里面写上/etc/init.d/keepalived stop即可

  14. 然后在测试,因为之前mysql主从已经安装好这里不再安装,,直接测试

  15. 首先授权漂移的ip地址或者在论坛配置文件下更改也可以,,测试停掉主服务器mysql用主服务器ip还可以正常访问论坛即可