Memcached cluster deployment and memcached cluster deployment
1. Introduction to Memcached
Memcached is a high-performance distributed memory object cache system. Memcached's high performance comes from the two-stage hash structure. Memcached is based on a HashMap that stores key/value pairs, reduces database load. It caches data and objects in the memory to reduce the number of reads to the database, so as to provide dynamic and database-driven website speeds. When the memory capacity reaches the specified value, the LRU algorithm automatically deletes unused caches.
Ii. Memcached application scenarios
(1) Most Memcached applications serve as front-end cache for databases, reducing the number of database connections, indirectly reducing database operations, improving data access efficiency, and improving system performance, in large systems, Memcached can greatly reduce the database pressure and improve the system performance.
(2) When there is a large volume of access, when the cache data reaches a large volume, we can easily perform horizontal scaling on Memcached clusters, because there is no communication between Memcached servers, when the memory is not enough, you can increase the Memcached server. one of the servers is suspended, which will not cause too much pressure on the database.
(3) For system cluster deployment, we need to share user login information. We can use Memcached for caching so that users can use it between systems.
Iii. Memcached is not suitable for application scenarios
(1) The cached data volume is small.
(2) cached data must be persistent.
4. Install Memcached
When Memcached is deployed in a distributed cluster, there is no communication between the Memcached server and the server is pseudo-distributed. distributed deployment is implemented by the client, the client implements distributed algorithms to store data to different Memcached servers.
Step 1: first install libevent
Memcached uses the libevent library, so install libevent first.
Http://libevent.org/download
(2) decompress 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) Compilation and Installation
# Make & make install
(6) test whether the installation is successful
# Ls/opt/lib | grep libevent:
Step 2: Install Memcached
(1) decompress 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 libevent
#./Configure -- prefix =/opt -- with-libevent =/opt:
(4) Compilation and Installation
# Make & make install
(5) test whether the installation is successful
# Ls-al/opt/bin/memcached:
5. Start the Memcached Service
(1) we are working on the 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 daemon mode.
-M: Set the memory size available for memcached, in MB.
-L set the IP address of the listener. If it is a local machine, this parameter is usually not set.
-P: Set the listening port. The default value is 11211. Therefore, you can leave this parameter unspecified.
-P is the pid file for saving Memcache.
-U specifies the user. If the current user is root, you must use this parameter to specify the user.
-F: Set the growth factor (used for optimization ).
-V/-vv: various parameters are displayed in detail during work.
We can view the parameters through the command
#/Opt/bin/memcached-h:
(2) Now let's check whether it is started. Let's check the thread ,:
After the cluster deployment is complete, continue to explain the implementation of the client.