How to deploy Memcached caching tool on CentOS 8 system image?

888u

Last update at :2024-05-13,Edit by888u

Memcached is a high-performance distributed memory object caching system used in dynamic web applications to reduce database load. It improves the speed of dynamic, database-driven websites by caching data and objects in memory to reduce the number of reads to the database. It was developed by Brad Fitzpatrick of LiveJournal but is used by many websites. This is a set of open source software, released under the BSD license. This article will record the tutorial on how to install and configure Memcached on CentOS 8.

The Memcached package is included in the default CentOS 8 repository. Installation is very simple, enter the following command as root or a user with sudo privileges:

sudo dnf install memcached libmemcached

After the installation is complete, enable and start the Memcached service by typing:

sudo systemctl enable memcached --now

Then we will verify whether it can take effect.

sudo systemctl status memcached

We see the following output content indicating that it has been installed.

● memcached.service - memcached daemon
Loaded: loaded (/usr/lib/systemd/system/memcached.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2020-04-13 20:12:52 UTC; 2s ago
...

That's it, we have Memcached installed on your CentOS 8 server and now we can start using it. Then we will start configuring Memcached.

Memcached options can be configured in the /etc/sysconfig/memcached file. By default, Memcached is set up to only listen on localhost. If the client connecting to the server is also running on the same host, no changes should be made.

If the application that connects to Memcached is hosted on a remote server, you need to configure the firewall and only allow access to Memcached port 11211 from the client IP address.

If configured improperly, Memcached can be used to perform distributed denial-of-service (DDoS) attacks. This is our common problem of port 11211 being attacked. There was a security issue before that caused many people to suffer.

The following example assumes we need to connect to the Memcached server over a private network. The Memcached server IP is 192.168.100.20 and the client IP address is 192.168.100.30.

As a first step, we need to edit the Memcached configuration and set the service to listen on the server's private network interface:

Open the memcached configuration file:

sudo nano /etc/sysconfig/memcached

In the OPTIONS parameter, add the server IP address -l 192.168.100.20. This instructs Memcached to bind only to the specified interface.

OPTIONS="-l 192.168.100.20"

Save the file and restart the Memcached service for the changes to take effect.

sudo systemctl restart memcached

After configuring the service, the next step is to open the memcached port in the firewall.

CentOS comes with its own firewall configuration tool FirewallD. The following command will create a new zone called memcached, open port 11211 and allow access only from client IP addresses.

sudo firewall-cmd --new-zone=memcached --permanent
sudo firewall-cmd --zone=memcached --add-port=11211/udp --permanent
sudo firewall-cmd --zone=memcached --add-port=11211/tcp --permanent
sudo firewall-cmd --zone=memcached --add-source=192.168.100.30/32 --permanent
sudo firewall-cmd --reload

Finally, we need to connect to Memcached.

1. PHP

To use Memcached as a caching database for PHP applications such as WordPress, Drupal or Magento, you need to install the php-pecl-memcached extension:

sudo dnf install php-pecl-memcache

2. Python

There are several Python libraries available for interacting with memcached. We can use pip to install your favorite libraries:

pip install pymemcache
pip install python-memcached

In this way, we have successfully deployed memcached in CentOS8.

Recommended site search: cloud server rental, Hong Kong server rental 99idc, free domain name space, Hong Kong server purchase, public network IP, space website, domain name space purchase, PHP space rental, overseas server rental price, mainland China bgp cloud host ,

How to deploy Memcached caching tool on CentOS 8 system image?

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码