14、高可用keepalived搭建及切换
tar -zxvf keepalived-1.2.13.tar.gzcd keepalived-1.2.13./configure -prefix=/usr/local/keepalivedmakemake install[root@likun keepalived-1.2.13]# cat /opt/mysql/mysql.sh#!/bin/shpkill keepalived[root@likun keepalived-1.2.13]# chmod +x /opt/mysql/mysql.sh
[root@likun keepalived-1.2.13]# cat /usr/local/keepalived/etc/keepalived.conf!ConfigurationFilefor keepalivedglobal_defs {notification_email {likun@163.com}router_id mysql-ha}vrrp_instance VI_20 {state BACKUPinterface eth0virtual_router_id 20priority 90advert_int 1nopreemptauthentication {auth_type PASSauth_pass 1111}virtual_ipaddress {192.168.1.76}}virtual_server 192.168.1.763306{delay_loop 2lb_algo wrrlb_kind DRpersistence_timeout 60protocol TCPreal_server 192.168.1.203306{weight 3notify_down /opt/mysql/mysql.shTCP_CHECK {connect_timeout 10nb_get_retry 3delay_before_retry 3connect_port 3306}}}
!ConfigurationFilefor keepalivedglobal_defs {notification_email {likun@163.com}router_id mysql-ha}vrrp_instance VI_21 {state BACKUPinterface eth0virtual_router_id 20--注意2边要一致priority 100advert_int 1nopreemptauthentication {auth_type PASSauth_pass 1111}virtual_ipaddress {192.168.1.76}}virtual_server 192.168.1.763306{delay_loop 2lb_algo wrrlb_kind DRpersistence_timeout 60protocol TCPreal_server 192.168.1.213306{weight 3notify_down /opt/mysql/mysql.shTCP_CHECK {connect_timeout 10nb_get_retry 3delay_before_retry 3connect_port 3306}}}
- 在20机器测试,mysql没有启动的情况下,keepalived启动会被自动杀掉,证明keepalived配置正确
- 在2边启动mysql并启动keepalived,测试用vip登陆数据库
[root@likun1 keepalived-1.2.13]# mysql -h192.168.1.76-P3306 -uroot -prootWelcome to the MySQL monitor. Commands end with ; or \g.YourMySQL connection id is 682Server version:5.5.30-log Source distributionCopyright(c)2000,2013,Oracle and/or its affiliates.All rights reserved.Oracle is a registered trademark of OracleCorporation and/or itsaffiliates.Other names may be trademarks of their respectiveowners.Type'help;' or '\h'for help.Type'\c' to clear the current input statement.mysql>
[root@likun1 keepalived-1.2.13]# ip addr show1: lo:<LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWNlink/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host loinet6 ::1/128 scope hostvalid_lft forever preferred_lft forever2: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 08:00:27:5d:ef:c3 brd ff:ff:ff:ff:ff:ffinet 192.168.1.21/24 brd 192.168.1.255 scope global eth0inet 192.168.1.76/32 scope global eth0inet6 fe80::a00:27ff:fe5d:efc3/64 scope linkvalid_lft forever preferred_lft forever
[root@likun keepalived-1.2.13]# ip addr show1: lo:<LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWNlink/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host loinet6 ::1/128 scope hostvalid_lft forever preferred_lft forever2: eth0:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 08:00:27:00:58:57 brd ff:ff:ff:ff:ff:ffinet 192.168.1.20/24 brd 192.168.1.255 scope global eth0inet6 fe80::a00:27ff:fe00:5857/64 scope linkvalid_lft forever preferred_lft forever
- 杀掉master的keepalived,vip会飘到slave上,slave的日志:
Jul2020:03:31 likun Keepalived_vrrp[8547]: VRRP_Instance(VI_20)Transition to MASTER STATEJul2020:03:32 likun Keepalived_vrrp[8547]: VRRP_Instance(VI_20)Entering MASTER STATEJul2020:03:32 likun Keepalived_vrrp[8547]: VRRP_Instance(VI_20) setting protocol VIPs.Jul2020:03:32 likun Keepalived_vrrp[8547]: VRRP_Instance(VI_20)Sending gratuitous ARPs on eth0 for192.168.1.76Jul2020:03:32 likun Keepalived_healthcheckers[8546]:Netlink reflector reports IP 192.168.1.76 added
- 再启动master的keepalived,不会抢vip,变为backup state,master的日志:
Jul2020:03:49 likun1 Keepalived[7416]:StartingKeepalived v1.2.13(07/20,2014)Jul2020:03:49 likun1 Keepalived[7417]:StartingHealthcheck child process, pid=7418Jul2020:03:49 likun1 Keepalived[7417]:Starting VRRP child process, pid=7419Jul2020:03:49 likun1 Keepalived_vrrp[7419]:Netlink reflector reports IP 192.168.1.21 addedJul2020:03:49 likun1 Keepalived_healthcheckers[7418]:Netlink reflector reports IP 192.168.1.21 addedJul2020:03:49 likun1 Keepalived_healthcheckers[7418]:Netlink reflector reports IP fe80::a00:27ff:fe5d:efc3 addedJul2020:03:49 likun1 Keepalived_healthcheckers[7418]:RegisteringKernel netlink reflectorJul2020:03:49 likun1 Keepalived_healthcheckers[7418]:RegisteringKernel netlink command channelJul2020:03:49 likun1 Keepalived_vrrp[7419]:Netlink reflector reports IP fe80::a00:27ff:fe5d:efc3 addedJul2020:03:49 likun1 Keepalived_vrrp[7419]:RegisteringKernel netlink reflectorJul2020:03:49 likun1 Keepalived_vrrp[7419]:RegisteringKernel netlink command channelJul2020:03:49 likun1 Keepalived_vrrp[7419]:Registering gratuitous ARP shared channelJul2020:03:49 likun1 Keepalived_vrrp[7419]:Opening file '/usr/local/keepalived/etc/keepalived.conf'.Jul2020:03:49 likun1 Keepalived_vrrp[7419]:Configuration is using:62953BytesJul2020:03:49 likun1 Keepalived_vrrp[7419]:UsingLinkWatch kernel netlink reflector...Jul2020:03:49 likun1 Keepalived_vrrp[7419]: VRRP_Instance(VI_21)Entering BACKUP STATEJul2020:03:49 likun1 Keepalived_vrrp[7419]: VRRP sockpool:[ifindex(2), proto(112), unicast(0), fd(10,11)]Jul2020:03:49 likun1 Keepalived_healthcheckers[7418]:Opening file '/usr/local/keepalived/etc/keepalived.conf'.Jul2020:03:49 likun1 Keepalived_healthcheckers[7418]:Configuration is using:11555BytesJul2020:03:49 likun1 Keepalived_healthcheckers[7418]:UsingLinkWatch kernel netlink reflector...Jul2020:03:49 likun1 Keepalived_healthcheckers[7418]:Activating healthchecker for service [192.168.1.21]:3306
[root@likun ~]# cat /usr/local/keepalived/etc/keepalived.confvrrp_script vs_mysql_20 {script "/usr/local/keepalived/checkMySQL.py -h 192.168.1.20 -P 3306"interval 60}vrrp_instance VI_20 {state BACKUPnopreemptinterface eth0virtual_router_id 21priority 100advert_int 5authentication {auth_type PASSauth_pass 1111}track_script {vs_mysql_20}virtual_ipaddress {192.168.1.76}}
[root@likun1 ~]# cat /usr/local/keepalived/etc/keepalived.confvrrp_script vs_mysql_21 {script "/usr/local/keepalived/checkMySQL.py -h 192.168.1.21 -P 3306"interval 60}vrrp_instance VI_21 {state BACKUPnopreemptinterface eth0virtual_router_id 21priority 90advert_int 5authentication {auth_type PASSauth_pass 1111}track_script {vs_mysql_21}virtual_ipaddress {192.168.1.76}}
[root@likun ~]#/usr/local/keepalived/sbin/keepalived -f /usr/local/keepalived/etc/keepalived.conf -D[root@likun ~]# tail -f /var/log/messagesAug 820:58:41 likun Keepalived[8023]:StoppingKeepalived v1.2.13(07/20,2014)Aug 820:59:04 likun Keepalived[8064]:StartingKeepalived v1.2.13(07/20,2014)Aug 820:59:04 likun Keepalived[8065]:StartingHealthcheck child process, pid=8066Aug 820:59:04 likun Keepalived[8065]:Starting VRRP child process, pid=8067Aug 820:59:04 likun Keepalived_vrrp[8067]:Netlink reflector reports IP 192.168.1.20 addedAug 820:59:04 likun Keepalived_vrrp[8067]:Netlink reflector reports IP 10.0.3.15 addedAug 820:59:04 likun Keepalived_vrrp[8067]:Netlink reflector reports IP fe80::a00:27ff:fe00:5857 addedAug 820:59:04 likun Keepalived_healthcheckers[8066]:Netlink reflector reports IP 192.168.1.20 addedAug 820:59:04 likun Keepalived_vrrp[8067]:Netlink reflector reports IP fe80::a00:27ff:fe5d:683a addedAug 820:59:04 likun Keepalived_vrrp[8067]:RegisteringKernel netlink reflectorAug 820:59:04 likun Keepalived_vrrp[8067]:RegisteringKernel netlink command channelAug 820:59:04 likun Keepalived_vrrp[8067]:Registering gratuitous ARP shared channelAug 820:59:04 likun Keepalived_healthcheckers[8066]:Netlink reflector reports IP 10.0.3.15 addedAug 820:59:04 likun Keepalived_healthcheckers[8066]:Netlink reflector reports IP fe80::a00:27ff:fe00:5857 addedAug 820:59:04 likun Keepalived_healthcheckers[8066]:Netlink reflector reports IP fe80::a00:27ff:fe5d:683a addedAug 820:59:04 likun Keepalived_healthcheckers[8066]:RegisteringKernel netlink reflectorAug 820:59:04 likun Keepalived_healthcheckers[8066]:RegisteringKernel netlink command channelAug 820:59:05 likun Keepalived_vrrp[8067]:Opening file '/usr/local/keepalived/etc/keepalived.conf'.Aug 820:59:05 likun Keepalived_healthcheckers[8066]:Opening file '/usr/local/keepalived/etc/keepalived.conf'.Aug 820:59:05 likun Keepalived_vrrp[8067]:Configuration is using:62993BytesAug 820:59:05 likun Keepalived_healthcheckers[8066]:Configuration is using:5287BytesAug 820:59:05 likun Keepalived_vrrp[8067]:UsingLinkWatch kernel netlink reflector...Aug 820:59:05 likun Keepalived_vrrp[8067]: VRRP_Instance(VI_20)Entering BACKUP STATEAug 820:59:05 likun Keepalived_vrrp[8067]: VRRP sockpool:[ifindex(2), proto(112), unicast(0), fd(10,11)]Aug 820:59:05 likun Keepalived_healthcheckers[8066]:UsingLinkWatch kernel netlink reflector...Aug 820:59:07 likun Keepalived_vrrp[8067]: VRRP_Script(vs_mysql_20) succeededAug 820:59:20 likun Keepalived_vrrp[8067]: VRRP_Instance(VI_20)Transition to MASTER STATEAug 820:59:25 likun Keepalived_vrrp[8067]: VRRP_Instance(VI_20)Entering MASTER STATEAug 820:59:25 likun Keepalived_vrrp[8067]: VRRP_Instance(VI_20) setting protocol VIPs.Aug 820:59:25 likun Keepalived_vrrp[8067]: VRRP_Instance(VI_20)Sending gratuitous ARPs on eth0 for192.168.1.76Aug 820:59:25 likun Keepalived_healthcheckers[8066]:Netlink reflector reports IP 192.168.1.76 addedAug 820:59:30 likun Keepalived_vrrp[8067]: VRRP_Instance(VI_20)Sending gratuitous ARPs on eth0 for192.168.1.76
[root@likun1 ~]#/usr/local/keepalived/sbin/keepalived -f /usr/local/keepalived/etc/keepalived.conf -D[root@likun1 ~]# tail -f /var/log/messagesAug 918:11:27 likun1 Keepalived[3355]:StartingKeepalived v1.2.13(07/20,2014)Aug 918:11:27 likun1 Keepalived[3356]:StartingHealthcheck child process, pid=3357Aug 918:11:27 likun1 Keepalived[3356]:Starting VRRP child process, pid=3358Aug 918:11:27 likun1 Keepalived_vrrp[3358]:Netlink reflector reports IP 192.168.1.21 addedAug 918:11:27 likun1 Keepalived_healthcheckers[3357]:Netlink reflector reports IP 192.168.1.21 addedAug 918:11:27 likun1 Keepalived_healthcheckers[3357]:Netlink reflector reports IP 10.0.3.15 addedAug 918:11:27 likun1 Keepalived_healthcheckers[3357]:Netlink reflector reports IP fe80::a00:27ff:fe5d:efc3 addedAug 918:11:27 likun1 Keepalived_vrrp[3358]:Netlink reflector reports IP 10.0.3.15 addedAug 918:11:27 likun1 Keepalived_healthcheckers[3357]:Netlink reflector reports IP fe80::a00:27ff:fe97:754a addedAug 918:11:27 likun1 Keepalived_healthcheckers[3357]:RegisteringKernel netlink reflectorAug 918:11:27 likun1 Keepalived_healthcheckers[3357]:RegisteringKernel netlink command channelAug 918:11:27 likun1 Keepalived_vrrp[3358]:Netlink reflector reports IP fe80::a00:27ff:fe5d:efc3 addedAug 918:11:27 likun1 Keepalived_vrrp[3358]:Netlink reflector reports IP fe80::a00:27ff:fe97:754a addedAug 918:11:27 likun1 Keepalived_vrrp[3358]:RegisteringKernel netlink reflectorAug 918:11:27 likun1 Keepalived_vrrp[3358]:RegisteringKernel netlink command channelAug 918:11:27 likun1 Keepalived_vrrp[3358]:Registering gratuitous ARP shared channelAug 918:11:30 likun1 Keepalived_vrrp[3358]:Opening file '/usr/local/keepalived/etc/keepalived.conf'.Aug 918:11:30 likun1 Keepalived_healthcheckers[3357]:Opening file '/usr/local/keepalived/etc/keepalived.conf'.Aug 918:11:30 likun1 Keepalived_vrrp[3358]:Configuration is using:63001BytesAug 918:11:30 likun1 Keepalived_healthcheckers[3357]:Configuration is using:5295BytesAug 918:11:30 likun1 Keepalived_vrrp[3358]:UsingLinkWatch kernel netlink reflector...Aug 918:11:30 likun1 Keepalived_vrrp[3358]: VRRP_Instance(VI_21)Entering BACKUP STATEAug 918:11:30 likun1 Keepalived_vrrp[3358]: VRRP sockpool:[ifindex(2), proto(112), unicast(0), fd(10,11)]Aug 918:11:30 likun1 Keepalived_healthcheckers[3357]:UsingLinkWatch kernel netlink reflector...Aug 918:11:31 likun1 Keepalived_vrrp[3358]: VRRP_Script(vs_mysql_21) succeeded
20日志:Aug 823:09:05 likun Keepalived_vrrp[8067]: VRRP_Script(vs_mysql_20) failedAug 823:09:08 likun Keepalived_vrrp[8067]: VRRP_Instance(VI_20)Entering FAULT STATEAug 823:09:08 likun Keepalived_vrrp[8067]: VRRP_Instance(VI_20) removing protocol VIPs.Aug 823:09:08 likun Keepalived_vrrp[8067]: VRRP_Instance(VI_20)Now in FAULT stateAug 823:09:08 likun Keepalived_healthcheckers[8066]:Netlink reflector reports IP 192.168.1.76 removed
21日志:Aug 920:21:00 likun1 Keepalived_vrrp[3358]: VRRP_Instance(VI_21)Transition to MASTER STATEAug 920:21:05 likun1 Keepalived_vrrp[3358]: VRRP_Instance(VI_21)Entering MASTER STATEAug 920:21:05 likun1 Keepalived_vrrp[3358]: VRRP_Instance(VI_21) setting protocol VIPs.Aug 920:21:05 likun1 Keepalived_healthcheckers[3357]:Netlink reflector reports IP 192.168.1.76 addedAug 920:21:05 likun1 avahi-daemon[1320]:Registeringnew address record for192.168.1.76 on eth0.IPv4.Aug 920:21:05 likun1 Keepalived_vrrp[3358]: VRRP_Instance(VI_21)Sending gratuitous ARPs on eth0 for192.168.1.76Aug 920:21:10 likun1 Keepalived_vrrp[3358]: VRRP_Instance(VI_21)Sending gratuitous ARPs on eth0 for192.168.1.76
Aug 823:49:05 likun Keepalived_vrrp[8067]: VRRP_Script(vs_mysql_20) succeededAug 823:49:08 likun Keepalived_vrrp[8067]: VRRP_Instance(VI_20)Entering BACKUP STATE
14、高可用keepalived搭建及切换的更多相关文章
- 高可用Keepalived+LVS搭建流程
本流程搭建1个master,1个backup节点的Keepalived,使用lvs轮询2个节点的服务. 一.使用版本 CentOS 7.7 Keepalived 1.3.5 ipvsadm 1.27( ...
- 美团点评基于MGR的CMDB高可用架构搭建之路【转】
王志朋 美团点评DBA 曾在京东金融担任DBA,目前就职于美团点评,主要负责金融业务线数据库及基础组件数据库的运维. MySQL Group Replication(以下简称MGR),于5.7.17版 ...
- 解决nginx负载均衡高可用keepalived只针对物理机的问题
在高可用keepalived软件,在默认的情况下仅仅在对方机器宕机或keepalived停掉的时候才会接管业务. 但是在实际工作过程中,例如在nginx负载均衡工作实例中,nginx服务已停止,而ke ...
- haproxy + rabbitmq + keepalived的高可用环境搭建
一.rabbitmq的搭建:参考rabbimq的安装及集群设置 二.安装和配置haproxy 1.安装haproxyyum install haproxy 2.安装rsysloga. 检查rsyslo ...
- Redis + keepalived 高可用群集搭建
本次实验环境介绍: 操作系统: Centos 7.3 IP : 192.168.10.10 Centos 7.3 IP : 192.168.10.20 VIP 地址 : 192.168.1 ...
- mamcached+(magent+keepalived高可用)搭建及理论概述
目录 一.理论概述 工作流程 二.部署 环境 环境概述 部署 三.测试 四.总结 一.理论概述 Memcached服务器端与PHP-Memcache客户端安装配置_服务器应用_Linux公社-Linu ...
- nginx1.14.0版本高可用——keepalived双机热备
nginx不支持主从,所以我们需要使用keepalive支持高可用. keepalived重要知识点 在局域网内,每个主机上各安装一个keepalived,注意关闭防火墙firewalld,然后设定一 ...
- HA高可用的搭建
HA 即 (high available)高可用,又被叫做双机热备,用于关键性业务. 简单理解就是,有两台机器A和B,正常是A提供服务,B待命闲置,当A宕机或服务宕掉,会切换至B机器继续提供服务.常用 ...
- linux下mysql5.7的MHA高可用架构搭建
一.MHA简介 MHA(Master High Availability)目前在mysql高可用方面比较成熟.是一套优秀的作为 mysql高可用性环境下故障切换和主从提升的高可用软件.在MySQL故障 ...
随机推荐
- 上传代码到github上
初始化 git init 添加远程仓库 git remote add origin[仓库名] 仓库地址 添加文件 git add . 本地提交 git commit -m 'message' 拉去远程 ...
- 转:java读取配置文件的几种方法
转自: http://www.iteye.com/topic/56496 在现实工作中,我们常常需要保存一些系统配置信息,大家一般都会选择配置文件来完成,本文根据笔者工作中用到的读取配置文件的方法小小 ...
- linux中链表的使用【转】
转自:http://blog.csdn.net/finewind/article/details/8074990 Linux下链表的使用方法跟我们常规的不一样,通常情况下,链表的next指针都指向节点 ...
- PL/SQL 05 存储过程 procedure
--存储过程(不带参数) create or replace procedure 存储过程名as 变量.常量声明;begin 代码;end; --存储过程(带输入参数) create or rep ...
- DRF基类APIView的子类GenericAPIView
DRF的基类是APIView类,GenericAPIView类是APIView类的子类. GenericAPIView类有什么存在的意义呢? 其实, 他主要提供了两个用处: 1.提供关于数据库查询的属 ...
- lucene in action
1. 索引——好比字典的索引一样,进行查询时使用 2. Field.Index.NO 则没有索引,则不能被搜索 3. 第三章 PhraseQuery 短语查询 按照顺序添加term PharseQu ...
- ORM-老师信息系统
老师信息管理 思考 三种方式创建多对多外键方式及其优缺点. 通过外键创建 (自定义第三张表,通过外键与其他两张表关联 但是不能用Django ORM 多对多操作的语法) class Class(mo ...
- [libgdx游戏开发教程]使用Libgdx进行游戏开发(2)-游戏框架搭建
让我们抛开理论开始code吧. 入口类CanyonBunnyMain的代码: package com.packtpub.libgdx.canyonbunny; import com.badlogic. ...
- Asp.net中的一个判断session是否合法的做法
1 if (Session["UserID"] == "" || Session["UserID"] == null) 2 { 3 ...
- HDU 1711 Number Sequence【kmp求子串首次出现的位置】
Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= ...