Install Memcached on Rocky Linux 9 [Step-by-Step]


Rocky Linux

Author: Omer Cakmak
Reviewer: Deepak Prasad

What is Memcached?

In this tutorial we will cover the steps to install Memcached on Rocky Linux 9. But before we start with the actual installation steps, let learn little bit about Memcached.

Memcached is a free and open source(Licensed under the Revised BSD license) high performance distributed memory object caching system.

Designed to speed up dynamic web applications by easing the database load. Its simple design provides rapid deployment, ease of development and solves many of the problems faced by big data caches. Memcached runs on Unix-like operating systems (Linux and macOS) and on Microsoft Windows. It depends on the libevent library.

Memcached is now used by many other systems, including YouTube, Reddit, Facebook, Pinterest, Twitter, Wikipedia, and OpenStack. Its API is available for most popular languages and applications. For example, Google Cloud Platform, Microsoft Azure and Amazon Web Services offer Memcached service via an API.

After this information, let's move on to "How to install and configure Memcached on Rocky Linux 9".

We will explain the installation of Memcached with 2 methods.

  • In the first method, we will install the version available in the Rocky Linux 9 repositories.
  • Then, in the second method, we will install it by compiling it from the source code.

Let's start.

 

Method-1: Install Memcached from Default Package Repository

Step-1 Installing Memcached

Start the installation by running the following command in the terminal:

[foc@rocky9 ~]$ sudo dnf install memcached -y

That's it for the installation, let's check the version:

[foc@rocky9 ~]$ memcached --version
memcached 1.6.9

 

Step-2 Start and Enable Memcached Service

After installing Memcached, the service is in a stop state. Start it with the following command:

[foc@rocky9 ~]$ sudo systemctl start memcached

Then let's bring it in the enable command to restart the service after reboot:

[foc@rocky9 ~]$ sudo systemctl enable memcached
Created symlink /etc/systemd/system/multi-user.target.wants/memcached.service → /usr/lib/systemd/system/memcached.service.

 

Step-3 Add Firewall Rules for Memcached

Enter the firewall rules for port 11211:

[foc@rocky9 ~]$ sudo firewall-cmd --add-port=11211/tcp --zone=public --permanent
success
[foc@rocky9 ~]$ sudo firewall-cmd --reload
success

We now have access to Memcached when we control access from localhost:

[foc@rocky9 ~]$ telnet localhost 11211
Trying ::1...
Connected to localhost.
Escape character is '^]'.

 

Step-4: Configure Memcached

You can customize the memcached service by changing the /etc/sysconfig/memcached file:

[foc@rocky9 ~]$ sudo nano /etc/sysconfig/memcached

PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS="-l 0.0.0.0,::1"
#OPTIONS="-l 127.0.0.1,::1"

Restart the service for the changes to take effect:

[foc@rocky9 ~]$ sudo systemctl restart memcached

 

Method-2: Install Memcached from Official Source

Step-1 Install Depedencies

Install the packages required for installation into the system:

[foc@rocky9 ~]$ sudo dnf install -y wget nano tar gcc libevent libevent-devel

 

Step-2 Download source package

Copy the link of the version you want to install from its official address and write it after the wget command:

[foc@rocky9 tmp]$ wget https://memcached.org/files/memcached-1.6.17.tar.gz

Or just download the latest version to download the latest version:

[foc@rocky9 ~]$ wget https://memcached.org/latest
--2022-09-23 20:42:01-- https://memcached.org/latest
Resolving memcached.org (memcached.org)... 107.170.231.145
Connecting to memcached.org (memcached.org)|107.170.231.145|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://www.memcached.org/files/memcached-1.6.17.tar.gz [following]
--2022-09-23 20:42:03-- https://www.memcached.org/files/memcached-1.6.17.tar.gz
Resolving www.memcached.org (www.memcached.org)... 107.170.231.145
Connecting to www.memcached.org (www.memcached.org)|107.170.231.145|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1713186 (1.6M) [application/octet-stream]
Saving to: ‘latest’

latest 100%[=============================>] 1.63M 15.7KB/s in 2m 20s

2022-09-23 20:44:27 (11.9 KB/s) - ‘latest’ saved [1713186/1713186]

Then extract it from the compressed file:

[foc@rocky9 ~]$ tar -zxf latest

In the last case you will have a memcached directory which also indicates the version:

[foc@rocky9 ~]$ ls -l
total 1680
-rw-r--r--. 1 foc foc 1713186 Aug 27 03:37 latest
drwxr-xr-x. 7 foc foc 4096 Aug 27 03:37 memcached-1.6.17

Finally move this directory under opt:

[foc@rocky9 ~]$ sudo mv memcached-1.6.17 /opt

 

Step-3 Build Memcached Package

For build go under opt/memcached-1.6.17 directory:

[foc@rocky9 ~]$ cd /opt/memcached-1.6.17/

Then follow the steps below in order for the build:

  • Configure:
[foc@rocky9 memcached-1.6.17]$ sudo ./configure --prefix=/usr/local/memcached
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for a BSD-compatible install... /bin/install -c

...

checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating doc/Makefile
config.status: creating config.h
config.status: executing depfiles commands

Execute Make:

[foc@rocky9 memcached-1.6.17]$ sudo make

Execute Make Install:

[foc@rocky9 memcached-1.6.17]$ sudo make install

Build completed successfully. Installed version:

[foc@rocky9 memcached-1.6.17]$ ./configure --version
memcached configure 1.6.17
generated by GNU Autoconf 2.71

Copyright (C) 2021 Free Software Foundation, Inc.
This configure script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it.

You can configure your applications and systems to use Memcached under this directory.

 

Finally

Using memcached from source code can be cumbersome. If the version in the repository is sufficient, we recommend you to install it with the first method.

You can get local help with the following command in package installation from the repository:

[foc@rocky9 memcached-1.6.17]$ memcached --help

In the second method, the following command will help:

[foc@rocky9 memcached-1.6.17]$ ./configure --help

 

References

memcached.org - Downloads
Github.com - Install Memcached

 

Omer Cakmak

Omer Cakmak

He is highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on OpenStack, KVM, Proxmox, and VMware. You can connect with him on his LinkedIn profile.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to admin@golinuxcloud.com

Thank You for your support!!

Leave a Comment