当前位置:Gxlcms > mysql > mysql-mmm集群(多实例)

mysql-mmm集群(多实例)

时间:2021-07-01 10:21:17 帮助过:45人阅读

一、需求说明最近一直在学习mysql-mmm,想以后这个架构也能用在我们公司的业务上,我们公司的业务是单机多实例部署,所以也想把mysql-mmm部署成这样,功夫不负有

三、部署

1、mysql和mysql-mmm的安装及mysql的主从配置请查看前面的博文:,美国空间,网站空间,这里只介绍mmm多实例配置。

2、db1上:

vi /etc/mysql-mmm/mmm_common_navy2.conf(navy2的配置文件)

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的配置文件)

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配置文件)

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

3、db2上:

复制db1上的文件到相应的目录下:

人气教程排行