keepalived+lvs

本文涉及的产品
传统型负载均衡 CLB,每月750个小时 15LCU
网络型负载均衡 NLB,每月750个小时 15LCU
EMR Serverless StarRocks,5000CU*H 48000GB*H
简介:

########hearbeat####
server1
yum install -y heartbeat-*
cd /usr/share/doc/heartbeat-3.0.4/
cp ha.cf authkeys  haresources /etc/ha.d/
cd /etc/ha.d/
vim /ha.cf
 48 keepalive 2
 55 deadtime 30
 60 warntime 10
 70 initdead 60
 75 udpport 717
 90 bcast   eth0  
156 auto_failback on
210 node    server1
211 node    server4
219 ping 172.25.23.250
252 respawn hacluster /usr/lib64/heartbeat/ipfail
258 apiauth ipfail gid=haclient uid=hacluster



vim authkeys 
 23 auth 1
 24 1 crc
chmod 600 authkeys 


vim haresources 
150 server1 IPaddr::172.25.23.100/24/eth0 httpd

scp ha.cf authkeys haresources server4:/etc/ha.d/

/etc/init.d/httpd status
/etc/init.d/heartbeat start
测试:当一台主机的服务挂掉之后,另一台主机会接替他继续执行服务

ip addr
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 pfifo_fast state UP qlen 1000
    link/ether 52:54:00:d1:96:0a brd ff:ff:ff:ff:ff:ff
    inet 172.25.23.1/24 brd 172.25.23.255 scope global eth0
    inet 172.25.23.100/24 scope global secondary eth0
    inet6 fe80::5054:ff:fed1:960a/64 scope link 
       valid_lft forever preferred_lft forever
   
#server1/4 

ip addr add 172.25.23.100/24 dev eth0                     ##添加vip

ipvsadm -A -t 172.25.23.100:80 -s rr                        ##设置负载均衡方式为轮询

ipvsadm -a -t 172.25.23.100:80 -r 172.25.23.2:80 -g  ##设置VIP和RIP

ipvsadm -a -t 172.25.23.100:80 -r 172.25.23.3:80 -g

/etc/init.d/ipvsadm save                                             ##保存设置



server2,server3

yum install arptables_jf -y

ip addr add 172.25.23.100/32  dev  eth0
arptables -A IN -d 172.25.23.100 -j DROP   ##直接连接IP就丢弃

arptables -A OUT -s 172.25.23.100 -j mangle --mangle-ip-s 172.25.23.3  #出去的是RIP

/etc/init.d/arptables_jf save  ##保存设置

/etc/init.d/arptables_jf start  ## 开启服务
vim /var/www/html/index.html
vm2:westos2

vm3:westos3

wKiom1l9oGiR3YE2AAAh8I_StLc061.png

wKiom1l9oGmiY6HQAAAEqG4uGWY840.png










vm1 vm4

##Heartbeat与Lvs负载均衡

cd /usr/share/doc/ldirectord-3.9.5/

cp ldirectord.cf /etc/ha.d/

vim ldirectord


25 virtual=172.25.23.100:80
 26         real=172.25.23.2:80 gate
 27         real=172.25.23.3:80 gate
 28         fallback=127.0.0.1:80 gate
 29         service=http
 30         scheduler=rr
 31         #persistent=600
 32         #netmask=255.255.255.255
 33         protocol=tcp
 34         checktype=negotiate
 35         checkport=80
 36         request="index.html"
 37 #       receive="Test Page"
 38 #       virtualhost=www.x.y.z


ipvsadm -C   ##刷掉以前的设置

  ip addr del 172.25.23.100/24 dev eth0  ##删除之前设置的VIP

  vim haresources

wKioL1l4tMSgzxGZAAAPXkVACog195.png

  scp haresources ldirectord.cf 172.25.2.4:/etc/ha.d/   ##复制文件到另一台热备主机

  /etc/init.d/heartbeat start

 测试

 Server1的heartbeat停止后,server4作热备,继续执行

wKiom1l4tSyg2swrAABL1dv2Tek059.png

wKioL1l4tS2i7ByqAAAh8A9RePI621.png



###keepalived

mkdir /etc/keepalived

 tar -zxf keepalived-1.3.5.tar.gz

    cd keepalived-1.3.5

   ./configure --prefix=/usr/local/keepalived

   make && make install   ##安装服务

   scp -r /usr/local/keepalived/ 172.25.23.4:/usr/local/   ##给另一台热备主机复制配置文件

   ln -s /usr/local/keepalived/sbin/keepalived /sbin/

   ln -s /usr/local/keepalived/etc/keepalived/ /etc/

   ln -s /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

   ln -s /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/


chmod +x /usr/local/keepalived/etc/rc.d/init.d/keepalived


/etc/keepalived
vim keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
        root@localhost
        }
   notification_email_from keep@server1
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
   vrrp_skip_check_adv_addr
   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

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

virtual_server 172.25.23.100 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    #persistence_timeout 50
    protocol TCP

    real_server 172.25.23.2 80 {
        weight 1
         TCP_CHECK{
        connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
real_server 172.25.23.3 80 {
        weight 1
        TCP_CHECK{
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }

}
scp keepalived.conf root@172.25.23.4:/etc/keepalived/   ##给另一台热备主机拷贝配置文件,注意要改priority值

    etc/init.d/keepalived start

ln -s /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig
ln -s /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/

一台主机的服务挂掉之后,另一台主机会接替他继续执行服务

wKioL1l4vBLgMlJ8AADEOtbXnzM173.png

wKiom1l4vBPTRdevAADMPywBCPU323.png










本文转自 漂浮的天堂  51CTO博客,原文链接:http://blog.51cto.com/12774215/1952140,如需转载请自行联系原作者
相关实践学习
SLB负载均衡实践
本场景通过使用阿里云负载均衡 SLB 以及对负载均衡 SLB 后端服务器 ECS 的权重进行修改,快速解决服务器响应速度慢的问题
负载均衡入门与产品使用指南
负载均衡(Server Load Balancer)是对多台云服务器进行流量分发的负载均衡服务,可以通过流量分发扩展应用系统对外的服务能力,通过消除单点故障提升应用系统的可用性。 本课程主要介绍负载均衡的相关技术以及阿里云负载均衡产品的使用方法。
目录
相关文章
|
12月前
|
负载均衡 应用服务中间件 Linux
Nginx系列教程(14) - LVS+KeepAlived+Nginx实现高性能负载均衡集群
Nginx系列教程(14) - LVS+KeepAlived+Nginx实现高性能负载均衡集群
1019 0
|
2月前
|
运维 负载均衡 网络协议
LVS+Keepalived 负载均衡
LVS+Keepalived 负载均衡
60 8
LVS+Keepalived 负载均衡
|
2月前
|
域名解析 运维 负载均衡
LVS+Keepalived 负载均衡(二)28-1
【8月更文挑战第28天】LVS+Keepalived 负载均衡 配置 LVS VIP
58 5
|
6月前
|
运维 负载均衡 监控
keepalived+LVS实现高可用性集群
通过结合keepalived和LVS,你可以创建一个高可用性的负载均衡集群,确保服务器的稳定性和性能。这对于托管Web服务、应用服务器等关键服务的服务器集群非常有用。
115 1
|
6月前
|
负载均衡 监控 Linux
CentOS6.5高可用集群LVS+Keepalived(DR模式)
CentOS6.5高可用集群LVS+Keepalived(DR模式)
|
6月前
|
负载均衡 监控 调度
Keepalived+Lvs(dr)调度器主备配置小实验
Keepalived和LVS(Linux Virtual Server)是两个常用的开源软件,通常结合使用以提供高可用性和负载均衡的解决方案。 Keepalived是一种用于实现高可用性的软件,它可以监控服务器的健康状态,并在主服务器出现故障时自动切换到备份服务器。
195 2
|
12月前
|
负载均衡 算法 网络协议
Keepalived+LVS搭建高可用负载均衡
Keepalived+LVS搭建高可用负载均衡
355 1
|
11月前
|
负载均衡 网络协议 Linux
小白带你学习linux的keepalived+lvs和keepalived双机热备(三十七)
小白带你学习linux的keepalived+lvs和keepalived双机热备(三十七)
162 0
|
负载均衡 监控 Linux
LVS + keepalived
LVS + keepalived
136 1
|
负载均衡 测试技术
LVS+KeepAlived构建高可用集群
LVS+KeepAlived构建高可用集群
98 0