1, installation Libevent
Install memcached before installing libevent
wget http://sourceforge.net/projects/levent/files/libevent/libevent-2.0/libevent-2.0.22-stable.tar.gz
Tar zxvf libevent-2.0.22-stable.tar.gz
CD libevent-2.0.22-stable
./configure
Make && make install
2, installation memcached
wget http://www.danga.com/memcached/dist/memcached-1.2.2.tar.gz
Tar zxvf memcached-1.2.7.tar.gz
CD memcached-1.2.7
./configure
Make && make install
Note: error when make is
MEMCACHED.C: In the function ' Add_iov ':
MEMCACHED.C:696:30: Error: ' Iov_max ' not declared (first use within this function)
MEMCACHED.C:696:30: NOTE: Each undeclared identifier is reported only once within the function in which it appears
MAKE[2]: * * [MEMCACHED-MEMCACHED.O] Error 1
You need to modify the Memcached.c file:
Copy Code
/* FreeBSD 4.x doesn ' t has iov_max exposed. */
#ifndef Iov_max
#if defined (__freebsd__) | | Defined (__apple__)
# define Iov_max 1024
#endif
#endif
Change to:
/* FreeBSD 4.x doesn ' t has iov_max exposed. */
#ifndef Iov_max
# define Iov_max 1024
#endif
Copy Code
Then Make&&make install and exit the root user after compiling.
memcached default directory is/usr/local/bin/memcached after installation is complete
3. Start memcached
/usr/local/bin/memcached-m 32m-p 11211-d-u root-p/var/run/memcached.pid-c 256
Start times the following error resolution method
/usr/local/bin/memcached:error while loading shared libraries:libevent-2.0.22.so.1:cannot open Shared object File:no s Uch file or directory
There's no way to find libevent-2.0.22.so's solution.
echo "/usr/local/lib" >>/etc/ld.so.conf
Ldconfig
Start parameter Description:
the-D option is to start a daemon.
- u root indicates that the user who initiated the memcached is root.
- M is the amount of memory allocated to Memcache, in megabytes, by default 64MB.
- m return error on memory exhausted (rather than removing items).
- U is the user running memcache, and if it is currently root, you need to specify the user with this parameter.
- L is the server IP address of the listener, which defaults to all network cards.
- P is the port that sets the TCP listener for memcache, preferably a port above 1024.
The- c option is the maximum number of concurrent connections to run, and the default is 1024.
-P is a PID file that is set to save Memcache.
- f <factor> chunk size growth factor (default:1.25).
-I Override the size of each slab page. Adjusts max item size (new 1.4.2 version). You can also start multiple daemons, but the ports cannot be duplicated
Test startup is normal
telnet localhost 11211
2. View memcached Start command
PS aux|grep memcached
2.1.2. Stop memcached
Kill ' Cat/var/run/memcached/pid '
6. Install memcache PHP Extension
wget http://pecl.php.net/get/memcache-2.2.5.tgz
Tar zxvf memcache-2.2.5.tar.gz
CD memcache-2.2.5
/home/webserver/php/bin/phpize
./configure--enable-memcache--with-php-config=/home/webserver/php/bin/php-config
Make && make install
The following prompts will appear when the installation is complete
Installing Shared extensions:
/home/webserver/php/lib/php/extensions/no-debug-non-zts-20121212/
Modify the php.ini file
Change Extension_dir = "./" To Extension_dir = "/home/webserver/php/lib/php/extensions/no-debug-non-zts-20121212/"
Add the following line of code
Extension=memcache.so
7, Test memcache PHP is installed successfully
Run the following code
<?php
$mem = new Memcache;
$mem->connect (' 127.0.0.1 ', 11211);
$mem->set (' Test ', "Hello world!", 0, 12);
$val = $mem->get (' Test ');
Echo $val;
?>
CentOS memcached Installation