准备四台服务器 (一台做LVS,一台做keepalived,俩台做web) 在LVS和keepalived上下载 yum -y install ipvsadm keepalived
! 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.19.110/24 # 可以写多个vip } }
virtual_server 192.168.19.110 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.19.130 80 { weight 1 inhibit_on_failure #当该节点失败时,把权重设置为0,而不>是从IPVS中删除 TCP_CHECK { #健康检查 connect_port 80 #检查的端口 connect_timeout 3 #连接超时的时间 } } real_server 192.168.19.131 80 { weight 1 inhibit_on_failure TCP_CHECK { connect_timeout 3 connect_port 80 } } }
! Configuration File for keepalived
global_defs { router_id lvs-keepalived-slave }
vrrp_instance VI_1 { state BACKUP #与lvs配置文件不一样 interface ens33 nopreempt #不抢占资源 virtual_router_id 80 priority 50 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.19.110/24 } } virtual_server 192.168.19.110 80 { delay_loop 3 lb_algo rr lb_kind DR nat_mask 255.255.255.0 protocol TCP real_server 192.168.19.130 80 { weight 1 inhibit_on_failure TCP_CHECK { connect_port 80 connect_timeout 3 } } real_server 192.168.19.131 80 { weight 1 inhibit_on_failure TCP_CHECK { connect_timeout 3 connect_port 80 } } }
俩台wed服务器 yum -y install nginx ip addr add dev lo 192.168.9.110/32 echo “ip addr add dev lo 172.16.147.101/32” >> /etc/rc.local echo “net.ipv4.conf.all.arp_ignore = 1” >> /etc/sysctl.conf sysctl -p