In this guide we will learn how to install and configure Memcached in RHEL 8/9 based systems like Rocky Linux and Alma Linux 8/9.
Memcached is an open source, distributed memory object caching system. The system caches data and objects in memory to minimize the frequency with which an external database or API must be accessed. This alleviates database load and speeds up dynamic Web applications. It offers a mature, scalable, open-source solution for delivering sub-millisecond response times making it useful as a cache or session store. Memcached is a popular choice for powering real-time applications in Web, Mobile Apps, Gaming, Ad-Tech, and E-Commerce.
Unlike databases that store data on disk or SSDs, Memcached keeps its data in memory. By eliminating the need to access disks, in-memory key-value stores such as Memcached avoid seek time delays and can access data in microseconds. Memcached is also distributed, meaning that it is easy to scale out by adding new nodes. And since Memcached is multithreaded, you can easily scale up compute capacity. As a result of its speed and scalability as well as its simple design, efficient memory management, and API support for most popular languages Memcached is a popular choice for high-performance, large-scale caching use cases.
Related content:
Ensuring that the server is up to date
Before proceeding, it is always a good practice to ensure that the server packages are updated. Use this command to achieve that:
|
|
Let us also install common packages that we will need during our installation and configuration.
|
|
Installing Memcached
Memcached packages are available in the default Rocky Linux repositories. Install them using this command:
|
|
Confirm the installation of memcached
|
|
Start and enable memcached service
Once the service is installed, it will not be started by default. Use this command to start the service
|
|
Confirm that the service is started with this command:
|
|
The output above is a confirmation that Memcached is up and running.
To enable the service on boot
|
|
Enable Memcached on firewall
open port 11211 on the firewall to allow traffic from the client host.
|
|
To confirm that port 11211 is opened on the firewall, execute the command.
|
|
Configure memcached
The memcached config is located in this path /etc/sysconfig/memcached
. Use this command to open the file for editing.
|
|
This is the default memcached configuration.
|
|
By default, Memcached listens to port 11211
and is configured to listen only to the localhost
system as shown in the final line. To configure Memcached so that applications from the remote systems can connect to the server, you need to change the localhost address 127.0.0.1 to the address of the remote host or to listen on all interfaces.
To use the remote host, replace the localhost address with the remote client’s IP 10.70.5.214 as shown.
|
|
To listen on all network interfaces 0.0.0.0
instead of 127.0.0.1
. Change the OPTIONS
line to below.
|
|
Once done configuring, restart the memcached server to apply the changes:
|
|
Confirm the changes with this command
|
|
Wrapping up
That is it! In this guide, we learned how to install and configure Memcached server on a Rocky Linux 8 Server. You can now configure your applications to connect and use the Memcached instance.