How To Install Memcached on Ubuntu 20.04
Posted on July 1, 2021 • 3 min read • 475 words## Overview {#h-overview}
In this tutorial we’ll learn how to install Memcached on Ubuntu 20.04 (LTS) Focal Fossa.
Memcached (pronounced: mem-cash-dee) is a free, high performance, distributed memory object caching system.
Memcached can be use for any caching usage but mostly used by dynamic web application to reduce database load. We can also cache API calls and page rendering.
For installing memcached on previous version of Ubuntu LTS you can read:
This tutorial assumes you have a fresh install of Ubuntu 20.04 Server. You can also follow this tutorial on any Ubuntu 20.04 flavors.
Using Ubuntu server will give minimalist installation of Ubuntu.
Let’s update our base system to latest update using command below.
sudo apt-get update
sudo apt-get upgrade
Install memcached by running command below
sudo apt-get install memcached
That’s it, memcached installed. Now let’s check whether memcached already started and listen to specific port.
Run netstat and find memcached process.
$ sudo netstat -naptu | grep memcached
tcp 0 0 127.0.0.1:11211 0.0.0.0:* LISTEN 3125/memcached
udp 0 0 127.0.0.1:11211 0.0.0.0:* 3125/memcached
Or we can also run run netstat and find memcached default port 11211
$ sudo netstat -naptu | grep 11211
tcp 0 0 127.0.0.1:11211 0.0.0.0:* LISTEN 3125/memcached
udp 0 0 127.0.0.1:11211 0.0.0.0:* 3125/memcached
We can also use ss as replacement of netstat to check where memcached listen.
ss -4n state listening | grep 11211
tcp 0 128 127.0.0.1:11211 *:*
We can check memcached service status by running command below. This is sysv compatible service command.
ubuntu@ubuntu-xenial:~$ sudo service memcached status
● memcached.service - memcached daemon
Loaded: loaded (/lib/systemd/system/memcached.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2018-09-29 02:24:57 UTC; 53s ago
Main PID: 2351 (memcached)
CGroup: /system.slice/memcached.service
└─2351 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1
Sep 29 02:24:57 ubuntu-xenial systemd[1]: Started memcached daemon.
Since Ubuntu 20.04 already use systemd, we can also systemctl
command to check memcached service status.
$ sudo systemctl status memcached
● memcached.service - memcached daemon
Loaded: loaded (/lib/systemd/system/memcached.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2018-09-29 02:24:57 UTC; 1min 4s ago
Main PID: 2351 (memcached)
CGroup: /system.slice/memcached.service
└─2351 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1
Sep 29 02:24:57 ubuntu-xenial systemd[1]: Started memcached daemon.
Now we have memcached running let’s learn how to configure memcached. Memcached comes with two configuration files.
/etc/default/memcached
/etc/memcached.conf
We can enable or disable memcached on boot by changing parameter on /etc/default/memcached
file. The default value on this file is
ENABLE_MEMCACHED=yes
To disable memcached on boot we need to change the line above to
ENABLE_MEMCACHED=no
Now let’s check /etc/memcached.conf
configuration file.
Memcached’s logging
directive is skipped by systemd-memcached-wrapper. This script located in /usr/share/memcached/scripts/systemd-memcached-wrapper
. In this scipt you can find line: