`

keepalived 实现热备

阅读更多
基本环境
MASTER机,10.0.0.9
BACKUP机,10.0.0.10

1,安装
wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gz
tar xvzf keepalived-1.2.7.tar.gz
cd keepalived-1.2.7
./configure
make
make install



2,配置(低版本貌似才需要这个配置)
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/sbin/keepalived /usr/sbin/
vi /etc/keepalived/keepalived.conf




3,MASTER配置keepalived.conf,避免立即将vip还回去配置双BACKUP

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 11
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.0.100
        10.0.0.101 
    }   
}

vrrp_instance VI_2 {
    state BACKUP
    interface eth1
    virtual_router_id 21
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.0.100
        192.168.0.101
    }
}





4,BACKUP配置keepalived.conf

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 11
    priority 10
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.0.100
        10.0.0.101 
    }   
}

vrrp_instance VI_2 {
    state BACKUP
    interface eth1
    virtual_router_id 21
    priority 10
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.0.100
        192.168.0.101
    }
}




5,启动
[root@davidserver keepalived]# keepalived



由于/etc/rc.d/init.d/keepalived start报错,故采用如此启动

6,MASTER机验证网络信息
[root@davidserver keepalived]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:50:56:20:3d:2a brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.9/24 brd 10.0.0.255 scope global eth0
    inet 10.0.0.100/32 scope global eth0
    inet 10.0.0.101/32 scope global eth0
    inet6 fe80::250:56ff:fe20:3d2a/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:50:56:34:80:48 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.9/16 brd 192.168.0.255 scope global eth1
    inet 192.168.0.100/32 scope global eth1
    inet 192.168.0.101/32 scope global eth1
    inet6 fe80::250:56ff:fe34:8048/64 scope link 
       valid_lft forever preferred_lft forever



7,停MASTER机keepalived服务,验证BACKUP机网络
[root@davidserver keepalived]# /etc/rc.d/init.d/keepalived stop
Stopping keepalived:                                       [  OK  ]



[root@davidserver keepalived]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:50:56:2e:2b:6d brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.10/24 brd 10.0.0.255 scope global eth0
    inet 10.0.0.100/32 scope global eth0
    inet 10.0.0.101/32 scope global eth0
    inet6 fe80::250:56ff:fe2e:2b6d/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:50:56:3b:e8:e2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.10/16 brd 192.168.0.255 scope global eth1
    inet 192.168.0.100/32 scope global eth1
    inet 192.168.0.101/32 scope global eth1
    inet6 fe80::250:56ff:fe3b:e8e2/64 scope link 
       valid_lft forever preferred_lft forever



8,更新后的配置
[root@davidserver ~]# cat /etc/keepalived/keepalived.conf 

global_defs {
    notification_email {
        jie.zhang@ttpod.com
    }
    notification_email_from keepalived@ttpod.com
    smtp_server 127.0.0.1
    stmp_connect_timeout 30
    router_id keepalived_for_backup
}

vrrp_script check_top {
    script "/root/bin/check_top"
    interval 10
    weight 10
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 11
    priority 10
    advert_int 1
    nopreempt
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.0.100/24 dev eth0 label eth0:0
        10.0.0.101/24 dev eth0 label eth0:1
    }   
    track_script {
        check_top weight 20
    }
}

vrrp_instance VI_2 {
    state BACKUP
    interface eth1
    virtual_router_id 21
    priority 10
    advert_int 1
    nopreempt
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.0.100/16 dev eth1 label eth1:0
        192.168.0.101/16 dev eth1 label eth1:1
    }
    track_script {
        check_top 
    }
}




9,查看网络信息
ip a
[root@davidserver ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:50:56:20:3d:2a brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.9/24 brd 10.0.0.255 scope global eth0
    inet 10.0.0.100/24 scope global eth0:0
    inet 10.0.0.101/24 scope global eth0:1
    inet6 fe80::250:56ff:fe20:3d2a/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:50:56:34:80:48 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.9/16 brd 192.168.0.255 scope global eth1
    inet 192.168.0.100/16 scope global eth1:0
    inet 192.168.0.101/16 scope global eth1:1
    inet6 fe80::250:56ff:fe34:8048/64 scope link 
       valid_lft forever preferred_lft forever



ifconfig
[root@davidserver ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:50:56:20:3D:2A  
          inet addr:10.0.0.9  Bcast:10.0.0.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:fe20:3d2a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1206 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1282 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:125352 (122.4 KiB)  TX bytes:148912 (145.4 KiB)

eth0:0    Link encap:Ethernet  HWaddr 00:50:56:20:3D:2A  
          inet addr:10.0.0.100  Bcast:0.0.0.0  Mask:255.255.255.255
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:1    Link encap:Ethernet  HWaddr 00:50:56:20:3D:2A  
          inet addr:10.0.0.101  Bcast:0.0.0.0  Mask:255.255.255.255
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth1      Link encap:Ethernet  HWaddr 00:50:56:34:80:48  
          inet addr:192.168.0.9  Bcast:192.168.0.255  Mask:255.255.0.0
          inet6 addr: fe80::250:56ff:fe34:8048/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:349754 errors:0 dropped:0 overruns:0 frame:0
          TX packets:476 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:21502934 (20.5 MiB)  TX bytes:32269 (31.5 KiB)

eth1:0    Link encap:Ethernet  HWaddr 00:50:56:34:80:48  
          inet addr:192.168.0.100  Bcast:0.0.0.0  Mask:255.255.255.255
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth1:1    Link encap:Ethernet  HWaddr 00:50:56:34:80:48  
          inet addr:192.168.0.101  Bcast:0.0.0.0  Mask:255.255.255.255
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

分享到:
评论

相关推荐

    Nginx+keepalived双机热备(主从模式)

    Nginx+keepalived双机热备(主从模式)是一种常见的负载均衡技术,用于实现高可用环境和故障转移。该技术通过将Nginx与keepalived结合,实现了前端负载均衡和高可用性。 Nginx是一款流行的开源Web服务器软件,具有...

    MYSQL+KEEPALIVED 双机热备方案.docx

    本文将详细介绍 MYSQL+KEEPALIVED 双机热备方案的实现细节。 MYSQL 主主复制配置 MYSQL 主主复制是 MYSQL+KEEPALIVED 双机热备方案的核心组件。通过配置 MYSQL 主主复制,可以实现两个 MYSQL 节点的实时数据同步,...

    构建Keepalived双机热备.pdf

    其中,使用双机热备方案是实现高可用性的一种有效方法,而Keepalived是实现双机热备的常用工具之一。本文档介绍了如何构建Keepalived双机热备架构,以便在网络中部署高可用的负载均衡服务。 ### Keepalived双机热备...

    lvs+keepalived双机热备.zip

    LVS+Keepalived双机热备的实现步骤大致如下: 1. **配置LVS**:首先,在两台服务器上分别安装LVS,设置相应的负载均衡策略,例如轮询、权重分配等。然后,配置虚拟IP地址,这将是对外提供服务的统一入口。 2. **...

    keepalived + redis 实现双机热备

    标题 "keepalived + redis 实现双机热备" 涉及到的是在IT行业中构建高可用性系统的关键技术。keepalived 和 redis 是两个关键组件,它们一起工作以确保服务的持续运行,即使在主服务器故障时也能无缝切换到备份...

    linux基于keepalived的mysql双机热备实现方案(详细过程完整版)

    【标题】:Linux环境下基于Keepalived的MySQL双机热备实现详解 【描述】:在企业级系统中,数据库往往是性能瓶颈的关键所在。MySQL主从架构虽然能缓解这一问题,但在面临单一主库故障时,系统仍存在风险。本文将...

    Nginx+keepalived双机热备(主从模式)高可用集群方案-完整部署记录(个人珍藏版)

    本片详细记录了Nginx+keepalived双机热备(主从模式)高可用集群方案-完整部署过程,讲解十分到位,可作为线上实操手册。特在此分享,希望能帮助到有用到的朋友。

    nginx+keepalived实现双机热备高可用

    nginx+keepalived实现双机热备高可用 本文详细介绍了使用nginx和keepalived实现双机热备高可用的技术解决方案。该解决方案旨在解决nginx集群部署时的单点故障问题。通过keepalived软件,实现对nginx服务器的高可用...

    keepalived双击热备 检测mysql服务是否正常,本地亲测,很实用。

    "keepalived双击热备 检测mysql服务是否正常"的标题揭示了一个关键的解决方案,即利用Keepalived实现对MySQL服务的健康检查和高可用性设置。Keepalived是一款开源的网络和服务监控软件,它能够为Linux环境下的服务...

    suse12 redis-sensienl-keepalived双击热备部署

    "suse12 redis-sensienl-keepalived双击热备部署"是一个针对SUSE Linux Enterprise Server 12 (SLES12) 上的Redis数据库进行高可用配置的实践案例。在这个部署方案中,Redis被配置为双主模式(也称为双活或双击),...

    Nginx负载均衡+keepalived双机热备

    通过上述步骤,我们可以成功地实现一个基于Nginx的负载均衡系统,并利用Keepalived来实现双机热备,确保了系统的高可用性和稳定性。这种架构不仅能够有效分发流量至多个Web服务器,还能在一台服务器出现故障时自动...

    RedHat5.9通过Keepalived双机热备Nginx

    ### RedHat 5.9 通过 Keepalived 实现 Nginx 双机热备部署详解 #### 一、背景介绍 随着业务需求的增长和技术的发展,服务器单点故障的风险日益凸显,因此高可用(High Availability,简称HA)架构设计成为了企业IT...

    mysql主主搭建+keepalived实现双击热备.docx

    MySQL主主搭建与Keepalived实现双机热备是构建高可用数据库系统的关键技术,它确保了即使在一台服务器故障时,数据服务也能不间断运行。以下是对这一主题的详细解释: 1. **MySQL主主复制**: 主主复制是一种...

    Nginx+Keepalived实现双机热备

    一.Keepalived Keepalived是保证集群高可用的服务软件,网络中优先级高的节点为master负责响应VIP的ARP包,将VIP和MAC地址映射关系告诉网络内其他主机,还会以多播的形式向网络中发送VRRP通告,告知自己的优先级。...

Global site tag (gtag.js) - Google Analytics