5.6.1.1. 安装和配置负载均衡

这里介绍在 Ubuntu 14.04 上安装 Apache HTTP Server 作为负载均衡。

  • 安装 Apache HTTP Servermod_jk 模块:

$ sudo apt-get install apache2 libapache2-mod-jk

  • 用以下内容替换 /etc/libapache2-mod-jk/workers.properties 文件内容:
  1. workers.tomcat_home=
  2. workers.java_home=
  3. ps=/
  4. worker.list=tomcat1,tomcat2,loadbalancer,jkstatus
  5. worker.tomcat1.port=8009
  6. worker.tomcat1.host=host1
  7. worker.tomcat1.type=ajp13
  8. worker.tomcat1.connection_pool_timeout=600
  9. worker.tomcat1.lbfactor=1
  10. worker.tomcat2.port=8009
  11. worker.tomcat2.host=host2
  12. worker.tomcat2.type=ajp13
  13. worker.tomcat2.connection_pool_timeout=600
  14. worker.tomcat2.lbfactor=1
  15. worker.loadbalancer.type=lb
  16. worker.loadbalancer.balance_workers=tomcat1,tomcat2
  17. worker.jkstatus.type=status
  • 添加下面的这些内容到 /etc/apache2/sites-available/000-default.conf
  1. <VirtualHost *:80>
  2. ...
  3. <Location /jkmanager>
  4. JkMount jkstatus
  5. Order deny,allow
  6. Allow from all
  7. </Location>
  8. JkMount /jkmanager/* jkstatus
  9. JkMount /app loadbalancer
  10. JkMount /app/* loadbalancer
  11. </VirtualHost>
  • 重启 Apache HTTP 服务:

$ sudo service apache2 restart