MYSQL负载均衡集群构建

Posted 家园叮咚

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MYSQL负载均衡集群构建相关的知识,希望对你有一定的参考价值。

1. Keepalived介绍

   Keepalived的作用是检测服务器的状态,如果有一台服务器宕机,或工作出现故障,Keepalived将检测到,并将有故障的服务器从系统中剔除,同时使用其它服务器代替该服务器的工作,当服务器工作 正常后Keepalived自动将服务器加入到服务器群中,这些工作全部自动完成,不需要人工干涉,需要人工做的只是修复故障的服务器。

2. Keepalived工具安装

2.1.安装 keepalived 需要用到 openssl

[root@localhost keepalived]# yum install gcc gcc-c++ openssl openssl-devel

[root@localhost home]# wget -q https://www.keepalived.org/software/keepalived-1.2.18.tar.gz

2.2.解压Keepalived并安装

[root@localhost home]# tar -zxvf keepalived-1.2.18.tar.gz

[root@localhost home]# cd keepalived-1.2.18

[root@localhost keepalived-1.2.18]# ./configure --prefix=/usr/local/keepalived

[root@localhost keepalived-1.2.18]# make && make install

2.3. keepalived 安装成 Linux 系统服务

因为没有使用 keepalived 的默认路径安装(默认是/usr/local,安装完成之后,需要做一些工作 复制默认配置文件到默认路径

[root@localhost keepalived-1.2.18]# mkdir /etc/keepalived

[root@localhost keepalived-1.2.18]# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/

[root@localhost keepalived-1.2.18]# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/

[root@localhost keepalived-1.2.18]# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

[root@localhost keepalived-1.2.18]# ln -s /usr/local/keepalived/sbin/keepalived /usr/sbin/

设置 keepalived 服务开机启动

[root@localhost keepalived-1.2.18]# chkconfig keepalived on

3. Keepalived配置文件

3.1 修改配置文件

(1)MASTER 节点配置文件(192.168.199.142

MYSQL负载均衡集群构建

(2)BACKUP 节点配置文件(192.168.209.133

haproxy状态检测脚本



以上是关于MYSQL负载均衡集群构建的主要内容,如果未能解决你的问题,请参考以下文章

Haproxy 构建负载均衡集群

高可用性负载均衡的mysql集群解决方案

负载均衡集群

LVS+keepalived做Mysql集群的负载均衡

基于Haproxy+Keepalived构建高可用负载均衡集群

高可用性负载均衡的mysql集群解决方案