Tuesday, January 31, 2012

Install memcached on Centos 6.x

Install Memcached package on
Fedora 16/15/14/13/12, CentOS/Red Hat (RHEL) 6.2/6.1/6

yum install memcached

Configure memcached
Most important value to configure is CACHESIZE, which is cache size on Megabytes. On all systems, particularly 32-bit, ensure that you leave enough room for both memcached application in addition to the memory setting. For example, if you have a dedicated memcached host with 4GB of RAM, do not set the memory size above 3500MB. Failure to do this may cause either a crash or severe performance issues. Example Following configuration use 3072 Mb memory for Memcached:

vi /etc/sysconfig/memcached
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="3072"
OPTIONS=""

Start Memcached
# Set Memcached to start automatically on boot
chkconfig memcached on
# Start Memcached
/etc/init.d/memcached start
## OR ##
service memcached start

Check that Memcached is Running and Working
echo stats | nc localhost 11211

Open Memcached Port (11211) on Iptables Firewall (If the Memcached will also be used other local servers)
Edit /etc/sysconfig/iptables file:
nano -w /etc/sysconfig/iptables
Add following line before COMMIT:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 11211 -j ACCEPT
Restart Iptables Firewall:
service iptables restart
## OR ##
/etc/init.d/iptables restart
Test remote connection:
echo stats | nc memcache_host_name_or_ip 11211


appendix:

To flush all the data from Memcached using command line:


echo "flush_all" | nc 127.0.0.1 11211

No comments:

Post a Comment