Apache + jetty load balancing and cluster configuration
I. Matching Environment
(1). Jetty installation and configuration
Jetty_a: 192.168.55.229
Jetty_ B: 192.168.55.231
(1) install JDK
Download and compress the JDK to the/usr/local directory:
[Root @ master ~] # Chmod 755 jdk-6u5-linux-x64.bin
[Root @ master ~] #./Jdk-6u5-linux-x64.bin
[Root @ master ~] # Mv jdk1.6.0 _ 05/usr/local
Create a JDK soft link under/usr/local/to facilitate later version upgrades:
[Root @ master ~] # Ln-S/usr/local/jdk1.6.0 _ 05 // usr/local/JDK
(2) install Apache-Maven and set Environment Variables
[Root @ master ZY] # tar-zxvf apache-maven-2.2.1-bin.tar.gz
[Root @ master ZY] # mv apache-maven-2.2.1/usr/local/Maven
[Root @ master ZY] # Vim/etc/profile
Add the following content:
Java_home =/usr/local/jdk1.6.0 _ 05
Java_bin =/usr/local/jdk1.6.0 _ 05/bin
Path = $ path: $ java_bin:/Usr/local/Maven/bin
Classpath = $ java_home/lib/dt. jar: $ java_home/lib/tools. Jar
Jetty_home =/usr/local/Jetty
Export java_home java_bin path classpathJetty_home
[Root @ master ZY] # source/etc/profile
[Root @ master ZY] # MVN -- version
Apache Maven 2.2.1 (r801777; 03:16:01 + 0800)
Java version: 1.6.0 _ 05
Java home:/usr/local/jdk1.6.0 _ 05/JRE
Default locale: en_us, platform encoding: UTF-8
OS name: "Linux" version: "2.6.18-238. EL5" arch: "amd64" Family: "Unix"
(3) install and start Jetty
[Root @ master ZY] # unzip jetty-6.1.14-fgw-aps.zip
[Root @ master ZY] # mv jetty-6.1.14-fgw-aps/usr/local/Jetty
[Root @ master jetty] # Java-jar start. JarOr go to the bin directory and run./Jetty. Sh start]
[Root @ master bin] #./Jetty. Sh start
Starting jetty: started jetty Mon Jul 11 11:54:03 CST 2011
[Root @ master bin] #11:54:04. 014: info: redirecting stderr/stdout to/usr/local/jetty/logs/20151107_11.stderrout.log
Enter
Http: // 192.168.55.229: 8080/remote.html(add remote.html here to avoid conflicts with Tomcat. In fact, http: // 192.168.55.229: 8080 can also be accessed, but the premise is that Tomcat must be disabled. OrJetty. xmlChange the port number to 9009. Now we can directly access http: // 192.168.55.229: 9009)
(4) simple deployment of an application
[Root @ master jetty] # cd webapps/
[Root @ master webapps] # ls
Fgw
[Root @ node2 webapps] # cd fgw/
[Root @ master fgw] # Vim index. jsp
<% @ Page contenttype = "text/html; charset = GBK" %>
<% @ Page import = "Java. util. *" %>
<HTML>
<Body>
<%
// Httpsession session = request. getsession (true );
System. Out. println (session. getcreationtime ());
Out. println ("<br> session ID:" + session. GETID () + "<br> ");
Out. println ("session serviced by jetty_a" + "<br> ");
Out. println ("session created time is:" + session. getcreationtime () + "<br> ");
%>
</Body>
</Html>
Test: http: // 192.168.55.229: 9009/fgw/
Configure jetty_ B in the same way. The test result is:
(2) install and configure Apache (using the source code compilation and installation method)
Apache address: 192.168.50.50
# Tar xzvf httpd-2.2.17.tar.gz
# Cd httpd-2.2.17
#./Configure -- With-LDAP -- enable-mod-shared = "all SSL ldap cache proxy authn_alias mem_cache file_cache authnz_ldap charset_lite dav_lock disk_cache"[This option is used to compile all modules]
1. Test
Set servername localhost in/usr/local/apache2/CONF/httpd. conf
# Cd/usr/local/apache2/bin
#./Apachectl start
The output is similar to httpd (PID 17040) already running.
Access address: http: // 192.168.50.50
It works! Hehe...
It indicates that the operation is successful ~ \ (Too many rows )/~ La la ,(~ O ~)~ Zz
II. (1)Mod_proxy Server Load balancer Configuration
1. Load the proxy Module
All the Agent modules to be loaded are mod_proxy.so, mod_proxy.ajp.so, mod_proxy.http.so, mod_proxy.ftp.so, mod_proxy.connect.so, mod_proxy.balancer.so
Because all modules have been loaded, you do not need to modify the configuration, that is, the following command in the/usr/local/apache2/CONF/httpd. conf file:
Loadmodule proxy_module modules/mod_proxy.so
Loadmodule proxy_ftp_module modules/mod_proxy_ftp.so
Loadmodule proxy_http_module modules/mod_proxy_http.so
Loadmodule proxy_ajp_module modules/mod_proxy_ajp.so
Loadmodule proxy_balancer_module modules/mod_proxy_balancer.so
2. Configure the virtual host proxybalancer
Add include CONF/app1.conf at the end of/usr/local/apache2/CONF/httpd. conf.
Add the following content to CONF/app1.conf:
Listen 8051.
<Virtualhost *: 8051>
Serveradmin angel.zhu@99bill.com# Specify the server administrator's E-MAIL address, which the server automatically reports errors
Servername localhost# Host name searched by the Web Client
Errorlog "/opt/apache_log/apppolicerror.log"
Customlog "/opt/apache_log/app1_access.log" common
Proxypass/balancer: // cluster/stickysession = jessionid | jessionid nofailover = on lbmethod = byrequests timeout = 5 maxattempts = 3
#Balancer: the method used to copy sessions, includingJSESSIONIDOrPHPSESSIONID
;Nofailover: On indicates that a session is interrupted when a worker error occurs or the session is stopped. If the backend server does not support session replication, set it to on. lbmethod: select the scheduling algorithm of the load. The default value isbyrequestsIndicates round robin scheduling ),bytrafficIndicates weighted scheduling.LoadfactorSpecify the weight.
Proxypassreverse/balancer: // cluster/# This command enables Apache to adjust the URL in the location, content-location, and Uri header in the HTTP redirect response. This avoids the problem of bypassing reverse proxy caused by HTTP redirection of backend servers when Apache is used as a reverse proxy.
# The proxyrequests directive shoshould usually be set off when using proxypass.
Proxyrequests off# Forward proxy not allowed
Proxypreservehost on# When enabled, this option will pass the "host:" line of the incoming request to the host to be proxy, rather than the host name specified in proxypass.
<Proxy balancer: // cluster>
Balancermember AJP: // 192.168.55.229: 8009 route =Jetty_a
Balancermember AJP: // 192.168.55.231: 8009 route =Jetty_ B
# The rout value is appended to the session ID.
</Proxy>
</Virtualhost>
3. modify the configuration file in Jetty. xml
<! -- ===================================================== ================================ -->
<! -- Set up global session ID manager -->
<! -- ===================================================== ================================ -->
<Set name = "sessionidmanager">
<New class = "org. mortbay. Jetty. servlet. hashsessionidmanager">
<Set name = "workername">Jetty_a</Set>
</New>
</Set>
Make the workername consistent with the route value in Apache: change the value to jetty_a and jetty_ B respectively.
4. Enable jetty's AJP Port
You can viewFileJetty-ajp.xml
[Note: it must be consistent with the AJP port mentioned above in Apache]
We can write a script in the/usr/local/jetty directory:
Vim startjetty. Sh
Note:
Heap and non-heap memory
According to the official statement: "A Java virtual machine has a heap. The heap is the runtime data area, and the memory of all class instances and arrays is allocated from this place. The heap is created when the Java Virtual Machine is started ." "Memory outside of the heap in JVM is called non-heap memory )". JVM manages two types of memory: heap and non-heap. In short, heap is the memory available for Java code and is reserved for developers. Non-heap is reserved for JVM, therefore, the method area, JVM internal processing or optimization of the required memory (such as the code cache after JIT compilation), each class structure (such as the runtime data pool, field and method data) the methods and constructor code are all in non-heap memory.
Heap Memory Allocation
The initial memory allocated by JVM is specified by-XMS. The default value is 1/64 of the physical memory. The maximum memory allocated by JVM is specified by-xmx. The default value is 1/4 of the physical memory. By default, when the free heap memory is less than 40%, the JVM will increase the heap until the maximum limit of-xmx. When the free heap memory is greater than 70%, the JVM will reduce the minimum limit of heap until-XMS. Therefore, the server generally sets-XMS and-xmx to be equal to each other to avoid GC
Then adjust the heap size.
Non-heap memory allocation
JVM uses-XX: permsize to set the non-heap memory initial value. The default value is 1/64 of the physical memory. The maximum non-heap memory size is set by XX: maxpermsize. The default value is 1/4 of the physical memory.
-D <name >=< Vale> sets the java system ownership (eg:-dfgw. sourceid = fgw001)
-Dfgw fgw is the name of the application package in webapp for ease of searching
-XX:-heapdumponoutofmemoryerror: When oom is first encountered, export related information in the heap.
Then execute sh startjetty. Sh
[Root @ master jetty] # sh startjetty. Sh
SelectChannelConnector@0.0.0.0: 9009
14:22:47. 134: info: started Ajp13SocketConnector@0.0.0.0: 8009
14:22:47. 134: info: ajp13 is not a secure protocol. Please protect port 8009
(5) test jetty respectively.
Edit in/usr/local/jetty/webapps/fgwIndex. jsp
The content is as follows:
Not yet resumed !! [Because the image cannot be uploaded, you can only write another image ,~~~~ (>_< )~~~~ ]