一.Tomcat的安装配置,jsp页面的访问

1.添加系统环境变量

[[email protected] ~]# vim /etc/profile

[[email protected] ~]# source /etc/profile

[[email protected] ~]# echo $PATH

nginx+tomcat+memcached

2.安装java

[[email protected] mnt]# tar zxf jdk-7u79-linux-x64.tar.gz -C /usr/local/

[[email protected] mnt]# cd /usr/local/

[[email protected] local]# ln -s jdk1.7.0_79/ java

nginx+tomcat+memcached

3.安装tomcat

[[email protected] mnt]# tar zxf apache-tomcat-7.0.37.tar.gz -C /usr/local/

[[email protected] mnt]# cd /usr/local/

[[email protected] local]# ln -s apache-tomcat-7.0.37/ tomcat

nginx+tomcat+memcached
 

4.开启tomcat

[[email protected] ~]# cd /usr/local/tomcat/
[[email protected] tomcat]# bin/startup.sh 
nginx+tomcat+memcached

5.测试tomcat 的8080端口是否开启

nginx+tomcat+memcached

6.修改jsp的测试访问页面

 

[[email protected] tomcat]# cd /usr/local/tomcat/webapps/ROOT/
[[email protected] ROOT]# vim test.jsp

nginx+tomcat+memcached

nginx+tomcat+memcached

二.Tomcat的负载均衡

 

1.在server3和server2配置同样的tomcat服务

 

nginx+tomcat+memcached

 

nginx+tomcat+memcached

 

nginx+tomcat+memcached

 

2.server1配置nginx

停用openresty中的nginx;给nginx添加sticky模块

 

[[email protected] nginx-1.10.1]#  ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --with-file-aio --with-threads --user=nginx --group=nginx --add-module=/mnt/nginx-sticky-module-ng

nginx+tomcat+memcached

 

[[email protected] nginx-1.10.1]# make && make install

nginx+tomcat+memcached

 

3.修改nginx配置,开启nginx

[[email protected] ~]# vim /usr/local/lnmp/nginx/conf/nginx.conf
[[email protected] ~]# nginx 
nginx+tomcat+memcached
nginx+tomcat+memcached

 

4.配置一个jsp测试页面

[[email protected] ~]# vim /usr/local/tomcat/webapps/ROOT/test.jsp 
[[email protected] ~]# scp /usr/local/tomcat/webapps/ROOT/test.jsp [email protected]:/usr/local/tomcat/webapps/ROOT/
nginx+tomcat+memcached
nginx+tomcat+memcached

5.配置memcache缓存,交叉存储

server2跟server3一样

nginx+tomcat+memcached

[[email protected] ~]# cd /usr/local/tomcat/conf/

[[email protected] conf]# vim context.xml 

[[email protected] tomcat]# bin/shutdown.sh

[[email protected] tomcat]# bin/startup.sh 

[[email protected] tomcat]# /etc/init.d/memcached start

nginx+tomcat+memcached

server2的缓存优先由n2提供,n2宕机时,由n1提供

nginx+tomcat+memcached

[[email protected] ~]# cd /usr/local/tomcat/conf/

[[email protected] conf]# vim context.xml 

[[email protected] tomcat]# bin/shutdown.sh 

[[email protected] tomcat]# bin/startup.sh 

[[email protected] tomcat]# /etc/init.d/memcached start
 

nginx+tomcat+memcached

 

server3的缓存优先由n1提供,n1宕机时,由n2提供

nginx+tomcat+memcached

6.测试

1.当jsp由server2提供时,缓存优先在n2(server3)上,当我们把server2的tomcat停止后,jsp由server3提供,从缓存n2中提取数据,数据还存在。

nginx+tomcat+memcached

[[email protected] tomcat]# bin/shutdown.sh 

nginx+tomcat+memcached

2.当jsp由server3提供时,缓存由优先在n1(server2)上,当把n1的缓存服务停止后,server3的缓存由n2(server3)提供,数据还在。

nginx+tomcat+memcached

[[email protected] tomcat]# /etc/init.d/memcached stop

nginx+tomcat+memcached

相关文章: