Put your message here! Contact me for more information
 
 








 

This is a quick summary for this process so that I can refer to it later on, and hopefully someone will find it useful as well.

Memcached requires libevent to handle its network IO stuff. The bundled libevent in the standard yum repository is old so it’s pretty useless. The newer versions memcached runs on newer libevent library so I ended up compiling libevent and memcached from the latest stable sources. I’m using libevent-1.4.4-stable and memcached-1.2.5.

First off, uninstall the libevent that yum may have installed on your machine

# sudo yum remove libevent

Download the sources for libevent and memcached , unzip( # gunzip *.gz ), untar (# tar -xvf *.tar), CD to the libevent folder. We will compile the libevent first.

# ./configure –prefix=/usr/local

# make

# make install

Basically we are telling libevent to install itself under /usr/local/lib/. When we compile memcached, we need to point it to the correct location as well. Once libevent is done installing (it’s really quick), we can move on and complie memcached.

CD to the un-tar memcached folder,

# ./configure –with-lib-event=/usr/local/

# make

# make install

After memcached is installed, you can try

# memcached

In my situation, I ran into an error

error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory

It turned out that the new libevent get installed, it doesn’t “register” the actual library file (similar to DLL on Windows) with the system. When Memcached runs, it tries to look for the libevent-1.4.so.2 file but since libevent is still playing hide and seek somewhere, memcached cries.

To fix this, we need to manually load the libevent library file into the system via the ld configuration. From the man page of ld:

ld combines a number of object and archive files, relocates their data and ties up symbol references. Usually the last step in compiling a program is to run ld.

I like to think ld as the regsrv32 used to register DLL’s on Windows. Now to fix up the reference to the libevent so file, we need to create a file under /etc/ld.so.conf.d/

# vi /etc/ld.so.conf.d/libevent-i386.conf

then enter

/usr/local/lib/

Write and quit (:wq!)

The path in the libevent-i386.conf is the path where the actual .so files are located at. We set this path when we run the ./configure –prefix=/usr/local/ during the libevent compilation. Reloading the ld configuration with

# ldconfig

now, you can start memcached in verbose mode (-vv) for testing

# memcached -vv

If you see something like ..

slab class 1: chunk size 104 perslab 10082
slab class 2: chunk size 136 perslab 7710
slab class 3: chunk size 176 perslab 5957
slab class 4: chunk size 224 perslab 4681
slab class 5: chunk size 280 perslab 3744

….

slab class 37: chunk size 367192 perslab 2
slab class 38: chunk size 458992 perslab 2
<6 server listening
<7 send buffer was 126976, now 268435456
<7 server listening (udp)

Congratulations! Memcached is up and running!

PS:  I’m renting the VPS from www.slicehost.com and so far my experience with them ( 1.5 months) is excellent.


Tags: , , , ,

 

12 Responses to “Installing Memcached from Source on CentOS 5



Nick B
9:14 am
July 7, 2008
#180239

Thanks! Been trying to get Apple’s CalendarServer to work on Fedora 8, but couldn’t work out for all these memcache / libevent errors..




5:01 am
July 16, 2008
#183979

Very helpful post. Fixed my problem and I learned something about ld along the way. Result! Thanks, K




James
6:44 pm
August 5, 2008
#194597

Cheers, this helped out a ton.

I never even knew about the ld system, so I’ll definitely be using that to troubleshoot other problems in the future.




Simon
6:44 am
October 23, 2008
#223815

When installing Apple’s Darwin Calendar Server on Ubuntu 8.04 it includes a version of both memcached and libevent. Memcached cannot find the libevent and I got the same error as above “error while loading shared libraries: libevent-1.4.so.2: …”.
The fix as described in this article worked for me.

Thanks Alex.




7:24 am
October 31, 2008
#226214

Thanks! This worked perfectly.




11:42 pm
December 10, 2008
#236030

In my case, I didn’t need to create a new ld conf file. I just ran /sbin/ldconfig and it worked.




Martin
7:38 pm
December 16, 2008
#237173

Simon,

I got through the installation of libevent and memcached. Now I’m getting an error saying:

[memcached] can’t run as root without the -u switch

I’ve tried a few things, but to no avail. Any ideas?




8:14 pm
December 16, 2008
#237177

Martin,

As the command is stating memcached can’t be run as root. Try running it like so

memcached -u nobody -vv

were nobody is the user to run it as. Ideally this would be the user that you run all your server processes under but nobody should work for testing.




9:40 am
February 13, 2009
#246861

Thank you for the how to. It worked like a charm for me.

-Steve




Franck
7:33 am
February 24, 2009
#248460

Thanks for the post. However I had the same error as above (using Sharedance and not Memcached) “error while loading shared libraries: libevent-1.4.so.2: …”.

The fix as described in this article did not worked for me.

Instead I fixed it by:

ln -s /usr/local/lib/libevent-1.4.so.2 /lib/libevent-1.4.so.2

Franck




10:10 am
March 30, 2009
#253874

On ubuntu this is fixed by installing memcached and libevent first with apt. Calendar Server will only install its own versions if it doesn’t find one in the system. Perhaps there is an equivalent under CentOS?




L
12:44 pm
May 17, 2009
#263921

dude. so appreciated :)




 

Leave a Reply