Reprint: Centos7 from zero compile configuration memcached

Source: Internet
Author: User
Tags configuration php delete key memcached php memcached zts

Preface

Memcached is a high-performance distributed memory object caching system for dynamic Web applications to mitigate database load. It improves the speed of dynamic, database-driven Web sites by caching data and objects in memory to reduce the number of times a 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.

Of course memcached is divided into server and client. The server is used to store the cache and the client is used to manipulate the cache.

There are two common implementations of clients.

The first is to use PHP code according to the service side of the communication rules to write their own.

The second is the installation of the PHP extension Library (php-memcached).

Directory

First, Centos7 from zero compile Nginx+php+mysql

Second, Centos7 from zero configuration nginx+php+mysql

Third, Centos7 from the zero compiler configuration memcached

First, the preparatory work

Create the directory source and package, respectively, to put the source code and the compiled file

# mkdir/source/# mkdir/package/

Ii.memcached(end of service)

First install the memcached dependent library libevent.

2.1 Installing Libevent

[Official website] http://libevent.org/

Command flow:

# cd/source/# wget https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/ libevent-2.0.22-stable.tar.gz# TAR-ZXVF libevent-2.0.22-stable.tar.gz
# CD libevent-2.0.22-stable#./configure--prefix=/package/libevent# make# make install

2.2 Installing memcached

[Official website] http://memcached.org/

Command flow:

# cd/source/
# wget http://memcached.org/files/memcached-1.4.25.tar.gz# tar-zxvf memcached-1.4.25.tar.gz# cd memcached-1.4.25#./ Configure--prefix=/lnmp/memcached--with-libevent=/package/libevent
# make
# make Install

This chapter summarizes:

It is easy to compile the memcached server with the above operation. At this point, you can open the server to work.

#/lnmp/memcached/bin/memcached-d-M 2048-l 127.0.0.1-p 11211-u root-c 1024–p/tmp/memcached.pid
Start parameter Description: the-D option is to start a daemon. The amount of memory used by-m allocated to Memcache, in megabytes, default 64MB. The IP address of the-l listener. (Default: Inaddr_any, all addresses)-P sets the port for TCP listening on memcache, preferably over 1024 ports. -U the user who runs Memcache, if it is currently root, needs to use this parameter to specify the user. The-c option is the maximum number of concurrent connections to run, and the default is 1024. -p Settings Save the PID file for Memcache.

Third,memcached (client- side article)

The first type: PHP Code

This method is the simplest way to implement the client, directly download my "sl_memcached" class library include to call the relevant objects in their own projects.

Of course, you can also implement it in other languages. This is not the place to talk.

Here's how to use it:

<?phpinclude (' memcached.class.php '); $memcached = new sl_memcached ();   Instantiate object $memcached->connect (' 127.0.0.1:11211 ');   Connect memcached server $memcached->set (' key1 ', ' I am happy key value ');    Set the key value $memcached->set (' Key2 ', ' I'm going to be deleted ');          Set the key value $memcached->delete (' Key2 ');      Delete key value Var_dump ($memcached->get (' Key1 '));      Gets the key value Var_dump ($memcached->get (' Key2 ')); Gets the key value?>

Output:

String (21) "I am the key value of happiness"

Null

Iv.memcached( client article)

The second type: php-memcached

This kind of client is more troublesome, he is the extension library file memcached.so that generates PHP.

First install the memcached dependent library zlib, libmemcached.

4.1 Installing Zlib

[Official website] http://zlib.net/

Command flow:

# cd/source/
# wget http://zlib.net/zlib-1.2.8.tar.gz# TAR-ZXVF zlib-1.2.8.tar.gz
#./configure--prefix=/package/zlib
# make
# make Install

4.2 Installing libmemcached

[Official website] http://libmemcached.org/

Command flow:

# cd/source/# wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz# TAR-ZXVF libmemcached-1.0.18.tar.gz# CD libmemcached-1.0.18#./configure--prefix=/package/libmemcached# make# make install

4.3 Installing M4

[Official website] Http://www.gnu.org/software/m4/m4.html

Command flow:

# cd/source/# wget http://ftp.gnu.org/gnu/m4/m4-1.4.17.tar.gz# tar-zxvf m4-1.4.17.tar.gz# cd m4-1.4.17#./configure--p refix=/package/m4# make# make install# export path=/package/m4/bin: $PATH

4.3 Installing php-memcached

[Official website] Http://pecl.php.net/package/memcached

Command flow:

# cd/source/# wget https://github.com/php-memcached-dev/php-memcached/archive/php7.zip# unzip php7.zip# CD php-memcached-php7#/lnmp/php/bin/phpize
#./configure \
#--with-php-config=/lnmp/php/bin/php-config \
#--with-zlib-dir=/package/zlib \
#--with-libmemcached-dir=/package/libmemcached \
#--DISABLE-MEMCACHED-SASL

# make
# make Install

Note:

After successful installation, there will be a similar prompt like this:

Installing Shared extensions:/lnmp/php/lib/php/extensions/no-debug-non-zts-20151012/

This means that the memcached.so will be generated under the/lnmp/php/lib/php/extensions/no-debug-non-zts-20151012/directory.

This is the directory where memcached.so is located. Let's remember this directory first.

Start Configuration php-memcached

Open php.ini

# Vi/lnmp/php/etc/php.ini

Add the following in the appropriate location
Extension =/lnmp/php/lib/php/extensions/no-debug-non-zts-20151012/memcached.so

------------------------------------------------------------

V. Common Mistakes

------------------------------------------------------------

5.1 Unable to load dynamic library ' memcached.so '-libmemcached.so.11:cannot open Shared object file:no such file or di Rectory in Unknown No line 0

Description: No additional libraries found for PHP memcached.so the required dynamic library libmemcached.so.11. The above error generally does not set the libmemcached directory to an environment variable.

We add it to the environment variable ld_library_path and we're done.

# Export Ld_library_path=/package/libmemcached/lib: $LD _library_path

Reprint: Centos7 from zero compile configuration memcached

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.