Install memcached on centos
1. Install libevent
Install libevent before installing memcached.
Wgethttp: // 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. Install memcached
Wgethttp: // 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: make reports an error.
Memcached. c: In the 'Add _ iov' function:
Memcached. c: 696: 30: Error: 'iov _ MAX 'is not declared (used for the first time in this function)
Memcached. c: 696: 30: Note: Each undeclared identifier is reported only once in the function it appears.
Make [2]: *** [memcached-memcached.o] Error 1
Modify the memcached. c file:
Copy code
/* FreeBSD 4.x doesn't have IOV_MAX exposed .*/
# Ifndef IOV_MAX
# If defined (_ FreeBSD _) | defined (_ APPLE __)
# Define IOV_MAX 1024
# Endif
# Endif
Changed:
/* FreeBSD 4.x doesn't have IOV_MAX exposed .*/
# Ifndef IOV_MAX
# Define IOV_MAX 1024
# Endif
Copy code
Make & make install again, and exit the root user after compilation.
After the installation is complete, the default directory of memcached is/usr/local/bin/memcached.
3. Start memcached
/Usr/local/bin/memcached-m 32 MB-p 11211-d-u root-P/var/run/memcached. pid-c 256
Solution to the following error:
/Usr/local/bin/memcached: error while loadingsharedlibraries: libevent-2.0.22.so.1: cannotopen#dobjectfile: Nosuchfileordirectory
Solution to libevent-2.0.22.so not found
Echo "/usr/local/lib">/etc/ld. so. conf
Ldconfig
Startup parameters:
The-d option is to start a daemon.
-U root indicates that the user who starts memcached is root.
-M indicates the amount of memory allocated to Memcache. The unit is MB. The default value is 64 MB.
-M return error on memory exhausted (rather than removing items ).
-U is the user who runs Memcache. If it is currently root, you need to use this parameter to specify the user.
-L is the IP address of the listening server. The default value is all NICs.
-P is the port used to set TCP listening for Memcache, preferably over 1024.
-The c option is the maximum number of concurrent connections. The default value is 1024.
-P is the pid file for saving Memcache.
-F <factor> chunk size growth factor (default: 1.25 ).
-I Override the size of each slab page. Adjusts max item size (New in version 1.4.2 ). You can also start multiple daemon processes, but the ports cannot be repeated.
Test whether startup is normal
Telnet local host 11211
2. view the memcached startup command
Ps aux | grep memcached
2.1.2. Stop memcached
Kill 'cat/var/run/memcached/pid'
6. install PHP extension for Memcache
Wgethttp: // pecl.php.net/get/memcache-2.2.5.tgz
Tar zxvf memcache-2.2.5.tar.gz
Cdmemcache-2.2.5
/Home/webserver/php/bin/phpize
./Configure -- enable-memcache -- with-php-config =/home/webserver/php/bin/php-config
Make & make install
After the installation is complete, the following prompt appears:
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 whether Memcache PHP is successfully installed.
Run the following code:
<? Php
$ Mem = new Memcache;
$ Mem-> connect ('2017. 0.0.1 ', 127 );
$ Mem-> set ('test', "hello world! ", 0, 12 );
$ Val = $ mem-> get ('test ');
Echo $ val;
?>