@JS's Notes

Site with notes from my work.

How to install Memcached caching server on CentOS 7

2019-10-08 System @JS

My test platform: CentOS Linux release 7.6.1810 (Core)

Memcached is an open source distributed memory object caching program that allows improve and speed up the performance of dynamic web applications by caching data and objects in memory. Memcached is also used to cache entire database tables and queries to improve the performance.

Requirements: user with root privileges or non-root user with sudo privileges.

Installation
$ sudo yum -y update 
$ sudo yum -y install memcached libmemcached
Memcached protection

We change the OPTIONS variable in the configuration file /etc/sysconfig/memcached thanks to which Memcached will listen on the local interface. These configuration settings will protect our server from denial of service attacks.

PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="2048"
OPTIONS="-l 127.0.0.1 -U 0" 
  • PORT: The port used by Memcached.
  • USER: The start-up daemon for Memcached service.
  • MAXCONN: The value used to set max simultaneous connections to 1024. For busy web servers you can increase depending on your requirements.
  • CACHESIZE: Set cache size memory to 2048. For busy servers you can increase up to 4GB.
  • OPTIONS: Set IP address of server, so that Apache or Nginx web servers can connect to it.

Start the service and enable the start Memcached together with the system:

$ sudo systemctl start memcached.service
$ sudo systemctl status memcached.service
$ sudo systemctl enable memcached.service

You can check the stats of the server using memcached-tool:

$ memcached-tool 127.0.0.1 stats

Make sure to allow access to Memcached server by opening a port 11211 on firewall:

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