LVS+Keepalived high-availability cluster actual deployment (updated and optimized version)

LVS+Keepalived high-availability cluster actual deployment

1. Experimental environment requirements

Configure keepalived on the basis of DR mode. For DR configuration, please see the previous blog
LVS Load Balancing Cluster—Detailed DR mode actual deployment

主DR 服务器:192.168.126.10

备DR 服务器:192.168.126.50

 Web 服务器1192.168.126.20

 Web 服务器2192.168.126.30 

共享服务器:192.168.126.40 

客户端:192.168.126.50 vip(虚拟IP):192.168.126.88

2. Experimental deployment steps

(1), configure the load scheduler (main and standby are the same)

systemctl stop firewalld.service
setenforce 0
yum -y install ipvsadm keepalived
modprobe ip_vs
cat /proc/net/ip_vs
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0
sysctl -p

(2) Configure keeplived (set on the primary and standby DR servers)

yum install -y 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
}
--14行--#vrrp_strict    #注释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 abc123
    }

Insert picture description here

 virtual_ipaddress {
    
    				#指定群集vip地址
        192.168.80.188
    }
}
--36行--修改,指定虚拟服务器地址(VIP)、端口,定义虚拟服务器和Web服务器池参数
virtual_server 192.168.80.188 80 {
    
    
    delay_loop 6					#健康检查的间隔时间(秒)
    lb_algo rr						#指定调度算法,轮询(rr)
--39行--修改,指定群集工作模式,直接路由(DR)
    lb_kind DR
    persistence_timeout 50			#连接保持时间(秒)
    protocol TCP					#应用服务采用的是 TCP协议
--43行--修改,指定第一个Web节点的地址、端口
    real_server 192.168.80.100 80 {
    
    
        weight 1					#节点的权重
--45行--删除,添加以下健康检查方式		
        TCP_CHECK {
    
    
			connect_port 80			#添加检查的目标端口
			connect_timeout 3		#添加连接超时(秒)
			nb_get_retry 3			#添加重试次数
			delay_before_retry 4	#添加重试间隔
		}
	}

	real_server 192.168.80.101 80 {
    
    		#添加第二个 Web节点的地址、端口
	    weight 1
	    TCP_CHECK {
    
    
			connect_port 80
			connect_timeout 3
			nb_get_retry 3
			delay_before_retry 4
		}
	}
##删除后面多余的配置##
}

Insert picture description here

Insert picture description here

Insert picture description here

(Three), configure the load scheduler ipvsadm rules (main and standby are the same)

ipvsadm-save > /etc/sysconfig/ipvsadm
systemctl start ipvsadm
ipvsadm -C

ipvsadm -A -t 192.168.126.10:80 -s rr          #地址为自己主(备)的IP地址

ipvsadm -a -t 192.168.126.10:80 -r 192.168.126.20:80 -g   

ipvsadm -a -t 192.168.126.10:80 -r 192.168.126.30:80 -g

ipvsadm

systemctl restart keepalived.service  #重启keepalived

ipvsadm -ln

Insert picture description here

Insert picture description here

Insert picture description here

(4) Test verification

在客户端访问 http://192.168.126.88/ ,默认网关指向 192.168.126.88

Insert picture description here

Insert picture description here

把主服务器keepaived停掉再测试systemctl stop keepalived.service
每次刷新页面需要等待几分钟

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_51573771/article/details/112969812