Apache-2.2.29 and tomcat-6.0.41 clusters in CentOS-6.4-minimal

Source: Internet
Author: User
/*** CentOS-6.4-minimal version of Apache-2.2.29 and tomcat-6.0.41 Implementation cluster * worker * this article is based on Apache-2.2.29 and tomcat-6.0.41 load balancing, for the implementation process, see the http://blog.csdn.net/jadyer/article/details/39617801 * worker *-------------------------------------------------------------------------------------------------------------------- -- * Terms * 1) Server Load balancer * after a front-end server (often called "Server Load balancer", "Server Load balancer", or "reverse proxy") receives an HTTP request, distribute requests to more than one "worker" Web server at the backend, which actually processes Requests * 2) session replication * session replication (Session sharing) is a mechanism that copies the original state of the Client Session to two or more server instances in the cluster for fault tolerance and failover. * 3) A cluster * consists of two or more web server instances that work in a consistent manner and transparently process client requests, the client considers a group of server instances as a single entity Service * between * several differences * 1) clusters are different from distributed It adopts the policy of running the same application on each server, and is distributed by the server responsible for balancing, which can improve the concurrency and throughput of the entire system * 2) as the cluster service needs to continuously copy sessions between requests, the copied sessions will gradually become large, therefore, its resource usage is very high * if the number of concurrent applications is large, the size of the copied session will become quite large, and the total memory used will increase rapidly * 3) the cluster's session replication increases the system's high availability. Because each server stores the user's session information * If a server in the server group goes down, applications can be automatically switched to other servers to continue running, but user information will not be lost, which improves the redundancy and error of Applications * 4) practice has proved that, when status replication is not required between application servers, Server Load balancer can achieve linear performance growth and higher concurrency requirements *-------------------------------------------------------------------------------- ------------------------------------ * Configure the Tomcat Instance name of the cluster * here, the jvmroute attribute value must be consistent with workers. the node names set in properties are the same, this value will be added as a suffix after each JSESSIONID generated by this node * While mod_jk determines which node should process a request based on the suffix after JSESSIONID, this is also the basic guarantee for implementing session_sticky * [[email protected] app] # vi/APP/tomcat1/CONF/server. XML (add the jvmroute attribute to the <engine/> node, and the attribute value is tomcat1) * [[email protected] app] # vi/APP/tomcat2/CONF/server. XML (add the jvmroute attribute to the <engine/> node, and the attribute value is atat2) * [[Email protected] app] # vi/APP/tomcat3/CONF/server. XML (add the jvmroute attribute to the <engine/> node, and the attribute value is atat3) * configure the cluster parameter * 0 for worker) if Tomcat is placed on different machines *, uncomment tomcat/CONF/server directly. <cluster classname = "org. apache. catalina. ha. TCP. simpletcpcluster "/> * 1) If Tomcat is placed on the same machine (refer to the http://tomcat.apach E.org/tomcat-6.0-doc/cluster-howto.html) * modify the default configuration of the <cluster/> node. The default configuration is as follows * <cluster classname = "org. apache. catalina. ha. TCP. simpletcpcluster "channelsendoptions =" 8 "> * <manager classname =" org. apache. catalina. ha. session. deltamanager "* expiresessionsonshutdown =" false "* yylistenersonreplication =" true "/> * <channel classname =" org. apache. catalina. tribes. group. groupchannel "> * <membership classnail m E = "org. apache. catalina. tribes. membership. mcastservice "* address =" 228.0.0.4 "* Port =" 45564 "* frequency =" 500 "* droptime =" 3000 "/> * <er classname =" org. apache. catalina. tribes. transport. NIO. nioreceiver "* address =" Auto "* Port =" 4000 "* autobind =" 100 "* selectortimeout =" 5000 "* maxthreads =" 6 "/> * <sender classname =" org. apache. catalina. tribes. transport. replicationtransmitter "> * <transport class Name = "org. apache. catalina. tribes. transport. NIO. pooledparallelsender "/> * </sender> * <interceptor classname =" org. apache. catalina. tribes. group. interceptors. tcpfailuredetector "/> * <interceptor classname =" org. apache. catalina. tribes. group. interceptors. messagedispatch15interceptor "/> * </channel> * <valve classname =" org. apache. catalina. ha. TCP. replicationvalve "filter =" "/> * <valve classname =" org. apach E. catalina. ha. session. jvmroutebindervalve "/> * <deployer classname =" org. apache. catalina. ha. deploy. farmwardeployer "* tempdir ="/tmp/war-temp/"* deploydir ="/tmp/war-deploy/"* watchdir ="/tmp/war-Listen/"* watchenabled = "false"/> * <clusterlistener classname = "org. apache. catalina. ha. session. jvmroutesessionidbinderlistener "/> * <clusterlistener classname =" org. apache. catalina. ha. session. clustersessionl Istener "/> * </cluster> * what we need to do is to explicitly add this default configuration and modify the above er port. Because we have three Tomcat nodes, therefore, this port is changed to 4003, 4300, and 4000 * is not changed to, because Tomcat officially recommends that the port range be between and ~ Between 4100 * prepare * The application prepares for the cluster * 1) the data stored in the session must be serialized * 2) in the Application Web. add the <distributable/> element * stri* * test cluster * to start Apache and three Tomcat servers. The test method is as follows (the test code is listed below) * 1) to access the test page, the sessionid is printed on the page ". tomcat2 ", which is added after the JSESSIONID mentioned above. jvmroute is a suffix that indicates that Tomcat 2 is processing this request * 2) refresh the test page and the printed sessionid does not change (the effect is significantly different from that after load balancing, see the http://blog.csdn.net/jadyer/article/details/39617801) * 3) Add a new attribute. after submitting the form, you will find that the newly added attribute name and attribute value are printed. Then, refresh the page and you will find that the added attribute still exists. * 4) the most critical step is, shut down the Tomcat 2 server, refresh the page, and you will find that the request is handled by "tomcat1", and the previously added attributes still exist .. at this point, the session is shared successfully, and the cluster is * successful * Note * 1) java.net. bindexception: cannot assign requested address; no faulty Members identified * The exception was reported when Tomcat was started. I guess it may be because Tomcat was installed in my VM, this attribute causes conflicts with the IP address of my host (ThinkPad notebook). * modify [Address = "Auto"] to [Address = "127.0.0.1"]. * 2) if the instance still fails to be started, or the instance is successfully started, but session sharing cannot be implemented, this may be due to a problem in multicast * because the cluster principle in Tomcat is to search nodes through multicast and use TCP connections for session replication, that is, Tomcat's session synchronization function requires multicast * you can use the [route add-net 224.0.0.0 netmask 240.0.0.0 Dev eth0] command to activate the Linux multicast service * If You Need To enable multicast when the server is started, add [eht0 net 224.0.0.0 netmask 240.0.0.0] * to the/etc/sysconfig/static-routes file. In addition, you can use the [netstat-G] or [route-E] command to view the multicast status * running * @ create Sep 27,201 4 7:59:32 * @ author Xuan Yu 


<% @ Page Language = "Java" pageencoding = "UTF-8" %> <% Out. println ("<br> session ID:" + session. GETID () + "<br>"); Session. setattribute ("myname", "session"); string dataname = request. getparameter ("dataname"); If (null! = Dataname & dataname. length ()> 0) {string datavalue = request. getparameter ("datavalue"); Session. setattribute (dataname, datavalue);} Out. print ("<B> session List </B> <br>"); Java. util. enumeration E = session. getattributenames (); While (E. hasmoreelements () {string name = (string) E. nextelement (); string value = session. getattribute (name ). tostring (); out. println (name + "=" + value + "<br>") ;}%> <form action = "demo. JSP "method =" Post "> attribute name: <input type = text size = 20 name =" dataname "> <br> attribute value: <input type = text size = 20 name = "datavalue"> <br> <input type = submit> </form>

Apache-2.2.29 and tomcat-6.0.41 clusters in CentOS-6.4-minimal

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.