一、搭建環境css
192.168.29.128(luxh-01.com) 安裝nginx,參考 http://www.cnblogs.com/luxh/p/4067038.htmlhtml
192.168.29.129(luxh-02.com) 安裝tomcat和memcachedjava
192.168.29.130(luxh-03.com) 安裝tomcat和memcachednginx
二、安裝memcachedweb
1)使用yum直接安裝tomcat
[root@Luxh-02 ~]# yum install memcached
2)啓動memcached,默認的啓動端口是11211服務器
[root@Luxh-02 ~]# memcached -u memcached -d
-u 指定用戶session
3)測試是否啓動成功app
[root@Luxh-02 ~]# telnet 127.0.0.1 11211
三、安裝Tomcat7webapp
參考:http://www.cnblogs.com/luxh/p/3188736.html
四、添加memcached-session-manager相關的jar到tomcat中
將如下jar放到tomcat安裝路徑的lib目錄中
memcached-session-manager-1.8.2.jar memcached-session-manager-tc7-1.8.2.jar spymemcached-2.11.1.jar
注意tomcat版本不一樣,用的jar版本也不一樣,具體可參考 http://code.google.com/p/memcached-session-manager/wiki/SetupAndConfiguration
五、將serializers相關的jar添加到web應用中
這裏使用 kryo-serializer實現序列化。
項目使用了maven,直接添加依賴便可
<dependency> <groupId>de.javakaffee.msm</groupId> <artifactId>msm-kryo-serializer</artifactId> <version>1.8.0</version> <scope>runtime</scope> </dependency>
若是沒有使用maven,自行添加如下的jar到項目中
msm-kryo-serializer-1.8.0.jar kryo-serializers-0.11.jar kryo-1.04.jar asm-3.2.jar reflectasm-1.01.jar minlog-1.2.jar jsr305-1.3.9.jar annotations-1.3.9.jar
六、在tomcat中配置memcached-session-manager
在tomcat的context.xml文件中加入如下內容(<Context></Context>標籤中)。
非粘性session配置,兩臺memcached服務器。
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager" memcachedNodes="n1:luxh-02.com:11211,n2:luxh-03.com:11211" sticky="false" sessionBackupAsync="false" requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$" transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory" />
七、配置nginx
1)nginx.conf文件中的http節點內容加入
upstream luxh-01.com {
server luxh-02.com:8080;
server luxh-03.com:8080;
}
2)nginx.conf文件中的server節點內容加入
location / {
proxy_pass http://luxh-01.com;
proxy_set_header X-Real-IP $remote_addr;
}
八、把應用分別部署到tomcat服務器中。
1)啓動memcached服務
2)啓動tomcat
3)啓動nginx
九、直接訪問http://luxh-01.com/webapp (我部署的項目是經過webapp訪問)