博客作業: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服務
~]# 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
啓動Nginx即完成Nginx的代理和輪詢調度的負載均衡;
配置Tomcat集羣
vim /etc/tomcat/service.xml
更改Host組件的appBase="/webapps",將網頁文件的位置更改爲/webapps;
在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
測試