Memcached standalone deployment-Single Instance/multiple instances

Source: Internet
Author: User

Memcached standalone deployment-Single Instance/multiple instances

Memcached is a high-performance distributed memory object Cache System for dynamic web applications to reduce database load. It caches data and objects in the memory to reduce the number of reads to the database, thus improving the speed of dynamic and database-driven websites. Memcached is based on a hash map that stores key/value pairs. Its daemon is written in c, but the client can write it in any language and communicate with the daemon through memcached protocol.

OK. For a brief introduction, deploy now!


  • CentOS 6.5 x86_64-bit installation is minimized, and the system has been optimized.
  • Selinux is disabled, and iptables is in unrestricted mode.
  • Host Name: bkjia
  • Source code package storage location:/usr/local/src
  • Libevent version: 2.0.21
  • Memcached version: 1.4.20

Memcached installation and startup script

Performance problems of using Memcached in PHP

Install Memcached in Ubuntu and its command explanation

Install and apply Memcached

Use Nginx + Memcached's small image storage solution

Getting started with Memcached

I. Basic Environment preparation

[Root @ bkjia ~] # Yum-y install gcc-c ++

2. Service deployment

1. Install libevent

Libevent is a library that encapsulates the epool of linux, kqueue of BSD operating systems, and other event processing functions into a unified interface. Even if the number of connections to the server increases, the performance can be excellent.

Because memcached uses the libevent library to process sockets, We need to install libevent before installing memcached. Currently, the latest version of libevent is a libevent-2.0.21. If you have already installed libevent, skip this step.

[Root @ bkjia ~] # Cd/usr/local/src

[Root @ bkjia src] # wget Orig

[Root @ bkjia src] # tar zxvf libevent-2.0.21-stable.tar.gz

[Root @ bkjia src] # cd libevent-2.0.21-stable

[Root @ bkjia libevent-2.0.21-stable] #./configure -- prefix =/usr

[Root @ bkjia libevent-2.0.21-stable] # make

[Root @ bkjia libevent-2.0.21-stable] # make install

[Root @ bkjia libevent-2.0.21-stable] # ll/usr/lib/libevent * # After libevent is installed, the following content will appear in the/usr/lib directory

Lrwxrwxrwx 1 root 21 Aug 11/usr/lib/>

-Rwxr-xr-x 1 root 968690 Aug 11/usr/lib/

-Rw-r -- 1 root 1571802 Aug 11 13:49/usr/lib/libevent.

Lrwxrwxrwx 1 root 26 Aug 11/usr/lib/>

-Rwxr-xr-x 1 root 585225 Aug 11/usr/lib/

-Rw-r -- 1 root 978482 Aug 11 13:49/usr/lib/libevent_core.a

-Rwxr-xr-x 1 root 970 Aug 11/usr/lib/

Lrwxrwxrwx 1 root 26 Aug 11 13:49/usr/lib/>

Lrwxrwxrwx 1 root 27 Aug 11/usr/lib/>

-Rwxr-xr-x 1 root 404852 Aug 11/usr/lib/

-Rw-r -- 1 root 593392 Aug 11 :49/usr/lib/libevent_extra.a

-Rwxr-xr-x 1 root 977 Aug 11/usr/lib/

Lrwxrwxrwx 1 root 27 Aug 11 13:49/usr/lib/>

-Rwxr-xr-x 1 root 935 Aug 11/usr/lib/libevent. la

Lrwxrwxrwx 1 root 30 Aug 11/usr/lib/>

-Rwxr-xr-x 1 root 18430 Aug 11/usr/lib/

-Rw-r -- 1 root 18670 Aug 11 13:49/usr/lib/libevent_pthreads.a

-Rwxr-xr-x 1 root 998 Aug 11/usr/lib/

Lrwxrwxrwx 1 root 30 Aug 11 13:49/usr/lib/>

Lrwxrwxrwx 1 root 21 Aug 11/usr/lib/libevent. so->

[Root @ bkjia libevent-2.0.21-stable] # cd ..

2. Install memcached

[Root @ bkjia memcached-1.4.20] # wget Orig

[Root @ bkjia src] # tar zxvf memcached-1.4.20.tar.gz

[Root @ bkjia src] # cd memcached-1.4.20

[Root @ bkjia memcached-1.4.20] #./configure -- with-libevent =/usr

[Root @ bkjia memcached-1.4.20] # make

[Root @ bkjia memcached-1.4.20] # make install

[Root @ bkjia memcached-1.4.20] # cd

[Root @ bkjia ~] # Ll/usr/local/bin/memcached # After the installation is complete, memcached will be put to/usr/local/bin/memcached

-Rwxr-xr-x 1 root 341907 Aug 11/usr/local/bin/memcached


If an error is reported in the middle, check the error information carefully and configure or add the corresponding library or path according to the error information.

Iii. STARTUP configuration

1. Start the Memcached service.

[Root @ bkjia ~] #/Usr/local/bin/memcached-d-m 10-u root-l 11211-c 256-P/tmp/memcached. pid

[Root @ bkjia ~] # Lsof-I tcp: 11211

Command pid user fd type device size/OFF NODE NAME

Memcached 11470 root 26u IPv4 19581 0t0 TCP memcache (LISTEN)

Supplement: Introduction to memcached startup commands

-D. Start a daemon process.

-M: The amount of memory allocated to memcache. The unit is MB.

-U: the user who runs memcache

-L Server IP address of the listener

-P: Set the memcache listening port. It is recommended that the port number be greater than 1024.

-C: sets the maximum number of concurrent connections for running memcache. The default value is 1024.

-P: Set the pid file address for saving memcache.

The advantage of setting the pid file is that it is convenient to end the memcache process.

If the pid file exists, run the following command to quickly end the memcached process:

[Root @ bkjia ~] # Kill 'cat/tmp/memcached. Pi'

2. Configure memcached to start automatically

[Root @ bkjia ~] # Echo "# memcached service daemon by sun 201408022">/etc/rc. local

[Root @ bkjia ~] # Echo "/usr/local/bin/memcached-d-m 10-u root-l 11211-c 256-P/tmp/memcached. pid ">/etc/rc. local

[Root @ bkjia ~] # Tail-2/etc/rc. local

# Memcached service daemon by sun201408022

/Usr/local/bin/memcached-d-m 10-u root-l 11211-c 256-P/tmp/memcached. pid

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • Next Page

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.