Get the App
SLTechnology News&Howtos  ›  Servers  › 

Building High performance web Server Cluster with keepalived+nginx+tomcat

Shulou Source: shulou.com Published: 2022-06-02 17:41:08 11月16日 Update

Keepalived+nginx+tomcat is used to build a high-performance web server cluster, the front end uses nginx as a reverse proxy to achieve load balancing, while combined with keepalived to achieve high availability of nginx, the back end uses tomcat to do dynamic jsp parsing to achieve dynamic and static separation.

(permanent address of this article: http://woymk.blog.51cto.com/10000269/1928716)

Building environment: centos 6.9

Prepare four servers

Vip: 192.168.75.130

Master: 192.168.75.131 (install nginx as reverse proxy to achieve load balancing, combined with keepalived to achieve high availability)

Backup: 192.168.75.132 (ibid.)

Web1: 192.168.75.151 (install nginx and tomcat to achieve static and dynamic separation)

Web2: 192.168.75.152 (ibid.)

To save servers here, nginx and tomcat are installed on a single service or can be configured separately.

The configuration steps are as follows:

1. Install nginx and tomcat software

Four servers have installed nginx respectively.

For installation method, please see: LNMP Environment Building

Install tomcat on web1,web2 respectively

For installation method, please see: installation and configuration of Tomcat8.5

Start nginx and tomcat on web1 and web2, respectively

Service nginx start

Service tomcat start

two。 Configure nginx on master and backup

Vi / usr/local/nginx/conf/nginx.conf

Add or modify the following:

Upstream web_nginx {

Server 192.168.75.151

Server 192.168.75.152

}

Upstream web_tomcat {

# ip_hash

Server 192.168.75.151:8080

Server 192.168.75.152:8080

}

Server {

Listen 80

Server_name localhost

# charset koi8-r

# access_log logs/host.access.log main

Location / {

Proxy_pass http://web_nginx/;

Proxy_set_header Host $host

Proxy_set_header X-Real-IP $remote_addr

Proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for

}

Location ~\ .jsp$ {

Proxy_pass http://web_tomcat/;

}

}

Start the nginx service on master and backup, respectively

Service nginx start

3. Configure keepalived

Install keepalived on master and backup, respectively

Yum install-y keepalived

1) configure master

Vi / etc/keepalived/keepalived.conf

Clear the original text and add the following:

! Configuration File for keepalived

Global_defs {

Notification_email {

# acassen@firewall.loc

# failover@firewall.loc

# sysadmin@firewall.loc

}

# notification_email_from Alexandre.Cassen@firewall.loc

# smtp_server 192.168.200.1

# smtp_connect_timeout 30

Router_id LVS_DEVEL

}

Vrrp_script chk_http_port {

Script "

Tags: Service configuration server content movement method log environment installation agent cluster high performance balance success first master front end dynamic original text at the same time address Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple vpn MySQL Microsoft MariaDB