当前位置: > Linux服务器 > 监控工具 >

安装 nagios server

时间:2015-09-30 23:41来源:linux.it.net.cn 作者:IT

下载地址:

wget http://cdnetworks-kr-1.dl.sourceforge.net/project/nagios/nagios-3.x/nagios-3.2.3/nagios-3.2.3.tar.gz

wget http://cdnetworks-kr-2.dl.sourceforge.net/project/nagiosplug/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz

wget http://cdnetworks-kr-1.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.12/nrpe-2.12.tar.gz

 

安装 nagios server
安装 nagios 之前的准备
设置 IP 地址。 关防火墙
安装 gd-devel ,
安装 nagios 时需要加 --with-gd-lib=/usr/lib --with-gd-inc=/usr/include
不然不能生成 statusmap.cgi 也就不能看状态图了! 用 yum install gd-devel 安装
添加用户,建立安装目录
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
查看运行 apache 的用户
grep ^User /etc/httpd/conf/httpd.conf
User apache
安装 nagios-3.2.3
tar zxf nagios-3.2.3.tar.gz
cd nagios-3.2.3
./configure --prefix=/usr/local/nagios --with-gd-lib=/usr/lib --with-gd-inc=/usr/include
--enable-event-broker
make all
make all install
make install-init // 安装启动脚本到 /etc/init.d/
make install-commandmode
make install-config // 安装初始配置文件到 /usr/local/nagios
安装 nagios-plugins
tar zxf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --prefix=/usr/local/nagios-plugins
make
make install
安装完成以后在 /usr/local/nagios-plugins 会产生一个 libexec 的目录,将该目录全部移动到

/usr/local/nagios 目录下即可。 mv /usr/local/nagios-plugins/libexec /usr/local/nagios/
配置 apache:
vi /etc/httpd/conf/httpd.conf
在 apache 的 httpd.conf 文件中加入如下内容 :
###nagios
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
# SSLRequireSSL
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
Alias /nagios "/usr/local/nagios/share"
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
然后重启 apache
service httpd restart

设置报报警邮箱
vi /usr/local/nagios/etc/objects/contacts.cfg
修改 nagiosadmin 这行其中的邮件地址为你的 email 地址,
设置登陆 web 密码
#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
#service httpd restart 重启动 apache
#service nagios restart 重启动 nagios
检查配置
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果出现如下显示就说明配置没问题
Total Warnings: 0
Total Errors: 0
如果有错误 , 用命令检查出错位置
cd /usr/local/nagios/bin//nagios
-v /usr/local/nagios/etc/nagios.cfg
cd /usr/local/nagios/var/
chown -R nagios.nagios nagios.log
service nagios restart
现在就可以 http:// 你的 IP/nagios/ 访问 nagios

client 安装过程
添加用户
useradd nagios
passwd nagios
安装 nagios-plugins-1.4.15
http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz
download
tar -zxvf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure
make
make install
安装 nagios-nrpe_2.9
http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.9/nrpe-

2.9.tar.gz/download
chown nagios.nagios /usr/local/nagios
然后
tar -zxvf nrpe-2.9.tar.gz
cd nrpe-2.9
./configure --with-command-group=nagcmd --prefix=/usr/local/nagios
make all
make install-plugin
make install-daemon
make install-daemon-config
设置服务器地址
vi /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1
后面加你的 nagios 服务器的 ip , 用“,”隔开, 加了之后如下:
allowed_hosts=127.0.0.1,121.48.96.91
启动 nrpe
cd /usr/local/nagios/bin/
./nrpe -c /usr/local/nrpe/etc/nrpe.cfg -d
察看是否在 5666 端口上监听
netstat -an|grep 5666
如果没有监听说明 nrpe 没启动
检查安装结果
/usr/local/nagios/libexec/check_nrpe -H localhost
察看是否能返回 nrpv 版本号, 返回则正常!
=============================================
配置监控对像
由监控原理可知被监控端做监控然后传给监控服务器绘总 , 设置监控详细参数主要是设置被
监控端的 nrpe.cfg 文件 , 可以看到里面监控对象。
vi /usr/local/nagios/etc/nrpe.cfg
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c
30,25,20
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20 -c 10
-p /dev/mapper (这里不一定是 mapper ,是 df 命令看到的磁盘)
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5
-c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w
150 -c 200
在这里添加一行 :
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%

nagios 服务器想要监控客户机 swap 分区 , 但客户机 nrpe.cfg 文件没有 swap 监控对像 ,
这时监控服务器就是报错 (NRPE command ‘ check_swap ’ no defined).
重新启动 nrpe
先停止 nrpe
kill `cat /var/run/nrpe.pid`
后启动
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
netstat -an|grep 5666
设置 nrpe 自启动: vi /etc/rc.local 在其中加中此行:
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d
监控端算设置完成
检查设置
/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_http ( 可检查任意一项 )
如果 http 服务出现 WARNING: HTTP/1.1 403 Forbidden 错误 .
如果这个服务器不是 web 服务器 , 可以把这个监控项去掉 .
如果必须要有这个服务 , 就在 /var/www/html/ 下面新建一个 index.html 文件

Windows client 安装
下载安装 NSClient++-0.3.8-Win32 , 安装时设 IP 地址, modules 选前三个。 在服务的登录身份
中选中允许服务与桌面交互就可以了

服务器端的设置
安装 nrpe-2.9
tar -zxvf nrpe-2.9.tar.gz
cd nrpe-2.9
./configure
make all
make install-plugin
测试连通性
/usr/local/nagios/libexec/check_nrpe -H 被监控端 ip
如果返回 nrpe 版本号, 正常
如果返回拒绝连接! 那么被监控端 nrpe 可能没启动
配置 commands.cfg
vi /usr/local/nagios/etc/objects/commands.cfg
最下面添加
#check nrpe

define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
添加监控主机
vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/linux.cfg 名字自己定义
linux 主机在 Definitions for monitoring the local (Linux) host 下面加
windows 主机在 Definitions for monitoring a Windows machine 下面加
新建 linux.cfg
vi /usr/local/nagios/etc/objects/linux.cfg
define host{
use linux-server
host_name game
alias linux-server
address 210.51.47.213
}
define service{
use generic-service
host_name game
service_description HTTP
check_command check_http
}
define service{
use generic-service
host_name game
service_description FTP
check_command check_ftp
}
define service{
use generic-service
host_name game
service_description SSH
check_command check_ssh
}
define service{
use generic-service
host_name game

service_description SMTP
check_command check_smtp
}
define service{
use generic-service
host_name game
service_description POP3
check_command check_pop
}
define service{
use generic-service
host_name game
service_description check-swap
check_command check_nrpe!check_swap
}
define service{
use generic-service
host_name game
service_description check-load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name game
service_description check-disk
check_command check_nrpe!check_disk
}
define service{
use generic-service
host_name game
service_description zombie_procs
check_command check_nrpe!check_zombie_procs
}
define service{
use generic-service
host_name game
service_description check-users
check_command check_nrpe!check_users

}
define service{
use generic-service
host_name game
service_description total_procs
check_command check_nrpe!check_total_procs
}
保存, 退出!这个里面定义了对象和服务!
windows 主机可以用模板 windows.cfg 修改 hostname 和 address 就可以了
cd /usr/local/nagios/etc/objects
cp windows.cfg windowADSL.cfg
vi windowADSL.cfg
# Define a host for the Windows machine we'll be monitoring
# Change the host_name, alias, and address to fit your situation
define host{
use windows-server ; Inherit default values from a template
host_name winserver ; The name we're giving to this host
alias My Windows Server ; A longer name associated with the host
address 121.48.96.188 ; IP address of the host
}
重新启动 nagios
service nagios restart

(责任编辑:IT)
------分隔线----------------------------