nginx + tomcat cluster

博客作業: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服務器; p_w_picpath 分別安裝Nginx服務和Tomcat服務

wKiom1ihBCvzAe24AAC_F9DOYBk649.png-wh_50



~]# 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;
p_w_picpathwKioL1ihBEygfJ5VAAAUikX1jCs334.png

在default.conf中配置代理
p_w_picpathwKiom1ihBGGCFoVtAAAsF4sP_y4082.png

啓動Nginx即完成Nginx的代理和輪詢調度的負載均衡;

配置Tomcat集羣

vim /etc/tomcat/service.xml
更改Host組件的appBase="/webapps",將網頁文件的位置更改爲/webapps;
p_w_picpath
在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

測試

p_w_picpath p_w_picpath

wKioL1ihBHfy-ZJkAAAfxRGIXF8842.png

wKiom1ihBHewwVWaAAAoBrxGnWo585.png


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章