{"id":2142,"date":"2019-06-30T20:26:35","date_gmt":"2019-06-30T12:26:35","guid":{"rendered":"https:\/\/tixbay.net\/?p=2142"},"modified":"2019-07-05T00:50:26","modified_gmt":"2019-07-04T16:50:26","slug":"k8s%e4%b8%ad%e6%90%ad%e5%bb%baredis%e9%9b%86%e7%be%a4","status":"publish","type":"post","link":"https:\/\/tixbay.net\/?p=2142","title":{"rendered":"[\u539f\u521b]K8s\u4e2d\u642d\u5efa\u81ea\u52a8\u6062\u590d\u7684redis\u96c6\u7fa4"},"content":{"rendered":"\n<p>\u53c2\u8003 <a href=\"https:\/\/www.jianshu.com\/p\/65c4baadf5d9\">https:\/\/www.jianshu.com\/p\/65c4baadf5d9<\/a><\/p>\n\n\n\n<p>\u4f46\u662f\u8fd9\u4e2a\u65b9\u6848\u5e76\u4e0d\u5b8c\u7f8e\uff0c\u5b58\u5728\u95ee\u9898\uff1a<\/p>\n\n\n\n<p>pod\u91cd\u542f\u540epod ip\u5df2\u7ecf\u6539\u53d8\uff0c\u800credis\u914d\u7f6enodes.conf\u4e2d\u7684ip\u5e76\u6ca1\u6709\u53d8\u3002\u5982\u679c\u5355\u4e2a\u8282\u70b9down\u6389\u540e\u91cd\u542f\uff0c\u96c6\u7fa4\u662f\u53ef\u4ee5\u6062\u590d\u7684\uff0c\u5982\u679c\u5b58\u5728\u4e00\u534a\u4ee5\u4e0a\u8282\u70b9down\u7684\u60c5\u51b5\u4e0b\uff0c\u6bd4\u5982k8s\u96c6\u7fa4\u91cd\u542f\uff0credis\u96c6\u7fa4\u662f\u4e0d\u80fd\u6062\u590d\u7684\u3002<\/p>\n\n\n\n<p>\u5982\u4f55\u5728\u96c6\u7fa4\u6574\u4f53\u91cd\u542f\u60c5\u51b5\u4e0b\u81ea\u52a8\u6062\u590d\uff1f<\/p>\n\n\n\n<p>redis\u662f\u4f9d\u8d56nodes.conf\u914d\u7f6e\u8282\u70b9\u4fe1\u606f\uff0c\u4ece\u800c\u76f8\u4e92\u901a\u4fe1\u3002\u56e0\u6b64\u6211\u4eec\u53ea\u8981\u4fdd\u8bc1nodes.conf\u80fd\u66f4\u65b0\u6210\u65b0\u7684pod ip\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n\n\n\n<p>\u6b65\u9aa4\uff1a<\/p>\n\n\n\n<p>pod\u542f\u52a8\u540e\u5411\u4e00\u4e2a\u6240\u6709redis\u5b9e\u4f8b\u90fd\u80fd\u8bbf\u95ee\u7684\u5730\u65b9\u5199\u5165\u4e00\u4e2aredisid\u548cip\u7684\u5bf9\u5e94\u5173\u7cfb\u3002\u540c\u65f6\u5bf9nodes.conf\u4e2d\u6240\u6709redisid\uff0c\u53bb\u67e5\u627e\u5bf9\u5e94\u7684ip\uff0c\u5982\u679c\u80fdping\u901a\uff08\u6216\u8005\u5176\u4ed6\u5065\u5eb7\u68c0\u6d4b\u65b9\u5f0f\uff09\u5219\u8ba4\u4e3aip\u6709\u6548\uff0c\u66f4\u65b0nodes.conf\u3002\u76f4\u5230\u6240\u6709ip\u90fd\u5728\u7ebf\u540e\uff0c\u542f\u52a8redis\u5b9e\u4f8b\u3002<\/p>\n\n\n\n<p>\u601d\u8def\u5c31\u662f\u8fd9\u6837\u4e86\uff0c\u4e0b\u9762\u662f\u5177\u4f53\u5b9e\u73b0\u5e76\u8d34\u4ee3\u7801\uff1a<\/p>\n\n\n\n<p>\u4fee\u6539redis-cluster.yaml\uff0c\u589e\u52a0\u516c\u5171\u8bbf\u95ee\u533a\u57df\uff1a<\/p>\n\n\n\n<p>\u6bd4\u5982\u6211\u8fd9\u91cc\u662fnfs\uff1a\u6302\u8f7d\u5230\/sh\uff0csh\u4e0b\u6dfb\u52a0start.sh\u548ccheckip.sh\uff0c\u7531\u4e8eredis\u955c\u50cf\u4e2d\u6ca1\u6709ping\u5de5\u5177\uff0c\u5077\u61d2\u8d77\u89c1\u624b\u52a8copy ping\u3001libcap.so.2\u3001libcrypto.so.10\u3001libidn.so.11\u5230\u6302\u8f7d\u76ee\u5f55\u4e0b\uff0c\u5e76\u5728start.sh\u4e2d\u6307\u5b9aLD_LIBRARY_PATH\u3002<\/p>\n\n\n\n<p>start.sh<\/p>\n\n\n\n<pre>#!\/bin\/bash\n\nexport LD_LIBRARY_PATH=\/sh:$LD_LIBRARY_PATH\n\nnewip=`cat \/etc\/hosts|grep redis-app|awk '{print $1}'`\nmyid=`cat \/var\/lib\/redis\/nodes.conf |grep myself|awk '{print $1}'`\nif [ \"$newip\"x == \"\"x ]; then\n    echo \"Cannot find new ip\";\n    exit 1;\nelif [ \"$myid\"x == \"\"x ]; then\n    echo \"no myid\";\n    exit 1;\nelse\n    echo $newip &gt; \/sh\/$myid \n    echo \"refresh ip: $myid -&gt; $newip\";\nfi\n\necho \"check nodes.conf\"\ncat \/var\/lib\/redis\/nodes.conf|grep -E \"master|slave\"|awk '{print $1}'|xargs -i \/sh\/checkip.sh {}\n\nif [ $? -eq 0 ]; then\n    echo \"done nodes.conf\"\n    redis-server \/etc\/redis\/redis.conf --protected-mode no\nelse\n    echo \"abort on error\"\nfi\n<\/pre>\n\n\n\n<p>checkip.sh<\/p>\n\n\n\n<pre>#!\/bin\/bash\n\nif [ $# -ne 1 ]; then\n    exit 1;\nfi\n\nwhile :\ndo\n    echo \"while\";\n    chkip=`cat \/sh\/$1`\n    if [ \"$chkip\"x == \"\"x ]; then\n        sleep 1s;\n    else\n        \/sh\/ping -c1 $chkip;\n        if [ $? -eq 0 ]; then\n            oldip=`cat \/var\/lib\/redis\/nodes.conf |grep -E \"^$1\"|awk '{print $2}'|cut -d \":\" -f1`\n            if [ \"$oldip\"x == \"\"x ]; then\n                echo \"no old ip\";\n                exit 1;\n            else\n                echo \"oldip=$oldip and newip=$chkip\"\n                sed -i \"s\/$oldip\/$chkip\/g\" \/var\/lib\/redis\/nodes.conf\n                echo \"done $1 $chkip\";\n                exit 0;\n            fi\n        else\n            sleep 1s;\n        fi\n    fi\ndone\n<\/pre>\n\n\n\n<p>\u6700\u540e\u628apod\u7684\u542f\u52a8\u811a\u672c\u6539\u4e3a\/sh\/start.sh\uff0c\u66f4\u65b0pod\uff1a<\/p>\n\n\n\n<p>kubectl apply -f redis-stateful.yaml<\/p>\n\n\n\n<p>\u6d4b\u8bd5\uff1a\u628aredis-stateful\u6574\u4f53\u79fb\u9664\uff0c\u5e76\u91cd\u65b0create\uff0c\u96c6\u7fa4\u6b63\u5e38\u6062\u590d\uff0c\u4ee5\u4e0b\u662fpod\u65e5\u5fd7\uff1a<\/p>\n\n\n\n<pre>refresh ip: 2d05fb2406a254f08664b5ff5d26a151b5b262cc -&gt; 10.244.4.68\ncheck nodes.conf\nwhile\nPING 10.244.4.68 (10.244.4.68) 56(84) bytes of data.\n64 bytes from 10.244.4.68: icmp_seq=1 ttl=64 time=0.072 ms\n\n--- 10.244.4.68 ping statistics ---\n1 packets transmitted, 1 received, 0% packet loss, time 0ms\nrtt min\/avg\/max\/mdev = 0.072\/0.072\/0.072\/0.000 ms\noldip=10.244.4.66 and newip=10.244.4.68\ndone 2d05fb2406a254f08664b5ff5d26a151b5b262cc 10.244.4.68\nwhile\nPING 10.244.1.89 (10.244.1.89) 56(84) bytes of data.\n\n--- 10.244.1.89 ping statistics ---\n1 packets transmitted, 0 received, 100% packet loss, time 0ms\n\nwhile\nPING 10.244.1.89 (10.244.1.89) 56(84) bytes of data.\n\n--- 10.244.1.89 ping statistics ---\n1 packets transmitted, 0 received, 100% packet loss, time 0ms\n\nwhile\nPING 10.244.1.91 (10.244.1.91) 56(84) bytes of data.\n64 bytes from 10.244.1.91: icmp_seq=1 ttl=62 time=1.86 ms\n\n--- 10.244.1.91 ping statistics ---\n1 packets transmitted, 1 received, 0% packet loss, time 0ms\nrtt min\/avg\/max\/mdev = 1.861\/1.861\/1.861\/0.000 ms\noldip=10.244.1.89 and newip=10.244.1.91\ndone 1665fb20c43e7468c54bbdea7ed6e283283669df 10.244.1.91\nwhile\nPING 10.244.2.135 (10.244.2.135) 56(84) bytes of data.\n64 bytes from 10.244.2.135: icmp_seq=1 ttl=62 time=1.87 ms\n\n--- 10.244.2.135 ping statistics ---\n1 packets transmitted, 1 received, 0% packet loss, time 0ms\nrtt min\/avg\/max\/mdev = 1.870\/1.870\/1.870\/0.000 ms\noldip=10.244.2.133 and newip=10.244.2.135\ndone 7a17b9c2f70a053f98fb480492a8e904d330f9ac 10.244.2.135\nwhile\nPING 10.244.1.90 (10.244.1.90) 56(84) bytes of data.\n64 bytes from 10.244.1.90: icmp_seq=1 ttl=62 time=1.96 ms\n\n--- 10.244.1.90 ping statistics ---\n1 packets transmitted, 1 received, 0% packet loss, time 0ms\nrtt min\/avg\/max\/mdev = 1.967\/1.967\/1.967\/0.000 ms\noldip=10.244.1.88 and newip=10.244.1.90\ndone 12cf9455a800f940f427c745318d1300a6730103 10.244.1.90\nwhile\nPING 10.244.4.69 (10.244.4.69) 56(84) bytes of data.\n64 bytes from 10.244.4.69: icmp_seq=1 ttl=64 time=0.106 ms\n\n--- 10.244.4.69 ping statistics ---\n1 packets transmitted, 1 received, 0% packet loss, time 0ms\nrtt min\/avg\/max\/mdev = 0.106\/0.106\/0.106\/0.000 ms\noldip=10.244.4.67 and newip=10.244.4.69\ndone d1e352d917cb9dfd5be2b053ef34473e11c7ea23 10.244.4.69\nwhile\nPING 10.244.2.136 (10.244.2.136) 56(84) bytes of data.\n64 bytes from 10.244.2.136: icmp_seq=1 ttl=62 time=1.89 ms\n\n--- 10.244.2.136 ping statistics ---\n1 packets transmitted, 1 received, 0% packet loss, time 0ms\nrtt min\/avg\/max\/mdev = 1.899\/1.899\/1.899\/0.000 ms\noldip=10.244.2.134 and newip=10.244.2.136\ndone 283aa9be8d0d4b25bfb79cf0a7eb084284b4f44d 10.244.2.136\ndone nodes.conf\n78:C 04 Jul 2019 08:54:28.879 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo\n78:C 04 Jul 2019 08:54:28.879 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=78, just started\n78:C 04 Jul 2019 08:54:28.879 # Configuration loaded\n78:M 04 Jul 2019 08:54:28.887 * Node configuration loaded, I'm 2d05fb2406a254f08664b5ff5d26a151b5b262cc\n78:M 04 Jul 2019 08:54:28.888 * Running mode=cluster, port=6379.\n78:M 04 Jul 2019 08:54:28.888 # WARNING: The TCP backlog setting of 511 cannot be enforced because \/proc\/sys\/net\/core\/somaxconn is set to the lower value of 128.\n78:M 04 Jul 2019 08:54:28.888 # Server initialized\n78:M 04 Jul 2019 08:54:28.888 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never &gt; \/sys\/kernel\/mm\/transparent_hugepage\/enabled' as root, and add it to your \/etc\/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.\n78:M 04 Jul 2019 08:54:28.890 * Reading RDB preamble from AOF file...\n78:M 04 Jul 2019 08:54:28.890 * Reading the remaining AOF tail...\n78:M 04 Jul 2019 08:54:28.892 * DB loaded from append only file: 0.004 seconds\n78:M 04 Jul 2019 08:54:28.892 * Ready to accept connections\n78:M 04 Jul 2019 08:54:28.899 * Clear FAIL state for node 283aa9be8d0d4b25bfb79cf0a7eb084284b4f44d: replica is reachable again.\n78:M 04 Jul 2019 08:54:32.367 * Clear FAIL state for node 1665fb20c43e7468c54bbdea7ed6e283283669df: replica is reachable again.\n78:M 04 Jul 2019 08:54:32.462 * Clear FAIL state for node d1e352d917cb9dfd5be2b053ef34473e11c7ea23: replica is reachable again.\n78:M 04 Jul 2019 08:54:33.316 * Replica 10.244.1.91:6379 asks for synchronization\n78:M 04 Jul 2019 08:54:33.316 * Partial resynchronization not accepted: Replication ID mismatch (Replica asked for 'ce61d735f3070e58c8d1eef8d705416e1dec10d8', my replication IDs are 'b726060355dca8aa11c4bf4c47e29d4423347021' and '0000000000000000000000000000000000000000')\n78:M 04 Jul 2019 08:54:33.316 * Starting BGSAVE for SYNC with target: disk\n78:M 04 Jul 2019 08:54:33.318 * Background saving started by pid 82\n82:C 04 Jul 2019 08:54:33.325 * DB saved on disk\n82:C 04 Jul 2019 08:54:33.328 * RDB: 4 MB of memory used by copy-on-write\n78:M 04 Jul 2019 08:54:33.372 * Background saving terminated with success\n78:M 04 Jul 2019 08:54:33.376 * Synchronization with replica 10.244.1.91:6379 succeeded\n78:M 04 Jul 2019 08:54:34.061 * Marking node 12cf9455a800f940f427c745318d1300a6730103 as failing (quorum reached).\n78:M 04 Jul 2019 08:54:35.294 # Failover auth granted to d1e352d917cb9dfd5be2b053ef34473e11c7ea23 for epoch 47\n78:M 04 Jul 2019 08:54:37.016 * Clear FAIL state for node 12cf9455a800f940f427c745318d1300a6730103: replica is reachable again.\n78:M 04 Jul 2019 08:54:39.654 * Clear FAIL state for node 7a17b9c2f70a053f98fb480492a8e904d330f9ac: is reachable again and nobody is serving its slots after some time.\n78:M 04 Jul 2019 08:54:40.364 # Cluster state changed: ok\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u53c2\u8003 https:\/\/www.jianshu.com\/p\/65c4baadf5d &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/tixbay.net\/?p=2142\">\u7ee7\u7eed\u9605\u8bfb &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2142","post","type-post","status-publish","format-standard","hentry","category-moo"],"_links":{"self":[{"href":"https:\/\/tixbay.net\/index.php?rest_route=\/wp\/v2\/posts\/2142","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tixbay.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tixbay.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tixbay.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tixbay.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2142"}],"version-history":[{"count":6,"href":"https:\/\/tixbay.net\/index.php?rest_route=\/wp\/v2\/posts\/2142\/revisions"}],"predecessor-version":[{"id":2158,"href":"https:\/\/tixbay.net\/index.php?rest_route=\/wp\/v2\/posts\/2142\/revisions\/2158"}],"wp:attachment":[{"href":"https:\/\/tixbay.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tixbay.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tixbay.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}