magent安装配置及错误解决

安装学习:http://zhumeng8337797.blog.163.com/blog/static/10076891420113431424757/

错误解决:http://ghostwolf.iteye.com/blog/774907

亲身操作

1. 上magent官网https://code.google.com/p/memagent/下载最新安装包,由于国内网络环境不稳定,在此上传一个供备用。写此blog时最新版 magent-0.6.tar.gz下载

2. 将包放到你要安装的目录,进入到该目录,执行以下安装命令(不要问博主这些命令的含义,因为博主也不知道)

 

[root@localhost magent]# tar zxvf magent-0.6.tar.gz 
[root@localhost magent]# /sbin/ldconfig
[root@localhost magent]# sed -i "s/LIBS = -levent/LIBS = -levent -lm/g" Makefile
[root@localhost magent]# make

#如遇到
gcc: /usr/lib64/libevent.a: No such file or directory
make: *** [magent] Error 1

#执行
[root@localhost magent]# ln -s /usr/lib/libevent.a /usr/lib64/libevent.a
[root@localhost magent]# make


#如遇到
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

#执行
[root@localhost magent]# gcc -lrt -Wall -g -O2 -I/usr/local/include -m64 -o magent magent.o ketama.o /usr/lib64/libevent.a /usr/lib64/libm.a

#测试是否安装好
[root@localhost magent]# ./magent
#如出现版本及帮助信息则表示ok了
memcached agent v0.6 Build-Date: Jul 18 2014 10:25:12
Usage:
  -h this message
  -u uid
  -g gid
  -p port, default is 11211. (0 to disable tcp support)
  -s ip:port, set memcached server ip and port
  -b ip:port, set backup memcached server ip and port
  -l ip, local bind ip address, default is 0.0.0.0
  -n number, set max connections, default is 4096
  -D don't go to background
  -k use ketama key allocation algorithm
  -f file, unix socket path to listen on. default is off
  -i number, set max keep alive connections for one memcached server, default is 20
  -v verbose

 

 

3. 配置启动命令

    

[root@localhost magent]# ps -ef|grep memcached
yxt       3571     1  0 Jul17 ?        00:00:00 /usr/local/memcached/bin/memcached -d -m 1024 -l 192.168.56.101 -p 9006 -u root
yxt       3578     1  0 Jul17 ?        00:00:00 /usr/local/memcached/bin/memcached -d -m 1024 -l 192.168.56.101 -p 9007 -u root
yxt       3585     1  0 Jul17 ?        00:00:00 /usr/local/memcached/bin/memcached -d -m 1024 -l 192.168.56.101 -p 9008 -u root

[root@localhost magent]# ./magent -u root -n 51200 -l 192.168.56.101 -p 19001 -s 192.168.56.101:9006 -s 192.168.56.101:9007 -b 192.168.56.101:9008
#表示最大连接51200个,对外ip与端口192.168.56.101:19001,真实服务的memcached为9006和9007,9008是备份机

 

 

 4. 测试

   正常情况

---------------------------------- telnet 192.168.56.101 19001
set ok 0 0 5
12345
STORED
get ok
VALUE ok 0 5
12345
END

------------------------------------telnet 192.168.56.101 9006
get ok
END


------------------------------------telnet 192.168.56.101 9007
get ok
VALUE ok 0 5
12345
END

------------------------------------telnet 192.168.56.101 9008
get ok
VALUE ok 0 5
12345
END

 

 

 kill掉9006和9007服务进程后,测试是否会自动切到备机, 是否能读到数据,

[root@localhost magent]# ps -ef|grep memcached
yxt       3585     1  0 Jul17 ?        00:00:00 /usr/local/memcached/bin/memcached -d -m 1024 -l 192.168.56.101 -p 9008 -u root

#9006和9007断开后,进19001还可以取到数据
-------------------------------------telnet 192.168.56.101 19001
get ok
VALUE ok 0 5
12345
END

#直连9008,放入只有9008有的数据
-------------------------------------telnet 192.168.56.101 9008
set bakOk 0 0 5
backu
STORED

#再连19001负载入口,看是否可以取到只有9008的数据
-------------------------------------telnet 192.168.56.101 9006
get bakOk
VALUE bakOk 0 5
backu
END

 可以读到数据,表示自动切换到备机成功

 

   

6. 总结,其实memcached也可以在客户端很方便的配置多个进行负载均衡,但也可能要改客户端代码,而现在这种magent方式,应对应用中memcached的使用并不规范的情况下,可以完全透明的集群,不用改应用代码,另外就是有备份机的机制,目前测试功能是通过了,有待生产环境验证。

 

你可能感兴趣的:(cache)