Memcached is primarily used to speed up sites that make heavy use of databases. It can store objects of any kind. Many programming languages have a Memcached library, including PHP, Perl, Ruby, and Python. Memcached runs in memory and is thus quite speedy since it does not need to write data to disk.

Installing Memcached

Memcached packages are included in the default CentOS 7 repositories. To install open up a terminal and type in the following command

yum install memcached libmemcached

One you are done with the installation, run the memcached services

[root@codesposts ~]# systemctl start memcached
[root@codesposts ~]# systemctl enable memcached
Created symlink from /etc/systemd/system/multi to /usr/lib/systemd/system/memcached.service.

Now you have a Memcached server running succesfully on a Linux Server

Configuring Memcached

To make assure that installed Memcached service is listening on the local interface, we will alter the OPTIONS variable in the /etc/sysconfig/memcached configuration file. This would protect us from DDoS attacks.

vi /etc/sysconfig/memcached

We will add both the -S and -vv parameters to our OPTIONS variable. The -vv option will provide verbose output to /var/log/memcached, which will help us as we debug. Add these options to the OPTIONS variable as follows:

OPTIONS="-l -U 0 -S -vv"

Save and close the file and restart the Memcached service for the changes to take effect

systemctl restart memcached
systemctl enable memcached

To ensure that Memcached is running, type in the following command:

[root@codesposts ~]# memstat --servers=""
Server: (11211)
         pid: 14054
         uptime: 403
         time: 1562011838
         version: 1.4.15
         libevent: 2.0.21-stable
         pointer_size: 64
         rusage_user: 0.008761
         rusage_system: 0.011682
         curr_connections: 10
         total_connections: 11
         connection_structures: 11
         reserved_fds: 20
         cmd_get: 0
         cmd_set: 0
         cmd_flush: 0
         cmd_touch: 0
         get_hits: 0
         get_misses: 0
         delete_misses: 0
         delete_hits: 0
         incr_misses: 0
         incr_hits: 0
         decr_misses: 0
         decr_hits: 0
         cas_misses: 0
         cas_hits: 0
         cas_badval: 0
         touch_hits: 0
         touch_misses: 0
         auth_cmds: 0
         auth_errors: 0
         bytes_read: 17
         bytes_written: 16
         limit_maxbytes: 67108864
         accepting_conns: 1
         listen_disabled_num: 0
         threads: 4
         conn_yields: 0
         hash_power_level: 16
         hash_bytes: 524288
         hash_is_expanding: 0
         bytes: 0
         curr_items: 0
         total_items: 0
         expired_unfetched: 0
         evicted_unfetched: 0
         evictions: 0
         reclaimed: 0

To check for SASL support

sudo journalctl -u memcached

Make sure that you have allowed access to Memcached server by opening a port 11211 on your firewall using the following command:

firewall-cmd --permanent --zone=public --add-port=11211/tcp