Tomcat+nginx Load Balancing cluster

Source: Internet
Author: User
Tags nginx load balancing


on-line environment Nginx+tomcat Web site Topology Architecture


650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M01/96/9A/wKiom1kjs5rC7BOpAACjlhWR-X4146.png-wh_500x0-wm_ 3-wmp_4-s_3928651220.png "title=" 1.png "style=" Float:left; alt= "Wkiom1kjs5rc7bopaacjlhwr-x4146.png-wh_50"/>













Server Software Requirements:

Host

IP Address

192.168.1.102

style= font-size:14px nginx-1.6.0.tar.gz

Tomcat1

192.168.1.100

style= font-size:14px jdk-7u65-linux-x64.gz

2.apache-tomcat-7.0.54.tar.gz

Tomcat2

192.168.1.101

1.jdk-7u65-linux-x64.gz

2.apache-tomcat-7.0.54.tar.gz


Install and configure the Java Environment:

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M00/96/99/wKiom1kjsTuy-9KTAAAPruUpq_k884.png-wh_500x0-wm_ 3-wmp_4-s_655143905.png "title=" qq picture 20170523114402.png "style=" Float:none; "alt=" wkiom1kjstuy-9ktaaapruupq_ K884.png-wh_50 "/>


650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M02/96/99/wKiom1kjsTqwYAZqAAAEPstrqrQ698.png-wh_500x0-wm_ 3-wmp_4-s_1222957264.png "title=" qq picture 20170523114355.png "style=" Float:none; "alt=" Wkiom1kjstqwyazqaaaepstrqrq698.png-wh_50 "/>


650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M02/96/9A/wKioL1kjsTrCY1NlAAAHDJPjpzc587.png-wh_500x0-wm_ 3-wmp_4-s_593137851.png "title=" qq picture 20170523114358.png "style=" Float:none; "alt=" Wkiol1kjstrcy1nlaaahdjpjpzc587.png-wh_50 "/>// import java script into environment variable and make it take effect

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M02/96/99/wKiom1kjsTng7MOJAAAKV_u8PNQ250.png-wh_500x0-wm_ 3-wmp_4-s_982034007.png "title=" qq picture 20170523114351.png "style=" Float:none; "alt=" wkiom1kjstng7mojaaakv_ U8pnq250.png-wh_50 "/>


Check the installation version

4. Install the configuration Tomcat:

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/96/9A/wKioL1kjsTnBeBNNAAAHfMO2POE036.png-wh_500x0-wm_ 3-wmp_4-s_3343875893.png "title=" qq picture 20170523114344.png "style=" Float:none; "alt=" Wkiol1kjstnbebnnaaahfmo2poe036.png-wh_50 "/>


// decompression file and generate apache-tomcat-7.0.54 , move to a common /usr/local under and renamed to TOMCAT7,

Start the service, check the listening port

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/96/99/wKiom1kjsTmRbdL2AAAVRwq1MjY188.png-wh_500x0-wm_ 3-wmp_4-s_3213081637.png "title=" qq picture 20170523114318.png "style=" Float:none; "alt=" Wkiom1kjstmrbdl2aaavrwq1mjy188.png-wh_50 "/>


5. set up a Java web site:

( 1 "first create web catalog   ( 2 index.jsp

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M00/96/9A/wKioL1kjsTigu2QsAAAG5KWeYVA974.png-wh_500x0-wm_ 3-wmp_4-s_3288327736.png "title=" qq picture 20170523114307.png "style=" Float:none; "alt=" Wkiol1kjstigu2qsaaag5kweyva974.png-wh_50 "/>


Enter the tomcat configuration file,/usr/local/tomcat7/conf/server.vml

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M01/96/9A/wKioL1kjsTizakFVAAAQkYhsDj0286.png-wh_500x0-wm_ 3-wmp_4-s_1002861425.png "title=" qq picture 20170523114310.png "style=" Float:none; "alt=" Wkiol1kjstizakfvaaaqkyhsdj0286.png-wh_50 "/>

(3) modify Tomcat 's server.xml file:

define a host, the domain name is localhost,appBase define the application base directory,Unpackwars define whether to extract automatically,autodeploy Define whether to deploy automatically

<contextdocbase= "/web/webapp1" path= "" reloadable= "false" >

</Context>

Description:The context defines the virtual host,path Specifies the directory to access,docBase defines the page directory, and when the application changes, automatically mounts without restarting Tomcat

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M01/96/99/wKiom1kjsTijuMNSAAAH0tzmlPI745.png-wh_500x0-wm_ 3-wmp_4-s_1793806663.png "style=" Float:none; "title=" QQ picture 20170523114304.png "alt=" Wkiom1kjstijumnsaaah0tzmlpi745.png-wh_50 "/>

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M00/96/9A/wKioL1kjsTfjYUWGAAAHm8KgJ2c441.png-wh_500x0-wm_ 3-wmp_4-s_332029527.png "title=" qq picture 20170523114301.png "style=" Float:none; "alt=" Wkiol1kjstfjyuwgaaahm8kgj2c441.png-wh_50 "/>


( 4 ) Restart the service TOMCAT2 Server Ibid .

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M00/96/99/wKiom1kjsTeQ2gzRAAAZD8scCxI598.png-wh_500x0-wm_ 3-wmp_4-s_2327374676.png "title=" qq picture 20170523114257.png "style=" Float:none; "alt=" Wkiom1kjsteq2gzraaazd8sccxi598.png-wh_50 "/>

6.nginx Server configuration:

Nginx configuration for reverse proxy and load balancing

(i) Installation of Nginx

1. Install the relevant package

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M01/96/99/wKiom1kjsTygJhSeAAAcv3xroU8829.png-wh_500x0-wm_ 3-wmp_4-s_1632823985.png "title=" qq picture 20170523114412.png "style=" Float:none; "alt=" Wkiom1kjstygjhseaaacv3xrou8829.png-wh_50 "/>


2. Create program users and Groups

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M02/96/9A/wKioL1kjsTvRdUpqAAAFebfntpA449.png-wh_500x0-wm_ 3-wmp_4-s_335399758.png "title=" qq picture 20170523114409.png "style=" Float:none; "alt=" Wkiol1kjstvrdupqaaafebfntpa449.png-wh_50 "/>


3. Installing nginx

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M00/96/9A/wKioL1kjsTuhzp8_AAALQntEhu8410.png-wh_500x0-wm_ 3-wmp_4-s_2112571095.png "title=" qq picture 20170523114405.png "style=" Float:none; "alt=" wkiol1kjstuhzp8_ Aaalqntehu8410.png-wh_50 "/>

--with-user,--with-group Specify users and Groups

--with-file-aio Enable file modification support

--with-http_stub_status_module Enable status statistics

-with-http_gzip_static_module enabling gzip static compression

Ith-http_flv_module enable flv module, providing time-based offset files seeking memory usage

//--with-http_ssl_module enabled SSL Module


(ii), configuration Nginx

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M00/96/99/wKiom1kjsTeDiYmKAAALvYWJDhs201.png-wh_500x0-wm_ 3-wmp_4-s_1339930152.png "title=" qq picture 20170523114240.png "style=" Float:none; "alt=" Wkiom1kjstediymkaaalvywjdhs201.png-wh_50 "/>

HTTP {

........

Upstream Tomcat_server {

Server 192.168.1.2:8080 weight=1;

Server 192.168.1.3:8080 weight=1;

}// Set the server list for load balancing,the weight parameter represents the permission, the higher the weight value, the greater the probability of being divided.

server {

Listen 80;

server_name localhost;

#charset Koi8-r;

#access_log Logs/host.access.log Main;

Location/{

root HTML;

Index index.html index.htm;

Proxy_pass Http://tomcat_server; Implementing a reverse proxy

}

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M02/96/9A/wKioL1kjsTaRGs-hAAAZ08izz1E727.png-wh_500x0-wm_ 3-wmp_4-s_783370417.png "title=" qq picture 20170523114234.png "style=" Float:none; "alt=" Wkiol1kjstargs-haaaz08izz1e727.png-wh_50 "/>

(c), start Nginx Process


/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.conf


Five . internal test reverse proxy and load balancing test

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M02/96/9A/wKioL1kjsTaTMNY-AAAaeP2mxv0812.png-wh_500x0-wm_ 3-wmp_4-s_2691910173.png "title=" qq picture 20170523114217.png "style=" Float:none; "alt=" Wkiol1kjstatmny-aaaaep2mxv0812.png-wh_50 "/>



650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M02/96/99/wKiom1kjsTWzTm4OAABfjwREehQ589.jpg-wh_500x0-wm_ 3-wmp_4-s_1498846358.jpg "title=" qq picture 20170523114136.jpg "style=" Float:none; "alt=" Wkiom1kjstwztm4oaabfjwreehq589.jpg-wh_50 "/>

Tomcat+nginx 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.