Nagios

开始安装

安装nagios-3.2.1.tar.gz到/usr/local/src

到/usr/local/src/nagios-3.2.1/html/docs用过以下命令找到帮助文档firefox index.html

http://192.168.22.14/nagios/




During portions of the installation you'll need to have root access to your machine.

Make sure you've installed the following packages on your Fedora installation before continuing.

    * Apache
    * PHP
    * GCC compiler
    * GD development libraries
yum install httpd php

yum install gcc glibc glibc-common

yum install gd gd-devel

Create a new nagios user account and give it a password.

/usr/sbin/useradd -m nagios

passwd nagios

Create a new nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user to the group.

/usr/sbin/groupadd nagcmd

/usr/sbin/usermod -a -G nagcmd nagios

/usr/sbin/usermod -a -G nagcmd apache

tar xzf nagios-3.2.1.tar.gz

cd nagios-3.2.1

Run the Nagios configure script, passing the name of the group you created earlier like so:

./configure --with-command-group=nagcmd


Compile the Nagios source code.

make all

Install binaries, init script, sample config files and set permissions on the external command directory.

make install

make install-init

make install-config

make install-commandmode


Don't start Nagios yet - there's still more that needs to be done...

Install the Nagios web config file in the Apache conf.d directory.

make install-webconf

Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account - you'll need it later.

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin


Restart Apache to make the new settings take effect.

service httpd restart

6) Compile and Install the Nagios Plugins

Extract the Nagios plugins source code tarball.

cd ~/downloads

tar xzf nagios-plugins-1.4.11.tar.gz

cd nagios-plugins-1.4.11

Compile and install the plugins.

./configure --with-nagios-user=nagios --with-nagios-group=nagios

make

make install

Add Nagios to the list of system services and have it automatically start when the system boots.

chkconfig --add nagios

chkconfig nagios on

Verify the sample Nagios configuration files.

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


If there are no errors, start Nagios.

service nagios start

监听本地服务

创建测试文件
cp  /usr/local/nagios/etc/objects/{localhost.cfg,192.168.22.6.cfg}

修改测试文件
vim /usr/local/nagios/etc/objects/192.168.22.6.cfg

注释这个hostgroup
#define hostgroup{
#        hostgroup_name  linux-servers ; The name of the hostgroup
#        alias           Linux Servers ; Long name of the group
#        members         localhost     ; Comma separated list of hosts that belong to this group
#        }


配置修改如下
define host{
        use                     linux-server    
        host_name               testserver
        alias                   host196
        address                 192.168.1.196
        }

#define hostgroup{
#        hostgroup_name  testserver ; The name of the hostgroup
#        alias           host; Long name of the group
#        members         localhost   ; Comma separated list of hosts that belong to this group
}
define service{
        use                             local-service
        host_name                       testserver
        service_description             PING
        check_command                   check_ping!100.0,20%!500.0,60%
        }

define service{
        use                             local-service  
    host_name                       testserver
        service_description             HTTP
        check_command                   check_http
#       notifications_enabled           0
        }

define service{
        use                             local-service
        host_name                       testserver
        service_description             NFS
        check_command                   check_tcp!2049
#       notifications_enabled           0
        }



保存后退出


vim /etc/init.d/nagios 编辑 功能为显示错误信息
189(行)                 $NagiosBin -v $NagiosCfgFile #> /dev/null 2>&1; (加个#号)
修改 vim /usr/local/nagios/etc/nagios.cfg
添加如下 :一般为36行 这行(cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
)下面添加你刚才创建的.cfg文件
cfg_file=/usr/local/nagios/etc/objects/192.168.22.7.cfg

保存退出
service nagios restart
chkconfig nagios on
servic     httpd restart
chkconfig httpd on

firefox -b &  打开浏览器命令
然后输入 http://localhost/nagios
输入用户名 : nagiosadmin  依据自己配置输入用户名和密码 然后查看
密码            :  123

监听主机其他服务需要调用的脚本和配置的文件

ls /usr/local/nagios/libexec 查看是否用相关插件   #这里可以通过./chek_apt --help 查询到每个插件脚本使用的方法,然后设置监听的服务,需要知道各种服务使用的基本命令或者是传输协议。
[root@7 libexec]# ls
check_apt       check_ftp           check_mailq     check_ping     check_time
check_breeze    check_http          check_mrtg      check_pop      check_udp
check_by_ssh    check_icmp          check_mrtgtraf  check_procs    check_ups
check_clamd     check_ide_smart     check_nagios    check_real     check_users
check_cluster   check_ifoperstatus  check_nntp      check_rpc      check .....等等


如果有相关插件(如果没有就得自己去写或者下载) 在/usr/local/nagios/etc/objects/commands.cfg 最后一行定义命令
vim /usr/local/nagios/etc/objects/commands.cfg
最后一行定义命令
define command{
        command_name  check_nfs   定义命令调用的脚本检查nfs的端口是否打开来判断nfs服务是否开启
        command_line  $USER1$/check_tcp -H $HOSTADDRESS$ -p $ARG1$ -w $ARG2$ -c $ARG3$
}


编辑你要监控的主机配置文件 /usr/local/nagios/etc/objects/192.168.22.6.cfg
cp /usr/local/nagios/etc/objects/{localhost.cfg,192.168.22.6.cfg}
vim /usr/local/nagios/etc/objects/192.168.22.6.cfg 修改
# Define a host for the local machine
define host{
        use                     linux-server            ; Name of host template to use
                                                        ; in (or inherited by) the linux-server host template definition.
        host_name               lihaiyang.com
        alias                   lihaiyang
        address                 192.168.22.6
    .
    .
    .在最后添加一下刚刚定义的命令
define service{
        use                             local-service
        host_name                       lihaiyang.com
        check_command                   check_nfs!2049
        notifications_enabled           0
}

保存退出
service nagios restart 重启服务后查看
firefox -b & 开启浏览器

远程监控私有服务

原理

服务端
                                                  |check_disk     
nagios->check_nrpe插件----ssl---->nrpe|check_load
                                                         |check_user        

server端

安装nrpe
tar -zxvf nrpe-2.12.tar.gz -C /usr/local/src/
cd /usr/local/src/nrpe-2.12/
./configure && make all && make install
make install-plugin                      设置插件权限



ls /usr/local/nagios/libexec 查看是否用相关插件
[root@7 libexec]# ls
check_apt       check_ftp           check_mailq     check_overcr   check_tcp
check_breeze    check_http          check_mrtg      check_ping     check_time
check_by_ssh    check_icmp          check_mrtgtraf  check_pop      check_udp
check_clamd     check_ide_smart     check_nagios    check_procs    check_ups
check_cluster   check_ifoperstatus  check_nntp      check_real     check_users .....等等

[root@6 libexec]# ./check_nrpe  查看定义的参数和方法


[root@6 libexec]# head -30 /etc/services  查看相关服务端口
tcpmux          1/tcp                           # TCP port service multiplexer
tcpmux          1/udp                           # TCP port service multiplexer
rje             5/tcp                           # Remote Job Entry
rje             5/udp                           # Remote Job Entry
echo            7/tcp
echo            7/udp
discard         9/tcp           sink null
discard         9/udp           sink null
systat          11/tcp          users

定义nrpe
cd /usr/local/nagios/etc/objects
vim commands.cfg 在该文件最末行后定义check_nrpe插件的调用参数
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ 此处 -c 为警告 请注意添加,如果没有就没有警告
}


cd /usr/local/nagios/etc/objects/
vim 192.168.1.100.cfg          配置文件
在最后添加如下两个service
define service{
    use             local-service ;
    host_name           ZHB-linux
    service_description Root Partition
    check_command       check_nrpe!check_root
}
定义调用命令及参数check_root 该参数会在客户端定义相对应的命令以达到通过该参数检测客户端硬盘使用率的信息

define service{
    use                 local-service ;模板templates.cfg
    host_name           ZHB-linux
    service_description Current Users
    check_command         check_nrpe!check_u
}
命令作用同上,server端同上


vim /usr/local/nagios/etc/nagios.cfg
在大约36行之后添加 你刚刚修改的要监控的配置文件
cfg_file=/usr/local/nagios/etc/objects/192.168.1.7.cfg




client端

安装nagios-plugins包
yum -y install openssl openssl-devel
tar -zxvf nagios-plugins-1.4.14.tar.gz -C /usr/local/src
useradd nagios     添加用户以及组
groupadd nagcmd
usermod -G nagcmd nagios
cd /usr/local/src/nagios-plugins-1.4.14
./configure && make && make install

安装nrpe
  tar -zxvf nrpe-2.12.tar.gz  -C /usr/local/src/
 cd /usr/local/src/nrpe-2.12/
./configure && make all && make install
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd    产生xinetd的配置文件nrpe

安装xinetd
yum -y install xinetd
设置nrpe及启动
在源文件/etc/xinet.d/nrpe文件里
vim /etc/xinetd.d/nrpe
service nrpe
{
        flags           = REUSE
        socket_type     = stream
        port            = 5666
        wait            = no
        user            = nagios
        group           = nagios
        server          = /usr/local/nagios/bin/nrpe
        server_args     = -c /usr/local/nagios/etc/nrpe.cfg --inetd
        log_on_failure  += USERID
        disable         = no
        only_from       = 127.0.0.1 192.168.22.7    
}
#注意 only_from     =127.0.0.1 后添加 192.168.1.1(服务端ip)

定义nrpe命令(check_root)
cd /usr/local/nagios/etc
vi nrpe.cfg
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_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 (默认已写好不用添加)
新添加如下一句
command[check_root]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda2(新加对应文件)
                                                                        剩余20%警告   10%为严重警告发邮件                

添加nrpe对应的端口(必须做)
vim /etc/services (该文件记录系统中所有服务的端口)
在最后一行添加
nrpe 5666/tcp # NRPE

启动nrpe
service xinetd restart
netstat -anptl | grep 5666  查看端口是否打开
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 21403/xinetd



服务端
service nagios restart
1测试nrpe
cd /usr/local/nagios/libexec/
./check_nrpe -H 192.168.1.170   注意 此IP是被监控端的IP
得到结果NRPE v2.12  如果出现则正确
2测试 是否有错误
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 检测文件时候正确
service nagios restart
访问http://192.168.1.160/nagios/
 
或者在本地监控端浏览器 里Sort by service name (descending)    Status Sort by service status (ascending)Sort by service status (descending)    Last Check Sort by last check time (ascending)Sort by last check time (descending)    Duration Sort by state duration (ascending)Sort by state duration time (descending)    Attempt Sort by current attempt (ascending)Sort by current attempt (descending)    Status Information
7.com
    
    
Current Users
    
    PENDING     N/A     0d 0h 0m 55s+     1/4     Service check scheduled for Sun Mar 31 03:26:27 CST 2013
    
Root Partition
    
    PENDING http://localhost/nagios


#####################################
小知识库
vim /etc/init.d/nagios 编辑 功能为显示nagios重启时的错误信息
189(行)                 $NagiosBin -v $NagiosCfgFile #> /dev/null 2>&1; (加个#号)

显示所有服务的端口 用于查看服务端口号
vim /etc/services

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值