Compiling memcached in Linux x86_64 environment

Source: Internet
Author: User

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?
    1. [[EMAIL PROTECTED] ~]# CD DOWNLOAD  
    2. [[email  protected] download]# ll  
    3. TOTAL 312  
    4. - Rw-r--r-- 1 root root 311926 nov 20 16:51 memcached-1.4.10.tar.gz   
    5. [[email protected] download]# tar -xf  memcached-1.4.10.tar.gz   
    6. [[email protected] download]# ll  
    7. TOTAL 316  
    8. drwxr-xr-x 6 1000 1000    4096 nov 10 08:32 memcached-1.4.10  
    9. -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?
    1. [Email protected] download]# CD memcached-1.4.10
    2. [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?
    1. Checking for libevent directory ... configure:error:libevent is required. You can get it from http://www.monkey.org/~provos/libevent/
    2. If it ' s already installed, specify its path using--with-libevent=/dir/
    3. [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?
    1. [[EMAIL PROTECTED] DOWNLOAD]# LL  
    2. total 1140   
    3. -rw-r--r-- 1 root root 837650 nov 20 17:16  libevent-2.0.16-stable.tar.gz  
    4. drwxr-xr-x 6 1000 1000   4096  nov 20 17:03 memcached-1.4.10  
    5. -rw-r--r-- 1 root  root 311926 nov 20 16:51 memcached-1.4.10.tar.gz  
    6. [[Email  protected] download]# tar -xf libevent-2.0.16-stable.tar.gz   
    7. 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?
    1. [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?
    1. [[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?
    1. [[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?
    1. [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?
    1. [[email protected] memcached-1.4.10]# make
[[email protected] memcached-1.4.10]# make

Install after compilation is complete

[Plain]View Plaincopy print?
    1. [[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?
    1. [Email protected] memcached-1.4.10]# cd/usr/local/bin/
    2. [[email protected] bin]# sudo./memcached-h
    3. ./memcached:error while loading shared libraries:libevent-2.0.so.5:cannot open Shared object file:no such file or dire Ctory
    4. [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?
    1. [[EMAIL PROTECTED] BIN]# LDD MEMCACHED   
    2.         libevent-2.0.so.5 => not found  
    3.         librt.so.1 => /lib64/ librt.so.1  (0x0000003714400000)   
    4.          libpthread.so.0 => /lib64/libpthread.so.0  (0x0000003712800000)   
    5.         libc.so.6 => /lib64/libc.so.6   (0x0000003711c00000)   
    6.         /lib64/ ld-linux-x86-64.so.2  (0x0000003711800000)   
    7. [[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?
    1. [Email protected] bin]# Whereis libevent-2.0.so.5
    2. Libevent-2.0.so:/usr/local/lib/libevent-2.0.so.5
    3. [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?
    1. [Email protected] bin]# echo $LD _library_path
    2. [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?
    1. 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?
    1. [Email protected] bin]# Source/etc/profile
[Email protected] bin]# Source/etc/profile

Check the default load library path again:

[Plain]View Plaincopy print?
    1. [Email protected] ~]# cd/etc/
    2. [[email protected] etc]# Source profile
    3. [Email protected] etc]# echo $LD _library_path
    4. /usr/local/lib:
    5. [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?
  1. [Email protected] etc]# cd/usr/local/bin/
  2. [[email protected] bin]# ls
  3. Dialyzer erl escript memcached run_test typer
  4. EPMD ERLC event_rpcgen.py Run_erl To_erl
  5. [Email protected] bin]# LDD memcached
  6. libevent-2.0.so.5 =/usr/local/lib/libevent-2.0.so.5 (0x00002b52aedd1000)
  7. Librt.so.1 =/lib64/librt.so.1 (0x0000003714400000)
  8. libpthread.so.0 =/lib64/libpthread.so.0 (0x0000003712800000)
  9. libc.so.6 =/lib64/libc.so.6 (0x0000003711c00000)
  10. /lib64/ld-linux-x86-64.so.2 (0x0000003711800000)
  11. [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?
    1. [Email protected] bin]#./memcached-h
    2. Memcached 1.4.10
    3. -P <num> TCP port number to listen on (default:11211)
    4. -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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.