In this guide we will learn how to install and configure Memcached in RHEL 8 based systems like Rocky Linux and Alma Linux 8.
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.
Table of Content
- Ensuring that the server is up to date
- Installing Memcached
- Start and enable memcached service
- Enable Memcached on firewall
- Configure memcached
1. 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:
sudo dnf -y update
Let us also install common packages that we will need during our installation and configuration.
sudo dnf install -y vim
2. Installing Memcached
Memcached packages are available in the default Rocky Linux repositories. Install them using this command:
sudo dnf install -y memcached
Confirm the installation of memcached
$ rpm -qi memcached Name : memcached Epoch : 0 Version : 1.5.22 Release : 2.el8 Architecture: x86_64 Install Date: Sun 09 Jan 2022 03:52:09 PM UTC Group : System Environment/Daemons Size : 414743 License : BSD Signature : RSA/SHA256, Mon 12 Apr 2021 07:04:12 AM UTC, Key ID 15af5dac6d745a60 Source RPM : memcached-1.5.22-2.el8.src.rpm Build Date : Mon 12 Apr 2021 04:45:42 AM UTC Build Host : ord1-prod-x86build003.svc.aws.rockylinux.org Relocations : (not relocatable) Packager : [email protected] Vendor : Rocky URL : https://www.memcached.org/ Summary : High Performance, Distributed Memory Object Cache Description : memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.
3. Start and enable memcached service
Once the service is installed, it will not be started by default. Use this command to start the service
sudo systemctl start memcached
Confirm that the service is started with this command:
$ sudo systemctl status memcached ● memcached.service - memcached daemon Loaded: loaded (/usr/lib/systemd/system/memcached.service; disabled; vendor preset: disabled) Active: active (running) since Mon 2022-01-10 02:59:15 UTC; 1min 32s ago Main PID: 54961 (memcached) Tasks: 10 (limit: 23176) Memory: 1.7M CGroup: /system.slice/memcached.service └─54961 /usr/bin/memcached -p 11211 -u memcached -m 64 -c 1024 -l 127.0.0.1,::1 Jan 10 02:59:15 rockysrv.citizix.com systemd: Started memcached daemon.
The output above is a confirmation that Memcached is up and running.
To enable the service on boot
sudo systemctl enable memcached
4. Enable Memcached on firewall
open port 11211 on the firewall to allow traffic from the client host.
$ sudo firewall-cmd --add-port=11211/tcp --zone=public --permanent $ sudo firewall-cmd --reload
To confirm that port 11211 is opened on the firewall, execute the command.
$ sudo firewall-cmd --list-ports | grep 11211
5. Configure memcached
The memcached config is located in this path
/etc/sysconfig/memcached. Use this command to open the file for editing.
sudo vim /etc/sysconfig/memcached
This is the default memcached configuration.
PORT="11211" USER="memcached" MAXCONN="1024" CACHESIZE="64" OPTIONS="-l 127.0.0.1,::1"
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:
sudo systemctl restart memcached
Confirm the changes with this command
$ sudo ss -tulpn | grep 11211 tcp LISTEN 0 128 10.70.5.214:11211 0.0.0.0:* users:(("memcached",pid=55522,fd=28)) tcp LISTEN 0 128 [::1]:11211 [::]:* users:(("memcached",pid=55522,fd=29))
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.
Pingback: How to Install and Configure Memcached on OpenSUSE Leap 15.3
Pingback: How to Install and Configure Memcached on Ubuntu 20.04
Pingback: How to Install and Configure Memcached on Debian 11 – Citizix