歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

Centos6.7 安裝Naigos教程

一.安裝依賴包  
[root@Nagios ~]# yum install -y httpd php
[root@Nagios ~]# yum install -y gcc glibc glibc-common
[root@Nagios ~]# yum install -y gd gd-devel
[root@Nagios ~]# yum install -y perl ntp unzip
[root@Nagios ~]# yum install -y openssl-devel

[root@Nagios ~]# /etc/init.d/ntpd start
[root@Nagios ~]# chkconfig ntpd on

[root@Nagios ~]# /usr/sbin/useradd -m nagios
[root@Nagios ~]# passwd nagios

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

 

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

 

  三.nagios plugins的安裝  
[root@Nagios src]# tar xzf nagios-plugins-2.1.1.tar.gz 
[root@Nagios src]# cd nagios-plugins-2.1.1
[root@Nagios nagios-plugins-2.1.1]# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
[root@Nagios nagios-plugins-2.1.1]# make && make install

 

  四.nrpe插件安裝
[root@Nagios src]# wget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
[root@Nagios src]# tar zxf nrpe-2.15.tar.gz 
[root@Nagios src]# cd nrpe-2.15
[root@Nagios nrpe-2.15]# ./configure --prefix=/usr/local/nagios
[root@Nagios nrpe-2.15]# make all
[root@Nagios nrpe-2.15]# make install-plugin
[root@Nagios nrpe-2.15]# make install-daemon
[root@Nagios nrpe-2.15]# make install-daemon-config

# 測試啟動
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

# 自帶了啟動腳本
[root@Nagios nrpe-2.15]# cp -rf init-script.in /etc/init.d/nrpe
[root@Nagios nrpe-2.15]# chmod a+x /etc/init.d/nrpe 
[root@Nagios ~]# /etc/init.d/nrpe start

 

  注:其實nagios獲取信息都是靠/usr/local/nagios/libexec/check_nrpe 這個腳本主動獲取nrpe服務端信息   五.配置並啟動服務
[root@Nagios ~]# vi /usr/local/nagios/etc/objects/contacts.cfg
define contact{
        contact_name                    nagiosadmin             
        use                             generic-contact         
        alias                           Nagios Admin            
        email                           [email protected] 
        }

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

# 檢查配置文件是否正確
[root@Nagios ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

[root@Nagios ~]# chkconfig nagios on
[root@Nagios ~]# service nagios start

[root@Nagios ~]# chkconfig nrpe on
[root@Nagios ~]# /etc/init.d/nrpe start

[root@Nagios ~]# chkconfig httpd on
[root@Nagios ~]# service httpd start
[root@Nagios ~]# touch /var/www/html/index.html

 

六.配置郵件發送   [root@Nagios ~]# yum -y install mailx [root@Nagios ~]# echo "mail test" | mail -s test [email protected]   #如果不配置mail.rc默認會用本地postfix發送郵件 #email send tools #nano /etc/mail.rc #set [email protected] smtp=smtp.126.com #set smtp-auth-user=xx@oo smtp-auth-password=xxoo #set smtp-auth=login

Copyright © Linux教程網 All Rights Reserved