编译keepalived-1.2.2的问题及解决方法

编译keepalived-1.2.2的时候遇到几个问题,在网上找了一下得以解决,备忘。

问题1:

ip_vs.h:19:31: error: netlink/genl/genl.h: No such file or directory
ip_vs.h:20:31: error: netlink/genl/ctrl.h: No such file or directory

这个时候需要安装libnl:
wget http://www.infradead.org/~tgr/libnl/files/libnl-1.1.tar.gz

不要用yum install这个方式安装,libnl.i386 libnl-devel.i386这两个的版本不够高。
如果已经通过yum install libnl.i386 libnl-devel.i386, 则要把/usr/lib/下面libnl相关的库删掉,不然会出现下面的错误:

libipvs-2.6/libipvs.a(libipvs.o): In function `ipvs_timeout_parse_cb':
/other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:953: undefined reference to `genlmsg_parse'
libipvs-2.6/libipvs.a(libipvs.o): In function `ipvs_getinfo_parse_cb':
/other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:141: undefined reference to `genlmsg_parse'
libipvs-2.6/libipvs.a(libipvs.o): In function `ipvs_daemon_parse_cb':
/other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:1010: undefined reference to `genlmsg_parse'
/other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:1023: undefined reference to `nla_get_string'
libipvs-2.6/libipvs.a(libipvs.o): In function `ipvs_dests_parse_cb':
/other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:714: undefined reference to `genlmsg_parse'
libipvs-2.6/libipvs.a(libipvs.o): In function `ipvs_services_parse_cb':
/other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:554: undefined reference to `genlmsg_parse'
/other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:587: undefined reference to `nla_get_string'
libipvs-2.6/libipvs.a(libipvs.o): In function `ipvs_nl_send_message':
/other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:72: undefined reference to `genl_connect'
/other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:75: undefined reference to `genl_ctrl_resolve'
/other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:86: undefined reference to `nl_socket_modify_cb'
/other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:92: undefined reference to `nl_recvmsgs_default'
libipvs-2.6/libipvs.a(libipvs.o): In function `ipvs_nl_message':
/other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:49: undefined reference to `nlmsg_alloc'
/other/keepalived-1.2.2/keepalived/libipvs-2.6/libipvs.c:53: undefined reference to `genlmsg_put'

问题2:

/usr/include/sys/types.h:62: error: conflicting types for ‘dev_t’
/usr/include/linux/types.h:13: error: previous declaration of ‘dev_t’ was here
...
make: *** [othptab.o] Error 1

从网上找了资料后找到解决办法,具体如下:
vim keepalived/libipvs-2.6/ip_vs.h
把#include linux/types.h /* For __beXX types in userland */
移到#include sys/types.h 这行的下面
再编译就可以通过了。