Drupal7中配置Memcache方法详解
发布:smiling 来源: PHP粉丝网 添加日期:2014-01-08 14:44:26 浏览: 评论:0
Memcache的配置就不多说,drupal由于模块较多,数据库调用频繁,因此memcache是drupal站点中必备的配置,本文大概列一下Drupal7中关于memcache的配置情况,以方便大家查阅。
1.安装memcache服务以及启动memcached.
2.安装drupal的memcache模块.(http://drupal.org/project/memcache)
3.配置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';
注意,需要将memcache.inc的文件路径写正确,如Drupal模块目录组织方式总结中提到,我们一般将memcache模块会放置在contrib文件夹下面,因此路径可能是 sites/all/modules/contrib/memcache/memcache.inc,此外memcache_key_prefix最好设置一下。
4.多个memcachd服务。
默认情况下,如果不配置memcache_servers以及memcache_bins的话,Drupal会认为只有一个server,即127.0.0.1:11211,如果有多个memcache实例的话,需要添加如下配置,代码如下:
- $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'
- );
一切就绪,最后讲解一下单台机器如何配置多个memcache实例,即单台机器的memcache集群搭建。
我们需要修改2个文件,一个是启动脚本/etc/init.d/memcached-multi,另一个是配置文件/etc/sysconfig/memcached,代码如下:
/etc/sysconfig/memcached
是用来配置多个memcache实例的大小,代码如下:
- PORT="11211"
- USER="memcached"
- MAXCONN="1024"
- CACHESIZE="512"
- OPTIONS=""
- MULTIBUCKET="2"
- CACHESIZEARRAY[1]="1024"
- CACHESIZEARRAY[2]="128"/etc/init.d/memcached-multi
是用来启动memcache集群,(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/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" ] && 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/memcached.pid memcached -d -p $PORT -u $USER -m $THISCACHESIZE -c $MAXCONN -P /var/run/memcached/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/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
至此一些就绪.
Tags: Drupal7 配置 Memcache
相关文章
- ·phpMyAdmin配置安装全攻略(2013-11-13)
- ·详解如何正确配置PHP开发环境(2013-11-13)
- ·phpmyadmin 配置方法与安装教程(2013-11-28)
- ·php 5.3环境配置方法(apache2.2 mysql5.1)(2013-11-28)
- ·PHP.ini中文配置说明(2014-02-18)
- ·wampSever本地配置404页面(2014-03-24)
- ·PHP5中SESSION路径配置详解(2014-03-24)
- ·修改PHP配置文件上传大文件几种方法(apache/nginx)(2014-07-08)
- ·PHPStorm 配置安装教程(2014-08-21)
- ·Laravel4安装配置的方法(2014-08-25)
- ·PHP XDebug配置与安装方法详解(2014-08-25)
- ·php sockets扩展安装配置详解(2014-08-25)
- ·windows wamp中配置安装xhprof步骤(2014-08-25)
- ·php xdebug安装配置与调试php技巧(2014-08-25)
- ·mac php netbeans xdebug 配置方法详解(2014-08-25)
- ·PHPStorm主题安装配置方法详解(2014-08-25)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)