Caching

How to Install and Configure Memcached on OpenSUSE Leap 15.3

Pinterest LinkedIn Tumblr

In this guide we will learn how to install and configure Memcached in ROpenSUSE Leap 15.3.

Memcached is an open source, distributed memory object caching system. The system caches data and objects in memory to minimize the frequency with which an external database or API must be accessed. This alleviates database load and speeds up dynamic Web applications. It offers a mature, scalable, open-source solution for delivering sub-millisecond response times making it useful as a cache or session store. Memcached is a popular choice for powering real-time applications in Web, Mobile Apps, Gaming, Ad-Tech, and E-Commerce.

Unlike databases that store data on disk or SSDs, Memcached keeps its data in memory. By eliminating the need to access disks, in-memory key-value stores such as Memcached avoid seek time delays and can access data in microseconds. Memcached is also distributed, meaning that it is easy to scale out by adding new nodes. And since Memcached is multithreaded, you can easily scale up compute capacity. As a result of its speed and scalability as well as its simple design, efficient memory management, and API support for most popular languages Memcached is a popular choice for high-performance, large-scale caching use cases.

Related Content:

Table of Content

  1. Ensuring that the server is up to date
  2. Installing Memcached
  3. Start and enable memcached service
  4. Enable Memcached on firewall
  5. Configure memcached

1. Ensuring that the server is up to date

Before proceeding, it is always a good practice to ensure that the server packages are updated. Use this command to achieve that:

sudo zypper ref
sudo zypper update -y

Let us also install common packages that we will need during our installation and configuration.

sudo zypper install -y vim

2. Installing Memcached

Memcached packages are available in the default OpenSUSE Leap repositories. Install them using this command:

sudo zypper install -y memcached

Confirm the installation of memcached

~> rpm -qi memcached
Name        : memcached
Version     : 1.5.6
Release     : 4.7.1
Architecture: x86_64
Install Date: Wed Jan 12 19:36:12 2022
Group       : Productivity/Networking/Other
Size        : 195610
License     : BSD-3-Clause
Signature   : RSA/SHA256, Thu May 20 14:16:23 2021, Key ID 70af9e8139db7c82
Source RPM  : memcached-1.5.6-4.7.1.src.rpm
Build Date  : Thu May 20 14:15:52 2021
Build Host  : sheep68
Relocations : (not relocatable)
Packager    : https://www.suse.com/
Vendor      : SUSE LLC <https://www.suse.com/>
URL         : http://memcached.org/
Summary     : A high-performance, distributed memory object caching system
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.

Danga Interactive developed memcached to enhance the speed of
LiveJournal.com, a site which was already doing 20 million+ dynamic
page views per day for 1 million users with a bunch of webservers and a
bunch of database servers. memcached dropped the database load to
almost nothing, yielding faster page load times for users, better
resource utilization, and faster access to the databases on a memcache
miss.
Distribution: SUSE Linux Enterprise 15

3. Start and enable memcached service

Once the service is installed, it will not be started by default. Use this command to start the service

sudo systemctl start memcached

Confirm that the service is started with this command:

~> sudo systemctl status memcached
● memcached.service - memcached daemon
     Loaded: loaded (/usr/lib/systemd/system/memcached.service; disabled; vendor preset: disabled)
     Active: active (running) since Wed 2022-01-12 19:36:33 UTC; 5s ago
   Main PID: 15787 (memcached)
      Tasks: 10 (limit: 4587)
     CGroup: /system.slice/memcached.service
             └─15787 /usr/sbin/memcached -u memcached -l 127.0.0.1

Jan 12 19:36:33 dev-susesrv.inv.re systemd[1]: Started memcached daemon.

The output above is a confirmation that Memcached is up and running.

To enable the service on boot

sudo systemctl enable memcached

4. Enable Memcached on firewall

open port 11211 on the firewall to allow traffic from the client host.

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

To confirm that port 11211 is opened on the firewall, execute the command.

$ sudo firewall-cmd --list-ports | grep 11211

If you are using rich rules

firewall-cmd --permanent --zone=public --add-rich-rule 'rule family="ipv4" source address="10.83.200.0/24" port port=11211 protocol=tcp accept

5. Configure memcached

The memcached config is located in this path /etc/sysconfig/memcached. Use this command to open the file for editing.

sudo vim /etc/sysconfig/memcached

This is the default memcached configuration.

## Path:        Network/WWW/Memcached
## Description: start parameters for memcached.
## Type:        string
## Default:     "-l 127.0.0.1"
## Config:      memcached
#
# start parameters for memcached.
#
# see man 1 memcached for more
#
MEMCACHED_PARAMS="-l 127.0.0.1"

## Path:        Network/WWW/Memcached
## Description: username memcached should run as
## Type:        string
## Default:     "memcached"
## Config:      memcached
#
# username memcached should run as
#
MEMCACHED_USER="memcached"

## Path:        Network/WWW/Memcached
## Description: group memcached should be run as
## Type:        string
## Default:     "memcached"
## Config:      memcached
#
# group memcached should be run as
#
MEMCACHED_GROUP="memcached"

By default, Memcached listens to port 11211 and is configured to listen only to the localhost system as shown in the final line. To configure Memcached so that applications from the remote systems can connect to the server, you need to change the localhost address 127.0.0.1 to the address of the remote host or to listen on all interfaces.

To use the remote host, replace the localhost address with the remote client’s IP 10.70.5.214 as shown.

MEMCACHED_PARAMS="-l 10.70.5.214,::1"

To listen on all network interfaces 0.0.0.0 instead of 127.0.0.1. Change the OPTIONS line to below.

 MEMCACHED_PARAMS="-l 0.0.0.0,::1"

Once done configuring, restart the memcached server to apply the changes:

sudo systemctl restart memcached

Confirm the changes with this command

$ sudo ss -tulpn | grep 11211
tcp   LISTEN 0      128      10.70.5.214:11211      0.0.0.0:*    users:(("memcached",pid=55522,fd=28))
tcp   LISTEN 0      128            [::1]:11211         [::]:*    users:(("memcached",pid=55522,fd=29))

Wrapping up

That is it! In this guide, we learned how to install and configure Memcached server on a OpenSUSE Leap 15.3 Server. You can now configure your applications to connect and use the Memcached instance.

I am a Devops Engineer, but I would describe myself as a Tech Enthusiast who is a fan of Open Source, Linux, Automations, Cloud and Virtualization. I love learning and exploring new things so I blog in my free time about Devops related stuff, Linux, Automations and Open Source software. I can also code in Python and Golang.

Write A Comment