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

How to achieve High availability load balancing with nginx + keepalived

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

Share

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

The following brings you how nginx + keepalived achieves high-availability load balancing. I hope it can give you some help in practical application. Load balancing involves more things, there are not many theories, and there are many books online. Today, we will use the accumulated experience in the industry to do an answer.

Virtual IP: 192.168.2.52

Nginx-1: 192.168.2.50

Nginx-2: 192.168.2.51

Close / etc/sysconfig/selinux

SELINUX=disabled

Nginx-1

Yum install keepalived

Vim / etc/keepalived/keepalived.conf

! Configuration File for keepalived

Global_defs {

Router_id LVS_DEVEL

}

Vrrp_instance VI_1 {

State MASTER / / is defined as a MASTER host

Interface eth0

Virtual_router_id 51 / / Virtual id

Priority 100 / / priority

Advert_int 1 / / Detection interval

Authentication {

Auth_type PASS / / authentication method

Auth_pass abcd / / Authentication password

}

Virtual_ipaddress {

192.168.2.52 / / Virtual ip, or VIP

}

Chkconfig keepalived on

Service keepalived start

Nginx-2

Yum install keepalived

Vim / etc/keepalived/keepalived.conf

-only the following changes are made

State BACKUP / / is defined as BACKUP

Priority 99 / / priority

Virtual_ipaddress {

192.168.2.52

}

Chkconfig keepalived on

Service keepalived start

Ip a

Has been bound successfully

Detect keepalived automatic handoff

Client:

Ping 192.168.2.52-t

Nginx-1: turn off the keepalived service

Service keepalived stop

Whether the client is normal, ping

Install nginx

Because centos does not have nginx, install a third-party epel-release source first

Yum install-y epel-release

Yum install-y nginx

Load balancing

Vi / etc/nginx/nginx.conf

Add the following

-

# for more information.

Include / etc/nginx/conf.d/*.conf

Upstream zhizhimao.com {

Server 192.168.2.101 80; # web CVM

Server 192.168.2.100 server 80; # web CVM

}

}

-

Reverse proxy

Vi / etc/nginx/conf.d/default.conf

-

Server {

Listen 80

Listen [::]: 80default_server

Server_name zhizhimao.com; # fill in IP if you only act as an agent

Root / usr/share/nginx/html

# Load configuration files for the default server block.

Include / etc/nginx/default.d/*.conf

Location / {

Proxy_pass http://zhizhimao.com; # fill in IP if only acting as an agent

}

Error_page 404 / 404.html

Location = / 40x.html {

}

Error_page 500 502 503 504 / 50x.html

Location = / 50x.html {

}

}

Chkconfig nginx on

Service nginx start

Firewall opens port 80

After reading the above about how nginx + keepalived achieves high-availability load balancing, if there is anything else you need to know, you can find out what you are interested in in the industry information or find our professional and technical engineers for answers. Technical engineers have more than ten years of experience in the industry.

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