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高可用架构详解的更多相关文章

  1. 基于Consul的数据库高可用架构【转】

    几个月没有更新博客了,已经长草了,特意来除草.本次主要分享如何利用consul来实现redis以及mysql的高可用.以前的公司mysql是单机单实例,高可用MHA加vip就能搞定,新公司mysql是 ...

  2. 美团点评基于MGR的CMDB高可用架构搭建之路【转】

    王志朋 美团点评DBA 曾在京东金融担任DBA,目前就职于美团点评,主要负责金融业务线数据库及基础组件数据库的运维. MySQL Group Replication(以下简称MGR),于5.7.17版 ...

  3. MySQL集群搭建(3)-MMM高可用架构

    1 MMM 介绍 1.1 简介 MMM 是一套支持双主故障切换以及双主日常管理的第三方软件.MMM 由 Perl 开发,用来管理和监控双主复制,虽然是双主架构,但是业务上同一时间只允许一个节点进行写入 ...

  4. (MHA+MYSQL-5.7增强半同步)高可用架构设计与实现

           架构使用mysql5.7版本基于GTD增强半同步并行复制配置 reploication 一主两从,使用MHA套件管理整个复制架构,实现故障自动切换高可用        优势:       ...

  5. centos6.6部署mysql mmm高可用架构

    一.环境简述 1.工作逻辑图 2.MySQL-MMM优缺点 优点:高可用性,扩展性好,出现故障自动切换,对于主主同步,在同一时间只提供一台数据库写操作,保证的数据的一致性. 缺点:Monitor节点是 ...

  6. 基于Consul的数据库高可用架构

    几个月没有更新博客了,已经长草了,特意来除草.本次主要分享如何利用consul来实现redis以及mysql的高可用.以前的公司mysql是单机单实例,高可用MHA加vip就能搞定,新公司mysql是 ...

  7. vivo 基于原生 RabbitMQ 的高可用架构实践

    一.背景说明 vivo 在 2016 年引入 RabbitMQ,基于开源 RabbitMQ 进行扩展,向业务提供消息中间件服务. 2016~2018年,所有业务均使用一个集群,随着业务规模的增长,集群 ...

  8. DRBD 高可用配置详解(转)

    高可用性集群解释:一般是指当集群中有某个节点失效的情况下,其上的任务会自动转移到其他正常的节点上.还指可以将集群中的某节点进行离线维护再上线,该过程并不影响整个集群的运行.今天来做个Heartbeat ...

  9. mysql mmm高可用架构设计

    项目概述:搭建主从,双主,安装Perl模块  安装配置mmm软件  测试 硬件环境:4台虚拟PC 软件环境:rehl6.5 MySQL-5.6.26 percona-xtrabackup-2.3.4 ...

随机推荐

  1. HTTP method constants

    HTTP method constants ngx.HTTP_GET ngx.HTTP_HEAD ngx.HTTP_PUT ngx.HTTP_POST ngx.HTTP_DELETE ngx.HTTP ...

  2. windows下通过压缩包安装MySQL

    一.下载压缩包 二.解压缩后存放在该路径下 三.配置环境变量     将D:\Program Files\mysql-8.0.11-winx64\bin添加到用户PATH变量或系统PATH变量中   ...

  3. mysql 单表更新记录UPDATE

    1.单表更新 (1)mysql> SELECT * FROM users;+----+----------+----------+-----+------+| id   | username | ...

  4. 第21月第7日 数据结构 b+树

    1.B+树 MySQL支持诸多存储引擎,而各种存储引擎对索引的支持也各不相同,因此MySQL数据库支持多种索引类型,如BTree索引,哈希索引,全文索引等等. http://blog.codingla ...

  5. jstl-----之<set>标签

    <table id="attachtab" border="0" cellpadding="0" cellspacing=" ...

  6. bae64编码

    data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAEAAAAkCAYAAABIdFAMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJb ...

  7. 省市联动-获取资源文件xml 获取nodes的方法要学会

    try { SAXReader reader = new SAXReader(); InputStream input = this.getClass().getResourceAsStream(&q ...

  8. java spring属性注入

    一.创建对象时候,向类里面属性设置值:一般有三个方式 1) .有参构造, 2). set**** 3).接口注入 二. 在spring框架里面,支持前面两种方式: 1).有参构造方法  用constr ...

  9. xadmin插件开发

    参考:http://blog.csdn.net/qq_15682489/article/details/70174784 项目中新添加的organization模块需要在toolbar中添加“课表详细 ...

  10. 20165231 2017-2018-2 《Java程序设计》第7周学习总结

    教材学习内容总结 第十一章 MySQL数据库管理系统,简称MySQL,是世界上最流行的开源数据库管理系统,其社区版(MySQL Community Edition)是最流行的免费下载的开源数据库管理系 ...