Nagios4.0.1版本安装适用于RHEL/Centos5.x/6.x或者Fedora17/18/19(一)
我的环境如下:
发展壮大离不开广大客户长期以来的信赖与支持,我们将始终秉承“诚信为本、服务至上”的服务理念,坚持“二合一”的优良服务模式,真诚服务每家企业,认真做好每个细节,不断完善自我,成就企业,实现共赢。行业涉及成都不锈钢雕塑等,在成都网站建设、成都全网营销推广、WAP手机网站、VI设计、软件开发等项目上具有丰富的设计经验。
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]# wgethttp://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.1.tar.gz
[root@taoteng nagios]# wgethttps://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)
步骤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
主机概述:
Nagios Overview
Nagios Overview
所有的服务概述:
进程概述:
Congratulations! You’ve successfully installed and configured Nagiosand 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难免会出现错误的~会在后续的过程中更新出来当然也非常欢迎友友联系我一起来交流解决您碰见的问题。
后续的博客也会跟进nagios如何添加Linux主机、windows主机、交换机、打印机等等一些设备到Nagios监视服务器中。
-------------第一次 发博文,错误之处,欢迎指出,敬请原谅-------------
文章题目:Nagios4.0.1版本安装适用于RHEL/Centos5.x/6.x或者Fedora17/18/19(一)
分享网址:http://pwwzsj.com/article/pejehs.html