Nginx+tomcat Load Balancing cluster

Source: Internet
Author: User
Tags nginx server

3rd: Deploying Tomcat and its load balancer (case)

Security code: Must be with loneliness before success!

Tomcat Application Scenario:

Tomcat server is a free open source Web application server, belongs to the lightweight application server, in small and medium-sized systems and concurrent access users are not a lot of occasions are widely used, is the first choice to start and debug JSP programs. But because of its ability to handle static HTML far less than Apache or Nginx, Tomcat is typically used as a servlet and JSP container, running on the back end alone.

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/89/33/wKioL1gMJkGjv_8lAABiJ-B-pL0242.png-wh_500x0-wm_3 -wmp_4-s_4255631776.png "title=" N40) 6 ' 9mg{r8xf5{h42 ' @K8. png "alt=" wkiol1gmjkgjv_8laabij-b-pl0242.png-wh_50 "/>

I. Deployment of TOMCAT

1. Install the JDK, configure the Java environment

1) Install JDK, build java.sh script

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/89/35/wKiom1gMO6fBZF_iAABvqwwQnyo107.png-wh_500x0-wm_3 -wmp_4-s_4127140401.png "title=" 1.png "alt=" Wkiom1gmo6fbzf_iaabvqwwqnyo107.png-wh_50 "/>

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/89/33/wKioL1gMPFyhs7mNAAAm2QzjB8E505.png-wh_500x0-wm_3 -wmp_4-s_168848267.png "title=" 2.png "alt=" Wkiol1gmpfyhs7mnaaam2qzjb8e505.png-wh_50 "/>

2) Import the java.sh script into the environment variable

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/89/35/wKiom1gMPJOCrWMPAAA3QDJpZCs148.png-wh_500x0-wm_3 -wmp_4-s_3398666217.png "title=" 3.png "alt=" Wkiom1gmpjocrwmpaaa3qdjpzcs148.png-wh_50 "/>

2. Configuring Tomcat

1) Start Tomcat

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/89/33/wKioL1gMPNDxDy5zAABJmavAsog165.png-wh_500x0-wm_3 -wmp_4-s_996699496.png "title=" 4.png "alt=" Wkiol1gmpndxdy5zaabjmavasog165.png-wh_50 "/>

2) test http://192.168.1.1:8080 on the browser

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/89/35/wKiom1gMPV2DbLW-AADxDd6OCjE048.png-wh_500x0-wm_3 -wmp_4-s_1406336317.png "title=" 5.png "alt=" Wkiom1gmpv2dblw-aadxdd6ocje048.png-wh_50 "/>

See the above page description successfully launched Tomcat

3. Build a Java Web site

1) Create a web directory and create a WEBAPP1 directory inside it to store the Web site files.

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/89/33/wKioL1gMPgjxnggeAAAqVFjgBSo698.png-wh_500x0-wm_3 -wmp_4-s_2239072879.png "title=" 6.png "alt=" Wkiol1gmpgjxnggeaaaqvfjgbso698.png-wh_50 "/>

2) Set up the INDEX.JSP test page

vim/web/webapp1/index.jsp

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/89/33/wKioL1gMPqnCxYsbAAA8hdIWvsY780.png-wh_500x0-wm_3 -wmp_4-s_907991026.png "title=" 7.png "alt=" Wkiol1gmpqncxysbaaa8hdiwvsy780.png-wh_50 "/>

3) Modify Tomcat's Server.xml file

Vim/usr/local/tomcat7/conf/server.xml

Add content to the host area (126-127 lines)

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/89/36/wKiom1gMPzCQQiZDAABZv6VdlVY398.png-wh_500x0-wm_3 -wmp_4-s_640824646.png "title=" 8.png "alt=" Wkiom1gmpzcqqizdaabzv6vdlvy398.png-wh_50 "/>

4) Restart the Tomcat service

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/89/33/wKioL1gMP2mgTXfgAABYI7XvYWw095.png-wh_500x0-wm_3 -wmp_4-s_198977259.png "title=" 9.png "alt=" Wkiol1gmp2mgtxfgaabyi7xvyww095.png-wh_50 "/>

5) Browse the Web http://192.168.1.1:8080

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/89/36/wKiom1gMP7nRjGySAAAoz_X0Sow087.png-wh_500x0-wm_3 -wmp_4-s_2225852464.png "title=" 10.png "alt=" Wkiom1gmp7nrjgysaaaoz_x0sow087.png-wh_50 "/>

The Web page you made above shows that the Tomcat site is successfully configured to run the JSP Web page.


Second, build Nginx+tomcat load Balancing cluster

Topology diagram:

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/89/33/wKioL1gMJkGjv_8lAABiJ-B-pL0242.png-wh_500x0-wm_3 -wmp_4-s_4255631776.png "title=" N40) 6 ' 9mg{r8xf5{h42 ' @K8. png "alt=" wkiol1gmjkgjv_8laabij-b-pl0242.png-wh_50 "/>

1. Build Tomcat

TOMCAT1 above has been set up, Tomcat2 construction method and Tomcat1 construction method, here is no longer explained. It should be noted that the TOMCAT2 Web page content to www.test2.com, the following is built.

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/89/36/wKiom1gMQSuyL9idAAAmiDE6ZbY977.png-wh_500x0-wm_3 -wmp_4-s_3945579011.png "title=" 11.png "alt=" Wkiom1gmqsuyl9idaaamide6zby977.png-wh_50 "/>

2. Build and configure Nginx server

1) Insert the CentOS CD, configure a Yum repository, and install the related packages below.

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/89/33/wKioL1gMQbqyjRKNAAAwqEHtor8350.png-wh_500x0-wm_3 -wmp_4-s_1233697403.png "title=" 1.2.png "alt=" Wkiol1gmqbqyjrknaaawqehtor8350.png-wh_50 "/>

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/89/36/wKiom1gMQdHTtJ_UAAAlrNWNywM875.png-wh_500x0-wm_3 -wmp_4-s_129298108.png "title=" 1.3.png "alt=" wkiom1gmqdhttj_uaaalrnwnywm875.png-wh_50 "/>650) this.width=650;" Src= "http://s2.51cto.com/wyfs02/M01/89/36/wKiom1gMQebAjO9CAAApgTmfSAU936.png-wh_500x0-wm_3-wmp_4-s_3209700313. PNG "title=" 13.png "alt=" Wkiom1gmqebajo9caaapgtmfsau936.png-wh_50 "/>

2) Set up users and groups, compile and install Nginx

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/89/36/wKiom1gMQjCxJ9EPAAAtENdHgNc043.png-wh_500x0-wm_3 -wmp_4-s_820435540.png "title=" 14.png "alt=" Wkiom1gmqjcxj9epaaatendhgnc043.png-wh_50 "/>

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/89/36/wKiom1gMQ3WwChtkAABTlDi1nAA432.png-wh_500x0-wm_3 -wmp_4-s_1000823410.png "title=" 9~]$1~x) 4cwxd15bh}ivuib.png "alt=" Wkiom1gmq3wwchtkaabtldi1naa432.png-wh_50 "/>

3) Modify Nginx configuration file, add content

First in http{...} Add the following code to set the server list for load balancing.

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/89/33/wKioL1gMQ_qSRnWEAAA-FyqAbsI176.png-wh_500x0-wm_3 -wmp_4-s_289964579.png "title=" 16.png "alt=" Wkiol1gmq_qsrnweaaa-fyqabsi176.png-wh_50 "/>

And then in http{...} Inside the server{...} Inside the location{...} Add a row to the

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/89/36/wKiom1gMUdTwvZSnAAAvSMLVHek964.png-wh_500x0-wm_3 -wmp_4-s_3131878665.png "title=" 17.png "alt=" Wkiom1gmudtwvzsnaaavsmlvhek964.png-wh_50 "/>

4) test the Nginx configuration file is correct

Executive/usr/local/nginx/sbin/nginx-t

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/89/33/wKioL1gMUlvD-WtKAAAzc9piu4s701.png-wh_500x0-wm_3 -wmp_4-s_950094376.png "title=" 4e[tiher94bkqdgbt[82}io.png "alt=" Wkiol1gmulvd-wtkaaazc9piu4s701.png-wh_50 "/>

5) Start Nginx Service

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/89/33/wKioL1gMUvHza9YhAABLwIpqAMs647.png-wh_500x0-wm_3 -wmp_4-s_3915942989.png "title=" X1txkeegnq[jl) (I (2{@r{0.png "alt=" Wkiol1gmuvhza9yhaablwipqams647.png-wh_50 "/>

3. Test Load Balancing effect

Warm tip: First in Tomcat1, TOMCAT2, Nginx server to do the relevant firewall rules allow access to the site, as shown:

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/89/33/wKioL1gMU_agS-K-AAAybLZA_tk894.png-wh_500x0-wm_3 -wmp_4-s_466499881.png "title=" 63e_c[' _44)}[[k) $6c (~mf.png "alt=" Wkiol1gmu_ags-k-aaayblza_tk894.png-wh_50 "/>

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/89/33/wKioL1gMVAvBqsk5AAAxbdIumfA203.png-wh_500x0-wm_3 -wmp_4-s_3534841578.png "title="}bks00va5h3ovfo8 (2rjtsl.png "alt=" Wkiol1gmvavbqsk5aaaxbdiumfa203.png-wh_50 "/>

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M01/89/33/wKioL1gMVH3SgANUAAApXbuNpPU576.png-wh_500x0-wm_3 -wmp_4-s_1115544213.png "title=" rx9$car_l] @Z5TDQN @kr ' 9b.png "alt=" Wkiol1gmvh3sganuaaapxbunppu576.png-wh_50 "/>

And then the subsequent operation

1) Open browser access http://192.168.1.3

2) constantly refresh the browser test, you can see that due to the same weight, the page will be repeated in the following two pages to switch back and forth, indicating that the load Balancing cluster build successfully.

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/89/33/wKioL1gMVS6xSPMXAABNmdO183s110.png-wh_500x0-wm_3 -wmp_4-s_3968823727.png "title="}hto$z4 ' @19gb216b ' go$m1.png "alt=" Wkiol1gmvs6xspmxaabnmdo183s110.png-wh_50 "/>

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/89/36/wKiom1gMVTyDaLy6AABO9XZXMsY899.png-wh_500x0-wm_3 -wmp_4-s_589634633.png "title=" _KXA3O]QR)%n_rq7}e89%m0.png "alt=" Wkiom1gmvtydaly6aabo9xzxmsy899.png-wh_50 "/>

Thank you for your visit, sincerely hope to help you.


This article from "Hello Sunshine" blog, declined reprint!

Nginx+tomcat Load Balancing cluster

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.