1. 安装memcached
tar zxvf libevent-1.2.tar.gz
cd libevent-1.2
./configure –prefix=/usr
make
make install
tar zxvf memcached-1.2.0.tar.gz
cd memcached-1.2.0
./configure --prefix=/usr/local/memcached --with-libevent=/usr
make
make install
2. 启动memcached
/usr/local/memcached/memcached -d -m 100 -p 11211 -u root
如果出错,则执行:
ln -s /usr/local/lib/libevent-1.2.so.1 /lib/libevent-1.2.so.1
3. 安装memcache的php扩展
tar vxzf memcache-2.2.1.tgz
cd memcache-2.2.1
/usr/local/php/bin/phpize
./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-2007xxxx/
把php.ini中的extension_dir = './'修改为
extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/”
添加一行来载入memcache扩展:extension=memcache.so
4. 安装libmemcached和memcached_functions_mysql
wget http://download.tangent.org/libmemcached-0.42.tar.gz
wget http://download.tangent.org/memcached_functions_mysql-0.9.tar.gz
tar zxvf libmemcached-0.42.tar.gz
tar zxvf memcached_functions_mysql-0.9.tar.gz
cd libmemcached-0.42
./configure --prefix=/usr/local/libmemcached/ --with-memcached=/usr/local/memcached/bin/memcached
make
make install
如果出错,可执行:
./configure --prefix=/usr/local/libmemcached/ --with-memcached=/usr/local/memcached/bin/memcached --disable-64bit CFLAGS="-O3 -march=i686"
cd memcached_functions_mysql-0.9
./configure --with-mysql=/usr/bin/mysql_config --libdir=/var/lib/mysql --with-libmemcached=/usr/local/libmemcached
make
make install
如果出错,可执行:
ln -s /usr/local/libmemcached/lib/libmemcached.so /lib/libmemcached.so
ln -s /usr/local/libmemcached/lib/libmemcached.so.5 /lib/libmemcached.so.5
或者重装libmemcached,换一个较低的版本(例如:libmemcached-0.30.tar.gz)
5. 进行映射
mysql -hlocalhost -uroot -p
将UDFs加载到MySQL中:
create function memc_servers_set returns int soname "libmemcached_functions_mysql.so";
create function memc_set returns int soname "libmemcached_functions_mysql.so";
create function memc_get returns string soname "libmemcached_functions_mysql.so";
create function memc_delete returns string soname "libmemcached_functions_mysql.so";
如果出错,可执行:
ln -s /var/lib/mysql/libmemcached_functions_mysql.so /lib/libmemcached_functions_mysql.so
测试UDF是否安装成功:
先添加Memcached,可以添加多台
select memc_servers_set('127.0.0.1:11211');
select memc_set('libing', 'roast');
select memc_get('libing');
6. 进行测试
mysql -hlocalhost -uroot -p
create table mctest(`key` int, `value` varchar(100));
create trigger mysqlmmc before insert on mctest for each row set @tmp = memc_set(NEW.key, NEW.value);
show triggers;
select memc_servers_set('127.0.0.1:11211');
insert into mctest values(9, 'roast');
select memc_get('9');
select * from mctest;
telnet 127.0.0.1 11211
get 9
7. 程序测试
参考:http://www.cnblogs.com/cy163/archive/2009/08/12/1544143.html
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/4801/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2015-2-11 17:29
评论列表
2011-11-26 20:32 | 李彦宏
学习了 厉害啊
分页: 1/1 1