感谢支持
我们一直在努力

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全攻略 http://www.linuxidc.com/Linux/2013-07/87067.htm

Nagios搭建与配置详解 http://www.linuxidc.com/Linux/2013-05/84848.htm

Nginx环境下构建Nagios监控平台 http://www.linuxidc.com/Linux/2011-07/38112.htm

在RHEL5.3上配置基本的Nagios系统(使用Nagios-3.1.2) http://www.linuxidc.com/Linux/2011-07/38129.htm

CentOS 5.5+Nginx+Nagios监控端和被控端安装配置指南 http://www.linuxidc.com/Linux/2011-09/44018.htm

Ubuntu 13.10 Server 安装 Nagios Core 网络监控运用 http://www.linuxidc.com/Linux/2013-11/93047.htm

步骤7:编译和安装nagios插件。

这儿已经下载了nagios插件在/root/nagios目录下面,直接进去编译和安装即可:

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

[root@taoteng nagios]# ./configure –with-nagios-user=nagios –with-nagios-group=nagios

[root@taoteng nagios]# make

[root@taoteng nagios]# make install

 

步骤8:验证nagios配置文件的是否有错误(这就是nagios其中的一个很不错的地方,可以很清晰的告诉你是否有错误)如果没有什么错误就输出下面的语句:

[root@taoteng nagios]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfgs

输出示例:

Running pre-flight check on configuration data…

 

Checking services…

        Checked 34 services.

Checking hosts…

        Checked 14 hosts.

Checking host groups…

        Checked 4 host groups.

Checking service groups…

        Checked 2 service groups.

Checking contacts…

        Checked 1 contacts.

Checking contact groups…

        Checked 1 contact groups.

Checking service escalations…

        Checked 0 service escalations.

Checking service dependencies…

        Checked 0 service dependencies.

Checking host escalations…

        Checked 0 host escalations.

Checking host dependencies…

        Checked 0 host dependencies.

Checking commands…

        Checked 25 commands.

Checking time periods…

        Checked 5 time periods.

Checking for circular paths between hosts…

Checking for circular host and service dependencies…

Checking global event handlers…

Checking obsessive compulsive processor commands…

Checking misc settings…

 

Total Warnings: 0

Total Errors:  0

Things look okay – No serious problems were detected during the pre-flight check

步骤9:让Nagios服务随计算机开机启动

 为了是Nagios和httpd在重启之后工作,我们需要把这两个服务chkconfig一下:

[root@taoteng ~]# chkconfig –add nagios

[root@taoteng ~]#chkconfig –level 35 nagios on

[root@taoteng ~]#chkconfig –add httpd

[root@taoteng ~]#chkconfig –level 35 httpd on

重启Nagios使更改生效!

[root@taoten ~]#service nagios restart

步骤10:通过浏览器来登录到Nagios

 我们的Nagios已经可以开始工作了,浏览器中输入http://192.168.162.153/nagios;输入“nagiosadmin”然后输入密码就okay了!

Nagios Login

RHEL/CentOS/Fedora安装Nagios 4.0.1

主机概述:

RHEL/CentOS/Fedora安装Nagios 4.0.1

Nagios Overview

RHEL/CentOS/Fedora安装Nagios 4.0.1

Nagios Overview

所有的服务概述:

RHEL/CentOS/Fedora安装Nagios 4.0.1

进程概述:

RHEL/CentOS/Fedora安装Nagios 4.0.1

Congratulations! You’ve successfully installed and configured Nagios and its Plugins. You’ve just begin your journey into monitoring.

!!升级nagios到新版本!!

如果你已经安装了一个老版本的nagios,那么你可以直接下载最新版本的nagios,按照下面的命令直接编译安装即可
[root@taoteng ~]# service nagios stop
[root@taoteng ~]# tar –zxvf nagios-4.0.1.tar.gz
[root@taoteng ~]# cd nagios-4.0.1
[root@taoteng ~]# ./configure
[root@taoteng ~]# make all
[root@taoteng ~]# make install
[root@taoteng ~]# service nagios start

到这里,nagios的基本配置已经完成,当然安装过程中n难免会出现错误的~会在后续的过程中更新出来当然也非常欢迎友友联系我一起来交流解决您碰见的问题。

赞(0) 打赏
转载请注明出处:服务器评测 » RHEL/CentOS/Fedora安装Nagios 4.0.1
分享到: 更多 (0)

听说打赏我的人,都进福布斯排行榜啦!

支付宝扫一扫打赏

微信扫一扫打赏