search
HomeDatabaseMysql TutorialMHA 配置文件样本描述

与绝大多数Linux应用程序类似,MHA的正确使用依赖于合理的配置文件。MHA的配置文件与mysql的my.cnf文件配置相似,采取的是分模块

与绝大多数Linux应用程序类似,MHA的正确使用依赖于合理的配置文件。MHA的配置文件与mysql的my.cnf文件配置相似,采取的是分模块,param=value的方式来配置,配置文件位于管理节点,通常包括每一个mysql server的主机名,mysql用户名,密码,工作目录等等。本文列出了单套MHA以及采用全局配置来管理多套MHA配置文件的一些样例,供大家参考。

1、单套MHA配置样本
manager_host$ cat /etc/app1.cnf

[server default]
# 登陆mysql数据库账户及密码,缺省为root,因为需要STOP SLAVE, CHANGE MASTER, RESET SLAVE等。
user=root
password=mysqlpass

# working directory on the manager  #位于管理节点工作目录
manager_workdir=/var/log/masterha/app1

# manager log file #位于管理节点工作日志文件
manager_log=/var/log/masterha/app1/app1.log

# working directory on MySQL servers
# node 上用于产生日志的工作目录,如果不存在,MHA node会自动创建,前提需要有相应的权限,否则node会终止。
# 缺省目录为 "/var/tmp".
remote_workdir=/var/log/masterha/app1

#[serverN] 部分,为各节点配置信息,作用域为各单独节点,各节点书写顺序影响成为新master的顺序
#也可以通过配置candidate_master参数来影响哪个节点具有优先级成为新master
[server1]
hostname=host1

[server2]
hostname=host2

[server3]
hostname=host3

 

2、多套MHA配置样本
如果生产环境中基于单个管理节点部署了多套MHA,可以通过使用全局配置文件来配置相同或共有部分以达到简化配置,易于管理的目的。
假定我们创建了/etc/masterha_default.cnf,则MHA Manager脚本会首先都读取该文件然后再读取指定的配置文件。
这个功能类似于/etc/profile,然后再读取~/.bash_profile
如果在未配置全局的配置文件的情形下,会收到以下提示:
[warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.

a、全局配置文件样本
如:/etc/masterha_default.cnf
[server default]
user=root
password=rootpass
ssh_user=root

#mysql 数据库master节点binlog的位置,该参数用于当master节点死掉后通过ssh方式顺序读取binlog event
#该参数需要配置,因为master节点死掉后无法通过replication机制来自动获取binlog日志位置
#以下为rpm安装方式缺省binlog位置,应根据情形做相应调整
master_binlog_dir= /var/lib/mysql
remote_workdir=/data/log/masterha

#用于检测各节点间的连接性,此处详细可参考MHA parameters描述部分
secondary_check_script= masterha_secondary_check -s remote_host1 -s remote_host2
ping_interval=3

#定义用于实现VIP漂移的脚本,后面的是shutdown以及report脚本
master_ip_failover_script=/script/masterha/master_ip_failover
shutdown_script= /script/masterha/power_manager
report_script= /script/masterha/send_master_failover_mail

b、各MHA单独配置样本
以下为2套不同应用对应的MHA配置文件,如下
app1:
  manager_host$ cat /etc/app1.cnf

  [server default]
  manager_workdir=/var/log/masterha/app1      #工作目录      Author:Leshami
  manager_log=/var/log/masterha/app1/app1.log  #日志文件 Blog  :
 
  [server1]
  hostname=host1
  candidate_master=1
 
  [server2]
  hostname=host2
  candidate_master=1
 
  [server3]
  hostname=host3
 
  [server4]
  hostname=host4
  no_master=1

app2:
  manager_host$ cat /etc/app2.cnf

  [server default]
  manager_workdir=/var/log/masterha/app2
  manager_log=/var/log/masterha/app2/app2.log
 
  [server1]
  hostname=host11
  candidate_master=1
 
  [server2]
  hostname=host12
  candidate_master=1
 
  [server3]
  hostname=host13
 
  [server4]
  hostname=host14
  no_master=1

注:对于上述配置,如果各应用配置与全局配置不同,应用配置具有最高优先级,即相同的项,,应用配置的值会替换掉全局配置的值

 

3、Binlog server
该功能自被MHA 0.56版支持。即可以定义[binlogN]选项。在这个部分,可以定义mysqlbinlog streaming servers.
如果开启了GTID,则MHA会检查binlog服务器,且binlog服务器日志在其他从节点日志之前,则MHA会在恢复之前从binlog服务器apply差量日志
如果未开启GTID,则MHA 忽略 binlog servers。如下样本:

manager_host$ cat /etc/app1.cnf
 
  [server default]
  # mysql user and password
  user=root
  password=mysqlpass
 
  # working directory on the manager
  manager_workdir=/var/log/masterha/app1
 
  # manager log file
  manager_log=/var/log/masterha/app1/app1.log
  # working directory on MySQL servers
  remote_workdir=/var/log/masterha/app1
 
  [server1]
  hostname=host1
 
  [server2]
  hostname=host2
 
  [server3]
  hostname=host3

  [binlog1]
  hostname=binlog_host1

  [binlog2]
  hostname=binlog_host2
 
参考:Writing an application configuration file

本文永久更新链接地址

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
When should you use a composite index versus multiple single-column indexes?When should you use a composite index versus multiple single-column indexes?Apr 11, 2025 am 12:06 AM

In database optimization, indexing strategies should be selected according to query requirements: 1. When the query involves multiple columns and the order of conditions is fixed, use composite indexes; 2. When the query involves multiple columns but the order of conditions is not fixed, use multiple single-column indexes. Composite indexes are suitable for optimizing multi-column queries, while single-column indexes are suitable for single-column queries.

How to identify and optimize slow queries in MySQL? (slow query log, performance_schema)How to identify and optimize slow queries in MySQL? (slow query log, performance_schema)Apr 10, 2025 am 09:36 AM

To optimize MySQL slow query, slowquerylog and performance_schema need to be used: 1. Enable slowquerylog and set thresholds to record slow query; 2. Use performance_schema to analyze query execution details, find out performance bottlenecks and optimize.

MySQL and SQL: Essential Skills for DevelopersMySQL and SQL: Essential Skills for DevelopersApr 10, 2025 am 09:30 AM

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

Describe MySQL asynchronous master-slave replication process.Describe MySQL asynchronous master-slave replication process.Apr 10, 2025 am 09:30 AM

MySQL asynchronous master-slave replication enables data synchronization through binlog, improving read performance and high availability. 1) The master server record changes to binlog; 2) The slave server reads binlog through I/O threads; 3) The server SQL thread applies binlog to synchronize data.

MySQL: Simple Concepts for Easy LearningMySQL: Simple Concepts for Easy LearningApr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

MySQL: A User-Friendly Introduction to DatabasesMySQL: A User-Friendly Introduction to DatabasesApr 10, 2025 am 09:27 AM

The installation and basic operations of MySQL include: 1. Download and install MySQL, set the root user password; 2. Use SQL commands to create databases and tables, such as CREATEDATABASE and CREATETABLE; 3. Execute CRUD operations, use INSERT, SELECT, UPDATE, DELETE commands; 4. Create indexes and stored procedures to optimize performance and implement complex logic. With these steps, you can build and manage MySQL databases from scratch.

How does the InnoDB Buffer Pool work and why is it crucial for performance?How does the InnoDB Buffer Pool work and why is it crucial for performance?Apr 09, 2025 am 12:12 AM

InnoDBBufferPool improves the performance of MySQL databases by loading data and index pages into memory. 1) The data page is loaded into the BufferPool to reduce disk I/O. 2) Dirty pages are marked and refreshed to disk regularly. 3) LRU algorithm management data page elimination. 4) The read-out mechanism loads the possible data pages in advance.

MySQL: The Ease of Data Management for BeginnersMySQL: The Ease of Data Management for BeginnersApr 09, 2025 am 12:07 AM

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

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)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.