你好,游客 登录 注册 搜索
背景:
阅读新闻

HAProxy+Keepalived构建高可用负载均衡

[日期:2012-03-04] 来源:Linux社区  作者:gaoming655 [字体: ]

web1 IP 192.168.0.47

web2 IP 192.168.0.48

haproxy_master 192.168.0.200

haproxy_backup 192.168.0.199

VIP 192.168.0.155




一.安装keepalived 

  • #wget http://www.keepalived.org/software/keepalived-1.1.15.tar.gz
  • #tar zxvf keepalived-1.1.15.tar.gz
  • #cd keepalived-1.1.15
  • #./configure
  • #make
  • #make install 将keepalived做成启动脚务

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

    #cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/

    #mkdir /etc/keepalived

    #cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/

    #cp /usr/local/sbin/keepalived /usr/sbin/

    配置keepalived.conf

    #vim /etc/keepalived/keepalived.conf

    1. ! Configuration File for keepalived  
    2.   
    3. global_defs {  
    4.    notification_email {  
    5.      gaoming@123.com  
    6.    }  
    7.    notification_email_from gaoming@123.com  
    8.    smtp_server 192.168.200.1  
    9.    smtp_connect_timeout 30  
    10.    router_id LVS_DEVEL  
    11. }  
    12.   
    13. vrrp_instance VI_1 {  
    14.     state MASTER    #备用服务器上改为 BACKUP  
    15.     interface eth0  
    16.     virtual_router_id 51  
    17.     priority 100    #备用服务器上改为99  
    18.     advert_int 1  
    19.     authentication {  
    20.         auth_type PASS  
    21.         auth_pass 1111  
    22.     }  
    23.     virtual_ipaddress {  
    24.         192.168.0.155/24 dev eth0 scope global  
    25.     }  
    26. }  
    启动keepalived

    service keepalived start

    启动之后可以用ip add 查看网卡多了一条192.168.0.155的IP

    eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
        link/ether 00:0c:29:ff:6c:c7 brd ff:ff:ff:ff:ff:ff
        inet 192.168.0.200/24 brd 192.168.0.255 scope global eth0
        inet 192.168.0.155/24 scope global secondary eth0
        inet6 fe80::20c:29ff:feff:6cc7/64 scope link
           valid_lft forever preferred_lft forever

    说明keepalived启动成功,配置生效

  • linux
    本文评论   查看全部评论 (0)
    表情: 表情 姓名: 字数

           

    评论声明
    • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
    • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
    • 本站管理人员有权保留或删除其管辖留言中的任意内容
    • 本站有权在网站内转载或引用您的评论
    • 参与本评论即表明您已经阅读并接受上述条款