{"id":201348,"date":"2025-05-10T09:45:37","date_gmt":"2025-05-10T01:45:37","guid":{"rendered":"https:\/\/server.hk\/cnblog\/201348\/"},"modified":"2025-05-10T09:45:37","modified_gmt":"2025-05-10T01:45:37","slug":"redis%e5%93%a8%e5%85%b5%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4%e5%92%8c%e7%9b%91%e6%8e%a7%e7%a4%ba%e4%be%8b%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/201348\/","title":{"rendered":"redis\u54e8\u5175\u5e38\u7528\u547d\u4ee4\u548c\u76d1\u63a7\u793a\u4f8b\u8be6\u89e3"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>redis\u54e8\u5175\u5e38\u7528\u547d\u4ee4\u548c\u76d1\u63a7\u793a\u4f8b\u8be6\u89e3<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u77e5\u8bc6\u70b9\u638c\u63e1\u4e86\uff0c\u8fd8\u9700\u8981\u4e0d\u65ad\u7ec3\u4e60\u624d\u80fd\u719f\u7ec3\u8fd0\u7528\u3002\u4e0b\u9762golang\u5b66\u4e60\u7f51\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u4e2a\u6570\u636e\u5e93\u5f00\u53d1\u5b9e\u6218\uff0c\u624b\u628a\u624b\u6559\u5927\u5bb6\u5b66\u4e60\u300aredis\u54e8\u5175\u5e38\u7528\u547d\u4ee4\u548c\u76d1\u63a7\u793a\u4f8b\u8be6\u89e3\u300b\uff0c\u5728\u5b9e\u73b0\u529f\u80fd\u7684\u8fc7\u7a0b\u4e2d\u4e5f\u5e26\u5927\u5bb6\u91cd\u65b0\u6e29\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6e29\u6545\u800c\u77e5\u65b0\uff0c\u56de\u5934\u770b\u770b\u8bf4\u4e0d\u5b9a\u53c8\u6709\u4e0d\u4e00\u6837\u7684\u611f\u609f\uff01<\/p>\n<p>sentinel monitor advertise 192.168.0.5 28001 2<br \/> sentinel set advertise client-reconfig-script \/etc\/redis\/reconfig.sh<br \/> sentinel flushconfig<\/p>\n<p>sentinel\u542f\u52a8\u540e\u9700\u8981\u624b\u52a8\u5c06\u914d\u7f6e\u6587\u4ef6\u5bf9\u5e94\u7684\u8c03\u6574\u4e3asentinel deny-scripts-reconfig no,\u5426\u5219\u4e0d\u652f\u6301\u547d\u4ee4\u884cruntime\u4fee\u6539client-reconfig-script<br \/> # SECURITY<br \/> #<br \/> # By default SENTINEL SET will not be able to change the notification-script<br \/> # and client-reconfig-script at runtime. This avoids a trivial security issue<br \/> # where clients can set the script to anything and trigger a failover in order<br \/> # to get the program executed.<\/p>\n<p>#sentinel deny-scripts-reconfig yes<\/p>\n<p>role\u547d\u4ee4<br \/> \u67e5\u770bsentinel monitor\u7684master names\u540d\u5b57<\/p>\n<p>sentinel masters<br \/> \u67e5\u770b\u6240\u6709\u76d1\u63a7master\u53ca\u5176\u914d\u7f6e\u4fe1\u606f<\/p>\n<p>sentinel master monitor_name<br \/> \u67e5\u770b\u6307\u5b9a\u76d1\u63a7master\u53ca\u5176\u914d\u7f6e\u4fe1\u606f<\/p>\n<p>sentinel failover monitor_name <br \/> \u624b\u52a8\u8fdb\u884cswithover\u5207\u6362\u4e3b\u4ece\uff0c\u5982\u679c\u6709\u591a\u4e2aslave\u4f1a\u9009\u62e9\u54ea\u4e2aslave\u505a\u4e3a\u65b0\u7684master\uff0c\u5f85\u6d4b\u8bd5\uff1f<\/p>\n<p>sentinel moniotr <br \/> \u6dfb\u52a0\u76d1\u89c6\u7684master <\/p>\n<p>sentinel remove monitor_name<br \/> \u5c06\u76d1\u89c6\u7684\u4e3aname\u7684master\u79fb\u9664\u76d1\u89c6<\/p>\n<p>sentinel set [ ] <br \/> \u4fee\u6539\u76d1\u89c6\u7684master\u7684\u4e00\u4e9b\u5c5e\u6027 <br \/> down-after-milliseconds \u8fc7\u4e86\u8fd9\u4e2a\u65f6\u95f4\u8003\u8651master go down <br \/> failover-timeout \u5237\u65b0\u6545\u969c\u8f6c\u79fb\u72b6\u6001\u7684\u6700\u5927\u65f6\u95f4 <br \/> parallel-syncs slave\u540c\u65f6reconfigure\u7684\u4e2a\u6570 <br \/> notification-script \u8bbe\u7f6e\u901a\u77e5\u811a\u672c <br \/> client-reconfig-script \u8bbe\u7f6e\u901a\u77e5\u811a\u672c <br \/> auth-pass \u6267\u884cauth\u7684\u5bc6\u7801 <br \/> quorum \u4fee\u6539master\u7684quorum <\/p>\n<p>sentinel flushconfig<\/p>\n<p>\u5c06sentinel\u4fe1\u606f\u5199\u5165\u5230\u914d\u7f6e\u6587\u4ef6\u4e2d<\/p>\n<p>sentinel\u914d\u7f6e\u6587\u4ef6\u793a\u4f8b\uff1a<\/p>\n<pre>\ndaemonize yes\npidfile \"\/home\/redis\/sentinel\/25000\/redis.pid\"\nloglevel notice\nprotected-mode yes\nbind 192.168.100.5\nlogfile \"\/home\/redis\/sentinel\/25000\/redis.log\"\nport 25000\ndir \"\/home\/redis\/sentinel\/25000\"\n# Generated by CONFIG REWRITE\nsentinel myid 0338c4ceb7cf39a8037a22fa17d0f7a76923b5a0\nsentinel deny-scripts-reconfig no\nsentinel monitor advertise 192.168.100.5 28001 2\nsentinel client-reconfig-script advertise \/etc\/redis\/reconfig.sh\nsentinel config-epoch advertise 4\nsentinel leader-epoch advertise 4\nsentinel known-replica advertise 192.168.100.6 28001\nsentinel known-sentinel advertise 192.168.100.7 25000 06f937e1d35496dc66d2899e3b25e286ff91d658\nsentinel known-sentinel advertise 192.168.100.6 25000 ede86ac0b7d2ff7b532d0e5352ba6e33dd36670e\n \nsentinel monitor mymaster1 192.168.100.6 28002 2\nsentinel client-reconfig-script mymaster1 \/etc\/redis\/reconfig.sh\nsentinel config-epoch mymaster1 5\nsentinel leader-epoch mymaster1 1\nsentinel known-replica mymaster1 192.168.100.5 28002\nsentinel known-sentinel mymaster1 192.168.100.7 25000 06f937e1d35496dc66d2899e3b25e286ff91d658\nsentinel known-sentinel mymaster1 192.168.100.6 25000 ede86ac0b7d2ff7b532d0e5352ba6e33dd36670e\nsentinel current-epoch 5<\/pre>\n<p>sentinel client-reconfig-script\u811a\u672c\u793a\u4f8b<\/p>\n<pre>\n#!\/bin\/bash\n \ncheck_time=$(date +\"%F-%T\")\nmaster_name=\"$1\"\nfrom_ip=\"$4\"\nfrom_port=\"$5\"\nto_ip=\"$6\"\nto_port=\"$7\"\n \n \n#\u586b\u5199\u81ea\u5df1\u6b63\u786e\u7684\u673a\u5668\u4eba\u94fe\u63a5\ncurl 'https:\/\/qyapi.weixin.qq.com\/cgi-bin\/webhook\/send?key=xxxx' \\\n   -H 'Content-Type: application\/json' \\\n   -d '\n   {\n        \"msgtype\": \"text\",\n        \"text\": {\n            \"content\": \"\u3010'$check_time' '$master_name' redis failover\u3011\\nfrom\\n'$from_ip:$from_port'\\nto\\n'$to_ip:$to_port'\",\n            \"mentioned_list\":[\"xiaodongl\"]\n        }\n   }'<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>redis\u54e8\u5175\u5e38\u7528\u547d\u4ee4\u548c\u76d1\u63a7\u793a\u4f8b&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-201348","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201348","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=201348"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201348\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=201348"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=201348"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=201348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}