您的位置:首页 > 运维架构 > Linux

CentOS 6.3_Nagios安装配置 推荐

2012-09-27 15:00 633 查看
实验环境
包含3台主机,详细信息如下
主机名
操作系统
IP地址
作用
nagios
CentOS 6.3_x64
10.10.10.254
监控机
web
CentOS 6.3_x64
10.10.10.253
被监控机
winserver
Windows sever 2003
10.10.10.252
被监控机
Nagios定义的监控状态
nagios定义了4中监控状态,代表不同的严重级别,除了OK代表正常不用关心外,其余3种都要引起重视.如下表

状态
代码
颜色
正常
OK
绿色
警告
WARNING
黄色
严重
CRITICAL
红色
未知错误
UNKOWN
深黄色
1、安装前准备
Nagios安装前,首先安装相关软件包,对于RHEL / CentOS系统: (依赖包的安装:wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp openssl openssl-devel)
检看一下是否安装相关软件包:
[root@nagios ~]# rpm -qa |grep *****(略)
[root@nagios ~]# yum install -y wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp openssl openssl-devel

Nagios源代码程序和插件
监控主机下载:
[root@nagios ~]# wget http://nchc.dl.sourceforge.net/project/nagios/nagios-3.x/nagios-3.4.4/nagios-3.4.4.tar.gz
[root@nagios ~]# wget http://nchc.dl.sourceforge.net/project/nagiosplug/nagiosplug/1.4.16/nagios-plugins-1.4.16.tar.gz
[root@nagios ~]# wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz

被监控Linux 主机下载:
[root@nagios ~]# wget http://nchc.dl.sourceforge.net/project/nagiosplug/nagiosplug/1.4.16/nagios-plugins-1.4.16.tar.gz
[root@nagios ~]# wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz

被监控Windows 主机下载:
http://nsclient.org/nscp/downloads
http://files.nsclient.org/0.3.x/NSClient%2B%2B-0.3.9-Win32.zip
http://files.nsclient.org/0.3.x/NSClient%2B%2B-0.3.9-x64.zip

2、添加Nagios用户和组  
[root@nagios ~]# useradd nagios
[root@nagios ~]# passwd nagios
[root@nagios ~]# groupadd nagcmd
[root@nagios ~]# usermod -a -G nagcmd nagios
3、编译与安装Nagios
[root@nagios ~]# tar -zxvf nagios-3.4.4.tar.gz
[root@nagios ~]# cd nagios
[root@nagios nagios]#./configure --with-command-group=nagcmd //编译Nagios 配置脚本并使用先前开设的用户及用户组
[root@nagios nagios]#make all //编译Nagios 程序包源码

*** Compile finished ***
If the main program and CGIs compiled without any errors, you
can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):
make install //使用make install来安装主程序,CGI和HTML文件
- This installs the main program, CGIs, and HTML files
make install-init //使用make install-init在/etc/rc.d/init.d安装启动脚本
- This installs the init script in /etc/rc.d/init.d
make install-commandmode //使用make install-commandmode来配置目录权限
- This installs and configures permissions on the
directory for holding the external command file
make install-config //把配置文件的例子复制到nagios的安装目录: /usr/local/nagios/etc
- This installs *SAMPLE* config files in /usr/local/nagios/etc
You'll have to modify these sample files before you can
use Nagios. Read the HTML documentation for more info
on doing this. Pay particular attention to the docs on
object configuration files, as they determine what/how
things get monitored!
make install-webconf //安装Nagios 的WEB 配置文件到Apache 的conf.d 目录下
- This installs the Apache config file for the Nagios
web interface
make install-exfoliation
- This installs the Exfoliation theme for the Nagios
web interface
make install-classicui
- This installs the classic theme for the Nagios
web interface
*** Support Notes *******************************************

安装二进制运行程序、初始化脚本、配置文件样本并设置运行目录权限
[root@nagios nagios]#make install
[root@nagios nagios]#make install-init
[root@nagios nagios]#make install-config
[root@nagios nagios]#make install-commandmode
[root@nagios nagios]#make install-webconf

复制nagios/contrib/eventhandlers目录下所有文件到/usr/local/nagios/libexec下:
[root@nagios nagios]#cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/

修改用户和主权限
[root@nagios nagios]#chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
[root@nagios nagios]# ll /usr/local/nagios/libexec/eventhandlers/

总用量 28
-rwxr-xr-x. 1 nagios nagios 828 9月 27 11:33 disable_active_service_checks
-rwxr-xr-x. 1 nagios nagios 759 9月 27 11:33 disable_notifications
drwxr-xr-x. 2 nagios nagios 4096 9月 27 11:33 distributed-monitoring
-rwxr-xr-x. 1 nagios nagios 827 9月 27 11:33 enable_active_service_checks
-rwxr-xr-x. 1 nagios nagios 760 9月 27 11:33 enable_notifications
drwxr-xr-x. 2 nagios nagios 4096 9月 27 11:33 redundancy-scenario1
-rwxr-xr-x. 1 nagios nagios 1184 9月 27 11:33 submit_check_result

验证Nagios配置文件,验证配置是否有误
[root@nagios nagios]#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

重启httpd
[root@nagios ~]# /etc/init.d/httpd start
[root@nagios ~]# chkconfig httpd on

修改配置文件
[root@nagios ~]# vim /usr/local/nagios/etc/objects/contacts.cfg
修改nagiosadmin(这里修改为你自己创建的帐号) 注:nagiosadmin是配置文件默认,可以不用修改。
创建一个默认用户登录Web界面访问: 创建HTTP认证用户登录Nagios,用户名nagiosadmin,密码123456
[root@nagios ~]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password: 123456
Re-type new password: 123456

验证程序是否被正确安装:
切换目录到安装路径(这里是/usr/local/nagios),看是否存在 bin etc libexec sbin share var这六个目录,如果存在则可以表明程序被正确的安装到系统了。后表是六个目录功能的简要说明:
bin
Nagios执行程序所在目录,nagios文件即为主程序
etc
Nagios配置文件位置,初始安装完后,只有几个*.cfg-sample文件
libexec
Nagios 系统库文件
sbin
Nagios Cgi文件所在目录,也就是执行外部命令所需文件所在的目录
Share
Nagios网页文件所在的目录
Var
Nagios日志文件、spid 等文件所在的目录
var/archives
Empty directory for the archived logs
var/rw
Empty directory for the external command file
4、编译并安装Nagios 插件
[root@nagios ~]# tar zxvf nagios-plugins-1.4.16.tar.gz
[root@nagios ~]# cd nagios-plugins-1.4.16
[root@nagios nagios-plugins-1.4.16]#./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root@nagios nagios-plugins-1.4.16]# make;make install

会显示安装的插件文件,即所有的插件都安装在libexec这个目录下
[root@nagios ~]# ls /usr/local/nagios/libexec/

验证Nagios 配置文件
[root@nagios ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

5、启动Nagios
把Nagios 加入到服务列表中以使之在系统启动时自动启动
[root@nagios ~]#/etc/init.d/nagios start
[root@nagios ~]# chkconfig nagios on

6、登录到WEB界面
输入用户名密码:nagiosadmin 123456
http://localhost/nagios




Services




7、防火墙配置
如果WEB无法访问,检查一下IPtables是否关闭。
[root@nagios ~]# service iptables status
添加httpd 80端口:
[root@nagios ~]# vim /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

Nagios 安装完成!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  CentOS 6.3 Nagios 安装