博客作业:tomcat
	(1) nginx + tomcat cluster, 
	httpd(proxy_http_module)+tomcat cluster, 
	httpd(proxy_ajp_module)+tomcat cluster;
	特别说明会话保持的实现方式;
	(2) tomcat cluster升级为session cluster, 使用deltaManager;
	(3) tomcat cluster将会话保存至memcached中;

tomacat web service (1)

(1)nginx + tomcat cluster

安装Nginx和tomcat

注意:在配置任意一配置文件是需要先对文件进行备份,并同步各个服务器的时间;

172.16.80.6安装nginx反代服务器;
172.16.80.7及172.16.80.8为tomcat服务器; nginx + tomcat cluster 分别安装Nginx服务和Tomcat服务

nginx + tomcat cluster



~]# yum -y install nginx

~]# yum -y install java-1.8.0-openjdk-devel tomcat-lib tomcat-admin-webapps tomcat-webapps

配置Nginx反代服务器

~]#vim /etc/nginx/nginx.conf

在http配置段添加upstream;
nginx + tomcat clusternginx + tomcat cluster

在default.conf中配置代理
nginx + tomcat clusternginx + tomcat cluster

启动Nginx即完成Nginx的代理和轮询调度的负载均衡;

配置Tomcat集群

vim /etc/tomcat/service.xml
更改Host组件的appBase="/webapps",将网页文件的位置更改为/webapps;
nginx + tomcat cluster
在172.16.80.7和172.16.80.8上分别执行以下命令并添加index.jsp

]# mkdir -pv /webapps/ROOT/{classes,lib,WEB-INF}
]# cd /webapps/ROOT/
]# vim index.jsp

<%@ page language="java" %><html>
  <head><title>TomcatA</title></head>
  <body>
    <h1><font color="red">TomcatA.magedu.com</font></h1>
    <table align="centre" border="1">
      <tr>
        <td>Session ID</td>
    <% session.setAttribute("magedu.com","magedu.com"); %>
        <td><%= session.getId() %></td>
      </tr>
      <tr>
        <td>Created on</td>
        <td><%= session.getCreationTime() %></td>
     </tr>
    </table>
  </body></html><%@ page language="java" %><html>
  
  
  <head><title>TomcatB</title></head>
  <body>
    <h1><font color="blue">TomcatB.magedu.com</font></h1>
    <table align="centre" border="1">
      <tr>
        <td>Session ID</td>
    <% session.setAttribute("magedu.com","magedu.com"); %>
        <td><%= session.getId() %></td>
      </tr>
      <tr>
        <td>Created on</td>
        <td><%= session.getCreationTime() %></td>
     </tr>
    </table>
  </body></html>

启动tamcat

~]#systemctl start tomcat

测试

nginx + tomcat cluster nginx + tomcat cluster

nginx + tomcat cluster

nginx + tomcat cluster