Home  >  Article  >  类库下载  >  What is a tomcat cluster? Introduction to tomcat cluster

What is a tomcat cluster? Introduction to tomcat cluster

青灯夜游
青灯夜游forward
2018-10-27 17:59:416157browse

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;   #工作进程的个数,一般与计算机的cpu核数一致

events {
    worker_connections  1024;   #单个进程最大连接数(最大连接数=连接数*进程数)
}


http {
    include       mime.types;   #文件扩展名与文件类型映射表
    default_type  application/octet-stream;   #默认文件类型

    sendfile        on;   #开启高效文件传输模式,普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off。

    keepalive_timeout  65;   #长连接超时时间,单位是秒

    gzip  on;   #启用Gizp压缩

    #tomcat集群
    upstream  myapp {   #tomcat集群名称 
        server    localhost:8080;   #tomcat1配置
        server    localhost:8181;   #tomcat2配置
    }   

    #nginx的配置
    server {
        listen       9090;   #监听端口,默认80
        server_name  localhost;   #当前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!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete