当前位置:Gxlcms > mysql > MySQL高可用架构之MySQL-MMM配置详解

MySQL高可用架构之MySQL-MMM配置详解

时间:2021-07-01 10:21:17 帮助过:35人阅读

实验系统:CentOS 6.6_x86_64 实验前提:防火墙和selinux都关闭 实验说明:本实验共有5台主机,IP分配如拓扑 实验软件:mariadb-

实验系统:CentOS 6.6_x86_64

实验前提:防火墙和selinux都关闭

实验说明:本实验共有5台主机,IP分配如拓扑

实验软件:mariadb-10.0.20  mysql-mmm-2.2.1  mysql-mmm-monitor-2.2.1  mysql-mmm-agent-2.2.1

下载地址:

或者:

------------------------------------------分割线------------------------------------------

FTP地址:ftp://ftp1.linuxidc.com

用户名:ftp1.linuxidc.com

密码:

在 2015年LinuxIDC.com\8月\MySQL高可用架构之MySQL-MMM配置详解

下载方法见

------------------------------------------分割线------------------------------------------

实验拓扑:

MySQL高可用架构之MySQL-MMM配置详解

使用MySQL-MMM实现MySQL集群部署

MySQL MMM架构看不到vip地址

MySQL的MMM高可用架构测试

MySQL-MMM实现MySQL高可用

MySQL-MMM切换演示

mysql proxy、MySQL-MMM实现读写分离高可用性

将MySQL-MMM Master从REPLICATION_FAIL状态恢复

CentOS下利用MySQL-MMM实现MySQL高可用

一、准备工作

1.根据下表,将各主机名进行修改:

MySQL高可用架构之MySQL-MMM配置详解

2.修改hosts文件,添加如下内容:

vim /etc/hosts
------------------------------------------->
192.168.19.21 mon
192.168.19.66 db1
192.168.19.74 db2
192.168.19.76 db3
192.168.19.79 db4

3.规划虚拟ip,列表如下:

MySQL高可用架构之MySQL-MMM配置详解

二、安装mariadb并配置

1.在db1-4上安装:

tar xf mariadb-10.0.20-linux-x86_64.tar.gz -C /usr/local/
cd /usr/local/
ln -sv mariadb-10.0.20-linux-x86_64 mysql
useradd -r mysql
mkdir -pv /mydata/data
chown -R mysql.mysql /mydata/data/
cd mysql/
chown -R root.mysql .
scripts/mysql_install_db --user=mysql --datadir=/mydata/data/
cp support-files/my-large.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on

2.编辑配置文件:   db1:

vim /etc/my.cnf
--------------------------------------------->
[mysqld]
server-id = 1
datadir = /mydata/data
log-bin = /mydata/data/mysql1-bin
binlog_format = ROW
relay_log = /mydata/data/relay-log
auto-increment-increment = 2
auto-increment-offset = 1
sync_binlog = 1
sync_master_info = 1
sync_relay_log = 1
sync_relay_log_info = 1
max_binlog_size = 100M
log_slave_updates = 1
<---------------------------------------------
service mysqld start

    db2:

vim /etc/my.cnf
--------------------------------------------->
[mysqld]
server-id = 2
datadir = /mydata/data
log-bin = /mydata/data/mysql2-bin
binlog_format = ROW
relay_log = /mydata/data/relay-log
auto-increment-increment = 2
auto-increment-offset = 2
sync_binlog = 1
sync_master_info = 1
sync_relay_log = 1
sync_relay_log_info = 1
max_binlog_size = 100M
log_slave_updates = 1
<---------------------------------------------
service mysqld start

    db3:

vim /etc/my.cnf
--------------------------------------------->
[mysqld]
server-id = 3
datadir = /mydata/data
log-bin = /mydata/data/mysql3-bin
binlog_format = ROW
relay_log = /mydata/data/relay-log
sync_binlog = 1
sync_master_info = 1
sync_relay_log = 1
sync_relay_log_info = 1
max_binlog_size = 100M
log_slave_updates = 1
<---------------------------------------------
service mysqld start

db4:

vim /etc/my.cnf
--------------------------------------------->
[mysqld]
server-id = 4
datadir = /mydata/data
log-bin = /mydata/data/mysql4-bin
binlog_format = ROW
relay_log = /mydata/data/relay-log
sync_binlog = 1
sync_master_info = 1
sync_relay_log = 1
sync_relay_log_info = 1
max_binlog_size = 100M
log_slave_updates = 1
<---------------------------------------------
service mysqld start

这里需要创建三个用户,如下表:

/usr/local/mysql/bin/mysql
------------------------------------------------->
GRANT REPLICATION CLIENT ON *.* TO 'mmm_monitor'@'192.168.19.%' IDENTIFIED BY '123456';
GRANT SUPER,REPLICATION CLIENT,PROCESS ON *.* TO 'mmm_agent'@'192.168.19.%' IDENTIFIED BY '123456';
GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.19.%' IDENTIFIED BY '123456'

4.查看二进制日志位置:

FLUSH TABLES WITH READ LOCK; //施加锁
SHOW MASTER STATUS;
+-------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| mysql1-bin.000004 | 936 | | |
+-------------------+----------+--------------+------------------+

5.不要关闭这个mysql进程连接,避免锁失效,我们另起一个ssh连接db1服务器,进行数据库备份:

/usr/local/mysql/bin/mysqldump --all-databases > /tmp/database-backup.sql

6.回到刚才mysql进程,进行解锁:

UNLOCK TABLES;

7.将database-backup.sql文件复制到其他db节点:

scp /tmp/database-backup.sql db2:/tmp/
scp /tmp/database-backup.sql db3:/tmp/
scp /tmp/database-backup.sql db4:/tmp/

8.db2-4主机导入sql文件,并刷新权限:

/usr/local/mysql/bin/mysql < /tmp/database-backup.sql
/usr/local/mysql/bin/mysql
------------------------------------------------->
FLUSH PRIVILEGES;

三、设置复制

1.在db2-4上操作,将db1设置为db2-4的主:

CHANGE MASTER TO MASTER_HOST='192.168.19.66',MASTER_USER='replication',MASTER_PASSWORD='123456',MASTER_LOG_FILE='mysql1-bin.000004',MASTER_LOG_POS=936;
START SLAVE;

2.查看状态:

SHOW SLAVE STATUS\G

MySQL高可用架构之MySQL-MMM配置详解

MySQL高可用架构之MySQL-MMM配置详解

MySQL高可用架构之MySQL-MMM配置详解

3.查看db2的master日志位置:

人气教程排行