lvs+keepalived离线安装包安装

一、ipvsadm安装

1,安装环境centos7.0内核3.10.0-327.el7.x86_64 。需安装gcc
[root@localhost ~]# yum -y install gcc

未避免安装过程安全其他依赖,可在安装系统时选择如下几个组件:

wKioL1fH0HzgZfZ0AAA-DJ2pRLw484.png

wKiom1fH0H3Aax07AABjkkVw6rE348.png

2,下载ipvsadm安装包(下载1.27版本)

https://kernel.org/pub/linux/utils/kernel/ipvsadm/

3,解压、编译、安装
[root@localhost ~]# tar -Jxvf ipvsadm-1.27.tar.xz
[root@localhost ~]# cd ipvsadm-1.27
[root@localhost ipvsadm-1.27]# make && make install
4,可能出现如下错误:
[root@localhost ipvsadm-1.27]# make &make install
[1] 14264
make -C libipvs
make -C libipvs
make[1]: Entering directory`/root/ipvsadm-1.27/libipvs'
gcc -Wall -Wunused -Wstrict-prototypes -g-fPIC -DLIBIPVS_USE_NL  -DHAVE_NET_IP_VS_H  -c -olibipvs.o libipvs.c
make[1]: Entering directory`/root/ipvsadm-1.27/libipvs'
gcc -Wall -Wunused -Wstrict-prototypes -g-fPIC -DLIBIPVS_USE_NL  -DHAVE_NET_IP_VS_H  -c -olibipvs.o libipvs.c
In file included from libipvs.h:13:0,
                 from libipvs.c:23:
ip_vs.h:15:29: fatal error:netlink/netlink.h: No such file or directory
 #include 
                            ^
compilation terminated.
In file included from libipvs.h:13:0,
                 from libipvs.c:23:
ip_vs.h:15:29: fatal error:netlink/netlink.h: No such file or directory
 #include 
                             ^
compilation terminated.
make[1]: *** [libipvs.o] Error 1
make[1]: Leaving directory`/root/ipvsadm-1.27/libipvs'
make: *** [libs] Error 2
make[1]: *** [libipvs.o] Error 1
make[1]: Leaving directory`/root/ipvsadm-1.27/libipvs'
make: *** [libs] Error 2
[1]+ Exit 2                  make

解决方法是安装如下软件:

[root@localhost ipvsadm-1.27]# yum installpopt-static
[root@localhost ipvsadm-1.27]# yum installlibnl* libpopt*

 

二、keepalived安装

1)软件下载(下载1.2.13版本)

http://www.keepalived.org/software/

2)解压、配置、编译、安装
[root@localhost ~]# tar -zxvf keepalived-1.2.13\ \(1\).tar.gz
[root@localhost ~]# cd keepalived-1.2.13
[root@localhost keepalived-1.2.13]#./configure --prefix=/usr/local/keepalived
[root@localhost keepalived-1.2.13]# make && make install
3)编译时可能会出现如下错误1
configure: error:
  !!!OpenSSL is not properly installed on your system. !!!
  !!!Can not include OpenSSL headers files.            !!!

解决方法:

[root@localhost keepalived-1.2.13]# yuminstall -y openssl openssl-devel

 

4)编译过程可能会出现如下错误2
[root@localhost keepalived-1.2.13]# make
make -C lib || exit 1;
make[1]: Entering directory`/root/keepalived-1.2.13/lib'
gcc -g -O2 -DFALLBACK_LIBNL1 -I. -Wall-Wunused -Wstrict-prototypes -D_WITHOUT_SNMP_ -c command.c
make[1]: Leaving directory`/root/keepalived-1.2.13/lib'
make -C keepalived
make[1]: Entering directory`/root/keepalived-1.2.13/keepalived'
make[2]: Entering directory`/root/keepalived-1.2.13/keepalived/core'
gcc -g -O2 -DFALLBACK_LIBNL1  -I/usr/src/linux/include -I/usr/src/linux/include-I../include -I../../lib -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_-D_WITH_LVS_ -D_WITH_VRRP_ -D_WITHOUT_SNMP_ -D_WITH_SO_MARK_  -c main.c
gcc -g -O2 -DFALLBACK_LIBNL1  -I/usr/src/linux/include-I/usr/src/linux/include -I../include -I../../lib -Wall -Wunused-Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_WITH_VRRP_ -D_WITHOUT_SNMP_-D_WITH_SO_MARK_  -c smtp.c
In file included from/usr/include/linux/if_addr.h:4:0,
                 from../include/vrrp_ipaddress.h:33,
                 from ../include/vrrp.h:31,
                 from ../include/smtp.h:34,
                 from smtp.c:27:
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
/usr/src/linux/include/linux/linkage.h:7:25:fatal error: asm/linkage.h: No such file or directory
 #include 
                         ^
compilation terminated.
make[2]: *** [smtp.o] Error 1
make[2]: Leaving directory`/root/keepalived-1.2.13/keepalived/core'
make[1]: *** [all] Error 1
make[1]: Leaving directory`/root/keepalived-1.2.13/keepalived'
make: *** [all] Error 2

解决方法:

去掉如下符号链接(之前配置符号链接ln -s /usr/src/kernels/3.10.0-229.el7.x86_64/ /usr/src/linux

[root@localhost keepalived-1.2.13]# rm -rf /usr/src/linux
5)配置
[root@localhost keepalived]#cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
[root@localhost keepalived]#cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
[root@localhost keepalived]#mkdir /etc/keepalived
[root@localhost keepalived]#cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
[root@localhost keepalived]#cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
6)修改配置文件

/etc/keepalived/keepalived.conf

7)启动服务并开启开机自启动
[root@localhost keepalived]# service keepalived
Usage: /etc/init.d/keepalived{start|stop|reload|restart|condrestart|status}
[root@localhost keepalived]# chkconfig keepalived on
8)启动可能出现如下错误3
[root@localhost ~]# service keepalived status
 keepalived.service - SYSV:Start and stop Keepalived
  Loaded: loaded (/etc/rc.d/init.d/keepalived)
  Active: failed (Result: exit-code) since Wed 2016-08-31 07:22:19 EDT;5min ago
    Docs: man:systemd-sysv-generator(8)
 Process: 2405 ExecStart=/etc/rc.d/init.d/keepalived start (code=exited,status=1/FAILURE)
 
Aug 31 07:22:19 localhost.localdomainsystemd[1]: Starting SYSV: Start and stop Keepalived...
Aug 31 07:22:19 localhost.localdomainkeepalived[2405]: Starting keepalived: /bin/bash: keepalived: command not found
Aug 31 07:22:19 localhost.localdomainkeepalived[2405]: [FAILED]
Aug 31 07:22:19 localhost.localdomainsystemd[1]: keepalived.service: control process exited, code=exited status=1
Aug 31 07:22:19 localhost.localdomainsystemd[1]: Failed to start SYSV: Start and stop Keepalived.
Aug 31 07:22:19 localhost.localdomainsystemd[1]: Unit keepalived.service entered failed state.
Aug 31 07:22:19 localhost.localdomainsystemd[1]: keepalived.service failed.

解决方法:

[root@localhost ~]# ln -s/usr/local/keepalived/sbin/keepalived /usr/sbin/

其中/usr/local/keepalived/为软件安装目录。