System: centos6.3 _ x64
Memcache uses the libevent library for Socket processing, so you also need to install libevent
1) install libevent first:
Wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.20-stable.tar.gz
# Tar-zxvf libevent-2.0.20-stable.tar.gz
# Cd libevent-2.0.20
#./Configure -- prefix =/usr
# Make
# Make install
2) install memcached
Wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz
# Tar zxvf memcached-memcached-1.4.15.tar.gz
# Cd memcached-memcached-1.4.15
#./Configure -- prefix =/usr/local -- with-libevent =/usr
# Make
# Make install
Start memcached
#/Usr/local/bin/memcached-d-m 2048-l 172.18.1.250-p 11211-u root
-D option is to start a daemon,
-M indicates the amount of memory allocated to Memcache. The unit is MB,
-U is the user who runs Memcache. Here I am system_u,
-L is the IP address of the listener server. If there are multiple IP addresses, you can use multiple-l YOU_IP addresses.
-P is the port used to set Memcache listening, preferably over 1024,
-The c option is the maximum number of concurrent connections running. The default value is 1024, Which is set based on the load of your server,
-P is the pid file for saving Memcache.
To end the Memcache process, run:
Use # ps-e to view Processes
# Kill pid memcached process number
After running, some systems will prompt-bash: kill: pid: arguments must be process or job IDs
But you can use # ps-e to view the process. There is no memcached process.
3) install the memcache extension of PHP.
# Tar zxvf memcache-2.1.0.tgz
# Cd memcache-2.1.0
#/Usr/local/php/bin/phpize
#./Configure -- enable-memcache -- with-php-config =/usr/local/php/bin/php-config -- with-zlib-dir
# Make
# Make install
In the php. ini (vi/etc/php. ini) file, add:
Extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20060613 /"
Extension = memcache. so
Session. cookie_lifetime = 86400
Session. gc_maxlife time = 86400
Session. save_handler = memcache
Session. save_path = "tcp: // 192.168.20.243: 11211, tcp: // 192.168.20.244: 11211"
Start memcached
Restart apache
Advantages and disadvantages:
Memcached implements memory space allocation and recovery, as well as storage service monitoring and provision. distributed implementation depends on the use and construction of the client. the client we use fully supports distributed. but some problems may occur.
For example, if a network problem occurs and one of the distributed servers loses contact, the data written to the distributed server cannot be obtained during the period when the server resumes normal operation. the Distributed hash table can be used to solve this problem.