First, the source package preparation
Server side is mainly installed Memcache server side
Download: http://memcached.googlecode.com/files/memcached-1.4.4.tar.gz
In addition, Memcache used the libevent this library for socket processing, so you also need to install libevent,
The latest version of Libevent is libevent-1.4.13-stable. (If your system already has libevent installed, you can not install it)
Official website: http://www.monkey.org/~provos/libevent/
Download: http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz
Prepare the memcached PHP extension for the source installation package:
Official website: http://pecl.php.net/get/memcache-2.2.5.tgz
Linux command download:
wget http://memcached.googlecode.com/files/memcached-1.4.4.tar.gzwget http:// www.monkey.org/~provos/libevent-1.4.13-stable.tar.gzwget http://
second, installation and configuration
1, first install Libevent
Tar zxvf Libevent-1.4.13-stable.tar. gzcd libevent-1.4.13-stable./configure--prefix=/
2. Test whether the Libevent is installed successfully
Ls-al/usr/lib | grep libeventlibevent -1.1a.so.1libevent -1.1a.so.1.0.2libevent -1.4.so.2 Libevent -1.4.so.2.1.3libevent . alibevent_core -1.4.so.2libevent_core -1.4.so.2.1.3libevent_core . alibevent_core . lalibevent_core . solibevent_extra -1.4.so.2libevent_extra -1.4.so.2.1.3libevent_extra . alibevent_extra . lalibevent_extra . solibevent . lalibevent . So
Different versions, the file list may be different.
3, install memcached, also need to install in the specified Libevent installation location
Tar zxvf Memcached-1.4.4.tar. gzcd memcached-1.4.4./configure–with-libevent=/
The memcached will be automatically placed on the/usr/local/bin/memcached after installation is complete.
4, test whether the successful installation of memcached
ls-al/usr/local/bin/mem*
-rwxr-xr-x 1 root root 201869 12-14 21:44/usr/local/bin/memcached
5. Install memcache PHP Extension
① installing PHP's memcache extension
Tar vxzf memcache-2.2.5.tgz
CD memcache-2.2.5
/usr/local/webserver/php/bin/phpize
./configure--enable-memcache--with-php-config=/usr/local/php/bin/php-config--with-zlib-dir
Make
Make install
② there will be a hint like this after the installation is complete:
Installing Shared extensions:/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/
③ add a line to the php.ini to load the memcache extension: extension=memcache.so
Three, the basic setting of memcached
1. Start the server side of the memcache:
Memcached-d-M 10-u root-l 202.207.177.177-p 11211-c 256-p/tmp/memcached.pid
Parameter description:
The-D option is to start a daemon,
-M is the amount of memory allocated to Memcache, in megabytes, I'm 10MB,
-U is the user running memcache, I am root here,
-L is the server IP address of the listener, if there are multiple addresses, I specify the server IP address 202.207.177.177,
-P is the port that sets Memcache listening, I set here 11211, preferably more than 1024 ports,
The-c option is the maximum number of concurrent connections to run, the default is 1024, I set the 256 here, according to the load of your server to set,
-P is set to save memcache PID file, I am here to save in/tmp/memcached.pid,
2. If you want to end the memcache process, execute:
Kill ' Cat/tmp/memcached.pid '
You can also start multiple daemons, but the ports cannot be duplicated.
3. Check if memcached is started
Netstat-ant
TCP 0 0 202.207.177.177:11211 0.0.0.0:* LIST
Port 11211 is already open, indicating that memcached has started normally.
4. Restart PHP nginx
Service php-fpm Restart #重启php-fpm
Service nginx Restart #重启nginx
Iv. Environmental testing of Memcache
Run the following PHP file, if there is output this is a test!, it indicates that the environment was built successfully. Start your memcache journey!
<?php
$mem = new Memcache;
$mem->connect ("202.207.177.177", 11211);
$mem->set (' key ', ' This is a test! ', 0, 60);
$val = $mem->get (' key ');
Echo $val;
?>
Reprint Address: Http://www.jb51.net/article/29668.htm thank the original author
Memcache installation steps under CentOS (linux+nginx+php+memcached)