用 KVM 搭建web集群实验笔记 - nagios 安装配置

Nagios 是一个开源的监控工具,能够监控 windows、Linux等系统的主机状态信息,以及交换机、路由器等网络设备。Nagios有一个主程序(Nagios)、一个插件程序(Nagios-plugins)和一些可选的附加程序 (NPRE、NSClient++、NSCA 和NDAOUtils)等组成。

服务器端:安装nagios和nagios-plugins插件(必选),NDOUtils(可选),存储配置信息和产生的数据。

客服端:linux/unix 安装NRPE组件( 被动方式),windows安装NSClient++组件。

服务器  nagios 192.168.122.34

客户端 nfssvr 192.168.122.41

一、 服务器安装

在nagios上执行操作

1. 配置对时,192.168.122.1为服务器

echo '#time sync by oliver on 2016-09-30 ' >> /var/spool/cron/root
echo '*/5 * * * * /usr/sbin/ntpdate 192.168.122.1 > /dev/null 2>&1' >> /var/spool/cron/root
crontab -l
2. 安装软件

yum install -y gcc glibc glibc-common 
yum install -y gd gd-devel
yum install -y mysql-server mysql-devel
yum install -y httpd php php-gd
3. 创建用户组和用户

/usr/sbin/useradd nagios -g nagios 
/usr/sbin/useradd apache -g nagios -M -s /sbin/nologin

/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd apache
4. 启动httpd

vi /etc/httpd/conf/httpd.conf

设置

ServerName 192.168.122.34:80

service httpd start 或者 /etc/init.d/httpd start

5. 下载nagios的软件包

check_iostat
check_memory.pl
Class-Accessor-0.31.tar.gz
Config-Tiny-2.12.tar.gz
libart_lgpl-2.3.17.tar.gz
Math-Calc-Units-1.07.tar.gz
nagios-3.5.1.tar.gz
Nagios-Plugin-0.34.tar.gz
nagios-plugins-1.4.16.tar.gz
nrpe-2.12.tar.gz
Params-Validate-0.91.tar.gz
pnp-0.4.14.tar.gz
Regexp-Common-2010010201.tar.gz
rrdtool-1.2.14.tar.gz
在网上可以搜到。可以进入http://www.filewatcher.com/ 这个网站搜。

6. 编译nagios-3.5.1.tar.gz

tar -xvf nagios-3.5.1.tar.gz
cd nagios
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf
htpasswd -bc /usr/local/nagios/etc/htpasswd.users nagios 123456
service httpd restart

配置邮件(这一步没有实际测试)

sed -i 's#nagios@localhost#em21@qq.com#g' /usr/local/nagios/etc/objects/contacts.cfg

7. 编译nagios-plugins-1.4.16.tar.gz

tar xvf 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 --with-mysql
make
make install
cd ..
确认configure的输出,然后在执行make 和 make install

config.status: creating po/Makefile
            --with-apt-get-command: 
              --with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s
               --with-ping-command: /bin/ping -n -U -w %d -c %d %s
                       --with-ipv6: yes
                      --with-mysql: /usr/bin/mysql_config
                    --with-openssl: yes
                     --with-gnutls: no
               --enable-extra-opts: no
                       --with-perl: /usr/bin/perl
             --enable-perl-modules: yes
                     --with-cgiurl: /nagios/cgi-bin
               --with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin
                   --enable-libtap: no
8. 编译nrpe-2.12.tar.gz
tar xvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
ls /usr/local/nagios/libexec/check_nrpe
9.启动httpd和nagios
chkconfig httpd on
chkconfig nagios on
二、 客服端安装配置

在nfssvr上操作

1.安装基本软件、增加用户

yum install -y gcc glibc glibc-common
yum install -y mysql-server mysql-devel
yum install -y perl-devel perl-CPAN openssl-devel

useradd nagios -M -s /sbin/nologin

2.编译nagios-plugins-1.4.16.tar.gz

tar -xvf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --with-nagios=nagios --with-nagios-group=nagios --enable-perl-modules --with-mysql
make
make install
cd ..

检查插件个数

[root@nfssvr _soft]# ls /usr/local/nagios/libexec/ |wc -l
58
[root@nfssvr _soft]# 
3.安装插件

#---------------

tar xvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
cd ..

#-------------------------
tar xvf Params-Validate-0.91.tar.gz
cd Params-Validate-0.91
perl Makefile.PL
make
make install
cd ..

#----------------------------------
tar xvf Class-Accessor-0.31.tar.gz
cd Class-Accessor-0.31 
perl Makefile.PL
make
make install
cd ..

#---------------------------------
tar xvf Config-Tiny-2.12.tar.gz
cd Config-Tiny-2.12 
perl Makefile.PL
make
make install
cd ..

#-------------------------------
tar xvf Math-Calc-Units-1.07.tar.gz
cd Math-Calc-Units-1.07
perl Makefile.PL
make
make install
cd ..

#-------------------------------
tar xvf Regexp-Common-2010010201.tar.gz
cd Regexp-Common-2010010201
perl Makefile.PL
make
make install
cd ..

#-------------------------------
tar xvf Nagios-Plugin-0.34.tar.gz
cd Nagios-Plugin-0.34
perl Makefile.PL
make
make install
cd ..

yum install -y sysstat
yum install -y dos2unix

cp /_soft/check_memory.pl /usr/local/nagios/libexec
cp /_soft/check_iostat /usr/local/nagios/libexec
chmod 755 check_memory.pl
chmod 755 check_iostat
dos2unix /usr/local/nagios/libexec/check_memory.pl
dos2unix /usr/local/nagios/libexec/check_iostat
4.配置nrpe服务

[root@nfssvr etc]# cd /usr/local/nagios/etc
[root@nfssvr etc]# sed -n '79'p nrpe.cfg
allowed_hosts=127.0.0.1
[root@nfssvr etc]# sed -i 's#allowed_hosts=127.0.0.1#allowed_hosts=127.0.0.1,192.168.122.34#g' nrpe.cfg
[root@nfssvr etc]# sed -n '79'p nrpe.cfg
allowed_hosts=127.0.0.1,192.168.122.34
vi nrpe.cfg
199~233行替换为
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_memory.pl -w 10% -c 3%
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 15% -c 7% -p /
command[check_hda1]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%  
command[check_hda1]=/usr/local/nagios/libexec/check_iostat -w 6 -c 10
启动nrep服务并检查

/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
netstat -lntup|grep nrpe
ps -ef|grep nrpe |grep -v grep
三、服务器端配置

1.编辑 /usr/local/nagios/etc/nagios.cfg

在34行下增加
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
cfg_dir=/usr/local/nagios/etc/objects/services

注释
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

2. 在ojbects 下将services目录

3. 配置/usr/local/nagios/etc/objects/hosts.cfg

cd /usr/local/nagios/etc/objects
head -51 localhost.cfg > hosts.cfg
chown nagios.nagios /usr/local/nagios/etc/objects/hosts.cfg
增加host
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               nfssvr
        alias                   nfssvr
        address                 192.168.122.41
        }


在组内增加一个成员

define hostgroup{
        hostgroup_name  linux-servers ; The name of the hostgroup
        alias           Linux Servers ; Long name of the group
        members         nfssvr     ; Comma separated list of hosts that belong to this group
        }

4. 配置/usr/local/nagios/etc/objects/services.cfg

touch services.cfg
chown nagios.nagios services.cfg

增加以下内容

define service {
    use                       generic-service
    host_name                 nfssvr
    service_description       Disk Partition
    check_command             check_nrpe!check_disk
}


define service {
    use                       generic-service
    host_name                 nfssvr
    service_description       Swap Useage
    check_command             check_nrpe!check_swap
}

define service {
    use                       generic-service
    host_name                 nfssvr
    service_description       MEM Useage
    check_command             check_nrpe!check_mem
}

define service {
    use                       generic-service
    host_name                 nfssvr
    service_description       Current Load
    check_command             check_nrpe!check_load
}

define service {
    use                       generic-service
    host_name                 nfssvr
    service_description       Disk Iostat
    check_command             check_nrpe!check_iostat!5!11
}

define service {
    use                       generic-service
    host_name                 nfssvr
    service_description       PING
    check_command             check_ping!100.0,20%!500.0,60%
}

5. 配置/usr/local/nagios/etc/objects/commands.cfg

增加以下内容

define command{
       command_name    check_nrpe
       command_line    $USER1$/check_nrpe -h $HOSTADDRESS$ -c $ARG1$
       }
6.建目录

mkdir -p /usr/local/nagios/etc/objects/services
chown -R nagios.nagios services

7. 修改 /usr/local/nagios/etc/cgi.cfg

将授权用户改为nagios,否则用nagios登录,不能查看相应的信息。

grep ^"authorized_for" cgi.cfg
sed -i 's#nagiosadmin#nagios#g' cgi.cfg
8. 验证

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

验证无误后重新启动nagios服务

servie nagios restart

9. 浏览器登录

四、问题诊断

如出现问题,可用以下方法诊断。

1. 检查客服端的nrpe是否能连接上,连接上会打印出版本号

在服务器端操作

[root@nagios libexec]# pwd
/usr/local/nagios/libexec
[root@nagios libexec]# ./check_nrpe -H 192.168.122.41
Connection refused by host
[root@nagios libexec]# ./check_nrpe -H 192.168.122.41
NRPE v2.12
[root@nagios libexec]# 

2. 检查某个service是否正常

在服务器端操作

[root@nagios libexec]# ./check_nrpe -H 192.168.122.41 -c check_mem
OK - 77.9% (391240 kB) free.|TOTAL=502096KB;;;; USED=110856KB;;;; FREE=391240KB;;;; CACHES=54296KB;;;;
[root@nagios libexec]# ./check_nrpe -H 192.168.122.41 -c check_disk
DISK OK - free space: / 8937 MB (90% inode=95%);| /=990MB;8895;9732;0;10465
[root@nagios libexec]# 

如无返回可以倒客服端上执行相应的命令,及在客户端上执行如下命令(在/usr/local/nagios/etc/nrpe.cfg)

[root@nfssvr etc]# /usr/local/nagios/libexec/check_disk -w 15% -c 7% -p /
DISK OK - free space: / 8937 MB (90% inode=95%);| /=990MB;8895;9732;0;10465
[root@nfssvr etc]# 







  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值