上一节我们讲到了keepalived的基本介绍以及其工作原理及相关组成部分,本小节,我们将会讲到keepalived的相关./configure,编译,安装等介绍

一. 编译安装keepalived

1.1 keepalived的源码获取 

keepalived源码包我们可以到keepalived的官网:http://www.keepalived.org/去下载,相关说明文档亦可在其官网查看,比如keepalived的使用,相关配置说明,这里演示的版本为:1.2.15


# wget http://www.keepalived.org/software/keepalived-1.2.15.tar.gz

1.2 安装keepalived的依赖包

下载后keepalived源码包后,我们还需要安装keepalived依赖的依赖包,比如:openssl  , popt 

# yum install openssl  openssl-devel  popt popt-devel

1.3 编译,安装keepalived

<--编译安装keepalived-->

# tar zxvf keepalived-1.2.15.tar.gz -C /usr/local/src
# cd /usr/local/src/keepalived-1.2.15/
# ./configure \
  --prefix=/usr/local/keepalived \
  --sbindir=/usr/local/keepalived/sbin  
# make 
# make install

<--对keepalived进行相关优化-->

<---拷贝keepalived相关启动命令--->
# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
<---将keepalived启动脚本添加到系统服务--->
# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
# chkconfig --add keepalived
# chkconfig --level 2345 keepalived on
<---创建keepalived相关配置文件--->
# mkdir -p /etc/keepalived
# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived

备注说明:
1.keepalived安装完成后,安装目录为:/usr/lccal/keepalived, 配置文件路径为:/etc/keepalive/
2.安装完成后,需要将启动脚本复制到/etc/ini.d/下
3.注意一定要执行述上的相关操作,不然有可能导致keepalived服务起不来
4.关于keepalived相关./configure等参数我们可以利用:./configure --help来查看,以下为keepalived的./configure相关参数说明如下

Configuration:
 -h, --help              display this help and exit
     --help=short        display options specific to this package
     --help=recursive    display the short help of all the included packages
 -V, --version           display version information and exit
 -q, --quiet, --silent   do not print `checking ...' messages
     --cache-file=FILE   cache test results in FILE [disabled]
 -C, --config-cache      alias for `--cache-file=config.cache'
 -n, --no-create         do not create output files
     --srcdir=DIR        find the sources in DIR [configure dir or `..']

Installation directories:
 --prefix=PREFIX         install architecture-independent files in PREFIX
                         [/usr/local]
 --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                         [PREFIX]

By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc.  You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
 --bindir=DIR            user executables [EPREFIX/bin]
 --sbindir=DIR           system admin executables [EPREFIX/sbin]
 --libexecdir=DIR        program executables [EPREFIX/libexec]
 --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
 --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
 --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
 --libdir=DIR            object code libraries [EPREFIX/lib]
 --includedir=DIR        C header files [PREFIX/include]
 --oldincludedir=DIR     C header files for non-gcc [/usr/include]
 --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
 --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
 --infodir=DIR           info documentation [DATAROOTDIR/info]
 --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
 --mandir=DIR            man documentation [DATAROOTDIR/man]
 --docdir=DIR            documentation root [DATAROOTDIR/doc/PACKAGE]
 --htmldir=DIR           html documentation [DOCDIR]
 --dvidir=DIR            dvi documentation [DOCDIR]
 --pdfdir=DIR            pdf documentation [DOCDIR]

 --psdir=DIR        ps documentation [DOCDIR]

Optional Features:
 --disable-option-checking  ignore unrecognized --enable/--with options
 --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
 --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
 --disable-lvs-syncd     do not use LVS synchronization daemon
 --disable-lvs           do not use the LVS framework
 --disable-vrrp          do not use the VRRP framework
 --disable-fwmark        compile without SO_MARK support
 --enable-snmp           compile with SNMP support
 --enable-sha1           compile with SHA1 support
 --enable-debug          compile with debugging flags
 --enable-profile        compile with profiling flags

Optional Packages:
 --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
 --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
 --with-kernel-dir=DIR   path to linux kernel source directory
 --with-kernel-version=VER forced value for linux kernel version (VER=2.4|2.6)

Some influential environment variables:
 CC          C compiler command
 CFLAGS      C compiler flags
 LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
             nonstandard directory <lib dir>
 LIBS        libraries to pass to the linker, e.g. -l<library>

 CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
             you have headers in a nonstandard directory <include dir>
 CPP         C preprocessor

二:启动keepalived服务

# service keepalived start
如果keepalived已经启动,这时我们就可以查看以下命令查看启动情况:
# service keepalived status  

# ps aux | grep keepalived

到这里,keepalived部署基本OK,下一章,我们将会讲到keepalived相关配置