前言:压测emq集群之前需要有负载均衡服务,做负载均衡的一般常用nginx,也可以用haproxy,我这里用nginx。
虽然一个nginx就可以实现负载均衡的功能,但nginx作为一个入口,如果挂了后续服务都将受到影响,nginx+keeplived能实现nginx的高可用。目前nginx+keeplived有两种搭建模式:1,主从热备 2,双机热备。我用第二种,更多利用服务器资源。
部署机器 128,135.
先安装nginx:
#准备依赖包:
cd /opt
yum -y install gcc pcre-devel zlib-devel openssl-devel openssl
wget http://nginx.org/download/nginx-1.15.12.tar.gz
安装Nginx,编译过程中开启 --with-stream,tcp转发必须模块,因为emqx转发的是tcp连接
tar -zxvf nginx-1.15.12.tar.gz
cd nginx-1.15.12
./configure --with-http_stub_status_module --with-http_ssl_module --with-stream --prefix=/opt/nginx
make && make install
编辑配置文件
vim /opt/nginx/conf/nginx.conf
#在文件最后加上自己定义tcp转发配置文件
include emqx.conf;
新建tcp