news
Serverspace has added a new Rocky Linux OS
VB
Vyacheslav Breus
July 27, 2022
Updated June 7, 2023

Install memcached on Ubuntu 20.04

Linux Ubuntu

Using another OS?

Select the desired version or distribution.

What is memcached and why should you use it

By default, much of "temporary" data is stores to the files on the disk. And it's so slow even if this drive is modern SSD. Obvious way to increase system performance is "drop" temp-files to the RAM. Most used method to do this is memcached.

Before the installation

To install secure service for caching you need:

  • Server with Linux operation system, e.g. Ubuntu 20.04
  • Privileged access credentials (root access or sudo permissions)
  • Optional - system firewall enabled

Install the service and tools

Setup procedure is very-very simple. Just do this:

Authorize as privileged user and update system software cache
sudo -s
apt-get update

pic.1

Main package and support tools installation:
apt-get install libmemcached-tools memcached -y

pic.2

Basic configuration

Caching service stores its settings into the file /etc/memcached.conf. The most interesting options is:

-m # how much memory is reserves into the RAM for caching
-p # used TCP-port which service will listen
-U # UDP-port (optional)
-l # service-listening IP-address, usually 127.0.0.1 for local services or "external" address for "remote"
-c # how much simultaneous connections are allowed
-S # this flag needed to use authentication (see below)

pic.3

To accept incoming connections please permit this on the system firewall side:

ufw allow <PORT>

pic. 4

Increase the safety

In case your server is accessible from the outside, some carrying about security would be nice.  In next steps we will implement simple authentication for memcached. Make follow steps to do it:

  • One-line installation:
apt-get -y install sasl2-bin

pic. 5

  • Adding the configuration:
mkdir /etc/sasl2; nano /etc/sasl2/memcached.conf

pic.6

  • Next step you can add the password and fix file ownership. NOTE: it is not system user, memcached has separate authorization:
saslpasswd2 -c -f /etc/sasl2/memcached-sasldb2 -a memcached <MEMCACHED_USERNAME>
chown memcache:memcache /etc/sasl2/memcached-sasldb2

pic.7

  • To apply all changes service restart needed:
service memcached restart

Check the result

You can simply check is caching service run or not. Just run:

memcstat --servers="<LISTENING_IP>" --username=<MEMCACHED_USERNAME> --password=<MEMCACHED_PASSWORD>

You should see something like this

pic. 8

Summary

This instruction learns you what is caches using aim, how to setup, tuning and secure this.

Vote:
5 out of 5
Аverage rating : 5
Rated by: 2
1101 CT Amsterdam The Netherlands, Herikerbergweg 292
+31 20 262-58-98
700 300
ITGLOBAL.COM NL
700 300
We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.