1. 程式人生 > >cenos/Red Hat 7.4 編譯keepalived,生成rpm包

cenos/Red Hat 7.4 編譯keepalived,生成rpm包

接下來解壓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, <www.openssl.org>

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<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

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 <[email protected]>. Keepalived home page: <http://www.keepalived.org/>.

我這裡新建了bld目錄,並在其中進行編譯。

[[email protected] keepalived-2.0.7]# pwd /root/keepalived-2.0.7 [[email protected] keepalived-2.0.7]# mkdir bld [[email protected] keepalived-2.0.7]# cd bld [[email protected] 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前面的字首設定為#或者空。如果啟用,則設定為空;如果禁用,則#就相當於將對應項註釋掉了,不起作用。

@[email protected]: pcre2-devel @[email protected]: pcre2

@[email protected]_OPTS="$CONFIG_OPTS --enable-regex"

還需要建幾個資料夾,在rpmbuild打包過程中會用到,而且打出來的rpm包也放在其中的RPMS資料夾下:

[[email protected] rpmbuild]# pwd /root/rpmbuild [[email protected] 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 [[email protected] rpmbuild]# 

然後開始打rpm包。等待輸出結束,沒有報錯就可以了。

make rpm

這裡值得說一些的地方就是,這裡生成的Makefile提供了多個target,具體的選項可以通過grep ':' Makefile檢視。