测试keepalived主备模式

目的:观察VIP在主备服务器上的切换过程

一、安装
yum -y install ipvsadm keepalived

二、服务配置
【keepalived  主】
[[email protected] ~]# cat /etc/keepalived/keepalived.conf 
! Configuration File for keepalived

global_defs {
   router_id R201-1
}

vrrp_instance VIP_Mysql {
    state MASTER
    interface em1
    virtual_router_id 150
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.201.100
    }
}
[[email protected] ~]# service keepalived start

【keepalived  备】
[[email protected] ~]# cat /etc/keepalived/keepalived.conf 
! Configuration File for keepalived

global_defs {
   router_id R201-2
}

vrrp_instance VIP_Mysql {
    state BACKUP
    interface em1
    virtual_router_id 150
    priority 50
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.201.100
    }
}
[[email protected] ~]# service keepalived start

三、刚启动时
【keepalived  主】
Mar 31 17:44:23 R201-1 Keepalived[39251]: Starting Keepalived v1.2.13 (10/15,2014)
Mar 31 17:44:23 R201-1 Keepalived[39252]: Starting Healthcheck child process, pid=39253
Mar 31 17:44:23 R201-1 Keepalived[39252]: Starting VRRP child process, pid=39254
Mar 31 17:44:23 R201-1 Keepalived_vrrp[39254]: Netlink reflector reports IP 10.0.201.1 added
Mar 31 17:44:23 R201-1 Keepalived_vrrp[39254]: Netlink reflector reports IP fe80::569f:35ff:fe0f:e098 added
Mar 31 17:44:23 R201-1 Keepalived_vrrp[39254]: Registering Kernel netlink reflector
Mar 31 17:44:23 R201-1 Keepalived_vrrp[39254]: Registering Kernel netlink command channel
Mar 31 17:44:23 R201-1 Keepalived_vrrp[39254]: Registering gratuitous ARP shared channel
Mar 31 17:44:23 R201-1 Keepalived_healthcheckers[39253]: Netlink reflector reports IP 10.0.201.1 added
Mar 31 17:44:23 R201-1 Keepalived_healthcheckers[39253]: Netlink reflector reports IP fe80::569f:35ff:fe0f:e098 added
Mar 31 17:44:23 R201-1 Keepalived_healthcheckers[39253]: Registering Kernel netlink reflector
Mar 31 17:44:23 R201-1 Keepalived_healthcheckers[39253]: Registering Kernel netlink command channel
Mar 31 17:44:23 R201-1 Keepalived_vrrp[39254]: Opening file ‘/etc/keepalived/keepalived.conf‘.
Mar 31 17:44:23 R201-1 Keepalived_vrrp[39254]: Configuration is using : 61953 Bytes
Mar 31 17:44:23 R201-1 Keepalived_vrrp[39254]: Using LinkWatch kernel netlink reflector...
Mar 31 17:44:23 R201-1 Keepalived_vrrp[39254]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
Mar 31 17:44:23 R201-1 Keepalived_healthcheckers[39253]: Opening file ‘/etc/keepalived/keepalived.conf‘.
Mar 31 17:44:23 R201-1 Keepalived_healthcheckers[39253]: Configuration is using : 6491 Bytes
Mar 31 17:44:23 R201-1 Keepalived_healthcheckers[39253]: Using LinkWatch kernel netlink reflector...
Mar 31 17:44:24 R201-1 Keepalived_vrrp[39254]: VRRP_Instance(VIP_Mysql) Transition to MASTER STATE
Mar 31 17:44:25 R201-1 Keepalived_vrrp[39254]: VRRP_Instance(VIP_Mysql) Entering MASTER STATE
Mar 31 17:44:25 R201-1 Keepalived_vrrp[39254]: VRRP_Instance(VIP_Mysql) setting protocol VIPs.
Mar 31 17:44:25 R201-1 Keepalived_vrrp[39254]: VRRP_Instance(VIP_Mysql) Sending gratuitous ARPs on em1 for 10.0.201.100
Mar 31 17:44:25 R201-1 Keepalived_healthcheckers[39253]: Netlink reflector reports IP 10.0.201.100 added
Mar 31 17:44:30 R201-1 Keepalived_vrrp[39254]: VRRP_Instance(VIP_Mysql) Sending gratuitous ARPs on em1 for 10.0.201.100

[[email protected] ~]# ip a s dev em1
2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 54:9f:35:0f:e0:98 brd ff:ff:ff:ff:ff:ff
    inet 10.0.201.1/8 brd 10.255.255.255 scope global em1
    inet 10.0.201.100/32 scope global em1
    inet6 fe80::569f:35ff:fe0f:e098/64 scope link 
       valid_lft forever preferred_lft forever

【keepalived  备】
Mar 31 17:44:56 201-2 Keepalived[39000]: Starting Keepalived v1.2.13 (10/15,2014)
Mar 31 17:44:56 201-2 Keepalived[39001]: Starting Healthcheck child process, pid=39002
Mar 31 17:44:56 201-2 Keepalived[39001]: Starting VRRP child process, pid=39003
Mar 31 17:44:56 201-2 Keepalived_vrrp[39003]: Netlink reflector reports IP 10.0.201.2 added
Mar 31 17:44:56 201-2 Keepalived_vrrp[39003]: Netlink reflector reports IP fe80::46a8:42ff:fe0b:f805 added
Mar 31 17:44:56 201-2 Keepalived_vrrp[39003]: Registering Kernel netlink reflector
Mar 31 17:44:56 201-2 Keepalived_vrrp[39003]: Registering Kernel netlink command channel
Mar 31 17:44:56 201-2 Keepalived_vrrp[39003]: Registering gratuitous ARP shared channel
Mar 31 17:44:56 201-2 Keepalived_healthcheckers[39002]: Netlink reflector reports IP 10.0.201.2 added
Mar 31 17:44:56 201-2 Keepalived_healthcheckers[39002]: Netlink reflector reports IP fe80::46a8:42ff:fe0b:f805 added
Mar 31 17:44:56 201-2 Keepalived_healthcheckers[39002]: Registering Kernel netlink reflector
Mar 31 17:44:56 201-2 Keepalived_healthcheckers[39002]: Registering Kernel netlink command channel
Mar 31 17:44:56 201-2 Keepalived_vrrp[39003]: Opening file ‘/etc/keepalived/keepalived.conf‘.
Mar 31 17:44:56 201-2 Keepalived_vrrp[39003]: Configuration is using : 61951 Bytes
Mar 31 17:44:56 201-2 Keepalived_vrrp[39003]: Using LinkWatch kernel netlink reflector...
Mar 31 17:44:56 201-2 Keepalived_vrrp[39003]: VRRP_Instance(VIP_Mysql) Entering BACKUP STATE
Mar 31 17:44:56 201-2 Keepalived_vrrp[39003]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
Mar 31 17:44:56 201-2 Keepalived_healthcheckers[39002]: Opening file ‘/etc/keepalived/keepalived.conf‘.
Mar 31 17:44:56 201-2 Keepalived_healthcheckers[39002]: Configuration is using : 6489 Bytes
Mar 31 17:44:56 201-2 Keepalived_healthcheckers[39002]: Using LinkWatch kernel netlink reflector...

[[email protected] ~]# ip a s dev em1
2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 44:a8:42:0b:f8:05 brd ff:ff:ff:ff:ff:ff
    inet 10.0.201.2/8 brd 10.255.255.255 scope global em1
    inet6 fe80::46a8:42ff:fe0b:f805/64 scope link 
       valid_lft forever preferred_lft forever

四、停止主
【keepalived  主】
Mar 31 17:45:47 R201-1 Keepalived[39252]: Stopping Keepalived v1.2.13 (10/15,2014)
Mar 31 17:45:47 R201-1 Keepalived_vrrp[39254]: VRRP_Instance(VIP_Mysql) sending 0 priority
Mar 31 17:45:47 R201-1 Keepalived_vrrp[39254]: VRRP_Instance(VIP_Mysql) removing protocol VIPs.

[[email protected] ~]# ip a s dev em1         
2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 54:9f:35:0f:e0:98 brd ff:ff:ff:ff:ff:ff
    inet 10.0.201.1/8 brd 10.255.255.255 scope global em1
    inet6 fe80::569f:35ff:fe0f:e098/64 scope link 
       valid_lft forever preferred_lft forever
       

【keepalived  备】
Mar 31 17:46:16 201-2 Keepalived_vrrp[39003]: VRRP_Instance(VIP_Mysql) Transition to MASTER STATE
Mar 31 17:46:17 201-2 Keepalived_vrrp[39003]: VRRP_Instance(VIP_Mysql) Entering MASTER STATE
Mar 31 17:46:17 201-2 Keepalived_vrrp[39003]: VRRP_Instance(VIP_Mysql) setting protocol VIPs.
Mar 31 17:46:17 201-2 Keepalived_vrrp[39003]: VRRP_Instance(VIP_Mysql) Sending gratuitous ARPs on em1 for 10.0.201.100
Mar 31 17:46:17 201-2 Keepalived_healthcheckers[39002]: Netlink reflector reports IP 10.0.201.100 added
Mar 31 17:46:22 201-2 Keepalived_vrrp[39003]: VRRP_Instance(VIP_Mysql) Sending gratuitous ARPs on em1 for 10.0.201.100

[[email protected] ~]# ip a s dev em1
2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 44:a8:42:0b:f8:05 brd ff:ff:ff:ff:ff:ff
    inet 10.0.201.2/8 brd 10.255.255.255 scope global em1
    inet 10.0.201.100/32 scope global em1
    inet6 fe80::46a8:42ff:fe0b:f805/64 scope link 
       valid_lft forever preferred_lft forever

五、再次启动主
【keepalived  主】
Mar 31 17:46:18 R201-1 Keepalived[39282]: Starting Keepalived v1.2.13 (10/15,2014)
Mar 31 17:46:18 R201-1 Keepalived[39283]: Starting Healthcheck child process, pid=39284
Mar 31 17:46:18 R201-1 Keepalived[39283]: Starting VRRP child process, pid=39285
Mar 31 17:46:18 R201-1 Keepalived_healthcheckers[39284]: Netlink reflector reports IP 10.0.201.1 added
Mar 31 17:46:18 R201-1 Keepalived_healthcheckers[39284]: Netlink reflector reports IP fe80::569f:35ff:fe0f:e098 added
Mar 31 17:46:18 R201-1 Keepalived_healthcheckers[39284]: Registering Kernel netlink reflector
Mar 31 17:46:18 R201-1 Keepalived_vrrp[39285]: Netlink reflector reports IP 10.0.201.1 added
Mar 31 17:46:18 R201-1 Keepalived_vrrp[39285]: Netlink reflector reports IP fe80::569f:35ff:fe0f:e098 added
Mar 31 17:46:18 R201-1 Keepalived_healthcheckers[39284]: Registering Kernel netlink command channel
Mar 31 17:46:18 R201-1 Keepalived_vrrp[39285]: Registering Kernel netlink reflector
Mar 31 17:46:18 R201-1 Keepalived_vrrp[39285]: Registering Kernel netlink command channel
Mar 31 17:46:18 R201-1 Keepalived_vrrp[39285]: Registering gratuitous ARP shared channel
Mar 31 17:46:18 R201-1 Keepalived_healthcheckers[39284]: Opening file ‘/etc/keepalived/keepalived.conf‘.
Mar 31 17:46:18 R201-1 Keepalived_vrrp[39285]: Opening file ‘/etc/keepalived/keepalived.conf‘.
Mar 31 17:46:18 R201-1 Keepalived_healthcheckers[39284]: Configuration is using : 6491 Bytes
Mar 31 17:46:18 R201-1 Keepalived_vrrp[39285]: Configuration is using : 61953 Bytes
Mar 31 17:46:18 R201-1 Keepalived_vrrp[39285]: Using LinkWatch kernel netlink reflector...
Mar 31 17:46:18 R201-1 Keepalived_vrrp[39285]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
Mar 31 17:46:18 R201-1 Keepalived_healthcheckers[39284]: Using LinkWatch kernel netlink reflector...
Mar 31 17:46:19 R201-1 Keepalived_vrrp[39285]: VRRP_Instance(VIP_Mysql) Transition to MASTER STATE
Mar 31 17:46:19 R201-1 Keepalived_vrrp[39285]: VRRP_Instance(VIP_Mysql) Received lower prio advert, forcing new election
Mar 31 17:46:20 R201-1 Keepalived_vrrp[39285]: VRRP_Instance(VIP_Mysql) Entering MASTER STATE
Mar 31 17:46:20 R201-1 Keepalived_vrrp[39285]: VRRP_Instance(VIP_Mysql) setting protocol VIPs.
Mar 31 17:46:20 R201-1 Keepalived_vrrp[39285]: VRRP_Instance(VIP_Mysql) Sending gratuitous ARPs on em1 for 10.0.201.100
Mar 31 17:46:20 R201-1 Keepalived_healthcheckers[39284]: Netlink reflector reports IP 10.0.201.100 added

【keepalived  备】
Mar 31 17:46:47 201-2 Keepalived_vrrp[39003]: VRRP_Instance(VIP_Mysql) Received higher prio advert
Mar 31 17:46:47 201-2 Keepalived_vrrp[39003]: VRRP_Instance(VIP_Mysql) Entering BACKUP STATE
Mar 31 17:46:47 201-2 Keepalived_vrrp[39003]: VRRP_Instance(VIP_Mysql) removing protocol VIPs.
Mar 31 17:46:47 201-2 Keepalived_healthcheckers[39002]: Netlink reflector reports IP 10.0.201.100 removed
时间: 2024-08-10 11:15:51

测试keepalived主备模式的相关文章

haproxy+keepalived主备与双主模式配置

Haproxy+Keepalived主备模式 主备节点设置 主备节点上各安装配置haproxy,配置内容且要相同 global log 127.0.0.1 local2 chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 4000 user haproxy group haproxy daemon defaults #defaults段默认值对frontend和backend和listen段生效 mode http #运行模式

L10 keepalived 基本使用(主备模式)

配置keepalive基本主备模式 配置说明: 要求默认情况下由节点node1提供服务,当节点node1不可用时,由节点node2提供服务(即虚拟IP漂移至节点node2). 节点node1 192.168.0.20 (主节点) 节点node2 192.168.0.21(备用节点) 虚拟IP(对外提供服务的IP 192.168.0.60 ping node 192.168.0.22(用于节点自身状态监测) 内容: 1,节点node1上的配置文件 2,节点node2配置 3,使用脚本防止脑裂. 4

【 Keepalived 】Nginx or Http 主-备模式

一.主-备模式: 操作系统:centos 6.4 x64 ka1: 192.168.2.10 ka2: 192.168.2.11 vip: 192.168.2.200 ka1-master服务器配置 [ka1 [email protected]192.168.2.10 ~]#yum install httpd keepalived -y # 这里使用apache代替nginx,效果是一样的,然后直接yum安装keepalived [ka1 [email protected]192.168.2.1

Nginx + Keepalived(主备模式)实现负载均衡高可用浅析

概述 目前关于负载均衡和高可用的架构方案能找到相当多且详尽的资料,此篇是自己学习相关内容的一个总结,防止将来遗忘再次重新查找资料,也避免踩相同的坑. 此次配置的负载均衡与高可用架构:Nginx + Keepalived(主备模式),Nginx 使用反向代理实现七层负载均衡. 众所周知,Nginx 是一款自由的.开源的.高性能HTTP服务器和反向代理服务器,也是一个IMAP.POP3.SMTP代理服务器. 也就是说Nginx本身就可以托管网站(类似于Tomcat一样),进行HTTP服务处理,也可以

MM(主主数据库)+keepalived主备高可用集群

博客分享的第一篇技术文章: 项目主要搭建:主主数据库高可用集群搭建. 数据库互为主备,应用技术:MM+keepalived 使用的是虚拟机搭建的实验向大家展示: 数据库1:192.168.4.7 数据库2:192.168.4.77 VIP:192.168.4.68 web1:192.168.4.69 web2:192.168.4.70 一.安装mysql,部署主主同步结构. 直接yum安装 配置主主同步: 由于主数据库192.168.4.7里面存放着数据,所以需要先导出数据,方法很多,我们采取m

redis演练(6) redis复制(主备模式)

redis是一款面向分布式的Nosql产品,天生对主备模式有很好的支持,而且配置一套完整的主备模式,非常简单.针对redis,主备模式配置非常简单,但线上意义重大. 主要内容 1.CAP理论 2.简单redis的复制原理 3.redis replaction相关配置参数解析 4.配置星型模型主备模式 5.配置有向无欢模型主备模式 1.研磨redis的复制与集群概念 redis的复制与集群,刚开始我把两者闹了个误会,在不断深入学习过程中及时改正了. 简单区分一下. redis复制:可以理解为把re

Nginx+Keepalived主备切换(包含nginx服务停止)

原文地址:http://blog.sina.com.cn/s/blog_79ac6aa80101bmed.html Nginx+Keepalived主备切换(包含nginx服务停止) 环境: VM中4台CentOS 本机PC充当测试机win8 步骤: 1.搭建 nginx+keepalived主备切换(不考虑主nginx停掉现象)文章中的环境 2.修改两台部署的keepalived的配置文件 3.编写观察nginx进程情况的脚本内容 #!/bin/bash A=`ps -C nginx --no

CentOS6.5和CentOS7.0双网卡主备模式配置

双网卡主备模式配置(bond0) 1     简述 通过双网卡设置主备模式,实现当一块网卡宕掉时,另外一块网卡可以自动顶替宕掉的网卡工作,保障网络正常访问. 2     实现 2.1.  查看网卡信息 执行ifconfig -a命令 2.2.  修改网卡配置文件 切换工作目录 cd /etc/sysconfig/network-scripts/ 修改网卡配置文件ifcfg-eth0 ,保证以下几项内容正确: TYPE=Ethernet BOOTPROTO=dhcp ONBOOT=yes MAST

centos7 搭建双网卡bond1(主备模式)实例

前景须知: 在redhat6 中网卡叫bond,在redhat7及centos7中改名team,此处只记录centos7中双网卡主备搭建过程. 应用情景:实现网络的高可用,防止一条网线或交换机故障影响该物理机进行数据交互 此次环境是由于在上线业务之前是没有做Team的 ,现在由于要撤掉交换机过程期间需要将网线连接到另外一台交换机,为了防止数据中断,因此采用Team主备模式,这样断掉一个网卡就不影响业务,测试发现重启网卡时候会有3到4个丢包 环境:centos7  网卡1 ens192  网卡2