Use snmp to monitor Linux hosts
1. Introduction to snmp protocol
SNMP (Simple Network Management Protocol) is also a protocol at the application layer. The default port number is 161. We usually monitor Linux hosts by installing an agent client for monitoring, but some companies also need to monitor network devices and Windows hosts. When you have to use the snmp protocol to monitor the equipment
SNMP has a MIB library. This MIB library stores the oid of each monitoring indicator. The so-called oid is the object id. Each monitoring indicator will have an oid and it is stored in the MIB library to ensure that all the oids of the monitoring indicators are Will not repeat
Take an example: For example, the monitoring item of CPU, a CPU has many monitoring indicators, such as kernel state, user state, etc., these indicators will be stored in the MIB library in order, for example, the user state is .1.1 then the user state is. 1.2 Push backwards in turn, if there are various indicators under the kernel state, then it is .1.1.1, and finally form a form similar to a tree structure
You need to enter the community password when connecting with the snmp protocol. If you do not set a password, the network device will be exposed to the entire network
The idea of using snmp monitoring is:
1. Install the snmp server program on the controlled end, configure the community password, and configure the range of indicators
2. Install the snmp client program on the monitoring side, and connect with the snmp server program to obtain monitoring indicators
snmp MIB library view address: https://blog.csdn.net/weixin_44953658/article/details/110986875
snmp is UDP protocol
2. Use snmp to monitor Linux hosts
2.1. Obtain the percentage OID used by the CPU user system in the MIB library
Visit https://blog.csdn.net/weixin_44953658/article/details/110986875
.1.3.6.1.4.1.2021.11.9.0 User CPU ratio.
1.3.6.1.4.1.2021.11.10.0 System CPU ratio[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-mLygXbYc-1617075696635)(.\zabbix-note picture storage\image-20201210204242690.png)]
2.2. Install the snmp server on the controlled end and configure it
1.安装snmp
[root@192_168_81_230 ~]# yum -y install net-snmp
2.配置snmp
[root@192_168_81_230 ~]# vim /etc/snmp/snmpd.conf
41 com2sec notConfigUser default jiangxl //设置密码口令
55 view systemview included .1 //设置允许的指标范围
3.启动snmp
[root@192_168_81_230 ~]# systemctl start snmpd
[root@192_168_81_230 ~]# systemctl enable snmpd
4.查看端口,注意一定要加上u,因为snmp是udp协议
[root@192_168_81_230 ~]# netstat -lnptu | grep snmp
tcp 0 0 127.0.0.1:199 0.0.0.0:* LISTEN 10746/snmpd
udp 0 0 0.0.0.0:161 0.0.0.0:* 10746/snmpd
2.3. Install the snmp client on the monitoring side and test
1.安装snmp客户端
[root@zabbix-server ~]# yum install net-snmp-utils.x86_64 -y
2.测试获取CPU系统态的使用情况
[root@zabbix-server ~]# snmpwalk -v 2c -c jiangxl 192.168.81.240 .1.3.6.1.4.1.2021.11.10.0
UCD-SNMP-MIB::ssCpuSystem.0 = INTEGER: 0
-v:表示指定版本
-c:指定密码口令
最后面的就是指标oid
3. Create snmp monitoring on the page
3.1. Create a host
Configuration-host-create host-fill in the host name-remove agent program-add snmp interface-fill in the host address
3.2. Link template
Here select the template with snmp
Here choose Template OS Linux SNMPv2 this template, this template is the template of snmp v2
3.3. Configure snmp community password
Click Macro----Inheritance and Host Macro----{$SNMP_COMMUNITY}
{$SNMP_COMMUNITY} => jiangxl
Find the following {$SNMP_COMMUNITY} => jiangxl
Finally click add