Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7436258
  • 博文数量: 1758
  • 博客积分: 18684
  • 博客等级: 上将
  • 技术积分: 16252
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-02 10:28
个人简介

啥也没写

文章分类

全部博文(1758)

文章存档

2024年(4)

2023年(44)

2022年(39)

2021年(46)

2020年(43)

2019年(27)

2018年(44)

2017年(50)

2016年(47)

2015年(15)

2014年(21)

2013年(43)

2012年(143)

2011年(228)

2010年(263)

2009年(384)

2008年(246)

2007年(30)

2006年(38)

2005年(2)

2004年(1)

分类: LINUX

2011-06-29 09:51:25

很早之前,就看到了通过mysql UDF 更新memcached ,原来也研究过一段时间,只是没有来得及写个文档,导致后来工作中,经常要google,搜索其安装,使用的方法,刹时麻烦,今天总结一下:

1:mysql memcached UDF 其实就是通过libmemcached来使用memcache的一系列函数,通过这些函数,你能 对memcache进行get, set, cas, append, prepend, delete, increment, decrement objects操作,如果我们通过mysql trigger来使用这些函数,那么就能通过mysql更好的,更自动的管理memcache!

2:安装方法:

1)安装memcache

2)安装libmemcached

shell> cd libmemcached-0.35
shell> ./configure --with-memcached=/usr/local/bin/memcached
shell> make && make install
shell> echo "/usr/local/lib" >> /etc/ld.so.conf
shell> ldconfig

3)安装memcached_functions_mysql
shell> tar zxvf memcached_functions_mysql-0.9.tar.gz
shell> cd memcached_functions_mysql-0.9
shell> ./configure --with-mysql=/usr/local/mysql51/bin/mysql_config --with-libmemcached =/usr/local/
shell> make && make install

4)拷贝lib文件到mysql的plugin下面
shell> cp -R /usr/local/lib/libmemcached_functions_mysql.* /usr/local/mysql51/lib/mysql/plugin/

5)添加memcache UDF 函数

在mysql里执行 source install_functions.sql

这样我们就可以使用mysql memcached UDF 了,我们可以通过下面语句查看是否已经正常安装

1)查看mysql.func,有很多函数

mysql> select * from mysql.func;
+------------------------------+-----+---------------------------------+----------+
| name | ret | dl | type |
+------------------------------+-----+---------------------------------+----------+
| memc_add | 2 | libmemcached_functions_mysql.so | function |
| memc_add_by_key | 2 | libmemcached_functions_mysql.so | function |
| memc_servers_set | 2 | libmemcached_functions_mysql.so | function |

2)添加trigger,看是否向memcache里insert、update等

具体的语句,我们可以参照:

1)memcached_functions_mysql-0.9/sql 目录下的trigger_fun.sql

2)使用参照文档:http://dev.mysql.com/doc/refman/5.1/en/ha-memcached-interfaces-mysqludf.html


我们还必须注意以下几点:

1)mysql 编译时一定不要带'--with-mysqld-ldflags=-all-static' 这个参数,因为这样就限制了mysql 的动态安装功能了

2)使用时,要观察mysql.err日志,不知道是有意还是无意,udf更新memcache都会记录在err日志里,注意清理该日志,否则一下就爆满了

3)mysql 官网有这样一句话:

The list of servers used by the memcached UDFs is not persistent over restarts of the MySQL server. If the MySQL server fails, then you must re-set the list of memcached servers.

所以,当我们重启mysql,我们必须通过select memc_servers_set('192.168.0.1:11211,192.168.0.2:11211');语句重新注册memcache服务器!

转:http://hi.baidu.com/ytjwt/blog/item/5fc8303f226c542f71cf6c3c.html

阅读(1223) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~