memcached的安装
安装libevent
[root@test ~]# wget https://cloud.github.com/downloads/libevent/libevent/libevent-2.0.19-stable.tar.gz [root@test ~]# tar zxvf libevent-2.0.19-stable.tar.gz [root@test ~]# cd libevent-2.0.19-stable [root@test libevent-2.0.19-stable]# ./configure --prefix=/usr/ [root@test libevent-2.0.19-stable]# make && make install
2.安装memcached
[root@test ~]# wget http://www.memcached.org/files/memcached-1.4.22.tar.gz [root@test ~]# tar zxvf memcached-1.4.22.tar.gz [root@test memcached-1.4.22]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/ [root@test memcached-1.4.22]# make && make install
magent的安装
magent是一款开源的Memcached代理服务器软件,其项目网址为:
[root@test ~]# tar zxvf magent-0.6.tar.gz [root@test ~]# mkdir /usr/local/magent [root@test magent]# tar zxvf magent-0.6.tar.gz ketama.c ketama.h magent.c Makefile [root@test 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 解决方法: [root@test magent]# vim ketama.h #ifndef SSIZE_MAX #define SSIZE_MAX 32767 #endif #ifndef _KETAMA_H #define _KETAMA_H struct dot { unsigned int point; int srvid; }; struct ketama { unsigned int numpoints; struct dot *dot; int count; char **name; int *weight; int totalweight; }; int create_ketama(struct ketama *, int); void free_ketama(struct ketama *); int get_server(struct ketama *, const char *); #endif [root@test 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 gcc: /usr/lib64/libevent.a: No such file or directory gcc: /usr/lib64/libm.a: No such file or directory make: *** [magent] Error 1 解决方案: [root@test magent]# ln -svf /usr/lib/libevent* /usr/lib64/ `/usr/lib64/libevent-2.0.so.5' -> `/usr/lib/libevent-2.0.so.5' `/usr/lib64/libevent-2.0.so.5.1.7' -> `/usr/lib/libevent-2.0.so.5.1.7' `/usr/lib64/libevent.a' -> `/usr/lib/libevent.a' `/usr/lib64/libevent_core-2.0.so.5' -> `/usr/lib/libevent_core-2.0.so.5' `/usr/lib64/libevent_core-2.0.so.5.1.7' -> `/usr/lib/libevent_core-2.0.so.5.1.7' `/usr/lib64/libevent_core.a' -> `/usr/lib/libevent_core.a' `/usr/lib64/libevent_core.la' -> `/usr/lib/libevent_core.la' `/usr/lib64/libevent_core.so' -> `/usr/lib/libevent_core.so' `/usr/lib64/libevent_extra-2.0.so.5' -> `/usr/lib/libevent_extra-2.0.so.5' `/usr/lib64/libevent_extra-2.0.so.5.1.7' -> `/usr/lib/libevent_extra-2.0.so.5.1.7' `/usr/lib64/libevent_extra.a' -> `/usr/lib/libevent_extra.a' `/usr/lib64/libevent_extra.la' -> `/usr/lib/libevent_extra.la' `/usr/lib64/libevent_extra.so' -> `/usr/lib/libevent_extra.so' `/usr/lib64/libevent.la' -> `/usr/lib/libevent.la' `/usr/lib64/libevent_pthreads-2.0.so.5' -> `/usr/lib/libevent_pthreads-2.0.so.5' `/usr/lib64/libevent_pthreads-2.0.so.5.1.7' -> `/usr/lib/libevent_pthreads-2.0.so.5.1.7' `/usr/lib64/libevent_pthreads.a' -> `/usr/lib/libevent_pthreads.a' `/usr/lib64/libevent_pthreads.la' -> `/usr/lib/libevent_pthreads.la' `/usr/lib64/libevent_pthreads.so' -> `/usr/lib/libevent_pthreads.so' `/usr/lib64/libevent.so' -> `/usr/lib/libevent.so' [root@test 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 gcc: /usr/lib64/libm.a: No such file or directory make: *** [magent] Error 1 解决方案: 如果是64bit的系统则不会在/usr/lib64/libm.a 生成,如果是32bit即会有 [root@test magent]# yum install glibc glibc-devel [root@test magent]# cp /usr/lib64/libm.so /usr/lib64/libm.a [root@test 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': /usr/local/src/libevent-2.0.19-stable/event.c:366: undefined reference to `clock_gettime' /usr/lib64/libevent.a(event.o): In function `detect_monotonic': /usr/local/src/libevent-2.0.19-stable/event.c:336: undefined reference to `clock_gettime' collect2: ld returned 1 exit status make: *** [magent] Error 1 解决方案: [root@test magent]# vim Makefile CFLAGS = -Wall -g -O2 -I/usr/local/include $(M64) 改为: CFLAGS = -lrt -Wall -g -O2 -I/usr/local/include $(M64) [root@test magent]# make 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@test magent]# ls 终于成功了- -! ketama.c ketama.h ketama.o magent magent-0.6.tar.gz magent.c magent.o Makefile [root@test magent]# cp magent /bin/
启动memcached
memecached默认不允许root用户启动进程,需要为memcached创建一个用户
[root@test src]# useradd -s /sbin/nologin memcached [root@test ~]# memcached -c 10240 -l 192.168.40.144 -p 11215 -u memcached -m 10 -n 40 -f 2 -d [root@test ~]# memcached -c 10240 -l 192.168.40.144 -p 11216 -u memcached -m 10 -n 40 -f 2 -d [root@test ~]# ps -ef | grep memcached | grep -v "grep" 501 11784 1 0 01:34 ? 00:00:00 memcached -c 10240 -l 192.168.40.144 -p 11215 -u memcached -m 10 -n 40 -f 2 -d 501 11791 1 0 01:35 ? 00:00:00 memcached -c 10240 -l 192.168.40.144 -p 11216 -u memcached -m 10 -n 40 -f 2 -d
启用magent管理memcached
[root@test ~]# magent -u root -n 51200 -l 192.168.40.144 -p 12001 -s 192.168.40.144:11215 -b 192.168.40.144:11216
# -S为主服务器 -b为备服务器