インストール手順
いきなり、dnfリポジトリサーバエラー
以下のサイトを見てエラー回避
sed -i 's/mirrorlist=/#mirrorlist=/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
社内の縛りがあるため、パッケージを一回ダウンロードする
今回インストールするパッケージは「net-snmp」「net-snmp-utils」
mkdir /tmp/net-snmp
mkdir net-snmp-utils
dnf install --downloadonly --destdir /tmp/net-snmp net-snmp
dnf localinstall net-snmp-5.8-30.el8.x86_64.rpm
systemctl enable snmpd.service --now
dnf install --downloadonly --destdir /tmp/net-snmp-utils/ net-snmp-utils
dnf localinstall
dnf localinstall net-snmp-utils-5.8-30.el8.x86_64.rpm
/etc/snmp/snmptrapd.confの編集
以下の1行を追加します。
いったんコミュニティ名を「public」に設定する。
[root@parent ~]# cat /etc/snmp/snmptrapd.conf
authCommunity log,execute,net public
/etc/snmp/snmptrapd.confの編集
-pはPID指定
-M DIR[:...] look in given list of directories for MIBs
-m MIB[:...] load given list of MIBs (ALL loads everything)
[root@parent ~]# cat /etc/sysconfig/snmptrapd
# snmptrapd command line options
# '-f' is implicitly added by snmptrapd systemd unit file
# OPTIONS="-Lsd"
OPTIONS="-Lsd -p /var/run/snmptrapd.pid -M /usr/share/snmp/mibs:/usr/share/snmp/vmw -m all"
snmptrapd.serviceの編集
念のため、「#Environment=OPTIONS="-Lsd"」をコメントアウトしておく
EnvironmentFile=-/etc/sysconfig/snmptrapd側に設定しているため
まぁどっちでもいいような気がする
[root@parent ~]# cat /etc/systemd/system/multi-user.target.wants/snmptrapd.service
[Unit]
Description=Simple Network Management Protocol (SNMP) Trap Daemon.
After=syslog.target network-online.target
[Service]
Type=notify
#Environment=OPTIONS="-Lsd"
EnvironmentFile=-/etc/sysconfig/snmptrapd
ExecStart=/usr/sbin/snmptrapd $OPTIONS -f
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
[root@parent ~]#
mibファイルの配置
※どこでもいいですよ。 ※今回こうしただけです。/usr/share/snmp/mibs:/usr/share/snmp/
配置場所は、以下のファイルに記載
/etc/snmp/snmptrapd.conf
その他
ログの出力先を変更したい場合
ESXiでsnmptrap設定&テスト方法
BIG-IPでのsnmptrapテスト方法
なかなか納得できなかった
Lsdのなぞ
Lは「LOGOPTS」
sは「 s facility: log to syslog (via the specified facility)」
dはsyslogなのかな
[root@parent ~]# snmptrap
No hostname specified.
USAGE: snmptrap [OPTIONS] AGENT TRAP-PARAMETERS
Version: 5.8
Web: http://www.net-snmp.org/
Email: net-snmp-coders@lists.sourceforge.net
OPTIONS:
-h, --help display this help message
-H display configuration file directives understood
-v 1|2c|3 specifies SNMP version to use
-V, --version display package version number
SNMP Version 1 or 2c specific
-c COMMUNITY set the community string
SNMP Version 3 specific
-a PROTOCOL set authentication protocol (MD5|SHA|SHA-224|SHA-256|SHA-384|SHA-512)
-A PASSPHRASE set authentication protocol pass phrase
-e ENGINE-ID set security engine ID (e.g. 800000020109840301)
-E ENGINE-ID set context engine ID (e.g. 800000020109840301)
-l LEVEL set security level (noAuthNoPriv|authNoPriv|authPriv)
-n CONTEXT set context name (e.g. bridge1)
-u USER-NAME set security name (e.g. bert)
-x PROTOCOL set privacy protocol (DES|AES|AES-192|AES-256)
-X PASSPHRASE set privacy protocol pass phrase
-Z BOOTS,TIME set destination engine boots/time
General communication options
-r RETRIES set the number of retries
-t TIMEOUT set the request timeout (in seconds)
Debugging
-d dump input/output packets in hexadecimal
-D[TOKEN[,...]] turn on debugging output for the specified TOKENs
(ALL gives extremely verbose debugging output)
General options
-m MIB[:...] load given list of MIBs (ALL loads everything)
-M DIR[:...] look in given list of directories for MIBs
(default: /root/.snmp/mibs:/usr/share/snmp/mibs)
-P MIBOPTS Toggle various defaults controlling MIB parsing:
u: allow the use of underlines in MIB symbols
c: disallow the use of "--" to terminate comments
d: save the DESCRIPTIONs of the MIB objects
e: disable errors when MIB symbols conflict
w: enable warnings when MIB symbols conflict
W: enable detailed warnings when MIB symbols conflict
R: replace MIB symbols from latest module
-O OUTOPTS Toggle various defaults controlling output display:
0: print leading 0 for single-digit hex characters
a: print all strings in ascii format
b: do not break OID indexes down
e: print enums numerically
E: escape quotes in string indices
f: print full OIDs on output
n: print OIDs numerically
p PRECISION: display floating point values with specified PRECISION (printf format string)
q: quick print for easier parsing
Q: quick print with equal-signs
s: print only last symbolic element of OID
S: print MIB module-id plus last element
t: print timeticks unparsed as numeric integers
T: print human-readable text along with hex strings
u: print OIDs using UCD-style prefix suppression
U: don't print units
v: print values only (not OID = value)
x: print all strings in hex format
X: extended index format
-I INOPTS Toggle various defaults controlling input parsing:
b: do best/regex matching to find a MIB node
h: don't apply DISPLAY-HINTs
r: do not check values for range/type legality
R: do random access to OID labels
u: top-level OIDs must have '.' prefix (UCD-style)
s SUFFIX: Append all textual OIDs with SUFFIX before parsing
S PREFIX: Prepend all textual OIDs with PREFIX before parsing
-L LOGOPTS Toggle various defaults controlling logging:
e: log to standard error
o: log to standard output
n: don't log at all
f file: log to the specified file
s facility: log to syslog (via the specified facility)
(variants)
[EON] pri: log to standard error, output or /dev/null for level 'pri' and above
[EON] p1-p2: log to standard error, output or /dev/null for levels 'p1' to 'p2'
[FS] pri token: log to file/syslog for level 'pri' and above
[FS] p1-p2 token: log to file/syslog for levels 'p1' to 'p2'
-C APPOPTS Set various application specific behaviour:
i: send an INFORM instead of a TRAP
-v 1 TRAP-PARAMETERS:
enterprise-oid agent trap-type specific-type uptime [OID TYPE VALUE]...
or
-v 2 TRAP-PARAMETERS:
uptime trapoid [OID TYPE VALUE] ...
[root@parent ~]#