1. Prepare the installation files
Download the installation files for memcached and libevent
http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz (memcached download address)
https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz (libevent download address)
1. Download the memcached server installation file, version: memcached-1.4.2.tar.gz.
2. Download libevent, memcached needs to use socked, which depends on this installation file. Version: libevent-1.4.12-stable.tar.gz.
3. Since the Linux system may have libevent installed by default, execute the command:
rpm -qa|grep libevent
Check whether the system has the installation software. If there is an execution command:
rpm -e libevent-1.1a-3.2.1 --nodeps (due to the old version that comes with the system, ignore the dependency deletion)
4. Install libevent,
tar zxvf libevent-1.4.12-stable.tar.gz cd libevent-1.4.12-stable ./configure --prefix=/usr/local/libevent-1.4 make && make install
5. Install memcached
tar zxvf memcached-1.4.2.tar.gz cd memcached-1.4.2 ./configure --prefix=/usr/local/memcached-1.4.2 --with-libevent=/usr/local/libevent-1.4/ make && make install
So far memcached is installed
6. Test
libevent.so is often not found when starting memcached; this can be checked with:
Enter the /usr/local/memcached-1.4.2/bin directory
LD_DEBUG=help ./memcached -v LD_DEBUG=libs ./ memcached -v
Solution:
ln -s /usr/local/libevent-1.4/lib/libevent-1.4.so.2 /lib64/libevent-1.4.so.2
7. Start memcache:
./memcached -help ./memcached -d -m 1024 -u root -p 11211 -c 1024 -P /tmp/memcached.pid
Description of startup parameters:
- The -d option is to start a daemon,
- -m is the amount of memory allocated to Memcache, the unit is MB, the default is 64MB
- -M return error on memory exhausted (rather than removing items)
- -u is the user running Memcache. If the current user is root, you need to use this parameter to specify the user.
- -l is the listening server IP address, the default is all network cards.
- -p is to set the TCP listening port of Memcache, preferably a port above 1024
- The -c option is the maximum number of concurrent connections to run, the default is 1024
- -P is set to save the pid file of Memcache
- -f chunk size growth factor (default: 1.25)
- -I Override the size of each slab page. Adjusts max item size(1.4.2版本新增)
It is also possible to start multiple daemons, but the ports cannot be duplicated
8. Stop the Memcache process:
kill `cat /tmp/memcached.pid`