Fork me on GitHub

Net-SNMP ARM部署

交叉编译
  1. net-snmp交叉编译,生成snmpd
  2. 交叉编译企业私有节点动态库 libbmserv.so
简单版配置文件snmpd.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
###########################################################################
# snmpd.conf
###########################################################################
dlmod bmserv /usr/lib/libbmserv.so

#v1/v2c
rocommunity rrrrr
rwcommunity wwww

#v1 trap
trapsink 10.30.33.2 rrrrr

#v2c trap
trap2sink 10.30.33.2 rrrrr

#v2c inform
informsink 10.30.33.2 rrrrr

#v3
engineIDType 3

rouser rouser priv
createUser rouser MD5 11111111 DES 22222222

rwuser rwuser priv
createUser rwuser MD5 33333333 DES 44444444

# v3 trap
trapsess -v 3 -u rouser -a MD5 -A 11111111 -x DES -X 22222222 -l priv 192.168.1.111

engineType. 1|2|3 : SNMP v3的安全配置,engine id的产生依赖于此选项自动生成;

配置了该选项,就不需要在trapsess选项中通过-e参数来手动指定engine id,否则就需要.

specifies that the engineID should be built from the IPv4 address (1), IPv6 address (2) or MAC address (3). Note that changing the IP address (or switching the network interface card) may cause problems.

ARM部署

将snmpd,libbmserv.so,snmpd.conf及相关的net-snmp库文件打包,然后放到arm开发环境。

snmpd一般放在/bin目录下,snmpd.conf一般放在/etc/snmp/config目录下(没有的话,可自己建立相应的目录)

libbmserv.so及net-snmp的动态库文件都可以放在/usr/local/lib下,私有mib文件及公共mib文件都放在/usr/share/mibs下,通过MIBS环境变量指定路径

1
$export MIBS=/home/lwang/work/chengw/github/net-snmp-x86/MIB/Bitmain.mib
手动启动
1
$snmpd -f -c /etc/snmp/config/snmpd.conf

全部可选参数如下:

OPTIONS

  • -a

    Log the source addresses of incoming requests.

  • -A

    Append to the log file rather than truncating it.

    默认每次重新启动snmpd,snmpd.log会被清理掉以便重新记录日志,之前旧的日志会被丢弃; 添加-A选项后,旧日志被保留,新的日志追加在旧的日志尾部

  • -c FILE

    Read FILE as a configuration file (or a comma-separated list of configuration files). Note that the loaded file will only understand snmpd.conf tokens, unless the configuration type is specified in the file as described in the snmp_config man page under SWITCHING CONFIGURATION TYPES IN MID-FILE.

  • -C

    Do not read any configuration files except the ones optionally specified by the -c option. Note that this behaviour also covers the persistent configuration files. This may result in dynamically-assigned values being reset following an agent restart, unless the relevant persistent config files are explicitly loaded using the -c option.

  • -d

    Dump (in hexadecimal) the sent and received SNMP packets.

  • -D[TOKEN[,…]]

    Turn on debugging output for the given TOKEN(s). Without any tokens specified, it defaults to printing all the tokens (which is equivalent to the keyword “ALL”). You might want to tryALL for extremely verbose output. Note: You can not put a space between the -D flag and the listed TOKENs.

  • -f

    Do not fork() from the calling shell.

  • -g GID

    Change to the numerical group ID GID after opening listening sockets.

  • -h, –help

    Display a brief usage message and then exit.

  • -H

    Display a list of configuration file directives understood by the agent and then exit.

  • -I [-]INITLIST

    Specifies which modules should (or should not) be initialized when the agent starts up. If the comma-separated INITLIST is preceded with a ‘-‘, it is the list of modules that should notbe started. Otherwise this is the list of the only modules that should be started.To get a list of compiled modules, run the agent with the arguments -Dmib_init -H (assuming debugging support has been compiled in).

  • -L[efos]

    Specify where logging output should be directed (standard error or output, to a file or via syslog). See LOGGING OPTIONS in snmpcmd(5) for details.

  • -m MIBLIST

    Specifies a colon separated list of MIB modules to load for this application. This overrides the environment variable MIBS. See snmpcmd(1) for details.

  • -M DIRLIST

    Specifies a colon separated list of directories to search for MIBs. This overrides the environment variable MIBDIRS. See snmpcmd(1) for details.

  • -n NAME

    Set an alternative application name (which will affect the configuration files loaded). By default this will be snmpd, regardless of the name of the actual binary.

  • -p FILE

    Save the process ID of the daemon in FILE.

  • -q

    Print simpler output for easier automated parsing.

  • -r

    Do not require root access to run the daemon. Specifically, do not exit if files only accessible to root (such as /dev/kmem etc.) cannot be opened.

  • -u UID

    Change to the user ID UID (which can be given in numerical or textual form) after opening listening sockets.

  • -U

    Instructs the agent to not remove its pid file (see the -p option) on shutdown. Overrides the leave_pidfile token in the snmpd.conf file, see snmpd.conf(5).

  • -v, –version

    Print version information for the agent and then exit.

  • -V

    Symbolically dump SNMP transactions.

  • -x ADDRESS

    Listens for AgentX connections on the specified address rather than the default “/var/agentx/master”. The address can either be a Unix domain socket path, or the address of a network interface. The format is the same as the format of listening addresses described below.

  • -X

    Run as an AgentX subagent rather than as an SNMP master agent.

  • name=value

    Allows to specify any token (“name”) supported in the snmpd.conf file and sets its value to “value”. Overrides the corresponding token in the snmpd.conf file. See snmpd.conf(5) for the full list of tokens.

SNMP服务自启动

利用debian的systemd机制,编写snmpd.service文件(xxx.service是snmp依赖的服务,根据实际情况修改)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[Unit]
Description=Simple Network Management Protocol (SNMP) Daemon
After=syslog.target network.target xxx.service
Requires=xxx.service

[Service]
Environment=LD_LIBRARY_PATH=/usr/lib
Environment=MIBDIRS=/usr/share/snmp/mibs
Type=simple
PIDFile=/var/run/snmpd.pid
ExecStart=/bin/snmpd -f -c /etc/snmp/config/snmpd.conf -p /var/run/snmpd.pid
Restart=on-failure
RestartSec=3

[Install]
WantedBy=multi-user.target

执行enable命令

1
$systemctl enable snmpd

系统下电重启,则SNMP服务会自动重新启动

其他控制操作

1.启动

1
$systemctl start snmpd

2.停止

1
$systemctl stop snmpd

3.重启

1
$systemctl restart snmpd

4.查询

1
$systemctl status snmpd
您的鼓励是我持之以恒的动力