[转]mysql-mmm集群(多实例)
一、需求说明
集群 | 角色 | 主机名 | IP | Mysql Port | Server ID | VIP Writer | VIP READER |
navy2 | Agent | db1 | 172.28.26.101 | 3307 | 11 | 172.28.26.107 | |
navy3 |
Agent
|
db2 | 172.28.26.102 | 3308 | 1 | |
172.28.26.110
|
navy2 |
Agent
|
db1 |
172.28.26.101
|
3307 | 22 | |
172.28.26.108
|
navy3 |
Agent
|
db2 |
172.28.26.102
|
3308 | 2 |
172.28.26.109
|
|
navy2/navy3 | Monitor |
Monitor
|
172.28.26.103
|
| | | |
vi /etc/mysql-mmm/mmm_common_navy2.conf
active_master_role writer
<host default>
cluster_interface eth1
agent_port 9912
mysql_port 3307
pid_path /var/run/mysql-mmm/mmm_agentd_navy2.pid
bin_path /usr/libexec/mysql-mmm/
replication_user slave
replication_password 123456
agent_user mmm_agent
agent_password 123456
</host>
<host db1>
ip 172.28.26.101
mysql_port 3307
mode master
peer db2
</host>
<host db2>
ip 172.28.26.102
mysql_port 3307
mode master
peer db1
</host>
<role writer>
hosts db1, db2
ips 172.28.26.107
mode exclusive
</role>
<role reader>
hosts db1, db2
ips 172.28.26.108
mode balanced
</role>
vi /etc/mysql-mmm/mmm_common_navy3.conf(navy的配置文件)
active_master_role writer
<host default>
cluster_interface eth1
agent_port 9913
mysql_port 3308
pid_path /var/run/mysql-mmm/mmm_agentd_navy3.pid
bin_path /usr/libexec/mysql-mmm/
replication_user slave
replication_password 123456
agent_user mmm_agent
agent_password 123456
</host>
<host db1>
ip 172.28.26.101
mysql_port 3308
mode master
peer db2
</host>
<host db2>
ip 172.28.26.102
mysql_port 3308
mode master
peer db1
</host>
<role writer>
hosts db1, db2
ips 172.28.26.109
mode exclusive
</role>
<role reader>
hosts db1, db2
ips 172.28.26.110
mode balanced
</role>
vi /etc/mysql-mmm/mmm_agent_navy2.conf(navy2的agent配置文件)
include mmm_common_navy2.conf
this db1
vi /etc/mysql-mmm/mmm_agent_navy3.conf(navy3的agent配置文件)
include mmm_common_navy3.conf
this db1
vi /etc/init.d/mysql-mmm-agent-navy2(navy2的agent启动脚本)
#!/bin/sh
# chkconfig: - 64 36
# description: MMM Agent.
# processname: mmm_agentd
# config: /etc/mysql-mmm/mmm_agent.conf
# pidfile: /var/run/mysql-mmm/mmm_agentd.pid
# Source function library and defaults file.
. /etc/rc.d/init.d/functions
. /etc/default/mysql-mmm-agent
# Cluster name (it can be empty for default cases)
CLUSTER='navy2'
LOCKFILE='/var/lock/subsys/mysql-mmm-agent_navy2'
prog='MMM Agent Daemon'
#-----------------------------------------------------------------------
# Paths
if [ "$CLUSTER" != "" ]; then
MMMD_AGENT_BIN="/usr/sbin/mmm_agentd @$CLUSTER"
MMMD_AGENT_PIDFILE="/var/run/mysql-mmm/mmm_agentd_$CLUSTER.pid"
else
MMMD_AGENT_BIN="/usr/sbin/mmm_agentd"
MMMD_AGENT_PIDFILE="/var/run/mysql-mmm/mmm_agentd.pid"
fi
start() {
if [ "${ENABLED}" != "1" ]; then
echo "$prog is disabled!"
exit 1
fi
echo -n "Starting $prog: "
if [ -s $MMMD_AGENT_PIDFILE ] && kill -0 `cat $MMMD_AGENT_PIDFILE` 2> /dev/null; then
echo " already running."
exit 0
fi
daemon $MMMD_AGENT_BIN
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch $LOCKFILE
return $RETVAL
}
stop() {
# Stop daemon.
echo -n "Stopping $prog: "
killproc -p $MMMD_AGENT_PIDFILE $MMMD_AGENT_BIN
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f $LOCKFILE
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p $MMMD_AGENT_PIDFILE $MMMD_AGENT_BIN
RETVAL=$?
;;
restart|reload)
stop
start
;;
condrestart)
if [ -f $LOCKFILE ]; then
stop
start
fi
;;
*)
echo "Usage: $0 {start|stop|restart|condrestart|status}"
;;
esac
exit $RETVAL
赋予执行权限:
chmod +x /etc/init.d/mysql-mmm-agent-navy2
vi /etc/init.d/mysql-mmm-agent-navy3(navy3的agent启动脚本)
#!/bin/sh
# chkconfig: - 64 36
# description: MMM Agent.
# processname: mmm_agentd
# config: /etc/mysql-mmm/mmm_agent.conf
# pidfile: /var/run/mysql-mmm/mmm_agentd.pid
# Source function library and defaults file.
. /etc/rc.d/init.d/functions
. /etc/default/mysql-mmm-agent
## Paths
#MMMD_AGENT_BIN="/usr/sbin/mmm_agentd"
#MMMD_AGENT_PIDFILE="/var/run/mysql-mmm/mmm_agentd.pid"
#LOCKFILE='/var/lock/subsys/mysql-mmm-agent'
#prog='MMM Agent Daemon'
# Cluster name (it can be empty for default cases)
CLUSTER='navy3'
LOCKFILE='/var/lock/subsys/mysql-mmm-agent_navy3'
prog='MMM Agent Daemon'
#-----------------------------------------------------------------------
# Paths
if [ "$CLUSTER" != "" ]; then
MMMD_AGENT_BIN="/usr/sbin/mmm_agentd @$CLUSTER"
MMMD_AGENT_PIDFILE="/var/run/mysql-mmm/mmm_agentd_$CLUSTER.pid"
else
MMMD_AGENT_BIN="/usr/sbin/mmm_agentd"
MMMD_AGENT_PIDFILE="/var/run/mysql-mmm/mmm_agentd.pid"
fi
start() {
if [ "${ENABLED}" != "1" ]; then
echo "$prog is disabled!"
exit 1
fi
echo -n "Starting $prog: "
if [ -s $MMMD_AGENT_PIDFILE ] && kill -0 `cat $MMMD_AGENT_PIDFILE` 2> /dev/null; then
echo " already running."
exit 0
fi
daemon $MMMD_AGENT_BIN
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch $LOCKFILE
return $RETVAL
}
stop() {
# Stop daemon.
echo -n "Stopping $prog: "
killproc -p $MMMD_AGENT_PIDFILE $MMMD_AGENT_BIN
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f $LOCKFILE
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p $MMMD_AGENT_PIDFILE $MMMD_AGENT_BIN
RETVAL=$?
;;
restart|reload)
stop
start
;;
condrestart)
if [ -f $LOCKFILE ]; then
stop
start
fi
;;
*)
echo "Usage: $0 {start|stop|restart|condrestart|status}"
;;
esac
exit $RETVAL
赋予可执行权限:
chmod +x /etc/init.d/mysql-mmm-agent-navy3
启动服务:
/etc/init.d/mysql-mmm-agent-navy2 start
/etc/init.d/mysql-mmm-agent-navy3 start
scp /etc/mysql-mmm/mmm_common_navy2.conf 172.28.26.102:/etc/mysql-mmm/
scp /etc/mysql-mmm/mmm_common_navy3.conf 172.28.26.102:/etc/mysql-mmm/
scp /etc/mysql-mmm/mmm_agent_navy2.conf 172.28.26.102:/etc/mysql-mmm/
scp /etc/mysql-mmm/mmm_agent_navy3.conf 172.28.26.102:/etc/mysql-mmm/
scp /etc/init.d/mysql-mmm-agent-navy2 172.28.26.102:/etc/init.d/
scp /etc/init.d/mysql-mmm-agent-navy3 172.28.26.102:/etc/init.d/
修改agent配置文件:
sed -i 's/this db1/this db2/' /etc/mysql-mmm/mmm_agent_navy2.conf
sed -i 's/this db1/this db2/' /etc/mysql-mmm/mmm_agent_navy3.conf
赋予可执行权限
chmod +x /etc/init.d/mysql-mmm-agent-navy2
chmod +x /etc/init.d/mysql-mmm-agent-navy3
启动服务:
/etc/init.d/mysql-mmm-agent-navy2 start
/etc/init.d/mysql-mmm-agent-navy3 start
scp /etc/mysql-mmm/mmm_common_navy2.conf 172.28.26.103:/etc/mysql-mmm/
scp /etc/mysql-mmm/mmm_common_navy3.conf 172.28.26.103:/etc/mysql-mmm/
vi /etc/mysql-mmm/mmm_mon_navy2.conf
include mmm_common_navy2.conf
<monitor>
ip 127.0.0.1
port 9992
pid_path /var/run/mysql-mmm/mmm_mond_navy2.pid
bin_path /usr/libexec/mysql-mmm
status_path /var/lib/mysql-mmm/mmm_mond_navy2.status
ping_ips 172.28.26.101,172.28.26.102
auto_set_online 10
# wait_for_other_master 2
# The kill_host_bin does not exist by default, though the monitor will
# throw a warning about it missing. See the section 5.10 "Kill Host
# Functionality" in the PDF documentation.
#
# kill_host_bin /usr/libexec/mysql-mmm/monitor/kill_host
#
</monitor>
<host default>
monitor_user mmm_monitor
monitor_password 123456
</host>
debug 0
vi /etc/mysql-mmm/mmm_mon_navy3.conf
include mmm_common_navy3.conf
<monitor>
ip 127.0.0.1
port 9993
pid_path /var/run/mysql-mmm/mmm_mond_navy3.pid
bin_path /usr/libexec/mysql-mmm
status_path /var/lib/mysql-mmm/mmm_mond_navy3.status
ping_ips 172.28.26.101,172.28.26.102
auto_set_online 10
# wait_for_other_master 2
# The kill_host_bin does not exist by default, though the monitor will
# throw a warning about it missing. See the section 5.10 "Kill Host
# Functionality" in the PDF documentation.
#
# kill_host_bin /usr/libexec/mysql-mmm/monitor/kill_host
#
</monitor>
<host default>
monitor_user mmm_monitor
monitor_password 123456
</host>
debug 0
vi /etc/mysql-mmm/mmm_mon_log_navy2.conf
#log4perl.logger = FATAL, MMMLog, MailFatal
log4perl.logger = FATAL, MMMLog
log4perl.appender.MMMLog = Log::Log4perl::Appender::File
log4perl.appender.MMMLog.Threshold = INFO
log4perl.appender.MMMLog.filename = /var/log/mysql-mmm/mmm_mond_navy2.log
log4perl.appender.MMMLog.recreate = 1
log4perl.appender.MMMLog.layout = PatternLayout
log4perl.appender.MMMLog.layout.ConversionPattern = %d %5p %m%n
#log4perl.appender.MailFatal = Log::Dispatch::Email::MailSender
#log4perl.appender.MailFatal.Threshold = FATAL
#log4perl.appender.MailFatal.from = mmm@example.com
#log4perl.appender.MailFatal.to = root
#log4perl.appender.MailFatal.buffered = 0
#log4perl.appender.MailFatal.subject = FATAL error in mysql-mmm-monitor
#log4perl.appender.MailFatal.layout = PatternLayout
#log4perl.appender.MailFatal.layout.ConversionPattern = %d %m%n
vi /etc/mysql-mmm/mmm_mon_log_navy3.conf
#log4perl.logger = FATAL, MMMLog, MailFatal
log4perl.logger = FATAL, MMMLog
log4perl.appender.MMMLog = Log::Log4perl::Appender::File
log4perl.appender.MMMLog.Threshold = INFO
log4perl.appender.MMMLog.filename = /var/log/mysql-mmm/mmm_mond_navy3.log
log4perl.appender.MMMLog.recreate = 1
log4perl.appender.MMMLog.layout = PatternLayout
log4perl.appender.MMMLog.layout.ConversionPattern = %d %5p %m%n
#log4perl.appender.MailFatal = Log::Dispatch::Email::MailSender
#log4perl.appender.MailFatal.Threshold = FATAL
#log4perl.appender.MailFatal.from = mmm@example.com
#log4perl.appender.MailFatal.to = root
#log4perl.appender.MailFatal.buffered = 0
#log4perl.appender.MailFatal.subject = FATAL error in mysql-mmm-monitor
#log4perl.appender.MailFatal.layout = PatternLayout
#log4perl.appender.MailFatal.layout.ConversionPattern = %d %m%n
vi /etc/init.d/mysql-mmm-monitor-navy2
#!/bin/sh
#
# mysql-mmm-monitor This shell script takes care of starting and stopping
# the mmm monitoring daemon.
#
# chkconfig: - 64 36
# description: MMM Monitor.
# processname: mmm_mond
# config: /etc/mysql-mmm/mmm_mon.conf
# pidfile: /var/run/mysql-mmm/mmm_mond.pid
# Source function library and defaults file.
. /etc/rc.d/init.d/functions
. /etc/default/mysql-mmm-monitor
# Cluster name (it can be empty for default cases)
CLUSTER='navy2'
LOCKFILE='/var/lock/subsys/mysql-mmm-monitor_navy2'
prog='MMM Monitor Daemon'
if [ "$CLUSTER" != "" ]; then
MMMD_MON_BIN="/usr/sbin/mmm_mond @$CLUSTER"
MMMD_MON_PIDFILE="/var/run/mysql-mmm/mmm_mond-$CLUSTER.pid"
else
MMMD_MON_BIN="/usr/sbin/mmm_mond"
MMMD_MON_PIDFILE="/var/run/mysql-mmm/mmm_mond.pid"
fi
start() {
if [ "${ENABLED}" != "1" ]; then
echo "$prog is disabled!"
exit 1
fi
echo -n "Starting $prog: "
if [ -s $MMMD_MON_PIDFILE ] && kill -0 `cat $MMMD_MON_PIDFILE` 2> /dev/null; then
echo " already running."
exit 0
fi
daemon $MMMD_MON_BIN
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch $LOCKFILE
return $RETVAL
}
stop() {
# Stop daemon.
echo -n "Stopping $prog: "
killproc -p $MMMD_MON_PIDFILE $MMMD_MON_BIN
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f $LOCKFILE
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p $MMMD_MON_PIDFILE $MMMD_MON_BIN
RETVAL=$?
;;
restart|reload)
stop
start
;;
condrestart)
if [ -f $LOCKFILE ]; then
stop
start
fi
;;
*)
echo "Usage: $0 {start|stop|restart|condrestart|status}"
;;
esac
exit $RETVAL
vi /etc/init.d/mysql-mmm-monitor-navy3
#!/bin/sh
#
# mysql-mmm-monitor This shell script takes care of starting and stopping
# the mmm monitoring daemon.
#
# chkconfig: - 64 36
# description: MMM Monitor.
# processname: mmm_mond
# config: /etc/mysql-mmm/mmm_mon.conf
# pidfile: /var/run/mysql-mmm/mmm_mond.pid
# Source function library and defaults file.
. /etc/rc.d/init.d/functions
. /etc/default/mysql-mmm-monitor
# Cluster name (it can be empty for default cases)
CLUSTER='navy3'
LOCKFILE='/var/lock/subsys/mysql-mmm-monitor_navy3'
prog='MMM Monitor Daemon'
if [ "$CLUSTER" != "" ]; then
MMMD_MON_BIN="/usr/sbin/mmm_mond @$CLUSTER"
MMMD_MON_PIDFILE="/var/run/mysql-mmm/mmm_mond-$CLUSTER.pid"
else
MMMD_MON_BIN="/usr/sbin/mmm_mond"
MMMD_MON_PIDFILE="/var/run/mysql-mmm/mmm_mond.pid"
fi
start() {
if [ "${ENABLED}" != "1" ]; then
echo "$prog is disabled!"
exit 1
fi
echo -n "Starting $prog: "
if [ -s $MMMD_MON_PIDFILE ] && kill -0 `cat $MMMD_MON_PIDFILE` 2> /dev/null; then
echo " already running."
exit 0
fi
daemon $MMMD_MON_BIN
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch $LOCKFILE
return $RETVAL
}
stop() {
# Stop daemon.
echo -n "Stopping $prog: "
killproc -p $MMMD_MON_PIDFILE $MMMD_MON_BIN
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f $LOCKFILE
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p $MMMD_MON_PIDFILE $MMMD_MON_BIN
RETVAL=$?
;;
restart|reload)
stop
start
;;
condrestart)
if [ -f $LOCKFILE ]; then
stop
start
fi
;;
*)
echo "Usage: $0 {start|stop|restart|condrestart|status}"
;;
esac
exit $RETVAL
赋予可执行权限:
chmod +x /etc/init.d/mysql-mmm-monitor-navy2
chmod +x /etc/init.d/mysql-mmm-monitor-navy3
启动监控服务:
/etc/init.d/mysql-mmm-monitor-navy2 start
/etc/init.d/mysql-mmm-monitor-navy3 start
结果
[root@monitor ~]# mmm_control show
db1(172.28.26.101) master/ONLINE. Roles: writer(172.28.26.104)
db2(172.28.26.102) master/ONLINE. Roles:
db3(172.28.26.188) slave/ONLINE. Roles: reader(172.28.26.105)
db4(172.28.26.189) slave/ONLINE. Roles: reader(172.28.26.106)
[root@monitor ~]# mmm_control @navy2 show
db1(172.28.26.101) master/ONLINE. Roles: writer(172.28.26.107)
db2(172.28.26.102) master/ONLINE. Roles: reader(172.28.26.108)
[root@monitor ~]# mmm_control @navy3 show
db1(172.28.26.101) master/ONLINE. Roles: writer(172.28.26.109)
db2(172.28.26.102) master/ONLINE. Roles: reader(172.28.26.110)
[root@monitor ~]#
[转]mysql-mmm集群(多实例)的更多相关文章
- 多图文,详细介绍mysql各个集群方案
目录 多图文,详细介绍mysql各个集群方案 一,mysql原厂出品 二,mysql第三方优化 三,依托硬件配合 四,其它 多图文,详细介绍mysql各个集群方案 集群的好处 高可用性:故障检测及迁移 ...
- MySQL分布式集群之MyCAT(转)
原文地址:http://blog.itpub.net/29510932/viewspace-1664499/ 隔了好久,才想起来更新博客,最近倒腾的数据库从Oracle换成了MySQL,研究了一段时间 ...
- MySQL Cluster 集群
本文转载 http://www.cnblogs.com/gomysql/p/3664783.html MySQL Cluster是一个基于NDB Cluster存储引擎的完整的分布式数据库系统.不仅仅 ...
- 基于keepalived搭建MySQL热机集群
背景 MySQL的高可用方案一般有如下几种: keepalived+双主,MHA,MMM,Heartbeat+DRBD,PXC,Galera Cluster 比较常用的是keepalived+双主,M ...
- MySQL分布式集群之MyCAT(一)简介【转】
隔了好久,才想起来更新博客,最近倒腾的数据库从Oracle换成了MySQL,研究了一段时间,感觉社区版的MySQL在各个方面都逊色于Oracle,Oracle真的好方便!好了,不废话,这次准备记录一些 ...
- mysql各种集群的优缺点
mysql各种集群的优缺点 1.主从架构:只是有数据备份的功能: 2.主主互备+keepalived:实现数据备份加高可用: 3.主主互备,主主下面分别挂个从: 4.A和B主主互备,把从库都挂到B下, ...
- 《综合》MMM集群
<综合>MMM集群 部署集群基础环境 MySQL-MMM架构部署 MySQL-MMM架构使用 1 部署集群基础环境 1.1 问题 本案例要求为MySQL集群准备基础环境,完成以下任务操作: ...
- Shell脚本实现---Swarm集群部署实例(Swarm Cluster)
Shell脚本实现---Swarm集群部署实例(Swarm Cluster) 一.机器环境(均是centos7.8) IP hostname 角色 192.168.10.200 manager-swa ...
- MySQL数据库集群进行正确配置步骤
MySQL数据库集群进行正确配置步骤 2010-06-09 10:47 arrowcat 博客园 字号:T | T 我们今天是要和大家一起分享的是对MySQL数据库集群进行正确配置,我前两天在相关网站 ...
- Facebook揭密:如何让MySQL数据库集群自主运行
Facebook运行着全球最大的MySQL数据库集群,该集群分布在两个大洲上的多个数据中心中数以千计的服务器上.让人不解的是,Facebook只动用了一个很小的团队来管理这个庞大的MySQL数据库集群 ...
随机推荐
- EditPlus 4.3.2543 中文版已经发布(2月3日更新,Emmet 功能回归)
新的 EditPlus 版本修复了 Emmet 组件的安全问题. 现在 Emmet 编辑功能又回来啦. 下载连接在页面左上角!
- Linux基础命令---mktemp
mktemp 创建临时文件或者目录,这样的创建方式是安全的.此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE.Fedora. 1.语法 mk ...
- zookeeper与卡夫卡集群搭建
首先这片博客没有任何理论性的东西,只是详细说明kafka与zookeeper集群的搭建过程,需要三台linux服务器. java环境变量设置 zookeeper集群搭建 kafka集群搭建 java环 ...
- shell中参数及带色彩打印
shell脚本中的一些函数参数说明如下: #!/bin/bash echo 显示参数的个数: $# echo 以单个字符串把每个参数连接起来: $* echo 显示脚本当前运行的进程id: $$ ec ...
- JavaScript中变量提升------Hoisting
原谅链接:http://www.cnblogs.com/damonlan/archive/2012/07/01/2553425.html 因为这个问题很是经典,而且容易出错,所以在介绍一次.哈哈.莫怪 ...
- 20145307陈俊达_安卓逆向分析_APKtools分析smail
20145307陈俊达_安卓逆向分析_APKtools分析smail 引言 真刺激呢!到了第二篇博客了,难度开始加大,之前是简单的dex2jar和有图形界面的jd-gui,现在来隆重介绍强大的反汇编工 ...
- Android实践项目汇报(总结)
天气客户端开发报告 1 系统需求分析 1.1功能性需求分析 天气预报客户端,最基本就是为用户提供准确的天气预报信息.天气查询结果有两种:一种是当天天气信息,信息结果比较详细,除温度.天气状况外还 ...
- 20165310 预备作业3 Linux安装及学习
预备作业3 Linux安装及学习 安装虚拟机 之前在win7系统下通过EasyBCD安装过Ubuntu虚拟机,这次阅读<基于VirtualBox虚拟机安装Ubuntu图文教程>又学习到了一 ...
- codevs 1423 骑士 - Tarjan - 动态规划
题目描述 Description Z国的骑士团是一个很有势力的组织,帮会中汇聚了来自各地的精英.他们劫富济贫,惩恶扬善,受到社会各界的赞扬. 最近发生了一件可怕的事情,邪恶的Y国发动了一场针对Z国的侵 ...
- SC命令---安装、开启、配置、关闭windows服务 bat批处理(转载)
转载:http://www.jb51.net/article/49627.htm 转载:http://blog.csdn.net/c1520006273/article/details/5053905 ...