LVS-DR+Keepalived high-availability cluster (optimized construction steps)


Preface

  • My previous blogs are well written, here is a link, students who are interested can check it out
  • LVS+Keepalived high availability cluster
  • This article has optimized the steps of building keepalived in the previous blog, and the following is directly posted dry goods

1. Environment

  • Host: Win10 professional workstation
  • VMware:16Pro(16.1.0)
  • CentOS 7
  • Network adapter: all in NAT mode
  • Network card configuration: get IP statically
  • YUM source: local
  • Main DR server (load scheduler) (CentOS 7-1): 192.168.126.11
  • From the DR server (load scheduler) (CentOS 7-2): 192.168.126.12
  • Web server 1 (CentOS 7-3): 192.168.126.13
  • Web server 2 (CentOS 7-4): 192.168.126.14
  • NFS server (CentOS 7-5): 192.168.126.15
  • VIP:192.168.126.166
  • Win10 client: 192.168.126.10

2. Construction steps

  • This experiment is based on the LVS-DR load balancing cluster that has been prepared, and only a slave scheduler is added, and the configuration is consistent with the master scheduler
  • Seeing this, I need to follow my previous blog to build LVS+DR first, and then add a slave scheduler with the same configuration. The link is posted below
  • Build LVS load balancing cluster-direct routing mode (LVS-DR)
  • Only the configuration steps of Keepalived are posted below
  1. Configure CentOS 7-1
yum -y install keepalived
#安装软件包

cd /etc/keepalived/
cp keepalived.conf keepalived.conf.bak
#备份

vim keepalived.conf

global_defs {
    
    						#定义全局参数
    #第10行,邮件服务指向本地
	smtp_server 127.0.0.1
    #第12行,指定服务器(路由器)的名称,主备服务器名称须不同,主为LVS_01,备为LVS_02
	router_id LVS_01
	
	#注释该行!严格遵守VRRP协议,可能会阻止启动Keepalived
	#vrrp_strict
	   
}

vrrp_instance VI_1 {
    
    				#定义VRRP热备实例参数
#20行,指定热备状态,主为MASTER,备为BACKUP
    state MASTER
    #21行,指定承载vip地址的物理接口
    interface ens33
    #第22行,指定虚拟路由器的ID号,每个热备组保持一致	
    virtual_router_id 10
    #第23行,指定优先级,数值越大优先级越高,主为100,备为99
    priority 100
    advert_int 1					#通告间隔秒数(心跳频率)
    authentication {
    
    				#定义认证信息,每个热备组保持一致
		auth_type PASS				#认证类型
        第27行,指定验证密码,主备服务器保持一致
        auth_pass 123123
    }
    virtual_ipaddress {
    
    				#指定群集vip地址
        192.168.126.166
    }
}
#第34行,指定虚拟服务器地址(VIP)、端口,定义虚拟服务器和Web服务器池参数
virtual_server 192.168.126.166 80 {
    
    
    delay_loop 6					#健康检查的间隔时间(秒)
    lb_algo rr						#指定调度算法,轮询(rr)
    #第37行,指定群集工作模式,直接路由(DR)
    lb_kind DR
    persistence_timeout 50			#连接保持时间(秒)
    protocol TCP					#应用服务采用的是 TCP协议
    #第41行,指定第一个Web节点的地址、端口
    real_server 192.168.126.13 80 {
    
    
        weight 1					#节点的权重
        第43行,添加以下健康检查方式		
        TCP_CHECK {
    
    
			connect_port 80			#添加检查的目标端口
			connect_timeout 3		#添加连接超时(秒)
			nb_get_retry 3			#添加重试次数
			delay_before_retry 3	#添加重试间隔
		}
	}

	real_server 192.168.126.14 80 {
    
    		#添加第二个Web节点的地址、端口
        weight 1
        TCP_CHECK {
    
    
			connect_port 80
			connect_timeout 3
			nb_get_retry 3
			delay_before_retry 3
		}
	}

#删除后面多余的配置
}


scp keepalived.conf [email protected]:/etc/keepalived/
#先去从调度器安装好 keepalived ,再远程把主调度器配置好的配置文件传输过去
#只要改动几个参数即可,快捷且方便

systemctl start keepalived
#主和从一起开启服务
  1. test
ip addr
#查看 IP 
  • First, the master and the slave execute this command separately
    mark
    mark
  • As you can see, only the master has VIP
  • Then we close the main keepalived to try
    mark
    mark
  • The VIP drifted to the slave scheduler. We then restarted the keepalived of the master scheduler and found that the virtual IP was back again. This is related to the master-slave priority set previously.
  • So it is verified that the IP address of the virtual router (VIP) can be transferred between the routers in the hot standby group
  • Let's finally verify the access to the browser, here the default gateway of the client does not need to point to VIP
    mark
    mark

Guess you like

Origin blog.csdn.net/weixin_51486343/article/details/112985989