LVS+keepalived构建PXC高可用集群

Stella981
• 阅读 643

1 高可用安装

1.1 集群信息

主机

IP

组件

bdc212

192.168.13.212

LVS:ipvsadm-1.27-7.el7.x86_64.rpm

Keepalived: keepalived-1.2.4.tar.gz

应用:Percona-XtraDB-Cluster

bdc213

192.168.13.213

LVS:ipvsadm-1.27-7.el7.x86_64.rpm

Keepalived: keepalived-1.2.4.tar.gz

应用:Percona-XtraDB-Cluster

bdc214

192.168.13.214

应用:Percona-XtraDB-Cluster

1.2 安装准备

  • 上传安装所需的压缩包到/opt目录

        keepalived-1.2.4.tar.gz

        (http://www.keepalived.org/software/keepalived-1.2.4.tar.gz)

  • 安装组件所需依赖包

    yum install openssl-devel popt-devel libnl* -y

1.3 安装LVS+keepalived

        在两台Director Server上分别安装LVS+Keepalived,BACKUP服务器与MASTER服务器一致,先安装lvs再安装keepalived。

1.3.3 安装LVS

        Ipvs(IP Virtual Server)是整个负载均衡的基础,没有这个基础,故障隔离与失败切换就毫无意义了。

yum install ipvsadm –y

1.3.4 安装keepalived

解压包:

tar zxvf keepalived-1.2.4.tar.gz

初始化:

cd keepalived-1.2.4
./configure --prefix=/usr/local/keepalived 

Keepalived configuration
------------------------
Keepalived version       : 1.2.4
Compiler                 : gcc
Compiler flags           : -g -O2
Extra Lib                : -lpopt -lssl -lcrypto  -lnl
Use IPVS Framework       : Yes
IPVS sync daemon support : Yes
IPVS use libnl           : Yes
Use VRRP Framework       : Yes
Use VRRP VMAC            : Yes
Use Debug flags          : No

编译并安装:

make&&make install

Make complete
make -C keepalived install
make[1]: Entering directory `/root/Desktop/keepalived-1.2.1/keepalived'
install -d /usr/local/keepalived/sbin
install -m 700 ../bin/keepalived /usr/local/keepalived/sbin/
install -d /usr/local/keepalived/etc/rc.d/init.d
install -m 755 etc/init.d/keepalived.init /usr/local/keepalived/etc/rc.d/init.d/keepalived
install -d /usr/local/keepalived/etc/sysconfig
install -m 755 etc/init.d/keepalived.sysconfig /usr/local/keepalived/etc/sysconfig/keepalived
install -d /usr/local/keepalived/etc/keepalived/samples
install -m 644 etc/keepalived/keepalived.conf /usr/local/keepalived/etc/keepalived/
install -m 644 ../doc/samples/* /usr/local/keepalived/etc/keepalived/samples/
install -d /usr/local/keepalived/share/man/man5
install -d /usr/local/keepalived/share/man/man8
install -m 644 ../doc/man/man5/keepalived.conf.5 /usr/local/keepalived/share/man/man5
install -m 644 ../doc/man/man8/keepalived.8 /usr/local/keepalived/share/man/man8
make[1]: Leaving directory `/root/Desktop/keepalived-1.2.1/keepalived'
make -C genhash install
make[1]: Entering directory `/root/Desktop/keepalived-1.2.1/genhash'
install -d /usr/local/keepalived/bin
install -m 755 ../bin/genhash /usr/local/keepalived/bin/
install -d /usr/local/keepalived/share/man/man1
install -m 644 ../doc/man/man1/genhash.1 /usr/local/keepalived/share/man/man1
make[1]: Leaving directory `/root/Desktop/keepalived-1.2.1/genhash'

1.4 配置路由转发

1> 更改配置文件

vi /etc/sysctl.conf 

        net.ipv4.ip_forward = 1

2> 刷新系统配置

sysctl -p

1.5 配置keepalived.cnf

        keepalived的配置分为三类: 全局配置(global configuration),VRRPD配置,LVS配置。

        全局配置就是对整个keepalived起效的配置,不管是否使用LVS。VRRPD是keepalived的核心,LVS配置只在要使用keepalived来配置的管理LVS时需要使用,如果仅仅使用keepalived来做HA,LVS的配置是不需要的。如果在只有一个负载均衡器的场合,就不须 VRRP 实例定义块。

mkdir /etc/keepalived
vi /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   router_id LVS_MASTER            #BACKUP  LVS_BACKUP
}

vrrp_instance VI_1 {
    state MASTER                   #BACKUP  BACKUP
    interface eno16777736
    virtual_router_id 51
    priority 100                   #BACKUP  80
    advert_int 1
    nopreempt
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.252.199
    }
}
  
virtual_server 192.168.252.199 3306 {
    delay_loop 6
    lb_algo rr
    lb_kind NAT
#   persistence_timeout 5
    protocol TCP

    real_server 192.168.252.159 3306 {
        weight 3
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 3306
        }
    }
   

    real_server 192.168.252.160 3306 {
        weight 3
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 3306
        }
    }

    real_server 192.168.252.161 3306 {
        weight 3
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
            connect_port 3306
        }
    }
}

        注:配置backup的/etc/keepalived/keepalived.conf,只需将批注部分改一下即可。

2 keepalived集群启动

2.1 master节点启动

/usr/local/keepalived/sbin/keepalived start

检查虚拟IP启动情况

方法1:

tail -30 /var/log/message

Jun 15 16:24:25 localhost Keepalived_vrrp[54297]: Interface queue is empty
Jun 15 16:24:25 localhost Keepalived_vrrp[54297]: No such interface, virbr0
Jun 15 16:24:25 localhost Keepalived_vrrp[54297]: No such interface, virbr0-nic
Jun 15 16:24:25 localhost Keepalived_vrrp[54297]: Registering Kernel netlink reflector
Jun 15 16:24:25 localhost Keepalived_vrrp[54297]: Registering Kernel netlink command channel
Jun 15 16:24:25 localhost Keepalived_vrrp[54297]: Registering gratuitous ARP shared channel
Jun 15 16:24:25 localhost Keepalived_vrrp[54297]: Opening file '/etc/keepalived/keepalived.conf'.
Jun 15 16:24:25 localhost Keepalived_vrrp[54297]: Configuration is using : 61916 Bytes
Jun 15 16:24:25 localhost Keepalived_vrrp[54297]: Using LinkWatch kernel netlink reflector...
Jun 15 16:24:25 localhost Keepalived_healthcheckers[54296]: Activating healthchecker for service [192.168.252.199]:3306
Jun 15 16:24:25 localhost Keepalived_healthcheckers[54296]: Activating healthchecker for service [192.168.252.199]:3306
Jun 15 16:24:25 localhost Keepalived_healthcheckers[54296]: Activating healthchecker for service [192.168.252.199]:3306
Jun 15 16:24:25 localhost Keepalived_vrrp[54297]: VRRP_Instance(VI_1) Transition to MASTER STATE
Jun 15 16:24:26 localhost Keepalived_vrrp[54297]: VRRP_Instance(VI_1) Entering MASTER STATE
Jun 15 16:24:26 localhost avahi-daemon[768]: Registering new address record for 192.168.252.199 on eno16777736.IPv4.

方法2:

[root@localhost Desktop]#ip addr

        LVS+keepalived构建PXC高可用集群

2.2 backup节点启动

/usr/local/keepalived/sbin/keepalived start

2.3 查看路由分发情况

查看ipvsadm

[root@localhost Desktop]#ipvsadm

        LVS+keepalived构建PXC高可用集群

也能够通过mysqladmin查看本地mysql服务连接状况

/opt/percona/bin/mysqladmin -uroot -p123456 status

        LVS+keepalived构建PXC高可用集群

3 PXC故障测试

3.1 杀死mysql服务

        杀死节点三上的mysql服务

kill -9 mysqld’s pid

3.2 查看ipvsadm

[root@localhost Desktop]# ipvsadm

        LVS+keepalived构建PXC高可用集群

         注:负载均衡服务解除了节点三,只向节点一二分发包。

3.3 重启mysql服务

/usr/share/percona-xtradb-cluster/mysql.server start

3.4 再查看ipvsadm

[root@localhost Desktop]# ipvsadm

        LVS+keepalived构建PXC高可用集群

        注:负载均衡服务重新把节点三放入了路由分发列表。

4 高可用测试

4.1 杀死master的KP服务

Kill -9 keepalived'pid

4.2 查看组建工作情况

    1> VIP持有情况:

        查看master ip:#ip add

            Master释放了VIP:192.168.13.100

        查看backup ip:#ip add

            Backup接收了VIP:192.168.13.100,继续提供负载均衡服务

    2> ipvsadm工作情况

查看master Ipvsadm:负载均衡没有工作

[root@localhost keepalived-1.2.4]# ipvsadm

         LVS+keepalived构建PXC高可用集群

查看backup ipvsadm:负载均衡仍然提供服务

[root@localhost keepalived-1.2.4]# ipvsadm

        LVS+keepalived构建PXC高可用集群

点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Easter79 Easter79
3年前
swap空间的增减方法
(1)增大swap空间去激活swap交换区:swapoff v /dev/vg00/lvswap扩展交换lv:lvextend L 10G /dev/vg00/lvswap重新生成swap交换区:mkswap /dev/vg00/lvswap激活新生成的交换区:swapon v /dev/vg00/lvswap
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
待兔 待兔
5个月前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Jacquelyn38 Jacquelyn38
3年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
Wesley13 Wesley13
3年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
3年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
3年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
11个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这