How to install Memcached on Debian 10?

Overview

Memcached is a free and open-source application. It is used to speed up dynamic web applications by reducing the database load.

This tutorial demonstrates how to set up Memcached on Debian 10.

Prerequisites

There are certain prerequisites that need to be met before you begin.

  • A server running Ubuntu 22.04

  • Non-root sudo user privileges

Get Started

Step 1 - Memcached installation for Debian 10

  • The Ubuntu 20.04 repositories contain the memcached package. Enter the following command as root or user with sudo access to install it:

sudo apt update
sudo apt install memcached libmemcached-tools

The libmemcached-tools package contains many command-line tools for communicating with the Memcached server.

  • The Memcached service will launch automatically after the installation is finished. You can confirm it by examining the service's state:

sudo systemctl status memcached

Congratulations! Memcached is successfully installed on your Debian 10 server.

Step 2 - Setting up Memcached

  • The /etc/memcached.conf file allows for the configuration of Memcached options. For the majority of users, the default configuration options are adequate.

Step 3 - Remote Access

  • Memcached can be used to launch a distributed denial-of-service (DDoS) attack if it is improperly configured. You must set up your firewall such that only trustworthy clients are permitted access to the Memcached UDP port 11211 in order to allow remote connections to the Memcached server.

  • It is assumed in the example below that you are connected via a private network to the Memcached server.

  • Edit the memcached configuration first, then configure the service to listen on the server's private networking interface. This can be done by opening the memcached.conf settings file:

sudo nano /etc/memcached.conf
  • Find the line that starts with -l 127.0.0.1, and substitute 192.168.100.20 for 127.0.0.1 in that line.

  • To make the modifications effective, restart the Memcached service:

sudo systemctl restart memcached
  • The memcached port must be opened in the firewall after the service has been configured.

sudo ufw allow from 192.168.100.30 to any port 11211

You can now establish a connection to the Memcached server from a remote location.

Step 4 - Getting Connected to Memcached

Memcached clients are available in a variety of versions and in numerous programming languages.

  • For working with memcache, there are numerous Python libraries. With pip, you can install the library of your choice:

pip install pymemcache
pip install python-memcached

Conclusion

We have successfully demonstrated how to set up Memcached on Debian 10.

Last updated