(Last Updated On: December 31, 2018)

In this tutorial, we will cover the installation of Memcached on 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.

How to Install Memcached on RHEL 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 : 1.el8
Architecture: x86_64
Install Date: Mon 31 Dec 2018 10:24:23 AM EAT
Group : System Environment/Daemons
Size : 286906
License : BSD
Signature : RSA/SHA256, Mon 13 Aug 2018 02:36:38 PM EAT, Key ID 938a80caf21541eb
Source RPM : memcached-1.5.9-1.el8.src.rpm
Build Date : Sun 12 Aug 2018 06:08:41 PM EAT
Build Host : x86-vm-10.build.eng.bos.redhat.com
Relocations : (not relocatable)
Packager : Red Hat, Inc. http://bugzilla.redhat.com/bugzilla
Vendor : Red Hat, Inc.
URL : https://www.memcached.org/
Summary : High Performance, Distributed Memory Object Cache
Description :
memcached is a high-performance, distributed memory object caching
system, generic in nature, but intended for use in speeding up dynamic
web applications by alleviating database load.

How to Start memcached service on 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

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