./magent -u root -n 4096 -l 192.168.0.107 -p 12000 -s 192.168.0.107:11212 -s 192.168.0.107:11213 -b 192.168.1.118:11214
其中,12000是magent的端口,11212、11213是memcached的主进程,11214是备用进程。
6.用windows的telnet测试,测试流程如下:
[iyunv@localhost ~]# telnet 192.168.1.118 12000
Trying 192.168.1.118...
Connected to 192.168.1.118 (192.168.1.118).
Escape character is '^]'.
stats
memcached agent v0.6
matrix 1 -> 192.168.1.118:11212, pool size 0
matrix 2 -> 192.168.1.118:11213, pool size 1
END
set key1 0 0 5
hello
STORED
set key2 0 0 5
world
STORED
quit
Connection closed by foreign host.
[iyunv@localhost ~]# telnet 192.168.1.118 11212
Trying 192.168.1.118...
Connected to 192.168.1.118 (192.168.1.118).
Escape character is '^]'.
get key1
END
get key2
VALUE key2 0 5
world
END
quit
Connection closed by foreign host.
[iyunv@localhost ~]# telnet 192.168.1.118 11213
Trying 192.168.1.118...
Connected to 192.168.1.118 (192.168.1.118).
Escape character is '^]'.
get key1
VALUE key1 0 5
hello
END
get key2
END
quit
Connection closed by foreign host.
[iyunv@localhost ~]# telnet 192.168.1.118 11214
Trying 192.168.1.118...
Connected to 192.168.1.118 (192.168.1.118).
Escape character is '^]'.
get key1
VALUE key1 0 5
hello
END
get key2
VALUE key2 0 5
world
END
quit
Connection closed by foreign host.
模拟11212、11213端口的memcache死掉
[iyunv@localhost ~]# ps -ef | grep memcached
root 5126 1 0 19:14 ? 00:00:00 memcached -m 1 -u root -d -l 192.168.1.118 -p 11212
root 5134 1 0 19:14 ? 00:00:00 memcached -m 1 -u root -d -l 192.168.1.118 -p 11213
root 5142 1 0 19:14 ? 00:00:00 memcached -m 1 -u root -d -l 192.168.1.118 -p 11214
root 5976 5526 0 20:11 pts/1 00:00:00 grep memcached
[iyunv@localhost ~]# kill -9 5126
[iyunv@localhost ~]# kill -9 5134
[iyunv@localhost ~]# telnet 192.168.1.118 12000
Trying 192.168.1.118...
Connected to 192.168.1.118 (192.168.1.118).
Escape character is '^]'.
get key1
VALUE key1 0 5
hello
END
get key2
VALUE key2 0 5
world
END
quit
Connection closed by foreign host.
模拟11212、11213端口的memcache重启复活
[iyunv@localhost ~]# memcached -m 1 -u root -d -l 192.168.1.118 -p 11212
[iyunv@localhost ~]# memcached -m 1 -u root -d -l 192.168.1.118 -p 11213
[iyunv@localhost ~]# telnet 192.168.1.118 12000
Trying 192.168.1.118...
Connected to 192.168.1.118 (192.168.1.118).
Escape character is '^]'.
get key1
END
get key2
END
quit
Connection closed by foreign host.
7. magent的语法较难理解,可以参考如下语法:
Storage Commands
Parameters : <key> : the key of the data stored <flags> : 32-bit unsigned integer that the server store with the data (provided by the user), and return along the data when the item is retrieved <exptime> : expiration time in seconds, 0 mean no delay, if exptime is superior to 30 day, Memcached will use it as a UNIX timestamps for expiration <bytes> : number of bytes in the data block <cas unique> : unique 64-bit value of an existing entry (retrieved with gets command) to use with cas command [noreply] : optional parameter that inform the server to not send the reply
These commands can return : STORED to indicate success NOT_STORED indicate that the data was not stored because condition for "add" or "replace" command wasn't met, or the item is in a delete queue EXISTS indicate that the item you are trying to store with "cas" command has been modified since last fetch NOT_FOUND indicate that the item did not exist or has been deleted
Set
Store key/value pair in Memcached
Telnet command : set <key> <flags> <exptime> <bytes> [noreply]\r\n<value>\r\n