设为首页 收藏本站
查看: 2650|回复: 1

yum搭建nagios监控linux&&window及邮件报警

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-1-19 09:28:56 | 显示全部楼层 |阅读模式
本文是小弟整合几位大神的文章,见笑@@
Linux利用sendmail和fetion发送报警通知
nagios监控windows主机 && linux主机
CentOS 5/6.X 使用 EPEL YUM源:

实验环境:
两台64位的centos-6.6
一台window-server-2003

安装网络yum源:
1
2
3
4
5
6
7
8
9
centos5.x--32位
[iyunv@centos-server ~]# wget http://mirrors.yun-idc.com/epel/ ... ease-5-4.noarch.rpm
centos5.x--64位
[iyunv@centos-server ~]# wget http://mirrors.hust.edu.cn/epel/ ... ease-5-4.noarch.rpm
centos6.x--32位
[iyunv@centos-server ~]# wget http://download.fedoraproject.or ... ease-6-8.noarch.rpm
centos6.x--64位
[iyunv@centos-server ~]# wget http://mirrors.hust.edu.cn/epel/ ... ease-6-8.noarch.rpm
[iyunv@centos-server ~]# rpm -ivh epel-release-6-8.noarch.rpm




搭建nagios监控服务器:
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
yum install httpd php* openssl openssl-devel nagios nagios-plugins*
setenforce 0
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
增加httpd的访问验证
[iyunv@centos-server ~]# htpasswd -c /etc/nagios/htpasswd nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
注意nagios的默认用户就是nagiosadmin,如果你使用的不是此用户,需要修改以下项目
[iyunv@centos-server objects]# cat /etc/nagios/cgi.cfg |grep nagiosadmin
authorized_for_system_information=nagiosadmin
authorized_for_configuration_information=nagiosadmin
authorized_for_system_commands=nagiosadmin
authorized_for_all_services=nagiosadmin
authorized_for_all_hosts=nagiosadmin
authorized_for_all_service_commands=nagiosadmin
authorized_for_all_host_commands=nagiosadmin
快速修改命令
[iyunv@centos-server ~]# sed -i 's/nagiosadmin/dragon/g' /etc/nagios/cgi.cfg
通过httpd访问nagios的web文件
[iyunv@centos-server objects]# cat >> /etc/httpd/conf/httpd.conf <<end
scriptAlias /nagios/cgi-bin "/usr/lib64/nagios/cgi-bin/"

AllowOverride AuthConfig
Options ExecCGI
Order allow,deny
Allow from all
AuthUserFile /etc/nagios/htpasswd

Alias /nagios /usr/share/nagios/html/

Options None
AllowOverride AuthConfig
Order allow,deny
Allow from all
AuthUserFile /etc/nagios/htpasswd

END




定义监控LINUX文件:
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
[iyunv@centos-server objects]# mkdir /etc/nagios/objects/server
[iyunv@centos-server objects]# vim /etc/nagios/nagios.cfg
cfg_dir=/usr/local/nagios/etc/servers
[iyunv@centos-server objects]# vim /etc/nagios/objects/server/192.168.150.143.cfg
define host{
        use                     linux-server
        host_name               192.168.150.143
        alias                   linux
        address                 192.168.150.143
        }


define service{
        use                             generic-service
        host_name                       192.168.150.143
        service_description             Check Swap
        check_command                   check_nrpe!check_swap
        }

define service{
        use                             generic-service
        host_name                       192.168.150.143
        service_description             total
        check_command                   check_nrpe!check_total_procs
        }

define service{
        use                             generic-service
        host_name                       192.168.150.143
        service_description             check_load
        check_command                   check_nrpe!check_load
        }

define service{
        use                             generic-service
        host_name                       192.168.150.143
        service_description             check_tcp_3306
        check_command                   check_tcp!3306
        }

define service{
        use                             generic-service
        host_name                       192.168.150.143
        service_description             check_users
        check_command                   check_nrpe!check_users
        }


define service{
        use                             generic-service
        host_name                       192.168.150.143
        service_description             check_mysql
        check_command                   check_nrpe!check_mysql
        }
define service{
        use                             generic-service
        host_name                        192.168.150.143
        service_description             check_http  192.168.150.143/index.html
        check_command                   check_http!'-u /index.html'
}
define service{
        use                             generic-service
        host_name                       192.168.150.143
        service_description             check_disk
        check_command                   check_nrpe!check_sda1
        }
在commonds.cfg中添加check_nrpe的命令
[iyunv@centos-server objects]# vim /etc/nagios/objects/commands.cfg
define command{
      command_name  check_nrpe
      command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}




配置linux客户端:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[iyunv@centos-server ~]# yum install nagios-plugins* openssl-devel openssl mysql-server
[iyunv@centos-server ~]# cat /etc/nrpe.d/nrpe
only_from=127.0.0.1 192.168.150.139
[iyunv@centos-server objects]# vim /etc/nagios/nrpe.cfg
添加nagios监控端的ip
allowed_hosts=127.0.0.1,192.168.150.139
添加以下内容
command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_sda1]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda1
command[check_zombie_procs]=/usr/lib64/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 150 -c 200
command[check_mysql]=/usr/lib64/nagios/plugins/check_mysql -H 127.0.0.1 -ubbq -pqwe123  #此用户需要在mysql中添加
command[check_swap]=/usr/lib64/nagios/plugins/check_swap -w 20% -c 10%



通过yum安装的nagios监控插件还有很多,有需要用到的可以研究下:
wKioL1S6jAqgyyOnAATy_9147zQ554.jpg

两端重启服务:
1
2
3
4
5
6
7
8
9
10
service nagios restart
service httpd restart
service nrpe restart
service xinetd restart
[iyunv@centos-server ~]# netstat -anl|grep 5666
tcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN      
tcp        0      0 :::5666                     :::*                        LISTEN  
在nagios监控端测试被监控端nrpe联通:
[iyunv@centos-server ~]# /usr/lib64/nagios/plugins/check_nrpe -H 192.168.150.143
NRPE v2.15





监控window-server:
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
[iyunv@centos-server objects]# vim /etc/nagios/objects/server/192.168.150.146.cfg
define host{
usewindows-server
        host_name               192.168.150.146
        alias                   my computer
        address                 192.168.150.146
        }


define service{
        use                             generic-service
        host_name                       192.168.150.146
        service_description             NSClient++ Version
        check_command                   check_win!CLIENTVERSION
         }

define service{
        use                             generic-service
        host_name                       192.168.150.146
        service_description             Uptime
        check_command                   check_win!UPTIME
        }

define service{
        use                             generic-service
        host_name                       192.168.150.146
        service_description             CPU Load
        check_command                   check_win!CPULOAD!-l 5,80,90
}

define service{
       use                     generic-service
       host_name               192.168.150.146
       service_description     Memory Usage
       check_command           check_win!MEMUSE!-w 80 -c 90
       }

define service{
       use                     generic-service
       host_name               192.168.150.146
       service_description     C: Drive Space
       check_command           check_win!USEDDISKSPACE!-l c -w 80 -c 90
       }

define service{
       use                     generic-service
       host_name               192.168.150.146
       service_description     D: Drive Space
       check_command           check_win!USEDDISKSPACE!-l d -w 80 -c 90
       }

define service{
       use                     generic-service
       host_name               192.168.150.146
       service_description     E: Drive Space
       check_command           check_win!USEDDISKSPACE!-l e -w 80 -c 90
       }
define service{
       use                     generic-service
       host_name               192.168.150.146
       service_description     Explorer
       check_command           check_win!PROCSTATE!-d SHOWALL -l Explorer.exe
       }
[iyunv@centos-server objects]# vim /etc/nagios/objects/commands.cfg
define command{
        command_name    check_win
        command_line    $USER1$/check_nt -H "$HOSTADDRESS$" -p 12489 -s dianyi123 -v $ARG1$ $ARG2$
}




测试配置文件:
1
2
3
4
5
6
[iyunv@centos-server objects]# /usr/sbin/nagios -v /etc/nagios/nagios.cfg
Error: Could not find any hostgroup matching 'windows-servers' (config file '/etc/nagios/objects/server/192.168.150.146.cfg', starting on line 1)
#这里我遇到这个错误了,把/etc/nagios/objects/templates.cfg 里window-server模版主机中以下这项注释就可以了
#hostgroups             windows-servers ;
重启以下服务
[iyunv@centos-server objects]# service nagios restart




配置window安装NSClient++:
1.
wKiom1S6gFrBZ7HYAADeAhEQOkk621.jpg
2.
wKioL1S6gSrQbpARAAFsEtE1Mpw099.jpg
3.
wKioL1S6gVDSzDFWAABQeJ6zylI022.jpg

看到监控结果:
wKiom1S6glOT7AoDAAg5M7efmTE172.jpg

邮件报警设置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
引用郑彦生的原文
1、停止系统自带的sendmail服务
# /etc/init.d/postfix stop

2、安装sendmail和mailx
# yum -y install sendmail mailx

3、修改sendmail配置文件
# cp /etc/mail.rc /etc/mail.rc.bak
# cat >> /etc/mail.rc << EOF
set from=13260071987@139.com smtp=smtp.139.com
set smtp-auth-user=13260071987@139.com smtp-auth-password=yi15093547036 smtp-auth=login
EOF

4、重新启动sendmail服务
# service sendmail restart
5.修改联系人
[iyunv@centos-server objects]# vim /etc/nagios/objects/contacts.cfg
define contact{
        contact_name                    nagiosadmin            
        use                             generic-contact         
        alias                           Nagios Admin         
        email                           18507656225@139.com     
        }




查看邮件:
wKioL1S6l9vy_82rAAGhjlX5myg617.jpg
wKioL1S6hFizf-AKAAGt3YnydGs294.jpg


</end

运维网声明 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-41025-1-1.html 上篇帖子: nagios自定义脚本监控<检查eip用户的java进程是否存在 > 下篇帖子: 新人求教,已装RRDtool,NRPE监控WindowsServer有Performance Data,但是没图 linux 监控
累计签到:2 天
连续签到:1 天
发表于 2015-1-27 11:33:49 | 显示全部楼层
谢谢!蛮受益!

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

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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