自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

tomcat負(fù)載均衡配置代碼大全

網(wǎng)絡(luò) 網(wǎng)絡(luò)優(yōu)化 網(wǎng)絡(luò)運(yùn)維
本文主要針對負(fù)載均衡配置的代碼進(jìn)行了一個(gè)完整的歸納和總結(jié)。其中,將配置的每一部都有詳細(xì)的說明和注釋,另外還包括了集群配置與應(yīng)用配置的相關(guān)代碼介紹。

前面我們介紹了tomcat負(fù)載均衡配置的安裝過程,接下來就進(jìn)入我們的重點(diǎn)了——tomcat負(fù)載均衡配置代碼內(nèi)容。當(dāng)然,我們在正確安裝之后才能進(jìn)行到這一步。之后還包括tomacat集群配置和應(yīng)用配置。相關(guān)的代碼介紹的比較詳細(xì),希望對大家有所幫助。

tomcat負(fù)載均衡配置過程

(1)在那臺要安裝apache的服務(wù)器上安裝apache2.0.55,我的安裝路徑為默認(rèn)C:\Program Files\Apache Group\Apache2

(2)安裝后測試apache能否正常啟動,調(diào)試到能夠正常啟動http://192.168.0.88

(3)下載jk2.0.4后解壓縮文件

(4)將解壓縮后的目錄中的modules目錄中的mod_jk2.so文件復(fù)制到apache的安裝目錄下的modules目錄中,我的為C:\Program Files\Apache Group\Apache2\modules

(5)修改apache的安裝目錄中的conf目錄的配置文件httpd.conf,在文件中加LoadModule模塊配置信息的最后加上一句LoadModule jk2_module modules/mod_jk2.so

(6)分別修改三個(gè)tomcat的配置文件conf/server.xml,修改內(nèi)容如下

修改前

  1. <!-- An Engine represents the entry point (within Catalina) that processes  
  2.          every request.  The Engine implementation for Tomcat stand alone  
  3.          analyzes the HTTP headers included with the request, and passes them  
  4.          on to the appropriate Host (virtual host). -->  
  5.  
  6.     <!-- You should set jvmRoute to support load-balancing via AJP ie :  
  7.     <Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1">           
  8.     -->   
  9.            
  10.     <!-- Define the top level container in our container hierarchy -->  
  11.     <Engine name="Catalina" defaultHost="localhost"

#p#修改后

  1. <!-- An Engine represents the entry point (within Catalina) that processes  
  2.      every request.  The Engine implementation for Tomcat stand alone  
  3.      analyzes the HTTP headers included with the request, and passes them  
  4.      on to the appropriate Host (virtual host). -->  
  5.  
  6. <!-- You should set jvmRoute to support load-balancing via AJP ie :-->  
  7. <Engine name="Standalone" defaultHost="localhost" jvmRoute="tomcat1">           
  8.    
  9.        
  10. <!-- Define the top level container in our container hierarchy   
  11. <Engine name="Catalina" defaultHost="localhost">  
  12. --> 

將其中的jvmRoute="jvm1"分別修改為jvmRoute="tomcat1"和jvmRoute="tomcat2"和jvmRoute="tomcat3"

(7)然后重啟三個(gè)tomcat,調(diào)試能夠正常啟動。

(8)在apache的安裝目錄中的conf目錄下創(chuàng)建文件workers2.propertie,寫入文件內(nèi)容如下

  1. # fine the communication channel   
  2. [channel.socket:192.168.0.1:8009]   
  3. info=Ajp13 forwarding over socket  
  4. #配置第一個(gè)服務(wù)器   
  5. tomcatId=tomcat1 #要和tomcat的配置文件server.xml中的jvmRoute="tomcat1"名稱一致  
  6. debug=0   
  7. lb_factor=1 #負(fù)載平衡因子,數(shù)字越大請求被分配的幾率越高  
  8.  
  9. # Define the communication channel   
  10. [channel.socket:192.168.0.2:8009]   
  11. info=Ajp13 forwarding over socket  
  12. tomcatId=tomcat2   
  13. debug=0   
  14. lb_factor=1   
  15.  
  16. # Define the communication channel   
  17. [channel.socket:192.168.0.4:8009]   
  18. info=Ajp13 forwarding over socket  
  19. tomcatId=tomcat3   
  20. debug=0   
  21. lb_factor=1   
  22.  
  23. [status:]   
  24. info=Status worker, displays runtime information.    
  25.  
  26. [uri:/jkstatus.jsp]   
  27. info=Display status information and checks the config file for changes.   
  28. group=status:   
  29.  
  30. [uri:/*]   
  31. info=Map the whole webapp   
  32. debug=0 

#p#(9)在三個(gè)tomcat的安裝目錄中的webapps建立相同的應(yīng)用,我和應(yīng)用目錄名為TomcatDemo,在三個(gè)應(yīng)用目錄中建立相同 WEB-INF目錄和頁面index.jsp,index.jsp的頁面內(nèi)容如下

  1. <%@ page contentType="text/html; charset=GBK" %>  
  2. <%@ page import="java.util.*" %>  
  3. <html><head><title>Cluster App Test</title></head>  
  4. <body>  
  5. Server Info:  
  6. <%  
  7. out.println(request.getLocalAddr() + " : " + request.getLocalPort()+"<br>");%>  
  8. <%  
  9.   out.println("<br> ID " + session.getId()+"<br>");  
  10.  
  11.   // 如果有新的 Session 屬性設(shè)置  
  12.   String dataName = request.getParameter("dataName");  
  13.   if (dataName != null && dataName.length() > 0) {  
  14.      String dataValue = request.getParameter("dataValue");  
  15.      session.setAttribute(dataName, dataValue);  
  16.   }  
  17.  
  18.   out.print("<b>Session 列表</b>");  
  19.  
  20.   Enumeration e = session.getAttributeNames();  
  21.   while (e.hasMoreElements()) {  
  22.      String name = (String)e.nextElement();  
  23.      String value = session.getAttribute(name).toString();  
  24.      out.println( name + " = " + value+"<br>");  
  25.          System.out.println( name + " = " + value);  
  26.    }  
  27. %>  
  28.   <form action="index.jsp" method="POST">  
  29.     名稱:<input type=text size=20 name="dataName">  
  30.      <br>  
  31.     值:<input type=text size=20 name="dataValue">  
  32.      <br>  
  33.     <input type=submit>  
  34.    </form>  
  35. </body>  
  36. </html> 

(10)重啟apache服務(wù)器和三個(gè)tomcat服務(wù)器,到此tomcat負(fù)載均衡配置完成。測試負(fù)載均衡先測試apache,訪問http://192.168.0.88/jkstatus.jsp

能否正常訪問,并查詢其中的內(nèi)容,有三個(gè)tomcat的相關(guān)配置信息和負(fù)載說明,訪問http://192.168.0.88/TomcatDemo/index.jsp看能夠運(yùn)行,能運(yùn)行,則已建立負(fù)載均衡。

責(zé)任編輯:佟健 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2014-07-28 11:37:49

NginxTomcat

2010-04-20 22:36:52

負(fù)載均衡配置

2010-04-22 16:41:56

負(fù)載均衡端口規(guī)則

2010-05-05 23:27:32

負(fù)載均衡配置

2010-04-20 21:27:28

tomcat負(fù)載均衡配

2010-04-21 12:28:50

Oracle負(fù)載均衡

2010-05-04 16:10:51

負(fù)載均衡算法

2018-09-13 08:47:09

Tomcat負(fù)載均衡服務(wù)器

2020-03-11 19:38:39

Tomcat負(fù)載均衡配置

2010-04-21 12:57:33

RAC負(fù)載均衡配置

2010-04-20 17:34:21

Linux雙網(wǎng)卡負(fù)載均衡

2010-05-04 13:23:55

Tomcat負(fù)載均衡

2010-05-06 15:24:35

Tomcat負(fù)載均衡

2010-04-22 23:47:55

tomcat負(fù)載均衡設(shè)

2010-05-06 15:04:51

Tomcat負(fù)載均衡

2010-04-22 10:09:28

負(fù)載均衡器

2010-04-22 23:07:47

服務(wù)器負(fù)載均衡

2010-04-22 12:45:05

2011-04-18 10:04:24

apachetomcat

2010-04-23 10:03:42

tomcat負(fù)載均衡技術(shù)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號