首页 > 代码库 > [转](多实例)mysql-mmm集群
[转](多实例)mysql-mmm集群
一、需求说明
最近一直在学习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 vi /etc/mysql-mmm/mmm_common_navy2.conf 2 active_master_role writer 3 <host default> 4 cluster_interface eth1 5 agent_port 9912 6 mysql_port 3307 7 pid_path /var/run/mysql-mmm/mmm_agentd_navy2.pid 8 bin_path /usr/libexec/mysql-mmm/ 9 replication_user slave10 replication_password 12345611 agent_user mmm_agent12 agent_password 12345613 </host>14 <host db1>15 ip 172.28.26.10116 mysql_port 330717 mode master18 peer db219 </host>20 <host db2>21 ip 172.28.26.10222 mysql_port 330723 mode master24 peer db125 </host>26 <role writer>27 hosts db1, db228 ips 172.28.26.10729 mode exclusive30 </role>31 <role reader>32 hosts db1, db233 ips 172.28.26.10834 mode balanced35 </role>
vi /etc/mysql-mmm/mmm_common_navy3.conf(navy的配置文件)
1 active_master_role writer 2 <host default> 3 cluster_interface eth1 4 agent_port 9913 5 mysql_port 3308 6 pid_path /var/run/mysql-mmm/mmm_agentd_navy3.pid 7 bin_path /usr/libexec/mysql-mmm/ 8 replication_user slave 9 replication_password 12345610 agent_user mmm_agent11 agent_password 12345612 </host>13 <host db1>14 ip 172.28.26.10115 mysql_port 330816 mode master17 peer db218 </host>19 <host db2>20 ip 172.28.26.10221 mysql_port 330822 mode master23 peer db124 </host>25 <role writer>26 hosts db1, db227 ips 172.28.26.10928 mode exclusive29 </role>30 <role reader>31 hosts db1, db232 ips 172.28.26.11033 mode balanced34 </role>
vi /etc/mysql-mmm/mmm_agent_navy2.conf(navy2的agent配置文件)
1 include mmm_common_navy2.conf2 this db1
vi /etc/mysql-mmm/mmm_agent_navy3.conf(navy3的agent配置文件)
1 include mmm_common_navy3.conf2 this db1
vi /etc/init.d/mysql-mmm-agent-navy2(navy2的agent启动脚本)
1 #!/bin/sh 2 # chkconfig: - 64 36 3 # description: MMM Agent. 4 # processname: mmm_agentd 5 # config: /etc/mysql-mmm/mmm_agent.conf 6 # pidfile: /var/run/mysql-mmm/mmm_agentd.pid 7 # Source function library and defaults file. 8 . /etc/rc.d/init.d/functions 9 . /etc/default/mysql-mmm-agent10 # Cluster name (it can be empty for default cases)11 CLUSTER=‘navy2‘12 LOCKFILE=‘/var/lock/subsys/mysql-mmm-agent_navy2‘13 prog=‘MMM Agent Daemon‘14 #-----------------------------------------------------------------------15 # Paths16 if [ "$CLUSTER" != "" ]; then17 MMMD_AGENT_BIN="/usr/sbin/mmm_agentd @$CLUSTER"18 MMMD_AGENT_PIDFILE="/var/run/mysql-mmm/mmm_agentd_$CLUSTER.pid"19 else20 MMMD_AGENT_BIN="/usr/sbin/mmm_agentd"21 MMMD_AGENT_PIDFILE="/var/run/mysql-mmm/mmm_agentd.pid"22 fi23 start() {24 if [ "${ENABLED}" != "1" ]; then25 echo "$prog is disabled!"26 exit 127 fi28 echo -n "Starting $prog: "29 if [ -s $MMMD_AGENT_PIDFILE ] && kill -0 `cat $MMMD_AGENT_PIDFILE` 2> /dev/null; then30 echo " already running."31 exit 032 fi33 daemon $MMMD_AGENT_BIN34 RETVAL=$?35 echo36 [ $RETVAL = 0 ] && touch $LOCKFILE37 return $RETVAL38 }39 stop() {40 # Stop daemon.41 echo -n "Stopping $prog: "42 killproc -p $MMMD_AGENT_PIDFILE $MMMD_AGENT_BIN43 RETVAL=$?44 echo45 [ $RETVAL = 0 ] && rm -f $LOCKFILE46 return $RETVAL47 }48 case "$1" in49 start)50 start51 ;;52 stop)53 stop54 ;;55 status)56 status -p $MMMD_AGENT_PIDFILE $MMMD_AGENT_BIN57 RETVAL=$?58 ;;59 restart|reload)60 stop61 start62 ;;63 condrestart)64 if [ -f $LOCKFILE ]; then65 stop66 start67 fi68 ;;69 *)70 echo "Usage: $0 {start|stop|restart|condrestart|status}"71 ;;72 esac73 exit $RETVAL
赋予执行权限:
1 chmod +x /etc/init.d/mysql-mmm-agent-navy2
vi /etc/init.d/mysql-mmm-agent-navy3(navy3的agent启动脚本)
1 #!/bin/sh 2 # chkconfig: - 64 36 3 # description: MMM Agent. 4 # processname: mmm_agentd 5 # config: /etc/mysql-mmm/mmm_agent.conf 6 # pidfile: /var/run/mysql-mmm/mmm_agentd.pid 7 # Source function library and defaults file. 8 . /etc/rc.d/init.d/functions 9 . /etc/default/mysql-mmm-agent10 ## Paths11 #MMMD_AGENT_BIN="/usr/sbin/mmm_agentd"12 #MMMD_AGENT_PIDFILE="/var/run/mysql-mmm/mmm_agentd.pid"13 #LOCKFILE=‘/var/lock/subsys/mysql-mmm-agent‘14 #prog=‘MMM Agent Daemon‘15 # Cluster name (it can be empty for default cases)16 CLUSTER=‘navy3‘17 LOCKFILE=‘/var/lock/subsys/mysql-mmm-agent_navy3‘18 prog=‘MMM Agent Daemon‘19 #-----------------------------------------------------------------------20 # Paths21 if [ "$CLUSTER" != "" ]; then22 MMMD_AGENT_BIN="/usr/sbin/mmm_agentd @$CLUSTER"23 MMMD_AGENT_PIDFILE="/var/run/mysql-mmm/mmm_agentd_$CLUSTER.pid"24 else25 MMMD_AGENT_BIN="/usr/sbin/mmm_agentd"26 MMMD_AGENT_PIDFILE="/var/run/mysql-mmm/mmm_agentd.pid"27 fi28 start() {29 if [ "${ENABLED}" != "1" ]; then30 echo "$prog is disabled!"31 exit 132 fi33 echo -n "Starting $prog: "34 if [ -s $MMMD_AGENT_PIDFILE ] && kill -0 `cat $MMMD_AGENT_PIDFILE` 2> /dev/null; then35 echo " already running."36 exit 037 fi38 daemon $MMMD_AGENT_BIN39 RETVAL=$?40 echo41 [ $RETVAL = 0 ] && touch $LOCKFILE42 return $RETVAL43 }44 stop() {45 # Stop daemon.46 echo -n "Stopping $prog: "47 killproc -p $MMMD_AGENT_PIDFILE $MMMD_AGENT_BIN48 RETVAL=$?49 echo50 [ $RETVAL = 0 ] && rm -f $LOCKFILE51 return $RETVAL52 }53 case "$1" in54 start)55 start56 ;;57 stop)58 stop59 ;;60 status)61 status -p $MMMD_AGENT_PIDFILE $MMMD_AGENT_BIN62 RETVAL=$?63 ;;64 restart|reload)65 stop66 start67 ;;68 condrestart)69 if [ -f $LOCKFILE ]; then70 stop71 start72 fi73 ;;74 *)75 echo "Usage: $0 {start|stop|restart|condrestart|status}"76 ;;77 esac78 exit $RETVAL
赋予可执行权限:
1 chmod +x /etc/init.d/mysql-mmm-agent-navy3
启动服务:
1 /etc/init.d/mysql-mmm-agent-navy2 start2 /etc/init.d/mysql-mmm-agent-navy3 start
3、db2上:
复制db1上的文件到相应的目录下:
1 scp /etc/mysql-mmm/mmm_common_navy2.conf 172.28.26.102:/etc/mysql-mmm/2 scp /etc/mysql-mmm/mmm_common_navy3.conf 172.28.26.102:/etc/mysql-mmm/3 scp /etc/mysql-mmm/mmm_agent_navy2.conf 172.28.26.102:/etc/mysql-mmm/4 scp /etc/mysql-mmm/mmm_agent_navy3.conf 172.28.26.102:/etc/mysql-mmm/5 scp /etc/init.d/mysql-mmm-agent-navy2 172.28.26.102:/etc/init.d/6 scp /etc/init.d/mysql-mmm-agent-navy3 172.28.26.102:/etc/init.d/
修改agent配置文件:
1 sed -i ‘s/this db1/this db2/‘ /etc/mysql-mmm/mmm_agent_navy2.conf2 sed -i ‘s/this db1/this db2/‘ /etc/mysql-mmm/mmm_agent_navy3.conf
赋予可执行权限
1 chmod +x /etc/init.d/mysql-mmm-agent-navy22 chmod +x /etc/init.d/mysql-mmm-agent-navy3
启动服务:
1 /etc/init.d/mysql-mmm-agent-navy2 start2 /etc/init.d/mysql-mmm-agent-navy3 start
4、monitor上
复制db1上的配置文件:
1 scp /etc/mysql-mmm/mmm_common_navy2.conf 172.28.26.103:/etc/mysql-mmm/2 scp /etc/mysql-mmm/mmm_common_navy3.conf 172.28.26.103:/etc/mysql-mmm/
vi /etc/mysql-mmm/mmm_mon_navy2.conf
1 include mmm_common_navy2.conf 2 <monitor> 3 ip 127.0.0.1 4 port 9992 5 pid_path /var/run/mysql-mmm/mmm_mond_navy2.pid 6 bin_path /usr/libexec/mysql-mmm 7 status_path /var/lib/mysql-mmm/mmm_mond_navy2.status 8 ping_ips 172.28.26.101,172.28.26.102 9 auto_set_online 1010 # wait_for_other_master 211 # The kill_host_bin does not exist by default, though the monitor will12 # throw a warning about it missing. See the section 5.10 "Kill Host13 # Functionality" in the PDF documentation.14 #15 # kill_host_bin /usr/libexec/mysql-mmm/monitor/kill_host16 #17 </monitor>18 <host default>19 monitor_user mmm_monitor20 monitor_password 12345621 </host>22 debug 0
vi /etc/mysql-mmm/mmm_mon_navy3.conf
1 include mmm_common_navy3.conf 2 <monitor> 3 ip 127.0.0.1 4 port 9993 5 pid_path /var/run/mysql-mmm/mmm_mond_navy3.pid 6 bin_path /usr/libexec/mysql-mmm 7 status_path /var/lib/mysql-mmm/mmm_mond_navy3.status 8 ping_ips 172.28.26.101,172.28.26.102 9 auto_set_online 1010 # wait_for_other_master 211 # The kill_host_bin does not exist by default, though the monitor will12 # throw a warning about it missing. See the section 5.10 "Kill Host13 # Functionality" in the PDF documentation.14 #15 # kill_host_bin /usr/libexec/mysql-mmm/monitor/kill_host16 #17 </monitor>18 <host default>19 monitor_user mmm_monitor20 monitor_password 12345621 </host>22 debug 0
vi /etc/mysql-mmm/mmm_mon_log_navy2.conf
1 #log4perl.logger = FATAL, MMMLog, MailFatal 2 log4perl.logger = FATAL, MMMLog 3 log4perl.appender.MMMLog = Log::Log4perl::Appender::File 4 log4perl.appender.MMMLog.Threshold = INFO 5 log4perl.appender.MMMLog.filename = /var/log/mysql-mmm/mmm_mond_navy2.log 6 log4perl.appender.MMMLog.recreate = 1 7 log4perl.appender.MMMLog.layout = PatternLayout 8 log4perl.appender.MMMLog.layout.ConversionPattern = %d %5p %m%n 9 #log4perl.appender.MailFatal = Log::Dispatch::Email::MailSender10 #log4perl.appender.MailFatal.Threshold = FATAL11 #log4perl.appender.MailFatal.from = mmm@example.com12 #log4perl.appender.MailFatal.to = root13 #log4perl.appender.MailFatal.buffered = 014 #log4perl.appender.MailFatal.subject = FATAL error in mysql-mmm-monitor15 #log4perl.appender.MailFatal.layout = PatternLayout16 #log4perl.appender.MailFatal.layout.ConversionPattern = %d %m%n
vi /etc/mysql-mmm/mmm_mon_log_navy3.conf
1 #log4perl.logger = FATAL, MMMLog, MailFatal 2 log4perl.logger = FATAL, MMMLog 3 log4perl.appender.MMMLog = Log::Log4perl::Appender::File 4 log4perl.appender.MMMLog.Threshold = INFO 5 log4perl.appender.MMMLog.filename = /var/log/mysql-mmm/mmm_mond_navy3.log 6 log4perl.appender.MMMLog.recreate = 1 7 log4perl.appender.MMMLog.layout = PatternLayout 8 log4perl.appender.MMMLog.layout.ConversionPattern = %d %5p %m%n 9 #log4perl.appender.MailFatal = Log::Dispatch::Email::MailSender10 #log4perl.appender.MailFatal.Threshold = FATAL11 #log4perl.appender.MailFatal.from = mmm@example.com12 #log4perl.appender.MailFatal.to = root13 #log4perl.appender.MailFatal.buffered = 014 #log4perl.appender.MailFatal.subject = FATAL error in mysql-mmm-monitor15 #log4perl.appender.MailFatal.layout = PatternLayout16 #log4perl.appender.MailFatal.layout.ConversionPattern = %d %m%n
vi /etc/init.d/mysql-mmm-monitor-navy2
1 #!/bin/sh 2 # 3 # mysql-mmm-monitor This shell script takes care of starting and stopping 4 # the mmm monitoring daemon. 5 # 6 # chkconfig: - 64 36 7 # description: MMM Monitor. 8 # processname: mmm_mond 9 # config: /etc/mysql-mmm/mmm_mon.conf10 # pidfile: /var/run/mysql-mmm/mmm_mond.pid11 # Source function library and defaults file.12 . /etc/rc.d/init.d/functions13 . /etc/default/mysql-mmm-monitor14 # Cluster name (it can be empty for default cases)15 CLUSTER=‘navy2‘16 LOCKFILE=‘/var/lock/subsys/mysql-mmm-monitor_navy2‘17 prog=‘MMM Monitor Daemon‘18 if [ "$CLUSTER" != "" ]; then19 MMMD_MON_BIN="/usr/sbin/mmm_mond @$CLUSTER"20 MMMD_MON_PIDFILE="/var/run/mysql-mmm/mmm_mond-$CLUSTER.pid"21 else22 MMMD_MON_BIN="/usr/sbin/mmm_mond"23 MMMD_MON_PIDFILE="/var/run/mysql-mmm/mmm_mond.pid"24 fi25 start() {26 if [ "${ENABLED}" != "1" ]; then27 echo "$prog is disabled!"28 exit 129 fi30 echo -n "Starting $prog: "31 if [ -s $MMMD_MON_PIDFILE ] && kill -0 `cat $MMMD_MON_PIDFILE` 2> /dev/null; then32 echo " already running."33 exit 034 fi35 daemon $MMMD_MON_BIN36 RETVAL=$?37 echo38 [ $RETVAL = 0 ] && touch $LOCKFILE39 return $RETVAL40 }41 stop() {42 # Stop daemon.43 echo -n "Stopping $prog: "44 killproc -p $MMMD_MON_PIDFILE $MMMD_MON_BIN45 RETVAL=$?46 echo47 [ $RETVAL = 0 ] && rm -f $LOCKFILE48 return $RETVAL49 }50 case "$1" in51 start)52 start53 ;;54 stop)55 stop56 ;;57 status)58 status -p $MMMD_MON_PIDFILE $MMMD_MON_BIN59 RETVAL=$?60 ;;61 restart|reload)62 stop63 start64 ;;65 condrestart)66 if [ -f $LOCKFILE ]; then67 stop68 start69 fi70 ;;71 *)72 echo "Usage: $0 {start|stop|restart|condrestart|status}"73 ;;74 esac75 exit $RETVAL
vi /etc/init.d/mysql-mmm-monitor-navy3
1 #!/bin/sh 2 # 3 # mysql-mmm-monitor This shell script takes care of starting and stopping 4 # the mmm monitoring daemon. 5 # 6 # chkconfig: - 64 36 7 # description: MMM Monitor. 8 # processname: mmm_mond 9 # config: /etc/mysql-mmm/mmm_mon.conf10 # pidfile: /var/run/mysql-mmm/mmm_mond.pid11 # Source function library and defaults file.12 . /etc/rc.d/init.d/functions13 . /etc/default/mysql-mmm-monitor14 # Cluster name (it can be empty for default cases)15 CLUSTER=‘navy3‘16 LOCKFILE=‘/var/lock/subsys/mysql-mmm-monitor_navy3‘17 prog=‘MMM Monitor Daemon‘18 if [ "$CLUSTER" != "" ]; then19 MMMD_MON_BIN="/usr/sbin/mmm_mond @$CLUSTER"20 MMMD_MON_PIDFILE="/var/run/mysql-mmm/mmm_mond-$CLUSTER.pid"21 else22 MMMD_MON_BIN="/usr/sbin/mmm_mond"23 MMMD_MON_PIDFILE="/var/run/mysql-mmm/mmm_mond.pid"24 fi25 start() {26 if [ "${ENABLED}" != "1" ]; then27 echo "$prog is disabled!"28 exit 129 fi30 echo -n "Starting $prog: "31 if [ -s $MMMD_MON_PIDFILE ] && kill -0 `cat $MMMD_MON_PIDFILE` 2> /dev/null; then32 echo " already running."33 exit 034 fi35 daemon $MMMD_MON_BIN36 RETVAL=$?37 echo38 [ $RETVAL = 0 ] && touch $LOCKFILE39 return $RETVAL40 }41 stop() {42 # Stop daemon.43 echo -n "Stopping $prog: "44 killproc -p $MMMD_MON_PIDFILE $MMMD_MON_BIN45 RETVAL=$?46 echo47 [ $RETVAL = 0 ] && rm -f $LOCKFILE48 return $RETVAL49 }50 case "$1" in51 start)52 start53 ;;54 stop)55 stop56 ;;57 status)58 status -p $MMMD_MON_PIDFILE $MMMD_MON_BIN59 RETVAL=$?60 ;;61 restart|reload)62 stop63 start64 ;;65 condrestart)66 if [ -f $LOCKFILE ]; then67 stop68 start69 fi70 ;;71 *)72 echo "Usage: $0 {start|stop|restart|condrestart|status}"73 ;;74 esac75 exit $RETVAL
赋予可执行权限:
1 chmod +x /etc/init.d/mysql-mmm-monitor-navy22 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
结果
1 [root@monitor ~]# mmm_control show 2 db1(172.28.26.101) master/ONLINE. Roles: writer(172.28.26.104) 3 db2(172.28.26.102) master/ONLINE. Roles: 4 db3(172.28.26.188) slave/ONLINE. Roles: reader(172.28.26.105) 5 db4(172.28.26.189) slave/ONLINE. Roles: reader(172.28.26.106) 6 [root@monitor ~]# mmm_control @navy2 show 7 db1(172.28.26.101) master/ONLINE. Roles: writer(172.28.26.107) 8 db2(172.28.26.102) master/ONLINE. Roles: reader(172.28.26.108) 9 [root@monitor ~]# mmm_control @navy3 show10 db1(172.28.26.101) master/ONLINE. Roles: writer(172.28.26.109)11 db2(172.28.26.102) master/ONLINE. Roles: reader(172.28.26.110)12 [root@monitor ~]#
[转](多实例)mysql-mmm集群
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。