一、安装 运行环境

yum -y install httpd php gcc glibc glibc-common gd gd-devel libpang libjpeg zlib

二、创建用户、用户组

useradd -s /sbin/nologin nagios

groupadd nagcmd

usermod -G nagcmd nagios

usermod -G nagcmd apache 

三、编译安装 nagios

##

make install-init是向/etc/rc.d/init.d中安装启动脚本

make install-commandmode是将额外的命令文件修改好恰当的权限

make  install-config是向/usr/local/nagios/etc目录下写入示例配置文件

##

tar -zxf nagiosxxxx

cd /nagiosxxx

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

make all

make install

make install-init

make install-config

make install-commandmode

make install-webconf 

四、 nagios 安装目录与配置文件

/usr/local/nagios   #默认安装目录

bin #测试命令目录

etc #配置文件目录

libexec #插件目录

sbin #cgi脚本目录

share #nagios网页文件目录

var #nagios运行中产生的数据

/usr/local/nagios/etc

cgi.cfg #cgi程序配置文件

nagios.cfg #nagios服务主配置文件

resource.cfg #定义nagios变量文件

/usr/local/nagios/etc/objects #监控对象的配置文件监控模板的配置

commands.cfg #定义监控命令配置文件

localhos.cfg #定义监控本机对象配置文件

contacts.cfg #指定报警邮件发送邮箱

timeperiods.cfg #监控时间模板文件

templates.cfg #监控方式模板文件

五、安装插件

tar zxf nagios-plugins

cd nagios-plugins

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

make && make install

插件的使用 

cd /usr/local/nagios/libexec

./check_http --help

./check_http -H localhost -p 80

因为NFS没有相关的命令检测,所以采用通用的check_tcp

./check-tcp -p 2049 

nagios 登录页面需要用户名和密码根据配置文件建立相对应的密码文件 用户名最好使用nagiosadmin  因为配置文件中定义的管理员名称就是他

配置密码:

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

启动 httpd 

service httpd restart

启动nagios

service nagios start

通过浏览器

本机ip/nagios