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.
In this article we shall cover all the steps required to install and configure Memcached on RHEL 8 / CentOS 8.
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.22
Release : 2.el8
Architecture: x86_64
Install Date: Thu 24 Aug 2023 01:16:51 PM UTC
Group : System Environment/Daemons
Size : 414743
License : BSD
Signature : RSA/SHA256, Mon 12 Apr 2021 07:04:12 AM UTC, Key ID 15af5dac6d745a60
Source RPM : memcached-1.5.22-2.el8.src.rpm
Build Date : Mon 12 Apr 2021 04:45:42 AM UTC
Build Host : ord1-prod-x86build003.svc.aws.rockylinux.org
Relocations : (not relocatable)
Packager : [email protected]
Vendor : Rocky
URL : https://www.memcached.org/
Summary : High Performance, Distributed Memory Object Cache
...
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 Thu 2023-08-24 13:18:02 UTC; 4s 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
Aug 24 13:18:02 rocky8.mylab.io 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: