Memcached is a high-performance, distributed memory object caching system, generic in nature, but originally intended for use in speeding up dynamic web applications by alleviating database load. Memcached is a very useful also in other cases, than only dynamic web applications.
This guide explains howto install Memcached 1.4.5 current stable version of distributed memory object caching system on CentOS 5.5, Fedora 12 and Red Hat RHEL 5.5. Fedora 12, Fedora 13 and Red Hat (RHEL) 6 has Memcached 1.4.5 as default so extra repositories is not needed on Fedora 12 or Fedora 13.
Install Memcached 1.4.5 Distributed Memory Object Caching System
Install Remi repository (not needed on Fedora 12 or Fedora 13):
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
Install Memcached package:
yum --enablerepo=remi install memcached Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile [...] Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package memcached.i386 0:1.4.5-2.el5.remi set to be updated --> Finished Dependency Resolution Dependencies Resolved ================================================================================================================================================================================= Package Arch Version Repository Size ================================================================================================================================================================================= Installing: memcached i386 1.4.5-2.el5.remi remi 71 k Transaction Summary ================================================================================================================================================================================= Install 1 Package(s) Update 0 Package(s) Remove 0 Package(s) Total download size: 71 k Is this ok [y/N]: y Downloading Packages: memcached-1.4.5-2.el5.remi.i386.rpm | 71 kB 00:00 Running rpm_check_debug Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Installing : memcached 1/1 Installed: memcached.i386 0:1.4.5-2.el5.remi Complete!
Configure memcached
Most important value to configure is CACHESIZE, which is cache size on Megabytes. Example Following configuration use 512 Mb memory for Memcached
nano -w /etc/sysconfig/memcached PORT="11211" USER="memcached" MAXCONN="1024" CACHESIZE="512" 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 STAT pid 7599 STAT uptime 10 STAT time 1265288542 STAT version 1.4.4 STAT pointer_size 32 STAT rusage_user 0.003999 STAT rusage_system 0.052991 STAT curr_connections 10 STAT total_connections 11 STAT connection_structures 11 STAT cmd_get 0 STAT cmd_set 0 STAT cmd_flush 0 STAT get_hits 0 STAT get_misses 0 STAT delete_misses 0 STAT delete_hits 0 STAT incr_misses 0 STAT incr_hits 0 STAT decr_misses 0 STAT decr_hits 0 STAT cas_misses 0 STAT cas_hits 0 STAT cas_badval 0 STAT auth_cmds 0 STAT auth_errors 0 STAT bytes_read 6 STAT bytes_written 0 STAT limit_maxbytes 536870912 STAT accepting_conns 1 STAT listen_disabled_num 0 STAT threads 4 STAT conn_yields 0 STAT bytes 0 STAT curr_items 0 STAT total_items 0 STAT evictions 0 END # Try to get some value echo get some_value | nc localhost 11211 END # Not found, but check the stats again echo stats | nc localhost 11211 STAT pid 7599 STAT uptime 10 STAT time 1265288542 STAT version 1.4.4 [...] STAT cmd_get 1 STAT cmd_set 0 STAT cmd_flush 0 STAT get_hits 0 STAT get_misses 1 STAT delete_misses 0 [...] STAT evictions 0 END
Everything working nice. Then it’s time to test memcache example with some web application.
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 RH-Firewall-1-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
Install Memcache PHP Module on Fedora 12 and Fedora 13
Install following package
yum install php php-pecl-memcacheRestart Web server
/etc/init.d/httpd restart ## OR ## service httpd restart
Related posts:
- Install Apache (httpd) and PHP 5.3.3 on Fedora 13, CentOS/RHEL 5.5/6 This guide shows howto install Apache HTTP Server (httpd) with PHP 5.3.3 and following modules: PEAR PDO MySQL PostgreSQL Memcache...
- Install MongoDB 1.6.0 on Fedora 13, CentOS 5.5, Red Hat (RHEL) 5.5 What is MongoDB?MongoDB (from “humongous”) is a scalable, high-performance, open source, schema-free, document-oriented database. Written in C++. MongoDB bridges the...
- Install MySQL 5.1 (5.1.50) on Fedora 13, CentOS 5.5, Red Hat (RHEL) 5.5 MySQL is a relational database management system (RDBMS) that runs as a server providing multi-user access to a number of...
- Install OpenOffice.org 3.2.1/3.3.0 on Fedora 13, CentOS/Red Hat (RHEL) 5.5 OpenOffice.org 3.2 is released and the new version has many new features. Example following: Faster Start Up Times - OpenOffice.org...
- Install VirtualBox 3.2.8 on Fedora 13, CentOS 5.5, Red Hat (RHEL) 5.5/6 VirtualBox is a powerful x86 and AMD64/Intel64 virtualization product for enterprise as well as home use. VirtualBox is a general-purpose...
The above instructions work fine for me with Fedora 12. Fedora 13 wasn’t working. /usr/lib/php/modules/memcache.so was missing. Copying that file from Fedora 12 installation seems to work, but I wonder why it was missing. rpm -ql memcached doesn’t show memcache.so.
Hi Charles,
I verified again that the this guide is working also with Fedora 13.
If you want install Memcache PHP module then you need to install following package:
yum install php-pecl-memcacheThen you get /usr/lib/php/modules/memcache.so file right place.
I added this also on end of this guide. :)