Install and configure and start memcached under Linux

Source: Internet
Author: User
Tags gz file memcached

    A. Download File :

Download memcached and libevent, and put it in the/hom/zwl/directory

    # wget http://www.danga.com/memcached/dist/memcached-1.2.0.tar.gz

# wget http://www.monkey.org/~provos/libevent-1.2.tar.gz

Since memcached needs lievent support, so, first of all, libevent to do a simple introduction:

      Libevent is a lightweight, open-source, high-performance network library

Of course the first compliment, Libevent has a few notable highlights:

Event-driven (Event-driven), high performance;
Lightweight, focus on the network, as the ACE is so bloated and huge;

The source code is quite refined and easy to read;
Cross-platform support for Windows, Linux, *bsd and Mac Os;
Support for multiple I/O multiplexing Technologies, Epoll, poll, Dev/poll, select, and Kqueue;
Supports events such as I/O, timers and signals;
Register event priority; Libevent has been widely used as the underlying network library, such as memcached, vomit, Nylon, netchat, and so on.

Well, the concept is not much to say, start the installation.

1). Install Libevent

1. Unzip the libevent-1.2.tar.gz file

   Tar zxvf libevent-1.2.tar.gz

CD libevent-1.2

2. Configure the installation directory

   ./configure-prefix=/home/zwl/memcached/libevent

    

3. Execute make and make install

    

4. Check: Ls-al /home/zwl/memcached/libevent/bin |grep libevent, if the following information appears, the installation is successful

lrwxrwxrwx 1 root root Oct 11:27 libevent-1.2.so.1-libevent-1.2.so.1.0.3
-rwxr-xr-x 1 root root 264104 Oct 11:27 libevent-1.2.so.1.0.3
-rw-r--r--1 root root 430428 Oct 11:27 libevent.a
-rwxr-xr-x 1 root root 805 Oct 11:27 libevent.la
lrwxrwxrwx 1 root root Oct 11:27 libevent.so-libevent-1.2.so.1.0.3

    

  

2). Install memcached, and you need to install the installation location of the specified libevent:

    1. Unzip the memcached-1.2.0.tar.gz file

Tar zxvf memcached-1.2.0.tar.gz

CD memcached-1.2.0

2. Specify the libevent location and specify the memcached installation location

    ./configure–with-libevent=/home/zwl/memcached/libevent-prefix=/home/zwl/memcached/memcached

3.make,make Install

  

4. Check, execute the following command: ls-al/home/zwl/memcached/memcached/bin/mem*

If the following effect occurs, the installation succeeds!!!

-rwxr-xr-x 1 root root 113236 Oct 11:29/home/zwl/memcached/memcached/bin/memcached
-rwxr-xr-x 1 root root 117583 Oct 11:29/home/zwl/memcached/memcached/bin/memcached-debug

    5. Start memcached and execute the following command

    # memcached-d-M 3072-u root-l 211.155.81.178-p 11211-c 4096-p/data/memcacheddamaokeji/memcached.pid /c8>

The-D option is to start a daemon,
-M is the amount of memory allocated to Memcache, in megabytes, 10MB,
-U is the user running memcache, this is root,
-L is the server IP address of the listener, if there are multiple addresses, this specifies the IP address of the server 192.168.0.200,
-P is the port that sets Memcache listening, which is set to 12000, preferably more than 1024 ports,
The-c option is the maximum number of concurrent connections to run, the default is 1024, which is set at 256, according to the load of your server to set,
-P is set to save memcache PID file, here is saved in/tmp/memcached.pid,
2. If you want to end the memcache process, execute:
# Kill ' Cat/tmp/memcached.pid '
You can also start multiple daemons, but the ports cannot be duplicated.
Restart Apache,service httpd Restart

  

    If you encounter problems when starting, don't be nervous, calm down !

    ./bin/memcached:error while loading shared libraries:libevent- 1.4.so. 2:cannot Open Shared object file:no such file or directory

    There are generally two reasons, one is that the operating system does not contain the shared library (lib*.so.* file) or the shared library version is not correct, in this case, go to the Internet download and install it.

    Another reason is that you have installed the shared library, but when you execute a program that calls the shared library, the program cannot find the shared library file by default shared library path.

    because I have installed the libevent, it should be the program follow the default shared path library to find, but did not find the cause.

First find out where the libevent-1.4.so.2 file is using the Find command

find/usr/-name libevent-1.4.so.2

/usr/lib64/libevent-1.4.so.2--The above command executes the result

Use the Debug Info Viewer to find a shared vault

   Ld_debug=libs/home/zwl/memcached/memcached/bin/memcached-v

    Which/home/zwl/memcached/memcached/bin/memcached: On behalf of my memcached procedure

The console output results are as follows:

  1. [Email protected] memcached]# ld_debug=libs /home/zwl/memcached/memcached/bin/memcached-v

    6513:search Cache=/etc/ld.so.cache

        6513:trying file=/lib/tls/i686/sse2/libevent-1.4.so. 2

        6513:trying file=/lib/tls/i686/libevent-1.4.so. 2

        6513:trying file=/lib/tls/sse2/libevent1.4.so. 2

    **********

    **********

    /home/zwl/memcached/memcached/bin/memcached:error while loading shared libraries:libevent-1.4.so. 2:cannot open Shared object file:no such file or directory

According to the debug log you can see that the program will only go down to/lib and/usr/lib to find the shared link library.

And my libevent is installed under the/home/zwl/memcached/libevent/lib/, so the memcache when the boot did not know to go to the bottom to find, so will error

Therefore, after installing the shared library, you should pay attention to the shared library path setting problem as follows:

    1) If the shared library file is installed in the/lib or/usr/lib directory, then you need to execute the ldconfig command

      The purpose of the Ldconfig command is to search for a shareable dynamic-link library (in the form of lib*.so*) in the default search directory (/lib and/usr/lib) and the directory listed in the dynamic library configuration file/etc/ld.so.conf, creating a dynamic Loader program ( ld.so) The required connection and cache files. The cache file defaults to/etc/ld.so.cache, which holds a list of queued dynamic-link library names.

2) If the shared library file is installed in/usr/local/lib (many open source shared libraries will be installed in this directory) or in other "non-/lib or/usr/lib" directories, before executing the ldconfig command, Also add the new shared library directory to the shared library configuration file/etc/ld.so.conf, as follows:

[Email protected] memcached]# cat/etc/ld.so.conf

Include ld.so.conf.d/*.conf

As shown above: The contents of the/etc/ld.so.conf configuration file are only one row,

Ld.so.conf.d/*.conf means a file containing a suffix of. conf under the ld.so.conf.d/directory

So we can create a new libevent.conf configuration file in the/ETC/LD.SO.CONF.D directory and configure the Libevent installation path.

My libevent content is as follows:

[email protected] ld.so.conf.d]# cat libevent.conf

/usr/libevent/lib

After configuration, execute the following ldconfig command

[[Email protected] ~] #ldconfig

3 ), if the shared library file is installed in a different "non-/lib or/usr/lib" directory, but does not want to add the path in the/etc/ld.so.conf (or there is no permission to add the path). You can also use the following solutions:

Use Ld_debug=help./memcached-v to determine which class library path to load by using the following method:
Ld_debug=libs./memcached-v 2>&1 >/dev/null | Less

      

The system will display:

        

    [Email protected] memcached]# ld_debug=libs /home/zwl/memcached/memcached/bin/memcached-v

6513:search Cache=/etc/ld.so.cache

    6513:trying file=/lib/tls/i686/sse2/libevent-1.4.so. 2

    6513:trying file=/lib/tls/i686/libevent-1.4.so. 2

    6513:trying file=/lib/tls/sse2/libevent1.4.so. 2

**********

**********

/home/zwl/memcached/memcached/bin/ memcached:error while loading shared libraries:libevent- 1.4.so. 2:cannot Open Shared object file:no such file or directory

     We see, memcached will go to many places to find, so according to other request, we only need to build a soft link, designated to our installed class library can be
Here's how:
ln-s/usr/local/lib/libevent-1.4.so.2/lib/libevent-1.4.so. 2

    

4) If the shared library file is installed in a different "non-/lib or/usr/lib" directory, but does not want to add the path in the/etc/ld.so.conf (or there is no permission to add the path). That can export a global variable ld_library_path, and then run the program will go to this directory to find the shared library.

Ld_library_path means to tell loader which directories can be found in the shared library. You can set up multiple search directories separated by colons. For example, install a MySQL into the/usr/local/mysql directory, where there are a lot of library files under/usr/local/mysql/lib, you can add the following statements in the. BASHRC or. Bash_profile or shell:

Export Ld_library_path=/usr/local/mysql/lib: $LD _library_path

In general, this is a temporary solution that is used when there is no authority or temporary need.

    

  

Install and configure and start memcached under Linux

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.