Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build EMQ X Cluster based on HAProxy

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Based on HAProxy how to build EMQ X cluster, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

The load balancer (LB) is responsible for distributing the MQTT connections and messages of the devices to the EMQ X cluster. Using LB can improve the availability of the EMQ X cluster, achieve load balancing and dynamically expand the capacity.

HAProxy is a free and open source software written in C language that provides high availability, load balancing, and TCP and HTTP-based application proxies. It is a free, fast and reliable solution.

This article describes how to deploy an EMQ X cluster based on HAProxy and terminate SSL connections on HAProxy, a deployment model in which a single EMQ X cluster can easily support millions of devices.

Prepare for

Software and hardware version

Ubuntu 18.04

EMQ X Broker v4.2.5

HAProxy 2.2 +

Machine allocation

172.16.239.107:HAProxy

172.16.239.108:EMQ X Node 1

172.16.239.109:EMQ X Node 2

Install EMQX

Reference EMQ X Broker

Wget https://www.emqx.io/downloads/broker/v4.2.5/emqx-ubuntu18.04-4.2.5-x86_64.zipunzip emqx-ubuntu18.04-4.2.5-x86_64.zipHAProxysudo apt-get updatesudo apt-get install software-properties-common-ysudo add-apt-repository-y ppa:vbernat/haproxy-2.2sudo apt-get updatesudo apt-get install-y haproxy=2.2.\ * configure EMQX

Modify the emqx/etc/emqx.conf configuration file, and the other one is the same.

# # modify the node name node.name = emqx@172.16.239.108## modify the cluster policy to static. There is no need to manually add nodes cluster.discovery = static## all cluster nodes cluster.static.seeds = emqx@172.16.239.108. In order to obtain the IP address, emqx@172.16.239.109## needs to set proxy_protocollistener.tcp.external.proxy_protocol = onHAProxy

Modify / etc/haproxy/haproxy.cfg

Add TCP backend configuration

Backend backend_emqx_tcp mode tcp balance roundrobin server emqx_node_1 172.16.239.108:1883 check-send-proxy send-proxy-v2 check inter 10s fall 2 rise 5 server emqx_node_2 172.16.239.109:1883 check-send-proxy send-proxy-v2 check inter 10s fall 2 rise 5

Add dashboard backend configuration

Backend backend_emqx_dashboard balance roundrobin server emqx_node_1 172.16.239.108:18083 check server emqx_node_2 172.16.239.109:18083 check

Add TCP frontend configuration

Frontend frontend_emqx_tcp bind *: 1883 option tcplog mode tcp default_backend backend_emqx_tcp

Add dashboard frontend configuration

Frontend frontend_emqx_dashboard bind *: 18083 option tcplog mode tcp default_backend backend_emqx_dashboard run EMQX$. / bin/emqx start## to check cluster status $. / bin/emqx_ctl cluster statusCluster status: # {running_nodes = > ['emqx@172.16.239.108','emqx@172.16.239.109'], stopped_nodes = > []} HAProxy$ sudo service haproxy start

At this point, you can access dashboard through 18083

Connect to the cluster through 1883, the connection can be viewed on dashboard, or execute commands on the node

/ bin/emqx_ctl clients list certificate

If you need TLS termination, first prepare the emqx.key and emqx.crt files, and then merge to generate the emqx.pem file

$cat emqx.crt emqx.key > emqx.pem

Then add the following configuration

Frontend frontend_emqx_tcp bind *: 8883 ssl crt / opt/certs/emqx.pem no-sslv3 option tcplog mode tcp default_backend backend_emqx_tcp is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report