yyyll 发表于 2013-8-20 09:11:19

keepalived源码打包RPM

个人比较喜欢通过spec文件打包成RPM后,然后安装到生产环境当中,为了提高服务器的安全系数,个人不希望线上服务器安装gcc等编译工具。环境:rhel6u3以下操作在相应的测试机操作,打包完成后上传到相应的线上服务器
1.下载keepalived源码包
wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gztar xfz keepalived -C /tmp
2.安装rpmbuildyum -y install rpm-build
mkdir ~/rmpbuildcd ~/rpmbuildmkdir 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 pollerName: keepalivedVersion: 1.2.2---这个地方的版本号一定要和SOURCES中的源码包的版本一直,默认的需要需改Release: 5License: GPLGroup: Applications/SystemURL: http://www.keepalived.org/
Source0: http://www.keepalived.org/software/keepalived-%{version}.tar.gzBuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
BuildRequires: openssl-devel# We need both of these for proper LVS supportBuildRequires: kernel, kernel-develRequires(post): /sbin/chkconfigRequires(preun): /sbin/service, /sbin/chkconfigRequires(postun): /sbin/service
%descriptionThe main goal of the keepalived project is to add a strong & robust keepalivefacility to the Linux Virtual Server project. This project is written in C withmultilayer TCP/IP stack checks. Keepalived implements a framework based onthree family checks : Layer3, Layer4 & Layer5/7. This framework gives thedaemon the ability to check the state of an LVS server pool. When one of theservers of the LVS server pool is down, keepalived informs the linux kernel viaa setsockopt call to remove this server entry from the LVS topology. Inaddition keepalived implements an independent VRRPv2 stack to handle directorfailover. So in short keepalived is a userspace daemon for LVS cluster nodeshealthchecks 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 1fi

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

%post/sbin/chkconfig --add keepalived
%preunif [ $1 -eq 0 ]; then   /sbin/service keepalived stop &>/dev/null || :   /sbin/chkconfig --del keepalivedfi
%postunif [ $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.安装测试软件包是否有问题。

狐狸情 发表于 2013-8-20 23:37:28

有竞争才有进步嘛

奥尔覅几22 发表于 2013-8-21 08:23:02

鸳鸳相抱何时了,鸯在一边看热闹。

uf123 发表于 2013-8-21 17:34:35

我是来刷分的,嘿嘿

4591566 发表于 2013-8-22 06:24:35

勿以坑小而不灌,勿以坑大而灌之。

zhangli-s 发表于 2013-8-22 21:55:37

漏洞与补丁齐飞,蓝屏共死机一色!

xxxmenger 发表于 2013-8-23 05:34:24

我本非随便的人,但如果你想随便,那我就随你的便好啦!
页: [1]
查看完整版本: keepalived源码打包RPM