How to Install Memcached on CentOS 8

Install Memcached on CentOS 8

In this article, we will have explained the necessary steps to install and configure Memcached on CentOS 8. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Memcached is a free and open-source high-performance memory caching system. It’s typically used to cache database data, API calls or page rendering chunks in RAM to increase the application performance.

Install Memcached on CentOS

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo yum update

Step 2. Install Memcached on CentOS.

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

sudo yum install memcached

Once the installation is completed, start and enable the Memcached service:

sudo systemctl enable --now memcached.service 
sudo systemctl status memcached

Step 3. Configuring Memcached on CentOS 8.

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

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

This is a brief description of the parameters:

**PORT**: The default port used by Memcached to run.
**USER**: The user Memcached runs as.
**MAXCONN**: The maximum number of allowed connections to Memcached. You can increase to any number based on your requirements.
**CACHESIZE**: The cache size for memory.
**OPTIONS**: Set IP address of server, so that Apache or Nginx web servers can connect to it.

Restart the service after making the change:

sudo systemctl restart memcached

Step 4. Configure Firewall for Memcached.

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

Congratulation, you have learned how to install and configure Memcached on CentOS 8. If you have any question, please leave a comment below.