编译安装nagios
yum install -y gcc glibc glibc-common gd gd-devel httpd php php-gd mysql* sendmail
unzip nagios.zip
useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache
echo 'export LC_ALL=C'>>/etc/profile
source /etc/profile
tar zxvf nagios-3.5.1.tar.gz
cd nagios
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
创建htpasswd.users,并添加nagios网页登录的用户密码
htpasswd -cb /usr/local/nagios/etc/htpasswd.users nagios 123456
打开浏览器,输入本机ip地址/nagios进行访问
#在34行修改email地址
vim /usr/local/nagios/etc/objects/contacts.cfg
编译安装nagios-plugins插件
tar zxvf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules
make
make install
#检查nagios语法
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios checkconfig
#启动nagios
/etc/init.d/nagios start
编译安装nrpe
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
创建hosts,services.cfg,services
cd /usr/local/nagios/etc/objects
head -51 localhost.cfg > hosts.cfg
#hosts.cfg实例配置
cat hosts.cfg
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 192.168.1.171
alias 192.168.1.171
address 192.168.1.171
}
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 192.168.1.172
alias 192.168.1.172
address 192.168.1.172
}
define hostgroup{
hostgroup_name linux-servers ; The name of the hostgroup
alias Linux Servers ; Long name of the group
members 192.168.1.171,192.168.1.172 ; Comma separated list of hosts that belong to this group
}
touch services.cfg
mkdir services
#添加客户端配置文件,实例
vim services/192.168.1.171.cfg
define service{
use generic-service
host_name 192.168.1.171
service_description Disk Partition
check_command check_nrpe!check_disk
}
define service{
use generic-service
host_name 192.168.1.171
service_description mem
check_command check_nrpe!check_mem
}
define service{
use generic-service
host_name 192.168.1.171
service_description load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name 192.168.1.171
service_description swap
check_command check_nrpe!check_swap
}
define service{
use generic-service
host_name 192.168.1.171
service_description iostat
check_command check_nrpe!check_iostat
}
define service{
use generic-service
host_name 192.168.1.171
service_description http
check_command check_http!192.168.1.171
}
define service{
use generic-service
host_name 192.168.1.171
service_description phpmyadmin
check_command check_http!192.168.1.171 -u /phpmyadmin/
}
define service{
use generic-service
host_name 192.168.1.171
service_description ping
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use generic-service
host_name 192.168.1.171
service_description port_80
check_command check_tcp!80
}
define service{
use generic-service
host_name 192.168.1.171
service_description mysql
check_command check_mysql!192.168.1.171
}
vim services/192.168.1.172.cfg
define service{
use generic-service
host_name 192.168.1.172
service_description Disk Partition
check_command check_nrpe!check_disk
}
define service{
use generic-service
host_name 192.168.1.172
service_description mem
check_command check_nrpe!check_mem
}
define service{
use generic-service
host_name 192.168.1.172
service_description load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name 192.168.1.172
service_description swap
check_command check_nrpe!check_swap
}
define service{
use generic-service
host_name 192.168.1.172
service_description iostat
check_command check_nrpe!check_iostat
}
define service{
use generic-service
host_name 192.168.1.172
service_description mysql
check_command check_mysql!192.168.1.172
}
chown -R nagios.nagios *
#添加命令,commands.cfg配置实例
vim commands.cfg
#将227到238替换为以下内容
# 'process-host-perfdata' command definition
define command{
command_name process-host-perfdata
command_line /usr/local/nagios/libexec/process_perfdata.pl
}
# 'process-service-perfdata' command definition
define command{
command_name process-service-perfdata
command_line /usr/local/nagios/libexec/process_perfdata.pl
}
在结尾添加
# 'check_nrpe' command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
# 'check_mysql' command definition
define command{
command_name check_mysql
command_line $USER1$/check_mysql -H $HOSTADDRESS$ -u root -p 123456
}
修改用户权限
vim /usr/local/nagios/etc/cgi.cfg
#将nagiosadmin用户替换为nagios,nagios为登录的用户,替换后才能出图
g/nagiosadmin/s//nagios/g
安装出图插件
yum install -y cairo pango zlib zlib-devel freetype freetype-devel gd gd-devel
tar zxvf libart_lgpl-2.3.17.tar.gz
cd libart_lgpl-2.3.17
./configure
make
make install
cp -r /usr/local/include/libart-2.0 /usr/include/
cd ..
tar zxvf rrdtool-1.2.14.tar.gz
cd rrdtool-1.2.14
./configure --prefix=/usr/local/rrdtool --disable-python --disable-tcl
make
make install
cd ..
tar zxvf pnp-0.4.14.tar.gz
cd pnp-0.4.14
./configure --with-rrdtool=/usr/local/rrdtool/bin/rrdtool --with-perfdata-dir=/usr/local/nagios/share/perfdata/
make all
make install
make install-config
make install -init
cd ..
vim nagios.cfg
#在35行添加
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_dir=/usr/local/nagios/etc/objects/services
#注释40行左右的下面这一行
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
#修改835行,将0改为1
process_performance_data=1
#取消847、848行的注释
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata
vim templates.cfg
#在linux-server中添加下列配置,大概在83行
process_perf_data 1
action_url /nagios/pnp/index.php?host=$HOSTNAME$
#在generic-service中添加下列配置,大概在179行
action_url /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
客户端插件安装
useradd nagios -M -s /sbin/nologin
echo 'export LC_ALL=C'>>/etc/profile
source /etc/profile
unzip nagios.zip
tar zxvf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules
make
make install
cd ..
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
cd ..
tar zxvf Params-Validate-0.91.tar.gz
cd Params-Validate-0.91
perl Makefile.PL
make
make install
cd ..
tar zxvf Class-Accessor-0.31.tar.gz
cd Class-Accessor-0.31
perl Makefile.PL
make
make install
cd ..
tar zxvf Config-Tiny-2.12.tar.gz
cd Config-Tiny-2.12
perl Makefile.PL
make
make install
cd ..
tar zxvf Math-Calc-Units-1.07.tar.gz
cd Math-Calc-Units-1.07
perl Makefile.PL
make
make install
cd ..
tar zxvf Regexp-Common-2010010201.tar.gz
cd Regexp-Common-2010010201
perl Makefile.PL
make
make install
cd ..
tar zxvf Nagios-Plugin-0.34.tar.gz
cd Nagios-Plugin-0.34
perl Makefile.PL
make
make install
cd ..
yum install -y sysstat dos2unix
cp check_iostat /usr/local/nagios/libexec/
cp check_memory.pl /usr/local/nagios/libexec/
cd /usr/local/nagios/libexec/
chmod 755 check_iostat
chmod 755 check_memory.pl
dos2unix check_iostat
dos2unix check_memory.pl
配置nrpe
vim /usr/local/nagios/etc/nrpe.cfg
在第79行填写监控服务器地址
allowed_hosts=192.168.1.178
将199到203行替换为以下内容
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_mem]=/usr/local/nagios/libexec/check_memory.pl -w 10% -c 3%
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 15% -c 7% -p /
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
command[check_iostat]=/usr/local/nagios/libexec/check_iostat -w 6 -c 10
启动nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d