扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
nagios
成都创新互联主要从事成都网站设计、网站制作、外贸营销网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务崇礼,十载网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792
nagios配置文件设置分为俩种,一种如下设置,第二种为创建servers目录集中管理被监控主机和generic_cfg目录管理监控本机的配置文件。
# yum install -y httpd php glibc glibc-common gd gd-devel gcc
[root@teacher ~]# useradd nagios
[root@teacher ~]# groupadd nagcmd
[root@teacher ~]# usermod -a -G nagcmd apache
[root@teacher ~]# usermod -a -G nagcmd nagios
开始安装
# tar zxvf nagios-3.2.3.tar.gz -C /usr/local/src
# cd /usr/local/src/nagios-3.2.3/
# ./configure --prefix=/usr/local/nagios --with-command-group=nagcmd
# make all
# make install-init
# make install-commandmode
# make install-config
# make install-webconf
# cd /etc/httpd/conf.d
# vim nagios.conf
//记住保存用户名和密码的文件
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin //配置密码
-------------
安装插件
# tar zxvf nagios-plugins-1.4.15.tar.gz -C /usr/local/src
# cd /usr/local/src/nagios-plugins-1.4.15/
# ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd
# make
# make install
# cd /usr/local/nagios/libexec/
# ls
# ./check_ssh --help //查看帮助
启动服务
# service httpd restart
# service nagios restart
----------------------------
监控端 (服务器端) 192.168.3.2
# cd /usr/local/nagios/etc/objects
# vim contacts.cfg
39 define contact{
40 contact_name matrix
41 # use generic-contact
42 alias administrator
43 service_notification_period 24x7
44 host_notification_period 24x7
45 service_notification_options w,u,c,r
46 host_notification_options d,u,r
47 service_notification_commands notify-service-by-email
48 host_notification_commands notify-host-by-email
49
50 email matrix@localhost
51 }
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin,matrix //添加matrix 逗号分隔
}
# vim remotehost.cfg
define host{
host_name apache
alias apache
address 192.168.3.3
max_check_attempts 5
check_period 24x7
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_period 24x7
notification_options d,u,r
}
# vim services.cfg
define service{
use local-service
host_name apache
service_description apache_alive
check_command check_ping!100.0,20%!500.0,60%
}
define service{
host_name apache
service_description check_tcp 80
max_check_attempts 5
check_period 24x7
normal_check_interval 5
retry_check_interval 2
contact_groups admins
notification_period 24x7
notification_options w,u,c,r
check_command check_tcp!80
}
# pwd
/usr/local/nagios/etc
# vim nagios.cfg
34 cfg_file=/usr/local/nagios/etc/objects/remotehost.cfg
35 cfg_file=/usr/local/nagios/etc/objects/services.cfg
//检查配置文件错误
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Total Warnings: 0
Total Errors: 0
//服务重启
# /etc/init.d/nagios restart
firefox http://192.168.3.2/nagios &
//监控端的ip
-------------------------------
需要监控被监控端的web服务
在被监控端 192.168.3.3
启动网页服务
# service httpd restart
--------------------------------------
通过NRPE 监控远程主机
远程主机(被监控端) 192.168.3.3
# useradd -s /sbin/nologin -M nagios
# yum install gcc glibc glibc-common -y
# tar zxvf nagios-plugins-1.4.15.tar.gz -C /usr/local/src
# cd /usr/local/src/nagios-plugins-1.4.15/
# ./configure --prefix=/usr/local/nagios
# make
# make install
安装NRPE
# yum install openssl openssl-devel -y
# tar zxvf nrpe-2.12.tar.gz -C /usr/local/src
# cd /usr/local/src/nrpe-2.12/
# ./configure --prefix=/usr/local/nagios
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
# make install-xinetd
# vim /etc/services
418 nrpe 5666/tcp # nrpe
# vim /etc/xinetd.d/nrpe
disable = no
only_from = 192.168.3.2 127.0.0.1 //添加监控端的ip地址
# /etc/init.d/xinetd restart
# netstat -altunp | grep :5666
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 21318/xinetd
若开启防火墙需开放端口
iptables -A INPUT -p tcp -m tcp --dport 5666 -j ACCEPT
编辑配置文件
# vim /usr/local/nagios/etc/nrpe.cfg
199 command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
200 command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
201 command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1
202 command[check_sda2]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda2
203 command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
204 command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
在本机测试
# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_sda2
DISK OK - free space: / 21788 MB (77% inode=98%);| /=6431MB;23804;26780;0;29756
[root@teacher xinetd.d]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 30G 6.3G 22G 23% /
/dev/sda1 99M 12M 83M 12% /boot
tmpfs 252M 0 252M 0% /dev/shm
/rhel55.iso 2.9G 2.9G 0 100% /mnt/cdrom
[root@teacher xinetd.d]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda2 7864320 156918 7707402 2% /
/dev/sda1 26104 34 26070 1% /boot
tmpfs 64413 1 64412 1% /dev/shm
/rhel55.iso 0 0 0 - /mnt/cdrom
-------------------------
监控端 192.168.3.2
# yum install openssl openssl-devel -y
# tar zxvf nrpe-2.12.tar.gz -C /usr/local/src
# cd /usr/local/src/nrpe-2.12/
# ./configure --prefix=/usr/local/nagios
# make all
# make install-plugin
手动测试 写上被监控端的ip地址
# /usr/local/nagios/libexec/check_nrpe -H 192.168.3.3 -c check_sda2
DISK OK - free space: / 21788 MB (77% inode=98%);| /=6431MB;23804;26780;0;29756
# cd /usr/local/nagios/etc/objects/
# vim commands.cfg
添加
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
# vim services.cfg
#define 192.168.3.3 "/boot"
define service{
use local-service
host_name apache
service_description boot partition
check_command check_nrpe!check_sda1
}
#define 192.168.3.3 "/"
define service{
use local-service
host_name apache
service_description / partition
check_command check_nrpe!check_sda2
}
检查配置文件
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
服务重启
# service nagios restart
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流