Architecture diagram
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/77/13/wKioL1ZipZjxfgppAABGRleQs2g582.png "title=" Lnmt.png "alt=" Wkiol1zipzjxfgppaabgrleqs2g582.png "/>
Environment description
all hosts based on CentOS 6.5
back-end host : ha111 ip:192.168.61.139 installing Tomcat
back-end host : ha222 ip:192.168.61.140 installing Tomcat
Load Balancer Scheduling host:rs1 ip:192.168.61.131 installation Nginx
ha111 Host Configuration
1. JDK installation, can be used Sun or openjdk, here with Sun 's
2.tomcat Installation
Adding system Services
Vim/etc/init.d/tomcat
#!/bin/sh
# Tomcat Init scriptfor Linux.
#
# chkconfig:2345 96 14
# Description:theapache Tomcat servlet/jsp container.
# java_opts= '-xms64m-xmx128m '
Java_home=/usr/java/latest#Note that these paths are correct
Catalina_home=/usr/local/tomcat#Note that these paths are correct
Exportjava_home Catalina_home#This sentence can not add, the front environment is set up on the line
Case $ in
Start
exec $CATALINA _home/bin/catalina.sh start;;
Stop
exec $CATALINA _home/bin/catalina.sh stop;;
Restart
$CATALINA _home/bin/catalina.sh Stop
Sleep 2
exec $CATALINA _home/bin/catalina.sh start;;
*)
echo "Usage: ' basename $ ' {Start|stop|restart}"
Exit 1
;;
Esac
Modify the default listener's 8080 port to 80
Vim/usr/local/tomcat/conf/server.xml
<connector port= "8080" protocol= "http/1.1" to
<connector port= "protocol=" http/1.1 "
chmod +x/etc/init.d/tomcat
Chkconfig--add Tomcat
Service Tomcat start Services
Build a test Site
Cd/usr/local/tomcat/webapp
MKDIR-PV Testapp/{web-inf,classes,meta-inf,lib}
Set up homepage
Vim testapp/index.jsp
<%@ page language= "java"%>
<body>
<tableborder= "1" >
<tr>
<td>session id</td>
<%session.setattribute ("dx.com", "dx.com"); %>
<td><%= Session.getid ()%></td>
</tr>
<tr>
<td>created on</td>
<td><%=session.getcreationtime ()%></td>
</tr>
</table>
</body>
Test Curl http://localhost:8080/testapp/index.jsp
3. ha222 Host configuration is the same as ha111
4. Nginx Load Balancer Scheduler rs1 Configuration
Compile and install after decompression
./configure--prefix=/usr/local/nginx--conf-path=/etc/nginx/nginx.conf--user=nginx--group=nginx--error-log-path =/var/log/nginx/error.log--http-log-path=/var/log/nginx/access.log--pid-path=/var/run/nginx/ Nginx.pid--lock-path=/var/lock/nginx.lock--with-http_ssl_module--with-http_stub_status_module--with-http_gzip_ Static_module--with-http_flv_module--with-http_mp4_module--http-client-body-temp-path=/var/tmp/nginx/ client--http-proxy-temp-path=/var/tmp/nginx/proxy--http-fastcgi-temp-path=/var/tmp/nginx/ Fastcgi--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi--add-module=. /nginx-sticky-module-1.1
Make && make install
Note: If you need to turn onSticky sessionfunction, need to add the above red this sentence,nginx-sticky-module-1.1where the module files are located, hereNginxthe source file andStickymodule source files in the same directory
Create the directory specified above, or you will get an error when booting
MKDIR-PV/VAR/TMP/NGINX/{CLIENT,PROXY,FASTCGI,UWSGI}
at this point all configuration is complete, as long as access http://192.168.61.131/testapp/index.jsp can implement a cookie-based session sticky LNMT
Implementation of session sticky LNMT based on cookie