用途mmm是基于信息探测方式进行mysql主从复制架构的监测与故障转移mmm可以做到负载均衡,100%的数据可用性mmm所涉及的检查项服务器可达性,服务可达性,复制线程可
用途
mmm是基于信息探测方式进行mysql主从复制架构的监测与故障转移
mmm可以做到负载均衡,100%的数据可用性
mmm所涉及的检查项 服务器可达性,服务可达性,复制线程可控性
如图: 当 master1在宕机时, mmm可以将之前分摊的流量进行转移,甚至于将从服务器提升为主
延续双主模型.
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
不熟yaml的童鞋可以 yaml.org