linux 初学之安装memcached

来源:互联网 发布:linux定时器crontab 编辑:程序博客网 时间:2024/05/12 01:46

1、安装memcached的依赖libevent                                yum -y install libevent

2、安装memcached

wget -c http://code.google.com/p/memcached/downloads/detail?name=memcached-1.4.15.tar.gz&can=2&q=

tar -zxf memcached-1.4.15.tar.gz

./configure --with-libevent=/usr/local/libevent

make

make install

3、安装memcache 的php拓展

wget -c http://pecl.php.net/get/memcache-3.0.8.tgz

tar -zxf memcache-3.0.8.tgz

cd memcache-3.0.8
/usr/local/php/bin/phpize

若phpize不行,那 yum install m4,yum install autoconf
./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir

make && make install

安装好后会出现:Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/

4、最后修改php.ini文件,在zend之前加入如下代码。

[memcache]

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"

extension=memcache.so

service httpd restart


启动Memcache的服务器端:
# /usr/local/bin/memcached -d -m 10 -u root -l 192.168.0.200 -p 12000 -c 256 -P /tmp/memcached.pid

如果要结束Memcache进程,执行:kill `cat /tmp/memcached.pid`

5、测试

$mem = new Memcache;
$mem->connect("127.0.0.1", 11211)or die ("Could not connect");
 
$mem->set('key', 'This is a test!', 0, 60);
$val = $mem->get('key');
echo $val;

原创粉丝点击