Keepalived安装

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.

Keepalived提供三种功能:

  1. 通过LVS实现负载均衡
  2. 通过VRRP实现高可用
  3. 健康检查 辅助实现负载均衡

其中高可用和负载均衡可以独立使用

2 安装

从官网下载安装包,Ubuntu需要安装以下依赖库:

openssl apt intall libssl-dev
apt install libnl-3-dev
apt install libnl-genl-3-dev
apt install libnfnetlink-dev

这点在它的链接库-lcrypto -lssl -lnl-genl-3 -lnl-3可以看到。

3 编译

./configure --prefix=/usr/local/keepalived #建立单独的目录
make
make install

然后修改~/.bashrc,增加export PATH=$PATH:/usr/local/keepalived/sbin,这样启动时比较方便。

4 配置文件

Keepalived的配置文件比较多,安装之后的/usr/local/keepalived/etc如下:

root@ns1-qingdns-01-sh:/usr/local/keepalived/etc# tree 
.
├── keepalived
│   ├── keepalived.conf
│   └── samples
│       ├── client.pem
│       ├── dh1024.pem
│       ├── keepalived.conf.conditional_conf
│       ├── keepalived.conf.fwmark
│       ├── keepalived.conf.HTTP_GET.port
│       ├── keepalived.conf.inhibit
│       ├── keepalived.conf.IPv6
│       ├── keepalived.conf.misc_check
│       ├── keepalived.conf.misc_check_arg
│       ├── keepalived.conf.quorum
│       ├── keepalived.conf.sample
......
└── sysconfig
    └── keepalived

samples目录包含一些example,需要时候参考。
准备配置文件:

  • /usr/local/keepalived/etc/keepalived.conf 拷贝到 /etc/keepalived/keepalived.conf(备注,默认没有/etc/keepalived目录,需新建)
  • /usr/local/keepalived/etc/sysconfig/keepalived 拷贝到 /etc/sysconfig/keepalived(备注,默认Ubuntu没有/etc/sysconfig目录,需新建)

之所以要这样做,因为keepalived默认启动参数是从/etc/sysconfig/keepalived读取,配置文件从/etc/keepalived/keepalived.conf读取。

5 配置文件

keepalived配置比较复杂,可以参考官网手册。

你可能感兴趣的:(Keepalived安装)