linux下nagios的搭建以及故障问题

nagios搭建过程:

一、搭建监控中心:

一、安装前的准备
1. 支持php
# yum -y install httpd php gd gd-devel libpng libpng-devel libjpeg libjpeg-devel zlib zlib-devel openssl-devel
# service httpd restart
# chkconfig httpd on
# vim /var/www/html/index.php
<?php
phpinfo();
?>

2. 确定当前主机邮件系统工作正常
# yum -y install postfix
# chkconfig postfix on
# service postfix restart
# echo "mail test..." |mail -s "nagios mail test" root@localhost //发往本机用户
# echo "mail test..." |mail -s "nagios mail test" tianyun@126.com //测试往外网用户发送邮件

二、监控中心Nagios
1. 主程序安装
[root@master ~]# groupadd nagcmd
[root@master ~]# useradd nagios -G nagcmd //组nagcmd用于从Web接口执行外部命令
[root@master ~]# gpasswd -a apache nagcmd
[root@master ~]# grep nagcmd /etc/group
nagcmd:x:500:nagios,apache

[root@master ~]# tar xvf nagios-3.2.0.tar.gz
[root@master ~]# cd nagios-3.2.0
[root@master nagios-3.2.0]# ./configure --prefix=/usr/local/nagios \
--with-command-group=nagcmd
[root@master nagios-3.2.0]# make all
[root@master nagios-3.2.0]# make install //安装nagios的主程序,CGI和HTML文件
[root@master nagios-3.2.0]# make install-init //生成/etc/rc.d/init.d/nagios启动脚本
[root@master nagios-3.2.0]# make install-config //安装示例配置文件,路径/usr/local/nagios/etc
[root@master nagios-3.2.0]# make install-commandmode //设定相应nagios工作目录的权限
[root@master nagios-3.2.0]# make install-webconf //安装Nagios的WEB配置文件到
Apache的conf.d目录下
[root@master ~]# ls /usr/local/nagios/ //查看nagios安装文件
bin etc libexec sbin share var
[root@master ~]# ls /usr/local/nagios/libexec/ //目前没有任何插件

2. 插件安装
[root@master ~]# tar xvf nagios-plugins-1.4.14.tar.gz
[root@master ~]# cd nagios-plugins-1.4.14
[root@master nagios-plugins-1.4.14]# ./configure \
--with-nagios-user=nagios \
--with-nagios-group=nagcmd \
--prefix=/usr/local/nagios
[root@master nagios-plugins-1.4.14]# make
[root@master nagios-plugins-1.4.14]# make install
[root@master ~]# ls /usr/local/nagios/libexec/
check_apt check_file_age check_log check_oracle check_tcp
check_breeze check_flexlm check_mailq check_overcr check_time
check_by_ssh check_ftp check_mrtg check_ping check_udp
check_clamd check_http check_mrtgtraf check_pop check_ups
check_cluster check_icmp check_nagios check_procs check_users
check_dhcp check_ide_smart check_nntp check_real check_wave
check_dig check_ifoperstatus check_nt check_rpc negate
check_disk check_ifstatus check_ntp check_sensors urlize
check_disk_smb check_imap check_ntp_peer check_smtp utils.pm
check_dns check_ircd check_ntp_time check_ssh utils.sh
check_dummy check_load check_nwstat check_swap

3. Apache访问控制
[root@master ~]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin

4. 启动nagios,httpd
[root@master ~]# chkconfig nagios on
[root@master ~]# service nagios start
Starting nagios: done.
[root@master ~]# chkconfig httpd on
[root@master ~]# service httpd restart

5. 测试访问
http://ip/nagios
输入之前设置的用户名和密码
查看导航栏中:主机、服务,如果能看localhost的监控,说明阶段成功!
========================================================
nagios文件的具体含义:(/usr/local/nagios/etc/objects)
command.cfg 定义nagios能调用的命令;
contacts.cfg 定义联系人;
localhost.cfg 定义监控本机的对象;
printer.cfg 定义对打印机的监控;
switch.cfg 定义对交换机的监控;
templates.cfg 定义模板;
timeperiods.cfg 定义时间对象;
windows.cfg 定义监控的windows主机;
========================================================
check_command check-host-alive #检查的命令
check_interval 5 #检测的时间间隔
retry_interval 1 #检测失败后重试的时间间隔
max_check_attempts 5 #最大重试次数
check_period 24x7 #检测的时段
process_perf_data 0
retain_nonstatus_information 0
contact_groups sagroup #联系组
notification_interval 30 #通知的时间间隔
notification_period 24x7 #通知的时间段
notification_options d,u,r #通知的选项
#w—报警(warning),u—未知(unkown)
#d = 状态为DOWN,f = flapping,n=不发送提醒
#c—严重(critical),r—从异常情况恢复正常

二、监控本地主机:

定义主机和服务
[root@master ~]# vim /usr/local/nagios/etc/objects/localhost.cfg
... ... ...
# Define a service to "ftp" the local machine
define service{

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值