记录一次线上实施snmp分析

哈哈 阅读:191 2021-07-13 12:51:41 评论:0

公司要实施一个部级的项目,我们公司的提供的产品要对接下客户的一个平台监控平台,该监控平台使用snmp,我们公司的产品不支持snmp,所以由我负责在现网实施snmp,记录这次现网

一、生成编译规则

1、下载snmp的tar包

 http://www.net-snmp.org/download.html

2、解压

[[email protected] admin]# tar -zxvf net-snmp-5.7.1.tar.gz  

  

drwxr-xr-x 18  1274  1274    4096 Sep 28  2011 net-snmp-5.7.1 
-rw-rw-r--  1 admin admin 6110619 Jul 23 14:37 net-snmp-5.7.1.tar.gz 

  

3、生成编译规则

./configure --prefix=/usr/local/snmp --with-mib-modules='ucd-snmp/diskio ip-mib/ipv4InterfaceTable' 

  

4、点击回车

5、点击回车:1、default version of-snmp-version:

6、点击回车:Systemcontact information(配置该设备的联系人):

7、点击回车:System location (该设备的位置):

8、点击回车:Location to write logfile (日志文件位置): /var/log/snmpd.log

9、点击回车:Location to Write persistent(数据存储目录): /var/net-snmp

10、编译规则生成完成

二、安装

1、编译并安装

make  &&  make install 

  

2、编译安装完成

 

3、snmp安装目录创建配置文件路径

[[email protected] snmp]# mkdir etc 
[[email protected] snmp]# pwd 
/usr/local/snmp 
[[email protected] snmp]# ll 
total 8 
drwxr-xr-x 2 root root 4096 Jul 23 14:57 bin 
drwxr-xr-x 2 root root    6 Jul 23 14:59 etc 
drwxr-xr-x 3 root root   21 Jul 23 14:57 include 
drwxr-xr-x 2 root root 4096 Jul 23 14:57 lib 
drwxr-xr-x 2 root root   34 Jul 23 14:57 sbin 
drwxr-xr-x 4 root root   27 Jul 23 14:57 share 

  

4、在源文件目录下拷贝配置文件到安装的etc目录

[[email protected] snmp]# scp /home/admin/net-snmp-5.7.1/EXAMPLE.conf /usr/local/snmp/etc/snmpd.conf 
You have mail in /var/spool/mail/root 
[[email protected] snmp]# ll 
total 8 
drwxr-xr-x 2 root root 4096 Jul 23 14:57 bin 
drwxr-xr-x 2 root root   23 Jul 23 15:01 etc 
drwxr-xr-x 3 root root   21 Jul 23 14:57 include 
drwxr-xr-x 2 root root 4096 Jul 23 14:57 lib 
drwxr-xr-x 2 root root   34 Jul 23 14:57 sbin 
drwxr-xr-x 4 root root   27 Jul 23 14:57 share 
[[email protected] snmp]# cd etc/ 

  

[[email protected] etc]# ll 
total 8 
-rw-r--r-- 1 root root 6993 Jul 23 15:01 snmpd.conf 

  

5、编辑配置文件

a、配置允许网络访问按照截图中的方式修改

b、选择v2c SNMP协议的版本按照截图中的方式修改

c、设置访问权限按照截图中的方式修改

三、启动和调试

1、启动

[[email protected] etc]# /usr/local/snmp/sbin/snmpd -c /usr/local/snmp/etc/snmpd.conf 

  

2、检查进程和端口

[[email protected] etc]# netstat -an |grep -w 161 
[[email protected] etc]# ps auxf |grep -w snmp 
root     26440  0.0  0.0 112708   980 pts/0    S+   15:10   0:00  |                   \_ grep --color=auto -w snmp 

  

[[email protected] etc]# ps auxf |grep snmp 
root      3327  0.0  0.0 112708   956 pts/0    S+   15:11   0:00  |                   \_ grep --color=auto snmp 
root      1696  0.2  0.0 187880  5164 ?        S    15:11   0:00 /usr/local/snmp/sbin/snmpd -c /usr/local/snmp/etc/snmpd.conf 
[[email protected] etc]# netstat -anu |grep 161 
udp        0      0 0.0.0.0:161             0.0.0.0:*                           
[[email protected] etc]#  

  

3、添加到开机启动项中

 

4、添加防火墙规则

firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 1 -s 10.87.18.101/24 -p udp --dport=161 -j ACCEPT 

  

[[email protected] init.d]# firewall-cmd --reload 

  

5、测试

6、附上oid

CPU Statistics  
Load  
1 minute Load: .1.3.6.1.4.1.2021.10.1.3.1  
5 minute Load: .1.3.6.1.4.1.2021.10.1.3.2  
15 minute Load: .1.3.6.1.4.1.2021.10.1.3.3  
CPU  
percentage of user CPU time: .1.3.6.1.4.1.2021.11.9.0  
raw user cpu time: .1.3.6.1.4.1.2021.11.50.0  
percentages of system CPU time: .1.3.6.1.4.1.2021.11.10.0  
raw system cpu time: .1.3.6.1.4.1.2021.11.52.0  
percentages of idle CPU time: .1.3.6.1.4.1.2021.11.11.0  
raw idle cpu time: .1.3.6.1.4.1.2021.11.53.0  
raw nice cpu time: .1.3.6.1.4.1.2021.11.51.0  
Memory Statistics  
Total Swap Size: .1.3.6.1.4.1.2021.4.3.0  
Available Swap Space: .1.3.6.1.4.1.2021.4.4.0  
Total RAM in machine: .1.3.6.1.4.1.2021.4.5.0  
Total RAM used: .1.3.6.1.4.1.2021.4.6.0  
Total RAM Free: .1.3.6.1.4.1.2021.4.11.0  
Total RAM Shared: .1.3.6.1.4.1.2021.4.13.0  
Total RAM Buffered: .1.3.6.1.4.1.2021.4.14.0  
Total Cached Memory: .1.3.6.1.4.1.2021.4.15.0 Disk Statistics  
The snmpd.conf needs to be edited. Add the following (assuming a machine with a single '/' partition):  
disk / 100000 (or)  
includeAllDisks 10% for all partitions and disks  
The OIDs are as follows  
Path where the disk is mounted: .1.3.6.1.4.1.2021.9.1.2.1  
Path of the device for the partition: .1.3.6.1.4.1.2021.9.1.3.1  
Total size of the disk / partion (kBytes): .1.3.6.1.4.1.2021.9.1.6.1  
Available space on the disk: .1.3.6.1.4.1.2021.9.1.7.1  
Used space on the disk: .1.3.6.1.4.1.2021.9.1.8.1  
Percentage of space used on disk: .1.3.6.1.4.1.2021.9.1.9.1  
Percentage of inodes used on disk: .1.3.6.1.4.1.2021.9.1.10.1  
System Uptime: .1.3.6.1.2.1.1.3.0  
Examples  
These Commands you need to run on the SNMP server  
Get available disk space for / on the target host  
# Snmpget-v 1-c "community" target_name_or_ip .1.3.6.1.4.1.2021.9.1.7.1  
this will return available disk space for the first entry in the 'disk' section of snmpd.conf; replace 1 with n for the nth entry  
Get the 1-minute system load on the target host  
# Snmpget-v 1-c "community" target_name_or_ip .1.3.6.1.4.1.2021.10.1.3.1  
Get the 5-minute system load on the target host  
# Snmpget-v 1-c "community" target_name_or_ip .1.3.6.1.4.1.2021.10.1.3.2  
Get the 15-minute system load on the target host  
# Snmpget-v 1-c "community" target_name_or_ip .1.3.6.1.4.1.2021.10.1.3.3  
Get amount of available swap space on the target host  
# Snmpget-v 1-c "community" target_name_or_ip .1.3.6.1.4.1.2021.4.4. 

  


标签:linux
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

发表评论
搜索
KIKK导航

KIKK导航

排行榜
关注我们

一个IT知识分享的公众号