1、为什么需要对tomcat服务器配置做负载均衡配置呢?【转】
tomcat服务器作为一个web服务器,其并发数目在300-500之间,如果大于这个并发数,tomcat那么会出现不能响应某些请求,严重影响程序的正常工作。另外,在访问量比较大的情况下,tomcat的线程数目会不断的增加。由于tomcat自身的对内存的占有控制,当对内存的占有达到最大值时便会出现内存溢出,对程序的访问会严重超时等现象,这样必须重启服务器来释放占有的内存,对网站或者游戏来说,会造成很大的损失。所以对tomcat的负载均衡很有必要。目前可以跟tomcat做负载均衡的有apache,但是由于ngnix的功能多并且配置简单,所以很多程序员会选择这种配置。ngnix并发数可达5W,所以理论上可以跟tomcat1:100做配置。
2、安装nginx(一般我们都需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩。)
1.选定源码目录
选定目录 /usr/local/
cd /usr/local/
2.安装PCRE库
cd /usr/local/
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.21.tar.gz
tar -zxvf pcre-8.21.tar.gz
cd pcre-8.21
./configure
make
make install
3.安装zlib库
cd /usr/local/
wget http://zlib.net/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8
cd zlib-1.2.8
./configure
make
make install
4.安装ssl
cd /usr/local/
wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
tar -zxvf openssl-1.0.1c.tar.gz
cd openssl-1.0.1c
./config
make
make install
安装nginx:
# ./configure --user=yuki --group=yuki --prefix=/usr/local/nginx --with-openssl=/usr/local/openssl-1.0.1c --with-pcre=/usr/local/pcre2-10.10 --with-zlib=/usr/local/zlib-1.2.8
# make
报错:
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I /usr/local/pcre2-10.10 -I /usr/local/zlib-1.2.8 -I objs \
-o objs/src/core/nginx.o \
src/core/nginx.c
In file included from src/core/ngx_core.h:63,
from src/core/nginx.c:9:
src/core/ngx_regex.h:15:18: error: pcre.h: No such file or directory
In file included from src/core/ngx_core.h:63,
from src/core/nginx.c:9:
src/core/ngx_regex.h:24: error: expected specifier-qualifier-list before ‘pcre’