设为首页 收藏本站
查看: 1131|回复: 0

[经验分享] zabbix监控之mysql

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-11-12 09:00:23 | 显示全部楼层 |阅读模式
1、创建zabbix用户
1
2
3
# groupadd zabbix
# useradd -g zabbix zabbix
# usermod -s /sbin/nologin zabbix



2、在mysql中给zabbix授权,或者任意一个有查询权限的用户都行,这里用zabbix

1
2
3
4
5
mysql> grant all on zabbix.* to zabbix@'%' identified by '123456';         
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
退出



3、编译zabbix agent端
1
2
3
4
# tar zxvf zabbix-2.2.3.tar.gz
# ./configure --enable-agent   
# make install
注:未指定--prefix=  则默认目录在/usr/local/etc/下



4、修改agend端配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
# vim /usr/local/etc/zabbix_agentd.conf
LogFile=/var/log/zabbix_agentd.log
Server=192.168.0.232
ServerActive=192.168.0.232
Hostname=Zabbix server
注:
  LogFile agend日志文件位置
  Server  zabbix服务端地址
  ServerActive  zabbix服务端地址
  Hostname   zabbix服务器主机名
由于修改了日志文件位置,手动创建文件,并赋予其权限
# touch /var/log/zabbix_agentd.log
# chmod 777 /var/log/zabbix_agentd.log



5、
1
2
3
# vim /etc/services
zabbix_agent    10050/tcp
zabbix_agent    10050/udp




6、复制启动脚本

1
2
3
4
# cp misc/init.d/tru64/zabbix_agentd  /etc/init.d/zabbix_agentd
# chmod +x /etc/init.d/zabbix_agentd
确保以下几项的路径为zabbix_agentd的正确路径
DAEMON=/usr/local/sbin/zabbix_agentd



7、启动agentd端
1
2
3
# /etc/init.d/zabbix_agentd start
[iyunv@node3 zabbix-2.2.3]# netstat -tunlp | grep 10050
tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      18705/zabbix_agentd



至此agentd端已经编译好了,并启动成功
8、配置监控mysql相关属性
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# vim /usr/local/etc/zabbix_agentd.conf
添加如下段
UserParameter=mysql.Ping,mysqladmin -uzabbix -h192.168.0.233 -p123456  ping|grep alive|wc -l
UserParameter=mysql.Threads,mysqladmin -uzabbix -h192.168.0.233 -p123456  status|cut -f3 -d":"|cut -f1 -d"Q"
UserParameter=mysql.Questions,mysqladmin -uzabbix -h192.168.0.233 -p123456  status|cut -f4 -d":"|cut -f1 -d"S"
UserParameter=mysql.Slowqueries,mysqladmin -uzabbix -h192.168.0.233 -h192.168.0.233 -p123456  status|cut -f5 -d":"|cut -f1 -d"O"
UserParameter=mysql.Qps,mysqladmin -uzabbix -h192.168.0.233 -p123456  status|cut -f9 -d":"
UserParameter=mysql.Slave_IO_State,if [ "$(mysql -uzabbix -h192.168.0.233 -p123456  -e "show slave statusG"| grep Slave_IO_Running|awk '{print $2}')" == "Yes" ];then echo 1; else echo 0;fi
UserParameter=mysql.Slave_SQL_State,if [ "$(mysql -uzabbix -h192.168.0.233 -p123456  -e "show slave statusG"| grep Slave_SQL_Running|awk '{print $2}')" == "Yes" ];then echo 1; else echo 0;fi
UserParameter=mysql.Key_buffer_size,mysql -uzabbix -h192.168.0.233 -p123456  -e "show variables like 'key_buffer_size';"| grep -v Value |awk '{print $2/1024^2}'
UserParameter=mysql.Key_reads,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'key_reads';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Key_read_requests,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'key_read_requests';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Key_cache_miss_rate,echo $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'key_reads';"| grep -v Value |awk '{print $2}') $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'key_read_requests';"| grep -v Value |awk '{print $2}')| awk '{printf("%1.4f",$1/$2*100)}'
UserParameter=mysql.Key_blocks_used,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'key_blocks_used';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Key_blocks_unused,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'key_blocks_unused';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Key_blocks_used_rate,echo $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'key_blocks_used';"| grep -v Value |awk '{print $2}') $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'key_blocks_unused';"| grep -v Value |awk '{print $2}')| awk '{printf("%1.4f",$1/($1+$2)*100)}'
UserParameter=mysql.Innodb_buffer_pool_size,mysql -uzabbix -h192.168.0.233 -p123456  -e "show variables like 'innodb_buffer_pool_size';"| grep -v Value |awk '{print $2/1024^2}'
UserParameter=mysql.Innodb_log_file_size,mysql -uzabbix -h192.168.0.233 -p123456  -e "show variables like 'innodb_log_file_size';"| grep -v Value |awk '{print $2/1024^2}'
UserParameter=mysql.Innodb_log_buffer_size,mysql -uzabbix -h192.168.0.233 -p123456  -e "show variables like 'innodb_log_buffer_size';"| grep -v Value |awk '{print $2/1024^2}'
UserParameter=mysql.Table_open_cache,mysql -uzabbix -h192.168.0.233 -p123456  -e "show variables like 'table_open_cache';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Open_tables,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'open_tables';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Opened_tables,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'opened_tables';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Open_tables_rate,echo $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'open_tables';"| grep -v Value |awk '{print $2}') $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'opened_tables';"| grep -v Value |awk '{print $2}')| awk '{printf("%1.4f",$1/($1+$2)*100)}'
UserParameter=mysql.Table_open_cache_used_rate,echo $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'open_tables';"| grep -v Value |awk '{print $2}') $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show variables like 'table_open_cache';"| grep -v Value |awk '{print $2}')| awk '{printf("%1.4f",$1/($1+$2)*100)}'
UserParameter=mysql.Thread_cache_size,mysql -uzabbix -h192.168.0.233 -p123456  -e "show variables like 'thread_cache_size';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Threads_cached,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Threads_cached';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Threads_connected,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Threads_connected';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Threads_created,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Threads_created';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Threads_running,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Threads_running';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Qcache_free_blocks,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Qcache_free_blocks';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Qcache_free_memory,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Qcache_free_memory';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Qcache_hits,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Qcache_hits';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Qcache_inserts,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Qcache_inserts';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Qcache_lowmem_prunes,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Qcache_lowmem_prunes';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Qcache_not_cached,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Qcache_not_cached';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Qcache_queries_in_cache,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Qcache_queries_in_cache';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Qcache_total_blocks,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Qcache_total_blocks';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Qcache_fragment_rate,echo $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Qcache_free_blocks';"| grep -v Value |awk '{print $2}') $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Qcache_total_blocks';"| grep -v Value |awk '{print $2}')| awk '{printf("%1.4f",$1/$2*100)}'
UserParameter=mysql.Qcache_used_rate,echo $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show variables like 'query_cache_size';"| grep -v Value |awk '{print $2}') $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Qcache_free_memory';"| grep -v Value |awk '{print $2}')| awk '{printf("%1.4f",($1-$2)/$1*100)}'
UserParameter=mysql.Qcache_hits_rate,echo $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Qcache_hits';"| grep -v Value |awk '{print $2}') $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Qcache_inserts';"| grep -v Value |awk '{print $2}')| awk '{printf("%1.4f",($1-$2)/$1*100)}'
UserParameter=mysql.Query_cache_limit,mysql -uzabbix -h192.168.0.233 -p123456  -e "show variables like 'query_cache_limit';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Query_cache_min_res_unit,mysql -uzabbix -h192.168.0.233 -p123456  -e "show variables like 'query_cache_min_res_unit';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Query_cache_size,mysql -uzabbix -h192.168.0.233 -p123456  -e "show variables like 'query_cache_size';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Sort_merge_passes,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Sort_merge_passes';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Sort_range,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Sort_range';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Sort_rows,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Sort_rows';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Sort_scan,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Sort_scan';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Handler_read_first,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Handler_read_first';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Handler_read_key,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Handler_read_key';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Handler_read_next,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Handler_read_next';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Handler_read_prev,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Handler_read_prev';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Handler_read_rnd,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Handler_read_rnd';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Handler_read_rnd_next,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Handler_read_rnd_next';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Com_select,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'com_select';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Com_insert,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'com_insert';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Com_insert_select,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'com_insert_select';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Com_update,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'com_update';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Com_replace,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'com_replace';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Com_replace_select,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'com_replace_select';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Table_scan_rate,echo $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Handler_read_rnd_next';"| grep -v Value |awk '{print $2}') $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'com_select';"| grep -v Value |awk '{print $2}')| awk '{printf("%1.4f",$1/$2*100)}'
UserParameter=mysql.Open_files,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'open_files';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Open_files_limit,mysql -uzabbix -h192.168.0.233 -p123456  -e "show variables like 'open_files_limit';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Open_files_rate,echo $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'open_files';"| grep -v Value |awk '{print $2}') $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show variables like 'open_files_limit';"| grep -v Value |awk '{print $2}')| awk '{printf("%1.4f",$1/$2*100)}'
UserParameter=mysql.Created_tmp_disk_tables,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'created_tmp_disk_tables';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Created_tmp_tables,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'created_tmp_tables';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Created_tmp_disk_tables_rate,echo $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'created_tmp_disk_tables';"| grep -v Value |awk '{print $2}') $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'created_tmp_tables';"| grep -v Value |awk '{print $2}')| awk '{printf("%1.4f",$1/$2*100)}'
UserParameter=mysql.Max_connections,mysql -uzabbix -h192.168.0.233 -p123456  -e "show variables like 'max_connections';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Max_used_connections,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Max_used_connections';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Max_connections_used_rate,echo $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Max_used_connections';"| grep -v Value |awk '{print $2}') $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show variables like 'max_connections';"| grep -v Value |awk '{print $2}')| awk '{printf("%1.4f",$1/$2*100)}'
UserParameter=mysql.Table_locks_immediate,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Table_locks_immediate';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Table_locks_waited,mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'table_locks_waited';"| grep -v Value |awk '{print $2}'
UserParameter=mysql.Engine_select,echo $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'Table_locks_immediate';"| grep -v Value |awk '{print $2}') $(mysql -uzabbix -h192.168.0.233 -p123456  -e "show status like 'table_locks_waited';"| grep -v Value |awk '{print $2}')| awk '{printf("%5.4f",$1/$2)}'



重启agentd端
1
# /etc/init.d/zabbix_agentd restart



ok  到这里,服务器上相关的配置工作,已经完成了,下边去zabbix的web页面上,添加监控项
9、
  (1)添加主机
  组态-->主机-->创建主机
wKioL1RhvPzzGEa7AANlTglYnlo826.jpg wKioL1RhvVayqyhYAAL2-Y2r-CM299.jpg wKioL1RhvY_R0q5YAAFVFQViSpM151.jpg

(2)、添加模板


重启agentd端,即可

过一会可以看出,漂亮的图片以及产生了


wKioL1RhvanyAEjsAAZcGMfBg9M563.jpg

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-28241-1-1.html 上篇帖子: 分布式监控之Zabbix-Server 下篇帖子: zabbix 监控服务系列之--------使用JMX监控tomcat mysql 监控
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表