安装NGINX
系统平台:CentOS 7
1、首先安装必要的库(nginx 中gzip模块需要 zlib 库,rewrite模块需要 pcre 库,ssl 功能需要openssl库),
yum install -y pcre zlib gcc make gcc-c++ openssl-devel
2.nginx的安装
- 下载安装包
wget http://nginx.org/download/nginx-1.8.0.tar.gz
- 解压安装包
tar -zxvf nginx-1.8.0.tar.gz
- 编译安装
cd nginx-1.8.0 ./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module make && make install
注意:安装NGINX,编译过程中开启 --with-stream,tcp转发必须模块
(2) 配置NGINX负载均衡:让所有EMQ节点共用一个入口.即使EMQ有节点无法工作,nginx反向代理的地址依然能正常工作
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream dc.ss.com
{
server 192.168.12.2:18883;
server 192.168.12.3:18883;
}
server {
listen 80;
server_name dc.ss.com;
location / {
proxy_pass http://dc.ss.com;
}
}
}
stream{
upstream emqt_cluster
{
zone tcp_servers 64k;
hash $remote_addr;
server 192.168.12.2:1883 max_fails=2 fail_timeout=30s;
server 192.168.12.3:1883 max_fails=2 fail_timeout=30s;
}
server
{
listen 1883;
proxy_pass emqt_cluster;
}
}