2012年1月19日木曜日

keepalived の rpm を作る

keepalived (http://www.keepalived.org/) の rpm を作るにあたり、KLab さんの「Keepalived のヘルスチェックを強化するパッチ」 を組み込んでみました。KLab さん、ありがとうございます。

keepalived のホームページへ行くと「2011-01-16 Release 1.2.2 - IPv6 Ready !」とありますが、RHEL5 では残念ながらコンパイルできませんでした。ソース全般に手を入れており、上記のパッチも、コンパイルエラーの内容を見てみると、すぐに動かないのがわかる、といった感じです。

最新よりひとつ前のバージョンの keepalived-1.2.1.tar.gz から rpm を作ります。
開発環境や開発用ライブラリ(openssl-devel)のインストールが済んでいる状態からの手順となります。一般ユーザ(とりあえず、mockbuild ユーザ、なんでもよい)で rpm をビルドするための設定とディレクトリを作成します。

$ mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
$ vi ~/.rpmmacros

<~/.rpmmacros>
1
2
3
4
5
6
7
8
%_topdir        /home/mockbuild/rpmbuild
%_sourcedir     %{_topdir}/SOURCES/%{name}
%_specdir       %{_topdir}/SPECS
%_builddir      %{_topdir}/BUILD
%_rpmdir        %{_topdir}/RPMS
%_srcrpmdir     %{_topdir}/SRPMS
%_query_all_fmt %%{name}-%%{version}-%%{release}.%%{arch}
%dist           .el5pcs

1行目だけあればとりあえず構築はできます。絶対パスで記載します。「~/rpmbuild」としてもビルドに失敗します。
2行目に「%{name}」を入れた勢いで3~6行目を記載しています。ソースファイルとそのパッチごとにディレクトリを分けておかないとパッチファイルの分別が非常に困難になるのでソース保存ディレクトリはパッケージ名を入れるようにしました。できたらバージョン番号もディレクトリ名に入れたかったのですが、ビルドできないパッケージが多いのであきらめました。
7行目は rpm コマンドでクエリした際のパッケージ名のフォーマットをデフォルトから変更しています。
8行目は、パッケージを Private build する際に rpm 名の中に Red Hat 社謹製の rpm ではないことがわかるような文言を入れたい、ということで定義しています。

keepalived の rpm を以下のように作成しました。

$ mkdir -p ~/rpmbuild/SOURCES/keepalived
$ wget -O ~/rpmbuild/SOURCES/keepalived/keepalived-1.2.1.tar.gz \
> http://www.keepalived.org/software/keepalived-1.2.1.tar.gz
(略)
2012-01-18 17:07:58 (135 KB/s) - `/home/mockbuild/rpmbuild/SOURCES/keepalived/keepalived-1.2.1.tar.gz' saved [239438/239438]

$ wget -O ~/rpmbuild/SOURCES/keepalived/keepalived-extcheck.patch \
> http://log.blog.klab.org/support/20070601/keepalived-extcheck.patch
(略)
2012-01-18 17:08:06 (930 KB/s) - `/home/mockbuild/rpmbuild/SOURCES/keepalived/keepalived-extcheck.patch' saved [47746/47746]

$ tar xzvf ~/rpmbuild/SOURCES/keepalived/keepalived-1.2.1.tar.gz \
> keepalived-1.2.1/keepalived.spec.in
keepalived-1.2.1/keepalived.spec.in
$ mv keepalived-1.2.1/keepalived.spec.in .
$ rmdir keepalived-1.2.1
$ patch << 'EOF'
> --- keepalived.spec.in  2010-12-28 22:32:42.000000000 +0900
> +++ keepalived.spec     2011-09-12 19:15:38.000000000 +0900
> @@ -7,12 +7,13 @@
Summary: HA monitor built upon LVS, VRRP and services poller
Name: keepalived
Version: 1.2.1
> -Release: 5
> +Release: 6%{dist}
License: GPL
Group: Applications/System
URL: http://www.keepalived.org/
>
Source0: http://www.keepalived.org/software/keepalived-%{version}.tar.gz
> +Patch0: http://log.blog.klab.org/support/20070601/keepalived-extcheck.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
>
BuildRequires: openssl-devel
> @@ -37,7 +38,7 @@
>
%prep
%setup
> -
> +%patch0 -p1
>
%build
%{?el3:export CPPFLAGS="-I/usr/kerberos/include"}
> @@ -99,6 +100,10 @@
>
>
%changelog
> +* Mon Sep 12 2011 dba@ha <hamada.pcserver.jp@gmail.com> 1.2.1
> +- Add KLab's Patch.
> +- http://dsas.blog.klab.org/archives/51030424.html
> +
* Thu Sep 13 2007 Alexandre Cassen <acassen@linux-vs.org> 1.1.14
- Merge work done by freshrpms.net... Thanks guys !!! ;)
> EOF
patching file keepalived.spec.in
$ mv keepalived.spec.in ~/rpmbuild/SPECS/keepalived.spec
$ cat ~/rpmbuild/SPECS/keepalived.spec

<~/rpmbuild/SPECS/keepalived.spec>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# $Id$
# Authority: dag

# Ugly, but we need headers from a kernel to rebuild against
%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.1
Release: 6%{dist}
License: GPL
Group: Applications/System
URL: http://www.keepalived.org/

Source0: http://www.keepalived.org/software/keepalived-%{version}.tar.gz
Patch0: http://log.blog.klab.org/support/20070601/keepalived-extcheck.patch
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
%patch0 -p1

%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
* Mon Sep 12 2011 dba@ha <hamada.pcserver.jp@gmail.com> 1.2.1
- Add KLab's Patch.
- http://dsas.blog.klab.org/archives/51030424.html

* Thu Sep 13 2007 Alexandre Cassen <acassen@linux-vs.org> 1.1.14
- Merge work done by freshrpms.net... Thanks guys !!! ;)

* Wed Feb 14 2007 Matthias Saou <http://freshrpms.net/> 1.1.13-5
- Add missing scriplet requirements.

* Tue Feb 13 2007 Matthias Saou <http://freshrpms.net/> 1.1.13-4
- Add missing \n to the kernel define, for when multiple kernels are installed.
- Pass STRIP=/bin/true to "make" in order to get a useful debuginfo package.

* Tue Feb 13 2007 Matthias Saou <http://freshrpms.net/> 1.1.13-3
- Add %%check section to make sure any build without LVS support will fail.

* Mon Feb  5 2007 Matthias Saou <http://freshrpms.net/> 1.1.13-2
- Use our own init script, include a sysconfig entry used by it for options.

* Thu Jan 25 2007 Matthias Saou <http://freshrpms.net/> 1.1.13-1
- Update to 1.1.13.
- Change mode of configuration file to 0600.
- Don't include all of "doc" since it meant re-including all man pages.
- Don't include samples in the main configuration path, they're in %%doc.
- Include patch to add an optional label to interfaces.

* Sat Apr 08 2006 Dries Verachtert <dries@ulyssis.org> - 1.1.12-1.2
- Rebuild for Fedora Core 5.

* Sun Mar 12 2006 Dag Wieers <dag@wieers.com> - 1.1.12-1
- Updated to release 1.1.12.

* Fri Mar 04 2005 Dag Wieers <dag@wieers.com> - 1.1.11-1
- Updated to release 1.1.11.

* Wed Feb 23 2005 Dag Wieers <dag@wieers.com> - 1.1.10-2
- Fixed IPVS/LVS support. (Joe Sauer)

* Tue Feb 15 2005 Dag Wieers <dag@wieers.com> - 1.1.10-1
- Updated to release 1.1.10.

* Mon Feb 07 2005 Dag Wieers <dag@wieers.com> - 1.1.9-1
- Updated to release 1.1.9.

* Sun Oct 17 2004 Dag Wieers <dag@wieers.com> - 1.1.7-2
- Fixes to build with kernel IPVS support. (Tim Verhoeven)

* Fri Sep 24 2004 Dag Wieers <dag@wieers.com> - 1.1.7-1
- Updated to release 1.1.7. (Mathieu Lubrano)

* Mon Feb 23 2004 Dag Wieers <dag@wieers.com> - 1.1.6-0
- Updated to release 1.1.6.

* Mon Jan 26 2004 Dag Wieers <dag@wieers.com> - 1.1.5-0
- Updated to release 1.1.5.

* Mon Dec 29 2003 Dag Wieers <dag@wieers.com> - 1.1.4-0
- Updated to release 1.1.4.

* Fri Jun 06 2003 Dag Wieers <dag@wieers.com> - 1.0.3-0
- Initial package. (using DAR)



$ rpmbuild -ba ~/rpmbuild/SPECS/keepalived.spec
(略)
Patch #0 (keepalived-extcheck.patch):
(略)
Keepalived configuration
------------------------
Keepalived version       : 1.2.1
Compiler                 : gcc
Compiler flags           : -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -DETHERTYPE_IPV6=0x86dd
Extra Lib                : -lpopt -lssl -lcrypto
Use IPVS Framework       : Yes
IPVS sync daemon support : Yes
Use VRRP Framework       : Yes
Use Debug flags          : No
(略)
Wrote: /home/mockbuild/rpmbuild/SRPMS/keepalived-1.2.1-6.el5pcs.src.rpm
Wrote: /home/mockbuild/rpmbuild/RPMS/x86_64/keepalived-1.2.1-6.el5pcs.x86_64.rpm
Wrote: /home/mockbuild/rpmbuild/RPMS/x86_64/keepalived-debuginfo-1.2.1-6.el5pcs.x86_64.rpm


0 件のコメント:

コメントを投稿