Home Database Mysql Tutorial 安装配置MySQLMTOP来监控MySQL运行性能的教程_MySQL

安装配置MySQLMTOP来监控MySQL运行性能的教程_MySQL

May 27, 2016 pm 01:45 PM
mysql

一、环境说明
1、服务器角色

2015129153745577.png (726×101)

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 的接口)

二、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
Copy after login

为避免 python 版本过高,导致 yum 不可以,需做如下修改:

# vim /usr/bin/yum
Copy after login

由 #!/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
Copy after login


三、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;"
Copy after login

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
Copy after login

3、在被监控机上创建授权账号

# mysql -uroot -e "grant select,super,process on *.* to &#39;monitor&#39;@&#39;172.18.35.29&#39; identified by &#39;monitor&#39;;"
# mysql -uroot -e "flush privileges;"
Copy after login

4、mysqlmtop配置

# cp -a mysqlmtop /usr/local/
# cp -a frontweb /data/web/data/

 
# cd /usr/local/mysqlmtop/
# vim etc/config.ini
Copy after login

2015129154018464.jpg (319×327)

# chmod +x *.py *.sh mtopctl
# ln -s /usr/local/mysqlmtop/mtopctl /usr/local/bin
Copy after login

( 注意:需要使用dos2unix命令对*.py、*.sh、mtopctl文件进行格式转换,否则会运行失败 )

5、测试MySQL连接是否正常

# cd /usr/local/mysqlmtop && ./test_mysql.py
Copy after login

MySQLDB OK!
Copy after login

6、启动监控系统

# mtopctl start
Copy after login

2015129154122888.jpg (410×60)

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
Copy after login

2015129154153004.jpg (498×215)

# vim /data/web/conf/mysqlmtop.confDocumentRoot /data/web/data/frontweb
  ServerName mysqlmtop.test.com
  DirectoryIndex index.php
  AddDefaultCharset UTF-8Order Deny,Allow
    Deny from AllAllowOverride ALL# service httpd graceful
Copy after login

然后本地hosts绑定(172.18.35.29 mysqlmtop.test.com)
通过 http://mysqlmtop.test.com 即可访问(初始授权账号:admin admin)

8、监控项设置
点击管理中心 --> 应用管理 添加应用

2015129154225845.jpg (1156×477)

点击管理中心 --> 服务器管理 添加 MySQL 服务器

2015129154243226.jpg (1164×744)

四、慢查询配置
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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

2、开启 MySQL 本身的慢查询功能

slow_query_log = 1
slow_query_log_file = /data/dbdata/slow_query.log
long_query_time = 1
Copy after login

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
Copy after login

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
Copy after login

以上数据表 mysql_slow_query_review、mysql_slow_query_review_history 的后缀为主机 ID,如图:

2015129154414920.jpg (1259×469)

5、为被监控的服务器开启慢查询

2015129154437909.jpg (825×591)

6、效果展示

2015129154518166.jpg (1372×669)

三、工具组件配置
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
Copy after login

2、效果展示

2015129154605413.jpg (1004×341)

四、资源监控配置
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="lovezym5@qq.com" \
--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
......
Copy after login

服务启动:

# /usr/local/snmp/sbin/snmpd -c /usr/local/snmp/share/snmp/snmpd.conf
Copy after login

2、监控服务器上的设置
NET-SNMP服务安装:

# 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="lovezym5@qq.com" \
--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"
Copy after login

重启监控服务:

# mtopctl stop && mtopctl start
Copy after login

问题修正(否则无法获取内存信息):

# vim /usr/local/mysqlmtop/check_linux_resource.sh
totalmem=`/usr/bin/snmpdf -v1 -c mysqlmtop ${ip} | awk &#39;/Real Memory/ {print $3}&#39;`
usedmem=`/usr/bin/snmpdf -v1 -c mysqlmtop ${ip} | awk &#39;/Real Memory/ {print $4}&#39;`
Copy after login

crontab 内容添加:

*/1 * * * * cd /usr/local/mysqlmtop; ./check_linux_resource.py >/dev/null 2>&1
Copy after login

效果展示

2015129154803297.jpg (1258×332)

 以上就是MySQLMTOP,MySQL,运行性能的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1669
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

Explain the purpose of foreign keys in MySQL. Explain the purpose of foreign keys in MySQL. Apr 25, 2025 am 12:17 AM

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

Compare and contrast MySQL and MariaDB. Compare and contrast MySQL and MariaDB. Apr 26, 2025 am 12:08 AM

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

SQL vs. MySQL: Clarifying the Relationship Between the Two SQL vs. MySQL: Clarifying the Relationship Between the Two Apr 24, 2025 am 12:02 AM

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

What software is better for yi framework? Recommended software for yi framework What software is better for yi framework? Recommended software for yi framework Apr 18, 2025 pm 11:03 PM

Abstract of the first paragraph of the article: When choosing software to develop Yi framework applications, multiple factors need to be considered. While native mobile application development tools such as XCode and Android Studio can provide strong control and flexibility, cross-platform frameworks such as React Native and Flutter are becoming increasingly popular with the benefits of being able to deploy to multiple platforms at once. For developers new to mobile development, low-code or no-code platforms such as AppSheet and Glide can quickly and easily build applications. Additionally, cloud service providers such as AWS Amplify and Firebase provide comprehensive tools

See all articles