How to Configure Memcached Log File Location in RHEL/CentOS: A sysadmin’s Guide to Log Management


5 views

When installed via yum on RHEL/CentOS systems, Memcached typically doesn't write to a dedicated log file by default. The service outputs its logs through syslog, which might not be ideal for debugging or monitoring purposes.

The most straightforward method is to modify the /etc/sysconfig/memcached file. Add the following parameter to the OPTIONS variable:

OPTIONS="-vv >> /var/log/memcached.log 2>&1"

This configuration will:

  • Enable verbose logging (-vv)
  • Redirect both stdout and stderr to your specified log file

For newer systems using systemd, you can configure journald to handle Memcached logs:

# Create a dedicated config file
sudo mkdir -p /etc/systemd/system/memcached.service.d
sudo tee /etc/systemd/system/memcached.service.d/logging.conf <

To prevent log files from growing indefinitely, create a logrotate configuration:

sudo tee /etc/logrotate.d/memcached <

If logs aren't appearing as expected:

  • Verify file permissions: sudo chown memcached:memcached /var/log/memcached.log
  • Check SELinux context: sudo chcon -t memcache_log_t /var/log/memcached.log
  • Restart the service: sudo systemctl restart memcached

For more advanced logging setups, you can configure rsyslog to filter Memcached messages:

# Create a rsyslog config file
sudo tee /etc/rsyslog.d/memcached.conf <

When running memcached through the default RHEL/CentOS package installation, logging behavior differs from manual compilation. The yum-installed version uses syslog by default rather than writing to a dedicated file.

To redirect memcached logs to a specific file, you'll need to modify both the init script and syslog configuration:


# First, edit /etc/sysconfig/memcached
OPTIONS="-vv >> /var/log/memcached.log 2>&1"

For more robust logging management, configure rsyslog:


# Create /etc/rsyslog.d/memcached.conf
:programname, isequal, "memcached" /var/log/memcached.log
& stop

Add this to /etc/logrotate.d/memcached for proper log management:


/var/log/memcached.log {
    weekly
    missingok
    rotate 12
    compress
    delaycompress
    notifempty
    create 644 memcached memcached
}

After making changes, restart services in this order:


service rsyslog restart
service memcached restart

Check the new log file with:


tail -f /var/log/memcached.log