magent编译安装及常见错误(来着csdn)

安装magent到/usr/local/下

cd /usr/local

mkdir magent

cd magent/

wget http://memagent.googlecode.com/files/magent-0.6.tar.gz

tar zxvf magent-0.6.tar.gz

/sbin/ldconfig

sed -i “s#LIBS = -levent#LIBS = -levent -lm#g” Makefile

make

错误1:

gcc -lrt -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

错误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

/usr/lib64/libevent.a(event.o): In function `gettime’:

(.text+0×449): undefined reference to `clock_gettime’

/usr/lib64/libevent.a(event.o): In function `event_base_new’:

(.text+0x72a): undefined reference to `clock_gettime’

collect2: ld returned 1 exit status

make: *** [magent] Error 1

解决办法

vim Makefile

 

CFLAGS = -Wall -g -O2 -I/usr/local/include $(M64)

改为:

CFLAGS = -lrt -Wall -g -O2 -I/usr/local/include $(M64)


错误3:centos 6

[root@test magent]# make

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/libm.a:没有那个文件或目录

make: *** [magent] 错误 1

解决办法

ln -s /usr/lib64/libm.so /usr/lib64/libm.a

注:有可能还会报错 gcc: /usr/lib64/libevent.a: 没有那个文件或目录

如果有,可执行

vi Makefile

找到 LIBS = /usr/lib64/libevent.a /usr/lib64/libm.a

修改 LIBS = /usr/libevent 的安装路径/libevent.a /usr/lib64/libm.a

例: LIBS = /usr/lib/libevent.a /usr/lib64/libm.a

查看magent是否安装成功

cd usr/bin/magent ./magent

please provide -s “ip:port” argument

 

memcached agent v0.6 Build-Date: Oct 15 2012 16:12:30

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