nagios安装配置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nagios安装配置相关的知识,希望对你有一定的参考价值。
环境rhel6.5server1,server2,server3
[[email protected] nagios]# yum install gd gd-devel openssl openssl-devel
httpd php gcc glic glic-common make net-snmp wget
[[email protected] ~]# groupadd nagios
[[email protected] ~]# useradd -g nagios nagios
[[email protected] ~]# ls
nagios nagios-3.2.2 nagios-3.2.2.tar.gz
[[email protected] ~]# cd nagios-3.2.2
[[email protected] nagios-3.2.2]# ./configure --with-nagios-user=nagios
--with-nagios- group=nagios
[[email protected] nagios-3.2.2]# make all
[[email protected] nagios-3.2.2]# make install
[[email protected] nagios-3.2.2]# make install-init
[[email protected] nagios-3.2.2]# make install-commandmode
[[email protected] nagios-3.2.2]# make install-config
[[email protected] ~]# ls
nagios nagios-3.2.2 nagios-3.2.2.tar.gz nagios-plugins-1.4.13.tar.gz
[[email protected] ~]# tar zxf nagios-plugins-1.4.13.tar.gz
[[email protected] ~]# cd nagios-plugins-1.4.13
[[email protected] nagios-plugins-1.4.13]# ls
[[email protected] nagios-plugins-1.4.13]# ./configure --prefix=/usr/local/nagios
[[email protected] nagios-plugins-1.4.13]# make && make install
[[email protected] ~]# 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
[[email protected] ~]# tar zxf nrpe-2.12.tar.gz
[[email protected] ~]# cd nrpe-2.12
[[email protected] nrpe-2.12]# ./configure
[[email protected] nrpe-2.12]# make install-plugin
[[email protected] nrpe-2.12]# make install-daemon
[[email protected] nrpe-2.12]# make install-daemon-config
[[email protected] nrpe-2.12]# chown -R nagios.nagios /usr/local/nagios/
[[email protected] nrpe-2.12]# htpasswd -c /usr/local/nagios/etc/htpasswd.users tomcat
[[email protected] nrpe-2.12]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[[email protected] nrpe-2.12]# service iptables save
[[email protected] nrpe-2.12]# /etc/init.d/nagios start
Starting nagios: done.
[[email protected] nrpe-2.12]# chkconfig httpd on
[[email protected] nrpe-2.12]# chkconfig nagios on
[[email protected] nrpe-2.12]# chkconfig --add nagios
[[email protected] ~]# vim /usr/local/nagios/etc/nagios.cfg
[[email protected] ~]# 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
[[email protected] ~]# vim /usr/local/nagios/etc/objects/commands.cfg #末尾加
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
[[email protected] ~]# vim /usr/local/nagios/etc/objects/contacts.cfg # 根据自己实际填写邮箱用户名等
[[email protected] ~]# vim /usr/local/nagios/etc/objects/timeperiods.cfg #可不做修改
[[email protected] ~]# vim /usr/local/nagios/etc/objects/localhost.cfg #可不做修改
[[email protected] ~]# vim /usr/local/nagios/etc/objects/templates.cfg #可不做修改
[[email protected] ~]# 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% #自行添加
[[email protected] ~]# cd /usr/local/nagios/etc/objects/
[[email protected] objects]# ls
[[email protected] objects]# cp localhost.cfg web2.cfg
[[email protected] objects]# cp localhost.cfg web1.cfg
[[email protected] 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
}
[[email protected] objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #语法错误检测,因配置文件太多根据错误排错
[[email protected]erver1 etc]# /etc/init.d/nagios restart
被检控节点
[[email protected] ~]# ls
nagios-plugins-1.4.13 nagios-plugins-1.4.13.tar.gz nrpe-2.12.tar.gz
[[email protected] nagios-plugins-1.4.13]# ./configure --prefix=/usr/local/nagios
[[email protected] nagios-plugins-1.4.13# make &&make install
[[email protected] nagios-plugins-1.4.13]# chown -R nagios.nagios /usr/local/nagios/
[[email protected] ~]# tar zxf nrpe-2.12.tar.gz
[[email protected] ~]# cd nrpe-2.12
[[email protected] nrpe-2.12]# ./configure
[[email protected] nrpe-2.12]# make all
[[email protected] nrpe-2.12]# make install-plugin
[[email protected] nrpe-2.12]# make install-daemon
[[email protected] nrpe-2.12]# make install-daemon-config
[[email protected] ~]# 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%
[[email protected] ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[[email protected] ~]# echo "/usr/local/nagios/bin/nrpe
-c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.local
[[email protected] ~]# netstat -nutlp |grep 5666
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 17161/nrpe
[[email protected] ~]# iptables -I INPUT -p tcp --dport 5666 -j ACCEPT
[[email protected] ~]# service iptables save
[[email protected] ~]# /usr/local/nagios/libexec/check_nrpe -H 172.25.135.2
server3和server2同样
浏览器输入:
http://172.25.135.1/nagios/
以上是关于nagios安装配置的主要内容,如果未能解决你的问题,请参考以下文章