标签:test 检测 清空 reader cache info wal def 技术分享
简介:MMM即Master-Master Replication Manager for MySQL(mysql主主复制管理器)通过MMM方案能实现服务器的故障转移,从而实现mysql的高可用。
关闭防火墙开启mariadb,直接mysql登录mariadb
在主1服务器上查看master状态(mysql_bin.000003 245 必须注意)
在两台主服务器上提权
开启slave
mmm群集脚本:
主服务器1 192.168.120.128 db1 vip:192.168.120.200
主服务器2 192.168.120.129 db2
从服务器1 192.168.120.130 db3 vip:192.168.120.210
从服务器2 192.168.120.131 db4 192.168.120.220
监控服务器 192.168.120.132
=======================================
四台同装 //下载阿里云源yum配置文件
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum install epel-release -y //安装epel源
yum clean all && yum makecache //清空所有,重新设置数据缓存
yum install mariadb-server mariadb -y //安装mariadb
vim /etc/my.cnf
删除原有【mysqld】文件插入
[mysqld]
log_error=/var/lib/mysql/mysql.err
log=/var/lib/mysql/mysql_log.log
log_slow_queries=var/lib/mysql/mysql_slow_queris.log
binlog-ignore-db=mysql,information_schema
character_set_server=utf8
log_bin=mysql_bin
server_id=1
log_slave_updates=true
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1
关闭防火墙
systemctl stop firewalld.service
setenforce 0
开启服务
systemctl start mariadb.service
可以登录mysql
授权(两台主上)
grant replication slave on . to ‘replication‘@‘192.168.120.%‘ identified by ‘123456‘;
change master to master_host=‘192.168.120.128‘,master_user=‘replication‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000003‘,master_log_pos=245;
开启同步
start slave;
查看状态
show slave status\G;
从服务器上
change master to master_host=‘192.168.120.128‘,master_user=‘replication‘,master_password=‘123456‘,master_log_file=‘mysql_bin.000003‘,master_log_pos=245;
开启同步
start slave;
查看状态
show slave status\G;
=================安装mmm======================
四台同装
yum install mysql-mmm* -y
cd /etc/mysql-mmm/
vim mmm_common.conf
在主1上(远程复制功能)
scp mmm_common.conf root@192.168.120.129:/etc/mysql-mmm/
scp mmm_common.conf root@192.168.120.130:/etc/mysql-mmm/
scp mmm_common.conf root@192.168.120.131:/etc/mysql-mmm/
监控服务器安装好mmm后
cd /etc/mysql-mmm/
vim mmm_mon.conf
修改
8 ping_ips 192.168.120.128,192.168.120.129,192.168.120.130,192.168.120.131
9 auto_set_online 10 //10秒自动上线
21 monitor_password 123456
----------------------------在四台服务器上为mmm agent授权-----
//授权代理mmm_agent
grant super, replication client, process on . to ‘mmm_agent‘@‘192.168.120.%‘ identified by ‘123456‘;
//监控授权mmm_monitor
grant replication client on . to ‘mmm_monitor‘@‘192.168.120.%‘ identified by ‘123456‘;
flush privileges; //刷新
vim mmm_agent.conf
修改四台
this db1
this db2
this db3
this db4
----------------------------在所有数据库服务器上启动mysql-mmm-agent---------
四台
systemctl start mysql-mmm-agent.service 开启服务
systemctl enable mysql-mmm-agent.service 开机自启动
systemctl start mysql-mmm-monitor.service 监控上开启
mmm_control show 监控上查看四台服务器状态
显示
db1(192.168.120.128) master/ONLINE. Roles: writer(192.168.120.200)
db2(192.168.120.129) master/ONLINE. Roles:
db3(192.168.120.130) slave/ONLINE. Roles: reader(192.168.120.210)
db4(192.168.120.131) slave/ONLINE. Roles: reader(192.168.120.220)
切换
mmm_control move_role writer db2
mmm_control checks all //需要全部ok
-----------------------------------故障检测------------------------------------
systemctl stop mariadb.service //关闭主1mariadb
mmm_control show //监控那台查看(自动会切第二台)
在四台服务器上为监控机地址授权登录
grant all on . to ‘testdba‘@‘192.168.120.132‘ identified by ‘123456‘;
flush privileges; //刷新
-----------------在监控服务器上-------------------------
mysql -utestdba -p -h 192.168.120.200 //直接登录访问
标签:test 检测 清空 reader cache info wal def 技术分享
原文地址:http://blog.51cto.com/13756916/2173120