当前位置: 首页 > news >正文

使用snmpsim与docker批量生成snmpd模拟服务

镜像资源已上传csdn资源,关键字:snmpsim.image

准备snmpsim环境

dirname=/opt/snmpsimdocker

mkdir -p $dirname

for i in {100..1100}; do

  cat > $dirname/device_$i.snmprec

1.3.6.1.2.1.1.1.0|4|SNMP Simulator Device $i

1.3.6.1.2.1.1.3.0|67|@random@/100:1000000

1.3.6.1.2.1.1.5.0|4|snmp-device-$i

1.3.6.1.2.1.25.2.3.1.6.1|2|@random@/1000:1000000

EOF

done

运行大量模拟容器

# 分批运行, 三位数端口需要拼接10作为端口号

 for i in $(seq 100 999);  do   docker run -d --restart=always --name snmpd-10$i --memory 256m    --cpus 0.2   --cpuset-cpus 0-3    --network=pidsnet -p 0.0.0.0:10$i:161/udp -v /opt/snmpsimdocker/device_$i.snmprec:/usr/local/snmpsim/data/device_$i.snmprec tandrup/snmpsim ; done

#分批运行, 四位数端口直接拼接1作为端口号,不会超过端口数量最大值65535

 for i in $(seq 1000 1100);  do   docker run -d --restart=always --name snmpd-1$i --memory 256m    --cpus 0.2   --cpuset-cpus 0-3    --network=pidsnet -p 0.0.0.0:1$i:161/udp -v /opt/snmpsimdocker/device_$i.snmprec:/usr/local/snmpsim/data/device_$i.snmprec tandrup/snmpsim ; done

# 这里容器限制 cpu 内存没有实际生效, 需要修改 内核 暂时没有修改

# ​找到以 GRUB_CMDLINE_LINUX或 GRUB_CMDLINE_LINUX_DEFAULT开头的行。在这行参数的值中,添加 cgroup_enable=memory swapaccount=1

#备份配置文件​:sudo cp /etc/default/grub /etc/default/grub.backup

# ​备份 GRUB 主配置​:sudo cp /boot/grub/grub.cfg /boot/grub/grub.cfg.backup

# /etc/default/grub GRUB_CMDLINE_LINUX_DEFAULT="quiet splash cgroup_enable=memory swapaccount=1"

#update-grub

# reboot

#重启 snmp相关容器

docker restart $(docker ps --filter "name=snmpd*" -qa)

#删除

#docker rm -f $(docker ps --filter "name=snmpd*" -qa)

提示:snmpsimd镜像的 CMD ["/bin/sh" "-c" "snmpsimd.py --agent-udpv4-endpoint=0.0.0.0:161 --process-user=snmpsim --process-group=nogroup $EXTRA_FLAGS"]

参考资料

获取snmpdsim镜像

请从互联网获取生产 本地镜像,放入服务器

#推荐使用dockerdesktop (win10 非常新的版本才可使用)

# 导出保存镜像为 本地文件,用于:无互联网的服务器上导入

docker save tandrup/snmpsim -o snmpsim.image

服务器上加载镜像

docker load -i snmpsim.image

SNMP服务中核心采集项 OID 参考

调试可以用MIB浏览器,可在gui上分析 snmpd oid等信息的客户端工具: MIB浏览器 https://ireasoning.com/downloadmibbrowserfree.php

下表列出了常用于模拟 Linux 系统 CPU、内存和磁盘信息的核心 OID,它们是构建模拟数据的基础 。

监控指标

OID

说明

​系统运行时间​

.1.3.6.1.2.1.1.3.0

设备从启动到现在的运行时间(单位:百分之一秒)

​CPU 空闲率​

.1.3.6.1.4.1.2021.11.11.0

百分比表示的 CPU 空闲时间

​CPU 用户态时间​

.1.3.6.1.4.1.2021.11.9.0

百分比表示的 CPU 用户态时间

​CPU 系统态时间​

.1.3.6.1.4.1.2021.11.10.0

百分比表示的 CPU 系统态时间

​总内存大小​

.1.3.6.1.4.1.2021.4.5.0

设备的总物理内存大小(单位:KB)

​可用内存​

.1.3.6.1.4.1.2021.4.6.0

设备的可用内存大小(单位:KB)

​磁盘总空间​

.1.3.6.1.4.1.2021.9.1.6.1

指定磁盘分区的总空间(单位:KB)

​磁盘已用空间​

.1.3.6.1.4.1.2021.9.1.8.1

指定磁盘分区的已用空间(单位:KB)

​磁盘使用百分比​

.1.3.6.1.4.1.2021.9.1.9.1

指定磁盘分区的空间使用百分比

​系统负载 (1分钟)​​

.1.3.6.1.4.1.2021.10.1.3.1

系统 1 分钟平均负载

​系统负载 (5分钟)​​

.1.3.6.1.4.1.2021.10.1.3.2

系统 5 分钟平均负载

​系统负载 (15分钟)​​

.1.3.6.1.4.1.2021.10.1.3.3

系统 15 分钟平均负载

以下是一份snmpd.conf的文档

###############################################################################

#

# EXAMPLE.conf:

# An example configuration file for configuring the Net-SNMP agent ('snmpd')

# See the 'snmpd.conf(5)' man page for details

#

# Some entries are deliberately commented out, and will need to be explicitly activated

#

###############################################################################

#

# AGENT BEHAVIOUR

#

# Listen for connections from the local system only

#agentAddress udp:127.0.0.1:161

# Listen for connections on all interfaces (both IPv4 *and* IPv6)

agentAddress udp:161,udp6:[::1]:161

###############################################################################

#

# SNMPv3 AUTHENTICATION

#

# Note that these particular settings don't actually belong here.

# They should be copied to the file /var/lib/snmp/snmpd.conf

# and the passwords changed, before being uncommented in that file *only*.

# Then restart the agent

# createUser authOnlyUser MD5 "remember to change this password"

# createUser authPrivUser SHA "remember to change this one too" DES

# createUser internalUser MD5 "this is only ever used internally, but still change the password"

# If you also change the usernames (which might be sensible),

# then remember to update the other occurances in this example config file to match.

###############################################################################

#

# ACCESS CONTROL

#

# system + hrSystem groups only

view systemonly included .1.3.6.1.2.1.1

view systemonly included .1.3.6.1.2.1.25.1

view systemonly included .1

# Full access from the local host

#rocommunity public localhost

# Default access to basic system info

rocommunity public default -V systemonly

# rocommunity6 is for IPv6

rocommunity6 public default -V systemonly

# Full access from an example network

# Adjust this network address to match your local

# settings, change the community string,

# and check the 'agentAddress' setting above

#rocommunity secret 10.0.0.0/16

# Full read-only access for SNMPv3

rouser authOnlyUser

# Full write access for encrypted requests

# Remember to activate the 'createUser' lines above

#rwuser authPrivUser priv

# It's no longer typically necessary to use the full 'com2sec/group/access' configuration

# r[ow]user and r[ow]community, together with suitable views, should cover most requirements

###############################################################################

#

# SYSTEM INFORMATION

#

# Note that setting these values here, results in the corresponding MIB objects being 'read-only'

# See snmpd.conf(5) for more details

sysLocation Sitting on the Dock of the Bay

sysContact Me

# Application + End-to-End layers

sysServices 72

#

# Process Monitoring

#

# At least one 'mountd' process

proc mountd

# No more than 4 'ntalkd' processes - 0 is OK

proc ntalkd 4

# At least one 'sendmail' process, but no more than 10

proc sendmail 10 1

# Walk the UCD-SNMP-MIB::prTable to see the resulting output

# Note that this table will be empty if there are no "proc" entries in the snmpd.conf file

#

# Disk Monitoring

#

# 10MBs required on root disk, 5% free on /var, 10% free on all other disks

disk / 10000

disk /var 5%

includeAllDisks 10%

# Walk the UCD-SNMP-MIB::dskTable to see the resulting output

# Note that this table will be empty if there are no "disk" entries in the snmpd.conf file

#

# System Load

#

# Unacceptable 1-, 5-, and 15-minute load averages

load 12 10 5

# Walk the UCD-SNMP-MIB::laTable to see the resulting output

# Note that this table *will* be populated, even without a "load" entry in the snmpd.conf file

###############################################################################

#

# ACTIVE MONITORING

#

# send SNMPv1 traps

trapsink localhost public

# send SNMPv2c traps

#trap2sink localhost public

# send SNMPv2c INFORMs

#informsink localhost public

# Note that you typically only want *one* of these three lines

# Uncommenting two (or all three) will result in multiple copies of each notification.

#

# Event MIB - automatically generate alerts

#

# Remember to activate the 'createUser' lines above

iquerySecName internalUser

rouser internalUser

# generate traps on UCD error conditions

defaultMonitors yes

# generate traps on linkUp/Down

linkUpDownNotifications yes

###############################################################################

#

# EXTENDING THE AGENT

#

#

# Arbitrary extension commands

#

extend test1 /bin/echo Hello, world!

extend-sh test2 echo Hello, world! ; echo Hi there ; exit 35

#extend-sh test3 /bin/sh /tmp/shtest

# Note that this last entry requires the script '/tmp/shtest' to be created first,

# containing the same three shell commands, before the line is uncommented

# Walk the NET-SNMP-EXTEND-MIB tables (nsExtendConfigTable, nsExtendOutput1Table

# and nsExtendOutput2Table) to see the resulting output

# Note that the "extend" directive supercedes the previous "exec" and "sh" directives

# However, walking the UCD-SNMP-MIB::extTable should still returns the same output,

# as well as the fuller results in the above tables.

#

# "Pass-through" MIB extension command

#

#pass .1.3.6.1.4.1.8072.2.255 /bin/sh PREFIX/local/passtest

#pass .1.3.6.1.4.1.8072.2.255 /usr/bin/perl PREFIX/local/passtest.pl

# Note that this requires one of the two 'passtest' scripts to be installed first,

# before the appropriate line is uncommented.

# These scripts can be found in the 'local' directory of the source distribution,

# and are not installed automatically.

# Walk the NET-SNMP-PASS-MIB::netSnmpPassExamples subtree to see the resulting output

#

# AgentX Sub-agents

#

# Run as an AgentX master agent

master agentx

# Listen for network connections (from localhost)

# rather than the default named socket /var/agentx/master

#agentXSocket tcp:localhost:705

http://www.dtcms.com/a/490227.html

相关文章:

  • 燕之屋(1497.HK)燕窝肽260万单场售罄,科技重塑传统
  • 【动态规划】数位DP的原理、模板(封装类)
  • 神经网络中的批归一化(BatchNorm)
  • 最新版本组件的docker下载-nacos-Rabbitmq-redis
  • 互素最多:任意五个整数互素的巧妙构造
  • 博客网站大全上海专业网站建设价格
  • Apache换行解析 文件上传漏洞复现:原理详解+环境搭建+渗透实践(CVE-2017-15715 vulhub)
  • 自动伸缩:K8s Cluster Autoscaler,节点池配置技巧?
  • 网站制作的预算网站建设著作权
  • 性能优化之前端与服务端中的 Gzip 压缩全解析
  • 【Day 77】Linux-iptables防火墙
  • GitHub 热榜项目 - 日榜(2025-10-16)
  • 爬虫汇总与实战
  • 哪个网站做网销更好python怎么做网站
  • dede 网站地图 插件添加图标wordpress
  • 对比k8s的service和kube-proxy
  • 理想汽车Java后台开发面试题及参考答案(上)
  • Kotlin 实现社交 App 音视频模块:语音录制、播放、暂停与进度控制全流程封装
  • Lustre/Scade 形式化语义基础 —— 同步Kahn网络 (1996)
  • 内核空间与用户空间解读
  • ELK运维之路(Filebeat第一章-7.17.24)
  • 开源接口管理工具深度横评,swagger vs PostIn哪个更适合你?
  • list的使用和模拟实现
  • 群辉怎么做网站服务器专做投放广告网站
  • 【34】MFC入门到精通——MFC 控件 ComboBox 运行点击控件下拉框 “终止“、“重试“、“忽略“、“引发异常”
  • 论文见解:REACT:在语言模型中协同推理和行动
  • Megatron-DeepSpeed 方案
  • 停止检索!刚刚这本期刊被数据库剔除!
  • Flink-Kafka 数据倾斜问题解决方案
  • html 实现鼠标滑动点亮横轴