A memcached Introduction
Memcached is a high performance distributed memory object caching system,Memcached High performance from a two-stage hash (two-stagehash) Structure , Memcached is based on a HashMap that stores key / value pairs , easing the database load by caching data and objects in memory to reduce the number of times a database is read, providing a dynamic, database-driven Web site speed. TheLRU algorithm automatically deletes unused caches when the memory capacity reaches the specified set value.
Two. Scenarios for memcached applications
(1) Most of the Memcached is used as a database front-end cache, reducing the number of connections to the database, indirectly reducing the operational database, improve the efficiency of access data, improve the performance of the system, because in large systems, concurrent frequent access to the same business, the use of Memcached can greatly reduce the database pressure and improve the performance of the system.
(2) When the large amount of traffic cache data reached very large, we Memcached in the cluster, do a very easy to do the level of expansion, because There is no communication between the Memcached server, when the memory is not enough, You can increase the server side of the Memcached server , where one of the servers hangs, not too much pressure on the database.
(3) System cluster deployment, we need user login information sharing, we can use Memcached to cache, so that users can be used between the system.
Three. memcached not suitable for application scenarios
(1) The amount of data cached is small.
(2) The cached data needs to be persisted.
Four.Memcached installation
Memcached in the implementation of distributed cluster deployment, There is no communication between the Memcached server, the server is pseudo-distributed, implementation of the distribution is implemented by the client, the client implemented a distributed algorithm to save the data to different Memcached service side.
First step: install libevent First
Memcached used libevent This library, so first install libevent
(1)http://libevent.org/ Download
(2) unpacking the installation package
# tar ZXVF libevent-2.0.21-stable.tar.gz
(3) Enter the Libevent directory
#cd libevent-2.0.21-stable
(4) Specify the installation directory
#./configure-prefix=/opt
(5) compiling and installing
# Make &&make Install
(6) test installation is successful
#ls/opt/lib |grep libevent :
Step Two: Install memcached
(1) unpacking the installation package
#tar ZXVF memcached-1.4.21.tar.gz
(2) Enter the Libevent directory
#cd memcached-1.4.21
(3) specify The installation location of the libevent
#./configure--prefix=/opt--with-libevent=/opt :
(4) compiling and installing
# Make &&make Install
(5) test installation is successful
#ls-al/opt/bin/memcached :
Five. memcached Start-up service
(1) We do Memcached Cluster service, so we started two processes:
#/opt/bin/memcached-d-M 5-u root-l 192.168.74.129-p 12000-c 256-p/tmp/memcached.pid
#/opt/bin/memcached-d-M 5-u root-l 192.168.74.130-p 13000-c 256-p/tmp/memcached.pid
-D runs memcached in the daemon (daemon) mode .
-M sets the amount of memory that memcached can use, in units of m.
-L SETS the IP address of the listener and, if it is native, it is usually not possible to set this parameter.
-P Sets the listening port, which defaults to 11211, so you can also not set this parameter.
- P is a pid file that is set to save Memcache
-u specifies that the user should be specified using this parameter if it is currently root .
-F Sets the growth factor (used when tuning).
-V/-VV detailed display of various parameters at work.
We can view the parameters by command
#/opt/bin/memcached-h:
(2) Let's check if it starts, we look at the thread:
This way the cluster deployment is complete, and the following continues to explain implementing the client.
Memcached Cluster deployment