监控机为Linux主机的nagios安装与配置之利用snmp方式监控远程主机上的“本地信息”
来源:互联网 发布:学费软件 编辑:程序博客网 时间:2024/05/20 06:24
一、前提条件
1 监控机:Linux一台
2 被监控机器:Linux几百台,且远程主机snmp服务已开启。
3 所需软件:
l Nagios-cn-3.2.3.tar.gz
l Nagios-plugins-2.0.3.tar.gz
l Nagios-snmp-plugins.1.1.1.tar.gz
l Crypt-DES-2.07.tar.gz
l Digest-HMAC-1.03.tar.gz
l Digest-MD5-2.53.tar.gz
l Digest-SHA1-2.13.tar.gz
l Net-SNMP-v6.0.1.tar.gz
下载见我的资源共享
二、主要步骤
1 安装nagios-cn-3.2.3.tar.gz
2 安装nagios插件nagios-plugins-2.0.3.tar.gz
3 安装与配置Apache和php
4 配置nagios
5 启动nagios
6 查看初步配置情况,如本机的相关信息。
7 监控远程Linux主机上的“本地信息”
可采取两种方式
l 利用nrpe组件监控远程Linux主机上的“本地信息”
l 利用SNMP方式监控远程Linux主机上的“本地信息”
比较:
利用nrpe组件,需要在监控端和被监控端都安装部分插件。
利用snmp方式,只需要在监控端和被监控端都开启snmp服务,修改些配置文件即可。
下面具体介绍采用snmp方式监控。
三、利用snmp方式监控远程主机上的“本地信息”
1 假设上面二中的1-6均已成功,即监控机能查看基本的服务。
2 snmp服务的安装与配置
2.1.安装snmp服务
yum -y install net-snmp*
2.2.启动snmp服务
service snmpd start
2.3. 验证snmp服务
使用snmpwalk命令,查看本机localhost的主机名:
snmpwalk -c public –v 2c localhost sysName.0
2.4. 配置snmp服务
修改监控机器和被监控机器的etc/snmp/snmpd.conf文件。如下是该配置文件的3个片段,修改部分在行尾注释了。
vi snmpd.conf
####
# First, map the community name"public" into a "security name"
sec.name source community
com2sec notConfigUser default public//共同体名字可修改为自己需要的字符串
####
# Finally, grant the group read-only accessto the systemview view.
group context sec.modelsec.level prefix read write notif
access notConfigGroup "" any noauth exact mib2 none none//修改为mib2
access notConfigGroup "" any noauth exact all none none//添加此行
## incl/excl subtree mask
view all included .1 80//此行前面的#去掉
## -or just the mib2 tree-
view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc//此行前面的#去掉
然后保存修改,重启snmp服务
service snmpd restart
3 安装Nagios-snmp-plugins
3.1 首先安装以下模块
Crypt-DES-2.07.tar.gz、Digest-HMAC-1.03.tar.gz、Digest-MD5-2.53.tar.gz、Digest-SHA1-2.13.tar.gz
3.2 然后安装Net-SNMP-v6.0.1.tar.gz
安装方法: tar –zxvf xxx.tar.gz
cd xxx
perl Makefile.pl
make test
make install
3.3 最后安装nagios-snmp-plugins.tar.gz
安装方法: tar–zxvf nagios-snmp-plugins.tar.gz
cdnagios_plugins 可以看到很多可用的插件
4 将需要的插件复制放到/usr/local/nagios/libexec目录下,并修改属主和添加文件的权限
cd/usr/local/nagios/libexec
chownnagios.nagios ./check_snmp_*
chmod777 ./check_snmp_*
5 Nagios分组显示监控服务。
由于主机过多,需要分组查看,因此分成了多个文件,每个文件中只包含若干个主机组和它包含的主机。
5.1 修改commands.cfg。在文件尾部添加命令如下:
################################################SNMP
#'check_snmp_load'
define command{
command_name check_snmp_load
command_line $USER1$/check_snmp_load.pl -H $HOSTADDRESS$ -C $ARG1$ -p $ARG2$ -w$ARG3$ -c $ARG4$
}
#'check_snmp_int'
define command{
command_name check_snmp_int
command_line $USER1$/check_snmp_int.pl -H$HOSTADDRESS$ -C $ARG1$ -n $ARG2$ -f -kB -Y -w $ARG3$,$ARG4$ -c $ARG5$,
$ARG6$ -d $ARG7$
}
#'check_traffic2'
define command{
command_name check_traffic2
command_line $USER1$/check_traffic2.sh -V 2c-C public -H $HOSTADDRESS$ -I $ARG1$-w $ARG2$ -c $ARG3$ -K -b
}
#'check_snmp_storage'
define command{
command_name check_snmp_storage
command_line $USER1$/check_snmp_storage.pl -H$HOSTADDRESS$ -C $ARG1$ -m $ARG2$ -w $ARG3$ -c $ARG4$ -S 0
}
#'check_snmp_proc'
define command{
command_name check_snmp_proc
command_line $USER1$/check_snmp_process.pl -H$HOSTADDRESS$ -C $ARG1$ -n $ARG2$ -m$ARG3$ -u $ARG4$ -t $ARG5$
}
5.2 定义并配置主机监控文件,如下为hosts住房-活体.cfg
define host{
use linux-server
host_name 住房-活体-济南/长春
alias 16.198.64.4
address 16.198.64.4
}
......
define host{
use linux-server
host_name 住房-活体-秦皇岛
alias 16.198.64.14
address 16.198.64.14
}
#定义主机组
define hostgroup{
hostgroup_name 住房-活体
alias 住房-活体
members 住房-活体-济南/长春, 住房-活体-青岛/大连, 住房-活体-石家庄/天津,住房-活体-沈阳/乌鲁木齐,住房-活体-呼>和浩特/哈尔滨, 住房-活体-合肥/银川, 住房-活体-西宁/深圳, 住房-活体-郑州/西安 , 住房-活体-兰州/太原, 住房-活体-北京, 住房-活体
-秦皇岛
}
如此类推,定义所有的主机文件。
5.3 定义每个主机需要监控的服务和主机资源services.cfg,如下
define service{
use local-service
host_name *
service_description Ping
check_command check-host-alive
}
define service{
use local-service
host_name *
service_description 检查cpu负载
check_command check_snmp_load!public!161!80!90
}
define service{
host_name *
service_description 网卡监控-eth0
check_command check_snmp_int!public!eth0!4000!4000!5000!5000!60
max_check_attempts 5
normal_check_interval 1
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_options w,u,c,r
process_perf_data 1
}
define service{
host_name *
service_description 网卡监控-eth1
check_command check_snmp_int!public!eth1!4000!4000!5000!5000!60
max_check_attempts 5
normal_check_interval 1
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_options w,u,c,r
process_perf_data 1
}
define service{
use local-service
host_name *
service_description 网卡流量监控-eth0
check_command check_traffic2!2!200,300!400,500
}
define service{
use local-service
host_name *
service_description 网卡流量监控-eth1
check_command check_traffic2!3!200,300!400,500
}
define service{
use local-service
host_name *
service_description 磁盘监控 /
check_command check_snmp_storage!public!"/"!92%!96%
is_volatile 0
check_period 24x7
max_check_attempts 30
normal_check_interval 1
retry_check_interval 1
notification_interval 10
notification_options w,u,c,r
process_perf_data 1
}
define service{
use local-service
host_name *
service_description 检查虚拟内存使用率
check_command check_snmp_storage!public!"Virtual Memory"!70!90
is_volatile 0
check_period 24x7
max_check_attempts 30
normal_check_interval 1
retry_check_interval 1
notification_interval 10
notification_options w,u,c,r
process_perf_data 1
}
define service{
use local-service
host_name *
service_description 检查物理内存使用率
check_command check_snmp_storage!public!"Real Memory"!70!90
is_volatile 0
check_period 24x7
max_check_attempts 30
normal_check_interval 1
retry_check_interval 1
notification_interval 10
notification_options w,u,c,r
process_perf_data 1
}
define service{
use local-service
host_name *
service_description 磁盘监控 /boot
check_command check_snmp_storage!public!"/boot"!92%!96%
is_volatile 0
check_period 24x7
max_check_attempts 30
normal_check_interval 1
retry_check_interval 1
notification_interval 10
notification_options w,u,c,r
process_perf_data 1
}
define service{
use local-service
host_name *
service_description 磁盘监控 /data
check_command check_snmp_storage!public!"/data"!92%!96%
is_volatile 0
check_period 24x7
max_check_attempts 30
normal_check_interval 1
retry_check_interval 1
notification_interval 10
notification_options w,u,c,r
process_perf_data 1
}
define service{
use local-service
host_name *
service_description 进程 mysqld
check_command check_snmp_proc!public!mysqld!200,300!90,99!10
}
define service{
use local-service
host_name *
service_description 进程mysqld_safe
check_command check_snmp_proc!public!mysqld_safe!200,300!90,99!10
}
define service{
use local-service
host_name *
service_description 进程 postgres
check_command check_snmp_proc!public!postgres!200,300!90,99!10
}
5.4 最后,需要修改nagios.cfg,添加各个文件的路径定义。
# You can specify individual object configfiles as shown below:
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_file=/usr/local/nagios/etc/objects/hosts住房-容灾.cfg
cfg_file=/usr/local/nagios/etc/objects/hosts住房-平台.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
5.5 重启nagios服务,即可登录web,查看相关服务的情况,如下图所示。
图nagios服务
- 监控机为Linux主机的nagios安装与配置之利用snmp方式监控远程主机上的“本地信息”
- nagios 监控 linux主机的信息
- Nagios监控平台之二:nrpe监控远程Linux主机
- Nagios监控远程主机
- Nagios远程监控软件的安装与配置详解(上)
- Nagios 探索之四 —— 主机监控的配置
- ubuntu nagios 配置监控远程主机
- nagios监控Linux主机
- nagios 监控Linux 主机
- nagios监控 主机与被监控机配置
- Nagios监控linux主机以及硬件信息
- Nagios利用NRPE监控Linux主机
- Nagios利用NRPE监控Linux主机
- nagios监控远程主机的存活、磁盘空间监控、负载监控、进程数监控、ip 连接
- nagios监控远程主机进程
- nagios监控远程主机端口
- nagios全攻略(四)----监控LINUX上的”本地信息”
- nagios监控远程主机服务可能出现的问题
- C语言的指针、数组和函数的联系
- Android自定义控件实战——滚动选择器PickerView
- Ubuntu 配置网络命令
- 平衡二叉树转化为双向链表
- POJ3692——Kindergarten
- 监控机为Linux主机的nagios安装与配置之利用snmp方式监控远程主机上的“本地信息”
- Web.xml配置详解之context-param
- Swift(二)
- hdu1004 Let the Balloon Rise
- 所有时间都不是虚度的,经过定有痕迹
- eclipse生成注释
- VIM配置文件vimrc
- spring循环依赖
- FMDB的一些基本操作小结