windows系統下nginx+tomcat+redis作負載均衡和session粘滯附整套解決方案

Nginx:nginx

在nginx-1.8.0\conf目錄下找到nginx.conf文件,打開文件修改文件中http{}中的內容,在http{}中加入web

   upstream localhost  { redis

        server localhost:8080;windows

        server localhost:8090;tomcat

    } 服務器

    include       mime.types;session

default_type  application/octet-stream;app

其中8080和8090是下面說到的兩個tomcat的端口號。負載均衡

另外須要注意的是upstream tomcat的tomcat是主機服務器域名,在本地測試的話是localhost,與此同時server中的代理配置webapp

location / {

            proxy_pass  http://tomcat;

        }

中的tomcat也須要改成localhost

以下圖

 

配置後雙擊nginx-1.8.0目錄下的nginx.exe啓動nginx,這個能夠在進程中看到。

 

Redis:

打開redis-latest文件夾,能夠看到redis-server.exe和redis-cli.exe兩個安裝文件,一個是redis的服務,一個是鏈接redis的客戶端窗口。

首先打開cmd ,進入到redis-latest文件夾下,執行redis-server.exe redis.windows.conf 啓動redis服務。

 

兩個tomcat模擬兩個服務器:

將原始文件中的tomcat7集羣文件夾下的jar包複製到每一個tomcat的lib目錄下,而後修改每一個tomcat的conf/content.xml文件,添加

<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" /> 

<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager" 

         host="localhost" 

         port="6379" 

         database="0" 

         maxInactiveInterval="60" /> 

兩個tomcat的webapp下放入同一個項目。

windows下配置負載均衡至此完畢。啓動兩個tomcat,測試一下ok。

 附件csdn下載地址:

負載均衡整套解決方案下載

http://download.csdn.net/detail/lsk_1992/9515075

相關文章
相關標籤/搜索