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

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

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

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 "

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