Keepalived clustering deployment, nginx load balancing, high-availability clustering, single point of failure solution-biu~biu~@*·~!

Environmental preparation

C entos7 four, turn off the firewall, turn off selinux

  1. No-1 Prevent single point of failure and nginx load balancing
    192.168.112.153
    192.168.112.154
  2. No-2 httpd simulated web page
    192.168.112.160
    192.168.112.161
  • Principle rendering
  • Insert picture description here
    Description: The two highly available devices should be divided into master and backup, and VIP defined. After nginx load balancing is configured, keepalived configures the RS end of the local machine and the ip address of the other keepalived. When both are alive, regardless of access to VIP or Both master and backup can be accessed. When a single point of failure occurs (when one end of the master or backup fails), the VIP is elegant and continuous flow is realized!

No-1 installation service

yum -y install gcc gcc-c++ pcre-devel zlib-devel keepalived
  • Upload nginx package

  • Insert picture description here

  • You can also download the latest nginx package from the official website

  • nginx download address

Install and configure nginx to achieve load balancing

tar xf nginx-1.18.0.tar.gz  解压
cd nginx-1.18.0  进入目录
./configure  检测编译环境
make && make install  编译并安装

Modify nginx configuration file

vim /usr/local/nginx/conf/nginx.conf
  • Lines 34~37 define the back-end server with load [outside the server]
    Insert picture description here
  • Add proxy [in server] on line 49
    Insert picture description here

Arrangement No-2

  • Install httpd
    yum -y install httpd
  • Write test page
vim /var/www/html/index.html

Content web1, the other one is different, web2
Insert picture description here
Insert picture description here

  • Start httpd, verify the port
    Insert picture description here

No-1 start nginx, verify the load

/usr/local/nginx/sbin/nginx

Insert picture description here
Insert picture description here

No-1 placement keepalived

vim /etc/keepalived/keepalived.conf
  • Delete the extra line
    Insert picture description here
  • 8 lines define master
  • Line 9 modify the network card to ens33
  • 11 Behavior weight [backup power is less important than master]
  • The 18th line defines VIP. The ip master and backup that are not occupied in this network segment
    Insert picture description here
    are required to have different configurations, and the others are the same!!!
    Insert picture description here
  • Fill in the VIP on line 22 and modify the port to 80
  • 24 behavioral algorithm
  • Comment out the persistence timeout on line 26 [symbol is!
  • The ip and port of the RS end on line 29
  • Modify line 31 to check for tcp
  • 32 lines delete the redundant ones, add the connection port in the next line
    Insert picture description here

Start the service and verify high availability

systemctl start keepalived

  • View VIP
ip a show ens33
  • Verification rendering, VIP of master
    Insert picture description here
  • All live, master, bakcup and VIP are all accessible to achieve load
    Insert picture description here
    Insert picture description here
    Insert picture description here

Simulate a single point of failure

  • Stop the master side, check VIP elegant
  • systemctl stop keepalived
    Insert picture description here
  • Backup check
    Insert picture description here
  • Webpage test renderings
    Insert picture description here
    Insert picture description here
  • Although the master side has been deactivated, the load can still be achieved, and the VIP is floating

The principle of keepalived please visit: keepalived principle and module

For detailed explanation of keepalived+LVS deployment and principles, please visit: keepalived+LVS clustered deployment

Guess you like

Origin blog.csdn.net/qing1912/article/details/109080613