linux CentOS7 keepalived+LVS(DR) build and deploy

Table of contents

1. Function

2. Introduction to environment

3. Operation steps


1. Function



Use keepalived to solve the single point of failure of lvs

High availability cluster

2. Introduction to environment



1. Prepare 6 virtual machines, 2 as LVS master and backup schedulers, 2 as web servers, 1 as storage, and 1 as client verification

2.LVS master and backup scheduler master (192.168.1.106) backup (192.168.1.110)

3.web1(192.168.1.120)web2(192.168.1.128)

4. Storage (192.168.1.121)

5. Client (192.168.1.140)

6. Virtual IP (192.168.1.156)

3. Operation steps



Deploy web server
and adjust ARP parameters of web1 and web2

vim /etc/sysctl.conf 

net.ipv4.conf.all.arp_ignore=1
net.ipv4.conf.all.arp_announce=2
net.ipv4.conf.default.arp_ignore=1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce=2

 

sysctl -p 

 

web1 and web2 install http

 yum -y install httpd

 

 Web1 and web2 each write an index.html for testing (/var/www/html/) httpd website root directory

 echo "web1" >/var/www/html/index.html

 echo "web2" >/var/www/html/index.html

 

web1 and web2 create virtual ip
 

cd /etc/sysconfig/network-scripts/

cp ifcfg-lo ifcfg-lo:0

DEVICE=lo:0
IPADDR=192.168.1.156
NETMASK=255.255.255.255
ONBOOT=yes
NAME=loopback:0

 

Restart the network card (you can see that the picture below has been created successfully)

systemctl restart network

ip a view 

 


Add loopback routes to web1 and web2

route add -host 192.168.1.156/32 dev lo:0

route -n view

 

enable httpd

systemctl start httpd

Deploy LVS master and backup schedulers
and adjust the ARP parameters of master and backup (consistent)

vim /etc/sysctl.conf 

net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects=0
net.ipv4.conf.ens33.send_redirects = 0

 

 

sysctl -p


Install keepalived ipvsadm on master and backup (consistent)

yum install -y keepalived ipvsadm

 

Configure keepalived master (red font master and backup are inconsistent)

vim /etc/keepalived/keepalived.conf

[After entering, delete everything except the first line]

global_defs {
   router_id LVS_DEVEL1
}

vrrp_instance master {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
    192.168.1.156        
    }
}

virtual_server 192.168.1.156 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    #persistence_timeout 50
    protocol TCP

    real_server 192.168.1.120 80 {
        weight 1
        HTTP_GET {
            url {
              path /
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 192.168.1.128 {
        weight 1
        HTTP_GET {
            url {
              path /
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

Configure keepalived backup

global_defs {
   router_id LVS_DEVEL2
}

vrrp_instance backup {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 99
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
    192.168.1.156
    }
}

virtual_server 192.168.1.156 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    #persistence_timeout 50
    protocol TCP

    real_server 192.168.1.120 80 {
        weight 1
        HTTP_GET {
            url {
              path /
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 192.168.1.128 80 {
        weight 1
        HTTP_GET {
            url {
              path /
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

 touch /etc/sysconfig/ipvsadm

[This command means to create a file named ipvsadm in the /etc/sysconfig directory. This file is a tool for configuring IPVS (IP Virtual Server), a Linux kernel module used to achieve load balancing and high availability. In this file, you can set]

Start keepalived and ipvsadm of master and backup
 

systemctl start keepalived

systemctl start ipvsadm

systemctl restart keepalived

systemctl restart ipvsadm

Master and backup load the ip_vs module

modprobe ip_vs

Check the lvs node status [turn it on first and then restart it to respond]

 ipvsadm -ln

 


Enter curl 192.168.1.156 to test (as you can see in the picture below, the test is successful and web1 and web2 are automatically switched)

 

Enter the virtual IP in your local browser to view

 Turn off the main server and check again [After turning off the main server, the slave server will automatically take over the work of the main server]

 

Deploy an NFS shared server
to store configuration files
(rw: the specified shared directory has read and write permissions)

(no_all_squash: All users retain the user permissions of the user who operates the file, and do not change the user identity)

Install nfs

yum -y install nfs-utils

vim /etc/exports

/data/www/html/ 192.168.1.0/24(rw,no_all_squash)

mkdir  -p /data/www/html

echo "web aaabbb123321" >/data/www/html/index.html

 systemctl start nfs

 showmount -e

web1 and web2 mount shared storage

mount 192.168.1.121:/data/www/html /var/www/html/

Test (as you can see in the picture below, the content in the shared storage can be accessed normally)

 nfs server input curl 192.168.1.156 to view

 

Guess you like

Origin blog.csdn.net/2302_77750172/article/details/131299318