Commit 7201ca24 authored by 吴文龙's avatar 吴文龙

up 定时切换配置文件

parent 2c3ca21c
# iot-mqtt-bl # iot-mqtt-bl
mqtt负载均衡 mqtt负载均衡
\ No newline at end of file
## 定时切换配置文件执行,防止IP封锁
```shell
crontab -e
0 1 * * 1 /path/to/rotate_haproxy_config.sh
```
\ No newline at end of file
haproxy_config1.cfg
\ No newline at end of file
#HA Proxy Config
global
ulimit-n 500000
maxconn 99999
maxpipes 99999
tune.maxaccept 500
external-check
log 127.0.0.1 local0
log 127.0.0.1 local1 debug
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
ssl-default-bind-options no-sslv3
defaults
log global
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
timeout tunnel 1h # timeout to use with WebSocket and CONNECT
default-server init-addr none
#enable resolving throught docker dns and avoid crashing if service is down while proxy is starting
resolvers docker_resolver
nameserver dns 127.0.0.11:53
listen stats
bind *:9999
stats enable
stats hide-version
stats uri /stats
stats auth admin:admin@123
listen mqtt-in
bind *:${MQTT_PORT}
mode tcp
option clitcpka # For TCP keep-alive
option tcplog
timeout client 3h
timeout server 3h
balance source # 固定服务
option redispatch # 服务出现故障时自动分配
option external-check
option log-health-checks
external-check path "/usr/bin:/bin:/usr/local/bin"
external-check command /usr/local/bin/check_mqtt.sh
server tbMqtt1 47.99.83.75:31883 check inter 120s rise 1 fall 1
server tbMqtt2 47.97.197.103:31883 check inter 120s rise 1 fall 1
server tbMqtt3 47.96.103.209:31883 check inter 120s rise 1 fall 1
#server tbMqtt4 121.43.228.88:31883 check inter 120s rise 1 fall 1
server tbMqtt5 121.43.169.33:31883 check inter 120s rise 1 fall 1
#server tbMqtt6 120.55.38.205:31883 check inter 120s rise 1 fall 1
server tbMqtt7 116.62.229.50:31883 check inter 120s rise 1 fall 1
#server tbMqtt8 121.196.10.235:31883 check inter 120s rise 1 fall 1
#server tbMqtt9 47.114.33.137:31883 check inter 120s rise 1 fall 1
#server tbMqtt10 47.97.181.210:31883 check inter 120s rise 1 fall 1
#HA Proxy Config
global
ulimit-n 500000
maxconn 99999
maxpipes 99999
tune.maxaccept 500
external-check
log 127.0.0.1 local0
log 127.0.0.1 local1 debug
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
ssl-default-bind-options no-sslv3
defaults
log global
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
timeout tunnel 1h # timeout to use with WebSocket and CONNECT
default-server init-addr none
#enable resolving throught docker dns and avoid crashing if service is down while proxy is starting
resolvers docker_resolver
nameserver dns 127.0.0.11:53
listen stats
bind *:9999
stats enable
stats hide-version
stats uri /stats
stats auth admin:admin@123
listen mqtt-in
bind *:${MQTT_PORT}
mode tcp
option clitcpka # For TCP keep-alive
option tcplog
timeout client 3h
timeout server 3h
balance source # 固定服务
option redispatch # 服务出现故障时自动分配
option external-check
option log-health-checks
external-check path "/usr/bin:/bin:/usr/local/bin"
external-check command /usr/local/bin/check_mqtt.sh
#server tbMqtt1 47.99.83.75:31883 check inter 120s rise 1 fall 1
#server tbMqtt2 47.97.197.103:31883 check inter 120s rise 1 fall 1
#server tbMqtt3 47.96.103.209:31883 check inter 120s rise 1 fall 1
server tbMqtt4 121.43.228.88:31883 check inter 120s rise 1 fall 1
#server tbMqtt5 121.43.169.33:31883 check inter 120s rise 1 fall 1
server tbMqtt6 120.55.38.205:31883 check inter 120s rise 1 fall 1
#server tbMqtt7 116.62.229.50:31883 check inter 120s rise 1 fall 1
server tbMqtt8 121.196.10.235:31883 check inter 120s rise 1 fall 1
server tbMqtt9 47.114.33.137:31883 check inter 120s rise 1 fall 1
server tbMqtt10 47.97.181.210:31883 check inter 120s rise 1 fall 1
#!/bin/bash
CURRENT_CONFIG=$(cat haproxy/config/current_config.txt)
if [ "$CURRENT_CONFIG" == "haproxy_config1.cfg" ]; then
cp haproxy/config/haproxy_config2.cfg haproxy/config/haproxy.cfg
echo "haproxy_config2.cfg" > haproxy/config/current_config.txt
else
cp haproxy/config/haproxy_config1.cfg haproxy/config/haproxy.cfg
echo "haproxy_config1.cfg" > haproxy/config/current_config.txt
fi
docker-compose restart haproxy
echo "HAProxy配置文件已切换为: $(cat haproxy/config/current_config.txt)"
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