How to install Memcached on CentOS 6 / RHEL 6

0

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 6.

Open Terminal and then switch to root user.

[raj@geeksite~/]$ su -l

Install Memcached:

Install Memcached using the following command.

[root@geeksite~/]# yum install memcached

Edit Memcached configuration file to change / enable the features.

[root@geeksite~/]# 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.

PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="256"
OPTIONS=""

Start Memcached.

[root@geeksite~/]# /etc/init.d/memcached restart

To auto-start Memcached on booting.

[root@geeksite~/]# chkconfig memcached on

Confirm the Memcached running status.

[root@geeksite~/]# memcached-tool  127.0.0.1:11211 stats
#127.0.0.1:11211   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
             conn_yields           0
   connection_structures          11
        curr_connections          10
              curr_items           0
               decr_hits           0
             decr_misses           0
             delete_hits           0
           delete_misses           0
               evictions           0
                get_hits           0
              get_misses           0
               incr_hits           0
             incr_misses           0
          limit_maxbytes    67108864
     listen_disabled_num           0
                     pid       29594
            pointer_size          64
           rusage_system    0.002999
             rusage_user    0.000000
                 threads           4
                    time  1332048624
       total_connections          11
             total_items           0
                  uptime          85
                 version       1.4.4

Iptables entry:

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

-A INPUT -m state --state NEW -m tcp -p tcp --dport 11211 -j ACCEPT

Check the remote connectivity.

[root@geeksite~/]# echo stats | nc memcache_host_name_or_ip 11211

Install PHP Module:

Install Memcached PHP module to work with PHP5.

[root@geeksite~/]# yum install php php-pecl-memcache

Now restart the Memcached and Apache server to take effect.

[root@geeksite~/]# /etc/init.d/memcached restart
[root@geeksite~/]# /etc/init.d/httpd restart

That’s all!

You might also like