{"id":105457,"date":"2024-09-26T22:35:11","date_gmt":"2024-09-26T14:35:11","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=105457"},"modified":"2024-09-26T22:35:11","modified_gmt":"2024-09-26T14:35:11","slug":"redis-write-problem","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/redis-write-problem.html","title":{"rendered":"\u89e3\u51b3Redis\u4fdd\u5b58\u540e\u65e0\u6cd5\u5199\u5165\u95ee\u9898"},"content":{"rendered":"
\u4eca\u5929\u5f00\u53d1\u7a81\u7136\u548c\u6211\u8bf4Redis\u4e0d\u80fd\u5199\u4e86\u3002\u6211\u8fdb\u5165Redis\u540e\u53d1\u73b0\u786e\u5b9e\u662f\u8fd9\u6837\uff0c\u4e0d\u53ef\u4ee5\u6267\u884cset\u6307\u4ee4\u4e86\u3002\u62a5\u9519\u5982\u4e0b\uff1a<\/p>\n
172.31.18.90:6379> set\u00a0 test test1\r\n\r\n(error) MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error.<\/pre>\n\u4e4b\u524dredis\u4e00\u76f4\u662f\u6b63\u5e38\u7684\u3002\u4e0d\u662f\u6743\u9650\u95ee\u9898\u5bfc\u81f4\u7684\uff0c\u4e5f\u4e0d\u662f\u5185\u5b58\u8017\u5c3d\u901a\u8fc7\u67e5\u770blog\u53d1\u73b0\u662f\u8fd9\u4e2a\u62a5\u9519fork: Cannot allocate memory<\/p>\n
\u5728\u5c0f\u5185\u5b58\u7684\u8fdb\u7a0b\u4e0a\u505a\u4e00\u4e2afork,\u4e0d\u9700\u8981\u592a\u591a\u8d44\u6e90\uff0c\u4f46\u5f53\u8fd9\u4e2a\u8fdb\u7a0b\u7684\u5185\u5b58\u7a7a\u95f4\u4ee5\uff27\u4e3a\u5355\u4f4d\u65f6\uff0cfork\u5c31\u6210\u4e3a\u4e00\u4ef6\u5f88\u6050\u6016\u7684\u64cd\u4f5c\u3002\u4f55\u51b5\u572816G\u5185\u5b58\u7684\u4e3b\u673a\u4e0afork 14G\u5185\u5b58\u7684\u8fdb\u7a0b\u5462\uff1f\u80af\u5b9a\u4f1a\u62a5\u5185\u5b58\u65e0\u6cd5\u5206\u914d\u7684\u3002\u66f4\u53ef\u6c14\u7684\u662f\uff0c\u8d8a\u662f\u6539\u52a8\u9891\u7e41\u7684\u4e3b\u673a\u4e0afork\u4e5f\u8d8a\u9891\u7e41\uff0cfork\u64cd\u4f5c\u672c\u8eab\u7684\u4ee3\u4ef7\u6050\u6015\u4e5f\u4e0d\u4f1a\u6bd4\u5047\u6b7b\u597d\u591a\u5c11\u3002\u627e\u5230\u539f\u56e0\u4e4b\u540e\uff0c\u76f4\u63a5\u4fee\u6539\u5185\u6838\u53c2\u6570 vm.overcommit_memory = 1,sysctl -p \u4f7f\u5185\u6838\u53c2\u6570\u751f\u6548.<\/p>\n
<\/p>\n
\u53c2\u6570\u89e3\u91ca\uff1a<\/strong><\/span><\/div>\nLinux\u5185\u6838\u4f1a\u6839\u636e\u53c2\u6570vm.overcommit_memory\u53c2\u6570\u7684\u8bbe\u7f6e\u51b3\u5b9a\u662f\u5426\u653e\u884c\u3002<\/p>\n
\u5982\u679c vm.overcommit_memory = 1\uff0c\u76f4\u63a5\u653e\u884cvm.overcommit_memory = 0\uff1a\u5219\u6bd4\u8f83 \u6b64\u6b21\u8bf7\u6c42\u5206\u914d\u7684\u865a\u62df\u5185\u5b58\u5927\u5c0f\u548c\u7cfb\u7edf\u5f53\u524d\u7a7a\u95f2\u7684\u7269\u7406\u5185\u5b58\u52a0\u4e0aswap\uff0c\u51b3\u5b9a\u662f\u5426\u653e\u884c\u3002vm.overcommit_memory = 2\uff1a\u5219\u4f1a\u6bd4\u8f83 \u8fdb\u7a0b\u6240\u6709\u5df2\u5206\u914d\u7684\u865a\u62df\u5185\u5b58\u52a0\u4e0a\u6b64\u6b21\u8bf7\u6c42\u5206\u914d\u7684\u865a\u62df\u5185\u5b58\u548c\u7cfb\u7edf\u5f53\u524d\u7684\u7a7a\u95f2\u7269\u7406\u5185\u5b58\u52a0\u4e0aswap\uff0c\u51b3\u5b9a\u662f\u5426\u653e\u884c\u3002<\/p>\n
\u8fd9\u91cc\u5728\u91cd\u65b0\u53d1\u4e00\u4e0bredis \u7684\u56de\u5199\u673a\u5236,Redis\u7684\u6570\u636e\u56de\u5199\u673a\u5236\u5206\u540c\u6b65\u548c\u5f02\u6b65\u4e24\u79cd\uff0c\u540c\u6b65\u56de\u5199\u5373SAVE\u547d\u4ee4\uff0c\u4e3b\u8fdb\u7a0b\u76f4\u63a5\u5411\u78c1\u76d8\u56de\u5199\u6570\u636e\u3002\u5728\u6570\u636e\u5927\u7684\u60c5\u51b5\u4e0b\u4f1a\u5bfc\u81f4\u7cfb\u7edf\u5047\u6b7b\u5f88\u957f\u65f6\u95f4\uff0c\u6240\u4ee5\u4e00\u822c\u4e0d\u662f\u63a8\u8350\u7684\u3002\u5f02\u6b65\u56de\u5199\u5373BGSAVE\u547d\u4ee4\uff0c\u4e3b\u8fdb\u7a0bfork\u540e\uff0c\u590d\u5236\u81ea\u8eab\u5e76\u901a\u8fc7\u8fd9\u4e2a\u65b0\u7684\u8fdb\u7a0b\u56de\u5199\u78c1\u76d8\uff0c\u56de\u5199\u7ed3\u675f\u540e\u65b0\u8fdb\u7a0b\u81ea\u884c\u5173\u95ed\u3002\u7531\u4e8e\u8fd9\u6837\u505a\u4e0d\u9700\u8981\u4e3b\u8fdb\u7a0b\u963b\u585e\uff0c\u7cfb\u7edf\u4e0d\u4f1a\u5047\u6b7b\uff0c\u4e00\u822c\u9ed8\u8ba4\u4f1a\u91c7\u7528\u8fd9\u4e2a\u65b9\u6cd5\u3002<\/p>\n
\u8fd9\u91cc\u6ce8\u610f\uff1a<\/strong><\/span><\/div>\n\u5728redis\u4e2d\u8fd0\u884cconfig set stop-writes-on-bgsave-error no\u547d\u4ee4\u53ea\u80fd\u6682\u65f6\u89e3\u51b3\u4e0d\u80fdset\u7684\u95ee\u9898\u3002\u51fa\u4e86\u95ee\u9898\u8fd8\u662f\u8981\u770blog\u7684\u9ed8\u8ba4\u914d\u7f6e stop-writes-on-bgsave-error yes\u5f53bgsave\u51fa\u9519\u65f6\u6570\u636e\u5c06\u4e0d\u80fd\u4fee\u6539\u3002<\/p>\n
\n\u539f\u6587\u6765\u81ea\uff1ahttp:\/\/www.linuxsir.org\/linuxsjk\/14252.html<\/a><\/p>\n