What this article brings to you is what is a tomcat cluster? Introduction to tomcat cluster. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
What is a tomcat cluster?
Use nginx to offload requests and assign them to different tomcats for processing, reducing the load of each tomcat and improving the response speed of the server.
Goal
Achieve high-performance load balancing tomcat cluster.
Tools
nginx-1.13.10
apache-tomcat-7.0.81
Implementation steps
1. Download nginx.
2. Unzip two tomcats and name them apache-tomcat-7.0.81-1 and apache-tomcat-7.0.81-2 respectively.
3. Modify the two tomcat startup ports to 8080 and 8181 respectively.
4. Modify the two tomcat default index.jsp pages to distinguish different tomcats.
5. Start two tomcats at the same time and access the test.
6. Configure nginx and open nginx-1.13.10/conf/nginx.conf.
Configure the following:
worker_processes 1; #工作進程的個數(shù),一般與計算機的cpu核數(shù)一致 events { worker_connections 1024; #單個進程最大連接數(shù)(最大連接數(shù)=連接數(shù)*進程數(shù)) } http { include mime.types; #文件擴展名與文件類型映射表 default_type application/octet-stream; #默認(rèn)文件類型 sendfile on; #開啟高效文件傳輸模式,普通應(yīng)用設(shè)為 on,如果用來進行下載等應(yīng)用磁盤IO重負(fù)載應(yīng)用,可設(shè)置為off。 keepalive_timeout 65; #長連接超時時間,單位是秒 gzip on; #啟用Gizp壓縮 #tomcat集群 upstream myapp { #tomcat集群名稱 server localhost:8080; #tomcat1配置 server localhost:8181; #tomcat2配置 } #nginx的配置 server { listen 9090; #監(jiān)聽端口,默認(rèn)80 server_name localhost; #當(dāng)前nginx域名 location / { proxy_pass http://myapp; proxy_redirect default; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
Core configuration:
7.dos command to start nginx.
8. To test, visit http://localhost:9090.
So far, we have implemented a load-balanced tomcat cluster using nginx.
nginx load balancing strategy:
1. Polling (default)
Each request is assigned to a different backend server one by one in chronological order , if the backend server goes down, it can be automatically eliminated.
upstream backserver { server 192.168.0.14; server 192.168.0.15; }
2. Specify the weight
Specify the polling probability. The weight is proportional to the access ratio and is used when the performance of the back-end server is uneven.
upstream backserver { server 192.168.0.14 weight=10; server 192.168.0.15 weight=10; }
3. IP binding ip_hash
Each request is assigned according to the hash result of the accessed IP, so that each visitor has fixed access to a back-end server, which can solve the session problem.
upstream backserver { ip_hash; server 192.168.0.14:88; server 192.168.0.15:80; }
4. fair (third party)
Requests are allocated according to the response time of the backend server, and those with short response times are allocated first.
upstream backserver { server server1; server server2; fair; }
5. url_hash (third party)
Distribute requests according to the hash result of the accessed URL, so that each URL is directed to the same back-end server. It is more effective when the back-end server is cached. .
upstream backserver { server squid1:3128; server squid2:3128; hash $request_uri; hash_method crc32; }
The above is the detailed content of What is a tomcat cluster? Introduction to tomcat cluster. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
