Install memcached on centos

Source: Internet
Author: User
Tags zts

Install memcached on centos

1. Install libevent

Install libevent before installing memcached.

Wgethttp: //

Tar zxvf libevent-2.0.22-stable.tar.gz

Cd libevent-2.0.22-stable


Make & make install

2. Install memcached

Wgethttp: //

Tar zxvf memcached-1.2.7.tar.gz

Cd memcached-1.2.7


Make & make install

Note: make reports an error.

Memcached. c: In the 'Add _ iov' function:

Memcached. c: 696: 30: Error: 'iov _ MAX 'is not declared (used for the first time in this function)

Memcached. c: 696: 30: Note: Each undeclared identifier is reported only once in the function it appears.

Make [2]: *** [memcached-memcached.o] Error 1

Modify the memcached. c file:

Copy code

/* FreeBSD 4.x doesn't have IOV_MAX exposed .*/

# Ifndef IOV_MAX

# If defined (_ FreeBSD _) | defined (_ APPLE __)

# Define IOV_MAX 1024

# Endif

# Endif


/* FreeBSD 4.x doesn't have IOV_MAX exposed .*/

# Ifndef IOV_MAX

# Define IOV_MAX 1024

# Endif

Copy code

Make & make install again, and exit the root user after compilation.

After the installation is complete, the default directory of memcached is/usr/local/bin/memcached.

3. Start memcached

/Usr/local/bin/memcached-m 32 MB-p 11211-d-u root-P/var/run/memcached. pid-c 256

Solution to the following error:

/Usr/local/bin/memcached: error while loadingsharedlibraries: cannotopen#dobjectfile: Nosuchfileordirectory

Solution to not found

Echo "/usr/local/lib">/etc/ld. so. conf


Startup parameters:
The-d option is to start a daemon.
-U root indicates that the user who starts memcached is root.
-M indicates the amount of memory allocated to Memcache. The unit is MB. The default value is 64 MB.
-M return error on memory exhausted (rather than removing items ).
-U is the user who runs Memcache. If it is currently root, you need to use this parameter to specify the user.
-L is the IP address of the listening server. The default value is all NICs.
-P is the port used to set TCP listening for Memcache, preferably over 1024.
-The c option is the maximum number of concurrent connections. The default value is 1024.
-P is the pid file for saving Memcache.
-F <factor> chunk size growth factor (default: 1.25 ).
-I Override the size of each slab page. Adjusts max item size (New in version 1.4.2 ). You can also start multiple daemon processes, but the ports cannot be repeated.

Test whether startup is normal

Telnet local host 11211
2. view the memcached startup command
Ps aux | grep memcached

2.1.2. Stop memcached

Kill 'cat/var/run/memcached/pid'

6. install PHP extension for Memcache

Wgethttp: //

Tar zxvf memcache-2.2.5.tar.gz



./Configure -- enable-memcache -- with-php-config =/home/webserver/php/bin/php-config

Make & make install

After the installation is complete, the following prompt appears:

Installing shared extensions:


Modify the php. ini file

Change extension_dir = "./" to extension_dir = "/home/webserver/php/lib/php/extensions/no-debug-non-zts-20121212 /"

Add the following line of code

Extension = memcache. so

7. Test whether Memcache PHP is successfully installed.

Run the following code:

<? Php

$ Mem = new Memcache;

$ Mem-> connect ('2017. 0.0.1 ', 127 );

$ Mem-> set ('test', "hello world! ", 0, 12 );

$ Val = $ mem-> get ('test ');

Echo $ val;


Related Article

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: 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.