LVS+keepalived构建PXC高可用集群

Stella981
• 阅读 293

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高可用集群

点赞
收藏
评论区
推荐文章
刚刚好 刚刚好
4个月前
css问题
1、在IOS中图片不显示(给图片加了圆角或者img没有父级)<div<imgsrc""/</divdiv{width:20px;height:20px;borderradius:20px;overflow:h
blmius blmius
1年前
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
晴空闲云 晴空闲云
4个月前
css中box-sizing解放盒子实际宽高计算
我们知道传统的盒子模型,如果增加内边距padding和边框border,那么会撑大整个盒子,造成盒子的宽度不好计算,在实务中特别不方便。boxsizing可以设置盒模型的方式,可以很好的设置固定宽高的盒模型。盒子宽高计算假如我们设置如下盒子:宽度和高度均为200px,那么这会这个盒子实际的宽高就都是200px。但是当我们设置这个盒子的边框和内间距的时候,那
艾木酱 艾木酱
3个月前
快速入门|使用MemFire Cloud构建React Native应用程序
MemFireCloud是一款提供云数据库,用户可以创建云数据库,并对数据库进行管理,还可以对数据库进行备份操作。它还提供后端即服务,用户可以在1分钟内新建一个应用,使用自动生成的API和SDK,访问云数据库、对象存储、用户认证与授权等功能,可专
Easter79 Easter79
1年前
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
Stella981 Stella981
1年前
KVM调整cpu和内存
一.修改kvm虚拟机的配置1、virsheditcentos7找到“memory”和“vcpu”标签,将<namecentos7</name<uuid2220a6d1a36a4fbb8523e078b3dfe795</uuid
Wesley13 Wesley13
1年前
MySQL查询按照指定规则排序
1.按照指定(单个)字段排序selectfromtable_nameorderiddesc;2.按照指定(多个)字段排序selectfromtable_nameorderiddesc,statusdesc;3.按照指定字段和规则排序selec
Stella981 Stella981
1年前
Angular material mat
IconIconNamematiconcode_add\_comment_addcommenticon<maticonadd\_comment</maticon_attach\_file_attachfileicon<maticonattach\_file</maticon_attach\
Wesley13 Wesley13
1年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
helloworld_28799839 helloworld_28799839
4个月前
常用知识整理
Javascript判断对象是否为空jsObject.keys(myObject).length0经常使用的三元运算我们经常遇到处理表格列状态字段如status的时候可以用到vue
helloworld_34035044 helloworld_34035044
6个月前
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为