×

Memcached is an open-source, high-performance, freely available, and in-memory key-value caching server.

It provides various features such as helps to speed up the applications by caching the various objects from the user authentication tokens and database API calls. 

Moreover, Memcached caching server helps in sharing a large amount of data across multiple application instances.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform Memcached queries on CentOS Linux System.

In this context, we shall look into the installation procedure and configuration of Memcached on CentOS 8 system.


How to install Memcached on CentOS 8 ?

To install and configure the Memcached server, root credentials or sudo privileges are required.

Then follow the steps provided below.


1. Install Memcached caching server

Before starting the installation of the Memcached service, it is recommended that update all system packages to refresh the repository. 

i. So, update the apt packages list by typing the below-given command:

$ sudo apt update

The Memcached packages are already present in the default CentOS 8 repository. 

Therefore, the installation of these packages is quite easy. 

ii. Just type the following command with root privileges to install the Memcached on CentOS 8 system:

$ sudo dnf install memcached libmemcached 

The 'libmemcached' package comes with various other command-line tools for managing the Memcached services.

iii. During the installation of Memcached, the list of necessary Memcached dependencies along with total size displays on the terminal. 

To continue the installation of these dependencies press 'y' and then hit the 'Enter' key from your keyboard.

When the 'complete' status shows on the terminal window that means the installation of all Memcached packages has been completed on this system.


2. Verify the Memcached installation

Once the installation of the Memcached server is completed, you can ensure the Memcached installation on your system by running the following command:

$ rpm -q memcached

The above command will verify that either Memcached is installed on your system or not. 

To get more information about the installed Memcached server such as version, architecture, and more. 

Use the about command with the 'qi' parameter, that displays all information about the installed Memcached caching server:

$ rpm -qi memcached


3. Enable Memcached Service on CentOS 8

i. Now, enable the Memcached services on your CentOS 8 system by typing the following command:

$ sudo systemctl enable memcached --now

ii. To check the Memcached caching server running status on your system, use the following command:

$ sudo systemctl status memcached

Now, you will see the Memcached service 'running' status on the terminal.

iii. To exit from the above-displayed output press 'Ctrl+C'.

Now, the installation of Memcached is completed. 

Next, we will discuss the Memcached configurations.


How to perform Memcached Configuration on CentOS 8 ?

Memcached configuration file you can find at this '/etc/sysconfig/memcached' location.

By default, the Memcached services run on the local host and listen on port '11211'. 

If the client with which you want to connect is also running on the same server that you don't need to make any changes to the configuration file. 

Open the Memcached configuration file by executing the following command:

$ sudo nano /etc/sysconfig/memcached

If the applicant connecting to the server is running on the remote host then, you need to make some changes to the Memcached configuration file.


Let's suppose, in the private network, the IP of the Memcached server is '192.168.100.01' and the client's IP is '192.168.100.02'. 

So, allows access to the server’s listening port and changes the following line in the configuration file:

OPTIONS="-l 192.168.100.01"

Save the above configuration and restart the Memcached services by using the below-mentioned command:

$ sudo systemctl restart memcached


How to Allow Firewall access ?

The following commands will create a new zone named Memcached and allow access to the required port and client's IP.

$ sudo firewall-cmd --new-zone=memcached --permanent
$ sudo firewall-cmd --zone=memcached --add-port=11211/udp --permanent
$ sudo firewall-cmd --zone=memcached --add-port=11211/tcp --permanent
$ sudo firewall-cmd --zone=memcached --add-source=192.168.100.16/24 --permanent
$ sudo firewall-cmd --reload

Now, enable and restart again the Memcached services.


How to Connect to Memcached ?

To connect with the Memcached server, you will always need to use the language-specific client.


i. Memcached for Python

There are many python libraries available to connect with Memcached. You can easily install these python packages through the pip tool:

$ pip install pymemcache
$ pip install python-memcached


ii. Memcached with PHP

To use the Memcached caching database with PHP application, you need to install the relevant extension on your CentOS 8 system as follows:

$ sudo dnf install php-pecl-memcache


How to Uninstall Memcached from CentOS System ?

If you don't find it useful more on your system then, by executing the following command you can uninstall the Memcached caching server from CentOS 8 along with dependencies:

$ sudo dnf remove memcached libmemcached


[Need assistance in configuring Memcached caching server on your Ubuntu Linux Server ? We can help you. ]


Conclusion

More Linux Tutorials

We create Linux HowTos and Tutorials for Sys Admins. Visit us on IbmiMedia.com

Also for Tech related tips, Visit forum.outsourcepath.com or General Technical tips on www.outsourcepath.com