nagios是开源的监控解决方案,可以用来监控linux、windows、unix的主机状态,可以通过短信和邮件的形式发送告警给用户。另一个优点是由于是开源方案,可以比较方面的写自己需要的监控脚本,网上也有很多现成的脚本可以借鉴等。总之,开源免费.
下面是具体的安装过程
版本是rhel6.3 +nagios 4.0.2
服务器端需要安装nagioscore,nagios nrpe和nagios plugin软件,Ip地址是10.4.1.11
windows客户端需要安装NSClient++
linux客户端需要安装nrpe和nagiosplugin
1,配置yum源,安装相关软件包
mount 10.1.1.11:/RHEL-INSTALL-REPO//nfsshare
[root@Stylog3 software]# mount 10.1.1.11:/RHEL-INSTALL-REPO//nfsshare
vi /etc/yum.repos.d/rhel5.repo
[Server]
name=rhel5server
baseurl=file:///nfsshare/rhel-5.9-repo/install
enable=1
gpcheck=1
gpgkey=file:///nfsshare/rhel-5.9-repo/install/RPM-GPG-KEY-redhat-release
mkdir /nfsshare
mount 10.1.1.11:/RHEL-INSTALL-REPO//nfsshare/
为了方便,直接使用linux自带的httpd服务
yum install -y httpd php gcc glibcglibc-common gd gd-devel make net-snmp
2,新建用户
useradd nagios
passwd nagios
3,编译安装nagios core
tar -zxvf nagios-4.0.2
cd nagios-4.0.2
./configure
make all
make install
make install-init
make install-commandmode
make install-config
4,配置web接口
cd nagios-4.0.2
make install-webconf
为了安全,创建用户
htpasswd -s -c/usr/local/nagios/etc/htpasswd.users nagiosadmin
启动http服务
service httpd start
5,安装nagios plugin
tar -zxvf nagios-plugins-1.5.tar.gz
cd nagios-plugins-1.5
./configure
make
make install
6,修改并验证配置文件
相关配置文件均在/usr/local/nagios/etc/目录下
/usr/local/nagios/bin/nagios -v/usr/local/nagios/etc/nagios.cfg
7,登录网站验证,是否正确安装
http://Your-server-IP-address/nagios
8, clinet端的配置,具体客户端如何安装见下文
只需要在nrpe.cfg文件中,添加相关命令即可,主要每个service对应的command都要添加一个对应的
cat /usr/local/nagios/etc/nrpe.cfg
添加如下类似内容
command[check_disk]=/usr/local/nagios/libexec/check_disk-w 15% -c 10% -p /home
1,安装软件nscp
默认安装在C:\Program Files\NSClient++,配置文件为nsclient.ini,默认监控端口为12489
服务器端安装监控windows的插件(已经默认安装了,就是check_nt)
2.定义命令
vi/usr/local/nagios/etc/objects/commands.cfg
# 'check_nt' command definition
define command{
command_name check_nt
command_line $USER1$/check_nt-H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$
}
3.定义要监控的项目 services
vi/usr/local/nagios/etc/objects/windows_stysql1.cfg
vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/windows_stysql1.cfg
1,上传并安装nagios plugin安装软件
scp /monitor/software/nrpe-2.12.tar.gz hadoop@stylog2:/monitor/software
scp [email protected]:/monitor/software/nagios-plugins-1.5.tar.gz /monitor/software/
scp [email protected]:/monitor/software/nrpe-2.12.tar.gz /monitor/software/
tar -zxvf nagios-plugins-1.5.tar.gz
2 ,配置yum源,安装相关软件包
vi /etc/yum.repos.d/rhel6.repo
[Server]
name=rhel6server
baseurl=file:///nfsshare/rhel-6.3-repo/RHEL63/Server
enable=1
gpcheck=1
gpgkey=file:///nfsshare/rhel-6.3-repo/RHEL63/RPM-GPG-KEY-redhat-release
mkdir /nfsshare
mount 10.1.1.11:/RHEL-INSTALL-REPO//nfsshare/
3,新建相关用户
useradd nagios
passwd nagios
4,编译nagios plugin
[root@tydb nagios]# cd nagios-plugins-1.5
[root@tydb nagios]# ./configure
[root@tydb nagios]# make
[root@tydb nagios]# make install
5,修改权限
chown nagios:nagios /usr/local/nagios
chown -R nagios:nagios/usr/local/nagios/libexec
6,安装xinetd
yum install xinetd
7,安装nrpe
备注:checkingfor SSL headers... configure: error: Cannot find ssl headers
yum -y install openssl-devel
scphadoop@stylog1:/monitor/software/nrpe-2.12.tar.gz /monitor/software/
tar -xvf nrpe-2.12.tar.gz
cd nrpe-2.12
[root@tydb]# ./configure
[root@tydb]# make all
[root@tydb]# make install-plugin
[root@tydb]# make install-daemon
[root@tydb]# make install-daemon-config
make install-xinetd
8,修改配置
vi /etc/xinetd.d/nrpe
only_from = 127.0.0.1 localhost<nagios_ip_address>
vi /etc/services
nrpe 5666/tcp NRPE
重启服务
service xinetd restart
9,验证是否安装成功
[root@stylog2 nrpe-2.12]# netstat -at | grep nrpe
tcp 0 0 *:nrpe *:* LISTEN
[root@stylog2 nrpe-2.12]#/usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.12
10,添加监控的配置
vi /usr/local/nagios/etc/nrpe.cfg
默认已经添加了
command[check_users]=/usr/local/nagios/libexec/check_users-w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load-w 15,10,5 -c 30,25,20
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs-w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs-w 1000 -c 1500
#command[check_ftp]=/usr/local/nagios/libexec/check_ftp-w 150 -c 200
command[check_ssh]=/usr/local/nagios/libexec/check_ssh10.1.1.5
command[check_disk]=/usr/local/nagios/libexec/check_disk-w 15% -c 10% -p /
你可以测试相关命令是否可以正常执行
/usr/local/nagios/libexec/check_nrpe -Hlocalhost -c check_users
当然你也可以根据需要,添加你需要的命令
11,监控server端也需要简单配置
a,确保已经安装nrpe和nrpe client
b,检查到新加被监控服务器的连接
[root@stadmin ~]#/usr/local/nagios/libexec/check_nrpe -H 10.1.1.6
NRPE v2.12
C, 添加hosts
vi /usr/local/nagios/etc/hosts.cfg
definehost{
use linux-tydb2 ; Inherit default values from atemplate
host_name stylog1 ; The name we're giving tothis server
alias stylog1 ; A longer name for the server
address 10.1.1.5 ; IP address of Remote Linux host
}
define host{
use linux-tydb2 ; Inherit default values from atemplate
host_name stylog2 ; The name we're giving tothis server
alias stylog2 ; A longer name for the server
address 10.1.1.6 ; IP address of Remote Linux host
}
D,新建一个服务配置文件
vi service_linux.cfg
示例只添加了一个service,实际上可能需要更多监控项的定义
define service{
use generic-service
host_name stylog2
service_description FileSystem Usage
check_command check_nrpe!check_disk
}
E,重新启动nagios
service nagios restart
已添加linux 文件系统的监控
默认配置文件在目录/usr/local/nagios/etc
A,nagios.cfg 中添加配置文件
cfg_file=/usr/local/nagios/etc/servicesi_linux.cfg
B,service_linux.cfg 配置文件中添加servicecheck_disk
define service{
use generic-service
host_name stylog1
service_description File System Usage
check_command check_nrpe!check_disk
}
C,客户端的服务器commands.cfg文件中添加命令
cat/usr/local/nagios/etc/objects/commands.cfg
# 'check_disk' command definition
define command{
command_name check_disk
command_line $USER1$/check_disk-w $ARG1$ -c $ARG2$ -p $ARG3$
}
参考文档
http://www.tecmint.com/install-nagios-in-linux/
http://www.tecmint.com/how-to-add-linux-host-to-nagios-monitoring-server/
http://www.tecmint.com/how-to-add-windows-host-to-nagios-monitoring-server/