Chinaunix首页 | 论坛 | 博客
  • 博客访问: 471669
  • 博文数量: 145
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1139
  • 用 户 组: 普通用户
  • 注册时间: 2014-01-14 16:47
个人简介

路漫漫其修远兮,吾将上下而求索

文章分类

全部博文(145)

文章存档

2016年(10)

2015年(15)

2014年(120)

我的朋友

分类: LINUX

2014-01-15 12:38:34

一、nagios core
1、下载nagios-3.5.0.tar.gz  nagios-plugins-1.4.16.tar.gz
2、

点击(此处)折叠或打开

  1. yum install -y wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp
3、

点击(此处)折叠或打开

  1. useradd nagios
  2. groupadd nagcmd
  3. usermod -a -G nagcmd nagios
  4. cd nagios
  5. ./configure --with-command-group=nagcmd
  6. make all
  7. make install
  8. make install-init
  9. make install-config
  10. make install-commandmode
  11. make install-webconf
  12. cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
  13. chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
  14. /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
  15. htpasswd -c /usr/local/nagios/etc/htpasswd.user nagios
  16. cd nagios-plugins
  17. ./configure --with-nagios-user=nagios --with-nagios-group=nagios
  18. make
  19. make install
4、

点击(此处)折叠或打开

  1. vi /usr/local/nagios/etccgi.cfg
  2. use_authentication=0
5、

点击(此处)折叠或打开

  1. cd /usr/local/nagios/etc/objects
  2. 根据需要更改localhost.cfg文件中的各项定义

6、

点击(此处)折叠或打开

  1. service httpd start
  2. service nagios start
  3. 访问

7、注:nagios默认用nagios账号,若用其它账号,需全新编译安装,详见./configure --help

二、nagios graph
1、

点击(此处)折叠或打开

  1. yum install php-devel php-common php-cli php-gd perl perl-URI perl-String

2、

点击(此处)折叠或打开

  1. 下载 rrdtool-1.0.50.tar.gz pnp-0.4.14.tar.gz cgilib-0.5.tar.gz

3、

点击(此处)折叠或打开

  1. cd cgilib-0.5
  2. make
  3. cp libcgi.a /usr/lib64
  4. cp cgi.h /usr/include
  5. cd rrdtool
  6. ./configure --prefix=/usr/local/rrdtool
  7. make
  8. make install
  9. cd pnp
  10. ./configure --with-rrdtool=/usr/local/rrdtool/bin/rrdtool
  11. 注:若使用其它账号和组,需在这里用--with-nagios-user/group指定
  12. make all
  13. make install
  14. make install-config
  15. make install-init
  16. 测试:
  17. /pnp/index.php?host=localhost
  18. 最后一行出现 Directory /usr/local/nagios/share/perfdata/localhost not found 则正常

4、

点击(此处)折叠或打开

  1. vi /usr/local/nagios/etc/nagios.cfg
  2. ### 0 改为 1
  3. process_performance_data=1
  4. ###去掉“#”
  5. host_perfdata_command=process-host-perfdata
  6. service_perfdata_command=process-service-perfdata

5、

点击(此处)折叠或打开

  1. vi /usr/local/nagios/etc/objects/commands.cfg
  2. 修改process-host-perfdata和 process-service-perfdata命令行:
  3. define command{
  4. command_name process-host-perfdata
  5. command_line $USER1$/process_perfdata.pl
  6. }
  7. define command{
  8. command_name process-service-perfdata
  9. command_line $USER1$/process_perfdata.pl
  10. }

6、

点击(此处)折叠或打开

  1. vi /usr/local/nagios/etc/objects/localhost.cfg
  2. 修改主机定义
  3. define host{
  4. use linux-server
  5. host_name localhost
  6. alias localhost
  7. address 127.0.0.1
  8. #一下两行为添加:
  9. process_perf_data 1
  10. action_url /nagios/pnp/index.php?host=$HOSTNAME$
  11. }

7、

点击(此处)折叠或打开

  1. service nagios restart
8、自定义图表的时间范围
默认情况下PNP有5个时间范围:


点击(此处)折叠或打开

  1. 4 Hours
  2. 24 Hours
  3. One Week
  4. One Month
  5. One Year
  6. vi /usr/local/nagios/etc/pnp/config.php
  7. ###
  8. $views[0]["title"] = "4 Hours";
  9. $views[0]["start"] = ( 60*60*4 );
  10. $views[1]["title"] = "24 Hours";
  11. $views[1]["start"] = ( 60*60*24 );
  12. ###更改为
  13. $views[0]["title"] = "30 Minutes";
  14. $views[0]["start"] = ( 60*60*1/2 );
  15. $views[1]["title"] = "1 Hour";
  16. $views[1]["start"] = ( 60*60*1 );
  17. $views[2]["title"] = "2 Hours";
  18. $views[2]["start"] = ( 60*60*2 );
  19. 以上更改可以生成半小时,1小时,2小时的图表


三、mysql监控
1、安装percona的yum库

点击(此处)折叠或打开

  1. rpm -Uhv

2、安装插件

点击(此处)折叠或打开

  1. yum install percona-nagios-plugins
  2. 默认安装到
  3. /usr/lib64/nagios/plugins路径下
  4. chown -R nagios:nagios /usr/lib64/nagios

3、

点击(此处)折叠或打开

  1. vi /usr/local/nagios/etc/resource.cfg
  2. 添加
  3. $USER2$=/usr/lib64/nagios/plugins

4、

点击(此处)折叠或打开

  1. vi /usr/local/nagios/etc/commands.cfg
  2. 添加
  3. # define command for mysql
  4. define command{
  5. command_name mysql_process
  6. command_line /usr/lib64/nagios/plugins/pmp-check-mysql-processlist -H 127.0.0.1 -l root -p admin
  7. }
  8. define command{
  9. command_name mysql_innodb
  10. command_line /usr/lib64/nagios/plugins/pmp-check-mysql-innodb -H 127.0.0.1 -l root -p admin
  11. }
  12. define command{
  13. command_name mysql_deleted
  14. command_line /usr/lib64/nagios/plugins/pmp-check-mysql-deleted-files -H 127.0.0.1 -l root -p admin
  15. }

5、

点击(此处)折叠或打开

  1. vi /usr/local/nagios/etc/localhost.cfg
  2. 添加
  3. define service {
  4. use local-service
  5. host_name localhost
  6. service_description Mysql Processlist
  7. check_command mysql_process!16!32
  8. }
  9. define service {
  10. use local-service
  11. host_name localhost
  12. service_description Mysql Innodb
  13. check_command mysql_innodb!3!10
  14. }
  15. define service {
  16. use local-service
  17. host_name localhost
  18. service_description Mysql Deleted
  19. check_command mysql_deleted!1!3
  20. }
  21. service nagios reload
6、注:
以上只添加了3个针对mysql的监控,可根据实际需要继续添加。
某些mysql监控脚本中的命令需要root权限,根据监控提示可对脚本作出一定更改




阅读(1225) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~