Linux下使用Tomcat7搭建高性能Java服务器
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配置:
?
?然后可以设置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目录下即可。
?