裝置設置裝備擺設MySQLMTOP來監控MySQL運轉機能的教程。本站提示廣大學習愛好者:(裝置設置裝備擺設MySQLMTOP來監控MySQL運轉機能的教程)文章只能為提供參考,不一定能成為您想要的結果。以下是裝置設置裝備擺設MySQLMTOP來監控MySQL運轉機能的教程正文
1、情況解釋
1、辦事器腳色
2、體系情況
CentOS 6.2 x86_64
3、情況請求
(1)、MySQL 5.0 及以上 (用來存儲監控體系收集的數據)
(2)、Apache 2.2 及以上 (WEB 辦事器運轉辦事器)
(3)、PHP 5.3 以上 (WEB 界面)
(4)、Python 2 (推舉 2.7 版本,其他版本未做測試,履行數據收集和報警義務)
(5)、MySQLdb for python (Python 銜接 MySQL 的接口)
2、Python基本情況安排
https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
# tar xvzf Python-2.7.6.tgz # cd Python-2.7.6 # ./configure --prefix=/usr/local/python2.7 --enable-shared # make && make install # echo '/usr/local/python2.7/lib' >> /etc/ld.so.conf # /sbin/ldconfig # mv /usr/bin/python /usr/bin/python_old # ln -s /usr/local/python2.7/bin/python2.7 /usr/bin/python
為防止 python 版本太高,招致 yum 弗成以,需做以下修正:
# vim /usr/bin/yum
由 #!/usr/bin/python 修正為 #!/usr/bin/python_old
http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz
# tar xvzf distribute-0.6.28.tar.gz # cd distribute-0.6.28 # python setup.py install https://github.com/farcepest/MySQLdb1/archive/MySQLdb-1.2.5.tar.gz # tar xvzf MySQLdb1-MySQLdb-1.2.5.tar.gz # cd MySQLdb1-MySQLdb-1.2.5 # vim site.cfg mysql_config =/usr/local/mysql/bin/mysql_config …… # python setup.py build # python setup.py install
3、mysqlmtop情況安排
1、創立監控機數據庫並受權
# mysql -uroot -e "create database mysqlmtop default character set utf8;" # mysql -uroot -e "grant all privileges on mysqlmtop.* to 'mtop_user'@'%' identified by '123456';" # mysql -uroot -e "flush privileges;"
2、導入SQL文件夾裡的SQL文件(表構造和數據文件)
# unzip mysqlmtop_v2.1.zip # cd mysqlmtop_v2.1 # mysql -uroot mysqlmtop < sql/mysqlmtop.sql # mysql -uroot mysqlmtop < sql/mysqlmtop_data.sql
3、在被監控機上創立受權賬號
# mysql -uroot -e "grant select,super,process on *.* to 'monitor'@'172.18.35.29' identified by 'monitor';" # mysql -uroot -e "flush privileges;"
4、mysqlmtop設置裝備擺設
# cp -a mysqlmtop /usr/local/ # cp -a frontweb /data/web/data/ # cd /usr/local/mysqlmtop/ # vim etc/config.ini
# chmod +x *.py *.sh mtopctl # ln -s /usr/local/mysqlmtop/mtopctl /usr/local/bin
( 留意:須要應用dos2unix敕令對*.py、*.sh、mtopctl文件停止格局轉換,不然會運轉掉敗 )
5、測試MySQL銜接能否正常
# cd /usr/local/mysqlmtop && ./test_mysql.py
MySQLDB OK!
6、啟動監控體系
# mtopctl start
7、前端WEB展現層設置裝備擺設
# cd /data/web/data/frontweb/ # chown -R nobody:nogroup /data/web/data/frontweb # chmod -R 750 /data/web/data/frontweb # vim application/config/database.php
# vim /data/web/conf/mysqlmtop.conf <VirtualHost *:80> DocumentRoot /data/web/data/frontweb ServerName mysqlmtop.test.com DirectoryIndex index.php AddDefaultCharset UTF-8 <LocationMatch "/data/web/.*\.php$"> Order Deny,Allow Deny from All </LocationMatch> <Directory /> AllowOverride ALL </Directory> </VirtualHost> # service httpd graceful
然後當地hosts綁定(172.18.35.29 mysqlmtop.test.com)
經由過程 http://mysqlmtop.test.com 便可拜訪(初始受權賬號:admin admin)
8、監控項設置
點擊治理中間 --> 運用治理 添加運用
點擊治理中間 --> 辦事器治理 添加 MySQL 辦事器
4、慢查詢設置裝備擺設
1、在被監控辦事器裝置以下組件
http://cpan.metacpan.org/authors/id/T/TI/TIMB/DBI-1.628.tar.gz
# tar xvzsf DBI-1.628.tar.gz # cd DBI-1.628 # perl Makefile.PL # make && make install
http://search.cpan.org/CPAN/authors/id/C/CA/CAPTTOFU/DBD-mysql-4.024.tar.gz
# tar xvzf DBD-mysql-4.024.tar.gz # cd DBD-mysql-4.024 # perl Makefile.PL --mysql_config=/usr/local/mysql/bin/mysql_config --with-mysql=/usr/local/mysql # make && make install
http://search.cpan.org/CPAN/authors/id/S/SU/SULLR/IO-Socket-SSL-1.972.tar.gz
# tar xvzf IO-Socket-SSL-1.972.tar.gz # cd IO-Socket-SSL-1.972 # perl Makefile.PL # make && make install
http://www.percona.com/redir/downloads/percona-toolkit/LATEST/percona-toolkit-2.2.7.tar.gz
# tar xvzf percona-toolkit-2.2.7.tar.gz # cd percona-toolkit-2.2.7 # perl Makefile.PL # make && make install
2、開啟 MySQL 自己的慢查詢功效
slow_query_log = 1 slow_query_log_file = /data/dbdata/slow_query.log long_query_time = 1
3、在被監控辦事器(10.160.22.14)上添加以下 crontab 項
00 * * * * /usr/bin/pt-query-digest --user=mtop_user --password=123456 --port=3306 --review h=172.18.35.29,D=mysqlmtop,t=mysql_slow_query_review_4 --history h=172.18.35.29,D=mysqlmtop,t=mysql_slow_query_review_history_4 --no-report --limit=0% /data/dbdata/slow_query.log >/dev/null 2>&1
4、在被監控辦事器(10.160.22.47)上添加以下 crontab 項
00 * * * * /usr/bin/pt-query-digest --user=mtop_user --password=123456 --port=3306 --review h=172.18.35.29,D=mysqlmtop,t=mysql_slow_query_review_5 --history h=172.18.35.29,D=mysqlmtop,t=mysql_slow_query_review_history_5 --no-report --limit=0% /data/dbdata/slow_query.log >/dev/null 2>&1
以上數據表 mysql_slow_query_review、mysql_slow_query_review_history 的後綴為主機 ID,如圖:
5、為被監控的辦事器開啟慢查詢
6、後果展現
3、對象組件設置裝備擺設
1、在被監控辦事器(172.18.35.29)上添加以下 crontab 項
*/30 * * * * cd /usr/local/mysqlmtop; ./check_mysql_widget_bigtable.py >/dev/null 2>&1 */1 * * * * cd /usr/local/mysqlmtop; ./check_mysql_widget_hit_rate.py >/dev/null 2>&1 */1 * * * * cd /usr/local/mysqlmtop; ./check_mysql_widget_connect.py >/dev/null 2>&1
2、後果展現
4、資本監控設置裝備擺設
1、被監控辦事器上的設置
NET-SNMP辦事裝置(留意版本):
ftp://ftp.fi.freebsd.org/pub/FreeBSD/ports/distfiles/net-snmp-5.3.2.tar.gz
# tar xvzf net-snmp-5.3.2.tar.gz # cd net-snmp-5.3.2 # ./configure --prefix=/usr/local/snmp \ --enable-mfd-rewrites \ --with-default-snmp-version="2" \ --with-sys-contact="[email protected]" \ --with-sys-location="China" \ --with-logfile="/var/log/snmpd.log" \ --with-persistent-directory="/var/net-snmp" # make && make install # cp EXAMPLE.conf /usr/local/snmp/share/snmp/snmpd.conf # vim /usr/local/snmp/share/snmp/snmpd.conf com2sec notConfigUser 172.18.35.29 mysqlmtop group notConfigGroup v1 notConfigUser group notConfigGroup v2c notConfigUser group notConfigGroup usm notConfigUser view all included .1 80 access notConfigGroup "" any noauth exact all none none ......
辦事啟動:
# /usr/local/snmp/sbin/snmpd -c /usr/local/snmp/share/snmp/snmpd.conf2、監控辦事器上的設置
# tar xvzf net-snmp-5.3.2.tar.gz # cd net-snmp-5.3.2 # ./configure --prefix=/usr/local/snmp \ --enable-mfd-rewrites \ --with-default-snmp-version="2" \ --with-sys-contact="[email protected]" \ --with-sys-location="China" \ --with-logfile="/var/log/snmpd.log" \ --with-persistent-directory="/var/net-snmp" # make && make install # cd /usr/local/mysqlmtop # ln -s /usr/local/snmp/bin/snmpwalk /usr/bin/snmpwalk # ln -s /usr/local/snmp/bin/snmpdf /usr/bin/snmpdf # vim /usr/local/mysqlmtop/check_linux_resource.sh host="172.18.35.29" port="3306" user="mtop_user" password="123456" dbname="mysqlmtop" ...... # vim /usr/local/mysqlmtop/etc/config.ini [linux_server] server_ip="10.160.22.14|10.160.22.47"
重啟監控辦事:
# mtopctl stop && mtopctl start
成績修改(不然沒法獲得內存信息):
# vim /usr/local/mysqlmtop/check_linux_resource.sh totalmem=`/usr/bin/snmpdf -v1 -c mysqlmtop ${ip} | awk '/Real Memory/ {print $3}'` usedmem=`/usr/bin/snmpdf -v1 -c mysqlmtop ${ip} | awk '/Real Memory/ {print $4}'`
crontab 內容添加:
*/1 * * * * cd /usr/local/mysqlmtop; ./check_linux_resource.py >/dev/null 2>&1
後果展現