<< 使用Spring的TaskExecutor的线程池执行异步操作 | 首页 | Yale CAS 证书以及Tomcat下配置 >>

使用Apache做负载均衡和Web服务器

使用Apache做负载均衡和Web服务器,并启用deflate,gzip压缩。配置httpd.conf如下:


LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so

 LoadModule deflate_module modules/mod_deflate.so

 LoadModule headers_module modules/mod_headers.so


<VirtualHost 10.150.152.102:80>

  ServerName 10.150.152.102

  DocumentRoot C:/

 

  ProxyPass /pfsys/images/ !
  ProxyPass /pfsys/styles/ !
  ProxyPass /pfsys/scripts/ !

  ProxyPass /psmis/images/ !
  ProxyPass /psmis/styles/ !
  ProxyPass /psmis/scripts/ !

  #ProxyPass / balancer://libraryfind/
  #ProxyPassReverse / balancer://libraryfind/
 
  ProxyPass /pfsys balancer://libraryfind/pfsys stickysession=JSESSIONID|jsessionid nofailover=On
  ProxyPassReverse /pfsys balancer://libraryfind/pfsys
  ProxyPass /psmis balancer://psmis/psmis stickysession=JSESSIONID|jsessionid nofailover=On
  ProxyPassReverse /psmis balancer://psmis/psmis
 
   #ProxyPreserveHost On

 AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript

  <Proxy balancer://libraryfind>
     BalancerMember http://10.150.152.102:7001
     #BalancerMember http://10.150.152.102:9001
  </Proxy>
 
 
  <Proxy balancer://psmis>
     BalancerMember http://10.150.152.102:9001
  </Proxy>

  <Directory "C:/">
     Options +FollowSymlinks +ExecCGI
     AllowOverride All
     Order allow,deny
     Allow from all
  </Directory>

  ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
  ErrorDocument 502 "<h2>Application error</h2>Unable to talk to back-end service"

#SetEnv force-proxy-request-1.0 1
#SetEnv proxy-nokeepalive 1
</VirtualHost>

另一个参考:

 

 

<VirtualHost 192.168.0.107:8080>
  ServerName 192.168.0.107
  DocumentRoot D:/

  ProxyPass /payCardSys/images/ !
  ProxyPass /payCardSys/styles/ !
  ProxyPass /payCardSys/scripts/ !

  ProxyPass / balancer://mycluster/ stickysession=JSESSIONID|jsessionid scolonpathdelim=On
   #ProxyPreserveHost On
 <Proxy balancer://mycluster>
 BalancerMember http://127.0.0.1:7011 route=node1
 BalancerMember http://127.0.0.1:7012 route=node2
 </Proxy>
  
  <Directory "D:/">
     Options +FollowSymlinks +ExecCGI
     AllowOverride All
     Order allow,deny
     Allow from all
  </Directory>

  ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
  ErrorDocument 502 "<h2>Application error</h2>Unable to talk to back-end service"

#SetEnv force-proxy-request-1.0 1
#SetEnv proxy-nokeepalive 1
</VirtualHost>

 

 

再附一个参考:

 

Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED

 

<VirtualHost 172.20.12.145:8080>

 

  ServerName 172.20.12.145

 

  DocumentRoot D:/

 

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript 

 

  ProxyPass /baseSys/images/ !

  ProxyPass /baseSys/styles/ !

  ProxyPass /baseSys/scripts/ !

 

   <Proxy balancer://libraryfind>

     BalancerMember http://172.20.12.145:80 route=app1

     BalancerMember http://172.20.37.249:8080 route=app2

  </Proxy>

  

  ProxyPass /baseSys balancer://libraryfind/baseSys  lbmethod=byrequests  stickysession=ROUTEID nofailover=Off

  ProxyPassReverse /baseSys balancer://libraryfind/baseSys

 

   #ProxyPreserveHost On

 

   <Directory "D:/">

     Options +FollowSymlinks +ExecCGI

     AllowOverride All

     Order allow,deny

     Allow from all

  </Directory>

 

  ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"

  ErrorDocument 502 "<h2>Application error</h2>Unable to talk to back-end service"

 

#SetEnv force-proxy-request-1.0 1

#SetEnv proxy-nokeepalive 1

</VirtualHost>

 

 

 例子:

 <VirtualHost 172.20.13.139:80>

Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED

ProxyPass /req/download/ !

<Proxy balancer://mycluster>

BalancerMember http://172.20.13.139:7003 route=1

BalancerMember http://172.20.13.139:7004 route=2

ProxySet stickysession=ROUTEID

</Proxy>

ProxyPass / balancer://mycluster/

ProxyPassReverse / balancer://mycluster/

 

DocumentRoot D:/req

<Directory "D:/req">

     Options +FollowSymlinks +ExecCGI

     AllowOverride All

     Order allow,deny

     Allow from all

</Directory>

</VirtualHost>

 



发表评论 发送引用通报