vlambda博客
学习文章列表

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状态检测脚本