Friday, October 17, 2008

Building rpm for memcached

We had to come up with an install base for our production server based on CentOS 5.2 and one of the components required was memcached. I could not find a rpm for memcached on CentOS 5.2. The memcached website just lets you download the source tarball to build on the destination system. We didn't want to include any development tools on the production server for security reasons. So here's how we went to build a rpm for ourselves.

Steps:
  1. Have a CentOS 5.2 development system created with gcc which will be required to build the rpm
  2. Download the memcached tarball and copy it to /usr/src/redhat/SOURCES/
  3. Create a rpmbuild spec file as below. Call it memcached.spec.
  4. Run the command "rpmbuild -ba memcached.spec" on it. This command will build three rpm files - for the binary, for sources and one with debuginfo.
  5. Copy the rpms from /usr/src/redhat/RPMS/ and /usr/src/redhat/SRPMS/. These can now be distributed to the production systems and installed.

Summary: Memcached Server
Name: memcached
Version: 1.2.6
Release: 1
Source0: %{name}-%{version}.tar.gz
License: BSD
Group: Applications/Databases
BuildRoot: %{_builddir}/%{name}-root
%description
memcached is a high-performance, distributed memory object caching system.
%prep
%setup -q
%build
./configure
make
%install
rm -rf $RPM_BUILD_ROOT
make DESTDIR=$RPM_BUILD_ROOT install
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root)
/usr/local/bin/memcached
/usr/local/bin/memcached-debug
/usr/local/share/man/man1/memcached.1
%doc COPYING AUTHORS README NEWS

One hurdle I faced with rpmbuild was that it was introducing a dependency for a version of libevent that was seemingly not present on our systems. It was inserting a dependency to libevent 1.3 whereas if I do a "rpm -qa" it showed only libevent 1.1. Eventually a ldd of the memcached binary showed that it was linked to libevent in /usr/local/lib which was of version 1.3. It must have been installed manually and not through rpms.

No comments: