{"id":136070,"date":"2019-02-19T09:43:59","date_gmt":"2019-02-19T01:43:59","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=136070"},"modified":"2019-02-18T09:46:24","modified_gmt":"2019-02-18T01:46:24","slug":"twemproxy-redis-node","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/twemproxy-redis-node.html","title":{"rendered":"Twemproxy\u589e\u52a0\u6216\u5254\u9664Redis\u8282\u70b9\u540e\u5bf9\u6570\u636e\u6709\u4f55\u5f71\u54cd"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u672c\u7bc7\u6587\u7ae0\uff0cTwemproxy\u589e\u52a0\u6216\u5254\u9664Redis\u8282\u70b9\u540e\u5bf9\u6570\u636e\u7684\u5f71\u54cd\u662f\u63a5\u7740\u201d\u901a\u8fc7Twemproxy\u4ee3\u7406Redis\u6570\u636e\u5206\u7247\u65b9\u6848\u201c\u8fd9\u7bc7\u6587\u7ae0\u5199\u7684\u3002\u6700\u597d\u8fd8\u8981\u61c2\u4e00\u81f4\u6027\u54c8\u5e0c\uff08ketama\uff09\u7684\u539f\u7406\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u4e0a\u4e00\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u914d\u7f6e\u4e86\u4e00\u4e2atwemproxy\u8282\u70b9\uff0c\u540e\u9762\u8ddf\u7740\u4e24\u4e2aRedis\u8282\u70b9\u505a\u7684\u7b80\u5355\u6d4b\u8bd5\u3002\u4e0b\u9762\u6211\u4eec\u6a21\u62df\u5728Redis\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u65b0\u589e\u4e00\u4e2a\u8282\u70b9\uff0c\u770b\u4e00\u770b\u4f1a\u4e22\u5931Key\u7684\u6bd4\u4f8b\u662f\u591a\u5c11\u3002\u81f3\u4e8e\u4e3a\u4ec0\u4e48\u4f1a\u4e22\u5931Key\u5462\uff1f\u6700\u7b80\u5355\u7684\u7406\u89e3\u5c31\u662f\u201c\u53d6\u6a21\u8fd0\u7b97\u201d\uff0c\u539f\u5148twemproxy\u662f\u5bf9\u4e24\u4e2aRedis\u8282\u70b9\u5bf9Key\u505a\u54c8\u5e0c\u540e\u5b58\u50a8\uff0c\u540c\u6837\u8bfb\u53d6\u6570\u636e\u7684\u65f6\u5019\u4e5f\u662f\u4f7f\u7528\u540c\u6837\u7684\u7b97\u6cd5\uff0c\u540c\u6837\u7684\u8282\u70b9\u6570\u505a\u8fd0\u7b97\uff0c\u6240\u4ee5\u53ef\u4ee5\u6b63\u786e\u62ff\u5230\u6bcf\u4e2aKey\u7684\u503c\u3002\u90a3\u4e48\u73b0\u5728\u65b0\u589e\u4e00\u4e2a\u8282\u70b9\u540e\uff0c\u5c31\u6210\u4e863\u4e2a\u8282\u70b9\u5bf9Key\u505a\u54c8\u5e0c\u8fd0\u7b97\u4e86\uff0c\u90a3\u4e48\u4f1a\u53d1\u751f\u4ec0\u4e48\u60c5\u51b5\u5462\uff1f\u539f\u5148\u5b58\u7684Key\u662f\u5bf92\u53d6\u6a21\uff0c\u4f46\u662f\u65b0\u589e\u4e00\u4e2a\u8282\u70b9\u540e\u53bb\u53d6Key\u65f6\u53d8\u6210\u4e86\u5bf93\u53d6\u6a21\u3002\u90a3\u4e48\u7ed3\u679c\u80af\u5b9a\u662f\u4e00\u5927\u6279Key\u65e0\u6cd5\u627e\u5230\u3002\u5f53\u7136\uff0c\u4e0a\u9762\u8bf4\u7684\u53ea\u662f\u5f88\u4e45\u4e4b\u524d\u4f7f\u7528\u7684\u65b9\u6cd5\uff0ctwemproxy\u4f7f\u7528\u7684\u662f\u4e00\u81f4\u6027\u54c8\u5e0c\uff0c\u8fd8\u662f\u90a3\u53e5\u8bdd\uff0c\u5bf9\u4e8e\u4e00\u81f4\u6027\u54c8\u5e0c\u5728memcached\u90e8\u5206\u6709\u8f83\u4e3a\u8be6\u7ec6\u7684\u4ecb\u7ecd\u4e86\uff0c\u6709\u5174\u8da3\u53ef\u4ee5\u770b\u770b\u3002<\/p>\n

\u4e0b\u9762\u6211\u4eec\u5c31\u5b9e\u9a8c\u770b\u770btwemproxy\u589e\u52a0\u6216\u5254\u9664\u8282\u70b9\u540e\u5bf9\u6570\u636e\u7684\u5f71\u54cd\u8303\u56f4\u6bd4\u4f8b\u662f\u591a\u5c11\u3002twemproxy\u548credis\u4e0a\u4e00\u7ae0\u8282\u5c31\u914d\u7f6e\u597d\u4e86\u3002<\/p>\n

\r\n[root@www ~]# ps aux | grep nut\r\nroot   13266  0.0  17916  2120 ?        Sl   16:22   0:00 \/etc\/twemproxy\/sbin\/nutcracker -c \r\n\/etc\/twemproxy\/conf\/nutcracker.yml -p \/var\/run\/nucracker.pid -o \/var\/log\/nutcracker.log -d\r\n<\/pre>\n
\r\n[root@www ~]# ps aux | grep redis\r\nroot   23092 0.0  36560  2300 ?    Ssl  12:17   0:14 \/usr\/local\/redis\/src\/redis-server 0.0.0.0:6547               \r\nroot   23112 0.0  36560  1580 ?    Ssl  12:17   0:15 \/usr\/local\/redis\/src\/redis-server 0.0.0.0:6546\r\n<\/pre>\n
\r\n[root@www ~]# netstat -nplt | grep -E \"(22122|6546|6547)\"\r\ntcp        0      0 0.0.0.0:6546     0.0.0.0:*         LISTEN      23112\/redis-server \r\ntcp        0      0 0.0.0.0:6547     0.0.0.0:*         LISTEN      23092\/redis-server \r\ntcp        0      0 0.0.0.0:22122    0.0.0.0:*         LISTEN      13266\/nutcracker\r\n<\/pre>\n

\u4e0b\u9762\u6211\u4eec\u5148\u6279\u91cf\u63d2\u51651000\u4e2aKey\uff0c\u5199\u4e2a\u6d4b\u8bd5\u811a\u672c\u8dd1\u4e00\u4e0b\u3002<\/p>\n

\r\n[root@www ~]# cat set.sh \r\n#!\/bin\/bash\r\n#\r\nfor i in `seq 1 1000`;do\r\n  redis-cli -p 22122 set \"key$i$i\" \"value$i\" \r\ndone\r\n<\/pre>\n

\u6267\u884c\u811a\u672c\uff0c\u7136\u540e\u5206\u522b\u53d66546\u548c6547\u4e24\u53f0\u4e3b\u673a\u4e0a\u770b\u770bKey\u7684\u5206\u5e03\u3002<\/p>\n

\r\n[root@www ~]# redis-cli -p 6546\r\n127.0.0.1:6546> KEYS *\r\n................\r\n448) \"key932932\"\r\n449) \"key109109\"\r\n450) \"key131131\"\r\n451) \"key271271\"\r\n<\/pre>\n
\r\n[root@www ~]# redis-cli -p 6547\r\n127.0.0.1:6547> KEYS *\r\n.................\r\n545) \"key245245\"\r\n546) \"key705705\"\r\n547) \"key455455\"\r\n548) \"key126126\"\r\n549) \"key251251\"\r\n<\/pre>\n

\u628atwemproxy\u65b0\u589e\u4e00\u4e2aRedis\u8282\u70b9\uff0c\u4e0b\u9762\u5148\u589e\u52a0\u4e00\u4e2aRedis\u8282\u70b9\u3002<\/p>\n

\r\n[root@www ~]# cat \/data\/redis-6548\/redis.conf \r\ndaemonize yes\r\npidfile \/var\/run\/redis\/redis-server.pid\r\nport 6548\r\nbind 0.0.0.0 \r\nloglevel notice\r\nlogfile \/var\/log\/redis\/redis-6548.log\r\n<\/pre>\n

\u7136\u540e\u628a\u8fd9\u4e2a\u8282\u70b9\uff08172.16.0.172:6548:1 redis03\uff09\u52a0\u5165twemproxy\u4e2d\u3002<\/p>\n

\r\n[root@www ~]# cat \/etc\/twemproxy\/conf\/nutcracker.yml\r\nredis-cluster:\r\n  listen: 0.0.0.0:22122\r\n  hash: fnv1a_64\r\n  distribution: ketama\r\n  timeout: 400\r\n  backlog: 65535\r\n  preconnect: true\r\n  redis: true\r\n  server_connections: 1\r\n  auto_eject_hosts: true\r\n  server_retry_timeout: 60000\r\n  server_failure_limit: 3\r\n  servers:\r\n    - 172.16.0.172:6546:1 redis01\r\n    - 172.16.0.172:6547:1 redis02\r\n    - 172.16.0.172:6548:1 redis03\r\n<\/pre>\n

\u91cd\u65b0\u542f\u52a8twemproxy\u548credis\u3002<\/p>\n

\r\n[root@www ~]# \/etc\/twemproxy\/sbin\/nutcracker -c \/etc\/twemproxy\/conf\/nutcracker.yml -p \/var\/run\/nucracker.pid -o \/var\/log\/nutcracker.log -d\r\n[root@www ~]# \/usr\/local\/redis\/src\/redis-server \/data\/redis-6548\/redis.conf\r\n<\/pre>\n

\u505a\u5b8c\u8fd9\u4e9b\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5\u53bb\u8bfb\u53d6\u6570\u636e\u4e86\uff0c\u770b\u770b\u6211\u4eec\u63d2\u5165\u76841000\u4e2aKey\u8fd8\u80fd\u6b63\u786e\u8bfb\u5230\u591a\u5c11\u4e2a\u3002\u4e0b\u9762\u6211\u4eec\u63d0\u4f9b\u4e00\u4e2a\u8bfb\u53d6\u5c0f\u811a\u672c\u3002<\/p>\n

\r\n[root@www ~]# cat get.sh \r\n#!\/bin\/bash\r\n#\r\nfor i in `seq 1 1000`;do\r\n  redis-cli -p 22122 get \"key$i$i\"\r\ndone\r\n<\/pre>\n

\u7136\u540e\u6267\u884c\u811a\u672c\uff0c\u5e76\u7edf\u8ba1\u4e00\u4e0b\u80fd\u67e5\u8be2\u5230\u503c\u5f97Key\u6709\u591a\u5c11\u4e2a\u3002<\/p>\n

\r\n[root@www ~]# bash get.sh | grep \"value\" | wc -l\r\n647\r\n<\/pre>\n

\u901a\u8fc7\u7ed3\u679c\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u51fa\uff0c\u5f53Redis\u4e3a2\u4e2a\u8282\u70b9\u65f6\uff0c\u6211\u4eec\u63d2\u51651000\u4e2aKey\uff0c\u7136\u540e\u65b0\u589e\u4e00\u4e2a\u8282\u70b9\u540e\u53ea\u8bfb\u53d6\u5230\u4e86647\u4e2aKey\uff0c\u8fd1\u4f3c\u503c3\/1\u3002\u5982\u679c\u4f60\u4e86\u89e3\u4e00\u81f4\u6027\u54c8\u5e0c\u7b97\u6cd5\u7684\u539f\u7406\u7684\u8bdd\uff0c\u5c31\u5e94\u8be5\u4f1a\u77e5\u9053\uff0c\u4e22\u5931Key\u7684\u6bd4\u4f8b\u5c31\u662f\u65b0\u589e\u8282\u70b9\u6570\u5360\u603b\u8282\u70b9\u6570\uff08\u539f\u6709\u8282\u70b9+\u65b0\u589e\u8282\u70b9\uff09\u7684\u6bd4\u4f8b\u3002\u6bd4\u5982\u539f\u6765\u67098\u4e2a\u8282\u70b9\uff0c\u65b0\u589e2\u4e2a\u8282\u70b9\uff0c\u4e22\u5931Key\u7684\u6bd4\u4f8b\u5c31\u662f2\/10\u3002\u5f53\u7136\u8fd9\u4e2a\u53ea\u662f\u7b80\u5355\u7684\u6570\u636e\u6d4b\u8bd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u4e0a\u4e00\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u914d\u7f6e\u4e86\u4e00\u4e2atwemproxy\u8282\u70b9\uff0c\u540e\u9762\u8ddf\u7740\u4e24\u4e2aRedis\u8282\u70b9\u505a\u7684\u7b80\u5355\u6d4b\u8bd5\u3002\u4e0b\u9762\u6211\u4eec\u6a21\u62df\u5728Re […]<\/p>\n","protected":false},"author":668,"featured_media":101135,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-136070","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\/136070","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\/668"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=136070"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/136070\/revisions"}],"predecessor-version":[{"id":136551,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/136070\/revisions\/136551"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/101135"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=136070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=136070"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=136070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}