Introduction
Memcached is an open-source, high-performance, in-memory key-value object caching system used to improve and speed up web applications that make heavy use of databases by caching objects in Memory.
This article will explain how to install and secure Memcached on CentOS 7.
Prerequisites
- A root or non-root user with
sudoprivileges.
Install Memcached
- Update the software repository before installing new software.
# sudo yum update -
Install the official Memcached package
memcachedandlibmemcachedwhich provides utilities to work with Memcached.# sudo yum install -y memcached libmemcached -
Start Memcached at boot using
systemctla command.# sudo systemctl enable memcached
Configuring Memcached
-
Open the
/etc/sysconfig/memcachedfile.
Find# sudo vi /etc/sysconfig/memcachedOPTIONSvariable and replace the empty value withOPTIONS="-l 127.0.0.1 -U 0"to bind Memcached to the local network. -
Save the file and exit from the editor then restart the Memcached service.
# sudo systemctl restart memcached -
To verify that Memcached is up and running follow the command.
Output:# memstat --servers="127.0.0.1"
Bind Memcached to the Private Network
-
Open the
/etc/sysconfig/memcachedfile.
Find# sudo vi /etc/sysconfig/memcachedOPTIONSvariable and replace its empty value withOPTIONS="-l YOUR_SEREVR_IP -U 0 -S -vv"to bind Memcached to the private network.
-
Save and close the file then restart the Memcached service.
# systemctl restart memcached - Verify that your Memcached service is bound to the private IP follow the below command.
# sudo netstat -plunt