1、安装
早些时候都是源码解压安装,本篇主要用yum来简单安装做一些介绍。
安装之前准备一台服务器(监控中心),其余的可以是linux主机也可以是windos机器或者路由器、交换机等设备。也可以是主机上的服务。
配置epel源即可。
[root@localhost yum.repos.d]wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@localhost yum.repos.d]# ls
bak bak2 CentOS-Base.repo epel.repo yum.repo
在监控中心安装nagios以及相关插件:
[root@localhost yum.repos.d]# yum install nagios nagios-plugins -y
[root@localhost yum.repos.d]# yum install nagios-plugins-* --skip-broken -y
nagios web登录密码:
[root@localhost yum.repos.d]# htpasswd -c /etc/nagios/passwd nagiosadmin
启动服务:
[root@localhost yum.repos.d]# systemctl restart httpd
[root@localhost yum.repos.d]# systemctl restart nagios
web下访问:
http://IP/nagios
默认监控本机:
nagios文件的含义:
[root@localhost yum.repos.d]# cd /etc/nagios/objects/
[root@localhost objects]# ls
commands.cfg fts3-template.cfg printer.cfg templates.cfg windows.cfg
contacts.cfg localhost.cfg switch.cfg timeperiods.cfg
command.cfg 定义nagios能调用的命令;
contacts.cfg 定义联系人;
localhost.cfg 定义监控本机的对象;
printer.cfg 定义对打印机的监控;
switch.cfg 定义对交换机的监控;
templates.cfg 定义模板;
timeperiods.cfg 定义时间对象;
windows.cfg 定义监控的windows主机;
2、监控windows机器
1、 windows 机器安装NSClient++,注意安装途中需要填写监控中心的IP以及密码。完毕之后关闭防火墙。进入“服务”,检查该项服务是否开启。或者cmd下net -ant| findstr 12489
C:\Users\gaofan>netstat -ano | findstr 12489 TCP 0.0.0.0:12489 0.0.0.0:0 LISTENING 1356 TCP 0.0.0.0:12489 0.0.0.0:0 LISTENING 1356 TCP [::]:12489 [::]:0 LISTENING 1356C:\Users\gaofan>ipconfigWindows IP 配置以太网适配器 本地连接: 连接特定的 DNS 后缀 . . . . . . . : localdomain 本地链接 IPv6 地址. . . . . . . . : fe80::7dc0:93cd:986f:bab8%11 IPv4 地址 . . . . . . . . . . . . : 192.168.0.107 子网掩码 . . . . . . . . . . . . : 255.255.255.0 默认网关. . . . . . . . . . . . . : 192.168.0.254
检查:出现下面windows下的nsclient++版本代表通信正常
[root@localhost objects]# /usr/lib64/nagios/plugins/check_nt -H 192.168.0.107 -V
check_nt v2.3.1 (nagios-plugins 2.3.1)
监控服务器设置:
[root@localhost objects]# vim ../nagios.cfg
去掉下面的注释:
# Definitions for monitoring a Windows machine
cfg_file=/etc/nagios/objects/windows.cfg
[root@localhost objects]# vim windows.cfg
# Define a host for the Windows machine we'll be monitoring
# Change the host_name, alias, and address to fit your situation
define host {
use windows-server ; Inherit default values from a template
host_name winserver ; The name we're giving to this host
alias My Windows Server ; A longer name associated with the host
address 192.168.0.107 ; IP address of the host
}
编辑command.cfg
[root@localhost objects]# vim commands.cfg
define command {
command_name check_nt
command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -s 123456 -v $ARG1$ $ARG2$
}
重启nagios,web下点击HOST。