search
HomeDatabaseMysql Tutorialmysql高可用之MHA(补充3)--管理多组主从复制_MySQL

前面我们了解了mha管理一组主从,然而在实际生产环境中不同的应用会使用不同的数据库,因此会有多组主从复制,我们可以使用一个mha manager 来管理多组主从复制数据库。我们只需要创建一个全局配置文件,你可以将这几组中相同的配置信息写到全局配置文件中,如用户名、密码等,而其他的配置信息单独写到每个app*.cnf中。

官网介绍:

https://code.google.com/p/mysql-master-ha/wiki/Configuration

下面我们就来介绍下:

mha架构:

\

如上:我们使用一个mha manager节点来管理3组主从复制,我这面只配置两组,每组具体的配置请参考前面的博文,在此只介绍重点。

10.10.10.59 mha manager

APP1:

10.10.10.56 master

10.10.10.57 slave1

10.10.10.58 slave2

10.10.10.60 vip

APP2:

10.10.10.61 master

10.10.10.62 slave1

10.10.10.63 slave2

10.10.10.64 vip

1.创建全局配置文件masterha_default.cnf

 

mkdir -p /etc/mha
cp /usr/local/src/mha4mysql-manager-0.56/samples/conf/masterha_default.cnf /etc/mha/
ln -s /etc/mha/masterha_default.cnf /etc/masterha_default.cnf
#将相同的配置信息写到全局配置文件中
[root@rd-mysql-test4 mha]# cat masterha_default.cnf 
[server default]
master_binlog_dir=/data/mysql
password=123456
ping_interval=1
remote_workdir=/tmp
repl_password=123456
repl_user=rep
report_script=/usr/local/bin/send_report
ssh_port=22
ssh_user=root
user=mha
注意:masterha_default.cnf一定要在/etc下,否则检查过程中会找不到这个文件,为将所有的mha相关配置文件放在一起方便管理,我做了软连接。
2.创建每个应用对应的配置文件app*.conf

 

app1.conf

 

[root@rd-mysql-test4 mha]# cat /etc/mha/app1.cnf 
[server default]
manager_log=/var/log/masterha/app1/manager.log
manager_workdir=/var/log/masterha/app1
master_ip_failover_script=/usr/local/bin/master_ip_failover_app1
master_ip_online_change_script=/usr/local/bin/master_ip_online_change_app1

[server1]
hostname=10.10.10.56
port=3306

[server2]
candidate_master=1
check_repl_delay=0
hostname=10.10.10.57
port=3306

[server3]
hostname=10.10.10.58
port=3306
app2.conf

 

 

[root@rd-mysql-test4 mha]# cat /etc/mha/app2.cnf 
[server default]
manager_log=/var/log/masterha/app2/manager.log
manager_workdir=/var/log/masterha/app2
master_ip_failover_script=/usr/local/bin/master_ip_failover_app2
master_ip_online_change_script=/usr/local/bin/master_ip_online_change_app2

[server1]
hostname=10.10.10.61
port=3306

[server2]
candidate_master=1
check_repl_delay=0
hostname=10.10.10.62
port=3306

[server3]
hostname=10.10.10.63
port=3306
注意:每个应用的master_ip_failover_script和master_ip_online_change_script对应的脚本不一样,因为我们在迁移过程中使用vip来达到高可用的目的,master_ip_failover在自动failover过程中使vip会自动漂移,而master_ip_online_change在在线迁移过程中使vip漂移。因此在多个主从复制组我们使用多个不同的脚本来管理不同的ip。

 

3.检查ssh配置

masterha_check_ssh --conf=/etc/mha/app1.cnf

masterha_check_ssh --conf=/etc/mha/app2.cnf

注:(1)全局配置文件在检测过程中会自动检查,如果找不到全局配置文件,就会读取指定的应用配置文件。

(2)每个主从复制组都需要和mha manager节点配置ssh无密码登录,但组与组之前不要配置。

4.检查replication配置

masterha_check_repl --conf=/etc/mha/app1.cnf

masterha_check_repl --conf=/etc/mha/app2.cnf

5.启动监控

nohup masterha_manager --conf=/etc/mha/app1.cnf --remove_dead_master_conf --ignore_last_failover /var/log/masterha/app1/manager.log 2>&1 &

nohup masterha_manager --conf=/etc/mha/app2.cnf --remove_dead_master_conf --ignore_last_failover /var/log/masterha/app1/manager.log 2>&1 &

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain the role of InnoDB redo logs and undo logs.Explain the role of InnoDB redo logs and undo logs.Apr 15, 2025 am 12:16 AM

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

What are the key metrics to look for in an EXPLAIN output (type, key, rows, Extra)?What are the key metrics to look for in an EXPLAIN output (type, key, rows, Extra)?Apr 15, 2025 am 12:15 AM

Key metrics for EXPLAIN commands include type, key, rows, and Extra. 1) The type reflects the access type of the query. The higher the value, the higher the efficiency, such as const is better than ALL. 2) The key displays the index used, and NULL indicates no index. 3) rows estimates the number of scanned rows, affecting query performance. 4) Extra provides additional information, such as Usingfilesort prompts that it needs to be optimized.

What is the Using temporary status in EXPLAIN and how to avoid it?What is the Using temporary status in EXPLAIN and how to avoid it?Apr 15, 2025 am 12:14 AM

Usingtemporary indicates that the need to create temporary tables in MySQL queries, which are commonly found in ORDERBY using DISTINCT, GROUPBY, or non-indexed columns. You can avoid the occurrence of indexes and rewrite queries and improve query performance. Specifically, when Usingtemporary appears in EXPLAIN output, it means that MySQL needs to create temporary tables to handle queries. This usually occurs when: 1) deduplication or grouping when using DISTINCT or GROUPBY; 2) sort when ORDERBY contains non-index columns; 3) use complex subquery or join operations. Optimization methods include: 1) ORDERBY and GROUPB

Describe the different SQL transaction isolation levels (Read Uncommitted, Read Committed, Repeatable Read, Serializable) and their implications in MySQL/InnoDB.Describe the different SQL transaction isolation levels (Read Uncommitted, Read Committed, Repeatable Read, Serializable) and their implications in MySQL/InnoDB.Apr 15, 2025 am 12:11 AM

MySQL/InnoDB supports four transaction isolation levels: ReadUncommitted, ReadCommitted, RepeatableRead and Serializable. 1.ReadUncommitted allows reading of uncommitted data, which may cause dirty reading. 2. ReadCommitted avoids dirty reading, but non-repeatable reading may occur. 3.RepeatableRead is the default level, avoiding dirty reading and non-repeatable reading, but phantom reading may occur. 4. Serializable avoids all concurrency problems but reduces concurrency. Choosing the appropriate isolation level requires balancing data consistency and performance requirements.

MySQL vs. Other Databases: Comparing the OptionsMySQL vs. Other Databases: Comparing the OptionsApr 15, 2025 am 12:08 AM

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

How does MySQL index cardinality affect query performance?How does MySQL index cardinality affect query performance?Apr 14, 2025 am 12:18 AM

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

MySQL: Resources and Tutorials for New UsersMySQL: Resources and Tutorials for New UsersApr 14, 2025 am 12:16 AM

The MySQL learning path includes basic knowledge, core concepts, usage examples, and optimization techniques. 1) Understand basic concepts such as tables, rows, columns, and SQL queries. 2) Learn the definition, working principles and advantages of MySQL. 3) Master basic CRUD operations and advanced usage, such as indexes and stored procedures. 4) Familiar with common error debugging and performance optimization suggestions, such as rational use of indexes and optimization queries. Through these steps, you will have a full grasp of the use and optimization of MySQL.

Real-World MySQL: Examples and Use CasesReal-World MySQL: Examples and Use CasesApr 14, 2025 am 12:15 AM

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)