bmwm3 发表于 2018-12-29 07:27:42

keepalived源码打包RPM

  个人比较喜欢通过spec文件打包成RPM后,然后安装到生产环境当中,为了提高服务器的安全系数,个人不希望线上服务器安装gcc等编译工具。
  环境:rhel6u3
http://blog.运维网.com/attachment/201308/114307972.png
  以下操作在相应的测试机操作,打包完成后上传到相应的线上服务器
  

  1.下载keepalived源码包
  

  wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gz
  tar xfz keepalived -C /tmp
  

  2.安装rpmbuild
  yum -y install rpm-build
  

  mkdir ~/rmpbuild
  cd ~/rpmbuild
  mkdir BUILD BUILDROOT RPMS SOURCES SPECS
  

  

  3.copy sepc文件和源码包到相应的目录中
  cp /tmp/keepalved-1.2.7.tar.gz ~/rpmbuild/SOURCES/
  cp /tmp/keepalived/keepalived.spec.in ~/rpmbuild/SPECS/keepalived.spec
  

  4.根据自己的需求修改keepalived.spec
  %define kernel %(rpm -q kernel-devel --qf '%{RPMTAG_VERSION}-%{RPMTAG_RELEASE}\\n' 2>/dev/null | head -1)
  

  Summary: HA monitor built upon LVS, VRRP and services poller
  Name: keepalived
  Version: 1.2.2---这个地方的版本号一定要和SOURCES中的源码包的版本一直,默认的需要需改
  Release: 5
  License: GPL
  Group: Applications/System
  URL: http://www.keepalived.org/
  

  Source0: http://www.keepalived.org/software/keepalived-%{version}.tar.gz
  BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
  

  BuildRequires: openssl-devel
  # We need both of these for proper LVS support
  BuildRequires: kernel, kernel-devel
  Requires(post): /sbin/chkconfig
  Requires(preun): /sbin/service, /sbin/chkconfig
  Requires(postun): /sbin/service
  

  %description
  The main goal of the keepalived project is to add a strong & robust keepalive
  facility to the Linux Virtual Server project. This project is written in C with
  multilayer TCP/IP stack checks. Keepalived implements a framework based on
  three family checks : Layer3, Layer4 & Layer5/7. This framework gives the
  daemon the ability to check the state of an LVS server pool. When one of the
  servers of the LVS server pool is down, keepalived informs the linux kernel via
  a setsockopt call to remove this server entry from the LVS topology. In
  addition keepalived implements an independent VRRPv2 stack to handle director
  failover. So in short keepalived is a userspace daemon for LVS cluster nodes
  healthchecks and LVS directors failover.
  

  

  %prep
  %setup
  

  

  %build
  %{?el3:export CPPFLAGS="-I/usr/kerberos/include"}
  %{?rh9:export CPPFLAGS="-I/usr/kerberos/include"}
  %configure \
  %{?el3:--includedir="/usr/kerberos/include"} \
  %{?rh9:--includedir="/usr/kerberos/include"} \
  --with-kernel-dir="/lib/modules/%{kernel}/build"
  %{__make} %{?_smp_mflags} STRIP=/bin/true
  

  

  %install
  %{__rm} -rf %{buildroot}
  %{__make} install DESTDIR=%{buildroot}
  # Remove "samples", as we include them in %%doc
  %{__rm} -rf %{buildroot}%{_sysconfdir}/keepalived/samples/
  

  %check
  # A build could silently have LVS support disabled if the kernel includes can't
  # be properly found, we need to avoid that.
  if ! grep -q "IPVS_SUPPORT='_WITH_LVS_'" config.log; then
  echo "ERROR: We do not want keeepalived lacking LVS support."
  exit 1
  fi
  

  

  %clean
  %{__rm} -rf %{buildroot}
  

  

  %post
  /sbin/chkconfig --add keepalived
  

  %preun
  if [ $1 -eq 0 ]; then
  /sbin/service keepalived stop &>/dev/null || :
  /sbin/chkconfig --del keepalived
  fi
  

  %postun
  if [ $1 -ge 1 ]; then
  /sbin/service keepalived condrestart &>/dev/null || :
  fi
  

  

  %files
  %defattr(-, root, root, 0755)
  %doc AUTHOR ChangeLog CONTRIBUTORS COPYING README TODO
  %doc doc/keepalived.conf.SYNOPSIS doc/samples/
  %dir %{_sysconfdir}/keepalived/
  %attr(0600, root, root) %config(noreplace) %{_sysconfdir}/keepalived/keepalived.conf
  %attr(0600, root, root) %config(noreplace) %{_sysconfdir}/sysconfig/keepalived
  %{_sysconfdir}/rc.d/init.d/keepalived
  %{_bindir}/genhash
  %{_sbindir}/keepalived
  %{_mandir}/man1/genhash.1*
  %{_mandir}/man5/keepalived.conf.5*
  %{_mandir}/man8/keepalived.8*
  

  

  %changelog
  

  

  5.通过rpmbuild生成rpm包
  rpmbuild -ba keepalived.spec 稍等片刻就OK了
  

  6.rpm会自动放到RPMS的目录中
  

  7.安装测试软件包是否有问题。
  




页: [1]
查看完整版本: keepalived源码打包RPM