原创

Keepalived-1.3.5编译安装步骤和启动方式详解

Keepalived是一个免费开源的,用C编写的类似于layer3, 4 & 7交换机制软件,具备我们平时说的第3层、第4层和第7层交换机的功能。主要提供loadbalancing(负载均衡)和high-availability(高可用)功能,负载均衡实现需要依赖Linux的虚拟服务内核模块(ipvs),而高可用是通过VRRP协议实现多台机器之间的故障转移服务。 


下面本站素文宅博客blog.yoodb.com主要讲述一下Keepalived编译和安装出现的问题以及解决方法,本人使用keepalived-1.3.5.tar.gz

官网源码包下载地址(2017-07-31 Keepalived最新版keepalived-1.3.5.tar.gz):http://www.keepalived.org/download.html

[root@iZ256w2hluuZ local]# tar -zxvf /tmp/keepalived-1.3.5.tar.gz 
[root@iZ256w2hluuZ local]# cd keepalived-1.3.5/
[root@iZ256w2hluuZ keepalived-1.3.5]# ./configure --prefix=/usr/local/keepalived


1. 系统出现警告信息“*** WARNING - this build will not support IPVS with IPv6. Please install libnl/libnl-3 dev libraries to support IPv6 with IPVS.”,具体日志如下:

Keepalived configuration
------------------------
Keepalived version       : 1.3.5
Compiler                 : gcc
Preprocessor flags       : 
Compiler flags           : -Wall -Wunused -Wstrict-prototypes -Wextra -g -O2
Linker flags             : 
Extra Lib                :  -lcrypto  -lssl 
Use IPVS Framework       : Yes
IPVS use libnl           : No
IPVS syncd attributes    : No
IPVS 64 bit stats        : No
fwmark socket support    : Yes
Use VRRP Framework       : Yes
Use VRRP VMAC            : Yes
Use VRRP authentication  : Yes
With ip rules/routes     : Yes
SNMP vrrp support        : No
SNMP checker support     : No
SNMP RFCv2 support       : No
SNMP RFCv3 support       : No
DBUS support             : No
SHA1 support             : No
Use Debug flags          : No
Stacktrace support       : No
Memory alloc check       : No
libnl version            : None
Use IPv4 devconf         : No
Use libiptc              : No
Use libipset             : No
init type                : upstart
Build genhash            : Yes
Build documentation      : No

*** WARNING - this build will not support IPVS with IPv6. Please install libnl/libnl-3 dev libraries to support IPv6 with IPVS.


解决方案一:(在线安装)

执行yum命令yum -y install libnl libnl-devel解决上述警告问题

[root@iZ256w2hluuZ keepalived-1.3.5]# yum -y install libnl libnl-devel


解决方案二:(离线安装)

离线安装libnl-devel包,从网上下载libnl-devel-1.1.4-2.el6.x86_64.rpm包,执行rpm -ivh libnl-devel-1.1.4-2.el6.x86_64.rpm命令。

[root@iZ256w2hluuZ other-packages]# wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libnl-devel-1.1.4-2.el6.x86_64.rpm
####执行wget命令是从另外一台可以连接外网的服务器上下载libnl-devel-1.1.4-2.el6.x86_64.rpm包的命令,可以忽略,只是为大家提供个下载libnl-devel地址####

[root@iZ256w2hluuZ other-packages]# rpm -ivh libnl-devel-1.1.4-2.el6.x86_64.rpm 
Preparing...                ########################################### [100%]
	package libnl-devel-1.1.4-2.el6.x86_64 is already installed


安装完成以后,重新执行configure命令

[root@iZ256w2hluuZ keepalived-1.3.5]# ./configure --prefix=/usr/local/keepalived


2. 系统出现错误信息“configure: error: libnfnetlink headers missing”,具体日志如下:

checking for nl_socket_modify_cb in -lnl... yes
checking for linux/rtnetlink.h... yes
checking libnfnetlink/libnfnetlink.h usability... no
checking libnfnetlink/libnfnetlink.h presence... no
checking for libnfnetlink/libnfnetlink.h... no
configure: error: libnfnetlink headers missing


解决方案一:(在线安装)

执行yum命令yum install -y libnfnetlink-devel解决上述错误问题

[root@iZ256w2hluuZ keepalived-1.3.5]# yum install -y libnfnetlink-devel


解决方案二:(离线安装)

Linux执行wget下载rpm包(离线安装libnfnetlink包时所需rpm包,执行wget下载libnfnetlink rpm包命令,此步可以忽略,只是为大家提供个下载libnfnetlink地址),具体命令如下:

wget ftp://mirror.switch.ch/mirror/centos/6/os/x86_64/Packages/libnfnetlink-1.0.0-1.el6.x86_64.rpm
wget ftp://mirror.switch.ch/mirror/centos/6/os/x86_64/Packages/libnfnetlink-devel-1.0.0-1.el6.x86_64.rpm

执行rpm -ivh libnfnetlink-1.0.0-1.el6.x86_64.rpm命令安装libnfnetlink-1.0.0-1.el6.x86_64.rpm包,具体如下:

[root@iZ256w2hluuZ other-packages]# rpm -ivh libnfnetlink-1.0.0-1.el6.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:libnfnetlink           ########################################### [100%]

执行rpm -ivh libnfnetlink-devel-1.0.0-1.el6.x86_64.rpm命令安装libnfnetlink-devel-1.0.0-1.el6.x86_64.rpm包,具体如下:

[root@iZ256w2hluuZ other-packages]# rpm -ivh libnfnetlink-devel-1.0.0-1.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:libnfnetlink-devel     ########################################### [100%]


安装完成以后,重新执行configure命令

[root@iZ256w2hluuZ keepalived-1.3.5]# ./configure --prefix=/usr/local/keepalived


3. 编译keepalived不会出现上述警告和其他错误,执行make && make install命令进行安装:

[root@iZ256w2hluuZ keepalived-1.3.5]# make && make install

至此Keepalived编译并安装结束,在下一篇文章中会详解介绍Nginx搭配Keepalived的详细配置和使用方法,欢迎大家收藏本站素文宅博客。


使用命令 /usr/local/keepalived/sbin -h 参看各启动参数,启动命令:

[root@iZ256w2hluuZ keepalived-1.3.5]# ./sbin/keepalived -f /usr/local/keepalived/etc/keepalived.conf

 

制作快捷启动,在源文件的目录./keepalived-1.3.5/keepalived/etc/init.d下有两个个快捷启动文件和生成/usr/local/keepalived目录下一个配置文件需要复制,具体执行如下命令:

[root@iZ256w2hluuZ keepalived-1.3.5]#  cp ./keepalived-1.3.5/keepalived/etc/init.d/keepalived /etc/init.d/
[root@iZ256w2hluuZ keepalived-1.3.5]#  cp  /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
[root@iZ256w2hluuZ keepalived-1.3.5]#  cp ./keepalived-1.3.5/keepalived/etc/sysconfig/keepalived /etc/sysconfig/keepalived

这样就可以执行service keepalived [start | stop | reload | restart ]命令。


启动报“Starting keepalived: /bin/bash: keepalived: command not found”错误,具体日志如下:

[root@yoodb /]# service keepalived start
正在启动 keepalived:/bin/bash: keepalived: command not found
                                                           [失败]

解决方案:

[root@yoodb /]# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
[root@yoodb /]# service keepalived start
正在启动 keepalived:                                      [确定]
[root@yoodb /]# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/

有上述日志信息,表示启动成功。

评论

  1. #1

    你笑的好勉强 (2017/08/21 10:15:46)回复
    文章写的不错,真的很好,666!Thanks♪(・ω・)ノ

  2. #2

    夜雨声烦 (2017/07/31 16:49:26)回复
    写的不错。。。。。帮助很大 感谢分享

  3. #3

    啥玩意 (2017/07/31 16:49:05)回复
    啥玩意?表示看不懂,这个有什么用能做什么吗?

    路人甲 (2017/07/31 16:59:20)回复
    负载均衡,双节点nginx配置方案,之后等你工作久了也会接触。

    不胖不换ID (2017/09/11 11:31:58)回复
    顶顶,自己弄了一天都没搞好,百度搜索了半天才找到,非常感谢。收藏了,以后没事光顾一下。嘿嘿。!

分享:

支付宝

微信