首页 > 代码库 > memcached主备安装
memcached主备安装
一、软件下载
wget http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz
wget http://memagent.googlecode.com/files/magent-0.6.tar.gz
wget http://monkey.org/~provos/libevent-1.4.9-stable.tar.gz
二、安装libevent-1.4.9-stable.tar.gz
tar zxvf libevent-2.0.13-stable.tar.gz cd libevent-2.0.13-stable ./configure --with-libevent=/usr make make install |
三、安装memcached
tar zxvf memcached-1.4.13.tar.gz cd memcached-1.4.13 ./configure --with-libevent=/usr make make install |
四、安装magent
tar zxvf magent-0.6.tar.gz make cp magent /usr/bin/ |
报错1: 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 解决办法: [root@centos6 memcached]# vi ketama.h #在开头加入 #ifndef SSIZE_MAX #define SSIZE_MAX 32767 #endif 报错2: gcc -Wall -g -O2 -I/usr/local/include -m64 -c -o magent.o magent.c gcc -Wall -g -O2 -I/usr/local/include -m64 -c -o ketama.o ketama.c gcc -Wall -g -O2 -I/usr/local/include -m64 -o magent magent.o ketama.o /usr/lib64/libevent.a /usr/lib64/libm.a gcc: /usr/lib64/libevent.a: No such file or directory gcc: /usr/lib64/libm.a: No such file or directory 解决办法: [root@centos6 memcached]# ln -s /usr/lib/libevent* /usr/lib64/ [root@centos6 memcached]# make 报错3: gcc -Wall -g -O2 -I/usr/local/include -m64 -o magent magent.o ketama.o /usr/lib64/libevent.a /usr/lib64/libm.a gcc: /usr/lib64/libm.a: No such file or directory make: *** [magent] Error 1 解决办法: yum install glibc glibc-devel 如果是64bit的系统则不会在/usr/lib64/libm.a 生成,如果是32bit即会有。 [root@centos6 memcached]# cp /usr/lib64/libm.so /usr/lib64/libm.a 报错4: 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 `detect_monotonic‘: event.c:(.text+0xc79): undefined reference to `clock_gettime‘ /usr/lib64/libevent.a(event.o): In function `gettime‘: event.c:(.text+0xd60): undefined reference to `clock_gettime‘ collect2: ld returned 1 exit status make: *** [magent] Error 1 解决办法: [root@centos6 memcached]# vi Makefile CFLAGS = -Wall -g -O2 -I/usr/local/include $(M64) 改为: CFLAGS = -lrt -Wall -g -O2 -I/usr/local/include $(M64) |
五、启动服务
5.1memcached启动
memcached启动参数描述: -d :启动一个守护进程, -m:分配给Memcache使用的内存数量,单位是MB,默认是64MB, -u :运行Memcache的用户 -l :监听的服务器IP地址 -p :设置Memcache监听的端口,默认是11211 注:-p(p为小写) -c :设置最大并发连接数,默认是1024 -P :设置保存Memcache的pid文件 注:-P(P为大写) 如果要结束Memcache进程,执行:kill cat pid文件路径 |
memcached -m 10 -u root -d -l 0.0.0.0 -p 11211 -vv >> /tmp/memcached.log 2>&1 netstat -antp |
5.2magent启动
magent -u root -n 51200 -l 192.168.35.56 -p 12000 -s 127.0.0.1:11211 -b 127.0.0.1:11212 |
分别在127.0.0.1机器的11211,11212端口启动2个Memcached进程,在12000端口开启magent代理程序;
11211主Memcached,11212为备份Memcached;
六、验证测试
[root@demoServer ~]# telnet 192.168.35.56 12000 Trying 192.168.35.56... Connected to 192.168.35.56. Escape character is ‘^]‘. stats memcached agent v0.6 matrix 1 -> 127.0.0.1:11211, pool size 0 END |
# telnet 192.168.1.219 12000 Trying 1192.168.1.219... Connected to 192.168.1。219. Escape character is ‘^]‘. stats memcached agent v0.4 matrix 1 -> 192.168.1.219:11211, pool size 0 matrix 2 -> 192.168.1.219:11212, pool size 0 END set key1 0 0 5 reesun STORED set key2 0 0 6 reesun1 STORED quit Connection closed by foreign host. # telnet 192.168.1.219 11211 Trying 192.168.1.219... Connected to 192.168.1.219. Escape character is ‘^]‘. get key1 END get key2 VALUE key2 0 6 reesun1 END quit Connection closed by foreign host. # telnet 192.168.1.219 11212 Trying 192.168.1.219... Connected to 1192.168.1.219. Escape character is ‘^]‘. get key1 VALUE key1 0 5 reesun END get key2 END quit Connection closed by foreign host. # telnet 192.168.1.219 11213 Trying 192.168.1.219... Connected to 1192.168.1.219. Escape character is ‘^]‘. get key1 VALUE key1 0 5 reesun END get key2 VALUE key2 0 6 reesun1 END quit Connection closed by foreign host |
本文出自 “向前看” 博客,请务必保留此出处http://ladder.blog.51cto.com/8847731/1567588
memcached主备安装
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。