Memcached 1.5.12 Porting Guide (openEuler 20.03 LTS SP1)
Introduction
Overview
Memcached is a high-performance, distributed memory object caching server, developed by Brad Fitzpatric from Danga Interactive, a subsidiary of LiveJournal. It is used to cache database query results and reduce database access times to improve the speed and scalability of dynamic web applications.
Official Memcached website: https://memcached.org/
Programming language: C
Brief description: distributed memory object caching system
Environmental Requirements
Hardware
The following table lists the hardware requirements.
Item | Description |
---|---|
Server | TaiShan 200 server (model 2280) |
CPU | Kunpeng 920 5250 processor |
Drive partition | No requirements |
Operating Systems
The following table lists the requirements for the operating system.
Item | Version |
---|---|
openEuler | 20.03 LTS SP1 AArch64 |
Kernel | 4.19 |
Check the current OS version.
cat /etc/os-release
For details about installing the openEuler OS, see https://docs.openeuler.org/en/docs/20.03_LTS_SP1/docs/Installation/Installation.html.
Note: You are advised to select the "Server with GUI" installation mode.
Configuring the Compilation Environment
To compile Memcached, you need to prepare the C compiler, GNU, make, automake, libevent, and libevent-devel.
Install the GNU Compiler Collection (GCC). If GCC has been installed, skip this step.
bashyum -y install gcc gcc-c++ kernel-devel
Install GNU make, Automake, unzip, and Telnet. If they have been installed, skip this step.
bashyum -y install make automake unzip telnet
Install libevent and libevent-devel.
bashyum -y install libevent libevent-devel
Obtaining Source Code
If your server can access the network, run the "wget https://github.com/memcached/memcached/archive/1.5.12.zip" command to download the source code. Otherwise, visit https://github.com/memcached/memcached/archive/1.5.12.zip to download the source code and copy it to the /home directory on the server.
Compiling and Installing Memcached
The following uses the source code downloaded to the local PC and then uploaded to the server as an example for describing compilation and installation operations.
Decompress the source package.
bashcd /home
bashunzip 1.5.12.zip
Go to the memcached-1.5.12 directory.
bashcd memcached-1.5.12
Configure Memcached.
bashsh autogen.sh
bash./configure --prefix=/opt/memcached
You can specify the Memcached installation directory, for example, /opt/memcached, in this step.
Perform compilation.
bashmake -j60
-j60 leverages the multi-core CPUs to speed up compilation.
Perform installation.
bashmake install
Switch to the Memcached installation directory /opt/memcached. If the generated bin directory contains the Memcached executable file, installation is successful.
Set environment variables.
a. Add the following command to the /etc/profile file:
bashexport PATH=/opt/memcached/bin/:$PATH
b. Make the environment variable effective.
bashsource /etc/profile
Running and Verifying Memcached
Start Memcached.
bashmemcached -t 24 -p 11211 -u root -m 49152 -c 10240
The following table describes the parameters in the startup command.
Parameter | Description | Default Value |
---|---|---|
-t | Thread count | 4 |
-p | TCP listening port | 11211 |
-u | User who starts the process | The default user cannot be root. |
-m | Memory size (in MB) allocated to Memcached | 64M |
-c | Maximum number of concurrent connections | 1024 |
-d | Starts a daemon in the background. | - |
Start another shell window to connect to Memcached.
bashtelnet 127.0.0.1 11211
After creating a connection, run the stats command to obtain the statistics of the Memcached server.
bashstats
The following table lists the common stats commands.
Command | Description |
---|---|
stats | Displays the overall status of Memcached, including the startup time, amount of data stored, cache hit ratio, and number of current connections. |
stats items | Outputs the item information of each slab. |
stats slabs | Outputs more details about slabs. |
stats sizes | Displays the size and number of all items. |
stats cachedump | Outputs certain pieces of data in a slab. If the input is 0, all data in the slab is output. |
stats detail | Sets (on/off) or displays (dump) detailed operation records, such as the get/set operation. |
flush_all | Invalidates all items in the memory. This operation does not suspend the server because no free memory is released and the existing items are marked as invalid. |
Note: To exit the Telnet connection, run the quit command.
quit
In addition to connecting to the Memcached service using Telnet to obtain data, the source code provides some tool scripts, such as memcached-tool, in the scripts directory of the source code.
For details about how to use the memcached-tool, see the following table.
Command | Description |
---|---|
./memcached-tool localhost display | Displays slabs information. |
./memcached-tool 10.0.0.5:11211 display | Displays slabs information. |
./memcached-tool 10.0.0.5:11211 stats | Displays memcached statistics. |
./memcached-tool 10.0.0.5:11211 settings | Displays memcached settings. |
./memcached-tool 10.0.0.5:11211 sizes | Displays the size and number of all items. |
./memcached-tool 10.0.0.5:11211 dump [limit] | Outputs keys and values from the cache. |