Blog / Linux/ How to Safely and Completely Uninstall Memcached in an LNMP Environment

How to Safely and Completely Uninstall Memcached in an LNMP Environment

如何在 LNMP 环境中安全彻底地卸载 Memcached 服务

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 memcached or rpm -e memcached instead. 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 systemctl for service management, but the file deletion logic remains similar.

Post a Comment

Your email will not be published. Required fields are marked with *.