nagios安裝配置
[root@server1 nagios]# yum install gd gd-devel openssl openssl-devel \
httpd php gcc glic glic-common make net-snmp wget
[root@server1 ~]# groupadd nagios
[root@server1 ~]# useradd -g nagios nagios
[root@server1 ~]# ls
nagios nagios-3.2.2 nagios-3.2.2.tar.gz
[root@server1 ~]# cd nagios-3.2.2[root@server1 nagios-3.2.2]# ./configure --with-nagios-user=nagios \
--with-nagios- group=nagios
[root@server1 nagios-3.2.2]# make all
[root@server1 nagios-3.2.2]# make install
[root@server1 nagios-3.2.2]# make install-init
[root@server1 nagios-3.2.2]# make install-commandmode
[root@server1 nagios-3.2.2]# make install-config
nagios nagios-3.2.2 nagios-3.2.2.tar.gz nagios-plugins-1.4.13.tar.gz
[root@server1 ~]# tar zxf nagios-plugins-1.4.13.tar.gz
[root@server1 ~]# cd nagios-plugins-1.4.13
[root@server1 nagios-plugins-1.4.13]# ls
[root@server1 nagios-plugins-1.4.13]# ./configure --prefix=/usr/local/nagios
[root@server1 ~]# ls
nagios nagios-3.2.2.tar.gz nagios-plugins-1.4.13.tar.gz
nagios-3.2.2 nagios-plugins-1.4.13 nrpe-2.12.tar.gz
[root@server1 ~]# tar zxf nrpe-2.12.tar.gz
[root@server1 ~]# cd nrpe-2.12
[root@server1 nrpe-2.12]# ./configure
[root@server1 nrpe-2.12]# make install-plugin
[root@server1 nrpe-2.12]# make install-daemon
[root@server1 nrpe-2.12]# make install-daemon-config
[root@server1 nrpe-2.12]# chown -R nagios.nagios /usr/local/nagios/
[root@server1 nrpe-2.12]# htpasswd -c /usr/local/nagios/etc/htpasswd.users tomcat
[root@server1 nrpe-2.12]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[root@server1 nrpe-2.12]# service iptables save
[root@server1 nrpe-2.12]# /etc/init.d/nagios start
Starting nagios: done.
[root@server1 nrpe-2.12]# chkconfig httpd on
[root@server1 nrpe-2.12]# chkconfig nagios on
[root@server1 nrpe-2.12]# chkconfig --add nagios
[root@server1 ~]# vim /usr/local/nagios/etc/nagios.cfg
[root@server1 ~]# vim /usr/local/nagios/etc/cgi.cfg #後綴加tomcat
authorized_for_system_information=nagiosadmin,tomcat
authorized_for_system_commands=nagiosadmin,tomcat
authorized_for_all_services=nagiosadmin,tomcat
authorized_for_all_hosts=nagiosadmin,tomcat
authorized_for_all_service_commands=nagiosadmin,tomcat
authorized_for_all_host_commands=nagiosadmin,tomcat
[root@server1 ~]# vim /usr/local/nagios/etc/objects/commands.cfg #末尾加
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
[root@server1 ~]# vim /usr/local/nagios/etc/objects/contacts.cfg # 根據自己實際填寫郵箱用戶名等
[root@server1 ~]# vim /usr/local/nagios/etc/objects/timeperiods.cfg #可不做修改
[root@server1 ~]# vim /usr/local/nagios/etc/objects/localhost.cfg #可不做修改
[root@server1 ~]# vim /usr/local/nagios/etc/objects/templates.cfg #可不做修改
[root@server1 ~]# vim /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,172.25.135.1
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% #自行添加
[root@server1 ~]# cd /usr/local/nagios/etc/objects/
[root@server1 objects]# ls
[root@server1 objects]# cp localhost.cfg web2.cfg
[root@server1 objects]# cp localhost.cfg web1.cfg
[root@server1 objects]# vim web1.cfg #web2和web1一樣改名稱和ip地址即可
define host{
use linux-server ; Name of host template to use
; This host definition will inherit all variables that are defined
; in (or inherited by) the linux-server host template definition.
host_name web1
alias web1.com
address 172.25.135.2
}
define hostgroup{
hostgroup_name webs ; The name of the hostgroup
alias Linux Servers ; Long name of the group
members web1 ; Comma separated list of hosts that belong to this group
}
define service{
use generic-service ; Name of service template to use
host_name web1
service_description PING
check_command check_ping!100.0,20%!500.0,60%
notifications_enabled 1
}
define service{
use generic-service ; Name of service template to use
host_name web1
service_description Sys_Load
check_command check_nrpe!check_load
notifications_enabled 1
}
define service{
use generic-service ; Name of service template to use
host_name web1
service_description Current Users
check_command check_nrpe!check_users
notifications_enabled 1
}
define service{
use generic-service ; Name of service template to use
host_name web1
service_description Total Processes
check_command check_nrpe!check_total_procs
notifications_enabled 1
}
define service{
use generic-service ; Name of service template to use
host_name web1
service_description SSH
check_command check_ssh
notifications_enabled 1
}
define service{
use generic-service ; Name of service template to use
host_name web1
service_description HTTP
check_command check_http
notifications_enabled 1
}
[root@server1 objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #語法錯誤檢測,因配置文件太多根據錯誤排錯
[root@server1 etc]# /etc/init.d/nagios restart
被檢控節點
[root@server2 ~]# ls
nagios-plugins-1.4.13 nagios-plugins-1.4.13.tar.gz nrpe-2.12.tar.gz
[root@server2 nagios-plugins-1.4.13]# ./configure --prefix=/usr/local/nagios
[root@server2 nagios-plugins-1.4.13# make &&make install
[root@server2 nagios-plugins-1.4.13]# chown -R nagios.nagios /usr/local/nagios/
[root@server2 ~]# tar zxf nrpe-2.12.tar.gz
[root@server2 ~]# cd nrpe-2.12
[root@server2 nrpe-2.12]# ./configure
[root@server2 nrpe-2.12]# make all
[root@server2 nrpe-2.12]# make install-plugin
[root@server2 nrpe-2.12]# make install-daemon
[root@server2 nrpe-2.12]# make install-daemon-config
[root@server2 ~]# vim /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,172.25.135.1 #指向server1控制節點
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10%
[root@server2 ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[root@server2 ~]# echo "/usr/local/nagios/bin/nrpe \
-c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.local
[root@server2 ~]# netstat -nutlp |grep 5666
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 17161/nrpe
[root@server2 ~]# iptables -I INPUT -p tcp --dport 5666 -j ACCEPT
[root@server2 ~]# service iptables save
[root@server2 ~]# /usr/local/nagios/libexec/check_nrpe -H 172.25.135.2
server3和server2同樣
瀏覽器輸入:
http://172.25.135.1/nagios/
nagios安裝配置