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 #编译所需软件包 nagios培训 #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%!/ nagios实施 }
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 #启动 nagios和 httpd 服务
#service httpd start
nagios #访问 nagios监控页面,输入上面添加的用户名和密码
[ /uploads/space/2014/0720/161405_bb2I_1867979.png][/url] 监控 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 添加如下行 nagios配置 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
[ /uploads/space/2014/0720/161539_KMBQ_1867979.png][/url] Nagios 通过 NRPE 监控远程主机系统状况 [ /uploads/space/2014/0720/161643_x0mN_1867979.png][/url] 远程主机设定
#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
想做Nagios, Zabbix,Cacti,iTop各种交流的,可以进入开源监控工具Nagios交流 QQ群号 :476809427
|