linux中nagios pnp4nagios 图形监控 mysql

爱互踩 爱互踩流量交换~

下文为各位介绍一个linux中nagios pnp4nagios 图形监控 mysql的教程希望这篇文章可以帮助到各位哦,nagios图形界面还是比较麻烦的,下面以mysql为例来说一下,监控mysql的插件比较多,在这里了解方法,而不是死搬硬套.

一,安装pnp4nagios

[root@localhost objects]# yum install pnp4nagios rrdtool

如果找不到包换epel源,博客里面有搜一下,关于nagios的安装,请参考:nagios 安装配置,详解.

二,配置nagios

1,修改nagios.cfg

  1. [root@localhostobjects]#vim/etc/nagios/nagios.cfg//修改以下内容
  2. process_performance_data=1//由0改为1
  3. host_perfdata_command=process-host-perfdata//前面的注释拿掉
  4. service_perfdata_command=process-service-perfdata//注释拿掉
  5. enable_environment_macros=1//如果有注释拿掉

2,修改commands.cfg

注释掉原有对process-host-perfdata和process-service-perfdata,重新定义

  1. [root@localhostobjects]#vim/etc/nagios/objects/commands.cfg
  2. definecommand{
  3. command_nameprocess-service-perfdata
  4. command_line/usr/bin/perl/usr/libexec/pnp4nagios/process_perfdata.pl
  5. }
  6. definecommand{
  7. command_nameprocess-host-perfdata
  8. command_line/usr/bin/perl/usr/libexec/pnp4nagios/process_perfdata.pl-dHOSTPERFDATA
  9. }

3、修改配置文件templates.cfg,添加以下内容:

  1. [root@localhostobjects]#vim/etc/nagios/objects/templates.cfg
  2. definehost{
  3. namehosts-pnp
  4. register0
  5. action_url/pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_
  6. process_perf_data1
  7. }
  8. defineservice{
  9. namesrv-pnp
  10. register0
  11. action_url/pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
  12. process_perf_data1
  13. }

4,修改服务器配置文件localhost.cfg

  1. [root@localhostobjects]#vim/etc/nagios/objects/localhost.cfg
  2. definehost{
  3. uselinux-server,hosts-pnp
  4. host_namelocalhost
  5. aliaslocalhost
  6. address127.0.0.1
  7. }//phpfensi.com
  8. defineservice{
  9. uselocal-service,srv-pnp
  10. host_namelocalhost
  11. service_descriptionPING
  12. check_commandcheck_ping!100.0,20%!500.0,60%
  13. }

上面只是例举了一个,你可以都加一下.

三,pnp4nagios配置

在网上好多关于pnp4nagios的文章,都是要把mv misccommands.cfg-sample misccommands.cfg 生成配置文件,我是yum安装的,安装目录下根本没有sample这样的东西.

  1. [root@localhostobjects]#tree/etc/pnp4nagios/
  2. /etc/pnp4nagios/
  3. ├──background.pdf
  4. ├──check_commands
  5. │├──check_all_local_disks.cfg
  6. │├──check_nrpe.cfg
  7. │└──check_nwstat.cfg
  8. ├──config.php
  9. ├──misccommands.cfg
  10. ├──nagios.cfg
  11. ├──npcd.cfg
  12. ├──pages
  13. │└──web_traffic.cfg
  14. ├──pnp4nagios_release
  15. ├──process_perfdata.cfg
  16. └──rra.cfg

所在我根本没有配置任何东西.

四,重启nagios,启动npcd

  1. [root@localhostpnp4nagios]#/etc/init.d/npcdstart
  2. [root@localhostpnp4nagios]#/etc/init.d/nagiosrestart

五,nginx配置

配置nginx的时候,配置挺头痛的,nagios的根目录是有php的,pnp4nagios是放在nagios的根目录下面,pnp4nagios也是php的,配置不好容易错乱的.

  1. server
  2. {
  3. listen80;
  4. server_namenagios.xxxx.com;
  5. indexindex.php;
  6. root/usr/share/nagios/html;
  7. location~.*\.(php|php5)?${//nagios根目录的php
  8. fastcgi_pass127.0.0.1:9000;
  9. fastcgi_indexindex.php;
  10. includefastcgi.conf;
  11. }
  12. location~.*\.(gif|jpg|jpeg|png|bmp|swf)${//nagios的图片重写
  13. rewrite^/nagios/images/(.*)/images/$1break;
  14. rewrite^/pnp4nagios/index.php/(.*)/pnp4nagios/$1break;
  15. expires30d;
  16. }
  17. location~.*\.(js|css)?${//nagios的js,css重写
  18. rewrite^/nagios/stylesheets/(.*)/stylesheets/$1break;
  19. rewrite^/nagios/js/(.*)/js/$1break;
  20. rewrite^/pnp4nagios/index.php/(.*)/pnp4nagios/$1break;
  21. expires1h;
  22. }
  23. location~.*\.cgi${//nagios的主程序是perl的,perl的cgi重写
  24. root/usr/lib64/nagios/cgi-bin;
  25. rewrite^/nagios/cgi-bin/(.*)\.cgi/$1.cgibreak;
  26. fastcgi_pass127.0.0.1:9001;
  27. fastcgi_indexindex.cgi;
  28. includefastcgi.conf;
  29. }
  30. location~^(/pnp4nagios.*\.php)(.*)${//pnp4nagios的php重写
  31. rewrite^/pnp4nagios/index.php/index.php/(.*)$/pnp4nagios/index.php/$1;break;
  32. fastcgi_pass127.0.0.1:9000;
  33. fastcgi_indexindex.php;
  34. includefastcgi.conf;
  35. }
  36. }

在这里有一个问题就是http://nagios.xxxx.com/pnp4nagios/index.php/index.php/graph?host=localhost&srv=PING在这里有二个index.php,这个是php的程序加上去的,我并没有改,同一个页面有二种链接.

由nagios的监控页面,跳转到pnp4nagios监控页面的连接是

http://nagios.xxxx.com/pnp4nagios/index.php/graph?host=localhost&srv=PING

点php4nagios监控页面中的连接然后就会多加一个index.php,http://nagios.xxxx.com/pnp4nagios/index.php/index.php/graph?host=localhost&srv=PING

这也是上面我为什么要加这一句rewrite ^/pnp4nagios/index.php/index.php/(.*)$ /pnp4nagios/index.php/$1;break;的原因.

二,安装perl mysql扩展

# yum install perl-Class-DBI-mysql

三,check_mysqld.php和check_mysqld.pl

1,下载

  1. http://exchange.nagios.org/components/com_mtree/attachment.php?link_id=174&cf_id=30
  2. http://exchange.nagios.org/components/com_mtree/attachment.php?link_id=174&cf_id=36

2,修改check_mysqld.php和check_mysqld.pl,本机是64位,根本没有/usr/lib/nagios,所以要把文件中的lib改成lib64.

3,copy和修改文件权限

  1. #cpcheck_mysqld.pl/usr/lib64/nagios/plugins
  2. #chmod755/usr/lib64/nagios/plugins/check_mysqld.pl
  3. #chgrpnagios/usr/lib64/nagios/plugins/check_mysqld.pl
  4. #cpcheck_mysqld.php/usr/share/nagios/html/pnp4nagios/templates.dist

四,nagios配置

1,修改command.cfg

  1. #vim/etc/nagios/objects/commands.cfg
  2. definecommand{
  3. command_namecheck_mysqld
  4. command_line$USER1$/check_mysqld.pl-H$HOSTADDRESS$-unagios-p$USER7$-auptime,threads_connected,questions,slow_queries,open_tables-w',,,,'-c',,,,'-A$USER21$
  5. }

2,修改resource.cfg

  1. #vim/etc/nagios/objects/resource.cfg
  2. $USER7$=nagios
  3. $USER21$='com_select,com_update,com_insert,com_insert_select,
  4. com_commit,com_delete,com_rollback,aborted_clients,
  5. aborted_connects,binlog_cache_disk_use,binlog_cache_use,
  6. bytes_received,bytes_sent,connections,created_tmp_disk_tables,
  7. created_tmp_files,created_tmp_tables,delayed_errors,
  8. delayed_insert_threads,delayed_writes,handler_update,handler_write,
  9. handler_delete,handler_read_first,handler_read_key,
  10. handler_read_next,handler_read_prev,handler_read_rnd,
  11. handler_read_rnd_next,key_blocks_not_flushed,
  12. key_blocks_unused,key_blocks_used,key_read_requests,key_reads,
  13. key_write_requests,key_writes,max_used_connections,
  14. not_flushed_delayed_rows,open_files,open_streams,open_tables,
  15. opened_tables,prepared_stmt_count,qcache_free_blocks,
  16. qcache_free_memory,qcache_hits,qcache_inserts,
  17. qcache_lowmem_prunes,qcache_not_cached,
  18. qcache_queries_in_cache,qcache_total_blocks,questions,
  19. select_full_join,select_rangle_check,slow_launch_threads,
  20. slow_queries,table_locks_immediate,table_locks_waited,
  21. threads_cached,threads_connected,threads_created,
  22. threads_running'

在这里要注意,$USER21$后面的内容要在一行.

3,修改localhost.cfg

  1. #vim/etc/nagios/objects/localhost.cfg
  2. defineservice{
  3. uselocal-service,srv-pnp//srv-pnp换成你自定义的
  4. host_namelocalhost
  5. service_descriptionMYSQLD
  6. check_commandcheck_mysqld!localhost!nagios!nagios
  7. }
  8. 4,pnp4nagios中增加check_mysqld.cfg
  9. #vim/etc/pnp4nagios/check_commands/check_mysqld.cfg
  10. DATATYPE=COUNTER

五,重启nagios

  1. #/etc/init.d/npcdrestart
  2. #/etc/init.d/nrperestart
  3. #/etc/init.d/nagiosrestart

相关广告
  • linux中nagios pnp4nagios 图形监控 mysql linux中nagios pnp4nagios 图形监控 mysql linux中nagios pnp4nagios 图形监控 mysql
相关阅读

linux中nagios pnp4nagios 图形监控 mysql

2019/10/10 17:46:02 | 谷歌SEO算法 | SEO教程