How to install Memcached on CentOS 6 / RHEL 6
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.
[[email protected]~/]$ su -l
Install Memcached using the following command.
[[email protected]~/]# yum install memcached
Edit Memcached configuration file to change / enable the features.
[[email protected]~/]# 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=""
[[email protected]~/]# /etc/init.d/memcached restart
To auto-start Memcached on booting.
[[email protected]~/]# chkconfig memcached on
Confirm the Memcached running status.
[[email protected]~/]# 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
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.
[[email protected]~/]# echo stats | nc memcache_host_name_or_ip 11211
Install PHP Module:
Install Memcached PHP module to work with PHP5.
[[email protected]~/]# yum install php php-pecl-memcache
Now restart the Memcached and Apache server to take effect.
[[email protected]~/]# /etc/init.d/memcached restart [[email protected]~/]# /etc/init.d/httpd restart