Home Database Mysql Tutorial MySQL-MMM的负载均衡及高可用

MySQL-MMM的负载均衡及高可用

Jun 07, 2016 pm 05:25 PM
mysql load balancing High availability

用途mmm是基于信息探测方式进行mysql主从复制架构的监测与故障转移mmm可以做到负载均衡,100%的数据可用性mmm所涉及的检查项服务器可达性,服务可达性,复制线程可

用途
 mmm是基于信息探测方式进行mysql主从复制架构的监测与故障转移
 mmm可以做到负载均衡,100%的数据可用性
 mmm所涉及的检查项   服务器可达性,服务可达性,复制线程可控性

 如图: 当 master1在宕机时, mmm可以将之前分摊的流量进行转移,甚至于将从服务器提升为主

延续双主模型.

wKioL1NT5nvQXXy2AADZ8aMp5QU075.jpg


mmm-agent端状态一览
   online 节点可用
   replication_delay 复制延迟或无法进行(检查req_backlog文件)
   replication_fail 复制失败
   awating_recovery 等待恢复
   hard_offline  主机离线
   admin_offline  主控端离线
   unknown  未知错误

规划如下
172.16.43.200  主控机器负责监测与资源的管理
172.16.43.1  vip(172.16.43.11)  master1 主主复制第一台(可读写)
172.16.43.2  vip(172.16.43.12)  master2 主主复制第二台(只读)
172.16.43.3  vip(172.16.43.13)  slave   主从方式复制 1 , 2 的信息(只读)


实验过程如下

主控安装安装: ansible, mysql客户端, mysql-mmm
集群节点安装如下: mariadb, mysql-agent


i)  主机互信,ansible部署的关键

yum -y install ansible-1.5.4-1.el6.noarch.rpm vim /etc/ansible/hosts # 主控节点完成 [masterserver] master1.king.com master2.king.com . [slaveserver] slave.king.com # 主控节点完成互信多个被管理节点不重复了 ssh-keygen -t rsa ssh-copy-id -i .ssh/id_rsa.pub root@slave.king.com . # 主控节点完成安装mysql-mmm* yum -y install mysql mysql-mmm* . # 实现mmm配置文件有两种 # 1. 主控端 mmm_common, mmm_mon # 2. 集群端 mmm_common, mmm_agent # 主控端配置common /etc/mysql-mmm/mmm_common.conf active_master_role writer . cluster_interface eth0 pid_path /var/run/mysql-mmm/mmm_agentd.pid bin_path /usr/sbin replication_user repl replication_password repl agent_user mmm_agent agent_password agent_password . ip 172.16.43.1 mode master peer master2 . ip 172.16.43.2 mode master peer master1 . ip 172.16.43.3 mode slave . # 谁能写 vip是多少(参照本文配置) hosts master1, master2 ips 172.16.43.11 mode exclusive . # 谁能读 vip是多少(参照本文配置) hosts master1, master2 ips 172.16.43.11, 172.16.43.12, 172.16.43.13 mode balanced . # 主控节点完成 vim /etc/mysql-mmm/mmm_mon.conf # 需要改 ping_ips, 把你想监控的集群加入进入就可以了 # 172.16.0.1 是网关ip ping_ips 172.16.0.1, 172.16.43.1, 172.16.43.2, 172.16.43.3 . monitor_user mmm_monitor monitor_password monitor_password

ii) 安装 mariadb, mysql-agent安装与配置

# 编写 install.yaml, 使用ansible-playbook执行按成安装配置 - hosts: masterserver:slaveserver remote_user: root tasks: - name: mariadb install copy: src=/root/mariadb-10.0.10-linux-x86_64.tar.gz dest=/tmp - name: conf service command: tar xf /tmp/mariadb-10.0.10-linux-x86_64.tar.gz -C /usr/local ############################################################### # 见谅下面的 name: x , 写了半天才知道不能在一个name中包含多个command,所以.. # ############################################################### - name: 1 command: ln -sv /usr/local/mariadb-10.0.10-linux-x86_64 /usr/local/mysql - name: 2 command: cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld - name: 3 command: chmod +x /etc/rc.d/init.d/mysqld - name: 4 command: mkdir /mydata/data -p - name: 5 command: mkdir /mydata/binlogs -p - name: 6 command: mkdir /mydata/relaylogs -p - name: 7 command: useradd -r -s /sbin/nologin mysql -U - name: 8 command: chown mysql.mysql /mydata -R - name: 9 command: chown mysql.mysql /usr/local/mysql -R - name: 9-1 # 将本地配置好的安装文件移植到集群节点, 解压的配置文件可能不符合要求 copy: src=/usr/local/mysql/scripts/mysql_install_db dest=/usr/local/mysql/scripts/ - name: 10 command: /usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/mydata/data - name: mariadb conf # 此处配置文件 /etc/my.cnf 配置好 # log-bin=/mydata/binlogs/mysql-bin # relay-log=/mydata/relaylogs/relay-bin # datadir=/mydata/data copy: src=/etc/my.cnf dest=/etc/my.cnf notify: - restart mariadb - name: install mysql-mmm-agent yum: name=mysql-mmm-agent state=present - name: conf mysql-mmm-agent copy: src=/etc/mysql-mmm/mmm_common.conf dest=/etc/mysql-mmm - name: modify mmm_agent.conf command: sed -i 's@^\(this[[:space:]]\).*@\1{{ item }}@' /etc/mysql-mmm/mmm_agent.conf with_items: - master1 - master2 - slave - name: 11 command: sed -i 's@^\(ENABLED=\).*@\11@' /etc/default/mysql-mmm-agent handlers: - name: restart mariadb service: name=mysqld state=restarted

wKioL1NT2rTwIXu9AAZvuvT0Nhc295.jpg


不熟yaml的童鞋可以 yaml.org


Statement of this Website
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

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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP's big data structure processing skills PHP's big data structure processing skills May 08, 2024 am 10:24 AM

Big data structure processing skills: Chunking: Break down the data set and process it in chunks to reduce memory consumption. Generator: Generate data items one by one without loading the entire data set, suitable for unlimited data sets. Streaming: Read files or query results line by line, suitable for large files or remote data. External storage: For very large data sets, store the data in a database or NoSQL.

How to optimize MySQL query performance in PHP? How to optimize MySQL query performance in PHP? Jun 03, 2024 pm 08:11 PM

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to insert data into a MySQL table using PHP? How to insert data into a MySQL table using PHP? Jun 02, 2024 pm 02:26 PM

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values ​​to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

Application of load balancing strategy in Java framework performance optimization Application of load balancing strategy in Java framework performance optimization May 31, 2024 pm 08:02 PM

Load balancing strategies are crucial in Java frameworks for efficient distribution of requests. Depending on the concurrency situation, different strategies have different performance: Polling method: stable performance under low concurrency. Weighted polling method: The performance is similar to the polling method under low concurrency. Least number of connections method: best performance under high concurrency. Random method: simple but poor performance. Consistent Hashing: Balancing server load. Combined with practical cases, this article explains how to choose appropriate strategies based on performance data to significantly improve application performance.

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

How to use MySQL stored procedures in PHP? How to use MySQL stored procedures in PHP? Jun 02, 2024 pm 02:13 PM

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

How to create a MySQL table using PHP? How to create a MySQL table using PHP? Jun 04, 2024 pm 01:57 PM

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

See all articles