RHEL / CentOS 6 Linux Install Memcached High Performance Distributed Memory Object Cache Server
ow do I install memcached server under Red Hat Enterprise Linux or CentOS Linux version6.x server running on IBM hardware to cache query for my php/perl/python based apps?
memcached is a high-performance, distributed memory object caching server, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load. You need to install the following packages:
- memcached : High Performance, Distributed Memory Object Cache server package.
- perl-Cache-Memcached : Perl client (library) to work with memcached server.
- python-memcached : Python client (library) to work with memcached server.
- php-pecl-memcache : PHP extension to work with the Memcached server.
Memcached is used by many high traffic sites including YouTube, Reddit, Facebook, Twitter, and many others.Google App Engine, AppScale and Amazon Web Services also offer a memcached service through an API. Memcached is also supported by popular open source projects and CMSs such as Drupal, Joomla, WordPress, and many more.
These examples only works with RHEL / CentOS Linux version 6.x or above
. For RHEL 5.x and older version use yum install memcached.x86_64 php-pecl-memcache.x86_64
# netstat -tulpn | grep :11211
tcp 0 0 192.168.1.15:11211 0.0.0.0:* LISTEN 24964/memcached
udp 0 0 192.168.1.15:11211 0.0.0.0:* 24964/memcached
Use the memcached-tool to get general stats about the server:
# memcached-tool 192.168.1.15:11211 stats
#192.168.1.15:11211 Field Value
How do I configure Firewall to protect my Memcached server?
Make sure iptables only allows access to your own servers. Edit /etc/sysconfig/iptables and append the following rules or add it as follows to your shell scripts:
## add to your shell script ##
## assumption default INPUT policy is set to DROP ##
## only accept connection to tcp/udp port 11211 if ip is between 192.168.1.10 and 192.168.1.15 ##
iptables -A INPUT -p tcp --destination-port 11211 -m state --state NEW -m iprange --src-range 192.168.1.10-192.168.1.15 -j ACCEPT
iptables -A INPUT -p udp --destination-port 11211 -m state --state NEW -m iprange --src-range 192.168.1.10-192.168.1.15 -j ACCEPT
See our RHEL / CentOS firewall tutorial here and here for more information about setting up firewall.
How Do I Cache MySQL Queries Using Memcached?
You need to modify your php code using APIs. You can find examples and code samples here. Alternately, you can install memcached extensions such as WordPress extension/plugins if you are using worpdress as CMS.
References: Sysadmin because even developers need heroes!!!
Share this tutorial on: