Nagios是一款开源的免费网络监视工具,能有效监控Windows、Linux和Unix的主机状态,交换机路由器等网络设备,打印机等。在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员,在状态恢复后发出正常的邮件或短信通知。
Nagios能监视所指定的本地或远程主机以及服务,同时提供异常通知功能等。
需要的软件包如下:
nagios-4.2.4 nagios-plugins-2.1.4 nrpe-3.0.1 httpd php
依赖包及环境如下:
gcc gcc-c++
创建进程所需用户:
[root@cc]# useradd nagios
[root@cc]# groupadd nagcmd
安装软件包nagios:
[root@cc]# yum -y install gcc gcc-c++
[root@cc]# tar -zxvf nagios-4.2.4.tar.gz //解包
[root@cc]# cd nagios-4.2.4/
[root@cc]# ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd --with-command-user=nagios --with-command-group=nagcmd
//配置
[root@cc]# make all //安装
[root@cc]# make install
[root@cc]# make install-init
[root@cc]# make install-commandmode
[root@cc]# make install-config
[root@cc]# make install-webconf
[root@cc]# make install-exfoliation
[root@cc]# make install-classicui
部署服务的运行环境:
[root@cc]# echo "cc" > /var/www/html/index.html //静态网页主页
[root@cc]# vim /var/www/html/index.php //动态网页主页
<?php
phpinfo();
?>
安装软件包nagios-plugins:
[root@cc]# tar -xf nagios-plugins-2.1.4.tar.gz
[root@cc]# ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd
[root@cc]# make
[root@cc]# make install
启用及访问Nagios平台:
Nagios平台添加web管理用户:
[root@cc]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin //根据提示输入两次密码
重启nagios和httpd服务
[root@cc]# systemctl restart httpd
[root@cc]# systemctl restart nagios
客户端访问Nagios平台如下:
默认安装目录为:/usr/local/nagios -/usr/local/nagios/bin 程序命令 -/usr/local/nagios/libexec 监控插件以及工具 -/usr/local/nagios/sbin cgi脚本 -/usr/local/nagios/share Nagios网页目录 -/usr/lcoal/nagios/var Nagios运行数据
-commands.cfg 监控命令配置 -localhost.cfg 监控本机对象设置 -contacts.cfg 报警收件邮箱设置 -timeperids.cfg 监控时间模版 -templates.cfg 监控方式模版
监控的过程以及原理:
服务启动时自动调用监控插件,调用插件时,管理者可以设置监控插件的警告值和错误值,监控插件把获取到的数据和管理者定义的警告和错误值比较,根据比较结果返回监控状态:
若 获取到的数据 < 警告值 返回监控状态 OK 若 获取到的数据 > 警告值 并且 < 错误值 返回监控状态 WARNING 若 获取到的数据 > 错误值 返回监控状态 CRITICAL
使用插件帮助信息:./check_* -help
[root@cc]# cd /usr/local/nagios/libexec/
[root@cc]# ./check_users -w 3 -c 5 //监控本机登陆用户,3个报警5个报错
[root@cc]# ./check_http -H localhost //监控本机httpd服务
[root@cc]# ./check_tcp -H localhost -p 3306 //监控本机数据库服务端口tcp协议
要求:监控本机的ftp服务运行状态,监控本机引导分区的使用量,不再对本机的交换分区做监控,监控本机登录系统用户数量时把警告值修改为1 错误值修改为2。
配置监控重点:
1.修改commonds.cfg 增加监控命令
2.修改localhost.cfg 添加监控对象
操作如下:
[root@cc]# vim /usr/local/nagios/etc/objects/commands.cfg define command { command_name check_local_ftp command_line $USER1$/check_ftp -H localhost } define command { command_name check_local_boot command_line $USER1$/check_disk -w 50% -c 25% -p /boot }
[root@cc]# vim /usr/local/nagios/etc/objects/localhost.cfg
define service{
use local-service
host_name localhost
service_description ftp
check_command check_local_ftp
}
define service{
use local-service
host_name localhost
service_description boot
check_command check_local_boot
}
客户端访问如下:
要求:配置远程主机192.168.4.10 apache服务器运行状态
[root@cc]# yum -y install httpd [root@cc]# echo "cc" > /var/www/html/index.html [root@cc]# systemctl restart httpd
[root@cc]# vim /usr/local/nagios/etc/nagios.cfg cfg_file=/usr/local/nagios/etc/objects/server10.cfg
[root@cc]# vim server10.cfg define host { use linux-server host_name server-10 address 192.168.4.10 } define service { use
local-service host_name server-10 service_description httpd check_command check_10_httpd }
[root@cc]# vim command.cfg define command{ command_name check_10_httpd command_line $USER1$/check_http -H 192.168.4.10 }
[root@cc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[root@cc]# /etc/init.d/nagios stop [root@cc]# /etc/init.d/nagios start
要求:监控远程主机boot使用量,登陆用户数,进程数
配置远程主机192.168.4.10
[root@cc]# tar -xf nagios-plugins-2.1.4.tar.gz [root@cc]# ./configure [root@cc]# make [root@cc]# make install
[root@cc]# useradd nagios [root@cc]# yum -y install openssl-devel //加密传输 [root@cc]# tar -xf nrpe-3.0.1.tar.gz [root@cc]# cd nrpe-3.0.1 [root@cc]# ./configure [root@cc]# make all [root@cc]# make install [root@cc]# make install-config [root@cc]# make install-init
[root@cc]# vim /usr/local/nagios/etc/nrpe.cfg
command[nrpe_check_users]=/usr/local/nagios/libexec/check_users -w 3 -c 4
command[nrpe_check_boot]=/usr/local/nagios/libexec/check_disk -w 50% -c 25% /boot command[nrpe_check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
[root@cc]# systemctl restart nrpe [root@cc]# netstat -antup | grep 5666
配置监控服务器
[root@cc]# yum -y install openssl-devel [root@cc]# tar -xf nrpe-3.0.1.tar.gz [root@cc]# cd nrpe-3.0.1/ [root@cc]# ./configure [root@cc]# make [root@cc]# make install
[root@cc]# vim commands.cfg define command{ command_name check_20_users command_line $USER1$/check_nrpe -H 192.168.4.20 -p 5666 -c nrpe_check_users } define command{ command_name check_20_boot command_line $USER1$/check_nrpe -H 192.168.4.20 -p 5666 -c nrpe_check_boot } define command{ command_name check_20_procs command_line $USER1$/check_nrpe -H 192.168.4.20 -p 5666 -c nrpe_check_total_procs }
[root@cc]# vim server10.cfg define service{ use
local-service host_name server20 service_description users check_command check_20_users!nrpe_check_users } define service{ use
local-service host_name server20 service_description boot check_command check_20_boot!nrpe_check_boot } define service{ use
local-service host_name server20 service_description process check_command check_20_procs!nrpe_check_total_procs }
[root@cc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[root@cc]# /etc/init.d/nagios stop [root@cc]# /etc/init.d/nagios start
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。