将设为首页浏览此站
开启辅助访问 天气与日历 收藏本站联系我们切换到窄版

易陆发现论坛

 找回密码
 开始注册
查看: 55|回复: 1
收起左侧

zabbix监控另一种方式安装与解析

[复制链接]
发表于 2022-11-3 17:30:05 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?开始注册

x
1.首先在服务器端安装snmp工具
[root@bogon yinzhengjie]# yum -y installnet-snmp-utils snmp-libs snmp-devel snmp
2.检测与路由器的连通性
[root@bogon yinzhengjie]# snmpwalk  -v 2c -c private192.168.1.1
在执行此命令之前~你首先要确认你的路由器是否开启了snmp功能哟~
% N! q6 q7 P  ?" v* i- n- K4 G, N  |
出现如下信息说明情况是正确的~这是zabbix server在服务器上可以在你的路由器获取到信息
3.添加路由器的监控主机
4.用snmp协议进行监控

' `. Z' u5 c, ~
5.选择zabbix自带的模板

6 N8 M$ d" t! y, R" H/ z6 c8 B1 {
等2分钟左右~会生成图像

8 C2 ]8 [6 ]; T% y& r6 j- ^+ G
我们来查看一下我的路由器的wan1口的出口流量

6 D$ I: j  m& ]$ ]: q; o$ u+ v. X4 f# \
我们的设备是双WAN口的路由器,让我们一起看看wan2口的流量吧

4 i$ g% {& P' B) G9 ?
5 n) r0 d6 R) |# B% ^
" t- C  ?. g5 `! ]; G3 V1 q
至此~我们对路由器的监控就搞定了~那么~你成功了吗?

$ E  q* r" j# T7 b* `2 }# T+ r% t1 I& W0 @2 v6 k: j  T- B
Step 1: Configure SNMP on the CiscoSwitch or Router
Configure SNMPv2c on Cisco routers andswitches with one command as shown below:
switch> enable
switch# configure terminal
switch(config)# snmp-server communityMyCommunity RO
switch(config)# exit
switch# copy running-config startup-config
That will cover most Cisco devices, but ifyou need to use SNMPv3 or configure Nexus or ASA firewall then read this short tutorial.
My favorite tool for testing SNMP isNet-SNMP. On Ubuntu/Debian you can install Net-SNMP tools with one simplecommand: “apt-get install snmp“,  or if you have CentOS/RHEL you canuse “yum install net-snmp net-snmp-utils“.
Run the following Net-SNMP command fromLinux machine to verify that SNMP is working as configured onthe device:
snmpwalk -v2c -c MyCommunity 192.168.1.11.3.6.1.2.1.1.1
iso.3.6.1.2.1.1.1.0 = STRING: "CiscoIOS Software, Catalyst 4500 L3 Switch Software (cat4500-ENTSERVICESK9-M),Version 12.2(54)SG1, RELEASE SOFTWARE (fc1)
Copyright (c) 1986-2011 by Cisco Systems,Inc.
Compiled Thu 27-Jan-11 11:39 "
If your snmpwalk fails, then make sure thatthe network or local firewall on the device is not blocking UDP port 161.
Need more examples for Net-SNMP tool usage?Check out my post about snmpwalk / snmpget examples.
Step 2: Install Zabbix monitoring system
You can install Zabbix in 10 minutes.Depending on your operating system (OS) preferences you can follow CentOS/Alma/Rocky/RHEL, Ubuntu, Debian, Raspberry Pi (Rasbian) tutorial.
Step 3: Change global SNMP communitystring for all devices
Zabbix needs SNMP community string toretrieve data from SNMP enabled devices. A community string is like a password.Global SNMP community string in Zabbix is “public” and if you are usingsomething else than you need to change it.
You can change community string for alldevices by changing value for macro “{$SNMP_COMMUNITY}” under Administration→General→Macrosjust as shown in the picture below.
Picture showing how to changeglobal macro {$SNMP_COMMUNITY} on Zabbix
WELL DONE!
5 O; m; Q# r9 _- G" \% T/ {2 z% mSNMP is enabled on the device and Zabbix is ready for monitoring. Now it’s timeto add that device to Zabbix.
Step 4: Add host to Zabbix withappropriate SNMP template
Go to the “Hosts” menu under the “Configuration”tab and click the “Create host” option to create a host in Zabbix.Define the name of your switch/router in the “Host name” field andchoose the appropriate template for your Cisco device under the section “Templates”by typing “Cisco”. Select the “Cisco IOS SNMP” template if you are notsure what to choose.
Picture showing how to addCisco Switch or Router to Zabbix monitoring system
Next, set “Groups” using existinghost groups or create a new one. Then add SNMP interface under the “Interfaces”section and set the IP address of the device.
CONGRATULATIONS!7 M' |0 U" `; e; b2 f" h2 \  [* _& l
You have successfully configured network monitoring (Cisco router and switch)on Zabbix!# `6 V, l: K( N/ X& z1 e6 N
No need to change anything else as other steps are optional.
. u$ U2 F3 i. i1 R3 T7 }" I  X9 y4 M
CONTINUE TO LEARN MORE:
3 d/ w7 E1 ^1 i5 V; T; P) {# YHow to use Clone option?3 l5 G9 M) c. U" @8 M3 t+ S
Create discovery rules and action to automatically add devices to Zabbix0 s5 U; i4 R5 S* l
Change community string per host
- ?1 O( J5 W! A3 Z2 @2 H+ B2 s7 mHow to force instant data collection
Step 5: Tips and tricks (optional)
This step is optional, but I stronglyrecommend the tips and tricks from this section, as they will ease your hostadministration in Zabbix.
a) Use Clone option
After you have added your first device youcan add other similar devices very fast by using “Clone” option.Clicking on “Clone” will retain all host parameters andtemplate linkage (don’t use “Full clone” option because itwill retain directly attached entities: applications, items, triggers, graphs,low-level discovery rules, and web scenarios).
Pictureshowing how to clone a host in Zabbix
Stepsfor clonning are very simple. Find the host that you want to clone with the “Search”option. Click on the “Clone” option, then change the “Host name”and “IP address” and add a new host by pressing “Add”button
b) Create discovery rules andaction to automatically add devices to Zabbix
Adding hosts to Zabbix manually is tediousjob, and even with the “Clone” option, it’s still slow and error-proneprocess. Wouldn’t it be great if Zabbix could automatically discover devices onthe network, add them to the appropriate host group and link them to theappropriate template depending on whether it was a Cisco, Juniper, HP,Mikrotik, Huawei device?
Well, good news! Zabbix can do just that!Let me show you.
I will configure Zabbix discovery rule thatwill scan the network and search for SNMP enabled devices. Discovery will querydevices with SNMP OID 1.3.6.1.2.1.1.1 (sysDescr) which contains a lot ofinformation about the vendor, hardware, and software versions of the device.This information will allow us to add devices to the appropriate host group andlink them to the appropriate template.
Go to the “Discovery” under the “Configuration”section and click the “Create discovery rule” option. Define the name ofyour discovery and your network. You can set one network like 192.168.1.1-255or use multiple networks divided with a comma just like I did in the picturebelow.
Pictureshowing how to create discovery rule in Zabbix
Under the section “Checks” add adiscovery check that will use: SNMPv2 agent on port 161; default Zabbix SNMPcommunity (you can change that to a another community ); and SNMP OID1.3.6.1.2.1.1.1.0.
Click the “Add” button when you aredone with the configuration.
Nice job! Zabbix will now scan the networkand on the “Discovery” section under the “Monitoring” tab, youcan view all the devices that Zabbix has found.
What now? Now we need to create a discoveryaction that will do something with discovered devices! In my case, I willconfigure a discovery action that will link Cisco devices to the Cisco templateand add them to the host group for network devices.
Navigate to “Configuration“→ “Actions”→ “Discovery actions” and click the “Create action” button in theupper right corner. Enter the name of your action and add 2 conditions justlike in the image below. Condition A will make sure that this discovery checkis only active on our newly create discovery rule, in my case that would be thediscovery rule “Discover my network“, and condition B will take intoaccount only devices that cointain the word “Cisco” in systemdescription (1.3.6.1.2.1.1.1.0).
Pictureshowing how to create discovery actions in Zabbix
Next, under the “Operations” tabcreate two operation, one that will link the device to the “Cisco IOS SNMP”template, and the other that will add the device to the host group “Devices/Network”(of course you can link any template and add any group as you wish).
Click the “Add” button when you’redone with the configuration! And that’s all there is to Zabbix rules anddiscovery actions!
c) Use “Execute now” option to forceinstant discovery and data collection
It will take some time before Zabbixdiscovers components (interfaces, power supply, serial number, etc.) on thenewly added device. Usually, it takes around 1 hour, but if you are impatientyou can speed things up by using the “Execute now” option.
Picture showing how toinstantly check all the LLD discoverys on a Zabbix host
Find the host that you want to force aninstant check with “Search” option and click on “Discovery“.Select all discoveries (LLD) and click “Execute now” option.
Most items have faster polling intervals(around 1 minute) so there is no need to use “Execute now” on them.However, you can force instant check even for them. Move to “Items”sections and do the same: select all items (ignore “SNMP trap” and “ZabbixTrapper” item types if present) and click “Execute now“.
d) Change SNMP community string per host(multiple SNMP community)
What if one device has a different SNMPcommunity string and (for some reason) you can’t change it on the device? Noproblem, you can set different SNMP community on any host in Zabbix.
How to change the SNMPcommunity string only for one host
Find the host that that is using differentSNMP community with the “Search” option. Under host configurationselect “Macros” and change tab to “Inherited and host macros“.Click “Change” on macro “{$SNMP_COMMUNITY}” and enter your newcommunity string. Hit the “Update” button after changing the SNMPcommunity.
Under host configuration select “Macros”and change tab to “Inherited and host macros“. Click “Change” onmacro “{$SNMP_COMMUNITY}” and enter your new community string. Hit the“Update” button after changing the SNMP community.
# i7 [1 G1 k! u& a0 V, {
Thank you for reading.4 \0 e" j" N; U! q/ d/ H0 c. l% s

0 l- J. Z% b# a. l9 Y4 V* r
Now, that you have your routers andswitches monitored, you can try out Zabbixinteractive topology maps!
, J5 {& D  l0 ?. Q2 u6 h) U5 K# V0 U

  g/ Q3 ?( S6 c2 {  f9 s

zabbix监控.docx

1.76 MB, 下载次数: 0

 楼主| 发表于 2022-11-3 17:30:06 | 显示全部楼层
一、实验环境  
    zabbix监控机(CentOS 7.7):192.168.10.7/24
    交换机(华为S5700):192.168.10.100/24
    路由器(华为AR2220):192.168.10.254/24
—— 基于eNSP+VMware环境搭建拓扑
eNSP+VMnet8网云配置如下:

9 s- p, k# U% }- T
        
二、配置SNMP被控端  
; j+ y' Y% `5 v" N& V9 `9 ^# k
1. 交换机(华为S5700)
    ++ 设置SNMP共同体为HUAWEI、允许读,支持协议SNMPv2c
    ++ 授权IP地址192.168.10.7作为监控主机
[hw-lsw1]snmp-agent 5 U1 s6 u- L& Q0 e3 E
[hw-lsw1]snmp-agent  community  read  HUAWEI
- Y7 ?2 ?# E) P5 K' p1 f1 c5 a[hw-lsw1]snmp-agent sys-info version v2c/ T1 y% ?& p7 B( H9 Y6 v) `
[hw-lsw1]snmp-agent target-host  trap  address  udp-domain  192.168.10.7  params  securityname  HUAWEI. {2 L0 C/ y& s

- K) i! i, j1 J  e
2. 路由器(华为AR2220)
    ++ 设置SNMP共同体为HUAWEI、允许读,支持协议SNMPv2c
    ++ 授权IP地址192.168.10.7作为监控主机
[hw-ar1]snmp-agent
% `0 d1 ~- L- y8 A[hw-ar1]snmp-agent  community  read  HUAWEI2 b# R8 s, i$ Y) Y
[hw-ar1]snmp-agent  sys-info  version  v2c
" [& Y! P7 n$ T- z[hw-ar1]snmp-agent  target-host  trap-hostname  zbx.example.com  address  192.168.10.7 trap-paramsname  HUAWAEI
" V0 P3 z. [/ ?% y, w; b

0 B/ N; ]- L3 D& e7 ~
* W  U) T, o  ^* p: H$ c1 E  G2 P7 K. K
三、在zabbix控制台添加设备  
1. 通过“配置-》主机-》创建主机”添加交换机 华为s5700-lsw1
1)设置好主机名、可见名、分组、SNMP接口信息
0 u9 h& z' I* I$ [
2)链接到“Template Net Huawei VRP SNMPv2”监控模板
$ ^& R# @7 R  n) F4 q
3)设置好认证宏/变量 {$SNMP_COMMUNITY} => HUAWEI

6 _* p" R6 n) V
2. 通过“配置-》主机-》创建主机”添加路由器 华为ar2220-ar1
1)设置好主机名、可见名、分组、SNMP接口信息

+ w0 B- s! J7 O; Y5 P9 i
2)链接到“Template Net Huawei VRP SNMPv2”监控模板

& J5 f2 H) o7 }3 V* N' F. _
3)设置好认证宏/变量 {$SNMP_COMMUNITY} => HUAWEI
! S) N# |5 j' a" n
3. 确认已添加的设备及连接状态(SNMP可用性为绿色)
    ++ 通过“配置-》主机”查看。

* n) w6 E2 g$ \; b( D$ W

" J, Q4 W! O3 v% d# T
三、管理设备监控项、查看监控图形  
    ++ zabbix监控模板已经包含大量预设的监控项(设备描述、设备名称、开机时间等),这些监控项可以直接使用。
    ++ zabbix自动发现机制也会设置大量的监控项(比如各接口的流量、带宽/速度等),这些监控项也可以直接使用。
1)查看监控项
3 D, a: I  \9 |, ]+ p; b4 ]
2)查看监控图形

2 h$ s2 k: v* M: w4 [% \  s5 }* @
3)禁用冗余监控项,减轻zabbix及设备的数据采集压力
6 R) I  n- o& s; f
    ++ 对于用不到的监控项目(比如针对闲置端口的监控项),应该将其禁用或者删除(自动发现的项目允许删除),只保留希望监控的监控项即可。
: L- V4 r1 G& a5 G2 p/ I1 `$ n
4)手动添加其他监控项
    ++ 如果管理员要手动添加SNMP监控项,需要设置相应指标的SNMP OID名称(或值)
    ++ 在zabbix监控机(CentOS)中可以参考以下方法获取相关信息
[root@zbx ~]# snmpwalk  -c  HUAWEI  -v2c  192.168.10.254   列出所有的OID指标名称、数据% ]8 S- w& V0 m: A
SNMPv2-MIB::sysDescr.0 = STRING: Huawei AR2220 Huawei Versatile Routing Platform Software  VRP (R) software,Version 5.130 (AR2220 V200R003C00) Copyright (C) 2011-2012 Huawei Technologies Co., Ltd( M( U4 g" I# O& u* k5 Z, S
SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.2011.2.224.5
* j0 |# h# p; @, yDISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (708888) 1:58:08.88
/ c* [% p+ |$ @) F( K$ U' KSNMPv2-MIB::sysContact.0 = STRING: R&D Shenzhen, Huawei Technologies Co., Ltd." Y/ `- x& L" Y7 D: O
SNMPv2-MIB::sysName.0 = STRING: hw-ar1
- l% e' Z) |. h8 w' e9 [# X$ KSNMPv2-MIB::sysLocation.0 = STRING: Shenzhen China
% K. ?7 L6 m8 K# ASNMPv2-MIB::sysServices.0 = INTEGER: 78+ I1 O6 B! R1 G3 v
IF-MIB::ifNumber.0 = INTEGER: 5' N3 _8 t8 H% `* w6 I
IF-MIB::ifIndex.1 = INTEGER: 1
5 g' o$ e2 L1 FIF-MIB::ifIndex.2 = INTEGER: 2
& V7 y3 o! L4 JIF-MIB::ifIndex.3 = INTEGER: 3
" d9 l6 {( @8 X4 n( E+ W$ L) MIF-MIB::ifIndex.4 = INTEGER: 4
3 c3 C, H, J: l+ g  _2 Z4 bIF-MIB::ifIndex.5 = INTEGER: 5
$ S& Q7 Y* Y5 V- xIF-MIB::ifDescr.1 = STRING: InLoopBack0
5 P0 x7 z" c3 S9 b! xIF-MIB::ifDescr.2 = STRING: NULL0" |5 c* }9 X# `% w7 `  o  \
IF-MIB::ifDescr.3 = STRING: GigabitEthernet0/0/0
+ f: l' C5 x, B; }. y7 wIF-MIB::ifDescr.4 = STRING: GigabitEthernet0/0/1
9 [9 D4 ^1 X. ^IF-MIB::ifDescr.5 = STRING: GigabitEthernet0/0/2
1 ^( q- {% {! Q6 H  w7 K  m0 C+ T: f$ I.. ..
% U5 N4 ^. T3 I% L& V( l" i+ H# p. m  S5 N0 K( ]! u
) W# _; k( `' f7 Q6 ~
[root@zbx ~]# snmpwalk  -c  HUAWEI  -v2c  192.168.10.254  ifInOctets  只列出进站流量各子项的指标名称、数据" K- m" W% z8 p
IF-MIB::ifInOctets.1 = Counter32: 0
/ a$ @6 l7 m4 H$ mIF-MIB::ifInOctets.2 = Counter32: 0
. M4 h/ m2 W1 D  }! S) u( B+ N" e. PIF-MIB::ifInOctets.3 = Counter32: 3609914
( x& s; p. h% b8 a; HIF-MIB::ifInOctets.4 = Counter32: 0
( d* R9 \5 x" d5 x) Z7 C0 ?IF-MIB::ifInOctets.5 = Counter32: 0
/ ~  l, x& }5 Y; W2 ]( j) D8 M/ j
1 ~- R* W; M7 {1 C+ p7 P, P2 W: n% C& D3 ^. I2 m; z
[root@zbx ~]# snmpget  -c  HUAWEI  -v2c  192.168.10.254  ifInOctets.3    //获取xx子项的数据结果
" d' j; l5 I% N! J3 K" }IF-MIB::ifInOctets.3 = Counter32: 3897262
3 Y9 w# ~2 h7 i! N9 F( B( t$ g6 O% |6 _
! X3 K, Z' E5 r
比如:
[root@zbx ~]# snmpwalk  -c HUAWEI -v2c 192.168.10.254 sysName //获取设备名称
7 C' }) m- U3 `SNMPv2-MIB::sysName.0 = STRING: hw-ar1
7 y# F. N! i, }! A& l* O
- x: F: z/ a; F. _  r1 w* L2 y0 ^6 c2 `
[root@zbx ~]# snmpget  -c  HUAWEI  -v2c  192.168.10.254  sysDescr.0  //获取设备描述信息7 F' s1 K4 y) V  C& L: s' h
SNMPv2-MIB::sysDescr.0 = STRING: Huawei AR2220 Huawei Versatile Routing Platform Software  VRP (R) software,Version 5.130 (AR2220 V200R003C00) Copyright (C) 2011-2012 Huawei Technologies Co., Ltd; u, I/ c: D* N% J3 {& K$ ?' p

7 U7 O1 A3 c- C3 S# T
0 H0 @, w. L+ S[root@zbx ~]# snmpwalk  -c HUAWEI -v2c 192.168.10.100 sysUpTimeInstance  //获取开机时间信息
+ q% O0 z: u, [: M3 t: I0 v& UDISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (913723) 2:32:17.23
! O6 o( s( \7 t6 |" O' t% e5 [) c8 H; R* [% A. i

' r/ L7 x- v$ S& o) ]7 d6 U
您需要登录后才可以回帖 登录 | 开始注册

本版积分规则

关闭

站长推荐上一条 /4 下一条

如有购买积分卡请联系497906712

QQ|返回首页|Archiver|手机版|小黑屋|易陆发现 点击这里给我发消息

GMT+8, 2022-12-10 11:12 , Processed in 0.050387 second(s), 24 queries .

Powered by LR.LINUX.cloud bbs168x X3.2 Licensed

© 2012-2022 Comsenz Inc.

快速回复 返回顶部 返回列表