监控软件nagios的配置
相关链接:nagios中文网站http://nagios-cn.sourceforge.net/
一、工作原理
nagios是利用插件来进行管理各个服务器的。先在安装有nagios的机器安装三个软件包,一个是nagiso的
所需要的安装包,一个是插件包,一个是nrpe插件包。
二、实验机器设置:192.168.0.254是nagios监控机器,192.168.0.2是被监控机器。
三、在nagios监控服务器上安装包
1.因为nagios是用httpd服务进行管理的,所以需要在监控机器上安装httpd包,还有maysql-server等
以下几个包。
1009 yum install httpd mysql-server php php-server
1010 ls
1011 cd /var/www/html/
1012 ls
1013 vim index.php
在index.php中加入以下一段话
<?php
phpinfo()
?>
1015 service httpd start
2.添加用户nagios和组nagcmd用来管理nagios服务,不建议用root来管理nagios
1018 useradd nagios
1019 passwd nagios
1020 groupadd nagcmd
1021 usermod -G nagcmd nagios
1022 usermod -G nagcmd apache
1024 tar zxvf nagios-3.2.0.tar.gz
1025 date ---如果系统的日期在安装包之前就没法安装,需要修改系统时间
1026 date -s 20090919
1027 date -s 0952
1030 cd nagios-3.2.0
1031 ls
1032 ./configure --help | grep user --查看配置文件的有关加user的选项
1033 ./configure --with-command-user=nagios --with-command-group=nagcmd
1034 make all
1035 make install && make install-init &&make install-commandmode && make install-config && make install-webconf
1036 ls /usr/local/nagios/
1037 ls /etc/httpd/conf.d/nagios.conf --执行make install-webconf会自动在这里生成一个nagios.conf的文件
1038 ls /usr/local/nagios/libexec/
1039 ls /usr/local/nagios/share/
1040 vim /etc/httpd/conf.d/nagios.conf
1041 htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin --加入一个管理帐号
1042 service httpd restart
2.安装插件包
=========================================
1056 tar zxvf nagios-plugins-1.4.13.tar.gz
1057 ls
1058 cd nagios-plugins-1.4.13
1059 ls
1060 ./configure --help | grep user
1061 ./configure --with-nagios-user=nagios --with-nagios-group=nagios
1062 make && make install
1063 ls /usr/local/nagios/libexec/
=========================================
3.安装nrpe插件包
1113 tar zxvf nrpe-2.12.tar.gz
1114 ls
1115 cd nrpe-2.12
1116 ls
1117 ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios
1118 make all
1119 make install-plugin
1120 ls /usr/local/nagios/libexec/check_nrpe
1129 vim /usr/local/nagios/etc/objects/commands.cfg
添加对命令check_nrpe的定义
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
四、在被监控机器上安装包
=========================
192.168.1.2 被监控机器
1.添加帐户nagios用于管理
1008 +191109 useradd nagios
1009 +191109 passwd nagios
2.安装插件包
1056 tar zxvf nagios-plugins-1.4.13.tar.gz
1057 ls
1058 cd nagios-plugins-1.4.13
1010 +191109 ./configure --with-nagios-user=nagios --with-nagios-group=nagios
1011 +191111 ls
1012 +191111 make && make install
1013 +191112 ls /usr/local/nagios/
1014 +191112 ls
1015 +191112 cd /usr/local/nagios/
1016 +191112 ls
1017 +191112 ls
1018 +191112 ls libexec/
1019 +191113 ls
1020 +191113 ls share/
3.安装nrpe插件包
-------------------
998 +191118 cd /root/nrpe-2.12
999 +191118 ls
1000 +191118 ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios
1001 +191119 make all
1003 +191120 ls /usr/local/nagios/libexec/check_nrpe
1004 +191120 make install-plugin
1005 +191120 ls /usr/local/nagios/libexec/check_nrpe
1006 +191120 make install-daemon
1007 +191121 ls /usr/local/nagios/bin/nrpe
1008 +191121 make install-daemon-config
1009 +191121 ls /usr/local/nagios/etc/nrpe.cfg
1010 +191121 make install-xinetd
1011 +191122 vim /etc/xinetd.d/nrpe
4.把服务的端口号加入到services文件中去
1012 +191123 vim /etc/services
内容:nrpe 5666/tcp
1013 +191123 service xinetd restart
1014 +191123 netstat -ntlp | grep 5666
5.本地服务器用nrpe插件的命令查看本地的资源情况。
1015 +191125 /usr/local/nagios/libexec/check_nrpe -H localhost
1016 +191125 /usr/local/nagios/libexec/check_nrpe -H localhost -c check_users
1017 +191126 vim /usr/local/nagios/etc/nrpe.cfg
1018 +191128 fdisk -l
1019 +191128 vim /usr/local/nagios/etc/nrpe.cfg
1020 +191129 service xinetd restart
1021 +191129 vim /usr/local/nagios/etc/nrpe.cfg
1022 +191132 who
1023 +191132 vim /usr/local/nagios/etc/nrpe.cfg
1024 +191133 df -h
1025 +191133 vim /usr/local/nagios/etc/nrpe.cfg
6.定义需要添加的查看命令
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_hda2]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda2
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
7.设定只允许那些机器能查看本地的资源
vim /etc/xinetd.d/nrpe
only_from = 127.0.0.1 192.168.1.254 192.168.1.4
五、nagios监控机器上再对被监控机器192.168.1.2的设定
=============================
192.168.1.254:
1.用已插件在命令行下测试被监控机器的资源情况
1120 ls /usr/local/nagios/libexec/check_nrpe
1121 /usr/local/nagios/libexec/check_nrpe -H 192.168.1.2
1123 /usr/local/nagios/libexec/check_nrpe -H 192.168.1.2 -c check_users
1124 /usr/local/nagios/libexec/check_nrpe -H 192.168.1.2 -c check_load
1125 /usr/local/nagios/libexec/check_nrpe -H 192.168.1.2 -c check_hda1
1126 df -h
1127 /usr/local/nagios/libexec/check_nrpe -H 192.168.1.2 -c check_hda2
2.在nagios配置文件中加入对192.168.1.2的监控配置文件
vim /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/stu2.cfg
cp /usr/local/nagios/etc/objects/localhost.cf stu2.cfg
1128 vim /usr/local/nagios/etc/objects/stu2.cfg
stu2.cfg具体配置查看下面的配置文件
3.用命令测试nagios.cfg有没有错误
1130 /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
4.启动nagios
1097 service nagios start
chkconfig --add nagios
chkconfig --level 35 nagios on
六.在浏览器中访问nagios管理页面
http://192.168.1.254/nagios
输入帐号和密码nagiosadmin
###############################################################################
# stu2.CFG - SAMPLE OBJECT CONFIG FILE FOR MONITORING THIS MACHINE
#
# Last Modified: 05-31-2007
#
# NOTE: This config file is intended to serve as an *extremely* simple
# example of how you can create configuration entries to monitor
# the local (Linux) machine.
#
###############################################################################
###############################################################################
###############################################################################
#
# HOST DEFINITION
#
###############################################################################
###############################################################################
# Define a host for the local machine
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 stu2
alias myclient
address 192.168.1.2
}
###############################################################################
###############################################################################
#
# HOST GROUP DEFINITION
#
###############################################################################
###############################################################################
# Define an optional hostgroup for Linux machines
define hostgroup{
hostgroup_name linux-servers1 ; The name of the hostgroup
alias Linux Servers ; Long name of the group
members stu2 ; Comma separated list of hosts that belong to this group
}
###############################################################################
###############################################################################
#
# SERVICE DEFINITIONS
#
###############################################################################
###############################################################################
# Define a service to "ping" the local machine
define service{
use local-service ; Name of service template to use
host_name stu2
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
# Define a service to check the disk space of the root partition
# on the local machine. Warning if < 20% free, critical if
# < 10% free space on partition.
define service{
use local-service ; Name of service template to use
host_name stu2
service_description / Partition
check_command check_nrpe!check_hda2
}
define service{
use local-service ; Name of service template to use
host_name stu2
service_description /boot Partition
check_command check_nrpe!check_hda1
}
# Define a service to check the number of currently logged in
# users on the local machine. Warning if > 20 users, critical
# if > 50 users.
define service{
use local-service ; Name of service template to use
host_name stu2
service_description Current Users
check_command check_nrpe!check_users
}
# Define a service to check the number of currently running procs
# on the local machine. Warning if > 250 processes, critical if
# > 400 users.
define service{
use local-service ; Name of service template to use
host_name stu2
service_description Total Processes
check_command check_nrpe!check_total_procs
}
define service{
use local-service ; Name of service template to use
host_name stu2
service_description ZombieProcesses
check_command check_nrpe!check_zombie_procs
}
# Define a service to check the load on the local machine.
define service{
use local-service ; Name of service template to use
host_name stu2
service_description Current Load
check_command check_nrpe!check_load
}
# Define a service to check the swap usage the local machine.
# Critical if less than 10% of swap is free, warning if less than 20% is free
#define service{
# use local-service ; Name of service template to use
# host_name localhost
# service_description Swap Usage
# check_command check_local_swap!20!10
# }
# Define a service to check SSH on the local machine.
# Disable notifications for this service by default, as not all users may have SSH enabled.
define service{
use local-service ; Name of service template to use
host_name stu2
service_description SSH
check_command check_ssh
notifications_enabled 1
}
# Define a service to check HTTP on the local machine.
# Disable notifications for this service by default, as not all users may have HTTP enabled.
define service{
use local-service ; Name of service template to use
host_name stu2
service_description HTTP
check_command check_http
notifications_enabled 1
}
define service{
use local-service ; Name of service template to use
host_name stu2
service_description FTP
check_command check_ftp
notifications_enabled 1
}
nagios安装实践
最新推荐文章于 2024-09-23 16:20:09 发布