Configure Memcached Distributed Memory Caching System

Memcached can speed up database driven dynamic web site. It must be deployed within trusted network where vm01 and vm02 clients may freely connect to our server. You need to type the following commands on vm03 having an IP address

Install memcached server on vm03

Type the following yum command to install memcached server on RHEL based system:
# yum install -y memcached

Install memcached client on vm01 and vm02

You may need to install any one of the following package on vm01 and vm02 (server running php5+apache/Lighttpd):

  1. perl-Cache-Memcached : Perl client (library) to work with memcached server.
  2. python-memcached : Python client (library) to work with memcached server.
  3. php-pecl-memcache : PHP extension to work with the Memcached server.

Configure memcached

Edit /etc/sysconfig/memcached file, enter:
# vi /etc/sysconfig/memcached
Sample outputs:

## make sure we accept connection from vm01 and vm02 on

Save and close the file. Start the memcached server:
# chkconfig memcached on
# /sbin/service memcached start

Edit /etc/sysconfig/iptables and make sure only vm01 and vm02 are allowed to connect to the our server:

## open vm01 and vm02 tcp/udp port for memcached server ##
-A INPUT -m state --state NEW -s -m tcp -p tcp --dport 11211 -j ACCEPT
-A INPUT -m state --state NEW -s -m udp -p udp --dport 11211 -j ACCEPT
-A INPUT -m state --state NEW -s -m udp -p udp --dport 11211 -j ACCEPT
-A INPUT -m state --state NEW -s -m tcp -p tcp --dport 11211 -j ACCEPT

Save and close the file. Restart the iptables service, enter:
# /sbin/service iptables restart
# /sbin/iptables -L -v -n

Increase file system and ports limits on vm03

For busy memcached server you need to increase system file descriptor and IP port limits:

# Increase system file descriptor limit to
fs.file-max = 50000
# Increase system IP port limits
net.ipv4.ip_local_port_range = 2000 65000

Load the changes by typing the following sysctl command to modify Linux kernel parameters at runtime:
# sysctl -p

See also

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 4 comments so far... add one
CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
4 comments… add one
  • Jalal Hajigholamali Jun 23, 2012 @ 2:34

    very nice article…

  • Amit Jun 23, 2012 @ 5:53

    I believe the line no 2 of the client installation need to be update.

    Currently its like:
    python-memcached : Perl client (library) to work with memcached server.

    should not be it ” python client “

  • 🐧 nixCraft Jun 23, 2012 @ 8:04


    Thanks for the heads up!

  • Rani Laxmi Mar 10, 2021 @ 7:26

    Will this work on modern CentOS 8?

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum