热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

nsitionalENhttp:www.w3.orgTRxhtml1DTDxhtml1-transitional.dtd

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: 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启动成功,配置生效


  • 推荐阅读
    author-avatar
    小丽丽很可爱
    这个家伙很懒,什么也没留下!
    PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
    Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有