nginx+tomcat+memcached

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

1.添加系统环境变量

[root@server2 ~]# vim /etc/profile

[root@server2 ~]# source /etc/profile

[root@server2 ~]# echo $PATH


2.安装java

[root@server2 mnt]# tar zxf jdk-7u79-linux-x64.tar.gz -C /usr/local/

[root@server2 mnt]# cd /usr/local/

[root@server2 local]# ln -s jdk1.7.0_79/ java


3.安装tomcat

[root@server2 mnt]# tar zxf apache-tomcat-7.0.37.tar.gz -C /usr/local/

[root@server2 mnt]# cd /usr/local/

[root@server2 local]# ln -s apache-tomcat-7.0.37/ tomcat



4.开启tomcat

[root@server2 ~]# cd /usr/local/tomcat/
[root@server2 tomcat]# bin/startup.sh

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


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

[root@server2 tomcat]# cd /usr/local/tomcat/webapps/ROOT/
[root@server2 ROOT]# vim test.jsp



二.Tomcat的负载均衡

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




2.server1配置nginx

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

[root@server1 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


[root@server1 nginx-1.10.1]# make && make install


3.修改nginx配置,开启nginx

[root@server1 ~]# vim /usr/local/lnmp/nginx/conf/nginx.conf
[root@server1 ~]# nginx


4.配置一个jsp测试页面

[root@server2 ~]# vim /usr/local/tomcat/webapps/ROOT/test.jsp
[root@server2 ~]# scp /usr/local/tomcat/webapps/ROOT/test.jsp root@172.25.87.3:/usr/local/tomcat/webapps/ROOT/


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

server2跟server3一样


[root@server2 ~]# cd /usr/local/tomcat/conf/

[root@server2 conf]# vim context.xml

[root@server2 tomcat]# bin/shutdown.sh

[root@server2 tomcat]# bin/startup.sh

[root@server2 tomcat]# /etc/init.d/memcached start

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


[root@server3 ~]# cd /usr/local/tomcat/conf/

[root@server3 conf]# vim context.xml

[root@server3 tomcat]# bin/shutdown.sh

[root@server3 tomcat]# bin/startup.sh

[root@server3 tomcat]# /etc/init.d/memcached start

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


6.测试

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


[root@server2 tomcat]# bin/shutdown.sh


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


[root@server2 tomcat]# /etc/init.d/memcached stop



www

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值