In this tutorial, we will cover the installation of Memcached on CentOS 8 / RHEL 8. Memcached is an open source and free high-performance in-memory caching system with distributed architecture. It is licensed under the Revised BSD license.

Memcached is often used to speed up websites load time by reducing the number of queries that go to the database server. It does this by caching data and objects in RAM for quick retrieval.

Install Memcached on RHEL 8 / CentOS 8

The Memcached package is available on the default RHEL 8 repositories. Install it by running the following command in your terminal.

sudo yum -y install memcached

More details about installed package can be queried by:

$ rpm -qi  memcached
Name        : memcached
Epoch       : 0
Version     : 1.5.9
Release     : 2.el8
Architecture: x86_64
Install Date: Mon 04 Nov 2019 10:32:08 PM EAT
Group       : System Environment/Daemons
Size        : 288594
License     : BSD
Signature   : RSA/SHA256, Tue 02 Jul 2019 03:03:48 AM EAT, Key ID 05b555b38483c65d
Source RPM  : memcached-1.5.9-2.el8.src.rpm
Build Date  : Tue 14 May 2019 05:25:17 AM EAT
Build Host  : x86-02.mbox.centos.org
Relocations : (not relocatable)
Packager    : CentOS Buildsys <[email protected]>
Vendor      : CentOS
URL         : https://www.memcached.org/

Start memcached service on CentOS 8 / RHEL 8

Now that the package is installed, you need to start the service and optionally set it to start on system boot.

$ sudo systemctl enable --now memcached.service 
Created symlink /etc/systemd/system/multi-user.target.wants/memcached.service → /usr/lib/systemd/system/memcached.service.

To check service status, run:

$ systemctl status memcached
● memcached.service - memcached daemon
Loaded: loaded (/usr/lib/systemd/system/memcached.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2018-12-31 10:26:15 EAT; 44s ago
Main PID: 10856 (memcached)
Tasks: 10 (limit: 5061)
Memory: 3.8M
CGroup: /system.slice/memcached.service
└─10856 /usr/bin/memcached -p 11211 -u memcached -m 64 -c 1024 -l 127.0.0.1,::1
Dec 31 10:26:15 rhel8 systemd[1]: Started memcached daemon.

Configuring Memcached on RHEL 8 / CentOS 8

Memcached configuration file is located in /etc/sysconfig/memcached. You can edit this file to set start options for Memcached service.

$ cat /etc/sysconfig/memcached
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS="-l 127.0.0.1,::1"

As an example, we will set the service to listen on all network interfaces 0.0.0.0 instead of 127.0.0.1. Change the OPTIONS line to below.

 OPTIONS="-l 0.0.0.0,::1"

Restart the service after making the change.

sudo systemctl restart memcached

Confirm new listen address

$ ss -tunelp | grep 11211
tcp LISTEN 0 128 0.0.0.0:11211 0.0.0.0:* users:(("memcached",pid=10896,fd=28)) uid:995 ino:44588 sk:5 <->
tcp LISTEN 0 128 [::1]:11211 [::]:* users:(("memcached",pid=10896,fd=29)) uid:995 ino:44589 sk:7 v6only:1 <->

Configure Memcached Firewall

If you have clients that need to connect to your Memcached server, you’ll need to open the port on the firewall.

sudo firewall-cmd --add-port=11211/tcp --permanent
sudo firewall-cmd --reload

Enjoy using Memcached to speed up dynamic database-driven websites by caching data in memory. You can also check:

Install and Configure Redis Server on RHEL 8 / CentOS 8

Install and Configure Varnish Cache on CentOS / RHEL 8