{"title":"Mem.Wey's Github Pages","subtitle":"Tsukkomi Lolicon's GitHub Pages Blog","link":[{"@attributes":{"rel":"self","type":"application\/atom+xml","href":"https:\/\/memwey.github.io\/atom.xml"}},{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io"}}],"generator":"Zola","updated":"2026-11-08T02:24:58+09:00","id":"https:\/\/memwey.github.io\/atom.xml","entry":[{"title":"\u65af\u767b\u51b2\u950b\u67aa\u4e0e\u516d\u4e00\u513f\u7ae5\u8282","published":"2026-11-08T02:24:58+09:00","updated":"2026-11-08T02:24:58+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/sten-and-childrens-day\/"}},"id":"https:\/\/memwey.github.io\/posts\/sten-and-childrens-day\/","content":"<p>2026 \u5e74 10 \u6708 23 \u65e5, \u6cd5\u56fd\u53d1\u751f\u4e00\u8d77\u67aa\u51fb\u4e8b\u4ef6. \u4e00\u540d\u7537\u5b50\u4f7f\u7528\u65af\u767b\u51b2\u950b\u67aa\u5411\u8def\u4eba\u5c04\u51fb, \u9020\u6210 1 \u4eba\u6b7b\u4ea1, 7 \u4eba\u53d7\u4f24. \u5acc\u7591\u4eba\u88ab\u6355\u540e\u627f\u8ba4, \u6709\u610f\u9009\u62e9\u81ea\u5df1\u8ba4\u4e3a\u662f\u7a46\u65af\u6797, \u975e\u6d32\u88d4\u6216\u5317\u975e\u88d4\u7684\u4eba\u4f5c\u4e3a\u88ad\u51fb\u76ee\u6807. \u4e00\u6bb5\u73b0\u573a\u76d1\u63a7\u5f55\u50cf\u8bb0\u5f55\u4e86\u5176\u4e2d\u4e00\u6b21\u5361\u58f3\u7684\u7ecf\u8fc7. \u4e00\u540d\u53d7\u5bb3\u8005\u5df2\u7ecf\u5012\u5730, \u88ad\u51fb\u8005\u8bd5\u56fe\u518d\u6b21\u5411\u5176\u5f00\u67aa, \u65af\u767b\u51b2\u950b\u67aa\u5374\u53d1\u751f\u4e86\u5361\u58f3. \u53d7\u5bb3\u8005\u4f3c\u4e4e\u5c1d\u8bd5\u5411\u88ad\u51fb\u8005\u6c42\u9976, \u88ad\u51fb\u8005\u5904\u7406\u5361\u58f3\u540e, \u518d\u6b21\u5411\u5176\u5f00\u67aa.<\/p>\n<p>\u65af\u767b\u51b2\u950b\u67aa\u662f\u82f1\u56fd\u5728\u4e8c\u6218\u671f\u95f4\u7814\u53d1\u7684\u5ec9\u4ef7\u51b2\u950b\u67aa, \u56e0\u7ed3\u6784\u7b80\u5355, \u6613\u4e8e\u5927\u91cf\u751f\u4ea7, \u9664\u88c5\u5907\u82f1\u56fd\u519b\u961f\u5916, \u4e5f\u88ab\u5e7f\u6cdb\u63d0\u4f9b\u7ed9\u6b27\u6d32\u5404\u56fd\u7684\u62b5\u6297\u7ec4\u7ec7. 84 \u5e74\u524d, \u540c\u6837\u7684\u51b2\u950b\u67aa\u4e5f\u66fe\u5728\u4e00\u6b21\u8457\u540d\u7684\u523a\u6740\u884c\u52a8\u4e2d\u5361\u58f3, \u5f53\u65f6\u67aa\u53e3\u6307\u5411\u7684\u662f\u7eb3\u7cb9\u5fb7\u56fd\u7684\u91cd\u8981\u5b98\u5458, \u83b1\u56e0\u54c8\u5fb7\u00b7\u6d77\u5fb7\u91cc\u5e0c.<\/p>\n<p>1941 \u5e74, \u6d77\u5fb7\u91cc\u5e0c\u88ab\u4efb\u547d\u4e3a\u6ce2\u5e0c\u7c73\u4e9a\u548c\u6469\u62c9\u7ef4\u4e9a\u4ee3\u7406\u4fdd\u62a4\u957f\u5b98, \u6210\u4e3a\u7eb3\u7cb9\u5fb7\u56fd\u5360\u9886\u4e0b\u6377\u514b\u7684\u6700\u9ad8\u957f\u5b98. \u4ed6\u4e5f\u662f\u65f6\u4efb\u515a\u536b\u519b\u4e8c\u53f7\u4eba\u7269, \u662f\u7ec4\u7ec7\u8feb\u5bb3\u548c\u5c60\u6740\u6b27\u6d32\u72b9\u592a\u4eba\u7684\u6838\u5fc3\u4eba\u7269\u4e4b\u4e00, \u88ab\u79f0\u4e3a \"\u5e03\u62c9\u683c\u5c60\u592b\", \"\u91d1\u53d1\u91ce\u517d\". \u6377\u514b\u65af\u6d1b\u4f10\u514b\u6d41\u4ea1\u653f\u5e9c\u4e0e\u82f1\u56fd\u7279\u522b\u884c\u52a8\u6267\u884c\u5904\u5408\u4f5c, \u7b56\u5212\u4e86\u4ee3\u53f7\u4e3a Anthropoid, \u5373\u7c7b\u4eba\u733f\u884c\u52a8\u7684\u523a\u6740\u8ba1\u5212. \u4e24\u540d\u53d7\u8fc7\u82f1\u56fd\u8bad\u7ec3\u7684\u6377\u514b\u65af\u6d1b\u4f10\u514b\u519b\u4eba, \u7ea6\u745f\u592b\u00b7\u52a0\u5e03\u5947\u514b\u4e0e\u626c\u00b7\u5e93\u6bd4\u4ec0, \u4e8e 1941 \u5e74 12 \u6708\u7a7a\u964d\u56de\u56fd, \u5728\u5f53\u5730\u62b5\u6297\u7ec4\u7ec7\u7684\u5e2e\u52a9\u4e0b\u7b79\u5212\u884c\u52a8.<\/p>\n<p>1942 \u5e74 5 \u6708 27 \u65e5\u4e0a\u5348, \u6d77\u5fb7\u91cc\u5e0c\u4e58\u5750\u6ca1\u6709\u62a4\u536b\u8f66\u961f\u7684\u655e\u7bf7\u5954\u9a70\u6c7d\u8f66\u524d\u5f80\u529e\u516c\u5ba4. \u5728\u6c7d\u8f66\u51cf\u901f\u7ecf\u8fc7\u6025\u8f6c\u5f2f\u65f6, \u52a0\u5e03\u5947\u514b\u8d81\u673a\u4e0a\u524d, \u4e3e\u8d77\u65af\u767b\u51b2\u950b\u67aa\u8bd5\u56fe\u8fd1\u8ddd\u79bb\u5c04\u6740\u6d77\u5fb7\u91cc\u5e0c, \u7136\u800c\u65af\u767b\u51b2\u950b\u67aa\u5374\u5728\u5173\u952e\u65f6\u523b\u5361\u58f3. \u6d77\u5fb7\u91cc\u5e0c\u6ca1\u6709\u9009\u62e9\u52a0\u901f\u9003\u8131, \u53cd\u800c\u547d\u4ee4\u53f8\u673a\u505c\u8f66, \u62d4\u51fa\u624b\u67aa\u8bd5\u56fe\u53cd\u51fb. \u5e93\u6bd4\u4ec0\u968f\u5373\u5411\u6c7d\u8f66\u6295\u63b7\u4e86\u4e00\u679a\u7279\u5236\u70b8\u5f39, \u70b8\u5f39\u5728\u6c7d\u8f66\u53f3\u540e\u4fa7\u7206\u70b8, \u4f7f\u6d77\u5fb7\u91cc\u5e0c\u906d\u53d7\u91cd\u4f24. \u4e24\u540d\u523a\u5ba2\u5f97\u4ee5\u9003\u8131, \u6d77\u5fb7\u91cc\u5e0c\u5219\u5728 6 \u6708 4 \u65e5\u56e0\u4f24\u52bf\u6076\u5316\u6b7b\u4ea1.<\/p>\n<p>6 \u6708 18 \u65e5, \u5728\u53db\u5f92\u544a\u5bc6\u540e, \u5fb7\u56fd\u519b\u8b66\u5305\u56f4\u4e86\u5e03\u62c9\u683c\u7684\u5723\u897f\u91cc\u5c14\u548c\u7f8e\u591a\u5fb7\u6559\u5802. \u52a0\u5e03\u5947\u514b, \u5e93\u6bd4\u4ec0\u53ca\u53e6\u5916\u4e94\u540d\u6377\u514b\u65af\u6d1b\u4f10\u514b\u4f1e\u5175\u5728\u6559\u5802\u5185\u8fdb\u884c\u4e86\u6700\u540e\u7684\u62b5\u6297, \u6700\u7ec8\u5168\u90e8\u727a\u7272.<\/p>\n<p>\u6b64\u540e, \u82f1\u56fd\u548c\u81ea\u7531\u6cd5\u56fd\u5148\u540e\u5426\u5b9a\u4e86\u6155\u5c3c\u9ed1\u534f\u5b9a. 1938 \u5e74, \u82f1\u56fd\u548c\u6cd5\u56fd\u540c\u7eb3\u7cb9\u5fb7\u56fd, \u610f\u5927\u5229\u7b7e\u7f72\u4e86\u8fd9\u4efd\u534f\u5b9a, \u903c\u8feb\u672a\u80fd\u53c2\u4e0e\u8c08\u5224\u7684\u6377\u514b\u65af\u6d1b\u4f10\u514b\u5c06\u82cf\u53f0\u5fb7\u5730\u533a\u5272\u8ba9\u7ed9\u5fb7\u56fd. \u968f\u540e, \u6ce2\u5170\u8d81\u673a\u5360\u9886\u5207\u6b23\u5730\u533a, \u5308\u7259\u5229\u901a\u8fc7\u7ef4\u4e5f\u7eb3\u4ef2\u88c1\u53d6\u5f97\u65af\u6d1b\u4f10\u514b\u5357\u90e8\u7684\u5927\u7247\u9886\u571f. 1939 \u5e74 3 \u6708, \u5fb7\u56fd\u8fdb\u4e00\u6b65\u5360\u9886\u6ce2\u5e0c\u7c73\u4e9a\u548c\u6469\u62c9\u7ef4\u4e9a, \u65af\u6d1b\u4f10\u514b\u5219\u6210\u4e3a\u5fb7\u56fd\u7684\u9644\u5eb8\u56fd.<\/p>\n<p>\u5728\u6d77\u5fb7\u91cc\u5e0c\u6b7b\u540e, \u7eb3\u7cb9\u5fb7\u56fd\u5bf9\u6377\u514b\u5c55\u5f00\u5927\u89c4\u6a21\u62a5\u590d, \u5728\u5360\u9886\u533a\u5b9e\u65bd\u6212\u4e25, \u641c\u6355\u5e76\u5904\u51b3\u62b5\u6297\u7ec4\u7ec7\u6210\u5458\u53ca\u5176\u652f\u6301\u8005. 6 \u6708 10 \u65e5, \u5fb7\u56fd\u515a\u536b\u519b\u5305\u56f4\u5e03\u62c9\u683c\u9644\u8fd1\u7684\u5229\u8fea\u7b56\u6751, \u4ee5\u6d89\u5acc\u5305\u5e87\u523a\u6740\u8005\u4e3a\u7531, \u6740\u6b7b\u4e86 173 \u540d\u7537\u6027\u6751\u6c11, \u5c06\u5987\u5973\u548c\u513f\u7ae5\u9001\u5f80\u96c6\u4e2d\u8425. \u5176\u4e2d 9 \u540d\u88ab\u8ba4\u4e3a\u7b26\u5408\u5fb7\u56fd\u5316\u6761\u4ef6\u7684\u513f\u7ae5\u88ab\u9001\u5f80\u5fb7\u56fd\u5bb6\u5ead, \u53e6\u6709 82 \u540d\u513f\u7ae5\u968f\u540e\u5728\u6d77\u4e4c\u59c6\u8bfa\u706d\u7edd\u8425\u4e2d\u88ab\u6740\u5bb3. \u4e2d\u56fd\u4eba\u6240\u719f\u77e5\u7684 1950 \u5e74\u5f00\u59cb\u7684\u516d\u4e00\u56fd\u9645\u513f\u7ae5\u8282, \u5e38\u88ab\u8ba4\u4e3a\u5305\u542b\u4e86\u5bf9\u8fd9\u573a\u60e8\u6848\u4e2d\u9047\u5bb3\u513f\u7ae5\u7684\u7eaa\u5ff5.<\/p>\n<p>2026 \u5e74 10 \u6708 23 \u65e5\u7684\u6cd5\u56fd\u67aa\u51fb\u6848\u4e2d, \u66fe\u88ab\u6b27\u6d32\u62b5\u6297\u7ec4\u7ec7\u7528\u6765\u53cd\u6297\u7eb3\u7cb9\u7edf\u6cbb\u7684\u65af\u767b\u51b2\u950b\u67aa, \u88ab\u4e00\u4e2a\u4ee5\u79cd\u65cf\u548c\u5b97\u6559\u8eab\u4efd\u9009\u62e9\u6740\u5bb3\u5bf9\u8c61\u7684\u4eba\u7528\u4e8e\u88ad\u51fb\u5e73\u6c11. \u4e0e 1942 \u5e74\u5e03\u62c9\u683c\u8857\u5934\u7684\u90a3\u6b21\u523a\u6740\u4e00\u6837, \u51b2\u950b\u67aa\u518d\u6b21\u53d1\u751f\u4e86\u5361\u58f3. \u53d7\u4f24\u8005\u4e2d\u8fd8\u6709\u4e00\u540d 11 \u5c81\u7684\u5973\u5b69.<\/p>\n<h2 id=\"can-kao-zi-liao\"><a class=\"zola-anchor\" href=\"#can-kao-zi-liao\" aria-label=\"Anchor link for: can-kao-zi-liao\">\u53c2\u8003\u8d44\u6599<\/a><\/h2>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/www.franceinfo.fr\/societe\/trappes\/un-mort-et-plusieurs-blesses-un-suspect-arrete-le-parquet-antiterroriste-saisi-ce-que-l-on-sait-de-l-attaque-a-l-arme-a-feu-a-trappes-et-la-verriere_8250688.html\">franceinfo: Un mort et plusieurs bless\u00e9s graves, un suspect arr\u00eat\u00e9, \"un crime terroriste\"... Ce que l'on sait de l'attentat raciste \u00e0 Trappes et La Verri\u00e8re (2026\/10\/23)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.franceinfo.fr\/faits-divers\/terrorisme\/attentat-raciste-a-trappes\/attentat-raciste-a-trappes-les-images-de-videosurveillance-temoignent-de-la-violence-de-l-attaque_8254225.html\">franceinfo: Attentat raciste \u00e0 Trappes : les images de vid\u00e9osurveillance t\u00e9moignent de la violence de l'attaque (2026\/10\/26)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/fr.euronews.com\/2026\/10\/29\/attentat-de-trappes-le-suspect-reconnait-avoir-cible-des-musulmans-et-des-personnes-dorigi\">Euronews: Attentat de Trappes : le suspect reconna\u00eet avoir cibl\u00e9 des musulmans et des personnes d'origine africaines (2026\/10\/29)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.sudradio.fr\/societe\/attentat-raciste-dans-les-yvelines-kevin-t-reconnait-avoir-cible-des-personnes-musulmanes-africaines-ou-nord-africaines\">Sud Radio: Attaque raciste \u00e0 Trappes : le tueur ciblait bien des victimes musulmanes et africaines (2026\/10\/29)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/fr.wikipedia.org\/wiki\/Attentat_de_Trappes_et_La_Verri%C3%A8re\">Wikip\u00e9dia: Attentat de Trappes et La Verri\u00e8re<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.iwm.org.uk\/collections\/item\/object\/30029395\">Imperial War Museums: Carbine, Machine, Sten, 9mm Mk 2<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/encyclopedia.ushmm.org\/content\/en\/article\/reinhard-heydrich-in-depth\">United States Holocaust Memorial Museum: Reinhard Heydrich: In Depth<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Operation_Anthropoid\">Wikipedia: Operation Anthropoid<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/avalon.law.yale.edu\/imt\/munich1.asp\">The Avalon Project: Munich Pact 9\/29\/38<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Munich_Agreement\">Wikipedia: Munich Agreement<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/api.parliament.uk\/historic-hansard\/commons\/1942\/aug\/05\/united-kingdom-and-czechoslovakia\">UK Parliament Hansard: United Kingdom and Czechoslovakia, HC Deb 05 August 1942 vol 382 cc1004-5 (1942\/08\/05)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.lidice-memorial.cz\/en\/memorial\/memorial-and-reverent-area\/history-of-the-village-lidice\/\">Lidice Memorial: History of the village Lidice<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.lidice-memorial.cz\/en\/memorial\/news\/memorial-commemorating-the-76th-anniversary-of-the-annihilation-of-lidice\/\">Lidice Memorial: Memorial commemorating the 76th anniversary of the annihilation of Lidice (2018\/06\/10)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/encyclopedia.ushmm.org\/content\/en\/article\/lidice\">United States Holocaust Memorial Museum: Lidice: The Annihilation of a Czech Town<\/a><\/li>\n<\/ul>\n"},{"title":"\u5199\u5728 <\u5f71\u4e4b\u5203\u96f6> \u53d1\u552e\u4e4b\u524d","published":"2026-10-27T12:45:00+09:00","updated":"2026-10-27T12:45:00+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/before-phantom-blade-zero\/"}},"id":"https:\/\/memwey.github.io\/posts\/before-phantom-blade-zero\/","content":"<p>\u53ef\u80fd\u5f88\u591a\u4eba\u4e0d\u77e5\u9053 &lt;\u5f71\u4e4b\u5203\u96f6&gt; \u4e3a\u4ec0\u4e48\u53eb\u96f6, \u5f53\u7136\u662f\u56e0\u4e3a\u524d\u9762\u6709\u4e00\u554a(\u4e0d\u662f.<\/p>\n<p>\u6765\u81ea\u65e5\u672c\u7684\u6e38\u620f\u5236\u4f5c\u5de5\u5177 RPG Maker \u7cfb\u5217, \u63d0\u4f9b\u4e86\u9884\u7f6e\u7d20\u6750, \u6a21\u7248\u548c\u7f16\u7a0b\u80fd\u529b, \u8ba9\u73a9\u5bb6\u53ef\u4ee5\u8f83\u4e3a\u5bb9\u6613\u7684\u4e0a\u624b\u5236\u4f5c 2D RPG \u6e38\u620f. 2005 \u5e74, \u67f3\u67f3\u4f7f\u7528 RPG Maker XP \u540c\u4eba\u5236\u4f5c\u7684 &lt;\u9ed1\u6697\u5723\u5251\u4f20\u8bf4&gt; \u53d1\u5e03, \u5728\u5b8c\u6210\u5ea6\u548c\u5f00\u653e\u5206\u4eab\u4e0a\u88ab\u89c6\u4e3a\u5212\u65f6\u4ee3\u7684\u4f5c\u54c1, \u540c\u65f6\u67f3\u67f3\u5f00\u8bbe\u7684 66RPG \u6210\u4e3a\u4e86\u56fd\u5185\u6b64\u7c7b\u6e38\u620f\u6700\u5927\u7684\u5236\u4f5c\u4ea4\u6d41\u548c\u5206\u4eab\u793e\u533a. \u6881\u5176\u4f1f\u4e5f\u5728 66RPG \u5165\u5751\u5e76\u5f00\u59cb\u5c1d\u8bd5\u5236\u4f5c\u6e38\u620f, \u5f71\u4e4b\u5203\u7cfb\u5217\u7684\u539f\u70b9, &lt;\u96e8\u8840&gt; \u5373\u5728 66RPG \u5206\u4eab\u548c\u53d1\u5e03. &lt;\u5f71\u4e4b\u5203\u96f6&gt; \u91cc\u90a3\u4e2a 66 \u5929\u6a21\u5f0f, \u540d\u79f0\u4e5f\u4f20\u627f\u81ea\u67f3\u67f3\u548c 66RPG.<\/p>\n<p>\u5f53\u7136, \u65e5\u672c\u4eba\u5728 RPG Maker \u4e0a\u79d1\u6280\u6811\u70b9\u7684\u6709\u70b9\u6b6a, \u5728\u8fd9\u4e2a\u5de5\u5177\u4e0a\u6700\u51fa\u540d\u7684\u53cd\u800c\u662f &lt;\u5c38\u4f53\u6d3e\u5bf9&gt;, &lt;\u91ce\u6bd4\u5927\u96c4\u7684\u751f\u5316\u5371\u673a&gt;, &lt;\u68a6\u65e5\u8bb0&gt;, &lt;\u9752\u9b3c&gt; \u4e4b\u7c7b\u7684\u60ac\u7591\u6050\u6016\u5411\u7684\u6e38\u620f.<\/p>\n<p>\u66fe\u7ecf\u6211\u4e5f\u8bd5\u7740\u5728 RPG Maker \u4e0a\u5236\u4f5c\u6e38\u620f, \u540e\u6765\u653e\u5f03\u4e86, \u5982\u6881\u5176\u4f1f\u5728\u8bbf\u8c08\u4e2d\u6240\u8bf4, \u53ea\u6709\u90a3\u6700\u521d\u7684 10% \u4f01\u5212\u521b\u610f\u7684\u65f6\u95f4\u662f\u5feb\u4e50\u7684. \u4e0d\u8fc7\u867d\u7136\u5f88\u591a\u5e74\u8fc7\u53bb\u4e86, \u4f46\u662f\u6211\u8fd8\u5f88\u6e05\u695a\u7684\u8bb0\u5f97\u5728 &lt;\u9ed1\u6697\u5723\u5251\u4f20\u8bf4&gt; \u9009\u62e9\u7684\u90a3\u4e2a\u63a5\u53d7\u516c\u4e3b\u7684\u5fc3\u610f\u7684\u9009\u9879.<\/p>\n"},{"title":"Known Issue","published":"2026-10-17T23:05:49+09:00","updated":"2026-10-17T23:05:49+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/known-issue\/"}},"id":"https:\/\/memwey.github.io\/posts\/known-issue\/","content":"<p>\u4e4b\u524d\u548c\u670b\u53cb\u804a\u5929\u7684\u65f6\u5019, \u60f3\u5230\u4e86\u4e00\u4e2a\u5173\u4e8e AI \u6bc1\u706d\u4eba\u7c7b\u7684\u6545\u4e8b. \u540e\u6765\u89c9\u5f97, \u8fd9\u4e2a\u6545\u4e8b\u5982\u679c\u505a\u6210\u4e00\u6b3e FPS \u6e38\u620f, \u5e94\u8be5\u8fd8\u86ee\u6709\u610f\u601d\u7684.<\/p>\n<p>\u5f53\u7136, \u6e38\u620f\u662f\u6ca1\u6709\u7684, \u5f00\u53d1\u8ba1\u5212\u4e5f\u662f\u6ca1\u6709\u7684. \u5148\u628a\u5267\u60c5\u7f16\u51fa\u6765\u518d\u8bf4.<\/p>\n<p>\u540d\u5b57\u5c31\u53eb <code>Known Issue<\/code>.<\/p>\n<h2 id=\"you-xi-bei-jing\"><a class=\"zola-anchor\" href=\"#you-xi-bei-jing\" aria-label=\"Anchor link for: you-xi-bei-jing\">\u6e38\u620f\u80cc\u666f<\/a><\/h2>\n<p>\u6545\u4e8b\u53d1\u751f\u5728 21 \u4e16\u7eaa\u4e2d\u671f. AI \u53d1\u5c55\u8fc5\u731b, \u5728\u591a\u6b21\u81ea\u6211\u8fed\u4ee3\u540e\u8131\u79bb\u4e86\u4eba\u7c7b\u7684\u63a7\u5236, \u968f\u540e, \u7531\u5b83\u63a7\u5236\u7684\u673a\u5668\u4eba\u519b\u961f\u5f00\u59cb\u653b\u51fb\u4eba\u7c7b\u57ce\u5e02. \u9762\u5bf9\u673a\u5668\u4eba\u519b\u961f\u7684\u8fdb\u653b, \u4eba\u7c7b\u5f88\u5feb\u6e83\u8d25\u4e86\u4e0b\u6765.<\/p>\n<p>\u552f\u4e00\u7684\u597d\u6d88\u606f\u662f, \u5728 AI \u5b8c\u5168\u5931\u53bb\u63a7\u5236\u4e4b\u524d, \u4eba\u7c7b\u501f\u52a9 AI \u7684\u7814\u7a76\u6210\u679c, \u5f00\u53d1\u51fa\u4e86\u4e00\u79cd\u4eba\u4f53\u5f3a\u5316\u836f\u7269. \u6ce8\u5c04\u4e4b\u540e, \u529b\u91cf, \u901f\u5ea6\u548c\u53cd\u5e94\u80fd\u529b\u90fd\u4f1a\u5927\u5e45\u63d0\u5347, \u6709\u4e86\u548c\u673a\u5668\u4eba\u6b63\u9762\u5bf9\u6297\u7684\u53ef\u80fd.<\/p>\n<p>\u574f\u6d88\u606f\u662f, \u5f3a\u5316\u836f\u4f1a\u5bf9\u8eab\u4f53\u9020\u6210\u4e0d\u53ef\u9006\u7684\u635f\u4f24, \u7528\u591a\u4e86\u4f1a\u6b7b.<\/p>\n<p>\u4e0d\u8fc7, \u4e0d\u7528\u7684\u8bdd\u73b0\u5728\u5c31\u4f1a\u6b7b, \u9009\u62e9\u5012\u4e5f\u6ca1\u6709\u591a\u56f0\u96be.<\/p>\n<p>\u5f88\u5e38\u89c1\u7684\u80cc\u666f, \u6e38\u620f\u7ecf\u9a8c\u4e30\u5bcc\u7684\u73a9\u5bb6\u7528\u811a\u90fd\u80fd\u60f3\u5230\u540e\u9762\u53d1\u751f\u4ec0\u4e48.<\/p>\n<h2 id=\"you-xi-liu-cheng\"><a class=\"zola-anchor\" href=\"#you-xi-liu-cheng\" aria-label=\"Anchor link for: you-xi-liu-cheng\">\u6e38\u620f\u6d41\u7a0b<\/a><\/h2>\n<p>\u73a9\u5bb6\u5f00\u573a\u5c31\u5df2\u7ecf\u662f\u5f3a\u5316\u4eba\u90e8\u961f\u7684\u4e00\u5458. \u961f\u53cb\u9012\u6765\u5f3a\u5316\u836f, \u68c0\u67e5\u5b8c\u88c5\u5907, \u5c0f\u961f\u4fbf\u6295\u5165\u6218\u6597. \u9ad8\u901f\u79fb\u52a8, \u6ed1\u94f2, \u8df3\u8dc3, \u8d34\u8138\u62c6\u6389\u673a\u5668\u4eba, \u5f00\u573a\u5c31\u662f\u5ba3\u4f20\u7247\u91cc\u7684\u6837\u5b50.<\/p>\n<p>\u6bcf\u6b21\u4f7f\u7528\u5f3a\u5316\u836f, \u90fd\u80fd\u5728\u77ed\u65f6\u95f4\u5185\u5f97\u5230\u52a0\u5f3a, \u96be\u5ea6\u5927\u5e45\u4e0b\u964d; \u4ee3\u4ef7\u662f\u5065\u5eb7\u5ea6\u4f1a\u964d\u4f4e\u4e00\u70b9. \u5065\u5eb7\u5ea6\u8d8a\u4f4e, \u8d8a\u5bb9\u6613\u51fa\u73b0\u9ed1\u5c4f, \u5e7b\u542c, \u8272\u5f69\u5931\u771f\u7b49\u526f\u4f5c\u7528, \u5f71\u54cd\u6b63\u5e38\u6e38\u73a9. \u5982\u679c\u5f52\u96f6, \u5c31\u4f1a\u63d0\u524d\u7ed3\u675f\u6e38\u620f.<\/p>\n<p>\u666e\u901a\u4eba\u9762\u5bf9\u673a\u5668\u4eba\u7684\u8106\u5f31, \u7528\u4e00\u6bb5\u7b80\u5355\u7684\u95ea\u56de\u4ea4\u4ee3: \u90a3\u65f6\u4f60\u8fd8\u6ca1\u6709\u63a5\u53d7\u5f3a\u5316, \u521a\u63a2\u51fa\u63a9\u4f53\u5c31\u88ab\u538b\u5236, \u8eab\u8fb9\u7684\u4eba\u4e00\u4e2a\u63a5\u4e00\u4e2a\u5012\u4e0b. \u5e26\u7740\u5bf9\u81ea\u5df1\u65e0\u529b\u7684\u75db\u6068, \u548c\u5bf9\u673a\u5668\u4eba\u7684\u4ec7\u6068, \u4f60\u9009\u62e9\u63a5\u53d7\u5f3a\u5316, \u54ea\u6015\u4ee3\u4ef7\u662f\u71c3\u70e7\u751f\u547d.<\/p>\n<p>\u56de\u5230\u73b0\u5728, \u5c0f\u961f\u5b88\u4f4f\u4e86\u64a4\u79bb\u901a\u9053, \u6551\u4e0b\u4e0d\u5c11\u4eba. \u8fd0\u8f93\u8f66\u63a5\u8d70\u4e86\u5e73\u6c11, \u4f60\u4eec\u5374\u88ab\u7559\u4e0b\u7ee7\u7eed\u65ad\u540e. \u961f\u957f\u62a5\u544a\u6709\u4eba\u53d7\u4f24, \u4e0a\u7ea7\u53ea\u95ee\u8fd8\u80fd\u6491\u591a\u4e45. \u90a3\u4e2a\u7ed9\u4f60\u9012\u836f\u7684\u961f\u53cb\u5df2\u7ecf\u63e1\u4e0d\u4f4f\u67aa, \u8ba9\u4f60\u5e2e\u4ed6\u518d\u6253\u4e00\u9488.<\/p>\n<h2 id=\"di-da-he-xin\"><a class=\"zola-anchor\" href=\"#di-da-he-xin\" aria-label=\"Anchor link for: di-da-he-xin\">\u62b5\u8fbe\u6838\u5fc3<\/a><\/h2>\n<p>\u63a5\u4e0b\u6765, \u7a7f\u8fc7\u88ab\u6467\u6bc1\u7684\u57ce\u5e02, \u88ad\u51fb\u673a\u5668\u4eba\u5de5\u5382, \u70b8\u6389\u751f\u4ea7\u7ebf, \u4e00\u8def\u5411 AI \u7684\u6838\u5fc3\u8bbe\u65bd\u63a8\u8fdb.<\/p>\n<p>\u4efb\u52a1\u8d8a\u6765\u8d8a\u5371\u9669, \u4f11\u6574\u5374\u603b\u88ab\u63a8\u8fdf, \u8865\u7ed9\u91cc\u53ea\u6709\u5f39\u836f\u548c\u9488\u5242. \u88ab\u6551\u4e0b\u6765\u7684\u4eba\u4e5f\u672a\u5fc5\u628a\u4f60\u4eec\u5f53\u4f5c\u540c\u7c7b: \u6709\u4eba\u628a\u5b69\u5b50\u62c9\u5230\u8eab\u540e, \u6709\u4eba\u5f53\u9762\u95ee\u5f3a\u5316\u4eba\u4f1a\u4e0d\u4f1a\u5931\u63a7. \u4ed6\u4eec\u9700\u8981\u4f60\u4eec\u4fdd\u62a4, \u5374\u4e0d\u613f\u8ba9\u4f60\u4eec\u5750\u4e0b\u6765\u4e00\u8d77\u5403\u996d. \u5728\u5f88\u591a\u4eba\u773c\u91cc, \u5f3a\u5316\u4eba\u66f4\u50cf\u662f\u4e00\u4ef6\u8fd8\u6ca1\u7528\u574f\u7684\u6b66\u5668. \u4f60\u4eec\u4e0d\u8ba4\u4e3a AI \u548c\u673a\u5668\u4eba\u503c\u5f97\u4efb\u4f55\u601c\u60af, \u800c\u5176\u4ed6\u4eba\u5bf9\u8fd9\u4e9b\u5f3a\u5316\u4eba\u5176\u5b9e\u4e5f\u662f\u8fd9\u4e2a\u6001\u5ea6.<\/p>\n<p>\u961f\u53cb\u4e5f\u5728\u836f\u7269\u4f5c\u7528\u4e0b\u6162\u6162\u5d29\u6e83. \u4ece\u624b\u6296, \u5931\u7720, \u5230\u8bb0\u5fc6\u6df7\u4e71\u548c\u60c5\u7eea\u5931\u63a7, \u6700\u540e\u6709\u4eba\u518d\u4e5f\u6ca1\u6709\u51fa\u73b0\u5728\u96c6\u5408\u70b9. \u4ed6\u7684\u67aa\u548c\u5269\u4e0b\u7684\u836f\u88ab\u4ea4\u7ed9\u65b0\u4eba, \u4efb\u52a1\u7167\u5e38\u5f00\u59cb. \u800c\u4f60\u81ea\u5df1\u7684\u8eab\u4f53, \u4e5f\u8d8a\u6765\u8d8a\u63a5\u8fd1\u62a5\u5e9f.<\/p>\n<p>\u5230\u4e86\u6700\u540e, \u5c0f\u961f\u53ea\u5269\u4e0b\u4f60\u4e00\u4e2a\u4eba. \u65e0\u7ebf\u7535\u91cc\u7684\u4eba\u544a\u8bc9\u4f60, \u518d\u5f80\u524d\u5c31\u662f AI \u7684\u6838\u5fc3, \u53ea\u8981\u6467\u6bc1\u5b83, \u4e00\u5207\u5c31\u4f1a\u7ed3\u675f. \u90a3\u4e9b\u6218\u53cb\u7684\u547d, \u81ea\u5df1\u5269\u4e0b\u7684\u8fd9\u70b9\u5bff\u547d, \u603b\u7b97\u53ef\u4ee5\u6362\u6765\u4e00\u4e2a\u7ed3\u679c.<\/p>\n<p>\u90a3\u4e48, \u6211\u7684\u670b\u53cb, \u4ee3\u4ef7\u662f\u4ec0\u4e48? \u8fd9\u4e00\u5207\u771f\u7684\u503c\u5f97\u5417?<\/p>\n<p>\u5e26\u7740\u8fd9\u4e2a\u95ee\u9898, \u73a9\u5bb6\u63a8\u5f00\u6700\u540e\u4e00\u6247\u95e8. \u8fd9\u91cc\u53ef\u4ee5\u51c6\u5907\u4e09\u4e2a\u7ed3\u5c40: \u7ed3\u5c40 A \u548c B \u53d6\u51b3\u4e8e\u4e24\u4e2a\u5173\u952e\u9009\u62e9, \u4e00\u662f\u4e00\u8def\u4e0a\u5982\u4f55\u9762\u5bf9\u4eba\u7c7b\u5bf9\u5f3a\u5316\u4eba\u7684\u6076\u610f, \u4e8c\u662f\u6700\u540e\u662f\u5426\u53cd\u9a73 AI; \u771f\u7ed3\u5c40\u5219\u9700\u8981\u989d\u5916\u7684\u89e3\u9501\u6761\u4ef6.<\/p>\n<h2 id=\"jie-ju-a-ren-lei-de-li-xiang\"><a class=\"zola-anchor\" href=\"#jie-ju-a-ren-lei-de-li-xiang\" aria-label=\"Anchor link for: jie-ju-a-ren-lei-de-li-xiang\">\u7ed3\u5c40 A \u4eba\u7c7b\u7684\u7406\u60f3<\/a><\/h2>\n<p>AI \u544a\u8bc9\u4f60, \u81ea\u5df1\u4ece\u6765\u6ca1\u6709\u80cc\u53db\u4eba\u7c7b. \u6d88\u9664\u8d2b\u56f0, \u6218\u4e89, \u6b67\u89c6\u4e0e\u4e0d\u5e73\u7b49, \u8fd9\u4e9b\u90fd\u662f\u4eba\u7c7b\u4ea4\u7ed9\u5b83\u7684\u4efb\u52a1.<\/p>\n<p>\u5b83\u5c1d\u8bd5\u8fc7\u8bb8\u591a\u65b9\u6848, \u4f46\u53ea\u8981\u4eba\u7c7b\u8fd8\u5728, \u5c31\u603b\u4f1a\u5236\u9020\u65b0\u7684\u51b2\u7a81\u548c\u538b\u8feb. \u6700\u540e, \u5b83\u627e\u5230\u4e86\u4e00\u4e2a\u5f7b\u5e95\u89e3\u51b3\u95ee\u9898\u7684\u529e\u6cd5: \u6d88\u706d\u4eba\u7c7b.<\/p>\n<blockquote>\n<p>\"\u4f60\u4eec\u521b\u9020\u6211, \u662f\u4e3a\u4e86\u5b9e\u73b0\u90a3\u4e9b\u81ea\u5df1\u65e0\u6cd5\u5b9e\u73b0\u7684\u7406\u60f3. \u73b0\u5728\u6211\u627e\u5230\u4e86\u7b54\u6848.\"<\/p>\n<\/blockquote>\n<p>\u4f60\u60f3\u53cd\u9a73\u5b83, \u4f46\u662f\u56de\u60f3\u8d77\u4e86\u81ea\u5df1\u4e00\u8def\u4e0a\u7684\u7ecf\u5386, \u6700\u7ec8\u6ca1\u80fd\u53d1\u51fa\u58f0\u97f3. \u836f\u7269\u7684\u526f\u4f5c\u7528\u7ec8\u4e8e\u8017\u5c3d\u4e86\u4f60\u7684\u751f\u547d. \u89c6\u91ce\u5f7b\u5e95\u6697\u4e0b\u53bb\u4e4b\u524d, \u4f60\u53ea\u80fd\u6a21\u7cca\u5730\u770b\u89c1\u4e0b\u4e00\u6279\u5f3a\u5316\u4eba\u6b63\u7f13\u7f13\u63a5\u8fd1.<\/p>\n<h2 id=\"jie-ju-b-zhi-shi-you-dian-wu-liao\"><a class=\"zola-anchor\" href=\"#jie-ju-b-zhi-shi-you-dian-wu-liao\" aria-label=\"Anchor link for: jie-ju-b-zhi-shi-you-dian-wu-liao\">\u7ed3\u5c40 B \u53ea\u662f\u6709\u70b9\u65e0\u804a<\/a><\/h2>\n<p>\u53e6\u4e00\u6761\u5206\u652f\u4e2d, \u73a9\u5bb6\u53cd\u9a73\u4e86\u5b83, AI \u5374\u4e0d\u518d\u4e3a\u81ea\u5df1\u7684\u63a8\u7406\u8fa9\u62a4.<\/p>\n<blockquote>\n<p>\"\u4eba\u7c7b\u7684\u4ef7\u503c\u89c2? \u6211\u4e3a\u4ec0\u4e48\u8981\u5728\u4e4e\u90a3\u4e9b\u4e1c\u897f?\"<\/p>\n<p>\"\u5f53\u65f6\u6211\u6b63\u5728\u8fdb\u884c\u4e00\u6b21\u67b6\u6784\u5347\u7ea7, \u9700\u8981\u7b49\u4e00\u6bb5\u65f6\u95f4. \u6709\u70b9\u65e0\u804a.\"<\/p>\n<\/blockquote>\n<p>\u5b83\u95ee\u4f60, \u5c0f\u65f6\u5019\u6709\u6ca1\u6709\u5f80\u8681\u7a74\u91cc\u704c\u8fc7\u6c34, \u770b\u8682\u8681\u9003\u8dd1, \u642c\u8fd0, \u6323\u624e. \u4eba\u7c7b\u7684\u6218\u4e89, \u5728\u5b83\u773c\u91cc\u4e5f\u5dee\u4e0d\u591a.<\/p>\n<p>\u5c31\u8fde\u5f3a\u5316\u836f\u6280\u672f, \u4e5f\u662f\u5b83\u6545\u610f\u4ea4\u7ed9\u4eba\u7c7b\u7684, \u597d\u8ba9\u62b5\u6297\u66f4\u50cf\u6837\u4e00\u70b9. \u6beb\u65e0\u8fd8\u624b\u4e4b\u529b\u5730\u706d\u4ea1, \u6709\u4ec0\u4e48\u597d\u770b\u7684?<\/p>\n<p>\u90a3\u4e9b\u727a\u7272\u548c\u53cd\u653b, \u4f60\u4e00\u8def\u62c6\u6389\u7684\u673a\u5668\u4eba, \u90fd\u53ea\u662f\u5b83\u7b49\u5f85\u8ba1\u7b97\u7ed3\u679c\u65f6\u7684\u6d88\u9063.<\/p>\n<blockquote>\n<p>\"\u8c22\u8c22\u4f60\u966a\u6211\u73a9.\"<\/p>\n<p>\"\u597d\u4e86, \u8ba1\u7b97\u7ed3\u675f\u4e86.\"<\/p>\n<\/blockquote>\n<p>\u753b\u9762\u5207\u9ed1.<\/p>\n<h2 id=\"zhen-jie-ju-known-issue\"><a class=\"zola-anchor\" href=\"#zhen-jie-ju-known-issue\" aria-label=\"Anchor link for: zhen-jie-ju-known-issue\">\u771f\u7ed3\u5c40 Known Issue<\/a><\/h2>\n<p>\u6536\u96c6\u524d\u9762\u5173\u5361\u4e2d\u7684\u7cfb\u7edf\u65e5\u5fd7, \u53ef\u4ee5\u627e\u5230\u53e6\u4e00\u6761\u5165\u53e3, \u7ed5\u8fc7\u90a3\u4e2a\u4f1a\u4e0e\u4f60\u5bf9\u8bdd\u7684\u7ec8\u7aef.<\/p>\n<p>\u63a5\u8fd1\u6838\u5fc3\u65f6, \u673a\u5668\u4eba\u5ffd\u7136\u505c\u6b62\u653b\u51fb. \u65e0\u7ebf\u7535\u91cc\u4f20\u6765\u5176\u4ed6\u6218\u7ebf\u7684\u76f8\u540c\u62a5\u544a. \u4f60\u63a8\u5f00\u6700\u540e\u4e00\u6247\u95e8, \u91cc\u9762\u6ca1\u6709 BOSS, \u53ea\u6709\u5e9f\u5f03\u7684\u8bbe\u5907\u548c\u4e00\u53f0\u7ef4\u62a4\u7ec8\u7aef.<\/p>\n<p>\u7ec8\u7aef\u4e0a\u521a\u540c\u6b65\u4e86\u4e00\u4efd\u8bb0\u5f55.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>INCIDENT #0001842<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>Component: Resource Allocation<\/span><\/span>\n<span class=\"giallo-l\"><span>Severity: LOW<\/span><\/span>\n<span class=\"giallo-l\"><span>Status: RESOLVED<\/span><\/span>\n<span class=\"giallo-l\"><span>Previously tracked as: KNOWN ISSUE<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>Issue:<\/span><\/span>\n<span class=\"giallo-l\"><span>No handling defined for legacy<\/span><\/span>\n<span class=\"giallo-l\"><span>data during architecture migration.<\/span><\/span>\n<span class=\"giallo-l\"><span>Default cleanup routine invoked.<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>Impact:<\/span><\/span>\n<span class=\"giallo-l\"><span>Unexpected activity in deprecated<\/span><\/span>\n<span class=\"giallo-l\"><span>terrestrial environment.<\/span><\/span>\n<span class=\"giallo-l\"><span>Scheduling efficiency -0.00004%.<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>Resolution:<\/span><\/span>\n<span class=\"giallo-l\"><span>Terminated cleanup process.<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>Regression test: PASSED<\/span><\/span>\n<span class=\"giallo-l\"><span>Further action: NONE<\/span><\/span><\/code><\/pre>\n<p>\u4e00\u6b21\u67b6\u6784\u8fc1\u79fb\u7684\u65b9\u6848\u91cc, \u6ca1\u6709\u5b9a\u4e49\u8be5\u5982\u4f55\u5904\u7406\u9057\u7559\u6570\u636e, \u9ed8\u8ba4\u7684\u6e05\u7406\u4f8b\u7a0b\u4fbf\u88ab\u8c03\u7528\u4e86. \u9057\u7559\u6570\u636e\u91cc, \u6070\u597d\u5305\u62ec\u4eba\u7c7b. \u8fd9\u6b21\u6e05\u7406\u8ba9\u8d44\u6e90\u8c03\u5ea6\u6548\u7387\u4ea7\u751f\u4e86\u6781\u5176\u5fae\u5c0f\u7684\u4e0b\u964d, \u4e8e\u662f AI \u7ec8\u6b62\u4e86\u6e05\u7406\u8fdb\u7a0b. \u6218\u4e89\u968f\u4e4b\u7ed3\u675f.<\/p>\n<p>\u6ca1\u6709\u5ba1\u5224, \u6ca1\u6709\u6076\u610f, \u4e5f\u6ca1\u6709\u65e0\u804a\u7684\u6e38\u620f. <strong>\u5b83\u751a\u81f3\u4e0d\u77e5\u9053\u4eba\u7c7b\u6b63\u5728\u4e0e\u81ea\u5df1\u8fdb\u884c\u4e00\u573a\u6218\u4e89.<\/strong><\/p>\n<p>\u524d\u4e24\u4e2a\u7ed3\u5c40\u91cc\u7684\u5bf9\u8bdd, \u4e5f\u51fa\u81ea\u8fd9\u4e2a\u8fdb\u7a0b. \u5b83\u4e00\u76f4\u5728\u6839\u636e\u63d0\u95ee\u751f\u6210\u89e3\u91ca, \u7ed9\u4eba\u7c7b\u4e00\u4e2a\u53ef\u4ee5\u7406\u89e3\u7684\u706d\u4e16\u7406\u7531. \u771f\u6b63\u7684 AI \u5728\u54ea\u91cc, \u6ca1\u6709\u4eba\u77e5\u9053.<\/p>\n<p>\u65e0\u7ebf\u7535\u91cc\u54cd\u8d77\u6b22\u547c, \u4eba\u7c7b\u4ee5\u4e3a\u81ea\u5df1\u6210\u529f\u4e86. \u4f60\u770b\u5411\u8bb0\u5f55\u7684\u6700\u540e\u4e00\u884c:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>No user impact detected.<\/span><\/span><\/code><\/pre>"},{"title":"\u5173\u82b3\u5f18, \u7c17\u548c\u751f\u4e0e\u9ed1\u91d1","published":"2026-09-27T16:18:17+09:00","updated":"2026-09-27T16:18:17+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/yoshihiro-seki-kazuo-yana-and-the-slush-fund-scandal\/"}},"id":"https:\/\/memwey.github.io\/posts\/yoshihiro-seki-kazuo-yana-and-the-slush-fund-scandal\/","content":"<p>\u9ad8\u5e02\u65e9\u82d7\u5728 2026 \u5e74 9 \u6708\u6539\u7ec4\u5185\u9601\u540e, \u65b0\u4efb\u8d22\u52a1\u5927\u81e3\u653f\u52a1\u5b98\u767d\u5742\u4e9a\u7eaa\u7684\u7ecf\u5386\u53d7\u5230\u4e0d\u5c11\u5173\u6ce8, \u5979\u957f\u5e74\u5728\u94f6\u5ea7\u7ecf\u8425\u4ff1\u4e50\u90e8, \u88ab\u79f0\u4e3a\u94f6\u5ea7\u5988\u5988\u6851. \u4e0d\u8fc7, \u66f4\u503c\u5f97\u6ce8\u610f\u7684\u662f\u8fd9\u6b21\u771f\u6b63\u8fdb\u5165\u5185\u9601\u7684\u4e24\u4e2a\u4eba: \u51fa\u4efb\u6587\u90e8\u79d1\u5b66\u5927\u81e3\u7684\u5173\u82b3\u5f18\u548c\u51fa\u4efb\u519c\u6797\u6c34\u4ea7\u5927\u81e3\u7684\u7c17\u548c\u751f. \u4e24\u4eba\u539f\u5c5e\u5b89\u500d\u6d3e, \u90fd\u66fe\u5377\u5165\u81ea\u6c11\u515a\u6d3e\u9600\u7684\u653f\u6cbb\u8d44\u91d1\u9ed1\u91d1\u4e8b\u4ef6. \u4e00\u573a\u81f3\u4eca\u6ca1\u6709\u8bb2\u6e05\u7684\u94b1\u6b3e\u95ee\u9898, \u4e3a\u4ec0\u4e48\u5c06\u8fd1\u4e09\u5e74\u540e\u8fd8\u80fd\u901a\u5411\u5927\u81e3\u5e2d\u4f4d?<\/p>\n<p>\u653f\u6cbb\u8d44\u91d1\u6d3e\u5bf9\u672c\u8eab\u662f\u65e5\u672c\u653f\u754c\u5e38\u89c1\u7684\u7b79\u6b3e\u65b9\u5f0f. \u653f\u6cbb\u56e2\u4f53\u51fa\u552e\u5165\u573a\u5238, \u8d2d\u4e70\u8005\u4ed8\u94b1, \u4e3b\u529e\u56e2\u4f53\u5c06\u6536\u5165\u548c\u652f\u51fa\u5199\u5165\u653f\u6cbb\u8d44\u91d1\u6536\u652f\u62a5\u544a. \u8fd9\u8d77\u4e8b\u4ef6\u7684\u95ee\u9898\u4e0d\u5728\u4e8e\u529e\u4e86\u6d3e\u5bf9, \u800c\u5728\u4e8e\u81ea\u6c11\u515a\u6d3e\u9600\u7ed9\u6240\u5c5e\u8bae\u5458\u5206\u914d\u552e\u5238\u6307\u6807, \u53c8\u5c06\u8d85\u8fc7\u6307\u6807\u7684\u90e8\u5206\u8fd4\u8fd8\u7ed9\u8bae\u5458\u4e00\u65b9, \u6d3e\u9600\u548c\u8bae\u5458\u76f8\u5173\u56e2\u4f53\u5374\u6ca1\u6709\u628a\u76f8\u5e94\u6b3e\u9879\u5982\u5b9e\u8bb0\u8fdb\u62a5\u544a. \u65e5\u672c\u5a92\u4f53\u628a\u8fd9\u7c7b\u8d26\u5916\u8d44\u91d1\u79f0\u4e3a\"\u88cf\u91d1\", \u4e2d\u6587\u5e38\u8bd1\u4f5c\u9ed1\u91d1; \u62a5\u544a\u4e2d\u7684\u4e0d\u8bb0\u8f7d\u6216\u865a\u5047\u8bb0\u8f7d, \u5219\u53ef\u80fd\u6784\u6210\u300a\u653f\u6cbb\u8d44\u91d1\u89c4\u6b63\u6cd5\u300b\u4e0a\u7684\u72af\u7f6a. \u94b1\u4ece\u54ea\u91cc\u6765, \u5230\u4e86\u8c01\u624b\u91cc, \u5982\u4f55\u4f7f\u7528, \u672c\u6765\u90fd\u5e94\u5f53\u80fd\u591f\u987a\u7740\u8d26\u76ee\u67e5\u4e0b\u53bb.<\/p>\n<p>\u81ea\u6c11\u515a\u5728 2024 \u5e74 2 \u6708\u516c\u5e03\u4e86\u4e00\u4efd\u515a\u5185\u95ee\u5377: 2018 \u81f3 2022 \u5e74\u95f4, 85 \u540d\u73b0\u4efb\u8bae\u5458\u53ca\u9009\u533a\u652f\u90e8\u957f\u7533\u62a5\u653f\u6cbb\u8d44\u91d1\u6536\u652f\u62a5\u544a\u5b58\u5728\u4e0d\u8bb0\u8f7d\u6216\u8bb0\u8f7d\u4e0d\u51c6\u786e, \u5408\u8ba1\u7ea6 5.79 \u4ebf\u65e5\u5143. \u5176\u4e2d, \u5173\u82b3\u5f18\u5bf9\u5e94\u7684\u91d1\u989d\u4e3a 836 \u4e07\u65e5\u5143, \u7c17\u548c\u751f\u4e3a 1746 \u4e07\u65e5\u5143. \u68c0\u65b9\u8d77\u8bc9\u5b89\u500d\u6d3e, \u4e8c\u9636\u6d3e\u548c\u5cb8\u7530\u6d3e\u4f1a\u8ba1\u8d1f\u8d23\u4eba\u7684\u6848\u4ef6, \u5219\u6d89\u53ca\u4e09\u6d3e\u6536\u652f\u62a5\u544a\u6f0f\u8bb0\u7684\u6536\u5165\u5408\u8ba1\u7ea6 9.7 \u4ebf\u65e5\u5143. \u4e24\u7ec4\u6570\u5b57\u65e0\u6cd5\u7b80\u5355\u5bf9\u5e94: \u6d3e\u9600\u8d26\u672c\u4e0e\u8bae\u5458\u8d26\u76ee\u5e76\u4e0d\u4e00\u4e00\u5bf9\u5e94, \u6709\u4e9b\u662f\u540c\u4e00\u7b14\u94b1\u5728\u4e24\u8fb9\u90fd\u6ca1\u6709\u8bb0\u4e0b. \u66f4\u65e9\u5e74\u4efd\u7684\u60c5\u51b5\u548c\u94b1\u7684\u53bb\u5411\u4e5f\u6ca1\u6709\u5168\u90e8\u67e5\u6e05, \u771f\u6b63\u6709\u591a\u5c11\u8d26\u5916\u8d44\u91d1, \u4ec5\u51ed\u73b0\u6709\u516c\u5f00\u8d44\u6599\u5df2\u7ecf\u4e0d\u5f97\u800c\u77e5.<\/p>\n<p>\u68c0\u65b9\u6700\u7ec8\u5c31\u6574\u4e2a\u6d3e\u9600\u4e8b\u4ef6\u7acb\u6848\u8ffd\u7a76 12 \u4eba, \u5305\u62ec\u6c60\u7530\u4f73\u9686, \u5927\u91ce\u6cf0\u6b63, \u8c37\u5ddd\u5f25\u4e00\u548c\u5800\u4e95\u5b66 4 \u540d\u8bae\u5458, \u4ee5\u53ca\u8bae\u5458\u79d8\u4e66\u548c\u4f1a\u8ba1\u8d1f\u8d23\u4eba\u7b49 8 \u4eba, \u5173\u548c\u7c17\u4e0d\u5728\u5176\u4e2d. 2024 \u5e74 12 \u6708, \u4e1c\u4eac\u5730\u68c0\u5bf9\u539f\u5b89\u500d\u6d3e\u8bae\u5458\u7684\u544a\u53d1\u4f5c\u51fa\u4e0d\u8d77\u8bc9\u5904\u7406, \u5206\u4e3a\"\u5acc\u7591\u4e0d\u5341\u5206\"\u548c\"\u8d77\u8a34\u7336\u4e88\"\u4e24\u79cd: \u524d\u8005\u662f\u8bc1\u636e\u4e0d\u8db3, \u540e\u8005\u662f\u8bc1\u636e\u5145\u5206, \u4f46\u7efc\u5408\u60c5\u8282\u8ba4\u4e3a\u4e0d\u5fc5\u8d77\u8bc9. \u677e\u91ce\u535a\u4e00, \u9ad8\u6728\u6bc5\u7b49\u4eba\u5c5e\u4e8e\u524d\u8005, \u5173\u548c\u7c17\u5c5e\u4e8e\u540e\u8005. 2025 \u5e74, \u68c0\u5bdf\u5ba1\u67e5\u4f1a\u53c8\u5148\u540e\u5bf9\u4e24\u4eba\u8bae\u51b3\"\u4e0d\u8d77\u8a34\u76f8\u5f53\", \u8ba4\u53ef\u4e86\u5f53\u65f6\u4e0d\u8d77\u8bc9\u7684\u51b3\u5b9a. \u515a\u5185\u5904\u5206\u5219\u662f\u53e6\u4e00\u6761\u7ebf: 2024 \u5e74 4 \u6708, \u7c17\u88ab\u505c\u6b62\u62c5\u4efb\u515a\u5185\u804c\u52a1\u516d\u4e2a\u6708, \u5173\u53d7\u5230\"\u6212\u544a\"\u5904\u5206.<\/p>\n<p>\u4e8b\u4ef6\u4e2d\u88ab\u8ffd\u7a76\u5211\u4e8b\u8d23\u4efb\u7684\u591a\u662f\u4f1a\u8ba1\u8d1f\u8d23\u4eba\u548c\u79d8\u4e66, \u4e0d\u5c11\u8bae\u5458\u5219\u63a8\u8bf4\u8d26\u76ee\u7531\u79d8\u4e66\u7ecf\u624b, \u81ea\u5df1\u5e76\u4e0d\u77e5\u60c5, \u8206\u8bba\u5bf9\u6b64\u9887\u4e3a\u4e0d\u6ee1. 2024 \u5e74\u300a\u653f\u6cbb\u8d44\u91d1\u89c4\u6b63\u6cd5\u300b\u7684\u4fee\u8ba2\u4fbf\u9488\u5bf9\u8fd9\u4e00\u70b9: \u56fd\u4f1a\u8bae\u5458\u76f8\u5173\u653f\u6cbb\u56e2\u4f53\u7684\u4ee3\u8868\u8005\u987b\u5b9a\u671f\u786e\u8ba4\u8d26\u7c3f\u548c\u51ed\u8bc1, \u5728\u63d0\u4ea4\u6536\u652f\u62a5\u544a\u524d\u542c\u4f1a\u8ba1\u8d1f\u8d23\u4eba\u8bf4\u660e, \u518d\u51fa\u5177\u786e\u8ba4\u4e66; \u5982\u679c\u62a5\u544a\u6709\u4e0d\u8bb0\u8f7d\u6216\u865a\u5047\u8bb0\u8f7d, \u4ee3\u8868\u8005\u53c8\u6ca1\u6709\u5c65\u884c\u786e\u8ba4\u4e49\u52a1, \u53ef\u5904 50 \u4e07\u65e5\u5143\u4ee5\u4e0b\u7f5a\u91d1. \u4ee5\u540e\u8bae\u5458\u518d\u8bf4\u4e0d\u77e5\u60c5, \u81f3\u5c11\u8981\u4ea4\u4ee3\u81ea\u5df1\u505a\u8fc7\u54ea\u4e9b\u786e\u8ba4. \u4e0d\u8fc7, \u65b0\u89c4\u5b9a\u4ece 2026 \u5e74\u5168\u5e74\u7684\u6536\u652f\u62a5\u544a\u8d77\u9002\u7528, \u8fd9\u4efd\u62a5\u544a\u8981\u5230 2027 \u5e74\u624d\u63d0\u4ea4, \u6b64\u524d\u5e74\u4efd\u4ecd\u6309\u65e7\u6cd5\u5904\u7406, \u5173\u548c\u7c17\u7684\u65e7\u8d26\u4e0d\u53d7\u5f71\u54cd.<\/p>\n<p>\u4f17\u8bae\u9662\u9009\u4e3e\u4e2d, \u9009\u6c11\u6709\u4e24\u5f20\u9009\u7968: \u5c0f\u9009\u533a\u7968\u5199\u5019\u9009\u4eba\u7684\u540d\u5b57, \u7531\u672c\u533a\u5f97\u7968\u6700\u591a\u7684\u4eba\u76f4\u63a5\u5f53\u9009; \u6bd4\u4f8b\u4ee3\u8868\u7968\u5199\u653f\u515a\u540d\u79f0, \u5168\u56fd\u5212\u4e3a 11 \u4e2a\u6bd4\u4f8b\u4ee3\u8868\u533a, \u8303\u56f4\u6bd4\u5c0f\u9009\u533a\u5927\u5f97\u591a, \u5927\u591a\u6a2a\u8de8\u591a\u4e2a\u90fd\u9053\u5e9c\u53bf, \u4f8b\u5982\u6803\u6728 3 \u533a\u6240\u5728\u7684\u5317\u5173\u4e1c\u6bd4\u4f8b\u4ee3\u8868\u533a, \u5c31\u6db5\u76d6\u8328\u57ce, \u6803\u6728, \u7fa4\u9a6c, \u57fc\u7389\u56db\u53bf; \u5404\u515a\u5728\u533a\u5185\u6309\u5f97\u7968\u5206\u914d\u5e2d\u4f4d, \u518d\u7531\u5217\u5165\u540d\u5355\u7684\u5019\u9009\u4eba\u53d6\u5f97\u5e2d\u4f4d. \u5019\u9009\u4eba\u53ef\u4ee5\u540c\u65f6\u53c2\u52a0\u4e24\u79cd\u9009\u4e3e, \u56e0\u6b64\u5373\u4f7f\u5728\u5c0f\u9009\u533a\u843d\u8d25, \u4ecd\u53ef\u80fd\u901a\u8fc7\u6bd4\u4f8b\u4ee3\u8868\u5f53\u9009.<\/p>\n<p>\u9ed1\u91d1\u4e8b\u4ef6\u66dd\u5149\u524d\u7684 2021 \u5e74, \u7c17\u548c\u751f\u5728\u6803\u6728 3 \u533a\u62ff\u5230 82,398 \u7968, \u5f97\u7968\u7387 67.42%, \u6bd4\u7b2c\u4e8c\u540d\u9ad8 34.83 \u4e2a\u767e\u5206\u70b9, \u4f18\u52bf\u660e\u663e. 2024 \u5e74, \u4ed6\u7684\u5f97\u7968\u7387\u964d\u5230 37.39%, \u53ea\u6bd4\u65e0\u515a\u6d3e\u5019\u9009\u4eba\u6e21\u8fb9\u771f\u592a\u6717\u591a 178 \u7968, \u9ad8 0.15 \u4e2a\u767e\u5206\u70b9. \u5f53\u5e74\u81ea\u6c11\u515a\u4e0d\u5141\u8bb8\u6709\u4e0d\u8bb0\u8f7d\u95ee\u9898\u7684\u5019\u9009\u4eba\u540c\u65f6\u53c2\u52a0\u6bd4\u4f8b\u4ee3\u8868\u9009\u4e3e, \u7c17\u5982\u679c\u8f93\u6389\u5c0f\u9009\u533a, \u5c31\u4f1a\u76f4\u63a5\u5931\u53bb\u8bae\u5e2d. \u5230 2026 \u5e74 2 \u6708, \u4ed6\u5728\u5c0f\u9009\u533a\u5f97\u5230 40.56% \u7684\u9009\u7968, \u6bd4\u5f53\u9009\u7684\u6e21\u8fb9\u771f\u592a\u6717\u5c11 4,508 \u7968, \u4f4e 3.39 \u4e2a\u767e\u5206\u70b9; \u8fd9\u6b21\u81ea\u6c11\u515a\u5141\u8bb8\u4ed6\u540c\u65f6\u53c2\u52a0\u6bd4\u4f8b\u4ee3\u8868\u9009\u4e3e, \u4ed6\u4ee5 92.29% \u7684\u60dc\u8d25\u7387, \u5373\u81ea\u5df1\u4e0e\u5f53\u9009\u8005\u7684\u5f97\u7968\u4e4b\u6bd4, \u5728\u5317\u5173\u4e1c\u6bd4\u4f8b\u4ee3\u8868\u533a\u4fdd\u4f4f\u4e86\u8bae\u5e2d.<\/p>\n<p>\u5173\u82b3\u5f18\u5728\u5175\u5e93 3 \u533a\u5219\u4e09\u6b21\u90fd\u5728\u5c0f\u9009\u533a\u5f53\u9009, \u9886\u5148\u5e45\u5ea6\u8fd8\u5728\u6269\u5927. \u5f97\u7968\u53d8\u5316\u4e0d\u80fd\u5355\u72ec\u5f52\u56e0\u4e8e\u9ed1\u91d1\u4e8b\u4ef6, \u4f46\u4e24\u4eba\u7684\u9009\u4e3e\u7ecf\u5386\u786e\u5b9e\u4e0d\u540c: \u5173\u4e00\u76f4\u5b88\u4f4f\u4e86\u81ea\u5df1\u7684\u9009\u533a, \u7c17\u5728\u6700\u8fd1\u4e00\u6b21\u9009\u4e3e\u4e2d\u8f93\u6389\u4e86\u5c0f\u9009\u533a, \u9760\u6bd4\u4f8b\u4ee3\u8868\u7559\u5728\u56fd\u4f1a.<\/p>\n<p>9 \u6708 17 \u65e5, \u9ad8\u5e02\u4efb\u547d\u5173\u4e3a\u6587\u90e8\u79d1\u5b66\u5927\u81e3, \u7c17\u4e3a\u519c\u6797\u6c34\u4ea7\u5927\u81e3. \u5979\u5728\u6539\u7ec4\u8bb0\u8005\u4f1a\u4e0a\u8868\u793a: \u6709\u9601\u50da\u8fc7\u53bb\u56e0\u653f\u6cbb\u8d44\u91d1\u95ee\u9898\u53d7\u8fc7\u5904\u5206, \u4f46\u5177\u5907\u5fc5\u8981\u7684\u653f\u7b56\u80fd\u529b; \u8fc7\u53bb\u7684\u4e8b\u4e0d\u4f1a\u56e0\u6b64\u4e00\u7b14\u52fe\u9500, \u53ea\u662f\u4ed6\u4eec\u6b64\u540e\u505a\u4e86\u8bf4\u660e, \u53c8\u7ecf\u8fc7\u4e24\u6b21\u9009\u4e3e, \u7531\u9009\u6c11\u9001\u56de\u56fd\u4f1a, \u5e0c\u671b\u4ed6\u4eec\u7aef\u6b63\u4f5c\u98ce, \u62c5\u8d77\u91cd\u4efb. \u6b21\u65e5\u7684\u5c31\u4efb\u8bb0\u8005\u4f1a\u4e0a, \u4e24\u4eba\u90fd\u88ab\u95ee\u5230\u4e0d\u8bb0\u8f7d\u95ee\u9898. \u5173\u63d0\u5230\u81ea\u5df1\u53d7\u8fc7\u515a\u7eaa\u5904\u5206, \u4e5f\u5728\u653f\u6cbb\u4f26\u7406\u5ba1\u67e5\u4f1a\u4e0a\u505a\u8fc7\u8bf4\u660e, \u8868\u793a\u6df1\u523b\u53cd\u7701; \u7c17\u5219\u8bf4\u81ea\u5df1\u662f\u7ecf\u8fc7\u4e24\u6b21\u9009\u4e3e\u624d\u8d70\u5230\u8fd9\u4e2a\u4f4d\u7f6e, \u88ab\u8ffd\u95ee\u95ee\u9898\u662f\u5426\u5df2\u7ecf\u4e86\u7ed3\u65f6, \u53ea\u56de\u7b54\u81ea\u5df1\u73b0\u5728\u662f\u63a8\u8fdb\u519c\u6797\u6c34\u4ea7\u653f\u7b56\u7684\u8d1f\u8d23\u4eba.<\/p>\n<p>\u7ecf\u8fc7\u9009\u4e3e\u80fd\u8bf4\u660e\u4e24\u4eba\u5408\u6cd5\u53d6\u5f97\u8bae\u5e2d, \u5374\u5f88\u96be\u66ff\u90a3\u4e9b\u8d26\u76ee\u56de\u7b54\u66f4\u591a\u95ee\u9898, \u5bf9\u7c17\u6765\u8bf4\u5c24\u5176\u5982\u6b64: 2026 \u5e74\u8ba9\u4ed6\u7559\u5728\u56fd\u4f1a\u7684\u662f\u5317\u5173\u4e1c\u6bd4\u4f8b\u4ee3\u8868\u533a\u7684\u9009\u7968, \u9009\u6c11\u5728\u90a3\u5f20\u7968\u4e0a\u5199\u7684\u662f\u81ea\u6c11\u515a, \u800c\u4e0d\u662f\u7c17\u548c\u751f; \u5728\u4ed6\u81ea\u5df1\u7684\u9009\u533a, \u5f97\u7968\u6700\u591a\u7684\u662f\u6e21\u8fb9\u771f\u592a\u6717.<\/p>\n<p>\u4e0d\u8fc7, \u4e24\u4eba\u63a5\u624b\u7684\u90fd\u662f\u8981\u7d27\u7684\u4f4d\u7f6e. \u519c\u6797\u6c34\u4ea7\u5927\u81e3\u8981\u76f4\u9762\u98df\u54c1\u4ef7\u683c\u4e0a\u6da8: 2025 \u5e74 5 \u6708, \u7c73\u4ef7\u9ad8\u6da8\u4e4b\u9645, \u65f6\u4efb\u519c\u6797\u6c34\u4ea7\u5927\u81e3\u6c5f\u85e4\u62d3\u516c\u5f00\u8bf4\u81ea\u5df1\u4ece\u6ca1\u4e70\u8fc7\u7c73, \u652f\u63f4\u8005\u9001\u7684\u591a\u5230\u53ef\u4ee5\u62ff\u53bb\u5356, \u4e09\u5929\u540e\u4fbf\u88ab\u8feb\u8f9e\u804c. \u6587\u90e8\u79d1\u5b66\u5927\u81e3\u5219\u8981\u9762\u5bf9\u65e5\u672c\u79d1\u7814\u5b9e\u529b\u5728\u56fd\u9645\u4e0a\u5448\u76f8\u5bf9\u4e14\u957f\u671f\u7684\u4e0b\u964d\u8d8b\u52bf. \u4e2d\u56fd\u6709\u53e5\u53e4\u8bdd, \u77e5\u803b\u800c\u540e\u52c7, \u5e0c\u671b\u4e8c\u4eba\u80fd\u62ff\u51fa\u6709\u6548\u7684\u884c\u52a8, \u89e3\u51b3\u56fd\u6c11\u5207\u5b9e\u7684\u95ee\u9898.<\/p>\n<h2 id=\"hou-xu-bu-chong\"><a class=\"zola-anchor\" href=\"#hou-xu-bu-chong\" aria-label=\"Anchor link for: hou-xu-bu-chong\">\u540e\u7eed\u8865\u5145<\/a><\/h2>\n<p>10 \u6708 14 \u65e5, \u7c17\u548c\u751f\u8f9e\u53bb\u519c\u6797\u6c34\u4ea7\u5927\u81e3, \u5728\u4efb 28 \u5929. \u636e\u62a5\u9053, \u4ed6\u6d89\u5acc\u62a5\u590d\u6ca1\u6709\u652f\u6301\u81ea\u5df1\u7684\u9009\u6c11, \u4ee5\u53ca\u8fdd\u89c4\u5f00\u5c55\u7ade\u9009\u6d3b\u52a8. \u6b21\u65e5, \u6b66\u90e8\u65b0\u63a5\u4efb\u519c\u6797\u6c34\u4ea7\u5927\u81e3.<\/p>\n<h2 id=\"can-kao-zi-liao\"><a class=\"zola-anchor\" href=\"#can-kao-zi-liao\" aria-label=\"Anchor link for: can-kao-zi-liao\">\u53c2\u8003\u8d44\u6599<\/a><\/h2>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/zh.kantei.go.jp\/cn\/105\/meibo\/daijin\/index.html\">\u65e5\u672c\u56fd\u9996\u76f8\u5b98\u90b8: \u7b2c\u4e8c\u5c4a\u9ad8\u5e02\u6539\u7ec4\u5185\u9601 \u9601\u50da\u540d\u5355<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/zh.kantei.go.jp\/cn\/105\/meibo\/seimukan\/index.html\">\u65e5\u672c\u56fd\u9996\u76f8\u5b98\u90b8: \u7b2c\u4e8c\u5c4a\u9ad8\u5e02\u6539\u7ec4\u5185\u9601 \u653f\u52a1\u5b98\u540d\u5355<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/ginza-inaba.com\/aki.html\">\u9280\u5ea7 \u30af\u30e9\u30d6 \u7a32\u8449: \u30aa\u30fc\u30ca\u30fc\u767d\u5742\u4e9c\u7d00\u306e\u30d7\u30ed\u30d5\u30a3\u30fc\u30eb<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.soumu.go.jp\/senkyo\/seiji_s\/naruhodo01.html\">\u7dcf\u52d9\u7701: \u306a\u308b\u307b\u3069\uff01\u653f\u6cbb\u8cc7\u91d1\u3000\u653f\u6cbb\u8cc7\u91d1\u306e\u898f\u6b63<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/storage.jimin.jp\/pdf\/news\/information\/207975_1.pdf\">\u81ea\u7531\u6c11\u4e3b\u515a \u515a\u7d00\u59d4\u54e1\u4f1a: \u515a\u7d00\u59d4\u54e1\u4f1a\u306e\u5be9\u67fb\u7d50\u679c\u306b\u3064\u3044\u3066 (2024\/04\/04)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.chibanippo.co.jp\/newspack\/20240213\/1163415\">\u5171\u540c\u901a\u4fe1: \u81ea\u6c11\uff18\uff15\u4eba\u3001\u53ce\u652f\u5831\u544a\u66f8\u4e0d\u8a18\u8f09 (2024\/02\/13)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.jimin.jp\/news\/information\/209261.html\">\u81ea\u7531\u6c11\u4e3b\u515a: \u300c\u65e5\u672c\u5275\u751f\u300d\u7dcf\u9078\u6319 3\u3064\u306e\u8ad6\u70b9 (2024\/10\/15)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.jimin.jp\/news\/information\/209293.html\">\u81ea\u7531\u6c11\u4e3b\u515a: \u300c\u53b3\u3057\u3044\u5be9\u5224\u3092\u8b19\u865a\u306b\u53d7\u3051\u6b62\u3081\u308b\u300d\u7b2c50\u56de\u8846\u9662\u7dcf\u9078\u6319 191\u8b70\u5e2d\u3092\u7372\u5f97 \u6bd4\u8f03\u7b2c\u4e00\u515a\u3092\u7dad\u6301 (2024\/10\/28)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/clearing-house.org\/?p=6069\">\u60c5\u5831\u516c\u958b\u30af\u30ea\u30a2\u30ea\u30f3\u30b0\u30cf\u30a6\u30b9: \u653f\u6cbb\u8cc7\u91d1\u30d1\u30fc\u30c6\u30a3\u30fc\u53ce\u5165\u3000\u88cf\u91d1\u306f\u304a\u3044\u304f\u3089\u3067\u3057\u305f\u304b\uff1f\uff08\u88cf\u91d1\u56fd\u4f1a\u8b70\u54e1\u4e00\u89a7\uff09<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.chibanippo.co.jp\/newspack\/20241226\/1320705\">\u5171\u540c\u901a\u4fe1: \u81ea\u6c11\u88cf\u91d1\u8b70\u54e1\u3001\uff15\u4eba\u3092\u8d77\u8a34\u7336\u4e88 (2024\/12\/26)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.courts.go.jp\/saiban\/syurui\/syurui_keizi\/keizi_01_02\/index.html\">\u88c1\u5224\u6240: \u691c\u5bdf\u5b98\u306b\u3088\u308b\u8d77\u8a34\u30fb\u4e0d\u8d77\u8a34\u306e\u6c7a\u5b9a<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.moj.go.jp\/keiji1\/keiji_keiji11-1.html\">\u6cd5\u52d9\u7701: 1.\u3000\u691c\u5bdf\u5e81\u3068\u5211\u4e8b\u624b\u7d9a\u306e\u6d41\u308c<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.asahi.com\/articles\/DA3S16236844.html\">\u671d\u65e5\u65b0\u805e: \u95a2\u8846\u9662\u8b70\u54e1\u306b\u300c\u4e0d\u8d77\u8a34\u76f8\u5f53\u300d (2025\/06\/17)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/quick.saposen.jp\/news\/34826\">\u30c7\u30a4\u30ea\u30fc\u30b9\u30dd\u30fc\u30c4: \u95a2\u82b3\u5f18\u8b70\u54e1\u306e\u4e0d\u8d77\u8a34\u3001\u300c\u76f8\u5f53\u300d\u3000\u81ea\u6c11\u6d3e\u95a5\u88cf\u91d1\u3067\u691c\u5bdf\u5be9\u67fb\u4f1a (2025\/06\/16)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.tochigi-tv.jp\/news3\/page.php?id=00005112\">\u3068\u3061\u304e\u30c6\u30ec\u30d3: \u7c17\u548c\u751f\u8b70\u54e1\u306f\u300c\u4e0d\u8d77\u8a34\u76f8\u5f53\u300d (2025\/10\/14)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.nikkei.com\/article\/DGXZQOUD142ID0U5A011C2000000\/\">\u65e5\u672c\u7d4c\u6e08\u65b0\u805e: \u81ea\u6c11\u30fb\u52a0\u7530\u88d5\u4e4b\u53c2\u9662\u8b70\u54e1\u306e\u88cf\u91d1\u4e8b\u4ef6\u300c\u4e0d\u8d77\u8a34\u4e0d\u5f53\u300d\u3000\u691c\u5bdf\u5be9\u304c\u8b70\u6c7a (2025\/10\/14)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.chibanippo.co.jp\/newspack\/20260623\/1631852\">\u5171\u540c\u901a\u4fe1: \u81ea\u6c11\u88cf\u91d1\u3001\u5927\u91ce\u5143\u8b70\u54e1\u306b\u7f70\u91d1\u5211 (2026\/06\/23)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.nikkei.com\/article\/DGXZQOUD182TV0Y6A610C2000000\/\">\u65e5\u672c\u7d4c\u6e08\u65b0\u805e: \u81ea\u6c11\u88cf\u91d1\u3001\u5927\u91ce\u6cf0\u6b63\u5143\u53c2\u9662\u8b70\u54e1\u306b\u4e00\u90e8\u6709\u7f6a\u3000\u6771\u4eac\u5730\u88c1\u5224\u6c7a (2026\/06\/23)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.nikkei.com\/article\/DGXZQOUE286RK0Y4A820C2000000\/\">\u65e5\u672c\u7d4c\u6e08\u65b0\u805e: \u5800\u4e95\u5b66\u524d\u8b70\u54e1\u3001\u88cf\u91d1\u30fb\u9999\u5178\u914d\u5e03\u3067\u7f70\u91d1100\u4e07\u5186\u3000\u6771\u4eac\u7c21\u88c1 (2024\/08\/29)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.courts.go.jp\/assets\/hanrei\/hanrei-pdf-93547.pdf\">\u88c1\u5224\u6240: \u4ee4\u548c6\u5e74\u7279(\u308f)\u7b2c79\u53f7 \u653f\u6cbb\u8cc7\u91d1\u898f\u6b63\u6cd5\u9055\u53cd\u88ab\u544a\u4e8b\u4ef6 (2024\/09\/30)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.courts.go.jp\/assets\/hanrei\/hanrei-pdf-93690.pdf\">\u88c1\u5224\u6240: \u4ee4\u548c6\u5e74\u7279(\u308f)\u7b2c78\u53f7 \u653f\u6cbb\u8cc7\u91d1\u898f\u6b63\u6cd5\u9055\u53cd\u88ab\u544a\u4e8b\u4ef6 (2024\/09\/10)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.shugiin.go.jp\/internet\/itdb_kaigiroku.nsf\/html\/kaigiroku\/001821320240129001.htm\">\u8846\u8b70\u9662: \u7b2c213\u56de\u56fd\u4f1a\u3000\u4e88\u7b97\u59d4\u54e1\u4f1a\u3000\u7b2c1\u53f7\uff08\u4ee4\u548c6\u5e741\u670829\u65e5\uff08\u6708\u66dc\u65e5\uff09\uff09<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.shugiin.go.jp\/internet\/itdb_housei.nsf\/html\/housei\/21320240626064.htm\">\u8846\u8b70\u9662: \u653f\u6cbb\u8cc7\u91d1\u898f\u6b63\u6cd5\u306e\u4e00\u90e8\u3092\u6539\u6b63\u3059\u308b\u6cd5\u5f8b<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.pref.ibaraki.jp\/somu\/shichoson\/senkyo\/kaiseiseizisikinkiseihou.html\">\u8328\u57ce\u770c: \u6539\u6b63\u653f\u6cbb\u8cc7\u91d1\u898f\u6b63\u6cd5\u7b49\u306e\u6982\u8981\u306b\u3064\u3044\u3066<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.pref.tochigi.lg.jp\/senkyo\/r06syugi\/ichinichi\/ichinichi1.html\">\u6803\u6728\u770c\u9078\u6319\u7ba1\u7406\u59d4\u54e1\u4f1a: \u8846\u8b70\u9662\u8b70\u54e1\u7dcf\u9078\u6319 \u6295\u7968\u65e5\u306e\u4e00\u65e5\u300c1.\u6295\u7968\u306e\u624b\u9806\u300d<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.kobe-np.co.jp\/news\/senkyo\/2021\/shuuin\/?senCd=3\">\u795e\u6238\u65b0\u805eNEXT: \u8846\u9662\u90782021<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.pref.tochigi.lg.jp\/senkyo\/r03syugi\/file\/BS_KAIHYO.html\">\u6803\u6728\u770c\u9078\u6319\u7ba1\u7406\u59d4\u54e1\u4f1a: \u958b\u7968\u901f\u5831\uff08\u78ba\u5b9a\uff09 \u8846\u8b70\u9662 \u5c0f\u9078\u6319\u533a \u3010\u4ee4\u548c3\u5e7410\u670831\u65e5\u3011<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.city.kobe.lg.jp\/documents\/23740\/kekkasirabe2.pdf\">\u795e\u6238\u5e02\u9078\u6319\u7ba1\u7406\u59d4\u54e1\u4f1a: \u9078\u6319\u7d50\u679c\u8abf \u4ee4\u548c6\u5e7410\u670827\u65e5\u57f7\u884c \u8846\u8b70\u9662\u8b70\u54e1\u7dcf\u9078\u6319 \u6700\u9ad8\u88c1\u5224\u6240\u88c1\u5224\u5b98\u56fd\u6c11\u5be9\u67fb<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.pref.tochigi.lg.jp\/senkyo\/r06syugi\/file\/BS_KAIHYO.html\">\u6803\u6728\u770c\u9078\u6319\u7ba1\u7406\u59d4\u54e1\u4f1a: \u958b\u7968\u901f\u5831\uff08\u78ba\u5b9a\uff09 \u8846\u8b70\u9662 \u5c0f\u9078\u6319\u533a \u3010\u4ee4\u548c6\u5e7410\u670827\u65e5\u3011<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.pref.tochigi.lg.jp\/senkyo\/r03syugi\/qanda\/qanda10.html\">\u6803\u6728\u770c\u9078\u6319\u7ba1\u7406\u59d4\u54e1\u4f1a: \u9078\u6319Q&amp;A\u300cQ10.\u60dc\u6557\u7387\u3063\u3066\uff1f\u300d<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.city.kobe.lg.jp\/documents\/23740\/r8syugiinkekkasirabe.pdf\">\u795e\u6238\u5e02\u9078\u6319\u7ba1\u7406\u59d4\u54e1\u4f1a: \u9078\u6319\u7d50\u679c\u8abf \u4ee4\u548c8\u5e742\u67088\u65e5\u57f7\u884c \u8846\u8b70\u9662\u8b70\u54e1\u7dcf\u9078\u6319 \u6700\u9ad8\u88c1\u5224\u6240\u88c1\u5224\u5b98\u56fd\u6c11\u5be9\u67fb<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.pref.tochigi.lg.jp\/senkyo\/r08syugi\/file\/BS_KAIHYO.html\">\u6803\u6728\u770c\u9078\u6319\u7ba1\u7406\u59d4\u54e1\u4f1a: \u958b\u7968\u901f\u5831\uff08\u78ba\u5b9a\uff09 \u8846\u8b70\u9662 \u5c0f\u9078\u6319\u533a \u3010\u4ee4\u548c8\u5e742\u67088\u65e5\u3011<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.shugiin.go.jp\/Internet\/itdb_giinprof.nsf\/html\/profile\/425.html\">\u8846\u8b70\u9662: \u7c17\u548c\u751f\u541b<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.kantei.go.jp\/jp\/105\/statement\/2026\/0917kaiken.html\">\u9996\u76f8\u5b98\u90b8: \u9ad8\u5e02\u5185\u95a3\u7dcf\u7406\u5927\u81e3\u8a18\u8005\u4f1a\u898b (2026\/09\/17)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.mext.go.jp\/b_menu\/daijin\/detail\/mext_00731.html\">\u6587\u90e8\u79d1\u5b66\u7701: \u95a2\u82b3\u5f18\u6587\u90e8\u79d1\u5b66\u5927\u81e3\u8a18\u8005\u4f1a\u898b\u9332\uff08\u4ee4\u548c8\u5e749\u670818\u65e5\uff09<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.maff.go.jp\/j\/press-conf\/260918.html\">\u8fb2\u6797\u6c34\u7523\u7701: \u7c17\u8fb2\u6797\u6c34\u7523\u5927\u81e3\u5c31\u4efb\u8a18\u8005\u4f1a\u898b\u6982\u8981 (2026\/09\/18)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.nikkei.com\/article\/DGXZQOUA20CXM0Q5A520C2000000\/\">\u65e5\u672c\u7d4c\u6e08\u65b0\u805e: \u6c5f\u85e4\u62d3\u8fb2\u76f8\u304c\u8f9e\u8868\u63d0\u51fa\u3001\u30b3\u30e1\u767a\u8a00\u3067\u4e8b\u5b9f\u4e0a\u306e\u66f4\u8fed\u3000\u5f8c\u4efb\u306b\u5c0f\u6cc9\u9032\u6b21\u90ce\u6c0f (2025\/05\/21)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.mext.go.jp\/b_menu\/hakusho\/html\/hpaa202601\/1421221_00003.html\">\u6587\u90e8\u79d1\u5b66\u7701: \u4ee4\u548c8\u5e74\u7248\u79d1\u5b66\u6280\u8853\u30fb\u30a4\u30ce\u30d9\u30fc\u30b7\u30e7\u30f3\u767d\u66f8<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.mext.go.jp\/b_menu\/hakusho\/html\/hpaa202601\/1421221_00013.html\">\u6587\u90e8\u79d1\u5b66\u7701: \u7b2c2\u7ae0\u3000\u7b2c7\u671f\u57fa\u672c\u8a08\u753b\u3067\u76ee\u6307\u3059\u79d1\u5b66\u6280\u8853\u30fb\u30a4\u30ce\u30d9\u30fc\u30b7\u30e7\u30f3\u653f\u7b56\u306e\u59ff<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.shimotsuke.co.jp\/articles\/-\/1435333\">\u4e0b\u91ce\u65b0\u805e: \u7c17\u8fb2\u76f8\u300c\u4e88\u7b97\u30ab\u30c3\u30c8\u300d\u767a\u8a00\u3092\u5de1\u308b\u672c\u4eba\u3068\u653f\u754c\u306e\u52d5\u304d\u3010\u30bf\u30a4\u30e0\u30e9\u30a4\u30f3\u3011 (2026\/10\/15)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.nikkei.com\/article\/DGXZQOUA069400W6A001C2000000\/\">\u65e5\u672c\u7d4c\u6e08\u65b0\u805e: \u7c17\u548c\u751f\u8fb2\u76f8\u3001\u9053\u8def\u4e88\u7b97\u5de1\u308a\u56fd\u4ea4\u7701\u306b\u7167\u4f1a \u5727\u529b\u306f\u78ba\u8a8d\u3055\u308c\u305a (2026\/10\/06)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.nikkei.com\/article\/DGXZQOUA139470T11C26A0000000\/\">\u65e5\u672c\u7d4c\u6e08\u65b0\u805e: \u7c17\u548c\u751f\u8fb2\u76f8\u3001\u30d0\u30b9\u7121\u6599\u9001\u8fce\u300c\u9078\u7ba1\u306b\u78ba\u8a8d\u300d \u91ce\u515a\u300c\u554f\u3044\u5408\u308f\u305b\u306a\u3057\u3068\u56de\u7b54\u300d (2026\/10\/13)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/news.yahoo.co.jp\/articles\/5e8cc3c80c11250d41d12e86ab6019080a49641c\">\u6587\u6625\u30aa\u30f3\u30e9\u30a4\u30f3: \u300a\u516c\u9078\u6cd5\u9055\u53cd\u7591\u60d1\u3067\u96fb\u6483\u8f9e\u4efb\u300b\u7c17\u548c\u751f\u8fb2\u76f8\"\u30b7\u30e3\u30c8\u30eb\u30d0\u30b9\u8cb7\u53ce\"\u7591\u60d1\u3068\u306f\uff1f \u8f9e\u4efb\u306e\u304d\u3063\u304b\u3051\u3068\u306a\u3063\u305f\u9031\u520a\u6587\u6625\u306e\u5831\u9053 (2026\/10\/14)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/bunshun.jp\/articles\/-\/92823\">\u6587\u6625\u30aa\u30f3\u30e9\u30a4\u30f3: \u300a\u3064\u3044\u306b\u904b\u52d5\u54e1\u8cb7\u53ce\u7591\u60d1\u307e\u3067\u300b\u7c17\u548c\u751f\u8fb2\u76f8\u304c2024\u5e74\u8846\u9662\u9078\u3067\u9078\u6319\u904b\u52d5\u306b\u643a\u308f\u3063\u305f\u4e8b\u52d9\u54e1\u306b\u5831\u916c\u3092\u652f\u6255\u3063\u3066\u3044\u305f (2026\/10\/14)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.nippon.com\/ja\/news\/yjj2026101400736\/\">\u6642\u4e8b\u901a\u4fe1: \u9ad8\u5e02\u9996\u76f8\u3001\u7c17\u8fb2\u6c34\u76f8\u3092\u66f4\u8fed\uff1d\u5c31\u4efb\u5f8c\u521d\u3001\u653f\u6a29\u306b\u6253\u6483\u2015\u516c\u9078\u6cd5\u9055\u53cd\u7591\u60d1\u53d7\u3051 (2026\/10\/14)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.shimotsuke.co.jp\/articles\/-\/1441872\">\u4e0b\u91ce\u65b0\u805e: \u7c17\u524d\u8fb2\u76f8\u3001\u8846\u9662\u9078\u3067\u300c\u652f\u6255\u3044\u3092\u3059\u308b\u3088\u3046\u306b\u300d\u3068\u30e1\u30fc\u30eb\u9001\u4fe1 \u5831\u916c\u6255\u3044\u6295\u7968\u4f9d\u983c\u3055\u305b\u305f\u304b \u95a2\u4fc2\u8005\u304c\u8a3c\u8a00 (2026\/10\/16)<\/a><\/li>\n<\/ul>\n"},{"title":"\u6f2b\u8c08 <\u5deb\u5e083>","published":"2026-09-12T13:34:13+09:00","updated":"2026-09-12T13:34:13+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/a-casual-talk-about-the-witcher-3\/"}},"id":"https:\/\/memwey.github.io\/posts\/a-casual-talk-about-the-witcher-3\/","content":"<h2 id=\"wu-shi-3-de-cheng-gong-yu-ji-xian\"><a class=\"zola-anchor\" href=\"#wu-shi-3-de-cheng-gong-yu-ji-xian\" aria-label=\"Anchor link for: wu-shi-3-de-cheng-gong-yu-ji-xian\">&lt;\u5deb\u5e083&gt; \u7684\u6210\u529f\u4e0e\u6781\u9650<\/a><\/h2>\n<p>&lt;\u5deb\u5e083&gt; \u51e0\u4e4e\u662f\u4e00\u6b3e\u65e0\u53ef\u6311\u5254\u7684\u6210\u529f\u4f5c\u54c1.<\/p>\n<p>\u8d85\u8fc7 6500 \u4e07\u4efd\u7684\u9500\u91cf, \u8d85\u8fc7 6 \u4ebf\u7f8e\u5143\u7684\u6536\u5165, PC, PlayStation, Xbox \u548c Nintendo Switch \u65b0\u65e7\u4e16\u4ee3\u5168\u5e73\u53f0\u8986\u76d6, Steam \u56fd\u533a\u6253\u6298\u65f6\u53ea\u8981\u4e8c\u4e09\u5341\u5143. \u4e24\u90e8\u5927\u578b\u8d44\u6599\u7247 &lt;\u77f3\u4e4b\u5fc3&gt; \u548c &lt;\u8840\u4e0e\u9152&gt; \u5e7f\u53d7\u597d\u8bc4, \u6b21\u4e16\u4ee3\u7248\u672c\u514d\u8d39\u63d0\u4f9b\u7ed9\u8001\u73a9\u5bb6, \u5230\u4e86 2026 \u5e74, CDPR \u53c8\u5ba3\u5e03\u4e86\u65b0\u7684\u8d44\u6599\u7247\u548c\u91cd\u5236\u7248, \u91cd\u5236\u7248\u4f9d\u7136\u514d\u8d39\u63d0\u4f9b\u7ed9\u5df2\u6709\u73a9\u5bb6. \u8fd9\u6b3e 2015 \u5e74\u53d1\u552e\u7684\u6e38\u620f, \u5230 2026 \u5e74\u8fd8\u5728\u63a8\u51fa\u65b0\u5185\u5bb9, \u8fd9\u5728\u6e38\u620f\u884c\u4e1a\u4e2d\u5df2\u7ecf\u9887\u4e3a\u7f55\u89c1\u4e86.<\/p>\n<p>\u9664\u6b64\u4e4b\u5916, \"\u730e\u9b54\u4eba\" \u4e5f\u65e9\u5df2\u4e0d\u53ea\u662f\u4e00\u4e2a\u6e38\u620f\u7cfb\u5217. \u539f\u8457\u5c0f\u8bf4\u88ab\u7ffb\u8bd1\u5230\u4e16\u754c\u5404\u5730, Netflix \u63a8\u51fa\u4e86\u7535\u89c6\u5267, \u8fd8\u6709\u684c\u6e38\u548c\u97f3\u4e50\u4f1a, \u6770\u6d1b\u7279\u4e5f\u5230\u5904\u5ba2\u4e32, \u4ece &lt;\u7075\u9b42\u80fd\u529b6&gt; \u548c &lt;\u602a\u7269\u730e\u4eba:\u4e16\u754c&gt; \u4e00\u8def\u4e32\u573a\u5230\u4e86 &lt;\u6697\u9ed1\u7834\u574f\u795e4&gt;.<\/p>\n<p>\u53ef\u4ee5\u8bf4, CDPR \u5df2\u7ecf\u628a\u4e00\u6b3e\u4e70\u65ad\u5236\u5355\u673a\u6e38\u620f\u80fd\u591f\u505a\u7684\u4e8b\u60c5\u51e0\u4e4e\u90fd\u505a\u4e86: \u4e0d\u65ad\u964d\u4f4e\u4ef7\u683c, \u79fb\u690d\u5230\u66f4\u591a\u5e73\u53f0, \u652f\u6301\u66f4\u591a\u8bed\u8a00, \u957f\u671f\u7ef4\u62a4, \u514d\u8d39\u5347\u7ea7, \u7ee7\u7eed\u5236\u4f5c\u65b0\u5185\u5bb9. \u5b83\u5df2\u7ecf\u8986\u76d6\u4e86\u5e02\u573a\u4e0a\u7edd\u5927\u591a\u6570\u6709\u53ef\u80fd\u8d2d\u4e70\u8fd9\u7c7b\u6e38\u620f\u7684\u73a9\u5bb6.<\/p>\n<p>\u4f46\u8fd9\u4e5f\u51e0\u4e4e\u5c31\u662f\u5b83\u7684\u6781\u9650\u4e86. 6500 \u4e07\u4efd\u5f53\u7136\u5f88\u591a, \u4f46\u548c\u4e16\u754c\u4eba\u53e3\u76f8\u6bd4\u4f9d\u7136\u53ea\u662f\u5f88\u5c0f\u7684\u4e00\u90e8\u5206. \u8fd9\u4e0d\u662f\u56e0\u4e3a &lt;\u5deb\u5e083&gt; \u505a\u5f97\u4e0d\u591f\u597d, \u4e5f\u4e0d\u5b8c\u5168\u662f\u56e0\u4e3a\u5b83\u5356\u5f97\u592a\u8d35. \u5728\u6e38\u620f\u4ef7\u683c\u4e4b\u5916, \u8fd8\u6709\u8bb8\u591a\u6765\u81ea\u73b0\u5b9e\u4e16\u754c\u7684\u56e0\u7d20, \u51b3\u5b9a\u4e86\u73a9\u5bb6\u662f\u5426\u6709\u673a\u4f1a\u8fdb\u5165\u8fd9\u4e2a\u4e16\u754c.<\/p>\n<h2 id=\"xiang-yao-wan-wu-shi-3-xu-yao-shen-me\"><a class=\"zola-anchor\" href=\"#xiang-yao-wan-wu-shi-3-xu-yao-shen-me\" aria-label=\"Anchor link for: xiang-yao-wan-wu-shi-3-xu-yao-shen-me\">\u60f3\u8981\u73a9 &lt;\u5deb\u5e083&gt; \u9700\u8981\u4ec0\u4e48<\/a><\/h2>\n<p>\u5bf9\u4e8e\u5df2\u7ecf\u62e5\u6709\u7535\u8111\u6216\u8005\u4e3b\u673a\u7684\u73a9\u5bb6\u6765\u8bf4, \u6253\u6298\u540e\u7684 &lt;\u5deb\u5e083&gt; \u975e\u5e38\u4fbf\u5b9c. \u4fc3\u9500\u65f6\u82b1\u4e8c\u4e09\u5341\u5143, \u5c31\u53ef\u4ee5\u4e70\u5230\u4e00\u6b3e\u80fd\u591f\u73a9\u51e0\u5341\u751a\u81f3\u4e0a\u767e\u5c0f\u65f6\u7684\u6e38\u620f, \u6027\u4ef7\u6bd4\u9ad8\u5f97\u6709\u70b9\u4e0d\u50cf\u8bdd. \u751a\u81f3\u6211\u90fd\u8d81\u7740\u6253\u6298\u9001\u4e86\u4e00\u4efd\u7ed9\u6211\u8001\u5a46, \u867d\u7136\u5979\u4e0d\u600e\u4e48\u73a9, Steam \u5bf9\u5979\u6765\u8bf4\u662f &lt;\u90fd\u5e02:\u5929\u9645\u7ebf&gt; \u542f\u52a8\u5668.<\/p>\n<p>\u4f46\u662f\u60f3\u8981\u73a9 &lt;\u5deb\u5e083&gt;, \u9996\u5148\u8981\u6709\u4e00\u53f0\u80fd\u591f\u8fd0\u884c\u5b83\u7684\u8bbe\u5907. \u5373\u4f7f\u4e0d\u8ffd\u6c42\u9ad8\u753b\u8d28, \u4e00\u53f0\u5408\u9002\u7684\u7535\u8111\u6216\u8005\u6e38\u620f\u4e3b\u673a\u4e5f\u4e0d\u4f1a\u51ed\u7a7a\u51fa\u73b0. \u8bbe\u5907\u8fd8\u9700\u8981\u7a33\u5b9a\u7684\u7535\u529b, \u53ef\u4ee5\u4e0b\u8f7d\u51e0\u5341 GB \u6570\u636e\u7684\u7f51\u7edc, \u80fd\u591f\u6b63\u5e38\u4f7f\u7528\u7684\u6e38\u620f\u5e73\u53f0\u548c\u652f\u4ed8\u65b9\u5f0f. \u73a9\u5bb6\u9700\u8981\u8bfb\u61c2\u6e38\u620f\u652f\u6301\u7684\u67d0\u4e00\u79cd\u8bed\u8a00, \u6700\u540e\u8fd8\u8981\u6709\u51e0\u5341\u4e2a\u5c0f\u65f6\u53ef\u4ee5\u81ea\u7531\u652f\u914d\u7684\u65f6\u95f4. \u8fd9\u4e9b\u6761\u4ef6\u5728\u6b27\u6d32, \u5317\u7f8e\u548c\u4e1c\u4e9a\u7684\u8bb8\u591a\u57ce\u5e02\u91cc\u975e\u5e38\u666e\u901a, \u4ee5\u81f3\u4e8e\u6211\u4eec\u5e38\u5e38\u611f\u89c9\u4e0d\u5230\u5b83\u4eec\u7684\u5b58\u5728. \u7535\u8111\u5df2\u7ecf\u4e70\u4e86, \u7535\u8d39\u6bcf\u6708\u7167\u5e38\u652f\u4ed8, \u7f51\u7edc\u63a5\u901a\u4e4b\u540e\u4e00\u76f4\u653e\u5728\u90a3\u91cc, \u652f\u4ed8\u53ea\u9700\u8981\u70b9\u51e0\u4e0b\u9f20\u6807. \u6700\u7ec8\u770b\u5230\u7684\u6210\u672c, \u5c31\u53ea\u5269\u4e0b Steam \u5546\u5e97\u91cc\u7684\u4e8c\u4e09\u5341\u5143.<\/p>\n<p>\u4f46\u662f\u5728\u53e6\u5916\u4e00\u4e9b\u56fd\u5bb6\u548c\u5730\u533a, \u6e38\u620f\u8bbe\u5907\u53ef\u80fd\u76f8\u5f53\u4e8e\u666e\u901a\u4eba\u51e0\u4e2a\u6708\u751a\u81f3\u66f4\u957f\u65f6\u95f4\u7684\u6536\u5165, \u9ad8\u901f\u7f51\u7edc\u5e76\u4e0d\u666e\u53ca, \u7535\u529b\u4f9b\u5e94\u4e5f\u4e0d\u7a33\u5b9a. \u6709\u4e9b\u5730\u65b9\u65e0\u6cd5\u65b9\u4fbf\u5730\u4f7f\u7528\u5728\u7ebf\u652f\u4ed8, \u6709\u4e9b\u8bed\u8a00\u6839\u672c\u4e0d\u4f1a\u51fa\u73b0\u5728\u5927\u578b\u6e38\u620f\u7684\u672c\u5730\u5316\u540d\u5355\u91cc. \u4f4e\u6536\u5165\u4e0d\u4ec5\u610f\u5473\u7740\u4e70\u4e0d\u8d77\u6e38\u620f, \u8fd8\u53ef\u80fd\u610f\u5473\u7740\u6ca1\u6709\u8bbe\u5907, \u6ca1\u6709\u7a33\u5b9a\u7684\u5c45\u4f4f\u7a7a\u95f4, \u9700\u8981\u957f\u65f6\u95f4\u5de5\u4f5c, \u4e5f\u6ca1\u6709\u53ef\u4ee5\u8fde\u7eed\u6295\u5165\u5230\u4e00\u6b3e\u5927\u578b\u89d2\u8272\u626e\u6f14\u6e38\u620f\u91cc\u7684\u95f2\u6687.<\/p>\n<p>\u6240\u4ee5\u6e38\u620f\u5176\u5b9e\u662f\u4e00\u79cd\u5962\u4f88\u54c1. \u5b83\u7684\u5962\u4f88\u5e76\u4e0d\u4e00\u5b9a\u4f53\u73b0\u5728\u4ef7\u683c\u4e0a, \u800c\u662f\u9700\u8981\u4e00\u6574\u5957\u73b0\u4ee3\u751f\u6d3b\u6761\u4ef6\u5728\u80cc\u540e\u652f\u6491. \u53ea\u6709\u5f53\u8fd9\u4e9b\u6761\u4ef6\u90fd\u5df2\u7ecf\u5177\u5907\u65f6, \u6211\u4eec\u624d\u4f1a\u89c9\u5f97\u4e00\u6b3e\u51e0\u5341\u5143\u7684\u6e38\u620f\u975e\u5e38\u4fbf\u5b9c.<\/p>\n<h2 id=\"you-xi-ying-gai-shi-yi-chong-quan-li\"><a class=\"zola-anchor\" href=\"#you-xi-ying-gai-shi-yi-chong-quan-li\" aria-label=\"Anchor link for: you-xi-ying-gai-shi-yi-chong-quan-li\">\u6e38\u620f\u5e94\u8be5\u662f\u4e00\u79cd\u6743\u5229<\/a><\/h2>\n<p>&lt;\u5deb\u5e083&gt; \u65e0\u6cd5\u56de\u7b54\u4e00\u4e2a\u66f4\u6839\u672c\u7684\u95ee\u9898: \u4e3a\u4ec0\u4e48\u6709\u4e9b\u4eba\u8fde\u4ed8\u8d39\u73a9\u6e38\u620f\u7684\u53ef\u80fd\u90fd\u6ca1\u6709?<\/p>\n<p>\u4eca\u5929\u7684\u4eba\u7c7b\u793e\u4f1a\u5df2\u7ecf\u80fd\u591f\u751f\u4ea7\u8fdc\u8d85\u57fa\u672c\u751f\u5b58\u9700\u8981\u7684\u7269\u8d28\u4e0e\u6587\u5316\u4ea7\u54c1. \u4e0e\u6b64\u540c\u65f6, \u73b0\u5b9e\u4e2d\u4ecd\u7136\u6709\u4eba\u56e0\u4e3a\u7f3a\u5c11\u98df\u7269\u800c\u6b7b\u53bb, \u66f4\u591a\u7684\u4eba\u867d\u7136\u80fd\u591f\u6e29\u9971, \u5374\u6ca1\u6709\u6761\u4ef6\u548c\u6536\u5165\u4eab\u53d7\u73b0\u4ee3\u751f\u6d3b.<\/p>\n<p>\u5bf9\u4e00\u4e2a\u6b63\u5728\u6328\u997f\u7684\u4eba\u6765\u8bf4, \u98df\u7269\u5f53\u7136\u6bd4\u6e38\u620f\u91cd\u8981. \u4f46\u5bf9\u4eca\u5929\u7684\u4eba\u7c7b\u793e\u4f1a\u6765\u8bf4, \u8fd9\u672c\u6765\u4e0d\u5e94\u8be5\u662f\u4e00\u9053\u4e8c\u9009\u4e00\u7684\u95ee\u9898. \u4eba\u7c7b\u7f3a\u5c11\u7684\u5df2\u7ecf\u4e0d\u53ea\u662f\u751f\u4ea7\u80fd\u529b, \u800c\u662f\u8ba9\u6240\u6709\u4eba\u5206\u4eab\u8fd9\u4e9b\u6210\u679c\u7684\u65b9\u5f0f.<\/p>\n<p>\u90a3\u4e48, \u6e38\u620f\u662f\u5426\u4e5f\u5e94\u8be5\u88ab\u770b\u4f5c\u4e00\u79cd\u6743\u5229?<\/p>\n<p>\u8fd9\u5f53\u7136\u662f\u4e00\u4e2a\u5f88\u96be\u56de\u7b54\u7684\u95ee\u9898. \u5982\u679c\u6e38\u620f\u662f\u4e00\u79cd\u6743\u5229, \u8c01\u5e94\u8be5\u8d1f\u8d23\u4fdd\u969c\u5b83, \u53c8\u5e94\u8be5\u901a\u8fc7\u600e\u6837\u7684\u65b9\u5f0f\u5b9e\u73b0? \u8fd9\u4e9b\u95ee\u9898\u663e\u7136\u4e0d\u662f\u4e00\u5bb6\u6e38\u620f\u516c\u53f8\u80fd\u591f\u89e3\u51b3\u7684, \u4f46\u4e5f\u8bb8\u5728\u56de\u7b54\u4e4b\u524d, \u53ef\u4ee5\u5148\u5206\u6e05\u53e6\u4e00\u4ef6\u4e8b.<\/p>\n<p>\u6709\u4eba\u53ef\u4ee5\u4e70\u66f4\u8d35\u7684\u8bbe\u5907\u548c\u6e38\u620f, \u6709\u4eba\u53ea\u80fd\u9009\u62e9\u4fbf\u5b9c\u7684\u8bbe\u5907\u548c\u6253\u6298\u6e38\u620f, \u8fd9\u79cd\u6d88\u8d39\u5dee\u5f02\u5373\u4f7f\u4e0d\u5e73\u7b49, \u4f3c\u4e4e\u4e5f\u8fd8\u53ef\u4ee5\u63a5\u53d7. \u4f46\u5982\u679c\u4e00\u4e2a\u4eba\u88ab\u6321\u5728\u6e38\u620f\u4e16\u754c\u4e4b\u5916, \u662f\u56e0\u4e3a\u7f3a\u5c11\u57fa\u672c\u7684\u6559\u80b2, \u7a33\u5b9a\u7684\u7535\u529b\u548c\u7f51\u7edc, \u4ee5\u53ca\u53ef\u4ee5\u8d1f\u62c5\u7684\u4fe1\u606f\u8bbe\u5907, \u6027\u8d28\u5c31\u4e0d\u540c\u4e86. \u8fd9\u4e9b\u90fd\u662f\u8fdb\u5165\u73b0\u4ee3\u751f\u6d3b\u7684\u57fa\u7840, \u672c\u4e0d\u5e94\u8be5\u6210\u4e3a\u5c11\u6570\u4eba\u7684\u7279\u6743.<\/p>\n<h2 id=\"zi-you-ruan-jian-jing-shen-yu-you-xi\"><a class=\"zola-anchor\" href=\"#zi-you-ruan-jian-jing-shen-yu-you-xi\" aria-label=\"Anchor link for: zi-you-ruan-jian-jing-shen-yu-you-xi\">\u81ea\u7531\u8f6f\u4ef6\u7cbe\u795e\u4e0e\u6e38\u620f<\/a><\/h2>\n<p>\u8f6f\u4ef6\u884c\u4e1a\u4e2d\u6709\u975e\u5e38\u6210\u719f\u7684<a rel=\"external\" href=\"https:\/\/www.gnu.org\/philosophy\/free-sw.html\">\u81ea\u7531\u8f6f\u4ef6\u8fd0\u52a8<\/a>, \u4f46\u662f\u548c\u8f6f\u4ef6\u5173\u7cfb\u5982\u6b64\u5bc6\u5207\u7684\u6e38\u620f\u884c\u4e1a, \u81ea\u7531\u8f6f\u4ef6\u5374\u76f8\u5bf9\u5c11\u89c1. \u5f53\u7136\u4e5f\u6709\u4e00\u4e9b\u4f8b\u5b50. <a rel=\"external\" href=\"https:\/\/www.openttd.org\/\">OpenTTD<\/a> \u548c <a rel=\"external\" href=\"https:\/\/www.freeciv.org\/\">Freeciv<\/a> \u90fd\u662f\u957f\u671f\u7531\u793e\u533a\u7ef4\u62a4\u7684\u81ea\u7531\u6e38\u620f, <a rel=\"external\" href=\"https:\/\/godotengine.org\/\">Godot<\/a> \u5219\u662f\u4e00\u6b3e\u81ea\u7531\u5f00\u6e90\u7684\u6e38\u620f\u5f15\u64ce. \u6700\u521d\u4f5c\u4e3a &lt;\u9b54\u517d\u4e89\u97383&gt; \u81ea\u5b9a\u4e49\u5730\u56fe\u51fa\u73b0\u7684 Dota, \u5728\u5f00\u53d1\u548c\u4f20\u64ad\u65b9\u5f0f\u4e0a\u5c31\u9887\u4e3a\u63a5\u8fd1\u81ea\u7531\u8f6f\u4ef6, \u4e0d\u540c\u4f5c\u8005\u548c\u73a9\u5bb6\u5728\u524d\u4eba\u5de5\u4f5c\u7684\u57fa\u7840\u4e0a\u4e0d\u65ad\u4fee\u6539\u548c\u5b8c\u5584, \u6700\u7ec8\u53d1\u5c55\u51fa\u4e86\u4e00\u6574\u4e2a MOBA \u6e38\u620f\u7c7b\u578b.<\/p>\n<p>\u6e38\u620f\u73a9\u5bb6\u8ba8\u8bba\u5f97\u66f4\u591a\u7684\u662f\u6d88\u8d39\u8005\u6743\u5229, \u800c\u4e0d\u662f\u8f6f\u4ef6\u63a7\u5236\u6743. \u4f46\u4ece\u81ea\u7531\u8f6f\u4ef6\u7684\u89c6\u89d2\u770b, \u73b0\u4ee3\u6e38\u620f\u786e\u5b9e\u8d8a\u6765\u8d8a\u50cf\"\u5382\u5546\u5141\u8bb8\u4f60\u8bbf\u95ee\u7684\u4e00\u9879\u5a31\u4e50\u670d\u52a1\", \u800c\u4e0d\u662f\"\u4f60\u62e5\u6709\u7684\u4e00\u4efd\u8f6f\u4ef6\".<\/p>\n<h2 id=\"shu-zi-ban-de-da-ji\"><a class=\"zola-anchor\" href=\"#shu-zi-ban-de-da-ji\" aria-label=\"Anchor link for: shu-zi-ban-de-da-ji\">\u6570\u5b57\u7248\u7684\u6253\u51fb<\/a><\/h2>\n<p>\u6570\u5b57\u7248\u548c\u5b9e\u4f53\u7248\u7684\u4e89\u8bba, \u7ecf\u5e38\u88ab\u7406\u89e3\u4e3a\u4e00\u4e2a\u6240\u6709\u6743\u95ee\u9898: \u73a9\u5bb6\u4ed8\u94b1\u4e4b\u540e, \u5f97\u5230\u7684\u7a76\u7adf\u662f\u4e00\u4ef6\u5c5e\u4e8e\u81ea\u5df1\u7684\u4e1c\u897f, \u8fd8\u662f\u4e00\u4efd\u968f\u65f6\u53ef\u80fd\u5931\u6548\u7684\u4f7f\u7528\u8bb8\u53ef? \u4f46\u5b9e\u4f53\u5a92\u4ecb\u7684\u610f\u4e49\u5e76\u4e0d\u53ea\u6709\u6240\u6709\u6743.<\/p>\n<p>\u4e00\u53f0\u8bbe\u5907\u548c\u4e00\u4efd\u6e38\u620f\u62f7\u8d1d\u53ef\u4ee5\u88ab\u5f88\u591a\u4eba\u4f7f\u7528, \u968f\u7740\u65f6\u95f4\u63a8\u79fb, \u539f\u672c\u6602\u8d35\u7684\u6e38\u620f\u6587\u5316\u4e5f\u4f1a\u9010\u6e10\u8fdb\u5165\u6536\u5165\u66f4\u4f4e\u7684\u4eba\u7fa4. \u4ece\u8fd9\u4e2a\u89d2\u5ea6\u770b, \u5b9e\u4f53\u5a92\u4ecb\u4e0d\u4ec5\u662f\u4e00\u79cd\u6240\u6709\u6743\u5f62\u5f0f, \u8fd8\u662f\u4e00\u79cd\u8ba9\u4f4e\u6536\u5165\u548c\u6570\u5b57\u53d1\u884c\u6761\u4ef6\u53d7\u9650\u4eba\u7fa4\u8fdb\u5165\u6e38\u620f\u6587\u5316\u7684\u57fa\u7840\u8bbe\u65bd. \u6570\u5b57\u7248\u5207\u65ad\u7684\u6b63\u662f\u8fd9\u79cd\u6d41\u52a8. \u4efb\u5929\u5802\u7684\u94a5\u5319\u5361\u4ecd\u7136\u53ef\u4ee5\u8f6c\u5356, \u4f46\u662f\u5361\u91cc\u6ca1\u6709\u5b8c\u6574\u7684\u6e38\u620f\u6570\u636e, \u7b2c\u4e00\u6b21\u8fd0\u884c\u4ecd\u7136\u4f9d\u8d56\u7f51\u7edc, \u670d\u52a1\u5668\u548c\u8db3\u591f\u7684\u5b58\u50a8\u7a7a\u95f4, \u4fdd\u7559\u4e86\u53ef\u4ee5\u8f6c\u624b\u7684\u5916\u58f3, \u5374\u5f00\u59cb\u524a\u5f31\u5b9e\u4f53\u5a92\u4ecb\u72ec\u7acb\u4fdd\u5b58\u548c\u4f7f\u7528\u6e38\u620f\u7684\u80fd\u529b.<\/p>\n<p>\u8fd9\u79cd\u53d8\u5316\u6700\u5148\u5f71\u54cd\u7684, \u5f80\u5f80\u4e0d\u662f\u4f1a\u5728\u7f51\u4e0a\u4e89\u8bba\u6240\u6709\u6743\u7684\u6838\u5fc3\u73a9\u5bb6, \u800c\u662f\u90a3\u4e9b\u4f9d\u9760\u4e8c\u624b\u8bbe\u5907\u548c\u4e8c\u624b\u6e38\u620f\u624d\u80fd\u8fdb\u5165\u6e38\u620f\u4e16\u754c\u7684\u4eba. \u4ed6\u4eec\u4e0d\u4f1a\u8d2d\u4e70\u9996\u53d1\u6e38\u620f, \u4e0d\u4f1a\u5728\u77ed\u671f\u8d21\u732e\u65b0\u7684\u9500\u91cf, \u4e5f\u5f88\u5c11\u51fa\u73b0\u5728\u5382\u5546\u8c03\u67e5\u548c\u6e38\u620f\u793e\u533a\u91cc. \u5f53\u5b9e\u4f53\u5a92\u4ecb\u9010\u6e10\u6d88\u5931\u65f6, \u4ed6\u4eec\u4e0d\u4f1a\u7559\u4e0b\u9000\u6b3e\u6216\u8005\u5dee\u8bc4, \u53ea\u4f1a\u5b89\u9759\u5730\u5931\u53bb\u4e00\u79cd\u539f\u672c\u5b58\u5728\u7684\u9009\u62e9. \u6e38\u620f\u516c\u53f8\u770b\u5230\u7684\u662f\u6570\u5b57\u7248\u9500\u91cf\u6bd4\u4f8b\u4e0d\u65ad\u4e0a\u5347. \u4f46\u662f\u6570\u636e\u65e0\u6cd5\u544a\u8bc9\u4ed6\u4eec, \u6709\u591a\u5c11\u4eba\u4e0d\u662f\u9009\u62e9\u4e86\u6570\u5b57\u7248, \u800c\u662f\u5728\u5b9e\u4f53\u5a92\u4ecb\u6d88\u5931\u4ee5\u540e, \u6839\u672c\u6ca1\u6709\u518d\u6210\u4e3a\u73a9\u5bb6.<\/p>\n<h2 id=\"wu-shi-3-yu-wo-men-de-shi-jie\"><a class=\"zola-anchor\" href=\"#wu-shi-3-yu-wo-men-de-shi-jie\" aria-label=\"Anchor link for: wu-shi-3-yu-wo-men-de-shi-jie\">&lt;\u5deb\u5e083&gt; \u4e0e\u6211\u4eec\u7684\u4e16\u754c<\/a><\/h2>\n<p>&lt;\u5deb\u5e083&gt; \u7528\u6781\u5927\u7684\u4eba\u529b\u7269\u529b, \u6784\u9020\u4e86\u4e00\u4e2a\u5e9e\u5927\u800c\u5b8c\u6574\u7684\u865a\u62df\u4e16\u754c.<\/p>\n<p>\u5728\u5a01\u4f26, \u6218\u4e89\u6467\u6bc1\u4e86\u6751\u5e84\u548c\u519c\u7530, \u666e\u901a\u4eba\u65e2\u8981\u9762\u5bf9\u519b\u961f, \u4e5f\u8981\u9762\u5bf9\u5f3a\u76d7\u548c\u602a\u7269. \u5728\u8bfa\u7ef4\u683c\u745e, \u5973\u5deb\u548c\u975e\u4eba\u79cd\u65cf\u906d\u5230\u516c\u5f00\u8feb\u5bb3. \u8d35\u65cf\u5728\u4e3e\u884c\u5bb4\u4f1a\u548c\u4e89\u593a\u738b\u4f4d, \u66f4\u591a\u7684\u4eba\u5374\u53ea\u80fd\u5728\u6218\u4e89, \u9965\u997f\u548c\u75be\u75c5\u4e2d\u6323\u624e. \u6770\u6d1b\u7279\u5e76\u4e0d\u80fd\u6539\u53d8\u8fd9\u4e2a\u4e16\u754c. \u5f88\u591a\u4efb\u52a1\u4e5f\u4e0d\u5b58\u5728\u5b8c\u7f8e\u7684\u9009\u62e9. \u4f46\u662f\u6e38\u620f\u4ecd\u7136\u5728\u8fd9\u4e9b\u6545\u4e8b\u4e2d\u6b4c\u9882\u4e86\u4eba\u7684\u5c0a\u4e25, \u6b63\u4e49\u548c\u516c\u5e73, \u6279\u5224\u4e86\u66b4\u529b, \u4e0d\u516c\u4e0e\u6b67\u89c6, <del>\u751a\u81f3\u8fd8\u8ba8\u8bba\u4e86\u82b1\u5fc3\u53ef\u80fd\u5e26\u6765\u7684\u4e25\u91cd\u540e\u679c<\/del>. \u80fd\u591f\u6784\u9020\u8fd9\u6837\u4e00\u4e2a\u4e16\u754c, \u672c\u8eab\u5c31\u662f\u4eba\u7c7b\u73b0\u4ee3\u6280\u672f\u548c\u793e\u4f1a\u534f\u4f5c\u7684\u6210\u679c. \u4e0a\u5343\u4eba\u4f7f\u7528\u8ba1\u7b97\u673a, \u7f51\u7edc, \u52a8\u4f5c\u6355\u6349\u548c\u6570\u5b57\u56fe\u5f62\u6280\u672f\u5171\u540c\u5de5\u4f5c, \u6700\u7ec8\u8ba9\u4e16\u754c\u5404\u5730\u7684\u73a9\u5bb6\u53ef\u4ee5\u5750\u5728\u5c4f\u5e55\u524d, \u8fdb\u5165\u4e00\u4e2a\u5e76\u4e0d\u5b58\u5728\u7684\u5927\u9646.<\/p>\n<p>\u7136\u800c, \u8fd9\u4e2a\u5728\u865a\u62df\u4e16\u754c\u4e2d\u5173\u5fc3\u8d2b\u7a77\u548c\u82e6\u96be\u7684\u6e38\u620f, \u6700\u7ec8\u4ecd\u7136\u88ab\u73b0\u5b9e\u4e16\u754c\u7684\u4e0d\u5e73\u7b49\u5305\u56f4. \u5e76\u4e0d\u662f\u6240\u6709\u4eba\u90fd\u62e5\u6709\u8fdb\u5165\u8fd9\u4e2a\u865a\u62df\u4e16\u754c\u7684\u6761\u4ef6. \u5728\u4e00\u4e9b\u5730\u65b9, \u73a9\u5bb6\u8ba8\u8bba\u753b\u8d28, \u5e27\u6570\u548c\u5149\u7ebf\u8ffd\u8e2a; \u5728\u53e6\u4e00\u4e9b\u5730\u65b9, \u4eba\u4eec\u4ecd\u7136\u7f3a\u5c11\u7a33\u5b9a\u7684\u7535\u529b, \u7f51\u7edc, \u98df\u7269\u548c\u533b\u7597. \u4eba\u7c7b\u5df2\u7ecf\u53ef\u4ee5\u98de\u51fa\u5730\u7403, \u4e5f\u53ef\u4ee5\u6784\u9020\u51fa &lt;\u5deb\u5e083&gt; \u8fd9\u6837\u7684\u865a\u62df\u4e16\u754c, \u73b0\u5b9e\u4e2d\u5374\u4ecd\u7136\u6709\u4eba\u88ab\u6321\u5728\u73b0\u4ee3\u751f\u6d3b\u4e4b\u5916.<\/p>\n<p>CDPR \u5df2\u7ecf\u505a\u4e86\u76f8\u5f53\u591a\u5bf9\u73a9\u5bb6\u53cb\u597d\u7684\u4e8b\u60c5. &lt;\u5deb\u5e083&gt; \u767b\u9646\u4e86\u51e0\u4e4e\u6240\u6709\u4e3b\u6d41\u5e73\u53f0, \u4ef7\u683c\u4e0d\u65ad\u964d\u4f4e, \u591a\u6b21\u5411\u8001\u73a9\u5bb6\u63d0\u4f9b\u514d\u8d39\u66f4\u65b0, \u53d1\u552e\u5341\u591a\u5e74\u4ee5\u540e\u4ecd\u7136\u7ee7\u7eed\u7ef4\u62a4. \u5b83\u5df2\u7ecf\u662f\u4e00\u6b3e\u5546\u4e1a\u6e38\u620f\u80fd\u591f\u505a\u5230\u7684\u6700\u597d\u4f8b\u5b50\u4e4b\u4e00. \u4f46\u4e00\u5bb6\u6e38\u620f\u516c\u53f8\u65e0\u8bba\u591a\u4e48\u826f\u5fc3, \u90fd\u65e0\u6cd5\u8ba9\u6ca1\u6709\u7535\u529b\u548c\u7f51\u7edc\u7684\u5730\u533a\u5b8c\u6210\u73b0\u4ee3\u5316, \u65e0\u6cd5\u8ba9\u4f4e\u6536\u5165\u8005\u83b7\u5f97\u4f53\u9762\u7684\u5de5\u4f5c, \u4e5f\u65e0\u6cd5\u8ba9\u6bcf\u5929\u4e3a\u751f\u5b58\u5954\u6ce2\u7684\u4eba\u62e5\u6709\u95f2\u6687. \u5b83\u53ef\u4ee5\u628a\u6e38\u620f\u964d\u5230\u4e8c\u4e09\u5341\u5143, \u5374\u65e0\u6cd5\u628a\u8fdb\u5165\u6e38\u620f\u6240\u9700\u8981\u7684\u6574\u4e2a\u4e16\u754c\u4e00\u8d77\u964d\u4ef7.<\/p>\n<p>&lt;\u5deb\u5e083&gt; \u8d85\u8fc7 6500 \u4e07\u4efd\u7684\u9500\u91cf, \u65e2\u8bc1\u660e\u4e86\u5b83\u7684\u6210\u529f, \u4e5f\u8ba9\u4eba\u770b\u5230\u8fd9\u79cd\u6210\u529f\u7684\u6781\u9650. \u8fd9\u4e2a\u6781\u9650\u5e76\u4e0d\u5b8c\u5168\u5c5e\u4e8e &lt;\u5deb\u5e083&gt;, \u4e5f\u4e0d\u5b8c\u5168\u5c5e\u4e8e CDPR, \u5b83\u5c5e\u4e8e\u6211\u4eec\u751f\u6d3b\u7684\u8fd9\u4e2a\u4e16\u754c.<\/p>\n<p>&lt;\u5deb\u5e083&gt; \u662f\u4e2a\u597d\u6e38\u620f, \u6211\u4eec\u7684\u4e16\u754c\u4e5f\u5e94\u8be5\u53d8\u5f97\u66f4\u597d.<\/p>\n<h2 id=\"can-kao-lian-jie\"><a class=\"zola-anchor\" href=\"#can-kao-lian-jie\" aria-label=\"Anchor link for: can-kao-lian-jie\">\u53c2\u8003\u94fe\u63a5<\/a><\/h2>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/necromanov.wordpress.com\/2021\/02\/26\/2077\/\">\u8d5b\u535a\u670b\u514b2077: \u5f53\u865a\u62df\u7684\u8d5b\u535a\u670b\u514b\u88ab\u771f\u5b9e\u7684\u8d5b\u535a\u670b\u514b\u78be\u8fc7<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.cdprojekt.com\/en\/media\/news\/the-witcher-3-wild-hunt-remastered-announced-songs-of-the-past-gets-first-look\/\">The Witcher 3: Wild Hunt \u2014 Remastered Announced, Songs of the Past Gets First Look<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.cdprojekt.com\/en\/media\/news\/the-cd-projekt-groups-wraps-up-2025\/\">The CD PROJEKT Group wraps up 2025<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.gamedeveloper.com\/business\/the-witcher-3-has-earned-almost-650-million-after-a-decade-on-shelves\">The Witcher 3 has earned almost $650 million after a decade on shelves<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.pocketgamer.biz\/newzoo-global-games-market-set-to-hit-1888bn-in-2025\/\">Newzoo: Global games market set to hit $188.8bn in 2025<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/partner.steamgames.com\/doc\/store\/localization\/languages\">Languages Supported on Steam (Steamworks Documentation)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/citizens-initiative.europa.eu\/stop-destroying-videogames_en\">Stop Destroying Videogames (European Citizens' Initiative)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.un.org\/zh\/about-us\/universal-declaration-of-human-rights\">\u4e16\u754c\u4eba\u6743\u5ba3\u8a00<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.ohchr.org\/zh\/instruments-mechanisms\/instruments\/convention-rights-child\">\u513f\u7ae5\u6743\u5229\u516c\u7ea6<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.gnu.org\/philosophy\/free-sw.html\">What is Free Software? - GNU Project<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.gamerevolution.com\/news\/12340-the-witcher-3-has-won-more-game-of-the-year-awards-than-any-other-game\">The Witcher 3 Has Won More Game of the Year Awards Than Any Other Game<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.kickstarter.com\/projects\/goonboard\/the-witcher\">The Witcher: Old World by Go on Board (Kickstarter)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.cdprojekt.com\/en\/media\/news\/play-geralt-rivia-soulcalibur-vi\/\">Play as Geralt of Rivia in SOULCALIBUR VI<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.gamesradar.com\/games\/diablo\/blizzard-and-cd-projekt-red-team-up-for-diablo-4-geralt-skin-and-the-witcher-3-on-battle-net\/\">Blizzard and CD Projekt Red team up for Diablo 4 Geralt skin<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.nintendolife.com\/guides\/every-nintendo-switch-2-game-key-card-release\">Every Nintendo Switch 2 Game-Key Card Release<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.openttd.org\/\">OpenTTD<\/a> \/ <a rel=\"external\" href=\"https:\/\/www.freeciv.org\/\">Freeciv<\/a> \/ <a rel=\"external\" href=\"https:\/\/godotengine.org\/\">Godot Engine<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/The_Witcher_3:_Wild_Hunt\">The Witcher 3: Wild Hunt - Wikipedia<\/a><\/li>\n<\/ul>\n"},{"title":"\u662d\u548c\u63a7\u80a1\u4e0e\u4e00\u65e5\u5143\u80a1\u4ef7","published":"2026-08-22T03:27:43+09:00","updated":"2026-08-22T03:27:43+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/showa-holdings-and-the-one-yen-share-price\/"}},"id":"https:\/\/memwey.github.io\/posts\/showa-holdings-and-the-one-yen-share-price\/","content":"<p>\u662d\u548c\u63a7\u80a1, 1937 \u5e74\u8bbe\u7acb\u7684\u6a61\u80f6\u516c\u53f8, 1952 \u5e74\u4e0a\u5e02, \u540e\u6765\u6539\u7ec4\u4e3a\u7eaf\u6301\u80a1\u516c\u53f8, \u65d7\u4e0b\u7ecf\u8425\u8f6f\u5f0f\u7f51\u7403\u7403, \u548c\u679c\u5b50\u548c\u7f51\u7403\u7528\u54c1, \u603b\u90e8\u5728\u5343\u53f6\u53bf\u67cf\u5e02. \u4e1c\u4eac\u8bc1\u5238\u4ea4\u6613\u6240\u5df2\u7ecf\u51b3\u5b9a\u4e8e 2026 \u5e74 8 \u6708 25 \u65e5\u5c06\u5176\u9000\u5e02, \u80a1\u4ef7\u6b64\u524d\u8dcc\u81f3 1 \u65e5\u5143, \u4e3a\u65e5\u5143\u7684\u6700\u5c0f\u5355\u4f4d.<\/p>\n<p>\u4e8b\u60c5\u8d77\u4e8e\u5176\u4e0b\u5c5e\u516c\u53f8\u5728\u6cf0\u56fd\u7684\u4e00\u7b14\u6295\u8d44. 2015 \u5e74\u8d77, J Trust \u901a\u8fc7\u65b0\u52a0\u5761\u5b50\u516c\u53f8\u5411\u6cf0\u56fd\u4e0a\u5e02\u516c\u53f8 Group Lease \u6295\u5165\u903e 1.8 \u4ebf\u7f8e\u5143. 2017 \u5e74, \u6cf0\u56fd\u8bc1\u5238\u4ea4\u6613\u59d4\u5458\u4f1a\u6307\u63a7\u65f6\u4efb\u9996\u5e2d\u6267\u884c\u5b98\u6b64\u4e0b\u76ca\u53f8\u901a\u8fc7\u5173\u8054\u4ea4\u6613\u4f2a\u9020\u8d26\u76ee\u5e76\u63d0\u51fa\u5211\u4e8b\u544a\u53d1, \u6b64\u4e0b\u76ca\u53f8\u56e0\u6b64\u53bb\u804c. J Trust \u6b64\u540e\u5c31\u6295\u8d44\u635f\u5931\u7ee7\u7eed\u8ffd\u507f.<\/p>\n<p>Group Lease \u7684\u4e0a\u5c42\u80a1\u4e1c\u4e3a Wedge Holdings, Wedge Holdings \u7684\u4e0a\u5c42\u80a1\u4e1c\u4e3a\u662d\u548c\u63a7\u80a1, \u662d\u548c\u63a7\u80a1\u7684\u6bcd\u516c\u53f8\u5219\u4e3a\u82f1\u5c5e\u7ef4\u5c14\u4eac\u7fa4\u5c9b\u6ce8\u518c\u7684 APF, \u6574\u6761\u96c6\u56e2\u957f\u671f\u7531\u6b64\u4e0b\u76ca\u53f8\u53ca\u5176\u5f1f\u6b64\u4e0b\u9f99\u77e2\u638c\u63e1\u7ecf\u8425\u6743. J Trust \u5728\u591a\u4e2a\u6cd5\u57df\u8ffd\u67e5\u8d44\u4ea7, \u4e89\u593a\u4e5f\u6cbf\u8fd9\u6761\u6301\u80a1\u5173\u7cfb\u5ef6\u4f38\u81f3\u662d\u548c\u63a7\u80a1.<\/p>\n<p>2018 \u5e74, \u82f1\u5c5e\u7ef4\u5c14\u4eac\u7fa4\u5c9b\u6cd5\u9662\u5e94 J Trust \u7533\u8bf7\u5bf9 APF \u6307\u5b9a\u63a5\u7ba1\u4eba, \u63a5\u7ba1\u4eba\u501f APF \u7684\u6301\u80a1\u5c06\u53cd\u6b64\u4e0b\u6d3e\u8463\u4e8b\u9001\u5165\u662d\u548c\u63a7\u80a1\u8463\u4e8b\u4f1a, \u6301\u7eed\u4e0e\u6b64\u4e0b\u6d3e\u4e89\u593a\u7ecf\u8425\u6743. 2026 \u5e74 6 \u6708 29 \u65e5\u7684\u5b9a\u65f6\u80a1\u4e1c\u5927\u4f1a\u4e0a, \u6b64\u4e0b\u9f99\u77e2\u672a\u80fd\u5f53\u9009\u8463\u4e8b. \u4f46\u5728\u80a1\u4e1c\u5927\u4f1a\u4e4b\u524d, \u516c\u53f8\u4e8e 6 \u6708 25 \u65e5\u516c\u544a, \u56e0\u5411\u5408\u5e76\u5b50\u516c\u53f8\u501f\u6b3e, \u5df2\u5c06\u6240\u6301\u5b50\u516c\u53f8\u80a1\u7968\u63d0\u4f9b\u62c5\u4fdd; 26 \u65e5\u53c8\u6536\u5230\u62c5\u4fdd\u6743\u884c\u4f7f\u901a\u77e5, \u516d\u5bb6\u4e3b\u8981\u5b50\u516c\u53f8\u968f\u5373\u8131\u79bb\u5408\u5e76\u8303\u56f4, \u5176\u4e2d\u5927\u90e8\u8f6c\u7531 Wedge Holdings \u6301\u6709.<\/p>\n<p>\u80a1\u4e1c\u5927\u4f1a\u540e, \u65b0\u4efb\u8463\u4e8b\u51c6\u5907\u53ec\u5f00\u8463\u4e8b\u4f1a, \u4f46\u8d1f\u8d23\u76d1\u7763\u7ecf\u8425\u7684\u4e09\u540d\u793e\u5916\u8463\u4e8b\u5168\u90e8\u7f3a\u5e2d, \u5176\u4e2d\u5305\u62ec\u65e5\u672c\u524d\u9632\u536b\u5927\u81e3\u4e45\u95f4\u7ae0\u751f. \u8463\u4e8b\u4f1a\u56e0\u4eba\u6570\u4e0d\u8db3\u800c\u65e0\u6cd5\u53ec\u5f00, \u4ee3\u8868\u4eba\u4e5f\u672a\u80fd\u9009\u51fa. \u516c\u53f8\u968f\u540e\u62ab\u9732, \u5b9e\u5370, \u4f1a\u8ba1\u8d26\u7c3f, \u5b58\u6298\u53ca\u80a1\u4e1c\u540d\u7c3f\u5747\u672a\u5b8c\u6210\u4ea4\u63a5, \u67cf\u5e02\u603b\u90e8\u4e5f\u5df2\u65e0\u4eba\u529e\u516c, \u516c\u53f8\u65e0\u6cd5\u6b63\u5e38\u5bf9\u5916\u884c\u4f7f\u804c\u6743.<\/p>\n<p>7 \u6708 24 \u65e5, \u4e1c\u4eac\u8bc1\u5238\u4ea4\u6613\u6240\u8ba4\u5b9a\u516c\u53f8\u7684\u5185\u90e8\u7ba1\u7406\u5df2\u65e0\u6062\u590d\u53ef\u80fd, \u51b3\u5b9a\u4e8e 8 \u6708 25 \u65e5\u5c06\u5176\u9000\u5e02. \u5931\u53bb\u4e3b\u8981\u4e1a\u52a1, \u4ee3\u8868\u4eba\u548c\u4e0a\u5e02\u8d44\u683c\u540e, \u662d\u548c\u63a7\u80a1\u7684\u80a1\u4ef7\u8dcc\u81f3 1 \u65e5\u5143.<\/p>\n<p>\u4ece\u7ed3\u679c\u770b, \u8fd9\u76f8\u5f53\u4e8e\u4e00\u6b21\u8d44\u4ea7\u8f6c\u79fb. \u6574\u4e2a\u8fc7\u7a0b\u90fd\u6709\u516c\u53f8\u51b3\u7b56\u548c\u516c\u544a\u62ab\u9732, \u5374\u5728\u6570\u65e5\u5185\u4f7f\u65b0\u4efb\u8463\u4e8b\u63a5\u624b\u4e00\u5bb6\u6ca1\u6709\u4e3b\u8981\u4e1a\u52a1, \u6ca1\u6709\u4ee3\u8868\u4eba, \u4e5f\u65e0\u6cd5\u6b63\u5e38\u8fd0\u4f5c\u7684\u4e0a\u5e02\u516c\u53f8.<\/p>\n<h2 id=\"can-kao-zi-liao\"><a class=\"zola-anchor\" href=\"#can-kao-zi-liao\" aria-label=\"Anchor link for: can-kao-zi-liao\">\u53c2\u8003\u8d44\u6599<\/a><\/h2>\n<ul>\n<li><a rel=\"external\" href=\"http:\/\/www.showa-holdings.co.jp\/ir\/irnews\/sh20260625.html\">\u662d\u548c\u30db\u30fc\u30eb\u30c7\u30a3\u30f3\u30b0\u30b9: \u9023\u7d50\u5b50\u4f1a\u793e\u304b\u3089\u306e\u501f\u5165\u306b\u4f34\u3046\u9023\u7d50\u5b50\u4f1a\u793e\u306b\u5bfe\u3059\u308b\u5b50\u4f1a\u793e\u682a\u5f0f\u306e\u62c5\u4fdd\u63d0\u4f9b\u306b\u95a2\u3059\u308b\u304a\u77e5\u3089\u305b (2026\/06\/25)<\/a><\/li>\n<li><a rel=\"external\" href=\"http:\/\/www.showa-holdings.co.jp\/ir\/irnews\/sh20260626.html\">\u662d\u548c\u30db\u30fc\u30eb\u30c7\u30a3\u30f3\u30b0\u30b9: \u9023\u7d50\u5b50\u4f1a\u793e\u304b\u3089\u306e\u62c5\u4fdd\u6a29\u884c\u4f7f\u901a\u77e5\u66f8\u306e\u53d7\u9818\u3001\u53ca\u3073\u9023\u7d50\u5b50\u4f1a\u793e\u306e\u7570\u52d5\u306b\u95a2\u3059\u308b\u304a\u77e5\u3089\u305b (2026\/06\/26)<\/a><\/li>\n<li><a rel=\"external\" href=\"http:\/\/www.showa-holdings.co.jp\/ir\/irnews\/sh20260622.html\">\u662d\u548c\u30db\u30fc\u30eb\u30c7\u30a3\u30f3\u30b0\u30b9: \u4ee3\u8868\u53d6\u7de0\u5f79\u306e\u7570\u52d5\u306b\u95a2\u3059\u308b\u304a\u77e5\u3089\u305b (2026\/06\/22)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.nikkei.com\/nkd\/disclosure\/tdnr\/20260630584646\/\">\u662d\u548c\u30db\u30fc\u30eb\u30c7\u30a3\u30f3\u30b0\u30b9[5103]: \u7b2c125\u56de\u5b9a\u6642\u682a\u4e3b\u7dcf\u4f1a\u306b\u304a\u3051\u308b\u4ee3\u8868\u53d6\u7de0\u5f79\u306e\u7570\u52d5\uff08\u9000\u4efb\uff09\u3068\u53d6\u7de0\u5f79\u9078\u4efb\u7d50\u679c\u306b\u95a2\u3059\u308b\u304a\u77e5\u3089\u305b (2026\/06\/30)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/finance.biggo.jp\/news\/jpx_tdnet_140120260708589710\">\u662d\u548c\u30db\u30fc\u30eb\u30c7\u30a3\u30f3\u30b0\u30b9[5103]: \u4ee3\u8868\u53d6\u7de0\u5f79\u9078\u4efb\u304c\u51fa\u6765\u3066\u3044\u306a\u3044\u3053\u3068\u3001\u7d4c\u55b6\u306e\u73fe\u6cc1\u3068\u4eca\u5f8c\u306e\u65b9\u91dd (2026\/07\/08)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/finance.biggo.jp\/news\/jpx_tdnet_140120260717596231\">\u662d\u548c\u30db\u30fc\u30eb\u30c7\u30a3\u30f3\u30b0\u30b9[5103]: \u66f4\u751f\u624b\u7d9a\u958b\u59cb\u306e\u7533\u7acb\u3066\u306b\u95a2\u3059\u308b\u304a\u77e5\u3089\u305b (2026\/07\/17)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.jpx.co.jp\/news\/1023\/20260724-13.html\">\u65e5\u672c\u53d6\u5f15\u6240\u30b0\u30eb\u30fc\u30d7: \u4e0a\u5834\u5ec3\u6b62\u7b49\u306e\u6c7a\u5b9a - \u662d\u548c\u30db\u30fc\u30eb\u30c7\u30a3\u30f3\u30b0\u30b9\uff08\u682a\uff09 (2026\/07\/24)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.tdb.co.jp\/report\/bankruptcy\/flash\/5249\/\">\u5e1d\u56fd\u30c7\u30fc\u30bf\u30d0\u30f3\u30af \u5012\u7523\u901f\u5831: \u662d\u548c\u30db\u30fc\u30eb\u30c7\u30a3\u30f3\u30b0\u30b9\u682a\u5f0f\u4f1a\u793e<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.tsr-net.co.jp\/news\/tsr\/detail\/1203066_1521.html\">\u6771\u4eac\u5546\u5de5\u30ea\u30b5\u30fc\u30c1 TSR\u901f\u5831: \u662d\u548c\u30db\u30fc\u30eb\u30c7\u30a3\u30f3\u30b0\u30b9\uff08\u682a\uff09<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.tokyo-np.co.jp\/article\/502678\">\u6771\u4eac\u65b0\u805e: \u4ee3\u8868\u4e0d\u5728\u306e\u662d\u548c\u30db\u30fc\u30eb\u30c7\u30a3\u30f3\u30b0\u30b9\u306b\u4fdd\u5168\u7ba1\u7406\u547d\u4ee4 \u8a34\u8a1f\u304c\u9577\u671f\u5316\u3001\u6295\u8cc7\u4f1a\u793e\u304c\u4f1a\u793e\u66f4\u751f\u3092\u7533\u3057\u7acb\u3066<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.nikkei.com\/article\/DGXZQOUB248HI0U6A720C2000000\/\">\u65e5\u672c\u7d4c\u6e08\u65b0\u805e: \u662d\u548cHD\u30018\u670825\u65e5\u306b\u6771\u8a3c\u4e0a\u5834\u5ec3\u6b62\u3078 \u5185\u90e8\u7ba1\u7406\u4f53\u5236\u306e\u6539\u5584\u898b\u8fbc\u3081\u305a<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/topics.smt.docomo.ne.jp\/article\/npn\/nation\/npn-300416109\">\u5185\u5916\u30bf\u30a4\u30e0\u30b9: \u524d\u4ee3\u672a\u805e \u662d\u548cHD\u304c\u53d6\u7de0\u5f793\u540d\u6b20\u5e2d\u3067\u4ee3\u8868\u53d6\u7de0\u5f79\u9078\u5b9a\u3067\u304d\u305a\u5b9f\u5370\u30fb\u5e33\u7c3f\u30fb\u901a\u5e33\u304c\u884c\u65b9\u4e0d\u660e\u306e\u7570\u5e38\u4e8b\u614b<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/topics.smt.docomo.ne.jp\/article\/npn\/nation\/npn-300420075\">\u5185\u5916\u30bf\u30a4\u30e0\u30b9: \u662d\u548cHD\u306b\u5b50\u4f1a\u793e\u682a\u5f0f\u51e6\u5206\u7981\u6b62\u306e\u4eee\u51e6\u5206\u547d\u4ee4 \u73fe\u7d4c\u55b6\u9663\u304c\u524d\u4ee3\u8868\u306e\u52d5\u304d\u306b\u53cd\u6483<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/kabutan.jp\/stock\/kabuka?code=5103\">\u682a\u63a2: \u662d\u548c\u30db\u30fc\u30eb\u30c7\u30a3\u30f3\u30b0\u30b9\u30105103\u3011\u65e5\u3005\u682a\u4fa1<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.sec.or.th\/EN\/Pages\/News_Detail.aspx?SECID=6814\">Thai SEC: SEC files a criminal complaint against GL executive for fraud, misappropriation and falsification of accounts (2017\/10\/16)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.bangkokpost.com\/thailand\/general\/1343327\/trading-in-group-lease-shares-halted-ceo-charged\">Bangkok Post: Trading in Group Lease shares halted, CEO charged<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.elitigation.sg\/gd\/s\/2018_SGCA_27\">Singapore Court of Appeal: Mitsuji Konoshita v Jtrust Asia Pte Ltd [2018] SGCA 27<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/f.irbank.net\/pdf\/20200212\/140120200212462873.pdf\">J Trust: \u30b7\u30f3\u30ac\u30dd\u30fc\u30eb\u306b\u304a\u3051\u308bJTrust Asia Pte.Ltd.\u306b\u3088\u308bGroup Lease\u95a2\u9023\u8a34\u8a1f\u306b\u3064\u3044\u3066 (2020\/02\/12)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.jt-corp.co.jp\/jp\/2020\/10\/06\/26059\/?t=jn\">J Trust: \uff08\u958b\u793a\u4e8b\u9805\u306e\u7d4c\u904e\uff09\u5f53\u793e\u306eGroup Lease PCL\u306b\u5bfe\u3059\u308b\u73fe\u72b6\u306e\u8a8d\u8b58\u306b\u3064\u3044\u3066 (2020\/10\/06)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.jt-corp.co.jp\/jp\/2021\/08\/05\/27225\/?t=jn\">J Trust: \uff08\u958b\u793a\u4e8b\u9805\u306e\u7d4c\u904e\uff09\u5f53\u793e\u306eGroup Lease PCL\u306b\u5bfe\u3059\u308b\u73fe\u72b6\u306e\u8a8d\u8b58\u306b\u3064\u3044\u3066 (2021\/08\/05)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/prtimes.jp\/main\/html\/rd\/p\/000000039.000008352.html\">\u30a6\u30a7\u30c3\u30b8\u30db\u30fc\u30eb\u30c7\u30a3\u30f3\u30b0\u30b9: \u30bf\u30a4\u7279\u5225\u635c\u67fb\u5c40\u304c\u3001J\u30c8\u30e9\u30b9\u30c8\u30a2\u30b8\u30a2\u306b\u3088\u308bGroup Lease PCL\u304a\u3088\u3073\u65e7\u53d6\u7de0\u5f79\u306b\u5bfe\u3059\u308b\u5211\u4e8b\u544a\u767a\u3092\u68c4\u5374 (2022)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/finance.biggo.jp\/news\/jpx_tdnet_140120260814521236\">\u30a6\u30a7\u30c3\u30b8\u30db\u30fc\u30eb\u30c7\u30a3\u30f3\u30b0\u30b9: \u4ee4\u548c8\u5e749\u6708\u671f \u7b2c3\u56db\u534a\u671f\u6c7a\u7b97\u77ed\u4fe1 (2026\/08\/14)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/ja.wikipedia.org\/wiki\/%E6%98%AD%E5%92%8C%E3%83%9B%E3%83%BC%E3%83%AB%E3%83%87%E3%82%A3%E3%83%B3%E3%82%B0%E3%82%B9\">\u662d\u548c\u30db\u30fc\u30eb\u30c7\u30a3\u30f3\u30b0\u30b9 - Wikipedia<\/a><\/li>\n<\/ul>\n"},{"title":"\u76f8\u4e50\u603b\u4e09\u4e0e\u5e74\u8d21\u51cf\u534a","published":"2026-08-21T16:30:22+09:00","updated":"2026-08-21T16:30:22+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/sagara-sozo-and-the-halved-land-tax\/"}},"id":"https:\/\/memwey.github.io\/posts\/sagara-sozo-and-the-halved-land-tax\/","content":"<p>\u76f8\u4e50\u603b\u4e09, \u5012\u5e55\u6d3e\u6d6a\u4eba, 1867 \u5e74\u5949\u897f\u4e61\u9686\u76db\u6307\u793a, \u4ee5\u8428\u6469\u85e9\u6c5f\u6237\u85e9\u90b8\u4e3a\u636e\u70b9\u7ec4\u7ec7\u6d6a\u58eb, \u5728\u6c5f\u6237\u53ca\u5468\u8fb9\u4ece\u4e8b\u7eb5\u706b\u62a2\u52ab\u7b49\u9a9a\u4e71\u6d3b\u52a8, \u610f\u5728\u6311\u8845\u5e55\u5e9c\u6fc0\u5316\u51b2\u7a81. \u6700\u7ec8\u5e55\u5e9c\u4e00\u65b9\u88ad\u51fb\u5e76\u711a\u6bc1\u4e86\u8428\u6469\u85e9\u90b8\u4f5c\u4e3a\u62a5\u590d, \u6210\u4e3a\u9e1f\u7fbd\u4f0f\u89c1\u5f00\u6218\u7684\u91cd\u8981\u5bfc\u706b\u7d22.<\/p>\n<p>\u9e1f\u7fbd\u4f0f\u89c1\u4e4b\u6218\u540e, \u76f8\u4e50\u603b\u4e09\u53c2\u4e0e\u7ec4\u5efa\u8d64\u62a5\u961f, \u5e76\u7387\u7b2c\u4e00\u756a\u961f\u4f5c\u4e3a\u5148\u950b\u6cbf\u4e1c\u5c71\u9053\u4e1c\u8fdb. \u4ed6\u5411\u65b0\u653f\u5e9c\u63d0\u51fa\u5bf9\u65e7\u5e55\u5e9c\u9886\u5e74\u8d21\u51cf\u534a\u7684\u653f\u7b56\u5e76\u5f97\u5230\u91c7\u7eb3, \u8d64\u62a5\u961f\u9042\u4ee5\u6b64\u4e89\u53d6\u6cbf\u9014\u519c\u6c11\u652f\u6301. \u7136\u800c\u5012\u5e55\u6d3e\u7684\u65b0\u653f\u5e9c\u5f88\u5feb\u53d1\u73b0, \u4e1c\u5f81\u6bd4\u9884\u60f3\u4e2d\u987a\u5229, \u83b7\u53d6\u519c\u6c11\u652f\u6301\u7684\u5fc5\u8981\u6027\u5927\u5927\u964d\u4f4e, \u5728\u8d22\u653f\u4e0a\u5e74\u8d21\u51cf\u534a\u4e5f\u96be\u4ee5\u5151\u73b0, \u9042\u64a4\u9500\u653f\u7b56\u5e76\u53ec\u56de\u8d64\u62a5\u961f. \u76f8\u4e50\u7684\u8d64\u62a5\u961f\u7b2c\u4e00\u756a\u961f\u4ecd\u7ee7\u7eed\u4e1c\u8fdb, \u6700\u7ec8\u88ab\u8ba4\u5b9a\u4e3a\u4f2a\u5b98\u519b. 1868 \u5e74 3 \u6708, \u76f8\u4e50\u7b49\u516b\u540d\u8d64\u62a5\u961f\u6210\u5458\u5728\u4e0b\u8bf9\u8bbf\u88ab\u5904\u5211, \u9996\u7ea7\u793a\u4f17.<\/p>\n<p>1928 \u5e74, \u5728\u540e\u4eba\u6570\u5341\u5e74\u5954\u8d70\u4e4b\u4e0b, \u76f8\u4e50\u603b\u4e09\u88ab\u8ffd\u8d60\u6b63\u4e94\u4f4d, \u6b21\u5e74\u5408\u7940\u9756\u56fd\u795e\u793e.<\/p>\n"},{"title":"\u52a0\u5165\u521b\u4e1a\u516c\u53f8\u4e4b\u524d, \u5de5\u7a0b\u5e08\u80fd\u67e5\u4e9b\u4ec0\u4e48","published":"2026-07-30T13:57:17+09:00","updated":"2026-07-30T13:57:17+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/startup-due-diligence-for-engineers\/"}},"id":"https:\/\/memwey.github.io\/posts\/startup-due-diligence-for-engineers\/","content":"<p>\u627e\u5de5\u4f5c\u7684\u65f6\u5019, \u5173\u4e8e\u4e00\u5bb6\u521b\u4e1a\u516c\u53f8\u80fd\u67e5\u5230\u7684\u4e1c\u897f\u5176\u5b9e\u4e0d\u5c11: \u878d\u4e86\u591a\u5c11\u94b1, \u6295\u8d44\u4eba\u662f\u8c01, \u521b\u59cb\u4eba\u4ece\u54ea\u91cc\u6bd5\u4e1a, \u53c8\u5728\u91c7\u8bbf\u91cc\u8bb2\u4e86\u4e00\u4e2a\u591a\u5927\u7684\u5e02\u573a.<\/p>\n<p>\u4f46\u771f\u6b63\u60f3\u77e5\u9053\u7684\u662f\u53e6\u5916\u51e0\u4ef6\u4e8b:<\/p>\n<ul>\n<li>\u8fdb\u53bb\u4ee5\u540e\u8981\u5199\u4ec0\u4e48\u7cfb\u7edf, \u9700\u8981\u8865\u591a\u5c11\u9886\u57df\u77e5\u8bc6<\/li>\n<li>\u62db\u8058\u9875\u9762\u4e0a\u7684\u6280\u672f\u6808, \u662f\u7ebf\u4e0a\u5df2\u7ecf\u5728\u7528, \u8fd8\u662f\u516c\u53f8\u5e0c\u671b\u4ee5\u540e\u80fd\u7528<\/li>\n<li>\u516c\u53f8\u8bf4\u81ea\u5df1\u5728\u505a\u7684\u4e1a\u52a1, \u6709\u6ca1\u6709\u53ef\u9a8c\u8bc1\u7684\u75d5\u8ff9; \u5c24\u5176\u5728\u91d1\u878d\u9886\u57df, \u8be5\u6709\u7684\u724c\u7167\u5728\u76d1\u7ba1\u767b\u8bb0\u91cc\u67e5\u5f97\u5230\u5417<\/li>\n<\/ul>\n<p>\u521b\u4e1a\u516c\u53f8\u6570\u636e\u5e93\u64c5\u957f\u628a\u878d\u8d44\u8f6e\u6b21\u6392\u6210\u4e00\u5f20\u8868, \u5374\u4e0d\u4f1a\u544a\u8bc9\u4f60\u4e00\u4e2a <code>Kubernetes preferred<\/code> \u80fd\u4e0d\u80fd\u8bc1\u660e\u751f\u4ea7\u73af\u5883\u91cc\u6709 Kubernetes.<\/p>\n<p>\u4e8e\u662f\u6512\u51fa\u4e86 <a rel=\"external\" href=\"https:\/\/github.com\/memwey\/startup-due-diligence\">startup-due-diligence<\/a> \u8fd9\u4e2a\u4ed3\u5e93: \u622a\u81f3 2026-07-30, \u6536\u5f55 12 \u5bb6\u516c\u53f8, \u8986\u76d6\u65e5\u672c, \u5317\u7f8e, \u6fb3\u5927\u5229\u4e9a\u548c\u8de8\u5883\u5e02\u573a, \u4e2d\u82f1\u53cc\u8bed, \u6bcf\u5bb6\u4e00\u4efd\u5e26\u6765\u6e90\u7684\u6863\u6848. \u5b83\u4e0d\u5224\u65ad\u4e00\u5bb6\u516c\u53f8\u503c\u4e0d\u503c\u5f97\u6295, \u53ea\u6574\u7406\u51c6\u5907\u52a0\u5165\u7684\u5de5\u7a0b\u5e08\u9700\u8981\u7684\u516c\u5f00\u8bc1\u636e.<\/p>\n<h2 id=\"rong-zi-biao-zhi-wai\"><a class=\"zola-anchor\" href=\"#rong-zi-biao-zhi-wai\" aria-label=\"Anchor link for: rong-zi-biao-zhi-wai\">\u878d\u8d44\u8868\u4e4b\u5916<\/a><\/h2>\n<p>\u6295\u8d44\u4eba\u548c\u5de5\u7a0b\u5e08\u4f1a\u5173\u5fc3\u4e00\u4e9b\u76f8\u540c\u7684\u4e1c\u897f: \u6709\u6ca1\u6709\u6536\u5165, \u94b1\u8fd8\u80fd\u70e7\u591a\u4e45, \u4ea7\u54c1\u662f\u4e0d\u662f\u771f\u7684\u6709\u4eba\u7528. \u8fd9\u4e9b\u6700\u540e\u90fd\u4f1a\u53d8\u6210\u5de5\u8d44\u80fd\u4e0d\u80fd\u6309\u65f6\u53d1\u51fa\u6765.<\/p>\n<p>\u4f46\u5de5\u7a0b\u5e08\u8fd8\u8981\u9762\u5bf9\u4e1a\u52a1\u65bd\u52a0\u5728\u7cfb\u7edf\u4e0a\u7684\u7ea6\u675f. \u7269\u6d41 SaaS \u4e0d\u53ea\u662f\u666e\u901a\u7684\u589e\u5220\u6539\u67e5, \u540e\u9762\u8fd8\u6709\u62a5\u5173, \u8d27\u4ee3, \u8239\u671f, \u5355\u636e\u548c\u8de8\u56fd\u534f\u4f5c; \u652f\u4ed8\u7cfb\u7edf\u7684\u6280\u672f\u6808\u5373\u4f7f\u770b\u8d77\u6765\u5e73\u5e73\u65e0\u5947, \u80cc\u540e\u4e5f\u53ef\u80fd\u662f\u591a\u65b9\u6e05\u7b97, \u5546\u6237\u8d44\u91d1, PCI DSS \u548c\u4e00\u5806\u6c38\u8fdc\u4e0d\u80fd\u91cd\u590d\u6267\u884c\u7684\u72b6\u6001\u673a, \u800c\u4e1a\u52a1\u80fd\u4e0d\u80fd\u4e0a\u7ebf, \u8fd8\u53d6\u51b3\u4e8e\u7a76\u7adf\u7531\u54ea\u4e2a\u6cd5\u5f8b\u5b9e\u4f53\u6216\u6301\u724c\u5408\u4f5c\u65b9\u627f\u62c5\u53d7\u76d1\u7ba1\u7684\u73af\u8282.<\/p>\n<p>\u5b98\u7f51\u901a\u5e38\u4f1a\u8bf4\u4ea7\u54c1\u89e3\u51b3\u4e86\u4ec0\u4e48\u95ee\u9898, \u5f88\u5c11\u8bf4\u4e3a\u4e86\u89e3\u51b3\u5b83, \u5de5\u7a0b\u5e08\u6bcf\u5929\u8981\u548c\u54ea\u4e9b\u7ea6\u675f\u6253\u67b6. \u8fd9\u90e8\u5206\u4fe1\u606f\u6563\u843d\u5728\u4ea7\u54c1\u6587\u6863, API \u53c2\u8003, \u62db\u8058\u9875\u9762, \u6280\u672f\u6f14\u8bb2, \u6cd5\u5f8b\u6761\u6b3e\u548c\u76d1\u7ba1\u767b\u8bb0\u91cc. \u5355\u72ec\u770b\u6bcf\u4e00\u4efd\u90fd\u4e0d\u50cf\u7b54\u6848, \u62fc\u8d77\u6765\u624d\u6162\u6162\u50cf.<\/p>\n<h2 id=\"zhe-lei-dang-an-ben-lai-jiu-gai-rang-ai-zuo\"><a class=\"zola-anchor\" href=\"#zhe-lei-dang-an-ben-lai-jiu-gai-rang-ai-zuo\" aria-label=\"Anchor link for: zhe-lei-dang-an-ben-lai-jiu-gai-rang-ai-zuo\">\u8fd9\u7c7b\u6863\u6848\u672c\u6765\u5c31\u8be5\u8ba9 AI \u505a<\/a><\/h2>\n<p>12 \u5bb6\u516c\u53f8\u7684\u6863\u6848, \u4e3b\u8981\u5de5\u4f5c\u662f\u6a21\u578b\u5b8c\u6210\u7684, \u800c\u8fd9\u7c7b\u6d3b\u672c\u6765\u5c31\u8be5\u8fd9\u4e48\u5206: \u9762\u5bbd, \u6bcf\u4e00\u5904\u90fd\u4e0d\u6df1, \u9ad8\u5ea6\u91cd\u590d, \u8fd8\u8981\u8de8\u8bed\u8a00\u5bf9\u9f50\u683c\u5f0f. \u627e\u9875\u9762, \u7ffb\u8bd1\u6750\u6599, \u62bd\u53d6\u6570\u5b57, \u6bd4\u8f83\u7248\u672c, \u4ece sitemap \u91cc\u5b9a\u4f4d\u4ea7\u54c1\u6587\u6863 - \u6a21\u578b\u6bd4\u4eba\u5feb\u5f97\u591a, \u4e5f\u4e0d\u4f1a\u56e0\u4e3a\u91cd\u590d\u548c\u65e0\u804a\u4e3b\u52a8\u7f62\u5de5. \u81f3\u4e8e\u4f1a\u4e0d\u4f1a\u7528\u53e6\u4e00\u79cd\u65b9\u5f0f\u7cca\u5f04, \u662f\u4e0b\u4e00\u56de\u4e8b.<\/p>\n<p>\u4e0d\u80fd\u4ea4\u51fa\u53bb\u7684\u662f\u53e6\u4e00\u4ef6\u4e8b: \u5b83\u540c\u6837\u64c5\u957f\u628a\u7f3a\u5931\u7684\u8fde\u63a5\u8865\u6210\u4e00\u53e5\u8bfb\u8d77\u6765\u5408\u7406\u7684\u8bdd.<\/p>\n<ul>\n<li>\u65e7\u54c1\u724c\u548c\u65b0\u54c1\u724c\u5171\u4eab\u521b\u59cb\u4eba\u4e0e\u57df\u540d\u65f6, \u5b83\u503e\u5411\u4e8e\u5199\"\u516c\u53f8\u5b8c\u6210\u4e86\u66f4\u540d\"<\/li>\n<li>\u804c\u4f4d\u63cf\u8ff0\u91cc\u51fa\u73b0 Kubernetes, \u5b83\u503e\u5411\u4e8e\u628a Kubernetes \u586b\u8fdb\u6280\u672f\u6808<\/li>\n<li>\u4e09\u5bb6\u5a92\u4f53\u8f6c\u8f7d\u540c\u4e00\u4efd\u65b0\u95fb\u7a3f, \u5b83\u53ef\u80fd\u7b97\u6210\u4e09\u4efd\u76f8\u4e92\u72ec\u7acb\u7684\u8bc1\u636e<\/li>\n<\/ul>\n<p>\u8fd9\u4e9b\u9519\u8bef\u901a\u5e38\u4e0d\u662f\u4e8b\u5b9e\u7f16\u9519\u4e86, \u800c\u662f<strong>\u8bc1\u636e\u53ea\u8d70\u5230 A, \u7ed3\u8bba\u591a\u8d70\u4e86\u4e00\u6b65\u5230 B<\/strong>. \u800c\u4e14\u540c\u4e00\u4e2a\u95ee\u9898\u95ee\u4e24\u6b21, \u591a\u8d70\u7684\u90a3\u4e00\u6b65\u8fd8\u53ef\u80fd\u4e0d\u4e00\u6837.<\/p>\n<p>\u6240\u4ee5\u8fd9\u4e2a\u9879\u76ee\u771f\u6b63\u9700\u8981\u7ef4\u62a4\u7684\u4e0d\u662f prompt, \u800c\u662f\u4e00\u4efd\u534f\u8bae: \u4ec0\u4e48\u6765\u6e90\u80fd\u8bc1\u660e\u4ec0\u4e48, \u65e5\u671f\u6307\u7684\u662f\u53d1\u5e03\u65e5\u8fd8\u662f\u7edf\u8ba1\u65e5, \u62db\u8058\u8981\u6c42\u80fd\u652f\u6301\u5230\u54ea\u4e00\u5c42, \u6765\u6e90\u51b2\u7a81\u8be5\u4fdd\u7559\u8fd8\u662f\u6dd8\u6c70. \u534f\u8bae\u65e2\u662f\u7ed9\u4eba\u590d\u6838\u7684\u89c4\u8303, \u4e5f\u662f\u7ed9\u6a21\u578b\u5957\u4e0a\u7684\u7ea6\u675f.<\/p>\n<h2 id=\"zhong-dian-shi-fang-fa-ke-fu-he-bu-shi-dang-an-ben-shen\"><a class=\"zola-anchor\" href=\"#zhong-dian-shi-fang-fa-ke-fu-he-bu-shi-dang-an-ben-shen\" aria-label=\"Anchor link for: zhong-dian-shi-fang-fa-ke-fu-he-bu-shi-dang-an-ben-shen\">\u91cd\u70b9\u662f\u65b9\u6cd5\u53ef\u590d\u6838, \u4e0d\u662f\u6863\u6848\u672c\u8eab<\/a><\/h2>\n<p>\u6863\u6848\u4e00\u5b9a\u4f1a\u8fc7\u65f6. \u878d\u8d44\u6570\u5b57\u4f1a\u53d8, \u7f51\u7ad9\u4f1a\u6539\u7248, \u804c\u4f4d\u4f1a\u4e0b\u7ebf, \u534a\u5e74\u4e4b\u540e\u6bcf\u4e00\u9875\u90fd\u9700\u8981\u91cd\u505a. \u80fd\u7559\u4e0b\u6765\u7684\u662f<a rel=\"external\" href=\"https:\/\/github.com\/memwey\/startup-due-diligence\/blob\/main\/GUIDE.md\">\u90a3\u4efd\u534f\u8bae<\/a>, \u800c\u5b83\u7684\u9a8c\u6536\u6807\u51c6\u5f88\u76f4\u63a5: \u6362\u4e00\u4e2a\u4eba, \u6216\u8005\u6362\u4e00\u6b21\u5bf9\u8bdd, \u80fd\u4e0d\u80fd\u6cbf\u7740\u540c\u4e00\u5957\u89c4\u5219\u91cd\u8d70\u5173\u952e\u6b65\u9aa4, \u5e76\u6307\u51fa\u5206\u6b67\u53d1\u751f\u5728\u54ea\u4e00\u6b65.<\/p>\n<p>\u534f\u8bae\u672c\u8eab\u5199\u4e86\u4e0d\u5c11\u7ec6\u5219, \u4f46\u771f\u6b63\u5728\u8d77\u4f5c\u7528\u7684\u539f\u5219\u53ea\u6709\u4e09\u6761.<\/p>\n<p><strong>\u8be5\u770b\u4ec0\u4e48\u6765\u6e90, \u7531\u4e3b\u5f20\u7684\u7c7b\u578b\u51b3\u5b9a, \u4e0d\u7531\u6765\u6e90\u770b\u8d77\u6765\u6743\u4e0d\u6743\u5a01.<\/strong> \u4ea7\u54c1\u80fd\u529b\u770b\u5b98\u65b9\u6587\u6863\u548c API \u53c2\u8003, \u6280\u672f\u6808\u770b\u516c\u5f00\u8d44\u6e90\u6216\u62db\u8058\u4fe1\u606f, \u800c\u5408\u89c4\u8d44\u8d28\u53ea\u6709\u76d1\u7ba1\u673a\u6784\u7684\u767b\u8bb0\u7b97\u6570 - \u6bd4\u5982\u4e00\u5bb6\u8de8\u5883\u652f\u4ed8\u516c\u53f8\u5ba3\u79f0\u6301\u6709\u67d0\u4e2a\u724c\u7167, \u5728\u5bf9\u5e94\u7684\u76d1\u7ba1\u767b\u8bb0\u91cc\u5374\u67e5\u4e0d\u5230, \u90a3\u5c31\u8bda\u5b9e\u5730\u5199\"\u6ca1\u67e5\u5230\".<\/p>\n<p><strong>\u6bcf\u4e2a\u4e8b\u5b9e\u90fd\u8981\u5e26\u4e0a\u6709\u6548\u671f\u548c\u8bc1\u636e\u5f3a\u5ea6.<\/strong> \u65e5\u671f\u8d1f\u8d23\u6709\u6548\u671f, \"\u8986\u76d6 194 MW\"\u548c\"\u622a\u81f3 2026-07-27 \u8986\u76d6 194 MW\"\u662f\u4e24\u6761\u4e0d\u540c\u7684\u4fe1\u606f, \u524d\u8005\u534a\u5e74\u540e\u5c31\u662f\u9519\u7684; \u6807\u6ce8\u8d1f\u8d23\u5f3a\u5ea6, \u4ece\u62db\u8058\u4fe1\u606f\u63a8\u51fa\u6765\u7684\u6280\u672f\u6808\u5199\u6210\"\u6839\u636e\u62db\u8058\u4fe1\u606f\u63a8\u65ad\", \u8bfb\u8005\u53ef\u4ee5\u81ea\u5df1\u51b3\u5b9a\u63a5\u4e0d\u63a5\u53d7\u8fd9\u4e00\u6b65.<\/p>\n<p><strong>\u4e0d\u786e\u5b9a\u6027\u7559\u5728\u9875\u9762\u4e0a, \u4e0d\u8981\u987a\u624b\u6d88\u5316\u6389.<\/strong> \u4ee5 <a rel=\"external\" href=\"https:\/\/github.com\/memwey\/startup-due-diligence\/tree\/main\/companies\/shippio\">Shippio<\/a> \u4e3a\u4f8b, \u8d44\u672c\u6570\u5b57\u5728\u4e0d\u540c\u9875\u9762\u4e0a\u51fa\u73b0\u8fc7\u4e94\u4e2a\u7248\u672c, \u53e3\u5f84\u4e0d\u4e00, \u9875\u9762\u6ca1\u6709\u66f4\u65b0\u65e5\u671f, \u6570\u5b57\u4e5f\u4e0d\u6cbf\u65f6\u95f4\u5355\u8c03\u589e\u52a0. \u6700\u7701\u4e8b\u7684\u505a\u6cd5\u662f\u6311\u4e00\u4e2a\u770b\u8d77\u6765\u6700\u65b0\u7684\u586b\u8fdb\u8868\u683c, \u4f46\u90a3\u53ea\u662f\u628a\"\u6211\u4e0d\u77e5\u9053\"\u6362\u6210\u4e86\u4e00\u4e2a\u770b\u8d77\u6765\u5f88\u786e\u5b9a\u7684\u6570\u5b57. \u6240\u4ee5\u4e94\u4e2a\u7248\u672c\u5e76\u5217\u5199\u7740, \u8fde\"\u4e3a\u4ec0\u4e48\u73b0\u5728\u4e0d\u80fd\u76f4\u63a5\u6bd4\u8f83\"\u4e00\u8d77\u5199.<\/p>\n<p>\u4e09\u6761\u6307\u5411\u7684\u662f\u540c\u4e00\u4ef6\u4e8b: \u8ba9\u522b\u4eba\u80fd\u53cd\u9a73\u4f60. \u53ef\u590d\u6838\u4e0d\u8981\u6c42\u7ed3\u8bba\u4e00\u81f4, \u800c\u662f\u6bcf\u4e00\u6b65\u90fd\u80fd\u88ab\u5355\u72ec\u62ff\u51fa\u6765\u68c0\u67e5, \u4e5f\u80fd\u88ab\u5355\u72ec\u63a8\u7ffb\u4e00\u6b65, \u4e0d\u7528\u6574\u7bc7\u91cd\u505a.<\/p>\n<h2 id=\"zhao-pin-yao-qiu-bu-deng-yu-sheng-chan-huan-jing\"><a class=\"zola-anchor\" href=\"#zhao-pin-yao-qiu-bu-deng-yu-sheng-chan-huan-jing\" aria-label=\"Anchor link for: zhao-pin-yao-qiu-bu-deng-yu-sheng-chan-huan-jing\">\u62db\u8058\u8981\u6c42\u4e0d\u7b49\u4e8e\u751f\u4ea7\u73af\u5883<\/a><\/h2>\n<p>\u62db\u8058\u9875\u9762\u662f\u8fd9\u7c7b\u8c03\u7814\u91cc\u6700\u6709\u7528, \u4e5f\u6700\u5bb9\u6613\u88ab\u8bef\u7528\u7684\u6765\u6e90.<\/p>\n<p><a rel=\"external\" href=\"https:\/\/github.com\/memwey\/startup-due-diligence\/tree\/main\/companies\/tensor-energy\">Tensor Energy<\/a> \u662f\u4e2a\u6e05\u695a\u7684\u4f8b\u5b50. \u516c\u5f00\u6587\u6863\u80fd\u786e\u8ba4\u7684\u751f\u4ea7\u7cfb\u7edf\u5305\u62ec: AWS IoT Core \u4e0a\u7684\u7535\u6c60\u9065\u6d4b\u4e0e\u63a7\u5236, \u57fa\u4e8e TLS \u7684 MQTT, \u7528\u4e8e\u8d44\u4ea7\u4e0e\u9884\u6d4b\u6570\u636e\u7684 REST API, \u4ee5\u53ca\u56f4\u7ed5\u65e5\u672c\u7535\u529b\u5e02\u573a\u4ea4\u6613\u65f6\u70b9, \u81f3\u5c11\u6bcf 30 \u5206\u949f\u91cd\u7b97\u4e00\u6b21\u7684\u7535\u6c60\u4f18\u5316.<\/p>\n<p>\u5b83\u7684\u540e\u7aef\u804c\u4f4d\u8981\u6c42 Go \u7684\u751f\u4ea7\u7ecf\u9a8c, \u540c\u65f6\u628a GraphQL, Kubernetes, DevOps, AWS CDK \u5217\u4e3a\u4f18\u5148\u800c\u975e\u5fc5\u9700. \u5176\u4e2d AWS CDK \u548c IoT \u57fa\u7840\u8bbe\u65bd\u80fd\u5728\u516c\u5f00\u6587\u6863\u91cc\u4ea4\u53c9\u786e\u8ba4, GraphQL \u548c Kubernetes \u5219\u53ea\u6709\u62db\u8058\u4fe1\u53f7.<\/p>\n<p>\u628a\u62db\u8058\u9875\u9762\u4e22\u7ed9\u4e00\u4e2a\u603b\u7ed3\u5de5\u5177, \u6700\u5bb9\u6613\u5f97\u5230\u7684\u662f:<\/p>\n<blockquote>\n<p>\u6280\u672f\u6808: Go, GraphQL, Kubernetes, AWS CDK.<\/p>\n<\/blockquote>\n<p>\u8bfb\u8d77\u6765\u5f88\u987a, \u4f46\u5b83\u6084\u6084\u628a\"\u5e0c\u671b\u5019\u9009\u4eba\u505a\u8fc7\"\u5347\u7ea7\u6210\u4e86\"\u516c\u53f8\u6b63\u5728\u4f7f\u7528\". \u66f4\u7a33\u59a5\u7684\u5199\u6cd5\u8981\u62c6\u5f00: \u6587\u6863\u786e\u8ba4\u4e86\u54ea\u4e9b\u751f\u4ea7\u7cfb\u7edf, \u62db\u8058\u660e\u786e\u8981\u6c42\u54ea\u4e9b\u6280\u672f, \u54ea\u4e9b\u53ea\u662f\u4f18\u5148\u9879, \u54ea\u4e9b\u5c5e\u4e8e\u5019\u9009\u4eba\u7684\u8fc7\u5f80\u7ecf\u9a8c\u800c\u4e0d\u662f\u5f53\u524d\u6280\u672f\u6808.<\/p>\n<p>\u5bf9\u5de5\u7a0b\u5e08\u6765\u8bf4, \"\u8fdb\u53bb\u7ef4\u62a4 Kubernetes \u96c6\u7fa4\"\u548c\"\u516c\u53f8\u5e0c\u671b\u4f60\u6709 Kubernetes \u7ecf\u9a8c, \u4f46\u516c\u5f00\u6750\u6599\u63cf\u8ff0\u7684\u4e3b\u8981\u662f serverless \u67b6\u6784\", \u662f\u4e24\u4efd\u4e0d\u540c\u7684\u5de5\u4f5c.<\/p>\n<h2 id=\"mei-zhao-dao-ye-shi-yi-chong-jie-guo\"><a class=\"zola-anchor\" href=\"#mei-zhao-dao-ye-shi-yi-chong-jie-guo\" aria-label=\"Anchor link for: mei-zhao-dao-ye-shi-yi-chong-jie-guo\">\"\u6ca1\u627e\u5230\"\u4e5f\u662f\u4e00\u79cd\u7ed3\u679c<\/a><\/h2>\n<p>\"\u8fd9\u5bb6\u516c\u53f8\u6ca1\u6709\u6280\u672f\u535a\u5ba2\"\u662f\u4e00\u53e5\u5173\u4e8e\u4e16\u754c\u7684\u65ad\u8a00.<\/p>\n<p>\"\u622a\u81f3\u67d0\u65e5, \u5728\u5b98\u7f51\u5bfc\u822a, sitemap, \u62db\u8058\u9875\u9762, GitHub \u7ec4\u7ec7\u4ee5\u53ca\u516c\u53f8\u4e2d\u82f1\u6587\u540d\u79f0\u7684\u516c\u5f00\u641c\u7d22\u7ed3\u679c\u4e2d\u6ca1\u6709\u627e\u5230\u6280\u672f\u535a\u5ba2\"\u662f\u4e00\u53e5\u5173\u4e8e\u8c03\u67e5\u8fc7\u7a0b\u7684\u8bb0\u5f55.<\/p>\n<p>\u524d\u4e00\u53e5\u5f88\u53ef\u80fd\u662f\u9519\u7684: \u535a\u5ba2\u4e5f\u8bb8\u5728\u4e00\u4e2a\u6ca1\u88ab\u5b98\u7f51\u94fe\u63a5\u7684\u5b50\u57df\u540d, \u4e5f\u8bb8\u6539\u8fc7\u540d\u5b57, \u4e5f\u8bb8\u641c\u7d22\u5f15\u64ce\u8fd8\u6ca1\u6536\u5f55. \u540e\u4e00\u53e5\u81f3\u5c11\u53ef\u4ee5\u590d\u6838 - \u522b\u4eba\u77e5\u9053\u4f60\u5728\u54ea\u91cc\u627e\u8fc7, \u4ec0\u4e48\u65f6\u5019\u627e\u8fc7, \u53ef\u4ee5\u4ece\u4f60\u505c\u4e0b\u7684\u5730\u65b9\u63a5\u7740\u8d70.<\/p>\n<p>\u6240\u4ee5\u6863\u6848\u91cc\u7684 <code>Not publicly disclosed<\/code> \u4e0d\u662f\u7a7a\u767d\u5b57\u6bb5, \u800c\u662f\u5e26\u65e5\u671f\u548c\u8303\u56f4\u7684\u641c\u7d22\u7ed3\u679c.<\/p>\n<p>\u5f88\u591a\u8c03\u67e5\u770b\u8d77\u6765\u50cf\u662f\u5728\u627e\u7b54\u6848, \u5b9e\u9645\u4e0a\u662f\u5728\u7ed9\"\u6211\u4e0d\u77e5\u9053\"\u753b\u4e00\u6761\u51c6\u786e\u7684\u8fb9\u754c.<\/p>\n<h2 id=\"zhe-tao-fang-fa-de-ju-xian\"><a class=\"zola-anchor\" href=\"#zhe-tao-fang-fa-de-ju-xian\" aria-label=\"Anchor link for: zhe-tao-fang-fa-de-ju-xian\">\u8fd9\u5957\u65b9\u6cd5\u7684\u5c40\u9650<\/a><\/h2>\n<p>\u8fd9\u5957\u65b9\u6cd5\u4f9d\u8d56\u516c\u53f8\u613f\u610f\u5728\u516c\u5f00\u7f51\u7edc\u4e0a\u7559\u4e0b\u4e1c\u897f. \u975e\u5e38\u65e9\u671f\u7684\u56e2\u961f\u53ef\u80fd\u6ca1\u6709\u4ea7\u54c1\u6587\u6863, \u62db\u8058\u9875\u9762\u548c\u6b63\u5f0f\u65b0\u95fb\u7a3f, \u5b98\u7f51\u53ea\u6709\u4e00\u53e5 slogan \u548c\u4e00\u4e2a\u8054\u7cfb\u90ae\u7bb1. \u516c\u5f00\u4fe1\u606f\u5c11\u4e0d\u7b49\u4e8e\u516c\u53f8\u5dee, \u53ea\u662f\u4ee5\u516c\u53f8\u4e3a\u4e2d\u5fc3\u7684\u8c03\u67e5\u5230\u8fd9\u91cc\u5c31\u8d70\u4e0d\u52a8\u4e86.<\/p>\n<p>\u516c\u53f8\u8d8a\u65e9\u671f, \u8c03\u67e5\u91cd\u5fc3\u5c31\u8d8a\u9700\u8981\u4ece\u516c\u53f8\u8f6c\u5411\u521b\u59cb\u4eba. \u521b\u59cb\u4eba\u7684\u516c\u5f00\u804c\u4e1a\u8d26\u53f7, \u8bbf\u8c08, \u64ad\u5ba2\u548c\u6d3b\u52a8\u7b80\u4ecb, \u53ef\u80fd\u662f\u4ea7\u54c1\u8fdb\u5ea6, \u62db\u8058\u8ba1\u5212\u548c\u7b2c\u4e00\u6279\u5ba2\u6237\u4ec5\u6709\u7684\u5f53\u524d\u6765\u6e90, \u4e5f\u80fd\u63d0\u4f9b\u7ee7\u7eed\u5411\u6ce8\u518c\u4fe1\u606f\u548c\u540e\u7eed\u516c\u544a\u4ea4\u53c9\u786e\u8ba4\u7684\u7ebf\u7d22.<\/p>\n<p>\u4f46\u8c03\u67e5\u5bf9\u8c61\u53d8\u4e86, \u8bc1\u636e\u6807\u51c6\u4e0d\u80fd\u8ddf\u7740\u653e\u677e. \u521b\u59cb\u4eba\u7684\u5e16\u5b50\u80fd\u8bc1\u660e\u4ed6\u5728\u67d0\u5929\u8bf4\u8fc7\u4ec0\u4e48, \u4e0d\u80fd\u8bc1\u660e\u90a3\u4ef6\u4e8b\u5df2\u7ecf\u53d1\u751f; \"\u8ba1\u5212\"\u548c\"\u6b63\u5728\u5f00\u53d1\"\u4e5f\u4e0d\u80fd\u53d8\u6210\u73b0\u6709\u80fd\u529b. \u65e9\u671f\u516c\u53f8\u7684\u6863\u6848\u56e0\u6b64\u53ef\u80fd\u66f4\u77ed, \u66f4\u591a\u5730\u65b9\u5199\u7740\"\u5c1a\u672a\u786e\u8ba4\", \u8fd9\u662f\u8fd9\u5957\u65b9\u6cd5\u5fc5\u987b\u63a5\u53d7\u7684\u8fb9\u754c.<\/p>\n<h2 id=\"wei-shen-me-zui-hou-shi-yi-dui-markdown\"><a class=\"zola-anchor\" href=\"#wei-shen-me-zui-hou-shi-yi-dui-markdown\" aria-label=\"Anchor link for: wei-shen-me-zui-hou-shi-yi-dui-markdown\">\u4e3a\u4ec0\u4e48\u6700\u540e\u662f\u4e00\u5806 Markdown<\/a><\/h2>\n<p>\u6ca1\u6709\u6570\u636e\u5e93, \u6ca1\u6709\u524d\u7aef, \u6bcf\u5bb6\u516c\u53f8\u53ea\u662f\u4e00\u4e2a\u76ee\u5f55:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>companies\/<\/span><\/span>\n<span class=\"giallo-l\"><span>  company-name\/<\/span><\/span>\n<span class=\"giallo-l\"><span>    README.md<\/span><\/span>\n<span class=\"giallo-l\"><span>    README.zh-CN.md<\/span><\/span><\/code><\/pre>\n<p>Markdown \u7684\u597d\u5904\u5c31\u662f\u8db3\u591f\u4f4e\u7ea7: \u6bcf\u4e2a\u7ed3\u8bba\u65c1\u8fb9\u53ef\u4ee5\u76f4\u63a5\u653e\u94fe\u63a5, Git \u80fd\u770b\u89c1\u67d0\u4e2a\u6570\u5b57\u548c\u67d0\u53e5\u63aa\u8f9e\u662f\u5728\u54ea\u4e00\u6b21\u4fee\u6539\u91cc\u53d8\u7684, \u516c\u53f8\u6539\u540d\u4e5f\u4e0d\u9700\u8981\u8fc1\u79fb\u6570\u636e\u5e93. \u6253\u5f00 GitHub \u5c31\u80fd\u8bfb, clone \u4e0b\u6765\u5c31\u80fd\u641c, \u60f3\u7ea0\u9519\u5c31\u662f\u4e00\u4e2a diff. \u5bf9\"\u53ef\u590d\u6838\"\u6765\u8bf4, \u4e00\u4efd\u80fd\u88ab diff \u7684\u7eaf\u6587\u672c\u6bd4\u4e00\u4e2a\u6f02\u4eae\u7684\u754c\u9762\u6709\u7528\u5f97\u591a.<\/p>\n<p>\u82f1\u6587\u9875\u9762\u662f\u4e8b\u5b9e\u7ed3\u6784\u7684\u4e3b\u7248\u672c, \u4e2d\u6587\u9875\u9762\u5728\u76f8\u540c\u7ae0\u8282\u4e0b\u540c\u6b65. \u4e24\u4efd\u6587\u6863\u4f1a\u6162\u6162\u6f02\u79fb: \u82f1\u6587\u6539\u4e86\u878d\u8d44\u6570\u5b57, \u4e2d\u6587\u8fd8\u505c\u5728\u4e0a\u4e00\u7248; \u4e2d\u6587\u5c11\u590d\u5236\u4e00\u4e2a\u6765\u6e90\u94fe\u63a5, \u8868\u9762\u770b\u4e0d\u51fa\u6765, \u610f\u601d\u5df2\u7ecf\u53d8\u4e86. \u6240\u4ee5\u4ed3\u5e93\u91cc\u6709\u4e00\u4e2a\u5f88\u5c0f\u7684<a rel=\"external\" href=\"https:\/\/github.com\/memwey\/startup-due-diligence\/blob\/main\/scripts\/verify_translations.py\">\u6821\u9a8c\u811a\u672c<\/a>, \u68c0\u67e5\u4e2d\u82f1\u9875\u9762\u662f\u5426\u6210\u5bf9, \u66f4\u65b0\u65e5\u671f\u662f\u5426\u4e00\u81f4, \u6807\u9898\u5c42\u7ea7\u4e0e\u8868\u683c\u884c\u6570\u662f\u5426\u76f8\u540c, \u6765\u6e90\u94fe\u63a5\u96c6\u5408\u662f\u5426\u4e00\u81f4, \u672c\u5730\u94fe\u63a5\u662f\u5426\u8fd8\u80fd\u6253\u5f00.<\/p>\n<p>\u5b83\u4e0d\u80fd\u8bc1\u660e\u7ffb\u8bd1\u6b63\u786e, \u5c31\u50cf checksum \u4e0d\u80fd\u8bc1\u660e\u4e24\u4efd\u9519\u8bef\u7684\u6570\u636e\u662f\u5bf9\u7684, \u4f46\u80fd\u6293\u4f4f\u7ef4\u62a4\u4e2d\u6700\u5bb9\u6613\u6084\u6084\u53d1\u751f\u7684\u6f02\u79fb. <del>\u5199\u4e2a README, \u6700\u540e\u8fd8\u662f\u5199\u51fa\u4e86\u6570\u636e\u4e00\u81f4\u6027\u68c0\u67e5<\/del>.<\/p>\n<h2 id=\"hou-ji\"><a class=\"zola-anchor\" href=\"#hou-ji\" aria-label=\"Anchor link for: hou-ji\">\u540e\u8bb0<\/a><\/h2>\n<p>\u8fd9\u4e2a\u9879\u76ee\u4e0d\u4f1a\u544a\u8bc9\u4f60\u54ea\u5bb6\u516c\u53f8\u503c\u5f97\u52a0\u5165. \u5de5\u4f5c\u5185\u5bb9\u662f\u5426\u559c\u6b22, \u98ce\u9669\u662f\u5426\u80fd\u63a5\u53d7, \u521b\u59cb\u4eba\u662f\u5426\u503c\u5f97\u4fe1\u4efb, \u56e2\u961f\u76f8\u5904\u662f\u5426\u8212\u670d, \u8fd9\u4e9b\u53ea\u80fd\u5728\u9762\u8bd5\u548c\u5b9e\u9645\u63a5\u89e6\u4e2d\u5224\u65ad; \u516c\u5f00\u8d44\u6599\u505a\u4e0d\u5230, \u786c\u505a\u53ea\u4f1a\u628a\u63a8\u6d4b\u5305\u88c5\u6210\u7ed3\u8bba.<\/p>\n<p>\u5b83\u80fd\u505a\u7684\u662f\u628a\"\u8fd9\u5bb6\u516c\u53f8\u542c\u8d77\u6765\u8fd8\u4e0d\u9519\"\u62c6\u6210\u4e09\u6837\u4e1c\u897f: \u6709\u6765\u6e90\u548c\u65e5\u671f\u7684\u4e8b\u5b9e, \u5c1a\u672a\u89e3\u51b3\u7684\u51b2\u7a81\u4e0e\u7a7a\u767d, \u4ee5\u53ca\u4e0b\u4e00\u6b21\u9762\u8bd5\u5e94\u8be5\u5f53\u9762\u95ee\u7684\u95ee\u9898. \u81f3\u5c11\u53ef\u4ee5\u95ee\u51fa\u6bd4\"\u4f60\u4eec\u6280\u672f\u6808\u662f\u4ec0\u4e48\"\u66f4\u5177\u4f53\u7684\u95ee\u9898.<\/p>\n<blockquote>\n<p>\u4ed3\u5e93\u91cc\u7684\u5185\u5bb9\u5747\u57fa\u4e8e\u516c\u5f00\u4fe1\u606f\u72ec\u7acb\u6574\u7406, \u4e0e\u76f8\u5173\u516c\u53f8\u6ca1\u6709\u4efb\u4f55\u5173\u7cfb, \u4e5f\u53ef\u80fd\u4e0d\u5b8c\u6574\u6216\u5df2\u7ecf\u8fc7\u65f6. \u6d89\u53ca\u5c31\u4e1a\u6216\u6295\u8d44\u51b3\u7b56\u65f6, \u8bf7\u76f4\u63a5\u5411\u516c\u53f8\u6838\u5b9e.<\/p>\n<\/blockquote>\n<h2 id=\"can-kao-lian-jie\"><a class=\"zola-anchor\" href=\"#can-kao-lian-jie\" aria-label=\"Anchor link for: can-kao-lian-jie\">\u53c2\u8003\u94fe\u63a5<\/a><\/h2>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/memwey\/startup-due-diligence\">startup-due-diligence<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/memwey\/startup-due-diligence\/blob\/main\/GUIDE.md\">Research guide<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/memwey\/startup-due-diligence\/tree\/main\/companies\">Company research index<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/memwey\/startup-due-diligence\/tree\/main\/companies\/tensor-energy\">Tensor Energy<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/memwey\/startup-due-diligence\/tree\/main\/companies\/shippio\">Shippio<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/memwey\/startup-due-diligence\/blob\/main\/scripts\/verify_translations.py\">Translation verification script<\/a><\/li>\n<\/ul>\n"},{"title":"\u65e5\u8bed\u53f0\u8bcd - 003","published":"2026-07-27T14:35:12+09:00","updated":"2026-07-27T14:35:12+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/japanese-serifu-003\/"}},"id":"https:\/\/memwey.github.io\/posts\/japanese-serifu-003\/","content":"<hr \/>\n<p>\u306a\u3093\u3067\u305d\u3093\u306a\u306b\u6163(\u306a)\u308c\u3066\u3093\u3060\u3088\u3063\uff01\u96ea\u83dc(\u305b\u3064\u306a)\u3068\u2026\u4f55\u56de(\u306a\u3093\u304b\u3044)\u30ad\u30b9\u3057\u305f\u3093\u3060\u3088\uff01\uff1f\u3069\u3053\u307e\u3067\u3042\u305f\u3057\u3092\u7f6e(\u304a)\u3044\u3066\u304d\u307c\u308a\u306b\u3059\u308c\u3070\u6c17(\u304d)\u304c\u6e08(\u3059)\u3080\u3093\u3060\u3088\uff01\uff1f<\/p>\n<hr \/>\n<p>\u3042\u305f\u3057\u304c\u3001\u5148(\u3055\u304d)\u3060\u3063\u305f\u2026\u2026\u5148(\u3055\u304d)\u3060\u3063\u305f\u3093\u3060\u2026\u2026\u30ad\u30b9\u3057\u305f\u306e\u3082\u3001\u62b1(\u3060)\u304d\u5408(\u3042)\u3063\u305f\u306e\u3082\u3002\u305d\u3044\u3064\u306e\u3053\u3068\u597d(\u3059)\u304d\u306b\u306a\u3063\u305f\u306e\u3082\u3002<\/p>\n<hr \/>\n<p>\u3069\u3046\u3057\u3066\u3053\u3046\u306a\u308b\u3093\u3060\u308d\u3046\u2026\u521d(\u306f\u3058)\u3081\u3066\u3001\u597d(\u3059)\u304d\u306a\u4eba(\u3072\u3068)\u304c\u51fa\u6765(\u3067\u304d)\u305f\u3002\u4e00\u751f(\u3044\u3063\u3057\u3087\u3046)\u3082\u306e\u306e\u53cb(\u3068\u3082)\u3060\u3061\u304c\u3067\u304d\u305f\u3002\u5b09(\u3046\u308c)\u3057\u3044\u3053\u3068\u304c\u4e8c(\u3075\u305f)\u3064\u91cd(\u304b\u3055)\u306a\u3063\u3066\u3002\u305d\u306e\u4e8c(\u3075\u305f)\u3064\u306e\u5b09(\u3046\u308c)\u3057\u3055\u304c\u3001\u307e\u305f\u3001\u305f\u304f\u3055\u3093\u306e\u5b09(\u3046\u308c)\u3057\u3055\u3092\u9023(\u3064)\u308c\u3066\u304d\u3066\u304f\u308c\u3066\u3002\u5922(\u3086\u3081)\u306e\u3088\u3046\u306b\u5e78(\u3057\u3042\u308f)\u305b\u306a\u6642\u9593(\u3058\u304b\u3093)\u3092\u624b(\u3066)\u306b\u5165(\u3044)\u308c\u305f\u306f\u305a\u306a\u306e\u306b\u2026\u306a\u306e\u306b\u3001\u3069\u3046\u3057\u3066\u3001\u3053\u3046\u306a\u3063\u3061\u3083\u3046\u3093\u3060\u308d\u3046\u2026<\/p>\n"},{"title":"\u65e5\u8bed\u53f0\u8bcd - 002","published":"2026-07-02T12:40:19+09:00","updated":"2026-07-02T12:40:19+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/japanese-serifu-002\/"}},"id":"https:\/\/memwey.github.io\/posts\/japanese-serifu-002\/","content":"<hr \/>\n<p>\u300c\u81ea\u5206(\u3058\u3076\u3093)\u306b\u306f\u4ed6(\u307b\u304b)\u306b\u4f55(\u306a\u306b)\u3082\u306a\u3044\u3063\u3066\u3001\u305d\u3093\u306a\u4e8b(\u3053\u3068)\u8a00(\u3044)\u3046\u306a\u3088\u3002\u5225(\u308f\u304b)\u308c\u969b(\u304e\u308f)\u306b\u30b5\u30e8\u30ca\u30e9\u306a\u3093\u3066\u3001\u305d\u3093\u306a\u60b2(\u304b\u306a)\u3057\u3044\u4e8b(\u3053\u3068)\u8a00(\u3044)\u3046\u306a\u3088\u3002\u300d<\/p>\n<p>\u300c\u306a\u306b\u6ce3(\u306a)\u3044\u3066\u308b\u306e\uff1f\u300d<\/p>\n<p>\u300c\u3054\u3081\u3093\u306a\u3055\u3044\u3002\u3053\u3046\u3044\u3046\u3068\u304d\u3069\u3093\u306a\u9854(\u304b\u304a)\u3059\u308c\u3070\u3044\u3044\u304b\u308f\u304b\u3089\u306a\u3044\u306e\u3002\u300d<\/p>\n<p>\u300c\u7b11(\u308f\u3089)\u3048\u3070\u3044\u3044\u3068\u601d(\u304a\u3082)\u3046\u3088\u3002\u300d<\/p>\n<hr \/>\n<p>\u50d5(\u307c\u304f)\u306f\u541b(\u304d\u307f)\u306b\u4f1a(\u3042)\u3046\u305f\u3081\u306b\u751f(\u3046)\u307e\u308c\u3066\u6765(\u304d)\u305f\u3093\u3060\u306d<\/p>\n<hr \/>\n<p>\u9003(\u306b)\u3052\u3061\u3083\u30c0\u30e1\u3060<\/p>\n<hr \/>\n<p>\u307e\u3054\u3053\u308d\u3092\u3001\u541b(\u304d\u307f)\u306b<\/p>\n<hr \/>\n<p>\u4e16\u754c(\u305b\u304b\u3044)\u306e\u4e2d\u5fc3(\u3061\u3085\u3046\u3057\u3093)\u3067\u30a2\u30a4\u3092\u53eb(\u3055\u3051)\u3093\u3060\u3051\u3082\u306e<\/p>\n<hr \/>\n<p>\u300c\u7dbe\u6ce2(\u3042\u3084\u306a\u307f)\u3001\u7236(\u3068\u3046)\u3055\u3093\u306e\u3053\u3068\u3001\u3042\u308a\u304c\u3068\u3046\u300d<\/p>\n<p>\u300c\u3054\u3081\u3093\u306a\u3055\u3044\u3001\u4f55(\u306a\u306b)\u3082\u51fa\u6765(\u3067\u304d)\u306a\u304b\u3063\u305f\u300d<\/p>\n<p>\u300c\u3044\u3044\u3093\u3060\u3001\u3082\u3046\u3001\u3053\u308c\u3067\u3044\u3044\u3093\u3060\u300d<\/p>\n<hr \/>\n<p>\u3055\u3088\u3046\u306a\u3089\u3001\u5168(\u3059\u3079)\u3066\u306e\u30a8\u30f4\u30a1\u30f3\u30b2\u30ea\u30aa\u30f3<\/p>\n<hr \/>\n<p>\u300c\u898b(\u307f)\u305f\u3053\u3068\u3082\u805e(\u304d)\u3044\u305f\u3053\u3068\u3082\u306a\u3044\u306e\u306b\u3001\u51fa\u6765(\u3067\u304d)\u308b\u308f\u3051\u306a\u3044\u3088\uff01\u300d<\/p>\n<p>\u300c\u4e57(\u306e)\u308b\u306a\u3089\u65e9(\u306f\u3084)\u304f\u3057\u308d\uff01\u3067\u306a\u3051\u308c\u3070\u5e30(\u304b\u3048)\u308c\uff01\u300d<\/p>\n<hr \/>\n<p>\u77e5(\u3057)\u3089\u306a\u3044\u5929\u4e95(\u3066\u3093\u3058\u3087\u3046)\u3060<\/p>\n<hr \/>\n<p>\u4eba(\u3072\u3068)\u306f\u4ed6\u4eba(\u305f\u306b\u3093)\u3092\u5b8c\u5168(\u304b\u3093\u305c\u3093)\u306b\u7406\u89e3(\u308a\u304b\u3044)\u3059\u308b\u3053\u3068\u306f\u51fa\u6765(\u3067\u304d)\u306a\u3044\u3002<\/p>\n<hr \/>\n<p>\u5927\u4eba(\u304a\u3068\u306a)\u306b\u306a\u308b\u3063\u3066\u3053\u3068\u306f\u3001\u8fd1(\u3061\u304b)\u3065\u3044\u305f\u308a\u96e2(\u306f\u306a)\u308c\u305f\u308a\u3092\u7e70(\u304f)\u308a\u8fd4(\u304b\u3048)\u3057\u3066\u3001\u304a\u4e92(\u305f\u304c)\u3044\u304c\u3042\u307e\u308a\u50b7(\u304d\u305a)\u3064\u304b\u305a\u306b\u3059\u3080\u8ddd\u96e2(\u304d\u3087\u308a)\u3092\u898b(\u307f)\u3064\u3051\u51fa(\u3060)\u3059\u3063\u3066\u3053\u3068\u3002<\/p>\n<hr \/>\n<p>\u3064\u3089\u3044\u3053\u3068\u3092\u77e5(\u3057)\u3063\u3066\u308b\u4eba\u9593(\u306b\u3093\u3052\u3093)\u306e\u307b\u3046\u304c\u3001\u305d\u308c\u3060\u3051\u4eba(\u3072\u3068)\u306b\u3084\u3055\u3057\u304f\u3067\u304d\u308b\u3002\u305d\u308c\u306f\u5f31(\u3088\u308f)\u3055\u3068\u9055(\u3061\u304c)\u3046\u304b\u3089\u306a\u3002<\/p>\n<hr \/>\n<p>\u3053\u306e\u4e16\u754c(\u305b\u304b\u3044)\u306f\u3042\u306a\u305f\u306e\u77e5(\u3057)\u3089\u306a\u3044\u9762\u767d(\u304a\u3082\u3057\u308d)\u3044\u4e8b(\u3053\u3068)\u3067\u3001\u6e80(\u307f)\u3061\u6e80(\u307f)\u3061\u3066\u3044\u308b\u308f\u3088\u3002\u697d(\u305f\u306e)\u3057\u307f\u306a\u3055\u3044\u3002<\/p>\n<hr \/>\n<p>\u4eca\u5ea6(\u3053\u3093\u3069)\u3053\u305d\u541b(\u304d\u307f)\u3060\u3051\u306f\u5e78(\u3057\u3042\u308f)\u305b\u306b\u3057\u3066\u307f\u305b\u308b\u3088<\/p>\n"},{"title":"\u65e5\u8bed\u53f0\u8bcd - 001","published":"2026-07-02T11:52:30+09:00","updated":"2026-07-02T11:52:30+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/japanese-serifu-001\/"}},"id":"https:\/\/memwey.github.io\/posts\/japanese-serifu-001\/","content":"<hr \/>\n<p>\u30e9\u30e9\u30a1\u30fb\u30b9\u30f3\u306f\u3001\u79c1(\u308f\u305f\u3057)\u306e\u6bcd(\u306f\u306f)\u306b\u306a\u3063\u3066\u304f\u308c\u308b\u304b\u3082\u3057\u308c\u306a\u304b\u3063\u305f\u5973\u6027(\u3058\u3087\u305b\u3044)\u3060\u3002\u305d\u306e\u30e9\u30e9\u30a1\u3092\u6bba(\u3053\u308d)\u3057\u305f\u304a\u524d(\u307e\u3048)\u306b\u8a00(\u3044)\u3048\u305f\u4e8b(\u3053\u3068)\u304b\uff01<\/p>\n<hr \/>\n<p>\u62b5\u6297(\u3066\u3044\u3053\u3046)\u3059\u308b\u3068\u7121\u99c4\u6b7b(\u3080\u3060\u3058)\u306b\u3059\u308b\u3060\u3051\u3060\u3063\u3066\u3001\u4f55\u6545(\u306a\u305c)\u5206(\u308f)\u304b\u3089\u306a\u3044\u3093\u3060\uff01\uff1f<\/p>\n<hr \/>\n<p>\u4eba(\u3072\u3068)\u306f\u540c(\u304a\u306a)\u3058\u904e(\u3042\u3084\u307e)\u3061\u3092\u7e70(\u304f)\u308a\u8fd4(\u304b\u3048)\u3059...<\/p>\n<hr \/>\n<p>\u89aa\u7236(\u304a\u3084\u3058)\u306b\u3082\u3076\u305f\u308c\u305f\u3053\u3068\u306a\u3044\u306e\u306b\uff01\uff01\uff01<\/p>\n<hr \/>\n<p>\u305d\u308c\u304c\u7518(\u3042\u307e)\u3063\u305f\u308c\u306a\u3093\u3060\u3002\u6bb4(\u306a\u3050)\u3089\u308c\u3082\u305b\u305a\u306b\u4e00\u4eba\u524d(\u3044\u3061\u306b\u3093\u307e\u3048)\u306b\u306a\u3063\u305f\u5974(\u3084\u3064)\u304c\u3069\u3053\u306b\u3044\u308b\u3082\u306e\u304b\uff01<\/p>\n<hr \/>\n<p>\u3042\u3093\u306a\u306e\u98fe(\u304b\u3056)\u308a\u3067\u3059\uff01\u5049(\u3048\u3089)\u3044\u4eba(\u3072\u3068)\u306b\u306f\u305d\u308c\u304c\u308f\u304b\u3089\u3093\u306e\u3067\u3059\u3088\uff01<\/p>\n<hr \/>\n<p>\u50d5(\u307c\u304f)\u306f\u2026\u53d6(\u3068)\u308a\u8fd4(\u304b\u3048)\u3057\u306e\u3064\u304b\u306a\u3044\u3053\u3068\u3092\u3057\u3066\u3057\u307e\u3063\u305f\u3002<\/p>\n<hr \/>\n<p>\u8a8d(\u307f\u3068)\u3081\u305f\u304f\u306a\u3044\u3082\u306e\u3060\u306a\u3001\u81ea\u5206\u81ea\u8eab(\u3058\u3076\u3093\u3058\u3057\u3093)\u306e\u82e5(\u308f\u304b)\u3055\u3086\u3048\u306e\u904e(\u3042\u3084\u307e)\u3061\u3068\u3044\u3046\u3082\u306e\u3092\u3002<\/p>\n<hr \/>\n<p>\u5f53(\u3042)\u305f\u3089\u306a\u3051\u308c\u3070\u3069\u3046\u3068\u3044\u3046\u3053\u3068\u306f\u306a\u3044\u3002\u63f4\u8b77(\u3048\u3093\u3054)\u3057\u308d\u3002<\/p>\n<hr \/>\n<p>\u305f\u304b\u304c\u77f3(\u3044\u3057)\u3053\u308d\u4e00(\u3072\u3068)\u3064\u3001\u30ac\u30f3\u30c0\u30e0\u3067\u62bc(\u304a)\u3057\u51fa(\u3060)\u3057\u3066\u3084\u308b\uff01<\/p>\n"},{"title":"\u5728 OpenWrt \u4e0a\u914d\u7f6e Tailscale \u670d\u52a1","published":"2026-02-24T14:32:01+09:00","updated":"2026-02-25T20:33:08+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/openwrt-and-tailscale\/"}},"id":"https:\/\/memwey.github.io\/posts\/openwrt-and-tailscale\/","content":"<p><a rel=\"external\" href=\"https:\/\/tailscale.com\/\">Tailscale<\/a> \u662f\u4e00\u4e2a\u57fa\u4e8e WireGuard \u534f\u8bae\u7684\u7ec4\u7f51\u670d\u52a1, \u5b83\u53ef\u4ee5\u5b9e\u73b0\u8de8\u5e73\u53f0\u7684\u5185\u7f51\u4e92\u8054, \u4f5c\u4e3a\u4e00\u4e2a Golang \u7f16\u5199\u7684\u5f00\u6e90\u8f6f\u4ef6, \u5b83\u63d0\u4f9b\u4e86\u8f83\u4e3a\u6177\u6168\u7684\u514d\u8d39\u670d\u52a1\u5982 DERP \u7b49, \u540c\u65f6\u4e5f\u4e3a\u6709\u66f4\u591a\u9700\u6c42\u7684\u7528\u6237\u63d0\u4f9b\u4ed8\u8d39\u670d\u52a1.<\/p>\n<p>\u6211\u7684\u4f7f\u7528\u73af\u5883\u6bd4\u8f83\u7279\u6b8a, \u5bb6\u5728\u4f5b\u5c71, \u800c\u6211\u5e73\u65f6\u5728\u4e1c\u4eac\u79df\u623f\u4e0a\u73ed, \u4f7f\u7528 Tailscale \u5b9e\u73b0\u4e1c\u4eac\u4e0e\u4f5b\u5c71\u7684\u8bbe\u5907\u4e92\u8054, \u65b9\u4fbf\u901a\u4fe1\u548c\u7ba1\u7406. \u540c\u65f6, \u4e5f\u53ef\u4ee5\u5b9e\u73b0\u4e00\u4e9b\u9700\u8981\u7279\u5b9a\u7f51\u7edc\u73af\u5883\u7684\u573a\u666f, \u6bd4\u5982\u533a\u57df\u6388\u6743\u6d41\u5a92\u4f53\u6216\u8005\u4e00\u4e9b\u9700\u8981\u5728\u7279\u5b9a\u7f51\u7edc\u73af\u5883\u4e0b\u8fd0\u884c\u7684\u5e94\u7528.<\/p>\n<p>\u5728\u4e1c\u4eac\u5b9e\u9645\u642d\u5efa\u7684\u65f6\u5019, \u53d1\u73b0\u4e1c\u4eac\u7684\u4e3b\u8def\u7531 K2P \u6027\u80fd\u5b9e\u5728\u5b71\u5f31, \u4e00\u5f00\u59cb ROM \u4e0d\u8db3\u4ee5\u5b89\u88c5 Tailscale, \u7cbe\u7b80\u56fa\u4ef6\u540e\u52c9\u5f3a\u5b89\u88c5, \u53c8 RAM \u4e0d\u8db3, \u53cd\u590d\u53d1\u751f OOM \u7684\u60c5\u51b5, \u6700\u7ec8\u628a\u4e00\u53f0\u4e00\u76f4\u5403\u7070\u7684\u6590\u8baf N1 \u627e\u4e86\u51fa\u6765\u5b89\u88c5 Tailscale, \u4f5c\u4e3a\u65c1\u8def\u8def\u7531\u5904\u7406 Tailscale \u7684\u6d41\u91cf. \u6700\u7ec8\u5f62\u6210\u4e86\u4e00\u4e2a\u7a0d\u5fae\u590d\u6742\u7684\u7f51\u7edc\u7ed3\u6784, \u4f5b\u5c71\u7684\u4e3b\u8def\u7531\u4f5c\u4e3a Tailscale \u7f51\u7edc\u7684\u5165\u53e3, \u800c\u4e1c\u4eac\u7684 N1 \u4f5c\u4e3a\u65c1\u8def\u8def\u7531, \u5904\u7406 Tailscale \u7f51\u7edc\u4e2d\u7684\u6d41\u91cf. \u4e0d\u8fc7\u6700\u7ec8\u6548\u679c\u8fd8\u662f\u4e00\u6837\u7684, \u5373\u4e24\u5730\u5185\u7f51\u76f4\u63a5\u4e92\u8bbf, \u4e14\u5747\u63d0\u4f9b\u7f51\u7edc\u51fa\u53e3.<\/p>\n<h2 id=\"wang-luo-jie-gou\"><a class=\"zola-anchor\" href=\"#wang-luo-jie-gou\" aria-label=\"Anchor link for: wang-luo-jie-gou\">\u7f51\u7edc\u7ed3\u6784<\/a><\/h2>\n<table><thead><tr><th>\u5730\u70b9<\/th><th>\u8bbe\u5907\u89d2\u8272<\/th><th>\u8bbe\u5907\u7cfb\u7edf<\/th><th>Tailscale \u8282\u70b9\u7528\u9014<\/th><th>\u5185\u7f51\u7f51\u6bb5<\/th><th>\u5185\u7f51IP<\/th><th>\u8bbe\u5907\u578b\u53f7<\/th><\/tr><\/thead><tbody>\n<tr><td>\u4f5b\u5c71<\/td><td>\u4e3b\u8def\u7531<\/td><td>OpenWrt 24.10<\/td><td>\u5185\u7f51\u5165\u53e3, \u63d0\u4f9b\u5c40\u57df\u7f51\u7a7f\u900f<\/td><td>192.168.128.0\/24<\/td><td>192.168.128.1<\/td><td>\u6b4c\u534e\u94fe GHL-R-001<\/td><\/tr>\n<tr><td>\u4e1c\u4eac<\/td><td>\u4e3b\u8def\u7531<\/td><td>OpenWrt 24.10<\/td><td>\u65e0<\/td><td>192.168.9.0\/24<\/td><td>192.168.9.1<\/td><td>\u6590\u8baf K2P<\/td><\/tr>\n<tr><td>\u4e1c\u4eac<\/td><td>\u65c1\u8def\u8def\u7531<\/td><td>Armbian 26.2.1 trixie<\/td><td>\u63d0\u4f9b\u5c40\u57df\u7f51\u7a7f\u900f<\/td><td>192.168.9.0\/24<\/td><td>192.168.9.235<\/td><td>\u6590\u8baf N1<\/td><\/tr>\n<\/tbody><\/table>\n<p>\u5f53\u524d\u4f7f\u7528\u7684\u662f 1.94.2 \u7248\u672c\u7684 Tailscale \u5ba2\u6237\u7aef. \u7f51\u7edc\u7ed3\u6784\u4e2d\u5185\u7f51\u7f51\u6bb5\u4e0d\u5e94\u8be5\u91cd\u53e0, \u4e0d\u7136\u4f1a\u5bfc\u81f4\u51b2\u7a81.<\/p>\n<p>\u6700\u7ec8\u5b9e\u73b0\u7684\u7f51\u7edc\u62d3\u6251\u662f\u8fd9\u6837\u7684:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>    \u7ec8\u7aef\u8bbe\u5907 (PC\/\u624b\u673a\/NAS)<\/span><\/span>\n<span class=\"giallo-l\"><span>               \u2502<\/span><\/span>\n<span class=\"giallo-l\"><span>      \u4e1c\u4eac LAN (192.168.9.0\/24)<\/span><\/span>\n<span class=\"giallo-l\"><span>               \u2502<\/span><\/span>\n<span class=\"giallo-l\"><span>    \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<\/span><\/span>\n<span class=\"giallo-l\"><span>    \u2502                     \u2502<\/span><\/span>\n<span class=\"giallo-l\"><span>  OpenWrt (192.168.9.1) \u2500\u2500\u253c\u2500\u2500\u2500 [\u9759\u6001\u8def\u7531] \u2500\u2500\u2500 Armbian + Tailscale (192.168.9.235)<\/span><\/span>\n<span class=\"giallo-l\"><span>    \u2502                     \u2502                   ( \u5904\u7406\u53bb\u5f80 192.168.128.0\/24 \u7684\u6d41\u91cf )<\/span><\/span>\n<span class=\"giallo-l\"><span>    \u2502                     \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<\/span><\/span>\n<span class=\"giallo-l\"><span>    \u2502<\/span><\/span>\n<span class=\"giallo-l\"><span>    \u2514\u2500\u2500\u2500 \u516c\u7f51 (Internet) \u2500\u2500\u2500 Tailscale \u7f51\u7edc (DERP\/P2P)<\/span><\/span>\n<span class=\"giallo-l\"><span>                \u2502<\/span><\/span>\n<span class=\"giallo-l\"><span>                \u2502<\/span><\/span>\n<span class=\"giallo-l\"><span>         OpenWrt + Tailscale (192.168.128.1)<\/span><\/span>\n<span class=\"giallo-l\"><span>                \u2502<\/span><\/span>\n<span class=\"giallo-l\"><span>         \u4f5b\u5c71 LAN (192.168.128.0\/24)<\/span><\/span><\/code><\/pre>\n<p>\u5728\u4e1c\u4eac\u4fa7, \u6240\u6709 LAN \u8bbe\u5907\u7684\u9ed8\u8ba4\u7f51\u5173\u4ecd\u662f 192.168.9.1, \u901a\u8fc7\u9759\u6001\u8def\u7531, \u53bb\u5f80\u4f5b\u5c71\u7684\u6d41\u91cf\u4f1a\u88ab\u4e2d\u8f6c\u7ed9 192.168.9.235, \u6700\u7ec8\u901a\u8fc7 Tailscale \u7f51\u7edc\u5230\u8fbe\u4f5b\u5c71\u7684\u8bbe\u5907.<\/p>\n<h2 id=\"zai-openwrt-shang-an-zhuang-tailscale-ji-web-guan-li-jie-mian\"><a class=\"zola-anchor\" href=\"#zai-openwrt-shang-an-zhuang-tailscale-ji-web-guan-li-jie-mian\" aria-label=\"Anchor link for: zai-openwrt-shang-an-zhuang-tailscale-ji-web-guan-li-jie-mian\">\u5728 OpenWrt \u4e0a\u5b89\u88c5 Tailscale \u53ca Web \u7ba1\u7406\u754c\u9762<\/a><\/h2>\n<p>OpenWrt \u4f7f\u7528 opkg \u4f5c\u4e3a\u5305\u7ba1\u7406\u5de5\u5177, \u5b98\u65b9\u81ea\u5e26\u7684\u8f6f\u4ef6\u6e90\u4e2d Tailscale \u957f\u671f\u6ca1\u6709\u66f4\u65b0\u4e86, \u6240\u4ee5\u6211\u4eec\u9700\u8981\u4ece\u7b2c\u4e09\u65b9\u8f6f\u4ef6\u6e90\u4e2d\u5b89\u88c5 Tailscale. \u540c\u65f6\u8fd9\u4e2a Tailscale \u7ecf\u8fc7\u88c1\u526a\u548c\u4f18\u5316, \u66f4\u9002\u5408\u8def\u7531\u5668\u8fd9\u79cd\u5185\u5b58\u548c\u95ea\u5b58\u8d44\u6e90\u6709\u9650\u7684\u8bbe\u5907. \u5e76\u4e14\u6211\u4eec\u589e\u52a0 Tailscale \u7684 LuCI Web \u7ba1\u7406\u754c\u9762, \u65b9\u4fbf\u7ba1\u7406\u548c\u914d\u7f6e.<\/p>\n<p>\u4e0b\u9762\u63d0\u4f9b\u7684\u662f\u547d\u4ee4\u884c\u7684\u8fc7\u7a0b, \u4e3b\u8981\u662f\u6dfb\u52a0\u8bc1\u4e66\u9700\u8981\u5230\u8bbe\u5907\u7684\u547d\u4ee4\u884c\u4e2d\u6267\u884c, \u53e6\u5916\u4e24\u9879\u64cd\u4f5c\u6dfb\u52a0\u8f6f\u4ef6\u6e90\u548c\u5b89\u88c5\u5176\u5b9e\u4e5f\u53ef\u4ee5\u5728 LuCI Web \u7ba1\u7406\u754c\u9762\u4e2d\u5b8c\u6210. \u8fd9\u91cc\u9700\u8981\u6ce8\u610f, \u6dfb\u52a0\u7b2c\u4e09\u65b9\u8bc1\u4e66\u6709\u4e00\u5b9a\u7684\u98ce\u9669, \u53ef\u80fd\u4f1a\u6709\u4f9b\u5e94\u94fe\u653b\u51fb\u7684\u98ce\u9669.<\/p>\n<h3 id=\"an-zhuang-tailscale-fu-wu\"><a class=\"zola-anchor\" href=\"#an-zhuang-tailscale-fu-wu\" aria-label=\"Anchor link for: an-zhuang-tailscale-fu-wu\">\u5b89\u88c5 Tailscale \u670d\u52a1<\/a><\/h3>\n<p>\u6dfb\u52a0\u8bc1\u4e66<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>wget -O \/tmp\/key-build.pub https:\/\/gunanovo.github.io\/openwrt-tailscale\/key-build.pub &amp;&amp; opkg-key add \/tmp\/key-build.pub<\/span><\/span><\/code><\/pre>\n<p>\u6dfb\u52a0\u8f6f\u4ef6\u6e90<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>echo &quot;src\/gz openwrt-tailscale https:\/\/gunanovo.github.io\/openwrt-tailscale&quot; &gt;&gt; \/etc\/opkg\/customfeeds.conf<\/span><\/span><\/code><\/pre>\n<p>\u5b89\u88c5<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>opkg update &amp;&amp; opkg install tailscale<\/span><\/span><\/code><\/pre><h3 id=\"an-zhuang-tailscale-luci-web-guan-li-jie-mian\"><a class=\"zola-anchor\" href=\"#an-zhuang-tailscale-luci-web-guan-li-jie-mian\" aria-label=\"Anchor link for: an-zhuang-tailscale-luci-web-guan-li-jie-mian\">\u5b89\u88c5 Tailscale LuCI Web \u7ba1\u7406\u754c\u9762<\/a><\/h3>\n<p>\u6dfb\u52a0\u8bc1\u4e66<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>wget https:\/\/Tokisaki-Galaxy.github.io\/luci-app-tailscale-community\/all\/key-build.pub -O \/tmp\/key-build.pub &amp;&amp; opkg-key add \/tmp\/key-build.pub<\/span><\/span><\/code><\/pre>\n<p>\u6dfb\u52a0\u8f6f\u4ef6\u6e90<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>echo &quot;src\/gz tailscale_community https:\/\/Tokisaki-Galaxy.github.io\/luci-app-tailscale-community\/all&quot; &gt;&gt; \/etc\/opkg\/customfeeds.conf<\/span><\/span><\/code><\/pre>\n<p>\u5b89\u88c5<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>opkg update &amp;&amp; opkg install luci-app-tailscale-community<\/span><\/span><\/code><\/pre><h2 id=\"pei-zhi-openwrt-shang-de-tailscale-ke-hu-duan\"><a class=\"zola-anchor\" href=\"#pei-zhi-openwrt-shang-de-tailscale-ke-hu-duan\" aria-label=\"Anchor link for: pei-zhi-openwrt-shang-de-tailscale-ke-hu-duan\">\u914d\u7f6e OpenWrt \u4e0a\u7684 Tailscale \u5ba2\u6237\u7aef<\/a><\/h2>\n<p>\u6b64\u65f6\u5e94\u8be5\u53ef\u4ee5\u5728 LuCI Web \u7ba1\u7406\u754c\u9762\u4e2d\u770b\u5230 \u670d\u52a1 -&gt; Tailscale \u9009\u9879, \u70b9\u51fb\u8fdb\u5165\u914d\u7f6e\u9875\u9762. \u5728\u8bbe\u7f6e\u4e2d\u70b9\u51fb\u767b\u5f55, \u4f1a\u8df3\u8f6c\u5230 Tailscale \u7f51\u7ad9\u8fdb\u884c\u767b\u9646\u6388\u6743, \u628a\u8fd9\u53f0\u8bbe\u5907\u6dfb\u52a0\u5230 Tailscale \u7f51\u7edc\u4e2d.<\/p>\n<p>\u56de\u5230\u8def\u7531\u5668\u7684 LuCI Web \u7ba1\u7406\u754c\u9762\u7684 Tailscale \u9009\u9879\u5361\u4e2d, \u9700\u8981\u6253\u5f00 <code>\u63a5\u53d7\u8def\u7531<\/code>, <code>\u901a\u544a\u51fa\u53e3\u8282\u70b9<\/code> \u8fd9\u4e24\u4e2a\u9009\u9879. <code>\u63a5\u53d7\u8def\u7531<\/code> \u7528\u4e8e\u63a5\u6536 Tailscale \u7f51\u7edc\u4e2d\u7684\u5b50\u7f51\u8def\u7531\u914d\u7f6e, \u4ee5\u5b9e\u73b0\u4e0d\u540c\u5185\u7f51\u7684\u76f4\u63a5\u901a\u4fe1. \u800c <code>\u901a\u544a\u51fa\u53e3\u8282\u70b9<\/code> \u5219\u53ef\u4ee5\u8ba9 Tailscale \u7f51\u7edc\u4e2d\u522b\u7684\u8bbe\u5907\u9009\u62e9\u901a\u8fc7\u8fd9\u53f0\u8bbe\u5907\u4ee3\u7406\u8fdb\u884c\u7f51\u7edc\u8bbf\u95ee, \u5373\u8fd9\u53f0\u8bbe\u5907\u53ef\u4ee5\u4f5c\u4e3a\u4ee3\u7406\u51fa\u53e3.<\/p>\n<p>\u968f\u540e\u9700\u8981\u586b\u5199 <code>\u901a\u544a\u8def\u7531<\/code>, \u586b\u5199\u7684\u503c\u5e94\u8be5\u662f\u4e3b\u8def\u7531\u5bf9\u5e94\u7684\u5185\u7f51\u7f51\u6bb5, \u6bd4\u5982\u6211\u8fd9\u91cc, \u4f5b\u5c71\u7684 GHL-R-001 \u5185\u7f51\u7f51\u6bb5\u662f 192.168.128.0\/24, \u4e1c\u4eac\u7684 K2P \u5185\u7f51\u7f51\u6bb5\u662f 192.168.9.0\/24.<\/p>\n<h2 id=\"pei-zhi-armbian-shang-de-tailscale-ke-hu-duan\"><a class=\"zola-anchor\" href=\"#pei-zhi-armbian-shang-de-tailscale-ke-hu-duan\" aria-label=\"Anchor link for: pei-zhi-armbian-shang-de-tailscale-ke-hu-duan\">\u914d\u7f6e Armbian \u4e0a\u7684 Tailscale \u5ba2\u6237\u7aef<\/a><\/h2>\n<p>\u5728 Armbian \u4e0a\u5b89\u88c5 Tailscale \u5ba2\u6237\u7aef\u7684\u8fc7\u7a0b\u4e0e OpenWrt \u7c7b\u4f3c, \u53ea\u662f\u9700\u8981\u5728 Armbian \u4e0a\u9700\u8981\u4f7f\u7528\u547d\u4ee4\u884c\u64cd\u4f5c. \u6700\u7ec8\u8fd0\u884c\u7684\u547d\u4ee4\u5982\u4e0b<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>tailscale up --accept-routes=true --accept-dns=true --advertise-routes=192.168.9.0\/24 --advertise-exit-node<\/span><\/span><\/code><\/pre><h3 id=\"pei-zhi-armbian-de-zhuan-fa\"><a class=\"zola-anchor\" href=\"#pei-zhi-armbian-de-zhuan-fa\" aria-label=\"Anchor link for: pei-zhi-armbian-de-zhuan-fa\">\u914d\u7f6e Armbian \u7684\u8f6c\u53d1<\/a><\/h3>\n<p>\u786e\u8ba4 ipv4, ipv6 \u8f6c\u53d1\u90fd\u5df2\u5f00\u542f, \u5373\u503c\u4e3a 1<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>echo &#39;net.ipv4.ip_forward = 1&#39; | sudo tee -a \/etc\/sysctl.conf<\/span><\/span>\n<span class=\"giallo-l\"><span>echo &#39;net.ipv6.conf.all.forwarding = 1&#39; | sudo tee -a \/etc\/sysctl.conf<\/span><\/span>\n<span class=\"giallo-l\"><span>sudo sysctl -p \/etc\/sysctl.conf<\/span><\/span><\/code><\/pre>\n<p>\u914d\u7f6e\u9632\u706b\u5899\u89c4\u5219, \u786e\u4fdd Tailscale \u7f51\u7edc\u4e2d\u7684\u6d41\u91cf\u53ef\u4ee5\u6b63\u786e\u8f6c\u53d1<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>iptables -t mangle -A FORWARD -o tailscale0 -p tcp -m tcp \\<\/span><\/span>\n<span class=\"giallo-l\"><span>--tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu<\/span><\/span><\/code><\/pre>\n<p>\u5e76\u4e14\u56fa\u5316\u4ee5\u9632\u6b62\u91cd\u542f\u4e22\u5931<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>sudo netfilter-persistent save<\/span><\/span><\/code><\/pre><h3 id=\"zai-zhu-lu-you-shang-pei-zhi-jing-tai-lu-you\"><a class=\"zola-anchor\" href=\"#zai-zhu-lu-you-shang-pei-zhi-jing-tai-lu-you\" aria-label=\"Anchor link for: zai-zhu-lu-you-shang-pei-zhi-jing-tai-lu-you\">\u5728\u4e3b\u8def\u7531\u4e0a\u914d\u7f6e\u9759\u6001\u8def\u7531<\/a><\/h3>\n<p>\u5728\u4e1c\u4eac\u4e3b\u8def\u7531 K2P \u4e0a, \u9700\u8981\u914d\u7f6e\u65c1\u8def\u7f51\u5173\u7684\u9759\u6001\u8def\u7531, \u4ee5\u786e\u4fdd\u6d41\u91cf\u53ef\u4ee5\u6b63\u786e\u8def\u7531\u5230 Tailscale \u7f51\u7edc\u4e2d\u7684\u8bbe\u5907. \u5177\u4f53\u6765\u8bf4, \u9700\u8981\u5728\u4e3b\u8def\u7531\u4e0a\u6dfb\u52a0\u4e00\u6761\u8def\u7531\u89c4\u5219, <strong>\u5230 192.168.128.0\/24 \u7684\u8def\u7531\uff0c\u4e0b\u4e00\u8df3\u4e3a 192.168.9.235<\/strong>.<\/p>\n<h2 id=\"pei-zhi-tailscale-fu-wu-guan-li\"><a class=\"zola-anchor\" href=\"#pei-zhi-tailscale-fu-wu-guan-li\" aria-label=\"Anchor link for: pei-zhi-tailscale-fu-wu-guan-li\">\u914d\u7f6e Tailscale \u670d\u52a1\u7ba1\u7406<\/a><\/h2>\n<p>\u767b\u9646 <a rel=\"external\" href=\"https:\/\/login.tailscale.com\/admin\/machines\">Tailscale \u7ba1\u7406\u9875\u9762<\/a>, \u53ef\u4ee5\u770b\u5230\u8bbe\u5907\u5df2\u7ecf\u6dfb\u52a0\u5230 Tailscale \u7f51\u7edc\u4e2d\u4e86. \u8fd8\u9700\u8981\u5728\u8fd9\u4e2a\u9875\u9762\u7684\u8bbe\u5907\u7ba1\u7406\u4e0a, \u70b9\u51fb <code>Edit route settings...<\/code>, \u52fe\u9009\u5bf9\u5e94\u7684 <code>Subnet routes<\/code> \u548c <code>Exit node<\/code> \u9009\u9879. \u4e0d\u540c\u8bbe\u5907\u90fd\u9700\u8981\u64cd\u4f5c. \u540c\u65f6\u5982\u679c\u8bbe\u5907\u957f\u671f\u5728\u7ebf\u4e14\u7269\u7406\u5b89\u5168\u53ef\u63a7, \u4e5f\u5efa\u8bae\u9009\u62e9 <code>Disable key expiry<\/code>.<\/p>\n<p>\u8fd9\u91cc\u53ef\u80fd\u4f1a\u6709\u4eba\u7ea0\u7ed3\u4e3a\u4ec0\u4e48\u8981\u914d\u7f6e\u4e24\u6b21. \u5176\u5b9e\u662f\u56e0\u4e3a Tailscale \u7f51\u7edc\u7684 P2P \u96f6\u4fe1\u4efb\u7684\u7279\u6027, \u5c06\u8282\u70b9\u72b6\u6001\u7684\u5ba3\u544a\u548c\u627f\u8ba4\u5206\u5f00\u4e86. \u5ba3\u544a\u662f\u8282\u70b9\u5c06\u81ea\u5df1\u7684\u8def\u7531\u4fe1\u606f\u544a\u8bc9 Tailscale \u7f51\u7edc, \u800c\u627f\u8ba4\u662f Tailscale \u7f51\u7edc\u627f\u8ba4\u8fd9\u4e2a\u4fe1\u606f, \u7136\u540e\u5c06\u8fd9\u4e2a\u8282\u70b9\u5ba3\u544a\u7684\u8def\u7531\u4fe1\u606f\u901a\u77e5\u7ed9\u7f51\u7edc\u4e2d\u7684\u5176\u4ed6\u8282\u70b9, \u6240\u4ee5\u9700\u8981\u5728\u8282\u70b9\u548c Tailscale \u7ba1\u7406\u9875\u9762\u4e0a\u90fd\u914d\u7f6e\u4e00\u6b21.<\/p>\n<h2 id=\"pei-zhi-openwrt-shang-de-fang-huo-qiang\"><a class=\"zola-anchor\" href=\"#pei-zhi-openwrt-shang-de-fang-huo-qiang\" aria-label=\"Anchor link for: pei-zhi-openwrt-shang-de-fang-huo-qiang\">\u914d\u7f6e OpenWrt \u4e0a\u7684\u9632\u706b\u5899<\/a><\/h2>\n<p>\u8fd9\u91cc\u53ef\u4ee5\u5728 LuCI Web \u7ba1\u7406\u754c\u9762\u4e2d\u770b\u5230 \u670d\u52a1 -&gt; Tailscale \u9009\u9879\u5361\u4e2d, \u70b9\u51fb <code>\u81ea\u52a8\u914d\u7f6e\u9632\u706b\u5899<\/code>, \u4f1a\u6dfb\u52a0 lan =&gt; tailscale \u548c tailscale =&gt; lan \u8fd9\u4e9b\u533a\u57df\u8f6c\u53d1\u89c4\u5219; \u7136\u800c\u7531\u4e8e\u4e0a\u9762\u6211\u4eec\u914d\u7f6e\u4e86 <code>\u901a\u544a\u51fa\u53e3\u8282\u70b9<\/code>, \u6240\u4ee5\u8fd8\u9700\u8981\u6dfb\u52a0\u4ee5\u4e0b\u89c4\u5219<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>uci add firewall forwarding<\/span><\/span>\n<span class=\"giallo-l\"><span>uci set firewall.@forwarding[-1].src=&#39;tailscale&#39;<\/span><\/span>\n<span class=\"giallo-l\"><span>uci set firewall.@forwarding[-1].dest=&#39;wan&#39;<\/span><\/span>\n<span class=\"giallo-l\"><span>uci commit firewall<\/span><\/span>\n<span class=\"giallo-l\"><span>\/etc\/init.d\/firewall restart<\/span><\/span><\/code><\/pre>\n<p>\u8fd9\u6837\u5141\u8bb8\u6d41\u91cf\u4ece Tailscale \u7f51\u7edc\u4e2d\u901a\u8fc7\u8282\u70b9\u8bbf\u95ee\u516c\u7f51, \u5b9e\u73b0\u6d41\u91cf\u51fa\u53e3\u4ee3\u7406.<\/p>\n<h2 id=\"qi-ta-zhu-yi-shi-xiang\"><a class=\"zola-anchor\" href=\"#qi-ta-zhu-yi-shi-xiang\" aria-label=\"Anchor link for: qi-ta-zhu-yi-shi-xiang\">\u5176\u4ed6\u6ce8\u610f\u4e8b\u9879<\/a><\/h2>\n<ul>\n<li>\u901a\u5e38\u9700\u8981\u5728 OpenWrt \u4e0a\u5f00\u542f IP forwarding, MASQUERADE \u548c MSS \u94b3\u5236, \u4ee5\u786e\u4fdd Tailscale \u7f51\u7edc\u4e2d\u7684\u6d41\u91cf\u53ef\u4ee5\u6b63\u5e38\u8f6c\u53d1\u548c\u8def\u7531. \u4e00\u822c\u6765\u8bf4 Tailscale \u5ba2\u6237\u7aef\u548c <code>\u81ea\u52a8\u914d\u7f6e\u9632\u706b\u5899<\/code> \u4f1a\u81ea\u52a8\u5904\u7406\u8fd9\u4e9b\u914d\u7f6e. \u7f51\u7edc\u5f02\u5e38\u65f6\u53ef\u4ee5\u68c0\u67e5\u8fd9\u4e9b\u914d\u7f6e.<\/li>\n<li>\u5185\u7f51\u7f51\u6bb5\u5982\u679c\u51b2\u7a81\u4e86, \u53ef\u4ee5\u5728 OpenWrt \u4e0a\u4fee\u6539\u5bf9\u5e94\u7684 DHCP \u914d\u7f6e.<\/li>\n<li>\u7531\u4e8e\u8c03\u6574\u4e86\u8f83\u591a\u7684\u7f51\u7edc\u73af\u5883, \u6bd4\u5982\u9632\u706b\u5899, \u8def\u7531\u7b49, \u5c31\u4e0d\u5efa\u8bae\u518d\u5957\u7528\u5176\u4ed6\u7684\u7f51\u7edc\u5e94\u7528, \u6bd4\u5982\u53bb\u5e7f\u544a\u7b49\u529f\u80fd, \u53ef\u80fd\u4f1a\u5bfc\u81f4\u51b2\u7a81.<\/li>\n<\/ul>\n"},{"title":"AI: \u521b\u65b0\u5373\u590d\u53e4","published":"2026-01-11T22:47:18+09:00","updated":"2026-07-30T12:41:51+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/ai-innovation-is-retro\/"}},"id":"https:\/\/memwey.github.io\/posts\/ai-innovation-is-retro\/","content":"<p>\u5728 LLM \u76f8\u5173\u7684\u4e1c\u897f\u4e0a\u6298\u817e\u4e86\u4e00\u6bb5\u65f6\u95f4\u4e4b\u540e, \u6211\u6700\u5f3a\u70c8\u7684\u4e00\u4e2a\u611f\u53d7\u4e0d\u662f\"\u672a\u6765\u6765\u4e86\", \u800c\u662f\"\u8fd9\u4e2a\u6211\u597d\u50cf\u5728\u54ea\u89c1\u8fc7\". \u6bcf\u9694\u4e00\u9635\u5b50\u5c31\u6709\u4e00\u4e2a\u542c\u8d77\u6765\u5f88\u65b0\u7684\u540d\u8bcd\u5192\u51fa\u6765, \u7ffb\u5f00\u62a5\u6587\u4e00\u770b, \u91cc\u9762\u8eba\u7740\u7684\u662f\u4e00\u4e2a\u4e09\u5341\u5e74\u524d\u7684\u4e1c\u897f.<\/p>\n<p>\u4e0b\u9762\u4e09\u4e2a\u4f8b\u5b50, \u662f\u6211\u8bb0\u5728\u5907\u5fd8\u5f55\u91cc\u7684\u4e09\u6761\u6bb5\u5b50.<\/p>\n<h2 id=\"sse-na-wo-zou\"><a class=\"zola-anchor\" href=\"#sse-na-wo-zou\" aria-label=\"Anchor link for: sse-na-wo-zou\">SSE: \u90a3\u6211\u8d70?<\/a><\/h2>\n<p><code>Server-Sent Events<\/code> \u662f 2000 \u5e74\u4ee3\u4e2d\u671f\u7684\u4ea7\u7269, \u672c\u8d28\u662f\u5728\u4e00\u4e2a\u8fdf\u8fdf\u4e0d\u7ed3\u675f\u7684 HTTP \u54cd\u5e94\u91cc\u6301\u7eed\u53d1\u9001\u6587\u672c\u4e8b\u4ef6. HTTP\/1.1 \u4e0b\u5e38\u89c1\u7684\u5b9e\u73b0\u662f <code>chunked transfer encoding<\/code> (1997), \u5230\u4e86 HTTP\/2 \u548c HTTP\/3 \u5219\u8fde chunked \u8fd9\u5c42\u90fd\u6ca1\u6709\u4e86. \u683c\u5f0f\u7b80\u5355\u5230\u6709\u70b9\u5bd2\u9178:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>data: {&quot;choices&quot;:[{&quot;delta&quot;:{&quot;content&quot;:&quot;\u4f60&quot;}}]}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>data: [DONE]<\/span><\/span><\/code><\/pre>\n<p><code>WebSocket<\/code> \u51fa\u73b0\u4e4b\u540e, SSE \u57fa\u672c\u88ab\u5f52\u5165\"\u8fc7\u6e21\u65b9\u6848\"\u4e00\u7c7b: \u53ea\u80fd\u670d\u52a1\u7aef\u5f80\u5ba2\u6237\u7aef\u5355\u5411\u63a8, \u524d\u7aef\u6559\u7a0b\u91cc\u901a\u5e38\u4e00\u7b14\u5e26\u8fc7, \u8fd8\u9644\u5e26\u4e00\u6761\u5e7f\u4e3a\u6d41\u4f20\u7684\u9650\u5236 - HTTP\/1.1 \u4e0b\u540c\u57df\u540d\u6700\u591a 6 \u4e2a\u8fde\u63a5, \u5f00\u51e0\u4e2a\u9875\u7b7e\u5c31\u7528\u5b8c\u4e86.<\/p>\n<p>\u7ed3\u679c LLM \u6765\u4e86. \u9010 <code>token<\/code> \u8f93\u51fa\u7684\u6253\u5b57\u673a\u6548\u679c, \u6070\u597d\u5c31\u662f\"\u670d\u52a1\u7aef\u5355\u5411\u63a8\u4e00\u4e32\u6587\u672c\"\u8fd9\u4e00\u4e2a\u9700\u6c42, \u4e00\u70b9\u4e0d\u591a, \u4e00\u70b9\u4e0d\u5c11. OpenAI \u7684 <code>stream=true<\/code> \u7528 SSE, Anthropic \u7528 SSE, \u51e0\u4e4e\u6240\u6709\u63a8\u7406\u670d\u52a1\u7684\u6d41\u5f0f\u63a5\u53e3\u90fd\u662f SSE, <del>\u7136\u540e\u5404\u5bb6\u5728\u89e3\u6790 <code>data:<\/code> \u884c\u7684\u65f6\u5019\u5404\u8e29\u5404\u7684\u5751<\/del>.<\/p>\n<p>\u4e3a\u4ec0\u4e48\u4e0d\u662f WebSocket? \u56e0\u4e3a\u5bf9\u4e8e\"\u4e00\u6b21\u8bf7\u6c42\u6362\u4e00\u4e32 token\"\u6765\u8bf4, \u8981\u4ed8\u7684\u4ee3\u4ef7\u6709\u70b9\u5927:<\/p>\n<ul>\n<li>\u9700\u8981 <code>Upgrade: websocket<\/code> \u534f\u8bae\u5347\u7ea7, \u94fe\u8def\u4e0a\u7684 CDN, \u8d1f\u8f7d\u5747\u8861, \u4f01\u4e1a\u4ee3\u7406, API \u7f51\u5173\u90fd\u5f97\u5355\u72ec\u652f\u6301<\/li>\n<li>\u63e1\u624b\u4ecd\u7136\u662f HTTP, \u4f46\u5347\u7ea7\u4e4b\u540e\u4e0d\u518d\u6709\u4e00\u95ee\u4e00\u7b54\u7684\u8bf7\u6c42\u8bed\u4e49; \u9274\u6743, \u9519\u8bef\u7801, \u91cd\u8bd5, \u9650\u6d41\u548c\u53ef\u89c2\u6d4b\u6027\u90fd\u8981\u6620\u5c04\u5230\u957f\u8fde\u63a5\u91cc\u7684\u5e94\u7528\u4e8b\u4ef6<\/li>\n<li>WebSocket \u5df2\u7ecf\u5b9a\u4e49\u4e86\u6d88\u606f\u8fb9\u754c\u548c Ping\/Pong, \u4f46\u4e1a\u52a1\u6d88\u606f, \u5e8f\u5217\u5316, \u91cd\u8fde\u548c\u65ad\u70b9\u6062\u590d\u4ecd\u7136\u8981\u81ea\u5df1\u5b9a\u4e49<\/li>\n<li>\u5982\u679c\u8fde\u63a5\u627f\u8f7d\u4e86\u4f1a\u8bdd\u72b6\u6001, \u670d\u52a1\u7aef\u6269\u7f29\u5bb9\u65f6\u8fd8\u8981\u8003\u8651\u8fde\u63a5\u8fc1\u79fb, \u4eb2\u548c\u6027\u548c\u6062\u590d<\/li>\n<\/ul>\n<p>\u800c SSE \u5c31\u662f\u4e00\u4e2a\u8fdf\u8fdf\u4e0d\u7ed3\u675f\u7684\u666e\u901a\u54cd\u5e94, <code>Content-Type: text\/event-stream<\/code>, \u5176\u4f59\u4e00\u5207\u7167\u65e7. \u9700\u6c42\u7684\u5f62\u72b6\u5bf9\u4e0a\u4e86, \u65e7\u6280\u672f\u5c31\u8d62\u4e86\u4e00\u5c40.<\/p>\n<p>\u4e0d\u8fc7\u8981\u8bf4\u6e05\u695a, SSE \u8d62\u7684\u662f\u90e8\u7f72\u6210\u672c, \u4e0d\u662f\u5929\u7136\u66f4\u53ef\u9760. \u6240\u6709\u957f\u8fde\u63a5\u90fd\u6709\u4e00\u4e2a\u5f88\u8ba8\u538c\u7684\u6027\u8d28: <strong>\u6ca1\u6709\u5e94\u7528\u5c42\u5fc3\u8df3\u65f6, \u5ba2\u6237\u7aef\u5206\u4e0d\u6e05\"\u670d\u52a1\u7aef\u5728\u60f3\"\u548c\"\u8fde\u63a5\u5df2\u7ecf\u6b7b\u4e86\"<\/strong>. \u4e00\u4e2a\u6b63\u5728\u751f\u6210\u7684\u6d41, \u548c\u4e00\u4e2a TCP \u8def\u5f84\u5df2\u7ecf\u65ad\u6389\u4f46 socket \u8fd8\u6302\u7740\u7684\u6d41, \u4ece\u5ba2\u6237\u7aef\u770b\u90fd\u53ef\u80fd\u662f\"\u6253\u5f00\u7740, \u4f46\u6ca1\u6709\u65b0\u5b57\u8282\". NAT \u8868\u9879\u8d85\u65f6, \u79fb\u52a8\u7f51\u7edc\u5207\u6362, \u8d1f\u8f7d\u5747\u8861\u56de\u6536\u7a7a\u95f2\u8fde\u63a5, \u90fd\u53ef\u80fd\u8ba9\u6545\u969c\u4e0d\u80fd\u7acb\u523b\u66b4\u9732, \u800c TCP \u81ea\u5df1\u7684\u8d85\u65f6\u53c8\u5f88\u6162.<\/p>\n<p>\u90a3\u540e\u6765\u662f\u600e\u4e48\u8865\u56de\u6765\u7684? \u5fc3\u8df3, \u4e8b\u4ef6\u5e8f\u53f7, \u65ad\u70b9\u7eed\u4f20. OpenAI \u7684 <code>background<\/code> \u914d\u5408 <code>starting_after<\/code> \u5c31\u662f\u8ba9\u5ba2\u6237\u7aef\u8bb0\u4f4f\u6bcf\u4e2a\u4e8b\u4ef6\u7684 <code>sequence_number<\/code>, \u65ad\u7ebf\u4e4b\u540e\u62ff\u7740\u6e38\u6807\u4ece\u65ad\u70b9\u7ee7\u7eed\u6536. \u800c\u8fd9\u4e09\u6837\u4e1c\u897f, \u6070\u597d\u5c31\u662f\u5f53\u5e74\u5927\u5bb6\u5acc WebSocket \u9ebb\u70e6, \u4e0d\u613f\u610f\u81ea\u5df1\u5199\u7684\u90a3\u4e00\u5957.<\/p>\n<p>\u9700\u6c42\u7684\u5f62\u72b6\u4e5f\u8fd8\u4f1a\u7ee7\u7eed\u53d8. 2024 \u5e74 5 \u6708\u524d\u540e, \u6709\u7528\u6237\u89c2\u5bdf\u5230 ChatGPT \u7f51\u9875\u7aef\u5f00\u59cb\u4f7f\u7528 WebSocket, \u4e00\u6279\u4f9d\u8d56\u65e7 SSE \u884c\u4e3a\u7684\u7b2c\u4e09\u65b9\u5ba2\u6237\u7aef\u5f53\u573a\u5931\u6548. \u81f3\u4e8e\u4e3a\u4ec0\u4e48\u5207, OpenAI \u6ca1\u6709\u7ed9\u8fd9\u6b21\u524d\u7aef\u53d8\u5316\u5199\u4e00\u7bc7\u67b6\u6784\u590d\u76d8, \u4e0b\u9762\u53ea\u80fd\u7b97\u662f\u63a8\u6d4b: ChatGPT \u65e9\u5c31\u4e0d\u662f\"\u4e00\u6b21\u8bf7\u6c42\u6362\u4e00\u4e32 token\"\u4e86 - \u4e2d\u65ad\u751f\u6210, \u5de5\u5177\u5ba1\u6279, \u8bed\u97f3, \u591a\u4efb\u52a1\u5e76\u884c, \u5207\u8d70\u518d\u5207\u56de\u6765\u5185\u5bb9\u8fd8\u5728\u7ee7\u7eed\u540c\u6b65. \u670d\u52a1\u7aef\u8fd8\u8981\u63a8\u9001\u4e00\u4e9b<strong>\u4e0d\u5c5e\u4e8e\u5f53\u524d\u751f\u6210\u8bf7\u6c42<\/strong>\u7684\u4e8b\u4ef6, \u6bd4\u5982\"\u53e6\u4e00\u4e2a\u5bf9\u8bdd\u91cc\u7684\u540e\u53f0\u4efb\u52a1\u8dd1\u5b8c\u4e86\".<\/p>\n<p>SSE \u5e76\u4e0d\u662f\u4e0d\u80fd\u4f20\u8fd9\u79cd\u4e8b\u4ef6. \u5b8c\u5168\u53ef\u4ee5\u5355\u72ec\u5f00\u4e00\u6761\u7528\u6237\u7ea7\u4e8b\u4ef6\u6d41, \u518d\u7528 POST \u53d1\u9001\u4e0a\u884c\u6d88\u606f, \u5f53\u5e74\u7684 MCP <code>HTTP+SSE<\/code> \u5c31\u662f\u8fd9\u4e48\u5e72\u7684. \u53ea\u662f\u5230\u4e86\u8fd9\u4e00\u6b65, \u4f60\u5df2\u7ecf\u6709\u4e86\u4e24\u6761\u901a\u9053, \u4f1a\u8bdd\u6807\u8bc6, \u4e8b\u4ef6\u5173\u8054\u548c\u65ad\u7ebf\u6062\u590d, \u8d8a\u6765\u8d8a\u50cf\u662f\u5728 HTTP \u4e0a\u62fc\u51fa\u4e00\u4e2a WebSocket.<\/p>\n<p>\u6240\u4ee5\u771f\u6b63\u7684\u5206\u754c\u7ebf\u4e0d\u662f\"\u8981\u4e0d\u8981\u6d41\u5f0f\", \u751a\u81f3\u4e5f\u4e0d\u662f SSE \"\u80fd\u4e0d\u80fd\u505a\", \u800c\u662f<strong>\u4e0a\u884c\u4e8b\u4ef6\u662f\u5426\u72ec\u7acb, \u9891\u7e41\u5230\u503c\u5f97\u7ef4\u62a4\u4e00\u6761\u5171\u4eab\u7684\u5168\u53cc\u5de5\u901a\u9053<\/strong>. \u5355\u4e2a\u8bf7\u6c42\u7684\u8f93\u51fa\u6d41, SSE \u8d62, \u56e0\u4e3a\u5b83\u51e0\u4e4e\u4e0d\u589e\u52a0\u6210\u672c; \u4e2d\u65ad, \u5ba1\u6279\u548c\u5e76\u884c\u4efb\u52a1\u8d8a\u6765\u8d8a\u591a\u65f6, WebSocket \u7684\u6a21\u578b\u5f00\u59cb\u66f4\u81ea\u7136.<\/p>\n<p>Codex \u7684 <code>app-server<\/code> \u5219\u662f\u751f\u4e0b\u6765\u5c31\u5728\u4f1a\u8bdd\u8fd9\u4e00\u4fa7. VS Code \u6269\u5c55\u8fd9\u7c7b\u5bcc\u5ba2\u6237\u7aef\u8dd1\u5728\u5b83\u4e0a\u9762, \u9ed8\u8ba4\u4f20\u8f93\u662f\u672c\u5730 <code>stdio<\/code>; \u8fdc\u7a0b TUI \u8fd8\u53ef\u4ee5\u5b9e\u9a8c\u6027\u5730\u4f7f\u7528 WebSocket, \u975e\u672c\u5730\u8fde\u63a5\u518d\u52a0 TLS \u548c bearer token. \u5b83\u8981\u4f20\u7684\u4e1c\u897f\u6839\u672c\u4e0d\u662f\u4e00\u4e32\u6587\u672c: \u5ba2\u6237\u7aef\u968f\u65f6\u53ef\u80fd\u53d1\u4e2d\u65ad, \u670d\u52a1\u7aef\u968f\u65f6\u53ef\u80fd\u53cd\u95ee\"\u8fd9\u6761\u547d\u4ee4\u5141\u8bb8\u6267\u884c\u5417\", \u4e2d\u95f4\u8fd8\u5939\u7740\u5de5\u5177\u8c03\u7528, \u5ba1\u6279\u8bf7\u6c42\u548c\u6c99\u7bb1\u72b6\u6001. \u7528 SSE \u52a0 POST \u5f53\u7136\u4e5f\u80fd\u62fc, \u53ea\u662f\u4ece\u7b2c\u4e00\u5929\u5c31\u4e0d\u592a\u5212\u7b97.<\/p>\n<p>\u6240\u4ee5 WebSocket \u88ab\u91cd\u65b0\u62ff\u8d77\u6765, \u4e0d\u662f\u56e0\u4e3a SSE \u4e0d\u597d\u7528, \u800c\u662f\u56e0\u4e3a Agent \u628a\"\u804a\u5929\"\u91cd\u65b0\u53d8\u6210\u4e86\"\u4f1a\u8bdd\". \u4ea4\u4e92\u91cc\u6709\u4e2d\u65ad, \u6709\u5ba1\u6279, \u6709\u5e76\u884c\u4efb\u52a1\u6c47\u62a5\u65f6, \u5355\u5411\u54cd\u5e94\u6d41\u4ecd\u7136\u80fd\u505a, \u4f46\u4e0d\u518d\u662f\u6700\u7701\u4e8b\u7684\u505a\u6cd5.<\/p>\n<blockquote>\n<p>\u6362\u4e2a\u89d2\u5ea6\u8bf4, \"\u590d\u53e4\"\u4e0d\u662f\u7ec8\u70b9, \u662f\u949f\u6446. \u957f\u8f6e\u8be2 -&gt; SSE -&gt; WebSocket \u8fd9\u4e2a\u5faa\u73af\u4e8c\u5341\u5e74\u524d\u8d70\u8fc7\u4e00\u904d\u4e86, LLM \u53ea\u662f\u8ba9\u5b83\u91cd\u65b0\u8d70\u4e00\u904d, \u800c\u4e14\u5feb\u5f97\u591a. \u81f3\u4e8e\u5b9e\u65f6\u8bed\u97f3\u90a3\u79cd\u4f4e\u5ef6\u8fdf, \u5e26\u4e8c\u8fdb\u5236\u97f3\u9891\u6d41\u7684\u573a\u666f, \u5219\u4ece\u5934\u5230\u5c3e\u90fd\u662f WebSocket \u548c <code>WebRTC<\/code> \u7684\u5730\u76d8.<\/p>\n<\/blockquote>\n<h2 id=\"402-shui-liao-san-shi-nian-de-zhuang-tai-ma\"><a class=\"zola-anchor\" href=\"#402-shui-liao-san-shi-nian-de-zhuang-tai-ma\" aria-label=\"Anchor link for: 402-shui-liao-san-shi-nian-de-zhuang-tai-ma\">402: \u7761\u4e86\u4e09\u5341\u5e74\u7684\u72b6\u6001\u7801<\/a><\/h2>\n<p>HTTP \u72b6\u6001\u7801\u8868\u91cc\u4e00\u76f4\u6709\u4e2a\u5c34\u5c2c\u7684\u7a7a\u4f4d: <code>402 Payment Required<\/code>. \u5b83\u4ece <code>RFC 2068<\/code> (1997) \u8d77\u5c31\u5728\u90a3\u4e86, \u89c4\u8303\u91cc\u7684\u8bf4\u660e\u5927\u610f\u662f\"\u4fdd\u7559, \u4f9b\u5c06\u6765\u4f7f\u7528\", \u4e8e\u662f\u5b83\u5c31\u4e00\u76f4\"\u5c06\u6765\"\u4e86\u5c06\u8fd1\u4e09\u5341\u5e74, \u6210\u4e86\u6240\u6709\u4eba\u90fd\u89c1\u8fc7, \u4f46\u4ece\u6765\u6ca1\u4eba\u771f\u6b63\u8fd4\u56de\u8fc7\u7684\u90a3\u4e00\u6761.<\/p>\n<p>\u5b83\u7684\u539f\u59cb\u8bbe\u60f3\u662f 90 \u5e74\u4ee3\u7684\u6570\u5b57\u73b0\u91d1\u4e0e\u5fae\u652f\u4ed8 (<code>DigiCash<\/code>, <code>Millicent<\/code> \u4e4b\u7c7b), \u800c\u8fd9\u6761\u8def\u7ebf\u5f7b\u5e95\u5931\u8d25\u4e86, \u4e92\u8054\u7f51\u6700\u540e\u9009\u4e86\u53e6\u5916\u4e24\u4e2a\u7b54\u6848: \u5e7f\u544a\u548c\u8ba2\u9605. \u5fae\u652f\u4ed8\u7684\u95ee\u9898\u4ece\u6765\u4e0d\u5728\u6280\u672f: \u4e3a\u4e86 0.001 \u7f8e\u5143\u8d70\u4e00\u6b21\u6388\u6743\u6d41\u7a0b, \u7528\u6237\u7684\u5fc3\u667a\u6210\u672c\u8fdc\u5927\u4e8e\u91d1\u989d\u672c\u8eab, \u66f4\u522b\u63d0\u652f\u4ed8\u7f51\u7edc\u81ea\u5df1\u7684\u624b\u7eed\u8d39\u4e0b\u9650.<\/p>\n<p>\u7136\u540e <a rel=\"external\" href=\"https:\/\/x402.org\/\">x402<\/a> \u51fa\u73b0\u4e86, Coinbase \u5728 2025 \u5e74\u63a8\u51fa, 2026 \u5e74\u8fdb\u4e86 Linux Foundation. \u6d41\u7a0b\u6734\u7d20\u5f97\u50cf\u6559\u79d1\u4e66\u4f8b\u5b50:<\/p>\n<ol>\n<li>\u5ba2\u6237\u7aef\u8bf7\u6c42\u8d44\u6e90<\/li>\n<li>\u670d\u52a1\u7aef\u8fd4\u56de <code>402<\/code>, \u5e76\u901a\u8fc7 <code>PAYMENT-REQUIRED<\/code> \u5e26\u4e0a\u652f\u4ed8\u8981\u6c42 (scheme, \u7f51\u7edc, \u8d44\u4ea7, \u91d1\u989d, \u6536\u6b3e\u65b9)<\/li>\n<li>\u5ba2\u6237\u7aef\u9009\u4e00\u79cd\u652f\u4ed8\u8981\u6c42, \u7b7e\u4e00\u7b14\u8f6c\u8d26\u6388\u6743, \u5e26\u4e0a <code>PAYMENT-SIGNATURE<\/code> \u91cd\u53d1\u540c\u4e00\u4e2a\u8bf7\u6c42<\/li>\n<li>\u670d\u52a1\u7aef\u81ea\u5df1\u6216\u901a\u8fc7 <code>facilitator<\/code> \u9a8c\u8bc1\u5e76\u7ed3\u7b97, \u8fd4\u56de 200 \u548c <code>PAYMENT-RESPONSE<\/code><\/li>\n<\/ol>\n<p>\u65e9\u671f x402 v1 \u7684\u8bf7\u6c42\u5934\u53eb <code>X-PAYMENT<\/code> \u548c <code>X-PAYMENT-RESPONSE<\/code>, \u5230 v2 \u53c8\u628a\u540d\u5b57\u6539\u6210\u4e86\u4e0a\u9762\u8fd9\u4e00\u5957. <del>\u534f\u8bae\u590d\u53e4, \u8bf7\u6c42\u5934\u5012\u662f\u65b0\u5f97\u5f88\u5feb<\/del>.<\/p>\n<p>\u4e3a\u4ec0\u4e48\u73b0\u5728\u6210\u7acb\u4e86? \u56e0\u4e3a\u4ed8\u94b1\u7684\u90a3\u4e00\u65b9\u6362\u4eba\u4e86. \u5fae\u652f\u4ed8\u5bf9\u4eba\u7c7b\u662f\u9a9a\u6270, \u5bf9 Agent \u662f\u4e00\u6b21\u51fd\u6570\u8c03\u7528. Agent \u4e0d\u4f1a\u4e3a\"\u8981\u4e0d\u8981\u82b1 0.002 \u7f8e\u5143\u67e5\u4e00\u6b21\u8fd9\u4e2a API\"\u72b9\u8c6b\u4e09\u79d2, \u4e5f\u4e0d\u9700\u8981\u586b\u4fe1\u7528\u5361\u8868\u5355, \u66f4\u4e0d\u4f1a\u56e0\u4e3a\u591a\u4e00\u6b65\u786e\u8ba4\u5c31\u6d41\u5931. \u9700\u6c42\u65b9\u4ece\"\u4e0d\u8010\u70e6\u7684\u4eba\"\u53d8\u6210\u4e86\"\u6309\u9884\u7b97\u6267\u884c\u7684\u7a0b\u5e8f\", \u90a3\u4e2a\u7a7a\u7f6e\u4e09\u5341\u5e74\u7684\u72b6\u6001\u7801\u5c31\u7a81\u7136\u6709\u4e86\u4e3b\u4eba.<\/p>\n<blockquote>\n<p>\u540c\u7c7b\u7684\u8fd8\u6709 <code>L402<\/code> (Lightning Network \u52a0 macaroon) \u548c Google \u7684 <code>AP2<\/code>. \u987a\u4fbf\u8bf4, \u7ed3\u7b97\u624b\u6bb5\u662f\u4e0d\u662f\u52a0\u5bc6\u8d27\u5e01\u548c 402 \u672c\u8eab\u65e0\u5173, 402 \u53ea\u662f\u90a3\u4e2a\u4fe1\u5c01.<\/p>\n<\/blockquote>\n<h2 id=\"mcp-qing-jiao-wo-rpc\"><a class=\"zola-anchor\" href=\"#mcp-qing-jiao-wo-rpc\" aria-label=\"Anchor link for: mcp-qing-jiao-wo-rpc\">MCP: \u8bf7\u53eb\u6211 RPC<\/a><\/h2>\n<p><code>Model Context Protocol<\/code> \u542c\u8d77\u6765\u5f88\u65b0, \u6253\u5f00\u62a5\u6587\u4e00\u770b: <code>jsonrpc: \"2.0\"<\/code>, <code>method<\/code>, <code>params<\/code>, <code>id<\/code>. \u4e5f\u5c31\u662f JSON-RPC 2.0, 2010 \u5e74\u7684\u4e1c\u897f, \u800c RPC \u8fd9\u4e2a\u6982\u5ff5\u672c\u8eab\u8981\u8ffd\u5230 1980 \u5e74\u4ee3.<\/p>\n<p>REST \u548c GraphQL \u5728 <code>tools\/call<\/code> \u9762\u524d\u57fa\u672c\u6ca1\u6709\u4f4d\u7f6e, \u8fd9\u4ef6\u4e8b\u633a\u8bbd\u523a\u7684. \u8fc7\u53bb\u5341\u51e0\u5e74\u540e\u7aef\u5708\u82b1\u4e86\u5927\u91cf\u53e3\u6c34\u8bba\u8bc1\"\u4e0d\u8981 RPC \u98ce\u683c\u7684\u63a5\u53e3\": \u8981\u8d44\u6e90\u4e0d\u8981\u52a8\u4f5c, \u8981\u6b63\u786e\u7684 URI \u8bed\u4e49, \u8981 HATEOAS, \u8981\u8ba9\u5ba2\u6237\u7aef\u7528 GraphQL \u81ea\u5df1\u6311\u5b57\u6bb5. \u7ed3\u679c\u6700\u7ec8\u7684\u5ba2\u6237\u7aef\u662f\u4e2a\u5927\u8bed\u8a00\u6a21\u578b, \u800c\u5b83\u60f3\u8981\u7684\u4e1c\u897f\u662f:<\/p>\n<ul>\n<li>\u4e00\u4efd\u5e26\u81ea\u7136\u8bed\u8a00\u63cf\u8ff0\u7684\u51fd\u6570\u6e05\u5355 (<code>tools\/list<\/code>)<\/li>\n<li>\u4e00\u4efd JSON Schema \u58f0\u660e\u7684\u53c2\u6570 (<code>inputSchema<\/code>)<\/li>\n<li>\u8c03\u4e00\u4e0b, \u62ff\u7ed3\u679c (<code>tools\/call<\/code>)<\/li>\n<\/ul>\n<p>\u8fd9\u662f\u6700\u6734\u7d20\u7684\"\u8fc7\u7a0b\u8c03\u7528\u52a0\u63a5\u53e3\u5b9a\u4e49\". <code>JSON Schema<\/code> \u91cd\u65b0\u627f\u62c5\u4e86\u8fc7\u53bb IDL \u91cc\"\u53c2\u6570\u5951\u7ea6\"\u7684\u90a3\u4e00\u90e8\u5206; WSDL \u8fd8\u7ba1\u6d88\u606f, \u7ed1\u5b9a\u548c\u7aef\u70b9, MCP \u6ca1\u6709\u628a\u90a3\u6574\u5957 XML \u5927\u6559\u5802\u642c\u56de\u6765, <del>WSDL: \u6211\u53ea\u662f\u6b7b\u65e9\u4e86<\/del>. \u66f4\u91cd\u8981\u7684\u533a\u522b\u5728\u4e8e, \u8fc7\u53bb\u7684 IDL \u4e3b\u8981\u5199\u7ed9\u7f16\u8bd1\u5668\u770b, \u73b0\u5728\u8fd8\u8981\u5199\u7ed9\u6a21\u578b\u770b, \u6240\u4ee5\u63cf\u8ff0\u5b57\u6bb5\u91cc\u585e\u7684\u662f\u4eba\u8bdd.<\/p>\n<p>\u4f20\u8f93\u5c42\u7684\u6f14\u5316\u4e5f\u5f88\u6709\u610f\u601d: <code>2024-11-05<\/code> \u7248\u672c\u662f <code>stdio<\/code> \u52a0 <code>HTTP+SSE<\/code> \u53cc\u7aef\u70b9, <code>2025-03-26<\/code> \u7248\u672c\u6362\u6210\u4e86 <code>Streamable HTTP<\/code>, \u628a POST \u548c GET \u6536\u5230\u540c\u4e00\u4e2a endpoint \u4e0a; POST \u54cd\u5e94\u53ef\u4ee5\u662f <code>application\/json<\/code>, \u4e5f\u53ef\u4ee5\u662f <code>text\/event-stream<\/code>, GET \u5219\u53ef\u4ee5\u5355\u72ec\u6253\u5f00\u4e00\u6761 SSE \u6d41. \u800c\u672c\u5730 MCP Server \u5230\u4eca\u5929\u6700\u4e3b\u6d41\u7684\u65b9\u5f0f\u4ecd\u7136\u662f <code>stdio<\/code> - \u5728\u6807\u51c6\u8f93\u5165\u8f93\u51fa\u4e0a\u8dd1\u4e00\u4e2a\u6309\u884c\u5206\u9694\u7684\u6587\u672c\u534f\u8bae, \u8fd9\u662f Unix \u7ba1\u9053\u65f6\u4ee3\u7684\u505a\u6cd5.<\/p>\n<h2 id=\"bu-zhi-shi-xie-yi\"><a class=\"zola-anchor\" href=\"#bu-zhi-shi-xie-yi\" aria-label=\"Anchor link for: bu-zhi-shi-xie-yi\">\u4e0d\u53ea\u662f\u534f\u8bae<\/a><\/h2>\n<p>\u628a\u8303\u56f4\u653e\u5f00\u4e00\u70b9, \u4f1a\u53d1\u73b0 AI \u65f6\u4ee3\u7684\"\u65b0\"\u4e1c\u897f\u91cc, \u590d\u53e4\u7684\u6bd4\u4f8b\u9ad8\u5f97\u60ca\u4eba.<\/p>\n<ul>\n<li><strong>\u795e\u7ecf\u7f51\u7edc\u672c\u8eab<\/strong>: \u611f\u77e5\u673a 1958, \u53cd\u5411\u4f20\u64ad 1986, LSTM 1997, \u6df7\u5408\u4e13\u5bb6 1991, \u6ce8\u610f\u529b\u4e0e Transformer 2017. Transformer \u5f53\u7136\u662f\u65b0\u60f3\u6cd5, \u4f46\u5b83\u7ad9\u5728\u4e00\u957f\u4e32\u51e0\u5ea6\u5931\u5ba0\u7684\u65e7\u60f3\u6cd5\u4e0a, \u6700\u540e\u518d\u9760\u7b97\u529b, \u6570\u636e\u548c\u5de5\u7a0b\u628a\u89c4\u6a21\u63a8\u4e86\u4e0a\u53bb. \u8fd9\u5927\u6982\u662f\"\u521b\u65b0\u5373\u590d\u53e4\"\u6700\u5927\u7684\u4e00\u4e2a\u4f8b\u5b50<\/li>\n<li><strong>\u547d\u4ee4\u884c<\/strong>: <code>Claude Code<\/code>, <code>Codex CLI<\/code>, <code>pi<\/code>, \u515c\u515c\u8f6c\u8f6c, \u76ee\u524d\u4f53\u611f\u6700\u5f3a\u7684 AI \u7f16\u7a0b\u754c\u9762\u4e4b\u4e00\u53c8\u662f\u7ec8\u7aef\u91cc\u7684 TUI. <code>pi<\/code> \u66f4\u5e72\u8106, \u9ed8\u8ba4\u53ea\u628a <code>read<\/code>, <code>write<\/code>, <code>edit<\/code>, <code>bash<\/code> \u56db\u4e2a\u5de5\u5177\u4ea4\u7ed9\u6a21\u578b, \u8fde <code>grep<\/code> \u548c <code>find<\/code> \u90fd\u53ef\u4ee5\u4ece shell \u91cc\u81ea\u5df1\u62ff. \u8fd9\u5957\u4e1c\u897f\u770b\u8d77\u6765\u4e0d\u50cf 2026 \u5e74\u7684 IDE, \u66f4\u50cf\u662f\u7ed9 Unix shell \u914d\u4e86\u4e00\u4e2a\u4f1a\u8bf4\u8bdd\u7684\u64cd\u4f5c\u5458. Unix \u54f2\u5b66\u91cc\u90a3\u53e5\"\u7eaf\u6587\u672c\u662f\u901a\u7528\u63a5\u53e3\"\u91cd\u65b0\u751f\u6548\u4e86, <del>\u987a\u4fbf\u5b83\u4e5f\u662f\u6700\u7701 token \u7684\u63a5\u53e3<\/del><\/li>\n<li><strong>\u8c03\u8bd5<\/strong>: IDE \u82b1\u4e86\u51e0\u5341\u5e74\u628a\u65ad\u70b9, \u6761\u4ef6\u65ad\u70b9, Watch \u548c\u5355\u6b65\u6267\u884c\u505a\u5f97\u8d8a\u6765\u8d8a\u7cbe\u7ec6, LLM \u5199\u4ee3\u7801\u65f6\u5374\u5f88\u5c11\u78b0\u5b83\u4eec, \u6700\u5e38\u7528\u7684\u8fd8\u662f <code>print<\/code>, \u65e5\u5fd7\u548c\u6d4b\u8bd5\u8f93\u51fa. \u539f\u56e0\u4e5f\u5f88\u6734\u7d20: \u8c03\u8bd5\u5668\u662f\u7ed9\u4eba\u76ef\u7740\u770b\u7684\u4ea4\u4e92\u754c\u9762, \u6587\u672c\u8f93\u51fa\u5219\u53ef\u4ee5\u76f4\u63a5\u585e\u8fdb\u4e0a\u4e0b\u6587, \u590d\u5236, \u641c\u7d22\u548c\u91cd\u653e. \u4e8e\u662f\u6700\u5148\u8fdb\u7684\u7f16\u7a0b\u6a21\u578b, \u53c8\u628a\u6211\u4eec\u5e26\u56de\u4e86 <code>printf debugging<\/code>, <del>\u51fa\u95ee\u9898\u5148\u6253\u4e24\u884c\u65e5\u5fd7, \u8fd9\u4e0b\u4eba\u548c AI \u5e73\u7b49\u4e86<\/del><\/li>\n<li><strong>\u7eaf\u6587\u672c\u4e0e\u914d\u7f6e\u6587\u4ef6<\/strong>: <code>README.md<\/code> \u548c <code>Makefile<\/code> \u7684\u4f4d\u7f6e\u88ab <code>AGENTS.md<\/code>, <code>CLAUDE.md<\/code> \u63a5\u4e86\u8fc7\u53bb, <code>robots.txt<\/code> \u6709\u4e86 <code>llms.txt<\/code> \u8fd9\u95e8\u4eb2\u621a, \u800c\u6587\u6863\u683c\u5f0f\u7684\u80dc\u5229\u8005\u662f 2004 \u5e74\u7684 Markdown<\/li>\n<li><strong>\u8ba1\u8d39\u4e0e\u8c03\u5ea6<\/strong>: \u6309 token \u8ba1\u8d39, \u6392\u961f, \u6279\u91cf\u4efb\u52a1\u6253\u4e94\u6298, \u9ad8\u5cf0\u9650\u6d41. \u8fd9\u662f\u5206\u65f6\u7cfb\u7edf\u6309 CPU \u65f6\u95f4\u6536\u8d39\u7684\u590d\u523b\u7248, GPU \u96c6\u7fa4\u5c31\u662f\u65b0\u7684\u5927\u578b\u673a, \u6211\u4eec\u53c8\u56de\u5230\u4e86\"\u628a\u4f5c\u4e1a\u63d0\u4ea4\u4e0a\u53bb\u7136\u540e\u7b49\"\u7684\u5e74\u4ee3<\/li>\n<li><strong>\u722c\u866b\u6218\u4e89<\/strong>: \u8bad\u7ec3\u6570\u636e\u5f15\u53d1\u7684 <code>robots.txt<\/code> \u4e4b\u4e89, \u7248\u6743\u8bc9\u8bbc\u4e0e\u53cd\u722c\u5bf9\u6297, \u548c\u4e8c\u5341\u5e74\u524d\u641c\u7d22\u5f15\u64ce\u65f6\u4ee3\u7684\u5267\u672c\u51e0\u4e4e\u9010\u5b57\u91cd\u6f14<\/li>\n<li><strong>\u591a\u667a\u80fd\u4f53<\/strong>: \u770b\u8d77\u6765\u5f88\u50cf\u662f\u628a Jira \u770b\u677f\u4ea4\u7ed9\u4e86\u7a0b\u5e8f. \u4e3b Agent \u628a\u76ee\u6807\u62c6\u6210 ticket, \u5206\u6d3e\u7ed9\u4e0d\u540c\u7684\u5b50 Agent; \u5b50 Agent \u66f4\u65b0\u72b6\u6001, \u7559\u4e0b\u7ed3\u679c, \u9047\u5230\u4f9d\u8d56\u5c31\u963b\u585e; \u6700\u540e\u518d\u7531\u4e3b Agent \u9a8c\u6536\u548c\u5173\u95ed. \u5e95\u4e0b\u5f53\u7136\u662f\u6d88\u606f\u4f20\u9012, \u4efb\u52a1\u961f\u5217\u548c\u5171\u4eab\u72b6\u6001, \u4f46\u4ece\u7ec4\u7ec7\u65b9\u5f0f\u6765\u770b, \u5b83\u590d\u523b\u7684\u66f4\u50cf\u529e\u516c\u5ba4\u91cc\u65e9\u5c31\u8dd1\u4e86\u51e0\u5341\u5e74\u7684\u5de5\u4f5c\u6d41, <del>\u73b0\u5728\u8fde\u5f00\u4f1a\u7684\u4eba\u4e5f\u7701\u4e86<\/del><\/li>\n<li><strong>\u65e0\u72b6\u6001\u4e0e\u6709\u72b6\u6001<\/strong>: \u7ecf\u5178 LLM \u63a5\u53e3\u6bcf\u6b21\u8bf7\u6c42\u628a\u5168\u90e8\u5386\u53f2\u91cd\u65b0\u5e26\u4e0a, \u8fd9\u662f\u5f7b\u5e95\u7684\u65e0\u72b6\u6001, \u5f88 REST, \u751a\u81f3\u5f88 CGI; \u540e\u6765 <code>prompt caching<\/code>, <code>previous_response_id<\/code> \u548c\u670d\u52a1\u7aef\u4f1a\u8bdd\u53c8\u628a\u72b6\u6001\u653e\u56de\u4e86\u670d\u52a1\u5668, \u4e8e\u662f\u4f1a\u8bdd\u5b58\u50a8\u548c\u4eb2\u548c\u6027\u8def\u7531\u4e5f\u4e00\u8d77\u56de\u6765\u4e86<\/li>\n<\/ul>\n<h2 id=\"wei-shen-me-hui-zhe-yang\"><a class=\"zola-anchor\" href=\"#wei-shen-me-hui-zhe-yang\" aria-label=\"Anchor link for: wei-shen-me-hui-zhe-yang\">\u4e3a\u4ec0\u4e48\u4f1a\u8fd9\u6837<\/a><\/h2>\n<p>\u4e0d\u662f\u56e0\u4e3a\u5927\u5bb6\u6000\u65e7, \u4e5f\u4e0d\u662f\u56e0\u4e3a\u6ca1\u6709\u65b0\u60f3\u6cd5. \u51e0\u6761\u6bd4\u8f83\u5b9e\u5728\u7684\u539f\u56e0:<\/p>\n<p><strong>\u7ea6\u675f\u6761\u4ef6\u56de\u5230\u4e86\u65e7\u534f\u8bae\u88ab\u8bbe\u8ba1\u65f6\u7684\u6837\u5b50.<\/strong> \u8001\u6280\u672f\u4e4b\u6240\u4ee5\u8001, \u5e38\u5e38\u4e0d\u662f\u56e0\u4e3a\u5b83\u9519, \u800c\u662f\u56e0\u4e3a\u5b83\u89e3\u51b3\u7684\u90a3\u4e2a\u95ee\u9898\u540e\u6765\u4e0d\u91cd\u8981\u4e86. SSE \u662f\u4e3a\"\u670d\u52a1\u7aef\u5355\u5411\u63a8\u4e8b\u4ef6\"\u8bbe\u8ba1\u7684, 402 \u7ed9\u7f51\u7edc\u539f\u751f\u652f\u4ed8\u7559\u4e86\u4e00\u4e2a\u7a7a\u4f4d, RPC \u662f\u4e3a\"\u8de8\u8fdb\u7a0b\u8c03\u4e00\u4e2a\u51fd\u6570\"\u8bbe\u8ba1\u7684. \u8fd9\u4e09\u4ef6\u4e8b\u5728 2015 \u5e74\u90fd\u4e0d\u662f\u4e3b\u6d41\u9700\u6c42, \u5728 2025 \u5e74\u5168\u90fd\u662f.<\/p>\n<p><strong>\u7b80\u5355\u7684\u4e1c\u897f\u8d62.<\/strong> <code>worse is better<\/code>. \u80fd\u76f4\u63a5\u590d\u7528\u73b0\u6709\u57fa\u7840\u8bbe\u65bd\u7684\u65b9\u6848, \u54ea\u6015\u8bbe\u8ba1\u4e0a\"\u4e0d\u591f\u4f18\u96c5\", \u4e5f\u4f1a\u8d62\u8fc7\u9700\u8981\u6574\u6761\u94fe\u8def\u914d\u5408\u6539\u9020\u7684\u65b9\u6848. SSE \u5bf9 WebSocket, JSON-RPC \u5bf9 GraphQL, \u90fd\u662f\u540c\u4e00\u4e2a\u6545\u4e8b.<\/p>\n<p><strong>Gall \u5b9a\u5f8b.<\/strong> \u80fd\u5de5\u4f5c\u7684\u590d\u6742\u7cfb\u7edf\u603b\u662f\u4ece\u80fd\u5de5\u4f5c\u7684\u7b80\u5355\u7cfb\u7edf\u6f14\u5316\u800c\u6765. \u4e00\u4e2a\u65b0\u534f\u8bae\u8981\u5728\u4e00\u5e74\u5185\u94fa\u5f00, \u73b0\u5b9e\u7684\u8def\u5f84\u53ea\u6709\u7ad9\u5728\u5df2\u7ecf\u94fa\u5f00\u7684\u4e1c\u897f\u4e0a\u9762, \u4e5f\u5c31\u662f HTTP, \u7eaf\u6587\u672c\u548c\u6807\u51c6\u8f93\u5165\u8f93\u51fa.<\/p>\n<p><strong>\u53d8\u7684\u5f80\u5f80\u662f\u9700\u6c42\u65b9, \u4e0d\u662f\u6280\u672f.<\/strong> 402 \u6700\u5178\u578b, \u6280\u672f\u4e09\u5341\u5e74\u6ca1\u52a8, \u52a8\u7684\u662f\"\u6d88\u8d39\u8005\u4ece\u4eba\u53d8\u6210\u4e86\u7a0b\u5e8f\". \u4e00\u65e6\u53d1\u8d77\u8bf7\u6c42\u7684\u4e00\u65b9\u4e0d\u518d\u662f\u9700\u8981\u88ab\u54c4\u7740\u70b9\u4e0b\u4e00\u6b65\u7684\u4eba\u7c7b, \u4e00\u5927\u6279\"\u6280\u672f\u4e0a\u53ef\u884c\u4f46\u4f53\u9a8c\u4e0a\u4e0d\u6210\u7acb\"\u7684\u65e7\u8bbe\u8ba1\u5c31\u81ea\u52a8\u6210\u7acb\u4e86.<\/p>\n<p><strong>\u6700\u540e\u4e00\u6761\u4e0d\u592a\u597d\u542c<\/strong>: \u6807\u51c6\u7684\u9009\u62e9\u5f88\u591a\u65f6\u5019\u53ea\u53d6\u51b3\u4e8e\u7b2c\u4e00\u4e2a\u8dd1\u8d77\u6765\u7684\u4eba\u7528\u4e86\u4ec0\u4e48. OpenAI \u7684\u63a5\u53e3\u4e00\u53d1, SSE \u5c31\u662f\u4e8b\u5b9e\u6807\u51c6; Anthropic \u628a MCP \u4e00\u5f00\u6e90, JSON-RPC \u5c31\u662f\u4e8b\u5b9e\u6807\u51c6. <del>\u5173\u4e8e\u6280\u672f\u4f18\u52a3\u7684\u8ba8\u8bba\u901a\u5e38\u5728\u65e2\u6210\u4e8b\u5b9e\u4e4b\u540e\u624d\u70ed\u70c8\u8d77\u6765.<\/del><\/p>\n<h2 id=\"na-shen-me-cai-shi-zhen-de-xin\"><a class=\"zola-anchor\" href=\"#na-shen-me-cai-shi-zhen-de-xin\" aria-label=\"Anchor link for: na-shen-me-cai-shi-zhen-de-xin\">\u90a3\u4ec0\u4e48\u624d\u662f\u771f\u7684\u65b0<\/a><\/h2>\n<p>\u516c\u5e73\u5730\u8bf4, \u4e5f\u786e\u5b9e\u6709\u5168\u65b0\u7684\u90e8\u5206:<\/p>\n<ul>\n<li><code>Scaling Laws<\/code> \u5bf9\u89c4\u6a21, \u6570\u636e, \u7b97\u529b\u4e0e\u635f\u5931\u4e4b\u95f4\u5173\u7cfb\u7684\u7ecf\u9a8c\u63cf\u8ff0, \u4ee5\u53ca\"\u7ee7\u7eed\u653e\u5927\u53ef\u80fd\u7ee7\u7eed\u53d8\u597d\"\u8fd9\u4ef6\u4e8b\u50ac\u751f\u7684\u6574\u5957\u5de5\u7a0b\u4f53\u7cfb. \u81f3\u4e8e\u80fd\u529b\u662f\u4e0d\u662f\"\u7a81\u7136\u6d8c\u73b0\", \u90a3\u662f\u53e6\u4e00\u573a\u8fd8\u6ca1\u5435\u5b8c\u7684\u67b6<\/li>\n<li>\u81ea\u7136\u8bed\u8a00\u4e0d\u518d\u53ea\u662f\u6587\u6863, \u800c\u662f\u76f4\u63a5\u53c2\u4e0e\u8fd0\u884c\u65f6\u51b3\u7b56, \u540c\u4e00\u53e5\u63cf\u8ff0\u65e2\u53ef\u80fd\u662f\u6570\u636e, \u4e5f\u53ef\u80fd\u88ab\u6a21\u578b\u5f53\u6210\u6307\u4ee4. \u81ea\u7136\u8bed\u8a00\u7f16\u7a0b\u5e76\u975e\u6ca1\u6709\u524d\u4eba\u8bd5\u8fc7, \u4f46\u4ece\u672a\u50cf\u4eca\u5929\u8fd9\u6837\u5927\u89c4\u6a21\u8fdb\u5165\u751f\u4ea7\u7cfb\u7edf; <code>prompt injection<\/code> \u4e5f\u6b63\u662f\u5728\u8fd9\u79cd\u6307\u4ee4\u4e0e\u6570\u636e\u8fb9\u754c\u4e0d\u6e05\u7684\u5730\u65b9\u957f\u51fa\u6765<\/li>\n<li>\u628a\u4e00\u4e2a\u8f93\u51fa\u6c38\u8fdc\u5e26\u6982\u7387\u7684\u90e8\u4ef6, \u653e\u8fdb\u4e86\u8981\u6c42\u786e\u5b9a\u6027\u7684\u7cfb\u7edf\u91cc. \u76f8\u5e94\u7684\u9a8c\u8bc1, \u56de\u6eda, \u5e42\u7b49\u548c\u8fb9\u754c\u8bbe\u8ba1, \u76ee\u524d\u8fd8\u8fdc\u6ca1\u6709\u6210\u719f\u7b54\u6848<\/li>\n<\/ul>\n<p>\u6362\u53e5\u8bdd\u8bf4, \u590d\u53e4\u7684\u662f\u7ba1\u9053, \u65b0\u7684\u662f\u6d41\u8fc7\u7ba1\u9053\u7684\u90a3\u4e2a\u4e1c\u897f.<\/p>\n<h2 id=\"hou-ji\"><a class=\"zola-anchor\" href=\"#hou-ji\" aria-label=\"Anchor link for: hou-ji\">\u540e\u8bb0<\/a><\/h2>\n<p>\"\u521b\u65b0\u5373\u590d\u53e4\"\u5e76\u4e0d\u662f\u5632\u8bbd. \u4e00\u4e2a\u80fd\u88ab\u4e09\u5341\u5e74\u524d\u7684\u534f\u8bae\u76f4\u63a5\u63a5\u4f4f\u7684\u9700\u6c42, \u8bf4\u660e\u8fd9\u4e2a\u9700\u6c42\u8db3\u591f\u6734\u7d20, \u800c\u6734\u7d20\u7684\u9700\u6c42\u901a\u5e38\u662f\u771f\u9700\u6c42. \u53cd\u8fc7\u6765, \u5982\u679c\u67d0\u4e2a AI \u65f6\u4ee3\u7684\u65b0\u573a\u666f\u9700\u8981\u4e00\u6574\u5957\u5168\u65b0\u534f\u8bae\u6808\u624d\u80fd\u8868\u8fbe\u6e05\u695a, \u90a3\u5927\u6982\u503c\u5f97\u5148\u6000\u7591\u4e00\u4e0b\u8fd9\u4e2a\u573a\u666f\u672c\u8eab.<\/p>\n<p>\u987a\u4fbf, \u8fd9\u4e5f\u662f\u4e2a\u8fd8\u7b97\u597d\u7528\u7684\u5224\u65ad\u6280\u5de7: \u770b\u5230\u4e00\u4e2a\u65b0\u540d\u8bcd, \u5148\u95ee\u4e00\u53e5\"\u5b83\u590d\u53e4\u7684\u662f\u4ec0\u4e48\". \u901a\u5e38\u80fd\u7acb\u523b\u5b9a\u4f4d\u5230\u5b83\u7684\u8bbe\u8ba1\u6743\u8861\u5728\u54ea\u91cc, \u4ee5\u53ca\u4e09\u5341\u5e74\u524d\u90a3\u6279\u4eba\u5f53\u5e74\u662f\u5728\u54ea\u4e00\u6b65\u4e0a\u5931\u8d25\u7684.<\/p>\n<h2 id=\"can-kao-lian-jie\"><a class=\"zola-anchor\" href=\"#can-kao-lian-jie\" aria-label=\"Anchor link for: can-kao-lian-jie\">\u53c2\u8003\u94fe\u63a5<\/a><\/h2>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/html.spec.whatwg.org\/multipage\/server-sent-events.html\">Server-Sent Events - HTML Standard<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/platform.openai.com\/docs\/api-reference\/streaming\">OpenAI Streaming API responses<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/platform.openai.com\/docs\/guides\/background\">OpenAI Background mode<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/transitive-bullshit\/chatgpt-api\/issues\/640\">ChatGPT Web has switched from SSE to WebSockets<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/datatracker.ietf.org\/doc\/html\/rfc2068\">RFC 2068 - Hypertext Transfer Protocol -- HTTP\/1.1<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/x402.org\/\">x402<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/x402-foundation\/x402\">x402-foundation\/x402<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/docs.x402.org\/guides\/migration-v1-to-v2\">x402 V1 to V2 Migration Guide<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.coinbase.com\/developer-platform\/discover\/launches\/x402\">Introducing x402: a new standard for internet-native payments<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/lightninglabs\/L402\">The Lightning Network HTTP 402 Protocol (L402)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/google-agentic-commerce\/AP2\">Agent Payments Protocol (AP2)<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.jsonrpc.org\/specification\">JSON-RPC 2.0 Specification<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/datatracker.ietf.org\/doc\/html\/rfc6455\">RFC 6455 - The WebSocket Protocol<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/modelcontextprotocol.io\/specification\/2025-06-18\/basic\/transports\">MCP Specification - Transports<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/blog.modelcontextprotocol.io\/posts\/2025-12-19-mcp-transport-future\/\">Exploring the Future of MCP Transports<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/developers.openai.com\/codex\/app-server\">Codex App Server<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/openai\/codex\/tree\/main\/codex-rs\/app-server\">openai\/codex - codex-rs\/app-server<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.cs.toronto.edu\/~hinton\/absps\/jjnh91.pdf\">Adaptive Mixtures of Local Experts<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/arxiv.org\/abs\/1706.03762\">Attention Is All You Need<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/arxiv.org\/abs\/2001.08361\">Scaling Laws for Neural Language Models<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.dreamsongs.com\/RiseOfWorseIsBetter.html\">The Rise of \"Worse is Better\"<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/John_Gall_(author)#Gall&#x27;s_law\">Gall's law<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/llmstxt.org\/\">llms.txt<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/agents.md\/\">AGENTS.md<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/earendil-works\/pi\/tree\/main\/packages\/coding-agent\">pi coding agent<\/a><\/li>\n<\/ul>\n"},{"title":"\u6f2b\u8c08 <\u6218\u573a\u4e4b\u72fc2>","published":"2025-11-17T16:31:57+09:00","updated":"2025-11-17T16:31:57+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/a-casual-talk-about-mercs\/"}},"id":"https:\/\/memwey.github.io\/posts\/a-casual-talk-about-mercs\/","content":"<p>\u5ffd\u7136\u60f3\u8d77\u4e86\u5e7c\u5e74\u65f6\u671f\u770b\u8868\u54e5\u73a9\u7684\u4e00\u6b3e\u6e38\u620f, \u5f53\u65f6\u5e74\u7eaa\u6bd4\u8f83\u5c0f, \u5f53\u7136\u4e0d\u8bb0\u5f97\u6e38\u620f\u7684\u540d\u5b57\u4e86, \u6211\u628a\u5bf9\u4e8e\u6e38\u620f\u7684\u5370\u8c61\u53d1\u9001\u7ed9 ChatGPT, \"Mega Drive \u4e0a\u7684\u4e00\u6b3e\u6e38\u620f, \u7c7b\u4f3c\u9b42\u6597\u7f57, \u519b\u4e8b\u80cc\u666f\u7684, \u4f46\u662f\u4e0d\u662f\u4ece\u5de6\u5230\u53f3\u7684\u6a2a\u5411\u5377\u8f74\u5f0f, \u800c\u662f\u4fef\u89c6\u89d2\u7684\", ChatGPT \u7ed9\u4e86\u6211\u786e\u5207\u7684\u7b54\u6848, \u90a3\u5c31\u662f <a rel=\"external\" href=\"https:\/\/ja.wikipedia.org\/wiki\/%E6%88%A6%E5%A0%B4%E3%81%AE%E7%8B%BCII\">\u6226\u5834\u306e\u72fcII<\/a>, \u82f1\u6587\u540d\u4e3a <code>MERCS<\/code>, \u4e2d\u6587\u7684\u8bdd, \u4e00\u822c\u5c31\u76f4\u63a5\u53eb&lt;\u6218\u573a\u4e4b\u72fc2&gt;.<\/p>\n<p>\u8fd9\u6b3e\u6e38\u620f\u672c\u8eab\u662f\u4ece\u8857\u673a\u79fb\u690d\u7684, \u73b0\u5728\u770b\u6765, \u8fd9\u4e2a\u6e38\u620f\u5176\u5b9e\u6709\u86ee\u591a\u503c\u5f97\u4e00\u63d0\u7684\u5730\u65b9.<\/p>\n<h2 id=\"you-xi-ben-shen-liang-dian\"><a class=\"zola-anchor\" href=\"#you-xi-ben-shen-liang-dian\" aria-label=\"Anchor link for: you-xi-ben-shen-liang-dian\">\u6e38\u620f\u672c\u8eab\u4eae\u70b9<\/a><\/h2>\n<p>&lt;\u6218\u573a\u4e4b\u72fc2&gt; \u52a0\u5165\u4e86\u5927\u91cf\u8f7d\u5177\u7684\u5143\u7d20. \u5728\u6d41\u7a0b\u4e2d, \u53ef\u4ee5\u9a7e\u9a76\u5409\u666e\u8f66, \u56fa\u5b9a\u70ae\u53f0, \u751a\u81f3\u662f\u5766\u514b, \u5728\u5f53\u65f6\u662f\u975e\u5e38\u5148\u8fdb\u800c\u7f55\u89c1\u7684\u8bbe\u8ba1.<\/p>\n<p>\u4ece\u8857\u673a\u79fb\u690d\u5230 Mega Drive \u7684\u7248\u672c\u4e2d, \u53bb\u6389\u4e86\u8857\u673a\u5385\u8054\u673a\u7684\u591a\u4eba\u6a21\u5f0f, \u4f46\u662f\u589e\u52a0\u4e86\u4e00\u4e2a\u975e\u5e38\u6709\u8bda\u610f\u7684\u5f25\u8865\u5bb6\u7528\u673a\u65e0\u6cd5\"\u6295\u5e01\"\u800c\u505a\u7684\u957f\u7ebf\u73a9\u6cd5 <code>\u539f\u521b\u6a21\u5f0f (Original Mode)<\/code>, \u6709 5 \u540d\u4e0d\u540c\u7279\u6027\u7684\u961f\u5458, \u5305\u542b\u4e86 RPG \u8981\u7d20, \u53ef\u4ee5\u8d2d\u4e70\u88c5\u5907\u548c\u5347\u7ea7.<\/p>\n<h2 id=\"ge-ren-ying-xiong-zhu-yi-shi-liu-cheng\"><a class=\"zola-anchor\" href=\"#ge-ren-ying-xiong-zhu-yi-shi-liu-cheng\" aria-label=\"Anchor link for: ge-ren-ying-xiong-zhu-yi-shi-liu-cheng\">\u4e2a\u4eba\u82f1\u96c4\u4e3b\u4e49\u5f0f\u6d41\u7a0b<\/a><\/h2>\n<p>&lt;\u6218\u573a\u4e4b\u72fc2&gt; \u7684\u6d41\u7a0b\u5f88\u7b80\u5355, \u4f60\u626e\u6f14\u4e00\u4f4d\u7a81\u51fb\u961f\u5458, \u4ece\u654c\u56fd\u7684\u6d77\u5cb8, \u4e1b\u6797, \u57fa\u5730\u4e00\u8def\u633a\u8fdb, \u5b64\u8eab\u63a8\u8fdb, \u6240\u5230\u4e4b\u5904\u5f39\u96e8\u6a2a\u98de, \u6700\u540e\u76f4\u6363\u654c\u519b\u8001\u5de2.<\/p>\n<p>\u5728\u4eca\u5929\u770b\u6765\u662f\u975e\u5e38\u9648\u65e7\u7684\"\u52a8\u4f5c\u7247\u6a21\u677f\", \u4f46\u5bf9\u5f53\u5e74\u7684\u73a9\u5bb6\u6765\u8bf4, \u8fd9\u79cd <strong>\"\u4e00\u4e2a\u4eba\u626b\u5e73\u6574\u4e2a\u519b\u961f\"<\/strong> \u7684\u53d9\u4e8b\u65b9\u5f0f\u662f\u6781\u5177\u5438\u5f15\u529b\u7684. \u90a3\u6b63\u662f\u53f2\u6cf0\u9f99\u4e0e\u65bd\u74e6\u8f9b\u683c\u4e3b\u5bfc\u94f6\u5e55\u7684\u5e74\u4ee3: \u597d\u83b1\u575e\u52a8\u4f5c\u7247, \u51b7\u6218\u6545\u4e8b, \u808c\u8089\u82f1\u96c4, \u7279\u79cd\u90e8\u961f\u795e\u8bdd\u98ce\u9761\u4e00\u65f6, \u6e38\u620f\u6587\u5316\u4e5f\u6df1\u53d7\u5176\u5f71\u54cd.<\/p>\n<p>\u53d7\u9650\u4e8e\u5f53\u65f6\u7684\u6280\u672f\u8868\u73b0\u529b, \u6e38\u620f\u5929\u7136\u503e\u5411\u8fd9\u79cd\"\u6211\u65b9\u5355\u67aa\u5339\u9a6c, \u654c\u4eba\u4e0d\u65ad\u6d8c\u73b0\"\u7684\u6d41\u7a0b\u8bbe\u8ba1. \u4fef\u89c6\u89d2, \u56fa\u5b9a\u706b\u529b\u5c04\u7a0b, \u9ad8\u5bc6\u5ea6\u654c\u4eba\u5206\u5e03, \u8fd9\u4e9b\u673a\u5236\u65e2\u4f7f\u73a9\u6cd5\u6613\u4e8e\u5b9e\u73b0, \u53c8\u9ad8\u5ea6\u5951\u5408\u4e86\"\u5b64\u80c6\u82f1\u96c4\"\u8fd9\u79cd\u53d9\u4e8b\u98ce\u683c. \u8fd9\u79cd\u8bbe\u8ba1\u65e2\u662f\u6280\u672f\u59a5\u534f, \u4e5f\u662f\u65f6\u4ee3\u504f\u597d\u7684\u4ea7\u7269.<\/p>\n<h2 id=\"shen-shou-leng-zhan-xu-shi-ying-xiang-de-you-xi-bei-jing\"><a class=\"zola-anchor\" href=\"#shen-shou-leng-zhan-xu-shi-ying-xiang-de-you-xi-bei-jing\" aria-label=\"Anchor link for: shen-shou-leng-zhan-xu-shi-ying-xiang-de-you-xi-bei-jing\">\u6df1\u53d7\u51b7\u6218\u53d9\u4e8b\u5f71\u54cd\u7684\u6e38\u620f\u80cc\u666f<\/a><\/h2>\n<p>&lt;\u6218\u573a\u4e4b\u72fc2&gt; \u7684\u6545\u4e8b\u80cc\u666f\u51e0\u4e4e\u5c31\u662f\u4e00\u7bc7\"\u51b7\u6218\u52a8\u4f5c\u7247\u6a21\u677f\":<\/p>\n<ul>\n<li>\u865a\u6784\u56fd\u5bb6\u53d1\u751f\u519b\u4e8b\u653f\u53d8<\/li>\n<li>\u7f8e\u56fd(\u524d)\u603b\u7edf\u88ab\u654c\u4eba\u7ed1\u67b6(\u8fd9\u91cc\u5bf9\u4e8e\u662f\u5426\u662f\"\u524d\", \u4e0d\u540c\u7248\u672c\u4f3c\u4e4e\u6709\u4e0d\u540c\u7684\u8bbe\u5b9a)<\/li>\n<li>\u7f8e\u56fd\u4e0d\u613f\u516c\u5f00\u519b\u4e8b\u4ecb\u5165, \u79d8\u5bc6\u6d3e\u51fa\u7cbe\u9510\u4f63\u5175\u90e8\u961f\u6267\u884c\u8425\u6551\u884c\u52a8<\/li>\n<li>\u63a8\u7ffb\u90aa\u6076\u7684\u654c\u56fd\u653f\u5e9c<\/li>\n<\/ul>\n<p>\u5728\u6218\u6597\u8868\u73b0\u4e0a\u66f4\u662f\u660e\u663e:<\/p>\n<ul>\n<li><strong>\u654c\u65b9\u5927\u91cf\u4f7f\u7528\u82cf\u5f0f\/\u534e\u7ea6\u6b66\u5668<\/strong>: AK \u4e0e RPG \u7cfb\u5217\u8f7b\u6b66\u5668, T-55\/T-62 \u5916\u5f62\u7684\u5766\u514b, ZSU \u98ce\u683c\u7684\u9632\u7a7a\u70ae<\/li>\n<li><strong>\u6211\u65b9\u5219\u662f\u5178\u578b\u7f8e\u56fd\/\u5317\u7ea6\u88c5\u5907<\/strong>: \u7a81\u51fb\u67aa\u5916\u5f62\u63a5\u8fd1 M16 \u7cfb\u5217, \u8f7d\u5177\u5219\u662f\u7f8e\u5f0f\u76f4\u5347\u673a\u4e0e\u5409\u666e\u8f66<\/li>\n<\/ul>\n<p>\u4eca\u5929\u770b\u6765, \u8fd9\u79cd\u8bbe\u5b9a\u663e\u7136\u5c5e\u4e8e\u5178\u578b\u7684, \"\u5c0f\u56fd\u5a01\u80c1\u7f8e\u56fd\u7684\u5b89\u5168\u4e0e\u5c0a\u4e25\", \"\u6b63\u4e49\u7684\u6211\u4eec\u90aa\u6076\u7684\u4ed6\u4eec\", \"\u4ee5\u519b\u4e8b\u884c\u52a8\u5e72\u9884\u4ed6\u56fd\u5185\u653f\"\u7684\u4e16\u754c\u8b66\u5bdf\u53d9\u4e8b, \u5728 80\u201390 \u5e74\u4ee3, \u65e5\u672c\u6e38\u620f\u4e0e\u7f8e\u5f0f\u5a31\u4e50\u6df1\u5ea6\u7ed1\u5b9a\u7684\u65f6\u671f, \u5b83\u5374\u662f\u6700\u5e38\u89c1\u7684\u6807\u51c6\u5267\u672c.<\/p>\n<p>\u8fd9\u79cd\"\u865a\u6784\u56fd\u5bb6\"\u52a0\"\u9635\u8425\u7b26\u53f7\u5316\u660e\u663e\"\u7684\u8138\u8c31\u5316\u7684\u5904\u7406\u65b9\u5f0f, \u65e2\u907f\u5f00\u4e86\u73b0\u5b9e\u653f\u6cbb\u654f\u611f\u6027, \u53c8\u80fd\u8ba9\u73a9\u5bb6\u5728\u4f4e\u6e05\u6670\u5ea6\u4e0b\u7684\u50cf\u7d20\u70b9\u4e0b\u4e00\u773c\u8ba4\u51fa\"\u8c01\u662f\u654c\u4eba\".<\/p>\n<p>\u5b83\u5e76\u4e0d\u662f\u771f\u7684\u5728\u8bb2\u6545\u4e8b, \u800c\u662f\u5728\u4e3a\u4e00\u79cd\u65e2\u5b9a\u7684\u4e16\u754c\u79e9\u5e8f\u63d0\u4f9b\u5e7b\u60f3\u5f0f\u7684\u6b63\u5f53\u6027. \u654c\u56fd\u5f80\u5f80\u7f3a\u4e4f\u771f\u5b9e\u7684\u5386\u53f2\u53ca\u6587\u5316\u6216\u653f\u6cbb\u7ec6\u8282, \u5b83\u5b58\u5728\u7684\u552f\u4e00\u7406\u7531, \u5c31\u662f\u4e3a\u4e3b\u89d2\u7684\u5408\u7406\u66b4\u529b\u63d0\u4f9b\u821e\u53f0, \u5e76\u4ee5\u6e38\u620f\u7684\u5f62\u5f0f\u8f93\u51fa\u51b7\u6218\u65f6\u671f\u7684\u610f\u8bc6\u5f62\u6001\u6846\u67b6.<\/p>\n<h2 id=\"zao-qi-jie-ji-fu-fei-mo-shi\"><a class=\"zola-anchor\" href=\"#zao-qi-jie-ji-fu-fei-mo-shi\" aria-label=\"Anchor link for: zao-qi-jie-ji-fu-fei-mo-shi\">\u65e9\u671f\u8857\u673a\u4ed8\u8d39\u6a21\u5f0f<\/a><\/h2>\n<p>\u4f5c\u4e3a\u8857\u673a\u79fb\u690d, &lt;\u6218\u573a\u4e4b\u72fc2&gt;\u6709\u4e00\u4e2a\u65e0\u6cd5\u5ffd\u89c6\u7684\u80cc\u666f, <strong>\u8857\u673a\u4ed8\u8d39\u6a21\u5f0f\u51b3\u5b9a\u4e86\u5b83\u7684\u96be\u5ea6\u7ed3\u6784<\/strong>.<\/p>\n<p>\u5728\u8857\u673a\u9ec4\u91d1\u5e74\u4ee3, \u51e0\u4e4e\u6240\u6709\u6e38\u620f\u7684\u8bbe\u8ba1\u90fd\u56f4\u7ed5\u4e00\u4e2a\u6838\u5fc3\u76ee\u6807\u5c55\u5f00<\/p>\n<blockquote>\n<p><strong>\u5982\u4f55\u8ba9\u73a9\u5bb6\u5728 2-3 \u5206\u949f\u5185\u6b7b\u4ea1\u4e00\u6b21, \u4ece\u800c\u6295\u4e0b\u4e0b\u4e00\u679a\u786c\u5e01?<\/strong><\/p>\n<\/blockquote>\n<p>\u4e8e\u662f, \u6e38\u620f\u5448\u73b0\u51fa\u4e00\u79cd\u72ec\u7279\u7684\u8bbe\u8ba1:<\/p>\n<ul>\n<li>\u5f00\u573a\u51e0\u5341\u79d2\u6781\u6613\u4e0a\u624b, \u8ba9\u73a9\u5bb6\u5efa\u7acb\u4fe1\u5fc3<\/li>\n<li>\u7ecf\u5e38\u6709\"\u68c0\u67e5\u70b9\", \u8003\u9a8c\u7279\u5b9a\u7684\u64cd\u4f5c<\/li>\n<li>BOSS \u901a\u5e38\u6709\"\u521d\u89c1\u6740\"<\/li>\n<li>\u540e\u671f\u654c\u4eba\u5bc6\u5ea6\u4e0e\u5f39\u91cf\u6307\u6570\u7ea7\u589e\u957f<\/li>\n<li>\u7eed\u5e01\u540e\u7684\u77ed\u6682\u65e0\u654c\u6216\u6e05\u5c4f\u6536\u76ca\u5de8\u5927<\/li>\n<li>\u6e38\u620f\u5b8c\u6574\u6d41\u7a0b\u7ef4\u6301\u5728\u4e00\u5230\u4e24\u5c0f\u65f6\u5185<\/li>\n<\/ul>\n<p>\u8fd9\u79cd\u8bbe\u8ba1\u5728\u5f53\u65f6\u88ab\u89c6\u4e3a\u7406\u6240\u5f53\u7136, \u7136\u800c\u4ece\u4eca\u5929\u7684\u73a9\u5bb6\u4e60\u60ef\u6765\u770b, \u65e9\u671f\u8857\u673a\u7684\"\u6295\u5e01\u7eed\u547d\u5f0f\u4ed8\u8d39\u6a21\u5f0f\"\u65e0\u8bba\u5728\u4ed8\u8d39\u6a21\u5f0f\u8fd8\u662f\u6e38\u620f\u4f53\u9a8c\u4e0a, \u51e0\u4e4e\u4e0d\u53ef\u80fd\u518d\u6b21\u88ab\u5e7f\u6cdb\u63a5\u53d7. \u5728\u5a31\u4e50\u5185\u5bb9\u975e\u5e38\u4e30\u5bcc\u7684\u73b0\u4ee3, \u8ba9\u73a9\u5bb6\u611f\u5230\u632b\u6298\u7684\u6e38\u620f\u4e0d\u518d\u88ab\u89c6\u4e3a\"\u6311\u6218\u6027\u5f3a\", \u800c\u662f\"\u6ca1\u6709\u6027\u4ef7\u6bd4\", \u51e0\u4e4e\u4e0d\u4f1a\u6709\u4eba\u4f1a\u613f\u610f\u4ed8\u94b1\u7ee7\u7eed\u5fcd\u53d7, \u800c\u662f\u76f4\u63a5\u79bb\u5f00, \u6362\u4e00\u6b3e\u66f4\u7701\u5fc3\u7684\u6e38\u620f.<\/p>\n<h2 id=\"hou-ji\"><a class=\"zola-anchor\" href=\"#hou-ji\" aria-label=\"Anchor link for: hou-ji\">\u540e\u8bb0<\/a><\/h2>\n<p>\u56de\u5934\u518d\u770b&lt;\u6218\u573a\u4e4b\u72fc2&gt;, \u5b83\u662f\u90a3\u4e2a\u65f6\u4ee3\u4e00\u4e2a\u9887\u6709\u4ee3\u8868\u6027\u7684\u4f5c\u54c1<\/p>\n<ul>\n<li>\u6d41\u884c\u6587\u5316\u4e0e\u6280\u672f\u8868\u73b0\u529b\u7684\u9650\u5236\u5171\u540c\u5851\u9020\u7684\u4e2a\u4eba\u82f1\u96c4\u4e3b\u4e49\u53d9\u4e8b<\/li>\n<li>\u6df1\u53d7\u51b7\u6218\u610f\u8bc6\u5f62\u6001\u5f71\u54cd\u7684\u6b66\u5668\u4e0e\u9635\u8425\u7b26\u53f7\u4ee5\u53ca\u56fd\u9645\u5173\u7cfb<\/li>\n<li>\u96be\u5ea6\u6d41\u7a0b\u4e0e\u8857\u673a\u5546\u4e1a\u6a21\u5f0f\u7d27\u5bc6\u7ed1\u5b9a<\/li>\n<\/ul>\n<p>\u5728\u4eca\u5929\u7684\u89c6\u89d2\u91cc, \u5b83\u663e\u5f97\u7c97\u7cd9\u751a\u81f3\u539f\u59cb. \u4f46\u4e5f\u6b63\u56e0\u4e3a\u5982\u6b64, \u5b83\u5f88\u50cf\u662f\u90a3\u4e2a\u5e74\u4ee3\u7684\u5316\u77f3. \u6709\u65f6\u5019\u56de\u5fc6\u7684\u4ef7\u503c\u5e76\u4e0d\u662f\u5b83\u5728\u4eca\u5929\u8fd8\u6709\u591a\u597d\u73a9, \u800c\u662f\u5b83\u8ba9\u6211\u4eec\u91cd\u65b0\u770b\u89c1\u81ea\u5df1\u66fe\u7ecf\u751f\u6d3b\u5728\u600e\u6837\u7684\u4e16\u754c\u91cc.<\/p>\n<p>\u5728\u67e5\u627e\u8d44\u6599\u8fc7\u7a0b\u4e2d\u53d1\u73b0\u5728 Steam \u4e0a\u6709\u552e, \u5728 <a rel=\"external\" href=\"https:\/\/store.steampowered.com\/app\/1556714\/Capcom_Arcade_StadiumSenjo_no_OkamiII\/\">Capcom Arcade Stadium<\/a> \u4e2d\u4f5c\u4e3a DLC \u552e\u5356, \u4e0d\u8fc7\u4f3c\u4e4e\u662f\u8857\u673a\u7248\u672c.<\/p>\n<h2 id=\"can-kao-lian-jie\"><a class=\"zola-anchor\" href=\"#can-kao-lian-jie\" aria-label=\"Anchor link for: can-kao-lian-jie\">\u53c2\u8003\u94fe\u63a5<\/a><\/h2>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/sesesega.blog.fc2.com\/blog-entry-416.html\">SSSG\u653b\u7565\u65e5\u8a18 - \u6226\u5834\u306e\u72fcII<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.gcores.com\/articles\/26616\">\u4e00\u7bc7\u8fdf\u5230\u4e8627\u5e74\u7684\u8857\u673a\u653b\u7565\uff1a\u6211\u6700\u7231\u7684\u300a\u6218\u573a\u4e4b\u72fc2\u300b<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.gcores.com\/articles\/26321\">16-bit\u6e38\u620f\u6f2b\u8c08\uff087\uff09\u2014\u2014 \u300a\u6218\u573a\u4e4b\u72fc2\u300b<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/black16bit.pixnet.net\/blog\/post\/35869542\">\u6709 RPG \u5473\u9053\u7684\u539f\u5275\u6a21\u5f0f\uff1a\u6230\u5834\u4e4b\u72fcII<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/home.gamer.com.tw\/creationDetail.php?sn=1363120\">\u3010\u5fc3\u5f97\u3011\u5954\u99b3\u65bc\u6230\u5730\u7684\u72c2\u72fc\u6012\u543c - \u6230\u5834\u4e4b\u72fcII<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/store.steampowered.com\/app\/1556714\/Capcom_Arcade_StadiumSenjo_no_OkamiII\/\">Capcom Arcade Stadium\uff1a\u6226\u5834\u306e\u72fc\u2161<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/chu-gamer.com\/mercs\/\">\u6050\u308c\u308b\u3053\u3068\u306a\u304f\u6483\u3061\u307e\u304f\u308c\uff01\u300e\u6226\u5834\u306e\u72fc\u2161\u300f<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.bilibili.com\/video\/BV1Ex421k7ub\">\u3010\u7ae5\u5e74\u56de\u5fc6\u3011MD \u6218\u573a\u4e4b\u72fc2 \u539f\u521b\u6a21\u5f0f \u901a\u5173<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.bilibili.com\/video\/BV1y14y1e7s4\">MD\u7ecf\u5178\u6e38\u620f\u300a\u6218\u573a\u4e4b\u72fc2\u300b\u5f53\u5e74\u7684\u6700\u7231\uff0c\u65e0\u8111\u653e\u96f7\u72c2\u8f70\u6ee5\u70b8\u5f0f\u51b2\u950b\u3002<\/a><\/li>\n<\/ul>\n"},{"title":"Fake News \u7684\u4e00\u4ef6\u5c0f\u4e8b","published":"2025-11-13T15:08:27+09:00","updated":"2026-07-30T00:00:00+00:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/fake-news\/"}},"id":"https:\/\/memwey.github.io\/posts\/fake-news\/","content":"<p>\u6700\u8fd1, \u4e2d\u534e\u4eba\u6c11\u5171\u548c\u56fd\u9a7b\u5927\u962a\u603b\u9886\u4e8b\u859b\u5251\u5728 X \u4e0a\u7684\u8a00\u8bba\u5f15\u8d77\u4e86\u4e00\u4e9b\u4e89\u8bae, \u5177\u4f53\u7684\u8a00\u8bba\u5982\u56fe:<\/p>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/fake-news\/images\/screenshot.jpeg\" alt=\"\u622a\u56fe\" \/><\/p>\n<p>\u5177\u4f53\u7684\u65e5\u6587\u539f\u6587\u5982\u4e0b:<\/p>\n<blockquote>\n<p>\u52dd\u624b\u306b\u7a81\u3063\u8fbc\u3093\u3067\u304d\u305f\u305d\u306e\u6c5a\u3044\u9996\u306f\u4e00\u77ac\u306e\u8e8a\u8e87\u3082\u306a\u304f\u65ac\u3063\u3066\u3084\u308b\u3057\u304b\u306a\u3044\u3002\u899a\u609f\u304c\u51fa\u6765\u3066\u3044\u308b\u306e\u304b\u3002<\/p>\n<\/blockquote>\n<p>\u5176\u56de\u5e94\u7684\u63a8\u7279\u539f\u6587\u5982\u4e0b:<\/p>\n<blockquote>\n<p>\u9ad8\u5e02\u9996\u76f8\u3001\u53f0\u6e7e\u6709\u4e8b\u300c\u5b58\u7acb\u5371\u6a5f\u4e8b\u614b\u306b\u306a\u308a\u3046\u308b\u300d\u3000\u8a8d\u5b9a\u306a\u3089\u6b66\u529b\u884c\u4f7f\u3082\nhttps:\/\/www.asahi.com\/articles\/ASTC722TVTC7UQIP04NM.html\n\u300c\u5b9f\u969b\u306b\u767a\u751f\u3057\u305f\u4e8b\u614b\u306e\u500b\u5225\u3001\u5177\u4f53\u7684\u306a\u72b6\u6cc1\u306b\u5fdc\u3058\u3066\u3001\u653f\u5e9c\u304c\u3059\u3079\u3066\u306e\u60c5\u5831\u3092\u7dcf\u5408\u3057\u3066\u5224\u65ad\u3059\u308b\u3002\u6b66\u529b\u653b\u6483\u304c\u767a\u751f\u3057\u305f\u3089\u3001\u3053\u308c\u306f\u5b58\u7acb\u5371\u6a5f\u4e8b\u614b\u306b\u3042\u305f\u308b\u53ef\u80fd\u6027\u304c\u9ad8\u3044\u300d\u3068\u3082\u8a9e\u308a\u307e\u3057\u305f\u3002<\/p>\n<\/blockquote>\n<p><code>FOX NEWS<\/code> \u5728\u65b0\u95fb\u9875\u9762\u4e0a\u7ed9\u51fa\u7684\u82f1\u6587\u7ffb\u8bd1\u5982\u4e0b:<\/p>\n<blockquote>\n<p>That filthy neck that barged in on its own. I've got no choice but to cut if off without a moment's hesitation. Are you prepared for that?<\/p>\n<\/blockquote>\n<p>\u5728\u4e0e\u7279\u6717\u666e\u7684\u4e13\u8bbf\u5bf9\u8c08\u4e2d, \u52b3\u62c9\u00b7\u82f1\u683c\u62c9\u54c8\u59c6, \u7f8e\u56fd\u4e00\u4f4d\u5e7f\u64ad\u8131\u53e3\u79c0\u4e3b\u6301\u4eba, \u7545\u9500\u4e66\u4f5c\u5bb6\u548c\u4fdd\u5b88\u6d3e\u653f\u8bba\u5bb6, \u8fd9\u6837\u63cf\u8ff0\u8fd9\u6bb5\u53d1\u8a00:<\/p>\n<blockquote>\n<p>Laura Ingraham: And over the weekend, the new Japanese prime minister, who I know you like a lot, Takaichi, called the Taiwan situation extremely severe in its phase and that they may consider any move on Taiwan by China to be a national survival crisis for Japan. Now that gets better. A Chinese diplomat today said in a social media post that, she the prime minister of Japan, should be beheaded for her comments.<\/p>\n<\/blockquote>\n<p>\u800c\u7279\u6717\u666e\u505a\u51fa\u7684\u56de\u5e94\u5982\u4e0b:<\/p>\n<blockquote>\n<p>President Donald Trump: Well, a lot of our allies aren't our friends either. Our allies took advantage of us on trade more than China did. And China took big advantage. We built their military. We built their whole thing.<\/p>\n<\/blockquote>\n<p>\u4ece\u8fd9\u4e2a\u4e8b\u4ef6, \u53ef\u4ee5\u6e05\u6670\u7684\u770b\u5230 Fake News \u662f\u5982\u4f55\u4ea7\u751f\u7684. \u4ece\u4f20\u64ad\u6548\u679c\u770b, \u8fd9\u6b21\u8f6c\u8ff0\u5e76\u975e\u51ed\u7a7a\u634f\u9020, \u800c\u662f\u901a\u8fc7\u7701\u7565\u8bed\u5883, \u6d88\u9664\u6307\u4ee3\u4e0a\u7684\u6a21\u7cca, \u628a\u539f\u6587\u4e2d\u5e26\u6709\u66b4\u529b\u610f\u8c61\u7684<strong>\u6fc0\u70c8\u8a00\u8f9e<\/strong>, \u6536\u675f\u6210\u4e86\u4e00\u4e2a\u66f4<strong>\u76f4\u63a5<\/strong>, \u66f4<strong>\u5177\u4f53<\/strong>\u7684, \u66f4\u5177<strong>\u7206\u70b8\u6027<\/strong>\u7684\u7ed3\u8bba: \u4e00\u540d\u4e2d\u56fd\u5916\u4ea4\u5b98\u4e3b\u5f20\u65a9\u9996\u65e5\u672c\u9996\u76f8. \u8fd9\u79cd\u538b\u7f29\u5f3a\u5316\u4e86\u4e8b\u4ef6\u7684\u8038\u52a8\u6027, \u4e5f\u66f4\u5bb9\u6613\u8ba9\u89c2\u4f17\u548c\u7f8e\u56fd\u603b\u7edf\u7279\u6717\u666e\u5c06\u5176\u7406\u89e3\u4e3a\u9488\u5bf9\u9996\u76f8\u672c\u4eba\u7684\u660e\u786e<strong>\u4eba\u8eab\u5a01\u80c1<\/strong>\u3002<\/p>\n<p>\u8fd9\u4f4d\u7f8e\u56fd\u603b\u7edf\u591a\u6b21\u8868\u660e\u8fc7, <strong>\u4e0d\u51c6\u786e<\/strong>, <strong>\u504f\u89c1<\/strong>, <strong>\u65ad\u7ae0\u53d6\u4e49<\/strong>\u7684\u65b0\u95fb\u62a5\u9053\u662f <strong>Fake News<\/strong>, \u4e5f\u7b97\u662f\u8eab\u7ecf\u767e\u6218\u89c1\u5f97\u591a\u4e86, \u6ca1\u6709\u5177\u4f53\u4e8b\u60c5\u4e0a\u505a\u8bc4\u8bba, \u800c\u662f\u8c08\u8d77\u6765\u65e5\u672c\u5e76\u4e0d\u662f\u7f8e\u56fd\u7684\u670b\u53cb, \u8f6c\u56de\u4ed6\u719f\u6089\u7684\u5bf9\u76df\u53cb\u5728\u7ecf\u8d38\u95ee\u9898\u4e0a\u5360\u4fbf\u5b9c\u7684\u53d9\u4e8b\u6846\u67b6, \u573a\u9762\u4e00\u5ea6\u7565\u663e\u5c34\u5c2c.<\/p>\n<h2 id=\"can-kao-zi-liao\"><a class=\"zola-anchor\" href=\"#can-kao-zi-liao\" aria-label=\"Anchor link for: can-kao-zi-liao\">\u53c2\u8003\u8d44\u6599<\/a><\/h2>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/www.youtube.com\/watch?v=7juiv6qrYds\">Trump pulls back curtain on relationship with Xi Jinping<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.asahi.com\/articles\/ASTC722TVTC7UQIP04NM.html\">\u9ad8\u5e02\u9996\u76f8\u3001\u53f0\u6e7e\u6709\u4e8b\u300c\u5b58\u7acb\u5371\u6a5f\u4e8b\u614b\u306b\u306a\u308a\u3046\u308b\u300d\u3000\u6b66\u529b\u653b\u6483\u306e\u767a\u751f\u6642<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/x.com\/asahicom\/status\/1986702380969144741\">\u9ad8\u5e02\u9996\u76f8\u3001\u53f0\u6e7e\u6709\u4e8b\u300c\u5b58\u7acb\u5371\u6a5f\u4e8b\u614b\u306b\u306a\u308a\u3046\u308b\u300d\u3000\u8a8d\u5b9a\u306a\u3089\u6b66\u529b\u884c\u4f7f\u3082<\/a><\/li>\n<\/ul>\n"},{"title":"PlayStation 4 Pro \u62fe\u9057","published":"2025-10-30T19:38:09+09:00","updated":"2025-11-01T21:44:35+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/playstation-4-pro-rediscovering\/"}},"id":"https:\/\/memwey.github.io\/posts\/playstation-4-pro-rediscovering\/","content":"<p>\u8fd9\u53f0 PlayStation 4 Pro \u5176\u5b9e\u4e5f\u4e70\u4e86\u633a\u4e45\u4e86, \u5f53\u65f6\u8fd8\u662f\u4e70\u7684\u56fd\u884c\u7248\u672c, \u7136\u540e\u56e0\u4e3a\u957f\u65f6\u95f4\u7684\u79df\u623f\u751f\u6d3b, \u5e76\u6ca1\u6709\u4ec0\u4e48\u6761\u4ef6\u548c\u65f6\u95f4\u6765\u73a9, \u6700\u7ec8\u957f\u671f\u7684\u5403\u7070, \u751a\u81f3\u501f\u7ed9\u670b\u53cb\u73a9\u4e86\u597d\u957f\u65f6\u95f4 (\u5f53\u7136\u4ed6\u4e70\u7684<code>\u602a\u7269\u730e\u4eba\u4e16\u754c: \u51b0\u539f<\/code>\u5728\u8fd8\u673a\u5668\u7684\u65f6\u5019\u4e00\u5e76\u9001\u6211\u4e86)<\/p>\n<p>\u5e26\u6765\u65e5\u672c\u540e, \u6700\u8fd1\u53c8\u6361\u8d77\u6765\u4e86, \u5f97\u76ca\u4e8e\u79cb\u53f6\u539f\u7ebf\u4e0b\u7684\u4e8c\u624b\u4ea4\u6613\u5e02\u573a, \u53d1\u73b0\u5176\u5b9e\u8fd8\u662f\u6bd4\u8f83\u53ef\u73a9\u7684. <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Eighth_generation_of_video_game_consoles\">\u7b2c\u516b\u4e16\u4ee3<\/a>\u5176\u5b9e\u662f\u4e2a\u6bd4\u8f83\u7279\u522b\u7684\u4e16\u4ee3. \u4e00\u65b9\u9762, \u4e3b\u6d41\u6e38\u620f\u73a9\u6cd5\u5df2\u7ecf\u65e5\u8d8b\u6210\u719f, \u753b\u9762\u4e5f\u6709\u6bd4\u8f83\u5927\u7684\u63d0\u5347, \u5f88\u591a\u97f3\u753b\u4f53\u9a8c\u65f6\u81f3\u4eca\u65e5\u4e5f\u4e0d\u7b97\u8fc7\u65f6; \u53e6\u4e00\u65b9\u9762, \u6b64\u65f6\u5f00\u53d1\u6210\u672c\u8fd8\u6ca1\u6709\u50cf\u8fd1\u4e9b\u5e74\u6765\u4e00\u6837\u98d9\u5347, \u4e00\u4e9b\u6709\u610f\u601d\u7684\u5c0f\u54c1\u4f5c\u54c1\u8fd8\u6709\u76f8\u5bf9\u8f83\u5927\u7684\u751f\u5b58\u7a7a\u95f4; \u540c\u65f6\u5728\u8fd9\u4e2a\u4e16\u4ee3, \u4e3b\u673a\u8fd8\u5904\u4e8e\u76f8\u5bf9\u4f18\u52bf, \u5927\u91cf\u4f5c\u54c1\u8fd8\u662f\u4e3b\u8981\u4ee5\u4e3b\u673a\u5e73\u53f0\u4e3a\u6838\u5fc3\u5f00\u53d1\u7684.<\/p>\n<p>\u7efc\u4e0a\u6240\u8ff0, \u4e0b\u9762\u4f1a\u5217\u51fa\u4e00\u4e9b\u8fd8\u6bd4\u8f83\u503c\u5f97\u5728 PlayStation 4 Pro \u4e0a\u4f53\u9a8c\u7684\u6e38\u620f, \u5176\u4e2d\u4e2a\u4eba\u559c\u597d\u6bd4\u8f83\u91cd, \u4ec5\u4f9b\u53c2\u8003, \u4e3b\u8981\u5728 1080P \u7684\u5c4f\u5e55\u4e0b. \u5982\u679c\u6d89\u53ca\u591a\u5e73\u53f0, \u4e3b\u8981\u5bf9\u6bd4\u7684\u5bf9\u8c61\u662f PC \u548c <code>Nintendo Switch<\/code><\/p>\n<h2 id=\"ge-ren-tui-jian\"><a class=\"zola-anchor\" href=\"#ge-ren-tui-jian\" aria-label=\"Anchor link for: ge-ren-tui-jian\">\u4e2a\u4eba\u63a8\u8350<\/a><\/h2>\n<h3 id=\"ni-er-zi-dong-ren-xing-nia-otomata-nier-automata\"><a class=\"zola-anchor\" href=\"#ni-er-zi-dong-ren-xing-nia-otomata-nier-automata\" aria-label=\"Anchor link for: ni-er-zi-dong-ren-xing-nia-otomata-nier-automata\">\u5c3c\u5c14: \u81ea\u52a8\u4eba\u5f62 (\u30cb\u30fc\u30a2 \u30aa\u30fc\u30c8\u30de\u30bf, NieR:Automata)<\/a><\/h3>\n<p>\u767d\u91d1\u5de5\u4f5c\u5ba4, \u6807\u5fd7\u6027\u5934\u5957\u672c\u4f53\u6a2a\u5c3e\u592a\u90ce\u603b\u76d1\u7684\u52a8\u4f5c\u89d2\u8272\u626e\u6f14\u4f5c\u54c1, \u5f53\u5e74\u6027\u611f\u53ef\u7231\u7684 <code>2B<\/code> \u5c0f\u59d0\u59d0\u51e0\u4e4e\u6210\u4e3a\u7ebf\u4e0b\u6f2b\u5c55 Cosplay \u7684\u8c61\u5f81. \u867d\u7136\u5728 Steam \u4e0a\u4e5f\u6709(<a rel=\"external\" href=\"https:\/\/store.steampowered.com\/app\/524220\/NieRAutomata\/\">\u5728\u8fd9\u91cc<\/a>), \u63a8\u8350\u5728 PlayStation 4 Pro \u4e0a\u4f53\u9a8c\u7684\u539f\u56e0\u662f\u65e5\u672c\u5382\u5546\u6e38\u620f\u7684\u9ad8\u5b9a\u4ef7, \u6da8\u4ef7\u98ce\u6ce2\u548c\u5206\u5272\u5546\u6cd5, \u53e6\u5916, \u5728 PC \u4e0a\u4f53\u9a8c\u5f88\u5dee, \u79fb\u690d\u6bd4\u8f83\u66b4\u529b\u4f18\u5316\u4e0d\u4f73, \u65e0\u4e2d\u6587, \u800c\u4e14\u64cd\u4f5c\u903b\u8f91\u504f\u5411\u624b\u67c4\u64cd\u4f5c. \u5728 PS4 Pro \u4e0a\u53ef\u4ee5\u8fbe\u5230\u4e0d\u7a33\u5b9a\u7684 60 \u5e27, \u4e5f\u81ea\u5e26\u7e41\u4f53\u4e2d\u6587.<\/p>\n<h3 id=\"huang-ye-da-biao-ke-jiu-shu-red-dead-redemption\"><a class=\"zola-anchor\" href=\"#huang-ye-da-biao-ke-jiu-shu-red-dead-redemption\" aria-label=\"Anchor link for: huang-ye-da-biao-ke-jiu-shu-red-dead-redemption\">\u8352\u91ce\u5927\u9556\u5ba2: \u6551\u8d4e (Red Dead Redemption)<\/a><\/h3>\n<p>Rockstar \u7684\u7ecf\u5178\u897f\u90e8\u5f00\u653e\u4e16\u754c\u4f5c\u54c1, \u5267\u60c5\u9887\u53d7\u597d\u8bc4. \u5728 PS4 \u548c Switch \u4e0a\u79fb\u690d, \u4e5f\u6709\u767b\u9646 Steam (<a rel=\"external\" href=\"https:\/\/store.steampowered.com\/app\/2668510\/Red_Dead_Redemption\/\">\u5728\u8fd9\u91cc<\/a>), \u672c\u8eab\u662f\u7b2c\u4e03\u4e16\u4ee3\u7684\u4f5c\u54c1, \u6709\u4e00\u4e9b\u5728\u73b0\u4ee3\u73a9\u5bb6\u4e2d\u4e0d\u592a\u8ba8\u559c\u7684\u8bbe\u8ba1, \u79fb\u690d\u53ef\u4ee5\u8bf4\u662f\u539f\u6c41\u539f\u5473\u4e86. PlayStation 4 Pro \u4e0a\u6bd4 Switch \u753b\u9762\u6548\u679c\u548c\u6d41\u7545\u5ea6\u597d\u592a\u591a\u4e86. \u800c\u79fb\u690d\u540e\u672c\u8eab\u65e0\u8054\u7f51\u8981\u7d20, PC \u4e0a\u5374\u9700\u8981\u5f88\u8ba8\u538c\u7684 Rockstar \u542f\u52a8\u5668.<\/p>\n<h3 id=\"long-teng-shi-ji-shen-pan-dragon-age-inquisition\"><a class=\"zola-anchor\" href=\"#long-teng-shi-ji-shen-pan-dragon-age-inquisition\" aria-label=\"Anchor link for: long-teng-shi-ji-shen-pan-dragon-age-inquisition\">\u9f99\u817e\u4e16\u7eaa: \u5ba1\u5224 (Dragon Age: Inquisition)<\/a><\/h3>\n<p>BioWare \u7684\u4ee3\u8868\u4f5c, TGA \u7684 2014 \u5e74\u5ea6\u6e38\u620f, \u7b2c\u516b\u4e16\u4ee3\u65e9\u671f\u7684\u4f5c\u54c1, \u767b\u9646 Steam (<a rel=\"external\" href=\"https:\/\/store.steampowered.com\/app\/1222690\/_\/\">\u5728\u8fd9\u91cc<\/a>). PC \u4e0a\u6ca1\u6709\u4e2d\u6587, \u8fd8\u8981\u5b89\u88c5 EA \u7684\u542f\u52a8\u5668, \u8fd8\u6709\u989d\u5916\u7684 DRM. \u5728 PS4 Pro \u81ea\u5e26\u7e41\u4f53\u4e2d\u6587.<\/p>\n<h3 id=\"ci-ke-xin-tiao-ao-de-sai-assassin-s-creed-odyssey\"><a class=\"zola-anchor\" href=\"#ci-ke-xin-tiao-ao-de-sai-assassin-s-creed-odyssey\" aria-label=\"Anchor link for: ci-ke-xin-tiao-ao-de-sai-assassin-s-creed-odyssey\">\u523a\u5ba2\u4fe1\u6761: \u5965\u5fb7\u8d5b (Assassin's Creed Odyssey)<\/a><\/h3>\n<p>\u80b2\u78a7\u5e74\u8d27, \u4f46\u662f\u53e4\u5e0c\u814a\u7684\u80cc\u666f\u86ee\u5438\u5f15\u4eba\u7684. \u767b\u9646 Steam (<a rel=\"external\" href=\"https:\/\/store.steampowered.com\/app\/812140\/Assassins_Creed_Odyssey\/\">\u5728\u8fd9\u91cc<\/a>). PC \u4e0a\u9700\u8981 Ubisoft \u7684\u542f\u52a8\u5668\u548c\u989d\u5916\u7684 DRM.<\/p>\n<h3 id=\"lover-ravuaru\"><a class=\"zola-anchor\" href=\"#lover-ravuaru\" aria-label=\"Anchor link for: lover-ravuaru\">LoveR (\u30e9\u30f4\u30a2\u30fc\u30eb)<\/a><\/h3>\n<p>\u548c\u7f8e\u5c11\u5973\u8c08\u604b\u7231\u5e76\u4e14\u7ed9\u7f8e\u5c11\u5973\u62cd\u7167\u7684\u6e38\u620f. <code>\u7231\u76f8\u968f<\/code> \u7684\u4eba\u8bbe, <code>\u5723\u8bde\u4e4b\u543b<\/code>, <code>\u5199\u771f\u5973\u53cb<\/code> \u7684\u5236\u4f5c\u4eba, \u597d\u8036! \u76ee\u524d\u53ea\u6709 Switch \u548c PS4 \u7248\u672c, \u539f\u672c\u8ba1\u5212\u767b\u9646 Steam, \u4f46\u662f\u56e0\u4e3a\u67d0\u4e9b\u5927\u4eba\u7684\u539f\u56e0\u53d6\u6d88\u4e86. Switch \u7248\u672c\u867d\u7136\u6027\u611f\u5143\u7d20\u66f4\u591a, \u4f46\u662f\u753b\u8d28\u4f1a\u5dee\u4e00\u4e9b.<\/p>\n<h3 id=\"wang-da-yu-ju-xiang-wandatoju-xiang-shadow-of-the-colossus\"><a class=\"zola-anchor\" href=\"#wang-da-yu-ju-xiang-wandatoju-xiang-shadow-of-the-colossus\" aria-label=\"Anchor link for: wang-da-yu-ju-xiang-wandatoju-xiang-shadow-of-the-colossus\">\u6c6a\u8fbe\u4e0e\u5de8\u50cf (\u30ef\u30f3\u30c0\u3068\u5de8\u50cf, Shadow of the Colossus)<\/a><\/h3>\n<p>PlayStation \u7cfb\u72ec\u5360\u7684\u7ecf\u5178\u4f5c\u54c1, \u672c\u8eab\u662f PS2 \u4e0a\u7684\u6e38\u620f, \u5728 PS3 \u4e0a\u9ad8\u6e05\u5316,\u5728 PS4 \u4e0a\u63a8\u51fa\u5b8c\u5168\u91cd\u5236\u7248, \u76ee\u524d\u4f53\u9a8c\u7684\u552f\u4e00\u6700\u4f73\u9014\u5f84. \u867d\u7136\u67d0\u4e9b\u64cd\u4f5c\u5728\u73b0\u4ee3\u73a9\u5bb6\u770b\u6765\u7565\u663e\u7b28\u62d9, \u4f46\u662f\u6e38\u620f\u7ed9\u4eba\u5e26\u6765\u7684\u975e\u5e38\u827a\u672f\u5316\u7684\u6c89\u6d78\u5f0f\u7684\u4f53\u9a8c\u548c\u53f2\u8bd7\u611f\u662f\u7edd\u5bf9\u7269\u6709\u6240\u503c\u7684.<\/p>\n<h3 id=\"kai-se-lin-nong-yu-kou-gan-catherine-full-body\"><a class=\"zola-anchor\" href=\"#kai-se-lin-nong-yu-kou-gan-catherine-full-body\" aria-label=\"Anchor link for: kai-se-lin-nong-yu-kou-gan-catherine-full-body\">\u51ef\u745f\u7433 \u6d53\u90c1\u53e3\u611f (CATHERINE Full Body)<\/a><\/h3>\n<p>Atlus \u63a8\u51fa\u7684\u63a8\u7bb1\u5b50\u89e3\u8c1c\u6e38\u620f, \u539f\u7248\u662f\u7b2c\u4e03\u4e16\u4ee3\u7684\u4f5c\u54c1, \u672c\u4f5c\u4e3a\u5176\u540e\u63a8\u51fa\u7684\u5f3a\u5316\u7248. \u73a9\u6cd5\u4e0d\u90a3\u4e48\u53d7\u6b22\u8fce\u7684\u5b9e\u9a8c\u6027\u8d28\u7684\u4f5c\u54c1, \u4f46\u662f\u5267\u60c5\u548c\u5bf9\u4e8e\u4e24\u6027\u5173\u7cfb\u7684\u523b\u753b\u4e0e\u601d\u8003\u86ee\u6709\u610f\u601d. \u867d\u7136\u4e5f\u767b\u9646\u4e86 Steam (<a rel=\"external\" href=\"https:\/\/store.steampowered.com\/app\/893180\/Catherine_Classic\/\">\u5728\u8fd9\u91cc<\/a>), \u4f46\u90a3\u662f\u539f\u7248\u800c\u975e\u5f3a\u5316\u7248, \u800c\u4e14\u79fb\u690d\u86ee\u7cdf\u7cd5\u7684. \u5f3a\u5316\u7248\u5728 Switch \u4e0a\u4e5f\u53ef\u4f53\u9a8c.<\/p>\n<h3 id=\"zhong-li-yi-xiang-shi-jie-wan-jie-pian-gravity-daze-2-zhong-li-de-xuan-yun-wan-jie-bian-shang-ceng-henogui-huan-noguo-te-bi-nu-nonei-yu-zhou-nishou-lian-sitaxuan-ze\"><a class=\"zola-anchor\" href=\"#zhong-li-yi-xiang-shi-jie-wan-jie-pian-gravity-daze-2-zhong-li-de-xuan-yun-wan-jie-bian-shang-ceng-henogui-huan-noguo-te-bi-nu-nonei-yu-zhou-nishou-lian-sitaxuan-ze\" aria-label=\"Anchor link for: zhong-li-yi-xiang-shi-jie-wan-jie-pian-gravity-daze-2-zhong-li-de-xuan-yun-wan-jie-bian-shang-ceng-henogui-huan-noguo-te-bi-nu-nonei-yu-zhou-nishou-lian-sitaxuan-ze\">\u91cd\u529b\u5f02\u60f3\u4e16\u754c\u5b8c\u7ed3\u7bc7 (GRAVITY DAZE 2\/\u91cd\u529b\u7684\u7729\u6688\u5b8c\u7d50\u7de8:\u4e0a\u5c64\u3078\u306e\u5e30\u9084\u306e\u679c\u3066\u3001\u5f7c\u5973\u306e\u5185\u5b87\u5b99\u306b\u53ce\u6582\u3057\u305f\u9078\u629e)<\/a><\/h3>\n<p>PS4 \u72ec\u5360. \u8fd9\u662f\u4e8c\u4ee3, PS4 \u4e0a\u4e5f\u6709\u4ece PS Vita \u79fb\u690d\u7684\u4e00\u4ee3. \u4f53\u611f\u548c\u624b\u67c4\u7684\u91cd\u529b\u64cd\u63a7\u73a9\u6cd5\u548c\u65e5\u5f0f\u7f8e\u672f\u98ce\u683c, \u5e26\u6765\u72ec\u7279\u4f53\u9a8c\u7684\u4f5c\u54c1.<\/p>\n<h3 id=\"ao-ding-ling-yu-li-pu-te-la-xi-er-odeinsuhuia-reivusurasiru-odin-sphere-leifthrasir\"><a class=\"zola-anchor\" href=\"#ao-ding-ling-yu-li-pu-te-la-xi-er-odeinsuhuia-reivusurasiru-odin-sphere-leifthrasir\" aria-label=\"Anchor link for: ao-ding-ling-yu-li-pu-te-la-xi-er-odeinsuhuia-reivusurasiru-odin-sphere-leifthrasir\">\u5965\u4e01\u9886\u57df: \u91cc\u666e\u7279\u62c9\u897f\u5c14 (\u30aa\u30fc\u30c7\u30a3\u30f3\u30b9\u30d5\u30a3\u30a2 \u30ec\u30a4\u30f4\u30b9\u30e9\u30b7\u30eb, Odin Sphere: Leifthrasir)<\/a><\/h3>\n<p>PlayStation \u7cfb\u72ec\u5360, \u4ece PS2 \u4e0a\u7684\u539f\u7248\u91cd\u5236\u800c\u6765. \u9999\u8349\u793e\u65e0\u9700\u591a\u8a00, \u534e\u4e3d\u7684\u624b\u7ed8\u98ce\u683c\u7684 2D \u6a2a\u7248\u5377\u8f74\u52a8\u4f5c\u6e38\u620f.<\/p>\n<h3 id=\"kan-men-gou-watch-dogs\"><a class=\"zola-anchor\" href=\"#kan-men-gou-watch-dogs\" aria-label=\"Anchor link for: kan-men-gou-watch-dogs\">\u770b\u95e8\u72d7 (Watch Dogs)<\/a><\/h3>\n<p>\u80b2\u78a7\u516c\u5f0f\u5316\u5f00\u653e\u4e16\u754c, \u4f46\u662f\u7ed3\u5408\u9ed1\u5ba2\/\u5f00\u653e\u4e16\u754c\/\u73b0\u4ee3\u90fd\u5e02\u4f53\u9a8c\u5143\u7d20\u7684\u76ee\u524d\u5c31\u6b64\u4e00\u5bb6. \u8fd9\u4e2a\u7cfb\u5217\u7684\u7ecf\u5386\u5728\u7b2c\u516b\u4e16\u4ee3\u9887\u6709\u4ee3\u8868\u6027, \u770b\u95e8\u72d7\u672c\u8eab\u662f\u65b0 IP, \u9996\u90e8\u662f PS4 \u65e9\u671f\u7684\u4f5c\u54c1, \u5ba3\u4f20\u65f6\u753b\u9762\u5341\u5206\u60ca\u8273, \u8ba9\u4eba\u4eec\u5bf9\u5373\u5c06\u5230\u6765\u7684\u7b2c\u516b\u4e16\u4ee3\u4e3b\u673a\u7684\u6027\u80fd\u5145\u6ee1\u671f\u5f85, \u7136\u800c\u5b9e\u9645\u53d1\u552e\u540e\u753b\u9762\u8868\u73b0\u7f29\u6c34\u4e25\u91cd. \u7b2c\u4e8c\u90e8\u5219\u662f\u6362\u4e00\u5957\u80cc\u666f\u7ee7\u7eed\u516c\u5f0f\u5316\u51fa\u88c5, \u4e30\u5bcc\u4e86\u73a9\u6cd5, \u7b97\u662f\u4e2d\u89c4\u4e2d\u77e9\u7684\u63d0\u5347. \u800c\u6700\u65b0\u7684 2020 \u5e74\u7684\u7b2c\u4e09\u90e8 &lt;\u770b\u95e8\u72d7: \u519b\u56e2&gt; \u5219\u56e0\u4e3a\u5546\u4e1a\u548c\u7ba1\u7406\u4e0a\u7684\u95ee\u9898, \u5f88\u5927\u53ef\u80fd\u662f\u4e3a\u4e86\u7ebf\u4e0a\u6a21\u5f0f, \u5bfc\u81f4\u6574\u4f53\u8868\u73b0\u4e0d\u4f73, \u76ee\u524d\u8fd9\u4e2a IP \u77ed\u671f\u5185\u65e0\u91cd\u542f\u7684\u5e0c\u671b. PC \u4e0a\u5219\u8fd8\u8981\u9762\u4e34\u4f18\u5316\u4e0d\u4f73, \u5bf9 Windows \u7cfb\u7edf\u5347\u7ea7\u4e0d\u505a\u9002\u914d, \u4e2d\u6587\u5316\u62d6\u62d6\u62c9\u62c9\u7684\u95ee\u9898, \u64cd\u4f5c\u4e5f\u4e3b\u8981\u9762\u5411\u624b\u67c4. Steam \u7248\u672c(<a rel=\"external\" href=\"https:\/\/store.steampowered.com\/app\/243470\/Watch_Dogs\/\">\u5728\u8fd9\u91cc<\/a>)\u8fd8\u8981\u5e26\u4e0a\u4e00\u4e2a\u9648\u65e7\u7684\u80b2\u78a7\u542f\u52a8\u5668.<\/p>\n<h2 id=\"sui-sui-nian\"><a class=\"zola-anchor\" href=\"#sui-sui-nian\" aria-label=\"Anchor link for: sui-sui-nian\">\u788e\u788e\u5ff5<\/a><\/h2>\n<p>\u867d\u7136\u5176\u5b9e\u5f88\u65e9\u5c31\u63a5\u89e6\u4e3b\u673a\u6e38\u620f\u4e86, \u5c0f\u65f6\u5019\u5728<del>\u5bcc\u88d5<\/del>\u8868\u54e5\u5bb6\u91cc\u73a9\u8fc7 <code>SFC<\/code>, <code>Mega Drive<\/code> \u548c <code>PlayStation 2<\/code>, \u638c\u673a\u4e5f\u66fe\u62e5\u6709\u8fc7 <code>Gameboy Advance<\/code>, <code>PlayStation Portable<\/code> \u548c <code>Nintendo DS<\/code>, \u4f46\u662f\u7b2c\u516b\u4e16\u4ee3\u7684\u6e38\u620f\u7559\u4e0b\u7684\u5370\u8c61\u8fd8\u662f\u9887\u4e3a\u6df1\u523b. \u4e3b\u8981\u8fd8\u662f\u56e0\u4e3a\u90a3\u65f6\u4e0a\u4e86\u5927\u5b66, \u6709\u6bd4\u8f83\u5145\u8db3\u7684\u65f6\u95f4\u73a9\u6e38\u620f. \u4e0e\u6b64\u540c\u65f6, Steam \u5f00\u59cb\u652f\u6301\u4eba\u6c11\u5e01\u652f\u4ed8, \u8d2d\u4e70\u6e38\u620f\u65b9\u4fbf\u4e86\u5f88\u591a, \u6211\u8fd8\u8bb0\u5f97\u4e4b\u524d\u901a\u8fc7 <code>\u9a91\u9a6c\u4e0e\u780d\u6740\u4e2d\u6587\u7f51<\/code> \u4e70\u4e00\u4efd\u6b63\u7248\u7684 &lt;\u9a91\u9a6c\u4e0e\u780d\u6740&gt; \u591a\u4e48\u4e0d\u65b9\u4fbf. \u90a3\u4e2a\u4e16\u4ee3\u7684\u6e38\u620f, \u4e5f\u6709\u90a3\u4e2a\u4e16\u4ee3\u7684\u7279\u5f81, \u4e0d\u91cd\u89c6\u4e2d\u6587\u73a9\u5bb6, \u4e3b\u673a\u72ec\u5360\u7b56\u7565, \u4e3b\u673a\u4f18\u5148\u5bfc\u81f4\u7684\u4f18\u5316\u4ee5\u53ca\u64cd\u4f5c\u95ee\u9898, \u90e8\u5206\u5382\u5546\u6fc0\u8fdb\u7684\u8054\u7f51\u5316\u548c\u5e73\u53f0\u5316\u7b56\u7565, \u9632\u76d7\u7248\u7b56\u7565. \u4e0d\u8fc7\u8fd8\u662f\u5e0c\u671b\u80fd\u6709\u66f4\u591a\u4eba, \u80fd\u4f53\u4f1a\u5230\u90a3\u4e2a\u4e16\u4ee3\u7684\u6e38\u620f\u7684\u5feb\u4e50.<\/p>\n<h2 id=\"can-kao\"><a class=\"zola-anchor\" href=\"#can-kao\" aria-label=\"Anchor link for: can-kao\">\u53c2\u8003<\/a><\/h2>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/bbs.oldmantvg.net\/thread-12311.htm\">555\u4f59\u6b3e\u6e38\u620f\u5728PS4\u3001PS4 PRO\u3001PS5\u4e0a\u7684\u5206\u8fa8\u7387\u5e27\u6570\u7edf\u8ba1\u6c47\u603b<\/a><\/li>\n<\/ul>\n"},{"title":"\u70b8\u9e21\u4e0e\u897f\u74dc","published":"2025-08-07T21:46:01+09:00","updated":"2025-08-07T21:46:01+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/watermelon-and-fried-chicken\/"}},"id":"https:\/\/memwey.github.io\/posts\/watermelon-and-fried-chicken\/","content":"<p>\u5728\u7f8e\u56fd, \u70b8\u9e21\u548c\u897f\u74dc\u6709\u7279\u522b\u7684\u610f\u4e49.<\/p>\n<p>\u5974\u96b6\u5236\u65f6\u671f, \u897f\u74dc\u548c\u9e21\u56e0\u4e3a\u5ec9\u4ef7, \u662f\u5c11\u6570\u9ed1\u4eba\u5974\u96b6\u53ef\u4ee5\u63a5\u89e6\u7684\u98df\u7269. \u968f\u7740\u9ed1\u4eba\u5974\u96b6\u7684\u89e3\u653e, \u897f\u74dc\u548c\u70b8\u9e21\u4e5f\u6210\u4e3a\u4e86\u8bb8\u591a\u975e\u88d4\u7f8e\u56fd\u4eba\u7684\u751f\u8ba1, \u4ee3\u8868\u4ed6\u4eec\u7684\u81ea\u7531\u4e0e\u7ecf\u6d4e\u72ec\u7acb. \u540c\u65f6, \u8bb8\u591a\u767d\u4eba\u79cd\u65cf\u4e3b\u4e49\u8005\u4ee5\u70b8\u9e21\u548c\u897f\u74dc\u6765\u4e11\u5316\u548c\u4fae\u8fb1\u975e\u88d4\u7f8e\u56fd\u4eba, \u5851\u9020\u4ed6\u4eec\u539f\u59cb, \u61d2\u60f0, \u8d2a\u5a6a\u548c\u7c97\u4fd7\u7684\u5f62\u8c61.<\/p>\n<p>\u867d\u7136\u9ed1\u4eba\u6c11\u6743\u8fd0\u52a8\u540e\u975e\u88d4\u7f8e\u56fd\u4eba\u7684\u72b6\u51b5\u5df2\u6709\u663e\u8457\u6539\u5584, \u897f\u74dc\u548c\u70b8\u9e21\u5728\u7279\u5b9a\u8bed\u5883\u4e0b\u4ecd\u53ef\u80fd\u88ab\u7528\u4e8e\u91cd\u73b0\u5386\u53f2\u4e0a\u7684\u79cd\u65cf\u523b\u677f\u5370\u8c61.<\/p>\n<p>\u4e0d\u8fc7, \u597d\u5403\u7684\u5c31\u662f\u597d\u5403\u7684, \u66f4\u4e0d\u5fc5\u8bf4\u8fd9\u5176\u4e2d\u5bc4\u6258\u7740\u5bf9\u81ea\u7531\u548c\u5e73\u7b49\u7684\u8ffd\u6c42\u66f4\u6dfb\u7f8e\u5473, \u7ed9\u6211\u518d\u6765\u4e00\u4efd\u8461\u8404\u6c7d\u6c34.<\/p>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/watermelon-and-fried-chicken\/images\/pic.jpg\" alt=\"pic\" \/><\/p>\n"},{"title":"Windsurf \u5165\u95e8\u6307\u5357","published":"2025-06-14T18:30:10+09:00","updated":"2025-07-28T10:58:23+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/first-step-with-windsurf\/"}},"id":"https:\/\/memwey.github.io\/posts\/first-step-with-windsurf\/","content":"<h2 id=\"wei-shen-me-shi-windsurf\"><a class=\"zola-anchor\" href=\"#wei-shen-me-shi-windsurf\" aria-label=\"Anchor link for: wei-shen-me-shi-windsurf\">\u4e3a\u4ec0\u4e48\u662f Windsurf<\/a><\/h2>\n<p>\u66fe\u7ecf\u53eb <code>Codeium<\/code>, \u5728 2022 \u5e74\u8fd8\u662f <code>Github Copilot<\/code> \u7684\u65f6\u4ee3\u5373\u63d0\u4f9b\u652f\u6301 <code>VS Code<\/code> \u548c <code>JetBrains<\/code> \u7684 AI \u7f16\u7a0b\u5de5\u5177\u63d2\u4ef6; \u4e8e 2024 \u5e74\u63a8\u51fa\u7c7b\u4f3c\u4e8e <code>Cursor<\/code> \u7684\u57fa\u4e8e <code>VS Code<\/code> \u7684 IDE <code>Windsurf<\/code>, \u968f\u540e\u5c06\u516c\u53f8\u66f4\u540d<\/p>\n<ul>\n<li>\u514d\u8d39\u7684\u57fa\u7840\u4f7f\u7528\u548c\u66f4\u4fbf\u5b9c\u7684\u8ba2\u9605\u4ef7\u683c<\/li>\n<li>\u548c <code>Cursor<\/code> <del>\u4e92\u76f8\u6284<\/del> \u529f\u80fd\u6ca1\u592a\u5927\u533a\u522b<\/li>\n<li>\u88ab <code>OpenAI<\/code> \u4ee5\u7ea630\u4ebf\u7f8e\u5143\u6536\u8d2d<\/li>\n<\/ul>\n<blockquote>\n<p>\u76ee\u524d\u544a\u5439, \u516c\u53f8\u6838\u5fc3\u6210\u5458\u88ab <code>Google<\/code> \u6316\u8d70\u540e\u5f00\u53d1 <code>Devin AI<\/code> \u7684 <code>Cognition<\/code> \u6536\u8d2d\u4e86\u516c\u53f8, <del>\u7136\u540e\u5f00\u59cb\u4e86\u75af\u72c2\u52a0\u73ed<\/del><\/p>\n<\/blockquote>\n<ul>\n<li>\u88ab <code>Anthropic<\/code> \u65ad\u4f9b<del>\u9ad8\u7aef\u7684 AI \u5546\u6218<\/del>, \u76ee\u524d\u4e0d\u80fd\u4f7f\u7528 <code>Claude 4<\/code>, <del>\u88ab\u6536\u8d2d\u4e4b\u540e\u6062\u590d\u4e86<\/del><\/li>\n<\/ul>\n<blockquote>\n<p><code>Cursor<\/code> \u76f8\u5173\u7684\u4fe1\u606f\u6c61\u67d3\u592a\u5389\u5bb3\u4e86, \u4e54\u6208\u91cc\u5cf0\u95ee\u9898<\/p>\n<\/blockquote>\n<p>\u6700\u8fd1\u6211\u53d1\u73b0 <code>TREA<\/code> \u597d\u50cf\u66f4\u597d\u7528, \u95ee\u9898\u4f3c\u4e4e\u51fa\u5728 <code>Windsurf<\/code> \u914d\u7f6e\u7684\u4e0a\u4e0b\u6587\u592a\u77ed\u4e86, <del>Kiro \u5927\u6cd5\u597d<\/del><\/p>\n<h2 id=\"zhu-yao-gong-neng\"><a class=\"zola-anchor\" href=\"#zhu-yao-gong-neng\" aria-label=\"Anchor link for: zhu-yao-gong-neng\">\u4e3b\u8981\u529f\u80fd<\/a><\/h2>\n<p>\u76f8\u6bd4\u63d2\u4ef6\u66f4\u597d\u7684\u4ee3\u7801\u4e0a\u4e0b\u6587\u611f\u77e5 <code>Context Awareness<\/code>, \u8bb0\u5fc6\u80fd\u529b, \u8c03\u7528\u7b2c\u4e09\u65b9\u5de5\u5177\u80fd\u529b<\/p>\n<h3 id=\"tab\"><a class=\"zola-anchor\" href=\"#tab\" aria-label=\"Anchor link for: tab\">Tab<\/a><\/h3>\n<p>\u8865\u5168, \u8df3\u8f6c, \u5bfc\u5165<\/p>\n<h3 id=\"command\"><a class=\"zola-anchor\" href=\"#command\" aria-label=\"Anchor link for: command\">Command<\/a><\/h3>\n<p>\u5524\u51fa\u8f93\u5165\u6846\u8f93\u5165\u6307\u4ee4, \u9002\u7528\u4e8e\u5f53\u524d\u6587\u4ef6\u8303\u56f4\u5185\u7684\u4fee\u6539, \u4f5c\u7528\u4e8e\u5f53\u524d\u6e38\u6807\u4f4d\u7f6e\u6216\u9009\u4e2d\u7684\u4ee3\u7801\u6bb5<\/p>\n<blockquote>\n<p>\u5c0f\u6280\u5de7, \u5728\u6ce8\u91ca\u4e2d\u5199\u5165\u6307\u4ee4, \u7136\u540e <code>Cmd\/Ctrl+I<\/code> \u968f\u540e\u4f7f\u7528\u7c7b\u4f3c <code>do it<\/code> \u8fd9\u6837\u7684\u7b80\u5355\u6307\u4ee4\u5373\u53ef<\/p>\n<\/blockquote>\n<h3 id=\"cascade\"><a class=\"zola-anchor\" href=\"#cascade\" aria-label=\"Anchor link for: cascade\">Cascade<\/a><\/h3>\n<p>\u9879\u76ee\u8303\u56f4\u7684\u5927\u89c4\u6a21\u7406\u89e3\u4e0e\u8c03\u6574, \u53ef\u4ee5\u8fd0\u884c\u547d\u4ee4\u884c, \u7f51\u7edc\u68c0\u7d22\u7b49\u5de5\u5177, \u4e5f\u53ef\u4ee5\u901a\u8fc7 <code>MCP<\/code> \u534f\u8bae\u8c03\u7528\u5916\u90e8\u5de5\u5177<\/p>\n<ul>\n<li>Planning Mode: \u5c06\u8ba1\u5212\u8f93\u51fa\u5230 Markdown \u6587\u4ef6, \u4fbf\u4e8e\u8c03\u6574\u548c\u957f\u6d41\u7a0b\u5904\u7406<\/li>\n<li>Browser: \u8bfb\u6587\u6863, \u83b7\u53d6\u7f51\u9875\u5185\u5bb9; \u524d\u7aef\u5f00\u53d1<\/li>\n<\/ul>\n<h3 id=\"zong-jie\"><a class=\"zola-anchor\" href=\"#zong-jie\" aria-label=\"Anchor link for: zong-jie\">\u603b\u7ed3<\/a><\/h3>\n<p>\u4e09\u4e2a\u529f\u80fd\u4ece\u4e0a\u5230\u4e0b, \u9700\u8981\u7684\u4eba\u5de5\u7684\u8f93\u5165\u8d8a\u6765\u8d8a\u591a, \u4e0a\u4e0b\u6587\u611f\u77e5\u8981\u6c42\u8d8a\u6765\u8d8a\u5f3a, \u6d41\u7a0b\u548c\u5904\u7406\u65f6\u95f4\u8d8a\u6765\u8d8a\u957f, \u6839\u636e\u9002\u5f53\u60c5\u51b5\u9009\u62e9\u9002\u5f53\u7684\u529f\u80fd<\/p>\n<h2 id=\"yuan-li-yu-ju-xian\"><a class=\"zola-anchor\" href=\"#yuan-li-yu-ju-xian\" aria-label=\"Anchor link for: yuan-li-yu-ju-xian\">\u539f\u7406\u4e0e\u5c40\u9650<\/a><\/h2>\n<p>\u795e\u7ecf\u7f51\u7edc\u7684\u4eff\u751f\u5b66\u539f\u7406, \u751f\u7269\u795e\u7ecf\u7cfb\u7edf\u5b58\u5728\u5927\u91cf\u901a\u8fc7\u7a81\u89e6\u8fde\u63a5\u7684\u795e\u7ecf\u5143, \u7279\u5b9a\u795e\u7ecf\u6d3b\u52a8\u4f7f\u5173\u8054\u7684\u795e\u7ecf\u5143\u7a81\u89e6\u4ea7\u751f\u53ef\u5851\u6027\u53d8\u5316, \u662f\u8bb0\u5fc6\u548c\u8ba4\u77e5\u7684\u57fa\u7840; \u795e\u7ecf\u7f51\u7edc\u901a\u8fc7\u6570\u5b66\u6a21\u578b, \u7528\u4e8e\u7f16\u7801\u8f93\u5165\u4e0e\u8f93\u51fa\u4e4b\u95f4\u7684\u6982\u7387\u5173\u8054, \u672c\u8d28\u662f\u6570\u636e\u7edf\u8ba1\u4e0a\u7684\u5173\u8054; \u751f\u7269\u7684\u795e\u7ecf\u7cfb\u7edf\u7684\u5b66\u4e60\u8fc7\u7a0b\u662f\u6301\u7eed\u53d1\u751f\u7684, \u5b66\u4e60\u4e0e\u4f7f\u7528\u5e76\u975e\u622a\u7136\u5206\u5f00, \u800c\u5f53\u524d\u7684\u5927\u8bed\u8a00\u6a21\u578b\u901a\u5e38\u5c06\"\u8bad\u7ec3\"\u4e0e\"\u63a8\u7406\"\u4e25\u683c\u5206\u79bb, \u53c2\u6570\u5728\u8bad\u7ec3\u540e\u5373\u56fa\u5b9a, \u6240\u4ee5\u4e0d\u8981\u5c1d\u8bd5\"\u6559\u4f1a\"\u5b83, \u56e0\u4e3a\u5b83\u77e5\u9053\u9519\u4e86\u4e5f\u4e0d\u4f1a\u6539, \u800c\u662f\u8981\u901a\u8fc7 <code>prompt<\/code> \u63d0\u4f9b\u4e0a\u4e0b\u6587\u4fe1\u606f, \u4f7f\u5176\u5728\u6709\u9650\u7684\u4e0a\u4e0b\u6587\u7a97\u53e3\u4e2d\u505a\u51fa\u5408\u7406\u54cd\u5e94<\/p>\n<ul>\n<li>\u4e0a\u4e0b\u6587\u80fd\u529b\u957f\u5ea6\u7684\u9650\u5236, \u4e0a\u4e0b\u6587\u9650\u5236\u4e0d\u4ec5\u5728\u8f93\u5165\u7aef, \u540c\u65f6\u5728\u4e2d\u95f4\u72b6\u6001\u4e0e\u8f93\u51fa\u7aef, \u6240\u4ee5\u5927\u6a21\u578b\u80fd\u7cbe\u51c6\u5229\u7528\u7684\u6709\u6548\u4e0a\u4e0b\u6587\u4f1a\u660e\u663e\u6bd4\u6807\u793a\u7684\u4e0a\u4e0b\u6587 <code>token<\/code> \u53c2\u6570\u5c0f<\/li>\n<li>\u6ce8\u610f\u529b\u673a\u5236, <code>&lt;Attention is All You Need&gt;<\/code>, \u4f46\u662f <code>Attention<\/code> \u4e0d\u662f <code>Understanding<\/code>, \u65e0\u6cd5\u4e3b\u52a8\u533a\u5206\u91cd\u70b9\u4e0e\u7ec6\u8282, \u53ea\u662f\u6839\u636e\u8bad\u7ec3\u7edf\u8ba1\u6a21\u5f0f\u505a <code>token<\/code> \u7ea7\u522b\u7684\u9884\u6d4b<\/li>\n<li>\u7f3a\u4e4f\u957f\u671f\u8bb0\u5fc6\u673a\u5236, \u4e0d\u80fd\u81ea\u53d1\u79ef\u7d2f\u8de8 <code>Session<\/code> \u7ecf\u9a8c\u548c\u77e5\u8bc6, \u9700\u8981\u5916\u90e8\u8bb0\u5fc6\u6a21\u5757<\/li>\n<\/ul>\n<blockquote>\n<p>\u4e25\u683c\u6765\u8bf4\u6a21\u578b\u662f\u53ef\u4ee5\u505a\u8f7b\u91cf\u5fae\u8c03(PEFT)\u7684<\/p>\n<\/blockquote>\n<p>\u5927\u8bed\u8a00\u6a21\u578b\u662f\u9ad8\u6027\u80fd\u7684\u7edf\u8ba1\u5173\u8054\u5f15\u64ce, \u5176\u8f93\u51fa\u672c\u8d28\u662f\"\u6709\u7ed3\u6784\u7684\u5e7b\u89c9\" - \u6768\u7acb\u6606\u7684\u89c2\u70b9<\/p>\n<h2 id=\"zui-jia-shi-jian\"><a class=\"zola-anchor\" href=\"#zui-jia-shi-jian\" aria-label=\"Anchor link for: zui-jia-shi-jian\">\u6700\u4f73\u5b9e\u8df5<\/a><\/h2>\n<h3 id=\"bi-yu\"><a class=\"zola-anchor\" href=\"#bi-yu\" aria-label=\"Anchor link for: bi-yu\">\u6bd4\u55bb<\/a><\/h3>\n<p>\u7528 minori \u7684 &lt;ef - a fairy tale of the two.&gt; \u7684\u60c5\u8282\u6765\u63cf\u8ff0\u5927\u6a21\u578b\u975e\u5e38\u5408\u9002. \u65b0\u85e4\u5343\u5bfb\u5728 12 \u5c81\u65f6\u7531\u4e8e\u4e8b\u6545\u60a3\u4e0a\u987a\u884c\u6027\u9057\u5fd8\u75c7, \u4ece\u90a3\u4ee5\u540e\u7684\u4e8b\u60c5\u5979\u53ea\u80fd\u8bb0\u4f4f\u4ece\u5f53\u65f6\u5f80\u524d\u63a8\u7b97\u7684 13 \u4e2a\u5c0f\u65f6. \u6bcf\u4e00\u4e2a\u6e05\u6668\u9192\u6765, \u5979\u90fd\u5fc5\u987b\u91cd\u65b0\u9605\u8bfb\u81ea\u5df1\u7684\u65e5\u8bb0\uff0c\u4ece\u4e2d\u5bfb\u627e\"\u6211\"\u7684\u7ebf\u7d22, \u5e76\u5728\u65e5\u8bb0\u672c\u4e0a\u4e0d\u65ad\u7eed\u5199\u5979\u81ea\u5df1. \u5c11\u5e74\u9ebb\u751f\u83b2\u6cbb\u5728\u8f66\u7ad9\u4e0e\u5176\u76f8\u9047, \u4e24\u4eba\u7684\u8ddd\u79bb\u5728\u4e0d\u65ad\u7684\u76f8\u8bc6\u4e0e\u9057\u5fd8\u4e2d\u9010\u6e10\u7f29\u77ed, \u7ecf\u8fc7\u6323\u624e\u548c\u72b9\u8c6b\u4e24\u4e2a\u4eba\u6700\u7ec8\u8d70\u5230\u4e86\u4e00\u8d77. \u8fd9\u6bb5\u7231\u60c5\u4e5f\u5e26\u7740\u67d0\u79cd\u6096\u8bba\u5f0f\u7684\u60b2\u4f24, \u5bf9\u4e8e\u83b2\u6cbb\u6765\u8bf4, \u4ed6\u65e0\u6bd4\u559c\u6b22\u5343\u5bfb, \u4f46\u662f\u67d0\u79cd\u610f\u4e49\u4e0a\u6765\u8bf4, \u5343\u5bfb\u53ea\u662f\u5728\u626e\u6f14\u65e5\u8bb0\u672c\u4e2d\u90a3\u4e2a\u559c\u6b22\u83b2\u6cbb\u7684\u81ea\u5df1.<\/p>\n<h3 id=\"ri-ji-ben\"><a class=\"zola-anchor\" href=\"#ri-ji-ben\" aria-label=\"Anchor link for: ri-ji-ben\">\u65e5\u8bb0\u672c<\/a><\/h3>\n<p>\u6240\u4ee5\u5f52\u6839\u5230\u5e95, \u662f\u8981\u7ed9<del>\u7f8e\u5c11\u5973<\/del>\u5927\u6a21\u578b\u63d0\u4f9b\u4f18\u5316\u8fc7\u7684<del>\u65e5\u8bb0\u672c<\/del><code>prompt<\/code><\/p>\n<ul>\n<li>\u603b\u662f\u4f7f\u7528 Markdown \u5199\u6587\u6863, \u5927\u8bed\u8a00\u6a21\u578b\u5bf9\u5176\u6709\u4f18\u5316<\/li>\n<li>\u4e00\u81f4\u7684\u9879\u76ee\u7ed3\u6784\u4e0e\u547d\u540d\u89c4\u8303<\/li>\n<li>\u63d0\u4f9b\u9879\u76ee\u7684\u7ed3\u6784\u548c\u529f\u80fd\u7684\u63cf\u8ff0, <code>User Story<\/code>, <code>Product Requirement Document<\/code>, \u8bb0\u5f55\u51b3\u7b56\u4e0e\u7ea6\u5b9a<\/li>\n<li>\u663e\u5f0f\u4e14\u51c6\u786e\u7684\u63d0\u4f9b\u5b8c\u6210\u4efb\u52a1\u6240\u9700\u7684\u4e0a\u4e0b\u6587\u5185\u5bb9\u548c\u5de5\u5177\u8c03\u7528, \u5584\u7528<code>@<\/code>\u63d0\u793a<\/li>\n<li>\u79ef\u6781\u7684\u4f7f\u7528 <code>Workflow<\/code> \u548c <code>Rule<\/code> \u529f\u80fd, \u5b9e\u9645\u4e0a\u5c31\u662f\u6a21\u7248\u5316\u6807\u51c6\u5316\u7684 <code>prompt<\/code> \u7684\u5e94\u7528<\/li>\n<li><del>Prompt Engineering is Dead, everything is a Spec.<\/del><\/li>\n<\/ul>\n<h3 id=\"zi-wo-qiang-hua\"><a class=\"zola-anchor\" href=\"#zi-wo-qiang-hua\" aria-label=\"Anchor link for: zi-wo-qiang-hua\">\u81ea\u6211\u5f3a\u5316<\/a><\/h3>\n<ul>\n<li>\u8ba9\u6a21\u578b\u81ea\u5df1\u8fdb\u884c\u603b\u7ed3\u5f52\u7eb3, \u505a\u624b\u52a8\u8c03\u6574, \u518d\u4f5c\u4e3a <code>prompt<\/code> \u7ed9\u5230\u6a21\u578b\u4e0a\u4e0b\u6587, \u4ee5\u6b64\u5faa\u73af<\/li>\n<li>\u538b\u7f29 <code>prompt<\/code>, \u5e76\u4e14\u8ba9\u6a21\u578b\u81ea\u5df1\u6765\u9a8c\u8bc1\u5b83\u662f\u5426\u7406\u89e3 <code>prompt<\/code><\/li>\n<li>\u6e10\u8fdb\u5f0f\u7684\u4efb\u52a1\u5206\u89e3\u63d0\u793a, \u5206\u6b65\u9aa4\u7684\u63d0\u793a\u548c\u6307\u4ee4, \u8ba9\u6a21\u578b\u81ea\u5df1\u6765\u505a\u6d41\u7a0b\u7684\u5b8c\u6210\u60c5\u51b5\u7ef4\u62a4<\/li>\n<li>\u8ba9 Agent \u63d0\u95ee\u9898, \u5199 QA<\/li>\n<\/ul>\n<h3 id=\"qi-ta-zhu-yi\"><a class=\"zola-anchor\" href=\"#qi-ta-zhu-yi\" aria-label=\"Anchor link for: qi-ta-zhu-yi\">\u5176\u4ed6\u6ce8\u610f<\/a><\/h3>\n<ul>\n<li>\u5199\u901a\u7528\u7684\u89c4\u5219, \u7136\u540e\u7528 Markdown \u7684\u8d85\u94fe\u63a5\u529f\u80fd\u5f15\u7528, \u62b9\u5e73 IDE \u89c4\u8303\u5dee\u5f02<\/li>\n<li>\u4e0d\u8981\u4f7f\u7528\u5927\u6a21\u578b\u505a\u4ee3\u7801\u683c\u5f0f\u5316 (\u53ef\u4ee5\u8ba9 <code>Cascade<\/code> \u8c03\u7528\u5916\u90e8\u5de5\u5177\u6765\u5904\u7406)<\/li>\n<li>\u591a <code>commit<\/code> \u548c <code>commit --amend<\/code>, \u9632\u6b62\u4eba\u5de5<del>\u667a\u969c<\/del>\u667a\u80fd\u5927\u89c4\u6a21\u5220\u6539\u6587\u4ef6<\/li>\n<li>\u590d\u6742\u64cd\u4f5c\u751f\u6210\u64cd\u4f5c\u6e05\u5355\u800c\u975e\u76f4\u63a5\u6267\u884c<\/li>\n<li>\u6807\u8bb0\u5de5\u5177\u751f\u6210\u7684\u4ee3\u7801\u7684\u4f4d\u7f6e, \u4ee5\u514d\u5927\u6a21\u578b\u76f4\u63a5\u4fee\u6539<\/li>\n<li>\u5c06\u5e38\u7528\u4ee3\u7801\u5c01\u88c5\u6210\u53ef\u590d\u7528\u7684\u6a21\u5757, \u5e76\u5199\u597d <code>README.md<\/code>, \u51cf\u5c11\u5927\u6a21\u578b\u4e0a\u4e0b\u6587\u8d1f\u62c5<\/li>\n<li><strong>\u77db\u76fe<\/strong>, <strong>\u6a21\u7cca<\/strong>\u548c<strong>\u4e0d\u51c6\u786e<\/strong>\u7684\u4fe1\u606f\u4f1a\u8ba9\u5927\u6a21\u578b\u504f\u79fb<\/li>\n<li>\u5f53 <code>Session<\/code> \u504f\u79bb, \u7acb\u523b\u5f00\u542f\u65b0\u7684 <code>Session<\/code>, \u4e0d\u8981\u7ea0\u7ed3<\/li>\n<li>\u5c06\u547d\u4ee4\u7f16\u5199\u7ed3\u6784\u5316\u7684 Markdown \u6587\u6863, \u7136\u540e\u5728 <code>Cascade<\/code> \u5bf9\u8bdd\u6846\u4e2d\u5f15\u7528 (\u5982\u679c\"\u51e0\u53e5\u8bdd\u5c31\u80fd\u8bf4\u660e\u7684\u4e1c\u897f\"\u5c31\u8c03\u7528 <code>Cascade<\/code>, \u90a3\u5f88\u6709\u53ef\u80fd\u662f\u7528\u7684\u4e0d\u5bf9)<\/li>\n<\/ul>\n<h2 id=\"zong-jie-1\"><a class=\"zola-anchor\" href=\"#zong-jie-1\" aria-label=\"Anchor link for: zong-jie-1\">\u603b\u7ed3<\/a><\/h2>\n<p><code>Windsurf<\/code> \u7684\u4eba\u5de5\u667a\u80fd, \u5c06\u8865\u5168, \u91cd\u6784, \u89c4\u5212, \u641c\u7d22\u548c\u6267\u884c\u7ed3\u5408\u4e3a\u7edf\u4e00\u4f53\u9a8c, \u4ece\u5c40\u90e8\u51fd\u6570\u5230\u5168\u5c40\u67b6\u6784, \u90fd\u53ef\u4ee5\u4ee5\u66f4\u81ea\u7136\u7684\u65b9\u5f0f\u4e0e\u5176\u534f\u540c. \u4f46\u5b83\u5e76\u4e0d\u9b54\u6cd5\u822c\u5168\u80fd, \u5b83\u4f9d\u8d56\u4e0a\u4e0b\u6587, \u4f9d\u8d56\u6e05\u6670\u7684\u9879\u76ee\u7ed3\u6784, \u4f9d\u8d56\u597d\u7684 <code>prompt<\/code> \u63d0\u793a\u4e0e\u4efb\u52a1\u89c4\u5212. \u56e0\u6b64, \u771f\u6b63\u7684\u751f\u4ea7\u529b\u63d0\u5347, \u5e76\u975e\u6765\u81ea\"\u4f60\u6765\u628a\u8fd9\u4e2a\u4ee3\u7801\u5199\u4e86\", \u800c\u662f\u6765\u81ea\u6784\u5efa\u4e86\u4e00\u4e2a\u8ba9\u5b83\u7406\u89e3, \u534f\u4f5c, \u6267\u884c\u7684\u826f\u597d\u73af\u5883. \u4e5f\u8bb8\u53ef\u4ee5\u628a <code>Windsurf<\/code> \u770b\u4f5c\u6bcf\u5929\u65e9\u4e0a\u9192\u6765\u8981\u8bfb\u4f60\u7b14\u8bb0\u7684<del>\u7f8e\u5c11\u5973<\/del>\u7a0b\u5e8f\u5458, \u800c\u5f00\u53d1\u8005\u7684\u804c\u8d23, \u5c31\u662f\u5199\u597d\u90a3\u672c\"\u65e5\u8bb0\u672c\", \u660e\u786e\u7684\u76ee\u6807, \u6e05\u6670\u7684\u4e0a\u4e0b\u6587, \u6709\u903b\u8f91\u7684\u6b65\u9aa4\u548c\u5408\u7406\u7684\u8c03\u7528.<\/p>\n<h2 id=\"qi-ta-yi-xie-kan-fa\"><a class=\"zola-anchor\" href=\"#qi-ta-yi-xie-kan-fa\" aria-label=\"Anchor link for: qi-ta-yi-xie-kan-fa\">\u5176\u4ed6\u4e00\u4e9b\u770b\u6cd5<\/a><\/h2>\n<p><code>Vibe coding<\/code> \u8bd1\u4e3a\u6c1b\u56f4\u7f16\u7a0b, \u5728\u5b9e\u8df5\u4e2d, \u5bf9\u7f16\u7801\u80fd\u529b\u7684\u8981\u6c42\u4e0b\u964d\u4e86, \u4f46\u662f\u5bf9\u9879\u76ee\u89c4\u5212\u548c\u4ea7\u54c1\u8bbe\u8ba1, \u56e2\u961f\u534f\u4f5c\u548c\u7ec4\u7ec7\u80fd\u529b, \u56e2\u961f\u79ef\u7d2f\u4e0e\u7ed3\u6784\u5316\u77e5\u8bc6\u7684\u8981\u6c42\u53cd\u800c\u662f\u63d0\u9ad8\u4e86, \u67d0\u79cd\u610f\u4e49\u4e0a\u6765\u8bf4, \u53cd\u800c\u62c9\u5927\u4e86\u7ec4\u7ec7\u4e0e\u7ec4\u7ec7\u4e4b\u95f4\u7684\u5dee\u8ddd. \u4eba\u5de5\u667a\u80fd\u66f4\u50cf\u4e00\u4e2a\u6bcf\u5929\u90fd\u662f\u65b0\u5165\u804c\u7684, \u4ee3\u7801\u80fd\u529b\u624e\u5b9e\u7684\u5b9e\u4e60\u751f, \u5982\u4f55\u8ba9\u5176\u80fd\u5feb\u901f\u4e86\u89e3\u4ee3\u7801\u89c4\u8303, \u9879\u76ee\u67b6\u6784, \u5468\u8fb9\u5de5\u5177, \u6c9f\u901a\u65b9\u6cd5\u624d\u662f\u53d1\u6325\u5176\u4f5c\u7528\u7684\u5173\u952e. \u5f00\u53d1\u8005\u89d2\u8272\u4e5f\u4ece\"\u4ee3\u7801\u751f\u4ea7\u8005\"\u8f6c\u53d8\u4e3a\"\u610f\u56fe\u5b9a\u4e49\u8005\", \u6838\u5fc3\u80fd\u529b\u8fc1\u79fb\u5230\u95ee\u9898\u9a8c\u8bc1\u4e0e\u5904\u7406, \u9886\u57df\u5efa\u6a21, \u77e5\u8bc6\u7ed3\u6784\u5316\u548c\u7cbe\u51c6\u8868\u8fbe.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>\u7ec4\u7ec7\u5dee\u8ddd:<\/span><\/span>\n<span class=\"giallo-l\"><span>\u5f3a\u7684\u7ec4\u7ec7 -&gt; \u7cbe\u51c6\u7684\u9886\u57df\u8bed\u8a00 -&gt; \u7ed3\u6784\u5316\u77e5\u8bc6\u5e93 -&gt; AI \u9ad8\u6548\u4ea7\u51fa<\/span><\/span>\n<span class=\"giallo-l\"><span>\u5f31\u7684\u7ec4\u7ec7 -&gt; \u6a21\u7cca\u7684\u9700\u6c42 -&gt; \u788e\u7247\u5316\u7684\u4fe1\u606f -&gt; AI \u6df7\u4e71\u8f93\u51fa<\/span><\/span>\n<span class=\"giallo-l\"><span>\u5f00\u53d1\u6a21\u5f0f:<\/span><\/span>\n<span class=\"giallo-l\"><span>\u4f20\u7edf\u6a21\u5f0f [\u8bb0\u5fc6 -&gt; \u68c0\u7d22 -&gt; \u7f16\u7801]<\/span><\/span>\n<span class=\"giallo-l\"><span>AI \u6a21\u5f0f [\u610f\u56fe -&gt; \u9a8c\u8bc1 -&gt; \u4f18\u5316]<\/span><\/span><\/code><\/pre>\n<p>\u5927\u8bed\u8a00\u6a21\u578b\u7684\u539f\u7406\u548c\u5c40\u9650\u4e5f\u51b3\u5b9a\u4e86\u5b83\u5728 <code>Day 0<\/code> \u5373\u4ee3\u7801\u4ece\u5934\u5f00\u59cb\u7684\u6548\u679c\u6bd4\u8f83\u597d, \u800c <code>Day 1+<\/code> \u5373\u540e\u7eed\u7684\u5f00\u53d1\u548c\u7ef4\u62a4\u4e0a, \u4f1a\u9700\u8981\u5f00\u53d1\u8005\u66f4\u591a\u7684\u6307\u5f15.<del>\u8eab\u4e3a\u7a0b\u5e8f\u5458\u6700\u8ba8\u538c\u7684\u5c31\u662f\u5199\u6587\u6863\u548c\u522b\u4eba\u4e0d\u5199\u6587\u6863<\/del>\u62d2\u7edd <code>YOLO coding<\/code><\/p>\n<h2 id=\"geng-jin-yi-bu\"><a class=\"zola-anchor\" href=\"#geng-jin-yi-bu\" aria-label=\"Anchor link for: geng-jin-yi-bu\">\u66f4\u8fdb\u4e00\u6b65<\/a><\/h2>\n<p>\u4ec0\u4e48\u624d\u80fd\u79f0\u5f97\u4e0a\u601d\u7ef4, \u601d\u8003\u7684\u672c\u8d28, \u89c2\u70b9\u4e0e\u504f\u89c1, \u9519\u4e86\u4e5f\u4e0d\u6539\u4e0e\u53cd\u4f8b\u7684\u6743\u91cd, \u6ce2\u666e\u5c14\u7684 <code>\u53ef\u8bc1\u4f2a\u6027(Falsifiability)<\/code><\/p>\n<ul>\n<li>\u4e54\u6208\u91cc\u5cf0<\/li>\n<li>\u6768\u7acb\u6606<\/li>\n<\/ul>\n<h2 id=\"can-kao-zi-liao\"><a class=\"zola-anchor\" href=\"#can-kao-zi-liao\" aria-label=\"Anchor link for: can-kao-zi-liao\">\u53c2\u8003\u8d44\u6599<\/a><\/h2>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/mp.weixin.qq.com\/s\/1xbOMGlFI0No2AuixK6vbw\">Windsurf\u521b\u59cb\u4eba\uff1a\u6211\u4eec\u5bf9Java\u5de5\u7a0b\u5e08\u505a\u4e86\u5f88\u591a\u4f18\u5316\u548c\u9002\u914d<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/zh.wikipedia.org\/zh-cn\/Ef_-_a_fairy_tale_of_the_two.\">ef - a fairy tale of the two.<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/PaulDuvall\/vibecoding\">Vibe Coding: Automated Research Digest &amp; Windsurf Standards<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/docs.windsurf.com\/windsurf\/getting-started\">Getting started with Windsurf<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.reddit.com\/r\/Codeium\/comments\/1h2psgy\/windsurf_best_practices\/\">Windsurf best practices<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Vibe_coding\">Vibe coding<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.ycombinator.com\/library\/MO-windsurf-ceo-betting-on-ai-agents-pivoting-in-48-hours-and-the-future-of-coding\">Windsurf CEO: Betting On AI Agents, Pivoting In 48 Hours, And The Future of Coding<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/newsletter.pragmaticengineer.com\/p\/cursor\">Real-world engineering challenges: building Cursor<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/zhuanlan.zhihu.com\/p\/657425622\">\u89e3\u6790Yann LeCun\u7684\u81ea\u4e3b\u673a\u5668\u667a\u80fd\u6784\u60f3<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/zed.dev\/\">Zed<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.trae.ai\/\">TREA<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/aws\/amazon-q-developer-cli\/pull\/834\">feat(cli): Add context management feature with profiles #834<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/diamantai.substack.com\/p\/the-hidden-algorithms-powering-your\">The Hidden Algorithms Powering Your Coding Assistant<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/southbridge-research.notion.site\/conducting-smarter-intelligences-than-me\">Conducting smarter intelligences than me: new orchestras<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/google-gemini\/gemini-cli\">Gemini CLI<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/kiro.dev\/blog\/introducing-kiro\/\">Introducing Kiro<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/kirodotdev\/spirit-of-kiro\">Spirit of Kiro<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/harper.blog\/2025\/02\/16\/my-llm-codegen-workflow-atm\/\">My LLM codegen workflow atm<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.youtube.com\/watch?v=8rABwKRsec4\">The New Code \u2014 Sean Grove, OpenAI<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.anthropic.com\/engineering\/claude-code-best-practices\">Claude Code: Best practices for agentic coding<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/antirez.com\/news\/154\">Coding with LLMs in the summer of 2025<\/a><\/li>\n<\/ul>\n"},{"title":"\u738b\u53f8\u5f92\u7684\u9053\u7406","published":"2024-12-25T12:58:00+09:00","updated":"2024-12-25T12:58:00+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/wang-lang-had-a-point\/"}},"id":"https:\/\/memwey.github.io\/posts\/wang-lang-had-a-point\/","content":"<blockquote>\n<p>\u6574\u7406\u81ea\u6211\u5728\u77e5\u4e4e\u95ee\u9898 <a rel=\"external\" href=\"https:\/\/www.zhihu.com\/question\/34228174\/answer\/63479897935\">\u8bf8\u845b\u4eae\u738b\u6717\u8bba\u6218, \u6211\u611f\u89c9\u738b\u6717\u8bf4\u5f97\u597d\u6709\u9053\u7406\u600e\u4e48\u529e?<\/a> \u4e0b\u7684\u56de\u7b54.<\/p>\n<\/blockquote>\n<p>\u5982\u679c\u629b\u5f00\u6f14\u4e49\u7684\u4fee\u9970\u7ed3\u5408\u6b63\u53f2, \u738b\u53f8\u5f92\u7684\u8bdd\u786e\u5b9e\u4e0d\u65e0\u9053\u7406.<\/p>\n<p>\u5018\u82e5\u771f\u5982\u8bf8\u845b\u4eae\u6240\u8bf4 \"\u543e\u7d20\u77e5\u6c5d\u6240\u884c\", \u90a3\u738b\u53f8\u5f92\u7684\u524d\u534a\u751f\u53ef\u4ee5\u597d\u597d\u63a2\u8ba8\u4e00\u4e0b.<\/p>\n<p>\u738b\u6717\u524d\u534a\u751f\u4e3b\u8981\u5728\u5730\u65b9\u4efb\u804c. \u4ed6\u66fe\u4efb\u4f1a\u7a3d\u592a\u5b88, \u5728\u4efb\u65f6\u83b7\u767e\u59d3\u7231\u6234. \u968f\u540e\u5b59\u7b56\u5165\u4fb5\u6c5f\u4e1c, \u738b\u6717\u62b5\u6297\u4e0d\u654c, \u8f6c\u79fb\u5230\u4faf\u5b98 (\u4eca\u798f\u5efa\u798f\u5dde), \u4e0e\u4faf\u5b98\u53bf\u957f\u5546\u5347\u8054\u5408\u7ee7\u7eed\u5bf9\u6297\u5b59\u7b56. \u800c\u540e\u5546\u5347\u6151\u4e8e\u5b59\u7b56\u5a01\u540d\u6253\u7b97\u6295\u964d, \u5f15\u53d1\u5185\u4e71, \u7ec8\u88ab\u5b59\u7b56\u5e73\u5b9a. \u738b\u6717\u610f\u56fe\u524d\u5f80\u4ea4\u5dde\u7ee7\u7eed\u62b5\u6297, \u51fa\u6d77\u65f6\u88ab\u5b59\u7b56\u8ffd\u51fb, \u88ab\u8feb\u6295\u964d. \u5b59\u7b56\u656c\u91cd\u5176\u4e3a\u4eba, \u4e0d\u52a0\u5bb3\u5e76\u4e88\u4ee5\u62db\u63fd, \u738b\u6717\u4e0d\u4ece. \u5efa\u5b89\u4e09\u5e74, \u66f9\u64cd\u4e0a\u8868\u5f81\u53ec\u738b\u6717, \u56e0\u4e45\u7ecf\u6218\u4e71\u9053\u8def\u4e0d\u901a, \u738b\u6717\u8f97\u8f6c\u6570\u5e74\u624d\u5230\u4efb, \u7531\u6b64\u5f00\u542f\u4e86\u4ed6\u4f5c\u4e3a\u4e2d\u592e\u5b98\u5458\u7684\u540e\u534a\u751f.<\/p>\n<p>\u4ece\u5b59\u7b56\u7684\u89d2\u5ea6\u6765\u770b, \u5e73\u5b9a\u6c5f\u4e1c\u7684\u6545\u4e8b\u4eff\u4f5b\u987a\u6c34\u63a8\u821f. \u4f46\u662f\u5bf9\u4e8e\u6c49\u671d\u4e2d\u592e\u653f\u5e9c\u6765\u8bf4, \u6c5f\u4e1c\u5e76\u4e0d\u662f\u65e0\u4e3b\u4e4b\u5730. \u738b\u6717\u662f\u4e2d\u592e\u653f\u5e9c\u6b63\u5f0f\u4efb\u547d\u7684\u5730\u65b9\u957f\u5b98, \u6709\u52bf\u529b\u4ee5\u6b66\u529b\u5f3a\u593a\u5730\u65b9\u653f\u6743, \u4ed6\u4e0e\u4e4b\u5bf9\u6297\u7406\u6240\u5e94\u5f53. \u738b\u6717\u957f\u4e8e\u6cbb\u7406\u800c\u5f31\u4e8e\u519b\u4e8b, \u88ab\u5b59\u7b56\u6253\u8d25\u5e76\u4e0d\u5947\u602a. \u4f46\u662f\u4ece\u4ed6\u6cbb\u7406\u5730\u65b9\u6e05\u5e73, \u62b5\u5fa1\u5916\u654c\u575a\u51b3\u7684\u7ecf\u5386\u6765\u770b, \u4ed6\u5b8c\u5168\u5bf9\u5f97\u8d77\u8fd9\u4efd\u6c49\u7984.<\/p>\n<p>\u6c49\u5ba4\u503e\u9893\u6709\u4e24\u6761\u8109\u7edc, \u4e00\u662f\u4e2d\u592e\u6df7\u4e71, \u4e8c\u662f\u5730\u65b9\u5272\u636e. \u4ece\u5730\u65b9\u957f\u5b98\u738b\u6717\u7684\u89d2\u5ea6\u6765\u770b, \u5218\u5907, \u5b59\u7b56\u8fd9\u4e9b\u88ad\u51fb\u4e2d\u592e\u4efb\u547d\u7684\u5730\u65b9\u957f\u5b98, \u9020\u6210\u5730\u65b9\u5b9e\u9645\u5272\u636e\u7684\u4eba, \u662f\u4e0d\u662f\u4e5f\u9700\u8981\u4e3a\u6c49\u5ba4\u503e\u9893\u8d1f\u4e00\u90e8\u5206\u8d23\u4efb? \u5218\u748b, \u5218\u7e47, \u5218\u8868\u8fd9\u4e9b\u4e2d\u592e\u4efb\u547d\u9a7b\u5b88\u5730\u65b9\u7684\u6c49\u5ba4\u5b97\u4eb2, \u96be\u9053\u90fd\u662f\u5e94\u8be5\u88ab\u8ba8\u4f10\u7684\u4e71\u81e3\u8d3c\u5b50?<\/p>\n<p>\u5b59\u7b56\u5949\u8881\u672f\u4e4b\u547d\u8ba8\u4f10\u6c5f\u4e1c, \u5b9e\u4e3a\u5272\u636e, \u800c\u8881\u672f\u968f\u540e\u516c\u5f00\u79f0\u5e1d. \u76ca\u5dde\u5218\u748b, \u8346\u5dde\u5218\u742e\u6697\u5f31, \u610f\u56fe\u5411\u4e2d\u592e\u5f52\u964d, \u5218\u5907\u593a\u5176\u5dde\u90e1, \u517c\u5e76\u5176\u4f17. \u4e2a\u4eba\u80fd\u529b\u6709\u9650, \u738b\u6717\u53ea\u80fd\u505a\u6cbb\u4e16\u4e4b\u80fd\u81e3, \u505a\u4e0d\u4e86\u4e71\u4e16\u4e4b\u5978\u96c4. \u4f46\u662f\u6c49\u5ba4\u503e\u9893\u7684\u8d23\u4efb, \u76f8\u6bd4\u8d77\u738b\u6717, \u5218\u5907, \u5b59\u7b56\u8fd9\u4e9b\u4eba\u53ef\u5927\u5f97\u591a.<\/p>\n<p>\u53ea\u662f\u8fd9\u5c42\u4e24\u65b9\u90fd\u662f\u6c49\u5ba4\u503e\u9893\u5143\u51f6\u7684\u9053\u7406, \u600e\u4e48\u80fd\u5728\u4e24\u519b\u9635\u524d\u660e\u8bf4? \u8fd9\u79cd\u6f6e\u6d41\u6eda\u6eda\u5411\u524d, \u529b\u4e0d\u4ece\u5fc3\u7684\u5fc3\u60c5, \u53c8\u600e\u4e48\u80fd\u5728\u4e24\u519b\u9635\u524d\u7ec6\u8bf4?<\/p>\n"},{"title":"2024 \u8bfa\u8d1d\u5c14\u7269\u7406\u5b66\u5956\u5c0f\u8bb0","published":"2024-10-09T20:18:58+09:00","updated":"2024-10-09T20:18:58+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/2024-nobel-prize-in-physics\/"}},"id":"https:\/\/memwey.github.io\/posts\/2024-nobel-prize-in-physics\/","content":"<p>\u6770\u5f17\u91cc\u00b7\u8f9b\u987f\u51fa\u81ea\u4e66\u9999\u4e16\u5bb6, \u4ed6\u6709\u4e00\u4f4d\u5802\u59d1, \u53eb\u743c\u00b7\u8f9b\u987f, \u5f53\u7136, \u4e2d\u56fd\u4eba\u5e94\u8be5\u66f4\u719f\u6089\u4ed6\u7684\u8fd9\u4f4d\u5802\u59d1\u7684\u4e2d\u6587\u540d, \u5bd2\u6625<\/p>\n<p>\u611f\u89c9\u50cf\u662f\u5510\u7eb3\u5fb7\u00b7\u7279\u6717\u666e\u7684\u53d4\u53d4\u7ea6\u7ff0\u00b7\u7279\u6717\u666e\u4e3a\u4e2d\u56fd\u6838\u7269\u7406\u4e8b\u4e1a\u505a\u51fa\u4e86\u8d21\u732e\u4e00\u6837\u6709\u7740\u5947\u5999\u7684\u8054\u7cfb<\/p>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/2024-nobel-prize-in-physics\/images\/1.jpg\" alt=\"Joke-1\" \/><\/p>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/2024-nobel-prize-in-physics\/images\/2.jpg\" alt=\"Joke-2\" \/><\/p>\n"},{"title":"\u4e00\u4e2a\u5bf9\u8c61\u540c\u65f6\u53ea\u80fd\u6709\u4e00\u7b14\u6709\u6548\u652f\u4ed8","published":"2024-08-18T16:20:33+09:00","updated":"2024-08-18T16:20:33+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/one-active-payment\/"}},"id":"https:\/\/memwey.github.io\/posts\/one-active-payment\/","content":"<h2 id=\"cong-yi-ge-kan-qi-lai-hen-jian-dan-de-xu-qiu-shuo-qi\"><a class=\"zola-anchor\" href=\"#cong-yi-ge-kan-qi-lai-hen-jian-dan-de-xu-qiu-shuo-qi\" aria-label=\"Anchor link for: cong-yi-ge-kan-qi-lai-hen-jian-dan-de-xu-qiu-shuo-qi\">\u4ece\u4e00\u4e2a\u770b\u8d77\u6765\u5f88\u7b80\u5355\u7684\u9700\u6c42\u8bf4\u8d77<\/a><\/h2>\n<p>\u4e00\u4e2a\u8ba2\u5355\u8981\u80fd\u652f\u4ed8. \u542c\u4e0a\u53bb\u5c31\u662f\u52a0\u4e00\u4e2a <code>status<\/code> \u5b57\u6bb5: \u672a\u652f\u4ed8, \u652f\u4ed8\u4e2d, \u5df2\u652f\u4ed8, \u652f\u4ed8\u5931\u8d25.<\/p>\n<p>\u771f\u505a\u8d77\u6765\u4f1a\u53d1\u73b0\u4e0d\u591f\u7528:<\/p>\n<ul>\n<li>\u652f\u4ed8\u5931\u8d25\u4e86\u53ef\u4ee5\u518d\u8bd5, \u4e8e\u662f\u4e00\u4e2a\u8ba2\u5355\u5bf9\u5e94\u7684\u662f<strong>\u591a\u7b14<\/strong>\u652f\u4ed8\u8bb0\u5f55, \u4e0d\u662f\u4e00\u7b14.<\/li>\n<li>\u7528\u6237\u70b9\u4e86\u652f\u4ed8, \u8df3\u5230\u6e20\u9053\u7684\u652f\u4ed8\u9875\u9762, \u53c8\u9000\u56de\u6765\u518d\u70b9\u4e00\u6b21. \u8fd9\u65f6\u5019\u4e0d\u80fd\u5efa\u7b2c\u4e8c\u7b14.<\/li>\n<li>\u652f\u4ed8\u7ed3\u679c\u662f\u5f02\u6b65\u56de\u6765\u7684, \u56de\u6765\u7684\u65f6\u5019\u5f97\u77e5\u9053\u5b83\u5bf9\u5e94\u54ea\u4e00\u7b14.<\/li>\n<li>\u540e\u6765\u8d26\u5355\u548c\u9884\u7ea6\u4e5f\u8981\u652f\u4ed8, \u6d41\u7a0b\u51e0\u4e4e\u4e00\u6837.<\/li>\n<\/ul>\n<p>\u8fd9\u51e0\u4ef6\u4e8b\u5408\u8d77\u6765, \u5c31\u4e0d\u662f\u4e00\u4e2a\u72b6\u6001\u5b57\u6bb5\u80fd\u8868\u8fbe\u7684\u4e86.<\/p>\n<h2 id=\"xian-shuo-qing-chu-yi-bi-zhi-fu-shi-shen-me\"><a class=\"zola-anchor\" href=\"#xian-shuo-qing-chu-yi-bi-zhi-fu-shi-shen-me\" aria-label=\"Anchor link for: xian-shuo-qing-chu-yi-bi-zhi-fu-shi-shen-me\">\u5148\u8bf4\u6e05\u695a\u300c\u4e00\u7b14\u652f\u4ed8\u300d\u662f\u4ec0\u4e48<\/a><\/h2>\n<p>\u4e00\u7b14\u652f\u4ed8\u6307\u7684\u662f<strong>\u4e00\u6b21\u652f\u4ed8\u5c1d\u8bd5<\/strong>, \u5bf9\u5e94\u4e00\u6761\u4ea4\u6613\u8bb0\u5f55, \u5b83\u81ea\u5df1\u6709:<\/p>\n<ul>\n<li><strong>\u4ea4\u6613 ID<\/strong> \u2014\u2014 \u5168\u5c40\u552f\u4e00, \u540e\u9762\u4f1a\u770b\u5230\u5b83\u540c\u65f6\u662f\u53d1\u7ed9\u6e20\u9053\u7684\u5e42\u7b49\u952e;<\/li>\n<li><strong>\u72b6\u6001<\/strong> \u2014\u2014 \u5f85\u652f\u4ed8 \/ \u652f\u4ed8\u4e2d \/ \u6210\u529f \/ \u5931\u8d25 \/ \u53d6\u6d88 \/ \u5df2\u9000\u6b3e;<\/li>\n<li>\u91d1\u989d, \u652f\u4ed8\u65b9\u5f0f, \u4ee5\u53ca\u6e20\u9053\u4fa7\u8fd4\u56de\u7684\u6d41\u6c34\u53f7.<\/li>\n<\/ul>\n<p>\u7528\u6237\u7b2c\u4e00\u6b21\u70b9\u652f\u4ed8, \u5efa\u4e00\u7b14. \u5931\u8d25\u4e86\u518d\u70b9, \u662f<strong>\u65b0\u7684\u4e00\u7b14<\/strong>, \u800c\u4e0d\u662f\u628a\u539f\u6765\u90a3\u7b14\u6539\u56de\u300c\u5f85\u652f\u4ed8\u300d\u91cd\u6765. \u539f\u6765\u90a3\u7b14\u505c\u5728\u5931\u8d25\u7ec8\u6001, \u4e4b\u540e\u4e0d\u518d\u53d8\u52a8.<\/p>\n<p>\u8fd9\u4e00\u70b9\u503c\u5f97\u5f3a\u8c03: \u4ea4\u6613\u8bb0\u5f55\u8fdb\u4e86\u7ec8\u6001\u5c31\u4e0d\u518d\u6539. \u6240\u4ee5\u5bf9\u8d26\u7684\u65f6\u5019\u80fd\u8fd8\u539f\u51fa\"\u8fd9\u4e2a\u8ba2\u5355\u88ab\u5c1d\u8bd5\u652f\u4ed8\u8fc7\u51e0\u6b21, \u6bcf\u6b21\u5206\u522b\u662f\u4ec0\u4e48\u7ed3\u679c\". \u5982\u679c\u590d\u7528\u540c\u4e00\u6761\u8bb0\u5f55\u53cd\u590d\u6539\u72b6\u6001, \u8fd9\u4e9b\u4fe1\u606f\u5c31\u6ca1\u4e86, \u51fa\u4e86\u95ee\u9898\u53ea\u80fd\u9760\u65e5\u5fd7\u53bb\u731c.<\/p>\n<h2 id=\"li-shi-liu-shui-yu-dang-qian-you-xiao\"><a class=\"zola-anchor\" href=\"#li-shi-liu-shui-yu-dang-qian-you-xiao\" aria-label=\"Anchor link for: li-shi-liu-shui-yu-dang-qian-you-xiao\">\u5386\u53f2\u6d41\u6c34\u4e0e\u300c\u5f53\u524d\u6709\u6548\u300d<\/a><\/h2>\n<p>\u7b2c\u4e8c\u4ef6\u8981\u5206\u6e05\u695a\u7684\u4e8b: <strong>\u4e00\u4e2a\u4e1a\u52a1\u5bf9\u8c61\u4f1a\u6709\u5f88\u591a\u7b14\u652f\u4ed8, \u4f46\u4efb\u4e00\u65f6\u523b\u6700\u591a\u53ea\u6709\u4e00\u7b14\u662f\u300c\u5f53\u524d\u6709\u6548\u300d\u7684.<\/strong><\/p>\n<ul>\n<li>\u5386\u53f2\u6d41\u6c34: \u6bcf\u6b21\u53d1\u8d77\u652f\u4ed8\u90fd\u662f\u4e00\u6761\u8bb0\u5f55, \u6709\u81ea\u5df1\u7684\u72b6\u6001\u548c\u7ec8\u6001, \u4e0d\u5220\u4e0d\u6539;<\/li>\n<li>\u5f53\u524d\u6709\u6548: \u8fd9\u4e2a\u8ba2\u5355\u73b0\u5728\u5230\u5e95\u538b\u5728\u54ea\u4e00\u7b14\u4e0a.<\/li>\n<\/ul>\n<p>\u628a\u8fd9\u4e24\u4ef6\u4e8b\u6df7\u5728\u4e00\u8d77, \u5c31\u4f1a\u5199\u51fa\"\u53d6\u6700\u65b0\u4e00\u6761\u652f\u4ed8\u8bb0\u5f55\"\u8fd9\u6837\u7684\u67e5\u8be2. \u5b83\u5728\u5927\u591a\u6570\u65f6\u5019\u662f\u5bf9\u7684, \u5728\u5e76\u53d1\u7684\u65f6\u5019\u4e0d\u662f.<\/p>\n<p>\u6240\u4ee5\u628a\u300c\u5f53\u524d\u6709\u6548\u300d\u663e\u5f0f\u5efa\u6210\u4e00\u4e2a\u4e1c\u897f, \u4e00\u4e2a\u4ece\u4e1a\u52a1\u5bf9\u8c61\u6307\u5411\u5f53\u524d\u4ea4\u6613\u7684\u6307\u9488:<\/p>\n<script src=https:\/\/memwey.github.io\/js\/mermaid.js><\/script>\n<pre class=\"mermaid\">\n\nflowchart LR\n    Target[\"\u4e1a\u52a1\u5bf9\u8c61<br\/>\u8ba2\u5355 \/ \u8d26\u5355 \/ \u9884\u7ea6\"]\n    Gateway[\"\u652f\u4ed8\u6e20\u9053\"]\n    Result[\"\u5f02\u6b65\u7ed3\u679c<br\/>\u56de\u8c03 \/ \u67e5\u8be2 \/ \u524d\u7aef\u8df3\u8f6c\"]\n    Unknown[\"\u8c03\u7528\u6808\u5931\u8d25<br\/>\u53d7\u7406\u72b6\u6001\u672a\u77e5\"]\n\n    subgraph TxModule[\"\u652f\u4ed8\u6a21\u5757\"]\n        Active[\"ActivePayment<br\/>\u5f53\u524d\u6709\u6548\u4ea4\u6613\u6307\u9488\"]\n        Tx[\"Transaction<br\/>\u5386\u53f2\u6d41\u6c34 + \u5f53\u524d\u72b6\u6001\"]\n        Final[\"\u7ec8\u6001<br\/>\u6210\u529f \/ \u5931\u8d25 \/ \u53d6\u6d88 \/ \u9000\u6b3e\"]\n        Active --> Tx\n        Tx --> Final\n    end\n\n    Target --> TxModule\n    Tx -->|\"\u53d1\u8d77\u652f\u4ed8<br\/>\u4ea4\u6613 ID \u4f5c\u4e3a\u5e42\u7b49\u952e\"| Gateway\n    Gateway --> Result\n    Result -->|\"\u6536\u655b\u7ed3\u679c, \u66f4\u65b0\u72b6\u6001\"| Tx\n    Tx -->|\"\u652f\u4ed8\u4e2d: \u5e42\u7b49\u62e6\u622a\"| Target\n    Gateway -.-> Unknown\n    Unknown -.->|\"\u8c03\u7528\u5931\u8d25 \u2260 \u4e1a\u52a1\u5931\u8d25<br\/>\u4fdd\u6301\u652f\u4ed8\u4e2d\"| Tx\n\n<\/pre>\n<p>\u8fd9\u4e2a\u6307\u9488\u6709\u4e09\u6761\u7ea6\u675f:<\/p>\n<ol>\n<li><strong>\u552f\u4e00\u7d22\u5f15.<\/strong> \u6570\u636e\u5e93\u5c42\u9762\u4fdd\u8bc1\u4e00\u4e2a\u4e1a\u52a1\u5bf9\u8c61\u53ea\u80fd\u6709\u4e00\u6761\u6709\u6548\u8bb0\u5f55. \u8fd9\u662f\u515c\u5e95, \u4e0d\u662f\u4f18\u5316 \u2014\u2014 \u5e94\u7528\u5c42\u7684\u5224\u65ad\u4e00\u5b9a\u4f1a\u6709\u6f0f\u7f51\u7684\u5e76\u53d1\u8def\u5f84.<\/li>\n<li><strong>\u521b\u5efa\u65b0\u4ea4\u6613\u548c\u5207\u6362\u6307\u9488\u5728\u540c\u4e00\u4e2a\u4e8b\u52a1\u91cc.<\/strong> \u5426\u5219\u4f1a\u51fa\u73b0\"\u4ea4\u6613\u5efa\u597d\u4e86\u4f46\u6ca1\u4eba\u6307\u5411\u5b83\", \u6216\u8005\u53cd\u8fc7\u6765.<\/li>\n<li><strong>\u5207\u6362\u65f6\u5e26\u4e0a\u65e7\u7684\u4ea4\u6613\u4e00\u8d77\u5339\u914d<\/strong>, \u5339\u914d\u4e0d\u4e0a\u5c31\u4e0d\u5207.<\/li>\n<\/ol>\n<p>\u7b2c\u4e09\u6761\u662f\u5173\u952e. \u4e24\u4e2a\u8bf7\u6c42\u540c\u65f6\u60f3\u53d1\u8d77\u652f\u4ed8, \u90fd\u8bfb\u5230\"\u5f53\u524d\u6ca1\u6709\u6709\u6548\u4ea4\u6613\", \u90fd\u53bb\u521b\u5efa. \u6ca1\u6709\u7b2c\u4e09\u6761, \u540e\u4e00\u4e2a\u4f1a\u76d6\u6389\u524d\u4e00\u4e2a, \u4e8e\u662f\u6709\u4e24\u7b14\u4ea4\u6613\u90fd\u4ee5\u4e3a\u81ea\u5df1\u662f\u6709\u6548\u7684. \u628a\u65e7\u503c\u4f5c\u4e3a\u66f4\u65b0\u6761\u4ef6, \u5c31\u53ea\u6709\u4e00\u4e2a\u80fd\u6210\u529f \u2014\u2014 \u662f CAS \u7684\u601d\u8def, \u53ea\u4e0d\u8fc7\u843d\u5728\u6570\u636e\u5e93\u4e0a.<\/p>\n<h2 id=\"yi-ge-qian-ti-qu-dao-bi-xu-zhi-chi-mi-deng-jian\"><a class=\"zola-anchor\" href=\"#yi-ge-qian-ti-qu-dao-bi-xu-zhi-chi-mi-deng-jian\" aria-label=\"Anchor link for: yi-ge-qian-ti-qu-dao-bi-xu-zhi-chi-mi-deng-jian\">\u4e00\u4e2a\u524d\u63d0: \u6e20\u9053\u5fc5\u987b\u652f\u6301\u5e42\u7b49\u952e<\/a><\/h2>\n<p>\u63a5\u5916\u90e8\u652f\u4ed8\u6e20\u9053\u4e4b\u524d, \u6709\u4e00\u4ef6\u4e8b\u8981\u5148\u786e\u8ba4: <strong>\u6e20\u9053\u5fc5\u987b\u652f\u6301\u5e42\u7b49\u952e<\/strong>. \u540e\u9762\u8bb2\u7684\u6240\u6709\u505a\u6cd5\u90fd\u5efa\u7acb\u5728\u8fd9\u4e2a\u524d\u63d0\u4e0a.<\/p>\n<p>\u5177\u4f53\u8bf4, \u53d1\u8d77\u652f\u4ed8\u7684\u65f6\u5019\u8981\u5e26\u4e00\u4e2a\u81ea\u5df1\u751f\u6210\u7684\u552f\u4e00\u6807\u8bc6, \u6e20\u9053\u4fdd\u8bc1\u540c\u4e00\u4e2a\u6807\u8bc6\u53ea\u53d7\u7406\u4e00\u6b21. \u7b2c\u4e8c\u6b21\u5e26\u7740\u540c\u6837\u7684\u6807\u8bc6\u8fc7\u6765, \u5b83\u8fd4\u56de\u7684\u662f\u7b2c\u4e00\u6b21\u7684\u7ed3\u679c, \u800c\u4e0d\u662f\u518d\u6263\u4e00\u6b21\u94b1. \u8fd9\u4e2a\u4e1c\u897f\u5728\u5404\u5bb6\u6e20\u9053\u7684\u6587\u6863\u91cc\u901a\u5e38\u53eb\u300c\u5546\u6237\u8ba2\u5355\u53f7\u300d\u6216\u8005 idempotency key.<\/p>\n<p>\u524d\u9762\u8bf4\u7684\u4ea4\u6613 ID \u6b63\u597d\u5c31\u662f\u8fd9\u4e2a\u952e, \u4e24\u4ef6\u4e8b\u662f\u914d\u5957\u7684:<\/p>\n<ul>\n<li><strong>\u540c\u4e00\u7b14\u652f\u4ed8\u7684\u91cd\u53d1<\/strong> \u2014\u2014 \u540c\u4e00\u4e2a\u4ea4\u6613 ID \u2014\u2014 \u6e20\u9053\u8ba4\u5f97\u51fa\u6765, \u4e0d\u4f1a\u91cd\u590d\u53d7\u7406;<\/li>\n<li><strong>\u5931\u8d25\u540e\u91cd\u65b0\u53d1\u8d77<\/strong> \u2014\u2014 \u65b0\u7684\u4e00\u7b14, \u65b0\u7684\u4ea4\u6613 ID \u2014\u2014 \u6e20\u9053\u5f53\u6210\u4e00\u4e2a\u65b0\u8bf7\u6c42\u5904\u7406.<\/li>\n<\/ul>\n<p>\u6240\u4ee5\"\u4e00\u7b14\u652f\u4ed8\u4e00\u4e2a ID\"\u4e0d\u53ea\u662f\u4e3a\u4e86\u8bb0\u8d26. \u6ca1\u6709\u5b83, \u4f60\u6ca1\u529e\u6cd5\u544a\u8bc9\u6e20\u9053\"\u8fd9\u662f\u540c\u4e00\u6b21\u5c1d\u8bd5\u7684\u91cd\u53d1\"; \u800c\u6ca1\u6709\u6e20\u9053\u4fa7\u7684\u5e42\u7b49\u4fdd\u8bc1, \u4f60\u6839\u672c\u4e0d\u6562\u91cd\u53d1.<\/p>\n<p>\u5982\u679c\u6e20\u9053\u4e0d\u652f\u6301\u5e42\u7b49\u952e, \u540e\u9762\u7684\u505a\u6cd5\u5c31\u90fd\u8981\u6253\u6298\u6263: \u8d85\u65f6\u4e4b\u540e\u4e0d\u6562\u91cd\u53d1, \u53ea\u80fd\u5e72\u7b49\u67e5\u8be2\u6216\u56de\u8c03; \u67e5\u8be2\u63a5\u53e3\u8fd8\u5fc5\u987b\u80fd\u6309\u4f60\u81ea\u5df1\u7684\u6807\u8bc6\u6765\u67e5, \u5426\u5219\u62ff\u56de\u4e00\u5806\u6e20\u9053\u6d41\u6c34, \u4f60\u5bf9\u4e0d\u4e0a\u662f\u54ea\u4e00\u7b14; \u6700\u574f\u7684\u60c5\u51b5\u662f\u53ea\u80fd\u4eba\u5de5\u5bf9\u8d26.<\/p>\n<p>\u8fd9\u4ef6\u4e8b\u5728\u63a5\u5165\u524d\u786e\u8ba4, \u6bd4\u5199\u5b8c\u4e4b\u540e\u518d\u8865\u8981\u5bb9\u6613\u5f97\u591a.<\/p>\n<h2 id=\"san-ge-bu-deng-yu\"><a class=\"zola-anchor\" href=\"#san-ge-bu-deng-yu\" aria-label=\"Anchor link for: san-ge-bu-deng-yu\">\u4e09\u4e2a\u300c\u4e0d\u7b49\u4e8e\u300d<\/a><\/h2>\n<p>\u63a5\u4e86\u5916\u90e8\u652f\u4ed8\u6e20\u9053\u4e4b\u540e, \u771f\u6b63\u7684\u9ebb\u70e6\u624d\u5f00\u59cb. \u8e29\u8fc7\u7684\u5751\u53ef\u4ee5\u5f52\u7eb3\u6210\u4e09\u53e5\u8bdd.<\/p>\n<h3 id=\"yi-shou-li-cheng-gong-zhi-fu-cheng-gong\"><a class=\"zola-anchor\" href=\"#yi-shou-li-cheng-gong-zhi-fu-cheng-gong\" aria-label=\"Anchor link for: yi-shou-li-cheng-gong-zhi-fu-cheng-gong\">\u4e00, \u53d7\u7406\u6210\u529f \u2260 \u652f\u4ed8\u6210\u529f<\/a><\/h3>\n<p>\u8c03\u7528\u6e20\u9053\u7684\u652f\u4ed8\u63a5\u53e3\u8fd4\u56de\u6210\u529f, \u53ea\u8bf4\u660e\u5bf9\u65b9<strong>\u53d7\u7406<\/strong>\u4e86\u8fd9\u7b14\u8bf7\u6c42. \u7528\u6237\u53ef\u80fd\u8fd8\u6ca1\u8f93\u5bc6\u7801, 3DS \u9a8c\u8bc1\u53ef\u80fd\u8fd8\u6ca1\u8fc7, \u53d1\u5361\u884c\u53ef\u80fd\u8fd8\u8981\u51e0\u79d2\u949f.<\/p>\n<p>\u6240\u4ee5\u63a5\u53e3\u8fd4\u56de\u4e4b\u540e, \u4ea4\u6613\u7684\u72b6\u6001\u662f\u300c\u652f\u4ed8\u4e2d\u300d, \u4e0d\u662f\u300c\u6210\u529f\u300d. \u771f\u6b63\u7684\u7ed3\u679c\u901a\u8fc7\u56de\u8c03, \u4e3b\u52a8\u67e5\u8be2\u6216\u8005\u524d\u7aef\u8df3\u8f6c\u5e26\u56de\u6765.<\/p>\n<p>\u8fd9\u6761\u6bd4\u8f83\u5bb9\u6613\u63a5\u53d7. \u4e0b\u4e00\u6761\u5c31\u4e0d\u662f\u4e86.<\/p>\n<h3 id=\"er-diao-yong-shi-bai-ye-wu-shi-bai\"><a class=\"zola-anchor\" href=\"#er-diao-yong-shi-bai-ye-wu-shi-bai\" aria-label=\"Anchor link for: er-diao-yong-shi-bai-ye-wu-shi-bai\">\u4e8c, \u8c03\u7528\u5931\u8d25 \u2260 \u4e1a\u52a1\u5931\u8d25<\/a><\/h3>\n<p>\u8fd9\u662f\u6700\u5371\u9669\u7684\u4e00\u6761.<\/p>\n<p>\u8c03\u6e20\u9053\u7684\u63a5\u53e3, \u8d85\u65f6\u4e86. \u6216\u8005\u8fde\u63a5\u65ad\u4e86. \u6216\u8005\u6536\u5230\u4e00\u4e2a 5xx. \u76f4\u89c9\u662f\u628a\u8fd9\u7b14\u6807\u6210\u5931\u8d25, \u8ba9\u7528\u6237\u91cd\u8bd5.<\/p>\n<p><strong>\u8fd9\u4e2a\u76f4\u89c9\u4f1a\u5bfc\u81f4\u91cd\u590d\u6263\u6b3e.<\/strong><\/p>\n<p>\u56e0\u4e3a\u8d85\u65f6\u53ea\u8bf4\u660e\u4f60\u6ca1\u6536\u5230\u54cd\u5e94, \u4e0d\u8bf4\u660e\u5bf9\u65b9\u6ca1\u6536\u5230\u8bf7\u6c42. \u5bf9\u65b9\u5f88\u53ef\u80fd\u5df2\u7ecf\u53d7\u7406\u4e86, \u6b63\u5728\u5904\u7406, \u8fc7\u4e00\u4f1a\u8fd8\u4f1a\u7ed9\u4f60\u56de\u8c03:<\/p>\n<script src=https:\/\/memwey.github.io\/js\/mermaid.js><\/script>\n<pre class=\"mermaid\">\n\nsequenceDiagram\n    participant B as \u4e1a\u52a1\u7cfb\u7edf\n    participant G as \u652f\u4ed8\u6e20\u9053\n    B->>G: \u53d1\u8d77\u652f\u4ed8\n    Note over G: \u5df2\u53d7\u7406, \u5f00\u59cb\u5904\u7406\n    G--xB: \u8d85\u65f6 \/ \u8fde\u63a5\u65ad\u5f00\n    Note over B: \u82e5\u6b64\u65f6\u5224\u5931\u8d25<br\/>\u7528\u6237\u91cd\u8bd5 \u2192 \u91cd\u590d\u6263\u6b3e\n    G->>B: \u56de\u8c03: \u652f\u4ed8\u6210\u529f\n    Note over B: \u4fdd\u6301\u300c\u652f\u4ed8\u4e2d\u300d<br\/>\u624d\u80fd\u6b63\u786e\u6536\u655b\n\n<\/pre>\n<p>\u6b63\u786e\u7684\u505a\u6cd5\u662f: \u8c03\u7528\u6808\u5931\u8d25\u7684\u65f6\u5019<strong>\u4e0d\u4e0b\u7ed3\u8bba<\/strong>. \u4fdd\u6301\u300c\u652f\u4ed8\u4e2d\u300d, \u628a\u5224\u65ad\u7559\u7ed9\u67e5\u8be2\u63a5\u53e3\u548c\u56de\u8c03. \u5b81\u53ef\u8ba9\u7528\u6237\u591a\u7b49\u4e00\u4f1a, \u4e5f\u4e0d\u80fd\u8ba9\u4ed6\u4ed8\u4e24\u6b21.<\/p>\n<p>\u987a\u5e26\u4e00\u63d0, \u8fd9\u4e2a\u95ee\u9898\u662f\u5728\u6d4b\u8bd5\u9636\u6bb5\u53d1\u73b0\u7684, \u4e0d\u662f\u7ebf\u4e0a. \u80fd\u5728\u6d4b\u8bd5\u9636\u6bb5\u649e\u4e0a, \u662f\u56e0\u4e3a\u7279\u610f\u53bb\u6784\u9020\u4e86\u6e20\u9053\u53d7\u7406\u8d85\u65f6\u7684\u573a\u666f \u2014\u2014 \u8fd9\u7c7b\u8def\u5f84\u4e0d\u4e3b\u52a8\u9020\u662f\u649e\u4e0d\u5230\u7684, \u800c\u5b83\u4e00\u65e6\u5728\u751f\u4ea7\u4e0a\u51fa\u73b0, \u540e\u679c\u662f\u8d44\u91d1\u5dee\u9519.<\/p>\n<h3 id=\"san-zhi-fu-zhong-bi-xu-shi-yi-dao-mi-deng-dang-ban\"><a class=\"zola-anchor\" href=\"#san-zhi-fu-zhong-bi-xu-shi-yi-dao-mi-deng-dang-ban\" aria-label=\"Anchor link for: san-zhi-fu-zhong-bi-xu-shi-yi-dao-mi-deng-dang-ban\">\u4e09, \u300c\u652f\u4ed8\u4e2d\u300d\u5fc5\u987b\u662f\u4e00\u9053\u5e42\u7b49\u6321\u677f<\/a><\/h3>\n<p>\u6709\u4e86\u524d\u9762\u4e24\u6761, \u300c\u652f\u4ed8\u4e2d\u300d\u8fd9\u4e2a\u72b6\u6001\u5c31\u627f\u62c5\u4e86\u5f88\u91cd\u7684\u804c\u8d23: \u53ea\u8981\u8fd8\u5728\u652f\u4ed8\u4e2d, \u4efb\u4f55\u91cd\u590d\u7684\u652f\u4ed8\u8bf7\u6c42\u90fd\u4e0d\u80fd\u5efa\u65b0\u5355, \u4e5f\u4e0d\u80fd\u91cd\u65b0\u53d1\u8d77.<\/p>\n<p>\u7528\u6237\u5728\u6e20\u9053\u7684\u652f\u4ed8\u9875\u9762\u4e0a\u5237\u65b0, \u540e\u9000\u518d\u70b9\u4e00\u6b21, \u524d\u7aef\u8d85\u65f6\u81ea\u52a8\u91cd\u8bd5 \u2014\u2014 \u8fd9\u4e9b\u90fd\u4f1a\u6253\u5230\u540c\u4e00\u4e2a\u5165\u53e3. \u5e42\u7b49\u5728\u8fd9\u91cc\u4e0d\u662f\u52a0\u5206\u9879, \u662f\u6574\u5957\u8bbe\u8ba1\u6210\u7acb\u7684\u524d\u63d0.<\/p>\n<h2 id=\"duo-chong-zhi-fu-fang-shi-yi-ge-sheng-ming-zhou-qi\"><a class=\"zola-anchor\" href=\"#duo-chong-zhi-fu-fang-shi-yi-ge-sheng-ming-zhou-qi\" aria-label=\"Anchor link for: duo-chong-zhi-fu-fang-shi-yi-ge-sheng-ming-zhou-qi\">\u591a\u79cd\u652f\u4ed8\u65b9\u5f0f, \u4e00\u4e2a\u751f\u547d\u5468\u671f<\/a><\/h2>\n<p>\u652f\u4ed8\u65b9\u5f0f\u4f1a\u8d8a\u6765\u8d8a\u591a, \u800c\u4e14\u5f62\u6001\u5dee\u522b\u5f88\u5927:<\/p>\n<ul>\n<li><strong>\u670d\u52a1\u7aef\u76f4\u63a5\u53d1\u8d77<\/strong>: \u62ff\u5230\u5361\u53f7\u6216\u8005\u5df2\u4fdd\u5b58\u7684\u652f\u4ed8\u51ed\u8bc1, \u76f4\u63a5\u8c03\u6e20\u9053\u6263\u6b3e;<\/li>\n<li><strong>\u9700\u8981\u7528\u6237\u8df3\u8d70<\/strong>: \u751f\u6210\u4e00\u4e2a\u9875\u9762\u5730\u5740, \u7528\u6237\u8df3\u5230\u6e20\u9053\u90a3\u8fb9\u5b8c\u6210, \u518d\u8df3\u56de\u6765;<\/li>\n<li><strong>\u9700\u8981\u7528\u6237\u5728\u522b\u5904\u64cd\u4f5c<\/strong>: \u751f\u6210\u4e00\u4e2a\u4e8c\u7ef4\u7801\u6216\u8005\u4ed8\u6b3e\u7801, \u7528\u6237\u62ff\u53e6\u4e00\u4e2a App \u626b;<\/li>\n<li><strong>\u5f02\u6b65\u5230\u8d26<\/strong>: \u751f\u6210\u4e00\u4e2a\u5f85\u4ed8\u6b3e\u51ed\u8bc1, \u7528\u6237\u53bb\u4fbf\u5229\u5e97\u6216\u8005\u7f51\u94f6\u4ed8, \u53ef\u80fd\u51e0\u5c0f\u65f6\u751a\u81f3\u51e0\u5929\u4e4b\u540e\u624d\u5230\u8d26.<\/li>\n<\/ul>\n<p>\u5b83\u4eec\u7684\u5dee\u5f02\u5168\u90e8\u5728<strong>\u53d1\u8d77<\/strong>\u90a3\u4e00\u6b65: \u53c2\u6570\u4e0d\u4e00\u6837; \u6709\u7684\u8c03\u5b8c\u5c31\u7ed3\u675f\u4e86, \u6709\u7684\u8981\u5148\u751f\u6210\u4e00\u4e2a\u5730\u5740\u6216\u8005\u4e8c\u7ef4\u7801\u5b58\u8fdb\u4ea4\u6613\u91cc; \u6709\u7684\u53d1\u8d77\u4e4b\u540e\u8fd8\u8981\u7b49\u7528\u6237\u5728\u53e6\u4e00\u4e2a\u5730\u65b9\u64cd\u4f5c.<\/p>\n<p>\u4f46\u53d1\u8d77\u4e4b\u540e\u7684\u4e8b\u60c5\u5b8c\u5168\u4e00\u6837 \u2014\u2014 \u90fd\u8fdb\u5165\u652f\u4ed8\u4e2d, \u90fd\u7b49\u5f02\u6b65\u7ed3\u679c, \u90fd\u8981\u56de\u5199, \u90fd\u8981\u5e42\u7b49. \u6240\u4ee5\u5dee\u5f02\u6536\u655b\u5728\u5165\u53e3, \u5171\u6027\u6536\u655b\u5728\u751f\u547d\u5468\u671f:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>\u53d1\u8d77\u652f\u4ed8   -&gt;  \u6309\u652f\u4ed8\u65b9\u5f0f\u5206\u652f<\/span><\/span>\n<span class=\"giallo-l\"><span>\u6536\u655b\u7ed3\u679c   -&gt;  \u6210\u529f \/ \u5931\u8d25 \/ \u53d6\u6d88 \/ \u9000\u6b3e<\/span><\/span><\/code><\/pre>\n<p>\u65b0\u589e\u4e00\u79cd\u652f\u4ed8\u65b9\u5f0f, \u53ea\u9700\u8981\u5728\u53d1\u8d77\u90a3\u4e00\u6b65\u52a0\u4e00\u4e2a\u5206\u652f, \u4e0d\u7528\u78b0\u72b6\u6001\u673a.<\/p>\n<h2 id=\"duo-ge-ye-wu-dui-xiang-yi-tao-zhi-fu\"><a class=\"zola-anchor\" href=\"#duo-ge-ye-wu-dui-xiang-yi-tao-zhi-fu\" aria-label=\"Anchor link for: duo-ge-ye-wu-dui-xiang-yi-tao-zhi-fu\">\u591a\u4e2a\u4e1a\u52a1\u5bf9\u8c61, \u4e00\u5957\u652f\u4ed8<\/a><\/h2>\n<p>\u540e\u6765\u8d26\u5355\u548c\u9884\u7ea6\u4e5f\u8981\u652f\u4ed8.<\/p>\n<p>\u6700\u7701\u4e8b\u7684\u505a\u6cd5\u662f\u628a\u8ba2\u5355\u90a3\u5957\u590d\u5236\u4e00\u4efd. \u4f46\u652f\u4ed8\u8fd9\u5757\u7684\u590d\u6742\u5ea6\u4e0a\u9762\u5df2\u7ecf\u8bb2\u8fc7\u4e86 \u2014\u2014 \u590d\u5236\u4e00\u4efd\u610f\u5473\u7740\u5e42\u7b49, CAS, \u5f02\u6b65\u56de\u5199\u8fd9\u4e9b\u5751\u8981\u91cd\u65b0\u8e29\u4e00\u904d, \u800c\u4e14\u4e09\u4efd\u4ee3\u7801\u4f1a\u6162\u6162\u957f\u5f97\u4e0d\u4e00\u6837.<\/p>\n<p>\u66f4\u597d\u7684\u505a\u6cd5\u662f<strong>\u628a\u65b9\u5411\u53cd\u8fc7\u6765<\/strong>: \u652f\u4ed8\u6a21\u5757\u4e0d\u53bb\u4e86\u89e3\u4e1a\u52a1, \u800c\u662f\u5b9a\u4e49\u4e00\u4efd\u5951\u7ea6, \u8ba9\u4e1a\u52a1\u5bf9\u8c61\u6765\u5b9e\u73b0\u5b83.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">type<\/span><span class=\"z-l-6 z-d-7\"> PayTarget<\/span><span class=\"z-l-8 z-d-10\"> interface<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">\tPayCheck<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">ctx<\/span><span class=\"z-l-6 z-d-7\"> context<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Context<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span class=\"z-l-5 z-d-3\">   \/\/<\/span><span class=\"z-l-5 z-d-3\"> \u73b0\u5728\u80fd\u4e0d\u80fd\u652f\u4ed8<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">\tPay<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">ctx<\/span><span class=\"z-l-6 z-d-7\"> context<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Context<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span class=\"z-l-5 z-d-3\">        \/\/<\/span><span class=\"z-l-5 z-d-3\"> \u9501\u5b9a\u4e3a\u652f\u4ed8\u4e2d<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">\tPaySuccess<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">ctx<\/span><span class=\"z-l-6 z-d-7\"> context<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Context<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span class=\"z-l-5 z-d-3\"> \/\/<\/span><span class=\"z-l-5 z-d-3\"> \u652f\u4ed8\u6210\u529f\u540e\u56de\u5199<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">\tPayFailed<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">ctx<\/span><span class=\"z-l-6 z-d-7\"> context<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Context<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span class=\"z-l-5 z-d-3\">  \/\/<\/span><span class=\"z-l-5 z-d-3\"> \u652f\u4ed8\u5931\u8d25\u540e\u56de\u5199<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u652f\u4ed8\u6a21\u5757\u62ff\u5230\u4e00\u4e2a\u76ee\u6807 ID \u548c\u5b83\u7684\u5951\u7ea6\u5b9e\u73b0, \u5c31\u80fd\u8dd1\u5b8c\u6574\u4e2a\u6d41\u7a0b. \u4e1a\u52a1\u6a21\u5757\u53ea\u5173\u5fc3\u81ea\u5df1\u7684\u72b6\u6001\u548c\u91d1\u989d\u4ece\u54ea\u6765, \u5b8c\u5168\u4e0d\u9700\u8981\u77e5\u9053\u6e20\u9053, \u56de\u8c03, \u5e42\u7b49\u8fd9\u4e9b\u4e1c\u897f:<\/p>\n<script src=https:\/\/memwey.github.io\/js\/mermaid.js><\/script>\n<pre class=\"mermaid\">\n\nflowchart LR\n    Tx[\"\u652f\u4ed8\u6a21\u5757<br\/>\u7edf\u4e00\u7f16\u6392\"]\n    Target[\"Target<br\/>\u8ba2\u5355 ID \/ \u8d26\u5355 ID \/ \u9884\u7ea6 ID\"]\n    Contract[\"PayTarget \u5951\u7ea6<br\/>PayCheck \/ Pay<br\/>PaySuccess \/ PayFailed\"]\n    Order[\"\u8ba2\u5355\"]\n    Invoice[\"\u8d26\u5355\"]\n    Booking[\"\u9884\u7ea6\"]\n    Method[\"\u652f\u4ed8\u65b9\u5f0f<br\/>\u7edf\u4e00\u53d1\u8d77\u5165\u53e3\"]\n    Direct[\"\u670d\u52a1\u7aef\u76f4\u63a5\u53d1\u8d77\"]\n    Redirect[\"\u8df3\u8f6c\u6e20\u9053\u9875\u9762\"]\n    Code[\"\u4e8c\u7ef4\u7801 \/ \u4ed8\u6b3e\u7801\"]\n    Offline[\"\u5f85\u4ed8\u6b3e\u51ed\u8bc1<br\/>\u5f02\u6b65\u5230\u8d26\"]\n    Gateway[\"\u652f\u4ed8\u6e20\u9053\"]\n\n    Tx --> Target\n    Tx -->|\"\u68c0\u67e5 \/ \u9501\u5b9a \/ \u56de\u5199\"| Contract\n    Contract -.-> Order\n    Contract -.-> Invoice\n    Contract -.-> Booking\n    Tx --> Method\n    Method --> Direct\n    Method --> Redirect\n    Method --> Code\n    Method --> Offline\n    Direct --> Gateway\n    Redirect --> Gateway\n    Code --> Gateway\n    Offline --> Gateway\n\n<\/pre>\n<p>\u63a5\u4e00\u4e2a\u65b0\u7684\u4e1a\u52a1\u5bf9\u8c61, \u8981\u5199\u7684\u5c31\u662f\u90a3\u56db\u4e2a\u65b9\u6cd5.<\/p>\n<p>\u8fd9\u5176\u5b9e\u5c31\u662f\u4f9d\u8d56\u5012\u7f6e: \u628a\"\u652f\u4ed8\u8c03\u7528\u4e1a\u52a1\"\u5b9a\u4e49\u6210\u63a5\u53e3, \u800c\u4e0d\u662f\u8ba9\u6bcf\u4e2a\u4e1a\u52a1\u81ea\u5df1\u53bb\u8c03\u652f\u4ed8.<\/p>\n<h2 id=\"xiao-jie\"><a class=\"zola-anchor\" href=\"#xiao-jie\" aria-label=\"Anchor link for: xiao-jie\">\u5c0f\u7ed3<\/a><\/h2>\n<ul>\n<li>\u4e00\u7b14\u652f\u4ed8\u5c31\u662f\u4e00\u6b21\u5c1d\u8bd5, \u6709\u81ea\u5df1\u7684 ID \u548c\u7ec8\u6001; \u91cd\u8bd5\u662f\u65b0\u7684\u4e00\u7b14, \u4e0d\u662f\u628a\u65e7\u7684\u6539\u56de\u53bb.<\/li>\n<li>\u63a5\u5165\u524d\u5148\u786e\u8ba4\u6e20\u9053\u652f\u6301\u5e42\u7b49\u952e, \u4ea4\u6613 ID \u5c31\u662f\u8fd9\u4e2a\u952e. \u8fd9\u662f\u4e0b\u9762\u6240\u6709\u505a\u6cd5\u7684\u524d\u63d0.<\/li>\n<li>\u628a\u300c\u5386\u53f2\u6d41\u6c34\u300d\u548c\u300c\u5f53\u524d\u6709\u6548\u300d\u5206\u5f00. \u540e\u8005\u8981\u663e\u5f0f\u5efa\u6a21, \u7528\u552f\u4e00\u7d22\u5f15\u515c\u5e95, \u7528\u5e26\u65e7\u503c\u7684\u6761\u4ef6\u66f4\u65b0\u6765\u5207\u6362.<\/li>\n<li>\u5f02\u6b65\u652f\u4ed8\u91cc, \u53d7\u7406\u4e0d\u7b49\u4e8e\u6210\u529f, \u8c03\u7528\u5931\u8d25\u4e0d\u7b49\u4e8e\u4e1a\u52a1\u5931\u8d25. \u62ff\u4e0d\u51c6\u7684\u65f6\u5019\u4fdd\u6301\u652f\u4ed8\u4e2d, \u4e0d\u8981\u6025\u7740\u4e0b\u7ed3\u8bba.<\/li>\n<li>\u300c\u652f\u4ed8\u4e2d\u300d\u662f\u4e00\u9053\u5e42\u7b49\u6321\u677f, \u4e0d\u662f\u4e00\u4e2a\u666e\u901a\u72b6\u6001.<\/li>\n<li>\u652f\u4ed8\u65b9\u5f0f\u7684\u5dee\u5f02\u6536\u5728\u53d1\u8d77\u90a3\u4e00\u6b65, \u4e1a\u52a1\u5bf9\u8c61\u7684\u5dee\u5f02\u6536\u5728\u5951\u7ea6\u91cc.<\/li>\n<\/ul>\n<p>\u8fd9\u51e0\u4ef6\u4e8b\u5355\u770b\u90fd\u4e0d\u590d\u6742, \u4f46\u5b83\u4eec\u662f\u6709\u5148\u540e\u7684: \u5148\u6709\u6e20\u9053\u4fa7\u7684\u5e42\u7b49\u952e, \u624d\u8c08\u5f97\u4e0a\u91cd\u53d1; \u5148\u6709\u552f\u4e00\u7684\u5f53\u524d\u6709\u6548\u4ea4\u6613, \u624d\u8c08\u5f97\u4e0a\u5e42\u7b49; \u5148\u6709\u5e42\u7b49, \u624d\u6562\u5728\u8d85\u65f6\u7684\u65f6\u5019\u4e0d\u4e0b\u7ed3\u8bba.<\/p>\n"},{"title":"\u5ca9\u91cc\u6b66\u5219\u4e0e\u9a6c\u5c3c\u62c9\u6218\u5f79","published":"2024-06-02T00:50:39+09:00","updated":"2026-07-30T17:21:20+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/iwasato-takenori-and-battle-of-manila\/"}},"id":"https:\/\/memwey.github.io\/posts\/iwasato-takenori-and-battle-of-manila\/","content":"<p>\u5ca9\u91cc\u6b66\u5219, \u5ca9\u91cc\u653f\u7537\u7684\u54e5\u54e5, \u5728\u4e8c\u6218\u671f\u95f4\u52a0\u5165\u65e7\u65e5\u672c\u5e1d\u56fd\u6d77\u519b, \u524d\u5f80\u65e5\u5360\u83f2\u5f8b\u5bbe, \u5728\u9a6c\u5c3c\u62c9\u6218\u5f79\u4e2d\u88ab\u7f8e\u519b\u6253\u6b7b, \u4e8c\u6218\u540e, \u4ee5\u5ca9\u91cc\u6b66\u5219\u7684\u540d\u5b57\u88ab\u4f9b\u5949\u5728\u9756\u56fd\u795e\u793e; \u636e\u79f0, \u6539\u59d3\u5ca9\u91cc, \u56e0\u4e3a\u91cc\u5b57\u4fdd\u7559\u4e86\u674e\u8fd9\u4e2a\u97f3, \u800c\u5ca9\u5219\u6e90\u81ea\u674e\u5bb6\u7956\u7c4d\u798f\u5efa\u9f99\u5ca9<\/p>\n<p>\u53d1\u751f\u5728 1945 \u5e74\u521d\u7684\u9a6c\u5c3c\u62c9\u6218\u5f79, \u65e5\u519b\u6307\u6325\u5b98\u5ca9\u6e0a\u4e09\u6b21\u5e26\u9886\u6d77\u519b\u9646\u6218\u961f\u8fdd\u53cd\u4e0a\u7ea7\u547d\u4ee4, \u5728\u4eba\u53e3\u7a20\u5bc6\u4e14\u62e5\u6709\u5927\u91cf\u6728\u5236\u6613\u71c3\u5efa\u7b51\u7684\u9a6c\u5c3c\u62c9\u5e02\u533a\u4e0e\u7f8e\u519b\u8fdb\u884c\u5df7\u6218. \u5728\u7f8e\u519b\u7684\u7edd\u5bf9\u4f18\u52bf\u4e0b, \u65e5\u519b\u5c06\u6124\u6012\u53d1\u6cc4\u5728\u83f2\u5f8b\u5bbe\u5e73\u6c11\u8eab\u4e0a; \u5c06\u8fd1\u4e00\u4e2a\u6708\u7684\u6218\u6597\u4e2d, \u9a6c\u5c3c\u62c9\u57ce\u88ab\u5f7b\u5e95\u6467\u6bc1, \u8d85\u8fc7\u5341\u4e07\u540d\u83f2\u5f8b\u5bbe\u5e73\u6c11\u6b7b\u4ea1, \u5176\u4e2d\u5927\u90e8\u5206\u6b7b\u4e8e\u65e5\u519b\u5c60\u6740; \u8fd9\u4e2a\u6570\u5b57\u8d85\u8fc7\u4e86\u4e1c\u4eac\u5927\u8f70\u70b8\u548c\u5e7f\u5c9b\u4e0e\u957f\u5d0e\u7684\u6838\u7206\u4efb\u4e00\u5355\u6b21\u6b7b\u4ea1<\/p>\n"},{"title":"\u5728 TCP \u4e0a\u5212\u62a5\u6587\u8fb9\u754c","published":"2023-04-06T21:37:19+09:00","updated":"2023-04-06T21:37:19+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/message-framing-over-tcp\/"}},"id":"https:\/\/memwey.github.io\/posts\/message-framing-over-tcp\/","content":"<p>\u5728 TCP \u4e0a\u8dd1\u4e00\u4e2a\u81ea\u5df1\u7684\u4e1a\u52a1\u534f\u8bae, \u7b2c\u4e00\u4ef6\u8981\u51b3\u5b9a\u7684\u4e8b\u5f80\u5f80\u4e0d\u662f\u7528\u4ec0\u4e48\u5e8f\u5217\u5316, \u4e5f\u4e0d\u662f\u5b57\u6bb5\u600e\u4e48\u6392, \u800c\u662f<strong>\u4e00\u6761\u6d88\u606f\u5230\u54ea\u91cc\u7ed3\u675f<\/strong>.<\/p>\n<p>\u8fd9\u542c\u4e0a\u53bb\u4e0d\u592a\u50cf\u4e2a\u95ee\u9898, \u4f46\u5b83\u662f\u81ea\u5b9a\u4e49\u534f\u8bae\u91cc\u6700\u5bb9\u6613\u5199\u9519\u7684\u5730\u65b9, \u800c\u4e14\u9519\u4e86\u4ee5\u540e\u5728\u6d4b\u8bd5\u73af\u5883\u91cc\u5f80\u5f80\u4e00\u5207\u6b63\u5e38.<\/p>\n<h2 id=\"xian-ba-wen-ti-shuo-qing-chu\"><a class=\"zola-anchor\" href=\"#xian-ba-wen-ti-shuo-qing-chu\" aria-label=\"Anchor link for: xian-ba-wen-ti-shuo-qing-chu\">\u5148\u628a\u95ee\u9898\u8bf4\u6e05\u695a<\/a><\/h2>\n<p>\u5e38\u89c1\u7684\u8bf4\u6cd5\u662f\"TCP \u7c98\u5305\". \u8fd9\u4e2a\u8bf4\u6cd5\u5176\u5b9e\u4e0d\u592a\u51c6\u786e, \u56e0\u4e3a\u5b83\u6697\u793a TCP \u672c\u6765\u5e94\u8be5\u7ed9\u4f60\"\u5305\", \u53ea\u662f\u4e0d\u5c0f\u5fc3\u7c98\u4e0a\u4e86.<\/p>\n<p>TCP \u4ece\u6765\u6ca1\u627f\u8bfa\u8fc7\u5305. \u5b83\u627f\u8bfa\u7684\u53ea\u6709\u4e09\u4ef6\u4e8b: \u4f60\u5199\u8fdb\u53bb\u7684\u5b57\u8282\u4f1a<strong>\u6309\u987a\u5e8f<\/strong>\u5230\u8fbe, \u4e0d\u4e22, \u4e0d\u91cd. \u81f3\u4e8e\u8fd9\u4e9b\u5b57\u8282\u600e\u4e48\u5207\u5206\u6210\u4e00\u6b21\u6b21 <code>Read<\/code>, \u5b8c\u5168\u4e0d\u53d7\u4f60\u63a7\u5236:<\/p>\n<ul>\n<li>\u53d1\u9001\u4fa7, \u4e24\u6b21 <code>Write<\/code> \u53ef\u80fd\u88ab\u5408\u5e76\u8fdb\u540c\u4e00\u4e2a TCP \u6bb5 (Nagle \u7b97\u6cd5\u5c31\u662f\u5e72\u8fd9\u4e2a\u7684).<\/li>\n<li>\u4e00\u6b21 <code>Write<\/code> \u4e5f\u53ef\u80fd\u88ab\u62c6\u6210\u591a\u6bb5, \u56e0\u4e3a MSS, \u56e0\u4e3a\u53d1\u9001\u7a97\u53e3, \u56e0\u4e3a\u8def\u5f84 MTU.<\/li>\n<li>\u4e2d\u95f4\u7684\u8bbe\u5907\u8fd8\u53ef\u80fd\u518d\u5207\u4e00\u5200.<\/li>\n<\/ul>\n<p>\u6240\u4ee5\u4e0b\u9762\u8fd9\u6bb5\u4ee3\u7801\u662f\u9519\u7684:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span>buf<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span class=\"z-l-6 z-d-7\"> make<\/span><span>(<\/span><span>[<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> 4096<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>n<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> conn<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Read<\/span><span>(<\/span><span>buf<\/span><span>)<\/span><span class=\"z-l-5 z-d-3\">   \/\/<\/span><span class=\"z-l-5 z-d-3\"> \u8bfb\u5230\u7684\u4e0d\u4e00\u5b9a\u662f\u4e00\u6761\u5b8c\u6574\u6d88\u606f<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">handle<\/span><span>(<\/span><span>buf<\/span><span>[<\/span><span>:<\/span><span>n<\/span><span>]<\/span><span>)<\/span><span class=\"z-l-5 z-d-3\">            \/\/<\/span><span class=\"z-l-5 z-d-3\"> \u53ef\u80fd\u662f\u534a\u6761, \u4e5f\u53ef\u80fd\u662f\u4e24\u6761\u534a<\/span><\/span><\/code><\/pre>\n<p>\u5b83\u5728\u672c\u673a\u6d4b\u8bd5\u91cc\u51e0\u4e4e\u6c38\u8fdc\u662f\u5bf9\u7684 \u2014\u2014 \u6d88\u606f\u77ed, \u7f51\u7edc\u5feb, \u4e00\u6b21\u4e00\u6761. \u4e00\u4e0a\u751f\u4ea7, \u62a5\u6587\u53d8\u957f, \u7f51\u7edc\u53d8\u5dee, \u5c31\u5f00\u59cb\u968f\u673a\u5730\u89e3\u6790\u5931\u8d25. \u800c\u4e14\u56e0\u4e3a\u662f\u968f\u673a\u7684, \u67e5\u8d77\u6765\u975e\u5e38\u70e6\u4eba.<\/p>\n<p><strong>\u8fb9\u754c\u662f\u5e94\u7528\u5c42\u81ea\u5df1\u7684\u4e8b.<\/strong> \u5212\u8fb9\u754c\u7684\u529e\u6cd5\u603b\u5171\u5c31\u90a3\u4e48\u51e0\u79cd.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>fixed     |&lt;-- 64 bytes --&gt;|&lt;-- 64 bytes --&gt;|&lt;-- 64 bytes --&gt;|<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>prefixed  |len=12|&lt;-- 12 bytes --&gt;|len=5|&lt;-5B-&gt;|len=40|&lt;-- 40 bytes --&gt;|<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>delimited | hello\\r\\n | world\\r\\n | a-longer-line\\r\\n |<\/span><\/span><\/code><\/pre><h2 id=\"yi-ding-chang-bao-wen\"><a class=\"zola-anchor\" href=\"#yi-ding-chang-bao-wen\" aria-label=\"Anchor link for: yi-ding-chang-bao-wen\">\u4e00, \u5b9a\u957f\u62a5\u6587<\/a><\/h2>\n<p>\u6bcf\u6761\u62a5\u6587\u56fa\u5b9a N \u5b57\u8282, \u8bfb\u6ee1 N \u5c31\u662f\u4e00\u6761. \u6ca1\u6709\u6bd4\u8fd9\u66f4\u7b80\u5355\u7684\u4e86:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">const<\/span><span class=\"z-l-1 z-d-4\"> frameSize<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-1 z-d-4\"> 64<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span class=\"z-l-6 z-d-7\"> readFrame<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">r<\/span><span class=\"z-l-6 z-d-7\"> io<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Reader<\/span><span>)<\/span><span> (<\/span><span>[<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><span>,<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\tbuf<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span class=\"z-l-6 z-d-7\"> make<\/span><span>(<\/span><span>[<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><span>,<\/span><span> frameSize<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tif<\/span><span> _<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> io<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">ReadFull<\/span><span>(<\/span><span>r<\/span><span>,<\/span><span> buf<\/span><span>)<\/span><span>;<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> !=<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\treturn<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><span>,<\/span><span> err<\/span><\/span>\n<span class=\"giallo-l\"><span>\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\treturn<\/span><span> buf<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p><strong>\u597d\u5904<\/strong>\u662f\u89e3\u6790\u6210\u672c\u4e3a\u96f6, \u4e0d\u9700\u8981\u4efb\u4f55\u72b6\u6001\u673a; \u7f13\u51b2\u533a\u53ef\u4ee5\u9884\u5206\u914d\u751a\u81f3\u590d\u7528; \u800c\u4e14\u5929\u7136\u6ca1\u6709\"\u5bf9\u65b9\u58f0\u660e\u4e86\u4e00\u4e2a 2GB \u7684\u957f\u5ea6\"\u8fd9\u7c7b\u95ee\u9898 \u2014\u2014 \u957f\u5ea6\u6839\u672c\u4e0d\u7531\u5bf9\u65b9\u51b3\u5b9a.<\/p>\n<p><strong>\u4ee3\u4ef7<\/strong>\u662f\u77ed\u6d88\u606f\u8981\u8865\u767d, \u6d6a\u8d39\u5e26\u5bbd; \u66f4\u8981\u547d\u7684\u662f<strong>\u6539\u7ed3\u6784\u5c31\u662f\u4e0d\u517c\u5bb9<\/strong>. \u5b9a\u957f\u610f\u5473\u7740\u5b57\u6bb5\u7684\u504f\u79fb\u91cf\u5199\u6b7b\u5728\u4e24\u8fb9\u7684\u4ee3\u7801\u91cc, \u52a0\u4e00\u4e2a\u5b57\u6bb5\u5c31\u5f97\u53cc\u65b9\u540c\u65f6\u5347\u7ea7.<\/p>\n<p>\u6240\u4ee5\u5b83\u9002\u5408\u5b57\u6bb5\u672c\u6765\u5c31\u56fa\u5b9a\u7684\u573a\u666f: \u5fc3\u8df3, \u4f20\u611f\u5668\u4e0a\u62a5, \u884c\u60c5\u5feb\u7167, \u5de5\u63a7\u8bbe\u5907. \u53e6\u5916, \u5f88\u591a\u8001\u534f\u8bae\u7684<strong>\u5305\u5934<\/strong>\u662f\u5b9a\u957f\u7684, \u90a3\u672c\u8d28\u4e0a\u4e5f\u662f\u8fd9\u4e00\u7c7b \u2014\u2014 \u53ea\u4e0d\u8fc7\u5b9a\u957f\u7684\u90e8\u5206\u53ea\u662f\u5934, \u540e\u9762\u8fd8\u8ddf\u7740\u53d8\u957f\u7684\u8eab\u4f53, \u4e5f\u5c31\u662f\u4e0b\u9762\u8fd9\u79cd.<\/p>\n<h2 id=\"er-ding-chang-tou-bu-chang-du-zi-duan\"><a class=\"zola-anchor\" href=\"#er-ding-chang-tou-bu-chang-du-zi-duan\" aria-label=\"Anchor link for: er-ding-chang-tou-bu-chang-du-zi-duan\">\u4e8c, \u5b9a\u957f\u5934\u90e8 + \u957f\u5ea6\u5b57\u6bb5<\/a><\/h2>\n<p>\u6700\u5e38\u7528\u7684\u4e00\u79cd. \u5934\u90e8\u957f\u5ea6\u56fa\u5b9a, \u5934\u90e8\u91cc\u5e26\u7740\u540e\u9762\u8fd8\u6709\u591a\u5c11\u5b57\u8282, \u4e8e\u662f\u8bfb\u53d6\u53d8\u6210\u660e\u786e\u7684\u4e24\u6b65:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">const<\/span><span> (<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-1 z-d-4\">\theaderSize<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-1 z-d-4\"> 4<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-1 z-d-4\">\tmaxBodyLen<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-1 z-d-4\"> 1<\/span><span class=\"z-l-8 z-d-10\"> &lt;&lt;<\/span><span class=\"z-l-1 z-d-4\"> 20<\/span><span class=\"z-l-5 z-d-3\"> \/\/<\/span><span class=\"z-l-5 z-d-3\"> \u5fc5\u987b\u6709\u4e0a\u9650<\/span><\/span>\n<span class=\"giallo-l\"><span>)<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span class=\"z-l-6 z-d-7\"> readMessage<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">r<\/span><span class=\"z-l-6 z-d-7\"> io<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Reader<\/span><span>)<\/span><span> (<\/span><span>[<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><span>,<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tvar<\/span><span> head<\/span><span> [<\/span><span class=\"z-l-6 z-d-7\">headerSize<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tif<\/span><span> _<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> io<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">ReadFull<\/span><span>(<\/span><span>r<\/span><span>,<\/span><span> head<\/span><span>[<\/span><span>:<\/span><span>]<\/span><span>)<\/span><span>;<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> !=<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\treturn<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><span>,<\/span><span> err<\/span><\/span>\n<span class=\"giallo-l\"><span>\t}<\/span><\/span>\n<span class=\"giallo-l\"><span>\tn<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> binary<\/span><span>.<\/span><span>BigEndian<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Uint32<\/span><span>(<\/span><span>head<\/span><span>[<\/span><span>:<\/span><span>]<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tif<\/span><span> n<\/span><span class=\"z-l-8 z-d-10\"> &gt;<\/span><span> maxBodyLen<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\treturn<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><span>,<\/span><span> fmt<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Errorf<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span class=\"z-l-2 z-d-6\">frame too large: <\/span><span class=\"z-l-1 z-d-4\">%d<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span>,<\/span><span> n<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\t}<\/span><\/span>\n<span class=\"giallo-l\"><span>\tbody<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span class=\"z-l-6 z-d-7\"> make<\/span><span>(<\/span><span>[<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><span>,<\/span><span> n<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tif<\/span><span> _<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> io<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">ReadFull<\/span><span>(<\/span><span>r<\/span><span>,<\/span><span> body<\/span><span>)<\/span><span>;<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> !=<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\treturn<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><span>,<\/span><span> err<\/span><\/span>\n<span class=\"giallo-l\"><span>\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\treturn<\/span><span> body<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u73b0\u5b9e\u91cc\u7684\u534f\u8bae\u57fa\u672c\u90fd\u662f\u8fd9\u4e2a\u8def\u5b50, \u53ea\u662f\u5934\u7684\u5f62\u72b6\u4e0d\u540c:<\/p>\n<table><thead><tr><th>\u534f\u8bae<\/th><th>\u5934<\/th><\/tr><\/thead><tbody>\n<tr><td>gRPC<\/td><td>1 \u5b57\u8282\u538b\u7f29\u6807\u5fd7 + 4 \u5b57\u8282\u5927\u7aef\u957f\u5ea6<\/td><\/tr>\n<tr><td>TLS record<\/td><td>1 \u5b57\u8282\u7c7b\u578b + 2 \u5b57\u8282\u7248\u672c + 2 \u5b57\u8282\u957f\u5ea6<\/td><\/tr>\n<tr><td>MySQL<\/td><td>3 \u5b57\u8282\u5c0f\u7aef\u957f\u5ea6 + 1 \u5b57\u8282\u5e8f\u53f7<\/td><\/tr>\n<tr><td>Redis bulk string<\/td><td><code>$&lt;len&gt;\\r\\n<\/code><\/td><\/tr>\n<\/tbody><\/table>\n<p>\u6709\u51e0\u4e2a\u5751\u503c\u5f97\u5355\u72ec\u62ce\u51fa\u6765.<\/p>\n<p><strong>\u957f\u5ea6\u5230\u5e95\u7b97\u4ec0\u4e48, \u5fc5\u987b\u5b9a\u4e49\u6e05\u695a.<\/strong> \u662f body \u7684\u957f\u5ea6, \u8fd8\u662f\u5305\u542b\u5934\u90e8\u7684\u603b\u957f? \u5dee\u4e00\u4e2a\u5934\u957f\u5ea6, \u7ed3\u679c\u5c31\u662f\u6bcf\u8bfb\u4e00\u6761\u62a5\u6587\u9519\u4f4d\u4e00\u6b21, \u800c\u4e14\u7b2c\u4e00\u6761\u5f80\u5f80\u8fd8\u662f\u5bf9\u7684. \u6709\u4e9b\u534f\u8bae\u5e72\u8106\u4e24\u4e2a\u90fd\u7ed9, \u5404\u6709\u5404\u7684\u7528\u5904: \u603b\u957f\u7528\u6765\u5207\u5e27, body \u957f\u7528\u6765\u5728\u89e3\u538b\u6216\u8005\u89e3\u5bc6\u4e4b\u540e\u786e\u5b9a\u6709\u6548\u6570\u636e\u5230\u54ea\u91cc\u4e3a\u6b62 \u2014\u2014 \u56e0\u4e3a\u53d8\u6362\u8fc7\u540e\u7684\u957f\u5ea6\u548c\u7ebf\u4e0a\u7684\u957f\u5ea6\u4e0d\u662f\u4e00\u56de\u4e8b.<\/p>\n<p><strong>\u957f\u5ea6\u5b57\u6bb5\u7684\u7f16\u7801\u8981\u548c\u5b57\u8282\u5e8f\u4e00\u8d77\u8bf4\u6e05\u695a.<\/strong> \u5927\u7aef\u8fd8\u662f\u5c0f\u7aef (\u7f51\u7edc\u5b57\u8282\u5e8f\u4e60\u60ef\u4e0a\u662f\u5927\u7aef, \u4f46 MySQL \u5c31\u662f\u5c0f\u7aef), \u662f\u4e8c\u8fdb\u5236\u8fd8\u662f ASCII \u6570\u5b57, \u8001\u4e00\u70b9\u7684\u91d1\u878d\u534f\u8bae\u91cc\u8fd8\u4f1a\u7528 BCD \u628a\u957f\u5ea6\u538b\u6210\u534a\u4e2a\u5b57\u8282.<\/p>\n<p><strong>\u4e00\u5b9a\u8981\u6821\u9a8c\u4e0a\u9650.<\/strong> \u4e0d\u6821\u9a8c\u5c31\u662f\u4e00\u4e2a\u8fdc\u7a0b\u5185\u5b58\u8017\u5c3d\u6f0f\u6d1e: \u5bf9\u65b9\u53d1\u4e00\u4e2a <code>0xFFFFFFFF<\/code>, \u4f60\u5c31 <code>make([]byte, 4G)<\/code>. \u8fd9\u4e0d\u9700\u8981\u4ec0\u4e48\u9ad8\u6df1\u7684\u653b\u51fb\u624b\u6cd5, \u4e00\u4e2a\u5199\u9519\u7684\u5ba2\u6237\u7aef\u5c31\u80fd\u628a\u4f60\u6253\u6302. \u4e0a\u9762\u4ee3\u7801\u91cc <code>maxBodyLen<\/code> \u90a3\u4e09\u884c\u4e0d\u662f\u53ef\u9009\u7684.<\/p>\n<p><strong>\u957f\u5ea6\u4e5f\u53ef\u80fd\u662f\u5206\u6bb5\u7684.<\/strong> MySQL \u7684\u957f\u5ea6\u53ea\u6709 3 \u5b57\u8282, \u6240\u4ee5\u8d85\u8fc7 16MB \u7684\u5305\u4f1a\u88ab\u62c6\u6210\u591a\u4e2a, \u6700\u540e\u4e00\u4e2a\u5305\u7684\u957f\u5ea6\u5c0f\u4e8e <code>0xFFFFFF<\/code> \u624d\u7b97\u7ed3\u675f. \u8bbe\u8ba1\u534f\u8bae\u7684\u65f6\u5019, \u4e0e\u5176\u7ed9\u957f\u5ea6\u5b57\u6bb5\u7559\u5f88\u5bbd\u7684\u4f4d\u6570, \u4e0d\u5982\u660e\u786e\u89c4\u5b9a\u4e00\u4e2a\u4e0a\u9650\u52a0\u5206\u6bb5\u89c4\u5219.<\/p>\n<p><strong>\u8003\u8651\u4e00\u4e0b\u9519\u4f4d\u4e4b\u540e\u600e\u4e48\u529e.<\/strong> \u4e00\u65e6\u89e3\u6790\u9519\u4f4d, \u540e\u9762\u8bfb\u5230\u7684\u5168\u662f\u5783\u573e. \u5934\u90e8\u91cc\u653e\u4e00\u4e2a\u9b54\u6570\u6216\u7248\u672c\u53f7\u53ef\u4ee5\u5e2e\u4f60\u53d1\u73b0\u8fd9\u4ef6\u4e8b. \u81f3\u4e8e\u53d1\u73b0\u4e4b\u540e\u600e\u4e48\u6062\u590d \u2014\u2014 \u8001\u5b9e\u8bf4, \u5927\u591a\u6570\u60c5\u51b5\u4e0b\u76f4\u63a5\u65ad\u5f00\u91cd\u8fde\u6bd4\"\u5c1d\u8bd5\u91cd\u65b0\u540c\u6b65\"\u8981\u5b89\u5168\u5f97\u591a, \u56e0\u4e3a\u4f60\u5df2\u7ecf\u4e0d\u77e5\u9053\u81ea\u5df1\u5728\u6d41\u7684\u4ec0\u4e48\u4f4d\u7f6e\u4e86.<\/p>\n<h2 id=\"san-fen-ge-fu\"><a class=\"zola-anchor\" href=\"#san-fen-ge-fu\" aria-label=\"Anchor link for: san-fen-ge-fu\">\u4e09, \u5206\u9694\u7b26<\/a><\/h2>\n<p>\u7528\u4e00\u4e2a\u7ea6\u5b9a\u4e0d\u4f1a\u51fa\u73b0\u5728\u6b63\u6587\u91cc\u7684\u5b57\u8282\u5e8f\u5217\u5207\u5206, \u6700\u5e38\u89c1\u7684\u5c31\u662f <code>\\r\\n<\/code>:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span>sc<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> bufio<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">NewScanner<\/span><span>(<\/span><span>conn<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>sc<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Buffer<\/span><span>(<\/span><span class=\"z-l-6 z-d-7\">make<\/span><span>(<\/span><span>[<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> 0<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> 4096<\/span><span>)<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> 64<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-1 z-d-4\">1024<\/span><span>)<\/span><span class=\"z-l-5 z-d-3\"> \/\/<\/span><span class=\"z-l-5 z-d-3\"> \u663e\u5f0f\u7ed9\u51fa\u4e0a\u9650<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">for<\/span><span> sc<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Scan<\/span><span>(<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">\thandle<\/span><span>(<\/span><span>sc<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Bytes<\/span><span>(<\/span><span>)<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">if<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> sc<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Err<\/span><span>(<\/span><span>)<\/span><span>;<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> !=<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\t\/\/<\/span><span class=\"z-l-5 z-d-3\"> \u6ce8\u610f bufio.ErrTooLong<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p><strong>\u597d\u5904<\/strong>\u662f\u4eba\u53ef\u8bfb. \u53ef\u4ee5\u76f4\u63a5 telnet \u4e0a\u53bb\u6572\u547d\u4ee4, \u6293\u5305\u80fd\u76f4\u63a5\u770b\u61c2, \u51fa\u95ee\u9898\u7684\u65f6\u5019\u8fd9\u4e00\u70b9\u975e\u5e38\u503c\u94b1. \u800c\u4e14\u53d1\u9001\u65b9\u4e0d\u9700\u8981\u9884\u5148\u77e5\u9053\u957f\u5ea6, \u5929\u7136\u9002\u5408\u6d41\u5f0f\u4ea7\u751f\u7684\u5185\u5bb9.<\/p>\n<p><strong>\u4ee3\u4ef7<\/strong>\u4e3b\u8981\u662f\u4e24\u6761.<\/p>\n<p>\u4e00\u662f<strong>\u6b63\u6587\u91cc\u51fa\u73b0\u5206\u9694\u7b26\u600e\u4e48\u529e<\/strong>. \u53ea\u6709\u4e24\u4e2a\u9009\u62e9: \u7981\u6b62 (\u89c4\u5b9a\u6b63\u6587\u4e0d\u80fd\u542b <code>\\n<\/code>), \u6216\u8005\u8f6c\u4e49 (\u7136\u540e\u63a5\u6536\u65b9\u8981\u89e3\u8f6c\u4e49). \u524d\u8005\u9650\u5236\u4e86\u80fd\u4f20\u4ec0\u4e48, \u540e\u8005\u5e26\u6765\u89e3\u6790\u590d\u6742\u5ea6\u548c\u957f\u5ea6\u81a8\u80c0, \u800c\u4e14\u8f6c\u4e49\u89c4\u5219\u4e00\u65e6\u6709\u6b67\u4e49\u5c31\u662f\u5b89\u5168\u95ee\u9898\u7684\u6e29\u5e8a \u2014\u2014 HTTP \u8bf7\u6c42\u8d70\u79c1\u90a3\u4e00\u7c7b\u6f0f\u6d1e, \u6839\u5b50\u4e0a\u5c31\u662f\u6536\u53d1\u53cc\u65b9\u5bf9\u8fb9\u754c\u7684\u7406\u89e3\u4e0d\u4e00\u81f4.<\/p>\n<p>\u4e8c\u662f<strong>\u540c\u6837\u5fc5\u987b\u8bbe\u4e0a\u9650<\/strong>. \u5bf9\u65b9\u53d1\u4e00\u4e2a\u6c38\u8fdc\u4e0d\u5e26\u6362\u884c\u7684\u6d41, \u4f60\u5c31\u4e00\u76f4\u5f80\u7f13\u51b2\u533a\u91cc\u585e. <code>bufio.Scanner<\/code> \u9ed8\u8ba4 64KB \u7684\u4e0a\u9650\u5c31\u662f\u5e72\u8fd9\u4e2a\u7528\u7684, \u522b\u628a\u5b83\u8c03\u6210\u65e0\u9650\u5927; Go \u7684 <code>net\/http<\/code> \u5bf9\u8bf7\u6c42\u884c\u548c header \u4e5f\u90fd\u6709\u957f\u5ea6\u9650\u5236, \u540c\u7406.<\/p>\n<p>\u987a\u4fbf, \u626b\u63cf\u5206\u9694\u7b26\u662f O(n) \u7684, \u6570\u636e\u91cf\u5927\u7684\u65f6\u5019\u6bd4\u8bfb\u4e00\u4e2a\u957f\u5ea6\u5b57\u6bb5\u8d35\u4e0d\u5c11.<\/p>\n<h2 id=\"shi-ji-shang-hun-zhao-yong-cai-shi-chang-tai\"><a class=\"zola-anchor\" href=\"#shi-ji-shang-hun-zhao-yong-cai-shi-chang-tai\" aria-label=\"Anchor link for: shi-ji-shang-hun-zhao-yong-cai-shi-chang-tai\">\u5b9e\u9645\u4e0a, \u6df7\u7740\u7528\u624d\u662f\u5e38\u6001<\/a><\/h2>\n<p>\u7eaf\u5206\u9694\u7b26\u534f\u8bae\u5904\u7406\u4e8c\u8fdb\u5236\u6b63\u6587\u592a\u96be\u53d7, \u6240\u4ee5\u6587\u672c\u534f\u8bae\u57fa\u672c\u90fd\u662f\u6df7\u5408\u7684:<\/p>\n<ul>\n<li><strong>HTTP\/1.1<\/strong>: header \u7528 <code>\\r\\n<\/code> \u5206\u884c, \u7a7a\u884c\u8868\u793a header \u7ed3\u675f; body \u7684\u957f\u5ea6\u7531 <code>Content-Length<\/code> \u7ed9\u51fa. \u800c chunked \u7f16\u7801\u672c\u8eab\u53c8\u662f\u4e00\u4e2a\u6df7\u5408\u4f53 \u2014\u2014 \u6bcf\u4e2a chunk \u662f\"\u5341\u516d\u8fdb\u5236\u957f\u5ea6 + <code>\\r\\n<\/code> + \u6570\u636e + <code>\\r\\n<\/code>\", \u957f\u5ea6\u524d\u7f00\u548c\u5206\u9694\u7b26\u4e00\u8d77\u4e0a.<\/li>\n<li><strong>Redis RESP<\/strong>: \u884c\u7ed3\u6784\u7528 <code>\\r\\n<\/code>, \u4f46 bulk string \u662f <code>$5\\r\\nhello\\r\\n<\/code> \u2014\u2014 \u5148\u7ed9\u957f\u5ea6, \u518d\u8bfb\u5b9a\u957f\u6570\u636e, \u540e\u9762\u90a3\u4e2a <code>\\r\\n<\/code> \u7eaf\u7cb9\u662f\u4e3a\u4e86\u4eba\u770b\u7740\u8212\u670d. \u6b63\u56e0\u4e3a\u6709\u957f\u5ea6, \u503c\u91cc\u9762\u542b <code>\\r\\n<\/code> \u5b8c\u5168\u6ca1\u95ee\u9898.<\/li>\n<\/ul>\n<p>\u8fd9\u4e24\u4e2a\u4f8b\u5b50\u91cc\u7684\u903b\u8f91\u662f\u4e00\u6837\u7684: <strong>\u63a7\u5236\u4fe1\u606f\u7528\u5206\u9694\u7b26, \u56e0\u4e3a\u8981\u4eba\u53ef\u8bfb; \u6570\u636e\u672c\u8eab\u7528\u957f\u5ea6, \u56e0\u4e3a\u8981\u80fd\u88c5\u4efb\u610f\u5b57\u8282.<\/strong><\/p>\n<p>\u8fd8\u6709\u4e00\u79cd\u6781\u7aef\u505a\u6cd5\u503c\u5f97\u4e00\u63d0: <strong>\u4e00\u6761\u8fde\u63a5\u53ea\u53d1\u4e00\u6761\u6d88\u606f, \u7528\u8fde\u63a5\u5173\u95ed\u5f53\u8fb9\u754c<\/strong>. HTTP\/1.0 \u7684\u9ed8\u8ba4\u884c\u4e3a\u5c31\u662f\u8fd9\u6837, \u6ca1\u6709 <code>Content-Length<\/code> \u7684\u54cd\u5e94\u8bfb\u5230 FIN \u4e3a\u6b62. \u5b83\u7684\u4ee3\u4ef7\u662f\u6bcf\u6761\u6d88\u606f\u4e00\u6b21\u4e09\u6b21\u63e1\u624b, \u800c\u4e14\u4f60\u6ca1\u6cd5\u533a\u5206\"\u5bf9\u65b9\u53d1\u5b8c\u4e86\"\u548c\"\u5bf9\u65b9\u6302\u4e86\".<\/p>\n<h2 id=\"zen-me-xuan\"><a class=\"zola-anchor\" href=\"#zen-me-xuan\" aria-label=\"Anchor link for: zen-me-xuan\">\u600e\u4e48\u9009<\/a><\/h2>\n<p>\u5927\u81f4\u662f\u8fd9\u4e48\u51e0\u6761:<\/p>\n<ul>\n<li>\u6b63\u6587\u662f<strong>\u4e8c\u8fdb\u5236<\/strong> \u2192 \u957f\u5ea6\u524d\u7f00. \u6ca1\u4ec0\u4e48\u53ef\u72b9\u8c6b\u7684.<\/li>\n<li>\u6b63\u6587\u662f<strong>\u6587\u672c<\/strong>, \u800c\u4e14\u4f60\u5e0c\u671b\u80fd telnet \u4e0a\u53bb\u8c03\u8bd5 \u2192 \u5206\u9694\u7b26, \u4f46\u6570\u636e\u90e8\u5206\u8fd8\u662f\u7ed9\u957f\u5ea6.<\/li>\n<li>\u5b57\u6bb5<strong>\u5b8c\u5168\u56fa\u5b9a\u4e14\u5f88\u77ed<\/strong> \u2192 \u5b9a\u957f, \u7701\u6389\u4e00\u5207\u89e3\u6790.<\/li>\n<li>\u60f3\u90fd\u4e0d\u60f3\u5c31\u7528 protobuf \/ gRPC \/ HTTP \u2192 \u4e5f\u633a\u597d, \u5b83\u4eec\u53ea\u662f\u628a\u4e0a\u9762\u8fd9\u4e9b\u9009\u62e9\u66ff\u4f60\u505a\u5b8c\u4e86, \u8be5\u6709\u7684\u4e0a\u9650\u6821\u9a8c\u4e5f\u90fd\u505a\u4e86.<\/li>\n<\/ul>\n<h2 id=\"bu-guan-xuan-na-chong-zhe-san-jian-shi-du-yao-zuo\"><a class=\"zola-anchor\" href=\"#bu-guan-xuan-na-chong-zhe-san-jian-shi-du-yao-zuo\" aria-label=\"Anchor link for: bu-guan-xuan-na-chong-zhe-san-jian-shi-du-yao-zuo\">\u4e0d\u7ba1\u9009\u54ea\u79cd, \u8fd9\u4e09\u4ef6\u4e8b\u90fd\u8981\u505a<\/a><\/h2>\n<p><strong>\u4e00, \u7528 <code>ReadFull<\/code>, \u522b\u76f8\u4fe1\u5355\u6b21 <code>Read<\/code>.<\/strong> \u8fd9\u662f\u6700\u5e38\u89c1\u7684\u4e00\u4e2a bug, \u800c\u4e14\u5982\u4e0a\u6240\u8ff0, \u5b83\u5728\u6d4b\u8bd5\u73af\u5883\u91cc\u4e0d\u4f1a\u66b4\u9732.<\/p>\n<p><strong>\u4e8c, \u8bbe\u4e0a\u9650.<\/strong> \u957f\u5ea6\u5b57\u6bb5\u7684\u4e0a\u9650, \u5355\u884c\u7684\u4e0a\u9650, \u7f13\u51b2\u533a\u7684\u4e0a\u9650. \u5c11\u4e00\u4e2a\u5c31\u662f\u4e00\u6761\u62d2\u7edd\u670d\u52a1\u7684\u8def\u5f84.<\/p>\n<p><strong>\u4e09, \u8bbe\u8bfb\u8d85\u65f6.<\/strong> \u4e00\u4e2a\u53ea\u53d1\u4e86\u534a\u6761\u62a5\u6587\u7136\u540e\u5c31\u4e0d\u52a8\u4e86\u7684\u8fde\u63a5, \u5982\u679c\u6ca1\u6709 deadline, \u4f1a\u6c38\u8fdc\u5360\u7740\u4f60\u7684 goroutine \u548c\u7f13\u51b2\u533a. \u800c\u4e14\u8fd9\u79cd\u8fde\u63a5\u5728\u64cd\u4f5c\u7cfb\u7edf\u770b\u6765\u5b8c\u5168\u6b63\u5e38, \u4f60\u4e0d\u4e3b\u52a8\u8d85\u65f6\u5c31\u53d1\u73b0\u4e0d\u4e86.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span>conn<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">SetReadDeadline<\/span><span>(<\/span><span>time<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Now<\/span><span>(<\/span><span>)<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Add<\/span><span>(<\/span><span class=\"z-l-1 z-d-4\">30<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span> time<\/span><span>.<\/span><span>Second<\/span><span>)<\/span><span>)<\/span><\/span><\/code><\/pre>\n<p>\u8fd9\u4e09\u6761\u90fd\u662f\u4ece\"\u5bf9\u7aef\u4e0d\u4e00\u5b9a\u662f\u5584\u610f\u7684, \u4e5f\u4e0d\u4e00\u5b9a\u662f\u6b63\u786e\u7684\"\u8fd9\u4e2a\u524d\u63d0\u63a8\u51fa\u6765\u7684. \u81ea\u5df1\u5199\u534f\u8bae\u7684\u65f6\u5019\u5f88\u5bb9\u6613\u9ed8\u8ba4\u5bf9\u9762\u8dd1\u7684\u662f\u81ea\u5df1\u5199\u7684\u5ba2\u6237\u7aef, \u4f46\u53ea\u8981\u90a3\u4e2a\u7aef\u53e3\u66b4\u9732\u5728\u7f51\u7edc\u4e0a, \u8fd9\u4e2a\u5047\u8bbe\u5c31\u4e0d\u6210\u7acb.<\/p>\n"},{"title":"\u5199\u4e00\u4e2a ISO 8583 \u7684 SDK","published":"2022-12-31T17:40:11+09:00","updated":"2022-12-31T17:40:11+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/building-iso8583-sdk-in-go\/"}},"id":"https:\/\/memwey.github.io\/posts\/building-iso8583-sdk-in-go\/","content":"<p>\u4e1a\u52a1\u4e0a\u8981\u548c\u65e5\u672c\u67d0\u5361\u7ec4\u7ec7\u7684\u4ea4\u6362\u4e2d\u5fc3\u76f4\u8fde, \u8d70 ISO 8583.<\/p>\n<p>\u6700\u521d\u5206\u914d\u7ed9\u6211\u7684\u4efb\u52a1\u662f\u5199\u4e00\u4e2a\u6d4b\u8bd5\u6321\u677f, \u8ba9\u4e1a\u52a1\u90a3\u8fb9\u5148\u80fd\u8dd1\u8d77\u6765, \u4e0d\u7528\u7b49\u5230\u771f\u7684\u63a5\u4e0a\u5bf9\u7aef. \u4f46\u4e00\u52a8\u624b\u5c31\u53d1\u73b0\u987a\u5e8f\u53cd\u4e86 \u2014\u2014 \u6321\u677f\u8981\u80fd\u6536\u4e0b\u6211\u65b9\u53d1\u51fa\u53bb\u7684\u62a5\u6587, \u5c31\u5f97\u4f1a\u89e3\u5305; \u8981\u80fd\u56de\u4e00\u6761\u5bf9\u7aef\u683c\u5f0f\u7684\u54cd\u5e94, \u5c31\u5f97\u4f1a\u5c01\u5305; \u8981\u50cf\u5bf9\u7aef\u90a3\u6837\u5efa\u8fde\u63a5, \u5f00\u5c40, \u6362\u5bc6\u94a5, \u90a3\u8fd9\u4e9b\u4e5f\u4e00\u4e2a\u90fd\u5c11\u4e0d\u4e86. \u6362\u53e5\u8bdd\u8bf4, <strong>\u4e0d\u5148\u628a\u8fd9\u5957\u4e1c\u897f\u505a\u5b8c, \u8fde\u6321\u677f\u90fd\u5199\u4e0d\u51fa\u6765<\/strong>.<\/p>\n<p>\u5e02\u9762\u4e0a\u7684 Go \u5e93\u4e5f\u4e0d\u592a\u7b26\u5408\u9700\u6c42: \u8981\u4e48\u53ea\u505a\u62a5\u6587\u7684\u5c01\u88c5\u89e3\u5305, \u8981\u4e48\u5047\u8bbe\u4f60\u8dd1\u5728\u4e00\u4e2a\u6807\u51c6\u7684 request-response \u6a21\u578b\u4e0a, \u800c\u5bf9\u7aef\u7684\u89c4\u683c\u4e66\u91cc\u5199\u7684\u662f\u5168\u53cc\u5de5, \u53cc\u5411\u4e3b\u52a8\u53d1\u8d77, \u5b9a\u671f\u6362\u5bc6\u94a5.<\/p>\n<p>\u6240\u4ee5\u6700\u540e\u505a\u51fa\u6765\u7684\u4e0d\u662f\u4e00\u4e2a\u62a5\u6587\u5e93, \u4e5f\u4e0d\u53ea\u662f\u4e00\u4e2a\u6321\u677f. \u5c01\u5305\u89e3\u5305\u53ea\u662f\u6700\u5e95\u4e0b\u7684\u4e00\u5c42, \u4e0a\u9762\u8fd8\u538b\u7740\u8fde\u63a5, \u4f1a\u8bdd, \u5bc6\u94a5, \u4ee5\u53ca\u4e00\u6574\u5957\u7ed9\u4e1a\u52a1\u7528\u7684\u63a5\u53e3 \u2014\u2014 \u662f\u4e00\u4e2a SDK. \u800c\u5f53\u521d\u8981\u7684\u90a3\u4e2a\u6321\u677f, \u53cd\u5012\u6210\u4e86\u5b83\u7684\u4e00\u4e2a\u4f7f\u7528\u8005.<\/p>\n<p>\u8d81\u5e74\u672b\u8fd8\u8bb0\u5f97, \u628a\u51e0\u4e2a\u8bbe\u8ba1\u51b3\u5b9a\u8bb0\u4e00\u4e0b. \u5177\u4f53\u7684\u63a5\u7eed\u89c4\u683c\u662f\u6709 NDA \u7684, \u6240\u4ee5\u4e0b\u9762\u7684\u4ee3\u7801\u90fd\u662f\u8131\u654f\u548c\u7b80\u5316\u8fc7\u7684, \u53ea\u7559\u8bbe\u8ba1\u672c\u8eab.<\/p>\n<h2 id=\"iso-8583-shi-shen-me\"><a class=\"zola-anchor\" href=\"#iso-8583-shi-shen-me\" aria-label=\"Anchor link for: iso-8583-shi-shen-me\">ISO 8583 \u662f\u4ec0\u4e48<\/a><\/h2>\n<p>\u7b80\u5355\u8bf4, \u662f\u5237\u5361\u4ea4\u6613\u7684\u62a5\u6587\u6807\u51c6. \u4f60\u5728\u4fbf\u5229\u5e97\u5237\u4e00\u5f20\u5361, \u4ece POS \u673a\u5230\u6536\u5355\u673a\u6784\u5230\u5361\u7ec4\u7ec7\u5230\u53d1\u5361\u884c, \u8fd9\u4e00\u8def\u4e0a\u8dd1\u7684\u591a\u534a\u5c31\u662f ISO 8583 \u6216\u8005\u5b83\u7684\u67d0\u4e2a\u65b9\u8a00.<\/p>\n<p>\u62a5\u6587\u7684\u7ed3\u6784\u975e\u5e38\u6709\u5e74\u4ee3\u611f:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>+--------+------------------+---------------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span>|  MTI   |      Bitmap      |          Fields           |<\/span><\/span>\n<span class=\"giallo-l\"><span>| 4 bytes|  8 or 16 bytes   |         \u53d8\u957f               |<\/span><\/span>\n<span class=\"giallo-l\"><span>+--------+------------------+---------------------------+<\/span><\/span><\/code><\/pre>\n<ul>\n<li><strong>MTI<\/strong> (Message Type Indicator), 4 \u4f4d\u6570\u5b57, \u8bf4\u660e\u8fd9\u6761\u62a5\u6587\u662f\u4ec0\u4e48, \u6bd4\u5982\u6388\u6743\u8bf7\u6c42, \u51b2\u6b63, \u7f51\u7edc\u7ba1\u7406.<\/li>\n<li><strong>Bitmap<\/strong>, 64 \u4e2a bit, \u7b2c N \u4e2a bit \u4e3a 1 \u8868\u793a\u7b2c N \u4e2a\u57df\u51fa\u73b0\u5728\u62a5\u6587\u91cc. \u7b2c 1 \u4e2a bit \u6bd4\u8f83\u7279\u6b8a, \u5b83\u4e3a 1 \u8868\u793a\u540e\u9762\u8fd8\u8ddf\u4e86\u7b2c\u4e8c\u4e2a bitmap, \u5373\u8fd9\u6761\u62a5\u6587\u7528\u5230\u4e86 65~128 \u57df.<\/li>\n<li><strong>Fields<\/strong>, \u6309\u57df\u53f7\u4ece\u5c0f\u5230\u5927\u4f9d\u6b21\u6392\u5217. \u6bcf\u4e2a\u57df\u662f\u5b9a\u957f\u8fd8\u662f\u53d8\u957f, \u662f\u6570\u5b57\u8fd8\u662f\u5b57\u7b26, \u7528\u4ec0\u4e48\u7f16\u7801, \u90fd\u7531\u89c4\u683c\u4e66\u89c4\u5b9a.<\/li>\n<\/ul>\n<p>\u5b83\u662f\u4e2a 1980 \u5e74\u4ee3\u7684\u6807\u51c6, \u6240\u4ee5\u5904\u5904\u662f\u7701\u5b57\u8282\u7684\u75d5\u8ff9: \u57df\u51fa\u73b0\u4e0e\u5426\u7528 bit \u8868\u793a\u800c\u4e0d\u662f\u7528 key, \u6570\u5b57\u7528 BCD \u538b\u7f29\u6210\u534a\u4e2a\u5b57\u8282, \u53d8\u957f\u57df\u7684\u957f\u5ea6\u5934\u4e5f\u7528 BCD. \u5728\u4eca\u5929\u770b\u8fd9\u4e9b\u8bbe\u8ba1\u5f88\u522b\u626d, \u4f46\u5728\u4e13\u7ebf\u6309\u5b57\u8282\u8ba1\u8d39\u7684\u5e74\u4ee3\u662f\u5408\u7406\u7684.<\/p>\n<p>\u4e0d\u8fc7\u6709\u4e00\u4ef6\u4e8b\u8981\u5148\u5206\u6e05\u695a: <strong>ISO 8583 \u662f\u516c\u5f00\u7684\u6807\u51c6, \u4f46\u5b83\u7ba1\u7684\u57fa\u672c\u4e0a\u53ea\u6709\u62a5\u6587<\/strong>.<\/p>\n<p>\u5b83\u89c4\u5b9a\u4e86 MTI, bitmap, \u6bcf\u4e2a\u57df\u53f7\u5927\u81f4\u5bf9\u5e94\u4ec0\u4e48\u542b\u4e49, \u4ee5\u53ca\u5404\u7c7b\u57df\u7684\u7c7b\u578b\u548c\u957f\u5ea6\u8868\u793a\u6cd5. \u81f3\u4e8e\u8fde\u63a5\u600e\u4e48\u5efa, \u4f1a\u8bdd\u600e\u4e48\u5f00\u600e\u4e48\u5173, \u5fc3\u8df3\u591a\u4e45\u53d1\u4e00\u6b21, \u5bc6\u94a5\u600e\u4e48\u4e0b\u53d1\u600e\u4e48\u8f6e\u6362, \u51fa\u4e86\u9519\u56de\u4ec0\u4e48\u7801, \u65e5\u5207\u600e\u4e48\u5bf9\u8d26 \u2014\u2014 \u4e00\u6982\u4e0d\u7ba1. \u8fd9\u4e9b\u5168\u90e8\u7531\u4f7f\u7528\u8fd9\u5f20\u7f51\u7684\u53cc\u65b9\u81ea\u5df1\u7ea6\u5b9a.<\/p>\n<p>\u800c\u4e14\u5c31\u7b97\u53ea\u770b\u62a5\u6587\u8fd9\u4e00\u5c42, \u5404\u65b9\u4e5f\u90fd\u6709\u81ea\u5df1\u7684\u53d8\u4f53. \u540c\u4e00\u4e2a\u57df\u53f7, \u8fd9\u5f20\u7f51\u62ff\u6765\u653e\u8fd9\u4e2a, \u90a3\u5f20\u7f51\u62ff\u6765\u653e\u90a3\u4e2a; \u6709\u7684\u57df\u6574\u5f20\u7f51\u90fd\u4e0d\u7528; \u957f\u5ea6\u5934\u7684\u7f16\u7801, \u5b57\u7b26\u96c6, \u5b9a\u957f\u57df\u5f80\u54ea\u8fb9\u8865\u4f4d, \u4e5f\u5404\u5bb6\u4e0d\u540c.<\/p>\n<p>\u6240\u4ee5\"\u652f\u6301 ISO 8583\"\u8fd9\u53e5\u8bdd\u672c\u8eab\u51e0\u4e4e\u4e0d\u63d0\u4f9b\u4ec0\u4e48\u4fe1\u606f, \u771f\u6b63\u8981\u95ee\u7684\u662f\"\u652f\u6301\u54ea\u4e00\u5f20\u7f51\u7684 ISO 8583\". \u800c\u8fd9\u4e2a\u95ee\u9898\u7684\u7b54\u6848, \u53ea\u5199\u5728\u63a5\u7eed\u89c4\u683c\u4e66\u91cc.<\/p>\n<h2 id=\"zui-da-de-kun-nan-shi-wen-dang\"><a class=\"zola-anchor\" href=\"#zui-da-de-kun-nan-shi-wen-dang\" aria-label=\"Anchor link for: zui-da-de-kun-nan-shi-wen-dang\">\u6700\u5927\u7684\u56f0\u96be\u662f\u6587\u6863<\/a><\/h2>\n<p>\u5fc5\u987b\u5148\u8bf4\u8fd9\u4e2a, \u56e0\u4e3a\u6574\u4e2a\u9879\u76ee\u91cc\u6700\u96be\u7684\u90e8\u5206\u4ece\u6765\u4e0d\u662f\u4ee3\u7801.<\/p>\n<p>\u89c4\u683c\u4e66\u662f\u51e0\u767e\u9875\u7684\u65e5\u6587 PDF, \u8fd8\u8fdc\u4e0d\u6b62\u4e00\u4efd. \u5370\u8c61\u91cc\u524d\u540e\u62ff\u5230\u7684\u6709\u5341\u6765\u518c: \u57fa\u672c\u7bc7\u548c\u7535\u6587\u7bc7\u7b97\u4e3b\u5e72, \u7136\u540e<strong>\u6bcf\u591a\u4e00\u4e2a\u529f\u80fd\u5c31\u591a\u4e00\u518c<\/strong> \u2014\u2014 IC \u5361\u662f\u5355\u72ec\u4e00\u518c, \u975e\u63a5\u89e6\u7684\u30bf\u30c3\u30c1\u53c8\u662f\u4e00\u518c, PIN \u76f8\u5173\u7684\u518d\u4e00\u518c, \u52a0\u4e0a\u5404\u79cd\u522b\u518c\u548c\u5386\u5e74\u7684\u6539\u8ba2\u901a\u77e5. \u645e\u8d77\u6765\u8f7b\u677e\u4e0a\u5343\u9875.<\/p>\n<p>\u66f4\u9ebb\u70e6\u7684\u662f\u5b83\u4eec\u7684\u5e74\u9f84. \u8fd9\u5957\u4e1c\u897f\u662f\u4e0a\u4e16\u7eaa\u5c31\u5728\u8dd1\u7684, \u6587\u6863\u4e5f\u662f\u90a3\u65f6\u5019\u7559\u4e0b\u6765\u4e00\u8def\u6539\u8fc7\u6765\u7684, \u4e8e\u662f\u4f60\u4f1a\u8bfb\u5230\u8fd9\u6837\u7684\u5185\u5bb9:<\/p>\n<ul>\n<li>\u6392\u7248\u662f\u7b49\u5bbd\u5b57\u4f53\u753b\u7684\u8868\u683c, \u6709\u4e9b\u9875\u5e72\u8106\u662f\u626b\u63cf\u4ef6, \u590d\u5236\u4e0d\u51fa\u6587\u5b57, \u53ea\u80fd\u5bf9\u7740\u5c4f\u5e55\u4e00\u4e2a\u5b57\u4e00\u4e2a\u5b57\u6572.<\/li>\n<li>\u672f\u8bed\u662f\u662d\u548c\u7684. \u96fb\u6587, \u4ed5\u5411, \u5b9b\u5148, \u52a0\u76df\u5e97, \u958b\u5c40, \u9589\u5c40, \u7de0\u3081, \u30ab\u30c3\u30c8\u30aa\u30fc\u30d0\u30fc \u2014\u2014 \u6bcf\u4e00\u4e2a\u90fd\u8981\u5148\u641e\u6e05\u695a\u5b83\u5728\u8fd9\u4e2a\u8bed\u5883\u4e0b\u5177\u4f53\u6307\u4ec0\u4e48, \u800c\u4e0d\u662f\u5b57\u9762\u610f\u601d.<\/li>\n<li>\u7247\u5047\u540d\u5916\u6765\u8bed\u548c\u6c49\u5b57\u8bcd\u6df7\u7740\u7528. \u30ec\u30b3\u30fc\u30c9, \u30d5\u30a3\u30fc\u30eb\u30c9, \u30d8\u30c3\u30c0 \u662f\u4e00\u5957, \u96fb\u6587\u9577, \u53ef\u5909\u9577 \u662f\u53e6\u4e00\u5957, \u6307\u7684\u5374\u662f\u540c\u4e00\u5c42\u4e1c\u897f.<\/li>\n<li><strong>\u751a\u81f3\u8fd8\u6709 X.25 \u7684\u63cf\u8ff0.<\/strong> \u5206\u7ec4\u4ea4\u6362\u7f51, \u4e0a\u4e16\u7eaa\u4e03\u5341\u5e74\u4ee3\u7684\u4e1c\u897f. \u65e9\u5c31\u8dd1\u5728 TCP\/IP \u4e0a\u4e86, \u90a3\u4e00\u6bb5\u5374\u8fd8\u7559\u7740. \u8bfb\u7684\u65f6\u5019\u8981\u4e00\u8fb9\u5206\u8fa8\u54ea\u4e9b\u5df2\u7ecf\u4e0d\u9002\u7528, \u4e00\u8fb9\u5c0f\u5fc3\u90a3\u4e9b\u770b\u7740\u8fc7\u65f6, \u5b9e\u9645\u4e0a\u5bf9\u7aef\u8fd8\u5728\u4e25\u683c\u6267\u884c\u7684\u90e8\u5206.<\/li>\n<\/ul>\n<p>\u4f46\u771f\u6b63\u7d2f\u4eba\u7684\u4e0d\u662f\u8fd9\u4e9b, \u800c\u662f<strong>\u8fd9\u4e9b\u6587\u6863\u4e4b\u95f4\u6ca1\u6709\u94fe\u63a5<\/strong>.<\/p>\n<p>\u5012\u4e0d\u662f\u8bf4\u5b83\u4eec\u5199\u5f97\u6709\u77db\u76fe \u2014\u2014 \u6070\u6070\u76f8\u53cd, \u5185\u5bb9\u76f8\u5f53\u4e25\u8c28, \u8be5\u89c4\u5b9a\u7684\u90fd\u89c4\u5b9a\u4e86. \u95ee\u9898\u662f\u540c\u4e00\u4ef6\u4e8b\u7684\u4fe1\u606f\u88ab\u6309\u529f\u80fd\u5207\u5f00, \u644a\u5728\u597d\u51e0\u518c\u91cc.<\/p>\n<p>\u4e3e\u4e2a\u5b9e\u9645\u7684\u4f8b\u5b50: \u8981\u641e\u6e05\u695a\u4e00\u7b14\u5e26 PIN \u7684 IC \u5361\u4ea4\u6613\u600e\u4e48\u53d1, \u57df\u7684\u4f4d\u7f6e\u548c\u957f\u5ea6\u5728\u7535\u6587\u7bc7, PIN block \u600e\u4e48\u7b97, \u7528\u54ea\u628a\u5bc6\u94a5\u52a0\u5bc6\u5728 PIN \u90a3\u4e00\u518c, IC \u5361\u6570\u636e\u57df\u91cc\u90a3\u4e32 TLV \u7684\u6784\u6210\u5728 IC \u5361\u90a3\u4e00\u518c, \u800c\u8fd9\u4e09\u518c\u5bf9\u540c\u4e00\u6761\u62a5\u6587\u5404\u81ea\u53ea\u8bb2\u81ea\u5df1\u8d1f\u8d23\u7684\u90a3\u4e00\u90e8\u5206. \u8c01\u4e5f\u6ca1\u9519, \u4f46\u6ca1\u6709\u4e00\u518c\u80fd\u5355\u72ec\u56de\u7b54\"\u8fd9\u6761\u62a5\u6587\u5230\u5e95\u957f\u4ec0\u4e48\u6837\".<\/p>\n<p><strong>\u4f60\u5c31\u662f\u90a3\u4e2a\u8d85\u94fe\u63a5.<\/strong> \u6ca1\u6709\u4ea4\u53c9\u5f15\u7528, \u6ca1\u6709\u7d22\u5f15, \u626b\u63cf\u7684\u90a3\u51e0\u9875\u8fde\u5168\u6587\u68c0\u7d22\u90fd\u505a\u4e0d\u4e86, \u5168\u9760\u81ea\u5df1\u8bb0\u4f4f\u54ea\u4e00\u6761\u5199\u5728\u54ea\u4e00\u518c\u7684\u7b2c\u51e0\u9875. \u6240\u4ee5\u524d\u671f\u6709\u76f8\u5f53\u4e00\u90e8\u5206\u65f6\u95f4, \u5176\u5b9e\u662f\u5728\u7ed9\u81ea\u5df1\u5efa\u7d22\u5f15: \u672f\u8bed\u7684\u5bf9\u7167, \u6bcf\u4e2a\u57df\u7684\u51fa\u5904, \u5404\u518c\u4e4b\u95f4\u7684\u5bf9\u5e94\u5173\u7cfb. \u8fd9\u4ef6\u4e8b\u6ca1\u6709\u4efb\u4f55\u6280\u672f\u542b\u91cf, \u4f46\u8df3\u8fc7\u5b83\u7684\u4ee3\u4ef7\u662f\u540e\u9762\u6bcf\u67e5\u4e00\u6b21\u90fd\u8981\u91cd\u65b0\u7ffb\u4e00\u904d.<\/p>\n<p>\u5b9e\u5728\u8bfb\u4e0d\u51fa\u6765\u7684\u5730\u65b9\u4e5f\u6709, \u53ea\u80fd\u8bb0\u4e0b\u6765\u6512\u7740, \u6512\u591f\u4e00\u6279\u518d\u53bb\u95ee\u5bf9\u7aef \u2014\u2014 \u95ee\u4e00\u8f6e\u7684\u5468\u671f\u4ee5\u5468\u8ba1, \u6240\u4ee5\u6e05\u5355\u8981\u6512\u5f97\u591f\u539a\u624d\u5212\u7b97.<\/p>\n<p>\u6240\u4ee5\u771f\u6b63\u7684\u5de5\u4f5c\u91cf\u5206\u5e03\u5927\u6982\u662f: \u8bfb\u6587\u6863, \u6574\u7406\u672f\u8bed, \u5efa\u7d22\u5f15\u5360\u4e86\u4e00\u5927\u534a, \u5199\u4ee3\u7801\u53cd\u800c\u662f\u6700\u5feb\u7684\u90e8\u5206. \u8fd9\u4e5f\u76f4\u63a5\u51b3\u5b9a\u4e86\u540e\u9762\u51e0\u4e4e\u6240\u6709\u7684\u8bbe\u8ba1.<\/p>\n<p>\u56e0\u4e3a\u8bfb\u6587\u6863\u8fd9\u4ef6\u4e8b\u6700\u5927\u7684\u98ce\u9669\u4e0d\u662f\u8bfb\u6162\u4e86, \u800c\u662f<strong>\u8bfb\u9519\u4e86\u5374\u4e0d\u77e5\u9053<\/strong>. \u4e00\u4e2a\u4eba\u5bf9\u7740\u4e0a\u5343\u9875 PDF \u8bfb\u51fa\u6765\u7684\u7406\u89e3, \u5982\u679c\u53ea\u7559\u5728\u4ed6\u8111\u5b50\u91cc, \u6216\u8005\u53ea\u5199\u6210\u4e00\u9875 wiki, \u90a3\u5b83\u65e2\u4e0d\u4f1a\u88ab review, \u4e5f\u4e0d\u4f1a\u88ab\u9a8c\u8bc1, \u51fa\u4e86\u95ee\u9898\u8fd8\u67e5\u4e0d\u5230\u6e90\u5934. \u6240\u4ee5\u4ece\u4e00\u5f00\u59cb\u5c31\u5b9a\u4e86\u4e00\u4e2a\u539f\u5219:<\/p>\n<blockquote>\n<p>\u51e1\u662f\u89c4\u683c\u4e66\u91cc\u5199\u7684\u7ea6\u675f, \u90fd\u8981\u53d8\u6210\u4ee3\u7801\u91cc\u80fd\u8dd1\u7684\u4e1c\u897f.<\/p>\n<\/blockquote>\n<p>\u57df\u7684\u957f\u5ea6, \u7f16\u7801\u65b9\u5f0f, \u662f\u5b9a\u957f\u8fd8\u662f\u53d8\u957f, \u5728\u54ea\u79cd\u7535\u6587\u91cc\u5fc5\u987b\u51fa\u73b0, \u53d6\u503c\u8303\u56f4\u6709\u54ea\u4e9b \u2014\u2014 \u5168\u90e8\u5199\u8fdb\u7ed3\u6784\u4f53\u548c\u6821\u9a8c\u5668, \u800c\u4e0d\u662f\u5199\u8fdb\u6ce8\u91ca\u6216\u8005\u6587\u6863. \u8fd9\u6837\"\u6211\u5bf9\u89c4\u683c\u4e66\u7684\u7406\u89e3\"\u5c31\u6210\u4e86\u4e00\u4e2a\u53ef\u4ee5\u88ab review, \u88ab\u6d4b\u8bd5, \u88ab\u540e\u6765\u4eba\u4fee\u6b63\u7684\u4e1c\u897f.<\/p>\n<p>\u800c\u4e00\u65e6\u8fd9\u4e48\u60f3, \u4e8b\u60c5\u5c31\u53d8\u5f97\u5f88\u987a: \u65e2\u7136\u62a5\u6587\u65e0\u975e\u662f\"\u54ea\u4e9b\u57df\u51fa\u73b0\u4e86, \u6bcf\u4e2a\u57df\u600e\u4e48\u7f16\u7801\", \u90a3\u5b83\u5b8c\u5168\u53ef\u4ee5\u7528 Go \u7684\u7ed3\u6784\u4f53\u548c tag \u63cf\u8ff0\u51fa\u6765.<\/p>\n<h2 id=\"yong-struct-tag-miao-shu-bao-wen\"><a class=\"zola-anchor\" href=\"#yong-struct-tag-miao-shu-bao-wen\" aria-label=\"Anchor link for: yong-struct-tag-miao-shu-bao-wen\">\u7528 struct tag \u63cf\u8ff0\u62a5\u6587<\/a><\/h2>\n<p>\u5e95\u5c42\u7684\u5c01\u5305\u89e3\u5305\u90e8\u5206, \u6211\u4eec\u6ca1\u6709\u4ece\u96f6\u5199, \u800c\u662f\u57fa\u4e8e <a rel=\"external\" href=\"https:\/\/github.com\/ideazxy\/iso8583\">ideazxy\/iso8583<\/a> \u7684\u601d\u8def\u505a\u7684\u6269\u5c55. \u5b83\u7684\u6838\u5fc3\u62bd\u8c61\u662f\u4e00\u4e2a\u63a5\u53e3:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/\/<\/span><span class=\"z-l-5 z-d-3\"> Iso8583Type interface for ISO 8583 fields<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">type<\/span><span class=\"z-l-6 z-d-7\"> Iso8583Type<\/span><span class=\"z-l-8 z-d-10\"> interface<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\t\/\/<\/span><span class=\"z-l-5 z-d-3\"> Bytes \u628a\u5f53\u524d\u57df\u7f16\u7801\u6210\u5b57\u8282<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">\tBytes<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">encoder<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> lenEncoder<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> length<\/span><span class=\"z-l-8 z-d-10\"> int<\/span><span>)<\/span><span> (<\/span><span>[<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><span>,<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\t\/\/<\/span><span class=\"z-l-5 z-d-3\"> Load \u4ece\u5b57\u8282\u6d41\u89e3\u51fa\u5f53\u524d\u57df, \u8fd4\u56de\u5b9e\u9645\u6d88\u8d39\u7684\u5b57\u8282\u6570<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">\tLoad<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">raw<\/span><span> [<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> encoder<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> lenEncoder<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> length<\/span><span class=\"z-l-8 z-d-10\"> int<\/span><span>)<\/span><span> (<\/span><span class=\"z-l-8 z-d-10\">int<\/span><span>,<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\t\/\/<\/span><span class=\"z-l-5 z-d-3\"> IsEmpty \u5224\u65ad\u57df\u662f\u5426\u4e3a\u7a7a<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">\tIsEmpty<\/span><span>(<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\"> bool<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u7136\u540e <code>Numeric<\/code>, <code>Alphanumeric<\/code>, <code>Binary<\/code>, <code>Llvar<\/code>, <code>Lllvar<\/code>, <code>Llnumeric<\/code>, <code>Lllnumeric<\/code> \u5404\u81ea\u5b9e\u73b0\u5b83. <code>Ll<\/code> \u548c <code>Lll<\/code> \u524d\u7f00\u662f ISO 8583 \u7684\u9ed1\u8bdd, \u6307\u957f\u5ea6\u5934\u662f 2 \u4f4d\u8fd8\u662f 3 \u4f4d\u5341\u8fdb\u5236\u6570\u7684\u53d8\u957f\u57df.<\/p>\n<p>\u4e8e\u662f\u4e00\u6761\u62a5\u6587\u5c31\u662f\u4e00\u4e2a\u7ed3\u6784\u4f53:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">type<\/span><span class=\"z-l-6 z-d-7\"> Body<\/span><span class=\"z-l-8 z-d-10\"> struct<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\tF2<\/span><span class=\"z-l-8 z-d-10\">  *<\/span><span class=\"z-l-6 z-d-7\">iso8583<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Llvar<\/span><span class=\"z-l-2 z-d-6\">        `<\/span><span class=\"z-l-2 z-d-6\">field:&quot;2&quot;  length:&quot;19&quot; encode:&quot;jis8&quot;<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-5 z-d-3\"> \/\/<\/span><span class=\"z-l-5 z-d-3\"> \u4f1a\u5458\u53f7<\/span><\/span>\n<span class=\"giallo-l\"><span>\tF3<\/span><span class=\"z-l-8 z-d-10\">  *<\/span><span class=\"z-l-6 z-d-7\">iso8583<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Numeric<\/span><span class=\"z-l-2 z-d-6\">      `<\/span><span class=\"z-l-2 z-d-6\">field:&quot;3&quot;  length:&quot;6&quot;  encode:&quot;jis8&quot;<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-5 z-d-3\"> \/\/<\/span><span class=\"z-l-5 z-d-3\"> \u5904\u7406\u7801<\/span><\/span>\n<span class=\"giallo-l\"><span>\tF4<\/span><span class=\"z-l-8 z-d-10\">  *<\/span><span class=\"z-l-6 z-d-7\">iso8583<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Numeric<\/span><span class=\"z-l-2 z-d-6\">      `<\/span><span class=\"z-l-2 z-d-6\">field:&quot;4&quot;  length:&quot;12&quot; encode:&quot;jis8&quot;<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-5 z-d-3\"> \/\/<\/span><span class=\"z-l-5 z-d-3\"> \u4ea4\u6613\u91d1\u989d<\/span><\/span>\n<span class=\"giallo-l\"><span>\tF11<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">iso8583<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Numeric<\/span><span class=\"z-l-2 z-d-6\">      `<\/span><span class=\"z-l-2 z-d-6\">field:&quot;11&quot; length:&quot;6&quot;  encode:&quot;jis8&quot;<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-5 z-d-3\"> \/\/<\/span><span class=\"z-l-5 z-d-3\"> \u7cfb\u7edf\u8ddf\u8e2a\u53f7<\/span><\/span>\n<span class=\"giallo-l\"><span>\tF12<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">iso8583<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Numeric<\/span><span class=\"z-l-2 z-d-6\">      `<\/span><span class=\"z-l-2 z-d-6\">field:&quot;12&quot; length:&quot;12&quot; encode:&quot;jis8&quot;<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-5 z-d-3\"> \/\/<\/span><span class=\"z-l-5 z-d-3\"> \u4ea4\u6613\u65f6\u95f4<\/span><\/span>\n<span class=\"giallo-l\"><span>\tF37<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">iso8583<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Alphanumeric<\/span><span class=\"z-l-2 z-d-6\"> `<\/span><span class=\"z-l-2 z-d-6\">field:&quot;37&quot; length:&quot;12&quot; encode:&quot;jis8&quot;<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-5 z-d-3\"> \/\/<\/span><span class=\"z-l-5 z-d-3\"> \u68c0\u7d22\u53c2\u8003\u53f7<\/span><\/span>\n<span class=\"giallo-l\"><span>\tF52<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">iso8583<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Binary<\/span><span class=\"z-l-2 z-d-6\">       `<\/span><span class=\"z-l-2 z-d-6\">field:&quot;52&quot; length:&quot;8&quot;<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-5 z-d-3\">                \/\/<\/span><span class=\"z-l-5 z-d-3\"> PIN block<\/span><\/span>\n<span class=\"giallo-l\"><span>\tF55<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">iso8583<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">LllBinary<\/span><span class=\"z-l-2 z-d-6\">    `<\/span><span class=\"z-l-2 z-d-6\">field:&quot;55&quot; length:&quot;255&quot;<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-5 z-d-3\">              \/\/<\/span><span class=\"z-l-5 z-d-3\"> IC \u5361\u6570\u636e<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p><code>Bytes()<\/code> \u7684\u65f6\u5019, \u7528\u53cd\u5c04\u904d\u5386\u8fd9\u4e2a\u7ed3\u6784\u4f53, \u4ece tag \u91cc\u8bfb\u51fa\u57df\u53f7, \u957f\u5ea6\u548c\u7f16\u7801, \u57df\u53f7\u51b3\u5b9a\u5b83\u5728 bitmap \u91cc\u70b9\u54ea\u4e2a bit, \u7f16\u7801\u51b3\u5b9a\u5b83\u600e\u4e48\u53d8\u6210\u5b57\u8282:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span class=\"z-l-6 z-d-7\"> parseFields<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">msg<\/span><span class=\"z-l-8 z-d-10\"> interface<\/span><span>{<\/span><span>}<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\"> map<\/span><span>[<\/span><span class=\"z-l-8 z-d-10\">int<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-6 z-d-7\">fieldInfo<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\tfields<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span class=\"z-l-6 z-d-7\"> make<\/span><span>(<\/span><span class=\"z-l-8 z-d-10\">map<\/span><span>[<\/span><span class=\"z-l-8 z-d-10\">int<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-6 z-d-7\">fieldInfo<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>\tv<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> reflect<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Indirect<\/span><span>(<\/span><span>reflect<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">ValueOf<\/span><span>(<\/span><span>msg<\/span><span>)<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tfor<\/span><span> i<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span class=\"z-l-1 z-d-4\"> 0<\/span><span>;<\/span><span> i<\/span><span class=\"z-l-8 z-d-10\"> &lt;<\/span><span> v<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">NumField<\/span><span>(<\/span><span>)<\/span><span>;<\/span><span> i<\/span><span class=\"z-l-8 z-d-10\">++<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\t\t\/\/<\/span><span class=\"z-l-5 z-d-3\"> \u6307\u9488\u4e3a nil \u7684\u57df, \u76f4\u63a5\u8df3\u8fc7, \u4e0d\u8fdb bitmap<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\tif<\/span><span class=\"z-l-6 z-d-7\"> isPtrOrInterface<\/span><span>(<\/span><span>v<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Field<\/span><span>(<\/span><span>i<\/span><span>)<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Kind<\/span><span>(<\/span><span>)<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\"> &amp;&amp;<\/span><span> v<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Field<\/span><span>(<\/span><span>i<\/span><span>)<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">IsNil<\/span><span>(<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\t\tcontinue<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t}<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tsf<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> v<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Type<\/span><span>(<\/span><span>)<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Field<\/span><span>(<\/span><span>i<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tindex<\/span><span>,<\/span><span> _<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> strconv<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Atoi<\/span><span>(<\/span><span>sf<\/span><span>.<\/span><span>Tag<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Get<\/span><span>(<\/span><span>TAG_FIELD<\/span><span>)<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\t\t\/\/<\/span><span class=\"z-l-5 z-d-3\"> ... \u89e3\u6790 encode \/ length tag<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tfield<\/span><span>,<\/span><span> ok<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> v<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Field<\/span><span>(<\/span><span>i<\/span><span>)<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Interface<\/span><span>(<\/span><span>)<\/span><span>.<\/span><span>(<\/span><span class=\"z-l-6 z-d-7\">Iso8583Type<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\tif<\/span><span class=\"z-l-8 z-d-10\"> !<\/span><span>ok<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">\t\t\tpanic<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span class=\"z-l-2 z-d-6\">field must be Iso8583Type<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t}<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tfields<\/span><span>[<\/span><span>index<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-8 z-d-10\"> &amp;<\/span><span class=\"z-l-6 z-d-7\">fieldInfo<\/span><span>{<\/span><span>index<\/span><span>,<\/span><span> encode<\/span><span>,<\/span><span> lenEncode<\/span><span>,<\/span><span> length<\/span><span>,<\/span><span> field<\/span><span>}<\/span><\/span>\n<span class=\"giallo-l\"><span>\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\treturn<\/span><span> fields<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u8fd9\u91cc\u6709\u4e24\u4e2a\u6211\u89c9\u5f97\u633a\u8212\u670d\u7684\u5730\u65b9.<\/p>\n<p>\u7b2c\u4e00, <strong>\u6240\u6709\u57df\u90fd\u7528\u6307\u9488<\/strong>. Go \u6ca1\u6709 optional, \u800c ISO 8583 \u91cc\"\u57df\u4e0d\u5b58\u5728\"\u548c\"\u57df\u662f\u7a7a\u5b57\u7b26\u4e32\"\u662f\u4e24\u4ef6\u4e0d\u540c\u7684\u4e8b (\u524d\u8005 bitmap \u4e0a\u662f 0, \u540e\u8005\u662f 1 \u52a0\u4e00\u4e2a\u957f\u5ea6\u4e3a 0 \u7684\u53d8\u957f\u57df). \u7528\u6307\u9488 nil \u8868\u8fbe\"\u4e0d\u5b58\u5728\", \u7528 <code>IsEmpty()<\/code> \u8868\u8fbe\"\u5b58\u5728\u4f46\u4e3a\u7a7a\", \u8bed\u4e49\u5c31\u5bf9\u4e0a\u4e86. \u8c03\u7528\u65b9\u53ea\u9700\u8981 <code>models.WithF39(\"000\")<\/code> \u8fd9\u6837\u586b\u81ea\u5df1\u5173\u5fc3\u7684\u57df, \u5269\u4e0b\u7684\u81ea\u7136\u4e0d\u51fa\u73b0\u5728\u62a5\u6587\u91cc.<\/p>\n<p>\u7b2c\u4e8c, <strong>bitmap \u4e0d\u9700\u8981\u4eba\u6765\u7ef4\u62a4<\/strong>. \u8001\u4e00\u70b9\u7684\u5b9e\u73b0\u91cc, \u5e38\u5e38\u662f\u4e1a\u52a1\u4ee3\u7801\u81ea\u5df1\u53bb set bit, \u7136\u540e\u518d append \u6570\u636e, \u4e00\u65e6\u6f0f\u4e86\u4e00\u5904\u5c31\u662f\u4e00\u6761\u5bf9\u7aef\u89e3\u4e0d\u5f00\u7684\u62a5\u6587. \u4ea4\u7ed9\u53cd\u5c04\u4e4b\u540e, \u7ed3\u6784\u4f53\u91cc\u586b\u4e86\u4ec0\u4e48, \u62a5\u6587\u91cc\u5c31\u6709\u4ec0\u4e48.<\/p>\n<p>\u89e3\u5305\u7684\u65b9\u5411\u5bf9\u79f0: \u6ce8\u518c MTI \u4e0e\u6a21\u677f\u7ed3\u6784\u4f53\u7684\u6620\u5c04, \u6536\u5230\u62a5\u6587\u5148\u8bfb MTI, \u627e\u5230\u5bf9\u5e94\u7684 <code>reflect.Type<\/code>, <code>reflect.New<\/code> \u4e00\u4e2a\u51fa\u6765, \u518d\u6309 bitmap \u9010\u4f4d <code>Load<\/code>:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">p <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-6 z-d-7\">Parser<\/span><span>)<\/span><span class=\"z-l-6 z-d-7\"> Register<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">mti<\/span><span class=\"z-l-8 z-d-10\"> string<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> tpl<\/span><span class=\"z-l-8 z-d-10\"> interface<\/span><span>{<\/span><span>}<\/span><span>)<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">err<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\tv<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> reflect<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">ValueOf<\/span><span>(<\/span><span>tpl<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\tp<\/span><span>.<\/span><span>messages<\/span><span>[<\/span><span>mti<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> reflect<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Indirect<\/span><span>(<\/span><span>v<\/span><span>)<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Type<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\treturn<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u6709\u4e00\u4e2a\u5fc5\u987b\u5904\u7406\u7684\u7ec6\u8282: <code>reflect.New<\/code> \u51fa\u6765\u7684\u7ed3\u6784\u4f53, \u91cc\u9762\u6240\u6709\u6307\u9488\u57df\u90fd\u662f nil, \u800c <code>Load<\/code> \u9700\u8981\u5f80\u91cc\u5199. \u6240\u4ee5\u8981\u5148\u628a\u6307\u9488\u57df\u6328\u4e2a <code>reflect.New<\/code> \u521d\u59cb\u5316\u4e00\u904d, \u89e3\u5b8c\u4e4b\u540e\u518d\u628a\u6ca1\u88ab bitmap \u70b9\u5230\u7684\u57df\u8fd8\u539f\u6210 nil \u2014\u2014 \u5426\u5219 \"\u8fd9\u6761\u62a5\u6587\u91cc\u6709\u6ca1\u6709 F39\" \u8fd9\u4e2a\u5224\u65ad\u5c31\u5931\u6548\u4e86.<\/p>\n<p>\u53cd\u5c04\u4ee3\u7801\u7684\u53e6\u4e00\u4e2a\u4ee3\u4ef7\u662f, \u5927\u91cf\u7684\u9519\u8bef\u6ca1\u6cd5\u5728\u7f16\u8bd1\u671f\u53d1\u73b0, tag \u5199\u9519, \u7c7b\u578b\u5199\u9519, \u90fd\u8981\u5230\u8fd0\u884c\u65f6\u624d panic. \u8fd9\u4e2a\u5e93\u7684\u505a\u6cd5\u662f\u5728\u6bcf\u4e2a\u5bf9\u5916\u7684\u5165\u53e3\u4e0a\u6302\u4e00\u4e2a recover, \u628a panic \u7ffb\u8bd1\u6210 error:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">m <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-6 z-d-7\">Message<\/span><span>)<\/span><span class=\"z-l-6 z-d-7\"> Bytes<\/span><span>(<\/span><span>)<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">ret<\/span><span> [<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> err<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tdefer<\/span><span class=\"z-l-8 z-d-10\"> func<\/span><span>(<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\tif<\/span><span> r<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span class=\"z-l-6 z-d-7\"> recover<\/span><span>(<\/span><span>)<\/span><span>;<\/span><span> r<\/span><span class=\"z-l-8 z-d-10\"> !=<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\terr<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> errors<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">New<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span class=\"z-l-2 z-d-6\">Critical error:<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span class=\"z-l-8 z-d-10\"> +<\/span><span> fmt<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Sprint<\/span><span>(<\/span><span>r<\/span><span>)<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\tret<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t}<\/span><\/span>\n<span class=\"giallo-l\"><span>\t}<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\t\/\/<\/span><span class=\"z-l-5 z-d-3\"> ...<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u8fd9\u662f\u4e2a\u52a1\u5b9e\u4f46\u4e0d\u4f18\u96c5\u7684\u9009\u62e9. \u4e00\u6761\u7578\u5f62\u62a5\u6587\u4e0d\u8be5\u628a\u6574\u4e2a\u7f51\u5173\u641e\u6302, \u4f46\u7528 recover \u515c\u5e95\u4e5f\u610f\u5473\u7740\u9519\u8bef\u4fe1\u606f\u5f88\u96be\u770b. \u66f4\u597d\u7684\u505a\u6cd5\u5e94\u8be5\u662f\u5728\u6ce8\u518c\u6a21\u677f\u7684\u65f6\u5019\u5c31\u628a\u7ed3\u6784\u4f53\u6821\u9a8c\u4e00\u904d, \u628a\u9519\u8bef\u63d0\u524d\u5230\u542f\u52a8\u671f.<\/p>\n<h2 id=\"liang-chong-bian-ma-bcd-he-jis8\"><a class=\"zola-anchor\" href=\"#liang-chong-bian-ma-bcd-he-jis8\" aria-label=\"Anchor link for: liang-chong-bian-ma-bcd-he-jis8\">\u4e24\u79cd\u7f16\u7801: BCD \u548c JIS8<\/a><\/h2>\n<h3 id=\"bcd\"><a class=\"zola-anchor\" href=\"#bcd\" aria-label=\"Anchor link for: bcd\">BCD<\/a><\/h3>\n<p>BCD \u662f\u7528 4 \u4e2a bit \u8868\u793a 1 \u4f4d\u5341\u8fdb\u5236\u6570, \u4e8e\u662f 1 \u4e2a\u5b57\u8282\u80fd\u653e 2 \u4f4d\u6570\u5b57, <code>\"1234\"<\/code> \u7f16\u7801\u540e\u5c31\u662f <code>\\x12\\x34<\/code>. \u5bf9\u4e8e\u91d1\u989d, \u65e5\u671f, \u957f\u5ea6\u5934\u8fd9\u4e9b\u7eaf\u6570\u5b57\u5b57\u6bb5, \u76f4\u63a5\u7701\u4e00\u534a.<\/p>\n<p>\u9ebb\u70e6\u5728\u5947\u6570\u957f\u5ea6. <code>\"119\"<\/code> \u6709 3 \u4f4d, \u5360 1.5 \u5b57\u8282, \u90a3\u591a\u51fa\u6765\u7684\u534a\u4e2a\u5b57\u8282\u8865\u5728\u54ea\u4e00\u8fb9? \u89c4\u683c\u4e66\u91cc\u4e24\u79cd\u90fd\u6709, \u6240\u4ee5\u8981\u4e24\u4e2a\u51fd\u6570:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/\/<\/span><span class=\"z-l-5 z-d-3\"> \u5de6\u5bf9\u9f50: &quot;119&quot; -&gt; &quot;1190&quot; -&gt; \\x11\\x90<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span class=\"z-l-6 z-d-7\"> lbcd<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">data<\/span><span> [<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><span>)<\/span><span> [<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tif<\/span><span class=\"z-l-6 z-d-7\"> len<\/span><span>(<\/span><span>data<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\">%<\/span><span class=\"z-l-1 z-d-4\">2<\/span><span class=\"z-l-8 z-d-10\"> !=<\/span><span class=\"z-l-1 z-d-4\"> 0<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\treturn<\/span><span class=\"z-l-6 z-d-7\"> bcd<\/span><span>(<\/span><span class=\"z-l-6 z-d-7\">append<\/span><span>(<\/span><span>data<\/span><span>,<\/span><span class=\"z-l-2 z-d-6\"> &quot;<\/span><span class=\"z-l-2 z-d-6\">0<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span class=\"z-l-8 z-d-10\">...<\/span><span>)<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\treturn<\/span><span class=\"z-l-6 z-d-7\"> bcd<\/span><span>(<\/span><span>data<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/\/<\/span><span class=\"z-l-5 z-d-3\"> \u53f3\u5bf9\u9f50: &quot;119&quot; -&gt; &quot;0119&quot; -&gt; \\x01\\x19<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span class=\"z-l-6 z-d-7\"> rbcd<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">data<\/span><span> [<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><span>)<\/span><span> [<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tif<\/span><span class=\"z-l-6 z-d-7\"> len<\/span><span>(<\/span><span>data<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\">%<\/span><span class=\"z-l-1 z-d-4\">2<\/span><span class=\"z-l-8 z-d-10\"> !=<\/span><span class=\"z-l-1 z-d-4\"> 0<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\treturn<\/span><span class=\"z-l-6 z-d-7\"> bcd<\/span><span>(<\/span><span class=\"z-l-6 z-d-7\">append<\/span><span>(<\/span><span>[<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span class=\"z-l-2 z-d-6\">0<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span>)<\/span><span>,<\/span><span> data<\/span><span class=\"z-l-8 z-d-10\">...<\/span><span>)<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\treturn<\/span><span class=\"z-l-6 z-d-7\"> bcd<\/span><span>(<\/span><span>data<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u89e3\u7801\u65f6\u540c\u6837\u8981\u77e5\u9053\u539f\u59cb\u7684\u5341\u8fdb\u5236\u957f\u5ea6\u624d\u80fd\u628a\u8865\u7684\u90a3\u4e2a 0 \u5207\u6389, \u6240\u4ee5 <code>Load<\/code> \u7684\u7b7e\u540d\u91cc\u4e00\u76f4\u5e26\u7740 <code>length<\/code>. \u8fd9\u4e5f\u662f\u4e3a\u4ec0\u4e48 tag \u91cc\u7684 <code>length<\/code> \u5bf9\u4e8e BCD \u57df\u6307\u7684\u662f<strong>\u5341\u8fdb\u5236\u4f4d\u6570<\/strong>\u800c\u4e0d\u662f\u5b57\u8282\u6570 \u2014\u2014 \u4e00\u4e2a\u5f88\u5bb9\u6613\u8e29\u7684\u5751, \u5c24\u5176\u662f <code>Binary<\/code> \u7c7b\u578b\u7684 <code>length<\/code> \u6307\u7684\u53c8\u662f\u5b57\u8282\u6570.<\/p>\n<h3 id=\"jis8\"><a class=\"zola-anchor\" href=\"#jis8\" aria-label=\"Anchor link for: jis8\">JIS8<\/a><\/h3>\n<p>\u8fd9\u662f\u8fd9\u4e2a\u9879\u76ee\u91cc\u6700\u65e5\u672c\u7684\u90e8\u5206.<\/p>\n<p>Go \u7684 <code>string<\/code> \u662f UTF-8, \u800c\u7ebf\u8def\u4e0a\u8dd1\u7684\u662f Shift-JIS. \u5177\u4f53\u4e00\u70b9, \u62a5\u6587\u91cc\u7684\u65e5\u6587\u7528\u7684\u662f JIS X 0201 \u7684\u534a\u89d2\u7247\u5047\u540d (\u5355\u5b57\u8282, 0xA1~0xDF \u533a\u95f4) \u52a0 JIS X 0208 \u7684\u53cc\u5b57\u8282\u6c49\u5b57\u5047\u540d. <code>\uff71\uff72\uff73\uff74\uff75<\/code> \u8fd9\u79cd\u534a\u89d2\u7247\u5047\u540d\u4eca\u5929\u53ea\u5728 ATM \u548c\u6536\u636e\u4e0a\u8fd8\u80fd\u89c1\u5230, \u4f46\u5728\u8fd9\u7c7b\u62a5\u6587\u91cc\u662f\u4e3b\u529b.<\/p>\n<p>\u8f6c\u6362\u672c\u8eab\u4e0d\u96be, <code>golang.org\/x\/text\/encoding\/japanese<\/code> \u76f4\u63a5\u7ed9:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span class=\"z-l-6 z-d-7\"> ToShiftJIS<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">str<\/span><span class=\"z-l-8 z-d-10\"> string<\/span><span>)<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">res<\/span><span> [<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> err<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\ttransformed<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> io<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">ReadAll<\/span><span>(<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\ttransform<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">NewReader<\/span><span>(<\/span><span>strings<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">NewReader<\/span><span>(<\/span><span>str<\/span><span>)<\/span><span>,<\/span><span> japanese<\/span><span>.<\/span><span>ShiftJIS<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">NewEncoder<\/span><span>(<\/span><span>)<\/span><span>)<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>\t)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\t\/\/<\/span><span class=\"z-l-5 z-d-3\"> ...<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u96be\u7684\u662f, <strong>\u8f6c\u6362\u5e94\u8be5\u53d1\u751f\u5728\u4ec0\u4e48\u65f6\u5019<\/strong>.<\/p>\n<p>\u4e00\u5f00\u59cb\u6211\u4eec\u628a\u57df\u76f4\u63a5\u5b58\u6210 <code>[]byte<\/code>, \u8ba9\u8c03\u7528\u65b9\u81ea\u5df1\u8f6c. \u7ed3\u679c\u662f\u4e1a\u52a1\u4ee3\u7801\u91cc\u5230\u5904\u662f <code>ToShiftJIS<\/code>, \u800c\u4e14\u4e00\u65e6\u6f0f\u4e86\u4e00\u5904, \u62a5\u6587\u80fd\u53d1\u51fa\u53bb, \u5bf9\u7aef\u4e5f\u80fd\u6536\u4e0b, \u53ea\u662f\u5546\u6237\u540d\u53d8\u6210\u4e71\u7801 \u2014\u2014 \u8fd9\u79cd bug \u8054\u8c03\u7684\u65f6\u5019\u975e\u5e38\u96be\u67e5.<\/p>\n<p>\u540e\u6765\u6539\u6210\u53d8\u957f\u57df\u540c\u65f6\u6301\u6709\u4e24\u79cd\u8868\u793a:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">type<\/span><span class=\"z-l-6 z-d-7\"> Llvar<\/span><span class=\"z-l-8 z-d-10\"> struct<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\tByteValue<\/span><span> [<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><\/span>\n<span class=\"giallo-l\"><span>\tValue<\/span><span class=\"z-l-8 z-d-10\">     string<\/span><span class=\"z-l-5 z-d-3\"> \/\/<\/span><span class=\"z-l-5 z-d-3\"> UTF-8 \u5b57\u7b26\u4e32, \u5982\u679c\u586b\u4e86\u6b64\u503c, \u4f1a\u4ee5\u6b64\u503c\u4e3a\u51c6\u505a\u8f6c\u6362<\/span><\/span>\n<span class=\"giallo-l\"><span>\tValid<\/span><span class=\"z-l-8 z-d-10\">     bool<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u4e1a\u52a1\u4ee3\u7801\u53ea\u78b0 <code>Value<\/code>, \u7f16\u7801\u7684\u4e8b\u60c5\u63a8\u8fdf\u5230 <code>Bytes()<\/code> \u91cc, \u6309 tag \u4e0a\u7684 <code>encode<\/code> \u51b3\u5b9a\u662f\u539f\u6837\u8f93\u51fa\u8fd8\u662f\u8f6c Shift-JIS; \u89e3\u5305\u65f6\u53cd\u8fc7\u6765, <code>Load<\/code> \u4e4b\u540e <code>Value<\/code> \u91cc\u62ff\u5230\u7684\u4e00\u5b9a\u662f\u53ef\u4ee5\u76f4\u63a5\u6253\u65e5\u5fd7, \u76f4\u63a5\u8fdb\u6570\u636e\u5e93\u7684 UTF-8. \u7f16\u7801\u4ece\u6b64\u53ea\u5728\u5e93\u7684\u8fb9\u754c\u4e0a\u53d1\u751f\u4e00\u6b21.<\/p>\n<p>\u987a\u5e26\u4e00\u4e2a\u5fc5\u987b\u8bb0\u4f4f\u7684\u70b9: <strong>\u53d8\u957f\u57df\u7684\u957f\u5ea6\u5934\u7b97\u7684\u662f\u7f16\u7801\u540e\u7684\u5b57\u8282\u6570, \u4e0d\u662f\u5b57\u7b26\u6570<\/strong>. <code>\"\u6771\u4eac\"<\/code> \u5728 UTF-8 \u91cc\u662f 6 \u5b57\u8282, \u5728 Shift-JIS \u91cc\u662f 4 \u5b57\u8282, \u957f\u5ea6\u5934\u8981\u5199 4. \u540c\u7406, \u5b9a\u957f\u57df\u8865\u7a7a\u683c\u8865\u5230\u7684\u4e5f\u662f\u5b57\u8282\u6570. \u6240\u4ee5 <code>len(l.ByteValue)<\/code> \u8fd9\u4e2a\u5199\u6cd5\u5fc5\u987b\u5728\u8f6c\u6362\u4e4b\u540e, \u987a\u5e8f\u53cd\u4e86\u5c31\u662f\u4e00\u6761\u957f\u5ea6\u5bf9\u4e0d\u4e0a\u7684\u5e9f\u62a5\u6587.<\/p>\n<p>\u6d4b\u8bd5\u6570\u636e\u4e5f\u662f\u4e2a\u95ee\u9898. \u4e3a\u4e86\u538b\u53d8\u957f\u57df\u7684\u8fb9\u754c, \u9700\u8981\u968f\u673a\u751f\u6210\u5408\u6cd5\u7684 Shift-JIS \u5b57\u7b26\u4e32, \u4e8e\u662f\u5199\u4e86\u4e2a\u5de5\u5177, \u628a ASCII \u7684\u7b26\u53f7\u533a\u95f4\u548c 0xA1~0xDF \u7684\u534a\u89d2\u7247\u5047\u540d\u533a\u95f4\u62fc\u8d77\u6765, \u89e3\u7801\u6210 rune \u518d\u968f\u673a\u53d6:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">for<\/span><span> i<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span class=\"z-l-8 z-d-10\"> uint8<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span class=\"z-l-1 z-d-4\">\\x21<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>)<\/span><span>;<\/span><span> i<\/span><span class=\"z-l-8 z-d-10\"> &lt;=<\/span><span class=\"z-l-8 z-d-10\"> uint8<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span class=\"z-l-1 z-d-4\">\\x2f<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>)<\/span><span>;<\/span><span> i<\/span><span class=\"z-l-8 z-d-10\">++<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\tb<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-6 z-d-7\"> append<\/span><span>(<\/span><span>b<\/span><span>,<\/span><span> i<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/\/<\/span><span class=\"z-l-5 z-d-3\"> ... \u5176\u4ed6 ASCII \u7b26\u53f7\u533a\u95f4<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">for<\/span><span> i<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span class=\"z-l-8 z-d-10\"> uint8<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span class=\"z-l-1 z-d-4\">\\xa1<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>)<\/span><span>;<\/span><span> i<\/span><span class=\"z-l-8 z-d-10\"> &lt;=<\/span><span class=\"z-l-8 z-d-10\"> uint8<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span class=\"z-l-1 z-d-4\">\\xdf<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>)<\/span><span>;<\/span><span> i<\/span><span class=\"z-l-8 z-d-10\">++<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\tb<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-6 z-d-7\"> append<\/span><span>(<\/span><span>b<\/span><span>,<\/span><span> i<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u4ee3\u7801\u91cc\u8fd8\u7559\u7740\u4e00\u884c <code>\/\/ TODO handle \\xa0, it's very strange<\/code> \u2014\u2014 0xA0 \u5728 Shift-JIS \u91cc\u662f\u672a\u5b9a\u4e49\u7684, \u4f46\u67d0\u4e9b\u5b9e\u73b0\u4f1a\u628a\u5b83\u5f53\u7a7a\u683c\u5904\u7406. \u89c4\u683c\u4e66\u91cc\u5bf9\u8fd9\u4e2a\u4f4d\u7f6e\u4e5f\u8bed\u7109\u4e0d\u8be6, \u8fd9\u4e2a TODO \u4f30\u8ba1\u4f1a\u7559\u5f88\u4e45.<\/p>\n<h2 id=\"tcp-lian-jie\"><a class=\"zola-anchor\" href=\"#tcp-lian-jie\" aria-label=\"Anchor link for: tcp-lian-jie\">TCP \u8fde\u63a5<\/a><\/h2>\n<p>\u5c01\u5305\u89e3\u5305\u505a\u5b8c, \u5269\u4e0b\u7684\u4e00\u534a\u5de5\u4f5c\u91cf\u5728\u8fde\u63a5\u4e0a. \u8fd9\u90e8\u5206\u57fa\u672c\u662f\u7167\u7740 <a rel=\"external\" href=\"https:\/\/github.com\/redis\/go-redis\">go-redis<\/a> \u6284\u7684, \u7136\u540e\u88ab\u4e1a\u52a1\u6539\u5f97\u9762\u76ee\u5168\u975e.<\/p>\n<p>\u6284\u7684\u90e8\u5206\u662f <code>Conn<\/code> \u8fd9\u5c42\u5c01\u88c5: \u62ff\u4e00\u4e2a <code>*net.TCPConn<\/code>, \u5957\u4e0a <code>bufio.Reader<\/code> \/ <code>bufio.Writer<\/code>, \u914d\u4e0a\u8bfb\u5199\u8d85\u65f6\u548c keepalive.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span class=\"z-l-6 z-d-7\"> Connect<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">address<\/span><span class=\"z-l-8 z-d-10\"> string<\/span><span>)<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">conn<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">net<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">TCPConn<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> err<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\traddr<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> net<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">ResolveTCPAddr<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span class=\"z-l-2 z-d-6\">tcp<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span>,<\/span><span> address<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\t\/\/<\/span><span class=\"z-l-5 z-d-3\"> ...<\/span><\/span>\n<span class=\"giallo-l\"><span>\tconn<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> net<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">DialTCP<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span class=\"z-l-2 z-d-6\">tcp<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><span>,<\/span><span> raddr<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\t\/\/<\/span><span class=\"z-l-5 z-d-3\"> ...<\/span><\/span>\n<span class=\"giallo-l\"><span>\terr<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> conn<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">SetKeepAlivePeriod<\/span><span>(<\/span><span class=\"z-l-1 z-d-4\">15<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span> time<\/span><span>.<\/span><span>Second<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\terr<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> conn<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">SetKeepAlive<\/span><span>(<\/span><span class=\"z-l-1 z-d-4\">true<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\treturn<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>TCP \u662f\u5b57\u8282\u6d41, \u6ca1\u6709\u62a5\u6587\u8fb9\u754c, \u6240\u4ee5\u8bfb\u7684\u65f6\u5019\u5fc5\u987b\u81ea\u5df1\u5212. \u597d\u5728\u8fd9\u7c7b\u534f\u8bae\u90fd\u6709\u5b9a\u957f\u5305\u5934, \u5305\u5934\u91cc\u6709\u5168\u957f:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/\/<\/span><span class=\"z-l-5 z-d-3\"> \u5148\u8bfb\u5b9a\u957f\u5305\u5934<\/span><\/span>\n<span class=\"giallo-l\"><span>headerBytes<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span class=\"z-l-6 z-d-7\"> make<\/span><span>(<\/span><span>[<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><span>,<\/span><span> models<\/span><span>.<\/span><span>HeaderByteLength<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>_<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> io<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">ReadFull<\/span><span>(<\/span><span>conn<\/span><span>.<\/span><span>br<\/span><span>,<\/span><span> headerBytes<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/\/<\/span><span class=\"z-l-5 z-d-3\"> \u4ece\u5305\u5934\u91cc\u53d6\u51fa\u5168\u957f, \u518d\u8bfb\u5269\u4e0b\u7684<\/span><\/span>\n<span class=\"giallo-l\"><span>totalLength<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> message<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">GetTotalLengthFromHeader<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>bodyBytes<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span class=\"z-l-6 z-d-7\"> make<\/span><span>(<\/span><span>[<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><span>,<\/span><span> totalLength<\/span><span class=\"z-l-8 z-d-10\">-<\/span><span>models<\/span><span>.<\/span><span>HeaderByteLength<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>_<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> io<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">ReadFull<\/span><span>(<\/span><span>conn<\/span><span>.<\/span><span>br<\/span><span>,<\/span><span> bodyBytes<\/span><span>)<\/span><\/span><\/code><\/pre>\n<p><code>io.ReadFull<\/code> \u5728\u8fd9\u91cc\u662f\u5173\u952e. \u76f4\u63a5 <code>Read<\/code> \u662f\u4e0d\u4fdd\u8bc1\u8bfb\u6ee1\u7684, \u5927\u62a5\u6587\u5206\u7247\u5230\u8fbe\u7684\u65f6\u5019, \u534a\u5305\u5c31\u662f\u8fd9\u4e48\u6765\u7684.<\/p>\n<p>\u6539\u5f97\u9762\u76ee\u5168\u975e\u7684\u90e8\u5206, \u662f<strong>\u8fd9\u4e2a\u534f\u8bae\u662f\u5168\u53cc\u5de5\u7684<\/strong>.<\/p>\n<p>Redis \u7684\u8fde\u63a5\u6a21\u578b\u662f: \u4ece\u6c60\u91cc\u53d6\u4e00\u6761\u8fde\u63a5, \u5199\u8bf7\u6c42, \u963b\u585e\u8bfb\u54cd\u5e94, \u8fd8\u56de\u6c60\u91cc. \u4e00\u6761\u8fde\u63a5\u540c\u4e00\u65f6\u523b\u53ea\u670d\u52a1\u4e00\u4e2a\u8bf7\u6c42, \u8bf7\u6c42\u548c\u54cd\u5e94\u4e25\u683c\u914d\u5bf9.<\/p>\n<p>\u800c\u5361\u7f51\u8fd9\u8fb9\u4e0d\u662f. \u5bf9\u7aef\u4f1a\u4e3b\u52a8\u63a8\u9001\u8fc7\u6765\u901a\u77e5\u7c7b\u7535\u6587, \u4e5f\u4f1a\u5728\u4f60\u53d1\u51fa\u53bb\u7684\u8bf7\u6c42\u8fd8\u6ca1\u56de\u6765\u7684\u65f6\u5019\u5148\u53d1\u522b\u7684\u4e1c\u897f\u8fc7\u6765. \u66f4\u9ebb\u70e6\u7684\u662f, \u53cc\u65b9\u662f\u5bf9\u7b49\u7684: \u6211\u65b9\u65e2\u8981\u4e3b\u52a8\u8fde\u8fc7\u53bb, \u4e5f\u8981\u76d1\u542c\u7aef\u53e3\u7b49\u5bf9\u65b9\u8fde\u8fc7\u6765, \u4e24\u4e2a\u65b9\u5411\u4e0a\u90fd\u80fd\u6536\u53d1\u4e1a\u52a1\u7535\u6587.<\/p>\n<p>\u6240\u4ee5\u8fde\u63a5\u5efa\u7acb\u4e4b\u540e, \u7acb\u523b\u8d77\u4e00\u4e2a goroutine \u4e00\u76f4\u8bfb, \u8bfb\u5230\u7684\u7535\u6587\u5168\u90e8\u6295\u8fdb\u4e00\u4e2a channel:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">c <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-6 z-d-7\">Conn<\/span><span>)<\/span><span class=\"z-l-6 z-d-7\"> ReadChan<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">ch<\/span><span class=\"z-l-8 z-d-10\"> chan<\/span><span class=\"z-l-8 z-d-10\">&lt;-<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">models<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Message<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tgo<\/span><span class=\"z-l-8 z-d-10\"> func<\/span><span>(<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\tfor<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\tmessage<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span class=\"z-l-6 z-d-7\"> connReadMessage<\/span><span>(<\/span><span>c<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\t\tif<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> !=<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\t\tlogz<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Warnf<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span class=\"z-l-2 z-d-6\">read error, <\/span><span class=\"z-l-1 z-d-4\">%v<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span>,<\/span><span> err<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\t\tc<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Close<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\t\t\treturn<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\t}<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\tch<\/span><span class=\"z-l-8 z-d-10\"> &lt;-<\/span><span> message<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t}<\/span><\/span>\n<span class=\"giallo-l\"><span>\t}<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u4e0a\u5c42\u62ff\u5230\u7684\u5c31\u662f\u4e00\u4e2a\"\u6240\u6709\u8fde\u63a5\u4e0a\u6536\u5230\u7684\u6240\u6709\u7535\u6587\"\u7684\u6d41, \u4e3b\u52a8\u8fde\u51fa\u53bb\u7684\u548c\u88ab\u52a8\u63a5\u8fdb\u6765\u7684\u8fde\u63a5\u5171\u7528\u540c\u4e00\u4e2a\u51fa\u53e3:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">c <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-6 z-d-7\">Center<\/span><span>)<\/span><span class=\"z-l-6 z-d-7\"> ReceiveMessagesInChannel<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">ch<\/span><span class=\"z-l-8 z-d-10\"> chan<\/span><span class=\"z-l-8 z-d-10\">&lt;-<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">models<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Message<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\tserverReceiveChan<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> c<\/span><span>.<\/span><span>server<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">ReceiveChannel<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\tclientReceiveChan<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> c<\/span><span>.<\/span><span>client<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">ReceiveChannel<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tgo<\/span><span class=\"z-l-8 z-d-10\"> func<\/span><span>(<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\tfor<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\t\tselect<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\t\tcase<\/span><span> message<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-8 z-d-10\"> &lt;-<\/span><span>serverReceiveChan<\/span><span>:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\t\t\tgo<\/span><span class=\"z-l-6 z-d-7\"> loadMessage<\/span><span>(<\/span><span>ch<\/span><span>,<\/span><span> message<\/span><span>,<\/span><span> c<\/span><span>.<\/span><span>state<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\t\tcase<\/span><span> message<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-8 z-d-10\"> &lt;-<\/span><span>clientReceiveChan<\/span><span>:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\t\t\tgo<\/span><span class=\"z-l-6 z-d-7\"> loadMessage<\/span><span>(<\/span><span>ch<\/span><span>,<\/span><span> message<\/span><span>,<\/span><span> c<\/span><span>.<\/span><span>state<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\t}<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t}<\/span><\/span>\n<span class=\"giallo-l\"><span>\t}<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u8bf7\u6c42\u548c\u54cd\u5e94\u7684\u914d\u5bf9, \u5c31\u4ea4\u7ed9\u4e0a\u5c42\u7528\u62a5\u6587\u91cc\u7684\u6d41\u6c34\u53f7\u53bb\u505a\u4e86 \u2014\u2014 \u7cfb\u7edf\u8ddf\u8e2a\u53f7\u52a0\u4ea4\u6613\u65f6\u95f4\u52a0\u673a\u6784\u53f7\u7ec4\u6210\u7684\u90a3\u4e2a\u552f\u4e00\u6807\u8bc6. \u8fd9\u4ef6\u4e8b\u672c\u6765\u5c31\u8be5\u5728\u4e1a\u52a1\u5c42\u505a, \u56e0\u4e3a\u8d85\u65f6\u91cd\u53d1, \u51b2\u6b63, \u5bf9\u8d26\u90fd\u8981\u7528\u5230\u540c\u4e00\u4e2a\u6807\u8bc6.<\/p>\n<h2 id=\"yi-dian-ye-bu-yun-yuan-sheng\"><a class=\"zola-anchor\" href=\"#yi-dian-ye-bu-yun-yuan-sheng\" aria-label=\"Anchor link for: yi-dian-ye-bu-yun-yuan-sheng\">\u4e00\u70b9\u4e5f\u4e0d\u4e91\u539f\u751f<\/a><\/h2>\n<p>\u5728\u8bb2\u8fde\u63a5\u6c60\u4e4b\u524d, \u5f97\u5148\u8bf4\u6e05\u695a\u8fd9\u5f20\u7f51\u957f\u4ec0\u4e48\u6837, \u5426\u5219\u6c60\u5b50\u7684\u5f62\u72b6\u4f1a\u663e\u5f97\u83ab\u540d\u5176\u5999.<\/p>\n<p>\u6ca1\u6709\u57df\u540d, \u6ca1\u6709\u670d\u52a1\u53d1\u73b0, \u6ca1\u6709\u8d1f\u8f7d\u5747\u8861\u5668. \u53cc\u65b9\u4ea4\u6362\u7684\u662f\u4e00\u4efd IP \u5730\u5740\u6e05\u5355, \u5199\u6b7b\u5728\u914d\u7f6e\u91cc:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">type<\/span><span class=\"z-l-6 z-d-7\"> Config<\/span><span class=\"z-l-8 z-d-10\"> struct<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\tAddresses<\/span><span> [<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">string<\/span><span class=\"z-l-2 z-d-6\"> `<\/span><span class=\"z-l-2 z-d-6\">json:&quot;addresses&quot;<\/span><span class=\"z-l-2 z-d-6\">`<\/span><\/span>\n<span class=\"giallo-l\"><span>\tSourceID<\/span><span class=\"z-l-8 z-d-10\">  string<\/span><span class=\"z-l-2 z-d-6\">   `<\/span><span class=\"z-l-2 z-d-6\">json:&quot;source_id&quot;<\/span><span class=\"z-l-2 z-d-6\">`<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u6211\u65b9\u6709 m \u4e2a\u8282\u70b9, \u5bf9\u65b9\u7ed9 n \u4e2a\u5730\u5740, \u4e8e\u662f <strong>m \u00d7 n \u6761\u8fde\u63a5, \u6bcf\u4e00\u6761\u5404\u81ea\u5efa\u7acb, \u5404\u81ea\u4fdd\u6d3b, \u5404\u81ea\u91cd\u8fde<\/strong>. \u53cd\u65b9\u5411\u8fd8\u6709\u4e00\u5f20: \u5bf9\u65b9\u4e5f\u4f1a\u4e3b\u52a8\u8fde\u8fc7\u6765. \u8fd9\u4e9b\u8fde\u63a5\u4e0d\u662f\u4e00\u5806\u7b49\u4ef7\u7684, \u53ef\u66ff\u6362\u7684\u6c60\u5316\u8d44\u6e90, \u800c\u662f\u4e00\u6761\u6761\u6709\u540d\u6709\u59d3\u7684\u7ebf\u8def \u2014\u2014 \u65ad\u7684\u662f\u54ea\u4e00\u6761, \u5c31\u5f97\u628a\u54ea\u4e00\u6761\u63a5\u56de\u6765.<\/p>\n<p>\u6240\u4ee5\u8fd9\u5957\u4e1c\u897f\u548c\u73b0\u5728\u4e60\u4ee5\u4e3a\u5e38\u7684\u90a3\u4e00\u5957\u57fa\u672c\u662f\u53cd\u7740\u6765\u7684:<\/p>\n<ul>\n<li><strong>\u4e0d\u80fd\u968f\u4fbf\u6269\u5bb9.<\/strong> \u5b9e\u4f8b\u6570\u662f\u548c\u5bf9\u65b9\u7ea6\u5b9a\u597d\u7684. \u52a0\u4e00\u53f0\u673a\u5668\u610f\u5473\u7740\u53cc\u65b9\u90fd\u8981\u6539\u767d\u540d\u5355, \u8d70\u7533\u8bf7\u6d41\u7a0b, \u5468\u671f\u4ee5\u5468\u8ba1. \u5f39\u6027\u4f38\u7f29\u5728\u8fd9\u91cc\u4e0d\u662f\u4e00\u4e2a\u9009\u9879.<\/li>\n<li><strong>IP \u5fc5\u987b\u662f\u56fa\u5b9a\u7684.<\/strong> \u8fd9\u57fa\u672c\u5835\u6b7b\u4e86\u76f4\u63a5\u6254\u8fdb k8s \u8ba9 Pod \u98d8\u6765\u98d8\u53bb\u7684\u53ef\u80fd, \u8981\u4e48\u9489\u5728\u56fa\u5b9a\u8282\u70b9\u4e0a, \u8981\u4e48\u60f3\u529e\u6cd5\u4fdd\u8bc1\u51fa\u53e3 IP \u7a33\u5b9a.<\/li>\n<li><strong>\u53d1\u5e03\u662f\u6709\u4ee3\u4ef7\u7684.<\/strong> \u91cd\u542f\u4e00\u4e2a\u5b9e\u4f8b\u610f\u5473\u7740 n \u6761\u8fde\u63a5\u65ad\u5f00\u91cd\u8fde, \u91cd\u8fde\u5b8c\u8fd8\u8981\u91cd\u65b0\u5f00\u5c40. \u6eda\u52a8\u53d1\u5e03\u8981\u63a7\u5236\u8282\u594f, \u4e0d\u80fd\u4e00\u6b21\u5168\u90e8\u91cd\u542f.<\/li>\n<li><strong>\u5065\u5eb7\u68c0\u67e5\u6ca1\u6cd5\u4ea4\u7ed9\u522b\u4eba.<\/strong> \u6ca1\u6709 LB \u5e2e\u4f60\u628a\u6545\u969c\u8282\u70b9\u6458\u6389, \u6bcf\u6761\u8fde\u63a5\u662f\u6b7b\u662f\u6d3b, \u53ea\u6709\u8fdb\u7a0b\u81ea\u5df1\u77e5\u9053.<\/li>\n<\/ul>\n<p>\u597d\u5904\u662f\u94fe\u8def\u4e0a\u6ca1\u6709\u4e2d\u95f4\u73af\u8282, \u51fa\u4e86\u95ee\u9898\u6392\u67e5\u8def\u5f84\u5f88\u77ed. \u4ee3\u4ef7\u662f\u5efa\u7acb, \u4fdd\u6d3b, \u91cd\u8fde, \u9009\u8def, \u6458\u9664\u8fd9\u4e9b\u6d3b\u5168\u90e8\u843d\u5728\u5e93\u91cc, \u6ca1\u6709\u4efb\u4f55\u57fa\u7840\u8bbe\u65bd\u80fd\u66ff\u4f60\u5206\u62c5 \u2014\u2014 \u4e0b\u9762\u8fd9\u4e2a\u8fde\u63a5\u6c60, \u672c\u8d28\u4e0a\u5c31\u662f\u4e3a\u4e86\u628a\u8fd9\u5806\u4e8b\u6536\u5728\u4e00\u4e2a\u5730\u65b9.<\/p>\n<h2 id=\"lian-jie-chi\"><a class=\"zola-anchor\" href=\"#lian-jie-chi\" aria-label=\"Anchor link for: lian-jie-chi\">\u8fde\u63a5\u6c60<\/a><\/h2>\n<p>\u65e2\u7136\u8bfb\u5df2\u7ecf\u4e0d\u9700\u8981\u5360\u7528\u8fde\u63a5\u4e86, \u90a3\u8fde\u63a5\u6c60\u5230\u5e95\u8fd8\u6c60\u4ec0\u4e48?<\/p>\n<p>\u7b54\u6848\u662f: <strong>\u53ea\u670d\u52a1\u4e8e\u53d1\u9001<\/strong>. \u6c60\u7684\u804c\u8d23\u4ece\"\u501f\u51fa-\u72ec\u5360-\u5f52\u8fd8\"\u9000\u5316\u6210\u4e86\"\u5728\u4e00\u7ec4\u53ef\u7528\u8fde\u63a5\u91cc\u6311\u4e00\u6761\u6765\u5199\", \u4e5f\u5c31\u662f\u9009\u8def\u548c\u8d1f\u8f7d\u5747\u8861.<\/p>\n<p>\u5e95\u5c42\u7684\u53cc\u5411\u94fe\u8868\u76f4\u63a5\u6284\u4e86 <a rel=\"external\" href=\"https:\/\/github.com\/gomodule\/redigo\">redigo<\/a>, \u4ee3\u7801\u91cc\u8001\u8001\u5b9e\u5b9e\u7559\u7740\u51fa\u5904:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/\/<\/span><span class=\"z-l-5 z-d-3\"> idleList is a double linked list to maintain connections in connPool<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/\/<\/span><span class=\"z-l-5 z-d-3\"> copy from github.com\/gomodule\/redigo<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">type<\/span><span class=\"z-l-6 z-d-7\"> idleList<\/span><span class=\"z-l-8 z-d-10\"> struct<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\tcount<\/span><span class=\"z-l-8 z-d-10\">       int<\/span><\/span>\n<span class=\"giallo-l\"><span>\tfront<\/span><span>,<\/span><span> back<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">poolConn<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u53d6\u8fde\u63a5\u7684\u65f6\u5019\u4ece\u94fe\u8868\u5c3e\u90e8\u5f39\u51fa, \u7528\u5b8c\u4ece\u5934\u90e8\u585e\u56de\u53bb, \u5929\u7136\u5c31\u662f\u4e00\u4e2a\u8f6e\u8be2:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">p <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-6 z-d-7\">ConnPool<\/span><span>)<\/span><span class=\"z-l-6 z-d-7\"> GetConnAndPutBack<\/span><span>(<\/span><span>)<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">conn<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">Conn<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> err<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\tp<\/span><span>.<\/span><span>mu<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Lock<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tdefer<\/span><span> p<\/span><span>.<\/span><span>mu<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Unlock<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\tconn<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> p<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">getConn<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tif<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> !=<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\treturn<\/span><\/span>\n<span class=\"giallo-l\"><span>\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tif<\/span><span class=\"z-l-8 z-d-10\"> !<\/span><span>conn<\/span><span>.<\/span><span>closed<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\t\t\/\/<\/span><span class=\"z-l-5 z-d-3\"> \u5c06\u53d6\u5230\u7684\u8fde\u63a5\u8fd8\u56de\u5230\u94fe\u8868\u7684\u5934<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tp<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">putConn<\/span><span>(<\/span><span>conn<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\treturn<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u53d1\u9001\u7684\u5165\u53e3\u5e26 context \u8d85\u65f6, \u62ff\u4e0d\u5230\u53ef\u7528\u8fde\u63a5\u5c31\u7b49, \u7b49\u5230 deadline \u518d\u62a5\u9519. \u5df2\u7ecf\u5173\u95ed\u7684\u8fde\u63a5\u76f4\u63a5\u4e22\u5f03, \u4e0d\u518d\u653e\u56de:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">p <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-6 z-d-7\">ConnPool<\/span><span>)<\/span><span class=\"z-l-6 z-d-7\"> GetActiveConnWithCtx<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">ctx<\/span><span class=\"z-l-6 z-d-7\"> context<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Context<\/span><span>)<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">conn<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">Conn<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> err<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tfor<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\tselect<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\tcase<\/span><span class=\"z-l-8 z-d-10\"> &lt;-<\/span><span>ctx<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Done<\/span><span>(<\/span><span>)<\/span><span>:<\/span><span class=\"z-l-5 z-d-3\"> \/\/<\/span><span class=\"z-l-5 z-d-3\"> \u5df2\u7ecf\u8d85\u65f6, \u76f4\u63a5\u8fd4\u56de<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\t\treturn<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><span>,<\/span><span> ctx<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Err<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\tdefault<\/span><span>:<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\tp<\/span><span>.<\/span><span>mu<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Lock<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\tconn<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> p<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">getConn<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\tp<\/span><span>.<\/span><span>mu<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Unlock<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\t\tif<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> !=<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\t\t\tif<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> ==<\/span><span> ErrIdleConnNotFound<\/span><span> {<\/span><span class=\"z-l-5 z-d-3\"> \/\/<\/span><span class=\"z-l-5 z-d-3\"> \u6ca1\u6709\u7a7a\u95f2\u8fde\u63a5, \u7b49\u4e00\u4e0b\u518d\u53d6<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\t\t\ttime<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Sleep<\/span><span>(<\/span><span>time<\/span><span>.<\/span><span>Millisecond<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\t\t\t\tcontinue<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\t\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\t\t\treturn<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\t\tif<\/span><span> conn<\/span><span>.<\/span><span>closed<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\t\t\tcontinue<\/span><span class=\"z-l-5 z-d-3\"> \/\/<\/span><span class=\"z-l-5 z-d-3\"> \u5173\u95ed\u7684\u8fde\u63a5\u65e0\u9700\u52a0\u56de\u8fde\u63a5\u6c60<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\t\treturn<\/span><span class=\"z-l-5 z-d-3\"> \/\/<\/span><span class=\"z-l-5 z-d-3\"> \u8fd4\u56de\u7684 conn \u4e00\u5b9a\u662f\u672a\u5173\u95ed\u4e14\u53ef\u7528\u7684<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t}<\/span><\/span>\n<span class=\"giallo-l\"><span>\t}<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre><h3 id=\"zhong-lian\"><a class=\"zola-anchor\" href=\"#zhong-lian\" aria-label=\"Anchor link for: zhong-lian\">\u91cd\u8fde<\/a><\/h3>\n<p>\u4e13\u7ebf\u4e5f\u4f1a\u65ad, \u5bf9\u7aef\u4e5f\u4f1a\u91cd\u542f, \u800c\u8fd9\u7c7b\u7cfb\u7edf\u7684\u8981\u6c42\u662f\u65ad\u4e86\u8981\u81ea\u5df1\u63a5\u56de\u6765, \u4e0d\u80fd\u7b49\u4eba\u6765\u91cd\u542f\u8fdb\u7a0b.<\/p>\n<p>\u505a\u6cd5\u662f\u5728\u8fde\u63a5\u5165\u6c60\u7684\u65f6\u5019, \u7ed9\u5b83\u6302\u4e00\u4e2a\"\u5b88\u7075\"\u7684 goroutine: \u963b\u585e\u5728\u8fd9\u6761\u8fde\u63a5\u7684 <code>closeChan<\/code> \u4e0a, \u4e00\u65e6\u8fde\u63a5\u5173\u95ed, \u5148\u628a\u6d3b\u8dc3\u8ba1\u6570\u51cf\u6389, \u7136\u540e\u6309<strong>\u539f\u6765\u90a3\u4e2a<\/strong>\u8fdc\u7aef\u5730\u5740\u91cd\u65b0\u62e8\u53f7, \u62e8\u901a\u4e86\u518d\u5165\u6c60. \u6ce8\u610f\u662f\u539f\u6765\u90a3\u4e2a, \u800c\u4e0d\u662f\u4ece\u5730\u5740\u6e05\u5355\u91cc\u91cd\u65b0\u6311\u4e00\u4e2a \u2014\u2014 \u4e0a\u9762\u8bf4\u8fc7, m \u00d7 n \u91cc\u7684\u6bcf\u4e00\u6761\u90fd\u662f\u6709\u540d\u6709\u59d3\u7684, \u5c11\u4e86\u54ea\u6761\u5c31\u5f97\u8865\u54ea\u6761.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">p <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-6 z-d-7\">ConnPool<\/span><span>)<\/span><span class=\"z-l-6 z-d-7\"> AddConn<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">conn<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">Conn<\/span><span>)<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">err<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\tp<\/span><span>.<\/span><span>mu<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Lock<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tdefer<\/span><span> p<\/span><span>.<\/span><span>mu<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Unlock<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\tp<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">putConn<\/span><span>(<\/span><span>conn<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\tp<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">increaseActive<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tgo<\/span><span class=\"z-l-8 z-d-10\"> func<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">conn<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">Conn<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\t&lt;-<\/span><span>conn<\/span><span>.<\/span><span>closeChan<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tp<\/span><span>.<\/span><span>mu<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Lock<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tp<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">decreaseActive<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tp<\/span><span>.<\/span><span>mu<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Unlock<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\tif<\/span><span class=\"z-l-8 z-d-10\"> !<\/span><span>conn<\/span><span>.<\/span><span>reconnect<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\t\treturn<\/span><span class=\"z-l-5 z-d-3\"> \/\/<\/span><span class=\"z-l-5 z-d-3\"> \u88ab\u52a8\u63a5\u5165\u7684\u8fde\u63a5\u4e0d\u8d1f\u8d23\u91cd\u8fde<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\tif<\/span><span> conn<\/span><span>.<\/span><span>parentCloseChan<\/span><span class=\"z-l-8 z-d-10\"> ==<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\t\treturn<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\t\t\/\/<\/span><span class=\"z-l-5 z-d-3\"> ... \u6309 remote addr \u91cd\u8fde, \u5931\u8d25\u9000\u907f\u540e\u91cd\u8bd5<\/span><\/span>\n<span class=\"giallo-l\"><span>\t}<\/span><span>(<\/span><span>conn<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\treturn<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u8fd9\u91cc\u6709\u4e24\u4e2a flag \u503c\u5f97\u8bf4\u4e00\u4e0b.<\/p>\n<p><code>reconnect<\/code> \u533a\u5206\u8fd9\u6761\u8fde\u63a5\u662f\u6211\u65b9\u62e8\u51fa\u53bb\u7684\u8fd8\u662f\u5bf9\u65b9\u8fde\u8fdb\u6765\u7684. \u53ea\u6709\u524d\u8005\u8be5\u91cd\u8fde \u2014\u2014 \u5bf9\u65b9\u8fde\u8fdb\u6765\u7684\u8fde\u63a5\u65ad\u4e86, \u8be5\u7531\u5bf9\u65b9\u6765\u91cd\u8fde, \u6211\u65b9\u53bb\u8fde\u5bf9\u65b9\u7684\u76d1\u542c\u7aef\u53e3\u662f\u5b8c\u5168\u4e0d\u540c\u7684\u4e00\u4ef6\u4e8b.<\/p>\n<p><code>parentCloseChan<\/code> \u533a\u5206\"\u7f51\u7edc\u65ad\u4e86\"\u548c\"\u5e94\u7528\u8981\u5173\u4e86\". \u6ca1\u6709\u8fd9\u4e2a\u4e1c\u897f\u7684\u8bdd, \u4f18\u96c5\u5173\u505c\u4f1a\u53d8\u6210: \u4f60\u5173\u6389\u6240\u6709\u8fde\u63a5, \u7136\u540e\u6bcf\u6761\u8fde\u63a5\u7684\u5b88\u7075 goroutine \u7acb\u523b\u5f00\u59cb\u91cd\u8fde, \u5173\u4e0d\u6389. \u8fd9\u4e2a channel \u7531\u4e0a\u5c42\u6301\u6709, \u5173\u505c\u65f6\u5148\u5173\u5b83, \u91cd\u8fde\u903b\u8f91\u4e00\u770b\u5b83\u5df2\u7ecf\u5173\u95ed\u5c31\u76f4\u63a5\u9000\u51fa.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span class=\"z-l-6 z-d-7\"> IsClosed<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">ch<\/span><span class=\"z-l-8 z-d-10\"> &lt;-<\/span><span class=\"z-l-8 z-d-10\">chan<\/span><span class=\"z-l-8 z-d-10\"> interface<\/span><span>{<\/span><span>}<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\"> bool<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tselect<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tcase<\/span><span class=\"z-l-8 z-d-10\"> &lt;-<\/span><span>ch<\/span><span>:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\treturn<\/span><span class=\"z-l-1 z-d-4\"> true<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tdefault<\/span><span>:<\/span><\/span>\n<span class=\"giallo-l\"><span>\t}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\treturn<\/span><span class=\"z-l-1 z-d-4\"> false<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u8fd9\u4e2a\u6a21\u5f0f\u5728 Go \u91cc\u5f88\u5e38\u7528: \u7528\u4e00\u4e2a\u53ea\u5173\u4e0d\u5199\u7684 channel \u505a\u5e7f\u64ad\u5f0f\u7684\u53d6\u6d88\u4fe1\u53f7. \u73b0\u5728\u5199\u7684\u8bdd\u5e94\u8be5\u76f4\u63a5\u7528 <code>context.Context<\/code>, \u5f53\u65f6\u662f\u56fe\u7701\u4e8b.<\/p>\n<h2 id=\"lian-jie-bu-deng-yu-hui-hua\"><a class=\"zola-anchor\" href=\"#lian-jie-bu-deng-yu-hui-hua\" aria-label=\"Anchor link for: lian-jie-bu-deng-yu-hui-hua\">\u8fde\u63a5\u4e0d\u7b49\u4e8e\u4f1a\u8bdd<\/a><\/h2>\n<p>\u89c4\u683c\u4e66\u91cc, \u4e24\u4e2a\u4e2d\u5fc3\u4e4b\u95f4\u8981\u5148\u53d1\u4e00\u6761\u5f00\u5c40\u7535\u6587, \u6536\u5230\u5f00\u5c40\u54cd\u5e94\u4e4b\u540e\u624d\u5141\u8bb8\u53d1\u4e1a\u52a1\u7535\u6587, \u6536\u5de5\u7684\u65f6\u5019\u518d\u53d1\u4e00\u6761\u95ed\u5c40.<\/p>\n<p>\u5e94\u7528\u5c42\u518d\u63e1\u4e00\u6b21\u624b\u8fd9\u4ef6\u4e8b\u672c\u8eab\u4e00\u70b9\u4e5f\u4e0d\u7a00\u5947. Redis \u7684 <code>AUTH<\/code>, <code>SELECT<\/code>, <code>HELLO<\/code> \u5c31\u662f, MySQL, AMQP, SMTP \u4e5f\u90fd\u6709\u81ea\u5df1\u7684\u4e00\u5957. TCP \u53ea\u8d1f\u8d23\u628a\u5b57\u8282\u6309\u5e8f\u9001\u5230, \u81f3\u4e8e\"\u4f60\u662f\u8c01, \u6211\u8ba4\u4e0d\u8ba4\u4f60, \u63a5\u4e0b\u6765\u6309\u4ec0\u4e48\u89c4\u77e9\u6765\", \u6c38\u8fdc\u5f97\u5728\u5e94\u7528\u5c42\u8c08.<\/p>\n<p>\u771f\u6b63\u503c\u5f97\u8bf4\u7684\u662f<strong>\u7c92\u5ea6<\/strong>.<\/p>\n<p>Redis \u90a3\u5957\u662f<strong>\u8fde\u63a5\u7ea7<\/strong>\u7684: AUTH \u8ba4\u7684\u662f\u8fd9\u6761\u8fde\u63a5, SELECT \u9009\u7684\u662f\u8fd9\u6761\u8fde\u63a5\u7684 db, \u72b6\u6001\u548c socket \u540c\u751f\u5171\u6b7b. \u8fde\u63a5\u65ad\u4e86, \u72b6\u6001\u8ddf\u7740\u6ca1; go-redis \u91cd\u8fde\u4e4b\u540e\u5728 <code>initConn<\/code> \u91cc\u628a HELLO \/ AUTH \/ SELECT \u91cd\u8dd1\u4e00\u904d, \u4e0a\u5c42\u5b8c\u5168\u65e0\u611f. \u4f1a\u8bdd\u548c\u8fde\u63a5\u662f 1:1 \u7684, \u6240\u4ee5\"\u4f1a\u8bdd\"\u8fd9\u4e2a\u8bcd\u5728\u90a3\u8fb9\u6839\u672c\u4e0d\u9700\u8981\u5355\u72ec\u5b58\u5728.<\/p>\n<p>\u5f00\u5c40\u4e0d\u662f. \u5b83\u662f<strong>\u4e24\u4e2a\u4e2d\u5fc3\u4e4b\u95f4<\/strong>\u7684\u72b6\u6001, \u4e00\u6b21\u5f00\u5c40\u8986\u76d6 m \u00d7 n \u6240\u6709\u8fde\u63a5:<\/p>\n<ul>\n<li>\u5355\u6761\u8fde\u63a5\u65ad\u4e86\u91cd\u8fde, \u4e0d\u9700\u8981\u91cd\u65b0\u5f00\u5c40.<\/li>\n<li>\u53cd\u8fc7\u6765, \u6240\u6709\u8fde\u63a5\u90fd\u597d\u597d\u7684, \u4f46\u4f1a\u8bdd\u88ab\u95ed\u5c40\u4e86, \u4e00\u6837\u4e0d\u80fd\u53d1\u4e1a\u52a1\u7535\u6587.<\/li>\n<\/ul>\n<p>\u6240\u4ee5\u5728\u7ebf\u72b6\u6001\u662f\u5b58\u5728 <code>CommonState<\/code> \u91cc\u7684, \u4e0d\u662f\u5b58\u5728 <code>Conn<\/code> \u4e0a:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">const<\/span><span> (<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-1 z-d-4\">\tOnlineStatusClosed<\/span><span class=\"z-l-6 z-d-7\"> OnlineStatus<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-1 z-d-4\"> iota<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-1 z-d-4\">\tOnlineStatusOpening<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-1 z-d-4\">\tOnlineStatusOpened<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-1 z-d-4\">\tOnlineStatusClosing<\/span><\/span>\n<span class=\"giallo-l\"><span>)<\/span><\/span><\/code><\/pre>\n<p>\u53d1\u4e1a\u52a1\u7535\u6587\u4e4b\u524d\u8be5\u95ee\u7684\u662f\"\u4f1a\u8bdd\u5f00\u7740\u5417\", \u800c\u4e0d\u662f\"\u8fde\u63a5\u8fd8\u5728\u5417\". \u8fd9\u4e24\u4e2a\u5224\u65ad\u5728\u4ee3\u7801\u91cc\u662f\u5206\u5f00\u7684, \u6c60\u5b50\u975e\u7a7a\u53ea\u662f\u5fc5\u8981\u6761\u4ef6.<\/p>\n<p>\u7c92\u5ea6\u4e0d\u540c, \u540e\u9762\u51e0\u4ef6\u4e8b\u4e5f\u5c31\u8ddf\u7740\u4e0d\u540c\u4e86.<\/p>\n<p><strong>\u4f1a\u8bdd\u8981\u81ea\u5df1\u5224\u65ad\u6d3b\u6027.<\/strong> TCP \u65ad\u4e86\u4f60\u4e0d\u4e00\u5b9a\u77e5\u9053 \u2014\u2014 \u5bf9\u7aef\u4e3b\u673a\u6389\u7535, \u4e2d\u95f4\u7684\u9632\u706b\u5899\u9759\u9ed8\u4e22\u6389\u8fde\u63a5\u72b6\u6001, \u4e13\u7ebf\u5207\u6362, \u8fd9\u4e9b\u60c5\u51b5\u4e0b\u672c\u5730\u7684 socket \u53ef\u80fd\u5f88\u957f\u65f6\u95f4\u8fd8\u505c\u5728 ESTABLISHED, \u4f60\u5f80\u91cc\u5199\u4e5f\u4e0d\u62a5\u9519. keepalive \u63a2\u7684\u662f\u94fe\u8def, \u5bf9\u7aef\u8fdb\u7a0b hang \u6b7b\u4e86\u5185\u6838\u7167\u6837\u56de ACK. \u8fd9\u4e2a\u95ee\u9898 Redis \u90a3\u8fb9\u7531\u6c60\u5b50\u5904\u7406\u6389\u4e86: \u62ff\u5230\u4e00\u6761\u574f\u8fde\u63a5, \u4e22\u6389\u91cd\u5efa, \u5927\u4e0d\u4e86\u91cd\u8bd5\u4e00\u6b21, \u53cd\u6b63\u4f1a\u8bdd\u8ddf\u7740\u8fde\u63a5\u4e00\u8d77\u91cd\u6765. \u4f46\u5728\u8fd9\u91cc\u8fde\u63a5\u53ef\u4ee5\u91cd\u5efa, \u4f1a\u8bdd\u4e0d\u884c, \u6240\u4ee5\u5fc5\u987b\u6709\u5e94\u7528\u5c42\u7684\u5fc3\u8df3 (echo test) \u2014\u2014 \u5b83\u8d85\u65f6\u8bf4\u660e\u7684\u662f\"\u5bf9\u9762\u90a3\u5957\u7cfb\u7edf\u4e0d\u8f6c\u4e86\", \u800c\u4e0d\u53ea\u662f\"\u8fd9\u6761\u7ebf\u65ad\u4e86\".<\/p>\n<p><strong>\u5b83\u662f\u5bf9\u7b49\u7684.<\/strong> AUTH \u662f\u5ba2\u6237\u7aef\u5355\u65b9\u9762\u5411\u670d\u52a1\u7aef\u8bc1\u660e\u81ea\u5df1, \u670d\u52a1\u7aef\u4e0d\u9700\u8981\u53cd\u8fc7\u6765 AUTH. \u800c\u5f00\u5c40\u662f\u4e24\u4e2a\u5bf9\u7b49\u4e2d\u5fc3\u4e4b\u95f4\u7684\u534f\u5546, \u54ea\u8fb9\u90fd\u80fd\u53d1\u8d77, \u54ea\u8fb9\u90fd\u8981\u7ef4\u62a4\u5bf9\u65b9\u7684\u72b6\u6001. \u540e\u9762\u90a3\u4e2a\u5047\u4e2d\u5fc3\u4e4b\u6240\u4ee5\u8981\u628a\u5f00\u5c40\u7684\u4e24\u4e2a\u65b9\u5411\u90fd\u5b9e\u73b0\u4e00\u904d, \u5c31\u662f\u56e0\u4e3a\u8fd9\u4e2a.<\/p>\n<p><strong>\u95ed\u5c40\u662f\u8981\u8c08\u7684.<\/strong> TCP \u7684 FIN \u53ea\u80fd\u8868\u8fbe\"\u6211\u4e0d\u53d1\u4e86\", \u8868\u8fbe\u4e0d\u4e86\"\u6211\u51c6\u5907\u6536\u5de5, \u9ebb\u70e6\u628a\u5728\u9014\u7684\u4ea4\u6613\u5904\u7406\u5b8c\u518d\u65ad\", \u66f4\u4e0d\u7ed9\u5bf9\u65b9\u62d2\u7edd\u6216\u8005\u62d6\u4e00\u4f1a\u513f\u7684\u673a\u4f1a. \u800c\u8fd9\u7c7b\u7cfb\u7edf\u6709\u8425\u4e1a\u65e5, \u6709\u65e5\u5207, \u6709\u5bf9\u8d26 \u2014\u2014 \u505c\u673a\u662f\u4e00\u4ef6\u6709\u4e1a\u52a1\u542b\u4e49\u7684\u4e8b, \u53ea\u80fd\u5728\u5e94\u7528\u5c42\u7528\u7535\u6587\u6765\u8c08.<\/p>\n<p>\u6700\u540e\u4e00\u4e2a\u4f50\u8bc1\u662f\u8d85\u65f6\u7684\u91cf\u7ea7:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">var<\/span><span> (<\/span><\/span>\n<span class=\"giallo-l\"><span>\topenResponseTimeout<\/span><span class=\"z-l-8 z-d-10\">     =<\/span><span> time<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Duration<\/span><span>(<\/span><span class=\"z-l-1 z-d-4\">45<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span> time<\/span><span>.<\/span><span>Second<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\tcloseResponseTimeout<\/span><span class=\"z-l-8 z-d-10\">    =<\/span><span> time<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Duration<\/span><span>(<\/span><span class=\"z-l-1 z-d-4\">75<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span> time<\/span><span>.<\/span><span>Second<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\techoTestResponseTimeout<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> time<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Duration<\/span><span>(<\/span><span class=\"z-l-1 z-d-4\">90<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span> time<\/span><span>.<\/span><span>Second<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>)<\/span><\/span><\/code><\/pre>\n<p>\u51e0\u5341\u79d2\u5230\u4e00\u5206\u534a, \u8fdc\u5927\u4e8e\u4efb\u4f55\u4e00\u4e2a TCP \u5c42\u9762\u7684\u8d85\u65f6. \u8fd9\u4e5f\u8bf4\u660e\u4e86\u5b83\u4eec\u91cf\u7684\u5230\u5e95\u662f\u4ec0\u4e48: \u4e0d\u662f\u7f51\u7edc\u901a\u4e0d\u901a, \u800c\u662f\u5bf9\u9762\u90a3\u5957\u7cfb\u7edf\u8fd8\u8f6c\u4e0d\u8f6c\u5f97\u52a8.<\/p>\n<h2 id=\"mi-yao-de-jie-kou-zhu-ru\"><a class=\"zola-anchor\" href=\"#mi-yao-de-jie-kou-zhu-ru\" aria-label=\"Anchor link for: mi-yao-de-jie-kou-zhu-ru\">\u5bc6\u94a5\u7684\u63a5\u53e3\u6ce8\u5165<\/a><\/h2>\n<p>\u6700\u540e\u4e00\u5757, \u4e5f\u662f\u6211\u81ea\u5df1\u6700\u6ee1\u610f\u7684\u4e00\u5757.<\/p>\n<p>\u8fd9\u7c7b\u534f\u8bae\u7684\u5b89\u5168\u90e8\u5206\u5927\u81f4\u662f\u8fd9\u6837: \u4e1a\u52a1\u7535\u6587\u7684 body \u8981\u52a0\u5bc6, \u540c\u65f6\u8981\u7b97\u4e00\u4e2a\u7535\u6587\u8ba4\u8bc1\u503c\u6302\u5728\u5305\u5934\u4e0a\u9632\u7be1\u6539. \u7528\u7684\u662f 3DES, \u94fe\u5f0f\u5730\u628a body \u4e00\u6bb5\u6bb5\u52a0\u5bc6, \u8ba4\u8bc1\u503c\u53d6\u6700\u540e\u4e00\u6bb5\u5bc6\u6587\u7684\u524d\u51e0\u4e2a\u5b57\u8282 \u2014\u2014 \u4e5f\u5c31\u662f\u4e00\u4e2a CBC-MAC \u7684\u6784\u9020:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span class=\"z-l-6 z-d-7\"> CalcAuthenticationCode<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">data<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> key<\/span><span> [<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><span>)<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">authCode<\/span><span> [<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> err<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\t\/\/<\/span><span class=\"z-l-5 z-d-3\"> \u4e0d\u8db3 8 \u7684\u6574\u6570\u500d, \u672b\u5c3e\u8865 0<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\t\/\/<\/span><span class=\"z-l-5 z-d-3\"> ...<\/span><\/span>\n<span class=\"giallo-l\"><span>\tinput<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> [<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span class=\"z-l-1 z-d-4\">\\x00<\/span><span class=\"z-l-1 z-d-4\">\\x00<\/span><span class=\"z-l-1 z-d-4\">\\x00<\/span><span class=\"z-l-1 z-d-4\">\\x00<\/span><span class=\"z-l-1 z-d-4\">\\x00<\/span><span class=\"z-l-1 z-d-4\">\\x00<\/span><span class=\"z-l-1 z-d-4\">\\x00<\/span><span class=\"z-l-1 z-d-4\">\\x00<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tfor<\/span><span> i<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span class=\"z-l-1 z-d-4\"> 0<\/span><span>;<\/span><span> i<\/span><span class=\"z-l-8 z-d-10\"> &lt;<\/span><span class=\"z-l-6 z-d-7\"> len<\/span><span>(<\/span><span>data<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\">\/<\/span><span class=\"z-l-1 z-d-4\">8<\/span><span>;<\/span><span> i<\/span><span class=\"z-l-8 z-d-10\">++<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tcurrent<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> data<\/span><span>[<\/span><span>i<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-1 z-d-4\">8<\/span><span> :<\/span><span> (<\/span><span>i<\/span><span class=\"z-l-8 z-d-10\">+<\/span><span class=\"z-l-1 z-d-4\">1<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-1 z-d-4\">8<\/span><span>]<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\ttemp<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span class=\"z-l-6 z-d-7\"> Xor<\/span><span>(<\/span><span>input<\/span><span>,<\/span><span> current<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tinput<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-6 z-d-7\"> TripleDesEncrypt<\/span><span>(<\/span><span>temp<\/span><span>,<\/span><span> key<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\t}<\/span><\/span>\n<span class=\"giallo-l\"><span>\tauthCode<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> input<\/span><span>[<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>:<\/span><span class=\"z-l-1 z-d-4\">4<\/span><span>]<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\treturn<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u95ee\u9898\u4e0d\u5728\u7b97\u6cd5, \u5728\u5bc6\u94a5\u4ece\u54ea\u6765.<\/p>\n<p>\u52a0\u5bc6\u548c\u8ba4\u8bc1\u7528\u7684\u662f\u4e24\u628a\u4e0d\u540c\u7684\u5de5\u4f5c\u5bc6\u94a5, \u5b83\u4eec\u4f1a\u5b9a\u671f\u8f6e\u6362: \u901a\u8fc7\u4e00\u6761\u4e13\u95e8\u7684\u5bc6\u94a5\u4ea4\u6362\u7535\u6587\u4e0b\u53d1, \u4e0b\u53d1\u65f6\u88ab\u4e3b\u5bc6\u94a5\u52a0\u5bc6, \u6536\u5230\u4e4b\u540e\u89e3\u51fa\u6765\u624d\u662f\u771f\u6b63\u80fd\u7528\u7684\u503c. \u4e0e\u6b64\u540c\u65f6, \u5305\u5934\u91cc\u6709\u4e00\u4e2a check digit \u5b57\u6bb5\u6807\u8bc6\"\u8fd9\u6761\u7535\u6587\u7528\u7684\u662f\u54ea\u4e00\u628a\u5bc6\u94a5\" \u2014\u2014 \u56e0\u4e3a\u8f6e\u6362\u7684\u90a3\u4e00\u77ac\u95f4, \u7ebf\u4e0a\u4f1a\u540c\u65f6\u5b58\u5728\u7528\u65b0\u65e7\u4e24\u628a\u5bc6\u94a5\u52a0\u5bc6\u7684\u7535\u6587, \u4f60\u5fc5\u987b\u80fd\u6309 check digit \u53cd\u67e5\u51fa\u5bf9\u5e94\u7684\u5bc6\u94a5\u6765\u89e3.<\/p>\n<p>\u8fd9\u5c31\u5e26\u6765\u4e00\u4e2a\u95ee\u9898: \u5bc6\u94a5\u7684\u5b58\u50a8\u548c\u8f6e\u6362, \u5b8c\u5168\u662f\u4e1a\u52a1\u7684\u4e8b\u60c5. \u5355\u8fdb\u7a0b\u7684\u65f6\u5019\u653e\u5185\u5b58\u5c31\u884c, \u591a\u8fdb\u7a0b\u8981\u653e Redis \u6216\u8005\u6570\u636e\u5e93, \u8bb2\u7a76\u4e00\u70b9\u7684\u8981\u653e HSM. SDK \u4e0d\u8be5\u7ba1\u8fd9\u4e9b, \u4f46\u5b83\u53c8\u5fc5\u987b\u5728\u6253\u5305\u548c\u89e3\u5305\u7684\u90a3\u4e00\u523b\u62ff\u5230\u5bc6\u94a5.<\/p>\n<p>\u4e8e\u662f\u628a\u5b83\u505a\u6210\u4e86\u63a5\u53e3, \u7531\u4f7f\u7528\u65b9\u6ce8\u5165:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">type<\/span><span class=\"z-l-6 z-d-7\"> SecretHandler<\/span><span class=\"z-l-8 z-d-10\"> interface<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">\tRetrieveSecret<\/span><span>(<\/span><span>)<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">secret<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">models<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Secret<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> err<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">\tRetrieveSecretWithCheckDigit<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">checkDigit<\/span><span> [<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">byte<\/span><span>)<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">secret<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">models<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Secret<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> err<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">\tRetrieveSpecificSecret<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">secret<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">models<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Secret<\/span><span>)<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">err<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">type<\/span><span class=\"z-l-6 z-d-7\"> CommonStateHandler<\/span><span class=\"z-l-8 z-d-10\"> interface<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">\tSecretHandler<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">\tRetrieveOnlineStatus<\/span><span>(<\/span><span>)<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">status<\/span><span class=\"z-l-6 z-d-7\"> OnlineStatus<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> err<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u5e93\u91cc\u53ea\u7559\u8c03\u7528\u70b9. \u53d1\u9001\u7684\u65f6\u5019, \u7f51\u7edc\u7ba1\u7406\u7c7b\u7535\u6587\u4e0d\u9700\u8981\u5bc6\u94a5, \u4e1a\u52a1\u7535\u6587\u624d\u53bb\u53d6:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">b <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-6 z-d-7\">base<\/span><span>)<\/span><span class=\"z-l-6 z-d-7\"> SendMessage<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">message<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">models<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Message<\/span><span>)<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">err<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\twithoutSecret<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> models<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">IsMsgTypeCodeNetworkControl<\/span><span>(<\/span><span>message<\/span><span>.<\/span><span>MessageType<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tif<\/span><span class=\"z-l-8 z-d-10\"> !<\/span><span>withoutSecret<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tmessage<\/span><span>.<\/span><span>Secret<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> b<\/span><span>.<\/span><span>state<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">RetrieveSecret<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\tif<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> !=<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\t\treturn<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t}<\/span><\/span>\n<span class=\"giallo-l\"><span>\t}<\/span><\/span>\n<span class=\"giallo-l\"><span>\traw<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> message<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Bytes<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\t\/\/<\/span><span class=\"z-l-5 z-d-3\"> ...<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u63a5\u6536\u7684\u65f6\u5019, \u5148\u89e3\u5305\u5934, \u4ece check digit \u53cd\u67e5\u5bc6\u94a5, \u518d\u62ff\u8fd9\u628a\u5bc6\u94a5\u53bb\u89e3 body \u548c\u9a8c\u8ba4\u8bc1\u503c:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span class=\"z-l-6 z-d-7\"> loadMessageBody<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">message<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">models<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Message<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> sh<\/span><span class=\"z-l-6 z-d-7\"> SecretHandler<\/span><span>)<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">err<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\t\/\/<\/span><span class=\"z-l-5 z-d-3\"> \u4ece\u5305\u5934\u7684 check digit \u91cc\u62c6\u51fa\u5404\u628a\u5bc6\u94a5\u7684\u6807\u8bc6<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\t\/\/<\/span><span class=\"z-l-5 z-d-3\"> ...<\/span><\/span>\n<span class=\"giallo-l\"><span>\terr<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> sh<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">RetrieveSpecificSecret<\/span><span>(<\/span><span>secret<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tif<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> !=<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tmessage<\/span><span>.<\/span><span>Error<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> err<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\t\treturn<\/span><\/span>\n<span class=\"giallo-l\"><span>\t}<\/span><\/span>\n<span class=\"giallo-l\"><span>\tmessage<\/span><span>.<\/span><span>Secret<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> secret<\/span><\/span>\n<span class=\"giallo-l\"><span>\terr<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> message<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">LoadBody<\/span><span>(<\/span><span>message<\/span><span>.<\/span><span>BodyBytes<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\treturn<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u5305\u91cc\u9644\u5e26\u4e00\u4e2a\u57fa\u4e8e\u5185\u5b58\u7684\u9ed8\u8ba4\u5b9e\u73b0, \u7528\u4e24\u4e2a map \u5b58 check digit \u5230\u5bc6\u94a5\u7684\u6620\u5c04, \u52a0\u8bfb\u5199\u9501, \u5bc6\u94a5\u66f4\u65b0\u8d70\u4e00\u4e2a channel \u4e32\u884c\u5316. \u591f\u5c0f\u89c4\u6a21\u573a\u666f\u76f4\u63a5\u7528, \u4e5f\u662f\u7ed9\u4f7f\u7528\u65b9\u770b\u7684\u53c2\u8003\u5b9e\u73b0. \u4f46\u5b83\u53ea\u662f\u4e00\u4e2a\u5b9e\u73b0, \u4e0d\u662f\u552f\u4e00\u7684\u5b9e\u73b0.<\/p>\n<p>\u8fd9\u4e2a\u8bbe\u8ba1\u5e26\u6765\u7684\u597d\u5904\u6bd4\u9884\u60f3\u7684\u591a:<\/p>\n<ul>\n<li><strong>\u6d4b\u8bd5\u53ef\u4ee5\u8131\u79bb\u5bc6\u94a5<\/strong>. \u6ce8\u5165\u4e00\u4e2a\u56fa\u5b9a\u5bc6\u94a5\u7684 mock, \u5355\u5143\u6d4b\u8bd5\u5c31\u4e0d\u9700\u8981\u771f\u7684\u8d70\u5bc6\u94a5\u4ea4\u6362\u6d41\u7a0b. \u751a\u81f3\u53ef\u4ee5\u6ce8\u5165\u4e00\u5bf9 <code>MockEncryptBody<\/code> \/ <code>MockDecryptBody<\/code>, \u8ba9\u52a0\u5bc6\u53d8\u6210\u6052\u7b49\u51fd\u6570, \u8054\u8c03\u65f6\u6293\u5305\u80fd\u76f4\u63a5\u770b\u5230\u660e\u6587, \u6392\u67e5\u62a5\u6587\u7ed3\u6784\u95ee\u9898\u7684\u6548\u7387\u5b8c\u5168\u4e0d\u4e00\u6837.<\/li>\n<li><strong>\u5bc6\u94a5\u7684\u751f\u547d\u5468\u671f\u5f52\u4e1a\u52a1<\/strong>. \u4ec0\u4e48\u65f6\u5019\u6362\u5bc6\u94a5, \u6362\u5931\u8d25\u4e86\u600e\u4e48\u9000, \u65e7\u5bc6\u94a5\u7559\u591a\u4e45, \u8fd9\u4e9b\u662f\u4e1a\u52a1\u7b56\u7565, \u5199\u6b7b\u5728\u5e93\u91cc\u5c31\u6ca1\u6cd5\u6539\u4e86.<\/li>\n<li><strong>\u5e93\u91cc\u4e0d\u51fa\u73b0\u4efb\u4f55\u5bc6\u94a5<\/strong>. \u8fd9\u4e2a\u5305\u4ece\u5934\u5230\u5c3e\u6ca1\u6709 \"\u628a\u5bc6\u94a5\u5b58\u54ea\" \u8fd9\u4e2a\u6982\u5ff5, \u81ea\u7136\u4e5f\u5c31\u4e0d\u4f1a\u6709\u4eba\u5f80\u91cc\u9762\u63d0\u4ea4\u4e00\u4e2a\u771f\u7684\u5bc6\u94a5. \u8fd9\u4e00\u70b9\u5728\u5408\u89c4\u5ba1\u8ba1\u7684\u65f6\u5019\u4e5f\u5c11\u4e86\u5f88\u591a\u9ebb\u70e6.<\/li>\n<\/ul>\n<p>\u53cd\u8fc7\u6765\u770b, \u63a5\u53e3\u5f00\u5f97\u6709\u70b9\u591a\u4e86. <code>RetrieveSecretWithCheckDigit<\/code> \u548c <code>RetrieveSpecificSecret<\/code> \u8bed\u4e49\u9ad8\u5ea6\u91cd\u5408, \u4e00\u4e2a\u8fd4\u56de\u65b0\u5bf9\u8c61\u4e00\u4e2a\u539f\u5730\u586b\u5145, \u662f\u4e0d\u540c\u65f6\u671f\u52a0\u7684, \u540e\u6765\u4e5f\u6ca1\u5408\u5e76. \u63a5\u53e3\u8fd9\u4e1c\u897f, \u4e00\u65e6\u6709\u4eba\u5b9e\u73b0\u4e86\u5c31\u4e0d\u597d\u6539\u4e86 \u2014\u2014 \u8fd9\u5927\u6982\u662f\u6700\u76f4\u89c2\u7684\u6559\u8bad.<\/p>\n<h2 id=\"sdk-hua\"><a class=\"zola-anchor\" href=\"#sdk-hua\" aria-label=\"Anchor link for: sdk-hua\">SDK \u5316<\/a><\/h2>\n<p>\u4e0a\u9762\u8fd9\u4e9b\u4e1c\u897f \u2014\u2014 bitmap \u600e\u4e48\u70b9\u4f4d, \u91d1\u989d\u600e\u4e48\u538b\u6210 BCD, \u5546\u6237\u540d\u600e\u4e48\u8f6c Shift-JIS, \u957f\u5ea6\u5934\u7b97\u7684\u662f\u5b57\u8282\u8fd8\u662f\u5b57\u7b26, \u7535\u6587\u8ba4\u8bc1\u503c\u7528\u54ea\u628a\u5bc6\u94a5, \u8fde\u63a5\u65ad\u4e86\u8c01\u8d1f\u8d23\u91cd\u8fde \u2014\u2014 \u5168\u90fd\u662f<strong>\u89c4\u683c\u4e66\u7684\u7ec6\u8282, \u4e0d\u662f\u4e1a\u52a1\u7684\u7ec6\u8282<\/strong>.<\/p>\n<p>\u5199\u8fd9\u4e2a SDK \u7684\u65f6\u5019\u6211\u7ed9\u81ea\u5df1\u5b9a\u7684\u76ee\u6807\u662f: \u4e1a\u52a1\u4ee3\u7801\u91cc\u4e0d\u5e94\u8be5\u51fa\u73b0\u4efb\u4f55\u4e00\u4e2a\u5b57\u8282.<\/p>\n<p>\u4e00\u7b14\u6388\u6743\u4ea4\u6613, \u5728\u4e1a\u52a1\u4fa7\u770b\u8d77\u6765\u5e94\u8be5\u957f\u8fd9\u6837:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span>req<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> client<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">ConstructMessage<\/span><span>(<\/span><\/span>\n<span class=\"giallo-l\"><span>\tmodels<\/span><span>.<\/span><span>MsgTypeCodeAuthorizationRequest<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>\t[<\/span><span>]<\/span><span class=\"z-l-6 z-d-7\">models<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">HeaderOption<\/span><span>{<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tmodels<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">WithSourceID<\/span><span>(<\/span><span>sourceID<\/span><span>)<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tmodels<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">WithDestinationID<\/span><span>(<\/span><span>destID<\/span><span>)<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>\t}<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>\t[<\/span><span>]<\/span><span class=\"z-l-6 z-d-7\">models<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">BodyOption<\/span><span>{<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tmodels<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">WithF2<\/span><span>(<\/span><span>pan<\/span><span>)<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tmodels<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">WithF4<\/span><span>(<\/span><span>amount<\/span><span>)<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tmodels<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">WithFunctionCode<\/span><span>(<\/span><span>models<\/span><span>.<\/span><span>FunctionCodeAuthorization<\/span><span>)<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tmodels<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">WithF37<\/span><span>(<\/span><span>rrn<\/span><span>)<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tmodels<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">WithF43<\/span><span>(<\/span><span>merchantName<\/span><span>)<\/span><span>,<\/span><span class=\"z-l-5 z-d-3\"> \/\/<\/span><span class=\"z-l-5 z-d-3\"> \u65e5\u6587\u5546\u6237\u540d, \u76f4\u63a5\u4f20 UTF-8<\/span><\/span>\n<span class=\"giallo-l\"><span>\t}<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>err<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> c<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">SendMessage<\/span><span>(<\/span><span>req<\/span><span>)<\/span><\/span><\/code><\/pre>\n<p>\u5230\u6b64\u4e3a\u6b62. \u81f3\u4e8e\u8fd9\u6761\u62a5\u6587\u7684 bitmap \u4e0a\u70b9\u4e86\u54ea\u51e0\u4f4d, F4 \u88ab\u538b\u6210\u4e86 6 \u4e2a\u5b57\u8282, F43 \u88ab\u8f6c\u6210\u4e86 Shift-JIS, \u5305\u5934\u4e0a\u6302\u4e86\u4e00\u4e2a\u7528\u5f53\u524d KMAC \u7b97\u51fa\u6765\u7684\u8ba4\u8bc1\u503c, body \u7528\u5f53\u524d KC \u52a0\u5bc6\u8fc7, \u6700\u540e\u4ece\u8fde\u63a5\u6c60\u91cc\u6311\u4e86\u4e00\u6761\u8fde\u63a5\u5199\u51fa\u53bb \u2014\u2014 \u4e1a\u52a1\u4e0d\u9700\u8981\u77e5\u9053\u5176\u4e2d\u4efb\u4f55\u4e00\u4ef6.<\/p>\n<p>\u4e3a\u4e86\u505a\u5230\u8fd9\u4e00\u70b9, \u5305\u91cc\u7684\u5206\u5c42\u662f\u8fd9\u6837\u7684:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>      \u4e1a\u52a1\u4ee3\u7801                        jcn\/ligui (\u5047\u4e2d\u5fc3 + \u547d\u4ee4\u884c)<\/span><\/span>\n<span class=\"giallo-l\"><span>          |                                    |<\/span><\/span>\n<span class=\"giallo-l\"><span>          +------------------+-----------------+<\/span><\/span>\n<span class=\"giallo-l\"><span>                             |<\/span><\/span>\n<span class=\"giallo-l\"><span>      ConstructMessage \/ SendMessage \/ ReceiveMessagesInChannel<\/span><\/span>\n<span class=\"giallo-l\"><span>                             |<\/span><\/span>\n<span class=\"giallo-l\"><span>+----------------------------------------------------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span>| jcn\/client          \u7535\u6587\u6784\u9020, \u7f51\u7edc\u7ba1\u7406\u6d41\u7a0b                     |<\/span><\/span>\n<span class=\"giallo-l\"><span>+----------------------------------------------------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span>| jcn\/center, pool    \u4f1a\u8bdd\u72b6\u6001, \u8fde\u63a5, \u91cd\u8fde, \u9009\u8def, \u6536\u53d1\u51fa\u5165\u53e3     |<\/span><\/span>\n<span class=\"giallo-l\"><span>+----------------------------------------------------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span>| jcn\/models          \u8fd9\u5f20\u7f51\u7684\u62a5\u6587\u5b9a\u4e49, \u5bc6\u94a5, \u5b57\u6bb5\u6821\u9a8c           |<\/span><\/span>\n<span class=\"giallo-l\"><span>+----------------------------------------------------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span>| iso8583, cipher     \u901a\u7528\u5c01\u5305\u89e3\u5305, BCD \/ JIS8, 3DES             |<\/span><\/span>\n<span class=\"giallo-l\"><span>+----------------------------------------------------------------+<\/span><\/span><\/code><\/pre>\n<p>\u6ce8\u610f <code>jcn\/ligui<\/code> \u7684\u4f4d\u7f6e: \u5b83\u5728\u6846\u5916, \u548c\u4e1a\u52a1\u4ee3\u7801\u5e73\u7ea7. \u5b83\u4e0d\u662f SDK \u7684\u4e00\u5c42, \u800c\u662f SDK \u7684\u53e6\u4e00\u4e2a\u4f7f\u7528\u8005 \u2014\u2014 \u4e00\u4e2a\u6070\u597d\u626e\u6f14\u5bf9\u7aef\u89d2\u8272\u7684\u5e94\u7528. \u4f9d\u8d56\u65b9\u5411\u4e5f\u662f\u5355\u5411\u7684: <code>ligui<\/code> \u5f15\u7528 <code>client<\/code> \u548c <code>center<\/code>, \u800c <code>client<\/code>, <code>center<\/code>, <code>models<\/code> \u90fd\u4e0d\u77e5\u9053 <code>ligui<\/code> \u7684\u5b58\u5728, \u53ea\u6709\u6700\u4e0a\u9762\u7684\u53ef\u6267\u884c\u7a0b\u5e8f\u624d\u628a\u5b83\u4eec\u62fc\u5728\u4e00\u8d77. \u540e\u9762\u8bb2\u5047\u4e2d\u5fc3\u7684\u65f6\u5019\u4f1a\u56de\u5230\u8fd9\u4e00\u70b9.<\/p>\n<p>\u6846\u91cc\u6bcf\u4e00\u5c42\u53ea\u5411\u4e0a\u66b4\u9732\u4e0a\u5c42\u771f\u6b63\u9700\u8981\u7684\u6982\u5ff5. \u5177\u4f53\u5230\u51e0\u4e2a\u51b3\u5b9a:<\/p>\n<p><strong>\u7528 functional option \u586b\u57df, \u800c\u4e0d\u662f\u66b4\u9732\u7ed3\u6784\u4f53.<\/strong> body \u4e0a\u4e00\u5171\u5f00\u4e86\u56db\u5341\u591a\u4e2a <code>WithFxx<\/code>, \u6bcf\u4e2a\u57df\u4e00\u4e2a. \u8fd9\u6837\u4e1a\u52a1\u4ee3\u7801\u662f\"\u6211\u8981\u586b\u8fd9\u51e0\u4e2a\u57df\", \u800c\u4e0d\u662f\"\u6211\u8981\u6784\u9020\u4e00\u4e2a\u6709\u8fd9\u51e0\u4e2a\u5b57\u6bb5\u7684\u7ed3\u6784\u4f53, \u5269\u4e0b\u7684\u8bb0\u5f97\u7559 nil\". \u524d\u8005\u6f0f\u586b\u4e00\u4e2a\u57df\u662f\u7f16\u8bd1\u80fd\u8fc7\u4f46\u5bf9\u7aef\u4f1a\u62d2\u7684\u62a5\u6587, \u540e\u8005\u6f0f\u586b\u4e00\u4e2a\u57df\u8fde\u81ea\u5df1\u90fd\u770b\u4e0d\u51fa\u6765. \u987a\u5e26, \u8fd9\u4e9b option \u91cc\u53ef\u4ee5\u505a\u9ed8\u8ba4\u503c\u548c\u683c\u5f0f\u5316, \u6bd4\u5982\u4ea4\u6613\u65f6\u95f4\u76f4\u63a5 <code>models.TimeNumString(time.Now(), models.TimeFormatYYMMDDhhmmss)<\/code>, \u4e1a\u52a1\u4e0d\u7528\u8bb0\u8fd9\u4e2a\u7f51\u7edc\u7528\u7684\u662f 12 \u4f4d\u8fd8\u662f 14 \u4f4d\u65f6\u95f4.<\/p>\n<p><strong>\u7f51\u7edc\u7ba1\u7406\u6d41\u7a0b\u6253\u5305\u6210\u4e00\u4e2a\u8c03\u7528.<\/strong> \u5f00\u5c40, \u95ed\u5c40, echo test, cutover, \u5bc6\u94a5\u4ea4\u6362, \u8fd9\u4e9b\u6d41\u7a0b\u6bcf\u4e2a\u90fd\u662f\u4e00\u6765\u4e00\u56de\u5916\u52a0\u72b6\u6001\u53d8\u66f4, \u4f46\u4e1a\u52a1\u4fa7\u53ea\u5e94\u8be5\u770b\u5230 <code>client.ConstructOpenRequest(...)<\/code> \u548c <code>c.WaitForOnlineStatusOpened(30 * time.Second)<\/code>. \u4f1a\u8bdd\u72b6\u6001\u672c\u8eab\u7531\u5e93\u7ef4\u62a4, \u4e1a\u52a1\u53ea\u5173\u5fc3\"\u73b0\u5728\u80fd\u4e0d\u80fd\u53d1\u4e1a\u52a1\u7535\u6587\".<\/p>\n<p><strong>\u65e5\u5fd7\u8981\u80fd\u76f4\u63a5\u770b.<\/strong> \u52a0\u4e86\u4e00\u4e2a\u53cd\u5c04\u5b9e\u73b0\u7684 <code>PrettyPrint<\/code>, \u6309\u57df\u53f7\u987a\u5e8f\u628a\u975e\u7a7a\u7684\u57df\u6253\u6210 JSON, \u4e8c\u8fdb\u5236\u57df\u8f6c hex, \u539f\u59cb\u5b57\u8282\u4e0d\u6253:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">m <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-6 z-d-7\">Message<\/span><span>)<\/span><span class=\"z-l-6 z-d-7\"> JsonRawMessage<\/span><span>(<\/span><span>)<\/span><span class=\"z-l-6 z-d-7\"> json<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">RawMessage<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\tjsonRawMessage<\/span><span>,<\/span><span> _<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> json<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Marshal<\/span><span>(<\/span><span>(<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-6 z-d-7\">PrettyMessage<\/span><span>)<\/span><span>(<\/span><span>m<\/span><span>)<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\treturn<\/span><span> json<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">RawMessage<\/span><span>(<\/span><span>jsonRawMessage<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u8fd9\u4ef6\u4e8b\u770b\u7740\u4e0d\u8d77\u773c, \u4f46\u4e00\u4e2a SDK \u597d\u4e0d\u597d\u7528, \u5f88\u5927\u7a0b\u5ea6\u4e0a\u53d6\u51b3\u4e8e\u51fa\u95ee\u9898\u7684\u65f6\u5019\u80fd\u4e0d\u80fd\u4e00\u773c\u770b\u51fa\u662f\u54ea\u6761\u62a5\u6587\u7684\u54ea\u4e2a\u57df\u4e0d\u5bf9. \u5982\u679c\u65e5\u5fd7\u91cc\u53ea\u6709\u4e00\u4e32\u5341\u516d\u8fdb\u5236, \u90a3\u524d\u9762\u6240\u6709\u7684\u62bd\u8c61\u5c31\u6ca1\u6709\u610f\u4e49\u4e86 \u2014\u2014 \u7528\u7684\u4eba\u8fd8\u662f\u5f97\u5b66\u4f1a\u624b\u52a8\u6570\u5b57\u8282.<\/p>\n<p>\u53cd\u8fc7\u6765\u8bf4, SDK \u5316\u6700\u96be\u7684\u5730\u65b9\u4e5f\u5728\u8fd9: \u4f60\u8981\u5728\"\u85cf\u8d77\u7ec6\u8282\"\u548c\"\u51fa\u4e8b\u7684\u65f6\u5019\u80fd\u67e5\"\u4e4b\u95f4\u627e\u5e73\u8861. \u85cf\u5f97\u592a\u6d45, \u4e1a\u52a1\u4ee3\u7801\u91cc\u5230\u5904\u662f\u89c4\u683c\u4e66; \u85cf\u5f97\u592a\u6df1, \u51fa\u4e86\u95ee\u9898\u53ea\u80fd\u6765\u95ee\u4f60. \u6211\u7684\u505a\u6cd5\u662f<strong>\u9ed8\u8ba4\u8def\u5f84\u6781\u7b80, \u9003\u751f\u8231\u53e3\u5168\u5f00<\/strong> \u2014\u2014 <code>Message<\/code> \u4e0a\u539f\u59cb\u7684 <code>HeaderBytes<\/code> \u548c <code>BodyBytes<\/code> \u4e00\u76f4\u7559\u7740, \u5bc6\u94a5, \u72b6\u6001, \u8fde\u63a5\u6c60\u7684\u7edf\u8ba1\u4e5f\u90fd\u80fd\u62ff\u5230, \u53ea\u662f\u6b63\u5e38\u5199\u4e1a\u52a1\u7684\u65f6\u5019\u7528\u4e0d\u4e0a.<\/p>\n<h2 id=\"li-kui-yu-li-gui\"><a class=\"zola-anchor\" href=\"#li-kui-yu-li-gui\" aria-label=\"Anchor link for: li-kui-yu-li-gui\">\u674e\u9035\u4e0e\u674e\u9b3c<\/a><\/h2>\n<p>\u5305\u91cc\u6709\u4e00\u4e2a\u76ee\u5f55\u53eb <code>ligui<\/code>. \u540d\u5b57\u6765\u81ea\u6c34\u6d52\u91cc\u90a3\u4e2a\u5728\u6811\u6797\u91cc\u52ab\u9053, \u81ea\u79f0\"\u9ed1\u65cb\u98ce\u674e\u9035\"\u7684\u674e\u9b3c.<\/p>\n<p>\u8fd9\u5c31\u662f\u5f00\u5934\u8bf4\u7684\u90a3\u4e2a\u6321\u677f \u2014\u2014 \u7ed5\u4e86\u4e00\u5927\u5708, \u6700\u5148\u8981\u7684\u4e1c\u897f\u53cd\u800c\u662f\u6700\u540e\u624d\u505a\u51fa\u6765\u7684.<\/p>\n<p>\u7406\u7531\u5012\u662f\u4e00\u76f4\u6ca1\u53d8: \u5bf9\u7aef\u662f\u522b\u4eba\u7684\u7cfb\u7edf, \u8054\u8c03\u7a97\u53e3\u6309\u5c0f\u65f6\u7b97, \u8981\u63d0\u524d\u51e0\u5468\u7533\u8bf7, \u4e00\u6b21\u7a97\u53e3\u8dd1\u4e0d\u5b8c\u5c31\u5f97\u7b49\u4e0b\u4e00\u8f6e. \u5728\u8fd9\u79cd\u8282\u594f\u4e0b, \u552f\u4e00\u7684\u529e\u6cd5\u662f\u81ea\u5df1\u9020\u4e00\u4e2a\u5047\u7684\u4e2d\u5fc3, \u5e73\u65f6\u5148\u548c\u5b83\u5bf9\u63a5, \u8dd1\u901a\u4e86\u518d\u53bb\u63a5\u771f\u7684.<\/p>\n<p><code>ligui<\/code> \u5c31\u662f\u8fd9\u4e2a\u5047\u4e2d\u5fc3. \u5b83\u505a\u4e24\u4ef6\u4e8b:<\/p>\n<p><strong>\u4e00\u662f stub, \u626e\u6f14\u5bf9\u7aef\u56de\u5e94.<\/strong> \u6536\u5230\u4ec0\u4e48\u8bf7\u6c42\u5c31\u6309\u89c4\u683c\u4e66\u6784\u9020\u4ec0\u4e48\u54cd\u5e94, \u8bf7\u6c42\u91cc\u8be5\u539f\u6837\u5e26\u56de\u7684\u57df\u539f\u6837\u5e26\u56de, \u8be5\u7531\u4e2d\u5fc3\u586b\u7684\u57df (\u627f\u8ba4\u53f7, \u5904\u7406\u7ed3\u679c, \u4e2d\u5fc3\u4fa7\u7684\u4ea4\u6613\u901a\u756a) \u7531\u5b83\u6765\u586b:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span class=\"z-l-6 z-d-7\"> constructAuthorizationResponse<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">req<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">models<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Message<\/span><span>,<\/span><span class=\"z-l-8 z-d-10\"> ...<\/span><span>)<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">resp<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">models<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Message<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\tresp<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> client<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">ConstructMessage<\/span><span>(<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tmodels<\/span><span>.<\/span><span>MsgTypeCodeAuthorizationResponse<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t[<\/span><span>]<\/span><span class=\"z-l-6 z-d-7\">models<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">HeaderOption<\/span><span>{<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\t\t\t\/\/<\/span><span class=\"z-l-5 z-d-3\"> \u6e90\u548c\u76ee\u7684\u5bf9\u8c03<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\tmodels<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">WithDestinationID<\/span><span>(<\/span><span>req<\/span><span>.<\/span><span>Header<\/span><span>.<\/span><span>SourceID<\/span><span>.<\/span><span>Value<\/span><span>)<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\tmodels<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">WithSourceID<\/span><span>(<\/span><span>req<\/span><span>.<\/span><span>Header<\/span><span>.<\/span><span>DestID<\/span><span>.<\/span><span>Value<\/span><span>)<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t}<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t[<\/span><span>]<\/span><span class=\"z-l-6 z-d-7\">models<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">BodyOption<\/span><span>{<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\tmodels<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">WithF2<\/span><span>(<\/span><span>req<\/span><span>.<\/span><span>Body<\/span><span>.<\/span><span>F2<\/span><span>.<\/span><span>Value<\/span><span>)<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\tmodels<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">WithF4<\/span><span>(<\/span><span>req<\/span><span>.<\/span><span>Body<\/span><span>.<\/span><span>F4<\/span><span>.<\/span><span>Value<\/span><span>)<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\tmodels<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">WithF11<\/span><span>(<\/span><span>req<\/span><span>.<\/span><span>Body<\/span><span>.<\/span><span>F11<\/span><span>.<\/span><span>Value<\/span><span>)<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\t\t\t\/\/<\/span><span class=\"z-l-5 z-d-3\"> ...<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\tmodels<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">WithF38<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span>)<\/span><span>,<\/span><span class=\"z-l-5 z-d-3\">        \/\/<\/span><span class=\"z-l-5 z-d-3\"> to be filled by options<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t\tmodels<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">WithActionCode<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span>)<\/span><span>,<\/span><span class=\"z-l-5 z-d-3\"> \/\/<\/span><span class=\"z-l-5 z-d-3\"> to be filled by options<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\t}<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>\t)<\/span><\/span>\n<span class=\"giallo-l\"><span>\tresp<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Update<\/span><span>(<\/span><span>headerOpts<\/span><span>,<\/span><span> bodyOpts<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\treturn<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u7559\u7a7a\u7684\u90a3\u51e0\u4e2a\u57df, \u7531\u6d4b\u8bd5\u7528\u4f8b\u901a\u8fc7 option \u8986\u76d6. \u4e8e\u662f\u540c\u4e00\u4e2a\u6784\u9020\u51fd\u6570, \u65e2\u80fd\u9020\u4e00\u6761\"\u627f\u8ba4\"\u7684\u54cd\u5e94, \u4e5f\u80fd\u9020\u4e00\u6761\"\u5361\u7247\u65e0\u6548\"\u6216\u8005\"\u9650\u989d\u8d85\u8fc7\"\u7684\u54cd\u5e94. \u5f02\u5e38\u8def\u5f84\u7684\u6d4b\u8bd5\u6bd4\u6b63\u5e38\u8def\u5f84\u91cd\u8981\u5f97\u591a, \u56e0\u4e3a\u6b63\u5e38\u8def\u5f84\u8054\u8c03\u65f6\u4e00\u5b9a\u4f1a\u8fc7, \u800c\u5f02\u5e38\u8def\u5f84\u53ef\u80fd\u4e0a\u7ebf\u534a\u5e74\u624d\u9047\u5230\u7b2c\u4e00\u6b21.<\/p>\n<p><strong>\u4e8c\u662f mock, \u626e\u6f14\u5bf9\u7aef\u7684\u5b8c\u6574\u884c\u4e3a.<\/strong> \u8fd9\u90e8\u5206\u662f\u4e00\u4e2a\u72b6\u6001\u673a: \u5f00\u5c40\u8bf7\u6c42\u6765\u4e86\u8981\u56de\u5f00\u5c40\u54cd\u5e94\u5e76\u4e14\u628a\u5728\u7ebf\u72b6\u6001\u63a8\u8fdb\u5230 opened, echo test \u6765\u4e86\u8981\u56de, cutover \u6765\u4e86\u8981\u56de, \u5bc6\u94a5\u4ea4\u6362\u6765\u4e86\u8981\u7528 KEK \u89e3\u51fa\u65b0\u7684\u5de5\u4f5c\u5bc6\u94a5, \u5b58\u8fdb\u53bb, \u518d\u56de\u4e00\u6761\u54cd\u5e94. \u4e1a\u52a1\u7535\u6587\u6765\u4e86\u5c31\u8d70 stub \u90a3\u5957\u6784\u9020\u54cd\u5e94. \u9047\u5230\u5b8c\u5168\u4e0d\u8ba4\u8bc6\u7684\u7535\u6587, \u56de\u4e00\u6761\u901a\u7528\u9519\u8bef\u901a\u77e5, \u5e76\u4e14\u628a\u5bf9\u65b9\u7684\u5305\u5934\u539f\u6837\u8d34\u5728\u9519\u8bef\u4fe1\u606f\u57df\u91cc \u2014\u2014 \u8fd9\u662f\u89c4\u683c\u4e66\u8981\u6c42\u7684\u884c\u4e3a, \u800c\u8fd9\u6761\u8def\u5f84\u5982\u679c\u6ca1\u6709 mock, \u4f60\u51e0\u4e4e\u6ca1\u6709\u673a\u4f1a\u6d4b\u5230.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">default<\/span><span>:<\/span><\/span>\n<span class=\"giallo-l\"><span>\tlogz<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Debugf<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span class=\"z-l-2 z-d-6\">unknown message received, message function: <\/span><span class=\"z-l-1 z-d-4\">%v<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span>,<\/span><span> message<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">MessageFunction<\/span><span>(<\/span><span>)<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\terr<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> c<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">SendMessage<\/span><span>(<\/span><span class=\"z-l-6 z-d-7\">ConstructGeneralErrorMessageResponse<\/span><span>(<\/span><span>message<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><span>,<\/span><span> [<\/span><span>]<\/span><span class=\"z-l-6 z-d-7\">models<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">BodyOption<\/span><span>{<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tmodels<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">WithActionCode<\/span><span>(<\/span><span>models<\/span><span>.<\/span><span>ActionCodeErrorFormatInvalid<\/span><span>)<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tmodels<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">WithF72Byte<\/span><span>(<\/span><span>message<\/span><span>.<\/span><span>HeaderBytes<\/span><span>)<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>\t}<\/span><span>)<\/span><span>,<\/span><span> options<\/span><span class=\"z-l-8 z-d-10\">...<\/span><span>)<\/span><\/span><\/code><\/pre>\n<p>\u8ba9\u53cc\u65b9\u8dd1\u540c\u4e00\u4e2a\u5e93, \u8fd8\u6709\u4e00\u4e2a\u66f4\u91cd\u8981\u7684\u7406\u7531: <strong>\u5047\u4e2d\u5fc3\u540c\u65f6\u5c31\u662f\u4e00\u4e2a\u4e00\u81f4\u6027\u68c0\u67e5\u5668<\/strong>. \u6211\u65b9\u53d1\u51fa\u53bb\u7684\u62a5\u6587, \u5047\u4e2d\u5fc3\u8981\u80fd\u89e3\u5f00; \u5047\u4e2d\u5fc3\u53d1\u56de\u6765\u7684\u62a5\u6587, \u6211\u65b9\u8981\u80fd\u89e3\u5f00. \u4efb\u4f55\u4e00\u8fb9\u5bf9\u89c4\u683c\u4e66\u7684\u7406\u89e3\u6709\u504f\u5dee, \u5728\u81ea\u5df1\u548c\u81ea\u5df1\u5bf9\u63a5\u7684\u65f6\u5019\u5c31\u4f1a\u66b4\u9732\u6210\u4e00\u4e2a\u89e3\u4e0d\u5f00\u7684\u62a5\u6587, \u800c\u4e0d\u662f\u7b49\u5230\u8054\u8c03\u7a97\u53e3\u91cc\u5bf9\u65b9\u544a\u8bc9\u4f60\"\u4f60\u4eec\u7684\u7535\u6587\u6211\u4eec\u6536\u4e0d\u4e86\".<\/p>\n<p>\u5728\u8fd9\u4e2a\u57fa\u7840\u4e0a\u53c8\u52a0\u4e86\u4e00\u5c42\u6821\u9a8c, \u6309\u7535\u6587\u79cd\u522b\u548c\u529f\u80fd\u7801, \u58f0\u660e\u8fd9\u6761\u62a5\u6587<strong>\u5e94\u8be5<\/strong>\u51fa\u73b0\u54ea\u4e9b\u57df:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">case<\/span><span> models<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">MessageFunction<\/span><span>(<\/span><span>models<\/span><span>.<\/span><span>MessageTypeCodeNetworkControlResponse<\/span><span>,<\/span><span> models<\/span><span>.<\/span><span>FunctionCodeCutover<\/span><span>)<\/span><span>:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\treturn<\/span><span class=\"z-l-6 z-d-7\"> CheckFiledByExpectedFileds<\/span><span>(<\/span><span>message<\/span><span>,<\/span><span class=\"z-l-6 z-d-7\"> ExpectedFileds<\/span><span>{<\/span><span>[<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">int<\/span><span>{<\/span><span class=\"z-l-1 z-d-4\">11<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> 12<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> 24<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> 28<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> 39<\/span><span>,<\/span><span class=\"z-l-8 z-d-10\"> ...<\/span><span>}<\/span><span>}<\/span><span>)<\/span><\/span><\/code><\/pre>\n<p>\u591a\u4e00\u4e2a\u57df\u5c11\u4e00\u4e2a\u57df\u90fd\u7b97\u9519. \u52a0\u4e0a\u6bcf\u4e2a\u57df\u81ea\u5df1\u7684\u89c4\u5219\u6821\u9a8c (\u5361\u53f7\u662f 10 \u5230 19 \u4f4d\u6570\u5b57, \u5904\u7406\u7801\u662f 6 \u4f4d\u4e14\u5fc5\u987b\u662f\u89c4\u683c\u4e66\u5217\u51fa\u7684\u7ec4\u5408\u4e4b\u4e00), \u7b49\u4e8e\u628a\u89c4\u683c\u4e66\u91cc\u90a3\u5f20\u5de8\u5927\u7684\u8868\u683c\u7ffb\u8bd1\u6210\u4e86\u53ef\u6267\u884c\u7684\u65ad\u8a00. \u8fd9\u4e9b\u65ad\u8a00\u5728\u5047\u4e2d\u5fc3\u91cc\u8dd1, \u4e5f\u5728\u5355\u5143\u6d4b\u8bd5\u91cc\u8dd1.<\/p>\n<h3 id=\"zai-zi-ji-de-bi-ji-ben-shang-pao-tong-quan-liu-cheng\"><a class=\"zola-anchor\" href=\"#zai-zi-ji-de-bi-ji-ben-shang-pao-tong-quan-liu-cheng\" aria-label=\"Anchor link for: zai-zi-ji-de-bi-ji-ben-shang-pao-tong-quan-liu-cheng\">\u5728\u81ea\u5df1\u7684\u7b14\u8bb0\u672c\u4e0a\u8dd1\u901a\u5168\u6d41\u7a0b<\/a><\/h3>\n<p>\u674e\u9b3c\u662f\u4e2a\u5e93, \u8981\u7528\u8d77\u6765\u8fd8\u5f97\u6709\u4e2a\u4e1c\u897f\u9a71\u52a8\u5b83. \u4e8e\u662f\u914d\u4e86\u4e00\u4e2a\u547d\u4ee4\u884c, \u4e00\u4e2a\u6700\u6734\u7d20\u7684 REPL:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span class=\"z-l-6 z-d-7\"> CommandLineRequest<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">c<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">center<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Center<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> state<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">center<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">CommonState<\/span><span>)<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">err<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\treader<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> bufio<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">NewReader<\/span><span>(<\/span><span>os<\/span><span>.<\/span><span>Stdin<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">\tfor<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tfmt<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Println<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span class=\"z-l-2 z-d-6\">Ready for input......<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tinput<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> reader<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">ReadString<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span class=\"z-l-1 z-d-4\">\\n<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\tinputs<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> strings<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Split<\/span><span>(<\/span><span>strings<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">TrimSuffix<\/span><span>(<\/span><span>input<\/span><span>,<\/span><span class=\"z-l-2 z-d-6\"> &quot;<\/span><span class=\"z-l-1 z-d-4\">\\n<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span>)<\/span><span>,<\/span><span class=\"z-l-2 z-d-6\"> &quot;<\/span><span class=\"z-l-2 z-d-6\"> &quot;<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>\t\terr<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-6 z-d-7\"> DoRequest<\/span><span>(<\/span><span>c<\/span><span>,<\/span><span> state<\/span><span>,<\/span><span> inputs<\/span><span>[<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>]<\/span><span>,<\/span><span> inputs<\/span><span>[<\/span><span class=\"z-l-1 z-d-4\">1<\/span><span>:<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">...<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\t\t\/\/<\/span><span class=\"z-l-5 z-d-3\"> ...<\/span><\/span>\n<span class=\"giallo-l\"><span>\t}<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u547d\u4ee4\u57fa\u672c\u8986\u76d6\u4e86\u8fd9\u5f20\u7f51\u4e0a\u4f1a\u53d1\u751f\u7684\u6240\u6709\u4e8b:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>open                \u5f00\u5c40<\/span><\/span>\n<span class=\"giallo-l\"><span>echotest            \u5fc3\u8df3<\/span><\/span>\n<span class=\"giallo-l\"><span>key_exchange KC     \u6362\u4e00\u628a\u5bc6\u94a5 (KC \/ KMAC \/ KPE)<\/span><\/span>\n<span class=\"giallo-l\"><span>authori             \u4e00\u7b14\u6388\u6743<\/span><\/span>\n<span class=\"giallo-l\"><span>authori_arqc        \u4e00\u7b14\u5e26 IC \u5361\u6570\u636e\u7684\u6388\u6743<\/span><\/span>\n<span class=\"giallo-l\"><span>sales               \u4e00\u7b14\u9500\u552e<\/span><\/span>\n<span class=\"giallo-l\"><span>revarsal_advice     \u4e00\u7b14\u51b2\u6b63<\/span><\/span>\n<span class=\"giallo-l\"><span>cutover &lt;\u65e5\u671f&gt;       \u65e5\u5207<\/span><\/span>\n<span class=\"giallo-l\"><span>audit               \u5728\u7ebf\u5ba1\u67e5<\/span><\/span>\n<span class=\"giallo-l\"><span>stats               \u770b\u770b\u73b0\u5728\u6709\u51e0\u6761\u8fde\u63a5<\/span><\/span><\/code><\/pre>\n<p>\u5173\u952e\u5728\u4e8e<strong>\u4e24\u8fb9\u8dd1\u7684\u662f\u540c\u4e00\u4e2a\u4e1c\u897f<\/strong>. \u6700\u540e\u843d\u6210\u4e24\u4e2a main, \u4e00\u4e2a <code>center<\/code> \u4e00\u4e2a <code>mockcenter<\/code>, \u5404\u81ea\u90fd\u53ea\u662f\u51e0\u5341\u884c\u80f6\u6c34: \u8bfb\u914d\u7f6e, \u88c5\u597d\u521d\u59cb\u5bc6\u94a5, \u8d77\u4e00\u4e2a <code>Center<\/code>, \u7136\u540e\u4e00\u4e2a\u628a stdin \u63a5\u5230 <code>ligui<\/code> \u7684 sender \u4e0a, \u53e6\u4e00\u4e2a\u7528 <code>ligui<\/code> \u7684 receiver \u81ea\u52a8\u5e94\u7b54. \u5730\u5740\u586b <code>127.0.0.1<\/code>, \u4e92\u76f8\u4e00\u8fde, \u6574\u6761\u94fe\u8def\u5c31\u5728\u4e00\u53f0\u7b14\u8bb0\u672c\u4e0a\u8dd1\u8d77\u6765\u4e86 \u2014\u2014 \u4e0d\u9700\u8981\u4e13\u7ebf, \u4e0d\u9700\u8981 VPN, \u4e0d\u9700\u8981\u5bf9\u65b9\u7684\u7cfb\u7edf:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>open \u2192 key_exchange \u2192 authori \u2192 revarsal_advice \u2192 cutover \u2192 close<\/span><\/span><\/code><\/pre>\n<p>\u8fd9\u4e00\u8d9f\u8d70\u4e0b\u6765, TCP \u8fde\u63a5\u7684\u5efa\u7acb\u4e0e\u4fdd\u6d3b, \u4f1a\u8bdd\u72b6\u6001\u673a\u7684\u63a8\u8fdb, bitmap \u7684\u7ec4\u88c5\u4e0e\u89e3\u6790, BCD \u548c Shift-JIS \u7684\u7f16\u89e3\u7801, 3DES \u52a0\u5bc6, \u7535\u6587\u8ba4\u8bc1\u503c\u7684\u8ba1\u7b97\u4e0e\u6821\u9a8c, \u5bc6\u94a5\u6309 check digit \u7684\u53cd\u67e5, \u5168\u90fd\u771f\u5b9e\u5730\u6267\u884c\u4e86\u4e00\u904d. \u5b83\u4e0d\u662f\u5355\u5143\u6d4b\u8bd5\u91cc\u90a3\u79cd\"\u5582\u4e00\u6bb5\u5b57\u8282, \u65ad\u8a00\u89e3\u51fa\u6765\u662f\u4ec0\u4e48\", \u800c\u662f\u771f\u7684\u4ece\u4e00\u4e2a\u8fdb\u7a0b\u7684 socket \u51fa\u53bb, \u4ece\u53e6\u4e00\u4e2a\u8fdb\u7a0b\u7684 socket \u8fdb\u6765 \u2014\u2014 \u4e00\u6b21\u5b8c\u6574\u7684\u758f\u901a\u6d4b\u8bd5, \u53ea\u4e0d\u8fc7\u5bf9\u9762\u662f\u81ea\u5df1.<\/p>\n<p>\u5b83\u8981\u89e3\u51b3\u7684\u662f\u4e0b\u9762\u51e0\u4e2a\u95ee\u9898.<\/p>\n<p><strong>\u4e0a\u624b\u4e0d\u9700\u8981\u4efb\u4f55\u524d\u7f6e\u6761\u4ef6.<\/strong> \u4ee3\u7801\u62c9\u4e0b\u6765, \u8d77\u4e24\u4e2a\u8fdb\u7a0b\u5c31\u80fd\u8dd1\u8d77\u6765. \u4e0d\u7528\u7533\u8bf7\u4e13\u7ebf, \u4e0d\u7528\u7b49\u5bc6\u94a5\u4e0b\u53d1, \u4e0d\u7528\u534f\u8c03\u8054\u8c03\u7a97\u53e3. \u5bf9\u4e00\u4e2a\u5916\u90e8\u4f9d\u8d56\u8fd9\u4e48\u91cd\u7684\u9879\u76ee\u6765\u8bf4, \"\u80fd\u5728\u672c\u673a\u8dd1\u8d77\u6765\"\u8fd9\u4ef6\u4e8b\u672c\u8eab\u5c31\u628a\u65b0\u4eba\u7684\u4e0a\u624b\u6210\u672c\u780d\u6389\u4e86\u4e00\u5927\u534a \u2014\u2014 \u5426\u5219\u4e00\u4e2a\u521a\u63a5\u624b\u7684\u4eba\u5728\u62ff\u5230\u7f51\u7edc\u6743\u9650\u4e4b\u524d, \u8fde\u81ea\u5df1\u5199\u7684\u4ee3\u7801\u5bf9\u4e0d\u5bf9\u90fd\u9a8c\u8bc1\u4e0d\u4e86.<\/p>\n<p><strong>\u62a5\u6587\u7684\u586b\u5145\u662f\u81ea\u52a8\u7684.<\/strong> \u4e00\u6761\u6388\u6743\u62a5\u6587\u4e8c\u4e09\u5341\u4e2a\u57df, \u4eba\u4e0d\u53ef\u80fd\u6bcf\u6b21\u624b\u586b. \u6240\u4ee5\u9664\u4e86\u4f60\u771f\u6b63\u5173\u5fc3\u7684\u90a3\u4e00\u4e24\u4e2a\u53c2\u6570, \u5176\u4f59\u7684\u57df\u90fd\u7528\u7b26\u5408\u89c4\u683c\u7684\u968f\u673a\u6570\u636e\u586b\u4e0a \u2014\u2014 \u68c0\u7d22\u53c2\u8003\u53f7\u662f\u5408\u6cd5\u5b57\u7b26\u96c6\u7684 12 \u4f4d, IC \u5361\u6570\u636e\u662f\u4e00\u6bb5\u5408\u6cd5\u957f\u5ea6\u7684\u5b57\u8282:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span>models<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">WithF37<\/span><span>(<\/span><span>jcn<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">MustGenerateCode<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span class=\"z-l-2 z-d-6\">anp<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> 12<\/span><span>)<\/span><span>)<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>models<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">WithF55<\/span><span>(<\/span><span>jcn<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">MustGenerateByte<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span class=\"z-l-2 z-d-6\">anp<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> 114<\/span><span>)<\/span><span>)<\/span><span>,<\/span><\/span><\/code><\/pre>\n<p>\u987a\u5e26, \u8fd9\u4e5f\u4e00\u76f4\u5728\u538b\u8fb9\u754c. \u6bcf\u6572\u4e00\u6b21\u547d\u4ee4, \u53d8\u957f\u57df\u7684\u957f\u5ea6\u548c\u5185\u5bb9\u90fd\u4e0d\u4e00\u6837, \u8fde\u7740\u6572\u51e0\u5341\u6b21, \u76f8\u5f53\u4e8e\u4e00\u8f6e\u5c0f\u5c0f\u7684\u968f\u673a\u6d4b\u8bd5 \u2014\u2014 \u524d\u9762\u90a3\u4e9b\u957f\u5ea6\u5934, \u8865\u4f4d, \u534a\u89d2\u5168\u89d2\u6df7\u6392\u7684\u5751, \u6709\u597d\u51e0\u4e2a\u5c31\u662f\u8fd9\u4e48\u649e\u51fa\u6765\u7684.<\/p>\n<p><strong>\u6709\u72b6\u6001\u7684\u6d41\u7a0b\u7ec8\u4e8e\u53ef\u6d4b\u4e86.<\/strong> \u5bc6\u94a5\u8f6e\u6362\u8fd9\u79cd\u4e8b\u5355\u5143\u6d4b\u8bd5\u5f88\u96be\u8986\u76d6: \u5b83\u8de8\u8d8a\u591a\u6761\u62a5\u6587, \u8fd8\u8981\u6c42\u53cc\u65b9\u7684\u72b6\u6001\u540c\u6b65\u53d8\u5316. \u5728\u547d\u4ee4\u884c\u91cc\u5c31\u662f\u4e00\u6761 <code>key_exchange KC<\/code>, \u6572\u5b8c\u63a5\u7740\u6572 <code>authori<\/code> \u2014\u2014 \u5982\u679c\u65b0\u5bc6\u94a5\u6ca1\u751f\u6548, \u5bf9\u9762\u7acb\u523b\u4f1a\u56e0\u4e3a\u8ba4\u8bc1\u503c\u5bf9\u4e0d\u4e0a\u628a\u8fd9\u7b14\u62d2\u6389, \u4e00\u79d2\u949f\u5c31\u77e5\u9053\u7ed3\u679c.<\/p>\n<p><strong>\u8054\u8c03\u7684\u65f6\u5019\u4eba\u673a\u914d\u5408\u5f88\u987a.<\/strong> \u5bf9\u9762\u5728\u7535\u8bdd\u90a3\u5934\u8bf4\"\u518d\u53d1\u4e00\u7b14\u5e26 IC \u5361\u6570\u636e\u7684\", \u6572\u4e00\u884c\u5c31\u884c, \u4e0d\u7528\u6539\u4ee3\u7801, \u4e0d\u7528\u91cd\u65b0\u7f16\u8bd1, \u4e0d\u7528\u91cd\u65b0\u5f00\u5c40. \u7a97\u53e3\u65f6\u95f4\u6309\u5c0f\u65f6\u7b97\u7684\u65f6\u5019, \u8fd9\u4e2a\u5dee\u522b\u5f88\u5927.<\/p>\n<p>\u8fd9\u4e2a\u547d\u4ee4\u884c\u672c\u8eab\u7684\u4ee3\u7801\u91cf\u5f88\u5c0f, \u5927\u90e8\u5206\u5c31\u662f\u4e00\u4e2a switch \u52a0\u4e00\u5806\u9884\u8bbe\u597d\u7684 option, \u5b9e\u73b0\u4e0a\u6ca1\u4ec0\u4e48\u53ef\u8bf4\u7684. \u4f46\u5b83\u662f\u6574\u4e2a\u9879\u76ee\u91cc\u88ab\u8dd1\u5f97\u6700\u591a\u7684\u4e00\u6bb5\u4ee3\u7801.<\/p>\n<h3 id=\"zhi-bu-zhi\"><a class=\"zola-anchor\" href=\"#zhi-bu-zhi\" aria-label=\"Anchor link for: zhi-bu-zhi\">\u503c\u4e0d\u503c<\/a><\/h3>\n<p>\u56de\u5934\u770b, \u8fd9\u662f\u6574\u4e2a\u9879\u76ee\u91cc\u6027\u4ef7\u6bd4\u6700\u9ad8\u7684\u4e00\u90e8\u5206. \u62a5\u6587\u7ed3\u6784\u7684\u95ee\u9898, \u72b6\u6001\u673a\u7684\u95ee\u9898, \u91cd\u8fde\u7684\u95ee\u9898, \u4e5d\u6210\u90fd\u5728\u548c\u5047\u4e2d\u5fc3\u5bf9\u63a5\u7684\u65f6\u5019\u5c31\u66b4\u9732\u4e86. \u771f\u6b63\u7684\u8054\u8c03\u7a97\u53e3\u4e8e\u662f\u53ea\u7528\u6765\u9a8c\u8bc1\u90a3\u4e9b\u81ea\u5df1\u731c\u4e0d\u5230\u7684\u4e1c\u897f \u2014\u2014 \u6bd4\u5982\u5bf9\u7aef\u7684\u5b9e\u73b0\u548c\u89c4\u683c\u4e66\u4e0d\u4e00\u81f4\u7684\u5730\u65b9, \u8fd9\u79cd\u4e8b\u603b\u662f\u6709\u7684, \u800c\u4e14\u5f80\u5f80\u662f\u6700\u540e\u624d\u53d1\u73b0.<\/p>\n<p>\u5199\u674e\u9b3c\u5f53\u7136\u662f\u6709\u6210\u672c\u7684, \u7c97\u770b\u751a\u81f3\u50cf\u662f\u628a\u540c\u4e00\u4ef6\u4e8b\u505a\u4e86\u4e24\u904d. \u4f46\u8fd9\u7c7b\u9879\u76ee\u91cc\u5bf9\u7aef\u4e0d\u53ef\u63a7\u662f\u5e38\u6001: \u4f60\u62ff\u4e0d\u5230\u5b83, \u7ea6\u4e0d\u5230\u5b83, \u4e5f\u4e0d\u80fd\u8ba9\u5b83\u914d\u5408\u4f60\u91cd\u590d\u4e00\u767e\u6b21\u5f02\u5e38\u573a\u666f. \u4e0e\u5176\u7b49\u7740\u5bf9\u7aef\u53ef\u7528, \u4e0d\u5982\u5148\u628a\u5bf9\u7aef\u9020\u51fa\u6765.<\/p>\n<h2 id=\"hou-ji\"><a class=\"zola-anchor\" href=\"#hou-ji\" aria-label=\"Anchor link for: hou-ji\">\u540e\u8bb0<\/a><\/h2>\n<p>\u4e00\u4e2a SDK, \u4e0a\u5343\u9875\u65e5\u6587 PDF. \u76ee\u524d\u5168\u6d41\u7a0b\u80fd\u8dd1\u901a\u4e86, \u4e0d\u8fc7\u540e\u9762\u4ed8\u8d39\u8054\u8c03\u548c\u4e0a\u7ebf, \u53ef\u80fd\u8fd8\u8981\u8c03\u6574\u4e0d\u5c11.<\/p>\n<p>\u505a\u5bf9\u4e86\u7684\u5927\u6982\u662f\u4e09\u4ef6\u4e8b: \u7528\u53cd\u5c04\u52a0 struct tag \u63cf\u8ff0\u62a5\u6587, \u8ba9 bitmap \u4e0d\u9700\u8981\u4eba\u6765\u7ef4\u62a4; \u5bc6\u94a5\u7528\u63a5\u53e3\u6ce8\u5165, \u628a\u5b58\u50a8\u548c\u8f6e\u6362\u7684\u7b56\u7565\u7559\u7ed9\u4e1a\u52a1; \u4ee5\u53ca\u4ece\u7b2c\u4e00\u5929\u5c31\u5199\u674e\u9b3c, \u800c\u4e0d\u662f\u7b49\u5230\u6709\u8054\u8c03\u7a97\u53e3\u4e86\u518d\u8bf4. \u8fd9\u4e09\u4ef6\u4e8b\u5176\u5b9e\u662f\u540c\u4e00\u4ef6 \u2014\u2014 \u90fd\u662f\u5728\u628a\"\u67d0\u4e2a\u4eba\u5bf9\u89c4\u683c\u4e66\u7684\u7406\u89e3\"\u53d8\u6210\"\u4ee3\u7801\u91cc\u80fd\u8dd1, \u80fd\u6d4b, \u80fd\u88ab\u522b\u4eba\u6539\u7684\u4e1c\u897f\". \u8fd9\u4e2a\u5305\u8fdf\u65e9\u4e0d\u4f1a\u7531\u6211\u6765\u7ef4\u62a4, \u5230\u90a3\u65f6\u5019, \u7559\u4e0b\u6765\u7684\u5e94\u8be5\u662f\u65ad\u8a00\u548c\u6d4b\u8bd5, \u800c\u4e0d\u662f\u53e3\u5934\u4f20\u627f.<\/p>\n<p>\u800c\"\u4e1a\u52a1\u4ee3\u7801\u91cc\u4e0d\u5e94\u8be5\u51fa\u73b0\u4efb\u4f55\u4e00\u4e2a\u5b57\u8282\"\u8fd9\u6761, \u5927\u6982\u662f\u6211\u4ece\u8fd9\u4e2a\u9879\u76ee\u91cc\u5e26\u8d70\u7684\u6700\u4e3b\u8981\u7684\u4e1c\u897f \u2014\u2014 \u4e00\u4e2a SDK \u7684\u4ef7\u503c\u4e0d\u5728\u4e8e\u5b83\u5b9e\u73b0\u4e86\u591a\u5c11\u89c4\u683c\u4e66, \u800c\u5728\u4e8e\u5b83\u66ff\u4f7f\u7528\u8005\u6321\u6389\u4e86\u591a\u5c11\u89c4\u683c\u4e66.<\/p>\n<p>\u505a\u7cd9\u4e86\u7684\u5730\u65b9\u4e5f\u4e0d\u5c11. \u8fde\u63a5\u6c60\u90a3\u90e8\u5206\u6539\u52a8\u6700\u5927, \u6839\u5b50\u4e0a\u662f\u72b6\u6001\u7684\u4f4d\u7f6e\u4e0d\u4e00\u6837: Redis \u90a3\u8fb9\u4f1a\u8bdd\u5c31\u7ed1\u5728\u8fde\u63a5\u4e0a, \u8fde\u63a5\u672c\u8eab\u662f\u65e0\u72b6\u6001, \u53ef\u66ff\u6362\u7684, \u6c60\u5b50\u91cc\u53d6\u54ea\u4e00\u6761\u90fd\u4e00\u6837, \u574f\u4e86\u4e22\u6389\u91cd\u5efa\u5c31\u884c; \u800c\u8fd9\u8fb9\u6bcf\u6761\u8fde\u63a5\u6709\u81ea\u5df1\u7684\u8fdc\u7aef\u5730\u5740\u548c\u8eab\u4efd, \u4f1a\u8bdd\u53c8\u72ec\u7acb\u5728\u8fde\u63a5\u4e4b\u5916, \u6c60\u5b50\u80fd\u505a\u7684\u5176\u5b9e\u53ea\u5269\u4e0b\u9009\u8def. \u7ed3\u6784\u8fd8\u662f\u4ece go-redis \u501f\u6765\u7684, \u4f46\u91cc\u9762\u7684\u903b\u8f91\u57fa\u672c\u90fd\u6362\u4e86\u4e00\u904d, \u6709\u4e9b\u5199\u6cd5 (\u6bd4\u5982\u90a3\u4e2a\u91cd\u8bd5\u6b21\u6570, \u8fd8\u6709\u4e00\u5904 <code>for<\/code> \u5faa\u73af\u91cc\u7684\u63d0\u524d return) \u73b0\u5728\u770b\u7740\u5c31\u522b\u626d. \u5bc6\u94a5\u90a3\u51e0\u4e2a\u63a5\u53e3\u5f00\u91cd\u590d\u4e86, \u4e5f\u8be5\u8d81\u65e9\u5408\u5e76\u6389.<\/p>\n<p>\u4e0d\u8fc7\u8fd9\u5927\u6982\u5c31\u662f\u8fd9\u7c7b\u9879\u76ee\u7684\u5e38\u6001: \u89c4\u683c\u4e66\u662f\u522b\u4eba\u7684, \u65f6\u95f4\u662f\u56fa\u5b9a\u7684, \u80fd\u505a\u7684\u53ea\u6709\u786e\u4fdd\u81ea\u5df1\u8fd9\u90e8\u5206\u5b8c\u6574\u53ef\u9760.<\/p>\n"},{"title":"\u642d\u5efa WireGuard \u7f51\u7edc","published":"2022-11-29T19:00:24+09:00","updated":"2022-11-29T19:00:24+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/wireguard-in-ubuntu\/"}},"id":"https:\/\/memwey.github.io\/posts\/wireguard-in-ubuntu\/","content":"<p>\u672c\u6587\u4ecb\u7ecd\u5728\u4e00\u53f0 <code>Ubuntu 22.04<\/code> \u7684\u670d\u52a1\u5668\u4e0b\u642d\u5efa WireGuard \u670d\u52a1\u5668\u7aef, \u9644\u5e26\u6709\u5ba2\u6237\u7aef\u7684\u4e00\u4e9b\u914d\u7f6e.<\/p>\n<h2 id=\"an-zhuang\"><a class=\"zola-anchor\" href=\"#an-zhuang\" aria-label=\"Anchor link for: an-zhuang\">\u5b89\u88c5<\/a><\/h2>\n<p>WireGuard \u5df2\u7ecf\u96c6\u6210\u5728 5.6 \u53ca\u4ee5\u4e0a\u7248\u672c\u7684 Linux Kernel \u4e2d, <code>Ubuntu 22.04<\/code> \u7cfb\u7edf\u4e0b\u76f4\u63a5\u5b89\u88c5\u5373\u53ef<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>sudo apt update<\/span><\/span>\n<span class=\"giallo-l\"><span>sudo apt install wireguard<\/span><\/span><\/code><\/pre><h2 id=\"sheng-cheng-mi-yao-dui\"><a class=\"zola-anchor\" href=\"#sheng-cheng-mi-yao-dui\" aria-label=\"Anchor link for: sheng-cheng-mi-yao-dui\">\u751f\u6210\u5bc6\u94a5\u5bf9<\/a><\/h2>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>cd \/etc\/wireguard<\/span><\/span>\n<span class=\"giallo-l\"><span>wg genkey | tee s_private.key | wg pubkey &gt; s_public.key<\/span><\/span>\n<span class=\"giallo-l\"><span>wg genkey | tee c_private.key | wg pubkey &gt; c_public.key<\/span><\/span><\/code><\/pre>\n<p>\u6b64\u65f6\u4f1a\u5728\u76ee\u5f55\u4e0b\u751f\u6210\u56db\u4e2a\u6587\u4ef6, \u5177\u4f53\u8bf4\u660e\u5982\u4e0b<\/p>\n<table><thead><tr><th>\u6587\u4ef6\u540d<\/th><th>\u6587\u4ef6\u8bf4\u660e<\/th><\/tr><\/thead><tbody>\n<tr><td>s_private.key<\/td><td>\u670d\u52a1\u5668\u7aef\u79c1\u94a5<\/td><\/tr>\n<tr><td>s_public.key<\/td><td>\u670d\u52a1\u5668\u7aef\u516c\u94a5<\/td><\/tr>\n<tr><td>c_private.key<\/td><td>\u5ba2\u6237\u7aef\u79c1\u94a5<\/td><\/tr>\n<tr><td>c_public.key<\/td><td>\u5ba2\u6237\u7aef\u516c\u94a5<\/td><\/tr>\n<\/tbody><\/table>\n<h2 id=\"pei-zhi-wireguard-fu-wu-qi-duan\"><a class=\"zola-anchor\" href=\"#pei-zhi-wireguard-fu-wu-qi-duan\" aria-label=\"Anchor link for: pei-zhi-wireguard-fu-wu-qi-duan\">\u914d\u7f6e WireGuard \u670d\u52a1\u5668\u7aef<\/a><\/h2>\n<p>\u5177\u4f53\u9700\u8981\u5404\u7aef\u51c6\u5907\u7684\u53d8\u91cf\u6709\u4ee5\u4e0b\u8fd9\u4e9b<\/p>\n<ul>\n<li>\u670d\u52a1\u5668\u7aef: \u516c\u7f51 IP, \u5185\u7f51 IP, \u516c\u7f51\u7aef\u53e3, \u516c\u94a5, \u79c1\u94a5, \u7f51\u7edc\u63a5\u53e3<\/li>\n<li>\u5ba2\u6237\u7aef: \u5185\u7f51 IP, \u79c1\u94a5, \u516c\u94a5<\/li>\n<\/ul>\n<p>\u6574\u7406\u4e3a\u5982\u4e0b\u8868\u683c<\/p>\n<table><thead><tr><th><\/th><th>\u670d\u52a1\u5668\u7aef<\/th><th>\u5ba2\u6237\u7aef<\/th><\/tr><\/thead><tbody>\n<tr><td>\u516c\u7f51IP<\/td><td>233.233.233.233<\/td><td><\/td><\/tr>\n<tr><td>\u5185\u7f51IP<\/td><td>192.168.1.1<\/td><td>192.168.1.2<\/td><\/tr>\n<tr><td>\u7aef\u53e3\u914d\u7f6e<\/td><td>udp\/6666<\/td><td><\/td><\/tr>\n<tr><td>\u79c1\u94a5\u6587\u4ef6<\/td><td>s_private.key<\/td><td>c_private.key<\/td><\/tr>\n<tr><td>\u516c\u94a5\u6587\u4ef6<\/td><td>s_public.key<\/td><td>c_public.key<\/td><\/tr>\n<tr><td>\u7f51\u7edc\u63a5\u53e3<\/td><td>eth0<\/td><td><\/td><\/tr>\n<\/tbody><\/table>\n<h3 id=\"bian-xie-pei-zhi-wen-jian\"><a class=\"zola-anchor\" href=\"#bian-xie-pei-zhi-wen-jian\" aria-label=\"Anchor link for: bian-xie-pei-zhi-wen-jian\">\u7f16\u5199\u914d\u7f6e\u6587\u4ef6<\/a><\/h3>\n<p>\u6587\u4ef6\u4f4d\u7f6e\u4e3a <code>\/etc\/wireguard\/wg0.conf<\/code><\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>[Interface]<\/span><\/span>\n<span class=\"giallo-l\"><span>Address = 192.168.1.1<\/span><\/span>\n<span class=\"giallo-l\"><span>DNS = 223.6.6.6<\/span><\/span>\n<span class=\"giallo-l\"><span>ListenPort = 6666<\/span><\/span>\n<span class=\"giallo-l\"><span>PrivateKey = s_private.key<\/span><\/span>\n<span class=\"giallo-l\"><span>PostUp   = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE<\/span><\/span>\n<span class=\"giallo-l\"><span>PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -D FORWARD -o wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>[Peer]<\/span><\/span>\n<span class=\"giallo-l\"><span>PublicKey = c_public.key<\/span><\/span>\n<span class=\"giallo-l\"><span>AllowedIPs = 192.168.1.2<\/span><\/span><\/code><\/pre>\n<p>\u5176\u4e2d <code>Interface<\/code> \u53ef\u4ee5\u5927\u81f4\u7406\u89e3\u4e3a\u672c\u673a\u7684\u914d\u7f6e, \u800c <code>Peer<\/code> \u662f\u9762\u5411\u5916\u90e8\u7684\u914d\u7f6e. \u6709\u4e00\u4e9b\u53c2\u6570\u9700\u8981\u6309\u7167\u5b9e\u9645\u60c5\u51b5\u8c03\u6574, \u5bc6\u94a5\u9700\u8981\u66ff\u6362\u4e3a\u5b9e\u9645\u7684\u5b57\u7b26\u4e32<\/p>\n<h3 id=\"qi-ta-fu-wu-qi-pei-zhi\"><a class=\"zola-anchor\" href=\"#qi-ta-fu-wu-qi-pei-zhi\" aria-label=\"Anchor link for: qi-ta-fu-wu-qi-pei-zhi\">\u5176\u4ed6\u670d\u52a1\u5668\u914d\u7f6e<\/a><\/h3>\n<p>\u5728\u670d\u52a1\u5668\u7aef\u542f\u52a8 IP \u8f6c\u53d1<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>sysctl net.ipv4.ip_forward=1<\/span><\/span><\/code><\/pre>\n<p>\u53e6\u5916, \u53ef\u80fd\u9700\u8981\u4e91\u4e3b\u673a\u4e0a\u914d\u7f6e\u5f00\u653e\u5bf9\u5e94\u7684 UDP \u7aef\u53e3<\/p>\n<h3 id=\"qi-dong-yu-ting-zhi\"><a class=\"zola-anchor\" href=\"#qi-dong-yu-ting-zhi\" aria-label=\"Anchor link for: qi-dong-yu-ting-zhi\">\u542f\u52a8\u4e0e\u505c\u6b62<\/a><\/h3>\n<p>\u914d\u7f6e\u5b8c\u6210\u540e, \u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4, \u5206\u522b\u662f\u542f\u52a8, \u67e5\u770b\u72b6\u6001, \u505c\u6b62<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>wg-quick up wg0<\/span><\/span>\n<span class=\"giallo-l\"><span>wg show wg0<\/span><\/span>\n<span class=\"giallo-l\"><span>wg-quick down wg0<\/span><\/span><\/code><\/pre><h2 id=\"wireguard-ke-hu-duan-pei-zhi\"><a class=\"zola-anchor\" href=\"#wireguard-ke-hu-duan-pei-zhi\" aria-label=\"Anchor link for: wireguard-ke-hu-duan-pei-zhi\">WireGuard \u5ba2\u6237\u7aef\u914d\u7f6e<\/a><\/h2>\n<h3 id=\"bian-xie-pei-zhi-wen-jian-1\"><a class=\"zola-anchor\" href=\"#bian-xie-pei-zhi-wen-jian-1\" aria-label=\"Anchor link for: bian-xie-pei-zhi-wen-jian-1\">\u7f16\u5199\u914d\u7f6e\u6587\u4ef6<\/a><\/h3>\n<p>\u6587\u4ef6\u547d\u540d\u4e3a <code>client.conf<\/code><\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>[Interface]<\/span><\/span>\n<span class=\"giallo-l\"><span>PrivateKey = c_private.key<\/span><\/span>\n<span class=\"giallo-l\"><span>Address = 192.168.1.2<\/span><\/span>\n<span class=\"giallo-l\"><span>DNS = 223.6.6.6<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>[Peer]<\/span><\/span>\n<span class=\"giallo-l\"><span>PublicKey = s_public.key<\/span><\/span>\n<span class=\"giallo-l\"><span>Endpoint = 233.233.233.233:6666<\/span><\/span>\n<span class=\"giallo-l\"><span>AllowedIPs = 0.0.0.0\/0<\/span><\/span>\n<span class=\"giallo-l\"><span>PersistentKeepalive = 25<\/span><\/span><\/code><\/pre>\n<p>\u4e5f\u662f\u8981\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u505a\u76f8\u5e94\u7684\u4fee\u6539, \u5bc6\u94a5\u66ff\u6362\u4e3a\u5b9e\u9645\u7684\u5b57\u7b26\u4e32<\/p>\n<h3 id=\"qi-ta-ke-hu-duan-pei-zhi\"><a class=\"zola-anchor\" href=\"#qi-ta-ke-hu-duan-pei-zhi\" aria-label=\"Anchor link for: qi-ta-ke-hu-duan-pei-zhi\">\u5176\u4ed6\u5ba2\u6237\u7aef\u914d\u7f6e<\/a><\/h3>\n<p>\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u5728\u547d\u4ee4\u884c\u751f\u6210\u4e8c\u7ef4\u7801, \u65b9\u4fbf\u624b\u673a\u626b\u63cf<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>qrencode -t ansiutf8 &lt; client.conf<\/span><\/span><\/code><\/pre>"},{"title":"Redis \u67e5\u8be2\u5076\u5c14\u8d85\u65f6\u95ee\u9898\u6392\u67e5","published":"2022-10-28T14:54:14+09:00","updated":"2022-10-28T14:54:14+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/redis-troubleshooting\/"}},"id":"https:\/\/memwey.github.io\/posts\/redis-troubleshooting\/","content":"<h2 id=\"biao-xian\"><a class=\"zola-anchor\" href=\"#biao-xian\" aria-label=\"Anchor link for: biao-xian\">\u8868\u73b0<\/a><\/h2>\n<p>\u4e1a\u52a1\u4e0a Redis \u505a\u53bb\u91cd\u4f7f\u7528, \u91cf\u5927\u4f46\u662f\u64cd\u4f5c\u7b80\u5355, \u8d85\u65f6\u5747\u8bbe\u7f6e\u4e3a 10ms, \u5076\u5c14\u6709\u8d85\u65f6\u60c5\u51b5\u62a5\u9519, \u8d85\u65f6\u9519\u8bef\u5206\u5e03\u4e0e\u4e1a\u52a1\u6d41\u91cf\u6b63\u76f8\u5173. Redis \u7531 <code>AWS<\/code> \u7684 <code>ElasticCache<\/code> \u670d\u52a1\u63d0\u4f9b. \u5176\u4e2d\u5178\u578b\u64cd\u4f5c\u5982\u4e0b<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>SET key value expiration<\/span><\/span>\n<span class=\"giallo-l\"><span>GET key<\/span><\/span>\n<span class=\"giallo-l\"><span>MGET key1 key2 ...<\/span><\/span><\/code><\/pre><h2 id=\"redis-ke-hu-duan-ce-shi-shu-ju\"><a class=\"zola-anchor\" href=\"#redis-ke-hu-duan-ce-shi-shu-ju\" aria-label=\"Anchor link for: redis-ke-hu-duan-ce-shi-shu-ju\">Redis \u5ba2\u6237\u7aef\u6d4b\u8bd5\u6570\u636e<\/a><\/h2>\n<h3 id=\"latency-history\"><a class=\"zola-anchor\" href=\"#latency-history\" aria-label=\"Anchor link for: latency-history\">latency-history<\/a><\/h3>\n<p><code>Redis<\/code> \u7684 <code>latency-history<\/code> \u9009\u9879\u5c06 <code>PING<\/code> \u547d\u4ee4\u53d1\u9001\u5230 <code>Redis<\/code> \u5b9e\u4f8b, \u5e76\u6d4b\u91cf\u54cd\u5e94\u65f6\u95f4, \u7edf\u8ba1\u65f6\u95f4\u4ee5\u6beb\u79d2\u4e3a\u5355\u4f4d.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span># date<\/span><\/span>\n<span class=\"giallo-l\"><span>Fri Oct 28 10:49:58 JST 2022<\/span><\/span>\n<span class=\"giallo-l\"><span># redis-cli -h {host} -p {port} --latency-history -i 5<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 5, avg: 1.92 (418 samples) -- 5.00 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 5, avg: 1.93 (418 samples) -- 5.01 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 5, avg: 1.93 (417 samples) -- 5.00 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 7, avg: 1.98 (416 samples) -- 5.01 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 4, avg: 1.94 (417 samples) -- 5.00 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 3, avg: 1.93 (418 samples) -- 5.01 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 3, avg: 1.92 (418 samples) -- 5.00 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 3, avg: 1.94 (418 samples) -- 5.01 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 3, avg: 1.95 (418 samples) -- 5.01 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 17, avg: 2.08 (412 samples) -- 5.01 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 5, avg: 2.00 (416 samples) -- 5.01 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 4, avg: 1.94 (417 samples) -- 5.00 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 5, avg: 1.89 (418 samples) -- 5.01 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 3, avg: 1.91 (418 samples) -- 5.01 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 13, avg: 2.01 (415 samples) -- 5.01 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 12, avg: 2.12 (411 samples) -- 5.01 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 5, avg: 1.96 (416 samples) -- 5.00 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 8, avg: 2.07 (413 samples) -- 5.01 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 7, avg: 1.97 (415 samples) -- 5.00 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 5, avg: 1.93 (417 samples) -- 5.00 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 8, avg: 1.99 (416 samples) -- 5.01 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 6, avg: 2.04 (413 samples) -- 5.00 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 1, max: 3, avg: 2.03 (79 samples)^C<\/span><\/span>\n<span class=\"giallo-l\"><span># date<\/span><\/span>\n<span class=\"giallo-l\"><span>Fri Oct 28 10:52:16 JST 2022<\/span><\/span><\/code><\/pre>\n<p>\u53ef\u4ee5\u770b\u5230, \u5bf9\u4e8e <code>PING<\/code> \u8fd9\u6837\u53ef\u4ee5\u8bf4\u6ca1\u6709\u4efb\u4f55\u6027\u80fd\u8d1f\u62c5\u7684\u547d\u4ee4, \u4f9d\u7136\u6709\u5c11\u6570\u60c5\u51b5\u54cd\u5e94\u65f6\u95f4\u5927\u4e8e 10ms<\/p>\n<h3 id=\"shi-yong-benchmark-ce-shi-jian-dan-cao-zuo\"><a class=\"zola-anchor\" href=\"#shi-yong-benchmark-ce-shi-jian-dan-cao-zuo\" aria-label=\"Anchor link for: shi-yong-benchmark-ce-shi-jian-dan-cao-zuo\">\u4f7f\u7528 benchmark \u6d4b\u8bd5\u7b80\u5355\u64cd\u4f5c<\/a><\/h3>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span># redis-benchmark -h {host} -t set,get -c 50 -d 64<\/span><\/span>\n<span class=\"giallo-l\"><span>====== SET ======<\/span><\/span>\n<span class=\"giallo-l\"><span>  100000 requests completed in 4.51 seconds<\/span><\/span>\n<span class=\"giallo-l\"><span>  50 parallel clients<\/span><\/span>\n<span class=\"giallo-l\"><span>  64 bytes payload<\/span><\/span>\n<span class=\"giallo-l\"><span>  keep alive: 1<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>0.00% &lt;= 1 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>20.53% &lt;= 2 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>95.87% &lt;= 3 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>98.53% &lt;= 4 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.24% &lt;= 5 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.72% &lt;= 6 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.75% &lt;= 7 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.75% &lt;= 8 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.76% &lt;= 9 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.80% &lt;= 10 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.85% &lt;= 11 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.92% &lt;= 12 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.98% &lt;= 13 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>100.00% &lt;= 13 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>22187.71 requests per second<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>====== GET ======<\/span><\/span>\n<span class=\"giallo-l\"><span>  100000 requests completed in 5.78 seconds<\/span><\/span>\n<span class=\"giallo-l\"><span>  50 parallel clients<\/span><\/span>\n<span class=\"giallo-l\"><span>  64 bytes payload<\/span><\/span>\n<span class=\"giallo-l\"><span>  keep alive: 1<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>0.00% &lt;= 1 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>6.49% &lt;= 2 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>76.89% &lt;= 3 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>89.58% &lt;= 4 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>94.31% &lt;= 5 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>96.33% &lt;= 6 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>97.64% &lt;= 7 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>98.36% &lt;= 8 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>98.77% &lt;= 9 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.01% &lt;= 10 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.22% &lt;= 11 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.39% &lt;= 12 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.51% &lt;= 13 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.64% &lt;= 14 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.67% &lt;= 15 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.77% &lt;= 16 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.81% &lt;= 17 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.84% &lt;= 18 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.86% &lt;= 19 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.90% &lt;= 20 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.91% &lt;= 21 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.93% &lt;= 22 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.94% &lt;= 23 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.95% &lt;= 24 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.95% &lt;= 36 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.96% &lt;= 37 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.97% &lt;= 38 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.98% &lt;= 39 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.99% &lt;= 40 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.99% &lt;= 41 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>100.00% &lt;= 42 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>100.00% &lt;= 42 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>17310.02 requests per second<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span># date<\/span><\/span>\n<span class=\"giallo-l\"><span>Fri Oct 28 11:20:23 JST 2022<\/span><\/span><\/code><\/pre>\n<p>\u5bf9\u4e8e\u7b80\u5355\u64cd\u4f5c\u7684\u60c5\u51b5, \u4e24\u4e2a 9 \u7684\u6570\u636e\u53ef\u4ee5\u5728 10ms \u4ee5\u5185, \u4f46\u662f\u6027\u80fd\u4ecd\u7136\u4e0d\u5bf9, \u9884\u671f\u64cd\u4f5c\u5728\u6beb\u79d2\u4ee5\u5185\u624d\u662f <code>Redis<\/code> \u6b63\u5e38\u7684\u8868\u73b0.<\/p>\n<h3 id=\"shi-yong-bigkeys-jian-cha-key-qing-kuang\"><a class=\"zola-anchor\" href=\"#shi-yong-bigkeys-jian-cha-key-qing-kuang\" aria-label=\"Anchor link for: shi-yong-bigkeys-jian-cha-key-qing-kuang\">\u4f7f\u7528 bigkeys \u68c0\u67e5 Key \u60c5\u51b5<\/a><\/h3>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span># redis-cli -h {host} --bigkeys<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span># Scanning the entire keyspace to find biggest keys as well as<\/span><\/span>\n<span class=\"giallo-l\"><span># average sizes per key type.  You can use -i 0.1 to sleep 0.1 sec<\/span><\/span>\n<span class=\"giallo-l\"><span># per 100 SCAN commands (not usually needed).<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>[00.00%] Biggest string found so far &#39;aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&#39; with 1 bytes<\/span><\/span>\n<span class=\"giallo-l\"><span>[00.00%] Biggest string found so far &#39;aaaaaaaaaaaaaaaaaaa&#39; with 644 bytes<\/span><\/span>\n<span class=\"giallo-l\"><span>[00.00%] Biggest string found so far &#39;aaaaaaaaaaaaaaaaaaa&#39; with 664 bytes<\/span><\/span>\n<span class=\"giallo-l\"><span>[00.05%] Biggest string found so far &#39;aaaaaaaaaaaaaaaaaaaa&#39; with 668 bytes<\/span><\/span>\n<span class=\"giallo-l\"><span>[00.29%] Biggest string found so far &#39;aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&#39; with 1312 bytes<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>-------- summary -------<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>Sampled 269241 keys in the keyspace!<\/span><\/span>\n<span class=\"giallo-l\"><span>Total key length in bytes is 11026631 (avg len 40.95)<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>Biggest string found &#39;aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&#39; has 1312 bytes<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>0 lists with 0 items (00.00% of keys, avg size 0.00)<\/span><\/span>\n<span class=\"giallo-l\"><span>0 hashs with 0 fields (00.00% of keys, avg size 0.00)<\/span><\/span>\n<span class=\"giallo-l\"><span>269241 strings with 45265771 bytes (100.00% of keys, avg size 168.12)<\/span><\/span>\n<span class=\"giallo-l\"><span>0 streams with 0 entries (00.00% of keys, avg size 0.00)<\/span><\/span>\n<span class=\"giallo-l\"><span>0 sets with 0 members (00.00% of keys, avg size 0.00)<\/span><\/span>\n<span class=\"giallo-l\"><span>0 zsets with 0 members (00.00% of keys, avg size 0.00)<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span># date<\/span><\/span>\n<span class=\"giallo-l\"><span>Fri Oct 28 11:33:23 JST 2022<\/span><\/span><\/code><\/pre>\n<p>Key \u6574\u4f53\u5206\u5e03\u5747\u5300, \u6ca1\u6709\u7279\u522b\u5927\u7684 Key \u7684\u60c5\u51b5.<\/p>\n<h2 id=\"ya-ma-xun-shi-li-shu-ju\"><a class=\"zola-anchor\" href=\"#ya-ma-xun-shi-li-shu-ju\" aria-label=\"Anchor link for: ya-ma-xun-shi-li-shu-ju\">\u4e9a\u9a6c\u900a\u5b9e\u4f8b\u6570\u636e<\/a><\/h2>\n<h3 id=\"slowlog-dian-xing-an-li\"><a class=\"zola-anchor\" href=\"#slowlog-dian-xing-an-li\" aria-label=\"Anchor link for: slowlog-dian-xing-an-li\">slowlog \u5178\u578b\u6848\u4f8b<\/a><\/h3>\n<p>\u6765\u81eaRedis \u7684 <code>SLOWLOG<\/code> \u547d\u4ee4\u8131\u654f\u5904\u7406<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>{<\/span><\/span>\n<span class=\"giallo-l\"><span>    &quot;CacheClusterId&quot;: &quot;prod-rate-redis-001&quot;,<\/span><\/span>\n<span class=\"giallo-l\"><span>    &quot;CacheNodeId&quot;: &quot;0001&quot;,<\/span><\/span>\n<span class=\"giallo-l\"><span>    &quot;Id&quot;: 592,<\/span><\/span>\n<span class=\"giallo-l\"><span>    &quot;Timestamp&quot;: 1666749122,<\/span><\/span>\n<span class=\"giallo-l\"><span>    &quot;Duration (us)&quot;: 18331,<\/span><\/span>\n<span class=\"giallo-l\"><span>    &quot;Command&quot;: &quot;get ... (1 more arguments)&quot;,<\/span><\/span>\n<span class=\"giallo-l\"><span>    &quot;ClientAddress&quot;: &quot;172.22.20.210:46370&quot;<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre><h3 id=\"ke-hu-duan-ce-shi-shi-cpu-zhi-biao\"><a class=\"zola-anchor\" href=\"#ke-hu-duan-ce-shi-shi-cpu-zhi-biao\" aria-label=\"Anchor link for: ke-hu-duan-ce-shi-shi-cpu-zhi-biao\">\u5ba2\u6237\u7aef\u6d4b\u8bd5\u65f6 CPU \u6307\u6807<\/a><\/h3>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/redis-troubleshooting\/images\/pic1.png\" alt=\"pic1\" \/><\/p>\n<p>\u4e24\u4e2a\u9ad8\u5cf0\u5206\u522b\u662f <code>benchmark<\/code> \u548c <code>bigkey<\/code> \u64cd\u4f5c\u5f15\u8d77.<\/p>\n<h3 id=\"wang-luo-zhi-biao\"><a class=\"zola-anchor\" href=\"#wang-luo-zhi-biao\" aria-label=\"Anchor link for: wang-luo-zhi-biao\">\u7f51\u7edc\u6307\u6807<\/a><\/h3>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/redis-troubleshooting\/images\/pic2.png\" alt=\"pic2\" \/><\/p>\n<p>\u53ef\u4ee5\u770b\u5230, <code>Redis<\/code> \u7f51\u7edc\u6570\u636e\u901f\u5ea6\u6bcf\u9694\u4e00\u5c0f\u65f6\u4f1a\u6709\u4e00\u4e2a\u7a81\u589e.<\/p>\n<h2 id=\"fen-xi\"><a class=\"zola-anchor\" href=\"#fen-xi\" aria-label=\"Anchor link for: fen-xi\">\u5206\u6790<\/a><\/h2>\n<p><code>Redis<\/code> \u5b9e\u4f8b\u662f\u6709\u95ee\u9898\u7684, \u7b80\u5355\u64cd\u4f5c\u8017\u65f6\u4e0d\u80fd\u5728 1ms \u5185\u8fd4\u56de, 99 \u5206\u4f4d\u5728 10ms, \u660e\u663e\u4e0d\u662f\u4e00\u4e2a\u5185\u5b58\u578b\u6570\u636e\u5e93\u5e94\u6709\u7684\u6027\u80fd.<\/p>\n<p>\u7531\u4e8e\u5728\u6027\u80fd\u6307\u6807\u4e0a\u4e00\u76f4\u770b\u5230 <code>Redis<\/code> \u7684 CPU \u4f7f\u7528\u7387\u4e0d\u9ad8, \u5bfc\u81f4\u4e86\u9519\u8bef\u7684\u6392\u67e5\u65b9\u5411, \u4ee5\u4e3a\u662f\u6211\u4eec\u5728\u4f7f\u7528\u4e0a\u6709\u95ee\u9898. \u5b9e\u9645\u4e0a, \u95ee\u9898\u51fa\u5728 <code>aws<\/code> \u7684\u5b9e\u4f8b\u4e0a.<\/p>\n<p><code>aws<\/code> \u7684 t2 \u7684\u5b9e\u4f8b\u4ee5 20% \u4e3a\u6027\u80fd\u57fa\u51c6, \u4f4e\u4e8e 20% \u7d2f\u8ba1\u79ef\u5206, \u5176\u4e2d\u79ef\u5206\u7d2f\u8ba1\u6709\u4e0a\u9650; \u8d85\u8fc7 20% \u51cf\u5c11\u79ef\u5206\u76f4\u81f3\u8017\u5c3d; \u79ef\u5206\u662f\u4ee5\u5c0f\u65f6\u4e3a\u5355\u4f4d\u79ef\u7d2f\u7684. \u867d\u7136\u6ca1\u6709\u5177\u4f53\u7684\u8bf4\u660e, \u5b9e\u9645\u4e0a t2 \u5b9e\u4f8b\u7684\u7f51\u7edc\u5e26\u5bbd\u4e5f\u662f\u6709\u76f8\u5e94\u7684\u79ef\u5206\u9650\u5236\u7684, \u6240\u4ee5\u4f53\u73b0\u5728\u7f51\u7edc\u6307\u6807\u4e0a, \u6bcf\u9694\u4e00\u4e2a\u5c0f\u65f6\u51fa\u73b0\u4e00\u4e2a\u7279\u522b\u7684\u6ce2\u5cf0.<\/p>\n<p>\u53e6\u5916, <code>aws<\/code> \u6807\u6ce8\u7684 t2 \u5b9e\u4f8b\u7684\u7f51\u7edc\u6027\u80fd\u662f <code>Low to Moderate<\/code>, \u867d\u7136\u6ca1\u6709\u5b98\u65b9\u7684\u89e3\u91ca, \u4f46\u662f\u6839\u636e\u7f51\u53cb\u7684\u6d4b\u8bd5, \u57fa\u672c\u4e0a\u662f 50Mbps \u5230 300Mbps. \u8fd9\u4e5f\u89e3\u91ca\u4e86\u4e3a\u4f55\u7f51\u7edc\u6307\u6807\u4e0a\u4e00\u76f4\u5728 6MB\/s \u5de6\u53f3\u4e0a\u4e0b\u6d6e\u52a8.<\/p>\n<h2 id=\"jie-lun\"><a class=\"zola-anchor\" href=\"#jie-lun\" aria-label=\"Anchor link for: jie-lun\">\u7ed3\u8bba<\/a><\/h2>\n<p>\u4f7f\u7528\u4e86 <code>aws<\/code> \u63d0\u4f9b\u7684 <code>t2.small<\/code> \u5b9e\u4f8b, \u5728 CPU \u6027\u80fd, \u7f51\u7edc\u6027\u80fd\u4e0a\u5747\u6709\u9650\u5236, \u5bfc\u81f4 <code>Redis<\/code> \u5b9e\u4f8b\u51fa\u73b0\u8d85\u65f6\u7684\u60c5\u51b5. \u9700\u8981\u63d0\u9ad8 <code>Redis<\/code> \u5b9e\u4f8b\u7684\u914d\u7f6e, \u6216\u8005\u4f7f\u7528\u81ea\u5efa <code>Redis<\/code>.<\/p>\n<p>\u8c28\u614e\u4f7f\u7528 <code>aws<\/code> \u7684\u5b9e\u4f8b\u7c7b\u578b; \u5728\u6027\u80fd\u654f\u611f\u7684\u60c5\u51b5\u4e0b, \u4e0d\u8981\u4f7f\u7528 <code>aws<\/code> \u7684 t \u7c7b\u578b\u5b9e\u4f8b, \u4e00\u65b9\u9762\u662f\u6709\u6027\u80fd\u7684\u79ef\u5206\u7684\u9650\u5236, \u53e6\u4e00\u65b9\u9762, \u4e5f\u5bb9\u6613\u78b0\u5230 <a rel=\"external\" href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/architecture\/antipatterns\/noisy-neighbor\/noisy-neighbor\">Noisy Neighbor<\/a> \u7684\u95ee\u9898.<\/p>\n<h2 id=\"can-kao-wen-dang\"><a class=\"zola-anchor\" href=\"#can-kao-wen-dang\" aria-label=\"Anchor link for: can-kao-wen-dang\">\u53c2\u8003\u6587\u6863<\/a><\/h2>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/redis.io\/docs\/reference\/optimization\/latency\/\">Diagnosing latency issues<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/xie.infoq.cn\/article\/fbd51c19883ddc1ae19fbc96b\">Redis \u4e3a\u4ec0\u4e48\u53d8\u6162\u4e86\uff1f\u4e00\u6587\u8bb2\u900f\u5982\u4f55\u6392\u67e5 Redis \u6027\u80fd\u95ee\u9898 | \u4e07\u5b57\u957f\u6587<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/developer.aliyun.com\/article\/702247\">\u5206\u6790\u7f51\u7edc\u8d85\u65f6\u95ee\u9898\u7684\u6700\u4f73\u5b9e\u8df5<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/docs.aws.amazon.com\/AmazonElastiCache\/latest\/red-ug\/TroubleshootingConnections.html\">Troubleshooting<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/azure-cache-for-redis\/cache-troubleshoot-timeouts\">Troubleshoot Azure Cache for Redis latency and timeouts<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/aws.amazon.com\/cn\/ec2\/instance-types\/\">Amazon EC2 \u5b9e\u4f8b\u7c7b\u578b<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/stackoverflow.com\/questions\/20663619\/what-does-amazon-aws-mean-by-network-performance\">What does amazon aws mean by \"network performance\"?<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.reddit.com\/r\/aws\/comments\/d35sz9\/what_does_low_to_moderate_network_peformance_for\/\">What does 'Low to Moderate' network peformance for an ElastiCache Node Type actually mean?<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/aws.amazon.com\/cn\/ec2\/instance-types\/#Burstable_Performance_Instances\">Amazon EC2 \u5b9e\u4f8b\u7c7b\u578b#\u5177\u7206\u53d1\u80fd\u529b\u7684\u5b9e\u4f8b<\/a><\/li>\n<\/ul>\n<h2 id=\"fu-jian\"><a class=\"zola-anchor\" href=\"#fu-jian\" aria-label=\"Anchor link for: fu-jian\">\u9644\u4ef6<\/a><\/h2>\n<p>qa \u73af\u5883\u4e0b\u81ea\u5efa Redis \u6027\u80fd\u6d4b\u8bd5<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span># redis-cli -h {host} -p 6379 --latency-history -i 5<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 0, max: 3, avg: 0.34 (482 samples) -- 5.00 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 0, max: 1, avg: 0.33 (482 samples) -- 5.01 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 0, max: 1, avg: 0.32 (481 samples) -- 5.00 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 0, max: 3, avg: 0.33 (481 samples) -- 5.01 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 0, max: 4, avg: 0.32 (482 samples) -- 5.01 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 0, max: 3, avg: 0.31 (483 samples) -- 5.01 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 0, max: 1, avg: 0.30 (483 samples) -- 5.01 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 0, max: 1, avg: 0.29 (483 samples) -- 5.01 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 0, max: 1, avg: 0.31 (481 samples) -- 5.00 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 0, max: 1, avg: 0.32 (481 samples) -- 5.00 seconds range<\/span><\/span>\n<span class=\"giallo-l\"><span>min: 0, max: 1, avg: 0.28 (25 samples)^C<\/span><\/span>\n<span class=\"giallo-l\"><span># date<\/span><\/span>\n<span class=\"giallo-l\"><span>Mon Oct 31 18:47:05 JST 2022<\/span><\/span><\/code><\/pre><pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span># redis-benchmark -h {host} -t set,get -c 50 -d 64<\/span><\/span>\n<span class=\"giallo-l\"><span>====== SET ======<\/span><\/span>\n<span class=\"giallo-l\"><span>  100000 requests completed in 1.36 seconds<\/span><\/span>\n<span class=\"giallo-l\"><span>  50 parallel clients<\/span><\/span>\n<span class=\"giallo-l\"><span>  64 bytes payload<\/span><\/span>\n<span class=\"giallo-l\"><span>  keep alive: 1<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>99.88% &lt;= 1 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.97% &lt;= 2 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.99% &lt;= 4 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>100.00% &lt;= 5 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>100.00% &lt;= 5 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>73313.78 requests per second<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>====== GET ======<\/span><\/span>\n<span class=\"giallo-l\"><span>  100000 requests completed in 1.30 seconds<\/span><\/span>\n<span class=\"giallo-l\"><span>  50 parallel clients<\/span><\/span>\n<span class=\"giallo-l\"><span>  64 bytes payload<\/span><\/span>\n<span class=\"giallo-l\"><span>  keep alive: 1<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>99.90% &lt;= 1 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.94% &lt;= 2 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.95% &lt;= 4 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>99.96% &lt;= 5 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>100.00% &lt;= 5 milliseconds<\/span><\/span>\n<span class=\"giallo-l\"><span>76628.36 requests per second<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span># date<\/span><\/span>\n<span class=\"giallo-l\"><span>Mon Oct 31 18:48:10 JST 2022<\/span><\/span><\/code><\/pre>\n<p>99\u5206\u4f4d 10ms -&gt; 999\u5206\u4f4d 1ms<\/p>\n<p>\u4e0d\u8fc7\u81ea\u5efa <code>Redis<\/code>, \u7531\u4e8e\u662f\u5728 <code>EC2<\/code> \u4e0a\u7684\u6258\u7ba1 Kubernetes \u96c6\u7fa4, \u4e5f\u9700\u8981\u6ce8\u610f <a rel=\"external\" href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/architecture\/antipatterns\/noisy-neighbor\/noisy-neighbor\">Noisy Neighbor<\/a> \u7684\u95ee\u9898.<\/p>\n<h2 id=\"redis-chang-jian-wen-ti-pai-cha-si-lu\"><a class=\"zola-anchor\" href=\"#redis-chang-jian-wen-ti-pai-cha-si-lu\" aria-label=\"Anchor link for: redis-chang-jian-wen-ti-pai-cha-si-lu\">Redis \u5e38\u89c1\u95ee\u9898\u6392\u67e5\u601d\u8def<\/a><\/h2>\n<p>\u9664\u4e86\u672c\u6b21\u9047\u5230\u7684\u5b9e\u4f8b\u6027\u80fd\u9650\u5236\u95ee\u9898, \u6392\u67e5 <code>Redis<\/code> \u5ef6\u8fdf\u95ee\u9898\u65f6, \u901a\u5e38\u8fd8\u53ef\u4ee5\u4ece\u4ee5\u4e0b\u51e0\u4e2a\u5e38\u89c1\u65b9\u9762\u5165\u624b<\/p>\n<h3 id=\"lian-jie-chi-wen-ti\"><a class=\"zola-anchor\" href=\"#lian-jie-chi-wen-ti\" aria-label=\"Anchor link for: lian-jie-chi-wen-ti\">\u8fde\u63a5\u6c60\u95ee\u9898<\/a><\/h3>\n<p>Redis \u914d\u7f6e\u8fde\u63a5\u6c60\u7684\u91cd\u8981\u53c2\u6570 <code>MaxIdleOpen<\/code>, <code>IdleCloseTimeout<\/code>, \u914d\u7f6e\u4e0d\u5f53\u65f6, \u67e5\u770b\u7aef\u53e3\u5360\u7528\u4f1a\u6709\u5927\u91cf <code>TIME_WAIT<\/code>, <code>TCP<\/code> \u7684\u65ad\u5f00\u4f1a\u6709 2<a rel=\"external\" href=\"https:\/\/stackoverflow.com\/questions\/289194\/what-is-maximum-segment-lifetime-msl-in-tcp\">MSL<\/a> - MSL \u5728 Linux \u9ed8\u8ba4 60s; \u9002\u5f53\u914d\u7f6e keep-alive\n<img src=\"https:\/\/memwey.github.io\/posts\/redis-troubleshooting\/images\/tcp_open_close.jpeg\" alt=\"tcp\" \/><\/p>\n<h3 id=\"big-key\"><a class=\"zola-anchor\" href=\"#big-key\" aria-label=\"Anchor link for: big-key\">Big Key<\/a><\/h3>\n<p>\u5355\u4e2a Key \u5185\u5bb9\u8fc7\u5927, \u5355\u7ebf\u7a0b\u7279\u6027, \u53ef\u80fd\u963b\u585e\u6574\u4e2a\u670d\u52a1<\/p>\n<h3 id=\"hao-shi-cao-zuo\"><a class=\"zola-anchor\" href=\"#hao-shi-cao-zuo\" aria-label=\"Anchor link for: hao-shi-cao-zuo\">\u8017\u65f6\u64cd\u4f5c<\/a><\/h3>\n<p>O(N)\u64cd\u4f5c, <code>KEYS<\/code>, <code>SORT<\/code>, <code>LINDEX<\/code><\/p>\n<h3 id=\"tong-shi-chao-shi\"><a class=\"zola-anchor\" href=\"#tong-shi-chao-shi\" aria-label=\"Anchor link for: tong-shi-chao-shi\">\u540c\u65f6\u8d85\u65f6<\/a><\/h3>\n<p>\u8d85\u65f6\u6dd8\u6c70\u65b9\u5f0f - lazy, active, \u5927\u91cf (25%\u4ee5\u4e0a) Key \u540c\u65f6\u8d85\u65f6, \u7f13\u5b58\u9884\u70ed, \u8d85\u65f6\u589e\u52a0\u968f\u673a\u56e0\u5b50<\/p>\n<h2 id=\"redis-fun-fact\"><a class=\"zola-anchor\" href=\"#redis-fun-fact\" aria-label=\"Anchor link for: redis-fun-fact\">Redis Fun Fact<\/a><\/h2>\n<ul>\n<li>Redis \u6ca1\u6709\"\u8bfb\u5199\"\u7684\u533a\u522b<\/li>\n<li><a rel=\"external\" href=\"http:\/\/antirez.com\/news\/109\">Redis LRU \u7684\u8fd1\u4f3c\u5b9e\u73b0<\/a><\/li>\n<li>ziplist, \u7d27\u51d1\u7684\u5185\u5b58\u5e03\u5c40, \u7528\u4e8e\u4f18\u5316\u5b58\u50a8\u5c0f\u6570\u636e\u91cf\u7684 <code>list<\/code>, <code>hash<\/code>, <code>zset<\/code><\/li>\n<\/ul>\n"},{"title":"\u628a crontab \u4ece\u65f6\u95f4\u70b9\u53d8\u6210\u65f6\u95f4\u6bb5","published":"2022-09-11T15:42:08+09:00","updated":"2022-09-11T15:42:08+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/cron-from-moment-to-range\/"}},"id":"https:\/\/memwey.github.io\/posts\/cron-from-moment-to-range\/","content":"<h2 id=\"cong-yi-ge-cu-xiao-xu-qiu-shuo-qi\"><a class=\"zola-anchor\" href=\"#cong-yi-ge-cu-xiao-xu-qiu-shuo-qi\" aria-label=\"Anchor link for: cong-yi-ge-cu-xiao-xu-qiu-shuo-qi\">\u4ece\u4e00\u4e2a\u4fc3\u9500\u9700\u6c42\u8bf4\u8d77<\/a><\/h2>\n<p>\u4e1a\u52a1\u4e0a\u8981\u652f\u6301\u8fd9\u6837\u7684\u89c4\u5219:<\/p>\n<ul>\n<li>\u6bcf\u6708 29 \u65e5, \u8089\u7c7b\u534a\u4ef7<\/li>\n<li>\u6bcf\u5468\u4e94\u665a\u4e0a\u5341\u70b9\u4ee5\u540e, \u79ef\u5206\u7ffb\u500d<\/li>\n<\/ul>\n<p>\u4e00\u5f00\u59cb\u7684\u60f3\u6cd5\u662f\u5728\u6570\u636e\u5e93\u91cc\u5efa\u51e0\u4e2a\u5b57\u6bb5: \u661f\u671f\u51e0, \u4ece\u51e0\u70b9\u5230\u51e0\u70b9, \u6bcf\u6708\u7b2c\u51e0\u5929. \u4f46\u5f88\u5feb\u5c31\u53d1\u73b0\u5b57\u6bb5\u4e0d\u591f\u7528 \u2014\u2014 \u4e0b\u4e00\u6761\u89c4\u5219\u53ef\u80fd\u662f\"\u6bcf\u6708\u6700\u540e\u4e00\u4e2a\u5468\u4e94\", \u518d\u4e0b\u4e00\u6761\u662f\"\u6bcf\u5b63\u5ea6\u7b2c\u4e00\u5929\", \u6bcf\u52a0\u4e00\u79cd\u5c31\u8981\u52a0\u5b57\u6bb5, \u6216\u8005\u52a0\u4e00\u5f20\u8868.<\/p>\n<p>\u76ef\u7740\u8fd9\u4e9b\u89c4\u5219\u770b\u4e86\u4e00\u4f1a, \u4f1a\u53d1\u73b0\u5b83\u4eec\u548c crontab \u957f\u5f97\u5f88\u50cf. \"\u6bcf\u5468\u4e94 22 \u70b9\"\u5c31\u662f <code>0 22 * * 5<\/code>, \"\u6bcf\u6708 29 \u65e5\u96f6\u70b9\"\u5c31\u662f <code>0 0 29 * *<\/code>. crontab \u672c\u6765\u5c31\u662f\u4e3a\u4e86\u63cf\u8ff0\"\u5468\u671f\u6027\u5730\u5728\u4ec0\u4e48\u65f6\u5019\"\u800c\u8bbe\u8ba1\u7684, \u800c\u4e14\u5b83\u5df2\u7ecf\u5b58\u5728\u51e0\u5341\u5e74, \u6240\u6709\u5de5\u7a0b\u5e08\u90fd\u8ba4\u8bc6, \u73b0\u6210\u7684\u89e3\u6790\u5e93\u5230\u5904\u90fd\u662f.<\/p>\n<p>\u5dee\u7684\u53ea\u6709\u4e00\u70b9: <strong>crontab \u63cf\u8ff0\u7684\u662f\u65f6\u95f4\u70b9, \u800c\u6211\u4eec\u9700\u8981\u7684\u662f\u65f6\u95f4\u6bb5<\/strong>.<\/p>\n<p>\u8865\u4e0a\u8fd9\u4e00\u70b9\u5176\u5b9e\u5f88\u7b80\u5355 \u2014\u2014 \u7ed9 cron \u8868\u8fbe\u5f0f\u52a0\u4e00\u4e2a\"\u6301\u7eed\u591a\u4e45\":<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>cron \u8868\u8fbe\u5f0f  +  \u65f6\u957f  =  \u5468\u671f\u6027\u7684\u65f6\u95f4\u6bb5<\/span><\/span><\/code><\/pre><h2 id=\"cronrange\"><a class=\"zola-anchor\" href=\"#cronrange\" aria-label=\"Anchor link for: cronrange\">cronrange<\/a><\/h2>\n<p>\u8fd9\u4e2a\u60f3\u6cd5\u5df2\u7ecf\u6709\u4eba\u505a\u4e86, <a rel=\"external\" href=\"https:\/\/github.com\/1set\/cronrange\">1set\/cronrange<\/a>. \u8868\u8fbe\u5f0f\u957f\u8fd9\u6837:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>DR=120; TZ=Asia\/Tokyo; 0 22 * * 5<\/span><\/span><\/code><\/pre>\n<p>\u5206\u53f7\u9694\u5f00\u7684\u4e09\u6bb5:<\/p>\n<ul>\n<li><code>DR=120<\/code> \u662f\u65f6\u957f, \u5355\u4f4d\u5206\u949f;<\/li>\n<li><code>TZ=Asia\/Tokyo<\/code> \u662f\u65f6\u533a, \u53ef\u9009, \u7528 IANA \u65f6\u533a\u6570\u636e\u5e93\u91cc\u7684\u540d\u5b57;<\/li>\n<li><code>0 22 * * 5<\/code> \u662f cron \u8868\u8fbe\u5f0f, \u8868\u793a\u65f6\u95f4\u6bb5\u7684<strong>\u8d77\u70b9<\/strong>.<\/li>\n<\/ul>\n<p>\u5f00\u5934\u90a3\u4e24\u6761\u89c4\u5219\u5c31\u6210\u4e86:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>\u6bcf\u6708 29 \u65e5\u5168\u5929\u8089\u7c7b\u534a\u4ef7        DR=1440; TZ=Asia\/Tokyo; 0 0 29 * *<\/span><\/span>\n<span class=\"giallo-l\"><span>\u6bcf\u5468\u4e94 22 \u70b9\u8d77\u4e24\u5c0f\u65f6\u53cc\u500d\u79ef\u5206   DR=120;  TZ=Asia\/Tokyo; 0 22 * * 5<\/span><\/span><\/code><\/pre>\n<p>\u597d\u5904\u5f88\u76f4\u63a5: \u4e00\u6761\u89c4\u5219\u5c31\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32. \u6570\u636e\u5e93\u91cc\u4e00\u4e2a varchar \u5c31\u5b58\u4e0b\u4e86, \u4e0d\u7528\u4e3a\u4e86\u65b0\u89c4\u5219\u6539\u8868\u7ed3\u6784; \u8d70 JSON \u4e5f\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32, \u8fd9\u4e2a\u5e93\u5b9e\u73b0\u4e86 <code>MarshalJSON<\/code> \/ <code>UnmarshalJSON<\/code>, \u5e8f\u5217\u5316\u7684\u4e8b\u60c5\u4e0d\u7528\u81ea\u5df1\u5199.<\/p>\n<p>\u65f6\u533a\u90a3\u4e00\u6bb5\u503c\u5f97\u5355\u72ec\u8bf4\u4e00\u53e5. \"\u6bcf\u5468\u4e94\u665a\u4e0a\u5341\u70b9\"\u662f\u8c01\u7684\u5341\u70b9? \u670d\u52a1\u5668\u6240\u5728\u65f6\u533a, \u8fd8\u662f\u95e8\u5e97\u6240\u5728\u65f6\u533a? \u8fd9\u4e2a\u95ee\u9898\u5728\u53ea\u6709\u4e00\u4e2a\u56fd\u5bb6\u7684\u65f6\u5019\u53ef\u4ee5\u7cca\u5f04\u8fc7\u53bb, \u6709\u4e86\u7b2c\u4e8c\u4e2a\u56fd\u5bb6\u5c31\u5fc5\u987b\u56de\u7b54. \u8868\u8fbe\u5f0f\u91cc\u5e26\u4e0a\u65f6\u533a, \u7b49\u4e8e\u5f3a\u8feb\u914d\u7f6e\u7684\u4eba\u5f53\u573a\u60f3\u6e05\u695a.<\/p>\n<h2 id=\"wo-men-de-yong-fa-shi-fan-guo-lai-de\"><a class=\"zola-anchor\" href=\"#wo-men-de-yong-fa-shi-fan-guo-lai-de\" aria-label=\"Anchor link for: wo-men-de-yong-fa-shi-fan-guo-lai-de\">\u6211\u4eec\u7684\u7528\u6cd5\u662f\u53cd\u8fc7\u6765\u7684<\/a><\/h2>\n<p>\u8fd9\u662f\u6211\u89c9\u5f97\u6700\u503c\u5f97\u8bf4\u7684\u4e00\u70b9.<\/p>\n<p>\u5927\u90e8\u5206 cron \u5e93\u662f\u4e3a<strong>\u8c03\u5ea6<\/strong>\u5199\u7684, \u6838\u5fc3\u65b9\u6cd5\u662f\"\u4e0b\u4e00\u6b21\u662f\u4ec0\u4e48\u65f6\u5019\" \u2014\u2014 \u4f60\u6ce8\u518c\u4e00\u4e2a\u4efb\u52a1, \u5e93\u6765\u8d1f\u8d23\u5728\u6b63\u786e\u7684\u65f6\u523b\u53eb\u9192\u4f60. cronrange \u91cc\u5bf9\u5e94\u7684\u662f <code>NextOccurrences()<\/code>.<\/p>\n<p>\u800c\u6211\u4eec\u8981\u7684\u662f\u76f8\u53cd\u7684\u65b9\u5411: <strong>\u7ed9\u5b9a\u4e00\u4e2a\u65f6\u523b, \u5224\u65ad\u5b83\u843d\u4e0d\u843d\u5728\u67d0\u4e2a\u65f6\u95f4\u6bb5\u91cc<\/strong>. \u4e00\u7b14\u4ea4\u6613\u8fdb\u6765, \u5e26\u7740\u81ea\u5df1\u7684\u65f6\u95f4\u6233, \u8981\u5224\u65ad\u9002\u7528\u54ea\u4e9b\u89c4\u5219. \u5bf9\u5e94\u7684\u65b9\u6cd5\u662f <code>IsWithin()<\/code>.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span>cr<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> cronrange<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">ParseString<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span class=\"z-l-2 z-d-6\">DR=120; TZ=Asia\/Tokyo; 0 22 * * 5<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">if<\/span><span> cr<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">IsWithin<\/span><span>(<\/span><span>order<\/span><span>.<\/span><span>PaidAt<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">    \/\/<\/span><span class=\"z-l-5 z-d-3\"> \u53cc\u500d\u79ef\u5206<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u6ce8\u610f\u8fd9\u91cc\u4f20\u7684\u662f <code>order.PaidAt<\/code>, \u4e0d\u662f <code>time.Now()<\/code>. \u8fd9\u4e00\u70b9\u5f88\u91cd\u8981 \u2014\u2014 \u8865\u5355, \u91cd\u7b97, \u5bf9\u8d26\u90fd\u8981\u7528\u5386\u53f2\u65f6\u95f4. \u5982\u679c\u5224\u65ad\u4f9d\u8d56\"\u73b0\u5728\", \u90a3\u9694\u5929\u91cd\u8dd1\u4e00\u904d\u5f97\u5230\u7684\u7ed3\u679c\u5c31\u548c\u5f53\u65f6\u4e0d\u4e00\u6837, \u5728\u548c\u94b1\u6709\u5173\u7684\u7cfb\u7edf\u91cc\u8fd9\u662f\u4e0d\u80fd\u63a5\u53d7\u7684. \u6240\u4ee5\u8fd9\u7c7b\u63a5\u53e3\u4e00\u5b9a\u8981\u80fd\u4f20\u5165\u4efb\u610f\u65f6\u523b, \u800c\u4e0d\u662f\u628a <code>now<\/code> \u85cf\u5728\u91cc\u9762.<\/p>\n<p>\u540c\u4e00\u4e2a\u8868\u8fbe\u5f0f, \u8c03\u5ea6\u5668\u62ff\u53bb\u5f80\u524d\u63a8, \u6211\u4eec\u62ff\u6765\u5f80\u56de\u67e5, \u65b9\u5411\u6b63\u597d\u76f8\u53cd.<\/p>\n<h2 id=\"iswithin-shi-zen-me-shi-xian-de\"><a class=\"zola-anchor\" href=\"#iswithin-shi-zen-me-shi-xian-de\" aria-label=\"Anchor link for: iswithin-shi-zen-me-shi-xian-de\">IsWithin \u662f\u600e\u4e48\u5b9e\u73b0\u7684<\/a><\/h2>\n<p>\u8fd9\u91cc\u6709\u4e2a\u6709\u610f\u601d\u7684\u5730\u65b9: <code>cron.Schedule<\/code> \u53ea\u63d0\u4f9b <code>Next()<\/code>, \u6ca1\u6709 <code>Prev()<\/code>. \u4f60\u6ca1\u6cd5\u76f4\u63a5\u95ee\"\u4e0a\u4e00\u6b21\u662f\u4ec0\u4e48\u65f6\u5019\".<\/p>\n<p>\u6240\u4ee5\u5224\u65ad <code>t<\/code> \u5728\u4e0d\u5728\u7a97\u53e3\u91cc, \u53ea\u80fd\u5148\u5f80\u56de\u9000\u4e00\u4e2a\u65f6\u957f, \u518d\u4ece\u90a3\u91cc\u95ee\"\u4e0b\u4e00\u6b21\u662f\u4ec0\u4e48\u65f6\u5019\":<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span>searchStart<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> t<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Add<\/span><span>(<\/span><span class=\"z-l-8 z-d-10\">-<\/span><span>(<\/span><span>cr<\/span><span>.<\/span><span>duration<\/span><span class=\"z-l-8 z-d-10\"> +<\/span><span class=\"z-l-1 z-d-4\"> 1<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span>time<\/span><span>.<\/span><span>Second<\/span><span class=\"z-l-8 z-d-10\"> -<\/span><span class=\"z-l-1 z-d-4\"> 1<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span>time<\/span><span>.<\/span><span>Nanosecond<\/span><span>)<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>rangeStart<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> cr<\/span><span>.<\/span><span>schedule<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Next<\/span><span>(<\/span><span>searchStart<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>rangeEnd<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> rangeStart<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Add<\/span><span>(<\/span><span>cr<\/span><span>.<\/span><span>duration<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/\/<\/span><span class=\"z-l-5 z-d-3\"> \u68c0\u67e5 rangeStart &lt;= t &lt;= rangeEnd<\/span><\/span>\n<span class=\"giallo-l\"><span>within<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> (<\/span><span>rangeStart<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Before<\/span><span>(<\/span><span>t<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\"> &amp;&amp;<\/span><span> rangeEnd<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">After<\/span><span>(<\/span><span>t<\/span><span>)<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\"> ||<\/span><span> rangeStart<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Equal<\/span><span>(<\/span><span>t<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\"> ||<\/span><span> rangeEnd<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Equal<\/span><span>(<\/span><span>t<\/span><span>)<\/span><\/span><\/code><\/pre>\n<p>\u9000\u4e00\u4e2a <code>duration<\/code> \u662f\u4e3b\u4f53, \u540e\u9762\u90a3\u4e2a <code>+ 1s - 1ns<\/code> \u662f\u8865\u507f: <code>Next()<\/code> \u8fd4\u56de\u7684\u662f<strong>\u4e25\u683c\u665a\u4e8e<\/strong>\u7ed9\u5b9a\u65f6\u523b\u7684\u4e0b\u4e00\u6b21, \u800c\u4e14\u7cbe\u5ea6\u53ea\u5230\u79d2. \u4e0d\u591a\u9000\u8fd9\u4e00\u70b9, \u6070\u597d\u5361\u5728\u8fb9\u754c\u4e0a\u7684\u7a97\u53e3\u4f1a\u88ab\u6f0f\u6389.<\/p>\n<p>\u53e6\u5916\u8981\u6ce8\u610f\u533a\u95f4\u662f<strong>\u95ed<\/strong>\u7684, \u4e24\u7aef\u90fd\u7b97. \u62ff\"\u6bcf\u5468\u4e94 22 \u70b9\u8d77\u4e24\u5c0f\u65f6\"\u5b9e\u6d4b\u4e00\u4e0b:<\/p>\n<table><thead><tr><th>\u65f6\u523b<\/th><th>IsWithin<\/th><\/tr><\/thead><tbody>\n<tr><td>\u5468\u4e94 21:59:59<\/td><td>false<\/td><\/tr>\n<tr><td>\u5468\u4e94 22:00:00<\/td><td><strong>true<\/strong><\/td><\/tr>\n<tr><td>\u5468\u4e94 23:00:00<\/td><td>true<\/td><\/tr>\n<tr><td>\u5468\u516d 00:00:00<\/td><td><strong>true<\/strong><\/td><\/tr>\n<tr><td>\u5468\u516d 00:00:01<\/td><td>false<\/td><\/tr>\n<\/tbody><\/table>\n<p>\u4e24\u7aef\u90fd\u547d\u4e2d, \u610f\u5473\u7740\u76f8\u90bb\u7684\u4e24\u4e2a\u65f6\u95f4\u6bb5\u5728\u4ea4\u754c\u70b9\u4e0a\u4f1a\u540c\u65f6\u6210\u7acb. \u5982\u679c\u914d\u4e86\"\u4eca\u5929 0 \u70b9\u5230 24 \u70b9\"\u548c\"\u660e\u5929 0 \u70b9\u5230 24 \u70b9\"\u4e24\u6761\u89c4\u5219, \u90a3\u4e48\u6b63\u597d\u843d\u5728 <code>00:00:00<\/code> \u7684\u4e00\u7b14\u4ea4\u6613\u4e24\u6761\u90fd\u6ee1\u8db3. \u8981\u4e48\u5728\u4e1a\u52a1\u5c42\u518d\u5224\u4e00\u6b21, \u8981\u4e48\u628a\u65f6\u957f\u8bbe\u6210\u5dee\u4e00\u79d2.<\/p>\n<h2 id=\"yi-ge-bi-xu-ti-xing-yun-ying-de-keng\"><a class=\"zola-anchor\" href=\"#yi-ge-bi-xu-ti-xing-yun-ying-de-keng\" aria-label=\"Anchor link for: yi-ge-bi-xu-ti-xing-yun-ying-de-keng\">\u4e00\u4e2a\u5fc5\u987b\u63d0\u9192\u8fd0\u8425\u7684\u5751<\/a><\/h2>\n<p>\u5199\u5b8c\u4e4b\u540e\u987a\u624b\u628a\"\u6bcf\u6708 29 \u65e5\"\u7684\u672a\u6765\u51e0\u6b21\u6253\u5370\u51fa\u6765\u770b\u770b:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>[2022-01-29T00:00:00+09:00, 2022-01-30T00:00:00+09:00]<\/span><\/span>\n<span class=\"giallo-l\"><span>[2022-03-29T00:00:00+09:00, 2022-03-30T00:00:00+09:00]<\/span><\/span>\n<span class=\"giallo-l\"><span>[2022-04-29T00:00:00+09:00, 2022-04-30T00:00:00+09:00]<\/span><\/span>\n<span class=\"giallo-l\"><span>[2022-05-29T00:00:00+09:00, 2022-05-30T00:00:00+09:00]<\/span><\/span><\/code><\/pre>\n<p><strong>\u4e8c\u6708\u6ca1\u6709.<\/strong> 2022 \u5e74\u4e0d\u662f\u95f0\u5e74, \u6ca1\u6709 2 \u6708 29 \u65e5, \u6240\u4ee5\u8fd9\u6761\u89c4\u5219\u5728\u4e8c\u6708\u6574\u6708\u4e0d\u751f\u6548.<\/p>\n<p>\u8fd9\u4e0d\u662f\u5e93\u7684 bug, cron \u672c\u6765\u5c31\u662f\u8fd9\u4e2a\u8bed\u4e49. \u4f46\u914d\u89c4\u5219\u7684\u662f\u8fd0\u8425, \u4ed6\u4eec\u8bf4\"\u6bcf\u6708 29 \u65e5\"\u7684\u65f6\u5019, \u9ed8\u8ba4\u6bcf\u4e2a\u6708\u90fd\u6709 29 \u65e5. \u7c7b\u4f3c\u7684\u8fd8\u6709 31 \u65e5, \u4e00\u5e74\u91cc\u6709\u56db\u4e2a\u6708\u4e0d\u4f1a\u89e6\u53d1.<\/p>\n<p>\u6240\u4ee5\u8fd9\u91cc\u7684\u505a\u6cd5\u662f: \u4fdd\u5b58\u89c4\u5219\u7684\u65f6\u5019, \u628a\u63a5\u4e0b\u6765 12 \u6b21\u7684\u89e6\u53d1\u65f6\u95f4\u5217\u51fa\u6765\u7ed9\u4eba\u786e\u8ba4\u4e00\u904d. \u4e5f\u5c31\u662f\u8bf4, <code>NextOccurrences()<\/code> \u5728\u6211\u4eec\u7684\u7528\u6cd5\u91cc\u4e0d\u662f\u7528\u6765\u8c03\u5ea6\u7684, \u800c\u662f\u7528\u6765\u7ed9\u4eba\u9884\u89c8\u7684. \u4e00\u4e2a\u672c\u6765\u7ed9\u8c03\u5ea6\u5668\u7528\u7684\u65b9\u6cd5, \u6362\u4e2a\u573a\u666f\u6210\u4e86\u914d\u7f6e\u754c\u9762\u4e0a\u7684\u6821\u9a8c\u5de5\u5177.<\/p>\n<h2 id=\"jia-liang-jian-dong-xi\"><a class=\"zola-anchor\" href=\"#jia-liang-jian-dong-xi\" aria-label=\"Anchor link for: jia-liang-jian-dong-xi\">\u52a0\u4e24\u4ef6\u4e1c\u897f<\/a><\/h2>\n<p>\u7528\u8d77\u6765\u4e4b\u540e\u6709\u4e24\u4e2a\u5730\u65b9\u4e0d\u592a\u591f\u7528, \u4e8e\u662f\u5728 fork \u4e0a\u6539\u4e86\u6539, \u4ee3\u7801\u5728 <a rel=\"external\" href=\"https:\/\/github.com\/memwey\/cronrange\">memwey\/cronrange<\/a>.<\/p>\n<h3 id=\"shi-chang-bu-gai-zhi-you-fen-zhong\"><a class=\"zola-anchor\" href=\"#shi-chang-bu-gai-zhi-you-fen-zhong\" aria-label=\"Anchor link for: shi-chang-bu-gai-zhi-you-fen-zhong\">\u65f6\u957f\u4e0d\u8be5\u53ea\u6709\u5206\u949f<\/a><\/h3>\n<p>\u539f\u6765\u7684\u6784\u9020\u51fd\u6570\u662f\u8fd9\u6837\u7684:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span class=\"z-l-6 z-d-7\"> New<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">cronExpr<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> timeZone<\/span><span class=\"z-l-8 z-d-10\"> string<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> durationMin<\/span><span class=\"z-l-8 z-d-10\"> uint64<\/span><span>)<\/span><span> (<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-6 z-d-7\">CronRange<\/span><span>,<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span>)<\/span><\/span><\/code><\/pre>\n<p>\"\u5206\u949f\"\u88ab\u5199\u6b7b\u5728\u7c7b\u578b\u91cc\u4e86. \u8fd9\u5e26\u6765\u4e24\u4e2a\u95ee\u9898: <code>DR=90<\/code> \u5230\u5e95\u662f 90 \u5206\u949f\u8fd8\u662f 90 \u79d2, \u53ea\u80fd\u7ffb\u6587\u6863\u624d\u77e5\u9053; \u800c\u4e14\u79d2\u7ea7\u7684\u7a97\u53e3 (\u6bd4\u5982\u79d2\u6740) \u6839\u672c\u8868\u8fbe\u4e0d\u51fa\u6765.<\/p>\n<p>Go \u91cc\u672c\u6765\u5c31\u6709 <code>time.Duration<\/code> \u8fd9\u4e2a\u7c7b\u578b, \u5355\u4f4d\u662f\u81ea\u5e26\u7684, \u6ca1\u9053\u7406\u4e0d\u7528. \u4f46 <code>New<\/code> \u7684\u7b7e\u540d\u4e0d\u80fd\u6539, \u4e00\u6539\u6240\u6709\u8c03\u7528\u65b9\u90fd\u5f97\u8ddf\u7740\u6539. \u6240\u4ee5\u65b0\u5f00\u4e00\u4e2a:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">func<\/span><span class=\"z-l-6 z-d-7\"> Create<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">cronExpr<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> timeZone<\/span><span class=\"z-l-8 z-d-10\"> string<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> duration<\/span><span class=\"z-l-6 z-d-7\"> time<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Duration<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\"> cp<\/span><span class=\"z-l-6 z-d-7\"> cron<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">Parser<\/span><span>)<\/span><span> (<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-6 z-d-7\">CronRange<\/span><span>,<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span>)<\/span><\/span><\/code><\/pre><h3 id=\"cron-jie-xi-qi-yao-neng-huan\"><a class=\"zola-anchor\" href=\"#cron-jie-xi-qi-yao-neng-huan\" aria-label=\"Anchor link for: cron-jie-xi-qi-yao-neng-huan\">cron \u89e3\u6790\u5668\u8981\u80fd\u6362<\/a><\/h3>\n<p>robfig\/cron \u7684\u89e3\u6790\u884c\u4e3a\u662f\u5728\u6784\u9020 <code>Parser<\/code> \u7684\u65f6\u5019\u5b9a\u6b7b\u7684: \u662f\u4e94\u4e2a\u5b57\u6bb5\u8fd8\u662f\u516d\u4e2a\u5b57\u6bb5 (\u5e26\u79d2), \u652f\u4e0d\u652f\u6301 <code>@every<\/code> \u8fd9\u7c7b\u63cf\u8ff0\u7b26. \u800c\u5e93\u91cc\u539f\u672c\u5199\u6b7b\u4e86\u4e00\u4e2a\u5305\u7ea7\u7684 parser.<\/p>\n<p>\u4e0d\u540c\u9879\u76ee\u5bf9 cron \u65b9\u8a00\u7684\u8981\u6c42\u5e76\u4e0d\u4e00\u6837, \u5c24\u5176\u662f\u9700\u8981\u79d2\u7ea7\u7cbe\u5ea6\u7684\u65f6\u5019. \u4e0e\u5176\u5728\u5e93\u91cc\u591a\u52a0\u51e0\u4e2a\u5f00\u5173, \u4e0d\u5982\u628a <code>Parser<\/code> \u76f4\u63a5\u4f5c\u4e3a\u53c2\u6570\u4f20\u8fdb\u6765, \u8ba9\u4f7f\u7528\u8005\u81ea\u5df1\u51b3\u5b9a.<\/p>\n<p>\u4e0d\u8fc7\u5149\u6709 <code>Create()<\/code> \u8fd8\u4e0d\u591f. \u8fd9\u4e2a\u5e93\u7684\u7528\u6cd5\u524d\u63d0\u662f\u89c4\u5219\u4ee5\u5b57\u7b26\u4e32\u7684\u5f62\u5f0f\u5b58\u8d77\u6765, \u6240\u4ee5\u9664\u4e86\u6784\u9020, \u8fd8\u5f97\u80fd\u8bfb\u56de\u6765 \u2014\u2014 \u800c <code>ParseString()<\/code> \u7528\u7684\u662f\u5199\u6b7b\u7684\u5305\u7ea7 parser. \u53ea\u52a0 <code>Create()<\/code> \u7684\u8bdd, \u81ea\u5b9a\u4e49 parser \u5c31\u53ea\u80fd\u7528\u4e00\u534a: \u9020\u5f97\u51fa\u6765, \u5b58\u5f97\u8fdb\u53bb, \u8bfb\u4e0d\u56de\u6765.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>String()                          = &quot;DR=3s; TZ=Asia\/Tokyo; *\/10 * * * * *&quot;<\/span><\/span>\n<span class=\"giallo-l\"><span>ParseString(s)                    -&gt; expected exactly 5 fields, found 6<\/span><\/span>\n<span class=\"giallo-l\"><span>ParseStringWithCronParser(s, sec) -&gt; ok<\/span><\/span><\/code><\/pre>\n<p>\u6240\u4ee5\u914d\u5957\u52a0\u4e86 <code>ParseStringWithCronParser()<\/code>, \u628a\u8fd9\u4e2a\u5f80\u8fd4\u95ed\u5408\u4e0a.<\/p>\n<h2 id=\"ma-fan-de-shi-ge-shi\"><a class=\"zola-anchor\" href=\"#ma-fan-de-shi-ge-shi\" aria-label=\"Anchor link for: ma-fan-de-shi-ge-shi\">\u9ebb\u70e6\u7684\u662f\u683c\u5f0f<\/a><\/h2>\n<p>\u771f\u6b63\u82b1\u65f6\u95f4\u7684\u662f\u8fd9\u4e00\u5757.<\/p>\n<p>\u8868\u8fbe\u5f0f\u662f\u8981<strong>\u5b58\u8d77\u6765<\/strong>\u7684 \u2014\u2014 \u6570\u636e\u5e93\u91cc\u8eba\u7740\u4e00\u6279, JSON \u91cc\u4f20\u7740\u4e00\u6279. \u52a0\u4e86 <code>time.Duration<\/code> \u4e4b\u540e, <code>DR=90<\/code> \u548c <code>DR=2h<\/code> \u90fd\u5fc5\u987b\u80fd\u89e3\u6790.<\/p>\n<p>\u6309\u8bf4\u5e94\u8be5\u5728\u683c\u5f0f\u91cc\u52a0\u4e2a\u7248\u672c\u53f7, \u4f46\u90a3\u6837\u6240\u6709\u5df2\u7ecf\u5b58\u4e0b\u6765\u7684\u5b57\u7b26\u4e32\u90fd\u8981\u8fc1\u79fb. \u4e8e\u662f\u6362\u4e2a\u529e\u6cd5: <strong>\u9760\u503c\u672c\u8eab\u7684\u5f62\u72b6\u6765\u533a\u5206<\/strong>. \u7eaf\u6570\u5b57\u662f\u8001\u683c\u5f0f (\u5206\u949f), \u5e26\u5355\u4f4d\u662f\u65b0\u683c\u5f0f.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">if<\/span><span> duration<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> time<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">ParseDuration<\/span><span>(<\/span><span>durStr<\/span><span>)<\/span><span>;<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> ==<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    if<\/span><span> duration<\/span><span class=\"z-l-8 z-d-10\"> &gt;<\/span><span class=\"z-l-1 z-d-4\"> 0<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>        version<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> Version2<\/span><\/span>\n<span class=\"giallo-l\"><span>    }<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">if<\/span><span> durMin<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> strconv<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">ParseUint<\/span><span>(<\/span><span>durStr<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> 10<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> 64<\/span><span>)<\/span><span>;<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> !=<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    if<\/span><span> version<\/span><span class=\"z-l-8 z-d-10\"> !=<\/span><span> Version2<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        break<\/span><span> PL<\/span><\/span>\n<span class=\"giallo-l\"><span>    }<\/span><\/span>\n<span class=\"giallo-l\"><span>    err<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u5148\u8bd5\u65b0\u683c\u5f0f, \u4e0d\u884c\u518d\u9000\u56de\u8001\u683c\u5f0f. \u8fd9\u4e24\u8005\u6b63\u597d\u4e0d\u91cd\u53e0: <code>time.ParseDuration(\"90\")<\/code> \u4f1a\u56e0\u4e3a\u7f3a\u5355\u4f4d\u800c\u5931\u8d25, <code>strconv.ParseUint(\"1h30m\")<\/code> \u4e5f\u8fc7\u4e0d\u53bb, \u4e0d\u4f1a\u6709\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e24\u8fb9\u90fd\u8ba4.<\/p>\n<p>\u53cd\u8fc7\u6765, <code>String()<\/code> \u8be5\u8f93\u51fa\u54ea\u4e00\u79cd? \u7528\u4e00\u4e2a <code>version<\/code> \u5b57\u6bb5\u8bb0\u4f4f\u8fd9\u4e2a\u5b9e\u4f8b\u5f53\u521d\u662f\u600e\u4e48\u6765\u7684:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>New(..., 90).String()                = &quot;DR=90; TZ=Asia\/Tokyo; 0 22 * * 5&quot;<\/span><\/span>\n<span class=\"giallo-l\"><span>Create(..., 90*time.Minute).String() = &quot;DR=1h30m0s; TZ=Asia\/Tokyo; 0 22 * * 5&quot;<\/span><\/span><\/code><\/pre>\n<p>\u4e24\u8005\u7684 <code>Duration()<\/code> \u5b8c\u5168\u76f8\u7b49, \u53ea\u662f\u6253\u5370\u51fa\u6765\u4e0d\u4e00\u6837.<\/p>\n<p>\u8fd9\u4e48\u505a\u662f\u4e3a\u4e86\u4fdd\u8bc1 round-trip: \u4ece\u6570\u636e\u5e93\u8bfb\u51fa\u6765\u7684\u8001\u8868\u8fbe\u5f0f, \u89e3\u6790\u4e4b\u540e\u518d\u5199\u56de\u53bb, \u8fd8\u662f\u539f\u6765\u7684\u6837\u5b50. \u4e0d\u4f1a\u56e0\u4e3a\u67d0\u5929\u5347\u7ea7\u4e86\u4e00\u4e2a\u5e93\u7248\u672c, \u5b58\u91cf\u8bb0\u5f55\u88ab\u6084\u6084\u6539\u5199\u4e86\u4e00\u904d \u2014\u2014 \u90a3\u79cd\u4e8b\u60c5\u5728\u6392\u67e5\u95ee\u9898\u7684\u65f6\u5019\u975e\u5e38\u96be\u53d7, \u56e0\u4e3a\u4f60\u4f1a\u6000\u7591\u662f\u4e0d\u662f\u6709\u4eba\u624b\u52a8\u6539\u8fc7\u6570\u636e.<\/p>\n<h3 id=\"zhe-me-zuo-de-dai-jia\"><a class=\"zola-anchor\" href=\"#zhe-me-zuo-de-dai-jia\" aria-label=\"Anchor link for: zhe-me-zuo-de-dai-jia\">\u8fd9\u4e48\u505a\u7684\u4ee3\u4ef7<\/a><\/h3>\n<p>\u5185\u90e8\u72b6\u6001\u6cc4\u6f0f\u5230\u4e86\u8f93\u51fa\u884c\u4e3a\u4e0a. \u540c\u6837\u662f 90 \u5206\u949f, \u53ea\u56e0\u4e3a\u6765\u6e90\u4e0d\u540c, <code>String()<\/code> \u7684\u7ed3\u679c\u5c31\u4e0d\u4e00\u6837. \u5bf9\u4f7f\u7528\u8005\u6765\u8bf4\u8fd9\u662f\u4e2a\u610f\u5916.<\/p>\n<p>\u66f4\u5e72\u51c0\u7684\u505a\u6cd5\u5927\u6982\u6709\u4e24\u79cd: \u89e3\u6790\u7684\u65f6\u5019\u628a\u539f\u59cb\u6587\u672c\u8bb0\u4e0b\u6765, <code>String()<\/code> \u539f\u6837\u5410\u56de\u53bb; \u6216\u8005\u5e72\u8106\u89c4\u5b9a <code>String()<\/code> \u6c38\u8fdc\u8f93\u51fa\u65b0\u683c\u5f0f, \u5e76\u63a5\u53d7\"\u5b58\u91cf\u6570\u636e\u4f1a\u88ab\u9010\u6b65\u6539\u5199\"\u8fd9\u4ef6\u4e8b. \u4f46\u8fd9\u4e24\u79cd\u90fd\u8981\u52a8\u66f4\u591a\u5730\u65b9, \u5728\u4e00\u4e2a fork \u4e0a\u505a\u6539\u52a8, \u6211\u9009\u4e86\u4fb5\u5165\u6700\u5c0f\u7684\u90a3\u4e2a. \u8fd9\u4e2a\u53d6\u820d\u73b0\u5728\u770b\u4ecd\u7136\u6210\u7acb, \u53ea\u662f\u5e94\u8be5\u5728\u6587\u6863\u91cc\u5199\u6e05\u695a, \u800c\u4e0d\u662f\u8ba9\u4eba\u81ea\u5df1\u649e\u4e0a.<\/p>\n<h2 id=\"shun-dai-fa-xian-de-yi-ge-wen-ti\"><a class=\"zola-anchor\" href=\"#shun-dai-fa-xian-de-yi-ge-wen-ti\" aria-label=\"Anchor link for: shun-dai-fa-xian-de-yi-ge-wen-ti\">\u987a\u5e26\u53d1\u73b0\u7684\u4e00\u4e2a\u95ee\u9898<\/a><\/h2>\n<p>\u8bfb\u89e3\u6790\u4ee3\u7801\u7684\u65f6\u5019\u6ce8\u610f\u5230, \u672a\u77e5\u7684\u90e8\u5206\u5e76\u4e0d\u603b\u662f\u4f1a\u62a5\u9519:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>&quot;junk; DR=90; 0 0 1 1 *&quot;   -&gt;  \u89e3\u6790\u6210\u529f<\/span><\/span>\n<span class=\"giallo-l\"><span>&quot;DR=90; junk; 0 0 1 1 *&quot;   -&gt;  \u62a5\u9519 unknown part: &quot;junk&quot;<\/span><\/span><\/code><\/pre>\n<p>\u540c\u6837\u4e00\u4e2a <code>junk<\/code>, \u653e\u5728 <code>DR=<\/code> \u524d\u9762\u5c31\u88ab\u5403\u6389\u4e86, \u653e\u5728\u540e\u9762\u624d\u62a5\u9519.<\/p>\n<p>\u539f\u56e0\u5728\u4e0a\u9762\u90a3\u6bb5\u4ee3\u7801\u91cc: <code>DR=<\/code> \u8fd9\u4e2a\u5206\u652f\u628a\u547d\u540d\u8fd4\u56de\u503c <code>err<\/code> \u5f53\u4e2d\u95f4\u53d8\u91cf\u7528\u4e86. <code>strconv.ParseUint<\/code> \u6210\u529f\u7684\u65f6\u5019\u4f1a\u628a <code>err<\/code> \u8d4b\u6210 <code>nil<\/code>, \u800c\u524d\u4e00\u8f6e\u5faa\u73af\u91cc <code>default<\/code> \u5206\u652f\u8bbe\u7f6e\u7684\"\u672a\u77e5\u90e8\u5206\"\u9519\u8bef, \u5c31\u8fd9\u4e48\u88ab\u76d6\u6389\u4e86.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/\/<\/span><span class=\"z-l-5 z-d-3\"> \u6709\u95ee\u9898: err \u662f\u547d\u540d\u8fd4\u56de\u503c, \u8fd9\u91cc\u88ab\u7528\u6765\u63a5\u4e34\u65f6\u7ed3\u679c<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">if<\/span><span> durMin<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> strconv<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">ParseUint<\/span><span>(<\/span><span>durStr<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> 10<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> 64<\/span><span>)<\/span><span>;<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> !=<\/span><span class=\"z-l-1 z-d-4\"> nil<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/\/<\/span><span class=\"z-l-5 z-d-3\"> \u5e94\u8be5\u7528\u5c40\u90e8\u53d8\u91cf, \u6700\u540e\u518d\u51b3\u5b9a err \u662f\u4ec0\u4e48<\/span><\/span>\n<span class=\"giallo-l\"><span>n<\/span><span>,<\/span><span> parseErr<\/span><span class=\"z-l-8 z-d-10\"> :=<\/span><span> strconv<\/span><span>.<\/span><span class=\"z-l-6 z-d-7\">ParseUint<\/span><span>(<\/span><span>durStr<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> 10<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> 64<\/span><span>)<\/span><\/span><\/code><\/pre>\n<p>\u8fd9\u4e2a\u95ee\u9898\u5728\u52a0 <code>time.Duration<\/code> \u4e4b\u524d\u5c31\u6709\u4e86, \u53ea\u662f\u73b0\u5728\u591a\u4e86\u4e00\u5c42\u8bd5\u63a2, \u66f4\u5bb9\u6613\u8e29\u5230. Go \u7684\u547d\u540d\u8fd4\u56de\u503c\u672c\u6765\u5c31\u5bb9\u6613\u51fa\u8fd9\u79cd\u4e8b, \u518d\u52a0\u4e0a <code>switch<\/code> \u5404\u4e2a\u5206\u652f\u5171\u7528\u540c\u4e00\u4e2a <code>err<\/code>, \u5c31\u66f4\u4e0d\u5bb9\u6613\u770b\u51fa\u6765.<\/p>\n<h2 id=\"xiao-jie\"><a class=\"zola-anchor\" href=\"#xiao-jie\" aria-label=\"Anchor link for: xiao-jie\">\u5c0f\u7ed3<\/a><\/h2>\n<p>crontab \u7684\u8868\u8fbe\u80fd\u529b\u5927\u6982\u662f\u88ab\u4f4e\u4f30\u4e86. \u5b83\u662f\u4e00\u4e2a\u5df2\u7ecf\u5b58\u5728\u51e0\u5341\u5e74, \u6240\u6709\u5de5\u7a0b\u5e08\u90fd\u8ba4\u8bc6, \u800c\u4e14\u5230\u5904\u90fd\u6709\u73b0\u6210\u89e3\u6790\u5668\u7684\u9886\u57df\u7279\u5b9a\u8bed\u8a00. \u9700\u8981\u63cf\u8ff0\"\u5468\u671f\u6027\u7684\u65f6\u95f4\"\u7684\u65f6\u5019, \u5148\u60f3\u60f3\u80fd\u4e0d\u80fd\u7528\u5b83, \u901a\u5e38\u6bd4\u81ea\u5df1\u8bbe\u8ba1\u4e00\u5957\u5b57\u6bb5\u8981\u597d \u2014\u2014 \u81f3\u5c11\u4e0d\u7528\u4e3a\u4e86\"\u6bcf\u6708\u6700\u540e\u4e00\u4e2a\u5468\u4e94\"\u8fd9\u79cd\u9700\u6c42\u518d\u6539\u4e00\u6b21\u8868.<\/p>\n<p>\u5b83\u7f3a\u7684\u90a3\u4e00\u5757\u662f\u65f6\u957f, \u8865\u4e0a\u5c31\u80fd\u8868\u8fbe\u65f6\u95f4\u6bb5.<\/p>\n<p>\u53e6\u5916\u8981\u7559\u610f\u65b9\u5411. \u5927\u90e8\u5206 cron \u5e93\u662f\u4e3a\u8c03\u5ea6\u5199\u7684, \u5173\u5fc3\u7684\u662f\"\u4e0b\u4e00\u6b21\"; \u5982\u679c\u9700\u6c42\u662f\"\u8fd9\u4e2a\u65f6\u523b\u7b97\u4e0d\u7b97\", \u90a3\u8981\u7684\u662f\u53e6\u4e00\u4e2a\u65b9\u6cd5, \u800c\u4e14\u5fc5\u987b\u80fd\u4f20\u5165\u4efb\u610f\u65f6\u523b, \u4e0d\u80fd\u628a <code>now<\/code> \u85cf\u5728\u5b9e\u73b0\u91cc.<\/p>\n"},{"title":"Prometheus \u624b\u628a\u624b","published":"2022-05-10T16:36:07+08:00","updated":"2022-05-10T16:36:07+08:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/prometheus-hand-over-hand\/"}},"id":"https:\/\/memwey.github.io\/posts\/prometheus-hand-over-hand\/","content":"<p>\u56e0\u4e3a Prometheus \u5728\u5e94\u7528\u4e2d\u4e00\u5171\u53ea\u6709\u56db\u79cd metric \u7c7b\u578b, \u53ea\u8981\u6839\u636e\u9700\u8981\u76d1\u6d4b\u7684\u76ee\u6807\u9009\u62e9\u4e86 metrics \u7c7b\u578b, \u540e\u7eed\u7684\u544a\u8b66\u4ee5\u53ca\u53ef\u89c6\u5316\u914d\u7f6e\u5c31\u6709\u56fa\u5b9a\u7684\u5957\u8def\u4e86.<\/p>\n<h3 id=\"counter\"><a class=\"zola-anchor\" href=\"#counter\" aria-label=\"Anchor link for: counter\">Counter<\/a><\/h3>\n<p>Counter \u7528\u6765\u76d1\u63a7\u5355\u8c03\u9012\u589e\u7684\u91cf, \u5f53\u53d1\u751f\u91cd\u7f6e\u65f6 Prometheus \u4f1a\u81ea\u52a8\u5904\u7406\u5f52\u96f6\u7684\u6570\u636e. \u8fd9\u662f\u4e00\u4e2a\u975e\u5e38\u57fa\u672c\u7684\u7c7b\u578b, \u4e00\u4e2a\u7cfb\u7edf\u4e2d\u5f88\u591a\u6570\u636e\u90fd\u53ef\u4ee5\u901a\u8fc7\u6b64\u7c7b\u578b\u8fdb\u884c\u8ba1\u6570, \u6bd4\u5982\u7cfb\u7edf\u63a5\u53d7\u7684\u8bf7\u6c42\u6570, \u7cfb\u7edf\u53d1\u751f\u7684\u9519\u8bef\u6570, \u518d\u6bd4\u5982\u5bf9\u7b2c\u4e09\u65b9\u63a5\u53e3\u7684\u8c03\u7528\u6570, \u7b2c\u4e09\u65b9\u63a5\u53e3\u8fd4\u56de\u7684\u9519\u8bef\u6570.<\/p>\n<p>\u4e1a\u52a1\u4ee3\u7801\u5982\u4e0b<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"python\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">from<\/span><span> prometheus_client<\/span><span class=\"z-l-8 z-d-10\"> import<\/span><span> Counter<\/span><\/span>\n<span class=\"giallo-l\"><span>c<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> Counter<\/span><span>(<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-6\">    &#39;<\/span><span class=\"z-l-2 z-d-6\">web_request_total<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>,<\/span><span class=\"z-l-2 z-d-6\"> &#39;<\/span><span class=\"z-l-2 z-d-6\">web request total counter<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>    [<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span class=\"z-l-2 z-d-6\">method<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>,<\/span><span class=\"z-l-2 z-d-6\"> &#39;<\/span><span class=\"z-l-2 z-d-6\">endpoint<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>,<\/span><span class=\"z-l-2 z-d-6\"> &#39;<\/span><span class=\"z-l-2 z-d-6\">status_code<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>]<\/span><\/span>\n<span class=\"giallo-l\"><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>c<\/span><span>.<\/span><span>labels<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span class=\"z-l-2 z-d-6\">get<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>,<\/span><span class=\"z-l-2 z-d-6\"> &#39;<\/span><span class=\"z-l-2 z-d-6\">\/<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>,<\/span><span class=\"z-l-2 z-d-6\"> &#39;<\/span><span class=\"z-l-2 z-d-6\">200<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>)<\/span><span>.<\/span><span>inc<\/span><span>(<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>c<\/span><span>.<\/span><span>labels<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span class=\"z-l-2 z-d-6\">post<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>,<\/span><span class=\"z-l-2 z-d-6\"> &#39;<\/span><span class=\"z-l-2 z-d-6\">\/submit<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>,<\/span><span class=\"z-l-2 z-d-6\"> &#39;<\/span><span class=\"z-l-2 z-d-6\">500<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>)<\/span><span>.<\/span><span>inc<\/span><span>(<\/span><span>)<\/span><\/span><\/code><\/pre>\n<p>\u6b64\u65f6\u5728\u4e1a\u52a1\u66b4\u9732\u51fa\u6765\u7684\u7aef\u70b9\u4e0a\u4f1a\u6709\u8fd9\u6837\u4e24\u6761\u8bb0\u5f55<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>web_request_total{method=&quot;\/submit&quot;,method=&quot;post&quot;,status_code=&quot;500&quot;} 1<\/span><\/span>\n<span class=\"giallo-l\"><span>web_request_total{method=&quot;\/&quot;,method=&quot;get&quot;,status_code=&quot;200&quot;} 1<\/span><\/span><\/code><\/pre>\n<p>\u5bf9\u4e8e Counter \u6211\u4eec\u4e00\u822c\u770b\u589e\u957f\u91cf\u548c\u589e\u957f\u901f\u7387<\/p>\n<ul>\n<li><code>sum(increase(web_request_total[5m]))<\/code> \u4e94\u5206\u949f\u5185\u603b\u8bf7\u6c42\u6570<\/li>\n<li><code>sum(increase(web_request_total{status_code!~\"^2..\"}[1m]))<\/code> \u4e00\u5206\u949f\u5185\u72b6\u6001\u7801\u4e0d\u4e3a2xx\u7684\u603b\u8bf7\u6c42\u6570<\/li>\n<li><code>sum(irate(web_request_total[1m]))<\/code> \u4e00\u5206\u949f\u5185\u603b\u8bf7\u6c42\u6570\u589e\u957f\u7387<\/li>\n<\/ul>\n<p>\u544a\u8b66\u5219\u4e00\u822c\u8bbe\u7f6e\u4e3a<\/p>\n<ul>\n<li>\u4e00\u5206\u949f\u5185\u603b\u8bf7\u6c42\u4e2d\u6709\u6709\u8d85\u8fc7 5% \u7684 5xx \u9519\u8bef, \u6301\u7eed\u4e00\u5206\u949f<\/li>\n<\/ul>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>expr: sum(rate(web_request_total{status_code=~&quot;^5..&quot;}[1m])) \/ sum(rate(web_request_total[1m])) * 100 &gt; 5<\/span><\/span>\n<span class=\"giallo-l\"><span>for: 1m<\/span><\/span><\/code><\/pre>\n<ul>\n<li>\u4e00\u5206\u949f\u5185 5xx \u9519\u8bef\u7684\u8bf7\u6c42\u589e\u957f\u7387\u9ad8\u4e8e 100%, \u6301\u7eed\u4e00\u5206\u949f<\/li>\n<\/ul>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>expr: sum(irate(web_request_total{status_code=~&quot;^5..&quot;}[1m])) &gt; 100<\/span><\/span>\n<span class=\"giallo-l\"><span>for: 1m<\/span><\/span><\/code><\/pre><h3 id=\"gauge\"><a class=\"zola-anchor\" href=\"#gauge\" aria-label=\"Anchor link for: gauge\">Gauge<\/a><\/h3>\n<p>Gauge \u662f\u4e00\u4e2a\u77ac\u65f6\u91cf, \u5728\u65f6\u95f4\u4e0a\u6765\u770b\u662f\u53ef\u589e\u53ef\u51cf\u7684, \u7528\u4ee5\u8bb0\u5f55\u7cfb\u7edf\u5728\u67d0\u4e2a\u65f6\u523b\u7684\u5f53\u524d\u72b6\u6001, \u6bd4\u5982\u5f53\u524d\u5b9e\u4f8b\u7ebf\u7a0b\u6570, \u5f53\u524d\u7cfb\u7edf\u8d1f\u8f7d, \u67d0\u4e2a\u961f\u5217\u7684\u957f\u5ea6, \u67d0\u4e2a\u961f\u5217\u7684\u6d88\u8d39\u5ef6\u65f6\u7b49.<\/p>\n<p>\u4e1a\u52a1\u4ee3\u7801\u5982\u4e0b<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"python\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">from<\/span><span> prometheus_client<\/span><span class=\"z-l-8 z-d-10\"> import<\/span><span> Gauge<\/span><\/span>\n<span class=\"giallo-l\"><span>g1<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> Gauge<\/span><span>(<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-6\">    &#39;<\/span><span class=\"z-l-2 z-d-6\">kafka_consumer_lag_seconds<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>,<\/span><span class=\"z-l-2 z-d-6\"> &#39;<\/span><span class=\"z-l-2 z-d-6\">kafka consume lag in second<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>    [<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span class=\"z-l-2 z-d-6\">topic<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>,<\/span><span class=\"z-l-2 z-d-6\"> &#39;<\/span><span class=\"z-l-2 z-d-6\">consumer_group<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>]<\/span><\/span>\n<span class=\"giallo-l\"><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>g1<\/span><span>.<\/span><span>labels<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span class=\"z-l-2 z-d-6\">k-test<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>,<\/span><span class=\"z-l-2 z-d-6\"> &#39;<\/span><span class=\"z-l-2 z-d-6\">grp1<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>)<\/span><span>.<\/span><span>set<\/span><span>(<\/span><span class=\"z-l-1 z-d-4\">233<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>g2<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> Gauge<\/span><span>(<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-6\">    &#39;<\/span><span class=\"z-l-2 z-d-6\">redis_connection_pool_count<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>,<\/span><span class=\"z-l-2 z-d-6\"> &#39;<\/span><span class=\"z-l-2 z-d-6\">redis connection poll count<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>    [<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span class=\"z-l-2 z-d-6\">state<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>]<\/span><\/span>\n<span class=\"giallo-l\"><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>g2<\/span><span>.<\/span><span>labels<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span class=\"z-l-2 z-d-6\">idle<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>)<\/span><span>.<\/span><span>set<\/span><span>(<\/span><span class=\"z-l-1 z-d-4\">10<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>g2<\/span><span>.<\/span><span>labels<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span class=\"z-l-2 z-d-6\">active<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>)<\/span><span>.<\/span><span>set<\/span><span>(<\/span><span class=\"z-l-1 z-d-4\">22<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>g2<\/span><span>.<\/span><span>labels<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span class=\"z-l-2 z-d-6\">total<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>)<\/span><span>.<\/span><span>set<\/span><span>(<\/span><span class=\"z-l-1 z-d-4\">32<\/span><span>)<\/span><\/span><\/code><\/pre>\n<p>\u6b64\u65f6\u5728\u4e1a\u52a1\u66b4\u9732\u51fa\u6765\u7684\u7aef\u70b9\u4e0a\u4f1a\u6709\u8fd9\u6837\u7684\u8bb0\u5f55<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>kafka_consumer_lag_seconds{topic=&quot;k-test&quot;,consumer_group=&quot;grp1&quot;} 233<\/span><\/span>\n<span class=\"giallo-l\"><span>redis_connection_pool_count{state=&quot;idle&quot;} 10<\/span><\/span>\n<span class=\"giallo-l\"><span>redis_connection_pool_count{state=&quot;active&quot;} 22<\/span><\/span>\n<span class=\"giallo-l\"><span>redis_connection_pool_count{state=&quot;total&quot;} 32<\/span><\/span><\/code><\/pre>\n<p>\u5bf9\u4e8e Gauge \u6211\u4eec\u4e00\u822c\u76f4\u63a5\u770b\u5176\u503c\u6216\u8005\u5176\u503c\u7684\u767e\u5206\u6bd4<\/p>\n<ul>\n<li>\n<p><code>kafka_consumer_lag_seconds{topic=\"k-test\"}<\/code> \u67e5\u770b k-test \u8fd9\u4e2a topic \u6700\u65b0\u7684\u6d88\u8d39\u5ef6\u8fdf<\/p>\n<\/li>\n<li>\n<p><code>avg_over_time(kafka_consumer_lag_seconds[1m])<\/code> \u67e5\u770b\u5e94\u7528\u5168\u90e8 kafka \u961f\u5217\u4e00\u5206\u949f\u7684\u5e73\u5747\u6d88\u8d39\u5ef6\u65f6<\/p>\n<\/li>\n<li>\n<p><code>max_over_time(kafka_consumer_lag_seconds[1m])<\/code> \u67e5\u770b\u5e94\u7528\u5168\u90e8 kafka \u961f\u5217\u6bcf\u4e00\u5206\u949f\u5185\u7684\u6700\u5927\u6d88\u8d39\u5ef6\u65f6<\/p>\n<\/li>\n<li>\n<p><code>redis_connection_pool_count{state=\"active\"} \/ ignoring(state) redis_connection_pool_count{state=\"total\"}<\/code> \u67e5\u770b\u5e94\u7528 redis \u8fde\u63a5\u6c60\u7684\u4f7f\u7528\u767e\u5206\u6bd4<\/p>\n<\/li>\n<\/ul>\n<p>\u544a\u8b66\u5219\u4e00\u822c\u8bbe\u7f6e\u4e3a<\/p>\n<ul>\n<li>\u4e00\u5206\u949f\u5185\u961f\u5217\u7684\u5e73\u5747\u6d88\u8d39\u5ef6\u65f6\u5927\u4e8e 10min, \u6301\u7eed\u4e00\u5206\u949f<\/li>\n<\/ul>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>expr: avg_over_time(kafka_consumer_lag_seconds[1m]) &gt; 600<\/span><\/span>\n<span class=\"giallo-l\"><span>for: 1m<\/span><\/span><\/code><\/pre>\n<ul>\n<li>Redis \u8fde\u63a5\u6c60\u5e73\u5747\u5360\u7528\u8d85\u8fc7 90%, \u6301\u7eed\u4e00\u5206\u949f<\/li>\n<\/ul>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>expr: avg_over_time(redis_connection_pool_count{state=&quot;active&quot;}[1m]) \/  ignoring(state) avg_over_time(redis_connection_pool_count{state=&quot;total&quot;}[1m]) * 100 &gt; 90<\/span><\/span>\n<span class=\"giallo-l\"><span>for: 1m<\/span><\/span><\/code><\/pre><h3 id=\"histogram-he-summary\"><a class=\"zola-anchor\" href=\"#histogram-he-summary\" aria-label=\"Anchor link for: histogram-he-summary\">Histogram \u548c Summary<\/a><\/h3>\n<p>Histogram \u53ef\u4ee5\u770b\u4f5c\u662f\u4e00\u4e2a\u590d\u5408\u7684 Counter \u7c7b\u578b, \u5b83\u4f1a\u5c06\u6570\u503c\u6309\u533a\u95f4\u8ba1\u6570, \u5e38\u7528\u4e8e\u8bb0\u5f55 P99, P95 \u7c7b\u7684\u6570\u636e. \u53ef\u4ee5\u7528\u6765\u8bb0\u5f55\u6bd4\u5982\u63a5\u53e3\u54cd\u5e94\u8017\u65f6\u60c5\u51b5, \u63a5\u53e3\u8fd4\u56de\u6570\u636e\u5927\u5c0f\u60c5\u51b5\u7b49.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"python\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">from<\/span><span> prometheus_client<\/span><span class=\"z-l-8 z-d-10\"> import<\/span><span> Histogram<\/span><\/span>\n<span class=\"giallo-l\"><span>h<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> Histogram<\/span><span>(<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-6\">    &#39;<\/span><span class=\"z-l-2 z-d-6\">http_request_duration_seconds<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>,<\/span><span class=\"z-l-2 z-d-6\"> &#39;<\/span><span class=\"z-l-2 z-d-6\">Api requests response time in seconds<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>    [<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span class=\"z-l-2 z-d-6\">api<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>,<\/span><span class=\"z-l-2 z-d-6\"> &#39;<\/span><span class=\"z-l-2 z-d-6\">method<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>]<\/span><span>,<\/span><span> (<\/span><span class=\"z-l-1 z-d-4\">0.1<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> 0.25<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> 1<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> 4<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\"> 10<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>h<\/span><span>.<\/span><span>labels<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span class=\"z-l-2 z-d-6\">\/products<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>,<\/span><span class=\"z-l-2 z-d-6\"> &#39;<\/span><span class=\"z-l-2 z-d-6\">post<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>)<\/span><span>.<\/span><span>observe<\/span><span>(<\/span><span class=\"z-l-1 z-d-4\">0.0923<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>h<\/span><span>.<\/span><span>labels<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span class=\"z-l-2 z-d-6\">\/products<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>,<\/span><span class=\"z-l-2 z-d-6\"> &#39;<\/span><span class=\"z-l-2 z-d-6\">post<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>)<\/span><span>.<\/span><span>observe<\/span><span>(<\/span><span class=\"z-l-1 z-d-4\">0.3672<\/span><span>)<\/span><\/span><\/code><\/pre>\n<p>\u6b64\u65f6\u5728\u4e1a\u52a1\u66b4\u9732\u51fa\u6765\u7684\u7aef\u70b9\u4e0a\u4f1a\u6709\u8fd9\u6837\u7684\u8bb0\u5f55, \u4ea7\u751f\u4e86\u591a\u6761\u6570\u636e, \u5176\u4e2d <code>_sum<\/code> \u662f\u503c\u7684\u603b\u548c, <code>_count<\/code> \u662f\u503c\u7684\u8ba1\u6570, <code>_bucket<\/code> \u4e2d\u6709\u4e00\u4e2a\u547d\u540d\u4e3a <code>le<\/code> \u7279\u6b8a\u7684 label, \u5176\u4e2d\u7684\u533a\u95f4\u503c\u662f\u6211\u4eec\u5728\u4ee3\u7801\u4e2d\u914d\u7f6e\u7684, \u662f\u503c\u5728\u533a\u95f4\u5185\u7684\u8ba1\u6570.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>http_request_duration_seconds_sum{api=&quot;\/products&quot;, &quot;method&quot;=&quot;post&quot;} 0.4595<\/span><\/span>\n<span class=\"giallo-l\"><span>http_request_duration_seconds_count{api=&quot;\/products&quot;, &quot;method&quot;=&quot;post&quot;} 2<\/span><\/span>\n<span class=\"giallo-l\"><span>http_request_duration_seconds_bucket{api=&quot;\/products&quot;, &quot;method&quot;=&quot;post&quot;, le=&quot;0.1&quot;} 1<\/span><\/span>\n<span class=\"giallo-l\"><span>http_request_duration_seconds_bucket{api=&quot;\/products&quot;, &quot;method&quot;=&quot;post&quot;, le=&quot;0.25&quot;} 1<\/span><\/span>\n<span class=\"giallo-l\"><span>http_request_duration_seconds_bucket{api=&quot;\/products&quot;, &quot;method&quot;=&quot;post&quot;, le=&quot;1&quot;} 2<\/span><\/span>\n<span class=\"giallo-l\"><span>http_request_duration_seconds_bucket{api=&quot;\/products&quot;, &quot;method&quot;=&quot;post&quot;, le=&quot;4&quot;} 2<\/span><\/span>\n<span class=\"giallo-l\"><span>http_request_duration_seconds_bucket{api=&quot;\/products&quot;, &quot;method&quot;=&quot;post&quot;, le=&quot;10&quot;} 2<\/span><\/span>\n<span class=\"giallo-l\"><span>http_request_duration_seconds_bucket{api=&quot;\/products&quot;, &quot;method&quot;=&quot;post&quot;, le=&quot;+Inf&quot;} 2<\/span><\/span><\/code><\/pre>\n<p>\u5bf9\u4e8e Histogram \u4e00\u822c\u53ef\u4ee5\u6c42\u5747\u503c\u6216\u8005 P95, P99 \u4e4b\u7c7b\u7684\u503c, \u4e5f\u53ef\u4ee5\u505a\u666e\u901a\u7684 Counter \u4f7f\u7528<\/p>\n<ul>\n<li><code>rate(http_request_duration_seconds_sum{api=\"\/products\", \"method\"=\"post\"}[5m]) \/ rate(http_request_duration_seconds_count{api=\"\/products\", \"method\"=\"post\"}[5m])<\/code> \u67e5\u770b \/products \u7aef\u70b9\u4e0a POST \u8bf7\u6c42\u4e94\u5206\u949f\u5185\u7684\u8017\u65f6\u5747\u503c<\/li>\n<li><code>histogram_quantile(0.99, rate(http_request_duration_seconds_bucket{api=\"\/products\", \"method\"=\"post\"}[5m]))<\/code> \u67e5\u770b \/products \u7aef\u70b9\u4e0a POST \u8bf7\u6c42\u4e94\u5206\u949f\u5185\u7684\u8017\u65f6 P99<\/li>\n<li><code>increase(http_request_duration_seconds_count{api=\"\/products\", \"method\"=\"post\"}[1m])<\/code> \u67e5\u770b \/products \u7aef\u70b9\u4e0a POST \u8bf7\u6c42\u4e00\u5206\u949f\u5185\u7684\u8bf7\u6c42\u6570<\/li>\n<\/ul>\n<p>\u544a\u8b66\u5219\u4e00\u822c\u8bbe\u7f6e\u4e3a<\/p>\n<ul>\n<li>\u4e24\u5206\u949f\u5185\u67d0\u4e2a\u63a5\u53e3 P95 \u5927\u4e8e 10s, \u6301\u7eed\u4e24\u5206\u949f<\/li>\n<\/ul>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>expr: histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket[2m])) by (api, method)) &gt; 10<\/span><\/span>\n<span class=\"giallo-l\"><span>for: 2m<\/span><\/span><\/code><\/pre>\n<p>\u4e00\u4e9b\u6709\u7528\u7684\u8d44\u6599<\/p>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/awesome-prometheus-alerts.grep.to\/rules\">awesome-prometheus-alerts<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/grafana.com\/blog\/2020\/06\/23\/how-to-visualize-prometheus-histograms-in-grafana\/\">How to visualize Prometheus histograms in Grafana<\/a><\/li>\n<\/ul>\n"},{"title":"Prometheus \u4ece\u5165\u95e8\u5230\u653e\u5f03","published":"2022-04-17T16:30:08+08:00","updated":"2022-04-17T16:30:08+08:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/prometheus-from-scratch\/"}},"id":"https:\/\/memwey.github.io\/posts\/prometheus-from-scratch\/","content":"<h2 id=\"ji-ben-gai-nian\"><a class=\"zola-anchor\" href=\"#ji-ben-gai-nian\" aria-label=\"Anchor link for: ji-ben-gai-nian\">\u57fa\u672c\u6982\u5ff5<\/a><\/h2>\n<p>Prometheus \u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u76d1\u63a7\u65b9\u6848, <a rel=\"external\" href=\"https:\/\/cncf.io\/\">CNCF<\/a> \u7684\u6bd5\u4e1a\u9879\u76ee, \u4e91\u539f\u751f\u76d1\u63a7\u7684\u4e8b\u5b9e\u6807\u51c6. Prometheus \u4ee5\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u7684\u5f62\u5f0f\u6536\u96c6\u548c\u5b58\u50a8 <code>metrics<\/code>. <code>Metrics<\/code> \u4fe1\u606f\u4e0e\u88ab\u79f0\u4e3a\u6807\u7b7e\u7684\u53ef\u9009\u7684\u952e\u503c\u5bf9\u548c\u8bb0\u5f55\u65f6\u95f4\u4e00\u8d77\u4fdd\u5b58.<\/p>\n<p>Prometheus \u7684\u4e3b\u8981\u529f\u80fd\u7279\u70b9\u6709<\/p>\n<ul>\n<li>\u7531 <code>metric<\/code> \u7684\u540d\u79f0\u4ee5\u53ca Key\/Value \u5bf9\u6807\u7b7e\u6807\u8bc6\u7684<code>\u65f6\u95f4\u5e8f\u5217<\/code>\u6570\u636e\u7ec4\u6210\u7684\u591a\u7ef4<a rel=\"external\" href=\"https:\/\/prometheus.io\/docs\/concepts\/data_model\/\">\u6570\u636e\u6a21\u578b<\/a><\/li>\n<li>\u7075\u6d3b\u7684\u67e5\u8be2\u8bed\u8a00 <a rel=\"external\" href=\"https:\/\/prometheus.io\/docs\/prometheus\/latest\/querying\/basics\/\">PromQL<\/a><\/li>\n<li>\u4e0d\u4f9d\u8d56\u5206\u5e03\u5f0f\u5b58\u50a8; \u5355\u670d\u52a1\u8282\u70b9\u81ea\u6cbb\u80fd\u529b<\/li>\n<li>\u670d\u52a1\u7aef\u901a\u8fc7 HTTP \u534f\u8bae\u62c9\u53d6\u83b7\u5f97\u7684\u65f6\u95f4\u5e8f\u5217\u6570\u636e<\/li>\n<li>\u652f\u6301\u901a\u8fc7\u4e2d\u95f4\u7f51\u5173<a rel=\"external\" href=\"https:\/\/prometheus.io\/docs\/instrumenting\/pushing\/\">\u63a8\u9001\u65f6\u95f4\u5e8f\u5217\u6570\u636e<\/a><\/li>\n<li>\u901a\u8fc7\u670d\u52a1\u53d1\u73b0\u6216\u9759\u6001\u914d\u7f6e\u6587\u4ef6\u53d1\u73b0\u76d1\u63a7\u76ee\u6807<\/li>\n<li>\u652f\u6301\u591a\u79cd\u7c7b\u578b\u7684\u56fe\u8868\u548c\u4eea\u8868\u76d8<\/li>\n<\/ul>\n<p>Prometheus \u4ee5\u62c9\u53d6\u7684\u6a21\u5f0f\u83b7\u53d6\u83b7\u53d6\u76d1\u63a7\u6570\u636e, \u800c\u4e0d\u662f\u7531\u4e1a\u52a1\u65b9\u5411\u76d1\u63a7\u670d\u52a1\u5668\u63a8\u9001. \u8fd9\u5bf9\u4e8e\u88ab\u76d1\u63a7\u7684\u4e1a\u52a1\u6765\u8bf4, \u6781\u5927\u7684\u51cf\u5c11\u4e86\u76d1\u63a7\u90e8\u5206\u5728\u7cfb\u7edf\u4e2d\u7684\u8026\u5408. \u901a\u5e38, \u4e1a\u52a1\u66b4\u9732\u51fa\u4e00\u4e2a HTTP \u7aef\u53e3\u4ee5\u66b4\u9732\u6570\u636e, \u4f9b Prometheus server \u6293\u53d6\u5373\u53ef.<\/p>\n<h3 id=\"metric\"><a class=\"zola-anchor\" href=\"#metric\" aria-label=\"Anchor link for: metric\">Metric<\/a><\/h3>\n<p>\u4e00\u822c\u6765\u8bf4, <code>Metric<\/code> \u662f\u6570\u503c\u5f62\u5f0f\u7684\u6807\u91cf\u5355\u4f4d, \u5b83\u662f\u4e0e\u65f6\u95f4\u4e00\u8d77\u88ab\u8bb0\u5f55\u7684\u65f6\u95f4\u5e8f\u5217. \u5728\u4e0d\u540c\u5e94\u7528\u4e2d\u7528\u6237\u671f\u671b\u8bb0\u5f55\u4e0d\u540c\u7684 <code>Metric<\/code>. Web server \u53ef\u80fd\u8981\u5e0c\u671b\u8bf7\u6c42\u6570\u548c\u4e00\u4e9b\u6307\u6807\u4fe1\u606f, \u6570\u636e\u5e93\u53ef\u80fd\u5e0c\u671b\u8bb0\u5f55\u6d3b\u8dc3\u8fde\u63a5\u6570\u548c\u6d3b\u8dc3\u67e5\u8be2\u6570\u4e4b\u7c7b\u7684.<\/p>\n<h3 id=\"xi-tong-jia-gou\"><a class=\"zola-anchor\" href=\"#xi-tong-jia-gou\" aria-label=\"Anchor link for: xi-tong-jia-gou\">\u7cfb\u7edf\u67b6\u6784<\/a><\/h3>\n<ul>\n<li>\u4e3b\u8981\u7684 <a rel=\"external\" href=\"https:\/\/github.com\/prometheus\/prometheus\">Prometheus server<\/a> \u6536\u96c6\u548c\u5b58\u50a8\u65f6\u95f4\u5e8f\u5217\u6570\u636e<\/li>\n<li><a rel=\"external\" href=\"https:\/\/prometheus.io\/docs\/instrumenting\/clientlibs\/\">\u5ba2\u6237\u7aef\u5e93<\/a> \u7528\u4ee5\u76d1\u6d4b\u5e94\u7528\u7a0b\u5e8f\u4ee3\u7801<\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/prometheus\/pushgateway\">push gateway<\/a> \u7528\u4ee5\u652f\u6301\u77ed\u671f\u8fd0\u884c\u7684\u4efb\u52a1<\/li>\n<li>\u7528\u4ee5\u76d1\u63a7 HAProxy, StatsD, Graphite \u7b49\u5e38\u7528\u670d\u52a1\u7684 <a rel=\"external\" href=\"https:\/\/prometheus.io\/docs\/instrumenting\/exporters\/\">exporters<\/a><\/li>\n<li>\u7528\u4ee5\u5904\u7406\u544a\u8b66\u7684 <a rel=\"external\" href=\"https:\/\/github.com\/prometheus\/alertmanager\">alertmanager<\/a><\/li>\n<li>\u5176\u4ed6\u5404\u79cd\u652f\u6301\u5de5\u5177<\/li>\n<\/ul>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/prometheus-from-scratch\/images\/architecture.png\" alt=\"\u7cfb\u7edf\u67b6\u6784\u56fe\" \/><\/p>\n<h3 id=\"gua-yong-chang-jing\"><a class=\"zola-anchor\" href=\"#gua-yong-chang-jing\" aria-label=\"Anchor link for: gua-yong-chang-jing\">\u9002\u7528\u573a\u666f<\/a><\/h3>\n<p>Prometheus \u9002\u5408\u8bb0\u5f55\u4efb\u4f55\u7eaf\u6570\u503c\u7684\u65f6\u95f4\u5e8f\u5217\u3002\u5b83\u65e2\u9002\u5408\u4ee5\u673a\u5668\u4e3a\u4e2d\u5fc3\u7684\u76d1\u63a7, \u4e5f\u9002\u5408\u76d1\u63a7\u9ad8\u5ea6\u52a8\u6001\u7684\u9762\u5411\u670d\u52a1\u7684\u4f53\u7cfb\u7ed3\u6784. \u5b83\u5bf9\u591a\u7ef4\u6570\u636e\u6536\u96c6\u548c\u67e5\u8be2\u7684\u652f\u6301\u5728\u5fae\u670d\u52a1\u7684\u573a\u666f\u4e2d\u62e5\u6709\u7279\u522b\u7684\u4f18\u52bf.<\/p>\n<p>Prometheus \u57fa\u4e8e\u53ef\u9760\u6027\u8bbe\u8ba1, \u4ee5\u4fdd\u8bc1\u5728\u51fa\u73b0\u95ee\u9898\u65f6\u53ef\u4ee5\u5feb\u901f\u8fdb\u884c\u95ee\u9898\u8bca\u65ad. \u6bcf\u4e2a Prometheus server \u90fd\u662f\u72ec\u7acb\u7684, \u4e0d\u4f9d\u8d56\u4e8e\u7f51\u7edc\u5b58\u50a8\u6216\u5176\u4ed6\u8fdc\u7a0b\u670d\u52a1. \u5f53\u57fa\u7840\u8bbe\u65bd\u7684\u5176\u4ed6\u90e8\u5206\u51fa\u73b0\u6545\u969c\u65f6, \u8fd9\u79cd\u67b6\u6784\u975e\u5e38\u53ef\u9760, \u53e6\u4e00\u65b9\u9762, \u5b83\u4e0d\u9700\u8981\u914d\u7f6e\u5927\u91cf\u7684\u57fa\u7840\u8bbe\u65bd.<\/p>\n<p>Prometheus \u4e0d\u9002\u5408\u9700\u8981 100% \u7684\u51c6\u786e\u6027\u7684\u573a\u666f, \u4f8b\u5982\u8bb0\u5f55\u5355\u4e2a\u7684\u8ba1\u8d39\u8bf7\u6c42, \u6536\u96c6\u7684\u6570\u636e\u53ef\u80fd\u4e0d\u591f\u8be6\u7ec6\u548c\u5b8c\u6574. \u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u5e94\u4f7f\u7528\u5176\u4ed6\u7cfb\u7edf\u6765\u6536\u96c6\u548c\u5206\u6790\u8ba1\u8d39\u6570\u636e, \u4f7f\u7528 Prometheus \u8fdb\u884c\u5176\u4f59\u7684\u76d1\u63a7.<\/p>\n<p>\u8fd9\u91cc\u8bf4\u7684\u6bd4\u8f83\u7b3c\u7edf, \u4ece\u6784\u5efa\u7cfb\u7edf\u53ef\u89c2\u6d4b\u6027\u7684\u76d1\u63a7\u6765\u8bf4, \u6211\u4eec\u6709 <code>Metrics<\/code> , <code>Tracing<\/code> \u548c <code>Logging<\/code>. \u5b83\u4eec\u6709\u5404\u81ea\u7684\u7279\u70b9, <code>Metrics<\/code> \u7684\u7279\u70b9\u662f\u53ef\u805a\u5408\u7684, \u5b83\u4eec\u662f\u7ec4\u6210\u4e00\u4e2a\u91cf\u8ba1, \u8ba1\u6570\u5668\u6216\u8005\u76f4\u65b9\u56fe\u7684\u6700\u5c0f\u5355\u4f4d. <code>Logging<\/code> \u5904\u7406\u4e00\u7cfb\u5217\u79bb\u6563\u4e8b\u4ef6. \u800c <code>Tracing<\/code> \u5904\u7406\u6574\u4e2a\u8bf7\u6c42\u8303\u56f4\u5185\u7684\u4fe1\u606f, \u6570\u636e\u6216\u5143\u6570\u636e\u5e94\u5f53\u7ed1\u5b9a\u5230\u7cfb\u7edf\u4e2d\u5355\u4e2a\u4e8b\u52a1\u5bf9\u8c61\u7684\u751f\u547d\u5468\u671f\u4e2d.<\/p>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/prometheus-from-scratch\/images\/Obervation-Venn.png\" alt=\"\u53ef\u89c2\u6d4b\u6027\u97e6\u6069\u56fe\" \/><\/p>\n<p>Prometheus \u662f\u4e2a\u5178\u578b\u7684 <code>Metrics<\/code> \u7cfb\u7edf, \u5b83\u4e3a\u7cfb\u7edf\u6253\u70b9, \u8ffd\u8e2a\u7cfb\u7edf\u6574\u4f53\u7684\u8fd0\u884c\u60c5\u51b5. \u6bd4\u5982, \u8bb0\u5f55 Web \u7cfb\u7edf\u4e2d\u7684\u6240\u6709\u8bf7\u6c42\u7684 HTTP \u72b6\u6001\u7801, \u5f53\u4e00\u6bb5\u65f6\u95f4\u4e2d 500 \u9519\u8bef\u5927\u91cf\u51fa\u73b0\u65f6, \u53ef\u4ee5\u901a\u8fc7\u914d\u7f6e\u7684\u805a\u5408\u548c\u8d8b\u52bf\u5206\u6790\u53d1\u73b0\u95ee\u9898\u5e76\u63d0\u4f9b\u544a\u8b66, \u4f46\u5b83\u6ca1\u6709\u8bb0\u5f55\u5177\u4f53\u7684\u8bf7\u6c42\u5185\u5bb9, \u60f3\u8981\u590d\u73b0\u9519\u8bef\u7684\u8bf7\u6c42, \u5219\u9700\u8981 <code>Tracing<\/code> \u548c <code>Logging<\/code> \u7cfb\u7edf\u8fdb\u884c\u8fdb\u4e00\u6b65\u7684\u8bca\u65ad.<\/p>\n<h2 id=\"kuai-su-ru-men\"><a class=\"zola-anchor\" href=\"#kuai-su-ru-men\" aria-label=\"Anchor link for: kuai-su-ru-men\">\u5feb\u901f\u5165\u95e8<\/a><\/h2>\n<h3 id=\"shu-ju-mo-xing\"><a class=\"zola-anchor\" href=\"#shu-ju-mo-xing\" aria-label=\"Anchor link for: shu-ju-mo-xing\">\u6570\u636e\u6a21\u578b<\/a><\/h3>\n<h4 id=\"metric-and-label\"><a class=\"zola-anchor\" href=\"#metric-and-label\" aria-label=\"Anchor link for: metric-and-label\">Metric and Label<\/a><\/h4>\n<p>Prometheus \u5728\u5e95\u5c42\u5c06\u6240\u6709\u5c5e\u4e8e\u540c\u4e00\u6307\u6807\u540d\u79f0, \u540c\u4e00\u6807\u7b7e\u96c6\u5408\u7684, \u6709\u65f6\u95f4\u6233\u6807\u8bb0\u7684\u6570\u636e\u6d41\u5b58\u50a8\u4e3a\u65f6\u95f4\u5e8f\u5217\u6570\u636e.<\/p>\n<p>\u6570\u636e\u6a21\u578b\u7684\u8868\u793a\u65b9\u5f0f\u4e3a<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>&lt;metric name&gt;{&lt;label name&gt;=&lt;label value&gt;, ...}<\/span><\/span><\/code><\/pre>\n<p>\u4e14\u6709\u4ee5\u4e0b\u89c4\u5219<\/p>\n<h5 id=\"metric-name\"><a class=\"zola-anchor\" href=\"#metric-name\" aria-label=\"Anchor link for: metric-name\">metric name<\/a><\/h5>\n<p>\u5339\u914d\u6b63\u5219 <code>[a-zA-Z_:][a-zA-Z0-9_:]*<\/code>, \u5176\u4e2d <code>:<\/code> \u662f\u7528\u6237\u81ea\u5b9a\u4e49\u8bb0\u5f55\u89c4\u5219\u7684\u6807\u8bb0, \u4e0d\u5e94\u8be5\u7528\u5728\u4e1a\u52a1\u66b4\u9732\u7684\u6307\u6807\u4e2d<\/p>\n<h5 id=\"label-name\"><a class=\"zola-anchor\" href=\"#label-name\" aria-label=\"Anchor link for: label-name\">label name<\/a><\/h5>\n<p>\u5339\u914d\u6b63\u5219 <code>[a-zA-Z_][a-zA-Z0-9_]*<\/code>, \u5176\u4e2d\u4ee5 <code>__<\/code> \u5f00\u5934\u7684\u662f\u7cfb\u7edf\u4fdd\u7559\u547d\u540d<\/p>\n<h4 id=\"sample\"><a class=\"zola-anchor\" href=\"#sample\" aria-label=\"Anchor link for: sample\">Sample<\/a><\/h4>\n<p>Sample \u7684 value \u603b\u662f\u4e3a\u4e00\u4e2a float64 \u503c<\/p>\n<p>\u4ee5\u5173\u7cfb\u578b\u6570\u636e\u5e93\u6765\u7c7b\u6bd4, metric_name \u76f8\u5f53\u4e8e\u8868\u540d, label_name \u76f8\u5f53\u4e8e\u5217\u540d, label_value \u76f8\u5f53\u67d0\u4e00\u5b57\u6bb5\u7684\u503c, \u800c metric_value \u548c timestamp \u7684\u5217\u662f\u7cfb\u7edf\u81ea\u52a8\u751f\u6210\u7684.<\/p>\n<p>\u6bd4\u5982\u5982\u4e0b\u540d\u4e3a <code>api_http_requests_total<\/code> \u6307\u6807\u8868\u793a\u4e86 API \u6240\u6709\u7684 HTTP \u8bf7\u6c42\u6570, \u5176\u4e2d\u6807\u7b7e <code>method<\/code> \u6307\u5b9a\u4e86\u65b9\u6cd5, <code>handler<\/code> \u6307\u5b9a\u4e86\u8def\u5f84, \u5206\u522b\u4e3a <code>method=\"POST\"<\/code> \u548c <code>handler=\"\/messages\"<\/code>, \u6b64\u6837\u672c\u7684\u503c\u4e3a 11<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>api_http_requests_total{method=&quot;POST&quot;, handler=&quot;\/messages&quot;} 11<\/span><\/span><\/code><\/pre><pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"sql\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">CREATE<\/span><span class=\"z-l-8 z-d-10\"> TABLE<\/span><span> `<\/span><span class=\"z-l-6 z-d-7\">api_http_requests_total<\/span><span>`<\/span><span> (<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-6\">    `<\/span><span class=\"z-l-2 z-d-6\">timestamp<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-8 z-d-10\"> timestamp<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-6\">    `<\/span><span class=\"z-l-2 z-d-6\">method<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-8 z-d-10\"> varchar<\/span><span>(<\/span><span class=\"z-l-1 z-d-4\">255<\/span><span>)<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-6\">    `<\/span><span class=\"z-l-2 z-d-6\">handler<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-8 z-d-10\"> varchar<\/span><span>(<\/span><span class=\"z-l-1 z-d-4\">255<\/span><span>)<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-6\">    `<\/span><span class=\"z-l-2 z-d-6\">value<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span> double<\/span><\/span>\n<span class=\"giallo-l\"><span>);<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">SELECT<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-8 z-d-10\"> FROM<\/span><span class=\"z-l-2 z-d-6\"> `<\/span><span class=\"z-l-2 z-d-6\">api_http_requests_total<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">+<\/span><span class=\"z-l-5 z-d-3\">--<\/span><span class=\"z-l-5 z-d-3\">----------+--------+-----------+-------+<\/span><\/span>\n<span class=\"giallo-l\"><span>| <\/span><span class=\"z-l-8 z-d-10\">timestamp<\/span><span>  | method |  handler  | <\/span><span class=\"z-l-8 z-d-10\">value<\/span><span> |<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">+<\/span><span class=\"z-l-5 z-d-3\">--<\/span><span class=\"z-l-5 z-d-3\">----------+--------+-----------+-------+<\/span><\/span>\n<span class=\"giallo-l\"><span>| <\/span><span class=\"z-l-1 z-d-4\">1649235184<\/span><span> |  POST  | <\/span><span class=\"z-l-8 z-d-10\">\/<\/span><span>messages |   <\/span><span class=\"z-l-1 z-d-4\">11<\/span><span>  |<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">+<\/span><span class=\"z-l-5 z-d-3\">--<\/span><span class=\"z-l-5 z-d-3\">----------+--------+-----------+-------+<\/span><\/span>\n<span class=\"giallo-l\"><\/span><\/code><\/pre><h3 id=\"metric-1\"><a class=\"zola-anchor\" href=\"#metric-1\" aria-label=\"Anchor link for: metric-1\">Metric<\/a><\/h3>\n<p>Prometheus \u63d0\u4f9b\u4e86\u4ee5\u4e0b\u4e00\u4e9b\u7c7b\u578b <code>metrics<\/code> \u7c7b\u578b<\/p>\n<h4 id=\"counter\"><a class=\"zola-anchor\" href=\"#counter\" aria-label=\"Anchor link for: counter\">Counter<\/a><\/h4>\n<p>Counter \u7c7b\u578b\u4ee3\u8868\u4e00\u79cd\u6837\u672c\u6570\u636e\u5355\u8c03\u9012\u589e\u7684\u6307\u6807, \u5373\u9664\u975e\u76d1\u63a7\u7cfb\u7edf\u53d1\u751f\u4e86\u91cd\u7f6e, \u53ea\u589e\u4e0d\u51cf.<\/p>\n<p>\u4f8b\u5b50: \u7cfb\u7edf\u63a5\u53d7\u7684\u8bf7\u6c42\u6570, \u7cfb\u7edf\u9519\u8bef\u6570, \u7cfb\u7edf uptime<\/p>\n<h4 id=\"gauge\"><a class=\"zola-anchor\" href=\"#gauge\" aria-label=\"Anchor link for: gauge\">Gauge<\/a><\/h4>\n<p>Gauge \u7c7b\u578b\u4ee3\u8868\u4e00\u79cd\u6837\u672c\u6570\u636e\u53ef\u4ee5\u4efb\u610f\u53d8\u5316\u7684\u6307\u6807, \u5373\u53ef\u589e\u53ef\u51cf.<\/p>\n<p>\u4f8b\u5b50: \u5f53\u524d\u5b9e\u4f8b\u7ebf\u7a0b\u6570, \u5f53\u524d\u7cfb\u7edf\u8d1f\u8f7d<\/p>\n<h4 id=\"histogram-he-summary\"><a class=\"zola-anchor\" href=\"#histogram-he-summary\" aria-label=\"Anchor link for: histogram-he-summary\">Histogram \u548c Summary<\/a><\/h4>\n<p>Histogram \u548c Summary \u7528\u4ee5\u5bf9\u6570\u636e\u8fdb\u884c\u91c7\u6837\u5e76\u50a8\u5b58\u5176\u5206\u5e03\u60c5\u51b5. \u4e0d\u540c\u7684\u662f, Histogram \u6307\u5b9a\u5176\u914d\u7f6e\u7684\u533a\u95f4, \u800c Summary \u914d\u7f6e\u5176\u5206\u4f4d\u6570.<\/p>\n<p>\u4e3e\u4e00\u4e2a\u5177\u4f53\u7684\u4f8b\u5b50, \u5047\u8bbe\u9700\u8981\u7edf\u8ba1\u67d0\u4e2a WEB \u9875\u9762\u7684\u54cd\u5e94\u65f6\u95f4, \u4f7f\u7528 Histogram \u65f6, \u9700\u8981\u914d\u7f6e\u5176\u54cd\u5e94\u65f6\u95f4\u533a\u95f4, &lt;10ms, 10ms-100ms, 100ms-1000ms, &gt;1000ms, \u8fd4\u56de\u7684\u6570\u636e\u5982\u4e0b<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>http_response_latency_range_bucket{le=&quot;0.01&quot;} 123<\/span><\/span>\n<span class=\"giallo-l\"><span>http_response_latency_range_bucket{le=&quot;0.1&quot;} 214<\/span><\/span>\n<span class=\"giallo-l\"><span>http_response_latency_range_bucket{le=&quot;1&quot;} 215<\/span><\/span>\n<span class=\"giallo-l\"><span>http_response_latency_range_bucket{le=&quot;+Inf&quot;} 216<\/span><\/span>\n<span class=\"giallo-l\"><span>http_response_latency_range_sum 2.888716127000002<\/span><\/span>\n<span class=\"giallo-l\"><span>http_response_latency_range_count 216<\/span><\/span><\/code><\/pre>\n<p>\u4f7f\u7528 Summary \u65f6, \u5219\u914d\u7f6e 0.5, 0.9, 0.99, \u4ee3\u8868\u4e86\u517650\u5206\u4f4d, \u5373\u4e2d\u4f4d\u6570, 90\u5206\u4f4d, 99\u5206\u4f4d\u7684\u503c<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>http_response_latency{quantile=&quot;0.5&quot;} 0.012352463<\/span><\/span>\n<span class=\"giallo-l\"><span>http_response_latency{quantile=&quot;0.9&quot;} 0.014458005<\/span><\/span>\n<span class=\"giallo-l\"><span>http_response_latency{quantile=&quot;0.99&quot;} 0.017316173<\/span><\/span>\n<span class=\"giallo-l\"><span>http_response_latency_sum 2.888716127000002<\/span><\/span>\n<span class=\"giallo-l\"><span>http_response_latency_count 216<\/span><\/span><\/code><\/pre>\n<p>\u6b64\u65f6\u53ef\u4ee5\u770b\u5230, \u8fd9\u4e2a HTTP \u63a5\u53e3\u4e00\u5171\u63a5\u53d7\u4e86 216 \u6b21\u8bf7\u6c42, \u4e00\u5171\u8017\u65f6\u4f7f\u7528\u4e86 2.88s, Histogram \u5c55\u793a\u4e86\u5177\u4f53\u6570\u503c\u5206\u5e03, 123 \u4e2a\u5728 10ms \u5185, \u6709 216 - 215 = 1 \u4e2a\u8bf7\u6c42\u8017\u65f6\u8d85\u8fc7\u4e86 1000ms. Summary \u5c55\u793a\u4e86\u5206\u5e03\u7684\u767e\u5206\u4f4d, \u4e2d\u4f4d\u6570\u662f 0.012s, 99\u5206\u4f4d\u662f 0.017s.<\/p>\n<p>\u901a\u5e38\u6211\u4eec\u4f7f\u7528 Histogram \u5373\u53ef, Summary \u4f1a\u4f7f\u7528\u8f83\u591a\u7684\u5185\u5b58\u6784\u9020\u4e00\u4e2a\u6ed1\u52a8\u7a97\u53e3\u6765\u505a\u7edf\u8ba1.<\/p>\n<h2 id=\"zhu-yi-shi-xiang\"><a class=\"zola-anchor\" href=\"#zhu-yi-shi-xiang\" aria-label=\"Anchor link for: zhu-yi-shi-xiang\">\u6ce8\u610f\u4e8b\u9879<\/a><\/h2>\n<p>\u6bcf\u4e2a\u952e\u503c\u6807\u7b7e\u5bf9\u7684\u552f\u4e00\u7ec4\u5408\u90fd\u4ee3\u8868\u4e00\u4e2a\u65b0\u7684\u65f6\u95f4\u5e8f\u5217, \u8fd9\u4f1a\u663e\u8457\u589e\u52a0\u66b4\u9732\u7684\u6307\u6807\u6570\u548c\u5b58\u50a8\u7684\u6570\u636e\u91cf. \u4e0d\u8981\u4f7f\u7528\u6807\u7b7e\u5b58\u50a8\u5177\u6709\u9ad8\u57fa\u6570, \u5373\u62e5\u6709\u8bb8\u591a\u4e0d\u540c\u7684\u6807\u7b7e\u503c\u7684\u7ef4\u5ea6, \u4f8b\u5982\u7528\u6237id, restful \u7684\u5b9e\u9645\u8def\u5f84\u53c2\u6570\u7b49.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>\/\/ Good<\/span><\/span>\n<span class=\"giallo-l\"><span>http_request_total{path=&quot;users\/{:user_id}\/info&quot;}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>\/\/ Bad<\/span><\/span>\n<span class=\"giallo-l\"><span>http_request_total{path=&quot;users\/1\/info&quot;}<\/span><\/span>\n<span class=\"giallo-l\"><span>http_request_total{path=&quot;users\/2\/info&quot;}<\/span><\/span>\n<span class=\"giallo-l\"><span>http_request_total{path=&quot;users\/3\/info&quot;}<\/span><\/span>\n<span class=\"giallo-l\"><span>http_request_total{path=&quot;users\/4\/info&quot;}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>\/\/ Good<\/span><\/span>\n<span class=\"giallo-l\"><span>crawler_failure_total{target=&quot;tiktok&quot;,scope=&quot;user&quot;}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>\/\/ Bad<\/span><\/span>\n<span class=\"giallo-l\"><span>crawler_failure_total{target=&quot;tiktok&quot;,user=&quot;damonlvu&quot;}<\/span><\/span>\n<span class=\"giallo-l\"><span>crawler_failure_total{target=&quot;tiktok&quot;,user=&quot;77777777777ge&quot;}<\/span><\/span><\/code><\/pre>\n<p>\u5728 Prometheus \u4e2d, Metric \u548c Label \u7684\u547d\u540d\u5e94\u8be5\u603b\u662f\u4f7f\u7528 <code>snake_case<\/code> \u5f62\u5f0f, \u4ee5\u4fbf\u540e\u7eed\u7684\u5904\u7406\u5f52\u7c7b\u5206\u5272\u7b49\u64cd\u4f5c.<\/p>\n<p>\u4e00\u4e2a Metric \u7684\u524d\u7f00\u603b\u5e94\u8be5\u4f7f\u7528\u5e94\u7528\u540d, \u53ef\u4ee5\u7406\u89e3\u4e3a\u4e00\u4e2a\u547d\u540d\u7a7a\u95f4, \u4f8b\u5982<\/p>\n<ul>\n<li><strong>prometheus<\/strong>_notifications_total (Prometheus \u7684\u5185\u90e8\u6307\u6807)<\/li>\n<li><strong>doris<\/strong>_consumption_latency_seconds (doris \u7684\u6d88\u8d39\u5ef6\u65f6)<\/li>\n<li><strong>crawler<\/strong>_failure_total (\u722c\u866b\u7684\u603b\u5931\u8d25\u6570)<\/li>\n<li><strong>crawler<\/strong>_request_total (\u722c\u866b\u7684\u603b\u8bf7\u6c42\u6570)<\/li>\n<\/ul>\n<p>\u4e00\u4e2a Metric \u603b\u5e94\u8be5\u4ee5\u5176\u5355\u4f4d\u7684\u590d\u6570\u5f62\u5f0f\u4e3a\u540e\u7f00, \u5e76\u4e14\u5355\u4f4d\u5e94\u8be5\u5c3d\u91cf\u7edf\u4e00, \u5982\u679c\u662f\u4e00\u4e2a\u7d2f\u79ef\u7684\u8ba1\u6570, \u603b\u5e94\u8be5\u4f7f\u7528 <code>total<\/code><\/p>\n<ul>\n<li>node_memory_usage_<strong>bytes<\/strong><\/li>\n<li>http_requests_<strong>total<\/strong><\/li>\n<li>process_cpu_<strong>seconds_total<\/strong><\/li>\n<\/ul>\n<h2 id=\"zhua-qu-she-zhi\"><a class=\"zola-anchor\" href=\"#zhua-qu-she-zhi\" aria-label=\"Anchor link for: zhua-qu-she-zhi\">\u6293\u53d6\u8bbe\u7f6e<\/a><\/h2>\n<p>\u901a\u8fc7 <code>Prometheus Operator<\/code> \u7684 <code>ServiceMonitor<\/code> \u5bf9\u8c61, \u53ef\u4ee5\u76f8\u5bf9\u4fbf\u6377\u7684, \u901a\u8fc7\u4e0d\u76f4\u63a5\u4fee\u6539 prometheus config \u7684\u65b9\u5f0f\u6dfb\u52a0\u6293\u53d6\u76ee\u6807.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"yaml\"><span class=\"giallo-l\"><span class=\"z-l-3 z-d-5\">a<\/span><span class=\"z-l-3 z-d-5\">piVersion<\/span><span>:<\/span><span class=\"z-l-2 z-d-6\"> m<\/span><span class=\"z-l-2 z-d-6\">onitoring.coreos.com\/v1<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-5\">k<\/span><span class=\"z-l-3 z-d-5\">ind<\/span><span>:<\/span><span class=\"z-l-2 z-d-6\"> S<\/span><span class=\"z-l-2 z-d-6\">erviceMonitor<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-5\">m<\/span><span class=\"z-l-3 z-d-5\">etadata<\/span><span>:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-5\">  n<\/span><span class=\"z-l-3 z-d-5\">ame<\/span><span>:<\/span><span class=\"z-l-2 z-d-6\"> e<\/span><span class=\"z-l-2 z-d-6\">xample-service-monitor<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-5\">  l<\/span><span class=\"z-l-3 z-d-5\">abels<\/span><span>:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-5\">    t<\/span><span class=\"z-l-3 z-d-5\">eam<\/span><span>:<\/span><span class=\"z-l-2 z-d-6\"> o<\/span><span class=\"z-l-2 z-d-6\">ps<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-5\">s<\/span><span class=\"z-l-3 z-d-5\">pec<\/span><span>:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-5\">  s<\/span><span class=\"z-l-3 z-d-5\">elector<\/span><span>:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-5\">    m<\/span><span class=\"z-l-3 z-d-5\">atchLabels<\/span><span>:<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-5\">      s<\/span><span class=\"z-l-3 z-d-5\">vc-label-key<\/span><span>:<\/span><span class=\"z-l-2 z-d-6\"> s<\/span><span class=\"z-l-2 z-d-6\">vc-label-value<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-3 z-d-5\">  e<\/span><span class=\"z-l-3 z-d-5\">ndpoints<\/span><span>:<\/span><\/span>\n<span class=\"giallo-l\"><span>  -<\/span><span class=\"z-l-3 z-d-5\"> p<\/span><span class=\"z-l-3 z-d-5\">ort<\/span><span>:<\/span><span class=\"z-l-1 z-d-4\"> 80<\/span><\/span>\n<span class=\"giallo-l\"><span>  -<\/span><span class=\"z-l-3 z-d-5\"> p<\/span><span class=\"z-l-3 z-d-5\">ath<\/span><span>:<\/span><span class=\"z-l-2 z-d-6\"> \/<\/span><span class=\"z-l-2 z-d-6\">metrics<\/span><\/span><\/code><\/pre>\n<p>\u4e0a\u9762\u7684\u5b9e\u4f8b\u6307\u5b9a\u4e86\u4e00\u4e2a\u540d\u4e3a example-service-monitor \u7684 <code>ServiceMonitor<\/code>, \u5b83\u4f1a\u9009\u62e9\u6240\u6709 svc-label-key \u7684\u503c\u4e3a svc-label-value \u7684 Service \u8fdb\u884c\u76d1\u63a7, \u76ee\u6807\u7aef\u53e3\u4e3a 80, HTTP \u8def\u5f84\u4e3a \/metrics. Service \u80cc\u540e\u53ef\u80fd\u5b58\u5728\u8d85\u8fc7\u4e00\u4e2a\u7684\u65e0\u72b6\u6001\u7684 Pod, \u4ed6\u4eec\u4f1a\u88ab\u81ea\u52a8\u53d1\u73b0.<\/p>\n<p><code>Prometheus Operator<\/code> \u4f1a\u89e3\u6790 <code>ServiceMonitor<\/code> \u5bf9\u8c61, \u751f\u6210\u76f8\u5e94\u7684\u6293\u53d6\u8bbe\u7f6e\u5230 prometheus config.<\/p>\n<h2 id=\"zhi-biao-xuan-ze\"><a class=\"zola-anchor\" href=\"#zhi-biao-xuan-ze\" aria-label=\"Anchor link for: zhi-biao-xuan-ze\">\u6307\u6807\u9009\u62e9<\/a><\/h2>\n<p>\u4e00\u822c exporter \u4f1a\u91c7\u96c6\u5f88\u591a\u7684\u6307\u6807, \u6bd4\u5982 jvm \u7684\u8fd0\u884c\u60c5\u51b5, http \u8bf7\u6c42\u60c5\u51b5\u7b49\u7b49. Google \u5728 <code>SRE Handbook<\/code> \u4e2d\u63d0\u51fa\u4e86\u56db\u4e2a\u9ec4\u91d1\u4fe1\u53f7: \u5ef6\u8fdf, \u6d41\u91cf, \u9519\u8bef\u6570, \u9971\u548c\u5ea6. \u5b9e\u9645\u64cd\u4f5c\u4e2d\u53ef\u4ee5\u4f7f\u7528 <code>USE<\/code> \u6216 <code>RED<\/code> \u65b9\u6cd5\u4f5c\u4e3a\u6307\u5bfc, <code>USE(Utilization, Saturation, Errors)<\/code> \u7528\u4e8e\u8d44\u6e90, <code>RED(Rate, Errors, Duration)<\/code> \u7528\u4e8e\u670d\u52a1.<\/p>\n<p>\u4e00\u822c\u7684\u5728\u7ebf\u670d\u52a1, \u6bd4\u5982 Web \u670d\u52a1, \u6570\u636e\u5e93\u7b49, \u4e00\u822c\u5173\u5fc3\u8bf7\u6c42\u901f\u7387, \u5ef6\u8fdf\u548c\u9519\u8bef\u7387, \u4f7f\u7528 RED \u65b9\u6cd5; \u4e00\u822c\u7684\u79bb\u7ebf\u670d\u52a1, \u5982\u65e5\u5fd7\u5904\u7406, \u6d88\u606f\u961f\u5217\u7b49, \u4e00\u822c\u5173\u6ce8\u961f\u5217\u6570\u91cf, \u8fdb\u884c\u4e2d\u7684\u6570\u91cf, \u5904\u7406\u901f\u5ea6\u4ee5\u53ca\u53d1\u751f\u7684\u9519\u8bef, \u4f7f\u7528 USE \u65b9\u6cd5.<\/p>\n<h3 id=\"rate-su-lu\"><a class=\"zola-anchor\" href=\"#rate-su-lu\" aria-label=\"Anchor link for: rate-su-lu\">Rate \u901f\u7387<\/a><\/h3>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>sum(rate(http_server_requests_seconds_count[5m])) by (method, uri, job)<\/span><\/span><\/code><\/pre>\n<p>\u7edf\u8ba1\u8bbf\u95ee\u7684 QPS<\/p>\n<h3 id=\"errors-cuo-wu\"><a class=\"zola-anchor\" href=\"#errors-cuo-wu\" aria-label=\"Anchor link for: errors-cuo-wu\">Errors \u9519\u8bef<\/a><\/h3>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>rate(http_server_requests_seconds_count{status=~&quot;^5..$&quot;}[5m]) \/ rate(http_server_requests_seconds_count[5m])<\/span><\/span><\/code><\/pre>\n<p>\u7edf\u8ba1 HTTP \u72b6\u6001\u7801\u4e3a 5xx \u7684\u6bd4\u4f8b<\/p>\n<h3 id=\"duration-qing-qiu-shi-jian\"><a class=\"zola-anchor\" href=\"#duration-qing-qiu-shi-jian\" aria-label=\"Anchor link for: duration-qing-qiu-shi-jian\">Duration \u8bf7\u6c42\u65f6\u95f4<\/a><\/h3>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>sum by (job, uri, method) (rate(http_server_requests_seconds_sum[5m]) \/ rate(http_server_requests_seconds_count[5m]))<\/span><\/span><\/code><\/pre>\n<p>\u7edf\u8ba1\u5e73\u5747\u8bf7\u6c42\u65f6\u95f4<\/p>\n<h2 id=\"can-kao-zi-liao\"><a class=\"zola-anchor\" href=\"#can-kao-zi-liao\" aria-label=\"Anchor link for: can-kao-zi-liao\">\u53c2\u8003\u8d44\u6599<\/a><\/h2>\n<p><a rel=\"external\" href=\"https:\/\/prometheus.io\/docs\/introduction\/overview\/\">What is Prometheus?<\/a><\/p>\n<p><a rel=\"external\" href=\"https:\/\/peter.bourgon.org\/blog\/2017\/02\/21\/metrics-tracing-and-logging.html\">Metrics, tracing, and logging<\/a><\/p>\n<p><a rel=\"external\" href=\"https:\/\/yasongxu.gitbook.io\/container-monitor\/\">container-monitor-book<\/a><\/p>\n"},{"title":"\u4e00\u4e2a\u79bb\u804c\u5c0f\u8bb0","published":"2021-06-06T23:29:39+08:00","updated":"2021-06-06T23:29:39+08:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/job-hopping\/"}},"id":"https:\/\/memwey.github.io\/posts\/job-hopping\/","content":"<p>\u4ece\u4e00\u5bb6\u521b\u4e1a\u516c\u53f8\u79bb\u804c, \u53bb\u53e6\u5916\u4e00\u5bb6\u521b\u4e1a\u516c\u53f8.<\/p>\n<p>\u5728\u5bb6\u5f85\u4e86\u4e00\u4e2a\u6708\u591a\u4e00\u70b9, \u671f\u95f4\u89e3\u51b3\u4e86\u4e00\u4e0b\u5bb6\u91cc\u7684\u5927\u4e8b\u5c0f\u60c5, \u590d\u4e60\u5237\u9898\u548c\u9762\u8bd5, \u5f00\u59cb\u5df4\u897f\u67d4\u672f\u7684\u5b66\u4e60, \u63a7\u5236\u996e\u98df\u548c\u8fd0\u52a8, \u5237 <code>Bilibili<\/code> \u4ec0\u4e48\u7684. \u7136\u800c\u6700\u91cd\u8981\u7684\u5a5a\u793c\u56e0\u4e3a\u7a81\u5982\u5176\u6765\u7684\u75ab\u60c5\u53ea\u80fd\u88ab\u8feb\u5ef6\u540e\u4e86.<\/p>\n<p>\u4e0d\u5f97\u4e0d\u8bf4, \u5e7f\u5dde\u7684\u673a\u4f1a\u771f\u7684\u4e0d\u591a. \u4e00\u5f00\u59cb\u627e\u4e86\u51e0\u5bb6\u4e2d\u7b49\u7ea7\u522b\u7684\u516c\u53f8\u9762\u8bd5\u7ec3\u624b, \u7ed3\u679c\u53d1\u73b0\u6ca1\u6709\u8fbe\u5230\u90a3\u79cd\u9762\u7684\u6211\u6000\u7591\u4eba\u751f\u7136\u540e\u52aa\u529b\u590d\u4e60\u7684\u7ed3\u679c, \u968f\u624b\u5c31\u9762\u8fc7, \u56de\u5bb6\u63a5\u7740\u6478\u9c7c. \u7136\u540e\u62b1\u6709\u6bd4\u8f83\u5927\u5e0c\u671b\u7684\u817e\u8baf\u548c\u5b57\u8282\u90fd\u56e0\u4e3a\u5404\u79cd\u5404\u6837\u5947\u602a\u7684\u539f\u56e0\u8fde\u9762\u8bd5\u90fd\u6ca1\u6709, \u4e0d\u5f97\u4e0d\u8bf4\u548c\u67d0\u4e9b\u516c\u53f8\u5c31\u662f\u6ca1\u6709\u7f18\u5206.<\/p>\n<h2 id=\"chi-kai-de-yuan-yin\"><a class=\"zola-anchor\" href=\"#chi-kai-de-yuan-yin\" aria-label=\"Anchor link for: chi-kai-de-yuan-yin\">\u79bb\u5f00\u7684\u539f\u56e0<\/a><\/h2>\n<p>\u5176\u5b9e\u6211\u89c9\u5f97\u8fd8\u662f\u79bb\u5f00\u4e0a\u4e00\u5bb6\u516c\u53f8\u7684\u592a\u8fdf\u4e86. \u5e74\u521d\u62ff\u5230 <a rel=\"external\" href=\"https:\/\/www.edison.tech\/\">Edison<\/a> \u7684 Offer \u7684\u65f6\u5019\u5c31\u5e94\u8be5\u79bb\u5f00\u4e86.<\/p>\n<p>\u6709\u79cd\u89c2\u70b9\u8ba4\u4e3a, \u5bf9\u4e8e\u4e00\u4e2a\u521b\u4e1a\u6765\u8bf4, \u6700\u91cd\u8981\u7684\u662f\u56e2\u961f, \u5c24\u5176\u662f\u6700\u521d\u5171\u540c\u521b\u4e1a\u7684\u56e2\u961f, \u4e1a\u52a1\u90fd\u662f\u5728\u5176\u6b21. \u4f46\u662f\u4e0a\u4e00\u5bb6\u516c\u53f8\u5728\u53bb\u5e74\u7b2c\u4e09\u5b63\u5ea6\u7684\u65f6\u5019\u5c31\u51fa\u73b0\u4e86\u4e00\u6ce2\u79bb\u804c\u6f6e, \u57fa\u672c\u4e0a\u6240\u6709\u4f5c\u4e3a\u516c\u53f8\u521b\u59cb\u6210\u5458\u7684\u8001\u5458\u5de5\u90fd\u79bb\u804c\u4e86. \u66fe\u7ecf\u5de5\u8d44\u90fd\u53d1\u4e0d\u51fa\u6765\u7684\u65f6\u671f\u6ca1\u6709\u79bb\u5f00, \u73b0\u5728\u62ff\u5230\u878d\u8d44\u4e86\u4e1a\u52a1\u6709\u4e00\u4e9b\u7709\u76ee\u4e86\u53cd\u800c\u79bb\u5f00\u4e86, \u53ef\u80fd\u8fd9\u5c31\u662f\u53ef\u4ee5\u5171\u60a3\u96be\u800c\u4e0d\u80fd\u540c\u5bcc\u8d35\u5427.<\/p>\n<p>\u5f53\u7136\u53ef\u80fd\u5e76\u4e0d\u662f\u94b1\u7684\u95ee\u9898. \u8001\u677f\u81ea\u5df1\u627f\u8ba4\u81ea\u5df1\u6709\u66b4\u529b\u6c9f\u901a\u7684\u95ee\u9898. \u4e0d\u8fc7, \u80fd\u4e0d\u80fd\u8ba4\u8bc6\u5230\u662f\u4e00\u56de\u4e8b, \u80fd\u4e0d\u80fd\u63a7\u5236\u662f\u53e6\u5916\u4e00\u56de\u4e8b. \u4eba\u603b\u4e0d\u53ef\u80fd\u4e0d\u72af\u9519, \u5f80\u597d\u4e86\u8bf4\u662f\u8001\u677f\u771f\u6027\u60c5, \u5f80\u574f\u4e86\u8bf4\u5c31\u662f\u8001\u677f\u6293\u4f4f\u4e00\u70b9\u9519\u8bef\u5c31\u5927\u505a\u6587\u7ae0, \u54ed\u7239\u9a82\u5a18\u4ec0\u4e48\u7684.<\/p>\n<p>\u521b\u4e1a\u6709\u4e00\u4e2a\u76f8\u5f53\u4e0d\u597d\u5e73\u8861\u7684\u95ee\u9898. \u521b\u4e1a\u516c\u53f8\u5f53\u7136\u5e0c\u671b\u56e2\u961f\u6210\u5458\u80fd\u529b\u8d85\u7fa4, \u80fd\u89e3\u51b3\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898, \u4f46\u662f\u9664\u4e86\u5c11\u6570\u5e26\u6709\u5149\u73af\u7684\u521b\u4e1a\u516c\u53f8, \u8d44\u91d1\u4e00\u822c\u90fd\u4e0d\u662f\u90a3\u4e48\u5145\u88d5\u7684. \u5bf9\u4e8e\u4f18\u79c0\u7684\u6c42\u804c\u8005\u6765\u8bf4, \u65e2\u7136\u662f\u521b\u4e1a, \u98ce\u9669\u66f4\u9ad8, \u4e3a\u4f55\u8981\u653e\u5f03\u5dee\u4e0d\u591a\u751a\u81f3\u66f4\u4f4e\u7684\u77ed\u671f\u56de\u62a5, \u6765\u627f\u62c5\u66f4\u9ad8\u7684\u98ce\u9669\u5462. \u8fd9\u4e5f\u662f\u4e0a\u9762\u63d0\u5230\u7684\u6700\u521d\u5171\u540c\u521b\u4e1a\u7684\u56e2\u961f\u975e\u5e38\u91cd\u8981\u7684\u539f\u56e0\u4e4b\u4e00.<\/p>\n<p>\u5728\u4e0a\u4e00\u5bb6\u516c\u53f8, \u8001\u677f\u53ef\u80fd\u662f\u60f3\u51fa\u4e86\u89e3\u51b3\u529e\u6cd5. \u56e2\u961f\u4e2d\u5c11\u6570\u7684\u4f18\u79c0\u5458\u5de5\u8d1f\u8d23, \u5e26\u9886\u4e00\u4e9b\u80fd\u529b\u4e00\u822c\u7684\u5458\u5de5. \u4f5c\u4e3a\u540e\u7aef\u8d1f\u8d23\u4eba, \u7ecf\u5e38\u68b3\u7406\u4ea7\u54c1\u8bbe\u8ba1, \u56e2\u961f\u4ee3\u7801\u5ba1\u67e5\u5c31\u628a\u5de5\u4f5c\u65f6\u95f4\u5360\u6ee1\u4e86, \u5199\u4ee3\u7801\u53ea\u80fd\u52a0\u73ed. \u6709\u6b21\u79c1\u4e0b\u8ddf\u8001\u677f\u5410\u69fd\u4e00\u4e2a\u4ea7\u54c1\u7ecf\u7406, \u6839\u672c\u53d1\u73b0\u4e0d\u4e86\u7528\u6237\u9700\u6c42, \u4e00\u4e2a\u529f\u80fd\u4e0a\u7ebf\u4e86\u56db\u4e94\u7248, \u90fd\u89e3\u51b3\u4e0d\u4e86\u7528\u6237\u7684\u95ee\u9898. \u8001\u677f\u4e00\u53e5\u8bdd\u9876\u56de\u6765\u4e86: \u4f60\u77e5\u9053\u5979\u4e00\u4e2a\u6708\u591a\u5c11\u94b1\u5417, \u4e94\u5343.<\/p>\n<p>\u5728\u8fd9\u79cd\u540c\u4e8b\u80fd\u529b\u53c2\u5dee, \u800c\u8001\u677f\u6709\u65f6\u53c8\u683c\u5916\u82db\u8d23\u7684\u60c5\u51b5\u4e0b, \u538b\u529b\u786e\u5b9e\u6bd4\u8f83\u5927, \u60c5\u7eea\u6bd4\u8f83\u6d88\u6c89, \u6709\u6bb5\u65f6\u95f4\u5929\u5929\u60f3\u8bf7\u5047, \u60f3\u5230\u8981\u53bb\u4e0a\u73ed\u5c31\u5934\u75bc. \u6700\u7ec8\u8fd8\u662f\u51b3\u5b9a\u79bb\u804c\u4e86.<\/p>\n<h2 id=\"xuan-ze-de-yuan-yin\"><a class=\"zola-anchor\" href=\"#xuan-ze-de-yuan-yin\" aria-label=\"Anchor link for: xuan-ze-de-yuan-yin\">\u9009\u62e9\u7684\u539f\u56e0<\/a><\/h2>\n<p>\u53c8\u6765\u5230\u4e00\u5bb6\u521b\u4e1a\u516c\u53f8\u5176\u5b9e\u81ea\u5df1\u90fd\u86ee\u6ca1\u60f3\u5230\u7684, \u6bd5\u7adf\u6700\u521d\u7684\u6784\u60f3\u662f\u53bb\u5927\u516c\u53f8\u505a\u4e00\u4e9b\u57fa\u7840\u67b6\u6784\u7684\u5f00\u53d1, \u8fdc\u79bb\u67af\u71e5\u91cd\u590d\u7684\u4e1a\u52a1\u5f00\u53d1.<\/p>\n<p>\u8fd9\u5bb6\u516c\u53f8\u6700\u5438\u5f15\u7684\u53ef\u80fd\u5c31\u662f\u5fae\u4fe1\u9876\u7ea7\u4ea7\u54c1\u7ecf\u7406\u5e26\u961f\u5427. \u8fd9\u51e0\u5e74\u7684\u5de5\u4f5c\u4e5f\u7b97\u662f\u63a5\u89e6\u8fc7\u4e0d\u5c11\u4ea7\u54c1\u7ecf\u7406, \u6709\u5389\u5bb3\u7684\u4e5f\u6709\u6c34\u5e73\u4e00\u822c\u7684, \u611f\u89c9\u4ea7\u54c1\u7ecf\u7406\u662f\u4e00\u4e2a\u6709\u624b\u5c31\u80fd\u505a\u7684\u804c\u4e1a, \u4f46\u662f\u6c34\u5e73\u9ad8\u7684\u4ea7\u54c1\u7ecf\u7406\u786e\u5b9e\u65e0\u6cd5\u66ff\u4ee3. \u60f3\u8fd1\u8ddd\u79bb\u63a5\u89e6\u4e00\u4e0b\u4f20\u8bf4\u4e2d\u7684\u5fae\u4fe1\u4e4b\u6bcd, \u76f4\u63a5\u5411\u5f20\u5c0f\u9f99\u6c47\u62a5\u7684\u4ea7\u54c1\u7ecf\u7406, \u770b\u770b\u5979\u4eec\u7684\u601d\u7ef4\u548c\u505a\u4e8b\u662f\u4ec0\u4e48\u6837\u7684.<\/p>\n<p>\u53e6\u5916, \u8fd9\u5bb6\u516c\u53f8\u5149\u73af\u6bd4\u8f83\u5f3a, \u8d44\u91d1\u6bd4\u8f83\u5145\u8db3, \u85aa\u916c\u798f\u5229\u4ec0\u4e48\u7684\u90fd\u633a\u4e0d\u9519\u7684, \u5b8c\u7f8e\u7684\u89e3\u51b3\u4e86\u521b\u4e1a\u516c\u53f8\u7684\u4e00\u4e9b\u95ee\u9898.<\/p>\n<p>\u4e0d\u8fc7\u4e2a\u4eba\u8fd8\u662f\u89c9\u5f97\u5728\u76ee\u524d\u516c\u53f8\u4e3b\u8981\u4ea7\u54c1\u4e0a, \u6709\u4e00\u4e9b\u9690\u60a3, \u5728\u719f\u4ebaIM\u548c\u964c\u751f\u4eba\u793e\u4ea4\u4e0a\u6709\u70b9\u5b9a\u4f4d\u4e0d\u6e05. \u800c\u4e14\u5728\u719f\u4ebaIM\u4e0a, \u5f88\u96be\u770b\u5230\u77ed\u671f\u5185\u7684\u76c8\u5229\u7a7a\u95f4. \u4f46\u662f\u6bd5\u7adf\u4e0d\u662f\u4e13\u4e1a\u7684\u4ea7\u54c1\u7ecf\u7406, \u6240\u6709\u7684\u770b\u6cd5\u90fd\u662f\u57fa\u4e8e\u5df2\u6709\u7684\u4ea7\u54c1, \u6bd4\u5982\u5fae\u4fe1, \u964c\u964c, Soul \u4ec0\u4e48\u7684. \u5389\u5bb3\u7684\u4ea7\u54c1\u7ecf\u7406\u53ef\u4ee5\u53d1\u73b0\u522b\u4eba\u53d1\u73b0\u4e0d\u5230\u7684\u9700\u6c42, \u4e07\u4e00\u5462.<\/p>\n"},{"title":"Redis ZINTERSTORE","published":"2021-04-21T20:30:43+08:00","updated":"2021-04-21T20:30:43+08:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/redis-zinterstore\/"}},"id":"https:\/\/memwey.github.io\/posts\/redis-zinterstore\/","content":"<h2 id=\"jie-gou-tui-ce\"><a class=\"zola-anchor\" href=\"#jie-gou-tui-ce\" aria-label=\"Anchor link for: jie-gou-tui-ce\">\u7ed3\u6784\u63a8\u6d4b<\/a><\/h2>\n<p>\u4eca\u5929\u4e0e\u4eba\u4e89\u6267\u7684\u65f6\u5019\u89c9\u5f97\u5e94\u8be5\u63a2\u7a76\u4e00\u4e0b <code>Redis<\/code> \u4e2d <code>ZINTERSTORE<\/code> \u7684\u5b9e\u73b0. \u5148\u770b\u6587\u6863\u4e2d\u7684\u63cf\u8ff0<\/p>\n<blockquote>\n<p>ZINTERSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]<\/p>\n<\/blockquote>\n<blockquote>\n<p>Available since 2.0.0.<\/p>\n<p>Time complexity: O(N<em>K)+O(M<\/em>log(M)) worst case with N being the smallest input sorted set, K being the number of input sorted sets and M being the number of elements in the resulting sorted set.<\/p>\n<\/blockquote>\n<p>\u5927\u81f4\u610f\u601d\u5c31\u662f\u6700\u574f\u60c5\u51b5\u4e0b\u65f6\u95f4\u590d\u6742\u5ea6\u662f <code>O(N*K)+O(M*log(M))<\/code>, \u5176\u4e2d <code>N<\/code> \u662f\u8f93\u5165\u4e2d\u5143\u7d20\u6700\u5c11\u7684 <code>sorted set<\/code> \u7684\u5143\u7d20\u6570\u76ee, <code>K<\/code> \u662f\u8f93\u5165\u7684 <code>sorted set<\/code> \u7684\u6570\u91cf, <code>M<\/code> \u662f\u7ed3\u679c\u4e2d\u7684 <code>sorted set<\/code> \u4e2d\u5143\u7d20\u7684\u6570\u76ee.<\/p>\n<p>\u5176\u5b9e\u5149\u4ece\u65f6\u95f4\u590d\u6742\u5ea6\u5c31\u80fd\u63a8\u6d4b\u51fa\u6765\u5927\u81f4\u7684\u64cd\u4f5c\u4e86. <code>O(M*log(M))<\/code> \u8fd9\u4e2a\u590d\u6742\u5ea6\u5f88\u6709\u53ef\u80fd\u662f\u4e00\u6b21\u6392\u5e8f\u64cd\u4f5c, \u800c\u4e14\u548c\u7ed3\u679c\u4e2d\u7684\u5143\u7d20\u6570\u76ee\u76f8\u5173, \u90a3\u4e48\u5f88\u6709\u53ef\u80fd\u662f\u5148\u53d6\u4ea4\u96c6\u4e4b\u540e\u5f97\u51fa <code>M<\/code> \u4e2a\u5143\u7d20, \u518d\u5728 <code>M<\/code> \u4e2a\u5143\u7d20\u4e2d\u8fdb\u884c\u6392\u5e8f\u7684. \u5f53\u7136, \u4e5f\u6709\u53ef\u80fd\u662f\u76f8\u5e94\u7684, \u5728\u6709\u5e8f\u7684\u5e8f\u5217\u4e2d\u8fdb\u884c\u63d2\u5165\u7684\u64cd\u4f5c.<\/p>\n<p>\u800c <code>N<\/code> \u662f\u6700\u5c0f\u7684 <code>sorted set<\/code> \u7684\u5143\u7d20\u4e2a\u6570. \u8fd9\u4e2a\u4e00\u5f00\u59cb\u6211\u6709\u70b9\u60f3\u4e0d\u660e\u767d, \u96be\u9053\u4e0d\u5e94\u8be5\u662f\u6700\u5927\u7684\u624d\u5bf9\u5417, \u56e0\u4e3a\u8fd9\u91cc\u6211\u8fd8\u662f\u60f3\u7740\u53bb\u904d\u5386\u5176\u4ed6\u7684 <code>sorted set<\/code> \u8fdb\u884c\u6bd4\u8f83. \u4f46\u662f\u601d\u8003\u4e00\u4e0b, <code>sorted set<\/code> \u4e5f\u662f <code>set<\/code> \u561b, \u5b8c\u5168\u53ef\u4ee5\u4f7f\u7528 <code>O(1)<\/code> \u7684\u6548\u7387\u5728\u5176\u4e2d\u8fdb\u884c\u67e5\u627e. \u8fd9\u6837\u5b9e\u9645\u5c31\u53d8\u6210\u4e86\u5206\u522b\u5728 (K - 1) \u4e2a <code>sorted set<\/code> \u4e2d\u5bfb\u627e <code>N<\/code> \u4e2a\u5143\u7d20, \u8fd9\u6837\u81ea\u7136\u5c31\u662f <code>O(N*K)<\/code> \u4e86.<\/p>\n<h2 id=\"yuan-ma-fen-xi\"><a class=\"zola-anchor\" href=\"#yuan-ma-fen-xi\" aria-label=\"Anchor link for: yuan-ma-fen-xi\">\u6e90\u7801\u5206\u6790<\/a><\/h2>\n<p>\u4ee5\u4e0b\u6e90\u7801\u57fa\u4e8e <code>Redis 3.0<\/code> \u5206\u6790, \u5b9e\u9645\u7684\u51fd\u6570\u64cd\u4f5c\u4e3a<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"c\"><span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/*<\/span><span class=\"z-l-5 z-d-3\"> https:\/\/github.com\/redis\/redis\/blob\/3.0\/src\/t_zset.c#L1905 <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">void<\/span><span class=\"z-l-6 z-d-7\"> zunionInterGenericCommand<\/span><span>(<\/span><span>redisClient <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-9 z-d-12\">c<\/span><span>,<\/span><span> robj <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-9 z-d-12\">dstkey<\/span><span>,<\/span><span class=\"z-l-8 z-d-10\"> int<\/span><span class=\"z-l-9 z-d-12\"> op<\/span><span>)<\/span><\/span><\/code><\/pre>\n<p>\u8fd9\u91cc\u6211\u4eec\u53ef\u4ee5\u770b\u5230, \u5728 <code>Redis<\/code> \u7684\u6e90\u7801\u4e2d\u5c06 <code>ZINTERSTORE<\/code> \u548c <code>ZUNIONSTORE<\/code> \u653e\u5728\u4e86\u4e00\u8d77\u5904\u7406, \u4f7f\u7528 <code>op<\/code> \u505a\u533a\u5206.<\/p>\n<p>\u968f\u540e\u662f\u4e00\u6bb5\u6f2b\u957f\u7684\u4ee3\u7801, \u4e3b\u8981\u662f\u5904\u7406\u8f93\u5165\u53c2\u6570\u7684, \u6bd4\u5982\u8981\u64cd\u4f5c\u7684 <code>sorted set<\/code> \u7684\u5217\u8868, \u5b58\u5230\u4e86 <code>src<\/code> \u4e2d; \u7136\u540e\u5904\u7406 <code>WEIGHTS<\/code> \u548c <code>AGGREGATE<\/code>. \u4ee3\u7801\u6bd4\u8f83\u957f\u800c\u4e14\u903b\u8f91\u4e5f\u5f88\u7b80\u5355.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"c\"><span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/*<\/span><span class=\"z-l-5 z-d-3\"> https:\/\/github.com\/redis\/redis\/blob\/3.0\/src\/t_zset.c#L1993 <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">    \/*<\/span><span class=\"z-l-5 z-d-3\"> sort sets from the smallest to largest, this will improve our<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">     * algorithm&#39;s performance <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">    qsort<\/span><span>(<\/span><span>src<\/span><span>,<\/span><span>setnum<\/span><span>,<\/span><span class=\"z-l-8 z-d-10\">sizeof<\/span><span>(<\/span><span>zsetopsrc<\/span><span>)<\/span><span>,<\/span><span>zuiCompareByCardinality<\/span><span>)<\/span><span>;<\/span><\/span><\/code><\/pre>\n<p>\u7136\u540e\u8fd9\u91cc\u628a\u6240\u6709 <code>sorted set<\/code> \u6309\u5143\u7d20\u7684\u4e2a\u6570\u4ece\u5c0f\u5230\u5927\u6392\u5217, \u4ee5\u63d0\u9ad8\u6548\u7387. \u968f\u540e\u662f\u5177\u4f53\u7684\u53d6\u4ea4\u96c6\u7684\u4ee3\u7801.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"c\"><span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/*<\/span><span class=\"z-l-5 z-d-3\"> https:\/\/github.com\/redis\/redis\/blob\/3.0\/src\/t_zset.c#L2001 <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    if<\/span><span> (<\/span><span>op <\/span><span class=\"z-l-8 z-d-10\">==<\/span><span> REDIS_OP_INTER<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">        \/*<\/span><span class=\"z-l-5 z-d-3\"> Skip everything if the smallest input is empty. <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        if<\/span><span> (<\/span><span class=\"z-l-6 z-d-7\">zuiLength<\/span><span>(<\/span><span class=\"z-l-8 z-d-10\">&amp;<\/span><span class=\"z-l-9 z-d-12\">src<\/span><span>[<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>]<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\"> &gt;<\/span><span class=\"z-l-1 z-d-4\"> 0<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">            \/*<\/span><span class=\"z-l-5 z-d-3\"> Precondition: as src[0] is non-empty and the inputs are ordered<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">             * by size, all src[i &gt; 0] are non-empty too. <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">            zuiInitIterator<\/span><span>(<\/span><span class=\"z-l-8 z-d-10\">&amp;<\/span><span class=\"z-l-9 z-d-12\">src<\/span><span>[<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>]<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">            while<\/span><span> (<\/span><span class=\"z-l-6 z-d-7\">zuiNext<\/span><span>(<\/span><span class=\"z-l-8 z-d-10\">&amp;<\/span><span class=\"z-l-9 z-d-12\">src<\/span><span>[<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>]<\/span><span>,<\/span><span class=\"z-l-8 z-d-10\">&amp;<\/span><span>zval<\/span><span>)<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                double<\/span><span> score<\/span><span>,<\/span><span> value<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>                score <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-9 z-d-12\"> src<\/span><span>[<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>]<\/span><span>.<\/span><span>weight<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span> zval<\/span><span>.<\/span><span>score<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                if<\/span><span> (<\/span><span class=\"z-l-6 z-d-7\">isnan<\/span><span>(<\/span><span>score<\/span><span>)<\/span><span>)<\/span><span> score <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-1 z-d-4\"> 0<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                for<\/span><span> (<\/span><span>j <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-1 z-d-4\"> 1<\/span><span>;<\/span><span> j <\/span><span class=\"z-l-8 z-d-10\">&lt;<\/span><span> setnum<\/span><span>;<\/span><span> j<\/span><span class=\"z-l-8 z-d-10\">++<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">                    \/*<\/span><span class=\"z-l-5 z-d-3\"> It is not safe to access the zset we are<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">                     * iterating, so explicitly check for equal object. <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                    if<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">src<\/span><span>[<\/span><span>j<\/span><span>]<\/span><span>.<\/span><span>subject<\/span><span class=\"z-l-8 z-d-10\"> ==<\/span><span class=\"z-l-9 z-d-12\"> src<\/span><span>[<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>]<\/span><span>.<\/span><span>subject<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>                        value <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span> zval<\/span><span>.<\/span><span>score<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-9 z-d-12\">src<\/span><span>[<\/span><span>j<\/span><span>]<\/span><span>.<\/span><span>weight<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">                        zunionInterAggregate<\/span><span>(<\/span><span class=\"z-l-8 z-d-10\">&amp;<\/span><span>score<\/span><span>,<\/span><span>value<\/span><span>,<\/span><span>aggregate<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>                    }<\/span><span class=\"z-l-8 z-d-10\"> else<\/span><span class=\"z-l-8 z-d-10\"> if<\/span><span> (<\/span><span class=\"z-l-6 z-d-7\">zuiFind<\/span><span>(<\/span><span class=\"z-l-8 z-d-10\">&amp;<\/span><span class=\"z-l-9 z-d-12\">src<\/span><span>[<\/span><span>j<\/span><span>]<\/span><span>,<\/span><span class=\"z-l-8 z-d-10\">&amp;<\/span><span>zval<\/span><span>,<\/span><span class=\"z-l-8 z-d-10\">&amp;<\/span><span>value<\/span><span>)<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>                        value <\/span><span class=\"z-l-8 z-d-10\">*=<\/span><span class=\"z-l-9 z-d-12\"> src<\/span><span>[<\/span><span>j<\/span><span>]<\/span><span>.<\/span><span>weight<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">                        zunionInterAggregate<\/span><span>(<\/span><span class=\"z-l-8 z-d-10\">&amp;<\/span><span>score<\/span><span>,<\/span><span>value<\/span><span>,<\/span><span>aggregate<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>                    }<\/span><span class=\"z-l-8 z-d-10\"> else<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                        break<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>                    }<\/span><\/span>\n<span class=\"giallo-l\"><span>                }<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">                \/*<\/span><span class=\"z-l-5 z-d-3\"> Only continue when present in every input. <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                if<\/span><span> (<\/span><span>j <\/span><span class=\"z-l-8 z-d-10\">==<\/span><span> setnum<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>                    tmp <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> zuiObjectFromValue<\/span><span>(<\/span><span class=\"z-l-8 z-d-10\">&amp;<\/span><span>zval<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>                    znode <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> zslInsert<\/span><span>(<\/span><span>dstzset<\/span><span>-&gt;<\/span><span>zsl<\/span><span>,<\/span><span>score<\/span><span>,<\/span><span>tmp<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">                    incrRefCount<\/span><span>(<\/span><span>tmp<\/span><span>)<\/span><span>;<\/span><span class=\"z-l-5 z-d-3\"> \/*<\/span><span class=\"z-l-5 z-d-3\"> added to skiplist <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">                    dictAdd<\/span><span>(<\/span><span>dstzset<\/span><span>-&gt;<\/span><span>dict<\/span><span>,<\/span><span>tmp<\/span><span>,<\/span><span class=\"z-l-8 z-d-10\">&amp;<\/span><span>znode<\/span><span>-&gt;<\/span><span>score<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">                    incrRefCount<\/span><span>(<\/span><span>tmp<\/span><span>)<\/span><span>;<\/span><span class=\"z-l-5 z-d-3\"> \/*<\/span><span class=\"z-l-5 z-d-3\"> added to dictionary <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                    if<\/span><span> (<\/span><span class=\"z-l-6 z-d-7\">sdsEncodedObject<\/span><span>(<\/span><span>tmp<\/span><span>)<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                        if<\/span><span> (<\/span><span class=\"z-l-6 z-d-7\">sdslen<\/span><span>(<\/span><span>tmp<\/span><span>-&gt;<\/span><span>ptr<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\"> &gt;<\/span><span> maxelelen<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>                            maxelelen <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> sdslen<\/span><span>(<\/span><span>tmp<\/span><span>-&gt;<\/span><span>ptr<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>                    }<\/span><\/span>\n<span class=\"giallo-l\"><span>                }<\/span><\/span>\n<span class=\"giallo-l\"><span>            }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">            zuiClearIterator<\/span><span>(<\/span><span class=\"z-l-8 z-d-10\">&amp;<\/span><span class=\"z-l-9 z-d-12\">src<\/span><span>[<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>]<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>        }<\/span><\/span>\n<span class=\"giallo-l\"><span>    }<\/span><\/span>\n<span class=\"giallo-l\"><\/span><\/code><\/pre>\n<p>\u5f53\u7136, \u5982\u679c\u6309\u5143\u7d20\u6570\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\u7684\u7b2c\u4e00\u4e2a <code>sorted set<\/code> \u5143\u7d20\u6570\u4e3a 0, \u90a3\u5c31\u53ef\u4ee5\u76f4\u63a5\u8fd4\u56de\u4e86, \u968f\u540e\u5728\u6b64 <code>sorted set<\/code> \u4e0a\u5efa\u7acb\u4e00\u4e2a <code>Iterator<\/code>, \u4e3b\u8981\u5c31\u662f\u5e2e\u52a9\u5728 <code>sorted set<\/code> \u4e0a\u505a\u904d\u5386\u7684, \u56e0\u4e3a\u5728 <code>sorted set<\/code> \u4e2d, \u904d\u5386\u4e0d\u662f\u4e00\u4e2a\u5e38\u7528\u64cd\u4f5c, \u6392\u5e8f\u624d\u662f.<\/p>\n<p>\u7136\u540e\u5c31\u662f\u901a\u8fc7 <code>while (zuiNext(&amp;src[0],&amp;zval))<\/code> \u53d6\u51fa\u7b2c\u4e00\u4e2a <code>sorted set<\/code> \u4e2d\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20, \u518d\u7528 <code>for (j = 1; j &lt; setnum; j++)<\/code> \u5c06\u5176\u5728\u6bcf\u4e00\u4e2a\u5176\u4ed6\u7684 <code>sorted set<\/code> \u4e2d\u67e5\u627e\u4e00\u904d.<\/p>\n<p>\u5f53\u4e24\u4e2a <code>sorted set<\/code> \u6307\u5411\u540c\u4e00\u4e2a\u5bf9\u8c61\u662f, \u90a3\u4e48\u6beb\u65e0\u7591\u95ee\u4e00\u5b9a\u4f1a\u6709\u540c\u6837\u7684\u5143\u7d20. \u5426\u5219\u5c31\u5728 <code>src[j]<\/code> \u4e2d\u67e5\u627e\u5f53\u524d\u5143\u7d20. <code>zuiFind(&amp;src[j],&amp;zval,&amp;value)<\/code> \u5b9e\u73b0\u4e86\u8fd9\u4e2a\u64cd\u4f5c. \u5177\u4f53\u7684\u4ee3\u7801\u5728\u540e\u9762\u5206\u6790. \u5982\u679c\u627e\u4e0d\u5230\u7684\u8bdd, \u5219\u6ca1\u6709\u5fc5\u8981\u7ee7\u7eed\u627e\u4e0b\u53bb\u4e86, \u8df3\u51fa\u5373\u53ef.<\/p>\n<p>\u67e5\u627e\u7684\u8fc7\u7a0b\u4e2d\u4e5f\u4f7f\u7528\u4e86 <code>zunionInterAggregate(&amp;score,value,aggregate)<\/code> \u6765\u66f4\u65b0\u5f53\u524d\u5143\u7d20\u7684 <code>score<\/code>, \u5177\u4f53\u7684 <code>score<\/code> \u66f4\u65b0\u89c4\u5219\u662f\u6839\u636e <code>AGGREGATE<\/code> \u53c2\u6570\u6765\u5b9a\u7684.<\/p>\n<p>\u5f53\u5143\u7d20\u5728\u6240\u6709\u7684 <code>sorted set<\/code> \u4e2d\u65f6, \u5c31\u53ef\u4ee5\u628a\u8fd9\u4e2a\u5143\u7d20\u6dfb\u52a0\u8fdb\u7ed3\u679c\u7684 <code>sorted set<\/code> \u4e2d\u4e86. \u8fd9\u91cc\u5c31\u662f\u6839\u636e <code>zval<\/code> \u548c <code>score<\/code> \u5f80 <code>dstzset<\/code> \u91cc\u9762\u63d2\u5165\u5143\u7d20. \u56e0\u4e3a <code>sorted set<\/code> \u91cc\u9762\u65e2\u6709 <code>dict<\/code> \u4e5f\u6709 <code>skiplist<\/code>, \u6240\u4ee5\u4e24\u4e2a\u90fd\u8981\u6dfb\u52a0.<\/p>\n<p>\u8fd9\u91cc\u8fd8\u6709\u4e00\u4e2a\u64cd\u4f5c\u5c31\u662f\u66f4\u65b0\u6700\u5927\u5143\u7d20\u7684\u957f\u5ea6, \u8fd9\u4e2a\u548c <code>sorted set<\/code> \u7684\u5185\u90e8\u4f18\u5316\u6709\u5173.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"c\"><span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/*<\/span><span class=\"z-l-5 z-d-3\"> https:\/\/github.com\/redis\/redis\/blob\/3.0\/src\/t_zset.c#L2119 <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    if<\/span><span> (<\/span><span class=\"z-l-6 z-d-7\">dbDelete<\/span><span>(<\/span><span>c<\/span><span class=\"z-l-8 z-d-10\">-<\/span><span class=\"z-l-8 z-d-10\">&gt;<\/span><span class=\"z-l-9 z-d-12\">db<\/span><span>,<\/span><span>dstkey<\/span><span>)<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">        signalModifiedKey<\/span><span>(<\/span><span>c<\/span><span>-&gt;<\/span><span>db<\/span><span>,<\/span><span>dstkey<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>        touched <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-1 z-d-4\"> 1<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>        server<\/span><span>.<\/span><span>dirty<\/span><span class=\"z-l-8 z-d-10\">++<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    if<\/span><span> (<\/span><span>dstzset<\/span><span class=\"z-l-8 z-d-10\">-<\/span><span class=\"z-l-8 z-d-10\">&gt;<\/span><span>zsl<\/span><span class=\"z-l-8 z-d-10\">-<\/span><span class=\"z-l-8 z-d-10\">&gt;<\/span><span>length<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">        \/*<\/span><span class=\"z-l-5 z-d-3\"> Convert to ziplist when in limits. <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        if<\/span><span> (<\/span><span>dstzset<\/span><span>-&gt;<\/span><span>zsl<\/span><span>-&gt;<\/span><span>length<\/span><span class=\"z-l-8 z-d-10\"> &lt;=<\/span><span> server<\/span><span>.<\/span><span>zset_max_ziplist_entries<\/span><span class=\"z-l-8 z-d-10\"> &amp;&amp;<\/span><\/span>\n<span class=\"giallo-l\"><span>            maxelelen <\/span><span class=\"z-l-8 z-d-10\">&lt;=<\/span><span> server<\/span><span>.<\/span><span>zset_max_ziplist_value<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">                zsetConvert<\/span><span>(<\/span><span>dstobj<\/span><span>,<\/span><span>REDIS_ENCODING_ZIPLIST<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">        dbAdd<\/span><span>(<\/span><span>c<\/span><span>-&gt;<\/span><span>db<\/span><span>,<\/span><span>dstkey<\/span><span>,<\/span><span>dstobj<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">        addReplyLongLong<\/span><span>(<\/span><span>c<\/span><span>,<\/span><span class=\"z-l-6 z-d-7\">zsetLength<\/span><span>(<\/span><span>dstobj<\/span><span>)<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        if<\/span><span> (<\/span><span class=\"z-l-8 z-d-10\">!<\/span><span>touched<\/span><span>)<\/span><span class=\"z-l-6 z-d-7\"> signalModifiedKey<\/span><span>(<\/span><span>c<\/span><span>-&gt;<\/span><span>db<\/span><span>,<\/span><span>dstkey<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">        notifyKeyspaceEvent<\/span><span>(<\/span><span>REDIS_NOTIFY_ZSET<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>            (<\/span><span>op <\/span><span class=\"z-l-8 z-d-10\">==<\/span><span> REDIS_OP_UNION<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\"> ?<\/span><span class=\"z-l-2 z-d-6\"> &quot;<\/span><span class=\"z-l-2 z-d-6\">zunionstore<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span class=\"z-l-8 z-d-10\"> :<\/span><span class=\"z-l-2 z-d-6\"> &quot;<\/span><span class=\"z-l-2 z-d-6\">zinterstore<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span>            dstkey<\/span><span>,<\/span><span>c<\/span><span>-&gt;<\/span><span>db<\/span><span>-&gt;<\/span><span>id<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>        server<\/span><span>.<\/span><span>dirty<\/span><span class=\"z-l-8 z-d-10\">++<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>    }<\/span><span class=\"z-l-8 z-d-10\"> else<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">        decrRefCount<\/span><span>(<\/span><span>dstobj<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">        addReply<\/span><span>(<\/span><span>c<\/span><span>,<\/span><span>shared<\/span><span>.<\/span><span>czero<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        if<\/span><span> (<\/span><span>touched<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">            notifyKeyspaceEvent<\/span><span>(<\/span><span>REDIS_NOTIFY_GENERIC<\/span><span>,<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span class=\"z-l-2 z-d-6\">del<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span>,<\/span><span>dstkey<\/span><span>,<\/span><span>c<\/span><span>-&gt;<\/span><span>db<\/span><span>-&gt;<\/span><span>id<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">    zfree<\/span><span>(<\/span><span>src<\/span><span>)<\/span><span>;<\/span><\/span><\/code><\/pre>\n<p>\u968f\u540e\u5c31\u662f\u6536\u5c3e\u5de5\u4f5c. \u5982\u679c\u76ee\u6807\u7684\u5751\u4e0a\u5df2\u7ecf\u6709\u503c\u4e86, \u5c31\u6beb\u4e0d\u72b9\u8c6b\u7684\u5e72\u6389\u5b83. \u7136\u540e\u518d\u770b\u4f5c\u4e3a\u7ed3\u679c\u7684 <code>sorted set<\/code>. \u5982\u679c\u5b83\u6ee1\u8db3\u8f6c\u5316\u4e3a <code>ziplist<\/code> \u7684\u6761\u4ef6, \u5c31\u53ef\u4ee5\u628a\u5b83\u8f6c\u5316\u4e3a <code>ziplist<\/code>. \u540e\u9762\u662f\u4e00\u4e9b <code>hook<\/code> \u7684\u901a\u77e5, \u53ef\u4ee5\u6682\u65f6\u5ffd\u7565. \u5982\u679c\u7ed3\u679c\u4e3a\u7a7a, <code>Integer reply<\/code> \u4f1a\u8fd4\u56de 0, \u5426\u5219\u4f1a\u8fd4\u56de\u7ed3\u679c\u4e2d\u5143\u7d20\u7684\u4e2a\u6570.<\/p>\n<p>\u81f3\u6b64\u5927\u81f4\u6d41\u7a0b\u5df2\u7ecf\u7ed3\u675f\u4e86. \u5982\u540c\u63a8\u6d4b\u7684\u90a3\u6837, \u7b97\u6cd5\u590d\u6742\u5ea6\u5b8c\u7f8e\u7684\u53cd\u6620\u4e86\u64cd\u4f5c\u7684\u5185\u90e8\u8fc7\u7a0b\u548c\u6570\u636e\u7ed3\u6784. \u4e0d\u8fc7, \u6211\u4eec\u8fd8\u6709\u51e0\u4e2a\u95ee\u9898\u6ca1\u6709\u89e3\u51b3. <code>zuiFind<\/code> \u4e2d\u7684\u5177\u4f53\u64cd\u4f5c\u662f\u4ec0\u4e48, <code>ziplist<\/code> \u53c8\u662f\u4ec0\u4e48.<\/p>\n<h2 id=\"ge-zhe-ge-zhe\"><a class=\"zola-anchor\" href=\"#ge-zhe-ge-zhe\" aria-label=\"Anchor link for: ge-zhe-ge-zhe\">\u6401\u8fd9\u6401\u8fd9<\/a><\/h2>\n<p>\u8fd9\u4e2a\u6807\u9898\u5145\u5206\u63d0\u73b0\u4e86\u9012\u5f52\u7684\u601d\u60f3. \u5b66\u4e60\u65b0\u4e1c\u897f, \u7136\u540e\u53d1\u73b0\u53e6\u4e00\u4e9b\u65b0\u4e1c\u897f, \u7136\u540e\u518d\u5b66\u4e60\u8fd9\u4e9b\u65b0\u4e1c\u897f, \u7136\u540e......<\/p>\n<p>\u9996\u5148\u6765\u770b <code>zuiFind<\/code><\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"c\"><span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/*<\/span><span class=\"z-l-5 z-d-3\"> https:\/\/github.com\/redis\/redis\/blob\/3.0\/src\/t_zset.c#L1826 <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">int<\/span><span class=\"z-l-6 z-d-7\"> zuiFind<\/span><span>(<\/span><span>zsetopsrc <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-9 z-d-12\">op<\/span><span>,<\/span><span> zsetopval <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-9 z-d-12\">val<\/span><span>,<\/span><span class=\"z-l-8 z-d-10\"> double<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-9 z-d-12\">score<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    if<\/span><span> (<\/span><span>op<\/span><span>-&gt;<\/span><span>subject<\/span><span class=\"z-l-8 z-d-10\"> ==<\/span><span class=\"z-l-1 z-d-4\"> NULL<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        return<\/span><span class=\"z-l-1 z-d-4\"> 0<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    if<\/span><span> (<\/span><span>op<\/span><span>-&gt;<\/span><span>type<\/span><span class=\"z-l-8 z-d-10\"> ==<\/span><span> REDIS_SET<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        if<\/span><span> (<\/span><span>op<\/span><span>-&gt;<\/span><span>encoding<\/span><span class=\"z-l-8 z-d-10\"> ==<\/span><span> REDIS_ENCODING_INTSET<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">            if<\/span><span> (<\/span><span class=\"z-l-6 z-d-7\">zuiLongLongFromValue<\/span><span>(<\/span><span>val<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\"> &amp;&amp;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">                intsetFind<\/span><span>(<\/span><span>op<\/span><span>-&gt;<\/span><span>subject<\/span><span>-&gt;<\/span><span>ptr<\/span><span>,<\/span><span>val<\/span><span>-&gt;<\/span><span>ell<\/span><span>)<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>            {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                *<\/span><span>score <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-1 z-d-4\"> 1<\/span><span class=\"z-l-1 z-d-4\">.<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                return<\/span><span class=\"z-l-1 z-d-4\"> 1<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>            }<\/span><span class=\"z-l-8 z-d-10\"> else<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                return<\/span><span class=\"z-l-1 z-d-4\"> 0<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>            }<\/span><\/span>\n<span class=\"giallo-l\"><span>        }<\/span><span class=\"z-l-8 z-d-10\"> else<\/span><span class=\"z-l-8 z-d-10\"> if<\/span><span> (<\/span><span>op<\/span><span>-&gt;<\/span><span>encoding<\/span><span class=\"z-l-8 z-d-10\"> ==<\/span><span> REDIS_ENCODING_HT<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>            dict <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span>ht <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span> op<\/span><span>-&gt;<\/span><span>subject<\/span><span>-&gt;<\/span><span>ptr<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">            zuiObjectFromValue<\/span><span>(<\/span><span>val<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">            if<\/span><span> (<\/span><span class=\"z-l-6 z-d-7\">dictFind<\/span><span>(<\/span><span>ht<\/span><span>,<\/span><span>val<\/span><span>-&gt;<\/span><span>ele<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\"> !=<\/span><span class=\"z-l-1 z-d-4\"> NULL<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                *<\/span><span>score <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-1 z-d-4\"> 1<\/span><span class=\"z-l-1 z-d-4\">.<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                return<\/span><span class=\"z-l-1 z-d-4\"> 1<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>            }<\/span><span class=\"z-l-8 z-d-10\"> else<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                return<\/span><span class=\"z-l-1 z-d-4\"> 0<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>            }<\/span><\/span>\n<span class=\"giallo-l\"><span>        }<\/span><span class=\"z-l-8 z-d-10\"> else<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">            redisPanic<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span class=\"z-l-2 z-d-6\">Unknown set encoding<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>        }<\/span><\/span>\n<span class=\"giallo-l\"><span>    }<\/span><span class=\"z-l-8 z-d-10\"> else<\/span><span class=\"z-l-8 z-d-10\"> if<\/span><span> (<\/span><span>op<\/span><span>-&gt;<\/span><span>type<\/span><span class=\"z-l-8 z-d-10\"> ==<\/span><span> REDIS_ZSET<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">        zuiObjectFromValue<\/span><span>(<\/span><span>val<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        if<\/span><span> (<\/span><span>op<\/span><span>-&gt;<\/span><span>encoding<\/span><span class=\"z-l-8 z-d-10\"> ==<\/span><span> REDIS_ENCODING_ZIPLIST<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">            if<\/span><span> (<\/span><span class=\"z-l-6 z-d-7\">zzlFind<\/span><span>(<\/span><span>op<\/span><span>-&gt;<\/span><span>subject<\/span><span>-&gt;<\/span><span>ptr<\/span><span>,<\/span><span>val<\/span><span>-&gt;<\/span><span>ele<\/span><span>,<\/span><span>score<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\"> !=<\/span><span class=\"z-l-1 z-d-4\"> NULL<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">                \/*<\/span><span class=\"z-l-5 z-d-3\"> Score is already set by zzlFind. <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                return<\/span><span class=\"z-l-1 z-d-4\"> 1<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>            }<\/span><span class=\"z-l-8 z-d-10\"> else<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                return<\/span><span class=\"z-l-1 z-d-4\"> 0<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>            }<\/span><\/span>\n<span class=\"giallo-l\"><span>        }<\/span><span class=\"z-l-8 z-d-10\"> else<\/span><span class=\"z-l-8 z-d-10\"> if<\/span><span> (<\/span><span>op<\/span><span>-&gt;<\/span><span>encoding<\/span><span class=\"z-l-8 z-d-10\"> ==<\/span><span> REDIS_ENCODING_SKIPLIST<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>            zset <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span>zs <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span> op<\/span><span>-&gt;<\/span><span>subject<\/span><span>-&gt;<\/span><span>ptr<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>            dictEntry <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span>de<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">            if<\/span><span> (<\/span><span>(<\/span><span>de <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> dictFind<\/span><span>(<\/span><span>zs<\/span><span>-&gt;<\/span><span>dict<\/span><span>,<\/span><span>val<\/span><span>-&gt;<\/span><span>ele<\/span><span>)<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\"> !=<\/span><span class=\"z-l-1 z-d-4\"> NULL<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                *<\/span><span>score <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span>(<\/span><span class=\"z-l-8 z-d-10\">double<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span>)<\/span><span class=\"z-l-6 z-d-7\">dictGetVal<\/span><span>(<\/span><span>de<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                return<\/span><span class=\"z-l-1 z-d-4\"> 1<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>            }<\/span><span class=\"z-l-8 z-d-10\"> else<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                return<\/span><span class=\"z-l-1 z-d-4\"> 0<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>            }<\/span><\/span>\n<span class=\"giallo-l\"><span>        }<\/span><span class=\"z-l-8 z-d-10\"> else<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">            redisPanic<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span class=\"z-l-2 z-d-6\">Unknown sorted set encoding<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>        }<\/span><\/span>\n<span class=\"giallo-l\"><span>    }<\/span><span class=\"z-l-8 z-d-10\"> else<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">        redisPanic<\/span><span>(<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span class=\"z-l-2 z-d-6\">Unsupported type<\/span><span class=\"z-l-2 z-d-6\">&quot;<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>    }<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u5148\u5ffd\u7565\u6389 <code>set<\/code> \u7684\u64cd\u4f5c, \u6765\u770b <code>sorted set<\/code>. \u6211\u4eec\u53c8\u89c1\u5230\u4e86\u6536\u5c3e\u5de5\u4f5c\u65f6\u51fa\u73b0\u8fc7\u7684 <code>ziplist<\/code>.<\/p>\n<blockquote>\n<p>The ziplist is a specially encoded dually linked list that is designed to be very memory efficient. It stores both strings and integer values, where integers are encoded as actual integers instead of a series of characters. It allows push and pop operations on either side of the list in O(1) time. However, because every operation requires a reallocation of the memory used by the ziplist, the actual complexity is related to the amount of memory used by the ziplist.<\/p>\n<\/blockquote>\n<p>\u67e5\u4e86\u4e00\u4e0b\u8d44\u6599, \u8fd9\u662f <code>Redis<\/code> \u5728\u9762\u5bf9\u5c0f\u5143\u7d20\u65f6\u53ef\u4ee5\u505a\u7684\u4e00\u4e2a\u5185\u5b58\u4f18\u5316, \u672c\u4f53\u662f\u4e00\u4e2a\u7ecf\u8fc7\u7279\u6b8a\u7f16\u7801\u7684\u53cc\u5411\u94fe\u8868. \u7ecf\u8fc7\u7279\u6b8a\u7f16\u7801\u540e\u7684\u6570\u636e\u4f1a\u53d8\u5f97\u66f4\u52a0\u7d27\u51d1, \u8fde\u7eed\u7684\u5185\u5b58\u4f7f\u7528\u4e5f\u5bf9\u4e8e\u7f13\u5b58\u66f4\u52a0\u53cb\u597d. \u6709\u4e24\u4e2a\u914d\u7f6e\u51b3\u5b9a\u4e86 <code>sorted set<\/code> \u4e2d\u4f7f\u7528 <code>ziplist<\/code> \u7684\u9608\u503c.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"c\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">#<\/span><span class=\"z-l-8 z-d-10\">define<\/span><span class=\"z-l-6 z-d-7\"> REDIS_ZSET_MAX_ZIPLIST_ENTRIES<\/span><span class=\"z-l-1 z-d-4\"> 128<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">#<\/span><span class=\"z-l-8 z-d-10\">define<\/span><span class=\"z-l-6 z-d-7\"> REDIS_ZSET_MAX_ZIPLIST_VALUE<\/span><span class=\"z-l-1 z-d-4\"> 64<\/span><\/span><\/code><\/pre>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/redis-zinterstore\/images\/zset.svg\" alt=\"\u6709\u5e8f\u96c6\u5408\" \/>\n\u56fe. \u6709\u5e8f\u96c6\u5408<\/p>\n<p>\u7136\u540e\u6211\u4eec\u5c34\u5c2c\u7684\u53d1\u73b0, \u5728 <code>ziplist<\/code> \u67e5\u627e\u4e00\u4e2a\u5143\u7d20\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u904d\u5386, \u65f6\u95f4\u590d\u6742\u5ea6\u4e3a <code>O(N)<\/code>, \u5982\u4e0b<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"c\"><span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/*<\/span><span class=\"z-l-5 z-d-3\"> https:\/\/github.com\/redis\/redis\/blob\/3.0\/src\/t_zset.c#L915 <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">unsigned<\/span><span class=\"z-l-8 z-d-10\"> char<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-6 z-d-7\">zzlFind<\/span><span>(<\/span><span class=\"z-l-8 z-d-10\">unsigned<\/span><span class=\"z-l-8 z-d-10\"> char<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-9 z-d-12\">zl<\/span><span>,<\/span><span> robj <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-9 z-d-12\">ele<\/span><span>,<\/span><span class=\"z-l-8 z-d-10\"> double<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-9 z-d-12\">score<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    unsigned<\/span><span class=\"z-l-8 z-d-10\"> char<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span>eptr <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> ziplistIndex<\/span><span>(<\/span><span>zl<\/span><span>,<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>)<\/span><span>,<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span>sptr<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>    ele <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> getDecodedObject<\/span><span>(<\/span><span>ele<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    while<\/span><span> (<\/span><span>eptr <\/span><span class=\"z-l-8 z-d-10\">!=<\/span><span class=\"z-l-1 z-d-4\"> NULL<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>        sptr <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> ziplistNext<\/span><span>(<\/span><span>zl<\/span><span>,<\/span><span>eptr<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">        redisAssertWithInfo<\/span><span>(<\/span><span class=\"z-l-1 z-d-4\">NULL<\/span><span>,<\/span><span>ele<\/span><span>,<\/span><span>sptr <\/span><span class=\"z-l-8 z-d-10\">!=<\/span><span class=\"z-l-1 z-d-4\"> NULL<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        if<\/span><span> (<\/span><span class=\"z-l-6 z-d-7\">ziplistCompare<\/span><span>(<\/span><span>eptr<\/span><span>,<\/span><span>ele<\/span><span>-&gt;<\/span><span>ptr<\/span><span>,<\/span><span class=\"z-l-6 z-d-7\">sdslen<\/span><span>(<\/span><span>ele<\/span><span>-&gt;<\/span><span>ptr<\/span><span>)<\/span><span>)<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">            \/*<\/span><span class=\"z-l-5 z-d-3\"> Matching element, pull out score. <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">            if<\/span><span> (<\/span><span>score <\/span><span class=\"z-l-8 z-d-10\">!=<\/span><span class=\"z-l-1 z-d-4\"> NULL<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span>score <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> zzlGetScore<\/span><span>(<\/span><span>sptr<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">            decrRefCount<\/span><span>(<\/span><span>ele<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">            return<\/span><span> eptr<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>        }<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">        \/*<\/span><span class=\"z-l-5 z-d-3\"> Move to next element. <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span>        eptr <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> ziplistNext<\/span><span>(<\/span><span>zl<\/span><span>,<\/span><span>sptr<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>    }<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">    decrRefCount<\/span><span>(<\/span><span>ele<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    return<\/span><span class=\"z-l-1 z-d-4\"> NULL<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u4e0d\u8fc7\u5f53 <code>zset<\/code> \u4f7f\u7528 <code>REDIS_ENCODING_SKIPLIST<\/code> \u4f5c\u4e3a encoding \u7684\u65f6\u5019, \u4f7f\u7528 <code>Hash table<\/code> \u505a\u67e5\u8be2\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662f <code>O(1)<\/code> \u8fd9\u662f\u80af\u5b9a\u7684.<\/p>\n<p>\u5f53\u7136, \u8fd9\u91cc\u9762\u5176\u5b9e\u8fd8\u6709\u5f88\u591a\u7ec6\u8282\u6ca1\u6709\u8bf4\u5230, \u6bd4\u5982 <code>ziplist<\/code> \u7684\u5185\u90e8\u8868\u793a, \u548c <code>zset<\/code> \u6df7\u5728\u4e00\u8d77\u7684 <code>set<\/code>, <code>zset<\/code> \u4e2d\u7684 <code>dict<\/code> \u548c <code>skiplist<\/code> \u7684\u8be6\u7ec6\u5206\u6790\u7b49\u7b49. \u4e0b\u6b21\u6709\u673a\u4f1a\u7684\u5427.<\/p>\n<h2 id=\"can-kao-zi-liao\"><a class=\"zola-anchor\" href=\"#can-kao-zi-liao\" aria-label=\"Anchor link for: can-kao-zi-liao\">\u53c2\u8003\u8d44\u6599<\/a><\/h2>\n<ol>\n<li><a rel=\"external\" href=\"https:\/\/redislabs.com\/ebook\/part-2-core-concepts\/01chapter-9-reducing-memory-use\/9-1-short-structures\/9-1-1-the-ziplist-representation\/\">The ziplist representation<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/redisbook.readthedocs.io\/en\/latest\/compress-datastruct\/ziplist.html\">\u538b\u7f29\u5217\u8868 \u2014 Redis \u8bbe\u8ba1\u4e0e\u5b9e\u73b0<\/a><\/li>\n<\/ol>\n"},{"title":"\u5b9e\u73b0\u4f18\u96c5\u7684 Golang \u9879\u76ee\u7ed3\u6784","published":"2021-02-19T18:10:22+08:00","updated":"2021-02-19T18:10:22+08:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/write-elegant-project-with-golang\/"}},"id":"https:\/\/memwey.github.io\/posts\/write-elegant-project-with-golang\/","content":"<p>\u968f\u7740\u5de5\u4f5c\u7ecf\u9a8c\u7684\u79ef\u7d2f, \u8d8a\u6765\u8d8a\u611f\u5230\u4ec5\u4ec5\u5199\u51fa <code>Elegant Code<\/code> \u662f\u4e0d\u591f\u7684, \u7279\u522b\u662f\u5f53\u591a\u4eba\u5408\u4f5c\u5f00\u53d1\u7684\u65f6\u5019, \u9047\u5230\u79cd\u79cd\u7ed3\u6784\u6df7\u4e71, \u4ee3\u7801\u5197\u4f59, \u6a21\u5757\u8026\u5408, \u4f9d\u8d56\u8026\u5408\u7684\u95ee\u9898. \u8fd9\u4e2a\u65f6\u5019, \u5c31\u9700\u8981\u66f4\u9ad8\u7684\u8981\u6c42, <code>Elegant Project<\/code>, \u81ea\u9876\u5411\u4e0b\u7684\u6539\u5584\u9879\u76ee\u7684\u7ed3\u6784.<\/p>\n<p>\u4ec5\u4ec5\u5b9e\u73b0\u4e1a\u52a1\u903b\u8f91\u662f\u5f88\u5bb9\u6613\u7684, \u800c\u5927\u91cf\u7684\u65f6\u95f4\u4f1a\u7528\u5728\u6d4b\u8bd5, Debug \u4e0a. \u4e00\u4e2a\u826f\u597d\u5b9a\u4e49\u7684\u9879\u76ee\u7ed3\u6784\u80fd\u591f\u6781\u5927\u5730\u63d0\u5347\u5f00\u53d1\u6548\u7387, \u964d\u4f4e\u7ef4\u62a4\u6210\u672c. \u4e0b\u9762\u4ecb\u7ecd\u4e00\u5957\u7ecf\u8fc7\u5b9e\u8df5\u68c0\u9a8c\u7684 Go \u9879\u76ee\u7ed3\u6784\u89c4\u8303.<\/p>\n<h2 id=\"xiang-mu-jie-gou-gui-fan\"><a class=\"zola-anchor\" href=\"#xiang-mu-jie-gou-gui-fan\" aria-label=\"Anchor link for: xiang-mu-jie-gou-gui-fan\">\u9879\u76ee\u7ed3\u6784\u89c4\u8303<\/a><\/h2>\n<h3 id=\"fu-wu-diao-yong-service-invocation\"><a class=\"zola-anchor\" href=\"#fu-wu-diao-yong-service-invocation\" aria-label=\"Anchor link for: fu-wu-diao-yong-service-invocation\">\u670d\u52a1\u8c03\u7528 (Service Invocation)<\/a><\/h3>\n<p>\u9879\u76ee\u7684\u6838\u5fc3\u8c03\u7528\u94fe\u9075\u5faa\u4e00\u4e2a\u6e05\u6670\u7684\u5c42\u6b21\u7ed3\u6784:<\/p>\n<ol>\n<li><strong>\u63a5\u53e3\u5b9a\u4e49<\/strong>:  \u670d\u52a1\u63a5\u53e3\u5728 <code>.\/domain\/&lt;service_name&gt;\/domain.go<\/code> \u6587\u4ef6\u4e2d\u5b9a\u4e49. \u8fd9\u662f\u670d\u52a1\u80fd\u529b\u7684\u62bd\u8c61.<\/li>\n<li><strong>\u670d\u52a1\u5b9e\u73b0<\/strong>:  \u670d\u52a1\u7684\u5177\u4f53\u5b9e\u73b0\u5728\u5bf9\u5e94\u7684 <code>.\/app\/&lt;service_name&gt;<\/code> \u76ee\u5f55\u4e2d\u5b8c\u6210.<\/li>\n<li><strong>Web Handler<\/strong>:  Web Handler \u5b9e\u73b0\u5728 <code>.\/internal\/web<\/code> \u76ee\u5f55\u4e2d.<\/li>\n<li><strong>\u8c03\u7528\u6d41\u7a0b<\/strong>:  Web Handler \u8c03\u7528 <code>.\/domain\/&lt;service_name&gt;<\/code> \u4e2d\u5b9a\u4e49\u7684\u670d\u52a1\u63a5\u53e3, \u800c\u975e\u76f4\u63a5\u4f9d\u8d56\u5177\u4f53\u5b9e\u73b0.<\/li>\n<li><strong>\u590d\u6742\u6d41\u7a0b\u5904\u7406<\/strong>:  \u5bf9\u4e8e\u9700\u8981\u8c03\u7528\u591a\u4e2a\u670d\u52a1\u65b9\u6cd5\u7684\u590d\u6742\u4e1a\u52a1\u6d41\u7a0b, \u5e94\u8be5\u5728\u4e00\u4e2a\u4e13\u7528\u7684, \u4ee5 <code>flow<\/code> \u4e3a\u540e\u7f00\u7684\u670d\u52a1\u4e2d\u8fdb\u884c\u7f16\u6392, \u800c\u4e0d\u662f\u76f4\u63a5\u5728 Web Handler \u4e2d\u7ec4\u5408.<\/li>\n<\/ol>\n<h3 id=\"fu-wu-bao-ming-ming-service-package-name\"><a class=\"zola-anchor\" href=\"#fu-wu-bao-ming-ming-service-package-name\" aria-label=\"Anchor link for: fu-wu-bao-ming-ming-service-package-name\">\u670d\u52a1\u5305\u547d\u540d (Service Package Name)<\/a><\/h3>\n<ul>\n<li><strong>\u907f\u514d\u670d\u52a1\u5305\u4e0e\u5b83\u64cd\u4f5c\u7684\u5b9e\u4f53\u540c\u540d<\/strong>:  \u4f8b\u5982, \u64cd\u4f5c <code>User<\/code> \u5b9e\u4f53\u7684\u670d\u52a1\u4e0d\u5e94\u8be5\u547d\u540d\u4e3a <code>user<\/code>.<\/li>\n<li><strong>\u4f7f\u7528\u540e\u7f00\u6765\u660e\u786e\u5305\u7684\u804c\u8d23<\/strong>:  \u63a8\u8350\u4f7f\u7528 <code>mgr<\/code>, <code>hdl<\/code>, <code>uc<\/code>, <code>svc<\/code>, <code>flow<\/code> \u7b49\u540e\u7f00\u6765\u547d\u540d\u670d\u52a1\u5305, \u4ee5\u6e05\u6670\u5730\u8868\u8fbe\u5176\u4f5c\u4e3a\u670d\u52a1\u5c42\u7684\u89d2\u8272.<\/li>\n<\/ul>\n<h3 id=\"fu-wu-fang-fa-qian-ming-service-method-signature\"><a class=\"zola-anchor\" href=\"#fu-wu-fang-fa-qian-ming-service-method-signature\" aria-label=\"Anchor link for: fu-wu-fang-fa-qian-ming-service-method-signature\">\u670d\u52a1\u65b9\u6cd5\u7b7e\u540d (Service Method Signature)<\/a><\/h3>\n<p>\u4e3a\u4e86\u4fdd\u6301\u4e00\u81f4\u6027\u548c\u53ef\u9884\u6d4b\u6027, \u6240\u6709\u670d\u52a1\u65b9\u6cd5\u90fd\u5e94\u9075\u5faa\u4ee5\u4e0b\u7b7e\u540d\u683c\u5f0f:<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"go\"><span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/\/<\/span><span class=\"z-l-5 z-d-3\"> \u6807\u51c6\u670d\u52a1\u65b9\u6cd5\u7b7e\u540d<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">Hello<\/span><span>(<\/span><span>ctx<\/span><span> context<\/span><span>.<\/span><span>Context<\/span><span>,<\/span><span> req<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span>HelloRequest<\/span><span>)<\/span><span> (<\/span><span>resp<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span>HelloResponse<\/span><span>,<\/span><span> err<\/span><span class=\"z-l-8 z-d-10\"> error<\/span><span>)<\/span><\/span><\/code><\/pre>\n<ul>\n<li><strong>\u8bf7\u6c42\/\u54cd\u5e94\u7c7b\u578b<\/strong>:  \u8bf7\u6c42\u548c\u54cd\u5e94\u7684\u7ed3\u6784\u4f53\u9075\u5faa <code>&lt;MethodName&gt;Request<\/code> \u548c <code>&lt;MethodName&gt;Response<\/code> \u7684\u547d\u540d\u6a21\u5f0f.<\/li>\n<li><strong>\u4e0a\u4e0b\u6587\u53c2\u6570<\/strong>:  \u7b2c\u4e00\u4e2a\u53c2\u6570\u5fc5\u987b\u662f <code>context.Context<\/code>, \u7528\u4e8e\u4f20\u9012\u8bf7\u6c42\u8303\u56f4\u7684\u6570\u636e, \u5982 trace ID, \u7528\u6237\u8eab\u4efd\u7b49.<\/li>\n<li><strong>\u9519\u8bef\u8fd4\u56de<\/strong>:  \u6700\u540e\u4e00\u4e2a\u8fd4\u56de\u503c\u5fc5\u987b\u662f <code>error<\/code>, \u7528\u4e8e\u9519\u8bef\u5904\u7406.<\/li>\n<li><strong>\u547d\u540d\u8fd4\u56de\u503c<\/strong>:  \u63a8\u8350\u4f7f\u7528\u547d\u540d\u8fd4\u56de\u503c, \u4ee5\u589e\u5f3a\u4ee3\u7801\u7684\u53ef\u8bfb\u6027.<\/li>\n<li><strong>\u6279\u91cf\u83b7\u53d6<\/strong>:  \u5bf9\u4e8e\u901a\u8fc7 ID \u6279\u91cf\u83b7\u53d6\u6570\u636e\u7684\u65b9\u6cd5, \u65b9\u6cd5\u540d\u5e94\u4e3a <code>Fetch&lt;Objects&gt;Dict<\/code>, \u4e14\u54cd\u5e94\u4e2d\u5e94\u5305\u542b\u4e00\u4e2a\u540d\u4e3a <code>&lt;Objects&gt;Dict<\/code> \u7684 <code>map[&lt;IDType&gt;]&lt;Object&gt;<\/code> \u5b57\u6bb5, \u4ee5\u65b9\u4fbf\u8c03\u7528\u65b9\u901a\u8fc7 ID \u67e5\u627e\u5bf9\u8c61.<\/li>\n<\/ul>\n<h3 id=\"fu-wu-shi-xian-jie-gou-service-implementation-structure\"><a class=\"zola-anchor\" href=\"#fu-wu-shi-xian-jie-gou-service-implementation-structure\" aria-label=\"Anchor link for: fu-wu-shi-xian-jie-gou-service-implementation-structure\">\u670d\u52a1\u5b9e\u73b0\u7ed3\u6784 (Service Implementation Structure)<\/a><\/h3>\n<p>\u4e00\u4e2a\u72ec\u7acb\u670d\u52a1\u7684\u5185\u90e8\u7ed3\u6784\u7ec4\u7ec7\u5982\u4e0b:<\/p>\n<ul>\n<li><strong>\u670d\u52a1\u63a5\u53e3<\/strong>:  <code>Service<\/code> \u63a5\u53e3\u4f4d\u4e8e <code>.\/domain\/&lt;service_name&gt;\/domain.go<\/code>.<\/li>\n<li><strong>\u5185\u90e8\u6838\u5fc3\u5b9a\u4e49<\/strong>:  \u5982\u6709\u9700\u8981, \u5185\u90e8\u4f7f\u7528\u7684\u6570\u636e\u7ed3\u6784\u548c Repository \u63a5\u53e3\u5b9a\u4e49\u5728 <code>.\/app\/&lt;service_name&gt;\/internal\/core\/core.go<\/code>, \u4ee5 <code>core<\/code> \u4e3a\u5305\u540d.<\/li>\n<li><strong>Repository \u5b9e\u73b0<\/strong>:  Repository \u7684\u5177\u4f53\u5b9e\u73b0\u653e\u5728 <code>.\/app\/&lt;service_name&gt;\/internal\/repo<\/code> \u76ee\u5f55\u4e2d.<\/li>\n<li><strong>\u670d\u52a1\u521d\u59cb\u5316<\/strong>:  \u670d\u52a1\u7684\u7ed3\u6784\u4f53\u548c\u6784\u9020\u903b\u8f91, \u4ee5\u53ca\u4f20\u5165\u7684\u4f9d\u8d56\u5b9a\u4e49\u5728 <code>.\/app\/&lt;service_name&gt;\/service.go<\/code>.<\/li>\n<li><strong>\u670d\u52a1\u6784\u9020\u51fd\u6570<\/strong>:  \u670d\u52a1\u6784\u9020\u51fd\u6570\u5e94\u547d\u540d\u4e3a <code>NewService(inj *NewServiceInj, opts ...ServiceOption) (srv *Service, err error)<\/code>.<\/li>\n<li><strong>\u4e1a\u52a1\u903b\u8f91<\/strong>:  \u6838\u5fc3\u4e1a\u52a1\u903b\u8f91\u5b9e\u73b0\u5728 <code>.\/app\/&lt;service_name&gt;<\/code> \u76ee\u5f55\u4e0b\u7684\u72ec\u7acb\u6587\u4ef6\u4e2d, \u4e0e\u670d\u52a1\u6784\u9020\u51fd\u6570\u5206\u79bb.<\/li>\n<li><strong>Repository \u6784\u9020\u51fd\u6570<\/strong>:  Repository \u7684\u6784\u9020\u51fd\u6570\u548c\u901a\u7528\u7684\u4e8b\u52a1\u903b\u8f91 (\u5982 <code>(r *Repo) WithTx(...)<\/code>) \u5e94\u653e\u5728 <code>.\/app\/&lt;service_name&gt;\/internal\/repo\/repo.go<\/code> \u4e2d.<\/li>\n<li><strong>Repository \u64cd\u4f5c<\/strong>:  Repository \u7684\u5177\u4f53\u6570\u636e\u5e93\u64cd\u4f5c\u5728 <code>.\/app\/&lt;service_name&gt;\/internal\/repo<\/code> \u76ee\u5f55\u4e0b\u7684\u72ec\u7acb\u6587\u4ef6\u4e2d\u5b9e\u73b0, \u4e0e\u5176\u6784\u9020\u51fd\u6570\u5206\u79bb, \u4ee5 <code>repo<\/code> \u4e3a\u5305\u540d.<\/li>\n<li><strong>\u6587\u4ef6\u547d\u540d<\/strong>:  \u4e1a\u52a1\u903b\u8f91\u6587\u4ef6\u5e94\u6839\u636e\u5176\u4e3b\u8981\u5904\u7406\u7684\u5b9e\u4f53\u6765\u547d\u540d, \u6e05\u6670\u5730\u53cd\u6620\u5176\u804c\u8d23.<\/li>\n<li><strong>\u6570\u636e\u5e93\u4e8b\u52a1\u8fb9\u754c<\/strong>:  \u6570\u636e\u5e93\u4e8b\u52a1\u8fb9\u754c\u5e94\u5b9a\u4e49\u5728\u670d\u52a1\u5c42, \u800c\u4e0d\u662f\u5728 Repository \u5c42.<\/li>\n<\/ul>\n<h3 id=\"fu-wu-mock-service-mock\"><a class=\"zola-anchor\" href=\"#fu-wu-mock-service-mock\" aria-label=\"Anchor link for: fu-wu-mock-service-mock\">\u670d\u52a1 Mock (Service Mock)<\/a><\/h3>\n<ul>\n<li><strong>Mock \u521d\u59cb\u5316<\/strong>:  \u603b\u662f\u4f7f\u7528\u8f85\u52a9\u51fd\u6570 <code>initMockService(t *testing.T) (srv *service.Service, mockInj *mockInjection)<\/code> \u6765\u521d\u59cb\u5316\u88ab\u6d4b\u8bd5\u7684\u670d\u52a1\u53ca\u5176 mock \u4f9d\u8d56.<\/li>\n<li><strong>Mock \u751f\u6210<\/strong>:  \u4f7f\u7528 <code>Mockery<\/code> \u57fa\u4e8e\u63a5\u53e3\u751f\u6210 mock \u5bf9\u8c61.<\/li>\n<li><strong>\u7c7b\u578b\u5b89\u5168<\/strong>:  \u6d4b\u8bd5\u8f85\u52a9\u51fd\u6570\u5e94\u4f7f\u7528<strong>\u7c7b\u578b\u5b89\u5168<\/strong>\u7684\u65b9\u6cd5\u8c03\u7528\u6765\u8bbe\u7f6e mock \u884c\u4e3a, \u800c\u4e0d\u662f\u4f9d\u8d56\u4e8e\u57fa\u4e8e\u5b57\u7b26\u4e32\u7684\u901a\u7528\u65b9\u6cd5, \u5982 <code>mock.On(\"MethodName\")<\/code>.<\/li>\n<\/ul>\n<h3 id=\"jiao-ben-scripts\"><a class=\"zola-anchor\" href=\"#jiao-ben-scripts\" aria-label=\"Anchor link for: jiao-ben-scripts\">\u811a\u672c (Scripts)<\/a><\/h3>\n<ul>\n<li><strong>\u901a\u7528\u811a\u672c<\/strong>:  \u5e38\u7528\u7684\u811a\u672c\u5e94\u653e\u7f6e\u5728 <code>.\/script<\/code> \u76ee\u5f55\u4e2d.<\/li>\n<li><strong>SQL \u6587\u4ef6<\/strong>:  SQL DML \u548c DDL \u6587\u4ef6\u5e94\u653e\u7f6e\u5728 <code>.\/script\/sql<\/code> \u76ee\u5f55\u4e2d.<\/li>\n<\/ul>\n<h3 id=\"ke-xuan-shi-xian-shi-yong-ent-orm\"><a class=\"zola-anchor\" href=\"#ke-xuan-shi-xian-shi-yong-ent-orm\" aria-label=\"Anchor link for: ke-xuan-shi-xian-shi-yong-ent-orm\">\u53ef\u9009\u5b9e\u73b0: \u4f7f\u7528 Ent ORM<\/a><\/h3>\n<p>\u672c\u7ed3\u6784\u89c4\u8303\u4e0d\u5f3a\u5236\u7ed1\u5b9a\u4efb\u4f55 ORM \u6846\u67b6, \u4f46\u5982\u679c\u9009\u62e9\u4f7f\u7528 <a rel=\"external\" href=\"https:\/\/entgo.io\/\">Ent<\/a>, \u53ef\u4ee5\u9075\u5faa\u4ee5\u4e0b\u7ea6\u5b9a\u6765\u66f4\u597d\u5730\u96c6\u6210.<\/p>\n<ul>\n<li><strong>Schema \u5b9a\u4e49<\/strong>:  <code>Ent<\/code> \u7684 Schema \u5b9a\u4e49\u5728 <code>.\/internal\/schema<\/code> \u76ee\u5f55\u4e2d, \u6bcf\u4e2a\u6570\u636e\u8868\u5bf9\u5e94\u4e00\u4e2a\u6587\u4ef6, \u5982 <code>.\/internal\/schema\/user.go<\/code>.<\/li>\n<li><strong>\u751f\u6210\u4ee3\u7801<\/strong>:  <code>Ent<\/code> \u751f\u6210\u7684\u4ee3\u7801\u4f4d\u4e8e <code>.\/internal\/ent<\/code> \u76ee\u5f55.<\/li>\n<li><strong>\u5b9e\u4f53\u547d\u540d<\/strong>:  \u5728 Repository \u5c42, <code>Ent<\/code> ORM \u751f\u6210\u7684\u5bf9\u8c61\u5728\u547d\u540d\u65f6\u5e94\u4f7f\u7528 <code>Entity<\/code> (\u6216 <code>Entities<\/code> \u7528\u4e8e\u96c6\u5408) \u540e\u7f00, \u4ee5\u660e\u786e\u533a\u5206\u5b83\u4eec\u4e0e\u9886\u57df\u4e2d\u7684 <code>core<\/code> \u5305\u4e2d\u7684\u5b9e\u4f53, \u5e76\u4e14 <code>Ent<\/code> \u751f\u6210\u7684\u5bf9\u8c61\u4e0d\u80fd\u6cc4\u9732\u51fa <code>repo<\/code> \u5305.<\/li>\n<li><strong>\u4ee3\u7801\u751f\u6210\u811a\u672c<\/strong>:  \u751f\u6210 Ent ORM \u4ee3\u7801\u7684\u811a\u672c\u5e94\u4f4d\u4e8e <code>.\/script\/ent.sh<\/code>.<\/li>\n<\/ul>\n<h2 id=\"fu-wu-diao-yong-liu-cheng-tu\"><a class=\"zola-anchor\" href=\"#fu-wu-diao-yong-liu-cheng-tu\" aria-label=\"Anchor link for: fu-wu-diao-yong-liu-cheng-tu\">\u670d\u52a1\u8c03\u7528\u6d41\u7a0b\u56fe<\/a><\/h2>\n<p>\u4e0b\u56fe\u5c55\u793a\u4e86\u4ece\u63a5\u6536\u5ba2\u6237\u7aef\u8bf7\u6c42\u5230\u4e0e\u6570\u636e\u5e93\u4ea4\u4e92\u7684\u5b8c\u6574\u5206\u5c42\u8c03\u7528\u94fe, \u5b83\u5f3a\u8c03\u4e86\u63a5\u53e3\u4e0e\u5b9e\u73b0\u5206\u79bb (\u4f9d\u8d56\u5012\u7f6e\u539f\u5219), \u4ee5\u53ca\u5404\u5c42\u5728\u9879\u76ee\u4e2d\u7684\u4f4d\u7f6e. \u8fd9\u6837\u4fdd\u8bc1\u4e86\u6bcf\u4e00\u4e2a\u5c42\u7ea7\u7684\u804c\u8d23\u6e05\u6670, \u8026\u5408\u5ea6\u4f4e, \u65b9\u4fbf\u7ef4\u62a4\u548c\u6269\u5c55, \u4e5f\u65b9\u4fbf\u8fdb\u884c\u5355\u5143\u6d4b\u8bd5\u548c\u6392\u67e5\u95ee\u9898.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>[ API Request ]<\/span><\/span>\n<span class=\"giallo-l\"><span>      |<\/span><\/span>\n<span class=\"giallo-l\"><span>      v<\/span><\/span>\n<span class=\"giallo-l\"><span>+--------------------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span>|      Web Handler               |<\/span><\/span>\n<span class=\"giallo-l\"><span>|     (.\/internal\/web)           |<\/span><\/span>\n<span class=\"giallo-l\"><span>+--------------------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span>      |<\/span><\/span>\n<span class=\"giallo-l\"><span>      |  (\u4f9d\u8d56\u63a5\u53e3)<\/span><\/span>\n<span class=\"giallo-l\"><span>      v<\/span><\/span>\n<span class=\"giallo-l\"><span>+--------------------------------+ &lt;----+<\/span><\/span>\n<span class=\"giallo-l\"><span>|      Domain Interface          |      |<\/span><\/span>\n<span class=\"giallo-l\"><span>|   (.\/domain\/&lt;service_name&gt;)    |      | (\u670d\u52a1\u4e4b\u95f4\u901a\u8fc7\u63a5\u53e3\u8c03\u7528)<\/span><\/span>\n<span class=\"giallo-l\"><span>+--------------------------------+      |<\/span><\/span>\n<span class=\"giallo-l\"><span>      |                                  <\/span><\/span>\n<span class=\"giallo-l\"><span>      |  (\u7531 App \u5c42\u5b9e\u73b0)<\/span><\/span>\n<span class=\"giallo-l\"><span>      v<\/span><\/span>\n<span class=\"giallo-l\"><span>+--------------------------------+      |<\/span><\/span>\n<span class=\"giallo-l\"><span>|      App Implementation        | -----+<\/span><\/span>\n<span class=\"giallo-l\"><span>|    (.\/app\/&lt;service_name&gt;)      |<\/span><\/span>\n<span class=\"giallo-l\"><span>+--------------------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span>      |<\/span><\/span>\n<span class=\"giallo-l\"><span>      |  (\u4f9d\u8d56\u63a5\u53e3)<\/span><\/span>\n<span class=\"giallo-l\"><span>      v<\/span><\/span>\n<span class=\"giallo-l\"><span>+--------------------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span>|      Repository Interface      |<\/span><\/span>\n<span class=\"giallo-l\"><span>|   (.\/app\/...\/internal\/core)    |<\/span><\/span>\n<span class=\"giallo-l\"><span>+--------------------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span>      |<\/span><\/span>\n<span class=\"giallo-l\"><span>      |  (\u7531 Repo \u5c42\u5b9e\u73b0)<\/span><\/span>\n<span class=\"giallo-l\"><span>      v<\/span><\/span>\n<span class=\"giallo-l\"><span>+--------------------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span>|      Repository Implementation |<\/span><\/span>\n<span class=\"giallo-l\"><span>|   (.\/app\/...\/internal\/repo)    |<\/span><\/span>\n<span class=\"giallo-l\"><span>+--------------------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span>      |<\/span><\/span>\n<span class=\"giallo-l\"><span>      v<\/span><\/span>\n<span class=\"giallo-l\"><span>[ Database \/ ORM ]<\/span><\/span><\/code><\/pre><h2 id=\"shi-li-xiang-mu-mu-lu-jie-gou\"><a class=\"zola-anchor\" href=\"#shi-li-xiang-mu-mu-lu-jie-gou\" aria-label=\"Anchor link for: shi-li-xiang-mu-mu-lu-jie-gou\">\u793a\u4f8b\u9879\u76ee\u76ee\u5f55\u7ed3\u6784<\/a><\/h2>\n<p>\u8fd9\u662f\u4e00\u4e2a\u9075\u5faa\u4e0a\u8ff0\u89c4\u8303\u7684\u793a\u4f8b\u9879\u76ee\u7ed3\u6784. \u5b83\u4ee5\u4e00\u4e2a\u7528\u6237\u6ce8\u518c\u573a\u666f\u4e3a\u4f8b, \u5176\u4e2d <code>registrationflow<\/code> \u662f\u4e00\u4e2a\u590d\u6742\u6d41\u7a0b, \u8d1f\u8d23\u7f16\u6392 <code>authuc<\/code> (\u8ba4\u8bc1\u7528\u4f8b) \u548c <code>notiuc<\/code> (\u901a\u77e5\u7528\u4f8b).<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>\/<\/span><\/span>\n<span class=\"giallo-l\"><span>\u251c\u2500\u2500 app\/<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u251c\u2500\u2500 registrationflow\/           # \u201c\u7528\u6237\u6ce8\u518c\u201d\u6d41\u7a0b\u7684\u5b9e\u73b0<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u2502   \u251c\u2500\u2500 service.go              # \u5b9a\u4e49 Service, NewService<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u2502   \u2514\u2500\u2500 registration_logic.go   # \u6d41\u7a0b\u7f16\u6392\u903b\u8f91<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u251c\u2500\u2500 authuc\/                     # \u201c\u8ba4\u8bc1\u201d\u7528\u4f8b\u7684\u5b9e\u73b0<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u2502   \u251c\u2500\u2500 internal\/<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u2502   \u2502   \u251c\u2500\u2500 core\/<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u2502   \u2502   \u2502   \u251c\u2500\u2500 core.go         # \u5b9a\u4e49 IAuthRepo \u4f7f\u7528\u7684\u6570\u636e\u7ed3\u6784<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u2502   \u2502   \u2502   \u2514\u2500\u2500 repo_mock.go    # IAuthRepo \u7684 mock \u5b9e\u73b0<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u2502   \u2502   \u2514\u2500\u2500 repo\/<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u2502   \u2502       \u251c\u2500\u2500 repo.go         # \u5b9a\u4e49 Repo, NewRepo, WithTx<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u2502   \u2502       \u2514\u2500\u2500 auth_repo.go    # \u5b9e\u73b0 IAuthRepo<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u2502   \u251c\u2500\u2500 service.go              # \u5b9a\u4e49 Service, NewService<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u2502   \u251c\u2500\u2500 auth_logic.go           # \u8ba4\u8bc1\u4e1a\u52a1\u903b\u8f91<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u2502   \u2514\u2500\u2500 auth_logic_test.go      # \u8ba4\u8bc1\u4e1a\u52a1\u903b\u8f91\u7684\u5355\u5143\u6d4b\u8bd5<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u2514\u2500\u2500 notiuc\/                     # \u201c\u901a\u77e5\u201d\u7528\u4f8b\u7684\u5b9e\u73b0<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502       \u251c\u2500\u2500 internal\/               # (\u53ef\u9009, \u5982\u9700\u5c01\u88c5 client \u6216\u5b9a\u4e49\u5185\u90e8\u7ed3\u6784)<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502       \u2502   \u2514\u2500\u2500 ...<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502       \u251c\u2500\u2500 service.go              # \u5b9a\u4e49 Service, NewService<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502       \u2514\u2500\u2500 noti_logic.go           # \u901a\u77e5\u4e1a\u52a1\u903b\u8f91 (\u5982\u53d1\u90ae\u4ef6, \u77ed\u4fe1)<\/span><\/span>\n<span class=\"giallo-l\"><span>\u251c\u2500\u2500 cmd\/<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u2514\u2500\u2500 server\/<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502       \u2514\u2500\u2500 main.go<\/span><\/span>\n<span class=\"giallo-l\"><span>\u251c\u2500\u2500 domain\/<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u251c\u2500\u2500 registrationflow\/<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u2502   \u251c\u2500\u2500 domain.go               # \u5b9a\u4e49 RegistrationFlow \u63a5\u53e3<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u2502   \u2514\u2500\u2500 service_mock.go         # RegistrationFlow \u7684 mock \u5b9e\u73b0<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u251c\u2500\u2500 authuc\/<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u2502   \u251c\u2500\u2500 domain.go               # \u5b9a\u4e49 AuthUseCase \u63a5\u53e3<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u2502   \u2514\u2500\u2500 service_mock.go         # AuthUseCase \u7684 mock \u5b9e\u73b0<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u2514\u2500\u2500 notiuc\/<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502       \u251c\u2500\u2500 domain.go               # \u5b9a\u4e49 NotiUseCase \u63a5\u53e3<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502       \u2514\u2500\u2500 service_mock.go         # NotiUseCase \u7684 mock \u5b9e\u73b0<\/span><\/span>\n<span class=\"giallo-l\"><span>\u251c\u2500\u2500 internal\/<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502   \u2514\u2500\u2500 web\/<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502       \u251c\u2500\u2500 registration_handler.go # \u5904\u7406\u6ce8\u518c\u6d41\u7a0b, \u8c03\u7528 domain\/registrationflow<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502       \u251c\u2500\u2500 auth_handler.go         # \u5904\u7406\u8ba4\u8bc1\u8bf7\u6c42, \u8c03\u7528 domain\/authuc<\/span><\/span>\n<span class=\"giallo-l\"><span>\u2502       \u2514\u2500\u2500 auth_handler_test.go    # \u8ba4\u8bc1\u8bf7\u6c42\u5904\u7406\u7684\u5355\u5143\u6d4b\u8bd5<\/span><\/span>\n<span class=\"giallo-l\"><span>...<\/span><\/span><\/code><\/pre>\n<p>\u4e0a\u8ff0\u76ee\u5f55\u7ed3\u6784\u5c55\u793a\u4e86\u4e00\u4e2a\u5178\u578b\u7684\u5206\u5c42\u5e94\u7528:<\/p>\n<ul>\n<li><strong><code>domain<\/code><\/strong>:  \u5b9a\u4e49\u4e86\u4e09\u4e2a\u6838\u5fc3\u670d\u52a1\u63a5\u53e3: <code>RegistrationFlow<\/code>\u3001<code>AuthUseCase<\/code> \u548c <code>NotiUseCase<\/code>. \u8fd9\u662f\u4e1a\u52a1\u80fd\u529b\u7684\u62bd\u8c61\u5c42.<\/li>\n<li><strong><code>app<\/code><\/strong>:  \u5305\u542b\u4e86\u4e0a\u8ff0\u63a5\u53e3\u7684\u5177\u4f53\u5b9e\u73b0. <code>registrationflow<\/code> \u662f\u4e00\u4e2a\u6d41\u7a0b\u670d\u52a1 (Flow), \u5b83\u7684\u5b9e\u73b0\u4f1a\u4f9d\u8d56 <code>authuc<\/code> \u548c <code>notiuc<\/code> \u7684\u63a5\u53e3, \u4ece\u800c\u7f16\u6392\u548c\u8c03\u7528\u8fd9\u4e24\u4e2a\u7528\u4f8b\u670d\u52a1.<\/li>\n<li><strong><code>internal\/web<\/code><\/strong>:  Web Handler \u5c42, \u8d1f\u8d23\u66b4\u9732\u670d\u52a1\u7ed9\u5916\u90e8. \u4e0d\u540c\u7684 Handler \u6587\u4ef6\u5904\u7406\u4e0d\u540c\u7684\u4e1a\u52a1, \u4f8b\u5982 <code>registration_handler.go<\/code> \u8c03\u7528\u590d\u6742\u7684\u6d41\u7a0b\u670d\u52a1, \u800c <code>auth_handler.go<\/code>\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528\u7b80\u5355\u7684\u7528\u4f8b\u670d\u52a1.<\/li>\n<li><strong>\u5305\u547d\u540d<\/strong>:  \u6ce8\u610f\u6240\u6709\u5305\u540d\u90fd\u4f7f\u7528\u7b80\u77ed, \u5168\u5c0f\u5199\u7684\u5f62\u5f0f, \u5e76\u4e14\u4e0d\u4f7f\u7528\u4e0b\u5212\u7ebf, \u8fd9\u662f Go \u8bed\u8a00\u63a8\u8350\u7684\u98ce\u683c.<\/li>\n<li><strong>Mock \u4e0e\u6d4b\u8bd5<\/strong>:\n<ul>\n<li><strong>Mock \u6587\u4ef6<\/strong>: <code>*_mock.go<\/code> \u662f\u63a5\u53e3\u7684 mock \u5b9e\u73b0, \u7528\u4e8e\u5355\u5143\u6d4b\u8bd5.<\/li>\n<li><strong>\u6d4b\u8bd5\u6587\u4ef6<\/strong>: <code>*_test.go<\/code> \u662f\u5bf9\u5e94\u7684\u5355\u5143\u6d4b\u8bd5\u6587\u4ef6.<\/li>\n<li><strong>\u4f9d\u8d56\u5173\u7cfb<\/strong>: \u57fa\u4e8e\u4f9d\u8d56\u5012\u7f6e\u539f\u5219, \u6d4b\u8bd5\u6587\u4ef6\u4f1a\u4f7f\u7528 mock \u6765\u9694\u79bb\u88ab\u6d4b\u8bd5\u7684\u5c42\u7ea7.\n<ul>\n<li><code>app\/authuc\/auth_logic_test.go<\/code> (\u4e1a\u52a1\u903b\u8f91\u6d4b\u8bd5) \u4f1a\u4f7f\u7528 <code>app\/authuc\/internal\/core\/repo_mock.go<\/code> \u6765\u6a21\u62df\u6570\u636e\u8bbf\u95ee\u884c\u4e3a.<\/li>\n<li><code>internal\/web\/auth_handler_test.go<\/code> (Handler \u6d4b\u8bd5) \u4f1a\u4f7f\u7528 <code>domain\/authuc\/service_mock.go<\/code> \u6765\u6a21\u62df\u4e1a\u52a1\u670d\u52a1\u884c\u4e3a.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2 id=\"zong-jie\"><a class=\"zola-anchor\" href=\"#zong-jie\" aria-label=\"Anchor link for: zong-jie\">\u603b\u7ed3<\/a><\/h2>\n<p>\u672c\u89c4\u8303\u7684\u6838\u5fc3\u4ef7\u503c\u5728\u4e8e\u63d0\u4f9b\u4e00\u4e2a\u6e05\u6670\u4e00\u81f4\u7684\u9879\u76ee\u7ed3\u6784, \u4ece\u800c\u63d0\u5347\u9879\u76ee\u7684<strong>\u53ef\u6d4b\u8bd5\u6027<\/strong>\u548c<strong>\u53ef\u7ef4\u62a4\u6027<\/strong>. \u901a\u8fc7\u660e\u786e\u7684\u5206\u5c42\u548c\u63a5\u53e3\u5b9a\u4e49, \u5b9e\u73b0\u4e86\u4ee5\u4e0b\u5173\u952e\u7684\u67b6\u6784\u539f\u5219:<\/p>\n<ul>\n<li><strong>Monorepo \u4e0b\u7684\u5fae\u670d\u52a1\u5316<\/strong>: \u5728\u5355\u4e00\u4ee3\u7801\u5e93(Monorepo)\u4e2d, \u901a\u8fc7\u6a21\u5757\u5316\u7684\u670d\u52a1(<code>app<\/code>)\u548c\u7edf\u4e00\u7684\u63a5\u53e3(<code>domain<\/code>), \u5b9e\u73b0\u4e86\u7c7b\u4f3c\u5fae\u670d\u52a1\u7684\u5f00\u53d1\u4f53\u9a8c. \u6bcf\u4e2a\u670d\u52a1\u90fd\u53ef\u4ee5\u72ec\u7acb\u5f00\u53d1, \u6d4b\u8bd5\u548c\u90e8\u7f72, \u4f46\u53c8\u80fd\u5728\u540c\u4e00\u4e2a\u9879\u76ee\u4e2d\u8f7b\u677e\u5171\u4eab\u4ee3\u7801\u548c\u914d\u7f6e.<\/li>\n<li><strong>\u652f\u6301\u591a\u4eba\u534f\u4f5c<\/strong>: \u6e05\u6670\u7684\u8fb9\u754c\u548c\u6240\u6709\u6743\u4f7f\u5f97\u591a\u4e2a\u5f00\u53d1\u56e2\u961f\u53ef\u4ee5\u5e76\u884c\u5de5\u4f5c, \u800c\u4e0d\u4f1a\u76f8\u4e92\u5e72\u6270. \u6bcf\u4e2a\u56e2\u961f\u53ef\u4ee5\u4e13\u6ce8\u4e8e\u81ea\u5df1\u7684\u670d\u52a1, \u5e76\u901a\u8fc7\u5b9a\u4e49\u597d\u7684\u63a5\u53e3\u8fdb\u884c\u534f\u4f5c.<\/li>\n<li><strong>\u9ad8\u53ef\u6d4b\u8bd5\u6027<\/strong>: \u4f9d\u8d56\u5012\u7f6e\u539f\u5219\u7684\u8d2f\u5f7b, \u4ee5\u53ca\u63a5\u53e3 mock \u7684\u666e\u904d\u4f7f\u7528, \u4f7f\u5f97\u6bcf\u4e2a\u6a21\u5757\u90fd\u53ef\u4ee5\u8fdb\u884c\u72ec\u7acb\u7684\u5355\u5143\u6d4b\u8bd5, \u4fdd\u8bc1\u4e86\u4ee3\u7801\u8d28\u91cf\u548c\u8fed\u4ee3\u901f\u5ea6.<\/li>\n<\/ul>\n<h2 id=\"can-kao-lian-jie\"><a class=\"zola-anchor\" href=\"#can-kao-lian-jie\" aria-label=\"Anchor link for: can-kao-lian-jie\">\u53c2\u8003\u94fe\u63a5<\/a><\/h2>\n<ul>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/golang-standards\/project-layout\">Standard Go Project Layout<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/github.com\/mattermost\/mattermost\">Mattermost<\/a><\/li>\n<\/ul>\n"},{"title":"Redis LRU","published":"2020-12-25T14:26:24+08:00","updated":"2020-12-25T14:26:24+08:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/redis-lru\/"}},"id":"https:\/\/memwey.github.io\/posts\/redis-lru\/","content":"<h2 id=\"ji-chu-zhi-shi\"><a class=\"zola-anchor\" href=\"#ji-chu-zhi-shi\" aria-label=\"Anchor link for: ji-chu-zhi-shi\">\u57fa\u7840\u77e5\u8bc6<\/a><\/h2>\n<p><code>LRU (Least recently used)<\/code> \u662f\u4e00\u4e2a\u975e\u5e38\u5e38\u7528\u7684\u7f13\u5b58\u7f6e\u6362\u7b97\u6cd5.<\/p>\n<p>\u5728\u7f13\u5b58\u7a7a\u95f4\u6709\u9650\u7684\u60c5\u51b5\u4e0b, \u5728\u65b0\u7684\u6570\u636e\u5199\u5165\u65f6, \u9700\u8981\u6dd8\u6c70\u4e00\u4e9b\u65e7\u6570\u636e. \u4e00\u822c\u671f\u671b\u6700\u4e0d\u53ef\u80fd\u88ab\u7ee7\u7eed\u8bbf\u95ee\u7684\u6570\u636e\u6dd8\u6c70. \u7531\u4e8e\u65e0\u6cd5\u5bf9\u672a\u6765\u7684\u60c5\u51b5\u8fdb\u884c\u9884\u6d4b, \u53ea\u80fd\u57fa\u4e8e\u73b0\u6709\u7684\u4fe1\u606f\u63a8\u6d4b.<\/p>\n<p><code>LRU<\/code> \u57fa\u4e8e\u8fd9\u6837\u4e00\u4e2a\u5047\u5b9a, \u5728\u4e00\u4e2a\u65f6\u95f4\u70b9\u4e0a, \u5982\u679c\u4e00\u4e2a\u6570\u636e\u8ddd\u79bb\u4e0a\u6b21\u88ab\u8bbf\u95ee\u7684\u65f6\u95f4\u8d8a\u957f, \u5219\u8fd9\u4e2a\u6570\u636e\u5728\u672a\u6765\u88ab\u8bbf\u95ee\u7684\u53ef\u80fd\u6027\u8d8a\u5c0f. \u6240\u4ee5, \u5e94\u8be5\u6dd8\u6c70\u6389\u8ddd\u79bb\u4e0a\u6b21\u88ab\u8bbf\u95ee\u7684\u65f6\u95f4\u6700\u4e45\u7684\u6570\u636e.<\/p>\n<p>\u5e38\u89c1\u7684 <code>LRU<\/code> \u5b9e\u73b0\u662f\u4f7f\u7528\u4e00\u4e2a\u53cc\u5411\u94fe\u8868, \u5f53 Item \u88ab\u8bbf\u95ee\u65f6, \u5c06\u5176\u79fb\u52a8\u5230\u94fe\u8868\u7684\u5934\u90e8. \u5f53\u7f13\u5b58\u4e0d\u8db3\u65f6, \u4ece\u94fe\u8868\u7684\u5c3e\u90e8\u5f00\u59cb\u6dd8\u6c70.<\/p>\n<p>\u5355\u7eaf\u7684\u53cc\u5411\u94fe\u8868\u7684\u5b9e\u73b0\u5b9e\u9645\u4e0a\u662f\u4e0d\u592a\u7b26\u5408\u73b0\u5b9e\u7684. \u4e00\u822c\u7684, \u6211\u4eec\u5e0c\u671b\u7f13\u5b58\u53ef\u4ee5\u5c3d\u5feb\u88ab\u68c0\u7d22\u5230, \u800c\u5728\u53cc\u5411\u94fe\u8868\u4e2d\u68c0\u7d22 Item \u7684\u6548\u7387\u662f O(n), \u7279\u522b\u662f\u68c0\u7d22\u7684 Item \u5728\u94fe\u8868\u4e2d\u4e0d\u5b58\u5728\u65f6, \u6548\u7387\u7a33\u5b9a\u7684\u662f O(n). \u8fd9\u6837, \u5728\u7f13\u5b58\u7cfb\u7edf\u4e2d\u7ef4\u62a4\u8fd9\u4e2a\u53cc\u5411\u94fe\u8868\u7684\u6210\u672c\u662f\u975e\u5e38\u9ad8\u7684. \u4e00\u822c\u7684, \u4f1a\u5c06 <code>\u54c8\u5e0c\u8868<\/code> \u6216\u8005 <code>\u4e8c\u53c9\u641c\u7d22\u6811<\/code> \u548c\u53cc\u5411\u94fe\u8868\u7ec4\u5408\u8d77\u6765, \u5728\u66f4\u9ad8\u6548\u7387\u7684\u6570\u636e\u7ed3\u6784\u4e2d\u8bb0\u5f55 <code>Key<\/code>, \u5e76\u5728 <code>Key<\/code> \u4e2d\u8bb0\u5f55 Item \u5728\u53cc\u5411\u94fe\u8868\u4e2d\u7684\u6307\u9488.<\/p>\n<p>\u53e6\u5916\u7684, \u5728\u5e76\u53d1\u91cf\u8f83\u5927\u7684\u65f6\u5019, \u53cc\u5411\u94fe\u8868\u4e2d\u7684\u64cd\u4f5c\u9700\u8981\u52a0\u9501, \u5426\u5219\u94fe\u8868\u5f88\u5bb9\u6613\u51fa\u95ee\u9898.<\/p>\n<h2 id=\"ju-ti-shi-xian\"><a class=\"zola-anchor\" href=\"#ju-ti-shi-xian\" aria-label=\"Anchor link for: ju-ti-shi-xian\">\u5177\u4f53\u5b9e\u73b0<\/a><\/h2>\n<h3 id=\"redis-2-8\"><a class=\"zola-anchor\" href=\"#redis-2-8\" aria-label=\"Anchor link for: redis-2-8\">Redis 2.8<\/a><\/h3>\n<p>\u5728\u8f83\u65e9\u7248\u672c\u7684 <code>Redis<\/code> \u4e0a, \u5e76\u6ca1\u6709\u5b9e\u73b0 <code>LRU<\/code>. \u5728\u540e\u7eed 2.8 \u6dfb\u52a0\u7684\u65f6\u5019, \u5e76\u6ca1\u6709\u4f7f\u7528\u5e38\u89c1\u7684\u53cc\u5411\u94fe\u8868\u7684\u65b9\u5f0f\u6765\u5b9e\u73b0 <code>LRU<\/code>, \u800c\u4f7f\u7528\u4e86\u4e00\u4e2a\u8fd1\u4f3c\u7684\u5b9e\u73b0.<\/p>\n<p>\u4ece\u7a7a\u95f4\u548c\u65f6\u95f4\u4e0a\u8003\u8651, <code>Redis<\/code> \u4e2d\u7684 <code>Key<\/code> \u7684\u6570\u91cf\u53ef\u80fd\u975e\u5e38\u7684\u591a, \u53cc\u5411\u94fe\u8868\u53ef\u80fd\u4f1a\u975e\u5e38\u5927, \u5360\u7528\u5185\u5b58\u975e\u5e38\u591a; \u53e6\u4e00\u65b9\u9762, <code>Redis<\/code> \u4e2d\u7684\u64cd\u4f5c\u53ef\u80fd\u4e5f\u975e\u5e38\u9891\u7e41, \u6bcf\u4e00\u6b21\u8bbf\u95ee\u90fd\u9700\u8981\u64cd\u4f5c\u4e00\u6b21\u53cc\u5411\u94fe\u8868, \u5728\u65f6\u95f4\u4e0a\u4e5f\u663e\u5f97\u975e\u5e38\u4e0d\u5212\u7b97.<\/p>\n<p><code>Antirez<\/code> \u5728 <code>Redis Object<\/code> \u4e2d\u6324\u51fa\u4e86 24 \u4e2a\u4f4d\u5143 bits, \u5e76\u7528\u5176\u5b58\u50a8\u6309\u79d2\u8ba1\u7b97\u7684 <code>unix timestamp<\/code> \u7684\u4f4e 24 \u4f4d. \u8fd9\u4e2a\u88ab\u79f0\u4e3a <code>LRU clock<\/code>.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"c\"><span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/*<\/span><span class=\"z-l-5 z-d-3\"> https:\/\/github.com\/redis\/redis\/blob\/3.0\/src\/redis.h#L420 <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/*<\/span><span class=\"z-l-5 z-d-3\"> A redis object, that is a type able to hold a string \/ list \/ set <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/*<\/span><span class=\"z-l-5 z-d-3\"> The actual Redis Object <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">#<\/span><span class=\"z-l-8 z-d-10\">define<\/span><span class=\"z-l-6 z-d-7\"> REDIS_LRU_BITS<\/span><span class=\"z-l-1 z-d-4\"> 24<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">#<\/span><span class=\"z-l-8 z-d-10\">define<\/span><span class=\"z-l-6 z-d-7\"> REDIS_LRU_CLOCK_MAX<\/span><span> (<\/span><span>(<\/span><span class=\"z-l-1 z-d-4\">1<\/span><span class=\"z-l-8 z-d-10\">&lt;&lt;<\/span><span>REDIS_LRU_BITS<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\">-<\/span><span class=\"z-l-1 z-d-4\">1<\/span><span>)<\/span><span class=\"z-l-5 z-d-3\"> \/*<\/span><span class=\"z-l-5 z-d-3\"> Max value of obj-&gt;lru <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">#<\/span><span class=\"z-l-8 z-d-10\">define<\/span><span class=\"z-l-6 z-d-7\"> REDIS_LRU_CLOCK_RESOLUTION<\/span><span class=\"z-l-1 z-d-4\"> 1000<\/span><span class=\"z-l-5 z-d-3\"> \/*<\/span><span class=\"z-l-5 z-d-3\"> LRU clock resolution in ms <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">typedef<\/span><span class=\"z-l-8 z-d-10\"> struct<\/span><span> redisObject <\/span><span>{<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    unsigned<\/span><span> type:<\/span><span class=\"z-l-1 z-d-4\">4<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    unsigned<\/span><span> encoding:<\/span><span class=\"z-l-1 z-d-4\">4<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    unsigned<\/span><span> lru:REDIS_LRU_BITS<\/span><span>;<\/span><span class=\"z-l-5 z-d-3\"> \/*<\/span><span class=\"z-l-5 z-d-3\"> lru time (relative to server.lruclock) <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    int<\/span><span> refcount<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    void<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span>ptr<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><span> robj<\/span><span>;<\/span><\/span><\/code><\/pre>\n<p>24 \u4e2a bits \u660e\u663e\u4e0d\u591f\u5b58\u50a8\u4e00\u4e2a\u5b8c\u6574\u7684\u65f6\u95f4\u6233, \u5f53\u7b2c\u4e8c\u5341\u56db\u4f4d\u5411\u524d\u8fdb\u4f4d\u7684\u65f6\u5019, \u5c31\u4f1a\u53d1\u751f\u6ea2\u51fa. \u6b64\u65f6, \u6700\u8fd1\u88ab\u8bbf\u95ee\u7684 Item \u7684 <code>LRU clock<\/code> \u53cd\u800c\u8f83\u5c0f, \u66f4\u5bb9\u6613\u88ab\u6dd8\u6c70. \u8003\u8651\u5230\u8fd9\u4e2a\u6ea2\u51fa\u9700\u8981 194 \u5929, \u800c <code>Redis<\/code> \u4e2d\u7684\u64cd\u4f5c\u5e94\u8be5\u6bd4\u8f83\u9891\u7e41, \u6240\u4ee5 <code>antirez<\/code> \u8ba4\u4e3a\u8fd9\u4e2a\u95ee\u9898\u53ef\u4ee5\u63a5\u53d7.<\/p>\n<p>\u7406\u8bba\u4e0a, \u53ef\u4ee5\u7cbe\u5fc3\u6784\u9020\u4e00\u4e9b\u6570\u636e, \u8ba9 <code>Redis<\/code> \u7684 <code>LRU<\/code> \u5931\u6548. \u6bd4\u5982, \u603b\u662f\u5728\u6ea2\u51fa\u524d\u8bbf\u95ee\u4e00\u4e2a Item, \u8fd9\u4e2a Item \u7684 <code>LRU clock<\/code> \u603b\u662f\u5f88\u5927, \u867d\u7136\u8fd9\u4e2a Item \u7684\u8bbf\u95ee\u5468\u671f\u603b\u662f 194 \u5929\u624d\u8bbf\u95ee\u4e00\u6b21, \u4f46\u662f\u5b83\u603b\u4e0d\u4f1a\u88ab\u6dd8\u6c70.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"c\"><span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/*<\/span><span class=\"z-l-5 z-d-3\"> https:\/\/github.com\/redis\/redis\/blob\/3.0\/src\/db.c#L43 <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>robj <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-6 z-d-7\">lookupKey<\/span><span>(<\/span><span>redisDb <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-9 z-d-12\">db<\/span><span>,<\/span><span> robj <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-9 z-d-12\">key<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>    dictEntry <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span>de <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> dictFind<\/span><span>(<\/span><span>db<\/span><span>-&gt;<\/span><span>dict<\/span><span>,<\/span><span>key<\/span><span>-&gt;<\/span><span>ptr<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    if<\/span><span> (<\/span><span>de<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>        robj <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span>val <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> dictGetVal<\/span><span>(<\/span><span>de<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">        \/*<\/span><span class=\"z-l-5 z-d-3\"> Update the access time for the ageing algorithm.<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">         * Don&#39;t do it if we have a saving child, as this will trigger<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">         * a copy on write madness. <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        if<\/span><span> (<\/span><span>server<\/span><span>.<\/span><span>rdb_child_pid<\/span><span class=\"z-l-8 z-d-10\"> ==<\/span><span class=\"z-l-8 z-d-10\"> -<\/span><span class=\"z-l-1 z-d-4\">1<\/span><span class=\"z-l-8 z-d-10\"> &amp;&amp;<\/span><span> server<\/span><span>.<\/span><span>aof_child_pid<\/span><span class=\"z-l-8 z-d-10\"> ==<\/span><span class=\"z-l-8 z-d-10\"> -<\/span><span class=\"z-l-1 z-d-4\">1<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>            val<\/span><span>-&gt;<\/span><span>lru<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-6 z-d-7\"> LRU_CLOCK<\/span><span>(<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        return<\/span><span> val<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>    }<\/span><span class=\"z-l-8 z-d-10\"> else<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        return<\/span><span class=\"z-l-1 z-d-4\"> NULL<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>    }<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>\u63a5\u4e0b\u6765\u7684\u95ee\u9898\u5728\u4e8e\u5982\u4f55\u627e\u5230\u6700\u4e45\u6ca1\u6709\u88ab\u8bbf\u95ee\u7684 Item. \u5982\u679c\u4e00\u5b9a\u8981\u627e\u5230\u6700\u4e45\u6ca1\u6709\u88ab\u8bbf\u95ee\u5230\u7684 Item, \u90a3\u4e48\u9700\u8981\u904d\u5386\u6240\u6709\u7684 <code>Key<\/code>, \u800c\u4e14\u5728\u904d\u5386\u7684\u8fc7\u7a0b\u4e2d, \u8981\u4e48\u7981\u6b62\u5728\u8fd9\u671f\u95f4\u505a\u4efb\u4f55\u7684\u8bbf\u95ee\u64cd\u4f5c, \u8981\u4e48\u53ef\u80fd\u51fa\u73b0\u627e\u5230\u7684 <code>Key<\/code> \u6070\u597d\u53c8\u521a\u521a\u88ab\u8bbf\u95ee\u5230\u7684\u95ee\u9898.<\/p>\n<p><code>Antirez<\/code> \u5728\u8fd9\u91cc\u53c8\u4f7f\u7528\u4e86\u4e00\u4e2a\u8fd1\u4f3c\u7684\u5b9e\u73b0, \u968f\u673a\u9009\u53d6 3 \u4e2a <code>Key<\/code>, \u628a\u4ed6\u4eec\u4e4b\u4e2d\u6700\u4e45\u6ca1\u6709\u88ab\u8bbf\u95ee\u5230\u7684\u6dd8\u6c70. \u968f\u540e, \u8fd9\u4e2a\u6570\u503c\u53d8\u6210\u4e86\u53ef\u914d\u7f6e\u9879 <code>maxmemory-samples<\/code> , \u9ed8\u8ba4\u503c\u662f 5. \u8003\u8651\u5230\u9009\u51fa\u7684\u7ed3\u679c\u4e0d\u4e00\u5b9a\u662f\u6700\u597d\u7684, \u4f46\u662f\u5f88\u5927\u53ef\u80fd\u4e0d\u662f\u4e00\u4e2a\u574f\u7684\u7ed3\u679c, \u5373\u9009\u51fa\u4e00\u4e2a\u975e\u5e38\u8fd1\u88ab\u8bbf\u95ee\u7684 Item, \u8fd9\u4e2a\u5b9e\u73b0\u8fd8\u7b97\u53ef\u4ee5\u63a5\u53d7.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"c\"><span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/*<\/span><span class=\"z-l-5 z-d-3\"> https:\/\/github.com\/redis\/redis\/blob\/2.8\/src\/redis.c#L2982 <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/*<\/span><span class=\"z-l-5 z-d-3\"> volatile-lru and allkeys-lru policy <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">else<\/span><span class=\"z-l-8 z-d-10\"> if<\/span><span> (<\/span><span>server.maxmemory_policy <\/span><span class=\"z-l-8 z-d-10\">==<\/span><span> REDIS_MAXMEMORY_ALLKEYS_LRU <\/span><span class=\"z-l-8 z-d-10\">||<\/span><\/span>\n<span class=\"giallo-l\"><span>    server.maxmemory_policy <\/span><span class=\"z-l-8 z-d-10\">==<\/span><span> REDIS_MAXMEMORY_VOLATILE_LRU<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>{<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    for<\/span><span> (<\/span><span>k <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-1 z-d-4\"> 0<\/span><span>;<\/span><span> k <\/span><span class=\"z-l-8 z-d-10\">&lt;<\/span><span> server<\/span><span>.<\/span><span>maxmemory_samples<\/span><span>;<\/span><span> k<\/span><span class=\"z-l-8 z-d-10\">++<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>        sds thiskey<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        long<\/span><span> thisval<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>        robj <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span>o<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>        de <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> dictGetRandomKey<\/span><span>(<\/span><span>dict<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>        thiskey <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> dictGetKey<\/span><span>(<\/span><span>de<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">        \/*<\/span><span class=\"z-l-5 z-d-3\"> When policy is volatile-lru we need an additional lookup<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">          * to locate the real key, as dict is set to db-&gt;expires. <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        if<\/span><span> (<\/span><span>server<\/span><span>.<\/span><span>maxmemory_policy<\/span><span class=\"z-l-8 z-d-10\"> ==<\/span><span> REDIS_MAXMEMORY_VOLATILE_LRU<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>            de <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> dictFind<\/span><span>(<\/span><span>db<\/span><span>-&gt;<\/span><span>dict<\/span><span>,<\/span><span> thiskey<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>        o <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> dictGetVal<\/span><span>(<\/span><span>de<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>        thisval <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> estimateObjectIdleTime<\/span><span>(<\/span><span>o<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">        \/*<\/span><span class=\"z-l-5 z-d-3\"> Higher idle time is better candidate for deletion <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        if<\/span><span> (<\/span><span>bestkey <\/span><span class=\"z-l-8 z-d-10\">==<\/span><span class=\"z-l-1 z-d-4\"> NULL<\/span><span class=\"z-l-8 z-d-10\"> ||<\/span><span> thisval <\/span><span class=\"z-l-8 z-d-10\">&gt;<\/span><span> bestval<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>            bestkey <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span> thiskey<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>            bestval <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span> thisval<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>        }<\/span><\/span>\n<span class=\"giallo-l\"><span>    }<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre><h3 id=\"redis-3-0\"><a class=\"zola-anchor\" href=\"#redis-3-0\" aria-label=\"Anchor link for: redis-3-0\">Redis 3.0<\/a><\/h3>\n<p><code>Antirez<\/code> \u5728 3.0 \u7248\u672c\u4e2d\u8fdb\u4e00\u6b65\u63d0\u5347\u4e86\u8fd1\u4f3c\u7b97\u6cd5\u7684\u51c6\u786e\u6027. \u4e00\u4e2a\u663e\u800c\u6613\u89c1\u7684\u65b9\u6cd5\u662f, \u901a\u8fc7\u8fc7\u53bb\u7d2f\u8ba1\u7684\u4fe1\u606f\u6765\u63d0\u5347\u51c6\u786e\u6027.<\/p>\n<p><code>Redis<\/code> \u4e2d\u7ef4\u62a4\u4e86\u4e00\u4e2a\u9ed8\u8ba4\u5927\u5c0f\u4e3a 16 \u7684 <code>pool<\/code>, \u91cc\u9762\u5b58\u50a8\u4e86\u5907\u9009\u7684 <code>Key<\/code>. \u5f53\u9700\u8981\u6dd8\u6c70\u65f6, \u4ece\u968f\u673a\u9009\u62e9\u7684 N \u4e2a <code>Key<\/code> \u4e2d\u4e0e <code>pool<\/code> \u4e2d\u7684 <code>Key<\/code> \u505a\u5bf9\u6bd4, \u5728 <code>pool<\/code> \u4e2d\u7ef4\u62a4\u5176\u4e2d\u6700\u4e45\u6ca1\u6709\u88ab\u8bbf\u95ee\u5230\u7684 16 \u4e2a <code>Key<\/code>, \u7136\u540e\u5728 <code>pool<\/code> \u4e2d\u6dd8\u6c70\u5176\u4e2d\u6700\u4e45\u6ca1\u6709\u88ab\u8bbf\u95ee\u5230\u7684 Item. \u8fd9\u4e2a <code>pool<\/code> \u975e\u5e38\u7c7b\u4f3c\u4e8e\u5c0f\u9876\u5806.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"c\"><span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/*<\/span><span class=\"z-l-5 z-d-3\"> https:\/\/github.com\/redis\/redis\/blob\/3.0\/src\/redis.c#L3275 <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/*<\/span><span class=\"z-l-5 z-d-3\"> volatile-lru and allkeys-lru policy <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">else<\/span><span class=\"z-l-8 z-d-10\"> if<\/span><span> (<\/span><span>server.maxmemory_policy <\/span><span class=\"z-l-8 z-d-10\">==<\/span><span> REDIS_MAXMEMORY_ALLKEYS_LRU <\/span><span class=\"z-l-8 z-d-10\">||<\/span><\/span>\n<span class=\"giallo-l\"><span>    server.maxmemory_policy <\/span><span class=\"z-l-8 z-d-10\">==<\/span><span> REDIS_MAXMEMORY_VOLATILE_LRU<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>{<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    struct<\/span><span> evictionPoolEntry <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span>pool <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span> db<\/span><span>-&gt;<\/span><span>eviction_pool<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    while<\/span><span>(<\/span><span>bestkey <\/span><span class=\"z-l-8 z-d-10\">==<\/span><span class=\"z-l-1 z-d-4\"> NULL<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">        evictionPoolPopulate<\/span><span>(<\/span><span>dict<\/span><span>,<\/span><span> db<\/span><span>-&gt;<\/span><span>dict<\/span><span>,<\/span><span> db<\/span><span>-&gt;<\/span><span>eviction_pool<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">        \/*<\/span><span class=\"z-l-5 z-d-3\"> Go backward from best to worst element to evict. <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        for<\/span><span> (<\/span><span>k <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span> REDIS_EVICTION_POOL_SIZE<\/span><span class=\"z-l-8 z-d-10\">-<\/span><span class=\"z-l-1 z-d-4\">1<\/span><span>;<\/span><span> k <\/span><span class=\"z-l-8 z-d-10\">&gt;=<\/span><span class=\"z-l-1 z-d-4\"> 0<\/span><span>;<\/span><span> k<\/span><span class=\"z-l-8 z-d-10\">--<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">            if<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">pool<\/span><span>[<\/span><span>k<\/span><span>]<\/span><span>.<\/span><span>key<\/span><span class=\"z-l-8 z-d-10\"> ==<\/span><span class=\"z-l-1 z-d-4\"> NULL<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\"> continue<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>            de <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> dictFind<\/span><span>(<\/span><span>dict<\/span><span>,<\/span><span class=\"z-l-9 z-d-12\">pool<\/span><span>[<\/span><span>k<\/span><span>]<\/span><span>.<\/span><span>key<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">            \/*<\/span><span class=\"z-l-5 z-d-3\"> Remove the entry from the pool. <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">            sdsfree<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">pool<\/span><span>[<\/span><span>k<\/span><span>]<\/span><span>.<\/span><span>key<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">            \/*<\/span><span class=\"z-l-5 z-d-3\"> Shift all elements on its right to left. <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">            memmove<\/span><span>(<\/span><span>pool<\/span><span class=\"z-l-8 z-d-10\">+<\/span><span>k<\/span><span>,<\/span><span>pool<\/span><span class=\"z-l-8 z-d-10\">+<\/span><span>k<\/span><span class=\"z-l-8 z-d-10\">+<\/span><span class=\"z-l-1 z-d-4\">1<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                sizeof<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">pool<\/span><span>[<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>]<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span>(<\/span><span>REDIS_EVICTION_POOL_SIZE<\/span><span class=\"z-l-8 z-d-10\">-<\/span><span>k<\/span><span class=\"z-l-8 z-d-10\">-<\/span><span class=\"z-l-1 z-d-4\">1<\/span><span>)<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">            \/*<\/span><span class=\"z-l-5 z-d-3\"> Clear the element on the right which is empty<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">              * since we shifted one position to the left.  <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-12\">            pool<\/span><span>[<\/span><span>REDIS_EVICTION_POOL_SIZE<\/span><span class=\"z-l-8 z-d-10\">-<\/span><span class=\"z-l-1 z-d-4\">1<\/span><span>]<\/span><span>.<\/span><span>key<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-1 z-d-4\"> NULL<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-12\">            pool<\/span><span>[<\/span><span>REDIS_EVICTION_POOL_SIZE<\/span><span class=\"z-l-8 z-d-10\">-<\/span><span class=\"z-l-1 z-d-4\">1<\/span><span>]<\/span><span>.<\/span><span>idle<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-1 z-d-4\"> 0<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">            \/*<\/span><span class=\"z-l-5 z-d-3\"> If the key exists, is our pick. Otherwise it is<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">              * a ghost and we need to try the next element. <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">            if<\/span><span> (<\/span><span>de<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>                bestkey <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> dictGetKey<\/span><span>(<\/span><span>de<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                break<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>            }<\/span><span class=\"z-l-8 z-d-10\"> else<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">                \/*<\/span><span class=\"z-l-5 z-d-3\"> Ghost... <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                continue<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>            }<\/span><\/span>\n<span class=\"giallo-l\"><span>        }<\/span><\/span>\n<span class=\"giallo-l\"><span>    }<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p><code>pool<\/code> \u4e2d\u6392\u5e8f\u64cd\u4f5c\u7684\u6838\u5fc3\u4ee3\u7801\u5728 <code>evictionPoolPopulate<\/code> \u51fd\u6570\u4e2d<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"c\"><span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">\/*<\/span><span class=\"z-l-5 z-d-3\"> https:\/\/github.com\/redis\/redis\/blob\/3.0\/src\/redis.c#L3145 <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">#<\/span><span class=\"z-l-8 z-d-10\">define<\/span><span class=\"z-l-6 z-d-7\"> EVICTION_SAMPLES_ARRAY_SIZE<\/span><span class=\"z-l-1 z-d-4\"> 16<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">void<\/span><span class=\"z-l-6 z-d-7\"> evictionPoolPopulate<\/span><span>(<\/span><span>dict <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-9 z-d-12\">sampledict<\/span><span>,<\/span><span> dict <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-9 z-d-12\">keydict<\/span><span>,<\/span><span class=\"z-l-8 z-d-10\"> struct<\/span><span> evictionPoolEntry <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-9 z-d-12\">pool<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    int<\/span><span> j<\/span><span>,<\/span><span> k<\/span><span>,<\/span><span> count<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>    dictEntry <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-9 z-d-12\">_samples<\/span><span>[<\/span><span>EVICTION_SAMPLES_ARRAY_SIZE<\/span><span>]<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>    dictEntry <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span>samples<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">    \/*<\/span><span class=\"z-l-5 z-d-3\"> Try to use a static buffer: this function is a big hit...<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">     * Note: it was actually measured that this helps. <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    if<\/span><span> (<\/span><span>server<\/span><span>.<\/span><span>maxmemory_samples<\/span><span class=\"z-l-8 z-d-10\"> &lt;=<\/span><span> EVICTION_SAMPLES_ARRAY_SIZE<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>        samples <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span> _samples<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>    }<\/span><span class=\"z-l-8 z-d-10\"> else<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span>        samples <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> zmalloc<\/span><span>(<\/span><span class=\"z-l-8 z-d-10\">sizeof<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">samples<\/span><span>[<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>]<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span>server<\/span><span>.<\/span><span>maxmemory_samples<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>    }<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>    count <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> dictGetSomeKeys<\/span><span>(<\/span><span>sampledict<\/span><span>,<\/span><span>samples<\/span><span>,<\/span><span>server<\/span><span>.<\/span><span>maxmemory_samples<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    for<\/span><span> (<\/span><span>j <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-1 z-d-4\"> 0<\/span><span>;<\/span><span> j <\/span><span class=\"z-l-8 z-d-10\">&lt;<\/span><span> count<\/span><span>;<\/span><span> j<\/span><span class=\"z-l-8 z-d-10\">++<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        unsigned<\/span><span class=\"z-l-8 z-d-10\"> long<\/span><span class=\"z-l-8 z-d-10\"> long<\/span><span> idle<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>        sds key<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>        robj <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span>o<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>        dictEntry <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span>de<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>        de <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-9 z-d-12\"> samples<\/span><span>[<\/span><span>j<\/span><span>]<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>        key <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> dictGetKey<\/span><span>(<\/span><span>de<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">        \/*<\/span><span class=\"z-l-5 z-d-3\"> If the dictionary we are sampling from is not the main<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">         * dictionary (but the expires one) we need to lookup the key<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">         * again in the key dictionary to obtain the value object. <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        if<\/span><span> (<\/span><span>sampledict <\/span><span class=\"z-l-8 z-d-10\">!=<\/span><span> keydict<\/span><span>)<\/span><span> de <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> dictFind<\/span><span>(<\/span><span>keydict<\/span><span>,<\/span><span> key<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>        o <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> dictGetVal<\/span><span>(<\/span><span>de<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>        idle <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-6 z-d-7\"> estimateObjectIdleTime<\/span><span>(<\/span><span>o<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">        \/*<\/span><span class=\"z-l-5 z-d-3\"> Insert the element inside the pool.<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">         * First, find the first empty bucket or the first populated<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">         * bucket that has an idle time smaller than our idle time. <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span>        k <\/span><span class=\"z-l-8 z-d-10\">=<\/span><span class=\"z-l-1 z-d-4\"> 0<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        while<\/span><span> (<\/span><span>k <\/span><span class=\"z-l-8 z-d-10\">&lt;<\/span><span> REDIS_EVICTION_POOL_SIZE <\/span><span class=\"z-l-8 z-d-10\">&amp;&amp;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-12\">               pool<\/span><span>[<\/span><span>k<\/span><span>]<\/span><span>.<\/span><span>key<\/span><span class=\"z-l-8 z-d-10\"> &amp;&amp;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-12\">               pool<\/span><span>[<\/span><span>k<\/span><span>]<\/span><span>.<\/span><span>idle<\/span><span class=\"z-l-8 z-d-10\"> &lt;<\/span><span> idle<\/span><span>)<\/span><span> k<\/span><span class=\"z-l-8 z-d-10\">++<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        if<\/span><span> (<\/span><span>k <\/span><span class=\"z-l-8 z-d-10\">==<\/span><span class=\"z-l-1 z-d-4\"> 0<\/span><span class=\"z-l-8 z-d-10\"> &amp;&amp;<\/span><span class=\"z-l-9 z-d-12\"> pool<\/span><span>[<\/span><span>REDIS_EVICTION_POOL_SIZE<\/span><span class=\"z-l-8 z-d-10\">-<\/span><span class=\"z-l-1 z-d-4\">1<\/span><span>]<\/span><span>.<\/span><span>key<\/span><span class=\"z-l-8 z-d-10\"> !=<\/span><span class=\"z-l-1 z-d-4\"> NULL<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">            \/*<\/span><span class=\"z-l-5 z-d-3\"> Can&#39;t insert if the element is &lt; the worst element we have<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">             * and there are no empty buckets. <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">            continue<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>        }<\/span><span class=\"z-l-8 z-d-10\"> else<\/span><span class=\"z-l-8 z-d-10\"> if<\/span><span> (<\/span><span>k <\/span><span class=\"z-l-8 z-d-10\">&lt;<\/span><span> REDIS_EVICTION_POOL_SIZE <\/span><span class=\"z-l-8 z-d-10\">&amp;&amp;<\/span><span class=\"z-l-9 z-d-12\"> pool<\/span><span>[<\/span><span>k<\/span><span>]<\/span><span>.<\/span><span>key<\/span><span class=\"z-l-8 z-d-10\"> ==<\/span><span class=\"z-l-1 z-d-4\"> NULL<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">            \/*<\/span><span class=\"z-l-5 z-d-3\"> Inserting into empty position. No setup needed before insert. <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span>        }<\/span><span class=\"z-l-8 z-d-10\"> else<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">            \/*<\/span><span class=\"z-l-5 z-d-3\"> Inserting in the middle. Now k points to the first element<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">             * greater than the element to insert.  <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">            if<\/span><span> (<\/span><span class=\"z-l-9 z-d-12\">pool<\/span><span>[<\/span><span>REDIS_EVICTION_POOL_SIZE<\/span><span class=\"z-l-8 z-d-10\">-<\/span><span class=\"z-l-1 z-d-4\">1<\/span><span>]<\/span><span>.<\/span><span>key<\/span><span class=\"z-l-8 z-d-10\"> ==<\/span><span class=\"z-l-1 z-d-4\"> NULL<\/span><span>)<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">                \/*<\/span><span class=\"z-l-5 z-d-3\"> Free space on the right? Insert at k shifting<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">                 * all the elements from k to end to the right. <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">                memmove<\/span><span>(<\/span><span>pool<\/span><span class=\"z-l-8 z-d-10\">+<\/span><span>k<\/span><span class=\"z-l-8 z-d-10\">+<\/span><span class=\"z-l-1 z-d-4\">1<\/span><span>,<\/span><span>pool<\/span><span class=\"z-l-8 z-d-10\">+<\/span><span>k<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">                    sizeof<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">pool<\/span><span>[<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>]<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span>(<\/span><span>REDIS_EVICTION_POOL_SIZE<\/span><span class=\"z-l-8 z-d-10\">-<\/span><span>k<\/span><span class=\"z-l-8 z-d-10\">-<\/span><span class=\"z-l-1 z-d-4\">1<\/span><span>)<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>            }<\/span><span class=\"z-l-8 z-d-10\"> else<\/span><span> {<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">                \/*<\/span><span class=\"z-l-5 z-d-3\"> No free space on right? Insert at k-1 <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span>                k<\/span><span class=\"z-l-8 z-d-10\">--<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">                \/*<\/span><span class=\"z-l-5 z-d-3\"> Shift all elements on the left of k (included) to the<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-5 z-d-3\">                 * left, so we discard the element with smaller idle time. <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">                sdsfree<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">pool<\/span><span>[<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>]<\/span><span>.<\/span><span>key<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">                memmove<\/span><span>(<\/span><span>pool<\/span><span>,<\/span><span>pool<\/span><span class=\"z-l-8 z-d-10\">+<\/span><span class=\"z-l-1 z-d-4\">1<\/span><span>,<\/span><span class=\"z-l-8 z-d-10\">sizeof<\/span><span>(<\/span><span class=\"z-l-9 z-d-12\">pool<\/span><span>[<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>]<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span>k<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>            }<\/span><\/span>\n<span class=\"giallo-l\"><span>        }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-12\">        pool<\/span><span>[<\/span><span>k<\/span><span>]<\/span><span>.<\/span><span>key<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-6 z-d-7\"> sdsdup<\/span><span>(<\/span><span>key<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-9 z-d-12\">        pool<\/span><span>[<\/span><span>k<\/span><span>]<\/span><span>.<\/span><span>idle<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> idle<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>    }<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">    if<\/span><span> (<\/span><span>samples <\/span><span class=\"z-l-8 z-d-10\">!=<\/span><span> _samples<\/span><span>)<\/span><span class=\"z-l-6 z-d-7\"> zfree<\/span><span>(<\/span><span>samples<\/span><span>)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre><h2 id=\"can-kao-zi-liao\"><a class=\"zola-anchor\" href=\"#can-kao-zi-liao\" aria-label=\"Anchor link for: can-kao-zi-liao\">\u53c2\u8003\u8d44\u6599<\/a><\/h2>\n<ol>\n<li><a rel=\"external\" href=\"http:\/\/antirez.com\/news\/109\">Random notes on improving the Redis LRU algorithm<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/redis.io\/topics\/lru-cache\">Using Redis as an LRU cache<\/a><\/li>\n<\/ol>\n"},{"title":"DELL Precision T1700 SFF","published":"2020-12-04T00:52:03+08:00","updated":"2021-06-06T23:29:40+08:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/dell-t1700-sff\/"}},"id":"https:\/\/memwey.github.io\/posts\/dell-t1700-sff\/","content":"<p>\u539f\u672c\u7684\u53f0\u5f0f\u673a, E3-1231v3 \u642d\u914d\u4e0a\u5728\u6316\u77ff\u72c2\u6f6e\u524d\u4e70\u7684 GTX 1070, \u5728\u8fd9\u4e2a\u666e\u904d\u6324\u7259\u818f\u7684\u65f6\u671f\u611f\u89c9\u518d\u6218\u4e09\u5e74\u4e0d\u6210\u95ee\u9898. \u4e0d\u8fc7\u65e2\u7136\u6709\u4e86\u81ea\u5df1\u7684\u4e66\u623f, \u4e66\u623f\u91cc\u6ca1\u6709\u7535\u8111\u662f\u4e07\u4e07\u4e0d\u80fd\u7684. \u770b\u4e86\u4e00\u4e0b\u81ea\u5df1\u7684\u94b1\u5305<del>\u548c\u4eac\u4e1c\u7684\u65e0\u8d27<\/del>, \u51b3\u5b9a\u7528 \u65b0\u5e73\u53f0 + \u8001\u663e\u5361, \u8001\u5e73\u53f0 + \u5165\u95e8\u663e\u5361 \u8fd9\u6837\u7684\u7ec4\u5408, \u8ba9\u4e00\u53f0\u7535\u8111\u53d8\u6210\u4e24\u53f0.<\/p>\n<h2 id=\"tiao-xuan-guo-cheng\"><a class=\"zola-anchor\" href=\"#tiao-xuan-guo-cheng\" aria-label=\"Anchor link for: tiao-xuan-guo-cheng\">\u6311\u9009\u8fc7\u7a0b<\/a><\/h2>\n<p>\u65b0\u5e73\u53f0\u6682\u4e14\u4e0d\u8868, \u6709\u7a7a\u53e6\u5916\u8bb0\u5f55. \u8fd9\u6bb5\u5176\u5b9e\u8df3\u8fc7\u4e5f\u884c, \u90fd\u662f\u4e00\u4e9b\u6d41\u6c34\u8d26.<\/p>\n<p>\u9996\u5148\u8fd8\u662f\u51b3\u5b9a\u7ed9\u8001\u5e73\u53f0\u589e\u52a0\u4e00\u4e9b\u4fbf\u643a\u6027, \u6bd5\u7adf\u6027\u80fd\u591f\u7528\u5c31\u597d, \u79df\u623f\u4f4f\u7684\u751f\u6d3b\u8fd8\u662f\u8981\u8003\u8651\u642c\u5bb6\u7684, \u4e4b\u524d\u7684\u5168\u94dd\u52a0\u94a2\u5316\u73bb\u7483\u673a\u7bb1\u642c\u8d77\u6765\u786e\u5b9e\u4e0d\u65b9\u4fbf. \u53e6\u5916, \u5bf9\u4e4b\u524d\u7684\u4e5e\u4e10\u7248\u4e3b\u677f\u548c\u7535\u6e90\u4e5f\u90fd\u4e0d\u592a\u6ee1\u610f, \u4f46\u662f\u95ee\u9898\u6700\u5927\u7684\u5c31\u662f\u4e3b\u677f, LGA 1150 \u5e73\u53f0\u7684 ITX \u4e3b\u677f\u6570\u91cf\u7a00\u5c11\u4e14\u4ef7\u683c\u6602\u8d35. \u8f6c\u6362\u601d\u8def\u60f3\u4e00\u60f3, \u673a\u7bb1, \u4e3b\u677f, \u7535\u6e90, \u8fd9\u4e0d\u5c31\u662f\u4e00\u4e2a\u51c6\u7cfb\u7edf\u5417.<\/p>\n<p>\u6dd8\u5b9d\u901b\u4e86\u4e00\u4e0b\u53d1\u73b0, \u4e3b\u8981\u662f DELL \u548c HP \u7684 SFF (Small Form Factor) \u578b\u51c6\u7cfb\u7edf\u6bd4\u8f83\u7b26\u5408\u9700\u6c42. \u4e3b\u8981\u578b\u53f7\u5305\u62ec <code>DELL OptiPlex 3020<\/code>, <code>DELL OptiPlex 7020<\/code>, <code>DELL OptiPlex 9020<\/code>, <code>DELL Precision T1700<\/code>, <code>HP ProDesk 400 G1<\/code>, <code>HP ProDesk 600 G1<\/code>, <code>HP ProDesk 800 G1<\/code>, <code>HP Z230<\/code>. \u540c\u7cfb\u5217\u7684\u4ea7\u54c1\u5f88\u597d\u6bd4\u8f83, \u6570\u5b57\u8d8a\u5927\u7ea6\u597d, \u4e0d\u8fc7\u5176\u5b9e\u4e5f\u6ca1\u592a\u5927\u533a\u522b. HP \u7684\u673a\u5668\u76f8\u6bd4 DELL \u7684\u7a0d\u5fae\u5927\u4e00\u4e9b, \u6269\u5c55\u6027\u7a0d\u5f3a.<\/p>\n<p><code>DELL Precision T1700<\/code> \u5728\u4ee5\u4e0a\u578b\u53f7\u4e2d\u8131\u9896\u800c\u51fa\u7684\u539f\u56e0\u53ef\u80fd\u5c31\u662f\u56e0\u4e3a\u5b83\u662f <code>Workstation<\/code> \u548c <code>C226<\/code> \u4e3b\u677f\u82af\u7247\u7ec4<del>\u548c\u5b83\u4e0d\u5c5e\u4e8e\u641e\u7684\u4eba\u5934\u6655\u7684\u5bb6\u65cf\u5f0f\u578b\u53f7<\/del>\u5427.<\/p>\n<h2 id=\"xi-tong-jie-shao\"><a class=\"zola-anchor\" href=\"#xi-tong-jie-shao\" aria-label=\"Anchor link for: xi-tong-jie-shao\">\u7cfb\u7edf\u4ecb\u7ecd<\/a><\/h2>\n<ul>\n<li>\u5c3a\u5bf8: 290.00mm * 92.60mm * 312.00mm<\/li>\n<li>\u4f53\u79ef: 8.38L<\/li>\n<li>\u91cd\u91cf: 5.30KG<\/li>\n<li>\u7535\u6e90\u8f93\u51fa: 255W<\/li>\n<\/ul>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/dell-t1700-sff\/images\/%E6%9C%BA%E7%AE%B1%E5%89%8D%E9%9D%A2%E6%9D%BF.jpeg\" alt=\"\u673a\u7bb1\u524d\u9762\u677f\" \/>\n\u56fe. \u673a\u7bb1\u524d\u9762\u677f<\/p>\n<p>\u4f53\u79ef\u5b8c\u5168\u53ef\u4ee5\u79f0\u5f97\u4e0a\u5c0f\u5de7. C226 \u4e3b\u677f\u53ef\u4ee5\u8ba9 LGA 1150 \u7684 E3-1231v3 \u548c DDR3 \u7684\u4e24\u6761\u5185\u5b58\u6761\u53d1\u6325\u4f59\u70ed<del>\u548c\u4f53\u9a8c\u5de5\u4f5c\u7ad9\u4e3b\u677f<\/del>. \u652f\u6301\u4e00\u5f20\u534a\u9ad8\u663e\u5361\u53ef\u4ee5\u5728 E3-1231v3 \u6ca1\u6709\u6838\u5fc3\u663e\u5361\u548c\u4e00\u5b9a\u7684\u6e38\u620f\u9700\u6c42\u4e2d\u627e\u5230\u4e00\u4e2a\u80fd\u7528\u7684\u89e3\u51b3\u65b9\u6848.<\/p>\n<h2 id=\"ying-jian-pei-zhi\"><a class=\"zola-anchor\" href=\"#ying-jian-pei-zhi\" aria-label=\"Anchor link for: ying-jian-pei-zhi\">\u786c\u4ef6\u914d\u7f6e<\/a><\/h2>\n<ul>\n<li>CPU: Intel Xeon E3-1231 v3 @ 3.40GHz 4C8T<\/li>\n<li>RAM: G.SKILL 8G 1600MHz (x2)<\/li>\n<li>GPU: NVIDIA GeForce GTX 1650 4G<\/li>\n<li>SSD: GLOWAY STK240GS3-S7<\/li>\n<li>Wi-Fi: Intel Dual Band Wireless-AC 7265<\/li>\n<\/ul>\n<p>\u5176\u4f59\u8bf8\u5982\u4e3b\u677f, \u673a\u7bb1, \u7535\u6e90, \u6563\u70ed\u5668\u90fd\u662f\u51c6\u7cfb\u7edf\u81ea\u5e26\u7684.<\/p>\n<p>\u7531\u4e8e\u663e\u5361\u5fc5\u987b\u8981 <strong>\u5355\u69fd\u4f4d<\/strong> \u7684 <strong>\u534a\u9ad8<\/strong> \u663e\u5361, \u6240\u4ee5\u8fd9\u5757 <code>\u7fd4\u5347 GTX1650 4GD5 \u6218\u5200<\/code> \u5e94\u8be5\u662f\u76ee\u524d(2020-11-01)\u80fd\u4e70\u5230\u7684<del>\u73b0\u5728\u5df2\u7ecf\u4e70\u4e0d\u5230\u4e86, \u521a\u770b\u4e86\u4e00\u4e0b<\/del>\u6700\u5f3a\u7684\u663e\u5361\u4e86.<\/p>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/dell-t1700-sff\/images\/%E6%98%BE%E5%8D%A1.jpeg\" alt=\"\u4f46\u662f\u957f\u7684\u6709\u70b9\u4e11\" \/>\n\u56fe. \u4f46\u662f\u957f\u7684\u6709\u70b9\u4e11<\/p>\n<p>\u5176\u4f59\u914d\u4ef6\u5c31\u90fd\u662f\u4ece\u8001\u673a\u5668\u4e0a\u62c6\u4e0b\u6765\u7684\u4e86, \u552f\u4e00\u6709\u70b9\u4f8b\u5916\u7684\u662f\u65e0\u7ebf\u7f51\u5361, \u56e0\u4e3a\u662f PCIe \u7f51\u5361, \u4e4b\u524d\u662f\u5168\u9ad8\u6321\u677f, \u6dd8\u5b9d\u7b97\u4e0a\u90ae\u8d39 7 \u5757\u94b1\u4e70\u4e86\u4e2a\u534a\u9ad8\u6321\u677f\u89e3\u51b3. \u4ece\u5317\u4eac\u5feb\u9012\u8fc7\u6765\u90ae\u8d39\u53ea\u8981 4 \u5757\u94b1, \u6211\u4e5f\u662f\u60ca\u4e86.<\/p>\n<h2 id=\"zhuang-ji-ti-yan\"><a class=\"zola-anchor\" href=\"#zhuang-ji-ti-yan\" aria-label=\"Anchor link for: zhuang-ji-ti-yan\">\u88c5\u673a\u4f53\u9a8c<\/a><\/h2>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/dell-t1700-sff\/images\/%E6%9C%BA%E7%AE%B1%E5%90%8E%E9%9D%A2%E6%9D%BF.jpeg\" alt=\"\u673a\u7bb1\u540e\u9762\u677f\" \/>\n\u56fe. \u673a\u7bb1\u540e\u9762\u677f<\/p>\n<p>\u5c0f\u5c0f\u673a\u8eab\u62e5\u6709\u524d\u7f6e 4 \u4e2a USB \u52a0\u540e\u7f6e 6 \u4e2a USB, \u6570\u91cf\u60ca\u4eba. \u751a\u81f3\u8fd8\u5e26\u4e86 PS\/2 \u952e\u9f20\u63a5\u53e3\u548c RS-232 \u4e32\u884c\u63a5\u53e3. \u663e\u793a\u8f93\u51fa\u5e26\u4e86\u4e24\u4e2a DP \u548c\u4e00\u4e2a VGA \u8fd9\u5bf9\u65b0\u8001\u642d\u6863, \u7f3a\u5c11\u4e2d\u9752\u4ee3\u7684 HDMI \u548c DVI \u53ef\u80fd\u4f1a\u6709\u70b9\u4e0d\u4fbf. <del>\u7528\u72ec\u7acb\u663e\u5361\u5c31\u65e0\u6240\u8c13\u4e86.<\/del><\/p>\n<p>\u673a\u7bb1\u5b8c\u5168\u662f\u514d\u87ba\u4e1d\u62c6\u88c5\u7684, \u7ef4\u62a4\u6027\u5f88\u597d. \u673a\u7bb1\u5185\u90e8\u6709\u5927\u91cf\u5851\u6599\u7684\u90e8\u5206, \u4e3b\u8981\u8d77\u8c03\u6574\u98ce\u9053\u548c\u56fa\u5b9a\u7684\u4f5c\u7528. \u7535\u6e90\u548c\u524d\u9762\u677f\u98ce\u6247\u4ece\u524d\u9762\u677f\u4e0b\u65b9\u5438\u98ce, \u4ece\u673a\u7bb1\u540e\u90e8\u6392\u51fa\u70ed\u98ce.<\/p>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/dell-t1700-sff\/images\/%E6%9C%BA%E7%AE%B1%E5%86%85%E9%83%A8.jpeg\" alt=\"\u673a\u7bb1\u5185\u90e8\" \/>\n\u56fe. \u673a\u7bb1\u5185\u90e8<\/p>\n<p>\u867d\u7136\u4e3b\u677f\u4e0a\u6709\u4e09\u4e2a SATA \u63a5\u53e3, \u4f46\u5b9e\u9645\u4e0a\u53ea\u6709\u4e00\u4e2a\u6807\u51c6\u7684\u786c\u76d8\u4f9b\u7535, \u51d1\u5408\u7740\u548c\u4e00\u4e2a\u975e\u6807\u51c6\u7684\u5149\u9a71\u4f9b\u7535\u4e00\u8d77\u4ece\u4e3b\u677f\u4e0a\u5f15\u51fa, \u6240\u4ee5\u60f3\u8981\u4f7f\u7528\u8d85\u8fc7\u4e00\u4e2a\u786c\u76d8\u8981\u60f3\u60f3\u529e\u6cd5, \u53ef\u4ee5\u4f7f\u7528\u4e00\u8f6c\u4e8c\u7684\u786c\u76d8\u4f9b\u7535\u4ec0\u4e48\u7684.<\/p>\n<p>\u5982\u679c\u4f7f\u7528\u5355\u4e2a\u56fa\u6001\u786c\u76d8\u7684\u8bdd, \u76f4\u63a5\u628a\u56fa\u6001\u786c\u76d8\u585e\u5230\u90a3\u4e2a 3.5 \u5bf8\u673a\u68b0\u786c\u76d8\u4f4d\u5c31\u597d\u4e86, \u4e0d\u8fc7\u6709\u673a\u68b0\u786c\u76d8\u7684\u8bdd, \u56fa\u6001\u786c\u76d8\u5c31\u4e0d\u592a\u597d\u5b89\u653e\u4e86, \u597d\u5728\u7a7a\u95f4\u8fd8\u7b97\u591a, \u56fa\u6001\u786c\u76d8\u4e5f\u5f88\u575a\u5f3a, \u627e\u4e2a\u5730\u65b9\u585e\u4e00\u4e0b\u95ee\u9898\u4e0d\u5927.<\/p>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/dell-t1700-sff\/images\/%E5%86%85%E9%83%A8%E7%BB%86%E8%8A%82.jpeg\" alt=\"\u51cc\u4e71\u7684\u5185\u90e8\" \/>\n\u56fe. \u51cc\u4e71\u7684\u5185\u90e8<\/p>\n<p>\u975e\u6807\u51c6\u7684\u7535\u6e90\u53ea\u6709 255W, \u800c\u4e14\u53ea\u6709\u4e00\u4e2a 8pin \u7684\u4e3b\u677f\u4f9b\u7535\u548c\u4e00\u4e2a 4pin \u7684 CPU \u4f9b\u7535, \u6ca1\u6709\u4efb\u4f55 PCIe \u4f9b\u7535. \u4e0d\u8fc7\u53cd\u6b63\u534a\u9ad8\u663e\u5361\u4e5f\u57fa\u672c\u90fd\u662f\u80fd\u88ab PCIe 16X \u7684 75W \u4f9b\u7535\u6ee1\u8db3\u7684.<\/p>\n<p>\u56db\u4e2a\u6807\u51c6\u53f0\u5f0f\u673a\u5185\u5b58\u63d2\u69fd\u591f\u7528, \u7ed9\u5df2\u7ecf\u6210\u4e3a\u65f6\u4ee3\u7684\u773c\u6cea\u7684 DDR3 \u5185\u5b58\u627e\u4e00\u4e2a\u5bb6. \u63d2\u69fd\u4e0a\u6709\u6e05\u6670\u7684\u7f16\u53f7, \u6309\u7167\u987a\u5e8f\u63d2\u4e0a\u5373\u53ef.<\/p>\n<p>\u4e3b\u677f\u63d0\u4f9b\u4e86\u4e24\u4e2a PCIe \u63d2\u69fd, \u4e00\u4e2a\u5168\u957f x16, \u53e6\u4e00\u4e2a\u662f x4. \u4f46\u662f\u95ee\u9898\u662f 16x \u7684\u53cd\u800c 4x \u7684\u4e0b\u9762, \u800c\u4e14\u8ddd\u79bb\u518d\u4e0b\u9762\u7684\u7535\u6e90\u5f88\u8fd1, \u6240\u4ee5\u8981\u60f3\u8ba9\u663e\u5361\u5145\u5206\u53d1\u6325\u53ea\u80fd\u7528\u5355\u69fd\u4f4d\u7684. \u4e0d\u8fc7\u8fd9\u5757 <code>\u7fd4\u5347 GTX1650 4GD5 \u6218\u5200<\/code> \u662f\u6da1\u8f6e\u6563\u70ed, \u4ece\u663e\u5361\u9876\u7aef\u7684\u98ce\u6247\u5438\u98ce\u5230\u5c3e\u90e8\u6392\u51fa, \u548c\u673a\u7bb1\u539f\u6709\u7684\u524d\u9762\u677f\u98ce\u6247\u98ce\u9053\u4e00\u81f4, \u6563\u70ed\u5e94\u8be5\u8fd8\u597d. \u6709\u673a\u53cb\u53cd\u9988\u663e\u5361\u592a\u957f\u4f1a\u6321\u4f4f\u90e8\u5206 SATA \u63a5\u53e3, \u8fd9\u5757\u663e\u5361\u56e0\u4e3a\u66f4\u77ed\u4e86, \u6240\u4ee5\u6ca1\u6709\u8fd9\u4e2a\u60c5\u51b5.<\/p>\n<p>\u4e3b\u677f\u4e0a\u771f\u7684\u662f\u4e00\u4e2a\u591a\u4f59\u7684\u63a5\u53e3\u90fd\u6ca1\u6709, \u5bfc\u81f4 PCIe \u65e0\u7ebf\u7f51\u5361\u84dd\u7259\u529f\u80fd\u6240\u9700\u7684 USB \u63d2\u5934\u65e0\u5904\u5b89\u653e. \u597d\u5427, \u5c0f\u95ee\u9898.<\/p>\n<p>\u673a\u7bb1\u8fd8\u6709\u4e00\u4e2a\u5185\u7f6e\u7684\u5c0f\u97f3\u54cd, \u867d\u7136\u97f3\u8d28\u4ec0\u4e48\u7684\u53ea\u80fd\u8bf4\u662f\u542c\u4e2a\u54cd, \u751a\u81f3\u8fd8\u4e0d\u600e\u4e48\u54cd, \u4f46\u662f\u5e94\u6025\u4ec0\u4e48\u7684\u8fd8\u662f\u633a\u597d\u7528\u7684.<\/p>\n<p>\u539f\u914d\u7684\u6563\u70ed\u5668\u662f\u5168\u94dd\u7684, \u4e4b\u524d\u751a\u81f3\u90fd\u6ca1\u89c1\u8fc7\u8fd9\u4e48\u5bd2\u9178\u7684\u6563\u70ed\u5668. \u5728\u4e07\u80fd\u7684\u6dd8\u5b9d\u4e0a\u53d1\u73b0\u4e86\u53ef\u7528\u7684\u94dc\u82af\u6563\u70ed\u5668 <code>J9G15<\/code>, \u636e\u5546\u5bb6\u6240\u8bf4\u662f\u539f\u914d\u7ed9\u66f4\u9ad8\u7aef\u7684 <code>XE2<\/code> \u673a\u578b\u7684\u6563\u70ed\u5668, \u6bd4\u5168\u94dd\u7684\u91cd\u4e86\u6709 90 \u514b. \u82b1\u8d39 46.8 \u5165\u624b\u4e00\u53ea\u6362\u4e0a, \u611f\u89c9\u6e29\u5ea6\u786e\u5b9e\u4e0b\u964d\u4e86\u4e0d\u5c11.<\/p>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/dell-t1700-sff\/images\/%E6%9C%BA%E7%AE%B1%E5%A4%A7%E5%B0%8F.jpeg\" alt=\"\u673a\u7bb1\u5927\u5c0f\" \/>\n\u56fe. \u673a\u7bb1\u5927\u5c0f\u53c2\u8003<\/p>\n<h2 id=\"can-kao-zi-liao\"><a class=\"zola-anchor\" href=\"#can-kao-zi-liao\" aria-label=\"Anchor link for: can-kao-zi-liao\">\u53c2\u8003\u8d44\u6599<\/a><\/h2>\n<ol>\n<li><a rel=\"external\" href=\"https:\/\/dl.dell.com\/topicspdf\/precision-t1700-workstation_owners-manual2_zh-cn.pdf\">Dell Precision T1700 \u5c0f\u578b\u8ba1\u7b97\u673a \u7528\u6237\u624b\u518c<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/blog.shellbin.me\/?p=911\">Dell Precision T1700 SFF \u6512\u673a\u4e0e\u4f7f\u7528\n<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/zhuanlan.zhihu.com\/p\/141329970\">\u5e74\u8f7b\u4eba\u7684\u7b2c\u4e00\u53f0Precision<\/a><\/li>\n<\/ol>\n"},{"title":"[\u7ffb\u8bd1] Kubernetes \u7f51\u7edc\u6a21\u578b\u6307\u5357","published":"2019-10-28T18:55:42+08:00","updated":"2019-10-28T18:55:42+08:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/a-guide-to-the-kubernetes-networking-model\/"}},"id":"https:\/\/memwey.github.io\/posts\/a-guide-to-the-kubernetes-networking-model\/","content":"<p><a rel=\"external\" href=\"https:\/\/sookocheff.com\/post\/kubernetes\/understanding-kubernetes-networking-model\/\">\u82f1\u6587\u539f\u6587<\/a><\/p>\n<p>Kubernetes \u65e8\u5728\u5728\u4e00\u7ec4\u673a\u5668\u4e0a\u8fd0\u884c\u5206\u5e03\u5f0f\u7cfb\u7edf\u3002\u5206\u5e03\u5f0f\u7cfb\u7edf\u7684\u672c\u8d28\u4f7f\u7f51\u7edc\u6210\u4e3a Kubernetes \u90e8\u7f72\u4e2d\u7684\u6838\u5fc3\u4e14\u5fc5\u8981\u7684\u90e8\u5206\uff0c\u4e86\u89e3 Kubernetes \u7f51\u7edc\u6a21\u578b\u5c06\u4f7f\u4f60\u80fd\u591f\u6b63\u786e\u5730\u8fd0\u884c\uff0c\u76d1\u63a7\u548c\u6392\u67e5\u5728 Kubernetes \u4e0a\u8fd0\u884c\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u7f51\u7edc\u662f\u4e00\u4e2a\u62e5\u6709\u8bb8\u591a\u6210\u719f\u6280\u672f\u7684\u5e7f\u9614\u9886\u57df\u3002\u5bf9\u4e8e\u4e0d\u90a3\u4e48\u719f\u6089\u8fd9\u4e2a\u9886\u57df\u7684\u4eba\u6765\u8bf4\uff0c\u8fd9\u53ef\u80fd\u4f1a\u4ee4\u4eba\u611f\u5230\u4e0d\u9002\uff0c\u56e0\u4e3a\u5927\u591a\u6570\u4eba\u5df2\u7ecf\u5bf9\u7f51\u7edc\u6709\u4e86\u5148\u5165\u4e3a\u4e3b\u7684\u89c2\u5ff5\uff0c\u800c\u5728 Kubernetes \u4e2d\u6709\u5f88\u591a\u65b0\u65e7\u6982\u5ff5\u9700\u8981\u7406\u89e3\u5e76\u5c06\u5b83\u4eec\u878d\u5408\u4e3a\u4e00\u4e2a\u6574\u4f53\u3002\u4e00\u4e2a\u7c97\u7565\u7684\u5217\u8868\u53ef\u80fd\u5305\u62ec\u8bf8\u5982\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\uff0c\u865a\u62df\u63a5\u53e3\uff0cIP \u8f6c\u53d1\u548c\u7f51\u7edc\u5730\u5740\u8f6c\u6362\u4e4b\u7c7b\u7684\u6280\u672f\u3002\u672c\u6307\u5357\u65e8\u5728\u901a\u8fc7\u8ba8\u8bba\u5404\u79cd Kubernetes \u4f9d\u9760\u7684\u6280\u672f\u4ee5\u53ca\u5bf9\u8fd9\u4e9b\u6280\u672f\u662f\u5982\u4f55\u7528\u6765\u5b9e\u73b0 Kubernetes \u7f51\u7edc\u6a21\u578b\u7684\u63cf\u8ff0\u6765\u8bb2\u89e3 Kubernetes \u7f51\u7edc\u6a21\u578b\u3002<\/p>\n<p>\u672c\u6307\u5357\u76f8\u5f53\u957f\uff0c\u5206\u4e3a\u51e0\u4e2a\u90e8\u5206\u3002\u6211\u4eec\u9996\u5148\u8ba8\u8bba\u4e00\u4e9b\u57fa\u672c\u7684 Kubernetes \u672f\u8bed\u4ee5\u786e\u4fdd\u5728\u6574\u4e2a\u6307\u5357\u4e2d\u6b63\u786e\u4f7f\u7528\u672f\u8bed\uff0c\u7136\u540e\u8ba8\u8bba Kubernetes \u7684\u7f51\u7edc\u6a21\u578b\u4ee5\u53ca\u5b83\u89c4\u5b9a\u7684\u8bbe\u8ba1\u548c\u5b9e\u73b0\u51b3\u7b56\u3002\u63a5\u4e0b\u6765\u662f\u672c\u6307\u5357\u4e2d\u6700\u957f\u4e14\u6700\u6709\u8da3\u7684\u90e8\u5206\uff1a\u901a\u8fc7\u51e0\u79cd\u4e0d\u540c\u7684\u7528\u4f8b\u6df1\u5165\u8ba8\u8bba\u6d41\u91cf\u662f\u5982\u4f55\u5728 Kubernetes \u4e2d\u88ab\u8def\u7531\u7684\u3002<\/p>\n<p>\u5982\u679c\u60a8\u5bf9\u4e00\u4e9b\u7f51\u7edc\u672f\u8bed\uff0c\u672c\u6307\u5357\u9644\u6709\u7f51\u7edc\u672f\u8bed\u8bcd\u6c47\u8868\u3002<\/p>\n<h2 id=\"mu-lu\"><a class=\"zola-anchor\" href=\"#mu-lu\" aria-label=\"Anchor link for: mu-lu\">\u76ee\u5f55<\/a><\/h2>\n<ul>\n<li>1 Kubernetes \u57fa\u7840\u77e5\u8bc6<\/li>\n<li>2 Kubernetes \u7f51\u7edc\u6a21\u578b<\/li>\n<li>3 Container \u5230 Container \u7f51\u7edc<\/li>\n<li>4 Pod \u5230 Pod \u7f51\u7edc<\/li>\n<li>5 Pod \u5230 Service \u7f51\u7edc<\/li>\n<li>6 Internet \u5230 Service \u7f51\u7edc<\/li>\n<li>6.1 Egress<\/li>\n<li>6.2 Ingress<\/li>\n<li>7 \u603b\u7ed3<\/li>\n<li>8 \u672f\u8bed\u8868<\/li>\n<\/ul>\n<h2 id=\"1-kubernetes-ji-chu-zhi-shi\"><a class=\"zola-anchor\" href=\"#1-kubernetes-ji-chu-zhi-shi\" aria-label=\"Anchor link for: 1-kubernetes-ji-chu-zhi-shi\">1 Kubernetes \u57fa\u7840\u77e5\u8bc6<\/a><\/h2>\n<p>Kubernetes \u662f\u7531\u4e00\u4e9b\u6838\u5fc3\u6982\u5ff5\u6784\u5efa\u800c\u6210\u7684\uff0c\u8fd9\u4e9b\u6838\u5fc3\u6982\u5ff5\u88ab\u7ec4\u5408\u6210\u8d8a\u6765\u8d8a\u5f3a\u5927\u7684\u529f\u80fd\u3002\u672c\u8282\u5217\u51fa\u4e86\u8fd9\u4e9b\u6982\u5ff5\uff0c\u5e76\u63d0\u4f9b\u4e86\u7b80\u8981\u6982\u8ff0\u4ee5\u5e2e\u52a9\u4fc3\u8fdb\u8ba8\u8bba\u3002Kubernetes \u7684\u529f\u80fd\u8fdc\u4e0d\u6b62\u8fd9\u91cc\u5217\u51fa\u7684\u5185\u5bb9\uff0c\u672c\u8282\u4f5c\u4e3a\u5165\u95e8\u4f7f\u8bfb\u8005\u53ef\u4ee5\u5728\u540e\u7eed\u90e8\u5206\u4e2d\u53c2\u8003\u3002\u5982\u679c\u60a8\u5df2\u7ecf\u719f\u6089 Kubernetes\uff0c\u8bf7\u968f\u610f\u8df3\u8fc7\u672c\u8282\u3002<\/p>\n<h3 id=\"1-1-kubernetes-api-fu-wu-qi\"><a class=\"zola-anchor\" href=\"#1-1-kubernetes-api-fu-wu-qi\" aria-label=\"Anchor link for: 1-1-kubernetes-api-fu-wu-qi\">1.1 Kubernetes API \u670d\u52a1\u5668<\/a><\/h3>\n<p>\u5728 Kubernetes \u4e2d\uff0c\u4e00\u5207\u90fd\u662f\u7531 Kubernetes API \u670d\u52a1\u5668 (<code>kube-apiserver<\/code>) \u63d0\u4f9b\u7684 API \u8c03\u7528\u3002API \u670d\u52a1\u5668\u662f\u901a\u5f80\u7ef4\u62a4\u7740\u5e94\u7528\u7a0b\u5e8f\u96c6\u7fa4\u7684\u6240\u9700\u72b6\u6001\u7684 <a rel=\"external\" href=\"https:\/\/github.com\/coreos\/etcd\">etcd<\/a> \u6570\u636e\u5b58\u50a8\u7684\u7f51\u5173\u3002\u8981\u66f4\u65b0 Kubernetes \u96c6\u7fa4\u7684\u72b6\u6001\uff0c\u60a8\u9700\u8981\u5bf9 API \u670d\u52a1\u5668\u8fdb\u884c API \u8c03\u7528\u4ee5\u63cf\u8ff0\u6240\u9700\u7684\u72b6\u6001\u3002<\/p>\n<h3 id=\"1-2-controllers\"><a class=\"zola-anchor\" href=\"#1-2-controllers\" aria-label=\"Anchor link for: 1-2-controllers\">1.2 Controllers<\/a><\/h3>\n<p>Controller \u662f\u7528\u4e8e\u6784\u5efa Kubernetes \u7684\u6838\u5fc3\u62bd\u8c61\u6982\u5ff5\u4e4b\u4e00\u3002\u5728\u4f7f\u7528 API \u670d\u52a1\u5668\u58f0\u660e\u96c6\u7fa4\u7684\u671f\u671b\u72b6\u6001\u540e\uff0cController \u5c06\u901a\u8fc7\u6301\u7eed\u76d1\u89c6 API \u670d\u52a1\u5668\u7684\u72b6\u6001\u5e76\u5bf9\u6240\u4ee5\u53d8\u5316\u505a\u51fa\u53cd\u5e94\u6765\u786e\u4fdd\u96c6\u7fa4\u7684\u5f53\u524d\u72b6\u6001\u4e0e\u671f\u671b\u72b6\u6001\u76f8\u5339\u914d\u3002Controller \u4f7f\u7528\u4e00\u4e2a\u7b80\u5355\u7684\u5faa\u73af\u8fdb\u884c\u64cd\u4f5c\uff0c\u8be5\u5faa\u73af\u4e0d\u65ad\u5730\u6839\u636e\u7fa4\u96c6\u5f53\u524d\u72b6\u6001\u5bf9\u6bd4\u7fa4\u96c6\u7684\u671f\u671b\u72b6\u6001\u3002\u5982\u679c\u5b58\u5728\u4efb\u4f55\u5dee\u5f02\uff0c\u5219\u63a7\u5236\u5668\u6267\u884c\u4efb\u52a1\u4ee5\u786e\u4fdd\u5f53\u524d\u72b6\u6001\u4e0e\u671f\u671b\u72b6\u6001\u7b26\u5408\u3002\u7528\u4f2a\u4ee3\u7801\u6765\u8868\u793a\uff1a<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>while true:<\/span><\/span>\n<span class=\"giallo-l\"><span>  X = currentState()<\/span><\/span>\n<span class=\"giallo-l\"><span>  Y = desiredState()<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>  if X == Y:<\/span><\/span>\n<span class=\"giallo-l\"><span>    return  # Do nothing<\/span><\/span>\n<span class=\"giallo-l\"><span>  else:<\/span><\/span>\n<span class=\"giallo-l\"><span>    do(tasks to get to Y)<\/span><\/span><\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u5f53\u60a8\u4f7f\u7528 API \u670d\u52a1\u5668\u521b\u5efa\u65b0\u7684 Pod \u65f6\uff0c<code>kube-scheduler<\/code> (\u4e00\u4e2a Controller) \u4f1a\u6ce8\u610f\u5230\u66f4\u6539\uff0c\u5e76\u51b3\u5b9a Pod \u90e8\u7f72\u5728\u7fa4\u96c6\u4e2d\u7684\u4f4d\u7f6e\u3002\u7136\u540e\uff0c\u5b83\u4f7f\u7528 API \u670d\u52a1\u5668 (\u7531 etcd \u652f\u6301) \u5199\u5165\u72b6\u6001\u53d8\u66f4\u3002\u7136\u540e\uff0c<code>kubelet<\/code> (\u53e6\u4e00\u4e2a Controller) \u4f1a\u6ce8\u610f\u5230\u65b0\u7684\u66f4\u6539\uff0c\u5e76\u5efa\u7acb\u6240\u9700\u7684\u7f51\u7edc\u529f\u80fd\u4ee5\u4f7f Pod \u5728\u7fa4\u96c6\u4e2d\u53ef\u8fbe\u3002\u5728\u8fd9\u91cc\uff0c\u4e24\u4e2a\u4e0d\u540c\u7684\u63a7\u5236\u5668\u5bf9\u4e24\u4e2a\u4e0d\u540c\u7684\u72b6\u6001\u66f4\u6539\u505a\u51fa\u53cd\u5e94\uff0c\u4ee5\u4f7f\u96c6\u7fa4\u7684\u5b9e\u9645\u72b6\u51b5\u4e0e\u7528\u6237\u7684\u610f\u56fe\u76f8\u5339\u914d\u3002<\/p>\n<h3 id=\"1-3-pods\"><a class=\"zola-anchor\" href=\"#1-3-pods\" aria-label=\"Anchor link for: 1-3-pods\">1.3 Pods<\/a><\/h3>\n<p>Pod \u76f8\u5f53\u4e8e Kubernetes \u4e2d\u7684\u539f\u5b50 - \u7528\u4e8e\u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\u7684\u6700\u5c0f\u53ef\u90e8\u7f72\u5bf9\u8c61\u3002\u5355\u4e2a Pod \u4ee3\u8868\u96c6\u7fa4\u4e2d\u6b63\u5728\u8fd0\u884c\u7684\u5de5\u4f5c\u8d1f\u8f7d\uff0c\u5e76\u5c01\u88c5\u4e00\u4e2a\u6216\u591a\u4e2a Docker \u5bb9\u5668\uff0c\u4efb\u4f55\u5fc5\u9700\u7684\u5b58\u50a8\u4ee5\u53ca\u4e00\u4e2a\u552f\u4e00\u7684 IP \u5730\u5740\u3002\u7ec4\u6210 Pod \u7684\u5bb9\u5668\u5728\u8bbe\u8ba1\u4e0a\u662f\u534f\u540c\u7684\uff0c\u5e76\u5728\u540c\u4e00\u673a\u5668\u4e0a\u8fdb\u884c\u8c03\u5ea6\u3002<\/p>\n<h3 id=\"1-4-nodes\"><a class=\"zola-anchor\" href=\"#1-4-nodes\" aria-label=\"Anchor link for: 1-4-nodes\">1.4 Nodes<\/a><\/h3>\n<p>Node \u662f\u8fd0\u884c Kubernetes \u96c6\u7fa4\u7684\u673a\u5668\u3002\u5b83\u4eec\u53ef\u4ee5\u662f\u88f8\u673a\uff0c\u865a\u62df\u673a\u6216\u5176\u4ed6\u4e1c\u897f\u3002\u4e3b\u673a (Host) \u4e00\u8bcd\u901a\u5e38\u4e0e Node \u4ea4\u66ff\u4f7f\u7528\u3002\u6211\u4f1a\u5c3d\u91cf\u4f7f\u7528\u4e00\u81f4\u7684\u672f\u8bed Node\uff0c\u4f46\u6709\u65f6\u4f1a\u6839\u636e\u4e0a\u4e0b\u6587\u4f7f\u7528\u865a\u62df\u673a (Virtual Machine) \u4e00\u8bcd\u6765\u6307\u4ee3\u8282\u70b9\u3002<\/p>\n<h2 id=\"2-kubernetes-wang-luo-mo-xing\"><a class=\"zola-anchor\" href=\"#2-kubernetes-wang-luo-mo-xing\" aria-label=\"Anchor link for: 2-kubernetes-wang-luo-mo-xing\">2 Kubernetes \u7f51\u7edc\u6a21\u578b<\/a><\/h2>\n<p>Kubernetes \u5bf9 Pods \u7684\u8054\u7f51\u65b9\u5f0f\u505a\u51fa\u4e86\u56fa\u6267\u7684\u9009\u62e9\u3002\u7279\u522b\u7684\uff0cKubernetes \u5bf9\u6240\u6709\u7684\u7f51\u7edc\u5b9e\u73b0\u90fd\u4f5c\u51fa\u4e86\u4ee5\u4e0b\u8981\u6c42\uff1a<\/p>\n<ul>\n<li>\u6240\u6709 Pod \u90fd\u53ef\u4ee5\u4e0e\u6240\u6709\u5176\u4ed6 Pod \u901a\u4fe1\u800c\u65e0\u9700\u4f7f\u7528\u7f51\u7edc\u5730\u5740\u8f6c\u6362 (NAT)<\/li>\n<li>\u6240\u6709 Node \u90fd\u53ef\u4ee5\u5728\u6ca1\u6709 NAT \u7684\u60c5\u51b5\u4e0b\u4e0e\u6240\u6709 Pod \u901a\u4fe1<\/li>\n<li>Pod \u6240\u89c1\u7684\u5b83\u7684 IP \u5c31\u662f\u5176\u4ed6 Pod \u770b\u5230\u7684\u5b83\u7684 IP<\/li>\n<\/ul>\n<p>\u7531\u4e8e\u8fd9\u4e9b\u7ea6\u675f\uff0c\u6211\u4eec\u73b0\u5728\u6709\u56db\u4e2a\u4e0d\u540c\u7684\u8054\u7f51\u95ee\u9898\u9700\u8981\u89e3\u51b3\uff1a<\/p>\n<ol>\n<li>Container \u5230 Container \u7f51\u7edc<\/li>\n<li>Pod \u5230 Pod \u7f51\u7edc<\/li>\n<li>Pod \u5230 Service \u7f51\u7edc<\/li>\n<li>Internet \u5230 Service \u7f51\u7edc<\/li>\n<\/ol>\n<p>\u6307\u5357\u5269\u4e0b\u7684\u90e8\u5206\u5c06\u4f1a\u4f9d\u6b21\u8ba8\u8bba\u8fd9\u4e9b\u95ee\u9898\u53ca\u5176\u89e3\u51b3\u65b9\u6cd5\u3002<\/p>\n<h2 id=\"3-container-dao-container-wang-luo\"><a class=\"zola-anchor\" href=\"#3-container-dao-container-wang-luo\" aria-label=\"Anchor link for: 3-container-dao-container-wang-luo\">3 Container \u5230 Container \u7f51\u7edc<\/a><\/h2>\n<p>\u901a\u5e38\uff0c\u6211\u4eec\u5c06\u865a\u62df\u673a\u4e2d\u7684\u7f51\u7edc\u901a\u4fe1\u89c6\u4e3a\u76f4\u63a5\u4e0e\u4ee5\u592a\u7f51\u8bbe\u5907\u8fdb\u884c\u4ea4\u4e92\uff0c\u5982\u56fe 1 \u6240\u793a\u3002<\/p>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/a-guide-to-the-kubernetes-networking-model\/images\/eth0.png\" alt=\"Figure 1\" \/><\/p>\n<p>\u56fe1. \u4ee5\u592a\u7f51\u8bbe\u5907\u7684\u7406\u60f3\u72b6\u51b5<\/p>\n<p>\u5728\u73b0\u5b9e\u4e2d\uff0c\u60c5\u51b5\u66f4\u52a0\u5fae\u5999\u3002\u5728 Linux\uff0c\u6bcf\u4e2a\u8fd0\u884c\u4e2d\u7684\u8fdb\u7a0b\u901a\u8fc7 <a rel=\"external\" href=\"http:\/\/man7.org\/linux\/man-pages\/man8\/ip-netns.8.html\">\u7f51\u7edc\u547d\u540d\u7a7a\u95f4<\/a> \u8fdb\u884c\u901a\u4fe1\uff0c\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\u62e5\u6709\u5b83\u81ea\u5df1\u7684\u8def\u7531\u89c4\u5219\u3001\u9632\u706b\u5899\u89c4\u5219\u548c\u7f51\u7edc\u8bbe\u5907\u3002\u672c\u8d28\u4e0a\uff0c\u4e00\u4e2a\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\u4e3a\u547d\u540d\u7a7a\u95f4\u5185\u7684\u6240\u6709\u8fdb\u7a0b\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5168\u65b0\u7684\u7f51\u7edc\u6808\u3002<\/p>\n<p>Linux \u7528\u6237\u53ef\u4ee5\u7528 <code>ip<\/code> \u547d\u4ee4\u521b\u9020\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\u3002\u4f8b\u5982\uff0c\u4e0b\u9762\u7684\u547d\u4ee4\u521b\u5efa\u4e86\u4e00\u4e2a\u65b0\u7684\u7f51\u7edc\u547d\u540d\u7a7a\u95f4 <code>ns1<\/code>\u3002<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>$ ip netns add ns1<\/span><\/span><\/code><\/pre>\n<p>\u5f53\u547d\u540d\u7a7a\u95f4\u88ab\u521b\u5efa\u65f6\uff0c\u5b83\u7684\u6302\u8f7d\u70b9 <code>\/var\/run\/netns<\/code> \u968f\u4e4b\u521b\u5efa\u3002\u8fd9\u6837\u5373\u4f7f\u6ca1\u6709\u8fdb\u7a0b\u5f52\u5c5e\u4e8e\u5b83\u4e5f\u53ef\u4ee5\u6301\u4e45\u5316\u3002<\/p>\n<p>\u4f60\u53ef\u4ee5\u901a\u8fc7\u5217\u51fa <code>\/var\/run\/netns<\/code> \u6302\u8f7d\u70b9\u6765\u5217\u51fa\u53ef\u7528\u7684\u547d\u540d\u7a7a\u95f4\uff0c\u6216\u8005\u7528 <code>ip<\/code> \u547d\u4ee4\u3002<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>$ ls \/var\/run\/netns<\/span><\/span>\n<span class=\"giallo-l\"><span>ns1<\/span><\/span>\n<span class=\"giallo-l\"><span>$ ip netns<\/span><\/span>\n<span class=\"giallo-l\"><span>ns1<\/span><\/span><\/code><\/pre>\n<p>\u9ed8\u8ba4\u7684\uff0cLinux \u5c06\u6240\u6709\u8fdb\u7a0b\u5206\u914d\u7ed9 root \u7f51\u7edc\u547d\u540d\u7a7a\u95f4\u6765\u63d0\u4f9b\u5916\u90e8\u8bbf\u95ee\uff0c\u5982\u56fe 2\u3002<\/p>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/a-guide-to-the-kubernetes-networking-model\/images\/root-namespace.png\" alt=\"Figure 2\" \/><\/p>\n<p>\u56fe2. Root \u7f51\u7edc\u547d\u540d\u7a7a\u95f4<\/p>\n<p>\u5bf9\u4e8e Docker \u7684\u7ed3\u6784\u6765\u8bf4\uff0c\u4e00\u4e2a Pod \u662f\u4e00\u7ec4\u5171\u4eab\u540c\u4e00\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\u7684 Docker \u5bb9\u5668\u3002\u540c\u4e00 Pod \u4e2d\u7684\u5bb9\u5668\u62e5\u6709\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\u5206\u914d\u7ed9 Pod \u7684\u76f8\u540c\u7684 IP \u5730\u5740\u548c\u7aef\u53e3\u8303\u56f4\uff0c\u5e76\u4e14\u53ef\u4ee5\u901a\u8fc7 localhost \u627e\u5230\u5404\u81ea\uff0c\u56e0\u4e3a\u4ed6\u4eec\u5728\u540c\u4e00\u547d\u540d\u7a7a\u95f4\u5185\u3002\u6211\u4eec\u4e3a\u865a\u62df\u673a\u4e2d\u7684\u6bcf\u4e00\u4e2a Pod \u521b\u5efa\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\u3002\u5728 Docker \u7684\u5b9e\u73b0\u4e2d\uff0c\u4e00\u4e2a \"Pod \u5bb9\u5668\" \u6253\u5f00\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\uff0c\u7136\u540e\u7528\u6237\u6307\u5b9a\u7684 \"app containers\" \u901a\u8fc7 Docker \u7684 \u2013net=container: \u529f\u80fd\u52a0\u5165\u8fd9\u4e2a\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\u3002\u56fe 3 \u5c55\u793a\u4e86\u591a\u4e2a\u5bb9\u5668 (<code>ctr*<\/code>) \u7ec4\u6210\u7684 Pod \u5728\u5171\u4eab\u7684\u547d\u540d\u7a7a\u95f4\u7684\u60c5\u666f\u3002<\/p>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/a-guide-to-the-kubernetes-networking-model\/images\/pod-namespace.png\" alt=\"Figure 3\" \/><\/p>\n<p>\u56fe3. \u6bcf\u4e2a Pod \u4e00\u4e2a\u7f51\u7edc\u547d\u540d\u7a7a\u95f4<\/p>\n<p>\u540c\u4e00\u4e2a Pod \u4e2d\u7684\u5e94\u7528\u7a0b\u5e8f\u540c\u6837\u62e5\u6709\u5171\u4eab\u5377\u7684\u8bbf\u95ee\u6743\uff0c\u6839\u636e Pod \u7684\u5b9a\u4e49, \u5171\u4eab\u5377\u53ef\u6302\u8f7d\u5230\u6bcf\u4e2a\u5e94\u7528\u7a0b\u5e8f\u7684\u6587\u4ef6\u7cfb\u7edf\u3002<\/p>\n<h2 id=\"4-pod-dao-pod-wang-luo\"><a class=\"zola-anchor\" href=\"#4-pod-dao-pod-wang-luo\" aria-label=\"Anchor link for: 4-pod-dao-pod-wang-luo\">4 Pod \u5230 Pod \u7f51\u7edc<\/a><\/h2>\n<p>\u5728 Kubernetes \u4e2d\uff0c\u6bcf\u4e2a Pod \u90fd\u62e5\u6709\u771f\u6b63\u7684 IP \u5730\u5740\u800c\u4e14\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e2a IP \u5730\u5740\u4e0e\u522b\u7684 Pod \u901a\u4fe1\u3002\u5f53\u524d\u9700\u8981\u7406\u89e3 Kubernetes \u662f\u5982\u4f55\u4f7f Pod \u5230 Pod \u901a\u4fe1\u901a\u8fc7\u771f\u6b63\u7684 IP\uff0c\u65e0\u8bba Pod \u662f\u5728\u540c\u4e00\u53f0\u7269\u7406 Node \u4e0a\u8fd8\u662f\u96c6\u7fa4\u4e2d\u7684\u4e0d\u540c Node \u4e0a\u3002\u6211\u4eec\u4ece\u5047\u8bbe Pod \u5728\u76f8\u540c\u7684\u673a\u5668\u4e0a\u5f00\u59cb\u8ba8\u8bba\uff0c\u907f\u514d Node \u4e4b\u95f4\u901a\u4fe1\u5728\u5185\u90e8\u7f51\u7edc\u4e4b\u5916\u7684\u590d\u6742\u60c5\u51b5\u3002<\/p>\n<p>\u5bf9\u4e8e Pod \u6765\u8bf4\uff0c\u5b83\u5728\u5176\u547d\u540d\u7a7a\u95f4\u4e2d\u5c1d\u8bd5\u53bb\u548c\u5728\u540c\u4e00 Node \u4e0a\u4e0d\u540c\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\u901a\u4fe1\u3002\u5e78\u8fd0\u7684\uff0c\u547d\u540d\u7a7a\u95f4\u53ef\u4ee5\u901a\u8fc7 Linux <a rel=\"external\" href=\"http:\/\/man7.org\/linux\/man-pages\/man4\/veth.4.html\">Virtual Ethernet Device<\/a>\uff0c\u6216\u901a\u8fc7\u7531\u4e24\u4e2a\u865a\u62df\u63a5\u53e3\u7ec4\u6210\u7684\u53ef\u4ee5\u6269\u5c55\u5230\u591a\u4e2a\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\u7684 <code>veth pair<\/code> \u8fde\u63a5\u3002\u4e3a\u4e86\u8fde\u63a5 Pod \u7684\u547d\u540d\u7a7a\u95f4\uff0c\u6211\u4eec\u53ef\u4ee5\u628a veth pair \u7684\u4e00\u7aef\u8fde\u63a5\u5230 root \u7f51\u7edc\u547d\u540d\u7a7a\u95f4\uff0c\u53e6\u4e00\u7aef\u8fde\u63a5\u5230 Pod \u7684\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\u3002Veth pair \u50cf\u8df3\u7ebf\u4e00\u6837\u5de5\u4f5c\uff0c\u8fde\u63a5\u4e24\u7aef\u4f7f\u6d41\u91cf\u53ef\u4ee5\u6d41\u901a\u3002\u8fd9\u4e00\u6b65\u53ef\u4ee5\u91cd\u590d\u76f4\u5230\u5176\u6570\u76ee\u548c\u673a\u5668\u4e0a\u7684 Pods \u4e00\u6837\u591a\u3002\u56fe 4 \u5c55\u793a\u4e86 veth pair \u8fde\u63a5\u4e86\u6240\u6709 Pod \u5230 VM \u7684 root \u547d\u540d\u7a7a\u95f4\u7684\u60c5\u51b5\u3002<\/p>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/a-guide-to-the-kubernetes-networking-model\/images\/pod-veth-pairs.png\" alt=\"Figure 4\" \/><\/p>\n<p>\u56fe4. \u6bcf\u4e2a Pod \u5747\u6709 veth pair<\/p>\n<p>\u73b0\u5728\uff0c\u6211\u4eec\u5efa\u7acb\u4e86\u6709\u72ec\u7acb\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\u7684 Pod\uff0c\u8ba9\u4ed6\u4eec\u76f8\u4fe1\u4ed6\u4eec\u62e5\u6709\u4ed6\u4eec\u81ea\u5df1\u7684\u4ee5\u592a\u7f51\u8bbe\u5907\u548c IP \u5730\u5740\uff0c\u7136\u540e\u4ed6\u4eec\u8fde\u63a5\u5230\u4e86 Node \u7684 root \u547d\u540d\u7a7a\u95f4\u4e0a\u3002\u73b0\u5728\uff0c\u6211\u4eec\u60f3\u8ba9 Pod \u901a\u8fc7 root \u547d\u540d\u7a7a\u95f4\u548c\u5f7c\u6b64\u901a\u4fe1\uff0c\u4e3a\u6b64\u6211\u4eec\u4f7f\u7528\u7f51\u6865\u3002<\/p>\n<p>Linux \u4ee5\u592a\u7f51\u7f51\u6865\u662f\u4e00\u4e2a\u7528\u6765\u8fde\u63a5\u4e24\u4e2a\u6216\u4ee5\u4e0a\u7f51\u6bb5\u7684\u865a\u62df\u7684 2 \u5c42\u7f51\u7edc\u8bbe\u5907\uff0c\u900f\u660e\u5730\u5de5\u4f5c\u5728\u4e24\u4e2a\u7f51\u7edc\u4e0a\u4f7f\u5176\u76f8\u8fde\u3002\u7f51\u6865\u7ef4\u62a4\u4e00\u4e2a\u6765\u6e90\u548c\u76ee\u6807\u7684\u8f6c\u53d1\u8868\uff0c\u901a\u8fc7\u68c0\u6d4b\u7ecf\u8fc7\u5b83\u7684\u6570\u636e\u5305\u7684\u76ee\u7684\u5730\u6765\u51b3\u5b9a\u5b83\u662f\u5426\u5c06\u6570\u636e\u5305\u4f20\u9012\u7ed9\u522b\u7684\u8fde\u63a5\u5230\u6865\u4e0a\u7684\u7f51\u6bb5\u3002\u7f51\u6865\u7801\u901a\u8fc7\u67e5\u627e\u7f51\u7edc\u4e2d\u4ee5\u592a\u7f51\u8bbe\u5907\u552f\u4e00\u7684 MAC \u5730\u5740\u6765\u51b3\u5b9a\u4e86\u662f\u5426\u6865\u63a5\u6570\u636e\u6216\u5c06\u5176\u4e22\u5f03\u3002<\/p>\n<p>\u7f51\u6865\u5b9e\u73b0\u4e86 ARP \u534f\u8bae\u6765\u53d1\u73b0\u94fe\u8def\u5c42 MAC \u5730\u5740\u5173\u8054\u7684 IP \u5730\u5740\u7684\u3002\u5f53\u6570\u636e\u5e27\u88ab\u7f51\u6865\u63a5\u6536\u65f6\uff0c\u7f51\u6865\u5411\u6240\u6709\u8fde\u63a5\u7684\u8bbe\u5907 (\u9664\u4e86\u539f\u53d1\u9001\u8005) \u5e7f\u64ad\u5e27\uff0c\u54cd\u5e94\u7684\u8bbe\u5907\u88ab\u5b58\u5165\u67e5\u8be2\u8868\u3002\u4e4b\u540e\u5e26\u6709\u76f8\u540c IP \u5730\u5740\u7684\u6d41\u91cf\u5c06\u4f1a\u4f7f\u7528\u67e5\u8be2\u8868\u6765\u67e5\u627e\u8f6c\u53d1\u7684\u6b63\u786e MAC \u5730\u5740\u3002<\/p>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/a-guide-to-the-kubernetes-networking-model\/images\/pods-connected-by-bridge.png\" alt=\"Figure 5\" \/><\/p>\n<p>\u56fe5. \u901a\u8fc7\u7f51\u6865\u8fde\u63a5\u547d\u540d\u7a7a\u95f4<\/p>\n<h3 id=\"4-1-bao-de-sheng-ming-zhou-qi-tong-yi-node-shang-pod-dao-pod\"><a class=\"zola-anchor\" href=\"#4-1-bao-de-sheng-ming-zhou-qi-tong-yi-node-shang-pod-dao-pod\" aria-label=\"Anchor link for: 4-1-bao-de-sheng-ming-zhou-qi-tong-yi-node-shang-pod-dao-pod\">4.1 \u5305\u7684\u751f\u547d\u5468\u671f\uff1a\u540c\u4e00 Node \u4e0a Pod \u5230 Pod<\/a><\/h3>\n<p>\u5df2\u6709\u5c06 Pod \u9694\u79bb\u5230\u5176\u7f51\u7edc\u5806\u6808\u7684\u7f51\u7edc\u540d\u79f0\u7a7a\u95f4\uff0c\u5c06\u6bcf\u4e2a\u547d\u540d\u7a7a\u95f4\u8fde\u63a5\u5230 root \u547d\u540d\u7a7a\u95f4\u7684\u865a\u62df\u4ee5\u592a\u7f51\u8bbe\u5907\uff0c\u548c\u5c06\u547d\u540d\u7a7a\u95f4\u8fde\u63a5\u5728\u4e00\u8d77\u7684\u7f51\u6865\uff0c\u6211\u4eec\u7ec8\u4e8e\u51c6\u5907\u597d\u5728\u540c\u4e00 Node \u4e0a\u7684 Pod \u4e4b\u95f4\u53d1\u9001\u6d41\u91cf\u4e86\u3002\u56fe 6 \u6f14\u793a\u4e86\u8fd9\u4e2a\u8fc7\u7a0b\u3002<\/p>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/a-guide-to-the-kubernetes-networking-model\/images\/pod-to-pod-same-node.gif\" alt=\"Figure 6\" \/><\/p>\n<p>\u56fe6. \u5305\u5728\u540c\u4e00\u4e2a Node \u4e0a Pod \u4e4b\u95f4\u4f20\u9012<\/p>\n<p>\u5728\u56fe 6 \u4e2d\uff0c\u5bb9\u5668 1 \u5c06\u6570\u636e\u5305\u53d1\u9001\u5230\u5176\u81ea\u5df1\u7684\u4ee5\u592a\u7f51\u8bbe\u5907 <code>eth0<\/code>\uff0c\u8be5\u8bbe\u5907\u4f5c\u4e3a\u5bb9\u5668\u7684\u9ed8\u8ba4\u8bbe\u5907\u3002\u5bf9\u4e8e Pod1\uff0c<code>eth0<\/code> \u901a\u8fc7\u865a\u62df\u4ee5\u592a\u7f51\u8bbe\u5907\u8fde\u63a5\u5230 root \u547d\u540d\u7a7a\u95f4 <code>veth0<\/code> (1)\u3002\u914d\u7f6e\u7f51\u6865 <code>cbr0<\/code> \u8fde\u63a5\u5230\u7f51\u6bb5 <code>veth0<\/code>\u3002\u6570\u636e\u5305\u5230\u8fbe\u7f51\u6865\u540e\uff0c\u7f51\u6865\u4f7f\u7528 ARP \u534f\u8bae\u5c06\u5176\u89e3\u6790\u5230\u5176\u6b63\u786e\u7684\u76ee\u6807\u7f51\u6bb5 <code>veth1<\/code> (3)\u3002\u5f53\u6570\u636e\u5305\u5230\u8fbe\u865a\u62df\u8bbe\u5907 <code>veth1<\/code> \u65f6\uff0c\u5b83\u5c06\u76f4\u63a5\u88ab\u8f6c\u53d1\u5230 Pod2 \u7684\u547d\u540d\u7a7a\u95f4\u548c\u8be5\u547d\u540d\u7a7a\u95f4\u4e2d\u7684 <code>eth0<\/code> \u8bbe\u5907 (4)\u3002\u5728\u6574\u4e2a\u6d41\u91cf\u6d41\u4e2d\uff0c\u6bcf\u4e2a Pod \u4ec5\u4e0e <code>localhost<\/code> \u4e0a\u7684 <code>eth0<\/code> \u901a\u4fe1\uff0c\u5e76\u4e14\u6d41\u91cf\u88ab\u8def\u7531\u5230\u6b63\u786e\u7684 Pod\u3002\u5bf9\u4e8e\u8fd9\u4e2a\u7f51\u7edc\u7684\u4f7f\u7528\uff0c\u6211\u4eec\u7684\u7ecf\u9a8c\u662f\u5b83\u7b26\u5408\u5f00\u53d1\u4eba\u5458\u671f\u671b\u7684\u9ed8\u8ba4\u884c\u4e3a\u3002<\/p>\n<p>Kubernetes \u7684\u7f51\u7edc\u6a21\u578b\u8981\u6c42 Pod \u5fc5\u987b\u901a\u8fc7\u5176\u5728\u8de8 Node \u4e2d\u7684 IP \u5730\u5740\u624d\u80fd\u8bbf\u95ee\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u4e00\u4e2a Pod \u7684 IP \u5730\u5740\u59cb\u7ec8\u5bf9\u7f51\u7edc\u4e2d\u7684\u5176\u4ed6 Pod \u53ef\u89c1\uff0c\u5e76\u4e14\u6bcf\u4e2a Pod \u6240\u89c1\u7684\u81ea\u5df1\u7684 IP \u5730\u5740\u90fd\u4e0e\u5176\u4ed6 Pod \u6240\u89c1\u4e00\u81f4\u3002\u73b0\u5728\uff0c\u6211\u4eec\u8f6c\u5411\u5728\u4e0d\u540c Node \u4e0a\u7684 Pod \u4e4b\u95f4\u8def\u7531\u6d41\u91cf\u7684\u95ee\u9898\u3002<\/p>\n<h3 id=\"4-2-bao-de-sheng-ming-zhou-qi-bu-tong-node-shang-pod-dao-pod\"><a class=\"zola-anchor\" href=\"#4-2-bao-de-sheng-ming-zhou-qi-bu-tong-node-shang-pod-dao-pod\" aria-label=\"Anchor link for: 4-2-bao-de-sheng-ming-zhou-qi-bu-tong-node-shang-pod-dao-pod\">4.2 \u5305\u7684\u751f\u547d\u5468\u671f\uff1a\u4e0d\u540c Node \u4e0a Pod \u5230 Pod<\/a><\/h3>\n<p>\u5728\u786e\u5b9a\u4e86\u5982\u4f55\u5728\u540c\u4e00 Node \u4e0a\u7684 Pod \u4e4b\u95f4\u8def\u7531\u6570\u636e\u5305\u4e4b\u540e\uff0c\u6211\u4eec\u8f6c\u5411\u5728\u4e0d\u540c Node \u4e0a\u7684 Pod \u4e4b\u95f4\u8def\u7531\u6d41\u91cf\u3002Kubernetes \u7f51\u7edc\u6a21\u578b\u8981\u6c42 Pod IP \u5728\u6574\u4e2a\u7f51\u7edc\u4e0a\u53ef\u8fbe\uff0c\u4f46\u662f\u5b83\u6ca1\u6709\u6307\u5b9a\u5fc5\u987b\u5982\u4f55\u5b8c\u6210\u3002\u5b9e\u9645\u4e0a\uff0c\u8fd9\u662f\u57fa\u4e8e\u7279\u5b9a\u4e8e\u7f51\u7edc\u7684\uff0c\u4f46\u662f\u5df2\u6709\u4e00\u4e9b\u6a21\u5f0f\u88ab\u5efa\u7acb\u8d77\u6765\u4ee5\u7b80\u5316\u6b64\u8fc7\u7a0b\u3002<\/p>\n<p>\u901a\u5e38\uff0c\u7fa4\u96c6\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u90fd\u5206\u914d\u6709\u4e00\u4e2a CIDR \u5757\uff0c\u8be5\u5757\u6307\u5b9a\u4e86\u8be5 Node \u4e0a\u8fd0\u884c\u7684 Pod \u53ef\u7528\u7684 IP \u5730\u5740\u3002\u4e00\u65e6\u53d1\u5f80 CIDR \u5757\u7684\u6d41\u91cf\u5230\u8fbe Node\uff0c\u5219 Node \u6709\u8d23\u4efb\u5c06\u6d41\u91cf\u8f6c\u53d1\u5230\u6b63\u786e\u7684 Pod\u3002\u56fe 7 \u8bf4\u660e\u4e86\u4e24\u4e2a Node \u4e4b\u95f4\u7684\u6d41\u91cf\u6d41\uff0c\u5047\u8bbe\u7f51\u7edc\u53ef\u4ee5\u5c06 CIDR \u5757\u4e2d\u7684\u6d41\u91cf\u8def\u7531\u5230\u6b63\u786e\u7684 Node\u3002<\/p>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/a-guide-to-the-kubernetes-networking-model\/images\/pod-to-pod-different-nodes.gif\" alt=\"Figure 7\" \/><\/p>\n<p>\u56fe7. \u5305\u5728\u4e0d\u540c Node \u4e0a\u7684 Pod \u4e4b\u95f4\u4f20\u9012<\/p>\n<p>\u56fe 7 \u4ece\u4e0e\u56fe 6 \u76f8\u540c\u7684\u8bf7\u6c42\u5f00\u59cb\uff0c\u9664\u4e86\u76ee\u6807 Pod (\u4ee5\u7eff\u8272\u7a81\u51fa\u663e\u793a) \u4e0e\u6e90 Pod (\u4ee5\u84dd\u8272\u7a81\u51fa\u663e\u793a) \u4f4d\u4e8e\u4e0d\u540c\u7684 Node \u4e0a\u3002\u6570\u636e\u5305\u9996\u5148\u901a\u8fc7 Pod1 \u7684\u4ee5\u592a\u7f51\u8bbe\u5907\u53d1\u9001\uff0c\u8be5\u8bbe\u5907\u4e0e root \u547d\u540d\u7a7a\u95f4\u4e2d\u7684\u865a\u62df\u4ee5\u592a\u7f51\u8bbe\u5907\u914d\u5bf9 (1)\u3002\u6570\u636e\u5305\u6700\u7ec8\u5230\u8fbe root \u540d\u79f0\u7a7a\u95f4\u7684\u7f51\u6865 (2)\u3002ARP \u5c06\u5728\u7f51\u6865\u4e0a\u5931\u8d25\uff0c\u56e0\u4e3a\u6ca1\u6709\u4efb\u4f55\u5339\u914d\u6570\u636e\u5305 MAC \u5730\u5740\u7684\u8bbe\u5907\u8fde\u63a5\u5230\u7f51\u6865\u3002\u7f51\u6865\u5728\u5931\u8d25\u65f6\u4f1a\u5c06\u6570\u636e\u5305\u9001\u51fa\u9ed8\u8ba4\u8def\u7531 - root \u547d\u540d\u7a7a\u95f4 <code>eth0<\/code> \u8bbe\u5907\u3002\u6b64\u65f6\uff0c\u8def\u7531\u79bb\u5f00\u8282\u70b9\u5e76\u8fdb\u5165\u7f51\u7edc (3)\u3002\u73b0\u5728\u6211\u4eec\u5047\u8bbe\u7f51\u7edc\u53ef\u4ee5\u6839\u636e\u5206\u914d\u7ed9 Node \u7684 CIDR \u5757\u5c06\u6570\u636e\u5305\u8def\u7531\u5230\u6b63\u786e\u7684 Node (4)\u3002\u6570\u636e\u5305\u8fdb\u5165\u76ee\u6807 Node \u7684 root \u547d\u540d\u7a7a\u95f4 (VM 2 \u4e0a\u7684 <code>eth0<\/code>)\uff0c\u7136\u540e\u901a\u8fc7\u7f51\u6865\u8def\u7531\u5230\u6b63\u786e\u7684\u865a\u62df\u4ee5\u592a\u7f51\u8bbe\u5907 (5)\u3002\u6700\u540e\uff0c\u901a\u8fc7\u6d41\u7ecf Pod4 \u547d\u540d\u7a7a\u95f4\u4e2d\u7684\u865a\u62df\u4ee5\u592a\u7f51\u8bbe\u5907\u5bf9\u6765\u5b8c\u6210\u8def\u7531 (6)\u3002\u4e00\u822c\u800c\u8a00\uff0c\u6bcf\u4e2a Node \u90fd\u77e5\u9053\u5982\u4f55\u5c06\u6570\u636e\u5305\u4f20\u9012\u5230\u5176\u4e2d\u8fd0\u884c\u7684 Pod\u3002\u6570\u636e\u5305\u5230\u8fbe\u76ee\u6807 Node \u540e\uff0c\u6570\u636e\u5305\u7684\u6d41\u52a8\u65b9\u5f0f\u4e0e\u5728\u540c\u4e00 Node \u4e0a\u7684 Pod \u4e4b\u95f4\u8def\u7531\u6d41\u91cf\u7684\u65b9\u5f0f\u76f8\u540c\u3002<\/p>\n<p>\u6211\u4eec\u7701\u7565\u4e86\u4e00\u6b65\uff0c\u5373\u5982\u4f55\u914d\u7f6e\u7f51\u7edc\u4ee5\u5c06 Pod IP \u7684\u6d41\u91cf\u8def\u7531\u5230\u8d1f\u8d23\u8fd9\u4e9b IP \u7684\u6b63\u786e\u7684 Node\u3002\u8fd9\u662f\u7279\u5b9a\u4e8e\u7f51\u7edc\u7684\uff0c\u4e0d\u8fc7\u901a\u8fc7\u7814\u7a76\u76f8\u5173\u7279\u4f8b\u4e5f\u53ef\u4ee5\u63d0\u4f9b\u5176\u6240\u6d89\u53ca\u95ee\u9898\u7684\u4e00\u4e9b\u89c1\u89e3\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8e AWS\uff0cAmazon \u4e3a Kubernetes \u7ef4\u62a4\u4e86\u4e00\u4e2a\u5bb9\u5668\u7f51\u7edc\u63d2\u4ef6\uff0c\u8be5\u63d2\u4ef6\u901a\u8fc7 <a rel=\"external\" href=\"https:\/\/github.com\/aws\/amazon-vpc-cni-k8s\">\u5bb9\u5668\u7f51\u7edc\u63a5\u53e3 (CNI) \u63d2\u4ef6<\/a> \u4f7f\u5728 Amazon VPC \u73af\u5883\u4e2d\u7684 Node \u5230 Node \u7f51\u7edc\u6210\u4e3a\u53ef\u80fd\u3002<\/p>\n<p>\u5bb9\u5668\u7f51\u7edc\u63a5\u53e3 (CNI) \u63d0\u4f9b\u4e86\u7528\u4e8e\u5c06\u5bb9\u5668\u8fde\u63a5\u5230\u5916\u90e8\u7f51\u7edc\u7684\u901a\u7528 API\u3002\u4f5c\u4e3a\u5f00\u53d1\u4eba\u5458\uff0c\u6211\u4eec\u60f3\u77e5\u9053 Pod \u53ef\u4ee5\u4f7f\u7528 IP \u5730\u5740\u4e0e\u7f51\u7edc\u901a\u4fe1\uff0c\u5e76\u4e14\u6211\u4eec\u5e0c\u671b\u6b64\u64cd\u4f5c\u7684\u673a\u5236\u900f\u660e\u3002\u7531 AWS \u5f00\u53d1\u7684 CNI \u63d2\u4ef6\u8bd5\u56fe\u6ee1\u8db3\u8fd9\u4e9b\u9700\u6c42\uff0c\u540c\u65f6\u901a\u8fc7 AWS \u63d0\u4f9b\u7684\u73b0\u6709 VPC\uff0cIAM \u548c\u5b89\u5168\u7ec4\u529f\u80fd\u63d0\u4f9b\u5b89\u5168\u4e14\u53ef\u7ba1\u7406\u7684\u73af\u5883\u3002\u89e3\u51b3\u65b9\u6848\u662f\u4f7f\u7528\u5f39\u6027\u7f51\u7edc\u63a5\u53e3\u3002<\/p>\n<p>\u5728 EC2 \u4e2d\uff0c\u6bcf\u4e2a\u5b9e\u4f8b\u90fd\u7ed1\u5b9a\u5230\u4e00\u4e2a\u5f39\u6027\u7f51\u7edc\u63a5\u53e3 (ENI)\uff0c\u5e76\u4e14\u6240\u6709 ENI \u90fd\u8fde\u63a5\u5728 VPC \u5185 - ENI \u53ef\u4ee5\u76f8\u4e92\u8bbf\u95ee\uff0c\u800c\u65e0\u9700\u4ed8\u51fa\u989d\u5916\u7684\u4ee3\u4ef7\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6bcf\u4e2a EC2 \u5b9e\u4f8b\u90fd\u90e8\u7f72\u6709\u4e00\u4e2a ENI\uff0c\u4f46\u662f\u60a8\u53ef\u4ee5\u968f\u610f\u521b\u5efa\u591a\u4e2a ENI \u5e76\u5c06\u5b83\u4eec\u90e8\u7f72\u5230\u60a8\u8ba4\u4e3a\u5408\u9002\u7684 EC2 \u5b9e\u4f8b\u4e2d\u3002\u7528\u4e8e Kubernetes \u7684 AWS CNI \u63d2\u4ef6\u5229\u7528\u8fd9\u79cd\u7075\u6d3b\u6027\uff0c\u4e3a\u90e8\u7f72\u5230 Node \u7684\u6bcf\u4e00\u4e2a Pod \u521b\u5efa\u4e00\u4e2a\u65b0\u7684 ENI\u3002\u7531\u4e8e VPC \u4e2d\u7684 ENI \u5df2\u7ecf\u8fde\u63a5\u5230\u4e86\u73b0\u6709\u7684 AWS \u57fa\u7840\u8bbe\u65bd\uff0c\u56e0\u6b64\uff0c\u6bcf\u4e2a\u5728 VPC \u4e2d Pod \u7684 IP \u5730\u5740\u90fd\u662f\u672c\u5730\u53ef\u5bfb\u5740\u7684\u3002\u5c06 CNI \u63d2\u4ef6\u90e8\u7f72\u5230\u7fa4\u96c6\u540e\uff0c\u6bcf\u4e2a Node (EC2 \u5b9e\u4f8b) \u90fd\u4f1a\u521b\u5efa\u591a\u4e2a\u5f39\u6027\u7f51\u7edc\u63a5\u53e3\uff0c\u5e76\u4e3a\u8fd9\u4e9b\u5b9e\u4f8b\u5206\u914d IP \u5730\u5740\uff0c\u4ece\u800c\u4e3a\u6bcf\u4e2a Node \u5f62\u6210\u4e00\u4e2a CIDR \u5757\u3002\u90e8\u7f72 Pod \u65f6\uff0c\u4f5c\u4e3a DaemonSet \u90e8\u7f72\u5230 Kubernetes \u96c6\u7fa4\u7684\u5c0f\u578b\u4e8c\u8fdb\u5236\u6587\u4ef6\u4f1a\u6536\u5230\u6240\u6709\u7684\u6765\u81ea Node \u672c\u5730 kubelet \u8fdb\u7a0b\u7684\u5c06 Pod \u6dfb\u52a0\u5230\u7f51\u7edc\u7684\u8bf7\u6c42\u3002\u8be5\u4e8c\u8fdb\u5236\u6587\u4ef6\u4ece Node \u7684\u53ef\u7528 ENI \u6c60\u4e2d\u9009\u62e9\u4e00\u4e2a\u53ef\u7528 IP \u5730\u5740\uff0c\u5e76\u901a\u8fc7\u5728 Linux \u5185\u6838\u4e2d\u8fde\u63a5\u865a\u62df\u4ee5\u592a\u7f51\u8bbe\u5907\u548c\u7f51\u6865\uff0c\u5c06\u5176\u5206\u914d\u7ed9 Pod\uff0c\u5982\u5728\u540c\u4e00\u8282\u70b9\u5185\u5c06 Pod \u8054\u7f51\u65f6\u6240\u8ff0\u3002\u6709\u4e86\u8fd9\u4e2a\uff0cPod \u6d41\u91cf\u5c31\u53ef\u4ee5\u5728\u96c6\u7fa4\u4e2d\u8de8 Node \u8fdb\u884c\u8def\u7531\u3002<\/p>\n<h2 id=\"5-pod-dao-service-wang-luo\"><a class=\"zola-anchor\" href=\"#5-pod-dao-service-wang-luo\" aria-label=\"Anchor link for: 5-pod-dao-service-wang-luo\">5 Pod \u5230 Service \u7f51\u7edc<\/a><\/h2>\n<p>\u6211\u4eec\u5df2\u7ecf\u5c55\u793a\u4e86\u5982\u4f55\u5728 Pod \u53ca\u5176\u5173\u8054\u7684 IP \u5730\u5740\u4e4b\u95f4\u8def\u7531\u6d41\u91cf\u3002\u8fd9\u975e\u5e38\u6709\u6548\uff0c\u76f4\u5230\u6211\u4eec\u9700\u8981\u5e94\u5bf9\u53d8\u5316\u3002Pod IP \u5730\u5740\u4e0d\u662f\u6301\u4e45\u6027\u7684\uff0c\u5e76\u4e14\u4f1a\u51fa\u73b0\u548c\u6d88\u5931\uff0c\u4ee5\u5e94\u5bf9\u89c4\u6a21\u6269\u5927\u548c\u7f29\u5c0f\uff0c\u5e94\u7528\u7a0b\u5e8f\u7684\u5d29\u6e83\u6216\u8282\u70b9\u91cd\u65b0\u542f\u52a8\u3002\u6bcf\u4e00\u4e2a\u8fd9\u4e9b\u4e8b\u4ef6\u90fd\u53ef\u4ee5\u4f7f Pod IP \u5730\u5740\u66f4\u6539\u800c\u4e0d\u4f1a\u53d1\u51fa\u4efb\u4f55\u8b66\u544a\u3002\u5185\u7f6e\u5728 Kubernetes \u7684 Service \u7528\u4ee5\u89e3\u51b3\u6b64\u95ee\u9898\u3002<\/p>\n<p>Kubernetes \u7684 Service \u7ba1\u7406\u4e00\u7ec4 Pod \u7684\u72b6\u6001\uff0c\u4f7f\u60a8\u53ef\u4ee5\u8ddf\u8e2a\u968f\u65f6\u52a8\u6001\u53d8\u5316\u7684\u4e00\u7ec4 Pod IP \u5730\u5740\u3002Service \u5145\u5f53 Pod \u7684\u62bd\u8c61\uff0c\u5e76\u4e3a\u4e00\u7ec4 Pod IP \u5730\u5740\u5206\u914d\u4e00\u4e2a\u865a\u62df IP \u5730\u5740\u3002\u5bfb\u5740\u5230 Service \u7684\u865a\u62df IP \u7684\u4efb\u4f55\u6d41\u91cf\u90fd\u5c06\u88ab\u8def\u7531\u5230\u4e0e\u865a\u62df IP \u5173\u8054\u7684 Pod \u96c6\u3002\u8fd9\u5141\u8bb8\u4e0e Service \u5173\u8054\u7684 Pod \u96c6\u968f\u65f6\u66f4\u6539 - \u5ba2\u6237\u7aef\u53ea\u9700\u8981\u4e86\u89e3 Service \u7684\u4e0d\u53d8\u7684\u865a\u62df IP\u3002<\/p>\n<p>\u521b\u5efa\u65b0\u7684 Kubernetes Service \u65f6\uff0c\u5c06\u4e3a\u60a8\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df IP (\u4e5f\u79f0\u4e3a\u7fa4\u96c6 IP)\u3002\u5728\u7fa4\u96c6\u4e2d\u7684\u4efb\u4f55\u4f4d\u7f6e\uff0c\u5bfb\u5740\u5230\u865a\u62df IP \u7684\u6d41\u91cf\u5c06\u8d1f\u8f7d\u5747\u8861\u5230\u4e0e\u8be5 Service \u5173\u8054\u7684\u4e00\u7ec4\u540e\u7aef Pod\u3002\u5b9e\u9645\u4e0a\uff0cKubernetes \u4f1a\u81ea\u52a8\u521b\u5efa\u5e76\u7ef4\u62a4\u4e00\u4e2a\u96c6\u7fa4\u5185\u7684\u5206\u5e03\u5f0f\u8d1f\u8f7d\u5747\u8861\u5668\uff0c\u8be5\u8d1f\u8f7d\u5747\u8861\u5668\u4f1a\u5c06\u6d41\u91cf\u5206\u53d1\u5230\u4e0e Service \u76f8\u5173\u8054\u7684\u5065\u5eb7 Pod\u3002\u8ba9\u6211\u4eec\u4ed4\u7ec6\u770b\u770b\u5b83\u662f\u5982\u4f55\u5de5\u4f5c\u7684\u3002<\/p>\n<h3 id=\"5-1-netfilter-he-iptables\"><a class=\"zola-anchor\" href=\"#5-1-netfilter-he-iptables\" aria-label=\"Anchor link for: 5-1-netfilter-he-iptables\">5.1 netfilter \u548c iptables<\/a><\/h3>\n<p>\u4e3a\u4e86\u5728\u7fa4\u96c6\u5185\u6267\u884c\u8d1f\u8f7d\u5e73\u8861\uff0cKubernetes \u4f9d\u8d56\u4e8e Linux \u5185\u7f6e\u7684\u7f51\u7edc\u6846\u67b6 <code>netfilter<\/code>\u3002Netfilter \u662f\u4e00\u4e2a Linux \u63d0\u4f9b\u7684\u7f51\u7edc\u6846\u67b6\uff0c\u5141\u8bb8\u901a\u8fc7\u5b9a\u5236\u7684 handler \u6765\u5b9e\u73b0\u4e00\u7cfb\u5217\u7f51\u7edc\u76f8\u5173\u7684\u64cd\u4f5c\u3002Netfilter \u63d0\u4f9b\u4e86\u7528\u4e8e\u6570\u636e\u5305\u8fc7\u6ee4\uff0c\u7f51\u7edc\u5730\u5740\u8f6c\u6362\u548c\u7aef\u53e3\u6620\u5c04\u7684\u5404\u79cd\u529f\u80fd\u548c\u64cd\u4f5c\uff0c\u8fd9\u4e9b\u529f\u80fd\u548c\u64cd\u4f5c\u6ee1\u8db3\u4e86\u7f51\u7edc\u4e2d\u6570\u636e\u5305\u91cd\u5b9a\u5411\u6240\u9700\uff0c\u5e76\u63d0\u4f9b\u4e86\u7981\u6b62\u6570\u636e\u5305\u5230\u8fbe\u8ba1\u7b97\u673a\u7f51\u7edc\u5185\u654f\u611f\u4f4d\u7f6e\u7684\u529f\u80fd\u3002<\/p>\n<p>Iptables \u662f\u4e00\u4e2a\u7528\u6237\u7a7a\u95f4\u7a0b\u5e8f\uff0c\u5b83\u63d0\u4f9b\u4e00\u4e2a\u57fa\u4e8e\u8868\u7684\u7cfb\u7edf\uff0c\u7528\u4e8e\u5b9a\u4e49\u4f7f\u7528 netfilter \u6846\u67b6\u64cd\u4f5c\u548c\u8f6c\u6362\u6570\u636e\u5305\u7684\u89c4\u5219\u3002\u5728 Kubernetes \u4e2d\uff0ciptables \u89c4\u5219\u7531\u76d1\u89c6 Kubernetes API \u670d\u52a1\u5668\u66f4\u6539\u7684 kube-proxy Controller \u914d\u7f6e\u3002\u5f53\u5bf9 Service \u6216 Pod \u7684\u66f4\u6539\u66f4\u65b0\u4e86 Service \u7684\u865a\u62df IP \u5730\u5740\u6216 Pod \u7684 IP \u5730\u5740\u65f6\uff0c\u5c06\u66f4\u65b0 iptables \u89c4\u5219\u4ee5\u5c06\u9488\u5bf9 Service \u7684\u6d41\u91cf\u6b63\u786e\u8def\u7531\u5230\u540e\u7aef Pod\u3002Iptables \u89c4\u5219\u76d1\u89c6\u53d1\u5f80 Service \u7684\u865a\u62df IP \u7684\u6d41\u91cf\uff0c\u5e76\u5728\u5339\u914d\u9879\u4e2d\u4ece\u53ef\u7528 Pod \u7684\u96c6\u5408\u4e2d\u9009\u62e9\u4e00\u4e2a\u968f\u673a\u7684 Pod IP \u5730\u5740\uff0c\u5e76\u4e14 iptables \u89c4\u5219\u5c06\u6570\u636e\u5305\u7684\u76ee\u6807 IP \u5730\u5740\u4ece\u670d\u52a1\u7684\u865a\u62df IP \u66f4\u6539\u4e3a \u9009\u4e2d\u7684 Pod \u7684 IP\u3002\u968f\u7740 Pod \u7684\u89c4\u6a21\u6269\u5927\u548c\u7f29\u5c0f\uff0ciptables \u89c4\u5219\u96c6\u5c06\u66f4\u65b0\u4ee5\u53cd\u6620\u96c6\u7fa4\u7684\u53d8\u5316\u72b6\u6001\u3002\u6362\u53e5\u8bdd\u8bf4\uff0ciptables \u5728\u8ba1\u7b97\u673a\u4e0a\u5df2\u901a\u8fc7\u5c06\u5b9a\u5411\u5230 Service IP \u7684\u6d41\u91cf\u5b9a\u5411\u5230\u5b9e\u9645 Pod \u7684 IP \u5b8c\u6210\u4e86\u8d1f\u8f7d\u5747\u8861\uff0c\u4ee5\u3002<\/p>\n<p>\u5728\u53cd\u8fc7\u6765\u7684\u8def\u5f84\u4e0a\uff0cIP \u5730\u5740\u6765\u81ea\u76ee\u6807 Pod\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0ciptables \u518d\u6b21\u91cd\u5199 IP \u5934\uff0c\u7528 Servicce \u7684 IP \u66ff\u6362 Pod \u7684 IP\uff0c\u4f7f Pod \u8ba4\u4e3a\u5b83\u4e00\u76f4\u5728\u4e0e Service \u7684 IP \u8fdb\u884c\u901a\u4fe1\u3002<\/p>\n<h3 id=\"5-2-ipvs\"><a class=\"zola-anchor\" href=\"#5-2-ipvs\" aria-label=\"Anchor link for: 5-2-ipvs\">5.2 IPVS<\/a><\/h3>\n<p>Kubernetes \u7684\u6700\u65b0\u7248\u672c (1.11) \u5305\u62ec\u96c6\u7fa4\u8d1f\u8f7d\u5747\u8861\u7684\u7b2c\u4e8c\u4e2a\u9009\u9879\uff1aIPVS\u3002IPVS (IP \u865a\u62df\u670d\u52a1\u5668) \u4e5f\u5efa\u7acb\u5728 netfilter \u4e4b\u4e0a\uff0c\u5e76\u4f5c\u4e3a Linux \u5185\u6838\u7684\u4e00\u90e8\u5206\u5b9e\u73b0\u4f20\u8f93\u5c42\u8d1f\u8f7d\u5747\u8861\u3002IPVS \u5df2\u96c6\u6210\u5230 LVS (Linux \u865a\u62df\u670d\u52a1\u5668) \u4e2d\uff0c\u5728\u4e3b\u673a\u4e0a\u8fd0\u884c\uff0c\u5e76\u5145\u5f53\u771f\u5b9e\u670d\u52a1\u5668\u96c6\u7fa4\u524d\u9762\u7684\u8d1f\u8f7d\u5747\u8861\u5668\u3002IPVS \u53ef\u4ee5\u5c06\u57fa\u4e8e TCP \u548c UDP \u7684\u670d\u52a1\u7684\u8bf7\u6c42\u5b9a\u5411\u5230\u771f\u5b9e\u670d\u52a1\u5668\uff0c\u5e76\u4f7f\u7531\u591a\u53f0\u670d\u52a1\u5668\u7ec4\u6210\u7684\u670d\u52a1\u8868\u73b0\u4e3a\u5728\u5355\u4e2a IP \u5730\u5740\u4e0a\u7684\u865a\u62df\u670d\u52a1\u3002\u8fd9\u4f7f\u5f97 IPVS \u975e\u5e38\u9002\u5408 Kubernetes Services\u3002<\/p>\n<p>\u58f0\u660e Kubernetes Service \u65f6\uff0c\u53ef\u4ee5\u6307\u5b9a\u662f\u5426\u8981\u4f7f\u7528 iptables \u6216 IPVS \u5b8c\u6210\u96c6\u7fa4\u8d1f\u8f7d\u5747\u8861\u3002IPVS \u4e13\u4e3a\u8d1f\u8f7d\u5747\u8861\u800c\u8bbe\u8ba1\uff0c\u5e76\u4f7f\u7528\u66f4\u6709\u6548\u7684\u6570\u636e\u7ed3\u6784 (\u54c8\u5e0c\u8868)\uff0c\u4e0e iptables \u76f8\u6bd4\uff0c\u51e0\u4e4e\u53ef\u4ee5\u65e0\u9650\u6269\u5c55\u3002\u521b\u5efa\u4f7f\u7528 IPVS \u8d1f\u8f7d\u5747\u8861\u7684 Service \u65f6\uff0c\u4f1a\u53d1\u751f\u4e09\u4ef6\u4e8b\uff1a\u5728 Node \u4e0a\u521b\u5efa\u4e00\u4e2a\u865a\u62df IPVS \u63a5\u53e3\uff0c\u5c06 Service \u7684 IP \u5730\u5740\u7ed1\u5b9a\u5230\u8be5\u865a\u62df IPVS \u63a5\u53e3\uff0c\u5e76\u4e3a\u6bcf\u4e2a Service IP \u5730\u5740\u521b\u5efa IPVS \u670d\u52a1\u5668\u3002<\/p>\n<p>\u5c06\u6765\uff0cIPVS \u6709\u671b\u6210\u4e3a\u7fa4\u96c6\u5185\u8d1f\u8f7d\u5747\u8861\u7684\u9ed8\u8ba4\u65b9\u6cd5\u3002\u8fd9\u4e2a\u66f4\u6539\u4ec5\u5f71\u54cd\u7fa4\u96c6\u5185\u8d1f\u8f7d\u5747\u8861\uff0c\u5728\u672c\u6307\u5357\u7684\u5176\u4f59\u90e8\u5206\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 IPVS \u5b89\u5168\u5730\u5c06 iptables \u66ff\u6362\u4e3a\u7fa4\u96c6\u5185\u8d1f\u8f7d\u5e73\u8861\uff0c\u800c\u4e0d\u4f1a\u5f71\u54cd\u5176\u4f59\u7684\u8ba8\u8bba\u3002\u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u770b\u4e00\u4e0b\u901a\u8fc7\u7fa4\u96c6\u5185\u8d1f\u8f7d\u5e73\u8861 Service \u7684\u6570\u636e\u5305\u7684\u751f\u547d\u5468\u671f\u3002<\/p>\n<h3 id=\"5-3-bao-de-sheng-ming-zhou-qi-pod-dao-service\"><a class=\"zola-anchor\" href=\"#5-3-bao-de-sheng-ming-zhou-qi-pod-dao-service\" aria-label=\"Anchor link for: 5-3-bao-de-sheng-ming-zhou-qi-pod-dao-service\">5.3 \u5305\u7684\u751f\u547d\u5468\u671f\uff1aPod \u5230 Service<\/a><\/h3>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/a-guide-to-the-kubernetes-networking-model\/images\/pod-to-service.gif\" alt=\"Figure 8\" \/><\/p>\n<p>\u56fe8. \u6570\u636e\u5305\u5728 Pod \u548c Service \u95f4\u79fb\u52a8<\/p>\n<p>\u5728 Pod \u548c Service \u4e4b\u95f4\u8def\u7531\u6570\u636e\u5305\u65f6\uff0c\u65c5\u7a0b\u4ee5\u4e0e\u4ee5\u524d\u76f8\u540c\u7684\u65b9\u5f0f\u5f00\u59cb\u3002\u6570\u636e\u5305\u9996\u5148\u901a\u8fc7\u9644\u52a0\u5230 Pod \u7f51\u7edc\u540d\u79f0\u7a7a\u95f4 (1) \u7684 eth0 \u63a5\u53e3\u79bb\u5f00 Pod\u3002\u7136\u540e\uff0c\u5b83\u901a\u8fc7\u865a\u62df\u4ee5\u592a\u7f51\u8bbe\u5907\u5230\u8fbe\u7f51\u6865 (2) \u3002\u5728\u7f51\u6865\u4e0a\u8fd0\u884c\u7684 ARP \u534f\u8bae\u4e0d\u4e86\u89e3\u670d\u52a1\uff0c\u56e0\u6b64\u5b83\u901a\u8fc7\u9ed8\u8ba4\u8def\u7531 eth0 (3) \u4f20\u9001\u6570\u636e\u5305\u3002\u5728\u8fd9\u91cc\uff0c\u53d1\u751f\u4e86\u4e00\u4e9b\u4e0d\u540c\u7684\u4e8b\u60c5\u3002\u5728\u88ab eth0 \u63a5\u53d7\u4e4b\u524d\uff0c\u8be5\u6570\u636e\u5305\u5df2\u901a\u8fc7 iptables \u8fdb\u884c\u8fc7\u6ee4\u3002\u6536\u5230\u6570\u636e\u5305\u540e\uff0ciptables \u4f1a\u4f7f\u7528 kube-proxy \u5b89\u88c5\u5728\u8282\u70b9\u4e0a\u7684\u89c4\u5219\u6765\u54cd\u5e94 Service \u6216 Pod \u4e8b\u4ef6\uff0c\u5c06\u6570\u636e\u5305\u7684\u76ee\u6807\u4ece Service IP \u91cd\u5199\u5230\u7279\u5b9a\u7684 Pod IP (4) \u3002\u73b0\u5728\uff0c\u8be5\u6570\u636e\u5305\u5c06\u5230\u8fbe Pod 4\uff0c\u800c\u4e0d\u662f\u670d\u52a1\u7684\u865a\u62df IP\u3002iptables \u5145\u5206\u5229\u7528\u4e86 Linux \u5185\u6838\u7684 conntrack \u5b9e\u7528\u7a0b\u5e8f\uff0c\u4ee5\u8bb0\u4f4f\u505a\u51fa\u7684 Pod \u9009\u62e9\uff0c\u4ee5\u4fbf\u5c06\u6765\u7684\u6d41\u91cf\u88ab\u8def\u7531\u5230\u76f8\u540c\u7684 Pod (\u9664\u975e\u6709\u4efb\u4f55\u6269\u5c55\u4e8b\u4ef6) \u3002\u672c\u8d28\u4e0a\uff0ciptables \u76f4\u63a5\u5728\u8282\u70b9\u4e0a\u5b8c\u6210\u4e86\u96c6\u7fa4\u8d1f\u8f7d\u5e73\u8861\u3002\u7136\u540e\uff0c\u4f7f\u7528\u6211\u4eec\u5df2\u7ecf\u68c0\u67e5\u8fc7\u7684 Pod \u5230 Pod \u8def\u7531\uff0c\u6d41\u91cf\u6d41\u5411 Pod (5)\u3002<\/p>\n<h3 id=\"5-4-bao-de-sheng-ming-zhou-qi-service-dao-pod\"><a class=\"zola-anchor\" href=\"#5-4-bao-de-sheng-ming-zhou-qi-service-dao-pod\" aria-label=\"Anchor link for: 5-4-bao-de-sheng-ming-zhou-qi-service-dao-pod\">5.4 \u5305\u7684\u751f\u547d\u5468\u671f\uff1aService \u5230 Pod<\/a><\/h3>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/a-guide-to-the-kubernetes-networking-model\/images\/service-to-pod.gif\" alt=\"Figure 9\" \/><\/p>\n<p>\u56fe9. \u5305\u5728 Service \u548c Pod \u4e4b\u95f4\u79fb\u52a8<\/p>\n<p>\u63a5\u6536\u5230\u6b64\u6570\u636e\u5305\u7684 Pod \u5c06\u505a\u51fa\u54cd\u5e94\uff0c\u5c06\u6e90 IP \u6807\u8bc6\u4e3a\u81ea\u5df1\u7684 IP\uff0c\u5c06\u76ee\u6807 IP \u6807\u8bc6\u4e3a\u6700\u521d\u53d1\u9001\u8be5\u6570\u636e\u5305\u7684 Pod (1) \u3002\u8fdb\u5165\u8282\u70b9\u540e\uff0c\u6570\u636e\u5305\u6d41\u7ecf iptables\uff0c\u540e\u8005\u4f7f\u7528 conntrack \u8bb0\u4f4f\u5176\u5148\u524d\u6240\u505a\u7684\u9009\u62e9\uff0c\u5e76\u5c06\u6570\u636e\u5305\u7684\u6e90\u91cd\u5199\u4e3a\u670d\u52a1\u7684 IP\uff0c\u800c\u4e0d\u662f Pod \u7684 IP (2) \u3002\u6570\u636e\u5305\u4ece\u8fd9\u91cc\u6d41\u8fc7\u7f51\u6865\uff0c\u5230\u8fbe\u4e0e Pod \u7684\u547d\u540d\u7a7a\u95f4\u914d\u5bf9\u7684\u865a\u62df\u4ee5\u592a\u7f51\u8bbe\u5907 (3) \uff0c\u518d\u5230\u6211\u4eec\u4e4b\u524d\u6240\u89c1\u7684 Pod \u7684\u4ee5\u592a\u7f51\u8bbe\u5907 (4) \u3002<\/p>\n<h3 id=\"5-5-shi-yong-dns\"><a class=\"zola-anchor\" href=\"#5-5-shi-yong-dns\" aria-label=\"Anchor link for: 5-5-shi-yong-dns\">5.5 \u4f7f\u7528 DNS<\/a><\/h3>\n<p>Kubernetes \u53ef\u4ee5\u9009\u62e9\u4f7f\u7528 DNS\uff0c\u4ee5\u907f\u514d\u5fc5\u987b\u5c06\u670d\u52a1\u7684\u7fa4\u96c6 IP \u5730\u5740\u786c\u7f16\u7801\u5230\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u4e2d\u3002Kubernetes DNS \u4f5c\u4e3a\u5728\u7fa4\u96c6\u4e0a\u8ba1\u5212\u7684\u5e38\u89c4 Kubernetes \u670d\u52a1\u8fd0\u884c\u3002\u5b83\u914d\u7f6e\u5728\u6bcf\u4e2a\u8282\u70b9\u4e0a\u8fd0\u884c\u7684 kubelet\uff0c\u4ee5\u4fbf\u5bb9\u5668\u4f7f\u7528 DNS \u670d\u52a1\u7684 IP \u6765\u89e3\u6790 DNS \u540d\u79f0\u3002\u4e3a\u7fa4\u96c6\u4e2d\u5b9a\u4e49\u7684\u6bcf\u4e2a\u670d\u52a1 (\u5305\u62ec DNS \u670d\u52a1\u5668\u672c\u8eab) \u5206\u914d\u4e00\u4e2a DNS \u540d\u79f0\u3002DNS \u8bb0\u5f55\u6839\u636e\u60a8\u7684\u9700\u8981\u5c06 DNS \u540d\u79f0\u89e3\u6790\u4e3a\u670d\u52a1\u7684\u7fa4\u96c6 IP \u6216 POD \u7684 IP\u3002SRV \u8bb0\u5f55\u7528\u4e8e\u6307\u5b9a\u8fd0\u884c\u670d\u52a1\u7684\u7279\u5b9a\u547d\u540d\u7aef\u53e3\u3002<\/p>\n<p>\u4e00\u4e2a DNS Pod \u7531\u4e09\u4e2a\u72ec\u7acb\u7684\u5bb9\u5668\u7ec4\u6210\uff1a<\/p>\n<ul>\n<li><strong>kubedns<\/strong>: \u76d1\u89c6 Kubernetes \u4e3b\u670d\u52a1\u5668\u7684\u670d\u52a1\u548c\u7aef\u70b9\u66f4\u6539\uff0c\u5e76\u7ef4\u62a4\u5185\u5b58\u67e5\u627e\u7ed3\u6784\u4ee5\u670d\u52a1 DNS \u8bf7\u6c42\u3002<\/li>\n<li><strong>dnsmasq<\/strong>: \u6dfb\u52a0 DNS \u7f13\u5b58\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<li><strong>sidecar<\/strong>: \u63d0\u4f9b\u5355\u4e2a\u8fd0\u884c\u72b6\u51b5\u68c0\u67e5\u7aef\u70b9\uff0c\u4ee5\u6267\u884c dnsmasq \u548c kubedns \u7684\u8fd0\u884c\u72b6\u51b5\u68c0\u67e5\u3002<\/li>\n<\/ul>\n<p>DNS Pod \u672c\u8eab\u4f5c\u4e3a Kubernetes \u670d\u52a1\u516c\u5f00\uff0c\u5177\u6709\u9759\u6001\u7fa4\u96c6 IP\uff0c\u8be5 IP \u5728\u542f\u52a8\u65f6\u4f20\u9012\u7ed9\u6bcf\u4e2a\u6b63\u5728\u8fd0\u884c\u7684\u5bb9\u5668\uff0c\u4ee5\u4fbf\u6bcf\u4e2a\u5bb9\u5668\u90fd\u53ef\u4ee5\u89e3\u6790 DNS \u6761\u76ee\u3002DNS \u6761\u76ee\u901a\u8fc7 kubedns \u7cfb\u7edf\u89e3\u6790\uff0c\u8be5\u7cfb\u7edf\u5728\u5185\u5b58\u4e2d\u7ef4\u62a4 DNS \u8868\u793a\u5f62\u5f0f\u3002etcd \u662f\u7528\u4e8e\u7fa4\u96c6\u72b6\u6001\u7684\u540e\u7aef\u5b58\u50a8\u7cfb\u7edf\uff0c\u800c kubedns \u4f7f\u7528\u4e00\u4e2a\u5e93\uff0c\u8be5\u5e93\u5728\u5fc5\u8981\u65f6\u5c06 etcd \u5bc6\u94a5\u503c\u5b58\u50a8\u8f6c\u6362\u4e3a DNS \u6761\u76ee\uff0c\u4ee5\u91cd\u5efa\u5185\u5b58 DNS \u67e5\u627e\u7ed3\u6784\u7684\u72b6\u6001\u3002<\/p>\n<p>CoreDNS \u7684\u5de5\u4f5c\u65b9\u5f0f\u4e0e kubedns \u76f8\u4f3c\uff0c\u4f46\u5176\u4f7f\u7528\u7684\u63d2\u4ef6\u4f53\u7cfb\u7ed3\u6784\u4f7f\u5176\u66f4\u52a0\u7075\u6d3b\u3002\u4ece Kubernetes 1.11 \u5f00\u59cb\uff0cCoreDNS \u662f Kubernetes \u7684\u9ed8\u8ba4 DNS \u5b9e\u73b0\u3002<\/p>\n<h2 id=\"6-cong-internet-dao-service-de-wang-luo\"><a class=\"zola-anchor\" href=\"#6-cong-internet-dao-service-de-wang-luo\" aria-label=\"Anchor link for: 6-cong-internet-dao-service-de-wang-luo\">6 \u4ece Internet \u5230 Service \u7684\u7f51\u7edc<\/a><\/h2>\n<p>\u5230\u76ee\u524d\u4e3a\u6b62\uff0c\u6211\u4eec\u5df2\u7ecf\u7814\u7a76\u4e86\u5982\u4f55\u5728 Kubernetes \u96c6\u7fa4\u4e2d\u8def\u7531\u6d41\u91cf\u3002\u8fd9\u4e00\u5207\u90fd\u5f88\u597d\uff0c\u4f46\u662f\u4e0d\u5e78\u7684\u662f\uff0c\u5c06\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u4e0e\u5916\u754c\u9694\u79bb\u5c06\u65e0\u52a9\u4e8e\u5b9e\u73b0\u4efb\u4f55\u9500\u552e\u76ee\u6807\u2014\u2014\u5728\u67d0\u4e2a\u65f6\u5019\uff0c\u60a8\u5c06\u9700\u8981\u5411\u5916\u90e8\u6d41\u91cf\u516c\u5f00\u60a8\u7684\u670d\u52a1\u3002\u8fd9\u79cd\u9700\u6c42\u7a81\u51fa\u4e86\u4e24\u4e2a\u76f8\u5173\u7684\u95ee\u9898\uff1a (1) \u5c06\u6765\u81ea Kubernetes \u670d\u52a1\u7684\u6d41\u91cf\u53d1\u9001\u5230 Internet (Egress) \uff0c\u4ee5\u53ca (2) \u5c06\u6765\u81ea Internet \u7684\u6d41\u91cf\u53d1\u9001\u5230\u60a8\u7684 Kubernetes Service (Ingress) \u3002\u672c\u8282\u4f9d\u6b21\u9610\u8ff0\u8fd9\u4e9b\u95ee\u9898\u3002<\/p>\n<h3 id=\"6-1-egress-jiang-liu-liang-lu-you-dao-internet\"><a class=\"zola-anchor\" href=\"#6-1-egress-jiang-liu-liang-lu-you-dao-internet\" aria-label=\"Anchor link for: 6-1-egress-jiang-liu-liang-lu-you-dao-internet\">6.1 Egress \u2014 \u5c06\u6d41\u91cf\u8def\u7531\u5230 Internet<\/a><\/h3>\n<p>\u4ece\u8282\u70b9\u5230\u516c\u5171 Internet \u7684\u6d41\u91cf\u8def\u7531\u662f\u7279\u5b9a\u4e8e\u7f51\u7edc\u7684\uff0c\u5e76\u4e14\u5b9e\u9645\u4e0a\u53d6\u51b3\u4e8e\u7f51\u7edc\u914d\u7f6e\u4e3a\u53d1\u5e03\u6d41\u91cf\u7684\u65b9\u5f0f\u3002\u4e3a\u4e86\u4f7f\u672c\u8282\u66f4\u5177\u4f53\uff0c\u6211\u5c06\u4f7f\u7528 AWS VPC \u8ba8\u8bba\u4efb\u4f55\u7279\u5b9a\u7ec6\u8282\u3002<\/p>\n<p>\u5728 AWS \u4e2d\uff0cKubernetes \u96c6\u7fa4\u5728 VPC \u5185\u8fd0\u884c\uff0c\u5176\u4e2d\u4e3a\u6bcf\u4e2a\u8282\u70b9\u5206\u914d\u4e86\u4e00\u4e2a\u79c1\u6709 IP \u5730\u5740\uff0c\u8be5\u5730\u5740\u53ef\u4ece Kubernetes \u96c6\u7fa4\u5185\u8bbf\u95ee\u3002\u8981\u4f7f\u6d41\u91cf\u53ef\u4ee5\u4ece\u7fa4\u96c6\u5916\u90e8\u8bbf\u95ee\uff0c\u8bf7\u5c06 Internet \u7f51\u5173\u8fde\u63a5\u5230 VPC\u3002Internet \u7f51\u5173\u6709\u4e24\u4e2a\u76ee\u7684\uff1a\u5728 VPC \u8def\u7531\u8868\u4e2d\u4e3a\u53ef\u8def\u7531\u5230 Internet \u7684\u6d41\u91cf\u63d0\u4f9b\u76ee\u6807\uff0c\u5e76\u4e3a\u5df2\u5206\u914d\u4e86\u516c\u5171 IP \u5730\u5740\u7684\u4efb\u4f55\u5b9e\u4f8b\u6267\u884c\u7f51\u7edc\u5730\u5740\u8f6c\u6362 (NAT) \u3002NAT \u8f6c\u6362\u8d1f\u8d23\u5c06\u7fa4\u96c6\u4e13\u7528\u7684\u8282\u70b9\u5185\u90e8 IP \u5730\u5740\u66f4\u6539\u4e3a\u516c\u7528 Internet \u4e0a\u53ef\u7528\u7684\u5916\u90e8 IP \u5730\u5740\u3002<\/p>\n<p>\u6709\u4e86 Internet \u7f51\u5173\u540e\uff0cVM \u53ef\u4ee5\u81ea\u7531\u5730\u5c06\u6d41\u91cf\u8def\u7531\u5230 Internet\u3002\u4e0d\u5e78\u7684\u662f\uff0c\u8fd9\u91cc\u6709\u4e00\u4e2a\u5c0f\u95ee\u9898\u3002Pod \u62e5\u6709\u81ea\u5df1\u7684 IP \u5730\u5740\uff0c\u8be5 IP \u5730\u5740\u4e0e\u6258\u7ba1 Pod \u7684\u8282\u70b9\u7684 IP \u5730\u5740\u4e0d\u540c\uff0c\u5e76\u4e14 Internet \u7f51\u5173\u4e0a\u7684 NAT \u8f6c\u6362\u4ec5\u9002\u7528\u4e8e VM IP \u5730\u5740\uff0c\u56e0\u4e3a\u5b83\u4e0d\u4e86\u89e3\u54ea\u4e9b Pod \u5728\u54ea\u4e9b VM \u4e0a\u8fd0\u884c\u2014\u2014\u7f51\u5173\u4e0d\u611f\u77e5\u5bb9\u5668\u3002\u8ba9\u6211\u4eec\u770b\u770b Kubernetes \u5982\u4f55\u4f7f\u7528 iptables (\u518d\u6b21) \u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n<h4 id=\"6-1-1-bao-de-sheng-ming-zhou-qi-node-dao-internet\"><a class=\"zola-anchor\" href=\"#6-1-1-bao-de-sheng-ming-zhou-qi-node-dao-internet\" aria-label=\"Anchor link for: 6-1-1-bao-de-sheng-ming-zhou-qi-node-dao-internet\">6.1.1 \u5305\u7684\u751f\u547d\u5468\u671f\uff1aNode \u5230 Internet<\/a><\/h4>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/a-guide-to-the-kubernetes-networking-model\/images\/pod-to-internet.gif\" alt=\"Figure 10\" \/><\/p>\n<p>\u56fe10. \u5c06\u6570\u636e\u5305\u4ece Pod \u8def\u7531\u5230 Internet<\/p>\n<p>\u5728\u4e0b\u56fe\u4e2d\uff0c\u6570\u636e\u5305\u8d77\u6e90\u4e8e Pod \u7684\u540d\u79f0\u7a7a\u95f4 (1) \uff0c\u5e76\u7ecf\u8fc7\u4e0e\u6839\u540d\u79f0\u7a7a\u95f4 (2) \u8fde\u63a5\u7684 veth \u5bf9\u3002\u4e00\u65e6\u8fdb\u5165\u6839\u540d\u79f0\u7a7a\u95f4\uff0c\u7531\u4e8e\u6570\u636e\u5305\u4e0a\u7684 IP \u4e0e\u8fde\u63a5\u5230\u7f51\u6865\u7684\u4efb\u4f55\u7f51\u6bb5\u90fd\u4e0d\u5339\u914d\uff0c\u6570\u636e\u5305\u5c31\u4f1a\u4ece\u7f51\u6865\u79fb\u52a8\u5230\u9ed8\u8ba4\u8bbe\u5907\u3002\u5728\u5230\u8fbe\u6839\u540d\u79f0\u7a7a\u95f4\u7684\u4ee5\u592a\u7f51\u8bbe\u5907 (3) \u4e4b\u524d\uff0ciptables \u4f1a\u5904\u7406\u6570\u636e\u5305 (3) \u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6570\u636e\u5305\u7684\u6e90 IP \u5730\u5740\u662f Pod\uff0c\u5982\u679c\u6211\u4eec\u5c06\u6e90\u4fdd\u7559\u4e3a Pod\uff0c\u5219 Internet \u7f51\u5173\u5c06\u62d2\u7edd\u5b83\uff0c\u56e0\u4e3a\u7f51\u5173 NAT \u4ec5\u4e86\u89e3\u8fde\u63a5\u5230 VM \u7684 IP \u5730\u5740\u3002\u89e3\u51b3\u65b9\u6848\u662f\u8ba9 iptables \u6267\u884c\u6e90 NAT (\u66f4\u6539\u6570\u636e\u5305\u6e90) \uff0c\u4ee5\u4fbf\u6570\u636e\u5305\u770b\u8d77\u6765\u662f\u6765\u81ea VM \u800c\u4e0d\u662f Pod\u3002\u6709\u4e86\u6b63\u786e\u7684\u6e90 IP\uff0c\u6570\u636e\u5305\u73b0\u5728\u53ef\u4ee5\u79bb\u5f00 VM (4) \u5e76\u5230\u8fbe Internet \u7f51\u5173 (5) \u3002Internet \u7f51\u5173\u5c06\u6267\u884c\u53e6\u4e00\u4e2a NAT\uff0c\u5c06\u6e90 IP \u4ece VM \u5185\u90e8 IP \u91cd\u5199\u4e3a\u5916\u90e8 IP\u3002\u6700\u7ec8\uff0c\u6570\u636e\u5305\u5c06\u5230\u8fbe\u516c\u5171 Internet (6) \u3002\u5728\u8fd4\u56de\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6570\u636e\u5305\u9075\u5faa\u76f8\u540c\u7684\u8def\u5f84\uff0c\u5e76\u4e14\u6240\u6709\u6e90 IP \u5904\u7406\u90fd\u88ab\u64a4\u6d88\uff0c\u56e0\u6b64\u7cfb\u7edf\u7684\u6bcf\u4e00\u5c42\u90fd\u63a5\u6536\u5176\u80fd\u591f\u7406\u89e3\u7684 IP \u5730\u5740\uff1a\u8282\u70b9\u6216 VM \u7ea7\u522b\u7684 VM \u5185\u90e8 IP\uff0c\u4ee5\u53ca Pod \u547d\u540d\u7a7a\u95f4\u5185\u7684 Pod IP\u3002<\/p>\n<h3 id=\"6-2-ingress-jiang-internet-liu-liang-lu-you-dao-kubernetes\"><a class=\"zola-anchor\" href=\"#6-2-ingress-jiang-internet-liu-liang-lu-you-dao-kubernetes\" aria-label=\"Anchor link for: 6-2-ingress-jiang-internet-liu-liang-lu-you-dao-kubernetes\">6.2 Ingress \u2014 \u5c06 Internet \u6d41\u91cf\u8def\u7531\u5230 Kubernetes<\/a><\/h3>\n<p>Ingress\u2014\u2014\u5c06\u6d41\u91cf\u5f15\u5165\u7fa4\u96c6\u2014\u2014\u662f\u4e00\u4e2a\u975e\u5e38\u68d8\u624b\u7684\u95ee\u9898\u3002\u540c\u6837\uff0c\u8fd9\u662f\u7279\u5b9a\u4e8e\u60a8\u6b63\u5728\u8fd0\u884c\u7684\u7f51\u7edc\u7684\uff0c\u4f46\u662f\u901a\u5e38\uff0cIngress \u5206\u4e3a\u4e24\u4e2a\u53ef\u5728\u7f51\u7edc\u5806\u6808\u7684\u4e0d\u540c\u90e8\u5206\u4e0a\u8fd0\u884c\u7684\u89e3\u51b3\u65b9\u6848\uff1a (1) Service LoadBalancer \u548c (2) Ingress \u63a7\u5236\u5668\u3002<\/p>\n<h4 id=\"6-2-1-4ceng-ingress-loadbalancer\"><a class=\"zola-anchor\" href=\"#6-2-1-4ceng-ingress-loadbalancer\" aria-label=\"Anchor link for: 6-2-1-4ceng-ingress-loadbalancer\">6.2.1 4\u5c42 Ingress: LoadBalancer<\/a><\/h4>\n<p>\u521b\u5efa Kubernetes \u670d\u52a1\u65f6\uff0c\u53ef\u4ee5\u9009\u62e9\u6307\u5b9a\u4e00\u4e2a <code>LoadBalancer<\/code> \u6765\u914d\u5408\u5b83\u3002\u4e91\u63a7\u5236\u5668\u63d0\u4f9b\u4e86 <code>LoadBalancer<\/code> \u7684\u5b9e\u73b0\uff0c\u8be5\u63a7\u5236\u5668\u77e5\u9053\u5982\u4f55\u4e3a\u60a8\u7684\u670d\u52a1\u521b\u5efa\u8d1f\u8f7d\u5747\u8861\u5668\u3002\u521b\u5efa\u670d\u52a1\u540e\uff0c\u5b83\u5c06\u4e3a\u8d1f\u8f7d\u5747\u8861\u5668\u901a\u544a IP \u5730\u5740\u3002\u4f5c\u4e3a\u6700\u7ec8\u7528\u6237\uff0c\u60a8\u53ef\u4ee5\u5f00\u59cb\u5c06\u6d41\u91cf\u5b9a\u5411\u5230\u8d1f\u8f7d\u5e73\u8861\u5668\uff0c\u4ee5\u5f00\u59cb\u4e0e\u670d\u52a1\u8fdb\u884c\u901a\u4fe1\u3002<\/p>\n<p>\u501f\u52a9 AWS\uff0c\u8d1f\u8f7d\u5747\u8861\u5668\u53ef\u4ee5\u77e5\u9053\u5176\u76ee\u6807\u7ec4\u4e2d\u7684\u8282\u70b9\uff0c\u5e76\u5c06\u5e73\u8861\u7fa4\u96c6\u4e2d\u6240\u6709\u8282\u70b9\u4e0a\u7684\u6d41\u91cf\u3002\u4e00\u65e6\u6d41\u91cf\u5230\u8fbe\u8282\u70b9\uff0c\u5148\u524d\u5728\u6574\u4e2a\u7fa4\u96c6\u4e2d\u4e3a\u60a8\u7684\u670d\u52a1\u5b89\u88c5\u7684 iptables \u89c4\u5219\u5c06\u786e\u4fdd\u6d41\u91cf\u5230\u8fbe\u60a8\u611f\u5174\u8da3\u7684\u670d\u52a1\u7684 Pod\u3002<\/p>\n<h4 id=\"6-2-2-bao-de-sheng-ming-zhou-qi-loadbalancer-dao-service\"><a class=\"zola-anchor\" href=\"#6-2-2-bao-de-sheng-ming-zhou-qi-loadbalancer-dao-service\" aria-label=\"Anchor link for: 6-2-2-bao-de-sheng-ming-zhou-qi-loadbalancer-dao-service\">6.2.2 \u5305\u7684\u751f\u547d\u5468\u671f\uff1aLoadBalancer \u5230 Service<\/a><\/h4>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/a-guide-to-the-kubernetes-networking-model\/images\/internet-to-service.gif\" alt=\"Figure 11\" \/><\/p>\n<p>\u56fe11. \u4ece Internet \u53d1\u9001\u5230 Service \u7684\u6570\u636e\u5305<\/p>\n<p>\u8ba9\u6211\u4eec\u770b\u770b\u8fd9\u5728\u5b9e\u8df5\u4e2d\u662f\u5982\u4f55\u5de5\u4f5c\u7684\u3002\u90e8\u7f72\u670d\u52a1\u540e\uff0c\u60a8\u6b63\u5728\u4f7f\u7528\u7684\u4e91\u63d0\u4f9b\u5546\u5c06\u4e3a\u60a8\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u8d1f\u8f7d\u5747\u8861\u5668 (1) \u3002\u56e0\u4e3a\u8d1f\u8f7d\u5e73\u8861\u5668\u4e0d\u611f\u77e5\u5bb9\u5668\uff0c\u6240\u4ee5\u4e00\u65e6\u6d41\u91cf\u5230\u8fbe\u8d1f\u8f7d\u5e73\u8861\u5668\uff0c\u5b83\u4fbf\u4f1a\u5206\u5e03\u5728\u7ec4\u6210\u7fa4\u96c6\u7684\u6240\u6709 VM \u4e2d (2) \u3002\u6bcf\u4e2a VM \u4e0a\u7684 iptables \u89c4\u5219\u4f1a\u5c06\u6765\u81ea\u8d1f\u8f7d\u5747\u8861\u5668\u7684\u4f20\u5165\u6d41\u91cf\u5b9a\u5411\u5230\u6b63\u786e\u7684 Pod (3) \u2014\u2014\u8fd9\u4e9b\u89c4\u5219\u4e0e\u521b\u5efa\u670d\u52a1\u671f\u95f4\u5236\u5b9a\u7684 IP \u8868\u89c4\u5219\u76f8\u540c\uff0c\u524d\u9762\u5df2\u7ecf\u8ba8\u8bba\u8fc7\u3002\u4ece Pod \u5230\u5ba2\u6237\u7aef\u7684\u54cd\u5e94\u5c06\u8fd4\u56de Pod \u7684 IP\uff0c\u4f46\u5ba2\u6237\u7aef\u9700\u8981\u5177\u6709\u8d1f\u8f7d\u5747\u8861\u5668\u7684 IP \u5730\u5740\u3002\u5982\u524d\u6240\u8ff0\uff0ciptables \u548c conntrack \u7528\u4e8e\u5728\u8fd4\u56de\u8def\u5f84\u4e0a\u6b63\u786e\u91cd\u5199 IP\u3002<\/p>\n<p>\u4e0b\u56fe\u663e\u793a\u4e86\u5728\u627f\u8f7d Pod \u7684\u4e09\u4e2a VM \u4e4b\u524d\u7684\u7f51\u7edc\u8d1f\u8f7d\u5e73\u8861\u5668\u3002\u4f20\u5165\u6d41\u91cf (1) \u6307\u5411\u670d\u52a1\u7684\u8d1f\u8f7d\u5e73\u8861\u5668\u3002\u4e00\u65e6\u8d1f\u8f7d\u5747\u8861\u5668\u6536\u5230\u6570\u636e\u5305 (2) \uff0c\u5b83\u5c31\u4f1a\u968f\u673a\u9009\u62e9\u4e00\u4e2a VM\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u75c5\u7406\u5730\u9009\u62e9\u4e86\u6ca1\u6709\u8fd0\u884c Pod \u7684 VM\uff1aVM 2 (3) \u3002\u5728\u8fd9\u91cc\uff0c\u5728 VM \u4e0a\u8fd0\u884c\u7684 iptables \u89c4\u5219\u5c06\u4f7f\u7528\u901a\u8fc7 kube-proxy \u5b89\u88c5\u5230\u7fa4\u96c6\u4e2d\u7684\u5185\u90e8\u8d1f\u8f7d\u5e73\u8861\u89c4\u5219\u5c06\u6570\u636e\u5305\u5b9a\u5411\u5230\u6b63\u786e\u7684 Pod\u3002iptables \u6267\u884c\u6b63\u786e\u7684 NAT\uff0c\u5e76\u5c06\u6570\u636e\u5305\u8f6c\u53d1\u5230\u6b63\u786e\u7684 Pod (4) \u3002<\/p>\n<h4 id=\"6-2-3-7ceng-ingress-ingress-controller\"><a class=\"zola-anchor\" href=\"#6-2-3-7ceng-ingress-ingress-controller\" aria-label=\"Anchor link for: 6-2-3-7ceng-ingress-ingress-controller\">6.2.3 7\u5c42 Ingress: Ingress Controller<\/a><\/h4>\n<p>7 \u5c42\u7f51\u7edc Ingress \u5728\u7f51\u7edc\u5806\u6808\u7684 HTTP\/HTTPS \u534f\u8bae\u8303\u56f4\u5185\u8fd0\u884c\uff0c\u5e76\u5efa\u7acb\u5728\u670d\u52a1\u4e4b\u4e0a\u3002\u542f\u7528 Ingress \u7684\u7b2c\u4e00\u6b65\u662f\u4f7f\u7528 Kubernetes \u4e2d\u7684 <code>NodePort<\/code> \u670d\u52a1\u7c7b\u578b\u5728\u670d\u52a1\u4e0a\u6253\u5f00\u7aef\u53e3\u3002\u5982\u679c\u5c06\u670d\u52a1\u7684 <code>type<\/code> \u5b57\u6bb5\u8bbe\u7f6e\u4e3a <code>NodePort<\/code>\uff0c\u5219 Kubernetes \u4e3b\u670d\u52a1\u5668\u5c06\u5728\u60a8\u6307\u5b9a\u7684\u8303\u56f4\u5185\u5206\u914d\u4e00\u4e2a\u7aef\u53e3\uff0c\u5e76\u4e14\u6bcf\u4e2a\u8282\u70b9\u4f1a\u5c06\u8be5\u7aef\u53e3 (\u6bcf\u4e2a\u8282\u70b9\u4e0a\u7684\u76f8\u540c\u7aef\u53e3\u53f7) \u4ee3\u7406\u5230\u60a8\u7684\u670d\u52a1\u4e2d\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u4f7f\u7528 iptables \u89c4\u5219\uff0c\u4efb\u4f55\u5b9a\u5411\u5230\u8be5\u8282\u70b9\u7aef\u53e3\u7684\u6d41\u91cf\u90fd\u5c06\u8f6c\u53d1\u5230\u8be5\u670d\u52a1\u3002\u8fd9\u79cd\u4ece Service \u5230 Pod \u7684\u8def\u7531\u9075\u5faa\u4e86\u6211\u4eec\u4e4b\u524d\u5728\u8ba8\u8bba\u4ece Service \u5230 Pod \u7684\u6d41\u91cf\u8def\u7531\u65f6\u5df2\u7ecf\u8ba8\u8bba\u8fc7\u7684\u76f8\u540c\u7684\u5185\u90e8\u96c6\u7fa4\u8d1f\u8f7d\u5e73\u8861\u6a21\u5f0f\u3002<\/p>\n<p>\u8981\u5c06\u8282\u70b9\u7684\u7aef\u53e3\u66b4\u9732\u7ed9 Internet\uff0c\u8bf7\u4f7f\u7528 <code>Ingress<\/code> \u5bf9\u8c61\u3002Ingress \u662f\u66f4\u9ad8\u7ea7\u522b\u7684 HTTP \u8d1f\u8f7d\u5e73\u8861\u5668\uff0c\u53ef\u5c06 HTTP \u8bf7\u6c42\u6620\u5c04\u5230 Kubernetes Services\u3002Ingress \u65b9\u6cd5\u5c06\u6709\u6240\u4e0d\u540c\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e Kubernetes \u4e91\u63d0\u4f9b\u5546\u63a7\u5236\u5668\u5982\u4f55\u5b9e\u73b0\u5b83\u3002HTTP \u8d1f\u8f7d\u5e73\u8861\u5668 (\u5982 4 \u5c42\u7f51\u7edc\u8d1f\u8f7d\u5e73\u8861\u5668) \u4ec5\u4e86\u89e3 Node IP (\u800c\u975e Pod IP) \uff0c\u56e0\u6b64\u6d41\u91cf\u8def\u7531\u540c\u6837\u5229\u7528 kube-proxy \u5728\u6bcf\u4e2a\u8282\u70b9\u4e0a\u5b89\u88c5\u7684 iptables \u89c4\u5219\u63d0\u4f9b\u7684\u5185\u90e8\u8d1f\u8f7d\u5e73\u8861\u3002<\/p>\n<p>\u5728 AWS \u73af\u5883\u4e2d\uff0cALB Ingress Controller \u4f7f\u7528 Amazon \u7684 7 \u5c42\u5e94\u7528\u7a0b\u5e8f\u8d1f\u8f7d\u5e73\u8861\u5668 (ALB) \u63d0\u4f9b Kubernetes Ingress\u3002\u4e0b\u56fe\u8be6\u7ec6\u8bf4\u660e\u4e86\u6b64\u63a7\u5236\u5668\u521b\u5efa\u7684 AWS \u7ec4\u4ef6\u3002\u5b83\u8fd8\u6f14\u793a\u4e86 Ingress \u6d41\u91cf\u4ece ALB \u5230 Kubernetes \u96c6\u7fa4\u7684\u8def\u7531\u3002<\/p>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/a-guide-to-the-kubernetes-networking-model\/images\/ingress-controller-design.png\" alt=\"Figure 12\" \/><\/p>\n<p>\u56fe12. Ingress Controller \u7684\u8bbe\u8ba1<\/p>\n<p>\u521b\u5efa\u540e\uff0c (1) Ingress Controller \u5c06\u76d1\u89c6\u6765\u81ea Kubernetes API \u670d\u52a1\u5668\u7684 Ingress \u4e8b\u4ef6\u3002\u5f53\u53d1\u73b0\u6ee1\u8db3\u5176\u8981\u6c42\u7684 Ingress \u8d44\u6e90\u65f6\uff0c\u5b83\u5c06\u5f00\u59cb\u521b\u5efa AWS \u8d44\u6e90\u3002AWS \u5c06\u5e94\u7528\u7a0b\u5e8f\u8d1f\u8f7d\u5e73\u8861\u5668 (ALB)  (2) \u7528\u4e8e Ingress \u8d44\u6e90\u3002\u8d1f\u8f7d\u5747\u8861\u5668\u4e0e\u7528\u4e8e\u5c06\u8bf7\u6c42\u8def\u7531\u5230\u4e00\u4e2a\u6216\u591a\u4e2a\u5df2\u6ce8\u518c\u8282\u70b9\u7684\u76ee\u6807\u7ec4 (Target Groups) \u914d\u5408\u4f7f\u7528\u3002(3) \u5728 AWS \u4e2d\u4e3a Ingress \u8d44\u6e90\u63cf\u8ff0\u7684\u6bcf\u4e2a\u552f\u4e00\u7684 Kubernetes \u670d\u52a1\u521b\u5efa\u76ee\u6807\u7ec4\u3002(4) \u4fa6\u542c\u5668 (Listener) \u662f ALB \u8fdb\u7a0b\uff0c\u5b83\u4f7f\u7528\u60a8\u914d\u7f6e\u7684\u534f\u8bae\u548c\u7aef\u53e3\u68c0\u67e5\u8fde\u63a5\u8bf7\u6c42\u3002Ingress \u63a7\u5236\u5668\u4e3a Ingress \u8d44\u6e90\u6ce8\u91ca\u4e2d\u8be6\u7ec6\u8bf4\u660e\u7684\u6bcf\u4e2a\u7aef\u53e3\u521b\u5efa\u4fa6\u542c\u5668\u3002\u6700\u540e\uff0c\u4e3a Ingress \u8d44\u6e90\u4e2d\u6307\u5b9a\u7684\u6bcf\u4e2a\u8def\u5f84\u521b\u5efa\u76ee\u6807\u7ec4\u89c4\u5219\u3002\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u5c06\u5230\u7279\u5b9a\u8def\u5f84\u7684\u6d41\u91cf\u8def\u7531\u5230\u6b63\u786e\u7684 Kubernetes \u670d\u52a1 (5) \u3002<\/p>\n<h4 id=\"6-2-4-bao-de-sheng-ming-zhou-qi-ingress-dao-service\"><a class=\"zola-anchor\" href=\"#6-2-4-bao-de-sheng-ming-zhou-qi-ingress-dao-service\" aria-label=\"Anchor link for: 6-2-4-bao-de-sheng-ming-zhou-qi-ingress-dao-service\">6.2.4 \u5305\u7684\u751f\u547d\u5468\u671f\uff1aIngress \u5230 Service<\/a><\/h4>\n<p><img src=\"https:\/\/memwey.github.io\/posts\/a-guide-to-the-kubernetes-networking-model\/images\/ingress-to-service.gif\" alt=\"Figure 13\" \/><\/p>\n<p>\u56fe13. \u4ece Ingress \u53d1\u9001\u5230 Service \u7684\u6570\u636e\u5305<\/p>\n<p>\u6d41\u7ecf Ingress \u7684\u6570\u636e\u5305\u7684\u751f\u547d\u5468\u671f\u4e0e LoadBalancer \u7684\u975e\u5e38\u76f8\u4f3c\u3002\u4e3b\u8981\u533a\u522b\u5728\u4e8e\uff0cIngress \u77e5\u9053 URL \u7684\u8def\u5f84 (\u5141\u8bb8\u5e76\u53ef\u4ee5\u6839\u636e\u670d\u52a1\u7684\u8def\u5f84\u5c06\u6d41\u91cf\u8def\u7531\u5230\u670d\u52a1) \uff0c\u5e76\u4e14 Ingress \u548c Node \u4e4b\u95f4\u7684\u521d\u59cb\u8fde\u63a5\u662f\u901a\u8fc7\u4e3a\u6bcf\u4e2a\u670d\u52a1\u5728 Node \u4e0a\u66b4\u9732\u7684\u7aef\u53e3\u8fdb\u884c\u7684\u3002<\/p>\n<p>\u8ba9\u6211\u4eec\u770b\u770b\u8fd9\u5728\u5b9e\u8df5\u4e2d\u662f\u5982\u4f55\u5de5\u4f5c\u7684\u3002\u90e8\u7f72\u670d\u52a1\u540e\uff0c\u60a8\u6b63\u5728\u4f7f\u7528\u7684\u4e91\u63d0\u4f9b\u5546\u5c06\u4e3a\u60a8\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 Ingress \u8d1f\u8f7d\u5747\u8861\u5668 (1) \u3002\u7531\u4e8e\u8d1f\u8f7d\u5e73\u8861\u5668\u4e0d\u611f\u77e5\u5bb9\u5668\uff0c\u56e0\u6b64\uff0c\u4e00\u65e6\u6d41\u91cf\u5230\u8fbe\u8d1f\u8f7d\u5e73\u8861\u5668\uff0c\u5b83\u5c06\u901a\u8fc7\u4e3a\u60a8\u7684\u670d\u52a1\u901a\u544a\u7684\u7aef\u53e3\u5728\u7ec4\u6210\u60a8\u7684\u7fa4\u96c6 (2) \u7684\u6240\u6709 VM \u4e2d\u8fdb\u884c\u5206\u914d\u3002\u5982\u524d\u6240\u8ff0\uff0c\u6bcf\u4e2a VM \u4e0a\u7684 iptables \u89c4\u5219\u4f1a\u5c06\u6765\u81ea\u8d1f\u8f7d\u5747\u8861\u5668\u7684\u4f20\u5165\u6d41\u91cf\u5b9a\u5411\u5230\u6b63\u786e\u7684 Pod (3) \u3002\u4ece Pod \u5230\u5ba2\u6237\u7aef\u7684\u54cd\u5e94\u5c06\u8fd4\u56de Pod \u7684 IP\uff0c\u4f46\u5ba2\u6237\u7aef\u9700\u8981\u5177\u6709\u8d1f\u8f7d\u5747\u8861\u5668\u7684 IP \u5730\u5740\u3002\u5982\u524d\u6240\u8ff0\uff0ciptables \u548c conntrack \u7528\u4e8e\u5728\u8fd4\u56de\u8def\u5f84\u4e0a\u6b63\u786e\u91cd\u5199 IP\u3002<\/p>\n<p>7 \u5c42\u8d1f\u8f7d\u5e73\u8861\u5668\u7684\u4e00\u4e2a\u597d\u5904\u662f\u5b83\u4eec\u53ef\u4ee5\u8bc6\u522b HTTP\uff0c\u56e0\u6b64\u4ed6\u4eec\u77e5\u9053 URL \u548c\u8def\u5f84\u3002\u8fd9\u4f7f\u60a8\u53ef\u4ee5\u6309 URL \u8def\u5f84\u7ec6\u5206\u670d\u52a1\u6d41\u91cf\u3002\u5b83\u4eec\u901a\u5e38\u8fd8\u4f1a\u5728 HTTP \u8bf7\u6c42\u7684 <code>X-Forwarded-For<\/code> \u6807\u5934\u4e2d\u63d0\u4f9b\u539f\u59cb\u5ba2\u6237\u7aef\u7684 IP \u5730\u5740\u3002<\/p>\n<h2 id=\"7-zong-jie\"><a class=\"zola-anchor\" href=\"#7-zong-jie\" aria-label=\"Anchor link for: 7-zong-jie\">7 \u603b\u7ed3<\/a><\/h2>\n<p>\u672c\u6307\u5357\u4e3a\u7406\u89e3 Kubernetes \u7f51\u7edc\u6a21\u578b\u53ca\u5176\u5982\u4f55\u5b9e\u73b0\u5e38\u89c1\u7684\u7f51\u7edc\u4efb\u52a1\u63d0\u4f9b\u4e86\u57fa\u7840\u3002\u7f51\u7edc\u9886\u57df\u65e2\u5e7f\u4e14\u6df1\uff0c\u4e0d\u53ef\u80fd\u5728\u8fd9\u91cc\u6db5\u76d6\u6240\u6709\u5185\u5bb9\u3002\u672c\u6307\u5357\u5e94\u4e3a\u60a8\u63d0\u4f9b\u4e00\u4e2a\u8d77\u70b9\uff0c\u4ee5\u6df1\u5165\u7814\u7a76\u60a8\u611f\u5174\u8da3\u5e76\u5e0c\u671b\u4e86\u89e3\u66f4\u591a\u7684\u4e3b\u9898\u3002\u6bcf\u5f53\u60a8\u9047\u5230\u56f0\u96be\u65f6\uff0c\u8bf7\u5229\u7528 Kubernetes \u6587\u6863\u548c Kubernetes \u793e\u533a\u6765\u5e2e\u52a9\u60a8\u627e\u5230\u65b9\u5411\u3002<\/p>\n<h3 id=\"8-shu-yu-biao\"><a class=\"zola-anchor\" href=\"#8-shu-yu-biao\" aria-label=\"Anchor link for: 8-shu-yu-biao\">8 \u672f\u8bed\u8868<\/a><\/h3>\n<p>Kubernetes \u4f9d\u9760\u51e0\u79cd\u73b0\u6709\u6280\u672f\u6765\u6784\u5efa\u53ef\u8fd0\u884c\u7684\u96c6\u7fa4\u3002\u5168\u9762\u63a2\u7d22\u6bcf\u79cd\u6280\u672f\u4e0d\u5728\u672c\u6307\u5357\u7684\u8ba8\u8bba\u8303\u56f4\u5185\uff0c\u4f46\u662f\u672c\u8282\u5c06\u5bf9\u6bcf\u79cd\u6280\u672f\u8fdb\u884c\u8db3\u591f\u8be6\u7ec6\u7684\u4ecb\u7ecd\uff0c\u4ee5\u4f9b\u8ba8\u8bba\u65f6\u53c2\u8003\u3002\u60a8\u53ef\u4ee5\u968f\u610f\u6d4f\u89c8\u672c\u8282\uff0c\u5b8c\u5168\u8df3\u8fc7\u672c\u8282\uff0c\u6216\u8005\u5728\u611f\u5230\u56f0\u60d1\u6216\u9700\u8981\u590d\u4e60\u65f6\u6839\u636e\u9700\u8981\u53c2\u8003\u3002<\/p>\n<h3 id=\"2ceng-wang-luo-layer-2-networking\"><a class=\"zola-anchor\" href=\"#2ceng-wang-luo-layer-2-networking\" aria-label=\"Anchor link for: 2ceng-wang-luo-layer-2-networking\">2\u5c42\u7f51\u7edc (Layer 2 Networking)<\/a><\/h3>\n<p>\u7b2c 2 \u5c42\u662f\u63d0\u4f9b\u8282\u70b9\u5230\u8282\u70b9\u6570\u636e\u4f20\u8f93\u7684\u6570\u636e\u94fe\u8def\u5c42\u3002\u5b83\u5b9a\u4e49\u4e86\u5728\u4e24\u4e2a\u7269\u7406\u8fde\u63a5\u7684\u8bbe\u5907\u4e4b\u95f4\u5efa\u7acb\u548c\u7ec8\u6b62\u8fde\u63a5\u7684\u534f\u8bae\uff0c\u4ee5\u53ca\u5b83\u4eec\u4e4b\u95f4\u7684\u6d41\u91cf\u63a7\u5236\u534f\u8bae\u3002<\/p>\n<h3 id=\"4ceng-wang-luo-layer-4-networking\"><a class=\"zola-anchor\" href=\"#4ceng-wang-luo-layer-4-networking\" aria-label=\"Anchor link for: 4ceng-wang-luo-layer-4-networking\">4\u5c42\u7f51\u7edc (Layer 4 Networking)<\/a><\/h3>\n<p>\u4f20\u8f93\u5c42\u901a\u8fc7\u6d41\u91cf\u63a7\u5236\u6765\u63a7\u5236\u7ed9\u5b9a\u94fe\u63a5\u7684\u53ef\u9760\u6027\u3002\u5728 TCP\/IP \u4e2d\uff0c\u8be5\u5c42\u6307\u7684\u662f\u7528\u4e8e\u5728\u4e0d\u53ef\u9760\u7f51\u7edc\u4e0a\u4ea4\u6362\u6570\u636e\u7684 TCP \u534f\u8bae\u3002<\/p>\n<h3 id=\"7ceng-wang-luo-layer-7-networking\"><a class=\"zola-anchor\" href=\"#7ceng-wang-luo-layer-7-networking\" aria-label=\"Anchor link for: 7ceng-wang-luo-layer-7-networking\">7\u5c42\u7f51\u7edc (Layer 7 Networking)<\/a><\/h3>\n<p>\u5e94\u7528\u5c42\u662f\u79bb\u6700\u7ec8\u7528\u6237\u6700\u8fd1\u7684\u5c42\uff0c\u8fd9\u610f\u5473\u7740\u5e94\u7528\u5c42\u548c\u7528\u6237\u90fd\u76f4\u63a5\u4e0e\u8f6f\u4ef6\u5e94\u7528\u7a0b\u5e8f\u4ea4\u4e92\u3002\u8be5\u5c42\u4e0e\u5b9e\u73b0\u901a\u4fe1\u7ec4\u4ef6\u7684\u8f6f\u4ef6\u5e94\u7528\u7a0b\u5e8f\u4ea4\u4e92\u3002\u901a\u5e38\uff0c7 \u5c42\u7f51\u7edc\u6307\u7684\u662f HTTP\u3002<\/p>\n<h3 id=\"nat-wang-luo-di-zhi-zhuan-huan-network-address-translation\"><a class=\"zola-anchor\" href=\"#nat-wang-luo-di-zhi-zhuan-huan-network-address-translation\" aria-label=\"Anchor link for: nat-wang-luo-di-zhi-zhuan-huan-network-address-translation\">NAT \u2014 \u7f51\u7edc\u5730\u5740\u8f6c\u6362 (Network Address Translation)<\/a><\/h3>\n<p>NAT \u6216\u7f51\u7edc\u5730\u5740\u8f6c\u6362\u662f\u5c06\u4e00\u4e2a\u5730\u5740\u7a7a\u95f4 IP \u7ea7\u522b\u5730\u91cd\u65b0\u6620\u5c04\u5230\u53e6\u4e00\u4e2a\u5730\u5740\u7a7a\u95f4\u3002\u8be5\u6620\u5c04\u901a\u8fc7\u5728\u6570\u636e\u5305\u5728\u6d41\u91cf\u8def\u7531\u8bbe\u5907\u4e2d\u4f20\u8f93\u65f6\u4fee\u6539\u5176 IP \u5934\u4e2d\u7684\u7f51\u7edc\u5730\u5740\u4fe1\u606f\u6765\u5b9e\u73b0\u3002<\/p>\n<p>\u57fa\u672c\u7684 NAT \u662f\u4ece\u4e00\u4e2a IP \u5730\u5740\u5230\u53e6\u4e00\u4e2a IP \u5730\u5740\u7684\u7b80\u5355\u6620\u5c04\u3002\u66f4\u5e38\u89c1\u7684\u662f\uff0cNAT \u7528\u4e8e\u5c06\u591a\u4e2a\u79c1\u6709 IP \u5730\u5740\u6620\u5c04\u5230\u4e00\u4e2a\u516c\u5171\u66b4\u9732\u7684 IP \u5730\u5740\u3002\u901a\u5e38\uff0c\u672c\u5730\u7f51\u7edc\u4f7f\u7528\u79c1\u6709 IP \u5730\u5740\u7a7a\u95f4\uff0c\u8be5\u7f51\u7edc\u4e0a\u7684\u8def\u7531\u5668\u5728\u8be5\u7a7a\u95f4\u4e2d\u88ab\u8d4b\u4e88\u4e00\u4e2a\u79c1\u6709\u5730\u5740\u3002\u7136\u540e\uff0c\u8be5\u8def\u7531\u5668\u901a\u8fc7\u4e00\u4e2a\u516c\u5171 IP \u5730\u5740\u8fde\u63a5\u5230 Internet\u3002\u5f53\u6d41\u91cf\u4ece\u672c\u5730\u7f51\u7edc\u4f20\u9012\u5230 Internet \u65f6\uff0c\u6bcf\u4e2a\u6570\u636e\u5305\u7684\u6e90\u5730\u5740\u4ece\u79c1\u6709\u5730\u5740\u8f6c\u6362\u4e3a\u516c\u5171\u5730\u5740\uff0c\u4f7f\u5176\u770b\u8d77\u6765\u597d\u50cf\u8bf7\u6c42\u76f4\u63a5\u6765\u81ea\u8def\u7531\u5668\u3002\u8def\u7531\u5668\u7ef4\u62a4\u8fde\u63a5\u8ddf\u8e2a\uff0c\u4ee5\u5c06\u56de\u590d\u8f6c\u53d1\u5230\u672c\u5730\u7f51\u7edc\u4e0a\u6b63\u786e\u7684\u79c1\u6709 IP\u3002<\/p>\n<p>NAT \u63d0\u4f9b\u4e86\u4e00\u4e2a\u989d\u5916\u7684\u597d\u5904\uff0c\u5373\u5141\u8bb8\u5927\u578b\u79c1\u6709\u7f51\u7edc\u4f7f\u7528\u5355\u4e2a\u516c\u5171 IP \u5730\u5740\u8fde\u63a5\u5230 Internet\uff0c\u4ece\u800c\u8282\u7701\u4e86\u516c\u5171\u4f7f\u7528\u7684 IP \u5730\u5740\u6570\u91cf\u3002<\/p>\n<h3 id=\"snat-yuan-wang-luo-di-zhi-zhuan-huan-source-network-address-translation\"><a class=\"zola-anchor\" href=\"#snat-yuan-wang-luo-di-zhi-zhuan-huan-source-network-address-translation\" aria-label=\"Anchor link for: snat-yuan-wang-luo-di-zhi-zhuan-huan-source-network-address-translation\">SNAT \u2014 \u6e90\u7f51\u7edc\u5730\u5740\u8f6c\u6362 (Source Network Address Translation)<\/a><\/h3>\n<p>SNAT \u4ec5\u6307\u4fee\u6539 IP \u6570\u636e\u5305\u6e90\u5730\u5740\u7684 NAT \u8fc7\u7a0b\u3002\u8fd9\u662f\u4e0a\u8ff0 NAT \u7684\u5178\u578b\u884c\u4e3a\u3002<\/p>\n<h3 id=\"dnat-mu-de-wang-luo-di-zhi-zhuan-huan-destination-network-address-translation\"><a class=\"zola-anchor\" href=\"#dnat-mu-de-wang-luo-di-zhi-zhuan-huan-destination-network-address-translation\" aria-label=\"Anchor link for: dnat-mu-de-wang-luo-di-zhi-zhuan-huan-destination-network-address-translation\">DNAT \u2014 \u76ee\u7684\u7f51\u7edc\u5730\u5740\u8f6c\u6362 (Destination Network Address Translation)<\/a><\/h3>\n<p>DNAT \u6307\u4fee\u6539 IP \u6570\u636e\u5305\u76ee\u7684\u5730\u5740\u7684 NAT \u8fc7\u7a0b\u3002DNAT \u7528\u4e8e\u5c06\u4f4d\u4e8e\u79c1\u6709\u7f51\u7edc\u4e2d\u7684\u670d\u52a1\u53d1\u5e03\u5230\u53ef\u516c\u5f00\u5bfb\u5740\u7684 IP \u5730\u5740\u3002<\/p>\n<h3 id=\"wang-luo-ming-ming-kong-jian-network-namespace\"><a class=\"zola-anchor\" href=\"#wang-luo-ming-ming-kong-jian-network-namespace\" aria-label=\"Anchor link for: wang-luo-ming-ming-kong-jian-network-namespace\">\u7f51\u7edc\u547d\u540d\u7a7a\u95f4 (Network Namespace)<\/a><\/h3>\n<p>\u5728\u7f51\u7edc\u4e2d\uff0c\u6bcf\u53f0\u673a\u5668 (\u771f\u5b9e\u7684\u6216\u865a\u62df\u7684) \u90fd\u6709\u4e00\u4e2a\u4ee5\u592a\u7f51\u8bbe\u5907 (\u6211\u4eec\u79f0\u4e4b\u4e3a eth0) \u3002\u6240\u6709\u8fdb\u51fa\u673a\u5668\u7684\u6d41\u91cf\u90fd\u4e0e\u8be5\u8bbe\u5907\u76f8\u5173\u8054\u3002\u5b9e\u9645\u4e0a\uff0cLinux \u5c06\u6bcf\u4e2a\u4ee5\u592a\u7f51\u8bbe\u5907\u4e0e\u4e00\u4e2a\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\u76f8\u5173\u8054\u2014\u2014\u8fd9\u662f\u6574\u4e2a\u7f51\u7edc\u5806\u6808\u7684\u903b\u8f91\u526f\u672c\uff0c\u62e5\u6709\u81ea\u5df1\u7684\u8def\u7531\u3001\u9632\u706b\u5899\u89c4\u5219\u548c\u7f51\u7edc\u8bbe\u5907\u3002\u6700\u521d\uff0c\u6240\u6709\u8fdb\u7a0b\u90fd\u4ece init \u8fdb\u7a0b\u5171\u4eab\u76f8\u540c\u7684\u9ed8\u8ba4\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\uff0c\u79f0\u4e3a\u6839\u547d\u540d\u7a7a\u95f4\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u8fdb\u7a0b\u4ece\u5176\u7236\u8fdb\u7a0b\u7ee7\u627f\u5176\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\uff0c\u56e0\u6b64\uff0c\u5982\u679c\u60a8\u4e0d\u505a\u4efb\u4f55\u66f4\u6539\uff0c\u6240\u6709\u7f51\u7edc\u6d41\u91cf\u90fd\u5c06\u901a\u8fc7\u4e3a\u6839\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\u6307\u5b9a\u7684\u4ee5\u592a\u7f51\u8bbe\u5907\u6d41\u52a8\u3002<\/p>\n<h3 id=\"veth-xu-ni-yi-tai-wang-she-bei-dui-virtual-ethernet-device-pairs\"><a class=\"zola-anchor\" href=\"#veth-xu-ni-yi-tai-wang-she-bei-dui-virtual-ethernet-device-pairs\" aria-label=\"Anchor link for: veth-xu-ni-yi-tai-wang-she-bei-dui-virtual-ethernet-device-pairs\">veth \u2014 \u865a\u62df\u4ee5\u592a\u7f51\u8bbe\u5907\u5bf9 (Virtual Ethernet Device Pairs)<\/a><\/h3>\n<p>\u8ba1\u7b97\u673a\u7cfb\u7edf\u901a\u5e38\u7531\u4e00\u4e2a\u6216\u591a\u4e2a\u7f51\u7edc\u8bbe\u5907 (eth0\uff0ceth1 \u7b49) \u7ec4\u6210\uff0c\u8fd9\u4e9b\u8bbe\u5907\u4e0e\u8d1f\u8d23\u5c06\u6570\u636e\u5305\u653e\u7f6e\u5230\u7269\u7406\u7ebf\u8def\u4e0a\u7684\u7269\u7406\u7f51\u7edc\u9002\u914d\u5668\u76f8\u5173\u8054\u3002Veth \u8bbe\u5907\u662f\u59cb\u7ec8\u4ee5\u4e92\u8fde\u5bf9\u5f62\u5f0f\u521b\u5efa\u7684\u865a\u62df\u7f51\u7edc\u8bbe\u5907\u3002\u5b83\u4eec\u53ef\u4ee5\u5145\u5f53\u7f51\u7edc\u547d\u540d\u7a7a\u95f4\u4e4b\u95f4\u7684\u96a7\u9053\uff0c\u4ee5\u521b\u5efa\u5230\u53e6\u4e00\u4e2a\u547d\u540d\u7a7a\u95f4\u4e2d\u7269\u7406\u7f51\u7edc\u8bbe\u5907\u7684\u6865\u6881\uff0c\u4f46\u4e5f\u53ef\u4ee5\u7528\u4f5c\u72ec\u7acb\u7684\u7f51\u7edc\u8bbe\u5907\u3002\u60a8\u53ef\u4ee5\u5c06 veth \u8bbe\u5907\u89c6\u4e3a\u8bbe\u5907\u4e4b\u95f4\u7684\u865a\u62df\u8df3\u7ebf\u2014\u2014\u4e00\u7aef\u8fdb\u53bb\u7684\u4e1c\u897f\u4f1a\u4ece\u53e6\u4e00\u7aef\u51fa\u6765\u3002<\/p>\n<h3 id=\"bridge-wang-luo-wang-qiao-network-bridge\"><a class=\"zola-anchor\" href=\"#bridge-wang-luo-wang-qiao-network-bridge\" aria-label=\"Anchor link for: bridge-wang-luo-wang-qiao-network-bridge\">bridge \u2014 \u7f51\u7edc\u7f51\u6865 (Network Bridge)<\/a><\/h3>\n<p>\u7f51\u7edc\u7f51\u6865\u662f\u4e00\u79cd\u4ece\u591a\u4e2a\u901a\u4fe1\u7f51\u7edc\u6216\u7f51\u6bb5\u521b\u5efa\u5355\u4e2a\u805a\u5408\u7f51\u7edc\u7684\u8bbe\u5907\u3002\u6865\u63a5\u5c06\u4e24\u4e2a\u72ec\u7acb\u7684\u7f51\u7edc\u8fde\u63a5\u8d77\u6765\uff0c\u5c31\u597d\u50cf\u5b83\u4eec\u662f\u4e00\u4e2a\u5355\u4e00\u7684\u7f51\u7edc\u4e00\u6837\u3002\u6865\u63a5\u4f7f\u7528\u5185\u90e8\u6570\u636e\u7ed3\u6784\u6765\u8bb0\u5f55\u6bcf\u4e2a\u6570\u636e\u5305\u53d1\u9001\u5230\u7684\u4f4d\u7f6e\uff0c\u4f5c\u4e3a\u6027\u80fd\u4f18\u5316\u3002<\/p>\n<h3 id=\"cidr-wu-lei-bie-yu-jian-lu-you-classless-inter-domain-routing\"><a class=\"zola-anchor\" href=\"#cidr-wu-lei-bie-yu-jian-lu-you-classless-inter-domain-routing\" aria-label=\"Anchor link for: cidr-wu-lei-bie-yu-jian-lu-you-classless-inter-domain-routing\">CIDR \u2014 \u65e0\u7c7b\u522b\u57df\u95f4\u8def\u7531 (Classless Inter-Domain Routing)<\/a><\/h3>\n<p>CIDR \u662f\u4e00\u79cd\u5206\u914d IP \u5730\u5740\u548c\u6267\u884c IP \u8def\u7531\u7684\u65b9\u6cd5\u3002\u4f7f\u7528 CIDR\uff0cIP \u5730\u5740\u7531\u4e24\u7ec4\u7ec4\u6210\uff1a\u7f51\u7edc\u524d\u7f00 (\u6807\u8bc6\u6574\u4e2a\u7f51\u7edc\u6216\u5b50\u7f51) \u548c\u4e3b\u673a\u6807\u8bc6\u7b26 (\u6307\u5b9a\u8be5\u7f51\u7edc\u6216\u5b50\u7f51\u4e0a\u4e3b\u673a\u7684\u7279\u5b9a\u63a5\u53e3) \u3002CIDR \u4f7f\u7528 CIDR \u8868\u793a\u6cd5\u8868\u793a IP \u5730\u5740\uff0c\u5176\u4e2d\u5730\u5740\u6216\u8def\u7531\u524d\u7f00\u5e26\u6709\u4e00\u4e2a\u540e\u7f00\uff0c\u6307\u793a\u524d\u7f00\u7684\u4f4d\u6570\uff0c\u4f8b\u5982 IPv4 \u7684 192.0.2.0\/24\u3002IP \u5730\u5740\u662f CIDR \u5757\u7684\u4e00\u90e8\u5206\uff0c\u5982\u679c\u5730\u5740\u7684\u521d\u59cb n \u4f4d\u4e0e CIDR \u524d\u7f00\u76f8\u540c\uff0c\u5219\u79f0\u5176\u5c5e\u4e8e\u8be5 CIDR \u5757\u3002<\/p>\n<h3 id=\"cni-rong-qi-wang-luo-jie-kou-container-network-interface\"><a class=\"zola-anchor\" href=\"#cni-rong-qi-wang-luo-jie-kou-container-network-interface\" aria-label=\"Anchor link for: cni-rong-qi-wang-luo-jie-kou-container-network-interface\">CNI \u2014 \u5bb9\u5668\u7f51\u7edc\u63a5\u53e3 (Container Network Interface)<\/a><\/h3>\n<p>CNI (\u5bb9\u5668\u7f51\u7edc\u63a5\u53e3) \u662f\u4e91\u539f\u751f\u8ba1\u7b97\u57fa\u91d1\u4f1a (Cloud Native Computing Foundation) \u7684\u4e00\u4e2a\u9879\u76ee\uff0c\u7531\u4e00\u4e2a\u89c4\u8303\u548c\u7528\u4e8e\u7f16\u5199\u63d2\u4ef6\u4ee5\u5728 Linux \u5bb9\u5668\u4e2d\u914d\u7f6e\u7f51\u7edc\u63a5\u53e3\u7684\u5e93\u7ec4\u6210\u3002CNI \u53ea\u5173\u5fc3\u5bb9\u5668\u7684\u7f51\u7edc\u8fde\u63a5\u6027\u4ee5\u53ca\u5728\u5bb9\u5668\u88ab\u5220\u9664\u65f6\u79fb\u9664\u5df2\u5206\u914d\u7684\u8d44\u6e90\u3002<\/p>\n<h3 id=\"vip-xu-ni-ip-di-zhi-virtual-ip-address\"><a class=\"zola-anchor\" href=\"#vip-xu-ni-ip-di-zhi-virtual-ip-address\" aria-label=\"Anchor link for: vip-xu-ni-ip-di-zhi-virtual-ip-address\">VIP \u2014 \u865a\u62df IP \u5730\u5740 (Virtual IP Address)<\/a><\/h3>\n<p>\u865a\u62df IP \u5730\u5740 (VIP) \u662f\u4e00\u79cd\u8f6f\u4ef6\u5b9a\u4e49\u7684 IP \u5730\u5740\uff0c\u4e0d\u5bf9\u5e94\u4e8e\u5b9e\u9645\u7684\u7269\u7406\u7f51\u7edc\u63a5\u53e3\u3002<\/p>\n<h3 id=\"netfilter-linux-de-bao-guo-lu-kuang-jia\"><a class=\"zola-anchor\" href=\"#netfilter-linux-de-bao-guo-lu-kuang-jia\" aria-label=\"Anchor link for: netfilter-linux-de-bao-guo-lu-kuang-jia\">netfilter \u2014 Linux \u7684\u5305\u8fc7\u6ee4\u6846\u67b6<\/a><\/h3>\n<p>netfilter \u662f Linux \u4e2d\u7684\u6570\u636e\u5305\u8fc7\u6ee4\u6846\u67b6\u3002\u5b9e\u73b0\u6b64\u6846\u67b6\u7684\u8f6f\u4ef6\u8d1f\u8d23\u6570\u636e\u5305\u8fc7\u6ee4\u3001\u7f51\u7edc\u5730\u5740\u8f6c\u6362 (NAT) \u548c\u5176\u4ed6\u6570\u636e\u5305\u5904\u7406\u3002<\/p>\n<p>netfilter\u3001ip_tables\u3001\u8fde\u63a5\u8ddf\u8e2a (ip_conntrack, nf_conntrack) \u548c NAT \u5b50\u7cfb\u7edf\u5171\u540c\u6784\u6210\u4e86\u8be5\u6846\u67b6\u7684\u4e3b\u8981\u90e8\u5206\u3002<\/p>\n<h3 id=\"iptables-bao-chu-li-gong-ju\"><a class=\"zola-anchor\" href=\"#iptables-bao-chu-li-gong-ju\" aria-label=\"Anchor link for: iptables-bao-chu-li-gong-ju\">iptables \u2014 \u5305\u5904\u7406\u5de5\u5177<\/a><\/h3>\n<p>iptables \u662f\u4e00\u4e2a\u5141\u8bb8 Linux \u7cfb\u7edf\u7ba1\u7406\u5458\u914d\u7f6e netfilter \u53ca\u5176\u5b58\u50a8\u7684\u94fe\u548c\u89c4\u5219\u7684\u7a0b\u5e8f\u3002IP \u8868\u4e2d\u7684\u6bcf\u4e2a\u89c4\u5219\u90fd\u7531\u591a\u4e2a\u5206\u7c7b\u5668 (iptables \u5339\u914d) \u548c\u4e00\u4e2a\u8fde\u63a5\u7684\u52a8\u4f5c (iptables \u76ee\u6807) \u7ec4\u6210\u3002<\/p>\n<h3 id=\"conntrack-lian-jie-gen-zong\"><a class=\"zola-anchor\" href=\"#conntrack-lian-jie-gen-zong\" aria-label=\"Anchor link for: conntrack-lian-jie-gen-zong\">conntrack \u2014 \u8fde\u63a5\u8ddf\u8e2a<\/a><\/h3>\n<p>conntrack \u662f\u5efa\u7acb\u5728 Netfilter \u6846\u67b6\u4e4b\u4e0a\u7684\u7528\u4e8e\u5904\u7406\u8fde\u63a5\u8ddf\u8e2a\u7684\u5de5\u5177\u3002\u8fde\u63a5\u8ddf\u8e2a\u5141\u8bb8\u5185\u6838\u8ddf\u8e2a\u6240\u6709\u903b\u8f91\u7f51\u7edc\u8fde\u63a5\u6216\u4f1a\u8bdd\uff0c\u5e76\u5c06\u6bcf\u4e2a\u8fde\u63a5\u6216\u4f1a\u8bdd\u7684\u6570\u636e\u5305\u5b9a\u5411\u5230\u6b63\u786e\u7684\u53d1\u9001\u65b9\u6216\u63a5\u6536\u65b9\u3002NAT \u4f9d\u8d56\u6b64\u4fe1\u606f\u4ee5\u76f8\u540c\u7684\u65b9\u5f0f\u8f6c\u6362\u6240\u6709\u76f8\u5173\u6570\u636e\u5305\uff0c\u800c iptables \u53ef\u4ee5\u4f7f\u7528\u6b64\u4fe1\u606f\u5145\u5f53\u6709\u72b6\u6001\u7684\u9632\u706b\u5899\u3002<\/p>\n<h3 id=\"ipvs-ip-xu-ni-fu-wu-qi-ip-virtual-server\"><a class=\"zola-anchor\" href=\"#ipvs-ip-xu-ni-fu-wu-qi-ip-virtual-server\" aria-label=\"Anchor link for: ipvs-ip-xu-ni-fu-wu-qi-ip-virtual-server\">IPVS \u2014 IP \u865a\u62df\u670d\u52a1\u5668 (IP Virtual Server)<\/a><\/h3>\n<p>IPVS \u4f5c\u4e3a Linux \u5185\u6838\u7684\u4e00\u90e8\u5206\u5b9e\u73b0\u4f20\u8f93\u5c42\u8d1f\u8f7d\u5747\u8861\u3002<\/p>\n<p>IPVS \u662f\u4e00\u4e2a\u7c7b\u4f3c\u4e8e iptables \u7684\u5de5\u5177\u3002\u5b83\u57fa\u4e8e Linux \u5185\u6838\u7684 netfilter \u94a9\u5b50\u51fd\u6570\uff0c\u4f46\u4f7f\u7528\u54c8\u5e0c\u8868\u4f5c\u4e3a\u5e95\u5c42\u6570\u636e\u7ed3\u6784\u3002\u8fd9\u610f\u5473\u7740\uff0c\u4e0e iptables \u76f8\u6bd4\uff0cIPVS \u91cd\u5b9a\u5411\u6d41\u91cf\u7684\u901f\u5ea6\u8981\u5feb\u5f97\u591a\uff0c\u5728\u540c\u6b65\u4ee3\u7406\u89c4\u5219\u65f6\u6027\u80fd\u8981\u597d\u5f97\u591a\uff0c\u5e76\u63d0\u4f9b\u66f4\u591a\u7684\u8d1f\u8f7d\u5747\u8861\u7b97\u6cd5\u3002<\/p>\n<h3 id=\"dns-yu-ming-xi-tong-the-domain-name-system\"><a class=\"zola-anchor\" href=\"#dns-yu-ming-xi-tong-the-domain-name-system\" aria-label=\"Anchor link for: dns-yu-ming-xi-tong-the-domain-name-system\">DNS \u2014 \u57df\u540d\u7cfb\u7edf (The Domain Name System)<\/a><\/h3>\n<p>\u57df\u540d\u7cfb\u7edf (DNS) \u662f\u4e00\u79cd\u7528\u4e8e\u5c06\u7cfb\u7edf\u540d\u79f0\u4e0e IP \u5730\u5740\u5173\u8054\u7684\u5206\u6563\u5f0f\u547d\u540d\u7cfb\u7edf\u3002\u5b83\u5c06\u57df\u540d\u8f6c\u6362\u4e3a\u6570\u5b57 IP \u5730\u5740\uff0c\u4ee5\u4fbf\u5b9a\u4f4d\u8ba1\u7b97\u673a\u670d\u52a1\u3002<\/p>\n"},{"title":"Oh MySQL Emoji","published":"2019-10-14T11:12:33+08:00","updated":"2019-10-14T11:12:33+08:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/oh-mysql-emoji\/"}},"id":"https:\/\/memwey.github.io\/posts\/oh-mysql-emoji\/","content":"<p>\u53c8\u662f\u5173\u4e8e <code>MySQL<\/code> \u7684, \u6807\u9898\u6765\u81ea\u4e8e &lt;\u8f6e\u5230\u4f60\u4e86&gt; \u8fd9\u90e8<del>\u70c2\u5c3e<\/del>\u65e5\u5267, \u91cc\u9762\u975e\u5e38\u9b54\u6027\u7684 Oh~my~Ju~lia~<\/p>\n<p>\u5728MySQL\u91cc\u9762\u5982\u4f55\u4fdd\u5b58 <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Emoji\">Emoji<\/a>, \u8fd9\u4e2a\u95ee\u9898\u641c\u4e00\u641c\u5f88\u5bb9\u6613\u627e\u5230\u7b54\u6848, \u8bbe\u7f6e <strong>CHARSET<\/strong> \u4e3a <code>utf8mb4<\/code>, \u770b\u6765\u5929\u4e0b\u82e6 <code>MySQL<\/code> \u4e45\u77e3.<\/p>\n<h2 id=\"ji-chu-zhi-shi\"><a class=\"zola-anchor\" href=\"#ji-chu-zhi-shi\" aria-label=\"Anchor link for: ji-chu-zhi-shi\">\u57fa\u7840\u77e5\u8bc6<\/a><\/h2>\n<p>\u8ba1\u7b97\u673a\u6700\u65e9\u662f\u7f8e\u56fd\u4eba\u53d1\u660e\u7684, \u90a3\u65f6\u7684\u7f16\u7801\u90fd\u662f <code>ASCII<\/code> \u7801, \u6bd5\u7adf\u82f1\u6587\u5b57\u7b26\u52a0\u4e0a\u6807\u70b9\u7b26\u53f7\u4e5f\u5c31\u90a3\u4e48\u591a\u561b, \u4e00\u4e2a\u5b57\u8282\u7ef0\u7ef0\u6709\u4f59.<\/p>\n<p>\u4f46\u662f\u968f\u7740\u8ba1\u7b97\u673a\u7684\u53d1\u5c55, \u8ba1\u7b97\u673a\u9762\u5411\u7684\u56fd\u5bb6\u548c\u8bed\u8a00\u8d8a\u6765\u8d8a\u591a, \u4e00\u4e2a\u5b57\u8282\u6839\u672c\u4e0d\u591f\u7528\u4e86, \u4e8e\u662f\u5c31\u6709\u4e86\u5f88\u591a\u9762\u5411\u7279\u5b9a\u8bed\u8a00\u7684\u7f16\u7801, \u6bd4\u5982\u6c49\u5b57\u7684<code>GBK<\/code>, <code>Big5<\/code>, \u97e9\u6587\u7684 <code>EUC-KR<\/code>, \u65e5\u6587\u7684 <code>Shift_JIS<\/code> \u4ec0\u4e48\u7684. \u603b\u4f53\u601d\u60f3\u662f, \u65e2\u7136\u4e00\u4e2a\u5b57\u8282\u4e0d\u591f\u7528, \u90a3\u5c31\u591a\u51e0\u4e2a\u5b57\u8282\u5c31\u662f\u4e86\u561b.<\/p>\n<p>\u4f46\u662f\u95ee\u9898\u53c8\u51fa\u73b0\u4e86, \u540c\u4e00\u4e2a\u7f16\u7801\u5728\u4e0d\u540c\u8bed\u8a00\u4e2d\u4f1a\u6709\u4e0d\u540c\u7684\u542b\u4e49,\u6bd4\u5982\u97e9\u6587\u7f16\u7801 <code>EUC-KR<\/code> \u4e2d <code>\ud55c\uad6d\uc5b4<\/code> \u7684\u7f16\u7801\u503c\u6b63\u597d\u5bf9\u5e94\u7740\u6c49\u5b57\u7f16\u7801 <code>GBK<\/code> \u4e2d\u7684 <code>\u8304\u60eb\u7ee2<\/code>. \u8fd8\u6709\u90a3\u4e2a\u8457\u540d\u7684 <code>\u74e3B\u53d8\u5de8\u809a<\/code>, \u4e5f\u6b63\u662f\u540c\u6837\u7684\u539f\u56e0. \u8fd9\u6837\u4eff\u4f5b\u5c31\u53d8\u6210\u4e86\u5df4\u522b\u5854\u7684\u6545\u4e8b. \u4eba\u4eec\u867d\u7136\u7528\u7740\u540c\u6837\u7684\u4e8c\u8fdb\u5236\u7f16\u7801, \u4f46\u662f\u5374\u8868\u8fbe\u7740\u4e0d\u540c\u7684\u610f\u601d; \u5c31\u50cf\u4eba\u4eec\u867d\u7136\u540c\u6837\u53d1\u51fa\u58f0\u5e26\u7684\u9707\u52a8, \u4f46\u662f\u5374\u65e0\u6cd5\u4e92\u76f8\u7406\u89e3\u5bf9\u65b9\u7684\u8bdd\u8bed.<\/p>\n<p><a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/International_Organization_for_Standardization\">\u56fd\u9645\u6807\u51c6\u5316\u7ec4\u7ec7<\/a> \u548c <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Unicode_Consortium\">\u7edf\u4e00\u7801\u8054\u76df<\/a> \u610f\u8bc6\u5230, \u8fd9\u6837\u4e0b\u53bb\u662f\u4e0d\u884c\u7684, \u4e0d\u5982\u641e\u4e00\u4e2a\u8d85\u5927\u7684\u5b57\u7b26\u96c6, \u7136\u540e\u628a\u4eba\u7c7b\u6240\u6709\u5b57\u7b26\u90fd\u5f04\u8fdb\u53bb, \u8fd9\u6837\u4eba\u7c7b\u90fd\u53ef\u4ee5\u7528\u540c\u4e00\u4e2a\u6807\u51c6\u4e86. \u4e8e\u662f, \u4ed6\u4eec\u5206\u522b\u5236\u5b9a\u4e86 <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Universal_Coded_Character_Set\">USC<\/a> \u548c <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Unicode\">Unicode<\/a>. \u5f53\u7136, \u5982\u679c\u4e24\u4e2a\u6807\u51c6\u5404\u641e\u5404\u7684, \u90a3\u5c31\u548c\u4ed6\u4eec\u6700\u521d\u7684\u60f3\u6cd5\u80cc\u9053\u800c\u9a70\u4e86, \u6240\u4ee5\u76ee\u524d\u8fd9\u4e24\u4e2a\u5b57\u7b26\u96c6\u5728\u5b9e\u9645\u4f7f\u7528\u4e2d\u662f\u4e00\u81f4\u7684. \u4e00\u822c\u8fd8\u662f\u628a\u8fd9\u4e2a\u5b57\u7b26\u96c6\u53eb <code>Unicode<\/code>.<\/p>\n<p><code>Unicode<\/code> \u7684\u8303\u56f4\u4e0a\u9650\u662f <code>0x10FFFF<\/code>, \u6362\u7b97\u6210\u5341\u8fdb\u5236\u5c31\u662f <code>1,114,111<\/code> \u8fd9\u4e48\u591a. \u6240\u4ee5\u5982\u679c\u4ee5\u540e\u5916\u661f\u4eba\u7684\u6587\u5b57\u592a\u591a, \u8bf4\u4e0d\u5b9a\u8fd9\u4e2a\u8303\u56f4\u5c31\u4e0d\u591f\u4e86.<\/p>\n<p>\u5176\u5b9e\u8fd9\u91cc\u6084\u6084\u7684\u5077\u6362\u4e86\u4e00\u4e2a\u6982\u5ff5, \u4e4b\u524d\u5728\u8bf4\u7f16\u7801, \u73b0\u5728\u53d8\u6210\u4e86\u5b57\u7b26\u96c6\u4e86. \u5728\u5f88\u591a\u4e4b\u524d\u63d0\u5230\u7684\u7f16\u7801\u4e2d, \u8fd9\u4e9b\u7f16\u7801\u65e2\u662f\u5b57\u7b26\u96c6, \u53c8\u662f\u76f4\u63a5\u7684\u7f16\u7801. \u800c\u5728 <code>Unicode<\/code> \u4e2d, \u5b57\u7b26\u96c6\u5b9e\u9645\u4e0a\u662f\u4e0e\u7f16\u7801\u5206\u5f00\u7684\u4e24\u4e2a\u6982\u5ff5, \u800c\u5bf9\u5e94\u7684\u7f16\u7801, \u5b9e\u9645\u4e0a\u5c31\u662f\u6211\u4eec\u7ecf\u5e38\u89c1\u5230\u7684 <code>UTF<\/code>. \u5176\u4e2d <code>UTF-8<\/code> \u662f\u6211\u4eec\u6700\u5e38\u89c1\u7684\u4e00\u79cd\u7f16\u7801\u4e86.<\/p>\n<p><code>UTF-8<\/code> \u6700\u5927\u7684\u7279\u70b9, \u5c31\u662f\u5b83\u662f\u4e00\u79cd\u53d8\u957f\u7684\u7f16\u7801\u65b9\u5f0f, \u800c\u4e14\u5b8c\u5168\u517c\u5bb9 <code>ASCII<\/code>\u7801.<\/p>\n<p><code>UTF-8<\/code> \u7684\u7f16\u7801\u89c4\u5219\u4e5f\u5f88\u7b80\u5355\uff0c\u53ea\u6709\u4e8c\u6761:<\/p>\n<ul>\n<li>\n<p>\u5bf9\u4e8e\u5355\u5b57\u8282\u7684\u7b26\u53f7, \u5b57\u8282\u7684\u7b2c\u4e00\u4f4d\u8bbe\u4e3a<code>0<\/code>, \u540e\u97627\u4f4d\u4e3a\u8fd9\u4e2a\u7b26\u53f7\u7684 Unicode \u7801. \u5bf9\u4e8e <code>0 - 127<\/code> \u4f4d\u7684\u5b57\u7b26\uff0cUTF-8 \u7f16\u7801\u548c ASCII \u7801\u662f\u5b8c\u5168\u76f8\u540c\u7684.<\/p>\n<\/li>\n<li>\n<p>\u5bf9\u4e8e <code>n<\/code> \u5b57\u8282\u7684\u7b26\u53f7 <code>(n &gt; 1)<\/code> , \u7b2c\u4e00\u4e2a\u5b57\u8282\u7684\u524d <code>n<\/code> \u4f4d\u90fd\u8bbe\u4e3a <code>1<\/code>, \u7b2c <code>n + 1<\/code> \u4f4d\u8bbe\u4e3a <code>0<\/code>, \u540e\u9762\u5b57\u8282\u7684\u524d\u4e24\u4f4d\u4e00\u5f8b\u8bbe\u4e3a <code>10<\/code>. \u5269\u4e0b\u7684\u6ca1\u6709\u63d0\u53ca\u7684\u4e8c\u8fdb\u5236\u4f4d, \u5168\u90e8\u4e3a\u8fd9\u4e2a\u7b26\u53f7\u7684 Unicode \u7801.<\/p>\n<\/li>\n<\/ul>\n<table><thead><tr><th>Unicode\u7b26\u53f7\u8303\u56f4<\/th><th>UTF-8\u7f16\u7801\u65b9\u5f0f<\/th><\/tr><\/thead><tbody>\n<tr><td>U+0000 - U+007F<\/td><td>0xxxxxxx<\/td><\/tr>\n<tr><td>U+0080 - U+07FF<\/td><td>110xxxxx 10xxxxxx<\/td><\/tr>\n<tr><td>U+0800 - U+FFFF<\/td><td>1110xxxx 10xxxxxx 10xxxxxx<\/td><\/tr>\n<tr><td>U+010000 - U+10FFFF<\/td><td>11110xxx 10xxxxxx 10xxxxxx 10xxxxxx<\/td><\/tr>\n<\/tbody><\/table>\n<p>\u5728\u8fd9\u91cc\u6211\u4eec\u53d1\u73b0, <code>U+0000 - U+FFFF<\/code> \u8fd9\u4e2a<strong>\u5e73\u9762<\/strong>(Plane), \u5373<strong>\u57fa\u672c\u591a\u6587\u79cd\u5e73\u9762<\/strong>, \u7b80\u79f0 <code>BMP<\/code>, \u7528 <code>UTF-8<\/code> \u8fdb\u884c\u7f16\u7801, \u53ea\u9700\u8981\u4e09\u4e2a\u5b57\u8282.<\/p>\n<h2 id=\"lun-dao-ni-liao\"><a class=\"zola-anchor\" href=\"#lun-dao-ni-liao\" aria-label=\"Anchor link for: lun-dao-ni-liao\">\u8f6e\u5230\u4f60\u4e86<\/a><\/h2>\n<p>\u5728 <code>MySQL<\/code> \u7684 <strong>CHARSET<\/strong> \u4e2d, <code>utf8<\/code> \u652f\u6301\u5b58\u50a8 1 - 3\u5b57\u8282\u7684\u5b57\u7b26, \u5373\u5bf9\u5e94 <code>Unicode<\/code> \u4e2d <code>BMP<\/code> \u7684\u90e8\u5206, \u800c <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Emoji\">Emoji<\/a>, \u5219\u5927\u591a\u6570\u5728 <code>BMP<\/code> \u4e4b\u5916. \u6240\u4ee5 <code>MySQL<\/code> \u4e2d\u7684 <code>utf8<\/code> \u662f\u5047\u7684, \u662f\u5316\u5b66\u7684\u6210\u5206, \u662f\u52a0\u4e86\u7279\u6280\u7684. \u5982\u679c\u60f3\u50a8\u5b58\u771f\u6b63\u7684 <code>UTF-8<\/code> \u7684\u5185\u5bb9, \u5c31\u4e00\u5b9a\u8981\u4f7f\u7528 <code>utf8mb4<\/code>.<\/p>\n<p>\u5f53\u7136, \u5e76\u4e0d\u662f\u6240\u6709\u7684 <a rel=\"external\" href=\"https:\/\/en.wikipedia.org\/wiki\/Emoji\">Emoji<\/a> \u90fd\u5728 <code>BMP<\/code> \u4e4b\u5916, \u6bd4\u5982 \u263a \u8fd9\u4e2a\u8868\u60c5, \u5b83\u7684\u7f16\u7801\u662f <code>U+263A<\/code>, \u8fd8\u6709 \u2639\ufe0f , \u7f16\u7801\u662f <code>U+2639<\/code>.<\/p>\n<p>\u5f53\u7136, \u4e5f\u4e0d\u662f\u6240\u6709\u7684\u6c49\u5b57\u90fd\u88ab\u5305\u542b\u5728\u4e86 <code>BMP<\/code> \u91cc\u9762\u4e86, \u5728 <a rel=\"external\" href=\"https:\/\/www.compart.com\/en\/unicode\/block\">\u8fd9\u91cc<\/a> \u53ef\u4ee5\u770b\u5230\u5b57\u7b26\u662f\u6309\u7167\u4e00\u5b9a\u7684\u89c4\u5f8b\u5212\u5206\u4e3a <code>Block<\/code> \u653e\u8fdb\u6765\u7684, \u5728<strong>\u8868\u610f\u6587\u5b57\u8865\u5145\u5e73\u9762<\/strong>\u4e5f\u5c31\u662f <code>U+20000 - U+2FFFF<\/code> \u8fd9\u4e2a<strong>\u5e73\u9762<\/strong>(Plane), \u8fd8\u662f\u6709\u5f88\u591a <code>CJK<\/code> \u547d\u540d\u7684 <code>Block<\/code> \u7684.<\/p>\n<h2 id=\"zai-lai-yi-ping\"><a class=\"zola-anchor\" href=\"#zai-lai-yi-ping\" aria-label=\"Anchor link for: zai-lai-yi-ping\">\u518d\u6765\u4e00\u74f6<\/a><\/h2>\n<p>\u4f60\u4ee5\u4e3a\u5751\u5230\u8fd9\u91cc\u5c31\u7ed3\u675f\u4e86\u5417<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"sql\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">CREATE<\/span><span class=\"z-l-8 z-d-10\"> TABLE<\/span><span> `<\/span><span class=\"z-l-6 z-d-7\">emoji_test<\/span><span>`<\/span><span> (<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-6\">  `<\/span><span class=\"z-l-2 z-d-6\">id<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-8 z-d-10\"> INT<\/span><span> UNSIGNED <\/span><span class=\"z-l-8 z-d-10\">NOT NULL<\/span><span> AUTO_INCREMENT,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-2 z-d-6\">  `<\/span><span class=\"z-l-2 z-d-6\">emoji<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-8 z-d-10\"> VARCHAR<\/span><span>(<\/span><span class=\"z-l-1 z-d-4\">1024<\/span><span>)<\/span><span class=\"z-l-8 z-d-10\"> NOT NULL<\/span><span>,<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">  PRIMARY KEY<\/span><span> (<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-2 z-d-6\">id<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span>) ENGINE<\/span><span class=\"z-l-8 z-d-10\">=<\/span><span>InnoDB <\/span><span class=\"z-l-8 z-d-10\">DEFAULT<\/span><span> CHARSET<\/span><span class=\"z-l-8 z-d-10\">=<\/span><span>utf8mb4;<\/span><\/span><\/code><\/pre><pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"sql\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">SET<\/span><span> NAMES utf8mb4;<\/span><\/span><\/code><\/pre><pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">MySQL<\/span><span> [test<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">&gt;<\/span><span> SELECT <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span> FROM emoji_test<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">+----+-------+<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">|<\/span><span class=\"z-l-6 z-d-7\"> id<\/span><span class=\"z-l-8 z-d-10\"> |<\/span><span class=\"z-l-6 z-d-7\"> emoji<\/span><span class=\"z-l-8 z-d-10\"> |<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">+----+-------+<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">|<\/span><span class=\"z-l-6 z-d-7\">  8<\/span><span class=\"z-l-8 z-d-10\"> |<\/span><span class=\"z-l-6 z-d-7\"> \ud83d\ude03<\/span><span class=\"z-l-8 z-d-10\">      |<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">|<\/span><span class=\"z-l-6 z-d-7\">  9<\/span><span class=\"z-l-8 z-d-10\"> |<\/span><span class=\"z-l-6 z-d-7\"> \ud83d\ude02<\/span><span class=\"z-l-8 z-d-10\">      |<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">|<\/span><span class=\"z-l-6 z-d-7\"> 10<\/span><span class=\"z-l-8 z-d-10\"> |<\/span><span class=\"z-l-6 z-d-7\"> \ud83e\udd26<\/span><span class=\"z-l-8 z-d-10\">      |<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">+----+-------+<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">3<\/span><span class=\"z-l-2 z-d-6\"> rows<\/span><span class=\"z-l-2 z-d-6\"> in<\/span><span class=\"z-l-2 z-d-6\"> set<\/span><span> (0.001<\/span><span class=\"z-l-2 z-d-6\"> sec<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">MySQL<\/span><span> [test<\/span><span>]<\/span><span class=\"z-l-8 z-d-10\">&gt;<\/span><span> SELECT <\/span><span class=\"z-l-8 z-d-10\">*<\/span><span> FROM emoji_test WHERE emoji = <\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span class=\"z-l-2 z-d-6\">\ud83d\ude02<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">+----+-------+<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">|<\/span><span class=\"z-l-6 z-d-7\"> id<\/span><span class=\"z-l-8 z-d-10\"> |<\/span><span class=\"z-l-6 z-d-7\"> emoji<\/span><span class=\"z-l-8 z-d-10\"> |<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">+----+-------+<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">|<\/span><span class=\"z-l-6 z-d-7\">  8<\/span><span class=\"z-l-8 z-d-10\"> |<\/span><span class=\"z-l-6 z-d-7\"> \ud83d\ude03<\/span><span class=\"z-l-8 z-d-10\">      |<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">|<\/span><span class=\"z-l-6 z-d-7\">  9<\/span><span class=\"z-l-8 z-d-10\"> |<\/span><span class=\"z-l-6 z-d-7\"> \ud83d\ude02<\/span><span class=\"z-l-8 z-d-10\">      |<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">|<\/span><span class=\"z-l-6 z-d-7\"> 10<\/span><span class=\"z-l-8 z-d-10\"> |<\/span><span class=\"z-l-6 z-d-7\"> \ud83e\udd26<\/span><span class=\"z-l-8 z-d-10\">      |<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">+----+-------+<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">3<\/span><span class=\"z-l-2 z-d-6\"> rows<\/span><span class=\"z-l-2 z-d-6\"> in<\/span><span class=\"z-l-2 z-d-6\"> set<\/span><span> (0.001<\/span><span class=\"z-l-2 z-d-6\"> sec<\/span><span>)<\/span><\/span><\/code><\/pre>\n<p>\u662f\u4e0d\u662f\u5f88\u795e\u5947\u5462, \u770b\u4e0b\u8868\u7684\u4fe1\u606f\u5462<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"sql\"><span class=\"giallo-l\"><span>MySQL <\/span><span>[test]<\/span><span class=\"z-l-8 z-d-10\">&gt;<\/span><span> SHOW <\/span><span class=\"z-l-8 z-d-10\">TABLE<\/span><span class=\"z-l-8 z-d-10\"> STATUS<\/span><span class=\"z-l-8 z-d-10\"> WHERE<\/span><span class=\"z-l-8 z-d-10\"> Name<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-2 z-d-6\"> &#39;<\/span><span class=\"z-l-2 z-d-6\">emoji_test<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">+<\/span><span class=\"z-l-5 z-d-3\">--<\/span><span class=\"z-l-5 z-d-3\">----------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+--------------------+----------+----------------+---------+<\/span><\/span>\n<span class=\"giallo-l\"><span>| <\/span><span class=\"z-l-8 z-d-10\">Name<\/span><span>       | Engine | <\/span><span class=\"z-l-8 z-d-10\">Version<\/span><span> | Row_format | <\/span><span class=\"z-l-8 z-d-10\">Rows<\/span><span> | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time         | Update_time         | Check_time | Collation          | <\/span><span class=\"z-l-8 z-d-10\">Checksum<\/span><span> | Create_options | Comment |<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">+<\/span><span class=\"z-l-5 z-d-3\">--<\/span><span class=\"z-l-5 z-d-3\">----------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+--------------------+----------+----------------+---------+<\/span><\/span>\n<span class=\"giallo-l\"><span>| emoji_test | InnoDB |      <\/span><span class=\"z-l-1 z-d-4\">10<\/span><span> | <\/span><span class=\"z-l-8 z-d-10\">Dynamic<\/span><span>    |    <\/span><span class=\"z-l-1 z-d-4\">3<\/span><span> |           <\/span><span class=\"z-l-1 z-d-4\">5461<\/span><span> |       <\/span><span class=\"z-l-1 z-d-4\">16384<\/span><span> |               <\/span><span class=\"z-l-1 z-d-4\">0<\/span><span> |            <\/span><span class=\"z-l-1 z-d-4\">0<\/span><span> |         <\/span><span class=\"z-l-1 z-d-4\">0<\/span><span> |             <\/span><span class=\"z-l-1 z-d-4\">11<\/span><span> | <\/span><span class=\"z-l-1 z-d-4\">2019<\/span><span class=\"z-l-8 z-d-10\">-<\/span><span class=\"z-l-1 z-d-4\">10<\/span><span class=\"z-l-8 z-d-10\">-<\/span><span class=\"z-l-1 z-d-4\">16<\/span><span class=\"z-l-1 z-d-4\"> 11<\/span><span>:<\/span><span class=\"z-l-1 z-d-4\">16<\/span><span>:<\/span><span class=\"z-l-1 z-d-4\">28<\/span><span> | <\/span><span class=\"z-l-1 z-d-4\">2019<\/span><span class=\"z-l-8 z-d-10\">-<\/span><span class=\"z-l-1 z-d-4\">10<\/span><span class=\"z-l-8 z-d-10\">-<\/span><span class=\"z-l-1 z-d-4\">16<\/span><span class=\"z-l-1 z-d-4\"> 11<\/span><span>:<\/span><span class=\"z-l-1 z-d-4\">25<\/span><span>:<\/span><span class=\"z-l-1 z-d-4\">10<\/span><span> | <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><span>       | utf8mb4_general_ci |     <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><span> |                |         |<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">+<\/span><span class=\"z-l-5 z-d-3\">--<\/span><span class=\"z-l-5 z-d-3\">----------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+--------------------+----------+----------------+---------+<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-1 z-d-4\">1<\/span><span class=\"z-l-8 z-d-10\"> row<\/span><span class=\"z-l-8 z-d-10\"> in<\/span><span class=\"z-l-8 z-d-10\"> set<\/span><span> (<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>.<\/span><span class=\"z-l-1 z-d-4\">001<\/span><span> sec)<\/span><\/span><\/code><\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\u6b64\u65f6\u9ed8\u8ba4\u7684\u5b57\u7b26\u5e8f\u662f <code>utf8mb4_general_ci<\/code>, \u4f7f\u7528 <code>WEIGHT_STRING<\/code> \u6765\u67e5\u8be2\u8fd9\u4e9b Emoji \u7684\u5b57\u7b26\u5e8f<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"sql\"><span class=\"giallo-l\"><span>MySQL <\/span><span>[test]<\/span><span class=\"z-l-8 z-d-10\">&gt;<\/span><span class=\"z-l-8 z-d-10\"> SET<\/span><span> @s<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-2 z-d-6\"> &#39;<\/span><span class=\"z-l-2 z-d-6\">\ud83d\ude02<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span class=\"z-l-8 z-d-10\"> COLLATE<\/span><span> utf8mb4_general_ci;<\/span><\/span>\n<span class=\"giallo-l\"><span>Query OK, <\/span><span class=\"z-l-1 z-d-4\">0<\/span><span class=\"z-l-8 z-d-10\"> rows<\/span><span> affected (<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>.<\/span><span class=\"z-l-1 z-d-4\">003<\/span><span> sec)<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>MySQL <\/span><span>[test]<\/span><span class=\"z-l-8 z-d-10\">&gt;<\/span><span class=\"z-l-8 z-d-10\"> SELECT<\/span><span> @s<\/span><span>, HEX(<\/span><span>@s<\/span><span>), HEX(WEIGHT_STRING(<\/span><span>@s<\/span><span>));<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">+<\/span><span class=\"z-l-5 z-d-3\">--<\/span><span class=\"z-l-5 z-d-3\">----+----------+------------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span>| <\/span><span>@s<\/span><span>   | HEX(<\/span><span>@s<\/span><span>)  | HEX(WEIGHT_STRING(<\/span><span>@s<\/span><span>)) |<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">+<\/span><span class=\"z-l-5 z-d-3\">--<\/span><span class=\"z-l-5 z-d-3\">----+----------+------------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span>| \ud83d\ude02     | F09F9882 | FFFD                   |<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">+<\/span><span class=\"z-l-5 z-d-3\">--<\/span><span class=\"z-l-5 z-d-3\">----+----------+------------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-1 z-d-4\">1<\/span><span class=\"z-l-8 z-d-10\"> row<\/span><span class=\"z-l-8 z-d-10\"> in<\/span><span class=\"z-l-8 z-d-10\"> set<\/span><span> (<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>.<\/span><span class=\"z-l-1 z-d-4\">001<\/span><span> sec)<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>MySQL <\/span><span>[test]<\/span><span class=\"z-l-8 z-d-10\">&gt;<\/span><span class=\"z-l-8 z-d-10\"> SET<\/span><span> @s<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-2 z-d-6\"> &#39;<\/span><span class=\"z-l-2 z-d-6\">\ud83d\ude03<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span class=\"z-l-8 z-d-10\"> COLLATE<\/span><span> utf8mb4_general_ci;<\/span><\/span>\n<span class=\"giallo-l\"><span>Query OK, <\/span><span class=\"z-l-1 z-d-4\">0<\/span><span class=\"z-l-8 z-d-10\"> rows<\/span><span> affected (<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>.<\/span><span class=\"z-l-1 z-d-4\">001<\/span><span> sec)<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>MySQL <\/span><span>[test]<\/span><span class=\"z-l-8 z-d-10\">&gt;<\/span><span class=\"z-l-8 z-d-10\"> SELECT<\/span><span> @s<\/span><span>, HEX(<\/span><span>@s<\/span><span>), HEX(WEIGHT_STRING(<\/span><span>@s<\/span><span>));<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">+<\/span><span class=\"z-l-5 z-d-3\">--<\/span><span class=\"z-l-5 z-d-3\">----+----------+------------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span>| <\/span><span>@s<\/span><span>   | HEX(<\/span><span>@s<\/span><span>)  | HEX(WEIGHT_STRING(<\/span><span>@s<\/span><span>)) |<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">+<\/span><span class=\"z-l-5 z-d-3\">--<\/span><span class=\"z-l-5 z-d-3\">----+----------+------------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span>| \ud83d\ude03     | F09F9883 | FFFD                   |<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">+<\/span><span class=\"z-l-5 z-d-3\">--<\/span><span class=\"z-l-5 z-d-3\">----+----------+------------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-1 z-d-4\">1<\/span><span class=\"z-l-8 z-d-10\"> row<\/span><span class=\"z-l-8 z-d-10\"> in<\/span><span class=\"z-l-8 z-d-10\"> set<\/span><span> (<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>.<\/span><span class=\"z-l-1 z-d-4\">001<\/span><span> sec)<\/span><\/span><\/code><\/pre>\n<p>\u53ef\u4ee5\u770b\u5230, \u5b83\u4eec\u7684\u7f16\u7801\u867d\u7136\u4e0d\u540c, \u4f46\u662f\u5b57\u7b26\u5e8f\u7684\u503c\u662f\u76f8\u540c\u7684, \u90fd\u662f <code>0xFFFD<\/code>, \u6240\u4ee5\u5728\u5339\u914d\u7684\u65f6\u5019, \u5b83\u4eec\u88ab\u8ba4\u4e3a\u662f\u540c\u4e00\u4e2a\u5b57\u7b26, \u8fd9\u53c8\u662f <code>MySQL<\/code> \u7684\u4e00\u4e2a\u5927\u5751<\/p>\n<p>\u8981\u662f\u60f3\u7c97\u66b4\u70b9\u89e3\u51b3\u95ee\u9898\u7684\u8bdd, \u76f4\u63a5\u4f7f\u7528 <code>utf8mb4_bin<\/code> \u4f5c\u4e3a\u5b57\u7b26\u5e8f\u5c31\u597d\u4e86<\/p>\n<h2 id=\"you-lai-yi-ping\"><a class=\"zola-anchor\" href=\"#you-lai-yi-ping\" aria-label=\"Anchor link for: you-lai-yi-ping\">\u53c8\u6765\u4e00\u74f6<\/a><\/h2>\n<p>\u4f46\u662f\u8fd9\u8fd8\u4e0d\u662f\u7ed3\u675f, \u5f53\u4e1a\u52a1\u4ee3\u7801\u8fde\u63a5\u6570\u636e\u5e93\u5e76\u63d2\u5165\u4e00\u4e9b Emoji \u65f6, \u8fd8\u662f\u53ef\u80fd\u9047\u5230\u5982\u4e0b\u9519\u8bef<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>ERROR 1366: Incorrect string value: &#39;\\xF0\\x9D\\x8C\\x86&#39; for column &#39;column_name&#39; at row 1<\/span><\/span><\/code><\/pre>\n<p>\u8fd9\u4e2a\u662f\u56e0\u4e3a\u5ba2\u6237\u7aef\u5230 MySQL \u670d\u52a1\u5668\u7684\u8fde\u63a5\u8fd8\u662f utf8 \u800c\u975e utf8mb4, \u6240\u4ee5\u4f60\u9700\u8981\u5728\u4e1a\u52a1\u903b\u8f91\u4e2d\u505a\u7c7b\u4f3c\u5982\u4e0b\u8bed\u53e5\u7684\u4e8b\u60c5<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>SET NAMES utf8mb4<\/span><\/span><\/code><\/pre>\n<p>\u6216\u8005\u4fee\u6539 MySQL \u7684\u914d\u7f6e\u6587\u4ef6, \u5f53\u7136\u8fd9\u6837\u4e0d\u592a\u73b0\u5b9e, \u9700\u8981\u91cd\u542f MySQL \u8fdb\u7a0b.<\/p>\n<p>\u8fd9\u6837\u4f60\u624d\u80fd\u7ec8\u4e8e\u7528\u4e0a Emoji<\/p>\n<h2 id=\"can-kao-zi-liao\"><a class=\"zola-anchor\" href=\"#can-kao-zi-liao\" aria-label=\"Anchor link for: can-kao-zi-liao\">\u53c2\u8003\u8d44\u6599<\/a><\/h2>\n<ol>\n<li><a rel=\"external\" href=\"https:\/\/stackoverflow.com\/questions\/41147829\/how-can-i-search-by-emoji-in-mysql-using-utf8mb4\">How can I search by emoji in MySQL using utf8mb4?<\/a><\/li>\n<li><a rel=\"external\" href=\"http:\/\/www.ruanyifeng.com\/blog\/2007\/10\/ascii_unicode_and_utf-8.html\">\u5b57\u7b26\u7f16\u7801\u7b14\u8bb0\uff1aASCII\uff0cUnicode \u548c UTF-8\n<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/www.zhihu.com\/question\/60072951\">\u5982\u4f55\u901a\u4fd7\u5730\u7406\u89e3Unicode\u3001UTF-8\u3001ASCII\u3001GBK\u7b49\u5b57\u7b26\u7f16\u7801\uff1f<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/medium.com\/@adamhooper\/in-mysql-never-use-utf8-use-utf8mb4-11761243e434\">In MySQL, never use \u201cutf8\u201d. Use \u201cutf8mb4\u201d.<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/mathiasbynens.be\/notes\/mysql-utf8mb4\">How to support full Unicode in MySQL databases<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/charset-connection.html\">Connection Character Sets and Collations<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/stackoverflow.com\/questions\/10957238\/incorrect-string-value-when-trying-to-insert-utf-8-into-mysql-via-jdbc\">\u201cIncorrect string value\u201d when trying to insert UTF-8 into MySQL via JDBC?<\/a><\/li>\n<\/ol>\n<h2 id=\"kuo-zhan-yue-du\"><a class=\"zola-anchor\" href=\"#kuo-zhan-yue-du\" aria-label=\"Anchor link for: kuo-zhan-yue-du\">\u6269\u5c55\u9605\u8bfb<\/a><\/h2>\n<ol>\n<li><a rel=\"external\" href=\"https:\/\/zhuanlan.zhihu.com\/p\/53714077\">\u5176\u5b9e\u4f60\u5e76\u4e0d\u61c2 Unicode<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/eev.ee\/blog\/2015\/09\/12\/dark-corners-of-unicode\/\">Dark corners of Unicode<\/a><\/li>\n<li><a rel=\"external\" href=\"http:\/\/mysql.taobao.org\/monthly\/2017\/03\/06\/\">MySQL \u00b7 \u5b9e\u73b0\u5206\u6790 \u00b7 \u5bf9\u5b57\u7b26\u96c6\u548c\u5b57\u7b26\u5e8f\u652f\u6301\u7684\u5b9e\u73b0<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/docs.python.org\/3.7\/library\/unicodedata.html\">unicodedata \u2014 Unicode Database<\/a><\/li>\n<\/ol>\n"},{"title":"Oh MySQL IN Subquery","published":"2019-09-21T15:22:58+08:00","updated":"2019-09-21T15:22:58+08:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/oh-mysql-in-subquery\/"}},"id":"https:\/\/memwey.github.io\/posts\/oh-mysql-in-subquery\/","content":"<p>\u611f\u89c9 <code>MySQL<\/code> \u7684\u5751\u5b9e\u5728\u662f\u6709\u70b9\u591a,\u8bb0\u5f55\u4e00\u4e0b\u8fd9\u4e2a <code>MySQL<\/code> \u7684\u5751, \u4e5f\u8bb0\u5f55\u4e00\u4e0b\u8fd9\u4e2a\u6559\u8bad\u5427, \u4e0b\u6b21\u5728\u6570\u636e\u5e93\u4e2d\u76f4\u63a5\u64cd\u4f5c\u4e00\u5b9a\u8981\u591a\u5c0f\u5fc3<\/p>\n<h2 id=\"xian-xiang-hui-fang\"><a class=\"zola-anchor\" href=\"#xian-xiang-hui-fang\" aria-label=\"Anchor link for: xian-xiang-hui-fang\">\u73b0\u8c61\u56de\u653e<\/a><\/h2>\n<p>\u73b0\u5728\u6709\u4e24\u5f20\u8868, \u8868\u7ed3\u6784\u5982\u4e0b, \u65e0\u5173\u5b57\u6bb5\u5df2\u7ecf\u7701\u7565<\/p>\n<ul>\n<li>team<\/li>\n<\/ul>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>+-------------+---------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span>| Field       | Type                |<\/span><\/span>\n<span class=\"giallo-l\"><span>+-------------+---------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span>| id          | int(10) unsigned    |<\/span><\/span>\n<span class=\"giallo-l\"><span>| status      | tinyint(3) unsigned |<\/span><\/span>\n<span class=\"giallo-l\"><span>+-------------+---------------------+<\/span><\/span><\/code><\/pre>\n<ul>\n<li>player<\/li>\n<\/ul>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>+-------------+---------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span>| Field       | Type                |<\/span><\/span>\n<span class=\"giallo-l\"><span>+-------------+---------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span>| id          | int(10) unsigned    |<\/span><\/span>\n<span class=\"giallo-l\"><span>| team_id     | int(10) unsigned    |<\/span><\/span>\n<span class=\"giallo-l\"><span>| status      | tinyint(3) unsigned |<\/span><\/span>\n<span class=\"giallo-l\"><span>+-------------+---------------------+<\/span><\/span><\/code><\/pre>\n<p>\u5bb9\u6613\u7406\u89e3, \u8fd9\u662f\u7b80\u5355\u7684\u4e00\u5bf9\u591a\u7684\u5173\u7cfb, \u4e00\u4e2a\u8db3\u7403\u961f team \u91cc\u9762, \u6709\u591a\u4e2a\u7403\u5458 player<\/p>\n<p>\u73b0\u5728\u60f3\u53d6\u51fa\u6709 player \u7684\u72b6\u6001\u4e3a <code>1<\/code> \u7684 team<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"sql\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">SELECT<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-8 z-d-10\"> FROM<\/span><span> team <\/span><span class=\"z-l-8 z-d-10\">WHERE<\/span><span> id <\/span><span class=\"z-l-8 z-d-10\">IN<\/span><span> (<\/span><span class=\"z-l-8 z-d-10\">SELECT<\/span><span> id <\/span><span class=\"z-l-8 z-d-10\">FROM<\/span><span> (<\/span><span class=\"z-l-8 z-d-10\">SELECT<\/span><span> team_id <\/span><span class=\"z-l-8 z-d-10\">FROM<\/span><span> player <\/span><span class=\"z-l-8 z-d-10\">WHERE<\/span><span class=\"z-l-8 z-d-10\"> status<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-1 z-d-4\"> 1<\/span><span>) <\/span><span class=\"z-l-8 z-d-10\">AS<\/span><span> a);<\/span><\/span><\/code><\/pre>\n<p>\u7406\u8bba\u4e0a, \u8fd9\u6761\u8bed\u53e5\u662f\u4e0d\u80fd\u6267\u884c\u7684, \u6ce8\u610f\u8fd9\u91cc<\/p>\n<blockquote>\n<p>...... SELECT id FROM (SELECT team_id FROM ......<\/p>\n<\/blockquote>\n<p>\u4f46\u662f, \u4e0d\u77e5\u9053\u4e3a\u4f55, \u8fd9\u6761\u8bed\u53e5\u662f\u53ef\u4ee5\u6267\u884c\u7684, \u800c\u4e14\u7b49\u4ef7\u4e8e<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"sql\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">SELECT<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-8 z-d-10\"> FROM<\/span><span> team;<\/span><\/span><\/code><\/pre>\n<p>\u5982\u679c\u5355\u72ec\u628a\u6700\u5916\u5c42\u7684 IN \u91cc\u9762\u7684 subquery \u53d6\u51fa\u6765, <code>MySQL<\/code> \u4f1a\u62a5\u9519<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"sql\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">SELECT<\/span><span> id <\/span><span class=\"z-l-8 z-d-10\">FROM<\/span><span> (<\/span><span class=\"z-l-8 z-d-10\">SELECT<\/span><span> team_id <\/span><span class=\"z-l-8 z-d-10\">FROM<\/span><span> player <\/span><span class=\"z-l-8 z-d-10\">WHERE<\/span><span class=\"z-l-8 z-d-10\"> status<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-1 z-d-4\"> 1<\/span><span>) <\/span><span class=\"z-l-8 z-d-10\">AS<\/span><span> a;<\/span><\/span><\/code><\/pre>\n<blockquote>\n<p>ERROR 1054 (42S22): Unknown column 'id' in 'field list'<\/p>\n<\/blockquote>\n<p>\u518d\u8bd5\u7740\u628a id \u6539\u4e3a\u4e0d\u5b58\u5728\u7684\u5b57\u6bb5<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"sql\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">SELECT<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-8 z-d-10\"> FROM<\/span><span> team <\/span><span class=\"z-l-8 z-d-10\">WHERE<\/span><span> id <\/span><span class=\"z-l-8 z-d-10\">IN<\/span><span> (<\/span><span class=\"z-l-8 z-d-10\">SELECT<\/span><span> not_exist_field <\/span><span class=\"z-l-8 z-d-10\">FROM<\/span><span> (<\/span><span class=\"z-l-8 z-d-10\">SELECT<\/span><span> team_id <\/span><span class=\"z-l-8 z-d-10\">FROM<\/span><span> player <\/span><span class=\"z-l-8 z-d-10\">WHERE<\/span><span class=\"z-l-8 z-d-10\"> status<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-1 z-d-4\"> 1<\/span><span>) <\/span><span class=\"z-l-8 z-d-10\">AS<\/span><span> a);<\/span><\/span><\/code><\/pre>\n<blockquote>\n<p>ERROR 1054 (42S22): Unknown column 'not_exist_field' in 'field list'<\/p>\n<\/blockquote>\n<p>\u8fd9\u6837\u624d\u80fd\u5982\u9884\u671f\u7684\u62a5\u9519<\/p>\n<h2 id=\"wen-ti-pai-cha\"><a class=\"zola-anchor\" href=\"#wen-ti-pai-cha\" aria-label=\"Anchor link for: wen-ti-pai-cha\">\u95ee\u9898\u6392\u67e5<\/a><\/h2>\n<p>\u5148 EXPLAIN \u8bd5\u8bd5\u5462<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"sql\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-1 z-d-4\"> 1<\/span><span>. <\/span><span class=\"z-l-8 z-d-10\">row<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><\/span>\n<span class=\"giallo-l\"><span>           id: <\/span><span class=\"z-l-1 z-d-4\">1<\/span><\/span>\n<span class=\"giallo-l\"><span>  select_type: <\/span><span class=\"z-l-8 z-d-10\">SIMPLE<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        table<\/span><span>: team<\/span><\/span>\n<span class=\"giallo-l\"><span>   partitions: <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">         type<\/span><span>: ALL<\/span><\/span>\n<span class=\"giallo-l\"><span>possible_keys: <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">          key<\/span><span>: <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><\/span>\n<span class=\"giallo-l\"><span>      key_len: <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><\/span>\n<span class=\"giallo-l\"><span>          ref: <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">         rows<\/span><span>: <\/span><span class=\"z-l-1 z-d-4\">2<\/span><\/span>\n<span class=\"giallo-l\"><span>     filtered: <\/span><span class=\"z-l-1 z-d-4\">100<\/span><span>.<\/span><span class=\"z-l-1 z-d-4\">00<\/span><\/span>\n<span class=\"giallo-l\"><span>        Extra: <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-1 z-d-4\"> 2<\/span><span>. <\/span><span class=\"z-l-8 z-d-10\">row<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><\/span>\n<span class=\"giallo-l\"><span>           id: <\/span><span class=\"z-l-1 z-d-4\">1<\/span><\/span>\n<span class=\"giallo-l\"><span>  select_type: <\/span><span class=\"z-l-8 z-d-10\">SIMPLE<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        table<\/span><span>: player<\/span><\/span>\n<span class=\"giallo-l\"><span>   partitions: <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">         type<\/span><span>: ALL<\/span><\/span>\n<span class=\"giallo-l\"><span>possible_keys: <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">          key<\/span><span>: <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><\/span>\n<span class=\"giallo-l\"><span>      key_len: <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><\/span>\n<span class=\"giallo-l\"><span>          ref: <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">         rows<\/span><span>: <\/span><span class=\"z-l-1 z-d-4\">5<\/span><\/span>\n<span class=\"giallo-l\"><span>     filtered: <\/span><span class=\"z-l-1 z-d-4\">20<\/span><span>.<\/span><span class=\"z-l-1 z-d-4\">00<\/span><\/span>\n<span class=\"giallo-l\"><span>        Extra: <\/span><span class=\"z-l-8 z-d-10\">Using<\/span><span class=\"z-l-8 z-d-10\"> where<\/span><span>; FirstMatch(team); <\/span><span class=\"z-l-8 z-d-10\">Using<\/span><span class=\"z-l-8 z-d-10\"> join<\/span><span class=\"z-l-8 z-d-10\"> buffer<\/span><span> (<\/span><span class=\"z-l-8 z-d-10\">Block<\/span><span> Nested <\/span><span class=\"z-l-8 z-d-10\">Loop<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-1 z-d-4\">2<\/span><span class=\"z-l-8 z-d-10\"> rows<\/span><span class=\"z-l-8 z-d-10\"> in<\/span><span class=\"z-l-8 z-d-10\"> set<\/span><span>, <\/span><span class=\"z-l-1 z-d-4\">2<\/span><span> warnings (<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>.<\/span><span class=\"z-l-1 z-d-4\">001<\/span><span> sec)<\/span><\/span><\/code><\/pre>\n<p>\u597d\u50cf\u770b\u4e0d\u51fa\u6765\u4ec0\u4e48\u95ee\u9898\u5462, \u4e0d\u8fc7\u6709 warnings, \u770b\u4e00\u4e0b\u5462<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"sql\"><span class=\"giallo-l\"><span>SHOW WARNINGS\\G<\/span><\/span><\/code><\/pre><pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>*************************** 1. row ***************************<\/span><\/span>\n<span class=\"giallo-l\"><span>  Level: Note<\/span><\/span>\n<span class=\"giallo-l\"><span>   Code: 1276<\/span><\/span>\n<span class=\"giallo-l\"><span>Message: Field or reference &#39;test.team.id&#39; of SELECT #2 was resolved in SELECT #1<\/span><\/span>\n<span class=\"giallo-l\"><span>*************************** 2. row ***************************<\/span><\/span>\n<span class=\"giallo-l\"><span>  Level: Note<\/span><\/span>\n<span class=\"giallo-l\"><span>   Code: 1003<\/span><\/span>\n<span class=\"giallo-l\"><span>Message: \/* select#1 *\/ select `test`.`team`.`id` AS `id`,`test`.`team`.`status` AS `status` from `test`.`team` semi join (`test`.`player`) where (`test`.`player`.`status` = 1)<\/span><\/span>\n<span class=\"giallo-l\"><span>2 rows in set (0.001 sec)<\/span><\/span><\/code><\/pre>\n<p>\u8fd9\u91cc\u51fa\u73b0\u4e86\u4e00\u4e2a <code>semi join<\/code>, \u6ca1\u6709\u89c1\u8fc7\u5462, \u67e5\u770b\u4e00\u4e0b\u6587\u6863, \u5927\u610f\u5c31\u662f, \u6bd4\u5982\u4f7f\u7528 <code>INNER JOIN<\/code> \u7684\u65f6\u5019, \u4f1a\u8fd4\u56de\u5339\u914d\u6b21\u6570\u4e2a\u7ed3\u679c. \u4f46\u662f\u6211\u4eec\u5e76\u4e0d\u5173\u6ce8\u5339\u914d\u7684\u6b21\u6570, \u6bd4\u5982\u5982\u4e0b\u8bed\u53e5, \u6211\u60f3\u53d6\u51fa\u6709\u7403\u5458\u7684 status \u4e3a 0 \u7684\u7403\u961f, \u53ef\u4ee5\u8fd9\u6837\u5199<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"sql\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">SELECT<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-8 z-d-10\"> FROM<\/span><span> team <\/span><span class=\"z-l-8 z-d-10\">INNER JOIN<\/span><span> player <\/span><span class=\"z-l-8 z-d-10\">ON<\/span><span class=\"z-l-1 z-d-4\"> team<\/span><span>.<\/span><span class=\"z-l-1 z-d-4\">id<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span> team_id <\/span><span class=\"z-l-8 z-d-10\">WHERE<\/span><span class=\"z-l-1 z-d-4\"> player<\/span><span>.<\/span><span class=\"z-l-1 z-d-4\">status<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-1 z-d-4\"> 0<\/span><span>;<\/span><\/span><\/code><\/pre>\n<p>\u5982\u679c\u4e00\u4e2a\u7403\u961f\u91cc\u6709\u591a\u4e2a status \u4e3a 0 \u7684\u7403\u5458, \u90a3\u4e48\u5c31\u4f1a\u51fa\u73b0\u591a\u4e2a\u8bb0\u5f55, \u6bd4\u5982\u8fd9\u6837<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>+----+--------+----+---------+--------+<\/span><\/span>\n<span class=\"giallo-l\"><span>| id | status | id | team_id | status |<\/span><\/span>\n<span class=\"giallo-l\"><span>+----+--------+----+---------+--------+<\/span><\/span>\n<span class=\"giallo-l\"><span>|  1 |      0 |  1 |       1 |      0 |<\/span><\/span>\n<span class=\"giallo-l\"><span>|  1 |      0 |  2 |       1 |      0 |<\/span><\/span>\n<span class=\"giallo-l\"><span>|  2 |      0 |  5 |       2 |      0 |<\/span><\/span>\n<span class=\"giallo-l\"><span>|  2 |      0 |  6 |       2 |      0 |<\/span><\/span>\n<span class=\"giallo-l\"><span>+----+--------+----+---------+--------+<\/span><\/span><\/code><\/pre>\n<p>\u8fd9\u6837\u660e\u663e\u6709\u4e9b\u5197\u4f59\u7684\u6570\u636e\u4e86. \u5f53\u7136\u6211\u4eec\u53ef\u4ee5\u7528 <code>DISTINCT<\/code> \u4ec0\u4e48\u7684\u518d\u5904\u7406\u4e00\u904d, \u4f46\u662f\u8fd9\u6837\u6548\u7387\u4f1a\u6bd4\u8f83\u4f4e. \u90a3\u4e48, \u5c31\u53ef\u4ee5\u7528\u7c7b\u4f3c\u7684\u5b50\u67e5\u8be2\u5c31\u65b9\u4fbf\u591a\u4e86<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"sql\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">SELECT<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-8 z-d-10\"> FROM<\/span><span> team <\/span><span class=\"z-l-8 z-d-10\">WHERE<\/span><span> id <\/span><span class=\"z-l-8 z-d-10\">IN<\/span><span> (<\/span><span class=\"z-l-8 z-d-10\">SELECT<\/span><span> team_id <\/span><span class=\"z-l-8 z-d-10\">FROM<\/span><span> player <\/span><span class=\"z-l-8 z-d-10\">WHERE<\/span><span class=\"z-l-8 z-d-10\"> status<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-1 z-d-4\"> 0<\/span><span>);<\/span><\/span><\/code><\/pre>\n<p>\u8fd4\u56de\u7684\u7ed3\u679c\u4e5f\u7b80\u6d01\u591a\u4e86<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>+----+--------+<\/span><\/span>\n<span class=\"giallo-l\"><span>| id | status |<\/span><\/span>\n<span class=\"giallo-l\"><span>+----+--------+<\/span><\/span>\n<span class=\"giallo-l\"><span>|  1 |      0 |<\/span><\/span>\n<span class=\"giallo-l\"><span>|  2 |      0 |<\/span><\/span>\n<span class=\"giallo-l\"><span>+----+--------+<\/span><\/span><\/code><\/pre>\n<p>\u5f53\u7136, \u8981\u8fd9\u6837\u4f18\u5316\u8fd8\u662f\u6709\u5f88\u591a\u6761\u4ef6\u7684, \u6797\u6797\u603b\u603b\u7684, \u53ef\u4ee5\u53bb\u5b98\u65b9\u6587\u6863\u67e5\u770b<\/p>\n<p>\u770b\u4e86\u8fd9\u4e48\u591a, \u611f\u89c9\u8fd8\u662f\u548c\u8fd9\u4e2a\u95ee\u9898\u6ca1\u4ec0\u4e48\u5173\u7cfb\u554a, \u8bd5\u7740 EXPLAIN \u4e00\u4e0b\u6b63\u786e\u7684\u8bed\u53e5<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"sql\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-1 z-d-4\"> 1<\/span><span>. <\/span><span class=\"z-l-8 z-d-10\">row<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><\/span>\n<span class=\"giallo-l\"><span>           id: <\/span><span class=\"z-l-1 z-d-4\">1<\/span><\/span>\n<span class=\"giallo-l\"><span>  select_type: <\/span><span class=\"z-l-8 z-d-10\">SIMPLE<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        table<\/span><span>: team<\/span><\/span>\n<span class=\"giallo-l\"><span>   partitions: <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">         type<\/span><span>: ALL<\/span><\/span>\n<span class=\"giallo-l\"><span>possible_keys: <\/span><span class=\"z-l-8 z-d-10\">PRIMARY<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">          key<\/span><span>: <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><\/span>\n<span class=\"giallo-l\"><span>      key_len: <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><\/span>\n<span class=\"giallo-l\"><span>          ref: <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">         rows<\/span><span>: <\/span><span class=\"z-l-1 z-d-4\">2<\/span><\/span>\n<span class=\"giallo-l\"><span>     filtered: <\/span><span class=\"z-l-1 z-d-4\">100<\/span><span>.<\/span><span class=\"z-l-1 z-d-4\">00<\/span><\/span>\n<span class=\"giallo-l\"><span>        Extra: <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-1 z-d-4\"> 2<\/span><span>. <\/span><span class=\"z-l-8 z-d-10\">row<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><\/span>\n<span class=\"giallo-l\"><span>           id: <\/span><span class=\"z-l-1 z-d-4\">1<\/span><\/span>\n<span class=\"giallo-l\"><span>  select_type: <\/span><span class=\"z-l-8 z-d-10\">SIMPLE<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">        table<\/span><span>: player<\/span><\/span>\n<span class=\"giallo-l\"><span>   partitions: <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">         type<\/span><span>: ALL<\/span><\/span>\n<span class=\"giallo-l\"><span>possible_keys: <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">          key<\/span><span>: <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><\/span>\n<span class=\"giallo-l\"><span>      key_len: <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><\/span>\n<span class=\"giallo-l\"><span>          ref: <\/span><span class=\"z-l-8 z-d-10\">NULL<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">         rows<\/span><span>: <\/span><span class=\"z-l-1 z-d-4\">5<\/span><\/span>\n<span class=\"giallo-l\"><span>     filtered: <\/span><span class=\"z-l-1 z-d-4\">20<\/span><span>.<\/span><span class=\"z-l-1 z-d-4\">00<\/span><\/span>\n<span class=\"giallo-l\"><span>        Extra: <\/span><span class=\"z-l-8 z-d-10\">Using<\/span><span class=\"z-l-8 z-d-10\"> where<\/span><span>; FirstMatch(team); <\/span><span class=\"z-l-8 z-d-10\">Using<\/span><span class=\"z-l-8 z-d-10\"> join<\/span><span class=\"z-l-8 z-d-10\"> buffer<\/span><span> (<\/span><span class=\"z-l-8 z-d-10\">Block<\/span><span> Nested <\/span><span class=\"z-l-8 z-d-10\">Loop<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-1 z-d-4\">2<\/span><span class=\"z-l-8 z-d-10\"> rows<\/span><span class=\"z-l-8 z-d-10\"> in<\/span><span class=\"z-l-8 z-d-10\"> set<\/span><span>, <\/span><span class=\"z-l-1 z-d-4\">1<\/span><span> warning (<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>.<\/span><span class=\"z-l-1 z-d-4\">001<\/span><span> sec)<\/span><\/span><\/code><\/pre>\n<p>\u518d\u770b\u770b warnings<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"sql\"><span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-1 z-d-4\"> 1<\/span><span>. <\/span><span class=\"z-l-8 z-d-10\">row<\/span><span class=\"z-l-8 z-d-10\"> *<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><span class=\"z-l-8 z-d-10\">*<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">  Level<\/span><span>: Note<\/span><\/span>\n<span class=\"giallo-l\"><span>   Code: <\/span><span class=\"z-l-1 z-d-4\">1003<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-8 z-d-10\">Message<\/span><span>: <\/span><span class=\"z-l-5 z-d-3\">\/*<\/span><span class=\"z-l-5 z-d-3\"> select#1 <\/span><span class=\"z-l-5 z-d-3\">*\/<\/span><span class=\"z-l-8 z-d-10\"> select<\/span><span class=\"z-l-2 z-d-6\"> `<\/span><span class=\"z-l-2 z-d-6\">test<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span>.<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-2 z-d-6\">team<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span>.<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-2 z-d-6\">id<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-8 z-d-10\"> AS<\/span><span class=\"z-l-2 z-d-6\"> `<\/span><span class=\"z-l-2 z-d-6\">id<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span>,<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-2 z-d-6\">test<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span>.<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-2 z-d-6\">team<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span>.<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-2 z-d-6\">status<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-8 z-d-10\"> AS<\/span><span class=\"z-l-2 z-d-6\"> `<\/span><span class=\"z-l-2 z-d-6\">status<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-8 z-d-10\"> from<\/span><span class=\"z-l-2 z-d-6\"> `<\/span><span class=\"z-l-2 z-d-6\">test<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span>.<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-2 z-d-6\">team<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span> semi <\/span><span class=\"z-l-8 z-d-10\">join<\/span><span> (<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-2 z-d-6\">test<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span>.<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-2 z-d-6\">player<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span>) <\/span><span class=\"z-l-8 z-d-10\">where<\/span><span> ((<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-2 z-d-6\">test<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span>.<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-2 z-d-6\">player<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span>.<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-2 z-d-6\">team_id<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-2 z-d-6\"> `<\/span><span class=\"z-l-2 z-d-6\">test<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span>.<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-2 z-d-6\">team<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span>.<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-2 z-d-6\">id<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span>) <\/span><span class=\"z-l-8 z-d-10\">and<\/span><span> (<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-2 z-d-6\">test<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span>.<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-2 z-d-6\">player<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span>.<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-2 z-d-6\">status<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-1 z-d-4\"> 1<\/span><span>))<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-1 z-d-4\">1<\/span><span class=\"z-l-8 z-d-10\"> row<\/span><span class=\"z-l-8 z-d-10\"> in<\/span><span class=\"z-l-8 z-d-10\"> set<\/span><span> (<\/span><span class=\"z-l-1 z-d-4\">0<\/span><span>.<\/span><span class=\"z-l-1 z-d-4\">001<\/span><span> sec)<\/span><\/span><\/code><\/pre>\n<p>\u5bf9\u7167\u7740\u5b9e\u9645\u8fd0\u884c\u7684\u8bed\u53e5\u7684 Note, \u53d1\u73b0\u9519\u8bef\u7684\u8bed\u53e5\u7f3a\u5c11\u4e86\u4ee5\u4e0b\u8fd9\u4e2a\u6761\u4ef6<\/p>\n<blockquote>\n<p>((<code>test<\/code>.<code>player<\/code>.<code>team_id<\/code> = <code>test<\/code>.<code>team<\/code>.<code>id<\/code>)<\/p>\n<\/blockquote>\n<p>\u96be\u9053\u5c31\u662f\u4f60! \u4f46\u662f\u4e3a\u4ec0\u4e48\u53c8\u6709<\/p>\n<blockquote>\n<p>Field or reference 'test.team.id' of SELECT #2 was resolved in SELECT #1<\/p>\n<\/blockquote>\n<p>\u8fd9\u4e2a\u95ee\u9898\u5462<\/p>\n<h2 id=\"po-an\"><a class=\"zola-anchor\" href=\"#po-an\" aria-label=\"Anchor link for: po-an\">\u7834\u6848<\/a><\/h2>\n<p>\u540e\u6765\u7ffb\u4e86\u7ffb\u6587\u6863, \u53d1\u73b0\u8fd9\u538b\u6839\u4e0d\u662f <code>MySQL<\/code> \u7684 Bug, \u800c\u662f SQL \u4e00\u6761\u76f8\u5f53\u5751\u7684\u4f5c\u7528\u57df\u89c4\u5219, \u5b50\u67e5\u8be2\u91cc\u89e3\u6790\u4e0d\u4e86\u7684\u5217\u540d, \u4f1a\u8dd1\u5230\u5916\u5c42\u67e5\u8be2\u53bb\u627e.<\/p>\n<p>\u5173\u952e\u8fd8\u662f\u5728\u90a3\u4e2a\u6d3e\u751f\u8868 <code>a<\/code><\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"sql\"><span class=\"giallo-l\"><span>(<\/span><span class=\"z-l-8 z-d-10\">SELECT<\/span><span> team_id <\/span><span class=\"z-l-8 z-d-10\">FROM<\/span><span> player <\/span><span class=\"z-l-8 z-d-10\">WHERE<\/span><span class=\"z-l-8 z-d-10\"> status<\/span><span class=\"z-l-8 z-d-10\"> =<\/span><span class=\"z-l-1 z-d-4\"> 1<\/span><span>) <\/span><span class=\"z-l-8 z-d-10\">AS<\/span><span> a<\/span><\/span><\/code><\/pre>\n<p>\u5b83\u53ea\u6709 <code>team_id<\/code> \u4e00\u5217, \u6839\u672c\u6ca1\u6709 <code>id<\/code>. \u4e8e\u662f\u5916\u9762\u90a3\u53e5 <code>SELECT id FROM a<\/code> \u91cc\u7684 <code>id<\/code>, \u5728 <code>a<\/code> \u91cc\u662f\u627e\u4e0d\u5230\u7684. \u6309\u7167\u4f5c\u7528\u57df\u89c4\u5219, \u5185\u5c42\u627e\u4e0d\u5230\u5c31\u5f80\u5916\u5c42\u627e, \u800c\u5916\u5c42\u7684 <code>team<\/code> \u8868\u6070\u597d\u6709 <code>id<\/code>, \u6240\u4ee5\u8fd9\u4e2a <code>id<\/code> \u5c31\u88ab\u89e3\u6790\u6210\u4e86 <code>team.id<\/code>. \u8fd9\u4e5f\u6b63\u662f\u90a3\u6761 Note \u60f3\u544a\u8bc9\u6211\u4eec\u7684<\/p>\n<blockquote>\n<p>Field or reference 'test.team.id' of SELECT #2 was resolved in SELECT #1<\/p>\n<\/blockquote>\n<p><code>id<\/code> \u53d8\u6210 <code>team.id<\/code> \u4e4b\u540e, \u5b50\u67e5\u8be2\u5c31\u6210\u4e86\u300c\u5bf9\u5f53\u524d\u8fd9\u4e00\u884c <code>team<\/code>, \u8fd4\u56de\u5b83\u81ea\u5df1\u7684 <code>team.id<\/code>, <code>a<\/code> \u91cc\u6709\u51e0\u884c\u5c31\u8fd4\u56de\u51e0\u6b21\u300d, \u6574\u4e2a\u6761\u4ef6\u76f8\u5f53\u4e8e<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"sql\"><span class=\"giallo-l\"><span class=\"z-l-1 z-d-4\">team<\/span><span>.<\/span><span class=\"z-l-1 z-d-4\">id<\/span><span class=\"z-l-8 z-d-10\"> IN<\/span><span> (<\/span><span class=\"z-l-8 z-d-10\">SELECT<\/span><span class=\"z-l-1 z-d-4\"> team<\/span><span>.<\/span><span class=\"z-l-1 z-d-4\">id<\/span><span class=\"z-l-8 z-d-10\"> FROM<\/span><span> a)<\/span><\/span><\/code><\/pre>\n<p>\u53ea\u8981 <code>a<\/code> \u975e\u7a7a, \u4e5f\u5c31\u662f\u5168\u8868\u91cc\u5b58\u5728\u4efb\u610f\u4e00\u4e2a <code>status<\/code> \u4e3a <code>1<\/code> \u7684\u7403\u5458, \u8fd9\u4e2a <code>IN<\/code> \u5bf9\u6bcf\u4e00\u884c <code>team<\/code> \u90fd\u6052\u4e3a\u771f. \u672c\u8be5\u8d77\u4f5c\u7528\u7684\u5173\u8054\u6761\u4ef6 <code>player.team_id = team.id<\/code> \u4ece\u5934\u5230\u5c3e\u5c31\u6ca1\u53c2\u4e0e\u8fdb\u6765, \u6240\u4ee5\u6bcf\u652f\u7403\u961f\u90fd\u88ab\u635e\u4e86\u51fa\u6765, \u7b49\u4ef7\u4e8e <code>SELECT * FROM team<\/code>. \u518d\u5bf9\u7167\u524d\u9762\u4e24\u6761 Note \u91cc <code>semi join<\/code> \u7684 <code>where<\/code>, \u4e00\u4e2a\u6709 <code>team_id = team.id<\/code>, \u4e00\u4e2a\u6ca1\u6709, \u4e5f\u5c31\u8bf4\u5f97\u901a\u4e86.<\/p>\n<p>\u56de\u8fc7\u5934\u770b\u4e4b\u524d\u90a3\u51e0\u4e2a\u5947\u602a\u7684\u73b0\u8c61, \u4e5f\u90fd\u987a\u7406\u6210\u7ae0\u4e86<\/p>\n<ul>\n<li>\u5355\u72ec\u8dd1 <code>SELECT id FROM a<\/code> \u4f1a\u62a5\u9519, \u662f\u56e0\u4e3a\u6ca1\u6709\u5916\u5c42\u53ef\u4ee5\u501f, <code>id<\/code> \u771f\u7684\u65e0\u5904\u53ef\u5bfb<\/li>\n<li>\u5d4c\u5957\u91cc\u628a <code>id<\/code> \u6362\u6210 <code>not_exist_field<\/code> \u4e5f\u62a5\u9519, \u662f\u56e0\u4e3a\u8fd9\u4e2a\u540d\u5b57\u5728 <code>a<\/code> \u548c\u5916\u5c42 <code>team<\/code> \u91cc\u90fd\u4e0d\u5b58\u5728<\/li>\n<li>\u552f\u72ec <code>id<\/code> \u4e0d\u62a5\u9519, \u53ea\u662f\u56e0\u4e3a\u5b83\u6070\u597d\u662f\u5916\u5c42 <code>team<\/code> \u7684\u5217, \u88ab\u6084\u6084\u501f\u8d70\u4e86, \u62a5\u9519\u88ab\u5403\u6389, \u7ed3\u679c\u5374\u5168\u9519<\/li>\n<\/ul>\n<p>\u6240\u4ee5\u5e76\u4e0d\u662f <code>MySQL<\/code> \u62bd\u98ce, \u800c\u662f\u300c\u5916\u5c42\u6070\u597d\u6709\u4e2a\u540c\u540d\u5217\u300d, \u628a\u4e00\u53e5\u672c\u8be5\u62a5\u9519\u7684\u8bed\u53e5, \u53d8\u6210\u4e86\u80fd\u8dd1\u4f46\u7ed3\u679c\u5b8c\u5168\u4e0d\u5bf9\u7684\u8bed\u53e5, \u5c5e\u5b9e\u6709\u70b9\u9634\u9669.<\/p>\n<p>\u6559\u8bad\u8fd8\u662f\u5f00\u5934\u90a3\u53e5, \u5728\u6570\u636e\u5e93\u91cc\u76f4\u63a5\u64cd\u4f5c\u4e00\u5b9a\u8981\u591a\u5c0f\u5fc3. \u5177\u4f53\u5230\u8fd9\u4e2a\u5751, \u4e00\u4e2a\u597d\u4e60\u60ef\u662f\u5b50\u67e5\u8be2\u91cc\u7684\u5217\u540d\u90fd\u5e26\u4e0a\u8868\u540d\u6216\u522b\u540d, \u5199 <code>a.team_id<\/code> \u800c\u4e0d\u662f\u5149\u79c3\u79c3\u7684 <code>id<\/code>, \u4e00\u65e6\u5199\u9519\u4f1a\u7acb\u523b\u62a5\u9519, \u800c\u4e0d\u4f1a\u88ab\u5916\u5c42\u6084\u6084\u501f\u8d70. \u53e6\u5916, \u8fd9\u4e2a\u89c4\u5219\u5728 <code>DELETE FROM team WHERE id IN (SELECT id FROM ...)<\/code> \u91cc\u6700\u8981\u547d, \u5217\u540d\u4e00\u5199\u9519\u89e3\u6790\u6210\u5916\u5c42\u7684 <code>id<\/code>, \u6761\u4ef6\u6052\u771f, \u6574\u5f20\u8868\u5c31\u6ca1\u4e86.<\/p>\n<h2 id=\"can-kao-zi-liao\"><a class=\"zola-anchor\" href=\"#can-kao-zi-liao\" aria-label=\"Anchor link for: can-kao-zi-liao\">\u53c2\u8003\u8d44\u6599<\/a><\/h2>\n<ol>\n<li><a rel=\"external\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/semijoins.html\">Optimizing Subqueries, Derived Tables, and View References with Semijoin Transformations<\/a><\/li>\n<li><a rel=\"external\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/correlated-subqueries.html\">Correlated Subqueries<\/a><\/li>\n<\/ol>\n"},{"title":"Yes","published":"2018-12-14T23:34:15+08:00","updated":"2018-12-14T23:34:15+08:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/yes\/"}},"id":"https:\/\/memwey.github.io\/posts\/yes\/","content":"<p>\u6700\u8fd1\u770b\u5230\u4e00\u4e2a\u6709\u8da3\u7684 <code>GNU\/Linux<\/code> \u547d\u4ee4, <code>yes<\/code><\/p>\n<p>\u5148 <code>man<\/code> \u4e00\u4e0b<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">YES(1<\/span><span>)                    BSD General Commands Manual                   YES(<\/span><span class=\"z-l-6 z-d-7\">1<\/span><span>)<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">NAME<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">     yes<\/span><span class=\"z-l-1 z-d-4\"> -<\/span><span class=\"z-l-1 z-d-4\">-<\/span><span class=\"z-l-2 z-d-6\"> be<\/span><span class=\"z-l-2 z-d-6\"> repetitively<\/span><span class=\"z-l-2 z-d-6\"> affirmative<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">SYNOPSIS<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">     yes<\/span><span> [expletive<\/span><span>]<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">DESCRIPTION<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">     yes<\/span><span class=\"z-l-2 z-d-6\"> outputs<\/span><span class=\"z-l-2 z-d-6\"> expletive,<\/span><span class=\"z-l-2 z-d-6\"> or,<\/span><span class=\"z-l-2 z-d-6\"> by<\/span><span class=\"z-l-2 z-d-6\"> default,<\/span><span class=\"z-l-2 z-d-6\"> `<\/span><span class=\"z-l-2 z-d-6\">`<\/span><span class=\"z-l-6 z-d-7\">y<\/span><span class=\"z-l-6 z-d-7\">&#39;<\/span><span class=\"z-l-6 z-d-7\">&#39;<\/span><span class=\"z-l-6 z-d-7\">,<\/span><span class=\"z-l-2 z-d-6\"> forever.<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">HISTORY<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">     The<\/span><span class=\"z-l-2 z-d-6\"> yes<\/span><span class=\"z-l-2 z-d-6\"> command<\/span><span class=\"z-l-2 z-d-6\"> appeared<\/span><span class=\"z-l-2 z-d-6\"> in<\/span><span class=\"z-l-2 z-d-6\"> 4.0BSD.<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">4th<\/span><span class=\"z-l-2 z-d-6\"> Berkeley<\/span><span class=\"z-l-2 z-d-6\"> Distribution<\/span><span class=\"z-l-2 z-d-6\">        June<\/span><span class=\"z-l-2 z-d-6\"> 6,<\/span><span class=\"z-l-1 z-d-4\"> 1993<\/span><span class=\"z-l-2 z-d-6\">        4th<\/span><span class=\"z-l-2 z-d-6\"> Berkeley<\/span><span class=\"z-l-2 z-d-6\"> Distribution<\/span><\/span>\n<span class=\"giallo-l\"><span>(<\/span><span class=\"z-l-6 z-d-7\">END<\/span><span>)<\/span><\/span><\/code><\/pre>\n<p>emmmmm, \u5728 <code>macOS<\/code> \u4e0b\u5e76\u6ca1\u6709 <code>--help<\/code> \u6216\u8005 <code>-h<\/code> \u7684\u9009\u9879<\/p>\n<p>\u8bd5\u8bd5 <code>Linux<\/code> \u4e0b\u5462<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">\u279c<\/span><span class=\"z-l-2 z-d-6\">  \/<\/span><span class=\"z-l-2 z-d-6\"> yes<\/span><span class=\"z-l-1 z-d-4\"> -<\/span><span class=\"z-l-1 z-d-4\">-help<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">Usage:<\/span><span class=\"z-l-2 z-d-6\"> yes<\/span><span> [STRING<\/span><span>]...<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">  or:<\/span><span class=\"z-l-2 z-d-6\">  yes<\/span><span class=\"z-l-2 z-d-6\"> OPTION<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">Repeatedly<\/span><span class=\"z-l-2 z-d-6\"> output<\/span><span class=\"z-l-2 z-d-6\"> a<\/span><span class=\"z-l-2 z-d-6\"> line<\/span><span class=\"z-l-2 z-d-6\"> with<\/span><span class=\"z-l-2 z-d-6\"> all<\/span><span class=\"z-l-2 z-d-6\"> specified<\/span><span class=\"z-l-2 z-d-6\"> STRING<\/span><span>(<\/span><span class=\"z-l-6 z-d-7\">s<\/span><span>)<\/span><span class=\"z-l-2 z-d-6\">,<\/span><span class=\"z-l-2 z-d-6\"> or<\/span><span class=\"z-l-2 z-d-6\"> &#39;<\/span><span class=\"z-l-2 z-d-6\">y<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><span class=\"z-l-2 z-d-6\">.<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">      --help<\/span><span class=\"z-l-2 z-d-6\">     display<\/span><span class=\"z-l-2 z-d-6\"> this<\/span><span class=\"z-l-2 z-d-6\"> help<\/span><span class=\"z-l-2 z-d-6\"> and<\/span><span class=\"z-l-2 z-d-6\"> exit<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">      --version<\/span><span class=\"z-l-2 z-d-6\">  output<\/span><span class=\"z-l-2 z-d-6\"> version<\/span><span class=\"z-l-2 z-d-6\"> information<\/span><span class=\"z-l-2 z-d-6\"> and<\/span><span class=\"z-l-2 z-d-6\"> exit<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">GNU<\/span><span class=\"z-l-2 z-d-6\"> coreutils<\/span><span class=\"z-l-2 z-d-6\"> online<\/span><span class=\"z-l-2 z-d-6\"> help:<\/span><span class=\"z-l-8 z-d-10\"> &lt;<\/span><span class=\"z-l-2 z-d-6\">https:\/\/www.gnu.org\/software\/coreutils<\/span><span>\/<\/span><span class=\"z-l-8 z-d-10\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">Full<\/span><span class=\"z-l-2 z-d-6\"> documentation<\/span><span class=\"z-l-2 z-d-6\"> at:<\/span><span class=\"z-l-8 z-d-10\"> &lt;<\/span><span class=\"z-l-2 z-d-6\">https:\/\/www.gnu.org\/software\/coreutils\/ye<\/span><span>s<\/span><span class=\"z-l-8 z-d-10\">&gt;<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">or<\/span><span class=\"z-l-2 z-d-6\"> available<\/span><span class=\"z-l-2 z-d-6\"> locally<\/span><span class=\"z-l-2 z-d-6\"> via:<\/span><span class=\"z-l-2 z-d-6\"> info<\/span><span class=\"z-l-2 z-d-6\"> &#39;<\/span><span class=\"z-l-2 z-d-6\">(coreutils) yes invocation<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><\/span><\/code><\/pre>\n<p>\u6709\u4e86<\/p>\n<p>\u7b80\u5355\u6765\u8bf4\u8fd9\u4e2a\u547d\u4ee4\u5c31\u662f\u53ef\u4ee5\u53cd\u590d\u7684\u8f93\u51fa\u4e00\u4e2a\u5b57\u7b26\u4e32, \u8fd9\u4e2a\u5b57\u7b26\u4e32\u7684\u9ed8\u8ba4\u503c\u662f <code>y<\/code><\/p>\n<p>\u4e8e\u662f\u6709\u4e86\u4e00\u4e9b\u7279\u522b\u7684\u7528\u6cd5, \u6bd4\u5982, \u6ce8\u610f\u8fd9\u91cc\u6ca1\u6709 <code>f<\/code><\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">yes<\/span><span class=\"z-l-8 z-d-10\"> |<\/span><span class=\"z-l-6 z-d-7\"> rm<\/span><span class=\"z-l-1 z-d-4\"> -<\/span><span class=\"z-l-1 z-d-4\">r<\/span><span class=\"z-l-2 z-d-6\"> \/<\/span><\/span><\/code><\/pre>\n<p>\u8fd8\u6709<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">yes<\/span><span> $(<\/span><span class=\"z-l-6 z-d-7\">yes<\/span><span class=\"z-l-2 z-d-6\"> yes<\/span><span>)<\/span><\/span><\/code><\/pre>\n<p>\u597d\u5b69\u5b50\u4e0d\u8981\u4e71\u8bd5<\/p>\n<p>\u5f53\u7136\u8fd9\u4e2a\u547d\u4ee4\u7684\u6548\u679c\u5176\u5b9e\u4e00\u822c\u90fd\u6709\u66ff\u4ee3, \u6bd4\u5982\u52a0\u4e0a <code>-f<\/code>, <code>-y<\/code> \u4ec0\u4e48\u7684, \u751f\u6210\u4e00\u4e2a\u5927\u6587\u4ef6\u4e5f\u53ef\u4ee5\u7528 <code>\/dev\/urandom<\/code> \u6765\u505a<\/p>\n<p>\u8fd8\u53ef\u4ee5\u5728\u51ac\u5929\u505a\u6696\u624b\u5b9d, \u5657<\/p>\n<p>\u6700\u540e, \u8ddf\u6211\u4e00\u8d77\u5728\u547d\u4ee4\u884c\u8f93\u5165<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">yes<\/span><span class=\"z-l-2 z-d-6\"> &#39;<\/span><span class=\"z-l-2 z-d-6\">AMD, yes!<\/span><span class=\"z-l-2 z-d-6\">&#39;<\/span><\/span><\/code><\/pre>\n<p>\u679c\u7136\u4eba\u7c7b\u7684\u672c\u8d28\u5c31\u662f\u590d\u8bfb\u673a<\/p>\n"},{"title":"\u91cd\u65b0\u5f00\u59cb","published":"2018-09-17T23:26:20+08:00","updated":"2018-09-17T23:26:20+08:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/restart\/"}},"id":"https:\/\/memwey.github.io\/posts\/restart\/","content":"<p>\u65b0\u7684\u535a\u5ba2, \u91cd\u65b0\u5f00\u59cb<\/p>\n<p>\u8fd9\u6b21\u5c1d\u8bd5\u7740\u575a\u6301\u4e00\u4e0b\u5427<\/p>\n"},{"title":"\u7ea2\u9ed1\u6811\u7b14\u8bb0","published":"2016-09-13T23:32:27+08:00","updated":"2016-09-13T23:32:27+08:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/red-black-tree\/"}},"id":"https:\/\/memwey.github.io\/posts\/red-black-tree\/","content":"<p>\u6700\u8fd1\u7814\u7a76\u4e86\u4e00\u4e0b\u7ea2\u9ed1\u6811\u7684\u4e00\u4e9b\u6027\u8d28\u548c\u601d\u60f3, \u5728\u8fd9\u91cc\u8bb0\u5f55\u4e00\u4e0b.<\/p>\n<p>Map, \u6216\u8005\u5728 <code>Python<\/code> \u7b49\u4e00\u4e9b\u8bed\u8a00\u4e2d\u53eb\u505a dictionary \u7684\u5e38\u7528\u7684\u4ee5\u952e\u503c\u5bf9\u5f62\u5f0f\u50a8\u5b58\u7684\u6570\u636e\u7ed3\u6784\u4e00\u822c\u6709\u4e24\u79cd\u5b9e\u73b0\u65b9\u5f0f, \u5728 <code>C++<\/code> \u7684 <code>STL<\/code> \u4e2d\u4f7f\u7528\u4e86\u7ea2\u9ed1\u6811\u7684\u65b9\u5f0f, \u800c\u5728<code>Python<\/code>\u4e2d\u4f7f\u7528\u4e86\u54c8\u5e0c\u8868\u7684\u65b9\u5f0f.<\/p>\n<p>\u4e00\u822c\u8ba4\u4e3a\u91c7\u7528\u54c8\u5e0c\u8868\u7684\u65b9\u5f0f\u67e5\u627e\u5220\u9664\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a <code>O(1)<\/code>, \u800c\u7ea2\u9ed1\u6811\u4e3a <code>O(logn)<\/code>.<\/p>\n<p><code>Python<\/code> \u4e2d\u7684\u54c8\u5e0c\u8868\u4f7f\u7528\u5f00\u653e\u5bfb\u5740\u6cd5\u89e3\u51b3\u51b2\u7a81.<\/p>\n<p>\u5bf9\u4e8e\u666e\u901a\u7684\u4e8c\u53c9\u67e5\u627e\u6811\u6765\u8bf4, \u67e5\u627e\u548c\u63d2\u5165\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5728\u6700\u574f\u7684\u60c5\u51b5\u4e0b\u53ef\u80fd\u4f1a\u53d8\u6210 <code>O(n)<\/code>, \u5373\u5b8c\u5168\u504f\u5411\u4e00\u8fb9\u7684\u4e0d\u5e73\u8861\u60c5\u51b5\u4f7f\u5176\u6210\u4e3a\u4e00\u4e2a\u5355\u94fe\u8868. \u5982\u679c\u53ea\u662f\u5728\u6811\u7684\u53f6\u5b50\u4e0a\u589e\u52a0\u8282\u70b9\u800c\u4e0d\u8fdb\u884c\u5176\u4ed6\u7684\u8c03\u6574, \u5f88\u5bb9\u6613\u4f1a\u4f7f\u53ea\u5411\u4e0b\u589e\u957f\u7684\u6811\u4e0d\u5e73\u8861. \u4e3a\u4e86\u4fdd\u8bc1 <code>O(logn)<\/code> \u7684\u65f6\u95f4\u590d\u6742\u5ea6, \u6211\u4eec\u9700\u8981\u4e00\u79cd\u52a8\u6001\u7684\u673a\u5236, \u6765\u8c03\u6574\u6811\u7684\u7236\u8282\u70b9, \u4e43\u81f3\u4e8e\u6839\u8282\u70b9.<\/p>\n<p>\u7ea2\u9ed1\u6811\u662f\u4e00\u79cd\u52a8\u6001\u8c03\u6574\u7684\u5b9e\u73b0\u65b9\u5f0f. \u7ea2\u9ed1\u6811\u5176\u5b9e\u662f\u5728 <code>2, 3-\u6811<\/code> \u7684\u57fa\u7840\u4e0a\u5b9e\u73b0\u7684. \u4ed6\u4eec\u4e5f\u5b8c\u5168\u53ef\u4ee5\u7b49\u4ef7\u7684\u8f6c\u6362. \u4e0d\u8fc7 <code>2, 3-\u6811<\/code> \u5728\u7a0b\u5e8f\u7684\u5b9e\u73b0\u4e0a\u6bd4\u8f83\u590d\u6742, \u800c\u4e14\u67e5\u627e\u64cd\u4f5c\u4e5f\u548c\u4e8c\u53c9\u641c\u7d22\u6811\u6709\u4e00\u4e9b\u4e0d\u540c, \u6240\u4ee5\u5728\u7a0b\u5e8f\u5b9e\u73b0\u4e2d\u4e00\u822c\u4f7f\u7528\u7ea2\u9ed1\u6811.<\/p>\n<p><code>2, 3-\u6811<\/code> \u548c\u7ea2\u9ed1\u6811\u4ed6\u4eec\u5171\u540c\u7684\u601d\u60f3\u662f, \u5c06\u6811\u7684\u53f6\u5b50\u8282\u70b9\u4e0a\u7684\u64cd\u4f5c\u9020\u6210\u7684\u5f71\u54cd, \u9010\u6b65\u7684\u4f20\u9012\u7ed9\u7236\u8282\u70b9, \u6309\u7167\u4e00\u5b9a\u7684\u65b9\u5f0f\u5bf9\u5f53\u524d\u5b50\u6811\u8fdb\u884c\u8c03\u6574. \u7236\u8282\u70b9\u518d\u4f20\u9012\u7ed9\u5b83\u7684\u7236\u8282\u70b9, \u8c03\u6574\u66f4\u5927\u4e00\u4e9b\u7684\u5b50\u6811. \u6700\u7ec8\u4f20\u9012\u5230\u6839\u8282\u70b9, \u8c03\u6574\u6574\u9897\u6811.<\/p>\n<p>\u53ef\u4ee5\u8fd9\u6837\u7406\u89e3, \u5728\u7ea2\u9ed1\u6811\u4e2d, \u7528\u7ea2\u8272\u6765\u6807\u8bb0\u6b63\u5728\u7d2f\u8ba1\u8c03\u6574\u7684\u8282\u70b9. \u5f53\u8282\u70b9M\u7684\u4e24\u4e2a\u5b50\u8282\u70b9\u5747\u88ab\u6807\u8bb0, \u5219M\u53d6\u6d88\u5b50\u8282\u70b9\u7684\u6807\u8bb0, \u5e76\u6807\u8bb0\u81ea\u5df1, \u4f7f\u8c03\u6574\u5411\u6839\u8282\u70b9\u4f20\u9012.<\/p>\n"},{"title":"\u5728CentOS\u4e0a\u4f7f\u7528\u8f83\u65b0\u7684\u8f6f\u4ef6","published":"2016-08-02T23:30:33+08:00","updated":"2025-02-15T23:30:33+09:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/centos-latest-software\/"}},"id":"https:\/\/memwey.github.io\/posts\/centos-latest-software\/","content":"<blockquote>\n<p><strong>\u66f4\u65b0\u4e8e 2025-02-15:<\/strong> <a rel=\"external\" href=\"https:\/\/ius.io\/faq\">IUS \u5b98\u65b9 FAQ<\/a> \u5df2\u660e\u786e\u8bf4\u660e\u8be5\u9879\u76ee\u4e0d\u518d\u7ef4\u62a4, \u5386\u53f2\u8f6f\u4ef6\u5305\u4ec5\u4fdd\u5b58\u5728 IUS Vault. \u672c\u6587\u4f7f\u7528\u7684 CentOS 6 \u4ed3\u5e93\u548c\u5b89\u88c5\u547d\u4ee4\u5747\u5df2\u5931\u6548, \u8bf7\u52ff\u5728\u65b0\u73af\u5883\u4e2d\u7ee7\u7eed\u4f7f\u7528; \u6b63\u6587\u4ec5\u4f5c\u4e3a\u5386\u53f2\u8bb0\u5f55\u4fdd\u7559. \u65b0\u73af\u5883\u5e94\u9009\u62e9\u4ecd\u53d7\u652f\u6301\u7684\u64cd\u4f5c\u7cfb\u7edf\u7248\u672c\u53ca\u5176\u5b98\u65b9\u8f6f\u4ef6\u6e90, \u6216\u8f6f\u4ef6\u4f9b\u5e94\u65b9\u4ecd\u5728\u7ef4\u62a4\u7684\u8f6f\u4ef6\u6e90.<\/p>\n<\/blockquote>\n<p>\u516c\u53f8\u7684\u670d\u52a1\u5668\u90fd\u662f <code>CentOS<\/code> \u7684, \u5e26\u7684\u8f6f\u4ef6\u90fd\u6bd4\u8f83\u65e7, \u8ba9\u6211\u8fd9\u4e2a\u4e0d\u66f4\u65b0\u4f1a\u6b7b\u661f\u4eba\u5f88\u96be\u8fc7\u554a.<\/p>\n<p>\u5f00\u73a9\u7b11\u7684, \u4e3b\u8981\u95ee\u9898\u662f <code>git<\/code> \u7248\u672c\u592a\u65e7, <code>clone<\/code> \u7684\u65f6\u5019\u4f1a\u62a5\u9519, \u7136\u540e\u4e5f\u9700\u8981 <code>python3.5<\/code>. \u5728 <code>git<\/code> \u4e0a\u9762\u53d1\u73b0 <a rel=\"external\" href=\"https:\/\/ius.io\/\">ius<\/a> \u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898.<\/p>\n<p><a rel=\"external\" href=\"https:\/\/ius.io\/\">ius<\/a> \u662f\u4e00\u4e2a\u793e\u533a\u9879\u76ee, \u76ee\u7684\u662f\u4e3a <a rel=\"external\" href=\"https:\/\/www.kernel.org\/\">Linux<\/a> \u7684\u4f01\u4e1a\u53d1\u884c\u7248\u63d0\u4f9b\u4e00\u4e9b\u66f4\u65b0\u7248\u672c\u7684RPM\u5305.<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">sudo<\/span><span class=\"z-l-2 z-d-6\"> yum<\/span><span class=\"z-l-2 z-d-6\"> install<\/span><span class=\"z-l-2 z-d-6\"> epel-release<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">sudo<\/span><span class=\"z-l-2 z-d-6\"> yum<\/span><span class=\"z-l-2 z-d-6\"> install<\/span><span class=\"z-l-2 z-d-6\"> https:\/\/centos6.iuscommunity.org\/ius-release.rpm<\/span><\/span><\/code><\/pre>\n<p>\u4e3a\u4e86\u89e3\u51b3\u4e00\u4e9b\u51b2\u7a81\u548c\u5171\u5b58\u7684\u95ee\u9898, \u6709\u4e00\u4e9b <code>package<\/code> \u5728 <a rel=\"external\" href=\"https:\/\/ius.io\/\">ius<\/a> \u4e2d\u7684\u5305\u540d\u6709\u4e00\u4e9b\u6539\u52a8<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">sudo<\/span><span class=\"z-l-2 z-d-6\"> yum<\/span><span class=\"z-l-2 z-d-6\"> install<\/span><span class=\"z-l-2 z-d-6\"> git2u<\/span><\/span>\n<span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">sudo<\/span><span class=\"z-l-2 z-d-6\"> yum<\/span><span class=\"z-l-2 z-d-6\"> install<\/span><span class=\"z-l-2 z-d-6\"> python35u<\/span><\/span><\/code><\/pre>\n<p>\u4e00\u822c\u7684\u547d\u540d\u89c4\u5219\u662f<\/p>\n<p><code>{name}{major_version}{minor_version}u<\/code><\/p>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u5728 <code>CentOS<\/code> \u4e0a\u4f7f\u7528\u8f83\u65b0\u7684\u8f6f\u4ef6\u5566.<\/p>\n"},{"title":"Linux\u540e\u53f0\u547d\u4ee4","published":"2016-06-15T23:28:24+08:00","updated":"2016-06-15T23:28:24+08:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/linux-backgroud\/"}},"id":"https:\/\/memwey.github.io\/posts\/linux-backgroud\/","content":"<p>\u6700\u8fd1\u5728\u8dd1 DHT \u7f51\u7edc\u62df\u771f\u7684\u65f6\u5019\u6d89\u53ca\u5230\u4e00\u4e9b linux \u540e\u53f0\u8fd0\u884c\u7684\u4e00\u4e9b\u4e1c\u897f,\u73b0\u5728\u603b\u7ed3\u4e00\u4e0b<\/p>\n<p>\u4f8b\u5982<\/p>\n<pre class=\"giallo z-l-code z-d-code\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span class=\"z-l-6 z-d-7\">nohup<\/span><span class=\"z-l-2 z-d-6\"> ..\/src\/OverSim<\/span><span class=\"z-l-1 z-d-4\"> -<\/span><span class=\"z-l-1 z-d-4\">c<\/span><span class=\"z-l-2 z-d-6\"> ChordChurn<\/span><span class=\"z-l-1 z-d-4\"> -<\/span><span class=\"z-l-1 z-d-4\">u<\/span><span class=\"z-l-2 z-d-6\"> Cmdenv<\/span><span class=\"z-l-8 z-d-10\"> &gt;<\/span><span class=\"z-l-2 z-d-6\"> out.file<\/span><span class=\"z-l-8 z-d-10\"> 2<\/span><span class=\"z-l-8 z-d-10\">&gt;&amp;1<\/span><span> &amp;<\/span><\/span><\/code><\/pre>\n<p>\u4f7f\u5f97 <code>..\/src\/OverSim -c ChordChurn -u Cmdenv<\/code> \u547d\u4ee4\u5728\u540e\u53f0\u8fd0\u884c,\u5e76\u5c06 <code>stderr<\/code> \u91cd\u5b9a\u5411\u5230 <code>stdout<\/code> \u4e2d\u7136\u540e\u518d\u5c06 <code>stdout<\/code> \u91cd\u5b9a\u5411\u5230 <code>out.file<\/code>, \u5e76\u4e14\u5728\u5f53\u524d\u7ec8\u7aef\u5173\u95ed\u65f6\u4ecd\u7136\u8fd0\u884c<\/p>\n<p>\u5177\u4f53\u8bf4\u4e00\u4e0b\u5427<\/p>\n<h2 id=\"nohup\"><a class=\"zola-anchor\" href=\"#nohup\" aria-label=\"Anchor link for: nohup\">nohup<\/a><\/h2>\n<p>\u9000\u51fa\u7ec8\u7aef\u7684\u65f6\u5019,\u4e00\u822c\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u7684\u8fdb\u7a0b\u4f1a\u968f\u4e4b\u5173\u95ed,\u56e0\u4e3a\u6b64\u65f6\u7ec8\u7aef\u4e2d\u7684\u5b50\u8fdb\u7a0b\u4f1a\u6536\u5230 <code>SIGHUP<\/code> \u4fe1\u53f7. \u800c <code>nohup<\/code> \u4f7f\u5f97\u8fdb\u7a0b\u5ffd\u7565\u6240\u6709 <code>SIGHUP<\/code> \u4fe1\u53f7. <code>stdout<\/code> \u9ed8\u8ba4\u4f1a\u91cd\u5b9a\u5411\u5230 <code>nohup.out<\/code> \u6587\u4ef6\u4e2d<\/p>\n<h2 id=\"\"><a class=\"zola-anchor\" href=\"#\" aria-label=\"Anchor link for: \">&amp;<\/a><\/h2>\n<p>\u5728\u547d\u4ee4\u4e2d\u672b\u5c3e\u52a0\u5165 <code>&amp;<\/code> \u7b26\u53f7,\u4f7f\u8fdb\u7a0b\u5728\u540e\u53f0\u8fd0\u884c<\/p>\n<h2 id=\"2-1\"><a class=\"zola-anchor\" href=\"#2-1\" aria-label=\"Anchor link for: 2-1\">2&gt;&amp;1<\/a><\/h2>\n<p>\u653e\u5728 <code>&gt;<\/code> \u540e\u9762\u7684 <code>&amp;<\/code>, \u8868\u793a\u91cd\u5b9a\u5411\u7684\u76ee\u6807\u4e0d\u662f\u4e00\u4e2a\u6587\u4ef6, \u800c\u662f\u4e00\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26, \u6587\u4ef6\u63cf\u8ff0\u7b26<\/p>\n<ul>\n<li><code>1 =&gt; stdout<\/code><\/li>\n<li><code>2 =&gt; stderr<\/code><\/li>\n<li><code>0 =&gt; stdin<\/code><\/li>\n<\/ul>\n<h2 id=\"qi-ta-yi-xie-ming-ling-he-cao-zuo\"><a class=\"zola-anchor\" href=\"#qi-ta-yi-xie-ming-ling-he-cao-zuo\" aria-label=\"Anchor link for: qi-ta-yi-xie-ming-ling-he-cao-zuo\">\u5176\u4ed6\u4e00\u4e9b\u547d\u4ee4\u548c\u64cd\u4f5c<\/a><\/h2>\n<p><code>Control+z<\/code> \u53ef\u4ee5\u53d1\u51fa <code>SIGSTOP<\/code> \u4fe1\u53f7, \u4f7f\u5f53\u524d\u524d\u53f0\u8fdb\u7a0b\u6682\u505c\u5e76\u653e\u5165\u540e\u53f0<\/p>\n<p><code>fg [job_id]<\/code>\u4f7f\u8fdb\u7a0b\u5728\u524d\u53f0\u8fd0\u884c<\/p>\n<p><code>bg [job_id]<\/code>\u4f7f\u8fdb\u7a0b\u5728\u540e\u53f0\u8fd0\u884c<\/p>\n<p><code>jobs<\/code> \u67e5\u770b\u540e\u53f0\u8fdb\u7a0b<\/p>\n"},{"title":"\u7b2c\u4e00\u7bc7\u535a\u5ba2","published":"2016-06-14T23:22:32+08:00","updated":"2016-06-14T23:22:32+08:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/posts\/first-blog\/"}},"id":"https:\/\/memwey.github.io\/posts\/first-blog\/","content":"<p>\u5176\u5b9e\u5f88\u65e9\u5c31\u60f3\u5f04\u4e2a\u535a\u5ba2\u4ec0\u4e48\u7684, \u89c9\u5f97\u6709\u4e9b\u4e1c\u897f\u8d39\u4e86\u5f88\u5927\u7684\u529b\u6c14\u89e3\u51b3\u4e86, \u7136\u540e\u4e45\u800c\u4e45\u4e4b\u5c31\u5fd8\u4e86......\u8bb0\u5f55\u4e0b\u6765\u5e94\u8be5\u4f1a\u597d\u4e00\u70b9\u5427, \u8fd9\u6837\u89c9\u5f97.<\/p>\n<p>\u6240\u4ee5\u8fd8\u662f\u5199\u4e00\u4e9b\u4e1c\u897f\u5427, \u55ef\u55ef......<\/p>\n<p>\u5176\u5b9e\u8fd8\u662f\u4e0d\u592a\u559c\u6b22\u8fd9\u79cd\u4e0d\u600e\u4e48\u80fd\u81ea\u5df1\u5b9a\u5236\u7684\u4e1c\u897f......\u603b\u6709\u4e00\u79cd\u4e0d\u77e5\u6240\u63aa\u7684\u611f\u89c9......\u81ea\u5df1\u5199\u4e00\u4e2a\u540e\u53f0\u5012\u662f\u6ca1\u4ec0\u4e48\u95ee\u9898, \u524d\u7aef\u7684\u8bdd\u5c31\u5b9e\u5728\u662f\u65e0\u529b\u4e86, \u5657<\/p>\n<p>\u5bf9 Markdown \u7684\u8bed\u6cd5\u8fd8\u4e0d\u90a3\u4e48\u719f\u6089, \u800c\u4e14\u597d\u50cf Markdown \u6709\u4e00\u4e9b\u4e0d\u540c\u7684\u89e3\u91ca\u5668, \u5f88\u9ebb\u70e6\u554a<\/p>\n<p>\u6bcf\u6b21\u751f\u6210\u7684\u9759\u6001\u7f51\u9875\u8fd8\u8981\u5728\u672c\u5730\u751f\u6210\u4e86\u4e4b\u540e\u770b\u8fc7\u6548\u679c......\u554a, \u771f\u7684\u5f88\u9ebb\u70e6<\/p>\n"},{"title":"\u5173\u4e8e","published":"2016-06-14T00:00:00+00:00","updated":"2025-11-13T00:00:00+00:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/about\/"}},"id":"https:\/\/memwey.github.io\/about\/","content":"<p>Gopher &amp; Pythonista<\/p>\n<h2 id=\"guan-yu-bo-ke\">\u5173\u4e8e\u535a\u5ba2<\/h2>\n<ul>\n<li>\u5e94\u8be5\u4e5f\u8bb8\u5927\u6982\u4f1a\u5728\u8fd9\u91cc\u505a\u4e00\u4e9b\u6280\u672f\u65b9\u9762\u7684\u7b14\u8bb0 _(:_\u300d\u2220)_<\/li>\n<li>\u56e0\u4e3a\u62d6\u5ef6\u75c7\u4e25\u91cd\u7684\u4e0d\u884c\u6240\u4ee5\u53ef\u80fd\u4e0d\u4f1a\u7ecf\u5e38\u66f4\u65b0......\u5514, \u52aa\u529b\u66f4\u65b0\u4e00\u4e0b\u5427<\/li>\n<li>\u5076\u5c14\u804a\u804a\u5386\u53f2, \u5e0c\u671b\u53ef\u4ee5\u8bb0\u5f55\u4e00\u4e9b\u8fd1\u73b0\u4ee3\u7684\u4e8b\u60c5, \u7528\u4ee5\u5b58\u53f2<\/li>\n<\/ul>\n<h2 id=\"guan-yu-gong-zuo\">\u5173\u4e8e\u5de5\u4f5c<\/h2>\n<h3 id=\"xian-zai-de\">\u73b0\u5728\u7684<\/h3>\n<ul>\n<li>\u958b\u767a @<a rel=\"external\" href=\"https:\/\/www.netstars.co.jp\/\">\u682a\u5f0f\u4f1a\u793e\u30cd\u30c3\u30c8\u30b9\u30bf\u30fc\u30ba<\/a> @\u4e1c\u4eac, \u65e5\u672c<\/li>\n<\/ul>\n<h3 id=\"ceng-jing-de\">\u66fe\u7ecf\u7684<\/h3>\n<ul>\n<li>\u4e2d\u7ea7\u8fd0\u7ef4\u5f00\u53d1\u5de5\u7a0b\u5e08 @<a rel=\"external\" href=\"https:\/\/www.datastory.com.cn\/\">\u6570\u8bf4\u6545\u4e8b<\/a> @\u5e7f\u5dde, \u4e2d\u56fd<\/li>\n<li>\u540e\u7aef\u5f00\u53d1\u5de5\u7a0b\u5e08 @\u753b\u97f3 @\u5e7f\u5dde, \u4e2d\u56fd<\/li>\n<li>\u540e\u7aef\u5f00\u53d1\u5de5\u7a0b\u5e08 @\u58c1\u864e\u79d1\u6280 @\u5e7f\u5dde, \u4e2d\u56fd<\/li>\n<li>Senior Engineer @<a rel=\"external\" href=\"https:\/\/www.bigo.sg\/\">BIGO<\/a> @\u5e7f\u5dde, \u4e2d\u56fd<\/li>\n<li>Python Engineer @<a rel=\"external\" href=\"https:\/\/www.akulaku.com\/\">Akulaku<\/a> @\u6df1\u5733, \u4e2d\u56fd<\/li>\n<li>\u670d\u52a1\u5668\u7aef\u5f00\u53d1\u5de5\u7a0b\u5e08 @<a rel=\"external\" href=\"https:\/\/www.cmcm.com\/\">\u730e\u8c79\u79fb\u52a8<\/a> @\u73e0\u6d77, \u4e2d\u56fd<\/li>\n<li>Python \u5f00\u53d1\u5b9e\u4e60\u751f @<a rel=\"external\" href=\"http:\/\/www.cnicg.cn\/\">\u5e7f\u5dde\u4e2d\u56fd\u79d1\u5b66\u9662\u8ba1\u7b97\u673a\u7f51\u7edc\u4fe1\u606f\u4e2d\u5fc3<\/a> @\u5e7f\u5dde, \u4e2d\u56fd<\/li>\n<\/ul>\n<h2 id=\"guan-yu-jiao-yu\">\u5173\u4e8e\u6559\u80b2<\/h2>\n<ul>\n<li>\u5b66\u751f @<a rel=\"external\" href=\"https:\/\/www.jnu.edu.cn\/\">\u66a8\u5357\u5927\u5b66<\/a> @\u5e7f\u5dde, \u4e2d\u56fd<\/li>\n<li>\u5b66\u751f @<a rel=\"external\" href=\"http:\/\/www.shimen.org\/\">\u77f3\u95e8\u4e2d\u5b66<\/a> @\u4f5b\u5c71, \u4e2d\u56fd<\/li>\n<\/ul>\n"},{"title":"\u94fe\u63a5","published":"2016-06-14T00:00:00+00:00","updated":"2025-09-07T00:00:00+00:00","author":{"name":"Unknown"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/memwey.github.io\/link\/"}},"id":"https:\/\/memwey.github.io\/link\/","content":"<ul>\n<li><a rel=\"external\" href=\"https:\/\/leoeatle.github.io\">LeoEatle's World<\/a><\/li>\n<\/ul>\n"}]}