
Memcached is a high-performance, open-source, distributed memory object caching system. It is often used for speeding up dynamic web applications by storing frequently requested data from the results of database calls and application requests. It is an excellent solution for reducing database load and serving as a placeholder for requests that cannot be served from the database. It provides different ways to store data, such as key-value pairs or sorted sets.
This guide will install Memcached from source code and secure it on a Ubuntu 20.04 server.
You need to install some tools to compile the Memcached source package.
The option --no-install-recommends is used to install mentioned package only.
The other package descriptions are below:
gcc is a well-known C compiler for the Memcached source files. make is used for directing compilation libc6-dev is used for reference of GNU C library and header files libevent-dev is a well-known development file for asynchronous event notificationAll Memcached dependencies are installed to download the Memcached source package and install it into the system.
Download the latest Memcached source file.
Extract the archive contents.
Change the working directory to the extracted files. The directory name might be different if you downloaded a newer version.
Use the --prefix= parameter to set the directory to install the Memcached binary and libraries. For this example, use the /usr/local directory.
Compile the Memcached source code with make.
Test Memcached by confirming the current version.
Install Memcached.
Test if Memcached is active and running on TCP port 11211.
After successful installation, you can manage the Memcached service with systemctl.
To start Memcached service:
To check the status of Memcached:
To stop Memcached:
By default, Memcached runs on the local interface with a TCP port. To restrict potential attacks, block incoming UDP connections on the Memcached port 11211 through your firewall.
You can also restrict Memcached to the local interface through the configuration file.
Open the Memcached configuration file with your favorite editor.
Find the following line in the file, and uncomment if commented.
If you want to restrict UDP also, add the following line at the end of the file.
Save and exit the file.
Restart the service.
Use netstat to verify Memcached is bound to the local interface and only listening to TCP connections.
You can use these other options in /etc/memcached.conf.
You can verify the Memcached setup with memcstat from the libmemcached-tools package.
You will get the output like:
There are several Memcached clients for different programming languages.
If you want to use Memcached as a caching database for your PHP applications such as WordPress, Magento, Joomla, or Drupal, you should use the Memcached extension, which you can install with:
Use pip to install Python libraries.
See the official website for more information.
0 Comments
Be the first to comment and share your perspective with the community.