MYSQL + MHA +keepalive + VIP安装配置(三)--keepalived安装配置
一、概述
keepalived介绍:Keepalived的作用是检测web服务器的状态,如果有一台web服务器死机,或工作出现故障,Keepalived将检测到,并将有故障的web 服务器从系统中剔除,当web服务器工作正常后Keepalived自动将web服务器加入到服务器群中,这些工作全部自动完成,不需要人工干涉,需要人 工做的只是修复故障的web服务器。
二、环境
vip:192.168.1.203\204
mysql-master:192.168.1.231
mysql-slave:192.168.1.232
三、keepalived安装
安装步骤两台机mysql-master、mysql-slave一样,如下:
1、下载地址:http://www.keepalived.org/software/keepalived-1.2.12.tar.gz
shell>wget http://www.keepalived.org/software/keepalived-1.2.12.tar.gz
2、安装环境
yum -y install openssl-devel
否则会报如下错误
configure: error:
!!! OpenSSL is not properly installed on your system. !!!
!!! Can not include OpenSSL headers files.
3、安装
shell>tar -zxvf keepalived-1.2.12.tar.gz
shell>cd keepalived-1.2.12
shell>./configure --prefix=/opt/keepalived --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/
shell>make
shell>make install
说明:
--prefix:安装路径
--with-kernel-dir:这个是重要的参数,这个参数并不表示我们要把Keepalived统进内核,而是指使用内核源码里面的头文件,也就是include目录。
2.6.32-431.el6.x86_64可以通过
shell>uname -r 命令查看到
4、配置
# cp /opt/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
# cp /opt/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
# mkdir /etc/keepalived
# cp /opt/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
# cp /opt/keepalived/sbin/keepalived /usr/sbin/
5、启动/停止
shell>service keepalived start
shell>service keepalived stop
shell>service keepalived restart
四、keepalived配置
1、mysql-master:192.168.1.231的配置
shell>vim /etc/keepalived/keepalived.conf
配置如下:
global_defs {
router_id mysql-master #修改为自己的主机名
notification_email {
mengtao10@163.com #接收邮件,可以有多个,一行一个
}
#当主、备份设备发生改变时,通过邮件通知
notification_email_from lzyangel@126.com
#发送邮箱服务器
smtp_server stmp.163.com
#发送邮箱超时时间
smtp_connect_timeout 30
}
##################第一部分###################
vrrp_instance VI_1 {
state BACKUP #都修改成BACKUP
interface eth0 #绑定的网卡
virtual_router_id 60 #默认51 主从都修改为60
priority 100 #优先级,在mysql-slave上LVS上修改成80
advert_int 1
nopreempt #不抢占资源,意思就是它活了之后也不会再把主抢回来
authentication {
# 认证方式,可以是PASS或AH两种认证方式
auth_type PASS
# 认证密码
auth_pass 1111
}
virtual_ipaddress {
192.168.1.203
192.168.1.204 #这可以增加多个VIP
}
}
##################第二部分###################
virtual_server 192.168.1.203 3306 {
delay_loop 6
lb_algo wrr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 192.168.1.231 3306 {
weight 1
notify_down /root/mysql_down.sh
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
connect_port 3306
}
}
}
2、mysql-master:192.168.1.232的配置
shell>vim /etc/keepalived/keepalived.conf
配置如下:
global_defs {
router_id mysql-master #修改为自己的主机名
notification_email {
mengtao10@163.com #接收邮件,可以有多个,一行一个
}
#当主、备份设备发生改变时,通过邮件通知
notification_email_from lzyangel@126.com
#发送邮箱服务器
smtp_server stmp.163.com
#发送邮箱超时时间
smtp_connect_timeout 30
}
##################第一部分###################
vrrp_instance VI_1 {
state BACKUP #都修改成BACKUP
interface eth0 #绑定的网卡
virtual_router_id 60 #默认51 主从都修改为60
priority 80 #优先级,在mysql-master上LVS上修改成100
advert_int 1
authentication {
# 认证方式,可以是PASS或AH两种认证方式
auth_type PASS
# 认证密码
auth_pass 1111
}
virtual_ipaddress {
192.168.1.203
192.168.1.204 #这可以增加多个VIP
}
}
##################第二部分###################
virtual_server 192.168.1.203 3306 {
delay_loop 6
lb_algo wrr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 50
protocol TCP
real_server 192.168.1.232 3306 {
weight 1
notify_down /root/mysql_down.sh
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
connect_port 3306
}
}
}
3、myslq_down.sh配置,两台机都要配置这一步!!!
这里需要注意的是,notify_down /root/mysql_down.sh这个选项,这个是是在keepalived检测不到mysql的时候要执行的脚本,从上面的配置文件来看real服务器只有本机。那么,keeaplived如果启动,客户端也只是访问本机的mysql。nopreempt这个选下也得注意,这个是不抢占资源在优先级高的机器上配置就可以。
看下这个脚本的内容:
# vim /root/mysql_down.sh
#!/bin/bash
pkill keepalived
# chmod +x /root/mysql_down.sh #授权可执行权限
脚本内容就一条命令:pkill keepalived,主要作用是如果本机的mysql挂掉了,那么同时会杀死本机的keepalived,这样另外一台就会接替他工作,虚拟IP也会被另一台接管,如果不杀死keepalived虚拟IP不会被另一台接管,mysql访问也就不会切换过去。
注意:必须要先启动MYSQL,再启动keepalived,否则keepalived启动后会运行mysql_down.sh脚本,等于自杀。
4、mysql-master(231)启动后查看IP的绑定情况,如下:
shell> ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:cc:92:22 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.232/24 brd 192.168.1.255 scope global eth0
inet 192.168.1.203/32 scope global eth0
inet 192.168.1.204/32 scope global eth0
inet6 fe80::a00:27ff:fecc:9222/64 scope link
valid_lft forever preferred_lft forever
五、测试
1、231、232两台机同时启动MYSQL及Keepalived.
通过win cmd 命令行的客户端(或程序)连接VIP:192.168.1.203或204,如下:
C:\Users\Duncan>mysql -h192.168.1.203 -usunney -psunney
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1440
Server version: 5.5.37-log MySQL Community Server (GPL) Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sunney |
| test |
+--------------------+
5 rows in set (0.04 sec) mysql>
注意:这时存储的数据库是mysql-master(192.168.1.231)因为他是主库。配置 priority 100 优先级高。
2、mysql-slave(232)的机同时关闭MYSQL及Keepalived.这时关闭上以上的是一样的。因为他没有走这个库。
3、mysql-master(231)同时关闭MYSQL及Keepalived,mysql-slave(232)同时启动MYSQL及Keepalived
切换很快,大概在2到3秒之间!
通过win cmd 命令行的客户端(或程序)连接VIP:192.168.1.203或204,如下:
C:\Users\Duncan>mysql -h192.168.1.203 -usunney -psunney
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1440
Server version: 5.5.37-log MySQL Community Server (GPL)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sunney |
| test |
+--------------------+
5 rows in set (0.04 sec) mysql>
成功!
MYSQL + MHA +keepalive + VIP安装配置(三)--keepalived安装配置的更多相关文章
- MYSQL + MHA +keepalive + VIP安装配置(二)--MHA的配置
一.总概 1.MHA介绍 MHA(Master High Availability)是自动的master故障转移和Slave提升的软件包.它是基于标准的MySQL复制(异步/半同步). MH ...
- MYSQL + MHA +keepalive + VIP安装配置(一)--MYSQL安装配置
一.总概: 本文介绍了MySQL高可用性的实现方案MHA,MHA由Node和Manager组成,Node运行在每一台MySQL服务器上,不管是MySQL主服务器,还是MySQL从服务器,都要安装Nod ...
- Apache Hadoop集群离线安装部署(三)——Hbase安装
Apache Hadoop集群离线安装部署(一)——Hadoop(HDFS.YARN.MR)安装:http://www.cnblogs.com/pojishou/p/6366542.html Apac ...
- grub安装的 三种安装方式
1. 引言 grub是什么?最常态的理解,grub是一个bootloader或者是一个bootmanager,通过grub可以引导种类丰富的系统,如linux.freebsd.windows等.但一旦 ...
- (转)yum安装MariaDB(使用国内镜像快速安装,三分钟安装完毕)
原文:https://blog.csdn.net/p__csdn/article/details/72675840 https://tinpont.com/2017/fix-yum-download- ...
- gitlab安装笔记三_Centos7安装GitLab
系统版本是CentOS-7-x86_64-Everything-1804.iso,很多软件默认都有了,不需要安装 https://about.gitlab.com/install/#centos-7 ...
- CentOS6.5上Zabbix3.0的RPM安装【三】-安装并添加Agent
七.Download and install Zabbix Agent Zabbix Agent is required to install on all remote systems needs ...
- Keepalived详解(二):Keepalived安装与配置【转】
一.Keepalived安装与配置: 1.Keepalived的安装过程: Keepalived的安装非常简单,本实例以源码安装讲解: Keepalived的官方网址:http://www.keepa ...
- keepalived安装及组合nginx配置负载实现高可用
目录 1. Keepalived安装配置 1.1 官网下载tar包 1.2 上传到指定目录安装 1.3 配置文件 1.4 配置nginx检测脚本文件 1.5 keepalived 启动/重启/停止/查 ...
随机推荐
- win 10 主题 美化
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha ========= 桌面背景,锁屏背景,文件名字,色调,文件夹 详细信息 显示 设置, ...
- 潭州课堂25班:Ph201805201 WEB 之 JS 第四课 (课堂笔记)
JS 引入方式 在 HTML 中写入 写在 的标签里 <script> </script>推荐 放在 </body> 结束之前 <!DOCTYPE html& ...
- LOJ6041 SAM+set+树状数组
首先对于原串建$SAM$,我们可以发先在一个点$i$的$right$集合里的点的相似度就是$len[i]$,于是可以将$SAM$的$right$集合通过$set$来启发式合并,每次加入新的点对$(i, ...
- 利用gsoap工具,通过wsdl文件生成webservice的C++工程文件
一.下载gsoap文件,下载地址:https://zh.osdn.net/projects/sfnet_gsoap2/releases/ 二.以gsoap-2.8为例,解压到D盘,在D:/gsoap- ...
- Ftrace使用指南及跟踪系统调用
http://vonnyfly.github.io/2013/06/24/ftraceshi-yong-zhi-nan/
- Image Processing in Python with Pillow
Introduction A lot of applications use digital images, and with this there is usually a need to proc ...
- 序列化与反序列化的单例模式实现和readResolve()【转】
如: public class SingleTest implements Serializable{private static final long serialVersionUID = -860 ...
- Recover database using backup controlfile until cancel
http://searchoracle.techtarget.com/answer/Recover-database-using-backup-controlfile-until-cancel Wha ...
- 1.5.3 GROUP BY子句
1.5.3 GROUP BY子句正在更新内容.请稍后
- ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode
备份数据库,报错如下 RMAN> backup database; Starting backup at -JAN- allocated channel: ORA_DISK_1 channel ...