How to Install, Configure, and Use Memcached on Linux: A Step‑by‑Step Guide
Learn how to install libevent, compile and set up Memcached on Linux, start the service with common options, monitor it via telnet, interpret detailed statistics, and use basic Memcached commands, all with clear command examples and parameter explanations.
Memcached Overview
Memcached is an open‑source, distributed, high‑performance caching system originally created by Brad Fitzpatrick for LiveJournal. It reduces database load by keeping frequently accessed data in memory.
Install libevent (required dependency)
wget https://github.com/downloads/libevent/libevent/libevent-1.4.14b-stable.tar.gz tar xvzf libevent-1.4.14b-stable.tar.gz ln -s /usr/local/libevent-1.4.14b-stable /usr/local/libevent cd /usr/local/libevent ./configure make make installInstall Memcached
wget http://www.memcached.org/files/memcached-1.4.20.tar.gz tar xvzf memcached-1.4.20.tar.gz ln -s /usr/local/memcached-1.4.20 /usr/local/memcached cd /usr/local/memcached ./configure --with-libevent=/usr/local/libevent/ make make installStart Memcached
After a successful build, start the daemon with a typical command:
/usr/local/bin/memcached -d -m 64 -I 20m -u root -l 192.168.1.6 -p 11211 -c 1024 -P /usr/local/memcached/memcached.pidCommon Startup Parameters
-d Run as a daemon.
-m Memory size (in MB) allocated to the cache.
-I Maximum item size.
-u User account under which the process runs.
-l Listening IP address (comma‑separated for multiple interfaces).
-p Listening port.
-c Maximum concurrent connections.
-P Path to the PID file.
-t Number of worker threads.
-s Unix socket file for local connections.
-a Permissions for the Unix socket.
-v Verbose output (warnings and errors).
Stop Memcached
ps -ef | grep memcached kill -9 <PID>Telnet client for monitoring
Use telnet to connect to the Memcached port and issue commands.
telnet 192.168.2.66 11211Example statistics (output of stats )
STAT pid 20487– process ID. STAT uptime 166666 – seconds since the server started. STAT version 1.4.20 – server version. STAT libevent 1.4.14 – libevent version. STAT curr_connections 60 – current open connections. STAT total_connections 6600 – total connections since start. STAT rusage_user 160 – cumulative user CPU time. STAT rusage_system 160.666 – cumulative system CPU time. STAT cmd_get 16000 – total GET commands received. STAT cmd_set 26000 – total SET commands received. STAT get_hits 960060 – successful GETs. STAT get_misses 174 – GETs that missed. STAT bytes_read 666666666 – total bytes read. STAT bytes_written 1666666666 – total bytes sent. STAT limit_maxbytes 1166666 – maximum memory allocated for caching. STAT threads 20 – number of worker threads. STAT curr_items 566 – current stored items. STAT total_items 166666 – total items stored since start.
Memcached command syntax
Storage command format
<command name> <key> <flags> <exptime> <bytes>
<data block>
Parameter explanation
<command name> : set, add or replace.
<key> : Identifier for the stored item.
<flags> : 32‑bit integer for client‑specific metadata.
<exptime> : Expiration time in seconds (0 means never expires).
<bytes> : Size of the data block in bytes.
<data block> : The actual value to be stored.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Full-Stack DevOps & Kubernetes
Focused on sharing DevOps, Kubernetes, Linux, Docker, Istio, microservices, Spring Cloud, Python, Go, databases, Nginx, Tomcat, cloud computing, and related technologies.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
