LVS_Director + keepalived

環境:
ディレクターディストリビューター:メイン:192.168.49.144スタンバイ:192.168.49.143
VIP:192.168.49.199実サーバー:192.168.49.140 192.168.49.145
ファイアウォールを閉じてselinux

1. LVS

1.ソフトウェアをインストールする

[root@lvs-keepalived-master ~]# yum -y install ipvsadm
[root@lvs-keepalived-slave ~]# yum -y install ipvsadm

2.LVSの導入

[root@lvs-server ~]# ip addr add dev ens33 192.168.49.199/32 #设置VIP
[root@xingdian-cloud ~]# ipvsadm -S > /etc/sysconfig/ipvsadm
[root@xingdian-cloud ~]# systemctl start ipvsadm
[root@lvs-server ~]# ipvsadm -A -t 192.168.49.199:80 -s rr 
[root@lvs-server ~]# ipvsadm -a -t 192.168.49.199:80 -r 192.168.49.140 -g 
[root@lvs-server ~]# ipvsadm -a -t 192.168.49.199:80 -r 192.168.49.145 -g 
[root@lvs-keepalived-master ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.49.199:80 rr persistent 20
  -> 192.168.49.140:80           Route   1      0          0         
  -> 192.168.49.145:80           Route   0      0          0

3.実サーバーを構成する

[root@test-nginx1 ~]# yum install -y nginx
[root@test-nginx2 ~]# yum install -y nginx
[root@test-nginx1 ~]# systemctl start nginx
[root@test-nginx2 ~]# systemctl start nginx
echo "web-server-1" > /usr/share/nginx/html/index.html
echo "web-server-2" > /usr/share/nginx/html/index.html
[root@test-nginx1 ~]# ip addr add dev lo 192.168.49.199/32
[root@test-nginx1 ~]# echo "net.ipv4.conf.all.arp_ignore = 1" >> /etc/sysctl.conf
[root@test-nginx1 ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[root@test-nginx1 ~]# sysctl -p
[root@test-nginx1 ~]# systemctl start nginx

二.Keepalived

1. keepalivedをインストールする

[root @ lvs-keepalived-master〜]#yum -y install keepalived
[root @ lvs-keepalived-slave〜]#yum -y install keepalived

2.構成ファイルを変更します

LVSマスター
[root@ha-proxy-master ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
    
    
   router_id lvs-keepalived-master    #辅助改为lvs-backup
}

vrrp_instance VI_1 {
    
    
    state MASTER
    interface ens33                #VIP绑定接口
    virtual_router_id 80         #VRID 同一组集群,主备一致          
    priority 100            #本节点优先级,辅助改为50
    advert_int 1            #检查间隔,默认为1s
    authentication {
    
    
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
    
    
        192.168.49.199/24
    }
}

virtual_server 192.168.49.199 80 {
    
        #LVS配置
	delay_loop 3
	lb_algo rr     #LVS调度算法
	lb_kind DR     #LVS集群模式(路由模式)
	nat_mask 255.255.255.0
	protocol TCP      #健康检查使用的协议
	real_server 192.168.49.140 80 {
    
    
		weight 1
		inhibit_on_failure   #当该节点失败时,把权重设置为0,而不是从IPVS中删除
		TCP_CHECK {
    
              #健康检查
			connect_port 80   #检查的端口
			connect_timeout 3  #连接超时的时间
			}
		}
	real_server 192.168.49.145 80 {
    
    
		weight 1
		inhibit_on_failure
		TCP_CHECK {
    
    
			connect_timeout 3
			connect_port 80
			}
		}
}
LVSスレーブ
[root@lvs-keepalived-slave ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
    
    
   router_id lvs-keepalived-slave
}

vrrp_instance VI_1 {
    
    
    state BACKUP
    interface ens33
    nopreempt                    #不抢占资源,可以不添加
    virtual_router_id 80
    priority 50
    advert_int 1
    authentication {
    
    
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
    
    
        192.168.49.199/24
    }
}
virtual_server 192.168.49.199 80 {
    
    
	delay_loop 3
	lb_algo rr
	lb_kind DR
	nat_mask 255.255.255.0
	persistence_timeout 20
	protocol TCP
	real_server 192.168.49.140 80 {
    
    
		weight 1
		inhibit_on_failure
		TCP_CHECK {
    
    
			connect_port 80
			connect_timeout 3
			}
		}
	real_server 192.168.49.145 80 {
    
    
		weight 1
		inhibit_on_failure
		TCP_CHECK {
    
    
			connect_timeout 3
			connect_port 80
			}
		}
}

3. VIPにアクセス

カール192.168.49.199
ここに画像の説明を挿入

おすすめ

転載: blog.csdn.net/weixin_49844466/article/details/108453917