读书人

nginx tomact 负荷 集群

发布时间: 2012-09-14 23:00:49 作者: rapoo

nginx tomact 负载 集群

今天看到"基于apache的tomcat负载均衡和集群配置"这篇文章成为javaEye热点。

略看了一下,感觉太复杂,要配置的东西太多,因此在这里写出一种更简洁的方法。

?

要集群tomcat主要是解决SESSION共享的问题,因此我利用memcached来保存session,多台TOMCAT服务器即可共享SESSION了。

?

你可以自己写tomcat的扩展来保存SESSION到memcached。

这里推荐使用memcached-session-manager这个开源项目(http://code.google.com/p/memcached-session-manager/),下面简称msm。


如何安装nginx、memcached、tomcat这些就不多说了。


先说明一下测试环境:

tomcat1、nginx、memcached安装在192.168.1.11

tomcat2安装在192.168.1.101


下面分步实现基于nginx的tomcat负载均衡和集群配置

?

一,tomcat集群

??? 1,先下载msm及其依赖包

??? http://memcached-session-manager.googlecode.com/files/memcached-session-manager-1.3.0.jar

?

??? http://memcached-session-manager.googlecode.com/files/msm-javolution-serializer-jodatime-1.3.0.jar

?

http://memcached-session-manager.googlecode.com/files/msm-javolution-serializer-cglib-1.3.0.jar

?

http://spymemcached.googlecode.com/files/memcached-2.4.2.jar


http://memcached-session-manager.googlecode.com/files/javolution-5.4.3.1.jar

?

2,将这5个包放到$TOMCAT_HOME/lib目录下


3,修改$TOMCAT_HOME/conf/server.xml

?

      #user??nobody;??worker_processes??1;????error_log??logs/error.log;????events?{??????worker_connections??1024;??}??????http?{??????include???????mime.types;??????default_type??application/octet-stream;????????sendfile????????on;??????keepalive_timeout??65;????????#gzip??on;??????upstream??www.docyeah.com???{????????????????server???192.168.1.11:8080;????????????????server???192.168.1.101:8080;??????}??????server?{??????????listen???????80;??????????server_name??www.docyeah.com;??????????charset?utf-8;??????????location?/?{??????????????root???html;??????????????index??index.html?index.htm;??????????????proxy_pass????????http://www.docyeah.com;??????????????proxy_set_header??X-Real-IP??$remote_addr;??????????????client_max_body_size??100m;??????????}??????????????location?~?^/(WEB-INF)/?{???????????deny?all;???????????}?????????????error_page???500?502?503?504??/50x.html;??????????location?=?/50x.html?{??????????????root???html;??????????}????????}??}??

    ?

    将www.docyeah.com替换成你的域名

    192.168.1.11和192.168.1.101替换成你服务器的IP

    ?

    OK,已经完成。启动nginx即可。


读书人网 >其他相关

热点推荐