memcached+magent组成高可用
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了memcached+magent组成高可用相关的知识,希望对你有一定的参考价值。
简介:
使用magent架设memcached高可用,当主的挂掉以后,备机可以继续使用。
magent
|
----------------------------------------
| | |
memcached1 memcached2 memcached3
(master) (master) (backup)
一 安装memcached
下载下面安装包
libevent-2.0.21-stable.tar.gz
memcached-1.4.32.tar.gz
magent-0.5.tar.gz
安装libevent
tar –xzvf libevent-2.0.21-stable.tar.gz cd libevent-2.0.21-stable ./configure –prefix=/usr/local/libevent make make install
|
安装memcached
tar –xzvf memcached-1.4.32 cd memcached-1.4.32 ./configure --prefix=/opt/memcached --with-libevent=/usr/local/libevent/ make make install
|
magent安装
下载安装包文件magent-0.5.tar.gz
解压tar –xzvf magent-0.5.tar.gz
make #执行编译安装
把编译好的magent拷贝到/opt/memcached/bin/ 目录下
安装报错解决方案
[[email protected] magent]# make gcc -Wall -g -O2 -I/usr/local/include -m64 -c -o magent.o magent.c magent.c:71:19: error: event.h: No such file or directory magent.c:130: error: field ‘ev’ has incomplete type magent.c:161: error: field ‘ev’ has incomplete type magent.c: In function ‘server_free’: magent.c:494: warning: implicit declaration of function ‘event_del’ magent.c: In function ‘pool_server_handler’: magent.c:514: error: ‘EV_READ’ undeclared (first use in this function) magent.c:514: error: (Each undeclared identifier is reported only once
# 解决办法,检查下libevent安装路径,如果自定义安装了,拷贝下路径库。 ln -s /usr/lib/libevent* /usr/lib64/
[[email protected] magent]# make gcc -Wall -g -O2 -I/usr/local/include -m64 -c -o magent.o magent.c magent.c: In function ‘writev_list’: magent.c:729: error: ‘SSIZE_MAX’ undeclared (first use in this function) magent.c:729: error: (Each undeclared identifier is reported only once magent.c:729: error: for each function it appears in.) make: *** [magent.o] Error 1
解决方法: vi ./ketama.h #在开头加入 #ifndef SSIZE_MAX #define SSIZE_MAX 32767 #endif
#libm.a不存在的时候,需要拷贝下面so,如果没有,需要安装glibc glibc-devel cp /usr/lib64/libm.so /usr/lib64/libm.a
gcc -Wall -g -O2 -I/usr/local/include -m64 -o magent magent.o ketama.o /usr/lib64/libevent.a /usr/lib64/libm.a /usr/lib64/libevent.a(event.o): In function `gettime‘: /root/libevent-2.0.21-stable/event.c:370: undefined reference to `clock_gettime‘ /usr/lib64/libevent.a(event.o): In function `detect_monotonic‘: /root/libevent-2.0.21-stable/event.c:340: undefined reference to `clock_gettime‘ collect2: ld returned 1 exit status make: *** [magent] Error 1
解决方法:
vi Makefile CFLAGS = -Wall -g -O2 -I/usr/local/include $(M64) 改为: CFLAGS = -lrt -Wall -g -O2 -I/usr/local/include $(M64)
[[email protected] magent5]# make gcc -lrt -Wall -g -O2 -I/usr/local/include -o magent magent.o ketama.o -levent ketama.o: In function `create_ketama‘: /root/magent5/ketama.c:399: undefined reference to `floorf‘ collect2: ld returned 1 exit status make: *** [magent] Error 1
解决办法: vi Makefile
LIBS = -levent –lm
|
三 启动
启动memcached
/opt/memcached/bin/memcached -d -u root -c 10000 -m 8192 192.168.100.22 -p 11211
|
启动magent
/opt/memcached/bin/magent -u root -n 102400 -l 192.168.100.24 -p 12001 -s 192.168.100.22:192.168.100.23:11211 -b 192.168.100.24:11211 |
四 测试
4.1 模拟一台主的坏掉
设置数据:
kill掉一台主
验证数据正常:
4.2 模拟第二台主机也down
验证数据,读写都正常。
4.3 模拟三台都宕机
magent无法读取数据
4.4 模拟主机down掉一台,启动主机,查看数据是否丢失
测试检查丢失了一条数据。
所以当主down以后,不要立即启动主,需要非工作时间处理。
本文出自 “痞子厨子戏子” 博客,请务必保留此出处http://chenwei.blog.51cto.com/32183/1869124
以上是关于memcached+magent组成高可用的主要内容,如果未能解决你的问题,请参考以下文章
Magent+keepalived+Memcached缓存高可用群集
Memcached+keepalived+magent实现主从复制和高可用