Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Deploy Tomcat and its load balancer

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1.tomcat server is a free and open source Web application server, which is a lightweight application server. It is widely used in small and medium-sized systems and not many concurrent access users. It is the first choice for developing and debugging JSP programs. Generally speaking, although Tomcat is the same as Apache or Nginx, which is a web server, it has the function of dealing with HTML pages, but its ability to handle static HTML is far less than that of Apache or Nginx, so Tomcat usually runs on the back end as a Servlet and JPS container.

two。 JDK must be installed before Tomcat can be installed. JDK, whose full name is java Development Kit, is a free Java language software development kit provided by Sun, which includes java Virtual Machine (JVM). The written java source program can be compiled to form java bytecode. As long as you install JDK, you can use JVM to interpret these bytecode files, thus ensuring the cross-platform nature of java.

(1)。 Check to see if JDK is installed

Run the java-version command to see if java is installed. If not, you need to download and install it yourself.

(2) install and configure Tomcat

Extract the apachen-tomcat-8.5.16.tar.gz package

(2) generate an aoache-tomcat-8.5.16 folder after decompression, and move the folder to / usr/local/.

(3) start tomcat

(4) Open the browser access test: http://192.168.1.10:8080. If the interface shown in the figure appears, it means that tomcat has been started successfully.

Instructions for 3.Tomcat configuration

The home directory of tomcat is / usr/local/tomcat8/

(1) main catalogue description

(2) configuration file description

4.tomcat main profile description

5. Set up a web site for java

(1) create a web directory under the root directory, and create a webapp1 directory in it to store website files.

(2) create an index.jsp test page under the webapp1 directory

(3) modify the server.xml of tomcat

Define a virtual machine and point the path of the website file to the recently established / web/webapp1, and add the context segment to the host section.

(4) shut down tomcat and restart

(5) access http://192.168.1.10:8080/ through browser. The page shown in the figure indicates that the tomcat site has been successfully configured and is nearly ready to run JSP.

Case: Nginx+Tomcat load balancing cluster

1. In general, a tomcat site may have a single point of failure and can not cope with the complex and diverse requests of too many customers, so it can not be used in the production environment alone, so we need a more reliable solution to improve the web site architecture.

Nginx is a very excellent http server software, it can support up to 50000 concurrent connections response, has a strong static resource processing capacity, stable operation, and memory, cpu and other system consumption is very low. At present, many large websites use Nginx server as the reverse proxy and load balancing of back-end website programs to improve the load concurrency ability of the whole site.

(1) the topology of the website is shown in the figure.

two。 Case implementation

(1) tomcat2 server configuration

The tomcat server configuration method is basically the same as tomcat1, which includes:

(1) turn off the firewall

(2) confirm whether the installation of JDK,java version is consistent with tomcat1server

(3) install and configure tomcat, and the version is the same as tomcat1 server.

(4) create the / web/webapp1 directory, modify the tomcat configuration file server.xml, and change the website file directory to the / web/webapp1/ path.

(5) create an index.jsp under the / web/webapp1/ path. In order to distinguish the content of the test page index.jsp, change it as follows.

3.Nginx server configuration

Install nginx on nginx server 192.168.1.30, reverse proxy two tomcat sites, and achieve load balancing.

(1) turn off the firewall

(2) install relevant software packages

(3) decompress and install Nginx

(4) configure nginx.conf

Add the following code to http {.} to set the list of servers for load balancer. The weight parameter indicates the weight. The higher the weight, the greater the probability of being assigned. In order to make the test effect more obvious, we set the package weight to the same.

(5) Test whether the Nginx configuration file is correct.

(6) start the nginx service

(7) View the Nginx service process.

Finally, open the browser and access http://192.168.1.30.

Constantly refreshing the browser test, you can see that the page repeatedly switches back and forth between the following two pages because of the same weight. The first visit, what appears is the test1 test page, after refreshing, the second visit, what appears is the test2 test page. As shown in the following figure, this shows that the load balancing cluster has been built successfully.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report