background:
1. There is no dedicated temperature monitoring equipment in the computer room of the company. In the past, the CPU or motherboard temperature of the server was obtained through the snmp function, and the approximate temperature of the computer room (the difference between the thermometer value and the server value) was calculated according to the deviation value. Run high-load tasks, resulting in extremely inaccurate calculated ambient temperature
2. Although there are complete sets of temperature alarm products on the Internet, they do not meet the company's requirements in the following aspects:
2-1: Most of the existing products are alarmed by email or mobile phone voice/SMS, WeChat, and our company needs to connect to the internal platform for unified alarm
2-2: Most of the equipment on the Internet is priced at 200~400 yuan, and those that support cloud functions need to renew the platform fee (the purchase and reimbursement approval are required every year, and the internal process is very troublesome)
Implementation process:
1. The first thing is to buy hardware equipment. The gateway + temperature sensor will cost about 200~220 yuan, as shown in the figure below:
The picture on the left is the modbus tcp gateway, which realizes 485 or modbus rtu protocol to modbus tcp protocol
The picture on the right is a temperature and humidity probe, which supports modbus rtu protocol , connects to the gateway through 485, and then converts to tcp protocol
2. System and software:
· Install Zabbix-Server version 5.2 and above in Linux system (modbus protocol is supported from 5.2)
· zabbix-agent2 (currently only zabbix-agent2 version supports modbus, and zabbix-agent support may be added later)
3. Straighten out the logic here, otherwise you may have errors or questions during configuration:
Although Zabbix-Server can directly monitor the monitored host such as ping, snmp, service.perf, port.perf, etc., the acquisition of modbus data is realized through zabbix-agent2, which means that agent2 obtains the controlled The modbus data of the host, and then send the result back to Zabbix-Server. If the modbus device itself or the network where it is located has a firewall policy, it is necessary to allow access to the agent2 host (the server and agent of Zabbix can be installed on the same linux system)
4. Deploy Zabbix-Server, because the official website has a very detailed tutorial, so I won’t describe it here. Here is a sentence: the database installed in the official website command is not complete, you need to install mariadb manually
· Official website link: official website installation tutorial
5. Install zabbix-agent2. Let me explain here: modbus needs the support of zabbix-agent2, and we use the command yum install zabbix-agent to install the v1 version by default, and Zabbix-Server comes with the v1 version of the agent
· First deactivate or uninstall the old version of agent (if it exists), take centos7 as an example, you can execute systemctl stop zabbix-agent; yum autoremove zabbix-agent to uninstall after deactivation
· Because zabbix-agent2 is partially written in go language, it depends on the go environment. Here we deploy it through a one-click installation script (based on Centos installation, if it is debian, you need to install sudo in advance):
Reference link: One-click installation of go environment
git clone https://gitee.com/xuthus5/golang-install-shell.git (if an error is reported, git needs to be installed)
cd golang-install-shell
chmod +x install.sh
./install.sh
After the following installation interface appears, select 0 to install the golang environment, and then install according to the default parameters :
----------------------------------
0) 安装golang环境
1) 安装gopm跨墙
2) 安装web框架
3) 安装包
4) 退出
----------------------------------
输入操作编号:0
----------------------------------
选择安装版本:
1) 1.11
2) 1.10.4
3) 1.9.7
4) 1.8.7
----------------------------------
输入安装版本编号(默认1):
~~~~~~~~~~~~~~~~~~~~~~省略很多软件安装的信息~~~~~~~~~~~~~~~~~~~~~~~
输入程序安装目录GOROOT(默认 /usr/local):
输入GOPATH目录(默认 /root/go):
After the installation is complete, select 4 to exit
go version go1.11 linux/amd64
环境变量配置成功!请执行 source /root/.bashrc 确保配置生效
----------------------------------
0) 安装golang环境
1) 安装gopm跨墙
2) 安装web框架
3) 安装包
4) 退出
----------------------------------
输入操作编号:4
· Install zabbix-agent2:
# Add official website source
rpm -Uvh https://repo.zabbix.com/zabbix/5.4/rhel/7/x86_64/zabbix-release-5.4-1.el7.noarch.rpm# Clear yum cache
yum clean all# Install agent2, the program will run automatically after installation, and automatically configure the boot self-start function
yum install zabbix-agent2
Edit the configuration file after the installation is successful :
# Edit the configuration file
vi /etc/zabbix/zabbix_agent2.conf# Modify the following items according to the actual environment
Hostname=
Server=
ServerActive=# Restart agent2 after configuration is complete
systemctl restart zabbix-agent2
Add a host with zabbix-agent2 installed on the Zabbix-Server server, and add modbus monitoring items
· Here is the detailed introduction and access link of the official website for modbus monitoring items: official website introduction
Parameter | Description | Defaults | Example |
---|---|---|---|
endpoint | Protocol and address of the endpoint, defined as protocol://connection_string Possible protocol values: rtu, ascii (Agent 2 only), tcp Connection string format: with tcp - address:port with serial line: rtu, ascii - port_name:speed:params where 'speed' - 1200, 9600 etc 'params' - data bits (5,6,7 or 8), parity (n,e or o for none/even/odd), stop bits (1 or 2) |
protocol: none rtu/ascii protocol: port_name: none speed: 115200 params: 8n1 tcp protocol: address: none port: 502 |
tcp://192.168.6.1:511 tcp://192.168.6.2 tcp://[::1]:511 tcp://::1 tcp://localhost:511 tcp://localhost rtu://COM1:9600:8n ascii://COM2:1200:7o2 rtu://ttyS0:9600 ascii://ttyS1 |
slave id | Modbus address of the device it is intended for (1 to 247), see MODBUS Messaging Implementation Guide (page 23) tcp device (not GW) will ignore the field |
serial: 1 tcp: 255 (0xFF) |
2 |
function | Empty or value of a supported function: 1 - Read Coil, 2 - Read Discrete Input, 3 - Read Holding Registers, 4 - Read Input Registers |
empty | 3 |
address | Address of the first registry, coil or input. If 'function' is empty, then 'address' should be in range for: Coil - 00001 - 09999 Discrete input - 10001 - 19999 Input register - 30001 - 39999 Holding register - 40001 - 49999 If 'function' is not empty, the 'address' field will be from 0 till 65535 and used without modification (PDU) |
empty function: 00001 non-empty function: 0 |
9999 |
count | Count of sequenced 'type' which will be read from device, where: for Coil or Discrete input the 'type' = 1 bit for other cases: (count*type)/2 = real count of registers for reading If 'offset' is not 0, the value will be added to 'real count' Acceptable range for 'real count' is 1:65535 |
1 | 2 |
type | Data type: for Read Coil and Read Discrete Input - bit for Read Holding Registers and Read Input Registers: int8 - 8bit uint8 - 8bit (unsigned) int16 - 16bit uint16 - 16bit (unsigned) int32 - 32bit uint32 - 32bit (unsigned) float - 32bit uint64 - 64bit (unsigned) double - 64bit |
bit uint16 |
uint64 |
endianness | Endianness type: be - Big Endian le - Little Endian mbe - Mid-Big Endian mle - Mid-Little Endian Limitations: for 1 bit - be for 8 bits - be,le for 16 bits - be,le |
be | le |
offset | Number of registers, starting from 'address', the result of which will be discarded. The size of each register is 16bit (needed to support equipment that does not support random read access). |
0 | 4 |
· 这是根据实际环境修改后的参照表:
说明 | 监控项 |
官方给出的监控项 | modbus.get[endpoint,<slaveid>,<function>,<address>,<count>,<type>,<endianness>,<offset>] |
对上述的解释 | modbus.get[通讯协议及地址,设备地址,功能码,寄存器地址,读取个数,数据类型,字节序,抵消] 备注:最后的字节序、抵消没弄明白是啥意思 |
根据实际环境修改 | modbus.get[tcp://192.168.1.202:502,1,3,512,1,int16,,] Use tcp port 502 to access the 192.168.1.202 gateway 1 indicates that the device address is 1 3 represents the function code, which is to read the holding register 512 is the register address in decimal, which means 02 00 in hexadecimal 1 is the number of reads · int16 indicates the data type returned by the gateway · The <byte order> and <offset> at the end don’t know what they do, just leave it blank Remarks: The above parameters need to use decimal |
The temperature sensor I used gives 10 times the actual value, so it should be divided by 10 in the zabbix process (that is, multiplied by 0.1 )
· After setting the monitoring items, the agent will have to wait for about 1 minute before using the new monitoring items. If you are in a hurry, you can manually execute systemctl restart zabbix-agent2 to force agent2 to restart and obtain new monitoring items immediately:
This is the temperature value obtained:
During the debugging process, if the modbus gateway does not respond, zabbix reports a gateway error, etc., you can download the debugging tool, use the machine as a gateway server, and then let zabbix-agent2 access the machine, and analyze where it appears according to the data in the received information mistake:
Tool download address: debugging assistant