到此服务器端的安装部分暂时告一段落
Nagios客户端安装部分
nagios client端基础准备:
echo 'export LC_ALL=C'>> /etc/profile
source /etc/profile #←使修改生效
关闭nagios server iptables防火墙
/etc/init.d/iptables stop
禁止自启动
chkconfig iptables off
解决时间同步
/usr/sbin/ntpdate pool.ntp.org
安装nagios 客户端插件
mkdir -p /home/rhy/tools/nagios
cd /home/rhy/tools/nagios
rz -y #←从本地上传oldboytraining_nagiossoft.zip 或自行下载nagios软件:
unzip oldboytraining_nagiossoft.zip
/usr/sbin/adduser nagios -M
tar zxvf nagios-plugins- 1.4.13 .tar.gz
cd nagios-plugins- 1.4.13
./configure --prefix=/usr/local/nagios --enable-perl-modules --enable-redhat-pthread-workaround
make
make install
cd ..
检查插件个数:
ls /usr/local/nagios/libexec/|wc -l
63
#此编译如遇到make: *** [all] Error 2 则configure加--with-mysql=/usr/local/mysql解决
#如果为red hat linux,可能会卡到如下位置:
configure: See http://nagiosplugins.org/faq/compile/configure_appears_to_hang if this next part takes a long time
checking for redhat spopen problem...
解决:
多等会就OK了。或增加编译参数 --enable-redhat-pthread-workaround重新编译
即:./configure --prefix=/usr/local/nagios --enable-perl-modules --enable-redhat-pthread-workaround
#安装nrpe
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
##生成nrpe.cfg
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 sysstat -y
注*:上文提到的各种插件本文附带了一个大的软件包,用户也可自行去下载
配置开发的几个基础脚本插件
/bin/cp /home/rhy/tools/nagios/training_soft/check_memory.pl /usr/local/nagios/libexec
/bin/cp /home/rhy/tools/nagios/training_soft/check_iostat /usr/local/nagios/libexec #注意路径
chmod 755 /usr/local/nagios/libexec/check_memory.pl
chmod 755 /usr/local/nagios/libexec/check_iostat
dos2unix /usr/local/nagios/libexec/check_memory.pl
dos2unix /usr/local/nagios/libexec/check_iostat
配置nrpe
#config nrpe.cfg cd /usr/local/nagios/etc
vi nrpe.cfg +79
加入可以监控该服务器的nagios server端的IP。
allowed_hosts=127.0.0.1, 172.16.1.196,172.16.1.190 ←主机的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
同时在下面新添加要监控的内容:
启动: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 -j ACCEPT
-A INPUT -s 10.0.0 .0/255.255.255.0 -p udp -m udp -j ACCEPT
测试环境,建议最好先把iptables关掉,等nagios都测试通了在来调试iptables,否则给学习测试增加了复杂度。关闭命令/etc/init.d/iptables stop
配置 nagios 监控服务
以下为server 端的操作
nagios.cfg 基本配置
在 nagios.cfg 文件中找到cfg_file 的部分,进行如下设置:
vi /usr/local/nagios/etc/nagios.cfg +34
#包含配置目录,目录下所有cfg 文件将被包含,通过这种方式便于写脚本批量处理。
需要增加的仅为以下三行
cfg_dir=/usr/local/nagios/etc/ objects/commands
cfg_dir=/usr/local/nagios/etc/ objects/services
cfg_dir=/usr/local/nagios/etc/ objects/hosts
#注*:相关配置文件用途上面已列表格说明,在此不重复了
下面绿色的配置当前不需要添加但以后会经常编辑,因此说明下
# You can specify individual object config files as shown below:
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
# Definitions for monitoring etiantian.org server and service
cfg_file=/usr/local/nagios/etc/objects/host.cfg
cfg_file=/usr/local/nagios/etc/objects/service.cfg
#cfg_file=/usr/local/nagios/etc/objects/servicegroups.cfg
注意:需要注释掉如下localhost.cfg 行,否则和我们要配的会冲突原 36 行
# Definitions for monitoring the local (Linux) host
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
生产库各配置文件实战配置例子写法
nagios 实战实例配置过程细节:
a.配置监控客户端服务器的磁盘分区、Load、Mem、Swap、磁盘io
首先需要在host.cfg 里添加客户端主机和主机组(HOST GROUP)
cd /usr/local/nagios/etc/objects/ #←进入到辅助配置文件的目录
vi host.cfg #←默认情况下host.cfg 是不存在的,需要手工创建
define host {
use linux-server
host_name 197-etiantian-1-1
alias 197-etiantian-1-1
address 172.16.1.197 #←注意是改成客户端的IP
check_command check-host-alive
max_check_attempts 3
normal_check_interval 2
retry_check_interval 2
check_period 24x7
notification_interval 300
notification_period 24x7
notification_options d,u,r
contact_groups admins
process_perf_data 1
}
#######################################################
# HOST GROUP DEFINITION
#create by ryan (qq:49000448)
#######################################################
# Define an optional hostgroup for Linux machines
define hostgroup{
hostgroup_name linux-servers ; The name of the hostgroup
alias Linux Servers ; Long name of the group
members 197-etiantian-1-1
}