项目中使用了负载均衡,通过haproxy搭建的负载,在请求分发过后,emqx获取的IP为负载机器的IP
要求:获取请求的原始IP
如下配置中主要通过send-proxy向后传递真实IP,一般获取IP主要是tcp和ssl
listen emqx_mqtt_tcp
bind *:1993
mode tcp
maxconn 1000000
option clitcpka
timeout client 2m
timeout server 2m
option tcplog
balance leastconn
server node1 node3.iotplatform.com:1883 send-proxy check
server node2 node2.iotplatform.com:1883 send-proxy check
listen emqx_mqtt_ssl
bind *:9993 ssl crt /etc/ssl/emqx/server.pem no-sslv3
mode tcp
#mode http
maxconn 1000000
option clitcpka
timeout client 2m
timeout server 2m
option tcplog
balance leastconn
server node1 node3.iotplatform.com:1883 send-proxy check
server node2 node2.iotplatform.com:1883 send-proxy check
listen emxq_dashboard
bind *:19093
mode tcp
maxconn 1000000
option clitcpka
timeout client 2m
timeout server 2m
option tcplog
balance leastconn
server node1 node3.iotplatform.com:18083 check
server node2 node2.iotplatform.com:18083 check
emqx需要配置emqx.conf文件,获取传递的IP ,通过rpm方式安装的emqx配置文件默认是/etc/emqx.conf
## 为了获取 IP 地址,需要设置 proxy_protocol
listener.tcp.external.proxy_protocol = on
listener.ssl.external.proxy_protocol = on