Last update at :2024-02-01,Edit by888u
Memcached is a high-performance, open source distributed in-memory object caching system that is commonly used to accelerate dynamic web applications by storing frequently requested data from database calls and application request results. Memcached is an excellent solution that reduces database load and acts 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. The acceleration effect of Memcached is quite obvious. We have been using it on our website and the effect is obvious.
In fact, Memcached can be installed directly on the Pagoda panel, which is very simple, convenient and fast. However, we can also choose to install it manually, compile and install it from the source code, and we may feel a sense of accomplishment.
1. Install dependencies
You need to install some tools to compile the Memcached source package.
$ sudo apt-get install gcc make libevent-dev libc6-dev --no-install-recommendsThe option –no-install-recommends is used to install only the mentioned packages.
Other package descriptions are as follows:
- gcc is a well-known C compiler for Memcached source files.
- make is used to guide compilation
- libc6-dev is used to reference the GNU C library and header files
- libevent-dev is a well-known asynchronous event notification development file
Install all Memcached dependencies to download the Memcached source package and install it into your system.
2. Download and compile Memcached
Download the latest Memcached files:
$ wget https://memcached.org/latestUnzip the installation package:
$ tar -xvf latestChange the working directory to the extracted files. If you downloaded a newer version, the directory name may be different.
$ cd Memcached-1.6.12/Use the –prefix= parameter to set the directory where Memcached binaries and libraries are installed. For example, the following example uses the /usr/local directory.
$ ./configure --prefix=/usr/local/memcachedCompile Memcached source code:
$ makeConfirm Memcached version number:
$ ./memcached --versionInstall Memcached:
$ sudo make installTests that Memcached is active and running on TCP port 11211.
$ netstat -tulpn | grep :112113. Memcached service management tutorial
After successfully installing Memcached, you can use the systemctl command to manage the Memcached service.
Start the Memcached service:
sudo systemctl start memcachedCheck the status of Memcached:
sudo systemctl status memcachedTo stop Memcached:
sudo systemctl stop memcached4. Memcached security settings tutorial
By default, Memcached runs on the local interface with a TCP port. To limit potential attacks, block incoming UDP connections on Memcached port 11211 through your firewall.
$ sudo ufw deny 11211/udp5. Configure Memcached
You can also restrict Memcached to the local interface via a configuration file. Open the Memcached configuration file using your favorite editor.
sudo vi /etc/memcached.confFind the following lines in the file and uncomment them if there are any.
-l 127.0.0.1If you also want to limit UDP, add the following lines at the end of the file.
-U 0Save the file and restart the service:
sudo systemctl restart memcachedUse netstat to verify that Memcached is bound to the local interface and is only listening for TCP connections.
sudo netstat -plunt6. Verify Memcached settings
You can verify Memcached settings using memcstat from the libmemcached-tools package.
memcstat --servers="localhost"You will get output similar to:
Server: localhost (11211) pid: 3927 uptime: 2217682 time: 1547170226 version: 1.4.25 libevent: 2.0.21-stable pointer_size: 64 rusage_user: 75.436000 rusage_system: 57.768000 curr_connections: 1 total_connections: 53082 ...7. Example of connecting to Memcached
PHP
If you want to use Memcached as a cache database for your PHP applications (such as WordPress, Magento, Joomla or Drupal), you should use the Memcached extension, which you can install:
sudo apt install php-memcachedPython
pip install pymemcache pip install python-memcachedAt this point, you can successfully install and use Memcached to accelerate the website.
Recommended plan 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.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 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, China CN2 GIA | $89.99/month $899.99/year | Buy |
HK | 4GB | 4 core | 80GB | 1TB | 1Gbps | $155.99/month $1559.99/year | Buy | |
TOKYO | 2GB | 2 cores | 40GB | 0.5TB | 1.2Gbps | Tokyo, Japan CN2 GIA | $89.99/month $899.99/year | Buy |
TOKYO | 4GB | 4 core | 80GB | 1TB | 1.2Gbps | $155.99/month $1559.99/year | Buy | |
Recommended site search: domain name query, personal domain name registration, Hong Kong virtual host space, download virtual host, registered international domain name IP address detailed query, Hong Kong's best virtual host, Alibaba Cloud free virtual host, domain name registration website, cheap domain name registration ,
发表评论