Introducing Dragonfly Cloud! Learn More

Question: Where is Memcached config file?

Answer

Memcached is a distributed caching system that stores data in memory. It is widely used to speed up dynamic web applications by reducing database load. The default configuration of Memcached is usually sufficient for most use cases, but sometimes you may need to customize it according to your specific needs.

By default, Memcached does not use a configuration file. Instead, you can set its parameters as command-line options when you start the Memcached daemon. However, some Linux distributions provide a default configuration file at /etc/memcached.conf.

If you want to use a configuration file, create a file called memcached.conf and place it in the /etc directory. Here's an example configuration file:

# Start with a small 16MB memory cache
-m 16

# Use port 11211
-p 11211

# Bind to the loopback interface
-l 127.0.0.1

# Allow connections from localhost only
-u memcached

In this example, we set the size of the memory cache to 16MB (-m 16), use port 11211 (-p 11211), bind to the loopback interface (-l 127.0.0.1), and run the Memcached daemon as the memcached user (-u memcached).

To start Memcached with the configuration file, run:

$ memcached -d -m 1024 -c 1024 -u memcached -l 127.0.0.1 -p 11211 -P /var/run/memcached.pid -t 1 -C -vv < /etc/memcached.conf

In this example, we start the Memcached daemon in the background (-d), set the size of the memory cache to 1GB (-m 1024), set the maximum number of connections to 1024 (-c 1024), use the memcached user (-u memcached), bind to the loopback interface (-l 127.0.0.1), use port 11211 (-p 11211), write the process ID to /var/run/memcached.pid (-P /var/run/memcached.pid), use 1 thread (-t 1), enable CAS support (-C), increase verbosity (-vv), and read the configuration from the /etc/memcached.conf file (< /etc/memcached.conf).

Note that if you specify a configuration option both in the command-line arguments and in the configuration file, the value specified on the command-line takes precedence.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Start building today 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.