Detailed description of how to configure Memcache in Drupal7

Source: Internet
Author: User
Tags drupal
This article describes how to configure Memcache in Drupal7. I hope this method will be helpful to you. Memcache configuration is not much said. due to the large number of modules in drupal and frequent database calls, mem... this article describes how to configure Memcache in Drupal7. I hope this method will be helpful to you.

Memcache configuration is not much said. because drupal has many modules and frequent database calls, memcache is a required configuration in the drupal site. This article describes the configuration of memcache in Drupal7, for your convenience.

1. install the memcache service and start memcached.

2. install the drupal memcache module. Http://drupal.org/project/memcache)

3. configure settings. php

 $conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';  // The 'cache_form' bin must be assigned no non-volatile storage.  $conf['cache_class_cache_form'] = 'DrupalDatabaseCache';  $conf['cache_default_class'] = 'MemCacheDrupal';  $conf['memcache_key_prefix'] = 'something_unique';

Note that memcache is required. the file path of inc is correctly written. as mentioned in the Drupal module directory organization summary, we generally place the memcache module under the contrib folder, therefore, the path may be sites/all/modules/contrib/memcache. inc.

In addition, it is best to set memcache_key_prefix.

4. multiple memcachd services.

By default, if memcache_servers and memcache_bins are not configured, Drupal considers that there is only one server, that is, 127.0.0.1: 11211. if there are multiple memcache instances, add the following configuration.

$conf['memcache_servers'] = array(  '10.1.1.1:11211' => 'default',  '10.1.1.1:11212' => 'default',  '10.1.1.2:11211' => 'default',  '10.1.1.3:11211' => 'cluster2',  '10.1.1.4:11211' => 'cluster2');$conf['memcache_bins'] = array(  'cache'  => 'default',  'cache_filter' => 'cluster2',  'cache_menu' => 'cluster2');

Everything is ready.

Finally, I will explain how to configure multiple memcache instances on a single machine, that is, to build a memcache cluster on a single machine.

We need to modify two files, one is the startup script/etc/init. d/memcached-multi, and the other is the configuration file/etc/sysconfig/memcached.

/Etc/sysconfig/memcached

Is used to configure the size of multiple memcache instances

PORT = "11211"

USER = "memcached"

MAXCONN = "1024"

CACHESIZE = "512"

OPTIONS = ""

MULTIBUCKET = "2"

CACHESIZEARRAY [1] = "1024"

CACHESIZEARRAY [2] = "128"/etc/init. d/memcached-multi

Is used to start the memcache cluster. (Start, stop, restart)

#! /Bin/sh

#

# Chkconfig:-55 45

# Description: The memcached daemon is a network memory cache service.

# Processname: memcached

# Config:/etc/sysconfig/memcached

# Pidfile:/var/run/memcached. pid

# Standard LSB functions

#./Lib/lsb/init-functions

# Source function library.

./Etc/init. d/functions

PORT = 11211

USER = memcached

MAXCONN = 1024

CACHESIZE = 64

OPTIONS = ""

MULTIBUCKET = ""

If [-f/etc/sysconfig/memcached]; then

./Etc/sysconfig/memcached

Fi

[-Z "$ MULTIBUCKET"] & amp; MULTIBUCKET = 1

# Check that networking is up.

./Etc/sysconfig/network

If ["$ NETWORKING" = "no"]

Then

Exit 0

Fi

RETVAL = 0

Prog = "memcached"

Start (){

Echo-n $ "Starting $ prog :"

# Insure that/var/run/memcached has proper permissions

If ["'stat-c % U/var/run/memcached "'! = "$ USER"]; then

Chown $ USER/var/run/memcached

Fi

For I in '/usr/bin/seq 1 $ multibucket'; do

THISCACHESIZE = $ CACHESIZE

[$ {# CACHESIZEARRAY [*]}-gt 0-a $ {CACHESIZEARRAY [$ I]: -0}-gt 0] & THISCACHESIZE =$ {CACHESIZEARRAY [$ I]}

Daemon -- pidfile/var/run/memcached. pid memcached-d-p $ PORT-u $ USER-m $ THISCACHESIZE-c $ MAXCONN-P/var/run/memcached-$ I. pid $ OPTIONS

Let RETVAL = $ RETVAL + $?

Let PORT = $ PORT + 1

Done

Echo

[$ RETVAL-eq 0] & touch/var/lock/subsys/memcached

}

Stop (){

Echo-n $ "Stopping $ prog :"

For I in '/usr/bin/seq 1 $ multibucket'; do

Killproc-p/var/run/memcached-$ I. pid/usr/bin/memcached

Let RETVAL = $ RETVAL + $?

Done

Echo

If [$ RETVAL-eq 0]; then

Rm-f/var/lock/subsys/memcached

Rm-f/var/run/memcached. pid

Fi

}

Restart (){

Stop

Start

}

# See how we were called.

Case "$1" in

Start)

Start

;;

Stop)

Stop

;;

Status)

Echo "Warning: This status check is laughable. Inspect netstat or ps output manually ."

Status memcached

;;

Restart | reload | force-reload)

Restart

;;

Condrestart)

[-F/var/lock/subsys/memcached] & restart |:

;;

*)

Echo $ "Usage: $0 {start | stop | status | restart | reload | force-reload | condrestart }"

Exit 1

Esac

Exit $ RETVAL

So far, some are ready.


Tutorial link:

Reprint at will ~ However, please keep the tutorial address★

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.