debian安装nginx及其相关包
源头:apache+tomcat集群的负载均衡算法有问题,现象是apache把过多压力分配给本地tomcat,另一台服务器的tomcat极为清闲(连接数差一个数量级),于是改用nginx作前端负载均衡
下载nginx ,我下的是nginx-1.4.1
进入解压目录编译 ./configure :报缺少pcre库
回头安转pcre,我下的是pcre-8.33,还是linux源码安装三部曲
再进nginx编译,这回报缺少zlib库
常识apt-get安装失败,查了下说是名称换了:zlib1g-dev,再试,再失败,总之缺少其他关联包,怒了,用源码安装方式,源码安装三部曲依旧
总算nginx编译通过,进入objs目录,启动命令就是nginx (注意默认80端口,不要被其他服务器抢了)
游览器输入localhost,出现welcome页,安装成功
========以下是集群配置========
修改nginx.conf,增加多个后端tomcat
01
......
02
03
http {
04
include mime.types;
05
default_type application/octet-stream;
06
07
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
08
# '$status $body_bytes_sent "$http_referer" '
09
# '"$http_user_agent" "$http_x_forwarded_for"';
10
11
#access_log logs/access.log main;
12
13
sendfile on;
14
#tcp_nopush on;
15
16
#keepalive_timeout 0;
17
keepalive_timeout 65;
18
19
#gzip on;
20
21
# ccq 6/5 add: tomcat_proxy
22
upstream localhost {
23
server localhost:8081;
24
server localhost:8080;
25
}
26
# ccq 6/5 add: tomcat_proxy end
27
28
server {
29
listen 80;
30
server_name localhost;
31
......
tomcat修改server.xml,防止端口冲突,这里是第二个tomcat的配置,第一个tomcat用默认的,注意加下jvmRoute
01
……
02
<Server port="9005" shutdown="SHUTDOWN">
03
……
04
<Connector port="9080" protocol="HTTP/1.1"
05
connectionTimeout="20000"
06
redirectPort="8443" />
07
……
08
<Connector port="9009" protocol="AJP/1.3" redirectPort="9443" jvmRoute="tomcat1"/>
09
……
10
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2">
11
……