首先下载keepalived-2.0.7,地址http://www.keepalived.org/download.html
接下来解压keepalived-2.0.7.tar.gz
tar -xzpvf keepalived-2.0.7.tar.gz
cd keepalived-2.0.7
目录中有个INSTALL的文件,我们先打开。可以看到如果是red hat系列的linux,需要安装一些包。对于file-devel、 net-snmp-devel、net-snmp-devel、glib2-devel、json-c-devel、pcre2-devel以及后面说的一些包,都是根据特定的需求需要安装的一些包,根据需要安装。
Library dependencies
====================
In order to compile Keepalived needs the following libraries :
* OpenSSL,
Linux flavours
==============
RedHat based systems (RedHat Enterprise/CentOS/Fedora)
------------------------------------------------------
The following libraries need to be installed:
openssl-devel libnl3-devel ipset-devel iptables-devel libnfnetlink-devel
For magic file identification support:
file-devel
For SNMP support:
net-snmp-devel
For DBUS support:
glib2-devel
For JSON support:
json-c-devel
For PCRE support
pcre2-devel
For building the documentation, the following packages need to be installed:
Fedora: python-sphinx (will pull in: python2-sphinx_rtd_theme)
CentOS-and-friends: python-sphinx epel-release python-sphinx_rtd_theme
For latex or pdf files, the following are also needed:
Fedora: latexmk python-sphinx-latex
CentOS-and-friends: latexmk texlive texlive-titlesec texlive-framed texlive-threeparttable texlive-wrapfig texlive-multirow
主要的,编译过程中需要gcc编译器,我这里gcc的版本是gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)。如果是较低的版本,可能有问题。打包rpm需要rpmbuild这个工具,也需要安装rpm-build-4.11.3-32.el7.x86_64。
先看看configure有哪些选项,下面这些选项大家根据自己需要选择,通常默认的就可以满足需求了。
需要重点说一下的就是最后的Some influential environment variables的部分,这里是通过设置环境变量来影响configure的过程。主要的可以设置CC这个env。例如export CC=g++ 。
`configure' configures Keepalived 2.0.7 to adapt to many kinds of systems.
Usage: ./configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
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]
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
--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/keepalived]
--htmldir=DIR html documentation [DOCDIR]
--dvidir=DIR dvi documentation [DOCDIR]
--pdfdir=DIR pdf documentation [DOCDIR]
--psdir=DIR ps documentation [DOCDIR]
Program names:
--program-prefix=PREFIX prepend PREFIX to installed program names
--program-suffix=SUFFIX append SUFFIX to installed program names
--program-transform-name=PROGRAM run sed PROGRAM on installed program names
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]
--enable-silent-rules less verbose build output (undo: "make V=1")
--disable-silent-rules verbose build output (undo: "make V=0")
--disable-lvs-syncd do not use LVS synchronization daemon
--disable-lvs do not use the LVS framework
--disable-lvs-64bit-stats
do not use the LVS 64-bit stats
--disable-vrrp do not use the VRRP framework
--enable-bfd use the BFD framework
--disable-fwmark compile without SO_MARK support
--enable-snmp compile with SNMP support
--enable-snmp-vrrp compile with SNMP vrrp support
--enable-snmp-keepalived
obsolete - use --enable-snmp-vrrp
--enable-snmp-checker compile with SNMP checker support
--enable-snmp-rfc compile with SNMP RFC2787 (VRRPv2) and SNMP RFC6527
(VRRPv3) support
--enable-snmp-rfcv2 compile with SNMP RFC2787 (VRRPv2) support
--enable-snmp-rfcv3 compile with SNMP RFC6257 (VRRPv3) support
--disable-snmp-reply-v3-for-v2
disable RFC6257 responses for VRRPv2 instances
--enable-dbus compile with dbus support
--enable-dbus-create-instance
compile with dbus support for creating instances
--enable-sha1 compile with SHA1 support
--enable-regex build with HTTP_GET regex checking
--enable-regex-timers build with HTTP_GET regex timers
--enable-json compile with signal to dump configuration and stats
as json
--disable-vrrp-auth compile without VRRP authentication
--disable-checksum-compat
compile without v1.3.6 and earlier VRRPv3 unicast
checksum compatibility
--disable-routes compile without ip rules/routes
--enable-gnu-std-paths use GNU standard paths for pid files etc
--enable-dynamic-linking
compile with/without dynamically linked
libiptc/libipset
--enable-libiptc-dynamic
compile with libiptc dynamically linked
--disable-libipset-dynamic
compile with libipset statically linked
--enable-libxtables-dynamic
compile with libxtables dynamically linked
--enable-libnl-dynamic compile with libnl dynamically linked
--disable-libiptc compile without libiptc
--disable-libipset compile without libipset
--disable-libnl compile without libnl
--enable-strict-config-checks
build with strict configuration checking
--disable-hardening do not build with security hardening
--optimise compiler optimisation level
--enable-mem-check compile with memory alloc checking
--enable-mem-check-log compile with memory alloc checking writing to syslog
--enable-debug compile with debugging flags
--enable-netlink-timers compile with netlink command timers
--enable-smtp-alert-debug
compile with smtp-alert debugging
--enable-stacktrace compile with stacktrace support
--enable-dump-threads compile with thread dumping support
--enable-select-debug compile with select debugging support
--enable-regex-debug compile with regex debugging support
--enable-tsm-debug compile with TSM debugging support
--enable-timer-debug compile with timer debugging support
--enable-profile compile with profiling flags
--enable-conversion-checks
compile with conversion warnings if sensible
--enable-force-conversion-checks
compile with conversion warnings
--enable-Werror compile with warnings being errors
--enable-dependency-tracking
do not reject slow dependency extractors
--disable-dependency-tracking
speeds up one-time build
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-init=(upstart|systemd|SYSV|SUSE|openrc)
specify init type
--with-systemdsystemunitdir=DIR
Directory for systemd service files
Some influential environment variables:
PKG_CONFIG path to pkg-config utility
PKG_CONFIG_PATH
directories to add to pkg-config's search path
PKG_CONFIG_LIBDIR
path overriding pkg-config's built-in search path
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L
nonstandard directory
LIBS libraries to pass to the linker, e.g. -l
CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I
you have headers in a nonstandard directory
CPP C preprocessor
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
Report bugs to
Keepalived home page:
我这里新建了bld目录,并在其中进行编译。
[root@MYSQL1 keepalived-2.0.7]# pwd
/root/keepalived-2.0.7
[root@MYSQL1 keepalived-2.0.7]# mkdir bld
[root@MYSQL1 keepalived-2.0.7]# cd bld
[root@MYSQL1 bld]# pwd
/root/keepalived-2.0.7/bld
../configure --enable-snmp-checker --enable-snmp --enable-snmp-vrrp --enable-bfd --enable-snmp-rfc --enable-snmp-rfcv2 --enable-snmp-rfcv3 --enable-dbus --enable-sha1 --enable-regex --enable-regex-timers --enable-dependency-tracking --enable-json --enable-stacktrace --enable-dump-threads --enable-select-debug --enable-regex-debug --enable-tsm-debug --enable-strict-config-checks
可以看到一些输出,启用和禁用的选项。
没问题的话,就进入打包过程。2.0.7这个tar文件中有一个keepalived.spec.in文件,打rpm包主要就是靠着个文件。
需要注意的是,keepalived.spec.in这个文件有两处错误,如果不修改的话,会造成rpm打包失败。注意下面几行,需要将@WITH_REGEX修改为@WITH_REGEX_TRUE。具体原因,大家可以在上面configure的时候,使用sh -x ../configure跟踪一下这个执行过程就可以发现:在根据keepalived.spec.in生成keepalived.spec的过程中,是根据我们设置的一些开关,来动态的将BuildRequires前面的前缀设置为#或者空。如果启用,则设置为空;如果禁用,则#就相当于将对应项注释掉了,不起作用。
@WITH_REGEX@BuildRequires: pcre2-devel
@WITH_REGEX@Requires: pcre2
@WITH_REGEX@CONFIG_OPTS="$CONFIG_OPTS --enable-regex"
还需要建几个文件夹,在rpmbuild打包过程中会用到,而且打出来的rpm包也放在其中的RPMS文件夹下:
[root@MYSQL1 rpmbuild]# pwd
/root/rpmbuild
[root@MYSQL1 rpmbuild]# ls -l
total 0
drwxr-xr-x 3 root root 30 Oct 24 11:02 BUILD
drwxr-xr-x 2 root root 6 Oct 24 11:03 BUILDROOT
drwxr-xr-x 3 root root 20 Oct 24 11:03 RPMS
drwxr-xr-x 2 root root 37 Oct 24 10:22 SOURCES
drwxr-xr-x 2 root root 6 Oct 24 10:21 SPECS
drwxr-xr-x 2 root root 40 Oct 24 11:03 SRPMS
[root@MYSQL1 rpmbuild]#
然后开始打rpm包。等待输出结束,没有报错就可以了。
make rpm
这里值得说一些的地方就是,这里生成的Makefile提供了多个target,具体的选项可以通过grep ':' Makefile查看。