Deploying a tomcat server for load Balancing

Source: Internet
Author: User

deploying Tomcat and load Balancing

Brief introduction:

Tomcat was originally made by Sun 's software architect James . Duncan . developed by Davidson, 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 develop and debug JSP programs, Tomcat is typically used as a Servlet and JSP container, running separately on the backend. It is primarily a Web server deployed as a Web site developed using the Java programming language .

The following is an experiment in a virtual machine to illustrate the use of Tomcat and to load balance the tomcat server

I. Deployment of TOMCAT

1) Install jdk(can be downloaded from Tomcat website)

the full name of the JDK is Java Developmentkit, a software Development Kit for the free Java language provided by Sun, which contains Java virtual machines ( JVM), well-written Java source programs compiled to form Java bytecode, as long as the jdk installed, you can use the JVM to interpret these bytecode files, so as to ensure the Java 's platform-crushing nature

Unzip the jdk* and move it to the/usr/local/and rename it to Java

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M02/8B/A4/wKioL1hTwFGBC00SAAA9G0Rfwe8019.jpg "style=" float: none; "title=" image001.jpg "alt=" Wkiol1htwfgbc00saaa9g0rfwe8019.jpg "/>

3) build on java.sh script

vim/etc/profile.d/java.sh

The contents are as follows:

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M01/8B/A7/wKiom1hTwFHBtFS-AAAQtGkXoJ8306.jpg "style=" float: none; "title=" image002.jpg "alt=" Wkiom1htwfhbtfs-aaaqtgkxoj8306.jpg "/>

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

Java-version can view the Java version

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M00/8B/A7/wKiom1hTwFGBVQzeAAAobELIGgY123.jpg "style=" float: none; "title=" image003.jpg "alt=" Wkiom1htwfgbvqzeaaaobeliggy123.jpg "/>

The Java environment is now configured.

2. Installation configuration Tomcat

1) Unpack the Apache-tomcat package

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M01/8B/A4/wKioL1hTwFLyRpqYAAAtijExw7g548.jpg "style=" float: none; "title=" image004.jpg "alt=" Wkiol1htwflyrpqyaaatijexw7g548.jpg "/>

after unpacking, move this folder to /usr/local/ , and change the name to TOMCAT7

MV APACHE-TOMCAT-7.0.54/USR/LOCAL/TOMCAT7

2) start Tomcat

/usr/local/tomcat7/bin/startup.sh

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M02/8B/A7/wKiom1hTwFLwpKnmAAA1hUJDqvY793.jpg "style=" float: none; "title=" image005.jpg "alt=" Wkiom1htwflwpknmaaa1hujdqvy793.jpg "/>

the default port for the Tomcat Web server is 8080.

If you are shutting down the Tomcat server's firewall, open the 8080 port exception, allowing access to the

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M00/8B/A4/wKioL1hTwFKwja6mAAAPIrXMjPY886.jpg "style=" float: none; "title=" image006.jpg "alt=" Wkiol1htwfkwja6maaapirxmjpy886.jpg "/>

2) test access http://192.168.1.10:8080 on the browser

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M01/8B/A7/wKiom1hTwFOQJfMCAACyEr65j7w968.jpg "style=" float: none; "title=" image007.jpg "alt=" Wkiom1htwfoqjfmcaacyer65j7w968.jpg "/>

See the above page description successfully launched Tomcat

Close Tomcatand run the /usr/local/tomcat7/bin/shutdown.sh command.

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://s1.51cto.com/wyfs02/M02/8B/A4/wKioL1hTwFPTaFojAAAXgabgOBk033.jpg "style=" float: none; "title=" image008.jpg "alt=" Wkiol1htwfptafojaaaxgabgobk033.jpg "/>

1) set up the index.jsp test page

vi/web/webapp1/index.jsp

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M01/8B/A4/wKioL1hTwFPgru_tAAAK9J_dfhU170.jpg "style=" float: none; "title=" image009.jpg "alt=" Wkiol1htwfpgru_taaak9j_dfhu170.jpg "/>

1) Modify Tomcat 's server.xml file

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

Add the following content to the host area

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M02/8B/A7/wKiom1hTwFSSw0xpAABm-nKxuBA956.jpg "style=" float: none; "title=" image010.jpg "alt=" Wkiom1htwfssw0xpaabm-nkxuba956.jpg "/>

1) Close the Tomcat service before booting

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M00/8B/A7/wKiom1hTwFSS5vXWAABLhqhjv9s452.jpg "style=" float: none; "title=" image011.jpg "alt=" Wkiom1htwfss5vxwaablhqhjv9s452.jpg "/>

1) Browse the Web http://localhost:8080

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M00/8B/A4/wKioL1hTwFXSW_n5AAA_iYv3L3s060.jpg "style=" float: none; "title=" image012.jpg "alt=" Wkiol1htwfxsw_n5aaa_iyv3l3s060.jpg "/>

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

Tomcat Configuration Related Instructions

Tomcat the home directory for/USR/LOCAL/TOMCAT7

------bin/ script file to start and close Tomcat on a Windows or Linux platform

------conf/ A variety of global configuration files for the Tomcat server, the most important of which is the Server.xml file

----lib/ library Files (JARS) to store tomcat operations

----logs/ log file for tomcat execution

---webapps tomcat main Web publishing directory (including application examples)

--- work store the class file generated by the JSP compilation

Configuration file Description

configuration file is located under, usr/local/tomcat7/conf/

Catalina.policy Rights Control Profiles

catalina.properties Tomcat Attribute Profile

context.xml Context configuration file

logging.properties log logs related configuration file

Server.xml Master configuration file

Tomcat-users.xml:manager-gui Manage user Profiles (Tomcat installation provides a Manager-gui management interface that allows access to be enabled via the file configuration)

Web. XML : Tomcat's servlet.servlet-mapping filter MIME and other related configurations.

Second, build nginx+tomcat load Balancing cluster

Topology diagram:


650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M01/8B/A7/wKiom1hTwFWAOGJFAAAmfKKqouI644.jpg "style=" float: none; "title=" image013.jpg "alt=" Wkiom1htwfwaogjfaaamfkkqoui644.jpg "/>

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M02/8B/A4/wKioL1hTwFXxL6ocAAArZQ4Sydc021.jpg "style=" float: none; "title=" image014.jpg "alt=" Wkiol1htwfxxl6ocaaarzq4sydc021.jpg "/>

1. Build Tomcat

TOMCAT1 We have been set up in the above, the following began to build tomcat2(Installation method and the first is exactly the same, here is no longer explained, but in order to distinguish between different servers, the second page of the modified content , I have been set up, As shown in the actual work, the pages of the two Tomcat servers are consistent!!

Note:tomcat firewall 8080 port to open exception

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M00/8B/A7/wKiom1hTwFXDTWb7AAAKx4m8U_k029.jpg "style=" float: none; "title=" image015.jpg "alt=" Wkiom1htwfxdtwb7aaakx4m8u_k029.jpg "/>

1. Build and configure nginx server

1) Insert the System CD, configure a yum repository, and install the following related packages

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M01/8B/A4/wKioL1hTwFawz3VdAAAqGqWBato828.jpg "style=" float: none; "title=" image016.jpg "alt=" Wkiol1htwfawz3vdaaaqgqwbato828.jpg "/>

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M02/8B/A7/wKiom1hTwFaRudB8AAAKySC1vP0371.jpg "style=" float: none; "title=" image017.jpg "alt=" Wkiom1htwfarudb8aaakysc1vp0371.jpg "/>

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

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M02/8B/A4/wKioL1hTwFaTj7jJAAASCKdCuPc978.jpg "style=" float: none; "title=" image018.jpg "alt=" Wkiol1htwfatj7jjaaasckdcupc978.jpg "/>

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M00/8B/A7/wKiom1hTwFbwYe6vAAAlWdrlAGc466.jpg "style=" float: none; "title=" image019.jpg "alt=" Wkiom1htwfbwye6vaaalwdrlagc466.jpg "/>

then execute make && make install

Comments:

--user=,--group= Specify which users and groups to run

--with-file-aio Enable file modification support

--with-http_stub_status_module enable State connections

--with-http_gzip_static_module enabling gzip static compression

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

--with-http_ssl_module enable SSL module

3) Modify nginx configuration file, add the following content

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M00/8B/A4/wKioL1hTwFfAIieGAAAMKolaoQE059.jpg "style=" float: none; "title=" image020.jpg "alt=" Wkiol1htwffaiiegaaamkolaoqe059.jpg "/>

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

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M00/8B/A4/wKioL1hTwFfwkrzkAAA62kqeA_c902.jpg "style=" float: none; "title=" image021.jpg "alt=" Wkiol1htwffwkrzkaaa62kqea_c902.jpg "/>

Weight parameter represents weights, the greater the weight is allocated to the probability of greater, in order to make the test effect is more obvious, so I set the weight of the same! General performance of the server, the weight of a larger number.

and then in http{...} inside the server{...} inside the location{...} add a row to the

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M01/8B/A7/wKiom1hTwFfRek9TAAAnjGSsHg4223.jpg "style=" float: none; "title=" image022.jpg "alt=" Wkiom1htwffrek9taaanjgsshg4223.jpg "/>

the default site of Nginx is proxied to the set of tomcat_server load Balancer Server group by Proxy_pass method.

3) test The nginx configuration file is correct

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

The following message appears to indicate correct

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M01/8B/A4/wKioL1hTwFjAaMh7AAAdoeYLkb4610.jpg "style=" float: none; "title=" image023.jpg "alt=" Wkiol1htwfjaamh7aaadoeylkb4610.jpg "/>

3) start nginx service

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M01/8B/A7/wKiom1hTwFnAG6J_AABCUgm4IqM790.jpg "style=" float: none; "title=" image024.jpg "alt=" Wkiom1htwfnag6j_aabcugm4iqm790.jpg "/>

3. Test Load Balancing effect

1) Open browser access http://192.168.1.102(Access nginx server)

2) Nginx Server open Port exception

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

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M02/8B/A7/wKiom1hTwFnQjfzuAAAdvQFjB1w108.jpg "style=" float: none; "title=" image025.jpg "alt=" Wkiom1htwfnqjfzuaaadvqfjb1w108.jpg "/>

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M01/8B/A4/wKioL1hTwFnBBKwqAAAcsrtBThg788.jpg "style=" float: none; "title=" image026.jpg "alt=" Wkiol1htwfnbbkwqaaacsrtbthg788.jpg "/>


This article from "Keep Keep your" blog, reproduced please contact the author!

Deploying a tomcat server for load Balancing

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.