monã«ããMySQLã®ãããããã¯æ¤ç¥ã¨ãã®ã³ã°
æ´æ°ãæ¿ããDBï¼MySQL)ã§InnoDBã®ããã¯ç«¶åãçºçããã¢ããªã±ã¼ã·ã§ã³ãµã¼ããè©°ã¾ãç¶æ³ãçºçãã¦ãã¾ãã¾ããã
é害ç£è¦ã¯monã¨ããã¢ããªã±ã¼ã·ã§ã³ã§è¡ãªã£ã¦ããã®ã§ããã
ä»åã¯ãã®monã使ã£ã¦MySQLãããããã¯ã®æ¤ç¥ã¨ãã®ã³ã°ãè¡ãããã¨æãã¾ãã
monã«ã¤ãã¦ã¯ä¸è¨ã®è³æããåç
§ãã ããã
Mon, Muninによる楽々監視生活
ãããããã¯è§£æã¯ä¸è¨ãµã¤ãã®SQLãå©ç¨ãã¦ãã¾ãã
MySQL InnoDBにおけるロック競合の解析手順
åæ
ã»MONã®ãµã¼ãã¯æ¢ã«æ§ç¯æ¸ã¿ã§ãããã¨
ã»DBãµã¼ãã¯MySQL5.5ã§ãããã¨ï¼MySQL5.1+InnoDB pluginã§ãå¯ï¼
ãããã以ä¸ãç£è¦å¯¾è±¡ã®DBãµã¼ãã«ã¦ä½æ¥ãããã
SNMPã¤ã³ã¹ãã¼ã«
yum install net-snmp
lockãæ¤ç¥ããã¹ã¯ãªããä½æ
vim /usr/local/sbin/mysql_lock_check.sh
#!/bin/sh #--------------------# # Define ENV # #--------------------# export PATH=$PATH:/usr/local/mysql/bin:/usr/bin/mysql HOST=`hostname` #--------------------# # DIR & FILE # #--------------------# NAME=`basename $0 .sh` PIDFILE=`dirname $0`/$NAME.pid MYSQL_DIR='/data/mysql' if [ -f "$PIDFILE" ] then echo 2 exit 2; fi echo $$ > $PIDFILE CNT=`mysql -N -uroot -e 'select count(*) from information_schema.INNODB_LOCK_WAITS'` if [ "${CNT}" != "0" ]; then rm $PIDFILE ããããecho `date` >> ${MYSQL_DIR}/${HOST}_innodb_lock.log mysql -uroot -e 'select t_b.trx_mysql_thread_id blocking_id,t_w.trx_mysql_thread_id requesting_id,p_b.HOST blocking_host,p_w.HOST requesting_host,l.lock_table lock_table,l.lock_index lock_index,l.lock_mode lock_mode,p_w.TIME seconds,p_b.INFO blocking_info,p_w.INFO requesting_info from information_schema.INNODB_LOCK_WAITS w,information_schema.INNODB_LOCKS l,information_schema.INNODB_TRX t_b,information_schema.INNODB_TRX t_w,information_schema.PROCESSLIST p_b,information_schema.PROCESSLIST p_w where w.blocking_lock_id = l.lock_id and w.blocking_trx_id = t_b.trx_id and w.requesting_trx_id = t_w.trx_id and t_b.trx_mysql_thread_id = p_b.ID and t_w.trx_mysql_thread_id = p_w.ID order by requesting_id,blocking_id \G' >> ${MYSQL_DIR}/${HOST}_innodb_lock.log echo 1 exit 1; fi rm $PIDFILE echo 0 exit 0;
SNMPã®è¨å®å¤æ´
vim /usr/local/net-snmp/etc/snmpd.conf
ä¸è¨ã追è¨
extend .1.3.6.1.4.1.3000.40 mysql_lock /bin/sh /usr/local/sbin/mysql_lock_check.sh
ãããã以ä¸ãMONãµã¼ãã§ä½æ¥ãããã
MONã®ãã§ãã¯ã¹ã¯ãªããä½æ
vim /usr/local/mon/mon.d/mysql_InnoDB_lock_check.monitor
#!/bin/sh RET='' ERRORWORD="MySQL InnoDB lock check failed." ERRORWORD1="MySQL InnoDB locked." ERRORWORD2="MySQL InnoDB lock check is already running." for host in "$@" do #EXEC RET=`/usr/local/net-snmp/bin/snmpwalk -v2c -c casnmp ${host} .1.3.6.1.4.1.3000.40.3.1.4 | gawk '{print $4}'` #RET CHECK if [ "${RET}" = 0 ]; then : else if [ "$SummaryOutput" = "" ]; then SummaryOutput=${host} eval DetailedText=\${host}\" : \"\${ERRORWORD${RET}} else SummaryOutput="${SummaryOutput} ${host}" eval DetailedText=\${DetailedText}\" \\n\"\${host}\" : \"\${ERRORWORD${RET}} fi fi done # ERROR CHECK if [ "${SummaryOutput}" != "" ]; then echo "${SummaryOutput}" echo -e "${DetailedText}" exit 1 fi exit 0
MONã®è¨å®ãã¡ã¤ã«ã«è¿½è¨
vim /usr/local/mon/etc/mon.cf
hostgroup hogehoge-mysql-InnoDB_lock {ç£è¦å¯¾è±¡IPã¢ãã¬ã¹} watch hogehoge-mysql-InnoDB_lock service mysql_InnoDB_lock interval 3m monitor mysql_InnoDB_lock_check.monitor allow_empty_group period wd {Sun-Sat} alertevery 5m alertafter 3 15m alert mail.alert -f {ã¢ã©ã¼ãã¡ã¼ã«éä¿¡å @hogehoge.com} upalert mail.alert -f {ã¢ã©ã¼ãã¡ã¼ã«éä¿¡å @hogehoge.com} -S "hogehoge server is back up [mysql_InnoDB_lock]" -u {ã¢ã©ã¼ãã¡ã¼ã«éä¿¡å @hogehoge.com}
MONãµã¼ãåèµ·å
/etc/init.d/mon stop
/etc/init.d/mon start
ããã¯æ
å ±ã®ãã°ã®è¦æ¹
mysqlã®ãã£ã¬ã¯ããªã«ãã°ãåãã¦ã¾ãã
less ${MYSQL_DIR}/hostname_innodb_lock.log
0 : 2013å¹´ 3æ 14æ¥ æ¨ææ¥ 16:02:20 JST *************************** 1. row *************************** 1 : blocking_id: 220 2 : requesting_id: 227 3 : blocking_host: 10.*.*.101:53890 4 : requesting_host: 10.*.*.102:32783 5 : lock_table: `hoge`.`user_status_5` 6 : lock_index: `PRIMARY` 7 : lock_mode: X 8 : seconds: 38 9 : blocking_info: NULL 10: requesting_info: update user_status_5 set f_cnt = f_cnt+1 where user_id = 130
ãã®ãã°ããã¯
1è¡ç®ã¨2è¡ç®ã¨8è¡ç®ã®æ
å ±ãã
ã220çªã®ã¹ã¬ããã227çªã®ã¹ã¬ããã38ç§å¾
ããã¦ãã
5è¡ç®ã¨6è¡ç®ã®æ
å ±ãã
ã220çªã®ã¹ã¬ããã¯user_status_5ãã¼ãã«ã®ä¸»ãã¼ãæä»ããã¯ãã¦ãã
3è¡ç®ã®æ
å ±ãã
ã10.*.*.101ã®ãµã¼ãããããã¯ãã¦ãã
9è¡ç®ã®æ
å ±ãã
ã220çªã®ã¹ã¬ããã¯ç¾å¨ã¢ã¤ãã«ç¶æ
ã§ãã
10è¡ç®ã®æ
å ±ãã
ã227çªã®ã¹ã¬ããã¯user_id:130ã®ã¬ã³ã¼ããæ´æ°ãããã¨ãã¦ãã
ãããããã¯ãæ¤ç¥ããããã©ã®ã¢ããªã±ã¼ã·ã§ã³ãµã¼ãããããã¯ãã¦ããã®ããããã®ã§ãã®ããã»ã¹ã殺ããªããã¾ãããã
é »ç¹ã«çºçãããããªãããã¼ã¿æ´æ°ã®ä»çµã¿èªä½ãæ¹åãã¦ãããã¾ãããâ¦ã
ã¨ãã¹ãã¼ãã®ããã®MySQL[éç¨+管ç]ãã©ãã«ã·ã¥ã¼ãã£ã³ã°ã¬ã¤ã
- ä½è : 奥éå¹¹ä¹
- åºç社/ã¡ã¼ã«ã¼: æè¡è©è«ç¤¾
- çºå£²æ¥: 2010/06/12
- ã¡ãã£ã¢: 大åæ¬
- è³¼å ¥: 16人 ã¯ãªãã¯: 204å
- ãã®ååãå«ãããã° (35件) ãè¦ã