环境和实现效果:
两台阿里云服务器做集群
服务器 1 (主):内网(10.0.0.1)外网(118.0.0.1)
服务器 2 (从):内网(10.0.0.2)外网(118.0.0.2)安装emq
1
2wget https://www.emqx.io/static/brokers/emqttd-ubuntu16.04-v2.3.11.zip
unzip emqttd-ubuntu16.04-v2.3.11.zip配置
1
2
3
4vim emqttd/etc/emq.conf
node.name = emq@内网IP
mqtt.allow_anonymous = false系统调优
切换到root账号操作比较方便
1
2
3
4
5
6
7
8
9
10vim /etc/security/limits.conf
ubuntu soft nofile 65535
ubuntu hard nofile 65535
root soft nofile 65535
root hard nofile 65535
* soft nofile 65536
* hard nofile 65536
* soft nproc 102400
* soft memlock unlimited
* hard memlock unlimited1
2
3
4sysctl -w fs.file-max=2097152
sysctl -w fs.nr_open=2097152
echo 2097152 > /proc/sys/fs/nr_open
ulimit -n 10485761
2
3
4vim /etc/sysctl.conf
fs.file-max = 1048576
vim /etc/systemd/system.conf
DefaultLimitNOFILE=10485761
2
3
4
5
6
7
8
9
10
11sysctl -w net.core.somaxconn=32768
sysctl -w net.ipv4.tcp_max_syn_backlog=16384
sysctl -w net.core.netdev_max_backlog=16384
sysctl -w net.ipv4.ip_local_port_range='1000 65535'
sysctl -w net.core.rmem_default=262144
sysctl -w net.core.wmem_default=262144
sysctl -w net.core.rmem_max=16777216
sysctl -w net.core.wmem_max=16777216
sysctl -w net.core.optmem_max=16777216
sysctl -w net.ipv4.tcp_rmem='1024 4096 16777216'
sysctl -w net.ipv4.tcp_wmem='1024 4096 16777216'加入集群
1
2
3
4
5以root账号运行
./bin/emqttd start
在节点运行
./bin/emqttd_ctl cluster join emq@10.0.0.1退出集群
1
2
3
4
5本节点退出集群
./bin/emqttd_ctl cluster leave
从集群删除其他节点
./bin/emqttd_ctl cluster remove emq@s2.emqtt.io负载均衡
省略