Install memcached on Ubuntu 20.04
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:
apt-get update
Basic configuration
Caching service stores its settings into the file /etc/memcached.conf. The most interesting options is:
-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)
To accept incoming connections please permit this on the system firewall side:
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:
- Adding the configuration:
- Next step you can add the password and fix file ownership. NOTE: it is not system user, memcached has separate authorization:
chown memcache:memcache /etc/sasl2/memcached-sasldb2
- To apply all changes service restart needed:
Check the result
You can simply check is caching service run or not. Just run:
You should see something like this
Summary
This instruction learns you what is caches using aim, how to setup, tuning and secure this.