标签:$? grants 系统版本 sage stop 文件 png erb others
在高可用集群环境中,keepalived使用的是VIP,利用keepalived自带的服务监控功能和自定义脚本来实现MYSQL故障时自带切换。
Keepalived基于VRRP协议,虚拟冗余路由协议,所谓vrrp的优先级就是它会根据优先级来确定其他在集群中的地位,用0-255来表示,数字越小则表示优先级越低,数值越大表示优先级越高。当值为0,代表着master放弃持有VIP;该值为255时,表示当前master的优先级最高并蚩尤VIP。
IP |
主机名 |
作用 |
数据库版本 |
操作系统版本 |
172.16.20.32 |
mastera |
master |
Mysql5.7.20 |
Redhat6.7 |
172.16.20.34 |
masterb |
master |
Mysql5.7.20 |
Redhat6.7 |
172.16.20.30 |
|
VIP |
|
|
此处参照以前论坛内容:
http://www.cnblogs.com/hmwh/p/9011377.html
https://www.cnblogs.com/hmwh/p/9011377.html
创建主从复制账号
create user ‘rep‘@‘172.16.20.%‘ identified by ‘mysql‘;
grant replication slave on *.* to ‘rep‘@‘172.16.20.%‘;
show grants for ‘rep‘@‘172.16.20.%‘;
flush privileges;
所有主机创建管理账号:
create user ‘zs‘@‘172.16.20.%‘ identified by ‘123456‘;
grant all privileges on *.* to ‘zs‘@‘172.16.20.%‘;
flush privileges;
配置主从复制:
change master to master_host=‘172.16.20.32‘,master_port=3307,master_user=‘rep‘,master_password=‘mysql‘,master_auto_position=1;
start slave;
show slave status\G;
无问题后再在主库配置复制关系:
change master to master_host=‘172.16.20.34‘,master_port=3307,master_user=‘rep‘,master_password=‘mysql‘,master_auto_position=1;
start salve;
show slave status\G;
由于我的没有keepalived包
yum install keepalived
下载地址:
rpm -ivh keepalived-1.2.13-5.el6_6.x86_64.rpm
两台服务器都配置检测脚本:内容根据情况自行修改
cd /etc/keepalived/
vim checkmysql.sh
内容如下:
#!/bin/bash
mysqlstr=/usr/local/mysql5.7/bin/mysql
host=172.16.2.32
user=zs
password=123456
port=3307
#####mysql service machine status health is 1,others 0
mysql_status=1
#####check mysql status#########
$mysqlstr -h $host -u $user -ppassword -Pport -e "show status;" > /dev/null 2>&1
if [ $? = 0 ];then
echo "mysql_status=1"
exit 0
else
/etc/init.d/keepalived stop
fi
chmod 775 checkmysql.sh
主库的:
vim keepalived.conf
vrrp_scripts vs_mysql_100 {
scripts "/etc/keepalived/checkmysql.sh"
interval 10
}
vrrp_instance VI_100 {
state BACKUP
nopreempt
interface eth0
virtual_router_id 100
priority 100 --注意,30的为100,34的为90。
advert_int 5
authentication {
auth_type PASS
auth_pass 1314
}
track_script {
vs_mysql_100
}
virtual_ipaddress {
172.16.20.30
}
}
备库的:
vim keepalived.conf
vrrp_scripts vs_mysql_101 {
scripts "/etc/keepalived/checkmysql.sh"
interval 10
}
vrrp_instance VI_101 {
state BACKUP
nopreempt
interface eth0
virtual_router_id 100
priority 90
advert_int 5
authentication {
auth_type PASS
auth_pass 1314
}
track_script {
vs_mysql_101
}
virtual_ipaddress {
172.16.20.30
}
}
32服务器先启动。
/etc/init.d/keepalived start
/etc/init.d/keepalived status
ps -ef |grep keep
tail -100f /var/log/messages
172.16.20.32优先级高,keepalived的状态已经由backup升级为master。
ip addr
34服务器启动keepalived进程:
/etc/init.d/keepalived start
/etc/init.d/keepalived status
ps -ef |grep keep
tail -100f /var/log/messages
查看日志为backup 模式
管理用户测试登陆:
查看的UUID为主库32的。
备库keepalived 启动了,并没有VIP。
关闭32。
可以看到VIP飘到34服务器上。
且keepalived状态由backup升级为master。
标签:$? grants 系统版本 sage stop 文件 png erb others
原文地址:https://www.cnblogs.com/hmwh/p/9285106.html