Chinaunix首页 | 论坛 | 博客
  • 博客访问: 48251
  • 博文数量: 67
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 380
  • 用 户 组: 普通用户
  • 注册时间: 2015-01-05 15:57
文章分类
文章存档

2015年(67)

我的朋友

分类: LINUX

2015-01-29 09:25:48

CenOS5.6下安装nagios3.2监控服务器群的运行状况

Nagios功能列表 所需软件包及环境
基本的监控:
 NAGIOS gcc、gcc-devel、appache、、gd、gd-devel
 NAGIOS-PLUGINS -devel(防止安装之后无法生存check_mysql的监控文件)
 NRPE openssl-devel  (Linux系统安装。监控端和被监控端)
 NSCLIENT 无(windows系统安装,只安装在被监控端)
邮件告警功能 
 安装centos时候定制软件选择DNS服务和邮件服务.
绘图功能 
 Pnp cairo、 pango、 libart_lgpl、 libart_lgpl-devel、 zlib、 zlib-devel 、freetype 、freetype-devel  
 rrdtool
飞信告警功能 
 Fetion libACE
MSN告警功能
 暂无测试

一:安装nagios

1:安装支持包
#yum -y install gcc gcc-c++ gd gd-devel php httpd openssl-devel mysql-devel
具体依赖的对应服务见上结构

2:添加用户和组
#useradd nagios
#passwd nagios  
#groupadd nagcmd
#usermod -G nagcmd nagios
#usermod -G nagcmd  
记得把apache加入到该用户组
chkconfig httpd on

3:正式安装nagios
tar –xzf nagios-3.2.0.tar.gz
cd nagios-3.2.0
./configure --with-command-group=nagcmd --prefix=/usr/local/nagios
make all
make install
make install-init
make install-config
make install-commandmode

4:配置apache的httpd.conf,允许文件目录被访问
默认安装位置在/etc/httpd/conf/httpd.conf
如何不知道也可以使用如下命令查找
find / name httpd.conf|grep httpd.conf
然后添加以下代码

 

[plain] 

 

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin" 
 
Options ExecCGI 
AllowOverride None 
Order allow,deny 
Allow from all 
AuthName "Nagios Access" 
AuthType Basic 
AuthUserFile /usr/local/nagios/etc/htpasswd.users 
Require valid-user 
 
Alias /nagios "/usr/local/nagios/share" 
 
Options None 
AllowOverride None 
Order allow,deny 
Allow from all 
AuthName "Nagios Access" 
AuthType Basic 
AuthUserFile /usr/local/nagios/etc/htpasswd.users 
Require valid-user 
 

5:创建apache目录验证文件  
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password: (输入密码) 
Re-type new password: (再输入一次密码) 
Adding password for user nagiosadmin 
service httpd restart  

6:安装nagios插件
tar –xzf nagios-plugins-1.4.13.tar.gz
cd nagios-plugins-1.4.13
./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios
make
make install

7:将nagios加入到开机启动项
chkconfig nagios on

8:检查配置文件
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
//这个检测非常有用,可以很快的判断我们的错误在哪里。

9:配置nagios
首先/usr/local/nagios/etc/nagios.cfg,取消前面的”#”即可.如下:

 

[plain] 

 

# 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 the local (Linux) host 
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg 
# Definitions for monitoring a Windows machine 
#cfg_file=/usr/local/nagios/etc/objects/windows.cfg 
# Definitions for monitoring a router/switch 
#cfg_file=/usr/local/nagios/etc/objects/switch.cfg 
# Definitions for monitoring a network printer 
#cfg_file=/usr/local/nagios/etc/objects/printer.cfg 
 
# You can also tell Nagios to process all config files (with a .cfg 
# extension) in a particular directory by using the cfg_dir 
# directive as shown below: 
# cfg_dir=/usr/local/nagios/etc/servers 

上面有些配置文件没有,需要自己手动创建
Commands.cfg主要是监控命令的配置文件。Contacts.cfg主要是联系人的配置文件
Timeperiods.cfg主要是时间配置,监控的时间段设置。Hots.cfg是主机配置.
Localhost.cfg监控的配置文件.
Windows.cfg监控微软系统的配置文件.
chown -R nagios.nagios /usr/local/nagios

10.修改commands.cfg配置文件
新增以下内容:

 

[plain] 

 

# 'check_nrpe' command definition 
define command{ 
command_name check_nrpe 
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ 


11.修改localhost.cfg

 

[plain] 

 

define host { 
host_name nagios-server 
alias nagios server 
address 192.168.152.156 
contact_groups sagroup 
check_command check-host-alive 
max_check_attempts 5 
notification_interval 10 
notification_period 24x7 
notification_options d,u,r 

define hostgroup { 
hostgroup_name sa-servers 
alias sa servers 
members nagios-server 



#加入如下服务(也可以删除当前文件夹下的其他所有service,我删除了否则验证的时候会报错,只预留以下几个)

 

[plain] 

 

define service { 
 host_name nagios-server 
 service_description check-host-alive 
 check_period 24x7 
 max_check_attempts 4 
 noal_check_interval 3 
 retry_check_interval 2 
 contact_groups sagroup 
 notification_interval 10 
 notification_period 24x7 
 notification_options w,u,c,r 
 check_command check-host-alive 

define service { 
 host_name nagios-server 
 service_description check_t 80 
 check_period 24x7 
 max_check_attempts 4 
 normal_check_interval 3 
 retry_check_interval 2 
 contact_groups sagroup 
 notifiion_interval 10 
 notification_period 24x7 
 notification_options w,u,c,r 
 check_command check_tcp!80 

define service{ 
 host_name nagios-server 
 service_description check-disk 
 check_command check_nrpe!check_df 
 max_check_attempts 4 
 normal_check_interval 3 
 retry_check_interval 2 
 check_period 24x7 
 notification_interval 10 
 notification_period 24x7 
 notification_options w,u,c,r 
 contact_grou sagroup 

define service{ 
 host_name nagios-server 
 service_description check-load 
 check_command check_nrpe!check_load 
 max_check_attempts 4 
 normal_check_interval 3 
 retry_check_interval 2 
 check_period 24x7 
 notification_in

  • 本文来自:
阅读(233) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~