mysql5.6基于主从复制的mmm高可用架构详解
MMM规划
192.168.3.12 master
192.168.3.13 slave1
192.168.3.198 slave2
MMM部署步骤
1.配置主主复制及主从同步集群
2.安装主从节点所需要的支持包
3.安装及配置MMM工具集
4.运行MMM监控服务
5.测试
一、环境初始化
1、修改主机名
主机: master执行命令
# sed -i 's/HOSTNAME=.*/HOSTNAME=master/g' /etc/sysconfig/network && hostname master
主机: slave01执行命令
# sed -i 's/HOSTNAME=.*/HOSTNAME=slave01/g' /etc/sysconfig/network && hostname slave01
主机: slave02执行命令(centos7.3)
# hostnamectl set-hostname slave02
2、主机名解析
在manager上执行如下命令
[root@master ~]# cat >> /etc/hosts << EOF
192.168.3.200 manager
192.168.3.12 master
192.168.3.13 slave01
192.168.3.198 slave02
EOF [root@master ~]# scp -o StrictHostKeyChecking=no /etc/hosts root@slave01:/etc/
[root@master ~]# scp -o StrictHostKeyChecking=no /etc/hosts root@slave02:/etc/
二、规划mysql
①安装mysql
1.yum安装相关依赖
yum -y install gcc gcc-c++ compat-gcc--g77 autoconf automake zlib zlib-devel libxml2-devel ncurses-devel libmcrypt-devel libmcrypt libtool-ltdl-devel* make cmake bison git openssl openssl-devel
2.编译安装
groupadd mysql
useradd -r -g mysql mysql
tar xf mysql-5.6..tar.gz
cd mysql-5.6. cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mydata -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE= -DWITH_MYISAM_STORAGE_ENGINE= -DWITH_ARCHIVE_STORAGE_ENGINE= -DWITH_PARTITION_STORAGE_ENGINE= -DWITH_BLACKHOLE_STORAGE_ENGINE= -DWITH_READLINE= -DWITH_SSL=system -DWITH_ZLIB=system -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DMYSQL_TCP_PORT= -DENABLED_LOCAL_INFILE= -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DWITH_LIBWRAP= -DDEFAULT_COLLATION=utf8_general_ci make && make install mkdir /data/mydata -p
mkdir /data/binlogs/
# slave节点要创建/data/relaylogs
mkdir /data/relaylogs chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /data/ cd /usr/local/mysql
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mydata
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
cp support-files/my-default.cnf /etc/my.cnf
修改配置
mysql master配置:
[root@master ~]# cat /etc/my.cnf
[client]
port =
socket = /tmp/mysql.sock
default-character-set = utf8mb4 [mysqld]
port =
innodb_file_per_table =
auto-increment-increment =
auto-increment-offset =
binlog-format=ROW
log-slave-updates=true
master-info-repository=table
relay-log-info-repository=table
sync-master-info=
slave-parallel-workers=
binlog-checksum=CRC32
master-verify-checksum=
slave-sql-verify-checksum=
binlog-rows-query-log_events=
server-id=
report-port=
log-bin=/data/binlogs/master-bin
max_binlog_size = 200M
datadir=/data/mydata
socket=/tmp/mysql.sock
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4 skip-name-resolve
skip-external-locking back_log =
max_connections =
max_connect_errors =
open_files_limit =
table_open_cache =
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size =
query_cache_type =
query_cache_size = 16M
query_cache_limit = 2M
ft_min_word_len =
expire_logs_days =
performance_schema =
explicit_defaults_for_timestamp default_storage_engine = InnoDB
innodb_open_files =
innodb_buffer_pool_size = 64M
innodb_write_io_threads =
innodb_read_io_threads =
innodb_thread_concurrency =
innodb_purge_threads =
innodb_flush_log_at_trx_commit =
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group =
innodb_max_dirty_pages_pct =
innodb_lock_wait_timeout = bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 512M
myisam_repair_threads = interactive_timeout =
wait_timeout = [mysqldump]
quick
max_allowed_packet = 16M [myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
mysql slave01 配置:
[root@slave01 src]# cat /etc/my.cnf
[client]
port =
socket = /tmp/mysql.sock
default-character-set = utf8mb4 [mysqld] port =
innodb_file_per_table =
binlog-format=ROW
read_only=on
log-slave-updates=true
auto-increment-increment =
auto-increment-offset =
master-info-repository=table
relay-log-info-repository=table
sync-master-info=
slave-parallel-workers=
binlog-checksum=CRC32
master-verify-checksum=
slave-sql-verify-checksum=
binlog-rows-query-log_events=
server-id=
report-port=
log-bin=/data/binlogs/master-bin
relay-log=/data/relaylogs/relay-bin
max_binlog_size = 200M
datadir=/data/mydata
socket=/tmp/mysql.sock
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4 skip-name-resolve
skip-external-locking back_log =
max_connections =
max_connect_errors =
open_files_limit =
table_open_cache =
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size =
query_cache_type =
query_cache_size = 16M
query_cache_limit = 2M
ft_min_word_len =
expire_logs_days =
performance_schema =
explicit_defaults_for_timestamp default_storage_engine = InnoDB
innodb_open_files =
innodb_buffer_pool_size = 64M
innodb_write_io_threads =
innodb_read_io_threads =
innodb_thread_concurrency =
innodb_purge_threads =
innodb_flush_log_at_trx_commit =
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group =
innodb_max_dirty_pages_pct =
innodb_lock_wait_timeout = bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 512M
myisam_repair_threads = interactive_timeout =
wait_timeout = [mysqldump]
quick
max_allowed_packet = 16M [myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
Mysql slave02配置
[root@slave02 ~]# cat /etc/my.cnf
[client]
port =
socket = /tmp/mysql.sock
default-character-set = utf8mb4 [mysqld] port =
innodb_file_per_table =
binlog-format=ROW
log-slave-updates=true
master-info-repository=table
relay-log-info-repository=table
sync-master-info=
slave-parallel-workers=
binlog-checksum=CRC32
master-verify-checksum=
slave-sql-verify-checksum=
binlog-rows-query-log_events=
server-id=
report-port=
log-bin=/data/binlogs/master-bin
relay-log=/data/relaylogs/relay-bin # 从节点要配置relay-log
max_binlog_size = 200M
datadir=/data/mydata
socket=/tmp/mysql.sock
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4 skip-name-resolve
skip-external-locking back_log =
max_connections =
max_connect_errors =
open_files_limit =
table_open_cache =
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size =
query_cache_type =
query_cache_size = 16M
query_cache_limit = 2M
ft_min_word_len =
expire_logs_days =
performance_schema =
explicit_defaults_for_timestamp default_storage_engine = InnoDB
innodb_open_files =
innodb_buffer_pool_size = 64M
innodb_write_io_threads =
innodb_read_io_threads =
innodb_thread_concurrency =
innodb_purge_threads =
innodb_flush_log_at_trx_commit =
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group =
innodb_max_dirty_pages_pct =
innodb_lock_wait_timeout = bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 512M
myisam_repair_threads = interactive_timeout =
wait_timeout = [mysqldump]
quick
max_allowed_packet = 16M [myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
配置从数据库服务器推荐配置项:
log-slave-updates = on
read_only=on [建议]
masterjnfo—repository =TABLE [建议]
relay-log-info-repository=TABLE [建议]
主主配置相关参数:
master参数:
auto-increment-increment = 2 # 步长
auto-increment-offset = 1 # 起始值
slave01备用主库:
auto-increment-increment = 2
auto-increment-offset = 2
每个节点的server-id必须不同
server-id=198
*************************************************
启动服务,保证master和两个slave节点都能正常启动
/etc/init.d/mysqld start
3.配置master、slave01和slave02之间基于binlog的主从复制
在MySQL5.6 的Replication配置中,master端同样要开启两个重要的选项,server-id和log-bin,并且选项server-id在全局架构中并且唯一,不能被其它主机使用,这里采用主机ip地址的最后一位充当server-id的值;slave端要开启relay-log
在master建立主从复制账号
mysql> create user repl@'192.168.3.%' identified by 'replpass'; mysql> grant replication slave on *.* to repl@'192.168.3.%';
如果数据库有数据的情况下需要先对数据库进行备份,然后恢复到几个从库中:
方法①:
[root@master ~]# mysqldump --single-transaction --set-gtid-purged=OFF --master-data= --triggers --routines --all-databases -uroot -p >all2.sql
Enter password:
在slave01和slave02上还原
mysql -uroot -p < all2.sql
方法二:percona-xtrabackup
详情参考:http://www.cnblogs.com/reblue520/p/6894481.html
4.在slave01和slave02上执行主从同步
master:
mysql> show master status;
+-------------------+----------+--------------+------------------+------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+------------------------------------------+
| master-bin. | | | | 4c6237f8-a7da-11e6--000c29f333f8:- |
+-------------------+----------+--------------+------------------+------------------------------------------+
slave01:
mysql> change master to master_host='192.168.3.12',master_user='repl',master_password='replpass',master_log_file='master-bin.000017',master_log_pos=;
mysql> start slave;
mysql> show slave status\G
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.3.12
Master_User: repl
Master_Port:
Connect_Retry:
Master_Log_File: master-bin.
Read_Master_Log_Pos:
Relay_Log_File: relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: master-bin.
Slave_IO_Running: Yes # 表示主从ok
Slave_SQL_Running: Yes
slave02:
mysql> change master to master_host='192.168.3.12',master_user='repl',master_password='replpass',master_log_file='master-bin.000017',master_log_pos=;
mysql> start slave;
mysql> show slave status\G
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.3.12
Master_User: repl
Master_Port:
Connect_Retry:
Master_Log_File: master-bin.
Read_Master_Log_Pos:
Relay_Log_File: relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: master-bin.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
配置master和slave01之间的主主复制:
slave01上查看状态
mysql> show master status\G
*************************** . row ***************************
File: master-bin.
Position:
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set: -3b2a-11e7-99fe-000c29ba4e78:-,
4c6237f8-a7da-11e6--000c29f333f8:-:-
row in set (0.00 sec)
master上执行主从同步:
mysql> change master to master_host='192.168.3.13',master_user='repl',master_password='replpass',master_log_file='master-bin.000016',master_log_pos=;
Query OK, rows affected, warnings (0.22 sec) mysql> start slave;
Query OK, rows affected, warning (0.01 sec) mysql> show slave status\G
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.3.13
Master_User: repl
Master_Port:
Connect_Retry:
Master_Log_File: master-bin.
Read_Master_Log_Pos:
Relay_Log_File: master-relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: master-bin.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
三、安装配置mmm
1.在每个节点上都安装mmm客户端
# yum install -y mysql-mmm-agent.noarch
2.slave02上安装mysql-mmm即监控端monitor
# yum install mysql-mmm* -y
注意:经过测试在centos7上yum方式安装监控无法启动,源码编译安装也有各种问题,最好使用centos6
3.主库上建立mmm_agent和mmm_monitor用户:
创建mmm_agent用户
mysql> grant super,replication client,process on *.* to 'mmm_agent'@'192.168.3.%' identified by '';
创建mmm_monitor用户
mysql> grant replication client on *.* to 'mmm_monitor'@'192.168.3.%' identified by '';
4.修改配置
①修改/etc/mysql-mmm/mmm_common.conf配置文件,并拷贝到slave01和slave02上
# vim /etc/mysql-mmm/mmm_common.conf
active_master_role writer <host default>
cluster_interface eth0
pid_path /var/run/mysql-mmm/mmm_agentd.pid
bin_path /usr/libexec/mysql-mmm/
replication_user repl #
replication_password replpass
agent_user mmm_agent
agent_password
</host> <host db1>
ip 192.168.3.12
mode master
peer db2
</host> <host db2>
ip 192.168.3.13
mode master
peer db1
</host> <host db3>
ip 192.168.3.198
mode slave
</host> <role writer>
hosts db1, db2
ips 192.168.3.90
mode exclusive
</role> <role reader>
hosts db1, db2, db3
ips 192.168.3.91,192.168.3.92,192.168.3.93
mode balanced
</role>
②修改/etc/mysql-mmm/mmm_agent.conf master、slave01和slave02内容分别是 this db1/this db2/this db3
master
# cat /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf this db1
slave01
# cat /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf this db2
slave01
# cat /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf this db3
③修改slave02即monitor的配置
[root@slave02 ~]# cat /etc/mysql-mmm/mmm_mon.conf
include mmm_common.conf <monitor>
ip 127.0.0.1
pid_path /run/mysql-mmm-monitor.pid
bin_path /usr/libexec/mysql-mmm
status_path /var/lib/mysql-mmm/mmm_mond.status
ping_ips 192.168.3.12,192.168.3.13,192.168.3.198 # 三个节点的IP
auto_set_online # The kill_host_bin does not exist by default, though the monitor will
# throw a warning about it missing. See the section 5.10 "Kill Host
# Functionality" in the PDF documentation.
#
# kill_host_bin /usr/libexec/mysql-mmm/monitor/kill_host
#
</monitor> <host default>
monitor_user mmm_monitor # 监控用户
monitor_password # 监控密码
</host> debug
启动所有节点上的mmm_agent服务
# /etc/init.d/mysql-mmm-agent start
启动slave02的monitor服务
# /etc/init.d/mysql-mmm-monitor start
四、进行主主切换测试:
监控节点执行检测功能,可以看到master有3.90写角色和3.92读的角色
[root@slave02 mysql-mmm]# mmm_control show
db1(192.168.3.12) master/ONLINE. Roles: reader(192.168.3.92), writer(192.168.3.90)
db2(192.168.3.13) master/ONLINE. Roles: reader(192.168.3.93)
db3(192.168.3.198) slave/ONLINE. Roles: reader(192.168.3.91)
1.停止master上的mysql服务
[root@master ~]# /etc/init.d/mysqld stop
Shutting down MySQL.. [ OK ]
[root@master ~]# /etc/init.d/mysqld status
MySQL is not running [FAILED]
再次查看监控节点状态,可以看到主节点已经切换到了slave01上
[root@slave02 mysql-mmm]# mmm_control show
db1(192.168.3.12) master/HARD_OFFLINE. Roles:
db2(192.168.3.13) master/ONLINE. Roles: reader(192.168.3.93), writer(192.168.3.90)
db3(192.168.3.198) slave/ONLINE. Roles: reader(192.168.3.91), reader(192.168.3.92)
通过在slave02上查看从库状态也可以看到主服务器已经重新指向了slave02
2.重新启动原master节点上的mysql服务,主节点也不会切回原节点
[root@slave02 mysql-mmm]# mmm_control show
db1(192.168.3.12) master/ONLINE. Roles: reader(192.168.3.91)
db2(192.168.3.13) master/ONLINE. Roles: reader(192.168.3.93), writer(192.168.3.90)
db3(192.168.3.198) slave/ONLINE. Roles: reader(192.168.3.92)
mysql5.6基于主从复制的mmm高可用架构详解的更多相关文章
- 基于Consul的数据库高可用架构【转】
几个月没有更新博客了,已经长草了,特意来除草.本次主要分享如何利用consul来实现redis以及mysql的高可用.以前的公司mysql是单机单实例,高可用MHA加vip就能搞定,新公司mysql是 ...
- 美团点评基于MGR的CMDB高可用架构搭建之路【转】
王志朋 美团点评DBA 曾在京东金融担任DBA,目前就职于美团点评,主要负责金融业务线数据库及基础组件数据库的运维. MySQL Group Replication(以下简称MGR),于5.7.17版 ...
- MySQL集群搭建(3)-MMM高可用架构
1 MMM 介绍 1.1 简介 MMM 是一套支持双主故障切换以及双主日常管理的第三方软件.MMM 由 Perl 开发,用来管理和监控双主复制,虽然是双主架构,但是业务上同一时间只允许一个节点进行写入 ...
- (MHA+MYSQL-5.7增强半同步)高可用架构设计与实现
架构使用mysql5.7版本基于GTD增强半同步并行复制配置 reploication 一主两从,使用MHA套件管理整个复制架构,实现故障自动切换高可用 优势: ...
- centos6.6部署mysql mmm高可用架构
一.环境简述 1.工作逻辑图 2.MySQL-MMM优缺点 优点:高可用性,扩展性好,出现故障自动切换,对于主主同步,在同一时间只提供一台数据库写操作,保证的数据的一致性. 缺点:Monitor节点是 ...
- 基于Consul的数据库高可用架构
几个月没有更新博客了,已经长草了,特意来除草.本次主要分享如何利用consul来实现redis以及mysql的高可用.以前的公司mysql是单机单实例,高可用MHA加vip就能搞定,新公司mysql是 ...
- vivo 基于原生 RabbitMQ 的高可用架构实践
一.背景说明 vivo 在 2016 年引入 RabbitMQ,基于开源 RabbitMQ 进行扩展,向业务提供消息中间件服务. 2016~2018年,所有业务均使用一个集群,随着业务规模的增长,集群 ...
- DRBD 高可用配置详解(转)
高可用性集群解释:一般是指当集群中有某个节点失效的情况下,其上的任务会自动转移到其他正常的节点上.还指可以将集群中的某节点进行离线维护再上线,该过程并不影响整个集群的运行.今天来做个Heartbeat ...
- mysql mmm高可用架构设计
项目概述:搭建主从,双主,安装Perl模块 安装配置mmm软件 测试 硬件环境:4台虚拟PC 软件环境:rehl6.5 MySQL-5.6.26 percona-xtrabackup-2.3.4 ...
随机推荐
- 【1】【leetcode-79】 单词搜索
(典型dfs,知道思想写错) 给定一个二维网格和一个单词,找出该单词是否存在于网格中. 单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格.同一个单 ...
- 804. Unique Morse Code Words
Description International Morse Code defines a standard encoding where each letter is mapped to a se ...
- write命令帮助文档(ubuntu 18.04)
WRITE() BSD General Commands Manual WRITE() NAME write — send a message to another user SYNOPSIS wri ...
- 使用js请求Servlet时的路径
项目结构如下: 全是web的html页面 js部分重要代码: function ajaxValidate() { var flag=false; $.ajax({ "url":&q ...
- 简单SQL语句
一.基础 模式定义了数据如何存储.存储什么样的数据以及数据如何分解等信息,数据库和表都有模式. 主键的值不允许修改,也不允许复用(不能使用已经删除的主键值赋给新数据行的主键). SQL 语句不区分大小 ...
- 第26月第7天 mac如何matplotlib中文乱码问题
1.mac如何matplotlib中文乱码问题 先查看 ~/.matplotlib/fontList.json 添加SimHei字体(simhei.ttf文件)到 /Library/Framework ...
- Python之List列表的增删改查
序列是Python中最基本的数据结构.序列中的每个元素都分配一个数字 - 它的位置,或索引,第一个索引是0,第二个索引是1,依此类推. Python有6个序列的内置类型,但最常见的是列表和元组. 序列 ...
- C hashtable小例子
参考链接: http://blog.csdn.net/qinpanke/article/details/9171541
- Struts2基础2
一.struts中的API 1)完全解耦合的方式 1.1首先创建一个示例工程,在WEB-INF下创建lib文件夹,把struts2核心jar包导入.在工程下创建resource文件夹,并将其设为资源文 ...
- linux上安装Docker(非常简单的安装方法)
Docker的三大核心概念:镜像.容器.仓库 镜像:类似虚拟机的镜像.用俗话说就是安装文件. 容器:类似一个轻量级的沙箱,容器是从镜像创建应用运行实例, 可以将其启动.开始.停止.删除.而这些容器都是 ...