主机环境 RedHat Linux 6.5 64位
实验环境 服务端1 ip 172.25.25.1
服务端2 ip 172.25.25.2
安装包 nagios-plugins-2.1.1.tar.gz
nagios-cn-3.2.3.tar.bz2
gd-devel-2.0.35-11.el6.x86_64.rpm
nrpe-2.15.tar.gz
防火墙状态:关闭
Selinux状态:Disabled
1.安装nagios、监控本地及测试
A)配置安装nagios及插件
[root@sever1 mnt]# ls
nagios-plugins-2.1.1.tar.gz nagios-cn-3.2.3.tar.bz2
gd-devel-2.0.35-11.el6.x86_64.rpm
[root@sever1 mnt]# yum installgd-devel-2.0.35-11.el6.x86_64.rpm -y
[root@sever1 mnt]# useradd Nagios #创建系统用户ngios
[root@sever1 mnt]# usermod -a -G nagcmd Nagios #将nagios添加到nagcmd附加组
[root@sever1 mnt]# usermod -a -G nagcmd apache #将apache也添加到nagcnd附加组
[root@sever1 mnt]# id Nagios #查看
uid=1001(nagios) gid=1001(nagios)groups=1001(nagios),1002(nagcmd)
[root@sever1 mnt]# id apache
uid=48(apache) gid=48(apache) groups=48(apache),1002(nagcmd)
[root@sever1 mnt]# tar jxf nagios-cn-3.2.3.tar.bz2 #解压
[root@sever1 mnt]# cd nagios-cn-3.2.3
[root@sever1 nagios-cn-3.2.3]# ./configure--with-command-group=nagcmd #配置
[root@sever1 nagios-cn-3.2.3]# make all
[root@sever1 nagios-cn-3.2.3]# make install #安装
[root@sever1 nagios-cn-3.2.3]# make install-init #安装脚本文件
[root@sever1 nagios-cn-3.2.3]# make install-config #安装配置文件
[root@sever1 nagios-cn-3.2.3]# make install-webconf
[root@sever1 nagios-cn-3.2.3]# cat /usr/local/nagios/etc/htpasswd.users #查看密码
nagiosadmin:gCWSDnqEHR45c
[root@sever1 nagios-cn-3.2.3]# htpasswd -c/usr/local/nagios/etc/htpasswd.users nagiosadmin #修改密码
New password:
Re-type new password:
Adding password for user nagiosadmin
[root@sever1 nagios-cn-3.2.3]# cat/usr/local/nagios/etc/htpasswd.usersnagiosadmin:QNeDXoEuaEVuI
[root@sever1 nagios-cn-3.2.3]# /etc/init.d/httpd start #开启httpd
Stopping httpd: [ OK ]
[root@sever1 nagios-cn-3.2.3]# /usr/local/nagios/bin/nagios -v/usr/local/nagios/etc/nagios.cfg #校验nagios的语法
[root@sever1 nagios-cn-3.2.3]# /etc/init.d/nagios start #开启nagios
Starting nagios: done.
#安装nagios插件
[root@sever1 mnt]# tar zxf nagios-plugins-2.1.1.tar.gz #解压
[root@sever1 mnt]# cd nagios-plugins-2.1.1
[root@sever1 nagios-plugins-2.1.1]# ./config--with-nagios-user=nagios --with-nagios-group=nagios #配置
[root@sever1 nagios-plugins-2.1.1]# make #编译
[root@sever1 nagios-plugins-2.1.1]# make install #安装
B)添加本地服务
[root@server1 etc]# vimnagios.cfg
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg #添加文件
cfg_file=/usr/local/nagios/etc/objects/services.cfg
# Definitions formonitoring the local (Linux) host
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg #标记localhost文件
[root@server1 etc]# cd objects/
[root@server1 objects]# cp -p localhost.cfg hosts.cfg
[root@server1 objects]# cp -p localhost.cfg services.cfg
[root@server1 objects]# vim hosts.cfg #主机配置文件
define host{ #主机
use linux-server #使用的模板
host_name server1.example.com #主机名
alias Manager #别名
address 172.25.29.1 #ip
icon_image server.gif #下面几行是在拓扑图中的位置
statusmap_image server.gd2
2d_coords 500,200
3d_coords 500,200,100
}
define hostgroup{
hostgroup_name linux-servers ;The name of the hostgroup
alias Linux Servers ; Long name of the group
members * ; Comma separated list of hosts that belong to this group
}
[root@server1 objects]# vim service.cfg #服务配置文件
define servicegroup{ #服务组
servicegroup_name系统负荷检查
alias 负荷检查
membersserver1.example.com,进程总数,server1.example.com,登录用户数,server1.example.com,根分区,server1.example.com,交换空间利用率
}
define service{ #服务
use local-service #使用的模板
host_name *
service_description PING
check_command check_ping!100.0,20%!500.0,60% #要传的参数
}
define service{
use local-service ; Name of service template to use
host_name server1.example.com
service_description 根分区
check_command check_local_disk!20%!10%!/
}
define service{
use local-service ; Name of service template to use
host_name server1.example.com
service_description 登录用户数
check_command check_local_users!20!50
}
define service{
use local-service ; Name of service template to use
host_name server1.example.com
service_description 进程总数
check_command check_local_procs!250!400!RSZDT
}
define service{
use local-service ; Name of service template to use
host_name server1.example.com
service_description 系统负荷
check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
}
define service{
use local-service ; Name of service template to use
host_name server1.example.com
service_description 交换空间利用率
check_command check_local_swap!20!10
}
define service{
use local-service ; Name of service template to use
host_name server1.example.com
service_description SSH
check_command check_tcp!22!1.0!10.0
notifications_enabled 0
}
define service{
use local-service ; Name of service template to use
host_name server1.example.com
service_description HTTP
check_command check_http
notifications_enabled 0
}
[root@server1 objects]# /etc/init.d/nagios reload #刷新
Running configuration check...done.
Reloading nagios configuration...done
C)测试172.25.25.1/Nagios