How to Safely and Completely Uninstall Memcached in an LNMP Environment
Uninstalling Memcached incorrectly in an LNMP (Linux, Nginx, MySQL, PHP) environment can leave behind residual files and configurations, potentially affecting system stability. This guide provides a standardized procedure for safely and thoroughly removing Memcached from a CentOS system (using LNMP 1.5 as an example).
Step 1: Stop the Memcached Service
First, stop any running Memcached processes.
service memcached stop
# For systems using systemd (e.g., CentOS 7+):
# systemctl stop memcached
Step 2: Disable Automatic Startup
Prevent Memcached from starting automatically on system reboot.
chkconfig memcached off
chkconfig --del memcached
# For systemd systems:
# systemctl disable memcached
Step 3: Remove Related Files and Directories
Delete the Memcached installation, configuration, and executable files. The paths below are common defaults for LNMP compilation installations; adjust them based on your actual setup.
# Remove the init script
rm -f /etc/rc.d/init.d/memcached
# Remove the installation directory
rm -rf /usr/local/memcached
# Remove the executable symlink or copy
rm -rf /usr/bin/memcached
# Optionally, remove configuration files if they exist:
# rm -f /etc/sysconfig/memcached
# rm -f /etc/memcached.conf
Step 4: Verify the Uninstallation (Optional)
After completing the steps, verify that Memcached has been fully removed.
# Check service status
service memcached status 2>&1 | grep -i 'not found' || echo 'Service may still have remnants.'
# Check for the executable
which memcached 2>/dev/null && echo 'Executable file still exists.' || echo 'Executable file removed.'
# Check for running processes
ps aux | grep memcached | grep -v grep
Important Notes:
- Before running deletion commands (especially
rm -rf), double-check the paths to avoid accidentally removing critical system files.- If Memcached was installed via a package manager (e.g., yum/rpm), use
yum remove memcachedorrpm -e memcachedinstead. The package manager will handle dependencies and cleanup automatically.- This guide uses CentOS 6.x and LNMP 1.5 as references. For newer systems (e.g., CentOS 7/8, AlmaLinux, Rocky Linux 8+), use
systemctlfor service management, but the file deletion logic remains similar.