{"id":382,"date":"2023-09-16T10:57:12","date_gmt":"2023-09-16T02:57:12","guid":{"rendered":""},"modified":"2023-09-16T10:57:12","modified_gmt":"2023-09-16T02:57:12","slug":"Redis\u5206\u5e03\u5f0f\u7f13\u5b58\u90e8\u7f72\u65b9\u6848\u8be6\u89e3","status":"publish","type":"post","link":"https:\/\/mushiming.com\/382.html","title":{"rendered":"Redis\u5206\u5e03\u5f0f\u7f13\u5b58\u90e8\u7f72\u65b9\u6848\u8be6\u89e3"},"content":{"rendered":"
Redis\u7684\u5206\u5e03\u5f0f\u90e8\u7f72\u6709\u591a\u79cd\u65b9\u5f0f\uff0c\u4f8b\u5982\u4e3b\u4ece\u590d\u5236\u3001\u54e8\u5175\u6a21\u5f0f\u548c\u96c6\u7fa4\u6a21\u5f0f\u7b49\u3002\u6bcf\u79cd\u65b9\u5f0f\u5404\u6709\u4f18\u7f3a\u70b9\uff0c\u9700\u8981\u6839\u636e\u4e1a\u52a1\u9700\u6c42\u548c\u5b9e\u9645\u60c5\u51b5\u8fdb\u884c\u9009\u62e9\u3002\u5728\u90e8\u7f72\u65f6\u9700\u8981\u6ce8\u610f\u8282\u70b9\u4e4b\u95f4\u7684\u901a\u4fe1\u3001\u6570\u636e\u540c\u6b65\u4ee5\u53ca\u8d1f\u8f7d\u5747\u8861\u7b49\u95ee\u9898\uff0c\u786e\u4fdd\u7cfb\u7edf\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002<\/p>\n
\u5728Redis\u4e3b\u4ece\u590d\u5236\u6a21\u5f0f\u4e2d\uff0c\u4e00\u4e2aRedis\u8282\u70b9\u4f5c\u4e3a\u4e3b\u8282\u70b9\uff0c\u5176\u4ed6\u8282\u70b9\u4f5c\u4e3a\u4ece\u8282\u70b9\u3002\u4e3b\u8282\u70b9\u8d1f\u8d23\u5199\u5165\u6570\u636e\uff0c\u4ece\u8282\u70b9\u8d1f\u8d23\u8bfb\u53d6\u6570\u636e\u5e76\u4e0e\u4e3b\u8282\u70b9\u540c\u6b65\u6570\u636e\u3002\u4e3b\u8282\u70b9\u5c06\u5199\u5165\u7684\u6570\u636e\u540c\u6b65\u5230\u4ece\u8282\u70b9\uff0c\u4ece\u8282\u70b9\u5728\u63a5\u6536\u5230\u6570\u636e\u540e\u8fdb\u884c\u5b58\u50a8\uff0c\u5e76\u4e0e\u4e3b\u8282\u70b9\u4fdd\u6301\u540c\u6b65\uff0c\u4ee5\u4fbf\u5728\u4e3b\u8282\u70b9\u5b95\u673a\u65f6\u53ef\u4ee5\u5feb\u901f\u5730\u8fdb\u884c\u6545\u969c\u8f6c\u79fb\u3002<\/p>\n
\u5728\u4e3b\u8282\u70b9\u4e0a\u521b\u5efa\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6redis.conf\uff0c\u5e76\u914d\u7f6e\u4e3b\u8282\u70b9\u7684IP\u5730\u5740\u548c\u7aef\u53e3\u53f7\u7b49\u4fe1\u606f\u3002<\/p>\n
\u542f\u52a8\u4e3b\u8282\u70b9\u65f6\uff0c\u9700\u8981\u6307\u5b9a\u914d\u7f6e\u6587\u4ef6\u7684\u8def\u5f84\u548c\u540d\u79f0\uff0c\u4f8b\u5982\uff1a<\/p>\n
redis-server \/path\/to\/redis.conf\n\n<\/code><\/pre>\n\n- \u914d\u7f6e\u4ece\u8282\u70b9<\/li>\n<\/ol>\n
\u5728\u4ece\u8282\u70b9\u4e0a\u521b\u5efa\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6redis.conf\uff0c\u5e76\u914d\u7f6e\u4ece\u8282\u70b9\u7684IP\u5730\u5740\u548c\u7aef\u53e3\u53f7\u7b49\u4fe1\u606f\u3002\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u9700\u8981\u6307\u5b9a\u4e3b\u8282\u70b9\u7684IP\u5730\u5740\u548c\u7aef\u53e3\u53f7\u3002<\/p>\n
\n- \u542f\u52a8\u4ece\u8282\u70b9<\/li>\n<\/ol>\n
\u542f\u52a8\u4ece\u8282\u70b9\u65f6\uff0c\u9700\u8981\u6307\u5b9a\u914d\u7f6e\u6587\u4ef6\u7684\u8def\u5f84\u548c\u540d\u79f0\uff0c\u4f8b\u5982\uff1a<\/p>\n
redis-server \/path\/to\/redis.conf\n\n<\/code><\/pre>\n\n- \u914d\u7f6e\u4e3b\u4ece\u5173\u7cfb<\/li>\n<\/ol>\n
\u5728\u4ece\u8282\u70b9\u4e0a\u8bbe\u7f6e\u4e3b\u8282\u70b9\u7684IP\u5730\u5740\u548c\u7aef\u53e3\u53f7\uff0c\u4f8b\u5982\uff1a<\/p>\n
slaveof <master_ip> <master_port>\n\n<\/code><\/pre>\n\n- \u68c0\u67e5\u4e3b\u4ece\u5173\u7cfb<\/li>\n<\/ol>\n
\u4f7f\u7528\u547d\u4ee4info replication\u53ef\u4ee5\u67e5\u770b\u4e3b\u4ece\u5173\u7cfb\u662f\u5426\u5df2\u7ecf\u5efa\u7acb\u3002\u5982\u679c\u4e3b\u4ece\u5173\u7cfb\u5df2\u7ecf\u5efa\u7acb\uff0c\u4ece\u8282\u70b9\u4f1a\u663e\u793a\u4e3b\u8282\u70b9\u7684\u4fe1\u606f\u3002<\/p>\n
Redis\u4e3b\u4ece\u590d\u5236\u6a21\u5f0f\u53ef\u4ee5\u63d0\u9ad8Redis\u7684\u53ef\u7528\u6027\u548c\u6027\u80fd\uff0c\u9002\u7528\u4e8e\u5bf9\u6570\u636e\u5b9e\u65f6\u6027\u548c\u4e00\u81f4\u6027\u8981\u6c42\u4e0d\u662f\u975e\u5e38\u9ad8\u7684\u573a\u666f\u3002\u5728\u90e8\u7f72\u65f6\u9700\u8981\u6ce8\u610f\u4e3b\u4ece\u8282\u70b9\u4e4b\u95f4\u7684\u901a\u4fe1\u548c\u6570\u636e\u540c\u6b65\u7b49\u95ee\u9898\uff0c\u786e\u4fdd\u7cfb\u7edf\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002<\/p>\n
\u4f7f\u7528\u573a\u666f<\/h3>\n
\u4e3b\u4ece\u590d\u5236\u9002\u7528\u4e8e\u5bf9\u6570\u636e\u7684\u53ef\u7528\u6027\u8981\u6c42\u8f83\u9ad8\uff0c\u4f46\u5bf9\u6570\u636e\u5b9e\u65f6\u6027\u548c\u4e00\u81f4\u6027\u8981\u6c42\u4e0d\u662f\u975e\u5e38\u9ad8\u7684\u573a\u666f\uff0c\u4f8b\u5982\u7f13\u5b58\u7cfb\u7edf\u548c\u8bfb\u591a\u5199\u5c11\u7684\u4e1a\u52a1\u7cfb\u7edf\u7b49\u3002<\/p>\n
Redis\u54e8\u5175\u6a21\u5f0f\u90e8\u7f72<\/h2>\n\u7b80\u4ecb<\/h3>\n
Redis\u54e8\u5175\u6a21\u5f0f\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u5206\u5e03\u5f0f\u90e8\u7f72\u65b9\u5f0f\uff0c\u5b83\u901a\u8fc7\u76d1\u63a7\u4e3b\u8282\u70b9\u7684\u72b6\u6001\uff0c\u5b9e\u73b0\u4e3b\u4ece\u590d\u5236\u7684\u9ad8\u53ef\u7528\u6027\u3002\u5728Redis\u54e8\u5175\u6a21\u5f0f\u4e2d\uff0c\u6709\u4e00\u4e2a\u6216\u591a\u4e2a\u54e8\u5175\u8282\u70b9\uff0c\u8d1f\u8d23\u76d1\u63a7\u4e3b\u8282\u70b9\u7684\u72b6\u6001\u3002\u5f53\u4e3b\u8282\u70b9\u5b95\u673a\u65f6\uff0c\u54e8\u5175\u8282\u70b9\u4f1a\u81ea\u52a8\u5c06\u4ece\u8282\u70b9\u5207\u6362\u4e3a\u4e3b\u8282\u70b9\uff0c\u5e76\u901a\u77e5\u5176\u4ed6\u8282\u70b9\u8fdb\u884c\u66f4\u65b0\u3002\u8fd9\u6837\u53ef\u4ee5\u907f\u514d\u56e0\u4e3b\u8282\u70b9\u5b95\u673a\u5bfc\u81f4\u7cfb\u7edf\u4e0d\u53ef\u7528\u7684\u95ee\u9898\u3002<\/p>\n
\u4f18\u70b9<\/h3>\n\n- \u9ad8\u53ef\u7528\u6027<\/strong>\uff1a\u54e8\u5175\u6a21\u5f0f\u53ef\u4ee5\u5b9e\u73b0\u4e3b\u4ece\u590d\u5236\u7684\u9ad8\u53ef\u7528\u6027\uff0c\u5373\u4f7f\u4e3b\u8282\u70b9\u5b95\u673a\uff0c\u54e8\u5175\u8282\u70b9\u4e5f\u53ef\u4ee5\u81ea\u52a8\u5c06\u4ece\u8282\u70b9\u5207\u6362\u4e3a\u4e3b\u8282\u70b9\uff0c\u4fdd\u8bc1\u7cfb\u7edf\u7684\u6b63\u5e38\u8fd0\u884c\u3002<\/li>\n
- \u6613\u4e8e\u90e8\u7f72<\/strong>\uff1a\u54e8\u5175\u6a21\u5f0f\u76f8\u5bf9\u4e8e\u96c6\u7fa4\u6a21\u5f0f\u800c\u8a00\uff0c\u90e8\u7f72\u76f8\u5bf9\u5bb9\u6613\uff0c\u4e0d\u9700\u8981\u8fdb\u884c\u590d\u6742\u7684\u914d\u7f6e\uff0c\u53ea\u9700\u8981\u5728\u54e8\u5175\u8282\u70b9\u4e0a\u6dfb\u52a0\u4e00\u4e9b\u914d\u7f6e\u5373\u53ef\u3002<\/li>\n
- \u81ea\u52a8\u5207\u6362<\/strong>\uff1a\u54e8\u5175\u8282\u70b9\u53ef\u4ee5\u81ea\u52a8\u5c06\u4ece\u8282\u70b9\u5207\u6362\u4e3a\u4e3b\u8282\u70b9\uff0c\u907f\u514d\u4e86\u624b\u52a8\u5207\u6362\u7684\u8fc7\u7a0b\uff0c\u63d0\u9ad8\u4e86\u7cfb\u7edf\u7684\u53ef\u7528\u6027\u3002<\/li>\n<\/ul>\n
\u7f3a\u70b9<\/h3>\n\n- \u6027\u80fd\u635f\u5931<\/strong>\uff1a\u54e8\u5175\u8282\u70b9\u4f1a\u5b9a\u671f\u5bf9\u4e3b\u8282\u70b9\u8fdb\u884c\u68c0\u6d4b\uff0c\u8fd9\u4f1a\u5bf9\u4e3b\u8282\u70b9\u7684\u6027\u80fd\u9020\u6210\u4e00\u5b9a\u7684\u5f71\u54cd\u3002<\/li>\n
- \u590d\u6742\u5ea6<\/strong>\uff1a\u54e8\u5175\u6a21\u5f0f\u6d89\u53ca\u5230\u591a\u4e2a\u8282\u70b9\u4e4b\u95f4\u7684\u901a\u4fe1\u548c\u534f\u8c03\uff0c\u76f8\u5bf9\u4e8e\u4e3b\u4ece\u590d\u5236\u800c\u8a00\uff0c\u90e8\u7f72\u548c\u7ef4\u62a4\u7684\u590d\u6742\u5ea6\u66f4\u9ad8\u3002<\/li>\n<\/ul>\n
\u4f7f\u7528\u573a\u666f<\/h3>\n
\u54e8\u5175\u6a21\u5f0f\u9002\u7528\u4e8e\u5bf9\u6570\u636e\u7684\u53ef\u7528\u6027\u8981\u6c42\u8f83\u9ad8\uff0c\u4f46\u5bf9\u6570\u636e\u5b9e\u65f6\u6027\u548c\u4e00\u81f4\u6027\u8981\u6c42\u4e0d\u662f\u975e\u5e38\u9ad8\u7684\u573a\u666f\uff0c\u4f8b\u5982\u7f13\u5b58\u7cfb\u7edf\u548c\u8bfb\u591a\u5199\u5c11\u7684\u4e1a\u52a1\u7cfb\u7edf\u7b49\u3002<\/p>\n
\u90e8\u7f72\u6b65\u9aa4<\/h3>\n\n- \u521b\u5efa\u914d\u7f6e\u6587\u4ef6<\/li>\n<\/ol>\n
\u5728\u54e8\u5175\u8282\u70b9\u4e0a\u521b\u5efa\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6sentinel.conf\uff0c\u914d\u7f6e\u6587\u4ef6\u4e2d\u9700\u8981\u6307\u5b9a\u54e8\u5175\u8282\u70b9\u7684IP\u5730\u5740\u548c\u7aef\u53e3\u53f7\uff0c\u4ee5\u53ca\u76d1\u63a7\u7684\u4e3b\u8282\u70b9\u4fe1\u606f\u3002<\/p>\n
\n- \u542f\u52a8\u54e8\u5175\u8282\u70b9<\/li>\n<\/ol>\n
\u542f\u52a8\u54e8\u5175\u8282\u70b9\u65f6\uff0c\u9700\u8981\u6307\u5b9a\u914d\u7f6e\u6587\u4ef6\u7684\u8def\u5f84\u548c\u540d\u79f0\uff0c\u4f8b\u5982\uff1a<\/p>\n
redis-sentinel \/path\/to\/sentinel.conf\n\n<\/code><\/pre>\n\n- \u914d\u7f6e\u4e3b\u8282\u70b9<\/li>\n<\/ol>\n
\u5728\u4e3b\u8282\u70b9\u4e0a\u521b\u5efa\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6redis.conf\uff0c\u5e76\u914d\u7f6e\u4e3b\u8282\u70b9\u7684IP\u5730\u5740\u548c\u7aef\u53e3\u53f7\u7b49\u4fe1\u606f\u3002<\/p>\n
\n- \u542f\u52a8\u4e3b\u8282\u70b9<\/li>\n<\/ol>\n
\u542f\u52a8\u4e3b\u8282\u70b9\u65f6\uff0c\u9700\u8981\u6307\u5b9a\u914d\u7f6e\u6587\u4ef6\u7684\u8def\u5f84\u548c\u540d\u79f0\uff0c\u4f8b\u5982\uff1a<\/p>\n
redis-server \/path\/to\/redis.conf\n\n<\/code><\/pre>\n\n- \u914d\u7f6e\u4ece\u8282\u70b9<\/li>\n<\/ol>\n
\u5728\u4ece\u8282\u70b9\u4e0a\u521b\u5efa\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6redis.conf\uff0c\u5e76\u914d\u7f6e\u4ece\u8282\u70b9\u7684IP\u5730\u5740\u548c\u7aef\u53e3\u53f7\u7b49\u4fe1\u606f\u3002\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u9700\u8981\u6307\u5b9a\u4e3b\u8282\u70b9\u7684IP\u5730\u5740\u548c\u7aef\u53e3\u53f7\u3002<\/p>\n
\n- \u542f\u52a8\u4ece\u8282\u70b9<\/li>\n<\/ol>\n
\u542f\u52a8\u4ece\u8282\u70b9\u65f6\uff0c\u9700\u8981\u6307\u5b9a\u914d\u7f6e\u6587\u4ef6\u7684\u8def\u5f84\u548c\u540d\u79f0\uff0c\u4f8b\u5982\uff1a<\/p>\n
redis-server \/path\/to\/redis.conf\n\n<\/code><\/pre>\n\n- \u68c0\u67e5\u54e8\u5175\u8282\u70b9\u72b6\u6001<\/li>\n<\/ol>\n
\u4f7f\u7528\u547d\u4ee4sentinel masters\u53ef\u4ee5\u67e5\u770b\u54e8\u5175\u8282\u70b9\u7684\u72b6\u6001\u548c\u4e3b\u8282\u70b9\u7684\u4fe1\u606f\u3002\u5982\u679c\u4e3b\u8282\u70b9\u5b95\u673a\uff0c\u54e8\u5175\u8282\u70b9\u4f1a\u81ea\u52a8\u5c06\u4ece\u8282\u70b9\u5207\u6362\u4e3a\u4e3b\u8282\u70b9\u3002<\/p>\n
\u603b\u7ed3<\/h3>\n
Redis\u54e8\u5175\u6a21\u5f0f\u662f\u4e00\u79cd\u5b9e\u73b0\u4e3b\u4ece\u590d\u5236\u9ad8\u53ef\u7528\u6027\u7684\u65b9\u5f0f\uff0c\u5b83\u53ef\u4ee5\u81ea\u52a8\u5207\u6362\u4ece\u8282\u70b9\u4e3a\u4e3b\u8282\u70b9\uff0c\u4fdd\u8bc1\u4e86\u7cfb\u7edf\u7684\u53ef\u7528\u6027\u3002\u54e8\u5175\u6a21\u5f0f\u76f8\u5bf9\u4e8e\u96c6\u7fa4\u6a21\u5f0f\u800c\u8a00\uff0c\u90e8\u7f72\u548c\u7ef4\u62a4\u7684\u590d\u6742\u5ea6\u8f83\u4f4e\uff0c\u9002\u7528\u4e8e\u5bf9\u6570\u636e\u5b9e\u65f6\u6027\u548c\u4e00\u81f4\u6027\u8981\u6c42\u4e0d\u662f\u975e\u5e38\u9ad8\u7684\u573a\u666f\u3002<\/p>\n
Redis\u96c6\u7fa4\u6a21\u5f0f\u90e8\u7f72<\/h2>\n\u7b80\u4ecb<\/h3>\n
Redis\u96c6\u7fa4\u6a21\u5f0f\u662f\u4e00\u79cd\u9ad8\u53ef\u7528\u3001\u9ad8\u6027\u80fd\u7684\u5206\u5e03\u5f0f\u90e8\u7f72\u65b9\u5f0f\uff0c\u5b83\u53ef\u4ee5\u5c06\u6570\u636e\u5206\u6563\u5230\u591a\u4e2a\u8282\u70b9\u4e0a\u5b58\u50a8\uff0c\u63d0\u9ad8\u7cfb\u7edf\u7684\u541e\u5410\u91cf\u548c\u54cd\u5e94\u901f\u5ea6\u3002\u5728Redis\u96c6\u7fa4\u6a21\u5f0f\u4e2d\uff0c\u6709\u591a\u4e2a\u8282\u70b9\u7ec4\u6210\u4e00\u4e2a\u96c6\u7fa4\uff0c\u6bcf\u4e2a\u8282\u70b9\u90fd\u4fdd\u5b58\u7740\u90e8\u5206\u6570\u636e\u548c\u5176\u4ed6\u8282\u70b9\u7684\u6620\u5c04\u5173\u7cfb\u3002\u5f53\u6570\u636e\u9700\u8981\u8fdb\u884c\u8bfb\u5199\u65f6\uff0c\u5ba2\u6237\u7aef\u4f1a\u6839\u636e\u54c8\u5e0c\u7b97\u6cd5\u5c06\u6570\u636e\u53d1\u9001\u5230\u5bf9\u5e94\u7684\u8282\u70b9\u4e0a\u8fdb\u884c\u5904\u7406\u3002<\/p>\n
\u4f18\u70b9<\/h3>\n\n- \u9ad8\u53ef\u7528\u6027<\/strong>\uff1aRedis\u96c6\u7fa4\u6a21\u5f0f\u53ef\u4ee5\u907f\u514d\u5355\u70b9\u6545\u969c\uff0c\u63d0\u9ad8Redis\u7684\u53ef\u7528\u6027\u3002\u5f53\u67d0\u4e2a\u8282\u70b9\u5b95\u673a\u65f6\uff0c\u5176\u4ed6\u8282\u70b9\u53ef\u4ee5\u63a5\u7ba1\u5de5\u4f5c\uff0c\u4fdd\u8bc1\u7cfb\u7edf\u7684\u6b63\u5e38\u8fd0\u884c\u3002<\/li>\n
- \u9ad8\u6027\u80fd<\/strong>\uff1aRedis\u96c6\u7fa4\u6a21\u5f0f\u53ef\u4ee5\u901a\u8fc7\u589e\u52a0\u8282\u70b9\u6570\u91cf\u6765\u63d0\u9ad8\u7cfb\u7edf\u7684\u541e\u5410\u91cf\u548c\u54cd\u5e94\u901f\u5ea6\u3002\u5f53\u9700\u8981\u5904\u7406\u5927\u91cf\u7684\u5e76\u53d1\u8bf7\u6c42\u65f6\uff0c\u53ef\u4ee5\u5c06\u8d1f\u8f7d\u5206\u6563\u5230\u591a\u4e2a\u8282\u70b9\u4e0a\u8fdb\u884c\u5904\u7406\uff0c\u907f\u514d\u51fa\u73b0\u6027\u80fd\u74f6\u9888\u3002<\/li>\n
- \u6613\u4e8e\u6269\u5c55<\/strong>\uff1aRedis\u96c6\u7fa4\u6a21\u5f0f\u53ef\u4ee5\u65b9\u4fbf\u5730\u6269\u5c55\u7cfb\u7edf\u7684\u5bb9\u91cf\u548c\u6027\u80fd\uff0c\u53ea\u9700\u6dfb\u52a0\u65b0\u8282\u70b9\u5373\u53ef\u3002\u5728\u8282\u70b9\u6570\u91cf\u8f83\u5c11\u65f6\uff0c\u53ef\u4ee5\u91c7\u7528\u52a8\u6001\u6269\u5c55\u7684\u65b9\u5f0f\uff0c\u5f53\u8282\u70b9\u6570\u91cf\u8f83\u591a\u65f6\uff0c\u53ef\u4ee5\u91c7\u7528\u9759\u6001\u5206\u7247\u7684\u65b9\u5f0f\u8fdb\u884c\u90e8\u7f72\u3002<\/li>\n<\/ul>\n
\u7f3a\u70b9<\/h3>\n\n- \u590d\u6742\u5ea6<\/strong>\uff1aRedis\u96c6\u7fa4\u6a21\u5f0f\u6d89\u53ca\u5230\u591a\u4e2a\u8282\u70b9\u4e4b\u95f4\u7684\u901a\u4fe1\u548c\u534f\u8c03\uff0c\u76f8\u5bf9\u4e8e\u4e3b\u4ece\u590d\u5236\u548c\u54e8\u5175\u6a21\u5f0f\u800c\u8a00\uff0c\u90e8\u7f72\u548c\u7ef4\u62a4\u7684\u590d\u6742\u5ea6\u66f4\u9ad8\u3002<\/li>\n
- \u6570\u636e\u4e00\u81f4\u6027<\/strong>\uff1aRedis\u96c6\u7fa4\u6a21\u5f0f\u4e2d\u7684\u6570\u636e\u540c\u6b65\u5b58\u5728\u4e00\u5b9a\u7684\u5ef6\u8fdf\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u60c5\u51b5\u3002\u5982\u679c\u9700\u8981\u4fdd\u8bc1\u6570\u636e\u7684\u5b9e\u65f6\u6027\u548c\u4e00\u81f4\u6027\uff0c\u9700\u8981\u4f7f\u7528\u5176\u4ed6\u65b9\u5f0f\u3002<\/li>\n<\/ul>\n
\u4f7f\u7528\u573a\u666f<\/h3>\n
Redis\u96c6\u7fa4\u6a21\u5f0f\u9002\u7528\u4e8e\u5bf9\u6570\u636e\u7684\u53ef\u7528\u6027\u548c\u6027\u80fd\u8981\u6c42\u8f83\u9ad8\u7684\u573a\u666f\uff0c\u4f8b\u5982\u7535\u5546\u7f51\u7ad9\u3001\u5728\u7ebf\u6e38\u620f\u3001\u793e\u4ea4\u5e73\u53f0\u7b49\u3002<\/p>\n
\u90e8\u7f72\u6b65\u9aa4<\/h3>\n\n- \u521b\u5efa\u914d\u7f6e\u6587\u4ef6<\/li>\n<\/ol>\n
\u5728\u6bcf\u4e2a\u8282\u70b9\u4e0a\u521b\u5efa\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6redis.conf\uff0c\u5e76\u914d\u7f6e\u8282\u70b9\u7684IP\u5730\u5740\u548c\u7aef\u53e3\u53f7\u7b49\u4fe1\u606f\u3002\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u9700\u8981\u6307\u5b9a\u96c6\u7fa4\u6a21\u5f0f\u7684\u53c2\u6570\uff0c\u4f8b\u5982cluster-enabled\u3001cluster-config-file\u3001cluster-node-timeout\u7b49\u3002<\/p>\n
\n- \u542f\u52a8\u8282\u70b9<\/li>\n<\/ol>\n
\u542f\u52a8\u6bcf\u4e2a\u8282\u70b9\u65f6\uff0c\u9700\u8981\u6307\u5b9a\u914d\u7f6e\u6587\u4ef6\u7684\u8def\u5f84\u548c\u540d\u79f0\uff0c\u4f8b\u5982\uff1a<\/p>\n
redis-server \/path\/to\/redis.conf\n\n<\/code><\/pre>\n\n- \u521b\u5efa\u96c6\u7fa4<\/li>\n<\/ol>\n
\u4f7f\u7528\u547d\u4ee4redis-cli --cluster create <node1>:<port1> <node2>:<port2> ... <nodeN>:<portN> --cluster-replicas <replicas>\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2aRedis\u96c6\u7fa4\u3002\u5176\u4e2d\uff0c<node1>:<port1>\u5230<nodeN>:<portN>\u4e3a\u8282\u70b9\u7684IP\u5730\u5740\u548c\u7aef\u53e3\u53f7\uff0c<replicas>\u4e3a\u6bcf\u4e2a\u4e3b\u8282\u70b9\u7684\u4ece\u8282\u70b9\u6570\u91cf\u3002<\/p>\n
\n- \u68c0\u67e5\u96c6\u7fa4\u72b6\u6001<\/li>\n<\/ol>\n
\u4f7f\u7528\u547d\u4ee4redis-cli --cluster check <ip>:<port>\u53ef\u4ee5\u68c0\u67e5\u96c6\u7fa4\u7684\u72b6\u6001\u3002\u5982\u679c\u96c6\u7fa4\u72b6\u6001\u6b63\u5e38\uff0c\u4f1a\u663e\u793a\u6bcf\u4e2a\u8282\u70b9\u7684\u4fe1\u606f\u548c\u6570\u636e\u5206\u5e03\u60c5\u51b5\u3002<\/p>\n
\u603b\u7ed3<\/h3>\n
Redis\u96c6\u7fa4\u6a21\u5f0f\u662f\u4e00\u79cd\u9ad8\u53ef\u7528\u3001\u9ad8\u6027\u80fd\u7684\u5206\u5e03\u5f0f\u90e8\u7f72\u65b9\u5f0f\uff0c\u9002\u7528\u4e8e\u5bf9\u6570\u636e\u7684\u53ef\u7528\u6027\u548c\u6027\u80fd\u8981\u6c42\u8f83\u9ad8\u7684\u573a\u666f\u3002\u5728\u90e8\u7f72\u65f6\u9700\u8981\u6ce8\u610f\u8282\u70b9\u4e4b\u95f4\u7684\u901a\u4fe1\u3001\u6570\u636e\u540c\u6b65\u4ee5\u53ca\u8d1f\u8f7d\u5747\u8861\u7b49\u95ee\u9898\uff0c\u786e\u4fdd\u7cfb\u7edf\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002<\/p>\n
\u5728Docker\u4e0a\u90e8\u7f72Redis\u96c6\u7fa4<\/h3>\n\n- \u4e0b\u8f7dRedis\u955c\u50cf<\/li>\n<\/ol>\n
\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4eceDocker Hub\u4e0a\u4e0b\u8f7dRedis\u955c\u50cf\uff1a<\/p>\n
docker pull redis\n\n<\/code><\/pre>\n\n- \u521b\u5efaDocker\u7f51\u7edc<\/li>\n<\/ol>\n
\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u4e00\u4e2aDocker\u7f51\u7edc\uff1a<\/p>\n
docker network create redis-network\n\n<\/code><\/pre>\n\n- \u542f\u52a8Redis\u5bb9\u5668<\/li>\n<\/ol>\n
\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a86\u4e2aRedis\u5bb9\u5668\uff1a<\/p>\n
docker run -d --name redis1 --net redis-network redis redis-server --appendonly yes\ndocker run -d --name redis2 --net redis-network redis redis-server --appendonly yes\ndocker run -d --name redis3 --net redis-network redis redis-server --appendonly yes\ndocker run -d --name redis4 --net redis-network redis redis-server --appendonly yes\ndocker run -d --name redis5 --net redis-network redis redis-server --appendonly yes\ndocker run -d --name redis6 --net redis-network redis redis-server --appendonly yes\n\n<\/code><\/pre>\n\n- \u521b\u5efaRedis\u96c6\u7fa4<\/li>\n<\/ol>\n
\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efaRedis\u96c6\u7fa4\uff1a<\/p>\n
docker run -it --rm --net redis-network redis redis-cli --cluster create \\\\\\\\\n 172.18.0.2:6379 172.18.0.3:6379 172.18.0.4:6379 \\\\\\\\\n 172.18.0.5:6379 172.18.0.6:6379 172.18.0.7:6379 \\\\\\\\\n --cluster-replicas 1\n\n<\/code><\/pre>\n\u5176\u4e2d\uff0c172.18.0.2\u5230172.18.0.7\u4e3aRedis\u5bb9\u5668\u7684IP\u5730\u5740\uff0c6379\u4e3aRedis\u5bb9\u5668\u7684\u7aef\u53e3\u53f7\uff0c--cluster-replicas 1\u8868\u793a\u6bcf\u4e2a\u4e3b\u8282\u70b9\u6709\u4e00\u4e2a\u4ece\u8282\u70b9\u3002<\/p>\n
\n- \u68c0\u67e5Redis\u96c6\u7fa4\u72b6\u6001<\/li>\n<\/ol>\n
\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u68c0\u67e5Redis\u96c6\u7fa4\u72b6\u6001\uff1a<\/p>\n
docker run -it --rm --net redis-network redis redis-cli --cluster check 172.18.0.2:6379\n\n<\/code><\/pre>\n\u5982\u679c\u96c6\u7fa4\u72b6\u6001\u6b63\u5e38\uff0c\u4f1a\u663e\u793a\u6bcf\u4e2a\u8282\u70b9\u7684\u4fe1\u606f\u548c\u6570\u636e\u5206\u5e03\u60c5\u51b5\u3002<\/p>\n
\u603b\u7ed3<\/h3>\n
\u5728Docker\u4e0a\u90e8\u7f72Redis\u96c6\u7fa4\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u6d4b\u8bd5\u548c\u5f00\u53d1\uff0c\u540c\u65f6\u4e5f\u53ef\u4ee5\u63d0\u9ad8Redis\u7684\u53ef\u7528\u6027\u548c\u6027\u80fd\u3002\u5728\u90e8\u7f72\u65f6\u9700\u8981\u6ce8\u610f\u8282\u70b9\u4e4b\u95f4\u7684\u901a\u4fe1\u3001\u6570\u636e\u540c\u6b65\u4ee5\u53ca\u8d1f\u8f7d\u5747\u8861\u7b49\u95ee\u9898\uff0c\u786e\u4fdd\u7cfb\u7edf\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Redis\u5206\u5e03\u5f0f\u7f13\u5b58\u90e8\u7f72\u65b9\u6848\u8be6\u89e3\u5728Redis\u4e3b\u4ece\u590d\u5236\u6a21\u5f0f\u4e2d\uff0c\u4e00\u4e2aRedis\u8282\u70b9\u4f5c\u4e3a\u4e3b\u8282\u70b9\uff0c\u5176\u4ed6\u8282\u70b9\u4f5c\u4e3a\u4ece\u8282\u70b9\u3002\u4e3b\u8282\u70b9\u8d1f\u8d23\u5199\u5165\u6570\u636e\uff0c\u4ece...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[83],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/382"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=382"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/382\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=382"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=382"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=382"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}