RHEL/CentOS/Fedora安装Nagios 4.0.1


Nagios 4.0.1版本安装,适用于RHEL/CentOS 5.x/6.x 或者Fedora 17/18/19。

我的环境如下:

Centos-6.2

Nagios 4.0.1

Nagios Plugin 1.5

Nagios是一个非常棒的免费的开源的监控工具,它提供给你一个很全面的监控环境,始终密切监视你的机器或者网络,不管是在数据中心还是在你自己的一个小实验室。

步骤1:安装需要的依赖包

需要安装Apache、PHP和一些库像:gcc、glibc、glibc-common、gd、gd-devel、make、net-snmp

[root@taoteng ~]# yum install -y httpd php gcc glibc glibc-common gd gd-devel make net-snmp

步骤2:创建一个nagios用户和组

创建一个新的nagios用户和nagcmd组账户并设置密码。
[root@taoteng ~]# useradd nagios
[root@taoteng ~]# groupadd nagcmd
接下来,添加nagios和Apache用户到nagcmd组。


[root@tecmint]# usermod -G nagcmd nagios
[root@tecmint]# usermod -G nagcmd apache

步骤3:下载Nagios-4.0.1和Nagios-plugin-1.5

在/root目录下创建一个安装包以及后续需要下载的安装包的目录。

[root@taoteng ~]# mkdir /root/nagios

[root@taoteng ~]# cd /root/nagios

现在来下载最新版本的Nagio-4.0.1和Nagios-plugin-1.5通过wget命令

  [root@taoteng nagios]# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.1.tar.gz

  [root@taoteng nagios]# wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz

步骤4:提取Nagios和nagios-plugins压缩包

  我们需要通过tar命令来提取下载的压缩包里面的文件:

  [root@taoteng nagios]# tar -zxvf nagios-4.0.1.tar.gz

  [root@taoteng nagios]# tar -zxvf nagios-plugins-1.5.tar.gz

紧接着nagios文件夹里面将会出现解压之后的文件夹

[root@taoteng nagios]# ll

总用量 30668

drwxrwxr-x 18 root  root      4096  2月 20 21:22 nagios-4.0.1

-r-xr-xr-x  1 root  root  1696847  2月 20 20:58 nagios-4.0.1.tar.gz

drwxr-xr-x 15 nagios nagios    4096  2月 24 00:58 nagios-cn-3.2.3

-r-xr-xr-x  1 root  root  9638175  2月 20 20:58 nagios-cn-3.2.3.tar.bz2

drwxr-xr-x 15    200    300    4096  2月 20 22:04 nagios-plugins-1.5

-r-xr-xr-x  1 root  root  2428258  2月 20 20:58 nagios-plugins-1.5.tar.gz

配置nagios的核心


现在,首先我们将配置nagios核心,将进入到nagios文件夹里面运行configure命令,如果一切运行顺利将会出现下面的界面:

[root@taoteng nagios]# cd nagios-4.0.1

[root@taoteng nagios-4.0.1]# ./configure --with-command-group=nagcmd


输出示例:

Nagios executable:  nagios        Nagios user/group:  nagios,nagios      Command user/group:  nagios,nagcmd            Event Broker:  yes        Install ${prefix}:  /usr/local/nagios    Install ${includedir}:  /usr/local/nagios/include/nagios                Lock file:  ${prefix}/var/nagios.lock  Check result directory:  ${prefix}/var/spool/checkresults          Init directory:  /etc/rc.d/init.d  Apache conf.d directory:  /etc/httpd/conf.d            Mail program:  /bin/mail                  Host OS:  linux-gnu Web Interface Options: ------------------------                HTML URL:  http://localhost/nagios/                  CGI URL:  http://localhost/nagios/cgi-bin/ Traceroute (used by WAP):  /bin/tracerouteReview the options above for accuracy.  If they look okay,type 'make all' to compile the main program and CGIs.
随后配置和编译所有的的二进制文件,make和make install将会在你的机器上安装所需的二进制文件然后才能继续安装,

[root@taoteng nagios-4.0.1]# make

[root@taoteng nagios-4.0.1]# make install

 


输出样例:


*** Main program, CGIs and HTML files installed ***You can continue with installing Nagios as follows (type 'make'without any arguments for a list of all possible options):  make install-init    - This installs the init script in /etc/rc.d/init.d  make install-commandmode    - This installs and configures permissions on the      directory for holding the external command file  make install-config    - This installs sample config files in /usr/local/nagios/etc
其实从上面的样例上可以看出下步我们需要的操作步骤,接着执行make install-init去安装初始化脚本。


[root@taoteng nagios-4.0.1]# make install-init

从输出的命令行上可以看出我们需要安装外部命令文件(libxce)

[root@taoteng nagios-4.0.1]# make install-commandmode

接下来安装nagios示例文件,运行下面的命令:

[root@taoteng nagios-4.0.1]# make install-config

输出示例:
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg*** Config files installed ***Remember, these are *SAMPLE* config files.  You'll need to readthe documentation for more information on how to actually defineservices, hosts, etc. to fit your particular needs.
步骤5:自定义nagios配置文件

打开“contacts.cfg”文件编辑当出现报警状态时候的nagios管理员的电子邮箱

[root@taoteng nagios-4.0.1]# vi /usr/local/nagios/etc/objects/contacts.cfg

输出样例:

###############################################################################

#

# CONTACTS

#

###############################################################################

###############################################################################

 


# Just one contact defined by default - the Nagios admin (that's you)

# This contact definition inherits a lot of default values from the 'generic-contact'

# template which is defined elsewhere.

 


define contact{

        contact_name                    nagiosadmin            ; Short name of user

        use                            generic-contact        ; Inherit default values from generic-contact template (defined above)

        alias                          Nagios Admin            ; Full name of user

 


        email                          xiantao412@sina.com      ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

        }

步骤6:安装和配置Nagios的web接口

 到目前为止,我们已经完成了所有的配置,接下来将用下面的命令来配置Nagios的web接口。

 下面的命令将配置web接口并同时创建一个“nagiosadmin”管理用户。

[root@taoteng nagios-4.0.1]# make install-webconf

接下来的这步将会创建一个密码为“nagiosadmin”记住这个密码,因为待会儿在浏览器中登录的时候将会用到这个密码。
[root@taoteng nagios-4.0.1]# htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
重启Apache服务使新的配置生效。


[root@taoteng nagios-4.0.1]# service httpd restart (On RedHat/CentOS)

[root@taoteng nagios-4.0.1]# systemctl start httpd.service (On Fedora)

Nagios 的详细介绍:请点这里
Nagios 的下载地址:请点这里

网络监控器Nagios全攻略

Nagios搭建与配置详解

Nginx环境下构建Nagios监控平台

在RHEL5.3上配置基本的Nagios系统(使用Nagios-3.1.2)

CentOS 5.5+Nginx+Nagios监控端和被控端安装配置指南

Ubuntu 13.10 Server 安装 Nagios Core 网络监控运用

  • 1
  • 2
  • 下一页

相关内容