nginx服务器配置:192.168.200.111
[root@nginx ~]# hostname nginx
[root@nginx ~]# bash
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
upstream tomcat_pool {
server 192.168.200.112:8080 weight=1 max_fails=1 fail_timeout=10s;
server 192.168.200.113:8080 weight=1 max_fails=1 fail_timeout=10s;
}
location / {
root html;
index index.html index.htm;
proxy_pass http://tomcat_pool;
proxy_set_header Host $http_host;
}
[root@nginx ~]# killall -1 nginx
第一台tomcat服务器配置:192.168.200.112
[root@node1 ~]# vim /usr/local/tomcat8/webapps/ROOT/session.jsp
Session ID:<%= session.getId() %> <BR>
SessionPort:<%= request.getServerPort() %>
<% out.println("This tomcat server 192.168.200.112"); %>
[root@node1 ~]# vim /usr/local/tomcat8/webapps/ROOT/session.jsp
Session ID:<%= session.getId() %> <BR>
SessionPort:<%= request.getServerPort() %>
<% out.println("This tomcat server 192.168.200.112"); %>
[root@node1 ~]# yum -y install libevent memcached
[root@node1 ~]# memcached -u root -m 512M -n 10 -f 2 -d -vvv -c 512
[root@node1 ~]# mkdir session
上传memcached的jar包
[root@node1 ~]# cp session/* /usr/local/tomcat8/lib/
[root@node1 ~]# vim /usr/local/tomcat8/conf/context.xml
<Context>
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="memA:192.168.200.112:11211 memB:192.168.200.113:11211"
requestUrilgnorePattern=".*(ico|png|gif|jpg|css|js)$"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>
</Context>
[root@node1 ~]# /usr/local/tomcat8/bin/shutdown.sh
[root@node1 ~]# /usr/local/tomcat8/bin/startup.sh
[root@node1 ~]# ls session/ | while read line ; do rm -rf /usr/local/tomcat8/lib/$line; done
第二台tomcat服务器配置:192.168.200.113
同上