Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the Memcached Service of Linux system

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article shows you how to understand the Linux system Memcached service, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Linux system Memcached service what is Memcached?

Memcached is a free and open source, high-performance, distributed memory object caching system, it improves the access performance of WEB by reducing the database load. Memcached is the main program of the server, these caches are generally used to save some frequently accessed objects or data (such as browsers will cache frequently accessed web pages), and end users improve the access experience by requesting cached data.

Memcached is a kind of memory cache, which caches the frequently accessed objects or data in memory, and the cached data in memory is accessed by API. The data is like a huge HASH table, which exists in the way of key-value pairs.

Memcache workflow

1. Check whether the data requested by the client exists in Memcache. If so, return the relevant data directly without any operation on the data.

2. If the data is not in Memcache, it will go to the database to query, return the data obtained from the database to the client, and cache the data to Memcache at the same time

3. When the database is updated (update or delete data), the data in Memcache is also updated to keep the data consistent.

The working logic diagram is as follows:

4. If the memory allocated to Memcache is used up, LRU (least recently used) and expiration policy will be used, and the invalid data will be replaced, and then the recently unused data will be replaced.

Characteristics of Memcache

1. The protocol is simple

Using the text line-based protocol, the data can be accessed directly on the Memcached server through telnet, which is relatively simple to implement.

2. Event handling based on Libevent

Libevent is a library based on C #, which is used by Memcached to handle asynchronous events.

3. Built-in memory management

Memcached has its own way of managing memory, and it is very efficient. All data is stored in the built-in memory of Memcached. When the stored data is full of space, LRU algorithm will be used to clear the unused cache data, so as to reuse the memory space of expired data, but restart the server data will be lost.

4. The Memcached servers do not communicate with each other and have the characteristic of split storage.

Each Memcached server does not communicate with each other and accesses data independently. Through the design of the client, it has the characteristics of split storage and supports a large number of caches and large-scale applications.

Installation of Memcached

The installation of Memcached is very simple. First, you need to download libevent and Memcached software. The download process will not be introduced any more.

Install the libevent command as follows (or you can install it directly with Yum):

Tar zxf libevent-1.4.13-stable.tar.gz

Cd libevent-1.4.13-stable

. / configure

Make & & make install

Install the Memcached command as follows:

Tar zxf memcached-1.4.20.tar.gz

Cd memcached-1.4.20

. / configure

Make & & make install

Start Memcached

/ usr/local/bin/memcached-p 11211-u root-c 1024-d

# #-p specify port 11211-c maximum concurrency-d background mode

If an error occurs and the libevent-1.4.so.xx file cannot be found, the solution is as follows

Echo "/ usr/local/lib" > > / etc/ld.so.conf

Ldconfig

[root@~] # lsof-I: 11211

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

Memcached 15744 root 26u IPv4 25499 0t0 TCP *: memcache (LISTEN)

Memcached 15744 root 27u IPv6 25500 0t0 TCP *: memcache (LISTEN)

Memcached 15744 root 28u IPv4 25503 0t0 UDP *: memcache

Memcached 15744 root 29u IPv4 25503 0t0 UDP *: memcache

Memcached 15744 root 30u IPv4 25503 0t0 UDP *: memcache

Memcached 15744 root 31U IPv4 25503 0t0 UDP *: memcache

Configure the Memcached service

Add data through NC

[root@~] # printf "set key001 00 10\ r\ ntest123456\ r\ n" | nc 127.0.0.1 11211

# add data with 10 bytes, which must be consistent later, otherwise the addition will not be successful

STORED

[root@~] # printf "get key001\ r\ n" | nc 127.0.0.1 11211

# query data

VALUE key001 0 10

Test123456

END

[root@~] # printf "delete key001\ r\ n" | nc 127.0.0.1 11211

# Delete data

DELETED

[root@~] # printf "get key001\ r\ n" | nc 127.0.0.1 11211

END

Add data through telnet

[root@LVS-2 ~] # telnet 127.0.0.1 11211

Trying 127.0.0.1...

Connected to 127.0.0.1.

Escape character is'^]'.

Set key 0 0 10

# add data

Test654321

STORED

Get key

# query data

VALUE key 0 10

Test654321

END

Delete key

# Delete data

DELETED

Get key

The above is how to understand the Memcached service of Linux system. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report