LVS - - 2. Environment Setup

LVS Environment Setup

  • Environmental Science:
    System: centos6.5

Install required software

yum install -y vim wget
yum install -y ipvsadm
cd /usr/src  
yum -y install openssl-devel  
wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gz  
wget http://mirror.centos.org/centos/6/os/x86_64/Packages/popt-static-1.13-7.el6.x86_64.rpm  
yum -y install popt-static-1.13-7.el6.x86_64.rpm  
yum -y install kernel-devel make gcc openssl-devel libnl* popt*  
ln -s /usr/src/kernels/2.6.32-754.27.1.el6.x86_64/ /usr/src/linux  
tar zxvf keepalived-1.2.7.tar.gz  
cd keepalived-1.2.7  
./configure --with-kernel-dir=/usr/src/kernels/2.6.32-754.27.1.el6.x86_64/

make && make install  

software configuration

cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/  
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/  
mkdir /etc/keepalived  
cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/  
cp /usr/local/sbin/keepalived /usr/sbin/  

keepalived configuration

vim /etc/sysctl.conf
 Modify "net.ipv4.ip_forward = 1" inside after opening  
After saving, execute the following command to take effect immediately

sysctl -p

Startup Configuration for keepalived

vim /etc/keepalived/keepalived.conf

Details of specific file configurations View documentation:
3.keepalived.conf file configuration details.md

Here is my file configuration

! Configuration File for keepalived

global_defs {
   notification_email {
     wangl@tailixin.cn
   }
   notification_email_from chenjw@tailixin.cn
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.8.63
    }
}

virtual_server 192.168.8.63 8080 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 50
    protocol TCP

    real_server 192.168.1.63 8080 {
        weight 1
        TCP_CHECK {
	    connect_timeout 3
	    nb_get_retry 3
	    delay_before_retry 3
	}
    }
}
192.168.1.63 As a business server ip  
192.168.8.63 Virtual Server as Load ip

Start keepalived

chkconfig keepalived on  
service keepalived start 

View process

ps aux | grep keepalived

As shown in the following image

root      3694  0.0  0.0  42172  1000 ?        Ss   10:55   0:00 keepalived -D
root      3695  0.0  0.1  44400  2296 ?        S    10:55   0:00 keepalived -D
root      3697  0.0  0.0  44276  1664 ?        S    10:55   0:00 keepalived -D
root      3728  0.0  0.0 103260   876 pts/1    S+   11:09   0:00 grep keepalived

Keepalived is running normally and starts three processes, one of which is the parent process, which monitors its children; one is the vrrp child process; and the other is the checkers child process.

If you only see two processes at this time, rerun the steps for installing keepalived.

Check if virtual ip has been added

ip a

The results are as follows, with 1.63 and 1.68 joined

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
        valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:50:56:9a:6d:ee brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.63/24 brd 192.168.1.255 scope global eth0
    inet 192.168.8.63/32 scope global eth0
    inet6 fe80::250:56ff:fe9a:6dee/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether 00:50:56:9a:64:89 brd ff:ff:ff:ff:ff:ff

Indicates that virtual ip has been automatically configured.

View request forwarding:

ipvsadm -lcn | grep fictitious IP
  • Now that the keepalived of this machine has been set up, the next step is to build from the node, from the node to the main node, just pay attention to modifying the configuration file in a few places

    vim /etc/keepalived/keepalived.conf

    global_defs {
    notification_email {
    wangl@tailixin.cn
    }
    notification_email_from chenjw@tailixin.cn
    smtp_server 192.168.200.1
    smtp_connect_timeout 30
    router_id LVS_BACKUP #The router_id here needs to be distinguished and can be changed by itself
    }

    vrrp_instance VI_1 {
    state BACKUP #Here you need to change MASTER to BACKUP
    interface eth0
    virtual_router_id 56 #This value should be consistent with the primary node
    priority 50 #The value here must be smaller than the primary node
    advert_int 1
    authentication {
    auth_type PASS
    auth_pass 1111
    }
    virtual_ipaddress {
    192.168.8.63
    }
    }

    virtual_server 192.168.8.63 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.0.0
    persistence_timeout 50
    protocol TCP

      real_server 192.168.1.63 80 {
          weight 1
          TCP_CHECK {
              connect_timeout 3
              nb_get_retry 3
              delay_before_retry 3
          }
      }
    
      #This adds information from the node, and also from the primary node
      real_server 192.168.1.65 80 {
          weight 1
          TCP_CHECK {
              connect_timeout 3
              nb_get_retry 3
              delay_before_retry 3
          }
      }
    

    }

Then the master and slave nodes restart the keepalived service
Verify last
*

  • When you hang up the rs2 server, access VIP automatically switches to the rs1 server
  • When you hang up the rs1 server, access VIP automatically switches to the rs2 server
  • And when either of the LVS's master and backup servers hangs up and you visit the vip address, the website will be fine.
82 original articles published. 26% praised. 130,000 visits+
Private letter follow

Tags: yum vim OpenSSL CentOS

Posted on Mon, 10 Feb 2020 22:29:04 -0500 by angelorigo