CentOS 6.7 安装Nagios教程

 

 

首页服务器应用

背景:

阅读新闻

CentOS 6.7 安装Nagios教程

[日期:2015-11-23]   来源:Linux社区  作者:caoguo   [字体:]  

CentOS 6.7 安装Nagios教程
参考文档:https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/quickstart-Fedora.html

一.安装依赖包

[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
[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
[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                          ca0gu0@126.com
        }

[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 ca0gu0@126.com

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/ab5d147265a4d35eba197f69aacc95e3.html