Last update at :2024-01-19,Edit by888u
Memcached is a free, open source, high-performance in-memory key-value data store. Typically, it is used as a caching system to speed up applications by caching various objects in the results of database calls. In this article, we will document 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 libmemcachedAfter the installation is complete, enable and start the Memcached service by typing:
sudo systemctl enable memcached --nowThen we will verify whether it can take effect.
sudo systemctl status memcachedWe 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 memcached configuration file:
sudo nano /etc/sysconfig/memcachedIn 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 memcachedAfter 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 --reloadFinally, we need to connect to Memcached.
1. PHP
To use Memcached as a cache database for PHP applications such as WordPress, Drupal or Magento, you need to install the php-pecl-memcached extension:
sudo dnf install php-pecl-memcache2. Python
There are several Python libraries available for interacting with memcached. We can install your favorite libraries using pip:
pip install pymemcache pip install python-memcachedIn this way, we have successfully deployed memcached in CentOS8.
Recommended discounts/cost-effective packages for bricklayers
Warm reminder: If you have difficulty choosing, just choose the CN2 GIA-E plan in the middle. The quarterly payment is $49.99, and you can switch between up to 12 computer rooms at will.Banwagonhost discount code: BWH3HYATVBJW, discount 6.58%, available everywhere. The table below summarizes more preferential packages for bricklayer removal.
CN2 (cheapest) | 1GB | 1 core | 20GB | 1TB | 1Gbps | DC3 CN2 DC8 ZNET | $49.99/year | Buy |
CN2 | 2GB | 1 core | 40GB | 2TB | 1Gbps | $52.99/half year $99.99/year | Buy | |
CN2 GIA-E (Most recommended) | 1GB | 2 cores | 20GB | 1TB | 2.5Gbps | DC6 CN2 GIA-E DC9 CN2 GIA Japan SoftBank JPOS_1 China Unicom Netherlands EUNL_9 | $49.99/quarter $169.99/year | Buy |
CN2 GIA-E | 2GB | 3 core | 40GB | 2TB | 2.5Gbps | $89.99/quarter $299.99/year | Buy | |
HK | 2GB | 2 cores | 40GB | 0.5TB | 1Gbps | Hong Kong CN2 GIA | $89.99/month $899.99/year | Buy |
HK | 4GB | 4 core | 80GB | 1TB | 1Gbps | $155.99/month $1559.99/year | Buy |
Select a suggestion:
- Getting started: Los Angeles CN2 package, currently the cheapest, optional CN2 GT computer room, the entry-level choice.
- Recommendation: Los Angeles CN2 GIA-E package, affordable, super fast, with many optional computer rooms, and the most cost-effective.
- High-end: Hong Kong CN2 GIA package, the price is higher, but impeccable.
Recommended site search: US host, website registration system, network registration, registration-free CDN, Hong Kong vps, virtual host control panel, domain name registration website, Korean server recommendation, Hong Kong server rental, mobile agent IP,
发表评论