一、修改麒麟配置
因为中标麒麟yum可能找不到snmp的安装包,先按以下步骤修改配置。
二、修改 /etc/os-release(没有就新建该文件)
NAME="CentOS Linux"
VERSION="7 (AltArch)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (AltArch)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7:server"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
三、修改yum配置文件/etc/yum.conf
配置项改为:distroverpkg=centos-release
四、修改yum源 /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever- Base
baseurl=https://mirrors.aliyun.com/centos-altarch/7/os/$basearch/
gpgcheck=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#releasedupdates
[updates]
name=CentOS-$releasever- Updates
baseurl=https://mirrors.aliyun.com/centos-altarch/7/updates/$basearch/
gpgcheck=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additionalpackages that may be useful
[extras]
name=CentOS-$releasever- Extras
baseurl=https://mirrors.aliyun.com/centos-altarch/7/extras/$basearch/
gpgcheck=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
enabled=1
#additionalpackages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever- Plus
baseurl=https://mirrors.aliyun.com/centos-altarch/7/centosplus/$basearch/
gpgcheck=0
enabled=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
执行 yum makecache
五、安装snmp
yum install -y net-snmp net-snmp-utils
可以理解为net-snmp是服务端,net-snmp-utils是客户端工具集;如果机器上只需要搭建服务那可以只安装net-snmp。
由于依赖关系,其实最终会安装net-snmp net-snmp-utils net-snmp-agent net-snmp-libs perl-Data-Dumper等几个包。
六、启动snmp服务
service snmpd start
service snmpd restart
service snmpd stop
加入随机自启动
chkconfig snmpd on
七、使用snmp
snmpwalk -v 2c -c public localhost .1.3.6.1.2.1.1
最后那个.x.x.x的叫OID,一个OID对应一种设备(比如网卡、磁盘等,在不同机器上同种设备的OID是一样的)
现在可以获取到一些基本的信息了,但是想获取更多的信息,还需要进一步配置 snmpd.conf
八、配置 /etc/snmpd/snmpd.conf
# First, map the community name "public" into a "security name"
# sec.name source community
com2sec notConfigUser default public
####
# Second, map the security name into a group name:
# groupName securityModel securityName
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser
####
# Third, create a view for us to let the group have rights to:
# Make at least snmpwalk -v 1 localhost -c public system fast again.
# name incl/excl subtree mask(optional)
#view systemview included .1.3.6.1.2.1.1
#view systemview included .1.3.6.1.2.1.25.1.1
view all included .1
####
# Finally, grant the group read-only access to the systemview view.
# group context sec.model sec.level prefix read write notif
#access notConfigGroup "" any noauth exact systemview none none
access notConfigGroup "" any noauth exact all all all
..........
###############################################################################
# Process checks.
proc mountd
proc ntalkd 4
proc sendmail 10 1
# # % snmpwalk -v 1 localhost -c public .1.3.6.1.4.1.2021.2
enterprises.ucdavis.procTable.prEntry.prIndex.1 = 1
enterprises.ucdavis.procTable.prEntry.prIndex.2 = 2
enterprises.ucdavis.procTable.prEntry.prIndex.3 = 3
enterprises.ucdavis.procTable.prEntry.prNames.1 = "mountd"
enterprises.ucdavis.procTable.prEntry.prNames.2 = "ntalkd"
enterprises.ucdavis.procTable.prEntry.prNames.3 = "sendmail"
enterprises.ucdavis.procTable.prEntry.prMin.1 = 0
enterprises.ucdavis.procTable.prEntry.prMin.2 = 0
enterprises.ucdavis.procTable.prEntry.prMin.3 = 1
enterprises.ucdavis.procTable.prEntry.prMax.1 = 0
enterprises.ucdavis.procTable.prEntry.prMax.2 = 4
enterprises.ucdavis.procTable.prEntry.prMax.3 = 10
enterprises.ucdavis.procTable.prEntry.prCount.1 = 0
enterprises.ucdavis.procTable.prEntry.prCount.2 = 0
enterprises.ucdavis.procTable.prEntry.prCount.3 = 1
enterprises.ucdavis.procTable.prEntry.prErrorFlag.1 = 1
enterprises.ucdavis.procTable.prEntry.prErrorFlag.2 = 0
enterprises.ucdavis.procTable.prEntry.prErrorFlag.3 = 0
enterprises.ucdavis.procTable.prEntry.prErrMessage.1 = "No mountd process running."enterprises.ucdavis.procTable.prEntry.prErrMessage.2 = ""
enterprises.ucdavis.procTable.prEntry.prErrMessage.3 = ""
enterprises.ucdavis.procTable.prEntry.prErrFix.1 = 0
enterprises.ucdavis.procTable.prEntry.prErrFix.2 = 0
enterprises.ucdavis.procTable.prEntry.prErrFix.3 = 0
...........
# disk checks
disk / 10000
load [1MAX=12.0] [5MAX=12.0] [15MAX=12.0]
load 12 14 14
# % snmpwalk -v 1 localhost -c public .1.3.6.1.4.1.2021.10
enterprises.ucdavis.loadTable.laEntry.loadaveIndex.1 = 1
enterprises.ucdavis.loadTable.laEntry.loadaveIndex.2 = 2
enterprises.ucdavis.loadTable.laEntry.loadaveIndex.3 = 3
enterprises.ucdavis.loadTable.laEntry.loadaveNames.1 = "Load-1"
enterprises.ucdavis.loadTable.laEntry.loadaveNames.2 = "Load-5"
enterprises.ucdavis.loadTable.laEntry.loadaveNames.3 = "Load-15"
enterprises.ucdavis.loadTable.laEntry.loadaveLoad.1 = "0.49" Hex: 30 2E 34 39
enterprises.ucdavis.loadTable.laEntry.loadaveLoad.2 = "0.31" Hex: 30 2E 33 31
enterprises.ucdavis.loadTable.laEntry.loadaveLoad.3 = "0.26" Hex: 30 2E 32 36
enterprises.ucdavis.loadTable.laEntry.loadaveConfig.1 = "12.00"
enterprises.ucdavis.loadTable.laEntry.loadaveConfig.2 = "14.00"
enterprises.ucdavis.loadTable.laEntry.loadaveConfig.3 = "14.00"
enterprises.ucdavis.loadTable.laEntry.loadaveErrorFlag.1 = 0
enterprises.ucdavis.loadTable.laEntry.loadaveErrorFlag.2 = 0
enterprises.ucdavis.loadTable.laEntry.loadaveErrorFlag.3 = 0
enterprises.ucdavis.loadTable.laEntry.loadaveErrMessage.1 = ""
enterprises.ucdavis.loadTable.laEntry.loadaveErrMessage.2 = ""
enterprises.ucdavis.loadTable.laEntry.loadaveErrMessage.3 = ""