Commit a29ab47d authored by 吴文龙's avatar 吴文龙

更新版本

parent e62862ee
......@@ -4,9 +4,10 @@ services:
haproxy:
restart: always
container_name: "iot-mqtt-bl"
image: thingsboard/haproxy-certbot:1.3.0
image: 47.110.145.204:8084/buildenv/tb-haproxy:1.6.0
volumes:
- ./haproxy/config:/config
- ./haproxy/data:/usr/local/bin
- ./haproxy/letsencrypt:/etc/letsencrypt
- ./haproxy/certs.d:/usr/local/etc/haproxy/certs.d
ports:
......
global
daemon
maxconn 256
defaults
mode tcp
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend mqtt_frontend
bind *:1883
mode tcp
default_backend mqtt_backend
backend mqtt_backend
mode tcp
balance roundrobin
option tcp-check
tcp-check send-binary 303c01000004000000000000
tcp-check expect binary 200201000004000000000000
tcp-check send-binary 100000016d7174742f04020000000c6d7174742d737461747573
tcp-check expect binary 20020001000c6d7174742d737461747573
server mqtt_server1 192.168.1.101:1883 check inter 5s rise 2 fall 3
server mqtt_server2 192.168.1.102:1883 check inter 5s rise 2 fall 3
server mqtt_server3 192.168.1.103:1883 check inter 5s rise 2 fall 3
lua-load /etc/haproxy/mqtt_health_check.lua
......@@ -46,6 +46,9 @@ listen mqtt-in
timeout server 3h
option tcplog
balance leastconn
option external-check
external-check path "/usr/local/bin:/bin"
external-check command /usr/local/bin/check_mqtt.sh
server tbMqtt1 47.99.83.75:31883 check inter 10s rise 2 fall 3
server tbMqtt2 47.97.197.103:31883 check inter 10s rise 2 fall 3
server tbMqtt3 47.96.103.209:31883 check inter 10s rise 2 fall 3
......
core.register_action("mqtt_health_check", {"tcp-req"}, function(txn)
txn:set_var(txn.TXN_CHECK_STATUS, "L7OK")
txn:set_var(txn.TXN_CHECK_CODE, "200")
txn:set_var(txn.TXN_CHECK_PAYLOAD, "")
if txn.f:has_subscribers() then
local ok, err = txn.f:publish("mqtt_health_check", "PINGREQ")
if not ok then
txn:set_var(txn.TXN_CHECK_STATUS, "L7FAIL")
txn:set_var(txn.TXN_CHECK_CODE, "503")
end
end
end)
core.register_subscriber("mqtt_health_check", function(applet)
applet:set_status(200)
applet:add_header("Content-Type", "text/plain")
applet:start_response()
applet:send("PONG\n")
end)
#!/bin/bash
echo $@ >> /tmp/all_arguments.txt
ip_adr=$(echo $@|awk '{print $3}')
if mosquitto_pub -h $ip_adr -p 31883 -u 123456 -t v1/devices/me/attributes -f test-mqtt.json -q 1 -d; then
exit 0
else
exit 1
fi
{"check-mqtt": "ok"}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment