Memcached is a high-performance distributed memory object caching system for dynamic Web applications to mitigate database load. It provides a dynamic, database-driven site speed by caching data and objects in memory to reduce the number of times the database is read. Memcached is based on a hashmap that stores key/value pairs. Its daemon (daemon) is written in C, but the client can write in any language and communicate with the daemon through the memcached protocol. However, it does not provide redundancy (for example, copying its hashmap entries), and when a server S is stopped or crashed, all key/value pairs stored on s are lost.
To be simple, memcached is to maintain a large map in memory. It takes advantage of random access to RAM (the memory reads and writes faster than the disk reads and writes, the latter is 10 of the 6 times), and an object is stored through a specific index value, which can be found immediately when the object is needed. The index value is unique across the memory buffer system and corresponds to a unique object at the same time. This allows you to speed up access by adding such a mechanism to the operations that involve querying the data.
The following is a description of Memcached's compilation process in Linux x86_64 environments.
The parameters of the working machine are as follows:
Cpu:intel Xeon 5110
Memory: DDR2 1g*4
Host model: ProLiant DL140 G3
Operating system: Red Hat Enterprise Linux Server Release 5.4 version x86_64
Kernel version: 2.6.18
GCC version: 4.1.2
g++ version: 4.1.2
1. Download Memcached Source Package
Visit Memcached official website http://memcached.org can download to the latest and most stable version of memcached source package
Unzip the download when it is complete
[Plain]View Plaincopy print?
- [[EMAIL PROTECTED] ~]# CD DOWNLOAD  
- [[email protected] download]# ll
- TOTAL 312  
- - Rw-r--r-- 1 root root 311926 nov 20 16:51 memcached-1.4.10.tar.gz
- [[email protected] download]# tar -xf memcached-1.4.10.tar.gz
- [[email protected] download]# ll
- TOTAL 316  
- drwxr-xr-x 6 1000 1000 4096 nov 10 08:32 memcached-1.4.10
- -rw-r--r-- 1 root root 311926 nov 20 16:51 memcached-1.4.10.tar.gz
[[Email protected] ~]# CD Download[[email protected] download]# lltotal 312-rw-r--r--1 root root 311926 Nov 16:51 memc Ached-1.4.10.tar.gz[[email protected] download]# tar-xf memcached-1.4.10.tar.gz [[email protected] download]# lltotal 316drwxr-xr-x 6 4096 Nov 08:32 memcached-1.4.10-rw-r--r--1 root root 311926 Nov 16:51 memcached-1.4.1 0.tar.gz
2. Attempt to configure memcached compilation
After entering the memcached extracted directory, execute the./configure command to detect the current system environment and generate makefile
[Plain]View Plaincopy print?
- [Email protected] download]# CD memcached-1.4.10
- [Email protected] memcached-1.4.10]#./configure
If the last line is found after execution, the following hints indicate that the Libevent library is missing:
[Plain]View Plaincopy print?
- Checking for libevent directory ... configure:error:libevent is required. You can get it from http://www.monkey.org/~provos/libevent/
- If it ' s already installed, specify its path using--with-libevent=/dir/
- [Email protected] memcached-1.4.10]#
Checking for libevent directory ... configure:error:libevent is required. You can get it from http://www.monkey.org/~provos/libevent/
This is a common problem in compiling memcached (Memcached is based on the Libevent event handling mechanism. Libevent is a library that encapsulates event-handling functions such as Linux's Epoll, BSD-class operating system kqueue, and so on as a unified interface. The performance of Time complexity O (1) can be played even if the number of connections to the server increases. Memcached uses this libevent library, so it can perform its high performance on Linux, BSD, Solaris and other operating systems. )。 The Libevent library will be installed. The latest and most stable source code can be downloaded from the Libevent official website http://libevent.org:
Also need to unzip and into the extracted source package directory:
[Plain]View Plaincopy print?
- [[EMAIL PROTECTED] DOWNLOAD]# LL  
- total 1140
- -rw-r--r-- 1 root root 837650 nov 20 17:16 libevent-2.0.16-stable.tar.gz
- drwxr-xr-x 6 1000 1000 4096 nov 20 17:03 memcached-1.4.10
- -rw-r--r-- 1 root root 311926 nov 20 16:51 memcached-1.4.10.tar.gz
- [[Email protected] download]# tar -xf libevent-2.0.16-stable.tar.gz
Li class= "alt" >[[EMAIL PROTECTED] DOWNLOAD]# CD LIBEVENT-2.0.16-STABLE  
[Email protected] download]# lltotal 1140-rw-r--r--1 root root 837650 Nov 17:16 LIBEVENT-2.0.16-STABLE.TAR.GZDRWXR-XR -X 6 4096 Nov 17:03 memcached-1.4.10-rw-r--r--1 root root 311926 Nov 16:51 memcached-1.4.10.tar.gz[[e Mail protected] download]# tar-xf libevent-2.0.16-stable.tar.gz [[email protected] download]# CD libevent-2.0.16-stable
The next step is to configure the compilation of the Libevent library. Here the configuration needs to be aware of the addition of the--prefix parameter, this parameter to specify when the compilation is completed, if you install this library, where to install the library. The default value is/usr/local. If you leave the default value, the library is installed in the/usr/local/lib directory. The default load library path for most Linux distributions does not contain this path. To avoid trouble, specify--PREFIX=/USR here. This compiles the installation to the/usr/lib directory. This directory is the default load library path for most Linux distributions.
To execute a configuration script:
[Plain]View Plaincopy print?
- [Email protected] libevent-2.0.16-stable]#/configure--PREFIX=/USR
[Email protected] libevent-2.0.16-stable]#/configure--PREFIX=/USR
If you forget to add this parameter when you configure it, it doesn't matter, there is a workaround behind it, then look down.
The configuration is ready to compile:
[Plain]View Plaincopy print?
- [[email protected] libevent-2.0.16-stable]# make
[[email protected] libevent-2.0.16-stable]# make
After compiling it, it is installed with root privileges:
[Plain]View Plaincopy print?
- [[email protected] libevent-2.0.16-stable]# sudo make install
[[email protected] libevent-2.0.16-stable]# sudo make install
3. Formally compiled memcached
Just introduced is encountered a small trouble when the solution, now there is no libevent library missing problem, if you encounter the Libevent library missing problem, at this time need to go back to the memcached source package directory, once again to execute the compilation configuration script:
[Plain]View Plaincopy print?
- [Email protected] memcached-1.4.10]#./configure
[Email protected] memcached-1.4.10]#./configure
Do not add parameters directly to the compile configuration script, which will be installed automatically to the/usr/local/bin directory at the time of installation. If you want to change the installation location, you can add the parameter--prefix. For example--prefix=/usr/local/memcached, installation will be installed into/usr/local/memcached/bin.
Check no problem, you can start compiling:
[Plain]View Plaincopy print?
- [[email protected] memcached-1.4.10]# make
[[email protected] memcached-1.4.10]# make
Install after compilation is complete
[Plain]View Plaincopy print?
- [[email protected] memcached-1.4.10]# sudo make install
[[email protected] memcached-1.4.10]# sudo make install
Then go and see if it's installed (memcached default installation directory is/usr/local/bin). Go to the memcached directory and start the memcached plus parameter-h display Help. Help the first line is the current memcached version:
[Plain]View Plaincopy print?
- [Email protected] memcached-1.4.10]# cd/usr/local/bin/
- [[email protected] bin]# sudo./memcached-h
- ./memcached:error while loading shared libraries:libevent-2.0.so.5:cannot open Shared object file:no such file or dire Ctory
- [Email protected] bin]#
If the previous libevent compiled with the--PREFIX=/USR parameter, the execution should be normal and the help message will be displayed. I did not add this parameter intentionally when I compiled the Libevent library, so memcached to this point there will be a problem-the shared library libevent-2.0.so.5 cannot be loaded. If you are experiencing this problem, look down:
In most Linux distributions, the default lookup path for statically loaded libraries after program startup is/lib (64-bit system with/lib64) and/usr/lib (and/usr/lib64 in 64-bit systems). The Libevent library installation path We compiled now is not in these default library load paths, so we need to configure the library load path:
Take a look at the LDD command first to see which libraries memcached need to load:
[Plain]View Plaincopy print?
- [[EMAIL PROTECTED] BIN]# LDD MEMCACHED   
- libevent-2.0.so.5 => not found
- librt.so.1 => /lib64/ librt.so.1 (0x0000003714400000)
- libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003712800000)
- libc.so.6 => /lib64/libc.so.6 (0x0000003711c00000)
- /lib64/ ld-linux-x86-64.so.2 (0x0000003711800000)
- [[email protected] bin]#
[Email protected] bin]# ldd memcached libevent-2.0.so.5 = not found librt.so.1 =/lib64/librt.so.1 ( 0x0000003714400000) libpthread.so.0 =/lib64/libpthread.so.0 (0x0000003712800000) libc.so.6 =/ Lib64/libc.so.6 (0x0000003711c00000)
You see the result first line: Libevent-2.0.so.5 = not found, which is the missing library that the library cannot find.
So where is this library? Let's ask the system:
[Plain]View Plaincopy print?
- [Email protected] bin]# Whereis libevent-2.0.so.5
- Libevent-2.0.so:/usr/local/lib/libevent-2.0.so.5
- [Email protected] bin]#
It tells us that the libevent-2.0.so.5 inventory is placed in the/usr/local/lib directory. So we add this directory to the system's default library load path. This is to modify the system environment variable $ld_library_path.
First look at the value of the current $ld_library_path:
[Plain]View Plaincopy print?
- [Email protected] bin]# echo $LD _library_path
- [Email protected] bin]#
The current value is empty, indicating whether the current library load path is the/lib mentioned above (64-bit systems also have/lib64) and/usr/lib (there are also/usr/lib64 in 64-bit systems). Next, use root permissions to modify the/etc/profile file to append a line to the end of the file:
[Plain]View Plaincopy print?
- Export Ld_library_path=/usr/local/lib: $LD _library_path
Export Ld_library_path=/usr/local/lib: $LD _library_path
Then save and update the system configuration:
[Plain]View Plaincopy print?
- [Email protected] bin]# Source/etc/profile
[Email protected] bin]# Source/etc/profile
Check the default load library path again:
[Plain]View Plaincopy print?
- [Email protected] ~]# cd/etc/
- [[email protected] etc]# Source profile
- [Email protected] etc]# echo $LD _library_path
- /usr/local/lib:
- [Email protected] etc]#
The directory where the Libevent library is located has been added to the system default library load path, and once again use the LDD command to see if memcached can fully load the required libraries:
[Plain]View Plaincopy print?
- [Email protected] etc]# cd/usr/local/bin/
- [[email protected] bin]# ls
- Dialyzer erl escript memcached run_test typer
- EPMD ERLC event_rpcgen.py Run_erl To_erl
- [Email protected] bin]# LDD memcached
- libevent-2.0.so.5 =/usr/local/lib/libevent-2.0.so.5 (0x00002b52aedd1000)
- Librt.so.1 =/lib64/librt.so.1 (0x0000003714400000)
- libpthread.so.0 =/lib64/libpthread.so.0 (0x0000003712800000)
- libc.so.6 =/lib64/libc.so.6 (0x0000003711c00000)
- /lib64/ld-linux-x86-64.so.2 (0x0000003711800000)
- [Email protected] bin]#
[[email protected] etc]# cd/usr/local/bin/[[email protected] bin]# lsdialyzer erl escript memcached Run_test typerepmd erlc event_rpcgen.py run_erl to_erl[[email protected] bin]# ldd memcached libevent-2.0.so.5 =/usr/local/lib/libevent-2.0.so.5 (0x00002b52aedd1000) librt.so.1 =/lib64/ Librt.so.1 (0x0000003714400000) libpthread.so.0 =/lib64/libpthread.so.0 (0x0000003712800000) libc.so.6 =/lib64/libc.so.6 (0x0000003711c00000)
You can find it already, look at the version information:
[Plain]View Plaincopy print?
- [Email protected] bin]#./memcached-h
- Memcached 1.4.10
- -P <num> TCP port number to listen on (default:11211)
- -U <num> UDP port number to listen on (default:11211, 0 is off)
[[email protected] bin]#./memcached-hmemcached 1.4.10-p <num> TCP port number to listen on (default:11211)-U <num> UDP Port number to listen on (default:11211, 0 is off)
There's no problem anymore.
This completes the compilation installation of memcached.
Recently I would like to write some configuration articles about memcached, please pay attention!
Resources:
Compile and install memcached on CentOS 5.6, http://whxhz.iteye.com/blog/1117118
Error while loading shared libraries:libevent-2.0.so.5 solution, http://blog.sina.com.cn/s/blog_6d09b5750100vqow.html
Compiling memcached in Linux x86_64 environment