系统环境:Centos6.3 最小化安装
环境准备
yum install –y libxml2-devel make gcc
1、安装前准备
(1)创建nagios用户和用户组
[root@localhost ~]#useradd -s /sbin/nologin nagios
[root@localhost ~]#mkdir /usr/local/nagios
[root@localhost ~]#chown –R nagios.nagios /usr/local/nagios
(2)开启系统sendmail服务
在nagios监控服务器上开启sendmail服务的主要作用是让nagios在检测到故障时可以发送报警邮件,目前几乎所有的linux发行版本都默认自带了sendmail服务,所以,在安装系统时只需开启sendmail服务即可,并且不需要在sendmail上做任何配置。
2、 编译安装Nagios
[root@localhost ~]# tar -zxvf nagios-3.2.0.tar.gz
[root@localhost ~]# cd nagios-3.2.0
[root@localhost nagios-3.2.0]#./configure --prefix=/usr/local/nagios
#指定nagios的安装目录,这里指定nagios安装到/usr/local/nagios目录
[root@localhost nagios-3.2.0]#make all
[root@localhost nagios-3.2.0]#make install
# make install用来安装nagios的主程序,CGI和HTML文件
[root@localhost nagios-3.2.0]# make install-init
#通过make install-init命令可以在/etc/rc.d/init.d目录下创建nagios启动脚本
[root@localhost nagios-3.2.0]# make install-commandmode
#通过make install-commandmode命令来配置目录权限
[root@localhost nagios-3.2.0]# make install-config
#make install-cofig命令用来安装nagios示例配置文件,这里安装的路径是/usr/local/nagios/etc
3、 安装Nagios插件
[root@localhost nagios]#tar –zxvf nagios-plugins-1.4.14.tar.gz
[root@localhost nagios]#cd nagios-plugins-1.4.14
[root@localhost nagios-plugins-1.4.14]#./configure --prefix=/usr/local/nagios
[root@localhost nagios-plugins-1.4.14]# make
[root@localhost nagios-plugins-1.4.14]# make install
安装完成,在/usr/local/nagios下的libexec目录下,生成很多可执行文件,这些正是nagios所需要的插件。
4、安装与配置apache和php
apache和php不是安装nagios所必须的,但是nagios提供了web监控界面,通过web监控界面可以清晰的看到被监控主机、资源的运行状态,因此,安装一个web服务是很必要的。
需要注意的是,nagios在nagios3.1.x版本以后,配置web监控界面时需要php的支持。这里我们下载的nagios版本为nagios-3.2.0,因此在编译安装完成apache后,还需要编译php模块,这里选取的php版本为php5.3.2。
(1)安装apache与php
首先安装apache,步骤如下:
[root@nagiosserver ~]# tar zxvf httpd-2.0.63.tar.gz
[root@nagiosserver ~]#cd httpd-2.0.63
[root@nagiosserver ~]#./configure --prefix=/usr/local/apache2
[root@nagiosserver ~]#make
[root@nagiosserver ~]#make install
接着安装php,步骤如下:
[root@nagiosserver ~]# tar zxvf php-5.3.2.tar.gz
[root@nagiosserver ~]#cd php-5.3.2
[root@nagiosserver ~]#./configure --prefix=/usr/local/php \
>--with-apxs2=/usr/local/apache2/bin/apxs
[root@nagiosserver ~]#make
[root@nagiosserver ~]#make install
从安装步骤可知,apache安装路径为/usr/local/apache2,而php安装路径为/usr/local/php。
(2)配置apache
找到apache配置文件/usr/local/apache2/conf/httpd.conf
找到:
User nobody
Group #-1
修改为
User nagios
Group nagios
然后找到
DirectoryIndex index.html index.html.var
修改为
DirectoryIndex index.html index.php
接着增加如下内容:
AddType application/x-httpd-php .php
为了安全其间,一般情况下要让nagios的web监控界面必须经过授权才能访问,这需要增加验证配置,即在httpd.conf文件最后添加如下信息:
#setting for nagios
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
<Directory "/usr/local/nagios/sbin">
AuthType Basic
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
AuthType Basic
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
(3)创建apache目录验证文件
在上面的配置中,指定了目录验证文件htpasswd,下面要创建这个文件:
[root@localhost nagios]#/usr/local/apache2/bin/htpasswd \
>-c /usr/local/nagios/etc/htpasswd nagiosadmin
New password: (输入密码)
Re-type new password: (再输入一次密码)
Adding password for user nagiosadmin
这样就在/usr/local/nagios/etc目录下创建了一个htpasswd验证文件,当通过http://ip/nagios/访问时就需要输入用户名和密码了。
最后,启动服务:
[root@ nagiosserver ~]#/usr/local/apache2/bin/apachectl start
[root@ nagiosserver ~]#/usr/local/nagios/bin/nagios –d /usr/local/nagios/etc/nagios.cfg start
5、使用check_esx3.pl脚本监控esx、esxi、vcenter
perl环境准备 yum install –y *perl* openssl-devel
(1)在Nagios服务端上安装VMware-vSphere-Perl-SDK-4.1.0-254719.x86_64.tar.gz (到vmware官方网站去下载,如果是32位操作系统,就安装i386的)
[root@localhost vmware-vsphere-cli-distrib]# perl vmware-install.pl #安装VMware-vSphere-Perl-SDK
(2)安装插件
下载 wget http://search.cpan.org/CPAN/authors/id/S/SF/SFINK/Math-Calc-Units-1.07.tar.gz
[root@localhost Math-Calc-Units-1.07]#perl Makefile.PL
[root@localhost Math-Calc-Units-1.07]#make && make install
下载,wget http://search.cpan.org/CPAN/authors/id/T/TO/TONVOON/Nagios-Plugin-0.34.tar.gz
[root@localhost Nagios-Plugin-0.34]# perl Makefile.PL
[root@localhost Nagios-Plugin-0.34]# make && make install
(3)下载check_esx3.pl并解压到/usr/local/nagios/libexec/ (wget http://tangyou.me/wp-content/uploads/2012/06/check_esx3.zip)完成~~
转载于:https://blog.51cto.com/wang11/1167932