Installing memcached on CentOS 7 and Fedora
These instructions are for CentOS and Fedora. They are intended specifically for installing Memcached on a single Linux CentOS or Fedora node. You must be logged in as root to install Memcached.
Install Memcached
First, clean-up yum:
yum clean all
Then, make sure your packages are updated:
yum -y update
Now you can install Memcached and related packages:
yum -y install memcached
Configure the Memcached Installation
Use the following command to view information on the memcached command:
memcached -h
The default configuration file for Memcached can be found at /etc/sysconfig/memcached.
When started, Memcached will start on port 1121 by default per the default configuration file:
PORT="11211" USER="memcached" MAXCONN="1024" CACHESIZE="64" OPTIONS=""
To change the port (PORT), the user Memcached runs as (USER), the maximum connections of allowed connections to Memcached (MAXCONN), or the cache size in megabytes(CACHESIZE), simply edit them in the configuration file.
For example, if I want to run Memcached on port 1337 with 4GB of memory and allow a maximum of 2,000 connections, I would change the config file as follows
vim /etc/sysconfig/memcached
Edit the configuration:
PORT="1337" USER="memcached" MAXCONN="2000" CACHESIZE="4096" OPTIONS=""
Exit and save the configuration file, then restart Memcached.
systemctl restart memcached
Configure Memcached to Start on Boot
To enable memcached to start on boot, use the following command:
systemctl enable memcached
Start, Stop and Check Status
You can run the following commands to start, stop and check the status of Memcached.
Start
systemctl start memcached
Stop
systemctl stop memcached
Check Status
systemctl status memcached
Now that you’ve seen how to install Memcached, let’s take a look at how to install the PHP Extension in our article Installing Memcached PHP Extension for CentOS and Fedora.