{"id":136083,"date":"2019-02-20T09:44:03","date_gmt":"2019-02-20T01:44:03","guid":{"rendered":"https:\/\/gulass.cn\/?p=136083"},"modified":"2019-02-18T09:46:41","modified_gmt":"2019-02-18T01:46:41","slug":"redis-master-slave","status":"publish","type":"post","link":"https:\/\/gulass.cn\/redis-master-slave.html","title":{"rendered":"\u8be6\u89e3\uff1aRedis\u4e3b\u4ece\u6280\u672f\u7684\u5e94\u7528"},"content":{"rendered":"
\u5728\u751f\u4ea7\u73af\u5883\u4e2d\uff0cRedis\u901a\u8fc7\u6301\u4e45\u5316\u529f\u80fd\uff08RDB\u548cAOF\u6280\u672f\uff09\u4fdd\u8bc1\u4e86\u5373\u4f7f\u5728\u670d\u52a1\u5668\u91cd\u542f\u7684\u60c5\u51b5\u4e0b\u4e5f\u4e0d\u4f1a\u635f\u5931\uff08\u6216\u5c11\u91cf\u635f\u5931\uff09\u6570\u636e\u3002\u4f46\u662f\u7531\u4e8e\u6570\u636e\u662f\u5b58\u50a8\u5728\u4e00\u53f0\u670d\u52a1\u5668\u4e0a\u7684\uff0c\u5982\u679c\u8fd9\u53f0\u670d\u52a1\u5668\u51fa\u73b0\u786c\u76d8\u6545\u969c\u7b49\u95ee\u9898\uff08\u751f\u4ea7\u73af\u5883\u4e2d\u591a\u6b21\u9047\u5230\uff09\uff0c\u4e5f\u4f1a\u5bfc\u81f4\u6570\u636e\u4e22\u5931\uff0c\u4e3a\u4e86\u907f\u514d\u5355\u70b9\u6545\u969c\uff0c\u901a\u5e38\u7684\u505a\u6cd5\u662f\u5c06\u6570\u636e\u5e93\u590d\u5236\u591a\u4e2a\u526f\u672c\u4ee5\u90e8\u7f72\u5728\u4e0d\u540c\u7684\u670d\u52a1\u5668\u4e0a\uff0c\u8fd9\u6837\u5373\u4f7f\u6709\u4e00\u53f0\u670d\u52a1\u5668\u51fa\u73b0\u6545\u969c\uff0c\u5176\u4ed6\u670d\u52a1\u5668\u4f9d\u7136\u53ef\u4ee5\u4ee5\u6700\u5feb\u7684\u901f\u5ea6\u63d0\u4f9b\u670d\u52a1\u3002\u4e3a\u6b64\uff0cRedis\u63d0\u4f9b\u4e86\u590d\u5236\uff08replication\uff09\u529f\u80fd\uff0c\u53ef\u4ee5\u5b9e\u73b0\u5f53\u4e00\u53f0\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u66f4\u65b0\u540e\uff0c\u81ea\u52a8\u5c06\u66f4\u65b0\u7684\u6570\u636e\u540c\u6b65\u5230\u5176\u4ed6\u6570\u636e\u5e93\u4e0a\u3002<\/p>\n
\u5728\u590d\u5236\u7684\u6982\u5ff5\u4e2d\uff0c\u6570\u636e\u5e93\u5206\u4e3a\u4e24\u7c7b\uff0c\u4e00\u7c7b\u662f\u4e3b\u6570\u636e\u5e93\uff08master\uff09\uff0c\u53e6\u4e00\u7c7b\u662f\u4ece\u6570\u636e\u5e93\uff08slave\uff09\u3002\u4e3b\u6570\u636e\u5e93\u53ef\u4ee5\u8fdb\u884c\u8bfb\u5199\u64cd\u4f5c\uff0c\u5f53\u5199\u64cd\u4f5c\u5bfc\u81f4\u6570\u636e\u53d8\u5316\u65f6\u81ea\u52a8\u5c06\u6570\u636e\u540c\u6b65\u7ed9\u4ece\u6570\u636e\u5e93\u3002\u800c\u4ece\u6570\u636e\u5e93\u4e00\u822c\u662f\u53ea\u8bfb\u7684\uff0c\u5e76\u63a5\u53d7\u4e3b\u6570\u636e\u5e93\u540c\u6b65\u8fc7\u6765\u7684\u6570\u636e\u3002\u4e00\u4e2a\u4e3b\u6570\u636e\u5e93\u53ef\u4ee5\u62e5\u6709\u591a\u4e2a\u4ece\u6570\u636e\u5e93\u3002<\/p>\n
Redis\u590d\u5236\u5f88\u7b80\u5355\u6613\u7528\uff0c\u5b83\u901a\u8fc7\u914d\u7f6e\u5141\u8bb8slave Redis Servers\u6216\u8005Master Servers\u7684\u590d\u5236\u54c1\u3002\u63a5\u4e0b\u6765\u6709\u51e0\u4e2a\u5173\u4e8eredis\u590d\u5236\u7684\u975e\u5e38\u91cd\u8981\u7279\u6027\uff1a<\/p>\n
\u4e00\u4e2aMaster\u53ef\u4ee5\u6709\u591a\u4e2aSlaves\u3002<\/p>\n
Slaves\u80fd\u901a\u8fc7\u548c\u5176\u4ed6slave\u7684\u94fe\u63a5\uff0c\u9664\u4e86\u53ef\u4ee5\u63a5\u53d7\u540c\u4e00\u4e2amaster\u4e0b\u9762slaves\u7684\u94fe\u63a5\u4ee5\u5916\uff0c\u8fd8\u53ef\u4ee5\u63a5\u53d7\u540c\u4e00\u4e2a\u7ed3\u6784\u56fe\u4e2d\u7684\u5176\u4ed6slaves\u7684\u94fe\u63a5\u3002<\/p>\n
redis\u590d\u5236\u662f\u5728master\u6bb5\u662f\u975e\u963b\u585e\u7684\uff0c\u8fd9\u5c31\u610f\u5473\u7740master\u5728\u540c\u4e00\u4e2a\u6216\u591a\u4e2aslave\u7aef\u6267\u884c\u540c\u6b65\u7684\u65f6\u5019\u8fd8\u53ef\u4ee5\u63a5\u53d7\u67e5\u8be2\u3002<\/p>\n
\u590d\u5236\u5728slave\u7aef\u4e5f\u662f\u975e\u963b\u585e\u7684\uff0c\u5047\u8bbe\u4f60\u5728redis.conf\u4e2d\u914d\u7f6eredis\u8fd9\u4e2a\u529f\u80fd\uff0c\u5f53slave\u5728\u6267\u884c\u7684\u65b0\u7684\u540c\u6b65\u65f6\uff0c\u5b83\u4ecd\u53ef\u4ee5\u7528\u65e7\u7684\u6570\u636e\u4fe1\u606f\u6765\u63d0\u4f9b\u67e5\u8be2\uff0c\u5426\u5219\uff0c\u4f60\u53ef\u4ee5\u914d\u7f6e\u5f53redis slaves\u53bbmaster\u5931\u53bb\u8054\u7cfb\u662f\uff0cslave\u4f1a\u7ed9\u53d1\u9001\u4e00\u4e2a\u5ba2\u6237\u7aef\u9519\u8bef\u3002<\/p>\n
\u4e3a\u4e86\u6709\u591a\u4e2aslaves\u53ef\u4ee5\u505a\u53ea\u8bfb\u67e5\u8be2\uff0c\u590d\u5236\u53ef\u4ee5\u91cd\u590d2\u6b21\uff0c\u751a\u81f3\u591a\u6b21\uff0c\u5177\u6709\u53ef\u6269\u5c55\u6027\uff08\u4f8b\u5982\uff1aslaves\u5bf9\u8bdd\u4e0e\u91cd\u590d\u7684\u6392\u5e8f\u64cd\u4f5c\uff0c\u6709\u591a\u4efd\u6570\u636e\u5197\u4f59\u5c31\u76f8\u5bf9\u7b80\u5355\u4e86\uff09\u3002<\/p>\n
\u901a\u8fc7\u590d\u5236\u53ef\u4ee5\u907f\u514dmaster\u5168\u91cf\u5199\u786c\u76d8\u7684\u6d88\u8017\uff1a\u53ea\u8981\u914d\u7f6e master \u7684\u914d\u7f6e\u6587\u4ef6redis.conf\u6765\u201c\u907f\u514d\u4fdd\u5b58\u201d\uff08\u6ce8\u91ca\u6389\u6240\u6709\u201dsave\u201d\u547d\u4ee4\uff09\uff0c\u7136\u540e\u8fde\u63a5\u4e00\u4e2a\u7528\u6765\u6301\u4e45\u5316\u6570\u636e\u7684slave\u5373\u53ef\u3002\u4f46\u662f\u8fd9\u6837\u8981\u786e\u4fddmasters \u4e0d\u4f1a\u81ea\u52a8\u91cd\u542f\uff08\u66f4\u591a\u5185\u5bb9\u8bf7\u9605\u8bfb\u4e0b\u6bb5\uff09<\/p>\n
\u5728Redis\u4e2d\u4f7f\u7528\u590d\u5236\u529f\u80fd\u975e\u5e38\u5bb9\u6613\uff0c\u53ea\u9700\u8981\u5728\u4ece\u6570\u636e\u5e93\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u52a0\u5165\u201cslaveof \u4e3b\u6570\u636e\u590d\u5236 \u4e3b\u6570\u636e\u5e93\u7aef\u53e3\u201d\u5373\u53ef\u3002<\/p>\n
\u4e3b\u6570\u636e\u5e93\u65e0\u9700\u8fdb\u884c\u4efb\u4f55\u914d\u7f6e\u3002\u4e0b\u9762\u5148\u6765\u770b\u770b\u4e00\u4e2a\u6700\u7b80\u5316\u7684\u590d\u5236\u7cfb\u7edf\uff0c\u6211\u4eec\u5728\u4e00\u53f0\u670d\u52a1\u5668\u4e0a\u542f\u52a8\u4e24\u4e2aredis\u793a\u4f8b\uff0c\u76d1\u542c\u5728\u4e0d\u540c\u7684\u7aef\u53e3\uff0c\u5176\u4e2d\u4e00\u4e2a\u4f5c\u4e3a\u4e3b\u6570\u636e\u5e93\uff0c\u53e6\u4e00\u4e2a\u4f5c\u4e3a\u4ece\u6570\u636e\u5e93\u3002<\/p>\n
\u9996\u5148\u6211\u4eec\u4e0d\u52a0\u4efb\u4f55\u53c2\u6570\u6765\u542f\u52a8\u4e00\u4e2aredis\u5b9e\u4f8b\u4f5c\u4e3a\u4e3b\u6570\u636e\u5e93\uff1a<\/p>\n
\r\n$ redis-server --port 6379 &\r\n<\/pre>\n\u8be5\u5b9e\u4f8b\u9ed8\u8ba4\u76d1\u542c6379\u7aef\u53e3\uff0c\u7136\u540e\u52a0\u4e0aslaveof\u53c2\u6570\u542f\u52a8\u53e6\u4e00\u4e2aredis\u5b9e\u4f8b\u4f5c\u4e3a\u4ece\u6570\u636e\u5e93\uff0c\u5e76\u8ba9\u5176\u76d1\u542c6380\u7aef\u53e3\uff1a<\/p>\n
\r\n$ redis-server --port 6380 --slaveof 127.0.0.1 6379 &\r\n<\/pre>\n\u67e5\u770b\u4e00\u4e0b\u5b9e\u4f8b\u7684\u542f\u52a8\u60c5\u51b5\uff1a<\/p>\n
\r\n$ ps aux | grep redis\r\nroot 2886 0.0 0.0 38652 4448 pts\/0 Sl 16:57 0:00 redis-server *:6379\r\nroot 2889 0.0 0.0 36604 4368 pts\/0 Sl 16:57 0:00 redis-server *:6380\r\n<\/pre>\n\u6b64\u65f6\u5728\u4e3b\u6570\u636e\u5e93\u4e2d\u7684\u4efb\u4f55\u6570\u636e\u53d8\u5316\u90fd\u4f1a\u81ea\u52a8\u540c\u6b65\u5230\u4ece\u6570\u636e\u5e93\u4e2d\uff0c\u6211\u4eec\u6253\u5f00redis-cli\u5b9e\u4f8bA\u5e76\u8fde\u63a5\u5230\u6570\u636e\u5e93\uff1a<\/p>\n
\r\n$ redis-cli -p 6379\r\n<\/pre>\n\u518d\u6253\u5f00redis-cli\u5b9e\u4f8bB\u5e76\u8fde\u63a5\u5230\u4ece\u6570\u636e\u5e93\uff1a<\/p>\n
\r\n$ redis-cli -p 6380\r\n<\/pre>\n\u8fd9\u65f6\u6211\u4eec\u4f7f\u7528INFO\u547d\u4ee4\u6765\u5206\u522b\u5728\u5b9e\u4f8bA\u548c\u5b9e\u4f8bB\u4e2d\u83b7\u53d6replication\u7684\u76f8\u5173\u4fe1\u606f\u3002<\/p>\n
\r\n127.0.0.1:6379> INfo replication\r\n# Replication\r\nrole:master\r\nconnected_slaves:1\r\nslave0:ip=127.0.0.1,port=6380,state=online,offset=266,lag=1\r\nmaster_repl_offset:266\r\nrepl_backlog_active:1\r\nrepl_backlog_size:1048576\r\nrepl_backlog_first_byte_offset:2\r\nrepl_backlog_histlen:265\r\n<\/pre>\n\u53ef\u4ee5\u770b\u5230\uff0c\u5b9e\u4f8bA\u7684\u89d2\u8272\uff08role\uff09\u662fmaster\uff0c\u5373\u4e3b\u6570\u636e\u5e93\uff0c\u540c\u65f6\u5df2\u8fde\u63a5\u7684\u4ece\u6570\u636e\u5e93\uff08connectd_slaves\uff09\u7684\u4e2a\u6570\u4e3a1\u4e2a\u3002<\/p>\n
\u540c\u6837\u5728\u5b9e\u4f8bB\u4e2d\u83b7\u53d6\u54cd\u5e94\u7684\u4fe1\u606f\u4e3a\uff1a<\/p>\n
\r\n127.0.0.1:6380> INfo replication\r\n# Replication\r\nrole:slave\r\nmaster_host:127.0.0.1\r\nmaster_port:6379\r\nmaster_link_status:up\r\nmaster_last_io_seconds_ago:9\r\nmaster_sync_in_progress:0\r\nslave_repl_offset:378\r\nslave_priority:100\r\nslave_read_only:1\r\nconnected_slaves:0\r\nmaster_repl_offset:0\r\nrepl_backlog_active:0\r\nrepl_backlog_size:1048576\r\nrepl_backlog_first_byte_offset:0\r\nrepl_backlog_histlen:0\r\n<\/pre>\n\u53ef\u4ee5\u770b\u5230\uff0c\u5b9e\u4f8bB\u7684role\u662fslave\uff0c\u5373\u4ece\u6570\u636e\u5e93\uff0c\u540c\u65f6\u5176\u4e3b\u6570\u636e\u5e93\u7684\u5730\u5740\u4e3a127.0.0.1\uff0c\u7aef\u53e3\u4e3a6379\u3002<\/p>\n
\u7136\u540e\u6211\u4eec\u5728\u5b9e\u4f8bA\u4e2d\u4f7f\u7528SET\u547d\u4ee4\u8bbe\u7f6e\u4e00\u4e2a\u952e\u7684\u503c\uff1a<\/p>\n
\r\n127.0.0.1:6379> set foo bar\r\nOK\r\n<\/pre>\n\u6b64\u65f6\u5728\u5b9e\u4f8bB\u4e2d\u5c31\u53ef\u4ee5\u83b7\u5f97\u8be5\u503c\u4e86\uff1a<\/p>\n
\r\n127.0.0.1:6380> get foo\r\n\"bar\"\r\n<\/pre>\n\u8bc1\u660e\u4e24\u4e2aRedis\u5b9e\u4f8b\u7684\u590d\u5236\u529f\u80fd\u5df2\u7ecf\u53ef\u7528\u4e86\u3002\u9ed8\u8ba4\u60c5\u51b5\uff0c\u4ece\u6570\u636e\u5e93\u662f\u53ea\u8bfb\u7684\uff0c\u5982\u679c\u76f4\u63a5\u4fee\u6539\u4ece\u6570\u636e\u5e93\u7684\u6570\u636e\u4f1a\u51fa\u73b0\u9519\u8bef\uff0c\u5982\u4e0b\uff1a<\/p>\n
\r\n127.0.0.1:6380> set foo hey\r\n(error) READONLY You can't write against a read only slave.\r\n<\/pre>\n\u4f46\u4e5f\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u4ece\u6570\u636e\u5e93\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684slave-read-only=no\uff0c\u4ee5\u4f7f\u4ece\u6570\u636e\u5e93\u53ef\u5199\uff0c\u4f46\u662f\u56e0\u4e3a\u5bf9\u4ece\u6570\u636e\u5e93\u7684\u4efb\u4f55\u66f4\u6539\u90fd\u4e0d\u4f1a\u540c\u6b65\u7ed9\u4efb\u4f55\u5176\u4ed6\u6570\u636e\u5e93\uff0c\u5e76\u4e14\u4e00\u65e6\u4e3b\u6570\u636e\u5e93\u4e2d\u7684\u66f4\u65b0\u4e86\u8d4c\u8d62\u7684\u6570\u636e\u5c31\u4f1a\u8986\u76d6\u4ece\u6570\u636e\u5e93\u4e2d\u7684\u6539\u52a8\uff0c\u6240\u4ee5\u901a\u5e38\u573a\u666f\u4e0b\u4e0d\u5e94\u8be5\u8bbe\u7f6e\u4ece\u6570\u636e\u5e93\u53ef\u5199\uff0c\u4ee5\u514d\u5bfc\u81f4\u6613\u88ab\u5ffd\u7565\u7684\u6f5c\u5728\u5e94\u7528\u903b\u8f91\u9519\u8bef\u3002<\/p>\n
\u914d\u7f6e\u591a\u53f0\u4ece\u6570\u636e\u5e93\u7684\u65b9\u6cd5\u4e5f\u4e00\u6837\uff0c\u5728\u6240\u6709\u7684\u4ece\u6570\u636e\u5e93\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u90fd\u52a0\u4e0asalveof\u53c2\u6570\u6307\u5411\u540c\u4e00\u4e2a\u4e3b\u6570\u636e\u5e93\u5373\u53ef\u3002\u9664\u4e86\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u6216\u547d\u4ee4\u884c\u53c2\u6570\u8bbe\u7f6eslaveof\u53c2\u6570\u5916\uff0c\u8fd8\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u4f7f\u7528slaveof\u547d\u4ee4\u4fee\u6539\uff0c\u4e0b\u9762\u6211\u4eec\u518d\u6dfb\u52a0\u4e00\u4e2a\u5b9e\u4f8bC\uff086381\uff09\uff1a<\/p>\n
\r\n$ redis-server --port 6381 &\r\n$ redis-cli -p 6381\r\n127.0.0.1:6381> slaveof 127.0.0.1 6379\r\n127.0.0.1:6381> get foo\r\n\"bar\"\r\n<\/pre>\n\u5982\u679c\u8be5\u6570\u636e\u5e93\u5df2\u7ecf\u662f\u5176\u4ed6\u4e3b\u6570\u636e\u5e93\u7684\u4ece\u6570\u636e\u5e93\u4e86\uff0cslaveof\u547d\u4ee4\u4f1a\u505c\u6b62\u548c\u539f\u6765\u6570\u636e\u5e93\u7684\u540c\u6b65\u8f6c\u800c\u548c\u65b0\u6570\u636e\u5e93\u540c\u6b65\uff0c\u6b64\u5916\u5bf9\u4e8e\u4ece\u6570\u636e\u5e93\u6765\u8bf4\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528slaveof no one\u547d\u4ee4\u6765\u4f7f\u5f53\u524d\u6570\u636e\u5e93\u505c\u6b62\u63a5\u6536\u5176\u4ed6\u6570\u636e\u5e93\u7684\u540c\u6b65\u5e76\u8f6c\u6362\u6210\u4e3a\u4e3b\u6570\u636e\u5e93\u3002\u5982\u4e0b\u6d4b\u8bd5\uff0c\u5728\u4ece\u5e93\u5b9e\u4f8bC\u4e0a\u5199\u5165\u6570\u636e\u65f6\u65f6\u4e0d\u5141\u8bb8\u7684\uff0c\u7136\u540e\u4f7f\u7528slaveof no one\u5c06\u6b64\u6570\u636e\u5e93\u8f6c\u6362\u4e3a\u4e3b\u6570\u636e\u5e93\uff0c\u7136\u540e\u518d\u5199\u5165\u6570\u636e\u5c31\u6ca1\u6709\u95ee\u9898\u4e86\u3002\u4e00\u822c\u7528\u4e8e\u4f46\u4e3b\u8282\u70b9\u6302\u6389\u7684\u65f6\u5019\uff0c\u7acb\u523b\u628a\u4ece\u8282\u70b9\u5207\u6362\u4e3a\u4e3b\u8282\u70b9\u63d0\u4f9b\u6570\u636e\u64cd\u4f5c\u670d\u52a1\u3002<\/p>\n
\r\n127.0.0.1:6381> set foo bar\r\n(error) READONLY You can't write against a read only slave.\r\n127.0.0.1:6381> SLAVEOF no one\r\n5493:M 07 Aug 17:23:06.792 # Connection with master lost.\r\n5493:M 07 Aug 17:23:06.792 * Caching the disconnected master state.\r\n5493:M 07 Aug 17:23:06.792 * Discarding previously cached master state.\r\n5493:M 07 Aug 17:23:06.792 * MASTER MODE enabled (user request from 'id=2 addr=127.0.0.1:40825 fd=6 name= age=348 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=slaveof')\r\n2886:M 07 Aug 17:23:06.792 # Connection with slave 127.0.0.1:6381 lost.\r\nOK\r\n127.0.0.1:6381> set foo bar\r\nOK\r\n<\/pre>\n\u590d\u5236\u5e38\u7528\u53c2\u6570<\/p>\n
\r\nslaveof\r\n<\/masterport><\/masterip><\/pre>\n \u5c06\u5f53\u524dserver\u505a\u4e3aslave\uff0c\u5e76\u4e3a\u5176\u6307\u5b9amaster\u4fe1\u606f\u3002<\/p>\n
\r\nmasterauth\r\n<\/master><\/pre>\n \u4ee5\u8ba4\u8bc1\u7684\u65b9\u5f0f\u8fde\u63a5\u5230master\uff0c\u5982\u679cmaster\u4e2d\u4f7f\u7528\u4e86\u201d\u5bc6\u7801\u4fdd\u62a4\u201d\uff0cslave\u5fc5\u987b\u4ea4\u4ed8\u6b63\u786e\u7684\u6388\u6743\u5bc6\u7801\uff0c\u624d\u80fd\u8fde\u63a5\u6210\u529f\u3002\u201drequirepas\u201d\u914d\u7f6e\u9879\u6307\u5b9a\u4e86\u5f53\u524dserver\u7684\u5bc6\u7801\u3002\u6b64\u914d\u7f6e\u9879\u4e2d
\u503c\u9700\u8981\u548cmaster\u673a\u5668\u7684\u201drequirepas\u201d\u4fdd\u6301\u4e00\u81f4\u3002\u6b64\u53c2\u6570\u914d\u7f6e\u5728slave\u7aef\u3002<\/p>\n \r\nslave-serve-stale-data yes\r\n<\/pre>\n\u5982\u679c\u5f53\u524dserver\u662fslave\uff0c\u90a3\u4e48\u5f53slave\u4e0emaster\u5931\u53bb\u901a\u8baf\u65f6\uff0c\u662f\u5426\u7ee7\u7eed\u4e3a\u5ba2\u6237\u7aef\u63d0\u4f9b\u670d\u52a1\uff0c\u201dyes\u201d\u8868\u793a\u7ee7\u7eed,\u201dno\u201d\u8868\u793a\u7ec8\u6b62\u3002\u5728\u201dyes\u201d\u60c5\u51b5\u4e0b\uff0cslave\u7ee7\u7eed\u5411\u5ba2\u6237\u7aef\u63d0\u4f9b\u53ea\u8bfb\u670d\u52a1\uff0c\u6709\u53ef\u80fd\u6b64\u65f6\u7684\u6570\u636e\u5df2\u7ecf\u8fc7\u671f\u3002\u5728\u201dno\u201d\u60c5\u51b5\u4e0b\uff0c\u4efb\u4f55\u5411\u6b64server\u53d1\u9001\u7684\u6570\u636e\u8bf7\u6c42\u670d\u52a1(\u5305\u62ec\u5ba2\u6237\u7aef\u548c\u6b64server\u7684slave)\u90fd\u5c06\u88ab\u544a\u77e5\u201derror\u201d\u3002<\/p>\n
\r\nslave-read-only yes\r\n\r\nslave\u662f\u5426\u4e3a\u201d\u53ea\u8bfb\u201d\uff0c\u5f3a\u70c8\u5efa\u8bae\u4e3a\u201dyes\u201d\u3002\r\n\r\nrepl-ping-slave-period 10\r\n\r\nslave\u5411\u6307\u5b9a\u7684master\u53d1\u9001ping\u6d88\u606f\u7684\u65f6\u95f4\u95f4\u9694(\u79d2)\uff0c\u9ed8\u8ba4\u4e3a10\u3002\r\n\r\nrepl-timeout 60\r\n\r\nslave\u4e0emaster\u901a\u8baf\u4e2d\uff0c\u6700\u5927\u7a7a\u95f2\u65f6\u95f4\uff0c\u9ed8\u8ba460\u79d2\uff0c\u8d85\u65f6\u5c06\u5bfc\u81f4\u8fde\u63a5\u5173\u95ed\u3002\r\n\r\nrepl-disable-tcp-nodelay no\r\n\r\nslave\u4e0emaster\u7684\u8fde\u63a5\uff0c\u662f\u5426\u7981\u7528TCP nodelay\u9009\u9879\u3002\u201dyes\u201d\u8868\u793a\u7981\u7528\uff0c\u90a3\u4e48socket\u901a\u8baf\u4e2d\u6570\u636e\u5c06\u4f1a\u4ee5packet\u65b9\u5f0f\u53d1\u9001(packet\u5927\u5c0f\u53d7\u5230socket buffer\u9650\u5236)\uff0c\u53ef\u4ee5\u63d0\u9ad8socket\u901a\u8baf\u7684\u6548\u7387(tcp\u4ea4\u4e92\u6b21\u6570)\uff0c\u4f46\u662f\u5c0f\u6570\u636e\u5c06\u4f1a\u88abbuffer\uff0c\u4e0d\u4f1a\u88ab\u7acb\u5373\u53d1\u9001\uff0c\u5bf9\u4e8e\u63a5\u53d7\u8005\u53ef\u80fd\u5b58\u5728\u5ef6\u8fdf\u3002\u201dno\u201d\u8868\u793a\u5f00\u542ftcp nodelay\u9009\u9879\uff0c\u4efb\u4f55\u6570\u636e\u90fd\u4f1a\u88ab\u7acb\u5373\u53d1\u9001\uff0c\u53ca\u65f6\u6027\u8f83\u597d\uff0c\u4f46\u662f\u6548\u7387\u8f83\u4f4e\u3002\u5efa\u8bae\u4e3a\u201dno\u201d\u3002\r\n\r\nslave-priority 100\r\n\r\n\u9002\u7528Sentinel\u6a21\u5757(unstable,M-S\u96c6\u7fa4\u7ba1\u7406\u548c\u76d1\u63a7)\uff0c\u9700\u8981\u989d\u5916\u7684\u914d\u7f6e\u6587\u4ef6\u652f\u6301\u3002slave\u7684\u6743\u91cd\u503c\uff0c\u9ed8\u8ba4100\u3002\u5f53master\u5931\u6548\u540e\uff0cSentinel\u5c06\u4f1a\u4eceslave\u5217\u8868\u4e2d\u627e\u5230\u6743\u91cd\u503c\u6700\u4f4e(>0)\u7684slave\uff0c\u5e76\u63d0\u5347\u4e3amaster\u3002\u5982\u679c\u6743\u91cd\u503c\u4e3a0\uff0c\u8868\u793a\u6b64slave\u4e3a\u201d\u89c2\u5bdf\u8005\u201d\uff0c\u4e0d\u53c2\u4e0emaster\u9009\u4e3e\u3002\r\n<\/pre>\n\u4e86\u89e3Redis\u7684\u590d\u5236\u539f\u7406<\/strong><\/span><\/div>\n\u4e86\u89e3Redis\u590d\u5236\u7684\u539f\u7406\u5bf9\u8fd0\u7ef4Redis\u8fc7\u7a0b\u4e2d\u6709\u5f88\u5927\u7684\u5e2e\u52a9\uff0c\u5305\u62ec\u5982\u4f55\u89c4\u5212\u8282\u70b9\uff0c\u5982\u679c\u5904\u7406\u8282\u70b9\u6545\u969c\u7b49\u3002\u4e0b\u9762\u4ecb\u7ecdRedis\u5b9e\u73b0\u590d\u5236\u7684\u5de5\u7a0b\u3002
\n<\/p>\n\u5f53\u4e00\u4e2a\u4ece\u6570\u636e\u5e93\u542f\u52a8\u540e\uff0c\u4f1a\u5411\u4e3b\u6570\u636e\u5e93\u53d1\u9001SYNC\u547d\u4ee4\uff0c\u540c\u65f6\u4e3b\u6570\u636e\u5e93\u63a5\u6536\u5230SYNC\u547d\u4ee4\u540e\u4f1a\u5f00\u59cb\u5728\u540e\u53f0\u4fdd\u5b58\u5feb\u7167\uff08\u5373RDB\u6301\u4e45\u5316\u7684\u8fc7\u7a0b\uff09\uff0c\u5e76\u5c06\u4fdd\u5b58\u5feb\u7167\u671f\u95f4\u63a5\u6536\u5230\u7684\u547d\u4ee4\u7f13\u5b58\u8d77\u6765\uff0c\u5f53\u5feb\u7167\u5b8c\u6210\u540e\uff0cRedis Master\u4f1a\u5c06\u5feb\u7167\u6587\u4ef6\u53d1\u9001\u7ed9\u4ece\u6570\u636e\u5e93\uff0c\u4ece\u6570\u636e\u5e93\u6536\u5230\u540e\uff0c\u4f1a\u8f7d\u5165\u5feb\u7167\u6587\u4ef6\u3002\u4e4b\u540eRedis Master\u4f1a\u4ee5Redis\u547d\u4ee4\u534f\u8bae\u7684\u683c\u5f0f\uff0c\u5c06\u5199\u547d\u4ee4\u7f13\u51b2\u533a\u4e2d\u79ef\u7d2f\u7684\u6240\u6709\u5185\u5bb9\u90fd\u53d1\u9001\u7ed9\u4ece\u670d\u52a1\u5668\u3002\u4ee5\u4e0a\u8fc7\u7a0b\u79f0\u4e3a\u590d\u5236\u521d\u59cb\u5316\uff0c\u590d\u5236\u521d\u59cb\u5316\u7ed3\u675f\u540e\uff0c\u4e3b\u6570\u636e\u5e93\u6bcf\u5f53\u6536\u5230\u5199\u547d\u4ee4\u65f6\u5c31\u4f1a\u5c06\u547d\u4ee4\u540c\u6b65\u7ed9\u4ece\u6570\u636e\u5e93\uff0c\u4ece\u800c\u4fdd\u8bc1\u4e3b\u4ece\u6570\u636e\u5e93\u6570\u636e\u4e00\u81f4\u3002<\/p>\n
\u4f60\u53ef\u4ee5\u901a\u8fc7telnet\u547d\u4ee4\u6765\u4eb2\u81ea\u9a8c\u8bc1\u8fd9\u4e2a\u540c\u6b65\u8fc7\u7a0b\uff1a\u9996\u5148\u8fde\u4e0a\u4e00\u4e2a\u6b63\u5728\u5904\u7406\u547d\u4ee4\u8bf7\u6c42\u7684Redis\u670d\u52a1\u5668\uff0c\u7136\u540e\u5411\u5b83\u53d1\u9001SYNC\u547d\u4ee4\uff0c\u8fc7\u4e00\u9635\u5b50\uff0c\u4f60\u5c06\u4f1a\u770b\u5230telnet\u4f1a\u8bdd\u63a5\u6536\u5230\u670d\u52a1\u5668\u53d1\u6765\u7684\u5927\u6bb5\u6570\u636e\uff08.rdb\u6587\u4ef6\uff09\uff0c\u4e4b\u540e\u8fd8\u4f1a\u770b\u5230\uff0c\u6240\u6709\u7684\u670d\u52a1\u5668\u6267\u884c\u8fc7\u7684\u5199\u547d\u4ee4\uff0c\u90fd\u4f1a\u91cd\u65b0\u53d1\u9001\u5230telnet\u4f1a\u8bdd\u6765\u3002<\/p>\n
\u5f53\u4e3b\u4ece\u6570\u636e\u5e93\u4e4b\u95f4\u7684\u8fde\u63a5\u65ad\u5f00\u91cd\u8fde\u540e\uff0cRedis 2.6\u4ee5\u53ca\u4e4b\u524d\u7684\u7248\u672c\u4f1a\u91cd\u65b0\u8fdb\u884c\u590d\u5236\u521d\u59cb\u5316\uff08\u5373\u4e3b\u6570\u636e\u5e93\u91cd\u65b0\u4fdd\u5b58\u5feb\u7167\u5e76\u4f20\u9001\u7ed9\u4ece\u6570\u636e\u5e93\uff09\uff0c\u5373\u4f7f\u4ece\u6570\u636e\u5e93\u53ef\u4ee5\u4ec5\u6709\u51e0\u6761\u547d\u4ee4\u6ca1\u6709\u6536\u5230\uff0c\u4e3b\u6570\u636e\u5e93\u4e5f\u5fc5\u987b\u8981\u5c06\u6570\u636e\u5e93\u91cc\u7684\u6240\u6709\u6570\u636e\u91cd\u65b0\u4f20\u9001\u7ed9\u4ece\u6570\u636e\u5e93\u3002\u8fd9\u4f7f\u5f97\u4e3b\u4ece\u6570\u636e\u5e93\u65ad\u7ebf\u91cd\u8fde\u540e\u7684\u6570\u636e\u6062\u590d\u8fc7\u7a0b\u6548\u7387\u5f88\u4f4e\u4e0b\uff0c\u5728\u7f51\u7edc\u73af\u5883\u4e0d\u597d\u7684\u65f6\u5019\u8fd9\u4e00\u95ee\u9898\u5c24\u5176\u660e\u663e\uff0cRedis 2.8\u7248\u672c\u7684\u4e00\u4e2a\u91cd\u8981\u6539\u8fdb\u5c31\u662f\u65ad\u7ebf\u91cd\u8fde\u80fd\u591f\u652f\u6301\u6709\u6761\u4ef6\u7684\u589e\u91cf\u6570\u636e\u4f20\u8f93\uff0c\u5f53\u4ece\u6570\u636e\u5e93\u91cd\u65b0\u8fde\u63a5\u4e0a\u4e3b\u6570\u636e\u5e93\u540e\uff0c\u4e3b\u6570\u636e\u5e93\u53ea\u9700\u8981\u5c06\u65ad\u7ebf\u671f\u95f4\u6267\u884c\u7684\u547d\u4ee4\u4f20\u9001\u7ed9\u4ece\u6570\u636e\u5e93\uff0c\u4ece\u800c\u5927\u5927\u63d0\u9ad8Redis\u590d\u5236\u7684\u5b9e\u7528\u6027\u3002<\/p>\n
\u589e\u91cf\u590d\u5236\u7684\u5b9e\u73b0\uff0c\u57fa\u4e8e\u4ee5\u4e0b3\u70b9\uff1a<\/strong><\/span><\/div>\n1\uff09\u4ece\u6570\u636e\u5e93\u4f1a\u5b58\u50a8\u4e3b\u6570\u636e\u5e93\u7684\u8fd0\u884cID\uff08run id\uff09\uff0c\u6bcf\u4e2aRedis\u8fd0\u884c\u5b9e\u4f8b\u5747\u4f1a\u62e5\u6709\u4e00\u4e2a\u552f\u4e00\u7684\u8fd0\u884cID\uff0c\u6bcf\u5f53\u5b9e\u4f8b\u91cd\u542f\u540e\uff0c\u5c31\u4f1a\u81ea\u52a8\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u8fd0\u884cID\u3002<\/p>\n
2\uff09\u5728\u590d\u5236\u540c\u6b65\u9636\u6bb5\uff0c\u4e3b\u6570\u636e\u5e93\u6bcf\u5c06\u4e00\u4e2a\u547d\u4ee4\u4f20\u9001\u7ed9\u4ece\u6570\u636e\u5e93\u65f6\uff0c\u90fd\u4f1a\u540c\u65f6\u628a\u8be5\u547d\u4ee4\u5b58\u653e\u5230\u4e00\u4e2a\u79ef\u538b\u961f\u5217\uff08backlog\uff09\u4e2d\uff0c\u5e76\u8bb0\u5f55\u4e0b\u5f53\u524d\u79ef\u538b\u961f\u5217\u4e2d\u5b58\u653e\u7684\u547d\u4ee4\u7684\u504f\u79fb\u91cf\u8303\u56f4\u3002<\/p>\n
3\uff09\u540c\u65f6\uff0c\u4ece\u6570\u636e\u5e93\u63a5\u6536\u5230\u4e3b\u6570\u636e\u5e93\u4f20\u6765\u7684\u547d\u4ee4\u65f6\uff0c\u4f1a\u8bb0\u5f55\u4e0b\u8be5\u547d\u4ee4\u7684\u504f\u79fb\u91cf\u3002<\/p>\n
\u8fd9\u4e09\u70b9\u662f\u5b9e\u73b0\u589e\u91cf\u590d\u5236\u7684\u57fa\u7840\uff0c\u5f53\u4e3b\u4ece\u8fde\u63a5\u51c6\u5907\u5c31\u7eea\u540e\uff0c\u4ece\u6570\u636e\u5e93\u4f1a\u53d1\u9001\u4e00\u6761SYNC\u547d\u4ee4\u6765\u544a\u8bc9\u4e3b\u6570\u636e\u5e93\u53ef\u4ee5\u5f00\u59cb\u628a\u6240\u6709\u6570\u636e\u540c\u6b65\u8fc7\u6765\u4e86\u3002\u800c2.8\u7248\u672c\u4e4b\u540e\uff0c\u4e0d\u518d\u53d1\u9001SYNC\u547d\u4ee4\uff0c\u53d6\u800c\u4ee3\u4e4b\u7684\u662f\u53d1\u9001PSYNC\uff0c\u683c\u5f0f\u4e3a\u201cPSYNC \u4e3b\u6570\u636e\u5e93\u7684\u8fd0\u884cID \u65ad\u5f00\u524d\u6700\u65b0\u7684\u547d\u4ee4\u504f\u79fb\u91cf\u201d\u3002\u4e3b\u6570\u636e\u5e93\u6536\u5230PSYNC\u547d\u4ee4\u540e\uff0c\u4f1a\u6267\u884c\u4ee5\u4e0b\u5224\u65ad\u6765\u51b3\u5b9a\u6b64\u6b21\u91cd\u8fde\u662f\u5426\u53ef\u4ee5\u6267\u884c\u589e\u91cf\u590d\u5236\u3002<\/p>\n
1\uff09\u9996\u5148\u4e3b\u6570\u636e\u5e93\u4f1a\u5224\u65ad\u4ece\u6570\u636e\u5e93\u4f20\u9001\u6765\u7684\u8fd0\u884cID\u662f\u5426\u548c\u81ea\u5df1\u7684\u8fd0\u884cID\u76f8\u540c\uff0c\u8fd9\u4e00\u6b65\u9aa4\u7684\u610f\u4e49\u5728\u4e8e\u786e\u4fdd\u4ece\u6570\u636e\u5e93\u4e4b\u524d\u786e\u5b9e\u662f\u548c\u81ea\u5df1\u540c\u6b65\u7684\uff0c\u4ee5\u514d\u4ece\u6570\u636e\u5e93\u62ff\u5230\u9519\u8bef\u7684\u6570\u636e\uff08\u5982\u4e3b\u6570\u636e\u5e93\u5728\u65ad\u8fde\u671f\u95f4\u91cd\u542f\u8fc7\uff0c\u4f1a\u9020\u6210\u6570\u636e\u7684\u4e0d\u4e00\u81f4\u6027\uff09\u3002<\/p>\n
2\uff09\u7136\u540e\u5224\u65ad\u4ece\u6570\u636e\u5e93\u6700\u540e\u540c\u6b65\u6210\u529f\u7684\u547d\u4ee4\u504f\u79fb\u91cf\u662f\u5426\u5728\u79ef\u538b\u961f\u5217\u4e2d\uff0c\u5982\u679c\u5728\u5219\u53ef\u4ee5\u6267\u884c\u589e\u91cf\u590d\u5236\uff0c\u5e76\u5c06\u79ef\u538b\u961f\u5217\u4e2d\u76f8\u5e94\u7684\u547d\u4ee4\u53d1\u9001\u7ed9\u4ece\u6570\u636e\u5e93\u3002<\/p>\n
\u5982\u679c\u6b64\u6b21\u91cd\u8fde\u4e0d\u6ee1\u8db3\u589e\u91cf\u590d\u5236\u7684\u6761\u4ef6\uff0c\u4e3b\u6570\u636e\u4f1a\u8fdb\u884c\u4e00\u6b21\u5168\u90e8\u540c\u6b65\uff08\u5373\u4e0eRedis 2.6\u7684\u8fc7\u7a0b\u76f8\u540c\uff09\uff0c\u5927\u90e8\u5206\u60c5\u51b5\u4e0b\uff0c\u589e\u91cf\u590d\u5236\u7684\u8fc7\u7a0b\u5bf9\u5f00\u53d1\u8005\u6765\u8bf4\u662f\u5b8c\u5168\u900f\u660e\u7684\uff0c\u5f00\u53d1\u8005\u4e0d\u9700\u8981\u5173\u5fc3\u589e\u91cf\u590d\u5236\u7684\u5177\u4f53\u7ec6\u8282\uff0c2.8\u7248\u672c\u7684\u4e3b\u6570\u636e\u5e93\u4e5f\u53ef\u4ee5\u6b63\u5e38\u5730\u548c\u65e7\u7248\u672c\u7684\u4ece\u6570\u636e\u5e93\u540c\u6b65\uff08\u901a\u8fc7\u63a5\u6536SYNC\u547d\u4ee4\uff09\uff0c\u540c\u68372.8\u7248\u672c\u7684\u4ece\u6570\u636e\u5e93\u4e5f\u53ef\u4ee5\u4e0e\u65e7\u7248\u672c\u7684\u4e3b\u6570\u636e\u5e93\u540c\u6b65\uff08\u901a\u8fc7\u53d1\u9001SYNC\u547d\u4ee4\uff09\uff0c\u552f\u4e00\u9700\u8981\u5f00\u53d1\u8005\u8bbe\u7f6e\u7684\u5c31\u662f\u79ef\u538b\u961f\u5217\u7684\u5927\u5c0f\u4e86\u3002<\/p>\n
\u79ef\u538b\u961f\u5217\u5728\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u56fa\u5b9a\u957f\u5ea6\u7684\u5faa\u73af\u961f\u5217\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u79ef\u538b\u961f\u5217\u7684\u5927\u5c0f\u4e3a1MB\uff0c\u53ef\u4ee5\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u7684repl-backlog-size\u9009\u9879\u6765\u8c03\u6574\u3002\u5f88\u5bb9\u6613\u7406\u89e3\u7684\u662f\uff0c\u79ef\u538b\u961f\u5217\u8d8a\u5927\uff0c\u5176\u5141\u8bb8\u7684\u4e3b\u4ece\u6570\u636e\u5e93\u65ad\u7ebf\u7684\u65f6\u95f4\u5c31\u8d8a\u957f\u3002\u6839\u636e\u4e3b\u4ece\u6570\u636e\u5e93\u4e4b\u95f4\u7684\u7f51\u7edc\u72b6\u6001\uff0c\u8bbe\u7f6e\u4e00\u4e2a\u5408\u7406\u7684\u79ef\u538b\u961f\u5217\u5f88\u91cd\u8981\u3002\u56e0\u4e3a\u79ef\u538b\u961f\u5217\u5b58\u50a8\u7684\u5185\u5bb9\u662f\u547d\u4ee4\u672c\u8eab\uff0c\u5982 SET FOO BAR\uff0c\u6240\u4ee5\u4f30\u7b97\u79ef\u538b\u961f\u5217\u7684\u5927\u5c0f\u53ea\u9700\u8981\u4f30\u8ba1\u4e3b\u4ece\u6570\u636e\u5e93\u65ad\u7ebf\u7684\u65f6\u95f4\u4e2d\u4e3b\u4ece\u6570\u636e\u5e93\u53ef\u80fd\u6267\u884c\u7684\u547d\u4ee4\u7684\u5927\u5c0f\u5373\u53ef\u3002\u4e0e\u79ef\u538b\u961f\u5217\u76f8\u5173\u7684\u53e6\u4e00\u4e2a\u914d\u7f6e\u9009\u9879\u662frepl-backlog-ttl\uff0c\u5373\u5f53\u6240\u6709\u4e3b\u4ece\u6570\u636e\u5e93\u4e0e\u4e3b\u6570\u636e\u65ad\u5f00\u8fde\u63a5\u540e\uff0c\u7ecf\u8fc7\u591a\u4e45\u65f6\u95f4\u53ef\u4ee5\u91ca\u653e\u79ef\u538b\u961f\u5217\u7684\u5185\u5b58\u7a7a\u95f4\uff0c\u9ed8\u8ba4\u65f6\u95f4\u662f1\u5c0f\u65f6\u3002<\/p>\n
\u4ece\u6570\u636e\u5e93\u6301\u4e45\u5316<\/strong><\/span><\/div>\n\u53e6\u4e00\u4e2a\u76f8\u5bf9\u8017\u65f6\u7684\u64cd\u4f5c\u662f\u6301\u4e45\u5316\uff0c\u4e3a\u4e86\u63d0\u9ad8\u6027\u80fd\uff0c\u53ef\u4ee5\u901a\u8fc7\u590d\u5236\u529f\u80fd\u5efa\u7acb\u4e00\u4e2a\u6216\u591a\u4e2a\u4ece\u6570\u636e\u5e93\uff0c\u5e76\u5728\u4ece\u6570\u636e\u5e93\u4e2d\u542f\u7528\u6301\u4e45\u5316\uff0c\u540c\u65f6\u5728\u4e3b\u6570\u636e\u5e93\u7981\u7528\u6301\u4e45\u5316\uff0c\u5f53\u4ece\u6570\u636e\u5e93\u5d29\u6e83\u91cd\u542f\u540e\u4e3b\u6570\u636e\u5e93\u4f1a\u81ea\u52a8\u5c06\u65f6\u95f4\u540c\u6b65\u8fc7\u6765\uff0c\u6240\u4ee5\u65e0\u9700\u62c5\u5fc3\u6570\u636e\u4e22\u5931\u3002<\/p>\n
\u7136\u540e\u5f53\u4e3b\u6570\u636e\u5e93\u5d29\u6e83\u65f6\uff0c\u60c5\u51b5\u5c31\u7a0d\u663e\u590d\u6742\u4e86\u3002\u624b\u5de5\u901a\u8fc7\u4ece\u6570\u636e\u5e93\u6570\u636e\u6062\u590d\u4e3b\u6570\u636e\u5e93\u6570\u636e\u65f6\uff0c\u9700\u8981\u4e25\u683c\u6309\u7167\u4ee5\u4e0b\u4e24\u6b65\u8fdb\u884c\uff1a<\/p>\n
1\uff09\u5728\u4ece\u6570\u636e\u5e93\u4e2d\u4f7f\u7528SLAVEOF NO ONE\u547d\u4ee4\u5c06\u4ece\u6570\u636e\u5e93\u63d0\u5347\u4e3a\u4e3b\u6570\u636e\u5e93\u7ee7\u7eed\u670d\u52a1\u3002<\/p>\n
2\uff09\u542f\u52a8\u4e4b\u524d\u5d29\u6e83\u7684\u4e3b\u6570\u636e\u5e93\uff0c\u7136\u540e\u4f7f\u7528SLAVEOF\u547d\u4ee4\u5c06\u5176\u8bbe\u7f6e\u6210\u65b0\u7684\u4e3b\u6570\u636e\u5e93\u7684\u4ece\u6570\u636e\u5e93\uff0c\u5373\u53ef\u5c06\u6570\u636e\u540c\u6b65\u56de\u6765\u3002<\/p>\n
\u6ce8\u610f\uff0c\u5f53\u5f00\u542f\u590d\u5236\u4e14\u4e3b\u6570\u636e\u5e93\u5173\u95ed\u6301\u4e45\u5316\u7684\u65f6\u5019\uff0c\u4e00\u5b9a\u4e0d\u8981\u4f7f\u7528supervisor\u4ee5\u53ca\u7c7b\u4f3c\u7684\u8fdb\u7a0b\u7ba1\u7406\u5de5\u5177\u4ee4\u4e3b\u6570\u636e\u5e93\u5d29\u6e83\u540e\u81ea\u52a8\u91cd\u542f\u3002\u540c\u6837\u5f53\u4e3b\u6570\u636e\u5e93\u6240\u5728\u7684\u670d\u52a1\u5668\u56e0\u6545\u5173\u95ed\u65f6\uff0c\u4e5f\u8981\u907f\u514d\u76f4\u63a5\u91cd\u65b0\u542f\u52a8\u3002\u8fd9\u662f\u56e0\u4e3a\u5f53\u4e3b\u6570\u636e\u5e93\u91cd\u65b0\u542f\u52a8\u540e\uff0c\u56e0\u4e3a\u6ca1\u5f00\u6301\u4e45\u5316\u529f\u80fd\uff0c\u6240\u4ee5\u6570\u636e\u5e93\u4e2d\u6240\u6709\u6570\u636e\u90fd\u88ab\u6e05\u7a7a\uff0c\u8fd9\u65f6\u4ece\u6570\u636e\u5e93\u4f9d\u7136\u4f1a\u4ece\u4e3b\u6570\u636e\u5e93\u4e2d\u63a5\u6536\u6570\u636e\uff0c\u4f7f\u5f97\u6240\u6709\u4ece\u6570\u636e\u5e93\u4e5f\u88ab\u6e05\u7a7a\uff0c\u5bfc\u81f4\u4ece\u6570\u636e\u5e93\u7684\u6301\u4e45\u5316\u5931\u53bb\u610f\u4e49\u3002<\/p>\n
\u65e0\u8bba\u54ea\u79cd\u60c5\u51b5\uff0c\u624b\u5de5\u7ef4\u62a4\u4ece\u6570\u636e\u5e93\u6216\u4e3b\u6570\u636e\u7684\u91cd\u542f\u4ee5\u53ca\u6570\u636e\u6062\u590d\u90fd\u76f8\u5bf9\u9ebb\u70e6\uff0c\u597d\u5728Redis\u63d0\u4f9b\u4e86\u4e00\u79cd\u81ea\u52a8\u5316\u65b9\u6848\u54e8\u5175\u6765\u5b9e\u73b0\u8fd9\u4e00\u8fc7\u7a0b\uff0c\u907f\u514d\u4e86\u624b\u5de5\u7ef4\u62a4\u7684\u9ebb\u70e6\u548c\u5bb9\u6613\u51fa\u9519\u7684\u95ee\u9898\u3002<\/p>\n
\u65e0\u786c\u76d8\u590d\u5236<\/strong><\/span><\/div>\n\u4e0a\u9762\u4ecb\u7ecd\u4e86Redis\u590d\u5236\u7684\u5de5\u4f5c\u539f\u7406\u65f6\u4ecb\u7ecd\u4e86\u590d\u5236\u662f\u57fa\u4e8eRDB\u65b9\u5f0f\u7684\u6301\u4e45\u5316\u5b9e\u73b0\u7684\uff0c\u5373\u4e3b\u6570\u636e\u5e93\u7aef\u5728\u540e\u53f0\u4fdd\u5b58\u4e86RDB\u5feb\u7167\uff0c\u4ece\u6570\u636e\u5e93\u7aef\u5219\u63a5\u6536\u5e76\u8f7d\u5165\u5feb\u7167\u6587\u4ef6\uff0c\u8fd9\u6837\u7684\u5b9e\u73b0\u6709\u70b9\u662f\u53ef\u4ee5\u663e\u8457\u5730\u7b80\u5316\u903b\u8f91\uff0c\u590d\u7528\u5df2\u6709\u7684\u4ee3\u7801\uff0c\u4f46\u662f\u7f3a\u70b9\u4e5f\u5f88\u660e\u663e\u3002<\/p>\n
1\uff09\u5f53\u4e3b\u6570\u636e\u5e93\u7981\u7528RDB\u5feb\u7167\u65f6\uff08\u5373\u5220\u9664\u4e86\u6240\u6709\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684save\u8bed\u53e5\uff09\uff0c\u5982\u679c\u6267\u884c\u4e86\u590d\u5236\u521d\u59cb\u5316\u64cd\u4f5c\uff0cRedis\u4f9d\u7136\u4f1a\u751f\u6210RDB\u5feb\u7167\uff0c\u6240\u4ee5\u4e0b\u6b21\u542f\u52a8\u540e\u4e3b\u6570\u636e\u5e93\u4f1a\u4ee5\u8be5\u5feb\u7167\u6062\u590d\u6570\u636e\u3002\u56e0\u4e3a\u590d\u5236\u53d1\u751f\u7684\u65f6\u95f4\u4e0d\u80fd\u786e\u5b9a\uff0c\u8fd9\u4f7f\u5f97\u6062\u590d\u7684\u6570\u636e\u53ef\u80fd\u662f\u4efb\u4f55\u65f6\u95f4\u70b9\u7684\u3002<\/p>\n
2\uff09\u56e0\u4e3a\u590d\u5236\u521d\u59cb\u5316\u65f6\u9700\u8981\u5728\u786c\u76d8\u4e2d\u521b\u5efaRDB\u5feb\u7167\u6587\u4ef6\uff0c\u6240\u4ee5\u5982\u679c\u786c\u76d8\u6027\u80fd\u5f88\u6162\u65f6\u8fd9\u4e00\u8fc7\u7a0b\u4f1a\u5bf9\u6027\u80fd\u4ea7\u751f\u5f71\u54cd\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u5f53\u4f7f\u7528Redis\u505a\u7f13\u5b58\u7cfb\u7edf\u65f6\uff0c\u56e0\u4e3a\u4e0d\u9700\u8981\u6301\u4e45\u5316\uff0c\u6240\u4ee5\u670d\u52a1\u5668\u7684\u786c\u76d8\u8bfb\u5199\u901f\u5ea6\u53ef\u80fd\u8f83\u5dee\u3002\u4f46\u662f\u5f53\u8be5\u7f13\u5b58\u7cfb\u7edf\u4f7f\u7528\u4e00\u4e3b\u591a\u4ece\u7684\u96c6\u7fa4\u67b6\u6784\u65f6\uff0c\u6bcf\u6b21\u548c\u4ece\u6570\u636e\u5e93\u540c\u6b65\uff0cRedis\u90fd\u4f1a\u6267\u884c\u4e00\u6b21\u5feb\u7167\uff0c\u540c\u65f6\u5bf9\u786c\u76d8\u8fdb\u884c\u8bfb\u5199\uff0c\u5bfc\u81f4\u6027\u80fd\u4e0b\u964d\u3002<\/p>\n
\u56e0\u6b64\u4ece2.8.18\u7248\u672c\u5f00\u59cb\uff0cRedis\u5f15\u5165\u4e86\u65e0\u786c\u76d8\u590d\u5236\u9009\u9879\uff0c\u5f00\u542f\u8be5\u9009\u9879\u65f6\uff0cRedis\u5728\u4e0e\u4ece\u6570\u636e\u5e93\u8fdb\u884c\u590d\u5236\u521d\u59cb\u5316\u65f6\u5c06\u4e0d\u4f1a\u5c06\u5feb\u7167\u5185\u5bb9\u5b58\u50a8\u5230\u786c\u76d8\u4e0a\uff0c\u800c\u662f\u76f4\u63a5\u901a\u8fc7\u7f51\u7edc\u53d1\u9001\u7ed9\u4ece\u6570\u636e\u5e93\uff0c\u907f\u514d\u4e86\u786c\u76d8\u7684\u6027\u80fd\u74f6\u9888\u3002\u53ef\u4ee5\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u4f7f\u7528\u5982\u4e0b\u914d\u7f6e\u6765\u5f00\u542f\u8be5\u529f\u80fd\uff1a<\/p>\n
\r\nrepl-diskless-sync yes\r\n<\/pre>\nPS\uff1a\u5f53\u9700\u8981\u628aSlave\u8f6c\u6362\u4e3aMaster\u65f6\u53ef\u4ee5\u4f7f\u7528\u201dSLAVEOF ON ONE\u201d\u6307\u4ee4\u3002<\/master><\/p>\n","protected":false},"excerpt":{"rendered":"
\u5728\u751f\u4ea7\u73af\u5883\u4e2d\uff0cRedis\u901a\u8fc7\u6301\u4e45\u5316\u529f\u80fd\uff08RDB\u548cAOF\u6280\u672f\uff09\u4fdd\u8bc1\u4e86\u5373\u4f7f\u5728\u670d\u52a1\u5668\u91cd\u542f\u7684\u60c5\u51b5\u4e0b\u4e5f\u4e0d\u4f1a\u635f\u5931\uff08\u6216\u5c11\u91cf\u635f […]<\/p>\n","protected":false},"author":668,"featured_media":136089,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-136083","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/136083","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/668"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=136083"}],"version-history":[{"count":4,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/136083\/revisions"}],"predecessor-version":[{"id":136554,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/136083\/revisions\/136554"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/136089"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=136083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=136083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=136083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}