1. Tomcat Load Balancing (implemented by apache mod_jk ):
2.
3. 1. Implementation Based on Apache mod_jk:
4. apache
5 ./\
6. tom1 tom2
7.
8. after installing the tomcat1 and tomcat2 servers, you want to achieve load balancing and use mod_jk to restore the node from failure. That is, if a node has a problem, mod_jk will not participate in the load, after a node is recovered from failure, mod_jk will involve it in the load. Whether the node fails or not is transparent to users.
9.
10. implementation process:
11. a. Apache immediately responds to the static content when the data accessed by the user reaches Apache;
12. B. If Apache finds that the user requests dynamic content such as jsp, it will throw the request to one of tomcat for processing.
13. c. Each time a user repeatedly accesses the server, the server is allocated to the same machine (Session sticking or session replication can be performed)
14.
15. In this article, a new server (Server Load balancer) is added based on the previous environment. In fact, the Server Load balancer is mainly handled by a configuration file! That is workers. propertise. By defining worker. the values of list, port, host, type, and lbfactor are used to define each tomcat host. lbfactor is used to distinguish the weights of each machine, the larger the weight value, the more user requests are obtained. Therefore, you only need to focus on the content of this file.
16.
17. Implementation:
18. a. Install Aapche
19. # tar-xzf httpd-2.2.22.tar.gz
20. # chown root. root-R httpd-2.2.22
21. # cd httpd-2.2.22
22. #./configure -- prefix =/usr/local/apache
23. # make & make install
24.
25. B. Compile the mod_jk Module
26.
27. # tar-xzf tomcat-connectors-1.2.32-src.tar.gz
28. # cd tomcat-connectors-1.2.32-src
29. # cd native/
30. #./configure -- with-apxs =/usr/local/apache/bin/apxs
31. # make & make install
32. # ll/usr/local/apache/modules/mod_jk.so
33.-rwxr-xr-x 1 root 1076923 Feb 20/usr/local/apache/modules/mod_jk.so
34.
35. c. Load mod_jk
36. # vim/usr/local/apache/conf/httpd. conf
37. # added content
38. LoadModule jk_module modules/mod_jk.so
39. JkWorkersFile/usr/local/apache/conf/workers. properties
40. JkMountFile/usr/local/apache/conf/uriworkermap. properties
41. JkLogFile/usr/local/apache/logs/mod_jk.log
42. JkLogLevel info
43. JkLogStampformat "[% a % B % d % H: % M: % S % Y]"
44.
45. # Tell apache how to deal with related class-shaped files (these lines are optional, as long as there are definitions in urlworkermap. properties! :)
46. JkMount/* controller
47. JkMount/*. jsp controller
48. JkMount/*. action controller
49.
50.
51. # cat/usr/local/apache/conf/workers. properties
52. # cat workers. properties
53. worker. list = controller
54. #========= export AT1 =========
55. worker. tomcat1.port = 8009
56. worker. tomcat1.host = 192.168.10.56
57. worker. tomcat1.type = ajp13
58. worker. tomcat1.lbfactor = 1
59. worker. tomcat12.connection _ pool_timeout = 750
60. worker. atat12.socket _ keepalive = 0
61. worker. worker at12.socket _ timeout = 3000
62. worker. worker at12.connect _ timeout = 1000
63. worker. tomcat12.reply _ timeout = 3300
64.
65. #========= tomcat2 ========
66. worker. tomcat2.port = 8009
67. worker. tomcat2.host = 192.168.10.57
68. worker. tomcat2.type = ajp13
69. worker. tomcat2.lbfactor = 1
70. worker. tomcat12.connection _ pool_timeout = 750
71. worker. atat12.socket _ keepalive = 0
72. worker. atat12.socket _ timeout = 3000
73. worker. worker at12.connect _ timeout = 1000
74. worker. tomcat12.reply _ timeout = 3300
75.
76. # ======= balance controller ====
77. worker. controller. type = lb
78. worker. retries = 3
79. worker. controller. balance_workers = worker at1, tomcat2
80. worker. controller. sticky_session = 1
81.
82. related parameter descriptions:
83. worker. tomcat12.socket _ keepalive = 0 # This attribute tells the operating system to send the KEEP_ALIVE information in an inactive connection (the sending interval depends on the operating system settings, generally 120 seconds ), this will prevent the firewall from discontinuing the inactive network connection.
84. worker. tomcat12.socket _ timeout = 300000 # This attribute indicates how long the connection lasts without being activated, and the web server will take the initiative to cut it off.
85. worker. tomcat12.connect _ timeout = 10000 # This attribute specifies the time (in ms) when the web server waits for PONG to respond ).
86. worker. tomcat12.reply _ timeout = 330000 # This attribute tells the web server to wait for a while before it receives a remote Tomcat response and switches to another Tomcat in the cluster in real time.
87. worker. tomcat12.reply _ timeout = 0 # This attribute describes how the web server recovers after detecting Tomcat failure (0 by default, all are restored)
88.
89. worker. loadbalancer. sticky_session = 0 # indicates whether to route requests for SESSION IDs back to the same Tomcat worker. (The default value is 0, and the session is not copied)
90.
91.
92. # cat uriworkermap. properties
93./* = controller
94 .! /*. Jpg = controller
95 .! /*. Gif = controller
96 .! /*. Png = controller
97 .! /*. Bmp = controller
98 .! /*. Html = controller
99 .! /*. Htm = controller
100 .! /*. Swf = controller
101 .! /*. Css = controller
102 .! /*. Js = controller
103.
104. After completing all the above, you will find that the two tomcat servers are indeed loaded, but a new problem arises and the session problem occurs. The first and second submissions are not on the same server, which is basically considered as data loss.
105. If you only browse, the problem may not be obvious. Of course, if you log on, the system will prompt you to log on. So we have tomcat session replication!
106. Currently, there are two common methods for tomcat session replication: Use the simple cluster function of tomcat to help copy sessions. The other is to use memcache and other caching programs to cache sessions.
107.
108. Today is of course the first method of choice. Use the simple functions of tomcat for session replication. For more information, see the next article! :)
This article is from the "diving into the ocean of technology" blog