安装配置Zabbix来监控MySQL的基本教程
程序员文章站
2024-02-25 10:49:10
zabbix的简单安装配置说明
1、在已有的lamp或者lnmp的基础上安装zabbix,安装一些依赖包:
yum -y install mysql-dev...
zabbix的简单安装配置说明
1、在已有的lamp或者lnmp的基础上安装zabbix,安装一些依赖包:
yum -y install mysql-devel libcurl-devel net-snmp-devel
2、添加用户:
groupadd zabbix useradd zabbix -g zabbix
3、创建数据库,添加授权账号
create database zabbix character set utf8; grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
4、编译安装zabbix
下载地址:
wget http://jaist.dl.sourceforge.net/project/zabbix/zabbix%20latest%20stable/2.2.0/zabbix-2.2.0.tar.gz tar zxf zabbix-2.2.0.tar.gz cd zabbix-2.2.0 ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent \ --with-mysql --with-net-snmp --with-libcurl make install
5、导入数据库
mysql -uzabbix -pzabbix -hlocalhost zabbix < database/mysql/schema.sql mysql -uzabbix -pzabbix -hlocalhost zabbix < database/mysql/images.sql mysql -uzabbix -pzabbix -hlocalhost zabbix < database/mysql/data.sql
6、修改配置文件
cp misc/init.d/fedora/core/zabbix_server /etc/init.d/ cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/ cp -r frontends/php /var/www/html/zabbix sed -i 's/^dbuser=.*$/dbuser=zabbix/g' /usr/local/zabbix/etc/zabbix_server.conf sed -i 's/^.*dbpassword=.*$/dbpassword=zabbix/g' /usr/local/zabbix/etc/zabbix_server.conf sed -i 's/basedir=\/usr\/local/basedir=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_server sed -i 's/basedir=\/usr\/local/basedir=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_agentd
7、添加服务端口:
cat >>/etc/services <<eof zabbix-agent 10050/tcp zabbix agent zabbix-agent 10050/udp zabbix agent zabbix-trapper 10051/tcp zabbix trapper zabbix-trapper 10051/udp zabbix trapper eof
8、启动服务
/etc/init.d/zabbix_server start /etc/init.d/zabbix_agentd start echo "/etc/init.d/zabbix_server start" >> /etc/rc.local echo "/etc/init.d/zabbix_agentd start" >> /etc/rc.local
9、web页面配置,配置http访问好了后web登陆:http://ip/zabbix
zabbix监控mysql性能
通过获取mysql状态值将这些状态值传递给服务器并绘制成图片,这样可以观察mysql的工作情况,通常需要获得状态变量有以下
- com_update:mysql执行的更新个数
- com_select:mysql执行的查询个数
- com_insert:mysql执行插入的个数
- com_delete:执行删除的个数
- com_rollback:执行回滚的操作个数
- bytes_received:接受的字节数
- bytes_sent:发送的字节数
- slow_queries:慢查询语句的个数
1、创建mysql性能监控脚本
#!/bin/bash #create by zhengdazhi 2014.09.22 mysql_dir=/usr/local/mysql mysql=${mysql_dir}/bin/mysql mysqladmin=${mysql_dir}/bin/mysqladmin mysql_sock="/tmp/mysql.sock" mysql_user=root mysql_pwd=root args=1 if [ $# -ne "$args" ];then echo "please input one arguement:" fi case $1 in uptime) result=`${mysqladmin} -u${mysql_user} -p${mysql_pwd} -s $mysql_sock status|cut -f2 -d":"|cut -f1 -d"t"` echo $result ;; com_update) result=`${mysqladmin} -u${mysql_user} -p${mysql_pwd} -s $mysql_sock extended-status |grep -w "com_update"|cut -d"|" -f3` echo $result ;; slow_queries) result=`${mysqladmin} -u${mysql_user} -p${mysql_pwd} -s $mysql_sock status |cut -f5 -d":"|cut -f1 -d"o"` echo $result ;; com_select) result=`${mysqladmin} -u${mysql_user} -p${mysql_pwd} -s $mysql_sock extended-status |grep -w "com_select"|cut -d"|" -f3` echo $result ;; com_rollback) result=`${mysqladmin} -u${mysql_user} -p${mysql_pwd} -s $mysql_sock extended-status |grep -w "com_rollback"|cut -d"|" -f3` echo $result ;; questions) result=`${mysqladmin} -u${mysql_user} -p${mysql_pwd} -s $mysql_sock status|cut -f4 -d":"|cut -f1 -d"s"` echo $result ;; com_insert) result=`${mysqladmin} -u${mysql_user} -p${mysql_pwd} -s $mysql_sock extended-status |grep -w "com_insert"|cut -d"|" -f3` echo $result ;; com_delete) result=`${mysqladmin} -u${mysql_user} -p${mysql_pwd} -s $mysql_sock extended-status |grep -w "com_delete"|cut -d"|" -f3` echo $result ;; com_commit) result=`${mysqladmin} -u${mysql_user} -p${mysql_pwd} -s $mysql_sock extended-status |grep -w "com_commit"|cut -d"|" -f3` echo $result ;; bytes_sent) result=`${mysqladmin} -u${mysql_user} -p${mysql_pwd} -s $mysql_sock extended-status |grep -w "bytes_sent" |cut -d"|" -f3` echo $result ;; bytes_received) result=`${mysqladmin} -u${mysql_user} -p${mysql_pwd} -s $mysql_sock extended-status |grep -w "bytes_received" |cut -d"|" -f3` echo $result ;; com_begin) result=`${mysqladmin} -u${mysql_user} -p${mysql_pwd} -s $mysql_sock extended-status |grep -w "com_begin"|cut -d"|" -f3` echo $result ;; *) echo "usage:$0(uptime|com_update|slow_queries|com_select|com_rollback|questions)" ;; esac
2、修改客户端配置文件
查看zabbix自带的mysql监控模板
可以看出该模板是读取 mysql.status的键,因此在客户端配置文件中加入的自定义键名也应该是mysql.status
vim /usr/local/zabbix_agentd/etc/zabbix_agentd.conf #开启用户自定义配置 unsafeuserparameters=1 #添加mysql监控 userparameter=mysql.status[*],/usr/local/zabbix_agent/bin/checkmysqlperformance.sh $1 $2
重启客户端
3、测试
[root@localhost bin]# ./zabbix_get -s 127.0.0.1 -k mysql.status[com_update] 77503
4、将模板加入主机
下一篇: Java Proxy机制详细解读