Centos6.7安装Naigos教程

11/26/2015来源:Linux教程人气:1750

Centos6.7 安装Naigos教程
参考文档:https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/quickstart-fedora.html

blog地址:http://www.cnblogs.com/caoguo


一.安装依赖包

[[email protected] ~]# yum install -y httpd php
[[email protected] ~]# yum install -y gcc glibc glibc-common
[[email protected] ~]# yum install -y gd gd-devel
[[email protected] ~]# yum install -y perl ntp unzip
[[email protected] ~]# yum install -y openssl-devel

[[email protected] ~]# /etc/init.d/ntpd start
[[email protected] ~]# chkconfig ntpd on

[[email protected] ~]# /usr/sbin/useradd -m nagios
[[email protected] ~]# passwd nagios

[[email protected] ~]# /usr/sbin/groupadd nagcmd
[[email protected] ~]# /usr/sbin/usermod -a -G nagcmd nagios
[[email protected] ~]# /usr/sbin/usermod -a -G nagcmd apache
[[email protected] ~]# id nagios
uid=500(nagios) gid=500(nagios) groups=500(nagios),501(nagcmd)
[[email protected] ~]# id apache
uid=48(apache) gid=48(apache) groups=48(apache),501(nagcmd)

 

二.nagios的安装

 

[[email protected] ~]# cd /usr/local/src
[[email protected] src]# wget http://nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz
[[email protected] src]# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.1.1.tar.gz
[[email protected] src]# tar zxvf nagios-4.1.1.tar.gz
[[email protected] src]# cd nagios-4.1.1
[[email protected] nagios-4.1.1]# ./configure --PRefix=/usr/local/nagios --with-comand-group=nagcmd
[[email protected] nagios-4.1.1]# make all
[[email protected] nagios-4.1.1]# make install
[[email protected] nagios-4.1.1]# make install-init
[[email protected] nagios-4.1.1]# make install-config
[[email protected] nagios-4.1.1]# make install-commandmode
[[email protected] nagios-4.1.1]# make install-webconf
[[email protected] nagios-4.1.1]# cp -rf contrib/eventhandlers /usr/local/nagios/libexec/
[[email protected] nagios-4.1.1]# chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers

 

 

 

 

三.nagios plugins的安装

[[email protected] src]# tar xzf nagios-plugins-2.1.1.tar.gz 
[[email protected] src]# cd nagios-plugins-2.1.1
[[email protected] nagios-plugins-2.1.1]# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
[[email protected] nagios-plugins-2.1.1]# make && make install

 

四.nrpe插件安装

[[email protected] src]# wget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
[[email protected] src]# tar zxf nrpe-2.15.tar.gz 
[[email protected] src]# cd nrpe-2.15
[[email protected] nrpe-2.15]# ./configure --prefix=/usr/local/nagios
[[email protected] nrpe-2.15]# make all
[[email protected] nrpe-2.15]# make install-plugin
[[email protected] nrpe-2.15]# make install-daemon
[[email protected] nrpe-2.15]# make install-daemon-config


# 测试启动
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

# 自带了启动脚本
[[email protected] nrpe-2.15]# cp -rf init-script.in /etc/init.d/nrpe
[[email protected] nrpe-2.15]# chmod a+x /etc/init.d/nrpe 
[[email protected] ~]# /etc/init.d/nrpe start

 

注:其实nagios获取信息都是靠/usr/local/nagios/libexec/check_nrpe 这个脚本主动获取nrpe服务端信息

 

五.配置并启动服务

 

[[email protected] ~]# vi /usr/local/nagios/etc/objects/contacts.cfg
define contact{
        contact_name                    nagiosadmin             
        use                             generic-contact         
        alias                           Nagios Admin            
        email                           [email protected]126.com 
        }

[[email protected] ~]# vi /usr/local/nagios/etc/objects/commands.cfg        
define command{
        command_name    check_nrpe
        command_line    $USER1$/check_nrpe -H "$HOSTADDRESS$" -c "$ARG1$"
}
        
[[email protected] ~]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

# 检查配置文件是否正确
[[email protected] ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

[[email protected] ~]# chkconfig nagios on
[[email protected] ~]# service nagios start

[[email protected] ~]# chkconfig nrpe on
[[email protected] ~]# /etc/init.d/nrpe start

[[email protected] ~]# chkconfig httpd on
[[email protected] ~]# service httpd start
[[email protected] ~]# touch /var/www/html/index.html

 

 

 

 

 

 

 

六.配置邮件发送

[[email protected] ~]# yum -y install mailx
[[email protected] ~]# echo "mail test" | mail -s test [email protected]126.com

#如果不配置mail.rc默认会用本地postfix发送邮件
#email send tools
#nano /etc/mail.rc
#set from[email protected]126.com smtp=smtp.126.com
#set [email protected] smtp-auth-passWord=xxoo
#set smtp-auth=login

 

 

 

结束!!!!!