MySQL双主高可用架构之MMM实战
MMM简介:MMM即Master-MasterReplicationManagerforMySQL(mysql主主复制管理器),是关于mysql主主复制配置的监控、故障转移和管理的一套可伸缩的脚本套件(在
MMM简介:
MMM即Master-Master Replication Manager for MySQL(mysql主主复制管理器),是关于mysql主主复制配置的监控、故障转移和管理的一套可伸缩的脚本套件(在任何时候只有一个节点可以被写入),这个套件也能基于标准的主从配置的任意数量的从服务器进行读负载均衡,所以你可以用它来在一组居于复制的服务器启动虚拟ip,除此之外,它还有实现数据备份、节点之间重新同步功能的脚本。
MySQL本身没有提供replication failover的解决方案,通过MMM方案能实现服务器的故障转移,从而实现mysql的高可用。
MMM项目来自
官方网站为:
MMM主要功能由下面三个脚本提供
mmm_mond :负责所有的监控工作的监控守护进程,决定节点的移除等等
mmm_agentd :运行在mysql服务器上的代理守护进程,通过简单远程服务集提供给监控节点
进程
关于此架构的优缺点:
优点:安全性、稳定性高,可扩展性好,当主服务器挂掉以后,另一个主立即接管,其他的从服务器能自动切换,不用人工干预。
缺点:至少三个节点,对主机的数量有要求,需要实现读写分离,可以在程序扩展上比较难实现。同时对主从(双主)同步延迟要求比较高!因此不适合数据安全非常严格的场合。
实用场所:高访问量,业务增长快,并且要求实现读写分离的场景。
环境:
MMM_Monitor: 192.168.8.31-----(MySQL-MON)
MySQL_Master1: 192.168.8.32-----(MySQL-M1)
MySQL_Master2: 192.168.8.33-----(MySQL-M2)
VIP_Write: 192.168.8.30-----(VIP0)
VIP_Read1: 192.168.8.34-----(VIP1)
VIP_Read2: 192.168.8.35-----(VIP2)
架构原理图:
一、环境基础配置
1. 设置hosts解析
三台服务器配置如下:
cat >>/etc/hosts
192.168.8.31 MySQL-MON
192.168.8.32 MySQL-M1
192.168.8.33 MySQL-M2
EOF
二、安装配置mysql
具体安装过过程略,如果不会安装 mysql的可以不用看本教程了!
MySQL-M1的配置:
server-id = 12
#log-slave-updates
#sync_binlog = 1
log-bin = /data/mysql/binlog/mysql-bin
auto-increment-increment = 2
auto-increment-offset = 2
relay-log=mysql-relay
relay-log-index=mysql-relay.index
MySQL-M2的配置:
server-id = 13
#log-slave-updates
#sync_binlog = 1
log-bin = /data/mysql/binlog/mysql-bin
auto-increment-increment = 2
auto-increment-offset = 2
relay-log=mysql-relay
relay-log-index=mysql-relay.index
三、安装mysql-mmm
在三台服务器安装
wget
rpm -ivh epel-release-5-4.noarch.rpm
yum -y install mysql-mmm*
[root@MySQL-M1 mysql-mmm]# rpm -qa |grep mysql-mmm
mysql-mmm-2.2.1-1.el5
mysql-mmm-agent-2.2.1-1.el5
mysql-mmm-tools-2.2.1-1.el5
mysql-mmm-monitor-2.2.1-1.el5
说明:也可以下载源码包安装:
wget :mmm2:mysql-mmm-2.2.1.tar.gz
mv :mmm2:mysql-mmm-2.2.1.tar.gz mysql-mmm-2.2.1.tar.gz
tar xf mysql-mmm-2.2.1.tar.gz
cd mysql-mmm-2.2.1
make install
四、配置MySQL-M1和MySQL-M2主主模式
1.首先创建三个账号

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.
