Installing and Configuring Memcached on CentOS 7

Memcached – software that implements a data caching service in RAM based on a hash table. By using the client library, it allows you to cache data in the RAM of many available servers.

Installing the memcached service

[[email protected]]# yum -y install memcached

We start the service and add it to startup

[[email protected]]# systemctl start memcached
[[email protected]]# systemctl enable memcached

Configuring Memcached in TCP Run Mode

To do this, edit the configuration file

[[email protected]]# nano /etc/sysconfig/memcached
USER="memcached"
PORT="11211"
MAXCONN="1024"
CACHESIZE="1024"
OPTIONS="-t 8 -l 127.0.0.1 -U 0"

where: – MAXCONN = “1024” – the number of simultaneous connections (by default 1024); – CACHESIZE = “1024” – the amount of memory allocated for the cache (by default 64MB); – OPTIONS = “- t 8 -l 127.0.0.1 -U 0 ″ – number of memcached threads 8 (default 4), listen only on localhost and disable UDP protocol

Restart Memcached

[[email protected]]# systemctl restart memcached

Let’s check that Memcached is bound to the local interface and only listens for TCP connections:

[[email protected]]# netstat -plunt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
. . .
tcp        0      0 127.0.0.1:11211         0.0.0.0:*               LISTEN      2383/memcached
. . .

Setting up Memcached in SOCK mode

Let’s edit the configuration file

[[email protected]]# nano /etc/sysconfig/memcached
USER="memcached"
MAXCONN="1024"
CACHESIZE="1024"
OPTIONS="-t 8 -s /tmp/memcached.sock"

where – USER = “memcached” is the user from which memcached will be launched; – OPTIONS = “- t 8 -s /tmp/memcached.sock” – the number of threads and the path to the socket.

Restart Memcached

[[email protected]]# systemctl restart memcached
Sidebar