Linux下的Memcache安装
作者: 曲文庆 日期: 2008-12-02 16:26
最近有个新项目应用memcache,记录下Memcache安装的过程。
Linux下Memcache服务器端的安装
服务器端主要是安装memcache服务器端,目前的最新版本是 memcached-1.2.6 。
下载:http://www.danga.com/memcached/dist/memcached-1.2.6.tar.gz
另外,Memcache用到了libevent这个库用于Socket的处理,所以还需要安装libevent,libevent的最新版本是libevent-1.4.8-stable。(如果你的系统已经安装了libevent,可以不用安装)
官网:http://www.monkey.org/~provos/libevent/
下载:http://www.monkey.org/~provos/libevent-1.4.8-stable.tar.gz用wget指令直接下载这两个东西.下载回源文件后。
1.先安装libevent。这个东西在配置时需要指定一个安装路径,即./configure –prefix=/usr/local/ libevent-1.4.8-stable;然后make;然后make install;
2.再安装memcached,只是需要在配置时需要指定libevent的安装路径即./configure --prefix=/usr/local/memcached-1.2.6 –with-libevent=/usr/local/ libevent-1.4.8-stable --enable-64bit --enable-threads;然后make;然后make install;
这样就完成了Linux下Memcache服务器端的安装。详细的方法如下:
1.分别把memcached和libevent下载回来,放到 /tmp 目录下:
# cd /tmp
# wget http://www.danga.com/memcached/dist/memcached-1.2.6.tar.gz
# wget http://www.monkey.org/~provos/ libevent-1.4.8-stable.tar.gz
2.先安装libevent:
# tar zxvf libevent-1.4.8-stable.tar.gz
# cd libevent-1.4.8-stable
# ./configure --prefix=/usr/local/libevent-1.4.8-stable
# make
# make install
3.测试libevent是否安装成功:
# ls -al /usr/local/libevent-1.4.8-stable/lib | grep libevent
vi /etc/ld.so.conf加入 /usr/local/libevent-1.4.8-stable/lib运行 ldconfig否则运行memcached的时候,会提示找不到so文件
4.安装memcached,同时需要安装中指定libevent的安装位置:
# cd /tmp
# tar zxvf memcached-1.2.6.tar.gz
# cd memcached-1.2.6
#./configure --prefix=/usr/local/memcached-1.2.6 --with-libevent=/usr/local/libevent-1.4.8-stable --enable-64bit --enable-threads
# make
# make install#ln -s /usr/local/memcached-1.2.6 /usr/local/memcached
如果中间出现报错,请仔细检查错误信息,按照错误信息来配置或者增加相应的库或者路径。
安装完成后会把memcached放到 /usr/local/memcached/bin/memcached
5.测试是否成功安装memcached:
# ls -al /usr/local/memcached/bin/mem*
-rwxr-xr-x 1 root root 137986 11?? 12 17:39 /usr/local/bin/memcached
-rwxr-xr-x 1 root root 140179 11?? 12 17:39 /usr/local/bin/memcached-debug
安装Memcache的PHP扩展
1.在http://pecl.php.net/package/memcache 选择相应想要下载的memcache版本。
2.安装PHP的memcache扩展#tar vxzf memcache-2.2.4.tgz
#cd memcache-2.2.4
#/usr/local/php/bin/phpize
#./configure --enable-memcache -with-php-config=/usr/local/php/bin/php-config -with-zlib-dir
#make
#make install
3.上述安装完后会有类似这样的提示:Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/
4.把php.ini中的extension_dir = “./”修改为extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/”
5.添加一行来载入memcache扩展:extension=memcache.so
memcached的基本设置:
1.启动Memcache的服务器端:
# /usr/local/bin/memcached -d -m 1024 -u nobody -l 192.168.0.200 -p 11211 -c 4096 -P /var/run/memcached/memcached.pid-d选项是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB,我这里是1024MB,
-u是运行Memcache的用户,我这里是nobody,
-l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.0.200,
-p是设置Memcache监听的端口,我这里设置了11211,最好是1024以上的端口,
-c选项是最大运行的并发连接数,默认是1024,我这里设置了4096,按照你服务器的负载量来设定,
-P是设置保存Memcache的pid文件,我这里是保存在 /var/run/memcached/memcached.pid,
2.如果要结束Memcache进程,执行:# kill `cat /tmp/memcached.pid`也可以启动多个守护进程,不过端口不能重复。
3.重新加载php
也可以写一个运行脚本来处理memcached
#! /bin/sh
#
# chkconfig: - 55 45
# description: The memcached daemon is a network memory cache service.
# processname: memcached
# config: /etc/sysconfig/memcached
Linux下Memcache服务器端的安装
服务器端主要是安装memcache服务器端,目前的最新版本是 memcached-1.2.6 。
下载:http://www.danga.com/memcached/dist/memcached-1.2.6.tar.gz
另外,Memcache用到了libevent这个库用于Socket的处理,所以还需要安装libevent,libevent的最新版本是libevent-1.4.8-stable。(如果你的系统已经安装了libevent,可以不用安装)
官网:http://www.monkey.org/~provos/libevent/
下载:http://www.monkey.org/~provos/libevent-1.4.8-stable.tar.gz用wget指令直接下载这两个东西.下载回源文件后。
1.先安装libevent。这个东西在配置时需要指定一个安装路径,即./configure –prefix=/usr/local/ libevent-1.4.8-stable;然后make;然后make install;
2.再安装memcached,只是需要在配置时需要指定libevent的安装路径即./configure --prefix=/usr/local/memcached-1.2.6 –with-libevent=/usr/local/ libevent-1.4.8-stable --enable-64bit --enable-threads;然后make;然后make install;
这样就完成了Linux下Memcache服务器端的安装。详细的方法如下:
1.分别把memcached和libevent下载回来,放到 /tmp 目录下:
# cd /tmp
# wget http://www.danga.com/memcached/dist/memcached-1.2.6.tar.gz
# wget http://www.monkey.org/~provos/ libevent-1.4.8-stable.tar.gz
2.先安装libevent:
# tar zxvf libevent-1.4.8-stable.tar.gz
# cd libevent-1.4.8-stable
# ./configure --prefix=/usr/local/libevent-1.4.8-stable
# make
# make install
3.测试libevent是否安装成功:
# ls -al /usr/local/libevent-1.4.8-stable/lib | grep libevent
vi /etc/ld.so.conf加入 /usr/local/libevent-1.4.8-stable/lib运行 ldconfig否则运行memcached的时候,会提示找不到so文件
4.安装memcached,同时需要安装中指定libevent的安装位置:
# cd /tmp
# tar zxvf memcached-1.2.6.tar.gz
# cd memcached-1.2.6
#./configure --prefix=/usr/local/memcached-1.2.6 --with-libevent=/usr/local/libevent-1.4.8-stable --enable-64bit --enable-threads
# make
# make install#ln -s /usr/local/memcached-1.2.6 /usr/local/memcached
如果中间出现报错,请仔细检查错误信息,按照错误信息来配置或者增加相应的库或者路径。
安装完成后会把memcached放到 /usr/local/memcached/bin/memcached
5.测试是否成功安装memcached:
# ls -al /usr/local/memcached/bin/mem*
-rwxr-xr-x 1 root root 137986 11?? 12 17:39 /usr/local/bin/memcached
-rwxr-xr-x 1 root root 140179 11?? 12 17:39 /usr/local/bin/memcached-debug
安装Memcache的PHP扩展
1.在http://pecl.php.net/package/memcache 选择相应想要下载的memcache版本。
2.安装PHP的memcache扩展#tar vxzf memcache-2.2.4.tgz
#cd memcache-2.2.4
#/usr/local/php/bin/phpize
#./configure --enable-memcache -with-php-config=/usr/local/php/bin/php-config -with-zlib-dir
#make
#make install
3.上述安装完后会有类似这样的提示:Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/
4.把php.ini中的extension_dir = “./”修改为extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/”
5.添加一行来载入memcache扩展:extension=memcache.so
memcached的基本设置:
1.启动Memcache的服务器端:
# /usr/local/bin/memcached -d -m 1024 -u nobody -l 192.168.0.200 -p 11211 -c 4096 -P /var/run/memcached/memcached.pid-d选项是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB,我这里是1024MB,
-u是运行Memcache的用户,我这里是nobody,
-l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.0.200,
-p是设置Memcache监听的端口,我这里设置了11211,最好是1024以上的端口,
-c选项是最大运行的并发连接数,默认是1024,我这里设置了4096,按照你服务器的负载量来设定,
-P是设置保存Memcache的pid文件,我这里是保存在 /var/run/memcached/memcached.pid,
2.如果要结束Memcache进程,执行:# kill `cat /tmp/memcached.pid`也可以启动多个守护进程,不过端口不能重复。
3.重新加载php
也可以写一个运行脚本来处理memcached
#! /bin/sh
#
# chkconfig: - 55 45
# description: The memcached daemon is a network memory cache service.
# processname: memcached
# config: /etc/sysconfig/memcached
# Source function library.
. /etc/rc.d/init.d/functions
. /etc/rc.d/init.d/functions
MEMCACHED=/usr/local/memcached/bin/memcached
PFILE=/var/run/memcached/memcached.pid
IP_ADDR=192.168.0.200
PORT=11211
USER=nobody
MAXCONN=4096
CACHESIZE=1024
THREADS=4
OPTIONS="-d -r -M"
PFILE=/var/run/memcached/memcached.pid
IP_ADDR=192.168.0.200
PORT=11211
USER=nobody
MAXCONN=4096
CACHESIZE=1024
THREADS=4
OPTIONS="-d -r -M"
if [ ! -f ${MEMCACHED} ]; then
exit 1
fi
exit 1
fi
if [ -f /etc/sysconfig/memcached ];then
. /etc/sysconfig/memcached
fi
. /etc/sysconfig/memcached
fi
# Check that networking is up.
if [ "$NETWORKING" = "no" ]
then
exit 0
fi
if [ "$NETWORKING" = "no" ]
then
exit 0
fi
RETVAL=0
prog="memcached"
prog="memcached"
start () {
echo -n $"Starting $prog: "
# insure that /var/run/memcached has proper permissions
if [ ! -d /var/run/memcached ]; then
mkdir -p /var/run/memcached
chown $USER /var/run/memcached
fi
daemon ${MEMCACHED} -l $IP_ADDR -p $PORT -t $THREADS -u $USER -m $CACHESIZE -c $MAXCONN -P $PFILE $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached
}
stop () {
echo -n $"Stopping $prog: "
killproc ${MEMCACHED}
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
rm -f /var/lock/subsys/memcached
rm -f /var/run/memcached.pid
fi
}
echo -n $"Starting $prog: "
# insure that /var/run/memcached has proper permissions
if [ ! -d /var/run/memcached ]; then
mkdir -p /var/run/memcached
chown $USER /var/run/memcached
fi
daemon ${MEMCACHED} -l $IP_ADDR -p $PORT -t $THREADS -u $USER -m $CACHESIZE -c $MAXCONN -P $PFILE $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached
}
stop () {
echo -n $"Stopping $prog: "
killproc ${MEMCACHED}
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
rm -f /var/lock/subsys/memcached
rm -f /var/run/memcached.pid
fi
}
restart () {
stop
start
}
stop
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status memcached
;;
restart|reload)
restart
;;
condrestart)
[ -f /var/lock/subsys/memcached ] && restart || :
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}"
exit 1
esac
exit $?
Memcache环境测试:
运行下面的php文件,如果有输出This is a test!,就表示环境搭建成功。开始领略Memcache的魅力把!
< ?php
$mem = new Memcache;
$mem->connect(”192.168.0.200″, 11211);
$mem->set(’key’, ‘This is a test!’, 0, 60);
$val = $mem->get(’key’);
echo $val;
?>
Memcache环境测试:
运行下面的php文件,如果有输出This is a test!,就表示环境搭建成功。开始领略Memcache的魅力把!
< ?php
$mem = new Memcache;
$mem->connect(”192.168.0.200″, 11211);
$mem->set(’key’, ‘This is a test!’, 0, 60);
$val = $mem->get(’key’);
echo $val;
?>
评论: 0 |
引用: 0 |
阅读: 7054
php-fpm for php-5.3.8 (2011-08-25 23:02)
关闭访问头部的php信息 (2011-01-02 22:53)
php 5.3 不建议使用的函数 (2010-05-19 16:53)
php 5.3 中新增加的魔术变量 __DIR__ (2010-05-14 13:46)
linux遭遇磁盘空间灵异事件 (2010-05-14 10:42)
linux 双网卡绑定(bonding)实现负载均衡或故障转移 (2010-05-13 16:11)
Windows 7 安装、运行 Sniffer 4.7.5 sp5 (2010-04-30 08:55)
yum更新和rpm安装包问题(rpmdb: PANIC: Invalid argument) (2010-04-28 11:10)
windows server 2003 IIS上安装 PHP 5.3 (2010-03-03 15:53)