Technology Blog

How to Install Memcached on CentOS 7


Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.

Memcached is simple yet powerful. Its simple design promotes quick deployment, ease of development, and solves many problems facing large data caches. Its APIis available for most popular languages.

Here is the simple steps to install Memcached on CentOS 7.

Install Memcached:

Install Memcached using the following command.

yum install memcached

Edit Memcached configuration file to change / enable the features.

vi /etc/sysconfig/memcached

There are some default settings available in the configuration file, change it (if necessary). The following is example settings for 256MB caching.


Start Memcached.

systemctl start memcached.service

To auto-start Memcached on booting.

systemctl enable  memcached.service

Confirm the Memcached running status.

memcached-tool stats
#   Field       Value
         accepting_conns           1
               auth_cmds           0
             auth_errors           0
                   bytes           0
              bytes_read           7
           bytes_written           0
              cas_badval           0
                cas_hits           0
              cas_misses           0
               cmd_flush           0
                 cmd_get           0
                 cmd_set           0
               cmd_touch           0
             conn_yields           0
   connection_structures          11
        curr_connections          10
              curr_items           0
               decr_hits           0
             decr_misses           0
             delete_hits           0
           delete_misses           0
       evicted_unfetched           0
               evictions           0
       expired_unfetched           0
                get_hits           0
              get_misses           0
              hash_bytes      524288
       hash_is_expanding           0
        hash_power_level          16
               incr_hits           0
             incr_misses           0
                libevent 2.0.21-stable
          limit_maxbytes   268435456
     listen_disabled_num           0
                     pid       12545
            pointer_size          64
               reclaimed           0
            reserved_fds          20
           rusage_system    0.014289
             rusage_user    0.000000
                 threads           4
                    time  1406441667
       total_connections          11
             total_items           0
              touch_hits           0
            touch_misses           0
                  uptime          48
                 version      1.4.15

Iptables entry:

Add the following entry to allow the incoming connection on port no 11211.

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

Check the remote connectivity.

echo stats | nc memcache_host_name_or_ip 11211

Install PHP Module:

Install Memcached PHP module to work with PHP5.

yum install php php-pecl-memcache

Now restart the Memcached and Apache server to take effect.

systemctl restart memcached.service
systemctl restart httpd.service

That’s all!