目录
你可以选泽Linux发行版的存储库安装或源代码编译安装keepalive,但从存储库通常是安装最快的办法
1 从存储库安装
1.1 在Red Hat(CentOS)安装
# 常规安装
yum install keepalived
# 安装到指定目录下,有可能不会复用已有依赖
# yum install --installroot=/usr/local -–releasever=/ keepalived
1.2 在Debian中安装
apt-get install keepalived
2. 源代码编译安装
2.1 依赖安装
编译keepalive需要 compiler, OpenSSL 和 Netlink Library。如果需要SNMP支持,请安装Net-SNMP。
RHEL/CentOS/Fedora依赖安装
在 RHEL, Centos, Fedora 安装依赖指令(旧版本使用yum替代 dnf )::
dnf install curl gcc autoconf automake openssl-devel libnl3-devel
iptables-devel ipset-devel net-snmp-devel libnfnetlink-devel file-devel
# DBUS 支持::
dnf install glib2-devel
# JSON 支持::
dnf install json-c-devel
Debian/Ubuntu依赖安装
在 Debian/Ubuntu中, 安装依赖指令::
apt-get install pkg-config curl gcc autoconf automake libssl-dev libnl-3-dev
libnl-genl-3-dev libsnmp-dev libnl-route-3-dev libnfnetlink-dev libipset-dev
iptables-dev libsnmp-dev
# DBUS 支持::
dnf install libglib2.0-dev
Alpine Linux依赖安装
autoconf automake iptables-dev ipset-dev libnfnetlink-dev libnl3-dev musl-dev and
openssl-dev or libressl-dev
# SNMP 支持::
net-snmp-dev (requires libressl-dev and not openssl-dev)
Archlinux 依赖安装
pacman -S ipset libnfnetlink libnl1
# SNMP 支持::
pacman -S net-snmp
2.2 依赖安装完后,进行keepalived的编译安装
最新版本查看 http://www.keepalived.org/download.html 或 https://github.com/acassen/keepalived.
使用curl 或 wget 下载tar包后编译安装
curl --progress http://keepalived.org/software/keepalived-1.2.15.tar.gz | tar xz
cd keepalived-1.2.15
./build_setup
./configure
make && make install
也可以指定安装目录::
./configure --prefix=/usr/local/keepalived-1.2.15
这使它容易卸载keepalive,只有删除父目录即可。此外,这种安装方法 允许多个版本的keepalive安装而不需要覆盖。使用软连接指向所需的版本。例如,您的目录布局可能看起来像这样:
[root@lvs1 ~]# cd /usr/local
[root@lvs1 local]# ls -l
total 12
lrwxrwxrwx. 1 root root 17 Feb 24 20:23 keepalived -> keepalived-1.2.15
drwxr-xr-x. 2 root root 4096 Feb 24 20:22 keepalived-1.2.13
drwxr-xr-x. 2 root root 4096 Feb 24 20:22 keepalived-1.2.14
drwxr-xr-x. 2 root root 4096 Feb 24 20:22 keepalived-1.2.15
3. 设置自启脚本
编译后,创建一个init脚本为了管理keepalive守护进程
3.1 在 RHEL中
# 存储库安装
ln -s /etc/rc.d/init.d/keepalived.init /etc/rc.d/rc3.d/S99keepalived
# 编译安装
mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
ln -s /usr/local/keepalived/sbin/keepalived /usr/sbin/
ln -s /usr/local/keepalived/sbin/keepalived /sbin/
# 开启自启
systemctl enable keepalived
3.3 在 Debian中
# 存储库安装
ln -s /etc/init.d/keepalived.init /etc/rc2.d/S99keepalived
注意:该链接应添加到您的默认运行级别目录中。