原文地址:http://ultrasql.blog.51cto.com/9591438/1636374
|
1
2
3
|
/usr/local/bin/memcached
-d -m 256 -u memcached -l 192.168.11.51 -p 11211 -c 1024 -P
/var/run/memcached/memcached
.pid
/usr/local/bin/memcached
-d -m 256 -u memcached -l 192.168.11.52 -p 11211 -c 1024 -P
/var/run/memcached/memcached
.pid
/usr/local/bin/memcached
-d -m 256 -u memcached -l 192.168.11.68 -p 11211 -c 1024 -P
/var/run/memcached/memcached
.pid
|
|
1
2
3
4
5
6
|
cd
/usr/local
mkdir
magent
cd
magent
wget http:
//memagent
.googlecode.com
/files/magent-0
.5.
tar
.gz
(若无法直接访问,可先下载安装包后上传到服务器上)
tar
zxvf magent-0.5.
tar
.gz
|
|
1
2
3
|
#ifndef SSIZE_MAX
#define SSIZE_MAX 32767
#endif
|
|
1
2
3
4
|
ln
-s
/usr/lib64/libm
.so
/usr/lib64/libm
.a
/sbin/ldconfig
sed
-i
"s#LIBS = -levent#LIBS = -levent -lm#g"
Makefile
vi
Makefile
|
|
1
|
CFLAGS = -Wall -O2 -g
|
|
1
|
CFLAGS = -lrt -Wall -O2 -g
|
|
1
|
make
|
|
1
2
3
|
gcc -lrt -Wall -O2 -g -c -o magent.o magent.c
gcc -lrt -Wall -O2 -g -c -o ketama.o ketama.c
gcc -lrt -Wall -O2 -g -o magent magent.o ketama.o -levent –lm
|
|
1
|
.
/magent
–h
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
memcached agent v0.4 Build-Date: Apr 21 2015 09:21:10
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
|
|
1
2
|
/usr/local/magent/magent
-u root -n 4096 -l 192.168.11.51 -p 11200 -s 192.168.11.51:11211 -s 192.168.11.52:11211 -b 192.168.11.68:11211
/usr/local/magent/magent
-u root -n 4096 -l 192.168.11.52 -p 11200 -s 192.168.11.51:11211 -s 192.168.11.52:11211 -b 192.168.11.68:11211
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
[root@mongo01 ~]# telnet 192.168.11.51 11200
Trying 192.168.11.51...
Connected to 192.168.11.51.
Escape character is '^]'.
stats
memcached agent v0.4
matrix 1 -> 192.168.11.51:11211, pool size 0
matrix 2 -> 192.168.11.52:11211, pool size 0
END
set key1 0 0 1
1
STORED
set key2 0 0 2
22
STORED
set key3 0 0 3
333
STORED
set key4 0 0 4
4444
STORED
set key5 0 0 5
55555
STORED
quit
Connection closed by foreign host.
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
[root@mongo01 ~]# telnet 192.168.11.51 11211
Trying 192.168.11.51...
Connected to 192.168.11.51.
Escape character is '^]'.
get key1
END
get key2
VALUE key2 0 2
22
END
get key3
END
get key4
VALUE key4 0 4
4444
END
get key5
END
quit
Connection closed by foreign host.
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
[root@mongo02 ~]# telnet 192.168.11.52 11211
Trying 192.168.11.52...
Connected to 192.168.11.52.
Escape character is '^]'.
get key1
VALUE key1 0 1
1
END
get key2
END
get key3
VALUE key3 0 3
333
END
get key4
END
get key5
VALUE key5 0 5
55555
END
quit
Connection closed by foreign host.
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
[root@szlnmp01 ~]# telnet 192.168.11.68 11211
Trying 192.168.11.68...
Connected to 192.168.11.68.
Escape character is '^]'.
get key1
VALUE key1 0 1
1
END
get key2
VALUE key2 0 2
22
END
get key3
VALUE key3 0 3
333
END
get key4
VALUE key4 0 4
4444
END
get key5
VALUE key5 0 5
55555
END
quit
Connection closed by foreign host.
|
|
1
|
kill
`
cat
/var/run/memcached/memcached
.pid`
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
[root@mongo01 magent]# telnet 192.168.11.51 11200
Trying 192.168.11.51...
Connected to 192.168.11.51.
Escape character is '^]'.
get key1
VALUE key1 0 1
1
END
get key2
VALUE key2 0 2
22
END
get key3
VALUE key3 0 3
333
END
get key4
VALUE key4 0 4
4444
END
get key5
VALUE key5 0 5
55555
END
quit
Connection closed by foreign host.
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
[root@mongo01 ~]# telnet 192.168.11.51 11200
Trying 192.168.11.51...
Connected to 192.168.11.51.
Escape character is '^]'.
get key1
END
get key2
VALUE key2 0 2
22
END
get key3
END
get key4
VALUE key4 0 4
4444
END
get key5
END
quit
Connection closed by foreign host.
|
|
1
2
3
4
5
6
|
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
|
|
1
2
3
|
#ifndef SSIZE_MAX
#define SSIZE_MAX 32767
#endif
|
|
1
2
3
4
5
6
7
|
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
make: *** [magent] Error 1
|
|
1
2
|
ln
-s
/usr/lib64/libm
.so
/usr/lib64/libm
.a
vi
Makefile
|
|
1
2
3
4
5
6
7
|
gcc -Wall -g -O2 -I/usr/local/include -m64 -o magent magent.o ketama.o /usr/lib/libevent.a /usr/lib64/libm.a
/usr/lib/libevent.a(event.o): In function `gettime':
/tmp/libevent-2.0.22-stable/event.c:370: undefined reference to `clock_gettime'
/usr/lib/libevent.a(event.o): In function `detect_monotonic':
/tmp/libevent-2.0.22-stable/event.c:340: undefined reference to `clock_gettime'
collect2: ld returned 1 exit status
make: *** [magent] Error 1
|
|
1
|
vi
Makefile
|
|
1
|
CFLAGS = -Wall -g -O2 -I/usr/local/include $(M64)
|
|
1
|
CFLAGS = -lrt -Wall -g -O2 -I/usr/local/include $(M64)
|
|
1
|
gcc -lrt -Wall -g -O2 -I/usr/local/include -m64 -o magent magent.o ketama.o /usr/lib/libevent.a /usr/lib64/libm.a
|
本文介绍了Memcached集群的搭建过程及Magent缓存代理的使用方法,通过Magent实现Memcached集群的高可用性和数据同步,有效防止单点故障。

836

被折叠的 条评论
为什么被折叠?



