nagios 服务端配置
1.yum 安装需要的软件包和支持库:
yum install -y httpd httpd-manual httpd-devel gd gd-devel perl-GD mysql-server mysql-devel php
php-mysql php-gd php-pear perl-DBI perl-Digest-SHA1 perl-Digest-HMAC net-snmp-utils
perl-Socket6 perl-IO-Socket-INET6 net-snmp-devel php-snmp dmidecode net-snmp-perl
perl-Crypt-DES fping perl-Config-IniFiles graphviz gcc-c++ glib2-devel php-gd php-pdo php-ldap
php-mbstring php-xml lib
2修改 snmp:
vi /etc/snmp/snmpd.conf
com2sec notConfigUser x.x.x.x public
access notConfigGroup "" any noauth exact all none none
view all included .1 80
service snmpd restart
3.安装 nagios
nagios 之前的准备,特别需要安装 gd-devel,
另外安装 nagios 时需要加--with-gd-lib=/usr/lib --with-gd-inc=/usr/include
不然不能生成 statusmap.cgi 也就不能看状态图了!
groupadd nagios
useradd -g nagios nagios
passwd nagios
mkdir /usr/local/nagios
chown -R nagios:nagios /usr/local/nagios
chmod 755 /usr/local/nagios/
usermod -G nagios apache
usermod -G nagios nagios
grep ser /etc/httpd/conf/httpd.conf
User apache
查看运行 apache 的用户
4.编译安装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
5. 安装Nagios插件
这里下载的版本是nagios-plugins-1.4.14。
注意:插件版本与nagios版本的关联并不大。
[root@localhost nagios]#tar �Czxvf 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所需要的插件。
6.配置apache
找到apache配置文件/etc/httpd/conf/httpd.conf
找到:
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/">
AllowOverride AuthConfig
Options ExecCGI
Order allow,deny
Allow from all
</Directory>
Alias /nagios /usr/local/nagios/share/
<Directory "/usr/local/nagios/share">
Options None
AllowOverride AuthConfig
Order allow,deny
Allow from all
</Directory>
7.在服务端安装nrpe
8.(1)安装nrpe插件
nrpe在服务端安装很简单,操作如下:
[root@nagiosserver ~]#tar zxvf nrpe-2.12.tar.gz
[root@ nagiosserver ~]#cd nrpe-2.12
[root@ nagiosserver ~]#./configure
[root@ nagiosserver ~]#make all
[root@ nagiosserver ~]#make install-plugin
通过“make install-plugin”命令将check_nrpe插件默认安装到了/usr/local/nagios/ libexec目录下。
(2)测试插件与客户端是否能正常通信
在nagios服务端(即nagios监控平台)服务器上执行如下指令:
/usr/local/nagios/libexec/check_nrpe -H 客户端主机地址
例如:
[root@nagiosserver ~]# /usr/local/nagios/libexec/check_nrpe -H 192.168.1.6
NRPE v2.12
如果能显示如上的输出信息,表明nrpe可以与客户端正常通信。
必须先在被监控机上安装nrpe,同时配置/usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,192.168.1.96
(3)定义一个check_nrpe监控命令
修改/usr/local/nagios/etc/commands.cfg文件,添加如下内容:
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
9.开始配置nagios
(1)定义监控主机
Vi /usr/local/nagios/etc/objects/hosts.cfg
define host{
use linux-server
host_name uat-test
alias ceshiji
address 192.168.1.6
}
(2)定义主机组
vi /usr/local/nagios/etc/objects/hostsgroup.cfg
define hostgroup {
hostgroup_name sa-servers
alias sa servers
members *
}
(3)定义监控服务
vi /usr/local/nagios/etc/objects/services.cfg
define service{
use local-service
host_name uat-test
service_description users
check_command check_nrpe!check_users_1
}
define service{
use local-service
host_name uat-test
service_description load
check_command check_nrpe!check_load_1
}
define service{
use local-service
"services.cfg" 69L, 1390C
define service{
use local-service
host_name uat-test
service_description users
check_command check_nrpe!check_users_1
}
define service{
use local-service
host_name uat-test
service_description load
check_command check_nrpe!check_load_1
}
define service{
use local-service
host_name uat-test
service_description disk
check_command check_nrpe!check_xvda2_1
}
(4)定义监控服务组
Vi /usr/local/nagios/etc/objects/servicesgroup.cfg
define servicegroup {
servicegroup_name service
alias system service-server
members uat-test,load
}
(5)定义nagios
/usr/local/nagios/etc/nagios.cfg
添加
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/hostsgroup.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
cfg_file=/usr/local/nagios/etc/objects/servicesgroup.cfg
Nagios客户端配置
(1)安装nagios插件
在nagios客户端主机上需要安装nrpe和nagios插件,Nrpe插件可以从nagios官方网站下载到,从http://www.nagios.org/download/addons下载最新稳定版本nrpe-2.12.tar.gz,然后开始安装和配置,基本操作如下:
[root@nagios-client ~]#useradd -s /usr/sbin/nologin nagios
[root@nagios-client ~]#tar zxvf nagios-plugins-1.4.14.tar.gz
[root@nagios-client ~]#cd nagios-plugins-1.4.14
[root@nagios-client ~]#./configure
[root@nagios-client ~]#make
[root@nagios-client ~]#make install
设置插件目录权限
[root@nagios-client ~]#chown nagios.nagios /usr/local/nagios
[root@nagios-client ~]#chown -R nagios.nagios /usr/local/nagios/libexec
(2)安装nrpe插件
在客户端安装nrpe插件过程要比在服务端安装复杂,因为nrpe在客户端是作为一个守护进程在运行的,操作如下:
[root@nagios-client ~]#tar zxvf nrpe-2.12.tar.gz
[root@nagios-client ~]#cd nrpe-2.12
[root@nagios-client ~]#./configure
[root@nagios-client ~]#make all
[root@nagios-client ~]#make install-plugin
[root@nagios-client ~]#make install-daemon
[root@nagios-client ~]#make install-daemon-config
(3)配置nrpenrpe的配置文件为/usr/local/nagios/etc/nrpe.cof。
首先找到“server_address=127.0.0.1”
将后面的地址改为客户端主机的ip地址,然后找到:
“allowed_hosts=127.0.0.1”
一行,将其改为:
allowed_hosts=127.0.0.1, Nagios监控服务器的地址或域名
修改这个配置的作用是声明合法的nrpe服务对象,没有在这里指定的地址是无法从本机的NRPE获得服务信息的。“Nagios监控服务器的地址或域名”可以是ip地址,也可以是域名。可以根据自己的情况设定。
(4)启动nrpe守护进程启动NRPE很简单,只需执行如下操作:
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
建议将此命令加入到/etc/rc.local文件中,这样就可以开机自动运行NRPE守护进程了。
Nrpe守护进程默认的端口为5666,通过如下命令可以检测端口是否启动:
[root@nagios-client ~]# netstat -antl|grep 5666
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN
可以看到,nrpe守护进程端口5666已经启动了。
(5)测试nrpe功能
首先在nagios客户端本机上测试,执行如下命令:
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
如果正常,应该出现如下信息:
[root@nagios-client ~]# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
NRPE v2.12
正常的返回值为被监控服务器上安装的NRPE的版本信息,如果能看到这些,表示NRPE已经正常工作了。
(6)定义监控服务器内容
要监控一个远程服务器下的某些信息,首先要在远程服务器中定义监控的内容,例如,如果要监控一台远程服务器上的当前用户数、cpu负载、磁盘利用率、交换空间使用情况时,则需要在nrpe.conf中定义监控内容:
command[check_users_1]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load_1]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_sda5_1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda5
command[check_zombie_procs_1]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs_1]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
command[check_swap_1]=/usr/local/nagios/libexec/check_swap -w 20 -c 10
其中,command后面中括号里面的内容就是定义的变量,变量名可以随意指定。
最后在nagios服务端测试和启动nagios服务
[root@nagiosserver ~]#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[root@nagiosserver ~]#/etc/init.d/nagios restart
Nagios汉化
安装Nagios中文化插件
中文插件下载地址:
http://sourceforge.net/projects/nagios-cn/files/
下载对应nagios版本的中文插件,然后开始安装:
[root@localhost ~]#tar xvfz nagios-cn-3.2.0.tar.bz2
[root@localhost nagios-cn-3.2.0]#cd nagios-cn-3.2.0
[root@localhost nagios-cn-3.2.0]#./configure
[root@localhost nagios-cn-3.2.0]#make all
[root@localhost nagios-cn-3.2.0]#make install