源頭:apache+tomcat集羣的負載均衡算法有問題,現象是apache把過多壓力分配給本地tomcat,另外一臺服務器的tomcat極爲悠閒(鏈接數差一個數量級),因而改用nginx做前端負載均衡 html
========如下是集羣配置======== 前端
...... http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; # ccq 6/5 add: tomcat_proxy upstream localhost { server localhost:9080; server localhost:8080; ip_hash; } # ccq 6/5 add: tomcat_proxy end server { listen 80; server_name localhost; ...... location / { root html; # ccq 6/5 upd: tomcat_proxy index index.html index.jsp; proxy_pass http://localhost; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; # ccq 6/5 upd: tomcat_proxy end } ……
…… <Server port="9005" shutdown="SHUTDOWN"> …… <Connector port="9080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> …… <Connector port="9009" protocol="AJP/1.3" redirectPort="9443" jvmRoute="tomcat1"/> …… <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2"> ……