美文网首页工具癖
单机多实例 nginx LB tomcat(session

单机多实例 nginx LB tomcat(session

作者: 王哲理 | 来源:发表于2018-01-04 15:17 被阅读121次

背景:

因用户数量增多,单个微信公众号接口服务负载压力过大,所以采用nginx做LB,调度两台tomcat。

微信公众号限制,nginx和tomcat同在一台机器部署。

微信公众号接口服务只支持绑定一个ip地址,所以在采用如下方案:

系统版本;

cat /etc/redhat-release

CentOS Linux release 7.3.1611 (Core)

IP地址;

192.168.22.170

环境部署(本地测试环境);

Nginx版本:

nginx-1.12.2

nginx下载地址

Tomcat版本:

apache-tomcat-8.0.46

tomcat下载地址

Nginx部署:

以root安装,安装完后,授权给普通用户;

解压并编译安装

yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel vim wget

tar -xf  nginx-1.12.2.tar.gz

cd nginx-1.12.2

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module

make && make install

Tomcat部署:

tar -xf  apache-tomcat-8.0.46.tar.gz

mv  apache-tomcat-8.0.46   tomcat1

mv  apache-tomcat-8.0.46   tomcat2

修改tomcat1和tomcat2,端口分别为8081和8082

tomcat1和tomcat2测试文件内容如下:

Nginx配置;

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

vim  nginx.conf

调度规则使用(ip_hash),保存用户session会话。

LB配置如下:

应用测试;

访问地址:  www.whoami.cn  显示如下:

日志查询:

相关文章

网友评论

    本文标题:单机多实例 nginx LB tomcat(session

    本文链接:https://www.haomeiwen.com/subject/haernxtx.html