How to Install, Optimize, and Harden Memcached with WHM/cPanel on AlmaLinux 8

Memcached is an open-source, distributed memory object-caching system that speeds up dynamic web applications by storing data in memory. It is often used to reduce the load on the database server and improve the performance of web applications. In this post, we will guide you on how to install, optimize, and harden Memcached with WHM/cPanel on Almalinux 8.

Step 1: Install Memcached
To install Memcached, log in to your Almalinux server via SSH and run the following command:

yum install memcached

Step 2: Configure Memcached
After installing Memcached, you need to configure it for optimal performance. You can do this by editing the configuration file located at /etc/sysconfig/memcached. Open the file using your favorite text editor and make the following changes:

PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS="-l 127.0.0.1"

Save the file and exit.

Step 3: Enable Memcached in WHM/cPanel
To enable Memcached in WHM/cPanel, log in to WHM and go to Service Configuration > PHP Configuration Editor. Select the PHP version for which you want to enable Memcached and click on “Advanced Mode.” Scroll down to the “Memcached” section and check the box next to “Enable.” Save the changes.

Step 4: Optimize Memcached
To optimize Memcached, you can adjust the “CACHESIZE” parameter in the configuration file to match the amount of available memory on your server. You can also enable “slab reassignment” by adding the following line to the configuration file:

OPTIONS="-l 127.0.0.1 -R 1"

This will allow Memcached to automatically redistribute memory when a slab becomes full.

Step 5: Harden Memcached
To harden Memcached, you can add a firewall rule to only allow incoming traffic from trusted IP addresses. For example, to allow incoming traffic from IP address 192.168.1.100, run the following command:

iptables -A INPUT -p tcp -s 192.168.1.100 --dport 11211 -j ACCEPT

You can also change the default port (11211) to a non-standard port to make it harder for attackers to find.

Conclusion
By following these steps, you can easily install, optimize, and harden Memcached with WHM/cPanel on Almalinux 8. This will help improve the performance of your web applications while also ensuring that your server is secure from potential attacks.

Picture of admin

admin

Leave a Reply

Sign up for our Newsletter

Get the latest information on what is going on in the I.T. World.