Keepalived 和 ZooKeeper 选哪个

1. Keepalived 和 ZooKeeper 选哪个

1.1. 什么是 Keepalived

Keepalived is a routing software written in C. The main goal of this project is to provide simple and robust facilities for loadbalancing and high-availability to Linux system and Linux based infrastructures. Loadbalancing framework relies on well-known and widely used Linux Virtual Server (IPVS) kernel module providing Layer4 loadbalancing. Keepalived implements a set of checkers to dynamically and adaptively maintain and manage loadbalanced server pool according their health. On the other hand high-availability is achieved by VRRP protocol. VRRP is a fundamental brick for router failover. In addition, Keepalived implements a set of hooks to the VRRP finite state machine providing low-level and high-speed protocol interactions. Keepalived frameworks can be used independently or all together to provide resilient infrastructures.

Keepalived is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

1.2. 什么是 ZooKeeper

ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. All of these kinds of services are used in some form or another by distributed applications. Each time they are implemented there is a lot of work that goes into fixing the bugs and race conditions that are inevitable. Because of the difficulty of implementing these kinds of services, applications initially usually skimp on them, which make them brittle in the presence of change and difficult to manage. Even when done correctly, different implementations of these services lead to management complexity when the applications are deployed.

1.3. 选择哪个

1.3.1. 从主被动的角度考虑

我们知道, Nginx server 通常和 Keepalived 进行结合, 那么 Keepalived 是怎么知道 Nginx 是否存活呢? 是 Nginx 主动向 Keepalived 汇报信息? 不是的。Keepalived 是主动向 Nginx 发送请求, 如果有响应, 那么则 Nginx 可用。

对于 ZooKeeper 而言, HDFS, HBase, Yarn 基于 ZooKeeper 做高可用, 这里的 ZooKeeper 就是被动的, 也就是说 HDFS, HBase, Yarn 主动向 ZooKeeper 中写数据。

1.3.2. 从负载的角度来考虑

Keepalived 可以帮助我们做到主从, 主从的划分是通过配置文件 (主从的 priority 之差 > 50) 指定的, 如果主没有挂掉, 那么大量的请求通过主然后负载到后端的 Nginx, 而从如果想要起作用只有等到主挂掉。

而利用 ZooKeeper 做 HA, ZooKeeper 中可以说是 “人人平等”, 客户端无论访问 follower, 还是 observer, 异或是 leader, 都能给我们返回相应的结果, 可以很好的实现了负载均衡, 这也可以说是 ZooKeeper 的一个优点。

1.3.3. 从存储数据的角度

Keepalived 不可以存储数据, 假设 Keepalived 的主现在有 50 个连接, 如果没有外部数据库存储这些连接的信息, 主挂了的话, 连接信息也就丢了, 所以使用 Keepalived 需要一个外部的数据库, 但是如果主挂了的同时数据库也挂了, 那么就 over 了, 信息就会丢失, 或者从起来后, 连不上数据库, 那么之前的连接信息也会丢失。

ZooKeeper 可以存储数据, ZooKeeper 中可以创建一个 zNode, 里面存放数据, ZooKeeper 可以做到一个分布式数据的一致性, ZooKeeper 中每个节点的视图是一致的, 数据本身可以做到最终一致性, 也就是说其中一个 server 挂了, 其他的 server 还有存的数据, 那么这样的话就不需要额外的数据库, ZooKeeper 本身就可以存储一定量的信息。这也可以说是 ZooKeeper 的另一个优点。

1.3.4. 从业务的角度

Keepalived 可以说比较简单, 只需要简单的配置一下就可以了, 使用 Keepalived 的场景: 如果我们只需要简单的知道当前的业务中哪个是主, 哪个是从, 那么可以选用 Keepalived。

如果除了高可用以外, 比如 kafka, storm 等还要想 ZooKeeper 中写一些数据, 这时候就需要 ZooKeeper。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

云满笔记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值