nagios部署
博客专区 > lee_ypp 的博客 > 博客详情
nagios部署
lee_ypp 发表于3年前
nagios部署
  • 发表于 3年前
  • 阅读 145
  • 收藏 0
  • 点赞 0
  • 评论 1

腾讯云 新注册用户 域名抢购1元起>>>   

摘要: nagios监控的部署 mysql主机的监控 nrpe插件的使用

RHEL6 Nagios 部署

系统环境:RHEL6 x86_64 selinux and iptables disabled

nagios 主机:192.168.2.20    server20.example.com

mysql 主机: 192.168.2.21    server21.example.com

#yum install httpd gcc make gd-devel perl-ExtUtils-Embed.x86_64 -y #编译所需软件包

#useradd nagios #运行 nagios服务的用户

#usermod -G nagios apache #使 apache用户对 nagios 目录具有写权限,不然web 页面操作失败

#tar jxf nagios-4.0.7.tar.gz #nagios 软件安装

#cd nagios-4.0.7

#./configure

#make all

#make install

#make install-init

#make install-commandmode

#make install-config

#make install-webconf

#make install-exfoliation

#make install-classicui

#yum install mysql-devel openssl-devel -y #编译所需软件包

#tar zxf nagios-plugins-1.4.15.tar.gz #nagios 插件安装

#cd nagios-plugins-1.4.15

#./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-extra-opts --enable-libtap –

enable-perl-modules

#make

#make install

#vi /usr/local/nagios/etc/nagios.cfg #nagios 配置

cfg_file=/usr/local/nagios/etc/objects/hosts.cfg #新建 hosts.cfg 文件,存放主机与主机组定义

cfg_file=/usr/local/nagios/etc/objects/services.cfg #新建 services.cfg 文件,存放服务与服务组定义

#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

#cd /usr/local/nagios/etc/objects

#cp localhost.cfg hosts.cfg

#cp localhost.cfg services.cfg

#vi /usr/local/nagios/etc/objects/host.cfg

define host{

use                     linux-server

host_name               server20.example.com

alias                   Manager

address                 127.0.0.1

icon_image               server.gif

statusmap_image       server.gd2

2d_coords               500,200

3d_coords               500,200,100

}

define hostgroup{ #主机组并不是必须的,这是配合nagios 的监控页面的显示

hostgroup_name  linux-servers

alias           Linux Servers

members         *

}

#vi /usr/local/nagios/etc/objects/services.cfg

define service{

use                             local-service

host_name                       *

service_description             PING

check_command                   check_ping!100.0,20%!500.0,60%

}

define service{

use                             local-service

host_name                       *

service_description             根分区

check_command                   check_local_disk!20%!10%!/

}

define service{

use                             local-service

host_name                       *

service_description             登录用户数

check_command                   check_local_users!20!50

}

define service{

use                             local-service

host_name                       *

service_description             进程数

check_command                   check_local_procs!250!400!RSZDT

}

define service{

use                             local-service

host_name                       *

service_description             系统负载

check_command                   check_local_load!5.0,4.0,3.0!10.0,6.0,4.0

}

define servicegroup{ #服务组并不是必须的,这是配合nagios 的监控页面的显示

servicegroup_name 系统状况检查

alias 系统概况

}

#usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #校验 nagios 配置文件的正确性

#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin #nagios 监控页面访问用户和密码

#service nagios start #启动 nagioshttpd 服务

#service httpd start

http://192.168.2.20/nagios #访问 nagios监控页面,输入上面添加的用户名和密码

监控 mysql 主机

mysql 主机上运行有 mysql服务,在其上创建监控检测帐户

mysql> create database nagdb;

mysql> grant select on nagdb.* to nagdb@'192.168.2.21';

mysql> flush privileges;

nagios 主机上检测是否可以连接mysql 主机上的 mysql 服务

/usr/local/nagios/libexec/check_mysql -H 192.168.2.20 -u nagdb -d nagdb

Uptime: 73 Threads: 1 Questions: 7 Slow queries: 0 Opens: 15 Flush tables: 1 Open tables: 8

Queries per second avg: 0.95

nagios 主机上添加对mysql 服务监控的定义

#vi /usr/local/nagios/etc/objects/hosts.cfg 添加如下行

define host{

use linux-server

host_name mysql 主机

alias mysql 服务器

address 192.168.2.20

icon_image server.gif

statusmap_image server.gd2

2d_coords 500,200

3d_coords 500,200,100

}

#vi /usr/local/nagios/etc/objects/services.cfg 添加如下行

define service{

use local-service

host_name mysql 主机

servce_groups mysql 服务组

service_description mysql 服务

check_command check_mysql

}

define servicegroup{

servicegroup_name mysql 服务组

alias mysql 服务器

}

#vi /usr/local/nagios/etc/objects/commands.cfg 添加如下行

define command{

command_name check_mysql

command_line $USER1$/check_mysql -H $HOSTADDRESS$ -u nagdb -d nagdb

}

#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

#service nagios reload

Nagios 通过 NRPE 监控远程主机系统状况

远程主机设定

#useradd nagios

#tar xzf nagios-plugins-1.4.15.tar.gz

#cd nagios-plugins-1.4.15

#./configure --with-nagios-user=nagios --with-nagios-group=nagios

#make

#make install

#yum install xinetd -y

#tar zxf nrpe-2.12.tar.gz

#cd nrpe-2.12

#./configure

#make all

#make install-plugin

#make install-daemon

#make install-daemon-config

#make install-xinetd

#vi /etc/xinetd.d/nrpe 修改如下行

only_from = 192.168.0.71 #nagios 主机ip 地址

#vi /etc/services 添加如下行

nrpe 5666/tcp #nrpe 服务监听端口

#vi /usr/local/nagios/etc/nrpe.cfg 修改如下行

command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p / #根分区监测

#service xinetd restart

#netstat -antlp |grep 5666

#tcp 0 0 :::5666 :::* LISTEN 26359/xinetd #看到如下输出说明NRPE 正常启动,并确保防火墙允许此端口

监控主机设定

#tar zxf nrpe-2.12.tar.gz

#cd nrpe-2.12

#./configure --with-nagios-user=nagios --with-nagios-group=nagios

#make all

#make install-plugin

#/usr/local/nagios/libexec/check_nrpe -H 192.168.2.20 #如看到如下输出说明连接正常

NRPE v2.12

#vi /usr/local/nagios/etc/objects/commands.cfg 添加如下行

define command{

command_name check_nrpe

command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

}

#vi /usr/local/nagios/etc/objects/services.cfg 添加如下行

define service{

use generic-service

host_name mysql 主机

service_description CPU Load

check_command check_nrpe!check_load

}

define service{

use generic-service

host_name mysql 主机

service_description Current Users

check_command check_nrpe!check_users

}

define service{

use generic-service

host_name  mysql 主机

service_description / Free Space

check_command check_nrpe!check_disk

}

define service{

use generic-service

host_name  mysql 主机

service_description Total Processes

check_command check_nrpe!check_total_procs

}

define service{

use generic-service

host_name  mysql 主机

service_description Zombie Processes

check_command check_nrpe!check_zombie_procs

}

#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

#service nagios reload

                --leeypp@gmail.com

共有 人打赏支持
粉丝 65
博文 43
码字总数 58692
评论 (1)
lee_ypp
最新版本的nagios部署
×
lee_ypp
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: