说明
主从配置在本文档略过,主要是mysql-mmm多实例的部署。文档中涉及的一些基础知识不做详细说明。
节点信息如下:
IP |
主机名 |
角色 |
192.168.0.1 |
db1 |
master1 |
192.168.0.2 | db2 |
master2 |
192.168.0.3 | db3 |
slave1 |
192.168.0.4 | db4 |
slave2 |
192.168.0.5 | db5 |
管理节点 |
1、软件安装
为了简单,本次安装都是通过yum来进行。配置epel的yum源
yum instll mysql-mmm mysql-mmm-agent mysql-mmm-monitor
2、配置
yum安装的mysql-mmm的配置文件路径是在 /etc/mysql-mmm/中,我们需要修改如下几个文件mmm_agent.conf,mmm_common.conf,mmm_mon_log.conf。由于是多实例的部署,所以默认提供的文件将不起作用。我应用中是以mysql的多实例端口,作为配置文件和启动服务的参数。默认安装的mysql-mmm启动命令也需要相应修改,稍后会提供方法。
创建一个slave密码为slave的帐号,用于mysql主从同步,以及mysql-mmm管理和其它使用。
比如:mysql端口为3301,那配置文件为mmm_agent_3301.conf
A>配置文件 【/etc/mysql/mmm_common_3301.conf】 这个文件要在4个节点中都存在
active_master_role writer <host default> cluster_interface bond1 pid_path /var/run/mysql-mmm/mmm_agentd_3301.pid bin_path /usr/libexec/mysql-mmm/ replication_user slave replication_password slave agent_user slave agent_password slave agent_port 43301 </host> <host db1> ip 192.168.0.1 mysql_port 3301 mode master peer db2 </host> <host db2> ip 192.168.0.2 mysql_port 3301 mode master peer db1 </host> <host db3> ip 192.168.0.3 mysql_port 3301 mode slave </host> <host db4> ip 192.168.0.4 mysql_port 3301 mode slave </host> <role writer> hosts db1, db2 ips 192.168.0.100 mode exclusive </role> <role reader> hosts db3, db4 ips 192.168.0.101,192.168.0.102 mode balanced </role>
B>配置文件 【/etc/mysql-mmm/mmm_agent_3301.conf】 不同的节点上,this以当前节点名为准
include mmm_common_3301.conf # The 'this' variable refers to this server. Proper operation requires # that 'this' server (db1 by default), as well as all other servers, have the # proper IP addresses set in mmm_common.conf. this db1
C>配置文件 【/etc/mysql-mmm/mmm_mon_3301.conf 】这个文件只存在管理节点上
include mmm_common_3301.conf <monitor> ip 192.168.0.5 port 53301 pid_path /var/run/mysql-mmm/mmm_mond_3301.pid bin_path /usr/libexec/mysql-mmm status_path /var/lib/mysql-mmm/mmm_mond.status ping_ips 192.168.0.1,192.168.0.2,192.168.0.3,192.168.0.4,192.168.201.5 auto_set_online 60 # 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 slave monitor_password slave </host> debug 0
3、修改mysql-mmm启动脚本
#!/bin/sh # # mysql-mmm-agent This shell script takes care of starting and stopping # the mmm agent daemon. # # 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 CLUSTER=$2 if [ "$CLUSTER" != "" ]; then MMMD_AGENT_BIN="/usr/sbin/mmm_agentd @$CLUSTER" MMMD_AGENT_PIDFILE="/var/run/mysql-mmm/mmm_agentd_$CLUSTER.pid" LOCKFILE="/var/lock/subsys/mysql-mmm-agentd_$CLUSTER" else MMMD_AGENT_BIN="/usr/sbin/mmm_agentd" MMMD_AGENT_PIDFILE="/var/run/mysql-mmm/mmm_agentd.pid" LOCKFILE="/var/lock/subsys/mysql-mmm-agentd" fi prog='MMM Agent Daemon' 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
4、修改mysql-mmm监控脚本
#!/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=$2 LOCKFILE='/var/lock/subsys/mysql-mmm-monitor' 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
5、启动和监控方法
/etc/init.d/mysql-mmm-agent start 3301
/etc/init.d/mysql-mmm-agent stop 3301
/etc/init.d/mysql-mmm-monitor start 3301
/etc/init.d/mysql-mmm-monitor stop 3301
mmm_control @3301 show
mmm_control @3301 checks all