(七)企业部分之tomcat
1.安装tomcattar zxf apache-tomcat-7.0.37.tar.gz -C /usr/local/lnmp/cd /usr/local/lnmp/
ln -s apache-tomcat-7.0.37/ tomcat
cd tomcat/
bin/startup.shhttp://s3.运维网.com/wyfs02/M00/82/B6/wKiom1de8fWQuPgNAAC3obemaRY343.png
vim /usr/local/lnmp/nginx/conf/nginx.conf 在location ~ \.php$之后,添上以下内容(82行之后)
location ~ \.jsp$ {
proxy_pass http://172.25.45.1:8080;
}
http://s1.运维网.com/wyfs02/M00/82/B4/wKioL1de8yPTISlHAABY8dGijfQ139.png
nginx -s reloadhttp://s5.运维网.com/wyfs02/M01/82/B6/wKiom1de8iSzUzhYAAB4WMjWAvI913.png
cd /usr/local/lnmp/tomcat/webapps/ROOT
vim test.jsp The time is:
http://s1.运维网.com/wyfs02/M01/82/B4/wKioL1de82Xi1OOkAAANoTzPBbI082.png
http://s1.运维网.com/wyfs02/M01/82/B6/wKiom1de8mPjTwbNAAAvOxCedjY640.png
2.tomcat 集群
再启动一个虚拟机server2,把配置好的java-jdk和tomcat复制到启动的server2中
【server1】
scp -r /usr/local/java/ root@172.25.45.2:/usr/local/
scp -r /usr/local/lnmp/tomcat/ root@172.25.45.2:/usr/local/
scp /etc/profile root@172.25.45.2:/etc/
【server2】
source /etc/profile
echo $PATH
cd /usr/local/tomcat
bin/startup.sh
访问server2的tomcat
http://s2.运维网.com/wyfs02/M01/82/B4/wKioL1de87vg9XZpAAA09fvdVvs592.png
3.rr论寻
【server1】
vim /usr/local/lnmp/nginx/conf/nginx.conf 16 http {
17 upstream westos{
18 server 172.25.45.1:8080;
19 server 172.25.45.2:8080;
20 }
http://s1.运维网.com/wyfs02/M00/82/B6/wKiom1de8wHQ9n8RAAA8eehEdr8182.png
修改server后的端口值为8080
81 location ~ \.jsp$ {
82 proxy_pass http://westos;
83 }
http://s2.运维网.com/wyfs02/M02/82/B4/wKioL1de8-vxqoVEAAAQugm-TS4229.png
将proxy_pass改为http://westos
nginx -t
nginx -s reloadcd /usr/local/lnmp/tomcat/webapps/ROOT
vim test.jsp 在内容最前面加上server1-
【server2】
cd /usr/local/tomcat/webapps/ROOT 对server2的test.jsp也进行修改,在内容最前面加上server2-
访问172.25.45.1/test.jsp
页面显示会在server1-The time与The time之间切换
关闭server1的tomcat,只显示server2的/usr/local/lnmp/tomcat/webapps/ROOT/test.jsp 内容
http://s5.运维网.com/wyfs02/M00/82/B4/wKioL1de9HyzuNMLAAAu0tFG7sA833.pnghttp://s2.运维网.com/wyfs02/M02/82/B6/wKiom1de82zSH53fAAAvI-yVdx4430.png 、
4.ip_hash
vim /usr/local/lnmp/nginx/conf/nginx.conf 在17行upstream westos段下添上ip_hash;
http://s1.运维网.com/wyfs02/M02/82/B4/wKioL1de9KTSBb-_AAAuWP1VjF4607.png
同一个ip访问的是同一台服务器
./shutdown.sh 关闭一台后访问另外一台
5.sticky模式
从新编译1.8版本的nginx
tar zxf nginx-1.8.0.tar.gz
tar zxf nginx-sticky-module-1.0.tar.gz./configure \
--prefix=/usr/local/lnmp/nginx \
--with-http_ssl_module --with-http_stub_status_module \
--add-module=/mnt/nginx-sticky-module-1.0
or
./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --add-module=/root/nginx-sticky-module-1.0
vim /usr/local/lnmp/nginx/conf/nginx.conf 在17行upstream westos段下注释掉ip_hash添上sticky
http://s4.运维网.com/wyfs02/M00/82/B6/wKiom1de9CaQAVxVAAAiNBXmzkw741.png
vim /usr/local/lnmp/tomcat/webapps/ROOT/test.jsp
Cluster App Test
Server Info:
0) {
String dataValue = request.getParameter("dataValue");
session.setAttribute(dataName, dataValue);
}
out.print("Session list");
Enumeration e = session.getAttributeNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = session.getAttribute(name).toString();
out.println( name + " = " + value+"");
System.out.println( name + " = " + value);
}
%>
name:
key:
sticky 模式当用户访问,只要访问主机tomcat不挂,就一直访问同一个
vim /usr/local/lnmp/nginx/conf/nginx.conf 注释掉sticky
nginx -t
nginx -s reload
http://s1.运维网.com/wyfs02/M01/82/B4/wKioL1de9XWibCuuAABdze-0NQU399.png
http://s3.运维网.com/wyfs02/M01/82/B4/wKioL1de9XWw6BbfAABcyY73axI415.png
【server1】
vim /usr/local/lnmp/nginx/conf/nginx.conf 取消sticky的注释
nginx -t
nginx -s reload
http://s1.运维网.com/wyfs02/M02/82/B6/wKiom1de9S2wwqlWAABZbaQL5kw369.png
【server2】
cd /usr/local/tomcat/logs
tail -f catalina.outcd /usr/local/tomcat
bin/shutdown.sh
server2关闭,访问server1
http://s2.运维网.com/wyfs02/M02/82/B6/wKiom1de9O2AYKZXAADuTUOk1qE836.png
页:
[1]