Nagios客户端安装
目录
1 概述... 1
a.naglos客户端无需安装lamp环境... 1
b.nagios客户端无需安装nagios服务端软件包... 1
c.nagios客户端需要多安装如下软件包... 1
d.客户端总共需要安装的软件有... 1
2 Nagios客户端安装... 1
步骤1:配置yum.. 1
步骤2:配置profile. 1
步骤3:关闭防火墙... 1
步骤4:配置时间同步 config time sync. 1
步骤5: 添加nagios用户... 1
步骤6:解压nagios 软件... 1
步骤7:安装nagio-plugins. 1
步骤8:安装nrpe. 1
步骤9:安装iostat软件... 1
步骤10:修改nrep.conf1
步骤11:启动nagios 客户端... 1
3 错误收集:... 1
1 概述
和nagios服务端相比,nagios客户端不需要安装如下内容:
a.naglos客户端无需安装lamp环境
yum install gd gd-devel -y
yum install mysql* -y
yum install httpd php php-gd -y
b.nagios客户端无需安装nagios服务端软件包
nagios-3.5.1.tar.gz
c.nagios客户端需要多安装如下软件包
Class-Accessor-0.31.tar.gz
Config-Tiny-2.12.tar.gz
Math-Calc_Units-1.07.tar.gz
Nagios-Plugin-0.34.tar.gz
Params-Validate-0.91.tar.gz
Regexp-Common-2010010201.tar.gz
check_iostat
check_memory.pl
nrpe-2.12.tar.gz
d.客户端总共需要安装的软件有
yum install gcc glibc glibc-common -y
yum install mysql* -y
nagios-plugins-1.4.16.tar.gz
nrpe-2.12.tar.gz
Class-Accessor-0.31.tar.gz
Config-Tiny-2.12.tar.gz
Math-Calc-Units-1.07.tar.gz
Nagios-Plugin-0.34.tar.gz
Params-Validate-0.91.tar.gz
Regexp-Common-2010010201.tar.gz
check_iostat
check_memory.pl
2 Nagios客户端安装
步骤1:配置yum
[root@nagios ~]# cd /etc/yum.repos.d/
[root@nagiosyum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
步骤2:配置profile
[root@nagios yum.repos.d]# echo 'exportLC_ALL=C'>> /etc/profile
[root@nagios yum.repos.d]# source /etc/profile
[root@nagios yum.repos.d]#
步骤3:关闭防火墙
[root@nagios yum.repos.d]#
[root@nagiosyum.repos.d]# /etc/init.d/iptables stop
[root@nagiosyum.repos.d]# chkconfig iptables off
[root@nagios yum.repos.d]#
[root@nagios yum.repos.d]#
[root@nagiosyum.repos.d]# setenforce 0
[root@nagiosyum.repos.d]# vi /etc/selinux/config
# This file controls the state of SELinux on thesystem.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
"/etc/selinux/config" 13L, 457C written
[root@nagios yum.repos.d]#
步骤4:配置时间同步 config time sync
[root@nagios ~]#
[root@nagios~]# /usr/sbin/ntpdate pool.ntp.org
[root@nagios~]# echo '#time sync by oldboy at 2015-07-01'>>/var/spool/cron/root
[root@nagios~]# echo '*/10 * * * * /usr/sbin/ntpdate pool.ntp.org >/dev/null2>&1'>>/var/spool/cron/root
[root@nagios~]# crontab -l
步骤5: 添加nagios用户
echo"------ step 1: add nagios user------"
#createuser group
/usr/sbin/useradd-m nagios -s /sbin/nologin
#create user group
/usr/sbin/useradd -m nagios -s/sbin/nologin
步骤6:解压nagios 软件
echo "------ step 2: unzip nagiossoft------"
mkdir -p/home/oldboy/tools/
cd/home/oldboy/tools/
[ ! -f ./oldboy_training_nagios_soft.zip ]&&{
echo"nagios soft is not exist."
exit 1
}
/bin/cpoldboy_training_nagios_soft.zip /home/oldboy/tools/
cd/home/oldboy/tools/
步骤7:安装nagio-plugins
echo"------ step 3: install nagios-plugins------"
yum -yinstall perl-devel
tar zxfnagios-plugins-1.4.16.tar.gz
cdnagios-plugins-1.4.16
./configure--prefix=/usr/local/nagios --enable-perl-modules--enable-redhat-pthread-workaround
make&& make install
cd ../
ls/usr/local/nagios/libexec/|wc -l
步骤8:安装nrpe
和服务端一样
echo "------ step 4: install nrpe------"
cd/home/oldboy/tools/
tar zxfnrpe-2.12.tar.gz
cdnrpe-2.12
./configure
make all
makeinstall-plugin
makeinstall-daemon
makeinstall-daemon-config
cd ..
步骤9:安装iostat软件
echo"------ step 4: install soft for iostat------"
cd/home/oldboy/tools/
tar zxvfParams-Validate-0.91.tar.gz
cdParams-Validate-0.91
perlMakefile.PL
make
makeinstall
cd ..
#----------------------------------------
cd/home/oldboy/tools/
tar zxvfClass-Accessor-0.31.tar.gz
cdClass-Accessor-0.31
perlMakefile.PL
make
makeinstall
cd ..
#----------------------------------------
cd/home/oldboy/tools/
tar zxvfConfig-Tiny-2.12.tar.gz
cdConfig-Tiny-2.12
perlMakefile.PL
make
makeinstall
cd ..
#----------------------------------------
cd/home/oldboy/tools/
tar zxvfMath-Calc-Units-1.07.tar.gz
cdMath-Calc-Units-1.07
perlMakefile.PL
make
makeinstall
cd ..
#----------------------------------------
cd/home/oldboy/tools/
tar zxvfRegexp-Common-2010010201.tar.gz
cdRegexp-Common-2010010201
perlMakefile.PL
make
makeinstall
cd ..
#----------------------------------------
cd/home/oldboy/tools/
tar zxvfNagios-Plugin-0.34.tar.gz
cdNagios-Plugin-0.34
perlMakefile.PL
make
makeinstall
cd ..
#______________________
#formonitor iostat
yuminstall sysstat -y
/bin/cp/home/oldboy/tools/check_memory.pl /usr/local/nagios/libexec
/bin/cp/home/oldboy/tools/check_iostat /usr/local/nagios/libexec
chmod755 /usr/local/nagios/libexec/check_memory.pl
chmod755 /usr/local/nagios/libexec/check_iostat
dos2unix/usr/local/nagios/libexec/check_memory.pl
dos2unix/usr/local/nagios/libexec/check_iostat
##################################################
或者参考如下:
#安装其它相关的插件
cd /home/oldboy/tools/oldboy_nagios/
tarzxvf Params-Validate-0.91.tar.gz
cd Params-Validate-0.91
perl Makefile.PL
make
make install
cd ..
#--------------------------------------
cd /home/oldboy/tools/oldboy_nagios/
tarzxvf Class-Accessor-0.31.tar.gz
cd Class-Accessor-0.31
perl Makefile.PL
make
make install
cd ..
#--------------------------------------
cd /home/oldboy/tools/oldboy_nagios/
tarzxvf Config-Tiny-2.12.tar.gz
cd Config-Tiny-2.12
perl Makefile.PL
make
make install
cd ..
#--------------------------------------
cd /home/oldboy/tools/oldboy_nagios/
tarzxvf Math-Calc-Units-1.07.tar.gz
cd Math-Calc-Units-1.07
perl Makefile.PL
make
make install
cd ..
#--------------------------------------
cd /home/oldboy/tools/oldboy_nagios/
tarzxvf Regexp-Common-2010010201.tar.gz
cd Regexp-Common-2010010201
perl Makefile.PL
make
make install
cd ..
#--------------------------------------
cd /home/oldboy/tools/oldboy_nagios/
tarzxvf Nagios-Plugin-0.34.tar.gz
cd Nagios-Plugin-0.34
perl Makefile.PL
make
make install
cd ..
#--------------------------------------
#for monitor iostat
yuminstall sysstat -y
注*:上文提到的各种插件本文附带了一个大的软件包,用户也可自行去下载
配置开发的几个基础脚本插件
#注意路径
/bin/cp/home/oldboy/tools/oldboy_nagios/check_memory.pl /usr/local/nagios/libexec
/bin/cp/home/oldboy/tools/oldboy_nagios/check_iostat /usr/local/nagios/libexec
chmod755 /usr/local/nagios/libexec/check_memory.pl
chmod755 /usr/local/nagios/libexec/check_iostat
dos2unix/usr/local/nagios/libexec/check_memory.pl
dos2unix/usr/local/nagios/libexec/check_iostat
[root@client01 oldboy_nagios]#
[root@client01oldboy_nagios]# ls /usr/local/nagios/libexec/|wc -l
62
[root@client01 oldboy_nagios]#
步骤10:修改nrep.conf
echo "------ step 5: 修改nrpe.cfg------"
perl -pi-e 's/allowed_hosts=127.0.0.1/allowed_hosts=127.0.0.1,192.168.1.19/g'/usr/local/nagios/etc/nrpe.cfg
#delete 199--203
cp/usr/local/nagios/etc/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg.ori
sed -i'199,203d' /usr/local/nagios/etc/nrpe.cfg
echo"command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,6 -c30,25,20">>/usr/local/nagios/etc/nrpe.cfg
echo"command[check_mem]=/usr/local/nagios/libexec/check_memory.pl -w 6% -c3%">>/usr/local/nagios/etc/nrpe.cfg
echo"command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 8% -p/">>/usr/local/nagios/etc/nrpe.cfg
echo"command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c10%">>/usr/local/nagios/etc/nrpe.cfg
echo"command[check_iostat]=/usr/local/nagios/libexec/check_iostat -w 6 -c10">>/usr/local/nagios/etc/nrpe.cfg
或者通过如下方法:
[root@client01 oldboy_nagios]#
[root@client01oldboy_nagios]# cd /usr/local/nagios/etc/
[root@client01 etc]# ls
nrpe.cfg
[root@client01etc]# cp nrpe.cfg nrpe.cfg.ori
[root@client01etc]# vi nrpe.cfg +79
#加入可以监控该服务器的nagios server端的IP
allowed_hosts=127.0.0.1,192.168.1.19 #主机的IP
#shift+g到结尾
#注释掉或者干脆删除199-203行即下面几行
#command[check_users]=/usr/local/nagios//libexec/check_users-w 5 -c 10
#command[check_load]=/usr/local/nagios//libexec/check_load-w 15,10,5 -c 30,25,20
#command[check_hda1]=/usr/local/nagios//libexec/check_disk-w 20% -c 10% -p /dev/hda1
#command[check_zombie_procs]=/usr/local/nagios//libexec/check_procs-w 5 -c 10 -s Z
#command[check_total_procs]=/usr/local/nagios//libexec/check_procs-w 150 -c 200
#同时在下面新添加要监控的内容:
echo"command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,6 -c30,25,20">>/usr/local/nagios/etc/nrpe.cfg
echo"command[check_mem]=/usr/local/nagios/libexec/check_memory.pl -w 6% -c3%">>/usr/local/nagios/etc/nrpe.cfg
echo"command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 8% -p/">>/usr/local/nagios/etc/nrpe.cfg
echo"command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c10%">>/usr/local/nagios/etc/nrpe.cfg
echo"command[check_iostat]=/usr/local/nagios/libexec/check_iostat -w 6 -c10">>/usr/local/nagios/etc/nrpe.cfg
步骤11:启动nagios 客户端
echo "------ step 6: start nagiosclient------"
#startnagios client
pkillnrpe
sleep 2
/usr/local/nagios/bin/nrpe-c /usr/local/nagios/etc/nrpe.cfg -d
echo "#nagios nrpe process cmd by oldboy2012-6-7" >> /etc/rc.local
echo"/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg-d">>/etc/rc.local
netstat-lnt|grep 5666 && echo "nagios client is ok"
或者:
启动:nagios client
/usr/local/nagios/bin/nrpe -c/usr/local/nagios/etc/nrpe.cfg -d
echo "/usr/local/nagios/bin/nrpe -c/usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.local
ps -ef|grep nagios
nagios 28466 1 0 21:50 ? 00:00:00/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
注意:
1、#执行完启动命令,进行检查是个良好的习惯
2、tips:重起nagios nrpe组合命令
pkill nrpe && /usr/local/nagios/bin/nrpe -c/usr/local/nagios/etc/nrpe.cfg -d
另外注意防火墙要允许5666端口加到/etc/sysconfig/iptables里,重起iptables.
vi /etc/sysconfig/iptables
-A INPUT -p udp --dport 5666 -j ACCEPT
-A INPUT -s 10.0.0.0/255.255.255.0 -p tcp -m tcp -jACCEPT
-A INPUT -s 10.0.0.0/255.255.255.0 -p udp -m udp -jACCEPT
测试环境,建议最好先把iptables关掉,等nagios都测试通了在来调试iptables,否则给学习测试增加了复杂度。关闭命令/etc/init.d/iptables stop
3 错误收集:
错误1:
[root@client01 oldboy_nagios]# dos2unix/usr/local/nagios/libexec/check_memory.pl
-bash: dos2unix: command not found
[root@client01 oldboy_nagios]#
处理方法:
yuminstall dos2unix -y
4 参见文档:
ww.bkjia.com/xtzh/973463.html