1、为什么需要对tomcat服务器配置做负载均衡配置呢?【转】
tomcat服务器作为一个web服务器,其并发数目在300-500之间,如果大于这个并发数,tomcat那么会出现不能响应某些请求,严重影响程序的正常工作。另外,在访问量比较大的情况下,tomcat的线程数目会不断的增加。由于tomcat自身的对内存的占有控制,当对内存的占有达到最大值时便会出现内存溢出,对程序的访问会严重超时等现象,这样必须重启服务器来释放占有的内存,对网站或者游戏来说,会造成很大的损失。所以对tomcat的负载均衡很有必要。目前可以跟tomcat做负载均衡的有apache,但是由于ngnix的功能多并且配置简单,所以很多程序员会选择这种配置。ngnix并发数可达5W,所以理论上可以跟tomcat1:100做配置。
2、安装nginx
[[email protected] nginx-1.3.15]# tar -zxvf nginx-1.3.15.tar.gz [[email protected] nginx-1.3.15]# cd nginx-1.3.15 [[email protected] nginx-1.3.15]# ./configure --prefix=/usr/local/nginx
报错:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
需要安装依赖包PCRE:
[[email protected] nginx-1.3.15]# yum install -y pcre-devel [[email protected] nginx-1.3.15]# ./configure --prefix=/usr/local/nginx
又报错:
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
继续安装依赖包zlib:
[[email protected] local]# cd zlib-1.2.8 [[email protected] zlib-1.2.8]# ./configure [[email protected] sbin]# ./configure --prefix=/usr/local/nginx --with-zlib=/usr/local/zlib-1.2.8 [[email protected] sbin]# make && make install [[email protected] sbin]# pwd /usr/local/nginx/sbin [[email protected] sbin]# ls nginx [[email protected] sbin]# ./nginx
查看80端口是否被占用:
[[email protected] sbin]# netstat -ano|grep 80
浏览器访问此IP:http://192.168.26.136/,出现如下,则搭建nginx成功。