Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6818751
  • 博文数量: 1662
  • 博客积分: 16831
  • 博客等级: 上将
  • 技术积分: 12554
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-25 07:23
个人简介

柔中带刚,刚中带柔,淫荡中富含柔和,刚猛中荡漾风骚,无坚不摧,无孔不入!

文章分类

全部博文(1662)

文章存档

2021年(8)

2020年(24)

2019年(4)

2018年(19)

2017年(66)

2016年(60)

2015年(49)

2014年(201)

2013年(221)

2012年(638)

2011年(372)

分类: Mysql/postgreSQL

2013-07-01 13:30:38

mysql-mmm集群(多实例) 2013-06-29 17:49:53
原创作品,允许转载,转载时请务必以超链接形式标明文章 、作者信息和本声明。否则将追究法律责任。http://navyaijm.blog.51cto.com/4647068/1232737

一、需求说明

最近一直在学习mysql-mmm,想以后这个架构也能用在我们公司的业务上,我们公司的业务是单机多实例部署,所以也想把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
PS:db1和db2上分别有两个库navy2和navy3,互为主主,172.28.26.107是navy2的写入虚拟IP,172.28.26.108是navy2的读虚拟IP,172.28.26.109是navy2的写入虚拟IP,172.28.26.110是navy3的读虚拟IP。
三、部署
1、mysql和mysql-mmm的安装及mysql的主从配置请查看前面的博文:http://navyaijm.blog.51cto.com/4647068/1230674,这里只介绍mmm多实例配置。
2、db1上:
vi /etc/mysql-mmm/mmm_common_navy2.conf(navy2的配置文件)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
vi /etc/mysql-mmm/mmm_common_navy2.conf
active_master_role      writer
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
ip      172.28.26.101
mysql_port              3307
mode    master
peer    db2
ip      172.28.26.102
mysql_port              3307
mode    master
peer    db1
hosts   db1, db2
ips     172.28.26.107
mode    exclusive
hosts   db1, db2
ips     172.28.26.108
mode    balanced
vi /etc/mysql-mmm/mmm_common_navy3.conf(navy3的配置文件)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
active_master_role      writer
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
ip      172.28.26.101
mysql_port              3308
mode    master
peer    db2
ip      172.28.26.102
mysql_port              3308
mode    master
peer    db1
hosts   db1, db2
ips     172.28.26.109
mode    exclusive
hosts   db1, db2
ips     172.28.26.110
mode    balanced
vi /etc/mysql-mmm/mmm_agent_navy2.conf(navy2的agent配置文件)
1
2
include mmm_common_navy2.conf
this db1
vi /etc/mysql-mmm/mmm_agent_navy3.conf(navy3的agent配置文件)
1
2
include mmm_common_navy3.conf
this db1
vi /etc/init.d/mysql-mmm-agent-navy2(navy2的agent启动脚本)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/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
赋予执行权限:
1
chmod +x /etc/init.d/mysql-mmm-agent-navy2
vi /etc/init.d/mysql-mmm-agent-navy3(navy3的agent启动脚本)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/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

赋予可执行权限:

1
chmod +x /etc/init.d/mysql-mmm-agent-navy3

启动服务:
1
2
/etc/init.d/mysql-mmm-agent-navy2 start
/etc/init.d/mysql-mmm-agent-navy3 start
3、db2上:
复制db1上的文件到相应的目录下:
1
2
3
4
5
6
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配置文件:
1
2
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
赋予可执行权限:
1
2
chmod +x /etc/init.d/mysql-mmm-agent-navy2
chmod +x /etc/init.d/mysql-mmm-agent-navy3
启动服务:
1
2
/etc/init.d/mysql-mmm-agent-navy2 start
/etc/init.d/mysql-mmm-agent-navy3 start
4、monitor上
复制db1上的配置文件:
1
2
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
include mmm_common_navy2.conf
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_user        mmm_monitor
monitor_password    123456
debug 0
vi /etc/mysql-mmm/mmm_mon_navy3.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
include mmm_common_navy3.conf
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_user        mmm_monitor
monitor_password    123456
debug 0
vi /etc/mysql-mmm/mmm_mon_log_navy2.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#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 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/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
赋予可执行权限:
1
2
chmod +x /etc/init.d/mysql-mmm-monitor-navy2
chmod +x /etc/init.d/mysql-mmm-monitor-navy3
启动监控服务:
1
2
/etc/init.d/mysql-mmm-monitor-navy2 start
/etc/init.d/mysql-mmm-monitor-navy3 start
结果:
1
2
3
4
5
6
7
8
9
10
11
12
[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 ~]#
阅读(1473) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~