1. 架构说明: nginx + 4个tomcat
nginx作为前端代理,并且肩负负载均衡的作用,多个tomcat可以解决单台服务器高并发的性能问题,至于后端放几个tomcat要看你的服务器有多大内存,我的服务器是4核的CPU,8G内存。
2. nginx安装简单说明:
编译参数:
--prefix=/opt/mysql/ --enable-assembler --with-extra-charsets=complex \
--enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server \
--enable-local-infile --with-plugins=innobase
可以根据自己的环境修改配置
nginx.conf配置:
从上面配置可以看出,nginx会把http请求均匀分发给8080,8081,8082,8083几个端口的后端服务,实现负载均衡的效果。
3. Tomcat 配置
server.xml配置,由于一个<Service></Service>会启动一个实例,所以我们这里要启动4个tomcat实例就设置4个Service :
然后可以设置tomcat为Linux的服务,以便可以自动启动,创建权限为755的配置文件:/etc/init.d/tomcat,内容如下:
添加服务:chkconfig --add tomcat
设置自动启动:chkconfig tomcat on
另外,需要修改tomcat/bin/startup.sh,在#!/bin/sh下面添加:CATALINA_OPTS='-Xms2048m -Xmx2048m'
4. Tomcat全局filter解决乱码问题:
代码就不写了,说下过程,filter代码网上到处都是,我要说的在tomcat/conf/web.xml中增加filter配置,和在单独应用中增加一样,然后把filter的class打包jar文件放在tomcat/lib目录下即可。