+3 votes
236 views
How to install memcached on CentOS 7

in Linux / Unix by (552k points)
reopened | 236 views

1 Answer

+4 votes
Best answer

1. How to update system packages to install memcached in CentOS 7 Linux
2. How to install memcached on CentOS 7 Linux
3. How to configure memcached in CentOS 7 Linux

Are you a Linux user? Did you know that an element called cache is hosted in the computer's memory? When we use a web object, call web site, web application or any element that is based on this technology, the memory will store by default some instructions and data whose purpose is that the processor can access them continuously. This saves time and resources by not having to repeat instructions, and this is what is known as cache memory . The cache memory has been designed in order to organize in a much more centralized way, the storage of data in the system. We all like that when we give an order it is executed quickly and this is precisely its purpose..

Now we are going to talk about an application in Linux that aims at a better administration of the memory cache and is memchached .

What is memcached?
The memcached utility has been designed to be a caching system associated with objects in distributed memory but with a high performance approach. That is to say, its initial goal is to accelerate the dynamic web applications by lightening the load of the database that acts when it must be accessed. Remember that when you click on a web link internally, many processes occur, and because of this, memcached can act as a short-term memory for the web applications that we work with.
The simple design with which memcached has been created will allow rapid implementation facilitating simultaneous development and management of large data caches. In addition to this we can not forget that the API is available for the most used languages, that is, we are facing a very useful, dynamic and versatile App.

We have talked a lot about the global work of memcached in our system for the management of the cache in memory, but surely you ask yourself, how does this work ?, TechnoWikis will explain in detail this task..

How does memchached work?
Basically memcached has the ability to access different sections of memory in the system; but it will only access the available memory and what is left over, will never use the memory reserved for processes or services. By taking this available memory it will be delivered and implemented in areas where memory is limited or scarce.

When using memcached we should keep in mind these usage characteristics:

  • Each node is completely independent of the other.
  • Each node is able to use the memory of other nodes in order to optimize scarce memory processes.

Now, let's see what elements make up the memcached application:

Elements that make up memcached
  • First of all, memcached has a client software, which is essential since it provides a list of available memcached servers.
  • We will also see a hashing algorithm, which is an algorithm based on the client and whose mission is to select a server based on the distributed key.
  • Then we will find the server software whose task is to store the values ​​with their assigned keys in an internal hash table, something scaled at the security level.
  • Last but not least, we found the LRU. This determines at what time memcached must access the old data (eye, if there is no memory) or reuse the available memory.

Before we go into detail to learn how to install and use memcached, let's see some of its features to see if it draws our attention or not the use of this utility:

Features of memcached
  • Use of Hash on multiple servers.
  • Storage of binary data or chains.
  • Hashing consistent either natively or through an external library.
  • Serialization of data structures.
  • Standard recovery commands through the Get command.

Now without further details we will see how to install memcached in CentOS 7.


1. How to update system packages to install memcached in CentOS 7 Linux


The first step we must always make is to update the system packages, for this we will execute the following command:
 sudo yum update 
image

2. How to install memcached on CentOS 7 Linux


Step 1

Once the system is updated, we will proceed with the installation of memcached, which will be performed with the execution of the following command:
 sudo yum install memcached 
There we will enter the letter and to confirm the download and installation of memcached in CentOS 7 image
Step 2

Once installed, we will see the following:


image
Step 3

The next step is to install libmemcached, which is a client library where we will have a couple of special tools to manage the memcache server; something that will be very beneficial for support tasks. For this installation we will execute the following:
 sudo yum install libmemcached 


image
Step 5

There we entered the letter and to proceed with the installation of these libraries. image
Note
Another option to install memcached in CentOS 7 is directly from the source. For this we must execute, in order, the following lines:
 sudo yum install libevent-devel sudo wget https://memcached.org/latest tar -zxf memcached-1.xxtar.gz cd memcached-1.xx ./configure --prefix = / usr / local / memcached make && make test && sudo make install 

3. How to configure memcached in CentOS 7 Linux


In order for memcached to work correctly, it will be necessary for the memcached service to be listening through the local address 127.0.0.1.
Step 1

To configure this we must apply a change in the OPTIONS variable in the configuration file / etc / sysconfig / memcached. For this we will use some text editor such as nano or vi:
 sudo nano / etc / sysconfig / memcached 
image
Step 2

We can see that the OPTIONS line is empty, there we will enter the following line:
 -l 127.0.0.1 -U 0 
image

We save the changes using the following keys:

+ O Ctrl + O

We exit the editor using the keys:

+ X Ctrl + X

To understand a little more than elements that integrate the memcached configuration file, TechnoWikis will explain the role of each:

PORT
As is to be expected, without knowing much English, this is the port used by memcached for its execution.
USER
This value refers to the start daemon for the memcached service.
MAXCONN
It is a key value to define the number of simultaneous connections, by default its value is 1024 but logically based on the level of access to the server this value can be edited at the necessary value.
CACHESIZE
Another value that we can deduce, is the value of the size of the cache memory which by default is 2048 but we can set it up to 4 GB.
OPTIONS
This is the line that we edit and there we can configure the IP address of the server, so we allow the Apache or Nginx web servers to establish connections with it.
Step 3

Once these changes have been processed, we must apply them, for which we execute the following:
 systemctl restart memcached systemctl enable memcached 
image
Step 4

When the service has been started, we will validate that the memcached service is linked to the local interface (127.0.0.1) and listens only on TCP connections. For this check we will use the netstat command in the following way:
 netstat -plunt 
image
Step 5

It will also be possible to verify the server statistics through the memcached-tool line:
 memcached-tool 127.0.0.1 stats 
image

The next step is to allow access to the memcached server by opening a port 11211 in the firewall. This will prevent security rules from being blocked. We will execute the following:

 firewall-cmd --permanent --zone = public --add-port = 11211 / tcp 
There are some add-on options that we can install so that memcached optimizes the use of applications based on the language used:
 yum install php-pecl-memcache (memcached extension for PHP) yum install perl-Cache-Memcached (memcached extension for PERL) yum install python-memcached (memcached extension for PYTHON) 
TechnoWikis always brings you the best to manage every aspect of the system and with memcached it will be possible to manage in a much more global way every aspect of the cache in CentOS 7.

by (3.5m points)
edited

Related questions

+4 votes
1 answer
asked May 14, 2020 in Linux / Unix by backtothefuture (552k points) | 635 views
+5 votes
1 answer
+4 votes
1 answer
asked Nov 20, 2019 in Linux / Unix by backtothefuture (552k points) | 265 views
+3 votes
1 answer
asked Nov 11, 2019 in Linux / Unix by backtothefuture (552k points) | 280 views
+5 votes
1 answer
asked Nov 10, 2019 in Linux / Unix by backtothefuture (552k points) | 564 views
Sponsored articles cost $40 per post. You can contact us via Feedback

Most popular questions within the last 30 days

10,659 questions
10,791 answers
510 comments
3 users