{"id":139359,"date":"2019-03-21T08:15:07","date_gmt":"2019-03-21T00:15:07","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=139359"},"modified":"2019-03-12T09:16:47","modified_gmt":"2019-03-12T01:16:47","slug":"twemproxy-install-use","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/twemproxy-install-use.html","title":{"rendered":"\u5b89\u88c5\u4e0e\u914d\u7f6eTwemproxy\u4ee3\u7406\u670d\u52a1\u5668"},"content":{"rendered":"

\u9996\u5148\u9700\u8981\u5b89\u88c5autoconf\u3001automake\u3001libtool\u5de5\u5177\uff0c\u6bd4\u5982ubuntu\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u5b89\u88c5<\/p>\n

\r\nyum install autoconf automake  \r\nyum install libtool  \r\n<\/pre>\n
\u4e0b\u8f7dTwemproxy\u5e76\u5b89\u88c5<\/strong><\/span><\/div>\n
\r\ncd \/usr\/servers  \r\nwget https:\/\/github.com\/twitter\/twemproxy\/archive\/v0.4.0.tar.gz  \r\ntar -xvf v0.4.0.tar.gz    \r\ncd twemproxy-0.4.0\/  \r\nautoreconf -fvi  \r\n.\/configure && make\r\n<\/pre>\n

\u6b64\u5904\u6839\u636e\u8981\u6ce8\u610f\uff0c\u5982\u4e0a\u5b89\u88c5\u65b9\u5f0f\u5728\u6709\u4e9b\u670d\u52a1\u5668\u4e0a\u53ef\u80fd\u5728\u5927\u91cf\u5982mset\u65f6\u53ef\u80fd\u5bfc\u81f4Twemproxy\u5d29\u6e83\uff0c\u9700\u8981\u4f7f\u7528\u5982 CFLAGS=\u201d-O1\u2033 .\/configure && make\u6216CFLAGS=\u201d-O3 -fno-strict-aliasing\u201d .\/configure && make\u5b89\u88c5\u3002<\/p>\n

\u914d\u7f6e<\/strong><\/span><\/div>\n
\r\nvim \/usr\/servers\/twemproxy-0.4.0\/conf\/nutcracker.yml\r\n\r\nserver1:  \r\n  listen: 127.0.0.1:1111  \r\n  hash: fnv1a_64  \r\n  distribution: ketama  \r\n  redis: true  \r\n  servers:  \r\n   - 127.0.0.1:6379:1 \r\n<\/pre>\n
\u542f\u52a8Twemproxy\u4ee3\u7406<\/strong><\/span><\/div>\n
\r\n\/usr\/servers\/twemproxy-0.4.0\/src\/nutcracker  -d -c \/usr\/servers\/twemproxy-0.4.0\/conf\/nutcracker.yml\r\n<\/pre>\n

-d\u6307\u5b9a\u540e\u53f0\u542f\u52a8 -c\u6307\u5b9a\u914d\u7f6e\u6587\u4ef6\uff1b\u6b64\u5904\u6211\u4eec\u6307\u5b9a\u4e86\u4ee3\u7406\u7aef\u53e3\u4e3a1111<\/p>\n

\u67e5\u770b\u662f\u5426\u542f\u52a8\u6210\u529f<\/strong><\/span><\/div>\n
\r\nps -aux | grep nutcracker\r\n<\/pre>\n
\u8fdb\u5165Redis\u5ba2\u6237\u7aef<\/strong><\/span><\/div>\n
\r\n\/usr\/servers\/redis-2.8.19\/src\/redis-cli  -p 1111\r\n<\/pre>\n
\u6267\u884c\u5982\u4e0b\u547d\u4ee4<\/strong><\/span><\/div>\n
\r\n127.0.0.1:1111> set i 1  \r\nOK  \r\n127.0.0.1:1111> get i  \r\n\"1\"\r\n<\/pre>\n
\u8bbe\u7f6e<\/strong><\/div>\n
\u57fa\u672c\u914d\u7f6e<\/strong><\/span><\/div>\n

\u5176\u4f7f\u7528YML\u8bed\u6cd5\uff0c\u5982:<\/p>\n

\r\nserver1:  \r\n  listen: 127.0.0.1:1111  \r\n  hash: fnv1a_64  \r\n  distribution: ketama  \r\n  timeout:1000  \r\n  redis: true  \r\n  servers:  \r\n   - 127.0.0.1:6660:1  \r\n   - 127.0.0.1:6661:1  \r\n\r\nserver1\uff1a\u662f\u7ed9\u5f53\u524d\u5206\u7247\u914d\u7f6e\u8d77\u7684\u540d\u5b57\uff0c\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\u53ef\u4ee5\u6709\u591a\u4e2a\u5206\u7247\u914d\u7f6e\uff1b\r\nlisten \uff1a \u76d1\u542c\u7684ip\u548c\u7aef\u53e3\uff1b\r\nhash\uff1a\u6563\u5217\u7b97\u6cd5\uff1b\r\ndistribution\uff1a\u5206\u7247\u7b97\u6cd5\uff0c\u6bd4\u5982\u4e00\u81f4\u6027Hash\/\u53d6\u6a21\uff1b\r\ntimeout\uff1a\u8fde\u63a5\u540e\u7aefRedis\u6216\u63a5\u6536\u54cd\u5e94\u7684\u8d85\u65f6\u65f6\u95f4\uff1b\r\nredis\uff1a\u662f\u5426\u662fredis\u4ee3\u7406\uff0c\u5982\u679c\u662ffalse\u5219\u662fmemcached\u4ee3\u7406\uff1b\r\nservers\uff1a\u4ee3\u7406\u7684\u670d\u52a1\u5668\u5217\u8868\uff0c\u8be5\u5217\u8868\u4f1a\u4f7f\u7528distribution\u914d\u7f6e\u7684\u5206\u7247\u7b97\u6cd5\u8fdb\u884c\u5206\u7247\uff1b\r\n<\/pre>\n
\u5206\u7247\u7b97\u6cd5<\/strong><\/span><\/div>\n
\r\n  #hash\u7b97\u6cd5\uff1a\r\n    one_at_a_time\r\n    md5\r\n    crc16\r\n    crc32 (crc32 implementation compatible with libmemcached)\r\n    crc32a (correct crc32 implementation as per the spec)\r\n    fnv1_64\r\n    fnv1a_64\r\n    fnv1_32\r\n    fnv1a_32\r\n    hsieh\r\n    murmur\r\n    jenkins\r\n  #\u5206\u7247\u7b97\u6cd5\uff1a\r\n    ketama(\u4e00\u81f4\u6027Hash\u7b97\u6cd5)\r\n    modula(\u53d6\u6a21)\r\n    random(\u968f\u673a\u7b97\u6cd5)\r\n<\/pre>\n
\u670d\u52a1\u5668\u5217\u8868<\/strong><\/span><\/div>\n
\r\n   servers:\r\n     - ip:port:weight alias\r\n\u5982\r\n  servers:\r\n   - 127.0.0.1:6660:1\r\n   - 127.0.0.1:6661:1\r\n\u6216\u8005\r\n  servers:\r\n   - 127.0.0.1:6660:1 server1\r\n\r\n   - 127.0.0.1:6661:1 server2\r\n<\/pre>\n
HashTag<\/strong><\/span><\/div>\n

\u6bd4\u5982\u4e00\u4e2a\u5546\u54c1\u6709\uff1a\u5546\u54c1\u57fa\u672c\u4fe1\u606f(p:id:)\u3001\u5546\u54c1\u4ecb\u7ecd(d:id:)\u3001\u989c\u8272\u5c3a\u7801(c:id:)\u7b49\uff0c\u5047\u8bbe\u6211\u4eec\u5b58\u50a8\u65f6\u4e0d\u91c7\u7528HashTag\u5c06\u4f1a\u5bfc\u81f4\u8fd9\u4e9b\u6570\u636e\u4e0d\u4f1a\u5b58\u50a8\u5230\u4e00\u4e2a\u5206\u7247\uff0c\u800c\u662f\u5206\u6563\u5230\u591a\u4e2a\u5206\u7247\uff0c\u8fd9\u6837\u83b7\u53d6\u65f6\u5c06\u9700\u8981\u4ece\u591a\u4e2a\u5206\u7247\u83b7\u53d6\u6570\u636e\u8fdb\u884c\u5408\u5e76\uff0c\u65e0\u6cd5\u8fdb\u884cmget\uff1b\u90a3\u4e48\u5982\u679c\u6709\u4e86HashTag\uff0c\u90a3\u4e48\u53ef\u4ee5\u4f7f\u7528\u201c::\u201d\u4e2d\u95f4\u7684\u6570\u636e\u505a\u5206\u7247\u903b\u8f91\uff0c\u8fd9\u6837id\u4e00\u6837\u7684\u5c06\u4f1a\u5206\u5230\u4e00\u4e2a\u5206\u7247\u3002<\/p>\n

nutcracker.yml\u914d\u7f6e\u5982\u4e0b:<\/p>\n

\r\nserver1:  \r\n  listen: 127.0.0.1:1111  \r\n  hash: fnv1a_64  \r\n  distribution: ketama  \r\n  redis: true  \r\n  hash_tag: \"::\"  \r\n  servers:  \r\n   - 127.0.0.1:6660:1 server1  \r\n   - 127.0.0.1:6661:1 server2  \r\n<\/pre>\n
\u8fde\u63a5Twemproxy<\/strong><\/span><\/div>\n
\r\n\/usr\/servers\/redis-2.8.19\/src\/redis-cli  -p 1111  \r\n<\/pre>\n

\u5728\u6211\u7684\u670d\u52a1\u5668\u4e0a\u53ef\u4ee5\u8fde\u63a56660\u7aef\u53e3<\/p>\n

\r\n\/usr\/servers\/redis-2.8.19\/src\/redis-cli  -p 6660  \r\n127.0.0.1:6660> get p:12:   \r\n\"1\"  \r\n127.0.0.1:6660> get d:12:   \r\n\"1\"  \r\n127.0.0.1:6660> get c:12:   \r\n\"1\"  \r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

\u9996\u5148\u9700\u8981\u5b89\u88c5autoconf\u3001automake\u3001libtool\u5de5\u5177\uff0c\u6bd4\u5982ubuntu\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u5b89\u88c5 yu […]<\/p>\n","protected":false},"author":1479,"featured_media":97213,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-139359","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/139359","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=139359"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/139359\/revisions"}],"predecessor-version":[{"id":139461,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/139359\/revisions\/139461"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/97213"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=139359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=139359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=139359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}