Memcached is an open-source high performance distributed memory object caching system. It is one of the most widely used cache mechanism used by some of the biggest websites like WordPress.com and LiveJournal.com.
It is also used by VBulletin software, for faster performance, that is one of the best software for Forums. It’s easy to install and there are so many client programs available on the Internet in different languages.
Read: Memcached Java Client
Install Memcached on Mac OS
Memcached is a memory based caching mechanism and build using C language. To install memcached server on Mac OS, we need C library. Here I am assuming that C library is already present in the system. If it’s not, then you can download C compiler and install it or install XCode that installs GCC compiler with it.
After that, you need to install the lib events library.
Steps are;
1 2 3 4 5 6 7 8 9 10 11 12 |
$ curl -OL https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz $ tar -xvf libevent-2.1.8-stable.tar.gz $ cd libevent-2.1.8-stable $ ./configure --prefix=/usr/local $ make $ sudo make install |
Once libevents is installed then you can install Memcached server.
Steps are;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$ curl -O https://memcached.org/files/memcached-1.5.0.tar.gz $ tar -xvf memcached-1.5.0.tar.gz $ cd memcached-1.5.0 $ ./configure --prefix=/usr/local $ make $ sudo make install Password: $ |
Now Memcached server is installed in your system. If the libevent library is not installed, configure command will give the following error.
1 2 3 4 5 6 7 8 |
$ ./configure --prefix=/usr/local ... checking for libevent directory... configure: error: libevent is required. You can get it from https://www.monkey.org/~provos/libevent/ If it's already installed, specify its path using --with-libevent=/dir/ pankaj:memcached-1.5.0 pankaj$ |
Memcached Server on Different Port
By default, memcached server runs on TCP port 11211 and listens on UDP port 11211 and you can run multiple instances of memcached server from one installation.
1 2 |
$memcached -d |
Above command will start the Memcached server on TCP port 11211 and listens on UDP port 11211 as a daemon process.
1 2 |
$memcached -p 11111 -U 11111 -d |
Above command will start the Memcached server on TCP port 11111 and listens on UDP port 11111 as a daemon process.
Test Memcached Server using Telnet
Next step is to use memcached telnet commands to test that it’s working fine.
In some of the Linux systems, you also need to add the libevent library location in the path.
If you get following error in starting memcached server:
./memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory
Then add following configuration in user profile (for example, .bash_profile or .profile)
1 |
$export LD_LIBRARY_PATH= /usr/local/lib |
Or, provide it’s path using --with-libevent
option in configure command.
I have used the above steps to install Memcached server on Mac OS. If you face any issues, let me know. I will try to resolve them.
Happy Caching…
Further Reading: Install Memcached on CentOS and PHP integration
References: