{"@attributes":{"version":"2.0"},"channel":{"title":"Morgoth","link":"https:\/\/canuxcheng.com\/","description":"Recent content on Morgoth","generator":"Hugo -- gohugo.io","language":"zh-CN","lastBuildDate":"Wed, 22 Jul 2026 10:00:00 +0800","item":[{"title":"LangGraph","link":"https:\/\/canuxcheng.com\/post\/ai_langgraph\/","pubDate":"Wed, 22 Jul 2026 10:00:00 +0800","guid":"https:\/\/canuxcheng.com\/post\/ai_langgraph\/","description":"<p>LangGraph \u662f\u4e00\u4e2a\u7528\u4e8e\u6784\u5efa\u6709\u72b6\u6001 Agent \u7684\u5e95\u5c42\u7f16\u6392\u6846\u67b6\u3002\u5b83\u628a Agent \u7684\u6267\u884c\u8fc7\u7a0b\u63cf\u8ff0\u6210\u4e00\u5f20\u56fe\uff1a\u72b6\u6001\u5728\u8282\u70b9\u4e4b\u95f4\u6d41\u52a8\uff0c\u8fb9\u51b3\u5b9a\u4e0b\u4e00\u6b65\u6267\u884c\u54ea\u4e2a\u8282\u70b9\uff0c\u76f4\u5230\u4efb\u52a1\u5b8c\u6210\u3002<\/p>\n<p>\u666e\u901a\u7684\u804a\u5929\u7a0b\u5e8f\u901a\u5e38\u53ea\u6709\u4e00\u6b21\u6a21\u578b\u8c03\u7528\uff0c\u800c Agent \u4f1a\u4e0d\u65ad\u91cd\u590d\u201c\u601d\u8003\u3001\u8c03\u7528\u5de5\u5177\u3001\u8bfb\u53d6\u7ed3\u679c\u3001\u7ee7\u7eed\u601d\u8003\u201d\u7684\u5faa\u73af\u3002\u968f\u7740\u6d41\u7a0b\u53d8\u957f\uff0c\u6211\u4eec\u8fd8\u4f1a\u9047\u5230\u5206\u652f\u3001\u91cd\u8bd5\u3001\u6301\u4e45\u5316\u3001\u4eba\u5de5\u5ba1\u6279\u548c\u6545\u969c\u6062\u590d\u7b49\u95ee\u9898\u3002LangGraph \u7684\u4ef7\u503c\u5c31\u662f\u8ba9\u8fd9\u4e9b\u63a7\u5236\u903b\u8f91\u53d8\u5f97\u663e\u5f0f\u3001\u53ef\u8ffd\u8e2a\u548c\u53ef\u6062\u590d\u3002<\/p>\n<h2 id=\"langgraph-\u4e0e-langchain\">LangGraph \u4e0e LangChain<\/h2>\n<p>LangChain \u548c LangGraph \u89e3\u51b3\u7684\u95ee\u9898\u5e76\u4e0d\u5b8c\u5168\u76f8\u540c\uff1a<\/p>\n<ul>\n<li>LangChain \u63d0\u4f9b\u6a21\u578b\u3001Prompt\u3001Tool\u3001Retriever \u548c\u9884\u6784\u5efa Agent \u7b49\u9ad8\u5c42\u62bd\u8c61\uff1b<\/li>\n<li>LangGraph \u63d0\u4f9b\u72b6\u6001\u56fe\u3001\u6301\u4e45\u5316\u3001\u6d41\u5f0f\u6267\u884c\u548c Human-in-the-loop \u7b49\u7f16\u6392\u80fd\u529b\uff1b<\/li>\n<li>LangSmith \u7528\u4e8e\u8ffd\u8e2a\u3001\u8bc4\u4f30\u548c\u89c2\u5bdf Agent \u7684\u6267\u884c\u8fc7\u7a0b\u3002<\/li>\n<\/ul>\n<p>\u5982\u679c\u53ea\u662f\u5f00\u53d1\u6807\u51c6\u7684 ReAct Agent\uff0cLangChain \u7684 <code>create_agent<\/code> \u901a\u5e38\u66f4\u7b80\u5355\u3002\u5982\u679c\u9700\u8981\u81ea\u5b9a\u4e49\u6267\u884c\u8def\u5f84\u3001\u5ba1\u6279\u8282\u70b9\u3001\u5e76\u884c\u4efb\u52a1\u6216\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u5de5\u4f5c\u6d41\uff0c\u518d\u76f4\u63a5\u4f7f\u7528 LangGraph\u3002<\/p>\n<h2 id=\"\u6838\u5fc3\u6982\u5ff5\">\u6838\u5fc3\u6982\u5ff5<\/h2>\n<p>\u4e00\u5f20 LangGraph \u4e3b\u8981\u7531\u4e09\u4e2a\u90e8\u5206\u7ec4\u6210\u3002<\/p>\n<h3 id=\"state\">State<\/h3>\n<p>State \u662f\u6574\u4e2a\u5de5\u4f5c\u6d41\u5171\u4eab\u7684\u6570\u636e\u3002\u5b83\u53ef\u4ee5\u4fdd\u5b58\u6d88\u606f\u3001\u7528\u6237\u4fe1\u606f\u3001\u4e2d\u95f4\u7ed3\u679c\u3001\u91cd\u8bd5\u6b21\u6570\u6216\u5ba1\u6279\u72b6\u6001\u3002<\/p>\n<p>\u8282\u70b9\u4e0d\u5e94\u8be5\u968f\u610f\u4fee\u6539 State\uff0c\u800c\u662f\u8fd4\u56de\u9700\u8981\u66f4\u65b0\u7684\u90e8\u5206\u3002LangGraph \u4f1a\u6839\u636e State Schema \u548c Reducer \u5408\u5e76\u66f4\u65b0\u3002<\/p>\n<h3 id=\"node\">Node<\/h3>\n<p>Node \u662f\u6267\u884c\u5b9e\u9645\u5de5\u4f5c\u7684\u51fd\u6570\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>\u8c03\u7528 LLM\uff1b<\/li>\n<li>\u6267\u884c Tool\uff1b<\/li>\n<li>\u67e5\u8be2\u6570\u636e\u5e93\uff1b<\/li>\n<li>\u68c0\u67e5\u6743\u9650\uff1b<\/li>\n<li>\u7b49\u5f85\u4eba\u5de5\u5ba1\u6279\u3002<\/li>\n<\/ul>\n<p>\u8282\u70b9\u8bfb\u53d6\u5f53\u524d State\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u5c40\u90e8 State \u66f4\u65b0\u3002<\/p>\n<h3 id=\"edge\">Edge<\/h3>\n<p>Edge \u51b3\u5b9a\u8282\u70b9\u4e4b\u95f4\u7684\u6267\u884c\u987a\u5e8f\uff1a<\/p>\n<ul>\n<li>\u666e\u901a Edge \u56fa\u5b9a\u8df3\u8f6c\u5230\u4e0b\u4e00\u4e2a\u8282\u70b9\uff1b<\/li>\n<li>Conditional Edge \u6839\u636e State \u52a8\u6001\u9009\u62e9\u8def\u5f84\uff1b<\/li>\n<li><code>START<\/code> \u548c <code>END<\/code> \u5206\u522b\u8868\u793a\u56fe\u7684\u5165\u53e3\u548c\u7ed3\u675f\u3002<\/li>\n<\/ul>\n<p>\u4e00\u4e2a Tool-calling Agent \u7684\u56fe\u901a\u5e38\u5982\u4e0b\uff1a<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-text\" data-lang=\"text\"><span style=\"display:flex;\"><span>START\n<\/span><\/span><span style=\"display:flex;\"><span> \u2502\n<\/span><\/span><span style=\"display:flex;\"><span> \u25bc\n<\/span><\/span><span style=\"display:flex;\"><span>Agent Node \u2500\u2500\u2500 \u65e0\u5de5\u5177\u8c03\u7528 \u2500\u2500\u2500\u25b6 END\n<\/span><\/span><span style=\"display:flex;\"><span> \u2502\n<\/span><\/span><span style=\"display:flex;\"><span> \u2502 \u6709\u5de5\u5177\u8c03\u7528\n<\/span><\/span><span style=\"display:flex;\"><span> \u25bc\n<\/span><\/span><span style=\"display:flex;\"><span>Tool Node\n<\/span><\/span><span style=\"display:flex;\"><span> \u2502\n<\/span><\/span><span style=\"display:flex;\"><span> \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u25b6 Agent Node\n<\/span><\/span><\/code><\/pre><\/div><p>\u6a21\u578b\u53ef\u4ee5\u8fde\u7eed\u8c03\u7528\u591a\u4e2a\u5de5\u5177\u3002\u53ea\u6709\u5f53\u6a21\u578b\u8fd4\u56de\u6700\u7ec8\u7b54\u6848\u3001\u4e0d\u518d\u4ea7\u751f Tool Call \u65f6\uff0c\u56fe\u624d\u4f1a\u8fdb\u5165 <code>END<\/code>\u3002<\/p>\n<h2 id=\"\u5f00\u53d1\u4e00\u4e2a-agent\">\u5f00\u53d1\u4e00\u4e2a Agent<\/h2>\n<p>\u4e0b\u9762\u5f00\u53d1\u4e00\u4e2a\u7b80\u5355\u7684\u5929\u6c14 Agent\u3002\u6a21\u578b\u8d1f\u8d23\u7406\u89e3\u7528\u6237\u610f\u56fe\uff0cTool \u8d1f\u8d23\u8fd4\u56de\u5929\u6c14\u4fe1\u606f\uff0cLangGraph \u8d1f\u8d23\u63a7\u5236\u6a21\u578b\u548c Tool \u4e4b\u95f4\u7684\u5faa\u73af\u3002<\/p>\n<h3 id=\"\u5b89\u88c5\u4f9d\u8d56\">\u5b89\u88c5\u4f9d\u8d56<\/h3>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-bash\" data-lang=\"bash\"><span style=\"display:flex;\"><span>python -m venv .venv\n<\/span><\/span><span style=\"display:flex;\"><span>source .venv\/bin\/activate\n<\/span><\/span><span style=\"display:flex;\"><span>pip install -U langgraph langchain langchain-openai\n<\/span><\/span><\/code><\/pre><\/div><p>\u901a\u8fc7\u73af\u5883\u53d8\u91cf\u63d0\u4f9b\u6a21\u578b\u51ed\u636e\uff1a<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-bash\" data-lang=\"bash\"><span style=\"display:flex;\"><span>export OPENAI_API_KEY<span style=\"color:#f92672\">=<\/span><span style=\"color:#e6db74\">&#34;...&#34;<\/span>\n<\/span><\/span><\/code><\/pre><\/div><p>\u4e0d\u8981\u628a API Key \u5199\u5165\u4ee3\u7801\u6216\u63d0\u4ea4\u5230\u7248\u672c\u63a7\u5236\u3002<\/p>\n<h3 id=\"\u5b9a\u4e49-tool\">\u5b9a\u4e49 Tool<\/h3>\n<p>Tool \u662f Agent \u4e0e\u5916\u90e8\u4e16\u754c\u4ea4\u4e92\u7684\u63a5\u53e3\u3002\u771f\u5b9e\u9879\u76ee\u4e2d\u7684 Tool \u53ef\u4ee5\u8c03\u7528 API\u3001\u6570\u636e\u5e93\u6216\u5185\u90e8\u670d\u52a1\uff1b\u8fd9\u91cc\u4f7f\u7528\u9759\u6001\u6570\u636e\uff0c\u4f7f\u793a\u4f8b\u53ef\u4ee5\u4e13\u6ce8\u4e8e Agent \u7684\u6267\u884c\u903b\u8f91\u3002<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-python\" data-lang=\"python\"><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> langchain.tools <span style=\"color:#f92672\">import<\/span> tool\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#a6e22e\">@tool<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#66d9ef\">def<\/span> <span style=\"color:#a6e22e\">get_weather<\/span>(city: str) <span style=\"color:#f92672\">-&gt;<\/span> str:\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;&#34;&#34;\u67e5\u8be2\u57ce\u5e02\u5f53\u524d\u7684\u5929\u6c14\u3002&#34;&#34;&#34;<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> weather <span style=\"color:#f92672\">=<\/span> {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;\u5317\u4eac&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\u6674\uff0c26\u00b0C&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;\u4e0a\u6d77&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\u591a\u4e91\uff0c29\u00b0C&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;\u6df1\u5733&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\u9635\u96e8\uff0c31\u00b0C&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> }\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#66d9ef\">return<\/span> weather<span style=\"color:#f92672\">.<\/span>get(city, <span style=\"color:#e6db74\">f<\/span><span style=\"color:#e6db74\">&#34;\u6682\u65f6\u6ca1\u6709 <\/span><span style=\"color:#e6db74\">{<\/span>city<span style=\"color:#e6db74\">}<\/span><span style=\"color:#e6db74\"> \u7684\u5929\u6c14\u6570\u636e&#34;<\/span>)\n<\/span><\/span><\/code><\/pre><\/div><p>\u51fd\u6570\u7684\u7c7b\u578b\u6807\u6ce8\u548c Docstring \u4f1a\u6210\u4e3a Tool Schema \u7684\u4e00\u90e8\u5206\u3002\u63cf\u8ff0\u5e94\u8be5\u6e05\u6670\u8bf4\u660e\u5de5\u5177\u80fd\u505a\u4ec0\u4e48\uff0c\u4f46\u4e0d\u8981\u8ba9\u6a21\u578b\u770b\u5230\u5185\u90e8\u51ed\u636e\u6216\u4e0d\u9700\u8981\u7684\u53c2\u6570\u3002<\/p>\n<h3 id=\"\u5b9a\u4e49\u6a21\u578b\u8282\u70b9\">\u5b9a\u4e49\u6a21\u578b\u8282\u70b9<\/h3>\n<p>\u5c06 Tool \u7ed1\u5b9a\u5230\u6a21\u578b\u540e\uff0c\u6a21\u578b\u53ef\u4ee5\u9009\u62e9\u8fd4\u56de\u666e\u901a\u6d88\u606f\uff0c\u4e5f\u53ef\u4ee5\u8fd4\u56de\u7ed3\u6784\u5316 Tool Call\u3002<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-python\" data-lang=\"python\"><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> langchain.chat_models <span style=\"color:#f92672\">import<\/span> init_chat_model\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> langgraph.graph <span style=\"color:#f92672\">import<\/span> MessagesState\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>tools <span style=\"color:#f92672\">=<\/span> [get_weather]\n<\/span><\/span><span style=\"display:flex;\"><span>model <span style=\"color:#f92672\">=<\/span> init_chat_model(<span style=\"color:#e6db74\">&#34;openai:gpt-4.1-mini&#34;<\/span>)<span style=\"color:#f92672\">.<\/span>bind_tools(tools)\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#66d9ef\">def<\/span> <span style=\"color:#a6e22e\">call_model<\/span>(state: MessagesState):\n<\/span><\/span><span style=\"display:flex;\"><span> system_message <span style=\"color:#f92672\">=<\/span> {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;role&#34;<\/span>: <span style=\"color:#e6db74\">&#34;system&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;content&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\u4f60\u662f\u4e00\u4e2a\u5929\u6c14\u52a9\u624b\u3002\u9700\u8981\u5b9e\u65f6\u6570\u636e\u65f6\u8c03\u7528\u5de5\u5177\uff0c\u4e0d\u8981\u7f16\u9020\u5929\u6c14\u3002&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> }\n<\/span><\/span><span style=\"display:flex;\"><span> response <span style=\"color:#f92672\">=<\/span> model<span style=\"color:#f92672\">.<\/span>invoke([system_message, <span style=\"color:#f92672\">*<\/span>state[<span style=\"color:#e6db74\">&#34;messages&#34;<\/span>]])\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#66d9ef\">return<\/span> {<span style=\"color:#e6db74\">&#34;messages&#34;<\/span>: [response]}\n<\/span><\/span><\/code><\/pre><\/div><p><code>MessagesState<\/code> \u5df2\u7ecf\u5b9a\u4e49\u4e86\u6d88\u606f\u5217\u8868\u53ca\u5bf9\u5e94\u7684 Reducer\u3002\u8282\u70b9\u53ea\u8fd4\u56de\u65b0\u6d88\u606f\uff0cReducer \u4f1a\u628a\u5b83\u8ffd\u52a0\u5230\u5386\u53f2\u8bb0\u5f55\uff0c\u800c\u4e0d\u662f\u8986\u76d6\u6574\u4e2a\u5217\u8868\u3002<\/p>\n<h3 id=\"\u6784\u5efa\u6267\u884c\u56fe\">\u6784\u5efa\u6267\u884c\u56fe<\/h3>\n<p><code>ToolNode<\/code> \u8d1f\u8d23\u6267\u884c\u6a21\u578b\u4ea7\u751f\u7684 Tool Call\uff0c<code>tools_condition<\/code> \u5219\u6839\u636e\u6a21\u578b\u8f93\u51fa\u51b3\u5b9a\u8fdb\u5165 Tool Node \u8fd8\u662f\u7ed3\u675f\u5de5\u4f5c\u6d41\u3002<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-python\" data-lang=\"python\"><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> langgraph.checkpoint.memory <span style=\"color:#f92672\">import<\/span> InMemorySaver\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> langgraph.graph <span style=\"color:#f92672\">import<\/span> START, StateGraph\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> langgraph.prebuilt <span style=\"color:#f92672\">import<\/span> ToolNode, tools_condition\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>builder <span style=\"color:#f92672\">=<\/span> StateGraph(MessagesState)\n<\/span><\/span><span style=\"display:flex;\"><span>builder<span style=\"color:#f92672\">.<\/span>add_node(<span style=\"color:#e6db74\">&#34;agent&#34;<\/span>, call_model)\n<\/span><\/span><span style=\"display:flex;\"><span>builder<span style=\"color:#f92672\">.<\/span>add_node(<span style=\"color:#e6db74\">&#34;tools&#34;<\/span>, ToolNode(tools))\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>builder<span style=\"color:#f92672\">.<\/span>add_edge(START, <span style=\"color:#e6db74\">&#34;agent&#34;<\/span>)\n<\/span><\/span><span style=\"display:flex;\"><span>builder<span style=\"color:#f92672\">.<\/span>add_conditional_edges(<span style=\"color:#e6db74\">&#34;agent&#34;<\/span>, tools_condition)\n<\/span><\/span><span style=\"display:flex;\"><span>builder<span style=\"color:#f92672\">.<\/span>add_edge(<span style=\"color:#e6db74\">&#34;tools&#34;<\/span>, <span style=\"color:#e6db74\">&#34;agent&#34;<\/span>)\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>checkpointer <span style=\"color:#f92672\">=<\/span> InMemorySaver()\n<\/span><\/span><span style=\"display:flex;\"><span>graph <span style=\"color:#f92672\">=<\/span> builder<span style=\"color:#f92672\">.<\/span>compile(checkpointer<span style=\"color:#f92672\">=<\/span>checkpointer)\n<\/span><\/span><\/code><\/pre><\/div><p><code>StateGraph<\/code> \u53ea\u662f\u6784\u5efa\u5668\uff0c\u8c03\u7528 <code>compile()<\/code> \u540e\u624d\u4f1a\u5f97\u5230\u53ef\u4ee5\u6267\u884c\u7684 Graph\u3002\u8fd9\u91cc\u52a0\u5165\u4e86\u5185\u5b58 Checkpointer\uff0c\u7528\u4e8e\u5728\u540c\u4e00\u4e2a Thread \u4e2d\u4fdd\u5b58\u6bcf\u4e00\u6b65\u7684 State\u3002<\/p>\n<h3 id=\"\u8fd0\u884c-agent\">\u8fd0\u884c Agent<\/h3>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-python\" data-lang=\"python\"><span style=\"display:flex;\"><span>config <span style=\"color:#f92672\">=<\/span> {<span style=\"color:#e6db74\">&#34;configurable&#34;<\/span>: {<span style=\"color:#e6db74\">&#34;thread_id&#34;<\/span>: <span style=\"color:#e6db74\">&#34;demo-thread&#34;<\/span>}}\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>inputs <span style=\"color:#f92672\">=<\/span> {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;messages&#34;<\/span>: [\n<\/span><\/span><span style=\"display:flex;\"><span> {<span style=\"color:#e6db74\">&#34;role&#34;<\/span>: <span style=\"color:#e6db74\">&#34;user&#34;<\/span>, <span style=\"color:#e6db74\">&#34;content&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\u4e0a\u6d77\u548c\u6df1\u5733\u54ea\u4e2a\u57ce\u5e02\u66f4\u70ed\uff1f&#34;<\/span>}\n<\/span><\/span><span style=\"display:flex;\"><span> ]\n<\/span><\/span><span style=\"display:flex;\"><span>}\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#66d9ef\">for<\/span> state <span style=\"color:#f92672\">in<\/span> graph<span style=\"color:#f92672\">.<\/span>stream(inputs, config, stream_mode<span style=\"color:#f92672\">=<\/span><span style=\"color:#e6db74\">&#34;values&#34;<\/span>):\n<\/span><\/span><span style=\"display:flex;\"><span> state[<span style=\"color:#e6db74\">&#34;messages&#34;<\/span>][<span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">1<\/span>]<span style=\"color:#f92672\">.<\/span>pretty_print()\n<\/span><\/span><\/code><\/pre><\/div><p>\u6267\u884c\u8fc7\u7a0b\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u7528\u6237\u6d88\u606f\u8fdb\u5165 <code>agent<\/code> \u8282\u70b9\uff1b<\/li>\n<li>\u6a21\u578b\u751f\u6210\u4e24\u4e2a\u5929\u6c14 Tool Call\uff1b<\/li>\n<li><code>tools_condition<\/code> \u628a\u6267\u884c\u8def\u5f84\u8def\u7531\u5230 <code>tools<\/code>\uff1b<\/li>\n<li><code>ToolNode<\/code> \u6267\u884c\u5de5\u5177\u5e76\u628a\u7ed3\u679c\u5199\u5165\u6d88\u606f\u5217\u8868\uff1b<\/li>\n<li>\u56fe\u91cd\u65b0\u8fdb\u5165 <code>agent<\/code>\uff1b<\/li>\n<li>\u6a21\u578b\u6bd4\u8f83\u5de5\u5177\u7ed3\u679c\u5e76\u751f\u6210\u6700\u7ec8\u56de\u7b54\uff1b<\/li>\n<li>\u6ca1\u6709\u65b0\u7684 Tool Call\uff0c\u56fe\u8fdb\u5165 <code>END<\/code>\u3002<\/li>\n<\/ol>\n<h2 id=\"\u591a\u8f6e\u5bf9\u8bdd\u4e0e\u6301\u4e45\u5316\">\u591a\u8f6e\u5bf9\u8bdd\u4e0e\u6301\u4e45\u5316<\/h2>\n<p>Checkpointer \u4f1a\u6309\u7167 <code>thread_id<\/code> \u4fdd\u5b58 Graph State\u3002\u4e0b\u4e00\u6b21\u8c03\u7528\u4f7f\u7528\u76f8\u540c\u7684 Thread ID\uff0cAgent \u5c31\u80fd\u7ee7\u7eed\u4e4b\u524d\u7684\u5bf9\u8bdd\uff1a<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-python\" data-lang=\"python\"><span style=\"display:flex;\"><span>follow_up <span style=\"color:#f92672\">=<\/span> {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;messages&#34;<\/span>: [\n<\/span><\/span><span style=\"display:flex;\"><span> {<span style=\"color:#e6db74\">&#34;role&#34;<\/span>: <span style=\"color:#e6db74\">&#34;user&#34;<\/span>, <span style=\"color:#e6db74\">&#34;content&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\u90a3\u5317\u4eac\u5462\uff1f&#34;<\/span>}\n<\/span><\/span><span style=\"display:flex;\"><span> ]\n<\/span><\/span><span style=\"display:flex;\"><span>}\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>result <span style=\"color:#f92672\">=<\/span> graph<span style=\"color:#f92672\">.<\/span>invoke(follow_up, config)\n<\/span><\/span><span style=\"display:flex;\"><span>print(result[<span style=\"color:#e6db74\">&#34;messages&#34;<\/span>][<span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">1<\/span>]<span style=\"color:#f92672\">.<\/span>content)\n<\/span><\/span><\/code><\/pre><\/div><p><code>InMemorySaver<\/code> \u9002\u5408\u672c\u5730\u5f00\u53d1\u548c\u6d4b\u8bd5\uff0c\u8fdb\u7a0b\u9000\u51fa\u540e\u6570\u636e\u5c31\u4f1a\u6d88\u5931\u3002\u751f\u4ea7\u73af\u5883\u5e94\u8be5\u4f7f\u7528\u6301\u4e45\u5316 Checkpointer\uff0c\u4f8b\u5982 PostgreSQL\uff0c\u6216\u8005\u4f7f\u7528\u81ea\u52a8\u7ba1\u7406\u6301\u4e45\u5316\u7684 Agent Server\u3002<\/p>\n<p>Checkpoint \u4e0d\u53ea\u662f\u804a\u5929\u8bb0\u5fc6\uff0c\u5b83\u8fd8\u652f\u6301\uff1a<\/p>\n<ul>\n<li>\u4ece\u5931\u8d25\u524d\u7684\u6210\u529f\u6b65\u9aa4\u7ee7\u7eed\u6267\u884c\uff1b<\/li>\n<li>\u67e5\u770b\u6bcf\u4e2a\u8282\u70b9\u6267\u884c\u540e\u7684 State\uff1b<\/li>\n<li>\u56de\u5230\u5386\u53f2 Checkpoint \u8fdb\u884c\u8c03\u8bd5\uff1b<\/li>\n<li>\u6682\u505c\u5de5\u4f5c\u6d41\u5e76\u7b49\u5f85\u4eba\u5de5\u8f93\u5165\u3002<\/li>\n<\/ul>\n<h2 id=\"human-in-the-loop\">Human-in-the-loop<\/h2>\n<p>\u5f53 Agent \u51c6\u5907\u6267\u884c\u53d1\u9001\u6d88\u606f\u3001\u4fee\u6539\u6570\u636e\u6216\u4ea7\u751f\u8d39\u7528\u7b49\u9ad8\u98ce\u9669\u64cd\u4f5c\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>interrupt()<\/code> \u6682\u505c Graph\uff1a<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-python\" data-lang=\"python\"><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> langgraph.types <span style=\"color:#f92672\">import<\/span> Command, interrupt\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#66d9ef\">def<\/span> <span style=\"color:#a6e22e\">review_action<\/span>(state):\n<\/span><\/span><span style=\"display:flex;\"><span> decision <span style=\"color:#f92672\">=<\/span> interrupt(\n<\/span><\/span><span style=\"display:flex;\"><span> {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;question&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\u662f\u5426\u5141\u8bb8\u6267\u884c\u8be5\u64cd\u4f5c\uff1f&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;action&#34;<\/span>: state[<span style=\"color:#e6db74\">&#34;pending_action&#34;<\/span>],\n<\/span><\/span><span style=\"display:flex;\"><span> }\n<\/span><\/span><span style=\"display:flex;\"><span> )\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#66d9ef\">return<\/span> {<span style=\"color:#e6db74\">&#34;decision&#34;<\/span>: decision}\n<\/span><\/span><\/code><\/pre><\/div><p>Graph \u4f1a\u4fdd\u5b58\u5f53\u524d State\uff0c\u5e76\u628a\u5ba1\u6279\u8bf7\u6c42\u8fd4\u56de\u7ed9\u8c03\u7528\u65b9\u3002\u5ba1\u6279\u5b8c\u6210\u540e\uff0c\u4f7f\u7528\u76f8\u540c\u7684 <code>thread_id<\/code> \u6062\u590d\u6267\u884c\uff1a<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-python\" data-lang=\"python\"><span style=\"display:flex;\"><span>graph<span style=\"color:#f92672\">.<\/span>invoke(Command(resume<span style=\"color:#f92672\">=<\/span><span style=\"color:#e6db74\">&#34;approve&#34;<\/span>), config)\n<\/span><\/span><\/code><\/pre><\/div><p>\u6062\u590d\u65f6\uff0c\u5305\u542b <code>interrupt()<\/code> \u7684\u8282\u70b9\u4f1a\u4ece\u5934\u91cd\u65b0\u6267\u884c\u3002\u56e0\u6b64\uff0c\u5e94\u628a\u4e0d\u53ef\u91cd\u590d\u7684\u526f\u4f5c\u7528\u653e\u5728\u5ba1\u6279\u4e4b\u540e\uff0c\u5e76\u4fdd\u8bc1\u53ef\u80fd\u91cd\u8bd5\u7684\u8282\u70b9\u5177\u6709\u5e42\u7b49\u6027\u3002<\/p>\n<h2 id=\"\u751f\u4ea7\u5b9e\u8df5\">\u751f\u4ea7\u5b9e\u8df5<\/h2>\n<h3 id=\"state-\u4fdd\u6301\u7cbe\u7b80\">State \u4fdd\u6301\u7cbe\u7b80<\/h3>\n<p>State \u5e94\u4fdd\u5b58\u63a7\u5236\u6d41\u7a0b\u9700\u8981\u7684\u6570\u636e\uff0c\u800c\u4e0d\u662f\u65e0\u9650\u589e\u957f\u7684\u539f\u59cb\u5185\u5bb9\u3002\u957f\u5bf9\u8bdd\u9700\u8981\u88c1\u526a\u3001\u6458\u8981\u6216\u5916\u90e8\u5b58\u50a8\uff0c\u5426\u5219\u6a21\u578b\u4e0a\u4e0b\u6587\u548c Checkpoint \u90fd\u4f1a\u4e0d\u65ad\u81a8\u80c0\u3002<\/p>\n<h3 id=\"tool-\u4fdd\u6301\u5355\u4e00\u804c\u8d23\">Tool \u4fdd\u6301\u5355\u4e00\u804c\u8d23<\/h3>\n<p>\u6bcf\u4e2a Tool \u5e94\u5b8c\u6210\u4e00\u4e2a\u6e05\u6670\u52a8\u4f5c\uff0c\u5e76\u4f7f\u7528\u4e25\u683c\u7684\u53c2\u6570\u7c7b\u578b\u3002\u8bfb\u64cd\u4f5c\u548c\u5199\u64cd\u4f5c\u6700\u597d\u5206\u5f00\uff0c\u5199\u64cd\u4f5c\u53ef\u4ee5\u5355\u72ec\u63a5\u5165\u5ba1\u6279\u8282\u70b9\u3002<\/p>\n<h3 id=\"\u5904\u7406\u9519\u8bef\u4e0e\u91cd\u8bd5\">\u5904\u7406\u9519\u8bef\u4e0e\u91cd\u8bd5<\/h3>\n<p>\u5916\u90e8 API \u53ef\u80fd\u8d85\u65f6\u6216\u9650\u6d41\u3002\u6839\u636e\u5f02\u5e38\u7c7b\u578b\u914d\u7f6e\u91cd\u8bd5\u7b56\u7565\uff0c\u4e0d\u8981\u8ba9\u6a21\u578b\u5728\u672a\u77e5\u9519\u8bef\u4e0a\u65e0\u9650\u5faa\u73af\u3002\u5de5\u5177\u9519\u8bef\u5e94\u8be5\u8fd4\u56de\u8db3\u591f\u7684\u4fe1\u606f\u4f9b\u6a21\u578b\u8c03\u6574\uff0c\u4f46\u4e0d\u80fd\u6cc4\u9732\u51ed\u636e\u548c\u5185\u90e8\u5b9e\u73b0\u3002<\/p>\n<h3 id=\"\u63a7\u5236\u5faa\u73af\">\u63a7\u5236\u5faa\u73af<\/h3>\n<p>Agent \u53ef\u80fd\u56e0\u4e3a\u9519\u8bef\u7684 Tool Call \u4e0d\u65ad\u5faa\u73af\u3002\u751f\u4ea7\u73af\u5883\u9700\u8981\u9650\u5236\u6267\u884c\u6b65\u6570\u3001\u8c03\u7528\u6b21\u6570\u548c\u603b\u8d85\u65f6\u65f6\u95f4\uff0c\u5e76\u4e3a\u65e0\u6cd5\u5b8c\u6210\u7684\u4efb\u52a1\u63d0\u4f9b\u660e\u786e\u7684\u9000\u51fa\u8def\u5f84\u3002<\/p>\n<h3 id=\"\u6301\u4e45\u5316\u524d\u8003\u8651\u5e42\u7b49\u6027\">\u6301\u4e45\u5316\u524d\u8003\u8651\u5e42\u7b49\u6027<\/h3>\n<p>\u6062\u590d\u548c\u91cd\u8bd5\u53ef\u80fd\u518d\u6b21\u6267\u884c\u8282\u70b9\u3002\u652f\u4ed8\u3001\u53d1\u9001\u6d88\u606f\u6216\u5199\u6570\u636e\u5e93\u7b49\u64cd\u4f5c\u5e94\u4f7f\u7528\u5e42\u7b49\u952e\uff0c\u907f\u514d\u4ea7\u751f\u91cd\u590d\u526f\u4f5c\u7528\u3002<\/p>\n<h3 id=\"\u589e\u52a0\u53ef\u89c2\u6d4b\u6027\">\u589e\u52a0\u53ef\u89c2\u6d4b\u6027<\/h3>\n<p>Agent \u7684\u95ee\u9898\u901a\u5e38\u4e0d\u662f\u5355\u4e2a\u51fd\u6570\u62a5\u9519\uff0c\u800c\u662f\u9009\u62e9\u4e86\u9519\u8bef\u8def\u5f84\u6216\u9519\u8bef\u5de5\u5177\u3002\u5e94\u8bb0\u5f55\u8282\u70b9\u8f93\u5165\u8f93\u51fa\u3001Tool Call\u3001\u5ef6\u8fdf\u3001Token \u4f7f\u7528\u91cf\u548c\u6700\u7ec8\u6267\u884c\u8def\u5f84\uff0c\u5e76\u4f7f\u7528 LangSmith \u7b49\u5de5\u5177\u8fdb\u884c\u8ffd\u8e2a\u548c\u8bc4\u4f30\u3002<\/p>\n<h2 id=\"\u4ec0\u4e48\u65f6\u5019\u4f7f\u7528-langgraph\">\u4ec0\u4e48\u65f6\u5019\u4f7f\u7528 LangGraph<\/h2>\n<p>\u9002\u5408\u76f4\u63a5\u4f7f\u7528 LangGraph \u7684\u573a\u666f\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>Agent \u6709\u660e\u786e\u7684\u591a\u6b65\u9aa4\u6d41\u7a0b\u548c\u6761\u4ef6\u5206\u652f\uff1b<\/li>\n<li>\u9700\u8981\u6682\u505c\u3001\u6062\u590d\u6216\u957f\u65f6\u95f4\u8fd0\u884c\uff1b<\/li>\n<li>\u9700\u8981\u4fdd\u5b58\u72b6\u6001\u6216\u8de8\u4f1a\u8bdd\u8bb0\u5fc6\uff1b<\/li>\n<li>\u9ad8\u98ce\u9669 Tool \u5fc5\u987b\u7ecf\u8fc7\u4eba\u5de5\u5ba1\u6279\uff1b<\/li>\n<li>\u9700\u8981\u591a\u4e2a Agent \u6216\u5b50\u56fe\u534f\u4f5c\uff1b<\/li>\n<li>\u9700\u8981\u7cbe\u786e\u63a7\u5236\u5931\u8d25\u91cd\u8bd5\u548c\u6267\u884c\u8def\u5f84\u3002<\/li>\n<\/ul>\n<p>\u5982\u679c\u9700\u6c42\u53ea\u662f\u201c\u6a21\u578b\u8c03\u7528\u51e0\u4e2a\u5de5\u5177\u5e76\u56de\u7b54\u95ee\u9898\u201d\uff0c\u4f18\u5148\u4ece\u9ad8\u5c42 Agent API \u5f00\u59cb\u3002\u53ea\u6709\u5f53\u9ed8\u8ba4\u5faa\u73af\u65e0\u6cd5\u8868\u8fbe\u4e1a\u52a1\u6d41\u7a0b\u65f6\uff0c\u518d\u4e0b\u6c89\u5230 LangGraph\u3002\u8fd9\u6837\u65e2\u80fd\u4fdd\u7559\u5f00\u53d1\u6548\u7387\uff0c\u4e5f\u4e0d\u4f1a\u8fc7\u65e9\u5f15\u5165\u590d\u6742\u5ea6\u3002<\/p>\n<h2 id=\"\u53c2\u8003\u8d44\u6599\">\u53c2\u8003\u8d44\u6599<\/h2>\n<ul>\n<li><a class=\"link\" href=\"https:\/\/docs.langchain.com\/oss\/python\/langgraph\/overview\" target=\"_blank\" rel=\"noopener\"\n>LangGraph overview<\/a><\/li>\n<li><a class=\"link\" href=\"https:\/\/docs.langchain.com\/oss\/python\/langgraph\/graph-api\" target=\"_blank\" rel=\"noopener\"\n>Graph API overview<\/a><\/li>\n<li><a class=\"link\" href=\"https:\/\/docs.langchain.com\/oss\/python\/langchain\/tools\" target=\"_blank\" rel=\"noopener\"\n>Tools<\/a><\/li>\n<li><a class=\"link\" href=\"https:\/\/docs.langchain.com\/oss\/python\/langgraph\/persistence\" target=\"_blank\" rel=\"noopener\"\n>Persistence<\/a><\/li>\n<li><a class=\"link\" href=\"https:\/\/docs.langchain.com\/oss\/python\/langchain\/human-in-the-loop\" target=\"_blank\" rel=\"noopener\"\n>Human-in-the-loop<\/a><\/li>\n<\/ul>"},{"title":"Amazon Q+SNS+Slack","link":"https:\/\/canuxcheng.com\/post\/aws_amazon_q_sns_slack\/","pubDate":"Tue, 21 Jul 2026 14:00:00 +0800","guid":"https:\/\/canuxcheng.com\/post\/aws_amazon_q_sns_slack\/","description":"<p>AWS Chatbot \u5df2\u7ecf\u66f4\u540d\u4e3a <strong>Amazon Q Developer in chat applications<\/strong>\u3002\u9664\u4e86\u5728\u804a\u5929\u7a97\u53e3\u4e2d\u56de\u7b54 AWS \u76f8\u5173\u95ee\u9898\uff0c\u5b83\u8fd8\u53ef\u4ee5\u628a AWS \u544a\u8b66\u81ea\u52a8\u53d1\u9001\u5230 Slack\uff0c\u8ba9\u56e2\u961f\u76f4\u63a5\u5728\u65e5\u5e38\u6c9f\u901a\u9891\u9053\u4e2d\u53d1\u73b0\u548c\u5904\u7406\u6545\u969c\u3002<\/p>\n<p>\u672c\u6587\u5173\u6ce8\u7684\u4e0d\u662f\u67d0\u4e00\u79cd\u57fa\u7840\u8bbe\u65bd\u4ee3\u7801\uff0c\u800c\u662f\u5982\u4f55\u7528 Amazon Q\u3001Amazon SNS \u548c Slack \u5efa\u7acb\u4e00\u6761\u81ea\u52a8\u5316\u544a\u8b66\u94fe\u8def\u3002<\/p>\n<h2 id=\"\u6574\u4f53\u67b6\u6784\">\u6574\u4f53\u67b6\u6784<\/h2>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-text\" data-lang=\"text\"><span style=\"display:flex;\"><span>AWS \u670d\u52a1\u6216\u5e94\u7528\n<\/span><\/span><span style=\"display:flex;\"><span> \u2502\n<\/span><\/span><span style=\"display:flex;\"><span> \u25bc\n<\/span><\/span><span style=\"display:flex;\"><span>CloudWatch Alarm\n<\/span><\/span><span style=\"display:flex;\"><span> \u2502\n<\/span><\/span><span style=\"display:flex;\"><span> \u25bc\n<\/span><\/span><span style=\"display:flex;\"><span> Amazon SNS\n<\/span><\/span><span style=\"display:flex;\"><span> \u2502\n<\/span><\/span><span style=\"display:flex;\"><span> \u25bc\n<\/span><\/span><span style=\"display:flex;\"><span>Amazon Q Developer\n<\/span><\/span><span style=\"display:flex;\"><span> \u2502\n<\/span><\/span><span style=\"display:flex;\"><span> \u25bc\n<\/span><\/span><span style=\"display:flex;\"><span> Slack Channel\n<\/span><\/span><\/code><\/pre><\/div><p>\u5404\u7ec4\u4ef6\u7684\u804c\u8d23\u5f88\u6e05\u6670\uff1a<\/p>\n<ul>\n<li>CloudWatch Alarm \u5224\u65ad\u6307\u6807\u662f\u5426\u8fdb\u5165\u544a\u8b66\u6216\u6062\u590d\u72b6\u6001\u3002<\/li>\n<li>SNS \u4f5c\u4e3a\u7edf\u4e00\u7684\u6d88\u606f\u5165\u53e3\uff0c\u63a5\u6536\u5e76\u5206\u53d1\u544a\u8b66\u3002<\/li>\n<li>Amazon Q Developer \u8ba2\u9605 SNS Topic\uff0c\u628a AWS \u6d88\u606f\u8f6c\u6362\u4e3a\u9002\u5408\u804a\u5929\u7a97\u53e3\u9605\u8bfb\u7684\u901a\u77e5\u3002<\/li>\n<li>Slack \u627f\u8f7d\u544a\u8b66\u901a\u77e5\u3001\u56e2\u961f\u8ba8\u8bba\u548c\u540e\u7eed\u5904\u7f6e\u3002<\/li>\n<\/ul>\n<p>\u76d1\u63a7\u7cfb\u7edf\u53ea\u9700\u8981\u77e5\u9053\u5e94\u8be5\u5411\u54ea\u4e2a SNS Topic \u53d1\u9001\u6d88\u606f\uff0c\u4e0d\u9700\u8981\u77e5\u9053 Slack Workspace\u3001\u9891\u9053\u6216\u804a\u5929\u5e94\u7528\u7684\u914d\u7f6e\u3002\u901a\u77e5\u6e20\u9053\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u544a\u8b66\u672c\u8eab\u4e0d\u9700\u8981\u8ddf\u7740\u4fee\u6539\u3002<\/p>\n<h2 id=\"\u4e3a\u4ec0\u4e48\u4f7f\u7528-amazon-q\u800c\u4e0d\u662f\u76f4\u63a5\u8c03\u7528-slack-webhook\">\u4e3a\u4ec0\u4e48\u4f7f\u7528 Amazon Q\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u8c03\u7528 Slack Webhook<\/h2>\n<p>\u76f4\u63a5\u8c03\u7528 Slack Webhook \u5f53\u7136\u4e5f\u80fd\u53d1\u9001\u6d88\u606f\uff0c\u4f46\u9700\u8981\u81ea\u5df1\u5904\u7406\u51ed\u8bc1\u3001\u6d88\u606f\u683c\u5f0f\u3001\u91cd\u8bd5\u548c AWS \u4e8b\u4ef6\u5185\u5bb9\u3002<\/p>\n<p>Amazon Q Developer \u63d0\u4f9b\u4e86 AWS \u539f\u751f\u7684\u8fde\u63a5\u65b9\u5f0f\uff1a<\/p>\n<ul>\n<li>\u76f4\u63a5\u63a5\u6536 SNS \u4e2d\u7684 AWS \u670d\u52a1\u901a\u77e5\uff1b<\/li>\n<li>\u8bc6\u522b\u5e76\u683c\u5f0f\u5316 CloudWatch Alarm \u7b49\u53d7\u652f\u6301\u7684\u4e8b\u4ef6\uff1b<\/li>\n<li>\u5728 Slack \u4e2d\u5c55\u793a\u544a\u8b66\u72b6\u6001\u3001Region\u3001\u65f6\u95f4\u548c\u76f8\u5173\u6307\u6807\uff1b<\/li>\n<li>\u652f\u6301\u544a\u8b66\u6062\u590d\u901a\u77e5\uff1b<\/li>\n<li>\u53ef\u4ee5\u5728\u540c\u4e00\u9891\u9053\u4e2d\u8be2\u95ee Amazon Q\uff0c\u8f85\u52a9\u5206\u6790 AWS \u8d44\u6e90\uff1b<\/li>\n<li>\u5728\u663e\u5f0f\u6388\u6743\u540e\uff0c\u53ef\u4ee5\u4ece\u804a\u5929\u9891\u9053\u6267\u884c\u53d7\u9650\u7684 AWS \u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<p>\u5982\u679c\u76ee\u6807\u53ea\u662f\u81ea\u52a8\u53d1\u9001\u544a\u8b66\uff0c\u53ef\u4ee5\u53ea\u542f\u7528\u901a\u77e5\u80fd\u529b\uff0c\u4e0d\u9700\u8981\u5f00\u653e\u4ece Slack \u6267\u884c AWS \u547d\u4ee4\u7684\u6743\u9650\u3002<\/p>\n<h2 id=\"\u914d\u7f6e-slack-\u4e0e-amazon-q\">\u914d\u7f6e Slack \u4e0e Amazon Q<\/h2>\n<p>\u7b2c\u4e00\u6b21\u63a5\u5165\u9700\u8981 Slack Workspace \u7ba1\u7406\u5458\u53c2\u4e0e\u6388\u6743\uff1a<\/p>\n<ol>\n<li>\u5728 Slack \u4e2d\u5b89\u88c5 <strong>Amazon Q Developer in chat applications<\/strong>\u3002<\/li>\n<li>\u6253\u5f00 <a class=\"link\" href=\"https:\/\/console.aws.amazon.com\/chatbot\/\" target=\"_blank\" rel=\"noopener\"\n>Amazon Q Developer in chat applications \u63a7\u5236\u53f0<\/a>\u3002<\/li>\n<li>\u9009\u62e9 Slack\uff0c\u5e76\u5b8c\u6210\u76ee\u6807 Workspace \u7684\u6388\u6743\u3002<\/li>\n<li>\u5728\u7528\u4e8e\u63a5\u6536\u544a\u8b66\u7684 Slack \u9891\u9053\u4e2d\u9080\u8bf7 Amazon Q\u3002<\/li>\n<li>\u56de\u5230 AWS \u63a7\u5236\u53f0\uff0c\u4e3a\u8be5 Slack \u9891\u9053\u521b\u5efa Channel Configuration\u3002<\/li>\n<\/ol>\n<p>\u5efa\u8bae\u5148\u5efa\u7acb\u4e13\u7528\u544a\u8b66\u9891\u9053\uff0c\u4f8b\u5982\u6309\u73af\u5883\u6216\u4e25\u91cd\u7ea7\u522b\u533a\u5206\u9891\u9053\uff0c\u907f\u514d\u6240\u6709\u6d88\u606f\u90fd\u8fdb\u5165\u540c\u4e00\u4e2a\u9891\u9053\u3002<\/p>\n<h2 id=\"\u521b\u5efa-sns-\u901a\u77e5\u5165\u53e3\">\u521b\u5efa SNS \u901a\u77e5\u5165\u53e3<\/h2>\n<p>\u5728 Amazon SNS \u4e2d\u521b\u5efa\u7528\u4e8e\u544a\u8b66\u901a\u77e5\u7684 Topic\u3002Topic \u662f\u544a\u8b66\u7cfb\u7edf\u548c Slack \u4e4b\u95f4\u7684\u8fb9\u754c\uff0c\u56e0\u6b64\u547d\u540d\u5e94\u8be5\u8868\u8fbe\u7528\u9014\uff0c\u800c\u4e0d\u662f\u7ed1\u5b9a\u67d0\u4e2a\u5177\u4f53\u5e94\u7528\u3002<\/p>\n<p>\u5e38\u89c1\u7684\u62c6\u5206\u65b9\u5f0f\u5305\u62ec\uff1a<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-text\" data-lang=\"text\"><span style=\"display:flex;\"><span>critical-alerts \u2192 \u9700\u8981\u7acb\u5373\u5904\u7406\u7684\u544a\u8b66\n<\/span><\/span><span style=\"display:flex;\"><span>warning-alerts \u2192 \u6027\u80fd\u3001\u5bb9\u91cf\u548c\u8d8b\u52bf\u7c7b\u544a\u8b66\n<\/span><\/span><\/code><\/pre><\/div><p>\u4e5f\u53ef\u4ee5\u6309\u73af\u5883\u62c6\u5206 Topic\uff0c\u907f\u514d\u6d4b\u8bd5\u73af\u5883\u7684\u544a\u8b66\u8fdb\u5165\u751f\u4ea7\u9891\u9053\u3002<\/p>\n<p>\u521b\u5efa Topic \u540e\uff0c\u5728 Amazon Q \u7684 Slack Channel Configuration \u4e2d\u628a\u5b83\u6dfb\u52a0\u4e3a\u901a\u77e5\u6765\u6e90\u3002\u4e00\u4e2a\u9891\u9053\u53ef\u4ee5\u5173\u8054\u591a\u4e2a SNS Topic\uff0c\u540c\u4e00\u4e2a Topic \u4e5f\u53ef\u4ee5\u4f5c\u4e3a\u591a\u4e2a\u544a\u8b66\u7684\u53d1\u9001\u76ee\u6807\u3002<\/p>\n<h2 id=\"\u5c06-cloudwatch-alarm-\u63a5\u5165-sns\">\u5c06 CloudWatch Alarm \u63a5\u5165 SNS<\/h2>\n<p>\u521b\u5efa\u6216\u4fee\u6539 CloudWatch Alarm \u65f6\uff0c\u5c06\u524d\u9762\u521b\u5efa\u7684 SNS Topic \u8bbe\u7f6e\u4e3a\u901a\u77e5\u76ee\u6807\u3002<\/p>\n<p>\u5efa\u8bae\u540c\u65f6\u914d\u7f6e\u4e24\u4e2a\u72b6\u6001\u52a8\u4f5c\uff1a<\/p>\n<ul>\n<li><strong>ALARM<\/strong>\uff1a\u6307\u6807\u8d85\u8fc7\u9608\u503c\u65f6\u53d1\u9001\u544a\u8b66\uff1b<\/li>\n<li><strong>OK<\/strong>\uff1a\u6307\u6807\u6062\u590d\u6b63\u5e38\u65f6\u53d1\u9001\u6062\u590d\u901a\u77e5\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u6837 Slack \u4e2d\u4e0d\u4ec5\u4f1a\u51fa\u73b0\u201c\u53d1\u751f\u4e86\u4ec0\u4e48\u201d\uff0c\u4e5f\u80fd\u770b\u5230\u201c\u95ee\u9898\u662f\u5426\u5df2\u7ecf\u6062\u590d\u201d\u3002<\/p>\n<p>\u8fd9\u5957\u94fe\u8def\u4e0d\u5c40\u9650\u4e8e\u67d0\u4e00\u79cd\u6307\u6807\u3002\u5e38\u89c1\u573a\u666f\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>ECS \u670d\u52a1\u6ca1\u6709\u8fd0\u884c\u4e2d\u7684 Task\uff1b<\/li>\n<li>CPU \u6216\u5185\u5b58\u6301\u7eed\u8d85\u8fc7\u9608\u503c\uff1b<\/li>\n<li>\u5e94\u7528\u65e5\u5fd7\u4e2d\u51fa\u73b0\u4e25\u91cd\u9519\u8bef\uff1b<\/li>\n<li>\u961f\u5217\u79ef\u538b\u6216\u8bf7\u6c42\u5931\u8d25\u7387\u5347\u9ad8\uff1b<\/li>\n<li>AWS Budgets\u3001Security Hub \u6216\u5176\u4ed6\u53d7\u652f\u6301\u670d\u52a1\u4ea7\u751f\u901a\u77e5\u3002<\/li>\n<\/ul>\n<p>\u5bf9\u4e8e\u5e94\u7528\u81ea\u5b9a\u4e49\u4e8b\u4ef6\uff0c\u53ef\u4ee5\u5148\u5c06\u4e8b\u4ef6\u8f6c\u6362\u6210 Amazon Q \u652f\u6301\u7684\u901a\u77e5\u683c\u5f0f\uff0c\u518d\u53d1\u5e03\u5230 SNS\u3002<\/p>\n<h2 id=\"\u4e00\u6761\u544a\u8b66\u5982\u4f55\u5230\u8fbe-slack\">\u4e00\u6761\u544a\u8b66\u5982\u4f55\u5230\u8fbe Slack<\/h2>\n<p>\u5f53 CloudWatch Alarm \u4ece <strong>OK<\/strong> \u53d8\u4e3a <strong>ALARM<\/strong> \u65f6\uff1a<\/p>\n<ol>\n<li>CloudWatch \u5c06\u72b6\u6001\u53d8\u5316\u53d1\u5e03\u5230 SNS Topic\u3002<\/li>\n<li>Amazon Q Developer \u63a5\u6536 SNS \u6d88\u606f\u3002<\/li>\n<li>Amazon Q \u8bc6\u522b\u544a\u8b66\u5185\u5bb9\u5e76\u751f\u6210\u7ed3\u6784\u5316 Slack \u6d88\u606f\u3002<\/li>\n<li>Slack \u9891\u9053\u6536\u5230\u544a\u8b66\uff0c\u503c\u73ed\u4eba\u5458\u53ef\u4ee5\u7acb\u5373\u8ba8\u8bba\u548c\u5904\u7406\u3002<\/li>\n<li>\u6307\u6807\u6062\u590d\u540e\uff0cCloudWatch \u518d\u6b21\u901a\u8fc7 SNS \u53d1\u9001 <strong>OK<\/strong> \u72b6\u6001\u3002<\/li>\n<li>Slack \u6536\u5230\u6062\u590d\u901a\u77e5\uff0c\u5f62\u6210\u5b8c\u6574\u7684\u4e8b\u4ef6\u95ed\u73af\u3002<\/li>\n<\/ol>\n<p>\u6574\u4e2a\u8fc7\u7a0b\u4e0d\u9700\u8981\u5e94\u7528\u76f4\u63a5\u8bbf\u95ee Slack\uff0c\u4e5f\u4e0d\u9700\u8981\u5728\u5e94\u7528\u4e2d\u4fdd\u5b58 Slack Token \u6216 Webhook\u3002<\/p>\n<h2 id=\"\u9a8c\u8bc1\u901a\u77e5\u94fe\u8def\">\u9a8c\u8bc1\u901a\u77e5\u94fe\u8def<\/h2>\n<p>\u914d\u7f6e\u5b8c\u6210\u540e\uff0c\u5148\u5728 Amazon Q Developer \u63a7\u5236\u53f0\u9009\u62e9\u5bf9\u5e94\u9891\u9053\u5e76\u53d1\u9001\u6d4b\u8bd5\u6d88\u606f\u3002\u786e\u8ba4 Slack \u80fd\u6536\u5230\u6d4b\u8bd5\u6d88\u606f\u540e\uff0c\u518d\u9a8c\u8bc1\u771f\u5b9e\u544a\u8b66\u3002<\/p>\n<p>\u63a8\u8350\u6309\u4ee5\u4e0b\u987a\u5e8f\u68c0\u67e5\uff1a<\/p>\n<ol>\n<li>Amazon Q \u662f\u5426\u5df2\u7ecf\u52a0\u5165\u76ee\u6807 Slack \u9891\u9053\uff1b<\/li>\n<li>Slack Workspace \u662f\u5426\u5df2\u5728 AWS \u4e2d\u5b8c\u6210\u6388\u6743\uff1b<\/li>\n<li>Amazon Q \u7684\u9891\u9053\u914d\u7f6e\u662f\u5426\u5173\u8054\u4e86\u6b63\u786e\u7684 SNS Topic\uff1b<\/li>\n<li>CloudWatch Alarm \u7684\u901a\u77e5\u52a8\u4f5c\u662f\u5426\u6307\u5411\u8be5 Topic\uff1b<\/li>\n<li>Alarm \u548c SNS Topic \u662f\u5426\u4f4d\u4e8e\u9884\u671f\u7684 AWS Region\uff1b<\/li>\n<li>Amazon Q \u7684 CloudWatch Logs \u4e2d\u662f\u5426\u5b58\u5728\u6743\u9650\u3001\u683c\u5f0f\u6216\u6295\u9012\u9519\u8bef\u3002<\/li>\n<\/ol>\n<p>\u5982\u679c\u6d4b\u8bd5\u6d88\u606f\u53ef\u4ee5\u5230\u8fbe Slack\uff0c\u4f46\u771f\u5b9e\u544a\u8b66\u4e0d\u80fd\uff0c\u95ee\u9898\u901a\u5e38\u4f4d\u4e8e CloudWatch \u5230 SNS \u8fd9\u4e00\u6bb5\uff1b\u5982\u679c SNS \u5df2\u7ecf\u6536\u5230\u6d88\u606f\u4f46 Slack \u6ca1\u6709\u901a\u77e5\uff0c\u5219\u91cd\u70b9\u68c0\u67e5 Amazon Q \u7684 Topic \u5173\u8054\u3001\u4e8b\u4ef6\u683c\u5f0f\u548c\u65e5\u5fd7\u3002<\/p>\n<h2 id=\"\u6743\u9650\u4e0e\u5b89\u5168\">\u6743\u9650\u4e0e\u5b89\u5168<\/h2>\n<p>\u901a\u77e5\u80fd\u529b\u548c\u804a\u5929\u64cd\u4f5c\u80fd\u529b\u5e94\u8be5\u5206\u5f00\u8003\u8651\u3002<\/p>\n<p>\u53ea\u53d1\u9001\u544a\u8b66\u65f6\uff0c\u5e94\u4f7f\u7528\u6700\u5c0f\u6743\u9650\u7684 Channel Role \u548c Guardrail\u3002\u4e0d\u8981\u56e0\u4e3a Amazon Q \u652f\u6301\u5728 Slack \u4e2d\u8fd0\u884c AWS \u547d\u4ee4\uff0c\u5c31\u9ed8\u8ba4\u6388\u4e88\u9891\u9053\u7ba1\u7406\u5458\u6743\u9650\u3002<\/p>\n<p>\u8fd8\u5e94\u9075\u5faa\u4ee5\u4e0b\u539f\u5219\uff1a<\/p>\n<ul>\n<li>\u4e0d\u5728\u6587\u6863\u6216\u4ee3\u7801\u4e2d\u8bb0\u5f55\u771f\u5b9e\u7684 AWS Account ID\u3001Slack \u6807\u8bc6\u548c\u5185\u90e8\u8d44\u6e90\u540d\u79f0\uff1b<\/li>\n<li>\u4e0d\u8ba9\u5e94\u7528\u76f4\u63a5\u6301\u6709 Slack Token \u6216 Webhook\uff1b<\/li>\n<li>\u6309\u73af\u5883\u548c\u4e25\u91cd\u7ea7\u522b\u9694\u79bb SNS Topic\uff1b<\/li>\n<li>\u9650\u5236\u53ef\u4ee5\u52a0\u5165\u8fd0\u7ef4\u9891\u9053\u7684\u6210\u5458\uff1b<\/li>\n<li>\u4e3a Amazon Q \u542f\u7528\u9519\u8bef\u65e5\u5fd7\uff0c\u4fbf\u4e8e\u5ba1\u8ba1\u548c\u6392\u969c\uff1b<\/li>\n<li>\u53ea\u6709\u5728\u786e\u6709\u9700\u8981\u65f6\uff0c\u624d\u5f00\u653e\u4ece Slack \u6267\u884c AWS \u64cd\u4f5c\u7684\u6743\u9650\u3002<\/li>\n<\/ul>\n<h2 id=\"\u603b\u7ed3\">\u603b\u7ed3<\/h2>\n<p>Amazon Q\u3001SNS \u548c Slack \u7ec4\u5408\u8d77\u6765\uff0c\u53ef\u4ee5\u5efa\u7acb\u4e00\u6761\u7b80\u5355\u800c\u6e05\u6670\u7684 AWS \u81ea\u52a8\u5316\u544a\u8b66\u94fe\u8def\uff1a<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-text\" data-lang=\"text\"><span style=\"display:flex;\"><span>\u544a\u8b66\u4ea7\u751f \u2192 SNS \u5206\u53d1 \u2192 Amazon Q \u8f6c\u6362 \u2192 Slack \u901a\u77e5 \u2192 \u56e2\u961f\u54cd\u5e94\n<\/span><\/span><\/code><\/pre><\/div><p>SNS \u8d1f\u8d23\u89e3\u8026\u544a\u8b66\u548c\u901a\u77e5\u6e20\u9053\uff0cAmazon Q \u8d1f\u8d23\u7406\u89e3 AWS \u4e8b\u4ef6\u5e76\u8fde\u63a5 Slack\uff0cCloudWatch \u7b49\u544a\u8b66\u6e90\u53ea\u8d1f\u8d23\u5224\u65ad\u4f55\u65f6\u9700\u8981\u901a\u77e5\u3002<\/p>\n<p>\u65e0\u8bba\u901a\u8fc7 AWS \u63a7\u5236\u53f0\u8fd8\u662f\u81ea\u52a8\u5316\u5de5\u5177\u5b8c\u6210\u914d\u7f6e\uff0c\u6838\u5fc3\u90fd\u662f\u8ba9\u544a\u8b66\u7edf\u4e00\u53d1\u5e03\u5230 SNS\uff0c\u518d\u7531 Amazon Q \u5c06\u6d88\u606f\u53ef\u9760\u5730\u9001\u5230 Slack\u3002<\/p>\n<h2 id=\"\u53c2\u8003\u8d44\u6599\">\u53c2\u8003\u8d44\u6599<\/h2>\n<ul>\n<li><a class=\"link\" href=\"https:\/\/docs.aws.amazon.com\/chatbot\/latest\/adminguide\/what-is.html\" target=\"_blank\" rel=\"noopener\"\n>What is Amazon Q Developer in chat applications?<\/a><\/li>\n<li><a class=\"link\" href=\"https:\/\/docs.aws.amazon.com\/chatbot\/latest\/adminguide\/slack-setup.html\" target=\"_blank\" rel=\"noopener\"\n>Tutorial: Get started with Slack<\/a><\/li>\n<li><a class=\"link\" href=\"https:\/\/docs.aws.amazon.com\/chatbot\/latest\/adminguide\/related-services.html\" target=\"_blank\" rel=\"noopener\"\n>Monitoring AWS services using Amazon Q Developer in chat applications<\/a><\/li>\n<li><a class=\"link\" href=\"https:\/\/docs.aws.amazon.com\/chatbot\/latest\/adminguide\/test-notifications-cw.html\" target=\"_blank\" rel=\"noopener\"\n>Test notifications using CloudWatch<\/a><\/li>\n<\/ul>"},{"title":"oh my posh","link":"https:\/\/canuxcheng.com\/post\/ai_statusline\/","pubDate":"Thu, 16 Jul 2026 10:00:00 +0800","guid":"https:\/\/canuxcheng.com\/post\/ai_statusline\/","description":"<h1 id=\"oh-my-posh\">Oh My Posh<\/h1>\n<p><a class=\"link\" href=\"https:\/\/ohmyposh.dev\/\" target=\"_blank\" rel=\"noopener\"\n>Oh My Posh<\/a> is a cross-platform prompt engine. A\nsingle theme describes blocks, segments, colors, icons, and templates; the\nengine combines that configuration with runtime data and prints the final\nANSI-formatted line.<\/p>\n<p>That rendering model works in several terminal interfaces, but the integration\npoint is different in each one:<\/p>\n<table>\n<thead>\n<tr>\n<th>Interface<\/th>\n<th>Who invokes the renderer<\/th>\n<th>Data source<\/th>\n<th>Renderer<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>zsh prompt<\/td>\n<td>zsh hooks installed by <code>oh-my-posh init zsh<\/code><\/td>\n<td>shell, path, git, command status, and environment<\/td>\n<td>Oh My Posh<\/td>\n<\/tr>\n<tr>\n<td>Claude Code status line<\/td>\n<td>Claude Code runs the configured command<\/td>\n<td>session JSON on stdin<\/td>\n<td>Oh My Posh<\/td>\n<\/tr>\n<tr>\n<td>Codex status line<\/td>\n<td>Codex TUI<\/td>\n<td>Codex session state<\/td>\n<td>Codex itself<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The distinction matters: Oh My Posh directly renders the first two. Codex\ncurrently owns its footer and does not expose an external status-line command.<\/p>\n<h2 id=\"render-the-zsh-prompt\">Render the zsh prompt<\/h2>\n<p>Install Oh My Posh and a <a class=\"link\" href=\"https:\/\/www.nerdfonts.com\/\" target=\"_blank\" rel=\"noopener\"\n>Nerd Font<\/a>, then add the\ninitialization command to the end of <code>~\/.zshrc<\/code>:<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-zsh\" data-lang=\"zsh\"><span style=\"display:flex;\"><span>eval <span style=\"color:#e6db74\">&#34;<\/span><span style=\"color:#66d9ef\">$(<\/span>oh-my-posh init zsh --config ~\/.config\/ohmyposh\/main.omp.json<span style=\"color:#66d9ef\">)<\/span><span style=\"color:#e6db74\">&#34;<\/span>\n<\/span><\/span><\/code><\/pre><\/div><p>Reload zsh:<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-zsh\" data-lang=\"zsh\"><span style=\"display:flex;\"><span>exec zsh\n<\/span><\/span><\/code><\/pre><\/div><p><code>oh-my-posh init zsh<\/code> generates the zsh integration script. The script installs\nprompt hooks that collect the current directory, exit code, execution time, and\nother shell state. On every prompt, Oh My Posh evaluates the configured\nsegments and returns the escape sequences assigned to zsh&rsquo;s prompt.<\/p>\n<p>A small theme with a left prompt and a right-aligned status area looks like\nthis:<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-json\" data-lang=\"json\"><span style=\"display:flex;\"><span>{\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;$schema&#34;<\/span>: <span style=\"color:#e6db74\">&#34;https:\/\/raw.githubusercontent.com\/JanDeDobbeleer\/oh-my-posh\/main\/themes\/schema.json&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;version&#34;<\/span>: <span style=\"color:#ae81ff\">3<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;blocks&#34;<\/span>: [\n<\/span><\/span><span style=\"display:flex;\"><span> {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;type&#34;<\/span>: <span style=\"color:#e6db74\">&#34;prompt&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;alignment&#34;<\/span>: <span style=\"color:#e6db74\">&#34;left&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;segments&#34;<\/span>: [\n<\/span><\/span><span style=\"display:flex;\"><span> {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;type&#34;<\/span>: <span style=\"color:#e6db74\">&#34;path&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;style&#34;<\/span>: <span style=\"color:#e6db74\">&#34;powerline&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;foreground&#34;<\/span>: <span style=\"color:#e6db74\">&#34;#ffffff&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;background&#34;<\/span>: <span style=\"color:#e6db74\">&#34;#0077c2&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;powerline_symbol&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\ue0b0&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;template&#34;<\/span>: <span style=\"color:#e6db74\">&#34; \uf07b {{ .Path }} &#34;<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> },\n<\/span><\/span><span style=\"display:flex;\"><span> {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;type&#34;<\/span>: <span style=\"color:#e6db74\">&#34;git&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;style&#34;<\/span>: <span style=\"color:#e6db74\">&#34;powerline&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;foreground&#34;<\/span>: <span style=\"color:#e6db74\">&#34;#111111&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;background&#34;<\/span>: <span style=\"color:#e6db74\">&#34;#ffeb3b&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;powerline_symbol&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\ue0b0&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;template&#34;<\/span>: <span style=\"color:#e6db74\">&#34; \ue0a0 {{ .HEAD }}{{ if .Working.Changed }} \uf044{{ end }} &#34;<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> }\n<\/span><\/span><span style=\"display:flex;\"><span> ]\n<\/span><\/span><span style=\"display:flex;\"><span> },\n<\/span><\/span><span style=\"display:flex;\"><span> {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;type&#34;<\/span>: <span style=\"color:#e6db74\">&#34;rprompt&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;alignment&#34;<\/span>: <span style=\"color:#e6db74\">&#34;right&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;segments&#34;<\/span>: [\n<\/span><\/span><span style=\"display:flex;\"><span> {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;type&#34;<\/span>: <span style=\"color:#e6db74\">&#34;executiontime&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;style&#34;<\/span>: <span style=\"color:#e6db74\">&#34;plain&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;foreground&#34;<\/span>: <span style=\"color:#e6db74\">&#34;#a0a0a0&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;template&#34;<\/span>: <span style=\"color:#e6db74\">&#34; {{ .FormattedMs }} &#34;<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> },\n<\/span><\/span><span style=\"display:flex;\"><span> {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;type&#34;<\/span>: <span style=\"color:#e6db74\">&#34;status&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;style&#34;<\/span>: <span style=\"color:#e6db74\">&#34;plain&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;foreground&#34;<\/span>: <span style=\"color:#e6db74\">&#34;#ff5f5f&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;template&#34;<\/span>: <span style=\"color:#e6db74\">&#34; exit {{ .Code }} &#34;<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> }\n<\/span><\/span><span style=\"display:flex;\"><span> ]\n<\/span><\/span><span style=\"display:flex;\"><span> }\n<\/span><\/span><span style=\"display:flex;\"><span> ]\n<\/span><\/span><span style=\"display:flex;\"><span>}\n<\/span><\/span><\/code><\/pre><\/div><p>Here, <code>prompt<\/code> renders on the left and <code>rprompt<\/code> renders against the right edge.\nThe path and git segments inspect the current repository, while <code>executiontime<\/code>\nand <code>status<\/code> use information captured from the previous command. Conditional\ntemplates keep irrelevant segments hidden.<\/p>\n<h2 id=\"render-the-claude-code-status-line\">Render the Claude Code status line<\/h2>\n<p>Claude Code has an external status-line protocol. After each update, it runs a\nconfigured command, writes session data as JSON to the command&rsquo;s stdin, and\ndisplays stdout at the bottom of the TUI.<\/p>\n<p>Oh My Posh implements that protocol with <code>oh-my-posh claude<\/code>. Add it to\n<code>~\/.claude\/settings.json<\/code>:<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-json\" data-lang=\"json\"><span style=\"display:flex;\"><span>{\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;statusLine&#34;<\/span>: {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;type&#34;<\/span>: <span style=\"color:#e6db74\">&#34;command&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;command&#34;<\/span>: <span style=\"color:#e6db74\">&#34;oh-my-posh claude&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;padding&#34;<\/span>: <span style=\"color:#ae81ff\">0<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> }\n<\/span><\/span><span style=\"display:flex;\"><span>}\n<\/span><\/span><\/code><\/pre><\/div><p>The data flow is:<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-text\" data-lang=\"text\"><span style=\"display:flex;\"><span>Claude Code session JSON\n<\/span><\/span><span style=\"display:flex;\"><span> \u2502 stdin\n<\/span><\/span><span style=\"display:flex;\"><span> \u25bc\n<\/span><\/span><span style=\"display:flex;\"><span>oh-my-posh claude\n<\/span><\/span><span style=\"display:flex;\"><span> \u2502 POSH_CLAUDE_STATUS\n<\/span><\/span><span style=\"display:flex;\"><span> \u25bc\n<\/span><\/span><span style=\"display:flex;\"><span>Claude segment + theme templates\n<\/span><\/span><span style=\"display:flex;\"><span> \u2502 stdout\n<\/span><\/span><span style=\"display:flex;\"><span> \u25bc\n<\/span><\/span><span style=\"display:flex;\"><span>Claude Code status line\n<\/span><\/span><\/code><\/pre><\/div><p>Without <code>--config<\/code>, Oh My Posh uses its built-in Claude theme. To control the\nlayout, point the command at a dedicated theme:<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-json\" data-lang=\"json\"><span style=\"display:flex;\"><span>{\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;statusLine&#34;<\/span>: {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;type&#34;<\/span>: <span style=\"color:#e6db74\">&#34;command&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;command&#34;<\/span>: <span style=\"color:#e6db74\">&#34;oh-my-posh claude --config ~\/.config\/ohmyposh\/claude.omp.json&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;padding&#34;<\/span>: <span style=\"color:#ae81ff\">0<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> }\n<\/span><\/span><span style=\"display:flex;\"><span>}\n<\/span><\/span><\/code><\/pre><\/div><p>The theme needs a <code>claude<\/code> segment. It can also reuse general segments such as\n<code>path<\/code> and <code>git<\/code>:<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-json\" data-lang=\"json\"><span style=\"display:flex;\"><span>{\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;$schema&#34;<\/span>: <span style=\"color:#e6db74\">&#34;https:\/\/raw.githubusercontent.com\/JanDeDobbeleer\/oh-my-posh\/main\/themes\/schema.json&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;version&#34;<\/span>: <span style=\"color:#ae81ff\">3<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;blocks&#34;<\/span>: [\n<\/span><\/span><span style=\"display:flex;\"><span> {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;type&#34;<\/span>: <span style=\"color:#e6db74\">&#34;prompt&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;alignment&#34;<\/span>: <span style=\"color:#e6db74\">&#34;left&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;segments&#34;<\/span>: [\n<\/span><\/span><span style=\"display:flex;\"><span> {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;type&#34;<\/span>: <span style=\"color:#e6db74\">&#34;claude&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;style&#34;<\/span>: <span style=\"color:#e6db74\">&#34;diamond&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;leading_diamond&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\ue0b6&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;trailing_diamond&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\ue0b4&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;foreground&#34;<\/span>: <span style=\"color:#e6db74\">&#34;#ffffff&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;background&#34;<\/span>: <span style=\"color:#e6db74\">&#34;#d97757&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;template&#34;<\/span>: <span style=\"color:#e6db74\">&#34; \udb82\udfc9 {{ .Model.DisplayName }} ctx {{ .TokenGauge }} {{ .FormattedCost }} &#34;<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> }\n<\/span><\/span><span style=\"display:flex;\"><span> ]\n<\/span><\/span><span style=\"display:flex;\"><span> }\n<\/span><\/span><span style=\"display:flex;\"><span> ]\n<\/span><\/span><span style=\"display:flex;\"><span>}\n<\/span><\/span><\/code><\/pre><\/div><p>The Claude segment parses model, token, cost, duration, workspace, rate-limit,\nvim-mode, agent, and pull-request fields from the session payload. Common\ntemplate properties include:<\/p>\n<table>\n<thead>\n<tr>\n<th>Property<\/th>\n<th>Value<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>.Model.DisplayName<\/code><\/td>\n<td>Human-readable model name<\/td>\n<\/tr>\n<tr>\n<td><code>.TokenGauge<\/code> \/ <code>.TokenUsagePercent<\/code><\/td>\n<td>Context-window gauge \/ percentage<\/td>\n<\/tr>\n<tr>\n<td><code>.FormattedTokens<\/code> \/ <code>.FormattedCost<\/code><\/td>\n<td>Human-readable token count \/ session cost<\/td>\n<\/tr>\n<tr>\n<td><code>.FormattedDuration<\/code><\/td>\n<td>Session duration<\/td>\n<\/tr>\n<tr>\n<td><code>.Workspace.CurrentDir<\/code> \/ <code>.Workspace.ProjectDir<\/code><\/td>\n<td>Current \/ project directory<\/td>\n<\/tr>\n<tr>\n<td><code>.FiveHourGauge<\/code> \/ <code>.SevenDayGauge<\/code><\/td>\n<td>Available rate-limit gauges<\/td>\n<\/tr>\n<tr>\n<td><code>.Vim.Mode<\/code> \/ <code>.Agent.Name<\/code><\/td>\n<td>Optional vim mode \/ active agent<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Some nested objects are absent when Claude Code does not provide the\ncorresponding data. Guard optional values before dereferencing them:<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-text\" data-lang=\"text\"><span style=\"display:flex;\"><span>{{ if .Agent }}agent {{ .Agent.Name }}{{ end }}\n<\/span><\/span><\/code><\/pre><\/div><h2 id=\"configure-the-codex-status-line\">Configure the Codex status line<\/h2>\n<p>Codex has a status line at the bottom of its terminal UI, but its integration\nmodel differs from Claude Code. Codex does not currently pipe session JSON to\nan external renderer, and Oh My Posh does not provide an <code>oh-my-posh codex<\/code>\ncommand. The Codex footer is therefore configured and rendered natively.<\/p>\n<p>The easiest way to change it is to run this slash command inside Codex:<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-text\" data-lang=\"text\"><span style=\"display:flex;\"><span>\/statusline\n<\/span><\/span><\/code><\/pre><\/div><p>The picker lets you select and reorder fields, then persists the result to\n<code>~\/.codex\/config.toml<\/code>. The equivalent direct configuration is:<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-toml\" data-lang=\"toml\"><span style=\"display:flex;\"><span>[<span style=\"color:#a6e22e\">tui<\/span>]\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#a6e22e\">status_line<\/span> = [\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;current-dir&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;model-with-reasoning&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;context-remaining&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;used-tokens&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;git-branch&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;five-hour-limit&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;weekly-limit&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;fast-mode&#34;<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>]\n<\/span><\/span><\/code><\/pre><\/div><p>Order in the array is order in the footer. A shorter configuration is often\neasier to scan:<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-toml\" data-lang=\"toml\"><span style=\"display:flex;\"><span>[<span style=\"color:#a6e22e\">tui<\/span>]\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#a6e22e\">status_line<\/span> = [<span style=\"color:#e6db74\">&#34;model-with-reasoning&#34;<\/span>, <span style=\"color:#e6db74\">&#34;context-remaining&#34;<\/span>, <span style=\"color:#e6db74\">&#34;git-branch&#34;<\/span>]\n<\/span><\/span><\/code><\/pre><\/div><p>Use an empty array to hide the Codex footer:<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-toml\" data-lang=\"toml\"><span style=\"display:flex;\"><span>[<span style=\"color:#a6e22e\">tui<\/span>]\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#a6e22e\">status_line<\/span> = []\n<\/span><\/span><\/code><\/pre><\/div><p>Oh My Posh still renders the surrounding zsh prompt before and after the Codex\nprocess runs; it simply does not own the footer inside the Codex TUI. If Codex\nadds an external status-line protocol in the future, the Claude integration is\nthe likely model: Codex would provide structured session data and invoke a\ndedicated Oh My Posh renderer.<\/p>\n<h2 id=\"resources\">Resources<\/h2>\n<p><a class=\"link\" href=\"https:\/\/ohmyposh.dev\/docs\/installation\/prompt?shell=zsh\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/ohmyposh.dev\/docs\/installation\/prompt?shell=zsh<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/ohmyposh.dev\/docs\/configuration\/block\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/ohmyposh.dev\/docs\/configuration\/block<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/ohmyposh.dev\/docs\/segments\/cli\/claude\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/ohmyposh.dev\/docs\/segments\/cli\/claude<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/code.claude.com\/docs\/en\/statusline\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/code.claude.com\/docs\/en\/statusline<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/developers.openai.com\/codex\/cli\/slash-commands#configure-footer-items-with-statusline\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/developers.openai.com\/codex\/cli\/slash-commands#configure-footer-items-with-statusline<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/developers.openai.com\/codex\/config-reference#configtoml\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/developers.openai.com\/codex\/config-reference#configtoml<\/a><\/p>"},{"title":"Spec-Driven Development","link":"https:\/\/canuxcheng.com\/post\/ai_sdd\/","pubDate":"Wed, 17 Jun 2026 10:00:00 +0800","guid":"https:\/\/canuxcheng.com\/post\/ai_sdd\/","description":"<h1 id=\"spec-driven-development\">Spec-Driven Development<\/h1>\n<p><strong>Spec-Driven Development (SDD)<\/strong> is a methodology for building software with AI\ncoding agents where the <em>specification<\/em>, not the code, is the primary artifact.\nInstead of prompting an agent ad-hoc and hoping the output is correct, you first\nwrite down <em>what<\/em> you want \u2014 requirements, scenarios, constraints \u2014 and let the\nspec drive the plan, the tasks, and finally the implementation.<\/p>\n<p>The core idea: AI agents are powerful but unpredictable. A natural-language\nprompt is lossy and easy to misread, and the larger the change, the more drift\naccumulates. A spec turns intent into a reviewable, version-controlled,\nexecutable contract. Humans and agents align <em>before<\/em> code is written, and the\nspec stays as living documentation afterwards.<\/p>\n<hr>\n<h2 id=\"why-sdd\">Why SDD<\/h2>\n<p>The classic &ldquo;vibe coding&rdquo; loop (prompt \u2192 diff \u2192 fix \u2192 prompt again) breaks down\nas soon as the task is non-trivial:<\/p>\n<ul>\n<li><strong>Ambiguity.<\/strong> The agent fills gaps with assumptions you never see.<\/li>\n<li><strong>Drift.<\/strong> Multi-step changes lose the original intent halfway through.<\/li>\n<li><strong>No source of truth.<\/strong> Once the chat is gone, <em>why<\/em> the code looks this way\nis gone too.<\/li>\n<li><strong>Hard to review.<\/strong> Reviewing a 600-line diff is much harder than reviewing a\none-page spec that produced it.<\/li>\n<\/ul>\n<p>SDD addresses these by inserting an explicit, cheap-to-review specification step\nin front of code generation. The phases are roughly:<\/p>\n<ol>\n<li><strong>Specify<\/strong> \u2014 what to build and why (requirements, user stories, scenarios).<\/li>\n<li><strong>Plan \/ Design<\/strong> \u2014 the technical approach, architecture, trade-offs.<\/li>\n<li><strong>Tasks<\/strong> \u2014 a checklist of small, independently verifiable units of work.<\/li>\n<li><strong>Implement<\/strong> \u2014 the agent executes tasks against the spec.<\/li>\n<\/ol>\n<p>The tools below differ mainly in <em>how heavy<\/em> this process is and <em>whether<\/em> the\nspec is a living document or a throwaway scaffold.<\/p>\n<hr>\n<h2 id=\"github-spec-kit\">GitHub Spec Kit<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/github\/spec-kit\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/github\/spec-kit<\/a><\/p>\n<p>GitHub&rsquo;s official, opinionated take on SDD. It ships a CLI (<code>specify<\/code>,\ninstalled via <code>uv<\/code>) that bootstraps a project and wires a full set of slash\ncommands into your agent of choice.<\/p>\n<p>The workflow is a sequence of gated phases:<\/p>\n<ul>\n<li><code>\/speckit.constitution<\/code> \u2014 establish project principles and governance.<\/li>\n<li><code>\/speckit.specify<\/code> \u2014 define requirements and user stories.<\/li>\n<li><code>\/speckit.plan<\/code> \u2014 create the technical implementation strategy.<\/li>\n<li><code>\/speckit.tasks<\/code> \u2014 generate an actionable task breakdown.<\/li>\n<li><code>\/speckit.implement<\/code> \u2014 execute the tasks systematically.<\/li>\n<\/ul>\n<p>Plus optional helpers: <code>\/speckit.clarify<\/code> (resolve ambiguities before\nplanning), <code>\/speckit.analyze<\/code> (cross-artifact consistency checks), and\n<code>\/speckit.checklist<\/code> (custom quality gates).<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-bash\" data-lang=\"bash\"><span style=\"display:flex;\"><span>uv tool install specify-cli\n<\/span><\/span><span style=\"display:flex;\"><span>specify init my-project\n<\/span><\/span><span style=\"display:flex;\"><span>specify integration list <span style=\"color:#75715e\"># 30+ supported agents<\/span>\n<\/span><\/span><\/code><\/pre><\/div><p><strong>Pros<\/strong><\/p>\n<ul>\n<li>Backed by GitHub; mature, well-documented, actively developed.<\/li>\n<li>Genuinely thorough \u2014 the constitution + clarify + analyze steps catch\nambiguity and inconsistency early.<\/li>\n<li>Technology-agnostic; supports 30+ agents (Copilot, Claude Code, Gemini CLI,\nCursor, Codex CLI, \u2026).<\/li>\n<li>TDD-compatible task generation and parallel-task markers.<\/li>\n<\/ul>\n<p><strong>Cons<\/strong><\/p>\n<ul>\n<li>Heavyweight. The full phase sequence is overkill for small changes.<\/li>\n<li>Requires Python 3.11+, <code>uv<\/code>, and Git just to bootstrap.<\/li>\n<li>Strongly greenfield-flavored; the constitution\/specify flow assumes you are\nstarting something new rather than evolving an existing codebase.<\/li>\n<\/ul>\n<p><strong>Best for:<\/strong> new projects, larger features, and teams that want a rigorous,\nrepeatable process with explicit governance and review gates.<\/p>\n<hr>\n<h2 id=\"openspec\">OpenSpec<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/Fission-AI\/OpenSpec\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/Fission-AI\/OpenSpec<\/a><\/p>\n<p>A lightweight, change-oriented alternative. Rather than treating the spec as a\none-shot scaffold, OpenSpec maintains <em>living<\/em> specs and models work as a series\nof <strong>change proposals<\/strong> layered on top of them.<\/p>\n<p>The repository keeps two key areas:<\/p>\n<ul>\n<li><code>specs\/<\/code> \u2014 the current, agreed-upon truth (what the system <em>does<\/em> today).<\/li>\n<li><code>changes\/<\/code> \u2014 proposed deltas (a proposal, spec changes, design notes, and a\ntask checklist) for work in flight.<\/li>\n<\/ul>\n<p>The loop is intentionally small:<\/p>\n<ul>\n<li><code>\/opsx:propose<\/code> \u2014 open a new change proposal.<\/li>\n<li><code>\/opsx:apply<\/code> \u2014 implement the proposed tasks.<\/li>\n<li><code>\/opsx:archive<\/code> \u2014 fold a completed change back into the specs and archive it.<\/li>\n<\/ul>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-bash\" data-lang=\"bash\"><span style=\"display:flex;\"><span>npx openspec init <span style=\"color:#75715e\"># also: openspec update to refresh agent instructions<\/span>\n<\/span><\/span><\/code><\/pre><\/div><p><strong>Pros<\/strong><\/p>\n<ul>\n<li>Lightweight and fluid \u2014 iterates without rigid phase gates.<\/li>\n<li>Equally at home in <strong>brownfield<\/strong> codebases; the spec\/change split is built\nexactly for evolving existing systems.<\/li>\n<li>Specs are durable living documentation, not throwaway scaffolding.<\/li>\n<li>Node-based, minimal setup; integrates with 25+ tools.<\/li>\n<li>MIT licensed.<\/li>\n<\/ul>\n<p><strong>Cons<\/strong><\/p>\n<ul>\n<li>Younger and smaller community than Spec Kit.<\/li>\n<li>Fewer built-in quality gates \u2014 the discipline of clarify\/analyze is on you.<\/li>\n<li>The change\/archive model takes a little practice to internalize.<\/li>\n<\/ul>\n<p><strong>Best for:<\/strong> ongoing work on existing codebases, incremental features, and\ndevelopers who want alignment-before-code without ceremony.<\/p>\n<hr>\n<h2 id=\"other-notable-tools\">Other notable tools<\/h2>\n<p>Two more worth knowing about, since they take meaningfully different shapes:<\/p>\n<h3 id=\"amazon-kiro\">Amazon Kiro<\/h3>\n<p><a class=\"link\" href=\"https:\/\/kiro.dev\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kiro.dev\/<\/a><\/p>\n<p>An agentic IDE (rather than a CLI add-on) with SDD as a first-class feature.\nFrom a prompt it generates three artifacts \u2014 <code>requirements.md<\/code> (EARS-style\nacceptance criteria), <code>design.md<\/code>, and <code>tasks.md<\/code> \u2014 and keeps them in sync as\nyou build. <strong>Pros:<\/strong> integrated end-to-end experience, structured requirements,\nstrong onboarding. <strong>Cons:<\/strong> it&rsquo;s a whole IDE to adopt and is more of a walled\ngarden than the editor-agnostic CLIs above. <strong>Best for:<\/strong> developers willing to\nswitch IDEs for a tightly integrated spec-to-code workflow.<\/p>\n<h3 id=\"bmad-method\">BMAD-METHOD<\/h3>\n<p><a class=\"link\" href=\"https:\/\/github.com\/bmad-code-org\/BMAD-METHOD\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/bmad-code-org\/BMAD-METHOD<\/a><\/p>\n<p>&ldquo;Breakthrough Method of Agile AI-Driven Development.&rdquo; Less a spec format and\nmore an <em>agentic team<\/em>: specialized agents (Analyst, PM, Architect, Scrum\nMaster, Dev) collaborate to produce a PRD and architecture, then shard them into\nhyper-detailed story files that carry full context into implementation.\n<strong>Pros:<\/strong> rich, role-based planning; great for complex, multi-feature products.\n<strong>Cons:<\/strong> the most ceremony of the bunch; a real learning curve. <strong>Best for:<\/strong>\nambitious greenfield products where up-front planning genuinely pays off.<\/p>\n<hr>\n<h2 id=\"how-to-choose\">How to choose<\/h2>\n<table>\n<thead>\n<tr>\n<th>Tool<\/th>\n<th>Weight<\/th>\n<th>Greenfield<\/th>\n<th>Brownfield<\/th>\n<th>Setup<\/th>\n<th>Living specs<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>Spec Kit<\/strong><\/td>\n<td>Heavy<\/td>\n<td>Excellent<\/td>\n<td>OK<\/td>\n<td>Python + uv<\/td>\n<td>Per-feature<\/td>\n<\/tr>\n<tr>\n<td><strong>OpenSpec<\/strong><\/td>\n<td>Light<\/td>\n<td>Good<\/td>\n<td>Excellent<\/td>\n<td>Node<\/td>\n<td>Yes (specs\/)<\/td>\n<\/tr>\n<tr>\n<td><strong>Kiro<\/strong><\/td>\n<td>Medium<\/td>\n<td>Excellent<\/td>\n<td>Good<\/td>\n<td>Dedicated IDE<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td><strong>BMAD-METHOD<\/strong><\/td>\n<td>Heavy<\/td>\n<td>Excellent<\/td>\n<td>OK<\/td>\n<td>Node\/agents<\/td>\n<td>PRD + stories<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>A practical rule of thumb:<\/p>\n<ul>\n<li>Starting a <strong>new project<\/strong> and want rigor \u2192 <strong>Spec Kit<\/strong>.<\/li>\n<li>Evolving an <strong>existing codebase<\/strong> and want speed \u2192 <strong>OpenSpec<\/strong>.<\/li>\n<li>Want an <strong>all-in-one IDE<\/strong> experience \u2192 <strong>Kiro<\/strong>.<\/li>\n<li>Building an <strong>ambitious product<\/strong> with heavy planning needs \u2192 <strong>BMAD-METHOD<\/strong>.<\/li>\n<\/ul>\n<p>All four are MIT\/open and agent-agnostic enough to try in an afternoon. The\ncommon thread \u2014 and the real takeaway \u2014 is this: write the spec first, review\nthe spec (not the diff), and let intent, not vibes, drive the agent.<\/p>\n<hr>\n<h2 id=\"resources\">Resources<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/github\/spec-kit\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/github\/spec-kit<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/Fission-AI\/OpenSpec\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/Fission-AI\/OpenSpec<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/kiro.dev\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kiro.dev\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/bmad-code-org\/BMAD-METHOD\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/bmad-code-org\/BMAD-METHOD<\/a><\/p>"},{"title":"Certification","link":"https:\/\/canuxcheng.com\/post\/k8s_certification\/","pubDate":"Sat, 26 Jul 2025 20:55:52 +0800","guid":"https:\/\/canuxcheng.com\/post\/k8s_certification\/","description":"<h1 id=\"certification\">Certification<\/h1>\n<ul>\n<li>CKA<\/li>\n<li>CKAD<\/li>\n<li>CKS<\/li>\n<\/ul>\n<p><a class=\"link\" href=\"https:\/\/github.com\/learnk8s\/learnk8s.io\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/learnk8s\/learnk8s.io<\/a><\/p>\n<p>\u5b9e\u64cd\u5e73\u53f0\uff1a<\/p>\n<p><a class=\"link\" href=\"https:\/\/kodekloud.com\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kodekloud.com\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/killer.sh\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/killer.sh\/<\/a><\/p>\n<h2 id=\"kubeadm\">kubeadm<\/h2>\n<p>\u672c\u5730\u901a\u8fc7multipass\u90e8\u7f72vm\u3002 \u4e5f\u53ef\u4ee5\u7528virtualbox\u3002<\/p>\n<pre><code>$ brew install --cask multipass\n<\/code><\/pre>\n<p>\u542f\u52a8\u4e24\u4e2avm<\/p>\n<pre><code>$ multipass launch --name k8s-master --cpus 2 --mem 4G --disk 10G\n$ multipass launch --name k8s-worker1 --cpus 2 --mem 4G --disk 10G\n$ multipass launch --name k8s-worker2 --cpus 2 --mem 4G --disk 10G\n<\/code><\/pre>\n<p>\u5176\u5b83\u6b65\u9aa4\u53c2\u8003kubeadm\u3002<\/p>\n<h2 id=\"kind\">Kind<\/h2>\n<p>\u901a\u8fc7kind\u90e8\u7f72k8s\u96c6\u7fa4\u3002<\/p>\n<hr>\n<h2 id=\"cka\">CKA<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/walidshaari\/Kubernetes-Certified-Administrator\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/walidshaari\/Kubernetes-Certified-Administrator<\/a><\/p>\n<h2 id=\"ckad\">CKAD<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/dgkanatsios\/CKAD-exercises\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/dgkanatsios\/CKAD-exercises<\/a><\/p>\n<h2 id=\"cks\">CKS<\/h2>"},{"title":"K8S Debug","link":"https:\/\/canuxcheng.com\/post\/k8s_debug\/","pubDate":"Sat, 26 Jul 2025 20:55:52 +0800","guid":"https:\/\/canuxcheng.com\/post\/k8s_debug\/","description":"<h1 id=\"debug--troubleshooting\">Debug &amp; Troubleshooting<\/h1>\n<p>Kubernetes\u8c03\u8bd5\u548c\u6545\u969c\u6392\u9664\u5de5\u5177\u3002<\/p>\n<ul>\n<li>kubernetes-dashboard<\/li>\n<li>lens<\/li>\n<li>octant<\/li>\n<li>weave scope<\/li>\n<li>k9s<\/li>\n<\/ul>\n<hr>\n<h2 id=\"crictl\">crictl<\/h2>\n<p>\u7528\u4e8e\u5bf9node\u8c03\u8bd5.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes-sigs\/cri-tools\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes-sigs\/cri-tools<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/kubernetes.io\/docs\/tasks\/debug\/debug-cluster\/crictl\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kubernetes.io\/docs\/tasks\/debug\/debug-cluster\/crictl\/<\/a><\/p>\n<h2 id=\"nerdctl\">nerdctl<\/h2>\n<p>\u8c03\u8bd5node\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/containerd\/nerdctl\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/containerd\/nerdctl<\/a><\/p>\n<h2 id=\"telepresence\">telepresence<\/h2>\n<p>\u7528\u4e8e\u672c\u5730\u8c03\u8bd5\u96c6\u7fa4\u4e0a\u7684\u670d\u52a1.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/telepresenceio\/telepresence\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/telepresenceio\/telepresence<\/a><\/p>\n<hr>\n<h2 id=\"kubernetes-dashboard\">kubernetes-dashboard<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes\/dashboard\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes\/dashboard<\/a><\/p>\n<pre><code>\/\/ \u90e8\u7f72dashboard\n$ kubectl apply -f https:\/\/raw.githubusercontent.com\/kubernetes\/dashboard\/v2.2.0\/aio\/deploy\/recommended.yaml\n\/\/ check\n$ kubectl -n kubernetes-dashboard get pods --watch\n\/\/ \u5220\u9664\u5df2\u5b89\u88c5\u7684dashboard\n$ kubectl delete ns kubernetes-dashboard\n<\/code><\/pre>\n<h3 id=\"dashboard-arguments\">dashboard arguments<\/h3>\n<p>\u4f7f\u7528basic auth:<\/p>\n<pre><code>--enable-skip-login\n--enable-insecure-login\n--system-banner=&quot;Welcome to Kubernetes&quot;\n--authentication-mode=&quot;basic&quot; \/\/ \u9ed8\u8ba4\u662f token \u767b\u9646.\n<\/code><\/pre>\n<h3 id=\"access-control\">access control<\/h3>\n<ul>\n<li>\n<p>kubeconfig<\/p>\n<\/li>\n<li>\n<p>authorization header<\/p>\n<\/li>\n<li>\n<p>token<\/p>\n<\/li>\n<li>\n<p>basic<\/p>\n<\/li>\n<\/ul>\n<p>username\/password login<\/p>\n<h3 id=\"access-dashboard\">access dashboard<\/h3>\n<p>\u672c\u673a\u8bbf\u95ee<\/p>\n<pre><code>$ kubectl proxy\n#&gt; http:\/\/localhost:8001\/api\/v1\/namespaces\/kubernetes-dashboard\/services\/https:kubernetes-dashboard:\/proxy\/\n<\/code><\/pre>\n<p>\u8fdc\u7a0b\u8bbf\u95ee<\/p>\n<p>port-forward:<\/p>\n<pre><code>$ kubectl port-forward -n kubernetes-dashboard service\/kubernetes-dashboard 8080:443 --address 0.0.0.0\n<\/code><\/pre>\n<p>nodePort:<\/p>\n<pre><code>kind: Service\napiVersion: v1\nmetadata:\nlabels:\nk8s-app: kubernetes-dashboard\nname: kubernetes-dashboard\nnamespace: kubernetes-dashboard\nspec:\ntype: NodePort\nports:\n- port: 443\ntargetPort: 8443\nnodePort: 30001\nselector:\nk8s-app: kubernetes-dashboard\n#&gt; https:\/\/&lt;node-ip&gt;:30001\n<\/code><\/pre>\n<p>ingress:<\/p>\n<pre><code>#&gt; https:\/\/&lt;ingress-host&gt;:&lt;ingress-port&gt;\n<\/code><\/pre>\n<hr>\n<h2 id=\"metrics-server\">metrics-server<\/h2>\n<p><code>kubectl top<\/code> \u547d\u4ee4\u4f9d\u8d56\u4e8e metrics-server\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes-sigs\/metrics-server\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes-sigs\/metrics-server<\/a><\/p>\n<p>\u53c2\u6570:<\/p>\n<pre><code>--kubelet-preferred-address-types\n--kubelet-insecure-tls\n--requestheader-client-ca-file\n<\/code><\/pre>\n<p>\u90e8\u7f72:<\/p>\n<pre><code># deploy 0.3.6\n# \u4fee\u6539image\u4e3a registry.aliyuncs.com\/google_containers\/metrics-server-amd64:v0.3.6\n$ kubectl apply -f https:\/\/github.com\/kubernetes-sigs\/metrics-server\/releases\/latest\/download\/components.yaml\n<\/code><\/pre>"},{"title":"Cloud_MultiCloud","link":"https:\/\/canuxcheng.com\/post\/cloud_multicloud\/","pubDate":"Mon, 21 Jul 2025 11:13:44 +0800","guid":"https:\/\/canuxcheng.com\/post\/cloud_multicloud\/","description":"<h1 id=\"multi-cloud\">Multi-Cloud<\/h1>\n<p>\u4ee5\u63d0\u5347\u5f39\u6027\u3001\u9ad8\u53ef\u7528\u6027\u3001\u907f\u514d\u4f9b\u5e94\u5546\u9501\u5b9a\u3001\u6216\u4f18\u5316\u6210\u672c\u3002<\/p>\n<p>\u67b6\u6784\uff1a<\/p>\n<ul>\n<li>\u591a\u6d3b<\/li>\n<li>\u4e3b\u4ece<\/li>\n<\/ul>\n<h2 id=\"\u6570\u636e\u4e00\u81f4\u6027\">\u6570\u636e\u4e00\u81f4\u6027<\/h2>\n<p>\u65b9\u6848\u4e00\uff1a\naws rds\u4f5c\u4e3a\u4e3b\u6570\u636e\u5e93\uff0c\u4fee\u6539TGW + SG\u5141\u8bb8 gcp\u548cazure \u4e0a\u7684\u670d\u52a1\u8bbf\u95eeaws rds\u3002\naws &lt;-&gt; gcp cloud interconnect + aws TGW\naws &lt;-&gt; Azure vpn gateway + aws TGW<\/p>\n<p>\u65b9\u6848\u4e8c\uff1a\n\u5c06aws rds\u4f5c\u4e3a\u4e3b\u6570\u636e\u5e93\uff0c\u5728gcp\uff0cazure\u521b\u5efa\u53ea\u8bfb\u526f\u672c\uff0c\u901a\u8fc7postgresql \u6d41\u590d\u5236(streaming replication)\u5b9e\u73b0\u6570\u636e\u540c\u6b65\u3002\u914d\u7f6e\u7684\u65f6\u5019\u914d\u7f6e\u4e3b\u4ece\u4e24\u4e2a\u6570\u636e\u5e93\u3002<\/p>\n<h2 id=\"\u5bf9\u8c61\u5b58\u50a8\">\u5bf9\u8c61\u5b58\u50a8<\/h2>\n<p>\u65b9\u6848\u4e00\uff1a\n\u5bf9\u8c61\u5728aws s3\uff0c\u5176\u5b83\u5e73\u53f0\u8fdc\u7a0b\u65b9\u6848\u3002<\/p>\n<p>\u65b9\u6848\u4e8c\uff1a\n\u90e8\u7f72minIO gateway\uff0c\u81ea\u52a8\u8def\u7531\u5230aws s3\uff0cgcp gcs\uff0cazure blob storage\u3002\n\u591a\u4e91\u4e4b\u95f4\u81ea\u52a8mirror\u3002\u914d\u7f6e\u4f7f\u7528minIO gateway\u7684URL\u5373\u53ef\u3002\n\u9700\u8981\u5728aws\uff0cgcp\uff0cazure\u90fd\u90e8\u7f72minIO gateway\u3002\n\u914d\u7f6emc\u8fde\u63a5\u6240\u6709minIO\u7f51\u5173\uff0c\u521b\u5efa\u7edf\u4e00\u6876\uff0c\u4f7f\u7528minIO\u81ea\u5e26\u7684mc mirror\u5b9e\u73b0\u8de8\u4e91\u540c\u6b65\u3002<\/p>\n<p>\u65b9\u6848\u4e09 \u591a\u6d3b\uff1a\n\u6bcf\u4e2a\u5e73\u53f0\u90fd\u53ef\u4ee5\u5b58\u50a8\u5bf9\u8c61\uff0c\u57fa\u4e8e\u4e8b\u4ef6\u89e6\u53d1\u81ea\u52a8\u540c\u6b65\u3002<\/p>\n<h2 id=\"\u7edf\u4e00\u8eab\u4efd\u8ba4\u8bc1\">\u7edf\u4e00\u8eab\u4efd\u8ba4\u8bc1<\/h2>\n<p>\u4f7f\u7528Azure AD \u6216\u8005 \u4f7f\u7528keycloak\u5b9e\u73b0\u8de8\u4e91\u7edf\u4e00\u8eab\u4efd\u8ba4\u8bc1\u3002<\/p>\n<h2 id=\"\u6d88\u606f\u961f\u5217\u548c\u7f13\u5b58\">\u6d88\u606f\u961f\u5217\u548c\u7f13\u5b58<\/h2>\n<p>\u901a\u5e38\u6d88\u606f\u961f\u5217\u548c\u7f13\u5b58\u4e0d\u9700\u8981\u8de8\u4e91\u540c\u6b65\u3002<\/p>"},{"title":"LangChain","link":"https:\/\/canuxcheng.com\/post\/ai_langchain\/","pubDate":"Sat, 19 Jul 2025 11:17:34 +0800","guid":"https:\/\/canuxcheng.com\/post\/ai_langchain\/","description":"<p>LangChain \u662f\u4e00\u4e2a\u7528\u4e8e\u5f00\u53d1 LLM \u5e94\u7528\u548c AI Agent \u7684\u5f00\u6e90\u6846\u67b6\u3002\u5b83\u7edf\u4e00\u4e86\u4e0d\u540c\u6a21\u578b\u63d0\u4f9b\u5546\u7684\u8c03\u7528\u65b9\u5f0f\uff0c\u5e76\u63d0\u4f9b Messages\u3001Tools\u3001Agents\u3001Middleware\u3001Retrieval \u548c Structured Output \u7b49\u7ec4\u4ef6\u3002<\/p>\n<p>LangChain \u7684\u91cd\u70b9\u4e0d\u662f\u5c01\u88c5\u4e00\u6b21\u6a21\u578b\u8bf7\u6c42\uff0c\u800c\u662f\u628a\u6a21\u578b\u4e0e\u5916\u90e8\u6570\u636e\u3001\u5de5\u5177\u548c\u5e94\u7528\u63a7\u5236\u903b\u8f91\u7ec4\u5408\u8d77\u6765\u3002\u5f00\u53d1\u8005\u53ef\u4ee5\u5148\u4f7f\u7528\u9ad8\u5c42 API \u5feb\u901f\u6784\u5efa Agent\uff0c\u518d\u5728\u9700\u8981\u7cbe\u786e\u63a7\u5236\u6267\u884c\u8def\u5f84\u65f6\u4e0b\u6c89\u5230 LangGraph\u3002<\/p>\n<h2 id=\"langchain-\u751f\u6001\">LangChain \u751f\u6001<\/h2>\n<p>LangChain \u751f\u6001\u4e2d\u7684\u51e0\u4e2a\u9879\u76ee\u5404\u6709\u804c\u8d23\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u9879\u76ee<\/th>\n<th>\u4e3b\u8981\u804c\u8d23<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>LangChain<\/td>\n<td>\u6a21\u578b\u3001Tool\u3001Agent\u3001Middleware \u548c Retrieval \u7b49\u5f00\u53d1\u6846\u67b6<\/td>\n<\/tr>\n<tr>\n<td>LangGraph<\/td>\n<td>\u6709\u72b6\u6001\u3001\u53ef\u6062\u590d\u7684\u5e95\u5c42 Agent \u7f16\u6392\u8fd0\u884c\u65f6<\/td>\n<\/tr>\n<tr>\n<td>LangSmith<\/td>\n<td>Trace\u3001\u8bc4\u4f30\u3001\u6d4b\u8bd5\u548c\u751f\u4ea7\u53ef\u89c2\u6d4b\u6027<\/td>\n<\/tr>\n<tr>\n<td>Deep Agents<\/td>\n<td>\u5728 LangGraph \u4e4b\u4e0a\u63d0\u4f9b\u89c4\u5212\u3001\u5b50 Agent\u3001\u6587\u4ef6\u7cfb\u7edf\u548c\u4e0a\u4e0b\u6587\u7ba1\u7406\u80fd\u529b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><code>create_agent<\/code> \u521b\u5efa\u7684 Agent \u5e95\u5c42\u8fd0\u884c\u5728 LangGraph \u4e0a\uff0c\u56e0\u6b64\u4e5f\u652f\u6301 State\u3001Checkpoint\u3001Streaming \u548c Human-in-the-loop\u3002\u5927\u591a\u6570\u9879\u76ee\u53ef\u4ee5\u4ece LangChain \u5f00\u59cb\uff0c\u4e0d\u9700\u8981\u4e00\u5f00\u59cb\u5c31\u624b\u5199 Graph\u3002<\/p>\n<h2 id=\"\u6838\u5fc3\u7ec4\u4ef6\">\u6838\u5fc3\u7ec4\u4ef6<\/h2>\n<h3 id=\"models\">Models<\/h3>\n<p>LangChain \u4f7f\u7528\u7edf\u4e00\u63a5\u53e3\u8fde\u63a5\u4e0d\u540c\u6a21\u578b\u63d0\u4f9b\u5546\u3002\u5e94\u7528\u53ef\u4ee5\u4f7f\u7528 <code>invoke()<\/code>\u3001<code>stream()<\/code>\u3001<code>batch()<\/code> \u548c\u5bf9\u5e94\u7684\u5f02\u6b65\u65b9\u6cd5\u8c03\u7528\u6a21\u578b\uff0c\u800c\u4e0d\u9700\u8981\u8ba9\u4e1a\u52a1\u903b\u8f91\u4f9d\u8d56\u67d0\u4e00\u4e2a SDK\u3002<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-python\" data-lang=\"python\"><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> langchain.chat_models <span style=\"color:#f92672\">import<\/span> init_chat_model\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>model <span style=\"color:#f92672\">=<\/span> init_chat_model(<span style=\"color:#e6db74\">&#34;openai:gpt-5.4&#34;<\/span>)\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>response <span style=\"color:#f92672\">=<\/span> model<span style=\"color:#f92672\">.<\/span>invoke(\n<\/span><\/span><span style=\"display:flex;\"><span> [\n<\/span><\/span><span style=\"display:flex;\"><span> {<span style=\"color:#e6db74\">&#34;role&#34;<\/span>: <span style=\"color:#e6db74\">&#34;system&#34;<\/span>, <span style=\"color:#e6db74\">&#34;content&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\u4f60\u662f\u4e00\u540d\u7b80\u6d01\u7684\u6280\u672f\u52a9\u624b\u3002&#34;<\/span>},\n<\/span><\/span><span style=\"display:flex;\"><span> {<span style=\"color:#e6db74\">&#34;role&#34;<\/span>: <span style=\"color:#e6db74\">&#34;user&#34;<\/span>, <span style=\"color:#e6db74\">&#34;content&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\u7528\u4e00\u53e5\u8bdd\u89e3\u91ca Tool Calling\u3002&#34;<\/span>},\n<\/span><\/span><span style=\"display:flex;\"><span> ]\n<\/span><\/span><span style=\"display:flex;\"><span>)\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>print(response<span style=\"color:#f92672\">.<\/span>content)\n<\/span><\/span><\/code><\/pre><\/div><p>\u6a21\u578b\u96c6\u6210\u901a\u5e38\u653e\u5728\u72ec\u7acb\u7684 Provider Package \u4e2d\u3002\u66f4\u6362\u6a21\u578b\u65f6\u9664\u4e86\u4fee\u6539\u6a21\u578b\u540d\u79f0\uff0c\u8fd8\u9700\u8981\u5b89\u88c5\u76f8\u5e94\u96c6\u6210\u5305\u5e76\u914d\u7f6e\u8be5\u63d0\u4f9b\u5546\u7684\u51ed\u636e\u3002<\/p>\n<h3 id=\"messages\">Messages<\/h3>\n<p>Messages \u662f\u6a21\u578b\u4ea4\u4e92\u7684\u6807\u51c6\u6570\u636e\u7ed3\u6784\u3002\u5e38\u89c1\u89d2\u8272\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>System Message\uff1a\u5b9a\u4e49\u6a21\u578b\u89d2\u8272\u548c\u7ea6\u675f\uff1b<\/li>\n<li>Human Message\uff1a\u7528\u6237\u8f93\u5165\uff1b<\/li>\n<li>AI Message\uff1a\u6a21\u578b\u8f93\u51fa\uff0c\u53ef\u80fd\u5305\u542b Tool Call\uff1b<\/li>\n<li>Tool Message\uff1a\u5de5\u5177\u6267\u884c\u7ed3\u679c\u3002<\/li>\n<\/ul>\n<p>\u4f7f\u7528 Messages \u800c\u4e0d\u662f\u62fc\u63a5\u5b57\u7b26\u4e32\uff0c\u53ef\u4ee5\u4fdd\u7559\u89d2\u8272\u3001Tool Call\u3001Token Usage \u548c\u5176\u4ed6\u5143\u6570\u636e\u3002<\/p>\n<h3 id=\"tools\">Tools<\/h3>\n<p>Tool \u8ba9\u6a21\u578b\u53ef\u4ee5\u8bfb\u53d6\u5b9e\u65f6\u6570\u636e\u6216\u6267\u884c\u5916\u90e8\u64cd\u4f5c\u3002\u666e\u901a Python \u51fd\u6570\u53ef\u4ee5\u901a\u8fc7 <code>@tool<\/code> \u8f6c\u6362\u4e3a Tool\uff1a<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-python\" data-lang=\"python\"><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> langchain.tools <span style=\"color:#f92672\">import<\/span> tool\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#a6e22e\">@tool<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#66d9ef\">def<\/span> <span style=\"color:#a6e22e\">get_weather<\/span>(city: str) <span style=\"color:#f92672\">-&gt;<\/span> str:\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;&#34;&#34;\u67e5\u8be2\u6307\u5b9a\u57ce\u5e02\u5f53\u524d\u7684\u5929\u6c14\u3002&#34;&#34;&#34;<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> weather <span style=\"color:#f92672\">=<\/span> {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;\u5317\u4eac&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\u6674\uff0c26\u00b0C&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;\u4e0a\u6d77&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\u591a\u4e91\uff0c29\u00b0C&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;\u6df1\u5733&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\u9635\u96e8\uff0c31\u00b0C&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> }\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#66d9ef\">return<\/span> weather<span style=\"color:#f92672\">.<\/span>get(city, <span style=\"color:#e6db74\">f<\/span><span style=\"color:#e6db74\">&#34;\u6682\u65f6\u6ca1\u6709 <\/span><span style=\"color:#e6db74\">{<\/span>city<span style=\"color:#e6db74\">}<\/span><span style=\"color:#e6db74\"> \u7684\u5929\u6c14\u6570\u636e&#34;<\/span>)\n<\/span><\/span><\/code><\/pre><\/div><p>\u51fd\u6570\u540d\u3001\u7c7b\u578b\u6807\u6ce8\u548c Docstring \u4f1a\u5171\u540c\u6784\u6210 Tool Schema\u3002\u63cf\u8ff0\u8d8a\u51c6\u786e\uff0c\u6a21\u578b\u8d8a\u5bb9\u6613\u5728\u6b63\u786e\u7684\u65f6\u673a\u9009\u62e9\u6b63\u786e\u7684\u5de5\u5177\u3002<\/p>\n<p>Tool \u5e94\u4fdd\u6301\u5355\u4e00\u804c\u8d23\u3002\u67e5\u8be2\u548c\u4fee\u6539\u64cd\u4f5c\u6700\u597d\u62c6\u5f00\uff0c\u654f\u611f\u53c2\u6570\u5e94\u7531\u8fd0\u884c\u65f6\u6ce8\u5165\uff0c\u4e0d\u8981\u66b4\u9732\u7ed9\u6a21\u578b\u3002<\/p>\n<h2 id=\"\u5f00\u53d1\u4e00\u4e2a-agent\">\u5f00\u53d1\u4e00\u4e2a Agent<\/h2>\n<h3 id=\"\u5b89\u88c5\u4f9d\u8d56\">\u5b89\u88c5\u4f9d\u8d56<\/h3>\n<p>\u4e0b\u9762\u4ee5 OpenAI Provider \u4e3a\u4f8b\uff1a<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-bash\" data-lang=\"bash\"><span style=\"display:flex;\"><span>python -m venv .venv\n<\/span><\/span><span style=\"display:flex;\"><span>source .venv\/bin\/activate\n<\/span><\/span><span style=\"display:flex;\"><span>pip install -U <span style=\"color:#e6db74\">&#34;langchain[openai]&#34;<\/span>\n<\/span><\/span><\/code><\/pre><\/div><p>\u901a\u8fc7\u73af\u5883\u53d8\u91cf\u914d\u7f6e\u51ed\u636e\uff0c\u4e0d\u8981\u628a API Key \u5199\u8fdb\u6e90\u4ee3\u7801\uff1a<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-bash\" data-lang=\"bash\"><span style=\"display:flex;\"><span>export OPENAI_API_KEY<span style=\"color:#f92672\">=<\/span><span style=\"color:#e6db74\">&#34;...&#34;<\/span>\n<\/span><\/span><\/code><\/pre><\/div><h3 id=\"\u521b\u5efa-tool-calling-agent\">\u521b\u5efa Tool-calling Agent<\/h3>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-python\" data-lang=\"python\"><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> langchain.agents <span style=\"color:#f92672\">import<\/span> create_agent\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> langchain.tools <span style=\"color:#f92672\">import<\/span> tool\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#a6e22e\">@tool<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#66d9ef\">def<\/span> <span style=\"color:#a6e22e\">get_weather<\/span>(city: str) <span style=\"color:#f92672\">-&gt;<\/span> str:\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;&#34;&#34;\u67e5\u8be2\u6307\u5b9a\u57ce\u5e02\u5f53\u524d\u7684\u5929\u6c14\u3002&#34;&#34;&#34;<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> weather <span style=\"color:#f92672\">=<\/span> {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;\u5317\u4eac&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\u6674\uff0c26\u00b0C&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;\u4e0a\u6d77&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\u591a\u4e91\uff0c29\u00b0C&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;\u6df1\u5733&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\u9635\u96e8\uff0c31\u00b0C&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> }\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#66d9ef\">return<\/span> weather<span style=\"color:#f92672\">.<\/span>get(city, <span style=\"color:#e6db74\">f<\/span><span style=\"color:#e6db74\">&#34;\u6682\u65f6\u6ca1\u6709 <\/span><span style=\"color:#e6db74\">{<\/span>city<span style=\"color:#e6db74\">}<\/span><span style=\"color:#e6db74\"> \u7684\u5929\u6c14\u6570\u636e&#34;<\/span>)\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>agent <span style=\"color:#f92672\">=<\/span> create_agent(\n<\/span><\/span><span style=\"display:flex;\"><span> model<span style=\"color:#f92672\">=<\/span><span style=\"color:#e6db74\">&#34;openai:gpt-5.4&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> tools<span style=\"color:#f92672\">=<\/span>[get_weather],\n<\/span><\/span><span style=\"display:flex;\"><span> system_prompt<span style=\"color:#f92672\">=<\/span><span style=\"color:#e6db74\">&#34;\u4f60\u662f\u5929\u6c14\u52a9\u624b\u3002\u9700\u8981\u5929\u6c14\u6570\u636e\u65f6\u8c03\u7528\u5de5\u5177\uff0c\u4e0d\u8981\u7f16\u9020\u7ed3\u679c\u3002&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span>)\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>result <span style=\"color:#f92672\">=<\/span> agent<span style=\"color:#f92672\">.<\/span>invoke(\n<\/span><\/span><span style=\"display:flex;\"><span> {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;messages&#34;<\/span>: [\n<\/span><\/span><span style=\"display:flex;\"><span> {<span style=\"color:#e6db74\">&#34;role&#34;<\/span>: <span style=\"color:#e6db74\">&#34;user&#34;<\/span>, <span style=\"color:#e6db74\">&#34;content&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\u4e0a\u6d77\u548c\u6df1\u5733\u54ea\u4e2a\u57ce\u5e02\u66f4\u70ed\uff1f&#34;<\/span>}\n<\/span><\/span><span style=\"display:flex;\"><span> ]\n<\/span><\/span><span style=\"display:flex;\"><span> }\n<\/span><\/span><span style=\"display:flex;\"><span>)\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>result[<span style=\"color:#e6db74\">&#34;messages&#34;<\/span>][<span style=\"color:#f92672\">-<\/span><span style=\"color:#ae81ff\">1<\/span>]<span style=\"color:#f92672\">.<\/span>pretty_print()\n<\/span><\/span><\/code><\/pre><\/div><p>Agent \u7684\u6267\u884c\u5faa\u73af\u662f\uff1a<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-text\" data-lang=\"text\"><span style=\"display:flex;\"><span>\u7528\u6237\u8f93\u5165 \u2192 \u6a21\u578b\u5224\u65ad \u2192 \u8c03\u7528 Tool \u2192 \u8bfb\u53d6\u7ed3\u679c \u2192 \u6a21\u578b\u7ee7\u7eed\u5224\u65ad \u2192 \u6700\u7ec8\u56de\u7b54\n<\/span><\/span><\/code><\/pre><\/div><p>\u5982\u679c\u6a21\u578b\u4e00\u6b21\u751f\u6210\u591a\u4e2a Tool Call\uff0cAgent \u53ef\u4ee5\u6267\u884c\u8fd9\u4e9b\u5de5\u5177\u540e\u518d\u628a\u7ed3\u679c\u4ea4\u56de\u6a21\u578b\u3002\u5f53\u6a21\u578b\u4e0d\u518d\u8bf7\u6c42\u5de5\u5177\u65f6\uff0c\u5faa\u73af\u7ed3\u675f\u3002<\/p>\n<h2 id=\"structured-output\">Structured Output<\/h2>\n<p>\u5982\u679c\u4e0b\u6e38\u4ee3\u7801\u9700\u8981\u7a33\u5b9a\u7684\u6570\u636e\u7ed3\u6784\uff0c\u4e0d\u5e94\u8be5\u4f9d\u8d56\u81ea\u7136\u8bed\u8a00\u89e3\u6790\u3002\u53ef\u4ee5\u901a\u8fc7 Pydantic Schema \u8981\u6c42 Agent \u8fd4\u56de\u7ed3\u6784\u5316\u7ed3\u679c\uff1a<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-python\" data-lang=\"python\"><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> pydantic <span style=\"color:#f92672\">import<\/span> BaseModel, Field\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> langchain.agents <span style=\"color:#f92672\">import<\/span> create_agent\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#66d9ef\">class<\/span> <span style=\"color:#a6e22e\">WeatherResult<\/span>(BaseModel):\n<\/span><\/span><span style=\"display:flex;\"><span> city: str <span style=\"color:#f92672\">=<\/span> Field(description<span style=\"color:#f92672\">=<\/span><span style=\"color:#e6db74\">&#34;\u57ce\u5e02\u540d\u79f0&#34;<\/span>)\n<\/span><\/span><span style=\"display:flex;\"><span> condition: str <span style=\"color:#f92672\">=<\/span> Field(description<span style=\"color:#f92672\">=<\/span><span style=\"color:#e6db74\">&#34;\u5929\u6c14\u60c5\u51b5&#34;<\/span>)\n<\/span><\/span><span style=\"display:flex;\"><span> temperature_celsius: float <span style=\"color:#f92672\">=<\/span> Field(description<span style=\"color:#f92672\">=<\/span><span style=\"color:#e6db74\">&#34;\u6444\u6c0f\u6e29\u5ea6&#34;<\/span>)\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>structured_agent <span style=\"color:#f92672\">=<\/span> create_agent(\n<\/span><\/span><span style=\"display:flex;\"><span> model<span style=\"color:#f92672\">=<\/span><span style=\"color:#e6db74\">&#34;openai:gpt-5.4&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> tools<span style=\"color:#f92672\">=<\/span>[get_weather],\n<\/span><\/span><span style=\"display:flex;\"><span> response_format<span style=\"color:#f92672\">=<\/span>WeatherResult,\n<\/span><\/span><span style=\"display:flex;\"><span>)\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>result <span style=\"color:#f92672\">=<\/span> structured_agent<span style=\"color:#f92672\">.<\/span>invoke(\n<\/span><\/span><span style=\"display:flex;\"><span> {<span style=\"color:#e6db74\">&#34;messages&#34;<\/span>: [{<span style=\"color:#e6db74\">&#34;role&#34;<\/span>: <span style=\"color:#e6db74\">&#34;user&#34;<\/span>, <span style=\"color:#e6db74\">&#34;content&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\u4e0a\u6d77\u5929\u6c14\u5982\u4f55\uff1f&#34;<\/span>}]}\n<\/span><\/span><span style=\"display:flex;\"><span>)\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>weather <span style=\"color:#f92672\">=<\/span> result[<span style=\"color:#e6db74\">&#34;structured_response&#34;<\/span>]\n<\/span><\/span><span style=\"display:flex;\"><span>print(weather<span style=\"color:#f92672\">.<\/span>temperature_celsius)\n<\/span><\/span><\/code><\/pre><\/div><p>\u5bf9\u4e8e\u652f\u6301\u539f\u751f Structured Output \u7684\u6a21\u578b\uff0cLangChain \u4f1a\u4f18\u5148\u4f7f\u7528 Provider \u80fd\u529b\uff1b\u5426\u5219\u53ef\u4ee5\u4f7f\u7528 Tool Calling \u751f\u6210\u7b26\u5408 Schema \u7684\u7ed3\u679c\u3002<\/p>\n<h2 id=\"memory\">Memory<\/h2>\n<p>Agent \u7684\u77ed\u671f\u8bb0\u5fc6\u4fdd\u5b58\u5728 State \u4e2d\u3002\u52a0\u5165 Checkpointer \u540e\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>thread_id<\/code> \u9694\u79bb\u548c\u6062\u590d\u4e0d\u540c\u4f1a\u8bdd\uff1a<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-python\" data-lang=\"python\"><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> langchain.agents <span style=\"color:#f92672\">import<\/span> create_agent\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> langgraph.checkpoint.memory <span style=\"color:#f92672\">import<\/span> InMemorySaver\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>checkpointer <span style=\"color:#f92672\">=<\/span> InMemorySaver()\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>agent <span style=\"color:#f92672\">=<\/span> create_agent(\n<\/span><\/span><span style=\"display:flex;\"><span> model<span style=\"color:#f92672\">=<\/span><span style=\"color:#e6db74\">&#34;openai:gpt-5.4&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> tools<span style=\"color:#f92672\">=<\/span>[get_weather],\n<\/span><\/span><span style=\"display:flex;\"><span> checkpointer<span style=\"color:#f92672\">=<\/span>checkpointer,\n<\/span><\/span><span style=\"display:flex;\"><span>)\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>config <span style=\"color:#f92672\">=<\/span> {<span style=\"color:#e6db74\">&#34;configurable&#34;<\/span>: {<span style=\"color:#e6db74\">&#34;thread_id&#34;<\/span>: <span style=\"color:#e6db74\">&#34;demo-thread&#34;<\/span>}}\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>agent<span style=\"color:#f92672\">.<\/span>invoke(\n<\/span><\/span><span style=\"display:flex;\"><span> {<span style=\"color:#e6db74\">&#34;messages&#34;<\/span>: [{<span style=\"color:#e6db74\">&#34;role&#34;<\/span>: <span style=\"color:#e6db74\">&#34;user&#34;<\/span>, <span style=\"color:#e6db74\">&#34;content&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\u6211\u51c6\u5907\u53bb\u4e0a\u6d77\u3002&#34;<\/span>}]},\n<\/span><\/span><span style=\"display:flex;\"><span> config,\n<\/span><\/span><span style=\"display:flex;\"><span>)\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>result <span style=\"color:#f92672\">=<\/span> agent<span style=\"color:#f92672\">.<\/span>invoke(\n<\/span><\/span><span style=\"display:flex;\"><span> {<span style=\"color:#e6db74\">&#34;messages&#34;<\/span>: [{<span style=\"color:#e6db74\">&#34;role&#34;<\/span>: <span style=\"color:#e6db74\">&#34;user&#34;<\/span>, <span style=\"color:#e6db74\">&#34;content&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\u90a3\u91cc\u7684\u5929\u6c14\u5982\u4f55\uff1f&#34;<\/span>}]},\n<\/span><\/span><span style=\"display:flex;\"><span> config,\n<\/span><\/span><span style=\"display:flex;\"><span>)\n<\/span><\/span><\/code><\/pre><\/div><p>\u540c\u4e00\u4e2a <code>thread_id<\/code> \u4f1a\u7ee7\u7eed\u4e4b\u524d\u7684\u6d88\u606f\u5386\u53f2\uff0c\u4e0d\u540c Thread \u4e4b\u95f4\u76f8\u4e92\u9694\u79bb\u3002<\/p>\n<p><code>InMemorySaver<\/code> \u53ea\u9002\u5408\u5f00\u53d1\u548c\u6d4b\u8bd5\u3002\u751f\u4ea7\u73af\u5883\u5e94\u4f7f\u7528\u6301\u4e45\u5316 Checkpointer\uff0c\u5e76\u5bf9\u957f\u5bf9\u8bdd\u8fdb\u884c\u88c1\u526a\u6216\u6458\u8981\uff0c\u907f\u514d\u4e0a\u4e0b\u6587\u65e0\u9650\u589e\u957f\u3002<\/p>\n<h2 id=\"middleware\">Middleware<\/h2>\n<p>Middleware \u53ef\u4ee5\u5728 Agent \u5faa\u73af\u7684\u5173\u952e\u4f4d\u7f6e\u63d2\u5165\u63a7\u5236\u903b\u8f91\uff0c\u800c\u4e0d\u9700\u8981\u4fee\u6539 Agent \u672c\u8eab\u3002\u5e38\u89c1\u7528\u9014\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u81ea\u52a8\u6458\u8981\u8fc7\u957f\u7684\u5bf9\u8bdd\uff1b<\/li>\n<li>\u9650\u5236\u6a21\u578b\u6216 Tool \u8c03\u7528\u6b21\u6570\uff1b<\/li>\n<li>\u91cd\u8bd5\u548c\u6a21\u578b\u964d\u7ea7\uff1b<\/li>\n<li>PII \u68c0\u6d4b\u4e0e\u8131\u654f\uff1b<\/li>\n<li>\u52a8\u6001\u9009\u62e9\u6a21\u578b\u548c Tool\uff1b<\/li>\n<li>\u8bb0\u5f55\u65e5\u5fd7\u3001\u5ef6\u8fdf\u548c Token \u4f7f\u7528\u91cf\uff1b<\/li>\n<li>\u5728\u654f\u611f\u64cd\u4f5c\u524d\u8bf7\u6c42\u4eba\u5de5\u5ba1\u6279\u3002<\/li>\n<\/ul>\n<h3 id=\"human-in-the-loop\">Human-in-the-loop<\/h3>\n<p>\u4e0b\u9762\u7684 Agent \u4f1a\u5728\u6267\u884c\u8ba2\u5355\u64cd\u4f5c\u524d\u6682\u505c\uff0c\u7b49\u5f85\u4eba\u5de5\u6279\u51c6\u3001\u4fee\u6539\u6216\u62d2\u7edd\uff1a<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-python\" data-lang=\"python\"><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> langchain.agents <span style=\"color:#f92672\">import<\/span> create_agent\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> langchain.agents.middleware <span style=\"color:#f92672\">import<\/span> HumanInTheLoopMiddleware\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> langchain.tools <span style=\"color:#f92672\">import<\/span> tool\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> langgraph.checkpoint.memory <span style=\"color:#f92672\">import<\/span> InMemorySaver\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> langgraph.types <span style=\"color:#f92672\">import<\/span> Command\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#a6e22e\">@tool<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#66d9ef\">def<\/span> <span style=\"color:#a6e22e\">submit_order<\/span>(item: str, quantity: int) <span style=\"color:#f92672\">-&gt;<\/span> str:\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;&#34;&#34;\u63d0\u4ea4\u5546\u54c1\u8ba2\u5355\u3002&#34;&#34;&#34;<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#66d9ef\">return<\/span> <span style=\"color:#e6db74\">f<\/span><span style=\"color:#e6db74\">&#34;\u5df2\u63d0\u4ea4 <\/span><span style=\"color:#e6db74\">{<\/span>quantity<span style=\"color:#e6db74\">}<\/span><span style=\"color:#e6db74\"> \u4ef6 <\/span><span style=\"color:#e6db74\">{<\/span>item<span style=\"color:#e6db74\">}<\/span><span style=\"color:#e6db74\">&#34;<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>agent <span style=\"color:#f92672\">=<\/span> create_agent(\n<\/span><\/span><span style=\"display:flex;\"><span> model<span style=\"color:#f92672\">=<\/span><span style=\"color:#e6db74\">&#34;openai:gpt-5.4&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> tools<span style=\"color:#f92672\">=<\/span>[submit_order],\n<\/span><\/span><span style=\"display:flex;\"><span> middleware<span style=\"color:#f92672\">=<\/span>[\n<\/span><\/span><span style=\"display:flex;\"><span> HumanInTheLoopMiddleware(\n<\/span><\/span><span style=\"display:flex;\"><span> interrupt_on<span style=\"color:#f92672\">=<\/span>{<span style=\"color:#e6db74\">&#34;submit_order&#34;<\/span>: <span style=\"color:#66d9ef\">True<\/span>},\n<\/span><\/span><span style=\"display:flex;\"><span> )\n<\/span><\/span><span style=\"display:flex;\"><span> ],\n<\/span><\/span><span style=\"display:flex;\"><span> checkpointer<span style=\"color:#f92672\">=<\/span>InMemorySaver(),\n<\/span><\/span><span style=\"display:flex;\"><span>)\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>config <span style=\"color:#f92672\">=<\/span> {<span style=\"color:#e6db74\">&#34;configurable&#34;<\/span>: {<span style=\"color:#e6db74\">&#34;thread_id&#34;<\/span>: <span style=\"color:#e6db74\">&#34;approval-thread&#34;<\/span>}}\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>agent<span style=\"color:#f92672\">.<\/span>invoke(\n<\/span><\/span><span style=\"display:flex;\"><span> {<span style=\"color:#e6db74\">&#34;messages&#34;<\/span>: [{<span style=\"color:#e6db74\">&#34;role&#34;<\/span>: <span style=\"color:#e6db74\">&#34;user&#34;<\/span>, <span style=\"color:#e6db74\">&#34;content&#34;<\/span>: <span style=\"color:#e6db74\">&#34;\u8ba2\u8d2d\u4e24\u4ef6\u663e\u793a\u5668&#34;<\/span>}]},\n<\/span><\/span><span style=\"display:flex;\"><span> config,\n<\/span><\/span><span style=\"display:flex;\"><span>)\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>agent<span style=\"color:#f92672\">.<\/span>invoke(\n<\/span><\/span><span style=\"display:flex;\"><span> Command(resume<span style=\"color:#f92672\">=<\/span>{<span style=\"color:#e6db74\">&#34;decisions&#34;<\/span>: [{<span style=\"color:#e6db74\">&#34;type&#34;<\/span>: <span style=\"color:#e6db74\">&#34;approve&#34;<\/span>}]}),\n<\/span><\/span><span style=\"display:flex;\"><span> config,\n<\/span><\/span><span style=\"display:flex;\"><span>)\n<\/span><\/span><\/code><\/pre><\/div><p>\u751f\u4ea7\u73af\u5883\u4e2d\u7684\u5199\u64cd\u4f5c\u5fc5\u987b\u5177\u5907\u5e42\u7b49\u6027\uff0c\u5e76\u4f7f\u7528\u6301\u4e45\u5316 Checkpointer\uff0c\u786e\u4fdd\u5ba1\u6279\u7b49\u5f85\u671f\u95f4\u8fdb\u7a0b\u91cd\u542f\u4e5f\u4e0d\u4f1a\u4e22\u5931 State\u3002<\/p>\n<h2 id=\"retrieval-\u4e0e-rag\">Retrieval \u4e0e RAG<\/h2>\n<p>LLM \u7684\u4e0a\u4e0b\u6587\u957f\u5ea6\u6709\u9650\uff0c\u8bad\u7ec3\u6570\u636e\u4e5f\u4e0d\u662f\u5b9e\u65f6\u77e5\u8bc6\u3002Retrieval \u4f1a\u5728\u8bf7\u6c42\u65f6\u83b7\u53d6\u76f8\u5173\u5916\u90e8\u5185\u5bb9\uff0c\u518d\u8ba9\u6a21\u578b\u57fa\u4e8e\u8fd9\u4e9b\u5185\u5bb9\u56de\u7b54\uff0c\u8fd9\u5c31\u662f RAG \u7684\u57fa\u7840\u3002<\/p>\n<p>LangChain \u5c06 Retrieval \u62c6\u6210\u53ef\u66ff\u6362\u7684\u7ec4\u4ef6\uff1a<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-text\" data-lang=\"text\"><span style=\"display:flex;\"><span>Document Loader\n<\/span><\/span><span style=\"display:flex;\"><span> \u2193\n<\/span><\/span><span style=\"display:flex;\"><span>Text Splitter\n<\/span><\/span><span style=\"display:flex;\"><span> \u2193\n<\/span><\/span><span style=\"display:flex;\"><span>Embedding Model\n<\/span><\/span><span style=\"display:flex;\"><span> \u2193\n<\/span><\/span><span style=\"display:flex;\"><span>Vector Store\n<\/span><\/span><span style=\"display:flex;\"><span> \u2193\n<\/span><\/span><span style=\"display:flex;\"><span>Retriever\n<\/span><\/span><span style=\"display:flex;\"><span> \u2193\n<\/span><\/span><span style=\"display:flex;\"><span>Prompt + Model\n<\/span><\/span><\/code><\/pre><\/div><p>\u4e0d\u540c\u573a\u666f\u53ef\u4ee5\u9009\u62e9\u4e0d\u540c\u7684 RAG \u67b6\u6784\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u67b6\u6784<\/th>\n<th>\u7279\u70b9<\/th>\n<th>\u9002\u7528\u573a\u666f<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>2-step RAG<\/td>\n<td>\u6bcf\u6b21\u5148\u68c0\u7d22\u518d\u751f\u6210\uff0c\u6d41\u7a0b\u56fa\u5b9a\u3001\u5ef6\u8fdf\u53ef\u9884\u6d4b<\/td>\n<td>FAQ\u3001\u6587\u6863\u95ee\u7b54<\/td>\n<\/tr>\n<tr>\n<td>Agentic RAG<\/td>\n<td>Agent \u81ea\u5df1\u51b3\u5b9a\u4f55\u65f6\u68c0\u7d22\u4ee5\u53ca\u4f7f\u7528\u54ea\u4e2a\u6570\u636e\u6e90<\/td>\n<td>\u7814\u7a76\u52a9\u624b\u3001\u591a\u6570\u636e\u6e90\u67e5\u8be2<\/td>\n<\/tr>\n<tr>\n<td>Hybrid RAG<\/td>\n<td>\u52a0\u5165\u67e5\u8be2\u6539\u5199\u3001\u68c0\u7d22\u9a8c\u8bc1\u548c\u7b54\u6848\u68c0\u67e5<\/td>\n<td>\u5bf9\u8d28\u91cf\u548c\u53ef\u63a7\u6027\u8981\u6c42\u8f83\u9ad8\u7684\u7cfb\u7edf<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5982\u679c\u5df2\u7ecf\u6709\u641c\u7d22\u670d\u52a1\u3001SQL \u6570\u636e\u5e93\u6216\u77e5\u8bc6\u5e93\uff0c\u4e0d\u9700\u8981\u4e3a\u4e86\u4f7f\u7528 LangChain \u91cd\u65b0\u5efa\u7acb\u5411\u91cf\u6570\u636e\u5e93\u3002\u53ef\u4ee5\u628a\u73b0\u6709\u7cfb\u7edf\u5305\u88c5\u6210 Retriever \u6216 Tool\u3002<\/p>\n<h2 id=\"langchain-\u4e0e-langgraph-\u7684\u9009\u62e9\">LangChain \u4e0e LangGraph \u7684\u9009\u62e9<\/h2>\n<p>\u4f18\u5148\u4f7f\u7528 LangChain \u7684\u573a\u666f\uff1a<\/p>\n<ul>\n<li>\u8c03\u7528\u4e0d\u540c Provider \u7684\u6a21\u578b\uff1b<\/li>\n<li>\u5f00\u53d1\u6807\u51c6 Tool-calling Agent\uff1b<\/li>\n<li>\u4f7f\u7528 Middleware\u3001Structured Output \u6216 RAG\uff1b<\/li>\n<li>\u5e0c\u671b\u5feb\u901f\u7ec4\u5408\u73b0\u6709\u96c6\u6210\u3002<\/li>\n<\/ul>\n<p>\u76f4\u63a5\u4f7f\u7528 LangGraph \u7684\u573a\u666f\uff1a<\/p>\n<ul>\n<li>\u5de5\u4f5c\u6d41\u5305\u542b\u590d\u6742\u6761\u4ef6\u5206\u652f\u6216\u5e76\u884c\u8282\u70b9\uff1b<\/li>\n<li>\u9700\u8981\u7cbe\u786e\u63a7\u5236 State \u548c\u6267\u884c\u8def\u5f84\uff1b<\/li>\n<li>\u9700\u8981\u6682\u505c\u3001\u6062\u590d\u3001\u957f\u65f6\u95f4\u8fd0\u884c\u6216\u6545\u969c\u6062\u590d\uff1b<\/li>\n<li>\u9700\u8981\u591a\u4e2a Agent \u6216\u5b50\u56fe\u534f\u4f5c\u3002<\/li>\n<\/ul>\n<p>\u4e24\u8005\u4e0d\u662f\u4e92\u65a5\u5173\u7cfb\u3002\u53ef\u4ee5\u5148\u7528 <code>create_agent<\/code> \u6784\u5efa\u4e00\u4e2a Agent\uff0c\u518d\u628a\u5b83\u4f5c\u4e3a Node \u6216 Subgraph \u653e\u5165\u66f4\u5927\u7684 LangGraph \u5de5\u4f5c\u6d41\u4e2d\u3002<\/p>\n<h2 id=\"\u751f\u4ea7\u5b9e\u8df5\">\u751f\u4ea7\u5b9e\u8df5<\/h2>\n<h3 id=\"\u660e\u786e-tool-\u8fb9\u754c\">\u660e\u786e Tool \u8fb9\u754c<\/h3>\n<p>Tool \u7684\u8f93\u5165\u5fc5\u987b\u4e25\u683c\u6821\u9a8c\u3002\u8bfb\u64cd\u4f5c\u548c\u5199\u64cd\u4f5c\u5206\u79bb\uff0c\u9ad8\u98ce\u9669 Tool \u9700\u8981\u6743\u9650\u68c0\u67e5\u548c\u4eba\u5de5\u5ba1\u6279\u3002\u4e0d\u8981\u8ba9\u6a21\u578b\u76f4\u63a5\u62fc\u63a5 SQL\u3001Shell \u6216\u5176\u4ed6\u53ef\u6267\u884c\u5185\u5bb9\u540e\u65e0\u6761\u4ef6\u8fd0\u884c\u3002<\/p>\n<h3 id=\"\u4f7f\u7528-structured-output\">\u4f7f\u7528 Structured Output<\/h3>\n<p>\u6a21\u578b\u8f93\u51fa\u9700\u8981\u8fdb\u5165\u6570\u636e\u5e93\u3001API \u6216\u540e\u7eed\u5de5\u4f5c\u6d41\u65f6\uff0c\u5e94\u4f7f\u7528 Schema \u6821\u9a8c\uff0c\u800c\u4e0d\u662f\u4f9d\u8d56\u6b63\u5219\u8868\u8fbe\u5f0f\u89e3\u6790\u81ea\u7136\u8bed\u8a00\u3002<\/p>\n<h3 id=\"\u9650\u5236-agent-\u5faa\u73af\">\u9650\u5236 Agent \u5faa\u73af<\/h3>\n<p>\u9650\u5236\u6a21\u578b\u8c03\u7528\u6b21\u6570\u3001Tool \u8c03\u7528\u6b21\u6570\u3001\u603b\u8d85\u65f6\u548c Token \u9884\u7b97\u3002Agent \u65e0\u6cd5\u5b8c\u6210\u4efb\u52a1\u65f6\u5e94\u8be5\u660e\u786e\u9000\u51fa\uff0c\u800c\u4e0d\u662f\u65e0\u9650\u91cd\u8bd5\u3002<\/p>\n<h3 id=\"\u7ba1\u7406\u4e0a\u4e0b\u6587\">\u7ba1\u7406\u4e0a\u4e0b\u6587<\/h3>\n<p>\u53ea\u5411\u6a21\u578b\u63d0\u4f9b\u5f53\u524d\u4efb\u52a1\u9700\u8981\u7684\u4fe1\u606f\u3002\u957f\u5bf9\u8bdd\u5e94\u88c1\u526a\u6216\u6458\u8981\uff0c\u5927\u578b\u6587\u6863\u5e94\u901a\u8fc7 Retrieval \u6309\u9700\u52a0\u8f7d\u3002<\/p>\n<h3 id=\"\u589e\u52a0-trace-\u4e0e\u8bc4\u4f30\">\u589e\u52a0 Trace \u4e0e\u8bc4\u4f30<\/h3>\n<p>\u8bb0\u5f55 Prompt\u3001\u6a21\u578b\u8f93\u51fa\u3001Tool Call\u3001\u5ef6\u8fdf\u3001\u9519\u8bef\u548c\u6267\u884c\u8def\u5f84\u3002\u9664\u4e86\u5355\u5143\u6d4b\u8bd5\uff0c\u8fd8\u5e94\u5efa\u7acb\u5305\u542b\u6b63\u5e38\u8bf7\u6c42\u3001\u8fb9\u754c\u6761\u4ef6\u548c\u6076\u610f\u8f93\u5165\u7684\u6570\u636e\u96c6\uff0c\u5bf9 Agent \u8fdb\u884c\u56de\u5f52\u8bc4\u4f30\u3002<\/p>\n<h3 id=\"\u4fdd\u6301-provider-\u53ef\u66ff\u6362\">\u4fdd\u6301 Provider \u53ef\u66ff\u6362<\/h3>\n<p>\u628a\u6a21\u578b\u521d\u59cb\u5316\u3001\u53c2\u6570\u548c\u51ed\u636e\u653e\u5728\u914d\u7f6e\u5c42\u3002\u5207\u6362 Provider \u65f6\u4ecd\u9700\u8981\u91cd\u65b0\u8bc4\u4f30 Tool Calling\u3001Structured Output\u3001\u4e0a\u4e0b\u6587\u957f\u5ea6\u3001\u5ef6\u8fdf\u548c\u6210\u672c\uff0c\u4e0d\u80fd\u53ea\u4fee\u6539\u6a21\u578b\u540d\u79f0\u5c31\u8ba4\u4e3a\u884c\u4e3a\u5b8c\u5168\u4e00\u81f4\u3002<\/p>\n<h2 id=\"\u53c2\u8003\u8d44\u6599\">\u53c2\u8003\u8d44\u6599<\/h2>\n<ul>\n<li><a class=\"link\" href=\"https:\/\/docs.langchain.com\/oss\/python\/langchain\/overview\" target=\"_blank\" rel=\"noopener\"\n>LangChain overview<\/a><\/li>\n<li><a class=\"link\" href=\"https:\/\/docs.langchain.com\/oss\/python\/langchain\/quickstart\" target=\"_blank\" rel=\"noopener\"\n>LangChain quickstart<\/a><\/li>\n<li><a class=\"link\" href=\"https:\/\/docs.langchain.com\/oss\/python\/langchain\/agents\" target=\"_blank\" rel=\"noopener\"\n>Agents<\/a><\/li>\n<li><a class=\"link\" href=\"https:\/\/docs.langchain.com\/oss\/python\/langchain\/models\" target=\"_blank\" rel=\"noopener\"\n>Models<\/a><\/li>\n<li><a class=\"link\" href=\"https:\/\/docs.langchain.com\/oss\/python\/langchain\/middleware\/overview\" target=\"_blank\" rel=\"noopener\"\n>Middleware<\/a><\/li>\n<li><a class=\"link\" href=\"https:\/\/docs.langchain.com\/oss\/python\/langchain\/retrieval\" target=\"_blank\" rel=\"noopener\"\n>Retrieval<\/a><\/li>\n<li><a class=\"link\" href=\"https:\/\/docs.langchain.com\/oss\/python\/langchain\/human-in-the-loop\" target=\"_blank\" rel=\"noopener\"\n>Human-in-the-loop<\/a><\/li>\n<\/ul>"},{"title":"Vector DB","link":"https:\/\/canuxcheng.com\/post\/ai_vector\/","pubDate":"Sat, 19 Jul 2025 11:01:29 +0800","guid":"https:\/\/canuxcheng.com\/post\/ai_vector\/","description":"<h1 id=\"vector-db\">Vector DB<\/h1>\n<p>\u5411\u91cf\u6570\u636e\u5e93\uff08Vector Database\uff09\u662f\u4e00\u79cd\u4e13\u95e8\u7528\u4e8e\u5b58\u50a8\u548c\u68c0\u7d22\u9ad8\u7ef4\u5411\u91cf\u6570\u636e\u7684\u6570\u636e\u5e93\u3002\u5b83\u4eec\u901a\u5e38\u7528\u4e8e\u5904\u7406\u673a\u5668\u5b66\u4e60\u3001\u81ea\u7136\u8bed\u8a00\u5904\u7406\u548c\u8ba1\u7b97\u673a\u89c6\u89c9\u7b49\u9886\u57df\u4e2d\u7684\u5411\u91cf\u6570\u636e\u3002<\/p>\n<h2 id=\"milvus\">Milvus<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/milvus-io\/milvus\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/milvus-io\/milvus<\/a><\/p>\n<h2 id=\"qdrant\">qdrant<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/qdrant\/qdrant\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/qdrant\/qdrant<\/a><\/p>"},{"title":"Agent","link":"https:\/\/canuxcheng.com\/post\/ai_agent\/","pubDate":"Sat, 19 Jul 2025 10:50:10 +0800","guid":"https:\/\/canuxcheng.com\/post\/ai_agent\/","description":"<h1 id=\"agent\">Agent<\/h1>\n<h2 id=\"what-is-an-agent\">What is an agent<\/h2>\n<p>An <strong>AI agent<\/strong> is an LLM wrapped in a loop that can <em>act<\/em>, not just answer. The\nmodel decides which tool to call, observes the result, and repeats until the\ngoal is met. The essential ingredients are:<\/p>\n<ul>\n<li><strong>A model<\/strong> \u2014 the reasoning engine.<\/li>\n<li><strong>Tools<\/strong> \u2014 functions it can call (run a command, read a file, search the web).<\/li>\n<li><strong>A loop<\/strong> \u2014 plan \u2192 act \u2192 observe \u2192 re-plan, until done.<\/li>\n<li><strong>Context \/ memory<\/strong> \u2014 the task, prior steps, and relevant project knowledge.<\/li>\n<\/ul>\n<p>A plain chatbot returns text. An agent edits files, runs tests, fixes the\nfailures, and reports back \u2014 it closes the loop on real work.<\/p>\n<h2 id=\"what-is-an-agent-plugin\">What is an agent plugin<\/h2>\n<p>A <strong>plugin<\/strong> packages reusable capability so you don&rsquo;t re-teach the agent every\ntime. Across today&rsquo;s tools a plugin typically bundles some of:<\/p>\n<ul>\n<li><strong>Slash commands<\/strong> \u2014 custom prompts\/workflows you invoke by name.<\/li>\n<li><strong>Subagents<\/strong> \u2014 specialized helpers the main agent can delegate to.<\/li>\n<li><strong>Skills<\/strong> \u2014 domain knowledge loaded on demand.<\/li>\n<li><strong>Hooks<\/strong> \u2014 scripts that fire on events (e.g. before a commit).<\/li>\n<li><strong>MCP servers<\/strong> \u2014 connections to external systems (see <a class=\"link\" href=\"..\/ai_mcp\/\" >MCP<\/a>).<\/li>\n<\/ul>\n<p>Plugins make an agent extensible and shareable: install one and the agent gains\nnew commands and integrations instantly.<\/p>\n<h2 id=\"three-mainstream-agents\">Three mainstream agents<\/h2>\n<table>\n<thead>\n<tr>\n<th>Agent<\/th>\n<th>Form<\/th>\n<th>Strength<\/th>\n<th>Trade-off<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>Claude Code<\/strong><\/td>\n<td>CLI \/ IDE<\/td>\n<td>Deep autonomy, rich plugin + MCP + skills ecosystem<\/td>\n<td>Terminal-first; needs a Claude subscription\/API<\/td>\n<\/tr>\n<tr>\n<td><strong>Cursor<\/strong><\/td>\n<td>Full IDE (VS Code fork)<\/td>\n<td>Best inline editing UX, multi-model, great for exploration<\/td>\n<td>You switch editors; agent autonomy is shallower<\/td>\n<\/tr>\n<tr>\n<td><strong>GitHub Copilot<\/strong><\/td>\n<td>IDE extension + coding agent<\/td>\n<td>Native GitHub\/PR integration, huge install base<\/td>\n<td>Less open\/customizable, ecosystem-locked<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>The differences in short:<\/strong><\/p>\n<ul>\n<li><strong>Claude Code<\/strong> is the most <em>agentic<\/em> and the most <em>open<\/em> to extend \u2014 plugins,\nskills, hooks and MCP make it programmable. Best when you want the agent to\ndrive multi-step work autonomously.<\/li>\n<li><strong>Cursor<\/strong> wins on <em>editing experience<\/em>. It&rsquo;s an IDE, so completions,\ndiffs and context-picking feel native. Best for hands-on, in-editor coding.<\/li>\n<li><strong>Copilot<\/strong> wins on <em>integration and ubiquity<\/em>. It lives where your code\nalready is (GitHub, VS Code, JetBrains) and its coding agent can take an issue\nto a PR. Best for teams already standardized on GitHub.<\/li>\n<\/ul>\n<p>There is no single winner \u2014 pick by how much autonomy vs. inline control you\nwant, and how much you care about extensibility vs. zero-setup integration.<\/p>\n<h2 id=\"developing-a-plugin\">Developing a plugin<\/h2>\n<p>Using Claude Code&rsquo;s plugin system as the concrete example, a plugin is just a\ndirectory with a manifest plus the components it adds:<\/p>\n<pre tabindex=\"0\"><code>my-plugin\/\n\u251c\u2500\u2500 .claude-plugin\/plugin.json # name, version, description\n\u251c\u2500\u2500 commands\/ # slash commands (markdown prompts)\n\u251c\u2500\u2500 agents\/ # subagent definitions\n\u251c\u2500\u2500 skills\/ # on-demand knowledge\n\u251c\u2500\u2500 hooks\/ # event scripts\n\u2514\u2500\u2500 .mcp.json # MCP servers to wire in\n<\/code><\/pre><p>The workflow is roughly:<\/p>\n<ol>\n<li>Scaffold the directory and <code>plugin.json<\/code> manifest.<\/li>\n<li>Add a command \u2014 a markdown file whose body is the prompt the agent runs.<\/li>\n<li>Optionally add subagents, skills, hooks, or MCP servers.<\/li>\n<li>Install it locally to test, then publish via a marketplace\/repo so others can\ninstall it.<\/li>\n<\/ol>\n<p>You&rsquo;re not writing model code \u2014 you&rsquo;re writing <em>prompts, configuration, and\nsmall scripts<\/em> that compose into reusable behavior.<\/p>\n<hr>\n<h2 id=\"resources\">Resources<\/h2>\n<p><a class=\"link\" href=\"https:\/\/docs.claude.com\/en\/docs\/claude-code\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.claude.com\/en\/docs\/claude-code<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/cursor.com\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/cursor.com\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/features\/copilot\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/features\/copilot<\/a><\/p>"},{"title":"MCP","link":"https:\/\/canuxcheng.com\/post\/ai_mcp\/","pubDate":"Sat, 19 Jul 2025 10:50:06 +0800","guid":"https:\/\/canuxcheng.com\/post\/ai_mcp\/","description":"<h1 id=\"mcp\">MCP<\/h1>\n<h2 id=\"what-is-mcp\">What is MCP<\/h2>\n<p><strong>MCP (Model Context Protocol)<\/strong> is an open standard, introduced by Anthropic in\nlate 2024, for connecting AI agents to external tools and data. Think of it as\n&ldquo;USB-C for AI&rdquo;: instead of every agent writing a bespoke integration for every\nservice, a tool exposes itself once as an <strong>MCP server<\/strong>, and any <strong>MCP client<\/strong>\n(Claude Code, Cursor, Copilot, \u2026) can use it.<\/p>\n<p>It&rsquo;s a client\u2013server protocol (JSON-RPC over stdio or HTTP). A server can expose\nthree kinds of capability:<\/p>\n<ul>\n<li><strong>Tools<\/strong> \u2014 actions the model can invoke (query a DB, create an issue).<\/li>\n<li><strong>Resources<\/strong> \u2014 data the model can read (files, records, docs).<\/li>\n<li><strong>Prompts<\/strong> \u2014 reusable prompt templates the user can trigger.<\/li>\n<\/ul>\n<p>The win is <strong>decoupling<\/strong>: build an integration once, use it from any agent.<\/p>\n<h2 id=\"popular-open-source-mcp-servers\">Popular open-source MCP servers<\/h2>\n<p>A few widely used, open-source servers to get started with:<\/p>\n<ul>\n<li><strong>Filesystem<\/strong> \u2014 read\/write local files within allowed paths.<\/li>\n<li><strong>Git \/ GitHub \/ GitLab<\/strong> \u2014 inspect repos, manage issues and PRs.<\/li>\n<li><strong>Postgres \/ SQLite<\/strong> \u2014 run queries against a database.<\/li>\n<li><strong>Fetch<\/strong> \u2014 retrieve and convert web pages to text.<\/li>\n<li><strong>Puppeteer \/ Playwright<\/strong> \u2014 drive a real browser for testing and scraping.<\/li>\n<li><strong>Slack<\/strong> \u2014 read and post messages.<\/li>\n<li><strong>Memory<\/strong> \u2014 a persistent knowledge graph across sessions.<\/li>\n<\/ul>\n<p>The reference servers live in the official repo, and the community has built\nhundreds more (cloud providers, search, monitoring, etc.).<\/p>\n<h2 id=\"developing-an-mcp-server\">Developing an MCP server<\/h2>\n<p>The fastest path is an official SDK \u2014 Python (<code>FastMCP<\/code>) or TypeScript. A\nminimal Python server:<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-python\" data-lang=\"python\"><span style=\"display:flex;\"><span><span style=\"color:#f92672\">from<\/span> mcp.server.fastmcp <span style=\"color:#f92672\">import<\/span> FastMCP\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span>mcp <span style=\"color:#f92672\">=<\/span> FastMCP(<span style=\"color:#e6db74\">&#34;demo&#34;<\/span>)\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#a6e22e\">@mcp.tool<\/span>()\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#66d9ef\">def<\/span> <span style=\"color:#a6e22e\">add<\/span>(a: int, b: int) <span style=\"color:#f92672\">-&gt;<\/span> int:\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#e6db74\">&#34;&#34;&#34;Add two numbers.&#34;&#34;&#34;<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#66d9ef\">return<\/span> a <span style=\"color:#f92672\">+<\/span> b\n<\/span><\/span><span style=\"display:flex;\"><span>\n<\/span><\/span><span style=\"display:flex;\"><span><span style=\"color:#66d9ef\">if<\/span> __name__ <span style=\"color:#f92672\">==<\/span> <span style=\"color:#e6db74\">&#34;__main__&#34;<\/span>:\n<\/span><\/span><span style=\"display:flex;\"><span> mcp<span style=\"color:#f92672\">.<\/span>run() <span style=\"color:#75715e\"># speaks MCP over stdio<\/span>\n<\/span><\/span><\/code><\/pre><\/div><p>The steps are:<\/p>\n<ol>\n<li>Create the server and declare <strong>tools<\/strong> (functions), <strong>resources<\/strong>, and\n<strong>prompts<\/strong> \u2014 docstrings and type hints become the schema the model sees.<\/li>\n<li>Pick a <strong>transport<\/strong>: <code>stdio<\/code> for local tools, HTTP for remote\/shared servers.<\/li>\n<li>Register it with your client (e.g. an <code>.mcp.json<\/code> entry or <code>claude mcp add<\/code>).<\/li>\n<\/ol>\n<p>Clear tool names, tight descriptions, and small focused tools matter more than\nquantity \u2014 that&rsquo;s what lets the model pick the right action reliably.<\/p>\n<hr>\n<h2 id=\"resources\">Resources<\/h2>\n<p><a class=\"link\" href=\"https:\/\/modelcontextprotocol.io\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/modelcontextprotocol.io\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/modelcontextprotocol\/servers\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/modelcontextprotocol\/servers<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/modelcontextprotocol\/python-sdk\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/modelcontextprotocol\/python-sdk<\/a><\/p>"},{"title":"RAG","link":"https:\/\/canuxcheng.com\/post\/ai_rag\/","pubDate":"Sat, 19 Jul 2025 10:50:02 +0800","guid":"https:\/\/canuxcheng.com\/post\/ai_rag\/","description":"<h1 id=\"rag\">RAG<\/h1>\n<p>RAG (Retrieval-Augmented Generation) is a technique that combines retrieval and generation to improve the performance of language models. It allows models to access external knowledge bases or documents to enhance their responses.<\/p>\n<hr>\n<h2><\/h2>"},{"title":"AI","link":"https:\/\/canuxcheng.com\/post\/ai\/","pubDate":"Sat, 19 Jul 2025 10:44:35 +0800","guid":"https:\/\/canuxcheng.com\/post\/ai\/","description":"<h1 id=\"ai\">AI<\/h1>\n<p>All in AI.<\/p>\n<h2 id=\"resources\">resources<\/h2>\n<p><a class=\"link\" href=\"https:\/\/huggingface.co\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/huggingface.co\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/paperswithcode.com\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/paperswithcode.com\/<\/a><\/p>\n<h2 id=\"self-hosted-ai\">Self-Hosted AI<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/mudler\/LocalAI\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/mudler\/LocalAI<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/ollama\/ollama\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/ollama\/ollama<\/a><\/p>"},{"title":"Kserve","link":"https:\/\/canuxcheng.com\/post\/ai_kserve\/","pubDate":"Sat, 19 Jul 2025 10:44:35 +0800","guid":"https:\/\/canuxcheng.com\/post\/ai_kserve\/","description":"<h1 id=\"kserve\">Kserve<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kserve\/kserve\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kserve\/kserve<\/a><\/p>\n<p>KServe \u4e3b\u8981\u7528\u4e8e\u6a21\u578b\u63a8\u7406\uff0c\u652f\u6301\u591a\u79cd\u6a21\u578b\u683c\u5f0f\u548c\u6846\u67b6\uff0c\u5982 TensorFlow\u3001PyTorch\u3001ONNX \u7b49\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a\u7edf\u4e00\u7684 API \u6765\u7ba1\u7406\u548c\u90e8\u7f72\u673a\u5668\u5b66\u4e60\u6a21\u578b\uff0c\u5e76\u652f\u6301\u81ea\u52a8\u6269\u7f29\u5bb9\u3001\u7248\u672c\u63a7\u5236\u7b49\u529f\u80fd\u3002<\/p>"},{"title":"Kubeflow","link":"https:\/\/canuxcheng.com\/post\/ai_kubeflow\/","pubDate":"Sat, 19 Jul 2025 10:44:35 +0800","guid":"https:\/\/canuxcheng.com\/post\/ai_kubeflow\/","description":"<h1 id=\"kubeflow\">Kubeflow<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubeflow\/kubeflow\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubeflow\/kubeflow<\/a><\/p>\n<p>Kubeflow \u662f\u4e00\u4e2a\u7528\u4e8e\u5728 Kubernetes \u4e0a\u90e8\u7f72\u548c\u7ba1\u7406\u673a\u5668\u5b66\u4e60\u5de5\u4f5c\u6d41\u7684\u5f00\u6e90\u5e73\u53f0\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u6574\u5957\u5de5\u5177\u548c\u7ec4\u4ef6\uff0c\u65e8\u5728\u7b80\u5316\u673a\u5668\u5b66\u4e60\u6a21\u578b\u7684\u5f00\u53d1\u3001\u8bad\u7ec3\u3001\u90e8\u7f72\u548c\u7ba1\u7406\u8fc7\u7a0b\u3002<\/p>"},{"title":"Gateway API","link":"https:\/\/canuxcheng.com\/post\/k8s_gatewayapi\/","pubDate":"Fri, 04 Jul 2025 20:03:39 +0800","guid":"https:\/\/canuxcheng.com\/post\/k8s_gatewayapi\/","description":"<h1 id=\"gateway-api\">Gateway API<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes-sigs\/gateway-api\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes-sigs\/gateway-api<\/a><\/p>\n<p>GatewayClass\u6ca1\u6709namespace<\/p>\n<p>kubernetes\u6807\u51c6\u89c4\u8303\u3002<\/p>\n<h2 id=\"envoy-gateway\">Envoy Gateway<\/h2>\n<h2 id=\"cilium-gateway-api\">Cilium Gateway API<\/h2>\n<h2 id=\"istio-gateway\">Istio Gateway<\/h2>"},{"title":"DevEx","link":"https:\/\/canuxcheng.com\/post\/devops_devex\/","pubDate":"Fri, 10 Jan 2025 09:41:39 +0000","guid":"https:\/\/canuxcheng.com\/post\/devops_devex\/","description":"<h1 id=\"devops-metrics\">DevOps Metrics<\/h1>\n<p>\u4ece\u4e1a\u52a1\u89d2\u5ea6\u6765\u770b\uff0c\u516c\u53f8\u5e0c\u671b\u66f4\u51c6\u786e\u5730\u5ea6\u91cf\u5176\u5f00\u53d1\u4eba\u5458\u7684\u751f\u4ea7\u529b\uff0c\u539f\u56e0\u5982\u4e0b:<\/p>\n<ul>\n<li>Monitoring progress over time<\/li>\n<li>Creation of benchmarks<\/li>\n<li>Rewarding top performers<\/li>\n<li>Determining resource allocation<\/li>\n<li>Identification of more productive development processes<\/li>\n<\/ul>\n<p>\u6846\u67b6\u662f\u60f3\u6cd5\u3001\u6982\u5ff5\u548c\u5173\u7cfb\u7684\u7b80\u5355\u603b\u7ed3\uff0c\u56e0\u6b64\u57fa\u4e8e\u60a8\u7684\u4e0a\u4e0b\u6587\u3001\u73af\u5883\u548c\u56e2\u961f\uff0c\u60a8\u53ef\u4ee5\u9009\u62e9\u4e00\u7ec4\u60a8\u53ef\u4ee5\u89e3\u91ca\u7684\u6307\u6807\uff0c\u4ee5\u786e\u5b9a\u56e2\u961f\u662f\u5426\u5728\u5b83\u5e94\u8be5\u5728\u7684\u5730\u65b9\u3002<\/p>\n<h2 id=\"dora\">DORA<\/h2>\n<p>DevOps Research and Assessment.<\/p>\n<p><a class=\"link\" href=\"https:\/\/getdx.com\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/getdx.com\/<\/a><\/p>\n<h3 id=\"speed-metrics\">Speed metrics<\/h3>\n<p>Deployment frequency: This measures how often a team deploys code to production.<\/p>\n<ul>\n<li>Low performance: once per month - once per semester. (inadequate integration, lack of automation.)<\/li>\n<li>Medium performance: once per month - once per week.<\/li>\n<li>High performance: daily for multiple times per day.<\/li>\n<\/ul>\n<p>Lead time for change: This measures the time it takes from the moment a code change is made until it is successfully deployed to production.<\/p>\n<ul>\n<li>Low performance: one - six months. (time-consuming manual testing, lack of automation.)<\/li>\n<li>Medium performance: one week - one month.<\/li>\n<li>High performance: less than one day.<\/li>\n<\/ul>\n<h3 id=\"stability-metrics\">Stability metrics<\/h3>\n<p>change failure rate: This metric measures the proportion of deployments that result in failures.<\/p>\n<ul>\n<li>Poor performance: 46% - 60%. (quality and reliability issues).<\/li>\n<li>Average performance: 15%-45%.<\/li>\n<li>High performance: 0% - 15%.<\/li>\n<\/ul>\n<p>mean time to restore: This metric helps assess team\u2019s ability to handle incidents and failures.<\/p>\n<ul>\n<li>Low performance: one week - one month. (lack of adequate monitoring and diagnostic tools).<\/li>\n<li>Medium performance: one day - one week.<\/li>\n<li>High performance: less than one day.<\/li>\n<\/ul>\n<hr>\n<h2 id=\"space\">SPACE<\/h2>\n<p>S: Satisfaction and well-being<\/p>\n<p>P: Performance<\/p>\n<p>A: Activity<\/p>\n<p>C: Collaboration and communication<\/p>\n<p>E: Efficiency and flow<\/p>\n<hr>\n<h2 id=\"devex\">DevEx<\/h2>\n<p>Developer Experience: DevEx captures how developers feel, how they think, and how they value their work.<\/p>\n<h3 id=\"feedback-loops\">Feedback loops<\/h3>\n<p>perceptions:<\/p>\n<ul>\n<li>satisfaction with automated test speed and output.<\/li>\n<li>satisfaction with time it takes to validate a local change.<\/li>\n<li>satisfaction with time it takes to deploy a change to production.<\/li>\n<\/ul>\n<p>workflows:<\/p>\n<ul>\n<li>time it takes to generate CI results.<\/li>\n<li>code review turnaround time.<\/li>\n<li>deployment lead time.<\/li>\n<\/ul>\n<h3 id=\"cognitive-load\">Cognitive load<\/h3>\n<p>perceptions<\/p>\n<ul>\n<li>perceive complexity of codebase.<\/li>\n<li>ease of debugging production systems<\/li>\n<li>easy of understanding documentation.<\/li>\n<\/ul>\n<p>workflows<\/p>\n<ul>\n<li>time it takes to get answers to technical questions.<\/li>\n<li>manual steps required to deploy a change.<\/li>\n<li>frequency of documentation improvements.<\/li>\n<\/ul>\n<h3 id=\"flow-state\">Flow state<\/h3>\n<p>perceptions<\/p>\n<ul>\n<li>perceived ability to focus and avoid interruptions.<\/li>\n<li>satisfaction with clarity of task or project goals.<\/li>\n<li>perceived disruptiveness of being on-call.<\/li>\n<\/ul>\n<p>workflows<\/p>\n<ul>\n<li>number of blocks of time without meetings or interruptions.<\/li>\n<li>frequency of unplanned tasks or requests.<\/li>\n<li>frequency of incidents requiring team attention.<\/li>\n<\/ul>"},{"title":"Secret","link":"https:\/\/canuxcheng.com\/post\/sec_secret\/","pubDate":"Sun, 28 Jul 2024 16:08:54 +0000","guid":"https:\/\/canuxcheng.com\/post\/sec_secret\/","description":"<h1 id=\"secret\">Secret<\/h1>\n<p>secret scan tools<\/p>\n<h2 id=\"trufflehog\">trufflehog<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/trufflesecurity\/trufflehog\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/trufflesecurity\/trufflehog<\/a><\/p>"},{"title":"React","link":"https:\/\/canuxcheng.com\/post\/js_react\/","pubDate":"Sat, 27 Jan 2024 22:19:20 +0000","guid":"https:\/\/canuxcheng.com\/post\/js_react\/","description":"<h1 id=\"react\">React<\/h1>\n<p><a class=\"link\" href=\"https:\/\/react.dev\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/react.dev\/<\/a><\/p>"},{"title":"AWS Development","link":"https:\/\/canuxcheng.com\/post\/aws_development\/","pubDate":"Tue, 23 Jan 2024 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/aws_development\/","description":"<h1 id=\"development\">Development<\/h1>\n<h2 id=\"tools\">Tools<\/h2>\n<h3 id=\"cloud9\">Cloud9<\/h3>\n<h3 id=\"codeartifact\">CodeArtifact<\/h3>\n<h3 id=\"codebuild\">CodeBuild<\/h3>\n<h3 id=\"codecommit\">CodeCommit<\/h3>\n<h3 id=\"codedeploy\">CodeDeploy<\/h3>\n<h3 id=\"codeguru\">CodeGuru<\/h3>\n<h3 id=\"codepipeline\">CodePipeline<\/h3>\n<h3 id=\"codestar\">CodeStar<\/h3>\n<h3 id=\"x-ray\">X-Ray<\/h3>\n<hr>\n<h2 id=\"blockchain\">Blockchain<\/h2>\n<hr>\n<h2 id=\"multimedia\">Multimedia<\/h2>\n<h3 id=\"elastic-transcoder\">Elastic Transcoder<\/h3>\n<h3 id=\"kinesis-video-streams\">Kinesis Video Streams<\/h3>\n<hr>\n<h2 id=\"webmobile\">Web&amp;Mobile<\/h2>\n<h3 id=\"amplify\">Amplify<\/h3>\n<h3 id=\"api-gateway\">API Gateway<\/h3>\n<h3 id=\"device-farm\">Device Farm<\/h3>\n<h3 id=\"pinpoint\">Pinpoint<\/h3>\n<hr>\n<h2 id=\"iot\">IoT<\/h2>\n<h3 id=\"iot-analytics\">IoT Analytics<\/h3>\n<h3 id=\"iot-core\">IoT Core<\/h3>\n<h3 id=\"iot-events\">IoT Events<\/h3>\n<p>&hellip;&hellip;<\/p>\n<hr>\n<h2 id=\"mlai\">ML&amp;AI<\/h2>\n<h3 id=\"comprehend\">Comprehend<\/h3>\n<h3 id=\"forecast\">Forecast<\/h3>\n<h3 id=\"fraud-detector\">Fraud Detector<\/h3>\n<h3 id=\"kendra\">Kendra<\/h3>\n<h3 id=\"lex\">Lex<\/h3>\n<p>&hellip;&hellip;<\/p>"},{"title":"Security","link":"https:\/\/canuxcheng.com\/post\/cncf_security\/","pubDate":"Thu, 19 Oct 2023 20:03:39 +0800","guid":"https:\/\/canuxcheng.com\/post\/cncf_security\/","description":"<h1 id=\"devops-security\">DevOps Security<\/h1>\n<p>**<\/p>\n<h2 id=\"keycloak\">keycloak<\/h2>\n<p>\u767b\u5f55\u7ba1\u7406\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/keycloak\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/keycloak<\/a><\/p>\n<h2 id=\"trivy\">Trivy<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/aquasecurity\/trivy\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/aquasecurity\/trivy<\/a><\/p>\n<p>Find vulnerabilities, misconfigurations, secrets, SBOM in containers, Kubernetes, code repositories, clouds and more<\/p>\n<h2 id=\"tetragon\">Tetragon<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/cilium\/tetragon\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/cilium\/tetragon<\/a><\/p>\n<p>Tetragon is a security observability tool that provides runtime visibility into system calls, network activity, and file access in Kubernetes environments. It helps detect and respond to security threats in real-time.<\/p>\n<h2 id=\"falco\">Falco<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/falcosecurity\/falco\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/falcosecurity\/falco<\/a><\/p>\n<p>Falco is a cloud-native runtime security tool that monitors system calls and detects suspicious activity in real-time. It helps identify potential security threats and policy violations in containerized environments.<\/p>"},{"title":"First_Aid","link":"https:\/\/canuxcheng.com\/post\/first_aid\/","pubDate":"Mon, 17 Jul 2023 14:46:57 +0800","guid":"https:\/\/canuxcheng.com\/post\/first_aid\/","description":"<h1 id=\"first-aid\">First Aid<\/h1>\n<p><img src=\"https:\/\/canuxcheng.com\/images\/fa1.jpg\"\nloading=\"lazy\"\nalt=\"pic0\"\n><\/p>\n<p><img src=\"https:\/\/canuxcheng.com\/images\/fa2.jpg\"\nloading=\"lazy\"\nalt=\"pic1\"\n><\/p>\n<ol>\n<li>\n<p>\u786e\u8ba4\u73b0\u573a\u73af\u5883\u5b89\u5168<\/p>\n<\/li>\n<li>\n<p>\u5224\u65ad\u547c\u5438\u548c\u610f\u8bc6<\/p>\n<\/li>\n<\/ol>\n<p>\u5148\u8dea\u4e0b\u5224\u65ad\u610f\u8bc6\u548c\u547c\u5438\u60c5\u51b5\uff0c\u4e24\u624b\u62cd\u80a9\u8180\u547c\u53eb\uff0c\u5224\u65ad\u610f\u8bc6\uff0c\u770b\u80f8\u53e3\u8d77\u4f0f\u5224\u65ad\u547c\u5438\uff0c\u6570\u65701001\uff0c1002\uff0c&hellip; 1008 \u516b\u79d2\uff1b\u5982\u679c\u6ca1\u6709\u610f\u8bc6\u548c\u547c\u5438\u624d\u9700\u8981\u5fc3\u80ba\u590d\u82cf\u3002\u5426\u5219\u53ef\u80fd\u662f\u6c14\u9053\u6897\u963b\u3002<\/p>\n<h2 id=\"\u6c14\u9053\u6897\u963b\">\u6c14\u9053\u6897\u963b<\/h2>\n<p>\u4e0d\u5b8c\u5168\u6c14\u9053\u6897\u963b\uff1a<\/p>\n<p>\u6709\u610f\u8bc6\uff0c\u80fd\u6c9f\u901a\uff0c\u4f18\u5148\u54b3\u55fd\u6392\u51fa\u3002\n\u5176\u6b21\u91c7\u7528\u80cc\u90e8\u53e9\u51fb\u3002\n\u6700\u540e\u624d\u4f7f\u7528\u8179\u90e8\u51b2\u51fb\uff08\u6d77\u59c6\u5229\u514b\u6cd5\uff09\u3002<\/p>\n<p>\u5b8c\u5168\u6c14\u9053\u6897\u963b\uff1a<\/p>\n<p>\u6ca1\u6709\u610f\u8bc6\uff0c\u6ca1\u6709\u547c\u5438\uff0c\u9700\u8981\u5fc3\u80ba\u590d\u82cf\u3002<\/p>\n<h2 id=\"\u5fc3\u80ba\u590d\u82cf\">\u5fc3\u80ba\u590d\u82cf<\/h2>\n<p>\u6765\u4eba\u554a\uff0c\u6551\u547d\u554a\uff0c\u6709\u4eba\u6655\u5012\u4e86\uff0c\u6211\u662f\u6025\u6551\u5458\uff0c\u8bf7\u4f60\u62e8\u6253120\uff0c\u6709AED\u4e00\u5e76\u5e26\u6765\uff0c\u4f1a\u6025\u6551\u7684\u548c\u6211\u4e00\u8d77\u3002<\/p>\n<p>\u80f8\u90e8\u6309\u538b30\u6b2101\uff0c02&hellip; 30\uff0c\u6df1\u5ea65cm\u5de6\u53f3\uff0c\u786e\u4fdd\u5b8c\u5168\u56de\u5f39\u3002<\/p>\n<p>\u7136\u540e\u6e05\u7406\u53e3\u8154\u5f02\u7269\uff0c\u5439\u6c14\u4e24\u6b21\u3002<\/p>\n<p>\u80f8\u90e8\u6309\u538b\u548c\u5439\u6c14\u8fde\u7eed\u505a5\u7ec4\u3002<\/p>\n<p>\u6bcf\u505a\u5b8c5\u7ec4\u68c0\u67e5\u8109\u640f\u548c\u547c\u5438\u3002\u4e00\u53ea\u624b\u653e\u5934\u90e8\uff0c\u53e6\u4e00\u53ea\u624b\u4e24\u4e2a\u6307\u5934\u653e\u52b2\u52a8\u8109\u3002\u8ba1\u65701001\uff0c1002\uff0c&hellip; 1008\uff1b\u82e5\u6709\u547c\u5438\u62a2\u6551\u6210\u529f\uff0c\u5426\u5219\u91cd\u590d\u4e0a\u8ff0\u6b65\u9aa4\u3002<\/p>\n<p>\u5982\u679c\u6709AED\uff0c\u968f\u5230\u968f\u7528\uff0c\u5148\u6253\u5f00\u7535\u6e90\uff0c\u4e00\u4e2a\u8d34\u7247\u7528\u4e8e\u75c5\u4eba\u53f3\u4fa7\u80f8\u90e8\u4e0a\u65b9\uff0c\u4e00\u4e2a\u7528\u4e8e\u5de6\u4fa7\u80f8\u90e8\u4fa7\u65b9\uff0c\u63d0\u9192\u65c1\u4eba\u79bb\u5f00\uff0c\u5f00\u59cb\u5206\u6790\u662f\u5426\u9700\u8981\u9664\u98a4\uff0c\u82e5\u9700\u8981\u63d0\u793a\u65c1\u4eba\u79bb\u5f00\uff0c\u6309\u4e0b\u6309\u94ae\u3002\u63d0\u793a\u5b8c\u6210\u540e\u7ee7\u7eed\u5fc3\u80ba\u590d\u82cf\u3002<\/p>"},{"title":"Arduino","link":"https:\/\/canuxcheng.com\/post\/hardware_arduino\/","pubDate":"Mon, 15 May 2023 09:41:39 +0800","guid":"https:\/\/canuxcheng.com\/post\/hardware_arduino\/","description":"<h1 id=\"arduino-uno\">Arduino Uno<\/h1>\n<p>tinogo-windows\u5f00\u53d1\u73af\u5883\u914d\u7f6e<\/p>\n<p><a class=\"link\" href=\"https:\/\/tinygo.org\/getting-started\/install\/windows\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/tinygo.org\/getting-started\/install\/windows\/<\/a><\/p>\n<pre><code>scoop install go\nscoop install tinygo\nscoop install avrdude\n<\/code><\/pre>\n<p>windows\u70e7\u5199\u7a0b\u5e8f<\/p>\n<pre><code>tinygo flash -monitor -baudrate=9600 -target arduino -port COMX \/path\/to\/blinky1\n<\/code><\/pre>\n<p>macos\u70e7\u5199\u7a0b\u5e8f<\/p>\n<pre><code>tinygo flash --target arduino -port \/dev\/cu.usbserial-0001 .\/blinking.go\n<\/code><\/pre>\n<h2 id=\"microcontroller\">Microcontroller<\/h2>\n<p>Arduino Uno \u4f7f\u7528\u7684\u662fATmega328p \u63a7\u5236\u5668<\/p>\n<p>\u652f\u6301\u7684\u5916\u8bbe\u63a5\u53e3:<\/p>\n<ul>\n<li>GPIO\uff1ageneral-purpose input\/output\uff0c\u6570\u5b57\u63a5\u53e3<\/li>\n<li>UART\uff1aUniversal asynchronous receiver-transmitter\uff0c\u5f02\u6b65\u4e32\u884c\u63a5\u53e3<\/li>\n<li>SPI\uff1aSerial Peripheral Interface\uff0c\u540c\u6b65\u4e32\u884c\u63a5\u53e3<\/li>\n<li>I2C\uff1aInter-Integrated Circuit, \u540c\u6b65\u4e32\u884c\u63a5\u53e3<\/li>\n<li>ADC\uff1aAnalog-to-digital, \u6a21\u62df\u8f6c\u6570\u5b57\u63a5\u53e3<\/li>\n<li>PWM: Pulse-width modulation,<\/li>\n<li>USB\uff1a\u4e0d\u652f\u6301\uff0c\u5f02\u6b65\u4e32\u884c\u63a5\u53e3<\/li>\n<\/ul>\n<h2 id=\"machine-\u5305\">machine \u5305<\/h2>\n<p>machine\u5305\u662ftinygo\u4e2d\u6838\u5fc3\u5305<\/p>\n<h2 id=\"driver\">Driver<\/h2>\n<p><a class=\"link\" href=\"https:\/\/tinygo.org\/docs\/reference\/devices\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/tinygo.org\/docs\/reference\/devices\/<\/a><\/p>\n<p>\u5b89\u88c5\u652f\u6301\u7684driver<\/p>\n<pre><code>go get tinygo.org\/x\/drivers\n<\/code><\/pre>"},{"title":"GCP","link":"https:\/\/canuxcheng.com\/post\/gcp\/","pubDate":"Sun, 23 Apr 2023 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/gcp\/","description":"<h1 id=\"gcp\">GCP<\/h1>\n<p>gcp certification:<\/p>\n<ul>\n<li>Google Cloud Certified Cloud Digital Leader<\/li>\n<li>Google Cloud Certified Associate Cloud Engineer<\/li>\n<li>Google Cloud Certified DevOps Engineer<\/li>\n<li>Google Cloud Certified Machine Learning Engineer<\/li>\n<li>Google Cloud Certified Professional Cloud Architect<\/li>\n<li>Google Cloud Certified Professional Data Engineer<\/li>\n<li>Google Cloud Certified Professional Network Engineer<\/li>\n<li>Google Cloud Certified Professional Security Engineer<\/li>\n<\/ul>\n<hr>\n<h2 id=\"cloud-sdk\">Cloud SDK<\/h2>\n<p><a class=\"link\" href=\"https:\/\/cloud.google.com\/sdk\/docs\/install\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/cloud.google.com\/sdk\/docs\/install<\/a><\/p>\n<p>\u9ed8\u8ba4\u5b89\u88c5\u7684\u7ec4\u4ef6:<\/p>\n<ul>\n<li>bq<\/li>\n<li>bundled-python3-unix<\/li>\n<li>gsutil<\/li>\n<li>core<\/li>\n<li>gcloud-crc32c<\/li>\n<li>alpha<\/li>\n<li>beta<\/li>\n<\/ul>\n<p>\u5b89\u88c5\u5176\u5b83\u7ec4\u4ef6:<\/p>\n<pre><code>gcloud components install app-engine-go docker-credential-gcr kustomize log-streaming terraform-tools app-engine-python app-engine-python-extras gke-gcloud-auth-plugin kubectl kubectl-oidc\n<\/code><\/pre>\n<p>\u5378\u8f7d:<\/p>\n<pre><code>gcloud components remove &lt;component_id&gt;\n<\/code><\/pre>\n<p>\u5347\u7ea7<\/p>\n<pre><code>gcloud components update\n<\/code><\/pre>\n<h2 id=\"gcp-command-line-interface\">GCP Command Line Interface<\/h2>\n<p>\u4f7f\u7528:<\/p>\n<pre><code>gcloud --help\n<\/code><\/pre>\n<h3 id=\"cli-credentials\">CLI credentials<\/h3>\n<p>\u521d\u59cb\u5316\uff1a<\/p>\n<pre><code>gcloud init\ngcloud init --no-launch-browser\ngcloud init --console-only\n<\/code><\/pre>\n<p>\u914d\u7f6e\uff1a<\/p>\n<p>\u914d\u7f6e\u5b58\u50a8\u4f4d\u7f6e:<\/p>\n<pre><code>linux\/unix: ~\/.config\/gcloud\nwindows: %APPDATA%\\gcloud\n<\/code><\/pre>\n<p>\u914d\u7f6e\u7ba1\u7406:<\/p>\n<pre><code>\/\/ \u521b\u5efa\u914d\u7f6e\ngcloud config configurations create [name]\n\/\/ \u5217\u51fa\u914d\u7f6e\ngcloud config configurations list\n\/\/ \u67e5\u770b\u914d\u7f6e\u5c5e\u6027\ngcloud config configurations describe [name]\n\/\/ \u6fc0\u6d3b\u914d\u7f6e\ngcloud config configurations activate [name]\n\/\/ \u5220\u9664\u914d\u7f6e\ngcloud config configurations delete [name]\n<\/code><\/pre>\n<p>\u5c5e\u6027\u7ba1\u7406:<\/p>\n<pre><code>\/\/ \u67e5\u770b\u5c5e\u6027\ngcloud config list\n\/\/ \u5207\u6362account\ngcloud config set account [account]\n\/\/ \u5207\u6362project\ngcloud config set project [project]\n\/\/ \u67e5\u770b\u53ef\u7528\u5c5e\u6027\ngcloud config set --help\n\/\/ \u663e\u793a\u53ef\u7528\u5c5e\u6027\u7684\u5217\u8868\ngcloud topic configurations\n<\/code><\/pre>\n<p>\u767b\u5f55:<\/p>\n<pre><code>\/\/ \u9ed8\u8ba4\u6253\u5f00\u6d4f\u89c8\u5668\u6388\u6743\ngcloud auth login\n\/\/ \u7528\u4e8e\u6ca1\u6709\u6d4f\u89c8\u5668\u7684\u673a\u5668\n\/\/ \u590d\u5236gcloud auth login --remote-bootstrap=&quot;\u547d\u4ee4\u5728\u53e6\u5916\u4e00\u53f0\u5b89\u88c5\u4e86\u6d4f\u89c8\u5668\u548cgcloud cli\u7684\u673a\u5668\u6253\u5f00\u3002\n\/\/ \u5c06\u6d4f\u89c8\u5668\u7684\u8f93\u51fa\u5e16\u56de\u6ca1\u6709\u6d4f\u89c8\u5668\u7684\u673a\u5668\u3002\ngcloud auth login --no-browser\n\/\/ \u7528\u4e8e\u6ca1\u6709\u6d4f\u89c8\u5668\u7684\u673a\u5668\uff0c\u590d\u5236Https\u7f51\u5740\u6253\u5f00\u6d4f\u89c8\u5668\u6388\u6743\u3002\ngcloud auth login --no-launch-browser\n\/\/ \u5217\u51fa\u8d26\u53f7.\ngcloud auth list\n\/\/ \u7981\u6b62\u901a\u8fc7cli\u767b\u5f55\ngcloud auth revoke [account]\n\/\/ \u67e5\u627e\u51ed\u636e\u6587\u4ef6\u4f4d\u7f6e\ngcloud info\n<\/code><\/pre>\n<p>Application Default Credentials\uff08ADC):<\/p>\n<pre><code>\/\/ \u5c06\u7528\u6237\u51ed\u636e\u63d0\u4f9b\u7ed9ADC(\u7528\u4e8esdk\u6216\u8005terraform\u7b49\u4ea4\u4e92\uff09\u3002\ngcloud auth application-default login --no-launch-browser\n<\/code><\/pre>\n<p>\u4ea4\u4e92\u5f0fshell<\/p>\n<pre><code>gcloud beta interactive\n<\/code><\/pre>\n<hr>\n<h2 id=\"compute\">compute<\/h2>\n<ul>\n<li>Kubernetes: GKE(EKS)<\/li>\n<li>Compute engine(EC2): compute engine<\/li>\n<li>Batch<\/li>\n<li>workload manager<\/li>\n<\/ul>\n<hr>\n<h2 id=\"serverless\">ServerLess<\/h2>\n<ul>\n<li>cloud run<\/li>\n<li>cloud functions<\/li>\n<li>app engine<\/li>\n<li>api gateway<\/li>\n<li>endpoints<\/li>\n<\/ul>\n<hr>\n<h2 id=\"network\">network<\/h2>\n<ul>\n<li>VPC<\/li>\n<li>cloud router<\/li>\n<li>cloud DNS(route53)<\/li>\n<li>cloud domains(route53)<\/li>\n<li>cloud firewall(DNS firewall, network firewall, SG, ACL)<\/li>\n<li>cloud interconnect(direct connect)<\/li>\n<li>cloud VPN<\/li>\n<li>cloud NAT<\/li>\n<li>cloud CDN<\/li>\n<li>cloud load balancing<\/li>\n<\/ul>\n<h3 id=\"cloud-load-balancer\">Cloud Load balancer<\/h3>\n<p>Application LB(http\/https):<\/p>\n<ul>\n<li>external LB(gce): external global lb(gke-l7-global-external-managed), external classic global lb(gke-l7-gxlb), external regional lb\uff08gke-l7-regional-external-managed\uff09.<\/li>\n<li>internal LB(gce-internal, gke-l7-rilb): internal regional lb.<\/li>\n<\/ul>\n<p>Proxy LB(TCP\/SSL):<\/p>\n<ul>\n<li>external<\/li>\n<li>internal<\/li>\n<\/ul>\n<p>Passthrough LB(TCP\/UDP):<\/p>\n<ul>\n<li>external<\/li>\n<li>internal<\/li>\n<\/ul>\n<hr>\n<h2 id=\"storage\">storage<\/h2>\n<ul>\n<li>persistent disk(EBS): (balanced\/extreme\/ssd\/standard) \u521b\u5efavm\u7684\u65f6\u5019\u521b\u5efa\u5757\u5b58\u50a8\u3002<\/li>\n<li>cloud storage(S3): (standard\/nearline\/coldline\/archive) \u53ef\u4ee5\u5728\u5168\u7403\u8303\u56f4\u5185\u968f\u65f6\u5b58\u50a8\u548c\u68c0\u7d22\u4efb\u610f\u6570\u91cf\u7684\u6570\u636e<\/li>\n<li>cloud storage for filebase(S3): \u4e13\u4e3a\u9700\u8981\u5b58\u50a8\u548c\u63d0\u4f9b\u7528\u6237\u751f\u6210\u7684\u5185\u5bb9\uff08\u5982\u7167\u7247\u6216\u89c6\u9891\uff09\u7684\u5e94\u7528\u5f00\u53d1\u8005\u800c\u6253\u9020\u7684<\/li>\n<li>filestore(EFS): file storage<\/li>\n<\/ul>\n<hr>\n<h2 id=\"database\">Database<\/h2>\n<ul>\n<li>Cloud SQL(RDS, Aurora): RDBMA<\/li>\n<li>Cloud Spanner(Aurora): RDBMS<\/li>\n<li>Cloud Bigtable(dynamoDB): NoSQL: Key-value<\/li>\n<li>datastore(dynamoDB): NoSQL: Indexed<\/li>\n<li>memorystore(elastiCache): In-memory data store, memcached\/redis<\/li>\n<li>BigQuery<\/li>\n<\/ul>\n<hr>\n<h2 id=\"security\">Security<\/h2>\n<ul>\n<li>certificate authority service(ACM): Certificate management<\/li>\n<li>cloud identity(IAM):<\/li>\n<li>Identity and access management(IAM):<\/li>\n<li>Identity-Aware Proxy(IAM):<\/li>\n<li>cloud key management service(KMS):<\/li>\n<\/ul>\n<p>IAM members:<\/p>\n<ul>\n<li>google account<\/li>\n<li>google service account<\/li>\n<li>google groups<\/li>\n<li>cloud identity domain<\/li>\n<li>google workspace domain<\/li>\n<\/ul>\n<p>IAM basic roles:<\/p>\n<ul>\n<li>Owner<\/li>\n<li>Editor<\/li>\n<li>Viewer<\/li>\n<li>Billing Administrator<\/li>\n<\/ul>\n<p>Service account types:<\/p>\n<ul>\n<li>user created<\/li>\n<li>built-in (compute engine or gke default SA)<\/li>\n<li>Google APIs SA<\/li>\n<\/ul>\n<hr>\n<h2 id=\"operation\">Operation<\/h2>\n<ul>\n<li>Monitoring<\/li>\n<li>Debugger<\/li>\n<li>Logging<\/li>\n<li>Error reporting<\/li>\n<li>Trace<\/li>\n<li>Profiler<\/li>\n<\/ul>\n<hr>\n<h2 id=\"analytics\">Analytics<\/h2>\n<ul>\n<li>BigQuery<\/li>\n<li>Pub\/Sub<\/li>\n<\/ul>\n<hr>\n<h2 id=\"cicd\">CI\/CD<\/h2>\n<ul>\n<li>cloud build<\/li>\n<li>cloud deploy<\/li>\n<li>container registry<\/li>\n<li>artifact registry<\/li>\n<li>source repositories<\/li>\n<\/ul>\n<hr>\n<h2 id=\"how-to-ssh-to-vm\">how to ssh to vm<\/h2>\n<h3 id=\"metadata\">Metadata<\/h3>\n<p>\u5206\u4e3aProject metadata\u548cinstance metadata\u3002<\/p>\n<h4 id=\"ssh\">ssh<\/h4>\n<p>Only for external IP (public IP).<\/p>\n<ul>\n<li>ssh key for vm: add ssh pub key to instance metadata.<\/li>\n<li>ssh key for project: add ssh pub key to project metadata.<\/li>\n<\/ul>\n<p>ssh to vm<\/p>\n<pre><code>ssh username_from_metadata@external_IP\n<\/code><\/pre>\n<h4 id=\"gcloud\">gcloud<\/h4>\n<p>\u9996\u6b21\u8fd0\u884c\u4f1a\u521b\u5efassh \u5bc6\u94a5\u5bf9\uff0c\u7528\u6237\u540d\u662f\u672c\u5730\u673a\u5668\u7528\u6237\u540d,google_compute_engine.<\/p>\n<p>\u516c\u94a5\u4f1a\u81ea\u52a8\u4e0a\u4f20\u5230project\/instance metadata.<\/p>\n<pre><code>gcloud compute ssh public-instance \\\n--project=PJ \\\n--zone=RZ\n<\/code><\/pre>\n<h3 id=\"os-login\">OS Login<\/h3>\n<p>\u8bbe\u7f6e OS Login \u5143\u6570\u636e\u65f6\uff0cCompute Engine \u4f1a\u5220\u9664\u865a\u62df\u673a\u7684 authorized_keys \u6587\u4ef6\uff0c\u5e76\u4e14\u4e0d\u518d\u63a5\u53d7\u6765\u81ea\u9879\u76ee\u6216\u5b9e\u4f8b\u5143\u6570\u636e\u4e2d\u5b58\u50a8\u7684 SSH \u5bc6\u94a5\u7684\u8fde\u63a5\u3002<\/p>\n<p>\u7528\u6237\u540d\u4e3acanuxcheng@gmail.com =&gt; canuxcheng_gmail_com<\/p>\n<h4 id=\"ssh-1\">ssh<\/h4>\n<p>\u4f7f\u7528ssh\u9700\u8981\u5c06\u516c\u94a5\u4e0a\u4f20\u5230OS Login\u914d\u7f6e(\u5ffd\u7565\u5bc6\u94a5\u4e2d\u7684\u7528\u6237\u540d\uff09\u3002<\/p>\n<pre><code>gcloud compute os-login ssh-keys add \\\n--key-file=public_KEY_FILE_PATH \\\n--project=PROJECT \\\n--ttl=EXPIRE_TIME\n<\/code><\/pre>\n<p>ssh<\/p>\n<pre><code>ssh canuxcheng_gmail_com@IP\n<\/code><\/pre>\n<h4 id=\"gcloud-1\">gcloud<\/h4>\n<p>\u9996\u6b21\u8fd0\u884c\u4f1a\u521b\u5efassh \u5bc6\u94a5\u5bf9\uff0c\u516c\u94a5\u4f1a\u81ea\u52a8\u4e0a\u4f20\u5230os login config.<\/p>\n<pre><code>gcloud compute ssh instance --internal-ip --project=PJ --zone=RZ\n<\/code><\/pre>\n<h3 id=\"iap\">IAP<\/h3>\n<p>Identity-Aware Proxy<\/p>\n<p><a class=\"link\" href=\"https:\/\/cloud.google.com\/iap\/docs\/using-tcp-forwarding?_ga=2.127808461.-1134224509.1683858043&amp;hl=zh-cn#firewall\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/cloud.google.com\/iap\/docs\/using-tcp-forwarding?_ga=2.127808461.-1134224509.1683858043&hl=zh-cn#firewall<\/a><\/p>\n<p>use internal ip directly:<\/p>\n<pre><code>gcloud compute ssh private-instance --project=PJ --zone=europe-west4-a --internal-ip\n<\/code><\/pre>\n<p>use iap:<\/p>\n<pre><code>gcloud compute ssh private-instance \\\n--project=PJ \\\n--zone=RZ \\\n--tunnel-through-iap\n<\/code><\/pre>"},{"title":"Auth","link":"https:\/\/canuxcheng.com\/post\/django_auth\/","pubDate":"Fri, 14 Jan 2022 04:29:37 +0000","guid":"https:\/\/canuxcheng.com\/post\/django_auth\/","description":"<h1 id=\"authpy\">auth.py<\/h1>\n<p>\u81ea\u5b9a\u4e49authentication backend.<\/p>\n<pre><code>from django.contrib.auth.backends import BaseBackend\nclass MyBackend(BaseBackend):\ndef authenticate(self, request):\n...\ndef get_user(self, user_id):\n...\n<\/code><\/pre>\n<p>\u914d\u7f6e\u4f7f\u7528\u81ea\u5b9a\u4e49backend<\/p>\n<pre><code>AUTHENTICATION_BACKENDS = (&quot;apps.ldap_auth.auth.MyBackend&quot;,)\n<\/code><\/pre>\n<p><a class=\"link\" href=\"https:\/\/github.com\/etianen\/django-python3-ldap\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/etianen\/django-python3-ldap<\/a><\/p>\n<h1 id=\"auth\">auth<\/h1>\n<p>\u914d\u7f6e<\/p>\n<pre><code>INSTALLED_APPS = (\n'django.contrib.auth'\uff0c\n'django.contrib.contenttypes'\n)\n<\/code><\/pre>\n<p>&lsquo;django.contrib.auth&rsquo; \u5305\u542b\u4e86\u9a8c\u8bc1\u6846\u67b6\u7684\u5185\u6838\u548c\u5b83\u7684\u9ed8\u8ba4\u6a21\u578b\u3002<\/p>\n<p>&lsquo;django.contrib.contenttypes&rsquo; \u662f Django content type system \uff0c\u5141\u8bb8\u4f60\u521b\u5efa\u7684\u6a21\u578b\u548c\u6743\u9650\u76f8\u5173\u8054\u3002<\/p>\n<pre><code>MIDDLEWARE_CLASSES = (\n'django.contrib.sessions.middleware.SessionMiddleware',\n'django.contrib.auth.middleware.AuthenticationMiddleware',\n)\n<\/code><\/pre>\n<p>\u7528\u6237\u767b\u5f55:<\/p>\n<pre><code>from django.contrib.auth import authenticate, login\nuser = authenticate(username='name', password='pw')\nlogin(request, user)\n<\/code><\/pre>\n<p>\u767b\u9646\u65f6\u7684\u9ed8\u8ba4\u9a8c\u8bc1\u540e\u7aef:<\/p>\n<pre><code>AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.ModelBackend']\n<\/code><\/pre>\n<p>\u7528\u6237\u767b\u51fa:<\/p>\n<pre><code>from django.contrib.auth import logout\nlogout(request)\n<\/code><\/pre>\n<hr>"},{"title":"Application","link":"https:\/\/canuxcheng.com\/post\/cncf_application\/","pubDate":"Sat, 04 Dec 2021 20:03:39 +0800","guid":"https:\/\/canuxcheng.com\/post\/cncf_application\/","description":"<h1 id=\"application-definition--image-build\">Application Definition &amp; Image Build<\/h1>\n<p>application choreography.<\/p>\n<ul>\n<li>helm<\/li>\n<li>backstage<\/li>\n<li>buildpack.io<\/li>\n<li>operatorframework<\/li>\n<li>dapr<\/li>\n<li>kubevela<\/li>\n<li>kubevirt<\/li>\n<\/ul>\n<hr>\n<h2 id=\"backstage\">backstage<\/h2>"},{"title":"AWS CLF","link":"https:\/\/canuxcheng.com\/post\/aws_clf\/","pubDate":"Sat, 23 Oct 2021 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/aws_clf\/","description":"<h1 id=\"clf\">CLF<\/h1>\n<p>Foundational: 6\u4e2a\u6708\u7ecf\u9a8c. Cloud Practitioner Foundational(CLF).<\/p>\n<ul>\n<li>Fundamental cloud concepts for AWS<\/li>\n<li>Understanding AWS core services<\/li>\n<li>Introduction to security &amp; architecture on AWS<\/li>\n<li>AWS certified cloud practitioner exam prep<\/li>\n<\/ul>"},{"title":"RTFM","link":"https:\/\/canuxcheng.com\/rtfm\/","pubDate":"Thu, 14 Oct 2021 01:54:39 -0400","guid":"https:\/\/canuxcheng.com\/rtfm\/","description":"<p>Read The Fucking Manual<\/p>\n<p><a class=\"link\" href=\"https:\/\/kubernetes.io\/docs\/home\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kubernetes.io\/docs\/home\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/docs.docker.com\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.docker.com\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/golang.org\/doc\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/golang.org\/doc\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/docs.python.org\/3\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.python.org\/3\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/www.typescriptlang.org\/docs\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.typescriptlang.org\/docs\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/nodejs.org\/en\/docs\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/nodejs.org\/en\/docs\/<\/a><\/p>"},{"title":"AWS Management","link":"https:\/\/canuxcheng.com\/post\/aws_management\/","pubDate":"Thu, 23 Sep 2021 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/aws_management\/","description":"<h1 id=\"aws-monitor\">AWS Monitor<\/h1>\n<h2 id=\"cli\">CLI<\/h2>\n<h2 id=\"management-console\">Management Console<\/h2>\n<h2 id=\"quotas\">Quotas<\/h2>\n<h2 id=\"service-catalog\">Service Catalog<\/h2>\n<h2 id=\"cloudwatch\">CloudWatch<\/h2>\n<p>\u76d1\u63a7\u548c\u7ba1\u7406\u670d\u52a1\uff0c\u6536\u96c6logs, metrics \u548c events\uff0c\u652f\u6301\u57fa\u4e8emetrics\u7684alert\u3002<\/p>\n<p>MTTR\nTCO<\/p>\n<h2 id=\"cloudwatch-logs\">CloudWatch Logs<\/h2>\n<h2 id=\"cloudtrail\">CloudTrail<\/h2>\n<p>\u53ef\u4ee5\u7528\u6765\u8bb0\u5f55\uff0c\u6301\u7eed\u76d1\u63a7\u548c\u4fdd\u7559\u4e0eAWS\u57fa\u7840\u8bbe\u65bd\u4e2d\u7684\u64cd\u4f5c\u76f8\u5173\u7684\u8d26\u6237\u6d3b\u52a8\u3002<\/p>\n<p>\u5c06\u5ba1\u8ba1\u8bb0\u5f55\u63d2\u5165S3\u6216\u8005cloudwatch log\uff0c \u8bb0\u5f55\u7a81\u53d1\u4e8b\u4ef6\u3002<\/p>\n<h2 id=\"aws-config\">AWS Config<\/h2>\n<p>\u63d0\u4f9b\u57fa\u7840\u8bbe\u65bd\u7684\u5386\u53f2\u914d\u7f6e\u3002\u57fa\u4e8e\u89c4\u5219\u6301\u7eed\u8bc4\u4f30\u57fa\u7840\u8bbe\u65bd\u3002<\/p>\n<h2 id=\"aws-trusted-advisor\">AWS Trusted Advisor<\/h2>\n<p>\u4f18\u5316\u6027\u80fd\u548c\u5b89\u5168\u6027<\/p>\n<h2 id=\"amazon-grafana\">Amazon Grafana<\/h2>\n<h2 id=\"amazon-prometheus\">Amazon Prometheus<\/h2>\n<h2 id=\"cloudformation\">CloudFormation<\/h2>\n<p>\u63d0\u4f9b\u57fa\u4e8e\u6a21\u677f(yaml\/json)\u7684\u57fa\u7840\u8bbe\u65bd\u670d\u52a1(IaaS).<\/p>\n<h2 id=\"compute-optimizer\">Compute Optimizer<\/h2>\n<h2 id=\"control-tower\">Control Tower<\/h2>\n<p>\u662forganization\u7684\u9ad8\u7ea7\u5c01\u88c5\uff0c\u63d0\u4f9b\u8de8\u8d26\u6237\u7684\u7ba1\u7406\u3002<\/p>\n<ul>\n<li>\u5feb\u901f\u90e8\u7f72\u591a\u8d26\u6237\u67b6\u6784\uff08Landing Zone\uff09<\/li>\n<li>\u81ea\u52a8\u5316\u521b\u5efa OU \u548c\u8d26\u6237<\/li>\n<li>\u7ba1\u7406\u5408\u89c4\u6027\u4e0e\u5ba1\u8ba1\uff08\u5f3a\u5236 Guardrails\uff09<\/li>\n<\/ul>\n<h2 id=\"health-dashboard\">Health Dashboard<\/h2>\n<h2 id=\"aws-systems-manager\">AWS Systems Manager<\/h2>\n<p>\u63d0\u4f9b\u8fd0\u7ef4\u6570\u636e\uff0c\u5e76\u4e14\u5728\u8de8\u57fa\u7840\u8bbe\u65bd\u4e2d\u8fdb\u884c\u81ea\u52a8\u5316\u64cd\u4f5c\u3002<\/p>\n<h2 id=\"aws-organizations\">AWS Organizations<\/h2>\n<p>\u4e3b\u8981\u529f\u80fd\uff1a<\/p>\n<ul>\n<li>\u521b\u5efa\u3001\u7ba1\u7406\u591a\u4e2a AWS \u8d26\u6237<\/li>\n<li>\u5b9e\u65bd\u7edf\u4e00\u7684\u6743\u9650\u7b56\u7565\u3001\u5b89\u5168\u7b56\u7565\u548c\u9884\u7b97\u7ba1\u7406<\/li>\n<li>\u96c6\u4e2d\u63a7\u5236\u548c\u76d1\u63a7\u4f01\u4e1a\u8d44\u6e90<\/li>\n<\/ul>\n<p>OU: organizational unit.<\/p>\n<p>\u4f01\u4e1a\u7ea7\u67b6\u6784\u8bbe\u8ba1\uff1a<\/p>\n<ul>\n<li>\u4e00\u4e2a OU \u653e\u201c\u751f\u4ea7\u8d26\u6237\u201d<\/li>\n<li>\u4e00\u4e2a OU \u653e\u201c\u5f00\u53d1\u4e0e\u6d4b\u8bd5\u8d26\u6237\u201d<\/li>\n<li>\u4e00\u4e2a OU \u4e13\u95e8\u505a\u201c\u5b89\u5168\u548c\u76d1\u63a7\u201d<\/li>\n<\/ul>\n<h2 id=\"aws-license-manager\">AWS License Manager<\/h2>\n<h2 id=\"proton\">Proton<\/h2>\n<h2 id=\"aws-well-architected-tool\">AWS Well-Architected Tool<\/h2>\n<hr>\n<h1 id=\"financial-management\">Financial Management<\/h1>\n<h2 id=\"budgets\">Budgets<\/h2>\n<h2 id=\"cost-explorer\">Cost Explorer<\/h2>\n<h2 id=\"savings-plans\">Savings Plans<\/h2>"},{"title":"CORS","link":"https:\/\/canuxcheng.com\/post\/sec_cors\/","pubDate":"Wed, 28 Jul 2021 16:08:54 +0000","guid":"https:\/\/canuxcheng.com\/post\/sec_cors\/","description":"<h1 id=\"cors\">CORS<\/h1>\n<p>CORS: Cross-Origin resource sharing, \u8de8\u57df\u8d44\u6e90\u5171\u4eab.<\/p>\n<p>\u662f\u4e00\u79cd\u57fa\u4e8e HTTP \u5934\u7684\u673a\u5236\uff0c\u8be5\u673a\u5236\u901a\u8fc7\u5141\u8bb8\u670d\u52a1\u5668\u6807\u793a\u9664\u4e86\u5b83\u81ea\u5df1\u4ee5\u5916\u7684\u5176\u4ed6\u6e90\uff08\u57df\u3001\u534f\u8bae\u6216\u7aef\u53e3\uff09\uff0c\u4f7f\u5f97\u6d4f\u89c8\u5668\u5141\u8bb8\u8fd9\u4e9b\u6e90\u8bbf\u95ee\u52a0\u8f7d\u81ea\u5df1\u7684\u8d44\u6e90\u3002\u8de8\u6e90\u8d44\u6e90\u5171\u4eab\u8fd8\u901a\u8fc7\u4e00\u79cd\u673a\u5236\u6765\u68c0\u67e5\u670d\u52a1\u5668\u662f\u5426\u4f1a\u5141\u8bb8\u8981\u53d1\u9001\u7684\u771f\u5b9e\u8bf7\u6c42\uff0c\u8be5\u673a\u5236\u901a\u8fc7\u6d4f\u89c8\u5668\u53d1\u8d77\u4e00\u4e2a\u5230\u670d\u52a1\u5668\u6258\u7ba1\u7684\u8de8\u6e90\u8d44\u6e90\u7684\u201c\u9884\u68c0\u201d\u8bf7\u6c42\u3002\u5728\u9884\u68c0\u4e2d\uff0c\u6d4f\u89c8\u5668\u53d1\u9001\u7684\u5934\u4e2d\u6807\u793a\u6709 HTTP \u65b9\u6cd5\u548c\u771f\u5b9e\u8bf7\u6c42\u4e2d\u4f1a\u7528\u5230\u7684\u5934\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/developer.mozilla.org\/zh-CN\/docs\/Web\/HTTP\/CORS\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/developer.mozilla.org\/zh-CN\/docs\/Web\/HTTP\/CORS<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/developer.mozilla.org\/zh-CN\/docs\/Web\/HTTP\/Headers\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/developer.mozilla.org\/zh-CN\/docs\/Web\/HTTP\/Headers<\/a><\/p>\n<h2 id=\"same-origin-policy\">same-origin policy<\/h2>\n<p>\u540c\u6e90\u7b56\u7565\uff0c\u662f\u4e00\u79cd\u5173\u952e\u7684\u5b89\u5168\u673a\u5236\uff0c\u5b83\u9650\u5236\u7531\u4e00\u4e2a\u6e90\u52a0\u8f7d\u7684\u6587\u6863\u6216\u811a\u672c\u5982\u4f55\u4e0e\u6765\u81ea\u53e6\u4e00\u4e2a\u6e90\u7684\u8d44\u6e90\u8fdb\u884c\u4ea4\u4e92\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/Security\/Same-origin_policy\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/Security\/Same-origin_policy<\/a><\/p>\n<p>\u540c\u6e90\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>protocal (http, https, &hellip;&hellip;)<\/li>\n<li>host<\/li>\n<li>port(80, 443, &hellip;&hellip;)<\/li>\n<\/ul>\n<h2 id=\"\u7b80\u5355\u8bf7\u6c42\">\u7b80\u5355\u8bf7\u6c42<\/h2>\n<p><a class=\"link\" href=\"https:\/\/developer.mozilla.org\/zh-CN\/docs\/Web\/HTTP\/CORS#%E7%AE%80%E5%8D%95%E8%AF%B7%E6%B1%82\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/developer.mozilla.org\/zh-CN\/docs\/Web\/HTTP\/CORS#%E7%AE%80%E5%8D%95%E8%AF%B7%E6%B1%82<\/a><\/p>\n<ol>\n<li>\u8bf7\u6c42\u65b9\u6cd5\u662f\u4ee5\u4e0b\u4e09\u79cd\u65b9\u6cd5\u4e4b\u4e00\uff1a<\/li>\n<\/ol>\n<ul>\n<li>HEAD<\/li>\n<li>GET<\/li>\n<li>POST<\/li>\n<\/ul>\n<ol start=\"2\">\n<li>HTTP\u7684\u5934\u4fe1\u606f\u4e0d\u8d85\u51fa\u4ee5\u4e0b\u51e0\u79cd\u5b57\u6bb5\uff1a<\/li>\n<\/ol>\n<ul>\n<li>Accept<\/li>\n<li>Accept-Language<\/li>\n<li>Content-Language<\/li>\n<li>Last-Event-ID<\/li>\n<li>Content-Type\uff1aapplication\/x-www-form-urlencoded\u3001multipart\/form-data\u3001text\/plain.<\/li>\n<\/ul>\n<p>\u7b80\u5355\u8bf7\u6c42\u5728header\u6dfb\u52a0Origin\u5b57\u6bb5\u8bf4\u660e\u8bf7\u6c42\u7684\u6e90(\u534f\u8bae\uff0c\u57df\u540d\uff0c\u7aef\u53e3):<\/p>\n<pre><code>Origin: https:\/\/domain.com:port\n<\/code><\/pre>\n<h2 id=\"\u9884\u68c0\u8bf7\u6c42\">\u9884\u68c0\u8bf7\u6c42<\/h2>\n<p><a class=\"link\" href=\"https:\/\/developer.mozilla.org\/zh-CN\/docs\/Web\/HTTP\/CORS#%E9%A2%84%E6%A3%80%E8%AF%B7%E6%B1%82\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/developer.mozilla.org\/zh-CN\/docs\/Web\/HTTP\/CORS#%E9%A2%84%E6%A3%80%E8%AF%B7%E6%B1%82<\/a><\/p>\n<p>\u9488\u5bf9\u5176\u5b83\u65b9\u6cd5\u6216\u5b57\u6bb5\u7c7b\u578b.<\/p>\n<h2 id=\"http-headers\">http headers<\/h2>\n<p>\u54cd\u5e94header\u4e2d\u53ef\u4ee5\u5e26\u4ee5\u4e0b\u5b57\u6bb5\uff1a<\/p>\n<p>Access-Control-Allow-Origin<\/p>\n<p>Access-Control-Max-Age<\/p>\n<p>Access-Control-Allow-Credentials<\/p>\n<p>Access-Control-Allow-Methods<\/p>\n<p>Access-Control-Expose-Headers\nAccess-Control-Allow-Headers<\/p>\n<p>\u8bf7\u6c42header\u4e2d\u7684\u5b57\u6bb5\uff1a<\/p>\n<p>Origin<\/p>\n<p>Access-Control-Request-Method<\/p>\n<p>Access-Control-Request-Headers<\/p>\n<p><a class=\"link\" href=\"https:\/\/developer.mozilla.org\/zh-CN\/docs\/Web\/HTTP\/Headers\/Access-Control-Request-Headers\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/developer.mozilla.org\/zh-CN\/docs\/Web\/HTTP\/Headers\/Access-Control-Request-Headers<\/a><\/p>"},{"title":"Let's Encrypt","link":"https:\/\/canuxcheng.com\/post\/sec_letsencrypt\/","pubDate":"Wed, 28 Jul 2021 16:08:54 +0000","guid":"https:\/\/canuxcheng.com\/post\/sec_letsencrypt\/","description":"<h1 id=\"lets-encrypt\">Let&rsquo;s Encrypt<\/h1>\n<p><a class=\"link\" href=\"https:\/\/letsencrypt.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/letsencrypt.org\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/letsencrypt\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/letsencrypt<\/a><\/p>\n<p>\u662f\u975e\u76c8\u5229\u7ec4\u7ec7ISRG\u63d0\u4f9b\u7684\u514d\u8d39\u7684\u8bc1\u4e66\u9881\u53d1\u673a\u6784\u3002<\/p>\n<p>let&rsquo;s encrypt\u751f\u6210\u8bc1\u4e66\u7684\u5de5\u5177\u5f88\u591acertbot, acme.sh\u7b49.<\/p>\n<h1 id=\"certbot\">certbot<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/certbot\/certbot\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/certbot\/certbot<\/a><\/p>\n<h1 id=\"acmesh\">acme.sh<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/acmesh-official\/acme.sh\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/acmesh-official\/acme.sh<\/a><\/p>"},{"title":"BSP","link":"https:\/\/canuxcheng.com\/post\/hardware_bsp\/","pubDate":"Sat, 15 May 2021 09:41:39 +0800","guid":"https:\/\/canuxcheng.com\/post\/hardware_bsp\/","description":"<h1 id=\"bsp\">BSP<\/h1>\n<p>BSP\uff0cBoard Support Package\uff0c\u677f\u7ea7\u652f\u6301\u5305.<\/p>\n<p>\u719f\u6089\u5e38\u89c1\u7684\u63a5\u53e3\u534f\u8bae\uff0c\u5982I2C, SPI, UART, USB\u7b49\u3002<\/p>"},{"title":"FPGA","link":"https:\/\/canuxcheng.com\/post\/hardware_fpga\/","pubDate":"Sat, 15 May 2021 09:41:39 +0800","guid":"https:\/\/canuxcheng.com\/post\/hardware_fpga\/","description":"<h1 id=\"fpga\">FPGA<\/h1>\n<p>FPGA: Field Programmable Gate Array, \u73b0\u573a\u53ef\u7f16\u7a0b\u903b\u8f91\u95e8\u9635\u5217.<\/p>\n<p>\u4e0b\u9762\u4ecb\u7ecd\u5404\u5bb6\u5382\u5546\u548c\u5bf9\u5e94\u7684\u4ea7\u54c1\u7cfb\u5217.<\/p>\n<hr>\n<h1 id=\"xilinx\u8d5b\u7075\u601d\">xilinx\/\u8d5b\u7075\u601d<\/h1>\n<p>Spartan<\/p>\n<p>Artix<\/p>\n<p>Kintex<\/p>\n<p>Virtex<\/p>\n<p>SoC\/MPSoC<\/p>\n<hr>\n<h1 id=\"altera\u963f\u5c14\u7279\u62c9\">Altera\/\u963f\u5c14\u7279\u62c9<\/h1>\n<p>\u88abIntel\u82f1\u7279\u5c14\u6536\u8d2d<\/p>\n<p>MAXII<\/p>\n<p>Cyclone<\/p>\n<p>Stratix<\/p>\n<p>Arria<\/p>\n<hr>\n<h1 id=\"lattice\u83b1\u8fea\u601d\">Lattice\/\u83b1\u8fea\u601d<\/h1>\n<p>ECP<\/p>\n<p>ICE<\/p>\n<p>Mach<\/p>\n<hr>\n<h1 id=\"synplicity\">Synplicity<\/h1>\n<p>\u88abSynopsys\u65b0\u601d\u79d1\u6280\u6536\u8d2d<\/p>\n<h2 id=\"haps\">HAPS<\/h2>\n<p>HAPS\u7cfb\u5217\u4ea7\u54c1\u662f\u4e13\u4e3aASIC\/SOC\u8bbe\u8ba1\u8005\u63d0\u4f9b\u7684\u9ad8\u6027\u80fd\u3001\u9ad8\u5bb9\u91cf\u7684\u57fa\u4e8eFPGA\u7684\u539f\u578b\u9a8c\u8bc1\u677f.<\/p>"},{"title":"Hardware","link":"https:\/\/canuxcheng.com\/post\/hardware\/","pubDate":"Sat, 15 May 2021 09:41:39 +0800","guid":"https:\/\/canuxcheng.com\/post\/hardware\/","description":"<h1 id=\"hardware\">Hardware<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/micropython\/micropython\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/micropython\/micropython<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/tinygo-org\/tinygo\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/tinygo-org\/tinygo<\/a><\/p>\n<h1 id=\"soc\">SoC<\/h1>\n<p>SOC\uff1a\uff08System-On-Chip)\u7247\u4e0a\u7cfb\u7edf\u3002\u53ef\u4ee5\u7b80\u5355\u7684\u7406\u89e3\u4e3a\u628a\u7cfb\u7edf\u505a\u5728\u4e00\u5757\u82af\u7247\u4e0a\u3002<\/p>\n<p>AP: application processor, CPU, GPU, NPU, ISP, DSP, ROM\/RAM.<\/p>\n<p>BP: base-band processor, BBU.<\/p>\n<p><img src=\"https:\/\/canuxcheng.com\/images\/chip.png\"\nloading=\"lazy\"\nalt=\"pic\"\n><\/p>\n<p><img src=\"https:\/\/canuxcheng.com\/images\/ISP.png\"\nloading=\"lazy\"\nalt=\"pic\"\n><\/p>\n<p>EUV: Extreme Ultraviolet Lithography\uff0c\u6781\u7d2b\u5916\u5149\u523b<\/p>\n<p>DSP: Digital Signal Processing.<\/p>\n<p>ISP: image signal process.<\/p>\n<p>\u5382\u5546\uff1a\u7d2b\u5149\u5c55\u9510\uff0c\u534e\u4e3a\u6d77\u601d\uff0c\u5168\u5fd7\u79d1\u6280\uff0c\u745e\u82af\u5fae\u3002<\/p>\n<h1 id=\"rfic\">RFIC<\/h1>\n<p>\u5c04\u9891\u82af\u7247<\/p>"},{"title":"KubeVirt","link":"https:\/\/canuxcheng.com\/post\/k8s_kubevirt\/","pubDate":"Mon, 10 May 2021 20:55:52 +0800","guid":"https:\/\/canuxcheng.com\/post\/k8s_kubevirt\/","description":"<h1 id=\"kubevirt\">KubeVirt<\/h1>\n<p><a class=\"link\" href=\"https:\/\/kubevirt.io\/quickstart_cloud\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kubevirt.io\/quickstart_cloud\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/quay.io\/organization\/kubevirt\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/quay.io\/organization\/kubevirt<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/docs.fedoraproject.org\/en-US\/quick-docs\/using-nested-virtualization-in-kvm\/index.html\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.fedoraproject.org\/en-US\/quick-docs\/using-nested-virtualization-in-kvm\/index.html<\/a><\/p>\n<h2 id=\"virtctl\">virtctl<\/h2>\n<h2 id=\"vm\">VM<\/h2>\n<p>\u521b\u5efavm<\/p>\n<pre><code>apiVersion: kubevirt.io\/v1\nkind: VirtualMachine\nmetadata:\nname: testvm\nspec:\nrunning: false\ntemplate:\nmetadata:\nlabels:\nkubevirt.io\/size: small\nkubevirt.io\/domain: testvm\nspec:\ndomain:\ndevices:\ndisks:\n- name: containerdisk\ndisk:\nbus: virtio\n- name: cloudinitdisk\ndisk:\nbus: virtio\ninterfaces:\n- name: default\nmasquerade: {}\nresources:\nrequests:\nmemory: 64M\nnetworks:\n- name: default\npod: {}\nvolumes:\n- name: containerdisk\ncontainerDisk:\nimage: quay.io\/kubevirt\/cirros-container-disk-demo\n- name: cloudinitdisk\ncloudInitNoCloud:\nuserDataBase64: SGkuXG4=\nnodeSelector:\nkubernetes.io\/arch: arm64\n<\/code><\/pre>"},{"title":"Cache","link":"https:\/\/canuxcheng.com\/post\/django_cache\/","pubDate":"Tue, 04 May 2021 04:51:30 +0000","guid":"https:\/\/canuxcheng.com\/post\/django_cache\/","description":"<h1 id=\"cache\">cache<\/h1>\n<p>\u7f13\u5b58\u7684backend\u53ef\u4ee5\u662fdjango\u5185\u7f6e\u7684\uff0c\u4e5f\u53ef\u4ee5\u662f\u7b2c\u4e09\u65b9\u7684\u3002<\/p>\n<ul>\n<li>\n<p>\u7f13\u5b58\u6574\u4e2a\u7ad9\u70b9<\/p>\n<p>MIDDLEWARE = [\n&lsquo;django.middleware.cache.UpdateCacheMiddleware&rsquo;,\n&lsquo;django.middleware.common.CommonMiddleware&rsquo;,\n&lsquo;django.middleware.cache.FetchFromCacheMiddleware&rsquo;,\n]<\/p>\n<\/li>\n<li>\n<p>\u89c6\u56fe\u7f13\u5b58<\/p>\n<p>from django.views.decorators.cache import cache_page<\/p>\n<p>@cache_page(60 * 2)\ndef my_view(request):\n&hellip;<\/p>\n<p>\u6216\u8005\u5728URLconf\u4e2d\u6307\u5b9a\nurlpatterns = [\npath(&lsquo;foo\/<a class=\"link\" href=\"int:code\" >int:code<\/a>\/&rsquo;, cache_page(60 * 2)(my_view)),\n]<\/p>\n<\/li>\n<li>\n<p>\u6a21\u677f\u7247\u6bb5\u7f13\u5b58<\/p>\n<p>{% load cache %}\n{% cache &hellip; %}\n&hellip;\n{% endcache %}<\/p>\n<\/li>\n<\/ul>\n<hr>\n<h2 id=\"redis\">redis<\/h2>\n<pre><code>CACHES = {\n&quot;default&quot;: {\n&quot;BACKEND&quot;: &quot;django_redis.cache.RedisCache&quot;,\n&quot;LOCATION&quot;: os.environ.get(&quot;REDIS_URL&quot;, ''),\n&quot;OPTIONS&quot;: {\n&quot;CLIENT_CLASS&quot;: &quot;django_redis.client.DefaultClient&quot;,\n},\n&quot;TIMEOUT&quot;: 60,\n}\n}\n<\/code><\/pre>\n<h2 id=\"memcached\">memcached<\/h2>\n<pre><code>CACHES = {\n'default': {\n'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',\n'LOCATION': '127.0.0.1:11211',\n}\n}\n<\/code><\/pre>\n<h2 id=\"database\">database<\/h2>\n<pre><code>CACHES = {\n'default': {\n'BACKEND': 'django.core.cache.backends.db.DatabaseCache',\n'LOCATION': 'my_cache_table',\n}\n}\n<\/code><\/pre>"},{"title":"AWS","link":"https:\/\/canuxcheng.com\/post\/aws\/","pubDate":"Fri, 23 Apr 2021 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/aws\/","description":"<h1 id=\"aws\">AWS<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/donnemartin\/awesome-aws\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/donnemartin\/awesome-aws<\/a><\/p>\n<p>aws certification:<\/p>\n<ul>\n<li>Foundational: 6\u4e2a\u6708\u7ecf\u9a8c. Cloud Practitioner Foundational(CLF).<\/li>\n<li>Associate: \u4e00\u5e74\u7ecf\u9a8c. Solutions Architect Associate(SAA); Developer, SysOps Administrator<\/li>\n<li>Professional: \u4e24\u5e74\u7ecf\u9a8c. Solutions Architect Professional(SAP), Devops Engineer.<\/li>\n<li>Specialty: \u7279\u6b8a\u9886\u57df.<\/li>\n<\/ul>\n<hr>\n<h2 id=\"sdk\">SDK<\/h2>\n<p>python<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/boto\/boto3\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/boto\/boto3<\/a><\/p>\n<p>golang<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/aws\/aws-sdk-go\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/aws\/aws-sdk-go<\/a><\/p>\n<hr>\n<h2 id=\"aws-management-console\">AWS Management Console<\/h2>\n<p>\u901a\u8fc7webUI\u7ba1\u7406\u8d44\u6e90.\nkkkkjjkijijijkkjddkkkkjj<\/p>\n<hr>\n<h2 id=\"aws-command-line-interface\">AWS Command Line Interface<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/aws\/aws-cli\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/aws\/aws-cli<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/awslabs\/aws-shell\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/awslabs\/aws-shell<\/a><\/p>\n<p>\u63a8\u8350\u4f7f\u7528awscli-V2:<\/p>\n<p><a class=\"link\" href=\"https:\/\/docs.aws.amazon.com\/cli\/latest\/userguide\/install-cliv2.html\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.aws.amazon.com\/cli\/latest\/userguide\/install-cliv2.html<\/a><\/p>\n<p>\u4f7f\u7528:<\/p>\n<pre><code>aws [-h] [--profile PROFILE] [--debug]\n<\/code><\/pre>\n<p>option:<\/p>\n<pre><code>-h, --help\n--profile PROFILE\n--debug\n<\/code><\/pre>\n<p>comand option:<\/p>\n<pre><code>aws &lt;service&gt; &lt;subcommand&gt; help\n<\/code><\/pre>\n<h3 id=\"cli-credentials\">CLI credentials<\/h3>\n<p>\u4f18\u5148\u7ea7\uff1a<\/p>\n<ol>\n<li>\u547d\u4ee4\u884c\u9009\u9879<\/li>\n<li>credentials\u6587\u4ef6<\/li>\n<li>config\u6587\u4ef6<\/li>\n<li>\u5bb9\u5668\u51ed\u8bc1<\/li>\n<li>\u5b9e\u4f8b\u914d\u7f6e\u6587\u4ef6\u51ed\u8bc1<\/li>\n<\/ol>\n<ul>\n<li>CLI<\/li>\n<\/ul>\n<p>\u914d\u7f6edefault profile<\/p>\n<pre><code>$aws configure\nAWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE\nAWS Secret Access Key [None]: wJalrXUtnFEMI\/K7MDENG\/bPxRfiCYEXAMPLEKEY\nDefault region name [None]: us-west-2\nDefault output format [None]: json\/yaml\/text\/table\/yaml-stream\n\/\/ \u914d\u7f6e\u6307\u5b9a\u7528\u6237\n$aws configure --profile canux\n\/\/ \u67e5\u770b\u914d\u7f6e\n$aws configure list\n$aws configure --profile canux list\n<\/code><\/pre>\n<p>\u547d\u4ee4\u884c\u9009\u9879\u6307\u5b9a\u914d\u7f6e\u6587\u4ef6<\/p>\n<pre><code>$aws --profile canux ...\n<\/code><\/pre>\n<p>\u73af\u5883\u53d8\u91cf\u6307\u5b9a\u914d\u7f6e\u6587\u4ef6<\/p>\n<pre><code>export AWS_PROFILE=canux\nexport AWS_DEFAULT_PROFILE=canux\n<\/code><\/pre>\n<ul>\n<li>Shared credentials file<\/li>\n<\/ul>\n<p>\u6587\u4ef6\u914d\u7f6e<\/p>\n<pre><code>\/\/ windows\n%USERPROFILE%\\.aws\\credentials\n\/\/ linux\n~\/.aws\/credentials\n\/\/ \u9ed8\u8ba4\u8d26\u53f7\u914d\u7f6e\n[default]\naws_access_key_id=AKIAIOSFODNN7EXAMPLE\naws_secret_access_key=wJalrXUtnFEMI\/K7MDENG\/bPxRfiCYEXAMPLEKEY\n\/\/ \u6307\u5b9a\u7528\u6237\u914d\u7f6e\n[canux]\naws_access_key_id=AKIAI44QH8DHBEXAMPLE\naws_secret_access_key=je7MtGbClwBF\/2Zp9Utk\/h3yCo8nvbEXAMPLEKEY\n<\/code><\/pre>\n<p>\u901a\u8fc7\u73af\u5883\u53d8\u91cf\u914d\u7f6e<\/p>\n<pre><code>export AWS_ACCESS_KEY_ID=&quot;id&quot;\nexport AWS_SECRET_ACCESS_KEY=&quot;key&quot;\nexport AWS_SESSION_TOKEN=&quot;token&quot;\n<\/code><\/pre>\n<ul>\n<li>Config file<\/li>\n<\/ul>\n<p>\u914d\u7f6e\u6587\u4ef6<\/p>\n<pre><code>\/\/ linux\n~\/.aws\/config\n[default]\nregion = eu-west-1\noutput = yaml\n[profile pro]\nsso_start_url = https:\/\/lz.awsapps.com\/start\nsso_region = eu-west-1\nsso_role_name = ProjAdmins\nsso_account_id = 123404000510\nregion = us-west-2\noutput = json\n\/\/ windows\n%USERPROFILE%\\.aws\\config\n<\/code><\/pre>\n<ul>\n<li>IAM role<\/li>\n<\/ul>\n<p>how to check:<\/p>\n<pre><code>$aws sts get-caller-identity --profile pro\n<\/code><\/pre>\n<h3 id=\"services\">services<\/h3>\n<pre><code>iam\nec2\nsts\neks\naws eks describe-addon-versions --addon-name aws-ebs-csi-driver\n<\/code><\/pre>\n<hr>"},{"title":"AWS Compute Services","link":"https:\/\/canuxcheng.com\/post\/aws_cs\/","pubDate":"Fri, 23 Apr 2021 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/aws_cs\/","description":"<h1 id=\"aws-compute-service\">AWS Compute Service<\/h1>\n<h2 id=\"ec2\">EC2<\/h2>\n<p>Elastic Compute.<\/p>\n<p>AMI: Amazon Machine Image.<\/p>\n<p>EC2\u5b9e\u4f8b\u7c7b\u578b:<\/p>\n<ul>\n<li>\u901a\u7528\u578b\u5b9e\u4f8b<\/li>\n<li>\u8ba1\u7b97\u4f18\u5316\u578b\u5b9e\u4f8b<\/li>\n<li>\u5185\u5b58\u4f18\u5316\u578b\u5b9e\u4f8b<\/li>\n<li>\u52a0\u901f\u8ba1\u7b97\u578b\u5b9e\u4f8b<\/li>\n<li>\u5b58\u50a8\u4f18\u5316\u578b\u5b9e\u4f8b<\/li>\n<\/ul>\n<p>EC2\u4ed8\u8d39\u7c7b\u578b:<\/p>\n<ul>\n<li>\u6309\u9700(on-demand)<\/li>\n<li>\u9884\u7559\u5b9e\u4f8b(reserved)<\/li>\n<li>\u50a8\u84c4\u8ba1\u5212(savings plans)<\/li>\n<li>Spot\u5b9e\u4f8b<\/li>\n<li>\u4e13\u7528\u4e3b\u673a(dedicated)<\/li>\n<\/ul>\n<h2 id=\"elastic-beanstalk\">Elastic Beanstalk<\/h2>\n<p>features:<\/p>\n<ul>\n<li>monitoring<\/li>\n<li>deployment<\/li>\n<li>scaling<\/li>\n<li>EC2 customization<\/li>\n<\/ul>\n<h2 id=\"lambda\">Lambda<\/h2>\n<h2 id=\"lightsail\">Lightsail<\/h2>\n<h2 id=\"batch\">Batch<\/h2>\n<h2 id=\"app-runner\">App Runner<\/h2>\n<h2 id=\"auto-scaling\">Auto Scaling<\/h2>\n<h2 id=\"fargate\">Fargate<\/h2>\n<h2 id=\"outposts\">Outposts<\/h2>\n<h2 id=\"wavelength\">Wavelength<\/h2>\n<hr>\n<h1 id=\"app-integration\">App Integration<\/h1>\n<h2 id=\"appflow\">AppFlow<\/h2>\n<h2 id=\"appsync\">AppSync<\/h2>\n<h2 id=\"eventbridge\">EventBridge<\/h2>\n<h2 id=\"step-functions\">Step Functions<\/h2>\n<p>\u65e0\u670d\u52a1\u67b6\u6784.<\/p>\n<h2 id=\"sns\">SNS<\/h2>\n<p>Simple Notification Service\u662f\u6d88\u606f\u53d1\u5e03\u8ba2\u9605\u670d\u52a1.<\/p>\n<h2 id=\"sqs\">SQS<\/h2>\n<p>Simple Queue Service\u662f\u6d88\u606f\u961f\u5217\u670d\u52a1.<\/p>\n<p>\u652f\u6301256KB\u7684payload.<\/p>\n<p>\u63d0\u4f9b\u4e24\u79cd\u7c7b\u578b\u7684queues:<\/p>\n<ul>\n<li>standard queue<\/li>\n<li>FIFO queue<\/li>\n<\/ul>\n<h2 id=\"mq\">MQ<\/h2>\n<p>activeMQ \u548c rabbitmq \u6258\u7ba1\u670d\u52a1\u3002<\/p>\n<hr>\n<h1 id=\"business-app-integration\">Business app integration<\/h1>\n<h2 id=\"simple-email-service\">Simple Email Service<\/h2>\n<p>SES<\/p>\n<h2 id=\"alexa-for-business\">Alexa for Business<\/h2>\n<hr>\n<h1 id=\"\u7ec8\u7aef\u7528\u6237\u8ba1\u7b97\">\u7ec8\u7aef\u7528\u6237\u8ba1\u7b97<\/h1>\n<h2 id=\"appstream\">AppStream<\/h2>\n<h2 id=\"workspaces\">WorkSpaces<\/h2>"},{"title":"AWS Containers","link":"https:\/\/canuxcheng.com\/post\/aws_containers\/","pubDate":"Fri, 23 Apr 2021 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/aws_containers\/","description":"<h1 id=\"aws-containers\">AWS Containers<\/h1>\n<h2 id=\"ecr\">ECR<\/h2>\n<p>Elastic Container Registry.<\/p>\n<h2 id=\"ecs-anywhere\">ECS Anywhere<\/h2>\n<h2 id=\"ecs\">ECS<\/h2>\n<p>Elastic Container Service.<\/p>\n<h2 id=\"eks-distro\">EKS Distro<\/h2>\n<h2 id=\"eks-anywhere\">EKS Anywhere<\/h2>\n<h2 id=\"eks\">EKS<\/h2>\n<p>Elastic Kubernetes Service.<\/p>\n<h3 id=\"\u901a\u8fc7aws-cli\u521b\u5efaeks\">\u901a\u8fc7AWS CLI\u521b\u5efaEKS<\/h3>\n<p>\u901a\u8fc7MC\u521b\u5efa\u7684\u8d44\u6e90\u90fd\u53ef\u4ee5\u901a\u8fc7CLI(aws)\u521b\u5efa.<\/p>\n<p>\u521b\u5efa\u5177\u6709\u516c\u6709\u548c\u79c1\u6709\u5b50\u7f51\u4e14\u7b26\u5408 Amazon EKS \u8981\u6c42\u7684 Amazon VPC<\/p>\n<pre><code>$ aws cloudformation create-stack \\\n--stack-name my-eks-vpc-stack \\\n--region region-code \\\n--template-url https:\/\/amazon-eks.s3.us-west-2.amazonaws.com\/cloudformation\/2020-10-29\/amazon-eks-vpc-private-subnets.yaml\n<\/code><\/pre>\n<p>\u521b\u5efa\u96c6\u7fa4 IAM \u89d2\u8272\u5e76\u5411\u5176\u9644\u52a0\u6240\u9700\u7684 Amazon EKS IAM \u6258\u7ba1\u7b56\u7565<\/p>\n<pre><code>\/\/ \u521b\u5efaEKS IAM role\naws iam create-role \\\n--role-name my-EKSClusterRole \\\n--assume-role-policy-document file:\/\/cluster-role-trust-policy.json&quot; \\\n--permissions-boundary arn:aws:iam::&lt;Your AWS ID&gt;:policy\/ProjAdminsPermBoundaryv2\n{\n&quot;Version&quot;: &quot;2012-10-17&quot;,\n&quot;Statement&quot;: [\n{\n&quot;Effect&quot;: &quot;Allow&quot;,\n&quot;Principal&quot;: {\n&quot;Service&quot;: &quot;eks.amazonaws.com&quot;\n},\n&quot;Action&quot;: &quot;sts:AssumeRole&quot;,\n&quot;Condition&quot;: {}\n}\n]\n}\n\/\/ \u7ed1\u5b9arole\u548ceks\u7b56\u7565\naws iam attach-role-policy \\\n--policy-arn arn:aws:iam::aws:policy\/AmazonEKSClusterPolicy \\\n--role-name my-EKSClusterRole\n<\/code><\/pre>\n<p>\u521b\u5efaEKS cluster:<\/p>\n<pre><code>aws eks create-cluster --name my-cluster \\\n--role-arn arn:aws:iam::&lt;ID&gt;:role\/my-EKSClusterRole \\\n--resources-vpc-config vpc.json \/ --resources-vpc-config subnetIds=subnet-6782e71e,subnet-e7e761ac,securityGroupIds=sg-6979fe18 \\\n--kubernetes-network-config eks.json \/ --kubernetes-network-config serviceIpv4Cidr=string,ipFamily=string \\\n--kubernetes-version &lt;version&gt; --tags &lt;tags&gt; --logging &lt;logging&gt;\n<\/code><\/pre>\n<p>\u7ed9\u96c6\u7fa4\u521b\u5efa\u8282\u70b9<\/p>\n<pre><code>\/\/ \u521b\u5efa\u8282\u70b9IAM role\naws iam create-role \\\n--role-name my-EKSNodeRole \\\n--assume-role-policy-document file:\/\/node-role-trust-policy.json&quot; \\\n--permissions-boundary arn:aws:iam::&lt;ID&gt;:policy\/ProjAdminsPermBoundaryv2\n{\n&quot;Version&quot;: &quot;2012-10-17&quot;,\n&quot;Statement&quot;: [\n{\n&quot;Effect&quot;: &quot;Allow&quot;,\n&quot;Principal&quot;: {\n&quot;Service&quot;: &quot;ec2.amazonaws.com&quot;\n},\n&quot;Action&quot;: &quot;sts:AssumeRole&quot;,\n&quot;Condition&quot;: {}\n}\n]\n}\n\/\/ \u7ed1\u5b9arole\u548cnode\u7b56\u7565\naws iam attach-role-policy \\\n--policy-arn arn:aws:iam::aws:policy\/AmazonEKSWorkerNodePolicy \\\n--role-name my-EKSNodeRole\naws iam attach-role-policy \\\n--policy-arn arn:aws:iam::aws:policy\/AmazonEC2ContainerRegistryReadOnly \\\n--role-name my-EKSNodeRole\naws iam attach-role-policy \\\n--policy-arn arn:aws:iam::aws:policy\/AmazonEKS_CNI_Policy \\\n--role-name my-EKSNodeRole\n<\/code><\/pre>\n<p>\u521b\u5efamanaged node group:<\/p>\n<pre><code>aws eks create-nodegroup \\\n--cluster-name my-cluster --nodegroup-name my-mng --subnets &lt;value&gt; --node-role &lt;value&gt; \\\n--scaling-config minSize=integer,maxSize=integer,desiredSize=integer \\\n--instance-types &lt;value&gt; --ami-type &lt;value&gt; --remote-access &lt;value&gt; --disk-size &lt;value&gt;\n<\/code><\/pre>\n<p>\u5c06\u8ba1\u7b97\u673a\u914d\u7f6e\u4e3a\u4e0e\u60a8\u7684\u96c6\u7fa4\u901a\u4fe1<\/p>\n<pre><code>aws eks describe-cluster --name my-cluster\n\/\/ \u901a\u8fc7aws eks\u81ea\u52a8\u66f4\u65b0kube.config\u6587\u4ef6.\n\/\/ \u9700\u8981\u8be5role\u5177\u6709\u53ef\u4ee5\u64cd\u4f5ceks cluster\u7684policy.\n$ aws eks update-kubeconfig --name my-cluster --role-arn &lt;role&gt; --region eu-west-1 --verbose\n$ kubectl get svc\n<\/code><\/pre>\n<p>\u5220\u9664\u96c6\u7fa4\u548c\u8282\u70b9:<\/p>\n<pre><code>aws eks delete-nodegroup --nodegroup-name my-mng --cluster-name my-cluster\naws eks delete-cluster --name my-cluster\naws cloudformation delete-stack --stack-name my-stack\n<\/code><\/pre>\n<h3 id=\"\u901a\u8fc7eksctl\u521b\u5efaeks\">\u901a\u8fc7eksctl\u521b\u5efaEKS<\/h3>\n<p><a class=\"link\" href=\"https:\/\/github.com\/weaveworks\/eksctl\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/weaveworks\/eksctl<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/eksctl.io\/usage\/schema\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/eksctl.io\/usage\/schema\/<\/a><\/p>\n<p>\u521b\u5efa\u96c6\u7fa4\u548c\u8282\u70b9\uff1a<\/p>\n<pre><code>$ eksctl create cluster -f\/--config-file .\/cluster.yaml\n$ eksctl create nodegroup -f\/--config-file .\/nodegroup.yaml\n<\/code><\/pre>\n<p>\u5220\u9664\u96c6\u7fa4\u548c\u8282\u70b9<\/p>\n<pre><code>$ eksctl delete cluster --name my-cluster --region us-west-2\n$ eksctl delete nodegroup --cluster my-cluster --region us-west-2 --name my-ng\n<\/code><\/pre>\n<h3 id=\"\u901a\u8fc7terraform\u521b\u5efaeks\">\u901a\u8fc7Terraform\u521b\u5efaEKS<\/h3>"},{"title":"AWS Data","link":"https:\/\/canuxcheng.com\/post\/aws_data\/","pubDate":"Fri, 23 Apr 2021 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/aws_data\/","description":"<h1 id=\"data-processing\">Data Processing<\/h1>\n<h2 id=\"athena\">Athena<\/h2>\n<p>serverless\u4ea4\u4e92\u5f0f\u5206\u6790<\/p>\n<h2 id=\"data-exchange\">Data Exchange<\/h2>\n<h2 id=\"glue\">Glue<\/h2>\n<p>AWS\u4e0a\u7684ETL(extract, transform and load)\u670d\u52a1\uff0c\u63d0\u4f9b\u6570\u636e\u7684\u63d0\u53d6\uff0c\u8f6c\u6362\uff0c\u52a0\u8f7d\u670d\u52a1\u3002<\/p>\n<h2 id=\"data-pipeline\">Data pipeline<\/h2>\n<p>\u4e5f\u662fETL\u670d\u52a1\u3002<\/p>\n<h2 id=\"emr\">EMR<\/h2>\n<p>EMR: Elastic MapReduce.<\/p>\n<p>AWS\u7684\u5927\u6570\u636e\u5e73\u53f0\u3002\u652f\u6301spark, hive, hbase, flink, hudi \u548cpresto.<\/p>\n<h2 id=\"kinesis\">Kinesis<\/h2>\n<ul>\n<li>Data Analytics<\/li>\n<li>Data Firehose<\/li>\n<li>Data Streams<\/li>\n<\/ul>\n<h2 id=\"lake-formation\">Lake Formation<\/h2>\n<h2 id=\"quicksight\">QuickSight<\/h2>\n<h2 id=\"opensearch\">OpenSearch<\/h2>\n<h2 id=\"msk\">MSK<\/h2>\n<hr>\n<h1 id=\"data-analysis\">Data Analysis<\/h1>\n<h2 id=\"athena-1\">Athena<\/h2>\n<p>serverless\u670d\u52a1<\/p>\n<h2 id=\"quicksight-1\">Quicksight<\/h2>\n<h2 id=\"aws-cloudsearch\">AWS CloudSearch<\/h2>\n<hr>"},{"title":"AWS Database","link":"https:\/\/canuxcheng.com\/post\/aws_database\/","pubDate":"Fri, 23 Apr 2021 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/aws_database\/","description":"<h1 id=\"aws-database\">AWS Database<\/h1>\n<h2 id=\"rds\">RDS<\/h2>\n<p>Relational Database Service\uff0c \u5173\u7cfb\u578b\u6570\u636e\u5e93\u670d\u52a1.<\/p>\n<p>\u652f\u6301\u7684\u6570\u636e\u5e93\u5f15\u64ce\uff1a<\/p>\n<ul>\n<li>Amazon Aurora<\/li>\n<li>PostgreSQL<\/li>\n<li>MySQL<\/li>\n<li>MariaDB<\/li>\n<li>Oracle Database<\/li>\n<li>Microsoft SQL Server<\/li>\n<\/ul>\n<h2 id=\"aurora-serverless\">Aurora Serverless<\/h2>\n<h2 id=\"aurora\">Aurora<\/h2>\n<p>\u517c\u5bb9mysql\u548cpostgresql.<\/p>\n<h2 id=\"dynamodb\">DynamoDB<\/h2>\n<p>\u975e\u5173\u7cfb\u6570\u636e\u5e93(NoSQL).<\/p>\n<p>DynamoDB\u662f\u4e00\u9879\u952e\u503c\u6570\u636e\u5e93\u670d\u52a1. \u65e0\u670d\u52a1\u5668\uff0c\u81ea\u52a8\u6269\u5c55\u3002<\/p>\n<p>\u5177\u6709Key-Value\u6570\u636e\u5e93\u548cDocument\u6570\u636e\u5e93\u7684\u529f\u80fd\u3002<\/p>\n<h2 id=\"documentdb\">DocumentDB<\/h2>\n<p>\u517c\u5bb9MongoDB.<\/p>\n<h2 id=\"elasticcache\">ElasticCache<\/h2>\n<p>\u5185\u5b58\u6570\u636e\u5e93(in-memory). \u517c\u5bb9redis\u548cmemcached.<\/p>\n<h2 id=\"keyspaces\">Keyspaces<\/h2>\n<p>\u517c\u5bb9cassandra\u7684\u65e0\u670d\u52a1\u5668\u6570\u636e\u5e93\u3002<\/p>\n<h2 id=\"redshift\">Redshift<\/h2>\n<p>Amazon Redshift \u662f\u4e00\u9879\u6570\u636e\u4ed3\u5e93\u670d\u52a1\uff0c\u53ef\u7528\u4e8e\u8fdb\u884c\u5927\u6570\u636e\u5206\u6790\u3002<\/p>\n<h2 id=\"neptune\">Neptune<\/h2>\n<p>\u56fe\u5f62\u6570\u636e\u5e93<\/p>\n<h2 id=\"timesteam\">Timesteam<\/h2>"},{"title":"AWS Network","link":"https:\/\/canuxcheng.com\/post\/aws_network\/","pubDate":"Fri, 23 Apr 2021 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/aws_network\/","description":"<h1 id=\"aws-network\">AWS Network<\/h1>\n<h2 id=\"vpc\">VPC<\/h2>\n<p>Virtual Private Cloud.<\/p>\n<p>EC2\u7684\u79c1\u6709\u5185\u90e8\u7f51\u7edc.<\/p>\n<ul>\n<li>subnets<\/li>\n<li>route tables<\/li>\n<li>internet gateways<\/li>\n<li>nat gateways<\/li>\n<\/ul>\n<p>ENI: Elastic network interfaces.<\/p>\n<p><a class=\"link\" href=\"https:\/\/canuxcheng.com\/images\/vpc.png\" >pic<\/a><\/p>\n<h2 id=\"elb\">ELB<\/h2>\n<p>ELB: Elastic Load Balancing<\/p>\n<p>\u5f39\u6027\u8d1f\u8f7d\u5747\u8861\uff0c\u53ef\u4ee5\u548cEC2,ECS\u548clambda\u96c6\u6210.<\/p>\n<p><a class=\"link\" href=\"https:\/\/aws.amazon.com\/cn\/elasticloadbalancing\/features\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/aws.amazon.com\/cn\/elasticloadbalancing\/features\/<\/a><\/p>\n<p>\u652f\u6301\u56db\u79cd\u8d1f\u8f7d\u5747\u8861\u5668\uff1a<\/p>\n<ul>\n<li>Classic Load Balancer(\u9ed8\u8ba4)<\/li>\n<li>Gateway Load Balancer<\/li>\n<li>Application Load Balancer(ALB)<\/li>\n<li>Network Load Balancer(NLB)<\/li>\n<\/ul>\n<p><a class=\"link\" href=\"https:\/\/docs.aws.amazon.com\/zh_cn\/eks\/latest\/userguide\/aws-load-balancer-controller.html\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.aws.amazon.com\/zh_cn\/eks\/latest\/userguide\/aws-load-balancer-controller.html<\/a><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528aws\u9ed8\u8ba4\u81ea\u5e26\u7684NLB controller.\u4e5f\u53ef\u4ee5\u901a\u8fc7\u5b89\u88c5aws-load-balancer-controller\u3002\u63a8\u8350\u540e\u8005\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes-sigs\/aws-load-balancer-controller\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes-sigs\/aws-load-balancer-controller<\/a><\/p>\n<p>\u9700\u8981\u7ed9vpc\u4e0a\u7684node\u7684subnet\u6253tag:<\/p>\n<pre><code>kubernetes.io\/role\/elb: 1\nkubernetes.io\/role\/internal-elb: 1\nkubernetes.io\/cluster\/${cluster-name}: owned\/shared\n<\/code><\/pre>\n<h2 id=\"route-53\">Route 53<\/h2>\n<p>DNS\u670d\u52a1.<\/p>\n<p>\u5728route 53\u521b\u5efa\u6258\u7ba1\u533a(hosted zones)\u4e4b\u540e\uff0c\u53ef\u4ee5\u5728ACM\u7533\u8bf7\u8bc1\u4e66\u3002<\/p>\n<p>\u7533\u8bf7\u597d\u4e86\u8bc1\u4e66\uff0c\u9700\u8981\u5728route 53\u521b\u5efa\u8bb0\u5f55.<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7external-DNS \u81ea\u52a8\u540c\u6b65eks\u4e0a\u7684service\u548cingress\u5230dns\u3002<\/p>\n<pre><code>aws route53 list-hosted-zones\n<\/code><\/pre>\n<h2 id=\"cloudfront\">CloudFront<\/h2>\n<p>CDN\u670d\u52a1.<\/p>\n<hr>\n<h2 id=\"direct-connect\">Direct Connect<\/h2>\n<p>\u63d0\u4f9b\u6570\u636e\u4e2d\u5fc3\u548cAWS\u76f4\u8fde\u3002<\/p>\n<h2 id=\"global-accelerator\">Global Accelerator<\/h2>\n<h2 id=\"privatelink\">PrivateLink<\/h2>\n<h2 id=\"transit-gateway\">Transit Gateway<\/h2>\n<h2 id=\"vpn\">VPN<\/h2>"},{"title":"AWS Security","link":"https:\/\/canuxcheng.com\/post\/aws_security\/","pubDate":"Fri, 23 Apr 2021 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/aws_security\/","description":"<h1 id=\"security\">Security<\/h1>\n<p>Acceptable Use Policy.<\/p>\n<h2 id=\"iam\">IAM<\/h2>\n<p>IAM: Identity and Access Management.<\/p>\n<p>STS: Security Token Service.<\/p>\n<p>ACL: Access control list.<\/p>\n<p>SG: Security Group.<\/p>\n<p><a class=\"link\" href=\"https:\/\/aws.amazon.com\/cn\/iam\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/aws.amazon.com\/cn\/iam\/<\/a><\/p>\n<pre><code>$aws iam list-users\n<\/code><\/pre>\n<p>IAM\u7684\u4e09\u79cd\u8eab\u4efd\u7c7b\u578b:<\/p>\n<ul>\n<li>Users<\/li>\n<li>Groups<\/li>\n<li>Roles<\/li>\n<\/ul>\n<p>IAM\u901a\u8fc7Policy(json)\u5206\u914d\u6743\u9650\u3002<\/p>\n<hr>\n<h2 id=\"sso\">SSO<\/h2>\n<p>sso\u767b\u9646:<\/p>\n<pre><code>aws configure sso\naws sso login --no-browser\naws sso logout\n<\/code><\/pre>\n<hr>\n<h2 id=\"secrets-manager\">Secrets Manager<\/h2>\n<hr>\n<h2 id=\"acm\">ACM<\/h2>\n<p>AWS Certificate Manager.<\/p>\n<p>\u5728route 53\u521b\u5efa\u6258\u7ba1\u533a(hosted zones)\u4e4b\u540e\uff0c\u53ef\u4ee5\u5728ACM\u7533\u8bf7\u8bc1\u4e66\u3002<\/p>\n<p>\u7533\u8bf7\u597d\u4e86\u8bc1\u4e66\uff0c\u9700\u8981\u5728route 53\u521b\u5efa\u8bb0\u5f55.<\/p>\n<pre><code>aws acm list-certificates --region eu-west-1\n<\/code><\/pre>\n<p>aws-load-balancer-controller\u53ef\u4ee5\u81ea\u52a8\u5173\u8054ACM\u7684\u8bc1\u4e66\u548cingress.<\/p>\n<hr>\n<h2 id=\"artifact\">Artifact<\/h2>\n<p>\u81ea\u52a9\u7684\u5408\u89c4\u62a5\u544a\u3002<\/p>\n<hr>\n<h2 id=\"waf\">WAF<\/h2>\n<h2 id=\"shield\">Shield<\/h2>\n<hr>\n<h2 id=\"kms\">KMS<\/h2>\n<p>Key Management Service.<\/p>\n<h2 id=\"inspector\">Inspector<\/h2>\n<h2 id=\"guardduty\">GuardDuty<\/h2>\n<h2 id=\"cognito\">Cognito<\/h2>\n<p>\u652f\u6301google\/amazon\/MS-AD\/SAML \u767b\u9646\u3002<\/p>\n<h2 id=\"audit-manager\">Audit Manager<\/h2>\n<h2 id=\"cloudhsm\">CloudHSM<\/h2>\n<h2 id=\"detective\">Detective<\/h2>\n<h2 id=\"directory-service\">Directory Service<\/h2>\n<h2 id=\"firewall-manager\">Firewall Manager<\/h2>\n<h2 id=\"macie\">Macie<\/h2>\n<h2 id=\"network-firewall\">Network Firewall<\/h2>\n<h2 id=\"ram\">RAM<\/h2>\n<p>Resource Access Manager<\/p>\n<h2 id=\"security-hub\">Security Hub<\/h2>\n<h2 id=\"sts\">STS<\/h2>\n<p>Security Token Service<\/p>"},{"title":"AWS Storage","link":"https:\/\/canuxcheng.com\/post\/aws_storage\/","pubDate":"Fri, 23 Apr 2021 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/aws_storage\/","description":"<h1 id=\"aws-storage\">AWS Storage<\/h1>\n<h2 id=\"s3\">S3<\/h2>\n<p>Simple Storage Service.<\/p>\n<p>S3\u5206\u7c7b\uff1a<\/p>\n<ul>\n<li>S3\u6807\u51c6<\/li>\n<li>S3\u6807\u51c6-IA<\/li>\n<li>S3\u5355\u533a-IA<\/li>\n<li>S3\u667a\u80fd\u5206\u5c42<\/li>\n<li>S3 Glacier<\/li>\n<li>S3 Glacire Deep Archive<\/li>\n<\/ul>\n<p>\u7279\u70b9:<\/p>\n<ul>\n<li>\u65e0\u9650\u5b58\u50a8<\/li>\n<li>\u5355\u4e2a\u5bf9\u8c61\u8fbe\u52305Tb<\/li>\n<li>\u4e00\u6b21\u5199\u5165\uff0c\u591a\u6b21\u8bfb\u53d6<\/li>\n<li>99%\u6301\u4e45\u6027<\/li>\n<\/ul>\n<h2 id=\"s3-glacier\">S3 Glacier<\/h2>\n<p>\u7528\u4e8e\u5b58\u653e\u5f52\u6863\u6587\u4ef6\uff0c\u6309\u7167\u8bbf\u95ee\u91cf\u6536\u8d39\u3002<\/p>\n<h2 id=\"ebs\">EBS<\/h2>\n<p>Elastic Block Store.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes-sigs\/aws-ebs-csi-driver\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes-sigs\/aws-ebs-csi-driver<\/a><\/p>\n<p>EBS\u53ef\u4ee5\u8fde\u63a5\u5230EC2\u5b9e\u4f8b\uff0c\u53ef\u7528\u533a\u7ea7\u8d44\u6e90\uff0c\u9700\u8981\u4f4d\u4e8e\u540c\u4e00\u53ef\u7528\u533a\u4e2d\u624d\u80fd\u8fde\u63a5\u5230EC2\u5b9e\u4f8b\uff0c\u5377\u4e0d\u4f1a\u81ea\u52a8\u6269\u5c55\u3002<\/p>\n<p>EBS\u53ea\u80fd\u88ab\u5355\u4e2aEC2\u5b9e\u4f8b\u8bbf\u95ee\u3002<\/p>\n<p>\u7279\u70b9:<\/p>\n<ul>\n<li>\u5927\u5c0f\u9ad8\u8fbe16Tb<\/li>\n<li>EC2\u5b9e\u4f8b\u7ec8\u6b62\u540e\u4ecd\u7136\u5b58\u5728<\/li>\n<li>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4e3a\u56fa\u6001(SSD)<\/li>\n<li>\u63d0\u4f9bIOPS SSD\u548cHDD\u9009\u9879<\/li>\n<\/ul>\n<h2 id=\"efs\">EFS<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes-sigs\/aws-efs-csi-driver\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes-sigs\/aws-efs-csi-driver<\/a><\/p>\n<p>Elastic File System \u662flinux\u7684NFS\u670d\u52a1.<\/p>\n<p>EFS\u662f\u533a\u57df\u6027\u670d\u52a1\uff0c\u5c06\u6570\u636e\u5b58\u50a8\u5728\u591a\u4e2a\u53ef\u7528\u533a\u4e2d\u3002\u53ef\u4ee5\u88ab\u4e0a\u5343\u4e2aEC2\u5b9e\u4f8b\u540c\u65f6\u8bbf\u95ee\u3002<\/p>\n<ul>\n<li>\u5b8c\u5168\u6258\u7ba1\u7684NFS\u6587\u4ef6\u7cfb\u7edf<\/li>\n<li>\u4e3alinux\u8d1f\u8f7d\u800c\u8bbe\u8ba1<\/li>\n<li>\u652f\u6301PB\u7ea7\u522b\u6570\u636e<\/li>\n<li>\u53ef\u4ee5\u8de8\u591a\u4e2a\u533a\u57df\u5b58\u50a8\u6570\u636e<\/li>\n<\/ul>\n<p>EFS\u63d0\u4f9b\u4e24\u79cd\u5b58\u50a8\u7c7b\u578b(StorageClass): Standard, Infrequent access.<\/p>\n<h2 id=\"fsx\">FSx<\/h2>\n<p>FSx\u662fwindows File Server\u670d\u52a1.<\/p>\n<h2 id=\"storage-gateway\">Storage Gateway<\/h2>\n<p>\u652f\u6301\u4e09\u79cd\u7c7b\u578b:<\/p>\n<ul>\n<li>Tape gateway<\/li>\n<li>Volume gateway<\/li>\n<li>File Gateway<\/li>\n<\/ul>\n<h2 id=\"aws-backup\">AWS Backup<\/h2>\n<h2 id=\"aws-edr\">AWS EDR<\/h2>\n<p>Elastic Disaster Recovery.<\/p>\n<hr>\n<h1 id=\"snow-family\">Snow Family<\/h1>\n<h2 id=\"snowcone\">Snowcone<\/h2>\n<h2 id=\"snowball\">Snowball<\/h2>\n<ul>\n<li>\u9488\u5bf9large-scale \u6570\u636e\u4f20\u8f93<\/li>\n<li>\u652f\u6301PB\u7ea7\u522b\u6570\u636e<\/li>\n<li>\u901a\u8fc7\u7269\u7406\u8bbe\u5907\u4e0a\u4f20\u6570\u636e\u5230S3<\/li>\n<\/ul>\n<h2 id=\"snowmobile\">Snowmobile<\/h2>\n<ul>\n<li>\u9488\u5bf9large-scale\u6570\u636e\u4f20\u8f93<\/li>\n<li>\u652f\u6301EB\u7ea7\u522b\u6570\u636e<\/li>\n<li>\u901a\u8fc7\u5de5\u4f5c\u7ad9\u4e0a\u4f20\u6570\u636e\u5230S3<\/li>\n<\/ul>\n<hr>\n<h1 id=\"transfer-family\">Transfer family<\/h1>\n<p>SFTP, FTPS, FTP.<\/p>\n<hr>\n<h1 id=\"aws-migration-and-transfer\">AWS Migration and Transfer<\/h1>\n<h2 id=\"ads\">ADS<\/h2>\n<p>Application Discovery Service.<\/p>\n<h2 id=\"ams\">AMS<\/h2>\n<p>Application Migration Service.<\/p>\n<h2 id=\"dms\">DMS<\/h2>\n<p>Database Migration Service.<\/p>\n<p>\u8ba9\u60a8\u80fd\u591f\u8fc1\u79fb\u5173\u7cfb\u6570\u636e\u5e93\u3001\u975e\u5173\u7cfb\u6570\u636e\u5e93\u548c\u5176\u4ed6\u7c7b\u578b\u7684\u6570\u636e\u5b58\u50a8\u3002<\/p>\n<h2 id=\"sct\">SCT<\/h2>\n<p>Schema Conversion Tool<\/p>\n<h2 id=\"datasync\">DataSync<\/h2>\n<h2 id=\"migration-hub\">Migration Hub<\/h2>"},{"title":"CDK","link":"https:\/\/canuxcheng.com\/post\/cloud_cdk\/","pubDate":"Fri, 23 Apr 2021 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/cloud_cdk\/","description":"<h1 id=\"cdk\">CDK<\/h1>\n<p>Cloud Development Kit<\/p>\n<p>SDK\u4e00\u822c\u662f\u548cservice\u4ea4\u4e92\u7684\u3002\nCDK\u7528\u6765\u548c\u57fa\u7840\u8bbe\u65bd\u4ea4\u4e92\u7684\u3002<\/p>\n<h2 id=\"aws-cdk\">AWS CDK<\/h2>\n<p>The AWS Cloud Development Kit (AWS CDK) is an open-source software development framework to define cloud infrastructure in code and provision it through AWS CloudFormation.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/aws\/aws-cdk\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/aws\/aws-cdk<\/a><\/p>\n<h2 id=\"cdk8s\">CDK8S<\/h2>\n<p>cdk8s is an open-source software development framework for defining Kubernetes applications and reusable abstractions using familiar programming languages and rich object-oriented APIs. cdk8s apps synthesize into standard Kubernetes manifests which can be applied to any Kubernetes cluster.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/cdk8s-team\/cdk8s\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/cdk8s-team\/cdk8s<\/a><\/p>\n<h1 id=\"ckdtf\">CKDTF<\/h1>\n<p>Cloud Development Kit for Terraform (CDKTF) allows you to use familiar programming languages to define cloud infrastructure and provision it through HashiCorp Terraform. This gives you access to the entire Terraform ecosystem without learning HashiCorp Configuration Language (HCL) and lets you leverage the power of your existing toolchain for testing, dependency management, etc.<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.terraform.io\/cdktf\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.terraform.io\/cdktf<\/a><\/p>\n<pre><code>$ npm install --global cdktf-cli@latest\n$ cd cdktf-demo\n$ cdktf init --template=&quot;go&quot; --local\n$ cdktf get\n$ go mod tidy\n$ cdktf synth\n$ cdktf deploy\n$ cdktf destroy\n<\/code><\/pre>"},{"title":"TypeScript","link":"https:\/\/canuxcheng.com\/post\/js_ts\/","pubDate":"Fri, 05 Mar 2021 09:36:32 +0000","guid":"https:\/\/canuxcheng.com\/post\/js_ts\/","description":"<h1 id=\"typescript\">TypeScript<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/microsoft\/TypeScript\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/microsoft\/TypeScript<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/www.typescriptlang.org\/zh\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.typescriptlang.org\/zh\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/microsoft\/tsdoc\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/microsoft\/tsdoc<\/a><\/p>\n<hr>\n<h2 id=\"tsx\">TSX<\/h2>\n<p>&ldquo;*.tsx&rdquo; \u662fjs\u7684\u6269\u5c55\uff0c\u5141\u8bb8\u4f7f\u7528xml\u8bed\u6cd5\u3002<\/p>\n<p>typescript\u652f\u6301interface\u3002<\/p>\n<hr>\n<h2 id=\"jsc\">jsc<\/h2>\n<p>\u5c06TS\u7f16\u8bd1\u6210JS, tsconfig.json\u662f\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<hr>"},{"title":"BitBake","link":"https:\/\/canuxcheng.com\/post\/linux_bitbake\/","pubDate":"Sun, 12 Jul 2020 21:18:33 +0000","guid":"https:\/\/canuxcheng.com\/post\/linux_bitbake\/","description":"<h1 id=\"bitbake\">BitBake<\/h1>\n<p>bitbake\u662f\u7c7b\u4f3c\u4e8emake\u7684\u6784\u5efa\u5de5\u5177\uff0c\u4e3b\u8981\u7528\u4e8eOpenEmbedded\u548cyocto\u6784\u5efalinux\u53d1\u884c\u7248.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/openembedded\/bitbake\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/openembedded\/bitbake<\/a><\/p>\n<p>bitbake:<\/p>\n<pre><code>$ bitbake python -c devshell\/devpyshell\n$ bitbake python -c clean\/cleanall\/cleanstate\n$ bitbake python -c compile\n$ bitbake python -c fetch\/fetchall\n# \u67e5\u627e\u4e0b\u8f7d\u5730\u5740\n$ bitbake -e python | grep ^SRC_URI\n# \u6839\u636e\u6587\u4ef6\u67e5\u627e\u5305\u540d\nbitbake&gt; oe-pkgdata-util find-path \/usr\/bin\/python3\n# \u5305\u540d\u67e5\u627erecipe\nbitbake&gt; oe-pkgdata-util lookup-recipe python3-core\n<\/code><\/pre>\n<h1 id=\"openembedded\">openembedded<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/openembedded\/openembedded-core\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/openembedded\/openembedded-core<\/a><\/p>\n<h1 id=\"yoctopoky\">yocto(poky)<\/h1>\n<p>poky\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u6700\u5c0f\u6784\u5efa\u793a\u4f8b\uff0c\u5185\u7f6ebitbake\uff0c\u53ef\u76f4\u63a5\u7f16\u8bd1.<\/p>\n<p><a class=\"link\" href=\"http:\/\/git.yoctoproject.org\/cgit\/cgit.cgi\/poky\/log\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/git.yoctoproject.org\/cgit\/cgit.cgi\/poky\/log\/<\/a><\/p>\n<p><a class=\"link\" href=\"http:\/\/git.yoctoproject.org\/cgit\/cgit.cgi\/meta-virtualization\/tree\/recipes-containers\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/git.yoctoproject.org\/cgit\/cgit.cgi\/meta-virtualization\/tree\/recipes-containers<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/crazy-canux\/poky\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/crazy-canux\/poky<\/a><\/p>\n<h1 id=\"toaster\">toaster<\/h1>"},{"title":"kernel","link":"https:\/\/canuxcheng.com\/post\/linux_kernel\/","pubDate":"Wed, 27 May 2020 22:29:00 +0800","guid":"https:\/\/canuxcheng.com\/post\/linux_kernel\/","description":"<h1 id=\"kernel\">Kernel<\/h1>\n<h1 id=\"command\">command<\/h1>\n<pre><code>lsmod \u67e5\u770b\u5df2\u52a0\u8f7d\u7684\u6a21\u5757 # \/proc\/modules\nrmmod &lt;name&gt; \u5220\u9664\u6a21\u5757\nmodprobe -c \u67e5\u770b\u5df2\u7f16\u8bd1\u53ef\u52a0\u8f7d\u7684\u5185\u6838\u6a21\u5757\nmodprobe &lt;name&gt; \u52a0\u8f7d\u6a21\u5757 # \/etc\/modules\nmodprobe -r &lt;name&gt; \u5220\u9664\u6a21\u5757\n\/\/ modprobe \u91cd\u542f\u5c31\u6ca1\u4e86\necho &quot;ipmi_devintf&quot; &gt;&gt; \/etc\/modules\n<\/code><\/pre>"},{"title":"Linux Security","link":"https:\/\/canuxcheng.com\/post\/linux_security\/","pubDate":"Sun, 24 May 2020 15:30:42 +0800","guid":"https:\/\/canuxcheng.com\/post\/linux_security\/","description":"<h1 id=\"selinux\">SeLinux<\/h1>\n<p>Security-Enhanced Linux<\/p>\n<h1 id=\"seccomp\">SecComp<\/h1>\n<p>Secure computing mode (seccomp) is a Linux kernel feature.<\/p>\n<h1 id=\"apparmor\">AppArmor<\/h1>\n<p>AppArmor (Application Armor) is a Linux security module that protects an operating system and its applications from security threats.<\/p>"},{"title":"K8S CNI","link":"https:\/\/canuxcheng.com\/post\/k8s_cni\/","pubDate":"Thu, 26 Mar 2020 20:55:52 +0800","guid":"https:\/\/canuxcheng.com\/post\/k8s_cni\/","description":"<h1 id=\"network-add-ons\">Network add-ons<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/containernetworking\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/containernetworking<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/ahmetb\/kubernetes-network-policy-recipes\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/ahmetb\/kubernetes-network-policy-recipes<\/a><\/p>\n<ul>\n<li>flannel<\/li>\n<li>cilium<\/li>\n<li>calico<\/li>\n<li>vpc-cni (aws)<\/li>\n<li>kube-router<\/li>\n<li>weavenet<\/li>\n<li>antrea<\/li>\n<li>romana<\/li>\n<\/ul>\n<hr>\n<h2 id=\"cilium\">cilium<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/cilium\/cilium\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/cilium\/cilium<\/a><\/p>\n<hr>\n<h2 id=\"flannel\">Flannel<\/h2>\n<p>flannel\u662fk8s\u6700\u5e38\u7528\u7684\u7f51\u7edc\u63d2\u4ef6.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/coreos\/flannel\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/coreos\/flannel<\/a><\/p>\n<p>\u5728\u6240\u6709node\u4e0a\u90e8\u7f72cni-plugin:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/containernetworking\/plugins\/releases\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/containernetworking\/plugins\/releases<\/a><\/p>\n<pre><code>$ sudo mkdir -p \/opt\/cni\/bin\n\/\/ \u4e0b\u8f7d\u5e76\u89e3\u538b\u6240\u6709\u63d2\u4ef6\u547d\u4ee4\u5230\u8be5\u76ee\u5f55.\n<\/code><\/pre>\n<p>network-addon(master\u4e0a\u64cd\u4f5c\u5373\u53ef):<\/p>\n<pre><code>$ kubectl apply -f https:\/\/raw.githubusercontent.com\/flannel-io\/flannel\/master\/Documentation\/kube-flannel.yml\n<\/code><\/pre>\n<p>veryfy:<\/p>\n<pre><code>$ kubectl get nodes\n$ kubectl get pod --all-namespaces\n<\/code><\/pre>\n<p>\u5220\u9664\u63d2\u4ef6:<\/p>\n<p>\u5220\u9664\u63d2\u4ef6\u4f1a\u5f71\u54cd\u5df2\u7ecf\u90e8\u7f72\u7684pod.<\/p>\n<pre><code>\/\/ \u5220\u9664flannel\n$ kubectl delete -f X.yml\n$ sudo systemctl stop kubelet docker\n\/\/ \u7b2c\u4e8c\u6b65\uff0c\u5728node\u8282\u70b9\u6e05\u7406flannel\u7f51\u7edc\u7559\u4e0b\u7684\u6587\u4ef6\nifconfig cni0 down\nip link delete cni0\nifconfig flannel.1 down\nip link delete flannel.1\nrm -rf \/var\/lib\/cni \/etc\/cni \/run\/flannel\n$ sudo rm -rf \/var\/lib\/kubelet \/var\/lib\/etcd\n\/\/ \u91cd\u542fkubelet\n$ sudo systemctl start kubelet docker\n<\/code><\/pre>\n<p>\u4fee\u6539\u914d\u7f6e:<\/p>\n<p>\/etc\/kube-flannel\/net-conf.json<\/p>\n<pre><code>{\n&quot;Network&quot;: &quot;10.244.0.0\/16&quot;,\n&quot;SubnetLen&quot;: 24,\n&quot;SubnetMin&quot;: &quot;10.244.0.0&quot;,\n&quot;SubnetMax&quot;: &quot;10.244.255.0&quot;,\n&quot;Backend&quot;: {\n&quot;Type&quot;: &quot;vxlan&quot;\n}\n}\n<\/code><\/pre>\n<p>\u4f7f\u7528kubeadm\uff1a<\/p>\n<p>kubeadm init\u5fc5\u987b\u6307\u5b9aflannel\u7684Network\u53c2\u6570:<\/p>\n<pre><code>--pod-network-cidr=10.244.0.0\/16\n<\/code><\/pre>\n<p>\u5982\u679c\u9700\u8981\u4fee\u6539\u5176\u5b83\u53c2\u6570\uff0c\u540c\u65f6\u9700\u8981\u4fee\u6539kubeadm\u7684\u914d\u7f6e<\/p>\n<hr>"},{"title":"K8S CSI","link":"https:\/\/canuxcheng.com\/post\/k8s_csi\/","pubDate":"Wed, 25 Mar 2020 20:55:52 +0800","guid":"https:\/\/canuxcheng.com\/post\/k8s_csi\/","description":"<h1 id=\"csi\">CSI<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/container-storage-interface\/spec\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/container-storage-interface\/spec<\/a><\/p>\n<ul>\n<li>rook<\/li>\n<li>cubefs<\/li>\n<li>longhorn<\/li>\n<li>ceph<\/li>\n<li>minio<\/li>\n<\/ul>\n<hr>\n<h2 id=\"\u5377volume\">\u5377Volume<\/h2>\n<p>\u548cdocker\u4e2d\u7684\u4e00\u6837\u3002<\/p>\n<p>volume\u652f\u6301\u7684\u5377\u7c7b\u578b\u6709: awsEBS, azureDisk, azureFile, gcePD, secret, configMap, emptyDir, hostPath, local, nfs\u7b49.<\/p>\n<pre><code>apiVersion: v1\nkind: Pod\nmetadata:\nname: test-ebs\nspec:\ncontainers:\n- image: k8s.gcr.io\/test-webserver\nname: test-container\nvolumeMounts:\n- mountPath: \/test-ebs\nname: test-volume\nvolumes:\n- name: test-volume\n# \u6b64 AWS EBS \u5377\u5fc5\u987b\u5df2\u7ecf\u5b58\u5728\nawsElasticBlockStore:\nvolumeID: &quot;&lt;volume-id&gt;&quot;\nfsType: ext4\n<\/code><\/pre>\n<p>AWS\u7684EBS\u548cEFS\u9700\u8981\u5b89\u88c5\u9a71\u52a8:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes-sigs\/aws-ebs-csi-driver\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes-sigs\/aws-ebs-csi-driver<\/a>\n<a class=\"link\" href=\"https:\/\/github.com\/kubernetes-sigs\/aws-efs-csi-driver\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes-sigs\/aws-efs-csi-driver<\/a><\/p>\n<hr>\n<h2 id=\"\u5b58\u50a8\u7c7bstorageclass\">\u5b58\u50a8\u7c7bStorageClass<\/h2>\n<p>storageclass\u6ca1\u6709namespace.<\/p>\n<p>\u6bcf\u4e2a\u5b58\u50a8\u7c7b\u5305\u542bprovisioner, parameters\u548creclaimPolicy.<\/p>\n<p>\u5185\u7f6eprovisioner\u7684\u5377\u63d2\u4ef6:<\/p>\n<ul>\n<li>awsEBS<\/li>\n<li>azureFile<\/li>\n<li>azureDisk<\/li>\n<li>gcePD<\/li>\n<li>openstack cinder<\/li>\n<\/ul>\n<p>\u6ca1\u6709provisioner\u7684\u5377\u7c7b\u578b\u53ef\u4ee5\u4f7f\u7528\u5916\u90e8\u63d2\u4ef6\u6216\u8005\u81ea\u5df1\u5f00\u53d1.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes-sigs\/sig-storage-lib-external-provisioner\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes-sigs\/sig-storage-lib-external-provisioner<\/a><\/p>\n<p>awsEBS:<\/p>\n<pre><code>kind: StorageClass\napiVersion: storage.k8s.io\/v1\nmetadata:\nname: sourcegraph\nlabels:\ndeploy: sourcegraph\n# provisioner: ebs.csi.aws.com\nprovisioner: kubernetes.io\/aws-ebs\nparameters:\ntype: gp2 # This configures SSDs (default).\nfsType: ext4 # (default)\nreclaimPolicy: Retain\nvolumeBindingMode: WaitForFirstConsumer\nallowVolumeExpansion: true\n<\/code><\/pre>\n<p>nfs:<\/p>\n<p>kubernetes\u4e0d\u5305\u542bnfs\u9a71\u52a8\uff0c\u9700\u8981\u4f7f\u7528\u5916\u90e8\u9a71\u52a8\u521b\u5efanfs\u5b58\u50a8\u7c7b.<\/p>\n<pre><code>apiVersion: storage.k8s.io\/v1\nkind: StorageClass\nmetadata:\nname: example-nfs\nprovisioner: example.com\/external-nfs\nparameters:\nserver: nfs-server.example.com\npath: \/share\nreadOnly: false\n<\/code><\/pre>\n<p>local:<\/p>\n<p>\u672c\u5730\u5377\u4e0d\u652f\u6301\u52a8\u6001\u5236\u5907.<\/p>\n<pre><code>kind: StorageClass\napiVersion: storage.k8s.io\/v1\nmetadata:\nname: local-storage\nprovisioner: kubernetes.io\/no-provisioner\nvolumeBindingMode: WaitForFirstConsumer\n<\/code><\/pre>\n<h2 id=\"\u6301\u4e45\u5377pv\">\u6301\u4e45\u5377PV<\/h2>\n<p>persistentvolume\u6ca1\u6709namespace, \u7528\u6765\u6307\u5b9a\u5177\u4f53\u7684\u5b58\u50a8\u8d44\u6e90\u3002\u6709\u9759\u6001\u548c\u52a8\u6001\u4e24\u79cd\u65b9\u5f0f\uff0c\u6700\u7ec8\u9700\u8981\u7ed1\u5b9a\u5230pvc\u4e0a\u3002<\/p>\n<p>pv\u7684\u56de\u6536\u7b56\u7565ReclaimPolicy:<\/p>\n<ul>\n<li>Retained\u4fdd\u7559<\/li>\n<li>Deleted\u5220\u9664<\/li>\n<\/ul>\n<p>pv\u7684\u5377\u7ed1\u5b9a\u6a21\u5f0fvolumeBindingMode:<\/p>\n<ul>\n<li>WaitForFirstConsumer<\/li>\n<li>Immediate<\/li>\n<\/ul>\n<p>\u5377\u6a21\u5f0fvolumeMode:<\/p>\n<ul>\n<li>Filesystem(\u9ed8\u8ba4)<\/li>\n<li>Block<\/li>\n<\/ul>\n<p>\u8bbf\u95ee\u6a21\u5f0faccessMode:<\/p>\n<ul>\n<li>RWO: ReadWriteOnce<\/li>\n<li>ROX: ReadOnlyMany<\/li>\n<li>RWX: ReadWriteMany<\/li>\n<li>RWOP: ReadWriteOncePod<\/li>\n<\/ul>\n<p>\u5377\u7684\u9636\u6bb5\uff1a<\/p>\n<ul>\n<li>Avaliable<\/li>\n<li>Bound<\/li>\n<li>Released<\/li>\n<li>Failed<\/li>\n<\/ul>\n<h3 id=\"static-volume-provisioning\">static volume provisioning<\/h3>\n<p>\u9759\u6001pvc\u548cpv\u7684\u7ed1\u5b9a\u901a\u8fc7storageClassName, accessMode\u548ccapacity\u6765\u5224\u65ad\u3002<\/p>\n<p>pv\u4e2d\u7684capacity\u5fc5\u987b\u5927\u4e8e\u7b49\u4e8epvc\u3002<\/p>\n<pre><code>apiVersion: v1\nkind: PersistentVolume\nmetadata:\nname: nas-csi-pv\nlabels:\napp: demo\nspec:\nstorageClassName:\npersistentVolumeReclaimPolicy: Retained\/Recycled\naccessModes:\n- ReadWriteMany\ncapacity:\nstorage: 5Gi\nhostPath:\npath: &quot;\/home\/path&quot;\ncsi:\ndriver: ...\n<\/code><\/pre>\n<h3 id=\"dynamic-volume-provisioning\">dynamic volume provisioning<\/h3>\n<p>\u52a8\u6001pv\u9700\u8981storageclass, \u7531StorageClass\u52a8\u6001\u7684\u521b\u5efaPV, \u4e0d\u9700\u8981\u624b\u52a8\u521b\u5efapv\uff0c\u53ea\u9700\u8981\u5728pvc\u4e2d\u6307\u5b9astorageclass\u5373\u53ef.<\/p>\n<p>storageclass\u6ca1\u6709namespace<\/p>\n<pre><code>kind: StorageClass\napiVersion: storage.k8s.io\/v1\nmetadata:\nname: sourcegraph\nlabels:\ndeploy: sourcegraph\nprovisioner: kubernetes.io\/aws-ebs\nparameters:\ntype: gp2\nreclaimPolicy: Retain\nvolumeBindingMode: WaitForFirstConsumer\nallowVolumeExpansion: true\napiVersion: v1\nkind: PersistentVolumeClaim\nmetadata:\nname: pgsql\nlabels:\ndeploy: sourcegraph\nsourcegraph-resource-requires: no-cluster-admin\napp.kubernetes.io\/component: pgsql\nspec:\n\/\/ \u901a\u8fc7storageClassName\u81ea\u52a8\u7ed9pvc\u521b\u5efapv\nstorageClassName: sourcegraph\naccessModes:\n- ReadWriteOnce\nresources:\nrequests:\nstorage: 200Gi\n<\/code><\/pre>\n<hr>\n<h2 id=\"pvc\">PVC<\/h2>\n<pre><code>apiVersion: v1\nkind: PersistentVolumeClaim\nmetadata:\nname: nsa-pvc\nnamespace: test\nlabels:\napp: demo\nspec:\naccessModes:\n- ReadWriteMany\nresources:\nrequests:\nstorage: 5Gi\n\/\/ \u901a\u8fc7selector\u8ba9PVC\u4f7f\u7528\u6307\u5b9a\u7684PV\u3002\nselector:\napp: demo\n<\/code><\/pre>\n<hr>\n<h2 id=\"volumesnapshotclass\">VolumeSnapshotClass<\/h2>\n<h2 id=\"volumesnapshot\">VolumeSnapshot<\/h2>\n<p>VS\u662f\u5bf9\u8d44\u6e90\u7684\u8bf7\u6c42.<\/p>\n<pre><code>apiVersion: snapshot.storage.k8s.io\/v1\nkind: VolumeSnapshot\nmetadata:\nname: new-snapshot-test\nspec:\nvolumeSnapshotClassName: csi-hostpath-snapclass\nsource:\npersistentVolumeClaimName: pvc-test\n<\/code><\/pre>\n<h2 id=\"volumesnapshotcontent\">VolumeSnapshotContent<\/h2>\n<p>VSC\u5b9e\u9645\u4e2d\u8d44\u6e90\u7ba1\u7406.<\/p>\n<pre><code>apiVersion: snapshot.storage.k8s.io\/v1\nkind: VolumeSnapshotContent\nmetadata:\nname: snapcontent-72d9a349-aacd-42d2-a240-d775650d2455\nspec:\ndeletionPolicy: Delete\ndriver: hostpath.csi.k8s.io\nsource:\nvolumeHandle: ee0cfb94-f8d4-11e9-b2d8-0242ac110002\nvolumeSnapshotClassName: csi-hostpath-snapclass\nvolumeSnapshotRef:\nname: new-snapshot-test\nnamespace: default\nuid: 72d9a349-aacd-42d2-a240-d775650d2455\n<\/code><\/pre>\n<hr>"},{"title":"Kubectl","link":"https:\/\/canuxcheng.com\/post\/k8s_kubectl\/","pubDate":"Fri, 10 Jan 2020 20:58:01 +0800","guid":"https:\/\/canuxcheng.com\/post\/k8s_kubectl\/","description":"<h1 id=\"kubectl\">kubectl<\/h1>\n<p>kubectl\u662fkubernetes\u7684\u7ba1\u7406\u5de5\u5177.<\/p>\n<p><a class=\"link\" href=\"https:\/\/kubernetes.io\/docs\/tasks\/tools\/#kubectl\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kubernetes.io\/docs\/tasks\/tools\/#kubectl<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/cloudnativelabs\/kube-shell\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/cloudnativelabs\/kube-shell<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/jonmosco\/kube-ps1\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/jonmosco\/kube-ps1<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/ahmetb\/kubectx\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/ahmetb\/kubectx<\/a><\/p>\n<p>\u5728master\u4e0a\u901a\u8fc7kubectl\u547d\u4ee4\u7ba1\u7406\u96c6\u7fa4.<\/p>\n<p>kubectl \u7248\u672c\u548c\u96c6\u7fa4\u7248\u672c\u4e4b\u95f4\u7684\u5dee\u5f02\u5fc5\u987b\u5728\u4e00\u4e2a\u5c0f\u7248\u672c\u53f7\u5185\u3002 \u4f8b\u5982\uff1av1.24 \u7248\u672c\u7684\u5ba2\u6237\u7aef\u80fd\u4e0e v1.23\u3001 v1.24 \u548c v1.25 \u7248\u672c\u7684\u63a7\u5236\u9762\u901a\u4fe1\u3002 \u7528\u6700\u65b0\u517c\u5bb9\u7248\u7684 kubectl \u6709\u52a9\u4e8e\u907f\u514d\u4e0d\u53ef\u9884\u89c1\u7684\u95ee\u9898\u3002<\/p>\n<h2 id=\"options\">Options<\/h2>\n<pre><code>kubectl options # \u67e5\u770b\u6240\u6709\u547d\u4ee4\u53ef\u7528\u9009\u9879\n--kubeconfig\nkubectl --kubeconfig=$HOME\/.kube\/config (default)\n-n\/--namespace\n<\/code><\/pre>\n<h2 id=\"basic-command\">basic command<\/h2>\n<p>create:<\/p>\n<pre><code># \u901a\u8fc7yaml\u6216json\u6587\u4ef6\u521b\u5efa\u65b0\u7684\u8d44\u6e90\n$ kubectl create -f FILENAME [options]\nkubectl create namespace &lt;NS&gt;\nkubectl create -f resource.yaml\n\/\/ \u8f93\u51fa\u4e00\u4e2a\u8d44\u6e90\u7684yaml\u683c\u5f0f.\nkubectl create deployment &lt;name&gt; --image=&lt;img-name&gt; --dry-run=client --output=yaml --namespace=&lt;ns&gt;\n<\/code><\/pre>\n<p>delete:<\/p>\n<pre><code>\/\/ \u5220\u9664\u8d44\u6e90\n$ kubectl delete (-f FILENAME | -k DICT | TYPE [(NAME|-l label|--all)]) [optiions]\noptions:\n-f\/--filename\n--all\n--all-namespaces\n--force\n--grace-period\n--cascade\n$ kubectl delete -f resource.yaml\n$ kubectl delete pods --all -n &lt;NS&gt; # delete all pods in the current namespace\n\/\/ \u5220\u9664\u6307\u5b9ans\u4e0b\u6240\u6709\u8d44\u6e90.\n$ kubectl delete all --all -n {namespace}\n<\/code><\/pre>\n<p>\u5220\u9664\u5e26\u6709finalizers\u5b57\u6bb5\u7684\u5bf9\u8c61\uff0c\u5bf9\u8c61\u5b9e\u9645\u88ab\u66f4\u65b0\u4e86\uff0c\u6ca1\u6709\u771f\u7684\u88ab\u5220\u9664\u3002\u53ef\u4ee5\u901a\u8fc7patch\u6765\u5220\u9664\u3002\u53c2\u8003patch\u3002<\/p>\n<p>\u5220\u9664\u5e26\u6709ownerReferences\u5b57\u6bb5\u7684\u5bf9\u8c61\uff0c\u5220\u9664\u7236\u5bf9\u8c61\u9ed8\u8ba4\u4f1a\u5220\u9664\u6240\u6709\u5b50\u5bf9\u8c61\uff0c\u901a\u8fc7&ndash;cascade=false\u53ea\u5220\u9664\u7236\u5bf9\u8c61\u3002<\/p>\n<pre><code>kubectl delete deployment &lt;deployment-name&gt; --cascade=false\n<\/code><\/pre>\n<p>expose:<\/p>\n<pre><code># \u5c06pod\/deployment\/replicaset\u66b4\u9732\u4e3aservice\uff0c \u4f1a\u521b\u5efa\u5bf9\u5e94\u7684service\u3002\n$ kubectl expose (-f FILENAME | TYPE NAME) [--port=port] [--protocol=TCP|UDP|SCTP] [--target-port=...] [--name=...] [--external-ip=...] [--type=ClusterIP|NodePort|LoadBalancer] [options]\n# \u9ed8\u8ba4\u662fClusterIP\n$ kubectl expose pod &lt;pod-name&gt; --port=80 --target-port=8080 --name=&lt;svc-name&gt;\n# \u66b4\u9732deployment\u4e3aservice\u3002\n# nodeport\u53ef\u4ee5\u4f7f\u7528\u4efb\u610f\u8282\u70b9\u7684IP\u8bbf\u95ee.\n$ kubectl expose deployment\/hello-world --type=NodePort --name=example-service\n$ kubectl expose deployment hello-world --type=LoadBalancer --port=80 --target-port=8080\n\/\/ \u83b7\u53d6service\u7684yaml\nkubectl expose deployment &lt;deploy-name&gt; --type=LoadBalancer --port=80 --dry-run=client --output=yaml\n<\/code><\/pre>\n<p>run:<\/p>\n<pre><code># \u521b\u5efapod:\n$ kubectl run NAME --image=image [--env=&quot;key=value&quot;] [--port=port] [--replicas=replicas] [--dry-run=bool] [--overrides=inline-json] [--command] -- [COMMAND] [args...] [options]\nkubectl run my-pod --image=nginx --replica=3 --port=80 --restart=Never\n<\/code><\/pre>\n<p>set:<\/p>\n<pre><code>$ kubectl set SUBCOMMAND [options]\n\/\/ \u66f4\u65b0\u8d44\u6e90\u7684\u5b57\u6bb5\u6216\u5c5e\u6027\n$ kubectl set image deployment\/my-deployment my-container=nginx:1.21\n$ kubectl set env deployment\/my-deployment LOG_LEVEL=debug\n$ kubectl set resources deployment\/my-deployment --limits=cpu=500m,memory=1Gi\n<\/code><\/pre>\n<p>get:<\/p>\n<pre><code>\/\/ \u83b7\u53d6resource\u4fe1\u606f(docker ps)\n$ kubectl [-n &lt;namespace&gt;] get [resource] [flags] [options]\noptions:\n-A\/--all-namespaces\n-f\/--filename\n-o\/--output json\/yaml\/json\/wide\/name\/...\n-w\/--watch\n--watch-only\nkubectl get nodes --show-labels\nkubectl get nodes\/no # \u83b7\u53d6node\u8282\u70b9\u4fe1\u606f\nkubectl get namespace\/ns # \u83b7\u53d6namespace\u4fe1\u606f\nkubectl get componentstatuses\/cs\nkubectl get all --all-namespaces\nkubectl get all -n kube-system\nkubectl get pod\/pods\/po\nkubectl get po -w\/--watch\nkubectl get po -o wide\nkubectl get deployment\/deployments\/deploy\nkubectl get service\/services\/svc\n<\/code><\/pre>\n<p>explain:<\/p>\n<p><a class=\"link\" href=\"https:\/\/kubernetes.io\/docs\/reference\/generated\/kubernetes-api\/v1.17\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kubernetes.io\/docs\/reference\/generated\/kubernetes-api\/v1.17\/<\/a><\/p>\n<pre><code>\/\/ \u67e5\u770b\u8d44\u6e90\u89e3\u6790\n$ kubectl explain RESOURCE [options]\n\/\/ \u67e5\u770b\u8d44\u6e90\u7684\u7279\u5b9a\u5b57\u6bb5\n$ kubectl explain pod.spec\n$ kubectl explain deploy.spec\n$ kubectl explain deploy.spec.template.spec\n\/\/ \u67e5\u770b\u7279\u5b9aapi\u7248\u672c\u7684\u8d44\u6e90\n$ kubectl explain deployment --api-version=apps\/v1\n<\/code><\/pre>\n<p>edit:<\/p>\n<pre><code>\/\/ \u5728\u7ebf\u4fee\u6539\u8d44\u6e90\uff0c\u76f4\u63a5\u751f\u6548.\n$ kubectl edit [RESOURCE_TYPE]\/[RESOURCE_NAME] [options]\nkubectl edit node my-node\n<\/code><\/pre>\n<h2 id=\"advanced-commands\">advanced commands<\/h2>\n<p>apply: \u521b\u5efa\u6216\u66f4\u65b0\u8d44\u6e90<\/p>\n<pre><code>$ kubectl apply -f FILENAME [options]\n$ kubectl apply -f resource1.yaml -f resource2.yaml\n$ kubectl apply -f .\/manifests\/\n$ kubectl apply -f resource.yaml --dry-run=client\n$ kubectl apply -f resource.yaml --force\n<\/code><\/pre>\n<p>diff:<\/p>\n<pre><code>$ kubectl diff -f &lt;file|directory&gt; [options]\n$ kubectl diff -f resource.yaml\n<\/code><\/pre>\n<p>patch<\/p>\n<pre><code># \u901a\u8fc7json\u6216yaml\u5bf9\u8d44\u6e90\u8fdb\u884c\u90e8\u5206\u66f4\u65b0\u3002\n$ kubectl patch [RESOURCE_TYPE] [RESOURCE_NAME] -p &lt;patch-data&gt; [options]\n\/\/ \u5220\u9664terminating\u72b6\u6001\u7684resource\n$ kubectl patch persistentvolumeclaim\/storage -p '{&quot;metadata&quot;:{&quot;finalizers&quot;:null}}' -n &lt;ns&gt;\n# \u66ff\u6362\u5df2\u6709\u7684\u8d44\u6e90\n$ kubectl replace -f &lt;file&gt; [options]\n$ kubectl replace -f resource.yaml -n my-namespace\n$ kubectl wait [RESOURCE_TYPE] [RESOURCE_NAME] --for=condition=&lt;CONDITION&gt; [options]\n$ kubectl kustomize\n<\/code><\/pre>\n<h2 id=\"deploy-command\">deploy command<\/h2>\n<p>scale:<\/p>\n<pre><code>$ kubectl scale [RESOURCE_TYPE] [RESOURCE_NAME] --replicas=&lt;number&gt; [options]\n$ kubectl scale deployment &lt;deploy-name&gt; -n &lt;ns&gt; --replicas=0\n<\/code><\/pre>\n<p>autoscale:<\/p>\n<pre><code># \u7ed9deploy\uff0creplicaset\uff0cstatefulset\u7b49\u8d44\u6e90\u8bbe\u7f6e\u81ea\u52a8\u4f38\u7f29.HPA\n$ kubectl autoscale [RESOURCE_TYPE]\/[RESOURCE_NAME] [flags]\nkubectl autoscale deployment my-deployment --min=2 --max=10 --cpu-percent=80\n<\/code><\/pre>\n<p>rollout:<\/p>\n<pre><code>\/\/ \u56de\u6eda\n$ kubectl rollout [SUBCOMMAND] [RESOURCE_TYPE\/RESOURCE_NAME] [options]\n\/\/ \u6682\u505c\/\u6062\u590d\/\u91cd\u542f deployment.\nkubectl rollout pause\/resume\/restart deploy\/katib-mysql -n kubeflow\n<\/code><\/pre>\n<h2 id=\"debugtroubleshoot\">debug&amp;troubleshoot<\/h2>\n<p>describe:<\/p>\n<pre><code>\/\/ like docker inspect\n$ kubectl describe (-f FILENAME | TYPE ... | TYPE\/NAME) [options]\noptions:\n-A\/--all-namespaces\n-f\/--filename\n\/\/ \u67e5\u770bnode\u4fe1\u606f\n$ kubectl describe nodes &lt;name&gt;\n\/\/\u67e5\u770bpod\u8be6\u7ec6\u4fe1\u606f\n$ kubectl describe pods &lt;name&gt;\n\/\/ \u83b7\u53d6k8s-dashboard\u7684token\n$ kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')\n<\/code><\/pre>\n<p>logs:<\/p>\n<pre><code># like docker logs\n$ kubectl logs [-f] [-p] (POD | TYPE\/NAME) [-c CONTAINER] [options]\noptions:\n--all-containers\n-f\/--follow\n-p\/--previous\n\/\/ \u67e5\u770bpod\u4e2d\u6307\u5b9acontainer log\nkubectl logs -f &lt;pod&gt; -c &lt;container&gt; -n &lt;ns&gt;\n<\/code><\/pre>\n<p>exec:<\/p>\n<pre><code># like docker exec\n$ kubectl exec (POD | TYPE\/NAME) [-c CONTAINER] [flags] -- COMMAND [args...] [options]\noptions:\n-c\/--container\n-i\/--stdin\n-t\/--tty\n$ kubectl exec -it &lt;pod&gt; -n &lt;ns&gt; -- \/bin\/bash\n$ kubectl exec -it &lt;pod&gt; -n &lt;ns&gt; -c &lt;container&gt; -- \/bin\/sh\n<\/code><\/pre>\n<p>port-forward:<\/p>\n<p>\u7531\u4e8e\u5df2\u77e5\u7684\u9650\u5236\uff0c\u76ee\u524d\u7684\u7aef\u53e3\u8f6c\u53d1\u4ec5\u9002\u7528\u4e8e TCP \u534f\u8bae.<\/p>\n<p>\u53ea\u80fd\u901a\u8fc7\u8fd0\u884c\u8f6c\u53d1\u547d\u4ee4\u7684IP\/FQDN\u8bbf\u95ee\u3002<\/p>\n<pre><code>$ kubectl port-forward [RESOURCE_TYPE]\/[RESOURCE_NAME] [LOCAL_PORT]:[REMOTE_PORT] [options]\n\/\/ \u8f6c\u53d1\u672c\u5730\u7aef\u53e3\u5230deploy\/rs\/svc\/pod\n$ kubectl port-forward pod\/my-pod 8080:80 -n &lt;ns&gt;\n$ kubectl port-forward svc\/redis-service 6379:6379 -n redis\n# \u5141\u8bb8\u6240\u6709IP\u8bbf\u95ee\n$ kubectl port-forward --address 0.0.0.0 -n kubernetes-dashboard service\/kubernetes-dashboard 8080:443\n<\/code><\/pre>\n<p>proxy:<\/p>\n<pre><code>$ kubectl proxy\n\/\/ \u901a\u8fc7proxy\u53ef\u4ee5\u8bbf\u95ee\u9ed8\u8ba4\u7684clusterIP\u670d\u52a1.\n<\/code><\/pre>\n<p>attach:<\/p>\n<pre><code>$ kubectl attach [POD_NAME] [-c CONTAINER] [options]\n$ kubectl attach my-pod -n &lt;ns&gt; -c &lt;container&gt;\n<\/code><\/pre>\n<p>cp:<\/p>\n<pre><code>$ kubectl cp &lt;source&gt; &lt;destination&gt; [options]\n$ kubectl cp .\/local-file.txt my-pod:\/app\/ -n my-namespace\n$ kubectl cp my-pod:\/app\/remote-file.txt .\/ -n my-namespace\n<\/code><\/pre>\n<p>auth:<\/p>\n<pre><code>$ kubectl auth [SUBCOMMAND] [options]\n$ kubectl auth can-i get pods -n my-namespace\n<\/code><\/pre>\n<p>debug:<\/p>\n<pre><code>$ kubectl debug [RESOURCE] [options]\n\/\/ debug node -- \u76f4\u63a5\u8fdb\u5165node\u7684shell\uff0clog\u5728\/host\/var\/log\n$ kubectl debug node\/&lt;name&gt; -it --image=\n\/\/ debug pod -- \u521b\u5efa\u4e00\u4e2a\u65b0\u7684pod\u6765\u8c03\u8bd5\u73b0\u6709\u7684pod\n$kubectl debug pod\/&lt;pod-name&gt; -n &lt;namespace&gt; --copy-to=&lt;new-pod-name&gt; --container=&lt;container-name&gt;\n$kubectl debug pod\/&lt;pod-name&gt; -n &lt;namespace&gt; --container=&lt;container-name&gt; --image=busybox\n<\/code><\/pre>\n<h2 id=\"cluster-management\">cluster management<\/h2>\n<p>top:<\/p>\n<pre><code>$ kubectl top [RESOURCE_TYPE] [RESOURCE_NAME] [options]\n$ kubectl top nodes\n$ kubectl top pods -n &lt;ns&gt;\n<\/code><\/pre>\n<p>cluster-info:<\/p>\n<pre><code>$ kubectl cluster-info\n<\/code><\/pre>\n<p>certificate:<\/p>\n<pre><code>$ kubectl certificate [SUBCOMMAND] [options]\n<\/code><\/pre>\n<p>cordon:<\/p>\n<pre><code>\/\/ \u8282\u70b9\u53d8\u6210unschedulable\n$ kubectl cordon &lt;node&gt;\n\/\/ \u8282\u70b9\u53d8\u6210schedulable\n$ kubectl uncordon &lt;node&gt;\n<\/code><\/pre>\n<p>drain:<\/p>\n<pre><code>\/\/ \u5b89\u5168\u4ece\u8282\u70b9\u9a71\u9010pod\n$ kubectl drain &lt;node-name&gt; [options]\n$ kubectl drain &lt;node&gt; --delete-emptydir-data --ignore-daemonsets\n\/\/ \u5f3a\u5236\u9a71\u9010\u8282\u70b9\u4e0a\u7684pod\n$ kubectl drain my-node --force --ignore-daemonsets\n<\/code><\/pre>\n<p>tain:<\/p>\n<pre><code>\/\/\u7ba1\u7406\u6c61\u70b9\n$ kubectl taint nodes &lt;node-name&gt; &lt;key&gt;=&lt;value&gt;:&lt;effect&gt;\n$kubectl taint nodes &lt;node&gt; &lt;key&gt;=&lt;value&gt;:NoSchedule-\n<\/code><\/pre>\n<h2 id=\"settings-commands\">Settings Commands<\/h2>\n<p>label<\/p>\n<pre><code>label Update the labels on a resource\nkubectl label nodes &lt;your-node-name&gt; disktype=ssd\n<\/code><\/pre>\n<p>annotate:<\/p>\n<pre><code>annotate Update the annotations on a resource\n<\/code><\/pre>\n<p>completion:<\/p>\n<pre><code>completion Output shell completion code for the specified shell (bash or zsh)\n<\/code><\/pre>\n<h2 id=\"others\">others<\/h2>\n<p>api-resources:<\/p>\n<pre><code>\/\/ api-resources Print the supported API resources on the server.\nkubectl api-resources\n<\/code><\/pre>\n<p>api-versions:<\/p>\n<pre><code>\/\/ api-versions Print the supported API versions on the server, in the form of &quot;group\/version&quot;.\nkubectl api-versions\n<\/code><\/pre>\n<p>config:<\/p>\n<pre><code>\/\/ \u53c2\u8003kubectx\nconfig Modify kubeconfig files.\n<\/code><\/pre>\n<p>plugin:<\/p>\n<pre><code>\/\/ \u53c2\u8003krew\nplugin Provides utilities for interacting with plugins.\n\/\/ \u67e5\u770b\u5b89\u88c5\u7684plugin\n$ kubectl plugin list\n<\/code><\/pre>\n<p>version:<\/p>\n<pre><code>version Print the client and server version information.\n<\/code><\/pre>\n<hr>\n<h2 id=\"kustomize\">kustomize<\/h2>\n<p><a class=\"link\" href=\"https:\/\/kustomize.io\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kustomize.io\/<\/a><\/p>\n<p>kustomize\u662fkubernetes\u7684\u8d44\u6e90\u7f16\u6392\u5de5\u5177.<\/p>\n<pre><code>kubectl kustomize DIR [flags] [options]\n<\/code><\/pre>\n<p>\u540c\u65f6build\u548capply\uff1a<\/p>\n<pre><code>kubectl apply -k dir\/\n<\/code><\/pre>\n<hr>\n<h2 id=\"shell-auotcompletion\">shell-auotcompletion<\/h2>\n<p>bash\/zsh \u81ea\u52a8\u8865\u5168\u5de5\u5177.<\/p>\n<p><a class=\"link\" href=\"https:\/\/kubernetes.io\/docs\/tasks\/tools\/install-kubectl\/#enabling-shell-autocompletion\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kubernetes.io\/docs\/tasks\/tools\/install-kubectl\/#enabling-shell-autocompletion<\/a><\/p>\n<pre><code>$ kubectl completion bash | sudo tee \/etc\/bash_completion.d\/kubectl\n<\/code><\/pre>\n<h2 id=\"krew\">krew<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes-sigs\/krew\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes-sigs\/krew<\/a><\/p>\n<p>\u5b89\u88c5kubectl plugin\u7684\u5de5\u5177<\/p>\n<pre><code>\/\/ \u4e0b\u8f7d\u63d2\u4ef6\u5217\u8868\n$ kubectl krew update\n\/\/ \u67e5\u627e\u63d2\u4ef6\n$ kubectl krew search\n\/\/ \u5b89\u88c5\u63d2\u4ef6\n$ kubectl krew install &lt;name&gt;\n\/\/ \u5347\u7ea7\u63d2\u4ef6\n$ kubectl krew upgrade\n\/\/ \u5378\u8f7d\u63d2\u4ef6\n$ kubectl krew uninstall &lt;name&gt;\n<\/code><\/pre>\n<h2 id=\"kubectx\">kubectx<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/ahmetb\/kubectx\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/ahmetb\/kubectx<\/a><\/p>\n<p>\u5728cluster\u548cnamespace\u4e4b\u95f4\u5207\u6362\u7684\u547d\u4ee4\u884c\u5de5\u5177.<\/p>\n<p>\u5305\u62eckubectx \u548c kubedns<\/p>\n<p>\u901a\u8fc7krew\u5b89\u88c5\uff0c\u4f5c\u4e3akubectl\u7684plugin:<\/p>\n<pre><code>$ kubectl krew install ctx\n$ kubectl krew install ns\n<\/code><\/pre>"},{"title":"CI\/CD","link":"https:\/\/canuxcheng.com\/post\/devops_cicd\/","pubDate":"Fri, 10 Jan 2020 20:55:52 +0800","guid":"https:\/\/canuxcheng.com\/post\/devops_cicd\/","description":"<h1 id=\"ci\">CI<\/h1>\n<h2 id=\"jenkins\">jenkins<\/h2>\n<h2 id=\"gitlab\">gitlab<\/h2>\n<h2 id=\"github-actions\">github actions<\/h2>\n<h2 id=\"cloudbees\">cloudbees<\/h2>\n<hr>\n<h1 id=\"cd\">CD<\/h1>\n<h2 id=\"argo-cd\">argo-cd<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/argoproj\/argo-cd\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/argoproj\/argo-cd<\/a><\/p>\n<p>argocd-image-updater.<\/p>\n<p>argo-rollout.<\/p>\n<h2 id=\"flux-cd\">flux-cd<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/fluxcd\/flux\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/fluxcd\/flux<\/a><\/p>"},{"title":"Contribution","link":"https:\/\/canuxcheng.com\/post\/k8s_oss\/","pubDate":"Fri, 10 Jan 2020 20:55:52 +0800","guid":"https:\/\/canuxcheng.com\/post\/k8s_oss\/","description":"<h1 id=\"kubernetes-contribution\">Kubernetes Contribution<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes\/community\/blob\/master\/contributors\/guide\/contributor-cheatsheet\/README-zh.md\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes\/community\/blob\/master\/contributors\/guide\/contributor-cheatsheet\/README-zh.md<\/a><\/p>\n<h2 id=\"\u521b\u5efagoogle\u8d26\u53f7\">\u521b\u5efagoogle\u8d26\u53f7<\/h2>\n<p>\u63a8\u8350\u7533\u8bf7\u4e00\u4e2agoogle\u90ae\u7bb1\u3002<\/p>\n<p>\u5728\u5f00\u53d1\u673a\u914d\u7f6egit<\/p>\n<pre><code>$ git config --global user.email name@gmail.com\n$ git config user.email name@gmail.com\n<\/code><\/pre>\n<h2 id=\"\u7b7ecla\u5e76\u9605\u8bfbcoc\">\u7b7eCLA\u5e76\u9605\u8bfbCoC<\/h2>\n<p>\u4e2a\u4eba\u5f00\u53d1\u8005\u9700\u8981\u7b7e\u7f72CLA, \u9009\u62e9individual contributors\u5e76\u7528github\u8d26\u53f7\u767b\u9646\uff0c\u7136\u540e\u53bb\u90ae\u7bb1\u6388\u6743\uff1b\u4e4b\u540e\u91cd\u65b0\u8fdb\u5165\uff0c\u518d\u53bb\u90ae\u7bb1\u7b7e\u5b57\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/identity.linuxfoundation.org\/projects\/cncf\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/identity.linuxfoundation.org\/projects\/cncf<\/a><\/p>\n<p>\u8bfb\u4e00\u4e0bCoC\u548cCV<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/cncf\/foundation\/blob\/master\/code-of-conduct-languages\/zh.md\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/cncf\/foundation\/blob\/master\/code-of-conduct-languages\/zh.md<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes\/community\/blob\/master\/values.md\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes\/community\/blob\/master\/values.md<\/a><\/p>\n<h2 id=\"\u914d\u7f6e\u5f00\u53d1\u73af\u5883\">\u914d\u7f6e\u5f00\u53d1\u73af\u5883<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes\/community\/blob\/master\/contributors\/devel\/README.md#setting-up-your-dev-environment-coding-and-debugging\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes\/community\/blob\/master\/contributors\/devel\/README.md#setting-up-your-dev-environment-coding-and-debugging<\/a><\/p>\n<p>\u53ef\u4ee5\u5728docker\u91cc\u9762\u7f16\u8bd1\uff0c\u4e5f\u53ef\u4ee5\u76f4\u63a5\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u7f16\u8bd1\u3002<\/p>\n<p>\u5728docker\u91cc\u9762\u7f16\u8bd1<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes\/kubernetes\/blob\/ae9ca48f01ddb03731e7903cfe91ef3db9ce8990\/build\/README.md\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes\/kubernetes\/blob\/ae9ca48f01ddb03731e7903cfe91ef3db9ce8990\/build\/README.md<\/a><\/p>\n<pre><code>build\/run.sh make \u53ea\u7f16\u8bd1linux\u5e73\u53f0\nbuild\/run.sh make cross \u7f16\u8bd1\u6240\u6709\u5e73\u53f0\nbuild\/run.sh make kubectl KUBE_BUILD_PLATFORMS=darwin\/amd64 \u7f16\u8bd1\u6307\u5b9a\u5e73\u53f0\u7684\u6307\u5b9a\u7ec4\u4ef6\nbuild\/run.sh make test \u5355\u5143\u6d4b\u8bd5\nbuild\/run.sh make test-integration \u96c6\u6210\u6d4b\u8bd5\nbuild\/run.sh make test-cmd \u547d\u4ee4\u884c\u6d4b\u8bd5\nbuild\/copy-output.sh \u5c06\u7f16\u8bd1\u7684binary\u4ece_output\/dockerized\/bin\u62f7\u8d1d\u5230\u672c\u5730\nbuild\/make-clean.sh \u6e05\u7a7a_output\nbuild.shell.sh \u4ea4\u4e92\u6a21\u5f0f\u8fdb\u5165\u7f16\u8bd1\u7684container\nbuild\/release.sh \u7f16\u8bd1\uff0c\u6d4b\u8bd5\uff0c\u6253\u5305\uff0ckubernetes.tar.gz\n...\n<\/code><\/pre>\n<p>\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u7f16\u8bd1<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes\/community\/blob\/master\/contributors\/devel\/development.md#building-kubernetes-on-a-local-osshell-environment\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes\/community\/blob\/master\/contributors\/devel\/development.md#building-kubernetes-on-a-local-osshell-environment<\/a><\/p>\n<p>\u5b89\u88c5\u4f9d\u8d56<\/p>\n<pre><code>sudo apt-get update\nsudo apt-get install build-essential\n\/\/ apt: docker, rsync, jq, go,\n\/\/ python: pyyaml,\n\/\/ \u5b89\u88c5etcd\u7528\u4e8e\u96c6\u6210\u6d4b\u8bd5\n.\/hack\/install-etcd.sh\nexport PATH=&quot;$GOPATH\/src\/k8s.io\/kubernetes\/third_party\/etcd:${PATH}&quot;\n<\/code><\/pre>\n<p>\u7f16\u8bd1\u548c\u6d4b\u8bd5<\/p>\n<pre><code>make all \u5168\u90e8\u7f16\u8bd1\nmake WHAT=cmd\/kubectl \u6307\u5b9a\u7f16\u8bd1\u7ec4\u4ef6\nmake cross \u7f16\u8bd1\u6240\u6709\u5e73\u53f0\nmake cross KUBE_BUILD_PLATFORMS=windows\/amd64 \u7f16\u8bd1\u6307\u5b9a\u5e73\u53f0\nmake verify presubmission verification\u6d4b\u8bd5\nmake test \u5355\u5143\u6d4b\u8bd5\nmake test-integration \u96c6\u6210\u6d4b\u8bd5\u4f9d\u8d56etcd\n<\/code><\/pre>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes\/test-infra\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes\/test-infra<\/a><\/p>\n<h2 id=\"\u4e86\u89e3\u793e\u533a\">\u4e86\u89e3\u793e\u533a<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes\/community\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes\/community<\/a><\/p>\n<p>\u56e0\u4e3a\u9879\u76ee\u7ec4\u4ef6\u5f88\u591a\uff0c\u6240\u4ee5\u901a\u8fc7\u7279\u522b\u5174\u8da3\u5c0f\u7ec4\u6765\u5206\u7c7b\u3002<\/p>\n<ul>\n<li>SIG: Special Interest Groups<\/li>\n<li>WG: Working Group<\/li>\n<li>UG: User Group<\/li>\n<\/ul>\n<p>KEP: Kubernetes Enhancement Proposal<\/p>\n<p>\u5bf9\u4e8e\u529f\u80fd\u548cAPI\u7684\u4fee\u6539\u9700\u8981\u5728KEP\u63d0\u4ea4\u8bae\u6848\u8ba8\u8bba\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes\/enhancements\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes\/enhancements<\/a><\/p>\n<p><a class=\"link\" href=\"http:\/\/slack.k8s.io\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/slack.k8s.io\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/discuss.kubernetes.io\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/discuss.kubernetes.io\/<\/a><\/p>\n<h2 id=\"\u9009\u53d6\u4fee\u6539\u7684cl\">\u9009\u53d6\u4fee\u6539\u7684CL<\/h2>\n<p>\u4ecegithub\u9009\u53d6\u4e00\u4e2aIssue\u8fdb\u884c\u4fee\u6539\u3002<\/p>\n<p>\u63a8\u8350\u65b0\u624b\u4ece\u201cgood first issue&quot; \u5f00\u59cb\u3002<\/p>\n<p>\u4e5f\u53ef\u4ee5\u901a\u8fc7sig\u6216\u8005kind\u6807\u7b7e\u8fc7\u6ee4\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes\/kubernetes\/issues?q=is%3Aopen&#43;is%3Aissue&#43;label%3A%22good&#43;first&#43;issue%22\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes\/kubernetes\/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22<\/a><\/p>\n<h2 id=\"\u63d0\u4ea4patch\">\u63d0\u4ea4patch<\/h2>\n<p>github\u7528\u6237\u76f4\u63a5fork\u5230\u81ea\u5df1\u8d26\u53f7\uff0cclone\u4e0b\u6765\u5373\u53ef\u3002<\/p>\n<pre><code>git clone https:\/\/github.com\/kubernetes\/kubernetes.git\n<\/code><\/pre>\n<p>\u521b\u5efa\u5f00\u53d1\u5206\u652f\u5e76\u4fee\u6539\u4ee3\u7801<\/p>\n<pre><code>git checkout -b canux_dev\n...\ngit add -A\ngit commit -m &quot;...&quot;\ngit push ...\n<\/code><\/pre>\n<h2 id=\"code-review\">code review<\/h2>\n<p>\u63d0\u4ea4\u4e4b\u540etrybots\u4f1a\u81ea\u52a8\u6784\u5efa\uff0c\u53ef\u4ee5\u901a\u8fc7build dashboard\u67e5\u770b\u5404\u4e2a\u5e73\u53f0build\u7ed3\u679c:<\/p>\n<p><a class=\"link\" href=\"https:\/\/build.golang.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/build.golang.org\/<\/a><\/p>\n<p>\u67e5\u770b\u81ea\u5df1\u7684patch\u7684review\u60c5\u51b5\uff1a<\/p>\n<p><a class=\"link\" href=\"https:\/\/go-review.googlesource.com\/dashboard\/self\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/go-review.googlesource.com\/dashboard\/self<\/a><\/p>\n<p>\u663e\u793a\u968f\u65f6\u95f4\u53d8\u5316\u7684\u5386\u53f2\u6d4b\u8bd5\u7ed3\u679c\uff1a<\/p>\n<p><a class=\"link\" href=\"https:\/\/testgrid.k8s.io\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/testgrid.k8s.io\/<\/a><\/p>\n<p>\u663e\u793apow\u4e2d\u7684\u81ea\u52a8\u5316\u6d4b\u8bd5\u60c5\u51b5\uff1a<\/p>\n<p><a class=\"link\" href=\"https:\/\/prow.k8s.io\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/prow.k8s.io\/<\/a><\/p>\n<p>\u67e5\u770b\u6240\u6709PR:<\/p>\n<p><a class=\"link\" href=\"https:\/\/gubernator.k8s.io\/pr\/all\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/gubernator.k8s.io\/pr\/all<\/a><\/p>\n<p>\u628a\u76f8\u4f3c\u7684\u5931\u8d25\u805a\u5408\u5728\u4e00\u8d77\u4ee5\u4fbf\u6392\u9664\u6545\u969c:<\/p>\n<p><a class=\"link\" href=\"https:\/\/storage.googleapis.com\/k8s-triage\/index.html\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/storage.googleapis.com\/k8s-triage\/index.html<\/a><\/p>"},{"title":"K8S API","link":"https:\/\/canuxcheng.com\/post\/k8s_api\/","pubDate":"Fri, 10 Jan 2020 20:55:52 +0800","guid":"https:\/\/canuxcheng.com\/post\/k8s_api\/","description":"<h1 id=\"api\">API<\/h1>\n<p>api-server\u7edf\u4e00\u7684\u64cd\u4f5c\u5165\u53e3.<\/p>\n<p>kubectl, UI, \u7b49\u90fd\u662f\u901a\u8fc7api-server\u64cd\u4f5c\u8d44\u6e90.<\/p>\n<p>payload\u53ef\u4ee5\u662fjson\uff0c\u4e5f\u53ef\u4ee5\u662fyaml.<\/p>\n<p>yaml\u6587\u4ef6\u4e2d#\u8868\u793a\u884c\u6ce8\u91ca\u3002<\/p>\n<hr>\n<h2 id=\"yaml\">yaml<\/h2>\n<p>\u90e8\u7f72k8s\u53ef\u4ee5\u901a\u8fc7yaml\u6587\u4ef6\u6765\u914d\u7f6e\u8d44\u6e90.<\/p>\n<p>\u8d44\u6e90\u5bf9\u8c61\u7ec4\u6210\u90e8\u5206:<\/p>\n<pre><code>apiVersion:\nkind:\nmetadata: \u5143\u6570\u636e\nspec: \u671f\u671b\u7684\u72b6\u6001\nstatus: \u89c2\u6d4b\u5230\u7684\u72b6\u6001\n<\/code><\/pre>\n<p>\u67e5\u770bapiVersion:<\/p>\n<pre><code>kubectl api-versions\n<\/code><\/pre>\n<p>\u67e5\u770bKind:<\/p>\n<pre><code>kubectl api-resources\n# In a namespace\nkubectl api-resources --namespaced=true\n# Not in a namespace\nkubectl api-resources --namespaced=false\n<\/code><\/pre>\n<p>metadata:<\/p>\n<pre><code>metadata:\nname:\nnamespace:\nlabels\/\u6807\u7b7e: \u7528\u6237\u7b5b\u9009\u8d44\u6e90\uff0c\u552f\u4e00\u7684\u8d44\u6e90\u7ec4\u5408\u65b9\u6cd5, \u53ef\u4ee5\u4f7f\u7528selector\u6765\u67e5\u8be2.\nannotations\/\u6ce8\u89e3: \u5b58\u50a8\u8d44\u6e90\u7684\u975e\u6807\u8bc6\u6027\u4fe1\u606f\uff0c\u6269\u5c55\u8d44\u6e90\u7684spec\/status.\nownerReference\/\u5173\u7cfb: \u65b9\u4fbf\u53cd\u5411\u67e5\u627e\u521b\u5efa\u8d44\u6e90\u7684\u5bf9\u8c61\uff0c\u65b9\u4fbf\u8fdb\u884c\u7ea7\u8054\u5220\u9664\u3002\n<\/code><\/pre>\n<p>spec:<\/p>\n<p>status:<\/p>\n<hr>\n<h2 id=\"\u8c03\u5ea6\u62a2\u5360\u9a71\u9010\">\u8c03\u5ea6\uff0c\u62a2\u5360\uff0c\u9a71\u9010<\/h2>\n<p>taints: \u6c61\u70b9\uff0c\u4f7f\u8282\u70b9\u6392\u65a5\u7279\u5b9apod\u3002\u5e94\u7528\u4e8enode\u3002\u52a0\u4e86tolerations\u6216\u8005affinity\u7684pod\u624d\u80fd\u8c03\u5ea6\u8fc7\u6765\u3002<\/p>\n<pre><code>taints:\n- effect: NoSchedule\nkey: kubernetes.io\/arch\nvalue: arm64\n<\/code><\/pre>\n<p>tolerations: \u5bb9\u5fcd\u5ea6\uff0c\u4f7fpod\u80fd\u5bb9\u5fcd\u52a0\u4e86traints\u7684\u8282\u70b9\u3002\u5e94\u7528\u4e8epod\u3002\n\u8fd9\u4e2a\u53ea\u80fd\u8ba9pod\u80fd\u90e8\u7f72\u5230\u52a0\u4e86\u6c61\u70b9\u7684node\uff0cpod\u4e5f\u80fd\u90e8\u7f72\u5230\u5176\u5b83\u6ca1\u6709\u52a0\u6c61\u70b9\u7684node\u3002<\/p>\n<pre><code>tolerations:\n- key: &quot;kubernetes.io\/arch&quot;\noperator: &quot;Equal&quot;\/&quot;Exists&quot;\nvalue: &quot;arm64&quot;\neffect: &quot;NoSchedule&quot;\/&quot;NoExecute&quot;\n<\/code><\/pre>\n<p>nodeAffinity: \u8282\u70b9\u4eb2\u548c\u6027\uff0c\u6307\u5b9apod\u53ea\u80fd\u8c03\u5ea6\u5230\u7279\u5b9anode\u4e0a\u3002\u5e94\u7528\u4e8epod\u3002<\/p>\n<pre><code> affinity:\nnodeAffinity:\nrequiredDuringSchedulingIgnoredDuringExecution:\nnodeSelectorTerms:\n- matchExpressions:\n- key: kubernetes.io\/arch\noperator: In\nvalues:\n- arm64\n<\/code><\/pre>\n<p>podAffinity: pod\u4eb2\u548c\u6027\uff0c\u6307\u5b9apod\u53ea\u80fd\u8c03\u5ea6\u5230\u7279\u5b9anode\u4e0a\u3002\u5e94\u7528\u4e8epod\u3002\u5e0c\u671b\u53ef\u4ee5\u548c\u5176\u5b83pod\u8c03\u5ea6\u5230\u540c\u4e00\u4e2anode\u4e0a\u3002<\/p>\n<pre><code> affinity:\npodAffinity:\nrequiredDuringSchedulingIgnoredDuringExecution:\nlabelSelector:\nmatchExpressions:\n- key: app\noperator: In\nvalues:\n- nginx\ntopologyKey: kubernetes.io\/hostname\n<\/code><\/pre>\n<p>podAntiAffinity: pod\u53cd\u4eb2\u548c\u6027\uff0c\u6307\u5b9apod\u4e0d\u80fd\u8c03\u5ea6\u5230\u7279\u5b9anode\u4e0a\u3002\u5e94\u7528\u4e8epod\u3002\u4e0d\u5e0c\u671b\u548c\u5176\u5b83pod\u8c03\u5ea6\u5230\u540c\u4e00\u4e2anode\u4e0a\u3002<\/p>\n<pre><code> affinity:\npodAntiAffinity:\nrequiredDuringSchedulingIgnoredDuringExecution:\nlabelSelector:\nmatchExpressions:\n- key: app\noperator: In\nvalues:\n- nginx\ntopologyKey: kubernetes.io\/hostname\n<\/code><\/pre>\n<p>nodeSelector: \u8282\u70b9\u9009\u62e9\uff0cpod\u53ea\u80fd\u8c03\u5ea6\u5230\u7279\u5b9a\u8282\u70b9\u3002<\/p>\n<pre><code> nodeSelector:\nkubernetes.io\/arch: arm64\n<\/code><\/pre>\n<h2 id=\"\u5b89\u5168\">\u5b89\u5168<\/h2>\n<p>securityContext\u7528\u6765\u914d\u7f6e Pod \u6216 \u5bb9\u5668 \u8fd0\u884c\u65f6\u7684\u5b89\u5168\u6027\u8bbe\u7f6e\u7684\u5b57\u6bb5\uff0c\u5b83\u80fd\u9650\u5236\u5bb9\u5668\u7684\u6743\u9650\u3001\u7528\u6237\u8eab\u4efd\u3001\u6587\u4ef6\u7cfb\u7edf\u8bbf\u95ee\u7b49\uff0c\u4ece\u800c\u964d\u4f4e\u5bb9\u5668\u88ab\u653b\u51fb\u540e\u9020\u6210\u7684\u7834\u574f\u8303\u56f4\u3002\u5bb9\u5668\u7ea7\u522b\u4f18\u5148\u7ea7\u9ad8\u4e8e Pod \u7ea7\u522b\u3002<\/p>\n<pre><code>securityContext:\nrunAsUser: 1000\nrunAsGroup: 3000\nfsGroup: 2000\nallowPrivilegeEscalation: false\ncapabilities:\ndrop:\n- ALL\nadd:\n- NET_ADMIN\n<\/code><\/pre>\n<hr>\n<h1 id=\"pod\">Pod<\/h1>\n<p>pod\u6a21\u677f\uff0c \u901a\u5e38\u4f7f\u7528deployment, job\u548cstatefulset, daemonset\u6765\u7ba1\u7406pod.<\/p>\n<pre><code>\/\/ kubectl explain pod.spec\napiVersion: v1\nkind: Pod\nmetadata:\nname: test\nnamespace: test\nlabels:\napp: test\nspec:\n\/\/\/\/ containers\nos: \/\/ \u64cd\u4f5c\u7cfb\u7edf\u6a21\u677f\nname:\nimagePullSecrets: \/\/ \u79c1\u6709\u955c\u50cf\u6388\u6743\n- name: my-harbor\ninitContainers: \/\/ initcontainer\u6a21\u677f\n- name: init\nimage: my-image\ncommand: ...\nargs: ...\ncontainers: \/\/ container \u6a21\u677f\n- name: test\n\/\/ image\nimage: image\nimagePullPolicy: Always\/IfNotPresent\/Never\n\/\/ entrypoint\ncommand:\nargs:\nworkingDir:\n\/\/ port\nports:\n\/\/ resources\nresources:\nrequests: \/\/ \u7533\u660e\u9700\u8981\u7684\u8d44\u6e90\nmemory: &quot;64Mi&quot; \/\/ byte\ncpu: &quot;250m&quot; \/\/ millicore (1 core = 1000 millicore)\nephemeral-storage: &quot;2Gi&quot; \/\/ byte\nlimits:\nmemory: &quot;128Mi&quot;\ncpu: &quot;500m&quot;\nephemeral-storage: &quot;4Gi&quot;\n\/\/ environment variables, \u9488\u5bf9\u5355\u4e2a\u952e\u503c\u5bf9.\nenv:\n- name: key\nvalue: value\n- name: key\nvalueFrom: \/\/ \u5c06cm-name\u4e2d\u7684\u503ccm-key\u4f20\u7ed9key\nconfigMapKeyRef:\nname: cm-name\nkey: cm-key\noptional:\n- name: key\nvalueFrom: \/\/ \u6302\u8f7dsecret\nsecretKeyRef:\nkey:\nname:\noptional:\nfieldRef:\nresourceFieldRef:\n\/\/ \u73af\u5883\u53d8\u91cf\uff0c\u9488\u5bf9\u6587\u4ef6\u4e2d\u6240\u6709\u952e\u503c\u5bf9.\nenvFrom:\n- configMapRef \/\/ \u5c06my-cm\u4e2d\u7684\u6240\u6709\u952e\u503c\u5bf9\u53d8\u6210\u73af\u5883\u53d8\u91cf.\nname: my-cm\noptional:\n- secretRef\nname:\noptional:\n\/\/ volumeMounts (\u53bbVolume\u627e\u5bf9\u5e94\u8d44\u6e90)\n\/\/ \u5982\u679c\u6ca1\u6709subpath\uff0c\u6574\u4e2a\u76ee\u5f55\u4f1a\u88ab\u8986\u76d6\uff0c\u76ee\u5f55\u4e0b\u53ea\u6709secret\/configmap\u6302\u8f7d\u7684\u6587\u4ef6.\nvolumeMounts: \/\/ secret\u4ee5\u6587\u4ef6\u5f62\u5f0f\u6302\u8f7d\u5230\/etc\/foo\n- name: my-secret\nmountPath: &quot;\/etc\/foo&quot; \/\/ \u6302\u8f7d\u4e4b\u540e\u8986\u76d6\u6574\u4e2a\u76ee\u5f55\nreadOnly: true\n- name: my-configmap\nmountPath: &quot;\/etc\/bar&quot; \/\/ \u6302\u8f7d\u4e4b\u540e\u8986\u76d6\u6574\u4e2a\u76ee\u5f55\n\/\/ \u5982\u679c\u6709subpath, secret\/configmap\u91cc\u7684data\u91cc\u7684\u6587\u4ef6\u540d\u9700\u8981\u4e0esubpath\u548cmountpath\u6307\u5b9a\u7684\u6587\u4ef6\u540d\u4e00\u81f4.\n- name: config\nmountPath: \/etc\/app\/app.conf \/\/ \u662f\u6587\u4ef6\uff0c\u6587\u4ef6\u540d\u8981\u548csubpath\u4e00\u81f4\u3002\nsubPath: app.conf \/\/ \u6302\u8f7d\u4e4b\u540e\u53ea\u8986\u76d6\u76ee\u5f55\u4e2d\u540c\u540d\u6587\u4ef6,\u5176\u5b83\u6587\u4ef6\u4e0d\u5f71\u54cd.\n\/\/ lifecycle\nlivenessProbe:\ninitialDelaySeconds: 10\nperiodSeconds: 10\ntimeoutSeconds: 5\nhttpGet:\npath: \/admin\nport: django\n# httpHeaders:\n# - name: Authorization\n# value: Basic $LDAP_ACCOUNT\nreadinessProbe:\ninitialDelaySeconds: 10\nperiodSeconds: 10\ntimeoutSeconds: 5\nhttpGet:\npath: \/admin\nport: django\n# httpHeaders:\n# - name: Authorization\n# value: Basic $LDAP_ACCOUNT\n\/\/ securityContext\nsecurityContext:\n\/\/ debugging\nstdin: false\nstdinOnce: false\ntty: false\n\/\/\/\/ security context\nsecurityContext: \/\/ pod\u7ea7\u522bsecurity context\u5b9a\u4e49\nrunAsuser: 1000\nrunAsGroup: 3000\nfsGroup: 2000\n\/\/\/\/ volumes\nvolumes:\n- name: my-secret \/\/ \u6307\u5b9a\u8981\u6302\u8f7d\u7684secret\nsecret:\nsecretName: mysecret\n- name: my-configmap\nconfigMap:\nname: myconfigmap\n\/\/\/\/ lifecycle\nrestartPolicy:\n\/\/\/\/ scheduling\nnodeName:\nnodeSelector: \/\/ \u5c06pod\u90e8\u7f72\u5230\u6307\u5b9anode\nkey: value\naffinity:\ntolerations:\n\/\/\/\/ others\nhostname:\nhostNetwork:\nserviceAccountName:\n<\/code><\/pre>\n<p>pod\u4e2d\u7684container\u5171\u4eab\u5b58\u50a8(pod volume):<\/p>\n<pre><code>apiVersion: v1\nKind: Pod\nmedadata:\nspec:\n# \u4e24\u79cdpod volume\nvolumes:\n# emptyDir\uff1a pod\u5220\u9664\u4e4b\u540e\u8be5\u76ee\u5f55\u4e5f\u4f1a\u88ab\u5220\u9664\n- name: cache-volume\nemptyDir: {}\n# hostPath: pod\u5220\u9664\u4e4b\u540e\u8be5\u76ee\u5f55\u8fd8\u5728host\u4e0a.\n- name: hostpath-volume\nhostPath:\npath: \/path\/on\/host\ncontainers:\n- name: container1\nimage: test\nvolumeMounts:\n- name: cache-volume\nmountpath: \/path\/on\/container\n# subPath\u4f1a\u5728emptyDir\u6216hostPath\u76ee\u5f55\u4e0b\u521b\u5efa\u5b50\u76ee\u5f55\nsubPath: cache1\n- name: container2\nimage: test\nvolumeMounts:\n- name: hostpath-volume\nmountpath: \/path\/on\/container\nreadOnly: true\n<\/code><\/pre>\n<hr>\n<h1 id=\"deployment\">Deployment<\/h1>\n<p>\u7528\u4e8e\u90e8\u7f72\u65e0\u72b6\u6001\u670d\u52a1\u3002<\/p>\n<pre><code>apiVersion: apps\/v1\nkind: Deployment\nmetadata:\nname: my-app-deploy\nnamespace: my-ns\nlables:\napp: my-app\nspec:\nreplicas: 3\n# \u9009\u62e9\u5668\nselector:\nmatchLabels:\napp: my-app\ntemplate:\nmetadata:\nlabels:\napp: my-app\nspec:\ncontainers:\n- name: my-app\nimage: image:latest\nimagePullPolicy: IfNotPresent\/Always\nports:\n- containerPort: 443\nvolumeMounts:\n- name: my-hostpath\nmountPath: \/path\/on\/cpod\n- name: my-pvc\nmountPath: \/data\nvolumes:\n- name: my-hostpath\nhostPath:\npath: \/path\/on\/host\n- name: my-pvc\npersistentVolumeClaim:\nclaimName: nfs-pvc\n<\/code><\/pre>\n<hr>\n<h1 id=\"daemonset\">DaemonSet<\/h1>\n<p>\u6bcf\u4e2anode\u4e0a\u90e8\u7f72\u4e00\u4e2astageless pod\uff0c\u7528\u4e8e\u90e8\u7f72agent\u3002<\/p>\n<p>DaemonSet<\/p>\n<pre><code>apiVersion: apps\/v1\nkind: DaemonSet\nmetadata:\nname: my-ds\nnamespace: my-ns\nlabels:\nk8s-app: my-app\nspec:\nselector:\nmatchLabels:\nname: my-app\ntemplate:\nmetadata:\nlabels:\nname: my-app\nspec:\ncontainers:\n- name: my-container\nimage: my-img\n<\/code><\/pre>\n<hr>\n<h1 id=\"statefulset\">StatefulSet<\/h1>\n<p>\u7528\u4e8e\u90e8\u7f72\u6709\u72b6\u6001\u670d\u52a1\u3002<\/p>\n<p>StatefulSet \u4e2d\u7684 Pod \u62e5\u6709\u4e00\u4e2a\u552f\u4e00\u7684\u987a\u5e8f\u7d22\u5f15\u548c\u7a33\u5b9a\u7684\u7f51\u7edc\u8eab\u4efd\u6807\u8bc6\u3002<\/p>\n<pre><code>apiVersion: apps\/v1\nkind: StatefulSet\nmetadata:\nname: web\nnamespace: test\nlabels:\nk8s-app: my-app\nspec:\nserviceName: &quot;nginx&quot;\nreplicas: 2\nselector:\nmatchLabels:\napp: nginx\ntemplate:\nmetadata:\nlabels:\napp: nginx\nspec:\ncontainers:\n- name: nginx\nimage: k8s.gcr.io\/nginx-slim:0.8\nports:\n- containerPort: 80\nname: web\nvolumeMounts:\n- name: www\nmountPath: \/usr\/share\/nginx\/html\nvolumeClaimTemplates:\n- metadata:\nname: www\nspec:\naccessModes: [ &quot;ReadWriteOnce&quot; ]\nresources:\nrequests:\nstorage: 1Gi\n<\/code><\/pre>\n<hr>\n<h1 id=\"job\">Job<\/h1>\n<p>Job<\/p>\n<pre><code>appVersion: batch\/v1\nkind: Job\nmetadata:\nname: my-job\nspec:\n# \u4ee3\u8868\u672cpod\u961f\u5217\u6267\u884c\u6b64\u6b21\u6570(\u88ab\u6267\u884c8\u6b21)\ncompletions: 8\n# \u4ee3\u8868\u5e76\u884c\u6267\u884c\u4e2a\u6570(\u540c\u65f6\u6709\u4e24\u4e2a\u5728\u8fd0\u884c)\nparallelism: 2\nbackoffLimit: 4\ntemplate:\nspec:\ncontainers:\n- name: my-job\nimage: my-image\nconmand: ['test']\nrestartPolicy: Never\n<\/code><\/pre>\n<hr>\n<h1 id=\"cronjob\">CronJob<\/h1>\n<p>CronJob<\/p>\n<pre><code>apiVersion: batch\/v1\nkind: CronJob\nmetadata:\nname: my-cj\nspec:\nschedule: &quot;* * * * *&quot;\nstartingDeadlineSeconds: None(default)\/10\nconcurrencyPolicy: Allow(default)\/Forbid\/Replace\nsuspend: false(default)\/true\nsuccessfulJobsHistoryLimit: 3(default)\nfailedJobsHistoryLimit: 1(default)\njobTemplate:\nspec:\ntemplate:\nmetadata:\nannotations: ...\nlabels: ...\nspec:\nnodeSelector:\n...\nimagePullSecrets:\n...\nrestartPolicy: OnFailure\ncontainers:\n- name: image\nimage: image\nargs:\n- \/bin\/sh\n- -c\n- date\n<\/code><\/pre>\n<hr>\n<h1 id=\"configmap\">ConfigMap<\/h1>\n<p>configmap\u53ea\u80fd\u5728\u5f53\u524dnamespace\u4f7f\u7528.<\/p>\n<p>configmap\u7684\u914d\u7f6e\u5728pod\u4e2d\u65e0\u6cd5\u4fee\u6539\u7ed1\u5b9a\u7684\u6587\u4ef6.<\/p>\n<p>data\u91cc\u9762\u7684\u6587\u4ef6\u540d\u5c31\u662f\u6302\u8f7d\u4e4b\u540e\u7684\u6587\u4ef6\u540d\u3002<\/p>\n<p>ConfigMap<\/p>\n<pre><code>apiVersion: v1\nkind: ConfigMap\nmetadata:\nlabels:\napp: flanel\ntier: node\nname: flannel-cfg\nnamespace: kube-system\ndata:\ncni-conf.json: |\n{\n&quot;name&quot;: &quot;n1&quot;\n}\n<\/code><\/pre>\n<p>\u521b\u5efa\u914d\u7f6e\u6587\u4ef6\u7684configmap<\/p>\n<pre><code>$ kubectl -n app create cm my-conf --from-file .\/config.ini -o yaml &gt; myconf-configmap.yaml\n$ kubectl -n influxdata create cm dashboard-docker --from-file Docker.json -o yaml &gt; grafana-dashboard-docker-configmap.yaml\n<\/code><\/pre>\n<hr>\n<h1 id=\"secret\">Secret<\/h1>\n<p>secret\u53ea\u80fd\u5728\u5f53\u524dnamespace\u4f7f\u7528.<\/p>\n<p>data\u91cc\u7684\u6587\u4ef6\u540d\u5c31\u662f\u6302\u8f7d\u4e4b\u540e\u7684\u6587\u4ef6\u540d\u3002<\/p>\n<p>Opaque\u662f\u7528\u6237\u81ea\u5b9a\u4e49\u683c\u5f0f<\/p>\n<p>generic secret<\/p>\n<pre><code>kubectl create secret generic empty-secret\napiVersion: v1\nkind: Secret\ntype: Opaque\nmetadata:\nname: mysecret\nnamespace: kube-system\ndata:\nusername: name\npassword: pw\n<\/code><\/pre>\n<p>\u521b\u5efatls secret\u8d26\u53f7:<\/p>\n<pre><code>kubectl -n kubernetes-dashboard create secret tls \\\nkubernetes-dashboard-tls --key ca.key --cert ca.crt\n<\/code><\/pre>\n<p>\u7c7b\u578b\u4e3a kubernetes.io\/tls \u7684 Secret \u4e2d\u5305\u542b\u5bc6\u94a5\u548c\u8bc1\u4e66\u7684 DER \u6570\u636e\uff0c\u4ee5 Base64 \u683c\u5f0f\u7f16\u7801\u3002 \u5982\u679c\u4f60\u719f\u6089\u79c1\u94a5\u548c\u8bc1\u4e66\u7684 PEM \u683c\u5f0f\uff0cbase64 \u4e0e\u8be5\u683c\u5f0f\u76f8\u540c\uff0c\u53ea\u662f\u4f60\u9700\u8981\u7565\u8fc7 PEM \u6570\u636e\u4e2d\u6240\u5305\u542b\u7684\u7b2c\u4e00\u884c\u548c\u6700\u540e\u4e00\u884c\u3002<\/p>\n<pre><code>apiVersion: v1\nkind: Secret\nmetadata:\nname: secret-tls\ntype: kubernetes.io\/tls\ndata:\ntls.crt: |\nMIIC2DCCAcCgAwIBAgIBATANBgkqh ...\ntls.key: |\nMIIEpgIBAAKCAQEA7yn3bRHQ5FHMQ ...\n<\/code><\/pre>\n<p>\u521b\u5efadocker secret:<\/p>\n<p>kubernetes.io\/dockercfg ~\/.dockercfg \u6587\u4ef6\u7684\u5e8f\u5217\u5316\u5f62\u5f0f<\/p>\n<p>kubernetes.io\/dockerconfigjson ~\/.docker\/config.json \u6587\u4ef6\u7684\u5e8f\u5217\u5316\u5f62\u5f0f<\/p>\n<p>\u7ed9\u4e00\u4e2aprivate registry\u521b\u5efasecret:<\/p>\n<pre><code>$ kubectl -n ns create secret docker-registry &lt;name&gt; \\\n--docker-server=https:\/\/harbor.domain.com --docker-username=user --docker-password=pw --docker-email=canuxcheng@gmail.com\n<\/code><\/pre>\n<p>\u6839\u636e\u672c\u5730\u7684\u6587\u4ef6\u521b\u5efasecret\uff08\u5982\u679c\u9700\u8981\u591a\u4e2aregistry\uff0c\u53ef\u4ee5\u5148\u5728\u672c\u5730\u767b\u9646\uff09<\/p>\n<pre><code>$ kubectl -n ns create secret generic regcred \\\n--from-file=.dockerconfigjson=$HOME\/.docker\/config.json \\\n--type=kubernetes.io\/dockerconfigjson\napiVersion: v1\nkind: Secret\nmetadata:\nname: artifactory-cred\nnamespace: ...\ntype: kubernetes.io\/dockerconfigjson\ndata:\n.dockerconfigjson: ewoJImF1d......\n<\/code><\/pre>\n<hr>\n<h1 id=\"service\">Service<\/h1>\n<pre><code>apiVersion: v1\nkind: Service\nmetadata:\nname: grafana-service\nnamespace: influxdata\nspec:\ntype: NodePort\nports:\n- name: https\nport: 3000 \/\/ \u96c6\u7fa4\u5185\u90e8\u8bbf\u95ee\u7684port.\ntargetPort: 3000 \/\/ pod\u6307\u5b9a\u7684port.\nnodePort: 32000 \/\/ \u96c6\u7fa4\u5916\u90e8\u8bbf\u95ee\u5185\u90e8service\u7684port.\nselector: \/\/ \u5339\u914d\u8d44\u6e90\u7684metadata.labels\napp: grafana\n<\/code><\/pre>\n<h2 id=\"externalname-service\">ExternalName Service<\/h2>\n<p>ExternalName Service \u662f Service \u7684\u7279\u4f8b\uff0c\u5b83\u6ca1\u6709\u9009\u62e9\u7b97\u7b26\uff0c\u4f46\u662f\u4f7f\u7528 DNS \u540d\u79f0, \u5c06\u670d\u52a1\u6620\u5c04\u5230 DNS \u540d\u79f0\uff0c\u800c\u4e0d\u662fselector.<\/p>\n<p>\u8bbf\u95ee\u5176\u5b83namespace\u7684service.<\/p>\n<p>\u5f53\u67e5\u627e\u4e3b\u673a\u00a0my-service.my-ns.svc.cluster.local\u00a0\u65f6\uff0c\u96c6\u7fa4 DNS \u670d\u52a1\u8fd4\u56de\u00a0CNAME\u00a0\u8bb0\u5f55\uff0c \u5176\u503c\u4e3a\u00a0out-service.out-ns.svc.cluster.local\u3002\n\u8bbf\u95ee\u00a0my-service\u00a0\u7684\u65b9\u5f0f\u4e0e\u5176\u4ed6\u670d\u52a1\u7684\u65b9\u5f0f\u76f8\u540c\uff0c\u4f46\u4e3b\u8981\u533a\u522b\u5728\u4e8e\u91cd\u5b9a\u5411\u53d1\u751f\u5728 DNS \u7ea7\u522b\uff0c\u800c\u4e0d\u662f\u901a\u8fc7\u4ee3\u7406\u6216\u8f6c\u53d1<\/p>\n<pre><code>apiVersion: v1\nkind: Service\nmetadata:\nname: my-service\nnamespace: my-ns\nspec:\ntype: ExternalName\nexternalName: out-service.out-ns.svc.cluster.local \/\/ \u6307\u5411\u5176\u5b83namespace\u7684service.\n<\/code><\/pre>\n<h2 id=\"endpoint\">Endpoint<\/h2>\n<p>\u4e0b\u9762\u573a\u666f\u53ef\u4ee5\u4f7f\u7528Endpoint.<\/p>\n<ol>\n<li>\u5e0c\u671b\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u4f7f\u7528\u5916\u90e8\u7684\u6570\u636e\u5e93\u96c6\u7fa4\uff0c\u4f46\u6d4b\u8bd5\u73af\u5883\u4f7f\u7528\u81ea\u5df1\u7684\u6570\u636e\u5e93\u3002<\/li>\n<li>\u5e0c\u671b\u670d\u52a1\u6307\u5411\u53e6\u4e00\u4e2a\u00a0\u547d\u540d\u7a7a\u95f4\u00a0\u4e2d\u6216\u5176\u5b83\u96c6\u7fa4\u4e2d\u7684\u670d\u52a1\u3002<\/li>\n<li>\u60a8\u6b63\u5728\u5c06\u5de5\u4f5c\u8d1f\u8f7d\u8fc1\u79fb\u5230 Kubernetes\u3002 \u5728\u8bc4\u4f30\u8be5\u65b9\u6cd5\u65f6\uff0c\u60a8\u4ec5\u5728 Kubernetes \u4e2d\u8fd0\u884c\u4e00\u90e8\u5206\u540e\u7aef\u3002<\/li>\n<\/ol>\n<p>\u5148\u521b\u5efaservice:<\/p>\n<pre><code>apiVersion: v1\nkind: Service\nmetadata:\nname: mysql-service\nnamespace: influxdata\nspec:\nports:\n- protocol: TCP\nport: 3306\ntargetPort: 3306\n<\/code><\/pre>\n<p>\u518d\u521b\u5efaendpoint\uff1a<\/p>\n<pre><code>apiVersion: v1\nkind: Endpoints\nmetadata:\nname: mysql-service\nnamespace: influxdata\nsubsets:\n- addresses:\n- ip: 10.103.X.X \/\/ \u6307\u5411\u5916\u90e8\u670d\u52a1\u7684IP\nports:\n- port: 3306\n<\/code><\/pre>\n<hr>\n<h1 id=\"hpa\">HPA<\/h1>\n<p>Horizontal Pod Autoscaler, \u6a2a\u5411\u4f38\u7f29\u3002<\/p>\n<pre><code>apiVersion: autoscaling\/v2beta2\nkind: HorizontalPodAutoscaler\nmetadata:\nname:\nlabels:\nspec:\nscaleTargetRef:\napiVersion: apps\/v1\nkind: Deployment\nname: d-name\nminReplicas: 2\nmaxReplicas: 20\nmetrics:\n- type: Resource\nresource:\nname: cpu\ntargetAverageUtilization: 80\n- type: Resource\nresource:\nname: memory\ntargetAverageUtilization: 80\n<\/code><\/pre>\n<hr>\n<h1 id=\"authentication\">Authentication<\/h1>\n<p>\u9ed8\u8ba4\u7684ClusterRole\u548cClusterRoleBinding\u5927\u90e8\u5206\u662fsystem:\u5f00\u5934\u3002<\/p>\n<h2 id=\"serviceaccont\">ServiceAccont<\/h2>\n<p>\u670d\u52a1\u8d26\u6237\u662f\u5728\u5177\u4f53\u540d\u5b57\u7a7a\u95f4\u7684\u3002<\/p>\n<pre><code>apiVersion: v1\nkind: ServiceAccount\nmetadata:\nname: default\nnamespace: default\n<\/code><\/pre>\n<p>1.22\u4e4b\u524dk8s\u4f1a\u81ea\u52a8\u7ed9SA\u521b\u5efatoken.<\/p>\n<p>1.24\u4e4b\u540e\u4f7f\u7528TokenRequest\u83b7\u53d6\u6709\u65f6\u95f4\u9650\u5236\u7684token\u3002<\/p>\n<p>\u521b\u5efa\u6301\u4e45\u5316token<\/p>\n<pre><code>apiVersion: v1\nkind: Secret\ntype: kubernetes.io\/service-account-token\nmetadata:\nname: mysecretname\nannotations:\nkubernetes.io\/service-account.name: myserviceaccount\n<\/code><\/pre>\n<h2 id=\"role\">Role<\/h2>\n<p>\u901a\u8fc7role\u6765\u7ed9\u6307\u5b9ans\u5185\u7684\u8d44\u6e90\u6388\u6743.<\/p>\n<pre><code>apiVersion: rbac.authorization.k8s.io\/v1\nkind: Role\nmetadata:\nnamespace: default\nname: pod-reader\nrules:\n- apiGroups: [&quot;&quot;] # &quot;&quot; \u6807\u660e core API \u7ec4\nresources: [&quot;pods&quot;]\nverbs: [&quot;get&quot;, &quot;watch&quot;, &quot;list&quot;]\n<\/code><\/pre>\n<h2 id=\"rolebinding\">RoleBinding<\/h2>\n<p>\u5c06role\u6216clusterrole\u6743\u9650\u8d4b\u4e88\u5177\u4f53\u7684\u89d2\u8272.<\/p>\n<pre><code>apiVersion: rbac.authorization.k8s.io\/v1\n# \u6b64\u89d2\u8272\u7ed1\u5b9a\u5141\u8bb8 &quot;jane&quot; \u8bfb\u53d6 &quot;default&quot; \u540d\u5b57\u7a7a\u95f4\u4e2d\u7684 Pods\nkind: RoleBinding\nmetadata:\nname: read-pods\nnamespace: default\nsubjects:\n# \u4f60\u53ef\u4ee5\u6307\u5b9a\u4e0d\u6b62\u4e00\u4e2a\u201csubject\uff08\u4e3b\u4f53\uff09\u201d\n- kind: User\nname: jane # &quot;name&quot; \u662f\u533a\u5206\u5927\u5c0f\u5199\u7684\napiGroup: rbac.authorization.k8s.io\nroleRef:\n# &quot;roleRef&quot; \u6307\u5b9a\u4e0e\u67d0 Role \u6216 ClusterRole \u7684\u7ed1\u5b9a\u5173\u7cfb\nkind: Role # \u6b64\u5b57\u6bb5\u5fc5\u987b\u662f Role \u6216 ClusterRole\nname: pod-reader # \u6b64\u5b57\u6bb5\u5fc5\u987b\u4e0e\u4f60\u8981\u7ed1\u5b9a\u7684 Role \u6216 ClusterRole \u7684\u540d\u79f0\u5339\u914d\napiGroup: rbac.authorization.k8s.io\n<\/code><\/pre>\n<h2 id=\"clusterrole\">ClusterRole<\/h2>\n<p>clusterrole\u7ed9\u6574\u4e2a\u96c6\u7fa4\u6388\u6743.\u4e0d\u9700\u8981namespace.<\/p>\n<pre><code>apiVersion: rbac.authorization.k8s.io\/v1\nkind: ClusterRole\nmetadata:\n# &quot;namespace&quot; \u88ab\u5ffd\u7565\uff0c\u56e0\u4e3a ClusterRoles \u4e0d\u53d7\u540d\u5b57\u7a7a\u95f4\u9650\u5236\nname: secret-reader\nrules:\n- apiGroups: [&quot;&quot;]\n# \u5728 HTTP \u5c42\u9762\uff0c\u7528\u6765\u8bbf\u95ee Secret \u5bf9\u8c61\u7684\u8d44\u6e90\u7684\u540d\u79f0\u4e3a &quot;secrets&quot;\nresources: [&quot;secrets&quot;]\nverbs: [&quot;get&quot;, &quot;watch&quot;, &quot;list&quot;]\n<\/code><\/pre>\n<h2 id=\"clusterrolebinding\">ClusterRoleBinding<\/h2>\n<p>\u8de8\u96c6\u7fa4\u6388\u6743\uff08\u4e5f\u5c31\u662f\u8981\u8bbf\u95ee\u4e0d\u540cns\u7684\u8d44\u6e90).\u4e0d\u9700\u8981namespace.<\/p>\n<pre><code>apiVersion: rbac.authorization.k8s.io\/v1\n# \u6b64\u96c6\u7fa4\u89d2\u8272\u7ed1\u5b9a\u5141\u8bb8 \u201cmanager\u201d \u7ec4\u4e2d\u7684\u4efb\u4f55\u4eba\u8bbf\u95ee\u4efb\u4f55\u540d\u5b57\u7a7a\u95f4\u4e2d\u7684 secrets\nkind: ClusterRoleBinding\nmetadata:\nname: read-secrets-global\nsubjects:\n- kind: Group\nname: manager # 'name' \u662f\u533a\u5206\u5927\u5c0f\u5199\u7684\napiGroup: rbac.authorization.k8s.io\nroleRef:\nkind: ClusterRole\nname: secret-reader\napiGroup: rbac.authorization.k8s.io\n<\/code><\/pre>\n<hr>\n<h2 id=\"admission-controllers\">Admission Controllers<\/h2>\n<p>api access control\u662f\u901a\u8fc7Admission Controllers\u6765\u5b9e\u73b0\u7684\u3002<\/p>\n<h3 id=\"mutatingadmissionwebhook\">MutatingAdmissionWebhook<\/h3>\n<h3 id=\"validatingadmissionwebhook\">ValidatingAdmissionWebhook<\/h3>\n<h3 id=\"validatingwebhookconfiguration\">ValidatingWebhookConfiguration<\/h3>\n<pre><code>apiVersion: admissionregistration.k8s.io\/v1\nkind: ValidatingWebhookConfiguration\nmetadata:\nannotations:\nmeta.helm.sh\/release-name: ingress-nginx-internal\nmeta.helm.sh\/release-namespace: ingress-nginx\nlabels:\napp.kubernetes.io\/component: admission-webhook\napp.kubernetes.io\/instance: ingress-nginx-internal\napp.kubernetes.io\/managed-by: Helm\napp.kubernetes.io\/name: ingress-nginx\napp.kubernetes.io\/part-of: ingress-nginx\napp.kubernetes.io\/version: 1.9.1\nhelm.sh\/chart: ingress-nginx-4.8.1\nname: ingress-nginx-internal-admission\nwebhooks:\n- admissionReviewVersions:\n- v1\nclientConfig:\ncaBundle:\nservice:\nname: ingress-nginx-internal-controller-admission\nnamespace: ingress-nginx\npath: \/networking\/v1\/ingresses\nport: 443\nfailurePolicy: Fail\nmatchPolicy: Equivalent\nname: validate.nginx.ingress.kubernetes.io\nnamespaceSelector: {}\nobjectSelector: {}\nrules:\n- apiGroups:\n- networking.k8s.io\napiVersions:\n- v1\noperations:\n- CREATE\n- UPDATE\nresources:\n- ingresses\nscope: '*'\nsideEffects: None\ntimeoutSeconds: 10\n<\/code><\/pre>\n<h3 id=\"mutatingwebhookconfiguration\">MutatingWebhookConfiguration<\/h3>\n<pre><code>apiVersion: admissionregistration.k8s.io\/v1\nkind: MutatingWebhookConfiguration\nmetadata:\nannotations:\nmeta.helm.sh\/release-name: vault-secrets-webhook\nmeta.helm.sh\/release-namespace: vault-secrets-webhook\nlabels:\napp.kubernetes.io\/managed-by: Helm\nname: vault-secrets-webhook\nwebhooks:\n- admissionReviewVersions:\n- v1beta1\nclientConfig:\ncaBundle:\nservice:\nname: vault-secrets-webhook\nnamespace: vault-secrets-webhook\npath: \/pods\nport: 443\nfailurePolicy: Ignore\nmatchPolicy: Equivalent\nname: pods.vault-secrets-webhook.admission.banzaicloud.com\nnamespaceSelector:\nmatchExpressions:\n- key: name\noperator: NotIn\nvalues:\n- kube-system\n- key: kubernetes.io\/metadata.name\noperator: NotIn\nvalues:\n- kube-system\n- key: kubernetes.io\/metadata.name\noperator: NotIn\nvalues:\n- vault-secrets-webhook\nobjectSelector:\nmatchExpressions:\n- key: security.banzaicloud.io\/mutate\noperator: NotIn\nvalues:\n- skip\nreinvocationPolicy: Never\nrules:\n- apiGroups:\n- '*'\napiVersions:\n- '*'\noperations:\n- CREATE\nresources:\n- pods\nscope: '*'\nsideEffects: NoneOnDryRun\ntimeoutSeconds: 10\n- admissionReviewVersions:\n- v1beta1\nclientConfig:\ncaBundle:\nservice:\nname: vault-secrets-webhook\nnamespace: vault-secrets-webhook\npath: \/secrets\nport: 443\nfailurePolicy: Ignore\nmatchPolicy: Equivalent\nname: secrets.vault-secrets-webhook.admission.banzaicloud.com\nnamespaceSelector:\nmatchExpressions:\n- key: name\noperator: NotIn\nvalues:\n- kube-system\n- key: kubernetes.io\/metadata.name\noperator: NotIn\nvalues:\n- kube-system\n- key: kubernetes.io\/metadata.name\noperator: NotIn\nvalues:\n- vault-secrets-webhook\nobjectSelector:\nmatchExpressions:\n- key: owner\noperator: NotIn\nvalues:\n- helm\n- key: security.banzaicloud.io\/mutate\noperator: NotIn\nvalues:\n- skip\nreinvocationPolicy: Never\nrules:\n- apiGroups:\n- '*'\napiVersions:\n- '*'\noperations:\n- CREATE\n- UPDATE\nresources:\n- secrets\nscope: '*'\nsideEffects: NoneOnDryRun\ntimeoutSeconds: 10\n- admissionReviewVersions:\n- v1beta1\nclientConfig:\ncaBundle:\nservice:\nname: vault-secrets-webhook\nnamespace: vault-secrets-webhook\npath: \/configmaps\nport: 443\nfailurePolicy: Ignore\nmatchPolicy: Equivalent\nname: configmaps.vault-secrets-webhook.admission.banzaicloud.com\nnamespaceSelector:\nmatchExpressions:\n- key: name\noperator: NotIn\nvalues:\n- kube-system\n- key: kubernetes.io\/metadata.name\noperator: NotIn\nvalues:\n- kube-system\n- key: kubernetes.io\/metadata.name\noperator: NotIn\nvalues:\n- vault-secrets-webhook\nobjectSelector:\nmatchExpressions:\n- key: owner\noperator: NotIn\nvalues:\n- helm\n- key: security.banzaicloud.io\/mutate\noperator: NotIn\nvalues:\n- skip\nreinvocationPolicy: Never\nrules:\n- apiGroups:\n- '*'\napiVersions:\n- '*'\noperations:\n- CREATE\n- UPDATE\nresources:\n- configmaps\nscope: '*'\nsideEffects: NoneOnDryRun\ntimeoutSeconds: 10\n<\/code><\/pre>"},{"title":"Operator","link":"https:\/\/canuxcheng.com\/post\/k8s_operator\/","pubDate":"Fri, 10 Jan 2020 20:55:52 +0800","guid":"https:\/\/canuxcheng.com\/post\/k8s_operator\/","description":"<h1 id=\"operator\">Operator<\/h1>\n<p>TPR(Third Party Resource) \u5728k8s 1.7 \u88ab\u96c6\u6210\uff0c\u5e76\u547d\u540d\u4e3aCRD(Custom Resource Definition).<\/p>\n<p>CRD\u662fk8s\u7684\u6269\u5c55\u673a\u5236\uff0c\u5141\u8bb8\u7528\u6237\u5b9a\u4e49\u81ea\u5df1\u7684\u8d44\u6e90\u7c7b\u578b\u3002<\/p>\n<p>Custom Resource + Custom Controller = Operator.<\/p>\n<p>\u901a\u8fc7CRD\uff0cK8S\u53ef\u4ee5\u52a8\u6001\u7684\u6dfb\u52a0\u548c\u7ba1\u7406\u8d44\u6e90\uff0ccontroller\u8ddf\u8e2a\u8fd9\u4e9b\u8d44\u6e90\u3002<\/p>\n<p>\u7528\u4e8e\u5f00\u53d1operator\u7684\u5de5\u5177\u6709kubebuilder\u548coperator-sdk, \u4ed6\u4eec\u90fd\u662f\u57fa\u4e8econtroller-runtime\u5f00\u53d1.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/operator-framework\/awesome-operators\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/operator-framework\/awesome-operators<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/access.redhat.com\/documentation\/zh-cn\/openshift_container_platform\/4.2\/html\/operators\/index\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/access.redhat.com\/documentation\/zh-cn\/openshift_container_platform\/4.2\/html\/operators\/index<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/operatorhub.io\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/operatorhub.io\/<\/a><\/p>\n<p>\u5f00\u53d1\u793a\u4f8b:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes\/sample-controller\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes\/sample-controller<\/a><\/p>\n<p>Operator\u529f\u80fd\uff1a<\/p>\n<ul>\n<li>\u76d1\u63a7K8S\u8d44\u6e90\u7684\u53d8\u5316<\/li>\n<li>\u54cd\u5e94K8S\u8d44\u6e90\u7684\u53d8\u5316\uff08\u90e8\u7f72\uff0c\u5347\u7ea7\uff0c\u56de\u6eda\u7b49\uff09<\/li>\n<li>\u6267\u884cK8S\u8d44\u6e90\u7684\u53d8\u5316 \uff08\u5907\u4efd\uff0c\u6269\u5bb9\uff0c\u914d\u7f6e\u7b49\uff09<\/li>\n<\/ul>\n<hr>\n<h2 id=\"kubebuilder\">kubebuilder<\/h2>\n<p>sig\u7ef4\u62a4\u7684kubebuilder\u80fd\u65b9\u4fbf\u7684\u5f00\u53d1operator.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes-sigs\/kubebuilder\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes-sigs\/kubebuilder<\/a><\/p>\n<p>Install:<\/p>\n<pre><code>curl -L -o kubebuilder &quot;https:\/\/go.kubebuilder.io\/dl\/latest\/$(go env GOOS)\/$(go env GOARCH)&quot;\nchmod +x kubebuilder &amp;&amp; sudo mv kubebuilder \/usr\/local\/bin\/\n<\/code><\/pre>\n<p>create project:<\/p>\n<pre><code>mkdir k8s-nim-operator\ncd k8s-nim-operator\nkubebuilder init --domain nvidia.com --repo github.com\/NVIDIA\/k8s-nim-operator --project-name k8s-nim-operator\n<\/code><\/pre>\n<p>Create API<\/p>\n<pre><code>kubebuilder create api --group apps --version v1alpha1 --kind NIMService --controller --resource --namespaced\nkubebuilder create api --group apps --version v1alpha1 --kind NIMCache --controller --resource --namespaced\nkubebuilder create api --group apps --version v1alpha1 --kind NIMBuild --controller --resource --namespaced\nkubebuilder create api --group apps --version v1alpha1 --kind NIMPipeline --controller --resource --namespaced\n<\/code><\/pre>\n<p>create webhook:<\/p>\n<pre><code>kubebuilder create webhook --group apps --version v1alpha1 --kind NIMService --defaulting --programmatic-validation\nkubebuilder create webhook --group apps --version v1alpha1 --kind NIMCache --defaulting --programmatic-validation\n<\/code><\/pre>\n<p>Test\uff1a<\/p>\n<pre><code>make install \/\/ deploy CRDs on k8s.\nmake uninstall\nmake run \/\/ run controller locally.\nkubectl apply -k config\/samples\/ \/\/ install CR instances\n<\/code><\/pre>\n<p>Deploy\uff1a<\/p>\n<pre><code>\/\/Build the operator:\nmake build\n\/\/Build and push container image:\nmake docker-build docker-push IMG=&lt;your-registry&gt;\/k8s-nim-operator:tag\n\/\/Deploy controller to cluster:\nmake deploy IMG=&lt;your-registry&gt;\/k8s-nim-operator:tag\nmake undeploy\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u521b\u5efahelm chart\u53d1\u5e03operator\u3002<\/p>\n<hr>\n<h2 id=\"operator-sdk\">operator-sdk<\/h2>\n<p>redhat\u7684operator-sdk(\u57fa\u4e8ekubebuilder)\u80fd\u5feb\u901f\u7684\u5f00\u53d1operator.<\/p>\n<p>\u652f\u6301go, ansible\u548chelm\u4e09\u79cd\u65b9\u5f0f.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/operator-framework\/operator-sdk\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/operator-framework\/operator-sdk<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/sdk.operatorframework.io\/docs\/installation\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/sdk.operatorframework.io\/docs\/installation\/<\/a><\/p>\n<p>operator\u7684run\u4e09\u79cd\u6a21\u5f0f:<\/p>\n<ul>\n<li>\u5728\u96c6\u7fa4\u5916\u90e8\u672c\u5730\u8fd0\u884c\uff08\u5f00\u53d1\u6d4b\u8bd5).<\/li>\n<li>\u4f5c\u4e3adeployment\u5728\u96c6\u7fa4\u5185\u90e8\u8fd0\u884c.<\/li>\n<li>\u901a\u8fc7OLM\u90e8\u7f72.<\/li>\n<\/ul>\n<hr>"},{"title":"Service Discovery","link":"https:\/\/canuxcheng.com\/post\/k8s_servicediscovery\/","pubDate":"Fri, 10 Jan 2020 20:55:52 +0800","guid":"https:\/\/canuxcheng.com\/post\/k8s_servicediscovery\/","description":"<h1 id=\"coordination--service-discovery\">Coordination &amp; Service Discovery<\/h1>\n<p>\u5fae\u670d\u52a1\u7684\u670d\u52a1\u6ce8\u518c\u548c\u670d\u52a1\u53d1\u73b0.<\/p>\n<ul>\n<li>coredns<\/li>\n<li>etcd<\/li>\n<li>zookeeper<\/li>\n<\/ul>\n<hr>\n<h2 id=\"etcd\">Etcd<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/etcd-io\/etcd\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/etcd-io\/etcd<\/a><\/p>\n<p>\u7c7b\u4f3c\u7684\u6709consul\u548czoomkeeper.<\/p>\n<p>\u76f8\u5173\u8bc1\u4e66:<\/p>\n<pre><code>\/etc\/kubernetes\/pki\/etcd\/server.key # private key\n\/etc\/kubernetes\/pki\/etcd\/server.crt # certificate\n\/etc\/kubernetes\/pki\/etcd\/ca.crt # \u6839\u8bc1\u4e66\n<\/code><\/pre>\n<h3 id=\"etcdctl\">etcdctl<\/h3>\n<p>\u4f7f\u7528\u8bc1\u4e66\u8bbf\u95ee:<\/p>\n<pre><code>$ etcdctl \\\n--cacert=\/etc\/kubernetes\/pki\/etcd\/ca.crt \\\n--cert=\/etc\/kubernetes\/pki\/etcd\/server.crt \\\n--key=\/etc\/kubernetes\/pki\/etcd\/server.key \\\n--insecure-skip-tls-verify=true \\\n&lt;command&gt;\n<\/code><\/pre>\n<p>\u67e5\u770b\u6240\u6709key<\/p>\n<pre><code>$ etcdctl get \/ --prefix --keys-only\n<\/code><\/pre>\n<hr>\n<h2 id=\"coredns\">Coredns<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/coredns\/coredns\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/coredns\/coredns<\/a><\/p>\n<p>Coredns\u662fKubernetes\u7684\u9ed8\u8ba4DNS\u670d\u52a1\u5668\uff0c\u63d0\u4f9b\u670d\u52a1\u53d1\u73b0\u529f\u80fd\u3002\u4f7f\u7528\u63d2\u4ef6\u67b6\u6784\uff0c\u53ef\u4ee5\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u6dfb\u52a0\u6216\u4fee\u6539\u529f\u80fd\u3002\u53ef\u4ee5\u901a\u8fc7Kubernetes\u7684Service\u8d44\u6e90\u8fdb\u884c\u670d\u52a1\u53d1\u73b0\u3002<\/p>\n<p>Coredns\u7684\u914d\u7f6e\u6587\u4ef6\u901a\u5e38\u4f4d\u4e8e<code>\/etc\/coredns\/Corefile<\/code><\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-yaml\" data-lang=\"yaml\"><span style=\"display:flex;\"><span><span style=\"color:#ae81ff\">. {<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#ae81ff\">errors<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#ae81ff\">health<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#ae81ff\">kubernetes cluster.local in-addr.arpa ip6.arpa { <\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#ae81ff\">pods insecure<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#ae81ff\">fallthrough in-addr.arpa ip6.arpa<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> }\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#ae81ff\">prometheus :9153<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#ae81ff\">forward . \/etc\/resolv.conf<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#ae81ff\">cache 30<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#ae81ff\">loop<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#ae81ff\">reload<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#ae81ff\">loadbalance<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span>}\n<\/span><\/span><\/code><\/pre><\/div><hr>\n<h2 id=\"zookeeper\">zookeeper<\/h2>"},{"title":"Compose","link":"https:\/\/canuxcheng.com\/post\/cncf_compose\/","pubDate":"Sat, 04 Jan 2020 21:53:40 +0800","guid":"https:\/\/canuxcheng.com\/post\/cncf_compose\/","description":"<h1 id=\"docker-compose\">docker-compose<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/docker\/compose\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/docker\/compose<\/a><\/p>\n<p>\u901a\u8fc7\u4e00\u4e2ayaml\u6587\u4ef6\u6765\u7ba1\u7406\u5bb9\u5668\u4e2d\u7684\u670d\u52a1\uff0c\u5305\u62ec\u7f51\u7edc\u548c\u5b58\u50a8\u3002<\/p>\n<p>\u5b89\u88c5:<\/p>\n<pre><code>https:\/\/docs.docker.com\/compose\/install\/\n$ sudo curl -L https:\/\/github.com\/docker\/compose\/releases\/download\/1.21.2\/docker-compose-$(uname -s)-$(uname -m) -o \/usr\/local\/bin\/docker-compose\n$ sudo chmod +x \/usr\/local\/bin\/docker-compose\n<\/code><\/pre>\n<h1 id=\"docker-compose\u547d\u4ee4\">docker-compose\u547d\u4ee4<\/h1>\n<pre><code>docker-compose [-f &lt;arg&gt;...] [options] [COMMAND] [ARGS...]\n-f\/--file\n-p\/--project-name # \u9ed8\u8ba4\u76ee\u5f55\u540d\n-H\/--host\n# \u62c9\u53d6compose\u6587\u4ef6\u4e2d\u6307\u5b9a\u7684\u955c\u50cf\n$ docker-compose -f service.yml pull\n# \u6839\u636edocker-compose.yml\u628astack\u6253\u5305\u6210\u4e00\u4e2aDistributed Application Bundles\u6587\u4ef6.\n$ docker-compose bundle -o &lt;project name&gt;.dab\n$ docker-compose start [servoce...]\n$ docker-compose stop [service...]\n$ docker-compose restart [service...]\n$ docker-compose up -d [service...]\n$ docker-compose down -v\n$ docker-compose logs -f\n<\/code><\/pre>\n<h1 id=\"docker-composeyml\">docker-compose.yml<\/h1>\n<p>compose\u4e2d\u7684\u53d8\u91cf\uff1a<\/p>\n<p>&ldquo;x-&ldquo;\u5f00\u5934\u7684\u4f1a\u88abcompose\u5ffd\u7565\uff0c\u4f46\u662f\u4f1a\u88abyaml\u89e3\u6790.<\/p>\n<pre><code>x-var-name: &amp;default-label\nkey1: val1\nkey2: val2\nservices:\nmysql:\n&lt;&lt;: *default-label\nimage: mysql\n<\/code><\/pre>\n<p>compose\u6587\u4ef6<\/p>\n<pre><code>version: &quot;3.6&quot;\nservices:\nmongo:\nimage: mongo:latest\nhostname: hostname\ninit\ndns\ndns_search\nexpose\nextra_hosts\nhealthcheck:\ntest: curl -f https:\/\/host\/ping || exit 1\ntest: wget --no-verbose --tries=1 --spider https:\/\/host\/ping || exit 1\ninterval:\ntimeout:\nretries:\nstat_period:\nstop_grrace_period\nisolation\npid\nprofiles\nstop_signal\nlabels:\ncom.example.key: value\n\/\/ start: \u4e0b\u5217\u9009\u9879\u4e0d\u80fd\u7528\u4e8eswarm stack\u90e8\u7f72.\nsysctls(19.03+)\nprivileged: true\ndepends_on:\n- service-name\nbuild\ncgroup_parent\ncontainer_name\ndevices:\n- \/dev\/vboxdrv:\/dev\/vboxdrv\ntmpfs\nexternal_links\nlinks\nnetwork_mode: bridge\/host\/none\nrestart: no(default)\nsecurity_opt\nuserns_mode\nulimits\ncap_add\ncap_drop\n\/\/ end\nnetworks:\n- mynetwork\n\/\/ \u53ea\u6709\u81ea\u5b9a\u4e49\u7f51\u7edc\u53ef\u4ee5\u6307\u5b9a\u9759\u6001IP\nnetworks:\nmynetwork:\nipv4_address: 172.19.0.100\nvolumes: \/\/ short syntax\n- \/container\/dir \/\/ \u81ea\u52a8\u521b\u5efavolume\n- myvolume:\/container\/dir\n- \/host\/dir:\/container\/dir\nvolumes: \/\/ long syntax\n- type: valume\/bind\/tmpfs\nsource:\ntarget:\nread_only:\nbind:\nvolume:\ntmpfs:\nconsistency:\nvolumes:\n- &quot;\/path\/to\/file:\/path\/to\/file \u6302\u8f7d\u6587\u4ef6\nconfigs:\n- my-conf\nconfigs:\n- source: config-name\ntarget: file-name\nsecrets:\n- my-sec\nsecrets:\n- source: secret-name\ntarget: file-name in \/run\/secrets\/\nlogging:\ndriver: syslog\noptions:\nsyslog-address: &quot;tcp:\/\/192.168.0.42:123&quot;\nports: \/\/ long syntax\n- target: 80\npublished: 8080\nmode: host\nprotocol: tcp\/udp\nports: \/\/ short syntax\n- 80 \/\/ host\u4e0a\u7684port\u6ca1\u6709\u6307\u5b9a\u5c31\u662f\u4e00\u4e2a\u968f\u673a\u7684port\n- 80:80\n- 1234:1234\/udp\n\/\/ \u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\nenvironment:\nRABBITMQ_DEFAULT_USER: sandbox\nRABBITMQ_DEFAULT_PASS: password\nenvironment:\n- RABBITMQ_DEFAULT_USER=sandbox\n- RABBITMQ_DEFAULT_PASS=password\n- TZ=UTC \/\/ \u8bbe\u7f6e\u65f6\u533a\n&lt;https:\/\/docs.docker.com\/compose\/compose-file\/#env_file&gt;\n# When you set the same environment variable in multiple files,\n# here\u2019s the priority used by Compose to choose which value to use:\n# 1. Compose file (environment)\n# 2. Shell environment variables(export key=value)\n# 3. Environment file (env_file)\n# 4. Dockerfile\n# 5. Variable is not defined\nenv_file:\nentrypoint:\ncommand: [&quot;.\/wait-for-it.sh&quot;, &quot;db:5432&quot;, &quot;--&quot;, &quot;python&quot;, &quot;app.py&quot;]\n\/\/ \u5757\u7ed3\u6784\uff0c\u548c\u4e0a\u9762\u7684[]\u7b49\u6548.\ncommand:\n- &quot;.\/wait-for-it.sh&quot;\n- &quot;:b:5432&quot;\n- &quot;--&quot;\n- &quot;python&quot;\n- &quot;app.py&quot;\n\/\/ \u89e3\u6790\u4e3a: &quot;line1 line2\\n&quot;, \u4f1a\u81ea\u52a8\u52a0\u6362\u884c\u7b26.\ncommand: &gt;\nline1\nline2\n\/\/ \u89e3\u6790\u4e3a: &quot;line1 line2&quot;, \u6ca1\u6709\u6362\u884c\u7b26.\ncommand: &gt;-\nline1\nline2\n\/\/ start: \u4e0b\u9762\u4e09\u4e2adeploy\u4e0b\u9762\u7684\u5b57\u6bb5\uff0c\u4e5f\u80fd\u7528\u4e8e\u975eswarm\u6a21\u5f0f.\n\/\/ \u5728compose v3 \u4e2d\u9488\u5bf9\u975eswarm\u6a21\u5f0f\u7684container\u505a\u8d44\u6e90\u9650\u5236\u7b49\u64cd\u4f5c.\n\/\/ --compatibility If set, Compose will attempt to convert keys in v3 files to their non-Swarm equivalent\n$ docker-compose --compatibility up -d\n\/\/ --compatibility \u652f\u6301\u4e0b\u9762\u4e09\u79cdkey:\nreplicas:\nrestart_policy:\ncondition: any(default)\nmax_attempts:\nresources:\nlimits:\ncpus: '0.5'\nmemory: 1G\nreservations:\ncpus: '0.25'\nmemory: 20M\n\/\/ start: \u5b9a\u4e49config\/secret\/volume\/netework\u8d44\u6e90\nconfigs:\nc-name:\n\/\/ \u6839\u636e\u6587\u4ef6\u521b\u5efa\nfile: .\/httpd.conf\n\/\/ \u4f7f\u7528\u5df2\u7ecf\u521b\u5efa\u597d\u7684\nexternal: true\nsecrets:\ns-name:\n\/\/ \u6839\u636e\u6587\u4ef6\u521b\u5efa\nfile: .\/server.cert\n\/\/ \u4f7f\u7528\u5df2\u7ecf\u521b\u5efa\u597d\u7684\nexternal: true\nvolumes:\ndata-volume:\n\/\/ \u4ee5\u5b9a\u4e49\u597d\u7684volume\nvolumes:\ndata:\nexternal: true\n\/\/ (\u63a8\u8350)\u4f7f\u7528\u5df2\u7ecf\u521b\u5efa\u597d\u7684\u7f51\u7edc\n\/\/ \u901a\u8fc7\u547d\u4ee4\u884c\u6216\u8005api \u521b\u5efa\u7f51\u7edc\nnetworks:\nmynetwork:\nexternal: true\nname: lan0 \/\/ \u901a\u8fc7docker network ls \u67e5\u770b\u540d\u5b57\n\/\/ \u521b\u5efabridge\u7f51\u7edc\n\/\/ \u4f1a\u5728\u7f51\u7edc\u540d\u5b57\u81ea\u52a8\u52a0namespace\nnetworks:\nmynetwork:\ndriver: bridge\ndriver_opts:\ncom.docker.network.bridge.name: lan0\nipam:\ndriver: default\nconfig:\n- subnet: 192.168.1.0\/24\n\/\/ \u521b\u5efaoverlay\u7f51\u7edc\n\/\/ \u4f1a\u5728\u7f51\u7edc\u540d\u5b57\u81ea\u52a8\u52a0namespace\nnetworks:\nol0:\ndriver: overlay\nattachable: true\ndriver_opts:\ncom.docker.network.bridge.name: ol0\nipam:\ndriver: default\nconfig:\n- subnet: 172.12.0.0\/16\n<\/code><\/pre>\n<p>compose\u6587\u4ef6\u4e2d\u7528\u5230\u7684\u53d8\u91cf<\/p>\n<pre><code>.Service.ID Service ID\n.Service.Name Service name\n.Service.Labels Service labels\n.Node.ID Node ID\n.Node.Hostname Node Hostname\n.Task.ID Task ID\n.Task.Name Task name\n.Task.Slot Task slot\n<\/code><\/pre>\n<p>yaml\u53d8\u91cf\uff1a<\/p>\n<pre><code>key: &amp;varhash value\nkey1: *varhash\n# \u5b9a\u4e49\u53d8\u91cf\nlist:\n&amp;varlist\nkey1: value1\nkey2: value2\n# \u5c06list\u7684\u5143\u7d20\u8d4b\u503c\u7ed9list1\nlist1:\n&lt;&lt;: *varlist\nkey3: value2\n<\/code><\/pre>\n<hr>\n<h1 id=\"kompose\">Kompose<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes\/kompose\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes\/kompose<\/a><\/p>\n<p>install:<\/p>\n<pre><code>$ curl -L https:\/\/github.com\/kubernetes\/kompose\/releases\/download\/v1.19.0\/kompose-linux-amd64 -o kompose\n$ chmod +x kompose\n$ sudo mv .\/kompose \/usr\/local\/bin\/kompose\n<\/code><\/pre>"},{"title":"Automation & Configuration","link":"https:\/\/canuxcheng.com\/post\/cncf_platform\/","pubDate":"Sat, 04 Jan 2020 20:03:39 +0800","guid":"https:\/\/canuxcheng.com\/post\/cncf_platform\/","description":"<h1 id=\"automation--configuration\">Automation &amp; Configuration<\/h1>\n<ul>\n<li>Cloud Custodian<\/li>\n<li>kubeedge<\/li>\n<li>pulumi<\/li>\n<li>terraform<\/li>\n<li>opentofu<\/li>\n<li>kratix<\/li>\n<\/ul>\n<p>platform orchestration.<\/p>\n<h2 id=\"kratix\">kratix<\/h2>"},{"title":"Key Management","link":"https:\/\/canuxcheng.com\/post\/k8s_key\/","pubDate":"Sat, 04 Jan 2020 20:03:39 +0800","guid":"https:\/\/canuxcheng.com\/post\/k8s_key\/","description":"<h1 id=\"key-management\">Key Management<\/h1>\n<ul>\n<li>spiffe<\/li>\n<li>spire<\/li>\n<\/ul>\n<p>\u6838\u5fc3\u529f\u80fd\uff1a<\/p>\n<ul>\n<li><strong>\u5bc6\u94a5\u8f6e\u6362<\/strong>\uff1a\u81ea\u52a8\u66f4\u65b0\u5bc6\u94a5\uff0c\u51cf\u5c11\u624b\u52a8\u64cd\u4f5c\u3002<\/li>\n<li><strong>\u5bc6\u94a5\u5b58\u50a8<\/strong>\uff1a\u96c6\u4e2d\u7ba1\u7406\u5bc6\u94a5\uff0c\u652f\u6301\u591a\u79cd\u5b58\u50a8\u540e\u7aef\u3002<\/li>\n<li><strong>\u5bc6\u94a5\u8bbf\u95ee\u63a7\u5236<\/strong>\uff1a\u57fa\u4e8e\u89d2\u8272\u7684\u8bbf\u95ee\u63a7\u5236\uff0c\u786e\u4fdd\u53ea\u6709\u6388\u6743\u7528\u6237\u548c\u670d\u52a1\u53ef\u4ee5\u8bbf\u95ee\u5bc6\u94a5\u3002<\/li>\n<li><strong>\u5bc6\u94a5\u5ba1\u8ba1<\/strong>\uff1a\u8bb0\u5f55\u5bc6\u94a5\u8bbf\u95ee\u548c\u4f7f\u7528\u60c5\u51b5\uff0c\u4fbf\u4e8e\u5b89\u5168\u5ba1\u8ba1\u3002<\/li>\n<li><strong>\u5bc6\u94a5\u52a0\u5bc6<\/strong>\uff1a\u4f7f\u7528\u5f3a\u52a0\u5bc6\u7b97\u6cd5\u4fdd\u62a4\u5bc6\u94a5\u5b58\u50a8\u548c\u4f20\u8f93\u3002<\/li>\n<li><strong>\u5bc6\u94a5\u5907\u4efd\u548c\u6062\u590d<\/strong>\uff1a\u5b9a\u671f\u5907\u4efd\u5bc6\u94a5\uff0c\u652f\u6301\u5feb\u901f\u6062\u590d\u3002<\/li>\n<li><strong>\u5bc6\u94a5\u7248\u672c\u7ba1\u7406<\/strong>\uff1a\u652f\u6301\u591a\u7248\u672c\u5bc6\u94a5\uff0c\u4fbf\u4e8e\u56de\u6eda\u548c\u5386\u53f2\u67e5\u8be2\u3002<\/li>\n<li><strong>\u5bc6\u94a5\u751f\u547d\u5468\u671f\u7ba1\u7406<\/strong>\uff1a\u81ea\u52a8\u5904\u7406\u5bc6\u94a5\u7684\u521b\u5efa\u3001\u66f4\u65b0\u3001\u5e9f\u5f03\u7b49\u751f\u547d\u5468\u671f\u4e8b\u4ef6\u3002<\/li>\n<li><strong>\u5bc6\u94a5\u96c6\u6210<\/strong>\uff1a\u4e0e\u5176\u4ed6\u7cfb\u7edf\uff08\u5982CI\/CD\u3001\u914d\u7f6e\u7ba1\u7406\uff09\u96c6\u6210\uff0c\u81ea\u52a8\u5316\u5bc6\u94a5\u7ba1\u7406\u6d41\u7a0b\u3002<\/li>\n<li><strong>\u5bc6\u94a5\u76d1\u63a7<\/strong>\uff1a\u5b9e\u65f6\u76d1\u63a7\u5bc6\u94a5\u4f7f\u7528\u60c5\u51b5\uff0c\u53ca\u65f6\u53d1\u73b0\u5f02\u5e38\u8bbf\u95ee\u3002<\/li>\n<li><strong>\u5bc6\u94a5\u901a\u77e5<\/strong>\uff1a\u5bc6\u94a5\u53d8\u66f4\u65f6\u81ea\u52a8\u901a\u77e5\u76f8\u5173\u7cfb\u7edf\u548c\u7528\u6237\uff0c\u786e\u4fdd\u53ca\u65f6\u66f4\u65b0\u914d\u7f6e\u3002<\/li>\n<li><strong>\u5bc6\u94a5\u7b56\u7565<\/strong>\uff1a\u5b9a\u4e49\u5bc6\u94a5\u4f7f\u7528\u548c\u5b58\u50a8\u7684\u5b89\u5168\u7b56\u7565\uff0c\u786e\u4fdd\u7b26\u5408\u5408\u89c4\u8981\u6c42\u3002<\/li>\n<li><strong>\u5bc6\u94a5\u9694\u79bb<\/strong>\uff1a\u652f\u6301\u591a\u79df\u6237\u73af\u5883\uff0c\u786e\u4fdd\u4e0d\u540c\u79df\u6237\u7684\u5bc6\u94a5\u76f8\u4e92\u9694\u79bb\u3002<\/li>\n<li><strong>\u5bc6\u94a5\u81ea\u52a8\u5316<\/strong>\uff1a\u901a\u8fc7API\u6216CLI\u81ea\u52a8\u5316\u5bc6\u94a5\u7ba1\u7406\u64cd\u4f5c\uff0c\u51cf\u5c11\u4eba\u5de5\u5e72\u9884\u3002<\/li>\n<li><strong>\u5bc6\u94a5\u52a0\u5bc6\u4f20\u8f93<\/strong>\uff1a\u786e\u4fdd\u5bc6\u94a5\u5728\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u4f7f\u7528TLS\u7b49\u5b89\u5168\u534f\u8bae\u52a0\u5bc6\uff0c\u9632\u6b62\u4e2d\u95f4\u4eba\u653b\u51fb\u3002<\/li>\n<li><strong>\u5bc6\u94a5\u8fc7\u671f\u7ba1\u7406<\/strong>\uff1a\u81ea\u52a8\u5904\u7406\u5bc6\u94a5\u8fc7\u671f\u4e8b\u4ef6\uff0c\u786e\u4fdd\u7cfb\u7edf\u4f7f\u7528\u7684\u5bc6\u94a5\u59cb\u7ec8\u6709\u6548\u3002<\/li>\n<li><strong>\u5bc6\u94a5\u4f9d\u8d56\u7ba1\u7406<\/strong>\uff1a\u8ddf\u8e2a\u54ea\u4e9b\u670d\u52a1\u4f9d\u8d56\u4e8e\u54ea\u4e9b\u5bc6\u94a5\uff0c\u4fbf\u4e8e\u53d8\u66f4\u548c\u66f4\u65b0\u3002<\/li>\n<li><strong>\u5bc6\u94a5\u5171\u4eab<\/strong>\uff1a\u652f\u6301\u5b89\u5168\u5730\u5171\u4eab\u5bc6\u94a5\u7ed9\u5176\u4ed6\u670d\u52a1\u6216\u7528\u6237\uff0c\u786e\u4fdd\u5171\u4eab\u8fc7\u7a0b\u5b89\u5168\u53ef\u9760\u3002<\/li>\n<li><strong>\u5bc6\u94a5\u52a0\u5bc6\u5b58\u50a8<\/strong>\uff1a\u4f7f\u7528\u5f3a\u52a0\u5bc6\u7b97\u6cd5\u5bf9\u5bc6\u94a5\u8fdb\u884c\u5b58\u50a8\uff0c\u9632\u6b62\u672a\u6388\u6743\u8bbf\u95ee\u3002<\/li>\n<li><strong>\u5bc6\u94a5\u8bbf\u95ee\u63a7\u5236\u5217\u8868<\/strong>\uff1a\u5b9a\u4e49\u54ea\u4e9b\u7528\u6237\u6216\u670d\u52a1\u53ef\u4ee5\u8bbf\u95ee\u54ea\u4e9b\u5bc6\u94a5\uff0c\u786e\u4fdd\u6700\u5c0f\u6743\u9650\u539f\u5219\u3002<\/li>\n<\/ul>"},{"title":"Microservivce","link":"https:\/\/canuxcheng.com\/post\/k8s_microservice\/","pubDate":"Sat, 04 Jan 2020 20:03:39 +0800","guid":"https:\/\/canuxcheng.com\/post\/k8s_microservice\/","description":"<h1 id=\"microservice\">Microservice<\/h1>\n<p>\u5fae\u670d\u52a1\u662f\u4e00\u79cd\u67b6\u6784\u3002<\/p>\n<p>\u5e38\u89c1\u7684\u67b6\u6784:<\/p>\n<ul>\n<li>Monolithic application \u5355\u4f53\u5e94\u7528.<\/li>\n<li>SOA(service-oriented architecture) \u9762\u5411\u670d\u52a1\u7684\u4f53\u7cfb\u7ed3\u6784.<\/li>\n<li>MicroServices \u5fae\u670d\u52a1.<\/li>\n<\/ul>\n<p>\u5fae\u670d\u52a1\u67b6\u6784\u7684\u670d\u52a1\u6cbb\u7406\u5305\u62ec:<\/p>\n<ul>\n<li>service registry \u670d\u52a1\u6ce8\u518c<\/li>\n<li>service discovery \u670d\u52a1\u53d1\u73b0<\/li>\n<li>observability \u53ef\u89c2\u6d4b\u6027(metrics,logging,trace)<\/li>\n<li>\u6d41\u91cf\u7ba1\u7406<\/li>\n<li>\u5b89\u5168<\/li>\n<li>\u63a7\u5236<\/li>\n<\/ul>\n<p>\u5fae\u670d\u52a1\u5e94\u7528\u53ef\u4ee5\u901a\u8fc7\u5bb9\u5668\u5316(docker, k8s)\u90e8\u7f72\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7serverless\u65b9\u5f0f\u90e8\u7f72.<\/p>\n<p>\u4e0d\u540c\u7684\u8bed\u8a00\u6709\u4e0d\u540c\u7684\u5fae\u670d\u52a1\u6846\u67b6.\njava\u7684dubbo, sprint boot.\ngolang\u7684go-kit, go-zero, kratos.\npython\u7684zappa, nameko.<\/p>\n<hr>\n<h2 id=\"dapr\">Dapr<\/h2>\n<p>Dapr is a portable, event-driven, runtime for building distributed applications across cloud and edge.<\/p>"},{"title":"Scheduling & Orchestration","link":"https:\/\/canuxcheng.com\/post\/cncf_orchestration\/","pubDate":"Sat, 04 Jan 2020 20:03:39 +0800","guid":"https:\/\/canuxcheng.com\/post\/cncf_orchestration\/","description":"<h1 id=\"scheduling--orchestration\">Scheduling &amp; Orchestration<\/h1>\n<ul>\n<li>docker swarm.<\/li>\n<li>KEDA<\/li>\n<li>Crossplane<\/li>\n<li>Knative<\/li>\n<li>Kubeflow<\/li>\n<li>Volcano<\/li>\n<\/ul>\n<hr>\n<h2 id=\"keda\">KEDA<\/h2>\n<hr>\n<h2 id=\"crossplane\">Crossplane<\/h2>\n<hr>\n<h2 id=\"volcano\">Volcano<\/h2>"},{"title":"Serverless","link":"https:\/\/canuxcheng.com\/post\/k8s_serverless\/","pubDate":"Sat, 04 Jan 2020 20:03:39 +0800","guid":"https:\/\/canuxcheng.com\/post\/k8s_serverless\/","description":"<h1 id=\"serverless\">Serverless<\/h1>\n<hr>\n<h2 id=\"knative\">Knative<\/h2>\n<p>Knative is a developer-focused serverless application layer which is a great complement to the existing Kubernetes application constructs. Knative consists of three components: an HTTP-triggered autoscaling container runtime called \u201cKnative Serving\u201d, a CloudEvents-over-HTTP asynchronous routing layer called \u201cKnative Eventing\u201d, and a developer-focused function framework which leverages the Serving and Eventing components, called &ldquo;Knative Functions&rdquo;.<\/p>"},{"title":"Service Mesh","link":"https:\/\/canuxcheng.com\/post\/k8s_servicemesh\/","pubDate":"Sat, 04 Jan 2020 20:03:39 +0800","guid":"https:\/\/canuxcheng.com\/post\/k8s_servicemesh\/","description":"<h1 id=\"service-mesh\">Service Mesh<\/h1>\n<p>servivce mesh\u662fcncf\u57fa\u4e8esidecar\u63a8\u51fa\u7684\u4e0b\u4e00\u4ee3\u9762\u5411\u4e91\u539f\u751f\u7684\u5fae\u670d\u52a1\u67b6\u6784\uff0c\u662f\u5fae\u670d\u52a1\u57fa\u7840\u8bbe\u65bd, \u7528\u4e8e\u5904\u7406\u5fae\u670d\u52a1\u901a\u4fe1\u3001\u6cbb\u7406\u3001\u63a7\u5236\u3001\u53ef\u89c2\u6d4b\u3001\u5b89\u5168\u7b49\u95ee\u9898\uff0c\u5177\u5907\u4e1a\u52a1\u65e0\u4fb5\u5165\u3001\u591a\u8bed\u8a00\u3001\u70ed\u5347\u7ea7\u7b49\u8bf8\u591a\u7279\u6027.<\/p>\n<p>sidecar: \u8fb9\u8f66\u6a21\u5f0f\uff0c\u5c31\u662f\u628a\u4e1a\u52a1\u65e0\u5173\u7684\u529f\u80fd\uff0c\u65e5\u5fd7\u8bb0\u5f55\u3001\u76d1\u63a7\u3001\u6d41\u91cf\u63a7\u5236\u3001\u670d\u52a1\u6ce8\u518c\u3001\u670d\u52a1\u53d1\u73b0\u3001\u670d\u52a1\u9650\u6d41\u3001\u670d\u52a1\u7194\u65ad\u3001\u9274\u6743\u3001\u8bbf\u95ee\u63a7\u5236\u548c\u670d\u52a1\u8c03\u7528\u53ef\u89c6\u5316\u7b49\u72ec\u7acb\u51fa\u6765\u3002<\/p>\n<p>\u7279\u70b9:<\/p>\n<ul>\n<li>\u5e94\u7528\u7a0b\u5e8f\u901a\u4fe1\u7684\u4e2d\u95f4\u5c42<\/li>\n<li>\u8f7b\u91cf\u7ea7\u7f51\u7edc\u4ee3\u7406<\/li>\n<li>\u5e94\u7528\u7a0b\u5e8f\u65e0\u611f\u77e5<\/li>\n<li>\u89e3\u8026\u5e94\u7528\u7a0b\u5e8f\u7684\u91cd\u8bd5\u3001\u8d85\u65f6\u3001\u76d1\u63a7\u3001\u8ffd\u8e2a\u548c\u670d\u52a1\u53d1\u73b0.<\/li>\n<\/ul>\n<p>Service Mesh\u662f\u5efa\u7acb\u5728\u7269\u7406\u6216\u8005\u865a\u62df\u7f51\u7edc\u5c42\u4e4b\u4e0a\u7684\uff0c\u57fa\u4e8e\u7b56\u7565\u7684\u5fae\u670d\u52a1\u7684\u6d41\u91cf\u63a7\u5236\uff0c\u4e0e\u4e00\u822c\u7684\u7f51\u7edc\u534f\u8bae\u4e0d\u540c\u7684\u662f\u5b83\u6709\u4ee5\u4e0b\u51e0\u4e2a\u7279\u70b9\uff1a<\/p>\n<ul>\n<li>\u5f00\u53d1\u8005\u9a71\u52a8<\/li>\n<li>\u53ef\u914d\u7f6e\u7b56\u7565<\/li>\n<li>\u670d\u52a1\u4f18\u5148\u7684\u7f51\u7edc\u914d\u7f6e\u800c\u4e0d\u662f\u534f\u8bae<\/li>\n<\/ul>\n<hr>\n<h2 id=\"istio\">Istio<\/h2>\n<p><a class=\"link\" href=\"https:\/\/istio.io\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/istio.io\/<\/a><\/p>\n<hr>\n<h2 id=\"linkerd\">Linkerd<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/linkerd\/linkerd2\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/linkerd\/linkerd2<\/a><\/p>\n<hr>"},{"title":"Service Proxy","link":"https:\/\/canuxcheng.com\/post\/k8s_proxy\/","pubDate":"Sat, 04 Jan 2020 20:03:39 +0800","guid":"https:\/\/canuxcheng.com\/post\/k8s_proxy\/","description":"<h1 id=\"service-proxy\">Service Proxy<\/h1>\n<p>ingress =&gt; gateway api<\/p>\n<ul>\n<li>envoy<\/li>\n<li>contour<\/li>\n<li>traefik proxy<\/li>\n<li>haproxy<\/li>\n<li>metaLB<\/li>\n<li>nginx<\/li>\n<li>openelb<\/li>\n<\/ul>\n<hr>\n<h2 id=\"ingress-controller\">ingress controller<\/h2>\n<ul>\n<li>Ingress-nginx(nginx)<\/li>\n<li>aws-load-balancer-controller(alb)<\/li>\n<li>ingress-gce<\/li>\n<li>Traefik<\/li>\n<\/ul>\n<p>The kubernetes.io\/ingress.class annotation is deprecated from kubernetes v1.22+.\u901a\u8fc7IngressClasses\u6765\u9009\u62e9ingress controller\u3002<\/p>\n<pre><code>ingressClassName: nginx\n<\/code><\/pre>\n<p>ingress \u8bed\u6cd5<\/p>\n<pre><code>apiVersion: networking.k8s.io\/v1\nkind: Ingress\nmetadata:\nname: minimal-ingress\nannotations:\nnginx.ingress.kubernetes.io\/rewrite-target: \/\nspec:\ningressClassName: nginx-example\ndefaultBackend:\nresource:\napiGroup: k8s.example.com\nkind: StorageBucket\nname: static-assets\nrules:\n- http:\npaths:\n- path: \/testpath\npathType: Prefix\nbackend:\nservice:\nname: test\nport:\nnumber: 80\n<\/code><\/pre>\n<p>ImplementationSpecific\uff1a\u5bf9\u4e8e\u8fd9\u79cd\u8def\u5f84\u7c7b\u578b\uff0c\u5339\u914d\u65b9\u6cd5\u53d6\u51b3\u4e8e IngressClass\u3002 \u5177\u4f53\u5b9e\u73b0\u53ef\u4ee5\u5c06\u5176\u4f5c\u4e3a\u5355\u72ec\u7684 pathType \u5904\u7406\u6216\u8005\u4e0e Prefix \u6216 Exact \u7c7b\u578b\u4f5c\u76f8\u540c\u5904\u7406\u3002<\/p>\n<p>Exact\uff1a\u7cbe\u786e\u5339\u914d URL \u8def\u5f84\uff0c\u4e14\u533a\u5206\u5927\u5c0f\u5199\u3002<\/p>\n<p>Prefix\uff1a\u57fa\u4e8e\u4ee5 \/ \u5206\u9694\u7684 URL \u8def\u5f84\u524d\u7f00\u5339\u914d\u3002\u5339\u914d\u533a\u5206\u5927\u5c0f\u5199\uff0c\u5e76\u4e14\u5bf9\u8def\u5f84\u4e2d\u7684\u5143\u7d20\u9010\u4e2a\u5b8c\u6210\u3002 \u8def\u5f84\u5143\u7d20\u6307\u7684\u662f\u7531 \/ \u5206\u9694\u7b26\u5206\u9694\u7684\u8def\u5f84\u4e2d\u7684\u6807\u7b7e\u5217\u8868\u3002 \u5982\u679c\u6bcf\u4e2a p \u90fd\u662f\u8bf7\u6c42\u8def\u5f84 p \u7684\u5143\u7d20\u524d\u7f00\uff0c\u5219\u8bf7\u6c42\u4e0e\u8def\u5f84 p \u5339\u914d\u3002<\/p>\n<p>ingressclass\u6ca1\u6709namespace\u3002<\/p>\n<h2 id=\"gateway-api-controller\">gateway api controller<\/h2>\n<ul>\n<li>cilium<\/li>\n<li>contour<\/li>\n<li>GKE<\/li>\n<li>EKS<\/li>\n<li>kong<\/li>\n<li>traefik<\/li>\n<\/ul>\n<hr>\n<h2 id=\"ingress-nginx\">ingress-nginx<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes\/ingress-nginx\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes\/ingress-nginx<\/a><\/p>\n<pre><code>\/\/ \u90e8\u7f72\n$ kubectl apply -f https:\/\/raw.githubusercontent.com\/kubernetes\/ingress-nginx\/controller-v0.34.1\/deploy\/static\/provider\/baremetal\/deploy.yaml\n\/\/ \u9a8c\u8bc1\u90e8\u7f72\n$ kubectl get pods --all-namespaces -l app.kubernetes.io\/name=ingress-nginx --watch\n\/\/ Detect installed version\nPOD_NAMESPACE=ingress-nginx\nPOD_NAME=$(kubectl get pods -n $POD_NAMESPACE -l app.kubernetes.io\/name=ingress-nginx -o jsonpath='{.items[0].metadata.name}')\n$ kubectl exec -it $POD_NAME -n $POD_NAMESPACE -- \/nginx-ingress-controller --version\n<\/code><\/pre>\n<p>tls:<\/p>\n<p><a class=\"link\" href=\"https:\/\/kubernetes.github.io\/ingress-nginx\/user-guide\/tls\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kubernetes.github.io\/ingress-nginx\/user-guide\/tls\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/kubernetes.io\/zh-cn\/docs\/concepts\/services-networking\/ingress\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kubernetes.io\/zh-cn\/docs\/concepts\/services-networking\/ingress\/<\/a><\/p>\n<hr>\n<h2 id=\"traefik\">traefik<\/h2>\n<p>traefik2.2+<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/traefik\/traefik\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/traefik\/traefik<\/a><\/p>\n<p>install with helm:<\/p>\n<pre><code>helm repo add traefik https:\/\/helm.traefik.io\/traefik\nhelm repo update\nhelm install --create-namespace traefik -n traefik traefik traefik\/traefik -f .\/value.yaml\n# expose dashboard:\nkubectl port-forward -n traefik $(kubectl get pods -n traefik --selector &quot;app.kubernetes.io\/name=traefik&quot; --output=name) 9000:9000 --address 0.0.0.0\n<\/code><\/pre>\n<p>\u8bf7\u6c42\u6a21\u578b<\/p>\n<pre><code>Client =&gt; Traefik =&gt; Backend\n<\/code><\/pre>\n<p>\u7aef\u53e3:<\/p>\n<pre><code>9000: traefik\u7ba1\u7406\u9875\u9762\u7aef\u53e3\n<\/code><\/pre>\n<h3 id=\"\u91cd\u8981\u7ec4\u4ef6\">\u91cd\u8981\u7ec4\u4ef6<\/h3>\n<ul>\n<li>Providers: \u81ea\u52a8\u53d1\u73b0\u5e73\u53f0\u4e0a\u7684\u670d\u52a1.<\/li>\n<li>Entrypoints: \u76d1\u542c\u4f20\u5165\u7684\u6d41\u91cf\uff0c\u5b9a\u4e49\u63a5\u53d7\u8bf7\u6c42\u7684\u7aef\u53e3.<\/li>\n<li>Routers: \u5206\u6790\u8bf7\u6c42\uff0c\u8d1f\u8d23\u5c06\u4f20\u5165\u8bf7\u6c42\u8fde\u63a5\u5230\u8d1f\u8d23\u5904\u7406\u7684\u670d\u52a1\u4e0a.<\/li>\n<li>Middlewares: \u5728routers\u8f6c\u7ed9services\u4e4b\u524d\u4fee\u6539\u8bf7\u6c42.<\/li>\n<li>Services\/LB: \u5c06\u8bf7\u6c42\u8f6c\u7ed9\u5e94\u7528, \u8d1f\u8d23\u914d\u7f6e\u5904\u7406\u8bf7\u6c42\u7684\u5b9e\u9645\u670d\u52a1.<\/li>\n<\/ul>\n<h3 id=\"\u914d\u7f6e\">\u914d\u7f6e<\/h3>\n<p>\u4e24\u79cd\u914d\u7f6e\u7c7b\u578b<\/p>\n<ul>\n<li>\u9759\u6001\u914d\u7f6e: \u542f\u52a8\u65f6\u7684\u914d\u7f6e\uff0c\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6(\/etc\/traefik\/traefik.[toml|yaml]\uff0c\u73af\u5883\u53d8\u91cf\u6216\u547d\u4ee4\u884c\u53c2\u6570\u914d\u7f6e providers\u548centrypoints\u7b49.<\/li>\n<li>\u52a8\u6001\u914d\u7f6e: \u52a8\u6001\u7684\u8def\u7531\u914d\u7f6e\uff0c\u5b9a\u4e49\u7cfb\u7edf\u5982\u4f55\u5904\u7406\u8bf7\u6c42,\u4eceproviders\u83b7\u53d6\u52a8\u6001\u914d\u7f6e.<\/li>\n<\/ul>\n<p>\u9759\u6001\u914d\u7f6e:<\/p>\n<ul>\n<li>entrypoints<\/li>\n<li>providers<\/li>\n<li>servertransport<\/li>\n<li>certificatesresolvers<\/li>\n<li>api<\/li>\n<li>ping<\/li>\n<li>experimental<\/li>\n<li>hostresolver<\/li>\n<li>accesslog<\/li>\n<li>log<\/li>\n<li>metrics(datadog, influxdb, prometheus,statsd)<\/li>\n<li>tracing(datadog, elastic, haystack, instana, jaeger, zipkin)<\/li>\n<\/ul>\n<p>\u5168\u5c40\u914d\u7f6e:<\/p>\n<pre><code>--global.checknewversion\n--global.sendanonymoususagge\n<\/code><\/pre>\n<p>\u63a7\u5236Traefik\u5230Backend\u7684\u8fde\u63a5\u7684\u53c2\u6570serversTransport:<\/p>\n<pre><code>--serversTransport.insecureSkipVerify=true\n# self-signed TLS CA.\n--serversTransport.rootCAs=foo.crt,bar.crt\n--serversTransport.maxIdleConnsPerHost=7\n--serversTransport.forwardingTimeouts.dialTimeout=1s\n--serversTransport.forwardingTimeouts.responseHeaderTimeout=1s\n--serversTransport.forwardingTimeouts.idleConnTimeout=1s\n<\/code><\/pre>\n<h3 id=\"kubernetes-provider\">kubernetes provider<\/h3>\n<p>kubernetes provider\u6709\u4e09\u79cd\u7c7b\u578b<\/p>\n<ul>\n<li>Ingress<\/li>\n<li>IngressRoute<\/li>\n<li>Gateway API<\/li>\n<\/ul>\n<h3 id=\"https--tls\">https &amp; tls<\/h3>\n<p>traefik\u7684\u8bc1\u4e66\u53ef\u4ee5\u662f\u624b\u52a8\u521b\u5efa\u8bc1\u4e66\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7let&rsquo;s encrypt\u81ea\u52a8\u521b\u5efa<\/p>\n<pre><code>---\napiVersion: traefik.containo.us\/v1alpha1\nkind: IngressRoute\nmetadata:\nname: name\nnamespace: ns\nspec:\ntls:\nsecretName: my-tls\n<\/code><\/pre>\n<p>\u901a\u8fc7Let&rsquo;s encrypt\u6765\u81ea\u52a8\u521b\u5efa\u8bc1\u4e66\u6709\u4e09\u79cd\u9a8c\u8bc1\u65b9\u5f0f\uff08tls, http, dns).<\/p>\n<pre><code>- &quot;--certificatesresolvers.myresolver.acme.httpchallenge=true&quot;\n- &quot;--certificatesresolvers.myresolver.acme.httpchallenge.entrypoint=web&quot;\n- &quot;--certificatesresolvers.myresolver.acme.tlschallenge=true&quot;\n- &quot;--certificatesresolvers.myresolver.acme.tlschallenge.entrypoint=websecure&quot;\n- &quot;--certificatesresolvers.myresolver.acme.email=canux.cheng@arm.com&quot;\n- &quot;--certificatesresolvers.myresolver.acme.storage=acme.json&quot;\n<\/code><\/pre>\n<hr>\n<h2 id=\"envoy\">Envoy<\/h2>"},{"title":"Kubeadm","link":"https:\/\/canuxcheng.com\/post\/k8s_kubeadm\/","pubDate":"Mon, 30 Dec 2019 21:47:17 +0800","guid":"https:\/\/canuxcheng.com\/post\/k8s_kubeadm\/","description":"<h1 id=\"kubeadm\">kubeadm<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes\/kubeadm\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes\/kubeadm<\/a><\/p>\n<p>kubeadm\u662fk8s\u81ea\u5e26\u7684\u90e8\u7f72\u96c6\u7fa4\u7684\u5de5\u5177.<\/p>\n<p>\u672c\u673a\u90e8\u7f72\u53ef\u4ee5\u7528minikube\u6216\u8005kind\u3002<\/p>\n<hr>\n<h1 id=\"install\">Install<\/h1>\n<h2 id=\"\u51c6\u5907\u5de5\u4f5c\">\u51c6\u5907\u5de5\u4f5c<\/h2>\n<p><a class=\"link\" href=\"https:\/\/kubernetes.io\/zh\/docs\/setup\/production-environment\/tools\/kubeadm\/install-kubeadm\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kubernetes.io\/zh\/docs\/setup\/production-environment\/tools\/kubeadm\/install-kubeadm\/<\/a><\/p>\n<h2 id=\"\u5b89\u88c5runtime\">\u5b89\u88c5runtime<\/h2>\n<p><a class=\"link\" href=\"https:\/\/kubernetes.io\/zh\/docs\/setup\/production-environment\/container-runtimes\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kubernetes.io\/zh\/docs\/setup\/production-environment\/container-runtimes\/<\/a><\/p>\n<p>\u9ed8\u8ba4\u7684cgroup\u9a71\u52a8\u65f6cgroupfs,\u5982\u679c\u7cfb\u7edf\u662fsystemd\uff0c\u5c31\u4f1a\u6709\u4e24\u4e2acgroup driver\uff0c\u4f1a\u51fa\u95ee\u9898.<\/p>\n<p>\u5982\u679c\u4fee\u6539cgroup driver\u9700\u8981\u540c\u65f6\u4fee\u6539CRI\u548ckubelet.<\/p>\n<p>\u4fee\u6539containerd\u7684cgroup driver:<\/p>\n<pre><code>$ sudo vim \/etc\/containerd\/config.toml\n#disabled_plugins = [&quot;cri&quot;]\n[plugins.&quot;io.containerd.grpc.v1.cri&quot;.containerd.runtimes.runc.options]\nSystemdCgroup = true\n$ sudo systemctl restart containerd\n<\/code><\/pre>\n<p>\u4fee\u6539kubelet\u7684cgroup driver(kubeadm-config.yaml):<\/p>\n<pre><code># kubeadm-config.yaml\nkind: ClusterConfiguration\napiVersion: kubeadm.k8s.io\/v1beta3\nkubernetesVersion: v1.21.0 \/\/ kubelet --version\n---\napiVersion: kubelet.config.k8s.io\/v1beta1\nkind: KubeletConfiguration\ncgroupDriver: systemd\n<\/code><\/pre>\n<h2 id=\"\u5b89\u88c5kubeadm-kubelet-kubectl\">\u5b89\u88c5kubeadm, kubelet, kubectl<\/h2>\n<p>\u5728\u6bcf\u53f0\u673a\u5668\u4e0a\u5b89\u88c5 kubeadm, kubelet, kubectl:<\/p>\n<pre><code>$ sudo apt-get update\n$ sudo apt-get install -y apt-transport-https ca-certificates curl\n$ sudo curl -fsSL https:\/\/mirrors.aliyun.com\/kubernetes\/apt\/doc\/apt-key.gpg | sudo apt-key add -\n$ echo &quot;deb https:\/\/mirrors.aliyun.com\/kubernetes\/apt\/ kubernetes-xenial main&quot; | sudo tee \/etc\/apt\/sources.list.d\/kubernetes.list\n$ sudo apt-get update\n$ sudo apt-get --yes --allow-unauthenticated install kubeadm kubelet kubectl\n$ sudo apt-mark hold kubelet kubeadm kubectl\n$ sudo systemctl enable kubelet\n<\/code><\/pre>\n<hr>\n<h1 id=\"kubeadm-cli\">Kubeadm CLI<\/h1>\n<p>init:<\/p>\n<pre><code>$ kubeadm init\n--config kubeadm-config.yaml\n--kubernetes-version &lt;version&gt; \/\/ kubelet --version\n--apiserver-advertise-address &lt;master&gt; \/\/ \u591a\u7f51\u5361\u6307\u5b9a\u7f51\u5361IP\n--image-repository &lt;registry&gt; \/\/ default: k8s.gcr.io\n--pod-network-cidr &lt;cidr&gt; \/\/ \u6307\u5b9apod\u7684cidr\n--service-cidr &lt;cidr&gt; \/\/ default: 10.96.0.0\/12\n--service-dns-domain \/\/ default: cluster.local\n--cri-socket \/\/ \u5982\u679c\u5b89\u88c5\u4e86\u591a\u4e2acri\u9700\u8981\u6307\u5b9a.\n--ignore-preflight-errors\n--upload-certs\n<\/code><\/pre>\n<p>join:<\/p>\n<pre><code>$ kubeadm join [apiserver-advertise-address] --token &lt;token&gt; --discovery-token-ca-cert-hash &lt;hash&gt;\n<\/code><\/pre>\n<p>reset:<\/p>\n<pre><code>$ kubeadm reset -f\/--force\n<\/code><\/pre>\n<p>token:<\/p>\n<pre><code>$ kubeadm token create\/delete\/generate\/list\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u90e8\u7f72cluster\">\u90e8\u7f72Cluster<\/h1>\n<h2 id=\"\u90e8\u7f72master\">\u90e8\u7f72master<\/h2>\n<p>\u5173\u95edswap<\/p>\n<pre><code>$ sudo swapoff -a\n<\/code><\/pre>\n<p>\u521d\u59cb\u5316<\/p>\n<pre><code>$ sudo kubeadm init \\\n--pod-network-cidr=10.244.0.0\/16 \\\n--apiserver-advertise-address=&lt;IP&gt; \\\n--kubernetes-version=v1.17.0 \\\n--image-repository=registry.aliyuncs.com\/google_containers \\\n--cri-socket=\/run\/containerd\/containerd.sock \\\n-v=6\n\/\/ --config \u4e00\u822c\u4f7f\u7528\u9ed8\u8ba4\u5373\u53ef.\n\/\/ --pod-network-cidr=10.244.0.0\/16 \u662f\u56fa\u5b9a\u7528\u6cd5\uff0c\u8868\u793a\u9009\u62e9flannel\u4e3a\u7f51\u7edc\u63d2\u4ef6\u3002\n\/\/ --image-repository \u6307\u5b9aregistry, \u9ed8\u8ba4\u662fgcr\n<\/code><\/pre>\n<p>\u914d\u7f6e\u5f53\u524d\u5e10\u53f7<\/p>\n<pre><code>mkdir -p $HOME\/.kube\nsudo cp -i \/etc\/kubernetes\/admin.conf $HOME\/.kube\/config\nsudo chown $(id -u):$(id -g) $HOME\/.kube\/config\n<\/code><\/pre>\n<p>\u90e8\u7f72\u7f51\u7edc\u63d2\u4ef6<\/p>\n<pre><code>\/\/ \u5728\u6240\u6709node\u4e0a\u90e8\u7f72cni-plugin:\n\/\/ &lt;https:\/\/github.com\/containernetworking\/plugins\/releases&gt;\n$ sudo mkdir -p \/opt\/cni\/bin\n\/\/ \u4e0b\u8f7d\u5e76\u89e3\u538b\u6240\u6709\u63d2\u4ef6\u547d\u4ee4\u5230\u8be5\u76ee\u5f55. \u9ed8\u8ba4CNI_PATH=\/opt\/cni\/bin\n\/\/ &lt;https:\/\/docs.cilium.io\/en\/stable\/installation\/k8s-install-kubeadm\/&gt;\n\/\/ cilium\u4f1a\u81ea\u52a8\u4e0b\u8f7dplugins\u5230\/opt\/cni\/bin.\n\/\/ &lt;https:\/\/github.com\/flannel-io\/flannel&gt;\n$ kubectl apply -f https:\/\/raw.githubusercontent.com\/coreos\/flannel\/master\/Documentation\/kube-flannel.yml\n<\/code><\/pre>\n<p>\u914d\u7f6emaster\u662f\u5426\u90e8\u7f72pod<\/p>\n<pre><code># enable master deploy pod (\u9ed8\u8ba4\u4e0d\u90e8\u7f72pod\u5230master)\nkubectl taint nodes --all node-role.kubernetes.io\/control-plane-\n# disable master deploy pod\nkubectl taint nodes &lt;node&gt; node-role.kubernetes.io\/master=true:NoSchedule\n<\/code><\/pre>\n<h2 id=\"\u90e8\u7f72node\">\u90e8\u7f72node<\/h2>\n<pre><code>$ sudo swapoff -a\n\/\/ \u5982\u679c\u6709vpn\uff0ckubeadm\u4f1a\u81ea\u52a8\u4e0b\u8f7d\u5b89\u88c5\n\/\/ \u5728\u6240\u6709node\u4e0a\u90e8\u7f72cni-plugin:\n\/\/ &lt;https:\/\/github.com\/containernetworking\/plugins\/releases&gt;\n$ sudo mkdir -p \/opt\/cni\/bin\n\/\/ \u4e0b\u8f7d\u5e76\u89e3\u538b\u6240\u6709\u63d2\u4ef6\u547d\u4ee4\u5230\u8be5\u76ee\u5f55.\n$ sudo kubeadm join 192.168.1.1:6443 \\\n--token 8po0v5.m1qlbc7w0btq15of \\\n--discovery-token-ca-cert-hash sha256:21d8365e336d5218637ddf26e2ec5d91c7dd2de518dbe47973e089837b13265b\n<\/code><\/pre>\n<h2 id=\"\u9a8c\u8bc1\">\u9a8c\u8bc1<\/h2>\n<pre><code>$ kubectl get pods -n kube-system\n$ kubectl get nodes\n<\/code><\/pre>\n<h2 id=\"\u5220\u9664cluster\">\u5220\u9664cluster<\/h2>\n<p>\u6240\u6709node\u8fd0\u884c:<\/p>\n<pre><code>$ sudo kubeadm reset -f\n\/\/ \u81ea\u52a8\u505c\u6b62kubelet\u5e76\u4e14\u5220\u9664\u4e0b\u5217\u6587\u4ef6\u548c\u76ee\u5f55\n[\/etc\/kubernetes\/manifests \/etc\/kubernetes\/pki]\n[\/etc\/kubernetes\/admin.conf \/etc\/kubernetes\/kubelet.conf \/etc\/kubernetes\/bootstrap-kubelet.conf \/etc\/kubernetes\/controller-manager.conf \/etc\/kubernetes\/scheduler.conf]\n[\/var\/lib\/etcd \/var\/lib\/kubelet \/var\/lib\/dockershim \/var\/run\/kubernetes \/var\/lib\/cni]\n<\/code><\/pre>\n<p>\u9700\u8981\u624b\u52a8\u5220\u9664:<\/p>\n<pre><code>$ sudo rm -rf \/etc\/cni\/net.d\n<\/code><\/pre>\n<p>\u6240\u6709node\u4e0a\u5220\u9664flannel\u7684\u7f51\u7edc\u914d\u7f6e<\/p>\n<pre><code>$ sudo ifconfig cni0 down\n$ sudo ip link delete cni0\n$ sudo ifconfig flannel.1 down\n$ sudo ip link delete flannel.1\n$ sudo rm -rf \/run\/flannel\n<\/code><\/pre>\n<p>\u6240\u6709node\u6e05\u7a7aiptables<\/p>\n<pre><code>$ sudo iptables -F\n$ sudo iptables -X\n$ sudo iptables -t nat -F\n$ sudo iptables -t nat -X\n<\/code><\/pre>\n<p>\u5982\u679c\u4f7f\u7528\u4e86IPVS:<\/p>\n<pre><code>$ ipvsadm --clear\n<\/code><\/pre>\n<p>\u5220\u9664\u914d\u7f6e<\/p>\n<pre><code>$ rm -rf $HOME\/.kube\n<\/code><\/pre>\n<h1 id=\"\u90e8\u7f72ha-cluster\">\u90e8\u7f72HA Cluster<\/h1>\n<p>ha\u9700\u8981\u5728\u6240\u6709master\u8282\u70b9\u5b89\u88c5haproxy\u548ckeepalived.<\/p>\n<p><a class=\"link\" href=\"https:\/\/kubernetes.io\/zh\/docs\/setup\/production-environment\/tools\/kubeadm\/high-availability\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kubernetes.io\/zh\/docs\/setup\/production-environment\/tools\/kubeadm\/high-availability\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes\/kubeadm\/blob\/master\/docs\/ha-considerations.md#options-for-software-load-balancing\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes\/kubeadm\/blob\/master\/docs\/ha-considerations.md#options-for-software-load-balancing<\/a><\/p>\n<p>\u5728master1\u4e0a\u521d\u59cb\u5316\uff1a<\/p>\n<pre><code>$ sudo kubeadm init --config .\/kubeadm.yaml -v=6 --upload-certs\n<\/code><\/pre>\n<p>\u52a0\u5165\u5176\u5b83master:<\/p>\n<pre><code>$ sudo kubeadm join 192.168.1.200:8443 --token &lt;token&gt; --discovery-token-ca-cert-hash &lt;hash&gt; --control-plane --certificate-key &lt;key&gt;\n<\/code><\/pre>\n<p>\u52a0\u5165node:<\/p>\n<pre><code>$ sudo kubeadm join 192.168.1.200:8443 --token &lt;token&gt; --discovery-token-ca-cert-hash &lt;hash&gt;\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u914d\u7f6e\">\u914d\u7f6e<\/h1>\n<p><a class=\"link\" href=\"https:\/\/kubernetes.io\/zh\/docs\/setup\/production-environment\/tools\/kubeadm\/control-plane-flags\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kubernetes.io\/zh\/docs\/setup\/production-environment\/tools\/kubeadm\/control-plane-flags\/<\/a><\/p>\n<p>\u4f7f\u7528\u81ea\u5b9a\u4e49\u914d\u7f6e:<\/p>\n<pre><code>$ sudo kubeadm init --config .\/config.yaml -v=6\n<\/code><\/pre>\n<p>\u67e5\u770b\u9ed8\u8ba4\u914d\u7f6e:<\/p>\n<pre><code>$ kubeadm config print init-defaults\n<\/code><\/pre>\n<p>\u914d\u7f6ekubeadm\uff1a<\/p>\n<pre><code>apiVersion: kubeadm.k8s.io\/v1beta2\nkind: InitConfiguration\nbootstrapTokens:\n- groups:\n- system:bootstrappers:kubeadm:default-node-token\ntoken: abcdef.0123456789abcdef\nttl: 24h0m0s\nusages:\n- signing\n- authentication\nlocalAPIEndpoint:\nadvertiseAddress: 10.103.1.1 \/\/ master IP\nbindPort: 6443\nnodeRegistration:\ncriSocket: \/run\/containerd\/containerd.sock\nname: debug \/\/ master hostname\ntaints:\n- effect: NoSchedule\nkey: node-role.kubernetes.io\/master\n<\/code><\/pre>\n<p>\u914d\u7f6ekubernetes:<\/p>\n<pre><code>\/\/ \u5b9a\u5236control plane\n&lt;https:\/\/kubernetes.io\/zh\/docs\/setup\/production-environment\/tools\/kubeadm\/control-plane-flags\/&gt;\napiVersion: kubeadm.k8s.io\/v1beta2\nkind: ClusterConfiguration\ncertificatesDir: \/etc\/kubernetes\/pki\nclusterName: kubernetes\ncontrolPlaneEndpoint: 10.58.203.200:8443 \/\/ HA\u4e2dhaproxy\u7684VIP\u548cport\ndns:\ntype: CoreDNS\netcd:\nlocal:\ndataDir: \/var\/lib\/etcd\nnetworking:\ndnsDomain: cluster.local\nserviceSubnet: 10.96.0.0\/12\npodSubnet: 10.244.0.0\/16 \/\/ for flannel\nimageRepository: k8s.gcr.io\nkubernetesVersion: v1.18.6\ncontrollerManager:\n...\nextraArgs:\n&lt;https:\/\/kubernetes.io\/docs\/reference\/command-line-tools-reference\/kube-controller-manager\/&gt;\nallocate-node-cidrs: 'true'\nnode-cidr-mask-size: '16' \/\/ flannel\u7684SubNetLen\ncluster-cidr: '10.0.0.0\/8' \/\/ flannel\u7684Network\nservice-cluster-ip-range: 10.96.0.0\/12\napiServer:\ntimeoutForControlPlane: 4m0s\n&lt;https:\/\/kubernetes.io\/docs\/reference\/command-line-tools-reference\/kube-apiserver\/&gt;\nextraArgs:\nadvertise-address: 192.168.0.103\nservice-cluster-ip-range: 10.96.0.0\/12\n...\nscheduler:\n...\n&lt;https:\/\/kubernetes.io\/docs\/reference\/command-line-tools-reference\/kube-scheduler\/&gt;\nextraArgs:\n...\n<\/code><\/pre>\n<p>\u4fee\u6539kubelet\u7684cgroup driver:<\/p>\n<pre><code>apiVersion: kubelet.config.k8s.io\/v1beta1\nkind: KubeletConfiguration\ncgroupDriver: systemd\n<\/code><\/pre>"},{"title":"Image","link":"https:\/\/canuxcheng.com\/post\/cncf_image\/","pubDate":"Tue, 03 Dec 2019 21:50:47 +0800","guid":"https:\/\/canuxcheng.com\/post\/cncf_image\/","description":"<h1 id=\"image\">image<\/h1>\n<p>\u5bb9\u5668\u955c\u50cf<\/p>\n<p>docker image driver: aufs, btrfs, devicemapper, overlay.<\/p>\n<h2 id=\"multi-platform-images\">multi-platform images<\/h2>\n<p><a class=\"link\" href=\"https:\/\/docs.docker.com\/build\/building\/multi-platform\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.docker.com\/build\/building\/multi-platform\/<\/a><\/p>\n<h3 id=\"qemu\">qemu<\/h3>\n<p>\u4f7f\u7528qume:<\/p>\n<pre><code>\/\/ \u5b89\u88c5bitfmt\ndocker run --privileged --rm tonistiigi\/binfmt --install all\n\/\/ \u67e5\u770b\u652f\u6301\u7684\u5e73\u53f0\nls -l \/proc\/sys\/fs\/binfmt_misc\/qemu-*\n<\/code><\/pre>\n<h3 id=\"multiple-native-nodes\">multiple native nodes<\/h3>\n<p>\u5b89\u88c5<\/p>\n<pre><code>\/\/ linux\nsudo apt install docker-buildx-plugin\n\/\/ mac\nbrew install docker-buildx\nmkdir -p ~\/.docker\/cli-plugins\nln -sfn $(which docker-buildx) ~\/.docker\/cli-plugins\/docker-buildx\ndocker buildx install\n<\/code><\/pre>\n<p>\u67e5\u770b\u7248\u672c<\/p>\n<pre><code>docker buildx version\n<\/code><\/pre>\n<p>\u7ba1\u7406builder instance<\/p>\n<pre><code>docker buildx create\n--append \u6dfb\u52a0node\u5230builder\u5b9e\u4f8b\u3002\n--leave \u4ecebuilder\u5b9e\u4f8b\u5220\u9664node\n--driver Driver to use(&quot;docker&quot;, &quot;docker-container&quot;, &quot;kubernetes&quot;)\n--name\n--use\n--node\n--platform\n--bootstrap \u542f\u52a8\u5b9e\u4f8b\uff08\u4ee5\u5bb9\u5668\u7684\u5f62\u5f0f\u542f\u52a8\uff09\n\/\/ \u4ee5\u672c\u5730\u662famd64\u4e3a\u4f8b\uff0c\u521b\u5efa\u4e00\u4e2a\u5b9e\u4f8b.\ndocker buildx create --use --bootstrap --platform linux\/amd64,linux\/amd64\/v2,linux\/amd64\/v3,linux\/arm64,linux\/arm\/v7,linux\/arm\/v6 --name canux-builder\n\/\/ \u5982\u679c\u6ca1\u6709qumu\uff0c\u53ef\u4ee5\u628a\u4e0d\u540c\u5e73\u53f0\u7684\u8fdc\u7a0b\u673a\u5668\u52a0\u5230builder\u5b9e\u4f8b.\ndocker buildx create \\\n--name local_remote_builder \\\n--append --node &lt;my-arm-server&gt; \\\n--platform linux\/arm64,linux\/riscv64,linux\/ppc64le,linux\/s390x,linux\/mips64le,linux\/mips64,linux\/arm\/v7,linux\/arm\/v6 \\\nssh:\/\/user@&lt;my-arm-server&gt;\ndocker buildx rm\ndocker buildx stop\ndocker buildx inspect\ndocker buildx use\n\/\/ \u67e5\u770b\u5f53\u524d\u53ef\u7528\u7684builders\ndocker buildx ls\n<\/code><\/pre>\n<p>\u6784\u5efa\u591a\u5e73\u53f0\u955c\u50cf<\/p>\n<pre><code>docker buildx build --platform &lt;p1,p2&gt; ...\n\/\/ \u4e00\u6b21\u7f16\u8bd1\u591a\u4e2a\u5e73\u53f0\u7684\u955c\u50cf\u76f4\u63a5push\u5230registry\u3002\ndocker buildx build --platform linux\/amd64,linux\/amd64\/v2,linux\/amd64\/v3,linux\/arm64,linux\/arm\/v7,linux\/arm\/v6 --push -t name\/target:tag .\n\/\/ \u7f16\u8f91\u6210\u4e0d\u540c\u7684image\ndocker buildx build -o type=docker --platform linux\/amd64 -t name:1.0.0 .\ndocker buildx build -o type=docker --platform linux\/arm64 -t name:1.0.0-linux-arm64 .\n<\/code><\/pre>\n<h3 id=\"cross-compilation\">cross-compilation<\/h3>\n<hr>\n<h2 id=\"overlay\">Overlay<\/h2>\n<p>\u6700\u4e0b\u5c42\u662f\u4e00\u4e2a lower \u5c42\uff0c\u4e5f\u5c31\u662f\u955c\u50cf\u5c42\uff0c\u5b83\u662f\u4e00\u4e2a\u53ea\u8bfb\u5c42\uff1b<\/p>\n<p>\u53f3\u4e0a\u5c42\u662f\u4e00\u4e2a upper \u5c42\uff0cupper \u662f\u5bb9\u5668\u7684\u8bfb\u5199\u5c42\uff0cupper \u5c42\u91c7\u7528\u4e86\u5199\u5b9e\u590d\u5236\u7684\u673a\u5236\uff0c\u4e5f\u5c31\u662f\u8bf4\u53ea\u6709\u5bf9\u67d0\u4e9b\u6587\u4ef6\u9700\u8981\u8fdb\u884c\u4fee\u6539\u7684\u65f6\u5019\u624d\u4f1a\u4ece lower \u5c42\u628a\u8fd9\u4e2a\u6587\u4ef6\u62f7\u8d1d\u4e0a\u6765\uff0c\u4e4b\u540e\u6240\u6709\u7684\u4fee\u6539\u64cd\u4f5c\u90fd\u4f1a\u5bf9 upper \u5c42\u7684\u526f\u672c\u8fdb\u884c\u4fee\u6539\uff1b<\/p>\n<p>upper \u5e76\u5217\u7684\u6709\u4e00\u4e2a workdir\uff0c\u5b83\u7684\u4f5c\u7528\u662f\u5145\u5f53\u4e00\u4e2a\u4e2d\u95f4\u5c42\u7684\u4f5c\u7528\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5f53\u5bf9 upper \u5c42\u91cc\u9762\u7684\u526f\u672c\u8fdb\u884c\u4fee\u6539\u65f6\uff0c\u4f1a\u5148\u653e\u5230 workdir\uff0c\u7136\u540e\u518d\u4ece workdir \u79fb\u5230 upper \u91cc\u9762\u53bb\uff0c\u8fd9\u4e2a\u662f overlay \u7684\u5de5\u4f5c\u673a\u5236\uff1b<\/p>\n<p>\u6700\u4e0a\u9762\u7684\u662f mergedir\uff0c\u662f\u4e00\u4e2a\u7edf\u4e00\u89c6\u56fe\u5c42\u3002\u4ece mergedir \u91cc\u9762\u53ef\u4ee5\u770b\u5230 upper \u548c lower \u4e2d\u6240\u6709\u6570\u636e\u7684\u6574\u5408\uff0c\u7136\u540e\u6211\u4eec docker exec \u5230\u5bb9\u5668\u91cc\u9762\uff0c\u770b\u5230\u4e00\u4e2a\u6587\u4ef6\u7cfb\u7edf\u5176\u5b9e\u5c31\u662f mergedir \u7edf\u4e00\u89c6\u56fe\u5c42\u3002<\/p>\n<pre><code># \u6302\u8f7d\u5230overlay\nmount -t overlay -o lowerdir=\/path\/lower,upperdir=\/path\/upper,workdir=\/path\/work overlay \/path\/di\n<\/code><\/pre>\n<hr>\n<h2 id=\"scratch\">scratch<\/h2>\n<p>scratch\u662f\u7a7a\u767d\u955c\u50cf\uff0c\u4e00\u822c\u7528\u4e8e\u57fa\u7840\u955c\u50cf\u6784\u5efa.\u6bd4\u5982\u5236\u4f5calpine\/ubuntu\/debian\/busybox\u955c\u50cf.<\/p>\n<h2 id=\"ubuntudebian\">ubuntu\/debian<\/h2>\n<p>Hash Sum mismatch:<\/p>\n<pre><code>RUN set -ex \\\n&amp;&amp; apt-get clean \\\n&amp;&amp; apt-get update -o Acquire::CompressionTypes::Order::=gz \\\n&amp;&amp; apt-get update \\\n&amp;&amp; apt-get install -y --allow-unauthenticated --no-install-recommends \\\nbuild-essential \\\n&amp;&amp; rm -rf \/var\/lib\/apt\/lists\/*\n<\/code><\/pre>\n<h2 id=\"centosfedora\">centos\/fedora<\/h2>\n<h2 id=\"buildpack-deps\">buildpack-deps<\/h2>\n<p>\u5728ubuntu\/debian\u57fa\u7840\u4e0a\u5b89\u88c5\u4e00\u4e9b\u5de5\u5177\uff0c\u6bd4ubuntu\/debian\u955c\u50cf\u66f4\u5927.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/docker-library\/buildpack-deps\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/docker-library\/buildpack-deps<\/a><\/p>\n<h2 id=\"busybox\">busybox<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/docker-library\/busybox\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/docker-library\/busybox<\/a><\/p>\n<h2 id=\"alpine\u63a8\u8350\">alpine(\u63a8\u8350)<\/h2>\n<p>\u5f88\u591a\u8bed\u8a00\u7684\u90fd\u662f\u57fa\u4e8ealpine: python-version:alpine-version, golang-version:alpine-version.<\/p>\n<p>\u4e00\u4e2a\u57fa\u4e8emusl\u548cbusybox\u7684linux\u53d1\u884c\u7248.<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.alpinelinux.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.alpinelinux.org\/<\/a><\/p>\n<p>alpine\u6bd4distroless\u5c3a\u5bf8\u5927\uff0c\u5305\u542b\u5305\u7ba1\u7406\u548cshell\uff0c\u65b9\u4fbf\u8c03\u8bd5.<\/p>\n<p>alpine\u4f7f\u7528musl\u4ee3\u66ffglibc\u4f1a\u5bfc\u81f4\u6709\u7684\u7a0b\u5e8f\u65e0\u6cd5\u8fd0\u884c, \u89e3\u51b3:<\/p>\n<pre><code># mkdir \/lib64\n# ln -s \/lib\/libc.musl-x86_64.so.1 \/lib64\/ld-linux-x86-64.so.2\n<\/code><\/pre>\n<p>\u6ce8\u610fwget \u90e8\u5206\u53c2\u6570\u4e0d\u53ef\u7528.<\/p>\n<h2 id=\"distroless\">distroless<\/h2>\n<p>google\u63d0\u4f9b\u7684\u53ea\u5305\u542b\u8fd0\u884c\u65f6\u7684\u7cbe\u7b80\u955c\u50cf.<\/p>\n<p>\u7f3a\u70b9\u662f\u6ca1\u6709\u5305\u7ba1\u7406\u548cshell\uff0c\u4e0d\u65b9\u4fbf\u8c03\u8bd5.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/GoogleContainerTools\/distroless\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/GoogleContainerTools\/distroless<\/a><\/p>\n<h2 id=\"slim\">slim<\/h2>\n<p>\u51cf\u5c0fimage\u5927\u5c0f,\u9002\u7528\u4e8eweb\u7a0b\u5e8f.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/slimtoolkit\/docker-slim\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/slimtoolkit\/docker-slim<\/a><\/p>\n<p>debian\u548cubuntu\u90fd\u6709slim\u7248\u672c\u3002<\/p>\n<p>python:3.13-slim == python:3.13-slim-trixie<\/p>\n<hr>"},{"title":"Helm","link":"https:\/\/canuxcheng.com\/post\/k8s_helm\/","pubDate":"Thu, 05 Sep 2019 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/k8s_helm\/","description":"<h1 id=\"helm\">Helm<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/helm\/helm\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/helm\/helm<\/a><\/p>\n<p>helm2\u6709\u4e24\u4e2a\u7ec4\u4ef6:<\/p>\n<ul>\n<li>helm: \u5ba2\u6237\u7aef<\/li>\n<li>tiller: \u670d\u52a1\u7aef(helm3\u88ab\u79fb\u9664)<\/li>\n<\/ul>\n<p>\u6982\u5ff5:<\/p>\n<ul>\n<li>chart: helm\u5305\uff0c\u5305\u542b\u8fd0\u884c\u4e00\u4e2a\u5e94\u7528\u6240\u9700\u7684\u955c\u50cf\uff0c\u4f9d\u8d56\u548c\u8d44\u6e90.<\/li>\n<li>repository: \u7528\u4e8e\u53d1\u5e03\u548c\u5b58\u50a8chart\u7684\u4ed3\u5e93.<\/li>\n<li>release: \u5728k8s\u96c6\u7fa4\u4e0a\u8fd0\u884c\u7684\u4e00\u4e2achart\u5b9e\u4f8b.<\/li>\n<\/ul>\n<p>repository\u6709\u54ea\u4e9b:<\/p>\n<ul>\n<li>charts: OSS, public, \u5df2\u7ecf\u88abartifacthub\u53d6\u4ee3, <a class=\"link\" href=\"https:\/\/github.com\/helm\/charts\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/helm\/charts<\/a><\/li>\n<li>artifacthub: OSS, public, <a class=\"link\" href=\"https:\/\/artifacthub.io\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/artifacthub.io\/<\/a><\/li>\n<li>chartmuseum: OSS, private, self-host, <a class=\"link\" href=\"https:\/\/github.com\/helm\/chartmuseum\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/helm\/chartmuseum<\/a><\/li>\n<li>harbor: OSS, private, self-host.<\/li>\n<li>artifactory(jfrog): enterprise, private, self-host.<\/li>\n<\/ul>\n<h2 id=\"\u5b89\u88c5\">\u5b89\u88c5<\/h2>\n<p>helm\u548ckubectl\u4e00\u6837\uff0c\u8bbf\u95ee\u6307\u5b9a\u914d\u7f6e\u7684k8s\u96c6\u7fa4\u3002<\/p>\n<p>helm2\u9700\u8981\u5b89\u88c5tiller\u5e76\u4e14\u6267\u884chelm init\u521d\u59cb\u5316,helm\u4e0d\u9700\u8981tiller.<\/p>\n<p>\u672c\u5730\u4e8c\u8fdb\u5236\u5b89\u88c5helm3+:<\/p>\n<pre><code>curl https:\/\/baltocdn.com\/helm\/signing.asc | sudo apt-key add -\nsudo apt-get install apt-transport-https --yes\necho &quot;deb https:\/\/baltocdn.com\/helm\/stable\/debian\/ all main&quot; | sudo tee \/etc\/apt\/sources.list.d\/helm-stable-debian.list\nsudo apt-get update\nsudo apt-get install helm\n<\/code><\/pre>\n<h2 id=\"\u547d\u4ee4\">\u547d\u4ee4<\/h2>\n<h3 id=\"repo\u7ba1\u7406\">repo\u7ba1\u7406<\/h3>\n<p>\u67e5\u770b\u6709\u54ea\u4e9brepo,\u9ed8\u8ba4\u6ca1\u6709repo<\/p>\n<pre><code>$ helm repo list\n<\/code><\/pre>\n<p>\u6dfb\u52a0repo\u5e76\u547d\u540d<\/p>\n<pre><code>$ helm repo add [NAME] [URL] [flags]\n\/\/ \u6dfb\u52a0charts\/artifactoryhub stable\u547d\u540d\u4e3astable\n$ helm repo add stable https:\/\/charts.helm.sh\/stable\n<\/code><\/pre>\n<p>\u66f4\u65b0repo:<\/p>\n<pre><code>$ helm repo update\n<\/code><\/pre>\n<h3 id=\"chart\u7ba1\u7406\">chart\u7ba1\u7406<\/h3>\n<p>\u4ecerepo\u4e2d\u67e5\u627echart:<\/p>\n<pre><code>$ helm search hub [KEYWORD] [flags]\n<\/code><\/pre>\n<p>\u4ecerepo\u91cc\u9762\u7684chart\u91cc\u9762\u641c\u7d22\u5173\u952e\u5b57:<\/p>\n<pre><code>$ helm search repo [keyword] [flags]\n\/\/\u67e5\u770brepo\u91cc\u9762\u6240\u6709chart\n$ helm search repo\n\/\/ \u67e5\u770brepo\u91cc\u9762\u6240\u6709treafik chart\n$ helm search repo traefik\n<\/code><\/pre>\n<p>\u67e5\u770bchart\u4fe1\u606f:<\/p>\n<pre><code>helm show chart traefik\/traefik\nhelm show values traefik\/traefik &gt; value.yaml\n<\/code><\/pre>\n<p>\u4e0b\u8f7dchart:<\/p>\n<pre><code>helm pull chart-name\n<\/code><\/pre>\n<h3 id=\"release\u7ba1\u7406\">release\u7ba1\u7406<\/h3>\n<p>install\/upgrade\/uninstall\/rollback<\/p>\n<p>status\/list\/get\/history<\/p>\n<p>\u5b89\u88c5chart:<\/p>\n<pre><code>helm install [name] [chart] [flags]\n\/\/ \u9a8c\u8bc1\u7b7e\u540d\nhelm install --verify ...\nhelm install traefik traefik\/traefik\n\/\/ \u9700\u63d0\u524d\u521b\u5efanamespace, \u4fee\u6539value\nhelm install kubernetes-dashboard kubernetes-dashboard\/kubernetes-dashboard -f value.yaml -n kubernetes-dashboard\n<\/code><\/pre>\n<p>\u67e5\u770brelease(\u6bcf\u4e2ainstall\u90fd\u662f\u4e00\u4e2arelease):<\/p>\n<pre><code>helm list\n-a, --all show all releases without any filter applied.\n-A, --all-namespaces list releases across all namespaces.\n<\/code><\/pre>\n<p>\u5378\u8f7drelease:<\/p>\n<pre><code>helm uninstall kubernetes-dashboard -n kubernetes-dashboard\n<\/code><\/pre>\n<p>\u67e5\u770b\u72b6\u6001:<\/p>\n<pre><code>helm status mysql\n<\/code><\/pre>\n<p>\u83b7\u53d6release\u4fe1\u606f:<\/p>\n<pre><code>helm get manifest [name]\n<\/code><\/pre>\n<h3 id=\"misc\">misc<\/h3>\n<pre><code>helm plugin\nhelm env\n<\/code><\/pre>\n<hr>\n<h2 id=\"chart\u5f00\u53d1\">chart\u5f00\u53d1<\/h2>\n<p>\u521b\u5efachart:<\/p>\n<pre><code>helm create my-chart\n<\/code><\/pre>\n<p>debug chart\uff1a<\/p>\n<pre><code>\/\/ \u68c0\u67e5\u8bed\u6cd5\nhelm lint my-chart\n\/\/ \u6a21\u62df\u5b89\u88c5\nhelm install my-chart .\/my-chart --dry-run --debug\n<\/code><\/pre>\n<p>\u6a21\u677f\u7ba1\u7406:<\/p>\n<pre><code>helm template [name] [chart]\n\/\/ \u5728\u672c\u5730\u6e32\u67d3\u6a21\u677f\nhelm template my-chart .\/my-chart\n<\/code><\/pre>\n<p>\u4f9d\u8d56chart\u7ba1\u7406:<\/p>\n<pre><code>helm dependency\n\/\/ \u5c06\u4f9d\u8d56\u7684chart\u4e0b\u8f7d\u5230chart\u76ee\u5f55.\nhelm dep up &lt;chart-name&gt;\n<\/code><\/pre>\n<p>\u6d4b\u8bd5chart:<\/p>\n<pre><code>helm test\n<\/code><\/pre>\n<p>\u6253\u5305chart:<\/p>\n<p><a class=\"link\" href=\"https:\/\/helm.sh\/zh\/docs\/topics\/provenance\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/helm.sh\/zh\/docs\/topics\/provenance\/<\/a><\/p>\n<pre><code>helm package my-chart\n\/\/ \u4f1a\u53e6\u5916\u751f\u6210\u4e00\u4e2a.prov\u6587\u4ef6\nhelm package --sign --key &quot;Canux&quot; --keyring ~\/.gnupg\/secring.gpg my-chart\n<\/code><\/pre>\n<p>\u9a8c\u8bc1\u6253\u5305\u7684chart:<\/p>\n<pre><code>helm verify my-chart.tgz\n<\/code><\/pre>\n<p>\u751f\u6210index\u6587\u4ef6:<\/p>\n<pre><code>helm repo index my-chart-folder --url &lt;repo-url&gt;\n<\/code><\/pre>\n<p>\u4e0a\u4f20chart\u5230registry\uff1a<\/p>\n<p>\u6709\u7684registry\u652f\u6301ui\u4e0a\u76f4\u63a5upload\uff0c\u6216\u8005CLI\u4e0a\u4f20\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7helm push\u4e0a\u4f20.<\/p>\n<pre><code>helm registry login\nhelm push my-chart.tgz oci:\/\/registry\/helm-charts\nhelm registry logout\n<\/code><\/pre>\n<p>\u5982\u679c\u662fOCI registry\u76ee\u524d\u53ea\u652f\u6301\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>helm registry login\/logout\nhelm push\nhelm pull\nhelm show\nhelm template\nhelm install\nhelm upgrade\n<\/code><\/pre>\n<p>chart \u76ee\u5f55:<\/p>\n<pre><code>values.yaml\nChart.yaml\ncharts\/\ntemplates\/\ntemplates\/tests\/\n<\/code><\/pre>\n<p>Chart.yaml\u8bed\u6cd5:<\/p>\n<p><a class=\"link\" href=\"https:\/\/helm.sh\/zh\/docs\/topics\/charts\/#chartyaml-%E6%96%87%E4%BB%B6\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/helm.sh\/zh\/docs\/topics\/charts\/#chartyaml-%E6%96%87%E4%BB%B6<\/a><\/p>\n<p>template\u7684\u6d41\u63a7\u5236:<\/p>\n<p><a class=\"link\" href=\"https:\/\/helm.sh\/zh\/docs\/chart_template_guide\/control_structures\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/helm.sh\/zh\/docs\/chart_template_guide\/control_structures\/<\/a><\/p>\n<pre><code>\/\/ \u7528$\u4ee3\u66ff. \u6765\u83b7\u53d6\u4e0a\u4e00\u7ea7\u7684\u53d8\u91cf\n{{- range .Values.worker }}\napiVersion: apps\/v1\nkind: Deployment\nmetadata:\nname: {{ include &quot;app.fullname&quot; $ }}-worker-{{ .name }}\nlabels:\n{{- include &quot;worker.labels&quot; $ | nindent 4 }}\nspec:\n{{- if not .autoscaling.enabled }}\nreplicas: {{ $.Values.replicaCount }}\n{{- end }}\n......\n---\n{{- end }}\n<\/code><\/pre>\n<p>template\u7684\u51fd\u6570:<\/p>\n<p><a class=\"link\" href=\"https:\/\/helm.sh\/zh\/docs\/chart_template_guide\/function_list\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/helm.sh\/zh\/docs\/chart_template_guide\/function_list\/<\/a><\/p>\n<p>hooks:<\/p>\n<p>helm uninstall \u4e0d\u4f1a\u5220\u9664\u6709hook\u7684\u8d44\u6e90\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/helm.sh\/zh\/docs\/topics\/charts_hooks\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/helm.sh\/zh\/docs\/topics\/charts_hooks\/<\/a><\/p>\n<pre><code> annotations:\n# This is what defines this resource as a hook. Without this line, the\n# job is considered part of the release.\n&quot;helm.sh\/hook&quot;: post-install, pre-install, ...\n&quot;helm.sh\/hook-weight&quot;: &quot;-5&quot;\n&quot;helm.sh\/hook-delete-policy&quot;: hook-succeeded, hook-failed, ...\n<\/code><\/pre>"},{"title":"K8S CRI","link":"https:\/\/canuxcheng.com\/post\/k8s_cri\/","pubDate":"Wed, 05 Jun 2019 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/k8s_cri\/","description":"<h1 id=\"cri\">CRI<\/h1>\n<p>CRI: Container Runtime Intarface<\/p>\n<p>\u5b9a\u4e49\u4e86k8s\u548ccontainer runtime\u8fdb\u884c\u4ea4\u4e92\u7684\u63a5\u53e3.<\/p>\n<p>\u662fk8s\u4e0econtainer\u4ea4\u4e92\u7684\u6807\u51c6.<\/p>\n<p><a class=\"link\" href=\"https:\/\/kubernetes.io\/zh\/docs\/setup\/production-environment\/container-runtimes\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kubernetes.io\/zh\/docs\/setup\/production-environment\/container-runtimes\/<\/a><\/p>\n<ul>\n<li>containerd<\/li>\n<li>cri-o<\/li>\n<li>rkt<\/li>\n<li>kata<\/li>\n<li>rancher<\/li>\n<\/ul>\n<hr>\n<h2 id=\"docker\">docker<\/h2>\n<p>k8s_1.20 \u5f00\u59cb\u8b66\u544a\u4e0d\u518d\u652f\u6301docker.<\/p>\n<p>k8s_1.23 \u5f00\u59cb\u79fb\u9664dockershim.<\/p>\n<p>\/var\/run\/dockerhsim.sock<\/p>\n<h2 id=\"containerd\">containerd<\/h2>\n<p>\/run\/container\/containerd.sock<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/containerd\/containerd\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/containerd\/containerd<\/a><\/p>\n<p>\u5b89\u88c5\u914d\u7f6e:<\/p>\n<p><a class=\"link\" href=\"https:\/\/kubernetes.io\/zh\/docs\/setup\/production-environment\/container-runtimes\/#containerd\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kubernetes.io\/zh\/docs\/setup\/production-environment\/container-runtimes\/#containerd<\/a><\/p>\n<h2 id=\"cri-o\">CRI-O<\/h2>\n<p>redhat.<\/p>\n<p>\/var\/run\/crio\/crio.sock<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/cri-o\/cri-o\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/cri-o\/cri-o<\/a><\/p>\n<h2 id=\"kata\">kata<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kata-containers\/runtime\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kata-containers\/runtime<\/a><\/p>\n<h2 id=\"rkt\">rkt<\/h2>\n<p>redhat(coreos)<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/rkt\/rkt\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/rkt\/rkt<\/a><\/p>\n<hr>"},{"title":"Virtualbox","link":"https:\/\/canuxcheng.com\/post\/virtualbox\/","pubDate":"Mon, 03 Jun 2019 22:53:23 +0800","guid":"https:\/\/canuxcheng.com\/post\/virtualbox\/","description":"<h1 id=\"virtualbox\">Virtualbox<\/h1>\n<p>\u865a\u62df\u5316\u5de5\u5177virtualbox.<\/p>\n<h1 id=\"vboxmanage\">vboxmanage<\/h1>\n<p>vm<\/p>\n<pre><code>\/\/ \u5bfc\u5165ova\n$ vboxmanage import win7.ova\n\/\/ \u6dfb\u52a0host\u7f51\u7edc\n$ vboxmanage modifyvm &quot;win764&quot; --nic1 hostonly --hostonlyadapter1 vboxnet0\n\/\/ \u6dfb\u52a0bridge\u7f51\u7edc\n$ vboxmanage modifyvm &quot;Win732&quot; --nic2 bridged --bridgeadapter2 docker_gwbridge\n\/\/ \u91cd\u547d\u540dvm\n$ vboxmanage modifyvm &lt;vm&gt; --name &lt;new-name&gt;\n\/\/ \u4fee\u6539\u53c2\u6570\n$ vboxmanage modifyvm &lt;vm&gt; --memory 4096 --cpus 4 --hwvirtex on --ioapic on\n\/\/ \u542f\u52a8\u865a\u62df\u673a\n$ vboxmanage startvm &quot;Win732&quot;\n$ vboxmanage startvm &lt;vm&gt; --type headless\n$ VBoxHeadless --startvm &lt;uuid|name&gt; --vrde on\n\/\/ \u63a7\u5236\u865a\u62df\u673a\n$ vboxmanage controlvm &lt;vm&gt; pause\/resume\/reset\/poweroff\/savestate\n\/\/ \u67e5\u770b\u6240\u6709\/\u8fd0\u884c\u865a\u62df\u673a\n$ vboxmanage list vms\/runningvms\n\/\/ \u5220\u9664vm\n$ vboxmanage unregistervm &lt;vm&gt; --delete\n\/\/ linux\u4e0a\u6267\u884c\u547d\u4ee4\n$ vboxmanage guestcontrol {} --username {} --password {} run --exe \/bin\/bash -- -l -c 'pwd'\n\/\/ windows\u4e0a\u6267\u884c\u547d\u4ee4\n$ vboxmanage guestcontrol {} --username 'Administrator' run --exe 'C:\\\\Program Files\\\\Oracle\\\\VirtualBox Guest Additions\\\\uninst.exe' -- uninst.exe \/S\n<\/code><\/pre>\n<p>media<\/p>\n<pre><code>\/\/ \u5217\u51fa\u6240\u6709hdd\n$ vboxmanage list hdds\n\/\/ \u5220\u9664hdd\n$ vboxmanage closemedium disk &lt;uuid&gt; --delete\n<\/code><\/pre>\n<p>snapshot<\/p>\n<pre><code>\/\/\u67e5\u770b\u5feb\u7167\n$ vboxmanage snapshot &lt;vm&gt; list\n$ vboxmanage snapshot &lt;vm&gt; take &lt;name&gt; --live --pause \/\/ \u521b\u5efa\u5feb\u7167\n$ vboxmanage snapshot &lt;vm&gt; delete &lt;snapshot-name\/uuid&gt; \/\/ \u5220\u9664\u5feb\u7167\n$ vboxmanage snapshot &lt;vm&gt; restore\u00a0&lt;name&gt;\n<\/code><\/pre>\n<p>hostonly-network<\/p>\n<pre><code>$ vboxmanage hostonlyif crate \/\/ \u521b\u5efahostonly bridge\n$ vboxmanage hostonlyif ipconfig vboxnet0 --ip 192.168.1.1 --netmask 255.255.255.0 \/\/ \u7ed9hostonly bridge\u5206\u914dip\u548cnetmask.\n$ vboxmanage hostonlyif remove &lt;name&gt;\n\/\/ \u67e5\u770b\u6240\u6709hostonly\u7f51\u8def\n$ vboxmanage list hostonlyifs\n<\/code><\/pre>\n<p>bridge-network<\/p>\n<p>nat-network<\/p>\n<p>storage<\/p>\n<p>extpack<\/p>\n<pre><code>\/\/ \u5b89\u88c5\u6269\u5c55\u5305\n$ sudo vboxmanage extpack install Oracle_VM_VirtualBox_Extension_Pack-6.0.8.vbox-extpack\n$ sudo vboxmanage extpack uninstall \\\n&quot;Oracle VM VirtualBox Extension Pack&quot;\n<\/code><\/pre>"},{"title":"Package","link":"https:\/\/canuxcheng.com\/post\/go_package\/","pubDate":"Tue, 23 Apr 2019 21:42:07 +0800","guid":"https:\/\/canuxcheng.com\/post\/go_package\/","description":{}},{"title":"Command","link":"https:\/\/canuxcheng.com\/post\/network_command\/","pubDate":"Sun, 31 Mar 2019 21:51:25 +0000","guid":"https:\/\/canuxcheng.com\/post\/network_command\/","description":"<h1 id=\"network-command\">network command<\/h1>\n<p>network related command<\/p>\n<hr>\n<h2 id=\"net-tools\">net-tools<\/h2>\n<p>deprecated<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/ecki\/net-tools\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/ecki\/net-tools<\/a><\/p>\n<pre><code>$ sudo apt-get install net-tools\n<\/code><\/pre>\n<h3 id=\"ifconfig\">ifconfig<\/h3>\n<p>\u67e5\u770b\u672c\u5730\u7f51\u7edc\u63a5\u53e3\u72b6\u6001\u548c\u6d41\u91cf<\/p>\n<pre><code>ifconfig # \u67e5\u770bup\u7684interface\nifconfig -a # \u67e5\u770b\u6240\u6709\u7684interface\nifconfig &lt;interface&gt; # \u67e5\u770b\u6307\u5b9a\u7684interface\nifconfig &lt;bridge&gt;\/&lt;interface&gt; up\/down\n<\/code><\/pre>\n<h3 id=\"netstat\">netstat<\/h3>\n<p>\u7528\u4e8e\u67e5\u770b\u7f51\u7edc\u8fde\u63a5\u3001\u8def\u7531\u8868\u3001\u63a5\u53e3\u7edf\u8ba1\u7b49\u4fe1\u606f.<\/p>\n<pre><code>netstat\n-a, --all, --listening # \u663e\u793a\u6240\u6709socket, \u9ed8\u8ba4\u53ea\u663e\u793aconnected\n-l, --listening # \u663e\u793alistening\n-n, --numeric\n-p, --programs # \u663e\u793apid\u6216\u7a0b\u5e8f\u540d\u79f0\n# socket\u9009\u9879:\n-t, --tcp\n-u, --udp\n-w, --raw\n-x, --unix\n--ax25\n--ipx\n--netrom\n# \u5e38\u7528\nnetstat -anp # \u67e5\u770b\u54ea\u4e9b\u7aef\u53e3\u662f\u6253\u5f00\u7684\uff0e\nsudo netstat -anp | grep port # \u67e5\u770b\u7aef\u53e3\u662f\u5426\u88ab\u4f7f\u7528\nsudo netstat -tulnp # \u67e5\u770btcp&amp;udp\u7aef\u53e3\u662f\u5426\u88ab\u76d1\u542c\n<\/code><\/pre>\n<h3 id=\"arp\">arp<\/h3>\n<pre><code>arp # \u7528\u4e8e\u786e\u5b9aIP\u5730\u5740\u7684\u7f51\u5361\u7269\u7406\u5730\u5740\n<\/code><\/pre>\n<h3 id=\"route\">route<\/h3>\n<p>Flags:<\/p>\n<ul>\n<li>U: route is up<\/li>\n<li>H: target is a host<\/li>\n<li>G: use gateway<\/li>\n<li>!: reject route<\/li>\n<\/ul>\n<p>Genmask: netmask for destination net.<\/p>\n<p>Metric: \u5230target\u8ddd\u79bb, hops.<\/p>\n<p>Ref: \u8be5\u8def\u7531\u5f15\u7528\u6b21\u6570<\/p>\n<p>Use: \u67e5\u627e\u8def\u7531\u7684\u6b21\u6570<\/p>\n<pre><code>route -n\n<\/code><\/pre>\n<h3 id=\"rarp\">rarp<\/h3>\n<h3 id=\"hostname\">hostname<\/h3>\n<h3 id=\"domainname\">domainname<\/h3>\n<h3 id=\"dnsdomainname\">dnsdomainname<\/h3>\n<hr>\n<h2 id=\"iproute2\">iproute2<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/shemminger\/iproute2\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/shemminger\/iproute2<\/a><\/p>\n<pre><code>$ sudo apt-get install iproute2\n<\/code><\/pre>\n<h3 id=\"ss\">ss<\/h3>\n<p>\u53d6\u4ee3netstat, \u7528\u4e8e\u67e5\u770bsocket\u8fde\u63a5\u72b6\u6001.<\/p>\n<pre><code>ss -s # \u67e5\u770bsocket\u7edf\u8ba1\u4fe1\u606f\nss -tuln # \u67e5\u770btcp\u548cudp\u7684\u76d1\u542c\u7aef\u53e3\nss -tulnp # \u67e5\u770btcp\u548cudp\u7684\u76d1\u542c\u7aef\u53e3\u548c\u5bf9\u5e94\u7684\u7a0b\u5e8f\n<\/code><\/pre>\n<h3 id=\"ip\">ip<\/h3>\n<p>\u53d6\u4ee3ifconfig, route, arp\u7b49\u547d\u4ee4\u7684\u96c6\u5408.<\/p>\n<pre><code>ip link show\n# \u521b\u5efavlan\nip link add link eth1 name eth1.10 type vlan id 10\n# \u6dfb\u52a0ip\nip addr add 192.168.100.1\/24 brd 192.168.100.255 dev eth1.10\n# \u542f\u52a8vlan\nip link set dev eth1.10 up\n# \u5173\u95edvlan\nip link set dev eth1.10 down\n# \u5220\u9664vlan\nip link delete eth1.10\n<\/code><\/pre>\n<p>addr\/address<\/p>\n<pre><code>ip addr show &lt;interface&gt; # \u67e5\u770b\u6307\u5b9ainterface\u7684ip\u5730\u5740\n<\/code><\/pre>\n<p>route<\/p>\n<pre><code>ip route show # \u67e5\u770b\u8def\u7531\u8868\n<\/code><\/pre>\n<p>rule<\/p>\n<pre><code>ip rule showa # \u67e5\u770b\u89c4\u5219\n<\/code><\/pre>\n<h3 id=\"devlink\">devlink<\/h3>\n<h3 id=\"ifstat\">ifstat<\/h3>\n<h3 id=\"bridge\">bridge<\/h3>\n<p>\u7528\u4e8e\u7ba1\u7406bridge, \u53d6\u4ee3brctl.<\/p>\n<pre><code>$ bridge link show # \u67e5\u770bbridge\u7684\u63a5\u53e3\n<\/code><\/pre>\n<hr>\n<h2 id=\"iputils\">iputils<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/iputils\/iputils\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/iputils\/iputils<\/a><\/p>\n<pre><code>$ sudo apt-get install iputils-ping\n<\/code><\/pre>\n<h3 id=\"ping\">ping<\/h3>\n<p>round-trip time\/RTT: \u5f80\u8fd4\u65f6\u95f4, \u5373\u4ece\u53d1\u9001\u6570\u636e\u5305\u5230\u63a5\u6536\u6570\u636e\u5305\u7684\u65f6\u95f4.<\/p>\n<pre><code>ping # \u7528\u4e8e\u786e\u5b9a\u7f51\u7edc\u7684\u8fde\u901a\u6027\nping -c 5 &lt;host&gt; # \u53d1\u90015\u4e2a\u5305\n<\/code><\/pre>\n<h3 id=\"arping\">arping<\/h3>\n<h3 id=\"tracepath\">tracepath<\/h3>\n<h3 id=\"clockdiff\">clockdiff<\/h3>\n<hr>\n<h2 id=\"traceroute\">traceroute<\/h2>\n<pre><code>sudo apt install traceroute\n<\/code><\/pre>\n<p>\u8def\u7531\u8ddf\u8e2a\u4e0e\u8df3\u6570\u68c0\u67e5<\/p>\n<pre><code>traceroute &lt;host&gt; # \u8ddf\u8e2a\u5230host\u7684\u8def\u7531\n# \u901a\u8fc7\u6307\u5b9a\u7aef\u53e3\u53f7\u6765\u8ddf\u8e2a\ntraceroute -p &lt;port&gt; &lt;host&gt;\n# \u4f7f\u7528tcp\u534f\u8bae\ntraceroute -T &lt;host&gt;\n# \u4f7f\u7528udp\u534f\u8bae\ntraceroute -U &lt;host&gt;\n<\/code><\/pre>\n<hr>\n<h2 id=\"tcpdump\">tcpdump<\/h2>\n<pre><code>sudo apt-get install tcpdump\ntcpdump\ntcpdump tcp port &lt;port&gt; # \u6293tcp \u5728port\u7aef\u53e3\u7684\u5305\ntcpdump udp port &lt;port&gt; #\u6293udp \u5728port\u7aef\u53e3\u7684\u5305\ntcpdump -i &lt;interface&gt; # \u6293\u53d6\u6307\u5b9ainterface\u7684\u5305\ntcpdump host &lt;ip&gt; and port &lt;port&gt; # \u6293\u53d6\u6307\u5b9aip\u548c\u7aef\u53e3\u7684\u5305\ntcpdump net &lt;network&gt; # \u6293\u53d6\u6307\u5b9a\u7f51\u7edc\u7684\u5305\n<\/code><\/pre>\n<hr>\n<h2 id=\"ncnetcat\">nc\/netcat<\/h2>\n<pre><code>\/\/ \u6709\u7684\u7cfb\u7edf\u9ed8\u8ba4\u5b89\u88c5netcat-traditional\n$ sudo apt-get install netcat-traditional\n\/\/ \u5b89\u88c5netcat-openbsd\n$ sudo apt-get install netcat-openbsd\n\/\/ \u8bbe\u7f6e\u9ed8\u8ba4\u503c\n$ sudo update-alternatives --config nc\n$ sudo update-alternatives --set nc \/bin\/nc.openbsd\nnc -z IP PORT # \u67e5\u770b\u6307\u5b9atcp:\/\/ip:port\u662f\u5426\u76d1\u542c\nnc -zu IP PORT # \u67e5\u770budp:\/\/ip:port\u662f\u5426\u76d1\u542c\n\/\/ \u901a\u8fc7nc\u76d1\u542c\u7aef\u53e3\nnc -l PORT\n\/\/ \u901a\u8fc7nc\u53d1\u9001\u8bf7\u6c42.\necho -e '{&quot;method&quot;:&quot;test&quot;,&quot;params&quot;:[&quot;test&quot;],&quot;id&quot;:1}' | nc IP PORT\n<\/code><\/pre>\n<hr>\n<h2 id=\"dnsutils\">dnsutils<\/h2>\n<pre><code>sudo apt-get install dnsutils\n<\/code><\/pre>\n<h3 id=\"nslookup\">nslookup<\/h3>\n<pre><code>nslookup # \u67e5\u8be2IP\u5730\u5740\u548c\u5bf9\u5e94\u7684\u57df\u540d\n<\/code><\/pre>\n<h3 id=\"dig\">dig<\/h3>\n<pre><code>dig # \u67e5\u8be2DNS\u8bb0\u5f55\ndig @&lt;dns-server&gt; &lt;domain&gt; # \u6307\u5b9adns\u670d\u52a1\u5668\u67e5\u8be2\u57df\u540d\ndig &lt;domain&gt; A # \u67e5\u8be2A\u8bb0\u5f55\ndig &lt;domain&gt; MX # \u67e5\u8be2MX\u8bb0\u5f55\ndig &lt;domain&gt; NS # \u67e5\u8be2NS\u8bb0\u5f55\ndig &lt;domain&gt; TXT # \u67e5\u8be2TXT\u8bb0\u5f55\ndig &lt;domain&gt; ANY # \u67e5\u8be2\u6240\u6709\u8bb0\u5f55\n# \u53cd\u5411\u89e3\u6790IP\u5730\u5740\ndig -x &lt;ip-address&gt;\n<\/code><\/pre>\n<h3 id=\"nsupdate\">nsupdate<\/h3>\n<h3 id=\"host\">host<\/h3>\n<hr>\n<h2 id=\"ethtool\">ethtool<\/h2>\n<pre><code>sudo apt-get install ethtool\nethtool # \u67e5\u8be2\u7f51\u7edc\u8bbe\u5907\u4fe1\u606f\nethtool &lt;interface&gt; # \u67e5\u8be2\u6307\u5b9a\u7f51\u7edc\u8bbe\u5907\u4fe1\u606f\n<\/code><\/pre>\n<hr>\n<h2 id=\"iftop\">iftop<\/h2>\n<p><a class=\"link\" href=\"http:\/\/www.ex-parrot.com\/~pdw\/iftop\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.ex-parrot.com\/~pdw\/iftop\/<\/a><\/p>\n<pre><code>$ sudo apt-get install iftop\nsudo iftop # \u67e5\u770b\u7f51\u7edc\u6d41\u91cf\nsudo iftop -i &lt;interface&gt; # \u67e5\u770b\u6307\u5b9a\u7f51\u7edc\u63a5\u53e3\u7684\u6d41\u91cf\n<\/code><\/pre>\n<hr>\n<h2 id=\"iperf3\">iperf3<\/h2>\n<hr>\n<h2 id=\"wget\">wget<\/h2>\n<pre><code>wget [option] [URL]\n-a, --append-output=FILE \u8f93\u51fa\u91cd\u5b9a\u5411\u5230\u65e5\u5fd7\n-o, --output-file=FILE\n-q, --quiet \u4e0d\u8f93\u51fa\n-b, --background\n-nv, --no-verbose\n--header &quot;authorization:c2FuZGJveDpTMG5pY3dhbGwK&quot;\n-t, --tries=NUMBER \u8d85\u65f6\u91cd\u8fde\u6b21\u6570, 0\u8868\u793a\u4e0d\u9650\u5236, \u9ed8\u8ba420\n-nc, --no-clobber \u4e0d\u8986\u76d6\u539f\u6709\u6587\u4ef6\n-N, --timestamping \u53ea\u4e0b\u8f7d\u6bd4\u672c\u5730\u65b0\u7684\u6587\u4ef6\n-c, --continue \u65ad\u70b9\u7eed\u4f20,\u4f1a\u8986\u76d6-N\n-T, --timeout=SECONDS \u8d85\u65f6\u65f6\u95f4, \u9ed8\u8ba4900s\n-w, --wait=SECONDS \u91cd\u8fde\u4e4b\u95f4\u7684\u7b49\u5f85\u65f6\u95f4\n-O, --output-document=FILE, \u91cd\u547d\u540d\u4e0b\u8f7d\u6587\u4ef6\n-nH, --no-host-directories \u4e0d\u521b\u5efa\u7ad9\u70b9\u7684\u6839\u76ee\u5f55\n-x, --force-directories \u521b\u5efa\u548c\u670d\u52a1\u5668\u4e00\u6837\u7684\u7ed3\u6784\u4e0b\u8f7d\n-P, --directory-prefix=PREFIX \u6307\u5b9a\u4e0b\u8f7d\u7684\u76ee\u5f55\n-R, --reject=LIST \u6392\u9664\u4e0b\u8f7d\u7684\u6587\u4ef6\n-r, --recursive \u8fed\u4ee3\u4e0b\u8f7d\n-np, --no-parent \u4e0d\u4e0b\u8f7d\u7236\u76ee\u5f55\u7684\u5185\u5bb9\n# \u540c\u6b65\u76ee\u5f55\nwget -Nc -r -np -nH --cut-dirs=3 -R &quot;index.*, *.js, *.css, *.html, *.jpg, *.png, *.gif&quot; -P \/path\/to\/source\/ http:\/\/host\/path\/to\/dest\/\n# ssl + basic auth\nwget --no-check-certificate --user &lt;user&gt; --password &lt;pw&gt; -nv -N -P &lt;dest-folder&gt; &lt;src-url&gt;\n$ wget -q -N -P \/folder url\n$ wget -q -c -O \/path\/to\/file.ext url\n<\/code><\/pre>\n<h2 id=\"curl\">curl<\/h2>\n<pre><code>curl\n-X\/--request post\/patch\/delte\/get\/...\n-H\/--header 'content-type: application\/json'\n-d\/--data '{&quot;key&quot;: &quot;value&quot;}'\n--data-raw DATA HTTP POST data, '@' allowed (H)\n--data-ascii DATA HTTP POST ASCII data (H)\n--data-binary DATA HTTP POST binary data (H)\n--data-urlencode DATA HTTP POST data url encoded (H)\n-G, --get Send the -d data with a HTTP GET (H)\n-k\/--insecure ignore ssl check.\n-u\/--user &lt;user:password&gt;\n-s\/--silent Silent mode\n<\/code><\/pre>"},{"title":"Command","link":"https:\/\/canuxcheng.com\/post\/storage_command\/","pubDate":"Sun, 31 Mar 2019 21:51:25 +0000","guid":"https:\/\/canuxcheng.com\/post\/storage_command\/","description":"<h1 id=\"sysstat\">sysstat:<\/h1>\n<pre><code># &lt;https:\/\/github.com\/sysstat\/sysstat&gt;\n$ sudo apt-get install sysstat\n# \u5305\u62ec iostat\/mpstat\/pidstat\/tapestat\/cifsiostat\niostat -d -x -k 1 10\npidstat -d -p pid\n<\/code><\/pre>\n<h1 id=\"iotop\">iotop<\/h1>\n<pre><code># \u67e5\u770b\u8fdb\u7a0b\u7684diskio\n$ sudo apt-get install iotop\n$ sudo iotop\n<\/code><\/pre>\n<h1 id=\"df\">df<\/h1>\n<p>df\u8ba1\u7b97\u6587\u4ef6\u7cfb\u7edf\u78c1\u76d8\u7a7a\u95f4\u4f7f\u7528:<\/p>\n<pre><code>df\n$ df -h\n# \u67e5\u770b\u76ee\u5f55\u4fe1\u606f(\u8bfb\u5199\u54ea\u4e2a\u8bbe\u5907)\n$ df \/path\/folder\n<\/code><\/pre>\n<h1 id=\"dd\">dd<\/h1>\n<p>dd\u8f6c\u5316\u5e76\u62f7\u8d1d\u6587\u4ef6:<\/p>\n<pre><code>dd\n<\/code><\/pre>\n<h1 id=\"fsck\">fsck<\/h1>\n<p>fsck\u68c0\u67e5\u5e76\u4fee\u590d\u6587\u4ef6\u7cfb\u7edf:<\/p>\n<pre><code>fsck\n<\/code><\/pre>\n<h1 id=\"fdisk\">fdisk<\/h1>\n<p>\u652f\u6301msdos\uff0c\u652f\u63012T\u4ee5\u4e0b\u7684\u78c1\u76d8.<\/p>\n<p>fdisk\u7ba1\u7406\u78c1\u76d8\u5206\u533a\u8868:<\/p>\n<pre><code>fdisk\nfdisk -l\nfdisk \/dev\/sda # \u53ef\u4ee5\u521b\u5efa\u65b0\u7684\u78c1\u76d8\u5206\u533a\n&gt; n ... \u521b\u5efa\u65b0\u7684\u5206\u533a\n&gt; t (8e\u8868\u793alinux LVM), \u4fee\u6539\u5206\u533a\u7c7b\u578b\n&gt; w \u4fdd\u5b58\u4fee\u6539\npartprobe \/dev\/sda # \u5728\u4e0d\u91cd\u542f\u7684\u60c5\u51b5\u4e0b\u4fdd\u5b58\u5206\u533a\n<\/code><\/pre>\n<h1 id=\"parted\">parted<\/h1>\n<p>\u652f\u6301gpt\u5206\u533a\u8868\uff0c\u652f\u63012T\u4ee5\u4e0a\u7684\u5927\u78c1\u76d8.<\/p>\n<p>\u5927\u5b58\u50a8\u5206\u533a\u5de5\u5177,\u6bd4\u5982nas,raid.<\/p>\n<pre><code>parted \/dev\/sda print\n<\/code><\/pre>\n<h1 id=\"mkfd\">mkfd<\/h1>\n<p>mkfs:<\/p>\n<pre><code>mkfs [options] [-t type fs-options] device [size]\nmkfs.ext4 \/dev\/sdb1 # \u5c06\u5206\u533a\u683c\u5f0f\u5316\u6210ext4\u683c\u5f0f.\n<\/code><\/pre>\n<h1 id=\"mountumount\">mount\/umount<\/h1>\n<p>\u76f8\u5173\u6587\u4ef6:<\/p>\n<pre><code>\/etc\/fstab\n\/etc\/mtab\n\u67e5\u770b\u78c1\u76d8\u7684uuid, \u901a\u8fc7uuid\u6302\u8f7d\nls -l \/dev\/disk\/by-uuid\n<\/code><\/pre>\n<p>mount\/umount\u6302\u8f7d\u6587\u4ef6\u7cfb\u7edf:<\/p>\n<pre><code>mount # \u67e5\u770b\u6240\u6709\u6302\u8f7d\u4fe1\u606f\nmount -t type -o option device dir\n# \u5c06\u76ee\u5f55\u6302\u8f7d\u5230\u6307\u5b9a\u78c1\u76d8\u5206\u533a\nmount -t ext4 \/dev\/sdb1 \/opt\n\u7b49\u6548\u4fee\u6539\/etc\/fstab\n\/dev\/sdb1 \/opt ext4 defaults 0 0\n# \u5c06\u76ee\u5f55\u6302\u5728\u5230\u5185\u5b58\u4e0a.\nmount -t tmpfs -o size=100G tmpfs \/var\/www\n# \u672c\u673a\u6302\u8f7d, \u5c06\u672c\u673a\u7684folder2\u6302\u8f7d\u5230folder1, folder2\u4e2d\u539f\u6709\u7684\u5185\u5bb9\u4f1a\u9690\u85cf.\nmount --bind \/path\/folder1 \/path\/folder2\n\/path\/folder1 \/path\/folder2 none bind 0 0\n# \u6302\u8f7d\u5230overlay\nmount -t overlay -o lowerdir=\/path\/lower,upperdir=\/path\/upper,workdir=\/path\/work overlay \/path\/dir\numount\numount device\/dir\n<\/code><\/pre>\n<h1 id=\"\u78c1\u76d8\u7ba1\u7406\">\u78c1\u76d8\u7ba1\u7406<\/h1>\n<pre><code># \u5148\u521b\u5efalinux lvm\u5206\u533a\npvcreate &lt;pv-name&gt; # \u521b\u5efa\u7269\u7406\u5377PV\npvdisplay\nvgextend &lt;vg-name&gt; &lt;pv-name&gt; # \u7ed9\u7269\u7406\u5377\u521b\u5efa\u5377\u7ec4VG\nvgdisplay\nlvextend -r -l +100%FREE &lt;lv-path&gt; # \u5c06\u7269\u7406\u5377\u4e0a\u7684\u7a7a\u95f2\u7a7a\u95f4\u5168\u90e8\u653e\u5230\u903b\u8f91\u5377LV\u4e0a\nlvdisplay\n<\/code><\/pre>\n<p>sync\u540c\u6b65\u7f13\u5b58\u5199\u5165\u56fa\u6001\u5b58\u50a8:<\/p>\n<pre><code>sync\n<\/code><\/pre>\n<p>\u67e5\u770b\u6240\u6709\u786c\u4ef6\u8bbe\u5907:<\/p>\n<pre><code>lshw # \u5217\u51fa\u786c\u4ef6\nlshw -class disk # \u67e5\u770b\u78c1\u76d8\u8bbe\u5907\n<\/code><\/pre>\n<p>\u8bbe\u5907\u7ba1\u7406:<\/p>\n<pre><code>lspci # \u5217\u51fa\u6240\u6709PCI\u8bbe\u5907\nlsusb # \u5217\u51faUSB\u8bbe\u5907\nlsblk # \u5217\u51fa\u5757\u8bbe\u5907\nsetleds\nloadkeys\ndumpkeys\nMAKEDEV\n<\/code><\/pre>\n<hr>\n<h1 id=\"iops\">IOPS<\/h1>\n<p>\u78c1\u76d8IO.<\/p>\n<p>\u5b89\u88c5fio:<\/p>\n<pre><code>$ sudo apt-get install fio\n<\/code><\/pre>\n<p>\u6d4b\u8bd5\u968f\u673a\u8bfb\u5199\u7684IO:<\/p>\n<pre><code>\/\/ \u6d4b\u8bd5\u672c\u5730\u78c1\u76d8\u8bfb\u5199\n$ fio -filename=\/dev\/sda1 -direct=1 -iodepth 1 -thread -rw=randrw \\\n-rwmixread=70 -ioengine=psync -bs=16k -size=200G -numjobs=30 -runtime=100 \\\n-group_reporting -name=mytest\n<\/code><\/pre>"},{"title":"Init","link":"https:\/\/canuxcheng.com\/post\/linux_init\/","pubDate":"Sun, 03 Feb 2019 14:04:05 +0000","guid":"https:\/\/canuxcheng.com\/post\/linux_init\/","description":"<h1 id=\"linux-init\">Linux Init<\/h1>\n<p>linux\u7cfb\u7edf\u542f\u52a8\u7684\u7b2c\u4e00\u4e2a\u8fdb\u7a0b,pid=1\u7684\u8fdb\u7a0b.<\/p>\n<pre><code>$ ls -l \/sbin\/init\n$ sudo readlink \/sbin\/init\n\/sbin\/init -&gt; upstart\n\/sbin\/init -&gt; \/lib\/systemd\/systemd\n\/etc\/init.d\nThe directory containing System V init scripts.\n\u901a\u8fc7service\u547d\u4ee4\u64cd\u4f5c\n\/etc\/init\nThe directory containing upstart jobs.\n\u901a\u8fc7initctl\u547d\u4ee4\u64cd\u4f5c\n<\/code><\/pre>\n<hr>\n<h1 id=\"systemd\">systemd<\/h1>\n<p>sytemd\u662fupstart\u7684\u66ff\u4ee3\u7248\u672c\uff0e\u901a\u8fc7\u67e5\u770b\/sbin\/init\u6307\u5411systemd\u8fd8\u662fupstart.<\/p>\n<p>service\u6587\u4ef6\u4f4d\u7f6e:<\/p>\n<pre><code>\/etc\/systemd\/system\/***.service\n\/lib\/systemd\/system\/*.service\n\/usr\/lib\/systemd\/system\/*.service\n<\/code><\/pre>\n<p>service\u6587\u4ef6\u7f16\u5199:<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.freedesktop.org\/software\/systemd\/man\/systemd.unit.html#\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.freedesktop.org\/software\/systemd\/man\/systemd.unit.html#<\/a><\/p>\n<pre><code>[Unit]\nDescription=details\nAfter=containerd.service # \u4e4b\u524d\u542f\u52a8\nBefore= # \u4e4b\u540e\u8fd0\u884c\nBindsto= #\nWants=containerd.service # \u5f31\u4f9d\u8d56\nRequires= # \u5f3a\u4f9d\u8d56\nStartLimitInterval=10s\nStartLimitBurst=5\n<\/code><\/pre>\n<p><a class=\"link\" href=\"https:\/\/www.freedesktop.org\/software\/systemd\/man\/systemd.service.html#\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.freedesktop.org\/software\/systemd\/man\/systemd.service.html#<\/a><\/p>\n<pre><code>[Service]\nType=simple\/notify\/dbus\/forking\/idle\/oneshot\nExecStartPre=\nExecStart=\nExecStartPost=\nExecStop=\nExecStopPost=\nExecReload=\nKillMode=node\/mixed\/process\/control-group\nRestart=no\/on-success\/on-failure\/on-abnormal\/on-abort\/on-watchdog\/always # always\u603b\u662f\u5f00\u673a\u542f\u52a8\uff0c\u5373\u4f7fsystemctl enable.\nRestartSec=3s # \u91cd\u542f\u4e4b\u524d\u7b49\u5f85\u7684\u65f6\u95f4.\nTimeoutSec= # TimeoutStartSec+TimeoutStopSec\nLimitNOFILE=49152 # \u9650\u5236\u5355\u4e2aservice\u7684fd\n[Install]\nWantedBy=multi-user.target\n<\/code><\/pre>\n<p>systemctl\u547d\u4ee4:<\/p>\n<pre><code># \u4fee\u6539\u540e\u9700\u8981\u91cd\u65b0\u52a0\u8f7d.service\u6587\u4ef6\n$ systemctl daemon-reload\n$ systemctl start\/stop\/status ***\n$ systemctl list-unit-files\n$ systemctl show docker\n# \u8bbe\u7f6e\u5f00\u673a\u81ea\u52a8\u542f\u52a8\n\/\/\u5728\/etc\/systemd\/system\/multi-user.target.wants\u4e0b\u521b\u5efa\u94fe\u63a5\n$ systemctl enable ***\n$ systemctl disable ***\n$ systemctl is-enabled ***\n<\/code><\/pre>\n<p>\u65e5\u5fd7\u7ba1\u7406:<\/p>\n<pre><code>$ sudo journalctl -fu docker.service\n<\/code><\/pre>\n<hr>\n<h1 id=\"upstart\">upstart<\/h1>\n<pre><code>\/etc\/init.d\/***\n\/etc\/init\/***.conf\n$ sudo service docker start\/stop\/status\/reload\/restart\n$ sudo initctl start\/stop\/status\/reload\/restart docker\n$ sudo initctl list\n# \u8bbe\u7f6e\u5f00\u673a\u81ea\u52a8\u542f\u52a8\n$ update-rc.d *** defaults\n# \u53d6\u6d88\u5f00\u673a\u542f\u52a8\n$ update-rc.d *** remove\n<\/code><\/pre>\n<p>\u65e5\u5fd7\u7ba1\u7406:<\/p>\n<pre><code>$ tail -f \/var\/log\/upstart\/docker.log\n<\/code><\/pre>\n<p>Stanzas\u529f\u80fd:<\/p>\n<p><a class=\"link\" href=\"http:\/\/upstart.ubuntu.com\/wiki\/Stanzas?highlight=%28%28CategoryDoc%29%29#pid\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/upstart.ubuntu.com\/wiki\/Stanzas?highlight=%28%28CategoryDoc%29%29#pid<\/a><\/p>\n<pre><code># \u6dfb\u52a0\u670d\u52a1\n$ sudo vim \/etc\/init\/docker.conf\n# docker - container daemon\ndescription &quot;docker&quot;\nstart on runlevel [2345]\nstop on runlevel [!2345]\nrespawn\n# give up if restart occurs 10 times in 100 seconds.\nrespawn limit 10 100\npre-start script\n# do something before start\nend script\nscript\necho &quot;ERROR: `date`: docker started by init.&quot;\nexec docker\nend script\npost-start script\n# do something after start\nend script\n# \u68c0\u67e5\u8bed\u6cd5\u9519\u8bef\n$ sudo init-checkconf \/etc\/init\/docker.conf\n# \u6ce8\u518c\u670d\u52a1\n$ sudo initctl reload-configuration\n<\/code><\/pre>\n<hr>"},{"title":"Nginx","link":"https:\/\/canuxcheng.com\/post\/nginx\/","pubDate":"Thu, 27 Sep 2018 03:25:26 +0000","guid":"https:\/\/canuxcheng.com\/post\/nginx\/","description":"<h1 id=\"nginx\">Nginx<\/h1>\n<p>\u5b89\u88c5<\/p>\n<p>\u914d\u7f6e<\/p>\n<p>\u547d\u4ee4\uff1a<\/p>\n<pre><code>nginx -s stop\/quit\/reload\/reopen\nnginx -V \u8be6\u7ec6\u4fe1\u606f\nnginx -v \u7248\u672c\u53f7\nnginx -t \u68c0\u67e5\u914d\u7f6e\u6587\u4ef6\n<\/code><\/pre>"},{"title":"AST","link":"https:\/\/canuxcheng.com\/post\/sec_ast\/","pubDate":"Sat, 28 Jul 2018 16:08:54 +0000","guid":"https:\/\/canuxcheng.com\/post\/sec_ast\/","description":"<h1 id=\"ast\">AST<\/h1>\n<p>AST: Application Security Testing, \u9759\u6001\u5e94\u7528\u7a0b\u5e8f\u5b89\u5168\u6d4b\u8bd5, \u5bf9\u5e94\u7528\u7a0b\u5e8f\u6e90\u4ee3\u7801\u6267\u884c\u76f4\u63a5\u7684\u767d\u76d2\u5206\u6790.<\/p>\n<hr>\n<h2 id=\"sast\">SAST<\/h2>\n<p>SAST: Static Application Security Testing<\/p>\n<p>Tools: SonarQube, Trivy, Coverity.<\/p>\n<p>gitlab SAST report.\ngitlab secret detection report.<\/p>\n<h3 id=\"trivy\">trivy<\/h3>\n<p><a class=\"link\" href=\"https:\/\/github.com\/aquasecurity\/trivy\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/aquasecurity\/trivy<\/a><\/p>\n<p>Trivy\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u5b89\u5168\u626b\u63cf\u5de5\u5177\uff0c\u652f\u6301\u5bb9\u5668\u955c\u50cf\u3001\u6587\u4ef6\u7cfb\u7edf\u548cGit\u4ed3\u5e93\u7684\u6f0f\u6d1e\u626b\u63cf\u3002<\/p>\n<pre><code>trivy image &lt;image&gt;\ntrivy fs &lt;path&gt;\ntrivy repo &lt;repo&gt;\n<\/code><\/pre>\n<h3 id=\"coverity\">Coverity<\/h3>\n<p><a class=\"link\" href=\"https:\/\/scan.coverity.com\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/scan.coverity.com\/<\/a><\/p>\n<p>Coverity\u662f\u4e00\u4e2a\u5546\u4e1a\u7684\u9759\u6001\u4ee3\u7801\u5206\u6790\u5de5\u5177\uff0c\u4e3b\u8981\u7528\u4e8e\u53d1\u73b0\u4ee3\u7801\u4e2d\u7684\u7f3a\u9677\u548c\u5b89\u5168\u6f0f\u6d1e\u3002<\/p>\n<pre><code>cov-init\ncov-build\ncov-analyze\n<\/code><\/pre>\n<hr>\n<h2 id=\"dast\">DAST<\/h2>\n<p>DAST: Dynamic Application Security Testing\uff0c\u52a8\u6001\u5e94\u7528\u7a0b\u5e8f\u5b89\u5168\u6d4b\u8bd5, \u5bf9\u5e94\u7528\u7a0b\u5e8f\u8fdb\u884c\u9ed1\u76d2\u5206\u6790.<\/p>\n<p>Tools:<\/p>\n<p>ZAP Scan(OWASP ZAP)<\/p>\n<p>synopsys WhiteHat Sentinel.<\/p>\n<p>gitlab DAST report.<\/p>\n<hr>\n<h2 id=\"iast\">IAST<\/h2>\n<p>IAST: Interactive Application Security Testing\uff0c\u4ea4\u4e92\u5f0f\u5e94\u7528\u7a0b\u5e8f\u5b89\u5168\u6d4b\u8bd5, \u7ed3\u5408\u4e86SAST\u548cDAST\u7684\u4f18\u70b9.<\/p>\n<hr>\n<h2 id=\"sca\">SCA<\/h2>\n<p>SCA: Software Composition Analysis.<\/p>\n<p>SBOM (software Bill of Materials),\u5f00\u6e90\u7ec4\u4ef6\u5b89\u5168\u626b\u63cf.<\/p>\n<p>Tools\uff1a BlackDuck, Jfrog Xray.<\/p>\n<p>gitlab dependency scanning report.<\/p>\n<h3 id=\"blackduck\">Blackduck<\/h3>\n<p><a class=\"link\" href=\"https:\/\/www.blackducksoftware.com\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.blackducksoftware.com\/<\/a><\/p>\n<p>Blackduck\u662f\u4e00\u4e2a\u5546\u4e1a\u7684\u5f00\u6e90\u7ec4\u4ef6\u5b89\u5168\u626b\u63cf\u5de5\u5177\uff0c\u4e3b\u8981\u7528\u4e8e\u53d1\u73b0\u5f00\u6e90\u7ec4\u4ef6\u4e2d\u7684\u6f0f\u6d1e\u548c\u8bb8\u53ef\u8bc1\u95ee\u9898\u3002<\/p>\n<pre><code>detect.sh ......\n<\/code><\/pre>"},{"title":"CA","link":"https:\/\/canuxcheng.com\/post\/sec_ca\/","pubDate":"Sat, 28 Jul 2018 16:08:54 +0000","guid":"https:\/\/canuxcheng.com\/post\/sec_ca\/","description":"<h1 id=\"ca\">CA<\/h1>\n<p>SSL: secure sockets layer<\/p>\n<p>TLS: transport layer security<\/p>\n<p>CA: Certificate Authority.<\/p>\n<p>SNI: server name indication<\/p>\n<p>\u8bc1\u4e66\u7c7b\u578b<\/p>\n<ul>\n<li>x509: \u53ea\u6709\u516c\u94a5\u6ca1\u6709\u79c1\u94a5\u5319<\/li>\n<\/ul>\n<p>\u7f16\u7801\u65b9\u5f0f<\/p>\n<ul>\n<li>pem: base64\u7f16\u7801<\/li>\n<li>der: \u4e8c\u8fdb\u5236<\/li>\n<\/ul>\n<p>\u8bc1\u4e66\u6587\u4ef6:<\/p>\n<ul>\n<li>crt: \u8bc1\u4e66\u6587\u4ef6\uff08\u53ef\u4ee5\u662fpem\u6216der\u7f16\u7801\uff09<\/li>\n<li>cer: \u8bc1\u4e66\u6587\u4ef6\uff08\u53ef\u4ee5\u662fpem\u6216der\u7f16\u7801\uff09<\/li>\n<li>csr: \u7533\u8bf7\u7b7e\u540d\u7684\u6587\u4ef6<\/li>\n<li>key: \u79c1\u94a5\u6587\u4ef6<\/li>\n<\/ul>\n<hr>\n<h1 id=\"\u521b\u5efa\u81ea\u7b7e\u540d\u8bc1\u4e66\">\u521b\u5efa\u81ea\u7b7e\u540d\u8bc1\u4e66<\/h1>\n<p>\u521b\u5efax509\u8bc1\u4e66:<\/p>\n<pre><code>$ openssl genrsa -out server.key 2048 \/\/ \u521b\u5efakey\n$ openssl req -new -key server.key -sha256 -out server.csr \/\/ \u521b\u5efacsr\n$ openssl x509 -req -days 365 -in server.csr -signkey server.key -sha256 -out server.crt \/\/ \u521b\u5efa\u8bc1\u4e66\n<\/code><\/pre>\n<p>\u67e5\u770b\u8bc1\u4e66\u4fe1\u606f:<\/p>\n<pre><code>\/\/ pem\u7f16\u7801\n$ openssl x509 -in cert.pem -noout -text\n\/\/ der\u7f16\u7801\n$ openssl x509 -in cert.der -inform der -noout -text\n<\/code><\/pre>\n<p>\u67e5\u770b\u8bc1\u4e66\u6709\u6548\u671f:<\/p>\n<pre><code>$ openssl x509 -in ca.domain.com.crt -noout -text -dates\n<\/code><\/pre>\n<h1 id=\"\u5ba2\u6237\u7aef\">\u5ba2\u6237\u7aef<\/h1>\n<p>\u5ba2\u6237\u7aef\u9700\u8981\u4fe1\u4efb\u8bc1\u4e66.<\/p>\n<p>Linux:<\/p>\n<pre><code>\/\/ \u6dfb\u52a0\n$ cp my-cert.crt \/usr\/local\/share\/ca-certificates\/my-cert.crt\n$ sudo update-ca-certificates\n\/\/ \u5220\u9664\n$ rm \/usr\/local\/share\/ca-certificates\/my-cert.crt\n$ sudo update-ca-certificates --fresh\n<\/code><\/pre>\n<p>windows:<\/p>\n<pre><code>\/\/ \u6dfb\u52a0\ncertutil -addstore -f &quot;ROOT&quot; my-cert.crt\n\/\/ \u5220\u9664\ncertutil -delstore &quot;ROOT&quot; my-cert.crt\n<\/code><\/pre>\n<h1 id=\"\u8bc1\u4e66\u9a8c\u8bc1\">\u8bc1\u4e66\u9a8c\u8bc1<\/h1>\n<p>\u7cfb\u7edf\u9ed8\u8ba4\u7684\u6839\u8bc1\u4e66\u5728<\/p>\n<pre><code>\/etc\/ssl\/certs.\n<\/code><\/pre>\n<p>python\u7684requests\u5305\u9ed8\u8ba4\u4f7f\u7528\u6839\u8bc1\u4e66\u5728<\/p>\n<pre><code>\/usr\/local\/lib\/python3.6\/site-packages\/requests\/cacert.pem\n<\/code><\/pre>\n<p>requests\u4e5f\u901a\u8fc7certifi\u6765\u7ba1\u7406\u6839\u8bc1\u4e66<\/p>\n<pre><code>\/usr\/local\/lib\/python3.6\/site-packages\/certifi\/cacert.pem\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6eREQUESTS_CA_BUNDLE\u73af\u5883\u53d8\u91cf\u6765\u8ba9requests\u4f7f\u7528\u7cfb\u7edf\u7684\u6839\u8bc1\u4e66\u3002<\/p>"},{"title":"Capture","link":"https:\/\/canuxcheng.com\/post\/sec_capture\/","pubDate":"Sat, 28 Jul 2018 16:08:54 +0000","guid":"https:\/\/canuxcheng.com\/post\/sec_capture\/","description":"<h1 id=\"packet-capture\">Packet Capture<\/h1>\n<p>\u7f51\u7edc\u6293\u5305<\/p>\n<h1 id=\"fiddler\">Fiddler<\/h1>\n<p><a class=\"link\" href=\"http:\/\/www.telerik.com\/fiddler\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.telerik.com\/fiddler<\/a><\/p>\n<h1 id=\"wireshark\">Wireshark<\/h1>\n<p><a class=\"link\" href=\"https:\/\/www.wireshark.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.wireshark.org\/<\/a><\/p>"},{"title":"Csrf","link":"https:\/\/canuxcheng.com\/post\/sec_csrf\/","pubDate":"Sat, 28 Jul 2018 16:08:54 +0000","guid":"https:\/\/canuxcheng.com\/post\/sec_csrf\/","description":"<h1 id=\"csrf\">CSRF<\/h1>\n<p>Cross-site request forgery, \u8de8\u7ad9\u8bf7\u6c42\u4f2a\u9020\uff0e<\/p>\n<p>\u53d1\u751f\u6761\u4ef6\uff1a<\/p>\n<ul>\n<li>\u767b\u9646\u53d7\u4fe1\u4efb\u7f51\u7ad9A, \u5e76\u5728\u672c\u5730\u751f\u6210cookie<\/li>\n<li>\u5728\u4e0d\u9000\u51faA\u7684\u60c5\u51b5\u4e0b\uff0c\u8bbf\u95ee\u5371\u9669\u7f51\u7ad9B<\/li>\n<\/ul>\n<p>\u9884\u9632\u65b9\u6cd5:<\/p>\n<ul>\n<li>\u6b63\u786e\u4f7f\u7528get,post\u548ccookie<\/li>\n<li>\u5728\u975eget\u8bf7\u6c42\u4e2d\u589e\u52a0\u4f2a\u968f\u673a\u6570<\/li>\n<\/ul>"},{"title":"HA","link":"https:\/\/canuxcheng.com\/post\/ha\/","pubDate":"Sat, 28 Jul 2018 16:08:54 +0000","guid":"https:\/\/canuxcheng.com\/post\/ha\/","description":"<h1 id=\"haproxy\">HAProxy<\/h1>\n<p><a class=\"link\" href=\"https:\/\/www.haproxy.com\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.haproxy.com\/<\/a><\/p>\n<p>\u5b89\u88c5:<\/p>\n<pre><code>$ sudo apt-get install haproxy\n<\/code><\/pre>\n<p>\u914d\u7f6e:<\/p>\n<pre><code>$ sudo vim \/etc\/haproxy\/haproxy.cfg\n<\/code><\/pre>\n<p>global:<\/p>\n<pre><code> log \/dev\/log local0\nlog \/dev\/log local1 notice\nchroot \/var\/lib\/haproxy\nstats socket \/run\/haproxy\/admin.sock mode 660 level admin expose-fd listeners\nstats timeout 30s\nuser haproxy\ngroup haproxy\ndaemon\n# Default SSL material locations\nca-base \/etc\/ssl\/certs\ncrt-base \/etc\/ssl\/private\n# Default ciphers to use on SSL-enabled listening sockets.\n# For more information, see ciphers(1SSL). This list is from:\n# https:\/\/hynek.me\/articles\/hardening-your-web-servers-ssl-ciphers\/\n# An alternative list with additional directives can be obtained from\n# https:\/\/mozilla.github.io\/server-side-tls\/ssl-config-generator\/?server=haproxy\nssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS\nssl-default-bind-options no-sslv3\n<\/code><\/pre>\n<p>defaults:<\/p>\n<pre><code> log global\nmode http\noption httplog\noption dontlognull\ntimeout connect 5000\ntimeout client 50000\ntimeout server 50000\n<\/code><\/pre>\n<p>frontend:<\/p>\n<p>backend:<\/p>\n<p>listen:<\/p>\n<hr>\n<h1 id=\"keepalived\">Keepalived<\/h1>\n<p><a class=\"link\" href=\"https:\/\/www.keepalived.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.keepalived.org\/<\/a><\/p>\n<p>\u5b89\u88c5:<\/p>\n<pre><code>$ sudo apt-get install keepalived\n<\/code><\/pre>\n<p>\u914d\u7f6e:<\/p>\n<pre><code>$ sudo vim \/etc\/keepalived\/keepalived.conf\n<\/code><\/pre>"},{"title":"Security","link":"https:\/\/canuxcheng.com\/post\/sec_security\/","pubDate":"Sat, 28 Jul 2018 16:08:54 +0000","guid":"https:\/\/canuxcheng.com\/post\/sec_security\/","description":"<h1 id=\"security\">Security<\/h1>\n<p><a class=\"link\" href=\"https:\/\/nvd.nist.gov\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/nvd.nist.gov\/<\/a><\/p>\n<p><a class=\"link\" href=\"http:\/\/cve.scap.org.cn\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/cve.scap.org.cn\/<\/a><\/p>\n<h1 id=\"gfw\">GFW<\/h1>\n<h1 id=\"ngfw\">NGFW<\/h1>\n<h1 id=\"utm\">UTM<\/h1>\n<p>Unified Threat Management, \u5b89\u5168\u7f51\u5173<\/p>\n<p>BUV: Block Until Verdict<\/p>\n<h1 id=\"waf\">WAF<\/h1>\n<p>Web Application Firewall, web\u5e94\u7528\u9632\u706b\u5899<\/p>\n<h1 id=\"ips\">IPS<\/h1>\n<p>Intrusion Prevention System, \u5165\u4fb5\u9632\u5fa1\u7cfb\u7edf<\/p>\n<h1 id=\"ids\">IDS<\/h1>\n<p>Intrusion Detection System, \u5165\u4fb5\u68c0\u6d4b\u7cfb\u7edf<\/p>\n<h1 id=\"nsm\">NSM<\/h1>\n<p>Network Security Monitoring, \u7f51\u7edc\u5b89\u5168\u76d1\u63a7<\/p>"},{"title":"Sql Injection","link":"https:\/\/canuxcheng.com\/post\/sec_sqlinjection\/","pubDate":"Sat, 28 Jul 2018 16:08:54 +0000","guid":"https:\/\/canuxcheng.com\/post\/sec_sqlinjection\/","description":"<h1 id=\"sql-injection\">SQL Injection<\/h1>\n<p>\u4ec0\u4e48\u662fsql injection:\u4ece\u6570\u636e\u5e93\u83b7\u53d6\u654f\u611f\u4fe1\u606f,\u6216\u8005\u5229\u7528\u6570\u636e\u5e93\u7684\u7279\u6027\u6267\u884c\u6dfb\u52a0\u7528\u6237,\u5bfc\u51fa\u6587\u4ef6\u7b49\u4e00\u7cfb\u5217\u6076\u610f\u64cd\u4f5c,\u751a\u81f3\u6709\u53ef\u80fd\u83b7\u53d6\u6570\u636e\u5e93\u4e43\u81f3\u7cfb\u7edf\u7528\u6237\u6700\u9ad8\u6743\u9650\u3002<\/p>\n<p>\u539f\u56e0:\u9020\u6210SQL\u6ce8\u5165\u7684\u539f\u56e0\u662f\u56e0\u4e3a\u7a0b\u5e8f\u6ca1\u6709\u6709\u6548\u8fc7\u6ee4\u7528\u6237\u7684\u8f93\u5165.<\/p>\n<p>\u9884\u9632\uff1a<\/p>\n<ul>\n<li>\u4e25\u683c\u9650\u5236\u6570\u636e\u5e93\u7684\u64cd\u4f5c\u6743\u9650<\/li>\n<li>\u68c0\u67e5\u8f93\u5165\u7684\u6570\u636e\u683c\u5f0f\u662f\u5426\u7b26\u5408\u8981\u6c42<\/li>\n<li>\u5bf9\u8fdb\u5165\u6570\u636e\u5e93\u7684\u7279\u6b8a\u5b57\u7b26\u8fdb\u884c\u8f6c\u4e49<\/li>\n<li>\u6570\u636e\u5e93\u67e5\u8be2\u8bed\u53e5\u4f7f\u7528\u6570\u636e\u5e93\u63d0\u4f9b\u7684\u53c2\u6570\u5316\u67e5\u8be2\u63a5\u53e3<\/li>\n<li>\u5728\u53d1\u5e03\u4e4b\u524d\u4f7f\u7528\u4e13\u4e1a\u7684sql\u6ce8\u5165\u68c0\u6d4b\u5de5\u5177\u8fdb\u884c\u68c0\u6d4b<\/li>\n<li>\u907f\u514d\u7f51\u7ad9\u6253\u5370sql\u9519\u8bef\u4fe1\u606f<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u8868\u5355\u6ce8\u5165\uff1a<\/p>\n<pre><code>username =&gt; myuser' or 'foo' = 'foo' --\nSELECT * FROM user WHERE username='myuser' or 'foo' = 'foo' --'' AND password='xxx'\n<\/code><\/pre>\n<p>mssql\u7684sql\u8bed\u53e5\u53ef\u4ee5\u6267\u884cdos\u547d\u4ee4:<\/p>\n<pre><code>exec xp_cmdshell 'net user username 2546 \/add' # \u65b0\u5efa\u7cfb\u7edf\u7528\u6237\nexec xp_cmdshell 'net localgroup administrator username \/add' # \u6388\u6743\n<\/code><\/pre>"},{"title":"Xss","link":"https:\/\/canuxcheng.com\/post\/sec_xss\/","pubDate":"Sat, 28 Jul 2018 16:08:54 +0000","guid":"https:\/\/canuxcheng.com\/post\/sec_xss\/","description":"<h1 id=\"xss\">XSS<\/h1>\n<p>XSS: Cross Site Scripting, \u8de8\u7ad9\u811a\u672c\u653b\u51fb<\/p>\n<p>XSS\u653b\u51fb\u6d89\u53ca\u5230\u653b\u51fb\u8005\uff0c\u5ba2\u6237\u7aef\uff0c\u548cweb\u5e94\u7528\u4e09\u8005.<\/p>\n<p>XSS\u539f\u7406:<\/p>\n<ul>\n<li>Web\u5e94\u7528\u672a\u5bf9\u7528\u6237\u63d0\u4ea4\u8bf7\u6c42\u7684\u6570\u636e\u505a\u5145\u5206\u7684\u68c0\u67e5\u8fc7\u6ee4,\u5141\u8bb8\u7528\u6237\u5728\u63d0\u4ea4\u7684\u6570\u636e\u4e2d\u63ba\u5165HTML\u4ee3\u7801(\u6700\u4e3b\u8981\u7684\u662f\u201c&gt;\u201d\u3001\u201c&lt;\u201d),\u5e76\u5c06\u672a\u7ecf\u8f6c\u4e49\u7684\u6076\u610f\u4ee3\u7801\u8f93\u51fa\u5230\u7b2c\u4e09\u65b9\u7528\u6237\u7684\u6d4f\u89c8\u5668\u89e3\u91ca\u6267\u884c,\u662f\u5bfc\u81f4XSS\u6f0f\u6d1e\u7684\u4ea7\u751f\u539f\u56e0\u3002<\/li>\n<\/ul>\n<p>XSS\u76ee\u524d\u4e3b\u8981\u624b\u6bb5\u548c\u76ee\u7684:<\/p>\n<ul>\n<li>\u76d7\u7528cookie,\u83b7\u53d6\u654f\u611f\u4fe1\u606f<\/li>\n<li>\u5229\u7528\u690d\u5165flash\uff0c\u901a\u8fc7crossdomain\u6743\u9650\u8bbe\u7f6e\u83b7\u53d6\u66f4\u9ad8\u6743\u9650\uff0e<\/li>\n<li>\u5229\u7528iframe, frame, XMLHttpRequests\u7b49\u65b9\u5f0f\u4ee5\u7528\u6237\u8eab\u4efd\u6267\u884c\u4e00\u4e9b\u7ba1\u7406\u64cd\u4f5c\uff0e<\/li>\n<\/ul>\n<p>XSS\u9884\u9632:<\/p>\n<ul>\n<li>\u8fc7\u6ee4\u7279\u6b8a\u5b57\u7b26<\/li>\n<li>\u4f7f\u7528http\u5934\u6307\u5b9a\u7c7b\u578b<\/li>\n<\/ul>"},{"title":"Cfssl","link":"https:\/\/canuxcheng.com\/post\/sec_cfssl\/","pubDate":"Sat, 28 Jul 2018 16:08:54 +0800","guid":"https:\/\/canuxcheng.com\/post\/sec_cfssl\/","description":"<h1 id=\"cfssl\">cfssl<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/cloudflare\/cfssl\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/cloudflare\/cfssl<\/a><\/p>"},{"title":"Gin","link":"https:\/\/canuxcheng.com\/post\/gin\/","pubDate":"Fri, 20 Jul 2018 23:14:07 +0800","guid":"https:\/\/canuxcheng.com\/post\/gin\/","description":"<h1 id=\"gin\">Gin<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/gin-gonic\/gin\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/gin-gonic\/gin<\/a><\/p>\n<p>install<\/p>\n<pre><code>$ go get -u github.com\/gin-gonic\/gin\n<\/code><\/pre>\n<p>import<\/p>\n<pre><code>import &quot;github.com\/gin-gonic\/gin&quot;\n<\/code><\/pre>"},{"title":"Restful","link":"https:\/\/canuxcheng.com\/post\/rest\/","pubDate":"Sat, 07 Jul 2018 16:43:15 +0000","guid":"https:\/\/canuxcheng.com\/post\/rest\/","description":"<h1 id=\"rest\">REST<\/h1>\n<p>REST: REpresentational State Transfer\uff0e<\/p>\n<hr>\n<h1 id=\"restclient\">restclient<\/h1>\n<p>\u4e00\u4e2a\u662ffirefox\u7684\u63d2\u4ef6\uff0e<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/chao\/RESTClient\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/chao\/RESTClient<\/a><\/p>\n<p>\u53e6\u4e00\u4e2a\u662fjava\u5f00\u53d1\u7684application.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/wiztools\/rest-client\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/wiztools\/rest-client<\/a><\/p>\n<h1 id=\"postman\">postman<\/h1>\n<p>postman\u662f\u4e00\u4e2aapplication,\u540c\u65f6\u4e5f\u53ef\u4ee5\u4ecechrome\u542f\u52a8.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/postmanlabs\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/postmanlabs<\/a><\/p>\n<h1 id=\"soupui\">soupui<\/h1>\n<p>\u4e00\u4e2a\u7528\u4e8eSOAP\u548cREST\u7684application.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/SmartBear\/soapui\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/SmartBear\/soapui<\/a><\/p>"},{"title":"Webhook","link":"https:\/\/canuxcheng.com\/post\/webhook\/","pubDate":"Sat, 07 Jul 2018 16:43:15 +0000","guid":"https:\/\/canuxcheng.com\/post\/webhook\/","description":"<h1 id=\"webhook\">WebHook<\/h1>\n<p>\u7528\u4e8eserver\u548cserver\u4e4b\u95f4\u901a\u8baf\uff0e<\/p>"},{"title":"WebService","link":"https:\/\/canuxcheng.com\/post\/webservice\/","pubDate":"Sat, 07 Jul 2018 16:43:15 +0000","guid":"https:\/\/canuxcheng.com\/post\/webservice\/","description":"<h1 id=\"webservice\">webservice<\/h1>\n<p>webservice\u7528\u4e8eserver\u548cbrowser\u4e4b\u95f4\u901a\u8baf\uff0e<\/p>\n<p>webservice\u662f\u57fa\u4e8ehttp\u7684\uff0c\u65e0\u72b6\u6001\u7684\uff0e<\/p>\n<p>webservice\u4e00\u822c\u5206\u4e3asoap webservice\u548chttp webservice.<\/p>\n<hr>\n<h1 id=\"soap\">SOAP<\/h1>\n<p>Simple Object Access Protocol, \u7b80\u5355\u5bf9\u8c61\u8bbf\u95ee\u534f\u8bae\uff0c\u662f\u4e00\u4e2a\u57fa\u4e8eXML\u7684\u534f\u8bae\uff0e<\/p>\n<p>\u7b80\u5355\u6765\u8bf4SOAP\u7684\u601d\u60f3\u5c31\u662f\u901a\u8fc7http + XML\u6765\u5728server\u548cbrowser\u4e4b\u95f4\u4ea4\u6362\u4fe1\u606f\uff0e<\/p>\n<hr>\n<h1 id=\"soupui\">soupui<\/h1>\n<p>\u4e00\u4e2a\u7528\u4e8eSOAP\u548cREST\u7684application.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/SmartBear\/soapui\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/SmartBear\/soapui<\/a><\/p>"},{"title":"Grok","link":"https:\/\/canuxcheng.com\/post\/devops_grok\/","pubDate":"Fri, 08 Jun 2018 09:46:47 +0000","guid":"https:\/\/canuxcheng.com\/post\/devops_grok\/","description":"<h1 id=\"grok\">grok<\/h1>\n<p>logstash\u548ctelegraf\u90fd\u662f\u7528grok\u6765\u89e3\u6790log<\/p>\n<p>\u5728\u7ebf\u68c0\u6d4b<\/p>\n<p><a class=\"link\" href=\"http:\/\/grokdebug.herokuapp.com\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/grokdebug.herokuapp.com\/<\/a><\/p>\n<p>grok\u7684\u6b63\u5219\u8868\u8fbe\u5f0f<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kkos\/oniguruma\/blob\/master\/doc\/RE\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kkos\/oniguruma\/blob\/master\/doc\/RE<\/a><\/p>\n<p>\u53ef\u7528\u7684pattern(logstash &amp; telegraf-logparser\/tail)<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/logstash-plugins\/logstash-patterns-core\/blob\/master\/patterns\/grok-patterns\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/logstash-plugins\/logstash-patterns-core\/blob\/master\/patterns\/grok-patterns<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/influxdata\/telegraf\/blob\/master\/plugins\/inputs\/logparser\/grok\/patterns\/influx-patterns\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/influxdata\/telegraf\/blob\/master\/plugins\/inputs\/logparser\/grok\/patterns\/influx-patterns<\/a><\/p>\n<hr>\n<h1 id=\"elastic-stack\">Elastic stack<\/h1>\n<p>beats\/filebeats: \u901a\u8fc7filebeats agent\u83b7\u53d6log\uff0e<\/p>\n<p>logstash: \u4f7f\u7528filebeats\u89e3\u6790log\u5e76\u5199\u5165stash(elasticsearch).<\/p>\n<hr>\n<h1 id=\"tick-stack\">TICK stack<\/h1>\n<p>telegraf(agent): \u901a\u8fc7logparser\/tail\u63d2\u4ef6\u89e3\u6790log\u5e76\u5199\u5165influxdb.<\/p>\n<p>pattern:<\/p>\n<pre><code># \u901a\u8fc7\u5df2\u7ecf\u5b9a\u4e49\u7684\u53d8\u91cf\u6765\u5b9a\u4e49filter\npatterns = ['''${&lt;capture_syntax&gt;[:&lt;semantic_name&gt;][:&lt;modifier&gt;]}''']\npatterns = ['''%{TIMESTAMP_ISO8601:asctime:string} \\[%{DATA:name:string}\\] %{LOGLEVEL:levelname:string}: %{GREEDYDATA:message:string}''']\ncapture_syntax\u662f\u5df2\u7ecf\u5b9a\u4e49\u597d\u7684pattern.\nsemantic_name\u662ffield\/tag\u7684\u540d\u5b57, \u9ed8\u8ba4\u90fd\u662fstring\u7c7b\u578b\u7684field\nmodifier \u662fstring\/int\/float\/tag\/drop\/ts-&quot;CUSTOM&quot;\/...\u7c7b\u578b\ntimestamp\u6709\u7279\u6b8a\u7684modifier:\ntimestamp \u6709\u7279\u6b8a\u7684modifier\uff1a\nTimestamp modifiers:ts (This will auto-learn the timestamp format)\nts-ansic (&quot;Mon Jan _2 15:04:05 2006&quot;)\nts-unix (&quot;Mon Jan _2 15:04:05 MST 2006&quot;)\nts-ruby (&quot;Mon Jan 02 15:04:05 -0700 2006&quot;)\nts-rfc822 (&quot;02 Jan 06 15:04 MST&quot;)\nts-rfc822z (&quot;02 Jan 06 15:04 -0700&quot;)\nts-rfc850 (&quot;Monday, 02-Jan-06 15:04:05 MST&quot;)\nts-rfc1123 (&quot;Mon, 02 Jan 2006 15:04:05 MST&quot;)\nts-rfc1123z (&quot;Mon, 02 Jan 2006 15:04:05 -0700&quot;)\nts-rfc3339 (&quot;2006-01-02T15:04:05Z07:00&quot;)\nts-rfc3339nano (&quot;2006-01-02T15:04:05.999999999Z07:00&quot;)\nts-httpd (&quot;02\/Jan\/2006:15:04:05 -0700&quot;)\nts-epoch (seconds since unix epoch, may contain decimal)\nts-epochnano (nanoseconds since unix epoch)\nts-syslog (&quot;Jan 02 15:04:05&quot;, parsed time is set to the current year)\nts-&quot;CUSTOM&quot;\n<\/code><\/pre>\n<p>custom_patterns:<\/p>\n<pre><code># \u901a\u8fc7\u6b63\u5219\u8868\u8fbe\u5f0f\u6216\u5df2\u7ecf\u5b9a\u4e49\u7684\u53d8\u91cf\u6765\u5b9a\u4e49\u65b0\u7684\u53d8\u91cf\n# \u4e00\u884c\u4e00\u4e2a\ncustom_patterns = '''\nLOGLEVEL_PYTHON (?:WARNING|ERROR|CRITICAL)\n'''\n<\/code><\/pre>\n<p>logparser:<\/p>\n<pre><code>[[inputs.logparser]]\nfiles = [&quot;\/opt\/sandbox\/logs\/appliance.log&quot;]\nfrom_beginning = false\nwatch_method = &quot;inotify&quot;\n[inputs.logparser.grok]\npatterns = ['''\n%{TIMESTAMP_ISO8601:timestamp:ts-&quot;2006-01-02 15:04:05.000&quot;}\n\\[%{DATA:name:string}\\]\n%{LOGLEVEL_PYTHON:levelname:tag}:\n%{GREEDYDATA:message:string}''']\nmeasurement = &quot;log_test&quot;\ncustom_pattern_files = []\ncustom_patterns = '''LOGLEVEL_PYTHON (?:WARNING|ERROR|CRITICAL)'''\ntimezone = &quot;Local&quot;\n<\/code><\/pre>\n<p>tail:<\/p>\n<pre><code>[[inputs.tail]]\nfiles = [&quot;\/opt\/sandbox\/logs\/appliance.log&quot;]\nfrom_beginning = false\npipe = false\nwatch_method = &quot;inotify&quot;\ndata_format = &quot;grok&quot;\ngrok_patterns = ['''%{TIMESTAMP_ISO8601:timestamp:ts-&quot;2006-01-02 15:04:05.000&quot;}\n\\[%{DATA:name:string}\\] %{LOGLEVEL_PYTHON:levelname:tag}:\n%{GREEDYDATA:message:string}''']\ngrok_custom_patterns = ''LOGLEVEL_PYTHON (?:WARNING|ERROR|CRITICAL)'''\ngrok_timezone = &quot;Local&quot;\n<\/code><\/pre>\n<hr>"},{"title":"Logging","link":"https:\/\/canuxcheng.com\/post\/devops_logging\/","pubDate":"Fri, 08 Jun 2018 09:46:47 +0000","guid":"https:\/\/canuxcheng.com\/post\/devops_logging\/","description":"<h1 id=\"logging\">Logging<\/h1>\n<p>\u65e5\u5fd7\u7684\u76d1\u63a7\u548c\u5206\u6790\u3002<\/p>\n<h2 id=\"elk\">ELK<\/h2>\n<p>elasticsearch: \u641c\u7d22\uff0c\u5206\u6790\uff0c\u5b58\u50a8\u6570\u636e<\/p>\n<p>logstash: \u52a8\u6001\u6570\u636e\u6536\u96c6\u7ba1\u9053\uff0c\u652f\u6301\u53ef\u6269\u5c55\u7684\u63d2\u4ef6\uff0e<\/p>\n<p>kibana: \u6570\u636e\u53ef\u89c6\u5316<\/p>\n<p>x-pack: \u5177\u6709\u76d1\u63a7\u548c\u62a5\u8b66\u529f\u80fd\u7684\u5de5\u5177\u5305.<\/p>\n<p>beats(agent): \u8f7b\u91cf\u578b\u6570\u636e\u91c7\u96c6\u5e73\u53f0\uff0c\u4ece\u8fb9\u7f18\u673a\u5668\u5411logstash\/elasticsearch\u53d1\u9001\u6570\u636e\uff0e<\/p>\n<hr>\n<h2 id=\"loki\">Loki<\/h2>"},{"title":"Dns","link":"https:\/\/canuxcheng.com\/post\/dns\/","pubDate":"Thu, 03 May 2018 14:46:19 +0000","guid":"https:\/\/canuxcheng.com\/post\/dns\/","description":"<h1 id=\"dns\">DNS<\/h1>\n<p>Domain Name System: \u57df\u540d\u7cfb\u7edf<\/p>"},{"title":"Container","link":"https:\/\/canuxcheng.com\/post\/cncf_container\/","pubDate":"Thu, 05 Apr 2018 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/cncf_container\/","description":"<h1 id=\"container\">Container<\/h1>\n<p>OCI: Open Container Initiative.<\/p>\n<p>CRI: Container Runtime Interface.<\/p>\n<p>CNI: Container Network Interface.<\/p>\n<p>CSI: Container Storage Interface.<\/p>\n<h1 id=\"oci\">OCI<\/h1>\n<p>Open Container Initiative\uff0c\u4e5f\u5c31\u662f\u5e38\u8bf4\u7684OCI\uff0c\u662f\u7531\u591a\u5bb6\u516c\u53f8\u5171\u540c\u6210\u7acb\u7684\u9879\u76ee\uff0c\u5e76\u7531linux\u57fa\u91d1\u4f1a\u8fdb\u884c\u7ba1\u7406\uff0c\u81f4\u529b\u4e8econtainer runtime\u7684\u6807\u51c6\u7684\u5236\u5b9a\u548crunc\u7684\u5f00\u53d1\u7b49\u5de5\u4f5c.<\/p>\n<p>\u662fcontainer\u7684\u6807\u51c6.<\/p>\n<p>\u76ee\u524d\u4e3b\u8981\u6709\u4e24\u4e2a\u6807\u51c6\u6587\u6863\uff1a\u5bb9\u5668\u8fd0\u884c\u65f6\u6807\u51c6 \uff08runtime spec\uff09\u548c \u5bb9\u5668\u955c\u50cf\u6807\u51c6\uff08image spec\uff09<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.opencontainers.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.opencontainers.org\/<\/a><\/p>\n<h2 id=\"runc\">runc<\/h2>\n<p>docker(libcontainer)<\/p>\n<p>runc\u652f\u6301OCI.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/opencontainers\/runc\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/opencontainers\/runc<\/a><\/p>\n<h2 id=\"rkt\">rkt<\/h2>\n<p>redhat(coreos)<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/rkt\/rkt\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/rkt\/rkt<\/a><\/p>\n<hr>\n<h1 id=\"tools\">tools<\/h1>\n<h2 id=\"dumb-init\">dumb-init<\/h2>\n<p>\u7ba1\u7406pid=1\u7684\u8fdb\u7a0b\u7684\u5b50\u8fdb\u7a0b:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/Yelp\/dumb-init\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/Yelp\/dumb-init<\/a><\/p>\n<h2 id=\"baseimage-docker\">baseimage-docker<\/h2>\n<p>\u5904\u7406container\u4e2d\u8fd0\u884c\u591a\u4e2a\u8fdb\u7a0b\u7684\u95ee\u9898:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/phusion\/baseimage-docker\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/phusion\/baseimage-docker<\/a><\/p>\n<h2 id=\"watchtower\">watchtower<\/h2>\n<p>\u6839\u636eregistry\u4e2d\u7684\u66f4\u65b0\u81ea\u52a8\u66f4\u65b0 container:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/containrrr\/watchtower\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/containrrr\/watchtower\/<\/a><\/p>\n<h2 id=\"hadolint\">hadolint<\/h2>\n<p>dockerfile \u8bed\u6cd5\u68c0\u67e5:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/hadolint\/hadolint\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/hadolint\/hadolint<\/a><\/p>\n<h2 id=\"gosu\">gosu<\/h2>\n<p>\u6743\u9650\u7ba1\u7406<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/tianon\/gosu\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/tianon\/gosu<\/a><\/p>\n<h2 id=\"swarm-cronjob\">swarm-cronjob<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/crazy-max\/swarm-cronjob\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/crazy-max\/swarm-cronjob<\/a><\/p>\n<hr>\n<h1 id=\"misc\">misc<\/h1>\n<p>get host ip(docker\/docker_gwbridge) from container:<\/p>\n<pre><code>ip route | awk '\/default\/ { print $3 }'\n<\/code><\/pre>"},{"title":"Docker","link":"https:\/\/canuxcheng.com\/post\/cncf_docker\/","pubDate":"Thu, 05 Apr 2018 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/cncf_docker\/","description":"<h1 id=\"docker\">Docker<\/h1>\n<p><a class=\"link\" href=\"https:\/\/store.docker.com\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/store.docker.com\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/hub.docker.com\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/hub.docker.com\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/docker\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/docker<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/moby\/moby\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/moby\/moby<\/a><\/p>\n<p>Docker\u662f\u4e00\u4e2a\u5bb9\u5668\u5f15\u64ce, \u5206\u4e3a\u793e\u533a\u7248CE, \u548c\u4f01\u4e1a\u7248EE, Docker\u4e0d\u662f\u865a\u62df\u673a, \u4e5f\u4e0d\u4f9d\u8d56\u865a\u62df\u5316\u6280\u672f\uff0e<\/p>\n<p>docker-cli -&gt; dockerd -&gt; containerd -&gt; shim -&gt; runc<\/p>\n<p>containerd\u662f\u5bb9\u5668\u8fd0\u884c\u65f6\u7ba1\u7406\u5f15\u64ce.<\/p>\n<p>shim\u7528\u4e8e\u7ba1\u7406\u5bb9\u5668\u751f\u547d\u5468\u671f.<\/p>\n<p>Docker\u5305\u62ec\u4e09\u4e2a\u57fa\u672c\u6982\u5ff5:<\/p>\n<ul>\n<li>\u4ed3\u5e93repository,\u96c6\u4e2d\u5b58\u653e\u955c\u50cf\u6587\u4ef6\u7684\u573a\u6240,docker hub\/store\u662f\u6700\u5927\u7684\u516c\u5f00\u4ed3\u5e93\uff0e<\/li>\n<li>\u955c\u50cfimage, \u955c\u50cf\u662f\u4e00\u4e2a\u6587\u4ef6\u7cfb\u7edf.<\/li>\n<li>\u5bb9\u5668container, \u5bb9\u5668\u662f\u955c\u50cf\u7684\u8fd0\u884c\u7684\u5b9e\u4f8b\uff0e<\/li>\n<\/ul>\n<p>\u4fee\u6539docker\u5b58\u50a8\u8def\u5f84:<\/p>\n<pre><code>$ service docker stop\n$ mv \/var\/lib\/docker \/opt\/ssd\/docker\n$ ln -s \/opt\/ssd\/docker \/var\/lib\/docker\n$ service docker start\n<\/code><\/pre>\n<p>Install:<\/p>\n<pre><code>windows:\n&lt;https:\/\/docs.docker.com\/docker-for-windows\/install\/&gt;\nlinux:\n&lt;https:\/\/docs.docker.com\/engine\/install\/ubuntu\/&gt;\nmac:\n&lt;https:\/\/github.com\/abiosoft\/colima\/blob\/main\/docs\/FAQ.md#docker&gt;\n<\/code><\/pre>\n<h2 id=\"config\">config<\/h2>\n<p><a class=\"link\" href=\"https:\/\/docs.docker.com\/engine\/reference\/commandline\/dockerd\/#daemon-configuration-file\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.docker.com\/engine\/reference\/commandline\/dockerd\/#daemon-configuration-file<\/a><\/p>\n<p>docker\u914d\u7f6e\u6587\u4ef6:<\/p>\n<pre><code>\/etc\/docker\/daemon.json\n\/lib\/systemd\/system\/docker.service\n{\n\/\/ debug\n&quot;debug&quot;: true,\n&quot;data-root&quot;\uff1a &quot;\/var\/lib\/docker&quot;,\n&quot;features&quot;: {\n&quot;buildkit&quot;: true\n},\n\/\/\u5bb9\u5668\u8bbf\u95ee\u5916\u7f51:\nip-forward=true \u4f1a\u8bbe\u7f6e net.ipv4.ip_forward=1, \u624d\u80fd\u8bbf\u95ee\u5916\u7f51\n\/\/ \u5bb9\u5668\u4e4b\u95f4\u8bbf\u95ee:\nicc=true,\niptables=true \u4f1a\u4fee\u6539iptables\u7684forward\u7b56\u7565\u4e3aaccept,\n\/\/ \u4fee\u6539\u9ed8\u8ba4docker0\n&quot;bridge&quot;:\n&quot;bip&quot;: &quot;10.0.0.1\/16&quot; \/\/ subnet + gateway\n&quot;fixed-cidr&quot;: &quot;10.41.0.0\/24&quot; \/\/ iprange\n&quot;fixed-cidr-v6&quot;: &quot;&quot;,\n&quot;mtu&quot;: 1500\n&quot;default-gateway&quot;:\n&quot;default-gateway-v6&quot;: &quot;&quot;,\n\/\/ \u4fee\u6539\u9ed8\u8ba4dns\n&quot;dns&quot; : [\n&quot;114.114.114.114&quot;,\n&quot;8.8.8.8&quot;\n]\n&quot;dns-opts&quot;: [],\n&quot;dns-search&quot;: [],\n\/\/ ipv6\n&quot;ipv6&quot;: true\n\/\/ private registry\n&quot;insecure-registries&quot;: [],\n\/\/ \u4fee\u6539registry\n&quot;registry-mirrors&quot;: [\n&quot;https:\/\/registry.docker-cn.com&quot;,\n&quot;https:\/\/z4yd270h.mirror.aliyuncs.com&quot;,\n&quot;http:\/\/f1361db2.m.daocloud.io&quot;,\n&quot;https:\/\/docker.mirrors.ustc.edu.cn&quot;\n]\n&quot;hosts&quot;: [],\n&quot;log-level&quot;: &quot;&quot;,\n&quot;tls&quot;: true,\n&quot;tlsverify&quot;: true,\n&quot;tlscacert&quot;: &quot;&quot;,\n&quot;tlscert&quot;: &quot;&quot;,\n&quot;tlskey&quot;: &quot;&quot;,\n}\n<\/code><\/pre>\n<p>proxy for pull image from google(gcr):<\/p>\n<p><a class=\"link\" href=\"https:\/\/docs.docker.com\/config\/daemon\/systemd\/#httphttps-proxy\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.docker.com\/config\/daemon\/systemd\/#httphttps-proxy<\/a><\/p>\n<hr>\n<h2 id=\"docker\u547d\u4ee4\">docker\u547d\u4ee4<\/h2>\n<p>system:<\/p>\n<pre><code>$ docker system df \/\/ Show docker disk usage\n$ docker system events \/\/ Get real time events from the server\n$ docker system info \/\/ Display system-wide information\n$ docker system prune \/\/ Remove unused data\n<\/code><\/pre>\n<p>image\u7ba1\u7406:<\/p>\n<pre><code>$ docker image COMMAND\n&gt; \u67e5\u770b\u672c\u5730\u955c\u50cf:\n$ docker image ls\n$ docker image -a\n&gt; \u6839\u636e\u521b\u5efadockerfile\uff0c\u521b\u5efa\u65b0\u7684images\n$ docker image build\n&gt; \u521b\u5efatag\n$ docker image tag\n&gt; \u5220\u9664image\n$ docker image rm &lt;IMAGE ID&gt;\n$ docker rmi &lt;IMAGE ID&gt;\n&gt; \u5220\u9664\u6240\u6709image\n$ docker rmi $(docker images -a -q)\n&gt; \u6e05\u7406\u6240\u6709\u4e34\u65f6images\n$ docker image prune\n<\/code><\/pre>\n<p>container\u7ba1\u7406<\/p>\n<pre><code>$docker container COMMAND\n# \u5217\u51facontainer:\n$ docker container ls\n$ docker ps -a # \u9ed8\u8ba4\u53ea\u663e\u793arunning\u72b6\u6001\u7684\n# \u8fd0\u884cimage,\u4ea7\u751f\u4e00\u4e2acontainer:\n$ docker container run &lt;IMAGE ID&gt;\/&lt;REPOSITORY&gt; [COMMAND] [ARGS]\n# \u5728container\u4e2d\u6267\u884c\u547d\u4ee4\n$ docker container exec [OPTIONS] &lt;CONTAINER&gt; COMMAND [ARG...]\n# \u521b\u5efacontainer\u4f46\u4e0d\u542f\u52a8\n$ docker container create --name &lt;name&gt; &lt;CONTAINER&gt;\n# \u542f\u52a8container:\n$ docker container start\/restart &lt;CONTAINER&gt;\n# \u505c\u6b62container:\n$ docker container stop &lt;CONTAINER&gt;\n# \u5220\u9664container\uff1a\n$ docker container rm &lt;CONTAINER&gt;\n$ docker rm &lt;CONTAINER&gt;\n# \u5220\u9664\u6240\u6709\u5bb9\u5668\n$ docker rm $(docker ps -a -q)\n# \u6e05\u7406\u505c\u6b62\u7684container\n$ docker container prune\n<\/code><\/pre>\n<p>\u5236\u4f5c\u955c\u50cfbuilder<\/p>\n<p>build: deprecated.<\/p>\n<pre><code># \u6839\u636eDockerfile \u6784\u5efaimage\ndocker builder [OPTIONS] PATH | URL | -\ndocker builder build . \/\/ \u9ed8\u8ba4\u5c31\u662f\u5f53\u524d\u76ee\u5f55\u7684Dockerfile\ndocker builder build -t &lt;repo&gt;\/&lt;name&gt;:&lt;tag&gt; . \/\/ \u521b\u5efatag\ndocker builder build -f \/path\/to\/mydockerfile . \/\/ \u4e5f\u53ef\u4ee5\u6307\u5b9a\u5176\u5b83\u8def\u5f84\u7684\u5176\u5b83\u6587\u4ef6\ndocker builder build --target &lt;stage&gt; . \/\/ \u6307\u5b9a\u9636\u6bb5\u6784\u5efa.\ndocker builder build ... --network=host \/\/ \u4f7f\u7528host\u7f51\u7edc\u6784\u5efa.\ndocker builder build --no-cache \/\/ \u4e0d\u4f7f\u7528\u7f13\u5b58\u6570\u636e\n--cache-from \/\/ \u4f7f\u7528\u672c\u5730\u6216registry\u4e0a\u7684cache\n--cache-to \/\/ cache\u5b58\u5230\u672c\u5730\u6216registry\n--progress = auto\/plain\/tty, \/\/ plain \u663e\u793a\u66f4\u591alog\u3002\ndocker builder prune --all \/\/ \u6e05\u7406\u6240\u6709image \u7684\u7f13\u5b58\u3002\n# \u628aimage\u5bfc\u51fa\u5230tar\u5305\n# \u65e2\u53ef\u4ee5\u4eceimage\u4e5f\u53ef\u4ee5\u4ececontainer\u5bfc\u51fa\u3002\n# \u4ececontainer\u5bfc\u51fa\u4e0d\u5305\u542b\u8fd0\u884c\u540e\u7684\u4fee\u6539\uff0c\u53ea\u5bfc\u51fa\u539f\u59cb\u955c\u50cf\u3002\n$ docker save -o name.tgz &lt;repo1&gt;:&lt;tag1&gt; &lt;repo2&gt;:&lt;tag2&gt; ...\n# \u4ecestdin\u6216\u6587\u4ef6\u52a0\u8f7dimage\ndocker load [OPTIONS]\ndocker load &lt; name.tar.gz\ndocker load --input\/-i name.tar\n# \u628acontainer\u5bfc\u51fa\u5230tar\u5305\uff0c\u4ececontainer\u5bfc\u51fa\u955c\u50cf\u3002\n# \u5305\u62eccontainer\u542f\u52a8\u540e\u7684\u4fee\u6539\u3002\ndocker export -o name.tar [container]\n# \u4ececontainer\u5bfc\u51fa\u7684\u5305\u52a0\u8f7d\u6210\u955c\u50cf\ndocker import name.tar [repo]:[tag]\n# \u6839\u636econtainer\u7684\u4fee\u6539\u521b\u5efa\u65b0\u7684image\ndocker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]\ndocker commit -a &quot;author&quot; -c &quot;Dockerfile instruction&quot; -m &quot;commit message&quot; CONTAINER [REPOSITORY[:TAG]]\n# \u521b\u5efa\u65b0\u7684tag\ndocker tag &lt;old&gt; &lt;new&gt;\n<\/code><\/pre>\n<p>\u8fd0\u884c\u5bb9\u5668<\/p>\n<pre><code># \u521b\u5efa\u4e00\u4e2a\u65b0\u7684container\u5e76\u8fd0\u884c\u547d\u4ee4\ndocker run [OPTIONS] IMAGE [COMMAND] [ARG...]\ndocker run --name [NAME] IMAGE \/\/ \u8fd0\u884c\u5bb9\u5668\u5e76\u547d\u540d\ndocker run -d IMAGE \/\/ \u540e\u53f0\u8fd0\u884c\ndocker run -it IMAGE \/bin\/bash \/\/ \u4ea4\u4e92\u6a21\u5f0f\u542f\u52a8\u5bb9\u5668\ndocker run -rm ... \/\/ \u8fd0\u884c\u540e\u5220\u9664\u5bb9\u5668\ndocker run -P IMAGE \/\/ \u9ed8\u8ba4\u5c06\u5bb9\u5668\u76848\uff10\u7aef\u53e3\u6620\u5c04\u5230\u4e3b\u673a\u7684\u968f\u673a\u7aef\ndocker run -p [host:port]:[containerPort] \/\/ \u6307\u5b9a\u6620\u5c04\u7aef\u53e3\n--add-host # \u76f8\u5f53\u4e8e\u4fee\u6539\u5bb9\u5668\u7684\/etc\/hosts,\u4f46\u662f\u5bb9\u5668\u91cd\u542f\u540e\u4e0d\u4f1a\u6d88\u5931\n-h\/--hostname # \u4fee\u6539\u5bb9\u5668\u7684\/etc\/hostname\\\n--runtime # \u6307\u5b9a\u8fd0\u884c\u65f6\n--device # \u76f4\u63a5\u628a\u4e3b\u673a\u7684\u8bbe\u5907\u8282\u70b9\u6620\u5c04\u5230\u5bb9\u5668\n--gpus all \/\/ \u6240\u6709gpu\n\/\/ cpu\n--cpus decimal Number of CPUs\n-c, --cpu-shares int CPU shares (relative weight)\n--cpuset-cpus string CPUs in which to allow execution (0-3, 0,1)\n--cpuset-mems string MEMs in which to allow execution (0-3, 0,1)\n--cpu-period\n--cpu-quota\n\/\/ memory\n-m, --memory bytes Memory limit\n--memory-reservation bytes Memory soft limit\n--memory-swap bytes Swap limit equal to memory plus swap: '-1' to enable unlimited swap\n--memory-swappiness int Tune container memory swappiness (0 to 100) (default -1)\n--oom-kill-disable\n--oom-score-adj\n--kernel-memory\n\/\/ io\n--blkio-weight\n--blkio-weight-device\n--device-read-bps\n--device-write-bps\n--device-read-iops\n--device-write-iops\n\/\/ security\n\/\/ https:\/\/docs.docker.com\/engine\/security\/apparmor\/\n\/\/ https:\/\/docs.docker.com\/engine\/security\/seccomp\/\n\/\/ https:\/\/docs.docker.com\/engine\/security\/userns-remap\/\n\/\/ https:\/\/docs.docker.com\/engine\/security\/rootless\/\nprivileged\nsysctl\nulimit\nuser\nuserns\nsecurity_ops\ncgroup_parent\ncap_add\ncap_drop\n# \u5728\u8fd0\u884c\u7684container\u4e2d\u6267\u884c\u547d\u4ee4\ndocker exec [OPTIONS] CONTAINER COMMAND [ARG...]\ndocker exec -d CONTAINER ... \/\/ \u5728\u540e\u53f0\u8fd0\u884c\ndocker exec -it CONTAINER \/bin\/bash ... \/\/ \u8fdb\u5165\u547d\u4ee4\u884c\n# metrics\ndocker stats\n# resource\ndocker top\n<\/code><\/pre>\n<p>log:<\/p>\n<pre><code>\/\/ \u67e5\u770blog driver\n\/\/ \u9ed8\u8ba4driver\u662f json-file, \u4e0d\u540c\u7684driver\uff0coption\u4e0d\u540c\n\/\/ driver\u662fjson-file, journald, \u901a\u8fc7docker logs docker-compose logs \u624d\u80fd\u770b\u5230log\n$ docker inspect -f '{{.HostConfig.LogConfig.Type}}' &lt;ID&gt;\ndocker run -it --log-driver &lt;driver&gt; --log-opt mode=blocking --log-opt max-buffer-size=4m alpine ash\n\/\/ --log-driver json-file\n\/\/ --log-opt mode blocking\/non-blocking\n\/\/ --log-opt max-buffer-size\n<\/code><\/pre>\n<p>\u5176\u5b83\u547d\u4ee4<\/p>\n<pre><code># \u5728container\u548chost\u4e4b\u524d\u62f7\u8d1d\u6587\u4ef6\u548c\u76ee\u5f55\ndocker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-\ndocker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH\n# \u67e5\u770b\u5bb9\u5668\u7684\u65e5\u5fd7\ndocker logs [OPTIONS] CONTAINER\ndocker diff CONTAINER\ndocker history [OPTIONS] IMAGE\n# \u67e5\u770bhealthcheck\u7684log\ndocker inspect --format &quot;{{json .State.Health }}&quot; &lt;container name&gt; | jq\ndocker system prune\n<\/code><\/pre>\n<p>register\u4f7f\u7528<\/p>\n<pre><code># \u767b\u9646\u5230docker hub \u6216\u5176\u4ed6register\ndocker login\ndocker login -u\/--username &lt;user&gt; -p\/--password &lt;password&gt;\n# \u4ecedocker hub\/store\u67e5\u627eimages\n$ docker search [OPTIONS] TERM\n$ docker search\n# \u4eceregistry\u83b7\u53d6repository\/images\u5230\/var\/lib\/docker\uff1a\n$ docker pull [OPTIONS] NAME[:TAG|@DIGEST]\n$ docker pull\n$ docker pull ubuntu # \u9ed8\u8ba4\u4e0b\u8f7d\u6240\u6709tag\n$ docker pull ubuntu:14.04\n# \u4ece\u4e2d\u56fd\u7ad9\u70b9\u4e0b\u8f7d\n$ docker pull registry.docker-cn.com\/library\/ubuntu:16.04\n# \u63a8\u9001\u5230docker hub\n$ docker push\n<\/code><\/pre>\n<p>secret<\/p>\n<p>secret\u4ee5\u6587\u4ef6\u5f62\u5f0f\u5b58\u5728\u4e8e\/run\/secrets\/<!-- raw HTML omitted --><\/p>\n<pre><code>\/\/ \u4fdd\u5b58\u654f\u611f\u6570\u636e\n$ docker secret\ndocker secret ls\ndocker secret inspect &lt;ID\/name&gt;\ndocker secret rm &lt;id\/name&gt;\n\/\/ \u6839\u636e\u6587\u4ef6\u521b\u5efa\ndocker secret create &lt;s-name&gt; &lt;s-file&gt;\n<\/code><\/pre>\n<p>config<\/p>\n<p>config\u4ee5\u6587\u4ef6\u5f62\u5f0f\u5b58\u5728\u4e8e\/<!-- raw HTML omitted --><\/p>\n<pre><code>\/\/ \u4fdd\u5b58\u975e\u654f\u611f\u6570\u636e\n$ docker config\ndocker config ls\ndocker config inspect &lt;id\/name&gt;\ndocker config rm &lt;id\/name&gt;\ndocker config create &lt;c-name&gt; &lt;c-file&gt;\n<\/code><\/pre>\n<p>plugin<\/p>\n<pre><code>\/\/ \u5b89\u88c5plugin\ndocker plugin install --grant-all-permissions name:tag key=value key=value\n\/\/ \u4fee\u6539plugin\u7684\u53c2\u6570\ndocker plugin set name:tag key=value\n\/\/ \u67e5\u770bplugin\u7684\u53c2\u6570\uff0csettable\u91cc\u9762\u7684\u662f\u6539\u53c2\u6570\u80fd\u4fee\u6539\u7684\u53d8\u91cf\ndocker plugin inspect name:tag\n\/\/ \u6fc0\u6d3bplugin\ndocker plugin enable name:tag\n\/\/ \u5220\u9664\ndocker plugin rm name:tag\n<\/code><\/pre>\n<p>\u5f00\u53d1\u63d2\u4ef6:<\/p>\n<pre><code>docker plugin create name:tag .\/plugin\ndocker plugin push name:tag\n<\/code><\/pre>\n<hr>\n<h2 id=\"dockerfile\">Dockerfile<\/h2>\n<p>\u6bcf\u4e2a\u547d\u4ee4\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2alayer,\u5c3d\u53ef\u80fd\u5408\u5e76\u76f8\u540c\u7684\u547d\u4ee4\u3002<\/p>\n<p>ADD<\/p>\n<pre><code># add\u53ef\u4ee5\u662f\u8fdc\u7a0b\u6587\u4ef6\uff0c\u4e0d\u63a8\u8350\u4f7f\u7528\nADD [--chown=&lt;user&gt;:&lt;group&gt;] &lt;src&gt;... &lt;dest&gt;\nADD [--chown=&lt;user&gt;:&lt;group&gt;] [&quot;&lt;src&gt;&quot;,... &quot;&lt;dest&gt;&quot;]\n<\/code><\/pre>\n<p>COPY<\/p>\n<pre><code># \u53ea\u80fd\u64cd\u4f5c\u672c\u5730\u6587\u4ef6, \u76ee\u6807\u8def\u5f84\u4e0d\u9700\u8981\u521b\u5efa\uff0c\u4e0d\u5b58\u5728\u4f1a\u81ea\u52a8\u521b\u5efa.\nCOPY [--chown=&lt;user&gt;:&lt;group&gt;] &lt;src&gt;... &lt;dest&gt;\nCOPY [--chown=&lt;user&gt;:&lt;group&gt;] [&quot;&lt;src&gt;&quot;,... &quot;&lt;dest&gt;&quot;]\nCOPY file \/path\/to\/file \u76f8\u5f53\u4e8e COPY file \/path\n# \u4e0d\u4f1a\u521b\u5efa\u76ee\u5f55\nCOPY folder \/path \u76f8\u5f53\u4e8e COPY folder\/* \/path\/\n# \u9700\u8981\u624b\u52a8\u6307\u5b9a\nCOPY folder \/path\/to\/folder\n<\/code><\/pre>\n<p>ENV<\/p>\n<pre><code>env\u4f1a\u88ab\u6d3e\u751fimage\u7ee7\u627f\u3002\n# \u6307\u5b9a\u5bb9\u5668\u4e2d\u7684\u73af\u5883\u53d8\u91cf\nENV &lt;key&gt; &lt;value&gt;\nENV &lt;key&gt;=&lt;value&gt; ...\n<\/code><\/pre>\n<p>EXPOSE<\/p>\n<pre><code>expose\u4f1a\u88ab\u6d3e\u751fimage\u7ee7\u627f.\n# \u6307\u5b9a\u5bb9\u5668\u9700\u8981\u6620\u5c04\u5230\u4e3b\u673a\u7684\u7aef\u53e3\nEXPOSE &lt;port&gt; [&lt;port&gt;\/&lt;protocol&gt;...]\n<\/code><\/pre>\n<p>FROM<\/p>\n<pre><code>FROM &lt;image&gt; [AS &lt;name&gt;]\nFROM &lt;image&gt;[:&lt;tag&gt;] [AS &lt;name&gt;]\nFROM &lt;image&gt;[@&lt;digest&gt;] [AS &lt;name&gt;]\n<\/code><\/pre>\n<p>LABEL<\/p>\n<pre><code>label\u4f1a\u88ab\u6d3e\u751fimage\u7ee7\u627f.\nLABEL &lt;key&gt;=&lt;value&gt; &lt;key&gt;=&lt;value&gt; &lt;key&gt;=&lt;value&gt; ...\n<\/code><\/pre>\n<p>STOPSIGNAL<\/p>\n<pre><code>STOPSIGNAL signal\n<\/code><\/pre>\n<p>USER<\/p>\n<pre><code>USER &lt;user&gt;[:&lt;group&gt;]\nUSER &lt;UID&gt;[:&lt;GID&gt;]\n<\/code><\/pre>\n<p>VOLUME<\/p>\n<pre><code># \u6307\u5b9a\u6302\u8f7d\u70b9\u505a\u6570\u636e\u6301\u4e45\u5316\nVOLUME [&quot;\/data&quot;]\n<\/code><\/pre>\n<p>WORKDIR<\/p>\n<pre><code>workdir\u4f1a\u88ab\u6d3e\u751fimage\u7ee7\u627f.\n# \u6307\u5b9a\u540e\u7684\u64cd\u4f5c\u90fd\u4ee5\u8be5\u76ee\u5f55\u4e3a\u5f53\u524d\u76ee\u5f55\uff0c\u76ee\u5f55\u4e0d\u5b58\u5728\u4f1a\u81ea\u52a8\u521b\u5efa\nWORKDIR \/path\/to\/workdir\n<\/code><\/pre>\n<p>RUN<\/p>\n<pre><code># \u5728\u5bb9\u5668\u6784\u5efa\u8fc7\u7a0b\u4e2d\u8fd0\u884c\nRUN &lt;command&gt; # shell \u683c\u5f0f\nRUN [&quot;executable&quot;, &quot;param1&quot;, &quot;param2&quot;] # exec \u683c\u5f0f\nRUN set -ex \\\n&amp;&amp; cmd1 \\\n&amp;&amp; cmd2......\n<\/code><\/pre>\n<p>ENTRYPOINT<\/p>\n<pre><code>entrypoint\u4f1a\u88ab\u6d3e\u751fimage\u7ee7\u627f\uff0c\u9664\u975e\u4f60\u5728\u6d3e\u751fimage\u91cd\u65b0\u6307\u5b9a.\n# \u548ccmd\u7c7b\u4f3c,\u6307\u5b9a\u5bb9\u5668\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u7684\u6267\u884c\u547d\u4ee4\nENTRYPOINT [&quot;executable&quot;, &quot;param1&quot;, &quot;param2&quot;] (exec form, preferred)\nENTRYPOINT command param1 param2\n<\/code><\/pre>\n<p>CMD<\/p>\n<pre><code>cmd\u4f1a\u88ab\u6d3e\u751fimage\u7ee7\u627f\uff0c\u9664\u975e\u4f60\u5728\u6d3e\u751fimage\u91cd\u65b0\u6307\u5b9a\u4e86entrypoint.\n# \u5728\u5bb9\u5668\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u8fd0\u884c, \u53ef\u4ee5\u88ab\u8986\u76d6\nCMD [&quot;executable&quot;, &quot;param1&quot;, &quot;param2&quot;] # exec\u683c\u5f0f\nCMD command param1 param2 # shell \u683c\u5f0f,\u901a\u8fc7\/bin\/bash \u6216 \/bin\/sh \u6267\u884c.\n\/\/ \u540c\u65f6\u6709cmd\u548centrypoint,cmd\u53ea\u662fentrypoint\u7684\u53c2\u6570.\nCMD [&quot;param2&quot;, &quot;param2&quot;] # entrypoint\u7684\u53c2\u6570\n<\/code><\/pre>\n<p>ARG<\/p>\n<pre><code># \u6307\u5b9a\u6784\u5efa\u73af\u5883\u7684\u53d8\u91cf\nARG &lt;name&gt;[=&lt;default value&gt;]\n<\/code><\/pre>\n<p>ONBUILD<\/p>\n<pre><code>onbuild\u4f1a\u88ab\u6d3e\u751fimage\u7ee7\u627f.\nONBUILD ...\n<\/code><\/pre>\n<p>stage:<\/p>\n<p>\u591a\u7ea7\u6784\u5efa\uff0c\u4e00\u822c0\u7ea7\u7528\u6765\u7f16\u8bd1\u6e90\u4ee3\u7801\uff0c\u5e76\u4e14\u7ec4\u7ec7\u76ee\u5f55\u7ed3\u6784\u3002\n\u4e0b\u4e00\u7ea7\u76f4\u63a5\u5c06\u7f16\u8bd1\u597d\u7684\u6216\u8005\u7ec4\u7ec7\u597d\u7684\u76ee\u5f55\u7ed3\u6784copy\u5230\u6307\u5b9a\u4f4d\u7f6e\u3002\n\u8fd9\u6837\u6700\u7ec8\u7684image\u4e0d\u4f1a\u542b\u6709\u6e90\u4ee3\u7801\u7684overlay.\n\u4e5f\u4e0d\u4f1a\u6709\u4e34\u65f6\u76ee\u5f55\u7ed3\u6784\u7684overlay.<\/p>\n<pre><code># \u4e0d\u6307\u5b9astage name, \u9ed8\u8ba4\u5c31\u662f\u6570\u5b57\nCOPY --from=0 \/path\/folder \/path\/folder\nCOPY --from=stage1 \/path\/folder \/path\/folder\ndocker build --target stage1 -t docker:latest .\n<\/code><\/pre>\n<p>.dockerignore\u00a0<\/p>\n<pre><code># comment\n\/path\/folder\npath\/folder\n*\/tmp*\n*\/*\/tmp*\ntmp?\n*.md\n!README.md\n<\/code><\/pre>\n<hr>\n<h2 id=\"docker-machine\">docker-machine<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/docker\/machine\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/docker\/machine<\/a><\/p>\n<p>\u5728\u672c\u5730\u5b89\u88c5docker\u548cdocker-machine\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u4ece\u672c\u673a\u5b89\u88c5\u6216\u7ba1\u7406\u8fdc\u7a0b\u673a\u5668\u4e0a\u7684docker.<\/p>\n<p>\u9700\u8981\u6dfb\u52a0ssh\u7684\u65e0\u5bc6\u7801\u767b\u9646:<\/p>\n<pre><code>ssh-copy-id -i ~\/.ssh\/id_rsa.pub user@remote-ip\n<\/code><\/pre>\n<p>\u5b89\u88c5:<\/p>\n<pre><code>https:\/\/docs.docker.com\/machine\/install-machine\/$ base=https:\/\/github.com\/docker\/machine\/releases\/download\/v0.16.0\n&amp;&amp; curl -L $base\/docker-machine-$(uname -s)-$(uname -m) &gt;\/tmp\/docker-machine\n&amp;&amp; sudo install \/tmp\/docker-machine \/usr\/local\/bin\/docker-machine\n<\/code><\/pre>\n<h3 id=\"docker-machine\u547d\u4ee4\">docker-machine\u547d\u4ee4<\/h3>\n<pre><code>docker-machine create -d generic \\\n--generic-ip-address=remote-ip \\\n--generic-ssh-user=user \\\n--generic-ssh-key ~\/.ssh\/id_rsa \\\nnode1\ndocker-machine ls\n<\/code><\/pre>\n<hr>\n<h2 id=\"oom\">OOM<\/h2>\n<p>kernel OOM \u4f1a\u5bfc\u81f4kernel\u968f\u673akill\u4e00\u4e9bcontainer\u91ca\u653e\u5185\u5b58\u3002<\/p>\n<p>\u9632\u6b62kernel OOM\u7684\u65b9\u6cd5\u5c31\u662f\u8bbe\u7f6eresource limit.<\/p>\n<p><a class=\"link\" href=\"https:\/\/docs.docker.com\/config\/containers\/resource_constraints\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.docker.com\/config\/containers\/resource_constraints\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/docker\/compose\/issues\/4513\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/docker\/compose\/issues\/4513<\/a><\/p>\n<p>swarm mode:<\/p>\n<p>swarm\u6a21\u5f0f\u4f7f\u7528compose format 3\u6765\u9650\u5236\u8d44\u6e90.<\/p>\n<p><a class=\"link\" href=\"https:\/\/docs.docker.com\/compose\/compose-file\/#resources\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.docker.com\/compose\/compose-file\/#resources<\/a><\/p>\n<p>non swarm mode:<\/p>\n<p>\u975eswarm\u6a21\u5f0f\u53ef\u4ee5\u7528compose format 2 \u6765\u505a\u8d44\u6e90\u9650\u5236.<\/p>\n<p><a class=\"link\" href=\"https:\/\/docs.docker.com\/compose\/compose-file\/compose-file-v2\/#cpu-and-other-resources\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.docker.com\/compose\/compose-file\/compose-file-v2\/#cpu-and-other-resources<\/a><\/p>\n<hr>\n<h2 id=\"colima\">colima<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/abiosoft\/colima\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/abiosoft\/colima<\/a><\/p>\n<p>docker for mac<\/p>\n<pre><code>brew install colima docker\ncolima start\nbrew services restart colima\nsudo ln -sf \/Users\/canche01\/.colima\/default\/docker.sock \/var\/run\/docker.sock\ndocker ps -a\n<\/code><\/pre>\n<p>\u6709vpn\u4e0b\u8f7dimage\u5931\u8d25\u5904\u7406\uff1a<\/p>\n<pre><code># vi ~\/.colima\/default\/colima.yaml\nenv:\nHTTP_PROXY: http:\/\/127.0.0.1:40009\nHTTPS_PROXY: http:\/\/127.0.0.1:40009\n<\/code><\/pre>"},{"title":"Kubernetes","link":"https:\/\/canuxcheng.com\/post\/kubernetes\/","pubDate":"Thu, 05 Apr 2018 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/kubernetes\/","description":"<h1 id=\"kubernetes\">Kubernetes<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes\/kubernetes\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes\/kubernetes<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes\/kubeadm\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes\/kubeadm<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes\/kops\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes\/kops<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes-sigs\/kubespray\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes-sigs\/kubespray<\/a><\/p>\n<p>kubernetes\u7b80\u79f0k8s, \u662f\u5f00\u6e90\u7684\u5bb9\u5668\u7f16\u6392\u5de5\u5177\u3002<\/p>\n<p>\u5b89\u88c5\u5355\u673a\u7248k8s:<\/p>\n<ul>\n<li>minikube<\/li>\n<\/ul>\n<p>\u5b89\u88c5k8s\u96c6\u7fa4:<\/p>\n<ul>\n<li>kubeadm (k8s\u5185\u7f6e\u7684\uff0c\u7c7b\u4f3c\u4e8edocker swarm mode, \u6ca1\u6709HA)<\/li>\n<li>kops (\u76ee\u524d\u4e3b\u8981\u652f\u6301aws\u7b49\u4e91\u5e73\u53f0, \u56fd\u5185\u4e0d\u53cb\u597d)<\/li>\n<li>kubespray (\u901a\u8fc7ansible\u90e8\u7f72, \u56fd\u5185\u4e0d\u53cb\u597d)<\/li>\n<\/ul>\n<p>k8s\u53d1\u884c\u7248\uff1a<\/p>\n<ul>\n<li>openshift-okd(redhat)<\/li>\n<li>rancher<\/li>\n<\/ul>\n<h1 id=\"k8s\u96c6\u7fa4\u7ec4\u6210\">k8s\u96c6\u7fa4\u7ec4\u6210<\/h1>\n<h2 id=\"master\">master<\/h2>\n<ul>\n<li>aip-server, \u63d0\u4f9b\u8d44\u6e90\u64cd\u4f5c\u552f\u4e00\u5165\u53e3<\/li>\n<li>scheduler, \u8d1f\u8d23\u8d44\u6e90\u8c03\u5ea6<\/li>\n<li>controller-manager, \u8d1f\u8d23\u7ef4\u62a4\u96c6\u7fa4\u72b6\u6001<\/li>\n<li>etcd(\u53ef\u4ee5\u90e8\u7f72\u5355\u72ec\u96c6\u7fa4), \u4fdd\u5b58\u6574\u4e2a\u96c6\u7fa4\u7684\u72b6\u6001<\/li>\n<\/ul>\n<h2 id=\"node\">node<\/h2>\n<ul>\n<li>kubelet, \u8d1f\u8d23\u7ef4\u62a4\u5bb9\u5668\u751f\u547d\u5468\u671f, \u8fd8\u5305\u62ecCNI CVI<\/li>\n<li>kube-proxy, \u4e3aservice\u63d0\u4f9bcluster\u5185\u90e8\u7684\u670d\u52a1\u53d1\u73b0\u548c\u8d1f\u8f7d\u5747\u8861<\/li>\n<li>CRI(containerd), \u521b\u5efapod<\/li>\n<\/ul>\n<h2 id=\"addons\">addons<\/h2>\n<ul>\n<li>coredns<\/li>\n<li>flannel\/cilium\/calico<\/li>\n<li>dashboard, web-gui<\/li>\n<li>metrics-server, \u53d6\u4ee3heapster\uff0c\u7528\u4e8ecpu\/memory\u76d1\u63a7<\/li>\n<li>ingress-nginx, \u4e3a\u670d\u52a1\u63d0\u4f9b\u5916\u7f51\u5165\u53e3<\/li>\n<li>federation, \u63d0\u4f9b\u8de8\u53ef\u7528\u533a\u7684\u96c6\u7fa4<\/li>\n<\/ul>\n<hr>\n<h1 id=\"\u6982\u5ff5\">\u6982\u5ff5<\/h1>\n<p>k8s\u5305\u542b\u7684\u91cd\u8981\u6982\u5ff5:<\/p>\n<p>-: nodes, \u8fd0\u884cpod\u7684\u7269\u7406\u673a\u6216\u865a\u62df\u673a.\n-: namespace, \u5bf9\u8d44\u6e90\u548c\u5bf9\u8c61\u7684\u62bd\u8c61\u96c6\u5408\uff0epods\/deployments\/services\u90fd\u5c5e\u4e8e\u67d0\u4e2ans.\n-: pods,\u4e00\u7ec4\u7d27\u5bc6\u5173\u8054\u7684\u5bb9\u5668\u96c6\u5408\uff0c\u5171\u4eabpid,ipc,network,uts,namespace.<\/p>\n<p>k8s\u4e1a\u52a1\u7c7b\u578b:<\/p>\n<p>-: long-running \u957f\u671f\u4f3a\u670d\u578b -&gt; RC, RS, Deployment\n-: batch \u6279\u5904\u7406\u578b-&gt; Job\n-: node-daemon \u8282\u70b9\u540e\u53f0\u652f\u6491\u578b-&gt; DaemonSet\n-: stateful application \u6709\u72b6\u6001\u5e94\u7528\u578b-&gt; StatefulSet<\/p>\n<p>api\u5bf9\u8c61\u4e09\u5927\u7c7b\u5c5e\u6027:<\/p>\n<ul>\n<li>metadata \u5143\u6570\u636e(\u81f3\u5c11\u5305\u542bnamespace, name, uid).<\/li>\n<li>spec \u89c4\u8303<\/li>\n<li>status \u72b6\u6001<\/li>\n<\/ul>\n<p>kubernetes\u5bf9\u5916\u66b4\u9732\u670d\u52a1\u7684\u4e09\u79cd\u65b9\u5f0f:<\/p>\n<ul>\n<li>NodePort: dev\/qa. (30000-32767)<\/li>\n<li>LoadBalance: cloud provider.<\/li>\n<\/ul>\n<p>clusterIP \u662fk8s\u5185\u90e8\u9ed8\u8ba4\u670d\u52a1\uff0c\u5916\u90e8\u65e0\u6cd5\u8bbf\u95ee\uff0c\u53ef\u4ee5\u901a\u8fc7proxy\u6765\u8bbf\u95ee\u3002<\/p>\n<hr>\n<h1 id=\"pod\">pod<\/h1>\n<p>\u4e00\u4e2apod\u5305\u542b\u4e00\u4e2a\u6216\u591a\u4e2a\u5bb9\u5668\uff0c\u8fd9\u4e9b\u5bb9\u5668\u901a\u8fc7infra container\u5171\u4eab\u540c\u4e00\u4e2anetwork namespace\u3002<\/p>\n<p>infra container: k8s.gcr.io\/pause, \u6c47\u7f16\u5199\u7684\uff0c\u6c38\u8fdc\u5904\u4e8e\u6682\u505c\u72b6\u6001\u3002<\/p>\n<p>pod\u5171\u4eab\u7f51\u7edc:<\/p>\n<p>\u540c\u4e00\u4e2apod\u91cc\u9762\u770b\u5230\u7684\u7f51\u7edc\u8ddfinfra\u5bb9\u5668\u770b\u5230\u7684\u662f\u4e00\u6837\u7684\uff0c\u4e00\u4e2apod\u53ea\u6709\u4e00\u4e2aip,\u4e5f\u5c31\u662f\u8fd9\u4e2aPod\u7684network namespace\u5bf9\u5e94\u7684IP; \u6574\u4e2apod\u7684\u751f\u547d\u5468\u671f\u8ddfinfra\u5bb9\u6613\u662f\u4e00\u6837\u7684\u3002<\/p>\n<p>pod\u5171\u4eab\u5b58\u50a8:<\/p>\n<p>\u901a\u8fc7pod volumes, \u4f7fpod\u4e2d\u7684container\u5171\u4eab\u5b58\u50a8\u3002<\/p>\n<p>\u5e94\u7528:<\/p>\n<ul>\n<li>\u4e00\u4e2apod\u4e2d\u7684\u67d0\u4e2a\u5bb9\u5668\u5f02\u5e38\u9000\u51fa\uff0c\u88abkubelet\u62c9\u8d77\u6765\u4e4b\u524d\u4fdd\u8bc1\u4e4b\u524d\u7684\u6570\u636e\u4e0d\u4e22\u5931.<\/li>\n<li>\u540c\u4e00\u4e2apod\u7684\u591a\u4e2a\u5bb9\u5668\u5171\u4eab\u6570\u636e.<\/li>\n<\/ul>\n<p>pod volume\u7c7b\u578b:<\/p>\n<ol>\n<li>\n<p>\u672c\u5730\u5b58\u50a8: emptydir\/hostpath&hellip;<\/p>\n<\/li>\n<li>\n<p>\u7f51\u7edc\u5b58\u50a8:<\/p>\n<p>in-tree(ks8\u5185\u7f6e\u652f\u6301): awsElasticBlockStore\/gcePresistentDisk\/nfs&hellip;\nout-of-tree(\u63d2\u4ef6): flexvolume\/csi&hellip;<\/p>\n<\/li>\n<li>\n<p>projected volume: secret\/configmap\/downwardAPI\/serviceAccountToken<\/p>\n<\/li>\n<\/ol>\n<p>pod\u670d\u52a1\u8d28\u91cf\u914d\u7f6e:<\/p>\n<p>\u4f9d\u636e\u5bb9\u5668\u5bf9cpu,memory\u8d44\u6e90\u7684request\/limit\u9700\u6c42\uff0cpod\u670d\u52a1\u8d28\u91cf\u5206\u7c7b:<\/p>\n<ul>\n<li>Guaranteed<\/li>\n<li>Burstable<\/li>\n<li>BestEffort<\/li>\n<\/ul>\n<p>initContainer:<\/p>\n<p>initContainer\u7528\u4e8e\u666e\u901aContainer\u542f\u52a8\u524d\u7684\u521d\u59cb\u5316\uff08\u5982\u914d\u7f6e\u6587\u4ef6\u51c6\u5907) \u548c \u524d\u7f6e\u6761\u4ef6\u6821\u9a8c (\u5982\u7f51\u7edc)\u3002<\/p>\n<ol>\n<li>initContainer\u4f1a\u5148\u4e8e\u666e\u901acontainer\u542f\u52a8\u6267\u884c\uff0c\u76f4\u5230\u6240\u6709initcontainer\u6267\u884c\u6210\u529f\u540e\uff0c\u666e\u901acontainer \u624d\u4f1a\u6267\u884c\u3002<\/li>\n<li>pod\u4e2d\u591a\u4e2ainitcontainer\u4e4b\u95f4\u662f\u6309\u6b21\u5e8f\u4f9d\u6b21\u542f\u52a8\u6267\u884c\uff0c\u800cpod\u4e2d\u591a\u4e2a\u666e\u901acontainer\u662f\u5e76\u884c\u542f\u52a8\u3002<\/li>\n<li>initcontainer \u6267\u884c\u6210\u529f\u540e\u5c31\u7ed3\u675f\u9000\u51fa\uff0c\u800c\u666e\u901acontainer\u4f1a\u4e00\u76f4\u6267\u884c\u6216\u91cd\u542f\u3002<\/li>\n<\/ol>\n<hr>\n<h1 id=\"resources\">resources<\/h1>\n<p>\u67e5\u770b\u6240\u6709\u5bf9\u8c61:<\/p>\n<pre><code>$ kubectl api-resources\n<\/code><\/pre>\n<p><a class=\"link\" href=\"https:\/\/kubernetes.io\/docs\/reference\/generated\/kubernetes-api\/v1.17\/#statefulsetcondition-v1beta2-apps\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kubernetes.io\/docs\/reference\/generated\/kubernetes-api\/v1.17\/#statefulsetcondition-v1beta2-apps<\/a><\/p>\n<h2 id=\"workloads\">Workloads<\/h2>\n<h3 id=\"replicasetsrs\">replicasets\/rs<\/h3>\n<p>\u63a7\u5236\u65e0\u72b6\u6001\u7684pod\u6570\u91cf,\u589e\u5220Pods.<\/p>\n<h3 id=\"deploymentsdeploy\">deployments\/deploy<\/h3>\n<p>\u5b9a\u4e49pod\u7684\u6570\u76ee\u548c\u7248\u672c\uff0c\u901a\u8fc7Controller\u81ea\u52a8\u6062\u590d\u5931\u8d25\u7684pod\uff0c\u6eda\u52a8\u5347\u7ea7\uff0c\u91cd\u65b0\u751f\u6210\uff0c\u56de\u6eda\u7b49\u3002<\/p>\n<p>DeploymentStatus: complete, processing, failed<\/p>\n<p>Deployment\u53ea\u8d1f\u8d23\u7ba1\u7406\u4e0d\u540c\u7248\u672c\u7684ReplicaSet, \u7531ReplicaSet\u7ba1\u7406Pod\u526f\u672c\u4e2a\u6570; \u6bcf\u4e2a\u7248\u672c\u7684ReplicaSet\u5bf9\u5e94\u4e86Deployment template\u7684\u4e00\u4e2a\u7248\u672c; \u4e00\u4e2aReplicaSet\u4e0b\u7684Pod\u90fd\u662f\u76f8\u540c\u7684\u7248\u672c.<\/p>\n<h3 id=\"daemonsetsds\">daemonsets\/ds<\/h3>\n<p>ds\u4f5c\u7528:<\/p>\n<ul>\n<li>\u4fdd\u8bc1\u96c6\u7fa4\u5185\u6bcf\u4e2a\u8282\u70b9\u8fd0\u884c\u4e00\u7ec4\u76f8\u540c\u7684pod<\/li>\n<li>\u8ddf\u8e2a\u96c6\u7fa4\u8282\u70b9\u72b6\u6001\uff0c\u4fdd\u8bc1\u65b0\u52a0\u5165\u7684\u8282\u70b9\u81ea\u52a8\u521b\u5efa\u5bf9\u5e94\u7684pod<\/li>\n<li>\u8ddf\u8e2a\u96c6\u7fa4\u8282\u70b9\u72b6\u6001\uff0c\u4fdd\u8bc1\u79fb\u9664\u7684\u8282\u70b9\u5220\u9664\u5bf9\u5e94\u7684pod<\/li>\n<li>\u8ddf\u8e2apod\u72b6\u6001\uff0c\u4fdd\u8bc1\u6bcf\u4e2a\u8282\u70b9pod\u5904\u4e8e\u8fd0\u884c\u72b6\u6001<\/li>\n<\/ul>\n<h3 id=\"jobs\">jobs<\/h3>\n<p>job\u7684\u4f5c\u7528:<\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a\u6216\u591a\u4e2apod\u786e\u4fdd\u6307\u5b9a\u6570\u91cf\u7684Pod\u53ef\u4ee5\u6210\u529f\u8fd0\u884c\u548c\u7ec8\u6b62.<\/li>\n<li>\u8ddf\u8e2apod\u72b6\u6001\uff0c\u6839\u636e\u914d\u7f6e\u53ca\u65f6\u91cd\u8bd5\u5931\u8d25\u7684pod.<\/li>\n<li>\u786e\u5b9a\u4f9d\u8d56\u5173\u7cfb\uff0c\u4fdd\u8bc1\u4e0a\u4e00\u4e2a\u4efb\u52a1\u8fd0\u884c\u5b8c\u6bd5\u540e\u518d\u8fd0\u884c\u4e0b\u4e00\u4e2a\u4efb\u52a1.<\/li>\n<li>\u63a7\u5236\u4efb\u52a1\u5e76\u884c\u5ea6\uff0c\u5e76\u6839\u636e\u914d\u7f6e\u786e\u4fddpod\u961f\u5217\u5927\u5c0f\u3002<\/li>\n<\/ul>\n<h3 id=\"cronjobscj\">cronJobs\/cj<\/h3>\n<h3 id=\"statefulsetssts\">statefulsets\/sts<\/h3>\n<p>\u63a7\u5236\u6709\u72b6\u6001\u7684pod\u6570\u91cf.<\/p>\n<hr>\n<h2 id=\"service-discovery--load-balancing\">service discovery &amp; load balancing<\/h2>\n<h3 id=\"servicessvc\">services\/svc<\/h3>\n<p>\u63d0\u4f9b\u8bbf\u95ee\u4e00\u4e2a\u6216\u591a\u4e2apod\u7684\u7a33\u5b9a\u7684\u8bbf\u95ee\u5730\u5740.\u652f\u6301ClusterIP, NodePort, LoadBalancer\u7b49\u8bbf\u95ee\u65b9\u5f0f.<\/p>\n<h3 id=\"ingresses\">ingresses<\/h3>\n<h3 id=\"endpointslices\">endpointslices<\/h3>\n<hr>\n<h2 id=\"config--storage\">Config &amp; Storage<\/h2>\n<h3 id=\"secrets\">secrets<\/h3>\n<p>secret\u7528\u4e8e\u5728\u96c6\u7fa4\u4e2d\u5b58\u50a8\u5bc6\u7801\uff0ctoken\u7b49\u654f\u611f\u4fe1\u606f\u7528\u7684\u8d44\u6e90\u5bf9\u8c61.<\/p>\n<p>\u5176\u4e2d\u654f\u611f\u6570\u636e\u91c7\u7528base-64\u7f16\u7801\u4fdd\u5b58.<\/p>\n<p>\u56db\u79cd\u7c7b\u578b:<\/p>\n<ul>\n<li>Opaque<\/li>\n<li>kubernetes.io\/service-account-token<\/li>\n<li>kubernetes.io\/dockerconfigjson<\/li>\n<li>bootstrap.kubernetes.io\/token<\/li>\n<\/ul>\n<p>secret\u4e3b\u8981\u88abpod\u4f7f\u7528\uff0c\u4e00\u822c\u901a\u8fc7volume\u6302\u8f7d\u5230\u6307\u5b9a\u5bb9\u5668\u76ee\u5f55\uff0c\u4f9b\u5bb9\u5668\u4e2d\u4e1a\u52a1\u4f7f\u7528.<\/p>\n<p>\u8bbf\u95ee\u79c1\u6709\u955c\u50cf\u4ed3\u5e93\u4e5f\u53ef\u4ee5\u901a\u8fc7secret\u5b9e\u73b0.<\/p>\n<p>secret\u5927\u5c0f\u9650\u52361M; secret\u4e0d\u9002\u5408\u673a\u5bc6\u4fe1\u606f\uff0c\u63a8\u8350\u7528vault.<\/p>\n<h3 id=\"configmapscm\">configmaps\/cm<\/h3>\n<p>\u4e3b\u8981\u7ba1\u7406\u5bb9\u5668\u8fd0\u884c\u6240\u9700\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u73af\u5883\u53d8\u91cf\uff0c\u547d\u4ee4\u884c\u53c2\u6570\u7b49\u53ef\u53d8\u914d\u7f6e\u3002<\/p>\n<p>\u53ef\u7528\u4e8e\u89e3\u8026\u5bb9\u5668\u955c\u50cf\u548c\u53ef\u53d8\u914d\u7f6e\uff0c\u4ece\u800c\u4fdd\u969c\u5de5\u4f5c\u8d1f\u8f7d\u7684\u53ef\u79fb\u690d\u6027.<\/p>\n<p>\u4e3b\u8981\u88abpod\u4f7f\u7528\uff0c\u4e00\u822c\u7528\u4e8e\u6302\u8f7dpod\u7528\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u73af\u5883\u53d8\u91cf\uff0c\u547d\u4ee4\u884c\u53c2\u6570.<\/p>\n<p>ConigMap \u5927\u5c0f\u4e0d\u8d85\u8fc71M; pod\u53ea\u80fd\u5f15\u7528\u76f8\u540cnamespace\u4e2d\u7684configmap, pod\u5f15\u7528\u7684configmap\u4e0d\u5b58\u5728\u65f6\uff0cpod\u65e0\u6cd5\u521b\u5efa;\u4f7f\u7528envFrom\u4eceConfigMap\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u65f6\uff0c\u5982\u679cConfigMap\u4e2d\u7684\u67d0\u4e9bkey\u88ab\u8ba4\u4e3a\u65e0\u6548\uff0c\u8be5\u73af\u5883\u53d8\u91cf\u4e0d\u4f1a\u6ce8\u5165\u5bb9\u5668\uff0c\u4f46\u662fpod\u53ef\u4ee5\u521b\u5efa; \u53ea\u6709\u901a\u8fc7k8s api\u521b\u5efa\u7684pod\u624d\u80fd\u4f7f\u7528ConfigMap, \u5176\u5b83\u65b9\u5f0f\u521b\u5efa\u7684pod\u4e0d\u80fd\u4f7f\u7528ConfigMap.<\/p>\n<h3 id=\"persistentvolumepv\">persistentvolume\/pv<\/h3>\n<p>static volume provisioning:<\/p>\n<p>dynamic volume provisioning:<\/p>\n<h3 id=\"persistentvolumeclaimspvc\">persistentvolumeclaims\/pvc<\/h3>\n<p>pvc\u4e2d\u53ea\u9700\u8981\u7533\u660e\u9700\u8981\u7684\u5b58\u50a8size, access mode\u7b49\u4e1a\u52a1\u9700\u6c42.<\/p>\n<p>pvc\u7b80\u5316\u4e86\u7528\u6237\u5bf9\u5b58\u50a8\u7684\u9700\u6c42\uff0cpv\u624d\u662f\u5b58\u50a8\u7684\u5b9e\u9645\u4fe1\u606f\u8f7d\u4f53\uff0c\u901a\u8fc7kube-controller-manager\u4e2d\u7684PersistentVolumeController\u5c06PVC\u4e0e\u5408\u9002\u7684PV \u7ed1\u5b9a.<\/p>\n<h3 id=\"csidrivers\">csidrivers<\/h3>\n<h3 id=\"csinodes\">csinodes<\/h3>\n<h3 id=\"storageclassessc\">storageclasses\/sc<\/h3>\n<h3 id=\"volumeattachments\">volumeattachments<\/h3>\n<hr>\n<h2 id=\"metadata\">metadata<\/h2>\n<h3 id=\"events\">events<\/h3>\n<h3 id=\"horizontalpodautoscaler\">horizontalpodautoscaler<\/h3>\n<h3 id=\"podtemplate\">podtemplate<\/h3>\n<hr>\n<h2 id=\"cluster\">cluster<\/h2>\n<h3 id=\"componentstatusescs\">componentstatuses\/cs<\/h3>\n<h3 id=\"namespacesns\">namespaces\/ns<\/h3>\n<p>\u4e00\u4e2a\u96c6\u7fa4\u5185\u90e8\u7684\u903b\u8f91\u9694\u79bb\u673a\u5236\uff0c\u6bcf\u4e2a\u8d44\u6e90\u90fd\u5c5e\u4e8e\u4e00\u4e2anamespace\uff0c\u540c\u4e00\u4e2anamespace\u4e2d\u7684\u8d44\u6e90\u547d\u540d\u552f\u4e00\uff0c\u4e0d\u540cnamespace\u4e2d\u7684\u8d44\u6e90\u53ef\u91cd\u540d.<\/p>\n<h3 id=\"nodesno\">nodes\/no<\/h3>\n<h3 id=\"serviceaccountsa\">serviceaccount\/sa<\/h3>\n<p>\u89e3\u51b3pod\u5728\u96c6\u7fa4\u4e2d\u7684\u8eab\u4efd\u8ba4\u8bc1\u95ee\u9898.<\/p>\n<hr>\n<h1 id=\"tools\">Tools<\/h1>\n<p>sonobuoy<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/vmware-tanzu\/sonobuoy\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/vmware-tanzu\/sonobuoy<\/a><\/p>\n<p>kuard<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes-up-and-running\/kuard\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes-up-and-running\/kuard<\/a><\/p>"},{"title":"Namespace","link":"https:\/\/canuxcheng.com\/post\/cncf_ns\/","pubDate":"Thu, 05 Apr 2018 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/cncf_ns\/","description":"<h1 id=\"ns\">NS<\/h1>\n<p>namespace \u662f Linux \u5185\u6838\u7528\u6765\u9694\u79bb\u5185\u6838\u8d44\u6e90\u7684\u65b9\u5f0f<\/p>\n<p>Linux namespace\u8d44\u6e90\uff1a<\/p>\n<ul>\n<li>Mount: \u6302\u8f7d\u70b9<\/li>\n<li>Network: \u7f51\u7edc\u8bbe\u5907\/\u534f\u8bae\u6808\/\u7aef\u53e3<\/li>\n<li>IPC: \u8fdb\u7a0b\u95f4\u901a\u4fe1<\/li>\n<li>USR: \u7528\u6237\u548c\u7528\u6237\u7ec4<\/li>\n<li>PID: \u8fdb\u7a0b<\/li>\n<li>UTS: \u4e3b\u673a\u540d\u548c\u57df\u540d<\/li>\n<li>Cgroup: \u63a7\u5236\u7ec4<\/li>\n<li>Time<\/li>\n<\/ul>\n<h1 id=\"cgroup\">Cgroup<\/h1>\n<p>Cgroup: Control Groups.\u662flinux\u4e0b\u7528\u4e8e\u5bf9\u4e00\u4e2a\u6216\u4e00\u7ec4\u8fdb\u7a0b\u8d44\u6e90\u63a7\u5236\u548c\u76d1\u63a7\u7684\u673a\u5236.\u53ef\u4ee5\u7ba1\u7406cpu, memory,diskIO \u7b49\u8d44\u6e90.\u4e0d\u540c\u8d44\u6e90\u7684\u5177\u4f53\u7ba1\u7406\u5de5\u4f5c\u7531\u76f8\u5e94\u7684cgrouup\u5b50\u7cfb\u7edf\u6765\u5b9e\u73b0.<\/p>\n<p>cgroup\u5728\u4e0d\u540c\u7684\u7cfb\u7edf\u8d44\u6e90\u7ba1\u7406\u5b50\u7cfb\u7edf\u4e2d\u4ee5\u5c42\u7ea7\u6811(Hierarchy)\u7684\u65b9\u5f0f\u6765\u7ec4\u7ec7\u7ba1\u7406, \u6bcf\u4e2acgroup\u53ef\u4ee5\u5305\u542b\u5176\u5b83\u5b50cgroup.<\/p>\n<pre><code>ls -l \/sys\/fs\/cgroup\n<\/code><\/pre>\n<p>cgroup\u5b50\u7cfb\u7edf:<\/p>\n<ul>\n<li>cpu<\/li>\n<li>cpuacct<\/li>\n<li>cpuset<\/li>\n<li>memory<\/li>\n<li>blkio<\/li>\n<li>devices<\/li>\n<li>freezer<\/li>\n<li>ns<\/li>\n<li>pid<\/li>\n<li>net_cls<\/li>\n<li>net_prio<\/li>\n<\/ul>\n<hr>\n<h1 id=\"lsns\">lsns<\/h1>\n<p>\u67e5\u770b\u7cfb\u7edf\u7684namespace<\/p>\n<p>ns\u7c7b\u578b: mnt, net, ipc, user, pid, uts, cgroup<\/p>\n<pre><code>$lsns -l\n$lsns -t net\n<\/code><\/pre>\n<h1 id=\"unshare\">unshare<\/h1>\n<p>\u4f7f\u7528\u975e\u5171\u4eab\u7684NS\u8fd0\u884c\u7a0b\u5e8f<\/p>\n<pre><code>\/\/ \u521b\u5efaunshare \u7684 ns\u7c7b\u578b.\n$unshare -f -m\/-n\/-i\/-U\/-p\/-u\/-C ...\n\/\/ \u5728net\u7c7b\u578b\u7684namespace\u6267\u884csleep\u547d\u4ee4\n$unshare -fn sleep 10\n<\/code><\/pre>\n<h1 id=\"nsenter\">nsenter<\/h1>\n<p>ns enter: Namespace enter.<\/p>\n<p>nsenter - run program with namespaces of other processes<\/p>\n<pre><code>$ nsenter [options] [program [arguments]]\n\/\/ \u6307\u5b9ans\u7684\u76ee\u6807\u8fdb\u7a0b\uff0c\u53ef\u4ee5\u901a\u8fc7nsls\u67e5\u770b.\n$ nsenter -t\/--target\n\/\/ \u8fdb\u5165\u6240\u6709\u7c7b\u578b\u7684ns.\n$ nsenter -a --all ...\n\/\/ \u8fdb\u5165\u6307\u5b9a\u7c7b\u578b\u7684ns\n$ nsenter -m\/-u\/-i\/-n\/-p\/-C\/-U ...\n\/\/ \u8fdb\u5165\u6307\u5b9ans\u7684\u6307\u5b9a\u8fdb\u7a0b\n$ nsenter -t &lt;pid&gt; -n ip a\n$ nsenter -S\/-G\/-r\/-w ...\n$ nsenter -F\/--no-fork ...\n$ nsenter -Z\/--follow-context ...\n<\/code><\/pre>"},{"title":"Registry","link":"https:\/\/canuxcheng.com\/post\/cncf_registry\/","pubDate":"Thu, 05 Apr 2018 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/cncf_registry\/","description":"<h1 id=\"container-registry\">Container Registry<\/h1>\n<ul>\n<li>Docker Hub Registry<\/li>\n<li>Google Container Registry (gcr.io)<\/li>\n<li>RedHat Quay Registry (quay.io)<\/li>\n<li>GitHub Docker Packages (docker.pkg.github.com)(Deprecated)<\/li>\n<li>GitHub Container Registry (ghcr.io)<\/li>\n<li>Kubernetes Registry(registry.k8s.io =&gt; k8s.gcr.io)<\/li>\n<\/ul>\n<h2 id=\"harbor\">Harbor<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/goharbor\/harbor\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/goharbor\/harbor<\/a><\/p>\n<p>Habor\u662f\u7531VMWare\u4e2d\u56fd\u56e2\u961f\u5f00\u6e90\u7684\u5bb9\u5668\u955c\u50cf\u4ed3\u5e93, \u7528\u4e8e\u5b58\u50a8\u548c\u5206\u53d1docker\u955c\u50cf\u7684registry\u670d\u52a1\u5668.<\/p>\n<p>\u5b89\u88c5\u6b65\u9aa4:<\/p>\n<ol>\n<li>\u4e0b\u8f7d\u5e76\u89e3\u538b\u5b89\u88c5\u5305, <a class=\"link\" href=\"https:\/\/github.com\/goharbor\/harbor\/releases\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/goharbor\/harbor\/releases<\/a><\/li>\n<li>\u914d\u7f6eharbor.cfg;<\/li>\n<\/ol>\n<p>\u4fee\u6539\u914d\u7f6e:<\/p>\n<pre><code>vim harbor.yml\n<\/code><\/pre>\n<p>\u8fd0\u884c\u5b89\u88c5\u7a0b\u5e8f:<\/p>\n<pre><code>.\/install.sh --with-notary --with-clair --with-chartmuseum\n<\/code><\/pre>\n<p>\u4fee\u6539web\u7684port:<\/p>\n<pre><code>$ vim \/data\/harbor\/docker-compose.yml\nproxy:\nports:\n- 8080:80 # \u9ed8\u8ba4http\u662f80\n- 4433:443 # \u9ed8\u8ba4https\u662f443\n$ vim \/data\/harbor\/harbor.yml\nhostname = ip\n<\/code><\/pre>\n<p>\u7ba1\u7406harbor:<\/p>\n<pre><code># cd \/data\/harbor\n# docker-compose down -v \u3000\u505c\u6b62\u5e76\u5220\u9664container\n&gt; \u66f4\u65b0\u914d\u7f6e\n# .\/prepare --with-notary --with-clair --with-chartmuseum\n&gt; \u542f\u52a8\n# docker-compose up -d\n<\/code><\/pre>\n<h2 id=\"docker\u4f7f\u7528harbor\">docker\u4f7f\u7528harbor<\/h2>\n<p>Deploy a plain HTTP registry:<\/p>\n<pre><code># vim \/etc\/docker\/daemon.json\n{ &quot;insecure-registries&quot; : [&quot;myregistrydomain.com:5000&quot;]}\n<\/code><\/pre>\n<p>Use self-signed certificates:<\/p>\n<pre><code># cp your-ca \/etc\/docker\/certs.d\/harbor.domain.com\/ca.crt\n# vim \/lib\/systemd\/system\/docker.service\nExecStart=\/usr\/bin\/dockerd --insecure-registry harbor.domain.com:port\n# systemctl daemon-reload\n# systemctl restart docker\n<\/code><\/pre>\n<p>update hosts on docker client:<\/p>\n<pre><code># vim \/etc\/hosts ip harbor.domain.com\n<\/code><\/pre>\n<p>create user account:<\/p>\n<pre><code>https:\/\/&lt;ip:port&gt;\n<\/code><\/pre>\n<p>push images to harbor:<\/p>\n<pre><code>$ docker login harbor.domain.com:port\n$ docker tag SOURCE_IMAGE[:TAG] harbor.domain.com:port\/&lt;project&gt;\/IMAGE[:TAG]\n$ docker push harbor.domain.com:port\/&lt;project&gt;\/IMAGE[:TAG]\n<\/code><\/pre>\n<p>pull images from harbor:<\/p>\n<pre><code>$ docker login harbor.domain.com:port\n$ docker pull harbor.domain.com:port\/&lt;project&gt;\/IMAGE[:TAG]\n<\/code><\/pre>\n<p>k8s\u4f7f\u7528harbor:<\/p>\n<p><a class=\"link\" href=\"https:\/\/kubernetes.io\/docs\/tasks\/configure-pod-container\/pull-image-private-registry\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kubernetes.io\/docs\/tasks\/configure-pod-container\/pull-image-private-registry\/<\/a><\/p>\n<h2 id=\"\u4fee\u6539\u5b58\u50a8\u8def\u5f84\">\u4fee\u6539\u5b58\u50a8\u8def\u5f84<\/h2>\n<p>\u9ed8\u8ba4\u8def\u5f84\u662f\/data\/registry<\/p>\n<p>\u505c\u670d\u52a1:<\/p>\n<pre><code>$ docker-compose down -v\n<\/code><\/pre>\n<p>\u4fee\u6539\u8def\u5f84:<\/p>\n<pre><code>$ mv \/data\/* \/new\/path\n$ vim \/new\/path\/harbor\/harbor.yml\ndata_volume: \/new\/path\n$ vim \/new\/path\/harbor\/docker-compose.yml\n\/data =&gt; \/new\/path\n<\/code><\/pre>\n<p>\u542f\u52a8\u670d\u52a1:<\/p>\n<pre><code>$ cd \/new\/path\n$ docker-compose up -d\n<\/code><\/pre>\n<hr>\n<h2 id=\"artifactory\">Artifactory<\/h2>"},{"title":"Swarm","link":"https:\/\/canuxcheng.com\/post\/swarm\/","pubDate":"Thu, 05 Apr 2018 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/swarm\/","description":"<h1 id=\"swarm\">Swarm<\/h1>\n<p>docker swarm \u662f docker\u5185\u7f6e\u7684\u5bb9\u5668\u7f16\u6392\u5de5\u5177\u3002<\/p>\n<p>\u4ecedocker1.12\u5f00\u59cbswarm\u5185\u7f6e\u4e8edocker engine.<\/p>\n<p>swarm mode\u5177\u6709\u5185\u7f6ekv\u5b58\u50a8\uff0c\u670d\u52a1\u53d1\u73b0\uff0c\u8d1f\u8f7d\u5747\u8861\uff0c\u8def\u7531\u7f51\u683c\uff0c\u52a8\u6001\u4f38\u7f29\uff0c\u6eda\u52a8\u66f4\u65b0\uff0c\u5b89\u5168\u4f20\u8f93\u7b49\u529f\u80fd\u3002<\/p>\n<p>swarm: \u8001\u7248\u672c\u7684swarm, \u9700\u8981kv store, \u53ef\u4ee5\u4f5c\u4e3a\u72ec\u7acb\u7684container\u8fd0\u884c, \u5df2\u5e9f\u5f03, \u5df2\u7ecf\u88abdocker swarm mode \u4ee3\u66ff.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/docker\/swarm\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/docker\/swarm<\/a><\/p>\n<p>swarmkit:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/docker\/swarmkit\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/docker\/swarmkit<\/a><\/p>\n<h1 id=\"swarm\u547d\u4ee4\">swarm\u547d\u4ee4<\/h1>\n<p>\u521b\u5efa\u96c6\u7fa4<\/p>\n<pre><code>docker swarm init\n--advertise-addr &lt;ip&gt; \u591a\u7f51\u5361\u60c5\u51b5\u4e0b\u6307\u5b9amanager\u7684ip\ndocker swarm join --token &lt;token&gt; &lt;host:port&gt;\n# \u67e5\u770btoken\ndocker swarm join-token manager \u83b7\u53d6\u6dfb\u52a0manager\u547d\u4ee4\ndocker swarm join-token worker \u83b7\u53d6\u6dfb\u52a0worker\u547d\u4ee4\ndocker swarm join-token -q worker\ndocker swarm leave -f\/--force\ndocker swarm update\n<\/code><\/pre>\n<p>\u7ba1\u7406\u8282\u70b9<\/p>\n<pre><code>docker node ls\ndocker node ls --format &quot;{{.Hostname}}&quot;\n\u200b\ndocker node rm\n\u200b\ndocker node inspect\n\u200b\n# \u67e5\u770bnode\u4e0a\u8fd0\u884c\u7684tasks\/container\ndocker node ps -f\/--filter NODE\n\u200b\n# \u6dfb\u52a0label, node.labels.role=api\ndocker node update --label-add role=api node1\n# \u5220\u9664label\ndocker node update --label-rm role node1\n\u200b\n# \u6d3b\u8dc3\u8282\u70b9\ndocker node update --availability active node1\n# \u6307\u5b9a\u8be5\u8282\u70b9\u6ee1\u8f7d,\u4e0d\u518d\u5206\u6d3e\u4efb\u52a1,\u5173\u95ed\u5df2\u6709\u4efb\u52a1\u5e76\u91cd\u65b0\u5206\u6d3e.\ndocker node update --availability drain node1\n# \u5df2\u6709\u4efb\u52a1\u7ee7\u7eed\u8fd0\u884c,\u4e0d\u5206\u914d\u65b0\u4efb\u52a1.\ndocker node update --availability pause node1\n# \u67e5\u770b\u6240\u6709node\u548clabel\ndocker node ls -q | xargs docker node inspect -f '{{ .ID }} [{{ .Description.Hostname }}]: {{ .Spec.Labels }}'\n<\/code><\/pre>\n<p>service<\/p>\n<pre><code># \u76f8\u5f53\u4e8edocker-compose.yml\u91cc\u9762\u7684service.\ndocker service ls # \u5217\u51fa\u6240\u6709service\n\u200b\ndocker service rm SERVICE\n\u200b\ndocker service inspect SERVICE\n\u200b\n# \u67e5\u770bservice\u7684log\ndocker service logs -f SERVICE\n\u200b\n# \u67e5\u770bservice\u7684\u72b6\u6001,\u5728\u54ea\u4e9bnode\u4e0a\u8fd0\u884c,\u8fd0\u884c\u72b6\u6001\u7b49\ndocker service ps SERVICE\n\u200b\ndocker service update\ndocker service update --image &lt;url:tag&gt; # \u6839\u636e\u955c\u50cf\u66f4\u65b0\u670d\u52a1\n\u200b\ndocker service scale\n\u200b\ndocker service rollback\n\u200b\ndocker service create\n--constraint node.id\/node.hostname\/node.role\/node.labels\/engine.labels\n--env\/-e\n--label\n--limit-cpu\n--limit-memory\n--replicas\n--restart-condition\n--user\/--group\n--mode global\/replicated\n--endpoint-mode vip\/dnsrr\n<\/code><\/pre>\n<p>stack<\/p>\n<pre><code># stack = n*service\n# service = n*task(container)\ndocker stack ls # \u5217\u51fa\u6240\u6709stack\n# \u67e5\u770bstack\u7684service\ndocker stack services &lt;stack&gt;\n# \u67e5\u770bstack\u7684task\/container\ndocker stack ps &lt;stack&gt;\ndocker stack rm STACK\n# \u6839\u636edocker-compose.yml\u90e8\u7f72\u5e94\u7528\ndocker stack deploy -c\/--compose-file &lt;docker-compose.yml&gt; STACK\ndocker stack deploy --bundle-file &lt;DAB&gt; STACK\n# \u9ed8\u8ba4\u6240\u6709node\u4ecedocker hub pull, \u5982\u679c\u662f\u79c1\u6709\u955c\u50cf\uff0c\u9700\u8981\u52a0\u53c2\u6570\n# \u9700\u8981\u5728manager\u4e0adocker login private-registry\ndocker stack deploy --with-registry-auth -c test.yml test\ndocker stack deploy --resolve-image (always|changed|never) ...\ndocker stack deploy --orchestrator (swarm|kubernetes|all) ...\n<\/code><\/pre>\n<hr>\n<h1 id=\"swarm-compose\">swarm compose<\/h1>\n<p>\u5176\u5b83\u5b57\u6bb5\u53c2\u8003Compose\uff0c \u8fd9\u91cc\u53ea\u5206\u6790deploy\u4e0b\u7684\u5b57\u6bb5.<\/p>\n<p>\u901a\u8fc7compose\u6587\u4ef6\u90e8\u7f72\u670d\u52a1.<\/p>\n<pre><code>deploy:\nendpoint_mode:\n\/\/ \u7ed9service\u6253\u6807\u7b7e(\u4e0d\u4f5c\u7528\u4e8econtainer)\nlabels:\ncom.examples.key: value\n\/\/ \u9ed8\u8ba4mode=replicated, replicas=1.\nmode: replicated\nmax_replicas_per_node:\nreplicas: 1\n\/\/ \u90e8\u7f72\u5230\u5339\u914d\u7684\u5168\u90e8node.\nmode: global\n\u200b\n# global\u548creplicated\u90fd\u53ef\u4ee5\u7528placement.\nplacement:\npreferences: \/\/ \u53ea\u652f\u6301spreed.\n- spreed: node.labels.datacenter\nconstraints:\n# \u591a\u4e2a\u7ea6\u675f\u662fand\u5173\u7cfb\n- node.id==...\n- node.hostname==...\n- node.role==...\n- node.role==manager\/worker\n- node.platform.os!=windows\n- node.platform.arch==x86\n- engine.labels.&lt;key&gt;==&lt;value&gt;\n# \u7528\u6237\u81ea\u5b9a\u4e49\u6807\u7b7e\n- node.labels.&lt;key&gt;==&lt;value&gt;\n\u200b\nresources:\nlimits:\ncpus: '0.5'\nmemory: 1G\nreservations:\ncpus: '0.25'\nmemory: 20M\n\u200b\nrestart_policy:\ncondition: any(default)\/on-failure\/none\ndelay: 0(default)\/5s\nmax_attempts: never give up(default)\/3\nwindow: decide immediately(default)\/10s\n\u200b\nupdate_config\/rollback_config:\nparallelism: 0 (default 0 means all)\ndelay: 10s (\u5bb9\u5668\u5347\u7ea7\u95f4\u9694\u65f6\u95f4)\nfailure_action: pause(default)\/continue\/rollback\nmonitor: 0s (\u66f4\u65b0\u5b8c\u6210\u540e\u786e\u8ba4\u6210\u529f\u7684\u65f6\u95f4)\nmax_failure_ratio: \u66f4\u65b0\u671f\u95f4\u5141\u8bb8\u7684\u5931\u8d25\u7387\norder: stop-first(default)\/start-first\n\/\/ \u9ed8\u8ba4endpoint_mode=vip, \u652f\u6301route mesh, \u81ea\u52a8\u8d1f\u8f7d\u5747\u8861\u548c\u670d\u52a1\u53d1\u73b0.\ndeploy:\nendpoint_mode: vip\nports:\n- target: 80\npublished: 8080\n\/\/ \u9ed8\u8ba4mode=ingress, \u4e5f\u53ef\u4ee5\u6539\u4e3ahost.\nmode: ingress\nprotocol: tcp\/udp\n- 8080:80\/tcp\n\/\/ dnsrr \u6a21\u5f0f\ndeploy:\nendpoint_mode: dnsrr\nupdate_config:\n\/\/ \u5982\u679cexpose\u7aef\u53e3\uff0c\u4e0d\u80fdstart-first, \u5426\u5219\u62a5\u9519no suitable node (host-mode port already in use on 1 node\norder: stop-first\n\/\/ \u8bbe\u7f6eiptables\u89c4\u5219\uff0c\u5916\u90e8\u8bbf\u95ee8080\u901a\u8fc7prerouting\u505adnat\u6307\u5b9a\u76ee\u7684ip\uff0c\u901a\u8fc7forward\u8f6c\u53d1\u7ed9container\u768480.\n\/\/ iptables-&gt;nat-&gt;prerouting:\n\/\/ DNAT tcp -- !docker_gwbridge * 0.0.0.0\/0 0.0.0.0\/0 tcp dpt:8080 to:172.18.0.16:80\n\/\/ iptables-&gt;filter-&gt;forward:\n\/\/ ACCEPT tcp -- enp5s0 * 0.0.0.0\/0 0.0.0.0\/0 multiport dports 80\nports:\n- target: 80\npublished: 8080\n\/\/ dnsrr\u53ea\u80fd\u7528port-&gt;mode=host.\nmode: host\nprotocol: tcp\/udp\n<\/code><\/pre>\n<hr>\n<h1 id=\"swarm-network\">swarm network<\/h1>\n<p>global\u6a21\u5f0fcontainer:<\/p>\n<pre><code>eth0: overlay(user define overlay)\neth1: ingress(swarm define ingress)\neth2: docker_gwbridge(swarm define bridge)\n<\/code><\/pre>\n<p>replicate\u6a21\u5f0fcontainer:<\/p>\n<pre><code>eth0: overlay(user define overlay)\neth1: docker_gwbridge(swarm define bridge)\n<\/code><\/pre>\n<p>overlay: \u901a\u8fc74789\/udp\u8de8\u4e3b\u673a\u8bbf\u95ee\u5176\u4ed6container, host\u4e0d\u80fd\u8bbf\u95eeoverlay\u7684ip\uff0c\u53ea\u6709container\u4e4b\u95f4\u901a\u8fc7container-servicename\u6216\u8005container-overlay\u7684ip\u76f8\u4e92\u8bbf\u95ee.<\/p>\n<p>overlay \u95ee\u9898: \u901a\u8fc7overlay\u8fde\u63a5\uff0c\u9ed8\u8ba415\u5206\u949ftimeout, \u6240\u4ee5\u6570\u636e\u5e93\u5efa\u8bae\u7528dnsrr\u6a21\u5f0f; \u5982\u679c\u7528vip\u6a21\u5f0f\uff0c\u9700\u8981\u4fee\u6539\u5185\u6838\u7f51\u7edc\u53c2\u6570:<\/p>\n<pre><code>$ sudo sysctl -w net.ipv4.tcp_keepalive_time=600 net.ipv4.tcp_keepalive_intvl=60 net.ipv4.tcp_keepalive_probes=3\n<\/code><\/pre>\n<p>vip\u6a21\u5f0f\u5c31\u662f\u8bbf\u95ee\u7684\u865a\u62dfip,replicated\u7684service\u5982\u679c\u6709\u591a\u4e2acontainer,\u901a\u8fc7servicename\u8bbf\u95ee\u7684\u5c31\u662f\u540c\u4e00\u4e2avip,\u901a\u8fc7vip\u89e3\u6790\u5230\u80cc\u540econtainer\u7684\u771f\u5b9eoverlay-ip(\u81ea\u52a8\u8d1f\u8f7d\u5747\u8861).<\/p>\n<p>dnsrr\u6a21\u5f0f\u5c31\u662f\u76f4\u63a5\u89e3\u6790container\u7684overlay-ip\u6765\u8bbf\u95ee,\u5982\u679c\u662freplicated\u7684service\u6709\u591a\u4e2acontainer,\u6bcf\u6b21\u8bbf\u95ee\u7684\u5c31\u662f\u4ecedns\u5217\u8868\u4e2d\u6839\u636e\u8d1f\u8f7d\u5747\u8861\u7b97\u6cd5\u62ff\u5230\u5176\u4e2d\u4e00\u4e2aoverlay-ip.<\/p>\n<p>ingress network: \u662f\u4e00\u4e2a\u7279\u6b8a\u7684 overlay \u7f51\u7edc\uff0c\u7528\u4e8e\u670d\u52a1\u8282\u70b9\u95f4\u7684\u8d1f\u8f7d\u5747\u8861\u3002\u5f53\u4efb\u4f55 Swarm \u8282\u70b9\u5728\u53d1\u5e03\u7684\u7aef\u53e3\u4e0a\u63a5\u6536\u5230\u8bf7\u6c42\u65f6\uff0c\u5b83\u5c06\u8be5\u8bf7\u6c42\u4ea4\u7ed9\u4e00\u4e2a\u540d\u4e3a IPVS \u7684\u6a21\u5757\u3002IPVS \u8ddf\u8e2a\u53c2\u4e0e\u8be5\u670d\u52a1\u7684\u6240\u6709IP\u5730\u5740\uff0c\u9009\u62e9\u5176\u4e2d\u7684\u4e00\u4e2a\uff0c\u5e76\u901a\u8fc7 ingress \u7f51\u7edc\u5c06\u8bf7\u6c42\u8def\u7531\u5230\u5b83\u3002<\/p>\n<p>docker_gwbridge: host\u548ccontainer\u4e4b\u95f4\u901a\u8fc7ip\u8bbf\u95ee, container\u80fd\u8bbf\u95eehost\u7684\u7269\u7406\u7f51\u5361\u7684ip\u548cdocker_gwbridge\u7684ip, host\u4e5f\u80fd\u8bbf\u95eecontainer\u7684docker_gwbridge\u7684ip, \u4f46\u662fcontainer\u4e4b\u95f4\u4e0d\u80fd\u8bbf\u95eebridge\u7684ip.<\/p>\n<p>\u4fee\u6539\u9ed8\u8ba4\u7684docker_gwbridge:<\/p>\n<pre><code>\/\/ \u5bf9\u4e8e\u5df2\u5b58\u5728\u7684\uff0c\u8981\u5148\u5220\u9664\n$ service docker stop\n$ sudo ip link set docker_gwbridge down\n$ sudo ip link del dev docker_gwbridge\n\/\/ \u521b\u5efaswarm\u4e4b\u524d\u521b\u5efa\u597d\u7f51\u7edc\n$ docker network create --subnet &quot;172.18.0.0\/16&quot;\u00a0 --ip-range \u201c172.18.1.0\/16\u201d \\\n--opt com.docker.network.bridge.name=docker_gwbridge \\\n--opt com.docker.network.bridge.enable_icc=false \\\n--opt com.docker.network.bridge.enable_ip_masquerade=true \\\ndocker_gwbridge\n\/\/ \u521b\u5efaswarm\n$ docker swarm init\n<\/code><\/pre>\n<p>endpoint_mode:<\/p>\n<ul>\n<li>vip: \u901a\u8fc7vip\u8fd9\u4e2a\u865a\u62dfip\u5bf9\u5916\u8bbf\u95ee\uff0c\u63d0\u4f9b\u8d1f\u8f7d\u5747\u8861\uff0c\u4e0d\u66b4\u9732\u5177\u4f53\u7684container\u7684ip.<\/li>\n<li>dnssr: DNS round-robin, \u4e3a\u6bcf\u4e2a\u670d\u52a1\u8bbe\u7f6edns,\u8fde\u63a5\u5230\u5176\u4e2d\u4e00\u4e2a\u5177\u4f53\u7684contaier\u7684ip.<\/li>\n<\/ul>\n<hr>\n<h1 id=\"swarm-scheduler\">swarm scheduler<\/h1>\n<p>filter\u8fc7\u6ee4\u5668\u53ef\u4ee5\u5b9e\u73b0\u7279\u5b9a\u7684\u5bb9\u5668\u8fd0\u884c\u5728\u7279\u5b9a\u7684node\u4e0a, swarm\u652f\u6301\uff13\u79cd\u7b56\u7565\u548c6\u4e2a\u8fc7\u6ee4\u5668.<\/p>\n<p>swarm strategy:<\/p>\n<ul>\n<li>spread\uff1a \u9ed8\u8ba4\u7b56\u7565,\u914d\u7f6e\u76f8\u540c\u7684\u60c5\u51b5\u4e0b\u9009\u62e9\u5bb9\u5668\u6570\u91cf\u6700\u5c11\u7684node<\/li>\n<li>binpack\uff1a \u5c3d\u53ef\u80fd\u5c06\u5bb9\u5668\u653e\u5230\u4e00\u53f0node\u4e0a\u8fd0\u884c\u3002<\/li>\n<li>random\uff1a \u76f4\u63a5\u968f\u673a\u5206\u914d<\/li>\n<\/ul>\n<p>swarm node filters:<\/p>\n<ul>\n<li>constraint<\/li>\n<li>health<\/li>\n<li>containerslots<\/li>\n<\/ul>\n<p>swarm container-configuration filters:<\/p>\n<ul>\n<li>affinity<\/li>\n<li>dependency<\/li>\n<li>port<\/li>\n<\/ul>"},{"title":"Swarm CNI","link":"https:\/\/canuxcheng.com\/post\/swarm_cni\/","pubDate":"Thu, 05 Apr 2018 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/swarm_cni\/","description":"<h1 id=\"cni\">CNI<\/h1>\n<p>CNI: Container Network Intarface<\/p>\n<h2 id=\"\u5355\u53f0host\u4e0a\u7684container\u901a\u4fe1\">\u5355\u53f0host\u4e0a\u7684container\u901a\u4fe1<\/h2>\n<ul>\n<li>none<\/li>\n<li>host<\/li>\n<li>bridge<\/li>\n<\/ul>\n<h2 id=\"\u591a\u53f0host\u4e4b\u95f4\u7684container\u901a\u4fe1\">\u591a\u53f0host\u4e4b\u95f4\u7684container\u901a\u4fe1<\/h2>\n<ul>\n<li>overlay<\/li>\n<li>macvlan<\/li>\n<\/ul>\n<h3 id=\"\u63d0\u4f9boverlaymacvlan\u7684\u7f51\u7edc\u670d\u52a1\">\u63d0\u4f9boverlay\/macvlan\u7684\u7f51\u7edc\u670d\u52a1<\/h3>\n<p>vxlan encapsulated:<\/p>\n<ul>\n<li>canal<\/li>\n<li>flannel<\/li>\n<li>weave<\/li>\n<\/ul>\n<p>bgp unencapsulated:<\/p>\n<ul>\n<li>calico<\/li>\n<li>romana<\/li>\n<li>cilium<\/li>\n<li>kube-router<\/li>\n<\/ul>\n<hr>\n<h1 id=\"docker\u7f51\u7edc\u7ba1\u7406\">Docker\u7f51\u7edc\u7ba1\u7406<\/h1>\n<p>\u67e5\u770b:<\/p>\n<pre><code>$ docker network ls # \u67e5\u770b\u6240\u6709\u7f51\u7edc\n<\/code><\/pre>\n<p>\u9ed8\u8ba4\u652f\u6301\u7684\u4e09\u79cd\u6a21\u5f0f:<\/p>\n<pre><code># \u9ed8\u8ba4\u542f\u52a8\u7684\u5bb9\u5668\u90fd\u662f\u6865\u63a5(docker0)\uff0c\u91cd\u542f\u540e\u5bb9\u5668\u7684ip\u5c31\u53d8\u4e86\u3002\ndocker run --network bridge ...\ndocker run --network host ... # \u5bb9\u5668\u548c\u4e3b\u673a\u4f7f\u7528\u76f8\u540c\u7684ip\ndocker run --network none ... # \u5bb9\u5668\u4e0d\u4f1a\u5206\u914d\u5c40\u57df\u7f51\u7684ip\n<\/code><\/pre>\n<p>\u521b\u5efa:<\/p>\n<pre><code>docker network create -d &lt;driver&gt; ... [name]\n-d\/--driver # \u9ed8\u8ba4\u662fbridge, \u53ef\u9009overlay\/macvlan\n--subnet # CIDR\u683c\u5f0f\n--gateway\n--ip-range\n<\/code><\/pre>\n<p>\u4f7f\u7528:<\/p>\n<pre><code>$ docker network connect [OPTIONS] NETWORK CONTAINER\n$ docker network disconnect [OPTIONS] NETWORK CONTAINER\n$ docker run --network [name] --name [container-name] [image:tag]\n# \u4f7f\u7528\u81ea\u5b9a\u4e49bridge\u7f51\u7edc\u5e76\u6307\u5b9aIP:\ndocker run --network [name] --ip [ip] ...\n<\/code><\/pre>\n<p>opt\u53ef\u7528\u7684\u53c2\u6570:<\/p>\n<pre><code>com.docker.network.bridge.name # bridge\u540d\u5b57\ncom.docker.network.bridge.enable_ip_masquerade # iptables:nat, \u5bb9\u5668\u8bbf\u95ee\u5916\u7f51.\ncom.docker.network.bridge.enable_icc # iptables:filter, \u540c\u4e00\u7f51\u6bb5\u5bb9\u5668\u76f8\u4e92\u8bbf\u95ee.\ncom.docker.network.bridge.host_binding_ipv4\ncom.docker.network.driver.mtu\n<\/code><\/pre>\n<hr>\n<h1 id=\"bridge\u7f51\u7edc\">bridge\u7f51\u7edc<\/h1>\n<p>bridge\u7f51\u7edc\u4e0d\u80fd\u8de8\u4e3b\u673a\u901a\u4fe1(\u5355\u7f51\u5361\u60c5\u51b5\u4e0b), node1\u4e0a\u7684container\u4e0d\u80fd\u901a\u8fc7container-hostname\/ip\u8bbf\u95eenode2\u4e0a\u7684container.<\/p>\n<p>\u4e3b\u8981\u7528\u4e8econtainer\u8bbf\u95eehost\u5e76\u901a\u8fc7host\u8bbf\u95ee\u5916\u90e8\u7f51\u7edc\uff0ccontainer\u80fd\u901a\u8fc7ip\u8bbf\u95eehost\u548c\u5c40\u57df\u7f51\u4e2d\u7684\u5176\u4ed6node,\u6216\u8005\u901a\u8fc7node\u8bbf\u95ee\u5916\u7f51\u3002<\/p>\n<p>host\u6216\u5c40\u57df\u7f51\u4e2d\u7684\u5176\u5b83\u673a\u5668\u80fd\u901a\u8fc7container-ip(bridge\u7f51\u7edc)\u8bbf\u95eecontainer.<\/p>\n<p>\u521b\u5efa:<\/p>\n<pre><code>$ docker network create -d bridge ... [name]\n$ docker network create --driver=bridge --gateway=192.168.1.1 --subnet=192.168.1.0\/24 --opt com.docker.network.bridge.name=br0 br0\n\/\/ \u5b9a\u5236docker_gwbridge\u7f51\u7edc\n$ docker network create --subnet 172.26.0.0\/16 --ip-range 172.26.0.0\/16 --gateway 172.26.0.1 \\\n--opt com.docker.network.bridge.name=docker_gwbridge \\\n--opt com.docker.network.bridge.enable_icc=true \\\n--opt com.docker.network.bridge.enable_ip_masquerade=true \\\ndocker_gwbridge\n<\/code><\/pre>\n<p>docker0:<\/p>\n<pre><code>\/\/ dockerd \u81ea\u52a8\u7684\u9ed8\u8ba4bridge\u7f51\u7edc\uff0c\u4e0d\u63a8\u8350\u7528\u4e8eproduction.\n1. \u5220\u9664docker0:\n\/\/ \u505c\u6b62\n$ ip link set dev docker0 down\n$ ifconfig docker0 down\n\/\/ \u5220\u9664\n$ ip link delete docker0\n$ brctl delbr docker0\n2. \u4fee\u6539\u9ed8\u8ba4\u7f51\u7edc:\n$ vim \/etc\/docker\/daemon.json\n{\n&quot;bip&quot;: &quot;192.168.1.5\/24&quot;,\n&quot;fixed-cidr&quot;: &quot;192.168.1.5\/25&quot;,\n&quot;fixed-cidr-v6&quot;: &quot;2001:db8::\/64&quot;,\n&quot;mtu&quot;: 1500,\n&quot;default-gateway&quot;: &quot;10.20.1.1&quot;,\n&quot;default-gateway-v6&quot;: &quot;2001:db8:abcd::89&quot;,\n&quot;dns&quot;: [&quot;10.20.1.2&quot;,&quot;10.20.1.3&quot;]\n}\n$ service docker restart\n<\/code><\/pre>\n<h1 id=\"overlay\u7f51\u7edc\">overlay\u7f51\u7edc<\/h1>\n<p>overlay\u7f51\u7edc\u53ef\u4ee5\u5b9e\u73b0\u5bb9\u5668\u4e4b\u95f4\u7684\u8de8\u4e3b\u673a\u901a\u4fe1.<\/p>\n<p>container\u901a\u8fc7overlay\u7f51\u7edc\u5b9e\u73b0\u901a\u4fe1.container\u80fd\u901a\u8fc7service-name\/container-ip\u8bbf\u95ee\u5176\u5b83container\u3002<\/p>\n<p>\u5c40\u57df\u7f51\u4e2d\u7684node \u65e2\u4e0d\u80fd\u901a\u8fc7container-servicename\u4e5f\u4e0d\u80fd\u901a\u8fc7container-ip(overlay\u7684ip)\u8bbf\u95eecontainer, \u4e5f\u5c31\u662f\u8bf4\u5916\u90e8\u670d\u52a1\u53ea\u80fd\u901a\u8fc7expose port\u6765\u8bbf\u95eecontainer.<\/p>\n<p>\u521b\u5efa:<\/p>\n<pre><code>$ docker network create -d overlay ... [name]\n$ docker network create --attachable --driver=overlay --gateway=172.27.0.1 --subnet=172.27.0.0\/24 --ip-range=172.27.0.0\/24 --opt com.docker.network.bridge.name=ol0 ol0\n<\/code><\/pre>\n<h1 id=\"macvlan\">macvlan<\/h1>\n<p>macvlan\u4e0d\u4ec5\u652f\u6301\u5728interface\u4e0a\u521b\u5efa\uff0c\u8fd8\u652f\u6301sub-interface(vlan).<\/p>\n<pre><code>ip link set eth1 promisc on |\nifconfig eth1 promisc\ndocker network create -d macvlan --subnet=192.168.100.0\/24 --gateway=192.168.100.1 -o parent=eth1 lan0\n<\/code><\/pre>\n<hr>"},{"title":"Swarm CSI","link":"https:\/\/canuxcheng.com\/post\/swarm_csi\/","pubDate":"Thu, 05 Apr 2018 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/swarm_csi\/","description":"<h1 id=\"csi\">CSI<\/h1>\n<p>CSI: Container Storage Interface<\/p>\n<p>CSI\u63d0\u4f9b\u5bb9\u5668\u7684\u6570\u636e\u6301\u4e45\u5316\u670d\u52a1.<\/p>\n<p>\u5bb9\u5668\u7ba1\u7406\u6570\u636e\u7684\u4e24\u79cd\u65b9\u5f0f\uff1a<\/p>\n<p>\u6570\u636e\u5377(Volumes)<\/p>\n<p>\u6302\u8f7d\u4e3b\u673a\u76ee\u5f55(bind mounts)<\/p>\n<p>\u4e34\u65f6\u6587\u4ef6\u7cfb\u7edf(tmpfs)<\/p>\n<h2 id=\"\u6570\u636e\u5b58\u50a8\u539f\u7406\">\u6570\u636e\u5b58\u50a8\u539f\u7406<\/h2>\n<p>\u5982\u679ccontainer\u4e0a\u76ee\u5f55\u4e0d\u5b58\u5728\uff0cdocker\u4f1a\u81ea\u52a8\u521b\u5efa<\/p>\n<p>\u5982\u679ccontainer\u76ee\u5f55\u5b58\u5728\u4e14\u6709\u5185\u5bb9\uff0c\u4f1a\u88abhost\u4e0a\u7684\u76ee\u5f55\u8986\u76d6\u6389\uff0c\u4f46\u4e0d\u4f1a\u88ab\u5220\u9664.<\/p>\n<h2 id=\"volumes\">Volumes<\/h2>\n<p>\u5982\u679chost\u4e0a\u76ee\u5f55\u4e0d\u5b58\u5728\uff0cdocker\u4f1a\u81ea\u52a8\u521b\u5efa<\/p>\n<p>volumes\u662f\u88ab\u8bbe\u8ba1\u7528\u6765\u6301\u4e45\u5316\u6570\u636e\u7684\uff0c\u5b83\u7684\u751f\u547d\u5468\u671f\u72ec\u7acb\u4e8e\u5bb9\u5668.\u6570\u636e\u5377\u901a\u8fc7docker volume\u547d\u4ee4\u7ba1\u7406\u7684\uff0c\u4f4d\u4e8e\/var\/lib\/docker\/volumes\/\u4e0b\u9762.<\/p>\n<p>Docker\u4e0d\u4f1a\u5728\u5bb9\u5668\u88ab\u5220\u9664\u540e\u81ea\u52a8\u5220\u9664 \u6570\u636e\u5377\uff0c\u5e76\u4e14\u4e5f\u4e0d\u5b58\u5728\u5783\u573e\u56de\u6536\u8fd9\u6837\u7684\u673a\u5236\u6765\u5904\u7406\u6ca1\u6709\u4efb\u4f55\u5bb9\u5668\u5f15\u7528\u7684 \u6570\u636e\u5377\u3002<\/p>\n<p>\u521b\u5efa:<\/p>\n<pre><code>$ docker volume create &lt;volume-name&gt;\n$ docker volume rm &lt;volume-name&gt;\n<\/code><\/pre>\n<p>\u4f7f\u7528\uff1a<\/p>\n<pre><code>$ docker run -v\/--volume myvolume:\/var\/lib\/app ...\n$ docker run --mount source=myvolume,target=\/var\/lib\/app ...\n<\/code><\/pre>\n<h2 id=\"bind-mount\">Bind mount<\/h2>\n<p>\u5982\u679chost\u4e0a\u76ee\u5f55\u4e0d\u5b58\u5728\u4f1a\u62a5\u9519\uff0c\u9700\u8981\u63d0\u524d\u521b\u5efa.<\/p>\n<p>bind mount\u5c31\u662f\u76f4\u63a5\u5c06host\u8def\u5f84\u6302\u5728\u5230docker\uff0e<\/p>\n<p>source\u548ctarget\u90fd\u662f\u6587\u4ef6\uff0c\u5373\u53ef\u6302\u8f7d\u5355\u4e2a\u6587\u4ef6.<\/p>\n<p>\u4f7f\u7528:<\/p>\n<pre><code>$ docker run -v\/--volume \/opt\/app:\/var\/lib\/app:ro ...\n$ docker run --mount type=bind,source=\/opt\/app,target=\/var\/lib\/app,readonly ...\n<\/code><\/pre>\n<h2 id=\"tmpfs\">tmpfs<\/h2>\n<p>tmpfs\u662f\u4e34\u65f6\u6587\u4ef6\u7cfb\u7edf\uff0c\u4e5f\u53eb\u5185\u5b58\u6587\u4ef6\u7cfb\u7edf\uff0c\u5c31\u662f\u5c06\u6570\u636e\u5b58\u5728\u5185\u5b58\u4e0a\u3002<\/p>\n<p>tmpfs\u53ea\u80fd\u7528\u4e8elinux, \u591a\u4e2a\u5bb9\u5668\u4e5f\u4e0d\u80fd\u5171\u4eab\uff0c\u5bb9\u5668\u505c\u6b62\u6570\u636e\u5c31\u9500\u6bc1\u3002<\/p>\n<p>\u4f7f\u7528&ndash;mount\u53ef\u4ee5\u6307\u5b9a\u53c2\u6570\uff0c\u4f7f\u7528&ndash;tmpfs\u4e0d\u80fd\u6307\u5b9a\u53c2\u6570\u3002<\/p>\n<p>\u4f7f\u7528:<\/p>\n<pre><code>$ docker run --mount type=tmpfs,destination=\/tmp\/app,tmpfs_size=10G tmpfs_mode=1777 ...\n$ docker run --tmpfs ...\n<\/code><\/pre>\n<hr>\n<h1 id=\"docker\u7ba1\u7406volume\">Docker\u7ba1\u7406volume<\/h1>\n<p>\u67e5\u770b:<\/p>\n<pre><code>docker volume ls # \u67e5\u770b\u6240\u6709\u5377\n<\/code><\/pre>\n<p>\u521b\u5efavolume:<\/p>\n<pre><code>docker volume create my-volume\n# mountpoint: \/var\/lib\/docker\/volumes\/my-volume\/_data.\ndocker run -v\/--volume my-volume:\/container\/path\n# src=https:\/\/canuxcheng.com\/var\/lib\/docker\/volumes\/my-volume\/_data, dest=\/container\/path\n<\/code><\/pre>\n<p>\u6307\u5b9a\u8def\u5f84\u4f5c\u4e3avolume\uff1a<\/p>\n<pre><code>docker run -v \/host\/path:\/container\/path ...\n# src=https:\/\/canuxcheng.com\/host\/path, dest=\/container\/path\n<\/code><\/pre>\n<p>\u9ed8\u8ba4\u968f\u673a\u8def\u5f84\uff0c\u6570\u636e\u4e0d\u80fd\u6301\u4e45\u5316\uff1a<\/p>\n<pre><code># src=https:\/\/canuxcheng.com\/var\/lib\/docker\/volumes\/... \/_data (on host)\ndocker run -v \/path ....\ndocker run --mount ...\n<\/code><\/pre>"},{"title":"Monitoring","link":"https:\/\/canuxcheng.com\/post\/storage_monitoring\/","pubDate":"Thu, 05 Apr 2018 21:47:54 +0000","guid":"https:\/\/canuxcheng.com\/post\/storage_monitoring\/","description":"<h1 id=\"monitoring\">Monitoring<\/h1>\n<h2 id=\"diskio\">diskio<\/h2>\n<p>IOPS: Input\/Output Per Second. \u6bcf\u79d2\u8f93\u5165\u8f93\u51fa\u91cf\uff0c\u4e5f\u53ebTPS.<\/p>\n<pre><code>SELECT non_negative_derivative(mean(reads),1s) as &quot;read&quot; FROM &quot;diskio&quot;\nSELECT non_negative_derivative(mean(writes),1s) as &quot;write&quot; FROM &quot;diskio&quot;\n<\/code><\/pre>\n<p>throughput:<\/p>\n<pre><code>SELECT non_negative_derivative(mean(read_bytes),1s) as &quot;read&quot; FROM &quot;diskio&quot;\nSELECT non_negative_derivative(mean(write_bytes),1s) as &quot;write&quot; FROM &quot;diskio&quot;\n<\/code><\/pre>\n<p>Utilization:<\/p>\n<pre><code>SELECT non_negative_derivative(last(&quot;io_time&quot;),1ms)\nFROM &quot;diskio&quot;\nWHERE &quot;name&quot; =~ \/^(v|s|)d(a|b|c|d)$\/\nGROUP BY &quot;host&quot;,&quot;name&quot;,time(_interval)\n<\/code><\/pre>\n<p>Queue length:<\/p>\n<pre><code>SELECT non_negative_derivative(last(&quot;weighted_io_time&quot;,1ms))\nFROM &quot;diskio&quot;\nWHERE &quot;name&quot; =~ \/^(v|s|)d(a|b|c|d)$\/\nGROUP BY &quot;host&quot;,&quot;name&quot;,time(_interval)\n<\/code><\/pre>"},{"title":"Storage","link":"https:\/\/canuxcheng.com\/post\/storage\/","pubDate":"Thu, 05 Apr 2018 21:47:54 +0000","guid":"https:\/\/canuxcheng.com\/post\/storage\/","description":"<h1 id=\"storage\">Storage<\/h1>\n<h1 id=\"raid\">RAID<\/h1>\n<p>RAID: redundant array of independent disks, \u72ec\u7acb\u78c1\u76d8\u5197\u4f59\u6570\u7ec4\uff0e<\/p>\n<h1 id=\"\u5b58\u50a8\u65b9\u5f0f\">\u5b58\u50a8\u65b9\u5f0f<\/h1>\n<p>DAS: direct attached storage, \u76f4\u8fde\u5f0f\u5b58\u50a8\uff0c\u901a\u8fc7SCSI\u6216FC\u8fde\u63a5\u670d\u52a1\u5668\uff0e<\/p>\n<p>NAS: network attached storage\uff0c\u7f51\u7edc\u63a5\u5165\u5b58\u50a8\uff0c\u901a\u8fc7IP(NFS\/CIFS\/..).<\/p>\n<p>SAN: storage area network, \u5b58\u50a8\u533a\u57df\u7f51\u7edc\uff0c\u6709IP\u6216FC\u4e24\u79cd\u65b9\u5f0f\uff0e<\/p>\n<h1 id=\"\u5b58\u50a8\u63a5\u53e3\">\u5b58\u50a8\u63a5\u53e3<\/h1>\n<p>SCSI<\/p>\n<p>iSCSI<\/p>\n<p>SAS<\/p>\n<p>SATA<\/p>\n<p>FC<\/p>\n<p>FCoE<\/p>\n<hr>"},{"title":"Websocket","link":"https:\/\/canuxcheng.com\/post\/websocket\/","pubDate":"Tue, 03 Apr 2018 14:46:19 +0000","guid":"https:\/\/canuxcheng.com\/post\/websocket\/","description":"<h1 id=\"websocket\">WebSocket<\/h1>\n<p>websocket\u7528\u4e8eserver\u548cbrowser\u4e4b\u95f4\u901a\u8baf\uff0e<\/p>\n<p>websocket\u91c7\u7528\u7279\u6b8a\u62a5\u5934\uff0c\u4f7f\u5f97\u6d4f\u89c8\u5668\u548c\u670d\u52a1\u5668\u53ea\u9700\u8981\u505a\u4e00\u4e2a\u63e1\u624b\u7684\u52a8\u4f5c\uff0e<\/p>\n<p>\u901a\u8baf\u6570\u636e\u4ee5\\x00\u5f00\u5934\uff0c\u4ee5\\xFF\u7ed3\u5c3e\uff0e<\/p>\n<p>url:<\/p>\n<pre><code>ws:\/\/\nwss:\/\/\n<\/code><\/pre>\n<p>\u4e00\u4e2a\u5ba2\u6237\u7aef\u53ea\u5efa\u7acb\u4e00\u4e2atcp\u8fde\u63a5<\/p>\n<p>\u670d\u52a1\u7aef\u53ef\u4ee5\u63a8\u9001\/push\u6570\u636e\u5230web\u5ba2\u6237\u7aef<\/p>\n<p>\u6709\u66f4\u52a0\u4eb2\u91cf\u7ea7\u7684\u5934\uff0c\u51cf\u5c11\u6570\u636e\u4f20\u9001\uff0e<\/p>"},{"title":"JS BOM","link":"https:\/\/canuxcheng.com\/post\/js_bom\/","pubDate":"Thu, 15 Mar 2018 09:36:32 +0000","guid":"https:\/\/canuxcheng.com\/post\/js_bom\/","description":"<h1 id=\"bom\">BOM<\/h1>\n<p>Browser Object Model<\/p>\n<p>\u4ecb\u7ecd\u6d4f\u89c8\u5668\u5bf9\u8c61\uff0c\u4e0d\u8fc7\u7f3a\u4e4f\u89c4\u8303.<\/p>\n<h1 id=\"window\">window<\/h1>\n<p>window\u5bf9\u8c61\u662f\u6700\u9876\u5c42\u5bf9\u8c61\uff0c\u67096\u5927\u5c5e\u6027,\u5c5e\u6027\u672c\u8eab\u4e5f\u662f\u5bf9\u8c61.<\/p>\n<p>window\u5bf9\u8c61\u7684document\u5c5e\u6027\u4e5f\u662f\u5bf9\u8c61\uff0cdocument\u5bf9\u8c61\u67095\u5927\u5c5e\u6027.<\/p>\n<p>\u5f15\u7528\u5f53\u524d\u7a97\u53e3\u65f6\uff0c\u53ef\u4ee5\u7701\u7565window\u5bf9\u8c61.<\/p>\n<p>eg:<\/p>\n<pre><code>window.document\ndocument\nwindow.alert()\nalert()\n<\/code><\/pre>\n<p>\u5bf9\u8c61\u96c6\u5408:<\/p>\n<pre><code>frames[]\n<\/code><\/pre>\n<p>attribution:<\/p>\n<pre><code>document # DOM\u7684Document\u5bf9\u8c61\nhistory # History\u5bf9\u8c61\nlocation # Location\u5bf9\u8c61\nNavigator # Navigator\u5bf9\u8c61\nScreen # Screen\u5bf9\u8c61\nwindow # \u7b49\u4ef7\u4e8eself\nclosed\ndefaultStatus\nstatus\ninnerheight\ninnerwidth\nouterheight\nouterwidth\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>alert() \/\/ \u5f39\u51fa\u8b66\u544a\u6846\nconfirm() \/\/ \u548calert\u5dee\u4e0d\u591a\uff0c\u5e26\u786e\u5b9a\u548c\u53d6\u6d88\u6309\u94ae\uff0c\u786e\u5b9a\u8fd4\u56detrue\nprompt() \/\/ \u8f93\u5165\u63d0\u793a\u6846,\u8fd4\u56de\u8f93\u5165\u5185\u5bb9\nfind() \/\/ \u67e5\u627e\n\/\/ \u5b50\u7a97\u53e3\u7684opener\u5c5e\u6027\u53cd\u8fc7\u6765\u5f15\u7528\u6253\u5f00\u5979\u7684\u90a3\u4e2a\u7a97\u53e3(\u7236\u7a97\u53e3)\nsubwin = open() \/\/ \u6253\u5f00\u4e00\u4e2a\u65b0\u7a97\u53e3, _parent\u5728\u5f53\u524d\u7a97\u53e3\u6253\u5f00, \u8fd4\u56de\u5b50\u7a97\u53e3\u7684window\u5bf9\u8c61.\nsubwin.opener \/\/ \u8868\u793awindow\nmoveTo()\nmoveBy()\nresizeTo()\nresizeBy()\nsetTimeout()\nclearTimeout()\nsetInterval()\nclearInterval()\nclose()\n<\/code><\/pre>\n<h1 id=\"location\">location<\/h1>\n<p>attribution:<\/p>\n<pre><code>hash\nhost\nhostname\nhref\npathname\nport\nprotocol\nsearch\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>assign()\nreload()\nreplace()\n<\/code><\/pre>\n<h1 id=\"history\">history<\/h1>\n<p>attribution:<\/p>\n<pre><code>lehgth\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>back()\nforward()\ngo()\n<\/code><\/pre>\n<h1 id=\"navigator\">navigator<\/h1>\n<p>\u5bf9\u8c61\u96c6\u5408:<\/p>\n<pre><code>plugins[] # Plugin\u5bf9\u8c61\u7684\u6570\u7ec4\nnavigator.plugins.length # \u63d2\u4ef6\u4e2a\u6570\nnavigator.plugins[i].name # \u7b2ci\u4e2a\u63d2\u4ef6\u540d\u5b57\nnavigator.plugins[i].filename # \u7b2ci\u4e2a\u63d2\u4ef6\u6587\u4ef6\u540d\n<\/code><\/pre>\n<p>attribution:<\/p>\n<pre><code>appName # \u6d4f\u89c8\u5668\u540d\u79f0\nappVersion # \u6d4f\u89c8\u5668\u7248\u672c\nuserAgent # user-agent \u5934\u90e8\u4fe1\u606f\nplatform # win32\/\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>javaEnabled()\ntaintEnabled()\n<\/code><\/pre>\n<h1 id=\"screen\">screen<\/h1>\n<p>attribution:<\/p>\n<pre><code>width\nheight\navailHeight\navailWidth\n<\/code><\/pre>"},{"title":"Brazil","link":"https:\/\/canuxcheng.com\/post\/travel_brazil\/","pubDate":"Thu, 08 Mar 2018 16:41:50 +0000","guid":"https:\/\/canuxcheng.com\/post\/travel_brazil\/","description":"<h1 id=\"\u5df4\u897f\u4e4b\u65c5\">\u5df4\u897f\u4e4b\u65c5<\/h1>\n<p>\u770b\u7167\u7247\uff1a<\/p>\n<h1 id=\"\u5e93\u91cc\u63d0\u5df4\">\u5e93\u91cc\u63d0\u5df4<\/h1>\n<p>\u5e93\u91cc\u63d0\u5df4\uff08Curitiba\uff09<\/p>"},{"title":"AlertManager","link":"https:\/\/canuxcheng.com\/post\/metrics_alertmanager\/","pubDate":"Thu, 18 Jan 2018 19:23:25 +0000","guid":"https:\/\/canuxcheng.com\/post\/metrics_alertmanager\/","description":"<h1 id=\"alert-manager\">alert-manager<\/h1>\n<p>\u5728Prometheus\u4e2d\u652f\u6301\u57fa\u4e8ePromQL\u521b\u5efa\u544a\u8b66\u89c4\u5219, prometheus\u901a\u8fc7push\u89e6\u53d1alertmanager.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/prometheus\/alertmanager\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/prometheus\/alertmanager<\/a><\/p>"},{"title":"Exporter","link":"https:\/\/canuxcheng.com\/post\/metrics_exporter\/","pubDate":"Thu, 18 Jan 2018 19:23:25 +0000","guid":"https:\/\/canuxcheng.com\/post\/metrics_exporter\/","description":"<h1 id=\"exporter\">exporter<\/h1>\n<p>\u5e7f\u4e49\u4e0a\u8bb2\u6240\u6709\u53ef\u4ee5\u5411Prometheus\u63d0\u4f9b\u76d1\u63a7\u6837\u672c\u6570\u636e\u7684\u7a0b\u5e8f\u90fd\u53ef\u4ee5\u88ab\u79f0\u4e3a\u4e00\u4e2aExporter\u3002\u800cExporter\u7684\u4e00\u4e2a\u5b9e\u4f8b\u79f0\u4e3atarget\uff0c\u5982\u4e0b\u6240\u793a\uff0cPrometheus\u901a\u8fc7\u8f6e\u8be2\u7684\u65b9\u5f0f\u5b9a\u671f\u4ece\u8fd9\u4e9btarget\u4e2d\u83b7\u53d6\u6837\u672c\u6570\u636e:<\/p>\n<p>prometheus\u901a\u8fc7pull\u4eceexporter\u62c9\u53d6\u6570\u636e.<\/p>\n<p>\u76f4\u63a5\u91c7\u96c6:cAdvisor, kubernetes, etcd, gokit\u7b49\u76f4\u63a5\u5185\u7f6e\u4e86\u7528\u4e8e\u5411prometheus\u66b4\u9732\u76d1\u63a7\u6570\u636e\u7684\u7aef\u70b9.<\/p>\n<p>\u95f4\u63a5\u91c7\u96c6: \u901a\u8fc7promethesu\u7684client api\u7f16\u5199exporter\uff0c\u4f8b\u5982mysql-exporter, consul-exporter.<\/p>\n<hr>\n<h1 id=\"host\">host<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/prometheus\/node_exporter\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/prometheus\/node_exporter<\/a><\/p>\n<hr>\n<h1 id=\"k8s\">k8s<\/h1>\n<p>k8s metrics api\u5305\u62ec resource metrics api \u548c customer metrics api.<\/p>\n<p>cadvisor, metrics-server, kube-state-metrics \u7b49\u5b9e\u73b0\u4e86 \u6838\u5fc3api.<\/p>\n<p>\u4e00\u4e9badapter\u5b9e\u73b0\u4e86\u81ea\u5b9a\u4e49api.<\/p>\n<p>k8s-prometheus-adapter\u5b9e\u73b0\u4e86metrics-server\u7684\u6838\u5fc3api\uff0c\u540c\u65f6\u5b9e\u73b0\u4e86\u81ea\u5b9a\u4e49api.<\/p>\n<h2 id=\"metrics-server\">metrics-server\u00a0<\/h2>\n<p>\u63d0\u4f9b\u4e86\u6574\u4e2a\u96c6\u7fa4\u7684\u8d44\u6e90\u76d1\u63a7\u6570\u636e<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes-sigs\/metrics-server\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes-sigs\/metrics-server<\/a><\/p>\n<h2 id=\"cadvisor\">cAdvisor<\/h2>\n<p>\u8d1f\u8d23\u5355\u8282\u70b9\u5185\u90e8\u7684\u5bb9\u5668\u548c\u8282\u70b9\u8d44\u6e90\u4f7f\u7528\u7edf\u8ba1\uff0c\u4f1a\u81ea\u52a8\u6536\u96c6\u672c\u673a\u5bb9\u5668 CPU\u3001\u5185\u5b58\u3001\u7f51\u7edc\u548c\u6587\u4ef6\u7cfb\u7edf\u7684\u8d44\u6e90\u5360\u7528\u60c5\u51b5<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/google\/cadvisor\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/google\/cadvisor<\/a><\/p>\n<h2 id=\"kube-state-metrics\">kube-state-metrics\u00a0<\/h2>\n<p>\u63d0\u4f9b\u4e86 Kubernetes \u8d44\u6e90\u5bf9\u8c61\uff08\u5982 DaemonSet\u3001Deployments \u7b49\uff09\u7684\u5ea6\u91cf\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes\/kube-state-metrics\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes\/kube-state-metrics<\/a><\/p>\n<h2 id=\"adapter\">adapter<\/h2>\n<p>\u540c\u65f6\u652f\u6301\u6838\u5fc3api\u548c\u81ea\u5b9a\u4e49api.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/DirectXMan12\/k8s-prometheus-adapter\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/DirectXMan12\/k8s-prometheus-adapter<\/a><\/p>\n<hr>\n<h1 id=\"blackbox\">blackbox<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/prometheus\/blackbox_exporter\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/prometheus\/blackbox_exporter<\/a><\/p>\n<h1 id=\"wmi\">wmi<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/martinlindhe\/wmi_exporter\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/martinlindhe\/wmi_exporter<\/a><\/p>\n<h1 id=\"snmp\">snmp<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/prometheus\/snmp_exporter\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/prometheus\/snmp_exporter<\/a><\/p>\n<h1 id=\"mysql\">mysql<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/prometheus\/mysqld_exporter\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/prometheus\/mysqld_exporter<\/a><\/p>\n<h1 id=\"rabbitmq\">rabbitmq<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/deadtrickster\/prometheus_rabbitmq_exporter\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/deadtrickster\/prometheus_rabbitmq_exporter<\/a><\/p>\n<h1 id=\"mongo\">mongo<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/percona\/mongodb_exporter\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/percona\/mongodb_exporter<\/a><\/p>\n<h1 id=\"redis\">redis<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/oliver006\/redis_exporter\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/oliver006\/redis_exporter<\/a><\/p>\n<h1 id=\"haproxy\">haproxy<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/prometheus\/haproxy_exporter\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/prometheus\/haproxy_exporter<\/a><\/p>\n<h1 id=\"consul\">consul<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/prometheus\/consul_exporter\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/prometheus\/consul_exporter<\/a><\/p>\n<hr>\n<h1 id=\"pushgateway\">pushgateway<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/prometheus\/pushgateway\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/prometheus\/pushgateway<\/a><\/p>\n<p>\u7531\u4e8ePrometheus\u6570\u636e\u91c7\u96c6\u57fa\u4e8ePull\u6a21\u578b\u8fdb\u884c\u8bbe\u8ba1\uff0c\u56e0\u6b64\u5728\u7f51\u7edc\u73af\u5883\u7684\u914d\u7f6e\u4e0a\u5fc5\u987b\u8981\u8ba9Prometheus Server\u80fd\u591f\u76f4\u63a5\u4e0eExporter\u8fdb\u884c\u901a\u4fe1\u3002 \u5f53\u8fd9\u79cd\u7f51\u7edc\u9700\u6c42\u65e0\u6cd5\u76f4\u63a5\u6ee1\u8db3\u65f6\uff0c\u5c31\u53ef\u4ee5\u5229\u7528PushGateway\u6765\u8fdb\u884c\u4e2d\u8f6c\u3002\u53ef\u4ee5\u901a\u8fc7PushGateway\u5c06\u5185\u90e8\u7f51\u7edc\u7684\u76d1\u63a7\u6570\u636e\u4e3b\u52a8Push\u5230Gateway\u5f53\u4e2d\u3002\u800cPrometheus Server\u5219\u53ef\u4ee5\u91c7\u7528\u540c\u6837Pull\u7684\u65b9\u5f0f\u4ecePushGateway\u4e2d\u83b7\u53d6\u5230\u76d1\u63a7\u6570\u636e.<\/p>"},{"title":"Influxdb","link":"https:\/\/canuxcheng.com\/post\/metrics_influxdb\/","pubDate":"Thu, 18 Jan 2018 19:23:25 +0000","guid":"https:\/\/canuxcheng.com\/post\/metrics_influxdb\/","description":"<h1 id=\"influxdb\">Influxdb<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/influxdata\/influxdb\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/influxdata\/influxdb<\/a><\/p>\n<p>Scalable datastore for metrics, events, and real-time analytics.<\/p>\n<p>\u652f\u6301\u4eceopentsdb, graphite, collectd\u7b49\u83b7\u53d6\u6570\u636e<\/p>\n<p>\u9ed8\u8ba4\u6570\u636e\u5e93_internal \u7528\u4e8e\u5b58\u50a8\u5185\u90e8\u8fd0\u884c\u6570\u636e<\/p>\n<p>\u5b89\u88c5\u914d\u7f6e\u53c2\u8003\u5b98\u65b9\u6587\u6863<\/p>\n<p>log<\/p>\n<pre><code>$ sudo journalctl -u influxdb.service\n<\/code><\/pre>\n<p>config:<\/p>\n<pre><code># \u5f00\u901akapacitor\u7684subscription\u529f\u80fd\n[[subscriber]]\nenable = true\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u6570\u636e\u7ed3\u6784\">\u6570\u636e\u7ed3\u6784<\/h1>\n<p>influxdb\u6bcf\u6761\u8bb0\u5f55\u662f\u4e00\u4e2apoint.<\/p>\n<p>points\u5305\u62ec\u4e0b\u9762\u90e8\u5206\uff1a<\/p>\n<pre><code>measurement: a measurement, like cpu_load, \u76f8\u5f53\u4e8e\u8868\u540d\ntags: zero or more tag, key=value, eg: host=ip\nfields: zero or more field, key=value, eg: value=0.18\ntime: a timestamp\n&lt;measurement&gt;[,&lt;tag-key&gt;=&lt;tag-value&gt;...] &lt;field-key&gt;=&lt;field-value&gt;[,&lt;field2-key&gt;=&lt;field2-value&gt;...] [unix-nano-timestamp]\n<\/code><\/pre>\n<p>series: \u5728\u4e00\u4e2adatabase\u4e2d,\u76f8\u540c\u7684retention policy, measurement, tag set\u7684\u6570\u636e\u96c6\uff0c\u53eb\u4e00\u4e2a\u5e8f\u5217\uff0e<\/p>\n<p>RP: retention policy, autogen\u662f\u9ed8\u8ba4\u7684\u5b58\u50a8\u7b56\u7565, \u7528\u4e8e\u8bbe\u7f6e\u6570\u636e\u4fdd\u7559\u65f6\u95f4.<\/p>\n<p>CQ: continuous query, \u8fde\u7eed\u67e5\u8be2\uff0c\u81ea\u52a8\u5b9a\u65f6\u542f\u52a8\u4e00\u7ec4\u8bed\u53e5\uff0c\u5c06\u7ed3\u679c\u653e\u5728\u6307\u5b9a\u6570\u636e\u8868\u4e2d\uff0e<\/p>\n<p>IFQL: influx query language.<\/p>\n<hr>\n<h1 id=\"cli\">CLI<\/h1>\n<pre><code>$ influx --help\n$ influx -username &lt;username&gt; -p &lt;password&gt; -h &lt;hostname&gt;\n$ influx -precision rfc3339 # \u663e\u793a\u53ef\u8bfb\u7684\u65f6\u95f4\u6233\n$ influx -database 'test' -host '127.0.0.1'\n-execute 'select * from &quot;test&quot;.&quot;test&quot;.&quot;test&quot; where time &gt; now() - 30d'\n-format 'csv' &gt; test.csv\n<\/code><\/pre>\n<p>database<\/p>\n<pre><code>$ CREATE DATABASE test\n$ DROP DATABASE test\n$ SHOW DATABASES\n$ USE test\n<\/code><\/pre>\n<p>measurement(table)<\/p>\n<pre><code>$ DROP MEASUREMENT &lt;measurement&gt;\n$ SHOW MEASUREMENTS\n$ SHOW MEASUREMENTS WHERE &lt;tagkey&gt;=&lt;tagvalue&gt;\n<\/code><\/pre>\n<p>tags<\/p>\n<pre><code>$ SHOW TAG KEYS\n$ SHOW TAG KEYS FROM &lt;measurement&gt;\n$ SHOW TAG VALUES FROM &lt;measurement&gt; WITH KEY=&lt;tagkey&gt;\n<\/code><\/pre>\n<p>fileds<\/p>\n<pre><code>$ SHOW FIELD KEYS\n$ SHOW FIELD KEYS FROM &lt;measurement&gt;\n<\/code><\/pre>\n<p>subscription<\/p>\n<pre><code>$ SHOW SUBSCRIPTIONS\n$ CREATE SUBSCIPTION &lt;subs_name&gt; ON &lt;db&gt;.&lt;rp&gt; DESTINATIONS (&quot;ANY&quot;|&quot;ALL&quot;) host{&quot;,&quot;, host}\n$ DROP SUBSCRIPTION &lt;subs_name&gt; ON &lt;db&gt;.&lt;rp&gt;\n<\/code><\/pre>\n<p>series<\/p>\n<pre><code>$ SHOW SERIES\n$ DROP SERIES FROM &lt;measurement&gt; WHERE &lt;tagkey&gt;='&lt;tagvalue&gt;'\n$ DROP SERIES WHERE &lt;tagkey&gt;='&lt;tagvalue&gt;' # \u4ece\u6240\u6709measurement\u5220\u9664\u6307\u5b9a\u8282\u70b9\u7684\u6240\u6709\u6570\u636e\n<\/code><\/pre>\n<p>shared<\/p>\n<pre><code>$ drop shard &lt;shard_id&gt;\n<\/code><\/pre>\n<hr>\n<h1 id=\"http-api\">HTTP API<\/h1>\n<pre><code>port = 8086\n<\/code><\/pre>\n<h2 id=\"write\">write<\/h2>\n<p>create:<\/p>\n<pre><code>curl -i -XPOST http:\/\/localhost:8086\/query --data-urlencode &quot;q=CREATE DATABASE mydb&quot;\npost \/query\ndata = {\n&quot;q&quot;: &quot;create database &lt;database&gt;&quot;\n}\n<\/code><\/pre>\n<h2 id=\"query\">query<\/h2>\n<p>show:<\/p>\n<pre><code>curl -G 'http:\/\/localhost:8086\/query' --data-urlencode &quot;q=show databases&quot;\nget \/query\nparams = {\n&quot;pretty&quot; : True,\n&quot;q&quot;: &quot;show databases&quot;\n}\n<\/code><\/pre>\n<hr>\n<h1 id=\"influxql\">influxQL<\/h1>\n<p>influxql\u8bed\u53e5\u6309\u4e0b\u5217\u5173\u952e\u5b57\u987a\u5e8f\u6392\u5217<\/p>\n<p>tag_key, field_key, measurement\u90fd\u9700\u8981\u7528\u53cc\u5f15\u53f7.<\/p>\n<p>The SELECT clause specifies an InfluxQL function.<\/p>\n<pre><code>select &quot;&lt;field_key\/tag_key&gt;&quot; from &quot;&lt;measurement&gt;&quot;\nselect &quot;&lt;field_key\/tag_key&gt;&quot; as &quot;alias&quot; from &quot;&lt;measurement&gt;&quot;\n<\/code><\/pre>\n<p>The INTO clause writes query results to a user-specified measurement.<\/p>\n<pre><code>select &lt;&gt; INTO &quot;&lt;measurement&gt;&quot; from &lt;&gt;\n<\/code><\/pre>\n<p>The FROM clause specifies a single measurement.<\/p>\n<pre><code>select &lt;&gt; from &quot;&lt;measurement&gt;&quot;\n<\/code><\/pre>\n<p>The WHERE clause specifies the time range for the query.<\/p>\n<pre><code>select &lt;&gt; from &lt;&gt; where &lt;condition1&gt; OR\/AND &lt;condition2&gt;\n# string\u7c7b\u578b\u7684 value\u5fc5\u987b\u7528\u5355\u5f15\u53f7\uff0e\nselect &lt;&gt; from &lt;&gt; where &quot;&lt;tag_key\/field_key&gt;&quot; &lt;operation&gt; '&lt;tag_value\/field_value&gt;'\nnow() : time &gt; now(() - 10m\n= != &lt; &gt;\nRE:\n=~ !~\n=~ : \/.*ERROR.*|.*CRITICAL.*\/ \/ERROR|CRITICAL\/\n<\/code><\/pre>\n<p>The GROUP BY clause groups results by all tags (*) and into 12-minute intervals.<\/p>\n<pre><code>select &lt;&gt; from &lt;&gt; where &lt;&gt; group by &quot;&lt;tag_key&gt;&quot;\nfill()\ntime()\/time(1ns\/u\/ms\/s\/m\/h\/d\/w)\n<\/code><\/pre>\n<p>The ORDER BY time DESC clause returns results in descending timestamp order.<\/p>\n<pre><code>select &lt;&gt; from &lt;&gt; where &lt;&gt; group by &lt;&gt; order by &lt;time\/field_key&gt;\nselect &lt;&gt; from &lt;&gt; where &lt;&gt; group by &lt;&gt; order by &lt;time\/field_key&gt; desc\n<\/code><\/pre>\n<p>The LIMIT 2 clause limits the number of points returned to two.<\/p>\n<pre><code>select &lt;&gt; from &lt;&gt; where &lt;&gt; group by &lt;&gt; order by &lt;&gt; limit &lt;number&gt;\nselect &lt;&gt; from &lt;&gt; where &lt;&gt; group by &lt;&gt; order by &lt;&gt; desc limit &lt;number&gt;\n<\/code><\/pre>\n<p>The OFFSET 2 clause excludes the first two averages from the query results.<\/p>\n<pre><code>select &lt;&gt; from &lt;&gt; where &lt;&gt; group by &lt;&gt; order by &lt;&gt; limit &lt;number&gt; offset &lt;&gt;\nselect &lt;&gt; from &lt;&gt; where &lt;&gt; group by &lt;&gt; order by &lt;&gt; desc limit &lt;number&gt; offset &lt;&gt;\n<\/code><\/pre>\n<p>The SLIMIT 1 clause limits the number of series returned to one.<\/p>\n<pre><code>select &lt;&gt; from &lt;&gt; where &lt;&gt; group by &lt;&gt; order by &lt;&gt; limit &lt;&gt; offset &lt;&gt; slimit &lt;&gt;\nselect &lt;&gt; from &lt;&gt; where &lt;&gt; group by &lt;&gt; order by &lt;&gt; desc limit &lt;&gt; offset &lt;&gt; slimit &lt;&gt;\n<\/code><\/pre>\n<p>The SOFFSET 1 clause paginates the series returned.<\/p>\n<pre><code>select &lt;&gt; from &lt;&gt; where &lt;&gt; group by &lt;&gt; order by &lt;&gt; limit &lt;&gt; offset &lt;&gt; slimit &lt;&gt; soffzet &lt;&gt;\nselect &lt;&gt; from &lt;&gt; where &lt;&gt; group by &lt;&gt; order by &lt;&gt; desc limit &lt;&gt; offset &lt;&gt; slimit &lt;&gt; soffset&lt;&gt;\n<\/code><\/pre>\n<p>The tz() clause returns the UTC offset for the specified timezone.<\/p>\n<pre><code>select &lt;&gt; from &lt;&gt; where &lt;&gt; group by &lt;&gt; order by &lt;&gt; limit &lt;&gt; offset &lt;&gt; slimit &lt;&gt; soffzet &lt;&gt; tz(&lt;time_zone&gt;)\nselect &lt;&gt; from &lt;&gt; where &lt;&gt; group by &lt;&gt; order by &lt;&gt; desc limit &lt;&gt; offset &lt;&gt; slimit &lt;&gt; soffset&lt;&gt; tz(&lt;time_zone&gt;)\n<\/code><\/pre>\n<hr>\n<h1 id=\"flux\">flux<\/h1>\n<p>influxql\u7684\u5347\u7ea7\u7248\uff0c\u652f\u6301\u591a\u8868\u67e5\u8be2.<\/p>\n<hr>\n<h1 id=\"function\">function<\/h1>\n<h2 id=\"aggregations\">aggregations<\/h2>\n<pre><code>count(&lt;fieldkey&gt;) # \u7edf\u8ba1fieldvalues\u884c\u6570\ndistinct(&lt;fieldkey&gt;) # \u8fd4\u56defieldvalues\u4e0d\u91cd\u590d\u7684\u503c\u7684\u5217\u8868\nintegral(&lt;fieldkey&gt;) # \u79ef\u5206\nmean(&lt;fieldkey&gt;) # \u8fd4\u56defieldvalues\u7684\u7b97\u6570\u5e73\u5747\u503c\nmedian(&lt;fieldkey&gt;) # \u8fd4\u56defieldvalues\u7684\u6392\u5e8f\u540e\u7684\u4e2d\u95f4\u503c\nmode(&lt;fieldkey&gt;) # \u8fd4\u56defieldvalues\u51fa\u73b0\u9891\u7387\u6700\u9ad8\u7684\u503c\nspread(&lt;fieldkey&gt;) # \u8fd4\u56defieldvalues\u6700\u503c\u4e4b\u95f4\u7684\u5dee\u5f02\nstddev(&lt;fiekdkey&gt;) # \u8fd4\u56defieldvalues\u7684\u6807\u51c6\u504f\u5dee\nsum(&lt;fieldkey&gt;) # \u8fd4\u56defieldvalues\u7684\u548c\n<\/code><\/pre>\n<h2 id=\"selectors\">selectors<\/h2>\n<pre><code>bottom(&lt;fieldkey&gt;, N) # \u8fd4\u56de\u6700\u5c0f\u7684N\u4e2afieldvalues\nfirst(&lt;fieldkey&gt;) # \u8fd4\u56detimestamp\u6700\u5c0f\u7684fieldvalue\nlast(&lt;fieldkey&gt;) # \u8fd4\u56detimestamp\u6700\u5927\u7684fieldvalue\nmax(&lt;fieldkey&gt;) # \u8fd4\u56de\u6700\u5927\u7684fieldvalue\nmin(&lt;fieldkey&gt;) # \u8fd4\u56de\u6700\u5c0f\u7684fieldvalue\npercentile(&lt;fieldkey&gt;, N) # \u767e\u5206\u6570\nsample(&lt;fieldkey&gt;, N) # \u8fd4\u56deN\u4e2afieldvalue\u7684\u968f\u5373\u6837\u672c\ntop(&lt;fieldkey&gt;, N) # \u8fd4\u56de\u6700\u5927\u7684N\u4e2afieldvalue\n<\/code><\/pre>\n<h2 id=\"transformations\">transformations<\/h2>\n<p>transformations\u51fd\u6570\u7684field_key\u53ef\u4ee5\u662faggregations\u548cselectors\u51fd\u6570\u7684\u8fd4\u56de\u503c<\/p>\n<pre><code>cumulative_sum(&lt;field_key&gt;)\nderivative(&lt;field_key&gt;, [&lt;unit&gt;]) # \u6c42\u5355\u4f4d\u65f6\u95f4\u7684\u53d8\u5316\u7387, (cur-last)\/(interval\/unit)\ndifference(&lt;field_key&gt;) # \u8fd4\u56de\u8fde\u7eed\u65f6\u95f4\u503c\u4e4b\u95f4\u7684\u5dee\u5f02 -&gt; \u503c\u7684\u5dee\u5f02\nelapsed(&lt;field_key&gt;) # \u8fd4\u56de\u8fde\u7eed\u65f6\u95f4\u95f4\u9694\u7684\u5dee\u5f02 -&gt; \u65f6\u95f4\u95f4\u9694\u5dee\u5f02\nmoving_average()\nnon_negative_derivative()\nnon_negative_difference()\n<\/code><\/pre>\n<h2 id=\"predictors\">predictors<\/h2>\n<pre><code>holt_winters(function(&lt;field_key&gt;), N, S)\n<\/code><\/pre>\n<hr>\n<h1 id=\"rp\">RP<\/h1>\n<p>\u6570\u636e\u4fdd\u5b58\u7b56\u7565.<\/p>\n<p>autogen\u662f\u9ed8\u8ba4RP\uff0cduration=infinite<\/p>\n<p>duration: \u5b58\u50a8\u7684\u6570\u636e\u65f6\u95f4\u95f4\u9694<\/p>\n<p>replication: \u5b58\u50a8\u7684\u6570\u636e\u526f\u672c\u6570\u91cf<\/p>\n<pre><code>show retention policies on &quot;&lt;database&gt;&quot;\ncreate retention policy &quot;&lt;rp_name&gt;&quot; on &quot;&lt;database&gt;&quot; duration 30d replication 1 default\ndrop retention policy &quot;&lt;rp_name&gt;&quot; on &quot;&lt;database&gt;&quot;\n<\/code><\/pre>\n<hr>\n<h1 id=\"cq\">CQ<\/h1>\n<p>\u5bf9\u8d85\u8fc7\u4fdd\u5b58\u7b56\u7565\u6307\u5b9a\u65f6\u95f4\u7684\u6570\u636e\uff0c\u53ef\u4ee5\u505a\u7edf\u8ba1\u91c7\u6837.(\u7c7b\u4f3c\u4e8estore procedure).<\/p>\n<p>CQ\u4e0d\u80fd\u66f4\u65b0\uff0c\u53ea\u80fd\u5220\u9664\u91cd\u5efa\uff0e<\/p>\n<pre><code>show continuous queries\ncreate continuous query &lt;CQ_name&gt; on &lt;database&gt;\nbegin\nSELECT &lt;function[s]&gt; INTO &lt;destination_measurement&gt; FROM &lt;measurement&gt; [WHERE &lt;stuff&gt;] GROUP BY time(&lt;interval&gt;)[,&lt;tag_key[s]&gt;]\nend\nDROP CONTINUOUS QUERY &lt;cq_name&gt; ON &lt;database_name&gt;\n<\/code><\/pre>\n<hr>\n<h1 id=\"best-practice\">Best Practice<\/h1>\n<pre><code>select 1-(mean(&quot;part&quot;) \/ mean(&quot;all&quot;)) as &quot;rate&quot;\nfrom (\nselect sum(&quot;value&quot;) as &quot;smart&quot; from &quot;jobs_type&quot; where &quot;type&quot;='smart' and $timeFilter\n),(\nselect sum(&quot;value&quot;) as &quot;all&quot; from &quot;jobs_type&quot; where &quot;type&quot;='reversinglab' and $timeFilter\n)\ngroup by time($__interval) fill(none)\n<\/code><\/pre>"},{"title":"Kapacitor","link":"https:\/\/canuxcheng.com\/post\/metrics_kapacitor\/","pubDate":"Thu, 18 Jan 2018 19:23:25 +0000","guid":"https:\/\/canuxcheng.com\/post\/metrics_kapacitor\/","description":"<h1 id=\"kapacitor\">Kapacitor<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/influxdata\/Kapacitor\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/influxdata\/Kapacitor<\/a><\/p>\n<p>Open source framework for processing, monitoring, and alerting on time series data<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7chrongraf\u521b\u5efatickscript\/task, \u7136\u540e\u901a\u8fc7api\/cli\u5bfc\u5165\u5230kapacitor.<\/p>\n<p>\u914d\u7f6e:<\/p>\n<pre><code>hostname = &quot;kapcitor-service&quot;\n# \u5982\u679c\u4eceinfluxdb\u8bfb\u53d6\u6570\u636e\u9700\u8981\u914d\u7f6e\u8be5\u9009\u9879\uff0e\n[[influxdb]]\nenabled = true\n# \u5982\u679c\u4ece\u8be5\u8def\u5f84\u52a0\u8f7dtickscript\n[[load]]\nenabled = true\ndir=&quot;\/etc\/kapacitor\/load&quot;\n# tasks, \u653e\u5230\/etc\/kapacitor\/load\/tasks\/*.tick,\u91cd\u542fkapacitor\u4f1a\u81ea\u52a8\u52a0\u8f7dtask,\u5e76\u9ed8\u8ba4enable.\n## \u8981\u6c42\uff0cID\u548ctick\u6587\u4ef6\u540c\u540d\uff0ctickscript\u5f00\u5934\u9700\u8981\u6307\u5b9adbrp, tickscript\u91cc\u9762\u9700\u8981\u6307\u5b9abatch\/stream.\n# templates...\n# handlers...\n<\/code><\/pre>\n<hr>\n<h1 id=\"cli\">CLI<\/h1>\n<pre><code>$ kapacitor help\n# \u521b\u5efatemplate(\u4e5f\u5c31\u662f\u53d8\u91cf\u53ef\u4ee5\u5355\u72ec\u8d4b\u503c\u7684tickscript)\n$ kapacitor define-template &lt;name&gt; -tick \/path\/template.tick\n$ kapacitor show-template &lt;name&gt;\n# \u521b\u5efa\/\u66f4\u65b0 task, \u521b\u5efa\u7684\u9ed8\u8ba4\u662fdisable\u72b6\u6001.\n# \u4ecetickscript\u521b\u5efatask\n$ kapacitor define &lt;name&gt; -tick task.tick -type [stream|batch] -dbrp [database.retentionPolicy]\n# \u4ecetemplate\u521b\u5efatask(\u5982\u679cyaml\/json\u4e2d\u6ca1\u6709\u6307\u5b9atemplate\u9700\u8981\u7528-template\u6307\u5b9a)\n$ kapacitor define &lt;name&gt; -file task.yaml\n$ kapacitor define &lt;name&gt; -file task.json\n# \u5220\u9664task\n$ kapacitor delete [task id\/name]\n$ kapacitor list tasks\/templates\n$ kapacitor reload [task id\/name] # \u76f8\u5f53\u4e8edisable &amp; enable.\n$ kapacitor enable [task id\/name]\n$ kapaciror disable [task id\/name]\n$ kapacitor show [id\/name]\n$ kapacitor watch [task id\/name]\n$ kapacitor list topics\n$ kapacitor delete topics [topic id]\n<\/code><\/pre>\n<hr>\n<h1 id=\"http-api\">Http API<\/h1>\n<pre><code>port = 9092\n<\/code><\/pre>\n<h2 id=\"configuration\">configuration<\/h2>\n<p>\u83b7\u53d6\u6240\u6709\u53ef\u4ee5overwrite\u7684\u53c2\u6570<\/p>\n<pre><code>GET \/kapacitor\/v1\/config\n<\/code><\/pre>\n<p>\u83b7\u53d6section\/option\u53c2\u6570<\/p>\n<pre><code>GET \/kapacitor\/v1\/config\/smtp\nGET \/kapacitor\/v1\/config\/smtp\/\nGET \/kapacitor\/v1\/config\/influxdb\nGET \/kapacitor\/v1\/config\/influxdb\/localhost\nPOST \/kapacitor\/v1\/config\/smtp\/\n{\n&quot;set&quot;:{\n&quot;enabled&quot;: true\n}\n}\n<\/code><\/pre>\n<p>\u64cd\u4f5ctask:<\/p>\n<pre><code>\/\/ \u4fee\u6539\u5df2\u5b58\u5728\u7684task\u7684\u53c2\u6570:\n$ curl -H 'content-type: application\/json' -X PATCH -d '{&quot;vars&quot;: {&quot;warn&quot;:{&quot;value&quot;:90, &quot;type&quot;:&quot;int&quot;}}}' http:\/\/kapacitor-service:9092\/kapacitor\/v1\/tasks\/cpu\n<\/code><\/pre>\n<p>\u64cd\u4f5calert:<\/p>\n<pre><code>\/\/ \u5217\u51fa\u6240\u6709topic:\n$ curl -H 'content-type: application\/json' -X GET http:\/\/kapacitor-service:9092\/kapacitor\/v1\/alerts\/topics\n\/\/ \u5217\u51fa\u6307\u5b9atopic\u7684\u6240\u6709events:\n$ curl -H 'content-type: application\/json' -X GET http:\/\/kapacitor-service:9092\/kapacitor\/v1\/alerts\/topics\/&lt;topic&gt;\/events\n\/\/ \u5217\u51fa\u6307\u5b9aevents\n$ curl -H 'content-type: application\/json' -X GET http:\/\/kapacitor-service:9092\/kapacitor\/v1\/alerts\/topics\/&lt;topic&gt;\/events\/&lt;event&gt;?min-level=CRITICAL\n<\/code><\/pre>\n<hr>\n<h1 id=\"tickscript\">TICKscript<\/h1>\n<p>\u6ce8\u91ca:<\/p>\n<pre><code>\/\/ comment\n<\/code><\/pre>\n<p>tickscript\u5b57\u7b26\u4e32\u7528\u5355\u5f15\u53f7\u548c\u4e09\u5355\u5f15\u53f7\u8868\u793a.<\/p>\n<pre><code>var a = 'test'\nvar b = '''test1\ntest2'''\n<\/code><\/pre>\n<p>Keywords:<\/p>\n<pre><code>TRUE\nFALSE\nAND\nOR\nlambda\nvar\ndbrp\n<\/code><\/pre>\n<p>operator:<\/p>\n<pre><code>+ - * \/ \u7b97\u6570\u8fd0\u7b97\n== != &lt; &lt;= &gt; &gt;= \u6bd4\u8f83\u8fd0\u7b97\n=~ !~ \u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u548c\u4e0d\u5339\u914d\n! AND OR \u903b\u8f91\u8fd0\u7b97\n<\/code><\/pre>\n<p>chaining operators:<\/p>\n<pre><code>| chaining method (constructor)\n. property method (property methods &amp; event handlers)\n@ User Define Function\n<\/code><\/pre>\n<p>status:<\/p>\n<pre><code>0 -&gt; OK\n1 -&gt; INFO\n2 -&gt; WARN\n3 -&gt; CRIT\n<\/code><\/pre>\n<hr>\n<h1 id=\"node\">node<\/h1>\n<p>node\u662ftickscript\u4e2d\u7684\u590d\u6742\u6570\u636e\u7ed3\u6784\uff0e<\/p>\n<p>\u4e24\u4e2a\u9876\u7ea7node\u7c7b\u578b\u662fstream\u548cbatch<\/p>\n<p>batch\u662f\u5b9a\u65f6\u67e5\u8be2influxdb.<\/p>\n<p>stream\u662f\u901a\u8fc7\u8ba2\u9605influxdb,\u5199\u5165\u5230influxdb\u7684\u6570\u636e\u4e5f\u4f1a\u5199\u5165kapacitor.<\/p>\n<p>constructor\u8c03\u7528\u76f8\u5e94\u7684property methods.<\/p>\n<h2 id=\"stream\">stream<\/h2>\n<pre><code>var data = stream\n|from()...\n<\/code><\/pre>\n<p>property methods:<\/p>\n<pre><code>quiet()\n<\/code><\/pre>\n<p>chaining methods:<\/p>\n<pre><code>Deadman\nFrom\nStats\n<\/code><\/pre>\n<h2 id=\"batch\">batch<\/h2>\n<pre><code>var data = batch\n|query()...\n<\/code><\/pre>\n<p>property methods:<\/p>\n<pre><code>quiet()\n<\/code><\/pre>\n<p>chaining methods:<\/p>\n<pre><code>Deadman\nQuery\nStats\n<\/code><\/pre>\n<h2 id=\"alert\">alert<\/h2>\n<p>alert\u6709\u4e09\u79cd\u7c7b\u578b: threshold, relative, deadman.<\/p>\n<pre><code>var alert = data\n|eval()...\n|alert()\n.id('{{ index .Tags &quot;&lt;tag-key&gt;&quot; }}')\n.message('{{ .ID }} {{ .Level }} {{ index .Fields &quot;&lt;field-key&gt;&quot; }} {{ .Time }}')\n.details(...)\n...\n<\/code><\/pre>\n<p>constructor:<\/p>\n<pre><code>alert()\n<\/code><\/pre>\n<p>property methods:<\/p>\n<pre><code>id() # \u5b9a\u4e49alert\u7684ID\nmessage() # \u76f8\u5f53\u4e8eemail\u7684subject.\ndetails() # html\u683c\u5f0f\u7684\u8b66\u544a\u4fe1\u606f\uff0c\u76f8\u5f53\u4e8eemail\u7684body.\ninfo()\ninfoReset()\nwarn()\nwarnReset()\ncrit()\ncritReset()\nemail()\nlog() # \u5c06json\u683c\u5f0f\u7684alert\u5b58\u653e\u5230\u6587\u4ef6\uff0e\nidTag\nidField\nlevelTag()\nlevelField()\ndurationField()\nmessageField()\npost()\ntcp()\nall() # period\u91cc\u9762\u6240\u6709\u503c\u90fd\u6ee1\u8db3\u6761\u4ef6\u624dalert\ntopic()\nflapping()\nhistory()\ninhibit(&lt;category&gt;, &lt;tags&gt;) \/\/ \u5ffd\u7565\u4e00\u7c7b\u544a\u8b66\nquiet()\nnoRecoveries() # \u4e0d\u8981\u53d1\u6062\u590d(OK)\u7684\u8b66\u544a\nstateChangesOnly() # \u72b6\u6001\u6539\u53d8\u624d\u53d1\u8b66\u544a,OK\/INFO\/WARNING\/CRITICAL\ncategory()\n<\/code><\/pre>\n<p>message\/details event data:<\/p>\n<pre><code># \u901a\u8fc7property methods\u5b9a\u4e49\u4e00\u4e9b\u53d8\u91cf\nID -&gt; {{ .ID }}\nName -&gt; measurement\nTaskName -&gt; task name\nGroup -&gt; groupBy\nTags -&gt; {{.Tags}} {{index .Tags &quot;&lt;tag_key&gt;&quot;}}\nFields -&gt; {{.Fields}} {{index .Fields &quot;&lt;field_key&gt;&quot;}}\nMessage\nDetails\nTime -&gt; {{ .Time }}\nDuration -&gt; {{ .Duration }}\nLevel -&gt; {{ .Level }}\nData\nRecoverable\n<\/code><\/pre>\n<h2 id=\"query\">query<\/h2>\n<p>constructor:<\/p>\n<pre><code>query(q string)\n<\/code><\/pre>\n<p>property methods:<\/p>\n<pre><code>fill()\nalign()\nalignGroup()\ngroupBy()\ncron()\nevery()\nperiod()\nquiet()\n<\/code><\/pre>\n<h2 id=\"from\">from<\/h2>\n<p>constructor:<\/p>\n<pre><code>from()\n<\/code><\/pre>\n<p>property methods:<\/p>\n<pre><code>database()\nretentionPolicy()\nmeasurement()\nwhere()\ngroupBy()\nround()\ntruncate()\nquiet()\n<\/code><\/pre>\n<h2 id=\"window\">window<\/h2>\n<p>constructor:<\/p>\n<pre><code>window()\n<\/code><\/pre>\n<p>property methods:<\/p>\n<pre><code>every()\nperiod()\nalign()\nquiet()\n<\/code><\/pre>\n<h2 id=\"log\">Log<\/h2>\n<p>constructor:<\/p>\n<pre><code>log()\n<\/code><\/pre>\n<p>property methods:<\/p>\n<pre><code>level()\nprefix()\nquiet()\n<\/code><\/pre>\n<h2 id=\"influxdbout\">influxDBOut<\/h2>\n<p>constructor:<\/p>\n<pre><code>influxDBOut()\n<\/code><\/pre>\n<p>property methods:<\/p>\n<pre><code>create()\n...\n<\/code><\/pre>\n<hr>\n<h1 id=\"handler\">handler<\/h1>\n<p>handler\u662f\u7528\u6765\u5904\u7406alert\u7684\u5de5\u5177, \u6700\u5e38\u7528\u7684\u662femail<\/p>\n<p>handler\u53ef\u4ee5\u8c03\u7528\u76f8\u5e94\u7684options.<\/p>\n<h2 id=\"email\">email<\/h2>\n<p>options:<\/p>\n<pre><code>to(&quot;&lt;email_address&gt;&quot;)\n<\/code><\/pre>\n<p>\u9700\u8981\u914d\u7f6esmtp<\/p>\n<pre><code>[smtp]\nenabled = true\nhost = &quot;localhost&quot; # \u4e00\u822cpostfix\/mailutils\u548ckapacitor\u5b89\u88c5\u5230\u540c\u4e00\u53f0server\nport = 25\nfrom = &quot;canuxcheng@gmail.com&quot; # \u5fc5\u987b\u914d\u7f6e\nto = [&quot;&quot;] # \u53ef\u4ee5\u5728tickscript\u4e2d\u6307\u5b9a, tickscript\u4e0d\u6307\u5b9a\uff0c\u5c31\u7528\u8be5\u914d\u7f6e.\nglobal = true # \u5f00\u542f\u540e,tickscript\u4e2d\u4e0d\u7528\u6307\u5b9ahandler,\u9ed8\u8ba4\u90fd\u662f\u53d1\u90ae\u4ef6.\n<\/code><\/pre>\n<h2 id=\"log-1\">log<\/h2>\n<p>options:<\/p>\n<pre><code>path\nmode\n<\/code><\/pre>\n<p>\u5199\u5165\u5230log.<\/p>\n<h2 id=\"slack\">slack<\/h2>\n<h2 id=\"post\">post<\/h2>\n<h2 id=\"tcp\">tcp<\/h2>"},{"title":"Prometheus","link":"https:\/\/canuxcheng.com\/post\/metrics_prometheus\/","pubDate":"Thu, 18 Jan 2018 19:23:25 +0000","guid":"https:\/\/canuxcheng.com\/post\/metrics_prometheus\/","description":"<h1 id=\"prometheus\">Prometheus<\/h1>\n<p>Prometheus Server\u662fPrometheus\u7ec4\u4ef6\u4e2d\u7684\u6838\u5fc3\u90e8\u5206\uff0c\u8d1f\u8d23\u5b9e\u73b0\u5bf9\u76d1\u63a7\u6570\u636e\u7684\u83b7\u53d6\uff0c\u5b58\u50a8\u4ee5\u53ca\u67e5\u8be2<\/p>\n<p>swarm\u90e8\u7f72:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/vegasbrianc\/prometheus\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/vegasbrianc\/prometheus<\/a><\/p>\n<p>k8s\u90e8\u7f72:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/coreos\/kube-prometheus\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/coreos\/kube-prometheus<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/coreos\/prometheus-operator\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/coreos\/prometheus-operator<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/helm\/charts\/tree\/master\/stable\/prometheus-operator\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/helm\/charts\/tree\/master\/stable\/prometheus-operator<\/a><\/p>\n<p>\u9ad8\u53ef\u7528:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/thanos-io\/thanos\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/thanos-io\/thanos<\/a><\/p>\n<p>prometheus grafana dashboard:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes-monitoring\/kubernetes-mixin\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes-monitoring\/kubernetes-mixin<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/grafana\/kubernetes-app\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/grafana\/kubernetes-app<\/a><\/p>\n<hr>\n<h1 id=\"promql\">PromQL<\/h1>\n<p>metrics\u7c7b\u578b:<\/p>\n<ol>\n<li>counter\u8ba1\u6570\u5668<\/li>\n<li>gauge\u4eea\u8868\u76d8<\/li>\n<li>histogram\u76f4\u65b9\u56fe<\/li>\n<li>summary\u6458\u8981<\/li>\n<\/ol>"},{"title":"Telegraf","link":"https:\/\/canuxcheng.com\/post\/metrics_telegraf\/","pubDate":"Thu, 18 Jan 2018 19:23:25 +0000","guid":"https:\/\/canuxcheng.com\/post\/metrics_telegraf\/","description":"<h1 id=\"telegraf\">Telegraf<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/influxdata\/telegraf\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/influxdata\/telegraf<\/a><\/p>\n<p>The plugin-driven server agent for collecting &amp; reporting metrics.<\/p>\n<hr>\n<h1 id=\"configuartion\">Configuartion<\/h1>\n<p>agent configuration:<\/p>\n<pre><code>interval \u6240\u6709inputs\u7684\u9ed8\u8ba4\u8fd0\u884c\u95f4\u9694\nround_interval\ncollection_jitter\nprecision ns\/us\/ms\/s\nflush_interval\nflush_jitter\n<\/code><\/pre>\n<p>input configuration:<\/p>\n<pre><code>interval\nname_override # \u9ed8\u8ba4measurements\u662f\u63d2\u4ef6\u540d,\u4fee\u6539\u9ed8\u8ba4measurements.\nname_prefix\nname_suffix\ntags\n<\/code><\/pre>\n<hr>\n<h1 id=\"go-api\">Go API<\/h1>\n<p><a class=\"link\" href=\"https:\/\/godoc.org\/github.com\/influxdata\/telegraf#Input\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/godoc.org\/github.com\/influxdata\/telegraf#Input<\/a><\/p>\n<p>\u6d4b\u8bd5\u63d2\u4ef6\uff1a<\/p>\n<pre><code># \u9700\u8981\u914d\u7f6e\u6587\u4ef6\n$ telegraf --input-filter &lt;plugin-name&gt; --test\n<\/code><\/pre>\n<hr>\n<h1 id=\"build\">Build<\/h1>\n<p>\u5b89\u88c5\u4f9d\u8d56\uff1a<\/p>\n<pre><code>sudo apt-get install ruby-dev\nsudo gem install fpm\nsudo apt-get install rpm\n<\/code><\/pre>\n<p>\u7f16\u8bd1telegraf:<\/p>\n<pre><code>make telegraf\n<\/code><\/pre>\n<p>\u751f\u6210\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>.\/telegraf config &gt; .\/etc\/telegraf.conf\n<\/code><\/pre>\n<p>\u6784\u5efadeb:<\/p>\n<pre><code>make package\n<\/code><\/pre>\n<hr>\n<h1 id=\"development\">Development<\/h1>\n<p>\u4fee\u6539\u9ed8\u8ba4enable\u7684plugin:<\/p>\n<pre><code># plugin\u4e2d\u76f8\u5e94\u7684sampleConfig\u4e2d\u7684\u5b57\u6bb5\u4e0d\u8981\u7528#\u6ce8\u91ca\uff0e\ninternal\/config\/config.go -&gt; \u53ef\u4ee5\u4fee\u6539\u9ed8\u8ba4enable\u7684plugin.\ninputDefaults\noutputDefaults\n<\/code><\/pre>\n<p>\u8c03\u8bd5\uff1a<\/p>\n<pre><code>.\/telegraf --config .\/etc\/telegraf.conf --input-filter process --test\n<\/code><\/pre>\n<p>\u6dfb\u52a0debugxinxi<\/p>\n<pre><code>import &quot;log&quot;\nlog.Printf(&quot;D! key: %v&quot;, value)\n# &quot;D!&quot; \u5f00\u5934\u7684\u4fe1\u606f\u5f53debug=true\u624d\u4f1a\u6253\u5370.\n<\/code><\/pre>\n<hr>"},{"title":"Contribution","link":"https:\/\/canuxcheng.com\/post\/go_oss\/","pubDate":"Mon, 01 Jan 2018 10:49:21 +0000","guid":"https:\/\/canuxcheng.com\/post\/go_oss\/","description":"<h1 id=\"golang-contribution\">Golang Contribution<\/h1>\n<p><a class=\"link\" href=\"https:\/\/go.dev\/doc\/contribute\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/go.dev\/doc\/contribute<\/a><\/p>\n<h2 id=\"\u521b\u5efagoogle\u8d26\u53f7\">\u521b\u5efagoogle\u8d26\u53f7<\/h2>\n<p>\u63a8\u8350\u7533\u8bf7\u4e00\u4e2agoogle\u90ae\u7bb1\u3002<\/p>\n<p>\u5728\u5f00\u53d1\u673a\u914d\u7f6egit<\/p>\n<pre><code>$ git config --global user.email name@example.com\n$ git config user.email name@example.com\n<\/code><\/pre>\n<h2 id=\"\u7b7ecla\">\u7b7eCLA<\/h2>\n<p>\u4e2a\u4eba\u5f00\u53d1\u8005\u9700\u8981\u7b7e\u7f72CLA\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/cla.developers.google.com\/about\/google-individual\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/cla.developers.google.com\/about\/google-individual<\/a><\/p>\n<h2 id=\"\u914d\u7f6egit\u8ba4\u8bc1\">\u914d\u7f6egit\u8ba4\u8bc1<\/h2>\n<p>\u70b9\u51fb\u201cGenerate Password\u201d\uff0c \u7528google\u90ae\u7bb1\u767b\u9646\uff0c\u6839\u636e\u63d0\u793a\u914d\u7f6egit\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/go.googlesource.com\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/go.googlesource.com\/<\/a><\/p>\n<h2 id=\"\u521b\u5efagerrit\u8d26\u53f7\">\u521b\u5efagerrit\u8d26\u53f7<\/h2>\n<p>\u7528google\u90ae\u7bb1\u767b\u9646\u5373\u53ef\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/go-review.googlesource.com\/dashboard\/self\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/go-review.googlesource.com\/dashboard\/self<\/a><\/p>\n<h2 id=\"\u5b89\u88c5git-codereview\">\u5b89\u88c5git-codereview<\/h2>\n<p>windows:<\/p>\n<pre><code>$ go get golang.org\/x\/review\/git-codereview@latest\n$ git --exec-path\n&gt; copy git-codereview.exe from GOBIN to Git\\mingw64\\libexec\\git-core\n$ git codereview help\n<\/code><\/pre>\n<p>linux\/mac:<\/p>\n<pre><code>$ go install golang.org\/x\/review\/git-codereview@latest\n$ git codereview help\n<\/code><\/pre>\n<h2 id=\"\u9009\u53d6\u4fee\u6539\u7684cl\">\u9009\u53d6\u4fee\u6539\u7684CL<\/h2>\n<p>\u4ecegithub\u9009\u53d6\u4e00\u4e2a\u8fd8\u6ca1\u6709\u4eba\u63d0\u4ea4CL(change log\/list)\u7684Issue\u8fdb\u884c\u4fee\u6539\u3002<\/p>\n<p>issue\u4e09\u79cd\u7c7b\u578b\uff1a<\/p>\n<ul>\n<li>NeedsInvestigation<\/li>\n<li>NeedsDecision<\/li>\n<li>NeedsFix \u9009\u8fd9\u4e2a\u91cc\u9762\u8fd8\u6ca1\u6709CL\u7684\u505a<\/li>\n<\/ul>\n<p><a class=\"link\" href=\"https:\/\/github.com\/golang\/go\/issues?q=is%3Aissue&#43;is%3Aopen&#43;label%3ANeedsFix&#43;NOT&#43;%22golang.org%2Fcl%22\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/golang\/go\/issues?q=is%3Aissue+is%3Aopen+label%3ANeedsFix+NOT+%22golang.org%2Fcl%22<\/a><\/p>\n<h2 id=\"\u63d0\u4ea4patch\">\u63d0\u4ea4patch<\/h2>\n<p>\u652f\u6301github\u6216\u8005gerrit\u63d0\u4ea4patch\u3002<\/p>\n<p>github\u7528\u6237\u76f4\u63a5fork\u5230\u81ea\u5df1\u8d26\u53f7\uff0cclone\u4e0b\u6765\u5373\u53ef\u3002<\/p>\n<pre><code>git clone https:\/\/github.com\/golang\/go.git\n<\/code><\/pre>\n<p>gerrit\u7528\u6237<\/p>\n<pre><code>git clone https:\/\/go.googlesource.com\/go\n<\/code><\/pre>\n<p>\u521b\u5efa\u5f00\u53d1\u5206\u652f\u5e76\u4fee\u6539\u4ee3\u7801<\/p>\n<pre><code>git checkout -b canux_dev\n...\ngit add -A\ngit codereview change\n...\n<\/code><\/pre>\n<p>\u672c\u5730\u6d4b\u8bd5\u4fee\u6539<\/p>\n<pre><code>.\/all.bash\n<\/code><\/pre>\n<p>\u63d0\u4ea4\u4fee\u6539\uff0cgithub\u7528\u6237\u76f4\u63a5\u53bbgithub\u9875\u9762\u63d0\u4ea4PR\u3002<\/p>\n<p>gerrit\u7528\u6237\u901a\u8fc7\u547d\u4ee4\u884c\u63d0\u4ea4\uff1a<\/p>\n<pre><code>$ git codereview mail # send changes to Gerrit\n<\/code><\/pre>\n<p>commit message\u683c\u5f0f\u6709\u4e25\u683c\u8981\u6c42\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/golang.org\/doc\/contribute#commit_messages\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/golang.org\/doc\/contribute#commit_messages<\/a><\/p>\n<h2 id=\"code-review\">code review<\/h2>\n<p>\u63d0\u4ea4\u4e4b\u540etrybots\u4f1a\u81ea\u52a8\u6784\u5efa\uff0c\u53ef\u4ee5\u901a\u8fc7build dashboard\u67e5\u770b\u5404\u4e2a\u5e73\u53f0build\u7ed3\u679c:<\/p>\n<p><a class=\"link\" href=\"https:\/\/build.golang.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/build.golang.org\/<\/a><\/p>\n<p>\u67e5\u770b\u81ea\u5df1\u7684patch\u7684review\u60c5\u51b5\uff1a<\/p>\n<p><a class=\"link\" href=\"https:\/\/go-review.googlesource.com\/dashboard\/self\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/go-review.googlesource.com\/dashboard\/self<\/a><\/p>"},{"title":"Debug","link":"https:\/\/canuxcheng.com\/post\/go_debug\/","pubDate":"Mon, 01 Jan 2018 10:49:21 +0000","guid":"https:\/\/canuxcheng.com\/post\/go_debug\/","description":"<h1 id=\"go\">go<\/h1>\n<pre><code>go vet\n<\/code><\/pre>\n<h1 id=\"gdb\">gdb<\/h1>\n<h1 id=\"delve\">delve<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/derekparker\/delve\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/derekparker\/delve<\/a><\/p>\n<hr>"},{"title":"Devops","link":"https:\/\/canuxcheng.com\/post\/go_devops\/","pubDate":"Mon, 01 Jan 2018 10:49:21 +0000","guid":"https:\/\/canuxcheng.com\/post\/go_devops\/","description":"<h1 id=\"go\">Go<\/h1>\n<p>go\u6709\u4e09\u79cd\u5b89\u88c5\u65b9\u5f0f\uff1a<\/p>\n<ol>\n<li>\u6e90\u7801\u5b89\u88c5<\/li>\n<li>\u6807\u51c6\u5305\u5b89\u88c5<\/li>\n<li>\u7b2c\u4e09\u65b9\u5de5\u5177\u5b89\u88c5<\/li>\n<\/ol>\n<p>GOROOT:<\/p>\n<pre><code>GOROOT \u5c31\u662fgo\u7684\u5b89\u88c5\u76ee\u5f55\n<\/code><\/pre>\n<p>windows\u6807\u51c6\u5305\u5b89\u88c5go:<\/p>\n<pre><code>msi\u6307\u5b9a\u5b89\u88c5\u8def\u5f84\uff0c\u81ea\u52a8\u6dfb\u52a0%GOROOT%\/bin\u5230\u73af\u5883\u53d8\u91cf\n<\/code><\/pre>\n<p>linux\u6807\u51c6\u5305\u5b89\u88c5go:<\/p>\n<pre><code>\u4e0b\u8f7d.tar.gz\u5305\u89e3\u538b\u5230\/usr\/local\/go\nGOROOT=\/usr\/local\/go\nexport PATH=$PATH:\/usr\/local\/go\/bin\n<\/code><\/pre>\n<p>\u9a8c\u8bc1\u5b89\u88c5\uff1a<\/p>\n<pre><code>$ go --help\n$ go version\n<\/code><\/pre>\n<p>\u7b2c\u4e09\u65b9\u5de5\u5177gvm\u5b89\u88c5go:<\/p>\n<p><a class=\"link\" href=\"http:\/\/github.com\/moovweb\/gvm\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/github.com\/moovweb\/gvm<\/a><\/p>\n<pre><code>$ gvm install go1.9.2\n$ gvm use go1.9.2\n<\/code><\/pre>\n<hr>\n<h1 id=\"gopath\">GOPATH<\/h1>\n<p>gopath\u7528\u6765\u5b58\u653ego\u6e90\u7801\uff0cgo\u7684\u53ef\u8fd0\u884c\u6587\u4ef6\uff0c\u4ee5\u53ca\u76f8\u5e94\u7684\u7f16\u8bd1\u4e4b\u540e\u7684\u5305\u6587\u4ef6\uff0e<\/p>\n<p>GOPATH \u4ecego1.1\u52301.7\u90fd\u9700\u8981\u8bbe\u7f6e\uff0c\u800c\u4e14\u4e0d\u80fd\u662fgo\u7684\u5b89\u88c5\u76ee\u5f55, go1.8\u5f00\u59cb\u6709\u9ed8\u8ba4\u503c:<\/p>\n<pre><code>GOPATH=$USERPROFILE%go\nGOPATH=$HOME\/go\n<\/code><\/pre>\n<p>gopath\u7ed3\u6784\uff1a<\/p>\n<pre><code>src \u5b58\u653e\u6e90\u7801\npkg \u7f16\u8bd1\u540e\u7684\u5e93\u6587\u4ef6\nbin \u7f16\u8bd1\u540e\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\n<\/code><\/pre>\n<p>gopath\u6709\u591a\u4e2a\u503c\u65f6\u7528\u5192\u53f7\u5206\u5f00\u5373\u53ef.<\/p>\n<h1 id=\"gobin\">GOBIN<\/h1>\n<p>\u63a8\u8350\u8bbe\u7f6e\uff1a<\/p>\n<pre><code>GOBIN=$GOPATH\/bin\n<\/code><\/pre>\n<p>go get \u548c go install \u5b89\u88c5\u7684\u4e8c\u8fdb\u5236\u5230GOBIN\u3002<\/p>\n<hr>\n<h1 id=\"go\u547d\u4ee4\">go\u547d\u4ee4<\/h1>\n<pre><code>$ go help [command]\n<\/code><\/pre>\n<p>get<\/p>\n<p>\u4e0b\u8f7d\u5e76\u5b89\u88c5\u5305\u548c\u4f9d\u8d56, \u4e5f\u5c31\u662f\u5b89\u88c5\u7b2c\u4e09\u65b9\u7684\u5e93\uff0e<\/p>\n<pre><code>$ go get [...] [packages]\n&gt; go get\u5b89\u88c5\u7b2c\u4e09\u65b9\u5305\u5982\u679c\u51fa\u73b0\u4f9d\u8d56\u65e0\u6cd5\u5b89\u88c5\uff0c\u53ef\u4ee5\u901a\u8fc7github\u4e0b\u8f7d\uff0e\n$ cd golang.org\/x\n$ git clone https:\/\/github.com\/golang\/crypto.git crypto\n$ go install golang.org\/x\/crypto\/ssh\ngo get -u\u00a0(without any arguments) now only upgrades the direct and indirect dependencies of your current\u00a0package, and no longer examines your entire\u00a0module.\ngo get -u .\/...\u00a0from your module root upgrades all the direct and indirect dependencies of your module, and now excludes test dependencies.\ngo get -u -t .\/...\u00a0is similar, but also upgrades test dependencies.\n<\/code><\/pre>\n<p>build<\/p>\n<p>\u7f16\u8bd1\u5305\u548c\u4f9d\u8d56<\/p>\n<pre><code>$ go build [-o output] [-i] [build flags] [packages]\n<\/code><\/pre>\n<p>install<\/p>\n<p>\u7f16\u8bd1\u5e76\u5b89\u88c5\u5305\u548c\u4f9d\u8d56<\/p>\n<pre><code>$ go install [build flags] [packages]\n<\/code><\/pre>\n<p>run<\/p>\n<p>\u7f16\u8bd1\u5e76\u8fd0\u884c\u7a0b\u5e8f<\/p>\n<pre><code>$ go run [...] gofiles... [...]\n<\/code><\/pre>\n<p>fmt<\/p>\n<p>\u683c\u5f0f\u5316\u4ee3\u7801\u548c\u6587\u6863\uff1a<\/p>\n<pre><code>$ go fmt [...] [packages]\n<\/code><\/pre>\n<p>vet<\/p>\n<p>\u68c0\u6d4b\u4ee3\u7801\u5e38\u89c1\u9519\u8bef:<\/p>\n<pre><code>$ go vet [-n] [-x] [build flags] [vet flags] [packages]\n<\/code><\/pre>\n<p>test<\/p>\n<p>\u6d4b\u8bd5\u5305:<\/p>\n<pre><code>$ go test [...] [packages] [...]\n<\/code><\/pre>\n<p>doc<\/p>\n<p>\u67e5\u770b\u6587\u6863\uff1a<\/p>\n<pre><code>$ go doc [package\/symbol]\n<\/code><\/pre>\n<p>tool<\/p>\n<p>\u8fd0\u884c\u5de5\u5177:<\/p>\n<pre><code>$ go tool [-n] command [args...]\naddr2line\nasm\nbuildid\ncgo\n\/\/ \u67e5\u770b\u6c47\u7f16\u4ee3\u7801\ncompile\ngo tool compile -S pkg.go\ncover\ndist\ndoc\nfix\nlink\nnm\nobjdump\npack\npprof\ntest2json\ntrace\nvet\n<\/code><\/pre>\n<p>mod<\/p>\n<pre><code>go mod init &lt;name&gt;\ngo mod tidy \/\/ \u6dfb\u52a0\u7f3a\u5c11\u7684\uff0c\u5220\u9664\u591a\u4f59\u7684.\ngo mod download \/\/ \u4e0b\u8f7d\u5305\ngo mod verify\ngo mod edit\ngo mod graph\ngo mod why\ngo mod vendor\n<\/code><\/pre>\n<p>env<\/p>\n<pre><code>\/\/ \u901a\u8fc7env \u8bbe\u7f6egolang\u7684\u53d8\u91cf\uff0c\u53d6\u4ee3\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\ngo env\ngo env -w GOROOT=&quot;\/usr\/local\/go&quot;\ngo env -w GOPATH=&quot;$HOME\/go&quot;\ngo env -w GOBIN=&quot;$HOME\/go\/bin&quot;\ngo env -w GO111MODULE=on\ngo env -w GOPROXY=https:\/\/goproxy.cn,direct\n<\/code><\/pre>\n<p>clean<\/p>\n<pre><code>go clean -cache\ngo clean -modcache\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u5b89\u88c5\u7b2c\u4e09\u65b9\u5305\">\u5b89\u88c5\u7b2c\u4e09\u65b9\u5305<\/h1>\n<p>go get\u7684\u529f\u80fd\u5f88\u6709\u9650\uff0e<\/p>\n<p>godep\u548cgolide\u90fd\u4f1a\u88ab\u5b98\u65b9\u7684dep\u53d6\u4ee3\uff0e<\/p>\n<h2 id=\"depdeprecated\">dep(deprecated)<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/golang\/dep\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/golang\/dep<\/a><\/p>\n<p>\u65e0\u6cd5\u89e3\u51b3GFW\u7684\u95ee\u9898.<\/p>\n<p>\u5b89\u88c5\uff1a<\/p>\n<pre><code>$ go get -u github.com\/golang\/dep\/cmd\/dep\n<\/code><\/pre>\n<p>go\u5b98\u65b9\u5305\u7ba1\u7406\u5668<\/p>\n<pre><code># \u521d\u59cb\u5316\u4e00\u4e2a\u4f7f\u7528dep\u7ba1\u7406\u5305\u7684\u9879\u76ee\uff0c\n# \u521b\u5efaGopkg.toml, Gopkg.lock, vendor\/\n$ dep init\n$ dep status\n$ dep prune\n$ dep ensure\n$ dep ensure -update\n<\/code><\/pre>\n<h2 id=\"module\">module<\/h2>\n<p>vgo\u5df2\u7ecf\u96c6\u6210\u5230go1.11<\/p>\n<p>\u901a\u8fc7go mod init\u521d\u59cb\u5316\u4e24\u4e2a\u6587\u4ef6.<\/p>\n<p>go.mod:<\/p>\n<pre><code>module\ngo\nrequire\nexclude\nreplace\n\/\/ \u4f7f\u7528\u672c\u5730module,\u6216\u4f7f\u7528\u6307\u5b9arepo\u91cc\u9762\u7684module\nreplace github.com\/crazy-canux\/go-devops =&gt; \/path\/to\/local\/github.com\/crazy-canux\/go-devops\n<\/code><\/pre>\n<p>go.sum:<\/p>\n<pre><code>go env -w GOSUMDB=off\n<\/code><\/pre>\n<p>\u8bbe\u7f6e\u76f8\u5173\u73af\u5883\u53d8\u91cf:<\/p>\n<pre><code>GO111MODULE:\n\/\/ auto\/on\/off\ngo env -w GO111MODULE=on\nGOPROXY:\ngo env -w GOPROXY=https:\/\/goproxy.cn,direct\nhttps:\/\/proxy.golang.org \/\/\u9ed8\u8ba4\u503c\nhttps:\/\/goproxy.cn\nhttps:\/\/goproxy.io\nhttps:\/\/mirrors.aliyun.com\/goproxy\/\nGOSUMDB:\nGOPRIVATE\nGONOPROXY\nGONOSUMDB\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u9879\u76ee\u7ed3\u6784\">\u9879\u76ee\u7ed3\u6784<\/h1>\n<pre><code>cmd: \u53ef\u6267\u884c\u6587\u4ef6\u5165\u53e3\npkg: \u6838\u5fc3\u4ee3\u7801\u5e93\napi: api\u7684spec, openapi\/swagger\/json\/protocol\/grpc\nhack: \u6784\u5efa\/\u6d4b\u8bd5\u76f8\u5173\u811a\u672c\nplugin: \u63d2\u4ef6\nstaging: wip\nthird_party: \u7b2c\u4e09\u65b9\u5de5\u5177\/\u4ee3\u7801\nvendor: \u9879\u76ee\u4f9d\u8d56\nbuild\ntest\ndocs\n<\/code><\/pre>\n<p>\u6ca1\u6709\u5b50\u76ee\u5f55\u5305\u7ed3\u6784\uff1a<\/p>\n<pre><code>go-devops\n|- README.md\n|- doc.go\n|- grafana.go\n|- grafana_test.go\n...\nimport &quot;go-devops&quot;\n<\/code><\/pre>\n<p>\u6709\u5b50\u76ee\u5f55\u7684\u5305\u7ed3\u6784\uff1a<\/p>\n<pre><code>go-devops\n|- README.md\n|- doc.go \/\/ package go_devops\n|- grafana\n|- doc.go \/\/ package grafana\n|- grafana.go\n|- grafana_test.go\nimport &quot;go-devops\/grafana&quot;\n<\/code><\/pre>\n<hr>\n<h1 id=\"proxy\">proxy<\/h1>\n<p>goproxy.io<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/goproxyio\/goproxy\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/goproxyio\/goproxy<\/a><\/p>\n<p>goproxy.cn<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/goproxy\/goproxy.cn\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/goproxy\/goproxy.cn<\/a><\/p>"},{"title":"Document","link":"https:\/\/canuxcheng.com\/post\/go_document\/","pubDate":"Mon, 01 Jan 2018 10:49:21 +0000","guid":"https:\/\/canuxcheng.com\/post\/go_document\/","description":"<h1 id=\"document\">Document<\/h1>\n<p>go\u6587\u6863\u76f8\u5173<\/p>\n<p><a class=\"link\" href=\"https:\/\/godoc.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/godoc.org\/<\/a><\/p>\n<p>go\u6587\u6863\u7684\u4e24\u79cd\u65b9\u5f0f:<\/p>\n<ul>\n<li>go doc<\/li>\n<li>godoc<\/li>\n<\/ul>\n<h1 id=\"go-doc\">go doc<\/h1>\n<p>\u76f4\u63a5\u5728\u547d\u4ee4\u884c\u67e5\u770b\u6587\u6863<\/p>\n<pre><code>$ go doc [package\/symbol]\n<\/code><\/pre>\n<h1 id=\"godoc\">godoc<\/h1>\n<p>go\u81ea\u5e26\u7684\u6587\u6863\u547d\u4ee4\u884c\u63a5\u53e3,\u5728\u6d4f\u89c8\u5668\u67e5\u770b\u6587\u6863<\/p>\n<pre><code>godoc package [name ...]\ngodoc -http=:6060\n<\/code><\/pre>\n<p>\u901a\u8fc7github\u7684\u9879\u76ee\u6587\u6863\u5728:<\/p>\n<pre><code>https:\/\/godoc.org\n<\/code><\/pre>\n<hr>\n<h1 id=\"godev\">go.dev<\/h1>\n<p><a class=\"link\" href=\"https:\/\/pkg.go.dev\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/pkg.go.dev<\/a><\/p>"},{"title":"Go","link":"https:\/\/canuxcheng.com\/post\/go\/","pubDate":"Mon, 01 Jan 2018 10:49:21 +0000","guid":"https:\/\/canuxcheng.com\/post\/go\/","description":"<h1 id=\"go\u6982\u8ff0\">Go\u6982\u8ff0<\/h1>\n<p><a class=\"link\" href=\"https:\/\/golang.org\/ref\/spec\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/golang.org\/ref\/spec<\/a><\/p>\n<p>go\u8bed\u8a00\u8868\u8fbe\u80fd\u529b\u5f3a\uff0c\u7b80\u6d01\uff0c\u6e05\u6670\uff0c\u9ad8\u6548\uff0e<\/p>\n<p>go\u662f\u4e00\u4e2a\u5feb\u901f\u7684\uff0c\u9759\u6001\u7684\uff0c\u5f3a\u7c7b\u578b\u7684\uff0c\u7f16\u8bd1\u578b\u8bed\u8a00\uff0e<\/p>\n<p>go\u5177\u6709\u9ad8\u5e76\u53d1\u548c\u5783\u573e\u56de\u6536\u529f\u80fd.<\/p>\n<hr>\n<h1 id=\"go\u57fa\u672c\u8bed\u6cd5\">Go\u57fa\u672c\u8bed\u6cd5<\/h1>\n<p>go\u6e90\u7a0b\u5e8f\u53eb*.go<\/p>\n<p>go\u5927\u5c0f\u5199\u654f\u611f<\/p>\n<p>go\u7a0b\u5e8f\u90fd\u662f\u7531\u5305\u7ec4\u6210\uff0c\u7a0b\u5e8f\u7684\u5165\u53e3\u662fmain\u5305\u4e2d\u7684main\u51fd\u6570\uff0c\u6bcf\u4e2a\u7a0b\u5e8f\u6709\u4e14\u53ea\u6709\u4e00\u4e2a\uff0e<\/p>\n<p>go\u4e2d\u53ea\u6709\u9996\u5b57\u6bcd\u5927\u5199\u7684\u540d\u79f0\u624d\u80fd\u4ece\u5305\u4e2d\u5bfc\u51fa\uff0e<\/p>\n<p>go\u7684\u7c7b\u578b\u5728\u53d8\u91cf\u540d\u540e\u9762\uff0e<\/p>\n<p>go\u51fd\u6570\u5916\u7684\u6bcf\u4e2a\u8bed\u53e5\u90fd\u5fc5\u987b\u4ee5\u5173\u952e\u5b57\u5f00\u59cb.<\/p>\n<p>go\u6807\u8bc6\u7b26(\u51fd\u6570\u540d\uff0f\u53d8\u91cf\u540d\uff0f\u5e38\u91cf\u540d\uff0f\u7c7b\u578b\u540d\uff0f\u8bed\u53e5\u6807\u53f7\uff0f\u5305\u540d)\u4ee5\u5b57\u6bcd\u6216\u4e0b\u5212\u7ebf\u5f00\u5934\uff0c\u540e\u9762\u8fd8\u53ef\u4ee5\u5305\u542b\u6570\u5b57,\u4e0d\u80fd\u7528\u5173\u952e\u5b57.<\/p>\n<p>go\u4f7f\u7528\u5927\u62ec\u53f7{}\u8868\u793a\u4e00\u4e2a\u4ee3\u7801\u5757.<\/p>\n<p>go\u4f7f\u7528\u5206\u53f7;\u8868\u793a\u4e00\u4e2a\u8bed\u53e5\u7ed3\u675f, \u4e00\u822c\u4e00\u884c\u5199\u591a\u4e2a\u8bed\u53e5\u624d\u9700\u8981\u663e\u793a\u6dfb\u52a0\u5206\u53f7\uff0e<\/p>\n<p>go\u7684\u5305\u540d\u4e00\u822c\u662f\u5c0f\u5199\u7684\u5355\u4e2a\u5355\u8bcd(\u6587\u4ef6\u6240\u5728\u7684\u6700\u540e\u4e00\u5c42\u76ee\u5f55\u540d).<\/p>\n<p>go\u4e00\u822c\u4f7f\u7528\u9a7c\u5cf0\u547d\u540d\u6cd5.<\/p>\n<p>go\u6ca1\u6709\u9017\u53f7\u64cd\u4f5c\u7b26.<\/p>\n<p>go\u4e2d++\/&ndash;\u662f\u8bed\u53e5\u4e0d\u662f\u8868\u8fbe\u5f0f\uff0e<\/p>\n<p>go\u4e2d\u5927\u5199\u5b57\u6bcd\u5f00\u5934\u7684\u53d8\u91cf\u6216\u51fd\u6570\u662f\u516c\u6709\u7684\uff0c\u5c0f\u5199\u5b57\u6bcd\u5f00\u5934\u7684\u662f\u5305\u79c1\u6709\u7684.<\/p>\n<hr>\n<h1 id=\"go\u6ce8\u91ca\">Go\u6ce8\u91ca<\/h1>\n<p>\u5355\u884c\u6ce8\u91ca\uff1a<\/p>\n<pre><code>\/\/ comment\n<\/code><\/pre>\n<p>\u591a\u884c\u6ce8\u91ca\uff1a<\/p>\n<pre><code>\/* comment *\/\n<\/code><\/pre>\n<hr>\n<h1 id=\"go\u5173\u952e\u5b57\">Go\u5173\u952e\u5b57<\/h1>\n<pre><code>var const\nbreak continue for if else switch case default goto fallthrough\nfunc return defer\npackage import\nrange type struct map\ninterface\nselect go chan\n<\/code><\/pre>\n<hr>\n<h1 id=\"go\u8fd0\u7b97\u7b26\u548c\u4f18\u5148\u7ea7\">Go\u8fd0\u7b97\u7b26\u548c\u4f18\u5148\u7ea7<\/h1>\n<p>go\u4e2d\u7684\u8fd0\u7b97\u90fd\u662f\u4ece\u5de6\u5230\u53f3\u7ed3\u5408\uff0e<\/p>\n<pre><code>^ #\n! # \u903b\u8f91\u975e\n*\n\/ # \u7ed3\u679c\u53d6\u6574\u6570\n%\n&lt;&lt; # \u4f4d\u8fd0\u7b97\uff0c\u5de6\u79fb\n&gt;&gt; # \u4f4d\u8fd0\u7b97\uff0c\u53f3\u79fb\n&amp; # \u4f4d\u8fd0\u7b97\uff0c\u3000\u6309\u4f4d\u4e0e\n&amp;^ #\n+\n-\n| # \u4f4d\u8fd0\u7b97,\u6309\u4f4d\u6216\n^ # \u4f4d\u8fd0\u7b97,\u6309\u4f4d\u5f02\u6216\n==\n!=\n&lt;\n&lt;=\n&gt;\n&gt;=\n&lt;- # chan\u8fd0\u7b97\u7b26\n&amp;&amp; # \u903b\u8f91\u4e0e\n|| # \u903b\u8f91\u6216\n<\/code><\/pre>\n<hr>\n<h1 id=\"go\u6570\u636e\u7c7b\u578b\">Go\u6570\u636e\u7c7b\u578b<\/h1>\n<h2 id=\"\u53d8\u91cf\">\u53d8\u91cf<\/h2>\n<p>\u5b9a\u4e49\/\u7533\u660e\u53d8\u91cf:<\/p>\n<p>\u901a\u8fc7\u5173\u952e\u5b57var\u5728\u5305\u6216\u51fd\u6570\u4e2d\u7533\u660e\/\u5b9a\u4e49\u53d8\u91cf<\/p>\n<p>\u5728\u51fd\u6570\u6216\u5757\u4e2d\u5b9a\u4e49\u7684\u53d8\u91cf\u4f5c\u7528\u57df\u5c31\u662f\u5f53\u524d\u51fd\u6570\u6216\u5f53\u524d\u5757\u3002<\/p>\n<p>\u5728\u51fd\u6570\u5916\u90e8\u5b9a\u4e49\u7684\u5168\u5c40\u53d8\u91cf\u4f5c\u7528\u57df\u662f\u6574\u4e2a\u5305.<\/p>\n<p>\u5927\u5199\u5b57\u6bcd\u5f00\u5934\u7684\u5168\u5c40\u53d8\u91cf\u80fd\u88ab\u5176\u5b83\u5305\u5f15\u7528\u3002<\/p>\n<p>\u5168\u5c40\u53d8\u91cf\u5fc5\u987b\u4f7f\u7528var\u5173\u952e\u5b57\uff0e<\/p>\n<p>\u6ca1\u6709\u521d\u59cb\u5316\u7684\u53d8\u91cf\u5728\u7533\u660e\u7684\u65f6\u5019\u8d4b\u4e88\u96f6\u503c.<\/p>\n<p>\u5df2\u7ecf\u7533\u660e\u4f46\u6ca1\u6709\u4f7f\u7528\u7684\u53d8\u91cf\u5728\u7f16\u8bd1\u65f6\u4f1a\u62a5\u9519\uff0e<\/p>\n<p>\u901a\u8fc7\u7b49\u53f7\u7ed9\u53d8\u91cf\u8d4b\u503c\u5c31\u662f\u5b9a\u4e49\u53d8\u91cf.<\/p>\n<p>\u5927\u5199\u5b57\u6bcd\u5f00\u5934\u7684\u53d8\u91cf\u662fpublic, \u5c0f\u5199\u5b57\u6bcd\u5f00\u5934\u7684\u662fprivate\u53d8\u91cf.<\/p>\n<p>\u7533\u660e\u53d8\u91cf:<\/p>\n<pre><code># \u4e00\u4e2a\u53d8\u91cf\u4e00\u79cd\u7c7b\u578b\nvar varname Type\n# \u591a\u4e2a\u53d8\u91cf\u4e00\u79cd\u7c7b\u578b\nvar varname varname1 ... Type\n<\/code><\/pre>\n<p>\u5b9a\u4e49(\u521d\u59cb\u5316)\u53d8\u91cf:<\/p>\n<pre><code># \u5b9a\u4e49\u7684\u65f6\u5019\u521d\u59cb\u5316\nvar i, j int = 1, 2\n# \u521d\u59cb\u5316\u4f7f\u7528\u8868\u8fbe\u5f0f\u53ef\u4ee5\u7701\u7565\u7c7b\u578b\uff0c\u4ece\u503c\u4e2d\u83b7\u53d6\u7c7b\u578b\nvar i, j = true, &quot;str&quot;\n# \u591a\u4e2a\u53d8\u91cf\u591a\u79cd\u7c7b\u578b\nvar (\nvar1 Type1 = val1\nvar2 Type2 = val2\n# \u7ed9\u7c7b\u578b\u53d6\u522b\u540d\nvariable alias Type = value\n...\n)\n<\/code><\/pre>\n<p>\u7279\u6b8a\u53d8\u91cf\uff1a<\/p>\n<pre><code>_ # \u4e0b\u5212\u7ebf\u662f\u4e2a\u7279\u6b8a\u53d8\u91cf\u540d\uff0c\u7528\u4e8e\u5ffd\u7565\u4e00\u4e2a\u503c.\n<\/code><\/pre>\n<h2 id=\"\u5e38\u91cf\">\u5e38\u91cf<\/h2>\n<p>\u5b9a\u4e49\u5e38\u91cf\uff1a<\/p>\n<p>\u901a\u8fc7\u5173\u952e\u5b57const\u5728\u5305\u6216\u51fd\u6570\u4e2d\u5b9a\u4e49\u5e38\u91cf\uff0e<\/p>\n<pre><code># \u5e38\u91cf\u53ef\u4ee5\u662fbool, string, \u6570\u503c\nconst Pi float = 3.14\nconst World = &quot;China&quot;\nconst Truth = true\n# \u5b9a\u4e49\u591a\u4e2a\u5e38\u91cf\nconst (\nPi = 3.14\n...\n)\n<\/code><\/pre>\n<p>\u679a\u4e3e:<\/p>\n<pre><code># iota\u5185\u7f6e\u5e38\u91cf\u7528\u6765\u7edf\u8ba1\u679a\u4e3e\u4e2d\u7684\u884c\u6570\nconst (\ncon = val\n...\n)\n<\/code><\/pre>\n<p>\u5e38\u91cf\u4e0d\u80fd\u7528:=\u8bed\u6cd5\u6765\u7533\u660e\u3002<\/p>\n<h2 id=\"bool\">bool<\/h2>\n<p>bool\u7c7b\u578b\u53d8\u91cf\u7684\u96f6\u503c\u662ffalse.<\/p>\n<p>bool\u7c7b\u578b\u662f\u503c\u4f20\u9012\uff0e<\/p>\n<pre><code>true\nfalse\n<\/code><\/pre>\n<h2 id=\"\u6570\u503c\u7c7b\u578b\">\u6570\u503c\u7c7b\u578b<\/h2>\n<p>\u6570\u503c\u7c7b\u578b\u53d8\u91cf\u7684\u96f6\u503c\u662f0.<\/p>\n<p>\u6570\u503c\u7c7b\u578b\u662f\u503c\u4f20\u9012.<\/p>\n<p>\u6709\u7b26\u53f7\u7c7b\u578b\uff1a<\/p>\n<pre><code>int int8 int16 int32(rune) int64\n<\/code><\/pre>\n<p>\u65e0\u7b26\u53f7\u7c7b\u578b:<\/p>\n<pre><code>uint uint8(byte) uint16 uint32 uint64 uintptr\n<\/code><\/pre>\n<p>int, uint, uintptr \u572832\u4f4d\u7cfb\u7edf\u662f32bit, \u572864\u4f4d\u7cfb\u7edf\u662f64bit<\/p>\n<p>\u6d6e\u70b9\u7c7b\u578b\uff1a<\/p>\n<pre><code>float32\nfloat64\n<\/code><\/pre>\n<p>\u590d\u6570\u7c7b\u578b\uff1a<\/p>\n<pre><code>complex64\ncomplex128\n<\/code><\/pre>\n<h2 id=\"string\">string<\/h2>\n<p>string\u7c7b\u578b\u53d8\u91cf\u7684\u96f6\u503c\u662f&quot;&quot;.<\/p>\n<p>string\u7c7b\u578b\u662f\u503c\u4f20\u9012.<\/p>\n<p>go\u4e2d\u7684\u5b57\u7b26\u4e32\u90fd\u91c7\u7528utf-8\u7f16\u7801.<\/p>\n<p>go\u4e2d\u7684\u5b57\u7b26\u4e32\u7528\u53cc\u5f15\u53f7 \u6216\u8005\u3000\u53cd\u5f15\u53f7<\/p>\n<pre><code># \u5355\u884c\u5b57\u7b26\u4e32\nvar str string = &quot;hello&quot;\n# \u591a\u884c\u5b57\u7b26\u4e32(\u539f\u6837\u8f93\u51fa)\nvar str string = `hello\nworld`\nvar str = &quot;hello&quot; \/\/ \u7c7b\u578b\u53ef\u4ee5\u901a\u8fc7\u503c\u786e\u5b9a\n<\/code><\/pre>\n<p>go\u4e2d\u7684\u5b57\u7b26\u4e32\u662f\u4e0d\u53ef\u53d8\u7684, \u4fee\u6539\u5b57\u7b26\u4e32\uff1a<\/p>\n<pre><code># \u4f7f\u7528\u7c7b\u578b\u8f6c\u6362\nvar str string = &quot;hello&quot;\nc := []byte(str) # str\u8f6c\u6362\u6210 []byte \u7c7b\u578b\nc[index] = value # \u91cd\u65b0\u8d4b\u503c\nnewString := string(c) # []byte \u8f6c\u6362\u6210 string\n# \u4f7f\u7528\u7d22\u5f15\u8fd0\u7b97\ns := &quot;hello&quot;\ns = &quot;str&quot; + s[1:]\n<\/code><\/pre>\n<p>\u5b57\u7b26\u4e32\u8fd0\u7b97\uff1a<\/p>\n<pre><code>s1 := &quot;hello&quot;\ns2 := &quot;world&quot;\ns3 := s1 + s2\n<\/code><\/pre>\n<p>\u904d\u5386\u5b57\u7b26\u4e32\uff1a<\/p>\n<pre><code>for index, value := range s {...}\nfor index := range s {...}\nfor _, value := range s {...}\n<\/code><\/pre>\n<h2 id=\"\u7ed3\u6784\u4f53struct\">\u7ed3\u6784\u4f53\/struct<\/h2>\n<p>\u7ed3\u6784\u4f53\u5c31\u662f\u5b57\u6bb5\u7684\u96c6\u5408\uff0e\u7ed3\u6784\u4f53\u5b57\u6bb5\u901a\u8fc7\u70b9\u64cd\u4f5c\u7b26\u6765\u8bbf\u95ee\uff0e<\/p>\n<p>\u7ed3\u6784\u4f53\u662f\u503c\u4f20\u9012.<\/p>\n<p>\u7533\u660e\u4e00\u4e2a\u7ed3\u6784\u4f53\u7c7b\u578b\uff1a<\/p>\n<pre><code>type StructName struct {\nvar Type\nvar1 Type1\n...\n}\n<\/code><\/pre>\n<p>\u7533\u660e\u591a\u4e2a\u7ed3\u6784\u4f53\u7c7b\u578b:<\/p>\n<pre><code>type (\nStructB struct {\n...\n}\nStructB struct {\n}\n)\n<\/code><\/pre>\n<p>\u7533\u660e\u4e00\u4e2a\u7ed3\u6784\u4f53\u7c7b\u578b\u7684\u53d8\u91cf<\/p>\n<pre><code>var s StructName\n<\/code><\/pre>\n<p>\u5b9a\u4e49\u7ed3\u6784\u4f53\u53d8\u91cf:<\/p>\n<pre><code># \u5217\u51fa\u5168\u90e8\u5b57\u6bb5\nvar s = StructName{val, ...}\ns := StructName{val, ...}\n# \u4f7f\u7528val: \u53ef\u4ee5\u4ec5\u5217\u51fa\u90e8\u5206\u5b57\u6bb5, \u672a\u5217\u51fa\u7684\u5b57\u6bb5\u4f7f\u7528\u9ed8\u8ba4\u503c\nvar s = StructName{\nvar: val,\n...\n}\ns := StructName{\nvar: val,\n...\n}\n# \u7ed9\u5b57\u6bb5\u8d4b\u503c\ns.var1 = value\n<\/code><\/pre>\n<p>\u7ed3\u6784\u4f53\u6307\u9488:<\/p>\n<pre><code>type StructName struct {\nvar Type\nvar1 Type1\n}\nvar s = &amp;StructName{}\ns := &amp;StructName{}\n(*s).Var1 = val1\ns.Var1 = val1 \/\/ go\u5141\u8bb8\u9690\u58eb\u95f4\u63a5\u5f15\u7528\ns := StructName{val, val1}\np := &amp;s\n# \u539f\u672c\u5e94\u8be5\u901a\u8fc7(*p).var\u6765\u8bbf\u95ee\uff0cgo\u5141\u8bb8\u9690\u5f0f\u95f4\u63a5\u5f15\u7528\uff0e\np.var = p.var1\n<\/code><\/pre>\n<h2 id=\"\u6307\u9488pointer\">\u6307\u9488\/pointer<\/h2>\n<p>\u6307\u9488\u7684\u96f6\u503c\u4e3anil.<\/p>\n<p>go\u7684\u6307\u9488\u4fdd\u5b58\u4e86\u503c\u7684\u5185\u5b58\u5730\u5740, go\u6ca1\u6709\u6307\u9488\u8fd0\u7b97\uff0e<\/p>\n<p>\u901a\u8fc7\u6307\u9488\u5b9e\u73b0\u5f15\u7528\u4f20\u9012.<\/p>\n<p>\u7533\u660e\u4e00\u4e2a\u6307\u9488\u53d8\u91cf\uff1a<\/p>\n<pre><code>var point *int\n<\/code><\/pre>\n<p>&amp;\u64cd\u4f5c\u7b26\u4f1a\u751f\u6210\u4e00\u4e2a\u6307\u5411\u5176\u64cd\u4f5c\u6570\u7684\u6307\u9488(\u4fdd\u5b58\u53d8\u91cf\u7684\u5730\u5740)\uff1a<\/p>\n<pre><code>point = &amp;variable\n<\/code><\/pre>\n<p>*\u64cd\u4f5c\u7b26\u8868\u793a\u6307\u9488\u6307\u5411\u7684\u6570\u503c(\u8bfb\u5199\u8be5\u5730\u5740\u4fdd\u5b58\u7684\u503c\uff1a<\/p>\n<pre><code>*point = value\n<\/code><\/pre>\n<h2 id=\"\u6570\u7ec4array\">\u6570\u7ec4\/array<\/h2>\n<p>\u6570\u7ec4\u901a\u8fc7\u4e0b\u6807\u6765\u8bbf\u95ee\uff0e\u6570\u7ec4\u4e0d\u80fd\u6539\u53d8\u5927\u5c0f\uff08\u957f\u5ea6\uff09<\/p>\n<p>\u6570\u7ec4\u662f\u503c\u4f20\u9012\uff0e<\/p>\n<p>\u6570\u7ec4\u7684\u5c5e\u6027\u6709\u7c7b\u578b\u548c\u957f\u5ea6,\u53ea\u6709\u957f\u5ea6\u548c\u7c7b\u578b\u90fd\u76f8\u540c\u7684\u624d\u662f\u540c\u7c7b\u578b\u6570\u7ec4,\u624d\u80fd\u76f8\u4e92\u8d4b\u503c.<\/p>\n<p>\u6570\u7ec4\u957f\u5ea6\u548c\u5bb9\u91cf\u76f8\u540c\uff0e<\/p>\n<p>\u7533\u660e\u6570\u7ec4:<\/p>\n<pre><code>var ArrayName [number]Type\n<\/code><\/pre>\n<p>\u5b9a\u4e49\u6570\u7ec4\uff1a<\/p>\n<pre><code>var ArrayName = [number]Type{}\nArrayName := [number]Type{val, val1, ...}\nArrayName := [number]Type{index: value, ...} \/\/ \u7ed9\u6307\u5b9a\u7d22\u5f15\u8d4b\u503c,\u5176\u4f59\u4e3a\u96f6\u503c\nArrayName := []Type{val, ...} \/\/ \u5bb9\u91cf\u4e5f\u53ef\u4ee5\u7531\u521d\u59cb\u5316\u7684\u5143\u7d20\u4e2a\u6570\u51b3\u5b9a.\nArrayName := [number]*Type{0: new(int), 1: new(string), ...} \/\/ \u6307\u9488\u6570\u7ec4\n<\/code><\/pre>\n<p>\u6570\u7ec4\u5143\u7d20\u8d4b\u503c\uff1a<\/p>\n<pre><code>ArrayName[0] = val\n*ArrayName[0] = val \/\/ \u6307\u9488\u6570\u7ec4\n<\/code><\/pre>\n<p>\u6570\u7ec4\u8d4b\u503c\uff08\u503c\u4f20\u9012\uff09\uff1a<\/p>\n<pre><code># \u53ea\u6709\u7c7b\u578b\u548c\u957f\u5ea6\u76f8\u540c\u7684\u6570\u7ec4\u624d\u80fd\u8d4b\u503c\n# \u975e\u6307\u9488\u6570\u7ec4\u8d4b\u503c\uff0c\u4f1a\u53e6\u5916\u5f00\u8f9f\u5730\u5740\u7a7a\u95f4.\n# \u4fee\u6539newArray\u7684\u503c\uff0c\u4e0d\u4f1a\u6539\u53d8ArrayName\u7684\u503c\nnewArray = ArrayName\n# \u6307\u9488\u7c7b\u578b\u7684\u6570\u7ec4\u8d4b\u503c\uff0c\u6307\u5411\u7684\u662f\u76f8\u540c\u7684\u5730\u5740.\n<\/code><\/pre>\n<p>\u591a\u7ef4\u6570\u7ec4(\u5d4c\u5957\u6570\u7ec4):<\/p>\n<pre><code>doubleArray := [2][4]int{[4]int{1, 2, 3, 4}, [4]int{5, 6 7, 8}}\n<\/code><\/pre>\n<p>\u904d\u5386\u6570\u7ec4\uff1a<\/p>\n<pre><code>for index, value := range a {\nfmt.Println('%d, %d\\n', index, value)\n}\n# \u53ea\u8981\u7d22\u5f15, \u53bb\u6389,value\u5373\u53ef\nfor index := range a {...}\n# \u53ea\u8981\u503c\uff0c\u7528_\u5ffd\u7565\u7d22\u5f15\nfor _, value := range a {...}\n<\/code><\/pre>\n<h2 id=\"\u5207\u7247slice\">\u5207\u7247\/slice<\/h2>\n<p>\u5207\u7247\u7684\u96f6\u503c\u662fnil, nil\u5207\u7247\u7684\u957f\u5ea6\u548c\u5bb9\u91cf\u90fd\u662f\uff10\uff0c\u4e14\u6ca1\u6709\u5e95\u5c42\u6570\u7ec4\uff0e<\/p>\n<p>\u5207\u7247\u4f20\u9012\u7684\u662f\u5730\u5740(\u5f15\u7528\u4f20\u9012),\u4fee\u6539\u5207\u7247\u7684\u5143\u7d20\u503c\u5176\u5b9e\u5c31\u662f\u4fee\u6539\u5e95\u5c42\u6570\u7ec4\u7684\u5bf9\u5e94\u7684\u5143\u7d20\u7684\u503c,\u5171\u4eab\u8be5\u5143\u7d20\u7684\u5176\u5b83\u5207\u7247\u7684\u503c\u4e5f\u76f8\u5e94\u6539\u53d8\uff0e<\/p>\n<p>\u5207\u7247\u7684\u5c5e\u6027\u5305\u62ec\u6307\u5411\u5e95\u5c42\u6570\u7ec4\u7684\u6307\u9488\uff0c\u5207\u7247\u7684\u957f\u5ea6\uff0c\u5207\u7247\u7684\u5bb9\u91cf.<\/p>\n<p>\u5207\u7247\u4e0d\u5b58\u50a8\u6570\u636e\uff0c\u53ea\u662f\u63cf\u8ff0\u6570\u7ec4\u7684\u4e00\u6bb5,\u56e0\u6b64\u5207\u7247\u4e0d\u6307\u5b9a\u5927\u5c0f\uff08\u957f\u5ea6\uff09.<\/p>\n<pre><code># \u8868\u793a\u5207\u7247\u7c7b\u578b\n[]Type\n<\/code><\/pre>\n<p>\u7533\u660e\u5207\u7247:<\/p>\n<pre><code>var SliceName []Type\n<\/code><\/pre>\n<p>\u5b9a\u4e49\u5207\u7247\uff1a<\/p>\n<pre><code>\/\/ \u901a\u8fc7\u5b57\u9762\u91cf\u5b9a\u4e49\nvar SliceName = []Type{}\nSliceName := []Type{val, val1, ...}\nSliceName := []Type{index: value} \/\/ \u7d22\u5f15\u5c31\u8868\u793a\u957f\u5ea6\u548c\u5bb9\u91cf\n\/\/ \u901a\u8fc7make\u51fd\u6570\u521b\u5efa\u5207\u7247\nvar SliceName = make([]type, len, cap)\nSliceName := make([]Type, len, cap)\n<\/code><\/pre>\n<p>\u901a\u8fc7\u5207\u7247\u5b9a\u4e49\u65b0\u5207\u7247:<\/p>\n<pre><code>\u5207\u7247\u7684\u64cd\u4f5c\u8fd4\u56de\u65b0\u7684\u5207\u7247\u3002\nNewS := SName[i:j]\ncap(SName) = k\nNewS \u957f\u5ea6\u548c\u5bb9\u91cf\uff1a\nlen = j-i\ncap = k-i\nNewS \u65e0\u6cd5\u8bbf\u95ee\u6307\u5411\u7684\u5e95\u5c42\u6570\u7ec4\u7b2c\u4e00\u4e2a\u5143\u7d20\u4e4b\u524d\u7684\u5143\u7d20\u3002\n\u4e5f\u4e0d\u80fd\u8bbf\u95ee\u8d85\u51fa\u957f\u5ea6\u4e4b\u540e\u7684\u7d22\u5f15,\u4f46\u662f\u53ef\u4ee5\u901a\u8fc7append\u589e\u52a0\u5207\u7247\u957f\u5ea6\u4e4b\u540e\u8bbf\u95ee.\nNewS[index] \/\/\u5f53index &gt;= j\u7f16\u8bd1\u5668\u62a5\u9519 \uff0c\u8d85\u51fa\u4e86NewS \u7684\u957f\u5ea6\uff0c\u65e0\u6cd5\u8bbf\u95ee\u3002\n<\/code><\/pre>\n<p>\u4e09\u7d22\u5f15\u64cd\u4f5c:<\/p>\n<pre><code>NewS := SName[i:j:k]\n\u4e09\u7d22\u5f15\u8868\u793a\u5bb9\u91cf\uff0c i:j \u8868\u793a\u957f\u5ea6\uff0c i:k \u8868\u793a\u5bb9\u91cf.\n\u5bb9\u91cf\u4e0d\u80fd\u8d85\u8fc7\u53ef\u7528\u5bb9\u91cf(\u4e5f\u5c31\u662fSName\u7684\u5bb9\u91cf).\n<\/code><\/pre>\n<p>\u5207\u7247\u64cd\u4f5c\uff1a<\/p>\n<pre><code># \u534a\u5f00\u533a\u95f4\uff0c\u4e0d\u5305\u62ec\u6700\u540e\u4e00\u4e2a\u4e0b\u6807\ns[low:high]\ns[:high] \/\/ low=0, default\ns[low:] \/\/ high=max, default\ns[:] \/\/ s[0:max], default\ns[:0] \/\/ \u628a\u5207\u7247\u7684\u957f\u5ea6\u53d8\u4e3a\uff10\uff08\u6e05\u7a7a\u5207\u7247)\ns[:4] \/\/ \u6269\u5c55\u4e3a\uff14\ns[2:] \/\/ \u6269\u5c55\u4e3a arrayname[2:4]\n<\/code><\/pre>\n<p>\u4e8c\u7ef4\u5207\u7247\uff1a<\/p>\n<pre><code>[][]Type\n<\/code><\/pre>\n<p>\u904d\u5386\u5207\u7247\uff1a<\/p>\n<pre><code># \u5207\u7247\u904d\u5386\u548c\u6570\u7ec4\u76f8\u540c\nfor index, value := range s {\n...\n}\nfor index := range s {...}\nfor _, value := range s {...}\n<\/code><\/pre>\n<p>slice\u4f5c\u4e3a\u51fd\u6570\u53c2\u6570:<\/p>\n<pre><code>\u5207\u7247\u4f5c\u4e3a\u51fd\u6570\u53c2\u6570\uff0c\u4f20\u9012\u7684\u5176\u5b9e\u662f\u503c,\u51fd\u6570\u4f1a\u4f7f\u7528\u548c\u5207\u7247\u76f8\u540c\u7684\u5e95\u5c42\u6570\u7ec4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5207\u7247\u6765\u64cd\u4f5c.\n\u6240\u4ee5\u51fd\u6570\u5185\u90e8\u4fee\u6539\u4e86\u5207\u7247\u7684\u503c,\u4f5c\u4e3a\u53c2\u6570\u7684\u5207\u7247\u7684\u503c\u4e5f\u88ab\u4fee\u6539\u4e86.\n<\/code><\/pre>\n<h2 id=\"\u6620\u5c04map\">\u6620\u5c04\/map<\/h2>\n<p>\u6620\u5c04\u7684\u96f6\u503c\u662fnil, \u65e2\u6ca1\u6709\u952e\uff0c\u4e5f\u4e0d\u80fd\u6dfb\u52a0\u952e\uff0e<\/p>\n<p>map\u662f\u5f15\u7528\u4f20\u9012\uff0e\u662f\u5b58\u50a8\u952e\u503c\u5bf9\u7684\u65e0\u5e8f\u96c6\u5408.<\/p>\n<p>map\u662f\u65e0\u5e8f\u7684\uff0c\u53ea\u80fd\u901a\u8fc7key\u7d22\u5f15\uff0c\u6ca1\u6709\u4e0b\u6807\u64cd\u4f5c.<\/p>\n<p>map\u7684key\u9700\u8981\u652f\u6301==\u6216!= \u8fd0\u7b97\uff0c\u4e0d\u80fd\u662f\u51fd\u6570\uff0c\u6620\u5c04\uff0c\u5207\u7247<\/p>\n<p>\u7533\u660e:<\/p>\n<pre><code>\/\/ \u7533\u660e\u503c\u4e3anil\u7684\u7a7a\u6620\u5c04\uff0c\u4e0d\u80fd\u7528\u4e8e\u5b58\u50a8\u952e\u503c\u5bf9.\nvar MapName map[keyType]ValueType\n<\/code><\/pre>\n<p>\u5b9a\u4e49\u6620\u5c04\uff1a<\/p>\n<pre><code>var MapName = map[keyType]ValueType{}\nvar MapName = map[keyType]ValueType{\nkey: value,\n...\n}\nMapName := map[keyType]valueType{}\nMapName := map[KeyType]ValueType{\n&quot;key&quot;: value,\n...\n}\n# \u901a\u8fc7make\u5b9a\u4e49map\nvar MapName = make(map[keyType]ValueType, cap)\nMapName := make(map[keyType]ValueType, cap)\n<\/code><\/pre>\n<p>\u6620\u5c04\u64cd\u4f5c\uff1a<\/p>\n<pre><code>m[key] = value\nvalue = m[key]\n# \u82e5key\u5728m\u4e2dok\u4e3atrue, \u5426\u5219\u4e3afalse, \u4e14value\u662f\u5bf9\u5e94\u7c7b\u578b\u7684\u96f6\u503c\nvalue, ok := m[key]\n<\/code><\/pre>\n<p>\u904d\u5386\u6620\u5c04\uff1a<\/p>\n<pre><code>for key, value := range m {...}\nfor key := range m {...}\nfor _, value := range m {...}\n<\/code><\/pre>\n<p>map\u4f5c\u4e3a\u51fd\u6570\u53c2\u6570:<\/p>\n<pre><code>\u4e0d\u4f1a\u521b\u5efa\u8be5\u6620\u5c04\u7684\u526f\u672c\uff0c\u8be5\u51fd\u6570\u5bf9\u6620\u5c04\u7684\u4fee\u6539\u5c31\u662f\u5bf9\u539f\u59cb\u53c2\u6570\u6307\u5411\u7684\u6620\u5c04\u7684\u4fee\u6539.\n<\/code><\/pre>\n<h2 id=\"\u7c7b\u578b\u8f6c\u6362\">\u7c7b\u578b\u8f6c\u6362<\/h2>\n<p>go\u4e2d\u517c\u5bb9\u7684\u7c7b\u578b\u624d\u80fd\u8f6c\u6362\uff0c\u800c\u4e14\u5fc5\u987b\u663e\u793a\u8f6c\u6362\uff0e<\/p>\n<pre><code>ValueA [:]= TypeA(ValueB)\nfloatA := float64(uint64Var)\n<\/code><\/pre>\n<h2 id=\"\u603b\u7ed3\">\u603b\u7ed3<\/h2>\n<p>\u503c\u4f20\u9012pass by value\uff1abool, number, string, struct, array, interface<\/p>\n<p>\u5f15\u7528\u4f20\u9012pass by reference\uff1a slice, map, function, channel<\/p>\n<p>zero value:<\/p>\n<ul>\n<li>struct, array \u53d6\u51b3\u4e8e\u5143\u7d20\u7c7b\u578b<\/li>\n<li>pointer, slice, map, channel, function, interface: nil<\/li>\n<\/ul>\n<p>&amp;: address of operator, used to get memory address. \u5730\u5740\u64cd\u4f5c\u3002\n*: dereference or pointer type. \u89e3\u5f15\u7528 \u6216 \u6307\u9488\u7c7b\u578b\u3002<\/p>\n<p>explicit(\u663e\u5f0f) is better than implicit\uff08\u9690\u5f0f\uff09\u3002<\/p>\n<hr>\n<h1 id=\"go\u63a7\u5236\u6d41\">Go\u63a7\u5236\u6d41<\/h1>\n<p>go\u63a7\u5236\u6d41\u7684\u5de6\u5927\u62ec\u53f7\u4e0d\u80fd\u53e6\u8d77\u4e00\u884c\uff0e<\/p>\n<p>golang\u6ca1\u6709\u5185\u7f6e\u7684while\u5faa\u73af\u3002<\/p>\n<h2 id=\"for\u5faa\u73af\">for\u5faa\u73af<\/h2>\n<p>go\u53ea\u6709for\u53ef\u4ee5\u5faa\u73af\uff0e<\/p>\n<pre><code>for i := 0; i &lt; 10; i++ {\nsum += i\n}\n<\/code><\/pre>\n<p>for\u5faa\u73af\u6709\u4e09\u79cd\u6a21\u5f0f\uff1a<\/p>\n<p>for\u5faa\u73af\u540e\u9762\u6ca1\u6709\u5c0f\u62ec\u53f7\uff0c\u4ee3\u7801\u5757\u5fc5\u987b\u8981\u5927\u62ec\u53f7\uff0e<\/p>\n<pre><code>for init; condition; statement {\n...\n}\n<\/code><\/pre>\n<p>for\u5faa\u73af\u7684\u521d\u59cb\u5316\u8bed\u53e5init\u548c\u540e\u7f6e\u8bed\u53e5statement\u53ef\u4ee5\u7701\u7565,\u76f8\u5f53\u4e8ewhile\uff0e<\/p>\n<pre><code>for condition {\n...\n}\n<\/code><\/pre>\n<p>\u65e0\u9650\u5faa\u73af, \u76f8\u5f53\u4e8efor(;;)\uff1a<\/p>\n<pre><code>for {\n...\n}\n<\/code><\/pre>\n<h2 id=\"if\u6761\u4ef6\u8bed\u53e5\">if\u6761\u4ef6\u8bed\u53e5<\/h2>\n<p>if\u540e\u9762\u7684\u5c0f\u62ec\u53f7\u4e0d\u8981\uff0c\u4f46\u662f\u4ee3\u7801\u5757\u9700\u8981\u5927\u62ec\u53f7\uff0e<\/p>\n<pre><code>if condition {\n...\n} else if condition {\n...\n} else {\n...\n}\n<\/code><\/pre>\n<h2 id=\"switch\u6761\u4ef6\u8bed\u53e5\">switch\u6761\u4ef6\u8bed\u53e5<\/h2>\n<p>go\u4e2d\u7684switch-case\u7684variable\u65e0\u9700\u4e3a\u5e38\u91cf\uff0c\u4e14\u53d6\u503c\u53ef\u4ee5\u4e0d\u662f\u6574\u6570\uff0e<\/p>\n<p>go\u4e2d\u7684\u53ea\u6267\u884c\u5339\u914d\u7684case\uff0c\u76f8\u5f53\u4e8e\u9ed8\u8ba4\u5728\u6bcf\u4e2acase\u540e\u9762\u52a0\u4e86break\u8bed\u53e5\uff0e<\/p>\n<p>case\u5339\u914d\u5230\u7684\u8bed\u53e5\u5982\u679c\u53ea\u6709\u4e00\u884c\u53ef\u4ee5\u548ccase\u8bed\u53e5\u5199\u5728\u540c\u4e00\u884c<\/p>\n<pre><code>switch variable {\ncase value1:\n...\ncase value2: expression\ndefault:\n...\n}\n<\/code><\/pre>\n<p>\u591a\u4e2a\u6761\u4ef6\u53ef\u4ee5\u653e\u5230\u4e00\u4e2acase:<\/p>\n<pre><code>switch variable {\ncase value1, value2, ...: expression\ncase valuen: fallthrough\ndefalut:\n...\n}\n<\/code><\/pre>\n<p>\u6ca1\u6709\u6761\u4ef6\u7684switch-case<\/p>\n<pre><code>switch {\ncase condition:\n...\n...\n}\n<\/code><\/pre>\n<p>\u5982\u679c\u4e0d\u9700\u8981\u9ed8\u8ba4\u7684break,\u9700\u8981\u6dfb\u52a0fallthrough:<\/p>\n<p>fallthrough\u4e0d\u4f1a\u5224\u65ad\u540e\u9762\u7684case\u7684condition,\u800c\u662f\u76f4\u63a5\u6267\u884c\u540e\u9762\u6240\u6709\u7684case.<\/p>\n<pre><code>switch variable {\ncase val1:\n...\nfallthrough\n...\n}\n<\/code><\/pre>\n<h2 id=\"label\">label<\/h2>\n<p>golang\u7684label\u4e0d\u9700\u8981\u7f29\u8fdb:<\/p>\n<pre><code>LabelName:\n<\/code><\/pre>\n<h2 id=\"break\">break<\/h2>\n<p>break\u7528\u4e8e\u8df3\u51fafor\/switch\/select\u5faa\u73af.<\/p>\n<pre><code>break\n<\/code><\/pre>\n<p>break\u4e5f\u652f\u6301label:<\/p>\n<p>break\u7684label\u53ef\u4ee5\u8df3\u51fa\u5916\u5c42\u5faa\u73af.<\/p>\n<pre><code>break [tag]\nlabel:\nfor i := 0; i &lt; 1000; i++ {\nfor j :=0; j &lt; 1000; j++ {\nif j &lt; i {\nbreak label \/\/ \u8df3\u51fa\u6700\u5916\u5c42\u5faa\u73af.\n}\n}\n}\n<\/code><\/pre>\n<h2 id=\"continue\">continue<\/h2>\n<p>continue\u8bed\u53e5\u53ea\u80fd\u5728for\u5faa\u73af\u4e2d\u4f7f\u7528<\/p>\n<pre><code>continue\n<\/code><\/pre>\n<p>continue\u4e5f\u652f\u6301label:<\/p>\n<p>continue\u7684label\u53ef\u4ee5\u4ece\u5916\u5c42\u5faa\u73af\u7ee7\u7eed\u6267\u884c.<\/p>\n<pre><code>continue [tag]\nnext:\nfor outer := 2; outer &lt; 3000; outer++ {\nfor inner :=2; inner &lt; outer; inner++ {\nif outer%inner == 0 {\ncontinue next \/\/ \u5e76\u975e\u7ee7\u7eed\u5185\u5b58\u5faa\u73af\uff0c\u800c\u662f\u4ece\u5916\u5c42\u5faa\u73af\u7ee7\u7eed\u6267\u884c.\n}\n}\n}\n<\/code><\/pre>\n<h2 id=\"goto\">goto<\/h2>\n<p>goto\u8df3\u8f6c\u8bed\u53e5\uff0c\u8df3\u8f6c\u5230\u6307\u5b9a\u6807\u7b7e\u8fd0\u884c\uff0e<\/p>\n<p>\u6807\u7b7e\u533a\u5206\u5927\u5c0f\u5199.<\/p>\n<pre><code>Label:\nexpression\n...\ngoto Label\ncontinue LABEL\nbreak LABEL\n...\n<\/code><\/pre>\n<hr>\n<h1 id=\"go\u51fd\u6570\">Go\u51fd\u6570<\/h1>\n<p>\u51fd\u6570\u7684\u96f6\u503c\u662fnil.<\/p>\n<p>\u51fd\u6570\u662f\u5f15\u7528\u7c7b\u578b.<\/p>\n<p>\u5927\u5199\u5b57\u6bcd\u5f00\u5934\u7684\u51fd\u6570\u662fpublic, \u5c0f\u5199\u5b57\u6bcd\u5f00\u5934\u7684\u662fprivate.<\/p>\n<p>\u521b\u5efa\u51fd\u6570\uff1a<\/p>\n<pre><code>func FuncName(var Type, var1 Type1) rType {\n...\nreturn ...\n}\n<\/code><\/pre>\n<p>\u591a\u503c\u8fd4\u56de\uff1a<\/p>\n<pre><code>func FuncName(var Type) (rType, rType1, ...) {\n...\nreturn ...\n}\n<\/code><\/pre>\n<p>\u547d\u540d\u8fd4\u56de\u503c(\u5fc5\u987b\u7528\u62ec\u53f7)\uff1a<\/p>\n<pre><code>\/\/ \u4e00\u822creturn\u540e\u9762\u4e0d\u5e26\u8fd4\u56de\u503c\uff0c\u5426\u5219\u9700\u8981\u8fd4\u56de\u5b9a\u4e49\u7684\u6240\u6709\u53d8\u91cf\nfunc FuncName(var Type) (rvar rType, rvar1 rType) {\n...\nrvar = ...\nrvar1 = ...\nreturn\n}\n<\/code><\/pre>\n<p>\u591a\u4e2a\u53d8\u91cf\u7c7b\u578b\u76f8\u540c\u65f6\u4fdd\u7559\u6700\u540e\u4e00\u4e2a\u7684\u7c7b\u578b\u5373\u53ef\uff1a<\/p>\n<pre><code>func FuncName(var, var1 Type) (rvar, rvar1 rType) {\n...\nreturn ...\n}\n<\/code><\/pre>\n<p>\u53d8\u91cf\u4f5c\u7528\u57df\uff1a<\/p>\n<pre><code>\u51fd\u6570\u5185\u90e8\u5b9a\u4e49\u7684\u53d8\u91cf\u662f\u5c40\u90e8\u53d8\u91cf\n\u51fd\u6570\u5916\u5b9a\u4e49\u7684\u53d8\u91cf\u662f\u5168\u5c40\u53d8\u91cf\uff0e\n\u5c40\u90e8\u53d8\u91cf\u4f18\u5148\u4f7f\u7528\uff0e\n<\/code><\/pre>\n<p>\u5f62\u5f0f\u53c2\u6570\uff1a<\/p>\n<pre><code>\u5f62\u5f0f\u53c2\u6570\u7684\u4f5c\u7528\u57df\u8303\u56f4\u548c\u51fd\u6570\u4f53\u4e2d\u7684\u5c40\u90e8\u53d8\u91cf\u4e00\u81f4\uff0e\n<\/code><\/pre>\n<p>\u8fd4\u56de\u503c\uff1a<\/p>\n<pre><code>\u51fd\u6570\u8fd4\u56de\u503c\u7684\u4f5c\u7528\u57df\u8303\u56f4\u548c\u51fd\u6570\u4f53\u4e2d\u7684\u5c40\u90e8\u53d8\u91cf\u4e00\u81f4\uff0e\n<\/code><\/pre>\n<p>\u5b9e\u9645\u53c2\u6570\uff1a<\/p>\n<pre><code>\u5b9e\u9645\u53c2\u6570\u53ef\u4ee5\u662f\u503c\u4f20\u9012\uff0c\u4e5f\u53ef\u4ee5\u662f\u5f15\u7528\u4f20\u9012\uff0e\n<\/code><\/pre>\n<p>\u6307\u9488\u53c2\u6570\uff1a<\/p>\n<pre><code># \u5b9e\u53c2\u5fc5\u987b\u662f\u6307\u9488\u624d\u80fd\u8c03\u7528\u8be5\u51fd\u6570\nfunc FuncName(v *Type) rType {\n...\n}\n<\/code><\/pre>\n<p>\u51fd\u6570\u4e2d\u77ed\u53d8\u91cf\u7533\u660e(\u5c40\u90e8\u53d8\u91cf):<\/p>\n<pre><code># \u5728\u51fd\u6570\u5185\u90e8\uff0c\u660e\u786e\u503c\u7684\u7c7b\u578b\u7684\u60c5\u51b5\u4e0b\u53ef\u4ee5\u7528 := \u4ee3\u66ffvar\u5173\u952e\u5b57\u5b9a\u4e49\u53d8\u91cf\nfunc FuncName() {\nvariable := value\nvar1, var2, ... := val1, val2, ...\n}\n<\/code><\/pre>\n<p>\u91cd\u590d\u7533\u660e\u77ed\u53d8\u91cf\uff1a<\/p>\n<pre><code>\u672c\u6b21\u7533\u660e\u4e0e\u5df2\u7533\u660e\u7684\u53d8\u91cf\u5728\u540c\u4e00\u4f5c\u7528\u57df\uff0e\n\u5728\u521d\u59cb\u5316\u4e2d\u4e0e\u5df2\u7533\u660e\u7684\u53d8\u91cf\u7c7b\u578b\u76f8\u540c\u624d\u80fd\u8d4b\u503c\uff0e\n\u672c\u6b21\u7533\u660e\u4e2d\u81f3\u5c11\u53e6\u6709\u4e00\u4e2a\u53d8\u91cf\u662f\u65b0\u7533\u660e\u7684\uff0e\n<\/code><\/pre>\n<p>defer\u5173\u952e\u5b57\uff1a<\/p>\n<p>defer\u4f1a\u5c06\u51fd\u6570\u63a8\u8fdf\u5230\u5916\u5c42\u51fd\u6570\u8fd4\u56de\u4e4b\u540e\u6267\u884c.<\/p>\n<p>\u63a8\u8fdf\u8c03\u7528\u7684\u51fd\u6570\u5176\u53c2\u6570\u4f1a\u7acb\u5373\u6c42\u503c\uff0c\u7136\u540e\u538b\u5165defer\u6808\u4e2d,\u5916\u5c42\u51fd\u6570\u8fd4\u56de\u540e\u6309\u7167\u540e\u8fdb\u5148\u51fa\u7684\u987a\u5e8f\u8c03\u7528\uff0e<\/p>\n<pre><code>func FuncOut() {\n...\ndefer FuncName()\n...\n}\n<\/code><\/pre>\n<p>\u51fd\u6570\u4e5f\u662f\u503c\uff0c\u4e5f\u53ef\u4ee5\u4f20\u9012\uff0c\u53ef\u4ee5\u7528\u4f5c\u51fd\u6570\u7684\u53c2\u6570\u6216\u8fd4\u56de\u503c\uff1a<\/p>\n<pre><code>func FuncName(variable func(Type, ...) rType) rType {\n...\n}\nFuncName := func(variable Type, ...) rType {\n..\n}\n<\/code><\/pre>\n<p>\u533f\u540d\u51fd\u6570:<\/p>\n<pre><code>func(&lt;arguments&gt;) (returns) {}()\n<\/code><\/pre>\n<p>\u53ef\u53d8\u53c2\u6570:<\/p>\n<pre><code>func FuncName(vars ...Type) rType {}\nFuncName(vars..)\n<\/code><\/pre>\n<p>closures\/\u95ed\u5305:<\/p>\n<p>init\u51fd\u6570:<\/p>\n<pre><code># \u6bcf\u4e2a\u5305\u4e2d\u53ef\u4ee5\u6709\u4efb\u610f\u4e2ainit\u51fd\u6570.\n# \u8fd9\u4e9binit\u51fd\u6570\u4f1a\u5728main\u51fd\u6570\u6267\u884c\u4e4b\u524d\u8c03\u7528.\n# init\u51fd\u6570\u4e0d\u80fd\u6709\u53c2\u6570\u548c\u8fd4\u56de\u503c\n# main\u4e2d\u7684init\u6700\u540e\u8c03\u7528.\nfunc init() {}\n<\/code><\/pre>\n<hr>\n<h1 id=\"go\u6587\u4ef6\u548c\u8f93\u5165\u8f93\u51fa\">Go\u6587\u4ef6\u548c\u8f93\u5165\u8f93\u51fa<\/h1>\n<p>go\u7684\u6807\u51c6\u5e93fmt\u5b9e\u73b0\u4e86\u7c7b\u4f3c\u4e8eC\u8bed\u8a00\u7684printf\u548cscanf\u683c\u5f0f\u5316I\/O\u51fd\u6570.<\/p>\n<p>\u8fd8\u6709io\u548cbufio\u6807\u51c6\u5e93\u53ef\u7528<\/p>\n<h2 id=\"\u8f93\u5165\">\u8f93\u5165<\/h2>\n<p>\u8f93\u5165\u7684\u672c\u8d28\u5c31\u662f\u4eceStdin\u8bfb\u53d6<\/p>\n<p>fmt:<\/p>\n<pre><code>var input string\nfmt.Scan*(&amp;input)\n<\/code><\/pre>\n<p>bufio.Reader:<\/p>\n<pre><code>inputReader := bufio.NewReader(os.Stdin)\ninputReader.Read*()\n<\/code><\/pre>\n<h2 id=\"\u8f93\u51fa\">\u8f93\u51fa<\/h2>\n<p>\u8f93\u51fa\u7684\u672c\u8d28\u5c31\u662f\u5f80os.Stdout\u5199<\/p>\n<p>fmt:<\/p>\n<pre><code>fmt.Print*()\n<\/code><\/pre>\n<p>os.File:<\/p>\n<pre><code>os.Stdout.Write*(&quot;hello&quot;)\n<\/code><\/pre>\n<p>bufio.Writer:<\/p>\n<pre><code>outputWriter := bufio.NewWriter(os.Stdout)\noutputWriter.Writer*()\noutputWriter.Flush()\n<\/code><\/pre>\n<h2 id=\"\u6587\u4ef6\">\u6587\u4ef6<\/h2>\n<p>\u6807\u51c6\u5e93os.File\u7ed3\u6784\u7684\u6307\u9488\u7528\u6765\u8868\u793a\u6587\u4ef6\u53e5\u67c4<\/p>\n<p>\u6807\u51c6\u5e93bufio\u63d0\u4f9b\u4e86\u5e26\u7f13\u51b2\u7684\u64cd\u4f5c<\/p>\n<p>\u8bfb\u6587\u4ef6<\/p>\n<pre><code>readFile, err := os.Open(&quot;filename&quot;)\nreadFile.Read*()\ninputReader := bufio.NewReader(readFile)\ninputReader.Read*('\\n')\n<\/code><\/pre>\n<p>\u5199\u6587\u4ef6<\/p>\n<pre><code>writeFile, err := os.Create(&quot;filename&quot;)\nwriteFile.Write*()\noutputWriter := bufio.NewWriter(outputFile)\noutputWriter.Write*(&quot;string&quot;)\noutputWriter.Flush()\n<\/code><\/pre>\n<hr>\n<h1 id=\"go\u5305\">Go\u5305<\/h1>\n<p>\u521b\u5efa\u5305\uff1a<\/p>\n<p>\u5305\u540d\u4e00\u822c\u548c\u6240\u5728\u8def\u5f84\u7684\u6700\u540e\u4e00\u5c42\u76ee\u5f55\u4e00\u81f4\uff0e\u4e00\u822c\u662f\u5c0f\u5199\u7684\u5355\u4e2a\u5355\u8bcd.<\/p>\n<p>\u540c\u4e00\u4e2a\u76ee\u5f55\u4e2d\u7684\u4ee3\u7801\u6587\u4ef6\u4f7f\u7528\u540c\u4e00\u4e2a\u5305\u540d\uff0e<\/p>\n<pre><code>package pkg1\n<\/code><\/pre>\n<p>\u5355\u4e2a\u5bfc\u5165:<\/p>\n<pre><code>import &quot;pkg1&quot;\nimport &quot;pkg2&quot;\n# \u5bfc\u5165\u65f6\u521b\u5efa\u522b\u540d\nimport alias &quot;pkg&quot;\n<\/code><\/pre>\n<p>\u7ec4\u5408\u5bfc\u5165:<\/p>\n<pre><code>import (\n&quot;pkg1&quot;\n&quot;pkg2&quot;\n...\n)\n<\/code><\/pre>\n<p>\u5305\u5185\u7684\u51fd\u6570\u540d\u9996\u5b57\u6bcd\u5927\u4e9b\u624d\u80fd\u88ab\u5176\u5b83\u5305\u5bfc\u5165\uff0c\u5426\u5219\u5c31\u662f\u79c1\u6709\u7684\uff0e<\/p>\n<p>\u547d\u540d\u5bfc\u5165:<\/p>\n<pre><code>import (\nalias &quot;pkg&quot; # \u7ed9\u5305\u53d6\u522b\u540d\n)\n<\/code><\/pre>\n<p>\u5bfc\u5165\u526f\u4f5c\u7528\uff1a<\/p>\n<p>\u53ea\u6267\u884c\u5bfc\u5165\u5305\u4e2d\u7684init\u51fd\u6570\u5e76\u521d\u59cb\u5316\u5168\u5c40\u53d8\u91cf\uff0c\u4e0d\u5bfc\u5165\u5176\u5b83\u5185\u5bb9\uff0e<\/p>\n<p>\u7f16\u8bd1\u65f6\u4e0d\u68c0\u67e5\u8be5\u5bfc\u5165\u662f\u5426\u4f7f\u7528.\u4e5f\u4e0d\u80fd\u901a\u8fc7\u5305\u540d\u8c03\u7528\u5176\u4e2d\u7684\u5bfc\u51fa\u51fd\u6570.<\/p>\n<pre><code>import _ &quot;path\/pkg&quot;\nimport (\n_ &quot;path\/pkg&quot;\n)\n<\/code><\/pre>\n<p>go\u5305\u67e5\u627e\u987a\u5e8f:<\/p>\n<pre><code>$GOROOT\/src\/... # \u5b89\u88c5golang\u7684\u8def\u5f84\u91cc\u9762\u7684\u6807\u51c6\u5e93\n$GOPATH\n<\/code><\/pre>\n<p>\u5f00\u53d1\u65f6\u5019\u63a8\u8350\u7684\u4e66\u5199\u987a\u5e8f:<\/p>\n<ul>\n<li>\u6807\u51c6\u5e93<\/li>\n<li>\u7b2c\u4e09\u65b9\u5305<\/li>\n<li>\u672c\u5730\u5305<\/li>\n<\/ul>\n<p>go\u5305\u7684\u7f16\u8bd1\u5668\u5bfc\u5165\u987a\u5e8f\uff1a\u6309\u7167\u4f9d\u8d56\u5173\u7cfb\u62d3\u6251\u6392\u5e8ftopological sort.<\/p>\n<p>\u7f16\u8bd1\u5668\u5bfc\u5165\u89c4\u5219\uff1a<\/p>\n<ul>\n<li>\u4f18\u5148\u52a0\u8f7d\u88ab\u4f9d\u8d56\u7684\u5305<\/li>\n<li>\u907f\u514d\u91cd\u590d\u52a0\u8f7d<\/li>\n<li>\u5305\u4e4b\u95f4\u6709\u4f9d\u8d56\u5173\u7cfb\u7684\uff0c\u6839\u636e\u4f9d\u8d56\u56fe\u987a\u5e8f\u52a0\u8f7d<\/li>\n<li>\u6240\u6709\u5305\u5728init()\u8c03\u7528\u524d\u5b8c\u6210\u521d\u59cb\u5316<\/li>\n<\/ul>\n<hr>\n<h1 id=\"go\u6587\u6863\">Go\u6587\u6863<\/h1>\n<p>\u901a\u8fc7\u6ce8\u91ca\u7f16\u5199\u6587\u6863\uff0cgodoc\u4f1a\u81ea\u52a8\u8bc6\u522b\uff0e\u5bf9\u5305\uff0c\u51fd\u6570\uff0c\u7c7b\u578b\uff0c\u5168\u5c40\u53d8\u91cf\u90fd\u53ef\u4ee5.<\/p>\n<pre><code>\/\/ this is documents\nfunc Fucntion() {}\n\/*\nThis is documents\n*\/\ntype St struct {}\n<\/code><\/pre>\n<p>\u4e5f\u53ef\u4ee5\u7ed9\u5305\u5199\u4e00\u6bb5\u6587\u5b57\u8f83\u591a\u7684\u6587\u6863\uff0c\u901a\u8fc7\u5728\u5305\u5185\u521b\u5efadoc.go.<\/p>\n<p>\u8fd9\u6bb5\u6587\u6863\u4f1a\u663e\u793a\u5728\u6240\u6709\u5176\u5b83\u6587\u6863\u4e4b\u524d\uff0e<\/p>\n<pre><code># vim doc.go\n\/*\nThis docs for package\n...\n*\/\npackage pkg # \u4f7f\u7528\u548c\u5305\u4e00\u6837\u7684\u540d\u5b57.\n<\/code><\/pre>\n<hr>\n<h1 id=\"go-runtime\">Go runtime<\/h1>\n<h2 id=\"\u8c03\u5ea6\u5668\">\u8c03\u5ea6\u5668<\/h2>\n<p>GMP\u6a21\u578b<\/p>\n<h2 id=\"\u5185\u5b58\u7ba1\u7406\">\u5185\u5b58\u7ba1\u7406<\/h2>\n<p>mcache: \u6bcf\u4e2ap\u7684\u672c\u5730\u7f13\u5b58\nmcentral\uff1a\u5168\u5c40\u4e2d\u5fc3\u7f13\u5b58\nmheap\uff1a\u64cd\u4f5c\u7cfb\u5185\u5b58\u7ba1\u7406<\/p>\n<h2 id=\"\u5783\u573e\u56de\u6536\">\u5783\u573e\u56de\u6536<\/h2>\n<p>GOGC\nGOMEMLIMIT<\/p>\n<p>\u4e09\u8272\u6807\u8bb0\u6e05\u9664\u7b97\u6cd5\u8fdb\u884c\u5783\u573e\u6536\u96c6Tricolor Mark-and-Sweep<\/p>\n<ul>\n<li>\u767d\u8272: \u672a\u8bbf\u95ee\uff0c\u53ef\u80fd\u662f\u5783\u573e<\/li>\n<li>\u7070\u8272\uff1a\u5df2\u88ab\u8bbf\u95ee\uff0c\u4f46\u5b50\u5bf9\u8c61\u6ca1\u6709\u626b\u63cf<\/li>\n<li>\u9ed1\u8272\uff1a\u5df2\u88ab\u8bbf\u95ee\uff0c\u5b50\u5bf9\u8c61\u5904\u7406\u5b8c\u6bd5<\/li>\n<\/ul>\n<p>GC\u56db\u4e2a\u9636\u6bb5\uff1a<\/p>\n<ol>\n<li>STW\uff08stop the world\uff09\u8d77\u59cb\u9636\u6bb5\uff1a\u6682\u505c\u6240\u6709goroutine\uff0c\u505a\u521d\u59cb\u6807\u8bb0\u3002<\/li>\n<li>concurrent mark\u5e76\u53d1\u6807\u8bb0\uff1a\u5e76\u53d1\u8ffd\u8e2a\u6240\u6709\u53ef\u8fbe\u5bf9\u8c61\u3002<\/li>\n<li>concurrent sweep\u5e76\u53d1\u6e05\u9664\uff1a\u5e76\u53d1\u91ca\u653e\u4e0d\u53ef\u8fbe\u5bf9\u8c61\u7684\u5185\u5b58\u3002<\/li>\n<li>STW\u7ec8\u6b62\u9636\u6bb5\uff1a\u505a\u6700\u540e\u540c\u6b65\u548c\u6536\u5c3e\u5de5\u4f5c\u3002<\/li>\n<\/ol>\n<h2 id=\"\u7f51\u7edc\u8f6e\u8be2\u5668netpoller\">\u7f51\u7edc\u8f6e\u8be2\u5668netpoller<\/h2>\n<h2 id=\"\u7cfb\u7edf\u76d1\u63a7sysmon\">\u7cfb\u7edf\u76d1\u63a7Sysmon<\/h2>\n<h2 id=\"\u6808\u7ba1\u7406\">\u6808\u7ba1\u7406<\/h2>\n<h2 id=\"\u5f02\u5e38\u5904\u7406\">\u5f02\u5e38\u5904\u7406<\/h2>\n<p>go\u7684\u6807\u51c6\u5e93errors\u5b9e\u73b0\u4e86\u7528\u4e8e\u9519\u8bef\u5904\u7406\u7684\u51fd\u6570.<\/p>\n<p>\u5185\u7f6e\u51fd\u6570panic\u662f\u65ad\u8a00\u51fd\u6570\uff0c\u4f1a\u89e6\u53d1\u4e00\u4e2a\u5f02\u5e38\uff0c\u7528\u4e8e\u7ec8\u6b62\u5f53\u524d\u7684\u7ebf\u7a0b(\u4f1a\u5728defer\u6267\u884c\u5b8c\u4e4b\u540e\u7ec8\u6b62\u7ebf\u7a0b)<\/p>\n<p>\u5185\u7f6e\u63a5\u53e3\u5b9a\u4e49\u4e86error\u63a5\u53e3\u7c7b\u578b, error\u7c7b\u578b\u90fd\u6709\u4e00\u4e2aError\u65b9\u6cd5.<\/p>\n<pre><code>type error interface {\nError() string\n}\n<\/code><\/pre>\n<p>\u5b9a\u4e49\u9519\u8bef:<\/p>\n<pre><code>var errName error = errors.New(&quot;error message.&quot;)\nerr := errors.New(&quot;error message.&quot;)\nerr := fmt.Errorf(format string, a ...interface{})\n<\/code><\/pre>\n<p>panic:<\/p>\n<p>\u76f8\u5f53\u4e8e\u629b\u51fa\u4e00\u4e2a\u5f02\u5e38\uff0c\u5728\u8fd0\u884c\u5b8cdefer\u4e4b\u540e,\u8fd4\u56de\u5230\u8c03\u7528\u8005\u7ee7\u7eed\u8fd0\u884cdefer\uff0c\u76f4\u5230\u6700\u5916\u5c42\u7684defer\u6267\u884c\u5b8c\u6bd5\uff0c\u7ec8\u6b62\u7a0b\u5e8f.<\/p>\n<pre><code>panic(v interface{})\npanic(&quot;ERROR: command not found&quot;)\n<\/code><\/pre>\n<p>recover:<\/p>\n<p>\u53ea\u80fd\u7528\u4e8edefer\u4fee\u9970\u7684\u51fd\u6570\uff0c\u7528\u4e8e\u63a5\u6536panic\u8c03\u7528\u4e2d\u4f20\u9012\u8fc7\u6765\u7684\u9519\u8bef\u503c,\u6ca1\u6709panic\u8fd4\u56denil.<\/p>\n<p>\u5f53\u524d\u51fd\u6570\u7684\u540e\u9762\u4e0d\u4f1a\u88ab\u6267\u884c\uff0crecover\u6355\u83b7\u5f02\u5e38\u4e4b\u540e\u4f1a\u8fd4\u56de\u5230\u8c03\u7528\u8005\u7ee7\u7eed\u6267\u884c.<\/p>\n<p>\u76f8\u5f53\u4e8ecatch\u4e00\u4e2a\u5f02\u5e38.<\/p>\n<pre><code>recover() interface{}\ndefer func() {\nif err := recover(); err != nil {\nfmt.Println(e)\n\/\/ &quot;ERROR: command not found&quot;\n}\n}()\n<\/code><\/pre>\n<p>\u603b\u7ed3\uff1a<\/p>\n<ol>\n<li>\u5728\u5305\u5185\u90e8\uff0c\u603b\u662f\u5e94\u8be5\u4ecepanic\u4e2drecover\uff0e<\/li>\n<li>\u603b\u662f\u5411\u5305\u7684\u8c03\u7528\u8005\u8fd4\u56de\u9519\u8bef\u503c\uff0c\u800c\u4e0d\u662fpanic.<\/li>\n<\/ol>\n<h2 id=\"\u53cd\u5c04\u4e0e\u63a5\u53e3\">\u53cd\u5c04\u4e0e\u63a5\u53e3<\/h2>\n<hr>"},{"title":"Go_Concurrency","link":"https:\/\/canuxcheng.com\/post\/go_concurrency\/","pubDate":"Mon, 01 Jan 2018 10:49:21 +0000","guid":"https:\/\/canuxcheng.com\/post\/go_concurrency\/","description":"<h1 id=\"\u5e76\u53d1concurrency\">\u5e76\u53d1\/concurrency<\/h1>\n<p>\u4f20\u7edf\u5e76\u53d1\u57fa\u4e8e\u7ebf\u7a0b\uff0cgolang\u57fa\u4e8eCSP<\/p>\n<p>CSP: communicating sequential processes, \u901a\u4fe1\u987a\u5e8f\u8fdb\u7a0b\u3002<\/p>\n<p>go\u7684\u5e76\u53d1\u540c\u6b65\u6a21\u578b\u6765\u81eaCSP\u6cdb\u578b\u3002CSP\u662f\u4e00\u79cd\u6d88\u606f\u4f20\u9012\u6a21\u578b\uff0c\u7528\u4e8e\u5728goroutine\u4e4b\u95f4\u540c\u6b65\u548c\u4f20\u9012\u6570\u636e\u7684\u7c7b\u578b\u662fchannel.<\/p>\n<p>concurrency:\u5e76\u53d1,\u540c\u65f6\u7ba1\u7406\u5f88\u591a\u4e8b\u60c5\uff0c\u53ef\u4ee5\u6267\u884c\u5230\u4e00\u534a\u5c31\u6682\u505c\u53bb\u505a\u5176\u4ed6\u4e8b\u60c5.\u6709\u540c\u65f6\u6267\u884c\u7684\u80fd\u529b\uff0c\u4f46\u4e0d\u4e00\u5b9a\u8981\u540c\u65f6\u6267\u884c.\u5e76\u53d1\u5c5e\u4e8e\u4ee3\u7801\u3002<\/p>\n<p>\u6240\u4ee5\u5982\u679c\u662f\u5355\u4e2acpu\uff0c\u6bcf\u6b21\u53ea\u80fd\u8fd0\u884c\u4e00\u4e2agoroutine,\u5982\u679c\u662f\u591acpu,\u5c31\u662f\u5e76\u884c,\u6bcf\u4e2acpu\u90fd\u53ef\u4ee5\u8dd1goroutine.<\/p>\n<p>parallelism: \u5e76\u884c,\u8ba9\u4e0d\u540c\u7684\u4ee3\u7801\u5728\u4e0d\u540c\u7684\u7269\u7406\u5904\u7406\u5668\u4e0a\u540c\u65f6\u6267\u884c. \u5e76\u884c\u5c5e\u4e8e\u8fd0\u884c\u4e2d\u7684\u7a0b\u5e8f\u3002\u5e76\u884c\u662f\u65f6\u95f4\u6216\u8005\u4e0a\u4e0b\u6587\u7684\u6982\u5ff5\u3002<\/p>\n<p>process: \u8fdb\u7a0b, \u662f\u7cfb\u7edf\u8d44\u6e90\u548c\u8c03\u5ea6\u7684\u57fa\u672c\u5355\u4f4d\uff0c\u5305\u62ec\u5185\u5b58\uff0c\u53e5\u67c4\uff0c\u7ebf\u7a0b\u7b49\u3002<\/p>\n<p>thread: \u7ebf\u7a0b,\u662fcpu\u8c03\u5ea6\u548c\u5206\u914d\u7684\u57fa\u672c\u5355\u4f4d,\u6bcf\u4e2a\u8fdb\u7a0b\u81f3\u5c11\u5305\u542b\u4e00\u4e2a\u7ebf\u7a0b\uff0c\u521d\u59cb\u7ebf\u7a0b\u5c31\u662f\u4e3b\u7ebf\u7a0b\uff0c\u6bcf\u4e2a\u7ebf\u7a0b\u7ed1\u5b9a\u5230\u4e00\u4e2a\u903b\u8f91cpu\u4e0a\u8fd0\u884c\u3002<\/p>\n<p>co-routine: \u534f\u7a0b\uff0c\u5927\u91cf\u7ebf\u7a0b\u4f1a\u6d88\u8017\u5185\u5b58\u548ccpu\u8c03\u5ea6\uff0c\u5c06\u7ebf\u7a0b\u5206\u4e3a\u5185\u6838\u6001\u7ebf\u7a0b\u548c\u7528\u6237\u6001\u7ebf\u7a0b\uff0c\u6bcf\u4e2a\u7528\u6237\u6001\u7ebf\u7a0b\u7ed1\u5b9a\u5230\u5185\u6838\u6001\u7ebf\u7a0b\uff0c\u4f46\u662fcpu\u4e0d\u77e5\u9053\u7528\u6237\u6001\u7ebf\u7a0b\u7684\u5b58\u5728\uff0c\u6211\u4eec\u628a\u7528\u6237\u6001\u7ebf\u7a0b\u53eb\u534f\u7a0b\u3002<\/p>\n<p>goroutine: go\u8bed\u8a00\u7684\u534f\u7a0b\uff0c\u662f\u5e76\u884c\u7684\uff0c\u901a\u8fc7channel\u6765\u901a\u4fe1.<\/p>\n<p>GMP: goroutine\u7684\u5b9e\u73b0\u6a21\u578b\u3002<\/p>\n<p>G: goroutine, \u521d\u59cb\u68082kb\uff0c\u591f\u8fc7go\u5173\u952e\u5b57\u521b\u5efa\uff0c\u5305\u542bgrunable, grunning, gwaiting\u4e09\u79cd\u72b6\u6001\u3002<\/p>\n<p>M: machine\uff0c\u5bf9\u5e94OS\u7ebf\u7a0b\uff0c\u4e0ecpu\u7ed1\u5b9a\uff0cgolang\u9ed8\u8ba410000\u4e2a\uff0cSetMaxThreads\u53ef\u4ee5\u8bbe\u7f6e\uff0c\u9700\u8981\u7ed1\u5b9aP\u624d\u80fd\u6267\u884cG\uff0c\u5426\u5219\u4f11\u7720\u3002<\/p>\n<p>P: processor, \u903b\u8f91\u5904\u7406\u5668\uff0c\u7ba1\u7406G\u7684\u672c\u5730\u961f\u5217\u548c\u8c03\u5ea6\u4e0a\u4e0b\u6587\u3002\u7531GOMAXPROCS\u786e\u5b9a\u4e2a\u6570(\u9ed8\u8ba4cpu\u6838\u4e2a\u6570)\u3002\u7528\u6765 \u89e3\u51b3GM\u7684\u9501\u7ade\u4e89\u95ee\u9898\u3002<\/p>\n<p>\u4e0d\u8981\u901a\u8fc7\u5171\u4eab\u5185\u5b58\u901a\u4fe1\uff0c\u901a\u8fc7\u901a\u4fe1\u6765\u5171\u4eab\u5185\u5b58\u3002<\/p>\n<h2 id=\"goroutines\">goroutines<\/h2>\n<p>go\u5173\u952e\u5b57\u4f1a\u542f\u52a8\u4e00\u4e2a\u65b0\u7684goroutine\u5e76\u6267\u884c.<\/p>\n<p>\u6bcf\u4e2agoroutine\u4f1a\u7ed1\u5b9a\u5230\u4e00\u4e2a\u903b\u8f91\u5904\u7406\u5668P\u4e0a\u8fd0\u884c\uff0c\u6bcf\u4e2a\u903b\u8f91\u5904\u7406\u5668\u4f1a\u7ed1\u5b9a\u5230\u5355\u4e2a\u64cd\u4f5c\u7cfb\u7edf\u7ebf\u7a0b\u3002<\/p>\n<p>\u5f53goroutine\u963b\u585e\uff0c\u5c31\u4f1a\u628agoroutine\u548cmachine\u4ece\u903b\u8f91\u5904\u7406\u5668P\u4e0a\u5206\u79bb\uff0c\u7136\u540e\u521b\u5efa\u4e00\u4e2a\u65b0\u7684machine\u7ed1\u5b9a\u5230\u8be5\u903b\u8f91\u5904\u7406\u5668P\uff0c\u5e76\u7ee7\u7eed\u8fd0\u884c\u961f\u5217\u4e2d\u7684\u5176\u5b83goroutine.<\/p>\n<p>\u5f53\u963b\u585e\u7684goroutine\u6062\u590d\uff0c\u4f1a\u518d\u6b21\u8fdb\u5165\u961f\u5217\uff0c\u548c\u8be5goroutine\u7ed1\u5b9a\u7684machine\u4e5f\u4f1a\u4fdd\u5b58\u4e0b\u6765.<\/p>\n<pre><code>go FuncName(...)\n<\/code><\/pre>\n<p>\u4e3b\u8fdb\u7a0bmain\u7ed3\u675f\u4e86\uff0cgoroutine\u4e5f\u7ed3\u675f\uff0e<\/p>\n<h2 id=\"\u7adf\u6001\">\u7adf\u6001<\/h2>\n<p>race condition: \u7ade\u4e89\u72b6\u6001\uff0c\u591a\u4e2agoroutine\u540c\u65f6\u64cd\u4f5c\u540c\u4e00\u8d44\u6e90.<\/p>\n<pre><code># \u68c0\u6d4b\u7ade\u4e89\u72b6\u6001\n$ go build -race\n<\/code><\/pre>\n<p>\u6240\u4ee5\u8981\u89e3\u51b3goroutine\u95f4\u7684\u901a\u4fe1\u548c\u540c\u6b65\u7684\u95ee\u9898.<\/p>\n<p>\u901a\u8fc7\u901a\u4fe1\u5171\u4eab\u5185\u5b58\uff0c\u800c\u4e0d\u662f\u901a\u8fc7\u5171\u4eab\u5185\u5b58\u800c\u901a\u4fe1,\u8bf4\u660e\u89e3\u51b3\u5e76\u53d1\u95ee\u9898\u4f18\u5148\u4f7f\u7528chan\uff0c\u800c\u4e0d\u662fsync\u5305\u3002<\/p>\n<p>channel\u8fd8\u662fmutex,\u9009\u62e9\u7684\u4f9d\u636e\u662f\u4ed6\u4eec\u7684\u80fd\u529b\/\u7279\u6027.<\/p>\n<p>channel\u7684\u80fd\u529b\u662f\u8ba9\u6570\u636e\u6d41\u52a8\u8d77\u6765\uff0c\u64c5\u957f\u7684\u662f\u6570\u636e\u6d41\u52a8\u7684\u573a\u666f:<\/p>\n<ul>\n<li>\u4f20\u9012\u6570\u636e\u7684\u6240\u6709\u6743\uff0c\u5373\u628a\u67d0\u4e2a\u6570\u636e\u53d1\u9001\u7ed9\u5176\u4ed6\u534f\u7a0b<\/li>\n<li>\u5206\u53d1\u4efb\u52a1\uff0c\u6bcf\u4e2a\u4efb\u52a1\u90fd\u662f\u4e00\u4e2a\u6570\u636e<\/li>\n<li>\u4ea4\u6d41\u5f02\u6b65\u7ed3\u679c\uff0c\u7ed3\u679c\u662f\u4e00\u4e2a\u6570\u636e<\/li>\n<\/ul>\n<p>sync\u7684\u80fd\u529b\u662f\u6570\u636e\u4e0d\u52a8\uff0c\u67d0\u6bb5\u65f6\u95f4\u53ea\u7ed9\u4e00\u4e2a\u534f\u7a0b\u8bbf\u95ee\u6570\u636e\u7684\u6743\u9650\u64c5\u957f\u6570\u636e\u4f4d\u7f6e\u56fa\u5b9a\u7684\u573a\u666f:<\/p>\n<ul>\n<li>\u7f13\u5b58<\/li>\n<li>\u72b6\u6001<\/li>\n<\/ul>\n<hr>\n<h2 id=\"channel\">channel<\/h2>\n<p>goroutine\u901a\u8fc7channel\u6765\u901a\u4fe1\u548c\u540c\u6b65\u3002<\/p>\n<p>channels\u662f\u5f15\u7528\u7c7b\u578b,chan\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff0c\u5e76\u4e14\u4e0d\u4f1a\u6709\u6570\u636e\u51b2\u7a81\u3002<\/p>\n<p>chan\u901a\u8fc7make\u6765\u521b\u5efa\uff0c\u901a\u8fc7close\u6765\u5173\u95ed\uff0echan\u662f\u5148\u8fdb\u5148\u51fa\u7684FIFO.<\/p>\n<p>chan \u652f\u6301\u7684\u7c7b\u578bType\uff1a \u57fa\u672c\u7c7b\u578b\uff08number, string, bool\uff09\uff0c\u590d\u5408\u7c7b\u578b\uff08pointer, struct, array, slice, map, function, interface\uff09\uff0c\u81ea\u5b9a\u4e49\u7c7b\u578b.<\/p>\n<p>chan\u7684Type\u4e0d\u80fd\u662fchannel\u672c\u8eab\u3002<\/p>\n<p>\u7533\u660e\u4e00\u4e2a\u53d8\u91cf:<\/p>\n<pre><code>var ChanName chan Type\n<\/code><\/pre>\n<p>\u5b9a\u4e49\u4e00\u4e2achan, \u9ed8\u8ba4chan\u90fd\u662f\u53cc\u5411\u7684:<\/p>\n<pre><code>var ch = make(chan Type, cap)\nch := make(chan Type, cap)\n<\/code><\/pre>\n<p>chan\u7684\u65b9\u5411\uff1a<\/p>\n<p>\u5c06make\u521b\u5efa\u7684\u53cc\u5411\u8f6c\u6362\u4e3a\u5355\u5411,\u4e5f\u53ef\u4ee5\u76f4\u63a5\u5728\u51fd\u6570\u53c2\u6570\u7533\u660e\u5355\u5411\u3002<\/p>\n<p>\u53ea\u63a5\u6536\u7684chan\u65e0\u6cd5\u5173\u95ed<\/p>\n<pre><code>var recvOnly chan&lt;- Type = ch\n<\/code><\/pre>\n<p>\u53ea\u53d1\u9001\u7684chan<\/p>\n<pre><code>var sendOnly &lt;-chan Type = ch\n<\/code><\/pre>\n<p>\u64cd\u4f5cchan:<\/p>\n<pre><code>ch &lt;- v # \u53d1\u9001\u503c\u5230ch\nv := &lt;-ch # \u4ecech\u63a5\u6536\u503c, \u5e76\u8d4b\u4e88Type\u7c7b\u578b\u53d8\u91cfv\nv, ok = &lt;-ch # \u4ecech\u63a5\u6536\u503c\u5e26\u72b6\u6001, \u5982\u679cch\u5173\u95ed\u6216\u6ca1\u6709\u6570\u636e\uff0cok\u5c31\u4e3afalse.\n<\/code><\/pre>\n<p>\u65e0\u7f13\u51b2\u7684chan(\u540c\u6b65):<\/p>\n<pre><code>ch := make(chan Type)\n<\/code><\/pre>\n<p>\u65e0\u7f13\u51b2\u7684chan\u53d1\u9001\u8005\u4f1a\u963b\u585eunbuffered\uff0c\u76f4\u5230\u63a5\u6536\u8005\u63a5\u6536\u6570\u636e, \u4e5f\u5c31\u662f\u8bf4\u662f\u540c\u6b65\u7684synchronous.<\/p>\n<p>\u53ea\u6709\u53d1\u9001\u8005\u6216\u53ea\u6709\u63a5\u53d7\u8005\u7684chan\u4f1a\u5bfc\u81f4\u6b7b\u9501\uff0c\u4ea7\u751fpanic.<\/p>\n<p>\u5e26\u7f13\u51b2\u7684chan\uff08\u5f02\u6b65\uff09:<\/p>\n<p>\u5e26\u7f13\u51b2\u7684chan\uff0c\u5728\u7f13\u51b2\u533a\u6ee1\u4e4b\u524d\uff0c\u90fd\u4e0d\u4f1a\u963b\u585ebuffered\uff0c\u662f\u5f02\u6b65\u7684asynchronous.<\/p>\n<p>\u53ea\u6709\u901a\u9053\u4e2d\u6ca1\u6709\u8981\u63a5\u6536\u7684\u503c\uff0c\u63a5\u6536\u52a8\u4f5c\u624d\u4f1a\u963b\u585e.<\/p>\n<p>\u53ea\u6709\u5728\u901a\u9053\u6ca1\u6709\u53ef\u7528\u7f13\u51b2\u533a\u5bb9\u7eb3\u88ab\u53d1\u9001\u7684\u503c\uff0c\u53d1\u9001\u52a8\u4f5c\u624d\u4f1a\u963b\u585e\uff0e<\/p>\n<pre><code>ch := make(chan Type, cap)\n\/\/ \u5e26\u7f13\u51b2\u7684chan\u53ef\u4ee5\u901a\u8fc7range\u904d\u5386\nfor val := range ch {\nfmt.Println(val)\n}\n<\/code><\/pre>\n<p>\u663e\u793a\u5173\u95edchan:<\/p>\n<p>\u901a\u9053\u5173\u95ed\u540e\uff0c\u4e0d\u80fd\u518d\u5411\u901a\u9053\u53d1\u9001\u503c\uff0c\u4f46\u662f\u5df2\u7ecf\u53d1\u9001\u7684\u503c\u53ef\u4ee5\u88ab\u63a5\u6536.<\/p>\n<pre><code>\/\/ \u4e00\u822c\u5728\u751f\u4ea7\u8005(\u53d1\u9001\u52a8\u4f5c)\u5173\u95edchan\nclose(ch)\n\/\/ \u5982\u679cchan\u5173\u95edok=false, v\u4e3a\u96f6\u503c.\nv, ok := &lt;-ch\n<\/code><\/pre>\n<hr>\n<h2 id=\"select\">select<\/h2>\n<p>\u76d1\u542cchan\u7684\u6570\u636e\u6d41\uff0c\u7c7b\u4f3c\u4e8eswitch-case, \u53ef\u7528\u4e8e\u5904\u7406\u591a\u4e2achan\u7684\u60c5\u51b5<\/p>\n<p>\u8fd0\u884c\u89c4\u5219\uff1a<\/p>\n<ol>\n<li>\n<p>\u6bcf\u6b21\u6267\u884cselect\u90fd\u53ea\u4f1a\u6267\u884c\u4e00\u4e2acase\u6216\u8005\u6267\u884cdefault\uff1b\u5f53\u6709case\u53ef\u4ee5\u6267\u884c\uff0cdefault\u4e0d\u4f1a\u6267\u884c\uff1b\u6ca1\u6709case\u6267\u884c\u65f6\u624d\u6267\u884cdefault\u3002<\/p>\n<\/li>\n<li>\n<p>\u5f53\u6ca1\u6709case\u6216default\u53ef\u4ee5\u6267\u884c\uff0cselect\u963b\u585e\u7b49\u5f85\u3002<\/p>\n<\/li>\n<li>\n<p>\u5f53\u6709\u591a\u4e2acase\u53ef\u4ee5\u6267\u884c\uff0cselect\u968f\u673a\u9009\u62e9\u4e00\u4e2a\u6267\u884c\u3002<\/p>\n<\/li>\n<li>\n<p>case\u540e\u9762\u5fc5\u987b\u662f\u8bfb\u6216\u5199chan\u7684\u64cd\u4f5c\uff0c\u5426\u5219\u7f16\u8bd1\u51fa\u9519\u3002<\/p>\n<p>ctx, cancel := context.WithCancel(context.Background())\nselect {\ncase var := &lt;-ch1:\ndo something\ncase ch2 &lt;-value:\ndo something\ncase &lt;-time.After(2 * time.Second):\nfmt.Println(&ldquo;timeout!&rdquo;)\ncase &lt;-ctx.Done():\nfmt.Println(&ldquo;cancelled:&rdquo;, ctx.Err())\n&hellip;\ndefault: \/\/ default\u53ef\u4ee5\u7701\u7565\ndo default thing.\n}<\/p>\n<\/li>\n<\/ol>\n<hr>\n<h2 id=\"\u9000\u51fagoroutine\">\u9000\u51fagoroutine<\/h2>\n<h3 id=\"for-range\">for-range<\/h3>\n<p>range\u80fd\u611f\u77e5channel\u5173\u95ed\uff0c\u5f53channel\u88ab\u53d1\u9001\u6570\u636e\u7684goroutine\u5173\u95ed\u65f6\uff0crange\u5c31\u4f1a\u7ed3\u675f\uff0c\u7136\u540e\u9000\u51fafor\u5faa\u73af\u3002<\/p>\n<pre><code>go func(send &lt;-chan int) {\nfor val := range send {\n...\n}\n}(sendOnly)\n<\/code><\/pre>\n<h3 id=\"for-select\">for-select<\/h3>\n<p>select\u6709\u591a\u8def\u590d\u7528\u80fd\u529b\uff0cfor-select \u53ef\u4ee5\u6301\u7eed\u5904\u7406\u591a\u8def\u591a\u4e2achannel\u7684\u80fd\u529b\u3002\u4f46select\u4e0d\u80fd\u611f\u77e5channel\u7684\u5173\u95ed.<\/p>\n<p>context.Context\u9000\u51fagoroutine:<\/p>\n<pre><code>go func() {\nfor {\nselect {\ncase &lt;-ctx.Done():\nfmt.Println(&quot;goroutine exiting:&quot;, ctx.Err())\nreturn\ndefault:\nfmt.Println(&quot;working...&quot;)\n}\n}\n}\n<\/code><\/pre>\n<p>\u67d0\u4e2a\u901a\u9053\u5173\u95ed\uff0c\u4e0d\u518d\u5904\u7406\u8be5\u901a\u9053\uff0c\u4f46\u662f\u7ee7\u7eed\u5904\u7406\u5176\u5b83channel,select\u4e0d\u4f1a\u5728nil\u7684\u901a\u9053\u4e0a\u8fdb\u884c\u7b49\u5f85:<\/p>\n<pre><code>go func() {\nfor {\nselect {\ncase x, ok := in1:\nif !ok {\nin1 = nil \u628a\u53ea\u8bfbchannel\u8bbe\u7f6e\u4e3anil,select\u4e0d\u4f1a\u5728\u8fd9\u91cc\u963b\u585e\u3002\n}\ncase y, ok :=&lt;-in2:\nif !ok {\nin2 = nil\n}\nif in1 == nil &amp;&amp; in2 == nil {\nreturn\n}\n}\n}()\n<\/code><\/pre>\n<p>\u4f7f\u7528\u4e13\u95e8channel\u53d1\u9001\u9000\u51fa\u4fe1\u53f7,\u53ea\u9700\u8981\u5728main\u4e2d\u5173\u95edchannel\uff0c\u6240\u6709goroutine\u90fd\u4f1a\u63a5\u6536\u5230\u4fe1\u53f7\u9000\u51fa:<\/p>\n<pre><code>go func() {\nfor {\nselect {\ncase &lt;- stopCh:\n...\nreturn\ncase &lt;- t.C:\n...\n}\n}\n}()\n<\/code><\/pre>"},{"title":"GSL_builtin","link":"https:\/\/canuxcheng.com\/post\/gsl_builtin\/","pubDate":"Mon, 01 Jan 2018 10:49:21 +0000","guid":"https:\/\/canuxcheng.com\/post\/gsl_builtin\/","description":"<h1 id=\"builtin\">builtin<\/h1>\n<p><a class=\"link\" href=\"https:\/\/pkg.go.dev\/builtin\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/pkg.go.dev\/builtin<\/a><\/p>\n<p>go\u7684builtin package.<\/p>\n<h2 id=\"constants\">constants<\/h2>\n<pre><code>true\nfalse\niota \/\/ Untyped int.\n<\/code><\/pre>\n<h2 id=\"variables\">variables<\/h2>\n<p>pointer, channel, func, interface, map, or slice type\u7684zero value\uff1a<\/p>\n<pre><code>nil\n<\/code><\/pre>\n<h2 id=\"functions\">functions<\/h2>\n<pre><code># \u5206\u914d\u5e76\u521d\u59cb\u5316\u5404\u79cd\u7c7b\u578b\u7684\u5bf9\u8c61, \u8fd4\u56de\u4e00\u4e2a\u6307\u9488\uff0e\nnew(Type) *Type\n# \u5206\u914d\u5e76\u521d\u59cb\u5316\u4e00\u4e2aSlice\/Map\/Channel\u7684\u5bf9\u8c61,\u8fd4\u56de\u76f8\u540c\u7c7b\u578b\u7684\u5bf9\u8c61.\nmake(t Type, size ...IntegerType) Type\n# \u8fd4\u56de\u5bb9\u91cf\uff0c\u3000Array\/ArrayPointer\/Slice\/Channel\ncap(v Type) int\n# \u8fd4\u56de\u957f\u5ea6\uff0c\u3000String\/Array\/ArrayPointer\/Slice\/Map\/Channel\nlen(v Type) int\nprint(args ...Type)\nprintln(args ...Type)\nfunc max[T cmp.Ordered](x T, y ...T) T\nfunc min[T cmp.Ordered](x T, y ...T) T\nfunc clear[T ~[]Type | ~map[Type]Type1](t T)\n<\/code><\/pre>\n<p>complex:<\/p>\n<pre><code># \u628a\u4e24\u4e2a\u6d6e\u70b9\u6570\u6784\u9020\u6210\u4e00\u4e2a\u590d\u6570\ncomplex(r, i FloatType) ComplexType\n# \u8fd4\u56de\u590d\u6570c\u7684\u5b9e\u90e8\nreal(c ComplexType) FloatType\n# \u8fd4\u56de\u590d\u6570c\u7684\u865a\u90e8\nimag(c ComplexType) FloatType\n<\/code><\/pre>\n<p>slice:<\/p>\n<pre><code># \u5411\u5207\u7247\u672b\u5c3e\u8ffd\u52a0\u5143\u7d20\uff0c\u8fd4\u56de\u65b0\u7684\u5207\u7247\uff0e\u5207\u7247\u957f\u5ea6\u589e\u52a0.\n# \u5982\u679c\u957f\u5ea6\u8d85\u8fc7\u5e95\u5c42\u6570\u7ec4\u957f\u5ea6\uff0c\u5c31\u521b\u5efa\u4e86\u4e00\u4e2a\u65b0\u7684\u5e95\u5c42\u6570\u7ec4. \u5426\u5219\u5e95\u5c42\u6570\u7ec4\u4e0d\u53d8\uff0e\n# \u5728\u5143\u7d20\u4e0d\u8d85\u8fc71000\u7684\u60c5\u51b5\u4e0b\uff0c\u81ea\u52a8\u521b\u5efa\u7684\u5e95\u5c42\u6570\u7ec4\u5bb9\u91cf\u7ffb\u500d.\nappend(slice []Type, elems ...Type) []Type\n# \u590d\u5236\u4e00\u4e2a\u5207\u7247, \u8fd4\u56de\u590d\u5236\u7684\u5143\u7d20\u7684\u4e2a\u6570\ncopy(dst, src []Type) int\n<\/code><\/pre>\n<p>map:<\/p>\n<pre><code># \u4ece\u6620\u5c04\u5220\u9664\u4e00\u4e2a\u952e\u503c\u5bf9\ndelete(m map[Type]1, key Type)\n<\/code><\/pre>\n<p>chan:<\/p>\n<pre><code># \u7531\u53d1\u9001\u8005\u5173\u95ed\u4e00\u4e2a\u53cc\u5411\u6216\u53ea\u53d1\u9001\u7684\u4fe1\u9053\nclose(c chan&lt;- Type)\n<\/code><\/pre>\n<p>error:<\/p>\n<pre><code># \u505c\u6b62\u5f53\u524dgo\u7a0b\u7684\u6b63\u5e38\u6267\u884c(\u65ad\u8a00\u51fd\u6570)\npanic(v interface{})\n# \u7ba1\u7406panic\u8fc7\u7a0b\u4e2d\u7684go\u7a0b\nrecover() interface{}\n<\/code><\/pre>\n<h2 id=\"types\">types<\/h2>\n<pre><code>bool\nuint\nuintptr\nuint8\/byte (0 - 255)\nuint16\nuint32\nuint64\nint\nint8 (-128 - 127)\nint16\nint32\/rune\nint64\nfloat32\nfloat64\ncomplex64\ncomplex128\nstring\n<\/code><\/pre>\n<p>\u6587\u6863\u7c7b\u578b:<\/p>\n<pre><code>Type\nType1\nIntegerType\nFloatType\nComplexType\n<\/code><\/pre>\n<p>\u9519\u8bef\u5904\u7406:<\/p>\n<pre><code>error\n\/\/ go\u4f7f\u7528error\u503c\u6765\u8868\u793a\u9519\u8bef\u72b6\u6001\uff0cnil\u8868\u793a\u6210\u529f\uff0c\u975enil\u8868\u793a\u5931\u8d25\uff0e\ntype error interface {\nERROR() string\n}\n<\/code><\/pre>\n<p>any:<\/p>\n<pre><code>type any = interface{}\n<\/code><\/pre>\n<p>comparable<\/p>\n<pre><code>type comparable interface{ comparable }\n<\/code><\/pre>\n<hr>"},{"title":"GSL_concurrency","link":"https:\/\/canuxcheng.com\/post\/gsl_concurrency\/","pubDate":"Mon, 01 Jan 2018 10:49:21 +0000","guid":"https:\/\/canuxcheng.com\/post\/gsl_concurrency\/","description":"<h1 id=\"sync\">sync<\/h1>\n<p>sync\u7528\u4e8egoroutine\u540c\u6b65.<\/p>\n<pre><code>import &quot;sync&quot;\n<\/code><\/pre>\n<h2 id=\"constants\">constants<\/h2>\n<h2 id=\"variables\">variables<\/h2>\n<h2 id=\"functions\">functions<\/h2>\n<h2 id=\"locker\">Locker<\/h2>\n<p>\u4e00\u4e2a\u53ef\u4ee5\u52a0\u9501\u548c\u89e3\u9501\u7684\u63a5\u53e3<\/p>\n<pre><code>type Locker interface {\nLock()\nUnlock()\n}\n<\/code><\/pre>\n<h2 id=\"pool\">Pool<\/h2>\n<p>Pool\u662f\u4e00\u4e2a\u53ef\u4ee5\u5206\u522b\u5b58\u53d6\u7684\u4e34\u65f6\u5bf9\u8c61\u7684\u96c6\u5408\u3002<\/p>\n<h2 id=\"once\">Once<\/h2>\n<p>\u53ea\u6267\u884c\u4e00\u6b21\u52a8\u4f5c\u7684\u5bf9\u8c61(\u5355\u4f8b\u6a21\u5f0f)<\/p>\n<pre><code>type Once struct {}\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>\/\/ \u53ea\u6709\u7b2c\u4e00\u6b21\u8c03\u7528\u624d\u6267\u884c\nfunc (o *Once) Do(f func())\n<\/code><\/pre>\n<h2 id=\"mutex\">Mutex<\/h2>\n<p>\u4e92\u65a5\u9501,\u9501\u548c\u7ebf\u7a0b\u65e0\u5173\uff0c\u53ef\u4ee5\u7531\u4e0d\u540c\u7684\u7ebf\u7a0b\u52a0\u9501\u548c\u89e3\u9501.<\/p>\n<p>Mutex\u7684\u521d\u59cb\u503c\u4e3a\u672a\u9501\u7684\u72b6\u6001\uff0c\u5e76\u4e14Mutex\u901a\u5e38\u4f5c\u4e3a\u7ed3\u6784\u4f53\u7684\u533f\u540d\u6210\u5458\u5b58\u5728\u3002<\/p>\n<p>\u540c\u4e00\u65f6\u523b\u53ea\u80fd\u6709\u4e00\u4e2a\u7ebf\u7a0b\u8fdb\u5165\u4e34\u754c\u533a.<\/p>\n<pre><code>type Mutex struct {}\nMutex\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>\/\/ \u52a0\u9501\uff0c\u5982\u679c\u5df2\u7ecf\u52a0\u9501\uff0c\u963b\u585e\u81f3m\u89e3\u9501\uff0e\nfunc (m *Mutex) Lock()\n\/\/ \u89e3\u9501\uff0c\u5982\u679c\u6ca1\u6709\u52a0\u9501\uff0c\u5bfc\u81f4panic\nfunc (m *Mutex) Unlock()\n<\/code><\/pre>\n<h2 id=\"rwmutex\">RWMutex<\/h2>\n<p>\u8bfb\u5199\u4e92\u65a5\u9501,\u53ef\u4ee5\u7531\u4e0d\u540c\u7684\u7ebf\u7a0b\u52a0\u9501\u548c\u89e3\u9501.<\/p>\n<pre><code>type RWMutex struct {}\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>\/\/ \u9501\u5b9a\u4e3a\u5199\u5165\u72b6\u6001\uff0c\u7981\u6b62\u5176\u5b83\u7ebf\u7a0b\u8bfb\u5199\uff0c\u4e00\u6b21\u53ea\u80fd\u6709\u4e00\u4e2a\u7ebf\u7a0b\u6301\u6709\u3002\nfunc (rw *RWMutex) Lock()\n\/\/ \u89e3\u9664\u5199\u5165\u9501\u5b9a\uff0c\u5982\u679c\u6ca1\u6709\u52a0\u9501\uff0c\u5bfc\u81f4panic\nfunc (rw *RWMutex) Unlock()\n\/\/ \u9501\u5b9a\u4e3a\u8bfb\u53d6\u72b6\u6001\uff0c\u7981\u6b62\u5176\u4ed6\u7ebf\u7a0b\u5199\u5165\uff0c\u591a\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u540c\u65f6\u6301\u6709\u8bfb\u9501\u3002\nfunc (rw *RWMutex) RLock()\n\/\/ \u89e3\u9664\u8bfb\u53d6\u9501\uff0c\u5982\u679c\u6ca1\u6709\u52a0\u9501\uff0c\u5bfc\u81f4panic.\nfunc (rw *RWMutex) RUnlock()\n<\/code><\/pre>\n<h2 id=\"cond\">Cond<\/h2>\n<p>\u6761\u4ef6\u53d8\u91cf.<\/p>\n<pre><code>type Cond struct {\nL Locker\n}\n<\/code><\/pre>\n<p>function:<\/p>\n<pre><code>func NewCond(l Locker) *Cond\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>func (c *Cond) Broadcase()\nfunc (c *Cond) Signal()\nfunc (c *Cond) Wait()\n<\/code><\/pre>\n<h2 id=\"waitgroup\">WaitGroup<\/h2>\n<p>\u7528\u4e8e\u7b49\u5f85\u4e00\u7ec4\u7ebf\u7a0b\u7ed3\u675f\uff0c\u7236\u7ebf\u7a0b\u7528Add\u65b9\u6cd5\u6765\u8bbe\u5b9a\u5e94\u7b49\u5f85\u7684\u7ebf\u7a0b\u6570\u91cf;\n\u6bcf\u4e2a\u88ab\u7b49\u5f85\u7684\u7ebf\u7a0b\u5728\u7ed3\u675f\u65f6\u5e94\u8c03\u7528Done\u65b9\u6cd5;\n\u540c\u65f6\uff0c\u4e3b\u7ebf\u7a0b\u5e94\u8c03\u7528Wait\u65b9\u6cd5\u963b\u585e\u81f3\u6240\u6709\u7ebf\u7a0b\u7ed3\u675f\uff0e<\/p>\n<p>struct:<\/p>\n<pre><code>type WaitGroup sttruct {}\n<\/code><\/pre>\n<p>functions:<\/p>\n<p>methods:<\/p>\n<pre><code># \u589e\u52a0\u8ba1\u6570\nfunc (*WaitGroup) Add(delta int)\n# \u51cf\u5c11\u8ba1\u6570\nfunc (*WaitGroup) Done()\n# \u963b\u585e\u76f4\u5230\u8ba1\u6570\u5668\u4e3a0\nfunc (*WaitGroup) Wait()\n<\/code><\/pre>\n<hr>\n<h1 id=\"syncatomic\">sync\/atomic<\/h1>\n<p>\u63d0\u4f9b\u5e95\u5c42\u7684\u539f\u5b50\u7ea7\u5185\u5b58\u64cd\u4f5c\uff0c\u4e3b\u8981\u7528\u4e8egoroutine\u540c\u6b65.<\/p>\n<p>int32, int64, uint32, uint64, uintptr, pointer.<\/p>\n<h2 id=\"function\">function<\/h2>\n<pre><code>func AddInt64(addr *int64, delta int64) (new int64)\nfunc AddUint64(addr *uint64, delta uint64) (new uint64)\nfunc LoadInt64(addr *int64) (val int64)\nfunc LoadUint64(addr *uint64) (val uint64)\nfunc StoreInt64(addr *int64, val int64)\nfunc StoreUint64(addr *uint64, val uint64)\nfunc SwapInt64(addr *int64, new int64) (old int64)\nfunc SwapUint64(addr *uint64, new uint64) (old uint64)\nfunc CompareAndSwapInt64(addr *int64, old, new int64) (swapped bool)\nfunc CompareAndSwapUint64(addr *uint64, old, new uint64) (swapped bool)\n<\/code><\/pre>"},{"title":"GSL_cryptographic","link":"https:\/\/canuxcheng.com\/post\/gsl_cryptographic\/","pubDate":"Mon, 01 Jan 2018 10:49:21 +0000","guid":"https:\/\/canuxcheng.com\/post\/gsl_cryptographic\/","description":"<h1 id=\"crypto\">crypto<\/h1>\n<p>\u6536\u96c6\u4e86\u5e38\u7528\u7684\u5bc6\u7801\u5e38\u91cf<\/p>\n<h2 id=\"functions\">functions<\/h2>\n<pre><code>RegisterHash(h Hash, f func() hash.Hash)\n<\/code><\/pre>\n<h2 id=\"publickey\">PublicKey<\/h2>\n<p>interface:<\/p>\n<pre><code>type PublicKey interface{}\n<\/code><\/pre>\n<h2 id=\"privatekey\">PrivateKey<\/h2>\n<p>interface:<\/p>\n<pre><code>type PrivateKey interface{}\n<\/code><\/pre>\n<h2 id=\"hash\">Hash<\/h2>\n<pre><code>type Hash uint\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>func (h Hash) Avaliable() bool\nfunc (h Hash) Size() int\nfunc (h Hash) New() hash.Hash\n<\/code><\/pre>\n<hr>\n<h1 id=\"cryptocipher\">crypto\/cipher<\/h1>\n<p>\u7528\u4e8e\u5305\u88c5\u5e95\u5c42\u5757\u52a0\u5bc6\u7b97\u6cd5\u7684\u5b9e\u73b0.<\/p>\n<h2 id=\"block\">Block<\/h2>\n<p>\u4ee3\u8868\u4e00\u4e2a\u4f7f\u7528\u7279\u5b9a\u5bc6\u94a5\u7684\u5e95\u5c42\u3000\u52a0\uff0f\u89e3\u5bc6\u5668\uff0e<\/p>\n<pre><code>type Block interface {\nBlockSize() int\nEncrypt(dst, src []byte)\nDecrypt(dst, src []byte)\n}\n<\/code><\/pre>\n<h2 id=\"blockmode\">BlockMode<\/h2>\n<p>\u4ee3\u8868\u4e00\u4e2a\u5de5\u4f5c\u5728\u5757\u6a21\u5f0f(CBC, ECB\u7b49)\u7684\u52a0\uff0f\u89e3\u5bc6\u5668<\/p>\n<pre><code>type BlockMode interface {\nBlockSize() int\nCryptBlocks(dst, src []byte)\n}\n<\/code><\/pre>\n<p>function:<\/p>\n<pre><code>\/\/ \u8fd4\u56de\u4e00\u4e2aBlockMode\u63a5\u53e3\uff0c\u5e95\u5c42\u7528b\u52a0\u5bc6\uff0c\u521d\u59cb\u5411\u91cf\u957f\u5ea6\u7b49\u4e8eb\u7684\u5757\u5c3a\u5bf8.\nfunc NewCBCEncrypter(b Block, iv []byte) BlockMode\n\/\/ \u8fd4\u56de\u4e00\u4e2aBlockMode\u63a5\u53e3\uff0c\u5e95\u5c42\u7528b\u89e3\u5bc6\uff0c\u521d\u59cb\u5411\u91cf\u957f\u5ea6\u7b49\u4e8eb\u7684\u5757\u5c3a\u5bf8.\nfunc NewCBCDecrypter(b Block, iv []byte) BlockMode\n<\/code><\/pre>\n<h2 id=\"stream\">Stream<\/h2>\n<p>stream\u63a5\u53e3\u8868\u793a\u4e00\u4e2a\u6d41\u6a21\u5f0f\u7684\u52a0\uff0f\u89e3\u5bc6\u5668\uff0e<\/p>\n<pre><code>type Stream interface {\nXORKeyStream(dst, src []byte)\n}\n<\/code><\/pre>\n<p>function:<\/p>\n<pre><code>func NewCFBEncrypter(block Block, iv []byte) Stream\nfunc NewCFBDecrypter(block Block, iv []byte) Stream\nfunc NewOFB(b Block, iv []byte) Stream\nfunc NewCTR(b Block, iv []byte) Stream\n<\/code><\/pre>\n<hr>\n<h1 id=\"cryptorand\">crypto\/rand<\/h1>\n<p>\u7528\u4e8e\u52a0\u89e3\u5bc6\u7684\u66f4\u5b89\u5168\u7684\u968f\u673a\u6570\u751f\u6210\u5668.<\/p>\n<hr>\n<h1 id=\"cryptoaes\">crypto\/aes<\/h1>\n<p>\u5bf9\u79f0\u52a0\u5bc6\u7b97\u6cd5,aes\u52a0\u5bc6\u7b97\u6cd5\u7528\u4e8e\u53d6\u4ee3des\u7b97\u6cd5.<\/p>\n<h2 id=\"constants\">constants<\/h2>\n<pre><code>const BlockSize = 16\n<\/code><\/pre>\n<h2 id=\"function\">function<\/h2>\n<pre><code>\/\/ \u521b\u5efa\u4e00\u4e2acipher.Block\u63a5\u53e3, key\u4e3a\u5bc6\u94a5\uff0c\u957f\u5ea6\u53ea\u80fd\u662f16(aes-128),24(aes-192),32(aes-256)\u5b57\u8282.\nfunc NewCipher(key []byte) (cipher.Block, error)\n<\/code><\/pre>\n<hr>\n<h1 id=\"cryptodsa\">crypto\/dsa<\/h1>\n<p>\u975e\u5bf9\u79f0\uff0c\u6570\u5b57\u7b7e\u540d\u7b97\u6cd5dsa.<\/p>\n<hr>\n<h1 id=\"cryptorsa\">crypto\/rsa<\/h1>\n<p>\u975e\u5bf9\u79f0\u52a0\u5bc6\u7b97\u6cd5rsa.<\/p>\n<hr>\n<h1 id=\"cryptomd5\">crypto\/md5<\/h1>\n<h2 id=\"constants-1\">constants<\/h2>\n<pre><code>const BlockSize = 64\nconst Size = 16\n<\/code><\/pre>\n<h2 id=\"function-1\">function<\/h2>\n<pre><code>\/\/ \u8fd4\u56dedata\u7684ms5\u68c0\u9a8c\u548c\nfunc Sum(data []byte) [Size]byte\nfunc New() hash.Hash\n<\/code><\/pre>\n<hr>\n<h1 id=\"cryptosha1\">crypto\/sha1<\/h1>\n<h2 id=\"constants-2\">constants<\/h2>\n<pre><code>\/\/ SHA1\u5757\u5927\u5c0f\nconst BlockSize = 64\n\/\/ SHA1\u6821\u9a8c\u548c\u7684\u5b57\u8282\u6570\nconst Size = 20\n<\/code><\/pre>\n<h2 id=\"functions-1\">functions<\/h2>\n<pre><code>\/\/ \u8fd4\u56de\u6570\u636edata\u7684SHA1\u6821\u9a8c\u548c\nfunc Sum(data []byte) [Size]byte\n\/\/ \u8fd4\u56de\u4e00\u4e2a\u4f7f\u7528\u65b0\u7684SHA1\u6821\u9a8c\u7684hash.Hash\u63a5\u53e3\nfunc New() hash.Hash\n<\/code><\/pre>\n<hr>\n<h1 id=\"cryptosha256\">crypto\/sha256<\/h1>\n<hr>\n<h1 id=\"cryptosha512\">crypto\/sha512<\/h1>\n<hr>\n<h1 id=\"hash-1\">hash<\/h1>\n<h2 id=\"hash-2\">Hash<\/h2>\n<p>\u88ab\u6240\u6709hash\u51fd\u6570\u5b9e\u73b0\u7684\u516c\u5171\u63a5\u53e3<\/p>\n<p>interface:<\/p>\n<pre><code>type Hash interface {\nio.Writer\nSum(b []byte) []byte\nReset()\nSize() int\nBlockSize() int\n}\n<\/code><\/pre>\n<h2 id=\"hash32\">Hash32<\/h2>\n<p>\u88ab\u6240\u670932\u4f4dhash\u51fd\u6570\u5b9e\u73b0\u7684\u516c\u5171\u63a5\u53e3<\/p>\n<p>interface:<\/p>\n<pre><code>type Hash32 interface {\nHash\nSum32() uint32\n}\n<\/code><\/pre>\n<h2 id=\"hash64\">Hash64<\/h2>\n<p>\u88ab\u6240\u670964\u4f4dhash\u51fd\u6570\u5b9e\u73b0\u7684\u516c\u5171\u63a5\u53e3<\/p>\n<p>interface:<\/p>\n<pre><code>type Hash64 interface {\nHash\nSum64() uint64\n}\n<\/code><\/pre>\n<hr>\n<h1 id=\"hashadler32\">hash\/adler32<\/h1>\n<hr>\n<h1 id=\"hashcrc32\">hash\/crc32<\/h1>\n<hr>\n<h1 id=\"hashcrc64\">hash\/crc64<\/h1>\n<hr>\n<h1 id=\"hashfnv\">hash\/fnv<\/h1>\n<hr>"},{"title":"GSL_data","link":"https:\/\/canuxcheng.com\/post\/gsl_data\/","pubDate":"Mon, 01 Jan 2018 10:49:21 +0000","guid":"https:\/\/canuxcheng.com\/post\/gsl_data\/","description":"<h1 id=\"time\">time<\/h1>\n<h2 id=\"constants\">constants<\/h2>\n<p>const:<\/p>\n<pre><code>const (\nANSIC = &quot;Mon Jan _2 15:04:05 2006&quot;\nUnixdate = &quot;Mon Jan _2 15:04:05 MST 2006&quot;\nRFC3339 = &quot;2006-01-02T15:04:05Z07:00&quot;\n...\n)\n<\/code><\/pre>\n<h2 id=\"functions\">functions<\/h2>\n<pre><code>\/\/ \u963b\u585ego\u7a0bd\u4ee3\u8868\u7684\u65f6\u95f4\u6bb5\nfunc Sleep(d Duration)\nfunc After(d Duration) &lt;- chan Time\nfunc Tick(d Duration) &lt;- chan Time\n<\/code><\/pre>\n<h2 id=\"time-1\">Time<\/h2>\n<p>\u4ee3\u8868\u4e00\u4e2a\u7eb3\u79d2\u7cbe\u5ea6\u7684\u65f6\u95f4\u70b9.<\/p>\n<p>\u96f6\u503c\u662fJanuary 1, year 1, 00:00:00.000000000 UTC.<\/p>\n<p>struct:<\/p>\n<pre><code>type Time struct {}\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>\/\/ \u683c\u5f0f\u5316\u4e00\u4e2a\u65f6\u95f4, eg:\u30002009-11-10 15:00:00 -0800 PST\nfunc date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) Time\n\/\/ \u8fd4\u56de\u5f53\u524d\u672c\u5730\u65f6\u95f4, eg: 2018-03-18 12:16:55.842029 +0800 CST m=+0.001962301\nfunc Now() Time\nfunc Parse(layout, value s tring) (Time, error)\nfunc ParseInLocation(layout, value string, loc *Location) (Time, error)\nfunc Unix(sec int64, nsec int64) Time\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>\/\/ \u8fd4\u56deT\u7684\u5730\u70b9\u548c\u65f6\u533a\u4fe1\u606f\nfunc (t Time) Location() *Location\n\/\/ \u8fd4\u56det\u7684\u65f6\u533a\u89c4\u8303\u540d\u548c\u76f8\u5bf9\u4e8eUTC\u7684\u504f\u79fb\u91cf\nfunc (t Time) Zone() (name string, offset int)\nfunc (t Time) IsZero() bool\nfunc (t Time) Local() Time\nfunc (t Time) UTC() Time\nfunc (t Time) In(loc *Location) Time\nfunc (t Time) Unix() int64\nfunc (t Time) UnixNano() int64\n\/\/ \u6bd4\u8f83\u4e24\u4e2a\u65f6\u95f4\nfunc (t Time) Equal(u Time) bool\n\/\/ t &gt; u \u8fd4\u56detrue\nfunc (t Time) Before(u Time) bool\n\/\/ t &lt; u \u8fd4\u56detrue\nfunc (t Time) After(u Time) bool\n\/\/ \u8fd4\u56det\u7684\u5e74\u6708\u65e5.\nfunc (t Time) date() (year int, month Month, day int)\n\/\/ \u8fd4\u56det\u5bf9\u5e94\u7684\u65f6\u5206\u79d2\nfunc (t Time) Clock() (hour, min, sec int)\n\/\/ \u8fd4\u56det\u5bf9\u5e94\u7684\u5e74\nfunc (t Time) Year() int\n\/\/ \u8fd4\u56det\u5bf9\u5e94\u7684\u6708\nfunc (t Time) Month() Month\nfunc (t Time) ISOWeek() (year, week int)\n\/\/ \u8fd4\u56det\u5bf9\u5e94\u7684\u5f53\u5e74\u7684\u7b2c\u51e0\u5929\nfunc (t Time) YearDay() int\n\/\/ \u8fd4\u56det\u5bf9\u5e94\u7684\u5f53\u6708\u7684\u7b2c\u51e0\u5929\nfunc (t Time) Day() int\n\/\/ \u8fd4\u56det\u5bf9\u5e94\u7684\u661f\u671f\u51e0\nfunc (t Time) Weekday() Weekday\n\/\/ \u8fd4\u56det\u5bf9\u5e94\u7684\u7b2c\u51e0\u5c0f\u65f6\nfunc (t Time) Hour() int\n\/\/ \u8fd4\u56det\u5bf9\u5e94\u7684\u5206\u949f\nfunc (t Time) Minute() int\n\/\/ \u8fd4\u56det\u5bf9\u5e94\u7684\u79d2\nfunc (t Time) Second() int\n\/\/ \u8fd4\u56det\u5bf9\u5e94\u7684\u7eb3\u79d2\u504f\u79fb\u91cf\nfunc (t Time) Nanosecond() int\nfunc (t Time) Add(d Duration) Time\nfunc (t Time) Adddate(years int, months int, days int) Time\nfunc (t Time) Sub(u Time) Duration\nfunc (t Time) Round(d duration) Time\nfunc (t Time) Truncate(d Duration) Time\nfunc (t Time) Format(layout string) string\nfunc (t Time) String(layout string) string\n<\/code><\/pre>\n<h2 id=\"weekday\">Weekday<\/h2>\n<pre><code>type Weekday int\nconst (\nSunday Weekday = iota\nMonday\nTuesday\nWednesday\nThursday\nFriday\nSaturday\n)\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>\/\/ \u8fd4\u56ded\u5bf9\u5e94\u7684\u82f1\u6587\u540d\nfunc (d Weekday) String() string\n<\/code><\/pre>\n<h2 id=\"month\">Month<\/h2>\n<pre><code>type Month int\nconst (\nJanuary Month = 1 + iota\nFebruary\nMarch\nApril\nMay\nJune\nJuly\nAugust\nSeptember\nOctober\nNovember\nDecember\n)\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>\/\/ \u8fd4\u56dem\u5bf9\u5e94\u7684\u82f1\u6587\u540d\nfunc (m Month) String() string\n<\/code><\/pre>\n<h2 id=\"location\">Location<\/h2>\n<p>struct:<\/p>\n<pre><code>type Location struct {}\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>\/\/ \u8fd4\u56de\u4f7f\u7528\u7ed9\u5b9a\u540d\u5b57\u521b\u5efa\u7684Location\n\/\/ name == &quot;&quot; \u6216\u3000name == &quot;UTC&quot;, \u8fd4\u56deUTC\n\/\/ name == &quot;Local&quot;, fanhui1Local\n\/\/ \u5176\u5b83\u65f6\u95f4\u6570\u636e\u5e93\u7684\u503c\nfunc LoadLocation(name string) (*Location, error)\n\/\/ \u4f7f\u7528\u7ed9\u5b9a\u7684\u540d\u79f0\u548c\u504f\u79fb\u91cf\u521b\u5efa\u4e00\u4e2aLocation\nfunc FixedZone(name string, offset int) *Location\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>\/\/ \u8fd4\u56de\u5bf9\u65f6\u533a\u4fe1\u606f\u7684\u63cf\u8ff0\nfunc (l *Location) String() string\n<\/code><\/pre>\n<h2 id=\"duration\">Duration<\/h2>\n<h2 id=\"timer\">Timer<\/h2>\n<h2 id=\"ticker\">Ticker<\/h2>\n<hr>\n<h1 id=\"containerheap\">container\/heap<\/h1>\n<hr>\n<h1 id=\"containerlist\">container\/list<\/h1>\n<hr>\n<h1 id=\"containerring\">container\/ring<\/h1>\n<hr>\n<h1 id=\"compressbzip2\">compress\/bzip2<\/h1>\n<hr>\n<h1 id=\"compressflate\">compress\/flate<\/h1>\n<hr>\n<h1 id=\"compressgzip\">compress\/gzip<\/h1>\n<hr>\n<h1 id=\"compresslzw\">compress\/lzw<\/h1>\n<hr>\n<h1 id=\"compresszlib\">compress\/zlib<\/h1>\n<hr>\n<h1 id=\"archive\">archive<\/h1>\n<hr>"},{"title":"GSL_database","link":"https:\/\/canuxcheng.com\/post\/gsl_database\/","pubDate":"Mon, 01 Jan 2018 10:49:21 +0000","guid":"https:\/\/canuxcheng.com\/post\/gsl_database\/","description":"<h1 id=\"databasesql\">database\/sql<\/h1>\n<p>\u4f7f\u7528\u8be5\u5305\uff0c\u5fc5\u987b\u63d0\u4f9b\u4e00\u4e2a\u6570\u636e\u5e93\u9a71\u52a8<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/golang\/go\/wiki\/SQLDrivers\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/golang\/go\/wiki\/SQLDrivers<\/a><\/p>\n<p>mssql driver:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/denisenkom\/go-mssqldb\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/denisenkom\/go-mssqldb<\/a><\/p>\n<p>mysql driver:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/go-sql-driver\/mysql\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/go-sql-driver\/mysql<\/a><\/p>\n<p>postgresql driver:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/lib\/pq\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/lib\/pq<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/jackc\/pgx\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/jackc\/pgx<\/a><\/p>\n<h2 id=\"variables\">variables<\/h2>\n<pre><code>\/\/ QueryRow \u6ca1\u6709\u8fd4\u56derow\u65f6\uff0c\u8c03\u7528\u8fd4\u56de\u503c\u7684Scan\u65b9\u6cd5\u4f1a\u8fd4\u56de\u8be5\u53d8\u91cf\nvar ErrNoRows = errors.New(&quot;sql: no rows in result set&quot;)\n<\/code><\/pre>\n<h2 id=\"functions\">functions<\/h2>\n<pre><code>\/\/ \u6ce8\u518c\u5e76\u547d\u540d\u4e00\u4e2a\u6570\u636e\u5e93\uff0c\u5728Open\u4e2d\u4f7f\u7528\u8be5\u547d\u540d\u542f\u7528\u8be5\u9a71\u52a8\n\/\/ \u5982\u679c\u6ce8\u518c\u540c\u4e00\u540d\u79f0\u4e24\u6b21\u6216\u8005driver\u53c2\u6570\u4e3anil, \u4f1a\u5bfc\u81f4panic.\nRegister(name string, driver driver.Driver)\n<\/code><\/pre>\n<h2 id=\"db\">DB<\/h2>\n<p>DB\u662f\u4e00\u4e2a\u6570\u636e\u5e93\u53e5\u67c4\uff0c\u4ee3\u8868\u4e00\u4e2a\u5177\u6709\u96f6\u5230\u591a\u4e2a\u5e95\u5c42\u8fde\u63a5\u7684\u8fde\u63a5\u6c60\uff0e<\/p>\n<p>\u53ef\u4ee5\u5b89\u5168\u7684\u88ab\u591a\u4e2ago\u7a0b\u540c\u65f6\u4f7f\u7528\uff0e<\/p>\n<p>struct:<\/p>\n<pre><code>type DB struct {}\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>\/\/ \u9a8c\u8bc1\u6570\u636e\u5e93\u9a71\u52a8\u548c\u53c2\u6570,\u5e76\u4e0d\u521b\u5efa\u548c\u6570\u636e\u5e93\u7684\u8fde\u63a5\uff0e\n\/\/ driverName: mssql, mysql, postgres\n\/\/ mssql dataSourceName: &quot;server=%s;port=%d;database=%s;user id=%s;password=%s&quot;\n\/\/ mysql dataSourceName: &quot;user:password@tcp(server:port)\/database&quot;\nOpen(driverName, dataSourceName string) (*DB, error)\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>\/\/ \u8fd4\u56de\u6570\u636e\u5e93\u4e0b\u5c42\u9a71\u52a8\nfunc (db *DB) Driver() driver.Driver\n\/\/ \u521b\u5efa\u548c\u6570\u636e\u5e93\u7684\u8fde\u63a5,\u68c0\u67e5\u8fde\u63a5\u662f\u5426\u6709\u6548\nfunc (db *DB) Ping() error\n\/\/ \u5173\u95ed\u6570\u636e\u5e93\uff0c\u91ca\u653e\u8d44\u6e90\nfunc (db *DB) Close() error\n\/\/ \u8bbe\u7f6e\u4e0e\u6570\u636e\u5e93\u5efa\u7acb\u8fde\u63a5\u7684\u6700\u5927\u6570\u76ee, \u9ed8\u8ba4\uff10\u8868\u793a\u65e0\u9650\u5236.\nfunc (db *DB) SetMaxOpenConns(n int)\n\/\/ \u8bbe\u7f6e\u8fde\u63a5\u6c60\u4e2d\u7684\u6700\u5927\u95f2\u7f6e\u8fde\u63a5\u6570\nfunc (db *DB) SetMaxIdleConns(n int)\n\/\/ \u6267\u884c\u547d\u4ee4\u4f46\u662f\u4e0d\u8fd4\u56de\u6267\u884c\u7ed3\u679c,\u4e00\u822c\u7528\u4e8e(insert\/update\/delete)\nfunc (db *DB) Exec(query string, args ...interface{}) (Result, error)\n\/\/ \u6267\u884c\u547d\u4ee4\u8fd4\u56de\u591a\u884c\u7ed3\u679c\uff08\u4e00\u822c\u7528\u4e8eselect)\nfunc (db *DB) Query(query string, args ...interface{}) (*Rows, error)\n\/\/ \u6267\u884c\u547d\u4ee4\u6700\u591a\u8fd4\u56de\u4e00\u884c\u7ed3\u679c\n\/\/ \u603b\u662f\u8fd4\u56de\u975enil\u503c\uff0c\u76f4\u5230\u8fd4\u56de\u503c\u7684Scan\u65b9\u6cd5\u88ab\u8c03\u7528\uff0c\u624d\u4f1a\u8fd4\u56de\u88ab\u5ef6\u8fdf\u7684\u9519\u8bef.\nfunc (db *DB) QueryRow(query string, args ...interface{}) *Row\n\/\/ \u521b\u5efa\u4e00\u4e2a\u51c6\u5907\u597d\u7684\u72b6\u6001\u7528\u4e8e\u4e4b\u540e\u7684\u547d\u4ee4\nfunc (db *DB) Prepare(query string) (*Stmt, error)\n\/\/ \u5f00\u59cb\u4e00\u4e2a\u4e8b\u52a1\nfunc (db *DB) Begin() (*Tx, error)\n<\/code><\/pre>\n<h2 id=\"stmt\">Stmt<\/h2>\n<p>stmt\u662f\u51c6\u5907\u597d\u7684\u72b6\u6001\uff0c\u53ef\u4ee5\u5b89\u5168\u7684\u88ab\u591a\u4e2ago\u7a0b\u540c\u65f6\u4f7f\u7528\uff0e<\/p>\n<p>struct:<\/p>\n<pre><code>type Stmt struct {}\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>func (s *Stmt) Exec(args ...interface{}) (Result, error)\nfunc (s *Stmt) Query(args ...interface{}) (*Rows, error)\nfunc (s *Stmt) QueryRow(args ...interface{}) *Row\nfunc (s *Stmt) Close() error\n<\/code><\/pre>\n<h2 id=\"tx\">Tx<\/h2>\n<p>Tx\u8868\u793a\u4e00\u4e2a\u8fdb\u884c\u4e2d\u7684\u6570\u636e\u5e93\u4e8b\u52a1\uff0e<\/p>\n<p>\u4e00\u6b21\u4e8b\u52a1\u5fc5\u987b\u4ee5\u5bf9Commit\u6216Rollback\u7684\u8c03\u7528\u7ed3\u675f\uff0e<\/p>\n<p>\u4e8b\u52a1\u7ed3\u675f\u540e\uff0c\u6240\u6709\u7684\u64cd\u4f5c\u90fd\u4f1a\u5931\u8d25\u5e76\u8fd4\u56deErrTxDone.<\/p>\n<p>struct:<\/p>\n<pre><code>type Tx struct {}\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>func (tx *Tx) Exec(query string, args ...interface{}) (Result, error)\nfunc (tx *Tx) Query(query string, args ...interface{}) (*Rows, error)\nfunc (tx *Tx) QueryRow(query string, args ...interface{}) *Row\nfunc (tx *Tx) Prepare(query string) (*Stmt, error)\n\/\/ \u4f7f\u7528\u5df2\u5b58\u5728\u7684\u72b6\u6001\u751f\u6210\u4e00\u4e2a\u7279\u5b9a\u7684\u72b6\u6001\uff0e\nfunc (tx *Tx) Stmt(stmt *Stmt) *Stmt\n\/\/ \u63d0\u4ea4\u4e8b\u52a1\nfunc (tx *Tx) Commit() error\n\/\/ \u56de\u6eda\u4e8b\u52a1\nfunc (tx *Tx) Rollback() error\n<\/code><\/pre>\n<h2 id=\"scanner\">Scanner<\/h2>\n<p>interface:<\/p>\n<pre><code>type Scanner interface {\nScan(src interface{}) error\n}\n<\/code><\/pre>\n<h2 id=\"result\">Result<\/h2>\n<p>Exec\u65b9\u6cd5\u8fd4\u56deResult.<\/p>\n<pre><code>type Result interface {\nLastInsertId() (int64, error)\nRowsAffected() (int64, error)\n}\n<\/code><\/pre>\n<h2 id=\"row\">Row<\/h2>\n<p>QueryRow\u65b9\u6cd5\u8fd4\u56deRow, \u8868\u793a\u5355\u884c\u67e5\u8be2\u7ed3\u679c\uff0e<\/p>\n<p>struct:<\/p>\n<pre><code>type Row struct {}\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>\/\/ \u5c06\u8be5\u884c\u67e5\u8be2\u7ed3\u679c\u5404\u5217\u5206\u522b\u4fdd\u5b58\u8fdbdest\u53c2\u6570\u6307\u5b9a\u7684\u503c\u4e2d\uff0e\n\/\/ \u5982\u679c\u5339\u914d\u591a\u884c\uff0c\u53ea\u53d6\u7b2c\u4e00\u884c\uff0c\u5982\u679c\u6ca1\u6709\u5339\u914d\u884c\uff0c\u8fd4\u56deErrNoRows.\nfunc (r *Row) Scan(dest ...interface{}) error\n<\/code><\/pre>\n<h2 id=\"rows\">Rows<\/h2>\n<p>Query\u65b9\u6cd5\u8fd4\u56deRows, \u8868\u793a\u67e5\u8be2\u7684\u7ed3\u679c\u96c6\uff0c\u5b83\u7684\u6e38\u6807\u6307\u5411\u7b2c\uff10\u884c\uff0c\u4f7f\u7528Next\u65b9\u6cd5\u904d\u5386\u8be5\u7ed3\u679c\u96c6\uff0e<\/p>\n<p>struct:<\/p>\n<pre><code>type Rows struct {}\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>\/\/ \u8fd4\u56de\u5217\u540d\nfunc (rs *Rows) Columns() ([]string, error)\n\/\/ \u5c06\u5f53\u524d\u884c\u7684\u5404\u5217\u7ed3\u679c\u586b\u5145\u8fdbdest\nfunc (rs *Rows) Scan(dest ...interface{}) error\n\/\/ \u51c6\u5907\u7528\u4e8eScan\u7684\u4e0b\u4e00\u884c\u7ed3\u679c\uff0c\u6bcf\u6b21\u8c03\u7528Scan\u90fd\u8981\u5148\u8c03\u7528Next\nfunc (rs *Rows) Next() bool\nfunc (rs *Rows) Close() error\nfunc (rs *Rows) Err() error\n<\/code><\/pre>\n<hr>\n<h1 id=\"databasesqldriver\">database\/sql\/driver<\/h1>"},{"title":"GSL_file","link":"https:\/\/canuxcheng.com\/post\/gsl_file\/","pubDate":"Mon, 01 Jan 2018 10:49:21 +0000","guid":"https:\/\/canuxcheng.com\/post\/gsl_file\/","description":"<h1 id=\"path\">path<\/h1>\n<h2 id=\"function\">function<\/h2>\n<pre><code>func IsAbs(path string) bool\nfunc Join(elem ...string) string\nfunc Split(path string) (dir, file string)\nfunc Join(elem ...string) string\nfunc Dir(path string) string\nfunc Base(path string) string\nfunc Ext(path string) string\n...\n<\/code><\/pre>\n<hr>\n<h1 id=\"pathfilepath\">path\/filepath<\/h1>\n<h2 id=\"constants\">Constants<\/h2>\n<pre><code>const (\nSeparator = os.PathSeparator\nListSeparator = os.PathListSeparator\n)\n<\/code><\/pre>\n<h2 id=\"variable\">Variable<\/h2>\n<pre><code>var ErrBadPattern = errors.New(&quot;Syntax error in pattern&quot;)\nvar SkipDir = errors.New(&quot;skip this diractory&quot;)\n<\/code><\/pre>\n<h2 id=\"function-1\">function<\/h2>\n<pre><code>func IsAbs(path string) bool\nfunc Abs(path string) (string, error)\n\/\/ \u8fd4\u56de targpath \u76f8\u5bf9\u4e8e basepath \u7684 \u8def\u5f84 \uff08\u76f8\u5f53\u4e8e\u8fd4\u56de targpath - basepath), \u5b9e\u9645\u5c31\u662f\u6587\u4ef6\u540d.\nfunc Rel(basepath, targpath string) (string, error)\nfunc Split(path string) (dir, file string)\nfunc Join(elem ...string) string\nfunc Dir(path string) string\nfunc Base(path string) string\nfunc Ext(path string) string) \/\/ \u5305\u62ec\u5c0f\u6570\u70b9\nfunc Walk(root string, walkFn WalkFunc) error\n<\/code><\/pre>\n<h2 id=\"walkfunc\">WalkFunc<\/h2>\n<p>\u8c03\u7528Walk\u65f6\u4f1a\u5bf9\u6bcf\u4e2a\u76ee\u5f55\u548c\u6587\u4ef6\u8c03\u7528\u8be5\u51fd\u6570.<\/p>\n<p>\u5982\u679c\u8be5\u51fd\u6570\u8fd4\u56de\u9519\u8bef\uff0cWalk\u51fd\u6570\u4f1a\u4e2d\u6b62.<\/p>\n<p>\u5982\u679c\u8be5\u51fd\u6570\u8fd4\u56deSkipDir, Walk\u4f1a\u6389\u8fc7\u5904\u7406\u8be5\u76ee\u5f55\uff0c\u7ee7\u7eed\u5904\u7406\u5176\u5b83\u5185\u5bb9.<\/p>\n<pre><code>type WalkFunc func(path string, info os.FileInfo, err error) error\n<\/code><\/pre>\n<hr>\n<h1 id=\"encoding\">encoding<\/h1>\n<p>\u5b9a\u4e49\u4e86\u4f9b\u5176\u5b83\u5305\u4f7f\u7528\u7684\u5728\u5b57\u8282\u548c\u6587\u672c\u4e4b\u95f4\u8f6c\u6362\u6570\u636e\u7684\u63a5\u53e3.<\/p>\n<pre><code>import &quot;encoding&quot;\n<\/code><\/pre>\n<hr>\n<h1 id=\"encodingjson\">encoding\/json<\/h1>\n<p>go\u548cjson\u6570\u636e\u7c7b\u578b\u5bf9\u5e94\u5173\u7cfb\uff0c\u53c2\u8003WEB\/JSON.<\/p>\n<p>\u5728\u7ebf\u83b7\u53d6json\u7684go\u6570\u636e\u7ed3\u6784:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/mholt\/json-to-go\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/mholt\/json-to-go<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/mholt.github.io\/json-to-go\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/mholt.github.io\/json-to-go<\/a><\/p>\n<p>chan\/complex\/func\u7c7b\u578b\u4e0d\u80fd\u7f16\u7801\u4e3ajson.<\/p>\n<pre><code>import &quot;encoding\/json&quot;\n<\/code><\/pre>\n<h2 id=\"constants-1\">constants<\/h2>\n<h2 id=\"variables\">variables<\/h2>\n<h2 id=\"functions\">functions<\/h2>\n<pre><code># \u8fd4\u56degolang\u5bf9\u8c61v\u7684json\u7f16\u7801(\u5c06go\u7684\u5bf9\u8c61\u8f6c\u6362\u4e3ajson\u5bf9\u8c61), \u53ef\u4ee5\u6253tag.\n&gt; &quot;-&quot; \u8be5\u5b57\u6bb5\u4e0d\u4f1a\u8f93\u51fa\u5230json\n&gt; myName \u5728json\u4e2d\u7684\u540d\u5b57\n&gt; omitempty \u5141\u8bb8json\u4e2d\u6ca1\u6709\u8be5\u5b57\u6bb5\n&gt; Type \u5982\u679c\u6307\u5b9a\u7c7b\u578b\uff0c\u4f1a\u8f6c\u6362\u6210\u6307\u5b9a\u7684\u7c7b\u578b\u51fa\u73b0\u5728json\njson.Marshal(v interface{}) ([]byte, error)\n# \u5177\u6709\u7f29\u8fdb\u529f\u80fd\njson.MarshalIndent(v interface{}, prefix, indent string) ([]byte, error)\n# \u5c06json\u5bf9\u8c61data\u8f6c\u6362\u6210go\u5bf9\u8c61\uff0c\u5b58\u5165v\n# \u53ea\u6709\u53ef\u5bfc\u51fa\u5b57\u6bb5\u624d\u4f1a\u5728json\u4e2d\u627e\u5230.\n&gt; Bool \u5bf9\u5e94JSON\u5e03\u5c14\u7c7b\u578b\n&gt; float64 \u5bf9\u5e94JSON\u6570\u5b57\u7c7b\u578b\n&gt; string \u5bf9\u5e94JSON\u5b57\u7b26\u4e32\u7c7b\u578b\n&gt; []interface{} \u5bf9\u5e94JSON\u6570\u7ec4\n&gt; map[string]interface{} \u5bf9\u5e94JSON\u5bf9\u8c61\n&gt; nil \u5bf9\u5e94JSON\u7684null\njson.Unmarshal(data []byte, v interface{}) error\n\/\/ \u5c06json\u683c\u5f0f\u7684src\u4e2d\u7684\u65e0\u7528\u7684\u7a7a\u767d\u5b57\u7b26\u5254\u9664\u540e\u5199\u5165dst.\nfunc Compact(dst *bytes.Buffer, src []byte) error\n\/\/ \u683c\u5f0f\u5316json\uff0c\u4ee5\u4fbfjson\u7f16\u7801\u80fd\u5b89\u5168\u7684\u5d4c\u5165html\u7684&lt;script&gt;\u6807\u7b7e\nfunc HTMLEscape(dst *bytes.Buffer, src []byte)\n\/\/\nfunc Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error\n<\/code><\/pre>\n<h2 id=\"marshaler\">Marshaler<\/h2>\n<p>interface:<\/p>\n<pre><code>type Marshaler interface {\nMarshalJSON() ([]byte, error)\n}\n<\/code><\/pre>\n<h2 id=\"unmarshaler\">Unmarshaler<\/h2>\n<p>interface:<\/p>\n<pre><code>type Unmarshaler interface {\nUnmarshalJSON([] byte) error\n}\n<\/code><\/pre>\n<h2 id=\"decoder\">Decoder<\/h2>\n<p>\u4ece\u8f93\u5165\u6d41\u89e3\u7801json\u5bf9\u8c61<\/p>\n<p>struct:<\/p>\n<pre><code>type Decoder struct {}\n<\/code><\/pre>\n<p>function:<\/p>\n<pre><code>func NewDecoder(r io.Reader) *Decoder\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>\/\/ \u4ecedec\u8bfb\u53d6\u4e0b\u4e00\u4e2a\u5bf9\u8c61\u5b58\u5165v.\nfunc (dec *Decoder) Decode(v interface{}) error\n<\/code><\/pre>\n<h2 id=\"encoder\">Encoder<\/h2>\n<hr>\n<h1 id=\"encodingcsv\">encoding\/csv<\/h1>\n<hr>\n<h1 id=\"encodinggob\">encoding\/gob<\/h1>\n<p>go binary, go\u7684\u6570\u636e\u6301\u4e45\u5316\u5305\uff0c\u7528\u4e8e\u7f16\u7801\u5668\u548c\u89e3\u7801\u5668\u4e4b\u95f4\u4ea4\u6362\u4e8c\u8fdb\u5236\u6570\u636e.<\/p>\n<h2 id=\"functions-1\">functions<\/h2>\n<pre><code>func Register(value interface{})\nfunc RegisterName(name string, value interface{})\n<\/code><\/pre>\n<h2 id=\"gobdecoder\">GobDecoder<\/h2>\n<h2 id=\"gobencoder\">GobEncoder<\/h2>\n<h2 id=\"decoder-1\">Decoder<\/h2>\n<p>\u7ba1\u7406\u4ece\u8fdc\u7aef\u8bfb\u53d6\u6570\u636e\u7684\u7c7b\u578b\u548c\u4fe1\u606f\u7684\u89e3\u7801\u64cd\u4f5c.<\/p>\n<p>struct:<\/p>\n<pre><code>type Decoder struct {}\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>\/\/ \u8fd4\u56de\u4e00\u4e2a\u4ecer\u8bfb\u53d6\u6570\u636e\u7684Decoder\nfunc NewDecoder(r io.Reader) *Decoder\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code># \u4ecedec\u8bfb\u53d6\u4e0b\u4e00\u4e2a\u503c\u5e76\u5b58\u5165e\nfunc (dec *Decoder) Decode(e interface{}) error\nfunc (dec *Decoder) DecodeValue(v reflect.Value) error\n<\/code><\/pre>\n<h2 id=\"encoder-1\">Encoder<\/h2>\n<p>\u7ba1\u7406\u6570\u636e\u7c7b\u578b\u548c\u4fe1\u606f\u7f16\u7801\u540e\u53d1\u9001\u5230\u8fdc\u7aef\u7684\u64cd\u4f5c.<\/p>\n<p>struct:<\/p>\n<pre><code>type Encoder struct {}\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>\/\/ \u8fd4\u56de\u4e00\u4e2a\u5c06\u7f16\u7801\u540e\u6570\u636e\u5199\u5165w\u7684Encoder\nfunc NewEncoder(w io.Writer) *Encoder\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>\/\/ \u5c06e\u7f16\u7801\u540e\u53d1\u9001\u5230enc\nfunc (enc *Encoder) Encode(e interface{}) error\nfunc (enc *Encoder) EncodeValue(value reflect.Value) error\n<\/code><\/pre>\n<h2 id=\"commontype\">CommonType<\/h2>\n<pre><code>type CommonType struct {\nName string\nId typeId\n}\n<\/code><\/pre>\n<hr>\n<h1 id=\"texttemplate\">text\/template<\/h1>\n<hr>\n<h1 id=\"texttemplateparse\">text\/template\/parse<\/h1>\n<hr>\n<h1 id=\"textscanner\">text\/scanner<\/h1>\n<hr>\n<h1 id=\"texttabwriter\">text\/tabwriter<\/h1>\n<hr>\n<h1 id=\"html\">html<\/h1>\n<p>\u63d0\u4f9b\u4e86\u7528\u4e8e\u8f6c\u4e49\u548c\u89e3\u8f6c\u4e49html\u6587\u672c\u7684\u51fd\u6570\uff0e<\/p>\n<pre><code>import &quot;net&quot;\n<\/code><\/pre>\n<h2 id=\"functions-2\">functions<\/h2>\n<pre><code>\/\/ \u5c06\u3000&lt;, &gt;, &amp;, ', &quot; \u8f6c\u4e49\u4e3a\u5b57\u7b26\u5b9e\u4f53 &amp;lt, &amp;gt, &amp;#39,\nfunc EscapeString(s string) string\nfunc UnescapeString(s string) string\n<\/code><\/pre>\n<hr>\n<h1 id=\"htmltemplate\">html\/template<\/h1>\n<p>\u5b9e\u73b0\u4e86\u6570\u636e\u9a71\u52a8\u6a21\u677f\uff0c\u7528\u4e8e\u751f\u6210\u53ef\u5bf9\u6297\u4ee3\u7801\u6ce8\u5165\u7684\u5b89\u5168html\u8f93\u51fa\uff0e<\/p>\n<h2 id=\"functions-3\">functions<\/h2>\n<pre><code>\/\/ \u5c06b\u8f6c\u4e49\u540e\u5199\u5165w\uff0e\nfunc HTMLEscape(w io.Writer, b []byte)\n\/\/ \u8f6c\u4e49s\u4e4b\u540e,\u8fd4\u56de\u7ed3\u679c\u5b57\u7b26\u4e32.\nfunc HTMLEscapeString(s string) string\n\/\/ \u8f6c\u4e49\u591a\u4e2a\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u7ed3\u679c\u5b57\u7b26\u4e32.\nfunc HTMLEscaper(args ...interface{}) string\n<\/code><\/pre>\n<h2 id=\"funcmap\">FuncMap<\/h2>\n<p>\u5b9a\u4e49\u51fd\u6570\u540d\u5b57\u7b26\u4e32\u5230\u51fd\u6570\u7684\u6620\u5c04\uff0c\u6bcf\u4e2a\u51fd\u6570\u5fc5\u987b\u89811\u52302\u4e2a\u8fd4\u56de\u503c\uff0e<\/p>\n<pre><code>type FuncMap map[string]interface{}\n<\/code><\/pre>\n<h2 id=\"template\">Template<\/h2>\n<pre><code>type Template struct {\nTree *parse.Tree\n}\n<\/code><\/pre>\n<p>function:<\/p>\n<pre><code>\/\/ \u521b\u5efa\u540d\u4e3aname\u7684\u6a21\u677f\nfunc New(name string) *Template\n\/\/ \u5728err\u975enil\u65f6panic, \u68c0\u6d4b\u6a21\u677f\u662f\u5426\u6b63\u786e\uff0e\n\/\/ \u901a\u8fc7template.New().Parse() \u8fd4\u56de\u503c\u4f5c\u4e3a\u53c2\u6570.\nfunc Must(t *Template, err error) *Template\n\/\/ \u521b\u5efa\u4e00\u4e2a\u6a21\u677f\uff0c\u5e76\u89e3\u6790filenames\u4f5c\u4e3a\u6a21\u677f\u5185\u5bb9\n\/\/ \u7b2c\u4e00\u4e2a\u6587\u4ef6\u540d\u4e3a\u6a21\u677f\u540d\u5b57(\u4e0d\u5305\u62ec\u6269\u5c55\u540d)\nfunc ParseFiles(filenames ...string) (*Template, error)\n\/\/ \u521b\u5efa\u4e00\u4e2a\u6a21\u677f\uff0c\u5e76\u89e3\u6790\u5339\u914dpattern\u7684\u6587\u4ef6\uff0e\n\/\/ \u5339\u914d\u7684\u7b2c\u4e00\u4e2a\u6587\u4ef6\u540d\u4e3a\u6a21\u677f\u540d\u5b57(\u4e0d\u5305\u62ec\u6269\u5c55\u540d)\nfunc ParseGlob(pattern string) (*Template, error)\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>\/\/ \u5c06\u5b57\u7b26\u4e32str\u89e3\u6790\u4e3a\u6a21\u677f\nfunc (t *Template) Parse(str string) (*Template, error)\n\/\/ \u5c06\u6587\u4ef6\u89e3\u6790\u4e3a\u6a21\u677f\nfunc (t *Template) ParseFiles(filenames ...string) (*Template, error)\n\/\/\nfunc (t *Template) ParseGlob(pattern string) (*Template, error)\n\/\/ \u5c06\u89e3\u6790\u597d\u7684\u6a21\u677f\u5e94\u7528\u5230data\u4e0a\uff0c\u5e76\u5c06\u8f93\u51fa\u5199\u5165wr.\nfunc (t *Template) Execute(wr io.Writer, data interface{}) (err error)\n\/\/ \u4f7f\u7528\u548ct\u5173\u8054\u7684\u540d\u4e3aname\u7684\u6a21\u677f\nfunc (t *Template) ExecuteTemplate(wr io.Writer, name string, data interface{}) error\n\/\/ \u6ce8\u518c\u51fd\u6570\u5230\u6a21\u677ft, funcMap\u7684key\u662f\u6a21\u677f\u4e2d\u8c03\u7528\u7684\u51fd\u6570\u540d\uff0cvalue\u662f\u5b9e\u9645\u7684\u51fd\u6570\nfunc (t *Template) Funcs(funcMap FuncMap) *Template\n<\/code><\/pre>\n<hr>\n<h1 id=\"yaml\">yaml<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/go-yaml\/yaml\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/go-yaml\/yaml<\/a><\/p>\n<hr>\n<h1 id=\"toml\">toml<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/toml-lang\/toml\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/toml-lang\/toml<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/BurntSushi\/toml\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/BurntSushi\/toml<\/a><\/p>"},{"title":"GSL_golang","link":"https:\/\/canuxcheng.com\/post\/gsl_golang\/","pubDate":"Mon, 01 Jan 2018 10:49:21 +0000","guid":"https:\/\/canuxcheng.com\/post\/gsl_golang\/","description":"<h1 id=\"runtime\">runtime<\/h1>\n<h2 id=\"constants\">constants<\/h2>\n<pre><code>\/\/ \u6307\u5b9a\u7f16\u8bd1\u5668\nconst Compiler = &quot;gc&quot;\/&quot;gccgo&quot;\n\/\/ \u5904\u7406\u5668\u67b6\u6784: 386\/amd64\/arm\nconst GOARCH string = theGoarch\n\/\/ \u64cd\u4f5c\u7cfb\u7edf: linux\/freebsd\/darwin\/win\nconst GOOS string = theGoos\n<\/code><\/pre>\n<h2 id=\"variables\">variables<\/h2>\n<pre><code>var MemProfileRate int = 512 * 1024\n<\/code><\/pre>\n<h2 id=\"functions\">functions<\/h2>\n<pre><code>func GOROOT() string\nfunc Version() string\n\/\/ \u8fd4\u56de\u672c\u5730\u673a\u5668\u7684\u903b\u8f91cpu\u4e2a\u6570\nfunc NumCPU() int\n\/\/\u66f4\u6539\u8c03\u5ea6\u5668\u53ef\u4ee5\u4f7f\u7528\u7684\u903b\u8f91cpu\u6570\u91cf, \u9ed8\u8ba4\u53ea\u7528\u4e00\u4e2acpu.\nfunc GOMAXPROCS(n int) int\n\/\/ \u4f7f\u5f53\u524dgoroutine\u8ba9\u51fa\u7ed1\u5b9a\u7684cpu,\u5176\u5b83goroutine\u53ef\u4ee5\u7ee7\u7eed\u6267\u884c.\n\/\/ \u5f53\u524dgoroutine\u653e\u56de\u961f\u5217\u7b49\u5f85\u7ee7\u7eed\u6267\u884c.\nfunc Gosched()\n\/\/ \u7ec8\u6b62\u5f53\u524dgoroutine,\u7ec8\u6b62\u524d\u6267\u884c\u6240\u6709defer.\nfunc Goexit()\n<\/code><\/pre>\n<hr>\n<h1 id=\"runtimedebug\">runtime\/debug<\/h1>\n<h2 id=\"function\">function<\/h2>\n<pre><code>\/\/ \u8bbe\u7f6e\u6700\u5927\u7ebf\u7a0b\u6570\uff0c\u9ed8\u8ba41000.\nfunc SetMaxThreads(threads int) int\n<\/code><\/pre>\n<hr>\n<h1 id=\"runtimecgo\">runtime\/cgo<\/h1>\n<hr>\n<h1 id=\"runtimepprof\">runtime\/pprof<\/h1>\n<hr>\n<h1 id=\"runtimerace\">runtime\/race<\/h1>\n<hr>\n<h1 id=\"runtimetrace\">runtime\/trace<\/h1>\n<hr>\n<h1 id=\"go\">go<\/h1>\n<hr>\n<h1 id=\"expvar\">expvar<\/h1>\n<hr>\n<h1 id=\"context\">context<\/h1>\n<hr>\n<h1 id=\"unsafe\">unsafe<\/h1>\n<hr>\n<h1 id=\"errors\">errors<\/h1>\n<h2 id=\"function-1\">function<\/h2>\n<pre><code>\/\/ \u4f7f\u7528\u5b57\u7b26\u4e32\u521b\u5efa\u4e00\u4e2a\u9519\u8bef, \u8fd4\u56de\u4e00\u4e2aerror\nfunc New(text string) error\n<\/code><\/pre>"},{"title":"GSL_math","link":"https:\/\/canuxcheng.com\/post\/gsl_math\/","pubDate":"Mon, 01 Jan 2018 10:49:21 +0000","guid":"https:\/\/canuxcheng.com\/post\/gsl_math\/","description":"<h1 id=\"math\">math<\/h1>\n<h2 id=\"constants\">constants<\/h2>\n<h2 id=\"variables\">variables<\/h2>\n<h2 id=\"functions\">functions<\/h2>\n<hr>\n<h1 id=\"mathbig\">math\/big<\/h1>\n<hr>\n<h1 id=\"mathcmplx\">math\/cmplx<\/h1>\n<hr>\n<h1 id=\"mathrand\">math\/rand<\/h1>\n<hr>\n<h1 id=\"sort\">sort<\/h1>\n<h2 id=\"functions-1\">functions<\/h2>\n<pre><code>func Ints(a []int)\nfunc IntAreSorted(a []int) bool\nfunc SearchInts(a []int, x int) int\nfunc Float64s(a []float64)\nfunc Float64sArerSorted(a []float64) bool\nfunc SearchFloat64s(a []float64, x float64) int\nfunc Strings(a []string)\nfunc StringsAreSorted(a []string) bool\nfunc SearchStrings(a []string, x string) int\nfunc Sort(data Interface)\nfunc Stable(data Interface)\nfunc IsSorted(data Interface) bool\nfunc Reverse(data Interface) Interface\n\/\/ \u4e8c\u5206\u67e5\u627e\nfunc Search(n int, f func(int) bool) int\n<\/code><\/pre>\n<h2 id=\"interface\">Interface<\/h2>\n<pre><code>type Interface interface {\nLen() int\nLess(i, j int) bool\nSwap(i, j int)\n}\n<\/code><\/pre>\n<h2 id=\"initslice\">InitSlice<\/h2>\n<pre><code>type InitSlice []int\n<\/code><\/pre>\n<h2 id=\"float64slice\">Float64Slice<\/h2>\n<pre><code>type Float64Slice []float64\n<\/code><\/pre>\n<h2 id=\"stringslice\">StringSlice<\/h2>\n<pre><code>type StringSlice []string\n<\/code><\/pre>\n<hr>"},{"title":"GSL_multimedia","link":"https:\/\/canuxcheng.com\/post\/gsl_multimedia\/","pubDate":"Mon, 01 Jan 2018 10:49:21 +0000","guid":"https:\/\/canuxcheng.com\/post\/gsl_multimedia\/","description":"<h1 id=\"image\">image<\/h1>\n<hr>\n<h1 id=\"mime\">mime<\/h1>"},{"title":"GSL_network","link":"https:\/\/canuxcheng.com\/post\/gsl_network\/","pubDate":"Mon, 01 Jan 2018 10:49:21 +0000","guid":"https:\/\/canuxcheng.com\/post\/gsl_network\/","description":"<h1 id=\"net\">net<\/h1>\n<p>\u7f51\u7edcIO\u63a5\u53e3\uff0c\u5305\u62ecTCP\/IP, UDP, SOCKET, DNS<\/p>\n<pre><code>import &quot;net&quot;\n<\/code><\/pre>\n<h2 id=\"constants\">constants<\/h2>\n<pre><code>const (\nIPv4len = 4\nIPv6len = 16\n)\n<\/code><\/pre>\n<h2 id=\"variables\">variables<\/h2>\n<h2 id=\"functions\">functions<\/h2>\n<h2 id=\"addr\">Addr<\/h2>\n<p>\u4ee3\u8868\u4e00\u4e2a\u7f51\u7edc\u7ec8\u7aef\u5730\u5740\uff0e<\/p>\n<p>TCPAddr, UDPAddr, IPAddr, UnixAddr \u90fd\u5b9e\u73b0\u4e86\u8be5\u63a5\u53e3<\/p>\n<pre><code>type Addr interface {\nNetwork() string\nString() string\n}\n<\/code><\/pre>\n<h2 id=\"tcpaddr\">TCPAddr<\/h2>\n<p>function:<\/p>\n<pre><code>func ResolveTCPAddr(net, addr string) (*TCPAddr, error)\n<\/code><\/pre>\n<h2 id=\"udpaddr\">UDPAddr<\/h2>\n<p>function:<\/p>\n<pre><code>func ResolveUDPAddr(net, addr string) (*UDPAddr, error)\n<\/code><\/pre>\n<h2 id=\"ipaddr\">IPAddr<\/h2>\n<p>function:<\/p>\n<pre><code>func ResolveIPAddr(net, addr string) (*IPAddr, error)\n<\/code><\/pre>\n<h2 id=\"unixaddr\">UnixAddr<\/h2>\n<p>function:<\/p>\n<pre><code>func ResolveUnixAddr(net, addr string) (*UnixAddr, error)\n<\/code><\/pre>\n<h2 id=\"conn\">Conn<\/h2>\n<p>\u8be5\u63a5\u53e3\u4ee3\u8868\u901a\u7528\u7684\u9762\u5411\u6d41\u7684\u7f51\u7edc\u8fde\u63a5\uff0e<\/p>\n<pre><code>type Conn interface {\nRead()\nWrite()\nClose()\nLocalAddr()\nRemoteAddr()\nSetDeadline()\nSetReadDeadline()\nsetWriteDeadline()\n}\n<\/code><\/pre>\n<p>function:<\/p>\n<pre><code>\/\/ tcp: &quot;tcp&quot;\u3001&quot;tcp4&quot;\u3001&quot;tcp6&quot;\u3001\n\/\/ unix: &quot;unix&quot;, &quot;unixpacket&quot;\n\/\/ unix: &quot;unixgramh&quot;\n\/\/ udp: &quot;udp&quot;\u3001&quot;udp4&quot;\u3001&quot;udp6&quot;\u3001\n\/\/ ip: &quot;ip&quot;\u3001&quot;ip4&quot;\u3001&quot;ip6&quot;\u3001\nfunc Dail(network, address string) (Conn, error)\nfunc DialTimeout(network, address string, timeout time.Duration) (Conn, error)\nfunc Pipe() (Conn, Conn)\n<\/code><\/pre>\n<h2 id=\"packetconn\">PacketConn<\/h2>\n<p>\u8be5\u63a5\u53e3\u4ee3\u8868\u901a\u7528\u7684\u9762\u5411\u6570\u636e\u5305\u7684\u7f51\u7edc\u8fde\u63a5\uff0e<\/p>\n<pre><code>type PacketConn interface {\nReadDrom()\nWriteTo()\nClose()\nLocalAddr()\nSetDeadline()\nSetReadDeadline()\nSetWriteDeadline()\n}\n<\/code><\/pre>\n<p>function:<\/p>\n<pre><code>\/\/ ip: &quot;ip&quot;\u3001&quot;ip4&quot;\u3001&quot;ip6&quot;\u3001\n\/\/ udp: &quot;udp&quot;\u3001&quot;udp4&quot;\u3001&quot;udp6&quot;\u3001\n\/\/ unix: &quot;unixgram&quot;\nfunc ListenPacket(net, laddr string) (PacketConn, error)\n<\/code><\/pre>\n<h2 id=\"listener\">Listener<\/h2>\n<p>\u901a\u7528\u7684\u9762\u5411\u6d41\u7684\u7f51\u7edc\u534f\u8bae\u7684\u516c\u7528\u7684\u7f51\u7edc\u76d1\u542c\u63a5\u53e3\uff0e<\/p>\n<pre><code>type Listener interface {\nAddr() addr\nAccept() (c Conn, err error)\nClose() error\n}\n<\/code><\/pre>\n<p>function:<\/p>\n<pre><code>\/\/ tcp: &quot;tcp&quot;\u3001&quot;tcp4&quot;\u3001&quot;tcp6&quot;\u3001\n\/\/ unix: &quot;unix&quot;, &quot;unixpacket&quot;\nfunc Listen(net, laddr string) (Listener, error)\n<\/code><\/pre>\n<h2 id=\"ipconn\">IPConn<\/h2>\n<p>\u5b9e\u73b0\u4e86Conn\u548cPacketConn\u63a5\u53e3\uff0e<\/p>\n<p>function:<\/p>\n<pre><code>func DilIP(netProto string, laddr, raddr *IPAddr) (*IPConn, error)\nfunc ListenIP(netProto string, laddr *IPAddr) (*IPConn, error)\n<\/code><\/pre>\n<p>method:<\/p>\n<h2 id=\"udpconn\">UDPConn<\/h2>\n<p>\u5b9e\u73b0\u4e86Conn\u548cPacketConn\u63a5\u53e3.<\/p>\n<p>function:<\/p>\n<pre><code>func DialUDP(net string, laddr, raddr *UDPAddr) (*UDPConn, error)\nfunc ListenDUP(net string, laddr *UDPAddr) (*UDPConn, error)\n<\/code><\/pre>\n<p>method:<\/p>\n<h2 id=\"tcpconn\">TCPConn<\/h2>\n<p>\u5b9e\u73b0\u4e86Conn\u63a5\u53e3.<\/p>\n<p>function:<\/p>\n<pre><code>func DialTCP(net string, laddr, raddr *TCPAddr) (*TCPConn, error)\n<\/code><\/pre>\n<p>method:<\/p>\n<h2 id=\"tcplistener\">TCPListener<\/h2>\n<p>function:<\/p>\n<pre><code>func ListenTCP(net string, laddr *TCPAddr) (*TCPListener, error)\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>func (l *TCPListener) Accept() (Conn, error)\n<\/code><\/pre>\n<h2 id=\"unixconn\">UnixConn<\/h2>\n<p>\u5b9e\u73b0\u4e86Conn\u548cPacketConn\u63a5\u53e3.<\/p>\n<p>function:<\/p>\n<pre><code>func DialUnix(net string, laddr, raddr *UnixAddr) (*UnixConn, error)\nfunc ListenUnixgram(net string, laddr *UnixAddr) (*UnixConn, error)\n<\/code><\/pre>\n<p>method:<\/p>\n<h2 id=\"unixlistener\">UnixListener<\/h2>\n<p>function:<\/p>\n<pre><code>func ListenUnix(net string, laddr *UnixAddr) (*UnixListener, error)\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>func (l *UnixListener) Accept() (c Conn, err error)\nfunc (l *UnixListener) AcceptUnix() (*UnixConn, error)\n<\/code><\/pre>\n<hr>\n<h1 id=\"nethttp\">net\/http<\/h1>\n<p>http\u534f\u8bae\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u7684\u5b9e\u73b0<\/p>\n<pre><code>import &quot;net\/http&quot;\n<\/code><\/pre>\n<h2 id=\"constants-1\">constants<\/h2>\n<pre><code>const (\nMethodGet = &quot;GET&quot;\nMethodHead = &quot;HEAD&quot;\nMethodPost = &quot;POST&quot;\nMethodPut = &quot;PUT&quot;\nMethodPatch = &quot;PATCH&quot;\nMethodDelete = &quot;DELETE&quot;\nMethodConnect = &quot;CONNECT&quot;\nMethodOptions = &quot;OPTIONS&quot;\nMethodTrace = &quot;TRACE&quot;\n)\n<\/code><\/pre>\n<h2 id=\"variables-1\">variables<\/h2>\n<h2 id=\"functions-1\">functions<\/h2>\n<pre><code>\/\/ \u5728w\u7684header\u4e2d\u6dfb\u52a0Set-Cookie\u5934\uff0e\nfunc SetCookie(w ResponseWriter, cookie *Cookie)\nfunc Handle(pattern string, handler Handler)\n\/\/ \u6ce8\u518c\u4e00\u4e2ahandler\u548c\u5bf9\u5e94\u7684pattern \u5230DefaultServeMux.\nfunc HandlerFunc(pattern string, handler func(ResponseWriter, *Request))\n\/\/ \u4e3a\u76d1\u542c\u5668\u6536\u5230\u7684\u6bcf\u4e2a\u8fde\u63a5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684goroutine\uff0e\n\/\/ goroutine \u4f1a\u8bfb\u53d6\u8bf7\u6c42\u5e76\u8c03\u7528handler\u56de\u590d\u8be5\u8bf7\u6c42\uff0e\nfunc Serve(l net.Listener, handler Handler) error\n\/\/ \u76d1\u542ctcp\u5730\u5740addr, \u4f7f\u7528handler\u53c2\u6570\u8c03\u7528Serve\u51fd\u6570\u5904\u7406\u8fde\u63a5\uff0e\n\/\/ handler = nil \u76f8\u5f53\u4e8eDefaultServeMux\nfunc ListenAndServe(addr string, handler Handler) error\n<\/code><\/pre>\n<h2 id=\"file\">File<\/h2>\n<pre><code>type File interface {\nio.Closer\nio.Reader\nReaddir(count int) ([]os.FileInfo, error)\nSeek(offset int64, whence int) (int64, error)\nStat() (os.FileInfo, error)\n}\n<\/code><\/pre>\n<h2 id=\"filesystem\">FileSystem<\/h2>\n<pre><code>type FileSystem interface {\nOpen(name string) (File, error)\n}\n<\/code><\/pre>\n<h2 id=\"dir\">Dir<\/h2>\n<pre><code>type Dir string\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>func (d Dir) Open(name string) (File, error)\n<\/code><\/pre>\n<h2 id=\"handler\">Handler<\/h2>\n<p>\u5b9e\u73b0Handler\u63a5\u53e3\u7684\u5bf9\u8c61\u53ef\u4ee5\u88ab\u6ce8\u518c\u4e3ahttp\u7684\u670d\u52a1\u51fd\u6570<\/p>\n<pre><code>type Handler interface {\nServeHTTP(ResponseWriter, *Request)\n}\n<\/code><\/pre>\n<p>function:<\/p>\n<pre><code>\/\/ \u5bf9\u6bcf\u4e2a\u8bf7\u6c42\u56de\u590d&quot;404 page not found&quot;\nfunc NotFoundHandler() Handler\n\/\/ \u5bf9\u6bcf\u4e2a\u8bf7\u6c42\u4f7f\u7528\u72b6\u6001\u7801code\u91cd\u5b9a\u5411\u5230url.\nfunc RedirectHandler(url string, code int) Handler\nfunc TimeoutHandler(h Handler, dt time.Duration, msg string) Handler\n\/\/ \u5c06\u8bf7\u6c42\u7684URL.Path\u4e2d\u7684\u524d\u7f00prefix\u53bb\u9664\u540e\u518d\u7ed9h.\nfunc StripPrefix(prefix string, h Handler) Handler\nfunc FileServer(root FileSystem) Handler\n<\/code><\/pre>\n<h2 id=\"handlerfunc\">HandlerFunc<\/h2>\n<p>\u5c06\u666e\u901a\u51fd\u6570\u8f6c\u6362\u6210http\u7684\u670d\u52a1\u51fd\u6570<\/p>\n<pre><code>type HandlerFunc func(ResponseWriter, *Request)\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>\/\/ ServeHTTP\u4f1a\u8c03\u7528f(w, r)\nfunc (f HandlerFunc) ServeHTTP(w ResponseWriter, r *Request)\n<\/code><\/pre>\n<h2 id=\"servemux\">ServeMux<\/h2>\n<p>ServeMux\u662fhttp\u8bf7\u6c42\u7684\u591a\u8def\u8f6c\u63a5\u5668\uff0e<\/p>\n<pre><code>type ServeMux struct {}\n<\/code><\/pre>\n<p>function:<\/p>\n<pre><code>\/\/ \u521b\u5efa\u5e76\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684*ServeMux\nfunc NewServeMux() *ServeMux\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>\/\/\nfunc (mux *ServeMux) Handle(pattern string, handler Handler)\nfunc (mux *ServeMux) HandleFunc(pattern string, handler func(ResponseWriter, *Request))\nfunc (mux *ServeMux) Handler(r *Request) (h Handler, pattern string)\nfunc (mux *ServeMux) ServeHTTP(w ResponseWriter, r *Request)\n<\/code><\/pre>\n<h2 id=\"server\">Server<\/h2>\n<p>\u5b9a\u4e49\u4e86\u8fd0\u884chttp\u670d\u52a1\u7aef\u7684\u53c2\u6570\uff0e<\/p>\n<pre><code>type Server struct {\nAddr string\nHandler Handler\nReadTimeout time.Duration\nWriteTimeout time.Duration\nMaxHeaderBytes int\nTLSConfig *tls.Config\nTLSNextProto map[string]func(*Server, *tls.Conn, Handler)\nConnState func(net.Conn, ConnState)\nErrorLog *log.Logger\n}\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>func (s *Server) SetKeepAlivesEnabled(v bool)\nfunc (s *Server) Serve(l net.Listener) error\nfunc (s *Server) ListenAndServe() error\nfunc (s *Server) ListenAndServeTLS(certFile, keyFile string) error\n<\/code><\/pre>\n<h2 id=\"client\">Client<\/h2>\n<p>\u4ee3\u8868\u4e00\u4e2ahttp\u5ba2\u6237\u7aef.<\/p>\n<pre><code>type Client struct {\nTransport RoundTripper\nCheckRedirect func(req *Request, via []*Request) error\nJar CookieJar\nTimeout time.Duration\n}\n<\/code><\/pre>\n<h2 id=\"header\">Header<\/h2>\n<p>\u4ee3\u8868http\u7684\u5934\u90e8.<\/p>\n<pre><code>type Header map[string][]string\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>func (h Header) Get(key string) string\nfunc (h Header) Set(key, value string)\n...\n<\/code><\/pre>\n<h2 id=\"cookie\">Cookie<\/h2>\n<p>\u4ee3\u8868\u4e00\u4e2ahttp\u56de\u590d\u7684\u5934\u90e8\u4e2dSetCookie\u5934\u7684\u503c\uff0c\u6216http\u8bf7\u6c42\u7684\u5934\u90e8\u91cc\u9762\u7684cookie\u503c\uff0e<\/p>\n<pre><code>type Cookie struct {\nName string\nValue string\nPath string\nDomain string\nExpires time.Time\nRawExpires string\nMaxAge int\nSecure bool\nHttpOnly bool\nRaw string\nUnparsed []string\n}\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>\/\/ \u8fd4\u56decookie\u5e8f\u5217\u5316\u7684\u7ed3\u679c\nfunc (c *Cookie) String() string\n<\/code><\/pre>\n<h2 id=\"request\">Request<\/h2>\n<p>\u4ee3\u8868\u4e00\u4e2a\u670d\u52a1\u7aef\u63a5\u6536\u7684\u6216\u5ba2\u6237\u7aef\u53d1\u9001\u7684http\u8bf7\u6c42.<\/p>\n<pre><code>type Request struct {\nMethod string\nURL *url.URL\nProto string \/\/ &quot;HTTP\/1.0&quot;\nProtoMajor int \/\/ 1\nProtoMinor int \/\/ 0\nHeader Header\nBody io.ReadCloser\nContentLength int64\nTransferEncoding []string\nClose bool\nHost string\nForm url.Values\nPostForm url.Values\nMultipartForm *multipart.Form\nTrailer Header\nRemoteAddr string\nRequestURI string\nTSL *tls.ConnectionState\n}\n<\/code><\/pre>\n<p>function:<\/p>\n<pre><code>func NewRequest(method, urlStr string, body io.Reader) (*Request, error)\nfunc ReadRequest(b *bufio.Reader) (req *Request, err error)\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>\/\/ \u89e3\u6790\u5e76\u8fd4\u56de\u8be5\u8bf7\u6c42r\u7684header\u8bbe\u7f6e\u7684cookie\nfunc (r *Request) Cookies() []*Cookie\n\/\/ \u8fd4\u56de\u8bf7\u6c42r\u4e2d\u547d\u540d\u4e3aname\u7684cookie,\u5982\u679c\u672a\u627e\u5230\u8fd4\u56denil, ErrNoCookie.\nfunc (r *Request) Cookie(name string) (*cookie, error)\n\/\/\u89e3\u6790r.URL\u4e2d\u7684\u67e5\u8be2\u5b57\u7b26\u4e32\uff0c\u5e76\u5c06\u89e3\u6790\u7ed3\u679c\u66f4\u65b0\u5230r.Form\u5b57\u6bb5.\n\/\/ post\u548cput\u7684body\u4f1a\u540c\u65f6\u66f4\u65b0\u5230r.PostForm\u548cr.Form.\nfunc (r *Request) ParseForm() error\n\/\/ \u5c06\u8bf7\u6c42\u7684\u4e3b\u4f53\u4f5c\u4e3amultipart\/form-data\u89e3\u6790.\nfunc (r *Request) ParseMultipartForm(maxMemory int64) error\n<\/code><\/pre>\n<h2 id=\"response\">Response<\/h2>\n<p>\u4ee3\u8868\u4e00\u4e2ahttp\u8bf7\u6c42\u7684\u56de\u590dr<\/p>\n<pre><code>type Response struct {\nStatus string\nStatusCode int\nProto string\nProtoMajor int\nProtoMinor int\nHeader Header\nBody io.ReadCloser\nContentLength int64\nTransferEncoding []string\nClose bool\nTrailer Header\nRequest *Request\nTLS *tls.ConnectionState\n}\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>func ReadResponse(r *bufio.Reader, req *Request) (*Response, error)\nfunc Head(url string) (resp *Response, err error)\nfunc Get(url string) (resp *Response, err error)\nfunc Post(url string, bodyType string, boyd io.Reader) (resp *Response, err error)\nfunc PostForm(url string, data url.Values) (resp *Response, err error)\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>func (r *Response) ProtoAtLeast(major, minor int) bool\n\/\/ \u83b7\u53d6\u76f8\u5e94\u4e2d\u7684Set-Cookie\u8bbe\u7f6e\u7684cookie\nfunc (r *Response) Cookies() []*Cookie\n<\/code><\/pre>\n<h2 id=\"responsewriter\">ResponseWriter<\/h2>\n<p>\u7528\u4e8e\u6784\u9020http\u56de\u590d.<\/p>\n<pre><code>type ResponseWriter interface {\nHeader() Header\nWriteHeader(int)\nWrite([]byte) (int, error)\n}\n<\/code><\/pre>\n<hr>\n<h1 id=\"netmail\">net\/mail<\/h1>\n<hr>\n<h1 id=\"netsmtp\">net\/smtp<\/h1>\n<hr>\n<h1 id=\"netrpc\">net\/rpc<\/h1>\n<p>function:<\/p>\n<pre><code>\/\/ \u5728DefaultServer\u6ce8\u518c\u5e76\u516c\u5e03rcvr\u65b9\u6cd5.\nfunc Register(rcvr interface{}) error\n\/\/ \u63a5\u6536\u8fde\u63a5\uff0c\u5c06\u6bcf\u4e2a\u8fde\u63a5\u4ea4\u7ed9DefaultServer\u670d\u52a1.\u4f1a\u963b\u585e.\nfunc Accept(lis net.Listener)\n\/\/ \u5728\u5355\u4e2a\u8fde\u63a5\u6267\u884cDefaultServer,\u4f1a\u963b\u585e.\nfunc ServceConn(conn io.ReadWriteCloser)\nfunc HandleHTTP()\n<\/code><\/pre>\n<h2 id=\"call\">Call<\/h2>\n<p>\u4ee3\u8868\u4e00\u4e2a\u6267\u884c\u4e2d\u6216\u6267\u884c\u5b8c\u6bd5\u7684\u4f1a\u8bdd\uff0e<\/p>\n<pre><code>type Call struct {\nServiceMethod string\nArgs interface{}\nReply interface{}\nError error\nDone chan *Call\n}\n<\/code><\/pre>\n<h2 id=\"client-1\">Client<\/h2>\n<p>rpc\u5ba2\u6237\u7aef<\/p>\n<pre><code>type client struct {}\n<\/code><\/pre>\n<p>function:<\/p>\n<pre><code>func NewClient(conn io.ReadWriteCloser) *Client\nfunc Dial(network, address string) (*Client, error)\nfunc DialHTTP(network, address string) (*Client, error)\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>\/\/ \u8c03\u7528\u6307\u5b9a\u7684\u65b9\u6cd5\uff0c\u7b49\u5f85\u8fd4\u56de\uff0c\u5c06\u7ed3\u679c\u5199\u5165reply.\nfunc (client *Client) Call(serviceMethod string, args interface{}, reply interface{}) error\nfunc (client *Client) Go(serviceMethod string, args interface{}, reply interface{}, done chan *Call) *Call\nfunc (client *Client) Close() error\n<\/code><\/pre>\n<hr>\n<h1 id=\"nettextproto\">net\/textproto<\/h1>\n<hr>\n<h1 id=\"neturl\">net\/url<\/h1>\n<pre><code>scheme:\/\/[userinfo@]host\/path[?query][#fragment]\n<\/code><\/pre>\n<h2 id=\"url\">URL<\/h2>\n<pre><code>type URL struct {\nScheme string\nOpaque string\nUser *Userinfo\nHost string \/\/ host or host:port\nPath string\nRawQuery string\nFragment string\n}\n<\/code><\/pre>\n<p>function:<\/p>\n<pre><code>func Parse(rawurl string) (url *URL, err error)\nfunc ParseRequestURI(rawurl string) (url *URL, err error)\n<\/code><\/pre>\n<p>methods:<\/p>\n<h2 id=\"userinfo\">Userinfo<\/h2>\n<h2 id=\"values\">VAlues<\/h2>\n<hr>"},{"title":"GSL_oop","link":"https:\/\/canuxcheng.com\/post\/gsl_oop\/","pubDate":"Mon, 01 Jan 2018 10:49:21 +0000","guid":"https:\/\/canuxcheng.com\/post\/gsl_oop\/","description":"<h1 id=\"reflect\">reflect<\/h1>\n<h2 id=\"constants\">constants<\/h2>\n<p>const:<\/p>\n<pre><code>const (\nSelectSend\nSelectRecv\nSelectDefault\n)\n<\/code><\/pre>\n<h2 id=\"functions\">functions<\/h2>\n<pre><code>\/\/ \u5c06src\u62f7\u8d1d\u5230dst, \u76f4\u5230src\u88ab\u8017\u5c3d\u6216dst\u88ab\u88c5\u6ee1.\nfunc Copy(dst, src Value) int\n\/\/ \u5224\u65ad\u4e24\u4e2a\u503c\u662f\u5426\u6df1\u5ea6\u4e00\u81f4\nfunc DeepEqual(a1, a2 interface{}) bool\n<\/code><\/pre>\n<h2 id=\"kind\">Kind<\/h2>\n<p>\u8868\u793aType\u7c7b\u578b\u503c\u8868\u793a\u7684\u5177\u4f53\u5206\u7c7b.<\/p>\n<pre><code>type Kind uint\nconst (\nInvalid Kind = iota\nBool\nInt\n...\nUint\n...\nFloat...\nComplex...\nArray\nChan\nFunc\nInterface\nMap\nPtr\nSlice\nString\nStruct\nUnsafePointer\n)\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>func (k Kind) String() string\n<\/code><\/pre>\n<h2 id=\"stringheader\">StringHeader<\/h2>\n<h2 id=\"sliceheader\">SliceHeader<\/h2>\n<h2 id=\"structfield\">StructField<\/h2>\n<h2 id=\"structtag\">StructTag<\/h2>\n<h2 id=\"chandir\">ChanDir<\/h2>\n<h2 id=\"selectdir\">SelectDir<\/h2>\n<h2 id=\"selectcase\">SelectCase<\/h2>\n<h2 id=\"method\">Method<\/h2>\n<h2 id=\"type\">Type<\/h2>\n<p>\u7528\u6765\u8868\u793a\u4e00\u4e2ago\u7c7b\u578b.<\/p>\n<p>interface:<\/p>\n<pre><code>type Type interface {\nKind() Kind\nName() string\nPkgPath() string\nString() string\nSize() uintptr\n...\n}\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>\/\/ \u8fd4\u56de\u63a5\u53e3\u4e2d\u4fdd\u5b58\u7684\u503c\u7684\u7c7b\u578b\nfunc TypeOf(i interface{}) Type\n\/\/ \u8fd4\u56de\u7c7b\u578bt\u7684\u6307\u9488\u7684\u7c7b\u578b\nfunc PtrTo(t Type) Type\n\/\/ \u8fd4\u56de\u7c7b\u578bt\u7684slice\u7684\u7c7b\u578b\nfunc SliceOf(t Type) Type\n\/\/ \u8fd4\u56de\u4e00\u4e2a\u952e\u7c7b\u578b\u4e3akey, \u503c\u7c7b\u578b\u4e3aelem\u7684map\u7c7b\u578b\nfunc MapOf(key, elem Type) Type\n\/\/ \u8fd4\u56de\u5143\u7d20\u7c7b\u578b\u4e3at, \u65b9\u5411\u4e3adir\u7684chan\u7c7b\u578b\nfunc ChanOf(dir ChanDir, t Type) Type\n<\/code><\/pre>\n<h2 id=\"value\">Value<\/h2>\n<p>\u4e3ago\u503c\u63d0\u4f9b\u53cd\u5c04\u63a5\u53e3.<\/p>\n<p>struct:<\/p>\n<pre><code>type Value struct {}\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>\/\/ \u8fd4\u56de\u4e00\u4e2a\u63a5\u53e3i\u4fdd\u5b58\u7684\u5177\u4f53\u503c\u7684Value\nfunc ValueOf(i interface{}) Value\n\/\/ \u8fd4\u56de\u4e00\u4e2a\u7c7b\u578btyp\u7684\u96f6\u503c\u7684Value\nfunc Zero(typ Type) Value\n...\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>\/\/ \u5982\u679cv\u662f\u5426\u6301\u6709\u503c\uff0c\u5982\u679cv\u662fValue\u96f6\u503c\uff0c\u8fd4\u56defalse.\nfunc (v Value) IsValid() bool\nfunc (v Value) IsNil() bool\n\/\/ \u8fd4\u56dev\u6301\u6709\u503c\u7684\u5206\u7c7b\uff0c\u5982\u679cv\u662fValue\u96f6\u503c\uff0c\u8fd4\u56deInvalid\nfunc (v Value) Kind() Kind\n\/\/ \u8fd4\u56dev\u6301\u6709\u7684\u503c\u7684\u7c7b\u578bType.\nfunc (v Value) Type() Type\n...\n<\/code><\/pre>\n<hr>"},{"title":"GSL_string","link":"https:\/\/canuxcheng.com\/post\/gsl_string\/","pubDate":"Mon, 01 Jan 2018 10:49:21 +0000","guid":"https:\/\/canuxcheng.com\/post\/gsl_string\/","description":"<h1 id=\"strings\">strings<\/h1>\n<p>\u5b9e\u73b0\u4e86\u7528\u4e8e\u64cd\u4f5c\u5b57\u7b26\u7684\u51fd\u6570.<\/p>\n<h2 id=\"functions\">functions<\/h2>\n<pre><code>func EqualFold(s, t string) bool\nfunc HasPrefix(s, prefix string) bool\nfunc HasSuffix(s, suffix string) bool\nfunc Count(s, sep string) int\nfunc Contains(s, substr string) bool\n...\nfunc Index(s, sep string) int\n...\nfunc LastIndex(s, sep string) int\n...\nfunc title(s string) string\nfunc ToLower(s string) string\n...\n\/\/ \u8fd4\u56decount\u4e2astring\nfunc Repeat(s string, count int) string\nfunc Replace(s, old, new string, n int) string\nfunc Map(mapping func(rune) rune, s string) string\nfunc Trim(s string, cutset string) string\n...\n\/\/ \u8fd4\u56de\u5c06\u5b57\u7b26\u4e32\u6309\u7167\u7a7a\u767d\u5206\u5272\u7684\u591a\u4e2a\u5b57\u7b26\u4e32\nfunc Fields(s string) []string\n\/\/ \u6309\u7167f\u4f5c\u4e3a\u5206\u9694\u7b26\u6765\u5206\u5272\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u5207\u7247\nfunc FieldsFunc(s string, f func(rune) bool) []string\nfunc Split(s, sep string) []string\n...\n\/\/ \u5c06\u4e00\u7cfb\u5217\u5b57\u7b26\u4e32\u8fde\u63a5\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u4e4b\u95f4\u7528sep\u6765\u5206\u5272.\nfunc Join(a []string, sep string) string\n<\/code><\/pre>\n<h2 id=\"reader\">Reader<\/h2>\n<h2 id=\"replacer\">Replacer<\/h2>\n<hr>\n<h1 id=\"bytes\">bytes<\/h1>\n<p>\u5b9e\u73b0\u4e86\u64cd\u4f5c[]bytes\u7684\u5e38\u7528\u51fd\u6570.<\/p>\n<h2 id=\"constants\">constants<\/h2>\n<h2 id=\"variables\">variables<\/h2>\n<h2 id=\"functions-1\">functions<\/h2>\n<h2 id=\"reader-1\">Reader<\/h2>\n<h2 id=\"buffer\">Buffer<\/h2>\n<p>Buffer\u662f\u4e00\u4e2a\u5b9e\u73b0\u4e86\u8bfb\u5199\u65b9\u6cd5\u7684\u53ef\u53d8\u5927\u5c0f\u7684\u5b57\u8282\u7f13\u51b2.<\/p>\n<p>\u96f6\u503c\u662f\u4e00\u4e2a\u7a7a\u7684\u53ef\u7528\u4e8e\u8bfb\u5199\u7684\u7f13\u51b2.<\/p>\n<p>struct:<\/p>\n<pre><code>type Buffer struct {}\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>func NewBuffer(buf []byte) *Buffer\nfunc NewBufferString(s string) *Buffer\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>func (b *Buffer) String() string\nfunc (b *Buffer) Read(p []byte) (n int, err error)\nfunc (b *Buffer) Write(p []byte) (n int, err error)\n<\/code><\/pre>\n<hr>\n<h1 id=\"strconv\">strconv<\/h1>\n<p>\u5b9e\u73b0\u4e86\u57fa\u672c\u6570\u636e\u7c7b\u578b\u548c\u5b57\u7b26\u4e32\u7684\u76f8\u4e92\u8f6c\u6362.<\/p>\n<h2 id=\"constants-1\">constants<\/h2>\n<pre><code>const InitSize = intSize\n<\/code><\/pre>\n<h2 id=\"variables-1\">Variables<\/h2>\n<pre><code>var ErrRange = errors.New(&quot;value out of range&quot;)\nvar ErrSyntax = errors.New(&quot;invalid syntax&quot;)\n<\/code><\/pre>\n<h2 id=\"functions-2\">functions<\/h2>\n<pre><code>\/\/ \u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u662f\u5426\u662f\u53ef\u6253\u5370\u7684\nfunc IsPrint(r rune) bool\n\/\/ \u8fd4\u56de\u5b57\u7b26\u4e32s\u662f\u5426\u53ef\u4ee5\u4e0d\u88ab\u4fee\u6539\u7684\u8868\u793a\u4e3a\u4e00\u4e2a\u53cd\u5f15\u53f7\u5b57\u7b26\u4e32\nfunc CanBackquote(s string) bool\nfunc Quote(s string) string\n...\nfunc Unquote(s string) (t string, err error)\n...\nfunc AppendInt(dst []byte, i int64, base int) []byte\n...\n\/\/ \u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u5176\u4ed6\u7c7b\u578b\nfunc ParseInt(s string, base int, bitSize int) (i int64, err error)\n...\n\/\/ \u5176\u4ed6\u7c7b\u578b\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\nfunc FormatInt(i int64, base int) string\n...\n\/\/ ParseInt(s, 10, 0)\u7684\u7b80\u5199, string -&gt; int\nfunc Atoi(s string) (i int, err error)\n\/\/ FormatInt(i, 10)\u7684\u7b80\u5199, int -&gt; string\nfunc Itoa(i int) string\n<\/code><\/pre>\n<h2 id=\"numerror\">NumError<\/h2>\n<p>\u8868\u793a\u4e00\u6b21\u5931\u8d25\u7684\u8f6c\u6362<\/p>\n<p>struct:<\/p>\n<pre><code>type NumError struct {\nFunc string\nNum string\nErr error\n}\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>func (e *NumError) Error() string\n<\/code><\/pre>\n<hr>\n<h1 id=\"unicode\">unicode<\/h1>\n<hr>\n<h1 id=\"regexp\">regexp<\/h1>\n<p>\u5b9e\u73b0\u4e86\u6b63\u5219\u8868\u8fbe\u5f0f\u641c\u7d22<\/p>\n<h2 id=\"functions-3\">functions<\/h2>\n<h2 id=\"regexp-1\">Regexp<\/h2>\n<p>Regexp\u4ee3\u8868\u4e00\u4e2a\u7f16\u8bd1\u597d\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\uff0e<\/p>\n<pre><code>type Regexp struct {}\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>func Compile(expr string) (*Regexp, error)\nfunc CompilePOSIX(expr string) (*Regexp, error)\nfunc MustCompile(str string) *Regexp\nfunc MustCompilePOSIX(str string) *Regexp\n<\/code><\/pre>\n<p>methods:<\/p>\n<hr>\n<h1 id=\"regexpsyntax\">regexp\/syntax<\/h1>\n<hr>\n<h1 id=\"indexsuffixarray\">index\/suffixarray<\/h1>"},{"title":"GSL_system","link":"https:\/\/canuxcheng.com\/post\/gsl_system\/","pubDate":"Mon, 01 Jan 2018 10:49:21 +0000","guid":"https:\/\/canuxcheng.com\/post\/gsl_system\/","description":"<h1 id=\"os\">os<\/h1>\n<p>\u63d0\u4f9b\u4e86\u64cd\u4f5c\u7cfb\u7edf\u7684\u4e0d\u4f9d\u8d56\u5e73\u53f0\u7684\u63a5\u53e3<\/p>\n<pre><code>import &quot;os&quot;\n<\/code><\/pre>\n<h2 id=\"constants\">constants<\/h2>\n<pre><code># flag \u53c2\u6570\nconst (\nO_RDONLY int = syscall.O_RDONLY\nO_WRONLY int = syscall.O_WRONLY\nO_RDWR int = syscall.O_RDWR\nO_CREATE int = syscall.O_CREATE # \u4e0d\u5b58\u5728\u5c31\u521b\u5efa\nO_APPEND int = syscall.O_APPEND # \u8ffd\u52a0\u5199\u5165\nO_TRUNC int = syscall.O_TRUNC # \u6253\u5f00\u65f6\u6e05\u7a7a\u6587\u4ef6\nO_EXCL int = syscall.O_EXCL\nO_SYNC int = syscall.O_SYNC\n)\nconst (\nSEEK_SET int = 0\nSEEK_CUR int = 1\nSEEK_END int = 2\n)\nconst (\n\/\/ \u64cd\u4f5c\u7cfb\u7edf\u6307\u5b9a\u7684\u8def\u5f84\u5206\u9694\u7b26\nPathSeperator = '\/'\n\/\/ \u64cd\u4f5c\u7cfb\u7edf\u6307\u5b9a\u7684\u8868\u5206\u9694\u7b26\nPathListSeparator = ':'\n)\n\/\/ \u64cd\u4f5c\u7cfb\u7edf\u7a7a\u8bbe\u5907\u7684\u540d\u5b57\nconst DevNull = &quot;\/dev\/null&quot;\n<\/code><\/pre>\n<h2 id=\"variables\">variables<\/h2>\n<pre><code>var (\nErrInvalid = errors.New(&quot;invalid argument&quot;)\n...\n)\n\/\/ \u6307\u5411\u6807\u51c6\u8f93\u5165\uff0f\u8f93\u51fa\uff0f\u9519\u8bef\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\nvar (\nStdin = NewFile(uintptr(syscall.Stdin), &quot;\/dev\/stdin&quot;)\nStdout = NewFile(uintptr(syscall.Stdout), &quot;\/dev\/stdout&quot;)\nStderr = NewFile(uintptr(syscall.Stderr), &quot;\/dev\/stderr&quot;)\n)\n\/\/ \u4fdd\u5b58\u4e86\u547d\u4ee4\u884c\u53c2\u6570\uff0c\u7b2c\u4e00\u4e2a\u662f\u7a0b\u5e8f\u540d\nvar Args []string\n<\/code><\/pre>\n<h2 id=\"functions\">functions<\/h2>\n<pre><code>\/\/ \u8fd4\u56de\u5185\u6838\u63d0\u4f9b\u7684\u4e3b\u673a\u540d\nfunc Hostname() (name string, err error)\n\/\/ \u5f53\u524d\u7a0b\u5e8f\u4ee5\u7ed9\u51fa\u7684\u72b6\u6001\u7801\u9a6c\u4e0a\u9000\u51fa\uff0cdefer\u4e0d\u4f1a\u6267\u884c\nfunc Exit(code int)\n\/\/ \u8fd4\u56dekey=value\u683c\u5f0f\u7684\u73af\u5883\u53d8\u91cf\u7684\u5b57\u7b26\u4e32\u7684\u5207\u7247\u62f7\u8d1d\nfunc Environ() []string\n<\/code><\/pre>\n<p>\u6587\u4ef6\u76f8\u5173\u7684\u64cd\u4f5c<\/p>\n<pre><code>func IsExist(err error) bool \/\/ \u6587\u4ef6\u5b58\u5728\u8fd4\u56detrue\nfunc IsNotExist(err error) bool \/\/ \u6587\u4ef6\u4e0d\u5b58\u5728\u8fd4\u56detrue\nfunc IsPathSeparator(c uint8) bool\n...\nfunc SameFile(fi1, fi2 FileInfo) bool\nfunc Getwd() (dir string, err error)\nfunc Chdir(dir string) error\nfunc Chmod(name string, mode FileMode) error\nfunc Chown(name string, uid, gid int) error\n...\nfunc Mkdir(name string, perm FileMode) error \/\/ \u521b\u5efa\u5355\u4e2a\u76ee\u5f55\nfunc MkdirAll(path string, perm FileMode) error \/\/ \u521b\u5efa\u591a\u7ea7\u76ee\u5f55\nfunc Rename(oldpath, newpath string) error\nfunc Truncate(name string, size int64) error\nfunc Remove(name string) error\nfunc RemoveAll(path string) error\nfunc Readlink(name string) (string, error)\nfunc Symlink(oldname, newname string) error \/\/ \u521b\u5efa\u7b26\u53f7\u8fde\u63a5\nfunc Link(oldname, newname string) error \/\/ \u521b\u5efa\u786c\u8fde\u63a5\nfunc TempDir() string \/\/ \u8fd4\u56de\u4e00\u4e2a\u7528\u4e8e\u4fdd\u7ba1\u4e34\u65f6\u6587\u4ef6\u7684\u9ed8\u8ba4\u76ee\u5f55\n\/\/ \u4ecefilename\u6307\u5b9a\u7684\u6587\u4ef6\u8bfb\u53d6\u6570\u636e\u5e76\u8fd4\u56de, \u6210\u529f\u8fd4\u56de\u6587\u4ef6\u5185\u5bb9\u548cnil\nfunc ReadFile(filename string) ([]byte, error)\n\/\/ \u5411filename\u6307\u5b9a\u6587\u4ef6\u5199\u5165\u6570\u636e\uff0c\u5982\u679c\u6587\u4ef6\u5b58\u5728\u5148\u6e05\u7a7a\u6587\u4ef6\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u521b\u5efa\u6587\u4ef6.\nfunc WriteFile(filename string, data []byte, perm os.FileMode) error\n<\/code><\/pre>\n<h2 id=\"signal\">Signal<\/h2>\n<p>interface:<\/p>\n<pre><code>type Signal interface {\nString() string\nSignal()\n}\n<\/code><\/pre>\n<p>variable:<\/p>\n<pre><code>var (\nInterrupt Signal = syscall.SIGINT\nKill Signal = syscall.SIGKILL\n)\n<\/code><\/pre>\n<h2 id=\"filemode\">FileMode<\/h2>\n<p>\u4ee3\u8868\u6587\u4ef6\u6a21\u5f0f\u548c\u6743\u9650\u4f4d\uff0e<\/p>\n<pre><code>type FileMode uint32\n<\/code><\/pre>\n<p>constant:<\/p>\n<pre><code>const (\nModeDir FileMode = 1 &lt;&lt; (32 - 1 - iota) \/\/ d: \u76ee\u5f55\n...\nModeType = ModeDir | ModeSymlink | ModeNamePipe | ModeSocket | ModeDevice\nModePerm FileMode = 0777\n)\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>func (m FileMode) IsDir() bool\nfunc (m FileMode) IsRegular() bool\n<\/code><\/pre>\n<h2 id=\"fileinfo\">FileInfo<\/h2>\n<p>\u7528\u6765\u63cf\u8ff0\u4e00\u4e2a\u6587\u4ef6\u5bf9\u8c61<\/p>\n<pre><code>type FileInfo interface {\nName() string\nSize() int64\nMode() FileMode\nModeTime() time.Time\nIsDir() bool\nSys() interface{}\n}\n<\/code><\/pre>\n<p>function:<\/p>\n<pre><code>\/\/ \u83b7\u53d6\u4e00\u4e2a\u6587\u4ef6\u5bf9\u8c61\nfunc Stat(name string) (fi FileInfo, err error)\nfunc Lstat(name string) (fi FileInfo, err error)\n<\/code><\/pre>\n<h2 id=\"file\">File<\/h2>\n<p>\u8868\u793a\u4e00\u4e2a\u6253\u5f00\u7684\u6587\u4ef6\u5bf9\u8c61<\/p>\n<p>struct:<\/p>\n<pre><code>type File struct {}\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>\/\/ \u91c7\u7528flag=os.O_RDWR\u548cperm=0666\u6a21\u5f0f\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aname\u7684\u6587\u4ef6, \u8fd4\u56de\u8bfb\u5199\u6587\u4ef6\u53e5\u67c4\n\/\/ \u6587\u4ef6\u5df2\u5b58\u5728\u5c31\u622a\u65ad\nfunc Create(name string) (file *File, err error)\n\/\/ \u6253\u5f00\u6307\u5b9a\u6587\u4ef6\uff0c\u8fd4\u56de\u53ea\u8bfb\u6587\u4ef6\u53e5\u67c4, flag=os.O_RDONLY\nfunc Open(name string) (file *File, err error)\n\/\/ \u6307\u5b9aflag\u548cperm\u521b\u5efa\uff0f\u6253\u5f00\u6587\u4ef6\nfunc OpenFile(name string, flag int, perm FileMode) (file *File, err error)\n\/\/ \u4f7f\u7528\u7ed9\u5b9a\u7684\u6587\u4ef6\u63cf\u8ff0\u670d\u548c\u540d\u79f0\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6.\nfunc NewFile(fd uintptr, name string) *File\n\/\/ \u8fd4\u56de\u4e00\u5bf9\u5173\u8054\u7684\u6587\u4ef6\u5bf9\u8c61\nfunc Pipe() (r *File, w *File, err error)\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>\/\/ \u4ece\u6587\u4ef6f\u4e2d\u6700\u591a\u8bfb\u53d6len(b)\u5b57\u8282\u6570\u636e\u5199\u5165b, \u8fd4\u56de\u8bfb\u53d6\u7684\u5b57\u8282\u6570\n\/\/ \u8fd4\u56de0, io.EOF, \u8868\u793a\u8bfb\u53d60\u4e2a\u5b57\u8282,\u6587\u4ef6\u7ec8\u6b62\uff0e\nfunc (f *File) Read(b []byte) (n int, err error)\nfunc (f *File) ReadAt(b []byte, off int64) (n int, err error)\n\/\/ \u5411\u6587\u4ef6f\u5199\u5165len(b)\u5b57\u8282\u6570\u636eb\uff0c\u8fd4\u56de\u5199\u5165\u5b57\u8282\u6570\nfunc (f *File) Write(b []byte) (n int, err error)\nfunc (f *File) WriteAt(b []byte, off int64) (ret int, err error)\nfunc (f *File) WriteString(s string) (ret int, err error)\nfunc (f *File) Close() error\n<\/code><\/pre>\n<h2 id=\"process\">Process<\/h2>\n<p>\u4fdd\u5b58\u4e00\u4e2a\u88abStarProcess\u521b\u5efa\u7684\u8fdb\u7a0b\u7684\u4fe1\u606f<\/p>\n<p>struct:<\/p>\n<pre><code>type Process struct {\nPid int\n}\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>\/\/ \u542f\u52a8\u4e00\u4e2a\u65b0\u8fdb\u7a0b\nfunc StartProcess(name string, argv []string, attr *ProcAttr) (*Process, error)\n\/\/ \u67e5\u627e\u4e00\u4e2a\u8fd0\u884c\u4e2d\u7684\u8fdb\u7a0b\nfunc FindProcess(pid int) (p *Process, err error)\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>\/\/ \u5411\u8fdb\u7a0b\u53d1\u9001\u4fe1\u53f7\nfunc (p *Process) Signal(sig Signal) error\n\/\/ \u963b\u585e\u76f4\u5230\u8fdb\u7a0b\u9000\u51fa\nfunc (p *Process) Wait() (*ProcessState, error)\n\/\/ \u8ba9\u8fdb\u7a0b\u7acb\u523b\u9000\u51fa\nfunc (p *Process) Kill() error\n\/\/ \u91ca\u653e\u8fdb\u7a0b\u7ed1\u5b9a\u7684\u8d44\u6e90\nfunc (p *Process) Release() error\n<\/code><\/pre>\n<h2 id=\"processstate\">ProcessState<\/h2>\n<p>\u4fdd\u7ba1Wait\u51fd\u6570\u62a5\u544a\u7684\u67d0\u4e2a\u5df2\u9000\u51fa\u8fdb\u7a0b\u7684\u4fe1\u606f\uff0e<\/p>\n<p>struct:<\/p>\n<pre><code>type ProcessState struct {}\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>\/\/ \u8fd4\u56de\u4e00\u4e2a\u5df2\u9000\u51fa\u7684\u8fdb\u7a0b\u7684id\nfunc (p *ProcessState) Pid() int\n\/\/ \u62a5\u544a\u8fdb\u7a0b\u662f\u5426\u5df2\u9000\u51fa\nfunc (p *ProcessState) Exited() bool\n\/\/ \u62a5\u544a\u8fdb\u7a0b\u662f\u5426\u6210\u529f\u9000\u51fa\nfunc (p *ProcessState) Success() bool\n\/\/ \u8fd4\u56de\u5df2\u9000\u51fa\u8fdb\u7a0b\u53ca\u5176\u5b50\u8fdb\u7a0b\u8017\u8d39\u7684\u7cfb\u7edfcpu\u65f6\u95f4\nfunc (p *ProcessState) SystemTime() time.Duration\n\/\/ \u8fd4\u56de\u5df2\u9000\u51fa\u8fdb\u7a0b\u53ca\u5176\u5b50\u8fdb\u7a0b\u8017\u8d39\u7684\u7528\u6237cpu\u65f6\u95f4\nfunc (p *ProcessState) UserTime() time.Duration\nfunc (p *ProcessState) Sys() interface{}\nfunc (p *ProcessState) SysUsage() interface{}\nfunc (p *ProcessState) String() string\n<\/code><\/pre>\n<h2 id=\"procattr\">ProcAttr<\/h2>\n<p>\u4fdd\u5b58\u88abStratProcess\u542f\u52a8\u7684\u65b0\u8fdb\u7a0b\u7684\u5c5e\u6027<\/p>\n<p>struct:<\/p>\n<pre><code>type ProcAttr struct {\nDir string\nEnv []string\nFiles []*File\nSys *syscall.SysProcAttr\n}\n<\/code><\/pre>\n<hr>\n<h1 id=\"osexec\">os\/exec<\/h1>\n<p>\u6267\u884c\u5916\u90e8\u547d\u4ee4\uff0c\u5305\u88c5\u4e86os.StartProcess\u51fd\u6570\uff0c\u63d0\u4f9b\u66f4\u9ad8\u7ea7\u7684\u63a5\u53e3.<\/p>\n<h2 id=\"variable\">variable<\/h2>\n<pre><code>var ErrNotFound = errors.New(&quot;executable file not found in $PATH&quot;)\n<\/code><\/pre>\n<h2 id=\"functions-1\">functions<\/h2>\n<pre><code>\/\/ \u5728\u73af\u5883\u53d8\u91cf\u6307\u5b9a\u7684\u76ee\u5f55\u4e2d\u641c\u7d22\u53ef\u6267\u884c\u6587\u4ef6file\nfunc LookPath(file string) (string, error)\n<\/code><\/pre>\n<h2 id=\"cmd\">Cmd<\/h2>\n<p>\u8868\u793a\u4e00\u4e2a\u51c6\u5907\u6267\u884c\u6216\u6267\u884c\u4e2d\u7684\u5916\u90e8\u547d\u4ee4<\/p>\n<p>struct:<\/p>\n<pre><code>type Cmd struct {\nPath string\nArgs []string\nEnv []string\nDir string\nstdin io.Reader\nStdout io.Writer\nStderr io.Writer\nExtraFiles []*os.File\nSysProcAttr *syscall.SysProcAttr\nProcess *os.Process\nProcessState *os.ProcessState\n}\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>\/\/ \u8fd4\u56de*Cmd\nfunc Command(name string, arg ***string) *Cmd\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>\/\/ \u540c\u6b65\uff1a\u6267\u884c\u547d\u4ee4\uff0c\u5e76\u963b\u585e\u76f4\u5230\u5b8c\u6210\nfunc (c *Cmd) Run() error\n\/\/ \u5f02\u6b65\uff1a\u5f00\u59cb\u6267\u884c\u547d\u4ee4\uff0c\u4e0d\u963b\u585e\u76f4\u63a5\u8fd4\u56de\uff0c\nfunc (c *Cmd) Start() error\n\/\/ \u963b\u585e\u901a\u8fc7Start\u6267\u884c\u7684\u547d\u4ee4\u76f4\u5230\u5b8c\u6210\uff0c\u8bbe\u7f6e\u72b6\u6001\u7801\u5e76\u91ca\u653e\u8d44\u6e90\uff0e\nfunc (c *Cmd) Wait() error\nfunc (c *Cmd) StdinPipe() (io.WriteCloser, error)\nfunc (c *Cmd) StdoutPipe() (io.ReadCloser, error)\nfunc (c *Cmd) StderrPipe() (io.ReadCloser, error)\n\/\/ \u6267\u884c\u547d\u4ee4\u5e76\u8fd4\u56destdout\u7684\u5207\u7247\nfunc (c *Cmd) Output() ([]byte, error)\n\/\/ \u6267\u884c\u547d\u4ee4\u5e76\u8fd4\u56destdout\u548cstderr\u5408\u5e76\u540e\u7684\u5207\u7247\nfunc (c *Cmd) CombinedOutput() ([]byte, error)\n<\/code><\/pre>\n<hr>\n<h1 id=\"ossignal\">os\/signal<\/h1>\n<hr>\n<h1 id=\"osuser\">os\/user<\/h1>\n<hr>\n<h1 id=\"syscall\">syscall<\/h1>\n<p>\u63d0\u4f9b\u4e86\u64cd\u4f5c\u7cfb\u7edf\u7ea7\u522b\u7684\u8c03\u7528\uff0e<\/p>\n<pre><code>import &quot;syscall&quot;\n<\/code><\/pre>\n<h2 id=\"constants-1\">constants<\/h2>\n<pre><code>const (\nAF_ALG = 0x26\n...\n)\n\/\/ \u5b9a\u4e49\u5f02\u5e38\nconst (\nE2BIG = Errno(0x70)\n...\n)\n\/\/ \u5b9a\u4e49\u4fe1\u53f7\nconst (\nSIGABRT = Signal(0x6)\n...\n)\nconst (\nSYS_READ = 0\n...\n)\nconst (\nSizeofSockaddrInet4 = 0x10\n...\n)\nconst (\nIFA_UNSPEC = 0x0\n...\n)\nconst (\nSizeofSockFilter = 0x8\n...\n)\nconst (\nVINTR = 0x0\n...\n)\nconst ImplementsGetwd = true\nconst PathMax = 0x1000\nconst SizeofInotifyEvent = 0x10\n<\/code><\/pre>\n<h2 id=\"variables-1\">variables<\/h2>\n<pre><code>var (\nStdin = 0\nStdout = 1\nStderr = 2\n)\nvar ForkLock sync.RWMutex\nvar SocketDisableIPv6 bool\n<\/code><\/pre>\n<h2 id=\"others\">others<\/h2>\n<p>\u53c2\u8003\u6587\u6863<\/p>\n<hr>\n<h1 id=\"io\">io<\/h1>\n<p>\u63d0\u4f9b\u4e86\u5bf9IO\u539f\u8bed\u7684\u57fa\u672c\u63a5\u53e3<\/p>\n<p>go1.16 \u5220\u9664\u4e86io\/ioutil<\/p>\n<pre><code>import &quot;io&quot;\n<\/code><\/pre>\n<h2 id=\"variables-2\">variables<\/h2>\n<pre><code>\/\/ \u653e\u65e0\u6cd5\u83b7\u53d6\u66f4\u591a\u8f93\u5165\u65f6Read\u65b9\u6cd5\u8fd4\u56deos.EOF\nvar EOF = errors.New(&quot;EOF&quot;)\n<\/code><\/pre>\n<h2 id=\"functions-2\">functions<\/h2>\n<pre><code>func ReadAll(r io.Reader) ([]byte, error)\nfunc ReadAtLeast(r Reader, buf []byte, min int) (n int, err error)\nfunc ReadFull(r Reader, buf []byte) (n int, err error)\n\/\/ \u5c06src\u6570\u636e\u62f7\u8d1d\u5230dst, \u76f4\u5230EOF\u6216\u51fa\u9519\uff0c\u8fd4\u56de\u62f7\u8d1d\u7684\u5b57\u8282\u6570\nfunc Copy(dst Writer, src Reader) (written int64, err error)\n\/\/ \u7c7b\u4f3cCopy\uff0c\u4e0d\u8fc7\u53ea\u62f7\u8d1dn\u4e2a\u5b57\u8282.\nfunc CopyN(dst Writer, src Reader, n int64) (written int64, err error)\nfunc CopyBuffer(dst Writer, src Reader, buf []byte) (written int64, err error)\n\/\/ \u5c06\u5b57\u7b26\u4e32s\u5199\u5165w\nfunc WriteString(w Writer, s string) (n int, err error)\n<\/code><\/pre>\n<h2 id=\"reader\">Reader<\/h2>\n<p>\u7528\u4e8e\u5305\u88c5\u57fa\u672c\u7684\u8bfb\u53d6\u65b9\u6cd5<\/p>\n<p>os.File(os.Stdout, os.Stdin. os.Stderr), bytes.Buffer \u548c bufio.Reader \u90fd\u662fio.Reader\u63a5\u53e3<\/p>\n<p>interface:<\/p>\n<pre><code>type Reader interface {\nRead(p []byte) (n int, err error)\n}\n<\/code><\/pre>\n<h2 id=\"writer\">Writer<\/h2>\n<p>\u7528\u4e8e\u5305\u88c5\u57fa\u672c\u7684\u5199\u5165\u65b9\u6cd5<\/p>\n<p>os.File(os.Stdin, os.Stderr, os.Stdin), bytes.Buffer \u548c bufio.Writer, net\/http.ResponseWriter \u90fd\u662fio.Writer\u63a5\u53e3<\/p>\n<p>interface:<\/p>\n<pre><code>type Writer interface {\nWrite(p []byte) (n int, err error)\n}\n<\/code><\/pre>\n<h2 id=\"closer\">Closer<\/h2>\n<p>\u7528\u4e8e\u5305\u88c5\u57fa\u672c\u7684\u5173\u95ed\u65b9\u6cd5<\/p>\n<p>interface:<\/p>\n<pre><code>type Closer interface {\nClose() error\n}\n<\/code><\/pre>\n<h2 id=\"seeker\">Seeker<\/h2>\n<p>\u7528\u4e8e\u5305\u88c5\u57fa\u672c\u7684\u79fb\u4f4d\u65b9\u6cd5<\/p>\n<p>interface:<\/p>\n<pre><code>type Seeker interface {\nSeek(offset int64, whence int) (int64, error)\n}\n<\/code><\/pre>\n<h2 id=\"readwriter\">ReadWriter<\/h2>\n<p>interface:<\/p>\n<pre><code>type ReadWriter interface {\nReader\nWriter\n}\n<\/code><\/pre>\n<hr>\n<h1 id=\"bufio\">bufio<\/h1>\n<p>bufio\u5b9e\u73b0\u4e86\u6709\u7f13\u51b2\u7684IO<\/p>\n<h2 id=\"constants-2\">constants<\/h2>\n<pre><code>const (\n\/\/ \u7528\u4e8e\u7f13\u51b2\u4e00\u4e2atoken\nMaxScanTokenSize = 64 * 1024\n)\n<\/code><\/pre>\n<h2 id=\"variables-3\">variables<\/h2>\n<pre><code>\/\/ \u4f1a\u88abScanner\u8fd4\u56de\u7684\u9519\u8bef\nvar (\nErrInvalidUnreadByte = errors.New(&quot;bufio: invalid use of UnreadByte&quot;)\n...\n)\n<\/code><\/pre>\n<h2 id=\"functions-3\">functions<\/h2>\n<pre><code>func ScanBytes(data []byte, atEOF bool) (advance int, token []byte, err error)\nfunc ScanRunes(data []byte, atEOF bool) (advance int, token []byte, err error)\nfunc ScanWords(data []byte, atEOF bool) (advance int, token []byte, err error)\n\/\/ \u5c06\u6bcf\u4e00\u884c\u6587\u672c\u53bb\u6389\u672b\u5c3e\u7684\u6362\u884c\u6807\u8bb0\uff0c\u7136\u540e\u4f5c\u4e3a\u4e00\u4e2atoken\u8fd4\u56de\nfunc ScanLines (data []byte, atEOF bool) (advance int, token []byte, err error)\n<\/code><\/pre>\n<h2 id=\"reader-1\">Reader<\/h2>\n<p>\u7ed9io.Reader\u63a5\u53e3\u5bf9\u8c61\u9644\u52a0\u7f13\u51b2<\/p>\n<p>struct:<\/p>\n<pre><code>type Reader struct {}\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>func NewReader(rd io.Reader) *Reader\nfunc NewReaderSize(rd io.Reader, size int) *Reader\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>func (b *Reader) Read(p []byte) (n int, err error)\n\/\/ \u8bfb\u53d6\u76f4\u5230\u7b2c\u4e00\u6b21\u9047\u5230delim\u5b57\u8282\uff0c\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u5df2\u8bfb\u53d6\u6570\u636e\u548cdelim\u5b57\u8282\u7684\u5b57\u7b26\u4e32\n\/\/ \u5f53\u4e14\u4ec5\u5f53\u8fd4\u56de\u7684\u5207\u7247\u4e0d\u4ee5delim\u7ed3\u5c3e\u65f6\uff0c\u8fd4\u56de\u975enil\u9519\u8bef\nfunc (b *Reader) ReadString(delim byte) (line string, err error)\nfunc (b *Reader) ReadBytes(delim byte) (line []byte, err error)\nfunc (b *Reader) ReadSlice(delim byte) (line []byte, err error)\nfunc (b *Reader) ReadLine() (line []byte, isPrefix bool, err error)\nfunc (b *Reader) ReadByte() (c byte, err error)\nfunc (b *Reader) ReadRune() (r rune, size int, err error)\n<\/code><\/pre>\n<h2 id=\"writer-1\">Writer<\/h2>\n<p>\u7ed9io.Writer\u63a5\u53e3\u5bf9\u8c61\u63d0\u4f9b\u7f13\u51b2<\/p>\n<p>struct:<\/p>\n<pre><code>type Writer struct {}\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>func NewWriter(w io.Writer) *Writer\nfunc NewWriterSize(w io.Writer, size int) *Writer\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>func (b *Writer) Write(p []byte) (nn int, err error)\nfunc (b *Writer) WriteString(s string) (int, error)\nfunc (b *Writer) WriteByte(c byte) error\nfunc (b *Writer) WriteRune(r rune) (size int, err error)\nfunc (b *Writer) Flush() error\n<\/code><\/pre>\n<h2 id=\"readwriter-1\">ReadWriter<\/h2>\n<p>struct:<\/p>\n<pre><code>type ReadWriter struct {\n*Reader\n*Writer\n}\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>func NewReadWriter(r *Reader, w *Writer) *ReadWriter\n<\/code><\/pre>\n<h2 id=\"scanner\">Scanner<\/h2>\n<p>\u63d0\u4f9b\u4e86\u65b9\u4fbf\u7684\u8bfb\u53d6\u6570\u636e\u63a5\u53e3<\/p>\n<p>struct:<\/p>\n<pre><code>type Scanner struct {}\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>\/\/ \u521b\u5efa\u5e76\u8fd4\u56de\u4e00\u4e2a\u4ecer\u8bfb\u53d6\u6570\u636e\u7684Scanner\uff0c\u9ed8\u8ba4\u5206\u5272\u51fd\u6570\u662fScanLines\nfunc NewScanner(r io.Reader) *Scanner\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>\/\/ \u8bbe\u7f6es\u7684\u5206\u5272\u51fd\u6570\nfunc (s *Scanner) Split(split SplitFunc)\n\/\/ \u83b7\u53d6\u5f53\u524d\u4f4d\u7f6e\u7684token, \u5e76\u8ba9Scanner\u7684\u626b\u63cf\u4f4d\u7f6e\u79fb\u52a8\u5230\u4e0b\u4e00\u4e2atoken.\nfunc (s *Scanner) Scan() bool\n\/\/ \u8fd4\u56de\u6700\u8fd1\u4e00\u6b21Scan\u8c03\u7528\u751f\u6210\u7684token.\nfunc (s *Scanner) Bytes() []byte\n\/\/ \u521b\u5efa\u4e00\u4e2a\u5b57\u7b26\u4e32\u4fdd\u5b58Bytes\u8fd4\u56de\u7684token,\u5e76\u8fd4\u56de\nfunc (s *Scanner) Text() string\n\/\/ \u8fd4\u56deScanner\u9047\u5230\u7684\u7b2c\u4e00\u4e2a\u975eEOF\u9519\u8bef\nfunc (s *Scanner) Err() error\n<\/code><\/pre>\n<h2 id=\"splitfunc\">SplitFunc<\/h2>\n<pre><code>type SplitFunc func(data []byte, atEOF bool) (advance int, token []byte, err error)\n<\/code><\/pre>\n<hr>\n<h1 id=\"fmt\">fmt<\/h1>\n<p>\u5b9e\u73b0\u4e86\u7c7b\u4f3c\u4e8eC\u7684printf\/scanf\u7684\u683c\u5f0f\u5316IO.<\/p>\n<pre><code>import &quot;fmt&quot;\n<\/code><\/pre>\n<p>\u901a\u7528\u5360\u4f4d\u7b26:<\/p>\n<pre><code>%v \u76f8\u5e94\u503c\u7684\u9ed8\u8ba4\u683c\u5f0f\n%#v \u76f8\u5e94\u503c\u7684go\u8bed\u6cd5\u8868\u793a\n%T \u76f8\u5e94\u503c\u7684\u7c7b\u578b\u7684go\u8bed\u6cd5\u8868\u793a\n%% \u5b57\u9762\u4e0a\u7684\u767e\u5206\u53f7\n<\/code><\/pre>\n<p>\u5e03\u5c14\u7c7b\u578b\uff1a<\/p>\n<pre><code>%t true\/false\n<\/code><\/pre>\n<p>\u6574\u6570\u7c7b\u578b\uff1a<\/p>\n<pre><code>%b \u4e8c\u8fdb\u5236\u8868\u793a\n%c \u76f8\u5e94\u7684unicode\u7801\u70b9\u6240\u8868\u793a\u7684\u5b57\u7b26\n%d \u5341\u8fdb\u5236\u8868\u793a\n%o \u516b\u8fdb\u5236\u8868\u793a\n%q \u5355\u5f15\u53f7\u5305\u56f4\u7684\u5b57\u7b26\u5b57\u9762\u503c\n%x \u5341\u516d\u8fdb\u5236(\u5b57\u6bcd\u5c0f\u5199)\n%X \u5341\u516d\u8fdb\u5236(\u5b57\u6bcd\u5927\u5199)\n%U unicode\u683c\u5f0f\n<\/code><\/pre>\n<p>\u6d6e\u70b9\u6570\u7c7b\u578b\uff1a<\/p>\n<pre><code>%b \u65e0\u5c0f\u6570\u90e8\u5206\u7684\uff0c\u6307\u6570\u4e3a\u4e8c\u7684\u5e42\u7684\u79d1\u5b66\u8ba1\u6570\u6cd5\uff0e\n%e \u79d1\u5b66\u8ba1\u6570\u6cd5\n%E \u79d1\u5b66\u8ba1\u6570\u6cd5\n%f \u6709\u5c0f\u6570\u70b9\uff0c\u800c\u65e0\u6307\u6570\n%g \u6839\u636e\u60c5\u51b5\u9009\u62e9%e \u6216 %f\n%G \u6839\u636e\u60c5\u51b5\u9009\u62e9E% \u6216 %f\n%[\u5bbd\u5ea6]Type\n%.[\u7cbe\u5ea6]Type\n%[\u5bbd\u5ea6].[\u7cbe\u5ea6]Type\n<\/code><\/pre>\n<p>\u5b57\u7b26\u4e32\u4e0e\u5b57\u8282\u5207\u7247\uff1a<\/p>\n<pre><code>%s \u5b57\u7b26\u4e32\u6216\u5207\u7247\u7684\u5b57\u8282\n%q \u53cc\u5f15\u53f7\u5305\u56f4\u7684\u5b57\u7b26\u4e32\n%x \u5341\u516d\u8fdb\u5236(\u5c0f\u5199\u5b57\u6bcd)\n%X \u5341\u516d\u8fdb\u5236(\u5927\u5199\u5b57\u6bcd)\n<\/code><\/pre>\n<p>\u6307\u9488\uff1a<\/p>\n<pre><code>%p \u5341\u516d\u8fdb\u5236\u8868\u793a(0x)\n<\/code><\/pre>\n<h2 id=\"functions-4\">functions<\/h2>\n<pre><code>\/\/ \u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u8be5\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u7684\u9519\u8bef\nfunc Errorf(format string, a ...interface{}) error\n\/\/ \u5199\u5165\u5230STDOUT, \u8fd4\u56de\u5199\u5165\u5b57\u8282\u6570\n\/\/ \u9ed8\u8ba4\u683c\u5f0f\u5316\nfunc Print(a ...interface{}) (n int, err error)\n\/\/ \u9ed8\u8ba4\u683c\u5f0f\u5316\uff0c\u81ea\u52a8\u7ed3\u5c3e\u6dfb\u52a0\u6362\u884c\u7b26\nfunc Println(a ...interface{}) (n int, err error)\n\/\/ \u6307\u5b9a\u683c\u5f0f\u5316\nfunc Printf(format string, a ...interface{}) (n int, err error)\n\/\/ \u5199\u5165\u5230w, \u8fd4\u56de\u5199\u5165\u5b57\u8282\u6570\n\/\/ w: os.File bufio.Writer\nfunc Fprint(w io.Writer, a ...interface{}) (n int, err error)\nfunc Fprintln(w io.Writer, a ...interface{}) (n int, err error)\nfunc Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)\n\/\/ \u8fd4\u56de\u8be5\u5b57\u7b26\u4e32\nfunc Sprint(a ...interface{}) string\nfunc Sprintln(a ...interface{}) string\nfunc Sprintf(format string, a ...interface{}) string\n\/\/ \u4eceSTDIN\u626b\u63cf\u6587\u672c\u5b58\u5165a,\u8fd4\u56de\u6210\u529f\u626b\u63cf\u7684\u4e2a\u6570\n\/\/ \u6362\u884c\u89c6\u4e3a\u7a7a\u767d\uff0c\u83b7\u53d6len(a)\u4e2a\u6761\u76ee\u624d\u505c\u6b62\u626b\u63cf\nfunc Scan(a ...interface{}) (n int, err error)\n\/\/ \u6362\u884c\u624d\u505c\u6b62\u626b\u63cf\nfunc Scanln(a ...interface{}) (n int, err error)\n\/\/ \u6839\u636e\u7a7a\u683c\u5206\u5272\u7684\u6761\u76ee\u683c\u5f0f\u5316\u5199\u5165\u6307\u5b9a\u53c2\u6570a\nfunc Scanf(format string, a ...interface{}) (n int, err error)\n\/\/ \u4ecer\u626b\u63cf\u6587\u672c\u5b58\u5165a, \u8fd4\u56de\u6210\u529f\u626b\u63cf\u7684\u6761\u76ee\n\/\/ r: os.File bufio.Reader\nfunc Fscan(r io.Reader, a ...interface{}) (n int, err error)\nfunc Fscanln(r io.Reader, a ...interface{}) (n int, err error)\nfunc Fscanf(r io.Reader, format string, a ...interface{}) (n int, err error)\n\/\/ \u4ece\u5b57\u7b26\u4e32str\u626b\u63cf\u6587\u672c\u5b58\u5165a, \u8fd4\u56de\u626b\u63cf\u6210\u529f\u7684\u6761\u76ee\nfunc Sscan(str string, a ...interface{}) (n int, err error)\nfunc Sscanln(str string, a ...interface{}) (n int, err error)\nfunc Sscanf(str string, format string, a ...interface{}) (n int, err error)\n<\/code><\/pre>\n<h2 id=\"stringer\">Stringer<\/h2>\n<p>interface:<\/p>\n<pre><code>type Stringer initerface {\nString() string\n}\n<\/code><\/pre>\n<h2 id=\"gostringer\">GoStringer<\/h2>\n<p>interface:<\/p>\n<pre><code>type GoStringer interface {\nGoString() string\n}\n<\/code><\/pre>\n<h2 id=\"state\">State<\/h2>\n<p>interface:<\/p>\n<pre><code>type State interface {\nWrite(b []byte) (ret int, err error)\nWidth() (wid int, ok bool)\nPrecision() (prec int, ok bool)\nFlag(c int) bool\n}\n<\/code><\/pre>\n<h2 id=\"formatter\">Formatter<\/h2>\n<p>interface:<\/p>\n<pre><code>type Formatter interface {\nFormat(f State, c rune)\n}\n<\/code><\/pre>\n<h2 id=\"scanstate\">ScanState<\/h2>\n<p>interface:<\/p>\n<pre><code>type ScanState interface {\nReadRune() (r rune, size int, err error)\nUnreadRune() error\nSkipSpace()\nToken(skipSpace bool, f func(rune) bool) (token []byte, err error)\nWidth() (wid int, ok bool)\nRead(buf []byte) (n int, err error)\n}\n<\/code><\/pre>\n<h2 id=\"scanner-1\">Scanner<\/h2>\n<p>interface:<\/p>\n<pre><code>type Scanner interface {\nScan(state ScanState, verb rune) error\n}\n<\/code><\/pre>\n<hr>\n<h1 id=\"log\">log<\/h1>\n<p>\u5b9e\u73b0\u4e86\u7b80\u5355\u7684\u65e5\u5fd7\u670d\u52a1.<\/p>\n<h2 id=\"constants-3\">Constants<\/h2>\n<pre><code>const (\nLdate = 1 &lt;&lt; iota \/\/ \u65e5\u671f\nLtime \/\/ \u65f6\u95f4\nLmicroseconds \/\/ \u5fae\u79d2\nLlongfile \/\/ \u7edd\u5bf9\u6587\u4ef6\u540d\u548c\u884c\u597d \/path\/to\/file.go:13\nLshortfile \/\/ \u6587\u4ef6\u540d\u548c\u884c\u597d, \u8986\u76d6\u4e0a\u9762\u5b57\u6bb5 file.go:13\nLstdFlags = Ldate | Ltime \/\/ \u6807\u51c6logger\u7684\u521d\u59cb\u503c\n)\n<\/code><\/pre>\n<h2 id=\"functions-5\">functions<\/h2>\n<pre><code>func Printf(format string, v ...interface{})\nfunc Print(v ...interface{})\nfunc Println(v ...interface{})\n\/\/ \u4e0b\u5217\u51fd\u6570\u5728Print...\u51fd\u6570\u57fa\u7840\u4e0a\u518d\u8c03\u7528os.Exit(1)\nfunc Fatalf(format string, v ...interface{})\nfunc Fatal(v ...interface{})\nfunc Fatalln(v ...interface{})\n\/\/ \u4e0b\u5217\u51fd\u6570\u5728Print...\u51fd\u6570\u57fa\u7840\u4e0a\u518d\u8c03\u7528panic(...)\n\/\/ panic\u4f1a\u6267\u884c\u5f53\u524d\u51fd\u6570\u7684defer, \u7136\u540e\u9000\u51fa\u5f53\u524d\u51fd\u6570\uff0c\u8fd4\u56de\u5230\u8c03\u7528\u8005\uff0c\n\/\/ \u8c03\u7528\u51fd\u6570\u4f1a\u6267\u884cdefer, \u76f4\u5230\u5e94\u7528\u7a0b\u5e8f\u9000\u51fa.\u6700\u540epanic.\nfunc Panicf(format string, v ...interface{})\nfunc Panic(v ...interface{})\nfunc Panicln(v ...interface{})\n<\/code><\/pre>\n<h2 id=\"logger\">Logger<\/h2>\n<p>struct:<\/p>\n<pre><code>type Logger struct {}\n<\/code><\/pre>\n<p>function:<\/p>\n<pre><code>\/\/ \u521b\u5efa\u4e00\u4e2aLogger.\nfunc New(out io.Writer, prefix string, flag int) *Logger\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>func (l *Logger) Flags() int\n<\/code><\/pre>\n<hr>\n<h1 id=\"flag\">flag<\/h1>\n<p>\u5b9e\u73b0\u4e86\u547d\u4ee4\u884c\u53c2\u6570\u89e3\u6790<\/p>\n<p>\u7b2c\u4e09\u65b9\u5305:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/alecthomas\/kingpin\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/alecthomas\/kingpin<\/a><\/p>\n<h2 id=\"variables-4\">variables<\/h2>\n<pre><code>var CommandLine = NewFlagSet(os.Args[0], ExitOnError)\n\/\/\nvar ErrHelp = errors.New(&quot;flag: help requested&quot;)\n\/\/\nvar Usage = func() {\nfmt.Fprintf(os.Stderr, &quot;Usage of %s:\\n&quot;, os.Args[0])\nPrintDefaults()\n}\n<\/code><\/pre>\n<h2 id=\"functions-6\">functions<\/h2>\n<pre><code>\/\/ \u8fd4\u56de\u5df2\u88ab\u8bbe\u7f6e\u7684flag\u6570\u91cf\nfunc NFlag() int\n\/\/ \u8fd4\u56de\u5df2\u6ce8\u518cflag\u7684\u7ed3\u6784\u4f53\u6307\u9488\nfunc Lookup(name string) *Flag\n\/\/ \u975eflag\u53c2\u6570\u4e0d\u80fd\u5728flag\u53c2\u6570\u524d\u9762\u6307\u5b9a\uff0c\u5426\u5219flag\u53c2\u6570\u4e0d\u4f1a\u88ab\u89e3\u6790\uff0e\n\/\/ \u8fd4\u56de\u975eflag\u53c2\u6570\u4e2a\u6570\nfunc NArg() int\n\/\/ \u8fd4\u56de\u6240\u6709\u975eflag\u53c2\u6570\nfunc Args() []string\n\/\/ \u8fd4\u56de\u7b2ci\u4e2a\u975eflag\u53c2\u6570, i=0 \u5c31\u662f\u7b2c\u4e00\u4e2a\u53c2\u6570\uff0c\u800c\u4e0d\u662f\u7a0b\u5e8f\u540d\u79f0\nfunc Arg(i int) string\n\/\/ \u5411Stderr\u5199\u5165\u6240\u6709\u6ce8\u518c\u597d\u7684flag\u7684\u9ed8\u8ba4\u503c\nfunc PrintDefaults()\n\/\/ \u4eceos.Args[1:] \u4e2d\u89e3\u6790\u6ce8\u518c\u7684flag.\nfunc Parse()\n\/\/ \u8fd4\u56de\u662f\u5426Parse\u662f\u5426\u88ab\u8c03\u7528\u8fc7\nfunc Parsed() bool\n\/\/ \u6309\u7167\u5b57\u5178\u987a\u5e8f\u904d\u5386flag\uff0c\u5e76\u5bf9\u6bcf\u4e2aflag\u8c03\u7528fn, \u53ea\u9488\u5bf9\u89e3\u6790\u65f6\u8bbe\u7f6e\u4e86\u7684flag\nfunc Visit(fn func(*Flag))\n\/\/ \u6309\u7167\u5b57\u5178\u987a\u5e8f\u904d\u5386flag,\u3000\u5e76\u5bf9\u6bcf\u4e2aflag\u8c03\u7528fn, \u9488\u5bf9\u6240\u6709flag.\nfunc VisitAll(fn func(*Flag))\n\/\/ \u7528\u6307\u5b9a\u7684\u540d\u79f0\uff0c\u9ed8\u8ba4\u503c\uff0c\u5e2e\u52a9\u4fe1\u606f\u6ce8\u518c\u4e00\u4e2abool\u7c7b\u578b\u7684flag\n\/\/ \u8fd4\u56de\u4e00\u4e2a\u4fdd\u5b58\u4e86\u8be5flag\u7684\u503c\u7684\u6307\u9488\nfunc Bool(name string, value bool, usage string) *bool\n\/\/ \u7528\u6307\u5b9a\u7684\u540d\u79f0\uff0c\u9ed8\u8ba4\u503c\uff0c\u5e2e\u52a9\u4fe1\u606f\u6ce8\u518c\u4e00\u4e2abool\u7c7b\u578b\u7684flag\n\/\/ \u5c06flag\u503c\u4fdd\u5b58\u5230\u6307\u9488p\u6307\u5411\u7684\u53d8\u91cf\nfunc BoolVar(p *bool, name string, value bool, usage string)\nfunc Int\nfunc IntVar\nfunc Int64\nfunc Int64Var\nfunc Uint\nfunc UintVar\nfunc Uint64\nfunc Uint64Var\nfunc Float64\nfunc Float64Var\nfunc String\nfunc StringVar\n\/\/ time.Duration\u7c7b\u578b\nfunc Duration\nfunc DurationVar\n\/\/ \u7528\u6307\u5b9a\u7684\u540d\u5b57\uff0c\u5e2e\u52a9\u4fe1\u606f\uff0c\u6ce8\u518c\u4e00\u4e2aflag\uff0c\u7c7b\u578b\u7531value\u51b3\u5b9a\nfunc Var(value Value, name string, usage string)\n\/\/ \u8bbe\u7f6e\u5df2\u6ce8\u518c\u7684flag\u7684\u503c\nfunc Set(name, value string) error\n<\/code><\/pre>\n<h2 id=\"errorhandling\">ErrorHandling<\/h2>\n<p>\u5b9a\u4e49\u5982\u4f55\u5904\u7406flag\u89e3\u6790\u9519\u8bef<\/p>\n<pre><code>type ErrorHandling int\nconst (\nContinueOnError ErrorHandling = iota\nExitOnError\nPanicOnError\n)\n<\/code><\/pre>\n<h2 id=\"flag-1\">Flag<\/h2>\n<p>\u5b9a\u4e49\u4e00\u4e2aflag<\/p>\n<p>struct:<\/p>\n<pre><code>type Flag struct {\nName string\nUsage string\nValue Value\nDefValue string\n}\n<\/code><\/pre>\n<h2 id=\"flagset\">FlagSet<\/h2>\n<p>\u4ee3\u8868\u4e00\u4e2a\u5df2\u6ce8\u518cflag\u96c6\u5408.<\/p>\n<p>FlagSet\u96f6\u503c\u6ca1\u6709\u540d\u5b57\uff0c\u9ed8\u8ba4\u91c7\u7528ContinueOnError.<\/p>\n<p>struct:<\/p>\n<pre><code>type FlagSet struct {\nUsage func()\n}\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>\/\/ \u521b\u5efa\u4e00\u4e2a\u65b0\u7684FlagSet\u53ebname\uff0c\u91c7\u7528errorHandling\u4e3a\u9519\u8bef\u5904\u7406\u7b56\u7565\nfunc NewFlagSet(name string, errorHandling ErrorHandling) *FlagSet\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>\/\/ \u8bbe\u7f6ef\u7684\u540d\u5b57\u548c\u9519\u8bef\u5904\u7406\u7b56\u7565.\nfunc (f *FlagSet) Init(name string, errorHandling ErrorHandling)\n<\/code><\/pre>\n<h2 id=\"value\">Value<\/h2>\n<p>\u7528\u4e8e\u5c06\u52a8\u6001\u503c\u4fdd\u5b58\u5728flag\u91cc.<\/p>\n<p>interface:<\/p>\n<pre><code>type Value interface {\nString() string\nSet(string) error\n}\n<\/code><\/pre>\n<h2 id=\"getter\">Getter<\/h2>\n<hr>\n<h1 id=\"logrus\">logrus<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/sirupsen\/logrus\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/sirupsen\/logrus<\/a><\/p>\n<hr>\n<h1 id=\"cobra\">cobra<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/spf13\/cobra\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/spf13\/cobra<\/a><\/p>"},{"title":"GSL_test","link":"https:\/\/canuxcheng.com\/post\/gsl_test\/","pubDate":"Mon, 01 Jan 2018 10:49:21 +0000","guid":"https:\/\/canuxcheng.com\/post\/gsl_test\/","description":"<h1 id=\"testing\">testing<\/h1>\n<p>go\u7684\u6d4b\u8bd5\u7531go test\u547d\u4ee4\u548ctesting\u5305\u7ec4\u6210\uff0e<\/p>\n<p>\u6d4b\u8bd5\u7a0b\u5e8f\u547d\u540d\uff1a<\/p>\n<pre><code>XXX.go # \u6d4b\u8bd5\u6587\u4ef6\u548c\u6e90\u7801\u653e\u5728\u4e00\u4e2a\u5305\u4e2d\nXXX_test.go\n<\/code><\/pre>\n<p>\u6d4b\u8bd5\u7a0b\u5e8f\u7ed3\u6784\uff1a<\/p>\n<pre><code>import &quot;testing&quot;\n# \u5355\u5143\u6d4b\u8bd5\n# go test \u4f1a\u81ea\u52a8\u6267\u884c\nfunc TestXXX(t *testing.T) {}\n# \u6027\u80fd\u6d4b\u8bd5\n# go test XXX_test.go -test.bench=&quot;.*&quot; \u538b\u529b\u6d4b\u8bd5\u9700\u8981\u6307\u5b9a\u624d\u80fd\u6267\u884c\nfunc BenchmarkXXX(b *testing.B) {}\n<\/code><\/pre>\n<h2 id=\"constants\">constants<\/h2>\n<h2 id=\"variables\">variables<\/h2>\n<h2 id=\"functions\">functions<\/h2>\n<h2 id=\"t\">T<\/h2>\n<p>\u7ba1\u7406\u6d4b\u8bd5\u72b6\u6001\u5e76\u652f\u6301\u683c\u5f0f\u5316\u6d4b\u8bd5\u7684\u65e5\u5fd7\uff0e<\/p>\n<p>struct:<\/p>\n<pre><code>type T struct {}\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>\/\/ \u5c06\u5f53\u524d\u6d4b\u8bd5\u6807\u8bc6\u4e3a\u5931\u8d25\uff0c\u4f46\u7ee7\u7eed\u6267\u884c\u8be5\u6587\u4ef6\u5269\u4e0b\u7684\u6d4b\u8bd5\nfunc (c *T) Fail()\n\/\/ \u5c06\u5f53\u524d\u6d4b\u8bd5\u6807\u8bc6\u4e3a\u5931\u8d25\uff0c\u5e76\u505c\u6b62\u6267\u884c\u8be5\u6d4b\u8bd5, \u7ee7\u7eed\u6267\u884c\u4e0b\u4e00\u4e2a\u6d4b\u8bd5\u6587\u4ef6.\nfunc (c *T) FailNow()\n\/\/ \u7528\u4e8e\u62a5\u544a\u6d4b\u8bd5\u51fd\u6570\u662f\u5426\u5931\u8d25\nfunc (c *T) Failed() bool\nfunc (c *T) Log(args ...interface{})\nfunc (c *T) Logf(format string, args ...interface{})\n# \u76f8\u5f53\u4e8eLog\/Logf\u4e4b\u540e\u8c03\u7528Fail.(\u5f53\u524dcase\u5931\u8d25)\nfunc (c *T) Error(args ...interface{})\nfunc (c *T) Errorf(format string, args ...interface{})\n# \u76f8\u5f53\u4e8eLog\/Logf\u4e4b\u540e\u8c03\u7528FailNow.(\u5f53\u524d\u6d4b\u8bd5\u6587\u4ef6\u5931\u8d25)\nfunc (c *T) Fatal(args ...interface{})\nfunc (c *T) Fatalf(format string, args ...interface{})\nfunc (c *T) Skip(args ...interface{})\nfunc (c *T) SkipNow()\nfunc (c *T) Skipf(format string, args ...interface{})\nfunc (c *T) Skipped() bool\n<\/code><\/pre>\n<h2 id=\"b\">B<\/h2>\n<p>\u7ba1\u7406\u57fa\u51c6\u6d4b\u8bd5\u7684\u8ba1\u65f6\u884c\u4e3a\uff0c\u5e76\u6307\u793a\u5e94\u8be5\u8fed\u4ee3\u7684\u8fd0\u884c\u6d4b\u8bd5\u591a\u5c11\u6b21.<\/p>\n<p>struct:<\/p>\n<pre><code>type B struct {\nN int\n}\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>func (c *B) Fail()\nfunc (c *B) FailNow()\nfunc (c *B) Failed() bool\nfunc (c *B) Error(args ...interface{})\nfunc (c *B) Errorf(format string, args ...interface{})\nfunc (c *B) Fatal(args ...interface{})\nfunc (c *B) Fatalf(format string, args ...interface{})\nfunc (c *B) Log(args ...interface{})\nfunc (c *B) Logf(format string, args ...interface{})\nfunc (c *B) Skip(args ...interface{})\nfunc (c *B) SkipNow()\nfunc (c *B) Skipf(format string, args ...interface{})\nfunc (c *B) Skipped() bool\n<\/code><\/pre>\n<hr>\n<h1 id=\"testingiotest\">testing\/iotest<\/h1>\n<hr>\n<h1 id=\"testingquick\">testing\/quick<\/h1>\n<hr>\n<h1 id=\"gotests\">gotests<\/h1>\n<p>\u901a\u8fc7\u6e90\u4ee3\u7801\u81ea\u52a8\u751f\u6210\u6d4b\u8bd5\u4ee3\u7801\uff0c\u53ef\u4ee5\u7528\u547d\u4ee4\u884c\uff0c\u4e5f\u53ef\u4ee5\u7528goland\u7b49\u7684\u63d2\u4ef6\uff0e<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/cweill\/gotests\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/cweill\/gotests<\/a><\/p>\n<pre><code>go get -u github.com\/cweill\/gotests\/...\n<\/code><\/pre>"},{"title":"OOP","link":"https:\/\/canuxcheng.com\/post\/go_oop\/","pubDate":"Mon, 01 Jan 2018 10:49:21 +0000","guid":"https:\/\/canuxcheng.com\/post\/go_oop\/","description":"<h1 id=\"go\u9762\u5411\u5bf9\u8c61\">Go\u9762\u5411\u5bf9\u8c61<\/h1>\n<p>golang\u4e0d\u662f\u4f20\u7edf\u7684\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff0c\u800c\u662f\u901a\u8fc7struct, method, interface, embedding\u5b9e\u73b0\u9762\u5411\u5bf9\u8c61\u7684\u6838\u5fc3\u529f\u80fd.<\/p>\n<hr>\n<h2 id=\"\u65b9\u6cd5method\">\u65b9\u6cd5\/method<\/h2>\n<p>go\u4e2d\u6ca1\u6709\u7c7b\uff0c\u4f46\u662f\u53ef\u4ee5\u4e3a\u7ed3\u6784\u4f53\u5b9a\u4e49\u65b9\u6cd5\uff0e<\/p>\n<p>\u65b9\u6cd5\u5c31\u662f\u4e00\u7c7b\u5e26\u6709\u7279\u6b8a\u7684\u3000\u63a5\u6536\u8005\u53c2\u6570\u3000\u7684\u51fd\u6570\uff0e<\/p>\n<p>\u53ea\u80fd\u4e3a\u540c\u4e00\u5305\u5185\u5b9a\u4e49\u7684\u7c7b\u578b\u7684\u63a5\u6536\u8005\u7533\u660e\u65b9\u6cd5\uff0c\u4e0d\u80fd\u4e3a\u5176\u5b83\u5305\u5185\u5b9a\u4e49\u7684\u7c7b\u578b\u7684\u63a5\u6536\u8005\u7533\u660e\u65b9\u6cd5\uff0e<\/p>\n<p>\u9664\u4e86\u7ed3\u6784\u4f53\u8fd8\u53ef\u4ee5\u4e3a\u975e\u7ed3\u6784\u4f53\u7533\u660e\u65b9\u6cd5\uff0c\u4f46\u662f\u4e0d\u80fd\u4e3a\u5185\u5efa\u7c7b\u578b\u7533\u660e\u65b9\u6cd5\uff0e<\/p>\n<p>\u65b9\u6cd5\u6709\u4e24\u79cd\u63a5\u6536\u8005,\u503c\u63a5\u6536\u8005\u548c\u6307\u9488\u63a5\u6536\u8005.<\/p>\n<pre><code>type Vertex struct {\n...\n}\n<\/code><\/pre>\n<p>\u503c\u63a5\u6536\u8005:<\/p>\n<p>\u503c\u63a5\u6536\u8005\u64cd\u4f5c\u7684\u662f\u503c\u7684\u526f\u672c.<\/p>\n<pre><code>func (v Vertex) MethodName() rType {\n...\n}\nvar v Vertex\nv.MethodName() \/\/ \u64cd\u4f5c\u503c\u7684\u526f\u672c\n# \u4f7f\u7528\u6307\u9488\u63a5\u6536\u8005\u6765\u8c03\u7528\u503c\u63a5\u6536\u8005\u7684\u65b9\u6cd5\uff0c\u7f16\u8bd1\u5668\u4f1a\u81ea\u52a8\u505a\u7c7b\u578b\u8f6c\u6362\nvp := new(Vertex)\nvp.MethodName() \/\/ \u6307\u9488\u88ab\u89e3\u5f15\u7528\u4e3a\u503c,(*vp).MethodName(),\u64cd\u4f5c\u7684\u662f\u6307\u9488\u6307\u5411\u7684\u503c\u7684\u526f\u672c.\n<\/code><\/pre>\n<p>\u6307\u9488\u63a5\u6536\u8005\uff1a<\/p>\n<p>\u6307\u9488\u63a5\u6536\u8005\uff0c\u8c03\u7528\u65b9\u6cd5\u7684\u65f6\u5019\u64cd\u4f5c\u7684\u662f\u8be5\u6307\u9488\u6307\u5411\u7684\u503c.<\/p>\n<pre><code># \u6307\u9488\u63a5\u6536\u8005\u7684\u65b9\u6cd5\u53ef\u4ee5\u4fee\u6539\u63a5\u6536\u8005\u6307\u5411\u7684\u503c\nfunc (v *Vertex) MethodName() rType {\n...\n}\nvp := new(Vertex)\nvp.MethodName() \/\/ \u64cd\u4f5c\u5b9e\u9645\u7684\u503c\n# \u4f7f\u7528\u503c\u63a5\u6536\u8005\u6765\u8c03\u7528\u6307\u9488\u63a5\u6536\u8005\u7684\u65b9\u6cd5\uff0c\u7f16\u8bd1\u5668\u4f1a\u81ea\u52a8\u505a\u7c7b\u578b\u8f6c\u6362.\nvar v Vertex\nv.MethodName() \/\/ (&amp;v).MethodName() , \u64cd\u4f5c\u7684\u662f\u5b9e\u9645\u7684\u503c\n<\/code><\/pre>\n<hr>\n<h2 id=\"\u63a5\u53e3interface\">\u63a5\u53e3\/Interface<\/h2>\n<p>\u63a5\u53e3\u662f\u5f15\u7528\u7c7b\u578b. zero value is nil.<\/p>\n<p>\u63a5\u53e3\u7c7b\u578b\u662f\u7531\u4e00\u7ec4\u65b9\u6cd5\u7b7e\u540d\u5b9a\u4e49\u7684\u96c6\u5408, \u4efb\u4f55\u5b9e\u73b0\u4e86\u8fd9\u4e9b\u65b9\u6cd5\u7684\u7c7b\u578b\uff0c\u81ea\u52a8\u88ab\u8ba4\u4e3a\u5b9e\u73b0\u4e86\u8fd9\u4e2a\u63a5\u53e3\u3002\uff0e<\/p>\n<p>\u67d0\u4e2a\u7c7b\u578b\u5b9e\u73b0\u4e86\u8be5\u63a5\u53e3\u7684\u6240\u6709\u65b9\u6cd5\u7b7e\u540d\uff0c\u5c31\u7b97\u5b9e\u73b0\u4e86\u8be5\u63a5\u53e3,\u65e0\u9700\u663e\u793a\u7533\u660e\u5b9e\u73b0\u4e86\u54ea\u4e2a\u63a5\u53e3.<\/p>\n<p>\u63a5\u53e3\u53ef\u4ee5\u533f\u540d\u5d4c\u5165\u5176\u5b83\u63a5\u53e3\uff0c\u6216\u5d4c\u5165\u5230\u7ed3\u6784\u4e2d\uff0e<\/p>\n<p>\u4e00\u822c\u53ea\u6709\u4e00\u4e2a\u65b9\u6cd5\u7684\u63a5\u53e3\u547d\u540d\u4e3aMethodName + &rsquo;er'.<\/p>\n<p>\u63a5\u53e3\u5b58\u50a8\u4e24\u4e2a\u6570\u636e\u63a5\u53e3\uff1a<\/p>\n<ul>\n<li>iTable, \u5305\u542b\u5b58\u50a8\u503c\u7684\u7c7b\u578b\u4fe1\u606f\u4ee5\u53ca\u548c\u8be5\u503c\u5173\u8054\u7684\u65b9\u6cd5.<\/li>\n<li>\u6307\u5411\u5b58\u50a8\u7684\u503c\u7684\u6307\u9488.<\/li>\n<\/ul>\n<p>\u5b9a\u4e49\u63a5\u53e3\uff1a<\/p>\n<pre><code>type Speaker interface {\nSpeak()\n}\ntype Animal struct {\nName string\n}\nfunc (a Animal) Speak() {\n...\n}\n<\/code><\/pre>\n<p>\u503c\u63a5\u6536\u8005\u65b9\u6cd5:<\/p>\n<p>\u63a5\u53e3\u7c7b\u578b\u7684\u503c\u4e3a\u503c\u6216\u6307\u9488\u90fd\u53ef\u4ee5\u8c03\u7528\u8be5\u65b9\u6cd5.<\/p>\n<pre><code>func (s SName) MethodName() {}\n<\/code><\/pre>\n<p>\u6307\u9488\u63a5\u6536\u8005\u65b9\u6cd5:<\/p>\n<p>\u63a5\u53e3\u7c7b\u578b\u7684\u503c\u5fc5\u987b\u4e3a\u6307\u9488\u624d\u80fd\u8c03\u7528\u8be5\u65b9\u6cd5.<\/p>\n<pre><code>func (s *SName) MethodName() {\n...\n}\ns := &amp;SName{...}\n\/\/ i = &amp;SName{...} \/\/\u63a5\u53e3\u53d8\u91cf\u80fd\u4fdd\u5b58\u5b9e\u73b0\u4e86\u8be5\u63a5\u53e3\u7684\u4efb\u610f\u7c7b\u578b\u7684\u5bf9\u8c61\ni = s\ni.MethodName()\n# \u63a5\u53e3\u7c7b\u578b\u4e3a\u503c\u65f6\uff0c\u8c03\u7528\u5931\u8d25\nvar s SName\ni = s\ni.MethodName() \/\/ \u8c03\u7528\u5931\u8d25\n<\/code><\/pre>\n<ul>\n<li>\u7a7a\u63a5\u53e3\uff1a<\/li>\n<\/ul>\n<p>\u6240\u6709\u7c7b\u578b\u90fd\u5b9e\u73b0\u4e86\u7a7a\u63a5\u53e3.<\/p>\n<p>\u6307\u5b9a\u4e86\u96f6\u4e2a\u65b9\u6cd5\u7684\u63a5\u53e3\u503c\u88ab\u79f0\u4e3a\u7a7a\u63a5\u53e3,\u4e00\u822c\u7528\u6765\u5904\u7406\u672a\u77e5\u7c7b\u578b\u7684\u503c.<\/p>\n<p>\u5f53\u63a5\u53e3\u50a8\u5b58\u7684\u7c7b\u578b\u548c\u5bf9\u8c61\u90fd\u4e3anil\uff0c\u63a5\u53e3\u624d\u4e3anil<\/p>\n<p>\u4ee5\u7a7a\u63a5\u53e3\u4e3a\u53c2\u6570\u7684\u51fd\u6570\u53ef\u4ee5\u63a5\u6536\u4efb\u610f\u7c7b\u578b\u7684\u503c\u4f5c\u4e3a\u53c2\u6570.<\/p>\n<p>\u5982\u679c\u4e00\u4e2a\u51fd\u6570\u8fd4\u56de\u7a7a\u63a5\u53e3\u5c31\u53ef\u4ee5\u8fd4\u56de\u4efb\u610f\u7c7b\u578b\u7684\u503c.<\/p>\n<pre><code>var x interface{}\nx = 43\nx = &quot;hello&quot;\n# \u7a7a\u63a5\u53e3\u53ef\u4ee5\u4fdd\u5b58\u4efb\u4f55\u7c7b\u578b\u7684\u503c\nvar i interface{}\n# \u7a7a\u63a5\u53e3\u4f5c\u4e3a\u5f62\u53c2\nfunc FuncName(i interface{}) {}\n<\/code><\/pre>\n<ul>\n<li>\u6307\u9488\u7684\u7c7b\u578b\u65ad\u8a00\/comma-ok\u65ad\u8a00\uff1a<\/li>\n<\/ul>\n<p>\u65ad\u8a00\u63a5\u53e3\u503ci\u4fdd\u5b58\u4e86\u5177\u4f53\u7c7b\u578bType, \u5e76\u5c06\u5e95\u5c42\u7c7b\u578b\u4e3aType\u7684\u503c\u8d4b\u4e88\u53d8\u91cft.<\/p>\n<pre><code>\u53ea\u8fd4\u56de\u4e00\u4e2a\u503c\uff0c\u65ad\u8a00\u5931\u8d25\u4f1a\u89e6\u53d1panic.\nt := i.(Type)\n\u8fd4\u56de\u4e24\u4e2a\u503c\uff0c\u65ad\u8a00\u6210\u529f\u8fd4\u56detrue, \u5931\u8d25\u8fd4\u56defalse.\nvar x interface{} = &quot;hello&quot;\nstr, ok := x.(string) \/\/ ok=true\nnum, ok := x.(int) \/\/ ok=false \u65ad\u8a00\u5931\u8d25\n\/\/ i.(type) \u662f\u56fa\u5b9a\u5199\u6cd5\nswitch v := i.(type) {\ncase string:\nfmt.Println(&quot;string&quot;)\ncase int:\nfmt.Println(&quot;int&quot;)\ndefault:\nfmt.Println(&quot;unknown type&quot;)\n}\n<\/code><\/pre>\n<ul>\n<li>\u5d4c\u5165\u63a5\u53e3:<\/li>\n<\/ul>\n<p>\u63a5\u53e3\u4e2d\u53ef\u4ee5\u5d4c\u5165\u5176\u5b83\u63a5\u53e3\uff0c\u8fd9\u6837\u5b9e\u73b0\u4e86\u8be5\u63a5\u53e3\u7684\u5bf9\u8c61\u5c31\u9690\u5f0f\u5305\u542b\u5d4c\u5165\u63a5\u53e3\u7684\u6240\u6709\u65b9\u6cd5.<\/p>\n<pre><code>type Reader interface {\nRead()\n}\ntype Writer interface {\nWrite()\n}\ntype ReadWriter interface {\nReader\nWriter\n}\n<\/code><\/pre>\n<hr>\n<h2 id=\"\u5c01\u88c5encapsulation\">\u5c01\u88c5Encapsulation<\/h2>\n<p>\u5c0f\u5199\u5b57\u6bcd\u5f00\u5934\u7684\u6807\u8bc6\u7b26\uff08\u7c7b\u578b\/\u5c5e\u6027\/\u65b9\u6cd5&hellip;)\u662f\u672a\u516c\u5f00\u7684\uff0c\u53ea\u80fd\u5728\u5f53\u524d\u5305\u5f15\u7528\uff0c\u4e0d\u80fd\u5728\u5176\u5b83\u5305\u5f15\u7528\u3002<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u5de5\u5382\u51fd\u6570\u5bf9\u5916\u66b4\u9732\u672a\u516c\u5f00\u7684\u6807\u8bc6\u7b26:<\/p>\n<ul>\n<li>\u6807\u8bc6\u7b26\u624d\u6709\u516c\u5f00\u6216\u672a\u516c\u5f00\u5c5e\u6027\uff0c\u503c\u6ca1\u6709<\/li>\n<li>\u77ed\u53d8\u91cf\u58f0\u660e\u64cd\u4f5c\u7b26\uff0c\u6709\u80fd\u529b\u6355\u83b7\u5f15\u7528\u7684\u7c7b\u578b\uff0c\u5e76\u521b\u5efa\u4e00\u4e2a\u672a\u516c\u5f00\u7684\u7c7b\u578b\u7684\u53d8\u91cf\uff1b\u663e\u793a\u58f0\u660e\u7684\u53d8\u91cf\u4e0d\u80fd\u5f15\u7528\u672a\u516c\u5f00\u7c7b\u578b\u3002<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u5de5\u5382\u51fd\u6570\u8fd4\u56de\u672a\u516c\u5f00\u7c7b\u578b\u7684\u503c:<\/p>\n<pre><code># packageA\ntype privateType Type\nfunc New(args) privateType {\nreturn privateType(args)\n}\n# packageB\nimport packageA\nfunc main() {\nb := packageA.New(args) \/\/ \u8fd4\u56de\u4e00\u4e2a\u503c\uff0c\u800c\u4e0d\u662f\u6807\u8bc6\u7b26\n}\n<\/code><\/pre>\n<p>\u516c\u5f00\u7c7b\u578b\u7684\u672a\u516c\u5f00\u5c5e\u6027:<\/p>\n<pre><code># packageA\ntype Public struct {\nprivate Type\n}\n# packageB\nimport packageA\nfunc main() {\nb := packageA.Public{\nprivate: value, \/\/ panic, \u516c\u5f00\u7c7b\u578b\u7684\u672a\u516c\u5f00\u5c5e\u6027\u4e0d\u80fd\u901a\u8fc7\u5b57\u9762\u91cf\u76f4\u63a5\u8d4b\u503c\n}\n}\n<\/code><\/pre>\n<p>\u7c7b\u578b\u5d4c\u5957\u4e2d\u7684\u672a\u516c\u5f00\u7c7b\u578b\u7684\u516c\u5f00\u5c5e\u6027\u4f1a\u63d0\u5347\u5230\u5916\u90e8\u7c7b\u578b:<\/p>\n<pre><code># packageA\ntype inner struct { \/\/ inner private\nIn Type \/\/ In public\n}\ntype Outer struct {\ninner\nOut Type\n}\n# packageB\nimport packageA\nfunc main() {\nb := packageA.Outer{\nOut: value, \/\/ \u5916\u90e8\u7c7b\u578b\u4e2d\u7684\u672a\u516c\u5f00\u5185\u90e8\u7c7b\u578b\u4e0d\u80fd\u901a\u8fc7\u5b57\u9762\u91cf\u76f4\u63a5\u8d4b\u503c\n}\nb.In = value \/\/ \u5185\u90e8\u7c7b\u578b\u7684\u516c\u5f00\u5c5e\u6027\u63d0\u5347\u5230\u5916\u90e8\u7c7b\u578b\u3002\n}\n<\/code><\/pre>\n<h2 id=\"\u591a\u6001polymorphism\">\u591a\u6001Polymorphism<\/h2>\n<p>golang\u591a\u6001\u901a\u8fc7interface\u5b9e\u73b0\u3002<\/p>\n<p>\u5f62\u5f0f\u53c2\u6570\u662f\u63a5\u53e3\u7684\u51fd\u6570\uff0c\u53eb\u505a\u591a\u6001\u51fd\u6570.<\/p>\n<pre><code>func FuncName(iVar IName) {}\n<\/code><\/pre>\n<p>\u6240\u6709\u5b9e\u73b0\u4e86\u63a5\u53e3\u7684\u65b9\u6cd5\u7684\u5b9e\u4f53\u7c7b\u578b\uff0c\u5c31\u53ef\u4ee5\u4f5c\u4e3a\u53c2\u6570\u4f20\u7ed9\u591a\u6001\u51fd\u6570.<\/p>\n<pre><code>type Speaker interface {\nSpeak()\n}\n<\/code><\/pre>\n<p>\u5b9e\u73b01<\/p>\n<pre><code>type Dog struct{}\nfunc (d Dog) Speak() {\nfmt.Println(&quot;dog&quot;)\n}\n<\/code><\/pre>\n<p>\u5b9e\u73b02<\/p>\n<pre><code>type Cat struct{}\nfunc (c Cat) Speak() {\nfmt.Println(&quot;cat&quot;)\n}\n<\/code><\/pre>\n<p>\u591a\u6001\u51fd\u6570<\/p>\n<pre><code>func makeSound(s Speaker) {\ns.Speak()\n}\nfunc main() {\nvar d Dog\nvar c Cat\nmakeSound(d) \/\/ dog\nmakeSound(c) \/\/ cat\n}\n<\/code><\/pre>\n<hr>\n<h2 id=\"\u7ee7\u627finheritance\">\u7ee7\u627fInheritance<\/h2>\n<p>golang\u6ca1\u6709\u7ee7\u627f\uff0c\u4f46\u662f\u53ef\u4ee5\u901a\u8fc7\u7ed3\u6784\u4f53\u5d4c\u5957\u5b9e\u73b0\u7ee7\u627f\u884c\u4e3a\u3002<\/p>\n<p>\u5982\u679c\u5916\u90e8\u7c7b\u578b\u5b9e\u73b0\u540c\u540d\u7684\u5c5e\u6027\u6216\u65b9\u6cd5\uff0c\u5c31\u4f1a\u8986\u76d6\u5185\u90e8\u7c7b\u578b\u7684\u5c5e\u6027\u6216\u65b9\u6cd5\uff08\u4e0d\u8fc7\u5185\u90e8\u7c7b\u578b\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u8fd8\u5728\uff0c\u53ef\u4ee5\u901a\u8fc7\u5185\u90e8\u7c7b\u578b\u8bbf\u95ee\uff09<\/p>\n<p>\u5185\u90e8\u7c7b\u578b\u5b9e\u73b0\u7684\u63a5\u53e3\uff0c\u4e5f\u4f1a\u81ea\u52a8\u63d0\u5347\u5230\u5916\u90e8\u7c7b\u578b\u3002\u53ea\u8981\u5185\u90e8\u7c7b\u578b\u5b9e\u73b0\u4e86\u67d0\u63a5\u53e3\uff0c\u5916\u90e8\u7c7b\u578b\u76f8\u5f53\u4e8e\u4e5f\u5b9e\u73b0\u4e86\u8be5\u63a5\u53e3\u3002<\/p>\n<p>\u5982\u679c\u533f\u540d\u5b57\u6bb5\u5b9e\u73b0\u4e86\u4e00\u4e2a\u65b9\u6cd5\uff0c\u90a3\u4e48\u5305\u542b\u8fd9\u4e2a\u533f\u540d\u5b57\u6bb5\u7684\u7ed3\u6784\u4e5f\u53ef\u4ee5\u8c03\u7528\u8be5\u65b9\u6cd5.<\/p>\n<pre><code>type Inner struct {\nin Type\n}\nfunc (i *Inner) InnerMethod() {}\ntype Outer struct {\nInner \/\/ \u53ea\u9700\u8981\u7c7b\u578b\u540d\u79f0\uff0c\u4e0d\u9700\u8981\u58f0\u660e\u53d8\u91cf\nout Type\n...\n}\nouter := Outer{}\nouter.Inner.InnerMethod() \/\/\u59cb\u7ec8\u53ef\u4ee5\u8bbf\u95ee\u5185\u90e8\u7c7b\u578b\u7684\u65b9\u6cd5\uff0c\u5373\u4f7f\u5916\u90e8\u7c7b\u578b\u5b9e\u73b0\u540c\u540d\u65b9\u6cd5\nouter.Inner.in \/\/ \u540c\u4e0a\nouter.InnerMethod() \/\/\u5982\u679c\u5916\u90e8\u7c7b\u578b\u6ca1\u6709\u5b9e\u73b0\u540c\u540d\u65b9\u6cd5\uff0c\u5c31\u662f\u5185\u90e8\u7c7b\u578b\u65b9\u6cd5\uff0c\u5426\u5219\u662f\u5916\u90e8\u7c7b\u578b\u65b9\u6cd5\nouter.in \/\/ \u540c\u4e0a\n<\/code><\/pre>\n<hr>\n<h2 id=\"\u53cd\u5c04reflection\">\u53cd\u5c04Reflection<\/h2>\n<p>\u53cd\u5c04\u5c31\u662f\u68c0\u67e5\u7a0b\u5e8f\u5728\u8fd0\u884c\u65f6\u7684\u72b6\u6001.<\/p>\n<p>\u4f7f\u7528\u53cd\u5c04\u4e00\u822c\u4f7f\u7528\u6807\u51c6\u5e93reflect.<\/p>\n<p>Go \u7684\u53cd\u5c04\u901a\u8fc7 reflect.TypeOf() \u548c reflect.ValueOf() \u5728\u8fd0\u884c\u65f6\u68c0\u67e5\u6216\u64cd\u4f5c\u5bf9\u8c61\uff0c\u662f\u5b9e\u73b0\u6cdb\u578b\u3001\u5e8f\u5217\u5316\u3001ORM\u3001\u63a5\u53e3\u65ad\u8a00\u7b49\u52a8\u6001\u529f\u80fd\u7684\u57fa\u7840\u3002<\/p>\n<pre><code>import &quot;reflect&quot;\nx := 123\nt := reflect.TypeOf(x) \/\/ int\nv := reflect.ValueOf(x) \/\/ 123\nk := t.Kind() \/\/ reflect.Int\n<\/code><\/pre>"},{"title":"Rabbitmq","link":"https:\/\/canuxcheng.com\/post\/rabbitmq\/","pubDate":"Mon, 25 Sep 2017 09:41:39 +0000","guid":"https:\/\/canuxcheng.com\/post\/rabbitmq\/","description":"<h1 id=\"amqp\">AMQP<\/h1>\n<p>AMQP: Advanced Message Queuing Protocol,\u9ad8\u7ea7\u6d88\u606f\u961f\u5217\u534f\u8bae<\/p>\n<p>\u5e38\u7528\u7684\u5f00\u6e90AMQP\u6846\u67b6\uff1a<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/rabbitmq\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/rabbitmq<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/apache\/kafka\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/apache\/kafka<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/apache\/activemq\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/apache\/activemq<\/a><\/p>\n<h1 id=\"mqtt\">MQTT<\/h1>\n<p>MQTT: Message Queuing Telemetry Transport,\u6d88\u606f\u961f\u5217\u9065\u6d4b\u4f20\u8f93\u534f\u8bae<\/p>\n<hr>\n<h1 id=\"rabbitmq\">Rabbitmq<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/rabbitmq\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/rabbitmq<\/a><\/p>\n<p>RabbitMQ\u662f\u4e00\u4e2aerlang\u5f00\u53d1\u7684\u7b26\u5408AMQP\u548cMQTT\u7684\u5f00\u6e90\u9879\u76ee\uff0e<\/p>\n<p>rabbitmq-server\u4e5f\u53ebbroker server<\/p>\n<p>rabbitmq\u7684\u4e09\u4e2a\u7ec4\u4ef6\uff1a<\/p>\n<ul>\n<li>exchange,\u3000\u4ea4\u6362\u5668\uff0c\u53d1\u9001\u6d88\u606f\u7684\u5b9e\u4f53<\/li>\n<li>binding, \u7ed1\u5b9a\u5668\uff0c\u8fde\u63a5\u4ea4\u6362\u5668\u548c\u961f\u5217\uff0c\u5e76\u4e14\u5c01\u88c5\u6d88\u606f\u7684\u8def\u7531\u4fe1\u606f<\/li>\n<li>queue,\u3000\u961f\u5217\uff0c\u63a5\u53d7\u6d88\u606f\u7684\u5b9e\u4f53<\/li>\n<\/ul>\n<p>workflow:<\/p>\n<pre><code>producer(publish-message) =&gt;\nrabbitmq-server =&gt; exchange -&gt; binding -&gt; queue =&gt;\n=&gt; comsumer\n<\/code><\/pre>\n<p>producer: \u751f\u4ea7message\u5e76\u4e14publish\u5230rabbitmq-server.<\/p>\n<p>consumer: \u8fde\u63a5\u5230rabbitmq-server\u5e76\u4e14subscribe\u4e00\u4e9bqueue.<\/p>\n<p>connection: producer\u548cconsumer\u90fd\u662f\u901a\u8fc7tcp\u8fde\u63a5\u5230rabbitmq-server.<\/p>\n<p>channels: \u5efa\u7acb\u5728tcp\u8fde\u63a5\u4e2d\u7684\u865a\u62df\u8fde\u63a5\uff0c\u7528\u4e8e\u5904\u7406\u6570\u636e\u6d41\u52a8.<\/p>\n<p>queue:\u3000\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u90fd\u5e94\u8be5\u521b\u5efaqueue.(\u53ea\u80fd\u901a\u8fc7exchange\u63a5\u6536message)<\/p>\n<p>exchanges\u7c7b\u578b:<\/p>\n<ul>\n<li>fanout: \u6240\u6709\u7ed1\u5b9a\u5230\u6b64exchange\u7684queue\u90fd\u53ef\u4ee5\u63a5\u6536\u6d88\u606f<\/li>\n<li>direct: \u901a\u8fc7routingKey\u548cexchange\u51b3\u5b9a\u7684\u90a3\u4e2a\u552f\u4e00\u7684queue\u53ef\u4ee5\u63a5\u6536\u6d88\u606f<\/li>\n<li>topic\uff1a\u6240\u6709\u7b26\u5408routingKey(\u6b64\u65f6\u53ef\u4ee5\u662f\u4e00\u4e2a\u8868\u8fbe\u5f0f)\u7684routingKey\u6240bind\u7684queue\u53ef\u4ee5\u63a5\u6536\u6d88\u606f<\/li>\n<\/ul>\n<p>message\u7c7b\u578b:<\/p>\n<ul>\n<li>messages: \u751f\u4ea7\u8005\u4ea7\u751f\u7684\u603b\u6d88\u606f\u6570\uff0e<\/li>\n<li>messages_ready: \u7b49\u5f85deliver\u7ed9\u6d88\u8d39\u8005\u7684\u6d88\u606f\uff0e<\/li>\n<li>messages_unack: \u5df2\u7ecf\u88abconsumer\u5904\u7406\uff0c\u4f46\u662f\u6ca1\u6709\u88aback\u7684\u6d88\u606f\uff0e<\/li>\n<\/ul>\n<p>virtual hosts: \u672c\u8d28\u5c31\u662f\u4e00\u4e2arabbitmq server,\u62e5\u6709\u72ec\u7acb\u7684exchange,queue.\u9ed8\u8ba4\u662f\/(%2F).<\/p>\n<p>round-robin dispatch: \u5faa\u73af\u5206\u53d1\uff0c\u6309\u987a\u5e8f\u5206\u53d1message\u5230consumer,\u5982\u679cmessage\u88abconsumer\u6b63\u786e\u63a5\u6536\uff0c\u5c31\u4f1a\u4ecequeue\u4e2d\u79fb\u9664\uff0e<\/p>\n<p>no-ack: \u6bcf\u6b21consumer\u63a5\u6536\u6570\u636e\u540e\uff0c\u4e0d\u7ba1\u662f\u5426\u5904\u7406\u5b8c\u6210\uff0c\u5c31\u6807\u8bb0\u4e3aack,\u7136\u540e\u4ecequeue\u4e2d\u5220\u9664\uff0e\u4f46\u662f\u5982\u679c\u5904\u7406\u8fc7\u7a0b\u5f02\u5e38\uff0c\u6570\u636e\u5c31\u4f1a\u4e22\u5931\uff0e<\/p>\n<p>ack: ack\u65b9\u5f0f\u5c31\u662f\u6570\u636e\u5904\u7406\u5b8c\u6210\u540e\u53d1\u9001ack,\u4fdd\u8bc1\u6570\u636e\u88ab\u5904\u7406\u518d\u4ecequeue\u5220\u9664\uff0c\u5982\u679c\u5f02\u5e38\uff0c\u4f1adispatch\u5230\u522b\u7684consumer.<\/p>\n<p>durable: \u6d88\u606f\u6301\u4e45\u5316\uff0c\u5982\u679crabbitmq-server\u5f02\u5e38\u9000\u51fa\u6216\u670d\u52a1\u5668\u91cd\u542f\uff0c\u4e3a\u4e86\u4fdd\u8bc1\u6570\u636e\u8fd8\u5728\uff0c\u9700\u8981\u505a\u6570\u636e\u6301\u4e45\u5316.<\/p>\n<p>\u6d88\u606f\u7684\u72b6\u6001\u4fe1\u606f\uff1a<\/p>\n<ul>\n<li>deliver: \u6d88\u606f\u6295\u9012\u7ed9\u6d88\u8d39\u7740\uff0e\nredeliver:\u3000\u6d88\u606f\u91cd\u65b0\u6295\u9012\u7ed9\u6d88\u8d39\u8005\uff0e<\/li>\n<li>publish\/subscribe: \u5c06\u540c\u4e00\u4e2a\u6d88\u606fdeliver\u5230\u591a\u4e2aconsumer\u53ebpublish\u6216subscribe.<\/li>\n<li>ack: \u5df2\u7ecf\u5904\u7406\u5b8c\u6210\u7684\u6d88\u606f<\/li>\n<\/ul>\n<p>\u5b89\u88c5<\/p>\n<pre><code>$ sudo apt-get install rabbitmq-server\n<\/code><\/pre>\n<p>\u914d\u7f6e<\/p>\n<p>rabbitmq-3.7 \u5f00\u59cb\u914d\u7f6e\u6587\u4ef6\u683c\u5f0f\u4e3asysctl\uff0c\u540c\u65f6\u4e5f\u517c\u5bb9\u65e7\u7684erlang\u683c\u5f0f\u3002<\/p>\n<p>erlang\u683c\u5f0f\uff1a<\/p>\n<pre><code>[\n{rabbit,\n[\n{heartbeat, 8000}\n]\n}\n].\n<\/code><\/pre>\n<p>sysctl\u683c\u5f0f:<\/p>\n<pre><code>key = value\n<\/code><\/pre>\n<h2 id=\"rabbitmqctl-\u547d\u4ee4\">rabbitmqctl \u547d\u4ee4<\/h2>\n<pre><code>$ sudo rabbitmqctl [-n node] [-t timeout] [-q] &lt;commands&gt; [command options]\n<\/code><\/pre>\n<p>\u6dfb\u52a0\u7528\u6237\u5e76\u6388\u6743\uff1a<\/p>\n<pre><code># \u9ed8\u8ba4\u7684guest\/guest\u53ea\u80fd\u7528\u4e8elocalhost.\n$ add_user [username] [password]\n$ delete_user &lt;username&gt;\n$ change_password &lt;username&gt; &lt;newpassword&gt;\n$ clear_password &lt;username&gt;\n$ set_user_tags [username] administrator\n$ list_users\n<\/code><\/pre>\n<p>\u6743\u9650\u7ba1\u7406:<\/p>\n<pre><code>add_vhost &lt;vhostpath&gt;\ndelete_vhost &lt;vhostpath&gt;\nlist_vhosts [&lt;vhostinfoitem&gt; ...]\nset_permissions [-p &lt;vhostpath&gt;] &lt;user&gt; &lt;conf&gt; &lt;write&gt; &lt;read&gt;\nclear_permissions [-p &lt;vhostpath&gt;] &lt;username&gt;\nlist_permissions [-p &lt;vhostpath&gt;]\nlist_user_permissions &lt;username&gt;\nlist_queues [-p &lt;vhostpath&gt;] [&lt;queueinfoitem&gt; ...]\nlist_exchanges [-p &lt;vhostpath&gt;] [&lt;exchangeinfoitem&gt; ...]\nlist_bindings [-p &lt;vhostpath&gt;] [&lt;bindinginfoitem&gt; ...]\nlist_connections [&lt;connectioninfoitem&gt; ...]\nlist_channels [&lt;channelinfoitem&gt; ...]\nlist_consumers [-p &lt;vhostpath&gt;]\nstatus\nenvironment\nreport\neval &lt;expr&gt;\n<\/code><\/pre>\n<h2 id=\"rabbitmq-plugins-\u63d2\u4ef6\u7ba1\u7406\">rabbitmq-plugins \u63d2\u4ef6\u7ba1\u7406<\/h2>\n<p>\u542f\u52a8web-gui:<\/p>\n<pre><code>$ rabbitmq-plugins enable rabbitmq_management\n# http:\/\/localhost:15672 guest\/guest\n<\/code><\/pre>\n<hr>\n<h1 id=\"haproxy\">HAProxy<\/h1>\n<p>rabbitmq-cluster\u90e8\u7f72\uff1a<\/p>\n<ol>\n<li>\n<p>\u5728\u6240\u6709node\u4e0a\u5b89\u88c5rabbitmq-server.<\/p>\n<\/li>\n<li>\n<p>\u4fee\u6539\u6240\u6709node\u7684\/etc\/hosts\uff0c\u914d\u7f6eip\u548chostname.<\/p>\n<\/li>\n<li>\n<p>\u540c\u6b65\u6240\u6709node\u7684cookie(\/var\/lib\/rabbitmq\/.erlang.cookie).<\/p>\n<\/li>\n<li>\n<p>\u542f\u52a8\u6240\u6709node\u4e0a\u7684rabbitmq-server.<\/p>\n<pre><code> # rabbitmq-server -detached\n<\/code><\/pre>\n<\/li>\n<li>\n<p>\u5c06\u6240\u6709slave node\u6dfb\u52a0manager\u7ec4\u6210cluster.<\/p>\n<pre><code> # rabbitmqctl stop_app\n# rabbitmqctl reset\n# rabbitmqctl join_cluster rabbit@manager\n# rabbitmqctl start_app\n<\/code><\/pre>\n<\/li>\n<li>\n<p>\u68c0\u67e5cluster\u72b6\u6001<\/p>\n<pre><code> # rabbitmqctl cluster_status\n<\/code><\/pre>\n<\/li>\n<li>\n<p>\u8bbe\u7f6epolicy<\/p>\n<pre><code> # rabbitmqctl set_policy ha-all &quot;&quot; '{&quot;ha-mode&quot;:&quot;all&quot;,&quot;ha-sync-mode&quot;:&quot;automatic&quot;}'\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p>haproxy-server\u90e8\u7f72:<\/p>\n<ol>\n<li>\n<p>\u5728haproxy server\u5b89\u88c5haproxy<\/p>\n<\/li>\n<li>\n<p>\u914d\u7f6ehaproxy<\/p>\n<pre><code> # sudo vim \/etc\/haproxy\/haproxy.cfg\nglobal\n\u00a0\u00a0 log \/dev\/log\u00a0\u00a0\u00a0 local0\n\u00a0\u00a0\u00a0 log \/dev\/log\u00a0\u00a0\u00a0 local1 notice\n\u00a0\u00a0\u00a0 chroot \/var\/lib\/haproxy\n\u00a0\u00a0\u00a0 user haproxy\n\u00a0\u00a0\u00a0 group haproxy\n\u00a0\u00a0\u00a0 daemon\ndefaults\n\u00a0\u00a0\u00a0 log\u00a0\u00a0\u00a0\u00a0 global\n\u00a0\u00a0\u00a0 mode\u00a0\u00a0\u00a0 tcp\n\u00a0\u00a0\u00a0 maxconn 10000\n\u00a0\u00a0\u00a0 timeout connect 3000\n\u00a0\u00a0\u00a0 timeout client 1000s\n\u00a0\u00a0\u00a0 timeout server 1000s\nfrontend rabbitmq_front\n\u00a0\u00a0\u00a0 bind &lt;haproxy-ip&gt;:5672\n\u00a0\u00a0\u00a0 reqadd X-Forwarded-Proto:\\ amqp\n\u00a0\u00a0\u00a0 default_backend rabbitmq_backend\nbackend rabbitmq_backend\n\u00a0\u00a0\u00a0 balance roundrobin\n\u00a0\u00a0\u00a0 server rabbitmq-master &lt;master-ip&gt;:5672 check\n\u00a0\u00a0\u00a0 server rabbitmq-slave &lt;slave-ip&gt;:5672 check\nbind 0.0.0.0:15672\nserver &lt;master-hostname&gt; &lt;master-ip&gt;:15672 check\nserver &lt;slave-hostname&gt; &lt;slave-ip&gt;:15672 check\n<\/code><\/pre>\n<\/li>\n<li>\n<p>\u91cd\u542fhaproxy service.<\/p>\n<\/li>\n<\/ol>\n<hr>\n<h1 id=\"celery\">Celery<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/celery\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/celery<\/a><\/p>\n<p>\u53ef\u7528\u914d\u7f6e\uff0cdjango\u9700\u8981\u52a0namespace\u4f5c\u4e3a\u524d\u7f00\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/docs.celeryproject.org\/en\/stable\/userguide\/configuration.html#new-lowercase-settings\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.celeryproject.org\/en\/stable\/userguide\/configuration.html#new-lowercase-settings<\/a><\/p>\n<p>django\u4e2d\u7684celery\u914d\u7f6e<\/p>\n<pre><code>CELERY_BROKER_URL = &quot;amqp:\/\/user:pw@amqp:5672&quot;\nCELERY_ACCEPT_CONTENT = ['json']\nCELERY_RESULT_SERIALIZER = 'json'\nCELERY_EVENT_SERIALIZER = 'json'\nCELERY_TIMEZONE = 'UTC'\nCELERY_ENABLE_UTC = True\nCELERY_WORKER_PREFETCH_MULTIPLIER = 4\nCELERY_TASK_ACKS_LATE = False\nCELERY_TASK_SERIALIZER = 'json'\nCELERY_TASK_QUEUES = (\nQueue('queue1', Exchange('exchange1', type='direct'), routing_key='default', queue_arguments={'x-max-priority': 100}),\nQueue('queue2', Exchange('exchange2', type='direct'), routing_key='default', queue_arguments={'x-max-priority': 100}),\n)\nCELERY_TASK_DEFAULT_QUEUE = 'default'\nCELERY_TASK_DEFAULT_EXCHANGE = 'default'\nCELERY_TASK_DEFAULT_EXCHANGE_TYPE = 'direct'\nCELERY_TASK_DEFAULT_DELIVERY_MODE = 'persistent'\nCELERY_TASK_DEFAULT_ROUTING_KEY = 'default'\nCELERY_TASK_ROUTES = (\n{\n&quot;proj.app1.tasks.task1&quot;: {\n&quot;queue&quot;: &quot;queue1&quot;,\n&quot;routing_key&quot;: &quot;default&quot;\n}\n},\n{\n&quot;proj.app2.tasks.task2&quot;: {\n&quot;queue&quot;: &quot;queue2&quot;,\n&quot;routing_key&quot;: &quot;default&quot;\n}\n},\n)\n<\/code><\/pre>\n<p>\u5728project\u4e2d\u521b\u5efacelery\u7684app:<\/p>\n<pre><code>import os\nfrom celery import Celery\n# set the default Django settings module for the 'celery' program.\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'site_main.settings')\napp = Celery('proj')\n\/\/ namespace\u5c31\u4f1a\u53bbdjango\u7684\u914d\u7f6e\u627e\u524d\u7f00\u4e3acelery\u7684\u53c2\u6570.\napp.config_from_object('django.conf:settings', namespace='CELERY')\napp.autodiscover_tasks()\n<\/code><\/pre>\n<p>celery\u9009\u9879:<\/p>\n<pre><code>celery [options] command [args]\n-A, --app &lt;app&gt;\u00b6\n-b, --broker &lt;broker&gt;\n--result-backend &lt;result_backend&gt;\n--loader &lt;loader&gt;\n--config &lt;config&gt;\n--workdir &lt;workdir&gt;\n-C, --no-color\n-q, --quiet\n--version\n<\/code><\/pre>\n<p>worker\u9009\u9879:<\/p>\n<pre><code>-n, --hostname\n-D, --detach\n-l, --loglevel\n-O default|fair\n\/\/ \u9ed8\u8ba4\u7684concurrency\u662fcpu\u7684\u4e2a\u6570\uff0c\u5982\u679c\u662fcontainer\u8fd0\u884c\u5c31\u662fhost\u7684cpu\u4e2a\u6570\uff0c\u4e0d\u662fresourcelimit\u7684cpu\u4e2a\u6570.\n-c, --concurrency\n\/\/ cpu\u5bc6\u96c6\u578b\u4efb\u52a1\u6700\u597d\u7528prefork, IO\u5bc6\u96c6\u6700\u597d\u7528eventlet\/gevent.\n-P, --poo prefork(default)|eventlet|gevent|solo\n-E, --task-events, --events\n-Q, --queues\n-B, --beat\n<\/code><\/pre>\n<p>beat\u9009\u9879:<\/p>\n<pre><code>--detach\n-s, --schedule\n-S, --scheduler\n-l, --loglevel\n<\/code><\/pre>\n<p>inspect\u9009\u9879:<\/p>\n<pre><code>-t, --timeout\n-d, --destination\n-j, --json\n<\/code><\/pre>"},{"title":"Rpc","link":"https:\/\/canuxcheng.com\/post\/rpc\/","pubDate":"Sun, 03 Sep 2017 14:46:19 +0000","guid":"https:\/\/canuxcheng.com\/post\/rpc\/","description":"<h1 id=\"rpc\">RPC<\/h1>\n<p>Remote Procedure Call Protocol: \u8fdc\u7a0b\u8fc7\u7a0b\u8c03\u7528.<\/p>\n<p>google\u7684rpc\u6846\u67b6\uff0c\u652f\u6301\u591a\u8bed\u8a00:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/grpc\/grpc\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/grpc\/grpc<\/a><\/p>\n<p>facebook\u7684rpc\u6846\u67b6\uff0c\u8d21\u732e\u7ed9\u4e86apache, \u652f\u6301\u591a\u8bed\u8a00:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/apache\/thrift\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/apache\/thrift<\/a><\/p>"},{"title":"Germany","link":"https:\/\/canuxcheng.com\/post\/travel_germany\/","pubDate":"Mon, 08 May 2017 16:41:50 +0000","guid":"https:\/\/canuxcheng.com\/post\/travel_germany\/","description":"<h1 id=\"\u5fb7\u56fd\u4e4b\u65c5\">\u5fb7\u56fd\u4e4b\u65c5<\/h1>\n<p>\u770b\u7167\u7247\uff1a<\/p>\n<p><a class=\"link\" href=\"http:\/\/user.qzone.qq.com\/1085694641\/4\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/user.qzone.qq.com\/1085694641\/4<\/a><\/p>\n<p>\u5fb7\u56fd\u662f\u6c7d\u8f66\u4e4b\u90fd\u3002<\/p>\n<p>\u5fb7\u56fd\u670916\u4e2a\u5dde\u3002<\/p>\n<h1 id=\"\u57ce\u5e02\u5dde\">\u57ce\u5e02\u5dde<\/h1>\n<p>\u5fb7\u56fd16\u4e2a\u5dde\u4e2d\u7684\u4e09\u4e2a\u57ce\u5e02\u5dde<\/p>\n<h2 id=\"\u67cf\u6797\">\u67cf\u6797<\/h2>\n<p>\u5fb7\u56fd\u9996\u90fd\u3002<\/p>\n<p>\u5fb7\u56fd\u7b2c\u4e00\u5927\u57ce\u5e02\u3002<\/p>\n<h2 id=\"\u6c49\u5821\">\u6c49\u5821<\/h2>\n<p>\u5fb7\u56fd\u7b2c\u4e8c\u5927\u57ce\u5e02\u3002<\/p>\n<h2 id=\"\u4e0d\u6765\u6885\">\u4e0d\u6765\u6885<\/h2>\n<h1 id=\"\u5df4\u4f10\u5229\u4e9a\u5dde\u62dc\u4ec1\u6d32\">\u5df4\u4f10\u5229\u4e9a\u5dde(\u62dc\u4ec1\u6d32)<\/h1>\n<p>\u6155\u5c3c\u9ed1\u662f\u9996\u5e9c\u3002<\/p>\n<h2 id=\"\u6155\u5c3c\u9ed1\">\u6155\u5c3c\u9ed1<\/h2>\n<p>\u6155\u5c3c\u9ed1\u7684\u5965\u7279\u83b1\u65af\u4f4d\u4e8eIngolstadt Village\u3002<\/p>\n<p>\u5965\u8fea\u7684\u603b\u90e8\u4f4d\u4e8e\u6155\u5c3c\u9ed1\u7684Ingolstadt\u3002<\/p>\n<p>\u5b9d\u9a6c\u603b\u90e8\u4f4d\u4e8e\u6155\u5c3c\u9ed1\u3002<\/p>\n<p>\u5fb7\u56fd\u7b2c\u4e09\u5927\u57ce\u5e02\u3002<\/p>\n<h2 id=\"\u7ebd\u4f26\u5821\">\u7ebd\u4f26\u5821<\/h2>\n<h2 id=\"\u5965\u683c\u65af\u5821\">\u5965\u683c\u65af\u5821<\/h2>\n<h2 id=\"\u975e\u68ee\">\u975e\u68ee<\/h2>\n<p>\u5929\u9e45\u5821\u7684\u6240\u5728\u5730Fussen\u3002<\/p>\n<h1 id=\"\u5df4\u767b\u7b26\u817e\u5821\u5dde\">\u5df4\u767b\u7b26\u817e\u5821\u5dde<\/h1>\n<p>\u65af\u56fe\u52a0\u7279\u662f\u9996\u5e9c\u3002<\/p>\n<h2 id=\"\u65af\u56fe\u52a0\u7279\">\u65af\u56fe\u52a0\u7279<\/h2>\n<p>\u65af\u56fe\u52a0\u7279\u7684\u5965\u7279\u83b1\u65af\u4f4d\u4e8eMetzingen Village\u3002<\/p>\n<p>\u4fdd\u65f6\u6377\u7684\u603b\u90e8\u3002<\/p>\n<p>\u5954\u9a70\u7684\u603b\u90e8\u3002<\/p>\n<h1 id=\"\u9ed1\u68ee\u5dde\">\u9ed1\u68ee\u5dde<\/h1>\n<p>\u5a01\u65af\u5df4\u767b\u662f\u9996\u5e9c\u3002<\/p>\n<h2 id=\"\u5a01\u65af\u5df4\u767b\">\u5a01\u65af\u5df4\u767b<\/h2>\n<h2 id=\"\u6cd5\u5170\u514b\u798f\">\u6cd5\u5170\u514b\u798f<\/h2>\n<p>\u8be5\u5dde\u6700\u5927\u57ce\u5e02,\u6cd5\u56fd\u7b2c\u4e94\u5927\u57ce\u5e02\u3002<\/p>\n<p>\u6cd5\u5170\u514b\u798f\u7684\u5965\u7279\u83b1\u65af\u4f4d\u4e8eWertheim Village\u3002<\/p>\n<h1 id=\"\u5317\u83b1\u8335-\u5a01\u65af\u7279\u6cd5\u4f26\u5dde\">\u5317\u83b1\u8335-\u5a01\u65af\u7279\u6cd5\u4f26\u5dde<\/h1>\n<p>\u675c\u585e\u5c14\u591a\u592b\u662f\u9996\u5e9c\u3002<\/p>\n<h2 id=\"\u675c\u585e\u5c14\u591a\u592b\">\u675c\u585e\u5c14\u591a\u592b<\/h2>\n<h2 id=\"\u79d1\u9686\">\u79d1\u9686<\/h2>\n<p>\u8be5\u5dde\u6700\u5927\u57ce\u5e02\uff0c\u5fb7\u56fd\u7b2c\u56db\u5927\u57ce\u5e02\u3002<\/p>\n<h1 id=\"\u4e0b\u8428\u514b\u68ee\u5dde\">\u4e0b\u8428\u514b\u68ee\u5dde<\/h1>\n<p>\u6c49\u8bfa\u5a01\u662f\u9996\u5e9c\u3002<\/p>\n<h2 id=\"\u6c49\u8bfa\u5a01\">\u6c49\u8bfa\u5a01<\/h2>\n<h2 id=\"\u6c83\u5c14\u592b\u65af\u5821\">\u6c83\u5c14\u592b\u65af\u5821<\/h2>\n<p>\u5927\u4f17\u603b\u90e8\u3002<\/p>"},{"title":"Hadoop MapReduce","link":"https:\/\/canuxcheng.com\/post\/hadoop_mapreduce\/","pubDate":"Wed, 03 May 2017 22:57:37 +0000","guid":"https:\/\/canuxcheng.com\/post\/hadoop_mapreduce\/","description":"<h1 id=\"map-reduce\">Map-Reduce<\/h1>\n<p>\u4e00\u79cd\u57fa\u4e8eYARN\u7684\u5927\u578b\u6570\u636e\u5e76\u884c\u5904\u7406\u7cfb\u7edf\uff0e\u4e3b\u8981\u5904\u7406\u79bb\u7ebf\u6570\u636e\uff0e<\/p>\n<hr>\n<h1 id=\"mapreduce-commands\">mapreduce commands<\/h1>\n<pre><code>mapred [SHELL_OPTIONS] COMMAND [GENERIC_OPTIONS] [COMMAND_OPTIONS]\n<\/code><\/pre>\n<p>user commands:<\/p>\n<pre><code>$ mapred archive\n...\n<\/code><\/pre>\n<p>admin commands:<\/p>\n<pre><code>$ mapred historyserver\n$ mapred hsadmin\n<\/code><\/pre>\n<hr>"},{"title":"Redis","link":"https:\/\/canuxcheng.com\/post\/redis\/","pubDate":"Wed, 03 May 2017 14:46:14 +0000","guid":"https:\/\/canuxcheng.com\/post\/redis\/","description":"<h1 id=\"redis\">Redis<\/h1>\n<p><a class=\"link\" href=\"http:\/\/redisdoc.com\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/redisdoc.com\/<\/a><\/p>\n<p>redis\u5728key-value\u5b58\u50a8\u4e0a\u6027\u80fd\u6bd4memcached\u66f4\u597d\uff0e<\/p>\n<p>\u5b89\u88c5\uff1a<\/p>\n<pre><code># redis-cli, redis-sentinel, redis-server\n$ sudo apt-get install redis-server\n<\/code><\/pre>\n<p>\u53ea\u5b89\u88c5redis-cli:<\/p>\n<pre><code>$ sudo apt-get install redis-tools\n<\/code><\/pre>\n<p>redis-server\u76d1\u542c\u7aef\u53e36379.<\/p>\n<p>redis-sentinel\u7aef\u53e326379.<\/p>\n<p>redis gui:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/qishibo\/AnotherRedisDesktopManager\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/qishibo\/AnotherRedisDesktopManager<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/luin\/medis\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/luin\/medis<\/a><\/p>\n<p>redis HA:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/CodisLabs\/codis\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/CodisLabs\/codis<\/a><\/p>\n<hr>\n<h1 id=\"redis\u7684\u547d\u4ee4\">redis\u7684\u547d\u4ee4<\/h1>\n<p>server:<\/p>\n<pre><code>redis-server\n<\/code><\/pre>\n<p>client:<\/p>\n<pre><code>redis-client\n<\/code><\/pre>\n<p>test:<\/p>\n<pre><code>redis-benchmark\n<\/code><\/pre>\n<p>sentinel:<\/p>\n<pre><code>redis-sentinel\n<\/code><\/pre>\n<hr>\n<h1 id=\"cli\">CLI<\/h1>\n<p>redis-cli \u8fdb\u5165\u547d\u4ee4\u884c\u6a21\u5f0f<\/p>\n<pre><code>&gt; command # \u67e5\u770b\u6240\u6709\u53ef\u7528\u547d\u4ee4\n&gt; info # \u67e5\u770bredis\u670d\u52a1\u5668\u4fe1\u606f\n&gt; monitor\n&gt; select 1 # \u9009\u4e2d\u6570\u636e\u5e931\n&gt; keys * # \u663e\u793a\u6240\u6709key\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u6570\u636e\u7c7b\u578b\">\u6570\u636e\u7c7b\u578b<\/h1>\n<p>string<\/p>\n<pre><code>&gt; set &lt;key&gt; &lt;value&gt;\n&gt; get &lt;key&gt;\n<\/code><\/pre>\n<p>list<\/p>\n<pre><code>&gt; lset &lt;key&gt; &lt;index&gt; &lt;value&gt;\n&gt; lindex &lt;key&gt; &lt;index&gt;\n&gt; rpop\n&gt; lpop &lt;key&gt;\n&gt; rpush\n&gt; lpush\n<\/code><\/pre>\n<p>hash<\/p>\n<pre><code>&gt; hset &lt;key&gt; &lt;field&gt; &lt;value&gt;\n&gt; hget &lt;key&gt; &lt;field&gt;\n<\/code><\/pre>\n<p>set<\/p>\n<pre><code>&gt; sadd &lt;key&gt; &lt;member&gt;\n&gt; spop &lt;key&gt;\n&gt; srem &lt;key&gt; &lt;memeber&gt;\n<\/code><\/pre>\n<p>sorted set<\/p>\n<pre><code>&gt; zadd &lt;key&gt; &lt;score&gt; &lt;member&gt;\n&gt; zrem &lt;key&gt; &lt;member&gt;\n<\/code><\/pre>\n<hr>\n<h1 id=\"monitoring\">Monitoring<\/h1>\n<p>\u901a\u8fc7redis-cli&gt; info\u67e5\u770b<\/p>\n<pre><code>\u5176\u5b83\u6307\u6807\u53c2\u8003grafana dashboard.\nRedis_mode: cluster\/standalone\n&gt;&gt;&gt; replication (master\/slave)\nConnected_slaves:\u00a0\u00a0\u00a0 \u8fde\u63a5\u7684slave\u5b9e\u4f8b\u4e2a\u6570\n&gt;&gt;&gt; persistence\u00a0 \uff08rdb\u548caof\u7684\u6301\u4e45\u5316\u4fe1\u606f\uff09\n<\/code><\/pre>"},{"title":"Smtp","link":"https:\/\/canuxcheng.com\/post\/smtp\/","pubDate":"Wed, 26 Apr 2017 09:56:04 +0000","guid":"https:\/\/canuxcheng.com\/post\/smtp\/","description":"<h1 id=\"email\">Email<\/h1>\n<p>MTA: Mail Transfer Agent<\/p>\n<p>MUA: Mail User Agent<\/p>\n<p>python\u90ae\u4ef6\u670d\u52a1\u5668MTA\uff1asmtp\u534f\u8bae<\/p>\n<p>python\u5ba2\u6237\u7aefMUA\uff1a\u672c\u5730\u534f\u8baepop3, \u8fdc\u7a0b\u534f\u8baeimap<\/p>\n<h2 id=\"mailutils\">mailutils:<\/h2>\n<p>mailutils\u9ed8\u8ba4\u5b89\u88c5postfix,\u5982\u679c\u5df2\u7ecf\u5b89\u88c5\u5176\u5b83MTA\u5c31\u4f7f\u7528\u5df2\u7ecf\u5b89\u88c5\u7684\uff0e<\/p>\n<pre><code>$ sudo apt-get install mailutils\n<\/code><\/pre>\n<p>\u975e\u4ea4\u4e92\u5b89\u88c5mailutils:<\/p>\n<pre><code># \u8fd9\u91cc\u4e0d\u7528\u914d\u7f6e\u4efb\u4f55\u53c2\u6570\uff0e\n$ sudo debconf-set-selections &lt;&lt;&lt; &quot;postfix postfix\/mailname string &quot;\n$ sudo debconf-set-selections &lt;&lt;&lt; &quot;postfix postfix\/main_mailer_type string 'Internet Site'&quot;\n$ sudo apt-get install -y mailutils\n<\/code><\/pre>\n<p>\u6d4b\u8bd5\uff1a<\/p>\n<pre><code>$ echo &quot;test mail body&quot; | mail -s &quot;test mail title&quot; canuxcheng@gmail.com\n<\/code><\/pre>\n<hr>\n<h1 id=\"sendmail\">sendmail<\/h1>\n<p>\u5f00\u6e90\u7684smtp\u670d\u52a1\u5668\uff0e<\/p>\n<p>\u5b89\u88c5sendmail:<\/p>\n<pre><code>$ sudo apt-get install sendmail\n$ sudo apt-get install sendmail-cf\n<\/code><\/pre>\n<p>\u914d\u7f6e\uff1a<\/p>\n<pre><code>$ sudo vim \/etc\/hosts\n127.0.0.1 localhost.localdomain localhost hostname\n$ sudo vim \/etc\/mail\/sendmail.mc\nmodify 127.0.0.1 to 0.0.0.0, \u624d\u80fd\u53d1\u9001\u7ed9\u5176\u5b83\u673a\u5668\uff0c\u5426\u5219\u53ea\u80fd\u53d1\u7ed9\u672c\u673a\uff0e\nDAEMON_OPTIONS('..., Port=smtp, Addr=127.0.0.1')dnl\n# mv sendmail.cf sendmail.cf.old\n# m4 sendmail.mc &gt; sendmail.cf\n<\/code><\/pre>\n<hr>\n<h1 id=\"postfix\">postfix<\/h1>\n<p>\u6bd4sendmail\u66f4\u53cb\u597d\u7684smtp\u670d\u52a1\u5668\uff0e<\/p>\n<p>\u5b89\u88c5\uff1a<\/p>\n<pre><code>$ sudo apt-get install postfix\n# general type of mail configuration -&gt; Internet site\n# system mail name -&gt; \u7a7a\u7740\n<\/code><\/pre>\n<p>\u914d\u7f6e\uff1a<\/p>\n<pre><code># \u4f7f\u7528\u9ed8\u8ba4\u503c\u5373\u53ef.\n$ sudo vim \/etc\/postfix\/main.cf\ninet_interfaces = all\nmydestination = localhost, $hostname, localhost.localdomain, localhost\n<\/code><\/pre>\n<hr>\n<h1 id=\"python\u7684email\u6807\u51c6\u5e93\">Python\u7684email\u6807\u51c6\u5e93<\/h1>\n<p>\u670d\u52a1\u7aef\uff1a<\/p>\n<ol>\n<li>smtpd<\/li>\n<\/ol>\n<p>\u5ba2\u6237\u7aef\uff1a<\/p>\n<ol>\n<li>smtplib<\/li>\n<li>poplib<\/li>\n<li>imaplib<\/li>\n<\/ol>"},{"title":"HAWQ","link":"https:\/\/canuxcheng.com\/post\/hawq\/","pubDate":"Mon, 24 Apr 2017 22:57:37 +0000","guid":"https:\/\/canuxcheng.com\/post\/hawq\/","description":"<h1 id=\"hawq\">HAWQ<\/h1>\n<p><a class=\"link\" href=\"http:\/\/hawq.incubator.apache.org\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/hawq.incubator.apache.org\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/apache\/incubator-hawq\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/apache\/incubator-hawq<\/a><\/p>\n<p>HAWQ\u662f\u5728Pivotal Greenplum\u548cPostgreSQL\u57fa\u7840\u4e0a\u5f00\u53d1\u800c\u6765\uff0e<\/p>\n<p>HAWQ\u4e5f\u5c31\u662fPivotal HDB.<\/p>\n<p>HAWQ\u548cPivotal\u3000HDB\u662f\u4e00\u4e2a\u9879\u76ee\uff0e<\/p>\n<p>Hortonworks\u516c\u53f8\u7684HDP\u96c6\u6210\u4e86HAWQ.<\/p>\n<p>HAWQ\u53ef\u4ee5\u901a\u8fc7HDFS\u5728\u672c\u673a\u5feb\u901f\uff0c\u4ea4\u4e92\u67e5\u8be2hadoop\u6570\u636e\uff0e<\/p>\n<p>hawq\u7684\u4ea4\u4e92\u5f0f\u547d\u4ee4\u884c\u63a5\u53e3, \u7c7b\u4f3c\u4e8epostgresql, \u53c2\u8003postgresql.<\/p>\n<p>hawq\u7684client: psql (\u53c2\u8003postgresql)<\/p>\n<hr>\n<h1 id=\"psql\">psql<\/h1>\n<pre><code>$ psql\n$ PGPASSWORD='password';psql -h &lt;host&gt; -p &lt;port&gt; -U &lt;username&gt; -d [database] -c &quot;[psql command]&quot;\n$ psql -l # \u67e5\u770b\u6240\u6709database\n# jdbc\n$ jdbc:pivotal:greenplum:\/\/hdm1:5432;DatabaseName=getstartdb;User=hdbuser;Password=hdbpass\n<\/code><\/pre>\n<hr>\n<h1 id=\"sql\">sql<\/h1>\n<p>AO(append only) table:<\/p>\n<pre><code>&gt; create table {table_name} (var type, var1 type1);\n<\/code><\/pre>\n<p>parquet table:<\/p>\n<pre><code>&gt; create table {table_name} (var type, var1 type2) WITH (appendonly=true, orientation=parquet);\n<\/code><\/pre>\n<p>AO table distributed by specified column and partitioned by range:<\/p>\n<pre><code>&gt; create table {table_name} (var type, var1 type1) distributed by range(var) partition by range(var1) (start val end val1 every val2);\n<\/code><\/pre>\n<p>AO table distributed by randomly and partitioned by range:<\/p>\n<pre><code>&gt; create table {table_name} (var type, var1 type1) distributed randomly partition by range (var) (start(val) end (val1) every(val2));\n<\/code><\/pre>\n<p>parquet table distributed by specified column and partitoned by list:<\/p>\n<pre><code>&gt; create table {table_name} (var type, var1 type1) WITH (appendonly=true, orientation=parquet) distributed by (var) partition by list (var1) (partition name values (val), partition name1 values (val1));\n<\/code><\/pre>\n<p>parquet table distributed by randomly and partitioned by list:<\/p>\n<pre><code>&gt; create table {table_name} (var type, var1 type1) WITH (appendonly=true, orientation=parquet) distributed randomly partiton by list (var1) (partition name values (val), partition name1 values (val));\n<\/code><\/pre>"},{"title":"Hive","link":"https:\/\/canuxcheng.com\/post\/hive\/","pubDate":"Mon, 24 Apr 2017 22:57:37 +0000","guid":"https:\/\/canuxcheng.com\/post\/hive\/","description":"<h1 id=\"hive\">Hive<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/apache\/hive\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/apache\/hive<\/a><\/p>\n<p><a class=\"link\" href=\"http:\/\/hive.apache.org\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/hive.apache.org\/<\/a><\/p>\n<p>Hive2\u6570\u636e\u4ed3\u5e93\u7528\u4e8e\u8bfb\u53d6\uff0c\u5199\u5165\u548c\u7ba1\u7406\u4f7f\u7528SQL\u7684\u5927\u578b\u5206\u5e03\u5f0f\u6570\u636e\u96c6\uff0e<\/p>\n<p>hive2\u7684client: beeline(hive\u547d\u4ee4\u7684\u5347\u7ea7\u7248)<\/p>\n<hr>\n<h1 id=\"hivebeeline\">hive\/beeline<\/h1>\n<p>hive<\/p>\n<pre><code>$ hive --help\n<\/code><\/pre>\n<p>beeline<\/p>\n<pre><code>$ beeline --silent=true\nbeeline&gt; !connect jdbc:hive2:\/\/[ip]:[port]\/[database] [username] [password]\n$ beeline -u &quot;jdbc:hive2:\/\/[ip]:10000[\/database]&quot; -n [username] -p [password] -e &quot;USE [database]; ...&quot;\n<\/code><\/pre>\n<hr>\n<h1 id=\"sql\">sql<\/h1>\n<p>normal table:<\/p>\n<pre><code>&gt; create table tablename (var type, var1 type1);\n<\/code><\/pre>\n<p>parquet table:<\/p>\n<pre><code>&gt; create table {table_name} (var type, var1 type1) STORED AS PARQUET;\n<\/code><\/pre>\n<p>partition table:<\/p>\n<pre><code>&gt; create table {table_name} (var type, var1 type1) PARTITION BY (var2 type2);\n&gt; insert into {table_name} PARTITION (var2 = {pid}) VALUES {values};\n<\/code><\/pre>\n<p>parquet partition table:<\/p>\n<pre><code>&gt; create table {table_name} (var type, var1 type1) PARTITIONED BY (var2 type2) STORED AS PARQUET;\n&gt; insert into {table_name} PARTITION (var2 = {pid}) VALUES {values};\n<\/code><\/pre>"},{"title":"Impala","link":"https:\/\/canuxcheng.com\/post\/impala\/","pubDate":"Mon, 24 Apr 2017 22:57:37 +0000","guid":"https:\/\/canuxcheng.com\/post\/impala\/","description":"<h1 id=\"impala\">Impala<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/apache\/incubator-impala\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/apache\/incubator-impala<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/impala.apache.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/impala.apache.org\/<\/a><\/p>\n<p>impala\u7684client: impala-shell<\/p>\n<p>Cloudera\u516c\u53f8\u7684CDH\u96c6\u6210\u4e86Impala.<\/p>\n<hr>\n<h1 id=\"impala-shellbeeline\">impala-shell\/beeline<\/h1>\n<p>impala-shell<\/p>\n<pre><code>$ impala-shell\n<\/code><\/pre>\n<p>beeline<\/p>\n<pre><code>$ beeline --silent=true\nbeeline&gt; !connect jdbc:hive2:\/\/[ip]:21050[\/database];auth=noSasl [username] [password]\n$ beeline -u &quot;jdbc:hive2:\/\/[ip]:21050[\/database];auth=noSasl&quot; -n [username] -p [password] -e &quot;USE [database]; ...&quot;\n<\/code><\/pre>\n<hr>\n<h1 id=\"sql\">sql<\/h1>\n<p>normal table:<\/p>\n<pre><code>&gt; create table {table_name} (var type, var1 type1);\n<\/code><\/pre>\n<p>parquet table:<\/p>\n<pre><code>&gt; crate table {table_name} (var type, var1 type1) STORED AS PARQUET;\n<\/code><\/pre>\n<p>partition table:<\/p>\n<pre><code>&gt; create table {table_name} (var type, var1 type1) PARTITIONED BY (var2 type2);\n&gt; insert into {table_name} PARTITION (var2 = val2) values (val, val1)\n<\/code><\/pre>\n<p>parquet partition table:<\/p>\n<pre><code>&gt; create table {table_name} (var type, var1 type1) PARTITION BY (var2 type2) STORED AS PARQUET;\n&gt; insert into {table_name} PARTITION (var2 = val2) values (val, val1)\n<\/code><\/pre>"},{"title":"Presto","link":"https:\/\/canuxcheng.com\/post\/presto\/","pubDate":"Mon, 24 Apr 2017 22:57:37 +0000","guid":"https:\/\/canuxcheng.com\/post\/presto\/","description":"<h1 id=\"presto\">Presto<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/prestodb\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/prestodb<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/prestodb.io\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/prestodb.io\/<\/a><\/p>\n<p>presto\u7684client: presto-cli(rename to presto)<\/p>\n<hr>\n<h1 id=\"presto-cli\">presto-cli<\/h1>\n<pre><code>$ presto --server localhost:8080 --catalog hive --schema default\n# jdbc for presto\n$ jdbc:presto:\/\/host:port\/catalog\/schema\n<\/code><\/pre>"},{"title":"MongoDB","link":"https:\/\/canuxcheng.com\/post\/mongodb\/","pubDate":"Sun, 16 Apr 2017 14:46:14 +0000","guid":"https:\/\/canuxcheng.com\/post\/mongodb\/","description":"<h1 id=\"mongodb\">MongoDB<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/mongodb\/mongo\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/mongodb\/mongo<\/a><\/p>\n<p>mongodb\u662f\u4e00\u79cd\u5f00\u6e90\u7684\u6587\u6863\u6570\u636e\u5e93\uff0c\u9ad8\u6027\u80fd\uff0c\u9ad8\u53ef\u7528\u6027\uff0c\u81ea\u52a8\u88c1\u526a\uff0e<\/p>\n<p>mongodb\u7684database\u548c\u5173\u7cfb\u6570\u636e\u5e93\u4e2d\u7684database\u4e00\u6837\uff0e<\/p>\n<p>mongodb\u5c06BSON(mongo\u7684JSON)\u6587\u6863\u5b58\u50a8\u5728\u96c6\u5408(collections)\u4e2d\uff0c\u96c6\u5408\u76f8\u5f53\u4e8e\u5173\u7cfb\u6570\u636e\u5e93\u4e2d\u7684\u8868table\uff0e<\/p>\n<p>mongodb\u7684collections\u4e2d\u7684\u57df(field)\uff0c\u76f8\u5f53\u4e8e\u5173\u7cfb\u6570\u636e\u5e93\u4e2d\u7684\u5b57\u6bb5column.<\/p>\n<p>mongodb\u7684collections\u4e2d\u7684\u6587\u6863(document)\uff0c\u76f8\u5f53\u4e8e\u5173\u7cfb\u6570\u636e\u5e93\u4e2d\u7684\u8bb0\u5f55\u884crow.<\/p>\n<p>mongodb\u4e5f\u652f\u6301index\u7d22\u5f15\u548cprimary key\u4e3b\u952e\uff0c\u4f46\u662f\u4e0d\u652f\u6301table joins\u8868\u8fde\u63a5\uff0e<\/p>\n<p>ubuntu\u5b89\u88c5:<\/p>\n<pre><code>$ sudo apt-key adv --keyserver hkp:\/\/keyserver.ubuntu.com:80 --recv0C49F3730359A14518585931BC711F9BA15703C6\n$ echo &quot;deb http:\/\/repo.mongodb.org\/apt\/ubuntu trusty\/mongodb-org\/3.4multiverse&quot; | sudo tee \/etc\/apt\/sources.list.d\/mongodb-org-3.4.list\n$ sudo apt-get update\n$ sudo apt-get install -y mongodb-org\n<\/code><\/pre>\n<p>ubuntu\u542f\u52a8:<\/p>\n<pre><code>$ sudo service mongod start\n<\/code><\/pre>\n<p>\u5b89\u88c5\u5b8c\u6210\u9ed8\u8ba4\u7684\u6570\u636e\u5e93\u662ftest.\u53e6\u5916db, admin, local\u662f\u4fdd\u7559\u7684\u6570\u636e\u5e93\u540d\u79f0\uff0e<\/p>\n<p>mongod\u7684\u9ed8\u8ba4\u7aef\u53e3\u662f27017.<\/p>\n<p>mongo web-gui:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/Studio3T\/robomongo\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/Studio3T\/robomongo<\/a><\/p>\n<hr>\n<h1 id=\"mongo\u7684\u547d\u4ee4\">mongo\u7684\u547d\u4ee4<\/h1>\n<pre><code>mongo [options] [db address] [file names (ending in .js)]\n<\/code><\/pre>\n<p>mongo shell\u8fdb\u5165\u5230\u6307\u5b9a\u6570\u636e\u5e93:<\/p>\n<pre><code>$ mongo [db_name]\n<\/code><\/pre>\n<p>\u672c\u5730\u547d\u4ee4\u884c\u6267\u884csql\u8bed\u53e5\uff1a<\/p>\n<pre><code>$ mongo [database] -e\/--eval [javascript]\n<\/code><\/pre>\n<p>\u8fdc\u7a0b\u6267\u884csql\u8bed\u53e5:<\/p>\n<pre><code>$ mongo -u [username] -p [password] [ip]:[port]\/[datbase] -e\/--eval [javascript]\n<\/code><\/pre>\n<hr>\n<h1 id=\"cli\">CLI<\/h1>\n<p>\u5148\u7528mongo\u547d\u4ee4\u8fdb\u5165mongo\u547d\u4ee4\u884c<\/p>\n<pre><code>help # \u67e5\u770b\u6240\u6709\u547d\u4ee4\nexit # \u9000\u51famongo shell\ndb # \u663e\u793a\u5f53\u524d\u6570\u636e\u5e93\nuse &lt;db_name&gt; # \u5207\u6362\u5230\u6307\u5b9a\u6570\u636e\u5e93, \u4e0d\u5b58\u5728\u5219\u521b\u5efa\uff0e\nshow dbs # \u67e5\u770b\u6240\u6709\u6570\u636e\u5e93\nshow collections # \u67e5\u770b\u5f53\u524ddatabase\u7684collections\nshow users\nshow profile\nshow logs\nshow log [name]\nsh.help()\nrs.help()\ndb.help() # \u67e5\u770b\u6240\u6709database\u7684\u65b9\u6cd5\ndb.hostInfo()\ndb.serverStatus()\ndb.mycoll.help() # \u67e5\u770b\u6240\u6709collections\u7684\u65b9\u6cd5\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u6570\u636e\u7c7b\u578b\">\u6570\u636e\u7c7b\u578b<\/h1>\n<hr>\n<h1 id=\"curd\">CURD<\/h1>\n<p>mongo\u7684CURD\u64cd\u4f5c\u5c31\u76f8\u5f53\u4e8e\u5173\u7cfb\u6570\u636e\u5e93\u4e2d\u7684sql\u64cd\u4f5c\uff0e<\/p>\n<p>CURD: create update read delete.<\/p>\n<pre><code>&gt; use &lt;database_name&gt; # \u5207\u6362\/\u521b\u5efa\u6570\u636e\u5e93\n&gt; db.createCollection(collection_name) # \u5728\u5f53\u524d\u6570\u636e\u5e93\u521b\u5efa\u96c6\u5408\n&gt; db.dropDatabase() # \u5220\u9664\u5f53\u524d\u6570\u636e\u5e93\n&gt; db.getCollectionNames() # \u83b7\u53d6\u5f53\u524d\u6570\u636e\u5e93\u7684\u6240\u6709\u96c6\u5408\n&gt; db.mycoll.insert(obj) #\u3000\u5f80\u96c6\u5408mycollection\u4e2d\u63d2\u5165JSON\u5bf9\u8c61obj.\n&gt; db.mycoll.find([query],[fields]) # \u67e5\u8be2\u6587\u6863\n&gt; db.mycoll.remove(query) # \u5220\u9664\u6587\u6863\n&gt; db.mycoll.save(obj) # \u66ff\u6362\u5df2\u6709\u7684\u6587\u6863\n&gt; db.mycoll.update( query, object[, upsert_bool, multi_bool] ) # \u66f4\u65b0\u5df2\u6709\u7684\u6587\u6863\n&gt; db.mycoll.drop() # \u5220\u9664\u5f53\u524d\u96c6\u5408\n# \u91ca\u653e\u5185\u5b58\n&gt; use admin\n&gt; db.runCommand({closeAllDatabases:1})\n<\/code><\/pre>\n<hr>\n<h1 id=\"monitoring\">Monitoring<\/h1>\n<p>\u901a\u8fc7mongo&gt; serverStatus()\u67e5\u770b<\/p>\n<p>\u5176\u5b83\u6307\u6807\u53c2\u8003grafana dashboard.<\/p>"},{"title":"Xml","link":"https:\/\/canuxcheng.com\/post\/xml\/","pubDate":"Fri, 07 Apr 2017 16:43:15 +0000","guid":"https:\/\/canuxcheng.com\/post\/xml\/","description":"<h1 id=\"xml\">XML<\/h1>\n<hr>"},{"title":"Xpath","link":"https:\/\/canuxcheng.com\/post\/xpath\/","pubDate":"Fri, 07 Apr 2017 16:43:15 +0000","guid":"https:\/\/canuxcheng.com\/post\/xpath\/","description":"<h1 id=\"xpath\">XPath<\/h1>\n<p>XPath\u662f\u4e00\u95e8\u5728XML\u6587\u6863\u4e2d\u67e5\u627e\u4fe1\u606f\u7684\u8bed\u8a00\uff0e<\/p>\n<p>xpath\u5b9a\u4f4d\u6709\u7edd\u5bf9\u5b9a\u4f4d\u548c\u76f8\u5bf9\u5b9a\u4f4d\uff0c\u63a8\u8350\u4f7f\u7528\u76f8\u5bf9\u5b9a\u4f4d\uff0e<\/p>\n<p>\u7edd\u5bf9\u7684XPath\u5b9a\u4f4d\u5305\u542b\u4e86\u4eceHTML\u6839\u8282\u70b9\u8d77\u7684\u6240\u6709\u5143\u7d20\uff0c\u5e76\u4e14\u4e00\u4e9b\u8f7b\u5fae\u7684\u6539\u53d8\u5c31\u4f1a\u5931\u6548\u3002<\/p>\n<p>\u76f8\u5bf9\u7684XPath\u7528id\u6216\u8005name\u5c5e\u6027\u6765\u627e\u5230\u4e00\u4e2a\u9760\u8fd1\u7684\u5143\u7d20(\u6bd4\u8f83\u7406\u60f3\u7684\u662f\u7236\u5143\u7d20)\uff0c\u8fd9\u6837\u4f60\u5c31\u53ef\u4ee5\u4f9d\u9760\u4ed6\u4eec\u7684\u76f8\u5bf9\u5173\u7cfb\u6765\u786e\u5b9a\u76ee\u6807\u5143\u7d20\u7684\u4f4d\u7f6e\u3002<\/p>\n<h1 id=\"firefox\">firefox<\/h1>\n<p>firebug + firepath<\/p>\n<p>firefox\u901a\u8fc7\u4e24\u8005\u7ed3\u5408\u6765\u83b7\u53d6xpath<\/p>\n<h1 id=\"chrome\">chrome<\/h1>\n<p>chrome\u7684\u5f00\u53d1\u8005\u5de5\u5177(F12)\u53ef\u4ee5\u76f4\u63a5copy xpath.<\/p>"},{"title":"Kvm","link":"https:\/\/canuxcheng.com\/post\/kvm\/","pubDate":"Wed, 05 Apr 2017 21:47:54 +0000","guid":"https:\/\/canuxcheng.com\/post\/kvm\/","description":"<h1 id=\"kvm\">KVM<\/h1>\n<p>Kernel-based Virtual Machine.<\/p>\n<hr>\n<h1 id=\"qemu\">Qemu<\/h1>\n<p>\u5b89\u88c5:<\/p>\n<pre><code>$ sudo apt-get install qemu-system qemu-kvm\n<\/code><\/pre>\n<hr>"},{"title":"Libvirt","link":"https:\/\/canuxcheng.com\/post\/libvirt\/","pubDate":"Wed, 05 Apr 2017 21:47:54 +0000","guid":"https:\/\/canuxcheng.com\/post\/libvirt\/","description":"<h1 id=\"libvirt\">Libvirt<\/h1>\n<p>\u652f\u6301\u591a\u79cd\u865a\u62df\u5316\u5e73\u53f0\u7684\u5e93<\/p>\n<p><a class=\"link\" href=\"https:\/\/libvirt.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/libvirt.org\/<\/a><\/p>\n<p>\u5b89\u88c5:<\/p>\n<pre><code>$ sudo apt-get install libvirt-bin (\u5305\u542bvirsh\u547d\u4ee4\u548clibvirtd daemon)\n\/\/ libvirtd\u5728container\u4e2d\u65e0\u6cd5\u8fd0\u884c\uff1b\u5728container\u4e2d\u5b89\u88c5libvirt-bin\u53ef\u4ee5\u83b7\u53d6virsh\u547d\u4ee4\u8fdc\u7a0b\u8bbf\u95eelibvirt-bin server.\n<\/code><\/pre>\n<p>libvirt-bin\u62c6\u5206\u6210\u4e86\u4e24\u4e2a\u5305\uff1a<\/p>\n<pre><code>libvirt-daemon-system\nlibvirt-clients\n$ sudo apt-get install libvirt-dev # \u5e93, python\/go client\u4f9d\u8d56\u8be5\u5e93\n$ sudo apt-get install virt-manager # windows\u7ba1\u7406\u5de5\u5177\n$ sudo apt-get install virt-view # ...\n$ sudo service libvirt-bin restart\n<\/code><\/pre>\n<h1 id=\"virsh\">virsh<\/h1>\n<p>libvirt\u7684\u547d\u4ee4\u884c\u5de5\u5177<\/p>\n<pre><code>$ virsh list --all # \u67e5\u770b\u6240\u6709\u865a\u62df\u673a\n$ virsh list --all --name # \u53ea\u770bdomain name.\n$ virsh define \/path\/to\/X.xml # \u4ecexml\u914d\u7f6e\u6587\u4ef6\u5b9a\u4e49\u4e00\u4e2adomain\n$ virsh start # \u542f\u52a8\u865a\u62df\u673a\n$ virsh reboot # \u91cd\u542f\u865a\u62df\u673a\n$ virsh shutdown # \u5173\u95ed\u865a\u62df\u673a\n$ virsh destroy # \u5f3a\u5236\u5173\u95ed\u865a\u62df\u673a\n$ virsh undefine # \u79fb\u9664\u865a\u62df\u673a\n$ virsh vncdisplay # \u67e5\u770b\u865a\u62df\u673a\u7684vnc\u4fe1\u606f\uff0c\u53ef\u4ee5\u901a\u8fc7vnc\u8bbf\u95ee.\n$ virsh net-list --all # \u67e5\u770b\u6240\u6709\u7f51\u7edc\n$ virsh net-define default.xml\n$ virsh net-autostart default\n$ virsh net-start default\n$ virsh net-undefine default\n$ virsh net-destroy default\n# \u6279\u91cf\u64cd\u4f5cvm\n$ for vm in `virsh list --all --name`; do virsh undefine\/destroy ${vm}; done\n<\/code><\/pre>\n<h1 id=\"qemu-img\">qemu-img<\/h1>\n<p>\u521b\u5efa\u865a\u62df\u673a\u7684\u955c\u50cf\u6587\u4ef6:<\/p>\n<pre><code>$ qemu-img create -f qcow2 \/path\/to\/name.qcow2 100G\n<\/code><\/pre>\n<hr>\n<h1 id=\"libvirt-qemu\">libvirt-qemu<\/h1>\n<p>libvirt\u64cd\u4f5cqemu\/kvm.<\/p>\n<p>\u672c\u5730:<\/p>\n<pre><code>qemu:\/\/\/system\nqemu:\/\/\/session\nqemu+unix:\/\/\/system\nqemu+unix:\/\/\/session\n<\/code><\/pre>\n<p>ssh\u8fdc\u7a0b:<\/p>\n<pre><code># libvirt-bin server\u4e0a\u9700\u8981\u5b89\u88c5nc\u548clibvirt-bin\n$ sudo apt-get install netcat-openbsd\n$ sudo update-alternatives --config nc \/\/ netcat-traditional\u907f\u514d\u4f7f\u7528\u9ed8\u8ba4\u5b89\u88c5\n# ssh\u7528\u6237\u9700\u8981\u5728libvirt\u548ckvm\u7ec4\u91cc\n$ adduser username libvirtd\n$ adduser username kvm\n$ sudo apt-get install sshpass \/\/ \u514d\u5bc6\u7801\u8bbf\u95ee\n# client\u4e0a\u9700\u8981\u5b89\u88c5openssh-clients\n$ sshpass -p password virsh -c qemu+ssh:\/\/user@127.0.0.1\/system list\n<\/code><\/pre>\n<p>tcp\u8fdc\u7a0b:<\/p>\n<pre><code>$ vim \/etc\/libvirt\/libvirtd.conf:\nlisten_tls = 0\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000 #\u7981\u7528tls\u767b\u5f55\nlisten_tcp = 1\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u00a0#\u542f\u7528tcp\u65b9\u5f0f\u767b\u5f55\ntcp_port = &quot;16509&quot;\u3000\u3000\u3000\u3000\u3000\u3000\u3000 #tcp\u7aef\u53e316509\nlisten_addr = &quot;0.0.0.0&quot; # \u5141\u8bb8\u4efb\u610fip\u8bbf\u95ee\nauth_tcp = &quot;none&quot;\u3000\u3000\u3000\u3000\u3000\u3000 \u00a0 #TCP\u4e0d\u4f7f\u7528\u8ba4\u8bc1\n$ vim \/etc\/default\/libvirt-bin\nstart_libvirtd=&quot;yes&quot;\nlibvirtd_opts=&quot;-l --config \/etc\/libvirt\/libvirtd.conf&quot;\n$ sudo service libvirt-bin restart\n$ virsh -c qemu+tcp:\/\/127.0.0.1:16509\/system list\n<\/code><\/pre>\n<h1 id=\"libvirtd\u914d\u7f6e\">libvirtd\u914d\u7f6e<\/h1>\n<p>\u914d\u7f6elibvirtd\uff1a<\/p>\n<pre><code>$ vim \/etc\/libvirt\/libvirtd.conf\nmax_clients = 1024\u3000\u3000\u3000\u3000\u3000\u3000 \u00a0 #\u6700\u5927\u603b\u7684\u8fde\u63a5\u5ba2\u6237\u65701024\nmin_workers = 50\u3000\u3000\u3000\u3000\u3000\u3000 \u00a0 \u00a0#libvirtd\u542f\u52a8\u65f6\uff0c\u521d\u59cb\u7684\u5de5\u4f5c\u7ebf\u7a0b\u6570\u76ee\nmax_workers = 200\u3000\u3000\u3000\u3000\u3000\u3000 #\u540c\u4e0a\uff0c\u6700\u5927\u6570\u76ee\nmax_requests = 1000\u3000\u3000\u3000\u3000\u3000\n#\u6700\u5927\u540c\u65f6\u652f\u6301\u7684RPC\u8c03\u7528\uff0c\u5fc5\u987b\u5927\u4e8e\u7b49\u4e8emax_workers\nmax_client_requests = 200\u3000\u3000 #\u6bcf\u4e2a\u5ba2\u6237\u7aef\u652f\u6301\u7684\u6700\u5927\u8fde\u63a5\u6570\n<\/code><\/pre>"},{"title":"IDE","link":"https:\/\/canuxcheng.com\/post\/devops_ide\/","pubDate":"Sun, 02 Apr 2017 21:11:26 +0000","guid":"https:\/\/canuxcheng.com\/post\/devops_ide\/","description":"<h1 id=\"jetbrains\">JetBrains<\/h1>\n<p>IntelliJ: Java\u7684IDE, \u5b89\u88c5Python\u7684\u63d2\u4ef6\u4e5f\u652f\u6301python.<\/p>\n<h2 id=\"pycharm\">PyCharm<\/h2>\n<p>PyCharm: Python\u7684IDE.<\/p>\n<h2 id=\"goland\">Goland<\/h2>\n<p>Goland: golang\u7684IDE.<\/p>\n<hr>\n<h1 id=\"vscode\">VSCode<\/h1>\n<h2 id=\"intellisense--code-navigation\">IntelliSense &amp; Code Navigation<\/h2>\n<p>Go to Definition: F12, \u8df3\u8f6c\u5230\u5b9a\u4e49.<\/p>\n<p>Peek Definition: Alt + F12\uff0c \u901f\u89c8\u5b9a\u4e49\uff0c\u4e0d\u8df3\u8f6c.<\/p>\n<p>Go to references: Shift + F12, \u8f6c\u5230\u5f15\u7528.<\/p>\n<h2 id=\"frontend\">frontend<\/h2>\n<h3 id=\"vs-js-debug\">vs-js-debug<\/h3>\n<p>vscode\u5185\u7f6e\u4e86js\/ts\/node\u7684debugger.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/microsoft\/vscode-js-debug\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/microsoft\/vscode-js-debug<\/a><\/p>\n<h3 id=\"live-server\">live server<\/h3>\n<p>live preview(html, svg&hellip;)<\/p>\n<p>\u5982\u679c\u7528remote-ssh\u5f00\u542flive server\u5c31\u662f\u5728\u8fdc\u7a0b\u673a\u5668\u4e0a\u5f00\u542f5500\u7aef\u53e3\uff0cwebroot\u5c31\u662fvscode\u6253\u5f00\u7684\u76ee\u5f55.<\/p>\n<p>\u5982\u679c\u662fremote-ssh\u5f00\u53d1html\uff0c\u7528\u8fd9\u4e2apreview\u5f88\u65b9\u4fbf.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/ritwickdey\/vscode-live-server\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/ritwickdey\/vscode-live-server<\/a><\/p>\n<h3 id=\"vscode-chrome-debug\">vscode-chrome-debug<\/h3>\n<p>\u6253\u5f00\u7684\u662f\u5b89\u88c5vscode\u7684\u673a\u5668\u4e0a\u7684chrome\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/microsoft\/vscode-chrome-debug\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/microsoft\/vscode-chrome-debug<\/a><\/p>\n<p>\u901a\u8fc7live server\u76d1\u542cremote-ssh\u673a\u5668\u4e0a\u76845500\uff0c\u53ef\u4ee5\u901a\u8fc7chrome\u8fdc\u7a0b\u8c03\u8bd5\u9759\u6001\u7ad9\u70b9\u3002<\/p>\n<pre><code>{\n&quot;version&quot;: &quot;0.2.0&quot;,\n&quot;configurations&quot;: [\n{\n&quot;name&quot;: &quot;angularjs&quot;,\n&quot;type&quot;: &quot;chrome&quot;,\n&quot;request&quot;: &quot;launch&quot;,\n&quot;url&quot;: &quot;http:\/\/remote-ssh-server:5500\/path\/to\/index.html&quot;,\n&quot;webRoot&quot;: &quot;${workspaceFolder}\/path\/to\/&quot;,\n},\n]\n}\n<\/code><\/pre>\n<hr>\n<h2 id=\"python\">python<\/h2>\n<p>debuging:<\/p>\n<p><a class=\"link\" href=\"https:\/\/code.visualstudio.com\/docs\/python\/debugging\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/code.visualstudio.com\/docs\/python\/debugging<\/a><\/p>\n<p>debug current file:<\/p>\n<pre><code>{\n&quot;name&quot;: &quot;current file&quot;,\n&quot;type&quot;: &quot;python&quot;,\n&quot;request&quot;: &quot;launch&quot;,\n&quot;program&quot;: &quot;${file}&quot;,\n&quot;console&quot;: &quot;integratedTerminal&quot;,\n}\n<\/code><\/pre>\n<p>debug with module:<\/p>\n<pre><code>{\n&quot;name&quot;: &quot;module&quot;,\n&quot;type&quot;: &quot;python&quot;,\n&quot;request&quot;: &quot;launch&quot;,\n&quot;module&quot;: &quot;module-name&quot;,\n&quot;console&quot;: &quot;integratedTerminal&quot;,\n}\n<\/code><\/pre>\n<p>debug with attach:<\/p>\n<pre><code>\/\/ create ssh tunnel\nssh -2 -L sourceport:localhost:5678 -i identifyfile user@remoteaddress\n{\n&quot;name&quot;: &quot;Python: Attach&quot;,\n&quot;type&quot;: &quot;python&quot;,\n&quot;request&quot;: &quot;attach&quot;,\n&quot;port&quot;: 5678,\n&quot;host&quot;: &quot;localhost&quot;,\n&quot;pathMappings&quot;: [\n{\n&quot;localRoot&quot;: &quot;${workspaceFolder}&quot;,\n&quot;remoteRoot&quot;: &quot;.&quot;,\n}\n]\n}\n<\/code><\/pre>\n<p>testing:<\/p>\n<p><a class=\"link\" href=\"https:\/\/code.visualstudio.com\/docs\/python\/testing\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/code.visualstudio.com\/docs\/python\/testing<\/a><\/p>\n<p>unittest:<\/p>\n<pre><code>{\n&quot;python.testing.autoTestDiscoverOnSaveEnabled&quot;: true,\n&quot;python.testing.unittestArgs&quot;: [\n&quot;-v&quot;,\n&quot;-s&quot;,\n&quot;.\/tests&quot;,\n&quot;-p&quot;,\n&quot;test_*.py&quot;\n],\n&quot;python.testing.pytestEnabled&quot;: false,\n&quot;python.testing.nosetestsEnabled&quot;: false,\n&quot;python.testing.unittestEnabled&quot;: true,\n&quot;restructuredtext.confPath&quot;: &quot;${workspaceFolder}\/docs&quot;,\n}\n<\/code><\/pre>\n<h2 id=\"django\">django<\/h2>\n<p><a class=\"link\" href=\"https:\/\/code.visualstudio.com\/docs\/python\/tutorial-django\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/code.visualstudio.com\/docs\/python\/tutorial-django<\/a><\/p>\n<p>debugging:<\/p>\n<pre><code>{\n\/\/ \u4f7f\u7528 IntelliSense \u4e86\u89e3\u76f8\u5173\u5c5e\u6027\u3002\n\/\/ \u60ac\u505c\u4ee5\u67e5\u770b\u73b0\u6709\u5c5e\u6027\u7684\u63cf\u8ff0\u3002\n\/\/ \u6b32\u4e86\u89e3\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u8bbf\u95ee: https:\/\/go.microsoft.com\/fwlink\/?linkid=830387\n&quot;version&quot;: &quot;0.2.0&quot;,\n&quot;configurations&quot;: [\n{\n&quot;name&quot;: &quot;Python: Django&quot;,\n&quot;type&quot;: &quot;python&quot;,\n&quot;request&quot;: &quot;launch&quot;,\n&quot;program&quot;: &quot;${workspaceFolder}\/path\/to\/manage.py&quot;,\n&quot;console&quot;: &quot;integratedTerminal&quot;,\n&quot;args&quot;: [\n&quot;runserver&quot;,\n&quot;0:8888&quot;\n],\n&quot;django&quot;: true,\n&quot;env&quot;: {\n}\n}\n]\n}\n<\/code><\/pre>\n<h2 id=\"golang\">golang<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/golang\/vscode-go\/blob\/master\/docs\/debugging.md\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/golang\/vscode-go\/blob\/master\/docs\/debugging.md<\/a><\/p>\n<p>debugging:<\/p>\n<pre><code>{\n&quot;version&quot;: &quot;0.2.0&quot;,\n&quot;configurations&quot;: [\n{\n&quot;name&quot;: &quot;golang file&quot;,\n&quot;type&quot;: &quot;go&quot;,\n&quot;request&quot;: &quot;launch&quot;,\n&quot;mode&quot;: &quot;auto&quot;,\n&quot;program&quot;: &quot;${file}&quot;\n},\n{\n&quot;name&quot;: &quot;gin debug&quot;,\n&quot;type&quot;: &quot;go&quot;,\n&quot;request&quot;: &quot;launch&quot;,\n&quot;mode&quot;: &quot;auto&quot;,\n&quot;program&quot;: &quot;${workspaceFolder}\/backend\/main.go&quot;\n},\n]\n}\n<\/code><\/pre>\n<h2 id=\"rest-client\">rest client<\/h2>\n<p>\u8c03\u8bd5rest API<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/Huachao\/vscode-restclient\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/Huachao\/vscode-restclient<\/a><\/p>\n<p>example.api:<\/p>\n<pre><code>@api = http:\/\/hostname:port\/api\/v0\n@Authorization = Basic a2FpemVuOkFybUFkbWluMSE=\n@Content-Type = application\/json\n###\nGET {{api}}\/users HTTP\/1.1\nAuthorization: {{Authorization}}\nContent-Type: {{Content-Type}}\n###\nPOST {{api}}\/groupus HTTP\/1.1\nAuthorization: {{Authorization}}\nContent-Type: {{Content-Type}}\n{\nkey: value\n}\n<\/code><\/pre>\n<h2 id=\"record\">record<\/h2>\n<p>vscode\u5f55\u5236.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/microsoft\/codetour\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/microsoft\/codetour<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/arciisine\/vscode-chronicler\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/arciisine\/vscode-chronicler<\/a><\/p>\n<p>\u652f\u6301\u8fdc\u7a0bdebug\u7684\u65f6\u5019\u5728\u672c\u5730\u5f55\u5236\uff0c\u4e5f\u5c31\u662f\u672c\u5730\u662fwindows\uff0c\u53ea\u9700\u8981\u672c\u5730\u5b89\u88c5ffmpeg\u548cchroicler\u3002<\/p>\n<h2 id=\"mcp\">MCP<\/h2>\n<p>&ldquo;&hellip;\/Code\/User\/settings.json&rdquo;<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/GLips\/Figma-Context-MCP\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/GLips\/Figma-Context-MCP<\/a>\n<a class=\"link\" href=\"https:\/\/github.com\/modelcontextprotocol\/servers\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/modelcontextprotocol\/servers<\/a><\/p>\n<pre><code>{\n&quot;servers&quot;: {\n&quot;postgres&quot;: {\n&quot;command&quot;: &quot;npx&quot;,\n&quot;args&quot;: [\n&quot;-y&quot;,\n&quot;@modelcontextprotocol\/server-postgres&quot;,\n&quot;postgresql:\/\/server?ssl=true&amp;sslmode=require&amp;rejectUnauthorized=false&quot;\n]\n},\n&quot;redis&quot;: {\n&quot;command&quot;: &quot;npx&quot;,\n&quot;args&quot;: [\n&quot;-y&quot;,\n&quot;@modelcontextprotocol\/server-redis&quot;,\n&quot;redis:\/\/localhost:6379&quot;\n]\n},\n&quot;playwright&quot;: {\n&quot;command&quot;: &quot;npx&quot;,\n&quot;args&quot;: [\n&quot;@playwright\/mcp@latest&quot;\n]\n},\n&quot;Azure MCP Server&quot;: {\n&quot;command&quot;: &quot;npx&quot;,\n&quot;args&quot;: [\n&quot;-y&quot;,\n&quot;@azure\/mcp@latest&quot;,\n&quot;server&quot;,\n&quot;start&quot;\n]\n},\n&quot;memory&quot;: {\n&quot;command&quot;: &quot;npx&quot;,\n&quot;args&quot;: [\n&quot;-y&quot;,\n&quot;@modelcontextprotocol\/server-memory&quot;\n]\n},\n&quot;sequential-thinking&quot;: {\n&quot;command&quot;: &quot;npx&quot;,\n&quot;args&quot;: [\n&quot;-y&quot;,\n&quot;@modelcontextprotocol\/server-sequential-thinking&quot;\n]\n},\n&quot;git&quot;: {\n&quot;command&quot;: &quot;docker&quot;,\n&quot;args&quot;: [\n&quot;run&quot;,\n&quot;--rm&quot;,\n&quot;-i&quot;,\n&quot;--mount&quot;,\n&quot;type=bind,src=${workspaceFolder},dst=\/workspace&quot;,\n&quot;mcp\/git&quot;\n]\n},\n&quot;filesystem&quot;: {\n&quot;command&quot;: &quot;npx&quot;,\n&quot;args&quot;: [\n&quot;-y&quot;,\n&quot;@modelcontextprotocol\/server-filesystem&quot;,\n&quot;${workspaceFolder}&quot;\n]\n},\n&quot;fetch&quot;: {\n&quot;command&quot;: &quot;docker&quot;,\n&quot;args&quot;: [\n&quot;run&quot;,\n&quot;-i&quot;,\n&quot;--rm&quot;,\n&quot;mcp\/fetch&quot;\n]\n},\n&quot;kubernetes&quot;: {\n&quot;command&quot;: &quot;npx&quot;,\n&quot;args&quot;: [\n&quot;-y&quot;,\n&quot;mcp-server-kubernetes&quot;\n]\n}\n}\n}\n<\/code><\/pre>"},{"title":"Cryptographic","link":"https:\/\/canuxcheng.com\/post\/sec_cryptographic\/","pubDate":"Mon, 27 Mar 2017 17:11:58 +0000","guid":"https:\/\/canuxcheng.com\/post\/sec_cryptographic\/","description":"<h1 id=\"pgp\">PGP<\/h1>\n<p>PGP: Pretty Good Privacy\u3002<\/p>\n<p>\u7528\u4e8e\u7b7e\u540d\u548c\u52a0\u5bc6\u89e3\u5bc6\u3002<\/p>\n<h2 id=\"pgp-1\">PGP<\/h2>\n<p><a class=\"link\" href=\"https:\/\/en.wikipedia.org\/wiki\/Pretty_Good_Privacy\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/en.wikipedia.org\/wiki\/Pretty_Good_Privacy<\/a><\/p>\n<h2 id=\"openpgp\">OpenPGP<\/h2>\n<p>OpenPGP\u662fPGP\u7684\u6807\u51c6,\u4e5f\u6709\u5f88\u591a\u5b9e\u73b0\u3002<\/p>\n<p><a class=\"link\" href=\"http:\/\/openpgp.org\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/openpgp.org\/<\/a><\/p>\n<h2 id=\"gnupg\">GnuPG<\/h2>\n<p>GunPG: Gun Privacy Guard, \u662f\u57fa\u4e8eopenPGP\u7684\u5b9e\u73b0\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/gnupg.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/gnupg.org\/<\/a><\/p>\n<pre><code>$ gpg --help\n$ \u5feb\u901f\u751f\u6210\u7b7e\u540d\u5bc6\u94a5\u5bf9\ngpg --quick-generate-key &quot;Canux&quot;\n\/\/ \u67e5\u770b\u516c\u94a5\ngpg --list-keys\n\/\/ \u67e5\u770b\u79c1\u94a5\ngpg --list-secret-keys\n\/\/ \u5220\u9664\u79c1\u94a5\ngpg --delete-secret-keys &quot;Canux&quot;\n\/\/ \u5220\u9664\u516c\u94a5\ngpg --delete-keys &quot;Canux&quot;\n<\/code><\/pre>\n<p>GPGME: GPG Made Easy, \u662f\u4e00\u4e2a\u8ba9\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528GPG\u66f4\u5bb9\u6613\u7684\u5e93\uff0e<\/p>\n<h1 id=\"openssl\">OpenSSL<\/h1>\n<p>\u7f51\u7edc\u5b89\u5168\u548c\u5bc6\u7801\u5de5\u5177\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.openssl.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.openssl.org\/<\/a><\/p>\n<pre><code>$ openssl --help\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u5355\u5411\u54c8\u5e0c\u52a0\u5bc6\">\u5355\u5411\u54c8\u5e0c\u52a0\u5bc6<\/h1>\n<p>md5\u548cshaX\u90fd\u662f\u5e38\u7528\u7684\u5b58\u50a8\u5bc6\u7801\u7684\u52a0\u5bc6\u65b9\u6cd5.<\/p>\n<p>rainbow table\u53ef\u4ee5\u7834\u89e3\u5355\u5411\u52a0\u5bc6.<\/p>\n<p>salt\u65b9\u6cd5\u53ef\u4ee5\u9632\u6b62rainbow table\u7834\u89e3.<\/p>\n<p>scrypt\u662f\u6700\u96be\u7834\u89e3\u7684\u52a0\u5bc6\u65b9\u6848.<\/p>\n<h2 id=\"md5\">md5<\/h2>\n<h2 id=\"sha1\">sha1<\/h2>\n<h2 id=\"sha256\">sha256<\/h2>\n<h2 id=\"sha512\">sha512<\/h2>\n<h2 id=\"hmac\">hmac<\/h2>\n<hr>\n<h1 id=\"symmetric-cryptography\">Symmetric Cryptography<\/h1>\n<p>\u5bf9\u79f0\u52a0\u5bc6\u5c31\u662f\u52a0\u5bc6\u548c\u89e3\u5bc6\u4f7f\u7528\u7684\u5bc6\u94a5\u662f\u76f8\u540c\u7684\uff0e<\/p>\n<h2 id=\"base32\">base32<\/h2>\n<h2 id=\"base64\">base64<\/h2>\n<h2 id=\"des\">des<\/h2>\n<h2 id=\"aes\">aes<\/h2>\n<h2 id=\"rc4\">rc4<\/h2>\n<hr>\n<h1 id=\"asymmetric-cryptography\">Asymmetric Cryptography<\/h1>\n<p>\u975e\u5bf9\u79f0\u52a0\u5bc6\u5c31\u662f\u5b58\u5728\u4e24\u4e2a\u5bc6\u94a5.<\/p>\n<h2 id=\"rsa\">rsa<\/h2>\n<h2 id=\"dsa\">dsa<\/h2>\n<h2 id=\"ecdsa\">ecdsa<\/h2>\n<h2 id=\"ecc\">ecc<\/h2>\n<p>elliptic curves cryptography<\/p>"},{"title":"JS DOM","link":"https:\/\/canuxcheng.com\/post\/js_dom\/","pubDate":"Wed, 15 Mar 2017 09:36:32 +0000","guid":"https:\/\/canuxcheng.com\/post\/js_dom\/","description":"<h1 id=\"dom\">DOM<\/h1>\n<p>DOM: document object model.<\/p>\n<p>\u5f53\u7f51\u9875\u88ab\u52a0\u8f7d\u65f6\uff0c\u6d4f\u89c8\u5668\u4f1a\u521b\u5efa\u9875\u9762\u7684\u6587\u6863\u5bf9\u8c61\u6a21\u578b(DOM).<\/p>\n<p>DOM\u64cd\u4f5c\u9700\u8981\u5728html\u52a0\u8f7d\u5b8c\u6210\u540e\u8fdb\u7a0b.<\/p>\n<p>js\u53ef\u4ee5\u901a\u8fc7DOM\u8bbf\u95eehtml\u6587\u6863\u7684\u6240\u6709\u5143\u7d20.<\/p>\n<ul>\n<li>JavaScript \u80fd\u591f\u6539\u53d8\u9875\u9762\u4e2d\u7684\u6240\u6709 HTML \u5143\u7d20<\/li>\n<li>JavaScript \u80fd\u591f\u6539\u53d8\u9875\u9762\u4e2d\u7684\u6240\u6709 HTML \u5c5e\u6027<\/li>\n<li>JavaScript \u80fd\u591f\u6539\u53d8\u9875\u9762\u4e2d\u7684\u6240\u6709 CSS \u6837\u5f0f<\/li>\n<li>JavaScript \u80fd\u591f\u5bf9\u9875\u9762\u4e2d\u7684\u6240\u6709\u4e8b\u4ef6\u505a\u51fa\u53cd\u5e94<\/li>\n<\/ul>\n<h2 id=\"\u67e5\u627ehtml\u5143\u7d20\">\u67e5\u627ehtml\u5143\u7d20<\/h2>\n<p>\u627e\u5230\u8fd4\u56de\u8be5\u5143\u7d20\u7684\u5bf9\u8c61\uff0c\u6ca1\u627e\u5230\u8fd4\u56denull.<\/p>\n<p>\u901a\u8fc7id:<\/p>\n<pre><code>document.getElementById(&quot;id&quot;);\n<\/code><\/pre>\n<p>\u901a\u8fc7\u6807\u7b7e\u540d:<\/p>\n<pre><code>document.getElementsByTagName(&quot;tag&quot;);\n<\/code><\/pre>\n<p>\u901a\u8fc7\u7c7b\u540d:<\/p>\n<pre><code>document.getElementsByName(&quot;name&quot;)\n<\/code><\/pre>\n<h2 id=\"\u64cd\u4f5chtml\u5143\u7d20\u6216\u6587\u672c\">\u64cd\u4f5chtml\u5143\u7d20\u6216\u6587\u672c<\/h2>\n<p>\u64cd\u4f5c\u6807\u7b7e\u6216\u6807\u7b7e\u5185\u7684\u6587\u672c.<\/p>\n<p>\u76f4\u63a5\u6539\u53d8html\u5185\u5bb9:<\/p>\n<pre><code># \u7edd\u4e0d\u8981\u4f7f\u7528\u5728\u6587\u6863\u52a0\u8f7d\u4e4b\u540e\u4f7f\u7528 document.write()\u3002\u8fd9\u4f1a\u8986\u76d6\u8be5\u6587\u6863\ndocument.write(...);\n<\/code><\/pre>\n<p>\u6539\u53d8\u5143\u7d20\u7684\u5185\u5bb9:<\/p>\n<pre><code>document.getElementById(id).innerHTML = &quot;new text&quot;;\n<\/code><\/pre>\n<h2 id=\"\u64cd\u4f5chtml\u5c5e\u6027\">\u64cd\u4f5chtml\u5c5e\u6027<\/h2>\n<p>\u6539\u53d8\u5143\u7d20\u5c5e\u6027:<\/p>\n<pre><code>document.getElementById(id).attribute = &quot;new value&quot;;\n<\/code><\/pre>\n<h2 id=\"\u64cd\u4f5ccss\">\u64cd\u4f5ccss<\/h2>\n<pre><code>document.getElementById(id).style.property = &quot;new style&quot;\n<\/code><\/pre>\n<h2 id=\"\u589e\u5220html\u5143\u7d20\">\u589e\u5220html\u5143\u7d20<\/h2>\n<p>\u589e\u52a0\u5143\u7d20:<\/p>\n<pre><code>var para = document.createElement(&quot;p&quot;);\nvar node = document.createTextNode(&quot;new para&quot;);\npara.appendChild(node);\n<\/code><\/pre>\n<p>\u5220\u9664\u5143\u7d20:<\/p>\n<pre><code>var parent = document.getElementById(&quot;id&quot;);\nvar child = document.getElementById(&quot;cid&quot;);\nparent.removeChild(child);\n<\/code><\/pre>\n<h2 id=\"\u5bf9\u4e8b\u4ef6\u505a\u51fa\u53cd\u5e94\">\u5bf9\u4e8b\u4ef6\u505a\u51fa\u53cd\u5e94<\/h2>\n<pre><code>function changetext(id) {\nid.innerHTML = &quot;new text&quot;\n}\n&lt;h1 onclick=&quot;changetext(this)&quot;&gt;&lt;\/h1&gt;\ndocument.getElementById(id).onclick=function(){...};\n<\/code><\/pre>\n<hr>\n<h1 id=\"document\">Document<\/h1>\n<p>\u96c6\u5408:<\/p>\n<pre><code>all[]\nanchors[]\napplets\nforms[]\nimages[]\nlinks[]\n<\/code><\/pre>\n<p>attribution:<\/p>\n<pre><code>body\ncookie\ndomain\nlastModified\nreferrer\ntitle\nURL\nreadyState \/\/ loading\/interfactive\/complete\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>open()\nclose()\ngetElementById() # \u8fd4\u56deid\u5bf9\u5e94\u7684\u7b2c\u4e00\u4e2a\u5bf9\u8c61\ngetElementsByName() # \u8fd4\u56de\u5bf9\u5e94\u7684\u6240\u6709\u5bf9\u8c61\u7684\u96c6\u5408\ngetElementsByTagName() # \u540c\u4e0a\nwrite()\nwriteln()\ncreateElement()\ncreateTextNode()\n<\/code><\/pre>\n<hr>\n<h1 id=\"element\">Element<\/h1>\n<p>element\u8868\u793ahtml\u5143\u7d20,\u62e5\u6709\u5143\u7d20\uff0c\u6587\u672c\u548c\u6ce8\u91ca\u7684\u5b50\u8282\u70b9.<\/p>\n<p>attribution:<\/p>\n<pre><code>tagName \/\/ tag\u540d\u5b57\ninnerHTML \/\/ \u5143\u7d20\u91cc\u9762\u7684\u6587\u672c\u5185\u5bb9\nid\ntitle\nstyle\nclassName\nlength\nnodeName \/\/ \u548ctagName\u76f8\u540c\nnodeType \/\/ \u8282\u70b9\u7c7b\u578b: 1= \u5143\u7d20\u8282\u70b9\uff0c2= \u5c5e\u6027\u8282\u70b9, 3= \u6587\u672c\u8282\u70b9, 8= \u6ce8\u91ca\nnodeValue \/\/ \u6587\u672c\u8282\u70b9\u7684\u503c\nparentNode \/\/ \u7236\u8282\u70b9\nchildNodes \/\/ \u5b50\u8282\u70b9\nfirstChild\nlastChild\nnextSibling\npreviousSibling\nownerDocument \/\/ \u8fd4\u56de\u5f53\u524d\u6839\u8282\u70b9\u6587\u6863\u5bf9\u8c61\naccesKey\nattributes\ncontentEditable\ndir\nlang\nnamespaceURI\ntabIndex\ntextContent\nclientHeight\nclientWidth\noffsetHeight\noffsetWidth\noffsetLeft\noffsetParent\noffsetTop\nscrollHeight\nscrollLeft\nscrollTop\nscrollWidth\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>appendChild(node) \/\/ \u5728\u5143\u7d20\u540e\u8ffd\u52a0node\nInsertBefore() \/\/ \u5728\u5143\u7d20\u524d\u63d2\u5165node\nremoveChild()\nreplaceChild()\ncloneNode()\ncompareDocumentPosition()\ngetAttribute()\ngetAttributeNode()\ngetElementsByTagName()\ngetFeature()\ngetUserData()\nhasAttribute()\nhasAttributes()\nhasChildNodes()\nisDefaultNamespace()\nisEqualNode()\nisSameNode()\nisSupported()\nnormalize()\nremoveAttribute()\nremoveAttributeNode()\nsetArrbitute()\nsetArrtibuteNode()\nsetIdAttribute()\nsetIdArrtibuteNode()\nsetUserData()\ntoString()\nitem() #\n<\/code><\/pre>\n<hr>\n<h1 id=\"attribute\">Attribute<\/h1>\n<p>Attribute\u8868\u793ahtml\u5c5e\u6027<\/p>\n<p>attribution:<\/p>\n<pre><code>isId\nname\nvalue\nspecified\nlength\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>gtNamedItem()\nitem()\nremoveNameItem()\nsetNamedItem()\n<\/code><\/pre>\n<hr>\n<h1 id=\"event\">Event<\/h1>\n<p>window\u4e8b\u4ef6:<\/p>\n<pre><code># \u7b49\u5f85html\u52a0\u8f7d\u5b8c\u6210\nonload\nwindow.onload = function(){};\nonunload\n<\/code><\/pre>\n<p>\u9f20\u6807\u4e8b\u4ef6:<\/p>\n<pre><code>onclick\nondblclick\nonmousedown\nonmousemove\nonmouseout\nonmouseover\nonmouseup\n<\/code><\/pre>\n<p>\u952e\u76d8\u4e8b\u4ef6:<\/p>\n<pre><code>onkeypress\nonkeydown\nonkeyup\n<\/code><\/pre>\n<p>\u8868\u5355\u4e8b\u4ef6:<\/p>\n<pre><code>onsubmit\n<\/code><\/pre>\n<p>\u5a92\u4f53\u4e8b\u4ef6:<\/p>\n<pre><code>onabort\nonerror\n<\/code><\/pre>\n<hr>"},{"title":"JS OOP","link":"https:\/\/canuxcheng.com\/post\/js_oop\/","pubDate":"Wed, 15 Mar 2017 09:36:32 +0000","guid":"https:\/\/canuxcheng.com\/post\/js_oop\/","description":"<h1 id=\"oop\">OOP<\/h1>\n<p>javascript\u4e2d\u4e00\u5207\u90fd\u662f\u5bf9\u8c61.<\/p>\n<p>javacript\u5185\u7f6e\u4e86Bull\/Number\/String\/Object\/Function\/Array\/Date\/RegExp\u7c7b\u578b.<\/p>\n<h1 id=\"object\">Object<\/h1>\n<p>\u521b\u5efaObject\u5b9e\u4f8b:<\/p>\n<pre><code>var obj = new Object();\nvar obj = Object(); \/\/ new \u53ef\u4ee5\u7701\u7565\nvar obj = \uff5b\nname: &quot;value&quot;\n};\nvar obj = {\n&quot;name&quot;: &quot;value&quot;\n}\n<\/code><\/pre>\n<p>\u6dfb\u52a0\u5c5e\u6027:<\/p>\n<pre><code>obj.attr = &quot;value&quot;\n<\/code><\/pre>\n<p>\u6dfb\u52a0\u65b9\u6cd5:<\/p>\n<pre><code>obj.method = methodName;\nfunction methodName() {};\nobj.method = function() {};\n<\/code><\/pre>\n<p>\u5220\u9664\u5c5e\u6027:<\/p>\n<pre><code>delete obj.attr\n<\/code><\/pre>\n<p>\u8bbf\u95ee\u5bf9\u8c61\u5c5e\u6027:<\/p>\n<pre><code>obj.property\n<\/code><\/pre>\n<p>\u8bbf\u95ee\u5bf9\u8c61\u65b9\u6cd5:<\/p>\n<pre><code>obj.method()\n<\/code><\/pre>\n<h1 id=\"boolean\">Boolean<\/h1>\n<p>attribution:<\/p>\n<pre><code>constructor\nprototype\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>toSource()\nvalueOf()\ntoString()\n<\/code><\/pre>\n<h1 id=\"number\">Number<\/h1>\n<p>attribution:<\/p>\n<pre><code>constructor\nprototype\nMAX_VALUE\nMIN_VALUE\nNaN\nNEGATIVE_INFINITY\nPOSITIVE_INFINITY\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>valueOf()\ntoString()\ntoLocaleString()\ntoFixed()\ntoExponential()\ntoPrecision()\n<\/code><\/pre>\n<h1 id=\"string\">String<\/h1>\n<p>attribution:<\/p>\n<pre><code>constructor\nprototype\nlength\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>toSource()\ntoString()\nvalueOf()\nanchor()\nbig()\nindexOf()\nreplace()\nmatch()\nsearch()\ntoLowerCase()\ntoUpperCase()\n...\n<\/code><\/pre>\n<h1 id=\"function\">Function<\/h1>\n<p>attribution:<\/p>\n<pre><code>Infinity\njava\nNaN\nPackages\nundefined\n<\/code><\/pre>\n<p>method\uff1a<\/p>\n<pre><code>decodeURI()\ndecodeURIComponent()\nencodeURI()\nencodeURIComponent()\nescape()\neval()\ngetClass()\nisFinite()\nisNaN()\nparseFloat()\nparseInt()\nString()\nunescape()\n<\/code><\/pre>\n<h1 id=\"array\">Array<\/h1>\n<p>\u521b\u5efa\u5bf9\u8c61:<\/p>\n<p>new\u90fd\u53ef\u4ee5\u7701\u7565.<\/p>\n<pre><code>var arr = new Array();\nvar arr = new Array(size);\nvar arr = new Array(element0, element1, ...);\nvar arr = [];\nvar arr = [1,2, &quot;test&quot;];\n<\/code><\/pre>\n<p>\u8d4b\u503c:<\/p>\n<pre><code>arr[index] = &quot;value&quot;;\n\/\/ \u5b57\u7b26\u4e32\u4e0b\u6807\uff0c\u4e0d\u80fd\u76f4\u63a5\u901a\u8fc7\u6570\u7ec4\u5bf9\u8c61\u8bbf\u95ee\uff0c\u53ea\u80fd\u901a\u8fc7\u5bf9\u8c61\u65b9\u6cd5\u8bbf\u95ee.\narr[&quot;key&quot;] = &quot;value&quot;;\n<\/code><\/pre>\n<p>attribution:<\/p>\n<pre><code>constructor\nprototype\nlength \/\/ set\u6216get\u6570\u7ec4\u4e2d\u5143\u7d20\u4e2a\u6570.\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>toSource()\ntoString()\nvalueOf()\ntoLocaleString()\njoin(separator) \/\/ \u8fd4\u56de\u6309\u7167\u5206\u9694\u7b26\u5206\u9694\u7684\u5b57\u7b26\u4e32\nconcat() \/\/ \u62fc\u63a5\npush() \/\/ \u5f80\u6570\u7ec4\u672b\u5c3e\u6dfb\u52a0\u5143\u7d20,\u8fd4\u56de\u6700\u65b0\u957f\u5ea6.\npop() \/\/ \u79fb\u9664\u6570\u7ec4\u672b\u5c3e\u5143\u7d20,\u5e76\u8fd4\u56de\nunshift() \/\/ \u5728\u6570\u7ec4\u5f00\u5934\u6dfb\u52a0\u5143\u7d20\uff0c\u8fd4\u56de\u6700\u65b0\u957f\u5ea6.\nshift() \/\/\u3000\u79fb\u9664\u6570\u7ec4\u5f00\u5934\u5143\u7d20\u5e76\u8fd4\u56de\nreverse() \/\/ \u5bf9\u6570\u7ec4\u9006\u5e8f\u6392\u5e8f\u64cd\u4f5c\uff0e\nsort(sortby) \/\/ \u5bf9\u6570\u7ec4\u987a\u5e8f\u6392\u5e8f\u64cd\u4f5c\nslice(start, end) \/\/ \u53d6\u4e0b\u6807\u4e3astart\u548cend\u4e4b\u95f4\u7684\u5143\u7d20\uff0c\u4e0d\u5305\u62ecstart\u548cend.\nsplice(index, howmany, item1, ...) \/\/ \u5220\u9664\uff0c\u63d2\u5165\uff0c\u66ff\u6362\u529f\u80fd.\nsplice(index, howmany) \/\/ \u4eceindex\u5f00\u59cb\uff0c\u83b7\u53d6howmany\u4e2a\u5143\u7d20\nsplice(index, 0, item) \/\/ \u4eceindex\u63d2\u5165item\nsplice(index, 1, item) \/\/ \u7528item\u66ff\u6362index\u7684\u5143\u7d20\n<\/code><\/pre>\n<h1 id=\"date\">Date<\/h1>\n<p>\u521b\u5efa\u5bf9\u8c61:<\/p>\n<pre><code>var date = new Date();\n<\/code><\/pre>\n<p>attribution:<\/p>\n<pre><code>constructor\nprototype\n<\/code><\/pre>\n<p>method:<\/p>\n<pre><code>toString()\ntoSource()\nvalueOf()\nDate()\nUTC()\nparse(datestring) \/\/ \u8fd4\u56dedatestring\u7684epoch\u6beb\u79d2\u6570\ntoLocalString()\ntoLocalTimeString()\ntoLocalDateString(0)\ntoUTCString()\ntoGMTString()\ntoDateString()\ntoTimeString()\nget...\nset...\n<\/code><\/pre>\n<h1 id=\"regexp\">RegExp<\/h1>\n<h1 id=\"math\">Math<\/h1>\n<h1 id=\"events\">Events<\/h1>"},{"title":"Angular","link":"https:\/\/canuxcheng.com\/post\/js_angular\/","pubDate":"Mon, 13 Mar 2017 09:36:32 +0000","guid":"https:\/\/canuxcheng.com\/post\/js_angular\/","description":"<h1 id=\"angularjs\">angularjs<\/h1>\n<p>angularjs 1.*<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/angular\/angular.js\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/angular\/angular.js<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/angularjs.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/angularjs.org\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/rev087\/ng-inspector\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/rev087\/ng-inspector<\/a><\/p>\n<hr>\n<h1 id=\"angular\">Angular<\/h1>\n<p>Angular \u662f\u4e00\u4e2a\u7528 HTML \u548c TypeScript \u6784\u5efa\u5ba2\u6237\u7aef\u5e94\u7528\u7684\u5e73\u53f0\u4e0e\u6846\u67b6\u3002<\/p>\n<p>angular.js \u7684\u5347\u7ea7\u7248<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/angular\/angular\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/angular\/angular<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/angular\/angular-cli\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/angular\/angular-cli<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/angular.io\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/angular.io<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/angular.cn\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/angular.cn<\/a><\/p>\n<p>\u5b89\u88c5 angular-cli:<\/p>\n<pre><code>$ npm install -g @angular\/cli\n<\/code><\/pre>\n<p>\u67e5\u770b\u7248\u672c:<\/p>\n<pre><code>$ ng v\n<\/code><\/pre>\n<p>\u65b0\u5efa\u9879\u76ee:<\/p>\n<pre><code>$ cd &lt;project&gt;\n$ ng new &lt;application&gt;\n# \u4e25\u683c\u6a21\u5f0f\n$ ng new &lt;application&gt; --strict\n$ ng generate &lt;schematic&gt; [options]\nappShell\napplication\nclass\ncomponent\ndirective\nenum\nguard\ninterceptor\ninterface\nlibrary\nmodule\npipe\nresolver\nservice\nserviceWorker\nwebWorker\n<\/code><\/pre>\n<p>\u6d4b\u8bd5\u9879\u76ee:<\/p>\n<pre><code>$ cd &lt;my-app&gt;\n$ ng serve\n\/\/ --open\u4f1a\u81ea\u52a8\u6253\u5f00\u6d4f\u89c8\u5668\n$ ng serve --open\n<\/code><\/pre>\n<p>\u6253\u5305:<\/p>\n<pre><code>$ ng build --prod\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u9879\u76ee\u7ed3\u6784\">\u9879\u76ee\u7ed3\u6784<\/h1>\n<p>\u5de5\u4f5c\u533a\u914d\u7f6e\uff1a<\/p>\n<ul>\n<li>.editorconfig: \u4ee3\u7801\u7f16\u8f91\u5668\u914d\u7f6e<\/li>\n<li>angular.json: \u4e3a\u5de5\u4f5c\u533a\u6240\u6709\u9879\u76ee\u6307\u5b9aCLI\u7684\u9ed8\u8ba4\u914d\u7f6e\uff0c\u5305\u62ecCLI\u8981\u7528\u5230\u7684\u6784\u5efa\uff0c\u542f\u52a8\u5f00\u53d1\u670d\u52a1\u5668\u548c\u6d4b\u8bd5\u5de5\u5177\u7684\u914d\u7f6e\u9879\u3002<\/li>\n<li>tsconfig.json: \u5de5\u4f5c\u7a7a\u95f4\u6240\u6709\u9879\u76ee\u7684\u57fa\u672ctypescript\u914d\u7f6e\u3002<\/li>\n<li>tslint.json: \u5de5\u4f5c\u7a7a\u95f4\u4e2d\u6240\u6709\u9879\u76ee\u7684\u9ed8\u8ba4\u7684TSlint\u914d\u7f6e\u3002<\/li>\n<li>src\/: \u6839\u9879\u76ee\u7684\u6e90\u6587\u4ef6\u3002<\/li>\n<li>e2e\/: \u7aef\u5230\u7aef\u6d4b\u8bd5\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<p>\u5e94\u7528\u914d\u7f6e:<\/p>\n<ul>\n<li>.browserslistrc \u914d\u7f6e\u524d\u7aef\u5de5\u5177\u4e4b\u95f4\u5171\u4eab\u7684\u76ee\u6807\u6d4f\u89c8\u5668\u548cnode.js\u7248\u672c<\/li>\n<li>karma.conf.js \u5e94\u7528\u7684karma\u914d\u7f6e<\/li>\n<li>tsconfig.app.json \u5e94\u7528\u7684typescript\u914d\u7f6e.<\/li>\n<li>tsconfig.spec.json \u5e94\u7528\u6d4b\u8bd5\u7684typescript\u914d\u7f6e\u3002<\/li>\n<\/ul>\n<p>\u5e94\u7528\u6e90\u6587\u4ef6\uff1a<\/p>\n<ul>\n<li>\n<p>app\/ \u5305\u542b\u5b9a\u4e49\u5e94\u7528\u903b\u8f91\u548c\u6570\u636e\u7684\u7ec4\u4ef6\u6587\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p>assets\/ \u5305\u542b\u8981\u5728\u6784\u5efa\u5e94\u7528\u65f6\u5e94\u8be5\u6309\u539f\u6837\u590d\u5236\u7684\u56fe\u50cf\u548c\u9759\u6001\u6587\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p>environments\/ \u5305\u542b\u7279\u5b9a\u76ee\u6807\u73af\u5883\u7684\u6784\u5efa\u914d\u7f6e\u9009\u9879\u3002<\/p>\n<\/li>\n<li>\n<p>favicon.ico \u5e94\u7528\u5728\u6807\u7b7e\u680f\u4e2d\u7684\u56fe\u6807\u3002<\/p>\n<\/li>\n<li>\n<p>index.html \u4e3b\u9875\u9762\u3002<\/p>\n<\/li>\n<li>\n<p>main.ts \u5e94\u7528\u7684\u5165\u53e3\u3002<\/p>\n<\/li>\n<li>\n<p>polyfills.ts \u4e3a\u6d4f\u89c8\u5668\u652f\u6301\u63d0\u4f9bpolyfill\u811a\u672c\u3002<\/p>\n<\/li>\n<li>\n<p>styles.css \u5217\u51fa\u4e3a\u9879\u76ee\u63d0\u4f9b\u6837\u5f0f\u7684css\u6587\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p>app\/app.component.ts \u6839\u7ec4\u4ef6AppComponent.<\/p>\n<\/li>\n<li>\n<p>app\/app.component.html<\/p>\n<\/li>\n<li>\n<p>app\/app.component.css<\/p>\n<\/li>\n<li>\n<p>app\/app.component.spec.ts \u6839\u7ec4\u4ef6\u7684\u5355\u5143\u6d4b\u8bd5.<\/p>\n<\/li>\n<li>\n<p>app\/app.module.ts \u5b9a\u4e49\u540d\u4e3aAppModule\u6839\u6a21\u5757.<\/p>\n<\/li>\n<\/ul>\n<hr>\n<h1 id=\"module\">Module<\/h1>\n<p>angular\u7684\u6a21\u5757\u5316\u7cfb\u7edfNgModule, \u4e5f\u5c31\u662f\u6839\u6a21\u5757\uff0c\u4e60\u60ef\u547d\u540d\u4e3aAppModule,\u4f4d\u4e8eapp.module.ts\u6587\u4ef6\u3002<\/p>\n<p>NgModule\u662f\u4e00\u4e2a\u5e26\u6709@NgModule()\u88c5\u9970\u5668\u7684\u7c7b\uff0c\u8be5\u88c5\u9970\u5668\u662f\u4e00\u4e2a\u51fd\u6570.<\/p>\n<p>\u91cd\u8981\u7684\u5c5e\u6027:<\/p>\n<ul>\n<li>declarations: \u53ef\u7533\u660e\u5bf9\u8c61\u8868\uff0c\u6570\u636e\u672cNgModule\u7684\u7ec4\u4ef6\uff0c\u6307\u4ee4\u548c\u7ba1\u9053\u3002<\/li>\n<li>exports\uff1a\u5bfc\u51fa\u8868\uff0c\u80fd\u5728\u5176\u5b83\u6a21\u5757\u7684\u7ec4\u4ef6\u6a21\u677f\u4e2d\u4f7f\u7528\u7684\u53ef\u7533\u660e\u5bf9\u8c61\u7684\u5b50\u96c6\u3002<\/li>\n<li>imports\uff1a\u5bfc\u5165\u8868\uff0c\u5bfc\u51fa\u4e86\u672c\u6a21\u5757\u4e2d\u7684\u7ec4\u4ef6\u6a21\u677f\u6240\u9700\u7684\u7c7b\u7684\u5176\u5b83\u6a21\u5757\u3002<\/li>\n<li>providers\uff1a\u672c\u6a21\u5757\u5411\u5168\u5c40\u670d\u52a1\u4e2d\u8d21\u732e\u7684\u90a3\u4e9b\u670d\u52a1\u7684\u521b\u5efa\u5668\u3002<\/li>\n<li>bootstrap\uff1a\u5e94\u7528\u7684\u4e3b\u89c6\u56fe\uff0c\u79f0\u4e3a\u6839\u7ec4\u4ef6\uff0c\u662f\u5e94\u7528\u4e2d\u6240\u6709\u5176\u5b83\u89c6\u56fe\u7684\u5bbf\u4e3b\u3002<\/li>\n<\/ul>\n<hr>\n<h1 id=\"components\">components<\/h1>\n<p>\u7ec4\u4ef6\u63a7\u5236\u5c4f\u5e55\u4e0a\u88ab\u79f0\u4e3a\u89c6\u56fe\u7684\u4e00\u5c0f\u7247\u533a\u57df, \u6bcf\u4e2aangular\u5e94\u7528\u6700\u5c11\u6709\u4e00\u4e2a\u6839\u7ec4\u4ef6\u3002<\/p>\n<p>\u901a\u8fc7@Component\u88c5\u9970\u5668\u5b9a\u4e49\u7ec4\u4ef6.<\/p>\n<p>\u7ec4\u4ef6\u914d\u7f6e\u9009\u9879\uff1a<\/p>\n<ul>\n<li>selector: \u9009\u62e9\u5668<\/li>\n<li>templateUrl: \u8be5\u7ec4\u4ef6\u7684HTML\u6a21\u677f\u6587\u4ef6\u76f8\u5bf9\u4e8e\u7ec4\u4ef6\u6587\u4ef6\u7684\u5730\u5740\u3002<\/li>\n<li>template: html<\/li>\n<li>styleUrls: \u8be5\u7ec4\u4ef6\u7684CSS\u6587\u4ef6\u76f8\u5bf9\u8def\u5f84.<\/li>\n<li>style: css<\/li>\n<li>providers: \u5f53\u524d\u7ec4\u4ef6\u6240\u9700\u7684\u670d\u52a1\u63d0\u4f9b\u8005\u7684\u4e00\u4e2a\u6570\u7ec4\u3002<\/li>\n<\/ul>\n<h1 id=\"pipes\">pipes<\/h1>\n<p>\u7ba1\u9053<\/p>\n<h1 id=\"directives\">directives<\/h1>\n<p>\u6307\u4ee4\u5c31\u662f\u5e26\u6709@Directive()\u88c5\u9970\u5668\u7684\u7c7b\u3002<\/p>\n<p>\u7ec4\u4ef6\u662f\u7279\u6b8a\u6307\u4ee4\uff0cangular\u8fd8\u5185\u7f6e\u4e86\u7ed3\u6784\u578b\u6307\u4ee4\u548c\u5c5e\u6027\u578b\u6307\u4ee4\uff0c\u4e5f\u53ef\u4ee5\u81ea\u5b9a\u4e49\u6307\u4ee4\u3002<\/p>\n<p>\u7ed3\u6784\u578b\u6307(structural)\u4ee4\u901a\u8fc7\u6dfb\u52a0\uff0c\u79fb\u9664\u6216\u66ff\u6362DOM\u5143\u7d20\u6765\u4fee\u6539\u5e03\u5c40\u3002<\/p>\n<p>\u5c5e\u6027\u578b\u6307\u4ee4(attribute)\u4f1a\u4fee\u6539\u73b0\u6709\u5143\u7d20\u7684\u5916\u89c2\u548c\u884c\u4e3a\u3002<\/p>\n<h1 id=\"services\">services<\/h1>\n<p>\u670d\u52a1\u7c7b\uff1a \u5bf9\u4e8e\u4e0e\u7279\u5b9a\u89c6\u56fe\u65e0\u5173\u5e76\u5e0c\u671b\u8de8\u7ec4\u4ef6\u5171\u4eab\u7684\u6570\u636e\u6216\u903b\u8f91\uff0c\u53ef\u4ee5\u521b\u5efa\u670d\u52a1\u7c7b\u3002<\/p>\n<h1 id=\"dependency-injection\">dependency injection<\/h1>\n<p>\u4f9d\u8d56\u6ce8\u5165\u53ef\u4ee5\u4fdd\u6301\u7ec4\u4ef6\u7684\u7cbe\u7b80\u548c\u9ad8\u6548\u3002<\/p>\n<p>\u901a\u8fc7@Injectable\u88c5\u9970\u5668\u6765\u5b9a\u4e49DI\u3002<\/p>\n<h1 id=\"routing\">routing<\/h1>"},{"title":"DevOps","link":"https:\/\/canuxcheng.com\/post\/js_devops\/","pubDate":"Mon, 13 Mar 2017 09:36:32 +0000","guid":"https:\/\/canuxcheng.com\/post\/js_devops\/","description":"<h1 id=\"js--ts\">JS &amp; TS<\/h1>\n<p>vscode<\/p>\n<div class=\"highlight\"><pre tabindex=\"0\" style=\"color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;\"><code class=\"language-json\" data-lang=\"json\"><span style=\"display:flex;\"><span>{\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;version&#34;<\/span>: <span style=\"color:#e6db74\">&#34;0.2.0&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;configurations&#34;<\/span>: [\n<\/span><\/span><span style=\"display:flex;\"><span> {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;name&#34;<\/span>: <span style=\"color:#e6db74\">&#34;Next.js: debug server-side&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;type&#34;<\/span>: <span style=\"color:#e6db74\">&#34;node-terminal&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;request&#34;<\/span>: <span style=\"color:#e6db74\">&#34;launch&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;command&#34;<\/span>: <span style=\"color:#e6db74\">&#34;npm run dev&#34;<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> },\n<\/span><\/span><span style=\"display:flex;\"><span> {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;name&#34;<\/span>: <span style=\"color:#e6db74\">&#34;Next.js: debug client-side&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;type&#34;<\/span>: <span style=\"color:#e6db74\">&#34;chrome&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;request&#34;<\/span>: <span style=\"color:#e6db74\">&#34;launch&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;url&#34;<\/span>: <span style=\"color:#e6db74\">&#34;http:\/\/localhost:3000&#34;<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> },\n<\/span><\/span><span style=\"display:flex;\"><span> {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;name&#34;<\/span>: <span style=\"color:#e6db74\">&#34;Next.js: debug client-side (Firefox)&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;type&#34;<\/span>: <span style=\"color:#e6db74\">&#34;firefox&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;request&#34;<\/span>: <span style=\"color:#e6db74\">&#34;launch&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;url&#34;<\/span>: <span style=\"color:#e6db74\">&#34;http:\/\/localhost:3000&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;reAttach&#34;<\/span>: <span style=\"color:#66d9ef\">true<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;pathMappings&#34;<\/span>: [\n<\/span><\/span><span style=\"display:flex;\"><span> {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;url&#34;<\/span>: <span style=\"color:#e6db74\">&#34;webpack:\/\/_N_E&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;path&#34;<\/span>: <span style=\"color:#e6db74\">&#34;${workspaceFolder}&#34;<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> }\n<\/span><\/span><span style=\"display:flex;\"><span> ]\n<\/span><\/span><span style=\"display:flex;\"><span> },\n<\/span><\/span><span style=\"display:flex;\"><span> {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;name&#34;<\/span>: <span style=\"color:#e6db74\">&#34;Next.js: debug full stack&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;type&#34;<\/span>: <span style=\"color:#e6db74\">&#34;node&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;request&#34;<\/span>: <span style=\"color:#e6db74\">&#34;launch&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;program&#34;<\/span>: <span style=\"color:#e6db74\">&#34;${workspaceFolder}\/node_modules\/next\/dist\/bin\/next&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;runtimeArgs&#34;<\/span>: [<span style=\"color:#e6db74\">&#34;--inspect&#34;<\/span>],\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;skipFiles&#34;<\/span>: [<span style=\"color:#e6db74\">&#34;&lt;node_internals&gt;\/**&#34;<\/span>],\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;serverReadyAction&#34;<\/span>: {\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;action&#34;<\/span>: <span style=\"color:#e6db74\">&#34;debugWithEdge&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;killOnServerStop&#34;<\/span>: <span style=\"color:#66d9ef\">true<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;pattern&#34;<\/span>: <span style=\"color:#e6db74\">&#34;- Local:.+(https?:\/\/.+)&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;uriFormat&#34;<\/span>: <span style=\"color:#e6db74\">&#34;%s&#34;<\/span>,\n<\/span><\/span><span style=\"display:flex;\"><span> <span style=\"color:#f92672\">&#34;webRoot&#34;<\/span>: <span style=\"color:#e6db74\">&#34;${workspaceFolder}&#34;<\/span>\n<\/span><\/span><span style=\"display:flex;\"><span> }\n<\/span><\/span><span style=\"display:flex;\"><span> }\n<\/span><\/span><span style=\"display:flex;\"><span> ]\n<\/span><\/span><span style=\"display:flex;\"><span>}\n<\/span><\/span><\/code><\/pre><\/div><p>SPA: Single page application, \u5355\u9875\u5e94\u7528\uff0clike react, vue and angular.\nSSR: server side rendering. \u670d\u52a1\u7aef\u6e32\u67d3, like next.js, nuxt.js<\/p>\n<hr>\n<h2 id=\"yalc\">yalc<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/wclr\/yalc\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/wclr\/yalc<\/a><\/p>\n<p>install:<\/p>\n<pre><code>npm i yalc -g\n<\/code><\/pre>\n<p>usage:<\/p>\n<pre><code>yalc publish\nyalc add ...\nyalc remove ...\nyalc publish\nyalc push\n<\/code><\/pre>\n<p>yalc publish\u9700\u8981exports dist\uff0c\u800c\u4e0d\u662fsrc\u3002<\/p>\n<pre><code>&quot;exports&quot;: {\n&quot;.&quot;: &quot;.\/dist\/index.cjs.js&quot;,\n&quot;.\/alpha&quot;: &quot;.\/dist\/alpha.cjs.js&quot;,\n&quot;.\/package.json&quot;: &quot;.\/package.json&quot;\n}\n<\/code><\/pre>\n<hr>\n<h2 id=\"eslint\">ESLint<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/typescript-eslint\/typescript-eslint\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/typescript-eslint\/typescript-eslint<\/a><\/p>\n<p>linting.<\/p>\n<hr>\n<h2 id=\"vite\">vite<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/vitejs\/vite\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/vitejs\/vite<\/a><\/p>\n<hr>\n<h2 id=\"webpack\">Webpack<\/h2>\n<p>bundler<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/webpack\/webpack\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/webpack\/webpack<\/a><\/p>\n<hr>\n<h2 id=\"rollup\">Rollup<\/h2>\n<p>bundler<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/rollup\/rollup\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/rollup\/rollup<\/a><\/p>\n<hr>\n<h2 id=\"gulp\">gulp<\/h2>\n<p>Automation - gulp is a toolkit that helps you automate painful or time-consuming tasks in your development workflow.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/gulpjs\/gulp\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/gulpjs\/gulp<\/a><\/p>\n<p>gulp command line<\/p>\n<pre><code>$ npm install --global gulp-cli\n<\/code><\/pre>\n<p>gulp for devDependencies<\/p>\n<pre><code>$ npm install --save-dev gulp\n<\/code><\/pre>\n<p>create gulpfile.js and test it.<\/p>\n<pre><code>$ vim gulpfile.js\n$ gulp\n<\/code><\/pre>\n<h2 id=\"karma\">karma<\/h2>\n<p>A simple tool that allows you to execute JavaScript code in multiple real browsers.<\/p>\n<p>angularjs \u7684 test runner.<\/p>\n<p>The main purpose of Karma is to make your test-driven development easy, fast, and fun.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/karma-runner\/karma\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/karma-runner\/karma<\/a><\/p>\n<p>karma command line:<\/p>\n<pre><code>$ npm install -g karma-cli\n<\/code><\/pre>\n<p>karma for devDependencies<\/p>\n<pre><code>$ npm install --save-dev karma\n$ npm install karma-jasmine karma-chrome-launcher jasmine-core --save-dev\n<\/code><\/pre>\n<p>run karma<\/p>\n<pre><code>$ karma start\n<\/code><\/pre>"},{"title":"JavaScript","link":"https:\/\/canuxcheng.com\/post\/js\/","pubDate":"Mon, 13 Mar 2017 09:36:32 +0000","guid":"https:\/\/canuxcheng.com\/post\/js\/","description":"<h1 id=\"javascript\u6982\u8ff0\">JavaScript\u6982\u8ff0<\/h1>\n<p>Javascript\u5305\u62ec\u4e09\u90e8\u5206:<\/p>\n<ol>\n<li>ECMAScript\u6838\u5fc3,\u63d0\u4f9b\u6838\u5fc3\u8bed\u8a00\u529f\u80fd\uff0e<\/li>\n<li>DOM\u6587\u6863\u5bf9\u8c61\u6a21\u578b, \u63d0\u4f9b\u8bbf\u95ee\u548c\u64cd\u4f5c\u7f51\u9875\u5185\u5bb9\u7684\u65b9\u6cd5\u548c\u63a5\u53e3\uff0e<\/li>\n<li>BOM\u6d4f\u89c8\u5668\u5bf9\u8c61\u6a21\u578b, \u63d0\u4f9b\u4e0e\u6d4f\u89c8\u5668\u4ea4\u4e92\u7684\u65b9\u6cd5\u548c\u63a5\u53e3\uff0e<\/li>\n<\/ol>\n<p>ES5.0 (2009)\nES5.1 (2011, ISO\/IEC)\nES6.0 (2015)<\/p>\n<hr>\n<h1 id=\"javascript\u57fa\u672c\u8bed\u6cd5\">javascript\u57fa\u672c\u8bed\u6cd5<\/h1>\n<p>javascript\u6e90\u7a0b\u5e8f\u53ebxxx.js.<\/p>\n<p>javascript\u5927\u5c0f\u5199\u654f\u611f\uff0e<\/p>\n<p>javascript\u4f7f\u7528\u9a7c\u5cf0\u547d\u540d\u6cd5\uff0e<\/p>\n<p>javascript\u7684\u6807\u8bc6\u7b26\u4ee5\u5b57\u6bcd\uff0c\u4e0b\u5212\u7ebf\u6216\u7f8e\u5143\u7b26\u53f7\u5f00\u5934\uff0c\u8fd8\u53ef\u4ee5\u5305\u542b\u6570\u5b57\uff0e\u4e0d\u80fd\u662f\u5173\u952e\u5b57\uff0e<\/p>\n<p>JvaScript\u4ee3\u7801\u5757\u4ee5\u5927\u62ec\u53f7{}\u5305\u56f4,\u5f00\u62ec\u53f7\u5199\u5728\u7b2c\u4e00\u884c\u7ed3\u5c3e\u5904\uff0c\u524d\u9762\u7a7a\u683c\uff0c\u95ed\u62ec\u53f7\u5355\u72ec\u4e00\u884c\u3002<\/p>\n<p>javascript\u4e2d\u6240\u6709\u4e8b\u7269\u90fd\u662f\u5bf9\u8c61\uff0c\u90fd\u6709\u5c5e\u6027\u548c\u65b9\u6cd5.<\/p>\n<p>JavaScript\u4f7f\u7528\u5206\u53f7;\u8868\u793a\u4e00\u4e2a\u8bed\u53e5\u7ed3\u675f, \u4e00\u822c\u4e00\u884c\u5199\u591a\u4e2a\u8bed\u53e5\u624d\u9700\u8981\u663e\u793a\u6dfb\u52a0\u5206\u53f7\uff0e<\/p>\n<p>javascript\u4e2d\u8fd0\u7b97\u7b26\u5468\u56f4\u8981\u6709\u7a7a\u683c\u3002<\/p>\n<p>javascript\u4e2d\u4f7f\u7528\u56db\u4e2a\u7a7a\u683c\u6765\u7f29\u8fdb\u3002<\/p>\n<p>javascript\u4e0d\u652f\u6301goto\u3002<\/p>\n<hr>\n<h1 id=\"\u6ce8\u91ca\">\u6ce8\u91ca<\/h1>\n<p>\u5355\u884c\u6ce8\u91ca\uff1a<\/p>\n<pre><code>\/\/ comment\n<\/code><\/pre>\n<p>\u591a\u884c\u6ce8\u91ca\uff1a<\/p>\n<pre><code>\/*\n* comment1\n* comment2\n*\/\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u5173\u952e\u5b57\">\u5173\u952e\u5b57<\/h1>\n<pre><code># \u6570\u636e\u7c7b\u578b\nvar function return typeof new delete\n# \u6d41\u7a0b\u63a7\u5236\nif else for in do while switch case default with break continue\n# \u4fee\u9970\u7b26\nvoid\n# \u52a8\u4f5c\u76f8\u5173\ninstanceof this\n# \u5f02\u5e38\u5904\u7406\ntry catch throw\n# \u8c03\u8bd5\ndebugger\n# ECMAScript2015\nlet const\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u8fd0\u7b97\u7b26\u548c\u4f18\u5148\u7ea7\">\u8fd0\u7b97\u7b26\u548c\u4f18\u5148\u7ea7<\/h1>\n<h2 id=\"\u7b97\u6570\u8fd0\u7b97\u7b26\">\u7b97\u6570\u8fd0\u7b97\u7b26<\/h2>\n<pre><code>+\n-\n*\n**\n\/\n%\n++\n--\n<\/code><\/pre>\n<h2 id=\"\u8d4b\u503c\u8fd0\u7b97\u7b26\">\u8d4b\u503c\u8fd0\u7b97\u7b26<\/h2>\n<pre><code>=\n+=\n-=\n*=\n\/=\n%=\n&lt;&lt;=\n&gt;&gt;=\n&gt;&gt;&gt;=\n&amp;=\n^=\n|=\n**=\n<\/code><\/pre>\n<h2 id=\"\u6bd4\u8f83\u8fd0\u7b97\u7b26\">\u6bd4\u8f83\u8fd0\u7b97\u7b26<\/h2>\n<pre><code>\/\/ \u5728\u6bd4\u8f83\u503c\u94b1\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362.\n==\n\/\/ \u5f3a\u5236\u5bf9\u503c\u548c\u7c7b\u578b\u8fdb\u884c\u6bd4\u8f83.\n===\n!=\n!==\n&gt;\n&lt;\n&gt;=\n&lt;=\n\/\/ \u4e09\u5143\u8fd0\u7b97\u7b26\n?\n<\/code><\/pre>\n<h2 id=\"\u903b\u8f91\u8fd0\u7b97\u7b26\">\u903b\u8f91\u8fd0\u7b97\u7b26<\/h2>\n<pre><code>\/\/ \u903b\u8f91\u4e0e\n&amp;&amp;\n\/\/ \u903b\u8f91\u6216\n||\n\/\/ \u903b\u8f91\u975e\n!\n<\/code><\/pre>\n<h2 id=\"\u7c7b\u578b\u8fd0\u7b97\u7b26\">\u7c7b\u578b\u8fd0\u7b97\u7b26<\/h2>\n<pre><code>typeof\ninstanceof\n<\/code><\/pre>\n<h2 id=\"\u4f4d\u8fd0\u7b97\u7b26\">\u4f4d\u8fd0\u7b97\u7b26<\/h2>\n<pre><code>&amp;\n|\n~\n^\n&lt;&lt;\n&gt;&gt;\n&gt;&gt;&gt;\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u6570\u636e\u7c7b\u578b\">\u6570\u636e\u7c7b\u578b<\/h1>\n<h2 id=\"var\u7533\u660e\u53d8\u91cf\">var\u7533\u660e\u53d8\u91cf<\/h2>\n<p>\u901a\u8fc7var\u7533\u660e\u7684\u53d8\u91cf\u6ca1\u6709\u5757\u4f5c\u7528\u57df\uff0c\u5728\u5757\u4e4b\u5916\u4e5f\u80fd\u8bbf\u95ee.<\/p>\n<p>\u7533\u660e\u53d8\u91cf:<\/p>\n<p>\u91cd\u590d\u7533\u660e\u540c\u540d\u53d8\u91cf\u4e0d\u4f1a\u6539\u53d8\u53d8\u91cf\u7684\u503c\uff0e<\/p>\n<pre><code>var varName;\n\/\/ \u4e00\u6b21\u7533\u660e\u591a\u4e2a\u53d8\u91cf\nvar varName1, varName2, ...;\n<\/code><\/pre>\n<p>\u8d4b\u503c:<\/p>\n<pre><code>varName = varValue;\n<\/code><\/pre>\n<p>\u7533\u660e\u5e76\u8d4b\u503c:<\/p>\n<p>\u52a8\u6001\u7c7b\u578b\u8bed\u8a00\uff0c\u53d8\u91cf\u53ef\u4ee5\u8d4b\u4e88\u4e0d\u540c\u7c7b\u578b\u503c.<\/p>\n<pre><code>var varName = varValue;\n\/\/ \u4e00\u6b21\u5b9a\u4e49\u591a\u4e2a\u53d8\u91cf\nvar varName1 = varValue1, varName2=varValue2, ...;\n<\/code><\/pre>\n<p>\u7533\u660e\u53d8\u91cf\u7c7b\u578b:<\/p>\n<pre><code>var varName = new Boolean\/Number\/String\/Array\/Object;\n<\/code><\/pre>\n<h2 id=\"let\u7533\u660e\u53d8\u91cf\">let\u7533\u660e\u53d8\u91cf<\/h2>\n<p>\u901a\u8fc7let\u7533\u660e\u6709\u5757\u4f5c\u7528\u57df\u7684\u53d8\u91cf.<\/p>\n<pre><code>{\nlet varName = varValue;\n}\n<\/code><\/pre>\n<p>let\u4e0d\u80fd\u591a\u6b21\u7533\u660e\u540c\u4e00\u4e2a\u53d8\u91cf\u3002<\/p>\n<h2 id=\"const\u7533\u660e\u5e38\u91cf\">const\u7533\u660e\u5e38\u91cf<\/h2>\n<p>const\u5b9a\u4e49\u7684\u53d8\u91cf\u4e0elet\u76f8\u4f3c\uff0c \u4f46\u4e0d\u80fd\u91cd\u65b0\u8d4b\u503c.<\/p>\n<p>\u5b83\u6ca1\u6709\u5b9a\u4e49\u5e38\u91cf\u503c\u3002\u5b83\u5b9a\u4e49\u4e86\u5bf9\u503c\u7684\u5e38\u91cf\u5f15\u7528\u3002<\/p>\n<pre><code>{\nconst varName = varValue;\n}\n<\/code><\/pre>\n<p>\u5e38\u91cf\u5bf9\u8c61\u7684\u5c5e\u6027\u53ef\u4ee5\u4fee\u6539\uff1a<\/p>\n<pre><code>const car = {type:&quot;porsche&quot;, model:&quot;911&quot;, color:&quot;black&quot;};\ncar.color = &quot;white&quot;;\n<\/code><\/pre>\n<p>\u5e38\u91cf\u6570\u7ec4\u5143\u7d20\u53ef\u4ee5\u4fee\u6539\uff1a<\/p>\n<pre><code>const cars = [&quot;audi&quot;, &quot;bmw&quot;];\ncars[0] = &quot;honda&quot;;\n<\/code><\/pre>\n<h2 id=\"\u5e03\u5c14boolean\">\u5e03\u5c14\/Boolean<\/h2>\n<p>\u5e03\u5c14\u7c7b\u578b\u53ea\u6709true\u548cfalse\u4e24\u4e2a\u503c\uff0e<\/p>\n<pre><code>var x = true\nvar y = false\n<\/code><\/pre>\n<h2 id=\"\u6570\u5b57number\">\u6570\u5b57\/Number<\/h2>\n<pre><code>var name = 1.3\n<\/code><\/pre>\n<h2 id=\"\u5b57\u7b26\u4e32string\">\u5b57\u7b26\u4e32\/String<\/h2>\n<p>\u5b57\u7b26\u4e32\u53ef\u4ee5\u7528\u5355\u5f15\u53f7\u6216\u53cc\u5f15\u53f7\u8868\u793a.<\/p>\n<pre><code>var name = &quot;string&quot;\n<\/code><\/pre>\n<h2 id=\"null\">Null<\/h2>\n<p>Null\u7c7b\u578b\u53ea\u6709\u4e00\u4e2a\u7279\u6b8a\u503cnull.\u8868\u793a\u4e00\u4e2a\u7a7a\u5bf9\u8c61\u6307\u9488.<\/p>\n<p>\u901a\u8fc7null\u6e05\u7a7a\u53d8\u91cf\u7684\u503c\uff0e<\/p>\n<pre><code>varName = null\n<\/code><\/pre>\n<h2 id=\"undefined\">Undefined<\/h2>\n<p>\u6ca1\u6709\u8d4b\u503c\u7684\u53d8\u91cf\u503c\u4e3aundefined.<\/p>\n<p>Undefined\u7c7b\u578b\u53ea\u6709\u4e00\u4e2a\u7279\u6b8a\u503cundefined.<\/p>\n<h2 id=\"\u5bf9\u8c61object\">\u5bf9\u8c61\/Object<\/h2>\n<p>\u5bf9\u8c61\u7531\u5927\u62ec\u53f7\u5305\u56f4\u7684\u952e\u503c\u5bf9\u8868\u793a\uff0c\u4e2d\u95f4\u7528\u9017\u53f7\u9694\u5f00.<\/p>\n<p>\u5b9a\u4e49\u5bf9\u8c61\uff1a<\/p>\n<pre><code>var obj = new Object;\nvar obj = {key: &quot;val&quot;, key1: &quot;val1&quot;};\nvar obj = {\nfirstName: &quot;bill&quot;, \/\/ \u5192\u53f7\u540e\u7a7a\u683c.\nlastName: &quot;gates&quot; \/\/ \u6700\u540e\u4e00\u4e2a\u4e0d\u8981\u90fd\u597d.\n};\n<\/code><\/pre>\n<p>\u8bbf\u95ee\u5bf9\u8c61\u5c5e\u6027:<\/p>\n<pre><code>val = obj.key\nval = obj[&quot;key&quot;]\n<\/code><\/pre>\n<p>\u8bbf\u95ee\u5bf9\u8c61\u65b9\u6cd5:<\/p>\n<pre><code>obj.method()\n<\/code><\/pre>\n<h2 id=\"typeof\">typeof<\/h2>\n<p>\u8be5\u64cd\u4f5c\u7b26\u53ef\u4ee5\u8fd4\u56de\u6570\u636e\u7c7b\u578b:<\/p>\n<pre><code>undefined\nboolean\nnumber\nstring\nobject\nfunction\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u63a7\u5236\u6d41\">\u63a7\u5236\u6d41<\/h1>\n<h2 id=\"if\">if<\/h2>\n<pre><code>if (condition) {\nexpression;\n}\nif (condition) {\nexpression;\n} else {\nexpression;\n}\nif (condition) {\nexpression;\n} else if (condition) {\nexpression;\n} else {\nexpression;\n}\n<\/code><\/pre>\n<h2 id=\"switch\">switch<\/h2>\n<pre><code>switch(expression) {\ncase value:\nstatement;\nbreak;\ncase value:\nstatement;\nbreak;\n...\ndefault:\nstatement;\n}\n<\/code><\/pre>\n<h2 id=\"for\">for<\/h2>\n<p>for:<\/p>\n<pre><code>for (initialization; expression; post-loop-expression) {\nstatement;\n}\n<\/code><\/pre>\n<p>for-in:<\/p>\n<p>\u5faa\u73af\u904d\u5386\u5bf9\u8c61\u7684\u5c5e\u6027<\/p>\n<pre><code>for (property in object) {\nstatement;\n}\n<\/code><\/pre>\n<h2 id=\"while\">while<\/h2>\n<p>do-while:<\/p>\n<pre><code>do {\nstatement;\n} while (condition);\n<\/code><\/pre>\n<p>while:<\/p>\n<pre><code>while (condition) {\nstatement;\n}\n<\/code><\/pre>\n<h2 id=\"with\">with<\/h2>\n<p>\u5c06\u4ee3\u7801\u4f5c\u7528\u4e8e\u8bbe\u5b9a\u5230\u4e00\u4e2a\u7279\u5b9a\u5bf9\u8c61.<\/p>\n<pre><code>with (expression) {\nstatement;\n}\n<\/code><\/pre>\n<h2 id=\"break\u548ccontinue\">break\u548ccontinue<\/h2>\n<p>label:<\/p>\n<p>break\u548ccontinue\u90fd\u53ef\u4ee5\u548clabel\u914d\u5408\u4f7f\u7528.<\/p>\n<pre><code>labelName: statement\n<\/code><\/pre>\n<p>break:<\/p>\n<p>\u8df3\u51fa\u5faa\u73af(for, while).<\/p>\n<pre><code>labelName:\nfor () {\nfor () {\nif () {\nbreak labelName; # \u8df3\u51fa\u6700\u5916\u5c42\u5faa\u73af\n}\n}\n}\n<\/code><\/pre>\n<p>continue:<\/p>\n<p>\u7ee7\u7eed\u4e0b\u4e00\u6b21\u5faa\u73af.<\/p>\n<pre><code>labelName:\nfor () {\nfor () {\nif () {\ncontinue labelName; # \u4ece\u5916\u5c42\u5faa\u73af\u7ee7\u7eed\u5faa\u73af\n}\n}\n}\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u6587\u4ef6\u548c\u8f93\u5165\u8f93\u51fa\">\u6587\u4ef6\u548c\u8f93\u5165\u8f93\u51fa<\/h1>\n<h2 id=\"\u8f93\u51fa\">\u8f93\u51fa<\/h2>\n<p>alert\u5199\u5165\u8b66\u544a\u6846\uff1a<\/p>\n<pre><code>window.alert(10);\n<\/code><\/pre>\n<p>write\u5199\u5165html\uff1a<\/p>\n<pre><code>document.write(10);\n<\/code><\/pre>\n<p>innerHTML\u5199\u5165html:<\/p>\n<pre><code>document.getElementById(&quot;demo&quot;).innerHTML = 10;\n<\/code><\/pre>\n<p>console.log\u5199\u5165\u6d4f\u89c8\u5668\u63a7\u5236\u53f0:<\/p>\n<pre><code>\/\/ \u53ef\u4ee5\u5728js\u4ee3\u7801\u6216\u8c03\u8bd5\u7a97\u53e3\u6253\u5370\u53d8\u91cf\u503c\uff1a\nconsole.log(10);\n<\/code><\/pre>\n<h2 id=\"\u8f93\u5165\">\u8f93\u5165<\/h2>\n<p>prompt<\/p>\n<p>alert\u548cprompt\u4f1a\u8df3\u8fc7\u6e32\u67d3\u5148\u88ab\u6267\u884c\u3002<\/p>\n<hr>\n<h1 id=\"\u51fd\u6570\">\u51fd\u6570<\/h1>\n<p>\u5b9a\u4e49\u51fd\u6570\uff1a<\/p>\n<pre><code>\/\/ \u6ca1\u53c2\u6570\nfunction funcName() {\n}\n\/\/ \u5e26\u53c2\u6570\nfunction funcName(args) {\n}\n\/\/ \u4f7f\u7528\u53d8\u91cf\nvar name = function(args) {};\n\/\/ \u4f7f\u7528\u6784\u9020\u65b9\u6cd5\nvar name = new Function(args, return value);\n<\/code><\/pre>\n<p>\u51fd\u6570\u8fd4\u56de\u503c:<\/p>\n<pre><code>function funcName() {\nreturn ...\n}\n\/\/ \u51fd\u6570\u8fd4\u56de\u503c\u8d4b\u503c\u7ed9\u53d8\u91cf\nvar value = funcName()\n<\/code><\/pre>\n<p>js\u7684\u51fd\u6570\u5f62\u5f0f\u53c2\u6570\u548c\u5b9e\u9645\u53c2\u6570\u53ef\u4ee5\u662f\u4efb\u610f\u4e2a\u6570\u548c\u4efb\u610f\u7c7b\u578b\uff0e<\/p>\n<p>\u51fd\u6570\u5185\u90e8\u5b9a\u4e49\u7684\u53d8\u91cf\u662f\u5c40\u90e8\u53d8\u91cf,\u5c40\u90e8\u53d8\u91cf\u5728\u51fd\u6570\u8fd0\u884c\u540e\u88ab\u5220\u9664\uff0e<\/p>\n<p>\u5982\u679c\u628a\u503c\u8d4b\u7ed9\u672a\u7533\u660e\u7684\u53d8\u91cf\uff0c\u8be5\u53d8\u91cf\u88ab\u81ea\u52a8\u4f5c\u4e3a\u5168\u5c40\u53d8\u91cf\uff0e<\/p>\n<pre><code>name = &quot;value&quot; \u76f8\u5f53\u4e8e\u5168\u5c40\u53d8\u91cf\n<\/code><\/pre>\n<p>\u51fd\u6570\u5185\u90e8\u5c5e\u6027:<\/p>\n<p>\u51fd\u6570\u5185\u90e8\u4e24\u4e2a\u7279\u6b8a\u5bf9\u8c61arguments\u548cthis.<\/p>\n<pre><code>arguments \/\/ \u7528\u6765\u5b58\u50a8\u8be5\u51fd\u6570\u7684\u6240\u6709\u53c2\u6570\narguments.callee \/\/ \u6307\u9488\uff0c\u6307\u5411\u8be5\u51fd\u6570\u672c\u8eab.\nthis \/\/ \u8868\u793a\u51fd\u6570\u8c03\u7528\u8bed\u53e5\u6240\u5904\u7684\u4f5c\u7528\u57df\nwindow \/\/ \u5f53\u5728\u5168\u5c40\u8c03\u7528this\uff0c\u5f15\u7528\u7684\u5c31\u662fwindow\u5bf9\u8c61.\n\/\/ \u8c03\u7528\u51fd\u6570\napply()\ncall()\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u9519\u8bef\u548c\u5f02\u5e38\">\u9519\u8bef\u548c\u5f02\u5e38<\/h1>\n<p>try-catch:<\/p>\n<pre><code>try {\nstatement;\n} catch(err) {\nstatement;\n}\n<\/code><\/pre>\n<p>throw:<\/p>\n<pre><code>throw exception\n<\/code><\/pre>\n<h2 id=\"\u4e25\u683c\u6a21\u5f0f\">\u4e25\u683c\u6a21\u5f0f<\/h2>\n<p>\u901a\u8fc7\u5728\u811a\u672c\u6216\u51fd\u6570\u5f00\u5934\u6dfb\u52a0\u4e25\u683c\u6a21\u5f0f\uff1a<\/p>\n<p>\u4e25\u683c\u6a21\u5f0f\u5728\u4e0d\u58f0\u660e\u53d8\u91cf\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528\u53d8\u91cf\uff0c\u662f\u4e0d\u5141\u8bb8\u7684<\/p>\n<pre><code>&quot;use strict&quot;;\n......\n<\/code><\/pre>\n<h2 id=\"debugger\u8c03\u8bd5\">debugger\u8c03\u8bd5<\/h2>\n<p>debugger\u5173\u952e\u5b57\u4f1a\u505c\u6b62js\u7684\u6267\u884c\uff0c\u5982\u679c\u6709\u8c03\u8bd5\u51fd\u6570\u5c31\u8c03\u7528\u3002<\/p>\n<p>\u5982\u679c\u8c03\u8bd5\u5668\u6253\u5f00\uff0c\u4f1a\u5728debugger\u505c\u6b62\u6267\u884c\uff0c\u5982\u679c\u6ca1\u6709\u6253\u5f00\u8c03\u8bd5\u5668\uff0c\u4f1a\u7ee7\u7eed\u8fd0\u884c\u3002<\/p>\n<pre><code>var x = 10;\ndebugger;\ndocument.getElementbyId(&quot;demo&quot;).innerHTML = x;\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u6a21\u5757\u548c\u5305\">\u6a21\u5757\u548c\u5305<\/h1>\n<h3 id=\"commonjs\">commonjs<\/h3>\n<p>for old nodejs projects.<\/p>\n<pre><code>\/\/ import\nrequire()\n\/\/ export\nmodule.exports\n<\/code><\/pre>\n<p>\u652f\u6301\u5355\u4e2a\u5bf9\u8c61\uff0c\u53ef\u4ee5\u662f\u9ed8\u8ba4\u5bf9\u8c61<\/p>\n<p>extention: &ldquo;*.js&rdquo;<\/p>\n<h3 id=\"es\">ES<\/h3>\n<p>for new nodejs projects.<\/p>\n<pre><code>\/\/ import\nimport * from *\n\/\/ export\nexport &lt;function&gt;\n<\/code><\/pre>\n<p>\u9ed8\u8ba4\u5bfc\u51fa\u548c\u547d\u540d\u5bfc\u51fa\u90fd\u53ef\u4ee5\u3002<\/p>\n<p>extention: *.mjs&quot;<\/p>\n<hr>\n<h1 id=\"\u6587\u6863\">\u6587\u6863<\/h1>\n<hr>\n<h1 id=\"jsx\">JSX<\/h1>\n<p>JSX \u662f JavaScript \u8bed\u6cd5\u6269\u5c55\uff0c\u53ef\u4ee5\u8ba9\u4f60\u5728 JavaScript \u6587\u4ef6\u4e2d\u4e66\u5199\u7c7b\u4f3c HTML \u7684\u6807\u7b7e\u3002\u867d\u7136\u8fd8\u6709\u5176\u5b83\u65b9\u5f0f\u53ef\u4ee5\u7f16\u5199\u7ec4\u4ef6\uff0c\u4f46\u5927\u90e8\u5206 React \u5f00\u53d1\u8005\u66f4\u559c\u6b22 JSX \u7684\u7b80\u6d01\u6027\uff0c\u5e76\u4e14\u5728\u5927\u90e8\u5206\u4ee3\u7801\u5e93\u4e2d\u4f7f\u7528\u5b83\u3002<\/p>"},{"title":"JS Test","link":"https:\/\/canuxcheng.com\/post\/js_test\/","pubDate":"Mon, 13 Mar 2017 09:36:32 +0000","guid":"https:\/\/canuxcheng.com\/post\/js_test\/","description":"<h1><\/h1>\n<hr>\n<h2 id=\"jest\">Jest<\/h2>\n<p>for javascript.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/jestjs\/jest\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/jestjs\/jest<\/a><\/p>\n<h2 id=\"ts-jest\">TS Jest<\/h2>\n<p>for typescript.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kulshekhar\/ts-jest\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kulshekhar\/ts-jest<\/a><\/p>\n<hr>\n<h2 id=\"jasmine\">jasmine<\/h2>\n<p>A JavaScript Testing Framework<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/jasmine\/jasmine\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/jasmine\/jasmine<\/a><\/p>\n<p>install jasmine to devDependencies<\/p>\n<pre><code>$ npm install --save-dev jasmineinit\n<\/code><\/pre>\n<p>jasmine in project<\/p>\n<pre><code>$ npx jasmine init\n<\/code><\/pre>\n<p>set jasmine as test script in package.json<\/p>\n<pre><code>&gt; &quot;scripts&quot;: { &quot;test&quot;: &quot;jasmine&quot; }\n<\/code><\/pre>\n<p>run test<\/p>\n<pre><code>$ npm test\n<\/code><\/pre>"},{"title":"Testing","link":"https:\/\/canuxcheng.com\/post\/testing\/","pubDate":"Wed, 01 Mar 2017 09:41:39 +0000","guid":"https:\/\/canuxcheng.com\/post\/testing\/","description":"<h1 id=\"qa\">QA<\/h1>\n<p>Quality Assurance<\/p>\n<p>QA\u4e3b\u8981\u5c31\u662f\u8fdb\u884c\u8f6f\u4ef6\u6d4b\u8bd5\u76f8\u5173\u7684\u5de5\u4f5c.<\/p>\n<p>\u8f6f\u4ef6\u6d4b\u8bd5\u5c31\u662f\u4f7f\u7528\u4eba\u5de5\u6216\u81ea\u52a8\u7684\u624b\u6bb5\u6765\u8fd0\u884c\u6216\u6d4b\u91cf\u8f6f\u4ef6\u7cfb\u7edf\u7684\u8fc7\u7a0b\uff0c\u4ee5\u68c0\u9a8c\u8f6f\u4ef6\u7cfb\u7edf\u662f\u5426\u6ee1\u8db3\u89c4\u5b9a\u7684\u8981\u6c42\uff0c\u5e76\u627e\u51fa\u4e0e\u9884\u671f\u7ed3\u679c\u4e4b\u95f4\u7684\u5dee\u5f02\uff0e<\/p>\n<p>\u8f6f\u4ef6\u6d4b\u8bd5\u4e94\u4e2a\u8981\u7d20\uff1a<\/p>\n<ul>\n<li>\u8d28\u91cf<\/li>\n<li>\u4eba\u5458<\/li>\n<li>\u6280\u672f<\/li>\n<li>\u6d41\u7a0b<\/li>\n<li>\u8d44\u6e90<\/li>\n<\/ul>\n<p>\u8f6f\u4ef6\u6d4b\u8bd5\u4e24\u4e2a\u76ee\u6807\uff1a<\/p>\n<ul>\n<li>\u6d4b\u8bd5\u8986\u76d6\u7387<\/li>\n<li>\u6d4b\u8bd5\u6548\u7387<\/li>\n<\/ul>\n<p>\u8f6f\u4ef6\u6d4b\u8bd5\u9636\u6bb5\uff1a<\/p>\n<ul>\n<li>\u5355\u5143\u6d4b\u8bd5(Unit Testing)<\/li>\n<li>\u96c6\u6210\u6d4b\u8bd5(Integration Testing)\uff1a \u9a8c\u8bc1\u591a\u4e2a\u6a21\u5757\u4e4b\u95f4\u63a5\u53e3\u4ea4\u4e92\u3002<\/li>\n<li>\u7cfb\u7edf\u6d4b\u8bd5(System Testing)\uff1a\u6574\u4e2a\u7cfb\u7edf\u7684\u6d4b\u8bd5\uff0c\u9a8c\u8bc1\u7cfb\u7edf\u662f\u5426\u6ee1\u8db3\u9700\u6c42\uff08\u529f\u80fd\uff0c\u6027\u80fd\uff0c\u517c\u5bb9\u6027\uff0c\u7a33\u5b9a\u6027\uff09\u3002<\/li>\n<li>\u9a8c\u6536\u6d4b\u8bd5(Acceptance Testing)\u00b7<\/li>\n<\/ul>\n<p>\u8f6f\u4ef6\u6d4b\u8bd5\u7684\u624b\u6bb5\uff1a<\/p>\n<ul>\n<li>\u624b\u52a8\u6d4b\u8bd5\/\u81ea\u52a8\u5316\u6d4b\u8bd5<\/li>\n<li>\u9759\u6001\u6d4b\u8bd5<\/li>\n<li>\u52a8\u6001\u6d4b\u8bd5<\/li>\n<li>\u9ed1\u76d2\u6d4b\u8bd5<\/li>\n<li>\u767d\u76d2\u6d4b\u8bd5<\/li>\n<li>\u7070\u5ea6\u6d4b\u8bd5\uff1a\u90e8\u5206\u4e86\u89e3\u5185\u90e8\u7ed3\u6784\uff0c\u5e38\u7528\u4e8e\u6d4b\u8bd5\u63a5\u53e3\uff0c\u96c6\u6210\u5c42\uff0c\u590d\u6742\u4e1a\u52a1\u903b\u8f91\u7b49\u3002<\/li>\n<\/ul>\n<p>\u8f6f\u4ef6\u6d4b\u8bd5\u7684\u7c7b\u578b\uff1a<\/p>\n<ul>\n<li>\u6027\u80fd\u6d4b\u8bd5<\/li>\n<li>\u7a33\u5b9a\u6027\u6d4b\u8bd5<\/li>\n<li>\u5b89\u5168\u6d4b\u8bd5<\/li>\n<li>\u53ef\u7528\u6027\u6d4b\u8bd5<\/li>\n<li>\u517c\u5bb9\u6027\u6d4b\u8bd5<\/li>\n<li>\u6587\u6863\u6d4b\u8bd5<\/li>\n<li>\u672c\u5730\u5316\u6d4b\u8bd5<\/li>\n<li>\u5192\u70df\u6d4b\u8bd5<\/li>\n<li>\u529f\u80fd\u6d4b\u8bd5Functional Testing<\/li>\n<li>\u56de\u5f52\u6d4b\u8bd5Regression Testing<\/li>\n<li>\u7528\u6237\u754c\u9762\u6d4b\u8bd5UI Testing<\/li>\n<li>\u7aef\u5230\u7aef\u6d4b\u8bd5End-To-End Testing<\/li>\n<\/ul>\n<p>\u8f6f\u4ef6\u6d4b\u8bd5\u7684\u6a21\u578b\uff1a<\/p>\n<ul>\n<li>\u4f20\u7edf\u7684\u7011\u5e03\u6a21\u578b<\/li>\n<li>V\u6a21\u578b<\/li>\n<li>W\u6a21\u578b<\/li>\n<li>X\u6a21\u578b<\/li>\n<li>H\u6a21\u578b<\/li>\n<li>\u654f\u6377\u6d4b\u8bd5\u6a21\u578b(\u91d1\u5b57\u5854\u6a21\u5f0f)<\/li>\n<\/ul>\n<p>\u8f6f\u4ef6\u6d4b\u8bd5\u7684\u6a21\u5f0f\uff1a<\/p>\n<ul>\n<li>\u91d1\u5b57\u5854\u6a21\u5f0fIdeal Test Automation Pyramid<\/li>\n<li>\u86cb\u7b52\u51b0\u6fc0\u51cc\u6a21\u5f0fIce Cream Cone<\/li>\n<li>\u53cc\u91d1\u5b57\u5854\u6a21\u5f0fDual Test Pyramid<\/li>\n<li>\u7eb8\u676f\u86cb\u7cd5\u6a21\u5f0fCupcake<\/li>\n<\/ul>\n<h1 id=\"test-automation-pyramid\">Test Automation Pyramid<\/h1>\n<p>Mike Cohn\u7684\u6d4b\u8bd5\u91d1\u5b57\u5854<\/p>\n<p><a class=\"link\" href=\"https:\/\/martinfowler.com\/bliki\/TestPyramid.html\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/martinfowler.com\/bliki\/TestPyramid.html<\/a><\/p>\n<ul>\n<li>Automated GUI Tests(10%)<\/li>\n<li>Automated Service Tests(Component\/Integration\/API)(20%)<\/li>\n<li>Automated Unit Tests(70%)<\/li>\n<\/ul>\n<hr>\n<h1 id=\"unit-test\u5355\u5143\u6d4b\u8bd5\">Unit Test\/\u5355\u5143\u6d4b\u8bd5<\/h1>\n<p>\u5355\u5143\u6d4b\u8bd5\u662f\u5f00\u53d1\u8005\u7f16\u5199\u7684\u6d4b\u8bd5\u4e00\u4e2a\u5355\u5143\uff08\u51fd\u6570\uff0f\u7c7b\uff09\u7684\u529f\u80fd\u662f\u5426\u7b26\u5408\u9884\u671f\uff0e<\/p>\n<p>\u5355\u5143\u6d4b\u8bd5\u7684\u8986\u76d6\u7387\u662f\u6307\u6d4b\u8bd5\u7684\u5355\u5143\u8c03\u7528\u4e86\u591a\u5c11\u4ee3\u7801\uff0e<\/p>\n<p>Unit Test\u7684\u5de5\u5177\u6709\uff1a<\/p>\n<ul>\n<li>Java: Junit<\/li>\n<li>Python: unittest(pyunit), nose2, pytest<\/li>\n<\/ul>\n<hr>\n<h1 id=\"test-automation\">Test Automation<\/h1>\n<p>\u654f\u6377\u6d4b\u8bd5\u7684\u6838\u5fc3\u5c31\u662f\u81ea\u52a8\u5316\u6d4b\u8bd5\uff0e<\/p>\n<p>\u81ea\u52a8\u5316\u6d4b\u8bd5\u6846\u67b6\uff1a<\/p>\n<ul>\n<li>Robot Framework<\/li>\n<\/ul>\n<p>ATDD: Acceptance test-driven development<\/p>\n<p>BDD: Behavior-driven development<\/p>\n<hr>\n<h1 id=\"big-list-of-naughty-strings\">big-list-of-naughty-strings<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/minimaxir\/big-list-of-naughty-strings\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/minimaxir\/big-list-of-naughty-strings<\/a><\/p>\n<p>\u6d4b\u8bd5\u4e2d\u8c28\u614e\u4f7f\u7528\u7684\u5b57\u7b26\u4e32\uff0e<\/p>\n<hr>\n<h1 id=\"allure\">Allure<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/allure-framework\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/allure-framework<\/a><\/p>\n<p>Allure\u662f\u4e00\u4e2a\u7075\u6d3b\u7684\u8f7b\u91cf\u7ea7\u591a\u8bed\u8a00\u6d4b\u8bd5\u62a5\u544a\u6846\u67b6\uff0e<\/p>\n<h1 id=\"reportportal\">reportportal<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/reportportal\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/reportportal<\/a><\/p>\n<p>ReportPortal\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u6d4b\u8bd5\u62a5\u544a\u5e73\u53f0\uff0c\u652f\u6301\u591a\u79cd\u6d4b\u8bd5\u6846\u67b6\u548c\u8bed\u8a00\uff0c\u63d0\u4f9b\u5b9e\u65f6\u7684\u6d4b\u8bd5\u7ed3\u679c\u548c\u5206\u6790\u3002<\/p>"},{"title":"RobotFramework","link":"https:\/\/canuxcheng.com\/post\/testing_robotframework\/","pubDate":"Sat, 25 Feb 2017 09:41:39 +0000","guid":"https:\/\/canuxcheng.com\/post\/testing_robotframework\/","description":"<h1 id=\"robot-framework\">Robot Framework<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/robotframework\/robotframework\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/robotframework\/robotframework<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/robotframework\/QuickStartGuide\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/robotframework\/QuickStartGuide<\/a><\/p>\n<p>\u652f\u6301python\u548cjava\u7684API.<\/p>\n<p>Robot Framework is a generic test automation framework for acceptance testing and acceptance test-driven development (ATDD).<\/p>\n<p>Install:<\/p>\n<pre><code>$ pip install robotframework\n<\/code><\/pre>\n<p>Modular:<\/p>\n<ul>\n<li>Test Data<\/li>\n<li>Robot Framework(test data syntax)<\/li>\n<li>Test Libraries(test library API) + Test Tools<\/li>\n<li>System under Test(system interface)<\/li>\n<\/ul>\n<p>Use:<\/p>\n<pre><code>$ robot --version\n$ robot [options] data_sources\n<\/code><\/pre>\n<p>\u4f1a\u751f\u6210\u4e09\u4e2a\u6587\u4ef6\uff1a<\/p>\n<ul>\n<li>output.xml<\/li>\n<li>log.html<\/li>\n<li>report.html<\/li>\n<\/ul>\n<hr>\n<h1 id=\"setting-table\">setting table<\/h1>\n<pre><code>*** Settings ***\n# \u524d\u4e09\u4e2a\u662f\u52a0\u8f7d\u5916\u90e8\u6587\u4ef6\nLibrary Selenium2Library # \u9700\u8981\u5728sys.path\u8def\u5f84\u91cc\u9762\nResource ${RESOURCES}\/common.tsv\nVariables ${RESOURCES}\/common.py\nDocumentation Docs\nMetadata Version 2.0\nSuite Setup\nSuite Teardown\nForce Tags\nDefault Tags\nTest Setup\nTest Teardown\nTest Template\nTest Timeout\n<\/code><\/pre>\n<h1 id=\"test-case-table\">Test Case table<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/robotframework\/HowToWriteGoodTestCases\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/robotframework\/HowToWriteGoodTestCases<\/a><\/p>\n<p>test case:data_sources\u5c31\u662ftest cases files.robotframework\u6d4b\u8bd5\u7528\u4f8b\u53ef\u4ee5\u4f7f\u7528\u5e26\u53c2\u6570\u7684\u7b80\u5355\u8868\u683c\u8bed\u6cd5\uff0c\u4e5f\u53ef\u4ee5\u662f\u4e0d\u5e26\u53c2\u6570\u7684\u5173\u952e\u5b57\u8868\u683c,\u4e5f\u53ef\u4ee5\u662f\u6570\u636e\u9a71\u52a8\u6d4b\u8bd5\u7528\u4f8b.<\/p>\n<p>Test Cases\u7531keywords\u548c\u53ef\u80fd\u7684arguments\u7ec4\u6210\uff0e<\/p>\n<pre><code>*** Test Cases ***\nTest Case Name\n[Documentation] Docs\n[Tags]\n[Setup]\n[Teardown]\n[Template]\n[Timeout]\n...\n<\/code><\/pre>\n<p>Test Case\u5206\u7c7b\uff1a<\/p>\n<ul>\n<li>Workflow tests<\/li>\n<li>higher-level tests<\/li>\n<li>Data-driven tests<\/li>\n<\/ul>\n<h1 id=\"keywords-table\">Keywords table<\/h1>\n<p>key word:\u6d4b\u8bd5\u7528\u4f8b\u4f7f\u7528\u5173\u952e\u8bcd\u521b\u5efa,\u5173\u952e\u8bcd\u76842\u4e2a\u6765\u6e90\u662f\u5e93\u5173\u952e\u5b57\u548c\u7528\u6237\u5173\u952e\u5b57\uff0e<\/p>\n<pre><code>*** Keywords ***\nKeyword name\n[Documentation] docs\n[Tags]\n[Arguments]\n[Return]\n[Teardown]\n[Timeout]\n<\/code><\/pre>\n<p>Keywords\u5206\u7c7b\uff1a<\/p>\n<ul>\n<li>Library keywords<\/li>\n<li>User keywords<\/li>\n<\/ul>\n<h1 id=\"variables\">Variables<\/h1>\n<p>variables:\u6d4b\u8bd5\u7528\u4f8b\u4e2d\u53ef\u80fd\u53d8\u5316\u7684\u6570\u636e\u5b9a\u4e49\u6210\u53d8\u91cf\uff0e<\/p>\n<pre><code>*** Variables ***\n${ScalarVar} first one second one\n@{ListVar} one two\n&amp;{DictVar} key=value key1=value1\n<\/code><\/pre>\n<p>\u53d8\u91cf\u7c7b\u578b\uff1a<\/p>\n<ul>\n<li>scalar variables\u6807\u91cf<\/li>\n<li>list variables\u5217\u8868<\/li>\n<li>dictionary variables\u5b57\u5178<\/li>\n<\/ul>\n<h1 id=\"organizing-test-cases\">Organizing test cases<\/h1>\n<p>test suites:\u6d4b\u8bd5\u7528\u4f8b\u7684\u96c6\u5408\u53eb\u6d4b\u8bd5\u5957\u4ef6\uff0e\u6bcf\u4e2a\u5305\u542b\u6d4b\u8bd5\u7528\u4f8b\u7684\u8f93\u5165\u6587\u4ef6\u7ec4\u6210\u4e00\u4e2a\u6d4b\u8bd5\u5957\u4ef6\uff0e<\/p>\n<p>test setup\/suit setup: \u5728\u6d4b\u8bd5\u4e4b\u524d\u6267\u884c\u67d0\u4e9b\u5173\u952e\u8bcd\uff0e<\/p>\n<p>test teardown\/suit teardown: \u5728\u6d4b\u8bd5\u4e4b\u540e\u6267\u884c\u67d0\u4e9b\u5173\u952e\u8bcd\uff0e<\/p>\n<pre><code>*** Settings ***\nSuite Setup Action\/Keyword\nTest Setup\nSuite Teardown Action\/Keyword\nTest Teardown\n<\/code><\/pre>\n<p>tags:\u7ed9\u6d4b\u8bd5\u7528\u4f8b\u8bbe\u7f6e\u6807\u7b7e\uff0c\u4ee5\u4fbf\u7ed9\u4ed6\u4eec\u81ea\u7531\u7684\u5143\u6570\u636e\uff0e<\/p>\n<p>\u7ed9\u6d4b\u8bd5\u5957\u4ef6\u52a0\u6807\u7b7e\uff1a<\/p>\n<pre><code>*** Settings ***\nForce Tags quickstart # \u8fd9\u4e2a\u662fcase\u7684\u5f3a\u5236\u7684tag.\nDefault Tags example smoke # \u8fd9\u4e2a\u662fcase\u7684\u9ed8\u8ba4\u7684tag.\n<\/code><\/pre>\n<p>\u81ea\u5b9a\u4e49\u6807\u7b7e\u6ce8\u610f\u591a\u4e2a\u6807\u7b7e\u4e4b\u95f4\u7528\u56db\u4e2a\u7a7a\u683c\u533a\u5206\uff0e<\/p>\n<p>\u7ed9\u5355\u4e2acase\u52a0\u6807\u7b7e\uff1a<\/p>\n<pre><code># \u81ea\u5b9a\u4e49\u7684tag\u540d\u5b57\u591a\u4e2a\u5355\u8bcd\u6700\u597d\u7528-\u8fde\u63a5\uff0c\u4e0d\u8981\u7528\u7a7a\u683c\uff0e\n[Tags] Your-tags1 tag2 # \u8fd9\u4e2a\u662f\u81ea\u5b9a\u4e49\u7684tag.\n<\/code><\/pre>\n<hr>\n<h1 id=\"libraries\">Libraries<\/h1>\n<p>\u5185\u7f6e\u6807\u51c6\u5e93\u548c\u7b2c\u4e09\u65b9\u5e93\uff0c\u81ea\u5b9a\u4e49\u5e93\u90fd\u53ef\u4ee5\u4f5c\u4e3akeywords.<\/p>\n<p>robotframework\u7684\u5f3a\u5927\u4e4b\u5904\u5728\u4e8e\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u8981\u5f00\u53d1\u81ea\u5df1\u7684\u5e93\uff0e<\/p>\n<h2 id=\"standardbuild-in-libraries\">standard(build-in libraries)<\/h2>\n<ul>\n<li>\n<p>BuiltIn<\/p>\n<p>\u5185\u7f6e\u6807\u51c6\u5e93\uff0c\u9ed8\u8ba4\u552f\u4e00\u81ea\u52a8\u52a0\u8f7d\u7684\u5e93\uff0e\u5176\u5b83\u7684\u5e93\u90fd\u9700\u8981\u624b\u52a8\u52a0\u8f7d\uff0e<\/p>\n<pre><code> # Comment\u5173\u952e\u5b57\u7528\u6765\u6ce8\u91ca\uff0e\nComment this is comment\n# Evaluate\u5173\u952e\u5b57\u7528\u6765\u8c03\u7528python\u7a0b\u5e8f\uff0e\n${var} Evaluate random.randint(1000, 999) random\n# Import Library\u5173\u952e\u5b57\u7528\u6765\u5bfc\u5165python\u6a21\u5757\uff0e\nImport Library mytest.py\n<\/code><\/pre>\n<\/li>\n<li>\n<p>Collections<\/p>\n<\/li>\n<li>\n<p>DateTime<\/p>\n<\/li>\n<li>\n<p>Dialogs<\/p>\n<\/li>\n<li>\n<p>Easter<\/p>\n<\/li>\n<li>\n<p>OperatingSystem<\/p>\n<\/li>\n<li>\n<p>Process<\/p>\n<\/li>\n<li>\n<p>Remote<\/p>\n<\/li>\n<li>\n<p>Screenshot<\/p>\n<p>\u7528\u4e8e\u6d4b\u8bd5\u8fc7\u7a0b\u4e2d\u7684\u622a\u5c4f\uff0e<\/p>\n<pre><code> # Take Screenshot\u5173\u952e\u5b57\u7528\u6765\u622a\u5c4f\nTake Screenshot\n<\/code><\/pre>\n<\/li>\n<li>\n<p>String<\/p>\n<\/li>\n<li>\n<p>Telnet<\/p>\n<\/li>\n<li>\n<p>XML<\/p>\n<\/li>\n<\/ul>\n<h2 id=\"external\">External<\/h2>\n<ul>\n<li>\n<p>selenium2library<\/p>\n<p>\u7528\u4e8eweb\u81ea\u52a8\u5316\u6d4b\u8bd5\uff0e\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5b9a\u4f4d\u5668\uff0c\u5305\u62ecid,name, xpath, css.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/robotframework\/Selenium2Library\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/robotframework\/Selenium2Library<\/a><\/p>\n<p>Install:<\/p>\n<pre><code> $ pip install robotframework-selenium2library\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<h2 id=\"other\">other<\/h2>\n<hr>\n<h1 id=\"tools\">Tools<\/h1>\n<p>robot framework\u76f8\u5173\u7684\u5de5\u5177\uff0e<\/p>\n<h2 id=\"build-in-tools\">build-in tools<\/h2>\n<ul>\n<li>\n<p>Rebot<\/p>\n<\/li>\n<li>\n<p>Testdoc<\/p>\n<\/li>\n<li>\n<p>Libdoc<\/p>\n<\/li>\n<li>\n<p>Tidy<\/p>\n<\/li>\n<\/ul>\n<h2 id=\"editors\">editors<\/h2>\n<ul>\n<li>\n<p>RIDE<\/p>\n<p>robot framework\u7684IDE.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/robotframework\/RIDE\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/robotframework\/RIDE<\/a><\/p>\n<p>Install:<\/p>\n<pre><code> # Only wxPython 2.8.12.1 with Unicode support is officially supported\n$ pip install robotframework-ride\n<\/code><\/pre>\n<p>Usage:<\/p>\n<pre><code> # \u6dfb\u52a0windows\u7684\u684c\u9762\uff1a\n# C:\\Python27\\python.exe -c &quot;from robotide import main; main()&quot;\n# C:\\Python27\\Lib\\site-packages\\robotide\\widgets\\robot.ico\n&gt; ride.py\n$ ride.py\n# F5\u641c\u7d22\u5173\u952e\u5b57\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<h2 id=\"build\">build<\/h2>\n<h2 id=\"other-1\">other<\/h2>\n<hr>\n<h1 id=\"robot-command\">robot command<\/h1>\n<pre><code>$ robot tests.robot\n$ robot -t\/--test [test cases] tests.robot\n$ robot -t My*test*case* tests.robot # \u4f8b\u5982case\u53ebMy test case just for test.\n$ robot -s\/--suite [test suites] tests.robot\n$ robot -i\/--include [tags] tests.robot\n$ robot -i My-test-tag tests.robot # \u4f8b\u5982tag\u53ebMy-test-tag.\n$ robot -e\/--exclude [tags] tests.robot\n-d --outputdir dir # \u5b58\u653eoutput, log, report\u6587\u4ef6\u7684\u8def\u5f84.\n-o --output file\n-l --log file\n-r --report file\n-W --consolewidth chars\n-C --consolecolors auto|on|ansi|off\n-K --consolemarkers auto|on|off\n-L --loglevel level # \u683c\u5f0fLOGLEVEL:DEFAULT, \u53ef\u9009TRACE, DEBUG, INFO (default), WARN, NONE\n# DEFAULT\u662flog file\u4e2d\u9ed8\u8ba4\u663e\u793a\u7684\u65e5\u5fd7\u7ea7\u522b\n-b --debugfile # \u5b58\u653edebug log\u7684\u6587\u4ef6\uff0e\n-T --timestampoutputs # \u8868\u793a\u6240\u6709\u5728outputdir\u91cc\u9762\u7684\u6587\u4ef6\u90fd\u81ea\u52a8\u52a0\u65f6\u95f4\u6233\uff0e\n-P --pythonpath path * # \u6307\u5b9aPYTHONPATH, \u53ef\u4ee5\u6307\u5b9a\u6b63\u5728\u5f00\u53d1\u7684\u5e93\u7528\u6765\u6d4b\u8bd5\uff0c\u800c\u4e0d\u9700\u8981\u5b89\u88c5\u5230site-packages.\n<\/code><\/pre>\n<hr>\n<h1 id=\"library\">Library<\/h1>\n<p>robotframework\u7684\u7075\u6d3b\u5c31\u5728\u4e8e\u53ef\u4ee5\u81ea\u5df1\u5f00\u53d1\u7b2c\u4e09\u65b9\u5e93\uff0c\u5b9e\u73b0\u548c\u81ea\u5df1\u4e1a\u52a1\u76f8\u5173\u7684\u5173\u952e\u5b57\uff0e<\/p>\n<p>\u5728robot\u4e2d\u5bfc\u5165\u7684\u8fd9\u4e2a\u5e93\u5fc5\u987b\u5728sys.path\u8def\u5f84\u91cc\u9762\uff0e<\/p>\n<p>\u5e93API\u7684\u4e09\u79cd\u7c7b\u578b\uff1a \u9759\u6001\u5e93, \u52a8\u6001\u5e93, \u6df7\u5408\u5e93.<\/p>\n<p>\u4ee5Selenium2Library\u4e3a\u4f8b\uff1a<\/p>\n<pre><code>Selenium2Library\n|-- docs\n|-- tests\n|-- Selenium2Library\n|-- __init__.py\n|-- keywords\/*.py\n|-- ...\n|-- setup.py\n|-- ...\n$ pip install robotframework-selenium2library\n# C:\\Python27\\Lib\\site-packages\\Selenium2Library\n# \/usr\/local\/lib\/python2.7\/dist-packages\/Selenium2Library\n# \u901a\u8fc7ride\u5bfc\u5165\u8be5\u5e93\u540e\uff0c\u53ef\u4ee5\u7528F5\u67e5\u770b\u5173\u952e\u5b57\u7684\u5e2e\u52a9.\n# __init__.py\n# \u4e00\u4e2a\u7c7b\u7ee7\u627f\u6240\u6709\u5173\u952e\u5b57\u6240\u5728\u7684\u7c7b\uff0erf\u901a\u8fc7\u5bfc\u5165\u8fd9\u4e2a\u7c7b\u5bfc\u5165\u6240\u6709\u5173\u952e\u5b57\uff0e\nfrom .keywords import *\nfrom .utils import LibraryListener\n...\n__version__ = 1.0.0\nclass Selenium2Library(keywords):\n&quot;&quot;&quot;docs.&quot;&quot;&quot;\nROBOT_LIBRARY_SCOPE = 'GLOBAL'\nROBOT_LIBRARY_VERSION = __version__\ndef __init__(self, ...):\n&quot;&quot;&quot;docs&quot;&quot;&quot;\nself.ROBOT_LIBRARY_LISTENER = LibraryListener()\n...\n<\/code><\/pre>\n<h1 id=\"static-librarty-api\">Static librarty API<\/h1>\n<p>\u4f7f\u7528\u4e00\u4e2a\u6a21\u5757\u6216\u4e00\u4e2a\u7c7b\uff0c\u65b9\u6cd5\u76f4\u63a5\u6620\u5c04\u5230\u5173\u952e\u5b57\u540d\u79f0\uff0e\u9759\u6001API\u662f\u6700\u57fa\u672c\u6700\u5e38\u7528\u7684\uff0e<\/p>\n<p>robotframework\u5728\u7c7b\u548c\u6a21\u5757\u4e2d\u5bfb\u627e\u5173\u952e\u5b57\u5bf9\u5e94\u7684\u65b9\u6cd5\uff0c\u4f1a\u5ffd\u7565\u5355\u4e0b\u5212\u7ebf\u6216\u53cc\u4e0b\u5212\u7ebf\u5f00\u5934\u7684\u65b9\u6cd5\uff0e<\/p>\n<p>robotframework\u5728\u7c7b\u4e2d\u5bfb\u627e\u5173\u952e\u5b57\u5bf9\u5e94\u7684\u65b9\u6cd5\uff0c\u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff0c\u4f1a\u81ea\u52a8\u5ffd\u7565\u7a7a\u683c\u548c\u4e0b\u5212\u7ebf\uff0e<\/p>\n<p>robotframework\u6d4b\u8bd5\u5e93\u5b9e\u73b0\u4e3a\u7c7b\u65f6\uff0c\u57fa\u7c7b\u4e2d\u7684\u65b9\u6cd5\u4e5f\u88ab\u8bc6\u522b\u4e3a\u5173\u952e\u5b57\uff0e<\/p>\n<p>robotframework\u6d4b\u8bd5\u5e93\u5b9e\u73b0\u4e3a\u6a21\u5757\u65f6\uff0c\u5bfc\u5165\u7684\u6a21\u5757\u7684\u547d\u540d\u7a7a\u95f4\u7684\u53ef\u80fd\u51fd\u6570\u4e5f\u88ab\u8bc6\u522b\u4e3a\u5173\u952e\u5b57\uff0e\u6b64\u65f6\u8981\u9632\u6b62\u5bfc\u5165\u7684\u5e93\u4e2d\u7684\u65b9\u6cd5\u6210\u4e3a\u5173\u952e\u5b57\uff0e<\/p>\n<p>\u5173\u952e\u5b57\u8dd1\u51fa\u5f02\u5e38\uff0c\u8be5\u5173\u952e\u5b57\u72b6\u6001\u5c31\u662ffailed,\u5426\u5219\u5c31\u662fpass.<\/p>\n<h1 id=\"dylamic-library-api\">dylamic library API<\/h1>\n<p>\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u52a8\u6001\u786e\u5b9a\u8981\u5b9e\u73b0\u7684\u5173\u952e\u5b57\u7684\u540d\u79f0\u4ee5\u53ca\u6267\u884c\u65b9\u6cd5\uff0e<\/p>\n<h1 id=\"hybird-library-api\">hybird library API<\/h1>\n<p>\u9759\u6001\u548c\u52a8\u6001\u90fd\u6709\u7684\u65b9\u5f0f\uff0e<\/p>\n<h1 id=\"\u6d4b\u8bd5\u5e93\u8303\u56f4\">\u6d4b\u8bd5\u5e93\u8303\u56f4<\/h1>\n<p>\u8981\u786e\u4fdd\u4e00\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u5bf9\u72b6\u6001\u7684\u66f4\u6539\u4e0d\u4f1a\u5f71\u54cd\u5176\u5b83\u7528\u4f8b\uff0e<\/p>\n<p>\u6d4b\u8bd5\u5e93\u53ef\u4ee5\u63a7\u5236\u4f55\u65f6\u4f7f\u7528\u7c7b\u5c5e\u6027\u521b\u5efa\u65b0\u5e93\uff0e<\/p>\n<pre><code>ROBOT_LIBRARY_SCOPE\n# Global: \u53ea\u6709\u4e00\u4e2ainstance\u521b\u5efa\uff0c\u5e76\u4e14\u6240\u6709test cases\u5171\u4eab\uff0e\n# TEST CASE: \u4e3a\u6bcf\u4e2atest case\u521b\u5efa\u4e00\u4e2ainstance.\n# TEST SUITE: \u4e3a\u6bcf\u4e2atest suite\u521b\u5efa\u4e00\u4e2ainstance.\n<\/code><\/pre>\n<h1 id=\"\u6d4b\u8bd5\u5e93\u7248\u672c\">\u6d4b\u8bd5\u5e93\u7248\u672c<\/h1>\n<pre><code>ROBOT_LIBRARY_VERSION\n<\/code><\/pre>\n<h1 id=\"\u6307\u5b9a\u6587\u6863\u683c\u5f0f\">\u6307\u5b9a\u6587\u6863\u683c\u5f0f<\/h1>\n<pre><code>ROBOT_LIBRARY_DOC_FORMAT\n# reST: \u9700\u8981\u5b89\u88c5docutils\u6a21\u5757\n# ROBOT: \u9ed8\u8ba4\u7684html\u683c\u5f0f\n# TEXT:\u3000\u7eaf\u6587\u672c\u683c\u5f0f\n<\/code><\/pre>\n<hr>\n<h1 id=\"listener\">Listener<\/h1>\n<p>Listener\u76d1\u542c\u5668\u63a5\u53e3\u5141\u8bb8\u5916\u90e8\u76d1\u542c\u5668\u83b7\u53d6\u5173\u4e8e\u6d4b\u8bd5\u6267\u884c\u7684\u901a\u77e5\uff0e<\/p>\n<p>\u540c\u540d\u7684\u9ed8\u8ba4\u65b9\u6cd5\u4f1a\u5148\u8c03\u7528\uff0c\u7136\u540e\u8c03\u7528\u81ea\u5b9a\u4e49\u7684\u65b9\u6cd5\uff0e<\/p>\n<p>\u53ef\u4ee5\u5b9e\u73b0\u7684\u65b9\u6cd5\u6709\uff1a<\/p>\n<pre><code>start_suite(name, attribute)\/end_suite(name, attribute) # test suite\u5f00\u59cb\/\u7ed3\u675f\u7684\u65f6\u5019\u8c03\u7528\nstart_test(name, attribute)\/end_test(name, attribute) # test case\u5f00\u59cb\/\u7ed3\u675f\u7684\u65f6\u5019\u8c03\u7528\nstart_keyword(name, attributes)\/end_keyword(name, attribute) # keyword\u5f00\u59cb\/\u7ed3\u675f\u7684\u65f6\u5019\u8c03\u7528\nclose() # \u76f8\u5f53\u4e8eteardown.\nlog_message(message) # \u5f53\u6267\u884c\u7684keyword\u5199log\u7684\u65f6\u5019\u8c03\u7528\nmessage(message) # \u5f53framework\u5199system log\u7684\u65f6\u5019\u8c03\u7528\n...\n<\/code><\/pre>\n<p><a class=\"link\" href=\"http:\/\/robotframework.org\/robotframework\/latest\/RobotFrameworkUserGuide.html#listener-interface-methods\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/robotframework.org\/robotframework\/latest\/RobotFrameworkUserGuide.html#listener-interface-methods<\/a><\/p>\n<pre><code># librarylistener.py\n# rf\u7684\u5916\u90e8\u76d1\u542c\u7a0b\u5e8f\nfrom robot.api import logger\n...\nclass LibraryListener(object):\n&quot;&quot;&quot;docs&quot;&quot;&quot;\n# version 2 for rf&gt;=2.1\n# version 3 for rf&gt;=3.0\nROBOT_LISTENER_API_VERSION = 2\n<\/code><\/pre>\n<hr>\n<h1 id=\"allure\">allure<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/allure-framework\/allure-python\/tree\/master\/allure-robotframework\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/allure-framework\/allure-python\/tree\/master\/allure-robotframework<\/a><\/p>\n<pre><code>$ pip install allure-robotframework\n$ robot --listener allure_robotframework .\/my_robot_test\n$ robot --listener allure_robotframework:\/set\/your\/path\/here .\/my_robot_test\nallure generate output\/allure\nallure serve output\/allure\n<\/code><\/pre>\n<h1 id=\"reportportal\">reportportal<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/reportportal\/plugin-import-robot\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/reportportal\/plugin-import-robot<\/a><\/p>"},{"title":"Selenium","link":"https:\/\/canuxcheng.com\/post\/testing_selenium\/","pubDate":"Sat, 25 Feb 2017 09:41:39 +0000","guid":"https:\/\/canuxcheng.com\/post\/testing_selenium\/","description":"<h1 id=\"selenium\">Selenium<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/SeleniumHQ\/selenium\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/SeleniumHQ\/selenium<\/a><\/p>\n<p>\u7528\u4e8e\u57fa\u4e8e\u6d4f\u89c8\u5668\u7684web\u5e94\u7528\u7684\u81ea\u52a8\u5316\u6d4b\u8bd5\u5de5\u5177\u96c6\uff0e<\/p>\n<pre><code>selenium1: deprecated.\nselenium2: \u9ed8\u8ba4\u652f\u6301firefox&lt;=46. \u652f\u6301python2.6+, python3.2+\nselenium3: \u652f\u6301firefox47+, \u6240\u6709\u6d4f\u89c8\u5668\u90fd\u9700\u8981\u5b89\u88c5webdriver.\u652f\u6301python2.6+, python3.3+, \u5fc5\u987b\u91cd\u542fOS.\n<\/code><\/pre>\n<p>\u652f\u6301python, java, javascript\u7b49API.<\/p>\n<p>\u9ed8\u8ba4\u5b89\u88c5selenium3:<\/p>\n<pre><code>$ pip install selenium\n<\/code><\/pre>\n<p>selenium3\u9700\u8981\u5b89\u88c5\u76f8\u5e94\u6d4f\u89c8\u5668\u7684driver, \u7136\u540e\u91cd\u542fOS:<\/p>\n<p>selenium, driver, browser\u4e09\u4e2a\u7248\u672c\u90fd\u9700\u8981\u517c\u5bb9\u624d\u80fd\u5de5\u4f5c\uff0e<\/p>\n<pre><code>winfows\u653e\u5728C:\\Python\\Scripts\\\nlinux\u653e\u5728\/usr\/local\/bin\/\n<\/code><\/pre>\n<p><a class=\"link\" href=\"https:\/\/sites.google.com\/a\/chromium.org\/chromedriver\/downloads\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/sites.google.com\/a\/chromium.org\/chromedriver\/downloads<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/mozilla\/geckodriver\/releases\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/mozilla\/geckodriver\/releases<\/a><\/p>\n<p>[Deprecated] Remote Control: \u4e5f\u5c31\u662fselenium1.selenium2\u4f9d\u7136\u4fdd\u7559\u4e86selenium1\u7684API.\u4f46\u662fselenium3\u4f1a\u5f7b\u5e95\u5220\u9664RC\u7684API.<\/p>\n<p>[Deprecated] IDE: selenium IDE\u662f\u4e00\u4e2afirefox\u7684\u63d2\u4ef6\uff0c\u7528\u4e8e\u8bb0\u5f55\u6d4f\u89c8\u5668\u4e0a\u7684\u6d4b\u8bd5\u6b65\u9aa4\uff0c\u80fd\u7528\u4e8e\u751f\u6210\u6d4b\u8bd5\u4ee3\u7801\uff0c\u5e76\u4e14\u8f6c\u6362\u6210\u7f16\u7a0b\u8bed\u8a00\uff0e\u4f46\u662f\u5df2\u7ecf\u88abWebDriver\u53d6\u4ee3\uff0e<\/p>\n<hr>\n<h1 id=\"webdriver\">WebDriver<\/h1>\n<p>\u4e5f\u5c31\u662fselenium2.\u5df2\u7ecf\u53d6\u4ee3\u4e86selenium RC\u548cselenium IDE.<\/p>\n<p>python\u7684API\u53c2\u8003python\u535a\u5ba2\uff0e<\/p>\n<hr>\n<h1 id=\"grid\">Grid<\/h1>\n<p>Selenium Grid\u7528\u4e8e\u5206\u5e03\u5f0f\u6d4b\u8bd5<\/p>\n<hr>\n<h1 id=\"\u5b9a\u4f4d\u5143\u7d20\">\u5b9a\u4f4d\u5143\u7d20<\/h1>\n<p>\u5bf9\u5e94\u7684python\u7684API\u53c2\u8003python\u535a\u6587\uff0e<\/p>\n<p>selenium\u63d0\u4f9b\uff18\u79cd\u5b9a\u4f4dweb\u9875\u9762\u4e2d\u5143\u7d20\u7684\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>id<\/li>\n<li>name<\/li>\n<li>class<\/li>\n<li>tag<\/li>\n<li>link<\/li>\n<li>partial_link<\/li>\n<li>\u901a\u8fc7xpath<\/li>\n<li>\u901a\u8fc7css<\/li>\n<\/ul>\n<p>\u5728\u6d4f\u89c8\u5668\u901a\u8fc7F12\u5feb\u6377\u952e\u8fdb\u5165\u8c03\u8bd5\u6a21\u5f0f\u83b7\u53d6\uff0e<\/p>"},{"title":"OpenStack","link":"https:\/\/canuxcheng.com\/post\/cloud_openstack\/","pubDate":"Thu, 23 Feb 2017 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/cloud_openstack\/","description":"<h1 id=\"openstack\">OpenStack<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/openstack\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/openstack<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/openstack-dev\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/openstack-dev<\/a><\/p>\n<p>openstack\u662f\u4e00\u4e2a\u4e91\u64cd\u4f5c\u7cfb\u7edf\uff0c\u901a\u8fc7\u6570\u636e\u4e2d\u5fc3\u53ef\u63a7\u5236\u5927\u578b\u7684\u8ba1\u7b97\uff0c\u5b58\u50a8\uff0c\u7f51\u7edc\u7b49\u8d44\u6e90\u6c60\uff0e<\/p>\n<p>\u6240\u6709\u7684\u7ba1\u7406\u901a\u8fc7\u524d\u7aef\u7684\u754c\u9762\u7ba1\u7406\u5458\u5c31\u53ef\u4ee5\u5b8c\u6210\uff0c\u540c\u6837\u4e5f\u53ef\u4ee5\u901a\u8fc7web\u63a5\u53e3\u8ba9\u6700\u7ec8\u7684\u7528\u6237\u90e8\u7f72\u8d44\u6e90\uff0e<\/p>\n<p>openstack\u7684\u8bbe\u8ba1\u539f\u5219\uff1a<\/p>\n<p><a class=\"link\" href=\"https:\/\/wiki.openstack.org\/wiki\/BasicDesignTenets\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/wiki.openstack.org\/wiki\/BasicDesignTenets<\/a><\/p>\n<hr>\n<h1 id=\"horizon---openstack-dashboard\">horizon - OpenStack Dashboard<\/h1>\n<p>\u63a7\u5236\u9762\u677f<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/openstack\/horizon\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/openstack\/horizon<\/a><\/p>\n<hr>\n<h1 id=\"keystone---openstack-identity\">keystone - OpenStack Identity<\/h1>\n<p>\u8ba4\u8bc1\u670d\u52a1<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/openstack\/keystone\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/openstack\/keystone<\/a><\/p>\n<hr>\n<h1 id=\"nova---openstack-compute\">nova - OpenStack Compute<\/h1>\n<p>\u8ba1\u7b97\u670d\u52a1<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/openstack\/nova\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/openstack\/nova<\/a><\/p>\n<hr>\n<h1 id=\"swift---openstack-storage\">swift - OpenStack Storage<\/h1>\n<p>\u5b58\u50a8\u670d\u52a1<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/openstack\/swift\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/openstack\/swift<\/a><\/p>\n<hr>\n<h1 id=\"neutron---openstack-networking\">neutron - OpenStack Networking<\/h1>\n<p>\u7f51\u7edc\u670d\u52a1(\u539f\u540dquantum)<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/openstack\/neutron\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/openstack\/neutron<\/a><\/p>\n<hr>\n<h1 id=\"glance---openstack-image-management\">glance - OpenStack Image Management<\/h1>\n<p>\u955c\u50cf\u7ba1\u7406<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/openstack\/glance\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/openstack\/glance<\/a><\/p>\n<hr>\n<h1 id=\"cinder---openstack-block-storage\">cinder - OpenStack Block Storage<\/h1>\n<p>\u5757\u5b58\u50a8\u670d\u52a1<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/openstack\/cinder\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/openstack\/cinder<\/a><\/p>\n<hr>"},{"title":"Makefile","link":"https:\/\/canuxcheng.com\/post\/linux_makefile\/","pubDate":"Thu, 12 Jan 2017 21:18:33 +0000","guid":"https:\/\/canuxcheng.com\/post\/linux_makefile\/","description":"<h1 id=\"make\">Make<\/h1>\n<p>make\u7684\u4f5c\u7528\uff1a<\/p>\n<ul>\n<li>\u63a7\u5236\u6e90\u4ee3\u7801\u7684\u7f16\u8bd1<\/li>\n<li>\u624b\u518c\u9875\u7684\u7f16\u5199<\/li>\n<li>\u5c06\u5e94\u7528\u7a0b\u5e8f\u5b89\u88c5\u5230\u76ee\u6807\u76ee\u5f55<\/li>\n<\/ul>\n<p>make\u7684\u4f7f\u7528\u89c4\u5219\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u5de5\u7a0b\u6ca1\u6709\u7f16\u8bd1\u8fc7\uff0c\u9700\u8981\u7f16\u8bd1\u6240\u6709\u6e90\u6587\u4ef6\u548c\u94fe\u63a5\u6240\u6709\u76ee\u6807\u6587\u4ef6\uff0e<\/li>\n<li>\u5982\u679c\u5de5\u7a0b\u91cc\u67d0\u51e0\u4e2a\u76ee\u6807\u6587\u4ef6\u88ab\u4fee\u6539\uff0c\u53ea\u9700\u8981\u7f16\u8bd1\u4fee\u6539\u7684\u6e90\u6587\u4ef6\uff0c\u5e76\u94fe\u63a5\u6240\u6709\u76ee\u6807\u6587\u4ef6\uff0e<\/li>\n<li>\u5982\u679c\u5934\u6587\u4ef6\u88ab\u4fee\u6539\uff0c\u53ea\u9700\u8981\u7f16\u8bd1\u5f15\u7528\u4e86\u88ab\u4fee\u6539\u7684\u5934\u6587\u4ef6\u7684\u6e90\u6587\u4ef6\uff0c\u5e76\u94fe\u63a5\u6240\u6709\u76ee\u6807\u6587\u4ef6\uff0e<\/li>\n<\/ul>\n<p>makefile\u6587\u4ef6\u67e5\u627e\u987a\u5e8f\uff1a<\/p>\n<ul>\n<li>\u5f53\u524d\u76ee\u5f55\u627emakefile<\/li>\n<li>\u5f53\u524d\u76ee\u5f55\u627eMakefile<\/li>\n<li>\u5f53\u524d\u76ee\u5f55\u627eGNUmakefile<\/li>\n<\/ul>\n<h1 id=\"make\u547d\u4ee4\">make\u547d\u4ee4<\/h1>\n<p>make\u547d\u4ee4\u4f1a\u6267\u884c\u5f53\u524d\u76ee\u5f55\u7684makefile\/Makefile\/GNUmakefile\u6587\u4ef6\uff0e<\/p>\n<pre><code>make [options] [target] ...\n-f FILE, --file=FILE, --makefile=FILE # \u6307\u5b9amakefile\u6587\u4ef6\n-n, --just-print, --dry-run, --recon # \u53ea\u6253\u5370\uff0c\u4e0d\u6267\u884c\n-k, --keep-going\u3000# \u5ffd\u7565\u9519\u8bef\u7ee7\u7eed\u6267\u884c\nmake\nmake all\nmake install\nmake clean\n<\/code><\/pre>\n<p>make\u7684\u5de5\u4f5c\u987a\u5e8f\uff1a<\/p>\n<ul>\n<li>\u8bfb\u5165\u6240\u6709makefile\u6587\u4ef6<\/li>\n<li>\u8bfb\u5165include\u7684\u5176\u5b83makefile\u6587\u4ef6<\/li>\n<li>\u521d\u59cb\u5316\u53d8\u91cf<\/li>\n<li>\u63a8\u5bfc\u9690\u6666\u89c4\u5219\uff0c\u5206\u6790\u6240\u6709\u89c4\u5219<\/li>\n<li>\u4e3a\u6240\u6709\u76ee\u6807\u6587\u4ef6\u521b\u5efa\u4f9d\u8d56\u5173\u7cfb\u94fe<\/li>\n<li>\u6839\u636e\u4f9d\u8d56\u5173\u7cfb\u51b3\u5b9a\u54ea\u4e9b\u76ee\u6807\u9700\u8981\u91cd\u65b0\u751f\u6210<\/li>\n<li>\u6267\u884c\u751f\u6210\u7684\u547d\u4ee4<\/li>\n<\/ul>\n<h1 id=\"makefile\u8bed\u6cd5\">makefile\u8bed\u6cd5<\/h1>\n<p>make\u547d\u4ee4\u6267\u884cmakefile\u6587\u4ef6\u65f6\uff0c\u4f1a\u6bd4\u8f83target\u548cprerequisites\u7684\u65f6\u95f4\u6233\uff0c\u5982\u679c\u540e\u8005\u6bd4\u524d\u8005\u65b0\uff0c\u6216\u8005\u524d\u8005\u4e0d\u5b58\u5728\uff0c\u5c31\u4f1a\u6267\u884ccommand,\u5426\u5219\u4f1a\u8df3\u8fc7command.<\/p>\n<p>\u5176\u4e2d#\u8868\u793a\u6ce8\u91ca\uff0c\\\u8868\u793a\u7eed\u884c\uff0e@\u8868\u793a\u8be5\u547d\u4ee4\u7684\u6267\u884c\u4e0d\u4f1a\u6253\u5370\u5230stdout,-\u8868\u793a\u5ffd\u7565\u9519\u8bef\u7ee7\u7eed\u6267\u884c\uff0e<\/p>\n<p>makefile\u4e2d\u7684command\u5fc5\u987b\u4ee5tab\u5f00\u5934\uff0ctarget\u548cprerequisites\u6709\u591a\u4e2a\u65f6\u7528\u7a7a\u683c\u5206\u5f00\uff0e<\/p>\n<pre><code># comment\ntarget...: prerequisites...\ncommand\ncommand1 too \\\nlong\n@command2\n-command3\n...\n<\/code><\/pre>\n<p>makefile\u53d8\u91cf\u8d4b\u503c:<\/p>\n<pre><code>var=val\nvar := val \u8986\u76d6\u4e4b\u524d\u7684\u503c\nvar ?= val \u5982\u679c\u6ca1\u6709\u88ab\u8d4b\u503c\u8fc7\uff0c\u5c31\u8d4b\u503c\nvar += val \u6dfb\u52a0\u4e00\u4e2a\u503c\n<\/code><\/pre>\n<p>\u901a\u8fc7\u547d\u4ee4\u5b9a\u4e49\u53d8\u91cf\uff1a<\/p>\n<pre><code>var := $(shell &lt;command&gt;)\n\u4e3a\u4e86\u533a\u5206makefile\u53d8\u91cf\u548cshell\u547d\u4ee4\u91cc\u9762\u7684\u53d8\u91cf\uff0c\u7528$$var\u8868\u793ashell\u53d8\u91cf\nvar := $(shell cat file | awk '\/.*\/{print $$0}')\n<\/code><\/pre>\n<p>makefile\u7684\u53d8\u91cf\uff1a<\/p>\n<pre><code>\u5b9a\u4e49\u53d8\u91cf\uff1a\nobj=a.o b.o c.o\n\u4f7f\u7528\u53d8\u91cf\uff1a\n$(obj)\n<\/code><\/pre>\n<p>\u81ea\u52a8\u5316\u53d8\u91cf\uff1a<\/p>\n<pre><code>$&lt; # \u7b2c\u4e00\u4e2a\u4f9d\u8d56\u6587\u4ef6\n$^ # \u6240\u6709\u7684\u4f9d\u8d56\u6587\u4ef6\n$@ # \u76ee\u6807\u6587\u4ef6\n$* # \u4e0d\u5305\u542b\u6269\u5c55\u540d\u7684\u76ee\u6807\u6587\u4ef6\u540d\u79f0\n$+ # \u6240\u6709\u7684\u4f9d\u8d56\u6587\u4ef6\uff0c\u7528\u7a7a\u683c\u5206\u5f00\n$? # \u6240\u6709\u65f6\u95f4\u6233\u6bd4\u76ee\u6807\u6587\u4ef6\u665a\u7684\u4f9d\u8d56\u6587\u4ef6\uff0c\u4ee5\u7a7a\u683c\u5206\u5f00\n$% # \u5982\u679c\u76ee\u6807\u662f\u5f52\u6863\u6210\u5458\uff0c\u5219\u8868\u793a\u76ee\u6807\u7684\u5f52\u6863\u6210\u5458\n<\/code><\/pre>\n<p>\u6e05\u7a7a\u76ee\u6807\u6587\u4ef6\uff1a<\/p>\n<pre><code>clean:\n-rm elf $(obj)\n# \u6216\u8005\u7528.PHONY\u8868\u793aclean\u662f\u4e00\u4e2a\u4f2a\u76ee\u6807\n.PHONY: clean\nclean:\n-rm elf $(obj)\n<\/code><\/pre>\n<p>\u5728makefile\u4e2d\u5f15\u7528\u5916\u90e8makefile:<\/p>\n<pre><code># \u4f18\u5148\u5728\u5f53\u524d\u76ee\u5f55\u67e5\u627e\uff0c-l\u53ef\u4ee5\u6307\u5b9a\u989d\u5916\u7684\u67e5\u627e\u8def\u5f84\n-include a.makefile b.makefile ...\n<\/code><\/pre>\n<p>makefile\u652f\u6301\u7684\u901a\u914d\u7b26\uff1a<\/p>\n<pre><code>~ # \u7528\u6765\u8868\u793a$HOME\u73af\u5883\u53d8\u91cf\n* # \u7528\u6765\u8868\u793a\u4efb\u610f\u957f\u5ea6\u5b57\u7b26\u4e32\n[...]\n<\/code><\/pre>\n<p>\u81ea\u52a8\u63a8\u5bfc\u548c\u9690\u6666\u89c4\u5219\uff1a<\/p>\n<p>\u4f2a\u76ee\u6807\uff1a<\/p>\n<p>\u67e5\u627e\u8def\u5f84\uff1a<\/p>"},{"title":"Grafana","link":"https:\/\/canuxcheng.com\/post\/devops_grafana\/","pubDate":"Thu, 12 Jan 2017 21:05:48 +0000","guid":"https:\/\/canuxcheng.com\/post\/devops_grafana\/","description":"<h1 id=\"grafana\">Grafana<\/h1>\n<p>The tool for beautiful monitoring and metric analytics &amp; dashboards for Graphite, InfluxDB &amp; Prometheus &amp; More.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/grafana\/grafana\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/grafana\/grafana<\/a><\/p>\n<p>\u652f\u6301\u591a\u79cddata source:<\/p>\n<p>graphite\/influxdb\/opentsdb\/premetheus\/elasticsearch\/mysql\/postgresql<\/p>\n<p>\u5b89\u88c5\u914d\u7f6e\u53c2\u8003\u5b98\u65b9\u6587\u6863<\/p>\n<p>grafana\u914d\u7f6e\u6587\u4ef6\u662fgrafana.ini.<\/p>\n<hr>\n<h1 id=\"http-api\">HTTP API<\/h1>\n<pre><code>port = 3000\n<\/code><\/pre>\n<h2 id=\"dashboard\">dashboard<\/h2>\n<p>create\/update dashboard:<\/p>\n<p>\u5c06datasource\u8bbe\u7f6e\u6210\u53d8\u91cf\uff0c\u7136\u540e\u5bfc\u51fa\u7684json\u6587\u4ef6\u5c31\u53ef\u4ee5\u76f4\u63a5\u5bfc\u5165\u4e86\uff0e<\/p>\n<p>dashboard.id=null\u624d\u80fd\u521b\u5efa\u65b0dashboard.<\/p>\n<pre><code>post \/api\/dashboards\/db\ndata = json.dumps({\n&quot;dashboard&quot;: {\n&quot;id&quot;: null,\n...\n},\n&quot;folderId&quot;: 0,\n&quot;overwrite&quot;: True, # True for python, true for go.\n&quot;message&quot;: &quot;commit message&quot;\n})\n<\/code><\/pre>\n<h2 id=\"datasource\">datasource<\/h2>\n<p>create datasource:<\/p>\n<pre><code>post \/api\/datasources\ndata = json.dumps({\n&quot;name&quot;:\n&quot;type&quot;:\n&quot;url&quot;:\n&quot;database&quot;:\n&quot;access&quot;: &quot;proxy&quot;\n})\n<\/code><\/pre>\n<h2 id=\"alert\">alert<\/h2>\n<p>create alert notification\/channel:<\/p>\n<pre><code>post \/api\/alert-notifications\ndata = json.dumps({\n&quot;name&quot;:\n&quot;type&quot;: &quot;email&quot;,\n&quot;isDefault&quot;: true,\n&quot;settings&quot;: {\n&quot;addresses&quot;: &quot;a.com; b.com&quot;,\n&quot;uploadImage&quot;: true\n}\n})\n<\/code><\/pre>\n<hr>\n<h1 id=\"dashboard-1\">Dashboard<\/h1>\n<p>graph<\/p>\n<p>singlestat<\/p>\n<p>table<\/p>\n<p>text<\/p>\n<p>heatmap<\/p>\n<p>alertlist<\/p>\n<h2 id=\"templating\">templating<\/h2>\n<p>\u5b9a\u4e49\u53d8\u91cf\uff1a<\/p>\n<pre><code>show tag values with key='host'\n# \u8bbe\u7f6e\u5728dashboard\u52a0\u8f7d\u65f6\u66f4\u65b0\n<\/code><\/pre>\n<p>\u5728templating\u4e2d\u5b9a\u4e49\u53d8\u91cf, query\u4e2d\u4f7f\u7528\u7684\u4e24\u79cd\u65b9\u5f0f:<\/p>\n<pre><code>$varname\nselect * from cpu where 'host' =~ \/^$host$\/\n[[varname]]\nselect * from cpu where 'host' =~ \/^[[host]]&amp;\/\n<\/code><\/pre>\n<p>\u5185\u7f6e\u53d8\u91cf\uff1a<\/p>\n<pre><code>$_interval # \u76f8\u5f53\u4e8einfluxdb\u91cc\u9762\u7684$interval\uff0c\u8868\u793agroup by\u7684\u65f6\u95f4\u95f4\u9694\n$timeFilter\/$_timeFilter # time &gt; now() - &lt;time range&gt;\n<\/code><\/pre>\n<p>panel\u91cc\u7684\u53d8\u91cf\uff1a<\/p>\n<pre><code>$col \u7ed9select\u51fa\u6765\u7684field\u53d6\u522b\u540d\n$tag_host\n<\/code><\/pre>\n<h2 id=\"annotations\">Annotations<\/h2>\n<hr>\n<h1 id=\"alerting\">Alerting<\/h1>\n<p>email\u9700\u8981\u5b89\u88c5\u914d\u7f6eSMTP,\u63a8\u8350\u4f7f\u7528sendmail.<\/p>\n<p>alert\u53d1\u51fa\u53bb\u7684\u56fe\u7247\u6216\u8fde\u63a5\u6253\u4e0d\u5f00\uff1a<\/p>\n<pre><code>$ vim \/etc\/grafana\/grafana.ini\n[server]\ndomain=\nroot_url=\n<\/code><\/pre>\n<p>grafana4.6.2\u53ea\u6709graph panel\u652f\u6301alert, singlestat \u548c table\u6682\u4e0d\u652f\u6301\uff0e<\/p>\n<p>conditions\u6682\u4e0d\u652f\u6301template variables.<\/p>\n<hr>\n<h1 id=\"plugins\">plugins<\/h1>\n<p>\u9ed8\u8ba4\u5b89\u88c5\u8def\u5f84\uff1a<\/p>\n<pre><code>\/var\/lib\/grafana\/plugins\n<\/code><\/pre>\n<p>\u547d\u4ee4\uff1a<\/p>\n<pre><code># \u67e5\u770b\u5df2\u7ecf\u5b89\u88c5\u7684plugin\n$ sudo grafana-cli plugins list-remote\n$ sudo grafana-cli plugins install &lt;plugin-id&gt; &lt;version&gt;\n# \u67e5\u770b\u5b89\u88c5\u7684plugin\n$ sudo grafana-cli plugins ls\n# \u5220\u9664plugin\n$ sudo grafana-cli plugins remove &lt;plugin-id&gt;\n<\/code><\/pre>\n<hr>\n<h1 id=\"enable-https\">enable https<\/h1>\n<pre><code>$ vim \/etc\/grafana\/grafana.ini\nprotocol=https\ncert-file=file.crt\nkey-file=file.key\n<\/code><\/pre>\n<h1 id=\"provisioning\">Provisioning<\/h1>\n<p><a class=\"link\" href=\"https:\/\/grafana.com\/docs\/administration\/provisioning\/#provisioning-grafana\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/grafana.com\/docs\/administration\/provisioning\/#provisioning-grafana<\/a><\/p>\n<p>datasource<\/p>\n<pre><code>$ vim \/etc\/grafana\/provisioning\/datasources\/datasource.yaml\n- name: MAF\ntype: influxdb\naccess: proxy\nurl: http:\/\/influxdb-service:8086\ndatabase: sandbox\nisDefault: true\neditable: true\n<\/code><\/pre>\n<p>dashboard<\/p>\n<pre><code>$ vim \/etc\/grafana\/provisioning\/dashboards\/dashboard.yaml\napiVersion: 1\nproviders:\n- name: 'default'\norgId: 1\nfolder: ''\ntype: file\ndisableDeletion: false\neditable: true\nupdateIntervalSeconds: 600\noptions:\npath: \/etc\/grafana\/dashboards\n<\/code><\/pre>"},{"title":"Vagrant","link":"https:\/\/canuxcheng.com\/post\/vagrant\/","pubDate":"Thu, 12 Jan 2017 21:00:01 +0000","guid":"https:\/\/canuxcheng.com\/post\/vagrant\/","description":"<h1 id=\"vagrant\">Vagrant<\/h1>\n<p>\u6784\u5efa\u5728\u865a\u62df\u5316\u6280\u672f\u4e4b\u4e0a\u7684\u865a\u62df\u673a\u8fd0\u884c\u73af\u5883\u7ba1\u7406\u5de5\u5177\uff0e<\/p>\n<p>\u9002\u5408\u7528\u6765\u6784\u5efa\u548c\u5206\u53d1\u5f00\u53d1\u73af\u5883\uff0e\u901a\u8fc7\u547d\u4ee4\u884c\u53ef\u4ee5\u6279\u91cf\u81ea\u52a8\u5316\uff0c\u4e0d\u7528\u4e00\u4e2a\u4e00\u4e2a\u5b89\u88c5\u914d\u7f6e\u56fe\u5f62\u754c\u9762\u7684\u865a\u62df\u673a\uff0e<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/mitchellh\/vagrant\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/mitchellh\/vagrant<\/a><\/p>\n<p>\u9700\u8981\u5b89\u88c5virtualbox\u6216vmware\u7b49\u865a\u62df\u673a.<\/p>\n<p>vagrant\u8fd8\u652f\u6301\u5176\u5b83\u7684providers(docker, vmware, hyper-v, aws)<\/p>\n<p>\u53ef\u4ee5\u5728\u8fd9\u91cc\u627e\u5230\u5f88\u591avagrant\u53ef\u7528\u7684box:<\/p>\n<p><a class=\"link\" href=\"https:\/\/atlas.hashicorp.com\/boxes\/search\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/atlas.hashicorp.com\/boxes\/search<\/a><\/p>\n<hr>\n<h1 id=\"\u521d\u59cb\u5316\">\u521d\u59cb\u5316<\/h1>\n<pre><code>$ mkdir -p \/home\/user\/vagrant\n$ cd \/vagrant\n# \u5728\u5f53\u524d\u76ee\u5f55\u751f\u6210\u4e00\u4e2aVagrantfile\u6587\u4ef6, \u9700\u624b\u52a8\u6dfb\u52a0vm.box\n$ vagrant init\n# \u76f8\u5f53\u4e8e\u76f4\u63a5\u6dfb\u52a0\u4e86vm.box\u5230Vagrantfile.\n$ vagrant init [box-name]\n<\/code><\/pre>\n<h1 id=\"\u6dfb\u52a0box\">\u6dfb\u52a0box<\/h1>\n<pre><code># \u9ed8\u8ba4\u4ecehttps:\/\/atlas.hashicorp.com\/boxes\/search\u4e0b\u8f7d\u8be5box.\n$ vagrant box add [[--name ]box-name] hashicorp\/precise64\n# \u4e5f\u53ef\u4ee5\u4f7f\u7528\u4e0b\u8f7d\u5230\u672c\u5730\u7684box\n$ vagrant box add [[--name ]box-name] \/path\/to\/your.box\n# \u4e5f\u53ef\u4ee5\u4f7f\u7528\u81ea\u5df1\u7684\u670d\u52a1\u5668\u4e0a\u7684box\n$ vagrant box add [[--name ]box-name] URL\n# \u6dfb\u52a0box\u4e4b\u540e\u4fee\u6539Vagrantfile,\u6dfb\u52a0vm.box:\nVagrant.configure(&quot;2&quot;) do |config|\nconfig.vm.box = &quot;[box-name]&quot;\nend\n<\/code><\/pre>\n<h1 id=\"\u4f7f\u7528box\">\u4f7f\u7528box<\/h1>\n<pre><code>$ vagrant up [box-name]\n$ vagrant up --provider docker\/aws\/vmware\/hyperv\/... [box-name]\n$ vagrant ssh\n# \u4f1a\u8fdb\u5165\u4e00\u4e2avagrant@precise64:~$\u7684\u73af\u5883\uff0e\n# \/vagrant \u662f\u4e00\u4e2a\u548c\/home\/user\/vagrant\u540c\u6b65\u7684\u8def\u5f84\uff0e\n<\/code><\/pre>\n<h1 id=\"\u7ed3\u675f\u4f7f\u7528\">\u7ed3\u675f\u4f7f\u7528<\/h1>\n<pre><code>$ vagrant status # \u67e5\u770bbox\u72b6\u6001\n$ vagrant halt # \u5173\u95edbox\n$ vagrant reload # \u91cd\u542fbox\n$ vagrant suspend\n$ vagrant resume\n$ vagrant provision\n# \u4f1a\u9500\u6bc1box\u5360\u7528\u7684\u6240\u6709\u8d44\u6e90\uff0c\u4f46\u4e0d\u5220\u9664box.\n$ vagrant destroy\n<\/code><\/pre>\n<h1 id=\"\u7ba1\u7406box\">\u7ba1\u7406box<\/h1>\n<pre><code>$ vagrant box list\n$ vagrant box remove\n<\/code><\/pre>\n<h1 id=\"\u5176\u5b83\">\u5176\u5b83<\/h1>\n<pre><code>$ vagrant global-status\n$ vagrant global-status --prune\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u914d\u7f6evagrantfile\">\u914d\u7f6eVagrantfile<\/h1>\n<pre><code>config.vm.box_version = &quot;1.1.0&quot;\ncfg.vm.hostname = &quot;ubuntu.labs&quot;\n# \u7aef\u53e3\u6620\u5c04, \u628a\u4e3b\u673a\u7684\u7aef\u53e3\u6620\u5c04\u5230vagrant\u7684box\n# \u8bbf\u95ee\u4e3b\u673a\u7684\u8be5\u7aef\u53e3\u5c31\u662f\u8bbf\u95eevagrant\u7684box\ncfg.vm.network :forward_port, guest: 80, host: 8080\n# \u79c1\u6709\u7f51\u7edc\uff0c\u53ea\u6709\u4e3b\u673a\u53ef\u4ee5\u8bbf\u95eevagrant\u7684box.\n# \u5982\u679c\u591a\u4e2avagrant\u7684box\u8bbe\u5b9a\u5728\u540c\u4e00\u4e2a\u7f51\u6bb5\u4e5f\u53ef\u4ee5\u4e92\u76f8\u8bbf\u95ee\uff0e\ncfg.vm.network :private_network, ip: &quot;192.168.50.10&quot;\n# \u516c\u6709\u7f51\u7edc\uff0cvagrant\u7684box\u548c\u4e3b\u673a\u4f7f\u7528\u4e00\u6837\u7684\u7f51\u7edc\uff0e\ncfg.vm.network :public_network\ncfg.vm.network :public_network, ip: &quot;192.168.1.1&quot;\ncfg.vm.synced_folder &quot;\/var\/tmp\/pkg-build&quot;, &quot;\/var\/tmp\/pkg-build&quot;\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u6253\u5305\">\u6253\u5305<\/h1>\n<p>\u7528\u6237\u53ef\u4ee5\u6253\u5305\u81ea\u5df1\u7684\u5f00\u53d1\u73af\u5883\uff0c\u7136\u540e\u5206\u53d1\u51fa\u53bb\uff0e<\/p>\n<pre><code>$ vagrant package [options] [name]\n$ vagrant package\n<\/code><\/pre>\n<hr>\n<h1 id=\"windows\">windows<\/h1>\n<p>\u5728windows\u7269\u7406\u673a\u5b89\u88c5virtualbox\u548cvagrant.<\/p>\n<p>windows\u4e0d\u652f\u6301ssh,\u6240\u4ee5\u9700\u8981\u7c7b\u4f3c\u4e8eputty\u8fd9\u79cd\u5ba2\u6237\u7aef\uff0e<\/p>\n<pre><code>host: 127.0.0.1\nport: 2222\nuser: vagrant\/root\npassword: vagrant\n<\/code><\/pre>\n<h1 id=\"linux\">linux<\/h1>\n<p>\u53ea\u80fd\u5728linux\u7269\u7406\u673a\u5b89\u88c5virtualbox\u548cvagrant\u4f7f\u7528\uff0e<\/p>\n<p>\u5982\u679c\u60f3\u5728windows\u7269\u7406\u673a\u91cc\u9762\u7684virtualbox\u4e0a\u5b89\u88c5\u7684linux\u7cfb\u7edf\u4e2d\u4f7f\u7528vagrant\u4f1a\u62a5\u9519\uff1a<\/p>\n<pre><code># default: Warning: Connection timeout. Retrying...\n<\/code><\/pre>\n<p>\u56e0\u4e3a\u9700\u8981\u5728linux\u4e0a\u5728\u5b89\u88c5virtualxo\uff0c\u7136\u540e\u4e0d\u80fd\u8bbe\u7f6e\u52a0\u901f\uff0e<\/p>\n<p><img src=\"https:\/\/canuxcheng.com\/images\/vagrant.PNG\"\nloading=\"lazy\"\nalt=\"Pic\"\n><\/p>\n<p><img src=\"https:\/\/canuxcheng.com\/images\/vagrant1.PNG\"\nloading=\"lazy\"\nalt=\"Pic1\"\n><\/p>\n<h1 id=\"qa\">Q&amp;A<\/h1>\n<ol>\n<li>\n<p>vagrant\u600e\u6837\u6253\u5305ESXi\u4e0a\u7684\u865a\u62df\u673a\uff0e<\/p>\n<\/li>\n<li>\n<p>vagrant\u80fd\u5426\u6253\u5305cluster(virtualbox\u6216esxi)<\/p>\n<\/li>\n<\/ol>"},{"title":"Django Misc","link":"https:\/\/canuxcheng.com\/post\/django_misc\/","pubDate":"Wed, 04 Jan 2017 01:13:36 +0000","guid":"https:\/\/canuxcheng.com\/post\/django_misc\/","description":"<h1 id=\"django\u7684\u56fd\u9645\u5316\u548c\u672c\u5730\u5316\">Django\u7684\u56fd\u9645\u5316\u548c\u672c\u5730\u5316<\/h1>\n<p>settings.py\u91cc\u9762\u548c\u56fd\u9645\u5316\u548c\u672c\u5730\u5316\u76f8\u5173\u7684\u8bbe\u7f6e:<\/p>\n<pre><code>USE_I18N = True\nUSE_L10N = True\nTIME_ZONE = 'UTC'\nUSE_TZ = True\n<\/code><\/pre>\n<h2 id=\"\u56fd\u9645\u5316i18n\">\u56fd\u9645\u5316(i18N)<\/h2>\n<p>\u7531\u5f00\u53d1\u8005\u5b8c\u6210,\u672c\u5730\u5316\u7684\u51c6\u5907\u5de5\u4f5c.<\/p>\n<p><a class=\"link\" href=\"http:\/\/www.i18nguy.com\/unicode\/language-identifiers.html\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.i18nguy.com\/unicode\/language-identifiers.html<\/a><\/p>\n<pre><code>LANGUAGE_CODE = 'en-us' # default\nLANGUAGES = [\n('en-US', _('English')),\n('zh-CN', _('Chinese')),\n]\n<\/code><\/pre>\n<h2 id=\"\u672c\u5730\u5316l10n\">\u672c\u5730\u5316(l10N)<\/h2>\n<p>\u7531\u7ffb\u8bd1\u8005\u5b8c\u6210.<\/p>\n<hr>\n<h1 id=\"django\u7684\u5b89\u5168\">Django\u7684\u5b89\u5168<\/h1>\n<hr>\n<h1 id=\"django\u7684\u6027\u80fd\u4f18\u5316\">Django\u7684\u6027\u80fd\u4f18\u5316<\/h1>\n<p><a class=\"link\" href=\"https:\/\/docs.djangoproject.com\/zh-hans\/3.2\/topics\/performance\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.djangoproject.com\/zh-hans\/3.2\/topics\/performance\/<\/a><\/p>\n<hr>\n<h1 id=\"django\u7684\u5730\u7406\u6846\u67b6\">Django\u7684\u5730\u7406\u6846\u67b6<\/h1>"},{"title":"TSDB","link":"https:\/\/canuxcheng.com\/post\/database\/","pubDate":"Tue, 03 Jan 2017 14:46:14 +0000","guid":"https:\/\/canuxcheng.com\/post\/database\/","description":"<h1 id=\"rdbms\">RDBMS<\/h1>\n<p>\u5173\u7cfb\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\u3002<\/p>\n<p>SQLite<\/p>\n<p>Oracle<\/p>\n<p>MSSQL<\/p>\n<p>Mysql<\/p>\n<p>Postgre<\/p>\n<hr>\n<h1 id=\"nosql\">NoSQL<\/h1>\n<p>NoSQL: Not only SQL.<\/p>\n<p>\u975e\u5173\u7cfb\u578b\u6570\u636e\u5e93\u3002<\/p>\n<p>memcached(cache)<\/p>\n<p>redis(cache)<\/p>\n<p>mongodb<\/p>\n<p>hbase(hadoop)<\/p>\n<p>cassandra(hadoop)<\/p>\n<p>rethinkdb<\/p>\n<hr>\n<h1 id=\"tsdb\">TSDB<\/h1>\n<p>Time series database.<\/p>\n<p>\u65f6\u5e8f\u6570\u636e\u5e93<\/p>\n<p>influxdb<\/p>\n<p>rrdtool<\/p>\n<p>graphite<\/p>\n<p>opentsdb<\/p>\n<p>premetheus<\/p>"},{"title":"Awk","link":"https:\/\/canuxcheng.com\/post\/shell_awk\/","pubDate":"Wed, 14 Dec 2016 00:55:37 +0800","guid":"https:\/\/canuxcheng.com\/post\/shell_awk\/","description":"<h1 id=\"awk\">awk<\/h1>\n<p>awk \u662f\u4e00\u95e8\u7f16\u7a0b\u8bed\u8a00<\/p>\n<p>awk\/nawk\/gawk\/mawk\uff1a\u6bd4sed\u66f4\u9ad8\u7ea7\u7684\u6d41\u7f16\u8f91\u5de5\u5177\uff0c\u662fsed\u548cgrep\u7684\u5347\u7ea7\u7248\uff0c\u4e3b\u8981\u7528\u4e8e\u6570\u636e\u6d41\u5904\u7406\u3002<\/p>\n<p>nawk\uff1a new awk\u3002<\/p>\n<p>mawk\uff1a awk\u7684\u89e3\u91ca\u5668<\/p>\n<p>gawk\u662fgnu\u7684awk\uff0c\u529f\u80fd\u66f4\u5168\u9762\u3002<\/p>\n<p>awk\u547d\u4ee4\u683c\u5f0f\uff1a<\/p>\n<pre><code>awk [-v var=value [-F *] [\u2013] '\/pattern\/ {action}' file\nawk [-v var=value [-F *] [-f scriptfile ...] [\u2013] file\nawk [-v var=value [-F *] [-] 'BEGIN {} \/pattern\/ {action} END {}' file\nBEGIN { } \u5728\u8bfb\u53d6\u8f93\u5165\u4e4b\u524d\u5c31\u64cd\u4f5c\nEND { } \u5728\u8bfb\u7269\u8f93\u5165\u4e4b\u540e\u64cd\u4f5c\n<\/code><\/pre>\n<p>awk\u7684\u6307\u4ee4\u9700\u8981\u7528\u5355\u5f15\u53f7\u5305\u56f4\uff1b\n\u6a21\u5f0f\u9700\u8981\u7528\/pattern\/\u5305\u56f4\uff1b\n\u8fc7\u7a0b\u9700\u8981\u7528{command1\uff1bcommand2}\u5305\u56f4\uff0c\u591a\u4e2a\u8fc7\u7a0b\u9700\u8981\u7528\uff1b\u9694\u5f00\u3002<\/p>\n<p>\u811a\u672c\u4e2d\u4f20\u9012\u53c2\u6570\u683c\u5f0f\uff1a<\/p>\n<pre><code>awk [-f scriptfile]OR['\/pattern\/{action}'] val1=value1 val2=value2 \u2026 file1 vala=valuea valb=valueb... file2 ...\n<\/code><\/pre>\n<p>\u5982\u679c\u901a\u8fc7shell\u4f20\u53c2\u6570\uff0c\u628avalue\u6539\u6210$n\u5373\u53ef\u3002\n\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u8fd4\u56de\u503c\u4f5c\u4e3a\u53c2\u6570value\u3002\n\u4e5f\u53ef\u4ee5\u4f7f\u7528\u73af\u5883\u53d8\u91cf\u4f5c\u4e3avalue\uff0c\u4e5f\u53ef\u4ee5\u7ed9awk\u7684\u73af\u5883\u53d8\u91cf\u8d4b\u503c\u3002\n\u53ef\u4ee5\u5728\u4efb\u4f55\u4f4d\u7f6e\u5b9a\u4e49\u53d8\u91cf\uff08\u2018 \u2018 \u4e4b\u540e\uff1b-v\u4e4b\u540e\uff1bBEGIN\u4e2d\uff1b{}\u4e2d\uff1bEND\u4e2d\uff09\u3002\n\u53ea\u6709\u5728-v\u548c\u5728BEGIN\u4e2d\u5b9a\u4e49\u7684\u53d8\u91cf\u80fd\u5728BEGIN\u4e2d\u4f7f\u7528\u3002\n\u5728END\u4e2d\u5b9a\u4e49\u7684\u53d8\u91cf\u53ea\u80fd\u5728END\u4e2d\u4f7f\u7528\uff0c\u5176\u5b83\u4f4d\u7f6e\u5b9a\u4e49\u7684\u53d8\u91cf\u90fd\u53ef\u4ee5\u5728{}\u4e2d\u4f7f\u7528\u3002\n\u5728\u4efb\u4f55\u4f4d\u7f6e\u5b9a\u4e49\u7684\u53d8\u91cf\u5728END\u4e2d\u90fd\u53ef\u4ee5\u4f7f\u7528\u3002<\/p>\n<p>Options:<\/p>\n<pre><code>-f: \u6307\u5b9a\u8fd0\u884c\u811a\u672c\u6587\u4ef6\u4e2d\u7684\u547d\u4ee4,\u53ef\u4ee5\u6307\u5b9a\u591a\u4e2a\u811a\u672c\u3002\n-F: \u6307\u5b9a\u8f93\u5165\u5b57\u6bb5\u5206\u9694\u7b26\uff0c\u9ed8\u8ba4\u662f\u7a7a\u683c\u952e\u548c\u5236\u8868\u7b26\u3002\n-v $val=value \u5b9a\u4e49\u53d8\u91cf\n<\/code><\/pre>\n<p>awk\u4e2d\u7684\u7531\u7a7a\u683c\u6216\u5236\u8868\u7b26\u5206\u9694\u7684\u5355\u5143\u4f5c\u4e3a\u4e00\u4e2a\u5b57\u6bb5<\/p>\n<pre><code>$0 \u5f53\u524d\u884c\u7684\u6587\u672c\u5185\u5bb9\n$1 \u7b2c\u4e00\u4e2a\u5b57\u6bb5\u7684\u6587\u672c\u5185\u5bb9\n$n \u7b2cn\u4e2a\u5b57\u6bb5\u7684\u6587\u672c\u5185\u5bb9\n<\/code><\/pre>\n<p>awk\u4e2d\u7684\u5e38\u91cf\u548c\u53d8\u91cf\uff1a<\/p>\n<pre><code>\u5e38\u91cf\uff1a\u5b57\u7b26\u4e32\u578b\u548c\u6570\u5b57\u578b\uff0c\u5b57\u7b26\u4e32\u5e38\u91cf\u5fc5\u987b\u7528\u201c\u201d\u5f15\u53f7\u5f15\u7528\u3002\n\u53d8\u91cf\uff1a\u53d8\u91cf\u540d\u5927\u5c0f\u5199\u654f\u611f\uff0c\u5b57\u6bcd\u6216\u4e0b\u5212\u7ebf\u5f00\u5934\uff0c\u53ef\u4ee5\u5305\u542b\u6570\u5b57\u3002\nawk\u4f1a\u81ea\u52a8\u5c06\u53d8\u91cf\u6839\u636e\u73af\u5883\u521d\u59cb\u5316\u4e3a\u7a7a\u4e32\u62160.\n<\/code><\/pre>\n<p>awk\u4e2d\u7684\u547d\u4ee4\uff1a<\/p>\n<pre><code>print\u547d\u4ee4\uff1a\nprint a,b \u53c2\u6570\u7528\uff0c\u9694\u5f00\uff0c\u6253\u5370\u51fa\u6765\u7684\u5c31\u662f\u7528\u7a7a\u683c\u9694\u5f00\u7684,eg\uff1aa b.\nprint a\u201cstring\u201db \u53c2\u6570\u4e2d\u7528\u53cc\u5f15\u53f7\u6253\u5370\u51fa\u6765\u5c31\u662f\u539f\u6837\u8f93\u51fa,eg:astringb.\nPrint \u6253\u5370\u5339\u914d\u5230\u7684\u884c\nprint \u201c\u201d \u6253\u5370\u4e00\u4e2a\u7a7a\u884c\n<\/code><\/pre>\n<p>printf\u547d\u4ee4\uff1a<\/p>\n<p>\u683c\u5f0f\u5316\u8f93\u51fa\uff0c\u548cc\u8bed\u8a00\u4e2d\u7684printf\u7c7b\u4f3c\u3002<\/p>\n<pre><code>printf(format[,arguments])\nformat\u662f\u7528\u201c\u201d\u5f15\u8d77\u6765\u7684\u683c\u5f0f\narguments\u662f\u4e00\u4e2a\u53ef\u9009\u7684\u53c2\u6570\u5217\u8868\n%s:\u5b57\u7b26\u4e32\n%d\uff1a\u5341\u8fdb\u5236\u6574\u6570\n%f\uff1a\u6d6e\u70b9\u683c\u5f0f\uff0c\u9ed8\u8ba4\u7cbe\u5ea6\u5c0f\u6570\u70b9\u540e6\u4f4d\u3002\n%%\uff1a\u6253\u5370%\n|%mX|:\u5bf9\u4e8e\u683c\u5f0fX\u6309\u7167\u9ed8\u8ba4\u7684\u53f3\u5bf9\u9f50\uff0c\u7cbe\u786e\u5230m\u4f4d\uff0c\u5de6\u8fb9\u8865\u7a7a\u683c\n|%-mX|\uff1a\u5bf9\u4e8e\u683c\u5f0fX\u6309\u7167\u5de6\u5bf9\u9f50\uff0c\u7cbe\u786e\u5230m\u4f4d\uff0c\u53f3\u8fb9\u8865\u7a7a\u683c\n\u201c%*.*g\u201d\uff0c m\uff0c n\uff0c $val \uff1a \u52a8\u6001\u6307\u5b9a\u7cbe\u5ea6\uff0c\u603b\u5171m\u4f4d\uff0c\u5c0f\u6570\u70b9\u540en\u4f4d\u3002\n\\t\uff1a\u8df3\u683c\n\\n\uff1a\u6362\u884c\n<\/code><\/pre>\n<p>next\u547d\u4ee4\uff1a<\/p>\n<p>\u53d6\u5f97\u4e0b\u4e00\u6761\u8bb0\u5f55<\/p>\n<p>delete\u547d\u4ee4\uff1a<\/p>\n<p>\u5220\u9664<\/p>\n<p>exit\u547d\u4ee4\uff1a<\/p>\n<p>\u9000\u51fa\u8f93\u5165\u8bb0\u5f55\u7684\u5904\u7406\uff0c\u8fdb\u5165END\u3002\nexit n \u8bbe\u7f6eawk\u7684\u9000\u51fa\u72b6\u6001\u3002<\/p>\n<p>awk\u4e2d\u7684\u5185\u7f6e\u7684\u53d8\u91cf\uff1a<\/p>\n<pre><code>FS \u5b9a\u4e49\u8f93\u5165\u8bb0\u5f55\u5b57\u6bb5\u5206\u9694\u7b26\uff0c\u9ed8\u8ba4\u662f\u7a7a\u683c\nOFS \u8f93\u51fa\u8bb0\u5f55\u5b57\u6bb5\u5206\u9694\u7b26\uff0c\u9ed8\u8ba4\u662f\u7a7a\u683c\nNF \u5f53\u524d\u8f93\u5165\u8bb0\u5f55\u7684\u5b57\u6bb5\u4e2a\u6570\uff08\u5217\u53f7\uff09\nRS \u8f93\u5165\u8bb0\u5f55\u5206\u9694\u7b26\uff0c\u9ed8\u8ba4\u662f\u6362\u884c\u7b26\nORS \u8f93\u51fa\u8bb0\u5f55\u5206\u9694\u7b26\uff0c\u9ed8\u8ba4\u662f\u6362\u884c\u7b26\nNR \u8bfb\u5165\u7684\u8f93\u5165\u8bb0\u5f55\u7684\u4e2a\u6570(\u884c\u53f7\uff09\nFILENAME \u5f53\u524d\u8f93\u5165\u6587\u4ef6\u7684\u540d\u5b57\nCONVFMT \u63a7\u5236\u7c7b\u578b\u8f6c\u6362\uff0c\u9ed8\u8ba4\u4e3a%.6g\n<\/code><\/pre>\n<p>\u5728BEGIN{}\u4e2d\u53ef\u4ee5\u7ed9\u53d8\u91cf\u8d4b\u503c\uff1b\u5728{}\u4e2d\u7528$\u6765\u5f15\u7528\u8fd9\u4e9b\u53d8\u91cf\uff1b\u5728END{}\u4e2d\u53ef\u4ee5\u6253\u5370\u8fd9\u4e9b\u53d8\u91cf\u3002<\/p>\n<p>\u8fd0\u7b97\u7b26\uff1a<\/p>\n<pre><code>\u7b97\u6570\u64cd\u4f5c\u7b26\uff1a\n+ - * \/ % ^\n\u8d4b\u503c\u64cd\u4f5c\u7b26\uff1a\n++ \u2013-\n+= -= *= \/= %= ^=\n\u5173\u7cfb\u64cd\u4f5c\u7b26\uff1a\n&lt; &gt; &lt;= &gt;=\n==(\u6ce8\u610f\u548c\u8d4b\u503c=\u7684\u533a\u522b\uff09 !=\n~\uff08\u5339\u914d\uff09 !~\uff08\u4e0d\u5339\u914d\uff09\n\u5e03\u5c14\u64cd\u4f5c\u7b26\uff1a\n&amp;&amp; \u903b\u8f91\u4e0e\uff0c\u4f18\u5148\u7ea7\u9ad8\u4e8e||\n|| \u903b\u8f91\u6216\n\uff01 \u903b\u8f91\u975e\n<\/code><\/pre>\n<p>awk\u5185\u7f6e\u7684\u8bed\u53e5\uff1a<\/p>\n<p>\u548cc\u8bed\u8a00\u76f8\u4f3c<\/p>\n<p>\u6761\u4ef6\u8bed\u53e5\uff1a<\/p>\n<pre><code>if (expression)\naction1\n[else if (expression2) {\naction2\naction3\n...\n}] \u591a\u4e2a\u52a8\u4f5c\u9700\u8981\u7528{}\u5305\u56f4\n[else if () {action1;action2;...}] \u591a\u4e2a\u52a8\u4f5c\u5199\u5728\u4e00\u884c\u9700\u8981\u7528\uff1b\u9694\u5f00\u3002\n[else if () action ; else action] \u5728\u540c\u4e00\u884c\u7528\uff1b\u7ed3\u675f\u4e00\u4e2a\u8bed\u53e5\n<\/code><\/pre>\n<p>\u4e5f\u53ef\u4ee5\u7528\u6761\u4ef6\u8fd0\u7b97\u7b26\u4ee3\u66ff\u6761\u4ef6\u8bed\u53e5\uff1a<\/p>\n<pre><code>expression ? Action1 : action2\n<\/code><\/pre>\n<p>\u5faa\u73af\u8bed\u53e5\uff1a<\/p>\n<pre><code>while (condition)\naction\nwhile (condition) {\naction1\naction2\n\u2026\n}\nwhile (condition) { action1 ; action2 ; \u2026 }\ndo\naction\nwhile (condition)\ndo {\naction1\naction2\n\u2026\n} while (condition)\ndo { action1;action2;...} while (condition)\nfor (set_counter; test_counter; increment_counter)\naction\n<\/code><\/pre>\n<p>break:<\/p>\n<p>\u9000\u51fa\u5faa\u73af<\/p>\n<p>continue\uff1a<\/p>\n<p>\u7ec8\u6b62\u672c\u6b21\u5faa\u73af\uff0c\u8fdb\u5165\u4e0b\u4e00\u6b21\u5faa\u73af<\/p>\n<p>\u6570\u7ec4\uff1a<\/p>\n<pre><code>array[subscript] = value\nawk\u4e2d\u7684\u6570\u7ec4\u76f4\u63a5\u7ed9\u6570\u7ec4\u5143\u7d20\u8d4b\u503c\uff0c\u4e0d\u7528\u6307\u5b9a\u6570\u7ec4\u5927\u5c0f\u3002\u901a\u8fc7\u4e0b\u6807\u8bbf\u95ee\u3002\n<\/code><\/pre>\n<p>\u5173\u8054\u6570\u7ec4\uff1a<\/p>\n<p>awk\u4e2d\u7684\u6570\u7ec4\u662f\u5173\u8054\u6570\u7ec4\uff0c\u4e5f\u5c31\u662f\u53ef\u4ee5\u7528\u6570\u503c\u548c\u5b57\u7b26\u4f5c\u4e3a\u4e0b\u6807\u6765\u8bbf\u95ee\u3002<\/p>\n<p>in\u64cd\u4f5c\u7b26\u7528\u6765\u6d4b\u8bd5variable\u662f\u5426\u662f\u6570\u7ec4array\u7684\u4e0b\u6807\uff0c\u5982\u679c\u662f\u6761\u4ef6\u4e3a\u771f\u3002<\/p>\n<pre><code>for (variable in array)\nprint variable: array[variable]\nif (variable in array)\nprint variable: array[variable]\n<\/code><\/pre>\n<p>\u5220\u9664\u6570\u7ec4\u5143\u7d20\uff1a<\/p>\n<pre><code>delete array[subscript]\n<\/code><\/pre>\n<p>\u7cfb\u7edf\u53d8\u91cf\u7684\u6570\u7ec4\uff1a<\/p>\n<pre><code>ARGV\uff1a\n\u547d\u4ee4\u884c\u53c2\u6570\u6570\u7ec4\uff0c\u4e0b\u6807\u4ece0\u5f00\u59cb\uff0c\u4e0d\u5305\u62ecawk\u811a\u672c\u672c\u8eab\u548c\u4efb\u4f55\u8c03\u7528awk\u811a\u672c\u6307\u5b9a\u7684\u9009\u9879\u3002\nakw -f awk.sh \u2026 #\u4e0d\u5305\u62ec-f\u548cawk.sh\n<\/code><\/pre>\n<p>ENVIRON\uff1a<\/p>\n<p>\u73af\u5883\u53d8\u91cf\u6570\u7ec4\uff0c\u4e0b\u6807\u662f\u73af\u5883\u53d8\u91cf\u7684\u540d\u5b57\uff0c\u5143\u7d20\u662f\u73af\u5883\u53d8\u91cf\u7684\u503c\u3002<\/p>\n<p>awk\u5185\u7f6e\u7684\u51fd\u6570\uff1a<\/p>\n<p>\u51fd\u6570\u5206\u4e3a\u7b97\u6570\u51fd\u6570\u548c\u5b57\u7b26\u4e32\u51fd\u6570\u3002<\/p>\n<p>\u7b97\u6570\u51fd\u6570\u67099\u4e2a\uff1a<\/p>\n<pre><code>sin(x)\uff1a\u8fd4\u56dex\u7684\u6b63\u5f26\ncos(x)\uff1a\u8fd4\u56dex\u7684\u4f59\u5f26\natan2(y,x)\uff1a\u8fd4\u56dey\/x\u7684\u53cd\u6b63\u5207\nexp(x)\uff1a\u8fd4\u56dee\u7684x\u6b21\u5e42\nlog(x)\uff1a\u8fd4\u56de\u4ee5e\u4e3a\u5e95\u7684x\u7684\u81ea\u7136\u5bf9\u6570\nsqrt(x)\uff1a\u8fd4\u56dex\u7684\u5e73\u65b9\u6839\nint(x)\uff1a\u8fd4\u56dex\u7684\u6574\u6570\u90e8\u5206\nrand()\uff1a\u8fd4\u56de\u4f2a\u968f\u673a\u6570r\uff0c0=&lt; r &lt;1\nsrand(x)\uff1a\u5efa\u7acbrand\uff08\uff09\u7684\u65b0\u7684\u79cd\u5b50\u6570\n<\/code><\/pre>\n<p>\u5b57\u7b26\u4e32\u51fd\u6570\uff1a<\/p>\n<pre><code>gsub(r,s,t) \u5728\u5b57\u7b26\u4e32t\u4e2d\u7528s\u66ff\u6362\u548c\u6b63\u5219\u8868\u8fbe\u5f0fr\u5339\u914d\u7684\u6240\u6709\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u66ff\u6362\u7684\u4e2a\u6570\u3002\ngsub(r,s) \u76f8\u5f53\u4e8et=$0\nsub(r,s,t)\u7528s\u66ff\u6362\u6b63\u5219\u8868\u8fbe\u5f0f\u5728t\u4e2d\u7684\u9996\u6b21\u5339\u914d\u3002\u6210\u529f\u8fd4\u56de1\uff0c\u5931\u8d25\u8fd4\u56de0.\nsub(r,s)\u76f8\u5f53\u4e8et=$0\nsubstr(s,p)\u8fd4\u56des\u4e2d\u4ece\u4f4d\u7f6ep\u5f00\u59cb\u7684\u5b50\u4e32\nsubstr(s,p,n)\u8fd4\u56des\u4e2d\u4ece\u4f4d\u7f6ep\u5f00\u59cb\u6700\u5927\u957f\u5ea6\u4e3an\u7684\u5b50\u4e32\u3002\nindex(s,t)\u8fd4\u56de\u5b50\u4e32t\u5728s\u4e2d\u7684\u4f4d\u7f6e\uff0c\u5982\u679c\u6ca1\u6709\u6307\u5b9as\u6216\u6ca1\u6709\u5339\u914d\u9879\u8fd4\u56de0.\u4e5f\u5c31\u662f\u8fd4\u56det\u4e2d\u7684\u9996\u5b57\u6bcd\u5728s\u4e2d\u662f\u7b2c\u51e0\u4e2a\u5b57\u7b26\uff0c\u5982\u679c\u9996\u5b57\u6bcd\u91cd\u590d\u51fa\u73b0\u8fd4\u56de\u7b2c\u4e00\u4e2a\u7684\u4f4d\u7f6e\u3002\nlength(s) \u8fd4\u56de\u5b57\u7b26\u4e32s\u957f\u5ea6\uff0c\u6ca1\u6709\u6307\u5b9as\u8fd4\u56de$0\u7684\u957f\u5ea6\uff0c\\n \\t \\r \u7a7a\u683c\u90fd\u7b97\u4e00\u4e2a\u5b57\u8282\u3002\nmatch(s,r)\u5982\u679c\u6b63\u5219\u8868\u8fbe\u5f0fr\u5728s\u4e2d\u51fa\u73b0\uff0c\u8fd4\u56de\u51fa\u73b0\u7684\u8d77\u59cb\u4f4d\u7f6e\uff0c\u6ca1\u6709\u5339\u914d\u8fd4\u56de0.\nsplit(string, array, separator)\n\u5c06\u5b57\u7b26\u4e32string\u5206\u89e3\u5230\u6570\u7ec4array\u4e2d\uff0c\u6570\u7ec4\u4e0b\u6807\u4ece1\u5230n\uff0cstring\u6839\u636e\u6307\u5b9a\u7684\u5206\u9694\u7b26\u6765\u5206\u89e3\uff0c\u5982\u679c\u6ca1\u6709\u6307\u5b9a\u5206\u9694\u7b26\uff0c\u9ed8\u8ba4\u4e3aFS\u3002\u8fd4\u56de\u6570\u7ec4\u4e2d\u5143\u7d20\u4e2a\u6570\u3002\nsprintf(\u201cformat\u201d, expr)\u548cprintf\u4e00\u6837\u3002\ntolower(s)\u5c06s\u4e2d\u7684\u6240\u6709\u5927\u5199\u5b57\u6bcd\u8f6c\u6362\u6210\u5c0f\u5199\u5e76\u8fd4\u56de\u65b0\u7684\u5b57\u7b26\u4e32\ntoupper(s)\u5c06s\u4e2d\u7684\u5de6\u53f3\u5c0f\u5199\u5b57\u6bcd\u8f6c\u6362\u6210\u5927\u5199\u5e76\u8fd4\u56de\u65b0\u7684\u5b57\u7b26\u4e32\n<\/code><\/pre>\n<p>\u5176\u5b83\u51fd\u6570\uff1a<\/p>\n<pre><code>getline\u547d\u4ee4\uff08\u5176\u5b9e\u662f\u4e2a\u51fd\u6570\uff09\uff1a\n\u83b7\u53d6\u4e0b\u4e00\u6761\u8bb0\u5f55\u7ed9$0,\u6210\u529f\u8fd4\u56de1\uff0c\u5230\u8fbeEOF\u8fd4\u56de0\uff0c\u5931\u8d25\u8fd4\u56de-1.\ngetline\u53ef\u4ee5\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\uff1agetline &lt; \u201cfilename\u201d,\u6bcf\u6b21\u8bfb\u4e00\u884c\u3002\ngetline\u4ece\u6807\u51c6\u8f93\u5165\u8bfb\u53d6\uff1agetline &lt; \u201c-\u201d,\u6bcf\u6b21\u4ecestdin\u8bfb\u53d6\u4e00\u884c\u3002\n\u5c06\u8f93\u5165\u8d4b\u7ed9\u4e00\u4e2a\u53d8\u91cf\uff1agetline var_name.\n\u4ece\u7ba1\u9053\u8bfb\u53d6\uff1a\u201dcommand\u201d|getline\uff1b\u201ccommand\u201d|getline var_name;\u628a\u4e00\u4e2a\u547d\u4ee4\u7ed3\u679c\u8f93\u51fa\u7ed9getline.\nclose()\uff1a\u5173\u95ed\u6253\u5f00\u7684\u6587\u4ef6\u548c\u7ba1\u9053\n\u201ccommand\u201d | ...\nclose(\u201ccommand\u201d)\u5173\u95ed\u8f93\u5165\u7ba1\u9053\n...| \u201ccommand\u201c &gt; filename\nclose(\u201ccommand &gt; filename\u201d)\u5173\u95ed\u8f93\u51fa\u7ba1\u9053\nsystem()\uff1a\u6267\u884c\u4e00\u4e2a\u547d\u4ee4\u3002\nsystem(\u201ccommand options\u201d),\u8fd4\u56de\u547d\u4ee4\u7684\u9000\u51fa\u72b6\u6001\u3002\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u5b9a\u4e49\u81ea\u5df1\u7684\u51fd\u6570\uff1a<\/p>\n<pre><code>function yourfunctionname(parameter-list) {\nstatements\n}\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u4f7f\u7528\u7cfb\u7edf\u5b9a\u4e49\u7684\u53d8\u91cf\u3001\u8bed\u53e5\u3001\u51fd\u6570\u6765\u5b9a\u4e49\u81ea\u5df1\u7684\u51fd\u6570\u3002\n\u4f7f\u7528\u81ea\u5df1\u5b9a\u4e49\u7684\u51fd\u6570\u53ef\u4ee5\u5c06\u51fd\u6570\u5199\u6210\u4e00\u4e2a\u5355\u72ec\u811a\u672c\uff0c\u4f7f\u7528-f\u9009\u9879\u6765\u6307\u5b9a\u591a\u4e2a\u811a\u672c\u8fdb\u884c\u8c03\u7528\u3002<\/p>\n<hr>\n<h1 id=\"\u5e38\u7528\u547d\u4ee4\">\u5e38\u7528\u547d\u4ee4<\/h1>\n<p>\u5220\u9664\u5b57\u7b26\u4e32\u524d\u540e\u7a7a\u683c:<\/p>\n<pre><code>echo &quot;string&quot; |\u3000awk &quot;$1=$1&quot;\n<\/code><\/pre>"},{"title":"Wordpress","link":"https:\/\/canuxcheng.com\/post\/wordpress\/","pubDate":"Fri, 18 Nov 2016 00:06:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/wordpress\/","description":"<h1 id=\"wordpress\">WordPress<\/h1>\n<h1 id=\"\u5b89\u88c5\">\u5b89\u88c5<\/h1>\n<p>\u5b89\u88c5\u4f9d\u8d56\uff1a<\/p>\n<pre><code>$sudo apt install apache2\n$sudo apt install mysql-server\n$sudo apt install php5\n<\/code><\/pre>\n<p>\u4e0b\u8f7dwordpress\uff1a<\/p>\n<pre><code>$cd \/var\/www\/html\n$git clone https:\/\/github.com\/WordPress\/WordPress.git\n<\/code><\/pre>\n<h1 id=\"\u914d\u7f6e\">\u914d\u7f6e<\/h1>\n<p>\u6dfb\u52a0mysql\u6570\u636e\u5e93\uff1a<\/p>\n<pre><code>$mysql -u root -p\nmysql&gt; create user 'wordpress'@'localhost' identified by '******';\nmysql&gt; create database 'wordpress';\nmysql&gt; GRANT ALL PRIVILEGES ON wordpress.* TO &quot;wordpress&quot;@&quot;localhost&quot;;\nmysql&gt; FLUSH PRIVILEGES;\n<\/code><\/pre>\n<p>\u7f16\u8f91\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>wp-config.php\n<\/code><\/pre>\n<p>\u767b\u9646\u5e76\u5b89\u88c5\u7ad9\u70b9\uff1a<\/p>\n<pre><code>http:\/\/localhost\n<\/code><\/pre>\n<p>\u7ba1\u7406\u754c\u9762\uff1a<\/p>\n<pre><code>http:\/\/localhost\/wp-admin\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u8bed\u8a00\">\u8bed\u8a00<\/h1>\n<p>\u4e0b\u8f7d\u76f8\u5e94\u7684\u8bed\u8a00\u7248\u672c,\u4e2d\u6587\u4e0b\u8f7d\u4e2d\u6587\u7248\u7684wordpress.<\/p>\n<p>\u7136\u540e\u5c06wordpress\/wp-content\/languages\u62f7\u8d1d\u5230\u82f1\u6587\u7248\u7684wordpress\/wp-content\u4e0b<\/p>\n<p>\u8bed\u8a00\u5305\u8def\u5f84:<\/p>\n<pre><code>wordpress\/wp-content\/languages\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u4e3b\u9898\">\u4e3b\u9898<\/h1>\n<p>\u4fee\u6539wp-config.php\u5b89\u88c5\u4e3b\u9898\u4e0d\u7528\u8f93\u5165ftp\u4fe1\u606f\uff1a<\/p>\n<pre><code>define(&quot;FS_METHOD&quot;, &quot;direct&quot;);\ndefine(&quot;FS_CHMOD_DIR&quot;, 0777);\ndefine(&quot;FS_CHMOD_FILE&quot;, 0777);\n<\/code><\/pre>\n<p>\u4e3b\u9898\u5b89\u88c5\u5728\uff1a<\/p>\n<pre><code>wordpress\/wp-content\/themes\n<\/code><\/pre>\n<p>\u4e3b\u9898\u6570\u636e\u5bfc\u5165\u5230:<\/p>\n<pre><code>wordpress\/wp-content\/uploads\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u63d2\u4ef6\">\u63d2\u4ef6<\/h1>\n<p>\u63d2\u4ef6\u5b89\u88c5\u5728\uff1a<\/p>\n<pre><code>wordpress\/wp-content\/plugins\n<\/code><\/pre>\n<h2 id=\"wordpress-reset\">WordPress Reset<\/h2>\n<p>\u4e00\u6b3e\u53ef\u4ee5\u91cd\u7f6e\u6240\u6709\u6570\u636e\u5e93\u6570\u636e\u7684\u63d2\u4ef6\u3002<\/p>\n<h2 id=\"widget-settings-importexport\">widget-settings-importexport<\/h2>\n<h2 id=\"wordpress-importer\">wordpress-importer<\/h2>\n<h2 id=\"wordpress-move\">wordpress-move<\/h2>\n<hr>\n<h1 id=\"\u8bbe\u7f6e\">\u8bbe\u7f6e<\/h1>\n<p>\u9ed8\u8ba4\u7684\u56fa\u5b9a\u8fde\u63a5:<\/p>\n<pre><code>\/index.php\/%year%\/%monthnum%\/%day%\/%postname%\/\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u4e3b\u9898\u5f00\u53d1\">\u4e3b\u9898\u5f00\u53d1<\/h1>\n<hr>\n<h1 id=\"\u63d2\u4ef6\u5f00\u53d1\">\u63d2\u4ef6\u5f00\u53d1<\/h1>"},{"title":"Html Form","link":"https:\/\/canuxcheng.com\/post\/html_form\/","pubDate":"Mon, 31 Oct 2016 04:00:49 +0000","guid":"https:\/\/canuxcheng.com\/post\/html_form\/","description":"<h1 id=\"html\u8868\u5355\">html\u8868\u5355<\/h1>\n<p>html\u8868\u5355\u7528\u4e8e\u641c\u96c6\u4e0d\u540c\u7c7b\u578b\u7684\u7528\u6237\u8f93\u5165\u3002<\/p>\n<hr>\n<h1 id=\"form\"><strong>form<\/strong><\/h1>\n<p>form\u5143\u7d20\u5b9a\u4e49html\u8868\u5355\u3002\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027\u3002<\/p>\n<pre><code>&lt;form action=&quot;action_page.py&quot;&gt;\n&lt;fieldset&gt;\n&lt;legend&gt;Form information:&lt;\/legend&gt;\nFirst name:&lt;br&gt;\n&lt;input type=&quot;text&quot; name=&quot;firstname&quot;&gt;\n&lt;br&gt;\nLast name:&lt;br&gt;\n&lt;input type=&quot;text&quot; name=&quot;lastname&quot;&gt;\n&lt;\/fieldset&gt;\n&lt;\/form&gt;\n# accept-charset\u5c5e\u6027\u89c4\u5b9a\u670d\u52a1\u5668\u53ef\u5904\u7406\u7684\u8868\u5355\u6570\u636e\u5b57\u7b26\u96c6\u3002\n# action\u5c5e\u6027\u89c4\u5b9a\u5f53\u63d0\u4ea4\u8868\u5355\u65f6\u5411\u4f55\u5904\u53d1\u9001\u8868\u5355\u6570\u636e\u3002\n&lt;form action=&quot;action_page.py&quot;&gt;\n# autocomplete\u5c5e\u6027\u89c4\u5b9a\u662f\u5426\u542f\u7528\u8868\u5355\u7684\u81ea\u52a8\u5b8c\u6210\u529f\u80fd\non\/off\n# enctype\u5c5e\u6027\u89c4\u5b9a\u5728\u53d1\u9001\u8868\u5355\u6570\u636e\u4e4b\u524d\u5982\u4f55\u7f16\u7801\napplication\/x-www-form-urlencoded, \u9ed8\u8ba4\u503c\uff0c\u8868\u793a\u5728\u53d1\u9001\u524d\u7f16\u7801\u6240\u6709\u503c\uff0e\nmultipart\/form-data, \u4e0d\u7f16\u7801\uff0c\u5728\u4f7f\u7528\u5305\u542b\u6587\u4ef6\u4e0a\u4f20\u63a7\u4ef6\u7684\u8868\u5355\u5fc5\u987b\u4f7f\u7528\uff0e\ntext\/plain, \u7a7a\u683c\u8f6c\u6362\u4e3a&quot;+&quot;\u52a0\u53f7\uff0c\u4e0d\u5bf9\u7279\u6b8a\u5b57\u7b26\u7f16\u7801\uff0e\n# method\u5c5e\u6027\u89c4\u5b9a\u7528\u4e8e\u53d1\u9001form-data\u7684http\u65b9\u6cd5\nget\/post\n# name\u5c5e\u6027\u89c4\u5b9a\u8868\u5355\u540d\u79f0\n# novalidate\u5c5e\u6027\u89c4\u5b9a\u63d0\u4ea4\u8868\u5355\u65f6\u4e0d\u9a8c\u8bc1\n# target\u5c5e\u6027\u89c4\u5b9a\u5728\u4f55\u5904\u6253\u5f00URL\u3002\n_blank\/_self\/_parent\/_top\n<\/code><\/pre>\n<hr>\n<h1 id=\"input\"><strong>input<\/strong><\/h1>\n<p>input\u5143\u7d20\u662f\u6700\u91cd\u8981\u7684\u8868\u5355\u5143\u7d20\u3002\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027\u3002<\/p>\n<pre><code># type\u5c5e\u6027\u89c4\u5b9a\u8f93\u5165\u5143\u7d20\u7c7b\u578b\nbutton\ncheckbox\nfile\nhidden\nimage\npassword\nradio\nreset\nsubmit\ntext\n# name\u5c5e\u6027\u5b9a\u4e49input\u5143\u7d20\u540d\u79f0\n# value\u5c5e\u6027\u5b9a\u4e49input\u5143\u7d20\u9ed8\u8ba4\u503c\nreadonly\ndisabled\nsize\nmaxlength\nalt\naccept\nchecked\nsrc\nautocomplete\nautofocus\nform\nformaction\nformenctype\nformmethod\nformnovalidate\nformtarget\nheight\nwidth\nlist\nmax\nmin\nmultiple\npattern\nplaceholder\nrequired\nstep\n<\/code><\/pre>\n<hr>\n<h1 id=\"fieldset\"><strong>fieldset<\/strong><\/h1>\n<p>fieldset\u5143\u7d20\u7ec4\u5408\u8868\u5355\u4e2d\u7684\u76f8\u5173\u6570\u636e\uff0c\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027<\/p>\n<pre><code># disable\u5c5e\u6027\u89c4\u5b9a\u5e94\u8be5\u7981\u7528fieldset\n# form\u5c5e\u6027\u89c4\u5b9afieldset\u6240\u5c5e\u7684\u4e00\u4e2a\u6216\u591a\u4e2a\u8868\u5355\u3002\n# name\u5c5e\u6027\u89c4\u5b9afieldset\u540d\u79f0\u3002\n<\/code><\/pre>\n<hr>\n<h1 id=\"legend\"><strong>legend<\/strong><\/h1>\n<p>legend\u5143\u7d20\u4e3afieldset\u5143\u7d20\u5b9a\u4e49\u6807\u9898\uff0c\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027,\u652f\u6301\u6837\u5f0f\u3002<\/p>\n<hr>\n<h1 id=\"select\"><strong>select<\/strong><\/h1>\n<p>\u5b9a\u4e49\u4e0b\u62c9\u5217\u8868\u3002\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027\u3002<\/p>\n<pre><code>&lt;form action=&quot;action_page.py&quot;&gt;\n&lt;select name=&quot;cars&quot;&gt;\n&lt;option value=&quot;volvo&quot;&gt;volvo&lt;\/option&gt;\n&lt;option value=&quot;audi&quot;&gt;audi&lt;\/option&gt;\n&lt;\/select&gt;\n&lt;\/form&gt;\n# autofocus\u5c5e\u6027\u89c4\u5b9a\u5728\u9875\u9762\u52a0\u8f7d\u540e\u6587\u672c\u533a\u57df\u81ea\u52a8\u83b7\u5f97\u7126\u70b9\n# disable\n# form\n# multiple\n# name\n# required\n# size\n<\/code><\/pre>\n<hr>\n<h1 id=\"optgroup\"><strong>optgroup<\/strong><\/h1>\n<hr>\n<h1 id=\"option\"><strong>option<\/strong><\/h1>\n<p>\u5b9a\u4e49\u9009\u9879\u3002\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027\u3002<\/p>\n<pre><code># disabled\n# label\n# selected\n# value\n<\/code><\/pre>\n<hr>\n<h1 id=\"label\"><strong>label<\/strong><\/h1>\n<hr>\n<h1 id=\"button\"><strong>button<\/strong><\/h1>\n<p>\u5b9a\u4e49\u53ef\u70b9\u51fb\u7684\u6309\u94ae\uff0c\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027\u3002<\/p>\n<pre><code>&lt;button type=&quot;button&quot; onclick=&quot;alert(&quot;hello world&quot;)&quot;&gt;Click Me&lt;\/button&gt;\n# name\u5c5e\u6027\u89c4\u5b9a\u6309\u94ae\u540d\u79f0\n# type\u5c5e\u6027\u89c4\u5b9a\u6309\u94ae\u7c7b\u578b\n# value\u5c5e\u6027\u89c4\u5b9a\u6309\u94ae\u521d\u59cb\u503c\n# autofocus\n# disabled\n# form\n# formaction\n# formenctype\n# formmethod\n# formnovalidate\n# formtarget\n<\/code><\/pre>\n<hr>\n<h1 id=\"textarea\"><strong>textarea<\/strong><\/h1>\n<hr>\n<h1 id=\"datalist\"><strong>datalist<\/strong><\/h1>\n<hr>\n<h1 id=\"keygen\"><strong>keygen<\/strong><\/h1>\n<hr>\n<h1 id=\"output\"><strong>output<\/strong><\/h1>"},{"title":"Bootstrap","link":"https:\/\/canuxcheng.com\/post\/js_bootstrap\/","pubDate":"Thu, 27 Oct 2016 22:19:20 +0800","guid":"https:\/\/canuxcheng.com\/post\/js_bootstrap\/","description":"<h1 id=\"bootstrap\">Bootstrap<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/twbs\/bootstrap\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/twbs\/bootstrap<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/www.bootcss.com\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.bootcss.com\/<\/a><\/p>\n<p>install:<\/p>\n<pre><code>$ npm install bootstrap@next\n<\/code><\/pre>\n<p>HTML,CSS,JavaScript\u7684\u652f\u6301\u54cd\u5e94\u5f0f\u548c\u79fb\u52a8\u8bbe\u5907\u7684WEB\u6846\u67b6.<\/p>"},{"title":"jQuery","link":"https:\/\/canuxcheng.com\/post\/js_jquery\/","pubDate":"Thu, 27 Oct 2016 22:19:20 +0800","guid":"https:\/\/canuxcheng.com\/post\/js_jquery\/","description":"<h1 id=\"jquery\">jQuery<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/jquery\/jquery\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/jquery\/jquery<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/www.jquery123.com\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.jquery123.com\/<\/a><\/p>\n<p>jquery\u662f\u4e00\u4e2ajs\u5e93\uff0c\u7b80\u5316\u4e86js\u7f16\u7a0b\u3002<\/p>\n<p>install:<\/p>\n<pre><code>$ npm install jqury\n<\/code><\/pre>\n<p>jquery\u529f\u80fd\uff1a<\/p>\n<ul>\n<li>HTML \u5143\u7d20\u9009\u53d6<\/li>\n<li>HTML \u5143\u7d20\u64cd\u4f5c<\/li>\n<li>HTML \u4e8b\u4ef6\u51fd\u6570<\/li>\n<li>HTML DOM \u904d\u5386\u548c\u4fee\u6539<\/li>\n<li>CSS \u64cd\u4f5c<\/li>\n<li>JavaScript \u7279\u6548\u548c\u52a8\u753b<\/li>\n<li>AJAX<\/li>\n<li>Utilities<\/li>\n<\/ul>\n<h1 id=\"syntax\">syntax<\/h1>\n<p>\u5bf9\u5143\u7d20\u64cd\u4f5c\u8bed\u6cd5\uff1a<\/p>\n<pre><code>$(selector).action()\n<\/code><\/pre>\n<p>\u6587\u6863\u5c31\u7eea\u51fd\u6570:<\/p>\n<pre><code>$(document).ready(function(){\n......\n})\n<\/code><\/pre>\n<p>head\u4e2d:<\/p>\n<pre><code>&lt;head&gt;\n&lt;script type=&quot;text\/javascript&gt;\n$(document).ready(function(){\n$(&quot;button&quot;).click(function(){\n$(&quot;p&quot;).hide();\n})\n})\n&lt;\/script&gt;\n&lt;\/head&gt;\n<\/code><\/pre>\n<p>\u72ec\u7acbjs\u6587\u4ef6<\/p>\n<pre><code>&lt;head&gt;\n&lt;script type=&quot;text\/javascript&quot; src=&quot;\/path\/to\/my.js&quot;&gt;&lt;\/script&gt;\n&lt;\/head&gt;\n<\/code><\/pre>\n<h1 id=\"\u9009\u62e9\u5668\">\u9009\u62e9\u5668<\/h1>\n<p><a class=\"link\" href=\"https:\/\/api.jquery.com\/category\/selectors\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/api.jquery.com\/category\/selectors\/<\/a><\/p>\n<pre><code>$(this).hide() this\u8868\u793a\u5f53\u524dhtml\u5143\u7d20\n$(&quot;p.test&quot;) class=&quot;test&quot;\u7684&lt;p&gt;&lt;\/p&gt;\u5143\u7d20\n$(&quot;p#test&quot;) id=&quot;test&quot;\u7684&lt;p&gt;&lt;\/p&gt;\u5143\u7d20\n$(&quot;div#test .demo&quot;) id=&quot;test&quot;\u7684&lt;div&gt;&lt;\/div&gt;\u4e2dclass=demo\u7684\u5143\u7d20\n$(&quot;ul li:first&quot;) \u6bcf\u4e2a&lt;ul&gt;&lt;\/ul&gt;\u7684\u7b2c\u4e00\u4e2a&lt;li&gt;&lt;\/li&gt;\n<\/code><\/pre>\n<p>element\u9009\u62e9\u5668\uff1a<\/p>\n<pre><code>$(&quot;p&quot;).hide() \u5143\u7d20&lt;p&gt;&lt;\/p&gt;\n<\/code><\/pre>\n<p>id\u9009\u62e9\u5668:<\/p>\n<pre><code>$(&quot;#test&quot;).hide() id=&quot;test&quot;\n<\/code><\/pre>\n<p>class\u9009\u62e9\u5668:<\/p>\n<pre><code>$(&quot;.test&quot;).hide() class=&quot;test&quot;\n<\/code><\/pre>\n<p>attribute\u9009\u62e9\u5668:<\/p>\n<pre><code>$(&quot;[href]&quot;) \u6240\u6709\u5e26href\u5c5e\u6027\u7684\u5143\u7d20\n$(&quot;[href='value']&quot;) \u5e26\u6709href\u5c5e\u6027\u4e14\u503c\u7b49\u4e8evalue\u7684\u5143\u7d20\n$(&quot;[href!='value']&quot;) \u5e26\u6709href\u5143\u7d20\u4e14\u503c\u4e0d\u7b49\u4e8evalue\u7684\u5143\u7d20\n$(&quot;[href$='.jpg']&quot;) \u5e26\u6709href\u5c5e\u6027\u4e14\u503c\u4ee5.jpg\u7ed3\u5c3e\u7684\u5143\u7d20\n<\/code><\/pre>\n<p>\u5b50\u5143\u7d20\u9009\u62e9\u5668\/child:<\/p>\n<p>\u540e\u4ee3\u9009\u62e9\u5668\/descendant:<\/p>\n<h1 id=\"event\u4e8b\u4ef6\">Event\/\u4e8b\u4ef6<\/h1>\n<p><a class=\"link\" href=\"https:\/\/api.jquery.com\/category\/events\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/api.jquery.com\/category\/events\/<\/a><\/p>\n<pre><code>$(selector).click(function) \u5355\u51fb\u4e8b\u4ef6\n$(selector).dblclick(function) \u53cc\u51fb\u4e8b\u4ef6\n$(selector).focus(function) \u7126\u70b9\u4e8b\u4ef6\n$(selector).mouseover(function) \u9f20\u6807\u60ac\u505c\u4e8b\u4ef6\n<\/code><\/pre>\n<hr>\n<h1 id=\"effects\u6548\u679c\">Effects\/\u6548\u679c<\/h1>\n<h2 id=\"basic\">basic<\/h2>\n<pre><code>.hide()\n.show()\n.toggle()\n<\/code><\/pre>\n<h2 id=\"custom\">custom<\/h2>\n<pre><code>.animate()\n.stop()\n<\/code><\/pre>\n<h2 id=\"fading\">fading<\/h2>\n<pre><code>.fadeIn()\n.fadeOut()\n.fadeTo()\n.fadeToggle()\n<\/code><\/pre>\n<h2 id=\"sliding\">sliding<\/h2>\n<pre><code>.slideDown()\n.slideToggle()\n.slideUp()\n<\/code><\/pre>\n<hr>\n<h1 id=\"core\">core<\/h1>\n<p>\u6838\u5fc3\u529f\u80fd<\/p>\n<h2 id=\"jquery-1\">jQuery()<\/h2>\n<h2 id=\"jquerynoconflict\">jQuery.noConflict()<\/h2>\n<p>\u4f7f\u7528\u5176\u5b83\u4ee3\u66ff$<\/p>\n<pre><code>&lt;script type=&quot;text\/javascript&gt;\n$.noConflict(); \/\/ \u517c\u5bb9\u5176\u5b83\u5e93\u4e5f\u662f\u7528$\nmy(document).ready(function(){\nmy(&quot;button&quot;).click(function(){\nmy(&quot;p&quot;).hide();\n})\n})\n&lt;\/script&gt;\n<\/code><\/pre>\n<h2 id=\"jqueryready\">jQuery.ready<\/h2>\n<hr>\n<h1 id=\"\u6587\u6863\u64cd\u4f5c\">\u6587\u6863\u64cd\u4f5c<\/h1>\n<h1 id=\"\u5c5e\u6027\u64cd\u4f5c\">\u5c5e\u6027\u64cd\u4f5c<\/h1>\n<h1 id=\"css\u64cd\u4f5c\">CSS\u64cd\u4f5c<\/h1>\n<p>jquey css\u9009\u62e9\u5668\u6539\u53d8\u5143\u7d20\u7684css\u5c5e\u6027:<\/p>\n<pre><code>.css()\n\/\/ \u4fee\u6539&lt;p&gt;&lt;\/p&gt;\u5143\u7d20\u7684\u80cc\u666f\u8272\n$(&quot;p&quot;).css(&quot;background-color&quot;,&quot;red&quot;);\n.addClass()\n.hasClass()\n<\/code><\/pre>\n<hr>\n<h1 id=\"attributes\">Attributes<\/h1>\n<pre><code>.attr()\n.addClass()\n.hasClass()\n.html()\n.val()\n<\/code><\/pre>\n<hr>\n<h1 id=\"data\">Data<\/h1>\n<pre><code>.data()\n.clearQueue()\n.dequeue()\n.queue()\n.removeData()\n<\/code><\/pre>\n<hr>\n<h1 id=\"ajax\">Ajax<\/h1>"},{"title":"Test","link":"https:\/\/canuxcheng.com\/post\/django_test\/","pubDate":"Tue, 04 Oct 2016 04:51:30 +0000","guid":"https:\/\/canuxcheng.com\/post\/django_test\/","description":"<h1 id=\"testspy\">tests.py<\/h1>\n<p><a class=\"link\" href=\"https:\/\/docs.djangoproject.com\/zh-hans\/3.1\/topics\/testing\/tools\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.djangoproject.com\/zh-hans\/3.1\/topics\/testing\/tools\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/docs.djangoproject.com\/zh-hans\/3.1\/topics\/testing\/advanced\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.djangoproject.com\/zh-hans\/3.1\/topics\/testing\/advanced\/<\/a><\/p>\n<p>\u5355\u4e2a\u6d4b\u8bd5\u6587\u4ef6<\/p>\n<pre><code>vim app\/tests.py\nfrom django.test import TestCase\n<\/code><\/pre>\n<p>\u591a\u4e2a\u6d4b\u8bd5\u6587\u4ef6<\/p>\n<pre><code>mkdir -p app\/tests\nvi test_case1.py\nvi test_case2.py\n<\/code><\/pre>\n<h1 id=\"\u914d\u7f6e\u548c\u8fd0\u884c\">\u914d\u7f6e\u548c\u8fd0\u884c<\/h1>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u8fd0\u884c manage.py test \u4f1a\u521b\u5efa\u6d4b\u8bd5\u6570\u636e\u5e93\u8fd0\u884ctestcase\uff0c\u5b8c\u6210\u540e\u81ea\u52a8\u9500\u6bc1\u6d4b\u8bd5\u6570\u636e\u5e93.<\/p>\n<p>\u6d4b\u8bd5\u76f8\u5173\u914d\u7f6e<\/p>\n<pre><code>vim project\/settings.py\nDATABASES = {\n'default': {\n'NAME': 'mydb',\n'TEST': {\n\/\/ \u9ed8\u8ba4\u6d4b\u8bd5\u6570\u636e\u5e93\u662f'NAME'\u524d\u52a0'test_' (eg: 'test_mydb')\n\/\/ \u53ef\u4ee5\u901a\u8fc7TEST.NAME\u6307\u5b9a\u6d4b\u8bd5\u6570\u636e\u5e93\n'NAME': 'mytestdb'\n}\n}\n}\n# \u6307\u5b9arunner\n## \u9ed8\u8ba4 django.test.runner.DiscoverRunner\nTEST_RUNNER = 'site_main.base_tests.TestRunner\n# \u6307\u5b9afixture\u6587\u4ef6\u8def\u5f84\nFIXTURE_DIRS = (os.path.join(BASE_DIR, 'app', 'fixtures'), )\n<\/code><\/pre>\n<p>\u8fd0\u884c\u6d4b\u8bd5\u7a0b\u5e8f\uff1a<\/p>\n<pre><code>$ python3 manage.py test \/\/ \u67e5\u627etest \u5f00\u5934\u7684\u6587\u4ef6\u8fd0\u884c\u91cc\u9762\u7684 unittest.TestCase\u7684\u5b50\u7c7b.\n$ python3 manage.py test &lt;package&gt; \/\/ \u8fd0\u884c\u6307\ufe0f\u5b9a\u5e94\u7528\u5185\u7684\u6d4b\u8bd5\n$ python3 manage.py test &lt;module&gt; \/\/ \u8fd0\u884c\u6307\u5b9a\u6a21\u5757\u5185\u7684\u6d4b\u8bd5\n$ python3 manage.py test &lt;module&gt;.tests.MyTestCase \/\/ \u8fd0\u884c\u4e00\u4e2a\u6307\u5b9a\u7684testcase\n$ python3 manage.py test &lt;module&gt;.tests.MyTestCase.test_method \/\/ \u8fd0\u884c\u4e00\u4e2a\u6307\u5b9a\u7684test method\n--keepdb \/\/ \u4fdd\u7559\u6d4b\u8bd5\u6570\u636e\u5e93\n--parallel \/\/ \u5e76\u884c\u8fd0\u884c\u6d4b\u8bd5\u3002\n-v\/--verbosity 0\/1\/2\/3 \u6d4b\u8bd5\u8f93\u51fa\u4fe1\u606f\u7ea7\u522b\uff0c\u9ed8\u8ba4\u4e3a1\uff0c 0\u8868\u793a\u4e0d\u8f93\u51fa\u3002\n-d\/--debug-sql \u8f93\u51fa\u6d4b\u8bd5\u6267\u884c\u7684sql\u8bed\u53e5.\n<\/code><\/pre>\n<hr>\n<h1 id=\"client\">Client<\/h1>\n<p>\u6d4b\u8bd5\u5ba2\u6237\u7aef\u662f\u4e00\u4e2a Python \u7c7b\uff0c\u5b83\u5145\u5f53\u4e00\u4e2a\u865a\u62df\u7684 Web \u6d4f\u89c8\u5668\uff0c\n\u5141\u8bb8\u4f60\u6d4b\u8bd5\u89c6\u56fe\u5e76\u4ee5\u7f16\u7a0b\u65b9\u5f0f\u4e0e Django \u9a71\u52a8\u7684\u5e94\u7528\u7a0b\u5e8f\u4ea4\u4e92\u3002<\/p>\n<pre><code>from django.test import Client\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u6d4b\u8bd5class\">\u6d4b\u8bd5Class<\/h1>\n<h2 id=\"simpletestcase\">SimpleTestCase<\/h2>\n<p>SimpleTestCase\u7ee7\u627f\u81eaunittest.TestCase.<\/p>\n<h2 id=\"transactiontestcase\">TransactionTestCase<\/h2>\n<p>TransactionTestCase\u7ee7\u627f\u81eaSimpleTestCase.<\/p>\n<h2 id=\"liveservertestcase\">LiveServerTestCase<\/h2>\n<p>LiveServerTestCase\u7ee7\u627f\u81eaTransactionTestCase.<\/p>\n<p>LiveServerTestCase \u548c TransactionTestCase` \u7684\u529f\u80fd\u57fa\u672c\u76f8\u540c\uff0c\n\u4f46\u591a\u4e86\u4e00\u4e2a\u529f\u80fd\uff1a\u5b83\u5728\u8bbe\u7f6e\u65f6\u5728\u540e\u53f0\u542f\u52a8\u4e00\u4e2a\u5b9e\u65f6\u7684 Django \u670d\u52a1\u5668\uff0c\u5e76\u5728\u5173\u95ed\u65f6\u5c06\u5176\u5173\u95ed\u3002\n\u8fd9\u5c31\u5141\u8bb8\u4f7f\u7528 Django \u865a\u62df\u5ba2\u6237\u7aef \u4ee5\u5916\u7684\u81ea\u52a8\u5316\u6d4b\u8bd5\u5ba2\u6237\u7aef\uff0c\n\u4f8b\u5982\uff0cSelenium \u5ba2\u6237\u7aef\uff0c\u5728\u6d4f\u89c8\u5668\u5185\u6267\u884c\u4e00\u7cfb\u5217\u529f\u80fd\u6d4b\u8bd5\uff0c\u5e76\u6a21\u62df\u771f\u5b9e\u7528\u6237\u7684\u64cd\u4f5c\u3002<\/p>\n<h2 id=\"testcase\">TestCase<\/h2>\n<p>TestCase\u7ee7\u627f\u81eaTransactionTestCase.<\/p>\n<h2 id=\"fixtures\">fixtures<\/h2>\n<p>fixtures\u662f\u7c7b\u5c5e\u6027, \u53ef\u4ee5\u901a\u8fc7\u6a21\u62df\u5728\u6570\u636e\u5e93\u4e2d\u63d2\u5165\u6570\u636e\u8fdb\u884c\u6d4b\u8bd5.<\/p>\n<p>\u5728setUp\u7684\u65f6\u5019\u4f1a\u63d2\u5165fixtures\u6307\u5b9a\u7684json\u6587\u4ef6\u4e2d\u7684\u6570\u636e\u3002<\/p>\n<p>\u5728tearDown\u7684\u65f6\u5019\u4f1a\u9500\u6bc1\u6570\u636e\u3002<\/p>\n<pre><code># \u5bfc\u51fa\u6570\u636e\u4e3ajson\u683c\u5f0f\uff0c\u7528\u4e8e\u5355\u5143\u6d4b\u8bd5\n$ python3 manage.py dumpdata &gt; test_data.json\n<\/code><\/pre>\n<h2 id=\"databases\">databases<\/h2>\n<p>databases\u662f\u7c7b\u5c5e\u6027<\/p>"},{"title":"Form","link":"https:\/\/canuxcheng.com\/post\/django_form\/","pubDate":"Tue, 04 Oct 2016 04:30:02 +0000","guid":"https:\/\/canuxcheng.com\/post\/django_form\/","description":"<h1 id=\"formspy\">forms.py<\/h1>\n<pre><code>from django import forms\n<\/code><\/pre>\n<h1 id=\"\u8868\u5355\">\u8868\u5355<\/h1>\n<p>\u7528\u6237\u5728\u6d4f\u89c8\u5668\u4e2d\u8f93\u5165\u6570\u636e\u63d0\u4ea4\uff0c\u5bf9\u6570\u636e\u9a8c\u8bc1\u4ee5\u53ca\u8f93\u5165\u6846\u7684\u751f\u6210\u7b49\u3002<\/p>\n<p>django\u7684\u8868\u5355\u7cfb\u7edf\u7684\u6838\u5fc3\u7c7b\u662fdjango.forms.Form\u7c7b,\u6240\u6709\u7684\u6784\u5efa\u7684\u8868\u5355\u90fd\u662f\u8fd9\u4e2a\u7c7b\u7684\u5b50\u7c7b\u3002<\/p>"},{"title":"Admin","link":"https:\/\/canuxcheng.com\/post\/django_admin\/","pubDate":"Tue, 04 Oct 2016 04:29:37 +0000","guid":"https:\/\/canuxcheng.com\/post\/django_admin\/","description":"<h1 id=\"adminpy\">admin.py<\/h1>\n<pre><code>from django.contrib import admin\n<\/code><\/pre>\n<p>\u521b\u5efa\u4e00\u4e2a\u7ba1\u7406\u5458\u7528\u6237\uff1a<\/p>\n<pre><code>$ python manage.py createsuperuser\n<\/code><\/pre>\n<p>\u7ba1\u7406\u5458\u767b\u9646\u754c\u9762\uff1a<\/p>\n<pre><code>http:\/\/localhost:8000\/admin\/\n<\/code><\/pre>\n<p>\u5728admin.py\u4e2d\u6ce8\u518c\u6a21\u578b\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u5728\u767b\u9646\u754c\u9762\u7ba1\u7406\u6a21\u578b\u4e86<\/p>\n<pre><code>from .models import Question\nadmin.site.register(Question)\n<\/code><\/pre>\n<p>\u81ea\u5b9a\u4e49\u7ba1\u7406\u8868\u5355\uff1a<\/p>\n<pre><code>from .models import Question\nclass QuestionAdmin(admin.ModelAdmin):\nfileds = ['pub_date', 'question_date']\nadmin.site.register(Question, QuestionAdmin)\n<\/code><\/pre>\n<p>\u628a\u8868\u5355\u5206\u5272\u6210\u5b57\u6bb5\u96c6\uff1a<\/p>\n<pre><code>from .models import Question\nclass QuestionAdmin(admin.ModelAdmin):\nfieldsets = [\n(None, {'fields': ['question_text']}),\n('Date information', {'fields': ['pub_date']}),\n]\nadmin.site.register(Question, QuestionAdmin)\n<\/code><\/pre>\n<h1 id=\"\u540e\u53f0\">\u540e\u53f0<\/h1>\n<p>django\u7684\u540e\u53f0\u7ba1\u7406\u7a0b\u5e8f\u3002<\/p>"},{"title":"URL","link":"https:\/\/canuxcheng.com\/post\/django_url\/","pubDate":"Tue, 04 Oct 2016 04:20:39 +0000","guid":"https:\/\/canuxcheng.com\/post\/django_url\/","description":"<h1 id=\"urlspy\">urls.py<\/h1>\n<pre><code>from django.urls import path, include\n<\/code><\/pre>\n<p>django\u8bf7\u6c42\u7ad9\u70b9\u7684\u65b9\u6cd5\uff1a<\/p>\n<ol>\n<li>ROOT_URLCONF\uff0c\u5728settings.py\u4e2d\u8bbe\u7f6e\u3002<\/li>\n<li>\u5bfb\u627eurlpatterns\uff0c\u5b83\u662fdjango.conf.urls.url()\u5b9e\u4f8b\u7684\u4e00\u4e2apython\u5217\u8868\u3002<\/li>\n<li>dnango\u4f9d\u6b21\u5339\u914d\u6bcf\u4e2aURL\u6a21\u5f0f\uff0c\u5728\u7b2c\u4e00\u4e2a\u5339\u914d\u505c\u4e0b\u3002<\/li>\n<li>\u4e00\u65e6\u4e00\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\uff0cdjango\u5c31\u8c03\u7528\u5bf9\u5e94\u7684\u89c6\u56fe\uff0c\u89c6\u56fe\u83b7\u5f97HttpRequest\u5b9e\u4f8b,\u5982\u679c\u662f\u6ca1\u6709\u547d\u540d\u7684\u7ec4\u8fd4\u56de\u5185\u5bb9\u4f5c\u4e3a\u4f4d\u7f6e\u53c2\u6570\uff0c\u5982\u679c\u662f\u547d\u540d\u7684\u7ec4\u8fd4\u56de\u5185\u5bb9\u4f5c\u4e3a\u5173\u952e\u5b57\u53c2\u6570\u3002<\/li>\n<li>\u5982\u679c\u6ca1\u6709\u5339\u914d\u5230\u6216\u8005\u8fc7\u7a0b\u8dd1\u51fa\u5f02\u5e38\uff0cdjango\u8c03\u7528\u5408\u9002\u7684\u9519\u8bef\u5904\u7406\u3002<\/li>\n<\/ol>\n<h1 id=\"\u9879\u76ee\u7684url\">\u9879\u76ee\u7684URL<\/h1>\n<p>\u9879\u76ee\u7684URL\u4e3b\u8981\u7528\u6765\u5305\u542b\u5e94\u7528\u7684URL\u4ee5\u53ca\u5168\u5c40\u7684URL:<\/p>\n<pre><code>from django.contrib import admin\nfrom django.urls import path, include\nurlpatterns = [\n# \u9ed8\u8ba4\u7684\u9879\u76ee\u7684admin\u7684url\npath('admin\/', admin.site.urls),\n# \u5728\u9879\u76eeURL\u6dfb\u52a0\u94fe\u63a5\u5230\u5e94\u7528URL\uff1a\n# \u5728\u4e0b\u9762\u6dfb\u52a0\u4f60\u7684\u6240\u6709\u5e94\u7528\u7684url,\npath('polls\/', include('polls.urls')),\n]\n<\/code><\/pre>\n<h1 id=\"\u5e94\u7528\u7684url\">\u5e94\u7528\u7684URL<\/h1>\n<p>\u5c06\u5e94\u7528\u7684\u89c6\u56fe\u6620\u5c04\u5230URL,\u9700\u8981\u5728\u5e94\u7528\u76ee\u5f55\u65b0\u5efaurls.py\u6587\u4ef6,\u7136\u540e\u5728\u9879\u76ee\u7684url\u4e2d\u5305\u542b\u5e94\u7528\u7684url\u3002<\/p>\n<p>urlpatterns\u662furl()\u5b9e\u4f8b\u7c7b\u578b\u7684python\u5217\u8868\u3002<\/p>\n<pre><code>from django.urls import path\nfrom . import views\napp_name = 'polls'\nurlpatterns = [\n# \u666e\u901a\u89c6\u56fe\npath('', views.index, name='index'),\n# \u7c7b\u89c6\u56fe\npath('', views.IndexView.as_view(), name='index'),\n]\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u6ca1\u6709\u547d\u540d\u7684\u7ec4\">\u6ca1\u6709\u547d\u540d\u7684\u7ec4<\/h1>\n<p>\u89c6\u56fe\u51fd\u6570\u53ea\u6709request\u53c2\u6570\uff0c\u5339\u914d\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u4f5c\u4e3a\u4f4d\u7f6e\u53c2\u6570\u3002<\/p>\n<pre><code>url(r'^pattern1\/pattern2\/$', views.index, name='index'),\ndef index(request):\n...\n<\/code><\/pre>\n<h1 id=\"\u547d\u540d\u7ec4\">\u547d\u540d\u7ec4<\/h1>\n<p>\u89c6\u56fe\u51fd\u6570\u9664\u4e86request\u53c2\u6570\u8fd8\u6709\u5173\u952e\u5b57\u53c2\u6570\uff0c\u5339\u914d\u7684\u547d\u540d\u8868\u8fbe\u5f0f\u7ec4\u4f5c\u4e3a\u5173\u952e\u5b57\u53c2\u6570,\u8986\u76d6\u9ed8\u8ba4\u7684\u5173\u952e\u5b57\u53c2\u6570\u3002<\/p>\n<p>\u4f7f\u7528\u547d\u540d\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u7ec4\uff1a (?P<!-- raw HTML omitted -->pattern)<\/p>\n<p>name\u5c31\u662f\u5173\u952e\u5b57\u53c2\u6570\u3002<\/p>\n<pre><code>url(r'^pattern1\/(?P&lt;name&gt;pattern)\/pattern2\/$), views.index, name='index),\ndef index(request, name):\n...\n<\/code><\/pre>\n<h1 id=\"\u9519\u8bef\u5904\u7406\">\u9519\u8bef\u5904\u7406<\/h1>\n<p>django\u4f1a\u8c03\u7528\u4e00\u4e2a\u9519\u8bef\u5904\u7406\u89c6\u56fe\u5904\u7406\u5f02\u5e38\u3002<\/p>\n<ol>\n<li>handler404 \u9875\u9762\u6ca1\u627e\u5230<\/li>\n<li>handler500 \u670d\u52a1\u5668\u9519\u8bef<\/li>\n<li>handler403 \u6743\u9650\u88ab\u62d2\u7edd<\/li>\n<li>handler400 \u65e0\u6548\u7684\u8bf7\u6c42<\/li>\n<\/ol>\n<p>\u4f60\u4e5f\u53ef\u4ee5\u5728\u9879\u76ee\u7684urls.py\u4e2d\u91cd\u65b0\u5b9a\u4e49\u8fd9\u4e9b\u9ed8\u8ba4\u89c6\u56fe\uff1a<\/p>\n<pre><code>handler404 = 'mysite.views.your_custom_page_not_found_view'\nhandler500 = 'mysite.views.your_custom_error_view'\nhandler403 = 'mysite.views.your_custom_permission_denied_view'\nhandler400 = 'mysite.views.your_custom_bad_request_view'\n<\/code><\/pre>"},{"title":"View","link":"https:\/\/canuxcheng.com\/post\/django_view\/","pubDate":"Tue, 04 Oct 2016 04:20:39 +0000","guid":"https:\/\/canuxcheng.com\/post\/django_view\/","description":"<h1 id=\"viewspy\">views.py<\/h1>\n<pre><code>from django.shortcuts import render\n<\/code><\/pre>\n<p>\u5b9a\u4e49\u81ea\u5df1\u7684\u89c6\u56fe\u51fd\u6570\uff1a<\/p>\n<pre><code>from django.http import HttpResponse\nfrom django.template import RequestContext, loader\n# \u5bfc\u5165\u6a21\u677f\u4e2d\u7684\u7c7b\nfrom .models import Question\ndef index(request):\n...\nt = loader.get_template('application\/index.html')\nc = RequestContext(request, {'foo': 'bar'})\nreturn HttpResponse(t.render(c), content_type=&quot;text\/html&quot;)\n<\/code><\/pre>\n<p>\u5f53\u8bf7\u6c42\u4e00\u4e2a\u9875\u9762\u65f6django\u4f1a\u5efa\u7acb\u4e00\u4e2a\u5305\u542b\u8bf7\u6c42\u5143\u6570\u636e\u7684HttpRequest\u5bf9\u8c61\uff0c\u5f53django\u52a0\u8f7d\u5bf9\u5e94\u89c6\u56fe\u65f6\uff0c\u8fd9\u4e2a\u5bf9\u8c61\u4f5c\u4e3a\u89c6\u56fe\u7b2c\u4e00\u4e2a\u53c2\u6570\u3002<\/p>\n<p>\u6bcf\u4e2a\u89c6\u56fe\u4f1a\u8fd4\u56de\u4e00\u4e2aHttpResponse\u5bf9\u8c61\u3002<\/p>\n<p>\u6bcf\u4e2a\u89c6\u56fe\u51fd\u6570\u90fd\u7528HttpRequest\u5bf9\u8c61\uff08\u901a\u5e38\u7528request\uff09\u4f5c\u4e3a\u7b2c\u4e00\u4e2a\u53c2\u6570\u3002<\/p>\n<p>\u6bcf\u4e2a\u89c6\u56fe\u51fd\u6570\u90fd\u8fd4\u56de\u4e00\u4e2aHttpResponse\u5bf9\u8c61\uff0c\u5305\u542b\u751f\u6210\u7684\u54cd\u5e94\u3002<\/p>\n<p>HttpRquest\u548cHttpResponse\u5728django.http\u5305\u4e2d\uff0c\u53c2\u8003\uff1a<\/p>\n<p><a class=\"link\" href=\"http:\/\/python.usyiyi.cn\/documents\/django_182\/ref\/request-response.html\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/python.usyiyi.cn\/documents\/django_182\/ref\/request-response.html<\/a><\/p>\n<p>HttpRequest\u5bf9\u8c61\u5c5e\u6027\uff1a<\/p>\n<pre><code>request.scheme # http\/https\nrequest.body\nrequest.path\nrequest.path_info\nrequest.method # GET\/POST\nrequest.encoding\nrequest.user\nrequest.session\nrequest.urlconf\nrequest.GET\nrequest.POST\nrequest.REQUEST\nrequest.COOKIES\nrequest.FILES\nrequest.META\n<\/code><\/pre>\n<p>HttpRequest\u5bf9\u8c61\u65b9\u6cd5\uff1a<\/p>\n<pre><code>request.get_host()\n...\n<\/code><\/pre>\n<p>HttpResponse\u5bf9\u8c61\u5c5e\u6027\uff1a<\/p>\n<pre><code>response.content\nresponse.charset\nresponse.status_code\nresponse.reason_phrase\nresponse.streaming\nresponse.closed\n<\/code><\/pre>\n<p>HttpResponse\u5bf9\u8c61\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre><code>response.getvalue()\n...\n<\/code><\/pre>\n<p>\u8fd4\u56de\u9519\u8bef\uff1a<\/p>\n<p>HttpResponse\u7684\u5b50\u7c7b\u63d0\u4f9b\u4e86\u5bf9\u4e0d\u540c\u7c7b\u578bHTTP\u54cd\u5e94\u3002<\/p>\n<pre><code>from django.http import HttpResponseBadRequest, HttpResponseNotFound, HttpResponseForbidden, HttpResponseServerError,\nreturn HttpResponseNotFound(&quot;&lt;h1&gt;Page not found&lt;\/h1&gt;&quot;)\n<\/code><\/pre>\n<p>http404\u5f02\u5e38\uff1a<\/p>\n<p>\u5728\u5e94\u7528\u7684\u6a21\u677f\u76ee\u5f55\u9876\u5c42\u5b9a\u4e49\u4e00\u4e2a404.html\u6a21\u677f\u6587\u4ef6\uff0c\u5f53\u8dd1\u51faHttp404\u5f02\u5e38\u5c31\u4f1a\u8c03\u7528\u8fd9\u4e2a\u6a21\u677f\u6587\u4ef6\u5c55\u793a\u3002<\/p>\n<pre><code>from django.http import Http404\ndef index(request):\ntry:\n...\nexcept Application.DoesNotExist:\nraise Http404(&quot;Application does not exist&quot;)\nreturn HttpResponse(...)\n<\/code><\/pre>\n<p>\u81ea\u5b9a\u4e49\u9519\u8bef\u89c6\u56fe\uff1a<\/p>\n<p>\u53c2\u8003urls\u4e2d\u7684\u5185\u5bb9\u3002<\/p>\n<h1 id=\"\u5feb\u6377\u51fd\u6570\">\u5feb\u6377\u51fd\u6570<\/h1>\n<p>django.shortcuts\u4e2d\u5b9a\u4e49\u4e86\u591a\u4e2a\u5feb\u6377\u51fd\u6570\u3002<\/p>\n<pre><code>from django.shortcuts import render\nrender(request, template_name, context=None, context_instance=&lt;object object&gt;, content_type=None, status=None, current_app=&lt;object object&gt;, dirs=&lt;object object&gt;, dictionary=&lt;object object&gt;, using=None)\n# render\u7b2c\u4e00\u4e2a\u53c2\u6570\u662frequest\uff0c\u6839\u636e\u7ed9\u5b9a\u6a21\u677f\u548c\u4e0a\u4e0b\u6587\u5b57\u5178\uff0c\u8fd4\u56de\u4e00\u4e2a\u6e32\u67d3\u540e\u7684HttpResponse\u5bf9\u8c61\u3002\nreturn render(request, 'application\/index.html', {'foo': 'bar'}, content_type=&quot;text\/html&quot;)\nfrom django.shortcuts import get_object_or_404\nget_object_or_404(klass, *args, **kwargs)\n# \u5728\u7ed9\u5b9a\u7684\u6a21\u578b\u7ba1\u7406\u5668\u8c03\u7528get()\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u5f15\u53d1Http404\u5f02\u5e38\u3002\n<\/code><\/pre>\n<h1 id=\"\u57fa\u4e8e\u7c7b\u7684\u89c6\u56fe\">\u57fa\u4e8e\u7c7b\u7684\u89c6\u56fe<\/h1>\n<p>\u57fa\u4e8e\u7c7b\u7684\u89c6\u56fe\u7684\u57fa\u7c7b\u5728django.views.generic\u4e2d<\/p>\n<pre><code>from django.views.generic import View\ndef MyView(View):\ndef get(self, request):\nreturn HttpResponse(...)\n<\/code><\/pre>\n<h1 id=\"templateresponse\u548csimpletemplateresponse\">TemplateResponse\u548cSimpleTemplateResponse<\/h1>\n<pre><code>from django.template.response import TemplateResponse, SimpleTemplateResponse\n<\/code><\/pre>\n<h1 id=\"\u89c6\u56fe\u88c5\u9970\u5668\">\u89c6\u56fe\u88c5\u9970\u5668<\/h1>\n<p>django.views.decorators\u5305\u4e2d\u5b9a\u4e49\u4e86\u89c6\u56fe\u7684\u88c5\u9970\u5668\u3002<\/p>\n<pre><code>from django.views.decorators import *\n<\/code><\/pre>\n<h1 id=\"\u5185\u5efa\u7684\u89c6\u56fe\">\u5185\u5efa\u7684\u89c6\u56fe<\/h1>\n<p>django.views.static.serve\u5b9a\u4e49\u4e86\u5f00\u53d1\u73af\u5883\u7684\u6587\u4ef6\u670d\u52a1\u5668\u89c6\u56fe\uff0c\u4ec5\u7528\u4e8e\u5f00\u53d1\u3002<\/p>\n<pre><code>from django.views.static import serve\n<\/code><\/pre>\n<p>django.views.defaults\u5b9a\u4e49\u4e86\u5185\u5efa\u7684\u9519\u8bef\u5904\u7406\u7684\u89c6\u56fe<\/p>\n<pre><code>from django.views.defaults import *\n<\/code><\/pre>"},{"title":"Model","link":"https:\/\/canuxcheng.com\/post\/django_model\/","pubDate":"Tue, 04 Oct 2016 04:20:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/django_model\/","description":"<h1 id=\"modelspy\">models.py<\/h1>\n<p>ORM(Object Relational Mapping)\u662f\u5bf9\u8c61\u5173\u7cfb\u6620\u5c04\u3002<\/p>\n<pre><code>from django.db import models\n<\/code><\/pre>\n<p>django\u6a21\u578b\u662f\u548c\u6570\u636e\u5e93\u5173\u8054\u7684\uff0c\u4ee3\u7801\u653e\u5728models.py\uff0c\u6570\u636e\u5e93\u4fe1\u606f\u5728settings.py\u4e2d\u7edf\u4e00\u914d\u7f6e\u5373\u53ef\u3002<\/p>\n<p>\u6bcf\u4e2a\u6a21\u578b\u5bf9\u5e94\u6570\u636e\u5e93\u552f\u4e00\u7684\u4e00\u5f20\u8868\uff0c\u662fdjango.db.models.Model\u7684\u5b50\u7c7b\u3002<\/p>\n<p>\u6bcf\u4e2a\u6a21\u578b\u5b9e\u4f8b\u4ee3\u8868\u6570\u636e\u5e93\u4e2d\u7684\u4e00\u6761\u7279\u5b9a\u8bb0\u5f55.<\/p>\n<p>\u6a21\u578b\u7684\u6bcf\u4e2a\u5c5e\u6027\u90fd\u8868\u793a\u4e3a\u6570\u636e\u5e93\u4e2d\u7684\u4e00\u4e2a\u5b57\u6bb5\u3002<\/p>\n<ul>\n<li>\n<p>\u5728\u9879\u76ee\u7684settings.py\u4e2d\u6fc0\u6d3b\u5e94\u7528\uff0c\u5e76\u8bbe\u7f6e\u6570\u636e\u5e93\u76f8\u5173\u53c2\u6570\u3002<\/p>\n<\/li>\n<li>\n<p>\u8ba9django\u5305\u542b\u4f60\u7684\u5e94\u7528\uff1a<\/p>\n<p>\u544a\u8bc9django\u4f60\u5bf9\u6a21\u578b\u505a\u4e86\u66f4\u6539\uff0c\u5e76\u4e14\u5c06\u8fd9\u4e9b\u66f4\u6539\u5b58\u50a8\u4e3a\u8fc1\u79fb\u6587\u4ef6polls\/migrations\/0001_initial.py:<\/p>\n<pre><code> $python manage.py makemigrations polls\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u67e5\u770b\u8fc1\u79fb\u6587\u4ef6\u6267\u884c\u4e86\u54ea\u4e9bsql\u8bed\u53e5,\u5e76\u4e0d\u771f\u7684\u5728\u6570\u636e\u5e93\u6267\u884c\uff1a<\/p>\n<pre><code> $python manage.py sqlmigrate polls 0001\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u68c0\u67e5\u9879\u76ee\u4e2d\u7684\u6a21\u578b\u662f\u5426\u5b58\u5728\u95ee\u9898\uff1a<\/p>\n<pre><code> $python manage.py check\n<\/code><\/pre>\n<p>\u5728\u6570\u636e\u5e93\u4e2d\u521b\u5efa\u6a21\u578b,\u67e5\u627e\u8fd8\u6ca1\u6709\u88ab\u5e94\u7528\u7684\u8fc1\u79fb\u6587\u4ef6\u7136\u540e\u548c\u6570\u636e\u5e93\u540c\u6b65\uff1a<\/p>\n<pre><code> $python manage.py migrate\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<hr>\n<h1 id=\"\u6a21\u578b\u7684\u5b57\u6bb5\u7c7b\u578b\u548c\u5b57\u6bb5\u9009\u9879\">\u6a21\u578b\u7684\u5b57\u6bb5\u7c7b\u578b\u548c\u5b57\u6bb5\u9009\u9879<\/h1>\n<p>\u6a21\u578b\u7684\u6bcf\u4e2a\u5c5e\u6027\u90fd\u8868\u793a\u4e3a\u6570\u636e\u5e93\u7684\u4e00\u4e2a\u5b57\u6bb5,\u662fField\u5b50\u7c7b\u7684\u67d0\u4e2a\u5b9e\u4f8b\u3002<\/p>\n<p>\u6a21\u578b\u7684\u5b57\u6bb5\u8fd8\u6709\u4e00\u4e9b\u9009\u9879\u3002<\/p>\n<p>\u5b57\u6bb5\u547d\u540d\u89c4\u5219\uff1a<\/p>\n<ol>\n<li>\u4e0d\u80fd\u662fpython\u7684\u4fdd\u7559\u5173\u952e\u5b57\u3002<\/li>\n<li>\u5b57\u6bb5\u540d\u4e2d\u8fde\u7eed\u7684\u4e0b\u5212\u7ebf\u4e0d\u80fd\u8d85\u8fc7\u4e00\u4e2a\u3002<\/li>\n<\/ol>\n<p>\u8bbf\u95ee\u5176\u5b83\u5e94\u7528\u7684\u6a21\u578b,\u5bfc\u5165\u5373\u53ef\uff1a<\/p>\n<pre><code>from &lt;other-aplication&gt;.models import &lt;module-name&gt;\n<\/code><\/pre>\n<p>\u6a21\u578b\u5b57\u6bb5\u7c7b\u578b\u548c\u9009\u9879\u53c2\u8003\uff1a<\/p>\n<p><a class=\"link\" href=\"http:\/\/python.usyiyi.cn\/documents\/django_182\/ref\/models\/fields.html#common-model-field-options\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/python.usyiyi.cn\/documents\/django_182\/ref\/models\/fields.html#common-model-field-options<\/a><\/p>\n<h2 id=\"\u6a21\u578b\u5b57\u6bb5\u7c7b\u578b\">\u6a21\u578b\u5b57\u6bb5\u7c7b\u578b<\/h2>\n<p>\u5b57\u6bb5\u7684\u7c7b\u578b\u90fd\u662fField\u7c7b\u7684\u5b50\u7c7b\uff1a<\/p>\n<p>\u6bcf\u4e2a\u5b57\u6bb5\u90fd\u63a5\u53d7\u4e00\u4e2a\u53ef\u9009\u7684\u4f4d\u7f6e\u53c2\u6570(\u4e00\u822c\u662f\u7b2c\u4e00\u4e2a\uff09\uff0c\u53eb\u5b57\u6bb5\u7684\u81ea\u8ff0\u540d,\u5982\u679c\u4e0d\u6307\u5b9a\u5c31\u9ed8\u8ba4\u662f\u5b57\u6bb5\u540d\u5b57\uff08\u4e0b\u5212\u7ebf\u6362\u6210\u7a7a\u683c\uff09\u3002<\/p>\n<p>\u81ea\u589e\u5b57\u6bb5:<\/p>\n<pre><code>AutoField\n# \u9ed8\u8ba4django\u4f1a\u6bcf\u4e2a\u6a21\u578b\u6dfb\u52a0\u4e00\u4e2a\u81ea\u589e\u4e3b\u952e\u5b57\u6bb5,\u5982\u679c\u4f60\u663e\u793a\u8bbe\u7f6e\u4e00\u4e2a\u81ea\u589e\u4e3b\u952e\u5b57\u6bb5\u5c31\u4e0d\u4f1a\u9ed8\u8ba4\u518d\u6dfb\u52a0,\u6bcf\u4e2a\u6a21\u578b\u53ea\u80fd\u6709\u4e00\u4e2a\u4e3b\u952e\u5b57\u6bb5\u3002\n# id = models.AutoField(primary_key=True)\n<\/code><\/pre>\n<p>\u666e\u901a\u5b57\u6bb5:<\/p>\n<pre><code>BigIntegerField\nBinaryField\nBooleanField\nCharField\nCommaSeparatedIntegerField\nDateField\nDateTimeField\nDecimalField\nDurationField\nEmailField\nFileField\nFilePathField\nFloatField\nGenericIPAddressField\nIPAddressField\nImageField\nIntegerField\nNullBooleanField\nPositiveIntegerField\nPositiveSmallIntegerField\nSlugField\nSmallIntegerField\nTextField\nTimeField\nURLField\nUUIDField\n<\/code><\/pre>\n<p>\u5173\u7cfb\u5b57\u6bb5:<\/p>\n<p>django\u5b9a\u4e49\u4e86\u4e00\u7cfb\u5217\u5b57\u6bb5\u7c7b\u578b\u63cf\u8ff0\u6570\u636e\u5e93\u4e4b\u95f4\u7684\u5173\u8054:<\/p>\n<p>\u8fd9\u4e09\u4e2a\u5b57\u6bb5\u8981\u6c42\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u6a21\u578b\u7c7b\uff0c\u7528verbose_name\u9009\u9879\u624d\u80fd\u6307\u5b9a\u81ea\u8ff0\u540d\u3002<\/p>\n<pre><code>ForeignKey \u5b9a\u4e49\u591a\u5bf9\u4e00\u5173\u7cfb\nOneToOneField \u5b9a\u4e49\u4e00\u5bf9\u4e00\u5173\u7cfb\nManyToManyField \u5b9a\u4e49\u591a\u5bf9\u591a\u5173\u7cfb\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u6267\u884c\u67e5\u8be2\">\u6267\u884c\u67e5\u8be2<\/h1>\n<p>\u4e00\u65e6\u5efa\u7acb\u6570\u636e\u6a21\u578b,django\u4f1a\u81ea\u52a8\u751f\u6210\u4e00\u5957\u62bd\u8c61\u7684API,\u7528\u4e8e\u521b\u5efa,\u68c0\u7d22,\u66f4\u65b0\u548c\u5220\u9664\u5bf9\u8c61.<\/p>\n<h2 id=\"\u521b\u5efa\u5bf9\u8c61\">\u521b\u5efa\u5bf9\u8c61<\/h2>\n<pre><code>q = Question(question_text='content', pub_date='date')\nq.save()\nq = Question(question_text='content')\nq.pub_date='date'\nq.save()\nQuestion.objects.create(question_text=&quot;content&quot;, pub_date='date')\n# \u9632\u6b62\u91cd\u590d,\u4e0d\u5b58\u5728\u5c31\u521b\u5efa\uff0c\u8fd4\u56de(object, True),\u5b58\u5728\u8fd4\u56de(object, False)\nQuestion.objects.get_or_create(question_text='content', pub_date='date')\n<\/code><\/pre>\n<h2 id=\"\u83b7\u53d6\u5bf9\u8c61\">\u83b7\u53d6\u5bf9\u8c61<\/h2>\n<p>\u901a\u8fc7\u6a21\u578b\u4e2d\u7684\u7ba1\u7406\u5668\u6784\u9020\u4e00\u4e2a\u67e5\u8be2\u96c6\u6765\u4ece\u6570\u636e\u5e93\u83b7\u53d6\u5bf9\u8c61.<\/p>\n<p>\u67e5\u8be2\u96c6\u6c42\u503c\uff1a<\/p>\n<ol>\n<li>\u8fed\u4ee3<\/li>\n<li>\u5207\u7247<\/li>\n<li>\u5e8f\u5217\u5316<\/li>\n<li>repr()<\/li>\n<li>len()<\/li>\n<li>list()<\/li>\n<li>bool()<\/li>\n<\/ol>\n<p>\u67e5\u8be2\u96c6\u53c2\u8003QuerySet\u7c7b\u7684\u65b9\u6cd5\uff1a<\/p>\n<p><a class=\"link\" href=\"http:\/\/python.usyiyi.cn\/translate\/django_182\/ref\/models\/querysets.html#queryset-api\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/python.usyiyi.cn\/translate\/django_182\/ref\/models\/querysets.html#queryset-api<\/a><\/p>\n<pre><code># \u83b7\u53d6\u8868\u4e2d\u6240\u6709\u5bf9\u8c61\nQuestion.objects.all()\n# \u5207\u7247\u83b7\u53d6\u90e8\u5206\nQuestion.objects.all()[:10]\n# \u83b7\u53d6\u5355\u4e2a\nQuestion.objects.get(question_text='content')\n# \u8fc7\u6ee4\nQuestion.objects.filter(**kwargs)\nQuestion.objects.exclude(**kwargs)\n<\/code><\/pre>\n<p>\u67e5\u8be2\u96c6\u7684\u94fe\u5f0f\u8fc7\u6ee4\uff1a<\/p>\n<pre><code>Question.objects.all().exists()\nQuestion.objects.all().order_by('name')\nQuestion.objects.filter(**kwargs).filter(**kwargs)\n<\/code><\/pre>\n<p>select_related() QuerySet \u65b9\u6cd5\u4f1a\u63d0\u524d\u9012\u5f52\u5730\u9884\u52a0\u8f7d\u6240\u6709\u4e00\u5bf9\u591a\u5173\u7cfb\u7684\u7f13\u5b58\u3002\u9002\u5408OneToOneField\u548cForeignKey\u3002<\/p>\n<pre><code>Question.objects.select_related('related_model').all()\n<\/code><\/pre>\n<p>prefetch_related() QuerySet \u65b9\u6cd5\u4f1a\u63d0\u524d\u9884\u52a0\u8f7d\u6240\u6709\u591a\u5bf9\u591a\u5173\u7cfb\u7684\u7f13\u5b58\u3002\u9002\u5408ManyToManyField\u3002<\/p>\n<pre><code>Question.objects.prefetch_related('related_model').all()\n<\/code><\/pre>\n<p>Q\u5bf9\u8c61\u590d\u6742\u67e5\u8be2<\/p>\n<pre><code>from django.db.models import Q\n# \u903b\u8f91\u6216\nQuestion.objects.filter(Q(question_text='content') | Q(pub_date='date'))\n# \u903b\u8f91\u4e0e\nQuestion.objects.filter(Q(question_text='content') &amp; Q(pub_date='date'))\n# \u903b\u8f91\u975e\nQuestion.objects.exclude(Q(question_text='content'))\n<\/code><\/pre>\n<hr>"},{"title":"Template","link":"https:\/\/canuxcheng.com\/post\/django_template\/","pubDate":"Tue, 04 Oct 2016 04:12:49 +0000","guid":"https:\/\/canuxcheng.com\/post\/django_template\/","description":"<h1 id=\"\u6a21\u677f\u8bbe\u7f6e\">\u6a21\u677f\u8bbe\u7f6e<\/h1>\n<p>\u6a21\u677f\u5f15\u64ce\u5728settings.py\u8bbe\u7f6e, django\u6709\u4e24\u5957\u6a21\u677f\u5f15\u64ce\uff1a<\/p>\n<pre><code>TEMPLATES = [\n# DjangoTemplates\n{\n'BACKEND': 'django.template.backends.django.DjangoTemplates',\n# \u5b9a\u4e49\u9879\u76ee\u7684\u901a\u7528\u6a21\u677f, mysite\/templates\n'DIRS': [os.path.join(BASE_DIR, 'templates')],\n# True \u8868\u793a\u5728\u6240\u6709\u5b89\u88c5\u5e94\u7528\u7684application\/templates\u4e2d\u67e5\u627e\u3002\n'APP_DIRS': True,\n# \u6a21\u677f\u7684\u9009\u9879\uff1a\n'OPTIONS': {\n'context_processors': [\n'django.template.context_processors.debug',\n'django.template.context_processors.request',\n'django.contrib.auth.context_processors.auth',\n'django.contrib.messages.context_processors.messages',\n]\n},\n},\n# Jinja2\n{\n'BACKEND': 'django.template.backends.jinja2.Jinja2',\n# \u5b9a\u4e49\u9879\u76ee\u7684\u901a\u7528\u6a21\u677f, mysite\/templates\n'DIRS': [os.path.join(BASE_DIR, 'templates')],\n# True\u8868\u793a\u5728\u6240\u6709\u5df2\u5b89\u88c5\u5e94\u7528\u7684application\/jinja2\u4e2d\u67e5\u627e\u3002\n'APP_DIRS': True,\n# \u6a21\u677f\u7684\u9009\u9879\uff1a\n'OPTIONS': {\n'context_processors': [\n'django.template.context_processors.debug',\n'django.template.context_processors.request',\n'django.contrib.auth.context_processors.auth',\n'django.contrib.messages.context_processors.messages',\n]\n},\n},\n]\n<\/code><\/pre>\n<p>BACKEND\u5b9a\u4e49\u6a21\u677f\u5f15\u64ce,django\u5185\u7f6e\u7684\u6a21\u677f\u5f15\u64ce\u6709\u4e24\u4e2adjango.template.backends.django.DjangoTemplates(\u9ed8\u8ba4)\u548cdjango.template.backends.jinja2.Jinja2<\/p>\n<p>DIRS\u5b58\u653e\u81ea\u5b9a\u4e49\u7684\u4e0d\u5728\u5e94\u7528\u8def\u5f84\u7684\u6a21\u677f\uff0c\u6a21\u677f\u5f15\u64ce\u6309\u5217\u8868\u987a\u5e8f\u641c\u7d22\u67e5\u627e\u6a21\u677f\u6e90\u6587\u4ef6,\u9ed8\u8ba4\u5c31\u662f\u9ed8\u8ba4\u5f15\u64ce\u7684\u9ed8\u8ba4\u8def\u5f84\u3002<\/p>\n<p>APP_DIRS\u544a\u8bc9\u6a21\u677f\u5f15\u64ce\u662f\u5426\u8fdb\u5165\u5b89\u88c5\u5e94\u7528\u7684templates(jinja2\u7684\u76ee\u5f55\u662fjinja2)\u67e5\u627e\u6a21\u677f\u3002<\/p>\n<p>\u5728\u89c6\u56fe\u4e2d\u4f7f\u7528\u6a21\u677f\uff1a<\/p>\n<p>\u9ed8\u8ba4django\u4f1a\u5728\u9879\u76ee\u7684\u6240\u6709\u5e94\u7528\u7684templates\u4e2d\u67e5\u627e\u6a21\u677f\uff0c\u6240\u4ee5\u4e3a\u4e86\u9632\u6b62\u591a\u4e2a\u5e94\u7528\u6709\u540c\u540d\u7684\u6a21\u677f\uff0c\u9700\u8981\u5728templates\u4e0b\u65b0\u5efaapplication\u540c\u540d\u7684\u76ee\u5f55\u6765\u5b58\u653e\u6a21\u677f<\/p>\n<p>\u5e94\u7528\u7684\u6a21\u677f\u6587\u4ef6\u9700\u8981\u5728\u5e94\u7528\u76ee\u5f55\u521b\u5efatemplates\u6587\u4ef6\u5939<\/p>\n<p>\u9ed8\u8ba4\u6a21\u677f\u653e\u5728polls\/templates\/polls\/XXX.html<\/p>\n<p>\u5e94\u7528\u7684\u9759\u6001\u6587\u4ef6\u9700\u8981\u5728\u5e94\u7528\u76ee\u5f55\u521b\u5efastatic\u6587\u4ef6\u5939<\/p>\n<p>\u9ed8\u8ba4\u9759\u6001\u6587\u4ef6\u5b58\u653e\u5728polls\/static\/polls\/XXX.css<\/p>\n<p>\u9759\u6001\u6587\u4ef6\u5939\u7528\u6765\u96c6\u4e2d\u5b58\u653e\u548c\u7ba1\u7406\u56fe\u7247\uff0cjs\u811a\u672c\u548ccss\u6837\u5f0f\u8868\u7b49\u9759\u6001\u6587\u4ef6\u3002<\/p>\n<p>django.template.loader\u5b9a\u4e49\u4e86\u4e24\u4e2a\u51fd\u6570\u52a0\u8f7d\u6a21\u677f\u3002<\/p>\n<pre><code>get_template(template_name, dirs=&lt;object object&gt;, using=None)\nselect_template(template_name_list, dirs=&lt;object object&gt;, using=None)\n<\/code><\/pre>\n<h1 id=\"\u6a21\u677f\u8bed\u8a00\">\u6a21\u677f\u8bed\u8a00<\/h1>\n<p>django\u6a21\u677f\u8bed\u8a00\u7531\u56db\u90e8\u5206\u7ec4\u6210\uff1a<\/p>\n<ul>\n<li>\u53d8\u91cf<\/li>\n<li>\u6807\u7b7e<\/li>\n<li>\u8fc7\u6ee4\u5668<\/li>\n<li>\u8bc4\u8bba<\/li>\n<\/ul>\n<h2 id=\"\u53d8\u91cf\">\u53d8\u91cf<\/h2>\n<pre><code>{{ var }}\n<\/code><\/pre>\n<p>\u663e\u793a\u5b57\u7b26\u4e32\uff1a<\/p>\n<pre><code>string = &quot;test string&quot;\nreturn render(request, 'index.html', {'string': string})\n{{ string }}\n<\/code><\/pre>\n<p>\u663e\u793a\u5b57\u5178\uff1a<\/p>\n<pre><code>dict = {&quot;key1&quot;: &quot;value1&quot;, &quot;key2&quot;: &quot;value2&quot;}\nreturn render(request, 'index.html', {'dict': dict})\n{{ dict.name1 }}\n<\/code><\/pre>\n<h2 id=\"\u6807\u7b7e\">\u6807\u7b7e<\/h2>\n<pre><code>{% tag %}\n<\/code><\/pre>\n<p>\u53c2\u8003\u5185\u7f6e\u6807\u7b7e\uff1a<\/p>\n<p><a class=\"link\" href=\"http:\/\/python.usyiyi.cn\/translate\/django_182\/ref\/templates\/builtins.html#ref-templates-builtins-tags\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/python.usyiyi.cn\/translate\/django_182\/ref\/templates\/builtins.html#ref-templates-builtins-tags<\/a><\/p>\n<p>for\u6807\u7b7e\uff1a<\/p>\n<p>\u904d\u5386\u5217\u8868\uff1a<\/p>\n<pre><code>list = ['val1', 'val2', 'val3']\nreturn render(request, 'index.html', {'list': 'list'})\n```html\n{% for i in list %}\n{{ i }}\n{% endfor %}\n```\n<\/code><\/pre>\n<p>\u904d\u5386\u5b57\u5178\uff1a<\/p>\n<pre><code>```html\n{% for key, value in dict.items %}\n{{ key }}: {{ value }}\n{% endfor %}\n```\n<\/code><\/pre>\n<p>empty\u5217\u8868\u53ef\u80fd\u4e3a\u7a7a\uff1a<\/p>\n<pre><code>```html\n{% for i in list %}\n...\n{% empty %}\n...\n{% endfor %}\n```\n<\/code><\/pre>\n<p>reversed\u53cd\u5411\u5faa\u73af\uff1a<\/p>\n<pre><code>{% for i in list reversed %}\n<\/code><\/pre>\n<p>for\u5faa\u73af\u6709\u7528\u7684\u53d8\u91cf\uff1a<\/p>\n<pre><code>forloop.counter # 1 - indexed\nforloop.counter0 # 0 - indexed\nforloop.revcounter # 1 - indexed\nforloop.revcounter0 # 0 - indexed\nforloop.first\nforloop.last\nforloop.parentloop\n<\/code><\/pre>\n<p>if\u6807\u7b7e\uff1a<\/p>\n<pre><code>```html\n{% if expression %}\n...\n{% else %}\n...\n{% endif %}\n```\n<\/code><\/pre>\n<p>if\u53ef\u7528\u7684\u5e03\u5c14\u64cd\u4f5c\u7b26\uff1a<\/p>\n<pre><code>{% if expression1 and expression2 %}\n{% if not expression %}\n{% if expression1 or expression2 %}\n{% if not expression1 or expression2 %} # not\u4f18\u5148\u7ea7\u9ad8\u4e8eor\n{% if expression1 and not expression2 %} # not\u4f18\u5148\u7ea7\u9ad8\u4e8eand\n{% if expression1 and expression2 or expression3 %} # and\u4f18\u5148\u7ea7\u9ad8\u4e8eor\n{% if var == value %}\n{% if var != value %}\n{% if var &lt; value %}\n{% if var &gt; value %}\n{% if var &lt;= value %}\n{% if var &gt;= value %}\n{% if var in value %}\n{% if a &gt; b and b &gt; c %}\n{% if var|filter&quot;arguments expression %} # if\u4e2d\u4f7f\u7528\u8fc7\u6ee4\u5668\n<\/code><\/pre>\n<p>\u5e03\u5c14\u64cd\u4f5c\u7b26\u7684\u4f18\u5148\u7ea7\uff1a<\/p>\n<pre><code>or\nand\nnot\nin\n==, !=, &lt;, &gt;, &lt;=, &gt;=\n<\/code><\/pre>\n<p>include\u6807\u7b7e\uff1a<\/p>\n<p>\u52a0\u8f7d\u6a21\u677f\u5e76\u4ee5\u6807\u7b7e\u5185\u7684\u53c2\u6570\u6e32\u67d3\u3002<\/p>\n<pre><code>{% include 'XXX.html' %}\n<\/code><\/pre>\n<p>load\u6807\u7b7e\uff1a<\/p>\n<p>\u52a0\u8f7d\u81ea\u5b9a\u4e49\u6a21\u677f\u6807\u7b7e\u96c6\u3002<\/p>\n<pre><code>{% load foo bar from somelibrary %}\n<\/code><\/pre>\n<p>now\u6807\u7b7e\uff1a<\/p>\n<p>\u663e\u793a\u6700\u8fd1\u7684\u65e5\u671f\u548c\u4e8b\u4ef6\u3002<\/p>\n<p>spaceless\u6807\u7b7e\uff1a<\/p>\n<p>\u5220\u9664html\u6807\u7b7e\u4e4b\u95f4\u7684\u7a7a\u767d\u683c\uff0c\u5305\u62ec\u5236\u8868\u7b26\u548c\u6362\u884c\u3002<\/p>\n<p>url\u6807\u7b7e\uff1a<\/p>\n<p>\u8fd4\u56de\u4e00\u4e2a\u7edd\u5bf9\u8def\u5f84\u7684\u5f15\u7528\uff0c\u8be5\u5f15\u7528\u5339\u914d\u4e00\u4e2a\u7ed9\u5b9a\u7684\u89c6\u56fe\u51fd\u6570\u548c\u4e00\u4e9b\u53ef\u9009\u7684\u53c2\u6570\u3002<\/p>\n<pre><code>{% 'some-url-name' v1 v2 %}\n<\/code><\/pre>\n<h3 id=\"\u6a21\u677f\u7ee7\u627f\">\u6a21\u677f\u7ee7\u627f<\/h3>\n<p>block\u6807\u7b7e\uff1a<\/p>\n<p>\u5728\u5e95\u5c42\u6a21\u677f\u5b9a\u4e49\u4e00\u4e9b\u901a\u7528\u7684\u5185\u5bb9\uff0cblock\u6807\u7b7e\u53ef\u4ee5\u88ab\u5b50\u6a21\u677f\u8986\u76d6\u3002<\/p>\n<pre><code>```html\n{% block XXX %}\nThis is default content\n{% endblock %}}\n```\n<\/code><\/pre>\n<p>extends\u6807\u7b7e\uff1a<\/p>\n<p>\u8868\u793a\u5f53\u524d\u6a21\u677f\u7ee7\u627f\u81ea\u7236\u6a21\u677f\u3002<\/p>\n<p>extends\u6807\u7b7e\u5fc5\u987b\u653e\u5728\u5b50\u6a21\u677f\u7b2c\u4e00\u884c\u3002<\/p>\n<p>extends\u7528\u6765\u8c03\u7528\u5e95\u5c42\u7684\u6a21\u677f\uff0c\u7136\u540e\u4fee\u6539block\u6807\u7b7e\u5185\u5bb9\u3002<\/p>\n<pre><code>```html\n{% extends &quot;XXX.html&quot;\/variable %}\n{% block XXX %}\nThis is rewrite content\n{% endblock %}\n```\n<\/code><\/pre>\n<p>block.super:<\/p>\n<p>\u5982\u679c\u9700\u8981\u83b7\u53d6\u7236\u6a21\u677f\u7684block\u4e2d\u7684\u5185\u5bb9\uff0c\u53ef\u4ee5\u7528block.super\u3002<\/p>\n<p>\u53ef\u4ee5\u5728\u7236\u6a21\u677f\u7684block\u4e2d\u589e\u52a0\u5185\u5bb9\uff0c\u800c\u4e0d\u662f\u5b8c\u5168\u8986\u76d6\u3002<\/p>\n<h2 id=\"\u8fc7\u6ee4\u5668\">\u8fc7\u6ee4\u5668<\/h2>\n<pre><code>{{ var|filter:arguments }}\n<\/code><\/pre>\n<p>\u53c2\u8003\u5185\u7f6e\u8fc7\u6ee4\u5668<\/p>\n<p><a class=\"link\" href=\"http:\/\/python.usyiyi.cn\/translate\/django_182\/ref\/templates\/builtins.html#ref-templates-builtins-filters\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/python.usyiyi.cn\/translate\/django_182\/ref\/templates\/builtins.html#ref-templates-builtins-filters<\/a><\/p>\n<p>add\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>\u628aadd\u540e\u7684\u53c2\u6570\u52a0\u7ed9value\u3002<\/p>\n<pre><code>{{ value|add:&quot;2&quot; }} # value -&gt; value+2\n{{ value|addslashes }} # &quot;I'm string&quot; -&gt; &quot;I\\'m string&quot;\n<\/code><\/pre>\n<p>addslashed\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>\u5728\u5f15\u53f7\u524d\u9762\u52a0\\<\/p>\n<pre><code>{{ value|addslashes }} # I'm canux -&gt; I\\'m canux\n<\/code><\/pre>\n<p>capfirst\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>\u53d8\u91cf\u7684\u7b2c\u4e00\u4e2a\u5b57\u6bcd\u5927\u5199\u3002<\/p>\n<pre><code>{{ value|capfirst }}\n<\/code><\/pre>\n<p>center\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>\u4f7fvalue\u5728\u7ed9\u5b9a\u7684\u5bbd\u5ea6\u8303\u56f4\u5185\u5c45\u4e2d\u3002<\/p>\n<pre><code>{{ value|center:&quot;15&quot; }}\n<\/code><\/pre>\n<p>cut\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>\u79fb\u9664value\u4e2d\u6240\u6709\u7684\u4e0e\u7ed9\u51fa\u7684\u53d8\u91cf\u76f8\u540c\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<pre><code>{{ value|cut:&quot;cut&quot; }} # \u79fb\u9664value\u4e2d\u7684\u5b57\u7b26\u4e32&quot;cut&quot;\n<\/code><\/pre>\n<p>date\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>\u6839\u636e\u7ed9\u5b9a\u683c\u5f0f\u5bf9\u4e00\u4e2adate\u53d8\u91cf\u683c\u5f0f\u5316\u3002<\/p>\n<p>default\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>\u7ed9value\u8bbe\u5b9a\u9ed8\u8ba4\u503c\uff0c\u5982\u679cvalue\u6ca1\u6709\u8d4b\u503c\uff0c\u5c31\u7528\u9ed8\u8ba4\u503c\u3002<\/p>\n<pre><code>{{ value|default:&quot;default-value&quot; }}\n<\/code><\/pre>\n<p>default_if_none\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>\u4ec5\u5f53value\u662fNone\u4f7f\u7528\u9ed8\u8ba4\u503c\u3002<\/p>\n<pre><code>{{ value:default_if_none:&quot;nothing&quot; }}\n<\/code><\/pre>\n<p>dictsort\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>dictsortreversed\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>divisibleby\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>\u5982\u679cvalue\u53ef\u4ee5\u88ab\u7ed9\u51fa\u7684\u53c2\u6570\u6574\u9664\uff0c\u8fd4\u56deTrue\u3002<\/p>\n<pre><code>{{ value|divisibleby:&quot;3&quot; }}\n<\/code><\/pre>\n<p>escape\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>escapejs\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>filesizeformat\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>\u683c\u5f0f\u5316\u4e3a\u4eba\u7c7b\u53ef\u8bfb\u7684\u6587\u4ef6\u5927\u5c0f\u3002<\/p>\n<p>first\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>\u8fd4\u56de\u8fed\u4ee3\u5668\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u3002<\/p>\n<p>floatformat\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>force_escape\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>get_digit\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>iriencode\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>join\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>last\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>length\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>length_is\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>linebreaks\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>linebreaksbr\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>linenumbers\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>ljust\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>lower\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>\u628a\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u5c0f\u5199\u3002<\/p>\n<p>make_list\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>phone2numeric\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>pluralize\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>pprint\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>random\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>romevetags\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>rjust\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>slice\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>slugify\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>stringformat\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>striptags\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>time\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>timesince\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>timeuntil\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>title\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>truncatechars\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>truncatechars_html\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>truncatewords\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>truncatewords_html\u8fc7\u6ee4\u5668;<\/p>\n<p>unordered_list\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>upper\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u5927\u5199\u5f62\u5f0f\u3002<\/p>\n<p>urlencode\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>urlize\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>urlizetrunc\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>wordcount\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>wordwrap\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>yesno\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>i18n\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>l10n\u8fc7\u6ee4\u5668\uff1a<\/p>\n<p>tz\u8fc7\u6ee4\u5668\uff1a<\/p>\n<h2 id=\"\u6ce8\u91ca\">\u6ce8\u91ca<\/h2>\n<p>\u5355\u884c\u6ce8\u91ca\uff1a<\/p>\n<pre><code>```html\n{# this is single line comment #}\n```\n<\/code><\/pre>\n<p>\u591a\u884c\u6ce8\u91ca\uff1a<\/p>\n<pre><code>```html\n{% comment %}\nline1\nline2\n{% endcomment %}\n```\n<\/code><\/pre>\n<h1 id=\"\u81ea\u52a8html\u8f6c\u4e49\">\u81ea\u52a8html\u8f6c\u4e49<\/h1>\n<p>\u5f53\u4ece\u6a21\u677f\u751f\u6210html\u65f6\uff0c\u503c\u53ef\u80fd\u5305\u542b\u5f71\u54cdhtml\u6700\u7ec8\u5448\u73b0\u7684\u5b57\u7b26\u3002<\/p>\n<p>django\u7684\u81ea\u52a8\u8f6c\u4e49,\u9ed8\u8ba4\u662f\u6253\u5f00\u7684\uff1a<\/p>\n<pre><code>&lt; \u8f6c\u4e49\u6210 &amp;lt;\n&gt; \u8f6c\u4e49\u6210 &amp;gt;\n' \u8f6c\u4e49\u6210 &amp;#39\n&quot; \u8f6c\u4e49\u6210 &amp;quot;\n$ \u8f6c\u4e49\u6210 &amp;amp;\n<\/code><\/pre>\n<p>\u5982\u679c\u4e0d\u9700\u8981\u81ea\u52a8\u8f6c\u4e49\u53ef\u4ee5\u5173\u95ed\u5b83<\/p>\n<p>\u53ef\u4ee5\u7528safe\u8fc7\u6ee4\u5668\u5173\u95ed\u72ec\u7acb\u53d8\u91cf\u4e2d\u7684\u81ea\u52a8\u8f6c\u4e49\uff1a<\/p>\n<pre><code>data = &lt;b&gt;\n{{ data }} -&gt; &amp;lt;b&amp;gt;\n{{ data|safe }} -&gt; &lt;b&gt;\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u7528autoescape\u6807\u7b7e\u5173\u95ed\u6a21\u677f\u4ee3\u7801\u4e2d\u7684\u81ea\u52a8\u8f6c\u4e49\uff1a<\/p>\n<p>autoescape\u6807\u7b7e\u6709off\u548con\u4e24\u4e2a\u53c2\u6570\uff0c\u8868\u793a\u5173\u95ed\u548c\u6253\u5f00\u81ea\u52a8\u8f6c\u4e49\u3002<\/p>\n<p>\u7236\u6a21\u677f\u4e2d\u7684autoescape\u53ef\u4ee5\u88ab\u5b50\u6a21\u677f\u7ee7\u627f\uff0c\u4e5f\u53ef\u4ee5\u88abinclude\u6807\u7b7e\u5305\u542b\u7684\u6a21\u677f\u7ee7\u627f\u3002<\/p>\n<pre><code>```html\n{% autoescape off %}\n{{ name }}\n{% endautoescape %}\n```\n<\/code><\/pre>"},{"title":"Deploy","link":"https:\/\/canuxcheng.com\/post\/django_deploy\/","pubDate":"Tue, 27 Sep 2016 10:23:22 +0000","guid":"https:\/\/canuxcheng.com\/post\/django_deploy\/","description":"<h1 id=\"\u53d1\u5e03django\u9879\u76ee\">\u53d1\u5e03django\u9879\u76ee<\/h1>\n<p>django\u5185\u7f6e\u4e00\u4e2a\u8f7b\u91cf\u7ea7web\u5f00\u53d1\u670d\u52a1\u5668\u3002<\/p>\n<p>\u5982\u679c\u8981\u53d1\u5e03django\u9879\u76ee\u9700\u8981\u53e6\u5916\u7684\u64cd\u4f5c\u3002<\/p>\n<p>\u4e5f\u53ef\u4ee5\u53d1\u5e03\u5230\u5176\u5b83\u7684\u4e91\u5e73\u53f0\u3002<\/p>\n<p>\u4e00\u822c\u901a\u8fc7wsgi\u6216\u8005asgi\u6765\u90e8\u7f72.<\/p>\n<p>WSGI: web server gateway interface. \u540c\u6b65<\/p>\n<p>ASGI: asynchronous server gateway interface. \u5f02\u6b65<\/p>\n<h2 id=\"deploy\u65f6django\u7684\u8bbe\u7f6e\">deploy\u65f6django\u7684\u8bbe\u7f6e<\/h2>\n<p>settings.py\u4e2d\u7684\u8bbe\u7f6e\uff1a<\/p>\n<pre><code>ALLOWED_HOSTS = ['*']\nDEBUG = False\n<\/code><\/pre>\n<hr>\n<h1 id=\"wsgi-\u90e8\u7f72\">WSGI \u90e8\u7f72<\/h1>\n<h2 id=\"apache2--mod_wsgi\">apache2 + mod_wsgi<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/GrahamDumpleton\/mod_wsgi\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/GrahamDumpleton\/mod_wsgi<\/a><\/p>\n<p>mod_wsgi\u662fC\u5199\u7684apache\u7684\u6a21\u5757\uff0c\u5b9e\u73b0\u4e86\u517c\u5bb9WSGI\u63a5\u53e3\uff0c\u7528\u6765\u90e8\u7f72python\u7684web\u5e94\u7528\u3002<\/p>\n<p>\u4f5c\u4e3aapache2\u7684\u6a21\u5757\u5b89\u88c5<\/p>\n<pre><code># ubuntu\/debian\nsudo aptitude install apache2 # \u5b89\u88c5apache2\nsudo aptitude install libapache2-mod-wsgi # for python2\nsudo aptitude install libapache2-mod-wsgi-py3 # for python3\n# redhat\/centos\/fedora\nsudo yum install httpd2\nsudo yum install httpd-devel\nsudo yum install mod_wsgi\n<\/code><\/pre>\n<p>Ubuntu\u521b\u5efa\u7f51\u7ad9\u7684\u914d\u7f6e\u6587\u4ef6\/etc\/apache2\/sites-available\/mysite.conf:<\/p>\n<p>Fedora\u521b\u5efa\u7f51\u7ad9\u7684\u914d\u7f6e\u6587\u4ef6\/etc\/httpd\/conf.d\/mysite.conf:<\/p>\n<p>\u4e00\u822c\u90e8\u7f72\u5230web\u670d\u52a1\u5668\uff0c\/home\/user\/\u4fee\u6539\u4e3a\/var\/www\/<!-- raw HTML omitted -->\/<\/p>\n<pre><code># Include the project dir, can not inside VirtualHost section.\nWSGIPythonPath \/home\/user\/mysite\n# If use virtualenv and named .venv\n# WSGIPythonPath \/home\/user\/mysite:\/home\/user\/mysite\/.venv\/lib\/python2.7\/site-packages\n&lt;VirtualHost *:80&gt;\nServerName localhost\n# ServerName yoursite.domain\nServerAdmin canuxcheng@gmail.com\nAlias \/robots.txt \/home\/user\/mysite\/static\/robots.txt\nAlias \/favicon.ico \/home\/user\/mysite\/static\/favicon.ico\nAlias \/media\/ \/home\/user\/mysite\/media\/\nAlias \/static\/ \/home\/user\/mysite\/static\/\n&lt;Directory \/home\/user\/mysite\/media&gt;\nRequired all granted\n&lt;\/Directory&gt;\n&lt;Directory \/home\/user\/mysite\/static&gt;\nRequired all granted\n&lt;\/Directory&gt;\n# If use daemon mode to run WSGI process.\nWSGIDaemonProcess mysite python-path=\/home\/user\/mysite\n# If use virtualenv and named .venv\n# WSGIDaemonProcess mysite python-path=\/home\/user\/mysite:\/home\/user\/mysite\/.venv\/lib\/python2.7\/site-packages\n# WSGIProcessGroup mysite\nWSGIScriptAlias \/ \/home\/user\/mysite\/mysite\/wsgi.py\n&lt;Directory \/home\/user\/mysite\/mysite&gt;\n&lt;Files wsgi.py&gt;\nRequired all granted\n&lt;\/Files&gt;\n&lt;\/Directory&gt;\n# check the log in \/var\/log\/apache2\/error_mysite.log or access_mysite.log\nErrorLog ${APACHE_LOG_DIR}\/error_mysite.log\nCustomLog ${APACHE_LOG_DIR}\/access_mysite.log combined\n&lt;\/VirtualHost&gt;\n<\/code><\/pre>\n<p>\u4fee\u6539\u9879\u76ee\u7684wsgi.py:<\/p>\n<p>\u56e0\u4e3a\u73af\u5883\u53d8\u91cf\u662f\u8fdb\u7a0b\u8303\u56f4\u7684\uff0c\u5728\u540c\u4e00\u4e2a\u8fdb\u7a0b\u8fd0\u884c\u591a\u4e2a\u7ad9\u70b9\u4f1a\u51fa\u95ee\u9898\uff0c\u6240\u4ee5\u63a8\u8350\u591a\u7ad9\u70b9\u4f7f\u7528mod_wsgi\u7684\u5b88\u62a4\u8fdb\u7a0b\u6a21\u5f0f,\u4e5f\u53ef\u4ee5\u5728\u5355\u8fdb\u7a0b\u4e2d\u8986\u76d6DJANGO_SETTINGS_MODULE\u8fd9\u4e2a\u53d8\u91cf\u3002<\/p>\n<pre><code>import os\nfrom django.core.wsgi import get_wsgi_application\n# If you have more than 1 django project you need to change this.\n# Or you can use daemon mode for WSGI process.\n# os.environ.setdefault(&quot;DJANGO_SETTINGS_MODULE&quot;, &quot;mysite.settings&quot;)\nos.environ[&quot;DIANGO_SETTINGS_MODULE&quot;] = &quot;mysite.settings&quot;\napplication = get_wsgi_application()\n<\/code><\/pre>\n<p>\u4fee\u6539\u9879\u76ee\u7684settings.py:<\/p>\n<p>ROOT\u8868\u793a\u5b58\u653e\u4f4d\u7f6e\uff0cURL\u8868\u793a\u5bf9\u5e94\u7f51\u5740\u3002<\/p>\n<pre><code>DEBUG = False\nALLOWED_HOSTS = ['*']\n# Static files (CSS, JavaScript, Images)\nSTATIC_URL = '\/static\/'\nSTATIC_ROOT = os.path.join(BASE_DIR, 'static')\n# Media files (upload files)\nMEDIA_URL = '\/media\/'\nMEDIA_ROOT = os.path.join(BASE_DIR, 'media')\n<\/code><\/pre>\n<p>\u6536\u96c6\u9759\u6001\u6587\u4ef6\u548c\u8fc1\u79fb\uff1a<\/p>\n<pre><code>$python manage.py makemigration\n$python mamage.py migrate\n$python manage.py collectstatic\n<\/code><\/pre>\n<p>\u8bbe\u7f6e\u6743\u9650\uff1a<\/p>\n<p>Ubuntu\u9ed8\u8ba4\u7528\u6237\u548c\u7ec4\u662fwww-data,Fedora\u9ed8\u8ba4\u7528\u6237\u548c\u7ec4\u662fapache\u3002<\/p>\n<pre><code>$cd \/home\/user\n$sudo chgrp www-data mysite\n$sudo chmod g+w mysite\n$sudo chgrp www-data mysite\/db.sqlite3\n$sudo chmod g+w mysite\/db.sqlite3\n$sudo chgrp -R www-data mysite\/media\/uploads\n$sudo chmod -R g+w mysite\/media\/uploads\n<\/code><\/pre>\n<p>Ubuntu\u6fc0\u6d3b\u7f51\u7ad9\uff1a<\/p>\n<pre><code>$sudo a2ensite &lt;newsite&gt;\n$sudo service apache2 restart\n<\/code><\/pre>\n<p>Fedora\u6fc0\u6d3b\u7f51\u7ad9\uff1a<\/p>\n<pre><code>$sudo systemctl restart httpd\n<\/code><\/pre>\n<h2 id=\"uwsgi\">uWSGI<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/unbit\/uwsgi\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/unbit\/uwsgi<\/a><\/p>\n<p>C\u5199\u7684wsgi\u5e94\u7528\u670d\u52a1\u5668\u3002<\/p>\n<pre><code>$ python3 -m pip install uwsgi\n$ uwsgi --http :8000 --chdir \/path\/to\/project --module mysite.wsgi\n<\/code><\/pre>\n<h2 id=\"gunicorn\">Gunicorn<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/benoitc\/gunicorn\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/benoitc\/gunicorn<\/a><\/p>\n<p>\u7eafpython\u5199\u7684WSGI\u670d\u52a1\u5668\u3002<\/p>\n<pre><code>$ python3 -m pip install gunicorn\n$ gunicorn mysite.wsgi\n<\/code><\/pre>\n<hr>\n<h1 id=\"asgi\">ASGI<\/h1>\n<h2 id=\"uvicorn\">Uvicorn<\/h2>\n<pre><code>$ python -m pip install uvicorn gunicorn\n$ gunicorn myproject.asgi:application -k uvicorn.workers.UvicornWorker\n<\/code><\/pre>\n<h2 id=\"hypercorn\">Hypercorn<\/h2>\n<pre><code>$ python -m pip install hypercorn\n$ hypercorn myproject.asgi:application\n<\/code><\/pre>\n<h2 id=\"daphne\">Daphne<\/h2>\n<pre><code>$ python -m pip install daphne\n$ daphne myproject.asgi:application\n<\/code><\/pre>"},{"title":"Nodejs","link":"https:\/\/canuxcheng.com\/post\/js_node\/","pubDate":"Tue, 27 Sep 2016 03:31:25 +0000","guid":"https:\/\/canuxcheng.com\/post\/js_node\/","description":"<h1 id=\"nodejs\">Nodejs<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/nodejs\/node\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/nodejs\/node<\/a><\/p>\n<p>Node.js \u662f\u4e00\u4e2a\u57fa\u4e8e Chrome V8 \u5f15\u64ce\u7684 JavaScript \u8fd0\u884c\u73af\u5883\u3002<\/p>\n<p>Node.js \u4f7f\u7528\u4e86\u4e00\u4e2a\u4e8b\u4ef6\u9a71\u52a8\u3001\u975e\u963b\u585e\u5f0f I\/O \u7684\u6a21\u578b\uff0c\u4f7f\u5176\u8f7b\u91cf\u53c8\u9ad8\u6548\u3002<\/p>\n<p>Node.js \u7684\u5305\u7ba1\u7406\u5668npm\uff0c\u662f\u5168\u7403\u6700\u5927\u7684\u5f00\u6e90\u5e93\u751f\u6001\u7cfb\u7edf.<\/p>\n<p>\u5e38\u8bf4\u7684javascript\u662f\u524d\u7aef\u8bed\u8a00\uff0cnodejs\u5c31\u662f\u540e\u7aef\u7248\u672c\u7684javascript\u3002<\/p>\n<p>\u5b89\u88c5nodejs(npm):<\/p>\n<pre><code>$ sudo apt-get install nodejs\n$ brew install nodejs\n<\/code><\/pre>\n<p>\u67e5\u770b<\/p>\n<pre><code>$ node --version\n$ npm --version\n<\/code><\/pre>\n<hr>\n<h1 id=\"nvm\">nvm<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/nvm-sh\/nvm\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/nvm-sh\/nvm<\/a><\/p>\n<p>nodejs\u7248\u672c\u7ba1\u7406\u5668.<\/p>\n<p>install:<\/p>\n<pre><code>curl -o- https:\/\/raw.githubusercontent.com\/nvm-sh\/nvm\/v0.37.2\/install.sh | bash\n<\/code><\/pre>\n<p>verify:<\/p>\n<pre><code>command -v nvm\n<\/code><\/pre>\n<p>usage:<\/p>\n<pre><code>\/\/ \u67e5\u770b\u6240\u6709\u53ef\u5b89\u88c5\u7248\u672c\nnvm ls-remote\n\/\/ \u5b89\u88c5\u6307\u5b9a\u7248\u672c\nnvm install v14.15.5\n\/\/ \u67e5\u770b\u5df2\u5b89\u88c5\u7248\u672c\nnvm ls\n\/\/ \u6307\u5b9a\u9ed8\u8ba4\u7248\u672c\nnvm alias default v16.14.0\n\/\/ \u6307\u5b9a\u7248\u672c\nnvm use v14.15.5\nnvm use default\n\/\/ \u67e5\u770b\u7248\u672c\nnvm run node --version\n<\/code><\/pre>"},{"title":"NPM","link":"https:\/\/canuxcheng.com\/post\/js_npm\/","pubDate":"Tue, 27 Sep 2016 03:31:25 +0000","guid":"https:\/\/canuxcheng.com\/post\/js_npm\/","description":"<h1 id=\"npm\">NPM<\/h1>\n<p><a class=\"link\" href=\"https:\/\/www.npmjs.cn\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.npmjs.cn\/<\/a><\/p>\n<p>npm: node package manager.<\/p>\n<p>npm \u7531\u4e09\u90e8\u5206\u7ec4\u6210\uff1a<\/p>\n<ul>\n<li>website <a class=\"link\" href=\"https:\/\/www.npmjs.com\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.npmjs.com<\/a><\/li>\n<li>CLI<\/li>\n<li>registry <a class=\"link\" href=\"https:\/\/registry.npmjs.org\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/registry.npmjs.org<\/a><\/li>\n<\/ul>\n<p>config:<\/p>\n<pre><code>\/\/ \u4fee\u6539registry\n$ npm config set registry https:\/\/registry.npm.taobao.org\n$ npm config get registry\n\/\/ \u4fee\u6539\u9ed8\u8ba4\u5168\u5c40\u5b89\u88c5\u8def\u5f84\nmkdir \/path\/npm_global\nnpm config set prefix \/path\/npm_global\necho 'export PATH=\/path\/npm_global\/bin:$PATH' &gt;&gt; ~\/.profile\nsource ~\/.profile\n\/\/ \u67e5\u770b\u914d\u7f6e\n$ npm config ls -l\n<\/code><\/pre>\n<p>install:<\/p>\n<pre><code>\/\/ \u6839\u636e\u5f53\u524d\u76ee\u5f55package.json\u5b89\u88c5\u5230\u5f53\u524d\u76ee\u5f55node_modules\n$ npm install\n\/\/ \u5b89\u88c5pkg\u5230\u5f53\u524d\u76ee\u5f55\u7684 node_modules\n$ npm install &lt;pkg&gt;\n\/\/ \u5b89\u88c5\u5230\u5168\u5c40\u7684node_modules\n$ npm install -g &lt;name&gt;\n--save-dev \/\/ \u5b89\u88c5\u5e76\u81ea\u52a8\u66f4\u65b0\u5230package.json\u7684devDependencies.\n--no-save \/\/ \u4e0d\u4fdd\u5b58\u5230package.json \u548c package-lock.json.\n--no-package-lock \/\/ \u4e0d\u751f\u6210package-lock.json\n<\/code><\/pre>\n<p>list:<\/p>\n<pre><code>\/\/ \u67e5\u770b\u5b89\u88c5\u4e86\u54ea\u4e9b\u5305\n$ npm list --depth=0 --global\n<\/code><\/pre>\n<p>init:<\/p>\n<pre><code>\/\/ \u521b\u5efapackage.json\n$ npm init\n<\/code><\/pre>\n<p>test:<\/p>\n<pre><code>$ npm test\n<\/code><\/pre>\n<p>publish:<\/p>\n<pre><code># \u6ce8\u518cnpm\u8d26\u53f7\n# \u6dfb\u52a0\u8d26\u53f7\nnpm adduser\n# \u9a8c\u8bc1\u8d26\u53f7\nnpm whoami\n# \u53d1\u5e03\nnpm publish\n<\/code><\/pre>\n<p>\u53d1\u5e03\u597d\u4e86\u53ef\u4ee5\u53bbnpm\u7f51\u7ad9\u67e5\u770b.<\/p>\n<p>npm + shrinkwrap = yarn lock\nnpm-shrinkwrap.json = yarn.lock<\/p>\n<h2 id=\"folders\">folders<\/h2>\n<p>nodejs\u52a0\u8f7d\u7684\u8def\u5f84:<\/p>\n<pre><code>1. \u5f53\u524d\u76ee\u5f55\n2. $HOME\/.node_modules\n$HOME\/.node_libraries\n$PREFIX\/lib\/node_modules\n3. $NODE_PATH\n\/\/ \u67e5\u770bprefix (\u4e5f\u662f-g \u5b89\u88c5\u7684\u76ee\u5f55)\n$ npm config ls -l | grep prefix\n<\/code><\/pre>\n<hr>\n<h2 id=\"npmrc\">npmrc<\/h2>\n<p>get token<\/p>\n<pre><code>curl -u&lt;username&gt;:&lt;api-key&gt; https:\/\/artifactory.canux.com\/artifactory\/api\/npm\/auth\n<\/code><\/pre>\n<p>&ldquo;.npmrc&rdquo; \u914d\u7f6eprivate registry<\/p>\n<pre><code>registry=https:\/\/artifactory.canux.com\/artifactory\/api\/npm\/iep.npm-virtual\nalways-auth=true\nemail=&lt;user-email&gt;\n\/\/artifactory.arm.com\/artifactory\/api\/npm\/:_auth=&lt;token&gt;\n<\/code><\/pre>\n<h2 id=\"npmignore\">npmignore<\/h2>\n<p>\u6253\u5305\u7684\u65f6\u5019\u5ffd\u7565\u7684\u6587\u4ef6\u548c\u76ee\u5f55\uff0c\u4f18\u5148\u7ea7\u9ad8\u4e8egitignore\u3002<\/p>\n<h2 id=\"packagejson\">package.json<\/h2>\n<p>package.json<\/p>\n<p>package-locks<\/p>\n<p>package-lock.json<\/p>\n<hr>\n<h2 id=\"yarn\">yarn<\/h2>\n<p><a class=\"link\" href=\"https:\/\/yarnpkg.com\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/yarnpkg.com\/<\/a><\/p>\n<p>\u4f7f\u7528corepack\u5b89\u88c5yarn\u3002<\/p>\n<p>\u6fc0\u6d3bcorepack<\/p>\n<pre><code>$ corepack enable\n<\/code><\/pre>\n<p>\u5b89\u88c5yarn<\/p>\n<pre><code>$ corepack prepare yarn@3.8.1 --activate\n<\/code><\/pre>\n<p>CLI:<\/p>\n<pre><code>\/\/ yarn config, yarn \u4f1a\u8bfbnpmrc\nyarn config\ncacheFolder: $HOME\/.yarn\/berry\/cache\nglobalFolder: $HOME\/.yarn\/berry\n\/\/ create package.json\n$ yarn init\n\/\/ \u8bbe\u7f6eproject\u7684yarn version\uff0c\u81ea\u52a8\u4e0b\u8f7d.yarn\/release\/yarn-&lt;version&gt;.cjs\nyarn set version berry\n\/\/ remove all local archives\n$ yarn cache clean\n\/\/ add\/remove\/install dependencies\n$ yarn add ...\n$ yarn remove ...\n$ yarn install --inline-builds\n\/\/ nodejs\n$ yarn node\n\/\/ check npm package information\n$ yarn npm info react\n\/\/ run script defined in package.json\n$ yarn run &lt;scriptName&gt;\n\/\/ plugin management\n$ yarn plugin ......\n\/\/ workspace management\n$ yarn workspaces ...\n$ yarn workspaces list\n$ yarn workspaces foreach \/\/ run command on all workspaces\n\/\/ login to private registry\nyarn npm login\nyarn npm logout\nyarn npm publish\nnpmRegistries:\n&quot;https:\/\/artifactory.arm.com\/artifactory\/api\/npm\/iep.npm-virtual&quot;:\nnpmAuthToken: &lt;token&gt;\nyarn build\n&quot;exports&quot;: {\n&quot;.&quot;: &quot;.\/src\/index.ts&quot;,\n&quot;.\/alpha&quot;: &quot;.\/src\/alpha.ts&quot;,\n&quot;.\/package.json&quot;: &quot;.\/package.json&quot;\n},\n<\/code><\/pre>"},{"title":"Web","link":"https:\/\/canuxcheng.com\/post\/web\/","pubDate":"Tue, 27 Sep 2016 03:25:26 +0000","guid":"https:\/\/canuxcheng.com\/post\/web\/","description":"<h1 id=\"web\">WEB<\/h1>\n<p>web\u4e00\u822c\u5305\u62ecweb server, web service, load balancing.<\/p>\n<p>URL: Uniform Resource Locator, \u7edf\u4e00\u8d44\u6e90\u5b9a\u4f4d\u7b26\uff0e<\/p>\n<pre><code>scheme:\/\/host[:port#]\/path\/...\/[?query-string][#anchor]\n<\/code><\/pre>\n<p>DNS: Domain Name System, \u57df\u540d\u7cfb\u7edf.<\/p>\n<p>header: header\u4e2d\u7528\u6765\u4fdd\u5b58session\uff0ccookie\u7b49\u5934\u90e8\u4fe1\u606f\uff0e<\/p>\n<p>session: \u670d\u52a1\u7aef\u7684\u6570\u636e\u5b58\u50a8\u673a\u5236\uff0e<\/p>\n<p>cookie: \u5ba2\u6237\u7aef\u7684\u6570\u636e\u5b58\u50a8\u673a\u5236\uff0e\u5206\u4e3a\u4f1a\u8bddcookie\u548c\u6301\u4e45cookie.<\/p>\n<hr>\n<h1 id=\"webserver\">webserver<\/h1>\n<p>LAMP: Linux+apache+mysql+php<\/p>\n<p>LNMP: Linux+nginx+mysql+php<\/p>\n<h1 id=\"blog\u9759\u6001\u7ad9\u70b9\">Blog\u9759\u6001\u7ad9\u70b9<\/h1>\n<p>hugo\u662fgolang\u5f00\u53d1\u7684\u9759\u6001\u7ad9\u70b9\u751f\u6210\u5668\uff0e<\/p>\n<p>pelican\u662fpython\u5f00\u53d1\u7684\u9759\u6001\u7ad9\u70b9\u751f\u6210\u5668.<\/p>\n<p>hexo\u662fnodejs\u5f00\u53d1\u7684\u9759\u6001\u7ad9\u70b9\u751f\u6210\u5668.<\/p>\n<p>jekyll\u662fruby\u5f00\u53d1\u7684\u9759\u6001\u7ad9\u70b9\u751f\u6210\u5668.<\/p>\n<p>octopress\u662fruby\u5f00\u53d1\u7684kekyll\u7684\u5347\u7ea7\u7248.<\/p>\n<h1 id=\"cms\u7cfb\u7edf\">CMS\u7cfb\u7edf<\/h1>\n<p>wordpress\u662fphp\u5f00\u53d1\u7684website, blog, app\u6846\u67b6\u3002<\/p>\n<p>joomla\u662fphp\u5f00\u53d1\u7684\u5185\u5bb9\u7ba1\u7406\u7cfb\u7edf.<\/p>\n<p>drupal\u662fphp\u5f00\u53d1\u7684\u5185\u5bb9\u7ba1\u7406\u7cfb\u7edf.<\/p>\n<p>django-cms\u662fpython\u5f00\u53d1\u7684\u57fa\u4e8edjango\u7684\u5185\u5bb9\u7ba1\u7406\u7cfb\u7edf.<\/p>\n<p>wagtail\u662fpython\u5f00\u53d1\u7684\u57fa\u4e8edjango\u7684\u5185\u5bb9\u7ba1\u7406\u7cfb\u7edf.<\/p>\n<p>mezzanine\u662fpython\u5f00\u53d1\u7684\u57fa\u4e8edjango\u7684\u5185\u5bb9\u7ba1\u7406\u7cfb\u7edf.<\/p>\n<h1 id=\"forum\u7cfb\u7edf\">Forum\u7cfb\u7edf<\/h1>\n<p>vanilla\u662fphp\u5f00\u53d1\u7684\u8bba\u575b\u7cfb\u7edf.<\/p>\n<p>phpbb\u662fphp\u5f00\u53d1\u7684\u8bba\u575b\u7cfb\u7edf.<\/p>\n<hr>\n<h1 id=\"webservice\">webservice<\/h1>\n<p>web service\u662f\u4e00\u79cd\u6807\u51c6,\u5c06\u5e94\u7528\u7a0b\u5e8f\u8f6c\u6362\u6210\u7f51\u7edc\u5e94\u7528\u7a0b\u5e8f.<\/p>\n<p>WSDL:\u7f51\u7edc\u670d\u52a1\u63cf\u8ff0\u8bed\u8a00<\/p>\n<p>UDDI:<\/p>\n<p>RDF:<\/p>\n<p>RSS:<\/p>\n<p>SOAP: \u662f\u4e00\u79cd\u7b80\u5355\u7684\u57fa\u4e8eXML\u7684\u534f\u8bae\uff0c\u5b83\u4f7f\u5e94\u7528\u7a0b\u5e8f\u901a\u8fc7HTTP\u6765\u4ea4\u6362\u4fe1\u606f\u3002<\/p>\n<hr>"},{"title":"TPL","link":"https:\/\/canuxcheng.com\/post\/django_tpl\/","pubDate":"Tue, 27 Sep 2016 01:33:42 +0000","guid":"https:\/\/canuxcheng.com\/post\/django_tpl\/","description":"<h1 id=\"django-third-party-library\">Django Third Party Library.<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/rosarior\/awesome-django\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/rosarior\/awesome-django<\/a><\/p>\n<p>Add this application to your django project in settings.py.<\/p>\n<pre><code>INSTALLED_APPS = (\n'south',\n'debug_toolbar',\n'crispy_forms',\n...\n)\n<\/code><\/pre>\n<h1 id=\"django-rest-framework\">django-rest-framework<\/h1>\n<p>django\u7684RESTful API\u7684application\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/tomchristie\/django-rest-framework\/tree\/master\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/tomchristie\/django-rest-framework\/tree\/master<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/django-json-api\/django-rest-framework-json-api\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/django-json-api\/django-rest-framework-json-api<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/SimpleJWT\/django-rest-framework-simplejwt\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/SimpleJWT\/django-rest-framework-simplejwt<\/a><\/p>\n<hr>\n<h1 id=\"admin-interface\">admin interface<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/geex-arts\/django-jet\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/geex-arts\/django-jet<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/sehmaschine\/django-grappelli\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/sehmaschine\/django-grappelli<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/darklow\/django-suit\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/darklow\/django-suit<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/sshwsfc\/xadmin\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/sshwsfc\/xadmin<\/a><\/p>\n<h1 id=\"authentication\">authentication<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/etianen\/django-python3-ldap\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/etianen\/django-python3-ldap<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/pennersr\/django-allauth\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/pennersr\/django-allauth\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/django-guardian\/django-guardian\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/django-guardian\/django-guardian<\/a><\/p>\n<h1 id=\"database\">database<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/django-dbbackup\/django-dbbackup\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/django-dbbackup\/django-dbbackup<\/a><\/p>\n<h1 id=\"debug\">debug<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/jazzband\/django-debug-toolbar\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/jazzband\/django-debug-toolbar<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/django-extensions\/django-extensions\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/django-extensions\/django-extensions\/<\/a><\/p>\n<h1 id=\"form\">form<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/django-crispy-forms\/django-crispy-forms\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/django-crispy-forms\/django-crispy-forms<\/a><\/p>\n<h1 id=\"search\">search<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/carltongibson\/django-filter\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/carltongibson\/django-filter<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/django-haystack\/django-haystack\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/django-haystack\/django-haystack<\/a><\/p>\n<h1 id=\"security\">security<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/adamchainz\/django-cors-headers\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/adamchainz\/django-cors-headers<\/a><\/p>\n<hr>\n<h1 id=\"cms-project\">CMS Project<\/h1>\n<h2 id=\"django-cms\">django-cms<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/divio\/django-cms\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/divio\/django-cms\/<\/a><\/p>\n<h2 id=\"wagtail\">wagtail<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/wagtail\/wagtail\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/wagtail\/wagtail<\/a><\/p>\n<h2 id=\"mezzanine\">mezzanine<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/stephenmcd\/mezzanine\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/stephenmcd\/mezzanine\/<\/a><\/p>\n<hr>\n<h1 id=\"e-commerce-project\">e-Commerce Project<\/h1>\n<h2 id=\"django-oscar\">django-oscar<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/django-oscar\/django-oscar\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/django-oscar\/django-oscar<\/a><\/p>\n<h2 id=\"django-shop\">django-shop<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/awesto\/django-shop\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/awesto\/django-shop<\/a><\/p>\n<hr>\n<h1 id=\"pm-project\">PM Project<\/h1>\n<h2 id=\"taiga\">taiga<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/taigaio\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/taigaio<\/a><\/p>"},{"title":"Apache","link":"https:\/\/canuxcheng.com\/post\/apache\/","pubDate":"Tue, 27 Sep 2016 03:25:26 +0800","guid":"https:\/\/canuxcheng.com\/post\/apache\/","description":"<h1 id=\"apache\">Apache<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/apache\/httpd\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/apache\/httpd<\/a><\/p>\n<p><a class=\"link\" href=\"http:\/\/httpd.apache.org\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/httpd.apache.org\/<\/a><\/p>\n<p>ubuntu\/debian\uff1a<\/p>\n<pre><code>sudo aptitude install apache2\n<\/code><\/pre>\n<p>redhat\/centos\/fedora:<\/p>\n<pre><code>$ sudo yum install httpd2\n<\/code><\/pre>\n<p>\u542f\u52a8\u670d\u52a1\u5668\uff1a<\/p>\n<pre><code>service apache2 start\n<\/code><\/pre>\n<p>\u542f\u52a8\u6d4f\u89c8\u5668\u67e5\u770b\uff1a<\/p>\n<pre><code>http:\/\/localhost:80\n<\/code><\/pre>\n<hr>\n<h1 id=\"apache\u547d\u4ee4\">apache\u547d\u4ee4<\/h1>\n<p>apache2ctl:<\/p>\n<pre><code>\/\/ \u68c0\u67e5\u914d\u7f6e\n$ apache2ctl configtest\n<\/code><\/pre>\n<p>a2ensite<\/p>\n<pre><code>\/\/ \u542f\u7528\u4e00\u4e2a\u7ad9\u70b9\n$ sudo a2ensite &lt;site&gt;\n<\/code><\/pre>\n<p>a2dissite<\/p>\n<pre><code>$ sudo a2dissite &lt;site&gt;\n<\/code><\/pre>\n<p>a2enmod<\/p>\n<pre><code>\/\/ \u542f\u7528\u4e00\u4e2a\u6a21\u5757\n$ sudo a2enmod &lt;mod&gt;\n<\/code><\/pre>\n<p>a2dismod<\/p>\n<pre><code>$ sudo a2dismod &lt;mod&gt;\n<\/code><\/pre>\n<h1 id=\"\u914d\u7f6e\">\u914d\u7f6e<\/h1>\n<p>\u914d\u7f6e\u7ad9\u70b9site-enable\/site.conf:<\/p>\n<pre><code>&lt;VirtualHost *:8080&gt;\nServerAdmin webmaster@localhost\nDocumentRoot \/opt\n# \u9002\u5408\u591a\u76ee\u5f55\nAlias \/qa \/opt\/qa\nAlias \/dev \/opt\/dev\nErrorLog ${APACHE_LOG_DIR}\/error.log\nCustomLog ${APACHE_LOG_DIR}\/access.log combined\n&lt;\/VirtualHost&gt;\n<\/code><\/pre>\n<p>\u4fee\u6539\u6743\u9650apache2.conf:<\/p>\n<pre><code>&lt;Directory \/opt\/qa&gt;\nOptions Indexes FollowSymLinks\nAllowOverride None\nRequire all granted\n&lt;\/Directory&gt;\n&lt;Directory \/opt\/dev&gt;\nOptions Indexes FollowSymLinks\nAllowOverride None\nRequire all granted\n&lt;\/Directory&gt;\n<\/code><\/pre>\n<p>\u4fee\u6539\u7aef\u53e3ports.conf:<\/p>\n<pre><code>Listen 8080\n&lt;IfModule ssl_module&gt;\nListen 4433\n&lt;\/IfModule&gt;\n&lt;IfModule mod_gnutls.c&gt;\nListen 4433\n&lt;\/IfModule&gt;\n<\/code><\/pre>\n<p>\u914d\u7f6essl\u548cbasic auth<\/p>\n<pre><code># \u5b89\u88c5\u521b\u5efa\u8d26\u53f7\u7684\u5de5\u5177\nsudo apt-get install apache2-utils\n\u521b\u5efa\u8d26\u53f7\nsudo htpasswd -c \/etc\/apache2\/.htpasswd user\nsudo htpasswd \/etc\/apache2\/.htpasswd another_user\n<\/code><\/pre>\n<p>\u542f\u7528\u4f9d\u8d56\u7684\u6a21\u5757:<\/p>\n<pre><code>cd \/etc\/apache2\/mods-enabled\nln -sf ..\/mods-available\/rewrite.load rewrite.load\nln -sf ..\/mods-available\/ssl.conf ssl.conf\nln -sf ..\/mods-available\/ssl.load ssl.load\n#ln -sf ..\/mods-available\/slotmem_shm.load slotmem_shm.load\n#ln -sf ..\/mods-available\/socache_shmcb.load socache_shmcb.load\n<\/code><\/pre>\n<p>\u4fee\u6539site-avaliable\/site.conf<\/p>\n<pre><code>&lt;VirtualHost *:80&gt;\nServerAdmin webmaster@localhost\nDocumentRoot \/var\/www\n\/\/ \u5c06http\u91cd\u5b9a\u5411\u5230https, \u5982\u679c\u6ce8\u91ca\u6389\uff0chttp\u548chttps\u90fd\u53ef\u4ee5\u8bbf\u95ee.\nRewriteEngine on\nRewriteCond %{SERVER_PORT} !^443$\nRewriteRule ^\/(.*) https:\/\/%{HTTP_HOST}\/$1 [NC,R=301,L]\nLogLevel warn\nErrorLog \/var\/log\/apache2\/error.log\nCustomLog \/var\/log\/apache2\/access.log combined\n&lt;\/VirtualHost&gt;\n&lt;VirtualHost *:443&gt;\nServerAdmin webmaster@localhost\nDocumentRoot \/var\/www\n\/\/ \u5f00\u542fssl\nSSLEngine on\nSSLCertificateFile &quot;\/etc\/apache2\/user.domain.com.crt&quot;\nSSLCertificateKeyFile &quot;\/etc\/apache2\/user.domain.com.key&quot;\nBrowserMatch &quot;MSIE [2-6]&quot; nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0\nBrowserMatch &quot;MSIE [17-9]&quot; ssl-unclean-shutdown\n\/\/ \u5f00\u542fbasic auth.\n&lt;Directory &quot;\/var\/www&quot;&gt;\nAuthType Basic\nAuthName &quot;Restricted Content&quot;\nAuthUserFile \/etc\/apache2\/.htpasswd\nRequire valid-user\n&lt;\/Directory&gt;\nLogLevel warn\nErrorLog \/var\/log\/apache2\/error.log\nCustomLog \/var\/log\/apache2\/access.log combined\n&lt;\/VirtualHost&gt;\n<\/code><\/pre>"},{"title":"Django","link":"https:\/\/canuxcheng.com\/post\/django\/","pubDate":"Tue, 20 Sep 2016 23:14:07 +0000","guid":"https:\/\/canuxcheng.com\/post\/django\/","description":"<h1 id=\"django\">Django<\/h1>\n<p>django\u662fpython\u7684web\u6846\u67b6\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/django\/django\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/django\/django<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/www.djangoproject.com\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.djangoproject.com\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/docs.djangoproject.com\/zh-hans\/3.1\/contents\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.djangoproject.com\/zh-hans\/3.1\/contents\/<\/a><\/p>\n<p>django\u9075\u5b88MVC\u8bbe\u8ba1\u6a21\u5f0f\uff0c\u91c7\u7528MTV\u6846\u67b6\u3002<\/p>\n<p>django\u7684MTV\u548c\u4f20\u7edf\u7684MVC\u533a\u522b\u662f\uff1acontroller\u7531\u6846\u67b6\u81ea\u52a8\u7ba1\u7406\u3002<\/p>\n<p>M: model,\u6570\u636e\u903b\u8f91\uff0c\u5b9a\u4e49\u6570\u636e\u7ed3\u6784\u3002<\/p>\n<p>T: template\uff0c\u5982\u4f55\u5c55\u73b0\u6570\u636e\uff0c\u6e32\u67d3html\u3002<\/p>\n<p>V: view\uff0c\u4e1a\u52a1\u903b\u8f91\uff0c\u5904\u7406\u8bf7\u6c42\u548c\u54cd\u5e94\u3002<\/p>\n<h1 id=\"\u5b89\u88c5\">\u5b89\u88c5<\/h1>\n<p><a class=\"link\" href=\"https:\/\/docs.djangoproject.com\/zh-hans\/3.1\/faq\/install\/#faq-python-version-support\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.djangoproject.com\/zh-hans\/3.1\/faq\/install\/#faq-python-version-support<\/a><\/p>\n<p>django1.11\u662f\u6700\u540e\u4e00\u4e2a\u652f\u6301python2.7\u7684\u957f\u671f\u652f\u6301\u7248(2017.4).<\/p>\n<p>django2.0\u5f00\u59cb\u53ea\u652f\u6301python3(2018).<\/p>\n<p>\u672c\u6587\u4ee5django3.1\u4e3a\u4f8b\u521b\u5efa\u540d\u4e3anext\u7684project.<\/p>\n<p>virtualenv\u4e2d\u5b89\u88c5\uff1a<\/p>\n<pre><code>$mkdir next\n$cd next\n$virtualenv .venv\n# mac\/linux\n$source .venv\/bin\/activate\n# windows\n&gt;cd .venv\/Scripts\n&gt;activate\n$pip install django\n<\/code><\/pre>\n<p>\u9a8c\u8bc1\u5b89\u88c5\uff1a<\/p>\n<pre><code>$python\n&gt;&gt;&gt;import django\n&gt;&gt;&gt;django.VERSION\n&gt;&gt;&gt;django.get_version()\n<\/code><\/pre>\n<p>\u5b89\u88c5\u4f7f\u7528\u7684\u6570\u636e\u5e93\u5f15\u64ce\u7684\u5e93\uff1a<\/p>\n<pre><code>$ sudo udo apt-get install libmysqlclient-dev\n$ pip install mysqlclient\n$pip install psycopg2\n$pip install cx_Oracle\n<\/code><\/pre>\n<p>django\u9ed8\u8ba4\u662fmysqlclient\uff0c\u53ef\u4ee5\u4f7f\u7528pymysql\u66ff\u4ee3\uff1a<\/p>\n<pre><code># vim settings.py\nimport pymysql\npymysql.version_info = (1, 4, 13, &quot;final&quot;, 0)\npymysql.install_as_MySQLdb()\n<\/code><\/pre>\n<hr>\n<h1 id=\"project\">project<\/h1>\n<p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3anext\u7684\u9879\u76ee<\/p>\n<pre><code>$ cd next\n$ django-admin startproject next.\nnext\n|-- manage.py\n|-- next\n|- __init__.py\n|- settings.py\n|- urls.py\n|- wsgi.py\n|- asgi.py\n<\/code><\/pre>\n<blockquote>\n<p>next \u6700\u5916\u5c42\u6839\u76ee\u5f55\u53ea\u662f\u4f60\u9879\u76ee\u7684\u5bb9\u5668\uff0c \u6839\u76ee\u5f55\u540d\u79f0\u5bf9Django\u6ca1\u6709\u5f71\u54cd\uff0c\u4f60\u53ef\u4ee5\u5c06\u5b83\u91cd\u547d\u540d\u4e3a\u4efb\u4f55\u4f60\u559c\u6b22\u7684\u540d\u79f0\u3002<\/p>\n<\/blockquote>\n<blockquote>\n<p>manage.py: \u4e00\u4e2a\u8ba9\u4f60\u7528\u5404\u79cd\u65b9\u5f0f\u7ba1\u7406 Django \u9879\u76ee\u7684\u547d\u4ee4\u884c\u5de5\u5177\u3002\u4f60\u53ef\u4ee5\u9605\u8bfb\u00a0django-admin and manage.py\u00a0\u83b7\u53d6\u6240\u6709\u00a0manage.py\u00a0\u7684\u7ec6\u8282\u3002<\/p>\n<\/blockquote>\n<blockquote>\n<p>templates: project\u7684\u6a21\u7248.<\/p>\n<\/blockquote>\n<blockquote>\n<p>next \u91cc\u5c42\u7684\u76ee\u5f55\u5305\u542b\u4f60\u7684\u9879\u76ee\uff0c\u5b83\u662f\u4e00\u4e2a\u7eaf Python \u5305\u3002\u5b83\u7684\u540d\u5b57\u5c31\u662f\u5f53\u4f60\u5f15\u7528\u5b83\u5185\u90e8\u4efb\u4f55\u4e1c\u897f\u65f6\u9700\u8981\u7528\u5230\u7684 Python \u5305\u540d\u3002 (\u6bd4\u5982\u00a0next.urls).<\/p>\n<\/blockquote>\n<blockquote>\n<blockquote>\n<p>next\/<strong>init<\/strong>.py\uff1a\u4e00\u4e2a\u7a7a\u6587\u4ef6\uff0c\u544a\u8bc9 Python \u8fd9\u4e2a\u76ee\u5f55\u5e94\u8be5\u88ab\u8ba4\u4e3a\u662f\u4e00\u4e2a Python \u5305\u3002\u5982\u679c\u4f60\u662f Python \u521d\u5b66\u8005\uff0c\u9605\u8bfb\u5b98\u65b9\u6587\u6863\u4e2d\u7684\u00a0\u66f4\u591a\u5173\u4e8e\u5305\u7684\u77e5\u8bc6\u3002<\/p>\n<\/blockquote>\n<\/blockquote>\n<blockquote>\n<blockquote>\n<p>next\/settings.py\uff1aDjango \u9879\u76ee\u7684\u914d\u7f6e\u6587\u4ef6\u3002\u5982\u679c\u4f60\u60f3\u77e5\u9053\u8fd9\u4e2a\u6587\u4ef6\u662f\u5982\u4f55\u5de5\u4f5c\u7684\uff0c\u8bf7\u67e5\u770b\u00a0Django \u914d\u7f6e\u00a0\u4e86\u89e3\u7ec6\u8282\u3002<\/p>\n<\/blockquote>\n<\/blockquote>\n<blockquote>\n<blockquote>\n<p>next\/urls.py\uff1aDjango \u9879\u76ee\u7684 URL \u58f0\u660e\uff0c\u5c31\u50cf\u4f60\u7f51\u7ad9\u7684\u201c\u76ee\u5f55\u201d\u3002\u9605\u8bfb\u00a0URL\u8c03\u5ea6\u5668\u00a0\u6587\u6863\u6765\u83b7\u53d6\u66f4\u591a\u5173\u4e8e URL \u7684\u5185\u5bb9\u3002<\/p>\n<\/blockquote>\n<\/blockquote>\n<blockquote>\n<blockquote>\n<p>next\/asgi.py\uff1a\u4f5c\u4e3a\u4f60\u7684\u9879\u76ee\u7684\u8fd0\u884c\u5728 ASGI \u517c\u5bb9\u7684Web\u670d\u52a1\u5668\u4e0a\u7684\u5165\u53e3\u3002\u9605\u8bfb\u00a0\u5982\u4f55\u4f7f\u7528 ASGI \u6765\u90e8\u7f72\u00a0\u4e86\u89e3\u66f4\u591a\u7ec6\u8282\u3002<\/p>\n<\/blockquote>\n<\/blockquote>\n<blockquote>\n<blockquote>\n<p>next\/wsgi.py\uff1a\u4f5c\u4e3a\u4f60\u7684\u9879\u76ee\u7684\u8fd0\u884c\u5728 WSGI \u517c\u5bb9\u7684Web\u670d\u52a1\u5668\u4e0a\u7684\u5165\u53e3\u3002\u9605\u8bfb\u00a0\u5982\u4f55\u4f7f\u7528 WSGI \u8fdb\u884c\u90e8\u7f72\u00a0\u4e86\u89e3\u66f4\u591a\u7ec6\u8282\u3002<\/p>\n<\/blockquote>\n<\/blockquote>\n<p>\u9a8c\u8bc1\u5f00\u53d1\u670d\u52a1\u5668\uff1a<\/p>\n<pre><code>$python manage.py runserver\n$python manage.py runserver &lt;ip address&gt;:&lt;port&gt;\n&gt; py manage.py runserver\n<\/code><\/pre>\n<p>\u6d4f\u89c8\u5668\u8f93\u5165\uff1a<\/p>\n<pre><code>http:\/\/127.0.0.1:8000\n<\/code><\/pre>\n<h2 id=\"settingspy\">settings.py<\/h2>\n<p>\u9ed8\u8ba4enable\u7684app:<\/p>\n<pre><code>INSTALLED_APPS = [\n'django.contrib.admin', \/\/\u7ba1\u7406\u5458\u7ad9\u70b9\uff0c \u4f60\u5f88\u5feb\u5c31\u4f1a\u4f7f\u7528\u5b83\u3002\n'django.contrib.auth', \/\/\u8ba4\u8bc1\u6388\u6743\u7cfb\u7edf\u3002\n'django.contrib.contenttypes', \/\/\u5185\u5bb9\u7c7b\u578b\u6846\u67b6\u3002\/\n'django.contrib.sessions', \/\/\u4f1a\u8bdd\u6846\u67b6\u3002\n'django.contrib.messages', \/\/\u6d88\u606f\u6846\u67b6\u3002\n'django.contrib.staticfiles', \/\/\u7ba1\u7406\u9759\u6001\u6587\u4ef6\u7684\u6846\u67b6\u3002\n]\n\u9ed8\u8ba4\u5f00\u542f\u7684\u67d0\u4e9b\u5e94\u7528\u9700\u8981\u81f3\u5c11\u4e00\u4e2a\u6570\u636e\u8868\uff0c\u6240\u4ee5\uff0c\u5728\u4f7f\u7528\u4ed6\u4eec\u4e4b\u524d\u9700\u8981\u5728\u6570\u636e\u5e93\u4e2d\u521b\u5efa\u4e00\u4e9b\u8868\n$ python manage.py migrate\n&gt; py manage.py migrate\n<\/code><\/pre>\n<p>\u9ed8\u8ba4enable\u7684midleware:<\/p>\n<pre><code>MIDDLEWARE = [\n'django.middleware.security.SecurityMiddleware',\n'django.contrib.sessions.middleware.SessionMiddleware',\n'django.middleware.common.CommonMiddleware',\n'django.middleware.csrf.CsrfViewMiddleware',\n'django.contrib.auth.middleware.AuthenticationMiddleware',\n'django.contrib.messages.middleware.MessageMiddleware',\n'django.middleware.clickjacking.XFrameOptionsMiddleware',\n]\n<\/code><\/pre>\n<p>\u652f\u6301\u7684template:<\/p>\n<pre><code>TEMPLATES = [\n{\n'BACKEND': 'django.template.backends.jinja2.Jinja2',\n'DIRS': [os.path.join(BASE_DIR, 'templates')],\n'APP_DIRS': True,\n'OPTIONS': {\n'context_processors': [\n'django.template.context_processors.debug',\n'django.template.context_processors.request',\n'django.contrib.auth.context_processors.auth',\n'django.contrib.messages.context_processors.messages',\n],\n},\n},\n{\n'BACKEND': 'django.template.backends.django.DjangoTemplates',\n'DIRS': [os.path.join(BASE_DIR, 'templates')],\n'APP_DIRS': True,\n'OPTIONS': {\n'context_processors': [\n'django.template.context_processors.debug',\n'django.template.context_processors.request',\n'django.contrib.auth.context_processors.auth',\n'django.contrib.messages.context_processors.messages',\n],\n},\n}\n]\n<\/code><\/pre>\n<p>\u9ed8\u8ba4\u7684\u6570\u636e\u5e93:<\/p>\n<pre><code>DATABASES = {\n'default': {\n'ENGINE': 'django.db.backends.sqlite3',\n'NAME': BASE_DIR \/ 'db.sqlite3',\n'TEST': {\n\/\/ \u9ed8\u8ba4\u6d4b\u8bd5\u6570\u636e\u5e93\u662ftest_ \u52a0 default.NAME\uff0cTEST\u53ef\u4ee5\u6307\u5b9a\u6570\u636e\u5e93\u540d\u5b57.\n'NAME': 'test_db'\n}\n}\n}\n\/\/ \u53ef\u6269\u5c55\u7684\u6570\u636e\u5e93\nENGINE:\ndjango.db.backends.mysql\ndjango.db.backends.oracle\ndjango.db.badkends.postgresql_psycopg2\nNAME:\nyour database name\nUSER:\nyour database username\nPASSWORD:\nyour database password\nHOST:\nlocal database or remote database\nPORT:\ndatabase port\n<\/code><\/pre>\n<p>\u5176\u5b83\u914d\u7f6e\uff1a<\/p>\n<pre><code>BASE_DIR = Path(__file__).resolve().parent.parent\nSECRET_KEY = '-%b)79izbio$!(g!0io(he)giaqi1@))fzfq!t3s1g1dzysc(r'\nWSGI_APPLICATION = 'next.wsgi.application'\nROOT_URLCONF = 'next.urls'\nDEBUG = True # \u5f00\u53d1\u7528\u6765\u8c03\u8bd5\nDEBUG = False # \u90e8\u7f72\u4e4b\u540e\u5173\u95ed\nALLOWED_HOSTS = [] # \u8bbe\u7f6e\u54ea\u4e9b\u57df\u540d\u53ef\u4ee5\u8bbf\u95ee\uff0c\u4f18\u5148\u7ea7\u9ad8\u4e8eweb\u670d\u52a1\u5668\uff0cdebug=false\u5fc5\u987b\u8bbe\u7f6e\nALLOWED_HOSTS = [''*''] # \u5141\u8bb8\u6240\u6709\u57df\u540d\u8bbf\u95ee\nSTATIC_URL = '\/static\/'\nSTATIC_ROOT = '\/path\/to\/static'\n# static\u76ee\u5f55\u5b58\u653ejs\/css\u7b49\u9759\u6001\u6587\u4ef6,collectstatic\u547d\u4ee4\u7528\u6765\u6536\u96c6\u9759\u6001\u6587\u4ef6\u3002\nLANGUAGE_CODE = 'en-us'\nTIME_ZONE = 'UTC'\nUSE_I18N = True\nUSE_L10N = True\nUSE_TZ = True\n<\/code><\/pre>\n<h2 id=\"urlspy\">urls.py<\/h2>\n<pre><code>from django.contrib import admin\nfrom django.urls import path, include\nurlpatterns = [\npath('polls\/', include('polls.urls')),\npath('admin\/', admin.site.urls),\n]\n<\/code><\/pre>\n<p>\u5728\u9879\u76ee\u7684urls\u6dfb\u52a0\u6240\u6709\u5e94\u7528\u7684urls\uff0c\u4e3a\u6bcf\u4e2a\u5e94\u7528\u72ec\u7acb\u521b\u5efaurls\uff0c\u65b9\u4fbf\u7ba1\u7406\u3002<\/p>\n<h2 id=\"wsgipy\">wsgi.py<\/h2>\n<p>Web Server Gateway Interface.<\/p>\n<pre><code>import os\nfrom django.core.wsgi import get_wsgi_application\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'next.settings')\napplication = get_wsgi_application()\ndjango\u901a\u8fc7wsgi\u6765\u90e8\u7f72\uff0c\u53c2\u8003django\u7684deploy\u3002\n<\/code><\/pre>\n<h2 id=\"asgipy\">asgi.py<\/h2>\n<p>Asynchronous Server Gateway Interface.<\/p>\n<pre><code>import os\nfrom django.core.asgi import get_asgi_application\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'next.settings')\napplication = get_asgi_application()\n<\/code><\/pre>\n<hr>\n<h1 id=\"application\">application<\/h1>\n<p>\u5e94\u7528\uff0c\u4e00\u4e2a\u9879\u76ee\u53ef\u4ee5\u6709\u591a\u4e2a\u5e94\u7528\uff0c\u4e00\u4e2a\u5e94\u7528\u53ef\u4ee5\u7528\u5230\u591a\u4e2a\u9879\u76ee\u4e2d\u3002<\/p>\n<p>\u53ef\u4ee5\u5355\u72ec\u6253\u5305\u5e94\u7528\u53d1\u5e03\u5230pypi\uff0c\u5305\u540d\u683c\u5f0fdjango-project\uff0c\u53c2\u8003python\u7684\u6253\u5305\u65b9\u6cd5\u3002<\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3apolls\u7684\u5e94\u7528\uff1a<\/p>\n<pre><code>$python manage.py startapp polls\n&gt; py manage.py startapp polls\npolls\/\n|- __init__.py\n|- admin.py\n|- apps.py\n|- models.py\n|- views.py\n|- tests.py (tests\/test_case.py)\n|- migrations\n|- __init__.py\n|- templates\n|- polls\n|- index.html\n|- static\n|- polls\n|- style.css\n<\/code><\/pre>\n<blockquote>\n<p>admin.py admin\u7ba1\u7406\u754c\u9762<\/p>\n<\/blockquote>\n<blockquote>\n<p>apps.py<\/p>\n<\/blockquote>\n<blockquote>\n<p>models.py \u6a21\u578b<\/p>\n<\/blockquote>\n<blockquote>\n<p>views.py \u89c6\u56fe<\/p>\n<\/blockquote>\n<blockquote>\n<p>urls.py \u65b0\u5efa\u7684application\u7684url<\/p>\n<\/blockquote>\n<blockquote>\n<p>test.py \u6d4b\u8bd5<\/p>\n<\/blockquote>\n<blockquote>\n<p>migrations \u8fc1\u79fb\u6587\u4ef6\u5939<\/p>\n<\/blockquote>\n<blockquote>\n<p>templates \u5e94\u7528\u7684\u6a21\u7248\u6587\u4ef6\u5939<\/p>\n<\/blockquote>\n<blockquote>\n<p>static \u9759\u6001\u6587\u4ef6<\/p>\n<\/blockquote>\n<hr>\n<h1 id=\"django-admin--managepy\">django-admin &amp; manage.py<\/h1>\n<pre><code>[staticfiles]\ncollectstatic # \u8bbe\u7f6eSTATIC_ROOT = '\/var\/www\/static\/project\/'\u7528\u6765\u6536\u96c6\u9759\u6001\u6587\u4ef6\nfindstatic\nrunserver # \u542f\u52a8django\u81ea\u5e26\u7684web\u5f00\u53d1\u670d\u52a1\u5668\n[sessions]\nclearsessions\n[auth]\nchangepassword\ncreatesuperuser\n[contenttypes]\nremove_stale_contenttypes\n[django]\nstartapp\nstartproject\ncheck\ncompilemessages\ncreatecachetable\ndbshell # \u6570\u636e\u5e93\u547d\u4ee4\u884c\ndiffsettings\ndumpdata # \u5bfc\u51fa\u6570\u636e (json, xml, yaml)\ndumpdata &gt; db.json\nflush # \u6e05\u7a7a\u6570\u636e\u5e93\nloaddata # \u5bfc\u5165\u6570\u636e\nloaddata db.json\ninspectdb\nmakemessages\nmakemigrations # \u521b\u5efa\u8fc1\u79fb\u6587\u4ef6\nmigrate # \u521b\u5efa\/\u66f4\u65b0\u8868\u7ed3\u6784\uff08\u6267\u884c\u8fc1\u79fb\u6587\u4ef6\uff09\nsendtestemail\nshell # \u9879\u76ee\u73af\u5883\u7ec8\u7aef\nshowmigrations # \u67e5\u770b\u53ef\u8fc1\u79fb\u7684\u6587\u4ef6\nsqlflush\nsqlmigrate # \u67e5\u770b\u8fc1\u79fb\u6587\u4ef6\u4f1a\u6267\u884c\u54ea\u4e9bsql\nsqlsequencereset\nsquashmigrations\ntest\ntestserver\n<\/code><\/pre>"},{"title":"Http","link":"https:\/\/canuxcheng.com\/post\/http\/","pubDate":"Tue, 13 Sep 2016 01:39:34 +0000","guid":"https:\/\/canuxcheng.com\/post\/http\/","description":"<h1 id=\"httphttps\">HTTP\/HTTPS<\/h1>\n<p>http port: 80<\/p>\n<p>https port: 443<\/p>\n<p>http\/https\u7684\u8bf7\u6c42\u65b9\u5f0f\uff1a<\/p>\n<pre><code>get # \u4ece\u670d\u52a1\u5668\u53d6\u51fa\u8d44\u6e90\npost # \u5728\u670d\u52a1\u5668\u65b0\u5efa\u8d44\u6e90\nput # \u5728\u670d\u52a1\u5668\u66f4\u65b0\u8d44\u6e90\uff0c\u5ba2\u6237\u7aef\u63d0\u4f9b\u6539\u53d8\u540e\u7684\u5b8c\u6574\u8d44\u6e90\ndelete # \u4ece\u670d\u52a1\u5668\u5220\u9664\u8d44\u6e90\npatch # \u5728\u670d\u52a1\u5668\u66f4\u65b0\u8d44\u6e90\uff0c\u5ba2\u6237\u7aef\u63d0\u4f9b\u6539\u53d8\u7684\u5c5e\u6027\nhead # \u83b7\u53d6\u8d44\u6e90\u7684\u6e90\u6570\u636e\noptions # \u83b7\u53d6\u8d44\u6e90\u7684\u54ea\u4e9b\u4fe1\u606f\u662f\u5ba2\u6237\u7aef\u53ef\u4ee5\u6539\u53d8\u7684\u4fe1\u606f\n<\/code><\/pre>\n<p>URL: Uniform Resource Locator<\/p>\n<p>URI: Universal Resource Identifier<\/p>\n<pre><code>&lt;scheme&gt;:\/\/&lt;netloc&gt;\/&lt;path&gt;;&lt;params&gt;?&lt;query&gt;#&lt;fragment&gt;\nscheme: http\/https\/ftp\/file\nnetloc: username:password@host:port\npath: \/path\/to\/path\nparams: options arguments\nquery: connector&amp;key-value\nfragment:\n<\/code><\/pre>\n<hr>\n<h1 id=\"http\u547d\u4ee4\">http\u547d\u4ee4<\/h1>\n<h2 id=\"curl\">curl<\/h2>\n<pre><code>$ curl [options] [URL...]\n<\/code><\/pre>\n<h2 id=\"httpie\">httpie<\/h2>\n<p>python\u5f00\u53d1\u7684\u7c7b\u4f3c\u4e8ecurl\u7684\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u540c\u65f6\u8fd8\u6709wget\u7684\u529f\u80fd\uff0e<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/jakubroztocil\/httpie\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/jakubroztocil\/httpie<\/a><\/p>\n<pre><code>$ sudo yum\/apt-get install httpie\n$ http -a 'username:password' GET http:\/\/google.com\n<\/code><\/pre>\n<hr>\n<h1 id=\"python\u7684http\u6807\u51c6\u5e93\">python\u7684http\u6807\u51c6\u5e93<\/h1>\n<p>python2\u7684http\u6807\u51c6\u5e93<\/p>\n<ol>\n<li>httplib for client<\/li>\n<li>BaseHTTPServer, CGIHTTPServer, SimpleHTTPServer, cookielib, Cookie for server<\/li>\n<\/ol>\n<p>python3\u7684\u6807\u51c6\u5e93<\/p>\n<ol>\n<li>http<\/li>\n<\/ol>\n<h1 id=\"python\u7684url\u6807\u51c6\u5e93\">python\u7684url\u6807\u51c6\u5e93<\/h1>\n<p>python2\u7684url\u6807\u51c6\u5e93\uff1a<\/p>\n<ol>\n<li>urlparse<\/li>\n<li>urllib<\/li>\n<li>urllib2<\/li>\n<\/ol>\n<p>python3\u7684url\u6807\u51c6\u5e93\uff1a<\/p>\n<ol>\n<li>urllib<\/li>\n<\/ol>\n<hr>"},{"title":"PSL_builtins","link":"https:\/\/canuxcheng.com\/post\/psl_builtins\/","pubDate":"Mon, 15 Aug 2016 11:16:29 +0000","guid":"https:\/\/canuxcheng.com\/post\/psl_builtins\/","description":"<h1 id=\"builtins\">builtins<\/h1>\n<p>python\u7684\u5185\u7f6e\u6a21\u5757\uff0c\u6240\u6709python\u7684\u5185\u7f6e\u529f\u80fd\u90fd\u5728\u8fd9\u4e2a\u6a21\u5757\u4e2d\uff0c\u4e0d\u9700\u8981import\u5bfc\u5165\u5c31\u53ef\u4ee5\u4f7f\u7528\u3002<\/p>\n<p>\u5305\u62ec\u5185\u7f6e\u7c7b\u7c7b\u578b\u4ee5\u53ca\u6240\u5c5e\u7684\u5185\u7f6e\u65b9\u6cd5\uff0c\u548c\u5185\u7f6e\u51fd\u6570.<\/p>\n<p>\u5185\u7f6e\u5e38\u91cf<\/p>\n<p>\u5185\u7f6e\u51fd\u6570(BIF)<\/p>\n<p>\u5185\u7f6e\u7c7b\u578b(BIT)<\/p>\n<p>\u5de5\u5382\u51fd\u6570\uff1apython\u5185\u7f6e\u7684\u7c7b\u578b\u90fd\u6709\u5bf9\u5e94\u7684\u7c7b\u7684\u5b9e\u73b0\uff0c\u540c\u540d\u7684\u7c7b\u7684\u65b9\u6cd5\u5c31\u662f\u5de5\u5382\u51fd\u6570\uff0e<\/p>\n<p>\u5185\u7f6e\u7c7b\u578b\u7684\u5185\u7f6e\u65b9\u6cd5(BIM)<\/p>\n<p>\u5185\u7f6e\u5f02\u5e38<\/p>\n<p>\u8be5\u6a21\u5757\u662f\u901a\u8fc7C\/C++\u5b9e\u73b0\u7684\uff0e<\/p>\n<pre><code>import builtins # can be ignored\ndir(builtins)\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u5185\u7f6e\u7279\u6b8a\u5e38\u91cf\">\u5185\u7f6e\u7279\u6b8a\u5e38\u91cf<\/h1>\n<pre><code>False # \u5185\u7f6e\u7c7b\u578bbool\u7684\u5b9e\u4f8b\nTrue # \u5185\u7f6e\u7c7b\u578bbool\u7684\u5b9e\u4f8b\nNone # python\u7684Null\u5bf9\u8c61\u6216types.NoneType,\u53ea\u6709\u4e00\u4e2a\u503cNone.\u5e03\u5c14\u503c\u59cb\u7ec8\u4e3aFalse.\nNotImplemented # types.NotImplementedType\nEllipsis # types.EllipsisType, \u7701\u7565\u5bf9\u8c61\uff0c\u5e03\u5c14\u503c\u59cb\u7ec8\u4e3aTrue.\n__debug__ # True\/False\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u5185\u7f6e\u51fd\u6570\">\u5185\u7f6e\u51fd\u6570<\/h1>\n<p>\u4e0d\u9700\u8981import\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u7684\u51fd\u6570<\/p>\n<pre><code>__import__(name, globals={}, locals={}, fromlist=[], level=-1) # import\u5173\u952e\u5b57\u5b9e\u9645\u8c03\u7528\u8be5\u51fd\u6570\nprint(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False) # python3\u65b0\u589e\ncompile(source, filename, mode[, flags[, dont_inherit]])\n# \u7f16\u8bd1source\u8fd4\u56de\u4e00\u4e2acode\u5bf9\u8c61(\u4ee3\u7801\u5bf9\u8c61)\uff0e\n# mode: exec, \u7528\u4e8e\u6a21\u5757 python2\u53ef\u4ee5\u7528exec\u5173\u952e\u5b57\u6267\u884c,python3\u6539\u6210exec()\u51fd\u6570;\nmodule = &quot;for i in xrange(10): print(i)&quot;\ncode = compile(module, '', 'exec')\ntype(code) # code\nexec code\n# mode: single, \u7528\u4e8e\u5355\u884c\u8bed\u53e5, \u4e5f\u662f\u7528exec\u6267\u884c;\ncode = compile(&quot;print 'test'&quot;, '', single)\ntype(code) # code\nexec code\n# mode: eval, \u7528\u4e8e\u8868\u8fbe\u5f0f \u53ef\u4ee5\u7528eval()\u51fd\u6570\u6267\u884c\uff0e eg:\nexpression = &quot;3 * 4&quot;\ncode = compile(expression, '', 'eval')\ntype(code) # code\neval(code)\neval(source[, globals[, locals]])\n# \u8fd4\u56depython\u8868\u8fbe\u5f0f\u7684\u7ed3\u679c\uff0csource\u53ef\u4ee5\u662fcompile()\u8fd4\u56de\u7684\u4ee3\u7801\u5bf9\u8c61\uff0c\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a\u8868\u8fbe\u5f0f\uff0e\nexec(object[, globals[, locals]]) # python3 \u65b0\u589e\n# object\u53ef\u4ee5\u662f\u4e00\u4e2a\u6587\u4ef6\u5bf9\u8c61\uff0c\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a\u8bed\u53e5\u6216\u4ee3\u7801\u5757\uff0e\nformat(value[, format_spec]) # \u8fd4\u56de\u683c\u5f0f\u5316\u540e\u7684\u5b57\u7b26\u4e32\u5f62\u5f0f\uff0e\n## \u73af\u5883\u53d8\u91cf\u76f8\u5173\nglobals() # \u8fd4\u56de\u5f53\u524d\u4f5c\u7528\u57df\u7684\u5168\u5c40\u540d\u79f0\u7a7a\u95f4\u7684\u5b57\u5178\uff0e\nlocals() # \u8fd4\u56de\u5f53\u524d\u4f5c\u7528\u57df\u7684\u5c40\u90e8\u540d\u79f0\u7a7a\u95f4\u7684\u5b57\u5178\uff0e\n## \u6570\u5b57\u7c7b\u578b\u7684\u6570\u5b66\u8fd0\u7b97\nabs(number) # \u8fd4\u56deint\/long\u7684\u7edd\u5bf9\u503c\ndivmod(x, y) # \u8fd4\u56dex\/y \u7684\u3000(\u5546\uff0c\u4f59\u6570) \u7ec4\u6210\u7684\u5143\u7ec4\npow(x, y[, z]) # \u8fd4\u56dex**y\u6216(x**y) % z\nround(number[, ndigits]) # \u8fd4\u56denumber\u56db\u820d\u4e94\u5165\u540e\u7684\u7ed3\u679c\uff0cndigits\u8868\u793a\u5c0f\u6570\u70b9\u540e\u7684\u4f4d\u6570\uff0c\u9ed8\u8ba4\u662f0.\nchr(i) # \u8fd4\u56de\u6574\u6570\uff49\u5bf9\u5e94\u7684ASCII\u5b57\u7b26\u7684\u5b57\u7b26\u4e32\u5f62\u5f0f\uff0c0 &lt;= i &lt; 256.\nord(c) # \u8fd4\u56de\u5b57\u7b26ASCII\u5b57\u7b26c\u5bf9\u5e94\u7684\u6574\u6570.\nbin(number) # \u8fd4\u56deint\/long\u7684\u4e8c\u8fdb\u5236\u7684\u5b57\u7b26\u4e32\u5f62\u5f0f\noct(number) # \u8fd4\u56deint\/long\u7684\u516b\u8fdb\u5236\u7684\u5b57\u7b26\u4e32\u5f62\u5f0f\uff0e\nhex(number) # \u8fd4\u56deint\/long\u7684\u5341\u516d\u8fdb\u5236\u7684\u5b57\u7b26\u4e32\u5f62\u5f0f.\n## \u5bf9\u8c61\u76f8\u5173\u7684\u64cd\u4f5c\nid(object) # \u8fd4\u56de\u4e00\u4e2a\u5bf9\u8c61\u7684ID, \u7528\u5185\u5b58\u5730\u5740\u4f5c\u4e3aID\u6765\u8868\u793a\u552f\u4e00\u6027. \u4e5f\u5c31\u662f\u5bf9\u8c61\u7684\u8eab\u4efd\uff0e\u7b49\u4ef7is\u5173\u952e\u5b57.\nrepr(object) # \u8fd4\u56deobject\u7684\u6807\u51c6\u5b57\u7b26\u4e32\u5f62\u5f0f\uff0c\u53ef\u4ee5\u901a\u8fc7eval()\u91cd\u65b0\u5f97\u5230\u8be5\u5bf9\u8c61\uff0eeval(repr(object)) == object. \u7ed9\u7a0b\u5e8f\u5458\u770b\u7684\u3002\nascii(object) # \u548crepr()\u51fd\u6570\u7b49\u6548\uff0e\ncallable(object) # \u5982\u679cobject\u662f\u53ef\u8c03\u7528\u7684\u8fd4\u56deTrue, \u9700\u8981\u5b9e\u73b0\u9b54\u6cd5\u65b9\u6cd5__call__()\nhash(object) # \u8fd4\u56de\u4e00\u4e2a\u5bf9\u8c61\u7684\u6563\u5217\/\u54c8\u5e0c(hash)\u503c\uff0c\u6709\u76f8\u540c\u503c\u7684\u5bf9\u8c61hash\u503c\u76f8\u540c.\u53ef\u7528\u505a\u5b57\u5178\u7684\u952e.\nlen(object) # \u8fd4\u56de\u5e8f\u5217\uff08str, tuple, list)\u6216\u6620\u5c04\uff08dict)\u7684\u957f\u5ea6\ndir([object]) # \u67e5\u770b\u5bf9\u8c61\u7684\u4fe1\u606f\ngetattr(object, name[, default]) # \u5982\u679cobject.name\u5b58\u5728,\u8fd4\u56dename\u7684\u503c\uff0c\u5426\u5219\u5982\u679cdefault\u5b58\u5728\uff0c\u8fd4\u56dedefault,\u5426\u5219\u629b\u51fa\u5f02\u5e38AttributeError, \u548csuper\u7684\u67e5\u627e\u987a\u5e8f\u4e00\u6837\uff0e\nhasattr(object, name) # \u548cgetattr\u4e00\u6837\uff0c\u4f46\u662f\u6355\u83b7\u4e86\u5f02\u5e38\uff0cobject.name\u5b58\u5728\u8fd4\u56deTrue,\u5426\u5219\u8fd4\u56deFalse.\nsetattr(object, name, value) # \u7ed9\u5bf9\u8c61\u7684\u5c5e\u6027\u8d4b\u503c\uff0c\u76f8\u5f53\u4e8eobject.name = value\ndelattr(object, name) # \u5220\u9664\u5bf9\u8c61object\u7684\u5c5e\u6027name\nisinstance(object, class-or-type-or-tuple) # \u5982\u679cobject\u662fclass-or-type\u4e2d\u6307\u5b9a\u7684\u7c7b\u6216\u7c7b\u578b\u7684\u5b9e\u4f8b\u6216\u5b50\u7c7b\u7684\u5b9e\u4f8b\uff0c\u8fd4\u56deTrue,\u5426\u5219\u8fd4\u56deFalse.\nissubclass(C, B-or-(B,A)) # \u5982\u679cC\u662fB\u6216(B,A,...)\u4e2d\u7684\u7c7b\u7684\u5b50\u7c7b\uff0c\u8fd4\u56deTrue,\u5426\u5219\u8fd4\u56deFalse. \u4e0d\u4e25\u683c\u5b50\u7c7b\u4e5f\u5141\u8bb8\uff0c\u4f8b\u5982\u4e00\u4e2a\u7c7b\u53ef\u4ee5\u770b\u4f5c\u662f\u81ea\u8eab\u7684\u5b50\u7c7b\uff0e\nvars([object]) # \u6ca1\u6709\u53c2\u6570\u7b49\u4e8elocals()\uff0c\u6709\u53c2\u6570\u7b49\u4e8eobject.__dict__.\n## related to iterable\nmin(iterable[, key=func]) # \u8fd4\u56de\u53ef\u8fed\u4ee3\u5bf9\u8c61iterable\u4e2d\u7684\u6700\u5c0f\u5143\u7d20\nmin(a, b, c, ...[, key=func]) # \u8fd4\u56dea,b,c...\u4e2d\u7684\u6700\u5c0f\u5143\u7d20\nmax(iterable[, key=func]) # \u548cmin\u76f8\u53cd\nmax(a, b, c, ...[, key=func]) # \u548cmin\u76f8\u53cd\nall(iterable) # \u5982\u679c\u53ef\u8fed\u4ee3\u7684\u53c2\u6570iterable\u4e2d\u6240\u6709\u7684\u5143\u7d20\u90fd\u4e0d\u662f0,False,''\u5219\u8fd4\u56deTrue,iterable\u4e3a\u7a7a\u4e5f\u8fd4\u56deTrue,\u5426\u5219\u8fd4\u56deFalse\nany(iterable) # \u5982\u679c\u53ef\u8fed\u4ee3\u7684\u53c2\u6570iterable\u4e2d\u6240\u6709\u7684\u5143\u7d20\u90fd\u662f0,False,''\u5219\u8fd4\u56deFalse,\u3000\u5426\u5219\u8fd4\u56deTrue\nsum(sequence[, start]) # \u8fd4\u56de\u6570\u5b57\u5e8f\u5217sequence\u7684\u6240\u6709\u5143\u7d20\u52a0\u4e0astart\u7684\u548c\uff0cstart\u9ed8\u8ba4\u662f\uff10\uff0e\n## related to iterator\niter(collection) # \u5c06\u53ef\u8fed\u4ee3\u5bf9\u8c61\uff08str, tuple, list, dict\u7684\u952e,\u96c6\u5408,\u6587\u4ef6\u7684\u884c\u7b49\uff09\u8f6c\u6362\u6210\u8fed\u4ee3\u5668,\u8fd4\u56de\u8fed\u4ee3\u5668\u5bf9\u8c61.\niter(callable, sentinel) # \u7b2c\u4e00\u4e2a\u53c2\u6570\u9700\u8981\u662fcallable\u7684\uff0c\u6bcf\u6b21\u8fed\u4ee3\u5230sentinel\u505c\u6b62\uff0e\nnext(iterator[, default]) # \u8fd4\u56de\u8fed\u4ee3\u5668iterator\u4e2d\u7684\u4e0b\u4e00\u4e2a\u5143\u7d20\uff0c\u5982\u679c\u6ca1\u6709\u5143\u7d20\u4e86\uff0cdefault\u6307\u5b9a\u5185\u5bb9\u8fd4\u56de\u8be5\u5185\u5bb9\uff0c\u5426\u5219\u629b\u51faStopIteration\u5f02\u5e38\uff0e\n## related to input\ninput([prompt]) # python3\n# \u6839\u636eprompt\u63d0\u793a\u8f93\u5165\u5185\u5bb9\uff0c\u8fd4\u56de\u8f93\u5165\u7684\u5185\u5bb9,\u5982\u679c\u662f\u8868\u8fbe\u5f0f\u4f1a\u5148\u6c42\u503c\u518d\u8fd4\u56de.\n## related to file\nopen(name[, mode[, buffering]]) # \u6253\u5f00\u4e00\u4e2a\u6587\u4ef6\uff0c\u8fd4\u56de\u4e00\u4e2afile\u7c7b\u7c7b\u578b\u7684\u5bf9\u8c61\uff0e\n\/\/ python3 refactor\nsorted(iterable, key=None, reverse=False)\n\/\/ \u591a\u7ef4\u6570\u636e\u6392\u5e8f\ndict = {'a': 3, 'b': 2, 'c': 1}\nsorted(dict.items(), key=lambda x:x[1], reverse=False)\njson = [{&quot;time&quot;: 1, &quot;data&quot;: &quot;message&quot;}, {&quot;time&quot;: 2, &quot;data&quot;: &quot;message&quot;}]\nsorted(json, key=lambda k:k[&quot;time&quot;])\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u5185\u7f6e\u5f02\u5e38\u7c7b\">\u5185\u7f6e\u5f02\u5e38\u7c7b<\/h1>\n<p>BaseException(object) # \u6240\u6709\u5f02\u5e38\u7684\u57fa\u7c7b, \u7ee7\u627f\u81eaobject.<\/p>\n<pre><code># BaseException\u7684\u56db\u4e2a\u5b50\u7c7b\nSystemExit # python\u89e3\u91ca\u5668\u8bf7\u6c42\u9000\u51fa\nKeyboardInterrupt # \u7528\u6237\u8f93\u5165ctrl-c\u4e2d\u65ad\u6267\u884c\nGeneratorExit # \u751f\u6210\u5668\u53d1\u51fa\u5f02\u5e38\u6765\u901a\u77e5\u9000\u51fa\nException # \u5e38\u89c4\u9519\u8bef\u7684\u57fa\u7c7b\nStopIteration # \u8fed\u4ee3\u5668\u7ed3\u675f\u629b\u51fa\u7684\u5f02\u5e38\nStandardError # \u6240\u6709\u5185\u7f6e\u6807\u51c6error\u7684\u57fa\u7c7b\nBufferError\nArithmeticError # \u6570\u503c\u8ba1\u7b97\u9519\u8bef\u7684\u57fa\u7c7b\nFloatingPointError\nOverflowError\nZeroDivisionError # \u9664\u6cd5\u5206\u6bcd\u4e3a\uff10\u9519\u8bef\nAsseertionError # \u65ad\u8a00\u8bed\u53e5\u5931\u8d25\nAttributeError # \u8bbf\u95ee\u672a\u77e5\u7684\u5bf9\u8c61\u5c5e\u6027\nEnvironmentError\nIOError # \u6253\u5f00\u4e0d\u5b58\u5728\u7684\u78c1\u76d8\u6587\u4ef6\u5bfc\u81f4\u7684\u8f93\u5165\/\u8f93\u51fa\u9519\u8bef\nOSError\nWindowError\nVMSError\nEOFError\nImportError\nLookupError\nIndexError # \u5e8f\u5217\u7684\u7d22\u5f15\u9519\u8bef\nKeyError # \u5b57\u5178\u7684\u952e\u9519\u8bef\nMemoryError\nNameError # \u672a\u7533\u660e\u6216\u521d\u59cb\u5316\u7684\u5bf9\u8c61\nUnboundLocalError\nReferenceError\nRuntimeError # \u4e00\u822c\u7684\u8fd0\u884c\u9519\u8bef\nNotImplementedError # \u5c1a\u672a\u5b9e\u73b0\u7684\u65b9\u6cd5\nSyntaxError # \u8bed\u6cd5\u9519\u8bef\uff0c \u552f\u4e00\u4e0d\u5728\u8fd0\u884c\u65f6\u53d1\u751f\u7684\u5f02\u5e38\nIndentationError # \u7f29\u8fdb\u9519\u8bef\nTabError # \u8df3\u683c\u548c\u7a7a\u683c\u6df7\u7528\nSystemError # \u4e00\u822c\u7684\u89e3\u91ca\u5668\u7cfb\u7edf\u9519\u8bef\nTypeError # \u5bf9\u7c7b\u578b\u65e0\u6548\u7684\u64cd\u4f5c\nValueError # \u4f20\u5165\u65e0\u6548\u7684\u53c2\u6570\nUnicodeError\nUnicodeDecodeError\nUnicodeEncodeError\nUnicodeTranslateError\nWarning # \u6240\u6709warning\u7684\u57fa\u7c7b\nDeprecationWarning # \u88ab\u5f03\u7528\u7279\u5f81\u7684\u8b66\u544a\nRuntimeWarning # \u53ef\u7591\u7684\u8fd0\u884c\u65f6\u884c\u4e3a\u8b66\u544a\nSyntaxWarning # \u53ef\u7591\u7684\u8bed\u6cd5\u884c\u4e3a\u8b66\u544a\nUserWarning # \u7528\u6237\u4ee3\u7801\u751f\u6210\u7684\u8b66\u544a\nFutureWarning # \u4f7f\u7528\u65b0\u7684\u8bed\u6cd5\u7279\u5f81\u7684\u8b66\u544a\nImportWarning # \u5bfc\u5165\u5305\u8b66\u544a\nUnicodeWarning\nByteWarning\n<\/code><\/pre>\n<hr>\n<h1 id=\"built-in-typesclass\">built-in Types\/Class<\/h1>\n<p>\u4e0b\u9762\u662f\u6570\u636e\u7c7b\u578b\uff1a<\/p>\n<h2 id=\"int\">int<\/h2>\n<pre><code>int(x=0)\nint(x, base=10)\n<\/code><\/pre>\n<p>\u5185\u7f6e\u65b9\u6cd5:<\/p>\n<pre><code>bit_length() # \u4e00\u4e2aint\u7c7b\u578b\u7684\u4e8c\u8fdb\u5236\u5f62\u5f0f\u7684\u4f4d\u6570\uff0e\nconjugate()\n<\/code><\/pre>\n<p>\u5185\u7f6e\u6570\u636e\u63cf\u8ff0\u7b26\uff1a<\/p>\n<pre><code>denominator\nnumerator\nimag\nreal\n<\/code><\/pre>\n<h2 id=\"boolint\">bool(int)<\/h2>\n<pre><code>bool(x)\n<\/code><\/pre>\n<p>\u5185\u7f6e\u7c7b\u7c7b\u578bint\u7684\u5185\u7f6e\u65b9\u6cd5\u548c\u6570\u636e\u63cf\u8ff0\u7b26\u90fd\u662f\u7ee7\u627f\u81ea\u57fa\u7c7bint.<\/p>\n<h2 id=\"float\">float<\/h2>\n<pre><code>float(x)\nfloat('-inf') # \u8d1f\u65e0\u7a77\u5927\nfloat('inf') # \u6b63\u65e0\u7a77\u5927\n<\/code><\/pre>\n<p>\u5185\u7f6e\u65b9\u6cd5:<\/p>\n<pre><code>as_integer_ratio() # \u8fd4\u56de\u4e00\u4e2a\u6574\u6570\u5bf9\uff0c\u76f8\u9664\u7684\u7ed3\u679c\u662f\u8be5\u6d6e\u70b9\u6570\nconjugate()\nfromhex(string) # \u5c06\u5341\u516d\u8fdb\u5236\u7684\u5b57\u7b26\u8f6c\u6362\u6210\u6d6e\u70b9\u578b\n# float.fromhex('-0x1p-1074')\nhex() # \u5c06\u6d6e\u70b9\u6570\u8f6c\u6362\u6210\u5341\u516d\u8fdb\u5236\u5f62\u5f0f\nis_integer() # \u5982\u679c\u6d6e\u70b9\u6570\u662f\u6574\u6570\uff0c\u8fd4\u56detrue\n<\/code><\/pre>\n<p>\u5185\u7f6e\u6570\u636e\u63cf\u8ff0\u7b26\uff1a<\/p>\n<pre><code>imag\nreal\n<\/code><\/pre>\n<h2 id=\"complex\">complex<\/h2>\n<pre><code>complex(real[, imag])\n<\/code><\/pre>\n<p>\u5185\u7f6e\u65b9\u6cd5:<\/p>\n<pre><code>conjugate() # \u8fd4\u56de\u4e00\u4e2a\u590d\u6570\u7684\u5de5\u8edb\u590d\u6570\n<\/code><\/pre>\n<p>\u5185\u7f6e\u6570\u636e\u63cf\u8ff0\u7b26\uff1a<\/p>\n<pre><code>imag \u590d\u6570\u7684\u865a\u90e8\nreal \u590d\u6570\u7684\u5b9e\u90e8\n<\/code><\/pre>\n<h2 id=\"str\">str<\/h2>\n<p>\u5b57\u7b26\u4e32\u662f\u4e0d\u53ef\u53d8\u7c7b\u578b, \u662f\u6807\u91cf\uff0c\u662f\u5e8f\u5217\uff0e<\/p>\n<pre><code>str(object='') # \u628a\u4e00\u4e2a\u5bf9\u8c61\u8f6c\u6362\u6210\u5b57\u7b26\u4e32\uff0e\u6216\u8005\u8fd4\u56de\u4e00\u4e2a\u5bf9\u8c61\u7684\u53ef\u8bfb\u6027\u597d\u7684\u5b57\u7b26\u4e32\u8868\u793a\uff0c\u65e0\u6cd5\u7528\u8bedeval()\u6c42\u503c\uff0e\u7ed9\u7528\u6237\u770b\u7684\u3002\n<\/code><\/pre>\n<p>\u5185\u7f6e\u65b9\u6cd5\uff1a<\/p>\n<pre><code>capitalize() # \u5b57\u7b26\u4e32\u9996\u5b57\u6bcd\u5927\u5199, \u8fd4\u56de\u65b0\u7684\u5b57\u7b26\u4e32\ntitle() # \u6240\u6709\u5355\u8bcd\u9996\u5b57\u6bcd\u5927\u5199\uff0c\u8fd4\u56de\u65b0\u7684\u5b57\u7b26\u4e32\nlower() # \u6240\u6709\u5b57\u7b26\u5c0f\u5199\uff0c\u8fd4\u56de\u65b0\u7684\u5b57\u7b26\u4e32\nupper() # \u6240\u6709\u5b57\u7b26\u5927\u5199\uff0c\u8fd4\u56de\u65b0\u7684\u5b57\u7b26\u4e32\nswapcase() # \u5927\u5199\u5b57\u7b26\u8f6c\u6362\u6210\u5c0f\u5199\uff0c\u5c0f\u5199\u8f6c\u5316\u6210\u5927\u5199\ntranslate(table [,deletechars]) #\njoin(iterable) # \u7528\u5b57\u7b26\u4e32\u5206\u5272iterable,\u8fd4\u56de\u65b0\u7684\u5b57\u7b26\u4e32\nreplace(old, new[, count]) # \u7528new\u66ff\u6362\u5b57\u7b26\u4e32\u4e2d\u7684\u524dcount\u4e2aold, \u8fd4\u56de\u66ff\u6362\u540e\u7684\u5b57\u7b26\u4e32\nexpandtabs([tabsize]) # \u628a\u5b57\u7b26\u4e32\u4e2d\u7684tab\u952e\u66ff\u6362\u4e3atabsize\u6307\u5b9a\u7684\u5bbd\u5ea6\u7684\u65b0tab\uff0c\u9ed8\u8ba4\u662f8,\u7136\u540e\u8fd4\u56de\u65b0\u7684\u5b57\u7b26\u4e32\nformat(*args, **kwargs) # \u8fd4\u56de\u683c\u5f0f\u5316\u540e\u7684\u5b57\u7b26\u4e32\nlstrip([chars]) # \u5982\u679c\u5b57\u7b26\u4e32\u4ee5chars\u5f00\u5934,\u5c31\u5220\u9664\u5f00\u5934chars\uff0c\u7136\u540e\u8fd4\u56de\u65b0\u7684\u5b57\u7b26\u4e32, chars\u9ed8\u8ba4\u662f\u7a7a\u683c\uff0e\nstrip([chars]) # \u5220\u9664\u5f00\u5934\u548c\u7ed3\u5c3e\u7684chars,\u5982\u679c\u6709\u7684\u8bdd\uff0c\u7136\u540e\u8fd4\u56de\u65b0\u7684\u5b57\u7b26\u4e32\uff0cchars\u9ed8\u8ba4\u662f\u7a7a\u683c\uff0e\nrstrip([chars]) # \u5982\u679c\u5b57\u7b26\u4e32\u4ee5chars\u7ed3\u5c3e\uff0c\u5c31\u5220\u9664\u7ed3\u5c3e\u7684chars,\u7136\u540e\u8fd4\u56de\u65b0\u7684\u5b57\u7b26\u4e32\uff0cchars\u9ed8\u8ba4\u662f\u7a7a\u683c\uff0e\ncenter(width[, fillchar]) # \u4ee5\u5b57\u7b26\u4e32\u4e3a\u4e2d\u5fc3\u586b\u5145\u5b57\u7b26\u4e32\uff0c\u9ed8\u8ba4\u7528\u7a7a\u683c\u586b\u5145,\u8fd4\u56de\u586b\u5145\u540e\u7684\u5b57\u7b26\u4e32\nzfill(width) # \u75280\u586b\u5145\u5b57\u7b26\u4e32\u7684\u5de6\u8fb9\uff0c\u76f4\u5230width\u957f\u5ea6\uff0c\u8fd4\u56de\u65b0\u7684\u5b57\u7b26\u4e32\nljust(width[, fillchar]) # \u5b57\u7b26\u4e32\u5de6\u5bf9\u9f50\uff0c\u53f3\u8fb9\u586b\u5145fillchar,\u9ed8\u8ba4\u7a7a\u683c\uff0c\u76f4\u5230\u957f\u5ea6\u4e3awidth,\u8fd4\u56de\u65b0\u7684\u5b57\u7b26\u4e32\nrjust(width[, fillchar]) # \u5b57\u7b26\u4e32\u53f3\u5bf9\u9f50\uff0c\u5de6\u8fb9\u586b\u5145fillchar\uff0c\u9ed8\u8ba4\u7a7a\u683c\uff0c\u76f4\u5230\u957f\u5ea6\u4e3awidth,\u8fd4\u56de\u65b0\u7684\u5b57\u7b26\u4e32\ncount(sub[, start[, end]]) # \u8fd4\u56desub\u5b57\u7b26\u4e32\u5728str[start:end]\u4e2d\u51fa\u73b0\u7684\u6b21\u6570\n# \u53c2\u8003codecs\u6a21\u5757\u7684decode\/encode.\ndecode([encoding[,errors]]) # \u89e3\u7801\nencode([encoding[,errors]]) # \u7f16\u7801\nstartswith(prefix[, start[, end]]) # \u5982\u679cstr[start:end]\u4ee5prefix\u5f00\u5934\uff0c\u8fd4\u56detrue.\nendswith(suffix[, start[, end]]) # \u5982\u679cstr[start:end]\u4ee5suffix\u7ed3\u5c3e\uff0c\u8fd4\u56detrue.\nisalnum() # \u5982\u679c\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u4e14\u5143\u7d20\u90fd\u662f\u5b57\u7b26\u6216\u6570\u5b57\uff0c\u8fd4\u56deTrue,\u5426\u5219\u8fd4\u56deFalse\nisalpha() # \u5982\u679c\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u4e14\u5143\u7d20\u90fd\u662f\u5b57\u7b26\uff0c\u8fd4\u56deTrue,\u5426\u5219\u8fd4\u56deFalse\nisdigit() # \u5982\u679c\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u4e14\u5143\u7d20\u90fd\u662f\u6570\u5b57\uff0c\u8fd4\u56deTrue,\u5426\u5219\u8fd4\u56deFalse\nisspace() # \u5982\u679c\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u4e14\u6240\u6709\u5143\u7d20\u90fd\u662f\u7a7a\u683c\uff0c\u8fd4\u56deTrue,\u5426\u5219\u8fd4\u56deFalse\nistitle() # \u5982\u679c\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u4e14\u6240\u6709\u5355\u8bcd\u7684\u9996\u5b57\u6bcd\u5927\u5199\uff0c\u8fd4\u56deTrue,\u5426\u5219\u8fd4\u56deFalse\nislower() # \u5982\u679c\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u4e14\u6240\u6709\u5143\u7d20\u90fd\u662f\u5c0f\u5199\uff0c\u8fd4\u56deTrue,\u5426\u5219\u8fd4\u56deFalse\nisupper() # \u5982\u679c\u975e\u7a7a\u5b57\u7b26\u4e32\uff0c\u4e14\u6240\u6709\u5355\u8bcd\u90fd\u662f\u5927\u5199\uff0c\u8fd4\u56deTrue,\u5426\u5219\u8fd4\u56deFalse\nsplitlines(keepends=False) # \u6839\u636e\\n,\\r,\\r\\n\u6765\u62c6\u5206\u5b57\u7b26\u4e32\uff0c\u8fd4\u56de\u62c6\u5206\u540e\u7684\u5217\u8868\uff0cTrue\u8868\u793a\u4fdd\u7559\u6362\u884c\u7b26\uff0c\u9ed8\u8ba4\u662fFalse\uff0e\nsplit([sep [,maxsplit]]) # \u5c06\u5b57\u7b26\u4e32\u4ee5\u4ece\u5de6\u5230\u53f3\u7684maxsplit\u4e2aseq\u5206\u5272\uff0c\u8fd4\u56de\u5206\u5272\u540e\u7684\u5217\u8868\uff0c\u9ed8\u8ba4seq\u662f\u7a7a\u683c\uff0cmaxsplit\u662f\u6240\u6709seq\uff0e\nrsplit([sep [,maxsplit]]) # \u548csplit\u76f8\u53cd,\u4ece\u53f3\u5230\u5de6\u7684maxsplit\u4e2aseq\u5206\u5272\uff0e\npartition(sep) # \u5b57\u7b26\u4e32\u6839\u636e\u4ece\u5de6\u5f80\u53f3\u6839\u636e\u7b2c\u4e00\u4e2a\u627e\u5230\u7684seq\u5206\u5272\uff0c\u8fd4\u56de\u4e00\u4e2a(head, seq, tail), \u5982\u679c\u6ca1\u6709\u627e\u5230seq, \u8fd4\u56de(str, '', '').\nrpartition(sep) # \u5b57\u7b26\u4e32\u6839\u636e\u6700\u540e\u4e00\u4e2a\u627e\u5230\u7684seq\u5206\u5272\uff0c\u8fd4\u56de(head, seq, tail),\u5982\u679c\u6ca1\u6709\u627e\u5230seq,\u8fd4\u56de('', '', str)\nfind(sub [,start [,end]]) # \u5728str[start:end]\u4e2d\u4ece\u5de6\u5f80\u53f3\u67e5\u627esub,\u8fd4\u56de\u627e\u5230\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u6240\u5728\u7684\u4e0b\u6807,\u6ca1\u627e\u5230\u8fd4\u56de-1\nrfind(sub [,start [,end]]) # \u5728str[start:end]\u4e2d\u67e5\u627esub,\u8fd4\u56de\u6700\u540e\u4e00\u4e2asub\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u7684\u7d22\u5f15,\u6ca1\u6709\u627e\u5230\u8fd4\u56de-1\nindex(sub [,start [,end]]) # \u548cfind\u4e00\u6837\uff0c\u4f46\u662f\u6ca1\u627e\u5230\u629b\u51fa\u5f02\u5e38ValueError\uff0e\nrindex(sub [,start [,end]]) # \u548crfind\u4e00\u6837\uff0c\u4f46\u662f\u6ca1\u627e\u5230\u629b\u51faValueError\u5f02\u5e38\uff0e\n<\/code><\/pre>\n<h2 id=\"bytes\">bytes<\/h2>\n<pre><code>bytes(iterable_of_ints) -&gt; bytes\nbytes(string, encoding[, errors]) -&gt; bytes\nbytes(bytes_or_buffer) -&gt; immutable copy of bytes_or_buffer\nbytes(int) -&gt; bytes object of size given by the parameter initialized with null bytes\nbytes() -&gt; empty bytes object\n<\/code><\/pre>\n<p>\u5185\u7f6e\u65b9\u6cd5\uff1a<\/p>\n<pre><code>capitalize()\n...\n<\/code><\/pre>\n<h2 id=\"bytearray\">bytearray<\/h2>\n<p>bytearray\u8868\u793a\u53ef\u53d8\u5b57\u8282\u6570\u7ec4\u7c7b\u578b, bytearray\u662f\u53ef\u53d8\u7c7b\u578b\uff0c\u662f\u5e8f\u5217\uff08\u53ef\u8fed\u4ee3\uff09<\/p>\n<pre><code>bytearray(iterable_of_ints) -&gt; bytearray\nbytearray(string, encoding[, errors]) -&gt; bytearray\nbytearray(bytes_or_buffer) -&gt; mutable copy of bytes_or_buffer\nbytearray(int) -&gt; bytes array of size given by the parameter initialized with null bytes\nbytearray() -&gt; empty bytes array\n<\/code><\/pre>\n<p>\u5185\u7f6e\u65b9\u6cd5:<\/p>\n<pre><code>append(int)\ncapitalize()\n...\n<\/code><\/pre>\n<hr>\n<h2 id=\"tuple\">tuple<\/h2>\n<p>\u5143\u7ec4\u662f\u4e0d\u53ef\u53d8\u7c7b\u578b, \u662f\u5bb9\u5668\uff0c\u662f\u5e8f\u5217.<\/p>\n<pre><code>tuple()\ntuple(iterable) # \u628a\u53ef\u8fed\u4ee3\u5bf9\u8c61\u8f6c\u6362\u6210\u5143\u7ec4.\n<\/code><\/pre>\n<p>\u5185\u7f6e\u65b9\u6cd5\uff1a<\/p>\n<pre><code>count(value) # \u8fd4\u56de\u503c\u4e3avalue\u7684\u5143\u7d20\u5728\u5143\u7ec4\u4e2d\u51fa\u73b0\u7684\u6b21\u6570\nindex(value, [start, [stop]]) # \u8fd4\u56de\u503c\u4e3avalue\u7684\u5143\u7d20\u5728\u5143\u7ec4tuple[start:stop]\u4e2d\u7684\u7b2c\u4e00\u6b21\u51fa\u73b0\u7684\u7d22\u5f15\uff0c\u6ca1\u6709\u8be5\u5143\u7d20\u8fd4\u56deValueError.\n<\/code><\/pre>\n<h2 id=\"list\">list<\/h2>\n<p>\u5217\u8868\u662f\u53ef\u53d8\u7c7b\u578b,\u3000\u662f\u5bb9\u5668\uff0c\u662f\u5e8f\u5217.<\/p>\n<pre><code>list()\nlist(iterable) # \u628a\u53ef\u8fed\u4ee3\u7684\u5bf9\u8c61\u8f6c\u6362\u6210\u5217\u8868\uff0e\n<\/code><\/pre>\n<p>\u5185\u7f6e\u65b9\u6cd5\uff1a<\/p>\n<pre><code>count(value) # \u8fd4\u56devalue\u5728\u5217\u8868\u4e2d\u51fa\u73b0\u7684\u6b21\u6570\nindex(value, [start, [stop]]) # \u4ece\u5de6\u5f80\u53f3\u5728list[start:stop]\u4e2d\u5bfb\u627evalue,\u8fd4\u56de\u7b2c\u4e00\u4e2a\u627e\u5230\u7684\u5143\u7d20\u7684\u7d22\u5f15\uff0c\u5426\u5219\u8fd4\u56deValueError\u5f02\u5e38\uff0e\n# \u4e0b\u5217\u6539\u53d8\u5217\u8868\u7684\u503c\u7684\u65b9\u6cd5\u90fd\u6ca1\u6709\u8fd4\u56de\u503c\uff0c\u76f4\u63a5\u6539\u53d8\u539f\u5217\u8868\u7684\u503c, \u8fd4\u56deNone\u3002\nappend(object) # \u5728\u5217\u8868\u7ed3\u5c3e\u8ffd\u52a0\u5bf9\u8c61\nextend(iterable) # \u5c06\u53ef\u8fed\u4ee3\u5bf9\u8c61iterable\u7684\u5143\u7d20\u4f9d\u6b21\u8ffd\u52a0\u5230\u5217\u8868,\u76f8\u5f53\u4e8e\u5e8f\u5217\u7684+\u8fd0\u7b97\uff0e\ninsert(index, object) # \u5728list[index]\u524d\u9762\u63d2\u5165object.\npop([index]) # \u5220\u9664list[index],\u9ed8\u8ba4\u662f\u6700\u540e\u4e00\u4e2a\u5143\u7d20\uff0c\u5982\u679c\u5217\u8868\u4e3a\u7a7a\u6216\u7d22\u5f15\u8d8a\u754c\uff0c\u629b\u51faIndexError\u5f02\u5e38\uff0e\nremove(value) # \u5220\u9664\u7b2c\u4e00\u4e2a\u51fa\u73b0\u7684value\uff0e\nreverse() # \u7ffb\u8f6c\u5217\u8868, \u8fd4\u56deNone\nsort(cmp=None, key=None, reverse=False) # \u9ed8\u8ba4\u5bf9\u5217\u8868\u4e2d\u7684\u5143\u7d20\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\uff0creverse=True,\u5219\u4ece\u5927\u5230\u5c0f\uff0e\n<\/code><\/pre>\n<h2 id=\"dict\">dict<\/h2>\n<p>\u5b57\u5178\u662f\u53ef\u53d8\u7c7b\u578b, \u662f\u5bb9\u5668\uff0c\u662f\u6620\u5c04\u7c7b\u578b\uff08mapping), \u5b57\u5178\u53ef\u4ee5\u8fed\u4ee3\u952e\uff0e\u5b57\u5178\u662f\u65e0\u5e8f\u7684\uff0e<\/p>\n<pre><code>dict()\ndict(mapping) # dict(one=1, two=2)\ndict(iterable) # dict([(1, 'one'), (2, 'two')]), dict([[1,1], [2,2]]), dict(([1,1], [2, 2])), dict(((1,1), (2,2))),\ndict(**kwargs) # dict({1:&quot;one&quot;, 2:&quot;two&quot;})\nin, not in\n<\/code><\/pre>\n<p>\u5185\u7f6e\u65b9\u6cd5\uff1a<\/p>\n<pre><code>copy() # \u8fd4\u56de\u5b57\u5178\u7684\u4e00\u4e2a\u6d45\u62f7\u8d1d\nclear() # \u6e05\u7a7a\u5b57\u5178\u6240\u6709\u5143\u7d20\nfromkeys(S[,v]) # \u8fd4\u56de\u4ee5S\u7684\u5143\u7d20\u4e3a\u952e\uff0cv\u4e3a\u503c\u7684\u65b0\u5b57\u5178\uff0cv\u9ed8\u8ba4\u4e3aNone.\nget(k[,d]) # \u5982\u679c\u952ek\u5728\u5b57\u5178\u91cc\u9762\uff0c\u8fd4\u56dedict[k], \u5426\u5219\u8fd4\u56ded, d\u9ed8\u8ba4\u4e3aNone.\npop(k[,d]) # \u4ece\u5b57\u5178\u4e2d\u5220\u9664\u952ek\u7684\u952e\u503c\u5bf9\uff0c\u8fd4\u56dedict[k], \u5982\u679c\u4e0d\u5b58\u5728\u8fd4\u56ded,\u5982\u679c\u6ca1\u6709\u6307\u5b9ad,\u629b\u51faKeyError\u5f02\u5e38\uff0e\npopitem() # \u4ece\u5b57\u5178\u4e2d\u5220\u9664\u968f\u673a\u7684\u952e\u503c\u5bf9\uff0c\u8fd4\u56de\u8be5\u952e\u503c\u5bf9\u7ec4\u6210\u7684\u5143\u7ec4\uff0c\u5982\u679c\u5b57\u5178\u4e3a\u7a7a\uff0c\u629b\u51faKeyError\u5f02\u5e38\uff0e\nsetdefault(k[,d]) # \u5982\u679c\u952ek\u5728\u5b57\u5178\u4e2d\u5b58\u5728\uff0c\u7b49\u6548\u4e8eget(k[,d]), \u5426\u5219\u5c31\u63d2\u5165D[k]=d\u952e\u503c\u5bf9\uff0e\nupdate([E, ]**F) # \u5411\u5b57\u5178\u63d2\u5165\u6307\u5b9a\u7684\u9879\u76ee(\u5b57\u5178\u6216\u53ef\u8fed\u4ee3\u5bf9\u8c61).\nkeys() # \u8fd4\u56de\u5b57\u5178\u7684\u952e\u7ec4\u6210\u7684\u5217\u8868\uff0e\nvalues() # \u8fd4\u56de\u5b57\u5178\u7684\u503c\u7ec4\u6210\u7684\u5217\u8868\uff0e\nitems() # \u8fd4\u56de\u4e00\u4e2a\u5217\u8868\uff0c\u6bcf\u4e2a\u5143\u7d20\u662f\u5b57\u5178\u7684\u952e\u548c\u503c\u7ec4\u6210\u7684\u5143\u7ec4\uff0e\niteritems() # \u8fd4\u56de\u5b57\u5178\u7684\u952e\u503c\u5bf9\u7ec4\u6210\u7684\u8fed\u4ee3\u5668\uff0cnext()\u6bcf\u6b21\u8fd4\u56de\u4e00\u4e2a\u4e00\u5bf9\u952e\u503c\u7ec4\u6210\u7684\u5143\u7ec4\uff0e\niterkeys() # \u8fd4\u56de\u5b57\u5178\u7684\u952e\u7ec4\u6210\u7684\u8fed\u4ee3\u5668\uff0e\nitervalues() # \u8fd4\u56de\u5b57\u5178\u7684\u503c\u7ec4\u6210\u7684\u8fed\u4ee3\u5668\uff0e\nviewitems() # \u8fd4\u56de\u952e\u548c\u503c\u7ec4\u6210\u7684\u53ef\u8fed\u4ee3\u5bf9\u8c61\nviewkeys()\u3000# \u8fd4\u56de\u952e\u7ec4\u6210\u7684\u53ef\u8fed\u4ee3\u5bf9\u8c61\nviewvalues() # \u8fd4\u56de\u503c\u7ec4\u6210\u7684\u53ef\u8fed\u4ee3\u5bf9\u8c61\n<\/code><\/pre>\n<h2 id=\"frozenset\">frozenset<\/h2>\n<p>\u4e0d\u53ef\u53d8\u96c6\u5408frozenset\u662f\u4e0d\u53ef\u53d8\u7c7b\u578b<\/p>\n<pre><code>frozenset()\nfrozenset(iterable)\n<\/code><\/pre>\n<p>\u4e0d\u53ef\u53d8\u96c6\u5408\u548c\u53ef\u53d8\u96c6\u5408\u5171\u540c\u7684\u5185\u7f6e\u65b9\u6cd5\uff1a<\/p>\n<pre><code>copy() # \u8fd4\u56de\u96c6\u5408\u7684\u4e00\u4e2a\u6d45\u62f7\u8d1d\nisdisjoint() # \u4e24\u4e2a\u96c6\u5408\u4ea4\u96c6\u4e3a\u7a7a\uff0c\u8fd4\u56de\u4e3aTrue.\na.issubset(b) # a\u662fb\u7684\u975e\u4e25\u683c\u5b50\u96c6\uff0c\u3000a &lt;= b, \u8fd4\u56deTrue\na.issuperset(b) # a\u662fb\u7684\u975e\u4e25\u683c\u8d85\u96c6, a &gt;= b, \u8fd4\u56deTrue\nunion() # \u8054\u5408\/\u5e76\u96c6\uff0cOR\u64cd\u4f5c\uff0c\u7b49\u6548\u4e8e|\u8fd0\u7b97\u7b26\nintersection([others, ...]) # \u4ea4\u96c6\uff0c\u3000AND\u64cd\u4f5c\uff0c\u3000\u7b49\u6548\u4e8e&amp;\u8fd0\u7b97\u7b26\ndifference([others, ...]) # \u5dee\u8865\u6216\u76f8\u5bf9\u8865\u5145\u96c6\uff0c\u7b49\u6548\u4e8e-\u8fd0\u7b97\u7b26\nsymmetric_difference() # \u5bf9\u79f0\u5dee\u5206\u6216\u5f02\u6216\uff0c\u7b49\u6548\u4e8e^\u8fd0\u7b97\u7b26\n<\/code><\/pre>\n<h2 id=\"set\">set<\/h2>\n<p>\u53ef\u53d8\u96c6\u5408set\u662f\u53ef\u53d8\u7c7b\u578b<\/p>\n<pre><code>set()\nset(iterable)\n<\/code><\/pre>\n<p>set\u9664\u4e86\u6709frozenset\u7684\u6240\u6709\u65b9\u6cd5\u8fd8\u6709\u81ea\u5df1\u7279\u6709\u7684\u5185\u7f6e\u65b9\u6cd5\uff1a<\/p>\n<pre><code>clear() # \u6e05\u7a7a\u96c6\u5408\u6240\u6709\u5143\u7d20\npop() # \u5220\u9664\u5e76\u8fd4\u56de\u4efb\u610f\u4e00\u4e2a\u96c6\u5408\u5143\u7d20\uff0c\u96c6\u5408\u4e3a\u7a7a\u629b\u51faKeyError.\nadd(obj) # \u5f80\u96c6\u5408\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u4e0d\u5b58\u5728\u7684\u5143\u7d20\nremove(obj) # \u5220\u9664\u96c6\u5408\u4e2d\u7684\u5b58\u5728\u7684\u6307\u5b9a\u7684\u6570\u5b57\u5143\u7d20, \u975e\u6570\u5b57\u629b\u51faKeyError.\ns.discard(obj) # \u5982\u679cobj\u662f\u96c6\u5408s\u4e2d\u7684\u5143\u7d20\uff0c\u4eces\u4e2d\u5220\u9664obj.\nupdate() # \u7b49\u6548\u4e8e|=\u8fd0\u7b97\u7b26\nintersection_update() # \u7b49\u6548\u4e8e&amp;=\u8fd0\u7b97\u7b26\ndifference_update() # \u7b49\u6548\u4e8e-=\u8fd0\u7b97\u6cd5\nsymmetric_difference_update() # \u7b49\u6548\u4e8e^=\u8fd0\u7b97\u7b26\n<\/code><\/pre>\n<h2 id=\"slice\">slice<\/h2>\n<pre><code>slice(stop)\nslice(start, stop[, step])\n<\/code><\/pre>\n<p>methods:<\/p>\n<pre><code>indices(len) -&gt; (start, stop, stride)\n<\/code><\/pre>\n<h2 id=\"range\">range<\/h2>\n<pre><code>range(stop) # \u8fd4\u56de[0, 1, stop-1]\u7684\u5217\u8868\nrange(start, stop[, step]) # \u8fd4\u56de[start, start+n*step... ], n&gt;=1,start+n*step&lt;stop.\n<\/code><\/pre>\n<p>Methods:<\/p>\n<pre><code>count(self, object, \/)\nindex(self, object, \/)\n<\/code><\/pre>\n<h2 id=\"memoryview\">memoryview<\/h2>\n<pre><code>memoryview(object)\n<\/code><\/pre>\n<p>\u5185\u7f6e\u65b9\u6cd5:<\/p>\n<pre><code>cast(self, \/, format, shape=&lt;unrepresentable&gt;)\nhex(self, \/, sep=&lt;unrepresentable&gt;, bytes_per_sep=1)\nrelease(self, \/)\ntobytes(self, \/, order='C')\n<\/code><\/pre>\n<p>\u5185\u7f6e\u6570\u636e\u63cf\u8ff0\u7b26\uff1a<\/p>\n<pre><code>format\nitemsize\n...\n<\/code><\/pre>\n<hr>\n<p>\u8fed\u4ee3\u5668\/\u751f\u6210\u5668\u7c7b<\/p>\n<h2 id=\"enumerate\">enumerate<\/h2>\n<p>\u8fd4\u56de\u4e00\u4e2a\u8fed\u4ee3\u5668\uff0c\u8fed\u4ee3\u5668\u7684\u5143\u7d20\u662fiterable\u4e2d\u7684\u5143\u7d20\u548c\u7d22\u5f15\u7ec4\u6210\u7684\u5143\u7ec4\u3002<\/p>\n<pre><code>enumerate(iterable, start=0)\nennumerate([&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]) # \u8fd4\u56de\u8fed\u4ee3\u5668\uff0c\u5143\u7d20\u662f(0, &quot;a&quot;), (1, &quot;b&quot;), (2, &quot;c&quot;)\n<\/code><\/pre>\n<h2 id=\"reversed\">reversed<\/h2>\n<p>\u8fd4\u56de\u4e00\u4e2a\u8fed\u4ee3\u5668\uff0c\u8fed\u4ee3\u5668\u7684\u5143\u7d20\u662fiterable\u4e2d\u7684\u5143\u7d20\u4ece\u540e\u5f80\u524d\u7684\u987a\u5e8f\u3002<\/p>\n<pre><code>reversed(iterable)\nreversed(&quot;abc&quot;) # \u8fd4\u56de\u8fed\u4ee3\u5668\uff0c\u5143\u7d20\u662f&quot;c&quot;, &quot;b&quot;, &quot;a&quot;\n<\/code><\/pre>\n<h2 id=\"map\">map<\/h2>\n<p>\u6309\u987a\u5e8f\u4f9d\u6b21\u6267\u884c\u51fd\u6570function(iterable)\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\uff0c\u8fd4\u56de\u4e00\u4e2a\u8fed\u4ee3\u5668\u3002<\/p>\n<pre><code>map(function, iterable, ...)\nmap(lambda x: x**2, [1, 2, 3]) # \u8fd4\u56de\u8fed\u4ee3\u5668\uff0c\u5143\u7d20\u662f1, 4, 9\n<\/code><\/pre>\n<h2 id=\"filter\">filter<\/h2>\n<p>\u8fd4\u56de\u4e00\u4e2a\u8fed\u4ee3\u5668\uff0c\u8fed\u4ee3\u5668\u7684\u5143\u7d20\u662fiterable\u4e2d\u6ee1\u8db3function(x)\u4e3aTrue\u7684\u5143\u7d20\u3002<\/p>\n<pre><code>filter(function, iterable)\nfilter(lambda x: x &gt; 0, [-1, 0, 1, 2]) # \u8fd4\u56de\u8fed\u4ee3\u5668\uff0c\u5143\u7d20\u662f1, 2\n<\/code><\/pre>\n<h2 id=\"zip\">zip<\/h2>\n<p>\u8fd4\u56de\u4e00\u4e2a\u8fed\u4ee3\u5668\uff0c\u8fed\u4ee3\u5668\u7684\u5143\u7d20\u662fiterable\u4e2d\u6bcf\u4e2a\u5143\u7d20\u7684\u5143\u7ec4\u3002<\/p>\n<pre><code>zip(iterable1, iterable2, ...)\nzip([1, 2, 3], [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]) # \u8fd4\u56de\u8fed\u4ee3\u5668\uff0c\u5143\u7d20\u662f(1, &quot;a&quot;), (2, &quot;b&quot;), (3, &quot;c&quot;)\n<\/code><\/pre>\n<hr>\n<h2 id=\"classmethod\">classmethod<\/h2>\n<h2 id=\"staticmethod\">staticmethod<\/h2>\n<h2 id=\"property\">property<\/h2>\n<hr>\n<h2 id=\"object\">object<\/h2>\n<p>object\u7c7b\u662f\u6240\u6709\u7c7b\u7684\u57fa\u7c7b<\/p>\n<h2 id=\"type\">type<\/h2>\n<p>\u6240\u6709\u7c7b\u7684\u7c7b\u578b\u6216\u5143\u7c7b<\/p>\n<p>type\u662f\u7528\u6765\u521b\u5efa\u7c7b\u7684\u7c7b\uff0c\u53ef\u4ee5\u52a8\u6001\u521b\u5efa\u7c7b\u3002<\/p>\n<pre><code>class type(object)\ntype(object) -&gt; the object's type\ntype(name, bases, dict, **kwds) -&gt; a new type\n<\/code><\/pre>\n<hr>"},{"title":"PSL_Concurrency","link":"https:\/\/canuxcheng.com\/post\/psl_concurrency\/","pubDate":"Mon, 15 Aug 2016 11:04:12 +0000","guid":"https:\/\/canuxcheng.com\/post\/psl_concurrency\/","description":"<h1 id=\"concurrent-execution\">Concurrent Execution<\/h1>\n<p>\u8fdb\u7a0b\uff1a\u6bcf\u4e2a\u8fdb\u7a0b\u90fd\u6709\u81ea\u5df1\u7684\u5730\u5740\u7a7a\u95f4\uff0c\u5185\u5b58\uff0c\u6570\u636e\u6808\u4ee5\u53ca\u5176\u5b83\u8bb0\u5f55\u5176\u8fd0\u884c\u8f68\u8ff9\u7684\u8f85\u52a9\u6570\u636e\uff0c\u8fdb\u7a0b\u95f4\u4e0d\u5171\u4eab\u5168\u5c40\u53d8\u91cf\u3002<\/p>\n<p>\u7ebf\u7a0b\uff1a\u7ebf\u7a0b\uff08\u6709\u65f6\u88ab\u79f0\u4e3a\u8f7b\u91cf\u7ea7\u8fdb\u7a0b\uff09\u8ddf\u8fdb\u7a0b\u6709\u4e9b\u76f8\u4f3c\uff0c\u4e0d\u540c\u7684\u662f\uff0c\u6240\u6709\u7684\u7ebf\u7a0b\u8fd0\u884c\u5728\u540c\u4e00\u4e2a\u8fdb\u7a0b\u4e2d\uff0c\u5171\u4eab\u76f8\u540c\u7684\u8fd0\u884c\u73af\u5883\uff0c\u540c\u4e00\u4e2a\u8fdb\u7a0b\u7684\u7ebf\u7a0b\u4e4b\u95f4\u5171\u4eab\u5168\u5c40\u53d8\u91cf\u3002<\/p>\n<p>IPC: \u8fdb\u7a0b\/\u7ebf\u7a0b\u4e4b\u95f4\u4ea4\u6362\u4fe1\u606f\u53eb\u8fdb\u7a0b\u95f4\u901a\u4fe1\uff0e<\/p>\n<p>python\u7684\u591a\u7ebf\u7a0b\u7531\u4e8eGIL\u53ea\u6709\u5e76\u53d1\u6ca1\u6709\u5e76\u884c\uff0c\u65e0\u8bba\u6709\u591a\u5c11cpu,\u4e00\u6b21\u53ea\u80fd\u6709\u4e00\u4e2apython\u89e3\u91ca\u5668(\u7ebf\u7a0b)\u6267\u884c.\u4e00\u6b21\u53ea\u80fd\u6267\u884c\u4e00\u4e2a\u7ebf\u7a0b.\u4e00\u6b21\u53ea\u80fd\u7528\u5230\u4e00\u4e2a\u903b\u8f91cpu.<\/p>\n<p>IO\u5bc6\u96c6\u578b\u4efb\u52a1\u6d88\u8017IO,\u4f46\u662f\u4e0d\u6d88\u8017CPU,cpu\u5207\u6362\u6d88\u8017\u5c11,\u9002\u5408\u7528\u591a\u7ebf\u7a0b.\uff08\u7ebf\u7a0b\u7b49\u5f85IO\u4f1a\u91ca\u653eGIL\uff09\u3002<\/p>\n<p>python\u7684\u591a\u8fdb\u7a0b\u53ef\u4ee5\u5e76\u884c,\u6bcf\u4e2a\u8fdb\u7a0b\u542f\u52a8\u4e00\u4e2a\u89e3\u91ca\u5668\u8fdb\u7a0b.<\/p>\n<p>\u591a\u8fdb\u7a0b\u5f00\u9500\u5927\uff0c\u6d88\u8017\u5185\u5b58.<\/p>\n<p>\u8ba1\u7b97\u5bc6\u96c6\u578b\u6d88\u8017cpu,\u4efb\u52a1\u4e2a\u6570\u4e0d\u8d85\u8fc7cpu\u4e2a\u6570\uff0e\u9002\u5408\u7528\u591a\u8fdb\u7a0b\uff0c\u628a\u6bcf\u4e2acpu\u8dd1\u6ee1. \u5982\u679c\u7528\u591a\u7ebf\u7a0b\u662f\u65e0\u6548\u7684\uff0c\u4f1a\u4e32\u884c\u6267\u884c\uff0c\u6d6a\u8d39\u591a\u6838\u6027\u80fd\u3002<\/p>\n<p>io\u5bc6\u96c6: \u7528\u5f02\u6b65asyncio(\u534f\u7a0b)\u6216\u8005\u591a\u7ebf\u7a0b, \u7f51\u7edc\u8bf7\u6c42\uff0c\u6587\u4ef6\u8bfb\u5199\uff0c\u6570\u636e\u5e93\u67e5\u8be2\u3002\n\u8ba1\u7b97\u5bc6\u96c6: \u7528\u591a\u8fdb\u7a0b<\/p>\n<p>\u7ed5\u8fc7GIL\u7684\u65b9\u5f0f\u6709\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528C\/C++\u7f16\u5199\u6269\u5c55\u6a21\u5757(numpy, pandas\u7b49)<\/li>\n<li>\u4f7f\u7528Cython\u7f16\u8bd1\u5668<\/li>\n<li>\u4f7f\u7528\u591a\u8fdb\u7a0b (multiprocessing)<\/li>\n<\/ul>\n<h2 id=\"multiprocessing\">multiprocessing<\/h2>\n<p>\u591a\u8fdb\u7a0b\u5c31\u662f\u540c\u65f6\u6267\u884c\u591a\u4e2a\u4efb\u52a1.<\/p>\n<p>python\u53ef\u4ee5\u901a\u8fc7\u591a\u8fdb\u7a0b\u53d6\u4ee3\u591a\u7ebf\u7a0b\uff0c\u4ece\u800c\u7ed5\u8fc7\u591a\u7ebf\u7a0b\u7684GIL.<\/p>\n<p>python\u662f\u9759\u6001\u8bed\u8a00\uff0c<\/p>\n<pre><code>import multiprocessing\n<\/code><\/pre>\n<p>classes:<\/p>\n<pre><code># multiprocessing.Process\nProcess(group=None, target=None, name=None, args=(), kwargs=None, *, daemon=None)\n# methods:\nrun(self) # \u5b50\u7c7b\u91cd\u5199\u7528\u6765\u5b9a\u4e49\u8fdb\u7a0b\u7684\u529f\u80fd\u7684\u51fd\u6570, \u901a\u5e38\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u6765\u521b\u5efa\u8fdb\u7a0b\nstart(self) # \u542f\u52a8\u4e00\u4e2a\u8fdb\u7a0b\njoin(self, timeout=None) # \u7236\u8fdb\u7a0b\u963b\u585e\u7b49\u5f85\u5b50\u8fdb\u7a0b\u7ed3\u675f\uff0c\u540e\u9762\u7684\u4ee3\u7801\u4e0d\u4f1a\u6267\u884c\uff0c\u76f4\u5230\u5b50\u8fdb\u7a0b\u7ed3\u675f\u3002\nis_alive() # \u8fd4\u56de\u8fdb\u7a0b\u662f\u5426\u8fd8\u5728\u8fd0\u884c\u7684boolean\nexit(self) # \u9000\u51fa\u8fdb\u7a0b\nterminate(self) # \u7ec8\u6b62\u8fdb\u7a0b\nexitcode() # \u8fd4\u56de\u8fdb\u7a0b\u7684\u9000\u51fa\u7801\nname() # \u8fd4\u56de\u8fdb\u7a0b\u7684\u540d\u5b57\npid() # \u8fd4\u56de\u8fdb\u7a0b\u7684pid\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>active_children()\nallow_connection_pickling()\ncpu_count() # \u83b7\u53d6cpu\u4e2a\u6570\ncurrent_process()\nfreeze_support()\nget_logger()\nlog_to_stderr(level=None)\n<\/code><\/pre>\n<p>Pool:<\/p>\n<pre><code>Pool(processes=None, initializer=None, initargs=(), maxtasksperchild=None) # \u8fd4\u56de\u4e00\u4e2a\u8fdb\u7a0b\u6c60\u5bf9\u8c61, processes\u9ed8\u8ba4\u662fcpu\u4e2a\u6570.\nwith Pool(processes=4) as pool:\npool.map(func, iterable) # \u963b\u585e\uff0c\u8fd4\u56de\u6240\u6709\u7ed3\u679c\n# func\u53ea\u80fd\u662f\u9876\u5c42\u51fd\u6570\uff0c\u4e0d\u80fd\u662f\u65b9\u6cd5\u548c\u5185\u90e8\u51fd\u6570.\n# \u8fdb\u7a0b\u6c60\uff0c\u53ef\u4ee5\u63a7\u5236\u8fdb\u7a0b\u6570\u91cf,processes \u9ed8\u8ba4\u662fcpu\u4e2a\u6570(cpu_count())\n# \u975e\u963b\u585e\uff0c\u7ef4\u6301\u8fdb\u7a0b\u603b\u6570\uff0c\u5f53\u4e00\u4e2a\u8fdb\u7a0b\u7ed3\u675f\u4f1a\u6dfb\u52a0\u65b0\u7684\u8fdb\u7a0b\u5230pool,\u4e3b\u8fdb\u7a0b\u4e0d\u963b\u585e\uff0c\u540c\u6b65\u8fd0\u884c\uff0cpool\u4e2d\u7684\u8fdb\u7a0b\u5e76\u53d1\u6267\u884c.\napply_async(func, args=(), kwargs={}, callback=None) # \u975e\u963b\u585e,\nmap_async(func, iterable, chunksize=None, callback=None) # \u975e\u963b\u585e\n# \u963b\u585e\uff0c\u7ef4\u6301\u8fdb\u7a0b\u603b\u6570\uff0c\u5f53\u4e00\u4e2a\u8fdb\u7a0b\u7ed3\u675f\u4f1a\u6dfb\u52a0\u65b0\u7684\u8fdb\u7a0b\u5230pool\uff0c\u4e3b\u8fdb\u7a0b\u963b\u585e\uff0cpool\u4e2d\u7684\u8fdb\u7a0b\u4e00\u4e2a\u4e00\u4e2a\u6267\u884c.\napply(func, args=(), kwargs={}) # \u963b\u585e\uff0c\u6267\u884c\u4e00\u6b21\u51fd\u6570\nmap(func, itreable, chunksize=None) # \u963b\u585e, \u8fd4\u56de\u6240\u6709\u7ed3\u679c\nterminate() # \u7ec8\u6b62\u6240\u6709\u4efb\u52a1\nclose() # \u5173\u95edpool,\u4e0d\u63a5\u53d7\u65b0\u4efb\u52a1\njoin() # \u7b49\u5f85pool\u4e2d\u5b50\u8fdb\u7a0b\u7ed3\u675f\uff0c\u8981\u5728close\/terminate\u4e4b\u540e\u8c03\u7528.\n<\/code><\/pre>\n<p>IPC: \u7ba1\u9053<\/p>\n<pre><code>Pipe(duplex=True) # duplex=True\u8868\u793a\u9ed8\u8ba4\u662f\u53cc\u5411pipe.\nreceiver, sender = Pipe()\nsender.send(obj)\nreceiver.recv()\nclose()\n<\/code><\/pre>\n<p>IPC: \u6d88\u606f\u961f\u5217<\/p>\n<pre><code># \u7528\u4e8e\u8fdb\u7a0b\u95f4\u901a\u4fe1\uff0c\u7ebf\u7a0b\u548c\u8fdb\u7a0b\u5b89\u5168\u3002\nQueue(maxsize=0) # return a queue object\nq = Queue()\nq.put(obj) # \u963b\u585e\uff0c\u653e\u5165\u4e00\u4e2a\u5bf9\u8c61\u5230\u961f\u5217\u4e2d\nq.put_nowait(obj) # \u975e\u963b\u585e\uff0c\u653e\u5165\u4e00\u4e2a\u5bf9\u8c61\u5230\u961f\u5217\u4e2d\nq.get() # \u963b\u585e\uff0c\u4ece\u961f\u5217\u4e2d\u83b7\u53d6\u4e00\u4e2a\u5bf9\u8c61\nq.get_nowait() # \u975e\u963b\u585e\uff0c\u4ece\u961f\u5217\u4e2d\u83b7\u53d6\u4e00\u4e2a\u5bf9\u8c61\nq.empty() # \u8fd4\u56de\u961f\u5217\u662f\u5426\u4e3a\u7a7a\u7684boolean\nq.full() # \u8fd4\u56de\u961f\u5217\u662f\u5426\u5df2\u6ee1\u7684boolean\nq.qsize() # \u8fd4\u56de\u961f\u5217\u7684\u5927\u5c0f\n<\/code><\/pre>\n<p>IPC: \u5171\u4eab\u5185\u5b58<\/p>\n<pre><code>Manager()\nEvent()\n# \u540c\u6b65\uff1a\u3000\u6761\u4ef6\u53d8\u91cf\nCondition(lock=None)\n# \u540c\u6b65\uff1a\u4fe1\u53f7\u91cf\nSemaphore(value=1)\n# \u540c\u6b65\uff1a\u6709\u754c\u4fe1\u53f7\u91cf\nBoundedSemaphore(value=1)\n# \u540c\u6b65\uff1a \u666e\u901a\u9501\uff0c\u4e00\u4e2a\u7ebf\u7a0b\u53ea\u80fdacquire\u4e00\u6b21\uff0c\u5426\u5219\u6b7b\u9501\u3002\nLock(*args, **kwargs) # \u8fd4\u56de\u4e00\u4e2aLock\u5bf9\u8c61, \u7528\u4e8e\u7ebf\u7a0b\u95f4\u540c\u6b65.\nwith Lock() as lock:\n......\n# \u540c\u6b65: \u91cd\u5165\u9501\uff0c\u5141\u8bb8\u540c\u4e00\u7ebf\u7a0b\u591a\u6b21\u83b7\u53d6\u9501\u548c\u91ca\u653e\u9501\u3002\nRLock(*args, **kwargs) # \u8fd4\u56de\u4e00\u4e2aRLock\u5bf9\u8c61, \u53ef\u91cd\u5165\u9501, \u5141\u8bb8\u540c\u4e00\u7ebf\u7a0b\u591a\u6b21\u83b7\u53d6\u9501.\n<\/code><\/pre>\n<hr>\n<h2 id=\"threading\">threading<\/h2>\n<p>\u591a\u7ebf\u7a0b\u5c31\u662f\u628a\u5355\u4e2a\u4efb\u52a1\u5206\u6210\u4e0d\u540c\u90e8\u5206\u8fd0\u884c.<\/p>\n<p>threading\u652f\u6301\u5b88\u62a4\u7ebf\u7a0b(\u901a\u8fc7join\u65b9\u6cd5\u5b9e\u73b0)\uff0e<\/p>\n<pre><code>import threading\n<\/code><\/pre>\n<p>classes:<\/p>\n<pre><code># threading.Thread\nThread(group=None, target=None, name=None, args=(), kwargs=None, daemon=None)\n# methods:\nappend(self, *args, **kwargs) # \u6dfb\u52a0\u7ebf\u7a0b\u5230\u7ebf\u7a0b\u7ec4\nrun(self) # \u5b50\u7c7b\u91cd\u5199\u7528\u6765\u5b9a\u4e49\u7ebf\u7a0b\u7684\u529f\u80fd\u7684\u51fd\u6570, \u901a\u5e38\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u6765\u521b\u5efa\u7ebf\u7a0b\nstart(self) # \u5f00\u59cb\u6267\u884c\u7ebf\u7a0b\njoin(self, timeout=None) # \u4e3b\u7a0b\u5e8f\u6302\u8d77\uff0c\u963b\u585e\u7b49\u5f85\u5b50\u7ebf\u7a0b\u7ed3\u675f,\u518d\u7ee7\u7eed\u8fd0\u884c\u4e3b\u7a0b\u5e8f\ngetName(self) # \u8fd4\u56de\u7ebf\u7a0b\u540d\u5b57\nsetName(self, name) # \u8bbe\u7f6e\u7ebf\u7a0b\u540d\u5b57\nis_alive(self) # \u8868\u793a\u7ebf\u7a0b\u662f\u5426\u8fd8\u5728\u8fd0\u884c\u7684boolean\nisDaemon(self) # \u8fd4\u56de\u7ebf\u7a0b\u7684daemon\u6807\u5fd7\nsetDaemon(self, daemonic) # daemonic=True \u4f7f\u7ebf\u7a0b\u5728\u540e\u53f0\u8fd0\u884c\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>active_count() # \u5f53\u524d\u6d3b\u52a8\u7684\u7ebf\u7a0b\u5bf9\u8c61\u7684\u6570\u91cf\ncurrent_thread() # \u8fd4\u56de\u5f53\u524d\u7ebf\u7a0b\u5bf9\u8c61\nenumerate() # \u8fd4\u56de\u5f53\u524d\u6d3b\u52a8\u7ebf\u7a0b\u5217\u8868\nsettrace(func) # \u4e3a\u6240\u6709\u7684\u7ebf\u7a0b\u8bbe\u7f6e\u4e00\u4e2a\u8ddf\u8e2a\u51fd\u6570\nsetprofile(func) # \u4e3a\u6240\u6709\u7ebf\u7a0b\u8bbe\u7f6e\u4e00\u4e2aprofile\u51fd\u6570\nstack_size()\n<\/code><\/pre>\n<p>\u8ba1\u65f6\u5668Timer\uff1a<\/p>\n<pre><code>Timer(*args, **kwargs)\nt = Timer(30.0, f, args=[], kwargs={})\nt.start() # \u5728\u4e00\u4e2a\u5b50\u7ebf\u7a0b\u7b49\u5f85\uff0ctimeout\u5c31\u6267\u884cf(*args, **kwaargs).\nt.cancel() # \u5982\u679c\u8fd8\u5728\u7b49\u5f85\u5c31\u53d6\u6d88\uff0e\n<\/code><\/pre>\n<p>\u4e8b\u4ef6event:<\/p>\n<pre><code>Event(*args, **kwargs)\n<\/code><\/pre>\n<p>\u6805\u680fbarrier:<\/p>\n<pre><code>Barrier(parties, *, timeout=None, action=None, reset_on_timeout=True)\n<\/code><\/pre>\n<p>\u540c\u6b65\uff1a\u3000\u6761\u4ef6\u53d8\u91cf<\/p>\n<pre><code>Condition(*args, **kwargs)\nwith Condition() as cond:\n# do something\n<\/code><\/pre>\n<p>\u540c\u6b65\uff1a\u3000\u4fe1\u53f7\u91cf<\/p>\n<pre><code>Semaphore(value=1, *args, **kwargs)\n# \u4fe1\u53f7\u91cf\uff0c\u9ed8\u8ba4value=1, \u5185\u90e8\u8ba1\u6570\u5668\u4e0d\u80fd\u5c0f\u4e8e0,\u5f53\u8ba1\u6570\u5668==0\u65f6\uff0c\u8c03\u7528acquire\u4f1a\u963b\u585e.\nwith Semaphore() as sem:\n# do something\n<\/code><\/pre>\n<p>\u540c\u6b65\uff1a\u3000\u6709\u754c\u4fe1\u53f7\u91cf<\/p>\n<pre><code>BoundedSemaphore(value=1, *args, **kwargs)\n# \u6709\u754c\u4fe1\u53f7\u91cf\uff0c\u9ed8\u8ba4value=1\uff0c\u5185\u90e8\u8ba1\u6570\u5668\u4e0d\u80fd\u5c0f\u4e8e0\uff0c\u5e76\u4e14\u4e0d\u80fd\u5927\u4e8evalue\u3002\n# \u5f53\u8ba1\u6570\u5668==0\uff0c\u8c03\u7528acquire\u4f1a\u963b\u585e\uff0c\u5f53&gt;value\u629b\u51faVAlueError\u5f02\u5e38\n# \u53ef\u7528\u6765\u63a7\u5236\u5e76\u53d1\u8fd0\u884c\u7684\u7ebf\u7a0b\u6570\u91cf\nwith BoundedSemaphore() as bs:\n# do something\n<\/code><\/pre>\n<p>\u540c\u6b65\uff1a\u3000\u9501<\/p>\n<pre><code>Lock()\n# \u4f7f\u540c\u4e00\u53d8\u91cf\u5728\u591a\u4e2a\u7ebf\u7a0b\u95f4\u540c\u6b65\nwith Lock() as lock:\n# do something\n<\/code><\/pre>\n<p>\u540c\u6b65\uff1a\u3000\u9501<\/p>\n<pre><code>RLock(*args, **kwargs)\nwith RLock() as rlock:\n# do something\n<\/code><\/pre>\n<h2 id=\"queue\">queue<\/h2>\n<p>queue\u7528\u4e8e\u7ebf\u7a0b\u95f4\u901a\u4fe1\uff0c\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\u3002<\/p>\n<pre><code>import queue\n<\/code><\/pre>\n<p>classes:<\/p>\n<pre><code># queue.Queue\nQueue(maxsize=0) # \u521b\u5efa\u4e00\u4e2a\u961f\u5217\u5bf9\u8c61\uff0cmaxsize=0\u8868\u793a\u65e0\u9650\u5236\u3002\n# methods:\nput(item, block=True, timeout=None) # \u5411\u961f\u5217\u4e2d\u6dfb\u52a0\u4e00\u4e2aitem\uff0c\u963b\u585e\u76f4\u5230\u961f\u5217\u6709\u7a7a\u95f4\u3002\nget(block=True, timeout=None) # \u4ece\u961f\u5217\u4e2d\u83b7\u53d6\u4e00\u4e2aitem\uff0c\u963b\u585e\u76f4\u5230\u961f\u5217\u6709\u6570\u636e\u3002\nqsize() # \u8fd4\u56de\u961f\u5217\u7684\u5927\u5c0f\nempty() # \u8fd4\u56de\u961f\u5217\u662f\u5426\u4e3a\u7a7a\u7684boolean\nfull() # \u8fd4\u56de\u961f\u5217\u662f\u5426\u6ee1\u7684boolean\ntask_done() # \u6807\u8bb0\u4e00\u4e2a\u4efb\u52a1\u5df2\u5b8c\u6210\uff0c\u5fc5\u987b\u5728get\u4e4b\u540e\u8c03\u7528\u3002\njoin() # \u963b\u585e\u76f4\u5230\u961f\u5217\u4e2d\u7684\u6240\u6709\u4efb\u52a1\u90fd\u5b8c\u6210\uff0c\u5fc5\u987b\u5728put\u4e4b\u540e\u8c03\u7528\u3002\n<\/code><\/pre>\n<h2 id=\"subprocess\">subprocess<\/h2>\n<p>\u5f00\u542f\u4e00\u4e2a\u5b50\u8fdb\u7a0b\u6765\u6267\u884c\u5916\u90e8\u547d\u4ee4.<\/p>\n<pre><code>import subprocess\n<\/code><\/pre>\n<p>classes:<\/p>\n<pre><code>Popen(args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0)\n# \u521b\u5efa\u4e00\u4e2a\u5b50\u8fdb\u7a0b\uff0cargs\u53ef\u4ee5\u662f\u5b57\u7b26\u4e32\u6216\u8005\u5217\u8868\u5f62\u5f0f.\n# args: \u547d\u4ee4\u548c\u53c2\u6570\u5217\u8868, \u53ef\u4ee5\u662f\u5b57\u7b26\u4e32\u6216\u8005\u5217\u8868\u5f62\u5f0f.\n# \u5982\u679c\u662f\u5b57\u7b26\u4e32\u5f62\u5f0f\uff0cshell=True, \u5426\u5219\u662f\u5217\u8868\u5f62\u5f0f.\n# \u5982\u679c\u662f\u5217\u8868\u5f62\u5f0f\uff0cshell=False, args[0]\u662f\u53ef\u6267\u884c\u6587\u4ef6\u7684\u8def\u5f84\uff0cargs[1:]\u662f\u53c2\u6570\u5217\u8868.\n# \u975e\u4ea4\u4e92\u6267\u884csudo\u547d\u4ee4, \u6216\u8005\u4f7f\u7528sh\/pexpect\u7b49\u7b2c\u4e09\u65b9\u5e93\nPopen(['sudo', '-S'] + shlex.split(command), stdin=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, ...)\nstdout, stderr = child.communicate(password+'\\n')\n# methods:\npoll() # \u68c0\u67e5\u5b50\u8fdb\u7a0b\u662f\u5426\u7ed3\u675f\uff0c\u8fd4\u56dereturncode.\nwait() # \u7b49\u5f85\u5b50\u8fdb\u7a0b\u7ed3\u675f\uff0c\u8fd4\u56dereturncode.\ncommunicate(input=None) # \u8fd4\u56de(stdout, stderr).\nkill() # \u53d1\u9001SIGKILL\u4fe1\u53f7\npipe_cloexec()\nsend_signal(sig)\nterminate()\n# Data:\nstdin\nstdout\nstderr\npid\nreturncode\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>call(*popenargs, **kwargs)\n# retcode = call([&quot;ls&quot;, &quot;-l&quot;])\ncheck_call(*popenargs, **kwargs)\n# check_call([&quot;ls&quot;, &quot;-l&quot;]) -&gt; \u5982\u679c\u8fd4\u56de\u7801\u4e3a\uff10\u5c31\u8fd4\u56de\uff0c\u5426\u5219\u629b\u51faCalledProcessError.\ncheck_output(*popenargs, **kwargs) # \u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32\n# output = check_output([&quot;ls&quot;, &quot;-l&quot;, &quot;\/dev\/null&quot;]) -&gt; \u5982\u679c\u8fd4\u56de\u7801\u4e3a\uff10\u8fd4\u56de\u547d\u4ee4\u7ed3\u679c\uff0c\u5426\u5219\u629b\u51faCalledProcessError.\n<\/code><\/pre>\n<p>data:<\/p>\n<pre><code>PIPE = -1\nSTDOUT = -2\n<\/code><\/pre>\n<h2 id=\"concurrent\">concurrent<\/h2>\n<p>concurrent\u6a21\u5757\u63d0\u4f9b\u4e86\u591a\u7ebf\u7a0b\u548c\u591a\u8fdb\u7a0b\u7684\u9ad8\u7ea7\u63a5\u53e3.<\/p>\n<pre><code>import concurrent.futures\n<\/code><\/pre>\n<h2 id=\"sched\">sched<\/h2>\n<h2 id=\"contextvars\">contextvars<\/h2>\n<hr>\n<h1 id=\"inter-process-communication-and-networking\">Inter Process Communication and Networking<\/h1>\n<h2 id=\"asyncio\">asyncio<\/h2>\n<p>asyncio\u662f\u57fa\u4e8eevent loop\uff08\u4e8b\u4ef6\u5faa\u73af\uff09\u7684\u5f02\u6b65\u7f16\u7a0b\u6846\u67b6\uff0c\u5e76\u53d1\u8fd0\u884c\u534f\u7a0b\u3001\u6267\u884c\u7f51\u7edcIO\u548cIPC\uff0c\u63a7\u5236\u5b50\u8fdb\u7a0b\uff0c\u901a\u8fc7\u961f\u5217\u5b9e\u73b0\u5206\u5e03\u5f0f\u4efb\u52a1\uff0c\u540c\u6b65\u5e76\u53d1\u4ee3\u7801\u3002<\/p>\n<p>asyncio \u5f80\u5f80\u662f\u6784\u5efa IO \u5bc6\u96c6\u578b\u548c\u9ad8\u5c42\u7ea7 \u7ed3\u6784\u5316 \u7f51\u7edc\u4ee3\u7801\u7684\u6700\u4f73\u9009\u62e9\u3002<\/p>\n<p>coroutine\uff08\u534f\u7a0b\uff09\u662f\u4e00\u4e2a\u7279\u6b8a\u7684\u51fd\u6570\uff0c\u53ef\u4ee5\u6682\u505c\u548c\u6062\u590d\u6267\u884c\uff0c\u5141\u8bb8\u5728\u7b49\u5f85IO\u64cd\u4f5c\u65f6\u4e0d\u963b\u585e\u4e3b\u7ebf\u7a0b\u3002\u5728\u5355\u7ebf\u7a0b\u5185\u8fd0\u884c\uff0c\u901a\u8fc7\u4e8b\u4ef6\u5faa\u73af\u8c03\u5ea6\uff0c\u975e\u62a2\u5360\u5f0f\uff0c\u5185\u5b58\u6d88\u8017\u5c0f\uff0c\u5207\u6362\u5feb\uff0c\u4e0d\u53d7GIL\u9650\u5236\u3002<\/p>\n<p>coroutine function: &ldquo;async def&rdquo; \u5b9a\u4e49\u534f\u7a0b\u51fd\u6570\uff0c\u8fd4\u56de\u534f\u7a0b\u5bf9\u8c61\u3002\ncoroutine object: \u8868\u793a\u4e00\u4e2a\u6ca1\u6709\u6267\u884c\u7684\u534f\u7a0b\uff0c\u9700\u8981\u53d8\u6210\u4e00\u4e2atask\uff0c\u5e76\u4e14\u8fdb\u5165event loop\u624d\u80fd\u6267\u884c\u3002<\/p>\n<pre><code>import asyncio\n<\/code><\/pre>\n<p>await\u540e\u5982\u679c\u662f\u4e00\u4e2acoroutine\uff1a<\/p>\n<ol>\n<li>\u9690\u58eb\u521b\u5efatask\uff08\u4e0d\u4f1a\u8c03\u7528create_task\uff09\uff0c\u53ea\u8fd0\u884c\u5f53\u524d\u534f\u7a0b\u3002<\/li>\n<li>\u987a\u5e8f\u6267\u884c<\/li>\n<\/ol>\n<p>await\u540e\u5982\u679c\u662f\u4e00\u4e2atask\uff1a<\/p>\n<ol>\n<li>\u76f4\u63a5\u6ce8\u518c\u5230event loop\u3002<\/li>\n<li>\u5e76\u53d1\u6267\u884c<\/li>\n<\/ol>\n<p>\u534f\u7a0b\u5bf9\u8c61\uff0c\u6216\u8005awaitable\u5bf9\u8c61\u5fc5\u987b\u8c03\u7528await\u3002<\/p>\n<p>classes:<\/p>\n<pre><code># asyncio.Runner\nrunner = Runner(loop=None, debug=False) # \u521b\u5efa\u4e00\u4e2aRunner\u5bf9\u8c61\uff0c\u7528\u4e8e\u8fd0\u884c\u534f\u7a0b\u3002\nwith asyncio.Runner() as runner:\nrunner.run(coro) # \u8fd0\u884c\u4e00\u4e2a\u534f\u7a0b\uff0c\u8fd4\u56de\u534f\u7a0b\u7684\u7ed3\u679c\u3002\n# asyncio.Task\nTask(coro, *, loop=None) # \u5c06coroutine\u53d8\u6210\u4e00\u4e2atask\uff0c\u5e76\u4e14\u6ce8\u518c\u5230event loop\uff0c\u8fd4\u56deTask\u5bf9\u8c61\u3002\n# methods:\ncancel() # \u53d6\u6d88\u4efb\u52a1\uff0c\u629b\u51faCancelledError\u5f02\u5e38\u3002\ndone() # \u8fd4\u56de\u4efb\u52a1\u662f\u5426\u5b8c\u6210\u7684boolean\u3002\nresult() # \u8fd4\u56de\u4efb\u52a1\u7684\u7ed3\u679c\uff0c\u5982\u679c\u4efb\u52a1\u672a\u5b8c\u6210\u5219\u629b\u51fa\u5f02\u5e38\u3002\nexception() # \u8fd4\u56de\u4efb\u52a1\u7684\u5f02\u5e38\uff0c\u5982\u679c\u4efb\u52a1\u672a\u5b8c\u6210\u5219\u629b\u51fa\u5f02\u5e38\u3002\nadd_done_callback(callback) # \u6dfb\u52a0\u4e00\u4e2a\u56de\u8c03\u51fd\u6570\uff0c\u5f53\u4efb\u52a1\u5b8c\u6210\u65f6\u8c03\u7528\u3002\n# asyncio.TaskGroup, \u6279\u91cf\u521b\u5efatask\u3002\ntask_group = TaskGroup(*, loop=None)\nasync with TaskGroup() as tg:\ntg1 = tg.create_task(coro1)\ntg2 = tg.create_task(coro2)\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>run(coro, *, debug=False) # \u662f\u8fd0\u884c\u534f\u7a0b\u7684\u552f\u4e00\u5165\u53e3\u51fd\u6570\uff0c\u8c03\u7528\u9876\u5c42\u534f\u7a0b\u51fd\u6570\uff0c\u8fd4\u56de\u534f\u7a0b\u7684\u7ed3\u679c\u3002\nasyncio.run(main())\ncreate_task(coro, *, loop=None) # \u5c06coroutine\u53d8\u6210\u4e00\u4e2atask\uff0c\u5e76\u4e14\u6ce8\u518c\u5230event loop\uff0c\u8fd4\u56deTask\u5bf9\u8c61\ntasks = [\nasyncio.create_task(coro(...)),\nfor i in range(10)\n]\ngather(*aws, return_exceptions=False) # \u5e76\u53d1\u6267\u884caws\u4e2d\u7684\u53ef\u7b49\u5f85\u5bf9\u8c61\u3002\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\uff0c\u987a\u5e8f\u4e0eaws\u4e2d\u4e00\u81f4\u3002gather\u4f1a\u81ea\u52a8\u628acoroutine\u53d8\u6210task\u3002\u65e0\u9700\u624b\u52a8\u8c03\u7528create_task\u3002\n# return_exceptions=False\u65f6\uff0c\u5982\u679c\u6709\u5f02\u5e38\u53d1\u751f\uff0c\u629b\u51fa\u5f02\u5e38\u3002\u9ed8\u8ba4\u503c\u3002\n# return_exceptions=True\u65f6\uff0c\u5982\u679c\u6709\u5f02\u5e38\u53d1\u751f\uff0c\u8fd4\u56de\u5f02\u5e38\u5bf9\u8c61\u800c\u4e0d\u662f\u629b\u51fa\u5f02\u5e38\u3002\nawait asyncio.gather(*tasks)\nsleep(delay, result=None, *, loop=None) # \u5f02\u6b65\u7761\u7720\uff0c\u8fd4\u56de\u4e00\u4e2aFuture\u5bf9\u8c61\nawait asyncio.sleep(1) # \u7b49\u5f851\u79d2\u949f\ntimeout(delay, *, loop=None) # \u8fd4\u56de\u4e00\u4e2aFuture\u5bf9\u8c61\uff0c\u5ef6\u8fdf\u6307\u5b9a\u65f6\u95f4\u540e\u5b8c\u6210\nasync with asyncio.timeout(10):\nawait my_task()\nwait(fs, *, loop=None, timeout=None, return_when=ALL_COMPLETED) # \u7b49\u5f85\u4e00\u7ec4Future\u5bf9\u8c61\u5b8c\u6210\uff0c\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u5df2\u5b8c\u6210\u548c\u672a\u5b8c\u6210Future\u5bf9\u8c61\u7684\u5143\u7ec4\u3002\ndone, pending = await asyncio.wait(fs, timeout=10, return_when=asyncio.ALL_COMPLETED)\nwait_for(aws, timeout=None, *, loop=None) # \u7b49\u5f85\u4e00\u4e2a\u53ef\u7b49\u5f85\u5bf9\u8c61\u5b8c\u6210\uff0c\u8fd4\u56de\u7ed3\u679c\u3002\u8d85\u65f6\u540e\u629b\u51faasyncio.TimeoutError\u5f02\u5e38\u3002\nawait asyncio.wait_for(coro(), timeout=10) # \u7b49\u5f85coro\u572810\u79d2\u5185\u5b8c\u6210\u3002\nshield(fut, *, loop=None) # \u4fdd\u62a4\u4e00\u4e2aFuture\u5bf9\u8c61\uff0c\u4f7f\u5176\u4e0d\u4f1a\u88ab\u53d6\u6d88\uff0c\u8fd4\u56de\u4e00\u4e2aFuture\u5bf9\u8c61\u3002\nas_completed(fs, *, loop=None) # \u8fd4\u56de\u4e00\u4e2a\u8fed\u4ee3\u5668\uff0c\u8fed\u4ee3\u5668\u4f1a\u6309\u5b8c\u6210\u7684\u987a\u5e8f\u8fd4\u56deFuture\u5bf9\u8c61\u3002\nasync for fut in as_completed(fs):\nresult = await fut # \u7b49\u5f85\u6bcf\u4e2aFuture\u5bf9\u8c61\u5b8c\u6210\uff0c\u6309\u5b8c\u6210\u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\u3002\ncurrent_task(loop=None) # \u8fd4\u56de\u5f53\u524d\u6b63\u5728\u8fd0\u884c\u7684Task\u5bf9\u8c61\uff0c\u5982\u679c\u6ca1\u6709\u6b63\u5728\u8fd0\u884c\u7684Task\uff0c\u5219\u8fd4\u56deNone\u3002\nall_tasks(loop=None) # \u8fd4\u56de\u5f53\u524d\u4e8b\u4ef6\u5faa\u73af\u4e2d\u7684\u6240\u6709Task\u5bf9\u8c61\u3002\niscoroutine(obj) # \u5224\u65adobj\u662f\u5426\u662f\u4e00\u4e2a\u534f\u7a0b\u5bf9\u8c61\niscoroutinefunction(obj) # \u5224\u65adobj\u662f\u5426\u662f\u4e00\u4e2a\u534f\u7a0b\u51fd\u6570\u3002\nisawaitable(obj) # \u5224\u65adobj\u662f\u5426\u662f\u4e00\u4e2a\u53ef\u7b49\u5f85\u5bf9\u8c61\u3002\nisfuture(obj) # \u5224\u65adobj\u662f\u5426\u662f\u4e00\u4e2aFuture\u5bf9\u8c61\u3002\n<\/code><\/pre>\n<p>Queue\u7528\u4e8e\u534f\u7a0b\u95f4\u901a\u4fe1, \u4e0d\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff1a<\/p>\n<pre><code># asyncio.Queue\nqueue = asyncio.Queue(maxsize=0, *, loop=None) # \u521b\u5efa\u4e00\u4e2a\u5f02\u6b65\u961f\u5217\uff0cmaxsize=0\u8868\u793a\u65e0\u9650\u5236\u3002\nawait queue.put(item) # \u5411\u961f\u5217\u4e2d\u6dfb\u52a0\u4e00\u4e2aitem\uff0c\u963b\u585e\u76f4\u5230\u961f\u5217\u6709\u7a7a\u95f4\u3002\nitem = await queue.get() # \u4ece\u961f\u5217\u4e2d\u83b7\u53d6\u4e00\u4e2aitem\uff0c\u963b\u585e\u76f4\u5230\u961f\u5217\u6709\u6570\u636e\u3002\nitem = queue.get_nowait() # \u975e\u963b\u585e\u83b7\u53d6\u961f\u5217\u4e2d\u7684\u4e00\u4e2aitem\uff0c\u5982\u679c\u961f\u5217\u4e3a\u7a7a\u5219\u629b\u51faasyncio.QueueEmpty\u5f02\u5e38\u3002\nqueue.task_done() # \u6807\u8bb0\u4e00\u4e2a\u4efb\u52a1\u5df2\u5b8c\u6210\uff0c\u901a\u5e38\u5728get\u4e4b\u540e\u8c03\u7528\u3002\nawait queue.join() # \u963b\u585e\u76f4\u5230\u6240\u6709\u4efb\u52a1\u90fd\u5b8c\u6210\u3002\n<\/code><\/pre>\n<p>\u540c\u6b65\u539f\u8bed\u76f8\u5173\uff1a<\/p>\n<pre><code>Lock\nEvent\nCondition\nSemaphore\nBoundedSemaphore\nBarrier\n<\/code><\/pre>\n<h2 id=\"socket\">socket<\/h2>\n<p>socket\u534f\u8bae\u7684\u6807\u51c6\u5e93<\/p>\n<pre><code>import socket\n<\/code><\/pre>\n<p>classes:<\/p>\n<pre><code># socket = class _socketobject(__builtin__.object)\n# socket.socket([family[, type[, proto]]])\nclose() # \u5173\u95edsocket\nshutdown(flag) # 0 \u5173\u95ed\u8bfb\uff0c\uff11\u5173\u95ed\u5199\uff0c\uff12\u5168\u90e8\u5173\u95ed\n# eg: socket.socket(AF_INET, SOCK_STREAM, 0) ipv4+tcp\n# eg: socket.socket(AF_INET, SOCK_DGRAM, 0) ipv4+udp\n# methods:\nbind(address) # \u670d\u52a1\u5668\u7ed1\u5b9a(host, port)\u5230socket\nlisten(backlog) # \u670d\u52a1\u5668\u5f00\u59cb\u76d1\u542ctcp\naccept() # \u670d\u52a1\u5668\u963b\u585e\u7b49\u5f85\u5ba2\u6237\u7684tcp\u8fde\u63a5, \u8fd4\u56de(socket object, address info)\nconnect(address) # \u5ba2\u6237\u7aef\u4e3b\u52a8\u521d\u59cb\u5316tcp\u8fde\u63a5,\u8fde\u63a5\u5931\u8d25\u629b\u51fa\u5f02\u5e38\nconnect_ex(address) # \u540c\u4e0a\uff0c\u8fde\u63a5\u5931\u8d25\u8fd4\u56deerrno\nsend(data[, flags]) # \u53d1\u9001tcp\u6570\u636e\nsendall(data[, flags]) # \u53d1\u9001\u5b8c\u6574tcp\u6570\u636e\nrecv(buflen[, flags]) # \u63a5\u6536tcp\u6570\u636e\nrecv_into(buffer[, nbytes[, flags]])\nsendto(data[, flags], addr) # \u53d1\u9001udp\u6570\u636e\nrecvfrom(buflen[, flags]) # \u63a5\u6536udp\u6570\u636e\nrecvfrom_into(buffer[, nbytes, [, flags])])\ngetpeername() # \u83b7\u53d6\u5f53\u524dsocket\u7684\u8fdc\u7aef\u5730\u5740\ngetsockname() # \u83b7\u53d6\u5f53\u524dsocket\u7684\u5730\u5740\ngetsockopt(level, option[, buffersize]) # \u83b7\u53d6socket\u53c2\u6570\nsetsockopt(level, option, value) # \u8bbe\u7f6esocket\u53c2\u6570\nsetblocking(flag)\ngettimeout()\nsettimeout(timeout)\nmakefile([mode[, bufsize]])\nfileno()\ndup()\n# data descriptor:\nfamily\/type\/proto\u3000\u53c2\u8003man 2 socket\nrecv\nrecv_into\nrecvfrom\nrecvfrom_into\nsend\nsendto\n<\/code><\/pre>\n<p>class SocketIO:<\/p>\n<pre><code>class SocketIO(io.RawIOBase)\nsio = SocketIO(sock, mode)\nmethods:\nclose()\nreadinto(b)\nwrite(b)\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>create_connection(address, timeout=&lt;object object&gt;, source_address=None)\nfromfd(fd, family, type[, proto]) # \u7528\u4e00\u4e2a\u5df2\u7ecf\u6253\u5f00\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u521b\u5efa\u4e00\u4e2asocket\u5bf9\u8c61\ngetaddrinfo(host, port [, family, socktype, proto, flags])\ngetdefaulttimeout()\ngetfqdn(name='') # FQDN, \u83b7\u53d6\u5b8c\u6574\u57df\u7684\u4fe1\u606f\ngethostbyaddr(host) -&gt; (name, aliaslist, addresslist)\ngethostbyname(host)\ngethostbyname_ex(host) -&gt; (name, aliaslist, addresslist)\ngethostname()\ngetnameinfo(sockaddr, flags) --&gt; (host, port)\ngetprotobyname(name)\ngetservbyname(servicename[, protocolname])\ngetservbyport(port[, protocolname])\nhtonl(integer)\nhtons(integer)\ninet_aton(string)\ninet_ntoa(packed_ip)\ninet_ntop(af, packed_ip)\ninet_pton(af, ip)\nntohl(integer)\nntohs(integer)\nsetdefaulttimeout(timeout)\nsocketpair([family[, type[, proto]]]) -&gt; (socket object, socket object)\n<\/code><\/pre>\n<h2 id=\"select\">select<\/h2>\n<p>\u7b49\u5f85IO\u4e8b\u4ef6\u53d1\u751f\uff0c\u8fd4\u56de\u5c31\u7eea\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u5217\u8868\u3002<\/p>\n<pre><code>import select\n<\/code><\/pre>\n<h2 id=\"selectors\">selectors<\/h2>\n<p>selectors\u6a21\u5757\u63d0\u4f9b\u4e86\u66f4\u9ad8\u7ea7\u7684IO\u591a\u8def\u590d\u7528\u63a5\u53e3\u3002<\/p>\n<pre><code>import selectors\n<\/code><\/pre>\n<h2 id=\"signal\">signal<\/h2>\n<h2 id=\"ssl\">ssl<\/h2>\n<h2 id=\"mmap\">mmap<\/h2>\n<hr>"},{"title":"PSL_Python","link":"https:\/\/canuxcheng.com\/post\/psl_python\/","pubDate":"Mon, 15 Aug 2016 11:04:12 +0000","guid":"https:\/\/canuxcheng.com\/post\/psl_python\/","description":"<h1 id=\"python-runtime-services\">Python Runtime Services<\/h1>\n<h2 id=\"builtins\">builtins<\/h2>\n<p>builtins - Built-in functions, exceptions, and other objects.<\/p>\n<p>python2\u53eb__builtin__<\/p>\n<p>python3\u53ebbuiltins<\/p>\n<h2 id=\"_main_\">_<em>main<\/em>_<\/h2>\n<blockquote>\n<p><strong>main<\/strong> - Top-level script environment.<\/p>\n<\/blockquote>\n<pre><code>if __name__ == &quot;__main__&quot;:\nmain()\n<\/code><\/pre>\n<p>\u5f53\u4f5c\u4e3a\u9876\u5c42\u811a\u672c\u8fd0\u884c\u65f6(<strong>main<\/strong>), \u5f53\u4f5c\u4e3a\u4e00\u4e2a\u6a21\u5757\u8fd0\u884c\u65f6\u5019\u5c31\u662f\u6a21\u5757\u540d\u79f0\uff0e<\/p>\n<h2 id=\"_future_\">_<em>future<\/em>_<\/h2>\n<p>\u628a\u4e0b\u4e00\u4e2a\u7248\u672c\u7684\u65b0\u7279\u6027\u5bfc\u5165\u5230\u5f53\u524d\u7248\u672c\u3002<\/p>\n<pre><code>from __future__ import &lt;feature_name&gt;\n# feature name:\nall_feature_names # \u4e00\u6b21\u5bfc\u5165\u6240\u6709feature\nabsolute_import # \u7edd\u5bf9\u5bfc\u5165\ndivision\ngenerators\nnested_scopes\nprint_function\nunicode_literals # python2\u4e2du'string'\u624d\u8868\u793aunicode, 'string'\u8868\u793astr\uff0cpython3\u4e2d\u6240\u6709\u5b57\u7b26\u4e32\u90fd\u662funicode\u3002\nwith_statement\n<\/code><\/pre>\n<p>data:<\/p>\n<pre><code>all_feature_names\n...\n<\/code><\/pre>\n<h2 id=\"sys\">sys<\/h2>\n<pre><code>import sys\n<\/code><\/pre>\n<p>Dynamic objects:<\/p>\n<pre><code># \u52a8\u6001\u5bf9\u8c61\nsys.argv # \u547d\u4ee4\u884c\u53c2\u6570\u7684\u5217\u8868\uff0csys.argv[0]\u662f\u7a0b\u5e8f\u540d\u79f0, len(sys.argv)\u5c31\u662fC\u8bed\u8a00\u4e2d\u7684argc\nsys.path # \u641c\u7d22\u7684\u8def\u5f84\uff0eimport\u5bfc\u5165\u6a21\u5757\u7684\u641c\u7d22\u8def\u5f84\uff0e\nsys.modules # \u5b57\u5178\u683c\u5f0f\u7684\u52a0\u8f7d\u7684\u6a21\u5757.\u5df2\u7ecf\u5bfc\u5165\u5e76\u52a0\u8f7d\u7684\u6a21\u5757\u4f1a\u52a0\u8fdb\u6765\uff0e\nsys.stdin # \u6807\u51c6\u8f93\u5165\uff0c\u7528\u4e8einput()\nsys.stdout # \u6807\u51c6\u8f93\u51fa\uff0c\u7528\u4e8eprint\nsys.stderr # \u6807\u51c6\u51fa\u9519\ndisplayhook -- called to show results in an interactive session\nexcepthook --\nlast_type -- type of last uncaught exception\nlast_value -- value of last uncaught exception\nlast_traceback --\n<\/code><\/pre>\n<p>Static objects:<\/p>\n<pre><code># \u9759\u6001\u5bf9\u8c61\nfloat_info -- a dict with information about the float inplementation.\nlong_info -- a struct sequence with information about the long implementation.\nmaxint -- the largest supported integer (the smallest is -maxint-1).\nmaxsize -- the largest supported length of containers.\nmaxunicode -- the largest supported character\nbuiltin_module_names -- tuple of module names built into this interpreter\nversion -- the version of this interpreter as a string\nversion_info -- version information as a named tuple\nhexversion -- version information encoded as a single integer\ncopyright -- copyright notice pertaining to this interpreter\nplatform -- platform identifier # \u53ef\u4ee5\u5224\u65ad\u64cd\u4f5c\u7cfb\u7edf\u7c7b\u578b\nsys.platform # 'win32', 'linux2', 'darwin'\nexecutable -- absolute path of the executable binary of the Python interpreter\nprefix -- prefix used to find the Python library\nexec_prefix -- prefix used to find the machine-specific Python library\nfloat_repr_style -- string indicating the style of repr() output for floats\n__stdin__ -- the original stdin; don't touch!\n__stdout__ -- the original stdout; don't touch!\n__stderr__ -- the original stderr; don't touch!\n__displayhook__ -- the original displayhook; don't touch!\n__excepthook__ -- the original excepthook; don't touch!\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>displayhook() -- print an object to the screen, and save it in __builtin__._\nexcepthook() -- print an exception and its traceback to sys.stderr\nexc_info() -- \u8fd4\u56de\u5f53\u524d\u5f02\u5e38\u7684\u7ebf\u7a0b\u5b89\u5168\u7684\u4e09\u4e2a\u4fe1\u606f\uff0etype, value, traceback.\nexc_clear() -- \u6e05\u7a7a\u5f53\u524d\u7ebf\u7a0b\u7684\u5f02\u5e38\u72b6\u6001\nexit() -- \u629b\u51fa SystemExit \u5f02\u5e38\u9000\u51fa\u89e3\u91ca\u5668\ngetdlopenflags() -- returns flags to be used for dlopen() calls\ngetprofile() -- get the global profiling function\ngetrefcount() -- return the reference count for an object (plus one :-)\ngetrecursionlimit() -- return the max recursion depth for the interpreter\ngetsizeof() -- return the size of an object in bytes\ngettrace() -- get the global debug tracing function\nsetcheckinterval() -- control how often the interpreter checks for events\nsetdlopenflags() -- set the flags to be used for dlopen() calls\nsetprofile() -- set the global profiling function\nsetrecursionlimit() -- set the max recursion depth for the interpreter\nsettrace() -- set the global debug tracing function\n<\/code><\/pre>\n<p>data:<\/p>\n<pre><code>flags # \u547d\u4ee4\u884c\u7684\u72b6\u6001\uff0c-d debug, -v verbose\n<\/code><\/pre>\n<h2 id=\"sysconfig\">sysconfig<\/h2>\n<h2 id=\"warnings\">warnings<\/h2>\n<p>python\u7684\u8b66\u544a\u6a21\u5757\uff0c\u53ea\u8b66\u544a\uff0c\u4e0d\u4e2d\u65ad\u7a0b\u5e8f\u8fd0\u884c\uff0e<\/p>\n<pre><code>import warnings\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>warn(message[, category[, stacklevel]])\n<\/code><\/pre>\n<h2 id=\"contextlib\">contextlib<\/h2>\n<p>\u7f16\u5199\u4e0a\u4e0b\u6587\u7ba1\u7406\u5668\u7684\u6a21\u5757\uff0e<\/p>\n<pre><code>import contextlib\n<\/code><\/pre>\n<h2 id=\"abc\">abc<\/h2>\n<p>\u5b9e\u73b0\u62bd\u8c61\u65b9\u6cd5\uff0e<\/p>\n<pre><code>import abc\n<\/code><\/pre>\n<p>classes:<\/p>\n<pre><code># abc.ABCMeta\nABCMeta\n# abc.abstractproperty\nabstractproperty\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>abstractmethod(funcobj)\n<\/code><\/pre>\n<h2 id=\"atexit\">atexit<\/h2>\n<h2 id=\"traceback\">traceback<\/h2>\n<p>For python stack traces. \u8ffd\u8e2apython\u7684\u5806\u6808\u4fe1\u606f\uff0e<\/p>\n<pre><code>import traceback\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>extract_stack(f=None, limit=None)\nextract_tb(tb, limit=None)\nformat_stack(f=None, limit=None)\nformat_tb(tb, limit=None) # \u683c\u5f0f\u5316\u540e\u8fd4\u56de\u5b57\u7b26\u4e32\nprint_stack(f=None, limit=None, file=None)\nprint_tb(tb, limit=None, file=None) # \u76f4\u63a5\u6253\u5370stacktrace\u4fe1\u606f\n...\n<\/code><\/pre>\n<h2 id=\"gc\">gc<\/h2>\n<p>garbage collector\uff1apython\u7684\u5783\u573e\u56de\u6536\u6a21\u5757\uff0e<\/p>\n<pre><code>import gc\n<\/code><\/pre>\n<h2 id=\"inspect\">inspect<\/h2>\n<p>\u4ece\u8fd0\u884c\u7684python\u5bf9\u8c61\u83b7\u53d6\u6709\u7528\u7684\u4fe1\u606f\uff0e<\/p>\n<pre><code>import inspect\n<\/code><\/pre>\n<p>classes:<\/p>\n<p>functions:<\/p>\n<pre><code>classify_class_attrs(cls)\nstack(context=1)\nisgenerator()\nisgeneratorfunction() # \u68c0\u67e5\u4e00\u4e2a\u51fd\u6570\u662f\u5426\u662f\u751f\u6210\u5668\n<\/code><\/pre>\n<p>data:<\/p>\n<h2 id=\"site\">site<\/h2>\n<h2 id=\"dataclass\">dataclass<\/h2>\n<hr>\n<h1 id=\"custom-python-interpreter\">Custom python interpreter<\/h1>\n<h2 id=\"code\">code<\/h2>\n<h2 id=\"codeop\">codeop<\/h2>\n<hr>\n<h1 id=\"python-language-services\">Python language services<\/h1>\n<h2 id=\"ast\">ast<\/h2>\n<h2 id=\"dis\">dis<\/h2>\n<h2 id=\"keyword\">keyword<\/h2>"},{"title":"PSL_System","link":"https:\/\/canuxcheng.com\/post\/psl_system\/","pubDate":"Mon, 15 Aug 2016 11:04:12 +0000","guid":"https:\/\/canuxcheng.com\/post\/psl_system\/","description":"<h1 id=\"generic-operating-system-services\">Generic Operating System Services<\/h1>\n<h2 id=\"os\">os<\/h2>\n<pre><code>import os\nos.path # \u53c2\u8003PSL_File\nos.name\nos.curdir\nos.pardir # \u8868\u793a\u4e0a\u4e00\u7ea7\u8def\u5f84.., \u9700\u8981\u7528abspath\u89e3\u6790\n# os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir))\nos.sep\nos.extsep\nos.altsep\nos.pathsep\nos.linesep\nos.defpath\nos.devnull\n<\/code><\/pre>\n<p>classes:<\/p>\n<p>functions:<\/p>\n<pre><code>WCOREDUMP(...)\n...\nabort(...)\nfork() # \u521b\u5efa\u4e00\u4e2a\u5b50\u8fdb\u7a0b\uff0c\u8fd4\u56de0\u7ed9\u5b50\u8fdb\u7a0b\uff0c\u8fd4\u56de\u5b50\u8fdb\u7a0bpid\u7ed9\u7236\u8fdb\u7a0b\uff0e\nexec*\nwait() # \u7b49\u5f85\u5b50\u8fdb\u7a0b\u7ed3\u675f\uff0c\u8fd4\u56de(pid, status).\nwaitpid(pid, options) # \u7b49\u5f85\u6307\u5b9a\u5b50\u8fdb\u7a0b\u7ed3\u675f.\nlistdir(path) # \u5217\u51fa\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u548c\u76ee\u5f55\nmakedirs(path [, mode=0o777], exist_ok=False)\nmkdir(path [, mode=0777])\nwalk(top, topdown=True, onerror=None, followlinks=False) # \u8fd4\u56de (dirpath, dirnames, filenames) \u7c7b\u578b\u7684\u8fed\u4ee3\u5668\nremove(path) # \u5220\u9664\u6587\u4ef6\nrmdir(path) # \u5220\u9664\u76ee\u5f55\nremovedirs(path)\nsymlink(src, dst)\nchown(path, uid, gid)\nchmod(path, mode=0o777)\n...\n# \u4f7f\u7528subprocess\u6a21\u5757\u4ee3\u66ff\u4e0b\u5217\u51fd\u6570\uff1a\nsystem(command) # \u5728subshell\u6267\u884c\u547d\u4ee4\uff0c\u8fd4\u56de\u9000\u51fa\u7801(windows\u7cfb\u7edf\u59cb\u7ec8\u4e3a0),\u800c\u975e\u547d\u4ee4\u6267\u884c\u7ed3\u679c\uff0e\nspawn*\npopen*(command [, mode='r' [, bufsize]]) # \u6267\u884c\u547d\u4ee4\uff0c\u8fd4\u56de\u547d\u4ee4\u6267\u884c\u7ed3\u679c\u7684\u6587\u4ef6\u53e5\u67c4(file\u5bf9\u8c61)\n<\/code><\/pre>\n<p>data:<\/p>\n<pre><code>EX_CANTCREAT = 73\n...\n<\/code><\/pre>\n<h2 id=\"time\">time<\/h2>\n<pre><code>import time\n<\/code><\/pre>\n<p>classes:<\/p>\n<p>functions:<\/p>\n<pre><code>clock()\nsleep(seconds) # \u5ef6\u8fdf\ntzset()\n# \u83b7\u53d6\u65f6\u95f4\u6233(Epoch seconds)\ntime() # \u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u6233\nmktime(tuple) # mktime((2017,8,23,11,7,10,12)) , \u53c2\u6570\u662f\u65f6\u95f4\u5143\u7ec4\n# \u83b7\u53d6\u65f6\u95f4\u5143\u7ec4 (tm_year,tm_mon,tm_mday,tm_hour,tm_min, tm_sec,tm_wday,tm_yday,tm_isdst)\nlocaltime([seconds]) # \u53c2\u6570\u662f\u65f6\u95f4\u6233\ngmtime([seconds]) # \u53c2\u6570\u662f\u65f6\u95f4\u6233\nstrptime(string, format) # \u53c2\u6570\u662f\u65f6\u95f4\u5b57\u7b26\u4e32\n# \u83b7\u53d6\u65f6\u95f4\u5b57\u7b26\u4e32\nasctime([tuple]) # \u53c2\u6570\u662f\u65f6\u95f4\u5143\u7ec4\nstrftime(format[, tuple]) # \u53c2\u6570\u662f\u65f6\u95f4\u5143\u7ec4\nctime(seconds) # \u53c2\u6570\u662f\u65f6\u95f4\u6233\n<\/code><\/pre>\n<p>data:<\/p>\n<h2 id=\"logging\">logging<\/h2>\n<pre><code>import logging\n<\/code><\/pre>\n<p>classes:<\/p>\n<pre><code>Logger(Filterer)\n# methods:\nsetLevel(self, level) # \u53ea\u4f1a\u8f93\u51fa\u6307\u5b9alevel\u4ee5\u4e0a\u7684log, \u9ed8\u8ba4\u662fWARNING\ncritical(self, msg, *args, **kwargs) # 50\nerror(self, msg, *args, **kwargs) # 40\nwarning(self, msg, *args, **kwargs) # 30\ninfo(self, msg, *args, **kwargs) # 20\ndebug(self, msg, *args, **kwargs) # 10\nexception(self, msg, *args, **kwargs) #\nlog(self, level, msg, *args, **kwargs) #\naddHandler(self, hdlr) # \u6dfb\u52a0handler\u5230logger\nFormatter\n# %(asctime)s:%(levelname)s:%(name)s:%(message)s'\nFormatter(fmt=None, datefmt=None)\nHandler(Filterer)\n# methods:\nsetFormatter(self, fmt)\nsetLevel(self, level)\nStreamHandler(Handler) # \u9ed8\u8ba4\u6253\u5370\u5230sys.stderr\nStreamHandler(stream=None)\nFileHandler(StreamHandler) # \u6253\u5370\u5230\u6587\u4ef6\nFileHandler(filename, mode='a', encoding=None, delay=0)\n# from logging.handlers import *\nWatchedFileHandler\nRotatingFileHandler\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>basicConfig(**kwargs) # \u8bbe\u7f6elog\u7684\u683c\u5f0f\n# filename\/filemode\/format\/datefmt\/level\/stream\n# format\u9ed8\u8ba4\u662fBASIC_FORMAT.\n# level\u9ed8\u8ba4\u662fwarning\/warn.\n# stream\u9ed8\u8ba4\u662fsys.stderr,\u5f53filename\u548cstream\u540c\u65f6\u6307\u5b9a\uff0cstream\u88ab\u5ffd\u7565\uff0e\n# datafmt\n# filename \u65e5\u5fd7\u6587\u4ef6\u540d\n# filemode w\u6bcf\u6b21\u8986\u76d6\u5199\u5165\uff0ca\u6bcf\u6b21\u8ffd\u52a0\u5199\u5165\ngetLogger(name=None) # \u8fd4\u56deLogger\u7c7b\u578b\u5bf9\u8c61\n<\/code><\/pre>\n<p>data:<\/p>\n<pre><code>BASIC_FORMAT = '%(levelname)s:%(name)s:%(message)s'\nCRITICAL = 50\nFATAL = 50\nERROR = 40\nWARN = 30\nWARNING = 30\nINFO = 20\nDEBUG = 10\nNOTSET = 0\n<\/code><\/pre>\n<h2 id=\"platform\">platform<\/h2>\n<h2 id=\"errno\">errno<\/h2>\n<h2 id=\"ctypes\">ctypes<\/h2>\n<hr>\n<h1 id=\"command-line-interface\">Command Line Interface<\/h1>\n<h2 id=\"argparse\">argparse<\/h2>\n<pre><code>import argparse\n<\/code><\/pre>\n<p>classes:<\/p>\n<pre><code># argparse.ArgumentParser(_AttributeHolder, _ActionsContainer)\nparser = argparse.ArgumentParser()\nprog -- The name of the program (default: sys.argv[0])\nusage -- A usage message (default: auto-generated from arguments)\ndescription -- A description of what the program does\nepilog -- Text following the argument descriptions\nparents -- Parsers whose arguments should be copied into this one\nformatter_class -- HelpFormatter class for printing help messages\nprefix_chars -- Characters that prefix optional arguments\nfromfile_prefix_chars -- Characters that prefix files containing additional arguments\nargument_default -- The default value for all arguments\nconflict_handler -- String indicating how to handle conflicts\nadd_help -- Add a -h\/-help option\n# methods:\nadd_argument_group(self, *args, **kwargs) # -&gt; argparse._ArgumentGroup\nadd_argument(self, *args, **kwargs)\nname or flags - Either a name or a list of option strings, e.g. foo or -f, --foo.\naction - The basic type of action to be taken when this argument is encountered at the command line.\nnargs - The number of command-line arguments that should be consumed.\nconst - A constant value required by some action and nargs selections.\ndefault - The value produced if the argument is absent from the command line.\ntype - The type to which the command-line argument should be converted.\nchoices - A container of the allowable values for the argument.\nrequired - Whether or not the command-line option may be omitted (optionals only).\nhelp - A brief description of what the argument does. # \u7528\u6765\u6253\u5370\u9ed8\u8ba4\u503c\uff1a%(default)s\nmetavar - A name for the argument in usage messages.\ndest - The name of the attribute to be added to the object returned by.\nadd_subparsers(self, **kwargs) # -&gt; argparse._SubParsersAction\nadd_mutually_exclusive_group(self, **kwargs)\nset_defaults(self, **kwargs)\nparse_args(self, args=None, namespace=None) # -&gt; argparse.Namespace\nparse_known_args(self, args=None, namespace=None) # -&gt; argparse.Namespace\nconvert_arg_line_to_args(self, arg_line)\nerror(self, message)\nexit(self, status=0, message=None)\nformat_help(self)\nformat_usage(self)\nformat_version(self)\nprint_help(self, file=None)\nprint_usage(self, file=None)\nprint_version(self, file=None)\nget_default(self, dest)\nregister(self, registry_name, value, object)\n# argparse._ArgumentGroup\n# methods:\nadd_argument(self, *args, **kwargs)\nadd_argument_group(self, *args, **kwargs)\nadd_mutually_exclusive_group(self, **kwargs)\nget_default(self, dest)\nregister(self, registry_name, value, object)\nset_defaults(self, **kwargs)\n# argparse._SubParsersAction\n# methods:\nadd_parser(self, name, **kwargs) # -&gt; argparse.ArgumentParser\n# HelpFormatter\n# Action\n<\/code><\/pre>\n<p>functions:<\/p>\n<p>data:<\/p>\n<h2 id=\"optparse\">optparse<\/h2>\n<h2 id=\"getpass\">getpass<\/h2>\n<p>getpass\u7528\u4e8e\u83b7\u53d6\u7528\u6237\u8f93\u5165\u7684\u5bc6\u7801\uff0c\u8f93\u5165\u65f6\u4e0d\u663e\u793a\u5b57\u7b26\uff0e<\/p>\n<pre><code>import getpass\n<\/code><\/pre>\n<h2 id=\"curses\">curses<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/crazy-canux\/python\/blob\/master\/python\/psl\/mycurses.py\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/crazy-canux\/python\/blob\/master\/python\/psl\/mycurses.py<\/a><\/p>\n<pre><code>import curses\n<\/code><\/pre>\n<h2 id=\"fileinput\">fileinput<\/h2>\n<hr>\n<h1 id=\"unixlinux-sytem\">Unix\/Linux sytem<\/h1>\n<h2 id=\"pwd\">pwd<\/h2>\n<pre><code>import pwd\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>\/\/ \u6839\u636e\u7528\u6237\u540d\u83b7\u53d6uid\u548cgid\npw = getpwnam(user)\npw.pw_uid\npw.pw_gid\ngetpwuid(uid)\n<\/code><\/pre>\n<h2 id=\"grp\">grp<\/h2>\n<pre><code>import grp\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>group = group.getgrnam(&lt;group_name&gt;)\ngroup.gr_name \/\/ \u8fd4\u56de\u7ec4\u540d\ngroup.gr_mem \/\/ \u8fd4\u56de\u8be5\u7ec4\u7684\u6240\u6709\u7528\u6237\n<\/code><\/pre>"},{"title":"PSL_GUI","link":"https:\/\/canuxcheng.com\/post\/psl_gui\/","pubDate":"Mon, 15 Aug 2016 10:28:54 +0000","guid":"https:\/\/canuxcheng.com\/post\/psl_gui\/","description":"<h1 id=\"gui\">GUI<\/h1>\n<h2 id=\"tkinter\">Tkinter<\/h2>\n<h2 id=\"ttk\">ttk<\/h2>\n<h2 id=\"tix\">Tix<\/h2>\n<h2 id=\"scrolledtext\">ScrolledText<\/h2>\n<h2 id=\"turtle\">turtle<\/h2>\n<hr>\n<h1 id=\"tpl\">TPL<\/h1>\n<p>\u76f8\u5173\u7684\u7b2c\u4e09\u65b9\u5e93<\/p>\n<h2 id=\"wxwidgets\">wxWidgets<\/h2>\n<p>python2\u7684\u5e93\u53ebwxPython.<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.wxpython.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.wxpython.org\/<\/a><\/p>\n<pre><code># Windows\u4e0b\u8f7d\u5b89\u88c5\u5305\u5b89\u88c5\u5373\u53ef\uff0e\n$ sudo apt-get install python-wxgtk2.8\n<\/code><\/pre>\n<p>python\uff13\u542f\u7528\u65b0\u7684\u9879\u76eephoneix.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/wxWidgets\/Phoenix\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/wxWidgets\/Phoenix<\/a><\/p>\n<h2 id=\"gtk\">gtk<\/h2>\n<pre><code>PyGTK\n<\/code><\/pre>\n<h2 id=\"qt\">qt<\/h2>\n<pre><code>PyQt\n<\/code><\/pre>"},{"title":"PSL_Misc","link":"https:\/\/canuxcheng.com\/post\/psl_misc\/","pubDate":"Mon, 15 Aug 2016 10:28:46 +0000","guid":"https:\/\/canuxcheng.com\/post\/psl_misc\/","description":"<h1 id=\"psl\">PSL<\/h1>\n<p>Python Standard Library: Python\u6807\u51c6\u5e93<\/p>\n<hr>\n<h1 id=\"internationalization\">Internationalization<\/h1>\n<h2 id=\"gettext\">gettext<\/h2>\n<h2 id=\"locale\">locale<\/h2>\n<hr>\n<h1 id=\"program-frameworks\">Program Frameworks<\/h1>\n<h2 id=\"cmd\">cmd<\/h2>\n<h2 id=\"shlex\">shlex<\/h2>\n<p>\u7c7bshell\u7684\u8bcd\u6cd5\u5206\u6790\uff0e<\/p>\n<p>classes:<\/p>\n<pre><code>shlex\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>split(s, comments=False, posix=True)\n# split(&quot;command **kwargs&quot;) -&gt; ['command', 'arg1', ...]\n<\/code><\/pre>\n<p>data:<\/p>\n<hr>\n<h1 id=\"custom-python-interpreters\">Custom Python Interpreters<\/h1>\n<h2 id=\"code\">code<\/h2>\n<h2 id=\"codeop\">codeop<\/h2>\n<hr>\n<h1 id=\"python-language-services\">Python Language Services<\/h1>\n<h2 id=\"keyword\">keyword<\/h2>\n<pre><code>import keyword\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>keyword.iskeyword(keyword) # x.__contains__(y) &lt;==&gt; y in x\n<\/code><\/pre>\n<p>data:<\/p>\n<pre><code>keyword.kwlist # \u8fd4\u56de\u6240\u6709\u5173\u952e\u5b57\u7684\u5217\u8868\n<\/code><\/pre>\n<h2 id=\"parser\">parser<\/h2>\n<h2 id=\"ast\">ast<\/h2>\n<h2 id=\"symtable\">symtable<\/h2>\n<h2 id=\"symbol\">symbol<\/h2>\n<h2 id=\"token\">token<\/h2>\n<h2 id=\"tokenize\">tokenize<\/h2>\n<h2 id=\"tabnanny\">tabnanny<\/h2>\n<h2 id=\"pyclbr\">pyclbr<\/h2>\n<h2 id=\"py_compile\">py_compile<\/h2>\n<h2 id=\"compileall\">compileall<\/h2>\n<h2 id=\"dis\">dis<\/h2>\n<h2 id=\"pickletools\">pickletools<\/h2>\n<hr>\n<h1 id=\"importing-modules\">Importing Modules<\/h1>\n<h2 id=\"imp\">imp<\/h2>\n<h2 id=\"importlib\">importlib<\/h2>\n<h2 id=\"zipimport\">zipimport<\/h2>\n<h2 id=\"pkgutil\">pkgutil<\/h2>\n<h2 id=\"modulefinder\">modulefinder<\/h2>\n<h2 id=\"runpy\">runpy<\/h2>\n<hr>\n<h1 id=\"miscellaneous-services\">Miscellaneous Services<\/h1>\n<h2 id=\"formatter\">formatter<\/h2>\n<h2 id=\"ihooks\">ihooks<\/h2>"},{"title":"PSL_Cryptographic","link":"https:\/\/canuxcheng.com\/post\/psl_cryptographic\/","pubDate":"Sun, 14 Aug 2016 21:15:14 +0000","guid":"https:\/\/canuxcheng.com\/post\/psl_cryptographic\/","description":"<h1 id=\"cryptographic-services\">Cryptographic Services<\/h1>\n<h2 id=\"hashlib\">hashlib<\/h2>\n<p>\u54c8\u5e0c\u7b97\u6cd5\u548c\u6458\u8981\u7b97\u6cd5\u6807\u51c6\u5e93\uff0c\u5c31\u662f\u628a\u4efb\u610f\u957f\u5ea6\u7684\u6570\u636e\u8f6c\u6362\u4e3a\u4e00\u4e2a\u957f\u5ea6\u56fa\u5b9a\u7684\u6570\u636e\u4e32\uff0e<\/p>\n<p>MD5: Message Digest Algorithm 5.<\/p>\n<p>SHA1: Secure Hash Algorithm.<\/p>\n<pre><code>import hashlib\n<\/code><\/pre>\n<p>classes:<\/p>\n<pre><code># methods:\n# \u54c8\u5e0c\u5bf9\u8c61\u6709\u4e0b\u5217\u65b9\u6cd5\uff1a\nupdate(arg) # \u66f4\u65b0\u5b57\u7b26\u4e32\nmd5.update('string or read from a file') # \u653e\u5165\u9700\u8981\u8f6c\u6362\u7684\u5185\u5bb9\ndigest() # \u5b57\u7b26\u4e32\nhexdigest() # \u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\nmd5.hexdigest() # \u83b7\u53d6md5\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\ncopy() # \u590d\u5236\u54c8\u5e0c\u5bf9\u8c61\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code># \u4e0b\u7c7b\u51fd\u6570\u90fd\u8fd4\u56de\u54c8\u5e0c\u5bf9\u8c61\nnew(name, string='')\nmd5()\nmd5 = hashlib.md5() # \u521b\u5efa\u4e00\u4e2amd5\u7684hash\u5bf9\u8c61\nsha1()\nsha224()\nsha256()\nsha384()\nsha512()\n<\/code><\/pre>\n<h2 id=\"hmac\">hmac<\/h2>\n<h2 id=\"secrets\">secrets<\/h2>\n<hr>\n<h1 id=\"tpl\">TPL<\/h1>\n<p>\u76f8\u5173\u7684\u7b2c\u4e09\u65b9\u5e93<\/p>\n<h2 id=\"pycrypto\">pycrypto<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/dlitz\/pycrypto\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/dlitz\/pycrypto<\/a><\/p>\n<p>windows\u9700\u8981MS Visual C++ compiler for python2.7.<\/p>\n<pre><code>$ pip install pycrypto\n<\/code><\/pre>\n<h2 id=\"ecdsa\">ecdsa<\/h2>\n<p>pure-python ECDSA signature\/verification<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/warner\/python-ecdsa\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/warner\/python-ecdsa<\/a><\/p>\n<pre><code>$ pip install ecdsa\n<\/code><\/pre>\n<h2 id=\"pygpgme\">pygpgme<\/h2>\n<p><a class=\"link\" href=\"https:\/\/pypi.python.org\/pypi\/pygpgme\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/pypi.python.org\/pypi\/pygpgme<\/a><\/p>\n<p>A Python wrapper for the GPGME library.<\/p>\n<p>Windows\u5b89\u88c5\u5931\u8d25\uff1f<\/p>\n<pre><code># \u9700\u8981\u5148\u5b89\u88c5gpgme\u7684\u5f00\u53d1\u5e93\n$ sudo apt-get install libgpgme11-dev\n$ pip install pygpgme\n<\/code><\/pre>"},{"title":"PSL_Data","link":"https:\/\/canuxcheng.com\/post\/psl_data\/","pubDate":"Sun, 14 Aug 2016 20:57:36 +0000","guid":"https:\/\/canuxcheng.com\/post\/psl_data\/","description":"<h1 id=\"text-processing-services\">Text Processing Services<\/h1>\n<h2 id=\"string\">string<\/h2>\n<pre><code>import string\n<\/code><\/pre>\n<p>classes:<\/p>\n<p>functions:<\/p>\n<p>data:<\/p>\n<pre><code>ascii_letters\nascii_lowercase\nascii_uppercase\ndigits\n...\n<\/code><\/pre>\n<h2 id=\"re\">re<\/h2>\n<pre><code>import re\n<\/code><\/pre>\n<p>classes:<\/p>\n<p>functions:<\/p>\n<pre><code>compile(pattern, flags=0)\nescape(pattern)\nfindall(pattern, string, flags=0)\nfinditer(pattern, string, flags=0)\nmatch(pattern, string, flags=0) # if not match, return None, else return object.\nsearch(pattern, string, flags=0)\npurge()\nsplit(pattern, string, maxsplit=0, flags=0) # \u6839\u636epattern\u5206\u5272string,\u8fd4\u56de\u5206\u5272\u540e\u7684\u5217\u8868\uff0e\nsub(pattern, repl, string, count=0, flags=0)\nsubn(pattern, repl, string, count=0, flags=0)\ntemplate(pattern, flags=0)\n<\/code><\/pre>\n<p>data:<\/p>\n<pre><code># flags:\nIGNORECASE # \u5927\u5c0f\u5199\u4e0d\u654f\u611f\nLOCALE\nMULTILINE\nDOTALL\nVERBOSE\nUNICODE\n<\/code><\/pre>\n<p>modules:<\/p>\n<pre><code># sre_parse module\n# functions:\nsre_parse.parse(str, flags=0, pattern=None)\nsre_parse.expand_template(template, match)\nsre_parse.parse_template(source, pattern)\n# sre_compile module\n# functions:\nsre_compile.compile(p, flags=0)\nsre_compile.isstring(obj)\n<\/code><\/pre>\n<h2 id=\"stringprep\">stringprep<\/h2>\n<h2 id=\"difflib\">difflib<\/h2>\n<h2 id=\"textwrap\">textwrap<\/h2>\n<pre><code>import textwrap\n<\/code><\/pre>\n<h2 id=\"unicodedata\">unicodedata<\/h2>\n<h2 id=\"readline\">readline<\/h2>\n<h2 id=\"rlcompleter\">rlcompleter<\/h2>\n<hr>\n<h1 id=\"binary-data-services\">Binary Data Services<\/h1>\n<h2 id=\"codecs\">codecs<\/h2>\n<p>python\u7684\u7f16\u7801\u89e3\u7801\u5668coder\/decoder\u3002<\/p>\n<pre><code>import codecs\n# \u4f7f\u7528\u6ce8\u518c\u540d\u4e3aencoding\u7684\u7f16\u7801\u5668\u7f16\u7801obj\uff0cencoding\u9ed8\u8ba4\u4e3aascii\u3002\n# encode\u5c06unicode\u7f16\u7801\u7684obj\u7f16\u7801\u6210encoding\u7f16\u7801\u5bf9\u5e94\u7684\u5b57\u8282\u5e8f\u5217\uff0e\ncodecs.encode(obj, [encoding[,errors]])\ncodecs.encode(u'hello world', 'utf-8') # \u7f16\u7801\u6210utf-8\u5b57\u8282\u5e8f\uff0e\n# \u4f7f\u7528\u6ce8\u518c\u540d\u4e3aencoding\u7684\u89e3\u7801\u5668\u89e3\u7801obj\uff0cencoding\u9ed8\u8ba4\u662fascii\u3002\n# decode\u5c06\u539f\u6765\u6309\u7167encoding\u7f16\u7801\u7684obj\u89e3\u7801\u6210unicode\u5b57\u7b26\u4e32.\ncodecs.decode(obj, [encoding[,errors]])\ncodecs.decode(obj, 'utf-8') # \u5c06utf-8\u7f16\u7801\u7684obj\u89e3\u7801\u6210unicode.\n# encoding\u53d6\u4e0b\u9762\u503c:\n# ascii\u662f\u9ed8\u8ba4\u503c,gb2312, gbk, gb18030, utf-8, utf-16\n# ascii\u5229\u7528\u4e00\u4e2a\u5b57\u8282\u628a\u5b57\u7b26\u8f6c\u6362\u6210\u6570\u5b57\uff0e\n# unicode\u5229\u7528\u591a\u5b57\u8282\u8f6c\u6362\uff0c\u652f\u6301\u591a\u79cd\u7f16\u7801\u65b9\u5f0f\uff0cutf-8, uft-16.\n# errors\u53d6\u4e0b\u9762\u503c\uff1a\n# strict, \u9ed8\u8ba4\u503c\uff0c\u629b\u51faUnicodeError\u5f02\u5e38\u3002\n# ignore\n# replace\n# xmlcharrefreplace\n# backslashreplace\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>open(filename, mode='rb', encoding=None, errors='strict', buffering=1)\n<\/code><\/pre>\n<p>data:<\/p>\n<h2 id=\"struct\">struct<\/h2>\n<pre><code>import struct\n# struct\u6a21\u5757\u63d0\u4f9b\u4e86\u5c06C\u8bed\u8a00\u7684struct\u8f6c\u6362\u6210python\u7684bytes\u5bf9\u8c61\u7684\u529f\u80fd\uff0e\n# \u4e5f\u53ef\u4ee5\u5c06bytes\u5bf9\u8c61\u8f6c\u6362\u6210C\u8bed\u8a00\u7684struct.\n<\/code><\/pre>\n<hr>\n<h1 id=\"data-types\">Data Types<\/h1>\n<h2 id=\"datetime\">datetime<\/h2>\n<pre><code>import datetime\n<\/code><\/pre>\n<p>classes:<\/p>\n<pre><code># datetime.date\ndate(year, month, day)\n# methods:\nctime(...)\n...\n# data descriptors:\nday\nmonth\nyear\n# datetime.datetime(datetime.date)\ndatetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])\n# methods:\ndatetime.datetime.strptime(string, format)\nformat_datetime = datetime.datetime.strptime('20160824161431', '%Y%m%d%H%M%S') # return: datetime.datetime(2016, 8, 24, 16, 14, 31)\nformat_datetime = datetime.datetime.strptime('24 August 2016 16:14:31', '%Y%m%d%H%M%S') # return: datetime.datetime(2016, 8, 24, 16, 14, 31)\ndatetime.datetime.strftime(format[, tuple])\nstring_datetime = format_datetime.strftime(&quot;%d %B %Y %H:%M:%S&quot;) # return: '24 August 2016 16:14:31'\ndatetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') # return: '2017-02-07 23:07:32'\nstr(datetime.datetime.now())\ndatetime.datetime.now().strftime('%Y%m%d%H%M%S') # \u5f53\u524d\u65f6\u95f4\u6233\n# datetime.time\n# datetime.timedelta\n# datetime.tzinfo\n<\/code><\/pre>\n<p>data:<\/p>\n<pre><code>MAXYEAR = 9999\nMINYEAR = 1\n<\/code><\/pre>\n<h2 id=\"calendar\">calendar<\/h2>\n<h2 id=\"zoneinfo\">zoneinfo<\/h2>\n<h2 id=\"collections\">collections<\/h2>\n<pre><code>import collections\n<\/code><\/pre>\n<p>classes:<\/p>\n<pre><code>Callable\n# \u7528\u4e8e\u68c0\u67e5\u5bf9\u8c61\u662f\u5426\u53ef\u8c03\u7528\nContainer\n# \u7528\u4e8e\u68c0\u67e5\u5bf9\u8c61\u662f\u5426\u662f\u5bb9\u5668\u7c7b\u578b\nCounter(iterable_or_mapping=None, **kwds)\n# \u8fd4\u56de\u4e00\u4e2aCounter\u7c7b\u578b\u7684\u5b9e\u4f8b\uff0c\u7c7b\u4f3c\u4e8edict\uff0c\u7edf\u8ba1\u5143\u7d20\u51fa\u73b0\u7684\u6b21\u6570\nHashableDict(mapping=None, **kwargs)\nIterable(iterable=None)\n<\/code><\/pre>\n<p>Iterator(iterable=None)<\/p>\n<p>functions:<\/p>\n<pre><code>namedtuple(typename[, field_names[, verbose[, rename]]]) # \u8fd4\u56de\u4e00\u4e2anamedtuple\u7c7b\u578b\u7684\u5b9e\u4f8b\uff0c\u7c7b\u4f3c\u4e8eC\u8bed\u8a00\u7684struct\nOrderedDict([items]) # \u8fd4\u56de\u4e00\u4e2aOrderedDict\u7c7b\u578b\u7684\u5b9e\u4f8b\uff0c\u7c7b\u4f3c\u4e8edict\uff0c\u4f46\u662f\u6709\u5e8f\nChainMap(*maps) # \u8fd4\u56de\u4e00\u4e2aChainMap\u7c7b\u578b\u7684\u5b9e\u4f8b\uff0c\u7c7b\u4f3c\u4e8edict\uff0c\u4f46\u662f\u53ef\u4ee5\u5408\u5e76\u591a\u4e2a\u5b57\u5178\nUserDict([mapping]) # \u8fd4\u56de\u4e00\u4e2aUserDict\u7c7b\u578b\u7684\u5b9e\u4f8b\uff0c\u7c7b\u4f3c\u4e8edict\uff0c\u4f46\u662f\u53ef\u4ee5\u7ee7\u627f\nUserList([sequence]) # \u8fd4\u56de\u4e00\u4e2aUserList\u7c7b\u578b\u7684\u5b9e\u4f8b\uff0c\u7c7b\u4f3c\u4e8elist\uff0c\u4f46\u662f\u53ef\u4ee5\u7ee7\u627f\nUserString([string]) # \u8fd4\u56de\u4e00\u4e2aUserString\u7c7b\u578b\u7684\u5b9e\u4f8b\uff0c\u7c7b\u4f3c\u4e8estr\uff0c\u4f46\u662f\u53ef\u4ee5\u7ee7\u627f\n<\/code><\/pre>\n<h2 id=\"heapq\">heapq<\/h2>\n<p>heapq\u6a21\u5757\u63d0\u4f9b\u4e86\u5806\u961f\u5217\u7b97\u6cd5\uff0c\u4e5f\u79f0\u4e3a\u4f18\u5148\u961f\u5217\u7b97\u6cd5\uff0e<\/p>\n<pre><code>import heapq\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>heappush(heap, item) # \u628aitem\u653e\u5230\u5806\u4e2d\nheappop(heap) # \u5f39\u51fa\u5806\u9876\u5143\u7d20, \u4e5f\u5c31\u662f\u6700\u5c0f\u7684\u5143\u7d20\n<\/code><\/pre>\n<h2 id=\"bisect\">bisect<\/h2>\n<h2 id=\"array\">array<\/h2>\n<h2 id=\"weakref\">weakref<\/h2>\n<h2 id=\"types\">types<\/h2>\n<h2 id=\"copy\">copy<\/h2>\n<p>copy\u548cdeepcopy\u90fd\u53ea\u62f7\u8d1d\u5bf9\u8c61\u7684\u7c7b\u578b\u548c\u6570\u503c\uff0c\u4e0d\u62f7\u8d1d\u5bf9\u8c61\u7684ID.\u4e5f\u5c31\u662f==\u8fd0\u7b97\u4e3aTrue, is(id())\u8fd0\u7b97\u4e3aFalse.<\/p>\n<pre><code>import copy\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>copy.copy(x) # \u6d45\u590d\u5236, \u53ea\u62f7\u8d1d\u7236\u5bf9\u8c61\uff0c\u4e0d\u62f7\u8d1d\u5185\u90e8\u7684\u5b50\u5bf9\u8c61.\ncopy.deepcopy(x, memo=None, _nil=[]) # \u6df1\u590d\u5236, \u62f7\u8d1d\u7236\u5bf9\u8c61\u548c\u5185\u90e8\u7684\u5b50\u5bf9\u8c61\n<\/code><\/pre>\n<h2 id=\"pprint\">pprint<\/h2>\n<h2 id=\"reprlib\">reprlib<\/h2>\n<h2 id=\"enum\">enum<\/h2>\n<pre><code>import enum\n<\/code><\/pre>\n<h2 id=\"graphlib\">graphlib<\/h2>\n<hr>\n<h1 id=\"data-persistence\">Data Persistence<\/h1>\n<p>pickle\/cPickle\/marshal\u63d0\u4f9b\u5bf9\u8c61\u7684\u5e8f\u5217\u5316\u64cd\u4f5c\uff0e<\/p>\n<p>gdb\u76f8\u5173\u7684\u6a21\u5757anydbm\/whichdb\/dbm\/gdbm\/dumbdbm\u63d0\u4f9b\u7c7b\u4f3c\u5b57\u5178\u548c\u6587\u4ef6\u7684\u5bf9\u8c61\uff0e<\/p>\n<p>shelve\u96c6\u5408\u4e86\u4ee5\u4e0a\u4e24\u8005\u7684\u529f\u80fd\uff0e<\/p>\n<h2 id=\"pickle\">pickle<\/h2>\n<p>pickle\u6a21\u5757\u63d0\u4f9b\u4e86\u5bf9\u8c61\u7684\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u64cd\u4f5c\uff0e<\/p>\n<pre><code>import pickle\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>dump(obj, file[, protocol, *, fix_imports, buffer_callback] # \u5c06\u5bf9\u8c61obj\u5e8f\u5217\u5316\u5230\u6587\u4ef6file\u4e2d\ndumps(obj[, protocol, *, fix_imports, buffer_callback] # \u5c06\u5bf9\u8c61obj\u5e8f\u5217\u5316\u4e3a\u5b57\u8282\u4e32\nload(file[, *, encoding, errors, buffers]) # \u4ece\u6587\u4ef6file\u4e2d\u53cd\u5e8f\u5217\u5316\u5bf9\u8c61\nloads(data[, *, encoding, errors, buffers]) # \u4ece\u5b57\u8282\u4e32data\u4e2d\u53cd\u5e8f\u5217\u5316\u5bf9\u8c61\n<\/code><\/pre>\n<p>data:<\/p>\n<pre><code>HIGHEST_PROTOCOL = 2\n<\/code><\/pre>\n<h2 id=\"marshal\">marshal<\/h2>\n<h2 id=\"shelve\">shelve<\/h2>\n<pre><code>import shelve\nwith shelve.open(f, flag='n', writeback=True) as f:\nr\/w: \u4e0d\u5b58\u5728\u62a5\u9519\nc: read-write to new\/existing\uff0c\u4e0d\u5b58\u5728\u521b\u5efa\nn: read-write to new. \u603b\u662f\u521b\u5efa\u65b0\u7684\n<\/code><\/pre>\n<h2 id=\"copyreg\">copyreg<\/h2>\n<h2 id=\"dbm\">dbm<\/h2>\n<h2 id=\"sqlite3\">sqlite3<\/h2>\n<p>python\u8bbf\u95ee\u6570\u636e\u5e93\u4e24\u79cd\u65b9\u5f0f\uff1a<\/p>\n<ol>\n<li>ORM<\/li>\n<li>DB-API<\/li>\n<\/ol>\n<p>ORM\u662f\u5bf9\u8c61-\u5173\u7cfb\u7ba1\u7406\u5668\uff0c\u76f8\u5173\u6a21\u5757\u6709SQLAlchemy, SQLObject.<\/p>\n<p>DB-API\u53c2\u8003PEP248\/249\u5b9a\u4e49\u4e86Database\u7684API\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.python.org\/dev\/peps\/pep-0249\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.python.org\/dev\/peps\/pep-0249\/<\/a><\/p>\n<pre><code>import sqlite3\n<\/code><\/pre>\n<p>classes:<\/p>\n<pre><code># sqlite3.Connection\n# methods:\nclose(...)\ncommit(...)\ncursor(...)\nexecute(...)\n...\n# sqlite3.Cursor\n# methods:\nclose(...)\n...\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>adapt(obj, protocol, alternate)\nconnect(database[, timeout, isolation_level, detect_types, factory])\n...\n<\/code><\/pre>\n<p>data:<\/p>\n<hr>\n<h1 id=\"data-compression-and-archiving\">Data Compression and Archiving<\/h1>\n<h2 id=\"gzip\">gzip<\/h2>\n<h2 id=\"bz2\">bz2<\/h2>\n<h2 id=\"zlib\">zlib<\/h2>\n<h2 id=\"zipfile\">zipfile<\/h2>\n<h2 id=\"tarfile\">tarfile<\/h2>\n<h2 id=\"lzma\">lzma<\/h2>\n<hr>"},{"title":"PSL_File","link":"https:\/\/canuxcheng.com\/post\/psl_file\/","pubDate":"Sun, 14 Aug 2016 20:51:28 +0000","guid":"https:\/\/canuxcheng.com\/post\/psl_file\/","description":"<h1 id=\"file-and-directory-access\">File and Directory Access<\/h1>\n<h2 id=\"ospath\">os.path<\/h2>\n<p>windows\u7684\u8def\u5f84\u8981\u5199\u6210\uff1a<\/p>\n<pre><code>C:\\\\test\\\\sub\\\\\nimport os\n<\/code><\/pre>\n<p>function:<\/p>\n<pre><code>os.path.expanduser(path) # \u628apath\u4e2d~\u6216~user\u6269\u5c55\u6210\u7edd\u5bf9\u8def\u5f84 expanduser(&quot;~\/src&quot;) -&gt; \/home\/user\/src\nos.path.expandvars(path) # \u628apath\u4e2d\u7684shell\u53d8\u91cf$var \u6216 ${var} \u8fd8\u539f\uff0e\nos.path.dirname(filename) # \u8fd4\u56defilename\u7684\u8def\u5f84 dirname(&quot;\/home\/user\/file.py&quot;) -&gt; \/home\/user\nos.path.join(a, *p) # \u62fc\u7ed3\u4e00\u4e2a\u5b8c\u6574\u7684\u8def\u5f84\u3000\nos.path.join(a, os.pardir) # \u8fd4\u56de\u4e0a\u7ea7\u76ee\u5f55\u7684\u8def\u5f84\nos.path.realpath(filename) # \u8fd4\u56defilename\u7684\u771f\u5b9e\u8def\u5f84+\u6587\u4ef6\u540d realpath('__file__')\nos.path.abspath(path) # \u8fd4\u56de\u7edd\u5bf9\u8def\u5f84, os.path.abspath('__file__')\nos.path.splitext(p) # \u5206\u89e3\u8def\u5f84\u548c\u6269\u5c55\u540d\u8fd4\u56de\u7ec4\u6210\u7684\u5143\u7ec4\uff0c\/home\/user\/test.py -&gt; (&quot;\/home\/user\/test&quot;, &quot;.py&quot;)\nos.path.basename(p) # \u8fd4\u56de\u6700\u540e\u4e00\u4e2a\u7ec4\u4ef6\u540d\uff0c\u4e5f\u5c31\u662f\u6587\u4ef6\u540d \/home\/user\/test.py -&gt; test.py\nos.path.getsize(filename) # \u8fd4\u56de\u6587\u4ef6\u5927\u5c0f\nos.path.exists(path) # \u5224\u65adpath(\u6587\u4ef6\u6216\u76ee\u5f55)\u662f\u5426\u5b58\u5728\nos.path.isfile(path) # \u5224\u65adpath\u662f\u5426\u662f\u5e38\u89c4\u6587\u4ef6\n<\/code><\/pre>\n<h2 id=\"pathlib\">pathlib<\/h2>\n<p>new in python3.4<\/p>\n<pre><code>from pathlib import Path\nfrom pathlib import PurePosixPath\nfrom pathlib import PureWindowsPath\n<\/code><\/pre>\n<h2 id=\"stat\">stat<\/h2>\n<h2 id=\"filecmp\">filecmp<\/h2>\n<h2 id=\"fnmatch\">fnmatch<\/h2>\n<h2 id=\"linecache\">linecache<\/h2>\n<h2 id=\"glob\">glob<\/h2>\n<p>functions:<\/p>\n<pre><code>glob(pathname) # \u8fd4\u56de\u5339\u914dpathname\u8def\u5f84\u4e0b\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u6240\u6709\u6587\u4ef6\u7ec4\u6210\u7684\u5217\u8868\niglob(pathname) # \u540c\u4e0a\uff0c\u8fd4\u56degenerator.\n<\/code><\/pre>\n<h2 id=\"shutil\">shutil<\/h2>\n<p>Utility functions for copying and archiving files and directory trees.<\/p>\n<pre><code>import shutil\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>copy(src, dst)\ncopy2(src, dst)\n...\nrmtree(path, ignore_errors=False, onerror=None) # \u5220\u9664\u6307\u5b9a\u7684\u76ee\u5f55,path\u4e0d\u80fd\u662f\u6587\u4ef6\uff0e\nunregister_archive_format(name)\nmove(src, dst)\n...\n<\/code><\/pre>\n<h2 id=\"tempfile\">tempfile<\/h2>\n<hr>\n<h1 id=\"file-formats\">File Formats<\/h1>\n<h2 id=\"csv\">csv<\/h2>\n<pre><code>import csv\n<\/code><\/pre>\n<p>classes:<\/p>\n<pre><code># csv.DictReader\nDictReader(self, f, fieldnames=None, restkey=None, restval=None, dialect='excel', *args, **kwds)\n# methods\nnext()\n# csv.DictWriter\nDictWriter(self, f, fieldnames, restval='', extrasaction='raise', dialect='excel', *args, **kwargs)\n# mthods\nwriteheader()\nwriterow(rowdict)\nwriterows(rowdicts)\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>\/\/ \u8fd4\u56deDictReader\u5bf9\u8c61\nreader(iterable, dialect='excel', **kwargs)\n\/\/ \u8fd4\u56deDictWriter\u5bf9\u8c61\nwriter(fileobj, dialect='excel', **kwargs)\n<\/code><\/pre>\n<p>data:<\/p>\n<h2 id=\"configparser\">configparser<\/h2>\n<p>\u4e00\u822c\u7528\u6765\u5904\u7406*.ini\u6587\u4ef6\uff0c\u683c\u5f0f\u4e3a\uff1a<\/p>\n<pre><code>[section]\noption-key = option-value\n<\/code><\/pre>\n<p>\u5bfc\u5165\uff1a<\/p>\n<pre><code>import ConfigParser\n<\/code><\/pre>\n<p>classes:<\/p>\n<pre><code>ConfigParser.ConfigParser(defaults=None)\n# methods:\nread(filenames) # \u8bfb\u53d6ini\u6587\u4ef6\nsections() # \u83b7\u53d6\u6240\u6709section\noptions(section) # \u83b7\u53d6section\u7684\u6240\u6709option\nget(section, option, raw=False, vars=None) # \u8fd4\u56de\u5b57\u7b26\u4e32\ngetint(section, options)\ngetfloat(section, options)\ngetboolean(section, options) # \u5927\u5c0f\u5199\u90fd\u53ef\u4ee5:0\/1, false\/true, no\/yes, off\/on\nset(section, option, value)\nhas_section(section)\nhas_option(section, option)\nremove_section(section)\nremove_option(section, option)\nwrite(fp)\n<\/code><\/pre>\n<p>issue:<\/p>\n<pre><code>\u9ed8\u8ba4\u662f\u5168\u90e8\u5c0f\u5199\u5199\u5165.\nconfig = ConfigParser.ConfigParser(allow_no_value=True)\nconfig.optionxform =str # \u539f\u6837\u5199\u5165\nfrom configparser import ConfigParser, ExtendedInterpolation\n<\/code><\/pre>\n<p>\u53d8\u91cf:<\/p>\n<pre><code>\/\/ \u9ed8\u8ba4interpolation\u53ea\u652f\u6301section\u4e4b\u95f4\u53d8\u91cf\n[section1]\n1var1 = \/opt\n1var2 = %(1var1)s\/test\n\/\/ \u6269\u5c55interpolation\u652f\u6301section\u53d8\u91cf\u5f15\u7528\nconfig = ConfigParser(interpolation=ExtendedInterpolation())\n[section1]\n1var1 = \/opt\n[section2]\n2var1 = ${section1:1var1}\/test\n<\/code><\/pre>\n<h2 id=\"tomllib\">tomllib<\/h2>\n<h2 id=\"netrc\">netrc<\/h2>\n<h2 id=\"plistlib\">plistlib<\/h2>\n<hr>"},{"title":"PSL_Math","link":"https:\/\/canuxcheng.com\/post\/psl_math\/","pubDate":"Fri, 12 Aug 2016 16:56:45 +0000","guid":"https:\/\/canuxcheng.com\/post\/psl_math\/","description":"<h1 id=\"numeric-and-mathematical-modules\">Numeric and Mathematical Modules<\/h1>\n<h2 id=\"random\">random<\/h2>\n<pre><code>import random\n<\/code><\/pre>\n<p>classes:<\/p>\n<pre><code># random.Random\nRandom()\n# methods:\nseed([self,], a=None)\nrandint(a, b) # \u968f\u673a\u4e00\u4e2a[a,b]\u4e2d\u7684\u6574\u6570\uff0e\nchoice(self, seq) # \u4eceseq\u4e2d\u968f\u673a\u9009\u62e9\u4e00\u4e2a\u5143\u7d20\nuniform(self, a, b) # \u968f\u673a\u4e00\u4e2a[a,b]\u4e2d\u7684\u6d6e\u70b9\u6570\uff0e\nsample(self, population, k)\nrandint(self, a, b)\nrandrange(self, start, stop=None, step=1, _int=&lt;type 'int'&gt;, _maxwidth=9007199254740992L)\n# random.SystemRandom(Random)\nSystemRandom(Random)\n# random.WichmannHill(Random)\nWichmannHill(Random)\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>random(self) # \u968f\u673a\u4e00\u4e2a\u5c0f\u4e8e\uff11\u7684\u6570\uff0e\n# \u6240\u6709Random\u7c7b\u7684methods\u4e5f\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\uff0e\nseed(self, a=None) # \u8bbe\u7f6e\u968f\u673a\u6570\u79cd\u5b50\uff0e\nuniform(self, a, b) # \u968f\u673a\u4e00\u4e2a[a,b]\u4e2d\u7684\u6d6e\u70b9\u6570\uff0e\n<\/code><\/pre>\n<h2 id=\"fractions\">fractions<\/h2>\n<h2 id=\"cmath\">cmath<\/h2>\n<h2 id=\"math\">math<\/h2>\n<h2 id=\"numbers\">numbers<\/h2>\n<h2 id=\"decimal\">decimal<\/h2>\n<hr>\n<h1 id=\"functional-programming-modules\">Functional Programming Modules<\/h1>\n<h2 id=\"functools\">functools<\/h2>\n<p>\u51fd\u6570\u5f0f\u7f16\u7a0b\u76f8\u5173\u7684\u6a21\u5757<\/p>\n<pre><code>import functools\n<\/code><\/pre>\n<p>classes:<\/p>\n<pre><code># functools.partial\npartial(func, *args, **keywords) # \u8fd4\u56defunctools.partial\u7c7b\u578b\u7684\u5bf9\u8c61, partial\u662ffunctools\u5185\u7f6e\u7684\u504f\u51fd\u6570\u7c7b\u7c7b\u578b.\nRED = partial(lambda content, color: color + str(content) + Fore.RESET, color=Fore.RED)\nRED(&quot;show me red&quot;) == lambda content, color: Fore.RED + str(&quot;show me red&quot;) + Fore.RESET\n# \u76f8\u5f53\u4e8e\u901a\u8fc7partial\u4f20\u4e00\u4e2a\u53c2\u6570\u7ed9func\uff0c\u7136\u540e\u5269\u4e0b\u7684\u53c2\u6570\u901a\u8fc7\u8fd4\u56de\u7684\u504f\u51fd\u6570\u4f20\u5165\uff0e\u8fd9\u6837\u53ef\u4ee5\u56fa\u5316\u4e00\u90e8\u5206\u53c2\u6570\uff0e\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>reduce(function, sequence[, initial]) # \u5982\u679cinitial\u5b58\u5728\uff0c\u5c31\u628ainitial\u4f5c\u4e3afunction\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\uff0c\u5982\u679cfunction\u6709\u4e24\u4e2a\u53c2\u6570\uff0c\u5c31\u518d\u4ecesequence\u53d6\u7b2c\u4e00\u4e2a\u5143\u7d20\u4f5c\u4e3afunction\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\uff0c\u7136\u540e\u8c03\u7528function\uff0c\u8fd4\u56de\u7684\u7ed3\u679c\u4f5c\u4e3afunction\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\uff0c\u518d\u7ee7\u7eed\u4ecesequence\u83b7\u53d6\u5143\u7d20\u4f5c\u4e3a\u53c2\u6570\uff0c\u7ee7\u7eed\u8c03\u7528function, \u76f4\u5230sequence\u4e3a\u7a7a\uff0e\nreduce(lambda x,y: x+y, range(5))\ncmp_to_key(mycmp)\ntotal_ordering(cls)\nupdate_wrapper(wrapper, wrapped, assigned=('__module__', '__name__', '__doc__'), updated=('__dict__',))\nwraps(wrapped, assigned=('__module__', '__name__', '__doc__'), updated=('__dict__',))\n# example:\ndef deco(func):\n@wraps(func):\ndef wrapper(*args, **kwargs):\n&quot;&quot;&quot;Docs for wrapper.&quot;&quot;&quot;\npass\n@deco\ndef foo()\n&quot;&quot;&quot;Docs for new function.&quot;&quot;&quot;\npass\n# \u4e0d\u7528wraps\u88ab\u88c5\u9970\u7684\u51fd\u6570foo\u7684\u5c5e\u6027\u5176\u5b9e\u662f\u539f\u6765\u51fd\u6570\u7684\u5c5e\u6027\uff0c\u4e5f\u5c31\u662fwrapper\u7684\u5c5e\u6027\n# \u7528\u4e86wraps\u88ab\u88c5\u9970\u7684\u51fd\u6570foo\u7684\u5c5e\u6027\u5c31\u662ffoo\u81ea\u5df1\u7684\u5c5e\u6027\uff0e\nprint foo.__name__\nprint foo.__doc__\n<\/code><\/pre>\n<h2 id=\"operator\">operator<\/h2>\n<p>\u64cd\u4f5c\u7b26\u76f8\u5173\u7684\u6a21\u5757<\/p>\n<pre><code>import operator\n<\/code><\/pre>\n<h2 id=\"itertools\">itertools<\/h2>\n<pre><code>import itertools\n<\/code><\/pre>\n<hr>"},{"title":"PSL_Multimedia","link":"https:\/\/canuxcheng.com\/post\/psl_multimedia\/","pubDate":"Fri, 12 Aug 2016 15:51:56 +0000","guid":"https:\/\/canuxcheng.com\/post\/psl_multimedia\/","description":"<h1 id=\"multimedia-services\">Multimedia Services<\/h1>\n<h2 id=\"audioop\">audioop<\/h2>\n<h2 id=\"aifc\">aifc<\/h2>\n<h2 id=\"sunau\">sunau<\/h2>\n<h2 id=\"wave\">wave<\/h2>\n<h2 id=\"chunk\">chunk<\/h2>\n<h2 id=\"colorsys\">colorsys<\/h2>\n<h2 id=\"imghdr\">imghdr<\/h2>\n<h2 id=\"sndhdr\">sndhdr<\/h2>\n<h2 id=\"ossaudiodev\">ossaudiodev<\/h2>\n<hr>"},{"title":"PSL_Network","link":"https:\/\/canuxcheng.com\/post\/psl_network\/","pubDate":"Fri, 12 Aug 2016 14:21:36 +0000","guid":"https:\/\/canuxcheng.com\/post\/psl_network\/","description":"<h1 id=\"internet-protocols-and-support\">Internet Protocols and Support<\/h1>\n<p>socketserver\/http\/ftp\u53c2\u8003<a class=\"link\" href=\"https:\/\/super-devops.readthedocs.io\/en\/latest\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/super-devops.readthedocs.io\/en\/latest\/<\/a>.<\/p>\n<p>pop,imap\/smtp\u53c2\u8003<a class=\"link\" href=\"https:\/\/super-devops.readthedocs.io\/en\/latest\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/super-devops.readthedocs.io\/en\/latest\/<\/a>.<\/p>\n<h2 id=\"urllib\">urllib<\/h2>\n<p>urllib.request<\/p>\n<p>urllib.respponse<\/p>\n<p>urllib.parse<\/p>\n<pre><code>from urllib.parse import urlparse\nfrom urllib.parse import urljoin\n<\/code><\/pre>\n<p>urllib.error<\/p>\n<p>urllib.robotparser<\/p>\n<h2 id=\"ipaddress\">ipaddress<\/h2>\n<h2 id=\"webbrowser\">webbrowser<\/h2>\n<h2 id=\"cgi\">cgi<\/h2>\n<h2 id=\"cgitb\">cgitb<\/h2>\n<h2 id=\"wsgiref\">wsgiref<\/h2>\n<h2 id=\"xmlrpc\">xmlrpc<\/h2>\n<h2 id=\"socketserver\">socketserver<\/h2>\n<h2 id=\"nntplib\">nntplib<\/h2>\n<p>network news transfer protocol<\/p>\n<pre><code>import nntplib\n<\/code><\/pre>\n<h2 id=\"telnet\">telnet<\/h2>\n<pre><code>import telnetlib\n<\/code><\/pre>\n<hr>\n<h1 id=\"structured-markup-processing-tools\">Structured Markup Processing Tools<\/h1>\n<h2 id=\"html\">html<\/h2>\n<h2 id=\"xml\">xml<\/h2>\n<hr>\n<h1 id=\"internet-data-handling\">Internet Data Handling<\/h1>\n<h2 id=\"json\">json<\/h2>\n<p>http api(restful)\u4e00\u822c\u4f7f\u7528json\u683c\u5f0f\u7684\u6570\u636e\uff0e<\/p>\n<p>python\u548cjson\u6570\u636e\u7c7b\u578b\u5bf9\u5e94\u5173\u7cfb\u53c2\u8003WEB\/JSON.<\/p>\n<p>complex\u548cclass\/def\u4e0d\u80fd\u88ab\u7f16\u7801.<\/p>\n<pre><code>import json\n<\/code><\/pre>\n<p>classes:<\/p>\n<p>functions:<\/p>\n<pre><code># \u5c06\u8f6c\u6362\u540e\u7684json\u683c\u5f0f\u5199\u5165\u6587\u4ef6\ndump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, encoding='utf-8', default=None, sort_keys=False, **kw)\nwith open(file, 'w') as f:\njson.dump(dict_data, f)\n# \u5c06dict\u7c7b\u578b\u8f6c\u6362\u6210json\u683c\u5f0f\ndumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, encoding='utf-8', default=None, sort_keys=False, **kw)\njson_data = json.dumps(dict_data)\nindent=4 # \u5199\u5165\u81ea\u52a8\u7f29\u8fdb\uff14\u4e2a\u7a7a\u683c\n# \u5c06\u8bfb\u51fa\u7684\u6587\u4ef6(json\u683c\u5f0f)\u8f6c\u6362\u6210dict\nload(fp, encoding=None, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)\nwith open(file, 'r') as f:\ndict_data = json.load(f)\n# json\u7c7b\u578b\u53d8\u6210dict\u7c7b\u578b\nloads(s, encoding=None, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)\nresponse_dict = json.loads(response.content) # \u4f7f\u7528requests\u83b7\u53d6\u7684json\u6570\u636e,\u8f6c\u5316\u4e3adict\u7c7b\u578b\n<\/code><\/pre>\n<h2 id=\"base64\">base64<\/h2>\n<h2 id=\"mailcap\">mailcap<\/h2>\n<h2 id=\"mailbox\">mailbox<\/h2>\n<h2 id=\"minetypes\">minetypes<\/h2>\n<h2 id=\"binhex\">binhex<\/h2>\n<h2 id=\"binascii\">binascii<\/h2>\n<h2 id=\"quopri\">quopri<\/h2>\n<h2 id=\"uu\">uu<\/h2>"},{"title":"ReStructuredText","link":"https:\/\/canuxcheng.com\/post\/restructuredtext\/","pubDate":"Mon, 08 Aug 2016 13:39:38 +0000","guid":"https:\/\/canuxcheng.com\/post\/restructuredtext\/","description":"<h1 id=\"restructuredtext\">reStructuredText<\/h1>\n<p><a class=\"link\" href=\"http:\/\/docutils.sourceforge.net\/rst.html\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/docutils.sourceforge.net\/rst.html<\/a><\/p>\n<p>reST\u662f\u6613\u8bfb\u6240\u89c1\u5373\u6240\u5f97\u7684\u6587\u672c\u6807\u8bb0\u8bed\u8a00\uff0c\u683c\u5f0f\u7c7b\u4f3cmarkdown\u3002<\/p>\n<p>python\u7684reST\u53c2\u8003pep12\u548cpep287:<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.python.org\/dev\/peps\/pep-0012\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.python.org\/dev\/peps\/pep-0012\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/www.python.org\/dev\/peps\/pep-0287\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.python.org\/dev\/peps\/pep-0287\/<\/a><\/p>\n<p>\u4e3b\u6807\u9898\uff1a<\/p>\n<pre><code>title\n=====\n=====\ntitle\n=====\n<\/code><\/pre>\n<p>\u526f\u6807\u9898\uff1a<\/p>\n<pre><code>Subtitle\n-----\n--------\nSubtitle\n--------\n<\/code><\/pre>\n<p>\u6b21\u7ea7\u6807\u9898\uff1a<\/p>\n<pre><code>Content\n^^^^^^^\n<\/code><\/pre>\n<p>\u661f\u53f7\u659c\u4f53\u5f3a\u8c03\uff1a<\/p>\n<pre><code>*text*\n<\/code><\/pre>\n<p>\u53cc\u661f\u53f7\u52a0\u7c97\u91cd\u70b9\u5f3a\u8c03\uff1a<\/p>\n<pre><code>**text**\n<\/code><\/pre>\n<p>\u56db\u4e2a\u6216\u4ee5\u4e0a\u7684-\u8868\u793a\u5206\u5272\u7ebf\uff1a<\/p>\n<pre><code>----\n<\/code><\/pre>\n<p>\u53c2\u8003\u5f0f\u94fe\u63a5\uff1a<\/p>\n<pre><code>`hyperlink`_\n.. _hyperlink: http:\/\/hyperlink.org\n<\/code><\/pre>\n<p>\u884c\u5185\u5f0f\u94fe\u63a5\uff1a<\/p>\n<pre><code>`link &lt;https:\/\/link.com&gt;`_\n<\/code><\/pre>\n<p>\u56fe\u7247\uff1a<\/p>\n<pre><code>.. image:: https:\/\/path\/image.png\n:alt: HTTPie compared to cURL\n:width: 679\n:heigh: 781\n:align: center\n<\/code><\/pre>\n<p>\u539f\u6837\u5f15\u7528\u5757\uff1a<\/p>\n<p>\u53cc\u5192\u53f7\u52a0\u56db\u4e2a\u7a7a\u683c<\/p>\n<pre><code>source code::\nprint(&quot;source&quot;)\nreturn 0\n<\/code><\/pre>\n<p>\u6587\u6863\u6d4b\u8bd5\u5757\uff1a<\/p>\n<pre><code>&gt;&gt;&gt; print doctest block.\n<\/code><\/pre>\n<p>\u65e0\u5e8f\u5217\u8868\uff1a<\/p>\n<pre><code>bullet lists:\n- This is item 1\n- This is item 2\n<\/code><\/pre>\n<p>\u6709\u5e8f\u5217\u8868\uff1a<\/p>\n<pre><code>enumerated lists:\n1. this is first item\n2. this is second item\n<\/code><\/pre>\n<p>\u5b9a\u4e49\u5217\u8868\uff1a<\/p>\n<pre><code>definition lists:\nwhat\nDefinition lists.\nhow\nThe term is a one-line phrase.\n<\/code><\/pre>\n<p>\u57df\u5217\u8868\uff1a<\/p>\n<pre><code>field lists:\n:Authors:\nCanux\n:Version: 1.0.0\n<\/code><\/pre>\n<p>\u9009\u9879\u5217\u8868\uff1a<\/p>\n<pre><code>option lists:\n-a option &quot;a&quot;\n-b file option for filename\n<\/code><\/pre>\n<p>\u8bc4\u8bba\uff1a<\/p>\n<pre><code>.. This is commnet.\nAs well.\n<\/code><\/pre>"},{"title":"Debug","link":"https:\/\/canuxcheng.com\/post\/psl_debug\/","pubDate":"Sat, 06 Aug 2016 16:54:08 +0000","guid":"https:\/\/canuxcheng.com\/post\/psl_debug\/","description":"<h1 id=\"debug-and-profiling\">Debug and Profiling<\/h1>\n<h2 id=\"bdb\">bdb<\/h2>\n<h2 id=\"pdb\">pdb<\/h2>\n<h2 id=\"timeit\">timeit<\/h2>\n<h2 id=\"trace\">trace<\/h2>\n<h2 id=\"trracemalloc\">trracemalloc<\/h2>\n<hr>\n<h2 id=\"tpl\">TPL<\/h2>\n<h3 id=\"viztracer\">viztracer<\/h3>\n<p><a class=\"link\" href=\"https:\/\/github.com\/gaogaotiantian\/viztracer\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/gaogaotiantian\/viztracer<\/a><\/p>"},{"title":"PEP","link":"https:\/\/canuxcheng.com\/post\/python_pep\/","pubDate":"Sat, 06 Aug 2016 16:54:08 +0000","guid":"https:\/\/canuxcheng.com\/post\/python_pep\/","description":"<h1 id=\"pep-8--style-guide-for-python-code\">PEP 8 &ndash; Style Guide for Python Code<\/h1>\n<p><a class=\"link\" href=\"https:\/\/www.python.org\/dev\/peps\/pep-0008\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.python.org\/dev\/peps\/pep-0008\/<\/a><\/p>\n<h1 id=\"pep-257--docstring-conventions\">PEP 257 &ndash; Docstring Conventions<\/h1>\n<p><a class=\"link\" href=\"https:\/\/www.python.org\/dev\/peps\/pep-0257\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.python.org\/dev\/peps\/pep-0257\/<\/a><\/p>\n<h1 id=\"pep-20pep-20--the-zen-of-python\">PEP-20PEP 20 &ndash; The Zen of Python<\/h1>\n<p><a class=\"link\" href=\"https:\/\/www.python.org\/dev\/peps\/pep-0020\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.python.org\/dev\/peps\/pep-0020\/<\/a><\/p>\n<pre><code># \u67e5\u770bpep20\n&gt;import this\n<\/code><\/pre>"},{"title":"Ftp","link":"https:\/\/canuxcheng.com\/post\/ftp\/","pubDate":"Thu, 28 Jul 2016 16:08:54 +0000","guid":"https:\/\/canuxcheng.com\/post\/ftp\/","description":"<h1 id=\"ftp\">FTP<\/h1>\n<p>ftp\u670d\u52a1\u5668\u6709\u5f88\u591a\uff1a<\/p>\n<ol>\n<li>vsftpd<\/li>\n<li>proftpd<\/li>\n<li>pyftpdlib<\/li>\n<\/ol>\n<hr>\n<h1 id=\"vsftpd\">vsftpd<\/h1>\n<p>\u5b89\u88c5vsftpd:<\/p>\n<pre><code>$ sudo apt-get install vsftpd\n<\/code><\/pre>\n<p>windows\u5f00\u542fftp\u670d\u52a1\u548c\u5efa\u7acbIIS\u7ad9\u70b9\u5373\u53ef\u3002<\/p>\n<p>linux\u914d\u7f6e\uff1a<\/p>\n<pre><code>$ vim \/etc\/vsftpd.conf\nlocal_root=\/home\/canux\/FTP\nanon_root=\/home\/canux\/FTP\nlocal_enable=YES\nanonymous_enable=YES\nchroot_local_user=YES\n$ sudo service vsftpd restart\n<\/code><\/pre>\n<p>ftp\u7684\u7f51\u9875\u6d4f\u89c8\u683c\u5f0f\uff1a<\/p>\n<pre><code>ftp:\/\/host\/path\nftp:\/\/username:password@host:port\/path\n<\/code><\/pre>\n<hr>\n<h1 id=\"ftp\u547d\u4ee4\">ftp\u547d\u4ee4<\/h1>\n<h2 id=\"ftp-1\">ftp<\/h2>\n<pre><code>$ ftp [-46pinegvd] [host [port]]\n<\/code><\/pre>\n<hr>\n<h1 id=\"python\u7684ftp\u6807\u51c6\u5e93\">python\u7684FTP\u6807\u51c6\u5e93<\/h1>\n<h2 id=\"ftplib\">ftplib<\/h2>\n<hr>"},{"title":"Ldap","link":"https:\/\/canuxcheng.com\/post\/ldap\/","pubDate":"Thu, 28 Jul 2016 16:08:54 +0000","guid":"https:\/\/canuxcheng.com\/post\/ldap\/","description":"<h1 id=\"ldap\">LDAP<\/h1>\n<p>LDAP\u5360\u7528tcp\u548cudp\u7684389\u7aef\u53e3\u3002<\/p>\n<p>\u4f7f\u7528SSL\u7684LDAP\u5360\u7528tcp\u548cudp\u7684636\u7aef\u53e3\u3002<\/p>\n<p>Lightweight Directory Access Protocol.<\/p>\n<p><a class=\"link\" href=\"http:\/\/www.openldap.org\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.openldap.org\/<\/a><\/p>\n<p>LDAP\u7684windows\u5de5\u5177\uff1aLDAPSoft LDAP Browser<\/p>\n<hr>"},{"title":"Nfs","link":"https:\/\/canuxcheng.com\/post\/nfs\/","pubDate":"Thu, 28 Jul 2016 16:08:54 +0000","guid":"https:\/\/canuxcheng.com\/post\/nfs\/","description":"<h1 id=\"nfs\">NFS<\/h1>\n<p>NFS: Network File System<\/p>\n<p>\u5b89\u88c5\uff1a<\/p>\n<pre><code># \u5728nfs\u670d\u52a1\u5668\u5b89\u88c5nfs\u670d\u52a1\n$ sudo apt-get install nfs-kernel-server\n# \u6dfb\u52a0\u5171\u4eab\u76ee\u5f55\u5e76\u6388\u6743\n$ sudo vim \/etc\/exports\n\/home\/user\/share *(rw,no_root_squash)\n$ sudo service nfs-kernel-server restart\n# \u5728nfs\u5ba2\u6237\u7aef\u5b89\u88c5nfs\u5ba2\u6237\u7aef\n$ sudo apt-get install nfs-common\n# \u81ea\u52a8\u6302\u8f7d\n$ sudo vim \/etc\/fstab\nnfs-server-ip:\/home\/user\/share \/home\/user1\/share nfs auto 0 0\n$ sudo mount -a\n# \u624b\u52a8\u6302\u8f7d\n$ sudo mount -t nfs nfs-server-ip:\/home\/user\/share \/home\/user1\/share\n<\/code><\/pre>\n<hr>\n<h1 id=\"nfs-server\">nfs-server<\/h1>\n<p>\u914d\u7f6e\/etc\/exports<\/p>\n<pre><code>\/etc\/exports \u00a0\u6587\u4ef6\u683c\u5f0f\n&lt;\u8f93\u51fa\u76ee\u5f55&gt; [\u5ba2\u6237\u7aef1 \u9009\u9879\uff08\u8bbf\u95ee\u6743\u9650,\u7528\u6237\u6620\u5c04,\u5176\u4ed6\uff09] [\u5ba2\u6237\u7aef2 \u9009\u9879\uff08\u8bbf\u95ee\u6743\u9650,\u7528\u6237\u6620\u5c04,\u5176\u4ed6\uff09]\n<\/code><\/pre>\n<h1 id=\"nfs-client\">nfs-client<\/h1>\n<p>\u914d\u7f6e\/etc\/fstab<\/p>"},{"title":"Ntp","link":"https:\/\/canuxcheng.com\/post\/ntp\/","pubDate":"Thu, 28 Jul 2016 16:08:54 +0000","guid":"https:\/\/canuxcheng.com\/post\/ntp\/","description":"<h1 id=\"ntp\">NTP<\/h1>\n<p>NFS: Network Time Protocol<\/p>\n<p>UTC: Coordinated Universal Time, \u4e16\u754c\u7edf\u4e00\u65f6\u95f4<\/p>\n<p>GMT: Greenwich Mean Time, \u683c\u6797\u5c3c\u6cbb\u6807\u51c6\u65f6\u95f4, = UTC<\/p>\n<p>CET: Central European Time, \u6b27\u6d32\u4e2d\u90e8\u65f6\u95f4, = UTC+1, \u4e0b\u4ee4\u65f6=UTC+2<\/p>\n<p>CST: Chinese Standard Time, \u4e2d\u56fd\u6807\u51c6\u65f6\u95f4, = UTC+8<\/p>\n<hr>\n<h1 id=\"\u65f6\u533a\u7ba1\u7406\">\u65f6\u533a\u7ba1\u7406<\/h1>\n<pre><code>$ timedatectl list-timezones # \u67e5\u770b\u6240\u6709\u65f6\u533a\n$ sudo timedatectl set-timezone Asia\/Shanghai # \u8bbe\u7f6e\u65f6\u533a\n$ sudo timedatectl set-timezone Etc\/UTC\n$ ls -l \/etc\/localtime # \u5e94\u8be5\u662f\u4e00\u4e2a\u94fe\u63a5\n<\/code><\/pre>\n<hr>\n<h1 id=\"ntp-1\">ntp<\/h1>\n<p>\u5b89\u88c5:<\/p>\n<pre><code>$ sudo apt-get install ntp\n<\/code><\/pre>\n<h2 id=\"ntpdate\">ntpdate<\/h2>\n<p>\u4ece\u76ee\u6807\u670d\u52a1\u5668\u540c\u6b65.<\/p>\n<pre><code>ntpdate -u ip\n<\/code><\/pre>\n<h2 id=\"ntpstat\">ntpstat<\/h2>\n<pre><code>$ sudo apt-get install ntpstat\n<\/code><\/pre>\n<hr>\n<h1 id=\"chrony\">chrony<\/h1>\n<p>ntp\u7684\u5347\u7ea7\u7248.<\/p>"},{"title":"Ssh","link":"https:\/\/canuxcheng.com\/post\/ssh\/","pubDate":"Thu, 28 Jul 2016 15:53:34 +0000","guid":"https:\/\/canuxcheng.com\/post\/ssh\/","description":"<h1 id=\"openssh\">OpenSSH<\/h1>\n<p><a class=\"link\" href=\"http:\/\/www.openssh.com\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.openssh.com\/<\/a><\/p>\n<p>windows\u4e0a\u652f\u6301ssh\u534f\u8bae\u7684\u5ba2\u6237\u7aef\uff1a<\/p>\n<ul>\n<li>putty<\/li>\n<li>xshell<\/li>\n<li>MobaXterm<\/li>\n<li>secureCRT<\/li>\n<\/ul>\n<p>\u5b89\u88c5\uff1a<\/p>\n<pre><code>$ sudo apt-get install openssh-server\n$ sudo apt-get install openssh-client\n<\/code><\/pre>\n<hr>\n<h1 id=\"ssh\u547d\u4ee4\">SSH\u547d\u4ee4<\/h1>\n<p>ssh\u662fopenssh\u534f\u8bae\u7684\u5ba2\u6237\u7aef\uff0e<\/p>\n<p>\u8fdc\u7a0b\u64cd\u4f5c\u7684\u547d\u4ee4\u5305\u62ecssh, scp, sftp.<\/p>\n<p>ssh<\/p>\n<pre><code>$ ssh\n# \u8fdc\u7a0b\u6267\u884c\u547d\u4ee4\u9700\u8981\u7528\u53cc\u5f15\u53f7\uff0c\u4e0d\u80fd\u7528\u5355\u5f15\u53f7\n$ ssh username@host &quot;command\/script&quot;\n<\/code><\/pre>\n<p>scp<\/p>\n<pre><code>$ scp\n<\/code><\/pre>\n<p>sftp<\/p>\n<pre><code>$ sftp\n<\/code><\/pre>\n<p>\u5e38\u7528\u9009\u9879\uff1a<\/p>\n<pre><code>-C compression\n# \u4e0d\u9700\u8981\u8f93\u5165yes\u6765\u4ea4\u4e92, \u6216\u8005\u4fee\u6539\/etc\/ssh\/ssh_config\n-o StrictHostKeyChecking=no\n-o UserKnownHostsFile \/dev\/null\n<\/code><\/pre>\n<p>ssh\u4e5f\u5305\u62ec\u4e00\u4e9b\u5bc6\u94a5\u7ba1\u7406\u7684\u547d\u4ee4.<\/p>\n<p>ssh-keygen<\/p>\n<pre><code>$ ssh-keygen -t rsa -C 'canuxcheng@gmail.com'\n# \u901a\u8fc7\u5c06\u672c\u673a\u7684\u516c\u94a5\u62f7\u8d1d\u5230\u8fdc\u7a0b\u673a\u5668\u5b9e\u73b0\u65e0\u5bc6\u7801\u8bbf\u95ee\uff0e\n# \u5c06\u672c\u673a\u7684public-key\u62f7\u8d1d\u5230\u8fdc\u7a0b\u673a\u5668\u7684authorized_keys.\n$ ssh-copy-id -i ~\/.ssh\/id_rsa.pub user@remote\n# \u53e6\u5916\u7684\u62f7\u8d1d\u65b9\u6cd5\n$ ssh user@host &quot;cat &gt;&gt; ~\/.ssh\/authorized_keys&quot; &lt; ~\/.ssh\/id_rsa.pub\n$ sudo service ssh restart # \u9700\u8981\u91cd\u542fssh\u670d\u52a1\n\u975e\u4ea4\u4e92\u5f0f\u901a\u8fc7\u547d\u4ee4\u884c\u4f20\u5bc6\u7801\u7684\u547d\u4ee4\uff1a\n$ sshpass -p [password]\n<\/code><\/pre>\n<p>ssh-add<\/p>\n<p>ssh-keysign<\/p>\n<p>ssh-keyscan<\/p>\n<hr>\n<h1 id=\"\u542f\u7528root\u8fdc\u7a0bssh\">\u542f\u7528root\u8fdc\u7a0bssh<\/h1>\n<pre><code>$ sudo -i\n# passwd root\n# vim \/etc\/ssh\/sshd_config\n&gt; PermitRootLogin prohibit-password\n&gt; PermitRootLogin yes\n# service ssh restart\n<\/code><\/pre>\n<h1 id=\"ssh-tunel\">ssh tunel<\/h1>\n<p>SSH Tunnel\u6709\u4e09\u79cd<\/p>\n<ul>\n<li>\n<p>\u672c\u5730Local\uff08ssh -NfL\uff09, \u5728ssh client(\u672c\u5730)\u6267\u884c.<\/p>\n<pre><code> \u6b63\u5411\u4ee3\u7406\uff1a\uff08a\u80fdssh\u5230b\uff0cb\u80fd\u8bbf\u95eec\uff0c\u5b9e\u73b0a\u8bbf\u95eec\uff0c\u76f8\u5f53\u4e8ea\u662fssh client\uff09A \u901a\u8fc7 \u4e2d\u8f6cB\u8fde\u63a5 server C.\n\u5728A \u4e0a\u5efa\u7acbtunnel:\nssh -Nf -L ssh-client-ip:ssh-client-port:remoteServerIp:remoteServerPort user@agentIp\n\u8bbf\u95eessh-client-ip\/A\u7684ssh-client-port \u5373\u53ef\u8bbf\u95ee remoteServerIp\/C \u7684 remoteServerPort \u63d0\u4f9b\u7684\u670d\u52a1.\n<\/code><\/pre>\n<\/li>\n<li>\n<p>\u8fdc\u7a0bRemote\uff08ssh -NfR\uff09, \u5728ssh server\u6267\u884c.<\/p>\n<pre><code> \u53cd\u5411\u4ee3\u7406\uff1a\uff08b\u80fdssh\u5230a\uff0cb\u80fd\u8bbf\u95eec\uff0c\u5b9e\u73b0a\u8bbf\u95eec, a\u76f8\u5f53\u4e8essh server, c\u76f8\u5f53\u4e8eremote server) A \u901a\u8fc7\u4e2d\u8f6cB\u8bbf\u95eeserver C.\n\u5728B\u4e0a\u5efa\u7acbtunnel:\nssh -Nf -R ssh-server-ip:ssh-server-port:remoteServerIp:remoteServerPort user@agent\n\u8bbf\u95eessh-server-ip\/A\u7684ssh-server-port\u7aef\u53e3\u5373\u53ef\u8bbf\u95eeremoteServerIp\/C \u7684 remoteServerPort \u63d0\u4f9b\u7684\u670d\u52a1\u3002\n<\/code><\/pre>\n<\/li>\n<li>\n<p>\u52a8\u6001Dynamic\uff08ssh -NfD\uff09<\/p>\n<pre><code> socks\u4ee3\u7406\uff1a a\u80fdssh\u5230B\uff0cb\u80fd\u8bbf\u95ee\u4e00\u4e2a\u7f51\u6bb5\uff0c\u5b9e\u73b0a\u8bbf\u95ee\u8be5\u7f51\u6bb5.\n\u5728a\u4e0a\u5efa\u7acbtunnel\nssh -D [ssh-client-ip]:ssh-client-port user@agent\nsocks\u4ee3\u7406\u914d\u7f6essh-client-ip:ssh-client-port \u5373\u53ef\u901a\u8fc7B\u8bbf\u95ee\u8be5\u7f51\u6bb5\u3002\n<\/code><\/pre>\n<\/li>\n<\/ul>"},{"title":"Remote Management","link":"https:\/\/canuxcheng.com\/post\/ps_remote\/","pubDate":"Mon, 18 Jul 2016 14:54:39 +0000","guid":"https:\/\/canuxcheng.com\/post\/ps_remote\/","description":"<h1 id=\"windows\u8fdc\u7a0b\u7ba1\u7406\">Windows\u8fdc\u7a0b\u7ba1\u7406<\/h1>\n<ol>\n<li>WinRM, \u8fdc\u7a0b\u5904\u7406,\u5728\u8fdc\u7a0b\u673a\u5668\u4e0a\u6267\u884c\u547d\u4ee4<\/li>\n<li>WMI\/CIM<\/li>\n<li>RPC, \u8fdc\u7a0b\u8fde\u63a5,\u5728\u53d1\u8d77\u8fdc\u7a0b\u8fde\u63a5\u7684\u673a\u5668\u4e0a\u6267\u884c\u547d\u4ee4<\/li>\n<\/ol>\n<hr>\n<h1 id=\"winrm\">WinRM<\/h1>\n<p>\u4e00\u5bf9\u4e00\u8fdc\u7a0b\u5904\u7406:<\/p>\n<p>\u7c7b\u4f3c\u4e8elinux\u7684ssh\u3002<\/p>\n<pre><code>Enter-PSSession -ComputerName name\n...\nExit-PSSession\n<\/code><\/pre>\n<p>\u4e00\u5bf9\u591a\u8fdc\u7a0b\u5904\u7406:<\/p>\n<p>\u540c\u65f6\u8fdc\u7a0b\u5230\u591a\u53f0\u673a\u5668\u6267\u884c\u547d\u4ee4\u6216\u811a\u672c\u3002<\/p>\n<p>Invoke-Command\u4e00\u6b21\u521b\u5efa\u4e00\u4e2a\u8fde\u63a5\u5bf9\u8c61\uff0c\u8fd4\u56dePSComputerName\u5c5e\u6027\uff0c\u6267\u884c\u5b8c\u540e\u5c31\u5173\u95ed\u8fde\u63a5\u3002<\/p>\n<pre><code>Invoke-Command -ComputerName name1,name2 -ScriptBlock {command1;command2}\nInvoke-Command -ComputerName name1,name2 -FilePath filepath\nInvoke-Command -ComputerName (Get-Content hosts.txt) ...\n<\/code><\/pre>\n<p>\u901a\u8fc7argumentlist\u628a\u672c\u5730\u7684\u53c2\u6570\u4f20\u7ed9\u8fdc\u7a0b\u7684\u547d\u4ee4:<\/p>\n<pre><code>$lvar1=&quot;value1&quot;\n$lvar2=&quot;value2&quot;\nInvoke-Command -ComputerName name\n-ScriptBlock {\nParam($var1, $var2)\n...\n}\n-ArgumentList $lvar1, $lvar2\n<\/code><\/pre>\n<p>\u901a\u8fc7$using:\u4f20\u672c\u5730\u53c2\u6570\u5230\u8fdc\u7a0b\u673a\u5668\uff1a<\/p>\n<pre><code>$var1=&quot;value1&quot;\nInvoke-Command -ComputerName name\n-ScriptBlock {\n... $using:var1\n}\n<\/code><\/pre>\n<p>\u521b\u5efa\u6301\u4e45\u7684\u8fdc\u7a0b\u5904\u7406\uff1a<\/p>\n<pre><code>$session1=New-PSSession -ComputerName server1\nEnter-PSSession -Session $session1 ...\nInvoke-Command -Session $session1 ...\n<\/code><\/pre>\n<hr>\n<h1 id=\"wmi\">WMI<\/h1>\n<pre><code>Get-WmiObject\nRemove-WmiObject\nInvoke-WmiMethod\nRegister-WmiEvent\nSet-WmiInstance\n# \u7528powershell\u8dd1\u4e00\u4e2awql\u3002\nGet-WmiObject -Query &quot;select * from win32_service where name='winRM'&quot; | Format-List -Property Name,status\n# \u8fdc\u7a0b\u7ba1\u7406\nGet-WMIObject -ComputerName ...\n<\/code><\/pre>\n<h1 id=\"cim\">CIM<\/h1>\n<pre><code>Get-CimClass\nGet-CimInstance\nGet-CimSession\nGet-CimAssociatedInstance\nInvoke-CimMethod\nNew-CimInstance\nNew-CimSession\nNew-CimSessionOption\nRegister-CimIndicationEvent\nRemove-CimInstance\nRemove-CimSession\nSet-CimInstance\n<\/code><\/pre>\n<hr>\n<h1 id=\"rpc\">RPC<\/h1>\n<pre><code># \u8fdc\u7a0b\u8fde\u63a5\nGet-Service -ComputerName ...\n<\/code><\/pre>"},{"title":"WinRM","link":"https:\/\/canuxcheng.com\/post\/win_winrm\/","pubDate":"Sun, 17 Jul 2016 08:36:36 +0000","guid":"https:\/\/canuxcheng.com\/post\/win_winrm\/","description":"<h1 id=\"winrm\">WinRM<\/h1>\n<p>Windows Remote Management<\/p>\n<p>WinRM\u662fWSMAN(WS-Management Protocol)\u7684\u589e\u5f3a\u7248\u3002<\/p>\n<p>WinRM\u662f\u57fa\u4e8eSOAP\u7684\u9632\u706b\u5899\u53cb\u597d\u7684\u8fdc\u7a0b\u534f\u8bae\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/aa384426%28v=vs.85%29.aspx\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/msdn.microsoft.com\/en-us\/library\/aa384426(v=vs.85).aspx<\/a><\/p>\n<p>WinRM\u8bbe\u7f6e:<\/p>\n<p><a class=\"link\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/aa384372%28v=vs.85%29.aspx\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/msdn.microsoft.com\/en-us\/library\/aa384372(v=vs.85).aspx<\/a><\/p>\n<p>\u68c0\u67e5winrm\u6240\u6709\u914d\u7f6e\uff1a<\/p>\n<pre><code>cmd&gt; winrm get winrm\/config\n<\/code><\/pre>\n<p>\u5feb\u901f\u8bbe\u7f6ewinrm\uff1a<\/p>\n<pre><code>cmd&gt; winrm quickconfig\ncmd&gt; winrm quickconfig -transport:https\n<\/code><\/pre>\n<p>\u67e5\u770blistener\u914d\u7f6e\uff1a<\/p>\n<pre><code>cmd&gt; winrm enumerate winrm\/config\/listener\n<\/code><\/pre>\n<p>WinRM\u914d\u7f6e\u5305\u62ec\u76d1\u542c\u8bbe\u7f6e,\u534f\u8bae\u8bbe\u7f6e,Client,Service\u548cWinrs\u56db\u90e8\u5206.<\/p>\n<p>windows\u7684\u4e09\u79cd\u7f51\u7edc\u5b89\u5168\u534f\u8bae\u3002<\/p>\n<p>Basic\u662f\u57fa\u672c\u7684\u660e\u6587\u534f\u8bae, NTLM\u662f\u65e9\u671f\u7684\u5b89\u5168\u534f\u8bae,Kerberos\u662f\u6700\u65b0\u7684\u5b89\u5168\u534f\u8bae.<\/p>\n<h1 id=\"service\u6743\u9650\u7ba1\u7406\">service\u6743\u9650\u7ba1\u7406<\/h1>\n<p>\u67e5\u770bservice\u7684auth\u914d\u7f6e\uff1a<\/p>\n<pre><code>cmd&gt; winrm get winrm\/config\/service\/auth\n<\/code><\/pre>\n<p>service\u53ea\u6709Negotiate\u548cKerberos\u662f\u9ed8\u8ba4\u5f00\u542f\u7684:<\/p>\n<pre><code>Basic = false\nKerberos = true\nNegotiate = true\nCertificate = false\nCredSSP = false\n<\/code><\/pre>\n<p>Negotiate\u5bf9domain\u7528\u6237\u9009\u62e9kerberos,\u5bf9local\u7528\u6237\u9009\u62e9NTLM.<\/p>\n<p>\u8bbe\u7f6eservice\u7684Basic\u548cCertificate\u548cCredSSP(\u9ed8\u8ba4\u5173\u95ed)\uff1a<\/p>\n<pre><code>#cmd&gt; winrm set winrm\/config\/service\/auth @{Basic=&quot;true&quot;}\n#cmd&gt; winrm set winrm\/config\/service\/auth @{Certificate=&quot;true&quot;}\n#cmd&gt; winrm set winrm\/config\/service\/auth @{CredSSP=&quot;true&quot;}\n<\/code><\/pre>\n<p>\u8bbe\u7f6e\u662f\u5426\u5141\u8bb8\u4e0d\u52a0\u5bc6\uff1a<\/p>\n<pre><code>#cmd&gt; winrm set winrm\/config\/service @{AllowUnencrypted=&quot;true&quot;}\n<\/code><\/pre>\n<h1 id=\"client\u6743\u9650\u7ba1\u7406\">client\u6743\u9650\u7ba1\u7406<\/h1>\n<p>\u67e5\u770bclient\u7684auth\u914d\u7f6e\uff1a<\/p>\n<pre><code>cmd&gt; winrm get winrm\/config\/client\/auth\n<\/code><\/pre>\n<p>\u8bbe\u7f6eclient\u7684CredSSP(\u9ed8\u8ba4\u5173\u95ed),\u5176\u5b83\u9ed8\u8ba4\u90fd\u662f\u5f00\u542f\uff1a<\/p>\n<pre><code>#cmd&gt; winrm set winrm\/config\/client\/auth @{CredSSP=&quot;true&quot;}\n<\/code><\/pre>\n<p>\u8bbe\u7f6eclient\u7684trustedhosts:<\/p>\n<pre><code>#cmd&gt; winrm set winrm\/config\/client @{TrustedHosts=&quot;*&quot;}\n<\/code><\/pre>\n<h1 id=\"winrs\">Winrs<\/h1>\n<p>winrs\u662fwinrm\u7684\u5ba2\u6237\u7aef\uff0e<\/p>\n<pre><code>$winrs -r:http:\/\/&lt;ip-address&gt; -u:domain\/user -p:pass command\n<\/code><\/pre>\n<hr>"},{"title":"Coreutils","link":"https:\/\/canuxcheng.com\/post\/ps_coreutils\/","pubDate":"Tue, 12 Jul 2016 17:24:25 +0000","guid":"https:\/\/canuxcheng.com\/post\/ps_coreutils\/","description":"<h1 id=\"\u5916\u90e8\u547d\u4ee4\">\u5916\u90e8\u547d\u4ee4<\/h1>\n<p>powershell\u53ef\u4ee5\u6267\u884c\u5916\u90e8\u547d\u4ee4.<\/p>\n<pre><code>C:\\Windows\\System32\\*.exe\n<\/code><\/pre>\n<h1 id=\"cmd\">cmd<\/h1>\n<h1 id=\"ping\">ping<\/h1>\n<h1 id=\"netstat\">netstat<\/h1>\n<h1 id=\"ipconfig\">ipconfig<\/h1>\n<h1 id=\"route\">route<\/h1>\n<h1 id=\"arp\">arp<\/h1>\n<h1 id=\"nslookup\">nslookup<\/h1>\n<h1 id=\"ftp\">ftp<\/h1>\n<h1 id=\"mstsc\">mstsc<\/h1>\n<p>RDP client.<\/p>\n<h1 id=\"taskmgr\">taskmgr<\/h1>\n<p>\u4efb\u52a1\u7ba1\u7406\u5668\uff0e<\/p>\n<h1 id=\"tskill\">tskill<\/h1>\n<h1 id=\"tree\">tree<\/h1>\n<h1 id=\"whoami\">whoami<\/h1>\n<hr>\n<p>\u9700\u8981\u4e0b\u8f7d\uff0c\u7136\u540e\u653e\u5165\u73af\u5883\u53d8\u91cf\u7684\u7b2c\u4e09\u65b9\u547d\u4ee4.<\/p>\n<h1 id=\"windump\">WinDump<\/h1>\n<p>Windows\u7248\u672c\u7684tcpdump, \u4f9d\u8d56WinPcap\u5305\uff0e<\/p>\n<p>\u901a\u8fc7windump\u5bfc\u51fa\u7684*.pcap\u6587\u4ef6\u53ef\u4ee5\u901a\u8fc7wireshark\u6253\u5f00\uff0e<\/p>"},{"title":"Json","link":"https:\/\/canuxcheng.com\/post\/json\/","pubDate":"Thu, 07 Jul 2016 16:43:15 +0000","guid":"https:\/\/canuxcheng.com\/post\/json\/","description":"<h1 id=\"json\">JSON<\/h1>\n<p><a class=\"link\" href=\"http:\/\/www.json.org\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.json.org\/<\/a><\/p>\n<p>JSON: JavaScript Object Notation.<\/p>\n<p>json\u6709\u4e24\u79cd\u6570\u636e\u7ed3\u6784.<\/p>\n<h1 id=\"key-value\u952e\u503c\u5bf9\">key-value\/\u952e\u503c\u5bf9<\/h1>\n<pre><code>{\nkey: value,\nkey1: value1,\n...\n}\n<\/code><\/pre>\n<h1 id=\"\u5217\u8868\u6570\u7ec4\">\u5217\u8868\/\u6570\u7ec4<\/h1>\n<pre><code>[value, value1, ...]\n<\/code><\/pre>\n<h1 id=\"\u6570\u636e\u7c7b\u578b\">\u6570\u636e\u7c7b\u578b<\/h1>\n<p>bool:<\/p>\n<pre><code>python -&gt; True\/False\ngo -&gt; true\/false\n<\/code><\/pre>\n<p>string:<\/p>\n<pre><code>&gt; \u53ea\u80fd\u7528\u53cc\u5f15\u53f7.\npython -&gt; str\ngo -&gt; string\ngo -&gt; []byte -&gt; base64\u7f16\u7801\u5b57\u7b26\u4e32\n<\/code><\/pre>\n<p>number:<\/p>\n<pre><code>python -&gt; int\/float\ngo -&gt; int64\/float64\n<\/code><\/pre>\n<p>null:<\/p>\n<pre><code>python -&gt; None\ngo -&gt; nil\n<\/code><\/pre>\n<p>array<\/p>\n<pre><code>python -&gt; tuple\/list\ngo -&gt; array\/slice\n<\/code><\/pre>\n<p>object<\/p>\n<pre><code>python -&gt; dict\ngo -&gt; struct\/map\n<\/code><\/pre>"},{"title":"Yaml","link":"https:\/\/canuxcheng.com\/post\/yaml\/","pubDate":"Thu, 07 Jul 2016 16:43:15 +0000","guid":"https:\/\/canuxcheng.com\/post\/yaml\/","description":"<h1 id=\"yaml\">YAML<\/h1>\n<p><a class=\"link\" href=\"https:\/\/yaml.org\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/yaml.org<\/a><\/p>\n<p>Yaml Ain&rsquo;t Markup Language.<\/p>\n<h2 id=\"yamllint\">yamllint<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/adrienverge\/yamllint\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/adrienverge\/yamllint<\/a><\/p>"},{"title":"CSS","link":"https:\/\/canuxcheng.com\/post\/css\/","pubDate":"Thu, 23 Jun 2016 09:40:45 +0000","guid":"https:\/\/canuxcheng.com\/post\/css\/","description":"<h1 id=\"css\"><strong>CSS<\/strong><\/h1>\n<p>CSS\u662f\u53e0\u5c42\u6837\u5f0f\u8868<\/p>\n<h1 id=\"css3\">CSS3<\/h1>\n<p>CSS3\u662f\u6700\u65b0\u7684CSS\u6807\u51c6<\/p>\n<h1 id=\"css\u521b\u5efa\">CSS\u521b\u5efa<\/h1>\n<p>\u4f18\u5148\u7ea7\u4ece\u4e0a\u5f80\u4e0b\u3002<\/p>\n<ol>\n<li>\u5185\u8054\u6837\u5f0f\uff0c \u5728html\u4e2d\u901a\u8fc7style\u5c5e\u6027\u5b9a\u4e49\uff0c\u4ec5\u7528\u4e8e\u4e00\u4e2ahtml\u5143\u7d20\u3002<\/li>\n<li>\u5185\u90e8\u6837\u5f0f\u8868\uff0c\u5728html\u4e2d\u901a\u8fc7style\u6807\u7b7e\u5728\u5934\u90e8\u5b9a\u4e49,\u9488\u5bf9\u5355\u4e2a\u9875\u9762\u3002<\/li>\n<li>\u5916\u90e8\u6837\u5f0f\u8868\uff0c\u5728html\u4e2d\u901a\u8fc7link\u6807\u7b7e\u5728\u6587\u6863\u5934\u90e8\u5b9a\u4e49\uff0c\u65b9\u4fbf\u5c06\u6837\u5f0f\u7528\u4e8e\u591a\u4e2a\u9875\u9762\u3002<\/li>\n<li>\u6d4f\u89c8\u5668\u7684\u9ed8\u8ba4\u503c\u3002<\/li>\n<\/ol>\n<hr>\n<h1 id=\"css\u57fa\u672c\u8bed\u6cd5\"><strong>CSS\u57fa\u672c\u8bed\u6cd5<\/strong><\/h1>\n<p>CSS\u7531\u4e24\u90e8\u5206\u7ec4\u6210\uff0c\u9009\u62e9\u5668\u548c\u58f0\u660e\uff0c\u9009\u62e9\u5668\u662fhtml\u5143\u7d20\uff0c\u58f0\u660e\u7531\u5c5e\u6027\u548c\u503c\u7ec4\u6210\u3002<\/p>\n<pre><code>selector {\nproperty1: value1;\nproperty2: value2;\n...;\n}\n<\/code><\/pre>\n<p>\u591a\u4e2a\u58f0\u660e\u7528\u5206\u53f7\u9694\u5f00\uff0c\u5c5e\u6027\u7684\u503c\u6709\u7a7a\u683c\u8981\u7528\u5f15\u53f7\u3002<\/p>\n<p>CSS\u5bf9\u5927\u5c0f\u5199\u4e0d\u654f\u611f\u3002<\/p>\n<p>CSS\u6ce8\u91ca:<\/p>\n<pre><code>\/* comment *\/\n<\/code><\/pre>\n<hr>\n<h1 id=\"css\u9009\u62e9\u5668\"><strong>CSS\u9009\u62e9\u5668<\/strong><\/h1>\n<p>\u6700\u5e38\u89c1\u7684\u9009\u62e9\u5668\u662f\u5143\u7d20\u9009\u62e9\u5668,html\u5143\u7d20\u662f\u6700\u57fa\u672c\u7684\u9009\u62e9\u5668\u3002<\/p>\n<h2 id=\"\u5143\u7d20\u9009\u62e9\u5668\">\u5143\u7d20\u9009\u62e9\u5668<\/h2>\n<p>html {color:black;}<\/p>\n<h2 id=\"id\u9009\u62e9\u5668\">id\u9009\u62e9\u5668<\/h2>\n<p>id\u9009\u62e9\u5668\u53ef\u4ee5\u4e3a\u6807\u6709\u7279\u5b9aid\u7684html\u5143\u7d20\u6307\u5b9a\u7279\u5b9a\u6837\u5f0f\u3002<\/p>\n<p>id\u9009\u62e9\u5668\u7528#\u5f00\u5934\u5b9a\u4e49\u3002<\/p>\n<pre><code>#red {color: red;}\n#green {color: green;}\n&lt;p id=&quot;red&quot;&gt;This is red.&lt;\/p&gt;\n<\/code><\/pre>\n<p>id\u9009\u62e9\u5668\u5e38\u5e38\u7528\u6765\u5efa\u7acb\u6d3e\u751f\u9009\u62e9\u5668\uff1a<\/p>\n<pre><code>#sidebar p {\nfont-style: italic;\ntext-align: right;\nmargin-top: 0.5em;\n}\n&lt;div id=&quot;sidebar&quot;&gt;...&lt;\/div&gt;\n<\/code><\/pre>\n<h2 id=\"class\u9009\u62e9\u5668\">class\u9009\u62e9\u5668<\/h2>\n<p>\u548cid\u9009\u62e9\u5668\u529f\u80fd\u7c7b\u4f3c\uff0c\u7c7b\u9009\u62e9\u5668\u4ee5.\u5f00\u5934\u3002<\/p>\n<pre><code>.center {text-align: center}\n&lt;h1 class=&quot;center&quot;&gt;...&lt;\/h1&gt;\n<\/code><\/pre>\n<p>\u7c7b\u9009\u62e9\u5668\u7528\u4e8e\u5efa\u7acb\u6d3e\u751f\u9009\u62e9\u5668\uff1a<\/p>\n<pre><code>.fancy td {\ncolor: #f60;\nbackground: #666;\n}\n&lt;td class=&quot;fancy&quot;&gt;\n<\/code><\/pre>\n<p>\u4e5f\u53ef\u4ee5\u7528\uff1a<\/p>\n<pre><code>td.fancy {\ncolor: #f60;\nbackground: #666;\n}\n&lt;td class=&quot;fancy&quot;&gt;\n<\/code><\/pre>\n<h2 id=\"\u5c5e\u6027\u9009\u62e9\u5668\">\u5c5e\u6027\u9009\u62e9\u5668<\/h2>\n<p>\u4e3a\u62e5\u6709\u6307\u5b9a\u5c5e\u6027\u7684html\u5143\u7d20\u8bbe\u7f6e\u6837\u5f0f\u3002<\/p>\n<pre><code>[title]\n{\ncolor: red;\n}\n&lt;a title=&quot;title is red&quot;&gt;...&lt;\/a&gt;\n<\/code><\/pre>\n<p>\u5c5e\u6027\u548c\u503c\u9009\u62e9\u5668\uff1a<\/p>\n<pre><code>[title=w3c]\n{\nborder: 5px solid blue;\n}\n&lt;img title=&quot;w3c&quot; src=&quot;\/images\/w3c.gif&quot;&gt;\n# \u5c5e\u6027\u548c\u503c\u9009\u62e9\u5668\u7684\u64cd\u4f5c\u7b26\uff1a\n=\n~=\n|=\n^=\n$=\n*=\n<\/code><\/pre>\n<h2 id=\"\u540e\u4ee3\u9009\u62e9\u5668descendant\">\u540e\u4ee3\u9009\u62e9\u5668\/descendant<\/h2>\n<h2 id=\"\u5b50\u5143\u7d20\u9009\u62e9\u5668child\">\u5b50\u5143\u7d20\u9009\u62e9\u5668\/child<\/h2>\n<h2 id=\"\u76f8\u90bb\u5144\u5f1f\u9009\u62e9\u5668adjacent-sibling\">\u76f8\u90bb\u5144\u5f1f\u9009\u62e9\u5668\/adjacent sibling<\/h2>\n<hr>\n<h1 id=\"css\u6837\u5f0f\"><strong>CSS\u6837\u5f0f<\/strong><\/h1>\n<p>\u5185\u8054\u6837\u5f0f\uff1a<\/p>\n<pre><code>&lt;p style=&quot;background: #ff0000 url(\/i\/eg_bg_03.gif) no-repeat fixed center&quot;&gt;...&lt;\/h1&gt;\n<\/code><\/pre>\n<p>\u6837\u5f0f\u8868\uff1a<\/p>\n<pre><code>p {\nbackground: #ff0000 url(\/i\/eg_bg_03.gif) no-repeat fixed center;\n}\n<\/code><\/pre>\n<h2 id=\"background\u6837\u5f0f\">background\u6837\u5f0f<\/h2>\n<pre><code>background: # \u53ef\u4ee5\u5b9a\u4e49\u6240\u6709\u80cc\u666f\u7684\u503c\nbackground-color: gray # \u80cc\u666f\u989c\u8272\nbackground-image: url(\/images\/test.gif) # \u80cc\u666f\u56fe\u7247,\u9ed8\u8ba4\u6c34\u5e73\u548c\u5782\u76f4\u90fd\u5e73\u94fa\nbackground-repeat: repeat-x # \u6c34\u5e73\u65b9\u5411\u5e73\u94fa\nbackground-repeat: repeat-y # \u5782\u76f4\u65b9\u5411\u5e73\u94fa\nbackground-repeat: no-repeat # \u4e0d\u5e73\u94fa\nbackground-position: center\/top\/buttom\/left\/right # \u56fe\u50cf\u5728\u80cc\u666f\u4e2d\u7684\u4f4d\u7f6e\nbackground-attachment: fixed # \u56fe\u50cf\u76f8\u5bf9\u4e8e\u53ef\u89c6\u533a\u662f\u56fa\u5b9a\u7684\nbackground-size\nbackground-origin\nbackground-clip\n<\/code><\/pre>\n<h2 id=\"\u6587\u672c\u6837\u5f0f\">\u6587\u672c\u6837\u5f0f<\/h2>\n<pre><code>color: red # \u8bbe\u7f6e\u6587\u672c\u989c\u8272\nline-height # \u8bbe\u7f6e\u884c\u9ad8\nletter-spacing # \u8bbe\u7f6e\u5b57\u7b26\u95f4\u8ddd\nword-spacing # \u8bbe\u7f6e\u5b57\u95f4\u8ddd\ntext-indent # \u7f29\u8fdb\u5143\u7d20\u4e2d\u6587\u672c\u9996\u884c\ndirection: ltr\/rtl # \u8bbe\u7f6e\u6587\u672c\u65b9\u5411\ntext-align: left\/right\/center\/justify # \u5bf9\u9f50\u5143\u7d20\u4e2d\u7684\u6587\u672c\ntext-decoration: none\/underline\/overline\/line-through\/blink # \u5411\u6587\u672c\u6dfb\u52a0\u4fee\u9970\ntext-transform: none\/capitalize\/uppercase\/lowercase # \u63a7\u5236\u5143\u7d20\u7684\u5b57\u6bcd\nwhite-space: normal\/pre\/nowrap\/pre-wrap\/pre-line # \u8bbe\u7f6e\u5143\u7d20\u4e2d\u7a7a\u767d\u7684\u5904\u7406\u65b9\u5f0f\n<\/code><\/pre>\n<h2 id=\"\u5b57\u4f53\u6837\u5f0f\">\u5b57\u4f53\u6837\u5f0f<\/h2>\n<pre><code>font: # \u5b9a\u4e49\u6240\u6709\u548c\u5b57\u4f53\u6709\u5173\u7684\u5c5e\u6027\nfont-family: # \u8bbe\u7f6e\u5b57\u4f53\u7cfb\u5217\nfont-size: # \u8bbe\u7f6e\u5b57\u4f53\u5c3a\u5bf8\nfont-style: normal\/italic\/oblique # \u8bbe\u7f6e\u5b57\u4f53\u98ce\u683c\nfont-variant: normal\/small-caps # \u8bbe\u7f6e\u5b57\u4f53\u53d8\u4f53\nfont-weight: normal\/bold\/bolder\/lighter\/... # \u8bbe\u7f6e\u5b57\u4f53\u7c97\u7ec6\n<\/code><\/pre>\n<h2 id=\"\u94fe\u63a5\u6837\u5f0f\">\u94fe\u63a5\u6837\u5f0f<\/h2>\n<p>\u94fe\u63a5\u53ef\u4ee5\u8bbe\u7f6ebackground\uff0ccolor\uff0cfont\u7b49\u6837\u5f0f\u3002<\/p>\n<pre><code>a:link {background: red} # \u666e\u901a\u7684\u672a\u88ab\u8bbf\u95ee\u7684\u94fe\u63a5\na:visited {color: blue} # \u7528\u6237\u5df2\u8bbf\u95ee\u7684\u94fe\u63a5\na:hover {font: } # \u9f20\u6807\u6307\u9488\u4f4d\u4e8e\u94fe\u63a5\u7684\u4e0a\u65b9\na:active {font: } # \u94fe\u63a5\u88ab\u70b9\u51fb\u7684\u65f6\u523b\n<\/code><\/pre>\n<h2 id=\"\u5217\u8868\u6837\u5f0f\">\u5217\u8868\u6837\u5f0f<\/h2>\n<pre><code>list-style: # \u5b9a\u4e49\u6240\u6709\u548c\u5217\u8868\u76f8\u5173\u7684\u5c5e\u6027\nlist-style-image: # \u628a\u56fe\u50cf\u8bbe\u7f6e\u4e3a\u5217\u8868\u9879\u6807\u5fd7\nlist-style-position: inside\/outside # \u8bbe\u7f6e\u5217\u8868\u9879\u6807\u5fd7\u7684\u4f4d\u7f6e\nlist-style-type: # \u8bbe\u7f6e\u5217\u8868\u9879\u6807\u5fd7\u7684\u4f4d\u7f6e\n<\/code><\/pre>\n<h2 id=\"\u8868\u683c\u6837\u5f0f\">\u8868\u683c\u6837\u5f0f<\/h2>\n<pre><code>border-collapse: separate\/collapse # \u8bbe\u7f6e\u662f\u5426\u628a\u8868\u683c\u8fb9\u6846\u5408\u5e76\u4e3a\u5355\u4e00\u7684\u8fb9\u6846\nborder-spacing: # \u8bbe\u7f6e\u5206\u5272\u5355\u5143\u8fb9\u6846\u8ddd\u79bb\ncaption-side: top\/bottom # \u89c4\u5b9a\u8868\u683c\u6807\u9898\u8bbe\u7f6e\u65b9\u5f0f\nempty-cells: hide\/show # \u8bbe\u7f6e\u662f\u5426\u73b0\u5b9e\u8868\u683c\u4e2d\u7684\u7a7a\u5355\u5143\u683c\ntable-layout: automatic\/fixed # \u8bbe\u7f6e\u73b0\u5b9e\u5355\u5143\uff0c\u884c\u548c\u5217\u7684\u7b97\u6cd5\n<\/code><\/pre>\n<h2 id=\"\u8f6e\u5ed3\u6837\u5f0f\">\u8f6e\u5ed3\u6837\u5f0f<\/h2>\n<pre><code>outline: # \u8bbe\u7f6e\u6240\u6709\u548c\u8f6e\u5ed3\u76f8\u5173\u7684\u5c5e\u6027\noutline-color: # \u8bbe\u7f6e\u8f6e\u5ed3\u989c\u8272\noutline-style: none\/dotted\/dashed\/solid\/double\/groove\/ridge\/inset\/outset # \u8bbe\u7f6e\u8f6e\u5ed3\u98ce\u683c\noutline-width: # \u8bbe\u7f6e\u8f6e\u5ed3\u5bbd\u5ea6\n<\/code><\/pre>\n<h2 id=\"\u5c3a\u5bf8\u5c5e\u6027\">\u5c3a\u5bf8\u5c5e\u6027<\/h2>\n<pre><code>height\nwidth\nmax-height\nmax-width\nmin-height\nmin-width\n<\/code><\/pre>\n<hr>\n<h1 id=\"css\u6a21\u578b\u6846\"><strong>CSS\u6a21\u578b\u6846<\/strong><\/h1>\n<h2 id=\"\u5185\u8fb9\u8ddd\u5c5e\u6027\">\u5185\u8fb9\u8ddd\u5c5e\u6027<\/h2>\n<pre><code>padding\npadding-top\npadding-rigit\npadding-bottom\npadding-left\n<\/code><\/pre>\n<h2 id=\"\u8fb9\u6846\u5c5e\u6027\">\u8fb9\u6846\u5c5e\u6027<\/h2>\n<pre><code>border\nborder-style\nborder-width\nborder-color\nborder-buttom\nborder-buttom-color\/style\/width\nborder-left\nborder-left-color\/style\/width\nborder-right\nborder-right-color\/style\/width\nborder-top\nborder-top-color\/style\/width\n<\/code><\/pre>\n<h2 id=\"\u5916\u8fb9\u8ddd\u5c5e\u6027\">\u5916\u8fb9\u8ddd\u5c5e\u6027<\/h2>\n<pre><code>margin # \u4f9d\u6b21\u4e3a\u4e0a\uff0c\u53f3\uff0c\u4e0b\uff0c\u5de6\uff0e\nmargin-right\nmargin-top\nmargin-bottom\nmargin-left\n<\/code><\/pre>\n<hr>\n<h1 id=\"css\u5b9a\u4f4d\"><strong>CSS\u5b9a\u4f4d<\/strong><\/h1>\n<pre><code>position # \u89c4\u5b9a\u5143\u7d20\u7684\u5b9a\u4f4d\ntop\nright\nbottom\nleft\noverflow # \u5185\u5bb9\u76ca\u5904\u5143\u7d20\u6846\u65f6\uff0cvisible\/hidden\/scroll\/auto\/inderit\nclip\nvertical-align\nz-index\ndisplay # \u89c4\u5b9a\u5143\u7d20\u5e94\u8be5\u751f\u6210\u7684\u6846\u7684\u7c7b\u578b, inline\/none\/block\/...\nfloat # none\/left\/right\/inderit, \u89c4\u5b9a\u6846\u662f\u5426\u5e94\u8be5\u6d6e\u52a8\n<\/code><\/pre>\n<hr>\n<h2 id=\"color\">color<\/h2>\n<p>16\u8fdb\u5236 \u548c rgb\u8868\u793a<\/p>\n<pre><code>rgb(255,255,255) == #FFFFFF == white\nrgb(0,0,0) == #000000 == black\nrgb(255,0,0) == red\nrgb(0,255,0) == green\nrgb(0,0,255) == blue\nrgb(255,255,0) == yellow\n<\/code><\/pre>"},{"title":"Html","link":"https:\/\/canuxcheng.com\/post\/html\/","pubDate":"Thu, 23 Jun 2016 09:40:39 +0000","guid":"https:\/\/canuxcheng.com\/post\/html\/","description":"<h1 id=\"html\">HTML<\/h1>\n<p>HTML\u662f\u8d85\u6587\u672c\u6807\u8bb0\u8bed\u8a00<\/p>\n<h1 id=\"xhtml\">XHTML<\/h1>\n<p>XHTML\u662f\u66f4\u4e25\u8c28\u7684\u66f4\u7eaf\u51c0\u7684HTML<\/p>\n<h1 id=\"html5\">HTML5<\/h1>\n<p>HTML5\u662f\u4e0b\u4e00\u4ee3HTML<\/p>\n<hr>\n<h1 id=\"html\u5143\u7d20\u548c\u5c5e\u6027\"><strong>html\u5143\u7d20\u548c\u5c5e\u6027<\/strong><\/h1>\n<p>html\u5143\u7d20\u6307\u4ece\u5f00\u59cb\u6807\u7b7e\u5230\u7ed3\u675f\u6807\u7b7e\u7684\u6240\u6709\u4ee3\u7801,\u5305\u62ec\u5143\u7d20\u5185\u5bb9\uff1a<\/p>\n<p>html\u5143\u7d20\u53ef\u4ee5\u5d4c\u5957\u3002<\/p>\n<pre><code>&lt;p&gt; This is paragrph &lt;\/p&gt;\n&lt;p&gt;&lt;\/p&gt; # \u7a7a\u5185\u5bb9\u7684\u5143\u7d20\n&lt;br \/&gt; # \u7a7a\u5143\u7d20\uff0c\u5728\u5f00\u59cb\u6807\u7b7e\u4e2d\u5173\u95ed\n<\/code><\/pre>\n<p>html\u6807\u7b7e\u53ef\u4ee5\u62e5\u6709\u5c5e\u6027\uff0c\u5c5e\u6027\u603b\u662f\u4ee5name=&lsquo;value&rsquo;\u7684\u5f62\u5f0f\u51fa\u73b0\uff0c\u5c5e\u6027\u603b\u662f\u5728html\u5143\u7d20\u7684\u5f00\u59cb\u6807\u7b7e\u4e2d\u89c4\u5b9a\u3002<\/p>\n<pre><code>&lt;a href=&quot;http:\/\/www.test.com&quot;&gt;This is a link&lt;\/a&gt;\n<\/code><\/pre>\n<p>html\u5c5e\u6027\u548c\u503c\u5927\u5c0f\u5199\u4e0d\u654f\u611f\uff0c\u63a8\u8350\u4f7f\u7528\u5c0f\u5199,\u59cb\u7ec8\u7ed9\u5c5e\u6027\u503c\u52a0\u5f15\u53f7\u3002<\/p>\n<h2 id=\"html\u7684\u5168\u5c40\u5c5e\u6027\u6807\u51c6\u5c5e\u6027\">html\u7684\u5168\u5c40\u5c5e\u6027(\u6807\u51c6\u5c5e\u6027)<\/h2>\n<p>\u53c2\u8003\uff1a<\/p>\n<p><a class=\"link\" href=\"http:\/\/www.w3school.com.cn\/tags\/html_ref_standardattributes.asp\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.w3school.com.cn\/tags\/html_ref_standardattributes.asp<\/a><\/p>\n<h2 id=\"html\u7684\u4e8b\u4ef6\u5c5e\u6027\">html\u7684\u4e8b\u4ef6\u5c5e\u6027<\/h2>\n<p>\u53c2\u8003\uff1a<\/p>\n<p><a class=\"link\" href=\"http:\/\/www.w3school.com.cn\/tags\/html_ref_eventattributes.asp\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.w3school.com.cn\/tags\/html_ref_eventattributes.asp<\/a><\/p>\n<h2 id=\"html\u5b57\u7b26\u5b9e\u4f53\">html\u5b57\u7b26\u5b9e\u4f53<\/h2>\n<p>\u53c2\u8003\uff1a<\/p>\n<p><a class=\"link\" href=\"http:\/\/www.w3school.com.cn\/tags\/html_ref_entities.html\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.w3school.com.cn\/tags\/html_ref_entities.html<\/a><\/p>\n<hr>\n<h1 id=\"html\u57fa\u672c\u6807\u7b7e\"><strong>html\u57fa\u672c\u6807\u7b7e<\/strong><\/h1>\n<h2 id=\"doctype\">DOCTYPE<\/h2>\n<pre><code># \u6587\u6863\u7c7b\u578b\n&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n...\n&lt;\/head&gt;\n&lt;body&gt;\n...\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n<h2 id=\"html-1\">html<\/h2>\n<pre><code># html\u6587\u6863,\u652f\u6301\u5168\u5c40\u5c5e\u6027\n&lt;html&gt;\n...\n&lt;\/html&gt;\n# mainfest\u5c5e\u6027\uff0c\u5b9a\u4e49\u4e00\u4e2aurl\uff0c\u63cf\u8ff0\u6587\u6863\u7f13\u5b58\u4fe1\u606f\n# xmlns\u5c5e\u6027\uff0c\u5b9a\u4e49XML\u7684namespace\u5c5e\u6027\n<\/code><\/pre>\n<h2 id=\"\u6ce8\u91ca\">\u6ce8\u91ca<\/h2>\n<pre><code># \u6ce8\u91ca, \u6d4f\u89c8\u5668\u4f1a\u5ffd\u7565\u6ce8\u91ca,\u6ca1\u6709\u4efb\u4f55\u5c5e\u6027\n&lt;!-- This is a comment --&gt;\n<\/code><\/pre>\n<h2 id=\"\u7a7a\u683c\">\u7a7a\u683c<\/h2>\n<pre><code>&amp;nbsp; # \u7a7a\u683c\n<\/code><\/pre>\n<hr>\n<h1 id=\"head\"><strong>head<\/strong><\/h1>\n<h2 id=\"head-1\">head<\/h2>\n<p>\u53ef\u4ee5\u5728head\u6807\u7b7e\u4e2d\u4f7f\u7528\u7684\u6807\u7b7e\uff1a link, style, base, meta, script, title.<\/p>\n<pre><code># html\u6587\u6863\u7684\u5934\u90e8, head\u652f\u6301\u5168\u5c40\u5c5e\u6027\n&lt;head&gt;\n&lt;base&gt;\n&lt;meta&gt;\n&lt;title&gt; \u5fc5\u987b\u7684\n&lt;link&gt;\n&lt;style&gt;\n&lt;script&gt;\n&lt;\/head&gt;\n# profile\u5c5e\u6027\n<\/code><\/pre>\n<h2 id=\"title\">title<\/h2>\n<p>\u5b9a\u4e49\u6587\u6863\u6807\u9898\uff0c\u652f\u6301\u5168\u5c40\u5c5e\u6027\u3002<\/p>\n<pre><code># dir\u5c5e\u6027\u89c4\u5b9a\u5143\u7d20\u4e2d\u5185\u5bb9\u7684\u6587\u672c\u65b9\u5411\n# lang\u5c5e\u6027\u89c4\u5b9a\u5143\u7d20\u4e2d\u5185\u5bb9\u7684\u8bed\u8a00\u7f16\u7801\n# xml:lang\u5c5e\u6027\u89c4\u5b9axhtml\u6587\u6863\u4e2d\u5143\u7d20\u5185\u5bb9\u7684\u8bed\u8a00\u7f16\u7801\n<\/code><\/pre>\n<h2 id=\"base\">base<\/h2>\n<p>\u5b9a\u4e49\u9875\u9762\u6240\u6709\u7684\u94fe\u63a5\u7684\u9ed8\u8ba4\u5730\u5740\u548c\u9ed8\u8ba4\u76ee\u6807\u3002<\/p>\n<pre><code># href\u5c5e\u6027\u89c4\u5b9a\u9875\u9762\u4e2d\u6240\u6709\u76f8\u5bf9\u94fe\u63a5\u7684\u57fa\u51c6url\n# target\u5c5e\u6027\u89c4\u5b9a\u5728\u4f55\u5904\u6253\u5f00\u9875\u9762\u4e2d\u7684\u94fe\u63a5\n<\/code><\/pre>\n<h2 id=\"meta\">meta<\/h2>\n<p>\u5b9a\u4e49\u5143\u6570\u636e,\u652f\u6301\u5168\u5c40\u5c5e\u6027<\/p>\n<pre><code># content\u5c5e\u6027\n# http-equiv\n# name\n# scheme\n<\/code><\/pre>\n<hr>\n<h1 id=\"body\"><strong>body<\/strong><\/h1>\n<h2 id=\"body-1\">body<\/h2>\n<pre><code># html\u6587\u6863\u7684\u4e3b\u4f53, \u652f\u6301\u6837\u5f0f\uff0c\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027\n&lt;body&gt;\n&lt;\/body&gt;\n<\/code><\/pre>\n<h2 id=\"h1-h6\">h1-h6<\/h2>\n<pre><code># \u6807\u9898,\u6d4f\u89c8\u5668\u4f1a\u81ea\u52a8\u5728\u6807\u9898\u524d\u540e\u6dfb\u52a0\u7a7a\u884c,\u652f\u6301\u6837\u5f0f\n&lt;h1&gt;This is the max heading&lt;\/h1&gt;\n...\n&lt;h6&gt;This is the min heading&lt;\/h6&gt;\n# \u652f\u6301\u90e8\u5206\u5168\u5c40\u5c5e\u6027\n# id,class,title,style,dir,lang,xml:lang\n# \u652f\u6301\u90e8\u5206\u4e8b\u4ef6\u5c5e\u6027\n# onclick,ondblclick,onmousedown,onmouseup,onmouseover,\n# onmousemove, ommouseout,onkeypress,onkeydown,onkeyup\n<\/code><\/pre>\n<h2 id=\"hr\">hr<\/h2>\n<pre><code># \u6c34\u5e73\u7ebf\u5206\u5272\u7ebf\uff0c\u652f\u6301\u6837\u5f0f\uff0c\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027\n&lt;hr \/&gt;\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u6bb5\u843d\"><strong>\u6bb5\u843d<\/strong><\/h1>\n<h2 id=\"p\">p<\/h2>\n<pre><code># \u6bb5\u843d, \u6d4f\u89c8\u5668\u4f1a\u81ea\u52a8\u5728\u6bb5\u843d\u524d\u540e\u6dfb\u52a0\u7a7a\u884c,\u652f\u6301\u6837\u5f0f\uff0c\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027\n&lt;p&gt;This is a paragraph&lt;\/p&gt;\n<\/code><\/pre>\n<h2 id=\"br\">br<\/h2>\n<pre><code># \u7a7a\u884c, \u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027\n&lt;br \/&gt;\n# clear\u5c5e\u6027\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u94fe\u63a5\u548c\u56fe\u50cf\"><strong>\u94fe\u63a5\u548c\u56fe\u50cf<\/strong><\/h1>\n<p>URL: Uniform Resource Locator<\/p>\n<pre><code>scheme:\/\/host.domain:port\/path\/filename\nscheme: http\/https\/ftp\/file\n<\/code><\/pre>\n<p>url\u53ea\u80fd\u4f7f\u7528ASCII\u5b57\u7b26\u96c6\u3002<\/p>\n<p>\u53c2\u8003\uff1a<\/p>\n<p><a class=\"link\" href=\"http:\/\/www.w3school.com.cn\/tags\/html_ref_urlencode.html\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.w3school.com.cn\/tags\/html_ref_urlencode.html<\/a><\/p>\n<h2 id=\"a\">a<\/h2>\n<p>\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027<\/p>\n<pre><code># href\u5c5e\u6027\u5b9a\u4e49\u6307\u5411\u53e6\u4e00\u4e2a\u6587\u6863\u7684\u94fe\u63a5\n&lt;a href=&quot;http:\/\/www.test.com&quot;&gt;Click me as link&lt;\/a&gt;\n# target\u5c5e\u6027\uff0c\u5b9a\u4e49\u88ab\u94fe\u63a5\u7684\u6587\u6863\u5728\u4f55\u5904\u663e\u793a, blank\u5728\u65b0\u7a97\u53e3\u663e\u793a,rect, circle, poly\n&lt;a href=&quot;http:\/\/www.test.com&quot; target=&quot;_blank&quot;&gt;Link&lt;\/a&gt;\n# name\u5c5e\u6027\u5b9a\u4e49\u6587\u6863\u5185\u7684\u4e66\u7b7e\n&lt;a href=&quot;http:\/\/www.test.com&quot; name=&quot;label&quot;&gt;Link&lt;\/a&gt;\n# hreflang\n# rel\n# download\n# media\n# type\n<\/code><\/pre>\n<h2 id=\"img\">img<\/h2>\n<p>\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027<\/p>\n<pre><code># src\u5c5e\u6027\u5b9a\u4e49\u6e90\n&lt;img src=&quot;url&quot; \/&gt;\n# alt\u5c5e\u6027\uff0c\u5f53\u56fe\u50cf\u4e0d\u80fd\u663e\u793a\uff0c\u5c31\u663e\u793aalt\u7684\u9ed8\u8ba4\u503c\u3002\n&lt;img src=&quot;http:\/\/www.test.com\/images\/test.img&quot; alt=&quot;default value&quot;\/&gt;\n# height\n# ismap\n# longdesc\n# usemap\n# width\n<\/code><\/pre>\n<h2 id=\"map\">map<\/h2>\n<p>\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027<\/p>\n<pre><code># id\u5c5e\u6027\u4e3amap\u5b9a\u4e49\u552f\u4e00\u7684\u540d\u79f0\n&lt;map id=&quot;planetmap&quot;&gt;\n...\n&lt;\/map&gt;\n# name\u5c5e\u6027\u4e3aimage-map\u89c4\u5b9a\u7684\u540d\u79f0\n<\/code><\/pre>\n<h2 id=\"area\">area<\/h2>\n<p>\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027<\/p>\n<pre><code># alt\n# coords\n# href\n# nohref\n# shape\n# target\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u6837\u5f0f\"><strong>\u6837\u5f0f<\/strong><\/h1>\n<p>\u5185\u8054\u6837\u5f0f,\u5b9a\u4e49\u5728html\u5143\u7d20\u5185\u90e8\u3002style\u6837\u5f0f\u5c5e\u6027\u53ef\u4ee5\u5305\u542b\u4efb\u4f55\u7684css\u5c5e\u6027\u3002<\/p>\n<p>\u5185\u8054\u6837\u5f0f\u4f18\u5148\u7ea7\u6700\u9ad8\u3002<\/p>\n<pre><code>&lt;h1 style=&quot;font-family:verdana&quot;&gt;A heading&lt;\/h1&gt;\n&lt;p style=&quot;font-family:arial;color:red;font-size:20px&quot;&gt;A paragraph&lt;\/p&gt;\n<\/code><\/pre>\n<h2 id=\"style\">style<\/h2>\n<p>\u5185\u90e8\u6837\u5f0f\u8868,\u4f4d\u4e8ehead\u6807\u7b7e\u5185\u90e8\u3002\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027<\/p>\n<p>\u4f18\u5148\u7ea7\u4ec5\u6b21\u4e8e\u5185\u8054\u6837\u5f0f\u3002<\/p>\n<pre><code>&lt;head&gt;\n&lt;style type=&quot;text\/css&quot;&gt;\nh1 {color: red}\np {color: blue}\n&lt;\/style&gt;\n&lt;\/head&gt;\n# type\u5c5e\u6027\u89c4\u5b9a\u6837\u5f0f\u8868\u7684MIME\u7c7b\u578b\n# media\u5c5e\u6027\u89c4\u5b9a\u4e0d\u540c\u7684\u5a92\u4f53\u7c7b\u578b\n<\/code><\/pre>\n<h2 id=\"link\">link<\/h2>\n<p>\u5916\u90e8\u6837\u5f0f\u8868,\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027<\/p>\n<p>\u4f18\u5148\u7ea7\u4ec5\u9ad8\u4e8e\u6d4f\u89c8\u5668\u7f3a\u7701\u503c\u3002<\/p>\n<pre><code>&lt;head&gt;\n&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;mystyle.css&quot;&gt;\n&lt;\/head&gt;\n# href\u5c5e\u6027\u89c4\u5b9a\u88ab\u94fe\u63a5\u6587\u6863\u7684\u4f4d\u7f6e\n# hreflang\u5c5e\u6027\u89c4\u5b9a\u88ab\u94fe\u63a5\u6587\u6863\u4e2d\u6587\u672c\u7684\u8bed\u8a00\n# media\u5c5e\u6027\u89c4\u5b9a\u88ab\u94fe\u63a5\u6587\u6863\u88ab\u663e\u793a\u5728\u4ec0\u4e48\u8bbe\u5907\n# rel\u5c5e\u6027\u89c4\u5b9a\u5f53\u524d\u6587\u6863\u4e0e\u88ab\u94fe\u63a5\u6587\u6863\u7684\u5173\u7cfb\n# sizes\u5c5e\u6027\u89c4\u5b9arel='icon'\u7684\u5c3a\u5bf8\n# type\u5c5e\u6027\u89c4\u5b9a\u88ab\u94fe\u63a5\u6587\u6863\u7684MINE\u7c7b\u578b\n<\/code><\/pre>\n<h2 id=\"div\">div<\/h2>\n<p>\u5206\u7c7b\u5757\u7ea7\u5143\u7d20,\u652f\u6301\u6837\u5f0f\uff0c\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027<\/p>\n<pre><code>&lt;div&gt; \u4f7f\u7528\u6837\u5f0f\u5c5e\u6027\n<\/code><\/pre>\n<h2 id=\"span\">span<\/h2>\n<p>\u5206\u7c7b\u884c\u5185\u5143\u7d20\uff0c\u652f\u6301\u6837\u5f0f\uff0c\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027<\/p>\n<pre><code>&lt;span&gt; \u5b9a\u4e49\u6587\u6863\u4e2d\u7684\u884c\u5185\u7684\u5757\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u683c\u5f0f\u5316\"><strong>\u683c\u5f0f\u5316<\/strong><\/h1>\n<h2 id=\"\u6587\u672c\u683c\u5f0f\u5316\u6807\u7b7e\">\u6587\u672c\u683c\u5f0f\u5316\u6807\u7b7e<\/h2>\n<pre><code>&lt;b&gt; \u5b9a\u4e49\u7c97\u4f53\u6587\u672c\n&lt;big&gt; \u5b9a\u4e49\u5927\u53f7\u5b57\n&lt;em&gt; \u5b9a\u4e49\u7740\u91cd\u6587\u5b57\n&lt;i&gt; \u5b9a\u4e49\u659c\u4f53\u5b57\n&lt;small&gt; \u5b9a\u4e49\u5c0f\u53f7\u5b57\n&lt;strong&gt; \u5b9a\u4e49\u52a0\u91cd\u8bed\u6c14\n&lt;sub&gt; \u5b9a\u4e49\u4e0b\u6807\u5b57\n&lt;sup&gt; \u5b9a\u4e49\u4e0a\u6807\u5b57\n&lt;ins&gt; \u5b9a\u4e49\u63d2\u5165\u5b57\n&lt;del&gt; \u5b9a\u4e49\u5220\u9664\u5b57\n<\/code><\/pre>\n<h2 id=\"\u8ba1\u7b97\u673a\u8f93\u51fa\u6807\u7b7e\">\u8ba1\u7b97\u673a\u8f93\u51fa\u6807\u7b7e<\/h2>\n<pre><code>&lt;code&gt; \u5b9a\u4e49\u8ba1\u7b97\u673a\u4ee3\u7801\n&lt;kbd&gt; \u5b9a\u4e49\u952e\u76d8\u7801\n&lt;samp&gt; \u5b9a\u4e49\u8ba1\u7b97\u673a\u4ee3\u7801\u6837\u672c\n&lt;tt&gt; \u5b9a\u4e49\u6253\u5b57\u673a\u4ee3\u7801\n&lt;var&gt; \u5b9a\u4e49\u53d8\u91cf\n&lt;pre&gt; \u5b9a\u4e49\u9884\u683c\u5f0f\u6587\u672c\n<\/code><\/pre>\n<h2 id=\"\u5f15\u7528\u548c\u672f\u8bed\u6807\u7b7e\">\u5f15\u7528\u548c\u672f\u8bed\u6807\u7b7e<\/h2>\n<pre><code>&lt;abbr&gt; \u5b9a\u4e49\u7f29\u5199\n&lt;p&gt;&lt;abbr title=&quot;Hyper Text Markup Language&quot;&gt;HTML&lt;\/abbr&gt;is perfect.&lt;\/p&gt;\n&lt;acronym&gt; \u5b9a\u4e49\u9996\u5b57\u6bcd\u7f29\u5199\n&lt;address&gt; \u5b9a\u4e49\u5730\u5740\n&lt;bdo&gt; \u5b9a\u4e49\u6587\u5b57\u65b9\u5411\n&lt;blockquote&gt; \u5b9a\u4e49\u957f\u7684\u5f15\u7528\n&lt;q&gt; \u5b9a\u4e49\u77ed\u7684\u5f15\u7528\n&lt;cite&gt; \u5b9a\u4e49\u8457\u4f5c\u7684\u6807\u9898\n&lt;dfn&gt; \u5b9a\u4e49\u4e00\u4e2a\u9879\u76ee\u6216\u7f29\u5199\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u8868\u683c\"><strong>\u8868\u683c<\/strong><\/h1>\n<pre><code>&lt;table border=&quot;1&quot;&gt;\n&lt;caption&gt;The title&lt;\/caption&gt;\n&lt;tr&gt;\n&lt;th&gt;Month&lt;\/th&gt;\n&lt;th&gt;Saving&lt;\/th&gt;\n&lt;\/tr&gt;\n&lt;tr&gt;\n&lt;td&gt;Jan.&lt;\/td&gt;\n&lt;td&gt;$100&lt;\/td&gt;\n&lt;\/tr&gt;\n&lt;\/table&gt;\n<\/code><\/pre>\n<h2 id=\"table\">table<\/h2>\n<p>\u5b9a\u4e49\u8868\u683c,\u652f\u6301\u4e8b\u4ef6\u5c5e\u6027\u548c\u5168\u5c40\u5c5e\u6027<\/p>\n<pre><code># border\u5c5e\u6027\u89c4\u5b9a\u8868\u683c\u8fb9\u6846\u5bbd\u5ea6\n# cellpadding\u5c5e\u6027\u89c4\u5b9a\u5355\u5143\u8fb9\u6cbf\u4e0e\u5176\u5185\u5bb9\u4e4b\u95f4\u7684\u7a7a\u767d\n# cellspacing\u5c5e\u6027\u89c4\u5b9a\u5355\u5143\u683c\u4e4b\u95f4\u7684\u7a7a\u767d\n# frame\u5c5e\u6027\u89c4\u5b9a\u5916\u4fa7\u8fb9\u6846\u7684\u54ea\u4e2a\u90e8\u5206\u662f\u53ef\u89c1\u7684\n# rules\u5c5e\u6027\u89c4\u5b9a\u5185\u4fa7\u8fb9\u6846\u7684\u54ea\u4e2a\u90e8\u5206\u662f\u53ef\u89c1\u7684\n# summary\u5c5e\u6027\u89c4\u5b9a\u8868\u683c\u7684\u6458\u8981\n# width\u5c5e\u6027\u89c4\u5b9a\u8868\u683c\u7684\u5bbd\u5ea6\n<\/code><\/pre>\n<h2 id=\"caption\">caption<\/h2>\n<p>\u5b9a\u4e49\u8868\u683c\u6807\u9898,\u652f\u6301\u6837\u5f0f\uff0c\u652f\u6301\u4e8b\u4ef6\u5c5e\u6027\u548c\u5168\u5c40\u5c5e\u6027<\/p>\n<h2 id=\"tr\">tr<\/h2>\n<p>\u5b9a\u4e49\u8868\u683c\u7684\u884c,\u652f\u6301\u4e8b\u4ef6\u5c5e\u6027\u548c\u5168\u5c40\u5c5e\u6027<\/p>\n<pre><code># align\u5c5e\u6027\u5b9a\u4e49\u8868\u683c\u5185\u5bb9\u5bf9\u9f50\u65b9\u5f0f\n# char\u5c5e\u6027\u89c4\u5b9a\u6839\u636e\u54ea\u4e2a\u5b57\u7b26\u6765\u8fdb\u884c\u6587\u672c\u5bf9\u9f50\n# charoff\u5c5e\u6027\u89c4\u5b9a\u7b2c\u4e00\u4e2a\u5bf9\u9f50\u5b57\u7b26\u7684\u504f\u79fb\u91cf\n# valign\u5c5e\u6027\u89c4\u5b9a\u8868\u683c\u4e2d\u5185\u5bb9\u7684\u5782\u76f4\u5bf9\u9f50\u65b9\u5f0f\n<\/code><\/pre>\n<h2 id=\"th-td\">th td<\/h2>\n<p>th\u5b9a\u4e49\u8868\u683c\u8868\u5934,\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027<\/p>\n<p>td\u5b9a\u4e49\u8868\u683c\u5355\u5143,\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027<\/p>\n<pre><code># abbr\u5c5e\u6027\u89c4\u5b9a\u5355\u5143\u683c\u4e2d\u5185\u5bb9\u7684\u7f29\u5199\u7248\u672c\n# align\u5c5e\u6027\u89c4\u5b9a\u5355\u5143\u683c\u5185\u5bb9\u7684\u6c34\u5e73\u5bf9\u9f50\u65b9\u5f0f\n# axis\u5c5e\u6027\u5bf9\u5355\u5143\u8fdb\u884c\u5206\u7c7b\n# char\n# charoff\n# colspan\n# headers\n# rowspan\n# scope\n# valign\n<\/code><\/pre>\n<h2 id=\"col\">col<\/h2>\n<p>\u5b9a\u4e49\u7528\u4e8e\u8868\u683c\u7684\u5c5e\u6027<\/p>\n<h2 id=\"colgroup\">colgroup<\/h2>\n<p>\u5b9a\u4e49\u8868\u683c\u7684\u7ec4<\/p>\n<hr>\n<h1 id=\"\u5217\u8868\"><strong>\u5217\u8868<\/strong><\/h1>\n<h2 id=\"ol\">ol<\/h2>\n<p>\u5b9a\u4e49\u6709\u5e8f\u5217\u8868,\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027<\/p>\n<pre><code>&lt;ol&gt;\n&lt;li&gt;first one&lt;\/li&gt;\n&lt;li&gt;second one&lt;\/li&gt;\n&lt;\/ol&gt;\n# reversed\u5c5e\u6027\u89c4\u5b9a\u5217\u8868\u987a\u5e8f\u4e3a\u964d\u5e8f\n# start\u5c5e\u6027\u6709\u5e8f\u5217\u8868\u7684\u8d77\u59cb\u503c\n# type\u5c5e\u6027\u89c4\u5b9a\u5728\u5217\u8868\u4e2d\u4f7f\u7528\u7684\u6807\u8bb0\u7c7b\u578b\n<\/code><\/pre>\n<h2 id=\"ul\">ul<\/h2>\n<p>\u5b9a\u4e49\u65e0\u5e8f\u5217\u8868,\u652f\u6301\u6837\u5f0f\uff0c\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027<\/p>\n<pre><code>&lt;ul&gt;\n&lt;li&gt;coffee&lt;\/li&gt;\n&lt;li&gt;tea&lt;\/li&gt;\n&lt;ul&gt;\n<\/code><\/pre>\n<h2 id=\"li\">li<\/h2>\n<p>\u5b9a\u4e49\u5217\u8868\u9879,\u652f\u6301\u6837\u5f0f\uff0c\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027<\/p>\n<h2 id=\"dl-dt-dd\">dl dt dd<\/h2>\n<p>dl\u5b9a\u4e49\u5b9a\u4e49\u5217\u8868,dt\u5b9a\u4e49\u5b9a\u4e49\u9879\u76ee,dd\u5b9a\u4e49\u5b9a\u4e49\u7684\u63cf\u8ff0,\u90fd\u652f\u6301\u5168\u5c40\u5c5e\u6027\u548c\u4e8b\u4ef6\u5c5e\u6027<\/p>\n<pre><code>&lt;dl&gt;\n&lt;dt&gt;computer&lt;\/dt&gt;\n&lt;dd&gt;used to monitor...&lt;\/dd&gt;\n&lt;\/dl&gt;\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u7f51\u7ad9\u5e03\u5c40\"><strong>\u7f51\u7ad9\u5e03\u5c40<\/strong><\/h1>\n<p>\u4f7f\u7528html5\u7684\u7f51\u7ad9\u5e03\u5c40\u6807\u7b7e.<\/p>\n<pre><code>&lt;head&gt;\n&lt;style&gt;\nheader {}\nnav {}\nsection {}\nfooter {}\n&lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;header&gt;...&lt;\/header&gt;\n...\n&lt;footer&gt;...&lt;\/footer&gt;\n&lt;\/body&gt;\n<\/code><\/pre>\n<p>\u4e5f\u53ef\u4ee5\u4f7f\u7528id\u9009\u62e9\u5668\uff1a<\/p>\n<pre><code>&lt;head&gt;\n&lt;style&gt;\n#header {}\n...\n#footer {}\n&lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;div id=&quot;header&quot;&gt;...&lt;\/div&gt;\n...\n&lt;div id=&quot;footer&quot;&gt;...&lt;\/div&gt;\n&lt;\/body&gt;\n<\/code><\/pre>\n<h2 id=\"header\u6807\u7b7e\">header\u6807\u7b7e<\/h2>\n<h2 id=\"nav\u6807\u7b7e\">nav\u6807\u7b7e<\/h2>\n<h2 id=\"section\u6807\u7b7e\">section\u6807\u7b7e<\/h2>\n<h2 id=\"article\u6807\u7b7e\">article\u6807\u7b7e<\/h2>\n<h2 id=\"aside\u6807\u7b7e\">aside\u6807\u7b7e<\/h2>\n<h2 id=\"footer\u6807\u7b7e\">footer\u6807\u7b7e<\/h2>\n<h2 id=\"details\u6807\u7b7e\">details\u6807\u7b7e<\/h2>\n<h2 id=\"summary\u6807\u7b7e\">summary\u6807\u7b7e<\/h2>\n<hr>\n<h1 id=\"\u6846\u67b6\"><strong>\u6846\u67b6<\/strong><\/h1>\n<p>\u6846\u67b6\u53ef\u4ee5\u5728\u4e00\u4e2ahtml\u6dfb\u52a0\u591a\u4e2a\u9875\u9762\u3002<\/p>\n<p>\u5782\u76f4\u6846\u67b6\uff1a<\/p>\n<pre><code>&lt;frameset cols=&quot;50%, 50%&quot;&gt;\n&lt;frame src=&quot;a.html&quot;&gt;\n&lt;frame src=&quot;b.html&quot;&gt;\n&lt;\/frameset&gt;\n<\/code><\/pre>\n<p>\u6c34\u5e73\u6846\u67b6\uff1a<\/p>\n<pre><code>&lt;frameset rows=&quot;50%, 50%&quot;&gt;\n&lt;frame src=&quot;a.html&quot;&gt;\n&lt;frame src=&quot;b.html&quot;&gt;\n&lt;\/frameset&gt;\n<\/code><\/pre>\n<p>\u6df7\u5408\u6846\u67b6\uff1a<\/p>\n<pre><code>&lt;frameset rows=&quot;50%, 50%&quot;&gt;\n&lt;frame src=&quot;a.html&quot;&gt;\n&lt;frameset cols=&quot;%25, 75%&quot;&gt;\n&lt;frame src=&quot;b.html&quot;&gt;\n&lt;frame src=&quot;c.html&quot;&gt;\n&lt;\/frameset&gt;\n&lt;\/frameset&gt;\n<\/code><\/pre>\n<h2 id=\"frameset\u6807\u7b7e\">frameset\u6807\u7b7e<\/h2>\n<pre><code># cols\u5c5e\u6027\u5b9a\u4e49\u6846\u67b6\u4e2d\u5217\u7684\u6570\u76ee\u548c\u5c3a\u5bf8\n# rows\u5c5e\u6027\u5b9a\u4e49\u6846\u67b6\u4e2d\u884c\u7684\u6570\u76ee\u548c\u5c3a\u5bf8\n# \u6807\u51c6\u5c5e\u6027\uff1a\nid,class,title,style\n<\/code><\/pre>\n<h2 id=\"frame\u6807\u7b7e\">frame\u6807\u7b7e<\/h2>\n<p>\u5b9a\u4e49frameset\u4e2d\u7684\u4e00\u4e2a\u7279\u5b9a\u7684\u7a97\u53e3\u3002<\/p>\n<pre><code># frameborder\u5c5e\u6027\u89c4\u5b9a\u662f\u5426\u73b0\u5b9e\u6846\u67b6\u5468\u56f4\u7684\u8fb9\u6846\n# longdesc\u5c5e\u6027\n# marginheight\u5c5e\u6027\n# marginwidth\u5c5e\u6027\n# name\u5c5e\u6027\n# scrolling\u5c5e\u6027\n# src\u5c5e\u6027\n# \u6807\u51c6\u5c5e\u6027\uff1a\nid,class,title,style\n<\/code><\/pre>\n<h2 id=\"iframe\u6807\u7b7e\">iframe\u6807\u7b7e<\/h2>\n<p>\u5185\u8054\u6846\u67b6\u3002<\/p>\n<p>\u628a\u5185\u5bb9\u653e\u5728iframe\u6807\u7b7e\u4e2d\uff0c\u5728\u65e0\u6cd5\u7406\u89e3iframe\u7684\u6d4f\u89c8\u5668\u663e\u793a\u3002<\/p>\n<p>\u652f\u6301\u4e8b\u4ef6\u5c5e\u6027\u548c\u5168\u5c40\u5c5e\u6027\u3002<\/p>\n<pre><code># frameborder\u5c5e\u6027\n# height\u5c5e\u6027\n# width\u5c5e\u6027\n# longdesc\u5c5e\u6027\n# marginheight\u5c5e\u6027\n# marginwidth\u5c5e\u6027\n# name\u5c5e\u6027\n# scrolling\u5c5e\u6027\n# src\u5c5e\u6027\n# sandbox\n# seamless\n# srcdoc\n<\/code><\/pre>\n<h2 id=\"noframes\u6807\u7b7e\">noframes\u6807\u7b7e<\/h2>\n<hr>\n<h1 id=\"\u811a\u672c\"><strong>\u811a\u672c<\/strong><\/h1>\n<p>\u5728html\u4e2d\u63d2\u5165javascript\u7b49\u811a\u672c<\/p>\n<h2 id=\"script\u6807\u7b7e\">script\u6807\u7b7e<\/h2>\n<p>\u5b9a\u4e49\u5ba2\u6237\u7aef\u811a\u672c\uff0c\u652f\u6301\u5168\u5c40\u5c5e\u6027<\/p>\n<p>\u76f4\u63a5\u5d4c\u5165javascript\u4ee3\u7801\u65f6\u6ce8\u610f\u4ee3\u7801\u4e2d\u5982\u679c\u6709&lt;\/script&gt;\u9700\u8981\u8f6c\u4e49\uff0e<\/p>\n<p>\u901a\u8fc7src\u5c5e\u6027\u6307\u5b9a\u5916\u90e8javascript\u811a\u672c\u7684script\u6807\u7b7e\u4e2d\u4e0d\u80fd\u5305\u542b\u989d\u5916\u7684javascript\u4ee3\u7801\uff0e<\/p>\n<pre><code>&lt;!-- \u76f4\u63a5\u5d4c\u5165javascript\u4ee3\u7801 --&gt;\n&lt;script type=&quot;text\/javascript&quot;&gt;\ndocument.write(&quot;hello javascript&quot;)\n&lt;\/script&gt;\n&lt;!-- \u6307\u5b9a\u5916\u90e8javascript\u811a\u672c\u3000--&gt;\n&lt;script type=&quot;text\/javascript&quot; src=&quot;example.js&quot;&gt;&lt;\/script&gt;\n# type \u53ef\u9009\uff0c\u6307\u5b9a\u811a\u672cMIME\u7c7b\u578b\uff0c\u6bd4\u5982text\/javascript\n# src \u53ef\u9009\uff0c\u8868\u793a\u6307\u5b9a\u7684\u5916\u90e8\u6587\u4ef6\n# charset \u53ef\u9009\uff0c\u8868\u793a\u901a\u8fc7src\u5c5e\u6027\u6307\u5b9a\u7684\u4ee3\u7801\u7684\u5b57\u7b26\u96c6\n# defer \u53ef\u9009\uff0c\u8868\u793a\u5916\u90e8\u811a\u672c\u53ef\u4ee5\u5ef6\u8fdf\u5230\u6587\u6863\u5b8c\u5168\u88ab\u89e3\u6790\u548c\u663e\u793a\u4e4b\u540e\u518d\u6267\u884c\n# async \u53ef\u9009\uff0c\u8868\u793a\u5e94\u8be5\u7acb\u5373\u4e0b\u8f7d\u5916\u90e8\u811a\u672c\n&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n...head content...\n&lt;!-- head\u4e2d\u7684script\u662f\u8c03\u7528\u624d\u6267\u884c\u7684\uff0c\u6216\u8005\u662f\u4e8b\u4ef6\u89e6\u53d1\u7684\uff0c\u53ef\u4ee5\u63d0\u524d\u5907\u52a0\u8f7d --&gt;\n&lt;script&gt;...&lt;\/script&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n...body content...\n&lt;!-- \u9875\u9762\u5185\u5bb9\u5148\u5448\u73b0\uff0c\u7136\u540e\u6309\u987a\u5e8f\u52a0\u8f7d\u548c\u89e3\u6790\u811a\u672c --&gt;\n&lt;script type=&quot;text\/javascript&quot; src=&quot;example.js&quot;&gt;&lt;\/script&gt;\n&lt;!-- defer\u8868\u793a\u6574\u4e2a\u9875\u9762\u89e3\u6790\u5b8c\u540e\u624d\u52a0\u8f7d\u548c\u89e3\u6790\u811a\u672c --&gt;\n&lt;script type=&quot;text\/javascript&quot; defer=&quot;defer&quot; src=&quot;example.js&quot;&gt;&lt;\/script&gt;\n&lt;!-- async\u8868\u793a\u5728\u52a0\u8f7d\u9875\u9762\u671f\u95f4\u5f02\u6b65\u52a0\u8f7d\u548c\u89e3\u6790\u811a\u672c --&gt;\n&lt;script type=&quot;text\/javascript&quot; async src=&quot;example.js&quot;&gt;&lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n<h2 id=\"noscript\u6807\u7b7e\">noscript\u6807\u7b7e<\/h2>\n<p>\u9488\u5bf9\u65e9\u671f\u4e0d\u652f\u6301javascript\u7684\u6d4f\u89c8\u5668\uff0c\u4e3a\u4e0d\u652f\u6301\u5ba2\u6237\u7aef\u811a\u672c\u7684\u6d4f\u89c8\u5668\u5b9a\u4e49\u66ff\u4ee3\u5185\u5bb9,\u652f\u6301\u5168\u5c40\u5c5e\u6027<\/p>\n<p>\u5f53\u6d4f\u89c8\u5668\u4e0d\u652f\u6301\uff0c\u5c31\u663e\u793anoscript\u6807\u7b7e\u7684\u5185\u5bb9\uff0c\u5426\u5219\u5c31\u4e0d\u663e\u793a\uff0e<\/p>\n<pre><code>&lt;script type=&quot;text\/javascript&quot; src=&quot;example.js&quot;&gt;&lt;\/script&gt;\n&lt;noscript&gt;Your browser does not support javascript&lt;\/noscript&gt;\n<\/code><\/pre>"},{"title":"PSL_Package","link":"https:\/\/canuxcheng.com\/post\/psl_package\/","pubDate":"Wed, 22 Jun 2016 05:17:19 +0000","guid":"https:\/\/canuxcheng.com\/post\/psl_package\/","description":"<h1 id=\"packaging-and-distribution\">Packaging and Distribution<\/h1>\n<p>PEP426\u662fpython\u6700\u65b0\u7684\u6253\u5305\u6807\u51c6\uff0c\u5b9a\u4e49\u4e86wheel\u4e3a\u6700\u65b0\u7684python\u5305\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.python.org\/dev\/peps\/pep-0426\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.python.org\/dev\/peps\/pep-0426\/<\/a><\/p>\n<h2 id=\"ensurepip\">ensurepip<\/h2>\n<p>python3.4\u5f00\u59cb\u5185\u7f6e\u4e86ensurepip\u6a21\u5757\uff0c\u7528\u4e8e\u5b89\u88c5pip\u548csetuptools\u3002<\/p>\n<pre><code>$ python3 -m ensurepip --default-pip\n<\/code><\/pre>\n<h2 id=\"venv\">venv<\/h2>\n<p>python3.3\u5f00\u59cb\u5185\u7f6e\u4e86venv\u6a21\u5757\uff0c\u7528\u4e8e\u521b\u5efa\u865a\u62df\u73af\u5883\u3002<\/p>\n<pre><code>$ python3 -m venv .env\n<\/code><\/pre>\n<h2 id=\"zipapp\">zipapp<\/h2>\n<p>python3.5\u5f00\u59cb\u5185\u7f6e\u4e86zipapp\u6a21\u5757\uff0c\u7528\u4e8e\u521b\u5efa\u53ef\u6267\u884c\u7684zip\u5305\u3002<\/p>\n<pre><code>$ python3 -m zipapp myapp -o myapp.pyz\n<\/code><\/pre>\n<hr>\n<h2 id=\"tpl\">TPL<\/h2>\n<p>\u76f8\u5173\u7684\u7b2c\u4e09\u65b9\u5e93<\/p>\n<h3 id=\"virtualenvdeprecated\">virtualenv(deprecated)<\/h3>\n<p>python3.5\u5f00\u59cb\u5e76\u5165\u4e86\u865a\u62df\u5316\u6807\u51c6\u5e93venv.<\/p>\n<p>\u5206\u79bb\u7684\u865a\u62df\u7684python\u73af\u5883,\u81ea\u52a8\u5b89\u88c5setuptools\u548cpip.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/pypa\/virtualenv\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/pypa\/virtualenv<\/a><\/p>\n<p>virtualenvwrapper<\/p>\n<p><a class=\"link\" href=\"https:\/\/bitbucket.org\/virtualenvwrapper\/virtualenvwrapper\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/bitbucket.org\/virtualenvwrapper\/virtualenvwrapper<\/a><\/p>\n<p>\u5c01\u88c5\u4e86virtualenv\u7684\u5de5\u5177:<\/p>\n<pre><code>$ pip install virtualenvwrapper\n<\/code><\/pre>\n<p>pipenv<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/pypa\/pipenv\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/pypa\/pipenv<\/a><\/p>\n<p>\u5c01\u88c5\u4e86virtualenv\u7684\u5de5\u5177\uff0c\u7528\u4e8e\u53d6\u4ee3virtualenvwrapper.<\/p>\n<h3 id=\"setuptools\">setuptools<\/h3>\n<p><a class=\"link\" href=\"https:\/\/github.com\/pypa\/setuptools\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/pypa\/setuptools<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/pypa\/wheel\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/pypa\/wheel<\/a><\/p>\n<p>python2.7.9\u548cpython3.4\u4ee5\u53cavirtualenv\u81ea\u5e26setuptools\uff0e<\/p>\n<p>\u652f\u6301sdist\u6253\u5305\u6210tar.gz\u5305,\u548cwheel\u6253\u5305\u6210whl\u5305\uff0e<\/p>\n<pre><code>$pip install -U pip\n$pip install -U setuotools\n$pip install -U wheel\n<\/code><\/pre>\n<p>\u521b\u5efasetup.py\u6587\u4ef6\uff1a<\/p>\n<p><a class=\"link\" href=\"https:\/\/pypi.python.org\/pypi?%3Aaction=list_classifiers\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/pypi.python.org\/pypi?%3Aaction=list_classifiers<\/a><\/p>\n<pre><code>import os\nfrom setuptools import setup, find_packages\nimport project\ndef read(readme):\nextend = os.path.splitext(readme)[1]\n# pypi\u53ea\u8bc6\u522breST\u683c\u5f0f\nif (extend == &quot;.rst&quot;):\nimport codecs\nreturn codecs.open(readme, 'r', 'utf-8').read()\n# pypandoc\u53ef\u4ee5\u5c06markdown\u683c\u5f0f\u8f6c\u6362\u6210reST\u683c\u5f0f\nelif (extend == &quot;.md&quot;):\nimport pypandoc\nreturn pypandoc.convert(readme, 'rst')\nsetup(\n# metadata:\nname=project,\nversion=project.__version__,\nurl='',\ndownload_url='',\nauthor='',\nauthor_email='',\nmaintainer='',\nmaintainer_email='',\ndescription=''\nlong_description=read('README.XXX'),\nlicense='',\nplatforms='any',\nkeywords='',\nclassifiers=[\n'Development Status :: 5 - Production\/Stable',\n...\n],\n# options\n# \u6307\u5b9a\u6e90\u7801\u7684\u4f4d\u7f6e\npackages=find_packages(),\npackage_dir={},\n# \u9700\u8981\u548c\u6e90\u7801\u4e00\u8d77\u5b89\u88c5\u7684\u975e\u4ee3\u7801\u6587\u4ef6,\u5199\u5165MANIFEST.in\n# \u6bd4\u5982\u6587\u6863\u548c\u6d4b\u8bd5\u6587\u4ef6\npackage_data={}, # \u5c06\u6307\u5b9a\u7684\u6587\u4ef6\u653e\u5165\u5b89\u88c5\u8def\u5f84\ninclude_package_data=None, # True\u8868\u793a\nexclude_package_data=None,\n# \u4e0d\u9700\u8981\u548c\u6e90\u7801\u4e00\u8d77\u5b89\u88c5\u7684\u975e\u4ee3\u7801\u6587\u4ef6.\n# \u6bd4\u5982\u914d\u7f6e\u6587\u4ef6\ndata_files=[(dest, source),()],\n# \u901a\u8fc7pip\u5b89\u88c5requirement\ninstall_requires=['a==1.0.0', 'b&gt;=1.0.0'],\n# python\u7248\u672c\u7684\u8981\u6c42\npython_requires='&gt;=3',\nsetup_requires=[],\nextras_require=None,\ntest_require=[]\nzip_safe=True,\n# \u5b89\u88c5\u4e00\u4e2a\u547d\u4ee4\nscripts=[], # \u4f1a\u88ab\u6dfb\u52a0\u5230\u73af\u5883\u53d8\u91cf\u7528\u4e8e\u547d\u4ee4.\nentry_points={}\n# preinst\/postinst\ncmdclass={\n&quot;develop&quot;: PostInstDevelop,\n&quot;install&quot;: PostInstInstall\n}\n)\n<\/code><\/pre>\n<p>\u600e\u6837\u5b9e\u73b0postinst\u529f\u80fd\uff1a<\/p>\n<pre><code>from setuptools.command.develop import develop\nfrom setuptools.command.install import install\nclass InstDevelop(develop):\ndef run(self):\n# your preinst code here for develop.\ndevelop.run(self)\n# your postinst code here for develop.\nclass InstInstall(install):\ndef run(self):\n# your preinst code here for install.\ninstall.run(self)\n# your postinst code here for install.\n<\/code><\/pre>\n<p>\u521b\u5efasetup.cfg\u6587\u4ef6\uff1a<\/p>\n<pre><code>[wheel]\nuniversal = 1\n<\/code><\/pre>\n<p>\u521b\u5efaREADME.rst\u6587\u4ef6\uff1a<\/p>\n<p>\u53ef\u4ee5\u662frst\u683c\u5f0f\u4e5f\u53ef\u662f\u662fmd\u683c\u5f0f\u3002<\/p>\n<p>\u5982\u679c\u662fmd\u683c\u5f0f\u4e0d\u8981\u4f7f\u7528\u7c7b\u4f3c\u4e8e***\u7684\u5206\u5272\u7ebf\u3002<\/p>\n<pre><code>\u53c2\u8003rst\u548cmd\u7684\u6587\u6863\n<\/code><\/pre>\n<p>\u521b\u5efaMAINFEST.in\u6587\u4ef6\uff1a<\/p>\n<p>\u9ed8\u8ba4\u53ea\u6709python\u6a21\u5757\u548c\u5305\u4f1a\u88ab\u6253\u5305\uff0c\u5982\u679c\u9700\u8981\u5176\u5b83\u6587\u4ef6\u9700\u8981\u6dfb\u52a0\u5230\u8fd9\u4e2a\u6587\u4ef6\u4e2d\u3002<\/p>\n<pre><code>include LICENSE README.rst AUTHORS.rst CONTRIBUTING.rst\nrecursive-include docs *\ngraft examples\ngraft tests\nglobal-exclude *.py[co]\nprune docs\/_build\nprune docs\/_themes\n<\/code><\/pre>\n<p>\u521b\u5efa__init__.py\u6587\u4ef6\uff1a<\/p>\n<p>\u4f4d\u4e8eproject\/project\/__init__.py\uff0c\u5b89\u88c5\u540e\u7528import\u5bfc\u5165\uff0chelp(project)\u770b\u5230\u7684\u4fe1\u606f\u3002<\/p>\n<pre><code>NAME: \u81ea\u52a8\u83b7\u53d6\u7684\u9879\u76ee\u540d\u5b57 - \u8be5\u6587\u4ef6\u6ce8\u91ca\u7684\u603b\u7ed3\u90e8\u5206\nFILE: \/install_path\/project\/project\/__init__.py\nDESCRIPTION: \u8be5\u6587\u4ef6\u7684\u6ce8\u91ca\uff0c\u9664\u603b\u7ed3\u90e8\u5206\nPACKAGE CONTENTS: \u5728project\/project\/\u81ea\u52a8\u83b7\u53d6\u7684py\u6587\u4ef6\u540d\nDATA: __\u5f00\u5934\u548c\u7ed3\u5c3e\u7684\u53d8\u91cf\nVERSION: __version__\u53d8\u91cf\u7684\u503c\nAUTHOR: __author__\u53d8\u91cf\u7684\u503c\n#!\/usr\/bin\/env python\n# -*- coding: utf-8 -*-\n&quot;&quot;&quot;\nSUMMARY\nDescriptions\n&quot;&quot;&quot;\n__version__ = ''\n__author__ = ''\n...\n<\/code><\/pre>\n<p>\u53d1\u5e03\u5230pypi\u4e3b\u670d\u52a1\u5668pypi\uff1a<\/p>\n<p>\u53bbpypi\u6ce8\u518c\u5e10\u53f7<\/p>\n<p><a class=\"link\" href=\"https:\/\/pypi.python.org\/pypi\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/pypi.python.org\/pypi<\/a><\/p>\n<p>\u521b\u5efa~\/.pypirc\u6587\u4ef6<\/p>\n<pre><code>[distutils]\nindex-servers = pypi\n[pypi]\nusername = &lt;username&gt;\npassword = &lt;password&gt;\n<\/code><\/pre>\n<p>\u5728\u7d22\u5f15\u4e2d\u6ce8\u518c\u9879\u76ee(\u4e0d\u518d\u652f\u6301\uff0c\u76f4\u63a5upload)\uff1a<\/p>\n<pre><code>[Deprecated] $ python setup.py register -r pypi\n<\/code><\/pre>\n<p>\u5148\u6253\u5305, \u5728dist\u76ee\u5f55\u751f\u6210\u5305:<\/p>\n<pre><code>$ python setup.py sdist # \u751f\u6210tarball\n$ python setup.py bdist_wheel # \u5b89\u88c5wheel\u540e\uff0c\u53ef\u4ee5\u7528setuptools\u751f\u6210wheel\u5305\n<\/code><\/pre>\n<p>\u518d\u4e0a\u4f20\u5230pypi(\u63a8\u8350):<\/p>\n<pre><code>$ pip install twine\n$ twine upload dist\/*\n<\/code><\/pre>\n<p>\u6253\u5305\u5e76\u4e0a\u4f20\u5230pypi\uff1a<\/p>\n<pre><code>$python setup.py sdist upload -r pypi\n$python setup.py bdist_wheel upload -r pypi\n<\/code><\/pre>\n<h3 id=\"cython\">cython<\/h3>\n<p>\u7f16\u8bd1\u6210.so\u6587\u4ef6<\/p>\n<p>\u5b89\u88c5:<\/p>\n<pre><code>$ sudo pip install cython\n<\/code><\/pre>\n<p>\u5728setup.py\u4e2d\u5f15\u7528:<\/p>\n<pre><code>from Cython.Build import cythonize\nfrom Cython.Distutils import build_ext\ndef add_extensions(modules):\nextensions = []\nfor module in modules:\nlevel = module\nfor depth in range(10):\nsource_dir = level + &quot;.py&quot;\nif glob.glob(source_dir):\nextensions.append(Extension(module, [source_dir], include_dirs=[&quot;.&quot;], extra_compile_args=['-O3']),)\nlevel = os.path.join(level, &quot;*&quot;)\nprint(extensions)\nreturn extensions\nINCLUDE_PACKAGES = []\nEXCLUDE_PACKAGES = []\nsetup(\next_modules=cythonize(\nadd_extensions(INCLUDE_PACKAGES),\nbuild_dir=&quot;build&quot;,\n# \u6307\u5b9a .py =&gt; .c \u4f7f\u75288\u4e2a\u7ebf\u7a0b\u7f16\u8bd1.\nnthreads=8,\ncompiler_directives=dict(\nalways_allow_keywords=True,\nlanguage_level=3),\nexclude=EXCLUDE_PACKAGES),\ncmdclass={\n&quot;install&quot;: InstInstall,\n&quot;build_ext&quot;: build_ext\n},\n)\n\/\/ -j 8 \u6307\u5b9a.c =&gt; .so \u4f7f\u75288\u4e2a\u7ebf\u7a0b\u7f16\u8bd1.\n$ python3 setup.py build_ext --inplace -j 8\n\/\/ \u5220\u9664\u7b26\u53f7\u4fe1\u606f\n$ find sandbox\/ -name &quot;*.so&quot; -exec strip {} \\;\n<\/code><\/pre>\n<h3 id=\"pbr\">pbr<\/h3>\n<p><a class=\"link\" href=\"https:\/\/github.com\/openstack-dev\/pbr\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/openstack-dev\/pbr<\/a><\/p>\n<h3 id=\"\u6269\u5c55\u70b9entry-points\">\u6269\u5c55\u70b9\uff08Entry Points\uff09<\/h3>\n<ul>\n<li>\n<p>pkg_resources<\/p>\n<\/li>\n<li>\n<p>entry_point_inspector<\/p>\n<\/li>\n<\/ul>\n<p><a class=\"link\" href=\"https:\/\/github.com\/dhellmann\/entry_point_inspector\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/dhellmann\/entry_point_inspector<\/a><\/p>\n<ul>\n<li>stevedore<\/li>\n<\/ul>\n<p><a class=\"link\" href=\"http:\/\/docs.openstack.org\/developer\/stevedore\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/docs.openstack.org\/developer\/stevedore\/<\/a><\/p>"},{"title":"OOP","link":"https:\/\/canuxcheng.com\/post\/python_oop\/","pubDate":"Tue, 21 Jun 2016 21:18:09 +0000","guid":"https:\/\/canuxcheng.com\/post\/python_oop\/","description":"<h1 id=\"\u9762\u5411\u5bf9\u8c61oop\">\u9762\u5411\u5bf9\u8c61\/OOP<\/h1>\n<p>OOD: Object Oriented Design.<\/p>\n<p>\u9762\u5411\u8fc7\u7a0b\u7684\u8bbe\u8ba1\u652f\u6301\u4efb\u4f55\u8bed\u8a00\uff0c\u4f46\u662f\u5982\u679c\u8bed\u8a00\u672c\u8eab\u5185\u7f6e\u9762\u5411\u8fc7\u7a0b\u7684\u7ed3\u6784\uff0c\u5c31\u4f1a\u66f4\u5bb9\u6613\u7f16\u7a0b\uff0e<\/p>\n<p>OOP: Object Oriented Programming.<\/p>\n<p>python\u5185\u7f6eOOP\u7684\u7ed3\u6784\uff0c\u4f46\u662f\u4e0d\u5fc5\u4e00\u5b9a\u8981\u4f7f\u7528\u7c7b\u548cOOP.<\/p>\n<p>\u9762\u5411\u5bf9\u8c61\u7684\u4e24\u4e2a\u4e3b\u9898\u5c31\u662f\u7c7b\u548c\u7c7b\u5b9e\u4f8b\uff0e<\/p>\n<p>\u521b\u5efa\u5b9e\u4f8b\u7684\u8fc7\u7a0b\u53eb\u5b9e\u4f8b\u5316\uff0e<\/p>\n<p>\u5c5e\u6027\u5c31\u662f\u5c5e\u4e8e\u53e6\u4e00\u4e2a\u5bf9\u8c61\u7684\u6570\u636e\u6216\u51fd\u6570\u5143\u7d20\uff0e\u5c5e\u6027\u5206\u4e3a\u6570\u636e\u5c5e\u6027\u548c\u51fd\u6570\u5c5e\u6027\uff0e<\/p>\n<hr>\n<h1 id=\"\u7c7bclass\">\u7c7b\/Class<\/h1>\n<p>\u7c7b\u662f\u73b0\u5b9e\u4e16\u754c\u7684\u62bd\u8c61\u7684\u5b9e\u4f53\u4ee5\u7f16\u7a0b\u7684\u5f62\u5f0f\u51fa\u73b0\uff0c\u5b9e\u4f8b\u662f\u8fd9\u4e9b\u5bf9\u8c61\u7684\u5177\u4f53\u5316\uff0e<\/p>\n<p>\u7c7b\u662f\u4e00\u79cd\u6570\u636e\u7ed3\u6784\u7684\u5b9a\u4e49\uff0c\u5b9e\u4f8b\u662f\u7533\u660e\u4e86\u4e00\u4e2a\u8fd9\u79cd\u7c7b\u578b\u7684\u53d8\u91cf\uff0e<\/p>\n<p>\u7c7b\u7684\u5b9a\u4e49\uff1a<\/p>\n<p>Python 3 \u6240\u6709\u7c7b\u9ed8\u8ba4\u7ee7\u627f\u81ea object\uff0c\u5373\u4f7f\u4e0d\u5199 (object) \u4e5f\u662f\u65b0\u5f0f\u7c7b\u3002\u5efa\u8bae\u4fdd\u7559 (object) \u4ee5\u517c\u5bb9\u6027\u548c\u53ef\u8bfb\u6027\u3002<\/p>\n<pre><code>class ClassName(object):\n&quot;&quot;&quot;Doc string.&quot;&quot;&quot;\nclass_suite\n<\/code><\/pre>\n<p>\u7c7b\u7684\u521d\u59cb\u5316\u65b9\u6cd5init(\u76f8\u5f53\u4e8e\u6784\u9020\u5668):<\/p>\n<p>\u5982\u679c\u5b9a\u4e49\u4e86__init__\u65b9\u6cd5\u5728\u5b9e\u4f8b\u5316\u7684\u65f6\u5019\u4f1a\u9996\u5148\u8c03\u7528\u8be5\u65b9\u6cd5\uff0c\u8fdb\u884c\u4e00\u4e9b\u521d\u59cb\u5316\u7684\u5de5\u4f5c\u3002<\/p>\n<p>init\u65b9\u6cd5\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u5fc5\u987b\u662f\u5b9e\u4f8bself\uff0c\u800c\u4e14\u4e0d\u80fd\u6709return\u8bed\u53e5\u3002<\/p>\n<p>init\u65b9\u6cd5\u4e00\u822c\u7528\u6765\u8bbe\u7f6e\u5b9e\u4f8b\u5c5e\u6027(\u4e5f\u5c31\u662f\u6570\u636e\u5c5e\u6027)\u3002<\/p>\n<pre><code>class ClassName(object):\ndef __init__(self, *args, **kwargs):\npass\n<\/code><\/pre>\n<p>\u7279\u6b8a\u65b9\u6cd5new:<\/p>\n<p>\u5982\u679c\u5b9a\u4e49\u4e86__new__\u65b9\u6cd5\uff0c\u4f1a\u5728init\u65b9\u6cd5\u4e4b\u524d\u8fd0\u884c\uff0c\u5e76\u4e14\u8fd4\u56de\u4e00\u4e2a\u5b9e\u4f8b\uff0c\u4e5f\u5c31\u662f__init__\u7684self\u3002<\/p>\n<p>new\u65b9\u6cd5\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u5fc5\u987b\u662f\u7c7bcls\u3002\u5e76\u4e14\u9700\u8981\u8fd4\u56de\u4e00\u4e2a\u5b9e\u4f8b\u3002<\/p>\n<p>new\u65b9\u6cd5\u5728object\u4e2d\u88ab\u5b9a\u4e49\u4e3astaticmethod\u3002<\/p>\n<p>\u76f8\u5f53\u4e8e\u6790\u6784\u5668\u7684\u7279\u6b8a\u65b9\u6cd5del:<\/p>\n<p>__del__\u7279\u6b8a\u65b9\u6cd5\u8981\u5728\u5b9e\u4f8b\u5bf9\u8c61\u7684\u6240\u6709\u5f15\u7528\u90fd\u88ab\u6e05\u9664\u540e\u624d\u4f1a\u6267\u884c\u3002<\/p>\n<p>\u4e0d\u8981\u5728del\u4e2d\u505a\u4e0e\u5b9e\u4f8b\u6ca1\u6709\u5173\u7cfb\u7684\u4e8b\u60c5\uff0c\u4e00\u822c\u4e0d\u5efa\u8bae\u5b9e\u73b0\u8be5\u65b9\u6cd5\u3002<\/p>\n<pre><code>class ClassName(object):\ndef __new__(cls, *args, **kwargs):\n...\nreturn ...\ndef __del__(self):\n...\n<\/code><\/pre>\n<h2 id=\"\u7c7b\u5c5e\u6027\">\u7c7b\u5c5e\u6027<\/h2>\n<p>\u7c7b\u5c5e\u6027\u5206\u4e3a\u6570\u636e\u5c5e\u6027\u548c\u65b9\u6cd5\u5c5e\u6027\u3002<\/p>\n<p>\u7c7b\u7684\u6570\u636e\u5c5e\u6027\u4ec5\u4ec5\u662f\u5b9a\u4e49\u7684\u7c7b\u7684\u53d8\u91cf\u3002<\/p>\n<p>\u6570\u636e\u5c5e\u6027\u901a\u5e38\u662f\u9759\u6001\u53d8\u91cf, \u4e5f\u5c31\u662f\u548c\u7c7b\u5bf9\u8c61\u7ed1\u5b9a, \u4e0e\u7c7b\u7684\u5b9e\u4f8b\u65e0\u5173\u3002<\/p>\n<p>\u76f4\u63a5\u901a\u8fc7\u7c7b\u540d\u6765\u8bbf\u95ee\u7c7b\u7684\u6570\u636e\u5c5e\u6027\u3002\u4e0d\u5efa\u8bae\u901a\u8fc7\u5b9e\u4f8b\u6765\u8bbf\u95ee\u7c7b\u7684\u6570\u636e\u5c5e\u6027\u3002<\/p>\n<pre><code>class ClassName(object):\nCONST_VARIABLE = 'value'\ndef __init__(self, *args, **kwargs):\nClassName.CONST_VARIABLE = 'new'\nClassName.CONST_VARIABLE = 'new value'\n<\/code><\/pre>\n<p>\u7c7b\u7684\u65b9\u6cd5\u5c5e\u6027\u4ec5\u4ec5\u662f\u4e00\u4e2a\u4f5c\u4e3a\u7c7b\u5b9a\u4e49\u7684\u4e00\u90e8\u5206\u5b9a\u4e49\u7684\u51fd\u6570, \u4e0e\u7c7b\u7684\u5b9e\u4f8b\u65e0\u5173\u3002<\/p>\n<p>\u7c7b\u4e2d\u5b9a\u4e49\u7684\u65b9\u6cd5\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u4e00\u4e2a\u5b9e\u4f8bself\u3002<\/p>\n<p>\u65b9\u6cd5\u5c5e\u6027\u5fc5\u987b\u7ed1\u5b9a\u5230\u4e00\u4e2a\u5b9e\u4f8b\u624d\u80fd\u88ab\u76f4\u63a5\u8c03\u7528, \u975e\u7ed1\u5b9a\u65b9\u6cd5\u6ca1\u6709\u7ed9\u51fa\u5b9e\u4f8b\u5bf9\u8c61\u4e00\u822c\u4e0d\u80fd\u76f4\u63a5\u8c03\u7528\u3002<\/p>\n<pre><code>class ClassName(object):\ndef func(self, *args, **kwargs):\npass\n<\/code><\/pre>\n<p>Python 3 \u4e2d\uff0c\u76f4\u63a5\u8c03\u7528 ClassName.func() \u4f1a\u62a5\u9519\uff1aTypeError: func() missing 1 required positional argument: &lsquo;self<\/p>\n<p>\u8c03\u7528\u975e\u7ed1\u5b9a\u65b9\u6cd5\uff1a<\/p>\n<pre><code>ClassName.func(ClassName()) # \u9664\u975e\u4f20\u5165\u5b9e\u4f8b\u4f5c\u4e3a\u7b2c\u4e00\u4e2a\u53c2\u6570self\u7684\u503c\n# \u5e38\u7528\u573a\u666f\uff1a \u8c03\u7528\u7236\u7c7b\u4e2d\u7684\u975e\u7ed1\u5b9a\u65b9\u6cd5\nclass ClassName(BaseClass):\ndef __init__(self, *args, **kwargs):\nsuper().__init__(*args, **kwargs)\n...\n<\/code><\/pre>\n<p>\u8c03\u7528\u7ed1\u5b9a\u65b9\u6cd5\uff1a \u81ea\u52a8\u628a\u5b9e\u4f8b\u4f5c\u4e3aself\u4f20\u5165\uff0c\u4e0d\u7528\u663e\u5f0f\u4f20\u5165\u3002<\/p>\n<pre><code>ClassName().func()\n<\/code><\/pre>\n<p>\u67e5\u770b\u7c7b\u7684\u5c5e\u6027\uff1a<\/p>\n<pre><code>dir(class) # \u5185\u5efa\u51fd\u6570\nclass.__dict__ # \u7c7b\u7684\u7279\u6b8a\u5c5e\u6027\n<\/code><\/pre>\n<p>\u7c7b\u7684\u7279\u6b8a\u5c5e\u6027\uff1a<\/p>\n<pre><code>class.__name__ # class namkkk\nclass.__qualname__\nclass.__module__\nclass.__doc__ # \u6587\u6863\u7684\u7279\u6b8a\u5c5e\u6027, \u4e0d\u4f1a\u88ab\u7ee7\u627f.\nclass.__annotations\nclass.__bases__ # \u7c7b\u7684\u7236\u7c7b\u6784\u6210\u7684\u5143\u7ec4\nclass.__orig_bases__\n# \u65b0\u5f0f\u7c7b\u65b0\u589e\u7684\u4e09\u4e2a\u7279\u6b8a\u5c5e\u6027:\nclass.__mro__ # \u8fd4\u56de\u65b9\u6cd5\u89e3\u6790\u987a\u5e8f\u7684\u5143\u7ec4, mro()\nclass.__subclasses__() # \u8fd4\u56de\u5b50\u7c7b\u7684\u5217\u8868\nclass.__dict__ # \u4ee5\u5b57\u5178\u7684\u5f62\u5f0f\u5b58\u50a8\u5bf9\u8c61\u7684\u5c5e\u6027\nclass.__weakref__\n<\/code><\/pre>\n<p>\u65b9\u6cd5\u548c\u51fd\u6570\u7684\u7279\u6b8a\u5c5e\u6027\uff1a<\/p>\n<pre><code>'__doc__',\n'__annotations__'\n'__qualname__'\n'__name__',\n'__module__',\n'__self__',\n'__func__',\n<\/code><\/pre>\n<h1 id=\"\u5b9e\u4f8binstances\">\u5b9e\u4f8b\/Instances<\/h1>\n<p>\u5b9e\u4f8b\u5316\uff1a<\/p>\n<pre><code>ins = ClassName()\n<\/code><\/pre>\n<h2 id=\"\u5b9e\u4f8b\u5c5e\u6027\">\u5b9e\u4f8b\u5c5e\u6027<\/h2>\n<p>\u5b9e\u4f8b\u5c5e\u6027\uff1a<\/p>\n<p>\u5b9e\u4f8b\u4e25\u683c\u6765\u8bf4\u53ea\u6709\u6570\u636e\u5c5e\u6027(\u65b9\u6cd5\u5c5e\u6027\u5e94\u8be5\u5c5e\u4e8e\u7c7b\u5c5e\u6027)\uff0c\u6570\u636e\u5c5e\u6027\u5c31\u662f\u548c\u67d0\u4e2a\u5b9e\u4f8b\u76f8\u5173\u8054\u7684\u6570\u636e\u503c\uff0c\u8fd9\u4e9b\u503c\u72ec\u7acb\u4e8e\u5176\u5b83\u5b9e\u4f8b\u6216\u7c7b\uff0c\u5f53\u4e00\u4e2a\u5b9e\u4f8b\u88ab\u91ca\u653e\uff0c\u76f8\u5e94\u7684\u6570\u636e\u5c5e\u6027\u4e5f\u88ab\u91ca\u653e\u3002\u901a\u5e38\u901a\u8fc7init\u65b9\u6cd5\u6765\u8bbe\u7f6e\u5b9e\u4f8b\u7684\u6570\u636e\u5c5e\u6027\u3002<\/p>\n<pre><code>class ClassName(object):\nDATA = &quot;in class&quot; # \u7c7b\u7684\u6570\u636e\u5c5e\u6027\ndef __init__(self, default=&quot;default&quot;, *args, **kwargs):\nself.default = default # \u5f53\u524d\u5b9e\u4f8b\u7684\u6570\u636e\u5c5e\u6027\n<\/code><\/pre>\n<p>\u533a\u522b\u7c7b\u7684\u6570\u636e\u5c5e\u6027\u548c\u5b9e\u4f8b\u7684\u6570\u636e\u5c5e\u6027\u3002<\/p>\n<pre><code>obj1 = ClassName()\nprint(obj1.DATA) # &quot;in class&quot;, \u5f53\u5b9e\u4f8b\u6ca1\u6709\u540c\u540d\u7684\u6570\u636e\u5c5e\u6027\uff0c\u4f1a\u8bbf\u95ee\u7c7b\u7684\u6570\u636e\u5c5e\u6027\u3002\nobj1.DATA = &quot;in obj1&quot; # \u76f8\u5f53\u4e8e\u7ed9\u5b9e\u4f8b\u65b0\u5efa\u4e86\u4e00\u4e2a\u6570\u636e\u5c5e\u6027\uff0c\u4f1a\u8986\u76d6\u7c7b\u7684\u6570\u636e\u5c5e\u6027\u3002\nprint(obj1.DATA) # &quot;in obj1&quot; \u8bbf\u95ee\u7684\u662f\u5b9e\u4f8b\u7684\u6570\u636e\u5c5e\u6027\uff0c\u8986\u76d6\u4e86\u7c7b\u7684\u6570\u636e\u5c5e\u6027\u3002\nprint(ClassName.DATA) # &quot;in class&quot; \u8bbf\u95ee\u7c7b\u7684\u6570\u636e\u5c5e\u6027\u3002\n<\/code><\/pre>\n<p>\u67e5\u770b\u5b9e\u4f8b\u5c5e\u6027:<\/p>\n<pre><code>instance.__dict__\n<\/code><\/pre>\n<p>\u5b9e\u4f8b\u7684\u7279\u6b8a\u5c5e\u6027\uff1a<\/p>\n<pre><code>instance.__dict__ # \u4ee5\u5b57\u5178\u7684\u5f62\u5f0f\u5b58\u50a8\u5bf9\u8c61\u7684\u5c5e\u6027\ninstance.__class__ # \u5b9e\u4f8b\u5bf9\u5e94\u7684\u7c7b\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u5c01\u88c5encapsulation\"><strong>\u5c01\u88c5\/Encapsulation<\/strong><\/h1>\n<p>\u5c01\u88c5\u63cf\u8ff0\u4e86\u5bf9\u6570\u636e\uff0f\u4fe1\u606f\u8fdb\u884c\u9690\u85cf\u7684\u89c2\u5ff5\uff0c\u5bf9\u6570\u636e\u5c5e\u6027\u63d0\u4f9b\u63a5\u53e3\u548c\u8bbf\u95ee\u51fd\u6570\uff0e<\/p>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6570\u636e\u5c5e\u6027\u548c\u7c7b\u5c5e\u6027\u90fd\u662fpublic\u7684\uff0e\u7c7b\u6240\u5728\u7684\u6a21\u5757\u548c\u5bfc\u5165\u4e86\u7c7b\u7684\u5176\u5b83\u6a21\u5757\u90fd\u53ef\u4ee5\u4f7f\u7528\uff0e<\/p>\n<pre><code>var # public\ndef method_name(self):\n<\/code><\/pre>\n<p>\u4e00\u4e2a\u4e0b\u5212\u7ebf\u5f00\u5934\u7684\u5c5e\u6027\u662fprotected,\u80fd\u5728\u7c7b\u672c\u8eab\u548c\u5b50\u7c7b\u4f7f\u7528\uff0c\u7c7b\u7684\u5b9e\u4f8b\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95ee\uff0c\u4e0d\u53ef\u4ee5\u7528from module import *\u5bfc\u5165\uff0e<\/p>\n<p>\u7528\u4e8e\u628a\u5c5e\u6027\u9650\u5236\u5728\u4e00\u4e2a\u6a21\u5757\u4e2d\uff0e<\/p>\n<pre><code>_xxx # protected\ndef _xxx(self):\n<\/code><\/pre>\n<p>\u53cc\u4e0b\u5212\u7ebf\u5f00\u5934\u7684\u5c5e\u6027\u662fprivate, \u53ea\u80fd\u7c7b\u672c\u8eab\u4f7f\u7528\uff0c\u7c7b\u7684\u5b9e\u4f8b\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\uff0c\u5b50\u7c7b\u548c\u5176\u5b83\u7c7b\u90fd\u4e0d\u80fd\u4f7f\u7528,\u5b50\u7c7b\u4e5f\u4e0d\u80fd\u8986\u76d6\uff0e<\/p>\n<p>\u7528\u4e8e\u628a\u5c5e\u6027\u9650\u5236\u5728\u4e00\u4e2a\u7c7b\u4e2d.<\/p>\n<pre><code>__xxx # private\ndef __xxx(self):\n<\/code><\/pre>\n<p>\u7cfb\u7edf\u5df2\u7ecf\u5b9a\u4e49\u7684\u7279\u6b8a\u65b9\u6cd5\uff0c\u4e5f\u79f0\u9b54\u6cd5\u65b9\u6cd5\uff0e<\/p>\n<pre><code>def __xxx__(self): # \u7cfb\u7edf\u5b9a\u4e49\u7684\u540d\u5b57\n<\/code><\/pre>\n<h2 id=\"composition\">Composition<\/h2>\n<p>\u7c7b\u4e4b\u95f4\u7684\u5173\u7cfb\u53ea\u6709\u4e24\u79cd\u7ee7\u627f\u548c\u5305\u542b.<\/p>\n<p>\u521b\u5efa\u590d\u5408\u5bf9\u8c61\u65f6\u53ef\u4ee5\u901a\u8fc7composition\u7ec4\u5408\u6765\u589e\u52a0\u529f\u80fd\u548c\u4ee3\u7801\u7684\u91cd\u7528\u6027\uff0e<\/p>\n<p>\u5f53\u7c7b\u4e4b\u95f4\u6709\u663e\u8457\u4e0d\u540c\uff0c\u5e76\u4e14\u8f83\u5c0f\u7684\u7c7b\u662f\u8f83\u5927\u7684\u7c7b\u6240\u9700\u7684\u7ec4\u4ef6\u65f6\u4e00\u822c\u4f7f\u7528\u7ec4\u5408\uff0e<\/p>\n<pre><code>from .company import Company\nfrom .home import Home\nclass Emp(object):\ndef __init__(self, *args, **kwargs):\nself.comp = Company(args)\nself.home = Home(kwargs)\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u7ee7\u627finheritance\"><strong>\u7ee7\u627f\/Inheritance<\/strong><\/h1>\n<p>\u5229\u7528\u7c7b\u7684\u4e24\u79cd\u65b9\u5f0f\u5c31\u662f\u5305\u88c5\u548c\u7ee7\u627f\uff0e<\/p>\n<h2 id=\"\u5b50\u7c7b\u548c\u6d3e\u751f\">\u5b50\u7c7b\u548c\u6d3e\u751f<\/h2>\n<p>\u5bf9\u4e8e\u76f8\u540c\u7684\u7c7b\u4f46\u662f\u6709\u4e0d\u540c\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u901a\u8fc7derivation\u6d3e\u751f\u6765\u5b9e\u73b0\uff0e<\/p>\n<p>\u901a\u8fc7\u4f7f\u7528\u4e00\u4e2a\u5df2\u7ecf\u5b9a\u4e49\u597d\u7684\u7c7b\uff0c\u6269\u5c55\u5b83\u6216\u8005\u4fee\u6539\uff0c\u800c\u4e0d\u4f1a\u5f71\u54cd\u7cfb\u7edf\u4e2d\u4f7f\u7528\u73b0\u5b58\u7c7b\u7684\u5176\u5b83\u4ee3\u7801\u7247\u6bb5\uff0e<\/p>\n<pre><code>class Father(object):\ndef woman(self):\n...\nclass Mother(object);\ndef man(self):\n...\nclass Child(Father, Mother):\ndef child(self):\n...\n<\/code><\/pre>\n<h2 id=\"\u7ee7\u627f\">\u7ee7\u627f<\/h2>\n<p>\u7ee7\u627f\u63cf\u8ff0\u4e86\u57fa\u7c7b\u7684\u5c5e\u6027\u5982\u4f55\u9057\u4f20\u7ed9\u6d3e\u751f\u7c7b\uff0e<\/p>\n<p>\u6d3e\u751f\u7c7b\uff08\u5b50\u7c7b\uff09\u7ee7\u627f\u81ea\u57fa\u7c7b\uff08\u7236\u7c7b\uff09<\/p>\n<p>python\u4e2d\u7684\u7c7b\u9700\u8981\u7ee7\u627f\u4e00\u4e2a\u6216\u591a\u4e2a\u7236\u7c7b\uff0e<\/p>\n<p>object\u7c7b\u662f\u6240\u6709\u7c7b\u7684\u7236\u7c7b\uff0e<\/p>\n<p>\u5b50\u7c7b\u7ee7\u627f\u4e86\u57fa\u7c7b\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\uff0e<\/p>\n<p>\u6587\u6863\u5b57\u7b26\u4e32__doc__\u662f\u552f\u4e00\u7684\uff0c\u4e0d\u80fd\u7ee7\u627f\uff0e<\/p>\n<p>\u4e00\u4e2a\u7c7b\u7684__bases__\u5c5e\u6027\u53ef\u4ee5\u67e5\u770b\u5b83\u7684\u7236\u7c7b\u7ec4\u6210\u7684\u5143\u7ec4\uff0e\u4e0d\u5305\u62ec\u7236\u7c7b\u7684\u7236\u7c7b\uff0e<\/p>\n<pre><code>class.__bases__ # \u7c7b\u7684\u7236\u7c7b\u6784\u6210\u7684\u5143\u7ec4\n<\/code><\/pre>\n<p>\u5b9e\u4f8b\u8c03\u7528\u65b9\u6cd5\u65f6\uff0c\u9ed8\u8ba4\u8c03\u7528\u7684\u8be5\u5bf9\u8c61\u7684\u7c7b\u7684\u672c\u8eab\u7684\u65b9\u6cd5\uff0c\u5982\u679c\u8be5\u7c7b\u6ca1\u6709\u5b9e\u73b0\u8be5\u65b9\u6cd5\u624d\u4f1a\u8c03\u7528\u7236\u7c7b\u7684\u65b9\u6cd5\uff0e<\/p>\n<pre><code>class Parent(object):\ndef foo(self):\nprint(&quot;in parent.&quot;)\nclass Child(Parent):\ndef foo(self):\nprint(&quot;in child.&quot;)\n<\/code><\/pre>\n<h2 id=\"\u4ece\u5185\u7f6e\u7c7b\u7ee7\u627f\">\u4ece\u5185\u7f6e\u7c7b\u7ee7\u627f<\/h2>\n<p>\u53ef\u4ee5\u4ece\u5185\u7f6e\u7c7b\u578b\u7ee7\u627f\u5b50\u7c7b\uff0c\u4fee\u6539\u4e00\u4e9b\u5c5e\u6027\uff0e<\/p>\n<pre><code>class RoundFloat(float):\ndef __new__(cls, val):\nreturn super(RoundFloat, cls).__new__(cls, round(val, 2))\nclass SortedKeyDict(dict):\ndef keys(self):\nreturn sorted(super(SortedKeyDict, self).keys())\n<\/code><\/pre>\n<h2 id=\"multiple-inheritance\u591a\u91cd\u7ee7\u627f\">Multiple inheritance\u591a\u91cd\u7ee7\u627f<\/h2>\n<p>\u7531\u4e8e\u7c7b\uff0c\u7c7b\u578b\uff0c\u5185\u5efa\u7c7b\u578b\u7684\u5b50\u7c7b\u90fd\u91cd\u65b0\u67b6\u6784\uff0c\u65b0\u7684\u7c7b\u91c7\u7528MRO\u7b97\u6cd5\u6765\u67e5\u627e\u5b50\u7c7b\u4e2d\u4f7f\u7528\u7684\u5c5e\u6027\uff0e<\/p>\n<p>MRO: Method Resolution Order, \u65b9\u6cd5\u89e3\u91ca\u987a\u5e8f\uff0e\u91c7\u7528\u5e7f\u5ea6\u4f18\u5148\uff0c\u4ece\u5de6\u81f3\u53f3\u8fb9\uff0c\u6765\u83b7\u53d6\u5728\u5b50\u7c7b\u4e2d\u7684\u5c5e\u6027\uff0e<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7\u65b0\u5f0f\u7c7b\u7684\u7279\u6b8a\u5c5e\u6027\u67e5\u770b\u5b50\u7c7b\u7684\u5c5e\u6027\u7684\u67e5\u627e\u987a\u5e8f\uff1a<\/p>\n<pre><code>class.__mro__ # \u8fd4\u56de\u65b9\u6cd5\u89e3\u6790\u987a\u5e8f\u7684\u5143\u7ec4\n<\/code><\/pre>\n<p>\u591a\u7ee7\u627f\uff0cmro\u548csuper\u7684\u7528\u6cd5\uff1a<\/p>\n<p>super\u6bcf\u6b21\u53ea\u8c03\u7528MRO\u4e2d\u7684\u7b2c\u4e00\u4e2a\u7236\u7c7b\uff0c\u548cgetattr\u7684\u987a\u5e8f\u4e00\u6837\uff0e\u5e76\u4e14\u76f8\u540c\u7684\u7236\u7c7b\u53ea\u8c03\u7528\u4e00\u6b21\uff0e<\/p>\n<p>\u6570\u636e\u5c5e\u6027\uff0c\u666e\u901a\u65b9\u6cd5\u5c5e\u6027\uff0c\u7279\u6b8a\u65b9\u6cd5\u5c5e\u6027\u90fd\u662f\u6309\u7167MRO\u987a\u5e8f\u6765\u67e5\u627e\uff0e<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/crazy-canux\/python\/tree\/master\/python\/multiple_inheritance\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/crazy-canux\/python\/tree\/master\/python\/multiple_inheritance<\/a><\/p>\n<hr>\n<h1 id=\"\u591a\u6001polymorphism\"><strong>\u591a\u6001\/Polymorphism<\/strong><\/h1>\n<p>python\u4e0d\u652f\u6301\u65b9\u6cd5\u91cd\u8f7d\uff0c\u4f46\u662f\u53ef\u4ee5\u901a\u8fc7\u5bf9\u53c2\u6570\u7684\u5224\u65ad\uff0c\u5bf9\u4e0d\u540c\u7684\u53c2\u6570\u8fdb\u884c\u4e0d\u540c\u7684\u5904\u7406\u3002\u4ee5\u6b64\u6765\u5b9e\u73b0\u91cd\u8f7d\u7684\u529f\u80fd\u3002<\/p>\n<p>python\u53ef\u4ee5\u91cd\u8f7d\u9b54\u6cd5\u65b9\u6cd5\u3002<\/p>\n<h2 id=\"magicmethod\">magicmethod<\/h2>\n<p>python\u7c7b\u6709\u4e00\u4e9b\u53ef\u81ea\u5b9a\u4e49\u7684\u7279\u6b8a\u65b9\u6cd5\u96c6\uff0c\u5b83\u4eec\u4e2d\u7684\u4e00\u4e9b\u6709\u9884\u5b9a\u4e49\u7684\u9ed8\u8ba4\u884c\u4e3a\uff0c\u4e00\u4e9b\u6ca1\u6709\uff0c\u7559\u5230\u9700\u8981\u7684\u65f6\u5019\u53bb\u5b9e\u73b0\u3002<\/p>\n<p>\u8fd9\u4e9b\u7279\u6b8a\u65b9\u6cd5\u662fpython\u4e2d\u7528\u6765\u6269\u5145\u7c7b\u7684\u65b9\u6cd5\u3002\u53ef\u4ee5\u7528\u6765\u6a21\u62df\u6807\u51c6\u7c7b\u578b\u6216\u8005\u91cd\u8f7d\u64cd\u4f5c\u7b26\u3002<\/p>\n<p>\u8fd9\u4e9b\u7279\u6b8a\u65b9\u6cd5\u90fd\u662f\u7528\u53cc\u4e0b\u5212\u7ebf\u5f00\u5934\u548c\u7ed3\u5c3e\u7684\uff0c\u4e5f\u88ab\u79f0\u4e3a\u9b54\u6cd5\u65b9\u6cd5\u3002<\/p>\n<p>\u5bf9\u8c61\u521b\u5efa\u548c\u9500\u6bc1\uff1a<\/p>\n<pre><code>__init__(self, *args, **kwargs) # \u6784\u9020\u5668\uff0c\u5e26\u4e00\u4e9b\u53ef\u9009\u7684\u53c2\u6570\n__new__(cls, *args, **kwargs) # \u6784\u9020\u5668\uff0c\u5e26\u4e00\u4e9b\u53ef\u9009\u7684\u53c2\u6570\uff0c\u901a\u5e38\u7528\u6765\u8bbe\u7f6e\u4e0d\u53ef\u53d8\u6570\u636e\u7c7b\u578b\u7684\u5b50\u7c7b\u3002\n__del__(self) # \u89e3\u6784\u5668\n<\/code><\/pre>\n<p>\u5b57\u7b26\u4e32\u8868\u793a\uff1a<\/p>\n<pre><code>__str__(self) # str(), print()\nobj = ClassName()\nprint(obj) # \u6ca1\u6709\u5b9a\u4e49__str__ \u4f1a\u8c03\u7528__repr__\n__repr__(self) # repr()\nobj = ClassName()\nobj # \u9ed8\u8ba4\u7684\u6253\u5370\u5bf9\u8c61\u7684\u8fd0\u884c\u65f6\u7684\u5b57\u7b26\u4e32\uff0c&lt;test.RoundFloat at 0x7fb715253e90&gt;\n# \u53ef\u4ee5\u901a\u8fc7\u91cd\u5199__repr__()\u6539\u53d8\u6253\u5370\u7684\u5185\u5bb9\n__bool__(self) # \u7528\u4e8ebool\u5224\u65ad\u771f\u5047\n<\/code><\/pre>\n<p>\u53ef\u8c03\u7528\u5bf9\u8c61\u7684\u7279\u6b8a\u65b9\u6cd5\uff1a<\/p>\n<pre><code>__call__(self, *args) # \u8868\u793a\u53ef\u8c03\u7528\u7684\u5b9e\u4f8b, callable(object) \u4f1a\u8fd4\u56detrue.\nclass TestClass(object):\ndef __call__(self, *args):\nprint(&quot;Instance is callable after implement call method in class.&quot;)\nprint(&quot;Args come from instance invoke is: {}&quot;.format(args))\ntc = TestClass()\ncallable(tc) # True\ntc()\ntc('arg1')\n<\/code><\/pre>\n<p>\u5b9e\u4f8b\u548c\u7c7b\u7684\u68c0\u67e5\u76f8\u5173\u7279\u6b8a\u65b9\u6cd5\uff1a<\/p>\n<pre><code>__instancecheck__(self, instance) # isinstance(instance, class)\n__subclasscheck__(self, subclass) # issubclass(subclass, class)\n<\/code><\/pre>\n<p>\u5c5e\u6027\u76f8\u5173\u7279\u6b8a\u65b9\u6cd5\uff1a<\/p>\n<pre><code>__getattr__(self, name) # getattr(), \u4ec5\u5f53\u5c5e\u6027\u6ca1\u6709\u5728\u5b9e\u4f8b\uff0f\u7c7b\uff0f\u7236\u7c7b\u7684__dict__\u4e2d\u627e\u5230\u624d\u4f1a\u8c03\u7528\uff0e\n__getattribute__(self, name)\n__setattr__(self, name, value)\n__delattr__(self, name)\n__dir__(self) # dir()\n# \u63cf\u8ff0\u7b26\u76f8\u5173\n__get__(self, instance, owner)\n__set__(self, instance, value)\n__delete__(self, instance)\n<\/code><\/pre>\n<p>with\u4e0a\u4e0b\u6587\u7ba1\u7406\u7279\u6b8a\u65b9\u6cd5\uff1a<\/p>\n<pre><code>__enter__(self) # return self, \u9700\u8981\u8fd4\u56deself\n__exit__(self, exc_type, exc_value, traceback)\n<\/code><\/pre>\n<p>\u5bf9\u8c61\u6bd4\u8f83\u7279\u6b8a\u65b9\u6cd5\uff1a<\/p>\n<pre><code>__cmp__(self, other) # cmp()\n__lt__(self, other)\n__le__(self, other)\n__eq__(self, other)\n__ne__(self, other)\n__gt__(self, other)\n__ge__(self, other)\n<\/code><\/pre>\n<p>\u5bb9\u5668\u7c7b\u578b\u76f8\u5173\u7279\u6b8a\u65b9\u6cd5:<\/p>\n<pre><code>__len__(self) #\u3000len()\n__getitem__(self, key) #\n__setitem__(self, key, value) #\n__delitem__(self, key) # del\n__reversed__(self) # reversed()\n__iter__(self) # iter()\n__contains__(self, item)\n__missing__(self, key)\n<\/code><\/pre>\n<p><a class=\"link\" href=\"https:\/\/github.com\/crazy-canux\/python\/blob\/master\/python\/magicmethod\/container.py\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/crazy-canux\/python\/blob\/master\/python\/magicmethod\/container.py<\/a><\/p>\n<p>\u6570\u503c\u7c7b\u578b\u76f8\u5173\u7279\u6b8a\u65b9\u6cd5\uff1a<\/p>\n<pre><code>__add__(self, other)\n__sub__(self, other)\n__mul__(self, other)\n__div__(self, other)\n__truediv__(self, other)\n__floordiv__(self, other)\n__mod__(self, other)\n__divmod__(self, other)\n__pow__(self, other[, module])\n__lshift__(self, other)\n__rshift__(self, other)\n__and__(self, other)\n__xor__(self, other)\n__or__(self, other)\n__rxxx__(self, other)\n# \u539f\u4f4d\u8fd0\u7b97\u5fc5\u987b\u8fd4\u56deself.\n__ixxx__(self, other) # self += other -&gt; self = self + other\n__neg__(self)\n__pos__(self)\n__abs__(self)\n__invert__(self)\n__complex__(self)\n__int__(self)\n__long__(self)\n__float__(self)\n__oct__(self)\n__hex__(self)\n__index__(self)\n__coerce__(self, other)\n<\/code><\/pre>\n<h2 id=\"delegation--wrapping\">Delegation &amp; Wrapping<\/h2>\n<p>Wrapping\u5305\u88c5\u5c31\u662f\u5bf9\u4e00\u4e2a\u5df2\u7ecf\u5b58\u5728\u7684\u5bf9\u8c61\u589e\u52a0\uff0c\u5220\u9664\u6216\u4fee\u6539\u5df2\u7ecf\u5b58\u5728\u7684\u529f\u80fd\uff0e<\/p>\n<p>Delegation\u6388\u6743(\u4ee3\u7406)\u662fWrapping\u5305\u88c5\u7684\u4e00\u4e2a\u7279\u6027,\u7528\u4e8e\u7b80\u5316\u5904\u7406\u76f8\u5173\u547d\u4ee4\u6027\u529f\u80fd\uff0c\u6700\u5927\u5316\u91cd\u7528\u4ee3\u7801\uff0e<\/p>\n<p>\u5b9e\u73b0delegation\u7684\u5173\u952e\u5728\u4e8e\u8986\u76d6__getattr__()\u7279\u6b8a\u65b9\u6cd5\uff0e\u901a\u8fc7\u8c03\u7528\u5185\u7f6e\u51fd\u6570getattr()\u5f97\u5230\u4e00\u4e2a\u5bf9\u8c61\u7684\u9ed8\u8ba4\u884c\u4e3a\uff0e<\/p>\n<pre><code>class Wrapper(object):\ndef __init__(self, obj):\nself.__data = obj\ndef __getattr__(self, attr):\nreturn getattr(self.__data, attr)\n<\/code><\/pre>\n<hr>\n<h1 id=\"metaclass\u5143\u7c7b\">metaclass\u5143\u7c7b<\/h1>\n<p>metaclass \u662f&quot;\u521b\u5efa\u7c7b\u7684\u7c7b&quot;\u3002\u6b63\u5982\u5b9e\u4f8b\u662f\u7c7b\u7684\u5b9e\u4f8b\u5316\uff0c\u7c7b\u4e5f\u662f\u5143\u7c7b\u7684\u5b9e\u4f8b\u5316\u3002\u5728 Python \u4e2d\uff0c\u7c7b\u672c\u8eab\u4e5f\u662f\u5bf9\u8c61\uff0c\u800c\u5143\u7c7b\u5c31\u662f\u7528\u6765\u521b\u5efa\u8fd9\u4e9b\u7c7b\u5bf9\u8c61\u7684\u3002<\/p>\n<p>\u5143\u7c7b\u7528\u6765\u5b9a\u4e49\u67d0\u4e9b\u7c7b\u662f\u5982\u4f55\u88ab\u521b\u5efa\u7684\u3002\u6539\u53d8\u7c7b\u7684\u9ed8\u8ba4\u884c\u4e3a\u548c\u521b\u5efa\u65b9\u5f0f\u3002<\/p>\n<p>\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u4e0d\u9700\u8981\u521b\u5efa\u5143\u7c7b\uff0c\u4e00\u822c\u4f7f\u7528\u7cfb\u7edf\u7684\u5143\u7c7b\u7684\u9ed8\u8ba4\u65b9\u5f0f\u3002<\/p>\n<p>\u5728\u6267\u884c\u7c7b\u5b9a\u4e49\u7684\u65f6\u5019\uff0c\u89e3\u91ca\u5668\u5fc5\u987b\u77e5\u9053\u8fd9\u4e2a\u7c7b\u7684\u5143\u7c7b\uff1b<\/p>\n<pre><code>class ClassName(metaclass=MetaClassName):\npass\n<\/code><\/pre>\n<p>\u5728\u6267\u884c\u7c7b\u5b9a\u4e49\u65f6\u5019\u68c0\u67e5\u5143\u7c7b\uff0c\u5143\u7c7b\u4f20\u9012\u4e09\u4e2a\u53c2\u6570\u5230\u6784\u9020\u5668\uff1a<\/p>\n<pre><code>\u7c7b\u540d\n\u4ece\u57fa\u7c7b\u7ee7\u627f\u6570\u636e\u7684\u5143\u7ec4, __bases__\n\u7c7b\u7684\u5c5e\u6027\u5b57\u5178, __dict__\n<\/code><\/pre>\n<p>\u5143\u7c7b\u76f8\u5173\u7684\u53ef\u5b9a\u5236\u5c5e\u6027\uff1a<\/p>\n<pre><code>__metaclass__\n<\/code><\/pre>\n<p>\u5b9a\u4e49\u4e00\u4e2a\u5143\u7c7b\uff1a<\/p>\n<pre><code>class MetaClassName(type):\ndef __new__(cls, name, bases, dicts):\nsuper().__new__(cls, name, bases, dicts)\n# \u5728\u8fd9\u91cc\u505a\u4e00\u4e9b\u4f60\u5e0c\u671b\u4f7f\u7528\u8be5\u5143\u7c7b\u7684\u7c7b\u5728\u5b9a\u4e49\u65f6\u505a\u7684\u64cd\u4f5c\ndef __call__(cls, *args, **kwargs):\nif cls not in cls._instances:\ncls._instances[cls] = super().__call__(*args, **kwargs)\nreturn cls._instances[cls]\nclass ClassName(metaclass=MetaClassName):\ndef __init__(self, value):\nself.value = value\n...\n<\/code><\/pre>\n<p><a class=\"link\" href=\"https:\/\/github.com\/crazy-canux\/python\/tree\/master\/python\/metaclass\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/crazy-canux\/python\/tree\/master\/python\/metaclass<\/a><\/p>\n<p>\u4f7f\u7528\u573a\u666f\uff1a<\/p>\n<ul>\n<li>\u5355\u4f8b\u6a21\u5f0f<\/li>\n<li>\u81ea\u52a8\u6ce8\u518c\u7c7b<\/li>\n<li>\u5c5e\u6027\u9a8c\u8bc1\u548c\u8f6c<\/li>\n<li>ORM\u6a21\u578b\u521b\u5efa<\/li>\n<li>\u62bd\u8c61\u57fa\u7c7b\u548c\u63a5\u53e3\u68c0\u67e5<\/li>\n<\/ul>\n<h2 id=\"abstractmethod\">abstractmethod<\/h2>\n<p>\u62bd\u8c61\u65b9\u6cd5\uff0c\u7c7b\u4f3c\u4e8ejava\u7684interface.<\/p>\n<p>\u6700\u7b80\u5355\u7684\u62bd\u8c61\u65b9\u6cd5\uff1a<\/p>\n<pre><code># \u5982\u679c\u5b50\u7c7b\u6ca1\u6709\u5b9e\u73b0\u540c\u540d\u7684\u8be5\u65b9\u6cd5\uff0c\u5c31\u4f1a\u629b\u51fa\u5f02\u5e38\uff0e\ndef base_method(self):\nraise NotImplementedError\n<\/code><\/pre>\n<p>\u6216\u8005\u4f7f\u7528abc\u6807\u51c6\u5e93\u6765\u5b9e\u73b0\uff1a<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/crazy-canux\/python\/tree\/master\/python\/psl\/myabc.py\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/crazy-canux\/python\/tree\/master\/python\/psl\/myabc.py<\/a><\/p>\n<hr>\n<h1 id=\"descriptors\u63cf\u8ff0\u7b26\">descriptors\u63cf\u8ff0\u7b26<\/h1>\n<p>\u666e\u901a\u5bf9\u8c61\u8bbf\u95ee(set\/get\/delete)\u5c5e\u6027\u7684\u4f18\u5148\u7ea7\uff1a<\/p>\n<pre><code>obj.__dict__['attr'] # \u5148\u8bbf\u95ee\u5b9e\u4f8b\u5bf9\u8c61\nobj.__class__.__dict__['attr'] # \u518d\u8bbf\u95ee\u7c7b\u5bf9\u8c61\nobj.__class__.__base__.__dict__['attr'] # \u63a5\u7740\u8bbf\u95ee\u57fa\u7c7b\u7684\u5bf9\u8c61,\u4e0d\u5305\u62ecmetaclass.\n__getattr__ # \u5982\u679c\u5b9e\u73b0\u4e86\u7684\u8bdd\uff0c\u4f18\u5148\u7ea7\u6700\u4f4e\n<\/code><\/pre>\n<p>\u63cf\u8ff0\u7b26\u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5b83\u5b9a\u4e49\u4e86\u5f53\u53e6\u4e00\u4e2a\u5bf9\u8c61\u7684\u5c5e\u6027\u88ab\u8bbf\u95ee\u65f6\u5e94\u8be5\u5982\u4f55\u5904\u7406\u3002\u4efb\u4f55\u5b9a\u4e49\u4e86 <strong>get<\/strong>()\u3001<strong>set<\/strong>() \u6216 <strong>delete<\/strong>() \u65b9\u6cd5\u7684\u7c7b\u90fd\u662f\u63cf\u8ff0\u7b26\u3002<\/p>\n<pre><code>__get__(self, obj, type=None) # \u8fd4\u56de\u4e00\u4e2a\u5c5e\u6027\u7684\u503c\n__set__(self, obj, value) # \u8bbe\u7f6e\u4e00\u4e2a\u5c5e\u6027\u7684\u503c\uff0c\u8fd4\u56deNone\n__delete__(self, obj) # \u5c5e\u6027\u7684\u5f15\u7528\u9012\u51cf\uff0c\u8fd4\u56deNone\n<\/code><\/pre>\n<p>\u63cf\u8ff0\u7b26\u662f\u6570\u636eproperty\uff0cclass\uff0cstaticmethod\uff0cclassmethod, \u4ee5\u53casuper\u7684\u673a\u5236\uff0e<\/p>\n<p>data descriptor:\u5b9a\u4e49\u4e86__get__\u548c__set__\u7684\u5bf9\u8c61\u662f\u6570\u636e\u63cf\u8ff0\u7b26, \u4e3b\u8981\u7528\u4e8e\u6570\u636e\u5c5e\u6027\uff0e<\/p>\n<p>non data descriptor:\u4ec5\u4ec5\u5b9a\u4e49\u4e86__get__\u7684\u5bf9\u8c61\u662f\u975e\u6570\u636e\u63cf\u8ff0\u7b26\uff0c\u4e3b\u8981\u7528\u4e8e\u65b9\u6cd5\u5c5e\u6027\uff0e<\/p>\n<p>\u5982\u679c\u5b9e\u4f8b\u7684\u5b57\u5178(obj.<strong>dict<\/strong>)\u5177\u6709\u4e0e\u6570\u636e\u63cf\u8ff0\u7b26\u76f8\u540c\u540d\u79f0\u7684\u6761\u76ee\uff0c\u5219\u6570\u636e\u63cf\u8ff0\u7b26\u4f18\u5148\u3002<\/p>\n<p>\u5982\u679c\u5b9e\u4f8b\u7684\u5b57\u5178(obj.<strong>dict<\/strong>)\u5177\u6709\u4e0e\u975e\u6570\u636e\u63cf\u8ff0\u7b26\u76f8\u540c\u540d\u79f0\u7684\u6761\u76ee\uff0c\u5219\u5b57\u5178\u6761\u76ee\u4f18\u5148\u3002<\/p>\n<pre><code>class DescriptorName(object):\ndef __init__(self, name):\nself.name = name\ndef __get__(self, instance, typ):\nprint('__get__', instance, typ)\nreturn self.name\ndef __set__(self, instance, value):\nprint('__set__', instance, value)\nself.name = value\nclass TestClass(object):\nname = DescriptorName('canux')\ntc = TestClass()\nprint(tc.name) # __get__(tc, type(tc))\u88ab\u8c03\u7528\nprint(TestClass.name) # __get__(None, TestClass)\u88ab\u8c03\u7528\ntc.__dict__['name'] = 'test' # \u65e0\u6548\ntc.name = 'test' # __set__\u88ab\u8c03\u7528\nTestClass.name = 'test' # \u4ec5\u4ec5\u662f\u91cd\u65b0\u5b9a\u4e49\u7c7b\u7684\u5c5e\u6027\uff0c\u8986\u76d6\u4e86\u63cf\u8ff0\u7b26\n# \u6b64\u65f6tc.__dict__\u6709\u540c\u540d\u5c5e\u6027\uff0c\u5982\u679c\u5b9a\u4e49\u4e86__set__\nprint(tc.name) # __get__\u88ab\u8c03\u7528\uff0c\u5c5e\u6027\u5df2\u7ecf\u4fee\u6539\nprint(TestClass.name) # __get__\u88ab\u8c03\u7528,\u5c5e\u6027\u5df2\u7ecf\u4fee\u6539\n# \u5982\u679c\u6ca1\u6709\u5b9a\u4e49__set__\uff0c\u5c31\u662f\u8c03\u7528\u7684tc.__dict__\u91cc\u9762\u7684\uff0e\n<\/code><\/pre>\n<p>\u63cf\u8ff0\u7b26\u8bbf\u95ee\u5c5e\u6027\u7684\u4f18\u5148\u7ea7\uff1a<\/p>\n<pre><code>\u6570\u636e\u63cf\u8ff0\u7b26(__set__, __get__)\n# \u5bf9\u4e8e\u8bbf\u95ee\u5b9e\u4f8b\u5c5e\u6027obj.__getattribute__\u8c03\u7528\u65b9\u5f0f\uff1atype(obj).__dict__['attr'].__get__(obj, type(obj))\n# \u5bf9\u4e8e\u8bbf\u95ee\u7c7b\u5c5e\u6027class.__getattribute__\u8c03\u7528\u65b9\u5f0f\uff1aClassName.__dict__['attr'].__get__(None, ClassName)\ninstance.__dict__\n\u975e\u6570\u636e\u63cf\u8ff0\u7b26(__get__)\n__getattr__ # \u5982\u679c\u5b9e\u73b0\u4e86\u7684\u8bdd\uff0c\u5728\u63cf\u8ff0\u7b26\u4e2d\u4f18\u5148\u7ea7\u6700\u4f4e\n<\/code><\/pre>\n<p>\u63cf\u8ff0\u7b26\u662f\u7531__getattribute__\u7279\u6b8a\u65b9\u6cd5\u8c03\u7528\uff0c\u8986\u76d6\u8be5\u65b9\u6cd5\u53ef\u4ee5\u9632\u6b62\u63cf\u8ff0\u7b26\u81ea\u52a8\u8c03\u7528.<\/p>\n<p>obj.__getattribute__\u548cclass.__getattribute__\u7684\u8c03\u7528\u65b9\u5f0f\u4e0d\u540c\uff0e<\/p>\n<p>\u63cf\u8ff0\u7b26\u7684\u4e09\u4e2a\u7279\u6b8a\u65b9\u6cd5\u4e00\u822c\u662f\u901a\u8fc7\u5c5e\u6027\u8bbf\u95ee\u81ea\u52a8\u8c03\u7528\uff0e<\/p>\n<p>\u51fd\u6570\u548c\u65b9\u6cd5\u7684\u63cf\u8ff0\u7b26\uff1a<\/p>\n<p>\u5728\u5c5e\u6027\u8bbf\u95ee\u671f\u95f4\u51fd\u6570\u5305\u62ec\u4e86__get__\u65b9\u6cd5\u7528\u4e8e\u7ed1\u5b9a\u65b9\u6cd5\uff0e\u56e0\u6b64\u51fd\u6570\u548c\u65b9\u6cd5\u662f\u975e\u6570\u636e\u63cf\u8ff0\u7b26\uff0e<\/p>\n<pre><code>class TClass(object):\ndef __get__(self, obj, typ=None):\nreturn types.MethodType(self, obj, typ)\ndef tmethod(self, args):\nreturn args\nclass Foo(object):\n@Tclass\ndef bar(self):\nprint('in bar')\nobj = TClass()\nTClass.__dict__['tmethod'] # __tion __main__.f\nTClass.tmethod # unbound method TClass.tmethod\nobj.tmethod # bound method TClass.tmethod of &lt;__main__.TClass object at 0x7f8a4f084c10&gt;\nobj.function(*args) -&gt; function(obj, *args)\nClass.function(*args) -&gt; function(*args)\n<\/code><\/pre>\n<h2 id=\"property\">property<\/h2>\n<p>property\u5c5e\u6027\u662f\u4e00\u79cd\u6709\u7528\u7684\u7279\u6b8a\u7c7b\u578b\u7684\u63cf\u8ff0\u7b26\uff0e \u4e5f\u662fdescriptor\u7684\u4e3b\u8981\u7528\u9014\uff0e<\/p>\n<pre><code>property(fget=None, fset=None, fdel=None, doc=None) # \u8fd4\u56de\u4e00\u4e2aproperty\u7c7b\u578b\u7684\u5bf9\u8c61\n<\/code><\/pre>\n<p>\u901a\u8fc7\u4e0a\u9762\u7684descriptor\u7684\u666e\u901a\u65b9\u5f0f\u5b9e\u73b0\u7eafpytho\u5199\u7684property:<\/p>\n<pre><code>class Property(object):\ndef __init__(self, fget, fset, fdelete):\nself.fget = fget\nself.fset = fset\nself.fdelete = fdelete\ndef __get__(self, obj, typ=None):\nreturn self.fget(obj)\ndef __set__(self, obj, val):\nself.fset(obj, val)\ndef __delete__(self, obj):\nself.fdelete(obj)\nclass Foo(object):\ndef fget(self):\nprint 'fget called'\ndef fset(self, val):\nprint 'fset called'\ndef fdelete(self):\nprint 'fdelete called'\nbar = Property(fget, fset, fdelete)\n<\/code><\/pre>\n<p>\u901a\u8fc7\u88c5\u9970\u5668@property\u6765\u5b9e\u73b0\uff1a<\/p>\n<pre><code>class Person(object):\ndef __init__(self):\nself._email = None\n@property\ndef email(self):\nreturn self._email\n@email.setter\ndef email(self, value):\nm = re.match('\\W+@\\W+\\.\\W+', value)\nif not m:\nraise Exception('email not valid')\nself._email = value\n@email.deleter\ndef email(self):\ndel self._email\n<\/code><\/pre>\n<p><a class=\"link\" href=\"https:\/\/github.com\/crazy-canux\/python\/tree\/master\/python\/descriptor\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/crazy-canux\/python\/tree\/master\/python\/descriptor<\/a><\/p>\n<hr>\n<h1 id=\"super\">super<\/h1>\n<p>\u56e0\u4e3a\u540c\u540d\u7684\u65b9\u6cd5\u5b50\u7c7b\u4f1a\u8986\u76d6\u7236\u7c7b\uff0c\u5728\u5b50\u7c7b\u4e2d\u8c03\u7528\u7236\u7c7b\u7684\u540c\u540d\u65b9\u6cd5\u53ef\u4ee5\u901a\u8fc7super\u5185\u7f6e\u51fd\u6570\u3002<\/p>\n<p>super()\u65b9\u6cd5\u5b9e\u9645\u662f\u4e00\u4e2a\u6784\u9020\u5668\u3002\u81ea\u52a8\u627e\u5230\u57fa\u7c7b\u65b9\u6cd5\uff0c\u540c\u65f6\u4f20\u5165self\u53c2\u6570\u3002<\/p>\n<pre><code>super().__init__() # \u4e0d\u9700\u8981\u4f20\u9012\u53c2\u6570\n<\/code><\/pre>\n<p>\u5bf9\u4e8e\u5355\u7ee7\u627f, super\u7528\u6765\u8c03\u7528\u7236\u7c7b\u540c\u540d\u65b9\u6cd5\u3002<\/p>\n<pre><code>class Child(Parent):\ndef foo(self):\nParent.foo(self) # \u53ef\u4ee5\u624b\u52a8\u8c03\u7528\u7236\u7c7b\u540c\u540d\u7684\u65b9\u6cd5\uff0c\u8c03\u7528\u975e\u7ed1\u5b9a\u65b9\u6cd5\uff0c\u4f20\u5165self\u53c2\u6570\u3002\nclass Child(Parent):\ndef __init__(self, *args, **kwargs):\nsuper().__init__(*args, **kwargs)\n...\ndef foo(self, *args, **kwargs):\nsuper().foo(*args, **kwargs)\n...\n<\/code><\/pre>\n<p>\u5bf9\u4e8e\u591a\u7ee7\u627f\uff0csuper\u7528\u6cd5\u53c2\u8003\u4e0a\u9762\u7684\u591a\u7ee7\u627f\uff0e<\/p>\n<p>\u5e38\u7528\u573a\u666f\uff1a<\/p>\n<ul>\n<li>\u8c03\u7528\u7236\u7c7b\u6784\u9020\u51fd\u6570<\/li>\n<li>\u6269\u5c55\u7236\u7c7b\u65b9\u6cd5<\/li>\n<li>\u591a\u91cd\u7ee7\u627f\u573a\u666f<\/li>\n<li>\u5c5e\u6027\u8bbe\u7f6e\u573a\u666f<\/li>\n<li>\u5408\u4f5c\u5f0f\u7ee7\u627f<\/li>\n<li>\u7c7b\u65b9\u6cd5\u4e2d\u4f7f\u7528<\/li>\n<li>\u9759\u6001\u65b9\u6cd5\u4e2d\u4f7f\u7528<\/li>\n<\/ul>\n<p>super()\u8fd4\u56de\u7684\u5bf9\u8c61\u6709\u4e00\u4e2a\u7528\u4e8e\u8c03\u7528Descriptor\u7684\u5b9a\u5236__getattribute__()\u65b9\u6cd5\uff0e<\/p>\n<pre><code>super(B, obj).method() -&gt;\nobj.__class__.__mro__ -&gt;\nA.__dict__['method'].__get__(obj, B)\n<\/code><\/pre>\n<p><a class=\"link\" href=\"https:\/\/rhettinger.wordpress.com\/2011\/05\/26\/super-considered-super\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/rhettinger.wordpress.com\/2011\/05\/26\/super-considered-super\/<\/a><\/p>\n<p>\u53c2\u8003\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff0e<\/p>\n<h1 id=\"classmethod\">classmethod<\/h1>\n<p>classmethod \u662f\u4e00\u4e2a\u5185\u7f6e\u88c5\u9970\u5668\uff0c\u7528\u4e8e\u5c06\u65b9\u6cd5\u8f6c\u6362\u4e3a\u7c7b\u65b9\u6cd5\u3002\u7c7b\u65b9\u6cd5\u7684\u7279\u70b9\u662f\uff1a<\/p>\n<ul>\n<li>\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u7c7b\u672c\u8eab cls\uff0c\u800c\u4e0d\u662f\u5b9e\u4f8b self<\/li>\n<li>\u53ef\u4ee5\u901a\u8fc7\u7c7b\u6216\u5b9e\u4f8b\u8c03\u7528<\/li>\n<li>\u53ef\u4ee5\u8bbf\u95ee\u7c7b\u5c5e\u6027\uff0c\u4f46\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u5b9e\u4f8b\u5c5e\u6027<\/li>\n<li>\u5e38\u7528\u4e8e\u521b\u5efa\u5907\u9009\u6784\u9020\u51fd\u6570<\/li>\n<\/ul>\n<p>\u7c7b\u65b9\u6cd5\u901a\u5e38\u7528\u4e8e\u66ff\u4ee3\u7c7b\u6784\u9020\u51fd\u6570\uff0e<\/p>\n<pre><code>class ClassName(object):\n@classmethod\ndef demo_cm(cls, *args, **kwargs):\n...\n# \u53ef\u4ee5\u901a\u8fc7\u7c7b\u6765\u8c03\u7528, \u4e5f\u5c31\u662f\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528\u975e\u7ed1\u5b9a\u65b9\u6cd5\uff0e\u81ea\u52a8\u4f20\u5165\u7c7b\u4f5c\u4e3a\u7b2c\u4e00\u4e2a\u53c2\u6570\uff0e\nClassName.demo_cm(args, kwargs)\n# \u4e5f\u53ef\u4ee5\u901a\u8fc7\u5b9e\u4f8b\u6765\u8c03\u7528, \u81ea\u52a8\u4f20\u5165\u7c7b\u4f5c\u4e3a\u7b2c\u4e00\u4e2a\u53c2\u6570\nClassName().demo_cm(args, kwargs) \/\/ not recommend\n<\/code><\/pre>\n<p>\u63cf\u8ff0\u7b26\u76f8\u5173\uff1a<\/p>\n<pre><code>obj.function(*args) -&gt; function(type(obj), *args)\nClass.function(*args) -&gt; function(Class, *args)\n<\/code><\/pre>\n<p>\u5e38\u7528\u573a\u666f\uff1a<\/p>\n<ul>\n<li>\u5907\u9009\u6784\u9020\u51fd\u6570<\/li>\n<li>\u5de5\u5382\u65b9\u6cd5\u6a21\u5f0f<\/li>\n<li>\u8bbf\u95ee\u548c\u4fee\u6539\u7c7b\u5c5e\u6027<\/li>\n<li>\u914d\u7f6e\u548c\u8bbe\u7f6e\u76f8\u5173\u65b9\u6cd5<\/li>\n<li>\u7ee7\u627f\u4e2d\u7684\u7c7b\u65b9\u6cd5<\/li>\n<\/ul>\n<h1 id=\"staticmethod\">staticmethod<\/h1>\n<p>staticmethod \u662f\u4e00\u4e2a\u5185\u7f6e\u88c5\u9970\u5668\uff0c\u7528\u4e8e\u5c06\u65b9\u6cd5\u8f6c\u6362\u4e3a\u9759\u6001\u65b9\u6cd5\u3002\u9759\u6001\u65b9\u6cd5\u7684\u7279\u70b9\u662f\uff1a<\/p>\n<ul>\n<li>\u4e0d\u63a5\u6536\u9690\u5f0f\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\uff08\u4e0d\u9700\u8981 self \u6216 cls\uff09<\/li>\n<li>\u53ef\u4ee5\u901a\u8fc7\u7c7b\u6216\u5b9e\u4f8b\u8c03\u2026\u2026<\/li>\n<li>\u4e0d\u80fd\u8bbf\u95ee\u7c7b\u6216\u5b9e\u4f8b\u7684\u5c5e\u6027<\/li>\n<li>\u884c\u4e3a\u7c7b\u4f3c\u666e\u901a\u51fd\u6570\uff0c\u53ea\u662f\u5728\u7c7b\u7684\u547d\u540d\u7a7a\u95f4\u4e2d<\/li>\n<\/ul>\n<p>\u4f8b\u5b50:<\/p>\n<pre><code>class ClassName(object):\n@staticmethod\ndef demo_sm():\n...\nClassName.demo_sm()\nClassName().demo_sm()\n<\/code><\/pre>\n<p>\u63cf\u8ff0\u7b26\u76f8\u5173\uff1a<\/p>\n<pre><code>obj.function(*args) -&gt; function(*args)\nClass.function(*args) -&gt; function(*args)\n<\/code><\/pre>\n<p>\u5e38\u7528\u573a\u666f\uff1a<\/p>\n<ul>\n<li>\u5de5\u5177\u51fd\u6570<\/li>\n<li>\u9a8c\u8bc1\u548c\u8f6c\u6362\u51fd\u6570<\/li>\n<li>\u5e38\u91cf\u548c\u914d\u7f6e\u76f8\u5173<\/li>\n<li>\u5de5\u5382\u65b9\u6cd5\u8f85\u52a9\u51fd\u6570<\/li>\n<\/ul>\n<hr>\n<h1 id=\"class-decorators\">Class Decorators<\/h1>\n<p>\u7c7b\u88c5\u9970\u5668\u6bd4\u51fd\u6570\u88c5\u9970\u5668\u66f4\u7075\u6d3b\uff0c\u9ad8\u5185\u805a\uff0c\u5c01\u88c5\u6027\u7b49\u4f18\u70b9\uff0e<\/p>\n<p>\u7c7b\u88c5\u9970\u5668\u7528\u4e8e\u88c5\u9970\u4e00\u4e2a\u7c7b.<\/p>\n<pre><code>def deco_name(cls):\nclass WrapperName(cls, ...):\ndef __init__(self, *args, **kwargs):\ncls.__init__()\n....__init__()\n...\nreturn WrapperName\n@deco_name\nclass ClassName(object):\ndef __init__(self, *args, **kwargs):\n...\n...\n<\/code><\/pre>\n<p><a class=\"link\" href=\"https:\/\/github.com\/crazy-canux\/python\/blob\/master\/python\/decorator\/class_decorator.py\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/crazy-canux\/python\/blob\/master\/python\/decorator\/class_decorator.py<\/a><\/p>\n<hr>"},{"title":"Python","link":"https:\/\/canuxcheng.com\/post\/python\/","pubDate":"Tue, 21 Jun 2016 21:18:09 +0000","guid":"https:\/\/canuxcheng.com\/post\/python\/","description":"<h1 id=\"python\u6982\u8ff0\"><strong>Python\u6982\u8ff0<\/strong><\/h1>\n<p><a class=\"link\" href=\"https:\/\/docs.python.org\/2.7\/index.html\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.python.org\/2.7\/index.html<\/a><\/p>\n<p><a class=\"link\" href=\"http:\/\/python.usyiyi.cn\/translate\/python_278\/index.html\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/python.usyiyi.cn\/translate\/python_278\/index.html<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/docs.python.org\/3.5\/index.html\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.python.org\/3.5\/index.html<\/a><\/p>\n<p><a class=\"link\" href=\"http:\/\/python.usyiyi.cn\/translate\/python_352\/index.html\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/python.usyiyi.cn\/translate\/python_352\/index.html<\/a><\/p>\n<p>python\u662f\u4e00\u95e8\u4f18\u96c5\u800c\u5065\u58ee\u7684\u8bed\u8a00.<\/p>\n<p>\u7ee7\u627f\u4e86\u7f16\u8bd1\u8bed\u8a00(\u9759\u6001\u8bed\u8a00)\u7684\u5f3a\u5927\u6027\u548c\u901a\u7528\u6027.<\/p>\n<p>\u540c\u65f6\u4e5f\u501f\u9274\u4e86\u811a\u672c\u8bed\u8a00(\u52a8\u6001\u8bed\u8a00)\u7684\u6613\u7528\u6027\uff0e<\/p>\n<p>python\u7279\u70b9\uff1a<\/p>\n<ul>\n<li>\u9ad8\u7ea7<\/li>\n<li>\u9762\u5411\u5bf9\u8c61<\/li>\n<li>\u53ef\u5347\u7ea7<\/li>\n<li>\u53ef\u6269\u5c55<\/li>\n<li>\u53ef\u79fb\u690d\u6027<\/li>\n<li>\u6613\u5b66<\/li>\n<li>\u6613\u8bfb<\/li>\n<li>\u6613\u7ef4\u62a4<\/li>\n<li>\u5065\u58ee\u6027<\/li>\n<li>\u9ad8\u6548\u7684\u5feb\u901f\u539f\u578b\u5f00\u53d1\u5de5\u5177<\/li>\n<li>\u5185\u5b58\u7ba1\u7406\u5668<\/li>\n<li>\u89e3\u91ca\u6027\u548c\u7f16\u8bd1\u6027<\/li>\n<\/ul>\n<hr>\n<h1 id=\"python\u57fa\u672c\u8bed\u6cd5\"><strong>python\u57fa\u672c\u8bed\u6cd5<\/strong><\/h1>\n<p>python\u6e90\u7a0b\u5e8f\u53ebxxx.py<\/p>\n<p>python\u4e2d\u4e00\u5207\u7686\u5bf9\u8c61\uff0e<\/p>\n<p>python\u5927\u5c0f\u5199\u654f\u611f\uff0e<\/p>\n<p>python\u901a\u8fc7\u7f29\u8fdb\u548c\u5192\u53f7:\u533a\u5206\u8bed\u6cd5\u5757\uff0c\u800c\u4e0d\u662f\u5927\u62ec\u53f7{}.<\/p>\n<p>python\u4e2d\u7684\u8868\u8fbe\u5f0f(\u6761\u4ef6\/\u5faa\u73af\u8868\u8fbe\u5f0f\u7b49)\u4e0d\u9700\u8981\u7528\u5c0f\u62ec\u53f7()\u62ec\u8d77\u6765\uff0e<\/p>\n<p>python\u6807\u8bc6\u7b26(\u53d8\u91cf\uff0c\u51fd\u6570\uff0c\u53c2\u6570\uff0c\u7c7b\u7b49)\u7531\u5b57\u6bcd\u548c\u4e0b\u5212\u7ebf\u5f00\u5934\uff0c\u8fd8\u53ef\u4ee5\u5305\u542b\u6570\u5b57\uff0e\u4e0d\u80fd\u662f\u5173\u952e\u5b57\uff0e<\/p>\n<p>python\u4e0d\u652f\u6301\u65b9\u6cd5\u6216\u51fd\u6570\u91cd\u8f7d\uff0e<\/p>\n<p>python\u4e0d\u652f\u6301char\u548ctype\u7c7b\u578b\uff0e<\/p>\n<p>python\u6ca1\u6709switch\u8bed\u53e5\uff0e<\/p>\n<p>python\u652f\u6301\u591a\u7ee7\u627f\uff0e<\/p>\n<p>python\u4e0d\u652f\u6301++\/&ndash;\u81ea\u589e\u548c\u81ea\u51cf\u8fd0\u7b97\u7b26\uff0e<\/p>\n<p>python\u652f\u6301\u8fde\u7eed\u6bd4\u8f83\uff0ca&lt;b&lt;c.<\/p>\n<p>\u547d\u540d\u89c4\u5219<\/p>\n<p>variable: snake_case, case\nfunction: get_user_info(), get()\nclass: User, UserInfo\nmodule: snake_case.py\npackage: myapp, utils<\/p>\n<h2 id=\"lexical-analysis\">lexical analysis<\/h2>\n<p><a class=\"link\" href=\"https:\/\/docs.python.org\/2\/reference\/lexical_analysis.html\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.python.org\/2\/reference\/lexical_analysis.html<\/a><\/p>\n<p>Logical lines and physical lines\uff1a<\/p>\n<pre><code># python\u901a\u8fc7\u884c\u5c3e\u7684\u4ee4\u724cNEWLINE\u8868\u793a\u903b\u8f91\u884c\nexpression\n# \u4ee5\u64cd\u4f5c\u7cfb\u7edf\u7684\u6362\u884c\u7b26\u8868\u793a\u7269\u7406\u884c\uff0e\n\\n\n<\/code><\/pre>\n<p>encoding declarations:<\/p>\n<pre><code># python\u811a\u672c\u4e2d\u7684\u7b2c\u4e00\u884c\u6216\u7b2c\u4e8c\u884c\u7684\ncoding[=:]\\s*([-\\w.]+)\n# \u6ce8\u91ca\u4e0e\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u5c06\u88ab\u4f5c\u4e3a\u7f16\u7801\u7533\u660e\u5904\u7406\uff0e\n<\/code><\/pre>\n<p>[Deprecated] explicit line joining:<\/p>\n<pre><code># \u591a\u4e2a\u7269\u7406\u884c\u901a\u8fc7\u53cd\u659c\u7ebfbackslash\u7eed\u884c\u8fdb\u884c\u663e\u793a\u6362\u884c\n# \u63a8\u8350\u7528\u9690\u5f0f\u6362\u884c\uff0e\nif a == b \\\nand c ==d: # \u53ea\u6709\u7eed\u884c\u7684\u6700\u540e\u4e00\u884c\u53ef\u4ee5\u6709\u6ce8\u91ca\uff0e\u53cd\u659c\u7ebf\u7684\u884c\u4e0d\u80fd\u6ce8\u91ca.\nprint('more than one physical line.')\n<\/code><\/pre>\n<p>implicit line joining\uff1a<\/p>\n<pre><code># \u5728\u62ec\u53f7(parentheses),\u65b9\u62ec\u53f7(square brackets)\uff0c\u5927\u62ec\u53f7(curly braces)\u4e2d\u7684\u8868\u8fbe\u5f0f\u53ef\u4ee5\u5206\u5272\u591a\u4e2a\u7269\u7406\u884c\u800c\u4e0d\u9700\u8981\u663e\u793a\u6362\u884c\uff0e\ntest_list = [\n'a', # \u6bcf\u4e00\u884c\u90fd\u53ef\u4ee5\u6ce8\u91ca\n'b'\n]\n<\/code><\/pre>\n<p>indentation:<\/p>\n<pre><code># \u903b\u8f91\u884c\u7684\u5f00\u5934\u7684\u7a7a\u683c\u548c\u8df3\u683c\u7528\u4e8e\u7f29\u8fdb\uff0cpython\u6839\u636e\u884c\u7684\u7f29\u8fdb\u7ea7\u522b\u533a\u5206\u8bed\u6cd5\u5757\uff0e\n# \u7f29\u8fdb\u7ea7\u522b\u7528\u4e8e\u751f\u6210INDENT\u548cDEDENT\u4e24\u4e2a\u4ee4\u724c\npep8\u5efa\u8bae\u7528\u56db\u4e2a\u7a7a\u683c\u8868\u793a\u4e00\u4e2a\u7f29\u8fdb\u7ea7\u522b\uff0e\n<\/code><\/pre>\n<p>\u6267\u884cpython\u4ee3\u7801\uff1a<\/p>\n<pre><code>$ python mycode.py\n# OR\n$ chmod u+x mycode.py\n$ .\/mycode.py\n<\/code><\/pre>\n<h3 id=\"f-string\">f-string<\/h3>\n<p>formatted string literal. \u7528\u6765\u5728\u5b57\u7b26\u4e32\u4e2d\u5d4c\u5165\u8868\u8fbe\u5f0f\u3002<\/p>\n<p>\u683c\u5f0f\u5b57\u7b26\u4e32\u5b57\u9762\u503c\u5219\u662f\u53ef\u5728\u8fd0\u884c\u65f6\u6c42\u503c\u7684\u8868\u8fbe\u5f0f\u3002<\/p>\n<pre><code>print(f&quot;Hello, {name}!&quot;)\n<\/code><\/pre>\n<p>\u683c\u5f0f\u5316:<\/p>\n<pre><code>f&quot;{price:.2f}&quot; # \u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\n<\/code><\/pre>\n<p>!s call str()<\/p>\n<pre><code>f&quot;{x!s}&quot; # \u8c03\u7528str()\u51fd\u6570\uff0c\u7b49\u4ef7\u4e8ef&quot;{str(x)}&quot;\n<\/code><\/pre>\n<p>!r call repr()<\/p>\n<pre><code>f&quot;his name is {name!r}&quot;\nf&quot;his name is {repr(name)}&quot;\n<\/code><\/pre>\n<p>!a call ascii()<\/p>\n<hr>\n<h1 id=\"python\u6ce8\u91ca\"><strong>python\u6ce8\u91ca<\/strong><\/h1>\n<p>\u5355\u884c\u6ce8\u91ca\uff1a<\/p>\n<pre><code># comment\n<\/code><\/pre>\n<p>\u591a\u884c\u6ce8\u91ca\uff1a<\/p>\n<pre><code>&quot;&quot;&quot;\ncomment1\ncomment2\ncomment3\n&quot;&quot;&quot;\n<\/code><\/pre>\n<hr>\n<h1 id=\"python3\u952e\u5b57\"><strong>python3\u952e\u5b57<\/strong><\/h1>\n<pre><code>def lambda class import from\nif elif else while for continue break try except finally return pass\nglobal raise assert del yield with as\nand or not is in nonlocal\nFalse None True\n<\/code><\/pre>\n<p>nonlocal: \u5728\u5185\u5c42\u51fd\u6570\u4fee\u6539\u5916\u5c42\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cf<\/p>\n<hr>\n<h1 id=\"python\u8fd0\u7b97\u7b26\u548c\u4f18\u5148\u7ea7\"><strong>python\u8fd0\u7b97\u7b26\u548c\u4f18\u5148\u7ea7<\/strong><\/h1>\n<p>\u4f18\u5148\u7ea7\u4ece\u9ad8\u5230\u5e95\uff1a<\/p>\n<pre><code># \u51fd\u6570\u8c03\u7528\nf(x)\n# \u5e8f\u5217\u7684\u5207\u7247\nseq[ind1:ind2:step]\n# \u5e8f\u5217\u4e0b\u6807\u7d22\u5f15\nseq[index]\n# \u5c5e\u6027\u8fd0\u7b97.\nobject.attribute\n# \u7b97\u672f\u8fd0\u7b97\u7b26\n** \u5e42\u8fd0\u7b97\uff0c\u4e58\u65b9\u8fd0\u7b97\u7b26, \u7b49\u6548\u5185\u7f6e\u51fd\u6570pow(), \u4f18\u5148\u7ea7\u9ad8\u4e8e\u5355\u76ee\u8fd0\u7b97\u7b26\n# \u4f4d\u8fd0\u7b97(\u53ea\u80fd\u7528\u4e8e\u6574\u6570)\n~ \u6309\u4f4d\u53d6\u53cd\n# \u5355\u76ee\u8fd0\u7b97\u7b26\uff0e\n+expr # \u7ed3\u679c\u7b26\u53f7\u4e0d\u53d8\n-expr # \u5bf9\u7ed3\u679c\u7b26\u53f7\u53d6\u8d1f\n# \u7b97\u672f\u8fd0\u7b97\u7b26, \u4f18\u5148\u7ea7\u4e00\u6837\n*\n\/ python2\u4e24\u4e2a\u64cd\u4f5c\u6570\u90fd\u662f\u6574\u6570\u65f6\uff0c\u7ed3\u679c\u662f\u5546\u820d\u53bb\u5c0f\u6570\u540e\u7684\u6574\u6570,\u4e5f\u5c31\u662f\u5730\u677f\u9664; \u53ea\u8981\u6709\u4e00\u4e2a\u4ee5\u4e0a\u7684\u6d6e\u70b9\u64cd\u4f5c\u6570,\u7ed3\u679c\u5c31\u662f\u6d6e\u70b9\u6570\uff0c\u4e5f\u5c31\u662f\u771f\u6b63\u7684\u9664\u6cd5\uff0e\n\/ python3\u4f1a\u81ea\u52a8\u8f6c\u5316\u6210\u4e24\u4e2a\u6d6e\u70b9\u6570\u51fa\u53d1\uff0c\u7ed3\u679c\u6c38\u8fdc\u662f\u6d6e\u70b9\u6570\uff0c\u6c38\u8fdc\u662f\u771f\u6b63\u7684\u9664\u6cd5\uff0e\n\/\/ \u5730\u677f\u9664\uff0c\u7ed3\u679c\u603b\u662f\u820d\u53bb\u5c0f\u6570\u90e8\u5206\uff0e\n%\n# \u7b97\u672f\u8fd0\u7b97\u7b26, \u4f18\u5148\u7ea7\u4e00\u6837\n+\n-\n# \u4f4d\u8fd0\u7b97(\u53ea\u80fd\u7528\u4e8e\u6574\u6570), \u4f18\u5148\u7ea7\u4e00\u6837\uff0e\n&lt;&lt; \u5de6\u79fb\u4f4d\u8fd0\u7b97\n&gt;&gt; \u53f3\u79fb\u4f4d\u8fd0\u7b97\n# \u4f4d\u8fd0\u7b97(\u53ea\u80fd\u7528\u4e8e\u6574\u6570)\n&amp; \u6309\u4f4d\u4e0e\n# \u4f4d\u8fd0\u7b97(\u53ea\u80fd\u7528\u4e8e\u6574\u6570), \u4f18\u5148\u7ea7\u4e00\u6837\n^ \u6309\u4f4d\u5f02\u6216\n| \u6309\u4f4d\u6216\n# \u5173\u7cfb\u8fd0\u7b97, \u4f18\u5148\u7ea7\u4e00\u6837\n&lt;\n&gt;\n&lt;=\n&gt;=\n# \u5173\u7cfb\u8fd0\u7b97, \u4f18\u5148\u7ea7\u4e00\u6837\n==\n!=\n# Python2\u7684&lt;&gt;\u4e0d\u518d\u652f\u6301\uff0c\u4f7f\u7528!=\n# \u8d4b\u503c\u8fd0\u7b97\u7b26\u548c\u589e\u91cf\u8d4b\u503c\n=\n+=\n-=\n*=\n\/=\n%=\n**=\n&lt;&lt;=\n&gt;&gt;=\n&amp;=\n|=\n^=\n# [New] \u5bf9\u8c61\u8fd0\u7b97\u7b26, \u4f18\u5148\u7ea7\u4e00\u6837\nis\nis not\n# [New] \u5e8f\u5217\u7684\u5143\u7d20\/\u5b57\u5178\u7684\u952e\/\u96c6\u5408\u7684\u5143\u7d20 \u6210\u5458\u8fd0\u7b97\u7b26, \u4f18\u5148\u7ea7\u4e00\u6837\nin\nnot in\n# boolean\u903b\u8f91\u8fd0\u7b97\u7b26\nnot \u903b\u8f91\u975e\n# boolean\u903b\u8f91\u8fd0\u7b97\u7b26, \u4f18\u5148\u7ea7\u4e00\u6837\nand \u903b\u8f91\u4e0e\nor \u903b\u8f91\u6216\n<\/code><\/pre>\n<hr>\n<h1 id=\"python\u6570\u636e\u7c7b\u578b\"><strong>python\u6570\u636e\u7c7b\u578b<\/strong><\/h1>\n<p>python\u4e2d\u4e00\u5207\u7686\u5bf9\u8c61\uff0c\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u6709\u8eab\u4efd(id()), \u7c7b\u578b(type()) \u548c \u503c\u4e09\u4e2a\u5c5e\u6027\uff0e<\/p>\n<p>python\u4e2d\u5bf9\u8c61\u7684\u7c7b\u578b\u548c\u5185\u5b58\u5360\u7528\u90fd\u662f\u5728\u8fd0\u884c\u65f6\u786e\u5b9a\u7684\uff0e<\/p>\n<p>is\u548cis not\u53ef\u4ee5\u5224\u65ad\u4e24\u4e2a\u53d8\u91cf\u662f\u5426\u6307\u5411\u540c\u4e00\u4e2a\u5bf9\u8c61\uff1a<\/p>\n<pre><code>a is b # \u7b49\u4ef7\u4e8e id(a) == id(b), \u8868\u793aa\u548cb\u662f\u540c\u4e00\u4e2a\u5bf9\u8c61\na is not b # \u7b49\u4ef7\u4e8e id(a) != id(b), \u8868\u793aa\u548cb\u4e0d\u662f\u540c\u4e00\u4e2a\u5bf9\u8c61\n<\/code><\/pre>\n<p>is\u548cis not\u53ef\u4ee5\u5224\u65ad\u53d8\u91cf\u7684\u7c7b\u578b:<\/p>\n<pre><code>import types\ntype(a) is types.IntType\n<\/code><\/pre>\n<h2 id=\"\u5783\u573e\u56de\u6536\"><em>\u5783\u573e\u56de\u6536<\/em><\/h2>\n<p>Garbage Collector\u5783\u573e\u56de\u6536\u673a\u5236\u662f\u5f15\u7528\u8ba1\u6570\u4e3a\u4e3b\uff0c\u6807\u8bb0\u6e05\u9664\u548c\u5206\u4ee3\u6536\u96c6\u4e3a\u8f85\uff0e<\/p>\n<p>\u5f53\u5bf9\u8c61\u88ab\u5f15\u7528\uff0c\u5305\u62ec\u5bf9\u8c61\u5728\u88ab\u521b\u5efa\uff0c\u5bf9\u8c61\u88ab\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u51fd\u6570\uff0c\u5bf9\u8c61\u6210\u4e3a\u5bb9\u5668\u5bf9\u8c61\u7684\u4e00\u4e2a\u5143\u7d20\u65f6\uff0c\u5f15\u7528\u503c\u589e\u52a0\uff0e<\/p>\n<p>\u5f53\u5bf9\u8c61\u7684\u5f15\u7528\u88ab\u9500\u6bc1\uff0c\u5305\u62ec\u4e00\u4e2a\u672c\u5730\u5f15\u7528\u79bb\u5f00\u5176\u4f5c\u7528\u57df\uff0c\u5bf9\u8c61\u7684\u522b\u540d\u88abdel\u663e\u793a\u9500\u6bc1\uff0c\u5bf9\u8c61\u7684\u522b\u540d\u88ab\u8d4b\u503c\u7ed9\u5176\u5b83\u5bf9\u8c61\uff0c\u5bf9\u8c61\u88ab\u4ece\u4e00\u4e2a\u7a97\u53e3\u5bf9\u8c61\u4e2d\u79fb\u9664\uff0c\u7a97\u53e3\u5bf9\u8c61\u672c\u8eab\u88abdel\u663e\u793a\u9500\u6bc1\uff0c\u5f15\u7528\u503c\u51cf\u5c11\uff0e<\/p>\n<p>del\u8bed\u53e5\u4f1a\u5220\u9664\u5bf9\u8c61\u7684\u4e00\u4e2a\u5f15\u7528\uff0e<\/p>\n<h2 id=\"\u53d8\u91cf\u548c\u5e38\u91cf\"><em>\u53d8\u91cf\u548c\u5e38\u91cf<\/em><\/h2>\n<p>python\u662f\u52a8\u6001\u7c7b\u578b\u8bed\u8a00\uff0c\u53d8\u91cf\u4e0d\u9700\u8981\u5148\u7533\u660e\uff0c\u53d8\u91cf\u7684\u7c7b\u578b\u548c\u503c\u5728\u8d4b\u503c\u7684\u65f6\u5019\u88ab\u521d\u59cb\u5316\uff0e<\/p>\n<p>\u7528\u5168\u90e8\u5c0f\u5199\u8868\u793a\u53d8\u91cf\uff1a<\/p>\n<pre><code>counter = 0\nmiles = 100.03\nname = &quot;canux&quot;\n<\/code><\/pre>\n<p>\u7528\u5168\u90e8\u5927\u5199\u8868\u793a\u5e38\u91cf\uff1a<\/p>\n<pre><code>PIE = 3.14\n<\/code><\/pre>\n<h2 id=\"\u7c7b\u578b\u603b\u7ed3\"><em>\u7c7b\u578b\u603b\u7ed3<\/em><\/h2>\n<p>\u66f4\u65b0\u6a21\u578b\uff1a<\/p>\n<ul>\n<li>\u4e0d\u53ef\u53d8\u7c7b\u578b:immutable\u4e0d\u53ef\u53d8\u7c7b\u578b\u5c31\u662f\u53d8\u91cf\u7684\u503c\u662f\u56fa\u5b9a\u7684\uff0c\u518d\u6b21\u8d4b\u503c\u5c31\u662f\u91cd\u65b0\u521b\u5efa\u4e86\u65b0\u7684\u5bf9\u8c61: \u6570\u5b57\u7c7b\u578b\uff0c\u5b57\u7b26\u4e32str\uff0c\u5143\u7ec4tuple\uff0c\u4e0d\u53ef\u53d8\u96c6\u5408frozenset.<\/li>\n<li>\u53ef\u53d8\u7c7b\u578b:mutable\u53ef\u53d8\u7c7b\u578b\u5c31\u662f\u53d8\u91cf\u7684\u503c\u662f\u53ef\u4ee5\u6539\u53d8\u7684: \u5217\u8868list\uff0c\u5b57\u5178dict\uff0c\u53ef\u53d8\u96c6\u5408set.<\/li>\n<\/ul>\n<p>\u5b58\u50a8\u6a21\u578b\uff1a<\/p>\n<ul>\n<li>scalar\u6807\u91cf\/\u539f\u5b50\u7c7b\u578b:\u53ea\u80fd\u5bb9\u7eb3\u5355\u4e2a\u5bf9\u8c61\uff1a\u6570\u5b57\u7c7b\u578b\uff0c\u5b57\u7b26\u4e32str<\/li>\n<li>container\u5bb9\u5668\u7c7b\u578b:\u53ef\u4ee5\u5bb9\u7eb3\u591a\u4e2a\u5bf9\u8c61\uff1a\u5143\u7ec4tuple\uff0c\u5217\u8868list\uff0c\u5b57\u5178dict,\u96c6\u5408set\/frozenset.<\/li>\n<\/ul>\n<p>\u8bbf\u95ee\u6a21\u578b\uff1a<\/p>\n<ul>\n<li>\u76f4\u63a5\u5b58\u53d6:\u6570\u5b57\u7c7b\u578b<\/li>\n<li>\u7d22\u5f15\u8bbf\u95ee:sequence\u5e8f\u5217\u662f\u987a\u5e8f\u8bbf\u95ee\uff1a\u5b57\u7b26\u4e32str\uff0c\u5143\u7ec4tuple\uff0c\u5217\u8868list.<\/li>\n<li>\u6620\u5c04\u8bbf\u95ee:mapping\u6620\u5c04\u7c7b\u578b\u662f\u6620\u5c04\u8bbf\u95ee,\u5143\u7d20\u65e0\u5e8f\u5b58\u653e\uff0c\u901a\u8fc7\u552f\u4e00\u7684key\u6765\u8bbf\u95ee\uff1a\u5b57\u5178dict.<\/li>\n<\/ul>\n<h2 id=\"\u6570\u636e\u62f7\u8d1d\">\u6570\u636e\u62f7\u8d1d<\/h2>\n<p>\u6d45\u62f7\u8d1d:<\/p>\n<pre><code>\u53ea\u62f7\u8d1d\u9876\u5c42\u6570\u636e.\n\u5bf9\u4e0d\u53ef\u53d8\u5bf9\u8c61\u4e0d\u5f00\u8f9f\u65b0\u7a7a\u95f4,\u76f8\u5f53\u4e8e\u8d4b\u503c\u64cd\u4f5c;\u4fee\u6539\u539f\u6570\u636e,\u76f8\u5f53\u4e8e\u5b9a\u4e49\u4e86\u4e00\u4e2a\u65b0\u7684\u6570\u636e.\u62f7\u8d1d\u7684\u6570\u636e\u4e0d\u53d8.\na=10\nb=copy.copy(a)\nold_id = id(a) == id(b)\na=5 # \u4fee\u6539a\u76f8\u5f53\u4e8e\u5b9a\u4e49\u4e86\u65b0\u53d8\u91cf\nid(a) != old_id\nid(b) == old_id # id(b) \u4e0d\u53d8\nid(b) == 10\n\u5bf9\u53ef\u53d8\u5bf9\u8c61\u4f1a\u5728\u5185\u5b58\u5f00\u8f9f\u65b0\u7a7a\u95f4\u4fdd\u5b58\u62f7\u8d1d\u7684\u6570\u636e;\u53ea\u62f7\u8d1d\u7b2c\u4e00\u5c42\u4e2d\u7684\u5f15\u7528,\u539f\u6570\u636e\u88ab\u4fee\u6539,\u62f7\u8d1d\u7684\u5bf9\u8c61\u4e5f\u88ab\u4fee\u6539.\na=[1,2,3]\nb=copy.copy(a)\nid(a) != id(b)\na[0]=5 # \u6539\u53d8a\u7684\u6570\u636e\nb == a # b\u7684\u6570\u636e\u4e5f\u6539\u53d8\ncopy.copy()\n<\/code><\/pre>\n<p>\u6df1\u62f7\u8d1d:<\/p>\n<pre><code>\u9010\u5c42\u62f7\u8d1d\u6570\u636e,\u76f4\u5230\u62f7\u8d1d\u7684\u6240\u6709\u5f15\u7528\u90fd\u662f\u4e0d\u53ef\u53d8\u5f15\u7528.\n\u6df1\u62f7\u8d1d,\u4e00\u4efd\u6570\u636e\u6539\u53d8,\u4e0d\u5f71\u54cd\u53e6\u4e00\u4efd\u6570\u636e.\ncopy.deepcopy()\n<\/code><\/pre>\n<h2 id=\"sequences\u5e8f\u5217\u7c7b\u578b\"><em>Sequences\u5e8f\u5217\u7c7b\u578b<\/em><\/h2>\n<p>sequence\u5e8f\u5217\u662f\u6307\u6210\u5458\u6709\u5e8f\u6392\u5217\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e0b\u6807\u504f\u79fb\u91cf\u8bbf\u95ee\uff0c\u540c\u65f6\u53ef\u4ee5\u8fdb\u884c\u5207\u7247\u64cd\u4f5c\uff0e\u5e8f\u5217\u662f\u53ef\u8fed\u4ee3\u7684\uff0e<\/p>\n<p>sequence\u7d22\u5f15\u64cd\u4f5c\uff1a<\/p>\n<pre><code>seq[ind] # \u83b7\u53d6\u4e0b\u6807\u4e3aind\u7684\u5143\u7d20\uff0c\u4e0b\u6807\u4ece0\u5f00\u59cb\uff0e\nseq[-1] # \u53d6\u6700\u540e\u4e00\u4e2a\u5143\u7d20\n<\/code><\/pre>\n<p>sequence\u5207\u7247\u64cd\u4f5c\uff1a<\/p>\n<pre><code>seq[ind1:ind2] # \u83b7\u53d6\u4e0b\u6807\u4eceind1\u5230ind2\u95f4\u7684\u5143\u7d20\u7684\u96c6\u5408\uff0e\u4e0d\u5305\u62ecind2.\nseq[:ind2] # ind1\u7f3a\u7701\u9ed8\u8ba4\u4e3a\uff10.\nseq[ind1:] # ind2\u7f3a\u7701\u8868\u793a\u4eceind1\u5230\u6700\u540e\u4e00\u4e2a\u5143\u7d20\nseq[ind1:ind2:step] # \u4ee5\u6b65\u957f\u4e3astep\u6765\u5207\u7247\nseq[:ind2:step]\nseq[::step] # ind1\u7f3a\u7701\u4e3a\uff10\uff0cind2\u7f3a\u7701\u4e3a\u6574\u4e2a\u5e8f\u5217\u957f\u5ea6\uff0e\nseq[::-1] # \u7ffb\u8f6c\u5e8f\u5217\nseq[::-step] # \u4ee5\u6b65\u957f\u4e3astep\u7ffb\u8f6c\u5e8f\u5217\uff0e\n<\/code><\/pre>\n<p>sequence\u7b97\u672f\u8fd0\u7b97\uff1a<\/p>\n<pre><code>seq * number # \u5e8f\u5217\u91cd\u590dnumber\u6b21\nsql1 + seq2 # \u4e24\u4e2a\u5e8f\u5217\u8fde\u63a5\n<\/code><\/pre>\n<p>sequence\u6210\u5458\u8fd0\u7b97\uff1a<\/p>\n<pre><code>obj in seq # obj\u5728\u5305\u542b\u5728\u5e8f\u5217\u4e2d,\u8fd4\u56deTrue\nobj not in seq # obj\u4e0d\u5305\u542b\u5728\u5e8f\u5217\u4e2d\u8fd4\u56deTrue\n<\/code><\/pre>\n<h2 id=\"\u6570\u5b57\u7c7b\u578b\"><em>\u6570\u5b57\u7c7b\u578b<\/em><\/h2>\n<p>\u6570\u5b57\u7c7b\u578b\u662f\u4e0d\u53ef\u53d8\u7c7b\u578b(immutable),\u662f\u6807\u91cf(scalar),\u662f\u76f4\u63a5\u5b58\u50a8\u7684\uff0e<\/p>\n<p>0b\u5f00\u5934\u8868\u793a\u4e8c\u8fdb\u5236<\/p>\n<p>0\u5f00\u5934\u8868\u793a\u516b\u8fdb\u5236<\/p>\n<p>0x\u5f00\u5934\u8868\u793a\u5341\u516d\u8fdb\u5236<\/p>\n<p>\u6570\u5b57\u7c7b\u578b\u8f6c\u6362\u7684\u5173\u7cfb\u662f\u6574\u6570\u8f6c\u6362\u6210\u6d6e\u70b9\u6570\uff0c\u975e\u590d\u6570\u8f6c\u6362\u6210\u590d\u6570\uff0e<\/p>\n<ul>\n<li>\n<p>int<\/p>\n<p>Python3\u7684int\u7c7b\u578b\u6574\u5408\u4e86short\u3001int\u3001long\u4e09\u79cd\u957f\u5ea6\uff0c\u7edf\u4e00\u4e3aint\u7c7b\u578b\uff0c\u4e14\u6ca1\u6709\u957f\u5ea6\u9650\u5236\u3002<\/p>\n<\/li>\n<li>\n<p>bool(int)<\/p>\n<p>bool\u7c7b\u7ee7\u627f\u81eaint.<\/p>\n<p>bool\u7c7b\u578b\u53ea\u6709True\u548cFalse\u4e24\u4e2a\u503c\uff0e<\/p>\n<pre><code> bool\u7c7b\u578b\u53d6\u53cd:\na = True\nb = bool(1-a) # b=False\n<\/code><\/pre>\n<\/li>\n<li>\n<p>float<\/p>\n<p>python\u4e2d\u7684float\u5176\u5b9e\u5c31\u5305\u62ec\u4e86\u5355\u7cbe\u5ea6\u548c\u53cc\u7cbe\u5ea6\uff0c\u76f8\u5f53\u4e8efloat\u548cdouble\u90fd\u53ef\u4ee5\u7528\uff0e<\/p>\n<\/li>\n<li>\n<p>complex<\/p>\n<p>python\u4e2d\u6709\u590d\u6570\u7c7b\u578b\uff0e<\/p>\n<\/li>\n<\/ul>\n<h2 id=\"str\"><em>str<\/em><\/h2>\n<p>python2\u4e2dstr\u548cunicode\u7ee7\u627f\u81eabasestring, basestring\u7ee7\u627f\u81eaobject.<\/p>\n<p>python3\u4e2dunicode\u548cbasestring\u5728python3\u4e2d\u88ab\u5e9f\u5f03\uff0estr\u76f4\u63a5\u7ee7\u627f\u81eaobject.<\/p>\n<p>python3\u4e2d\u4e0d\u518d\u9700\u8981u\/U\u6765\u8868\u793aunicode\u5b57\u7b26\u4e32\uff0e<\/p>\n<p>str\u7c7b\u578b\u662f\u4e0d\u53ef\u53d8\u7c7b\u578b(immutable),\u662f\u6807\u91cf(scalar),\u662f\u5e8f\u5217(sequence)\u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee\uff0e<\/p>\n<p>\u5b57\u7b26\u4e32\u8868\u793a\u65b9\u6cd5\uff1a<\/p>\n<pre><code>'This is a string'\n&quot;This is a string&quot;\n&quot;&quot;&quot;This is a string&quot;&quot;&quot;\n<\/code><\/pre>\n<p>\u5b57\u7b26\u4e32\u7684\u7eed\u884c\uff1a<\/p>\n<p>\u4e0b\u9762\u90fd\u8868\u793a\u4e00\u4e2a\u53ea\u6709\u4e00\u884c\u7684\u5b57\u7b26\u4e32\uff0e<\/p>\n<pre><code># \u4e00\u4e2a\u5f15\u53f7\u7684\u60c5\u51b5,\u9700\u8981\u5728\u5f15\u53f7\u5185\u90e8\u7a7a\u683c\u8868\u793a\u548c\u4e0b\u4e00\u884c\u6709\u7a7a\u683c\uff0c\u7eed\u884c\u7b26\u524d\u7684\u7a7a\u683c\u53ef\u6709\u53ef\u65e0\uff0e\na = 'This is a ' \\\n'string'\nb = 'This is a \\\nstring'\nc = &quot;This is a &quot; \\\n&quot;string&quot;\nd = &quot;This is a \\\nstring&quot;\n# \u4e09\u5f15\u53f7\u7eed\u884c\u7b26\u524d\u7684\u7a7a\u683c\u5c31\u8868\u793a\u548c\u4e0b\u4e00\u884c\u6709\u7a7a\u683c\uff0e\nc = &quot;&quot;&quot;This is a \\\nstring&quot;&quot;&quot;\n&gt; This is a string\nc = &quot;&quot;&quot;line1\nline2&quot;&quot;&quot;\n&gt; line1\\nline2 \u6ca1\u6709\u7eed\u884c\u7b26\u4f1a\u5728\u884c\u5c3e\u52a0\u6362\u884c\u7b26\u53f7.\n<\/code><\/pre>\n<p>\u7f16\u8bd1\u65f6\u5b57\u7b26\u4e32\u8fde\u63a5\uff1a<\/p>\n<pre><code>foo = &quot;hello&quot; 'world'\nurllib.urlopen('http:\/\/' # protocol\n'localhost' # hostname\n':8000' # port\n'\/') # path\n<\/code><\/pre>\n<p>\u539f\u59cb\u5b57\u7b26\u4e32\uff1a<\/p>\n<pre><code># \u6b63\u5e38\u60c5\u51b5\u4e0b\u5728\u5b57\u7b26\u4e32\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u4e32(\\\u52a0\u4e00\u4e2a\u5b57\u7b26)\u8868\u793a\u7279\u6b8a\u542b\u4e49\uff0e\u662f\u4e0d\u53ef\u6253\u5370\u7684\uff0e\nprint('\\n')\n# \u5982\u679c\u9700\u8981\u8868\u793a\u6b63\u5e38\u542b\u4e49\u9700\u8981\u8f6c\u8bd1(\\\u7528\u6765\u8f6c\u610f)\uff0e\nprint('\\\\n') # \u9700\u8981\u8f6c\u8bd1\uff0e\n# \u4e5f\u53ef\u4ee5\u4f7f\u7528\u539f\u59cb\u5b57\u7b26\u4e32\u6765\u8868\u793a\u6b63\u5e38\u542b\u4e49\uff0er''\u548cR''\u90fd\u53ef\u4ee5\uff0e\nprint(r'\\n')\nopen(r'C:\\windows\\test.txt')\n<\/code><\/pre>\n<p>\u5b57\u7b26\u4e32\u7f16\u7801\u89e3\u7801:<\/p>\n<p>Unicode: Universal Multiple-Octet Coded Character Set. \u4f7f\u7528\u5341\u516d\u8fdb\u5236\u8868\u793a\uff0e\u52a0\u4e0a\u524d\u7f00U+<\/p>\n<p>ASCII: American Standard Code for Information<\/p>\n<p>UFT-8: Unicode Transformation Format<\/p>\n<p>python2\u56e0\u4e3a\u6bd4unicode\u51fa\u73b0\u8981\u65e9\uff0c\u6240\u4ee5python2\u9ed8\u8ba4\u4f7f\u7528\u7684\u662fASCII\u7f16\u7801\uff0e<\/p>\n<p>python3 \u9ed8\u8ba4\u4f7f\u7528utf-8\u7f16\u7801\u3002<\/p>\n<pre><code># \u83b7\u53d6\u9ed8\u8ba4\u7f16\u7801\nimport sys\nprint(sys.getdefaultencoding())\n\/\/ python2\na = u'\u6d4b\u8bd5'\ntype(a) # unicode\na # u'\\u6d4b\\u8bd5',\u3000\u5341\u516d\u8fdb\u5236\u8868\u793a\n\/\/ python2\n# str\u7c7b\u578b\nb = '\u6d4b\u8bd5'\ntype(b) # str\nb # \\xe6\\xb5\\x8b\\xe8\\xaf\\x95\n\/\/ python2\n# encode\u5c06unicode\u7c7b\u578b\u7f16\u7801\u6210str\u7c7b\u578b\u7528\u4e8e\u6570\u636e\u4f20\u8f93\uff0e\nencode([encoding[,errors]]) # \u7f16\u7801\nc = a.encode('uft-8')\ntype(c) # str\nc # \\xe6\\xb5\\x8b\\xe8\\xaf\\x95\n\/\/ python2\n# decode\u5c06str\u7c7b\u578b\u6839\u636e\u539f\u6765\u7684\u7f16\u7801\u7c7b\u578b\u89e3\u7801\u6210unicode\u7c7b\u578b\u8fdb\u884c\u9605\u8bfb\uff0e\ndecode([encoding[,errors]]) # \u89e3\u7801\nd = c.decode('utf-8') # \u53c2\u6570\u5fc5\u987b\u662f\u539f\u6765\u7684\u7f16\u7801\u7684\u7c7b\u578b\ntype(d) # unicode\nd # u'\\u6d4b\\u8bd5'\n\/\/ python2\n# python2\u9ed8\u8ba4ascii\u7f16\u7801\uff0c\u6240\u4ee5encode\u548cdecode\u9ed8\u8ba4\u90fd\u662fascii. \u4e0d\u80fd\u5904\u7406\u4e2d\u6587\nu'\u6d4b\u8bd5'.encode() # UnicodeEncodeError\n\/\/ python2\n# str+unicode, str\u4f1a\u9690\u5f0f\u7684\u8f6c\u6362\u6210unicode.\n'\u6d4b' + u'\u8bd5' -&gt; '\u6d4b'.decode() + u'\u8bd5' # \u56e0\u4e3adecode\u9ed8\u8ba4\u662fascii\u4e0d\u80fd\u89e3\u7801\u4e2d\u6587,UnicodeDecodeError\uff0e\n'\u6d4b'.decode('uft-8') + u'\u8bd5'\n\/\/ python2\n# \u5bf9\u975eunicode\u8fdb\u884cencode\u7f16\u7801\uff0c\u4f1a\u5148\u9690\u5f0f\u89e3\u7801\u6210unicode\u518d\u7f16\u7801\n'\u6d4b\u8bd5'.encode('utf-8') # UnicodeDecodeError, \u56e0\u4e3a'\u6d4b\u8bd5'.decode()\u9ed8\u8ba4\u7528ascii\u89e3\u7801\n'\u6d4b\u8bd5'.decode('utf-8').decode('utf-8')\n# python2\u7a0b\u5e8f\u4e2d\u51fa\u73b0\u5b57\u7b26\u4e32\u4e00\u5b9a\u52a0\u524d\u7f00u.\u8868\u793a\u6210unicode\u683c\u5f0f\nu'hello world'\n# \u4e0d\u8981\u7528str(), \u7528unicode().\n# \u53ea\u5728\u5199\u5165\u6587\u4ef6\uff0f\u6570\u636e\u5e93\uff0f\u7f51\u7edc\u65f6\u624d\u8c03\u7528\u7f16\u7801\u51fd\u6570encode().\n# \u53ea\u5728\u8bfb\u56de\u6570\u636e\u65f6\u624d\u8c03\u7528\u89e3\u7801\u51fd\u6570decode().\n# \u59cb\u7ec8\u4f7f\u7528utf-8\u7f16\u7801\uff0e\u5426\u5219\u5bb9\u6613\u51fa\u73b0\u4e71\u7801\uff0e\n\/\/ python3 \u9ed8\u8ba4\u7c7b\u578b\u975estr\uff0c\u800c\u662fbytes\u3002\nstr.encode() # str\u7c7b\u578b\u901a\u8fc7encode\u7f16\u7801\u6210types\u7c7b\u578b\nbytes.decode() # bytes\u7c7b\u578b\u901a\u8fc7decode\u89e3\u7801\u6210str\u7c7b\u578b\n<\/code><\/pre>\n<p>\u53ef\u8fed\u4ee3\u5bf9\u8c61\u8f6c\u6362\u6210\u5b57\u7b26\u4e32\uff1a<\/p>\n<pre><code>''.join(('a', 'b')) # \u53ef\u8fed\u4ee3\u5bf9\u8c61\u7684\u5143\u7d20\u9700\u8981\u662fstr\u7c7b\u578b.\n''.join(['a', 'b']) # \u53ef\u8fed\u4ee3\u5bf9\u8c61\u7684\u5143\u7d20\u9700\u8981\u662fstr\u7c7b\u578b.\n''.join({'a': 'b'}) # \u5b57\u5178\u8fed\u4ee3\u952e\uff0c\u53ef\u8fed\u4ee3\u5bf9\u8c61\u7684\u5143\u7d20\u9700\u8981\u662fstr\u7c7b\u578b.\n<\/code><\/pre>\n<h2 id=\"tuple\"><em>tuple<\/em><\/h2>\n<p>tuple\u7c7b\u578b\u662f\u4e0d\u53ef\u53d8\u7c7b\u578b(immutable),\u662f\u5bb9\u5668(container),\u662f\u5e8f\u5217(sequence)\u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee\uff0e<\/p>\n<p>\u5143\u7ec4\u662f\u4e0d\u53ef\u53d8\u7c7b\u578b\uff0c\u4e0d\u80fd\u5bf9\u5143\u7ec4\u7684\u5143\u7d20\u8fdb\u884c\u589e\u5220\u64cd\u4f5c\uff0e<\/p>\n<h2 id=\"list\"><em>list<\/em><\/h2>\n<p>list\u7c7b\u578b\u662f\u53ef\u53d8\u7c7b\u578b(immutable),\u662f\u5bb9\u5668(container),\u662f\u5e8f\u5217(sequence)\u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee\uff0e<\/p>\n<p>\u5217\u8868\u5143\u7d20\u589e\u5220\u4fee\u6539\uff1a<\/p>\n<pre><code># \u9664\u4e86\u4f7f\u7528\u5185\u7f6e\u65b9\u6cd5\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5e8f\u5217\u7684\u7d22\u5f15\uff0e\nlst[index] = value\ndel lst[index]\n<\/code><\/pre>\n<h3 id=\"list-comprehensions\u5217\u8868\u89e3\u6790\"><em>list comprehensions\u5217\u8868\u89e3\u6790<\/em><\/h3>\n<p>List Comprehensions\u5217\u8868\u89e3\u6790,\u6765\u81ea\u51fd\u6570\u5f0f\u7f16\u7a0b\u8bed\u8a00Haskell.<\/p>\n<p>\u5217\u8868\u89e3\u6790\u4f7f\u7528\u4e2d\u62ec\u53f7\uff0c\u5217\u8868\u89e3\u6790\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\u3002<\/p>\n<pre><code>lst = [expression for item in iterable]\n# \u5d4c\u5957if\nlst = [expression for item in iterable if condition]\n# \u5d4c\u5957for\nlst = [expression for item in iterable for item1 in iterable1]\n[x ** 2 for x in range(10)]\n\u7b49\u6548\u4e8e,python2\u7684\u5185\u7f6e\u51fd\u6570map(), filter()\u90fd\u662f\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u5e94\u7528\uff0e\nmap(lambda x: x**2, range(10))\n[(x+1, y+1) for x in range(10) for y in range(10)]\n<\/code><\/pre>\n<hr>\n<h2 id=\"range\"><em>range<\/em><\/h2>\n<p>\u7528\u4e8e\u751f\u6210\u6574\u6570\u5e8f\u5217\u7684\u5185\u5efa\u7c7b\u578b\uff0c\u8fd4\u56de\u5bf9\u8c61<\/p>\n<pre><code>range(stop)\nrange(start, stop)\nrange(start, stop, step)\n<\/code><\/pre>\n<h2 id=\"bytes\"><em>bytes<\/em><\/h2>\n<h2 id=\"bytearray\"><em>bytearray<\/em><\/h2>\n<h2 id=\"memoryview\"><em>memoryview<\/em><\/h2>\n<hr>\n<h2 id=\"dict\"><em>dict<\/em><\/h2>\n<p>dict\u7c7b\u578b\u662f\u53ef\u53d8\u7c7b\u578b(immutable),\u662f\u5bb9\u5668(container),\u662f\u6620\u5c04(mapping)\u7c7b\u578b,\u662f\u65e0\u5e8f\u7684,\u901a\u8fc7\u6620\u5c04\u8bbf\u95ee\uff0e<\/p>\n<p>\u5b57\u5178\u8fed\u4ee3\u952e\uff0c\u5b57\u5178\u7684\u952e\u5fc5\u987b\u662f\u53ef\u54c8\u5e0c\u7684\uff0c\u5b57\u5178\u7684\u952e\u5fc5\u987b\u662f\u4e0d\u53ef\u53d8\u7c7b\u578b\uff0e\u5217\u8868\/\u5b57\u5178\/\u53ef\u53d8\u96c6\u5408\u7b49\u4e0d\u53ef\u54c8\u5e0c\u5bf9\u8c61\u4e0d\u80fd\u7528\u4f5c\u5b57\u5178\u7684\u952e\uff0e<\/p>\n<p>\u6240\u6709\u4e0d\u53ef\u53d8\u7c7b\u578b\u90fd\u662f\u53ef\u54c8\u5e0c\u7684\uff0c\u90fd\u53ef\u4ee5\u4f5c\u4e3a\u5b57\u5178\u7684\u952e\uff0e<\/p>\n<p>\u53ef\u7528\u5185\u7f6e\u51fd\u6570hash()\u83b7\u53d6\u6216\u5224\u65ad\u662f\u5426\u80fd\u7528\u4f5c\u5b57\u5178\u7684\u952e\uff0e<\/p>\n<p>\u5b57\u5178\u7684\u952e\u5fc5\u987b\u662f\u552f\u4e00\u7684\uff0c\u4e0d\u80fd\u4e00\u4e2a\u952e\u5bf9\u5e94\u591a\u4e2a\u503c\uff0e\u6709\u8fd9\u79cd\u60c5\u51b5\u53d6\u6700\u540e\u4e00\u4e2a\u8d4b\u503c\uff0e<\/p>\n<p>\u5b57\u5178\u7684\u952e\u64cd\u4f5c\u7b26\uff1a<\/p>\n<pre><code># \u5b57\u5178\u901a\u8fc7\u952e\u64cd\u4f5c\u7b26\u6765\u8bfb\u53d6\u5143\u7d20\u7684\u503c\ndic['key']\n<\/code><\/pre>\n<p>\u952e\u6210\u5458\u64cd\u4f5c\u7b26:<\/p>\n<pre><code># \u53d6\u4ee3has_key()\u548ckeys()\u5185\u7f6e\u65b9\u6cd5\n'key' in dic # \u63a8\u8350\u7528 'key' in dic \u5224\u65ad\u952e\u662f\u5426\u5b58\u5728\n'key' not in dic\n# Python3\u4e2ddict.keys()\u3001dict.values()\u3001dict.items()\u8fd4\u56de\u7684\u662f\u89c6\u56fe\u5bf9\u8c61\uff08\u53ef\u8fed\u4ee3\uff09\uff0c\u5982\u9700\u5217\u8868\u53ef\u7528list(dict.keys())\u7b49\u3002\n<\/code><\/pre>\n<p>\u5b57\u5178\u5143\u7d20\u589e\u5220\u4fee\u6539\uff1a<\/p>\n<pre><code>dic['key'] = 'value'\ndel dic['key']\n<\/code><\/pre>\n<p>\u5b57\u5178\u5408\u5e76\uff1a<\/p>\n<pre><code>d1 = {&quot;a&quot;: 1}\nd2 = {&quot;b&quot;: 2}\nd1 | d2\n&gt; {'a': 1, 'b': 2}\n<\/code><\/pre>\n<h3 id=\"dict-comprehensions\">dict comprehensions<\/h3>\n<p>\u5b57\u5178\u89e3\u6790\u3002<\/p>\n<pre><code>{key: value for item in iterable if condition}\nmodified = {\nk: (expected[k], actual[k])\nfor k in expected\nif k in actual and expected[k] != actual[k]\n}\n<\/code><\/pre>\n<h2 id=\"sets\u96c6\u5408\"><em>Sets\u96c6\u5408<\/em><\/h2>\n<p>\u96c6\u5408\u662f\u4e00\u7ec4\u65e0\u5e8f\u6392\u5217\u7684\u503c\uff0c\u4e0d\u80fd\u8fdb\u884c\u7d22\u5f15\u548c\u5207\u7247\u64cd\u4f5c\uff0c\u4e5f\u4e0d\u80fd\u8fdb\u884c\u952e\u64cd\u4f5c\uff0c\u53ea\u80fd\u901a\u8fc7for\u5faa\u73af\u8fed\u4ee3\u96c6\u5408\u5143\u7d20\uff0e<\/p>\n<p>\u96c6\u5408\u5206\u4e3a\u53ef\u53d8\u96c6\u5408\u548c\u4e0d\u53ef\u53d8\u96c6\u5408.<\/p>\n<p>\u96c6\u5408\u8fd0\u7b97\u7b26\uff1a<\/p>\n<pre><code>'element' in st \u662f\u6210\u5458\n'element' not in st \u4e0d\u662f\u6210\u5458\n== \u7b49\u4e8e\n!= \u4e0d\u7b49\u4e8e\n&lt; \u4e25\u683c\u5b50\u96c6\n&lt;= \u975e\u4e25\u683c\u5b50\u96c6, \u7b49\u6548\u4e8eissubset()\n&gt; \u4e25\u683c\u8d85\u96c6\n&gt;= \u975e\u4e25\u683c\u8d85\u96c6, \u7b49\u6548\u4e8eissuperset()\n| \u8054\u5408\/\u5408\u5e76, OR\u64cd\u4f5c\uff0c\u7b49\u6548\u4e8eunion()\u5185\u7f6e\u65b9\u6cd5\n&amp; \u4ea4\u96c6, AND\u64cd\u4f5c\uff0c\u7b49\u6548\u4e8eintersection()\u5185\u7f6e\u65b9\u6cd5\n- \u5dee\u8865\u6216\u76f8\u5bf9\u8865\u96c6, \u7b49\u6548\u4e8edifference()\u5185\u7f6e\u65b9\u6cd5\n^ \u5bf9\u79f0\u5dee\u5206\u6216\u5f02\u6216, XOR\u64cd\u4f5c\uff0c\u7b49\u6548\u4e8esymmetric_difference()\u5185\u7f6e\u65b9\u6cd5\n\u4ec5\u7528\u4e8e\u53ef\u53d8\u96c6\u5408\u7684\u8fd0\u7b97\u7b26\uff1a\n|= \u7b49\u6548\u4e8eupdate()\u5185\u7f6e\u65b9\u6cd5\n&amp;= \u7b49\u6548\u4e8eintersection_update()\u5185\u7f6e\u65b9\u6cd5\n-= \u7b49\u6548\u4e8edifference_update()\u5185\u7f6e\u65b9\u6cd5\n^= \u7b49\u6548\u4e8esymmetric_difference_update()\u5185\u7f6e\u65b9\u6cd5\n<\/code><\/pre>\n<p>\u96c6\u5408\u8fd0\u7b97\u8fd4\u56de\u7ed3\u679c\u7684\u7c7b\u578b\u4e0e\u5de6\u64cd\u4f5c\u6570\u7684\u7c7b\u578b\u76f8\u540c\uff0c\u5de6\u8fb9\u662f\u53ef\u53d8\u96c6\u5408\uff0c\u7ed3\u679c\u5c31\u662f\u53ef\u53d8\u96c6\u5408\uff0c\u5426\u5219\u662f\u4e0d\u53ef\u53d8\u96c6\u5408\uff0e<\/p>\n<h3 id=\"frozenset\">frozenset<\/h3>\n<p>frozenset\u7c7b\u578b\u662f\u4e0d\u53ef\u53d8\u7c7b\u578b(immutable),\u662f\u5bb9\u5668(container).<\/p>\n<h3 id=\"set\">set<\/h3>\n<p>set\u7c7b\u578b\u662f\u53ef\u53d8\u7c7b\u578b(mutable)\uff0c\u662f\u5bb9\u5668(container).<\/p>\n<h3 id=\"set-comprehensions\">set comprehensions<\/h3>\n<p>\u96c6\u5408\u89e3\u6790<\/p>\n<pre><code>{expression for item in iterable if condition}\n{x for x in range(10) if x % 2 == 0}\n\u7b49\u6548\u4e8e\nset(filter(lambda x: x % 2 == 0, range(10)))\n<\/code><\/pre>\n<hr>\n<h1 id=\"python\u63a7\u5236\u6d41\"><strong>python\u63a7\u5236\u6d41<\/strong><\/h1>\n<p>continue\u8bed\u53e5:\u8868\u793a\u7acb\u5373\u7ec8\u6b62\u672c\u6b21\u5faa\u73af\uff0c\u542f\u52a8\u5faa\u73af\u7684\u4e0b\u4e00\u6b21\u8fed\u4ee3\uff0e<\/p>\n<p>break\u8bed\u53e5\uff1a\u8868\u793a\u7ed3\u675f\u5f53\u524d\u5faa\u73af\u5757\uff0c\u8df3\u8f6c\u5230\u540e\u9762\u7684\u8bed\u53e5\uff0e<\/p>\n<p>pass\u8bed\u53e5\uff1a \u8868\u793a\u4e0d\u505a\u4efb\u4f55\u4e8b\u60c5\uff0cNOP.<\/p>\n<h2 id=\"if\u6761\u4ef6\u8bed\u53e5\"><em>if\u6761\u4ef6\u8bed\u53e5<\/em><\/h2>\n<pre><code>if condition:\nexpression\nelif condition:\nexpression\nelse:\nexpression\n<\/code><\/pre>\n<p>python\u4e2d\u7684\u4e09\u76ee\u8fd0\u7b97\uff1a<\/p>\n<pre><code>X if C else Y\n\u7b49\u6548\u4e8e\nif C:\nX\nelse:\nY\n# \u4e09\u76ee\u8fd0\u7b97\u7b26\u9ad8\u4e8e\u8d4b\u503c\u8fd0\u7b97\u7b26\uff0e\na = b if c else d\n# \u7b49\u6548\u4e8e\na = (b if c else d)\n<\/code><\/pre>\n<p>python\u6ca1\u6709switch\uff0c\u53ef\u4ee5\u7528if\u5b9e\u73b0:<\/p>\n<pre><code>if var == &quot;a&quot;:\nreturn &quot;A&quot;\nelif var == &quot;b&quot;:\nreturn &quot;B&quot;\nelse:\nreturn &quot;unknown&quot;\n<\/code><\/pre>\n<p>3.10+\u5f15\u5165match-case\u3002<\/p>\n<h2 id=\"while\u5faa\u73af\u8bed\u53e5\"><em>while\u5faa\u73af\u8bed\u53e5<\/em><\/h2>\n<pre><code>while condition:\nexpression\n# while\u6267\u884c\u5b8c\u4f1a\u6267\u884celse(\u5305\u62ecwhile\u4e0d\u6267\u884c)\uff0cbreak\u4f1a\u8df3\u8fc7else\uff0e\nwhile condition:\nexpression\nelse:\nexpression\n<\/code><\/pre>\n<h2 id=\"for\u5faa\u73af\u8bed\u53e5\"><em>for\u5faa\u73af\u8bed\u53e5<\/em><\/h2>\n<p>for\u5faa\u73af\u53ef\u4ee5\u7528\u4e8e\u904d\u5386\u5e8f\u5217\uff0c\u5b57\u5178\u7684\u952e \u548c \u6587\u4ef6\u7684\u884c\uff0c\u96c6\u5408\uff0c\u5217\u8868\u89e3\u6790\uff0c\u751f\u6210\u5668\u8868\u8fbe\u5f0f.<\/p>\n<p>for\u5faa\u73af\u4f1a\u81ea\u52a8\u8c03\u7528\u8fed\u4ee3\u5668\u7684next()\u65b9\u6cd5\uff0c\u6355\u83b7StopIteration\u5f02\u5e38\u7ed3\u675f\u5faa\u73af\uff0e<\/p>\n<p>\u7528for\u8fed\u4ee3\u53ef\u53d8\u5bf9\u8c61\u7684\u65f6\u5019\uff0c\u4e0d\u5e94\u8be5\u6539\u53d8\u53ef\u53d8\u5bf9\u8c61\u7684\u5143\u7d20\u7684\u503c\uff0e<\/p>\n<pre><code>for condition:\nexpression\n# for\u6267\u884c\u5b8c\u6210\u4f1a\u6267\u884celse, break\u4f1a\u8df3\u8fc7else.\nfor condition:\nexpression\nelse:\nexpression\n# \u5b57\u5178\u6709\u4e24\u79cd\u5199\u6cd5\nfor loop in dic.keys()\n\u7b49\u6548\u4e8e\nfor loop in dic\n# \u6587\u4ef6\u6709\u4e24\u79cd\u5199\u6cd5\nfor loop in open('file', 'r').readlines():\n\u7b49\u6548\u4e8e\nfor loop in open('file','r'):\n<\/code><\/pre>\n<h2 id=\"iterator\u8fed\u4ee3\u5668-\u7c7b\u578b\"><em>iterator\u8fed\u4ee3\u5668 \u7c7b\u578b<\/em><\/h2>\n<p>Iterable\u53ef\u8fed\u4ee3\u5bf9\u8c61: \u80fd\u76f4\u63a5\u7528\u4e8efor\u5faa\u73af\u7684\u5bf9\u8c61\u4e3a\u53ef\u8fed\u4ee3\u5bf9\u8c61Iterable. \u53ea\u9700\u8981\u5b9e\u73b0__iter__()\u65b9\u6cd5\u5373\u53ef\u3002<\/p>\n<p>Iterator\u8fed\u4ee3\u5668: \u80fd\u88abnext(g)\u5185\u7f6e\u51fd\u6570\u8c03\u7528\u5e76\u4e0d\u65ad\u8fd4\u56de\u4e0b\u4e00\u4e2a\u503c\u7684\u5bf9\u8c61\u4e3a\u8fed\u4ee3\u5668Iterator,\u8fed\u4ee3\u5b8c\u6210\u540e\u629b\u51faStopIteration\u5f02\u5e38, \u4e5f\u80fd\u7528for\u5faa\u73af\uff0c\u8981\u540c\u65f6\u5b9e\u73b0__iter__()\u548c__next__()<\/p>\n<p>enumerate\u548creversed\u5185\u7f6e\u7c7b\u7c7b\u578b\u7684\u5de5\u5382\u51fd\u6570\u8fd4\u56de\u7684\u90fd\u662f\u8fed\u4ee3\u5668\u7c7b\u578b\uff0e<\/p>\n<p>\u521b\u5efa\u8fed\u4ee3\u5668\u76843\u79cd\u65b9\u6cd5\uff1a<\/p>\n<pre><code># \u901a\u8fc7\u5185\u5efa\u51fd\u6570iter()\niter()\n# \u901a\u8fc7\u5de5\u5382\u51fd\u6570\nenumerate() # \u8fed\u4ee3\u65f6\u540c\u65f6\u83b7\u53d6\u5143\u7d20\u503c\u548c\u7d22\u5f15\nreversed() # \u53cd\u8f6c\u5e8f\u5217\u5bf9\u8c61\n# \u81ea\u5b9a\u4e49\u7c7b\uff0c\u9700\u8981\u5b9e\u73b0 __iter__() \u548c__next__() \u4e24\u4e2a\u65b9\u6cd5(python3)\nclass TestIterator(object):\ndef __init__(self, data):\nself.data = data\ndef __iter__(self):\nfor item in self.data\nyield item\ndef __next__(self):\nif condition:\n...\nelse:\nraise StopIteration()\ni = TestIterator()\ntype(i)\n&gt; iterator\n<\/code><\/pre>\n<h2 id=\"generator\u751f\u6210\u5668\u7c7b\u578b\"><em>generator\u751f\u6210\u5668\u7c7b\u578b<\/em><\/h2>\n<p>\u751f\u6210\u5668\u5c31\u662f\u4e00\u4e2a\u8fed\u4ee3\u5668\u5bf9\u8c61\uff0c\u5728\u6bcf\u6b21\u8c03\u7528next()\u65b9\u6cd5\u65f6\u8fd4\u56de\u4e00\u4e2a\u503c\uff0e\u76f4\u5230\u629b\u51faStopIteration\u5f02\u5e38, \u751f\u6210\u5668\u901a\u5e38\u7528\u4e8e\u8fed\u4ee3\u4e00\u4e2a\u5de8\u5927\u7684\u6570\u636e\u96c6\uff0e<\/p>\n<p>generator\u7c7b\u7c7b\u578b,\u662f\u4e00\u4e2a\u8fed\u4ee3\u5668\uff0c\u53ef\u4ee5\u7528for\u5faa\u73af\u8fed\u4ee3:<\/p>\n<pre><code>generator.close() # \u5728\u751f\u6210\u5668\u5185\u90e8\u629b\u51faGeneratorExit\u5f02\u5e38\u8981\u6c42\u751f\u6210\u5668\u9000\u51fa\uff0e\ngenerator.send(arg) # \u5c06\u503c\u56de\u9001\u7ed9\u751f\u6210\u5668\uff0e\ngenerator.throw(typ[,val[,tb]]) # \u5728\u751f\u6210\u5668\u629b\u51fa\u5f02\u5e38\n<\/code><\/pre>\n<p>\u521b\u5efa\u751f\u6210\u5668\u7684\u4e24\u79cd\u65b9\u6cd5\uff1a<\/p>\n<ol>\n<li>\n<p>\u4f7f\u7528\u5217\u8868\u89e3\u6790\u7684\u53d8\u79cd<\/p>\n<p>g = (expression for item1 in iterable1 if condition1)\ntype(g)<\/p>\n<blockquote>\n<p>generator<\/p>\n<\/blockquote>\n<p>next(g)<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528yield\u5173\u952e\u5b57<\/p>\n<\/li>\n<\/ol>\n<p>\u6709yield\u7684\u51fd\u6570\u8fd4\u56de\u7684\u5c31\u662f\u4e00\u4e2a\u751f\u6210\u5668\uff0e<\/p>\n<p>yield\u51fd\u6570\u80fd\u8bb0\u4f4f\u4e0a\u4e00\u6b21\u8fd4\u56de\u65f6\u5728\u51fd\u6570\u4f53\u4e2d\u7684\u4f4d\u7f6e\uff0c\u8fed\u4ee3\u751f\u6210\u5668\u4f1a\u8df3\u8f6c\u81f3\u8be5\u51fd\u6570\u4e2d\u95f4\uff0c\u800c\u4e14\u4e0a\u6b21\u8c03\u7528\u7684\u6240\u6709\u5c40\u90e8\u53d8\u91cf\u4fdd\u6301\u4e0d\u53d8\uff0e<\/p>\n<p>yield\u51fd\u6570\u548c\u666e\u901a\u51fd\u6570\u6267\u884c\u987a\u5e8f\u4e0d\u4e00\u6837\uff0c\u666e\u901a\u51fd\u6570\u987a\u5e8f\u6267\u884c\uff0c\u9047\u5230return\u6216\u6700\u540e\u4e00\u884c\u8bed\u53e5\u8fd4\u56de\uff0eyield\u51fd\u6570\u9047\u5230yield\u8bed\u53e5\u8fd4\u56de\uff0c\u4e0b\u6b21\u6267\u884c\u4ece\u4e0a\u6b21\u8fd4\u56de\u7684yield\u8bed\u53e5\u5f00\u59cb\u7ee7\u7eed\u6267\u884c\uff0e\u9047\u5230return\u8bed\u53e5\u629b\u51faStopIteration\u5f02\u5e38\uff0e<\/p>\n<pre><code>def gena():\nyield 'first'\nyield 'second'\ng = gena()\ntype(g)\n&gt; generator\nnext(g) # first\nnext(g) # second\nnext(g) # StopIteration\n<\/code><\/pre>\n<h3 id=\"generator-expressions\u751f\u6210\u5668\u8868\u8fbe\u5f0f\"><em>generator expressions\u751f\u6210\u5668\u8868\u8fbe\u5f0f<\/em><\/h3>\n<p>Generator Expressions\u751f\u6210\u5668\u8868\u8fbe\u5f0f, \u662f\u5217\u8868\u89e3\u6790\u7684\u4e00\u4e2a\u6269\u5c55\uff0e<\/p>\n<p>\u5217\u8868\u89e3\u6790\u7684\u7f3a\u70b9\u5c31\u662f\u8981\u8fed\u4ee3\u6574\u4e2a\u5bf9\u8c61\u7528\u6765\u521b\u5efa\u5217\u8868\uff0c\u5bf9\u5927\u7684\u5bf9\u8c61\u6765\u8bf4\u6027\u80fd\u5dee.<\/p>\n<p>\u751f\u6210\u5668\u8868\u8fbe\u5f0f\u5c31\u662f\u7ed3\u5408\u751f\u6210\u5668\u548c\u5217\u8868\u89e3\u6790\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0e<\/p>\n<p>\u751f\u6210\u5668\u8868\u8fbe\u5f0f\u4e0d\u5fc5\u521b\u5efa\u5b8c\u6574\u7684\u5217\u8868\uff0c\u800c\u662f\u4e00\u8fb9\u5faa\u73af\u4e00\u8fb9\u8ba1\u7b97\uff0c\u8fd4\u56de\u4e00\u4e2a\u751f\u6210\u5668\u5bf9\u8c61\u3002<\/p>\n<pre><code>g = (expression for item1 in iterable1 if condition1)\n<\/code><\/pre>\n<hr>\n<h1 id=\"python\u6587\u4ef6\u548c\u8f93\u5165\u8f93\u51fa\"><strong>python\u6587\u4ef6\u548c\u8f93\u5165\u8f93\u51fa<\/strong><\/h1>\n<p>python2\u4f7f\u7528open()\u5185\u7f6e\u51fd\u6570\u6253\u5f00\u6587\u4ef6\uff0c\u8fd4\u56defile\u7c7b\u7c7b\u578b\u7684\u5bf9\u8c61\uff0c\u51fa\u9519\u8fd4\u56deIOError\u5f02\u5e38.<\/p>\n<p>file\u7c7b\u7c7b\u578b\u5bf9\u8c61\u662f\u8fed\u4ee3\u5668\uff0c\u540c\u65f6\u4e5f\u662f\u4e0a\u4e0b\u6587\u7ba1\u7406\u5668\uff0e<\/p>\n<p>python3\u5e9f\u5f03\u4e86file\u7c7b\u7c7b\u578b\uff0copen()\u5185\u7f6e\u51fd\u6570\u8fd4\u56deIO\u6d41\uff0e<\/p>\n<pre><code># python2\nopen(name[, mode='r'[, buffering=-1]])\nmode\nr: \u8bfb\uff0c\u6587\u4ef6\u5fc5\u987b\u5b58\u5728\nw: \u5199\uff0c\u6587\u4ef6\u4e0d\u5b58\u5728\u5219\u521b\u5efa\uff0c\u5426\u5219\u5148\u6e05\u7a7a\u6587\u4ef6\u518d\u5199\u5165\uff0e\na: \u8ffd\u52a0\uff0c\u6587\u4ef6\u5b58\u5728\u5c31\u8ffd\u52a0\u5230\u6587\u4ef6\u7ed3\u5c3e,\u5426\u5219\u5c31\u521b\u5efa\uff0e\nt: text\u6a21\u5f0f\uff0c\u8fd9\u4e2a\u662f\u9ed8\u8ba4\u6a21\u5f0f\uff0e\u4e0d\u7528\u6307\u5b9a\uff0e\nrb\/wb\/ab: \u4e8c\u8fdb\u5236\u8bfb\u5199\uff0e\nr+\/w+\/a+: \u4ee5\u8bfb\u5199\u6a21\u5f0f\u6253\u5f00\u6587\u672c\u6587\u4ef6\uff0e\nrb+\/wb+\/ab+: \u4ee5\u8bfb\u5199\u6a21\u5f0f\u6253\u5f00\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0e\nU: \u63d0\u4f9b\u901a\u7528\u6362\u884c\u7b26\u652f\u6301\uff0c\u6587\u4ef6\u5fc5\u987b\u5b58\u5728\nbuffering\n0: \u4e0d\u7f13\u51b2\n1: \u53ea\u7f13\u51b2\u4e00\u884c\u6570\u636e\n&lt;0: \u4f7f\u7528\u7cfb\u7edf\u9ed8\u8ba4\u7f13\u51b2\u673a\u5236\n&gt;1: \u4f7f\u7528\u7ed9\u5b9a\u503c\u4f5c\u4e3a\u7f13\u51b2\u533a\u5927\u5c0f\n<\/code><\/pre>\n<p>\u901a\u7528\u6362\u884c\u7b26UNS:<\/p>\n<p>Universal Newline Support.<\/p>\n<p>\u5982\u679c\u662f\u4e8c\u8fdb\u5236\u6587\u4ef6\u8bfb\u5199rb\/wb\/ab\uff0c\u4e0d\u4f1a\u6709\u6362\u884c\u7b26\u7684\u95ee\u9898\uff0c\u5982\u679c\u662f\u6587\u672c\u6587\u4ef6\u5efa\u8bae\u7528rU\/wU\/aU\u6765\u8bfb\u5199.<\/p>\n<pre><code># UNS\u4f1a\u628a\n\\r\\n\n\\r\n\\n\n# \u90fd\u88ab\u66ff\u6362\u4e3a\n\\n\n<\/code><\/pre>\n<p>\u6587\u4ef6\u53ef\u4ee5\u4f7f\u7528with\u4e0a\u4e0b\u6587\u7ba1\u7406\u5668\uff0c\u5e76\u4e14\u8fed\u4ee3\u6587\u4ef6\u7684\u884c:<\/p>\n<pre><code>with open('file', 'rU') as f:\nfor line in f:\n...\n<\/code><\/pre>\n<p>\u6807\u51c6\u6587\u4ef6:<\/p>\n<p>\u7cfb\u7edf\u9ed8\u8ba4\u7684\u4e09\u4e2a\u6807\u51c6\u6587\u4ef6: sys.stdin, sys.stdout, sys.stderr.<\/p>\n<pre><code># python2\u7684\u5173\u952e\u5b57print\u4f1a\u628a\u8bed\u53e5\u6253\u5370\u5230sys.stdout,\u5e76\u9ed8\u8ba4\u5728\u8bed\u53e5\u7ed3\u5c3e\u52a0\u6362\u884c\u7b26.\nprint(expression)\nprint(expression, end='') # \u53ef\u4ee5\u907f\u514d\u9ed8\u8ba4\u52a0\u6362\u884c\u7b26\n# \u5185\u7f6e\u51fd\u6570input()\u4f1a\u4ecesys.stdin\u63a5\u53d7\u8f93\u5165\na = input()\n<\/code><\/pre>\n<hr>\n<h1 id=\"python\u9519\u8bef\u548c\u5f02\u5e38\"><strong>python\u9519\u8bef\u548c\u5f02\u5e38<\/strong><\/h1>\n<p>\u53c2\u8003\u5185\u7f6e\u7684\u9519\u8bef\u548c\u5f02\u5e38.<\/p>\n<p>BaseException\u662f\u6240\u6709\u5f02\u5e38\u7684\u57fa\u7c7b\uff0e Exception\u662f\u5e38\u89c4\u9519\u8bef\u7684\u57fa\u7c7b.<\/p>\n<p>\u9519\u8bef\u548c\u5f02\u5e38\u7684\u68c0\u6d4b\u548c\u5904\u7406\uff1a<\/p>\n<pre><code>try:\ntry_suite\nexcept Exception0[ as reason]: # reason\u53ef\u4ee5\u7528\u4e8e\u5728except_suite\u4e2d\u6253\u5370\u5177\u4f53\u7684\u5f02\u5e38\u4fe1\u606f\uff0creason\u662f\u4e00\u4e2aException0\u7c7b\u578b\u7684\u5b9e\u4f8b\uff0e\nexcept_suite\nexcept Exception1[ as reason]: # \u53ef\u4ee5\u6709\u591a\u4e2aexcept\u7528\u6765\u6355\u83b7\u4e0d\u540c\u7684\u5f02\u5e38\uff0c\u4f46\u662f\u53ea\u6709\u4e00\u4e2aexcept\u4f1a\u88ab\u6267\u884c.\nexcept_suite\nexcept (Exception2, Exception3)[ as reason]: # \u4e5f\u53ef\u4ee5\u5728\u4e00\u4e2aexcept\u4e2d\u540c\u65f6\u68c0\u6d4b\u591a\u4e2a\u5f02\u5e38\uff0e\u653e\u5165\u4e00\u4e2atuple\u4e2d. reason\u662f\u4e00\u4e2a\u5b9e\u4f8b\u7684\u5143\u7ec4\uff0e\nexcept_suite\nexcept Exception[, reason]: # \u53ef\u4ee5\u7528Exception\u6765\u6355\u83b7\u6240\u6709\u5f02\u5e38\uff0c\u800c\u4e0d\u7528\u533a\u5206\u5177\u4f53\u7684\u5f02\u5e38\uff0e\u4e0d\u63a8\u8350\u7528\u9017\u53f7\uff0c\u5e94\u8be5\u7528as\u4ee3\u66ff\uff0e\nexcept_suite\n[Deprecated] except: # \u4e0d\u63a8\u8350\u6b64\u7528\u6cd5\uff0c\u548c\u4e0a\u9762\u4e00\u4e2a\u7b49\u6548\nexcept_suite\n...\nelse: # \u53ef\u9009\uff0c \u6ca1\u6709\u5f02\u5e38\u89e6\u53d1except\u65f6\u8fd0\u884celse,\u3000except\u548celse\u53ea\u80fd\u8fd0\u884c\u4e00\u4e2a\uff0e\nexpression\nfinally: # \u53ef\u9009\uff0c\u65e0\u8bba\u662f\u5426\u6355\u6349\u5230\u5f02\u5e38\u90fd\u4f1a\u6267\u884c\u7684\uff0e\nexpression\n# \u4e5f\u53ef\u4ee5\u4e0d\u5bf9\u5f02\u5e38\u5904\u7406\ntry:\ntry_suite\nfinally:\nfinally_suite\n# \u5f02\u5e38\u7684\u53c2\u6570\nreason.__clas__.__name__ # \u5c31\u662f\u5f02\u5e38\u7c7b\u7684\u540d\u5b57\nprint(reason) # \u6253\u5370\u5f02\u5e38\u53c2\u6570\uff0e\n<\/code><\/pre>\n<h2 id=\"raise\u89e6\u53d1\u5f02\u5e38\"><em>raise\u89e6\u53d1\u5f02\u5e38<\/em><\/h2>\n<p>\u9664\u4e86\u4e0a\u9762\u6355\u83b7\u89e3\u91ca\u5668\u89e6\u53d1\u7684\u5f02\u5e38\uff0c\u7528\u6237\u8fd8\u53ef\u4ee5\u7528raise\u81ea\u5df1\u89e6\u53d1\u5f02\u5e38:<\/p>\n<pre><code>raise [SomeException [, args [, traceback]]]\n<\/code><\/pre>\n<p>SomeException\u53ef\u4ee5\u662f\u5b57\u7b26\u4e32\uff0c\u5185\u7f6e\u5f02\u5e38\uff0c\u7b2c\u4e09\u65b9\u5e93\u5f02\u5e38\u7c7b\uff0c\u81ea\u5b9a\u4e49\u5f02\u5e38\u7c7b, \u6216\u5b9e\u4f8b.<\/p>\n<pre><code>raise ExceptionClass[, args[, traceback]] # \u7c7b\nraise ExceptionClass(arguments)[, args[, traceback]] # \u5b9e\u4f8b\nraise ExceptionClass, instance # [TODO]\nraise instance # \u89e6\u53d1\u5b9e\u4f8b\u5f02\u5e38, raise reason \u5c31\u662f\u8dd1\u51fa\u4e00\u4e2aExceptionClass\u7c7b\u578b\u7684instance.\nraise string # \u89e6\u53d1\u5b57\u7b26\u4e32\u5f02\u5e38\nraise # \u91cd\u65b0\u89e6\u53d1\u524d\u4e00\u4e2a\u5f02\u5e38\uff0c\u5982\u679c\u4e4b\u524d\u6ca1\u6709\u5f02\u5e38\u89e6\u53d1TypeError.\n<\/code><\/pre>\n<h2 id=\"\u81ea\u5b9a\u4e49\u5f02\u5e38\u548c\u9519\u8bef\"><em>\u81ea\u5b9a\u4e49\u5f02\u5e38\u548c\u9519\u8bef<\/em><\/h2>\n<p>\u81ea\u5b9a\u4e49\u5f02\u5e38\u9700\u8981\u7ee7\u627f\u4e00\u4e2a\u6807\u51c6\u5f02\u5e38\u6216\u8005\u7b2c\u4e09\u65b9\u5e93\u7684\u5f02\u5e38\u6765\u5b9e\u73b0\u4e00\u4e2a\u7c7b\uff0e<\/p>\n<p>\u901a\u8fc7raise\u6765\u89e6\u53d1\u81ea\u5b9a\u4e49\u7684\u5f02\u5e38\uff0e<\/p>\n<pre><code>class MyError(Exception\/StandardError\/Warning):\ndef __init__(self, msg):\nsuper(...).__init__(self, ...)\n...\n...\nraise MyError, args\n<\/code><\/pre>\n<h2 id=\"assert\u65ad\u8a00\"><em>assert\u65ad\u8a00<\/em><\/h2>\n<p>\u65ad\u8a00\u8bed\u53e5\u7b49\u6548assert\u8868\u8fbe\u5f0f, \u5982\u679c\u65ad\u8a00\u6210\u529f\u4e0d\u91c7\u53d6\u4efb\u4f55\u63aa\u65bd\uff0c\u5426\u5219\u89e6\u53d1AssertionError\u5f02\u5e38\uff0e<\/p>\n<pre><code>assert expression[, arguments]\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u63d0\u4f9b\u4e00\u4e2a\u5f02\u5e38\u53c2\u6570\u548c\u6355\u83b7AssertionError\u5f02\u5e38:<\/p>\n<pre><code>try:\nassert expression, &quot;If raise AssertionError, print this message.&quot;\nexcept AssertionError as e:\nprint('%s: %s' % (e.__class__.__name__, e))\n<\/code><\/pre>\n<h2 id=\"with\u4e0a\u4e0b\u6587\u7ba1\u7406\"><em>with\u4e0a\u4e0b\u6587\u7ba1\u7406<\/em><\/h2>\n<p>CMP: context management protocol.<\/p>\n<p>with\u4e0a\u4e0b\u6587\u7ba1\u7406\u4ec5\u7528\u4e8e\u652f\u6301\u4e0a\u4e0b\u6587\u7ba1\u7406\u534f\u8bae(CMP)\u7684\u5bf9\u8c61\uff0e<\/p>\n<p>\u901a\u5e38\u7528\u4e8e\u6253\u5f00\u6587\u4ef6\u3001\u7f51\u7edc\u8fde\u63a5\u3001\u6570\u636e\u5e93\u8fde\u63a5\u3001\u9501\u7b49\u9700\u8981\u663e\u5f0f\u5173\u95ed\u6216\u91ca\u653e\u8d44\u6e90\u7684\u573a\u666f\u3002<\/p>\n<pre><code>with context_expr [as var]:\nwith_suite\n<\/code><\/pre>\n<p>with\u8bed\u53e5\u6267\u884c\u65f6\u5c31\u6267\u884c\u4e0a\u4e0b\u6587\u7b26\u53f7\uff08with\u548cas\u4e4b\u95f4\u7684\u5185\u5bb9\uff09\u6765\u83b7\u5f97\u4e00\u4e2a\u4e0a\u4e0b\u6587\u7ba1\u7406\u5668\uff0e<\/p>\n<p>\u4e0a\u4e0b\u6587\u7ba1\u7406\u5668\u8c03\u7528__context__()\u65b9\u6cd5\u6765\u8fd4\u56de\u4e00\u4e2a\u4e0a\u4e0b\u6587\u5bf9\u8c61\uff0e<\/p>\n<p>\u4e0a\u4e0b\u6587\u5bf9\u8c61\u4f1a\u8c03\u7528__enter_()\u65b9\u6cd5\u5b8c\u6210with\u8bed\u53e5\u5757\u6267\u884c\u524d\u7684\u51c6\u5907\u5de5\u4f5c\uff0e\u8fd4\u56de\u503c\u8d4b\u7ed9as\u540e\u9762\u7684var\u53d8\u91cf\uff0e<\/p>\n<p>with\u8bed\u53e5\u5757\u6267\u884c\u5b8c\u6bd5\u540e\u8c03\u7528__exit__()\u65b9\u6cd5\uff0c<strong>exit<\/strong>()\u6709\u4e09\u4e2a\u53c2\u6570\uff0c\u5982\u679c\u6ca1\u6709\u5f02\u5e38\u90fd\u662fNone,\u5426\u5219\u662fsys.exc_info()\u7684\u4e09\u4e2a\u8fd4\u56de\u503c\uff0e<\/p>\n<p>\u81ea\u5b9a\u4e49\u4e0a\u4e0b\u6587\u7ba1\u7406\u5668:<\/p>\n<pre><code>class CMPTest(object):\ndef __enter__(self):\n...\nreturn self\ndef __exit__(self, type, value, traceback):\n...\n<\/code><\/pre>\n<p>\u7236\u7c7b\u5b9e\u73b0\u4e86\u4e0a\u4e0b\u6587\u7ba1\u7406\u534f\u8bae\uff0c\u5b50\u7c7b\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528with.<\/p>\n<hr>\n<h1 id=\"\u51fd\u6570function\"><strong>\u51fd\u6570function<\/strong><\/h1>\n<p>\u5b9a\u4e49\/\u7533\u660e\u4e00\u4e2a\u51fd\u6570:<\/p>\n<p>python\u5bf9\u51fd\u6570\u7684\u7533\u660e\u548c\u5b9a\u4e49\u662f\u4e00\u8d77\u7684\uff0e<\/p>\n<p>\u51fd\u6570\u5fc5\u987b\u5148\u5b9a\u4e49\/\u7533\u660e\u624d\u80fd\u5f15\u7528\/\u8c03\u7528.<\/p>\n<p>\u901a\u8fc7\u5173\u952e\u5b57def\u6765\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570.<\/p>\n<p>def function_name(arguments)\nexpression<\/p>\n<p>\u51fd\u6570\u5f15\u7528\uff1a<\/p>\n<p>\u5f15\u7528\u4e00\u4e2a\u51fd\u6570\u540d\u5e76\u4e0d\u4f1a\u6267\u884c\u51fd\u6570\u5185\u5bb9\uff0e<\/p>\n<pre><code>function_copy = function_name\n# \u53ef\u4ee5\u5c06\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u4f20\u7ed9\u53e6\u5916\u4e00\u4e2a\u51fd\u6570\uff0c\u7136\u540e\u5728\u53e6\u5916\u4e00\u4e2a\u51fd\u6570\u8c03\u7528\u8be5\u51fd\u6570\ndef fun_name(arg):\nprint(arg(10))\nfun_name(str)\n<\/code><\/pre>\n<p>\u51fd\u6570\u8c03\u7528:<\/p>\n<p>\u8c03\u7528\u4e00\u4e2a\u51fd\u6570\u624d\u4f1a\u6267\u884c\u51fd\u6570\u5185\u5bb9.<\/p>\n<pre><code>function_name(arguments)\n# \u53ef\u4ee5\u901a\u8fc7\u5f15\u7528\u7684\u526f\u672c\u6765\u8c03\u7528\u51fd\u6570\nfunction_copy(args)\n<\/code><\/pre>\n<p>\u51fd\u6570\u7684\u8fd4\u56de\u503c\uff1a<\/p>\n<p>\u7701\u7565return\u8868\u793a\u8fd4\u56deNone. \u5355\u4e2areturn\u8868\u793a\u8fd4\u56deNone.\u5176\u5b83\u8868\u793a\u8fd4\u56de\u4e00\u4e2a\u5bf9\u8c61\uff0e<\/p>\n<pre><code>return\nreturn return_value\n<\/code><\/pre>\n<p>\u51fd\u6570\u7684\u5b9e\u53c2\uff1a<\/p>\n<p>\u4f4d\u7f6e\u53c2\u6570\uff0c\u8c03\u7528\u7684\u65f6\u5019\u901a\u8fc7\u5148\u540e\u987a\u5e8f\u4f20\u9012\u7684\u53c2\u6570,\u51fd\u6570\u5b9a\u4e49\u65f6\u9700\u8981\u653e\u5728\u524d\u9762\uff0e<\/p>\n<p>\u9ed8\u8ba4\u53c2\u6570\uff0c\u5728\u51fd\u6570\u5b9a\u4e49\u65f6\u5c31\u5df2\u7ecf\u521d\u59cb\u5316\u7684\u53c2\u6570\uff0c\u8c03\u7528\u65f6\u53ef\u4ee5\u4e0d\u518d\u8d4b\u503c\uff0e<\/p>\n<p>\u9ed8\u8ba4\u53c2\u6570\u5728\u51fd\u6570\u5b9a\u4e49\u65f6\u9700\u8981\u653e\u5728\u4f4d\u7f6e\u53c2\u6570\u7684\u540e\u9762\uff0e\u5426\u5219\u629b\u51faSytaxError.<\/p>\n<pre><code>def function_test(position_args, keyword_args, *args, **kwargs):\npass\n<\/code><\/pre>\n<p>\u4f4d\u7f6e\u53c2\u6570\u5f3a\u5236\u5206\u9694\u7b26\uff1a<\/p>\n<pre><code>def function(pos1, pos2, \/, pos3, *, kw1, kw2):\npass\n# \/\u8868\u793a\u524d\u9762\u7684pos1\u548cpos2\u662f\u4f4d\u7f6e\u53c2\u6570\uff0c\u4e0d\u80fd\u4f7f\u7528\u5173\u952e\u5b57\u53c2\u6570\u4f20\u9012\uff0e\n# *\u8868\u793a\u540e\u9762\u7684kw1\u548ckw2\u662f\u5173\u952e\u5b57\u53c2\u6570\uff0c\u4e0d\u80fd\u4f7f\u7528\u4f4d\u7f6e\u53c2\u6570\u4f20\u9012\uff0e\n<\/code><\/pre>\n<p>\u51fd\u6570\u7684\u5f62\u53c2\uff1a<\/p>\n<p>\u4f4d\u7f6e\u53c2\u6570\uff0c\u5728\u51fd\u6570\u8c03\u7528\u65f6\u6839\u636e\u5b9a\u4e49\u7684\u53c2\u6570\u7684\u987a\u5e8f\u6765\u4f20\u9012\uff0e<\/p>\n<p>\u9ed8\u8ba4\u53c2\u6570\uff0c\u5728\u51fd\u6570\u8c03\u7528\u65f6\u5982\u679c\u6ca1\u6709\u4f20\u503c\u5219\u4f7f\u7528\u5b9a\u4e49\u7684\u9ed8\u8ba4\u503c\uff0e<\/p>\n<p>\u5173\u952e\u5b57\u53c2\u6570\uff0c\u5728\u51fd\u6570\u8c03\u7528\u65f6\uff0c\u6839\u636e\u5b9a\u4e49\u65f6\u7684\u53c2\u6570\u540d\u79f0\u6765\u4f20\u503c.<\/p>\n<p>\u975e\u5173\u952e\u5b57\u53c2\u6570\u7684\u4f20\u503c\u4e0d\u80fd\u5728\u5173\u952e\u5b57\u53c2\u6570\u540e\u9762\uff0e<\/p>\n<pre><code>def func_test(arg1, arg2, arg3=&quot;val1&quot;, arg4=&quot;val2&quot;):\npass\nfunc_test(1, 2, 3, 4) # \u4f4d\u7f6e\u53c2\u6570\nfunc_test(1, 2) # \u4f7f\u7528\u9ed8\u8ba4\u53c2\u6570\nfunc_test(arg2=2, arg1=1) # \u5173\u952e\u5b57\u4f20\u53c2\n<\/code><\/pre>\n<p>\u53ef\u53d8\u957f\u5ea6\u53c2\u6570:<\/p>\n<p>\u5f53\u51fd\u6570\u53c2\u6570\u4e0d\u786e\u5b9a\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u53ef\u53d8\u957f\u5ea6\u53c2\u6570\uff0e<\/p>\n<p>\u4e00\u4e2a\u661f\u53f7\u8868\u793a\u4e00\u4e2a\u975e\u5173\u952e\u5b57\u53c2\u6570\u7ec4\u6210\u7684\u5143\u7ec4(\u53ef\u4ee5\u662f\u5176\u5b83\u5e8f\u5217\uff0c\u4f1a\u81ea\u52a8\u8f6c\u6362\u6210\u5143\u7ec4)\uff0e<\/p>\n<pre><code>*args # args\u662f\u4e00\u4e2a\u5143\u7ec4\ncall_me(1,2,3)\na = (1, 2, 3)\ncall_me(*a) # \u4f20\u9012\u53c2\u6570\u8981\u7528* \u89e3\u5305\u3002\na = [1, 2, 3]\ncall_me(*a)\n<\/code><\/pre>\n<p>\u4e24\u4e2a\u661f\u53f7\u8868\u793a\u4e00\u4e2a\u5173\u952e\u5b57\u53c2\u6570\u7ec4\u6210\u7684\u5b57\u5178\uff0e<\/p>\n<pre><code>**kwargs # kwargs\u662f\u4e00\u4e2a\u5b57\u5178\ncall_me(key1='val1', key2='val2')\na = {'key1': 'val1', 'key2': 'val2'}\ncall_me(**a) # \u4f20\u9012\u53c2\u6570\u8981\u7528** \u89e3\u5305\u3002\n<\/code><\/pre>\n<p>\u51fd\u6570\u5b9a\u4e49\u65f6\u53ef\u53d8\u957f\u5ea6\u53c2\u6570\u5fc5\u987b\u5728\u4f4d\u7f6e\u53c2\u6570\u548c\u9ed8\u8ba4\u53c2\u6570\u540e\u9762\uff0e\u800c\u4e14\u5173\u952e\u5b57\u53d8\u957f\u53c2\u6570\u5e94\u8be5\u5728\u6700\u540e.<\/p>\n<pre><code>def func_test(position, default='value', *args, **kwargs):\npass\n<\/code><\/pre>\n<p>\u8c03\u7528\u53ef\u53d8\u957f\u5ea6\u53c2\u6570\u65f6\uff0c\u53ef\u4ee5\u628a\u975e\u5173\u952e\u5b57\u53d8\u957f\u53c2\u6570\u653e\u5230\u4e00\u4e2a\u5143\u7ec4\uff0c\u628a\u5173\u952e\u5b57\u53d8\u957f\u53c2\u6570\u653e\u5230\u4e00\u4e2a\u5b57\u5178\uff0e<\/p>\n<p>\u4e5f\u53ef\u4ee5\u5728\u5143\u7ec4\u548c\u5b57\u5178\u4e2d\u653e\u90e8\u5206\u53c2\u6570\uff0c\u53e6\u5916\u4e00\u90e8\u5206\u76f4\u63a5\u4f20\u9012, \u975e\u5173\u952e\u5b57\u53c2\u6570\u7684\u4f20\u503c\u4e0d\u80fd\u5728\u5173\u952e\u5b57\u53c2\u6570\u540e\u9762\uff0e<\/p>\n<pre><code># \u6ce8\u610f\uff0c\u51fd\u6570\u5b9a\u4e49\u7684\u65f6\u5019\u661f\u53f7\u662f\u5fc5\u987b\u7684\uff0c\u51fd\u6570\u8c03\u7528\u7684\u65f6\u5019\u4e5f\u9700\u8981\u661f\u53f7\uff0e\nargs = ('val1', 'val2')\nkwargs = {key1: 'val1', key2: 'val2'}\nfunc_test('position', 'default', *args, **kwargs)\n# \u90e8\u5206\u4f20\u9012\uff0c\u591a\u51fa\u6765\u7684\u975e\u5173\u952e\u5b57\u53c2\u6570\u5c5e\u4e8e\u53d8\u957f\u975e\u5173\u952e\u5b57\u53c2\u6570\uff0c\u591a\u51fa\u6765\u7684\u5173\u952e\u5b57\u53c2\u6570\u5c5e\u4e8e\u53d8\u957f\u5173\u952e\u5b57\u53c2\u6570\uff0e\nfunc_test('position', 'default', 'non-keyword', key='keyword', *(1,2), **{3: 'three'})\n<\/code><\/pre>\n<p>\u51fd\u6570\u7684\u5c5e\u6027\uff1a<\/p>\n<p>\u901a\u8fc7\u5c0f\u6570\u70b9\u6765\u8c03\u7528\u51fd\u6570\u7684\u5c5e\u6027\uff0e<\/p>\n<p>\u5185\u7f6e\u51fd\u6570\u7684\u7279\u6b8a\u5c5e\u6027(BIF)\uff1a<\/p>\n<pre><code>function_test.__doc__\nfunction_test.__name__\nfunction_test.__module__ # __builtin__\nfunction_test.__self__ # None\n<\/code><\/pre>\n<p>\u81ea\u5b9a\u4e49\u51fd\u6570\u7684\u5c5e\u6027(UDF)\uff1a<\/p>\n<pre><code>dir(function_test)\n'__doc__',\n'__name__',\n'func_closure',\n'func_code',\n'func_defaults',\n'func_dict',\n'func_doc',\n'func_globals',\n'func_name'\n<\/code><\/pre>\n<p>\u504f\u51fd\u6570:<\/p>\n<p>\u504f\u51fd\u6570\u5c31\u662f\u901a\u8fc7\u56fa\u5b9a\u539f\u51fd\u6570\u7684\u90e8\u5206\u53c2\u6570\uff0c\u5f97\u5230\u4e00\u4e2a\u65b0\u7684\u51fd\u6570<\/p>\n<pre><code>from functools import partial\npartial(func, *args, **keywords) # \u4e00\u4e2a\u504f\u51fd\u6570\u7684\u7c7b\n<\/code><\/pre>\n<p>\u53d8\u91cf\u4f5c\u7528\u57df:<\/p>\n<p>python\u641c\u7d22\u4e00\u4e2a\u6807\u8bc6\u7b26\u5148\u4ece\u5c40\u90e8\u4f5c\u7528\u57df\u5f00\u59cb\u641c\u7d22\uff0c\u5982\u679c\u6ca1\u6709\u627e\u5230\u5c31\u5728\u5168\u5c40\u4f5c\u7528\u57df\u627e\uff0c\u5426\u5219\u629b\u51faNameError\u5f02\u5e38\uff0e<\/p>\n<pre><code># \u5f53\u5728\u51fd\u6570\u5916\u90e8\u548c\u5185\u90e8\u90fd\u5b9a\u4e49\u4e86\u540c\u4e00\u4e2a\u53d8\u91cf\uff0c\u5c40\u90e8\u53d8\u91cf\u4f1a\u8986\u76d6\u5168\u5c40\u53d8\u91cf\nvar = 'global'\ndef func_test(*args, **kwargs):\nvar = 'local'\nprint(var)\nfunc_test() # local\n# \u5982\u679c\u5728\u51fd\u6570\u5185\u90e8\u4f7f\u7528\u4e00\u4e2a\u4e0d\u5728\u51fd\u6570\u5185\u90e8\u5b9a\u4e49\u7684\u53d8\u91cf\uff0c\u5c31\u4f1a\u5728\u51fd\u6570\u5916\u90e8\u67e5\u627e\uff0e\nvar = 'global'\ndef func_test(*args, **kwargs):\nprint(var)\nfunc_test() # global\n# \u5728\u51fd\u6570\u5185\u90e8\u4e0d\u80fd\u4fee\u6539\u5916\u90e8\u53d8\u91cf,\u53ea\u80fd\u5f15\u7528.\nvar = 'global'\ndef func_test(*args, **kwargs):\nvar += 'local'\nprint(var)\nfunc_test() # UnboundLocalError: local variable 'var' referenced before assignment\n# \u5982\u679c\u9700\u8981\u5728\u5c40\u90e8\u5f15\u7528\u5168\u5c40\u53d8\u91cf\u9700\u8981\u4f7f\u7528global\u5173\u952e\u5b57\nvar = 'global'\ndef func(*args, **kwargs):\nglobal var\nvar = 'local'\nprint(var)\nfunc() # local\nprint(var) # local # \u5168\u5c40\u53d8\u91cf\u5728\u5c40\u90e8\u88ab\u4fee\u6539\uff0e\n<\/code><\/pre>\n<p>\u7c7b\u578b\u6ce8\u91ca<\/p>\n<pre><code>def func1(arg1: int, arg2: str) -&gt; bool:\n......\n\/\/ with default value\ndef func2(arg1: str = &quot;hello&quot;) -&gt; str\n......\ndef func3(arg1: Optional[str]) -&gt; int\n......\ndef func4() -&gt; Tuple[int, int]:\n......\n# \u8054\u5408\u7c7b\u578b\uff0c\u4f7f\u7528 | \u8868\u793a\ndef func5(x: int | str):\n......\n<\/code><\/pre>\n<h2 id=\"lambda\u533f\u540d\u51fd\u6570\"><em>lambda\u533f\u540d\u51fd\u6570<\/em><\/h2>\n<p>lambda\u533f\u540d\u51fd\u6570\u5c31\u662f\u4e00\u4e2a\u53ea\u6709\u4e00\u884c\u8868\u8fbe\u5f0f\uff0c\u4e0d\u9700\u8981\u901a\u8fc7def\u6765\u547d\u540d\u7684\u51fd\u6570.<\/p>\n<p>lambda\u533f\u540d\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u53ef\u8c03\u7528\u7684\u51fd\u6570\u5bf9\u8c61\uff0e<\/p>\n<p>lambda\u533f\u540d\u51fd\u6570\u652f\u6301\u901a\u8fc7def\u5b9a\u4e49\u7684\u51fd\u6570\u7684\u6240\u6709\u529f\u80fd\uff0e<\/p>\n<p>lambda\u533f\u540d\u51fd\u6570\u4e2d\u4e0d\u80fd\u6709return\u8bed\u53e5, expression\u7684\u7ed3\u679c\u5c31\u662f\u51fd\u6570\u8fd4\u56de\u503c\uff0e<\/p>\n<pre><code>lambda [arg1[, arg2, ...argN]]: expression\nlambda *args, **kwargs: expression\nlambda : expression\n<\/code><\/pre>\n<h2 id=\"functional-programming\u51fd\u6570\u5f0f\u7f16\u7a0b\"><em>Functional Programming\u51fd\u6570\u5f0f\u7f16\u7a0b<\/em><\/h2>\n<p>python\u6d89\u53ca\u5230\u51fd\u6570\u5f0f\u7f16\u7a0b\u4e3b\u8981\u6709\u51e0\u4e2a\u5185\u7f6e\u7c7b\u7c7b\u578b\u7684\u5de5\u5382\u51fd\u6570\u548clambda\u533f\u540d\u51fd\u6570\uff0e<\/p>\n<pre><code>zip(*iterables, strict=False)\nfilter(function, iterable, \/)\nresult = filter(lambda x: x%2==0, [1,2,3,4,5])\n&gt; x=1, 1%2==0 False\n&gt; x=2, 2%2==0, True\n&gt; x=3, 3%2==0, False\nprint(list(result))\n&gt; [2]\nmap(function, iterable, \/, *iterables)\nresult = map(lambda x: x**2, [1,2,3])\n&gt; x=1, x**2 =1\n&gt; x=2, 2**2=4\n&gt; x=3, 3**2=9\nprint(list(result))\n&gt; [1,4,9]\nfrom functools import reduce\nreduce(func, iterable[, initializer])\nreduce(lambda x,y: x*y, [1,2,3,4])\n&gt; x=1,y=2, x*y=2\n&gt; x=2, y=3, x*y=6\n&gt; x=6, y=4, x*y=24\n<\/code><\/pre>\n<hr>\n<h2 id=\"\u5185\u5d4c\u51fd\u6570\"><em>\u5185\u5d4c\u51fd\u6570<\/em><\/h2>\n<p>\u53ef\u4ee5\u5728\u51fd\u6570\u5185\u90e8\u5b9a\u4e49\u51fd\u6570\uff0c\u5185\u90e8\u51fd\u6570\u4e0d\u80fd\u5728\u5916\u90e8\u51fd\u6570\u4ee5\u5916\u7684\u5730\u65b9\u8c03\u7528\uff0e\n\u5185\u5d4c\u51fd\u6570\u4e0d\u4e00\u5b9a\u8fd4\u56de\uff0c\u4e0d\u4f1a\u8bb0\u4f4f\u5916\u90e8\u53d8\u91cf\u3002<\/p>\n<pre><code>def outer(*args, **kwargs):\nvar = 'value' # \u5916\u90e8\u51fd\u6570\u7684\u53d8\u91cf\ndef inner(arg): # \u5185\u5d4c\u51fd\u6570\u7684\u53c2\u6570\u4e0d\u80fd\u662f\u5916\u90e8\u51fd\u6570\u7684\u53c2\u6570\uff0e\u5185\u90e8\u51fd\u6570\u5fc5\u987b\u5b8c\u5168\u72ec\u7acb\uff0e\nprint(var) # \u5185\u5d4c\u51fd\u6570\u53ef\u4ee5\u5f15\u7528\u5916\u90e8\u51fd\u6570\u7684\u53d8\u91cf\n# var += 1 # \u5185\u5d4c\u51fd\u6570\u4e0d\u80fd\u4fee\u6539\u5916\u90e8\u51fd\u6570\u7684\u4e0d\u53ef\u53d8\u7c7b\u578b\u53d8\u91cf\ninner(args)\ndef outer():\nx = 1\ndef inner():\nnonlocal x # nonlocal\u5173\u952e\u5b57\u53ef\u4ee5\u5f15\u7528\u5916\u90e8\u51fd\u6570\u7684\u4e0d\u53ef\u53d8\u7c7b\u578b\u53d8\u91cf \u8fdb\u884c\u4fee\u6539\u3002\nx += 1\ninner()\nprint(x) # 2\ndef outer(*args, **kwargs):\nfilter(lambda arg: expression, sequence)\nmap(lambda arg: expression, sequence)\nfunctools.reduce(lambda arg: expression, sequence)\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u5728\u51fd\u6570\u5185\u90e8\u5185\u5d4c\u533f\u540d\u51fd\u6570\uff0c\u533f\u540d\u51fd\u6570\u53ef\u4ee5\u4f7f\u7528\u5916\u90e8\u51fd\u6570\u7684\u53c2\u6570:<\/p>\n<pre><code>def foo(x, y):\nbar = lambda :x + y\nprint(bar())\nfoo(4,3)\n<\/code><\/pre>\n<p>\u9012\u5f52\uff1a<\/p>\n<pre><code>\u5728\u51fd\u6570\u4e2d\u8c03\u7528\u51fd\u6570\u672c\u8eab\u662f\u4e00\u79cd\u9012\u5f52\u65b9\u6cd5\ndef fib(n):\nif n in[0, 1]:\nval = 1\nelse:\nval = fib(n-1) + fib(n-2)\nreturn val\n<\/code><\/pre>\n<h2 id=\"closure\u95ed\u5305\"><em>closure\u95ed\u5305<\/em><\/h2>\n<p>\u95ed\u5305\u4e00\u5b9a\u662f\u5185\u5d4c\u51fd\u6570\uff0c\u5185\u5d4c\u51fd\u6570\u4e0d\u4e00\u5b9a\u662f\u95ed\u5305\u3002<\/p>\n<p>\u5728\u4e00\u4e2a\u5185\u90e8\u51fd\u6570\u91cc\u5bf9\u5728\u5916\u90e8\u4f5c\u7528\u57df\u7684\u53d8\u91cf\u8fdb\u884c\u5f15\u7528\uff0c\u5185\u90e8\u51fd\u6570\u88ab\u8ba4\u4e3a\u662fclosure.<\/p>\n<p>\u5b9a\u4e49\u5728\u5916\u90e8\u51fd\u6570\u5185\u7684\u4f46\u7531\u5185\u90e8\u51fd\u6570\u5f15\u7528\u7684\u53d8\u91cf\u79f0\u4e3a\u81ea\u7531\u53d8\u91cf\uff0e\u81ea\u7531\u53d8\u91cf\u7684\u503c\u80fd\u88ab\u8bb0\u4f4f\u3002<\/p>\n<pre><code>def outer(arg):\nfree_var = arg # \u5916\u90e8\u51fd\u6570\u7684\u81ea\u7531\u53d8\u91cf\ndef inner(*args, **kwargs):\nprint(free_var)\nreturn free_var\nreturn inner\n<\/code><\/pre>\n<p>\u5f53\u81ea\u7531\u53d8\u91cf\u662f\u4e00\u4e2a\u51fd\u6570\u65f6\uff0c\u95ed\u5305\u5c31\u662f\u4e00\u4e2a\u88c5\u9970\u5668\uff0cdecorator\u662fclosure\u6700\u5e38\u89c1\u7684\u5e94\u7528\uff0e<\/p>\n<pre><code>def outer():\ndata = []\ndef clos(value):\ndata.append(value) # \u53ef\u53d8\u7c7b\u578b\u4e0d\u9700\u8981nonlocal\u3002\nreturn data\nreturn clos\ncall = outer() # \u8c03\u7528\u5916\u90e8\u51fd\u6570\uff0c\u8fd4\u56de\u4e00\u4e2a\u5185\u90e8\u51fd\u6570\u7684\u5f15\u7528\nprint(call(1)) # [1]\nprint(call(2)) # [1, 2]\n# \u8c03\u7528\u5916\u90e8\u51fd\u6570\uff0c\u8fd4\u56de\u4e00\u4e2a\u5185\u90e8\u51fd\u6570\u7684\u5f15\u7528,\u3000\u4f20\u5165\u5916\u90e8\u51fd\u6570\u7684\u5c31\u662f\u81ea\u7531\u53d8\u91cf,\u8fd4\u56de\u7684\u5185\u90e8\u51fd\u6570\u5c31\u662f\u95ed\u5305.\nfirst_clos = outer(arg)\n# \u8c03\u7528closure\nfirst_clos(*args, **kwargs)\n<\/code><\/pre>\n<h2 id=\"decorator\u88c5\u9970\u5668\"><em>decorator\u88c5\u9970\u5668<\/em><\/h2>\n<p>\u88c5\u9970\u5668\u5206\u4e3a\u51fd\u6570(\u65b9\u6cd5)\u88c5\u9970\u5668\u548c\u7c7b\u88c5\u5668\uff0e\u51fd\u6570\u4e2d\u518d\u5b9a\u4e49\u51fd\u6570\u662f\u51fd\u6570\u88c5\u9970\u5668\uff0c\u51fd\u6570\u4e2d\u518d\u5b9a\u4e49\u7c7b\u662f\u7c7b\u88c5\u9970\u5668\uff0e<\/p>\n<p>\u51fd\u6570\u88c5\u9970\u5668\u4fee\u9970\u51fd\u6570\u548c\u7c7b\u4e2d\u7684\u65b9\u6cd5\uff0c\u7c7b\u88c5\u9970\u5668\u4fee\u9970\u7c7b\uff0e\u7c7b\u88c5\u9970\u5668\u53c2\u8003OOP\uff0e<\/p>\n<p>\u88c5\u9970\u5668\u672c\u8d28\u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u53ef\u4ee5\u8ba9\u5176\u5b83\u51fd\u6570\u5728\u4e0d\u505a\u4fee\u6539\u7684\u60c5\u51b5\u4e0b\u589e\u52a0\u989d\u5916\u7684\u529f\u80fd\uff0e<\/p>\n<p>\u5e38\u7528\u4e8e\u63d2\u5165\u65e5\u5fd7\uff0c\u6027\u80fd\u6d4b\u8bd5\uff0c\u4e8b\u52a1\u5904\u7406\uff0c\u7f13\u5b58\uff0c\u6743\u9650\u6821\u9a8c\u7b49\u573a\u666f\uff0e<\/p>\n<p>\u88c5\u9970\u5668\u662f\u7528\u6765\u88c5\u9970\u51fd\u6570\u7684\u5305\u88c5\uff0c\u8fd4\u56de\u4e00\u4e2a\u4fee\u6539\u540e\u7684\u51fd\u6570\u5bf9\u8c61\uff0e\u5c06\u5176\u91cd\u65b0\u8d4b\u503c\u7ed9\u539f\u6765\u7684\u6807\u8bc6\u7b26\uff0c\u5e76\u6c38\u4e45\u5931\u53bb\u5bf9\u539f\u59cb\u51fd\u6570\u5bf9\u8c61\u7684\u8bbf\u95ee\uff0e<\/p>\n<p>\u7b26\u53f7@\u662f\u88c5\u9970\u5668\u7684\u8bed\u6cd5\u7cd6.<\/p>\n<p>\u4e0d\u5e26\u53c2\u6570\u7684\u88c5\u9970\u5668\uff1a<\/p>\n<pre><code>def deco_name(func):\ndef wrapper_name(*args, **kwargs): # \u62bd\u8c61\u51fa\u76f8\u540c\u7684\u90e8\u5206\u8fdb\u884c\u5305\u88c5\n&quot;&quot;&quot;Docs for wrapper_name.&quot;&quot;&quot;\nprint(func.__name__) # \u62bd\u8c61\u51fa\u6765\u7684\u90e8\u5206\u5728\u8fd9\u91cc\u5b9e\u73b0\nprint(args, kwargs) # \u53ef\u4ee5\u5f15\u7528func\u4f20\u5165\u7684\u53c2\u6570\nreturn func(*args, **kwargs) # \u6700\u540e\u8c03\u7528\u65b0\u589e\u52a0\u7684\u529f\u80fd\nreturn wrapper_name # \u8fd4\u56de\u5305\u88c5\u51fd\u6570\u7684\u5f15\u7528.\n# \u589e\u52a0\u65b0\u529f\u80fd,\u88c5\u9970\u540e\u8fd4\u56de\u5305\u88c5\u51fd\u6570\u7684\u4e00\u4e2a\u5f15\u7528,\u8d4b\u503c\u7ed9\u539f\u6765\u7684foo\uff0e\u6b64\u65f6\u5305\u88c5\u51fd\u6570wrapper_name\u5e76\u4e0d\u4f1a\u6267\u884c\n@deco_name\ndef foo(*args, **kwargs):\n&quot;&quot;&quot;Docs for foo.&quot;&quot;&quot;\nprint('call foo')\n# \u7b49\u6548\u4e8e\nfoo = deco_name(foo)\n# \u8c03\u7528\u88c5\u9970\u540e\u7684\u51fd\u6570,\u3000\u8c03\u7528\u7684\u662f\u88c5\u9970\u540e\u7684\u65b0\u7684\u51fd\u6570\uff0e\nfoo(*args, **kwargs)\n<\/code><\/pre>\n<p>\u5e26\u53c2\u6570\u7684\u88c5\u9970\u5668:<\/p>\n<pre><code>def deco_name(arg):\ndef deco_inner(func):\ndef wrapper_name(*args, **kwargs):\n&quot;&quot;&quot;Docs for wrapper_name.&quot;&quot;&quot;\nprint(arg) # \u901a\u8fc7\u88c5\u9970\u5668\u7684\u53c2\u6570arg\u6765\u505a\u4e00\u4e9b\u5224\u65ad\nprint(func.__name__)\nprint(func.__doc__)\nprint(args, kwargs)\nreturn func(*args, **kwargs)\nreturn wrapper_name\nreturn deco_inner\n# deco_name(arg)(foo) -&gt; deco_inner(foo) -&gt; wrapper_name\n@deco_name(arg=&quot;value&quot;)\ndef foo(*args, **kwargs):\n&quot;&quot;&quot;Docs for foo.&quot;&quot;&quot;\npass\n# wrapper_name(*args, **kwargs)\nfoo(*args, **kwargs)\n<\/code><\/pre>\n<p>\u88c5\u9970\u5668\u7684\u5c5e\u6027\uff1a<\/p>\n<pre><code>foo.__name__ # wrapper_name, \u5e76\u975efoo\nfoo.__doc__ # &quot;Docs for wrapper_name.&quot;, \u5e76\u975efoo\u7684doc.\n# \u53ef\u4ee5\u901a\u8fc7import functools.wraps\u6765\u4fee\u9970wrapper_name\u6539\u53d8\u8fd9\u4e00\u5c5e\u6027\uff0e\n<\/code><\/pre>\n<p><a class=\"link\" href=\"https:\/\/github.com\/crazy-canux\/python\/blob\/master\/python\/psl\/myfunctools.py\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/crazy-canux\/python\/blob\/master\/python\/psl\/myfunctools.py<\/a><\/p>\n<p>\u591a\u5c42\u88c5\u9970\u5668\uff1a<\/p>\n<pre><code>@foo\n@bar\ndef func(*args, **kwargs):\n...\nfunc = foo(bar(func))\n<\/code><\/pre>\n<p><a class=\"link\" href=\"https:\/\/github.com\/crazy-canux\/python\/blob\/master\/python\/decorator\/function_decorator.py\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/crazy-canux\/python\/blob\/master\/python\/decorator\/function_decorator.py<\/a><\/p>\n<hr>\n<h1 id=\"python\u6a21\u5757\u548c\u5305\"><strong>python\u6a21\u5757\u548c\u5305<\/strong><\/h1>\n<p>\u540d\u79f0\u7a7a\u95f4\uff1a<\/p>\n<ul>\n<li>\u5c40\u90e8\u540d\u79f0\u7a7a\u95f4<\/li>\n<li>\u5168\u5c40\u540d\u79f0\u7a7a\u95f4<\/li>\n<li>\u5185\u5efa\u540d\u79f0\u7a7a\u95f4<\/li>\n<\/ul>\n<p>python\u89e3\u91ca\u5668\u6a21\u5757\u52a0\u8f7d\u987a\u5e8f\uff1a<\/p>\n<ul>\n<li>\u5185\u5b58\u4e2d\u5df2\u7ecf\u52a0\u8f7d\u7684\u6a21\u5757\uff0c\u4e5f\u5c31\u662f\u7f13\u5b58(sys.modules)<\/li>\n<li>\u6700\u5148\u52a0\u8f7d\u5185\u5efa\u540d\u79f0\u7a7a\u95f4\uff0c\u4e5f\u5c31\u662f\u5185\u7f6e\u6a21\u5757\uff0e<\/li>\n<li>sys.path\u8def\u5f84\u4e2d\u7684\u6a21\u5757<\/li>\n<\/ul>\n<p>\u7136\u540e\u52a0\u8f7d\u6267\u884c\u6a21\u5757\u7684\u5168\u5c40\u540d\u79f0\u7a7a\u95f4\uff0c\u5728\u6a21\u5757\u6267\u884c\u65f6\u662f\u6d3b\u52a8\u540d\u79f0\u7a7a\u95f4\uff0e<\/p>\n<p>\u6700\u540e\u52a0\u8f7d\u5c40\u90e8\u540d\u79f0\u7a7a\u95f4\uff0c\u5728\u6267\u884c\u671f\u95f4\u662f\u4e0d\u65ad\u53d8\u5316\u7684\uff0e<\/p>\n<p>\u540d\u79f0\u7a7a\u95f4\u548c\u53d8\u91cf\u7684\u4f5c\u7528\u57df\u662f\u6709\u533a\u522b\u7684\uff0e<\/p>\n<p>\u53d8\u91cf\uff0f\u51fd\u6570\uff0f\u65b9\u6cd5\u5148\u4ece\u5c40\u90e8\u540d\u79f0\u7a7a\u95f4\u5f00\u59cb\u67e5\u627e\uff0c\u5728\u627e\u5168\u5c40\u540d\u79f0\u7a7a\u95f4\uff0c\u6700\u540e\u67e5\u627e\u5185\u5efa\u540d\u79f0\u7a7a\u95f4\uff0e<\/p>\n<p>\u5982\u679c\u90fd\u6ca1\u627e\u5230\u5c31\u629b\u51faNameError\u5f02\u5e38\uff0e<\/p>\n<p>\u65e0\u9650\u5236\u540d\u79f0\u7a7a\u95f4\uff0c\u53ef\u4ee5\u901a\u8fc7\u5c5e\u6027\u8fd0\u7b97\u5c0f\u6570\u70b9\u6765\u6307\u5b9a\u540d\u79f0\u7a7a\u95f4\uff0e<\/p>\n<pre><code>module.var\nmodule.function()\nmodule.method()\n<\/code><\/pre>\n<p>\u641c\u7d22\u8def\u5f84:<\/p>\n<p>\u641c\u7d22\u8def\u5f84\u5728\u4e0d\u540c\u7684\u64cd\u4f5c\u4e00\u540c\u4e00\u822c\u4e0d\u540c.<\/p>\n<p>\u641c\u7d22\u8def\u5f84\u901a\u8fc7\u4e24\u4e2a\u53d8\u91cf\u6765\u8bbe\u7f6e<\/p>\n<ol>\n<li>shell\u7684\u73af\u5883\u53d8\u91cfPYTHONPATH\uff0e<\/li>\n<li>python\u89e3\u91ca\u5668\u7684\u53d8\u91cfsys.path\u5217\u8868\u91cc.<\/li>\n<\/ol>\n<p>\u5728\u4ee3\u7801\u91cc\u4fee\u6539\u641c\u7d22\u8def\u5f84sys.path<\/p>\n<ul>\n<li>sys.path.append(os.path.abspath(..))<\/li>\n<li>sys.path.insert(0, os.path.abspath(..)) # \u63d2\u5165\u5230\u6700\u524d\u9762\uff0c\u4e5f\u5c31\u662f\u5728sys.path\u7684\u7b2c\u4e00\u4e2a&rsquo;&rsquo;(\u5f53\u524d\u8def\u5f84)\u7684\u524d\u9762\uff0e<\/li>\n<\/ul>\n<p>\u6240\u6709\u5bfc\u5165\u5e76\u52a0\u8f7d\u7684\u6a21\u5757\u4f1a\u5b58\u653e\u5728sys.modules\u4e2d\uff0c\u5bfc\u5165\u6a21\u5757\u65f6\u7684\u641c\u7d22\u987a\u5e8f<\/p>\n<ol>\n<li>\u5148\u641c\u7d22\u5f53\u524d\u76ee\u5f55.(\u4f1a\u8986\u76d6\u540c\u540d\u7684\u6807\u51c6\u5e93), \u5176\u5b9e\u662f\u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u52a8\u6001\u6dfb\u52a0\u5230sys.path\u4e2d\u7b2c\u4e00\u4e2a&rsquo;&lsquo;\u7684\u4f4d\u7f6e\uff0e<\/li>\n<li>\u6ca1\u6709\u7684\u8bdd\u518d\u641c\u7d22sys.path,\u6309\u7167\u8fd9\u4e2a\u5217\u8868\u7684\u987a\u5e8f\u641c\u7d22\u627e\u5230\u7b2c\u4e00\u4e2a\uff0c\u7136\u540e\u52a0\u8f7d\u8be5\u6a21\u5757.<\/li>\n<li>\u6ca1\u641c\u5230\u629b\u51faImportError\u5f02\u5e38\uff0e<\/li>\n<\/ol>\n<h2 id=\"module\u6a21\u5757\"><em>module\u6a21\u5757<\/em><\/h2>\n<p>\u6a21\u5757\u5c31\u662f\u4e00\u4e2apython\u7a0b\u5e8f\u7684\u6e90\u6587\u4ef6\uff0e\u6a21\u5757\u662f\u7528\u6765\u7ec4\u7ec7python\u4ee3\u7801\u7684\u65b9\u6cd5\uff0e<\/p>\n<p>\u628a\u5176\u4ed6\u6a21\u5757\u4e2d\u5c5e\u6027\u9644\u52a0\u5230\u4f60\u7684\u6a21\u5757\u4e2d\u7684\u64cd\u4f5c\u53eb\u505a\u5bfc\u5165(import).<\/p>\n<p>\u90a3\u4e9b\u81ea\u6211\u5305\u542b\u5e76\u4e14\u6709\u7ec4\u7ec7\u7684\u4ee3\u7801\u7247\u65ad\u5c31\u662f\u6a21\u5757( module ).<\/p>\n<p>\u67e5\u770b\u6240\u6709\u6a21\u5757\uff1a<\/p>\n<pre><code>help('modules')\n<\/code><\/pre>\n<h2 id=\"package\"><em>package<\/em><\/h2>\n<p>\u5305\u5c31\u662f\u628a\u591a\u4e2a\u6a21\u5757\u653e\u5728\u4e00\u4e2a\u76ee\u5f55\u4e2d\uff0c\u7136\u540e\u5fc5\u987b\u52a0\u4e0a__init__.py\u6587\u4ef6\uff0e\u5305\u662f\u7528\u6765\u7ec4\u7ec7\u6a21\u5757\u7684\uff0e<\/p>\n<pre><code># \u5305\u652f\u6301\u6a21\u7cca\u5bfc\u5165.\n[Deprecated] from package.module import * # \u4f1a\u5bfc\u5165\u5305\u91cc\u9762\u6240\u6709\u7684\u53d8\u91cf\uff0c\u51fd\u6570\uff0c\u7c7b\uff0e\n<\/code><\/pre>\n<p>\u5728__init__.py\u5bfc\u5165\u5c5e\u6027\uff0c\u5bfc\u5165\u65f6\u53ef\u4ee5\u7701\u7565\u6a21\u5757\u540d\uff1a<\/p>\n<pre><code>robot\/__init__.py\nfrom robot.run import run, run_cli\ntest.py\nfrom robot import run, run_cli # \u53ef\u4ee5\u7701\u7565\u5c5e\u6027\u6240\u5728\u7684\u6a21\u5757\u540d\nrun()\nrun_cli()\n\u7b49\u6548:\ntest.py\nfrom robot.run import run, run_cli # \u901a\u8fc7\u5305\u540d\u548c\u6a21\u5757\u540d\u76f4\u63a5\u5bfc\u5165\uff0e\nrun()\nrun_cli()\n<\/code><\/pre>\n<p>\u5728__init__.py\u5b9a\u4e49__all__\u53d8\u91cf\u6765\u51b3\u5b9a\u5bfc\u5165\u54ea\u4e9b\u5c5e\u6027\uff0e<\/p>\n<pre><code>from robot.run import run, run_cli\n__all__ = [run, run_cli]\nfrom robot import * # \u4ec5\u4ec5\u5bfc\u5165__all__\u6307\u5b9a\u7684\u5c5e\u6027\n<\/code><\/pre>\n<h2 id=\"import\u5bfc\u5165\u6a21\u5757\u548c\u5305\"><em>import\u5bfc\u5165\u6a21\u5757\u548c\u5305<\/em><\/h2>\n<p>\u5982\u679c\u6a21\u5757\u7b2c\u4e00\u6b21\u88ab\u5bfc\u5165\uff0c\u5c31\u4f1a\u88ab\u52a0\u8f7d\u5e76\u6267\u884c\uff0e\u4e5f\u5c31\u662f\u8bf4\u6a21\u5757\u88ab\u52a0\u8f7d\u65f6\u9876\u5c42\u7684\u4ee3\u7801\u4f1a\u88ab\u6267\u884c\uff0c\u4e00\u822c\u5305\u62ec\u5168\u5c40\u53d8\u91cf\uff0c\u7c7b\u548c\u51fd\u6570\u7684\u7533\u660e\uff0e<\/p>\n<p>\u4e00\u4e2a\u6a21\u5757\u65e0\u8bba\u88ab\u5bfc\u5165(import)\u591a\u5c11\u6b21\uff0c\u53ea\u5728\u7b2c\u4e00\u6b21\u5bfc\u5165\u65f6\u88ab\u52a0\u8f7d\u4e00\u6b21\uff0e\u9664\u975e\u7528reload()\u51fd\u6570\uff0e<\/p>\n<p>\u5199\u4ee3\u7801\u65f6\u5019import\u5bfc\u5165\u987a\u5e8f(\u4e2d\u95f4\u7a7a\u4e00\u683c)\uff1a<\/p>\n<ul>\n<li>\u6807\u51c6\u5e93\u6a21\u5757<\/li>\n<li>\u7b2c\u4e09\u65b9\u5e93\u6a21\u5757<\/li>\n<li>\u81ea\u5b9a\u4e49\u6a21\u5757<\/li>\n<\/ul>\n<p>import\u5173\u952e\u5b57\u5bfc\u5165\u6a21\u5757\/\u5305\uff1a<\/p>\n<pre><code>import module\nimport package\n# \u5305\u53ef\u4ee5\u591a\u5c42\u5d4c\u5957\nimport package.subpackage\nimport package.subpackage.module\n<\/code><\/pre>\n<p>from-import\u5173\u952e\u5b57\u5bfc\u5165\u6a21\u5757\u4e2d\u7684\u5c5e\u6027\uff1a<\/p>\n<pre><code>from module import function\/method\/variable\nfrom package.module import function\/method\/variable\nfrom package.subpackage.module import function\/method\/variable\n<\/code><\/pre>\n<p>from-import\u5173\u952e\u5b57\u5bfc\u5165\u5305\u4e2d\u7684\u7684\u5305\/\u6a21\u5757\u5230\u5f53\u524d\u7684\u540d\u79f0\u7a7a\u95f4\uff1a<\/p>\n<pre><code>from package import subpackage\nfrom package...subpackage import sub-subpackage\nfrom package import module\n<\/code><\/pre>\n<p>as\u5173\u952e\u5b57\u53ef\u4ee5\u7ed9\u6a21\u5757\/\u5305\/\u5c5e\u6027\u53d6\u522b\u540d\uff1a<\/p>\n<pre><code>import module\/package\/package.subpackage as alias\nfrom module\/package.module\/package.subpackage.module import function\/method\/variable as alias\nfrom package\/package.subpackage import module\/subpackage\/sub-subpackage alias\n<\/code><\/pre>\n<p>\u76f8\u5173\u7684\u5185\u7f6e\u51fd\u6570:<\/p>\n<pre><code>locals()\nglobal()\n[Deprecated] reload() # \u63a8\u8350\u7528from imp import reload(), \u91cd\u65b0\u5bfc\u5165\u4e00\u4e2a\u5df2\u7ecf\u5bfc\u5165\u7684\u6a21\u5757\uff0e\n<\/code><\/pre>\n<p>\u6a21\u5757\u7684\u7279\u6b8a\u5c5e\u6027\uff1a<\/p>\n<pre><code>__name__ # \u6a21\u5757\u7684\u7279\u6b8a\u5c5e\u6027\n# \u5982\u679c\u6a21\u5757\u76f4\u63a5\u8fd0\u884c\uff0c\u4e5f\u5c31\u662f\u4f5c\u4e3atop-level\u811a\u672c\u8fd0\u884c\uff0e\u503c\u4e3a__main__.\n# \u5982\u679c\u4f5c\u4e3amodule,\u4e5f\u5c31\u662f(import\/python -m)\uff0c\u503c\u4e3a\u6a21\u5757\u540d\u79f0.\n# \u4e00\u822c\u7528\u6765\u505a\u5355\u5143\u6d4b\u8bd5.\nif __name__ == &quot;__main__&quot;:\nmain()\n<\/code><\/pre>\n<h2 id=\"pep0328\"><em>PEP0328<\/em><\/h2>\n<p>\u591a\u884c\u5bfc\u5165\uff1a<\/p>\n<pre><code># \u901a\u8fc7\u7eed\u884c\u7b26\nfrom module import a, b, c, \\\nd, e, f\n# \u901a\u8fc7\u5206\u6210\u4e24\u884c\u5bfc\u5165\nfrom module import a, b, c\nfrom module import d, e, f\n# PEP328\u5efa\u8bae\u4f7f\u7528\u5206\u7ec4\u5bfc\u5165\nfrom module import (a, b, c,\nd, e, f)\n# \u4e0d\u63a8\u8350\u4f7f\u7528\u6a21\u7cca\u5bfc\u5165\uff0e\n[Deprecated] from module import *\n<\/code><\/pre>\n<p>\u7edd\u5bf9\u5bfc\u5165\uff1a<\/p>\n<p>\u9ed8\u8ba4\u91c7\u7528\u7edd\u5bf9\u5bfc\u5165\uff0c\u4e5f\u5c31\u662f\u901a\u8fc7\u5b8c\u6574\u7684\u5305\u8def\u5f84\u6765\u5bfc\u5165\uff0c\u907f\u514d\u548c\u6807\u51c6\u5e93\u6a21\u5757\u51b2\u7a81\uff0e<\/p>\n<p>\u9ed8\u8ba4\u7684\u5305\u8def\u5f84\u5c31\u662fsys.path\u6216PYTHONPATH.<\/p>\n<p>\u53ea\u6709import\u6ca1\u6709from\u7684\u4e00\u5b9a\u662f\u7edd\u5bf9\u5bfc\u5165\uff0e<\/p>\n<pre><code>import package\/module\n<\/code><\/pre>\n<p>\u76f8\u5bf9\u5bfc\u5165\uff1a [TODO]<\/p>\n<p>\u5c0f\u6570\u70b9\u5f00\u5934\u8868\u793a\u76f8\u5bf9\u5bfc\u5165\uff0c\u4e00\u4e2a\u5c0f\u6570\u70b9\u8868\u793a\u5f53\u524d\u7684\u5305\uff0c\u4e24\u4e2a\u5c0f\u6570\u70b9\u8868\u793a\u4e0a\u4e00\u5c42\u7684\u5305\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff0e<\/p>\n<p>\u76f8\u5bf9\u5bfc\u5165\u4e00\u5b9a\u662fimport-from\u7ed3\u6784\uff0e<\/p>\n<p>\u76f8\u5bf9\u5bfc\u5165\u7684\u4f18\u5148\u7ea7\u4f4e\u4e8e\u7edd\u5bf9\u5bfc\u5165\uff0c\u4e5f\u5c31\u662f\u5148\u53bbsys.path\u4e2d\u67e5\u627e\uff0c\u7136\u540e\u6839\u636e\u5f53\u524d\u6a21\u5757\u7684\u76f8\u5bf9\u4f4d\u7f6e\u67e5\u627e\uff0e<\/p>\n<pre><code>from . import package\/module\nfrom .foo import bar\nfrom ..foo import bar\nfrom ...foo import bar\n<\/code><\/pre>\n<hr>\n<h1 id=\"python\u6587\u6863\"><strong>python\u6587\u6863<\/strong><\/h1>\n<p>\u6587\u6863\u6ce8\u91ca:<\/p>\n<p>python\u7684\u6587\u6863\u6ce8\u91ca\u91c7\u7528reST\u98ce\u683c\u7684\u6ce8\u91ca.<\/p>\n<p>\u5305\/\u6a21\u5757\u6587\u6863:<\/p>\n<p>\u5305\u62ec\u4f5c\u8005,\u7248\u6743,\u6a21\u5757\u7684\u4fe1\u606f.<\/p>\n<pre><code>&quot;&quot;&quot;\nFile Summary\nCopyright\nLicense\n:author:\n:version:\n:since:\nDescription\n&quot;&quot;&quot;\n<\/code><\/pre>\n<p>\u7c7b\/\u51fd\u6570\/\u65b9\u6cd5\u6587\u6863:<\/p>\n<p>\u5305\u62ec\u4f5c\u7528,\u521d\u59cb\u5316\u65b9\u6cd5\u53c2\u6570\u548c\u7c7b\u578b,\u51fd\u6570\u548c\u65b9\u6cd5\u7684\u53c2\u6570\u548c\u7c7b\u578b,\u8fd4\u56de\u7c7b\u578b\u548c\u629b\u51fa\u5f02\u5e38,\u4ee5\u53ca\u7528\u6cd5\u7528\u4f8b.<\/p>\n<pre><code>&quot;&quot;&quot;Summary\n:param param1: param1 used for what\n:type param1: param1 type\n:param param2: param2 used for what\n:type param2: param2 type\n...\n:returns param: return what\n:rtype param: return type\n...\n:raise exceptionname: raise what exception\nUsage\/Description\n&quot;&quot;&quot;\n<\/code><\/pre>\n<p>\u6587\u6863\u7684\u7279\u6b8a\u5c5e\u6027:<\/p>\n<pre><code>__doc__ # \u51fd\u6570\/\u7c7b\/\u65b9\u6cd5\u7684\u7279\u6b8a\u5c5e\u6027\uff0c\u7528\u6765\u8868\u793a\u6587\u6863\u7684\u5c5e\u6027\n# \u6587\u6863\u5b57\u7b26\u4e32\u4e0d\u80fd\u88ab\u5b50\u7c7b\u7ee7\u627f\uff0e\n<\/code><\/pre>\n<hr>"},{"title":"Tmux","link":"https:\/\/canuxcheng.com\/post\/devops_tmux\/","pubDate":"Sun, 19 Jun 2016 11:17:53 +0000","guid":"https:\/\/canuxcheng.com\/post\/devops_tmux\/","description":"<h1 id=\"tmux\">tmux<\/h1>\n<p>tmux\u662f\u7ec8\u7aef\u590d\u7528\u5de5\u5177\uff0c\u7c7b\u4f3c\u4e8egnu screen\u3002<\/p>\n<p>tmux\u4e09\u4e2a\u57fa\u672c\u6982\u5ff5\uff1a<\/p>\n<ol>\n<li>\n<p>\u4f1a\u8bdd\uff08session\uff09<\/p>\n<\/li>\n<li>\n<p>\u7a97\u53e3\uff08window\uff09<\/p>\n<\/li>\n<li>\n<p>\u9762\u677f\uff08pane\uff09<\/p>\n<\/li>\n<\/ol>\n<p>tmux\u4f7f\u7528c\/s\u67b6\u6784\uff0ctmux\u547d\u4ee4\u542f\u52a8tmux\u670d\u52a1\u5668\uff0c\u4e00\u4e2atmux\u670d\u52a1\u6709\u591a\u4e2asession\uff0c\n\u6bcf\u4e2asession\u5c31\u662ftmux\u7ba1\u7406\u4e0b\u7684\u4f2a\u7ec8\u7aef\u96c6\u5408\uff0c\u4e00\u4e2asession\u6709\u591a\u4e2awindow\u4e0e\u4e4b\u5173\u8054\uff0c\n\u6bcf\u4e2awindow\u5c31\u662f\u4e00\u4e2a\u4f2a\u7ec8\u7aef\uff0c\u5360\u636e\u6574\u4e2a\u5c4f\u5e55\uff0c\u4e00\u4e2awindow\u53ef\u4ee5\u88ab\u5206\u5272\u6210\u591a\u4e2apane\u3002<\/p>\n<hr>\n<h1 id=\"tmux\u5b89\u88c5\u548c\u914d\u7f6e\">tmux\u5b89\u88c5\u548c\u914d\u7f6e<\/h1>\n<p>tmux\u4f9d\u8d56libevent\u548cncurses\u5e93\u3002<\/p>\n<p><a class=\"link\" href=\"http:\/\/libevent.org\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/libevent.org\/<\/a><\/p>\n<pre><code>$ sudo yum install libevent-devel\n<\/code><\/pre>\n<p><a class=\"link\" href=\"http:\/\/invisible-island.net\/ncurses\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/invisible-island.net\/ncurses\/<\/a><\/p>\n<pre><code>$ sudo yum install ncurese-devel\n<\/code><\/pre>\n<p><a class=\"link\" href=\"http:\/\/tmux.github.io\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/tmux.github.io\/<\/a><\/p>\n<pre><code>sudo apt-get install tmux\nsudo yum install tmux\n<\/code><\/pre>\n<p>\u7528\u6237\u914d\u7f6e\u6587\u4ef6\uff1a ~\/.tmux.conf<\/p>\n<p>\u7cfb\u7edf\u914d\u7f6e\u6587\u4ef6\uff1a \/etc\/tmux.conf<\/p>\n<hr>\n<h1 id=\"tmux\u76f8\u5173\u9879\u76ee\">tmux\u76f8\u5173\u9879\u76ee<\/h1>\n<h2 id=\"tpm\">TPM<\/h2>\n<p>Tmux Plugins Manager.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/tmux-plugins\/tpm\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/tmux-plugins\/tpm<\/a><\/p>\n<hr>\n<h1 id=\"tmux\u7528\u6cd5\">tmux\u7528\u6cd5<\/h1>\n<pre><code>man tmux\n<\/code><\/pre>\n<p>\u5f00\u542ftmux\uff1a<\/p>\n<pre><code>tmux\n<\/code><\/pre>\n<p>\u9000\u51fatmux\uff1a<\/p>\n<pre><code>exit\nctrl + d\n<\/code><\/pre>\n<p>\u5217\u51fatmux\u4f1a\u8bdd\uff1a<\/p>\n<pre><code>tmux ls\n<\/code><\/pre>\n<h2 id=\"tmux\u5feb\u6377\u952e\">tmux\u5feb\u6377\u952e<\/h2>\n<p>tmux\u7684prefix\u662fctrl-b<\/p>\n<p>\u6309\u4e0bctrl-b\u7136\u540e\u677e\u5f00\uff0c\u901a\u77e5tmux\u4e0b\u9762\u7684\u6309\u952e\u662f\u5feb\u6377\u952e\u3002<\/p>\n<p>\u67e5\u770b\u6240\u6709\u5feb\u6377\u952e\uff1a<\/p>\n<pre><code>ctrl-b + ?\n<\/code><\/pre>\n<p>\u663e\u793a\u65f6\u95f4\uff1a<\/p>\n<pre><code>ctrl-b + t\n<\/code><\/pre>\n<h2 id=\"session\u64cd\u4f5c\">session\u64cd\u4f5c<\/h2>\n<p>\u4ea4\u4e92\u5f0f\u9009\u62e9\u4e00\u4e2asession:<\/p>\n<pre><code>ctrl-b + s\n<\/code><\/pre>\n<p>\u9009\u62e9\u4e00\u4e2asession\u6765detach\uff1a<\/p>\n<pre><code>ctrl-b + D\n<\/code><\/pre>\n<p>detach\u5f53\u524dsession:<\/p>\n<pre><code>ctrl-b + d\n<\/code><\/pre>\n<p>\u91cd\u547d\u540d\u5f53\u524d\u7684session\uff1a<\/p>\n<pre><code>ctrl-b + $\n<\/code><\/pre>\n<h2 id=\"window\u64cd\u4f5c\">window\u64cd\u4f5c<\/h2>\n<p>\u4ea4\u4e92\u5f0f\u9009\u62e9\u4e00\u4e2awindow:<\/p>\n<pre><code>ctrl-b + w\n<\/code><\/pre>\n<p>\u521b\u5efa\u4e00\u4e2a\u65b0window:<\/p>\n<pre><code>ctrl-b + c\n<\/code><\/pre>\n<p>\u5173\u95ed\u5f53\u524dwindow:<\/p>\n<pre><code>ctrl-b + &amp;\n<\/code><\/pre>\n<p>\u5207\u6362\u5230\u4e0a\u4e00\u4e2awindow:<\/p>\n<pre><code>ctrl-b + p\n<\/code><\/pre>\n<p>\u5207\u6362\u5230\u4e0b\u4e00\u4e2awindow:<\/p>\n<pre><code>ctrl-b + n\n<\/code><\/pre>\n<p>\u79fb\u5230\u4e4b\u524d\u9009\u4e2d\u7684window\uff1a<\/p>\n<pre><code>ctrl-b + l\n<\/code><\/pre>\n<p>\u4f7f\u7528window\u53f7\u5207\u6362window:<\/p>\n<pre><code>ctrl-b + [number]\n<\/code><\/pre>\n<p>\u91cd\u547d\u540dwindow:<\/p>\n<pre><code>ctrl-b + ,\n<\/code><\/pre>\n<h2 id=\"pane\u64cd\u4f5c\">pane\u64cd\u4f5c<\/h2>\n<p>\u6a2a\u5411\u5206\u5c4f:<\/p>\n<pre><code>ctrl-b + %\n<\/code><\/pre>\n<p>\u7eb5\u5411\u5206\u5c4f:<\/p>\n<pre><code>ctrl-b + &quot;\n<\/code><\/pre>\n<p>\u9009\u62e9pane:<\/p>\n<pre><code>ctrl-b + [\u65b9\u5411\u952e]\n<\/code><\/pre>\n<p>\u5173\u95ed\u5f53\u524dpane:<\/p>\n<pre><code>ctrl-b + x\n<\/code><\/pre>\n<p>\u663e\u793apane\u53f7:<\/p>\n<pre><code>ctrl-b + q\n<\/code><\/pre>\n<p>\u628a\u5f53\u524d\u7684pane\u53d8\u6210\u4e00\u4e2awindow\uff1a<\/p>\n<pre><code>ctrl-b + !\n<\/code><\/pre>\n<p>\u79fb\u52a8\u5230\u4e4b\u524d\u7684\u6d3b\u8dc3\u7684pane\uff1a<\/p>\n<pre><code>ctrl-b + ;\n<\/code><\/pre>\n<p>\u9009\u62e9\u5f53\u524dwindow\u7684\u4e0b\u4e00\u4e2apane\uff1a<\/p>\n<pre><code>ctrl-b + o\n<\/code><\/pre>\n<h2 id=\"tmux\u4f7f\u7528\u9f20\u6807\u548c\u7c98\u8d34\u590d\u5236\">tmux\u4f7f\u7528\u9f20\u6807\u548c\u7c98\u8d34\u590d\u5236<\/h2>\n<p>\u590d\u5236\uff1a<\/p>\n<pre><code>shift-\u9f20\u6807\u5de6\u952e\n<\/code><\/pre>\n<p>\u7c98\u8d34\uff1a<\/p>\n<pre><code>shift-\u9f20\u6807\u53f3\u952e\n<\/code><\/pre>\n<p>\u5217\u51fa\u6240\u6709\u7c98\u8d34\u7f13\u51b2\u533a\uff1a<\/p>\n<pre><code>ctrl-b + #\n<\/code><\/pre>\n<p>\u4ea4\u4e92\u5f0f\u9009\u62e9\u4e00\u4e2a\u7f13\u51b2\u533a\u7684\u5185\u5bb9\u7c98\u8d34\uff1a<\/p>\n<pre><code>ctrl-b + =\n<\/code><\/pre>\n<p>\u4f7f\u7528\u590d\u5236\u6a21\u5f0f\uff1a<\/p>\n<pre><code>ctrl-b + [\n<\/code><\/pre>\n<p>\u4f7f\u7528\u7c98\u8d34\u6a21\u5f0f\uff1a<\/p>\n<pre><code>ctrl-b + ]\n<\/code><\/pre>"},{"title":"Monitoring","link":"https:\/\/canuxcheng.com\/post\/devops_monitoring\/","pubDate":"Wed, 08 Jun 2016 09:46:47 +0000","guid":"https:\/\/canuxcheng.com\/post\/devops_monitoring\/","description":"<h1 id=\"monitoring\">Monitoring<\/h1>\n<p>Tranditional monitoring is for Datacenter, like nagios, zabbix.<\/p>\n<p>Modern monitoring is for Cloud and Container.<\/p>\n<p>Modern monitoring based on metrics, logs and tracing.<\/p>\n<p>\u73b0\u4ee3\u7684\u76d1\u63a7\u7cfb\u7edf\u5728DevOps\u7684\u57fa\u7840\u4e0a\uff0c\u9664\u4e86\u4f20\u7edf\u7684metrics\u548clogging\u7684\u91c7\u96c6\uff0c\u8fd8\u9700\u8981tracing\u5e94\u7528\u3002<\/p>\n<hr>\n<h2 id=\"tick-stack\">TICK stack<\/h2>\n<p>telegraf(agent): metrics collector.<\/p>\n<p>influxdb: tsdb.<\/p>\n<p>chronograf: GUI.<\/p>\n<p>kapacitor: alerting.<\/p>\n<hr>\n<h2 id=\"lgtm-stack\">LGTM stack<\/h2>\n<p>loki: log collector.<\/p>\n<p>grafana: visualization.<\/p>\n<p>tempo: tracing.<\/p>\n<p>mimir: TSDB.<\/p>\n<hr>\n<h2 id=\"elk\">ELK<\/h2>\n<p>elasticsearch: \u641c\u7d22\uff0c\u5206\u6790\uff0c\u5b58\u50a8\u6570\u636e\u3002<\/p>\n<p>logstash: \u52a8\u6001\u6570\u636e\u6536\u96c6\u7ba1\u9053\uff0c\u652f\u6301\u53ef\u6269\u5c55\u7684\u63d2\u4ef6\u3002<\/p>\n<p>kibana: \u6570\u636e\u53ef\u89c6\u5316\u3002<\/p>\n<hr>\n<h2 id=\"prometheus\">Prometheus<\/h2>\n<p>prometheus: tsdb.\nalertmanager: alerting.\ncollector: node_exporter, cAdvisor, kube-state-metrics, etc.<\/p>"},{"title":"Tracing","link":"https:\/\/canuxcheng.com\/post\/devops_tracing\/","pubDate":"Wed, 08 Jun 2016 09:46:47 +0000","guid":"https:\/\/canuxcheng.com\/post\/devops_tracing\/","description":"<h1 id=\"tracing\">Tracing<\/h1>\n<p>APM \u76d1\u63a7\uff0c\u4e5f\u53eb\u5168\u94fe\u8def\u76d1\u63a7\u3002<\/p>\n<h2 id=\"sentry\">sentry<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/getsentry\/sentry\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/getsentry\/sentry<\/a><\/p>\n<h2 id=\"zipkin\">zipkin<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/openzipkin\/zipkin\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/openzipkin\/zipkin<\/a><\/p>\n<h2 id=\"open-telemetry\">open-telemetry<\/h2>\n<p>opentracing\u548copencensus \u5408\u5e76\u6210open-telemetry.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/opentracing\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/opentracing<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/census-instrumentation\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/census-instrumentation<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/open-telemetry\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/open-telemetry<\/a><\/p>\n<h2 id=\"jaeger\">jaeger<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/jaegertracing\/jaeger\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/jaegertracing\/jaeger<\/a><\/p>\n<h2 id=\"tempo\">tempo<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/grafana\/tempo\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/grafana\/tempo<\/a><\/p>"},{"title":"Package","link":"https:\/\/canuxcheng.com\/post\/linux_package\/","pubDate":"Tue, 07 Jun 2016 16:57:45 +0000","guid":"https:\/\/canuxcheng.com\/post\/linux_package\/","description":"<h1 id=\"dpkg\">DPKG<\/h1>\n<p>debian\u7684\u5305\u7ba1\u7406\u673a\u5236\u3002<\/p>\n<hr>\n<h2 id=\"dpkg-1\">dpkg<\/h2>\n<p>dpkg\u7684\u672c\u5730\u524d\u7aef\u5de5\u5177\u3002<\/p>\n<h3 id=\"deb---debian-binary-package-format\">deb - Debian binary package format<\/h3>\n<h3 id=\"dpkg---package-manager-for-debian\">dpkg - package manager for Debian<\/h3>\n<pre><code>dpkg\ndpkg -X .\/xxx.deb xxx # \u5c06deb\u5305\u89e3\u538b\u5230xxx\u76ee\u5f55\ndpkg -e .\/xxx.deb xxx\/DEBIAN # \u5c06control\u4fe1\u606f\u89e3\u538b\ndpkg -l | grep pkg # \u67e5\u770b\u5b89\u88c5\u7684\u5305\n<\/code><\/pre>\n<h3 id=\"dpkg-reconfigure---reconfigure-an-already-installed-package\">dpkg-reconfigure - reconfigure an already installed package<\/h3>\n<pre><code>dpkg-reconfigure\n<\/code><\/pre>\n<h3 id=\"dpkg-deb---debian-package-archive-deb-manipulation-tool\">dpkg-deb - Debian package archive (.deb) manipulation tool<\/h3>\n<p>\u76ee\u5f55\u7ed3\u6784, DEBIAN\/control\u662f\u5fc5\u9700\u7684<\/p>\n<pre><code>|- debian_root\n|- DEBIAN\n|- control\n|- preinst\/preinstallation # \u89e3\u538bdeb\u5305\u4e4b\u524d\u6267\u884c\n|- prerm\/preremove\n|- postinst\/postinstallation # \u89e3\u538b\u5b8c\u6210\u4e4b\u540e\u6267\u884c\uff0c\u901a\u5e38\u7528\u6765\u914d\u7f6e\n|- postrm\/postremove\n|- copyright\n|- changelog\n|- conffiles\n|- etc\n|- init.d\/systemd\n|- &lt;service&gt;\n|- logrotate.d\n|- &lt;service&gt;\n|- user\/local\/...\n|- opt\/...\n<\/code><\/pre>\n<p>control:<\/p>\n<pre><code>Package\nVersion\nDescription\nMaintain:\nSection: utils\/net\/mail\/text\/x11\/...\nPriority: required\/standard\/optional\/extra\/...\nEssential: yes\/no\nArchitecture: i386\/amd64\/...\nSource:\nDepends: # \u8fd0\u884c\u8be5process\u9700\u8981\u7684\u4f9d\u840a, \u53ea\u80fd\u5b89\u88c5\u4e4b\u524d\u5b89\u88c5\u597d\uff0c\u6216\u8005\u7528gdebi\u5b89\u88c5\nPre-Depends:\nRecommends:\nSuggests:\n...\n<\/code><\/pre>\n<p>postrm:<\/p>\n<pre><code>case &quot;$1&quot; in\nremove)\nremove\necho &quot;Remove complete&quot;\n;;\npurge)\npurge\necho &quot;Purge complete&quot;\n;;\nupgrade|failed-upgrade|disappear)\necho &quot;Do nothing&quot;\n;;\nabort-install|abort-upgrade)\necho &quot;Do nothing&quot;\n;;\n*)\necho &quot;$0 called with unknown argument \\`$1'&quot; 1&gt;&amp;2\nexit 1\n;;\nesac\n<\/code><\/pre>\n<p>\u521b\u5efadebian\u5305<\/p>\n<pre><code>$ dpkg-deb -b|--build &lt;directory&gt; [&lt;deb&gt;]\n<\/code><\/pre>\n<p>\u67e5\u770b\u5305\u4fe1\u606f<\/p>\n<pre><code>$ dpkg-deb -I XXX.deb\n<\/code><\/pre>\n<h3 id=\"dpkg-query---a-tool-to-query-the-dpkg-database\">dpkg-query - a tool to query the dpkg database<\/h3>\n<pre><code>dpkg-query\n<\/code><\/pre>\n<hr>\n<h2 id=\"gdebi---simple-tool-to-install-deb-files\">gdebi - Simple tool to install deb files<\/h2>\n<p>dpkg\u7684\u672c\u5730\u524d\u7aef\u5de5\u5177\u3002<\/p>\n<p>\u4f7f\u7528gdebi\u5b89\u88c5deb\u5305\u4f1a\u81ea\u52a8\u89e3\u51b3\u4f9d\u8d56\u95ee\u9898:<\/p>\n<p>\u5b89\u88c5gdebi:<\/p>\n<pre><code>$ sudo apt-get install gdebi-core\n$ sudo apt-get install gdebi-gtk\n$ sudo aptitude install gdebi-core # install gdebi itself\n$ sudo aptitude install gdebi-gtk # install gdebi GUI\n<\/code><\/pre>\n<p>\u4f7f\u7528gdebi:<\/p>\n<pre><code>sudo gdebi XXX.deb # install package\n<\/code><\/pre>\n<hr>\n<h2 id=\"apt---command-line-interface\">apt - command-line interface<\/h2>\n<p>dpkg\u7684\u8fdc\u7a0b\u524d\u7aef\u5de5\u5177\u3002<\/p>\n<p>apt - command-line interface<\/p>\n<pre><code>$ apt install package\n<\/code><\/pre>\n<p>apt-get - APT package handling utility &ndash; command-line interface<\/p>\n<pre><code>$ sudo apt-get option command package\n# command:\ninstall\nremove\npurge\ndownload\nsource\nupdate\n# install\n# \u53ef\u4ee5\u901a\u8fc7apt-cache madison\u67e5\u770bversion\napt-get install &lt;package&gt;=&lt;version&gt;\n# option:\n-d, --download-only\n--print-uris\n-y,--yes,--assume-yes # \u4ea4\u4e92\u65f6\u786e\u8ba4\n-f,--force-yes\n--reinstall\n--allow-unauthenticated\n--allow-downgrades (&gt;= ubuntu1604)\n# \u6253\u5370\u5728\u5f53\u524d\u73af\u5883\u5b89\u88c5\u8be5\u5305\u9700\u8981\u7684\u6240\u6709\u4ee5\u6765\u7684\u4e0b\u8f7d\u8fde\u63a5\u4fe1\u606f\napt-get --print-uris install package\n<\/code><\/pre>\n<p>aptitude - high-level interface to the package manager<\/p>\n<pre><code>$ sudo aptitude install package\n<\/code><\/pre>\n<p>apt-cache - query the APT cache<\/p>\n<pre><code>$ apt-cache showpkg &lt;pkg&gt;\n$ apt-cache showsrc &lt;pkg&gt;\n$ apt-cache search &lt;pkg&gt;\n$ apt-cache madison &lt;pkg&gt; # \u67e5\u770b\u5f53\u524d\u6e90\u53ef\u4ee5\u5b89\u88c5\u7684\u7248\u672c\n$ apt-cache policy &lt;pkg&gt;\n# \u67e5\u770b\u54ea\u4e9b\u5305\u4f9d\u8d56\u8be5\u5305\n$ apt-cache rdepends &lt;pkg&gt;\n# \u67e5\u770b\u8be5\u5305\u4f9d\u8d56\u54ea\u4e9b\u5305\n$ apt-cache depends &lt;pkg&gt;\n# \u67e5\u770b\u4f9d\u8d56\uff0c\u3000\u4ee5\u53ca\u4f9d\u8d56\u7684\u4f9d\u8d56\n$ apt-cache --recurse depends &lt;pkg&gt;\n<\/code><\/pre>\n<hr>\n<h1 id=\"rpm\">RPM<\/h1>\n<p>redhat\u7684\u5305\u7ba1\u7406\u673a\u5236\u3002<\/p>\n<h2 id=\"rpm-1\">rpm<\/h2>\n<p>rpm\u7684\u672c\u5730\u524d\u7aef\u5de5\u5177\u3002<\/p>\n<p>rpm - RPM Package Manager<\/p>\n<h2 id=\"yum\">yum<\/h2>\n<p>rpm\u7684\u8fdc\u7a0b\u524d\u7aef\u5de5\u5177\u3002<\/p>\n<p>yum - redirecting to DNF Command Reference<\/p>\n<hr>\n<h1 id=\"zypper\">zypper<\/h1>\n<p>suse\u7684\u5305\u7ba1\u7406\u673a\u5236\u3002<\/p>\n<hr>\n<h1 id=\"alien\">Alien<\/h1>\n<blockquote>\n<p>alien is a program that converts between Red Hat rpm, Debian deb, Stampede slp, Slackware tgz, and Solaris pkg file formats.<\/p>\n<\/blockquote>\n<h1 id=\"gbp\">gbp<\/h1>\n<p>\u901a\u8fc7git\u6765\u7ba1\u7406deb\u6216rpm\u5305\uff0e<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/agx\/git-buildpackage\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/agx\/git-buildpackage<\/a><\/p>\n<pre><code>$sudo -E pip install gbp\n<\/code><\/pre>\n<h1 id=\"fpm\">fpm<\/h1>\n<p>\u901a\u8fc7fpm\u6765\u521b\u5efadeb\/rpm\u5305<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/jordansissel\/fpm\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/jordansissel\/fpm<\/a><\/p>\n<hr>\n<h1 id=\"patch\">patch<\/h1>"},{"title":"Oracle","link":"https:\/\/canuxcheng.com\/post\/oracle\/","pubDate":"Wed, 01 Jun 2016 22:40:22 +0000","guid":"https:\/\/canuxcheng.com\/post\/oracle\/","description":"<h1 id=\"oracle\">Oracle<\/h1>\n<p>oracle\u7684GUI\uff1a<\/p>\n<ol>\n<li>oracle sql developer(officer)<\/li>\n<li>pl\/sql<\/li>\n<li>toad<\/li>\n<\/ol>\n<p>oracle\u7684CLI\uff1a<\/p>\n<ol>\n<li>sqlplus<\/li>\n<\/ol>\n<h1 id=\"oracle\u547d\u4ee4\">Oracle\u547d\u4ee4<\/h1>\n<p>sys\u662foracle\u9ed8\u8ba4\u7ba1\u7406\u5458\u6743\u9650<\/p>\n<pre><code>$ sqlplus \/ as sysdba\n<\/code><\/pre>\n<p>system\u662foracle\u7684\u9ed8\u8ba4\u6700\u9ad8\u6743\u9650\uff0c\u9ed8\u8ba4\u5bc6\u7801\u662fmanager\uff0c\u9700\u8981sys\u6388\u6743\u624d\u80fd\u767b\u9646<\/p>\n<pre><code>$ sqlplus \/ as sysdba\n&gt; alter user system account unlock;\n&gt; alter user system identified by manager;\n&gt; conn system\/manager\n<\/code><\/pre>\n<p>scott\u662foracle\u7684\u9ed8\u70ed\u4f60\u7684\u666e\u901a\u7528\u6237\uff0c\u9ed8\u8ba4\u5bc6\u7801\u662ftiger\uff0c\u9700\u8981sys\u6388\u6743\u624d\u80fd\u767b\u9646<\/p>\n<pre><code>$ sqlplus \/ as sysdba\n&gt; alter user scott account unlock;\n&gt; alter user scott identified by tiger;\n&gt; conn scott\/tiger\n<\/code><\/pre>\n<p>\u672c\u5730\u547d\u4ee4\u884c\u6267\u884csql\u8bed\u53e5\uff1a<\/p>\n<pre><code>$ &lt;sql query&gt; | &lt;sqlplus&gt; &lt;db user&gt;\/&lt;db password&gt;@&lt;db sid&gt; | sudo ORACLE_HOME=&lt;oracle home&gt; -i -u &lt;oracle user&gt;\n<\/code><\/pre>\n<p>dbsnmp\u662foracle\u7684\u7528\u6237\u667a\u80fd\u4ee3\u7406\u7528\u6237\uff0c\u7528\u6765\u76d1\u63a7\u548c\u7ba1\u7406\u6570\u636e\u5e93\u76f8\u5173\u6027\u80fd\u3002<\/p>\n<p>sysman\u662foracle\u7684\u6570\u636e\u5e93\u7528\u6237EM\u7ba1\u7406\u7528\u6237\u3002<\/p>\n<p>\u76d1\u542c\u7ba1\u7406\uff1a<\/p>\n<pre><code>su - oracle\nlsnrctl start\nlsnrctl stop\nlsnrctl status\n<\/code><\/pre>\n<h1 id=\"cli\">CLI<\/h1>\n<p>\u5148\u7528sqlplus\u547d\u4ee4\u8fdb\u5165oracle\u7684\u547d\u4ee4\u884c\uff0e<\/p>\n<pre><code>help index\n? index\n<\/code><\/pre>\n<p>\u67e5\u770b\u547d\u4ee4\u5e2e\u52a9\u4fe1\u606f\uff1a<\/p>\n<pre><code>help &lt;command&gt;\n<\/code><\/pre>\n<p>\u767b\u9646\u548c\u9000\u51fasqlplus\uff1a<\/p>\n<pre><code>sqlplus\nexit\/quit\n<\/code><\/pre>\n<p>\u8c03\u7528sql\u8bed\u53e5\uff1a<\/p>\n<pre><code>@\n<\/code><\/pre>\n<p>\u4e0d\u9000\u51fasqlplus\u6267\u884cshell\u547d\u4ee4\uff1a<\/p>\n<pre><code>host\n<\/code><\/pre>\n<p>\u7528\u6237\u767b\u9646\u548c\u9000\u51fa\uff1a<\/p>\n<pre><code>connect\/conn &lt;username&gt;\/&lt;password&gt;\ndisconnect\n<\/code><\/pre>\n<p>\u6e05\u5c4f\uff1a<\/p>\n<pre><code>clear\n! clear\nclear scr\n<\/code><\/pre>\n<p>\u4fee\u6539\u5bc6\u7801\uff1a<\/p>\n<pre><code>password\n<\/code><\/pre>\n<p>\u67e5\u770b\u53d8\u91cf\uff1a<\/p>\n<pre><code>show\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u6570\u636e\u7c7b\u578b\">\u6570\u636e\u7c7b\u578b<\/h1>\n<hr>\n<h1 id=\"\u51fd\u6570\">\u51fd\u6570<\/h1>\n<p>isnull\u51fd\u6570:<\/p>\n<p>\u3000\u3000\u3000\u3000NVL(column, 0) column\u4e3anull\u51fd\u6570\u8fd4\u56de0<\/p>\n<hr>\n<h1 id=\"sql\">SQL<\/h1>\n<p>\u521b\u5efa\u7528\u6237\uff1a<\/p>\n<pre><code>CREATE USER &lt;username&gt; IDENTIFIED BY &lt;password&gt;;\n<\/code><\/pre>\n<p>\u7528\u6237\u6388\u6743\uff1a<\/p>\n<pre><code>GRANT DBA TO &lt;username&gt;;\nGRANT UNLIMITED TABLESPACE TO &lt;username&gt;;\nGRANT SELECT ANY TABLE TO &lt;username&gt;;\nGRANT SELECT ANY DICTIONARY TO &lt;username&gt;;\n<\/code><\/pre>\n<p>\u5e38\u7528\u67e5\u8be2\uff1a<\/p>\n<pre><code>SELECT * FROM global_name; \u67e5\u770b\u9ed8\u8ba4\u6570\u636e\u5e93\nSELECT * FROM dba_tables; DBA\u6743\u9650\u67e5\u8be2\u6570\u636e\u6240\u6709\u8868\nSELECT * FROM all_users; \u67e5\u770b\u6240\u6709\u7528\u6237\nSELECT username FROM dba_users; \u67e5\u770b\u6240\u6709DBA\u7528\u6237\nSELECT user FROM dual; \u67e5\u770b\u5f53\u524d\u767b\u9646\u7528\u6237\nSELECT * FROM user_tables; \u67e5\u8be2\u5f53\u524d\u7528\u6237\u6709\u54ea\u4e9b\u8868\nSELECT * FROM all_tables; \u67e5\u8be2\u5f53\u524d\u7528\u6237\u53ef\u4ee5\u8bbf\u95ee\u7684\u6240\u6709\u8868\nSELECT banner FROM sys.v_$version; \u67e5\u8be2\u6570\u636e\u5e93\u7248\u672c\nSELECT count(*) FROM v$version; \u67e5\u8be2oracle\u8fde\u63a5\u6570\nSELECT count(*) FROM v$version WHERE STATUS = 'ACTIVE'; \u67e5\u8be2oracle\u5e76\u53d1\u8fde\u63a5\u6570\nALTER system SET processes = &lt;number&gt; scope = spfile; \u4fee\u6539\u6570\u636e\u5e93\u5141\u8bb8\u6700\u5927\u8fde\u63a5\u6570\nSELECT value FROM v$parmeter WHERE name = 'processes'; \u67e5\u8be2\u6570\u636e\u5e93\u5141\u8bb8\u6700\u5927\u8fde\u63a5\u6570\nSELECT value FROM v$parmeter WHERE name = 'open_cursor'; \u67e5\u8be2\u6570\u636e\u5e93\u5141\u8bb8\u6700\u5927\u6e38\u6807\u6570\n<\/code><\/pre>\n<hr>\n<h1 id=\"python\">python<\/h1>\n<h2 id=\"cx_oracle\">cx_Oracle<\/h2>\n<p><a class=\"link\" href=\"http:\/\/cx-oracle.sourceforge.net\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/cx-oracle.sourceforge.net\/<\/a><\/p>\n<p>\u9700\u8981\u5b89\u88c5oracle\u6570\u636e\u5e93\u6216\u8005oracle instant client\u5e76\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<p>\u53c2\u8003oracle\u7f51\u7ad9\u4e0b\u8f7d\u5b89\u88c5\u914d\u7f6eoracle instant client<\/p>\n<p><a class=\"link\" href=\"http:\/\/www.oracle.com\/technetwork\/topics\/linuxx86-64soft-092277.html\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.oracle.com\/technetwork\/topics\/linuxx86-64soft-092277.html<\/a><\/p>\n<pre><code>import cx_Oracle\n<\/code><\/pre>\n<hr>"},{"title":"SQL","link":"https:\/\/canuxcheng.com\/post\/sql\/","pubDate":"Wed, 25 May 2016 22:06:13 +0000","guid":"https:\/\/canuxcheng.com\/post\/sql\/","description":"<h1 id=\"sql\">SQL<\/h1>\n<p>sql\u662f\u7ed3\u6784\u5316\u67e5\u8be2\u8bed\u8a00\u3002<\/p>\n<p>sql\u662f\u4e00\u79cd\u6807\u51c6\uff0c\u51e0\u4e4e\u6240\u6709\u5173\u7cfb\u578b\u6570\u636e\u5e93\u90fd\u9075\u5b88\u3002<\/p>\n<p>\u4f46\u662f\u4e0d\u540c\u7684\u6570\u636e\u5e93\u53c8\u6709\u81ea\u5df1\u7684\u6269\u5c55\u3002<\/p>\n<p>SQL\u5206\u4e3a\u4e24\u90e8\u5206\uff0cDML\u548cDDL\u3002<\/p>\n<p>SQL\u5927\u5c0f\u5199\u654f\u611f\uff0c\u6587\u672c\u4f7f\u7528\u5355\u5f15\u53f7\uff0c\u6570\u503c\u4e0d\u9700\u8981\u5f15\u53f7\u3002<\/p>\n<h1 id=\"sql\u8bed\u6cd5\">sql\u8bed\u6cd5<\/h1>\n<p>sql\u6ce8\u91ca:<\/p>\n<pre><code># \u591a\u884c\u6ce8\u91ca\n\/*\ncomment multi lines\nin a sql file.\n*\/\n# \u5355\u884c\u6ce8\u91ca\n\/* comment single line *\/\n# \u5355\u884c\u6ce8\u91ca\u8fd8\u53ef\u4ee5\u76f4\u63a5\u7528 -- \u8868\u793a\nselect * from table -- where condition;\n-- select * from table where condition;\n<\/code><\/pre>\n<hr>\n<h1 id=\"ddl\">DDL<\/h1>\n<p>DDL: \u6570\u636e\u5b9a\u4e49\u8bed\u8a00<\/p>\n<h2 id=\"create\">create<\/h2>\n<p>\u521b\u5efa\u6570\u636e\u5e93\uff1a<\/p>\n<pre><code>CREATE DATABASE database_name;\n<\/code><\/pre>\n<p>\u5efa\u8868\uff1a<\/p>\n<pre><code>CREATE TABLE table(\ncolumn1 type1,\ncolumn2 type2,\n...\n);\n<\/code><\/pre>\n<p>create\u4e5f\u53ef\u4ee5\u7528\u6765\u521b\u5efa\u7d22\u5f15\u548c\u89c6\u56fe\uff0e<\/p>\n<h2 id=\"drop\">drop<\/h2>\n<p>\u5220\u9664\u6570\u636e\u5e93\uff1a<\/p>\n<pre><code>DROP DATABASE database_name;\n<\/code><\/pre>\n<p>\u5220\u8868\uff1a<\/p>\n<pre><code>DROP TABLE table;\n# \u4ec5\u4ec5\u5220\u9664\u8868\u4e2d\u7684\u6570\u636e\uff0c\u4fdd\u7559\u8868\nTRUNCATE TABLE table;\n<\/code><\/pre>\n<p>drop\u4e5f\u53ef\u4ee5\u7528\u6765\u5220\u9664\u7d22\u5f15\u548c\u89c6\u56fe\uff0e<\/p>\n<h2 id=\"alter\">alter<\/h2>\n<p>\u53d8\u66f4\u8868\uff1a<\/p>\n<pre><code># \u6dfb\u52a0\u5217\nALTER TABLE table ADD COLUMN column type;\n# \u5220\u9664\u5217\nALTER TABLE table DROP COLUMN column;\n# \u6539\u53d8\u5217\u7684\u6570\u636e\u7c7b\u578b\n# sql server\nALTER TABLE table ALTER COLUMN column type;\n# mysql\nALTER TABLE table MODIFY COLUMN column type;\n# mysql\/oracle\nALTER TABLE table MODIFY column type;\n<\/code><\/pre>\n<hr>\n<h1 id=\"dml\">DML<\/h1>\n<p>DML: \u6570\u636e\u64cd\u4f5c\u8bed\u8a00<\/p>\n<h2 id=\"select\">select<\/h2>\n<p>\u67e5\u8be2\u64cd\u4f5c:<\/p>\n<pre><code>SELECT * FROM table;\n# \u5355\u8868\u67e5\u8be2\nSELECT column FROM table;\n# \u591a\u8868\u67e5\u8be2\nSELECT table1.column1, table2.column2 FROM table1, table2;\n<\/code><\/pre>\n<p>where\u5b50\u53e5\u9009\u53d6\u6570\u636e\uff1a<\/p>\n<pre><code>SELECT column FROM table WHERE condition;\n<\/code><\/pre>\n<p>\u5f15\u53f7\u7684\u4f7f\u7528\uff1a<\/p>\n<pre><code># \u6587\u672c\u4f7f\u7528\u5355\u5f15\u53f7\uff0c\u5927\u90e8\u5206\u6570\u636e\u5e93\u4e5f\u63a5\u53d7\u53cc\u5f15\u53f7\nSELECT column FROM table WHERE name='text';\n# \u6570\u5b57\u4e0d\u80fd\u4f7f\u7528\u5f15\u53f7\uff0e\nSELECT column FROM table WHERE id=number;\n<\/code><\/pre>\n<p>where\u5b50\u53e5\u6761\u4ef6\u8868\u8fbe\u5f0f\u53ef\u7528\u7684\u8fd0\u7b97\u7b26\uff1a<\/p>\n<pre><code>=\n&lt;&gt;\n!=\n&gt;\n&lt;\n&gt;=\n&lt;=\nBETWEEN [value1, value2]\nBETWEEN value1 AND value2\nNOT BETWEEN\nIN (value1, value2)\nNOT IN\nIS NULL\nIS NOT NULL\nLIKE\nNOT LIKE\n<\/code><\/pre>\n<p>like\u8fd0\u7b97\u7b26\u7684\u901a\u914d\u7b26\uff1a<\/p>\n<pre><code>% \u66ff\u4ee3\u4e00\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\n_ \u66ff\u4ee3\u4e00\u4e2a\u5b57\u7b26\n[char list] \u5b57\u7b26\u5217\u4e2d\u7684\u4efb\u4f55\u5355\u4e00\u5b57\u7b26\n[^char list] \u4e0d\u5728\u5b57\u7b26\u5217\u4e2d\u7684\u4efb\u4f55\u5355\u4e00\u5b57\u7b26\n[!char list] \u548c\u4e0a\u9762\u4e00\u4e2a\u7b49\u6548\nSELECT * FROM table WHERE name LIKE '[abc]%' # \u4ee5abc\u5f00\u5934\u7684name\n<\/code><\/pre>\n<p>where\u5b50\u53e5\u591a\u4e2a\u6761\u4ef6\u53ef\u4ee5\u4f7f\u7528\u7684\u8fd0\u7b97\u7b26\uff1a<\/p>\n<pre><code>AND \u4e0e\u8fd0\u7b97\nSELECT * FROM table WHERE name='canux' AND id=10;\nOR \u6216\u8fd0\u7b97\nSELECT * FROM table WHERE name='canux' OR id=10;\n<\/code><\/pre>\n<p>order by\u5b50\u53e5\u5bf9\u7ed3\u679c\u8fdb\u884c\u6392\u5e8f,\u9ed8\u8ba4\u5347\u5e8f(ASC)\uff1a<\/p>\n<pre><code># \u9ed8\u8ba4\u5347\u5e8f\nSELECT column, column1 FROM table ORDER BY column;\nSELECT column, column1 FROM table ORDER BY column, column1;\nSELECT column, column1 FROM table ORDER BY column ASC;\n# DESC\u964d\u5e8f\nSELECT column, column1 FROM table ORDER BY column DESC;\nSELECT column, column1 FROM table ORDER BY column DESC, column1 ASC;\n# \u6839\u636e\u7b2c\u51e0\u4e2a\u5b57\u6bb5\u6392\u5e8f\nSELECT column, column1 FROM table ORDER BY number;\n# \u591a\u4e2a\u5b57\u6bb5\u6392\u5e8f\uff0c\u4f18\u5148\u7ea7\u4ece\u524d\u5230\u540e\nSELECT column FROM table ORDER BY column1, column2\nSELECT column FROM table ORDER BY column1 DESC, column2 DESC\n<\/code><\/pre>\n<p>top\u5b50\u53e5\u7528\u4e8e\u89c4\u5b9a\u8981\u8fd4\u56de\u7684\u8bb0\u5f55\u6570\u76ee\uff1a<\/p>\n<pre><code># SQL Server\nSELECT TOP number * FROM table;\n# mysql\nSELECT * FROM table LIMIT number;\n# oracle\nSELECT * FROM table WHERE ROWNUM &lt;= number;\nTop \u4e00\u822c\u9700\u8981order by\n# number\u6700\u5c0f\u768410\u4e2a\nselect top 10 from table order by number\n# number\u6700\u5927\u768410\u4e2a\nselect top 10 from table order by number desc\n<\/code><\/pre>\n<p>group by\u5b50\u53e5\u7528\u6765\u5206\u7ec4\uff0c\u653e\u5728where\u5b50\u53e5\u540e\u9762\u5982\u679c\u6709\u7684\u8bdd:<\/p>\n<p>group by\u4e00\u5b9a\u8981\u7528\u5408\u8ba1\u51fd\u6570(count, max, min, sum, avg, &hellip;).<\/p>\n<pre><code>SELECT column1, aggregate_function(column2) FROM table GROUP BY column1;\n<\/code><\/pre>\n<p>having\u5b50\u53e5\u7528\u6765\u8fc7\u6ee4group by\u7684\u7ed3\u679c(\u76f8\u5f53where)\uff0c\u653e\u5728group by\u5b50\u53e5\u540e\u9762\uff1a<\/p>\n<p>\u56e0\u4e3awhere\u4e0d\u80fd\u548c\u5408\u8ba1\u51fd\u6570\u4e00\u8d77\u4f7f\u7528\uff0c\u6240\u4ee5\u4f7f\u7528having\u5b50\u53e5\uff0e<\/p>\n<pre><code>SELECT column1, aggregate_function(column2) FROM table GROUP BY column1 HAVING aggregate_function(column) condition;\n<\/code><\/pre>\n<p>distinct\u5173\u952e\u5b57\u6392\u9664\u91cd\u590d\uff1a<\/p>\n<pre><code>SELECT DISTINCT column FROM table;\n<\/code><\/pre>\n<p>as\u5173\u952e\u5b57\u6307\u5b9a\u522b\u540d\uff1a<\/p>\n<pre><code># \u6307\u5b9a\u8868\u7684\u522b\u540d\nSELECT alias_table1.column1, alias_table2.column2\nFROM table1 AS alias_table1, table2 AS alias_table2\nWHERE alias_table1.column2='test';\n# \u6307\u5b9a\u5b57\u6bb5\u522b\u540d\nSELECT column1 AS alias1, column2 AS alias2 FROM table;\n<\/code><\/pre>\n<p>\u6267\u884c\u987a\u5e8f\uff1a<\/p>\n<pre><code>from -&gt; where -&gt; group by -&gt; having -&gt; select -&gt; distinct -&gt; union -&gt; order by -&gt; top\n<\/code><\/pre>\n<h2 id=\"insert-into\">insert into<\/h2>\n<p>\u5411\u8868\u683c\u63d2\u5165\u65b0\u7684\u884c\uff1a<\/p>\n<pre><code># \u4e00\u6b21\u63d2\u5165\u5b8c\u6574\u884c\nINSERT INTO table VALUES (value1, value2, ...);\n# \u4e00\u6b21\u63d2\u5165\u591a\u884c\nINSERT INTO table VALUES (val11, val12, ...) (val21, val22, ...) ...\n# \u4e00\u6b21\u63d2\u5165\u4e00\u884c\u7684\u4e00\u90e8\u5206\nINSERT INTO table (column1, column2, ...) VALUES (value1, value2, ...);\n# \u4e00\u6b21\u63d2\u5165\u591a\u884c\u7684\u4e00\u90e8\u5206\nINSERT INTO table (col1, col2, ...) VALUES (val11, val12, ...) (val21, val22, ...)\n<\/code><\/pre>\n<h2 id=\"update-set\">update set<\/h2>\n<p>\u4fee\u6539\u8868\u4e2d\u6570\u636e\uff1a<\/p>\n<pre><code>UPDATE table SET column1=value1 WHERE condition;\n<\/code><\/pre>\n<h2 id=\"delete-from\">delete from<\/h2>\n<p>\u5220\u9664\u8868\u4e2d\u7684\u884c\uff1a<\/p>\n<pre><code>DELETE FROM table WHERE condition;\nDELETE FROM table; # \u5220\u9664\u6240\u6709\u884c\nTRUNCATE TABLE table; # mysql\u6e05\u7a7a\u8868\u7684\u5185\u5bb9\uff0c\u4e0d\u53ef\u6062\u590d\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u51fd\u6570\">\u51fd\u6570<\/h1>\n<p>\u4e0d\u540c\u7684\u6570\u636e\u5e93\u5185\u7f6e\u7684\u90e8\u5206\u51fd\u6570\u4e0d\u540c\uff0e\u4e0b\u9762\u53ea\u5217\u51fa\u5927\u90e8\u5206\u6570\u636e\u5e93\u90fd\u6709\u7684\u51fd\u6570\uff0e<\/p>\n<p>sql\u5185\u7f6e\u4e24\u79cd\u51fd\u6570\uff1a\u5408\u8ba1(aggregate)\u51fd\u6570\u3000\u548c\u3000\u6807\u91cf(scalar)\u51fd\u6570.<\/p>\n<p>sql\u51fd\u6570\u7684\u8bed\u6cd5\uff1a<\/p>\n<pre><code>SELECT FUNCTION(args) FROM table ...;\n<\/code><\/pre>\n<h2 id=\"aggregate-function\">aggregate function<\/h2>\n<pre><code>AVG()\uff1a\u3000\u6c42\u5e73\u5747\u503c\nCOUNT(): \u7edf\u8ba1\u884c\u6570\nFIRST(): \u8fd4\u56de\u6307\u5b9a\u5b57\u6bb5\u4e2d\u7b2c\u4e00\u4e2a\u8bb0\u5f55\u7684\u503c\nLAST():\u3000\u8fd4\u56de\u6307\u5b9a\u5b57\u6bb5\u4e2d\u6700\u540e\u4e00\u4e2a\u8bb0\u5f55\u7684\u503c\nMAX():\u3000\u8fd4\u56de\u4e00\u5217\u4e2d\u7684\u6700\u5927\u503c\nMIN():\u3000\u8fd4\u56de\u4e00\u5217\u4e2d\u7684\u6700\u5c0f\u503c\nSUM():\u3000\u8fd4\u56de\u4e00\u5217\u7684\u548c\n<\/code><\/pre>\n<h2 id=\"scalar-function\">scalar function<\/h2>\n<pre><code>UCASE():\u3000\u628a\u5b57\u6bb5\u7684\u503c\u8f6c\u6362\u4e3a\u5927\u5199\nLCASE():\u3000\u628a\u5b57\u6bb5\u7684\u503c\u8f6c\u6362\u4e3a\u5c0f\u5199\nMID(column, start[, length]):\u3000\u4ece\u6587\u672c\u5b57\u6bb5\u4e2d\u63d0\u53d6\u5b57\u7b26\uff0cstart\u4ece\uff11\u5f00\u59cb\nLEN(): \u8fd4\u56de\u6587\u672c\u5b57\u6bb5\u4e2d\u7684\u957f\u5ea6\nFORMAT(column, format): \u5bf9\u5b57\u6bb5\u8fdb\u884c\u683c\u5f0f\u5316\nROUND(column, decimals): \u628a\u6570\u503c\u5b57\u6bb5\u820d\u5165\u4e3a\u6307\u5b9a\u7684\u5c0f\u6570\u4f4d\u6570\nNOW() \u8fd4\u56de\u5f53\u524d\u7684\u65e5\u671f\u548c\u65f6\u95f4\n<\/code><\/pre>\n<hr>\n<h1 id=\"join\">join<\/h1>\n<p>\u4e3a\u4e86\u4ece\u591a\u4e2a\u8868\u4e2d\u83b7\u53d6\u7ed3\u679c\uff0c\u5c31\u9700\u8981\u7528join.<\/p>\n<h2 id=\"inner-join\">inner join<\/h2>\n<p>inner join\u4e5f\u5c31\u662f\u9ed8\u8ba4\u7684join.<\/p>\n<p>\u5168\u90e8\u5339\u914d\u624d\u8fd4\u56de\uff0e\u76f8\u5f53\u4e8etable1\u548ctable2\u4e0e.<\/p>\n<pre><code># \u4e24\u5f20\u8868\u8fde\u63a5\nSELECT table1.column, table2.column\nFROM table1 INNER JOIN table2\nON table1.column = table2.column;\n# \u4e09\u5f20\u8868\u8fde\u63a5\nSELECT column\nFROM ((table1 INNER JOIN table2 ON table1.column1 = table2.column1) INNER JOIN table3\nON table1.column2 = table3.column2);\n<\/code><\/pre>\n<h2 id=\"left-join\">left join<\/h2>\n<p>\u5de6\u8fde\u63a5\uff0e\u8fd4\u56de\u5de6\u8868table1\u7684\u6240\u6709\u884c\uff0c\u548c\u53f3\u8868table2\u5339\u914d\u7684\u884c<\/p>\n<pre><code>SELECT column\nFROM table1 LEFT JOIN table2\nON table1.column = table2.column;\n<\/code><\/pre>\n<h2 id=\"right-join\">right join<\/h2>\n<p>\u53f3\u8fde\u63a5\uff0c\u8fd4\u56de\u53f3\u8868table2\u7684\u6240\u6709\u884c\uff0c\u548c\u5de6\u8868table1\u5339\u914d\u7684\u884c<\/p>\n<pre><code>SELECT column\nFROM table1 RIGHT JOIN table2\nON table1.column = table2.column;\n<\/code><\/pre>\n<h2 id=\"full-join\">full join<\/h2>\n<p>\u8fd4\u56de\u4e24\u5f20\u8868\u7684\u6240\u6709\u884c\uff0e<\/p>\n<pre><code>SELECT column\nFROM table1 FULL JOIN table2\nON table1.column = table2.column;\n<\/code><\/pre>\n<hr>\n<h1 id=\"union\">union<\/h1>\n<p>union\u64cd\u4f5c\u7b26\u7528\u4e8e\u5408\u5e76\u4e24\u4e2a\u6216\u591a\u4e2aselect\u8bed\u53e5\u7684\u7ed3\u679c\u96c6\uff0e<\/p>\n<p>union\u53ea\u9009\u53d6\u4e0d\u540c\u7684\u503c,\u4e5f\u5c31\u662f\u8bf4table1\u548ctable2\u4e2d\u7684\u76f8\u540ccolumn\u53ea\u51fa\u73b0\u4e00\u6b21\uff0e<\/p>\n<pre><code>SELECT column FROM table1\nUNION\nSELECT column FROM table2;\n<\/code><\/pre>\n<p>union all\u4f1a\u5217\u51fa\u6240\u6709\u7684\u503c\uff0c\u5305\u62ec\u91cd\u590d\u7684\uff0e<\/p>\n<pre><code>SELECT column FROM table1\nUNION ALL\nSELECT column FROM table2;\n<\/code><\/pre>\n<hr>\n<h1 id=\"select-into\">select into<\/h1>\n<p>\u521b\u5efa\u8868\u7684\u5907\u4efd\u590d\u4ef6\uff0e<\/p>\n<p>\u628atable1\u7684\u6240\u6709\u5217\u63d2\u5165\u5230table2:<\/p>\n<pre><code>SELECT * INTO table2 FROM table1 WHERE condition;\n# table2\u5c5e\u4e8e\u53e6\u5916\u4e00\u4e2a\u6570\u636e\u5e93externaldatabase\nSELECT * INTO table2 IN externaldatabase FROM table1 WHERE condition;\n<\/code><\/pre>\n<p>\u628atable1\u7684\u90e8\u5206\u5217\u63d2\u5165\u5230table2:<\/p>\n<pre><code>SELECT column INTO table2 FROM table1 WHERE condition;\n# table2\u5c5e\u4e8e\u53e6\u5916\u4e00\u4e2a\u6570\u636e\u5e93externaldatabase\nSELECT column INTO table2 IN externaldatabase FROM table1 WHERE condition;\n<\/code><\/pre>\n<p>mysql\u9700\u8981\u7528insert into &hellip; select:<\/p>\n<pre><code># \u5982\u679ctable2\u5df2\u7ecf\u5b58\u5728\nINSERT INTO table2 SELECT * FROM table1 WHERE condition;\n# \u5982\u679ctable2\u4e0d\u5b58\u5728\nCREATE TABLE table2 AS SELECT * FROM table1 WHERE condition;\n<\/code><\/pre>\n<hr>\n<h1 id=\"constraints\">constraints<\/h1>\n<p>constraints\u7ea6\u675f\u7528\u4e8e\u9650\u5236\u52a0\u5165\u8868\u7684\u6570\u636e\u7684\u7c7b\u578b\uff0e<\/p>\n<h2 id=\"not-null\">NOT NULL<\/h2>\n<p>not null\u5f3a\u5236\u7ea6\u675f\u5217\u4e0d\u80fd\u63a5\u53d7null\u503c\uff0e<\/p>\n<pre><code>CREATE TABLE tablename (\nid int NOT NULL,\nname varchar(255)\n);\n<\/code><\/pre>\n<h2 id=\"unique\">UNIQUE<\/h2>\n<p>unique\u7ea6\u675f\u552f\u4e00\u6807\u8bc6\u6570\u636e\u5e93\u8868\u4e2d\u7684\u6bcf\u6761\u8bb0\u5f55\uff0e<\/p>\n<p>\u6bcf\u4e2a\u8868\u53ef\u4ee5\u6709\u591a\u4e2aunique\u7ea6\u675f\uff0e<\/p>\n<pre><code># mysql:\nCREATE TABLE table (\nid int NOT NULL,\nname varchar(255),\nUNIQUE (id)\n);\n# sql server\/oracle:\nCREATE TABLE table(\nid int NOT NULL UNIQUE,\nname varchar(255)\n);\n<\/code><\/pre>\n<p>\u7ed9\u7ea6\u675f\u547d\u540d\uff0c\u5e76\u4e14\u6807\u8bb0\u591a\u4e2a\u5217\u5230unique:<\/p>\n<pre><code>CREATE TABLE table (\nid int NOT NULL,\nfirstname varchar(255),\nlastname varchar(255),\nCONSTRAINT constraintname UNIQUE (id, lastname)\n);\n<\/code><\/pre>\n<p>\u7ed9\u5df2\u7ecf\u5b58\u5728\u7684\u8868\u6dfb\u52a0\u7ea6\u675f\uff1a<\/p>\n<pre><code>ALTER TABLE table ADD UNIQUE (id);\n# \u7ed9\u7ea6\u675f\u547d\u540d\uff0c\u5e76\u4e14\u6807\u8bb0\u591a\u4e2a\u5217\u5230unique\nALTER TABLE table ADD CONSTRAINT constraintname UNIQUE (id, lastname);\n<\/code><\/pre>\n<p>\u64a4\u9500\u7ea6\u675f\uff1a<\/p>\n<pre><code># mysql:\nALTER TABLE table DROP INDEX constraintname;\n# sql server\/oracle:\nALTER TABLE table DROP CONSTRAINTNAME constraintname;\n<\/code><\/pre>\n<h2 id=\"primary-key\">PRIMARY KEY<\/h2>\n<p>primary key\u4e3b\u952e\u5fc5\u987b\u5305\u542b\u552f\u4e00\u7684\u503c\uff0c\u4e3b\u952e\u5217\u4e0d\u80fd\u5305\u542bNULL\u503c\uff0e<\/p>\n<p>\u6bcf\u5f20\u8868\u6700\u591a\u53ea\u80fd\u6709\u4e00\u4e2a\u4e3b\u952e\uff0e<\/p>\n<pre><code># mysql:\nCREATE TABLE table (\nid int NOT NULL,\nfirstname varchar(255),\nlastname varchar(255),\nPRIMARY KEY (id)\n);\n# sql server\/oracle:\nCREATE TABLE table (\nid int NOT NULL PRIMARY KEY,\nfirstname varchar(255),\nlastname varchar(255)\n);\n<\/code><\/pre>\n<p>\u7ed9\u4e3b\u952e\u547d\u540d\uff0c\u5e76\u4e14\u6dfb\u52a0\u591a\u4e2a\u5217\u5230primary key:<\/p>\n<pre><code>CREATE TABLE table (\nid int NOT NULL,\nfirstname varchar(255),\nlastname varchar(255),\nCONSTRAINT constraintname PRIMARY KEY (id, lastname)\n);\n<\/code><\/pre>\n<p>\u7ed9\u5df2\u7ecf\u5b58\u5728\u7684\u8868\u6dfb\u52a0\u7ea6\u675f\uff1a<\/p>\n<pre><code>ALTER TABLE table ADD PRIMARY KEY (id);\n# \u7ed9\u7ea6\u675f\u547d\u540d\uff0c\u5e76\u4e14\u6dfb\u52a0\u591a\u4e2a\u5217\u5230\u4e3b\u952e\uff1a\nALTER TABLE table ADD CONSTRAINT constraintname PRIMARY KEY (id, lastname);\n<\/code><\/pre>\n<p>\u64a4\u9500\u7ea6\u675f\uff1a<\/p>\n<pre><code># mysql:\nALTER TABLE table DROP PRIMARY KEY;\n# sql server\/oracle:\nALTER TABLE talbe DROP CONSTRAINT constraintname;\n<\/code><\/pre>\n<h2 id=\"foreign-key\">FOREIGN KEY<\/h2>\n<p>\u4e00\u4e2a\u8868\u4e2d\u7684\u5916\u952e\u6307\u5411\u53e6\u4e00\u4e2a\u8868\u4e2d\u7684\u4e3b\u952e\uff0e<\/p>\n<pre><code># mysql:\nCREATE TABLE table1 (\nid_1 int NOT NULL,\nid_2 int,\nPRIMARY KEY (id_1),\nFOREIGN KEY (id_2) REFERENCES table2(id_2)\n);\n# sql server\/oracle:\nCREATE TABLE table1 (\nid_1 int NOT NULL PRIMARY KEY,\nid_2 int FOREIGN KEY REFERENCES table2(id_2)\n);\n<\/code><\/pre>\n<p>\u7ed9\u5916\u952e\u547d\u540d\uff0c\u5e76\u4e14\u6dfb\u52a0\u591a\u4e2a\u5217\u5230foreign key:<\/p>\n<pre><code>CREATE TABLE table1 (\nid_1 int NOT NULL,\nid_2 int,\nPRIMARY KEY (id_1),\nCONSTRAINT constraintname FOREIGN KEY (id_2) REFERENCES table2(id_2)\n);\n<\/code><\/pre>\n<p>\u7ed9\u5df2\u7ecf\u5b58\u5728\u7684\u8868\u6dfb\u52a0\u7ea6\u675f\uff1a<\/p>\n<pre><code>ALTER TABLE table1 ADD FOREIGN KEY (id_2) REFERENCES table2(id_2);\n# \u7ed9\u5916\u952e\u547d\u540d\uff0c\u5e76\u4e14\u6dfb\u52a0\u591a\u5217\u5230\u5916\u952e\nALTER TABLE table1 ADD CONSTRAINT constraintname FOREIGN KEY (id_2) REFERENCES table2(id_2);\n<\/code><\/pre>\n<p>\u64a4\u9500\u7ea6\u675f\uff1a<\/p>\n<pre><code># mysql:\nALTER TABLE table1 DROP FOREIGN KEY constraintname;\n# sql server\/oracle:\nALTER TABLE table1 DROP CONSTRAINT constraintname;\n<\/code><\/pre>\n<h2 id=\"check\">CHECK<\/h2>\n<p>check\u7528\u4e8e\u9650\u5236\u5217\u4e2d\u7684\u503c\u7684\u8303\u56f4\uff0e<\/p>\n<pre><code># mysql:\nCREATE TABLE table (\nid int NOT NULL,\nfirstname varchar(255),\nlastname varchar(255),\nCHECK (id&gt;0)\n);\n# sql server\/oracle:\nCREATE TABLE table (\nid int NOT NULL CHECK (id&gt;0),\nfirstname varchar(255),\nlastname varchar(255)\n);\n<\/code><\/pre>\n<p>\u7ed9\u7ea6\u675f\u547d\u540d\uff0c\u5e76\u4e14\u6dfb\u52a0\u591a\u4e2a\u5217\u5230\u7ea6\u675f\uff1a<\/p>\n<pre><code>CREATE TABLE table (\nid int NOT NULL,\nfirstname varchar(255),\nlastname varchar(255),\nCONSTRAINT constraintname CHECK (id&gt;0 AND lastname='cheng')\n);\n<\/code><\/pre>\n<p>\u7ed9\u5df2\u7ecf\u5b58\u5728\u7684\u8868\u6dfb\u52a0\u7ea6\u675f\uff1a<\/p>\n<pre><code>ALTER TABLE table ADD CHECK (id&gt;0);\n# \u7ed9\u7ea6\u675f\u547d\u540d\uff0c\u5e76\u4e14\u6dfb\u52a0\u591a\u5217\u5230\u7ea6\u675f\nALTER TABLE table ADD CONSTRAINT constraintname CHECK (id&gt;0 AND lastname='cheng');\n<\/code><\/pre>\n<p>\u64a4\u9500\u7ea6\u675f\uff1a<\/p>\n<pre><code># mysql:\nALTER TABLE table DROP CONSTRAINT constraintname;\n# sql server\/oracle:\nALTER TABLE table DROP CHECK constraintname;\n<\/code><\/pre>\n<h2 id=\"default\">DEFAULT<\/h2>\n<p>default\u7ea6\u675f\u7528\u4e8e\u5411\u5217\u4e2d\u63d2\u5165\u9ed8\u8ba4\u503c\uff0e<\/p>\n<pre><code>CREATE TABLE table (\nid int NOT NULL,\ncountry varcha(255) DEFAULT 'china'\n);\n<\/code><\/pre>\n<p>\u7ed9\u5df2\u7ecf\u5b58\u5728\u7684\u8868\u6dfb\u52a0\u7ea6\u675f\uff1a<\/p>\n<pre><code># mysql\nALTER TABLE table ALTER country SET DEFAULT 'china';\n# sqlserver\/oracle\nALTER TABLE table ALTER COLUMN country SET DEFAULT 'china';\n<\/code><\/pre>\n<p>\u64a4\u9500\u7ea6\u675f\uff1a<\/p>\n<pre><code># mysql:\nALTER TABLE table ALTER country DROP DEFAULT;\n# sql server\/oracle:\nALTER TABLE table ALTER COLUMN country DROP DEFAULT;\n<\/code><\/pre>\n<hr>\n<h1 id=\"increment\">increment<\/h1>\n<p>auto increment\u5728\u6bcf\u6b21\u63d2\u5165\u65b0\u8bb0\u5f55\u65f6\uff0c\u81ea\u52a8\u521b\u5efa\u4e3b\u952e\u5b57\u6bb5\u7684\u503c\uff0e<\/p>\n<pre><code># mysql\u4f7f\u7528auto_increment\nCREATE TABLE table (\nid int NOT NULL AUTO_INCREMENT,\nfirstname varchar(255),\nlastname varchar(255),\nPRIMARY KEY (id)\n);\n# sql server\u4f7f\u7528identity:\nCREATE TABLE table (\nid int PRIMARY KEY IDENTITY;\nfirstname varchar(255),\nlastname varchar(255)\n);\n# oracle\u4f7f\u7528sequence\u5bf9:\nCREATE SEQUENCE sequencename\nMINVALUE 1\nSTART WITH 1\nINCRREMENT BY 1\nCACHE 10\n# \u4f7f\u7528nextval\u51fd\u6570\u83b7\u53d6\u4e0b\u4e00\u4e2a\u503c\uff1a\nINSERT INTO table (id, firstname, lastname) VALUES (sequencename.nextval, 'canux', 'cheng');\n<\/code><\/pre>\n<p>auto increment\u7684\u9ed8\u8ba4\u8d77\u59cb\u503c\u662f1,\u6bcf\u6b21\u63d2\u5165\u4e00\u884c\u9ed8\u8ba4\u52a0\u4e00\uff0c\u53ef\u4ee5\u4fee\u6539\u8d77\u59cb\u503c\uff1a<\/p>\n<pre><code>ALTER TABLE table AUTO_INCREMENT=10;\n<\/code><\/pre>\n<hr>\n<h1 id=\"index\">index<\/h1>\n<p>\u521b\u5efa\u7d22\u5f15\u53ef\u4ee5\u5feb\u901f\u9ad8\u6548\u67e5\u8be2\u6570\u636e\uff0c\u4f46\u662f\u7528\u6237\u65e0\u6cd5\u770b\u5230\u7d22\u5f15\uff0e<\/p>\n<pre><code># \u5728\u8868\u4e2d\u521b\u5efa\u7b80\u5355\u7d22\u5f15\uff0c\u5141\u8bb8\u4f7f\u7528\u91cd\u590d\u7684\u503c:\nCREATE INDEX indexname ON table (column, column1, ...);\n# \u5728\u8868\u4e2d\u521b\u5efa\u552f\u4e00\u7d22\u5f15\uff0c\u4e24\u4e2a\u884c\u4e0d\u80fd\u6709\u76f8\u540c\u7d22\u5f15\u503c:\nCREATE UNIQUE INDEX indexname ON table (column, column1, ...);\n<\/code><\/pre>\n<p>\u5220\u9664\u7d22\u5f15\uff1a<\/p>\n<pre><code># mysql:\nALTER TABLE table DROP INDEX indexname;\n# sql server:\nDROP INDEX table.indexname;\n# oracle:\nDROP INDEX indexname;\n<\/code><\/pre>\n<hr>\n<h1 id=\"view\">view<\/h1>\n<p>\u89c6\u56fe\u662f\u57fa\u4e8esql\u8bed\u53e5\u7684\u7ed3\u679c\u96c6\u7684\u53ef\u89c6\u5316\u7684\u8868\uff1a<\/p>\n<pre><code>CREATE VIEW viewname AS SELECT * FROM table WHERE condition;\n<\/code><\/pre>\n<p>\u66f4\u65b0\u89c6\u56fe\uff1a<\/p>\n<pre><code>CREATE OR REPLACE VIEW viewname AS SELECT column FROM table WHERE condition;\n<\/code><\/pre>\n<p>\u67e5\u8be2\u89c6\u56fe\uff1a<\/p>\n<pre><code>SELECT * FROM viewname;\n<\/code><\/pre>\n<p>\u5220\u9664\u89c6\u56fe\uff1a<\/p>\n<pre><code>DROP VIEW viewname;\n<\/code><\/pre>\n<hr>"},{"title":"Mysql","link":"https:\/\/canuxcheng.com\/post\/mysql\/","pubDate":"Wed, 25 May 2016 12:14:59 +0000","guid":"https:\/\/canuxcheng.com\/post\/mysql\/","description":"<h1 id=\"mysql\">Mysql<\/h1>\n<p>\u5b89\u88c5mysql\u670d\u52a1\u5668<\/p>\n<pre><code>$ sudo apt-get install mysql-server\n$ sudo yum install mysql-community-server\n$ sudo vim \/etc\/mysql\/mysql.conf.d\/mysqld.cnf\n# \u6ce8\u610fmysql\u7684\/etc\/mysql\/my.cnf\u548c\u76f8\u5173\u6587\u4ef6\u5982\u679c\u8bbe\u7f6e\u4e86bind-address = 127.0.0.1\u5c31\u65e0\u6cd5\u8fdc\u7a0b\u8bbf\u95ee\uff0c\u9700\u8981\u6ce8\u91ca\u6389\uff0e\n<\/code><\/pre>\n<p>\u5b89\u88c5mysql\u5ba2\u6237\u7aef<\/p>\n<pre><code>$ sudo apt-get install mysql-client\n$ sudo yum install mysql-community-client\n<\/code><\/pre>\n<p>\u5b89\u88c5\u5f00\u53d1\u5de5\u5177\uff1a<\/p>\n<pre><code>$ sudo apt-get install libmysqlclient-dev\n<\/code><\/pre>\n<p>CLI\u5de5\u5177\uff1a mysql<\/p>\n<p>GUI\u5de5\u5177\uff1a mysql workbench<\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u9ed8\u8ba4\u7684\u6570\u636e\u5e93\u662f mysql\u3002<\/p>\n<p>mysqld\u7684\u9ed8\u8ba4\u7aef\u53e3\u662f3306.<\/p>\n<hr>\n<h1 id=\"mysql\u547d\u4ee4\">mysql\u547d\u4ee4<\/h1>\n<p>tips: \u7528\u6237\u540d\u5bc6\u7801\u6709\u7279\u6b8a\u5b57\u7b26\u7528\u5f15\u53f7.<\/p>\n<pre><code>$ mysql [OPTIONS] [database]\n<\/code><\/pre>\n<p>\u521d\u59cb\u5316\u65f6\u9700\u8981\u7528root\u7528\u6237\u8fdb\u5165mysql\u547d\u4ee4\u884c<\/p>\n<pre><code>$ mysql -uroot -p\n$ mysql -h&lt;host&gt; -P&lt;port&gt; -uroot -p&lt;password&gt;\n<\/code><\/pre>\n<p>\u521b\u5efa\u7528\u6237\u540e\u7528\u5176\u5b83\u7528\u6237\u64cd\u4f5c\uff1a<\/p>\n<pre><code>$ mysql -u&lt;user&gt; -p\n<\/code><\/pre>\n<p>\u672c\u5730\u6267\u884csql\u8bed\u53e5\u6216mysql\u5ba2\u6237\u7aef\u547d\u4ee4:<\/p>\n<pre><code>$ mysql -u&lt;username&gt; -p&lt;password&gt; &lt;database&gt; -e\/--execute &lt;sql query&gt;\n$ mysql -u&lt;username&gt; -p&lt;password&gt; &lt;database&gt; &lt; test.sql\n<\/code><\/pre>\n<p>\u8fdc\u7a0b\u6267\u884csql\u8bed\u53e5\u6216mysql\u5ba2\u6237\u7aef\u547d\u4ee4:<\/p>\n<pre><code>$ mysql -h&lt;host&gt; -P&lt;port&gt; -u&lt;username&gt; -p&lt;password&gt; &lt;database&gt; -e\/--execute &lt;sql query&gt;\n$ mysql -h&lt;host&gt; -P&lt;port&gt; -u&lt;username&gt; -p&lt;password&gt; &lt;database&gt; &lt; test.sql\n<\/code><\/pre>\n<p>\u542f\u7528&rsquo;load data local&rsquo;\u547d\u4ee4\uff1a<\/p>\n<pre><code># \u4ea4\u4e92\u5f0f\n$ mysql --local-infile=1 -uroot -ppassword\n# \u975e\u4ea4\u4e92\u5f0f\n$ mysql --local-infile=1 -uroot -pchengca w3c -e &quot;LOAD DATA LOCAL INFILE '\/home\/user\/customers.txt' INTO TABLE Customers COLUMNS TERMINATED BY '\\t' LINES TERMINATED BY '\\n';&quot;\n<\/code><\/pre>\n<p>\u5bfc\u51fa\u6570\u636e\u547d\u4ee4:<\/p>\n<pre><code>$ mysqldump -u&lt;username&gt; -p&lt;password&gt; &lt;databasename&gt; &gt; dump.sql\n<\/code><\/pre>\n<p>mycli:<\/p>\n<p>A command line client for MySQL that can do auto-completion and syntax highlighting.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/dbcli\/mycli\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/dbcli\/mycli<\/a><\/p>\n<pre><code>$ pip install -U mycli\n<\/code><\/pre>\n<hr>\n<h1 id=\"cli\">CLI<\/h1>\n<p>\u5148\u7528mysql\u547d\u4ee4\u8fdb\u5165mysql\u7684\u547d\u4ee4\u884c\u3002<\/p>\n<pre><code>? (\\?) Synonym for help.\nhelp (\\h) Display this help.\nexit (\\q) Exit mysql. Same as quit.\nquit (\\q) Quit mysql.\nclear (\\c) Clear the current input statement.\nconnect (\\r) Reconnect to the server. Optional arguments are db and host.\ndelimiter (\\d) Set statement delimiter.\nedit (\\e) Edit command with \\$EDITOR.\nego (\\G) Send command to mysql server, display result vertically.\ngo (\\g) Send command to mysql server.\nnopager (\\n) Disable pager, print to stdout.\nnotee (\\t) Don't write into outfile.\npager (\\P) Set PAGER [to_pager]. Print the query results via PAGER.\nprint (\\p) Print current command.\nprompt (\\R) Change your mysql prompt.\nrehash (\\#) Rebuild completion hash.\nsource (\\.) Execute an SQL script file. Takes a file name as an argument.\nmysql&gt; source \/path\/to\/dump.sql # \u4ecesql\u5bfc\u5165\u6570\u636e\nstatus (\\s) Get status information from the server.\nsystem (\\!) Execute a system shell command.\ntee (\\T) Set outfile [to_outfile]. Append everything into given outfile.\nuse (\\u) Use another database. Takes database name as argument.\nmysql&gt; use database # \u5207\u6362\u5230\u6570\u636e\u5e93\ncharset (\\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.\nwarnings (\\W) Show warnings after every statement.\nnowarning (\\w) Don't show warnings after every statement.\n<\/code><\/pre>\n<p>\u5176\u5b83\u53ef\u4ee5\u5728mysql\u5ba2\u6237\u7aef\u6267\u884c\u7684\u547d\u4ee4\uff1a<\/p>\n<pre><code># \u4ece\u672c\u5730\u4e00\u4e2a\u6587\u4ef6\u5bfc\u5165\u6570\u636e\uff0c\u5217\u5206\u9694\u7b26\u4e3a\\t,\u884c\u5206\u9694\u7b26\u4e3a\\n\nLOAD DATA LOCAL INFILE '\/home\/user\/customers.txt' INTO TABLE Customers COLUMNS TERMINATED BY '\\t' LINES TERMINATED BY '\\n';\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u6570\u636e\u7c7b\u578b\">\u6570\u636e\u7c7b\u578b<\/h1>\n<hr>\n<h1 id=\"\u51fd\u6570\u548c\u8fd0\u7b97\u7b26\">\u51fd\u6570\u548c\u8fd0\u7b97\u7b26<\/h1>\n<p>date and time\uff1a<\/p>\n<p><a class=\"link\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/date-and-time-functions.html\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/date-and-time-functions.html<\/a><\/p>\n<pre><code>NOW() \/\/ '2018-11-18 16:00:28'\nUTC_TIMESTAMP() \/\/ '2018-11-18 08:01:04'\nCURDATE() \/\/ '2018-11-18'\nUTC_DATE() \/\/ '2018-11-18'\nCURTIME() \/\/ '16:02:18'\nUTC_TIME() \/\/ '08:03:36'\nUNIX_TIMESTAMP() \/\/ '1542528051'\nDATE() \/\/ '2021-1-12'\nTIME() \/\/ '14:28:00'\nDATEDIFF()\ndate_format(column, '%Y-%m-%d')\n<\/code><\/pre>\n<p>control flow:\uff1a<\/p>\n<pre><code>CASE\nIF()\nIFNULL(column, 0)\nNULLIF()\n<\/code><\/pre>\n<p>comparison:<\/p>\n<pre><code>COALESCE(column, 0)\nISNULL()\nIS NULL\nIN()\nNOT IN()\n<\/code><\/pre>\n<hr>\n<h1 id=\"sql\">SQL<\/h1>\n<p>\u6ce8\u610f\uff1ahostname \u6307\u5b9a\u80fd\u8fde\u63a5\u7684server\uff0c%\u8868\u793a\u4efb\u4f55server\uff0e<\/p>\n<p>\u67e5\u770b\u7248\u672c\uff1a<\/p>\n<pre><code>SELECT VERSION();\n<\/code><\/pre>\n<p>\u67e5\u770b\u6240\u6709\u7528\u6237\uff1a<\/p>\n<pre><code>SELECT DISTINCT(USER) FROM mysql.user;\nSELECT user,host,plugin FROM mysql.user;\n<\/code><\/pre>\n<p>\u67e5\u770b\u5f53\u524d\u7528\u6237\uff1a<\/p>\n<pre><code>SELECT USER();\n<\/code><\/pre>\n<p>\u521b\u5efa\/\u5220\u9664\u7528\u6237\uff1a<\/p>\n<pre><code>CREATE USER 'username'@'%' IDENTIFIED BY 'password';\nDROP USER 'username'@'%';\n<\/code><\/pre>\n<p>\u8bbe\u7f6e\u548c\u66f4\u6539\u5bc6\u7801\uff1a<\/p>\n<pre><code>UPDATE mysql.user SET PASSWORD('password') WHRER USER='username' AND HOST='hostname';\n<\/code><\/pre>\n<p>\u67e5\u770b\u6240\u6709\u6570\u636e\u5e93\uff1a<\/p>\n<pre><code>show databases;\n<\/code><\/pre>\n<p>\u67e5\u770b\u5f53\u524d\u6570\u636e\u5e93\uff1a<\/p>\n<pre><code>SELECT DATABASE();\n<\/code><\/pre>\n<p>\u521b\u5efa\/\u5220\u9664\u6570\u636e\u5e93\uff1a<\/p>\n<pre><code>CREATE DATABASE databasename;\nDROP DATABASE databasename;\n<\/code><\/pre>\n<p>\u6307\u5b9a\u6570\u636e\u5e93\u5bf9\u7528\u6237\u6388\u6743\uff1a<\/p>\n<pre><code>GRANT ALL PRIVILEGES ON databasename.* TO 'username'@'%';\nFLUSH PRIVILEGES;\n<\/code><\/pre>\n<p>\u67e5\u770b\u6743\u9650\uff1a<\/p>\n<pre><code>SHOW GRANTS FOR 'username'@'%';\n<\/code><\/pre>\n<p>\u4f7f\u7528\u6570\u636e\u5e93\uff1a<\/p>\n<pre><code>use databasename\n<\/code><\/pre>\n<p>\u67e5\u770b\u6240\u6709\u8868\uff1a<\/p>\n<pre><code>show tables;\n<\/code><\/pre>\n<p>\u67e5\u770b\u8868\u7ed3\u6784\uff1a<\/p>\n<pre><code>desc tablename;\n<\/code><\/pre>\n<p>\u6b63\u5219\uff1a<\/p>\n<pre><code>\/\/ \u7c7b\u4f3clike\uff0c\u7279\u6b8a\u5b57\u7b26\u8981\u7528\u53cc\u53cd\u659c\u6760\u8f6c\u4e49.\nselect * from tablename where colume REGEXP '...'\n<\/code><\/pre>\n<p>\u67e5\u770b\u7cfb\u7edf\u914d\u7f6e:<\/p>\n<pre><code>show variables like 'version';\nselect @@version;\n<\/code><\/pre>\n<hr>\n<h1 id=\"issue\">Issue<\/h1>\n<ol>\n<li>mysql8 workbench \u8fde\u4e0d\u4e0a\u7684\u95ee\u9898 :<\/li>\n<\/ol>\n<p>issue:<\/p>\n<pre><code>authentication plugin 'caching_sha2_password' cannot be loaded: the specified module could not be found\u3002\n<\/code><\/pre>\n<p>fix\uff1a<\/p>\n<pre><code>mysql8 \u5f00\u59cb\u9ed8\u8ba4\u6388\u6743\u63d2\u4ef6\u6539\u6210caching_sha2_password.\n\u53ef\u4ee5\u6307\u5b9a\u4e3a--default-authentication-plugin=mysql_native_password\uff0c\nalter user 'sandbox'@'%' identified with mysql_native_password by 'password';\n<\/code><\/pre>\n<ol start=\"2\">\n<li>max_commection \u95ee\u9898:<\/li>\n<\/ol>\n<p>issue:<\/p>\n<pre><code>\u5f53\u8fde\u63a5\u6c60\u8fde\u63a5\u6570\u91cf\u8d85\u8fc7\u6700\u5927\u8fde\u63a5\u6570\u5c31\u65e0\u6cd5\u518d\u5efa\u7acb\u8fde\u63a5\n<\/code><\/pre>\n<p>fix:<\/p>\n<pre><code>show processlist;\nshow variables like 'max_connections';\nset global max_connections = 2048;\n<\/code><\/pre>\n<ol start=\"3\">\n<li>1153, &ldquo;Got a packet bigger than &lsquo;max_allowed_packet&rsquo; bytes&rdquo;<\/li>\n<\/ol>\n<p>issue:<\/p>\n<pre><code>\u8bf7\u6c42\u6570\u636e\u8d85\u8fc7\u9650\u5236\uff0c\u9ed8\u8ba4\u53ef\u80fd\u662f4M\n<\/code><\/pre>\n<p>fix:<\/p>\n<pre><code>\/\/ \u8bbe\u7f6e\u6210\u6700\u5927\u503c1G\nselect @@max_allowed_packet;\nSET GLOBAL max_allowed_packet = 1024 * 1024 * 1024;\n<\/code><\/pre>\n<ol start=\"4\">\n<li>1205, &lsquo;Lock wait timeout exceeded; try restarting transaction&rsquo;<\/li>\n<\/ol>\n<p>issue:<\/p>\n<pre><code>\u540e\u63d0\u4ea4\u7684\u4e8b\u52a1\u7b49\u5f85\u524d\u9762\u5904\u7406\u7684\u4e8b\u52a1\u91ca\u653e\u9501\uff0c\u4f46\u662f\u5728\u7b49\u5f85\u7684\u65f6\u5019\u8d85\u8fc7\u4e86mysql\u7684\u9501\u7b49\u5f85\u65f6\n<\/code><\/pre>\n<p>fix:<\/p>\n<pre><code>\/\/ \u9996\u5148\u4f18\u5316\u8868\u7d22\u5f15.\nselect @@innodb_lock_wait_timeout\nset global innodb_lock_wait_timeout=100;\n<\/code><\/pre>\n<p>5.\u00a01840 (HY000) at line 24: @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_EXECUTED is empty.<\/p>\n<p>fix:<\/p>\n<pre><code>&quot;mysql&gt; reset master&quot;.\n<\/code><\/pre>\n<hr>\n<h1 id=\"monitoring\">Monitoring<\/h1>"},{"title":"Builtins","link":"https:\/\/canuxcheng.com\/post\/ps_builtins\/","pubDate":"Tue, 24 May 2016 10:44:44 +0000","guid":"https:\/\/canuxcheng.com\/post\/ps_builtins\/","description":"<h1 id=\"get-help\u548chelp\">Get-Help\u548cHelp:<\/h1>\n<p>get-help\u67e5\u770b\u5e2e\u52a9\u4fe1\u606f,help\u5206\u9875\u67e5\u770b\u5e2e\u52a9\u4fe1\u606f\uff0cman\u662fhelp\u7684\u522b\u540d<\/p>\n<p>\u547d\u4ee4\u8bf4\u660e\uff1a<\/p>\n<pre><code>Get-Help\nHelp\n<\/code><\/pre>\n<p>\u67e5\u770b\u6240\u6709\u547d\u4ee4\u548c\u6982\u5ff5\uff1a<\/p>\n<pre><code>Get-Help *\nHelp *\n<\/code><\/pre>\n<p>\u6a21\u7cca\u67e5\u627e\u547d\u4ee4\u548c\u6982\u5ff5\uff1a<\/p>\n<pre><code>Get-Help *&lt;name&gt;*\nHelp *&lt;name&gt;*\n<\/code><\/pre>\n<p>\u67e5\u770b\u5177\u4f53\u547d\u4ee4\u5e2e\u52a9\uff1a<\/p>\n<pre><code>Get-Help {&lt;CmdletName&gt; | &lt;TopicName&gt;}\nHelp {&lt;CmdletName&gt; | &lt;TopicName&gt;}\n&lt;CmdletName&gt; -?\n<\/code><\/pre>\n<p>get-help\/help\u7684\u9009\u9879:<\/p>\n<pre><code>get-help get-help\n-examples # \u67e5\u770b\u793a\u4f8b\n-full # \u67e5\u770b\u6240\u6709\u5e2e\u52a9\n-parameter # \u67e5\u770b\u9009\u9879\u7684\u5e2e\u52a9\n-detailed # \u67e5\u770b\u8be6\u7ec6\u4fe1\u606f\n-online # \u6253\u5f00\u6587\u6863\u4e2d\u7684link\n-showwindow # \u7528\u7a97\u53e3\u6253\u5f00\n<\/code><\/pre>\n<h1 id=\"helpfile\">Helpfile<\/h1>\n<p>3.0\/4.0 \u9700\u8981\u5148\u4e0b\u8f7d\u5e2e\u52a9\u624b\u518c\uff1a<\/p>\n<pre><code>update-help\n<\/code><\/pre>\n<p>\u6240\u6709helpfile\uff1a<\/p>\n<pre><code>Get-Help\/Help about_*\n<\/code><\/pre>\n<p>\u67e5\u770b\u5177\u4f53helpfile\uff1a<\/p>\n<pre><code>Get-Help\/Help about_&lt;name&gt;\n<\/code><\/pre>\n<hr>\n<h1 id=\"cmdlets\">Cmdlets<\/h1>\n<p>cmdlets\u662fpowershell\u7684\u5185\u7f6e\u547d\u4ee4,\u7c7b\u578b\u662fSystem.Management.Automation.CmdletInfo<\/p>\n<p>cmdlets\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre><code>Equals\nGetHashCode\nGetType\nToString\n<\/code><\/pre>\n<p>cmdlets\u7684\u5c5e\u6027\uff1a<\/p>\n<pre><code>CommandType\nDefaultParameterSet\nDefinition\nHelpFile\nImplementingType\nModule\nModuleName\nName\nNoun\nOutputType\nParameters\nParameterSets\nPSSnapln\nVerb\nVisibility\nDLL\nHelpUri\n<\/code><\/pre>\n<p>\u5e38\u7528cmdlets\u547d\u4ee4\uff1a<\/p>\n<pre><code>Get-Command -CommandType cmdlet # \u67e5\u770b\u6240\u6709cmdlet\nGet-Command\nInvoke-Command\nMeasure-Command\nShow-Command\nTrace-Command\nGet-Service\nNew-Service\nRestart-Service\nResume-Service\nSet-Service\nStop-Service\nSuspend-Service\nGet-Process\nDebug-Process\nStart-Process\nStop-Process\nWait-Process\nGet-Member # \u67e5\u770b\u5c5e\u6027\nAdd-Member\nGet-Host\nRead-Host\nWrite-Host\nOut-Host\nOut-Default\nOut-File # \u91cd\u5b9a\u5411\uff0c\u4e5f\u53ef\u4ee5\u7528&gt;, &gt;&gt;\nOut-GridView\nOut-Null\nOut-Printer\nOut-String\nWrite-Debug\nWrite-Error\nWrite-EventLog\nWrite-Output\nWrite-Progress\nWrite-Verbose\nWrite-Warning\n<\/code><\/pre>\n<h1 id=\"function\">Function<\/h1>\n<p>powershell\u5185\u7f6e\u51fd\u6570<\/p>\n<pre><code>Get-Command -CommandType function # \u67e5\u770b\u6240\u6709function\nls function:\n<\/code><\/pre>\n<p>\u6240\u6709function\uff1a<\/p>\n<pre><code>prompt\nTabExpansion2\nClear-Host\nmore\nhelp\nmkdir\nGet-Verb\noss\ncd..\ncd\\\nImportSystemModules\nPause\nA:\n...\nZ:\nGet-FileHash\n<\/code><\/pre>\n<h1 id=\"alias\">Alias<\/h1>\n<p>powershell\u5185\u7f6e\u522b\u540d<\/p>\n<pre><code>Get-Command -CommandType alias # \u67e5\u770b\u6240\u6709alias\ndir alias: # \u67e5\u770b\u6240\u6709alias\nls alias: | where {$_.Definition.Startswith(&quot;Start&quot;)}\nGet-Alias # \u67e5\u770b\u6240\u6709alias\nSet-Alias\nNew-Alias\nImport-Alias\nExport-Alias\n<\/code><\/pre>\n<p>\u5e38\u7528alias\uff1a<\/p>\n<pre><code>ForEach-Object %\/foreach\nWhere-Object ?\/where\nSelect-Object select\nCompare-Object compare\/diff\nTee-Object tee\nSort-Object sort\nSet-Location cd\/chdir\/sl\nGet-Location pwd\/gl\nClear-Content clc\nGet-Content cat\/type\/gc\nClear-History clhy\nGet-History h\/history\/ghy\nInvoke-History ihy\/r\nClear-Variable clv\nSet-Variable set\/sv\nClear-Item cli\nClear-ItemProperty clp\nCopy-Item copy\/cp\/cpi\nRemove-Item del\/erase\/rd\/ri\/rm\/rmdir\nMove-Item mv\/move\/mi\nGet-ChildItem dir\/ls\/gci\nGet-Process ps\/gps\nStop-Process kill\/spps\nStart-Process start\/saps\nClear-Host clear\/cls\nWrite-Output echo\/write\nNew-PSDrive mount\nInvoke-WebRequest curl\/wget\nStart-Sleep sleep\nhelp man\nmkdir md\n<\/code><\/pre>\n<hr>\n<h1 id=\"provider\">Provider<\/h1>\n<p>provider\u76f8\u5173cmdlet\uff1a<\/p>\n<pre><code>Get-PSProvider # \u67e5\u770bprovider\nGet-PSDrive # \u67e5\u770b\u9a71\u52a8\u5668\nNew-PSDrive # \u65b0\u5efa\u9a71\u52a8\u5668\nRemove-PSDrive # \u5220\u9664\u9a71\u52a8\u5668\n<\/code><\/pre>\n<p>\u6240\u6709provider\uff1a<\/p>\n<pre><code># \u8fd9\u4e09\u4e2a\u9a71\u52a8\u5668\u53ef\u4ee5\u7528ls\u6216dir\u76f4\u63a5\u67e5\u770b\u5185\u5bb9\nls alias:\ndir function:\nAlias # \u522b\u540d\u9a71\u52a8\u5668\nFunction # \u51fd\u6570\u9a71\u52a8\u5668\nVariable # \u53d8\u91cf\u9a71\u52a8\u5668\n# \u8fd9\u4e09\u4e2a\u9a71\u52a8\u5668\u9700\u8981\u5177\u4f53\u7684\u9a71\u52a8\u5668,\u7136\u540ecd\u8fdb\u53bb\u67e5\u770b\nFileSystem # \u6587\u4ef6\u7cfb\u7edf\u9a71\u52a8\u5668\nEnvironment\nRegistry\nhelp\/get-help &lt;provider_name&gt; # \u67e5\u770bprovider\u5e2e\u52a9\n<\/code><\/pre>\n<hr>\n<h1 id=\"object\">object<\/h1>\n<p>object\u4e3b\u8981\u901a\u8fc7\u7ba1\u9053|\u4f7f\u7528\u3002<\/p>\n<p>object\u76f8\u5173\u7684cmdlet\uff1a<\/p>\n<pre><code>Compare-Object\nForEach-Object\nGroup-Object\nMeasure-Object\nNew-Object\nSelect-Object\nSort-Object\nTee-Object\nWhere-Object\n<\/code><\/pre>\n<p>object\u8f6c\u5316\uff1a<\/p>\n<pre><code>get-command -verb *convert*\n...\n<\/code><\/pre>\n<p>\u5bfc\u51faobject\uff1a<\/p>\n<pre><code>get-command -verb *export*\n...\n<\/code><\/pre>\n<p>\u5bfc\u5165object\uff1a<\/p>\n<pre><code>get-command -verb *import*\n...\n<\/code><\/pre>\n<h1 id=\"module\">module<\/h1>\n<pre><code>Get-Module\nget-module -listavailable # \u67e5\u627e\u5b89\u88c5\u7684\u6a21\u5757\nImport-Module\nimport-module sqlps # \u5bfc\u5165\u7b2c\u4e09\u65b9mssql\u6a21\u5757\nget-command -module sqlps # \u67e5\u770b\u6a21\u5757\u4e2d\u6240\u6709\u547d\u4ee4\nNew-Module\nRemove-Module\n<\/code><\/pre>\n<h1 id=\"format\">format<\/h1>\n<p>\u5b89\u88c5\u8def\u5f84\u6709\u4e00\u4e9bxml\u6587\u4ef6\u5df2\u7ecf\u505a\u4e86\u4e00\u4e9b\u9ed8\u8ba4\u7684\u683c\u5f0f\u5316\u3002<\/p>\n<p>\u683c\u5f0f\u5316\u7684\u6570\u636e\u53ea\u80fd\u4f20\u7ed9Out-File\/out-host\/out-printer\/out-null\/out-string\/out-default.<\/p>\n<pre><code>Export-FormatData\nGet-FormatData\nUpdate-FormatData\nFormat-Custom\nFormat-List\nFormat-Table\nFormat-Wide\n<\/code><\/pre>"},{"title":"Snmp","link":"https:\/\/canuxcheng.com\/post\/snmp\/","pubDate":"Tue, 26 Apr 2016 09:56:04 +0000","guid":"https:\/\/canuxcheng.com\/post\/snmp\/","description":"<h1 id=\"snmp\">SNMP<\/h1>\n<p>Simple Network Management Protocol, \u7b80\u5355\u7f51\u7edc\u7ba1\u7406\u534f\u8bae<\/p>\n<p>MIB<\/p>\n<p>SMI<\/p>\n<p>\u5b89\u88c5\u548c\u914d\u7f6esnmp:<\/p>\n<pre><code>$sudo apt-get install snmp snmpd snmp-mibs-downloader\n<\/code><\/pre>\n<hr>\n<h1 id=\"snmp\u547d\u4ee4\">snmp\u547d\u4ee4<\/h1>\n<hr>"},{"title":"Admin","link":"https:\/\/canuxcheng.com\/post\/win_admin\/","pubDate":"Tue, 26 Apr 2016 09:54:45 +0000","guid":"https:\/\/canuxcheng.com\/post\/win_admin\/","description":{}},{"title":"PowerShell","link":"https:\/\/canuxcheng.com\/post\/ps\/","pubDate":"Tue, 26 Apr 2016 09:52:02 +0000","guid":"https:\/\/canuxcheng.com\/post\/ps\/","description":"<h1 id=\"powershell\">PowerShell<\/h1>\n<p>Console: command line interface<\/p>\n<p>ISE: script editor and console combination<\/p>\n<p>Version:<\/p>\n<p>2.0,3.0,4.0,5.0<\/p>\n<p>C:\\Windows\\System32\\powershell \u5b58\u653e64\u4f4dpowershell<\/p>\n<p>C:\\Windows\\SysWOW64\\powershell \u5b58\u653e32\u4f4dpowershell<\/p>\n<pre><code>&gt;$PSVersionTable\n&gt;$HOST\n<\/code><\/pre>\n<p>Install\/Update:<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.microsoft.com\/zh-CN\/download\/details.aspx?id=40855\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.microsoft.com\/zh-CN\/download\/details.aspx?id=40855<\/a><\/p>\n<p>\u5b89\u88c5Windows Management Framework4.0\u5373\u53ef\u3002<\/p>\n<pre><code>&gt;$PSHOME\n<\/code><\/pre>\n<p>\u591a\u7248\u672c\u65f6\u5207\u6362\u7248\u672c:<\/p>\n<pre><code>&gt;powershell -version 2\n<\/code><\/pre>\n<hr>\n<h1 id=\"powershell\u76f8\u5173\u9879\u76ee\">powershell\u76f8\u5173\u9879\u76ee<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/Microsoft\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/Microsoft<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/PowerShell\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/PowerShell<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/PowerShellOrg\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/PowerShellOrg<\/a><\/p>\n<h2 id=\"win32-openssh\">win32-openssh<\/h2>\n<p>windows\u7684SSH\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/PowerShell\/Win32-OpenSSH\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/PowerShell\/Win32-OpenSSH<\/a><\/p>\n<hr>\n<h1 id=\"powershell\u547d\u4ee4\">powershell\u547d\u4ee4<\/h1>\n<pre><code>&gt;powershell -?\n&gt;powershell \/?\n&gt;powershell -help\n<\/code><\/pre>\n<hr>\n<h1 id=\"powershell-script\">powershell script<\/h1>\n<p>powershell\u662f\u9ed8\u8ba4\u5927\u5c0f\u5199\u4e0d\u654f\u611f\u7684\u3002<\/p>\n<p>\u540c\u4e00\u884c\u591a\u4e2a\u547d\u4ee4\u9700\u8981\u7528\u5206\u53f7;\u9694\u5f00\u3002<\/p>\n<p>powershell\u7684\u5b89\u5168\u7b56\u7565\uff1a<\/p>\n<ol>\n<li>restricted(default)<\/li>\n<li>allsigned<\/li>\n<li>remotesigned<\/li>\n<li>unrestricted<\/li>\n<li>bypass<\/li>\n<\/ol>\n<h1 id=\"\u6ce8\u91ca\">\u6ce8\u91ca<\/h1>\n<p>\u5355\u884c\u6ce8\u91ca\uff1a<\/p>\n<pre><code># comment\n<\/code><\/pre>\n<p>\u591a\u884c\u6ce8\u91ca(\u6587\u6863\u6ce8\u91ca)\uff1a<\/p>\n<pre><code>&lt;#\ncomment1\ncomment2\n...\n#&gt;\n<\/code><\/pre>\n<p>\u5e2e\u52a9\u6587\u6863:<\/p>\n<p>\u5728\u811a\u672c\u5f00\u5934\u7684\u6ce8\u91ca\u4e2d\u7528\u4e0b\u9762\u5173\u952e\u5b57\u63d2\u5165\u6587\u6863\u3002<\/p>\n<pre><code>&lt;#\n.SYNOPSIS\nWrite your synopsis here.\n.DESCRIPTION\nWrite your description here.\n.PARAMETER param1\nWrite your param1 information here.\n.EXAMPLE\nWrite your example1 here.\n.NOTES\nWrite your notes here.\n.LINK\nhttp:\/\/test.com\n#&gt;\n<\/code><\/pre>\n<h1 id=\"\u6570\u636e\u7c7b\u578b\">\u6570\u636e\u7c7b\u578b<\/h1>\n<h2 id=\"\u53d8\u91cf\">\u53d8\u91cf<\/h2>\n<p>\u6240\u6709\u7684\u53d8\u91cf\u90fd\u5b58\u50a8\u5728Variable\u9a71\u52a8\u5668\u4e2d,\u53ef\u4ee5\u7528Variable\u9a71\u52a8\u5668\u5bf9\u53d8\u91cf\u64cd\u4f5c\u3002<\/p>\n<pre><code>ls Variable: # \u67e5\u770b\u6240\u6709\u53d8\u91cf\n<\/code><\/pre>\n<p>\u7cfb\u7edf\u53d8\u91cf\uff1a<\/p>\n<pre><code>$_ # \u8868\u793a\u7ba1\u9053\u4e2d\u7684\u5f53\u524d\u5bf9\u8c61\n? # True\u8868\u793a\u4e0a\u4e00\u4e2a\u547d\u4ee4\u6210\u529f\u6267\u884c,False\u5931\u8d25\n<\/code><\/pre>\n<p>\u81ea\u5b9a\u4e49\u53d8\u91cf\uff1a<\/p>\n<p>\u53d8\u91cf\u4ee5$\u5f00\u5934\u5b9a\u4e49,\u4f46\u662f$\u4e0d\u662f\u53d8\u91cf\u540d\u7684\u4e00\u90e8\u5206\u3002<\/p>\n<p>\u53d8\u91cf\u5305\u542b\u6570\u5b57\uff0c\u5b57\u6bcd\u548c\u5c0f\u5212\u7ebf\u3002<\/p>\n<pre><code>$var1=&quot;test&quot;\n$var1\n# \u4ea4\u6362\u4e24\u4e2a\u53d8\u91cf\u7684\u503c\n$var1,$var2=$var2,$var1\n<\/code><\/pre>\n<p>\u53d8\u91cf\u7c7b\u578b\uff1a<\/p>\n<p>\u53ef\u4ee5\u4e0d\u7528\u6307\u5b9a\u53d8\u91cf\u7c7b\u578b\u3002<\/p>\n<pre><code>[string]$str=&quot;123&quot;\n[int]$num=123\n[boolean]bool=&quot;True&quot;\n<\/code><\/pre>\n<p>\u5224\u65ad\u53d8\u91cf\u7c7b\u578b\uff1a<\/p>\n<pre><code>$str -is [string]\n$num -as [int]\n<\/code><\/pre>\n<h2 id=\"\u6570\u7ec4\">\u6570\u7ec4<\/h2>\n<p>\u5305\u542b\u591a\u4e2a\u53d8\u91cf\u5c31\u662f\u4e00\u4e2a\u6570\u7ec4\u3002<\/p>\n<pre><code>$var2=1,2,3\n$var2[index]\n$var2[0] # \u6570\u7ec4\u7b2c\u4e00\u4e2a\u5143\u7d20\n$var2[-1] # \u6570\u7ec4\u6700\u540e\u4e00\u4e2a\u5143\u7d20\n<\/code><\/pre>\n<h2 id=\"\u5b57\u5178\">\u5b57\u5178\uff1a<\/h2>\n<p>hash\u7c7b\u578b\u3002<\/p>\n<pre><code>@{L=&lt;key&gt;;\nE={$_.&lt;value&gt;};\nformatstring=&lt;format&gt;}\n@{N=&lt;key&gt;;E={$_.&lt;value&gt;}}\n@{Label=&lt;key&gt;;E={$_.&lt;value&gt;}}\n@{Name=&lt;key&gt;;E={$_.&lt;value&gt;}}\n<\/code><\/pre>\n<h1 id=\"\u8fd0\u7b97\u7b26\">\u8fd0\u7b97\u7b26<\/h1>\n<p>\u57fa\u672c\u8fd0\u7b97\u7b26\uff1a<\/p>\n<pre><code>= # \u8d4b\u503c\u8fd0\u7b97\u7b26\uff0c\u53ef\u4ee5\u628a\u4efb\u4f55\u6570\u636e\u7c7b\u578b\u5305\u62ec\u5bf9\u8c61\u8d4b\u503c\u7ed9\u53d8\u91cf\n+ # \u52a0\u6cd5\u548c\u5b57\u7b26\u4e32\u62fc\u63a5\n- # \u51cf\u6cd5\n* # \u4e58\u6cd5\n\/ # \u9664\u6cd5\n() # \u4f18\u5148\u8fd0\u7b97\u7b26\n<\/code><\/pre>\n<p>\u7279\u6b8a\u8fd0\u7b97\u7b26\uff1a<\/p>\n<pre><code>$($procs[0].name) # \u5b50\u53d8\u91cf\n'$var' # \u5355\u5f15\u53f7\u4e2d\u7684\u53d8\u91cf\u539f\u6837\u8f93\u51fa\n&quot;$var&quot; # \u53cc\u5f15\u53f7\u4e2d\u7684\u53d8\u91cf\u88ab\u66ff\u6362\n&quot;`$var&quot; # `\u91cd\u97f3\u7b26\u53ef\u4ee5\u7528\u5728\u53cc\u5f15\u53f7\u4e2d\u8f6c\u4e49\n`t # \u5236\u8868\u7b26\n`n # \u6362\u884c\u7b26\nkb\/mb\/gt\/tb\/pb # \u5355\u4f4d\u53ef\u4ee5\u8fd0\u7b97\n<\/code><\/pre>\n<p>\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff1a<\/p>\n<pre><code>-eq\n-ne\n-gt\n-ge\n-lt\n-le\n-contains \u5305\u542b\n-notcontains\n<\/code><\/pre>\n<p>\u5e03\u5c14\u8fd0\u7b97\u7b26\uff1a<\/p>\n<pre><code>-not \u6c42\u53cd\n-and\n-or\n-xor\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u63a7\u5236\u6d41\">\u63a7\u5236\u6d41<\/h1>\n<p>powershell\u652f\u6301foreach\u5faa\u73af\u3002<\/p>\n<p>if\u6761\u4ef6\u8bed\u53e5\uff1a<\/p>\n<pre><code>if ($this -eq $that) {\nexpression\n} elseif ($those -gt $these) {\nexpression2\n} else {\nexpression3\n}\n<\/code><\/pre>\n<p>switch\u6761\u4ef6\u8bed\u53e5\uff1a<\/p>\n<pre><code>switch ($condition) {\nval1 {\nexpression\nbreak\n}\nval2 {\nexpression2; break\n}\ndefault {\ndefault_expression\n}\n}\n<\/code><\/pre>\n<p>foreach\u5faa\u73af\u8bed\u53e5\uff1a<\/p>\n<pre><code>foreach ($name in $names) {\nexpression\n}\n<\/code><\/pre>\n<p>for\u5faa\u73af\u8bed\u53e5\uff1a<\/p>\n<pre><code>for ($loop=1; condition; $loop++)\n{\nexpression\n}\n<\/code><\/pre>\n<p>while\u5faa\u73af\u8bed\u53e5:<\/p>\n<pre><code>while (condition)\n{\nexpression\n}\n<\/code><\/pre>\n<p>do-while\u5faa\u73af\u8bed\u53e5\uff1a<\/p>\n<pre><code>do {\nexpression\n} while (condition)\n<\/code><\/pre>\n<p>break\u8bed\u53e5\uff1a<\/p>\n<p>break\u7528\u4e8e\u5faa\u73af\u548cswitch\u8bed\u53e5\u3002<\/p>\n<p>continue\u8bed\u53e5\uff1a<\/p>\n<p>continue\u7528\u4e8e\u5faa\u73af\u8bed\u53e5\u3002<\/p>\n<hr>\n<h1 id=\"\u51fd\u6570\">\u51fd\u6570<\/h1>\n<p>\u51fd\u6570\uff1a<\/p>\n<pre><code>function name {\n...\n}\n<\/code><\/pre>\n<p>\u8c03\u7528\u51fd\u6570:<\/p>\n<pre><code>.\\file.ps1\nname\n<\/code><\/pre>\n<p>\u9009\u9879\uff1a<\/p>\n<pre><code>[CmdletBinding()]\nParam(\n[Parameter(Mandatory=$True)]\n[String]$ComputerName, # ComputerName\u5f3a\u5236\u4e3a\u901a\u8fc7\u547d\u4ee4\u884c\u8f93\u5165\u53c2\u6570\n[int]$EventID=1234, # EventID\u6709\u9ed8\u8ba4\u53c2\u6570\n[Parameter(Mandatory=$True)][ValidateRange(0,23)]\n[int]$Number # \u7ed9\u51fa\u53c2\u6570\u7684\u8303\u56f4\n)\n[CmdletBinding(SupportsShouldProcess$True)] # \u652f\u6301-whatif\u548c-confirm\n[ValidateSet(1,3,8)] # \u7ed9\u51fa\u53c2\u6570\u7684\u53ef\u9009\u503c\n[alias(&quot;id&quot;, &quot;nunber&quot;)] # \u7ed9\u53c2\u6570\u6307\u5b9a\u522b\u540d\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u6a21\u5757\">\u6a21\u5757<\/h1>\n<p>\u7cfb\u7edf\u6a21\u5757\u8def\u5f84\uff1a<\/p>\n<pre><code>c:\\Windows\\System32\\WindowsPowershell\\v1.0\\Modules\\\n<\/code><\/pre>\n<p>\u51fd\u6570\u53ef\u4ee5\u6253\u5305\u6210\u6a21\u5757\u653e\u5728\u7cfb\u7edf\u6a21\u5757\u8def\u5f84\u6216\u7528\u6237\u81ea\u5df1\u7684\u6a21\u5757\u8def\u5f84\u3002<\/p>\n<p>\u6a21\u5757\u653e\u5230\u540c\u540d\u7684\u76ee\u5f55mytools\u4e0b\uff0c\u53d6\u540dmytools.psm1<\/p>\n<p>\u5bfc\u5165\u7528\u6237\u81ea\u5df1\u8def\u5f84\u4e0b\u7684\u6a21\u5757\uff1a<\/p>\n<pre><code>Import-Module -name C:\\Modules\\mytools\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u5f02\u5e38\u548c\u9519\u8bef\u5904\u7406\">\u5f02\u5e38\u548c\u9519\u8bef\u5904\u7406<\/h1>\n<p>\u8c03\u8bd5\u8bed\u53e5\uff1a<\/p>\n<pre><code>Write-Verbose &quot;print verbose information.&quot; # \u6253\u5370\u8c03\u8bd5\u4fe1\u606f\nWrite-Debug &quot;print debug information.&quot; # \u4f7f\u7528-Debug\u8fdb\u5165debug\u6a21\u5f0f\uff0cexit\u9000\u51fa\u3002\n<\/code><\/pre>\n<p>\u8c03\u8bd5\u76f8\u5173\u7cfb\u7edf\u53d8\u91cf\uff1a<\/p>\n<pre><code>$ErrorActionPreference='Continue' # \u8c03\u8bd5\u7684\u7cfb\u7edf\u53d8\u91cf\uff0c\u9ed8\u8ba4\u62a5\u9519\u7ee7\u7eed\u6267\u884c\n$DebugPreference='SilentlyContinue'\n$ErrorView='NormalView'\n$Error \u5b58\u50a8\u6574\u4e2ashell\u7684\u9519\u8bef\u3002\n<\/code><\/pre>\n<p>\u5f02\u5e38\u6355\u83b7\uff1a<\/p>\n<pre><code>Try {\nexpressions\n}\nCatch {\n&quot;execute when catch the error.&quot;\n}\nFinally {\n&quot;execute anyway.&quot;\n}\n<\/code><\/pre>\n<p>\u65ad\u70b9\u8c03\u8bd5\uff1a<\/p>\n<pre><code>$Condition = {if ($a -is [int] -and $a -gt 100) {Write-Host &quot;`$a was modified&quot;}}\n$Breakpoint = Set-PSBreakpoint -Variable a -Mode Write -Script $psise.CurrentFile.FullPath -Action $Condition\n<\/code><\/pre>"},{"title":"Utils","link":"https:\/\/canuxcheng.com\/post\/ps_utils\/","pubDate":"Tue, 26 Apr 2016 09:52:02 +0000","guid":"https:\/\/canuxcheng.com\/post\/ps_utils\/","description":"<h1 id=\"windows\u76f8\u5173\u9879\u76ee\">windows\u76f8\u5173\u9879\u76ee\uff1a<\/h1>\n<h2 id=\"choco\">choco<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/chocolatey\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/chocolatey<\/a><\/p>\n<p>windows\u7684apt\/yum\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/chocolatey\/choco\" target=\"_blank\" rel=\"noopener\"\n>choco<\/a> is replacement of <a class=\"link\" href=\"https:\/\/github.com\/chocolatey\/chocolatey\" target=\"_blank\" rel=\"noopener\"\n>chocolatey<\/a><\/p>\n<pre><code>choco install openssh\n<\/code><\/pre>\n<h2 id=\"cmder\">cmder<\/h2>\n<p>cmd\u7684\u5347\u7ea7\u7248\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/cmderdev\/cmder\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/cmderdev\/cmder<\/a><\/p>\n<h2 id=\"babun\">babun<\/h2>\n<p>a linux-shell like on windows.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/babun\/babun\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/babun\/babun<\/a><\/p>\n<h2 id=\"flinux\">flinux<\/h2>\n<p>run unmodified linux applications inside windows<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/wishstudio\/flinux\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/wishstudio\/flinux<\/a><\/p>"},{"title":"Tivoli","link":"https:\/\/canuxcheng.com\/post\/metrics_tivoli\/","pubDate":"Wed, 20 Apr 2016 13:57:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/metrics_tivoli\/","description":"<h1 id=\"itm\">ITM<\/h1>\n<p>ITM: IBM Tivoli Monitoring<\/p>\n<p>\u662fIBM\u7684Cloud &amp; Smart Infrastructure\u76d1\u63a7\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p>Architecture Overview:<\/p>\n<p><img src=\"https:\/\/canuxcheng.com\/images\/tivoli.png\"\nloading=\"lazy\"\nalt=\"pic\"\n><\/p>\n<p>ITM\u4e3b\u8981\u7531\u7ba1\u7406\u7ec4\u4ef6\u548c\u53ef\u9009\u7ec4\u4ef6\u7ec4\u6210\u3002<\/p>\n<p>Tivoli Management Services:<\/p>\n<ol>\n<li>TEMS<\/li>\n<li>TEPS<\/li>\n<li>TEP client<\/li>\n<li>Historical data collection(warehouse agent)\n<ul>\n<li>warehouse proxy<\/li>\n<li>summarization and pruning agent<\/li>\n<\/ul>\n<\/li>\n<li>OS agent<\/li>\n<\/ol>\n<p>Optional components:<\/p>\n<ol>\n<li>Dashboard Application Services Hub\n<ul>\n<li>Tivoli Monitoring dashboards(Infrastructure Management Dashboards for Servers)<\/li>\n<li>Tivoli Common Reporting<\/li>\n<li>Tivoli Enterprise Monitoring Automation Server<\/li>\n<\/ul>\n<\/li>\n<li>Tivoli Event Synchronization component<\/li>\n<li>Authorization Policy Components(tivcmd)<\/li>\n<\/ol>\n<p><a class=\"link\" href=\"http:\/\/www.ibm.com\/support\/knowledgecenter\/SSTFXA_6.3.0\/com.ibm.itm.doc_6.3\/welcome_63.htm\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.ibm.com\/support\/knowledgecenter\/SSTFXA_6.3.0\/com.ibm.itm.doc_6.3\/welcome_63.htm<\/a><\/p>\n<h2 id=\"\u5b89\u88c5itm\">\u5b89\u88c5ITM<\/h2>\n<p>Windows: C:\\IBM\\ITM<\/p>\n<p>Linux\/Unix: \/opt\/IBM\/ITM<\/p>\n<p>\u5206\u4e3a\u672c\u5730\u5b89\u88c5\u548c\u5206\u5e03\u5f0f\u5b89\u88c5\u3002<\/p>\n<ol>\n<li>\n<p>\u9700\u8981\u5148\u4e3aTEPS\u548cTDW\u5b89\u88c5DB(ODBC\/JDBC)\u3002<\/p>\n<p>DB2<\/p>\n<p>MSSQL<\/p>\n<p>Oracle<\/p>\n<\/li>\n<li>\n<p>\u5728windows\/linux\/unix\u5b89\u88c5ITM framework<\/p>\n<p>TEMA<\/p>\n<p>Warehouse Proxy agent<\/p>\n<p>Summarization and Pruning agent<\/p>\n<p>Tivoli performance Analyzer<\/p>\n<p>TEMS<\/p>\n<p>TEPS<\/p>\n<p>TEPD<\/p>\n<p>TEMAS<\/p>\n<\/li>\n<li>\n<p>\u5b89\u88c5agent<\/p>\n<p>\u5b89\u88c5\u64cd\u4f5c\u7cfb\u7edf\u7684agent\uff1a<\/p>\n<p>monitoring agent for your OS\u3002<\/p>\n<p>\u5b89\u88c5\u6570\u636e\u5e93\u7684agent\uff1a<\/p>\n<p>TEMA\/TEMS\/TEPS\u540c\u65f6\u52fe\u9009DB\u7684agent\u3002<\/p>\n<p>\u5b89\u88c5agent builder\u7684agent\u3002<\/p>\n<\/li>\n<\/ol>\n<p><a class=\"link\" href=\"http:\/\/www-933.ibm.com\/support\/fixcentral\/swg\/downloadFixes?parent=ibm%2FTivoli&amp;product=ibm\/Tivoli\/IBM&#43;Tivoli&#43;Monitoring&amp;release=All&amp;platform=All&amp;function=fixId&amp;fixids=6.3.0-TIV-ITM-FP0005&amp;includeRequisites=1&amp;includeSupersedes=0&amp;downloadMethod=http\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www-933.ibm.com\/support\/fixcentral\/swg\/downloadFixes?parent=ibm%2FTivoli&product=ibm\/Tivoli\/IBM+Tivoli+Monitoring&release=All&platform=All&function=fixId&fixids=6.3.0-TIV-ITM-FP0005&includeRequisites=1&includeSupersedes=0&downloadMethod=http<\/a><\/p>\n<p>&hellip;<\/p>\n<h1 id=\"tems\">TEMS<\/h1>\n<p>TEMS: Tivoli Enterprise Monitoing Server<\/p>\n<p>TEMS\u5206\u4e3aremote\u548chub\uff0cremote\u6700\u540e\u90fd\u6c47\u603b\u5230hub\u3002<\/p>\n<p>HTEMS: Hub Tivoli Enterprise Monitoring Server<\/p>\n<p>RTEMS: Remote Tivoli Enterprise Monitoring Server<\/p>\n<p>\u4e00\u4e2aTEMS\u5efa\u8bae\u7ba1\u7406700\u4e2aagent<\/p>\n<h1 id=\"tema\">TEMA<\/h1>\n<p>TEMA: Tivoli Enterprise Monitoring Agent<\/p>\n<p>\u5b89\u88c5agent\u4e4b\u540e\u901a\u8fc7GUI\u5de5\u5177Tivoli Enterprise Monitoring Service\u6765\u914d\u7f6e\u548c\u542f\u52a8agent\u3002<\/p>\n<p>\u4e5f\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u6765\u914d\u7f6e\u548c\u542f\u52a8agent\u3002<\/p>\n<p>agent\u914d\u7f6e\u9700\u8981\u6307\u5b9aHTEMS\u670d\u52a1\u5668\u3002<\/p>\n<h2 id=\"agentless\">Agentless<\/h2>\n<p>TEMS -&gt; Agentless server -&gt; servers<\/p>\n<p>\u5c31\u662f\u7528\u4e00\u4e2a\u4e2d\u95f4\u670d\u52a1\u5668\u901a\u8fc7snmp\u7b49\u534f\u8bae\u6765\u76d1\u63a7\u4e0d\u9700\u8981\u5b89\u88c5agent\u7684\u88ab\u76d1\u63a7\u670d\u52a1\u5668\u3002<\/p>\n<p>\u4e00\u4e2aagentless\u53ef\u4ee5\u8bbe\u7f6e10\u4e2a\u5b9e\u4f8b(\u64cd\u4f5c\u7cfb\u7edf)\uff0c\u4e00\u4e2a\u5b9e\u4f8b\u53ef\u4ee5\u76d1\u63a7100\u4e2a\u8282\u70b9(\u88ab\u76d1\u63a7\u670d\u52a1\u5668)\u3002<\/p>\n<p>Agentless OS agents:<\/p>\n<ol>\n<li>Agentless Monitoring for AIX OS - SNMP<\/li>\n<li>Agentless Monitoring for HP-UX OS - SNMP<\/li>\n<li>Agentless Monitoring for Linux OS - SNMP<\/li>\n<li>Agentless Monitoring for Solaris OS - SNMP,CIM-XML<\/li>\n<li>Agentless Monitoring for Windows OS - SNMP,WMI<\/li>\n<\/ol>\n<h2 id=\"agent\">Agent<\/h2>\n<p>TEMS -&gt; servers(agent)<\/p>\n<p>\u4e00\u4e2aagent\u8fde2\u4e2aTEMS,\u4e00\u4e2aprimary\uff0c\u4e00\u4e2abackup\u3002<\/p>\n<p>agent\u5206\u4e3a\uff1a<\/p>\n<ol>\n<li>Operating System agent<\/li>\n<li>specialized agent<\/li>\n<li>Application agent<\/li>\n<\/ol>\n<p>OS agent\uff1a<\/p>\n<ol>\n<li>Windows<\/li>\n<li>Unix<\/li>\n<li>Linux<\/li>\n<li>IBM i5\/OS<\/li>\n<\/ol>\n<p>specialized agent\uff1a<\/p>\n<ol>\n<li>warehouse proxy agent<\/li>\n<li>warehouse summarization and pruning agent<\/li>\n<li>Log file agent<\/li>\n<li>System p\u00ae agents (AIX Premium, CEC Base, HMC Base, VIOS Premium)<\/li>\n<li>Systems Director base agent<\/li>\n<li>Tivoli zEnterprise\u00ae Agent<\/li>\n<li>Performance Analyzer<\/li>\n<\/ol>\n<h1 id=\"tepsdb\">TEPS+DB<\/h1>\n<p>TEPS: Tivoli Enterprise Portal Server<\/p>\n<p>\u4f7f\u7528MTEMS\u6765\u914d\u7f6eTEPS,\u6dfb\u52a0DB\u3002<\/p>\n<h1 id=\"tepdtep-client\">TEPD(TEP client)<\/h1>\n<p>TEP -&gt; TEPS<\/p>\n<p>TEP: Tivoli Enterprise Portal client<\/p>\n<p>TEP\u662fGUI\u754c\u9762\uff0c\u5206\u4e3a\uff1a<\/p>\n<ol>\n<li>Desktop<\/li>\n<li>Browser<\/li>\n<li>JavaWS: java web start<\/li>\n<\/ol>\n<p>\u9700\u8981\u5b89\u88c5IBM\u7684java\uff0c\u5728C:\\Program Files\\IBM\\Java70\u3002<\/p>\n<p>\u4f7f\u7528TEP\u6765\u67e5\u770b\u76d1\u63a7\u7ed3\u679c\u3002<\/p>\n<p>\u9ed8\u8ba4\u7528\u6237\u662fsysadmin, \u9700\u8981\u4e3aTEPD\u6307\u5b9aTEPS\u670d\u52a1\u5668\u3002<\/p>\n<ol>\n<li>\n<p>Browser\u7248\u672c<\/p>\n<pre><code> http:\/\/&lt;TEPS Server&gt;:15200\/cnp.html\n<\/code><\/pre>\n<\/li>\n<li>\n<p>Desktop\u7248\u672c<\/p>\n<pre><code> http:\/\/&lt;TEPS Server&gt;:15200\/tep.jnlp\n<\/code><\/pre>\n<p>\u5b89\u88c5ITM\u53ef\u4ee5\u9009\u62e9\u5b89\u88c5\u684c\u9762\u7248,\u4e5f\u53ef\u4ee5\u4eceJava Web Start\u83b7\u53d6\u684c\u9762\u7248\u3002<\/p>\n<\/li>\n<li>\n<p>Java Web Start\u7248\u672c<\/p>\n<p>\u7ed3\u5408\u4e86desktop\u548cbrowser\u7684\u4f18\u70b9,\u4eceweb\u4e0b\u8f7d\uff0c\u5728\u684c\u9762\u8fd0\u884c\u3002<\/p>\n<\/li>\n<\/ol>\n<p>TEP\u7684\u7ed3\u6784\uff1a<\/p>\n<ul>\n<li>\n<p>Navigator view<\/p>\n<p>Enterprise<\/p>\n<p>Operating Platform(\u64cd\u4f5c\u7cfb\u7edf\u7c7b\u578b)<\/p>\n<p>Node(\u4e00\u53f0\u670d\u52a1\u5668\u4e00\u4e2a\u8282\u70b9)<\/p>\n<p>Agent(\u4e00\u4e2a\u8282\u70b9\u4e0a\u7684agent)<\/p>\n<p>Situation(\u4e00\u4e2aagent\u4e0a\u7684situation)<\/p>\n<p>Event(\u4e00\u4e2asituation\u6709\u591a\u4e2aevent)<\/p>\n<p>Attribute group(\u76f8\u540c\u7684Situation\u662f\u4e00\u4e2agroup)<\/p>\n<\/li>\n<li>\n<p>Navigator workspace<\/p>\n<p>\u6bcf\u4e2aview\u9879\u76ee\u90fd\u6709\u4e00\u4e2a\u9ed8\u8ba4\u7684workspace\u3002<\/p>\n<\/li>\n<\/ul>\n<p>&hellip;<\/p>\n<h1 id=\"history-data-collectiontdw\">History data collection(TDW)<\/h1>\n<p>TDW: Tivoli Data Warehouse<\/p>\n<p>\u5b58\u50a8\u5386\u53f2\u6570\u636e\u3002\u652f\u6301DB2\uff0cOracle\uff0c MSSQL\u3002<\/p>\n<p>\u4e5f\u5c31\u662f\u5c06agent\u6536\u96c6\u7684\u6570\u636e\u5b58\u5230\u6570\u636e\u5e93\u3002<\/p>\n<h2 id=\"warehouse-proxy\">Warehouse Proxy<\/h2>\n<p>TDW\u4f7f\u7528\u8be5agent\u4eceagents\u6536\u96c6\u548c\u52a0\u8f7d\u6570\u636e\u3002<\/p>\n<p>\u4f7f\u7528MTEMS\u914d\u7f6ewarehouse proxy\u3002<\/p>\n<h2 id=\"summarization-and-pruning-agent\">Summarization and Pruning agent<\/h2>\n<p>TDW\u4f7f\u7528\u8be5agent\u63a7\u5236\u6570\u636e\u5e93\u5927\u5c0f\u3002<\/p>\n<p>\u4f7f\u7528MTEMS\u914d\u7f6esummarization and pruning agent\u3002<\/p>\n<h1 id=\"jazz-for-service-managementvisualization\">Jazz for Service Management(Visualization)<\/h1>\n<h2 id=\"dashboard-application-services-hubdashvisualization-services\">Dashboard Application Services Hub(DASH)(visualization services)<\/h2>\n<h2 id=\"ibm-tivoli-common-reportingreporting-services\">IBM Tivoli Common Reporting(reporting services)<\/h2>\n<h2 id=\"registry-services\">Registry Services<\/h2>\n<h2 id=\"security-services\">Security Services<\/h2>\n<h2 id=\"administration-services\">Administration Services<\/h2>\n<h2 id=\"tivoli-directory-integrator\">Tivoli Directory Integrator<\/h2>\n<h2 id=\"ibm-http-server\">IBM HTTP Server<\/h2>\n<h2 id=\"ibm-websphere-application-server\">IBM WebSphere\u00ae Application Server<\/h2>\n<h2 id=\"web-server-plug-ins-for-ibm-websphere-application-server\">Web Server Plug-ins for IBM WebSphere Application Server<\/h2>\n<p>&hellip;<\/p>\n<h1 id=\"management\">Management<\/h1>\n<p>\u7ba1\u7406\u6240\u6709\u7ec4\u4ef6\u4e00\u822c\u4f7f\u7528GUI\u53ebmanage tivoli monitoring services<\/p>\n<p>windows\/linux\/unix\u90fd\u53ef\u4ee5\u7528GUI\u3002<\/p>\n<p>\u4e5f\u53ef\u4ee5\u4f7f\u7528CLI\uff08\u547d\u4ee4\u884c\uff09,\u89c1\u540e\u6587.<\/p>\n<p>\u4e00\u822c\u4f7f\u7528GUI\u6765\u542f\u52a8\u3001\u505c\u6b62\u548c\u914d\u7f6e\u7ec4\u4ef6\u3002<\/p>\n<h1 id=\"cli\">CLI<\/h1>\n<p>Command Line Interface<\/p>\n<h2 id=\"tacmd\">tacmd<\/h2>\n<p>\u652f\u6301windows\/linux\/unix\u3002<\/p>\n<p>\/opt\/IBM\/ITM\/bin\/tacmd<\/p>\n<p>C:\\IBM\\ITM\\BIN\\tacmd<\/p>\n<p>\u67e5\u770btacmd\u624b\u518c\uff1a<\/p>\n<pre><code>.\/tacmd help\n.\/tacmd ?\n<\/code><\/pre>\n<p>\u767b\u9646\u548c\u767b\u51faHTEMS:<\/p>\n<pre><code>.\/tacmd login -s [PROTOCOL:\/\/]HOST[:PORT] -u [USERNAME] -p [PASSWORD] -t [TIMEOUT]\n.\/tacmd logout\n<\/code><\/pre>\n<p>\u767b\u9646\u548c\u767b\u51faTEPS\uff1a<\/p>\n<pre><code>.\/tacmd tepsLogin -s [TEPS_HOSTNAME] -u [USERNAME] -p [TEPS_PASSWORD] -t [TIMEOUT] -i [IGNORE]\n.\/tacmd tepsLogout\n<\/code><\/pre>\n<p>\u7ba1\u7406agent\uff1a<\/p>\n<pre><code>.\/tacmd startAgent\/stopAgent\/restartAgent\/viewAgent\/updateAgent ...\n<\/code><\/pre>\n<p>\u5237\u65b0Netcool\/OMNIbus\uff1a<\/p>\n<pre><code>.\/tacmd refreshTECinfo {-t|--type} {eif|maps|attr|all}\n<\/code><\/pre>\n<h2 id=\"itmcmd\">itmcmd<\/h2>\n<p>\u7528\u4e8eLinux\/Unix\u7cfb\u7edf\u7684\u547d\u4ee4<\/p>\n<p>\/opt\/IBM\/ITM\/bin\/itmcmd<\/p>\n<p>\u67e5\u770bitmcmd\u624b\u518c\uff1a<\/p>\n<pre><code>.\/itmcmd help\n.\/itmcmd ?\n<\/code><\/pre>\n<p>\u542f\u52a8\u6216\u505c\u6b62TEMS:<\/p>\n<pre><code>.\/itmcmd server [-options] {start|stop} tems_name\n<\/code><\/pre>\n<p>\u542f\u52a8\u6216\u505c\u6b62agent\uff1a<\/p>\n<pre><code>.\/itmcmd agent [-options] {start|stop} {pc ...|all}\n<\/code><\/pre>\n<p>\u542f\u52a8MTEMS:<\/p>\n<pre><code>.\/itmcmd manage &amp;\n<\/code><\/pre>\n<h2 id=\"tivcmd\">tivcmd<\/h2>\n<p>&hellip;<\/p>\n<h1 id=\"advanced-administration\">Advanced Administration<\/h1>\n<h2 id=\"queriesquery-editor\">Queries(query editor)<\/h2>\n<p>DB agent -&gt; normal way to get data source from database servers.<\/p>\n<p>ODBC -&gt; get data source from windows database<\/p>\n<p>JDBC -&gt; get data source from linux\/unix database<\/p>\n<h2 id=\"advanced-link-topics\">Advanced link topics<\/h2>\n<p>Simple link:<\/p>\n<p>Just used to navigate portal workspaces without using the navigator.<\/p>\n<p>Advanced link:<\/p>\n<p>Can be used to manipulate data that is displayed in the target workspace.<\/p>\n<h2 id=\"advanced-situation-techniquessituation-editor\">Advanced situation techniques(situation editor)<\/h2>\n<h2 id=\"agent-autonomy\">Agent autonomy<\/h2>\n<h2 id=\"policyworkflow-editor\">Policy(workflow editor)<\/h2>\n<h2 id=\"agentless-monitoring\">Agentless monitoring<\/h2>\n<p>TEPS -&gt; Agentless Monitoring Serve -&gt; Servers<\/p>\n<h2 id=\"agent-managent-servicesams\">Agent Managent Services(AMS)<\/h2>\n<hr>\n<hr>\n<h1 id=\"agent-builder\">Agent Builder<\/h1>\n<p>IBM Agent Builder agents<\/p>\n<p>windows:<\/p>\n<pre><code>C:\\Program Files(x86)\\IBM\\AgentBuilder\n<\/code><\/pre>\n<p>aix\/linux:<\/p>\n<pre><code>\/opt\/ibm\/AgentBuilder\n<\/code><\/pre>\n<p>Data source:<\/p>\n<ol>\n<li>JDBC<\/li>\n<li>HTTP<\/li>\n<li>SOAP<\/li>\n<li>Ping<\/li>\n<li>Socket<\/li>\n<li>Java API<\/li>\n<li>WMI<\/li>\n<li>Perfmon<\/li>\n<li>CIM<\/li>\n<li>SNMP<\/li>\n<li>JMX<\/li>\n<li>command return code<\/li>\n<li>output from a script<\/li>\n<li>A log file<\/li>\n<li>AIX Binary Log<\/li>\n<li>windows event log<\/li>\n<li>A process<\/li>\n<li>A Windows service<\/li>\n<\/ol>\n<h1 id=\"create-agent\">create agent<\/h1>\n<p>Every agent have a unique produce code.<\/p>\n<p>Like: k00-k99, k{0-9}{A-Z}.<\/p>\n<ol>\n<li>\n<p>Create the agent in the Agent Builder\nagent information\ndata source\nruntime configuration<\/p>\n<\/li>\n<li>\n<p>Install and test the agent\noutput and install the agent\nconfig and start agent in MTEMS.\nconfirm agent data\nrevise and retest as needed<\/p>\n<\/li>\n<li>\n<p>Add application support\ncreate in TEP, including queries, workspaces, situations, and take actions.\nImport application support into agent in Agent Builder.\nRetest the agent and application support<\/p>\n<\/li>\n<li>\n<p>Create an installation solution.\nCreate solution install package from the agent.\nCreate solution install package from the package.\nRun the image on the target location.<\/p>\n<\/li>\n<\/ol>\n<h1 id=\"install-agent\">install agent<\/h1>\n<p>Three ways to instal the agent.<\/p>\n<p>You must install the TEMS and TEPS support on TEMS(HTEMS) and TEPS server.<\/p>\n<ol>\n<li>\n<p>generate the agent files in an ITM installation on this machine<\/p>\n<p>\u901a\u8fc7GUI\u5feb\u901f\u5b89\u88c5\uff0cAgent Builder\u548cITM\uff08TEMS\u548cTEPS\uff09\u5b89\u88c5\u5728\u540c\u4e00\u53f0\u673a\u5668\u4e0a\u3002<\/p>\n<\/li>\n<li>\n<p>generate a solution install package<\/p>\n<p>\u521b\u5efa\u5b89\u88c5\u955c\u50cf\u6765\u5b89\u88c5\uff0cwindows\u7684.exe\u548clinux\/unix\u7684.bin\u3002<\/p>\n<\/li>\n<li>\n<p>create a compressed file so that the agent can be installed on another system<\/p>\n<p>\u547d\u4ee4\u884c\u5b89\u88c5\u3002\n\u751f\u6210\u4e00\u4e2a.zip\u548c\u4e00\u4e2a.tgz\u6587\u4ef6\u3002\n\u5305\u62ecwindows\u7684.bat\u548clinux\/unix\u7684.sh\u5b89\u88c5\u6587\u4ef6<\/p>\n<p>\u5b89\u88c5\u4e0b\u9762\u4e09\u4e2a\u5305(\u7b49\u6548\u65b9\u6cd5\u4e00\uff09\uff1a<\/p>\n<pre><code> InstallIra.bat\/.sh itm_install_location [[-h Hub_TEMS_hostname] -u HUB_TEMS_username -p Hub_TEMS_password]\nInstallIra.bat C:\\IBM\\ITM -h &lt;HTEMS&gt; -u &lt;username&gt; -p &lt;password&gt; # for windows\n.\/InstallIra.sh \/opt\/IBM\/ITM -h &lt;HTEMS&gt; -u &lt;username&gt; -p &lt;password&gt; # for linux\n<\/code><\/pre>\n<p>\u5728\u88ab\u76d1\u63a7\u673a\u5668\u5b89\u88c5agent:<\/p>\n<pre><code> installIraAgent.bat\/.sh itm_install_location\ninstallIraAgent.bat C:\\IBM\\ITM # for windows\n.\/installIraAgent.sh \/opt\/IBM\/ITM # for linux\n<\/code><\/pre>\n<p>\u5728TEMS(HTEMS)\u670d\u52a1\u5668\u5b89\u88c5\u5bf9agent\u7684\u652f\u6301\uff1a<\/p>\n<pre><code> installIraAgentTEMS.bat\/.sh itm_install_location [[-h Hub_TEMS_hostname] -u HUB_TEMS_username -p Hub_TEMS_password]\ninstallIraAgentTEMS.bat C:\\IBM\\ITM # for local HTEMS windows server.\n.\/installIraAgentTEMS.sh \/opt\/IBM\/ITM # for local HTEMS linux server.\n<\/code><\/pre>\n<p>\u5728TEPS\u670d\u52a1\u5668\u5b89\u88c5\u5bf9agent\u7684\u652f\u6301\uff1a<\/p>\n<pre><code> installIraAgentTEPS.bat\/.sh itm_install_location [[-h TEPS_hostname] -u TEPS_username -p TEPS_password]\ninstallIraAgentTEPS.bat C:\\IBM\\ITM # for local TEPS windows server.\n.\/installIraAgentTEPS.sh \/opt\/IBM\/ITM # for local TEPS linux server.\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<h1 id=\"config-agent\">config agent<\/h1>\n<p>\u9700\u8981\u4e3aagent\u6307\u5b9aHTEMS\u670d\u52a1\u5668\uff0c\u5e76\u91cd\u542fagent\uff0c\u7136\u540e\u91cd\u542fTEPD\u3002<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7Tivoli Enterprise Monitoring Service\u6765\u914d\u7f6e\u548c\u542f\u52a8\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u3002<\/p>\n<p>\u67e5\u770b\u6240\u6709agent\u4fe1\u606f\uff1a<\/p>\n<pre><code>\/opt\/IBM\/ITM\/bin\/cinfo -i # check the productcode and platformCode.\n<\/code><\/pre>\n<p>config agent:<\/p>\n<pre><code>.\/itmcmd config -A productcode\n<\/code><\/pre>\n<p>start agent:<\/p>\n<pre><code>.\/tacmd agent start productcode\n<\/code><\/pre>\n<h1 id=\"uninstall-agent\">uninstall agent<\/h1>\n<ol>\n<li>\n<p>uninstall from commandline.<\/p>\n<p>windows:<\/p>\n<pre><code> cd ITM_INSTALL\/TMAITM6\ncd C:\\IBM\\ITM\\TMAITM6_x64\nkxx_uninstall.vbs ITM_INSTALL\nK&lt;product code&gt;_uninstall.vbs C:\\IBM\\ITM\n<\/code><\/pre>\n<p>linux\/unix:<\/p>\n<pre><code> \/opt\/IBM\/ITM\/bin\/uninstall.sh [-f] [-i] [-h install_dir] productcode platformCode\n<\/code><\/pre>\n<\/li>\n<li>\n<p>Remove from TEP client(clear offline entry)<\/p>\n<\/li>\n<\/ol>\n<h1 id=\"monitoring-windows-resources\">Monitoring windows resources<\/h1>\n<ol>\n<li>\n<p>Windows Management Instrumentation(WMI)<\/p>\n<\/li>\n<li>\n<p>Windows Performance Monitor(Perfmon)<\/p>\n<\/li>\n<li>\n<p>Windows Event Log<\/p>\n<\/li>\n<\/ol>\n<h1 id=\"monitoring-process-and-command-return-codes\">Monitoring process and command return codes<\/h1>\n<ol>\n<li>\n<p>Monitoring process<\/p>\n<\/li>\n<li>\n<p>Monitoring command return code<\/p>\n<\/li>\n<\/ol>\n<h1 id=\"monitoring-custom-data-sources\">Monitoring custom data sources<\/h1>\n<ol>\n<li>\n<p>Monitoring script output<\/p>\n<\/li>\n<li>\n<p>Monitoring log file<\/p>\n<\/li>\n<\/ol>\n<h1 id=\"monitoring-remote-resources\">Monitoring remote resources<\/h1>\n<ol>\n<li>\n<p>Monitoring SNMP<\/p>\n<\/li>\n<li>\n<p>Monitoring CIM<\/p>\n<\/li>\n<li>\n<p>Moitoring JMX<\/p>\n<\/li>\n<\/ol>\n<hr>\n<hr>\n<h1 id=\"netcoolomnibus\">Netcool\/OMNIbus<\/h1>\n<p>IBM Tivoli Netcool\/OMNIbus<\/p>\n<p>TEC: Tivoli Enterprise Console, \u5df2\u7ecf\u88abNetcool\/OMNIbus\u66ff\u4ee3\u3002<\/p>\n<p>windows:<\/p>\n<pre><code>C:\\Program Files(x86)\\IBM\\NCOhome\n<\/code><\/pre>\n<p>linux\/aix:<\/p>\n<pre><code>\/opt\/IBM\/NCOhome\n<\/code><\/pre>\n<p>Browser\u7248\u672c\u9700\u8981\u5b89\u88c5IBM\u7684JRE\uff0c\u5728C:\\Program Files\\IBM\\Java70\u3002<\/p>\n<h1 id=\"eif\">EIF<\/h1>\n<p>EIF: Event Integration Facility<\/p>"},{"title":"Find","link":"https:\/\/canuxcheng.com\/post\/shell_find\/","pubDate":"Wed, 20 Apr 2016 13:55:36 +0800","guid":"https:\/\/canuxcheng.com\/post\/shell_find\/","description":"<h1 id=\"find\">find<\/h1>\n<p>Find \u67e5\u627e\uff0c\u7528\u4e8e\u5728\u76ee\u5f55\u4e2d\u67e5\u627e\u3002<\/p>\n<pre><code>find path options tests actions\npath \u8def\u5f84\noptions \u9009\u9879\ntests \u6d4b\u8bd5\nactions \u52a8\u4f5c\n<\/code><\/pre>\n<p>optioins\u9009\u9879:<\/p>\n<pre><code>-follow\n-depth\n-maxdepth\n-mindepth\nfind dir -mindepth n \u6307\u5b9a\u6700\u5c0f\u7684\u76ee\u5f55\u6df1\u5ea6\uff0c\u81f3\u5c11\u4ecedir\u5f80\u4e0bn\u7ea7\u76ee\u5f55\u5f00\u59cb\u5f80\u4e0b\u641c\u7d22\uff0cdir\u548cn\u7ea7\u4e4b\u95f4\u7684\u5ffd\u7565\u3002\nfind dir -maxdepth n \u6307\u5b9a\u6700\u5927\u76ee\u5f55\u6df1\u5ea6\uff0c\u4e0d\u641c\u7d22n\u7ea7\u4e4b\u540e\u7684\u76ee\u5f55\u3002\n<\/code><\/pre>\n<p>test\u9009\u9879\u5f88\u591a\uff1a<\/p>\n<pre><code>-newer pattern \u6bd4pattern\u6587\u4ef6\u8981\u65b0\n-user pattern \u6587\u4ef6\u5c5e\u4e3b\u662fpattern\n-name pattern \u67e5\u627e\u548ctype\u5339\u914d\u7684\n-iname pattern \u67e5\u627e\u548ctype\u5339\u914d\u7684\uff0c\u4f1a\u5ffd\u7565\u5927\u5c0f\u5199\n-iwholename\n-path pattern \u6309\u7167\u6587\u4ef6\u8def\u5f84\u5339\u914d\n-type c c\u662f\u6587\u4ef6\u7c7b\u578b\uff0c\u6309\u7167\u6587\u4ef6\u7c7b\u578b\u5339\u914d\u6587\u4ef6\nc\u53ef\u4ee5\u662f\uff1af \u5e38\u89c4\u6587\u4ef6 d \u76ee\u5f55 p \u547d\u540d\u7ba1\u9053 l \u7b26\u53f7\u94fe\u63a5 b \u5757\u8bbe\u5907 c \u5b57\u7b26\u8bbe\u5907 s \u5957\u63a5\u5b57\n-size +\/- nk\/c\/w\/k\/b\/M\/G \u5339\u914d\u5927\u4e8e\u6216\u5c0f\u4e8en kb\/.. \u7684\u6587\u4ef6\nfind dir -size +10M # \u67e5\u627e\u5927\u4e8e10M\u7684\u6587\u4ef6\n-perm XXX \u57fa\u4e8e\u6587\u4ef6\u6743\u9650\u7684\u5339\u914d\nfind dir -perm 644 # \u67e5\u627e\u6743\u9650\u662f644\u7684\u6587\u4ef6\nfind dir \u2013atime\/mtime\/ctime +\/-n \u6839\u636e\u65f6\u95f4\u7d2f\u5339\u914d\uff0catime\u8868\u793a\u8bbf\u95ee\u65f6\u95f4\uff0cmtime\u8868\u793a\u4fee\u6539\u65f6\u95f4\uff0cctime\u8868\u793a\u53d8\u5316\u65f6\u95f4\uff0c+\u8868\u793a\u5927\u4e8e\uff0c-\u8868\u793a\u5c0f\u4e8e\uff0c\u5355\u4f4d\u662f\u5929\u3002\n-a\/-and pattern\n-o\/-or pattern\n\uff01\/-not pattern\nfind dir ! test pattern \u5217\u51fa\u6240\u6709\u6ca1\u6709\u6309\u7167-options pattern\u6a21\u5f0f\u7684\u9879\n\\(...\\) \u4f7f\u7528\u62ec\u53f7\u9700\u8981\u7528\u5f15\u53f7\u6765\u5f15\u7528\u3002\n<\/code><\/pre>\n<p>action\u9009\u9879\uff1a<\/p>\n<pre><code>-prune \u5982\u679c\u662f\u4e00\u4e2a\u6307\u5b9a\u7684\u76ee\u5f55\u5c31\u5ffd\u7565\u8fd9\u4e2a\u76ee\u5f55,\u8981\u7528-path\u6307\u5b9a\u76ee\u5f55.\n-print \u6253\u5370\uff0c\u6362\u884c\u7b26\u7ed3\u5c3e,\u6240\u6709\u7ed3\u679c\u4e00\u884c\u4e00\u4e2a\u3002\n-print0 \u6253\u5370\uff0c\u7a7a\u5b57\u7b26\u7ed3\u5c3e\uff0c\u6240\u6709\u7ed3\u679c\u6253\u5370\u5230\u4e00\u884c\u3002\n-delete \u5220\u9664\n-exec command # \u6267\u884c\u4e00\u4e2a\u547d\u4ee4\nexec command {} \\;\noperators: find\u53ef\u4ee5\u7528\u4e00\u4e9b\u8fd0\u7b97\u7b26\u6765\u8fde\u63a5\u591a\u4e2atest\u6761\u4ef6\u3002\n\uff01expr #\u53d6\u53cd\nexpr1 -a expr2 #\u4e0e\u8fd0\u7b97\uff0c\u53ef\u4ee5\u7701\u7565-a\nexpr1 -o expr2 #\u6216\u8fd0\u7b97\n\u67e5\u627e\u5f53\u524d\u76ee\u5f55\u4e0b\u9664\u4e86develop\u91cc\u9762\u7684\u6587\u4ef6\u4ee5\u5916\u768430\u5929\u4e4b\u5185\u4fee\u6539\u8fc7\u7684.txt\u6587\u4ef6\nfind . -path .\/develop -prune -o -mtime -30 -type f -name &quot;*.txt&quot; -print\n<\/code><\/pre>\n<p>\u5c06\u524d\u9762\u7684\u547d\u4ee4\u7684\u7ed3\u679c\u901a\u8fc7\u7ba1\u9053\u548cxargs\u4f5c\u4e3a\u540e\u9762\u547d\u4ee4\u7684\u8f93\u5165\uff0c\u7c7b\u4f3c\u4e8efind\u547d\u4ee4\u7684-exec\u9009\u9879\u3002<\/p>\n<p>\u683c\u5f0f \uff1acommand1 | xargs -options command2<\/p>\n<pre><code>xargs -n number \u8bbe\u7f6e\u6bcf\u884c\u663e\u793a\u7684\u53c2\u6570\u6570\u91cf\u4e3anumber\u3002\nxargs -d char \u6307\u5b9achar\u4e3a\u754c\u5b9a\u7b26\uff0c\u4e5f\u5c31\u662f\u5c06char\u6362\u6210\u7a7a\u683c\u3002\nxargs -I {} \u5c06\u547d\u4ee4\u53c2\u6570\u7528STDIN\u7684\u53c2\u6570\u66ff\u6362\u6389\u3002\nxargs -0 \u4ee5\/0\u4e3a\u5b9a\u754c\u7b26\uff0c\u800c\u4e0d\u662f\u7a7a\u683c\u3002\nfind . -name \u201c*.c\u201d | xargs wc -l\nfind . -name \u201c*.c\u201d -exec wc -l {} \\;\nwc -l `find . -name \u201c*.c\u201d`\n<\/code><\/pre>"},{"title":"Grep","link":"https:\/\/canuxcheng.com\/post\/shell_grep\/","pubDate":"Wed, 20 Apr 2016 13:55:36 +0800","guid":"https:\/\/canuxcheng.com\/post\/shell_grep\/","description":"<h1 id=\"grep\">grep<\/h1>\n<p>grep\u76f8\u5173\u7684\u547d\u4ee4\uff1a<\/p>\n<pre><code>grep\negrep == grep -E\nfgrep == grep -F\nrgrep == grep -r\n<\/code><\/pre>\n<p>grep:<\/p>\n<pre><code>grep [OPTIONS] PATTERN [FILE\/DIR...]\ngrep [OPTIONS] [-e PATTERN | -f FILE] [FILE\/DIR...]\n<\/code><\/pre>\n<p>options:<\/p>\n<pre><code># Matcher Selection\n-G, --basic-regexp grep\u9ed8\u8ba4\u53ea\u652f\u6301BRE, \u53ea\u80fd\u4f7f\u7528\u57fa\u672c\u7684RE\n-E, --extended-regexp \u9009\u62e9ERE, \u53ef\u4ee5\u4f7f\u7528\u6269\u5c55\u7684RE\n# grep -E &quot;pattern1|pattern2&quot; \u6bd4\u5982\u652f\u6301\u6216\u8fd0\u7b97\n-F, --fixed-strings\n-P, --perl-regexp perl RE\n# Matching Control\n-e PATTERN, --regexp=PATTERN \u53ef\u4ee5\u6307\u5b9a\u591a\u4e2apattern\n# grep -e pattern1 -e pattern2 filename \u76f8\u5f53\u4e8e\u6216\u8fd0\u7b97\uff0c\u6ee1\u8db3\u4e00\u4e2a\u5c31\u88ab\u8fc7\u6ee4\u51fa\u6765\n-f FILE, --file=FILE \u6587\u4ef6\u7684\u6bcf\u4e00\u884c\u5c31\u662f\u4e00\u4e2apattern.\n-i, --ignore-case \u5ffd\u7565\u5927\u5c0f\u5199\n-v, --invert-match \u5ffd\u7565\u542b\u6709pattern\u7684\u884c\n-w, --word-regexp \u7cbe\u786e\u5339\u914d\u4e00\u4e2a\u5355\u8bcd\n-x, --line-regexp \u7cbe\u786e\u5339\u914d\u4e00\u884c\n-y\n# General Output Control\n-c, --count \u7edf\u8ba1\u5339\u914d\u5230\u7684\u884c\u6570\n--color[=WHEN], --colour[=WHEN] \u8f93\u51fa\u5339\u914d\u7684pattern\u9ad8\u4eae\n-L, --files-without-match \u5217\u51fa\u6ca1\u6709\u5339\u914d\u5230\u7684\u6587\u4ef6\u540d\n-l, --files-with-matches \u5217\u51fa\u5339\u914d\u5230\u7684\u6587\u4ef6\u7684\u6587\u4ef6\u540d\n# grep -rl pattern1 | xargs grep -r pattern2 \u76f8\u5f53\u4e8e\u4e0e\u8fd0\u7b97\uff0c\u8fc7\u6ee4\u540c\u65f6\u6ee1\u8db3\u4e24\u4e2apattern\n-m NUM, --max-count=NUM\n-o, --only-matching \u53ea\u8f93\u51fa\u5339\u914d\u7684\u90e8\u5206\n# grep -o pattern filename | wc -l \u7edf\u8ba1\u5339\u914d\u7684\u884c\u6570\n-q, --quiet, --silent \u4e0d\u6253\u5370\u67e5\u627e\u7684\u7ed3\u679c\n-s, --no-messages\n# Output Line Prefix Control\n-b, --byte-offset \u6253\u5370\u5339\u914d\u7684\u5b57\u7b26\u6570\u6216\u504f\u79fb\u91cf\n-H, --with-filename\n-h, --no-filename\n--label=LABEL\n-n, --line-number \u6253\u5370\u5339\u914d\u7684\u884c\u7684\u884c\u53f7\n-T, --initial-tab\n-u, --unix-byte-offsets\n-Z, --null\n# Context Line Control\n-A NUM, --after-context=NUM \u6253\u5370\u5339\u914d\u5230\u7684\u884c\u7684\u540eNUM\u884c\n-B NUM, --before-context=NUM \u6253\u5370\u5339\u914d\u5230\u7684\u884c\u7684\u524dNUM\u884cj\n-C NUM, -NUM, --context=NUM \u6253\u5370\u5339\u914d\u5230\u7684\u884c\u7684\u524dNUM\u884c\u548c\u540eNUM\u884c\n# File and Directory Selection\n-a, --text\n--binary-files=TYPE\n-D ACTION, --devices=ACTION\n-d ACTION, --directories=ACTION\n--exclude=GLOB \u6392\u9664\u67e5\u627e\u6307\u5b9a\u7684\u6587\u4ef6\n--exclude-from=FILE\n--exclude-dir=DIR \u6392\u9664\u67e5\u627e\u6307\u5b9a\u7684\u76ee\u5f55\n-I\n--include=GLOB \u6307\u5b9a\u67e5\u627e\u7684\u6587\u4ef6\n-r, --recursive \u9012\u5f52\u67e5\u627e\n-R, --dereference-recursive \u9012\u5f52\u67e5\u627e\n# grep -nR\/-nr pattern filename \u9605\u8bfb\u6e90\u7801\u53ef\u4ee5\u9012\u5f52\u67e5\u627e\u5e76\u6253\u5370\u884c\u53f7\n# Other Options\n--line-buffered\n--mmap\n-U, --binary\n-z, --null-data\n<\/code><\/pre>\n<h1 id=\"ack\">ack<\/h1>\n<p>ack\/ack2\u662fgrep\u7684\u5347\u7ea7\u7248<\/p>\n<p>ack:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/beyondgrep\/ack\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/beyondgrep\/ack<\/a><\/p>\n<p>ack2(ack-grep):<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/beyondgrep\/ack2\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/beyondgrep\/ack2<\/a><\/p>\n<h1 id=\"ag\">ag<\/h1>\n<p>ack\/ack2\u7684\u5347\u7ea7\u7248<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/ggreer\/the_silver_searcher\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/ggreer\/the_silver_searcher<\/a><\/p>\n<p>\u5b89\u88c5\uff1a<\/p>\n<pre><code>$sudo apt-get install silversearcher-ag\n$sudo yum install the_silver_searcher\n<\/code><\/pre>\n<p>\u4f7f\u7528\uff1a<\/p>\n<pre><code>$man ag\n<\/code><\/pre>"},{"title":"Development","link":"https:\/\/canuxcheng.com\/post\/devops_dev\/","pubDate":"Fri, 15 Apr 2016 09:41:39 +0000","guid":"https:\/\/canuxcheng.com\/post\/devops_dev\/","description":"<h1 id=\"development\">Development<\/h1>\n<p>\u5f00\u53d1\u76f8\u5173\u7684\u5de5\u5177<\/p>\n<p>\u4f20\u7edf\u7684\u8f6f\u4ef6\u5f00\u53d1\u91c7\u7528\u7684\u662f\u7011\u5e03\u5f0f\u5f00\u53d1\u6d41\u7a0b\uff0e<\/p>\n<p>\u73b0\u4ee3\u7684\u8f6f\u4ef6\u5f00\u53d1\u91c7\u7528\u7684\u662f\u654f\u6377\u5f00\u53d1\u6d41\u7a0b(Agile development).<\/p>\n<p>Alpha: inner test version.<\/p>\n<p>Beta: outer test version.<\/p>\n<p>RC: release candidate. \u6700\u7ec8\u7248\u672c\u4e4b\u524d\u7684\u6700\u540e\u4e00\u4e2a\u7248\u672c\uff0e\u4e5f\u53ebgamma.<\/p>\n<p>RTM: release to manufacture, \u6700\u7ec8\u7248<\/p>\n<p>GA: generally avaliable. stable\/production.<\/p>\n<hr>\n<h1 id=\"\u600e\u6837\u9009\u62e9licenses\">\u600e\u6837\u9009\u62e9Licenses<\/h1>\n<p><a class=\"link\" href=\"http:\/\/choosealicense.com\/licenses\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/choosealicense.com\/licenses\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/choosealicense.com\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/choosealicense.com\/<\/a><\/p>\n<p><img src=\"https:\/\/canuxcheng.com\/images\/license.jpeg\"\nloading=\"lazy\"\nalt=\"pic\"\n><\/p>\n<hr>\n<h1 id=\"semver\">semver<\/h1>\n<p>\u8bed\u4e49\u5316\u7248\u672c\uff0e<\/p>\n<p><a class=\"link\" href=\"http:\/\/semver.org\/lang\/zh-CN\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/semver.org\/lang\/zh-CN\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/mojombo\/semver\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/mojombo\/semver<\/a><\/p>\n<pre><code>\u4e3b\u7248\u672c\u53f7.\u6b21\u7248\u672c\u53f7.\u4fee\u8ba2\u53f7\nMajor.Minor.Patch\nMajor: \u505a\u4e86\u4e0d\u517c\u5bb9\u7684API\u4fee\u6539\nMinor: \u505a\u4e86\u5411\u4e0b\u517c\u5bb9\u7684\u529f\u80fd\u6027\u65b0\u589e\nPatch: \u505a\u4e86\u5411\u4e0b\u517c\u5bb9\u7684\u95ee\u9898\u4fee\u6b63\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u6587\u6863\u9605\u8bfb\u5de5\u5177\">\u6587\u6863\u9605\u8bfb\u5de5\u5177<\/h1>\n<h2 id=\"zeal\">zeal<\/h2>\n<h2 id=\"dash\">dash<\/h2>\n<hr>\n<h1 id=\"cookiecutter\">cookiecutter<\/h1>\n<p>\u4e00\u4e2a\u5feb\u901f\u5efa\u7acb\u5de5\u7a0b\u6a21\u677f\u7684\u547d\u4ee4\u884c\u5de5\u5177\uff0e<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/audreyr\/cookiecutter\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/audreyr\/cookiecutter<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/audreyr\/cookiecutter-pypackage\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/audreyr\/cookiecutter-pypackage<\/a><\/p>\n<pre><code>$sudo -E pip install cookiecutter\n# \u521b\u5efapython\u9879\u76ee\n$cookiecutter https:\/\/github.com\/audreyr\/cookiecutter-pypackage.git\n# \u521b\u5efadjango\u683c\u5f0f\u7684python\u9879\u76ee\n$cookiecutter https:\/\/github.com\/pydanny\/cookiecutter-django\n# \u521b\u5efaopenstack\u683c\u5f0f\u7684python\u9879\u76ee\n$cookiecutter https:\/\/git.openstack.org\/openstack-dev\/cookiecutter.git\n$cookiecutter https:\/\/github.com\/openstack-dev\/cookiecutter.git\n<\/code><\/pre>\n<hr>\n<h1 id=\"bumpversion\">bumpversion<\/h1>\n<p>\u7248\u672c\u7ba1\u7406\u5de5\u5177<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/peritus\/bumpversion\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/peritus\/bumpversion<\/a><\/p>\n<pre><code>$sudo -E pip install bumpversion\n# put config in setup.cfg\n[bumpversion]\ncurrent_version = 1.2.0\nfiles = pymonitoringplugins\/__init__.py\n$bumpversion major\/minor\/patch --commit # commit\u65b0\u7248\u672c\n<\/code><\/pre>\n<hr>"},{"title":"DevOps","link":"https:\/\/canuxcheng.com\/post\/devops\/","pubDate":"Fri, 15 Apr 2016 09:41:39 +0000","guid":"https:\/\/canuxcheng.com\/post\/devops\/","description":"<h1 id=\"devops\">DevOps<\/h1>\n<p>DevOps\u5305\u62ecChatOps, \u654f\u6377\u5f00\u53d1\uff0c\u6301\u7eed\u96c6\u6210,\u6301\u7eed\u4ea4\u4ed8,\u6301\u7eed\u53d1\u5e03\/\u90e8\u7f72\uff0cQA(\u81ea\u52a8\u5316\u6d4b\u8bd5\uff09\uff0c\u667a\u80fd\u76d1\u63a7\u548c\u65e5\u5fd7\u7ba1\u7406\u7b49\u5185\u5bb9\uff0e<\/p>\n<p>DevOps\u6d89\u53ca\u5230\u4e09\u4e2a\u90e8\u95e8\uff1a<\/p>\n<ul>\n<li>Development<\/li>\n<li>Operations<\/li>\n<li>Quality Assurance<\/li>\n<\/ul>\n<hr>\n<h1 id=\"ci\">CI<\/h1>\n<p>Continuous Integration.<\/p>\n<p>\u6301\u7eed\u96c6\u6210\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u7f16\u8bd1\u4ee3\u7801.<\/li>\n<li>\u9759\u6001\u4ee3\u7801\u5206\u6790.<\/li>\n<li>\u81ea\u52a8\u5316\u6d4b\u8bd5\uff0c\u4f8b\u5982selenium.<\/li>\n<li>\u4ee3\u7801\u8986\u76d6\u7387\u5206\u6790.<\/li>\n<li>\u6784\u5efa\uff0c\u4f8b\u5982docker.<\/li>\n<\/ul>\n<h1 id=\"cd\">CD<\/h1>\n<p>Continuous Delivery.<\/p>\n<p>\u6301\u7eed\u4ea4\u4ed8\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u5c06\u901a\u8fc7\u6d4b\u8bd5\u7684\u4ee3\u7801\u90e8\u7f72\u5230Staging.<\/li>\n<\/ul>\n<h1 id=\"continuous-releasedeploy\">Continuous Release\/Deploy<\/h1>\n<p>\u6301\u7eed\u90e8\u7f72\/\u53d1\u5e03\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u5c06\u901a\u8fc7\u8bc4\u5ba1\u7684\u4ea4\u4ed8\u4ee3\u7801\u90e8\u7f72\u5230Production.<\/li>\n<\/ul>\n<hr>\n<h1 id=\"cicd\u7684\u5de5\u5177\">CI\/CD\u7684\u5de5\u5177<\/h1>\n<p>\u6301\u7eed\u96c6\u6210\u548c\u90e8\u7f72<\/p>\n<h2 id=\"jenkins\">Jenkins<\/h2>\n<h2 id=\"travis-ci\">travis CI<\/h2>\n<p><a class=\"link\" href=\"https:\/\/travis-ci.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/travis-ci.org\/<\/a><\/p>\n<p>travis CI\u662f\u57fa\u4e8egithub\u7684CI\u5de5\u5177, \u90e8\u7f72\u4ee3\u7801\u7136\u540e\u8fd0\u884c\u6d4b\u8bd5\u4ee3\u7801.<\/p>\n<p>\u5728github\u9879\u76ee\u6dfb\u52a0.travis.yml\u6587\u4ef6\uff1a<\/p>\n<pre><code>language: python\npython:\n- &quot;2.7&quot;\ninstall:\n- pip install -r requirements.txt\n- pip install coveralls\nscript:\n- coverage run --source=pymonitoringplugins setup.py test\nafter_success:\n- coveralls\n<\/code><\/pre>\n<h2 id=\"circleci\">circleci<\/h2>\n<p><a class=\"link\" href=\"https:\/\/circleci.com\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/circleci.com\/<\/a><\/p>\n<hr>\n<h1 id=\"coverage\u7684\u5de5\u5177\">coverage\u7684\u5de5\u5177<\/h1>\n<p>\u7edf\u8ba1\u5355\u5143\u6d4b\u8bd5\u7684\u8986\u76d6\u7387<\/p>\n<h2 id=\"coveralls\">coveralls<\/h2>\n<p><a class=\"link\" href=\"https:\/\/coveralls.io\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/coveralls.io\/<\/a><\/p>\n<h2 id=\"codecov\">codecov<\/h2>\n<p><a class=\"link\" href=\"https:\/\/codecov.io\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/codecov.io\/<\/a><\/p>\n<hr>\n<h1 id=\"stackstorm\">stackstorm<\/h1>\n<p>StackStorm is a platform for integration and automation across services and tools, taking actions in response to events.<\/p>\n<p>For DevOps and ChatOps.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/StackStorm\/st2\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/StackStorm\/st2<\/a><\/p>\n<h1 id=\"drone\">Drone<\/h1>\n<p>Drone is a Continuous Delivery platform built on Docker, written in Go<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/drone\/drone\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/drone\/drone<\/a><\/p>\n<h1 id=\"supervisor\">supervisor<\/h1>\n<p>Supervisor process control system for UNIX\/Linux.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/Supervisor\/supervisor\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/Supervisor\/supervisor<\/a><\/p>\n<pre><code>$ pip install supervisor\n<\/code><\/pre>\n<hr>\n<h1 id=\"redmine\">redmine<\/h1>\n<p>ruby\u5f00\u53d1\u7684\u9879\u76ee\u7ba1\u7406\u5de5\u5177,\u96c6\u6210bug\u548cwiki\u5de5\u5177\uff0e<\/p>\n<hr>\n<h1 id=\"dokuwiki\">dokuwiki<\/h1>\n<p>php\u5f00\u53d1\u7684wiki\u7ba1\u7406\u5de5\u5177<\/p>\n<hr>\n<h1 id=\"atlassian\">Atlassian<\/h1>\n<p>Jira for Porject Management.<\/p>\n<p>Bitbucket for Source code management.<\/p>\n<p>Bamboo for CI\/CD.<\/p>\n<hr>\n<h1 id=\"bugzilla\">bugzilla<\/h1>\n<p>perl\u5f00\u53d1\u7684bug\u8ffd\u8e2a\u7cfb\u7edf\uff0e<\/p>\n<hr>\n<h1 id=\"errbot\">errbot<\/h1>\n<p>python\u5f00\u53d1\u7684ChatOps\u5de5\u5177\uff0e<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/errbotio\/errbot\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/errbotio\/errbot<\/a><\/p>\n<hr>\n<h1 id=\"zulip\">zulip<\/h1>\n<p>\u56e2\u961f\u804a\u5929\u5de5\u5177\u4ecb\u7ecd<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/zulip\/zulip\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/zulip\/zulip<\/a><\/p>"},{"title":"Gitlab","link":"https:\/\/canuxcheng.com\/post\/devops_gitlab\/","pubDate":"Fri, 15 Apr 2016 09:41:39 +0000","guid":"https:\/\/canuxcheng.com\/post\/devops_gitlab\/","description":"<h1 id=\"gitlab\">Gitlab<\/h1>\n<p>gitlab\u662f\u5f00\u6e90\u7684\u6709web\u754c\u9762\u7684git\u670d\u52a1\u5668\uff0e<\/p>\n<p><a class=\"link\" href=\"https:\/\/about.gitlab.com\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/about.gitlab.com\/<\/a><\/p>\n<p>\u5b89\u88c5gitlab:<\/p>\n<pre><code>sudo apt-get install -y curl openssh-server ca-certificates\nsudo apt-get install -y postfix\ncurl https:\/\/packages.gitlab.com\/install\/repositories\/gitlab\/gitlab-ce\/script.deb.sh | sudo bash\nsudo EXTERNAL_URL=&quot;http:\/\/gitlab.example.com&quot; apt-get install gitlab-ce\n<\/code><\/pre>\n<p>\u914d\u7f6e:<\/p>\n<pre><code>\/etc\/gitlab\/gitlab.rb\n<\/code><\/pre>\n<p>\u5347\u7ea7gitlab:<\/p>\n<p>\u9700\u8981\u5148\u5347\u7ea7\u5230\u4e0b\u4e2amajor\u7248\u672c\u7684\u6700\u540e\u4e00\u4e2a\u7a33\u5b9a\u7248.<\/p>\n<pre><code>current:\u00a0 \u00a09.4.7\npatch: gitlab-ce=9.5.10\npatch:\u00a0gitlab-ce_10.8.7\npatch: gitlab-ce=11.11.8\npatch: gitlab-ce=12.0.12\ntarget: 12.10.14\n<\/code><\/pre>\n<p>runner:<\/p>\n<pre><code>#sudo curl -L --output \/usr\/local\/bin\/gitlab-runner https:\/\/gitlab-runner-downloads.s3.amazonaws.com\/latest\/binaries\/gitlab-runner-linux-amd64\nsudo chmod +x \/usr\/local\/bin\/gitlab-runner\nsudo gitlab-runner install --user=canux --working-directory=\/home\/canux\/gitlab\nsudo gitlab-runner register\nsudo gitlab-runner start\n<\/code><\/pre>\n<hr>\n<h1 id=\"cli\">CLI<\/h1>\n<p>\u5907\u4efd\uff1a<\/p>\n<pre><code>&gt; \u4fee\u6539\u5907\u4efd\u8def\u5f84\uff1agitlab_rails['backup_path'] = &quot;\/var\/opt\/gitlab\/backups&quot;\n# gitlab-rake gitlab:backup:create\n<\/code><\/pre>\n<p>\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e:<\/p>\n<pre><code># gitlab-ctl reconfigure\n<\/code><\/pre>\n<p>\u91cd\u542f:<\/p>\n<pre><code># gitlab-ctl restart\/start\/stop\n<\/code><\/pre>"},{"title":"Jenkins","link":"https:\/\/canuxcheng.com\/post\/devops_jenkins\/","pubDate":"Fri, 15 Apr 2016 09:41:39 +0000","guid":"https:\/\/canuxcheng.com\/post\/devops_jenkins\/","description":"<h1 id=\"jenkins\">Jenkins<\/h1>\n<p>Jenkins is a self-contained, open source automation server which can be used to automate all sorts of tasks such as building, testing, and deploying software.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/jenkinsci\/jenkins\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/jenkinsci\/jenkins<\/a><\/p>\n<p>\u5b89\u88c5\u597dJenkins\u540e\u5b89\u88c5\u9700\u8981\u7684\u63d2\u4ef6\uff0e<\/p>\n<p>\u5b89\u88c5jenkins:<\/p>\n<pre><code># download jenkins.war and install java8.\n$ java -jar jenkins.war --httpPort=8080\n$ firefox http:\/\/localhost:8080\n<\/code><\/pre>\n<p>\u8bbe\u7f6e\u5f00\u673a\u81ea\u52a8\u542f\u52a8\uff0c\u4e0d\u7528\u6bcf\u6b21\u4ece\u7ec8\u7aef\u542f\u52a8:<\/p>\n<pre><code>$ vim \/etc\/systemd\/system\/jenkins.service\n$ systemctl daemon-reload\n$ systemctl enable jenkins.service\n$ systemctl start jenkins\n<\/code><\/pre>\n<p>jinkens\u4e3b\u76ee\u5f55:<\/p>\n<pre><code># \u9ed8\u8ba4\u4e3b\u76ee\u5f55\u5728\/home\/canux\/.jenkins\n<\/code><\/pre>\n<hr>\n<h1 id=\"nodes\">nodes<\/h1>\n<p>\u6dfb\u52a0\u8282\u70b9\u9700\u8981\u5b89\u88c5\u548cmaster\u7248\u672c\u4e00\u6837\u7684java.<\/p>\n<p>on jenkins agent:<\/p>\n<ol>\n<li>install java.<\/li>\n<li>create folder and grant permission. (\/home\/jenkins)<\/li>\n<\/ol>\n<p>on jenkins:<\/p>\n<ol>\n<li>create credential and node.<\/li>\n<\/ol>\n<hr>\n<h1 id=\"plugins\">plugins<\/h1>\n<h2 id=\"thinbackup\">thinbackup<\/h2>\n<p>\u5907\u4efd\u63d2\u4ef6\uff0c\u4e3b\u8981\u5907\u4efdjenkins\u4e3b\u76ee\u5f55.<\/p>\n<h2 id=\"pipeline\">pipeline<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/jenkinsci\/pipeline-plugin\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/jenkinsci\/pipeline-plugin<\/a><\/p>\n<p>\u4f7f\u7528pipeline\u9700\u8981\u5148\u5b89\u88c5pipeline\u63d2\u4ef6.<\/p>\n<p>pipeline\u662fgroovy\u8bed\u6cd5\u7684jenkins\u7684DSL.<\/p>\n<h2 id=\"blueocean\">blueocean<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/jenkinsci\/blueocean-plugin\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/jenkinsci\/blueocean-plugin<\/a><\/p>\n<h1 id=\"git-plugin\">git plugin<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/jenkinsci\/git-plugin\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/jenkinsci\/git-plugin<\/a><\/p>\n<h1 id=\"docker-plugin\">docker plugin<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/jenkinsci\/docker-workflow-plugin\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/jenkinsci\/docker-workflow-plugin<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/docs.cloudbees.com\/docs\/admin-resources\/latest\/plugins\/docker-workflow\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.cloudbees.com\/docs\/admin-resources\/latest\/plugins\/docker-workflow<\/a><\/p>\n<h1 id=\"k8s\">k8s<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/jenkinsci\/kubernetes-plugin\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/jenkinsci\/kubernetes-plugin<\/a><\/p>\n<hr>\n<h1 id=\"docker\">docker<\/h1>\n<p>\u5728docker\u4e0a\u6267\u884c\u6d41\u6c34\u7ebf<\/p>\n<pre><code>agent {\ndocker {\nimage 'maven:3-alpine'\nlabel 'my-defined-label'\nargs '-v \/tmp:\/tmp'\n}\n}\nagent {\n\/\/ Equivalent to &quot;docker build -f Dockerfile.build --build-arg version=1.0.2 .\/build\/\ndockerfile {\nfilename 'Dockerfile.build'\ndir 'build'\nlabel 'my-defined-label'\nadditionalBuildArgs '--build-arg version=1.0.2'\n}\n}\n<\/code><\/pre>"},{"title":"Operations","link":"https:\/\/canuxcheng.com\/post\/devops_ops\/","pubDate":"Fri, 15 Apr 2016 09:41:39 +0000","guid":"https:\/\/canuxcheng.com\/post\/devops_ops\/","description":"<h1 id=\"operations\">Operations<\/h1>\n<p>\u8fd0\u7ef4\u76f8\u5173\u7684\u5de5\u5177\uff0e<\/p>\n<hr>\n<h1 id=\"\u6279\u91cf\u914d\u7f6e\u7ba1\u7406\">\u6279\u91cf\u914d\u7f6e\u7ba1\u7406<\/h1>\n<h2 id=\"puppet\">puppet<\/h2>\n<h2 id=\"chef\">chef<\/h2>\n<h2 id=\"salt\">salt<\/h2>\n<h2 id=\"ansible\">ansible<\/h2>\n<hr>\n<h1 id=\"\u5bc6\u7801\u7ba1\u7406\u5de5\u5177\">\u5bc6\u7801\u7ba1\u7406\u5de5\u5177<\/h1>\n<h2 id=\"keepass\">keepass<\/h2>\n<p><a class=\"link\" href=\"http:\/\/keepass.info\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/keepass.info\/<\/a><\/p>\n<h2 id=\"keepassx\">KeePassX<\/h2>\n<p><a class=\"link\" href=\"https:\/\/www.keepassx.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.keepassx.org\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/keepassx\/keepassx\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/keepassx\/keepassx<\/a><\/p>\n<hr>"},{"title":"Admin","link":"https:\/\/canuxcheng.com\/post\/linux_admin\/","pubDate":"Fri, 15 Apr 2016 09:41:39 +0800","guid":"https:\/\/canuxcheng.com\/post\/linux_admin\/","description":"<h1 id=\"linux-admin\">Linux Admin<\/h1>\n<p>dpkg: ubuntu, debian.<\/p>\n<p>rpm: fedora, centos, redhat.<\/p>\n<p>zypper: suse.<\/p>\n<hr>\n<h1 id=\"linux\u7cfb\u7edf\u5e38\u7528\u7684\u5b89\u88c5\u548c\u914d\u7f6e\">Linux\u7cfb\u7edf\u5e38\u7528\u7684\u5b89\u88c5\u548c\u914d\u7f6e<\/h1>\n<h2 id=\"terminalizer\">terminalizer<\/h2>\n<p>\u7ec8\u7aef\u5f55\u5236\u5de5\u5177<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/faressoft\/terminalizer\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/faressoft\/terminalizer<\/a><\/p>\n<h2 id=\"virtualbox\">virtualbox<\/h2>\n<p>\u5f00\u673a\u81ea\u52a8\u6302\u8f7d\u5171\u4eab\u6587\u4ef6\u5939<\/p>\n<pre><code># \u624b\u52a8\u6302\u5728\u547d\u4ee4, \u9700\u8981\u5b89\u88c5\u589e\u5f3a\u529f\u80fd\n$ mount -t vboxsf FolderNameOnWindows \/path\/on\/linux\n# \u5b9e\u73b0\u5f00\u673a\u81ea\u52a8\u6302\u8f7d\n$ sudo vim \/etc\/rc.local\nmount.vboxsf -w ShareFolderNameOnWindows MountPointOnLinux\n<\/code><\/pre>\n<h2 id=\"xrdp\">xrdp<\/h2>\n<p>\u4ecewindows\u7684RDP\u8fdc\u7a0b\u8fde\u63a5linux.<\/p>\n<p>use RDP on windows to connect to ubuntu16.04.<\/p>\n<pre><code>sudo dpkg -i tigervncserver_1.6...deb # download and install tigervncserver first.\nsudo apt-get install -f\nsudo apt-get instal xrdp -y\necho unity &gt; ~\/.xsession\n<\/code><\/pre>\n<p>use RDP on windows to connect to ubuntu14.04.<\/p>\n<pre><code>sudo apt-get install xrdp\nsudo apt-get install xfce4\necho xfce4-session &gt; ~\/.xsession\nsudo vim \/etc\/xrdp\/startwm.sh\n# add 'startxfce4' to last line.\nsudo service xrdp restart\n<\/code><\/pre>\n<h2 id=\"\u6e05\u7406\u5185\u5b58\u7684buffcache\">\u6e05\u7406\u5185\u5b58\u7684buff\/cache<\/h2>\n<pre><code>echo 3 &gt; \/proc\/sys\/vm\/drop_caches\n# reboot\u624d\u80fd\u6539\u56de\u9ed8\u8ba4\u76840\n<\/code><\/pre>\n<h2 id=\"\u7ec8\u7aef\u73b0\u5b9e\u8d85\u5927\u827a\u672f\u5b57\">\u7ec8\u7aef\u73b0\u5b9e\u8d85\u5927\u827a\u672f\u5b57<\/h2>\n<pre><code>$ sudo apt-get install figlet\n$ figlet &lt;text&gt;\n<\/code><\/pre>\n<hr>\n<h1 id=\"ubuntudebian\u5b89\u88c5\u540e\u7684\u57fa\u672c\u914d\u7f6e\">Ubuntu\/Debian\u5b89\u88c5\u540e\u7684\u57fa\u672c\u914d\u7f6e<\/h1>\n<pre><code>sudo apt-get install build-essential make libssl-dev\n<\/code><\/pre>\n<h2 id=\"apt-mirror\">apt mirror<\/h2>\n<pre><code>vim \/etc\/apt\/sources.list\n# deb http:\/\/ip:port\/path ubuntu16\/\n# deb [trusted=yes] https:\/\/&lt;user&gt;:&lt;pw&gt;@ip:port\/path ubuntu16\/\ndeb [trusted=yes] https:\/\/user:pw@mirror.com\/mirror ubuntu16\/\nvim \/etc\/apt\/apt.conf\nAcquire::https::mirror.com::Verify-Peer &quot;false&quot;;\nAcqhire::https::mirror.com::Verify-Host &quot;false&quot;;\n<\/code><\/pre>\n<h2 id=\"\u4e2d\u6587\u8f93\u5165\u6cd5\">\u4e2d\u6587\u8f93\u5165\u6cd5<\/h2>\n<p>\u5b89\u88c5\u4e00\u4e2a\u4e2d\u6587\u8f93\u5165\u6cd5\u6846\u67b6fcitx(IBus, SCIM, UIM)\uff1a<\/p>\n<pre><code>$ sudo apt-get install fcitx\n<\/code><\/pre>\n<p>\u5b89\u88c5\u4e00\u79cd\u8f93\u5165\u6cd5\u5f15\u64ce\uff1a<\/p>\n<pre><code>sudo apt-get install fcitx-googlepinyin\nsudo apt-get install fcitx-sunpinyin\nsudo apt-get install fcitx-libpinyin\nsudo apt-get install fcitx-sougoupinyin\nsudo apt-get install fcitx-cloudpinyin\n<\/code><\/pre>\n<p>\u914d\u7f6e\u7a0b\u5e8f\uff1a<\/p>\n<pre><code>kcm-fcitx - for qt - &lt;https:\/\/github.com\/fcitx\/kcm-fcitx&gt;\nfcitx-configtool - for gtk - &lt;https:\/\/github.com\/fcitx\/fcitx-configtool&gt;\n<\/code><\/pre>\n<p>\u5728\u952e\u76d8\u8f93\u5165\u65b9\u5f0f\u7cfb\u7edf\u4eceibus\u6539\u4e3afcitx\uff0c\u7136\u540e\u91cd\u542f\u3002<\/p>\n<h2 id=\"dconf\u4fee\u6539\u914d\u7f6e\">dconf\u4fee\u6539\u914d\u7f6e<\/h2>\n<p>\u4e5f\u53ef\u4ee5\u901a\u8fc7\u7cfb\u7edf\u81ea\u5e26\u7684dconf\u547d\u4ee4\u4fee\u6539\uff0e<\/p>\n<pre><code>$ sudo apt-get install dconf-editor\n<\/code><\/pre>\n<p>gedit\u6253\u5f00txt\u6587\u4ef6\u4e71\u7801<\/p>\n<pre><code># org-&gt;gnome-&gt;gedit-&gt;preferences-&gt;encodings-&gt;auto-detected \u6dfb\u52a0'GB2312','GBK',...\n<\/code><\/pre>\n<p>\u5f00\u542f\u8fdc\u7a0b\u684c\u9762\u65e0\u5bc6\u7801\u767b\u9646<\/p>\n<pre><code>$ dconf write \/org\/gnome\/desktop\/remote-access\/require-encryption false\nor\n# org-&gt;gnome-&gt;desktop-&gt;remote-access-&gt;require-encryption false\n<\/code><\/pre>\n<h2 id=\"\u6302\u8f7du\u76d8\u5931\u8d25\">\u6302\u8f7dU\u76d8\u5931\u8d25<\/h2>\n<p>\u79fb\u52a8\u786c\u76d8\u6216\u8005u\u76d8\u4e0d\u80fd\u6302\u8f7d\uff0c\u5220\u6389\/etc\/fstab\u7684\u5173\u4e8esdb\u7684\u884c\uff0c\u4fdd\u5b58\u540e\u91cd\u65b0\u63d2\u62d4\u3002<\/p>\n<h2 id=\"\u521b\u5efa\u684c\u9762\u56fe\u6807\u6bd4\u5982eclipse\">\u521b\u5efa\u684c\u9762\u56fe\u6807\uff08\u6bd4\u5982eclipse\uff09<\/h2>\n<pre><code>cd \/usr\/share\/applications\nsudo vi XXX.desktop\n<\/code><\/pre>\n<p>\u6dfb\u52a0\u5fc5\u8981\u5c5e\u6027\u540e\u62d6\u5230\u684c\u9762\u6216\u542f\u52a8\u680f\u5373\u53ef\u3002<\/p>\n<h2 id=\"\u5b89\u88c5qq\">\u5b89\u88c5QQ<\/h2>\n<pre><code>sudo apt-get install libgtk2.0-0:i386\nsudo apt-get install lib32ncurses5\nsudo apt-get install -f\nsudo dpkg -i fonts-wqy-microhei_0.2.0-beta-2_all.deb\nsudo dpkg -i ttf-wqy-microhei_0.2.0-beta-2_all.deb\nsudo dpkg -i wine-qqintl_0.1.3-2_i386.deb\n<\/code><\/pre>\n<h2 id=\"\u5b89\u88c5\u6587\u6863\u7684\u5305\">\u5b89\u88c5\u6587\u6863\u7684\u5305<\/h2>\n<p>\u624b\u518c\u4f4d\u4e8e\/usr\/share\/man<\/p>\n<pre><code>sudo apt-get install glibc-doc manpages-dev manpages-posix-dev manpages-zh\n<\/code><\/pre>\n<h2 id=\"\u8bb0\u5f55\u7ec8\u7aef\u64cd\u4f5c\">\u8bb0\u5f55\u7ec8\u7aef\u64cd\u4f5c<\/h2>\n<p>\u5b89\u88c5\u76f8\u5173\u5de5\u5177:<\/p>\n<pre><code>$sudo apt-get install ttyrec\n$sudo apt-get install imagemagick\n$hg clone https:\/\/bitbucket.org\/antocuni\/tty2gif\n<\/code><\/pre>\n<p>\u5f00\u59cb\u8bb0\u5f55:<\/p>\n<pre><code>$ttyrec\n<\/code><\/pre>\n<p>\u5728\u7ec8\u7aef\u64ad\u653e\u8bb0\u5f55\u6587\u4ef6ttyrecord:<\/p>\n<pre><code>$ttyplay ttyrecord\n<\/code><\/pre>\n<p>\u5c06ttyrecord\u6587\u4ef6\u8f6c\u5316\u6210gif\u6587\u4ef6:<\/p>\n<pre><code>$tty2gif.py typing ttyrecord\n<\/code><\/pre>\n<p>\u5c06\u591a\u4e2agif\u6587\u4ef6\u5408\u5e76\u6210\u4e00\u4e2a\u6587\u4ef6:<\/p>\n<pre><code>$convert -limit memory 2mb -limit map 2mb -delay 2 -loop 0 *.gif example.gif\n<\/code><\/pre>\n<h2 id=\"\u6dfb\u52a0\u7528\u6237\u4e3a\u7ba1\u7406\u5458\">\u6dfb\u52a0\u7528\u6237\u4e3a\u7ba1\u7406\u5458<\/h2>\n<pre><code>$ vim \/etc\/sudoers\nuser ALL = (ALL:ALL) ALL\n<\/code><\/pre>\n<h2 id=\"ubuntu\u7f51\u7edc\u8bbe\u7f6e\">Ubuntu\u7f51\u7edc\u8bbe\u7f6e<\/h2>\n<p>\u67e5\u770bdns\uff1a<\/p>\n<pre><code>$ systemd-resolve --status\n<\/code><\/pre>\n<p>ubuntu\u4fee\u6539hostname:<\/p>\n<pre><code>$ sudo vim \/etc\/hostname\nnew-hostname\n$ sudo vim \/etc\/hosts\nip-address hostname\n$ sudo reboot\n<\/code><\/pre>\n<p>\u8bbe\u7f6e\u7cfb\u7edf\u4ee3\u7406:<\/p>\n<pre><code>$ vim \/etc\/profile.d\/sys_proxy.sh\nhttp_proxy=&quot;http:\/\/proxy-server:port&quot;\nhttps_proxy=&quot;http:\/\/proxy-server:port&quot;\nftp_proxy=&quot;http:\/\/proxy-server:port&quot;\nno_proxy=localhost,127.0.0.1,...\nexport http_proxy ftp_proxy https_proxy no_proxy\n<\/code><\/pre>\n<p>\u8bbe\u7f6e\u9759\u6001IP:<\/p>\n<pre><code>$ ifconfig\n# \u67e5\u770b\u7f51\u5361\uff0cubuntu14.04 eth0, ubuntu16.04 ens160\n$ vim \/etc\/network\/interfaces\nauto eth0\niface eth0 inet static\naddress 192.168.0.1\nnetmask 255.255.255.0\ngateway 192.168.0.0\ndns-nameservers 8.8.8.8\n$ sudo service networking restart\n<\/code><\/pre>\n<p>ubuntu18:<\/p>\n<pre><code>netplan:\n$ sudo vim \/etc\/netplan\/*.yaml\nnetwork:\nversion: 2\nrenderer: networkd\nethernets:\nens160:\ndhcp4: no\naddresses: [192.168.1.0\/23]\ngateway4: 193.168.0.1\nnameservers:\naddresses: [8.8.8.8]\n$ sudo netplan apply\n<\/code><\/pre>\n<h2 id=\"ubuntu-vlan\">ubuntu vlan<\/h2>\n<p>vlan\u9700\u8981\u5185\u6838\u6a21\u57578021q<\/p>\n<pre><code>$ echo &quot;8021q&quot; &gt;&gt; \/etc\/modules\nauto vlan1023\niface vlan1023 inet static\naddress 18.28.4.123\nnetmask 255.255.255.0\ngateway 18.28.4.1\nvlan-raw-device eth0\n<\/code><\/pre>\n<p>\u521b\u5efavlan<\/p>\n<pre><code>\/\/ \u521b\u5efavlan(eth0.10), attach\u5230interface(eth0)\nauto eth0.10\niface eth0.10 inet manual\nvlan-raw-device eth0\n<\/code><\/pre>\n<h2 id=\"ubuntu-bridge\">ubuntu bridge<\/h2>\n<pre><code># \u9700\u8981\u7ed1\u5b9a\u5230interface\u624d\u9700\u8981\u914d\u7f6einterface.\nauto eth0\niface eth0 inet manual\nauto br0\niface br0 inet dhcp\n# For static configuration delete or comment out the above line and uncomment the following:\n# iface br0 inet static\n# address 192.168.1.10\n# netmask 255.255.255.0\n# gateway 192.168.1.1\n# dns-nameservers 192.168.1.5\n# dns-search example.com\nbridge_ports eth0\n# \u4e0d\u7ed1\u5b9a\u5230interface\u5c31\u662fnone\n# bridge_ports none\nbridge_stp off\nbridge_fd 0\nbridge_maxwait 0\n<\/code><\/pre>\n<p>\u521b\u5efabridge<\/p>\n<pre><code>\/\/ \u521b\u5efabridge\uff0cattach\u5230vlan.\nauto br0\niface br0 inet static\naddress 172.16.0.4\nnetmask 255.255.240.0\nbridge_ports eth0.10\nbridge_stp off\nbridge_fd 0\nbridge_vlan_aware yes\n<\/code><\/pre>\n<h2 id=\"e-sub-process-usrbindpkg-returned-an-error-code-1\">E: Sub-process \/usr\/bin\/dpkg returned an error code (1)<\/h2>\n<p>method1:<\/p>\n<pre><code>$ sudo mkdir -p \/var\/lib\/dpkg\/info\/package\n$ sudo mv \/var\/lib\/dpkg\/info\/package.* \/var\/lib\/dpkg\/info\/package\n<\/code><\/pre>\n<p>method2:<\/p>\n<pre><code>$ sudo apt-get purge package\n$ sudo apt-get install package\n<\/code><\/pre>\n<h2 id=\"ubuntu\u5b89\u88c5\u914d\u7f6epython37\">ubuntu\u5b89\u88c5\u914d\u7f6epython3.7<\/h2>\n<p>ubuntu16.04\u81ea\u5e26python3.5, ubuntu18.04\u81ea\u5e26python3.6.<\/p>\n<p>\u6d4b\u8bd5: ubuntu16.04\/18.04\u5b89\u88c5python3.7<\/p>\n<pre><code>$ sudo apt-get install software-properties-common\n$ sudo add-apt-repository ppa:deadsnakes\/ppa\n$ sudo apt-get update\n$ sudo apt-get install python3.7 python3.7-gdbm python3.7-dev\n$ sudo update-alternatives --install \/usr\/bin\/python3 python3 \/usr\/bin\/python3.7 1\n$ sudo update-alternatives --install \/usr\/bin\/python python \/usr\/bin\/python3.7 1\n$ sudo update-alternatives --config python\n$ sudo update-alternatives --config python3\n$ sudo apt-get purge python-pip python3-pip\n$ sudo rm -rf \/usr\/bin\/pip* \/usr\/local\/bin\/pip* \/usr\/lib\/python3*\/dist-packages\/pip \/usr\/local\/lib\/python3.*\/dist-packages\/pip\n$ sudo apt-get install python3-pip\n$ sudo pip3 install -U pip\n\/\/ ubuntu16.04\u901a\u8fc7apt-get\u5b89\u88c5\u7684c-binding\u5305\u9ed8\u8ba4\u8fd8\u662f\u5230python3.5.\n\/\/ ubuntu18.04 \u662f\u5230python3.6.\n#!\/usr\/bin\/env bash\nfor PKG in `find \/usr\/lib\/python3\/dist-packages -name &quot;*.so&quot;`\ndo\n\u00a0 \u00a0 DIR=`dirname ${PKG}`\n\u00a0 \u00a0 OLD=`basename ${PKG}`\n\u00a0 \u00a0 NEW=`echo ${OLD} | sed 's\/35m\/37m\/g'`\n\u00a0 \u00a0 cp -f ${PKG} ${DIR}\/${NEW}\ndone\n<\/code><\/pre>\n<hr>\n<h1 id=\"centosfedoraredhat\u5b89\u88c5\u540e\u7684\u57fa\u672c\u914d\u7f6e\">Centos\/Fedora\/Redhat\u5b89\u88c5\u540e\u7684\u57fa\u672c\u914d\u7f6e<\/h1>\n<pre><code>$ sudo yum -y install epel-release kernel-devel gcc gcc-c++\n<\/code><\/pre>\n<h2 id=\"centos\u7f51\u7edc\u914d\u7f6e\">Centos\u7f51\u7edc\u914d\u7f6e<\/h2>\n<p>\u5b89\u88c5mini\u7248\u672c\u4e4b\u540e\u914d\u7f6e\u7f51\u7edc\uff1a<\/p>\n<pre><code>$ vi \/etc\/sysconfig\/network-scripts\/ifcfg-enxxx\nONBOOT=no -&gt; yes\n# service network restart\n$ sudo yum install net-tools\n$ ifconfig\n<\/code><\/pre>\n<p>\u8bbe\u7f6e\u9759\u6001IP:<\/p>\n<pre><code>$ vim \/etc\/sysconfig\/network-scripts\/ifcfg-enxxx\nONBOOT=yes\nBOOTPROTO=static # dhcp(\u81ea\u52a8\u83b7\u53d6), static(\u56fa\u5b9aIP), node(\u624b\u52a8\u8bbe\u7f6e)\nPREFIX=&quot;21&quot;\nIPADDR=&quot;192.168.0.1&quot;\nNETMASK=&quot;255.255.255.0&quot;\nGATEWAY=&quot;192.168.0.0&quot;\nDNS1=&quot;192.168.0.0&quot;\n$ sudo nmcli c reload\n<\/code><\/pre>\n<p>\u8bbe\u7f6e\u53ef\u4ee5\u540c\u65f6\u8bbf\u95ee\u5916\u7f51\u548c\u672c\u5730\u8fde\u63a5\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre><code># \u7f51\u5361\uff11\u7528\u4e8e\u5916\u7f51\u8fde\u63a5\n# settings -&gt; network -&gt; network card1 -&gt; NAT\n$ cat \/etc\/sysconfig\/network-scripts\/ifcfg-en01\nBOOTPROTO=dhcp # \u81ea\u52a8\u83b7\u53d6ip\nONBOOT=yes\nUUID # \u901a\u8fc7$ nmcli con show \u547d\u4ee4\u67e5\u770b\nHWADDR # \u901a\u8fc7 $ ip addr \u547d\u4ee4\u67e5\u770b, \u8fd9\u4e2a\u53ef\u4ee5\u4e0d\u8bbe\u7f6e\n# \u7f51\u5361\uff12\u7528\u4e8e\u672c\u5730\u5c40\u57df\u7f51\nsetting -&gt; network-&gt; network card2 -&gt; host-only\n# cp \/etc\/sysconfig\/network-scripts\/ifcfg-en01 \/etc\/sysconfig\/network-scripts\/ifcfg-en02\n$ vim \/etc\/sysconfig\/network-scripts\/ifcfg-en02\nNAME\nDEVICE\nBOOTPROTO=static\nONBOOT=yes\nUUID\nHWADDR\nIPADDR=192.168.56.102\n$ sudo service network restart\n<\/code><\/pre>\n<p>\u4fee\u6539hostname,\u5c40\u57df\u7f51\u53ef\u4ee5\u6839\u636ehostname\u76f8\u4e92\u8bbf\u95ee\uff1a<\/p>\n<pre><code>$ sudo vim \/etc\/sysconfig\/network\nNETWORKING=yes\nHOSTNAME=new-hostname\n$ sudo vim \/etc\/hostname\nnew-hostname\n$ sudo vim \/etc\/hosts\nip-address hostname\n$ sudo reboot\n<\/code><\/pre>\n<h2 id=\"centos\u5b89\u88c5\u589e\u5f3a\u529f\u80fd\">centos\u5b89\u88c5\u589e\u5f3a\u529f\u80fd<\/h2>\n<pre><code>$ sudo mkdir -p \/media\/cdrom\n$ sudo mount \/dev\/cdrom \/media\/cdrom\n$ cd \/media\/cdrom\n$ sudo .\/VBoxLinuxAdditions.run --nox11\n<\/code><\/pre>"},{"title":"Agile","link":"https:\/\/canuxcheng.com\/post\/devops_agile\/","pubDate":"Fri, 15 Apr 2016 09:41:39 +0800","guid":"https:\/\/canuxcheng.com\/post\/devops_agile\/","description":"<h1 id=\"agile-methodologies\">Agile methodologies<\/h1>\n<p>Agile\u7684\u5177\u4f53\u65b9\u6cd5\u6709Scrum, XP\u548ckanban.<\/p>\n<p>ThoughtWorks\u516c\u53f8\u7684Martin Fowler\u63d0\u51fa\u7684\u654f\u6377\u65b9\u6cd5\uff0e<\/p>\n<hr>\n<h1 id=\"scrum\">Scrum<\/h1>\n<p>Scrum\u65b9\u6cd5\u7531Ken Schwaber\u548cJeff Sutherland \u63d0\u51fa.<\/p>\n<p>scrum\u662f\u4e00\u4e2a\u7528\u4e8e\u5f00\u53d1\u548c\u7ef4\u62a4\u590d\u6742\u4ea7\u54c1\u7684\u6846\u67b6\uff0c\u662f\u4e00\u4e2a\u589e\u91cf\u7684\uff0c\u8fed\u4ee3\u7684\u5f00\u53d1\u8fc7\u7a0b\uff0e<\/p>\n<p>sprint: \u4e00\u4e2a\u77ed\u7684\u8fed\u4ee3\u5468\u671f\uff0e\u4e00\u822c\uff12\u5230\uff14\u5468\uff0e<\/p>\n<p>backlog: \u6309\u5546\u4e1a\u4ef7\u503c\u6392\u5e8f\u7684\u9700\u6c42\u5217\u8868\uff0e<\/p>\n<h2 id=\"scrum\u6846\u67b6\u7684\u4e09\u4e2a\u89d2\u8272\">scrum\u6846\u67b6\u7684\u4e09\u4e2a\u89d2\u8272<\/h2>\n<p>product owner: \u4ea7\u54c1\u8d1f\u8d23\u4eba<\/p>\n<p>scrum master: \u654f\u6377\u6559\u7ec3\u548c\u9886\u5bfc\u8005<\/p>\n<p>scrum team\uff1adeveloper<\/p>\n<h2 id=\"scrum\u6846\u67b6\u7684\u4e09\u4e2a\u5de5\u4ef6\">scrum\u6846\u67b6\u7684\u4e09\u4e2a\u5de5\u4ef6<\/h2>\n<p>Product backlog: \u6574\u4e2a\u4ea7\u54c1\u5f85\u5f00\u53d1\u9700\u6c42\u5217\u8868<\/p>\n<p>sprint backlog: \u4e00\u6b21\u8fed\u4ee3\u7684\u5f85\u5f00\u53d1\u9700\u6c42\u5217\u8868<\/p>\n<p>increment: \u4ea7\u54c1\u589e\u91cf<\/p>\n<h2 id=\"scrum\u6846\u67b6\u7684\u4e94\u4e2a\u4e8b\u4ef6\">scrum\u6846\u67b6\u7684\u4e94\u4e2a\u4e8b\u4ef6<\/h2>\n<p>sprint planning meeting: sprint\u8ba1\u5212\u4f1a\u8bae<\/p>\n<p>Daily Scrum Meeting\/DSM: \u6bcf\u65e5\u7ad9\u7acb\u4f1a\u8bae<\/p>\n<p>sprint review meeting: sprint\u8bc4\u5ba1\u4f1a\u8bae<\/p>\n<p>sprint retrospective meeting: sprint\u56de\u987e\u4f1a\u8bae<\/p>\n<p>product backlog refinement: \u4ea7\u54c1backlog\u68b3\u7406\u4f1a\u8bae<\/p>\n<h2 id=\"scrum\u6846\u67b6\u7684\u4e94\u4e2a\u4ef7\u503c\u89c2\">scrum\u6846\u67b6\u7684\u4e94\u4e2a\u4ef7\u503c\u89c2<\/h2>\n<p>\u627f\u8bfa<\/p>\n<p>\u4e13\u6ce8<\/p>\n<p>\u5f00\u653e<\/p>\n<p>\u5c0a\u91cd<\/p>\n<p>\u52c7\u6c14<\/p>\n<h2 id=\"scrum\u6846\u67b6\u7684\u56db\u5927\u652f\u67f1\">scrum\u6846\u67b6\u7684\u56db\u5927\u652f\u67f1<\/h2>\n<p>\u8fed\u4ee3\u5f00\u53d1<\/p>\n<p>\u589e\u91cf\u4ea4\u4ed8<\/p>\n<p>\u81ea\u7ec4\u7ec7\u56e2\u961f<\/p>\n<p>\u9ad8\u4f18\u5148\u7ea7\u7684\u9700\u6c42\u9a71\u52a8<\/p>\n<hr>\n<h1 id=\"xp\">XP<\/h1>\n<p>Extreme Programming<\/p>"},{"title":"Ansible","link":"https:\/\/canuxcheng.com\/post\/devops_ansible\/","pubDate":"Fri, 15 Apr 2016 09:41:39 +0800","guid":"https:\/\/canuxcheng.com\/post\/devops_ansible\/","description":"<h1 id=\"ansible\">Ansible<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/ansible\/ansible\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/ansible\/ansible<\/a><\/p>\n<p><a class=\"link\" href=\"http:\/\/www.ansible.com.cn\/index.html\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.ansible.com.cn\/index.html<\/a><\/p>\n<p>ansible\u901a\u8fc7SSH\u6765\u8fdc\u7a0b\u7ba1\u7406Linux\/Unix\u673a\u5668\uff0e<\/p>\n<p>ansible\u901a\u8fc7winrm+powershell\u6765\u8fdc\u7a0b\u7ba1\u7406Windows\u673a\u5668\uff0e<\/p>\n<p>\u5b89\u88c5:<\/p>\n<pre><code>$ sudo pip install ansible\n$ sudo apt-get install ansible\n$ sudo yum install ansible\n$ brew install ansible sshpass\n<\/code><\/pre>\n<p>\u914d\u7f6e\uff1a<\/p>\n<p>\u53c2\u8003Network-SSH\u5b9e\u73b0\u4ececontroller\u5230\u6240\u6709node\u7684\u65e0\u5bc6\u7801\u767b\u9646<\/p>\n<p>\u914d\u7f6e\u6587\u4ef6\u6267\u884c\u987a\u5e8f:<\/p>\n<pre><code>ANSIBLE_CONFIG\nansible.cfg\n.ansible.cfg\n\/etc\/ansible\/ansible.cfg\n<\/code><\/pre>\n<p>\u624b\u52a8\u914d\u7f6e:<\/p>\n<pre><code>$ sudo vim \/etc\/ansible\/ansible.cfg\n[defaults]\nask_pass = False\nhost_key_checking = False\n<\/code><\/pre>\n<h2 id=\"ansible\u547d\u4ee4\">ansible\u547d\u4ee4<\/h2>\n<p>ansible\u8fd0\u884c\u547d\u4ee4\u7684\u4e24\u79cd\u65b9\u5f0f\uff1a<\/p>\n<ol>\n<li>Ad-hoc\u76f8\u5f53\u4e8e\u76f4\u63a5\u8fd0\u884cshell\u547d\u4ee4<\/li>\n<li>playbooks\u76f8\u5f53\u4e8e\u8fd0\u884cshell\u811a\u672c<\/li>\n<\/ol>\n<p>ansible:<\/p>\n<pre><code>$ ansible group1:group1:group3\/all -i inventory ......\n$ansible --help\n-m MODULE_NAME, --module-name=MODULE_NAME # \u6267\u884c\u6a21\u5757\uff0c\u9ed8\u8ba4\u662fcommand\n-M MODULE_PATH, --module-path=MODULE_PATH # \u6307\u5b9a\u6a21\u5757\u7684\u8def\u5f84\n-a MODULE_ARGS, --args=MODULE_ARGS # \u6a21\u5757\u7684\u53c2\u6570\n-i INVENTORY, --inventory INVENTORY # \u9ed8\u8ba4\/etc\/ansible\/hosts, \u9700\u8981\u6307\u5b9ahosts\u5206\u7ec4\n-f FORKS, --forks=FORKS # \u6307\u5b9a\u5e76\u53d1\u8fdb\u7a0b\u7684\u6570\u91cf\n-C, --check\n-D, --diff\n-l SUBSET, --limit=SUBSET\n--syntax-check\n--list-hosts\n-v, --verbose # -v, -vvv, -vvvv\n# \u63d0\u6743\u9009\u9879\n-b, --become\n--become-method=BECOME_METHOD # sudo(default)\/su\/pbrun\/pfexec\/runas\/doas\n--become-user=BECOME_USER # root(default)\n-K, --ask-become-pass\n# \u8fde\u63a5\u9009\u9879\n-u REMOTE_USER\n--ssh-common-args\n--ssh-extra-args\n-T TIMEOUT # default 10s\n-K, --ask-pass\n<\/code><\/pre>\n<hr>\n<h2 id=\"inventory\">inventory<\/h2>\n<p>inventory\u5305\u62ec\u4e3b\u673a\u548c\u5206\u7ec4,\u4ee5\u53ca\u4e3b\u673a\u53d8\u91cf\u548c\u5206\u7ec4\u53d8\u91cf. \u9ed8\u8ba4\u662f<code>\/etc\/ansible\/hosts<\/code>\u6587\u4ef6.<\/p>\n<p>\u53ef\u4ee5\u662fini\u683c\u5f0f\uff0c\u4e5f\u53ef\u4ee5\u662fyaml\u683c\u5f0f.<\/p>\n<p>\u53ef\u4ee5\u662f\u4e00\u4e2a\u6587\u4ef6\uff0c\u53ef\u4ee5\u662f\u591a\u4e2a\u6587\u4ef6\uff0c\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a\u76ee\u5f55.<\/p>\n<pre><code>$ ansible all -i inventory\/folder\/ ......\n<\/code><\/pre>\n<p>ini\u683c\u5f0f:<\/p>\n<pre><code>\u5b9a\u4e49\u4e3b\u673a\u548c\u4e3b\u673a\u53d8\u91cf\n[host1]\nnode1\nansible_connection=ssh\nansible_host=host\nansible_port=port\nansible_user=user\nansible_ssh_pass=password\n\u5b9a\u4e49\u5206\u7ec4\u548c\u5206\u7ec4\u53d8\u91cf\n[group1]\nnode1\nnode2\n[group1:vars]\nansible_connection=local\/smart\/ssh\/paramiko\nansible_host=\nansible_port=\nansible_user=\nansible_ssh_pass=\nansible_ssh_common_args=\nansible_ssh_extra_args=\nansible_become=\nansible_become_method=\nansible_become_user=\nansible_become_pass=\nansible_become_exe=\nansible_become_flags=\n\u5b9a\u4e49\u5206\u7ec4\u7684\u5206\u7ec4, children\u662f\u56fa\u5b9a\u5199\u6cd5\n[big-group:children]\ngroup1\ngroup2\n<\/code><\/pre>\n<p>yaml:<\/p>\n<pre><code>all:\nhosts: # hosts, \u5b9a\u4e49\u4e3b\u673a\u548c\u4e3b\u673a\u53d8\u91cf\nnode1:\nansible_host:\nansible_port:\nansible_user:\nansible_ssh_pass: &quot;${{ ansible_ssh_pass }}&quot; # use ansible-vault\nchildren: # children, \u5b9a\u4e49\u5206\u7ec4\u548c\u5206\u7ec4\u53d8\u91cf\nproduction:\nhosts:\nnode1:\nnode2:\nvars:\nenv: prod\nstaging:\nhosts:\nnode3:\nnode4:\nvars:\nenv: staging\n<\/code><\/pre>\n<hr>\n<h2 id=\"module\">module<\/h2>\n<p>module\u4e5f\u5c31\u662f\u6240\u8bf4\u7684task plugins\/library plugins.<\/p>\n<pre><code>$ ansible-doc -l\/--list #\u3000\u67e5\u770b\u6240\u6709\u5df2\u7ecf\u5b89\u88c5\u7684\u6a21\u5757\n$ ansible-doc apt # \u67e5\u770bapt\u6a21\u5757\u7684\u6587\u6863\n<\/code><\/pre>\n<h3 id=\"\u5185\u7f6e\u7684\u6a21\u5757\">\u5185\u7f6e\u7684\u6a21\u5757<\/h3>\n<pre><code>$ ansible-docs -l | grep &quot;ansible.builtin&quot;\nping\n<\/code><\/pre>\n<p>\u6267\u884c\u547d\u4ee4<\/p>\n<pre><code>command # \u9ed8\u8ba4\u6a21\u5757\uff0c\u7528\u4e8e\u5728\u8fdc\u7a0b\u673a\u5668\u4e0a\u6267\u884c\u547d\u4ee4\nshell # \u548ccommand\u76f8\u540c\uff0c\u53ea\u662f\u8be5\u6a21\u5757\u652f\u6301\u7ba1\u9053\u548c\u7279\u6b8a\u5b57\u7b26\uff0c\u4e00\u822c\u7528\u6765\u6267\u884c\u811a\u672c\u548c\u590d\u6742\u547d\u4ee4\nraw\nexpect\nscript\ntelnet\n<\/code><\/pre>\n<p>files modules:<\/p>\n<pre><code>copy src dest mode ...\nsynchronize src dest ...\n<\/code><\/pre>\n<p>package modules:<\/p>\n<pre><code>apt name\/deb state=present\/absent\/latest\/build-dep update_cache autoclean autoremove\napt_repository repo state=present\/absent\napt_rpm pkg state=present\/absent\nyum name state=present\/absent\/latest\/installed\/removed\n<\/code><\/pre>\n<hr>\n<h2 id=\"adhoc\">adhoc<\/h2>\n<pre><code>$ ansible group -m &lt;module&gt; -a &lt;args&gt; ...\n$ ansible all -i inventory.yml -m ping -e &quot;@vault.yml&quot; --ask-vault-pass\n<\/code><\/pre>\n<p>copy:<\/p>\n<pre><code>$ ansible group -m copy -a &quot;src=https:\/\/canuxcheng.com\/sr dest=\/dest mode=0655&quot;\n<\/code><\/pre>\n<h2 id=\"ansible-playbooks\">ansible-playbooks<\/h2>\n<p>playbook\u7684\u683c\u5f0f\u662fYAML.<\/p>\n<pre><code>$ ansible-playbook -i inventory playbook.yaml -K -vvv &gt; output.txt\n$ ansible-playbook -i inventory.yml playbook.yml -e &quot;@vault.yml&quot; --ask-vault-pass\n$ ansible-playbook -i inventory.yml playbook.yml -e &quot;@vault.yml&quot; --vault-password-file ~\/.vault_pass.txt\n<\/code><\/pre>\n<p>playbook:<\/p>\n<pre><code>- name: install\nhosts: host-or-group\nbecome: true\nvars:\nvar1: value1\nvar2: value2\ntasks:\n- name: &quot;{{ var1 }}&quot;\nmodule: args\ndebug:\nmsg: &quot;This is a debug message&quot;\n- name: &quot;{{ var2 }}&quot;\nmodule: args\n<\/code><\/pre>\n<p>variables:<\/p>\n<pre><code>register: var # \u7528var\u6765\u5b58\u50a8task\u7684\u7ed3\u679c,\u67e5\u770b\u4e0d\u540c\u6a21\u5757\u7684\u8fd4\u56de\u503c\uff0e\n<\/code><\/pre>\n<p>become:<\/p>\n<pre><code>become: true\nbecome_user: root\nbecome_method: sudo\nbecome_flags:\n<\/code><\/pre>\n<p>debug:<\/p>\n<pre><code>strategy: debug\n<\/code><\/pre>\n<hr>\n<h2 id=\"ansible-vault\">ansible-vault<\/h2>\n<p>ansible-vault\u7528\u4e8e\u52a0\u5bc6\u654f\u611f\u6570\u636e\uff0c\u6bd4\u5982\u5bc6\u7801\u7b49.<\/p>\n<pre><code>$ ansible-vault create vault.yml\n$ ansible-vault edit vault.yml\n$ ansible-vault view vault.yml\n$ ansible-vault encrypt vault.yml\n$ ansible-vault decrypt vault.yml\n<\/code><\/pre>\n<hr>\n<h2 id=\"ansible-inventory\">ansible-inventory<\/h2>\n<p>ansible-inventory\u7528\u4e8e\u67e5\u770binventory\u7684\u5185\u5bb9.<\/p>\n<pre><code>$ ansible-inventory --list -i inventory.yml\n$ ansible-inventory --graph -i inventory.yml\n$ ansible-inventory --host host1 -i inventory.yml # \u67e5\u770b\u4e3b\u673a\u7684\u8be6\u7ec6\u4fe1\u606f\n$ ansible-inventory --tree -i inventory.yml # \u67e5\u770b\u5206\u7ec4\u6811\u72b6\u56fe\n$ ansible-inventory --export -i inventory.yml # \u5bfc\u51fainventory\u5230\u6807\u51c6\u8f93\u51fa\n$ ansible-inventory --validate -i inventory.yml # \u9a8c\u8bc1inventory\u6587\u4ef6\u7684\u8bed\u6cd5\n<\/code><\/pre>\n<hr>\n<h2 id=\"ansible-config\">ansible-config<\/h2>\n<p>ansible-config\u7528\u4e8e\u67e5\u770b\u548c\u7ba1\u7406ansible\u7684\u914d\u7f6e.<\/p>\n<pre><code>$ ansible-config view # \u67e5\u770b\u5f53\u524d\u914d\u7f6e\n$ ansible-config dump --only-changed # \u67e5\u770b\u4fee\u6539\u8fc7\u7684\u914d\u7f6e\n$ ansible-config list --type=defaults # \u5217\u51fa\u6240\u6709\u9ed8\u8ba4\u914d\u7f6e\n$ ansible-config list --type=privilege # \u5217\u51fa\u7279\u6743\u914d\u7f6e\n$ ansible-config list --type=all # \u5217\u51fa\u6240\u6709\u914d\u7f6e\n$ ansible-config init --disabled &gt; ansible.cfg # \u521d\u59cb\u5316\u4e00\u4e2a\u65b0\u7684ansible.cfg\u6587\u4ef6\n<\/code><\/pre>\n<hr>\n<h2 id=\"ansible-pull\">ansible-pull<\/h2>\n<p>ansible-pull\u7528\u4e8e\u4ece\u8fdc\u7a0b\u4ed3\u5e93\u62c9\u53d6playbook\u5e76\u6267\u884c.<\/p>\n<pre><code>$ ansible-pull -U &lt;repo_url&gt; -i inventory.yml playbook.yml\n-U, --url &lt;repo_url&gt; # \u6307\u5b9a\u8fdc\u7a0b\u4ed3\u5e93\u7684URL\n-i, --inventory &lt;inventory&gt; # \u6307\u5b9ainventory\u6587\u4ef6\n-d, --directory &lt;directory&gt; # \u6307\u5b9a\u5de5\u4f5c\u76ee\u5f55\n-C, --checkout &lt;branch&gt; # \u6307\u5b9a\u5206\u652f\n-c, --clean # \u6e05\u7406\u5de5\u4f5c\u76ee\u5f55\n<\/code><\/pre>\n<hr>\n<h2 id=\"ansible-console\">ansible-console<\/h2>\n<p>ansible-console\u662f\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u7684\u547d\u4ee4\u884c\u754c\u9762\uff0c\u53ef\u4ee5\u6267\u884cansible\u547d\u4ee4\u548cplaybook.<\/p>\n<pre><code>$ ansible-console -i inventory.yml\n-i, --inventory &lt;inventory&gt; # \u6307\u5b9ainventory\u6587\u4ef6\n-c, --connection &lt;connection&gt; # \u6307\u5b9a\u8fde\u63a5\u65b9\u5f0f\uff0c\u9ed8\u8ba4\u662fssh\n-u, --user &lt;user&gt; # \u6307\u5b9a\u8fdc\u7a0b\u7528\u6237\n-k, --ask-pass # \u63d0\u793a\u8f93\u5165SSH\u5bc6\u7801\n<\/code><\/pre>\n<hr>\n<h2 id=\"ansible-galaxy\">ansible-galaxy<\/h2>\n<p>ansible-galaxy\u7528\u4e8e\u7ba1\u7406Ansible\u7684\u89d2\u8272\u548c\u96c6\u5408.<\/p>\n<pre><code>$ ansible-galaxy install &lt;role_name&gt; # \u5b89\u88c5\u89d2\u8272\n$ ansible-galaxy remove &lt;role_name&gt; # \u5378\u8f7d\u89d2\u8272\n$ ansible-galaxy list # \u5217\u51fa\u5df2\u5b89\u88c5\u7684\u89d2\u8272\n$ ansible-galaxy init &lt;role_name&gt; # \u521d\u59cb\u5316\u4e00\u4e2a\u65b0\u7684\u89d2\u8272\n$ ansible-galaxy collection install &lt;collection_name&gt; # \u5b89\u88c5\u96c6\u5408\n$ ansible-galaxy collection remove &lt;collection_name&gt; # \u5378\u8f7d\u96c6\u5408\n$ ansible-galaxy collection list # \u5217\u51fa\u5df2\u5b89\u88c5\u7684\u96c6\u5408\n<\/code><\/pre>"},{"title":"Terraform","link":"https:\/\/canuxcheng.com\/post\/devops_terraform\/","pubDate":"Fri, 15 Apr 2016 09:41:39 +0800","guid":"https:\/\/canuxcheng.com\/post\/devops_terraform\/","description":"<h1 id=\"terraform\">Terraform<\/h1>\n<p>install:<\/p>\n<p><a class=\"link\" href=\"https:\/\/learn.hashicorp.com\/tutorials\/terraform\/install-cli\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/learn.hashicorp.com\/tutorials\/terraform\/install-cli<\/a><\/p>\n<p>\u9879\u76ee\u7ed3\u6784\uff1a<\/p>\n<pre><code>.\/terraform\nphz\ncache\nrds\nvpc\neks: (s3, cluster, karpenter, bank-vaults, argocd, argocd-apps)\n.\/terraform\/eks\/argocd-apps:\nprojects\nmain.tf\nprovider.tf\nvariables.tf\nexternal-dns-iam.tf\ncert-manager.tf\nargocd-image-updater.tf\n.\/manifests\nmetrics-server\ningress-nginx\nexternal-dns\ncert-manager\nargocd\nargocd-image-updater\nargo-rollouts\n.\/helm\nargocd (dev.yml, prod.yml)\nargocd-image-updater\nargo-rollouts\ncert-manager\nexternal-dns\ningress-nginx\n<\/code><\/pre>\n<hr>\n<h2 id=\"cli\">CLI<\/h2>\n<p>\u64cd\u4f5c\u5de5\u4f5c\u76ee\u5f55<\/p>\n<pre><code>\/\/ \u521d\u59cb\u5316\u76ee\u5f55\uff0c\u4f1a\u6839\u636e\u914d\u7f6e\u4e0b\u8f7d\u548c\u5b89\u88c5provider.\nterraform init\nterraform get\n<\/code><\/pre>\n<p>\u64cd\u4f5ctf\u6587\u4ef6<\/p>\n<pre><code>\/\/ \u683c\u5f0f\u5316\u6587\u4ef6\nterraform fmt -recursive\n\/\/ \u9a8c\u8bc1\u6587\u4ef6\nterraform validate\n\/\/ \u53ef\u4ee5\u901a\u8fc7\u7ec8\u7aef\u9a8c\u8bc1\u51fd\u6570.\nterraform console\n<\/code><\/pre>\n<p>\u64cd\u4f5c\u57fa\u7840\u8bbe\u65bd:<\/p>\n<pre><code>terraform plan\nterraform plan -out test.tfplan\nterraform apply -auto-approve\nterraform apply test.tfplan\nterraform destroy\n<\/code><\/pre>\n<p>\u68c0\u67e5\u57fa\u7840\u8bbe\u65bd:<\/p>\n<pre><code>terraform show\nterraform graph\nterraform output\nterraform state list\/show\n<\/code><\/pre>\n<p>\u8ba4\u8bc1:<\/p>\n<pre><code>terraform login\nterraform logout\n<\/code><\/pre>\n<hr>\n<h2 id=\"tf\">TF<\/h2>\n<p><a class=\"link\" href=\"https:\/\/www.terraform.io\/language\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.terraform.io\/language<\/a><\/p>\n<p>\u6ce8\u91ca:<\/p>\n<pre><code># comment\n\/\/ comment\n\/* comment *\/\n<\/code><\/pre>\n<h3 id=\"backend-and-state\">backend and state<\/h3>\n<p><a class=\"link\" href=\"https:\/\/www.terraform.io\/language\/settings\/backends\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.terraform.io\/language\/settings\/backends<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/www.terraform.io\/language\/state\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.terraform.io\/language\/state<\/a><\/p>\n<hr>\n<h3 id=\"provider\">provider<\/h3>\n<hr>\n<h3 id=\"data-sources\">data sources<\/h3>\n<p>data source: \u83b7\u53d6\u670d\u52a1\u7684\u53c2\u6570<\/p>\n<hr>\n<h3 id=\"module\">module<\/h3>\n<p>\u7ba1\u7406provider\u4e0a\u7684\u6a21\u5757\/\u670d\u52a1.\u5b9a\u4e49\u4e86input, resource\/data source, output\u7684\u5c31\u53ef\u4ee5\u8ba4\u4e3a\u662fmodule.<\/p>\n<h4 id=\"meta-arguments\">meta-arguments<\/h4>\n<ul>\n<li>providers<\/li>\n<li>depends_on<\/li>\n<li>count<\/li>\n<li>for_each<\/li>\n<\/ul>\n<hr>\n<h3 id=\"resources\">resources<\/h3>\n<p>resources: \u521b\u5efa\u670d\u52a1\u7684\u53c2\u6570<\/p>\n<h4 id=\"meta-arguments-1\">meta-arguments<\/h4>\n<ul>\n<li>depends_on<\/li>\n<li>count<\/li>\n<li>for_each<\/li>\n<li>provider<\/li>\n<li>lifecycle<\/li>\n<\/ul>\n<h4 id=\"lifecycle\">lifecycle<\/h4>\n<p>\u7528\u6765\u63a7\u5236\u8d44\u6e90\u7684\u521b\u5efa\u3001\u66f4\u65b0\u548c\u5220\u9664\u884c\u4e3a\u3002<\/p>\n<h4 id=\"connection\">connection<\/h4>\n<p>\u7528\u6765\u5b9a\u4e49\u5982\u4f55\u8fde\u63a5\u5230\u8fdc\u7a0b\u8d44\u6e90\uff0c\u901a\u5e38\u7528\u4e8eprovisioner.<\/p>\n<h4 id=\"provisioner\">provisioner<\/h4>\n<p>\u7279\u6b8a\u7684resource\uff0c\u53ef\u4ee5\u5728\u672c\u5730\u6216\u8fdc\u7a0b\u673a\u5668\u505a\u4e00\u4e9b\u51c6\u5907\u5de5\u4f5c\u3002\u4e5f\u5c31\u662f\u5728\u8d44\u6e90\u521b\u5efa\u540e\u6267\u884c\u4e00\u4e9b\u64cd\u4f5c.<\/p>\n<p>\u652f\u6301\uff1a<\/p>\n<ul>\n<li>file<\/li>\n<li>local-exec<\/li>\n<li>remote-exec<\/li>\n<\/ul>\n<hr>\n<h3 id=\"variable\">Variable<\/h3>\n<p><a class=\"link\" href=\"https:\/\/www.terraform.io\/language\/values\/variables\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.terraform.io\/language\/values\/variables<\/a><\/p>\n<p>input variable: \u8f93\u5165\u53d8\u91cf<\/p>\n<p>local variable: \u672c\u5730\u53d8\u91cf<\/p>\n<p>output variable: \u8f93\u51fa\u53c2\u6570<\/p>\n<p>\u5b50\u6a21\u5757\u65e0\u6cd5\u5f15\u7528\u7236\u6a21\u5757\u7684local\u53d8\u91cf\uff0c resource\u5c5e\u6027\uff0cinput\u53d8\u91cf\u3002\u4f46\u662f\u53ef\u4ee5\u901a\u8fc7output\u53c2\u6570\u5f15\u7528\u3002<\/p>\n<p>\u7236\u6a21\u5757\u65e0\u6cd5\u5f15\u7528\u5b50\u6a21\u5757\u7684local\u53d8\u91cf\uff0cresource\u5c5e\u6027\u3002\u4f46\u662f\u53ef\u4ee5\u901a\u8fc7output\u53c2\u6570\u5f15\u7528\uff0c\u800c\u4e14\u7236\u6a21\u5757\u53ef\u4ee5\u901a\u8fc7input\u53d8\u91cf\u4f20\u503c\u7ed9\u5b50\u6a21\u5757\u3002<\/p>\n<h3 id=\"\u8868\u8fbe\u5f0f\">\u8868\u8fbe\u5f0f<\/h3>\n<h3 id=\"\u51fd\u6570\">\u51fd\u6570<\/h3>\n<h3 id=\"workspace\">workspace<\/h3>\n<p>Workspace \u662f Terraform \u7528\u6765\u9694\u79bb\u72b6\u6001\u6587\u4ef6\uff08state\uff09\u7684\u4e00\u79cd\u673a\u5236\uff0c\u5141\u8bb8\u4f60\u5728\u540c\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\u4e2d\u7ba1\u7406\u591a\u4e2a\u73af\u5883\uff08\u5982 dev\u3001staging\u3001prod\uff09\u800c\u4e0d\u4f1a\u76f8\u4e92\u5e72\u6270\u3002<\/p>\n<pre><code>terraform workspace new dev\nterraform workspace list\nterraform select &lt;name&gt;\n<\/code><\/pre>\n<p>\u4f7f\u7528terraform.workspace\u4f5c\u4e3a\u53c2\u6570.<\/p>\n<hr>"},{"title":"Vault","link":"https:\/\/canuxcheng.com\/post\/devops_vault\/","pubDate":"Fri, 15 Apr 2016 09:41:39 +0800","guid":"https:\/\/canuxcheng.com\/post\/devops_vault\/","description":"<h1 id=\"vault\">Vault<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/hashicorp\/vault\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/hashicorp\/vault<\/a><\/p>\n<p>Install:<\/p>\n<p><a class=\"link\" href=\"https:\/\/learn.hashicorp.com\/tutorials\/vault\/getting-started-install\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/learn.hashicorp.com\/tutorials\/vault\/getting-started-install<\/a><\/p>\n<h1 id=\"cli\">CLI<\/h1>\n<p>\u53ef\u4ee5\u901a\u8fc7\u73af\u5883\u53d8\u91cf\u6216\u8005\u547d\u4ee4\u884c\u53c2\u6570\u6307\u5b9aserver:<\/p>\n<pre><code>-address VAULT_ADDR\n-namespace VAULT_NAMESPACE\nvault [subcommand] -address=&quot;https:\/\/server:8200&quot;\n<\/code><\/pre>\n<p>server:<\/p>\n<pre><code>\/\/ \u542f\u52a8vault\n$ vault server -config=\/etc\/vault\/config.hcl\n<\/code><\/pre>\n<p>agent:<\/p>\n<pre><code>$ vault agent\n<\/code><\/pre>\n<p>login:<\/p>\n<pre><code>\/\/ \u8ddf\u636etoken\u767b\u9646.\n$ vault login\n$vault login -token-only -method=oidc\n<\/code><\/pre>\n<p>operator:<\/p>\n<pre><code>\/\/ init\u751f\u6210keys\u548ctoken.\n$ vault operator init\n\/\/ \u901a\u8fc7keys unseal\n$ vault operator unseal\n\/\/ \u901a\u8fc7token seal\n$ vault operator seal\n<\/code><\/pre>\n<p>auth:<\/p>\n<pre><code>\/\/ \u67e5\u770bauth\n$ vault auth list\n<\/code><\/pre>\n<p>secrets<\/p>\n<pre><code>\/\/ \u67e5\u770bsecrets engine\n$ vault secrets list\n\/\/ enable kv\n$ vault secrets enable -path=&lt;ns&gt;\/&lt;name&gt; kv\n$ vault secrets enable kv\n\/\/ disable kv\n$ vault secrets disable kv\n\/\/ \u521b\u5efa\u4e00\u4e2adatabase engine\nvault secrets enable -path &lt;ns&gt;\/mysql database\n\/\/ \u521b\u5efarabbitmq engine\nvault secrets enable -path &lt;ns&gt;\/rabbitmq rabbitmq\n<\/code><\/pre>\n<p>policy<\/p>\n<pre><code>\/\/ \u67e5\u770bpolicy\n$ vault policy list\n\/\/ \u521b\u5efapolicy\n$ vault policy write &lt;my-policy&gt; .\/my-policy.hcl\n<\/code><\/pre>\n<p>plugin:<\/p>\n<pre><code>$ vault plugin list database\n<\/code><\/pre>\n<p>read\/write\/delete\/list:<\/p>\n<pre><code>$ vault read\n$ vault write\n$ vault write my-secret\/my-app my-field=value\n$ vault delete\n$ vault list\n<\/code><\/pre>\n<h1 id=\"api\">API<\/h1>\n<p><a class=\"link\" href=\"https:\/\/www.vaultproject.io\/api-docs\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.vaultproject.io\/api-docs<\/a><\/p>\n<pre><code>$ curl --header &quot;X-Vault-Token: TOKEN&quot; https:\/\/FQDN\/v1\/&lt;engine-path&gt;\/data\/&lt;secret-path&gt;\n$ curl --header &quot;X-Vault-Token: TOKEN&quot; https:\/\/FQDN\/v1\/&lt;engine-path&gt;\/data\/&lt;secret-path&gt;?version=&lt;version&gt;\n<\/code><\/pre>\n<hr>\n<h1 id=\"auth-methods\">auth methods<\/h1>\n<p><a class=\"link\" href=\"https:\/\/www.vaultproject.io\/docs\/auth\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.vaultproject.io\/docs\/auth<\/a><\/p>\n<h1 id=\"secrets-engine\">secrets engine<\/h1>\n<p><a class=\"link\" href=\"https:\/\/www.vaultproject.io\/docs\/secrets\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.vaultproject.io\/docs\/secrets<\/a><\/p>\n<hr>\n<h1 id=\"vault-pki\">vault PKI<\/h1>\n<p>\u901a\u8fc7pki engine\u6765\u751f\u6210\u548c\u7ba1\u7406\u8bc1\u4e66\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/learn.hashicorp.com\/tutorials\/vault\/pki-engine\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/learn.hashicorp.com\/tutorials\/vault\/pki-engine<\/a><\/p>\n<p>generate:<\/p>\n<pre><code>vault write -format=json -namespace=&lt;ns&gt; &lt;pki_root&gt;\/issue\/&lt;role&gt; \\\ncommon_name=&quot;canuxcheng.com&quot; \\\nalt_names=&quot;canuxcheng.com,*.canuxcheng.com&quot; \\\nttl=8760h \\\nformat=pem\/der\/pem_bundle \\\n| tee \\\n&gt;(jq -r '.data.certificate' &gt; canuxcheng.crt) \\\n&gt;(jq -r '.data.private_key' &gt; private.key)\n<\/code><\/pre>\n<p>list:<\/p>\n<pre><code>vault list -namespace=&lt;ns&gt; &lt;pki_root&gt;\/certs\n<\/code><\/pre>\n<p>verify:<\/p>\n<pre><code>vault read -namespace=iac-phoenix\/test it\/pki\/cert\/&lt;sn&gt;\ncurl -s https:\/\/vault.canux.com\/v1\/&lt;ns&gt;\/&lt;pki_root&gt;\/cert\/&lt;serial-num&gt; | jq -r '.data.certificate' | openssl x509 -in - -noout -text\n<\/code><\/pre>\n<p>revoke:<\/p>\n<pre><code>vault write &lt;ns&gt;\/&lt;pki_root&gt;\/revoke serial_number=&quot;******&quot;\n<\/code><\/pre>\n<p>remove expired ca:<\/p>\n<pre><code>vault write &lt;pki_root&gt;\/tidy tidy_cert_store=true tidy_revoked_certs=true\n<\/code><\/pre>\n<hr>\n<h1 id=\"vault--k8s\">vault + k8s<\/h1>\n<p>vault\u63d0\u4f9b\u4e24\u79cd\u65b9\u5f0f\u5728k8s\u4e2d\u4f7f\u7528secret.<\/p>\n<h2 id=\"vault-sidecar-agent-injector\">Vault Sidecar Agent Injector<\/h2>\n<p><a class=\"link\" href=\"https:\/\/www.vaultproject.io\/docs\/platform\/k8s\/injector\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.vaultproject.io\/docs\/platform\/k8s\/injector<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/hashicorp\/vault-k8s\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/hashicorp\/vault-k8s<\/a><\/p>\n<h2 id=\"mutating-webhook-of-bank-vaults\">mutating webhook of Bank-Vaults<\/h2>\n<p><a class=\"link\" href=\"https:\/\/banzaicloud.com\/docs\/bank-vaults\/mutating-webhook\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/banzaicloud.com\/docs\/bank-vaults\/mutating-webhook\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/banzaicloud\/bank-vaults\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/banzaicloud\/bank-vaults<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/banzaicloud.com\/blog\/inject-secrets-into-pods-vault-revisited\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/banzaicloud.com\/blog\/inject-secrets-into-pods-vault-revisited\/<\/a><\/p>\n<h2 id=\"vault-csi-provider\">Vault CSI Provider<\/h2>\n<p><a class=\"link\" href=\"https:\/\/www.vaultproject.io\/docs\/platform\/k8s\/csi\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.vaultproject.io\/docs\/platform\/k8s\/csi<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kubernetes-sigs\/secrets-store-csi-driver\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kubernetes-sigs\/secrets-store-csi-driver<\/a><\/p>"},{"title":"PSL_Test","link":"https:\/\/canuxcheng.com\/post\/psl_devops\/","pubDate":"Mon, 11 Apr 2016 22:58:13 +0000","guid":"https:\/\/canuxcheng.com\/post\/psl_devops\/","description":"<h1 id=\"devops\">DevOps<\/h1>\n<p>development, testing, documentation.<\/p>\n<h2 id=\"typing\">typing<\/h2>\n<p>\u7528\u4e8e\u7c7b\u578b\u63d0\u793a\uff0c\u63d0\u4f9b\u7c7b\u578b\u68c0\u67e5\uff0c\u4ee3\u7801\u53ef\u8bfb\u6027\u548c\u7f16\u8f91\u5668\u81ea\u52a8\u8865\u5168\u652f\u6301\u3002<\/p>\n<p>\u57fa\u7840\u7c7b\u578b\uff1a<\/p>\n<pre><code>Tuple[int, int], Tuple[int, ...]\nList[str]\nDict[str, int]\nSet[str]\nOptional[int]\nUnion[int, str, float]\n<\/code><\/pre>\n<p>\u6cdb\u578b<\/p>\n<pre><code>TypeVar\nGeneric\n<\/code><\/pre>\n<p>\u51fd\u6570\u7b7e\u540d<\/p>\n<pre><code>Callable\n<\/code><\/pre>\n<p>\u7c7b\u76f8\u5173<\/p>\n<pre><code>Type\nProtocol\n<\/code><\/pre>\n<p>\u9ad8\u7ea7\u7c7b\u578b<\/p>\n<pre><code>Linteral\nFinal\nAnnotated\n<\/code><\/pre>\n<h2 id=\"pydoc\">pydoc<\/h2>\n<pre><code>import pydoc\n<\/code><\/pre>\n<h2 id=\"test\">test<\/h2>\n<pre><code>import test\n<\/code><\/pre>\n<h2 id=\"doctest\">doctest<\/h2>\n<p>python\u5185\u7f6e\u7684\u6587\u6863\u6d4b\u8bd5\u5e93\uff0e<\/p>\n<pre><code>import doctest\n<\/code><\/pre>\n<h2 id=\"unittest\">unittest<\/h2>\n<p>python\u5185\u7f6e\u7684\u5355\u5143\u6d4b\u8bd5\u5e93\uff0e<\/p>\n<pre><code>import unittest\n<\/code><\/pre>\n<hr>\n<h1 id=\"tpl\">TPL<\/h1>\n<p>\u76f8\u5173\u7684\u7b2c\u4e09\u65b9\u5e93<\/p>\n<h2 id=\"unittest2\">unittest2<\/h2>\n<p>unittest2\u662funittest\u7684\u5347\u7ea7\u7248\uff0e<\/p>\n<p>python3\u96c6\u6210\u4e86unittest2\u5230unittest,\u50cf\u4f7f\u7528unittest\u4e00\u6837\u4f7f\u7528\u5373\u53ef\uff0e<\/p>\n<pre><code># python2.7\n$pip install unittest2\nimport unittest2\n# python3\nimport unittest\n<\/code><\/pre>\n<p>unittest\u4e5f\u53ebpyunit\uff0c\u7c7b\u4f3c\u4e8eJunit(java)\u90fd\u662f\u57fa\u4e8eKent Beck\u548cErich Gamma\u7684XUnit\u6846\u67b6\uff0e<\/p>\n<p>\u6d4b\u8bd5\u7ed3\u679c\uff1a<\/p>\n<p>OK \u8868\u793a\u6d4b\u8bd5\u901a\u8fc7<\/p>\n<p>FAIL \u8868\u793a\u6d4b\u8bd5\u6ca1\u6709\u901a\u8fc7\uff0c\u5e76\u5f15\u53d1\u4e00\u4e2aAssertionError\u5f02\u5e38\uff0e<\/p>\n<p>ERROR \u8868\u793a\u6d4b\u8bd5\u8fc7\u7a0b\u5f15\u53d1\u4e00\u4e2a\u4e0d\u662fAssertionError\u7684\u5f02\u5e38\uff0e<\/p>\n<pre><code># Python2.7 \u6b64\u5904\u7528\u7684\u662f\u6807\u51c6\u5e93\u7684unittest.\nimport unittest\nimport MyClass\n<\/code><\/pre>\n<p>classes:<\/p>\n<pre><code>unittest.TestCase: \u6bcf\u4e2a\u5b9e\u4f8b\u5c31\u662f\u4e00\u4e2atest case. \u4f7f\u7528TestCase.assert* \u7cfb\u5217\u65b9\u6cd5\u8fdb\u884c\u6d4b\u8bd5\uff0e\nunittest.TestSuite: \u6bcf\u4e2a\u5b9e\u4f8b\u5c31\u662f\u4e00\u4e2atest suite. \u591a\u4e2atest case\u653e\u5728\u4e00\u8d77\u5c31\u662f\u4e00\u4e2atest suite.\nunittest.TestLoader\/unittest.defaultTestLoader: \u7528\u6765\u52a0\u8f7dTestCase\u5230TestSuite.\nunittest.TestResult: \u7528\u6765\u4fdd\u5b58\u6d4b\u8bd5\u7684\u7ed3\u679c\uff0e\nunittest.TestProgram\/unittest.main(): \u641c\u7d22\u8be5\u6a21\u5757\u4e0b\u6240\u6709test\u5f00\u5934\u7684\u6d4b\u8bd5\u7528\u4f8b\u65b9\u6cd5\u5e76\u6267\u884c\uff0e\nfixtures\u5bf9\u4e00\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u7684\u73af\u5883\u7684\u642d\u5efa\u548c\u9500\u6bc1\uff0c\u901a\u8fc7\u91cd\u8f7dTestCase\u7684setUp()\u548cteaeDown()\u65b9\u6cd5\uff0e\nunittest.TextTestRunner: \u7528\u6765\u6267\u884c\u6d4b\u8bd5\u7528\u4f8b\uff0e\nunittest.TextTestResult: \u7528\u6765\u6253\u5370\u683c\u5f0f\u5316\u7684\u6d4b\u8bd5\u7ed3\u679c\uff0e\n# unittest.TestCase\n# methods:\nassertXXX\u3000\u7cfb\u5217\u65b9\u6cd5\uff0e\nfailXXX \u7cfb\u5217\u65b9\u6cd5\nfail(self, msg=None) # test\u7acb\u5373\u5931\u8d25\naddCleanup(self, function, *args, **kwargs)\naddTypeEqualityFunc(self, typeobj, function)\ncountTestCases(self)\ndebug(self)\ndefaultTestResult() # return unittest.TestResult()\ndoCleanups(self)\nid(self)\nrun(self, result=None) # \u53ef\u4ee5\u5728\u5b50\u7c7b\u8986\u76d6\u8be5\u65b9\u6cd5\uff0e\nshortDescription(self)\nskipTest(self, reason)\nsetUp(self) # \u91cd\u5199\u4e4b\u540e\uff0c\u6bcf\u4e2acase\u8fd0\u884c\u4e4b\u524d\u90fd\u4f1a\u8c03\u7528\u4e00\u6b21\uff0e\ntearDown(self) # \u540c\u4e0a\n# classmethods:\nsetUpClass(cls) # \u901a\u8fc7@classmethod\u91cd\u5199\uff0c\u8fd9\u6837\u6240\u6709\u7684case\u8fd0\u884c\u4e4b\u524d\u53ea\u8c03\u7528\u4e00\u6b21\uff0c\u800c\u4e0d\u662f\u6bcf\u4e2acase\u8fd0\u884c\u4e4b\u524d\u90fd\u8c03\u7528\uff0e\ntearDownClass(cls) # \u540c\u4e0a\n# data:\nfailureException = AssertionError\nlongMessage = False\nmaxDiff = 640\n<\/code><\/pre>\n<p>functions:<\/p>\n<pre><code>findTestCases(module, prefix='test', sortUsing=&lt;built-in function cmp&gt;, suiteClass=&lt;class 'unittest.suite.TestSuite'&gt;)\ngetTestCaseNames(testCaseClass, prefix, sortUsing=&lt;built-in function cmp&gt;)\ninstallHandler()\nmakeSuite(testCaseClass, prefix='test', sortUsing=&lt;built-in function cmp&gt;, suiteClass=&lt;class 'unittest.suite.TestSuite'&gt;)\nregisterResult(result)\nremoveHandler(method=None)\nremoveResult(result)\n# unittest.case\u5b9e\u73b0\u4e86\u51e0\u4e2a\u51fd\u6570\u7528\u6765\u589e\u5f3aunittest.TestCase\u7684\u65b9\u6cd5, \u4e00\u822c\u5f53\u88c5\u9970\u5668\u7528\uff0e\nexpectedFailure(func) # \u5982\u679c\u8fd9\u4e2acase\u5931\u8d25\u4e86\uff0c\u4e0d\u8ba1\u5165\u5931\u8d25\u7684\u6570\u76ee\uff0e\n# @unittest.expectedFailure\nskip(reason) # \u65e0\u6761\u4ef6\u8df3\u8fc7\u4e00\u4e2atest case.\nskipIf(condition, reason) # condition\u4e3atrue\u5c31\u8df3\u8fc7\u4e00\u4e2atest case.\nskipUnless(condition, reason) # \u548c\u4e0a\u9762\u76f8\u53cd\n<\/code><\/pre>\n<p>examples:<\/p>\n<pre><code>class MyClassTestCase(unittest.TestCase):\n@classmethod\ndef setUpClass(cls):\nprint 'Just execute before the first test case start.'\n@classmethod\ndef tearDownClass(cls):\nprint 'Just execute after all test case end.'\ndef setUp(self):\n&quot;&quot;&quot;\u91cd\u8f7dsetUp\u8fdb\u884c\u6d4b\u8bd5\u4e4b\u524d\u7684\u521d\u59cb\u5316\u5de5\u4f5c.\u8fd0\u884c\u6bcf\u4e2atest_func\u4e4b\u524d\u90fd\u4f1a\u8fd0\u884c\u8be5\u65b9\u6cd5&quot;&quot;&quot;\nprint &quot;start&quot;\ndef tearDown(self):\n&quot;&quot;&quot;\u91cd\u8f7dtearDown\u8fdb\u884c\u6d4b\u8bd5\u7ed3\u675f\u540e\u7684\u6e05\u7406\u5de5\u4f5c.\u7ed3\u675f\u8fd0\u884c\u6bcf\u4e2atest_func\u4e4b\u540e\u90fd\u4f1a\u8fd0\u884c\u8be5\u65b9\u6cd5&quot;&quot;&quot;\nprint &quot;end&quot;\ndef test_func(self):\n&quot;&quot;&quot;\u5177\u4f53\u7684\u6d4b\u8bd5\u7528\u4f8b\uff0c\u9700\u8981\u7528test\u5f00\u5934,\u591a\u4e2atest_func\u4f1a\u6839\u636efunc\u540d\u5b57\u4e2d\u7684\u6570\u5b57\u6216\u5b57\u6bcd\u7684\u987a\u5e8f\u6765\u6267\u884c\uff0c\u548c\u4f4d\u7f6e\u65e0\u5173.\n\u4e0d\u662f\u7528test\u5f00\u5934\u7684\u65b9\u6cd5\u9ed8\u8ba4\u4e0d\u4f1a\u88ab\u6267\u884c&quot;&quot;&quot;\nself.assertEqual(MyClass.method(args), value, &quot;message&quot;)\nif __name__ == &quot;__main__&quot;:\nunittest.main()\n# \u81ea\u52a8\u53d1\u73b0\u548c\u6279\u91cf\u6267\u884ctestcase\/testsuite:\ndef discover_test_case():\ntest_cases = []\n_module = ...\ntests.append(unittest.defaultTestLoader.loadTestsFromModule(_module))\nunittest.defaultTestLoader.discover()\nreturn tests\ndef get_test_suite():\n&quot;&quot;&quot;\u6253\u5305\u4e00\u4e2atestsuite.&quot;&quot;&quot;\nreturn unittest.TestSuite(discover_test_case())\nunittest.TextTestRunner\nif __name__ == &quot;__main__&quot;:\nrunner = unittest.TextTestRunner()\nresult = runner.run(get_test_suite())\n<\/code><\/pre>\n<h2 id=\"mock\">mock<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/testing-cabal\/mock\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/testing-cabal\/mock<\/a><\/p>\n<p>python3\u96c6\u6210\u4e86mock\u5230unittest\u6a21\u5757\uff0c\u5bfc\u5165unittest.mock\u5373\u53ef\uff0e<\/p>\n<pre><code># Python2.7\n$pip install mock\nimport mock\n# Python3\nimport unittest.mock\n<\/code><\/pre>\n<p>mock\u5c31\u662f\u5728\u6d4b\u8bd5\u4e2d\u5bf9\u4e8e\u4e0d\u5bb9\u6613\u6784\u9020\u6216\u83b7\u53d6\u7684\u5bf9\u8c61\uff0c\u7528\u4e00\u4e2a\u865a\u62df\u7684\u5bf9\u8c61\u6765\u4ee3\u66ff\u4ee5\u4fbf\u6d4b\u8bd5\u7684\u65b9\u6cd5\uff0e<\/p>\n<pre><code># Python2.7 \u6b64\u5904\u7528\u7684\u662f\u7b2c\u4e09\u65b9\u5e93mock\nfrom mock import Mock, patch, PropertyMock, MagicMock\n<\/code><\/pre>\n<h2 id=\"nose2\">nose2<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/nose-devs\/nose2\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/nose-devs\/nose2<\/a><\/p>\n<p>nose\u662funittest\/unittest2\u7684\u5347\u7ea7\u7248\uff0e<\/p>\n<p>nose2\u662fnose\u7684\u5347\u7ea7\u7248\uff0e<\/p>\n<p>nose2\u7528\u4e8e\u5355\u5143\u6d4b\u8bd5\uff0e<\/p>\n<pre><code>$ pip install nose\nimport nose\n<\/code><\/pre>\n<h2 id=\"pytest\">pytest<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/pytest-dev\/pytest\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/pytest-dev\/pytest\/<\/a><\/p>\n<p>pytest\u7528\u4e8e\u5355\u5143\u6d4b\u8bd5\uff0e\u63a8\u8350\u4f7f\u7528\uff0e<\/p>\n<pre><code>$ pip install -U pytest\nimport pytest\n<\/code><\/pre>\n<hr>\n<h2 id=\"coverage\">coverage<\/h2>\n<p>\u5206\u6790\u5355\u5143\u6d4b\u8bd5\u7684\u4ee3\u7801\u8986\u76d6\u7387<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/nedbat\/coveragepy\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/nedbat\/coveragepy<\/a><\/p>\n<pre><code>$ pip install coverage\n# \u901a\u8fc7\u547d\u4ee4\u8fdb\u884c\u6d4b\u8bd5\uff0c\u53ef\u4ee5\u96c6\u6210\u5230\u5176\u5b83\u5de5\u5177\uff0e\n$ coverage run --source=&lt;package-name&gt; setup.py test\n<\/code><\/pre>\n<hr>\n<h2 id=\"tox\">tox<\/h2>\n<p>virtualenv management and test command line tool.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/tox-dev\/tox\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/tox-dev\/tox<\/a><\/p>\n<pre><code>$ pip install tox\n# \u901a\u8fc7\u547d\u4ee4\u8fdb\u884c\u6d4b\u8bd5\uff0c\u53ef\u4ee5\u96c6\u6210unittest, nose2, pytest\u7b49\u5de5\u5177\uff0e\n$ tox\n<\/code><\/pre>\n<hr>\n<h2 id=\"sphinx\">Sphinx<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/sphinx-doc\/sphinx\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/sphinx-doc\/sphinx<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/zh-sphinx-doc.readthedocs.io\/en\/latest\/contents.html\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/zh-sphinx-doc.readthedocs.io\/en\/latest\/contents.html<\/a><\/p>\n<p>Sphinx\u5c31\u662fpython\u5904\u7406reStructuredText\u683c\u5f0f\u7684\u5de5\u5177\u3002<\/p>\n<p>\u5b89\u88c5\uff1a<\/p>\n<pre><code>$pip install -U Sphinx\n<\/code><\/pre>\n<p>\u4f7f\u7528sphinx\uff1a<\/p>\n<pre><code>$cd your-project\/docs\n$sphinx-quickstart\n# \u4ee5\u4e0b\u9009\u9879\u9700\u8981\u624b\u52a8\u8bbe\u5b9a\uff0c\u5176\u5b83\u90fd\u53ef\u4ee5\u7528\u9ed8\u8ba4\u503c\uff1a\n&gt; Project name: pydeveloper\n&gt; Author name(s): Canux CHENG\n&gt; Project version: 1.0.0.0\n&gt; autodoc: automatically insert docstrings from modules (y\/n) [n]: y\n&gt; doctest: automatically test code snippets in doctest blocks (y\/n) [n]: y\n<\/code><\/pre>\n<p>\u914d\u7f6e\u6587\u4ef6conf.py\u5305\u542b\u521a\u624d\u7684\u6240\u6709\u914d\u7f6e\uff0c\u53ef\u4ee5\u5728\u8fd9\u91cc\u624b\u52a8\u4fee\u6539\u3002<\/p>\n<p><a class=\"link\" href=\"http:\/\/www.sphinx-doc.org\/en\/1.4.8\/config.html#confval-locale_dirs\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.sphinx-doc.org\/en\/1.4.8\/config.html#confval-locale_dirs<\/a><\/p>\n<p>\u6dfb\u52a0\u5305\u7684\u7248\u672c\uff1a<\/p>\n<pre><code>sys.path.insert(0, os.path.abspath(&quot;..&quot;))\nfrom &lt;project&gt; import __version__\n<\/code><\/pre>\n<p>\u4fee\u6539\u81ea\u5df1\u7684\u914d\u7f6e\uff1a<\/p>\n<pre><code>copyright = u'2016, &lt;a href=&quot;http:\/\/canuxcheng.com&quot;&gt;Canux CHENG&lt;\/a&gt;'\n<\/code><\/pre>\n<h3 id=\"sphinx-docs\">sphinx-docs<\/h3>\n<p><a class=\"link\" href=\"https:\/\/zh-sphinx-doc.readthedocs.io\/en\/latest\/markup\/index.html#sphinxmarkup\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/zh-sphinx-doc.readthedocs.io\/en\/latest\/markup\/index.html#sphinxmarkup<\/a><\/p>\n<p>sphinx\u7684\u6807\u8bb0\u628areST\u683c\u5f0f\u7684\u6587\u6863\u5173\u8054\u8d77\u6765\u3002<\/p>\n<p>index.rst\u8fd9\u662f\u6587\u6863\u7684\u9996\u9875\u3002<\/p>\n<h3 id=\"sphinx-build\">sphinx-build<\/h3>\n<p>\u751f\u6210web\u53ef\u8bfb\u7684\u6587\u6863\u3002<\/p>\n<p>\u7b80\u5355\u65b9\u6cd5\u751f\u6210\u6587\u6863\uff1a<\/p>\n<pre><code># \u751f\u6210html\u683c\u5f0f\u7684\u6587\u6863\n$make html\n<\/code><\/pre>\n<h3 id=\"sphinx-apidoc\">sphinx-apidoc<\/h3>\n<p>\u81ea\u52a8\u751f\u6210API\u6587\u6863\u3002<\/p>\n<pre><code>$sphinx-apidoc\n<\/code><\/pre>\n<h3 id=\"debug\">Debug<\/h3>\n<p>\u6d4f\u89c8\u5668\u6253\u5f00docs\/_build\/html\/index.html\u5373\u53ef\u3002<\/p>\n<pre><code>$firefox _build\/html\/index.html\n<\/code><\/pre>\n<hr>\n<h2 id=\"readthedocs\">ReadTheDocs<\/h2>\n<p><a class=\"link\" href=\"https:\/\/readthedocs.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/readthedocs.org\/<\/a><\/p>\n<p><a class=\"link\" href=\"http:\/\/readthedocs.readthedocs.io\/zh_CN\/latest\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/readthedocs.readthedocs.io\/zh_CN\/latest\/<\/a><\/p>\n<p>\u5c06\u9879\u76ee\u6587\u6863\u90e8\u7f72\u5230readthedocs\u7ad9\u70b9\u3002<\/p>\n<p>\u76f4\u63a5\u6ce8\u518c\u5e10\u53f7\uff0c\u540c\u6b65github\u9879\u76ee\uff0c\u7136\u540e\u5bfc\u5165\u4f60\u7684\u9879\u76ee\u5373\u53ef\u3002<\/p>\n<hr>\n<h2 id=\"pypandoc\">pypandoc<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/bebraw\/pypandoc\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/bebraw\/pypandoc<\/a><\/p>\n<p>\u6587\u6863\u8f6c\u6362\u5de5\u5177pandoc\u7684python\u5305\u3002<\/p>\n<p>\u5b89\u88c5\uff1a<\/p>\n<pre><code>$ sudo apt-get install pandoc\n$ pip install pypandoc\n<\/code><\/pre>"},{"title":"DevOps","link":"https:\/\/canuxcheng.com\/post\/c_devops\/","pubDate":"Mon, 11 Apr 2016 22:57:37 +0000","guid":"https:\/\/canuxcheng.com\/post\/c_devops\/","description":"<h1 id=\"ide\">IDE<\/h1>\n<ul>\n<li>Visual Studio<\/li>\n<li>VSCode<\/li>\n<\/ul>\n<h2 id=\"compilers\">Compilers<\/h2>\n<p>\u7f16\u8bd1\u5668\u7ec4\u6210\uff1a<\/p>\n<ul>\n<li>frontend<\/li>\n<li>optimizer<\/li>\n<li>backend<\/li>\n<\/ul>\n<p><a class=\"link\" href=\"https:\/\/zh.cppreference.com\/w\/cpp\/compiler_support\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/zh.cppreference.com\/w\/cpp\/compiler_support<\/a><\/p>\n<p>windows:<\/p>\n<ul>\n<li>llvm clang<\/li>\n<li>Mingw<\/li>\n<li>Msvc<\/li>\n<\/ul>\n<p>linux:<\/p>\n<ul>\n<li>llvm clang<\/li>\n<li>gcc<\/li>\n<\/ul>\n<p>mac:<\/p>\n<ul>\n<li>llvm clang<\/li>\n<li>gcc<\/li>\n<li>apple clang<\/li>\n<\/ul>\n<h3 id=\"gcc\">gcc<\/h3>\n<p>gnu gcc,g++<\/p>\n<h3 id=\"llvm-clang\">llvm clang<\/h3>\n<p>llvm: low level virtual machine. (backend)<\/p>\n<p>clang: c language.(frontend)<\/p>\n<hr>\n<h2 id=\"tools\">tools<\/h2>\n<ul>\n<li>CMake<\/li>\n<li>MSBuild<\/li>\n<li>Makefile<\/li>\n<\/ul>\n<hr>\n<h2 id=\"gcc-1\">GCC<\/h2>\n<p>&ldquo;-ansi&rdquo;<\/p>\n<p>for c: == -std=c90\nfor cpp: ==-std=c++98<\/p>\n<p>&ldquo;-std&rdquo;<\/p>\n<p>c++17, gnu++17, gnu17,c17\ngnu2x: \u4e0b\u4e2aISO C\u6807\u51c6\u3002\nc2x:\u4e0b\u4e2aISO C\u6807\u51c6\u3002\nc++2a: \u4e0b\u4e2aISO C++\u6807\u51c6\ngnu+2a:\u4e0b\u4e2aISO C++\u6807\u51c6<\/p>\n<p>gcc8 \u5f00\u59cb\u652f\u6301c++20.\ngcc11\u5f00\u59cb\u652f\u6301c++23.<\/p>\n<h2 id=\"vscode\">vscode<\/h2>\n<p>for macOS:<\/p>\n<pre><code>xcode-select --install\n<\/code><\/pre>\n<p>extentions:<\/p>\n<ul>\n<li>c\/c++<\/li>\n<li><\/li>\n<\/ul>"},{"title":"Document","link":"https:\/\/canuxcheng.com\/post\/c_document\/","pubDate":"Mon, 11 Apr 2016 22:57:37 +0000","guid":"https:\/\/canuxcheng.com\/post\/c_document\/","description":"<h1 id=\"document\">Document<\/h1>\n<hr>\n<h1 id=\"doxygen\">Doxygen<\/h1>"},{"title":"Hadoop","link":"https:\/\/canuxcheng.com\/post\/hadoop\/","pubDate":"Mon, 11 Apr 2016 22:57:37 +0000","guid":"https:\/\/canuxcheng.com\/post\/hadoop\/","description":"<h1 id=\"hadoop\">Hadoop<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/apache\/hadoop\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/apache\/hadoop<\/a><\/p>\n<p>apache hadoop\u662f\u4e00\u4e2a\u6846\u67b6\uff0c\u5141\u8bb8\u4f7f\u7528\u7b80\u5355\u7684\u7f16\u7a0b\u6a21\u578b\u5728\u5927\u91cf\u8ba1\u7b97\u673a\u4e0a\u5bf9\u5927\u578b\u6570\u636e\u96c6\u8fdb\u884c\u5206\u5e03\u5f0f\u5904\u7406\uff0e<\/p>\n<p>hadoop1\u53ea\u6709HDFS\u548cMapReduce\u4e24\u4e2a\u6a21\u5757\uff0chadoop2\u5f00\u59cb\u5206\u4e3aHDFS, YARN, MapReduce\u4e09\u4e2a\u6a21\u5757\uff0e<\/p>\n<p>hadoop\u7684\u7248\u672c:<\/p>\n<ul>\n<li>apache hadoop<\/li>\n<li>hortonworks hadoop (HDP)<\/li>\n<li>cloudera hadoop (CDH)<\/li>\n<li>mapr<\/li>\n<li>transwarp<\/li>\n<\/ul>\n<h1 id=\"\u5b89\u88c5hadoop\">\u5b89\u88c5hadoop<\/h1>\n<p>hadoop\u6709\u4e09\u79cd\u5b89\u88c5\u6a21\u5f0f\uff1a<\/p>\n<ul>\n<li>\u5355\u8282\u70b9\u6a21\u5f0f<\/li>\n<li>\u4f2a\u5206\u5e03\u5f0f\u6a21\u5f0f<\/li>\n<li>\u5206\u5e03\u5f0f\u6a21\u5f0f<\/li>\n<\/ul>\n<p>\u53c2\u8003Linux Admin\u548cNetwork SSH\u5982\u4f55\u5b89\u88c5\u591a\u53f0centos\uff0c\u5e76\u4e14\u914d\u7f6e\u5c40\u57df\u7f51\uff0c\u8ba9\u672c\u5730\u591a\u53f0\u673a\u5668\u76f8\u4e92\u8bbf\u95ee\uff0e<\/p>\n<p>\u4e0b\u8f7dhadoop\u7684\u4e8c\u8fdb\u5236\u5b89\u88c5\u5305\uff0c\u7136\u540e\u653e\u5230\/home\/hadoop\/\u76ee\u5f55\u4e0b\u5e76\u89e3\u538b\uff0e<\/p>\n<p>\u63a8\u8350\u7684cluster node:<\/p>\n<pre><code>NameNode(hdfs)\nSecondary NameNode(hdfs)\nDataNode(hdfs)\nResourceManager server(yarn)\nNodeManager server(yarn)\nWebAppProxy server(yarn)\nMapReduceJobHistory server(mapreduce)\n<\/code><\/pre>\n<p>\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<pre><code>$ vim ~\/.bash_profile\nexport JAVA_HOME=\/usr\/lib\/jvm\/java-1.8.0-openjdk-...\/jre\nexport HADOOP_HOME=\/home\/hadoop\/hadoop-3.0.0-alpha2\nexport PATH=$JAVA_HOME\/bin:$HADOOP_HOME\/bin:$PATH\n$ source ~\/.bash_profile\n<\/code><\/pre>\n<p>\u4fee\u6539hadoop\u7684\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<pre><code>$ cd hadoop-3.0.0-alpha2\/etc\/hadoop\n$ vim hadoop-env.sh\nexport JAVA_HOME='\/usr\/lib\/jvm\/java-1.8.0-openjdk-...\/jre\n# \u6d4b\u8bd5java\u548chadoop\u7684\u73af\u5883\u662f\u5426\u53ef\u7528\uff1a\n$ hadoop\n<\/code><\/pre>\n<p>\u5206\u5e03\u5f0f\u73af\u5883\u642d\u5efa\uff1a<\/p>\n<p><a class=\"link\" href=\"http:\/\/hadoop.apache.org\/docs\/current\/hadoop-project-dist\/hadoop-common\/ClusterSetup.html\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/hadoop.apache.org\/docs\/current\/hadoop-project-dist\/hadoop-common\/ClusterSetup.html<\/a><\/p>\n<pre><code>$ vim core-site.xml\n$ vim hdfs-site.xml # namenode, datanode\n$ vim yarn-site.xml # resourcemanager, nodemanager, webappproxy\n$ vim mapred-site.xml # mr application, mr jobhistory\n# slaves file\n$ vim workers\nnamenode\nsecondnamenode\ndatanode\ndatanode2\nyarnserver\nmjhserver\n# hadoop rack awareness\n# logging\n$ vim log4j.properties\n<\/code><\/pre>\n<p>CLI for hadoop cluster:<\/p>\n<p>\u542f\u52a8\u4e00\u4e2ahadoop\u3000cluster\u9700\u8981\u540c\u65f6\u542f\u52a8hdfs\u548cyarn, \u63a8\u8350\u7528\u5355\u72ec\u7684\u7528\u6237\u5206\u522b\u542f\u52a8\u8fd9\u4e24\u4e2a\u7ec4\u4ef6\uff0e<\/p>\n<pre><code># \u7b2c\u4e00\u6b21\u542f\u52a8hdfs\uff0c\u9700\u8981\u683c\u5f0f\u5316hdfs\n$ hdfs namenode -format &lt;cluster_name&gt;\n# \u542f\u52a8hdfs namenode \u548c\u3000datanode\n$ hdfs --daemon start namenode\n$ hdfs --daemon start datanode\n# \u5982\u679cssh\u5df2\u7ecf\u5b9e\u73b0\u65e0\u5bc6\u7801\u8fde\u63a5\uff0c\u53ef\u4ee5\u4e00\u6b21\u542f\u52a8cluster\u7684\u6240\u6709node\n$ $HADOOP_HOME\/sbin\/start-dfs.sh\n# \u542f\u52a8yarn resourcemanager\u3000\u548c\u3000nodemanager\n$ yarn --daemon start resourcemanager\n$ yarn --daemon start nodemanager\n# \u5982\u679c\u914d\u7f6e\u4e86slaves file \u5e76\u4e14cluster node\u5b9e\u73b0ssh\u65e0\u5bc6\u7801\u767b\u9646\uff0c\u53ef\u4ee5\u4e00\u6b21\u542f\u52a8\n$ $HADOOP_HOME\/sbin\/start-yarn.sh\n# \u542f\u52a8webappproxy server\n$ yarn --daemon start proxyserver\n# \u542f\u52a8MapReduce Jobhistory server.\n$ mapred --daemon start historyserver\n# stop namenode\n$ hdfs --daemon stop namenode\n# stop datanode\n$ hdfs --daemon stop datanode\n# stop at the same time\n$ $HADOOP_HOME\/sbin\/stop-dfs.sh\n# stop resourcemanager\n$ yarn --daemon stop resourcemanager\n# stop nodemanager\n$ yarn --daemon stop nodemanager\n# stop at the same time\n$ $HADOOP_HOME\/sbin\/stop-yarn.sh\n# stop webappproxy server\n$ yarn stop proxyserver\n# stop jobhistory server\n$ mapred --daemon stop historyserver\n<\/code><\/pre>\n<p>GUI for hadoop cluster:<\/p>\n<pre><code># namenode\nhttp:\/\/nn:9870\n# resource manager\nhttp:rm:8080\n# mapreduce job history server\nhttp:\/\/jhs:19888\n<\/code><\/pre>\n<hr>\n<h1 id=\"hadoop-commands\">Hadoop Commands<\/h1>\n<pre><code> hadoop [--config confdir] [--loglevel loglevel] [COMMAND] [GENERIC_OPTIONS] [COMMAND_OPTIONS]\n<\/code><\/pre>\n<p>user command:<\/p>\n<pre><code>$ hadoop archive\n$ hadoop fs\n...\n<\/code><\/pre>\n<p>admin command:<\/p>\n<pre><code>$ hadoop daemonlog\n...\n<\/code><\/pre>\n<hr>\n<h1 id=\"fs-commands\">fs commands<\/h1>\n<p>file system command:<\/p>\n<p>\u652f\u6301\u672c\u5730\u6587\u4ef6\u7cfb\u7edf\uff0chdfs\u6587\u4ef6\u7cfb\u7edf\uff0c\u8fd8\u6709\u5176\u5b83\u6587\u4ef6\u7cfb\u7edf\uff0e<\/p>\n<pre><code>$ hadoop fs\n$ hadoop fs -cat URI [URI ...]\n...\n<\/code><\/pre>\n<hr>"},{"title":"Hadoop HDFS","link":"https:\/\/canuxcheng.com\/post\/hadoop_hdfs\/","pubDate":"Mon, 11 Apr 2016 22:57:37 +0000","guid":"https:\/\/canuxcheng.com\/post\/hadoop_hdfs\/","description":"<h1 id=\"hdfs\">HDFS<\/h1>\n<p>Hadoop Distributed File System: hadoop\u5206\u5e03\u5f0f\u6587\u4ef6\u7cfb\u7edf<\/p>\n<p>hadoop hdfs\u5206\u4e3a\u4e09\u90e8\u5206:<\/p>\n<p>NameNode -&gt; JobTracker<\/p>\n<p>secondary NameNode<\/p>\n<p>DataNode -&gt; TaskTracker<\/p>\n<hr>\n<h1 id=\"hdfs-commands\">hdfs commands<\/h1>\n<pre><code>hdfs [SHELL_OPTIONS] COMMAND [GENERIC_OPTIONS] [COMMAND_OPTIONS]\n<\/code><\/pre>\n<p>user commands:<\/p>\n<pre><code>$ hdfs classpath\n$ hdfs dfs # \u53c2\u8003 hadoop fs\u547d\u4ee4\n...\n<\/code><\/pre>\n<p>admin commands:<\/p>\n<pre><code>$ hdfs balancer\n...\n<\/code><\/pre>\n<p>debug commands:<\/p>\n<pre><code>$ hdfs verify\n$ hdfs recoverLease\n<\/code><\/pre>\n<hr>"},{"title":"Hadoop YARN","link":"https:\/\/canuxcheng.com\/post\/hadoop_yarn\/","pubDate":"Mon, 11 Apr 2016 22:57:37 +0000","guid":"https:\/\/canuxcheng.com\/post\/hadoop_yarn\/","description":"<h1 id=\"yarn\">YARN<\/h1>\n<p>\u4f5c\u4e1a\u8c03\u5ea6\u548c\u96c6\u7fa4\u8d44\u6e90\u7ba1\u7406\u7684\u6846\u67b6\uff0e<\/p>\n<p>yarn\u7684\u4e24\u4e2a\u7ec4\u4ef6\uff1a<\/p>\n<ul>\n<li>resourcemanager<\/li>\n<li>nodemanager<\/li>\n<\/ul>\n<hr>\n<h1 id=\"yarn-commands\">yarn commands<\/h1>\n<pre><code>yarn [--config confdir] COMMAND [--loglevel loglevel] [GENERIC_OPTIONS] [COMMAND_OPTIONS]\n<\/code><\/pre>\n<p>user commands:<\/p>\n<pre><code>$ yarn application\n...\n<\/code><\/pre>\n<p>admin commands:<\/p>\n<pre><code>$ yarn daemonlog\n...\n<\/code><\/pre>\n<hr>\n<h1 id=\"resource-manager\">resource manager<\/h1>\n<p>resource manager\u7531\u4e24\u90e8\u5206\u7ec4\u6210\uff1a<\/p>\n<ul>\n<li>scheduler<\/li>\n<li>applicationmanager<\/li>\n<\/ul>\n<p>ResourceManager\u529f\u80fd\uff1a<\/p>\n<ul>\n<li>\u5904\u7406\u5ba2\u6237\u8bf7\u6c42<\/li>\n<li>\u542f\u52a8\uff0f\u76d1\u63a7applicationmaster<\/li>\n<li>\u76d1\u63a7nodemanager<\/li>\n<li>\u8d44\u6e90\u5206\u914d\u4e0e\u8c03\u5ea6<\/li>\n<\/ul>\n<p>ApplicationMaster\u529f\u80fd\uff1a<\/p>\n<ul>\n<li>\u6570\u636e\u5207\u5206<\/li>\n<li>\u4e3a\u5e94\u7528\u7533\u8bf7\u8d44\u6e90, \u5e76\u5206\u914d\u7ed9\u5185\u90e8\u4efb\u52a1<\/li>\n<li>\u4efb\u52a1\u76d1\u63a7\u4e0e\u5bb9\u9519<\/li>\n<\/ul>\n<hr>\n<h1 id=\"node-manager\">node manager<\/h1>\n<p>node manager\u529f\u80fd\uff1a<\/p>\n<ul>\n<li>\u5355\u4e2a\u8282\u70b9\u7684\u8d44\u6e90\u7ba1\u7406<\/li>\n<li>\u5904\u7406\u6765\u81earesourcemanager\u7684\u547d\u4ee4<\/li>\n<\/ul>\n<hr>"},{"title":"Package","link":"https:\/\/canuxcheng.com\/post\/c_package\/","pubDate":"Mon, 11 Apr 2016 22:57:37 +0000","guid":"https:\/\/canuxcheng.com\/post\/c_package\/","description":"<h1 id=\"package\">Package<\/h1>"},{"title":"BigData","link":"https:\/\/canuxcheng.com\/post\/bigdata\/","pubDate":"Mon, 11 Apr 2016 22:57:37 +0800","guid":"https:\/\/canuxcheng.com\/post\/bigdata\/","description":"<h1 id=\"bigdata\">BigData<\/h1>\n<p>\u5927\u6570\u636e\u6700\u6d41\u884c\u7684\u6846\u67b6\u662fhadoop.<\/p>\n<p>\u5927\u90e8\u5206\u5de5\u5177\u90fd\u5c5e\u4e8eApache\u57fa\u91d1\u4f1a\u7684\u9879\u76ee\uff0e<\/p>\n<h1 id=\"mpp\">MPP<\/h1>\n<p>Massive Parallel Process<\/p>\n<p>\u5927\u89c4\u6a21\u5e76\u884c\u5904\u7406\u6570\u636e\u5e93\u5305\u62ecimpala, hawq<\/p>\n<hr>\n<h1 id=\"\u5206\u5e03\u5f0f\u5b58\u50a8\">\u5206\u5e03\u5f0f\u5b58\u50a8<\/h1>\n<h2 id=\"hadoop-hdfs\">hadoop hdfs<\/h2>\n<hr>\n<h1 id=\"\u8d44\u6e90\u8c03\u5ea6\">\u8d44\u6e90\u8c03\u5ea6<\/h1>\n<h2 id=\"hadoop-yarn\">hadoop yarn<\/h2>\n<hr>\n<h1 id=\"\u5206\u5e03\u5f0f\u8ba1\u7b97\u6846\u67b6\">\u5206\u5e03\u5f0f\u8ba1\u7b97\u6846\u67b6<\/h1>\n<h2 id=\"hadoop-mapreduce\">hadoop mapreduce<\/h2>\n<h2 id=\"spark\">Spark<\/h2>\n<h1 id=\"\u6d41\u5f0f\u8ba1\u7b97\u6846\u67b6\">\u6d41\u5f0f\u8ba1\u7b97\u6846\u67b6<\/h1>\n<h2 id=\"storm\">Storm<\/h2>\n<h2 id=\"flink\">Flink<\/h2>\n<hr>\n<h1 id=\"\u90e8\u7f72\u5de5\u5177\">\u90e8\u7f72\u5de5\u5177<\/h1>\n<h2 id=\"ambari\">Ambari<\/h2>\n<p>\u7528\u4e8e\u914d\u7f6e\uff0c\u7ba1\u7406\uff0c\u76d1\u63a7hadoop\u96c6\u7fa4\u7684web\u5de5\u5177\uff0e<\/p>\n<h2 id=\"bigtop\">Bigtop<\/h2>\n<p>\u5bf9hadoop\u76f8\u5173\u8f6f\u4ef6\u6253\u5305\uff0c\u5206\u53d1\uff0c\u6d4b\u8bd5\u7684\u5de5\u5177\uff0e<\/p>\n<h2 id=\"whirr\">whirr<\/h2>\n<h2 id=\"cloudera-hue\">Cloudera Hue<\/h2>\n<h2 id=\"hortonworks-hoya\">Hortonworks hoya<\/h2>\n<h1 id=\"\u670d\u52a1\u7f16\u7a0b\">\u670d\u52a1\u7f16\u7a0b<\/h1>\n<h2 id=\"zookeeper\">Zookeeper<\/h2>\n<p>\u5206\u5e03\u5f0f\u5e94\u7528\u7a0b\u5e8f\u7684\u9ad8\u6027\u80fd\u534f\u8c03\u670d\u52a1<\/p>\n<h2 id=\"curator\">Curator<\/h2>\n<h2 id=\"avro\">Avro<\/h2>\n<h2 id=\"chuckwa\">chuckwa<\/h2>\n<p>\u7528\u4e8e\u76d1\u63a7\u5927\u578b\u5206\u5e03\u5f0f\u7cfb\u7edf\u7684\u6570\u636e\u6536\u96c6\u7cfb\u7edf\uff0e<\/p>\n<hr>\n<h1 id=\"\u4ea4\u4e92\u5f0f\u5206\u6790\u6846\u67b6sql-on-hadoop\">\u4ea4\u4e92\u5f0f\u5206\u6790\u6846\u67b6(Sql On Hadoop)<\/h1>\n<h2 id=\"facebook-presto\">Facebook Presto<\/h2>\n<h2 id=\"hive\">Hive<\/h2>\n<h2 id=\"hawqpivotal\">Hawq(Pivotal)<\/h2>\n<p>Hortonworks\u7684HDP\u96c6\u6210\u4e86HAWQ.<\/p>\n<h2 id=\"impalacloudera\">Impala(Cloudera)<\/h2>\n<p>Cloudera\u7684CHD\u96c6\u6210\u4e86Impala.<\/p>\n<h1 id=\"\u4ea4\u4e92\u5f0f\u5206\u6790\u6846\u67b6nosql-on-hadoop\">\u4ea4\u4e92\u5f0f\u5206\u6790\u6846\u67b6(NoSQL On Hadoop)<\/h1>\n<h2 id=\"hbase\">HBase<\/h2>\n<h2 id=\"cassandra\">Cassandra<\/h2>\n<hr>\n<h1 id=\"\u6570\u636e\u7ba1\u7406\u5de5\u5177\">\u6570\u636e\u7ba1\u7406\u5de5\u5177<\/h1>\n<h2 id=\"sqoop\">Sqoop<\/h2>\n<h2 id=\"flume\">Flume<\/h2>\n<h1 id=\"\u6d88\u606f\u961f\u5217\">\u6d88\u606f\u961f\u5217<\/h1>\n<h2 id=\"kafka\">Kafka<\/h2>\n<h2 id=\"pivotal-rabbitmq\">Pivotal RabbitMQ<\/h2>\n<hr>\n<h1 id=\"dsl\">DSL<\/h1>\n<h2 id=\"pig\">Pig<\/h2>\n<hr>\n<h1 id=\"workflow-and-lifecycle\">Workflow and Lifecycle<\/h1>\n<h2 id=\"oozie\">Oozie<\/h2>\n<h2 id=\"aurora\">aurora<\/h2>\n<h2 id=\"falcon\">falcon<\/h2>\n<hr>\n<h1 id=\"security\">Security<\/h1>\n<h2 id=\"sentry\">Sentry<\/h2>\n<hr>\n<h1 id=\"data-search\">Data search<\/h1>\n<h2 id=\"solr\">Solr<\/h2>\n<h2 id=\"nutch\">Nutch<\/h2>\n<h2 id=\"lucene\">Lucene<\/h2>\n<hr>\n<h1 id=\"data-analytics\">Data Analytics<\/h1>\n<h2 id=\"mahout\">Mahout<\/h2>\n<h2 id=\"kuducloudera\">Kudu(Cloudera)<\/h2>\n<hr>\n<h1 id=\"misc\">Misc<\/h1>\n<h2 id=\"hama\">hama<\/h2>\n<h2 id=\"giraph\">giraph<\/h2>\n<h2 id=\"crunch\">crunch<\/h2>\n<h2 id=\"hcatalog\">hcatalog<\/h2>"},{"title":"France","link":"https:\/\/canuxcheng.com\/post\/travel_france\/","pubDate":"Sun, 10 Apr 2016 17:49:15 +0000","guid":"https:\/\/canuxcheng.com\/post\/travel_france\/","description":"<h1 id=\"\u6cd5\u56fd\u4e4b\u65c5\">\u6cd5\u56fd\u4e4b\u65c5<\/h1>\n<p>\u770b\u7167\u7247\uff1a<\/p>\n<p><a class=\"link\" href=\"http:\/\/user.qzone.qq.com\/1085694641\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/user.qzone.qq.com\/1085694641<\/a><\/p>\n<p>\u6234\u9ad8\u4e50\u673a\u573a<\/p>\n<p>\u96c5\u9ad8\u96c6\u56e2\u7684\u5b9c\u5fc5\u601d\u9152\u5e97<\/p>\n<p>SNCF\u7684TVG\u706b\u8f66<\/p>\n<p>\u6cd5\u56fd\u670922\u4e2a\u5927\u533a\u3002<\/p>\n<h1 id=\"\u6cd5\u5170\u897f\u5c9b\">\u6cd5\u5170\u897f\u5c9b<\/h1>\n<h2 id=\"\u5df4\u9ece\u7701\">\u5df4\u9ece\u7701<\/h2>\n<p>\u5df4\u9ece\u662f\u6cd5\u56fd\u9996\u90fd\uff0c\u5927\u533a\u9996\u5e9c\u548c\u8be5\u7701\u7701\u4f1a\u3002<\/p>\n<p>\u57c3\u83f2\u5c14\u94c1\u5854<\/p>\n<p>\u51ef\u65cb\u95e8<\/p>\n<p>\u585e\u7eb3\u6cb3<\/p>\n<p>\u5362\u6d6e\u5bab<\/p>\n<p>\u5df4\u9ece\u5723\u6bcd\u9662<\/p>\n<h2 id=\"\u4f0a\u592b\u6797\u7701\">\u4f0a\u592b\u6797\u7701<\/h2>\n<p>\u51e1\u5c14\u8d5b\u662f\u8be5\u7701\u7701\u4f1a\u3002<\/p>\n<p>\u8457\u540d\u666f\u70b9\u51e1\u5c14\u8d5b\u5bab\u3002<\/p>\n<h2 id=\"\u585e\u7eb3-\u9a6c\u6069\u7701\">\u585e\u7eb3-\u9a6c\u6069\u7701<\/h2>\n<p>\u8457\u540d\u666f\u70b9\u67ab\u4e39\u767d\u9732\u3002<\/p>\n<h1 id=\"\u5f17\u6717\u4ec0-\u5b54\u6cf0\">\u5f17\u6717\u4ec0-\u5b54\u6cf0<\/h1>\n<h2 id=\"\u675c\u7701\">\u675c\u7701<\/h2>\n<p>\u8d1d\u6851\u677e\u662f\u5927\u533a\u9996\u5e9c\u548c\u7701\u4f1a\u3002<\/p>\n<p>\u8499\u8d1d\u5229\u4e9a\u5c14\u662f\u675c\u7701\u7684\u4e00\u4e2a\u533a\u3002<\/p>\n<h2 id=\"\u8d1d\u5c14\u798f\u5730\u533a\">\u8d1d\u5c14\u798f\u5730\u533a<\/h2>\n<p>\u8d1d\u5c14\u798f\u662f\u7701\u4f1a\u9a7b\u5730,\u4e0e\u745e\u58eb\u76f8\u90bb\u3002<\/p>\n<p>\u666f\u70b9\u6709\u8d1d\u5c14\u798f\u96c4\u72ee\u3002<\/p>\n<p>Eurock\u00e9ennes\u6cd5\u56fd\u6700\u5927\u7684\u6447\u6eda\u97f3\u4e50\u8282\u3002<\/p>\n<h1 id=\"\u963f\u5c14\u8428\u65af\">\u963f\u5c14\u8428\u65af<\/h1>\n<p>\u65af\u7279\u62c9\u65af\u5821\u662f\u7701\u4f1a\u3002<\/p>\n<h2 id=\"\u4e0b\u83b1\u8335\u7701\">\u4e0b\u83b1\u8335\u7701<\/h2>\n<p>\u65af\u7279\u62c9\u65af\u5821\u662f\u5927\u533a\u9996\u5e9c\u548c\u7701\u4f1a\u3002<\/p>\n<h2 id=\"\u4e0a\u83b1\u8335\u7701\">\u4e0a\u83b1\u8335\u7701<\/h2>\n<p>\u79d1\u5c14\u9a6c\u662f\u8be5\u7701\u7684\u9996\u5e9c,\u662f\u7ae5\u8bdd\u5c0f\u9547\u3002<\/p>"},{"title":"MSSql","link":"https:\/\/canuxcheng.com\/post\/mssql\/","pubDate":"Wed, 06 Apr 2016 15:33:42 +0000","guid":"https:\/\/canuxcheng.com\/post\/mssql\/","description":"<h1 id=\"mssql\">MSSQL<\/h1>\n<p>\u5546\u4e1a\u7248\uff1a<\/p>\n<ol>\n<li>\u4f01\u4e1a\u7248<\/li>\n<li>\u5546\u4e1a\u667a\u80fd\u7248<\/li>\n<li>\u6807\u51c6\u7248<\/li>\n<\/ol>\n<p>\u514d\u8d39\u7248\uff1a<\/p>\n<ol>\n<li>Express<\/li>\n<li>Developer<\/li>\n<li>Compact<\/li>\n<li>Web<\/li>\n<li>SQL Azure<\/li>\n<\/ol>\n<p>system databases:<\/p>\n<ol>\n<li>master \u4e3b\u6570\u636e\u5e93<\/li>\n<li>model \u6a21\u677f\u6570\u636e\u5e93<\/li>\n<li>msdb \u81ea\u52a8\u673a\u6570\u636e\u5e93<\/li>\n<li>tempdb \u96f6\u65f6\u4ea4\u6362\u6570\u636e\u5e93,\u4e0d\u9700\u8981\u5907\u4efd,\u6302\u8f7d\u5230\u72ec\u7acb\u7684\u5b50\u7cfb\u7edf\u3002<\/li>\n<li>resource<\/li>\n<\/ol>\n<p>default port\uff1a1433<\/p>\n<p>2008: max instance 16<\/p>\n<p>2012: max instance 256<\/p>\n<p>Client -&gt; SNAC(OLE DB\/ODBC) -&gt; Network Libraries -&gt; TDS &lt;=&gt; Server -&gt; Endpoints -&gt; SQL OS(relational engine\/storage engine)<\/p>\n<h2 id=\"gui\">GUI<\/h2>\n<ul>\n<li>\n<p>SSMS<\/p>\n<p>SQL Server Management Studio\u662fmssql\u7684\u56fe\u5f62\u5316\u7ba1\u7406\u754c\u9762\u3002<\/p>\n<p>\u4ece\u6a21\u677f\u4e2d\u83b7\u53d6\u5e38\u7528\u7684SQL\uff1a<\/p>\n<p>view -&gt; template explorer + query -&gt; specify values for template parameters.<\/p>\n<\/li>\n<li>\n<p>SSIS<\/p>\n<p>\u6570\u636e\u96c6\u6210\u670d\u52a1\u3002<\/p>\n<\/li>\n<li>\n<p>cliconfg.exe<\/p>\n<p>\u7528\u4e8e\u7ed9\u6570\u636e\u5e93\u53d6\u522b\u540d\u5e76\u5206\u53d1\u3002<\/p>\n<\/li>\n<\/ul>\n<h2 id=\"cli\">CLI<\/h2>\n<ul>\n<li>\n<p>sqlcmd<\/p>\n<p>SQL Server\u7684\u547d\u4ee4\u884c\u754c\u9762\u3002<\/p>\n<pre><code> sqlcmd -? # \u67e5\u770b\u5e2e\u52a9\nsqlcmd \/?\nsqlcmd -A # \u7ba1\u7406\u5458\u4e13\u7528\u6a21\u5f0f\u3002\n<\/code><\/pre>\n<\/li>\n<li>\n<p>bcp<\/p>\n<p>\u6570\u636e\u5e93import\/export\u5de5\u5177<\/p>\n<pre><code> bcp -? # \u67e5\u770b\u5e2e\u52a9\nbcp XXX out XXX -T -c\n<\/code><\/pre>\n<\/li>\n<li>\n<p>sqlps<\/p>\n<p>SQL Server\u7684PowerShell\u547d\u4ee4\u884c\u6a21\u5f0f\u3002<\/p>\n<\/li>\n<\/ul>\n<hr>\n<h1 id=\"\u6570\u636e\u7c7b\u578b\">\u6570\u636e\u7c7b\u578b<\/h1>\n<p>\u4e09\u79cd\u6570\u636e\u7c7b\u578b\uff1a<\/p>\n<ol>\n<li>system data types<\/li>\n<li>alias data types<\/li>\n<li>user-defined data types<\/li>\n<\/ol>\n<p>system data\u6709\u4e0b\u9762\u7c7b\u578b\uff1a<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7SSMS\u67e5\u770b\u3002<\/p>\n<pre><code>tinyint: 8bits\nsmallint: 16bits\nint: 32bits\nbigint: 64bits\ndecimal:\nnumeric:\nsmallmoney: 32bits\nmoney: 64bits\nbit: 0\/1\nfloat: &lt;=53bits\nreal: 32bits\ndate:\ndatetime2:\ndatetime:\ndatetimeoffset:\nsmalldatetime:\ntime:\n# \u53ea\u80fd\u7528\u5355\u5f15\u53f7\uff0c\u4e0d\u80fd\u7528\u53cc\u5f15\u53f7\nchar:\nnchar:\nvarchar:\nnvarchar:\nvarchar(max): &lt;=2GB\nnvarchar(max): &lt;=2GB\nrowversion:\n<\/code><\/pre>\n<h2 id=\"data-attribution\">data attribution<\/h2>\n<pre><code>uniqueidentifer\nnull\nnot null\nunicode\ncollate\n<\/code><\/pre>\n<h2 id=\"modify-data-type\">modify data type<\/h2>\n<pre><code>cast\nconvert\ntry_convert\nparse\ntry_parse\nImplicit data conversion(\u9690\u5f0f\u7684\u6570\u636e\u8f6c\u6362)\u3002\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u51fd\u6570\u548c\u64cd\u4f5c\u7b26\">\u51fd\u6570\u548c\u64cd\u4f5c\u7b26<\/h1>\n<p>date &amp; time:<\/p>\n<pre><code>Current_Timestamp \/\/ 2018-11-18 00:33:27.840\nGetdate() \/\/ 2018-11-18 00:34:00.173\nGetutcdate() \/\/ 2018-11-18 08:34:11.137\nSysdatetime() \/\/ 2018-11-18 00:34:59.9698057\nSysutcdatetime() \/\/ 2018-11-18 08:35:30.6485379\nDATEDIFF(datepart varchar, startingdate datetime, endingdate datetime) \/\/ \u8fd4\u56de\u4e24\u4e2a\u65f6\u95f4\u7684\u95f4\u9694\nDATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE()) # \u5f53\u524d\u65f6\u95f4\u7684epoch time.\nDATEADD()\nDATEPART()\nDATENAME()\n<\/code><\/pre>\n<p>other:<\/p>\n<pre><code>Cast()\nNullif()\nIsnull(column, 0) column\u4e3aNULL\u51fd\u6570\u8fd4\u56de0\nConvert()\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u5e38\u7528sql\">\u5e38\u7528sql<\/h1>\n<pre><code>select @@version()\n<\/code><\/pre>\n<hr>\n<h1 id=\"security\">Security<\/h1>\n<p>\u8bbe\u7f6e\u6743\u9650\uff1a<\/p>\n<ol>\n<li>\u6570\u636e\u5e93\u670d\u52a1\u5668\u7ea7\u522b\u6743\u9650<\/li>\n<li>\u6570\u636e\u5e93\u6743\u9650<\/li>\n<li>\u8868\u7ea7\u6743\u9650(schema)<\/li>\n<li>\u5217\u7ea7\u6743\u9650<\/li>\n<\/ol>\n<ul>\n<li>\n<p>\u6570\u636e\u5e93\u670d\u52a1\u5668\u7684security<\/p>\n<ol>\n<li>\u53ef\u4ee5\u521b\u5efaLogins\u7528\u6237\uff0c\u5305\u62ecsa\u5e10\u53f7\u548cwindows\u7684AD\u5e10\u53f7\u3002<\/li>\n<\/ol>\n<\/li>\n<li>\n<p>\u6570\u636e\u5e93\u7684security<\/p>\n<ol>\n<li>\u53ef\u4ee5\u521b\u5efaUsers\u7528\u6237\uff0c\u7528\u4e8e\u8fde\u63a5\u8fd9\u4e2a\u6570\u636e\u5e93\u3002<\/li>\n<li>\u53ef\u4ee5\u521b\u5efa\u548c\u8bbe\u7f6eschemas,\u9ed8\u8ba4dbo\u3002<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<p>\u6743\u9650\u7684\u8bbe\u7f6e\u5728SSMS\u7684 \u5c5e\u6027-&gt;\u6743\u9650 \u91cc\u9762\u8bbe\u7f6e\u3002<\/p>\n<hr>\n<h1 id=\"\u6570\u636e\u7ed3\u6784\">\u6570\u636e\u7ed3\u6784<\/h1>\n<h2 id=\"tables\">tables<\/h2>\n<p>\u521b\u5efacreate\uff0c\u66f4\u65b0alert\uff0c\u5220\u9664drop\u90fd\u662f\u6807\u51c6sql\u3002<\/p>\n<p>\u63d2\u5165insert\uff0c\u66f4\u6539update\uff0c\u5220\u9664delete\u8868\u7684\u5185\u5bb9\u90fd\u662f\u6807\u51c6sql\u3002<\/p>\n<ul>\n<li>\n<p>merge<\/p>\n<p>\u4f7f\u7528merge\u6765\u5feb\u901f\u63d2\u5165\uff0c\u6ca1\u6709\u5c31insert\uff0c\u6709\u5c31update\u3002<\/p>\n<\/li>\n<\/ul>\n<h2 id=\"views\">views<\/h2>\n<p>\u521b\u5efacreate\uff0c\u66f4\u65b0alert\uff0c\u5220\u9664drop\u90fd\u662f\u6807\u51c6sql\u3002<\/p>\n<ul>\n<li>\n<p>system views<\/p>\n<p>\u7cfb\u7edf\u89c6\u56fe\u90fd\u662f\u4ee5sys\u5f00\u5934\u7684\u3002<\/p>\n<pre><code> SELECT * FROM [dbname].sys.databases # \u67e5\u8be2\u6240\u6709\u6570\u636e\u5e93\u4fe1\u606f\u3002\nSELECT * FROM [dbname].sys.servers\nSELECT * FROM [dbname].sys.services\n<\/code><\/pre>\n<\/li>\n<li>\n<p>\u7528\u6237\u81ea\u5b9a\u4e49\u7684view<\/p>\n<\/li>\n<\/ul>\n<h2 id=\"index\">index<\/h2>\n<p>\u521b\u5efacreate\uff0c\u66f4\u65b0alert\uff0c\u5220\u9664drop\u90fd\u662f\u6807\u51c6sql\u3002<\/p>\n<p>table\u548cview\u90fd\u6709index\u3002<\/p>\n<hr>\n<h1 id=\"database-actions\">database actions<\/h1>\n<h2 id=\"administrator-command\">administrator command<\/h2>\n<p>sa\u662f\u6570\u636e\u5e93\u9ed8\u8ba4\u7684\u7ba1\u7406\u5458,dbcc\u9700\u8981sa\u6743\u9650\u6267\u884c\u3002<\/p>\n<pre><code>DBCC HELP('?') # \u67e5\u8be2\u6240\u6709DBCC\u547d\u4ee4\nDBCC HELP('command') # \u67e5\u8be2\u5177\u4f53\u547d\u4ee4\u7684\u5e2e\u52a9\n<\/code><\/pre>\n<p>\u521b\u5efa\/\u5220\u9664\u6570\u636e\u5e93\uff1a<\/p>\n<pre><code>CREATE DATABASE databasename;\nDROP DATABASE databasename;\n<\/code><\/pre>\n<h2 id=\"replication\">replication<\/h2>\n<p>\u5728\u4e0d\u540c\u7684\u6570\u636e\u5e93\u670d\u52a1\u5668\u4e4b\u95f4\u5bfc\u6570\u636e\u3002<\/p>\n<h2 id=\"transaction-log-ship\">transaction log ship<\/h2>\n<p>\u5728\u4e0d\u540c\u7684\u6570\u636e\u5e93\u670d\u52a1\u5668\u4e4b\u95f4\u5bfc\u6570\u636e\u3002<\/p>\n<h2 id=\"db-tasks-importexportcopy\">db-&gt;tasks-&gt;import\/export\/copy<\/h2>\n<p>\u5bfc\u5165\/\u5bfc\u51fa\/\u590d\u5236\uff0c\u4ee5\u8868\u4e3a\u5355\u4f4d\u8fdb\u884c\u590d\u5236\u3002<\/p>\n<hr>\n<h1 id=\"programmabilityt-sql\">programmability(T-SQL)<\/h1>\n<h2 id=\"sql-query\">sql query<\/h2>\n<p>\u548c\u6807\u51c6SQL\u64cd\u4f5c\u4e00\u6837\u3002<\/p>\n<pre><code>bulk insert\n<\/code><\/pre>\n<h2 id=\"stored-procedures\">Stored Procedures<\/h2>\n<ul>\n<li>\n<p>system stored Procedures(\u7cfb\u7edf\u81ea\u5e26\u7684SP)<\/p>\n<p>sys.sp_XXX\u662f\u7cfb\u7edfSP\u3002\nsys.xp_XXX\u662f\u6269\u5c55SP\u3002<\/p>\n<\/li>\n<li>\n<p>\u7528\u6237\u81ea\u5b9a\u4e49\u7684SP<\/p>\n<\/li>\n<\/ul>\n<ol>\n<li>\n<p>\u521b\u5efaSP<\/p>\n<pre><code> CREATE PROCEDURE &lt;schema&gt;.&lt;procedure&gt;\n@p1 type = value1\n@p2 type = value2\n...\nAS\nBEGIN\nSELECT @p1, @p2, ...\nEND\nGO\n<\/code><\/pre>\n<\/li>\n<li>\n<p>\u4fee\u6539SP<\/p>\n<pre><code> ALERT PROCEURE &lt;schema&gt;.&lt;procedure&gt;\n@p1 type2 = value1\n@p2 type2 = value2\n...\nAS\nSELECT @p1, @p2 ...\nGO\n<\/code><\/pre>\n<\/li>\n<li>\n<p>\u6267\u884cSP<\/p>\n<pre><code> EXECUTE\/EXEC &lt;Schema&gt;.&lt;Procedure&gt; &lt;value1&gt; &lt;value2&gt; ...\nGO\n\u8be5sql\u8bed\u53e5\u53ef\u4ee5\u6267\u884cdos\u547d\u4ee4\nexec xp_cmdshell 'net user username 2546 \/add' # \u65b0\u5efa\u7cfb\u7edf\u7528\u6237\nexec xp_cmdshell 'net localgroup administrator username \/add' # \u6388\u6743\n<\/code><\/pre>\n<\/li>\n<li>\n<p>\u5220\u9664SP<\/p>\n<pre><code> DROP PROCEDURE &lt;procedure&gt;\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<h2 id=\"functions\">functions<\/h2>\n<ul>\n<li>\n<p>system functions<\/p>\n<p>\u7cfb\u7edf\u81ea\u5e26\u7684\u51fd\u6570\u3002<\/p>\n<pre><code> SELECT @@VERSION\nSELECT @@SERVERNAME\nSELECT @@SERVICENAME\n<\/code><\/pre>\n<\/li>\n<li>\n<p>scalar functions<\/p>\n<p>scalar-valued: \u6807\u91cf\u51fd\u6570\uff0c\u8fd4\u56de\u5355\u4e00\u503c\u3002<\/p>\n<\/li>\n<li>\n<p>table-valued functions<\/p>\n<p>\u8868\u503c\u51fd\u6570\uff0c\u8fd4\u56de\u4e00\u4e2a\u6570\u636e\u548c\u7c7b\u578b\u5bf9\u7684\u8868\u3002\ninline table-valued: \u5185\u5d4c\u7684\u8868\u503c\u51fd\u6570\u3002\nmulti-statement table-valued:<\/p>\n<\/li>\n<\/ul>\n<ol>\n<li>\n<p>\u521b\u5efascalar-valued\u51fd\u6570<\/p>\n<pre><code> CREATE FUNCTION &lt;schema&gt;.&lt;function&gt; (@p1 type1)\nRETURNS return_value_datatype\nWITH EXECUTE AS CALLER\nAS\nBEGIN\nbody of the function\nEND\nGO\n<\/code><\/pre>\n<\/li>\n<li>\n<p>\u521b\u5efainline table-valued\u51fd\u6570<\/p>\n<\/li>\n<li>\n<p>\u521b\u5efamulti-statement table-valued\u51fd\u6570<\/p>\n<\/li>\n<li>\n<p>\u5220\u9664\u51fd\u6570<\/p>\n<pre><code> DROP FUNCTION &lt;schema&gt;.&lt;function&gt;\nGO\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<h2 id=\"debug\">debug<\/h2>\n<p>11-16<\/p>\n<p>RAISE ERROR<\/p>\n<p>THROW error, &lsquo;msg&rsquo;, number;<\/p>\n<hr>\n<h1 id=\"wmi\">wmi<\/h1>\n<p>\u5b89\u88c5mssql\u4e4b\u540e\u63d0\u4f9bmssql\u7684wmi\u7684\u7c7b\uff1a<\/p>\n<p>\u901a\u8fc7\u8fd0\u884cwql\u83b7\u53d6\u6570\u636e\u5e93\u5c5e\u6027\u3002<\/p>\n<pre><code>select * from Win32_PerfFormattedData_MSSQLSERVER_SQLServerLocks\n<\/code><\/pre>\n<h1 id=\"powershell\">powershell<\/h1>\n<p>\u901a\u8fc7powershell\u8fd0\u884csql\u8bed\u53e5\u6216store procedure\uff1a<\/p>\n<pre><code>$connection = new-object System.Data.SqlClient.SqlConnection &quot;Server=$server;Database=$database&quot;;Trusted_Connection=True&quot;\n$connection.Open()\n$sql = &quot;select @@version&quot;\n$command = new-object System.Data.SqlClient.SqlCommand $sql $connection\n$return = $command.ExecuteReader()\n<\/code><\/pre>\n<p>\u5b89\u88c5mssql\u4e4b\u540e\u63d0\u4f9bmssql\u7684powershell\u6a21\u5757sqlps\uff1a<\/p>\n<p>\u901a\u8fc7\u6a21\u5757\u7684\u547d\u4ee4\u8fd0\u884csql\u8bed\u53e5\u548cstore procedure\u3002<\/p>\n<pre><code>import-module sqlps\nget-command -module sqlps\ninvoke-sqlcmd -ServerInstance $serverinstance -Database $database -Query $sql\n<\/code><\/pre>\n<hr>\n<h1 id=\"freetds\">freeTDS<\/h1>\n<blockquote>\n<p>FreeTDS is a set of libraries for Unix and Linux that allows your programs to natively talk to Microsoft SQL Server and Sybase databases.<\/p>\n<\/blockquote>\n<p><a class=\"link\" href=\"http:\/\/www.freetds.org\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.freetds.org\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/FreeTDS\/freetds\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/FreeTDS\/freetds<\/a><\/p>\n<pre><code>$sudo apt-get install freetds-dev\n<\/code><\/pre>\n<p>\u914d\u7f6efreetds\uff0c\/etc\/freetds\/freetds.conf:<\/p>\n<pre><code># A typical Microsoft server\n[egServer70]\nhost = ntmachine.domain.com\nport = 1433\ntds version = 7.0\n<\/code><\/pre>\n<p>freetds\u7684\u547d\u4ee4\u884c\u5de5\u5177tsql:<\/p>\n<pre><code>$ sudo apt-get install freetds-bin\n$ man tsql\n<\/code><\/pre>\n<hr>\n<h1 id=\"monitoring\">Monitoring<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/Microsoft\/mssql-monitoring\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/Microsoft\/mssql-monitoring<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/blogs.msdn.microsoft.com\/sqlcat\/2017\/07\/03\/how-the-sqlcat-customer-lab-is-monitoring-sql-on-linux\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/blogs.msdn.microsoft.com\/sqlcat\/2017\/07\/03\/how-the-sqlcat-customer-lab-is-monitoring-sql-on-linux\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/docs.microsoft.com\/zh-cn\/sql\/relational-databases\/system-dynamic-management-views\/system-dynamic-management-views?view=sql-server-2017\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.microsoft.com\/zh-cn\/sql\/relational-databases\/system-dynamic-management-views\/system-dynamic-management-views?view=sql-server-2017<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/docs.microsoft.com\/zh-cn\/sql\/relational-databases\/system-dynamic-management-views\/sql-server-operating-system-related-dynamic-management-views-transact-sql?view=sql-server-2017\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/docs.microsoft.com\/zh-cn\/sql\/relational-databases\/system-dynamic-management-views\/sql-server-operating-system-related-dynamic-management-views-transact-sql?view=sql-server-2017<\/a><\/p>\n<p>\u53c2\u8003telegraf\/inputs\/sqlserver.<\/p>"},{"title":"CloudComputing","link":"https:\/\/canuxcheng.com\/post\/cloud_computing\/","pubDate":"Tue, 05 Apr 2016 22:02:31 +0000","guid":"https:\/\/canuxcheng.com\/post\/cloud_computing\/","description":"<h1 id=\"cloudcomputing\">CloudComputing<\/h1>\n<p>IAAS: Infrastructure as a service<\/p>\n<p>PAAS: Platform as a service<\/p>\n<p>SAAS: Software as a service<\/p>\n<h1 id=\"serverless\">Serverless<\/h1>\n<p>Faas: Function as a service.<\/p>\n<p>Baas: Backend as a service.<\/p>"},{"title":"Esxi","link":"https:\/\/canuxcheng.com\/post\/esxi\/","pubDate":"Tue, 05 Apr 2016 21:47:54 +0000","guid":"https:\/\/canuxcheng.com\/post\/esxi\/","description":"<h1 id=\"vmware\">VMware<\/h1>\n<p>vSphere\u662fvmware\u7684\u865a\u62df\u5316\u5e73\u53f0,\u5305\u62ecESXi\u548cvSphere Client.<\/p>\n<p>vSphere Hypervisor(\u4e5f\u53ebESXi)\u662fvSphere\u7684\u514d\u8d39\u88f8\u673ahypervisor. \u628a\u7269\u7406\u673a\u865a\u62df\u51fa\u591a\u4e2a\u865a\u62df\u673a\uff0e<\/p>\n<p>vSphere client\u662fvSphere\u7684\u7b80\u5355\u7ba1\u7406\u5de5\u5177\uff0e\u53ea\u80fd\u7ba1\u7406\u4e00\u53f0ESXi\u7269\u7406\u673a\u548c\u4e0a\u9762\u7684\u865a\u62df\u673a\uff0e<\/p>\n<p>vCenter Server\u662fvSphere\u7684\u9ad8\u7ea7\u7ba1\u7406\u7cfb\u7edf\uff0e\u9700\u5355\u72ec\u8d2d\u4e70\uff0e<\/p>\n<hr>\n<h1 id=\"\u914d\u7f6e\u7ba1\u7406\">\u914d\u7f6e\u7ba1\u7406<\/h1>\n<p>\u5f00\u542f\u865a\u62df\u673acopy\/paste\u529f\u80fd\uff1a<\/p>\n<pre><code># \u901a\u8fc7vsphere client\nedit properties -&gt; Options -&gt; Advanced -&gt; General -&gt; configuration Parameters\n# isolation.tools.copy.disable false\n# isolation.tools.paste.disable false\n<\/code><\/pre>\n<p>\u5f00\u542f\u865a\u62df\u673a\u7684\u865a\u62df\u5316\u529f\u80fd\uff1a<\/p>\n<pre><code># \u901a\u8fc7ssh\u5230esxi\u670d\u52a1\u5668\n$ vim \/vmfs\/volumes\/datastore1\/Ubuntu1604\/Ubuntu1604.vmx\nvhv.enable = &quot;TRUE&quot; # \u6dfb\u52a0\u5230\u6700\u540e\u4e00\u884c\n<\/code><\/pre>\n<p>\u521b\u5efa\u7684vm\u547d\u540d\u4e0d\u80fd\u5e26\u5c0f\u6570\u70b9.<\/p>\n<hr>\n<h1 id=\"\u547d\u4ee4\">\u547d\u4ee4<\/h1>\n<p>vim-cmd:<\/p>\n<pre><code>vim-cmd vmsvc\/getallvms # \u83b7\u53d6\u6240\u6709\u865a\u62df\u673a\nvim-cmd vmsvc\/reload\nvim-cmd vmsvc\/power.on vmid\nvim-cmd vmsvc\/power.shutdown vimid\nvim-cmd vmsvc\/power.off vimid\nvim-cmd vmsvc\/power.reboot vimid\n# power on all vms\nfor vm in `vim-cmd vmsvc\/getallvms | awk '{if (NR&gt;1) {print $1}}'`;\ndo\necho &quot;power on ${vm}...&quot;;\nvim-cmd vmsvc\/power.on ${vm}\ndone\n<\/code><\/pre>\n<p>esxcli:<\/p>\n<pre><code>esxcli vm process list # \u67e5\u770b\u6240\u6709\u8fd0\u884c\u7684vm\nesxcli vm process kill --type=[force\/soft\/hard] --world-id=&lt;world-id&gt; # \u5173\u673a\n<\/code><\/pre>\n<p>esxtop:<\/p>\n<pre><code># \u7c7b\u4f3c\u4e8elinux\u7684top\u547d\u4ee4\nesxtop\n<\/code><\/pre>\n<p>vscsiStats:<\/p>\n<pre><code>vscsiStats -l\n<\/code><\/pre>\n<hr>\n<h1 id=\"python\">python<\/h1>\n<p>pyVmomi is the Python SDK for the VMware vSphere API that allows you to manage ESX, ESXi, and vCenter.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/vmware\/pyvmomi\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/vmware\/pyvmomi<\/a><\/p>\n<pre><code>pip install pyvmomi\nfrom pyVmomi import vim\nfrom pyVim import connect\nsi = connect.SmartConnect(host='hostname', user='username', pwd='password', port='port')\ndef find_vm(si, name):\nct = si.content\nov = ct.viewManager.CreatecontainerView(ct.rootFolder, [vim.VirtualMachine], true)\nvm_list = ov.view\nfor vm in vm_list:\nif vm.name == &quot;vmname&quot;:\nreturn vm\nreturn None\n<\/code><\/pre>\n<hr>"},{"title":"Virtualization","link":"https:\/\/canuxcheng.com\/post\/virtualization\/","pubDate":"Tue, 05 Apr 2016 21:47:54 +0000","guid":"https:\/\/canuxcheng.com\/post\/virtualization\/","description":"<h1 id=\"virtualization\">Virtualization<\/h1>\n<p>\u865a\u62df\u5316\u6280\u672f\u7684\u53d1\u5c55\uff1a<\/p>\n<ol>\n<li>\n<p>DataCenter, \u6700\u539f\u59cb\u7684\u6570\u636e\u4e2d\u5fc3<\/p>\n<\/li>\n<li>\n<p>Virtualization, \u865a\u62df\u5316\u6280\u672f\uff0c\u5305\u62ecKvm, Xen(Citrix), HyperV(MicroSoft), ESXi(VMware)\u7b49<\/p>\n<\/li>\n<\/ol>\n<hr>"},{"title":"Monitoring","link":"https:\/\/canuxcheng.com\/post\/network_monitoring\/","pubDate":"Sun, 03 Apr 2016 14:46:19 +0000","guid":"https:\/\/canuxcheng.com\/post\/network_monitoring\/","description":"<h1 id=\"monitoring\">Monitoring<\/h1>\n<p>network usage:<\/p>\n<pre><code>bytes_sent(out)\nbytes_recv(in)\n<\/code><\/pre>\n<p>packets:<\/p>\n<pre><code>packets_sent(out)\npackets_recv(in)\n<\/code><\/pre>\n<p>error_in\/out:<\/p>\n<pre><code>SELECT non_negative_derivative(mean(&quot;err_in&quot;), 1s) AS &quot;recv&quot;,\nnon_negative_derivative(mean(&quot;err_out&quot;), 1s) AS &quot;send&quot;\nFROM &quot;net&quot;\nWHERE &quot;interface&quot; =~ \/^(vlan|eth|ens|bond).*\/ AND $timeFilter\nGROUP BY time($__interval), &quot;host&quot;, &quot;interface&quot; fill(none)\n<\/code><\/pre>\n<p>drop_in\/out:<\/p>\n<pre><code>SELECT non_negative_derivative(mean(&quot;drop_in&quot;), 1s) AS &quot;recv&quot;, non_negative_derivative(mean(&quot;drop_out&quot;), 1s) AS &quot;send&quot;\nFROM &quot;net&quot;\nWHERE &quot;interface&quot; =~ \/^(vlan|eth|ens|bond).*\/ AND $timeFilter\nGROUP BY time($__interval), &quot;host&quot;, &quot;interface&quot; fill(none)\n<\/code><\/pre>"},{"title":"Network","link":"https:\/\/canuxcheng.com\/post\/network\/","pubDate":"Sun, 03 Apr 2016 14:46:19 +0000","guid":"https:\/\/canuxcheng.com\/post\/network\/","description":"<h1 id=\"\u7f51\u7edc\u57fa\u7840\">\u7f51\u7edc\u57fa\u7840<\/h1>\n<p>\u5c0f\u7aef\uff1a \u4f4e\u5b57\u8282\u5728\u8d77\u59cb\u5730\u5740\uff0c\u9ad8\u5b57\u8282\u5728\u9ad8\u5730\u5740<\/p>\n<p>\u5927\u7aef\uff1a \u9ad8\u5b57\u8282\u5728\u8d77\u59cb\u5730\u5740\uff0c\u4f4e\u5b57\u8282\u5728\u9ad8\u5730\u5740<\/p>\n<p>linux\u4e00\u822c\u662f\u5c0f\u7aef\uff0cunix\u4e00\u822c\u662f\u5927\u7aef<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.rfc-editor.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.rfc-editor.org\/<\/a><\/p>\n<hr>\n<h2 id=\"osi\u7f51\u7edc\u6a21\u578b\">OSI\u7f51\u7edc\u6a21\u578b<\/h2>\n<p>Open Systems Interconnection (OSI) \u6a21\u578b\u662f\u4e00\u4e2a\u6807\u51c6\u5316\u7684\u7f51\u7edc\u901a\u4fe1\u6a21\u578b\uff0c\u5206\u4e3a\u4e03\u5c42\uff0c\u6bcf\u4e00\u5c42\u90fd\u6709\u7279\u5b9a\u7684\u529f\u80fd\u3002<\/p>\n<ul>\n<li>\n<p>\u5e94\u7528\u5c42<\/p>\n<\/li>\n<li>\n<p>\u8868\u793a\u5c42\uff1a\u6570\u636e\u538b\u7f29\uff0c\u6570\u636e\u52a0\u5bc6\uff0c\u6570\u636e\u63cf\u8ff0\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f1a\u8bdd\u5c42\uff1a\u5efa\u7acb\u3001\u7ba1\u7406\u548c\u7ec8\u6b62\u4f1a\u8bdd\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f20\u8f93\u5c42<\/p>\n<\/li>\n<li>\n<p>\u7f51\u7edc\u5c42<\/p>\n<\/li>\n<li>\n<p>\u94fe\u8def\u5c42<\/p>\n<\/li>\n<li>\n<p>\u7269\u7406\u5c42<\/p>\n<\/li>\n<\/ul>\n<h2 id=\"tcpip\u56db\u5c42\u6a21\u578b\">TCP\/IP\u56db\u5c42\u6a21\u578b<\/h2>\n<p>TCP\/IP\u6a21\u578b\u662f\u4e00\u4e2a\u7b80\u5316\u7684\u7f51\u7edc\u901a\u4fe1\u6a21\u578b\uff0c\u5206\u4e3a\u56db\u5c42\uff0c\u6bcf\u4e00\u5c42\u5bf9\u5e94OSI\u6a21\u578b\u7684\u4e00\u4e9b\u529f\u80fd\u3002<\/p>\n<ul>\n<li>\u5e94\u7528\u5c42<\/li>\n<li>\u4f20\u8f93\u5c42<\/li>\n<li>\u7f51\u7edc\u5c42<\/li>\n<li>\u7f51\u7edc\u63a5\u53e3\u5c42(\u4e5f\u53ef\u4ee5\u62c6\u5206\u6210\u7269\u7406\u5c42\u548c\u6570\u636e\u94fe\u8def\u5c42\u76845\u5c42\u6a21\u578b)<\/li>\n<\/ul>\n<h2 id=\"\u5e94\u7528\u5c42\">\u5e94\u7528\u5c42<\/h2>\n<p>0-1024\u662f\u7cfb\u7edf\u4fdd\u7559\u7aef\u53e3, 1024-65535\u662f\u53ef\u7528\u81ea\u5b9a\u4e49\u7aef\u53e3<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.iana.org\/assignments\/service-names-port-numbers\/service-names-port-numbers.xhtml\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.iana.org\/assignments\/service-names-port-numbers\/service-names-port-numbers.xhtml<\/a><\/p>\n<p>8443: tcp\/udp - https port\n9443: tcp\/udp tungsten-https\n4443: tcp\/udp pharos<\/p>\n<p>\u57fa\u4e8eTCP\u7684\u5e94\u7528\u5c42<\/p>\n<pre><code>FTP: 21,\nSSH: 22,\nTelnet: 23,\nSMTP: 25,\nHTTP: 80,\nHTTPS: 443,\nPOP3: 110,\nPOP3 SSL: 995\nIMAP: 143,\nIMAP SSL: 993,\nNNTP: 119,\nNNTP SSL: 563,\n<\/code><\/pre>\n<p>\u57fa\u4e8eUDP\u7684\u5e94\u7528\u5c42<\/p>\n<pre><code>DNS: 53,\nDHCP: 67,\nTFTP\uff1a69,\u7b80\u5355\u6587\u4ef6\u4f20\u8f93\u534f\u8bae\u3002\nNTP\/SNTP: 123,\nSNMP\uff1a161,\u7b80\u5355\u7f51\u7edc\u7ba1\u7406\u534f\u8bae\u3002\nSNMPtrap: 162,\n<\/code><\/pre>\n<p>\u57fa\u4e8eSCTP\u7684\u5e94\u7528\u5c42<\/p>\n<pre><code>M3UA: 2905\n<\/code><\/pre>\n<p>\u67e5\u770b\u7aef\u53e3<\/p>\n<pre><code>cat \/etc\/services\n<\/code><\/pre>\n<p>\u5e94\u7528\u7a0b\u5e8f\u67b6\u6784\uff1a\nC\/S\u67b6\u6784\uff1a\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u4e4b\u95f4\u901a\u8fc7\u7f51\u7edc\u8fdb\u884c\u901a\u4fe1(\u7ec6\u5206\u4e3aclient\/server\u548cbrowser\/server)\u3002\nPeer-to-Peer\u67b6\u6784\uff1a\u6bcf\u4e2a\u8282\u70b9\u90fd\u53ef\u4ee5\u5145\u5f53\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u3002<\/p>\n<h2 id=\"\u4f20\u8f93\u5c42\">\u4f20\u8f93\u5c42<\/h2>\n<p>TCP\uff1a\u4f20\u8f93\u63a7\u5236\u534f\u8bae\uff0c\u63d0\u4f9b\u53ef\u9760\u7684\u3001\u9762\u5411\u8fde\u63a5\u7684\u5b57\u8282\u6d41\u670d\u52a1,\u5efa\u7acb\u8fde\u63a5\u9700\u8981\u4e09\u6b21\u63e1\u624b\uff0e<\/p>\n<p>UDP\uff1a\u6570\u636e\u62a5\u534f\u8bae\uff0c\u63d0\u4f9b\u4e0d\u53ef\u9760\u7684\u3001\u65e0\u8fde\u63a5\u7684\u9762\u5411\u6570\u636e\u62a5\u7684\u670d\u52a1\u3002<\/p>\n<p>SCTP\uff1a\u6d41\u63a7\u5236\u4f20\u8f93\u534f\u8bae\u3002<\/p>\n<h2 id=\"\u7f51\u7edc\u5c42\">\u7f51\u7edc\u5c42<\/h2>\n<p>\u4e5f\u53eb\u4e92\u8054\u7f51\u5c42.<\/p>\n<p>IP\uff1a\u7f51\u9645\u534f\u8bae\uff0c\u63d0\u4f9b\u4e0d\u53ef\u9760\u3001\u65e0\u8fde\u63a5\u7684\u6570\u636e\u62a5\u4f20\u9001\u670d\u52a1\u3002<\/p>\n<p>ICMP\uff1aInternet\u63a7\u5236\u62a5\u6587\u534f\u8bae\uff0c\u4f20\u9012\u5dee\u9519\u62a5\u6587\u548c\u9700\u8981\u6ce8\u610f\u7684\u4fe1\u606f\uff0c\u5c01\u88c5\u5728IP\u6570\u636e\u62a5\u5185\u90e8\u3002<\/p>\n<pre><code># \u57fa\u4e8eICMP\u7684\u5e94\u7528\u5c42\uff1a\nPing:\nTraceroute:\n<\/code><\/pre>\n<p>IGMP\uff1aInternet\u7ec4\u7ba1\u7406\u534f\u8bae\uff0c\u7528\u4e8e\u652f\u6301\u4e3b\u673a\u548c\u8def\u7531\u5668\u8fdb\u884c\u591a\u64ad\uff0c\u8ba9\u4e00\u4e2a\u7269\u8054\u7f51\u7edc\u4e0a\u7684\u6240\u6709\u7cfb\u7edf\u77e5\u9053\u4e3b\u673a\u5f53\u524d\u6240\u5728\u7684\u591a\u64ad\u7ec4\uff0c\u5c01\u88c5\u5728IP\u6570\u636e\u62a5\u5185\u90e8\u3002<\/p>\n<h2 id=\"\u7f51\u7edc\u63a5\u53e3\u5c42\">\u7f51\u7edc\u63a5\u53e3\u5c42<\/h2>\n<p>\u4e5f\u53eb\u6570\u636e\u94fe\u8def\u5c42\u6216.<\/p>\n<p>\u4ee5\u592a\u7f51\u5e27\u7ed3\u6784\uff1a\u4ee5\u592a\u7f51\u9996\u90e8+IP\u9996\u90e8+TCP\u9996\u90e8\/UDP\u6570\u636e\u62a5+\u5e94\u7528\u6570\u636e+\u4ee5\u592a\u7f51\u5c3e\u90e8\u3002<\/p>\n<p>ARP\uff1a\u5730\u5740\u89e3\u6790\u534f\u8bae\uff0c\u4e3aIP\u5730\u5740\u5230\u786c\u4ef6\u5730\u5740\u4e4b\u95f4\u63d0\u4f9b\u52a8\u6001\u6620\u5c04\u3002<\/p>\n<p>RARP\uff1a\u6ca1\u6709\u78c1\u76d8\u9a71\u52a8\u5668\u7684\u7cfb\u7edf\u4f7f\u7528\u3002<\/p>\n<p>\u52a8\u6001\u9009\u8def\u534f\u8bae:<\/p>\n<ul>\n<li>RIP\uff1a\u9009\u8def\u4fe1\u606f\u534f\u8bae<\/li>\n<li>OSPF\uff1a\u5f00\u653e\u6700\u77ed\u8def\u4f18\u5148<\/li>\n<li>IGP-EGP-BGP\uff1a\u8fb9\u754c\u7f51\u5173\u534f\u8bae<\/li>\n<li>CIDR\uff1a\u65e0\u7c7b\u578b\u57df\u95f4\u9009\u8def<\/li>\n<\/ul>\n<hr>\n<h2 id=\"ip-address\">IP address<\/h2>\n<p>A: 0 + 7 * network number + 24 * host number, 0.0.0.0 - 127.255.255.255\nB: 10 + 14 * network number + 16 * host number; 128.0.0.0 - 191.255.255.255\nC: 110 + 21 * network number + 8 * host number; 192.0.0.0 - 223.255.255.255\nD: 1110 + 28 * multicast number; 224.0.0.0 - 239.255.255.255\nE: 11110 + 27 * reserved; 240.0.0.0 - 247.255.255.255<\/p>\n<hr>\n<h2 id=\"file\">File<\/h2>\n<p>File\u534f\u8bae\u662f\u672c\u5730\u6587\u4ef6\u534f\u8bae<\/p>\n<pre><code>file:\/\/\/C:\/\n<\/code><\/pre>\n<hr>\n<h2 id=\"\u8fdc\u7a0b\u684c\u9762\u534f\u8bae\">\u8fdc\u7a0b\u684c\u9762\u534f\u8bae<\/h2>\n<p>RDP: remote desktop protocol\uff0c windows\u7cfb\u7edf\u4e4b\u95f4\u7684\u8fdc\u7a0b\u684c\u9762\u534f\u8bae\u3002<\/p>\n<p>RFB(VNC): remote frame buffer, \u8de8\u5e73\u53f0\u7684\u8fdc\u7a0b\u684c\u9762\u534f\u8bae\uff0ccs\u67b6\u6784\u3002<\/p>\n<p>VNC: \u8de8\u5e73\u53f0\u7684RFB\uff08VNC\uff09\u5de5\u5177\u6709realvnc, tightvnc, tigervnc.<\/p>\n<p>remmina\uff1a\u57fa\u4e8egtk\uff0c\u652f\u6301RFB(VNC), RDP, SSH\/SFTP\u534f\u8bae\u3002<\/p>\n<p>krdc\uff1a\u57fa\u4e8ekde\uff0c\u652f\u6301RFB(VNC), RDP\u534f\u8bae\u3002<\/p>\n<p>mRemoteNG: RDP, VNC, SSH, Telnet, Http, Rlogin, RAW, ICA<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/mRemoteNG\/mRemoteNG\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/mRemoteNG\/mRemoteNG<\/a><\/p>\n<p>FreeDRP: DRP<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/FreeRDP\/FreeRDP\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/FreeRDP\/FreeRDP<\/a><\/p>\n<hr>\n<h2 id=\"url\">URL<\/h2>\n<p>url\u4e2d\u7684\u4fdd\u7559\u81ea\u5b57\u7b26\u9700\u8981\u7f16\u7801\u3002<\/p>\n<p>The percent-encoded values for the special characters are as follows:<\/p>\n<pre><code># \u2192 %23\n? \u2192 %3F\n&amp; \u2192 %26\n<\/code><\/pre>\n<p>These encodings are used in URLs to ensure that these characters are treated as literal values rather than special symbols.<\/p>"},{"title":"Samba","link":"https:\/\/canuxcheng.com\/post\/samba\/","pubDate":"Sun, 03 Apr 2016 14:46:19 +0000","guid":"https:\/\/canuxcheng.com\/post\/samba\/","description":"<h1 id=\"smbcifs\">SMB\/CIFS<\/h1>\n<p>SMB\/CIFS\u5360\u7528TCP\u548cUDP\u7684139\u548c445\u7aef\u53e3\u3002<\/p>\n<p>SMB: server message block.<\/p>\n<p>CIFS: common internet file system, \u662fSMB\u7684\u5347\u7ea7\u7248\u672c\u3002<\/p>\n<h1 id=\"samba\">Samba<\/h1>\n<p>Samba: Linux\/Unix\u4e0a\u7684SBM\/CIFS,\u7528\u4e8e\u8de8\u5e73\u53f0\u7684\u5171\u4eab\u3002<\/p>\n<p>\u5b89\u88c5:<\/p>\n<pre><code>$ sudo apt-get insall samba\n<\/code><\/pre>\n<p>\u914d\u7f6e\uff1a<\/p>\n<pre><code>$ vim \/etc\/samba\/smb.conf\n[shared]\ncomment = share this folder\npath = \/home\/canux\/Share\npublic = yes\nguest ok = yes\nbrowsable = yes\nwritable = no\nread only = yes\n<\/code><\/pre>\n<p>\u91cd\u542f\uff1a<\/p>\n<pre><code>$ sudo service smbd restart\n<\/code><\/pre>\n<p>windows\u8bbf\u95ee\uff1a<\/p>\n<pre><code>\\\\ip\\folder\n<\/code><\/pre>\n<p>linux\u8bbf\u95ee\uff1a<\/p>\n<pre><code>connect to server -&gt; smb:\/\/ip\/folder\n<\/code><\/pre>"},{"title":"Postgresql","link":"https:\/\/canuxcheng.com\/post\/postgre\/","pubDate":"Sun, 03 Apr 2016 14:46:14 +0000","guid":"https:\/\/canuxcheng.com\/post\/postgre\/","description":"<h1 id=\"postgresql\">PostgreSQL<\/h1>\n<p>\u5b89\u88c5postgresql\uff1a<\/p>\n<pre><code>$ sudo apt-get install postgresql\n<\/code><\/pre>\n<p>\u5b89\u88c5\u7b2c\u4e09\u65b9\u5e93\uff1a<\/p>\n<pre><code>$ sudo apt-get install postgresql-contrib-9.3 libpg-dev postgresql-server-dev-9.3\n<\/code><\/pre>\n<p>GUI\u5de5\u5177\uff1a pgAdminIII<\/p>\n<p>CLI\u5de5\u5177\uff1a psql<\/p>\n<p>postgresql\u7684\u7aef\u53e3\u662f5432\uff0e<\/p>\n<h1 id=\"postgresql\u547d\u4ee4\">postgresql\u547d\u4ee4<\/h1>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\u9ed8\u8ba4\u7684admin\u5c31\u662fpostgres, postgres\u91cc\u6709\u9ed8\u8ba4\u6570\u636e\u5e93postgres.<\/p>\n<pre><code>$passwd postgres # \u4fee\u6539\u9ed8\u8ba4\u7ba1\u7406\u5458\u7528\u6237postgres\u7684\u5bc6\u7801\n$su - postgres # \u5207\u6362\u5230\u9ed8\u8ba4\u7684postgres\u7528\u6237\n$ psql [OPTION]... [DBNAME [USERNAME]]\n$createuser &lt;username&gt; -P # \u5728\u547d\u4ee4\u884c\u6dfb\u52a0\u7528\u6237\n$dropuser &lt;username&gt; # \u5728\u547d\u4ee4\u884c\u5220\u9664\u7528\u6237\n$createdb &lt;database&gt; -O &lt;username&gt; # \u5728\u547d\u4ee4\u884c\u6dfb\u52a0\u6570\u636e\u5e93\n$dropdb &lt;database&gt; # \u5728\u547d\u4ee4\u884c\u5220\u9664\u6570\u636e\u5e93\n# \u4ea4\u4e92\u5f0f:\n$ psql -U [username] [database]\n# \u975e\u4ea4\u4e92\u5f0f\uff1a\n$ PGPASSWORD='password';psql -h &lt;host&gt; -p &lt;port&gt; -U &lt;username&gt; -d [database] -c &quot;[psql command]&quot;\n<\/code><\/pre>\n<p>\u5bfc\u51fa\u6570\u636e\uff1a<\/p>\n<pre><code>$ pg_dump dbname &gt; out.sql\n<\/code><\/pre>\n<p>pgcli:<\/p>\n<p>This is a postgres client that does auto-completion and syntax highlighting.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/dbcli\/pgcli\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/dbcli\/pgcli<\/a><\/p>\n<pre><code>$ pip install -U pgcli\n<\/code><\/pre>\n<h1 id=\"cli\">CLI<\/h1>\n<p>\u5148\u7528psql\u8fdb\u5165postgre\u7684\u547d\u4ee4\u884c.<\/p>\n<pre><code>help # \u67e5\u770b\u6240\u6709\u4fe1\u606f\n\\? # \u67e5\u770bpsql\u547d\u4ee4\n\\h # \u67e5\u770bsql\u547d\u4ee4\n\\g # \u6267\u884csql\u8bed\u53e5\n\\q # \u9000\u51fapsql\n\\du # \u67e5\u770b\u6240\u6709\u7528\u6237\u4fe1\u606f\n\\l # \u67e5\u8be2\u5f53\u524d\u7528\u6237\u7684\u6240\u6709\u6570\u636e\u5e93\n\\c &lt;database&gt; # \u5207\u6362\u6570\u636e\u5e93\n\\c &lt;database&gt; &lt;username&gt; # \u767b\u9646\u7528\u6237\u7684\u6570\u636e\u5e93\n\\dt \u7b49\u6548\u4e8eshow tables;\n\\d # \u67e5\u770b\u8868\u5173\u7cfb\n\\d &lt;table&gt; # \u67e5\u8be2\u8868\u7ed3\u6784\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u6570\u636e\u7c7b\u578b\">\u6570\u636e\u7c7b\u578b<\/h1>\n<h1 id=\"\u51fd\u6570\">\u51fd\u6570<\/h1>\n<h1 id=\"sql\">SQL<\/h1>\n<pre><code>ALTER USER\/ROLE &lt;username&gt; WITH PASSWORD &lt;password&gt;; #\u66f4\u6539\u7528\u6237\u5bc6\u7801\nSELECT username\/* FROM pg_user; # \u67e5\u770b\u6240\u6709\u7528\u6237\nSELECT username\/* FROM pg_shadow; # \u67e5\u770b\u6240\u6709\u7528\u6237\u5bc6\u7801\nCREATE GROUP &lt;groupname&gt;; # \u6dfb\u52a0\u7528\u6237\u7ec4\nALTER GROUP &lt;groupname&gt; ADD USER &lt;username&gt;,&lt;username1&gt;,...; # \u6dfb\u52a0\u7528\u6237\u5230\u7ec4\nALTER GROUP &lt;groupname&gt; DROP USER &lt;username&gt;,&lt;username1&gt;,...; # \u4ece\u7ec4\u5220\u9664\u7528\u6237\nCREATE ROLE &lt;username&gt; PASSWORD &lt;password&gt;; # \u521b\u5efa\u7528\u6237\u548c\u5bc6\u7801\nCREATE ROLE &lt;username&gt; LOGIN;\nCREATE ROLE &lt;username&gt; SUPERUSER;\nCREATE ROLE &lt;username&gt; CREATEDB;\nCREATE ROLE &lt;username&gt; CREATEROLE;\nCREATE ROLE &lt;username&gt; REPLICATION;\nDROP ROLE &lt;username&gt;; # \u5220\u9664role\nSELECT datname\/* FROM pg_database; # \u67e5\u8be2\u5f53\u524d\u7528\u6237\u7684\u6240\u6709\u6570\u636e\u5e93\nCREATE DATABASE &lt;database&gt; OWNER=&lt;username&gt;; # \u521b\u5efa\u6570\u636e\u5e93\nDROP DATABASE &lt;database&gt;; # \u5220\u9664\u6570\u636e\u5e93\nSELECT tablename\/* FROM pg_tables; # \u67e5\u770b\u6240\u6709\u8868\nCREATE TABLE tablename(\n&lt;type&gt; &lt;name&gt;,\n...\n); # \u521b\u5efa\u8868\nDROP TABLE &lt;table&gt;; # \u5220\u9664\u8868\nSELECT version();\nSELECT current_date;\nSELECT current_time;\n<\/code><\/pre>\n<hr>"},{"title":"WMI","link":"https:\/\/canuxcheng.com\/post\/win_wmi\/","pubDate":"Sun, 03 Apr 2016 14:15:47 +0000","guid":"https:\/\/canuxcheng.com\/post\/win_wmi\/","description":"<h1 id=\"wmicim\">WMI\/CIM<\/h1>\n<p>WMI: windows management instrumentation.<\/p>\n<p><a class=\"link\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/aa394582%28v=vs.85%29.aspx\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/msdn.microsoft.com\/en-us\/library\/aa394582(v=vs.85).aspx<\/a><\/p>\n<p>CIM: common information model.<\/p>\n<p><a class=\"link\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/aa389234%28v=vs.85%29.aspx\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/msdn.microsoft.com\/en-us\/library\/aa389234(v=vs.85).aspx<\/a><\/p>\n<p>DCOM: distributed COM.<\/p>\n<p>wmi\u901a\u8fc7DCOM\u8fdc\u7a0b\u8fde\u63a5\uff0c\u4f46\u662fDCOM\u4e0d\u80fd\u7ed5\u8fc7\u9632\u706b\u5899\u3002<\/p>\n<p>\u547d\u540d\u7a7a\u95f4:<\/p>\n<pre><code>root\\cimv2\nroot\\microsoftdns\nroot\\securitycenter\n<\/code><\/pre>\n<p>WMI\u5de5\u5177\uff1a<\/p>\n<ol>\n<li>windows\u81ea\u5e26wmi\u6d4b\u8bd5\u5de5\u5177wbemtest.<\/li>\n<li>WMI Explorer\u7528\u4e8e\u67e5\u627ewmi\u548ccim\u7684Class\u548cProperties.<\/li>\n<\/ol>\n<p><a class=\"link\" href=\"http:\/\/www.ks-soft.net\/hostmon.eng\/wmi\/index.htm#SysReq\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.ks-soft.net\/hostmon.eng\/wmi\/index.htm#SysReq<\/a><\/p>\n<p>windows\u600e\u6837\u8bbe\u7f6ewmi\uff1a<\/p>\n<p>135 (Microsoft RPC), 137-139 (NetBIOS) and 445 (Microsoft DS). These are TCP ports.<\/p>\n<p>\u8bbe\u7f6e\u7684\u7528\u6237\u9700\u8981\u662f\u7ba1\u7406\u5458\u7ec4\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/technet.microsoft.com\/en-us\/library\/cc771551%28v=ws.11%29.aspx\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/technet.microsoft.com\/en-us\/library\/cc771551(v=ws.11).aspx<\/a><\/p>\n<p>\u7ed9wmi\u8bbe\u7f6efix port(server in DMZ)\uff1a<\/p>\n<p>\u4f7f\u7528\u8fc7\u7a0b\u4e2d\u4e0d\u9700\u8981\u6307\u5b9a\u7aef\u53e3\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/msdn.microsoft.com\/zh-cn\/library\/bb219447%28v=vs.85%29.aspx\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/msdn.microsoft.com\/zh-cn\/library\/bb219447(v=vs.85).aspx<\/a><\/p>\n<h1 id=\"wmic\">wmic<\/h1>\n<p>wmic\u662fwmi\u7684\u5ba2\u6237\u7aef\u547d\u4ee4\u3002<\/p>\n<p>windows\u7684wmic\uff1a<\/p>\n<pre><code>&gt;wmic # \u8fdb\u5165wmi\u7684\u4ea4\u4e92\u6a21\u5f0f\n&gt;wmic -? # \u67e5\u770b\u5e2e\u52a9\n&gt;wmic \/? # \u67e5\u770b\u5e2e\u52a9\n&gt;wmic ... # \u975e\u4ea4\u4e92\u6a21\u5f0f\u8fd0\u884c\u547d\u4ee4\n&gt;wmic process call create shutdown.exe # \u672c\u5730\u5173\u673a\n<\/code><\/pre>\n<p>linux\u7684wmic\uff1a<\/p>\n<p>Linux\u9700\u8981\u81ea\u5df1\u521b\u5efawmic\u547d\u4ee4\uff0c\u53ef\u4ee5\u901a\u8fc7samba\u83b7\u53d6\uff0c\u4e5f\u53ef\u4ee5\u5b89\u88c5openvas\u7684\u5b89\u88c5\u5305\u3002<\/p>\n<pre><code>$man wmic\n$wmic -U [domain\/]adminuser%password \/\/host &quot;select * from Win32_ComputerSystem&quot;\n<\/code><\/pre>\n<p><a class=\"link\" href=\"https:\/\/mikepalmer.net\/debianubuntu-wmi-client-package-with-openvas-libwmiclient1-patches\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/mikepalmer.net\/debianubuntu-wmi-client-package-with-openvas-libwmiclient1-patches\/<\/a><\/p>\n<h1 id=\"wmi\u7684class\">WMI\u7684Class<\/h1>\n<p><a class=\"link\" href=\"https:\/\/msdn.microsoft.com\/zh-cn\/library\/aa394554%28v=vs.85%29.aspx\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/msdn.microsoft.com\/zh-cn\/library\/aa394554(v=vs.85).aspx<\/a><\/p>\n<ol>\n<li>\n<p>wmi system class<\/p>\n<p><a class=\"link\" href=\"https:\/\/msdn.microsoft.com\/zh-cn\/library\/aa394583%28v=vs.85%29.aspx\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/msdn.microsoft.com\/zh-cn\/library\/aa394583(v=vs.85).aspx<\/a><\/p>\n<pre><code> __Win32Provider\n...\n<\/code><\/pre>\n<\/li>\n<li>\n<p>MSFT class<\/p>\n<p>policy provider classes<\/p>\n<pre><code> MSFT_Providers\nMSFT_Rule\nMSFT_SomFilter\n<\/code><\/pre>\n<p>WMI Troubleshooting classes<\/p>\n<pre><code> MSFT_WmiProvider_Counters\nMSTF_WmiSelfEvent\n<\/code><\/pre>\n<\/li>\n<li>\n<p>CIM class<\/p>\n<p><a class=\"link\" href=\"https:\/\/msdn.microsoft.com\/zh-cn\/library\/aa386179%28v=vs.85%29.aspx\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/msdn.microsoft.com\/zh-cn\/library\/aa386179(v=vs.85).aspx<\/a><\/p>\n<pre><code> CIM_Action\n...\n<\/code><\/pre>\n<\/li>\n<li>\n<p>Standard Consumer class<\/p>\n<pre><code> ActiveScriptEventConsumer\nCommandLineEventConsumer\nLogFileEventConsumer\nNTEventLogEventConsumer\nScriptingStandardConsumerSetting\nSMTPEventConsumer\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<h1 id=\"wmi\u7684provider\">WMI\u7684Provider<\/h1>\n<p><a class=\"link\" href=\"https:\/\/msdn.microsoft.com\/zh-cn\/library\/aa394570%28v=vs.85%29.aspx\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/msdn.microsoft.com\/zh-cn\/library\/aa394570(v=vs.85).aspx<\/a><\/p>\n<ol>\n<li>\n<p>Win32 Provider<\/p>\n<p>Computer System Hardware Classes<\/p>\n<p><a class=\"link\" href=\"https:\/\/msdn.microsoft.com\/zh-cn\/library\/aa389273%28v=vs.85%29.aspx\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/msdn.microsoft.com\/zh-cn\/library\/aa389273(v=vs.85).aspx<\/a><\/p>\n<pre><code> Win32_Fan\n...\n<\/code><\/pre>\n<p>Operating System Classes<\/p>\n<p><a class=\"link\" href=\"https:\/\/msdn.microsoft.com\/zh-cn\/library\/dn792258%28v=vs.85%29.aspx\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/msdn.microsoft.com\/zh-cn\/library\/dn792258(v=vs.85).aspx<\/a><\/p>\n<pre><code> Win32_ClassicCOMApplicationClasses\n...\n<\/code><\/pre>\n<p>Performance Counter Classes<\/p>\n<p><a class=\"link\" href=\"https:\/\/msdn.microsoft.com\/zh-cn\/library\/aa392738%28v=vs.85%29.aspx\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/msdn.microsoft.com\/zh-cn\/library\/aa392738(v=vs.85).aspx<\/a><\/p>\n<pre><code> Win32_Perf\nWin32_PerfFormattedData\nWin32_PerfRawData\n<\/code><\/pre>\n<p>WMI Service Management Classes<\/p>\n<p><a class=\"link\" href=\"https:\/\/msdn.microsoft.com\/zh-cn\/library\/dn792273%28v=vs.85%29.aspx\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/msdn.microsoft.com\/zh-cn\/library\/dn792273(v=vs.85).aspx<\/a><\/p>\n<pre><code> Win32_MethodParameterClass\nWin32_WMISetting\nWim32_WMIElementSetting\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<h1 id=\"wql\">wql<\/h1>\n<p><a class=\"link\" href=\"https:\/\/msdn.microsoft.com\/zh-cn\/library\/aa394606%28v=vs.85%29.aspx\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/msdn.microsoft.com\/zh-cn\/library\/aa394606(v=vs.85).aspx<\/a><\/p>\n<p>wql\u5173\u952e\u5b57\uff1a<\/p>\n<pre><code>SELECT, FROM, WHERE, AND, OR, NOT, NULL, IS, TRUE, FALSE, WITHIN, LIKE, HAVING\nREFERENCES OF, KEYSONLY, ISA, ASSOCIATORS OF, __CLASS, GROUP Clause\n<\/code><\/pre>\n<p>\u5e38\u7528WQL\uff1a<\/p>\n<pre><code>select * from meta_class where __class like '%win32%' # \u67e5\u8be2wmi\u7684\u7c7b\nselect * from meta_class where __class like '%cim%' # \u67e5\u8be2cim\u7684\u7c7b\nselect * from cim_datafile where drive=&quot;c:&quot; and path=&quot;\\\\path\\\\&quot; and filename like &quot;%%&quot; and extension like '%%'\nselect * from cim_directory where drive=&quot;c:&quot; and path=&quot;\\\\path\\\\&quot;\nselect * from cim_logicaldisk\nselect * from win32_operationsystem\nselect * from win32_service\nselect * from win32_process\n<\/code><\/pre>\n<hr>"},{"title":"FileSystem","link":"https:\/\/canuxcheng.com\/post\/win_filesystem\/","pubDate":"Sun, 03 Apr 2016 14:15:40 +0000","guid":"https:\/\/canuxcheng.com\/post\/win_filesystem\/","description":{}},{"title":"Monitoring","link":"https:\/\/canuxcheng.com\/post\/win_monitoring\/","pubDate":"Sun, 03 Apr 2016 14:15:40 +0000","guid":"https:\/\/canuxcheng.com\/post\/win_monitoring\/","description":"<h1 id=\"windows\u7684services\u548cprocess\">windows\u7684services\u548cprocess<\/h1>\n<p>services\u662fwindows\u7684\u670d\u52a1\uff0c\u6709Name(Display Name)\uff0cService Name\uff0cDescription\u7b49\u5c5e\u6027\u3002<\/p>\n<p>process\u662f\u4ee5.exe\u4e3a\u540e\u7f00\u7684application\uff0c\u6709Name(product name)\u3001original filename(Image Name)\u3001file description(description)\u7b49\u5c5e\u6027\u3002<\/p>"},{"title":"Windows","link":"https:\/\/canuxcheng.com\/post\/win\/","pubDate":"Sun, 03 Apr 2016 14:15:40 +0000","guid":"https:\/\/canuxcheng.com\/post\/win\/","description":"<h1 id=\"windows\u7684ide\">windows\u7684IDE<\/h1>\n<p>VS Enterprise: \u6536\u8d39\u4f01\u4e1a\u7248\nVS Professional: \u6536\u8d39\u4e2a\u4eba\u7248\nVS Community: \u514d\u8d39\u793e\u533a\u7248<\/p>\n<p>windows\u7684\u5f15\u5bfc\u7a0b\u5e8f\u662fntloader\u3002<\/p>\n<p>DOS\u548cNT\u662fwindows\u7cfb\u7edf\u7684\u5185\u6838\u3002<\/p>\n<p>BIOS\u548cMBR\u57fa\u672c\u8f93\u5165\u8f93\u51fa\u7cfb\u7edf\u548c\u4e3b\u5f15\u5bfc\u8bb0\u5f55\u3002<\/p>\n<p>UEFI\u548cGPT\u662f\u7edf\u4e00\u7684\u53ef\u6269\u5c55\u63a5\u53e3\u548cGUID\u5206\u533a\u8868\u3002<\/p>\n<p>FAT\u662fmsdos\u7684\u6587\u4ef6\u7cfb\u7edf<\/p>\n<p>NTFS\u662fmsnt\u7684\u6587\u4ef6\u7cfb\u7edf<\/p>\n<hr>\n<h1 id=\"ad\">AD<\/h1>\n<p>AD: Active Directory<\/p>\n<p>\u7ba1\u7406\u5de5\u5177\uff1aLDAPSoft AD Browser<\/p>"},{"title":"DevOps","link":"https:\/\/canuxcheng.com\/post\/python_devops\/","pubDate":"Sun, 03 Apr 2016 10:49:21 +0000","guid":"https:\/\/canuxcheng.com\/post\/python_devops\/","description":"<h1 id=\"python\">Python<\/h1>\n<p>python2\u7684\u6700\u540e\u4e00\u4e2a\u7248\u672c\u662fpython2.7, 2020\u5e74\u505c\u6b62\u66f4\u65b0.<\/p>\n<p>Windows\u5b89\u88c5\uff1a<\/p>\n<pre><code>Python2.7.9\u4e4b\u540e\u7684\u7248\u672c\u76f4\u63a5\u4e0b\u8f7dmsi\u5b89\u88c5\u5373\u53ef\uff0e\n\u9009\u62e9\u81ea\u52a8\u8bbe\u7f6ePATH\uff0c\u9ed8\u8ba4\u5b89\u88c5pip\u548csetuptools.\n\u53ef\u4ee5\u4f7f\u7528IDLE\u6216python\u547d\u4ee4\u884c\u6216cmd\u6267\u884cpython\u547d\u4ee4\n<\/code><\/pre>\n<p>Linux\u5b89\u88c5\uff1a<\/p>\n<pre><code>$sudo apt-get install python\n$sudo yum install python\n$sudo apt-get install python-dev\n$sudo apt-get install python3-dev\n$sudo yum install python-devel\n<\/code><\/pre>\n<p>\u6807\u51c6\u5e93\u7684\u8def\u5f84\uff1a<\/p>\n<pre><code>C:\\Python*\\Lib\n\/usr\/lib\/python*\/\n<\/code><\/pre>\n<p>python\u7684IDE\uff1a<\/p>\n<ol>\n<li>Windows: IDLE<\/li>\n<li>Linux: Vim<\/li>\n<li>Pycharm\/VS<\/li>\n<\/ol>\n<hr>\n<h1 id=\"python\u547d\u4ee4\">python\u547d\u4ee4<\/h1>\n<pre><code>$ python\/ipython # \u8fdb\u5165python\u89e3\u91ca\u5668\n&gt;&gt;&gt;exit()\/Ctrl+d # \u9000\u51fapython\u89e3\u91ca\u5668\n&gt;&gt;&gt;help() # \u8fdb\u5165help\u5de5\u5177\nhelp&gt;quit # \u9000\u51fahelp\u5de5\u5177\n$ pydoc --help # \u6587\u6863\u5de5\u5177\n# -c\u3000cmd, __name__ != '__main__'\n$ python -c 'import module\/package; expressions'\n# -m mod, __name__ == '__main__'\n$ python -m 'module\/package'\n<\/code><\/pre>\n<hr>\n<h1 id=\"python\u7684\u53ef\u7528\u63a5\u53e3\">python\u7684\u53ef\u7528\u63a5\u53e3<\/h1>\n<ol>\n<li>\n<p>python\u5185\u7f6e\u5e38\u91cf\uff0c\u51fd\u6570\uff0c\u7c7b\u548c\u5f02\u5e38\uff0e<\/p>\n<p>C\/C++\u5b9e\u73b0\u7684\uff0c\u4e0d\u9700\u8981\u5bfc\u5165\u5c31\u53ef\u4ee5\u4f7f\u7528\u7684\u3002<\/p>\n<\/li>\n<li>\n<p>python\u6807\u51c6\u5e93<\/p>\n<p>python\u5b9e\u73b0\u7684\uff0c\u9700\u8981\u5bfc\u5165\u624d\u80fd\u4f7f\u7528\u7684\u3002<\/p>\n<\/li>\n<li>\n<p>python\u5916\u90e8\u5e93<\/p>\n<p>\u9700\u8981\u5b89\u88c5\u548c\u5bfc\u5165\u624d\u80fd\u4f7f\u7528\u7684\u3002\u5916\u90e8\u5e93\u662f\u5bf9python\u4ee3\u7801\u7684\u8865\u5145\u3002<\/p>\n<\/li>\n<li>\n<p>python\u6846\u67b6<\/p>\n<p>\u9700\u8981\u5b89\u88c5\u548c\u5bfc\u5165\u624d\u80fd\u4f7f\u7528\u7684\u3002python\u4ee3\u7801\u662f\u5bf9\u5916\u90e8\u5e93\u7684\u8865\u5145\u3002<\/p>\n<\/li>\n<\/ol>\n<hr>\n<h1 id=\"python\u7684\u5176\u5b83\u89e3\u91ca\u5668\">python\u7684\u5176\u5b83\u89e3\u91ca\u5668<\/h1>\n<h2 id=\"cpython\">cpython<\/h2>\n<p>python\u7684\u9ed8\u8ba4\u89e3\u91ca\u5668\uff0c\u5b89\u88c5python\u5373\u53ef\u83b7\u5f97\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/python\/cpython\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/python\/cpython<\/a><\/p>\n<h2 id=\"stackless\">stackless<\/h2>\n<p>cpython\u7684\u589e\u5f3a\u7248\uff0c\u652f\u6301\u591a\u7ebf\u7a0b\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/bitbucket.org\/stackless-dev\/stackless\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/bitbucket.org\/stackless-dev\/stackless<\/a><\/p>\n<h2 id=\"pypy\">pypy<\/h2>\n<p>\u7528python\u5199\u7684python\u89e3\u91ca\u5668\u3002<\/p>\n<p>\u6bd4cpython\u66f4\u5feb\u7684python\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/bitbucket.org\/pypy\/pypy\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/bitbucket.org\/pypy\/pypy<\/a><\/p>\n<h2 id=\"jpython\">jpython<\/h2>\n<p>java\u5f00\u53d1\u7684\u53ef\u4ee5\u8fd0\u884c\u5728JVM\u5e73\u53f0\u7684python\u89e3\u91ca\u5668\u3002<\/p>\n<h2 id=\"ironpython\">ironpython<\/h2>\n<p>C#\u5f00\u53d1\u7684\u53ef\u4ee5\u8fd0\u884c\u5728.net\/mono\u5e73\u53f0\u7684python\u89e3\u91ca\u5668\u3002<\/p>\n<hr>\n<h1 id=\"python\u5f00\u53d1\u76f8\u5173\u7684\u5de5\u5177\">python\u5f00\u53d1\u76f8\u5173\u7684\u5de5\u5177<\/h1>\n<h2 id=\"ipython\">ipython<\/h2>\n<p>python\u5199\u7684\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/ipython\/ipython\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/ipython\/ipython<\/a><\/p>\n<pre><code>$pip install ipython\n<\/code><\/pre>\n<h2 id=\"pyenv\">pyenv<\/h2>\n<p>python\u7684\u7248\u672c\u7ba1\u7406\u5de5\u5177,\u3000\u7528\u4e8e\u7ba1\u7406\u591a\u4e2apyton\u7248\u672c.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/yyuu\/pyenv\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/yyuu\/pyenv<\/a><\/p>\n<hr>\n<h1 id=\"\u5b89\u88c5\u7b2c\u4e09\u65b9\u5e93\">\u5b89\u88c5\u7b2c\u4e09\u65b9\u5e93<\/h1>\n<p><a class=\"link\" href=\"https:\/\/pypi.python.org\/pypi\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/pypi.python.org\/pypi<\/a><\/p>\n<p>\u7b2c\u4e09\u65b9\u5e93\u8def\u5f84\uff1a<\/p>\n<pre><code>C:\\Python*\\Lib\\site-packages\n~\/.local\/lib\/python*\/site-packages\n\/usr\/local\/lib\/python*\/dist-packages\n\/usr\/local\/lib\/python*\/site-packages\n\/usr\/lib\/python*\/dist-packages\n\/usr\/lib\/python*\/site-packages\n<\/code><\/pre>\n<p>\u4e8c\u8fdb\u5236\u5b89\u88c5\uff1a<\/p>\n<pre><code>$sudo apt-get install python-&lt;packagename&gt;\n<\/code><\/pre>\n<p>\u6e90\u7801\u5b89\u88c5\u7b2c\u4e09\u65b9\u5e93\uff1a<\/p>\n<pre><code>$ cd package\n$ python setup.py install\n# \u5b89\u88c5\u5230\u3000~\/.local\/lib\/python*\/site-packages\n$ python setup.py install --user\n<\/code><\/pre>\n<p>easy_install(setuptools)\u5b89\u88c5\uff1a<\/p>\n<pre><code>&lt;https:\/\/github.com\/pypa\/setuptools&gt;\neasy_install\u5b89\u88c5egg\u5305,\u4e0d\u63a8\u8350\u4f7f\u7528\uff0e\nsetuptools\u5e26\u7684\u5de5\u5177,\u4ecepypi\u7684egg\u5f52\u6863\u683c\u5f0f\u4e2d\u5b89\u88c5\u3002\npython2.7.9, python3.4, virtualenv\u81ea\u5e26setuptools.\n\u7f3a\u70b9\u662f\u4e0d\u652f\u6301\u5378\u8f7d\u3002\n$sudo apt-get install python-setuptools\n$sudo yum install python-setuptools\n$ sudo apt-get install python3-setuptools\n$ pip install -U setuptools\n$sudo -E easy_install packagename[=version] # \u5b89\u88c5\n$sudo -E easy_install -U packagename[=version] # \u5347\u7ea7\n<\/code><\/pre>\n<p>pip\u5b89\u88c5\uff1a<\/p>\n<pre><code>&lt;https:\/\/github.com\/pypa\/pip&gt;\n\u76f4\u63a5\u4ecepypi\u5b89\u88c5wheel\u683c\u5f0f\u548csdist\u683c\u5f0f(\u4e5f\u5c31\u662ftarball)\u3002\n$sudo apt-get install python-pip\n$sudo apt-get install python-wheel\n$sudo yum install python-pip\n$sudo yum install python-wheel\n$ sudo apt-get install python3-pip\n$ sudo apt-get install python3-wheel\n$pip install -U pip\n$pip install -U wheel\n$pip install -U setuptools\n$ pip install packagename[==version] # \u5b89\u88c5\n$ pip install -U packagename[==version] # \u5347\u7ea7\n$ pip uninstall packagename # \u5378\u8f7d\n$ pip install XXX.whl # \u5b89\u88c5wheel\u5305\n$ pip3 install\/uninstall &lt;packagename&gt;\n<\/code><\/pre>\n<p>pip\u547d\u4ee4:<\/p>\n<pre><code>$pip list\n$pip search packagename\n$pip freeze &gt; requirements.txt\n$pip install -r requirements.txt\n$ pip install [options] &lt;requirement specifier&gt; [package-index-options]\n$ pip install --target &lt;dir&gt; # \u901a\u8fc7target\u6307\u5b9a\u5b89\u88c5\u7684\u5177\u4f53site-packages\u8def\u5f84,\u4e0d\u5305\u62ecscripts\/data\n$ pip install --prefix &lt;dir&gt; # \u901a\u8fc7prefix\u6307\u5b9a\u5b89\u88c5\u7684bin, lib\u7b49\u8def\u5f84\uff0c\u4f1a\u5b89\u88c5scripts\/data\u7b49\n$ pip install --root &lt;dir&gt; # \u4f1a\u81ea\u52a8\u521b\u5efa&lt;dir&gt;\/usr\/local\/bin,&lt;dir&gt;\/usr\/local\/lib\u6765\u5b89\u88c5\n$ pip install --user # \u5b89\u88c5\u5230\/home\/$USER\/.local\/lib\n# \u4e0b\u9762\u662f\u901a\u8fc7\u6e90\u7801\u5b89\u88c5\uff0c\u4e0d\u80fd\u901a\u8fc7whl\u7b49\u4e8c\u8fdb\u5236\u5b89\u88c5\n$ pip install --install-option=&quot;--&lt;options&gt;&quot; # \u901a\u8fc7\u6e90\u7801\u5b89\u88c5\uff0c\u4f20\u9012\u53c2\u6570\u7ed9python setup.py install\n$ pip install --global-option=...\n# \u4e00\u822c\u6307\u5b9a\u4e86\u5176\u5b83\u5b89\u88c5\u8def\u5f84\u90fd\u9700\u8981\u7528-I, \u56e0\u4e3a\u5982\u679c\u7cfb\u7edf\u8def\u5f84\u5df2\u7ecf\u5b89\u88c5\uff0c\u5c31\u4e0d\u4f1a\u518d\u5b89\u88c5\n$ pip install -I\/--ignore-installed # \u91cd\u65b0\u5b89\u88c5, \u914d\u5408--prefix\u4f7f\u7528.\n# General options:\n--log &lt;path&gt;\n--timeout &lt;sec&gt;\n--trusted-host &lt;hostname&gt;\n--cache-dir &lt;dir&gt;\n--no-cache-dir\n--disable-pip-version-check\n# Package index options\n-i, --index-url &lt;url&gt;\n--extra-index-url &lt;url&gt;\n--no-index\n-f, --find-links &lt;url&gt;\n--process-dependency-links\n# \u624b\u52a8\u4fee\u6539pip\u7684\u6e90\n$ sudo vim \/etc\/pip.conf\n[global]\ntimeout=120\nno-cache-dir = false\ntrusted-host =\u00a0pypi.douban.com\nindex-url =\u00a0http:\/\/pypi.douban.com\/simple\n# index-url =\u00a0https:\/\/&lt;user&gt;:&lt;password&gt;@ip:port\/simple\n[freeze]\ntimeout = 10\n[install]\nignore-installed = true\nno-dependencies = yes\nno-compile = no\n<\/code><\/pre>\n<p>uv:<\/p>\n<pre><code>uv python *\nuv init\nuv add\/remove\/sync\nuv build\/publish\nuv venv\nuv pip *\nuv pip install -e .\n<\/code><\/pre>\n<p>pipx:<\/p>\n<pre><code>pipx --help\n<\/code><\/pre>\n<hr>\n<h1 id=\"python\u4ee3\u7801\u68c0\u67e5\">python\u4ee3\u7801\u68c0\u67e5<\/h1>\n<h2 id=\"flake8\">flake8<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/PyCQA\/flake8\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/PyCQA\/flake8<\/a><\/p>\n<p>Include: pyflakes, pep8\/pycodestyle, McCabe<\/p>\n<h2 id=\"pylama\">pylama<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/klen\/pylama\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/klen\/pylama<\/a><\/p>\n<p>Include: pyflakes, pylint, pep8\/pycodestyle, pep257\/pydocstyle, mccabe, radon, ghslint(for js)<\/p>\n<h2 id=\"pep8pycodestyle\">pep8\/pycodestyle<\/h2>\n<p>Simple Python style checker in one Python file.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/PyCQA\/pycodestyle\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/PyCQA\/pycodestyle<\/a><\/p>\n<h2 id=\"pep257pydocstyle\">pep257\/pydocstyle<\/h2>\n<p>docstring style checker<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/PyCQA\/pydocstyle\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/PyCQA\/pydocstyle<\/a><\/p>\n<h2 id=\"jedi\">jedi<\/h2>\n<p>Awesome autocompletion and static analysis library for python.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/davidhalter\/jedi\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/davidhalter\/jedi<\/a><\/p>\n<h2 id=\"mccabe\">mccabe<\/h2>\n<p>McCabe complexity checker for Python<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/PyCQA\/mccabe\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/PyCQA\/mccabe<\/a><\/p>\n<h2 id=\"pyflakes\">pyflakes<\/h2>\n<p>A simple program which checks Python source files for errors.<\/p>\n<p>Faster than pylint.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/PyCQA\/pyflakes\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/PyCQA\/pyflakes<\/a><\/p>\n<h2 id=\"pylint\">pylint<\/h2>\n<p>A Python source code analyzer which looks for programming errors, helps enforcing a coding standard and sniffs for some code smells<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/PyCQA\/pylint\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/PyCQA\/pylint<\/a><\/p>\n<pre><code>$pylint --list-msgs\n$pylint --help-msg=C6409\n<\/code><\/pre>\n<h2 id=\"rope\">rope<\/h2>\n<p>A python refactoring library<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/python-rope\/rope\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/python-rope\/rope<\/a><\/p>\n<hr>\n<h1 id=\"python\u9879\u76ee\u7ed3\u6784\">python\u9879\u76ee\u7ed3\u6784<\/h1>\n<pre><code>.\n|-- README.rst\n|-- LICENSE\n|-- AUTHORS.rst\n|-- CONTRIBUTING.rst\n|-- project \u9879\u76ee\u6e90\u4ee3\u7801\u76ee\u5f55\n|-- __init__.py \u5305\u6587\u4ef6\n|-- &lt;module&gt;.py \/\/ \u6a21\u5757\u540d\u4e0d\u8981\u548c\u5df2\u77e5\u7684\u5305\u91cd\u540d\n...\n|-- docs \u7528\u6765\u5b58\u653e\u6587\u6863\n|-- conf.py\n|-- index.rst\n...\n|-- tests \u7528\u6765\u5b58\u653e\u6d4b\u8bd5\u76f8\u5173\u7684\u6587\u4ef6(\u4e0d\u80fd\u6709__init__.py)\n|-- examples \u7528\u6765\u5b58\u653e\u4f7f\u7528\u672c\u5305\u76f8\u5173\u7684\u4f8b\u5b50(\u4e0d\u80fd\u6709__init__.py)\n|-- bin \u7528\u6765\u5b58\u653e\u5c06\u88absetup.py\u5b89\u88c5\u7684\u4e8c\u8fdb\u5236\u811a\u672c\n|-- data \u7528\u6765\u5b58\u653e\u5176\u5b83\u7c7b\u578b\u6587\u4ef6\n|-- etc \u7528\u6765\u5b58\u653e\u914d\u7f6e\u6587\u4ef6\n|-- tools \u7528\u6765\u5b58\u653e\u4e0e\u5de5\u5177\u76f8\u5173shell\u811a\u672c\n|-- scripts \u7528\u6765\u5b58\u653e\u5b89\u88c5\u76f8\u5173\u7684\u811a\u672c\n|-- setup.py \u6807\u51c6\u5b89\u88c5\u811a\u672c\n|-- setup.cfg\n|-- MANIFEST.in\n|-- .gitignore\n|-- .gitattributes\n|-- requirements.txt \u4f9d\u8d56\u7684\u73af\u5883\n|-- Makefile\n|-- fabfile.py\n<\/code><\/pre>\n<hr>\n<h1 id=\"cicd\">CICD<\/h1>\n<h2 id=\"buildbot\">buildbot<\/h2>\n<p>Python-based continuous integration testing framework<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/buildbot\/buildbot\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/buildbot\/buildbot<\/a><\/p>\n<h2 id=\"pybuilder\">pybuilder<\/h2>\n<p>Continuous build tool for Python.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/pybuilder\/pybuilder\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/pybuilder\/pybuilder<\/a><\/p>\n<hr>\n<h1 id=\"pypi\">pypi<\/h1>\n<p>\u521b\u5efa\u79c1\u6709\u7684pypi\u670d\u52a1\u5668<\/p>\n<h2 id=\"pypiserver\">pypiserver<\/h2>"},{"title":"Git","link":"https:\/\/canuxcheng.com\/post\/devops_git\/","pubDate":"Sat, 02 Apr 2016 21:11:33 +0000","guid":"https:\/\/canuxcheng.com\/post\/devops_git\/","description":"<h1 id=\"git\">Git<\/h1>\n<p>GIT: \u5206\u5e03\u5f0f\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u3002<\/p>\n<p>SVN: subversion\u5e76\u53d1\u5f0f\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u3002<\/p>\n<p>Mercurial: hg\u5206\u5e03\u5f0f\u7248\u672c\u63a7\u5236\u3002<\/p>\n<p>\u548cgit\u76f8\u5173\u7684\u4ea7\u54c1\uff1a<\/p>\n<ol>\n<li>github<\/li>\n<li>bitbucket<\/li>\n<li>sourceForge<\/li>\n<li>gitlab<\/li>\n<\/ol>\n<p>Git\u5b89\u88c5\uff1a<\/p>\n<pre><code>$ sudo apt-get install git\n$ yum install git\n<\/code><\/pre>\n<h1 id=\"git-config-git\u914d\u7f6e\">git config (Git\u914d\u7f6e)<\/h1>\n<p><a class=\"link\" href=\"https:\/\/git-scm.com\/book\/zh\/v2\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/git-scm.com\/book\/zh\/v2<\/a><\/p>\n<p>git\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<ol>\n<li>\/etc\/gitconfig \u7cfb\u7edf\u7ea7\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u901a\u8fc7git config &ndash;system\u8bbe\u7f6e<\/li>\n<li>~\/.gitconfig \u7528\u6237\u7ea7\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u901a\u8fc7git config &ndash;global\u8bbe\u7f6e<\/li>\n<li>.git\/config \u4ed3\u5e93\u7ea7\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u901a\u8fc7git config &ndash;local\u8bbe\u7f6e<\/li>\n<\/ol>\n<p>git\u914d\u7f6e\uff1a<\/p>\n<p>\u4f7f\u7528git config &ndash;global\u547d\u4ee4\u914d\u7f6e,\u6216\u8005\u76f4\u63a5\u4fee\u6539~\/.gitconfig\u6587\u4ef6\u3002<\/p>\n<pre><code># \u67e5\u770b\u5e2e\u52a9\ngit help config\nman git-config\ngit config --help\ngit config -l\/--list # \u67e5\u770b\u6240\u6709\u914d\u7f6e\ngit config --system\ngit config --global\ngit config --local\ngit config --global user.name &quot;your_name&quot;\ngit config --global user.email &quot;your_email&quot;\ngit config --global core.editor vim\n<\/code><\/pre>\n<p>\u591a\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<p>\u5728~\/.gitconfig\u6dfb\u52a0include\u53ef\u4ee5\u8c03\u7528\u5176\u5b83\u914d\u7f6e\u6587\u4ef6<\/p>\n<pre><code>[include]\npath = ~\/myCode\/pydeveloper\/etc\/git\/gitcofig\n<\/code><\/pre>\n<hr>\n<h1 id=\"git-remote-git-\u534f\u8bae\">git remote (git \u534f\u8bae)<\/h1>\n<p><a class=\"link\" href=\"https:\/\/git-scm.com\/book\/zh\/v2\/%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E7%9A%84-Git-%E5%8D%8F%E8%AE%AE\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/git-scm.com\/book\/zh\/v2\/%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E7%9A%84-Git-%E5%8D%8F%E8%AE%AE<\/a><\/p>\n<p>git\u6709\u56db\u4e2a\u534f\u8bae\uff1a<\/p>\n<ol>\n<li>\n<p>\u672c\u5730\u534f\u8baefile<\/p>\n<pre><code> file:\/\/\/path\/to\/project.git\n<\/code><\/pre>\n<\/li>\n<li>\n<p>SSH\u534f\u8bae<\/p>\n<p>\u62f7\u8d1dssh\u7684\u516c\u94a5\u540e\u4e0d\u9700\u8981\u8f93\u5165\u7528\u6237\u540d\u548c\u5bc6\u7801<\/p>\n<pre><code> ssh:\/\/git@github.com\/&lt;username&gt;\/&lt;project&gt;.git\ngit@github.com:&lt;username&gt;\/&lt;project&gt;.git\n<\/code><\/pre>\n<\/li>\n<li>\n<p>http\u534f\u8bae<\/p>\n<p>\u9ed8\u8ba4\u9700\u8981\u624b\u52a8\u8f93\u5165\u8fdc\u7a0b\u4ed3\u5e93\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801<\/p>\n<pre><code> https:\/\/github.com\/&lt;username&gt;\/&lt;project&gt;.git\n# \u4e0d\u7528\u624b\u52a8\u8f93\u5165\u5bc6\u7801\nhttps:\/\/&lt;username&gt;:&lt;password&gt;@github.com\/&lt;username&gt;\/&lt;project&gt;.git\n<\/code><\/pre>\n<p>\u8bbe\u7f6ehttp\u4ee3\u7406\uff1a<\/p>\n<pre><code> git config --global http.proxy &quot;http:\/\/&lt;server&gt;:&lt;port&gt;&quot;\ngit config --global http.proxy &quot;https:\/\/&lt;username&gt;:&lt;password&gt;@&lt;proxy&gt;:&lt;port&gt;&quot;\ngit config --global https.proxy &quot;https:\/\/&lt;server&gt;:&lt;PORT&gt;&quot;\n# In gitconfig file\n[http]\nproxy = http:\/\/&lt;server&gt;:&lt;port&gt;\n<\/code><\/pre>\n<\/li>\n<li>\n<p>Git\u534f\u8bae<\/p>\n<pre><code> git:\/\/git@github.com\/&lt;username&gt;\/&lt;project&gt;.git\n<\/code><\/pre>\n<p>\u8bbe\u7f6egit\u4ee3\u7406\uff1a<\/p>\n<pre><code> git config --global core.gitproxy ...\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p>\u8bbe\u7f6egit\u534f\u8bae\uff1a<\/p>\n<p>\u5982\u679c\u516c\u53f8\u768422\u7aef\u53e3\u88ab\u5c01\uff0c\u4e0d\u80fdSSH\u5230\u5916\u7f51\uff0c\u7528set-url\u5c06\u534f\u8bae\u6539\u6210http\u5373\u53ef\u3002<\/p>\n<p>\u5982\u679c\u4f7f\u7528\u4ee3\u7406\uff0c\u914d\u7f6ehttp.proxy\u5373\u53ef\u3002<\/p>\n<pre><code># \u67e5\u770b\u5e2e\u52a9\ngit remote --help\ngit help remote\nman git-remote\ngit remote -v # \u67e5\u770b\u8fdc\u7a0b\u4ed3\u5e93\u7684\u8be6\u7ec6\u4fe1\u606f\ngit remote add [-t &lt;branch&gt;] [-m &lt;master&gt;] [-f] [--[no-]tags] [--mirror=&lt;fetch|push&gt;] &lt;name&gt; &lt;url&gt;\ngit remote add origin &lt;url&gt; # \u7ed9\u8fdc\u7a0b\u4ed3\u5e93origin\u6dfb\u52a0url, \u4e00\u4e2a\u4ed3\u5e93\u53ef\u4ee5\u6dfb\u52a0\u591a\u4e2aurl\u3002\ngit remote rename &lt;oldname&gt; &lt;newname&gt; # \u91cd\u547d\u540d\u8fdc\u7a0b\u4ed3\u5e93\ngit remote remove\/rm &lt;name&gt; # \u5220\u9664\u548c\u8fdc\u7a0b\u4ed3\u5e93\u76f8\u5173\u7684\u6240\u6709\u4fe1\u606f\ngit remote set-head\ngit remote set-branches\ngit remote [-v | --verbose] show [-n] &lt;name&gt;...\ngit remote -v show origin # \u67e5\u770b\u8fdc\u7a0b\u4ed3\u5e93origin\u8be6\u7ec6\u4fe1\u606f\ngit remote prune\ngit remote update\ngit remote set-url [--push] &lt;name&gt; &lt;newurl&gt; [&lt;oldurl&gt;]\ngit remote set-url origin &lt;newurl&gt; # \u4fee\u6539\u8fdc\u7a0b\u4ed3\u5e93origin\u7684url\ngit remote set-url --add [--push] &lt;name&gt; &lt;newurl&gt;\ngit remote set-url --delete [--push] &lt;name&gt; &lt;url&gt;\n<\/code><\/pre>\n<hr>\n<h1 id=\"projcetgitignore\">projcet\/.gitignore<\/h1>\n<p>\u5ffd\u7565\u6587\u4ef6<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/github\/gitignore\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/github\/gitignore<\/a><\/p>\n<h1 id=\"projectgitattributes\">project\/.gitattributes<\/h1>\n<p>github\u663e\u793a\u7f16\u7a0b\u8bed\u8a00<\/p>\n<pre><code>* linguist-language=Python\n<\/code><\/pre>\n<p><a class=\"link\" href=\"https:\/\/github.com\/github\/linguist\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/github\/linguist<\/a><\/p>\n<hr>\n<h1 id=\"git\u76f8\u5173\u9879\u76ee\">git\u76f8\u5173\u9879\u76ee<\/h1>\n<h2 id=\"gui\">GUI<\/h2>\n<p>Linux\uff1a<\/p>\n<p>git-gui gitk<\/p>\n<p><a class=\"link\" href=\"http:\/\/repo.or.cz\/w\/git-gui.git\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/repo.or.cz\/w\/git-gui.git\/<\/a><\/p>\n<pre><code>sudo apt-get install gitk\n<\/code><\/pre>\n<p>windows:<\/p>\n<p><a class=\"link\" href=\"https:\/\/git-scm.com\/downloads\/guis\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/git-scm.com\/downloads\/guis<\/a><\/p>\n<h2 id=\"git-for-windows\">git-for-windows<\/h2>\n<p>windows\u7684git<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/git-for-windows\/git\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/git-for-windows\/git<\/a><\/p>\n<h2 id=\"post-git\">post-git<\/h2>\n<p>powershell\u7684git<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/dahlbyk\/posh-git\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/dahlbyk\/posh-git<\/a><\/p>\n<h2 id=\"git-extras\">git-extras<\/h2>\n<p>GIT utilities &ndash; repo summary, repl, changelog population, author commit percentages and more<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/tj\/git-extras\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/tj\/git-extras<\/a><\/p>\n<pre><code>$sudo apt-get install git-extras\n<\/code><\/pre>\n<h2 id=\"git-sweep\">git-sweep<\/h2>\n<p>A command-line tool that helps you clean up Git branches that have been merged into master.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/arc90\/git-sweep\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/arc90\/git-sweep<\/a><\/p>\n<pre><code>$sudo -E pip install git-sweep\n$cd git-repo\n$git-sweep preview # \u67e5\u770b\u54ea\u4e9b\u8fdc\u7a0b\u7684branch\u5df2\u7ecfmerge\u5230master.\n$git-sweep cleanup # \u5220\u9664\u8fdc\u7a0b\u5df2\u7ecfmerge\u5230master\u7684branch.\n$git-sweep cleanup --skip integration, sandbox\n<\/code><\/pre>\n<h2 id=\"git-imerge\">git-imerge<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/mhagger\/git-imerge\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/mhagger\/git-imerge<\/a><\/p>\n<h2 id=\"git-standup\">git-standup<\/h2>\n<p>Recall what you did on the last working day. Psst! or be nosy and find what someone else in your team did ;<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/kamranahmedse\/git-standup\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/kamranahmedse\/git-standup<\/a><\/p>\n<pre><code>$npm install -g git-standup\n<\/code><\/pre>\n<h2 id=\"git-lfs\">git-lfs<\/h2>\n<p>git\u7684\u5927\u6587\u4ef6\u7ba1\u7406<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/git-lfs\/git-lfs\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/git-lfs\/git-lfs<\/a><\/p>\n<h2 id=\"gerrit\">Gerrit<\/h2>\n<p>Gerrit is a code review and project management tool for Git based projects.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/gerrit-review\/gerrit\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/gerrit-review\/gerrit<\/a><\/p>\n<hr>\n<h1 id=\"\u642d\u5efa\u79c1\u6709git\u670d\u52a1\u5668\">\u642d\u5efa\u79c1\u6709git\u670d\u52a1\u5668<\/h1>\n<pre><code>$sudo groupadd git\n$sudo adduser git -g git\n$ cd \/home\/git\n$ mkdir src\n$ git init --bare src\n$ sudo chown -R git:git src\n<\/code><\/pre>\n<h2 id=\"gitolite\">gitolite<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/sitaramc\/gitolite\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/sitaramc\/gitolite<\/a><\/p>\n<h2 id=\"gitosis\">gitosis<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/res0nat0r\/gitosis\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/res0nat0r\/gitosis<\/a><\/p>\n<hr>\n<h1 id=\"git\u547d\u4ee4\">Git\u547d\u4ee4<\/h1>\n<p>git\u7684\u7ed3\u6784\uff1a<\/p>\n<ol>\n<li>\n<p>working directory(\u5de5\u4f5c\u76ee\u5f55),\u901a\u8fc7git init\u521d\u59cb\u5316<\/p>\n<\/li>\n<li>\n<p>staging area(\u6682\u5b58\u533a),\u901a\u8fc7git add\u6dfb\u52a0index\u5230\u6682\u5b58\u533a<\/p>\n<\/li>\n<li>\n<p>repository(\u4ed3\u5e93),\u901a\u8fc7git commit\u63d0\u4ea4\u5230repository<\/p>\n<pre><code> git help &lt;verb&gt;\ngit &lt;verb&gt; --help\nman git-&lt;verb&gt;\ngit help -a\ngit help -g\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<h2 id=\"archive\">archive<\/h2>\n<p>download one file from git server(github\/gitlab\/gerrit)<\/p>\n<pre><code>git archive --remote=ssh:\/\/user@gerrit.domain.com:port\/group\/project.git HEAD:path\/to file | tar -x\n<\/code><\/pre>\n<h2 id=\"init\">init<\/h2>\n<p>Create an empty Git repository or reinitialize an existing one<\/p>\n<pre><code>git init # \u521b\u5efa\u4e00\u4e2a\u7a7arepository\n<\/code><\/pre>\n<h2 id=\"add\">add<\/h2>\n<p>Add file contents to the index<\/p>\n<pre><code>git add . # \u4e0d\u5305\u62ec\u5220\u9664\u7684\u6587\u4ef6\ngit add -u # \u4e0d\u5305\u62ec\u65b0\u5efa\u7684\u6587\u4ef6\ngit add -A # \u6dfb\u52a0working tree\u4e0b\u7684\u6240\u6709\u6587\u4ef6\u5230index\n<\/code><\/pre>\n<h2 id=\"commit\">commit<\/h2>\n<p>Record changes to the repository<\/p>\n<pre><code>git commit -m &quot;[1.0.0.0]init repository.&quot;\ngit commit --amend\n<\/code><\/pre>\n<h2 id=\"bisect\">bisect<\/h2>\n<p>Find by binary search the change that introduced a bug<\/p>\n<h2 id=\"branch\">branch<\/h2>\n<p>List, create, or delete branches<\/p>\n<pre><code>git branch [branch-name]\ngit branch -d [branch-name] # \u5220\u9664\u5df2\u7ecfmerge\u5230master\u7684\u5206\u652f\ngit branch -D [branch-name] # \u5f3a\u5236\u5220\u9664\u5206\u652f\ngit branch -m [old-name] [new-name] # \u91cd\u547d\u540d\ngit branch -M [old-name] [new-name] # \u5f3a\u5236\u91cd\u547d\u540d\ngit branch -vv # \u67e5\u770b\u4e0a\u6e38\ngit branch --unset-upstream [branch] # \u53d6\u6d88\u4e0a\u6e38\ngit branch -u &lt;origin\/branch&gt; [branch] # \u8bbe\u7f6e\u4e0a\u6e38\n<\/code><\/pre>\n<h2 id=\"blame\">blame<\/h2>\n<p>Show what revision and author last modified each line of a file<\/p>\n<pre><code>git blame filename # \u67e5\u770b\u6587\u4ef6\u7684\u5386\u53f2\u8bb0\u5f55\n<\/code><\/pre>\n<h2 id=\"checkout\">checkout<\/h2>\n<p>Checkout a branch or paths to the working tree<\/p>\n<pre><code>git checkout [branch-name]\ngit checkout -b [branch-name] [start-point] # \u521b\u5efa\u5e76\u5207\u6362\u5230\u5206\u652f\ngit checkout -B [branch-name] [start-point] # \u5f3a\u5236\u6267\u884c\ngit checkout -- file\/path # \u64a4\u9500\u5de5\u4f5c\u76ee\u5f55\u4e2d\u6587\u4ef6\u7684\u4fee\u6539\ngit checkout [branch-name] -- file\/path # \u83b7\u53d6\u8fdc\u7a0b\u4ed3\u5e93\u7684\u6587\u4ef6\u5230\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\ngit checkout -b &lt;b-n&gt; tags\/v1.0.0 # \u57fa\u4e8etag\u521b\u5efabranch.\n<\/code><\/pre>\n<h2 id=\"clone\">clone<\/h2>\n<p>Clone a repository into a new directory<\/p>\n<pre><code>git clone [url]\n<\/code><\/pre>\n<h2 id=\"diff\">diff<\/h2>\n<p>Show changes between commits, commit and working tree, etc<\/p>\n<pre><code>git diff # \u67e5\u770b\u5de5\u4f5c\u76ee\u5f55\u53d8\u5316\ngit diff --staged # \u67e5\u770b\u6682\u5b58\u533a\u53d8\u5316\n<\/code><\/pre>\n<h2 id=\"fetch\">fetch<\/h2>\n<p>Download objects and refs from another repository<\/p>\n<pre><code>git fetch\ngit fetch -p\n<\/code><\/pre>\n<h2 id=\"grep\">grep<\/h2>\n<p>Print lines matching a pattern reinitialize an existing one<\/p>\n<pre><code>git grep [&lt;pathspec&gt;...]\n<\/code><\/pre>\n<h2 id=\"log\">log<\/h2>\n<p>Show commit logs<\/p>\n<pre><code>git log # \u663e\u793acommit\u7684log\ngit log --pretty=format:'%h' -n 1 \/\/ \u67e5\u770bcommit id.\n<\/code><\/pre>\n<h2 id=\"merge\">merge<\/h2>\n<p>merge\u76845\u4e2d\u7b56\u7565:<\/p>\n<ul>\n<li>resolve<\/li>\n<li>recursive<\/li>\n<li>octopus<\/li>\n<li>ours<\/li>\n<li>subtree<\/li>\n<\/ul>\n<p>Join two or more development histories together<\/p>\n<pre><code>git merge [branch-name]\ngit merge --ff # fast-forward,\u9ed8\u8ba4\u76f4\u63a5\u4e24\u4e2a\u5206\u652f\u5408\u5e76\uff0c\u4e0d\u4f1a\u4ea7\u751f\u65b0\u7684commit,\u770b\u4e0d\u5230\u5f00\u53d1\u5206\u652f\u7684\u5206\u53c9\uff0e\ngit merge --ff-only\ngit merge --no-ff # no fast-forward,\u6bcf\u6b21\u5408\u5e76\u4f1a\u521b\u5efa\u65b0\u7684commit.\u53ef\u4ee5\u770b\u5230\u5f00\u53d1\u5206\u652f\u7684\u5206\u53c9\ngit merge --squash\n<\/code><\/pre>\n<h2 id=\"mv\">mv<\/h2>\n<p>Move or rename a file, a directory, or a symlink<\/p>\n<pre><code>git mv [old] [new] # \u91cd\u547d\u540d\u6682\u5b58\u533a\u6587\u4ef6\n<\/code><\/pre>\n<h2 id=\"pull\">pull<\/h2>\n<p>Fetch from and integrate with another repository or a local branch<\/p>\n<pre><code>git pull\n<\/code><\/pre>\n<h2 id=\"push\">push<\/h2>\n<p>Update remote refs along with associated objects<\/p>\n<pre><code>git config --global push.default simple\ngit push origin --delete &lt;branch&gt;\ngit push origin :&lt;branch&gt;\ngit push origin --tags -f # push\u6240\u6709tag\ngit push origin [tagname] # push\u5355\u4e2atag\ngit push origin --delete tag [tagname]\ngit push origin :refs\/tags\/[tagname]\n<\/code><\/pre>\n<h2 id=\"rebase\">rebase<\/h2>\n<p>Forward-port local commits to the updated upstream head<\/p>\n<pre><code>git rebase -i [commit] # \u4fee\u6539\u63d0\u4ea4\u7684\u4fe1\u606f\npick\nreword\nedit\nsquash\nfixup\nexec\ndrop\nlabel\nreset\nmerge\ngit rebase --continue\ngit rebase --abort\ngit rebase --skip\ngit rebase --edit-todo\n<\/code><\/pre>\n<h2 id=\"reset\">reset<\/h2>\n<p>Reset current HEAD to the specified state<\/p>\n<pre><code>\/\/ \u786c\u91cd\u7f6e, \u4e4b\u540e\u7684commit\u548c \u4fee\u6539\u7684\u6587\u4ef6\u90fd\u6ca1\u4e86\ngit reset --hard [commit] # \u5168\u90e8\u56de\u9000\n\/\/ \u8f6f\u91cd\u7f6e, \u4e4b\u540ecommit\u6ca1\u4e86\uff0c\u4fee\u6539\u7684\u6587\u4ef6\u8fd8\u5728\ngit reset --soft [commit]\ngit reset --mixed [commit]\ngit reset --merge [commit]\ngit reset --keep [commit]\n<\/code><\/pre>\n<h2 id=\"rm\">rm<\/h2>\n<p>Remove files from the working tree and from the index<\/p>\n<pre><code>git rm &lt;file&gt; # \u5220\u9664\u5de5\u4f5c\u76ee\u5f55\u548c\u6682\u5b58\u533a\u7684\u6587\u4ef6\ngit rm --cached &lt;file&gt; # \u4e0d\u5220\u9664\u5de5\u4f5c\u76ee\u5f55\u7684\u6587\u4ef6,\u3000\u53ea\u5220\u9664\u6682\u5b58\u533a.\ngit rm -r --cached &lt;file&gt;\n<\/code><\/pre>\n<h2 id=\"revert\">revert<\/h2>\n<p>Revert some existing commits<\/p>\n<pre><code>git revert [commit] # \u64a4\u9500\u4e00\u6b21merge\n<\/code><\/pre>\n<h2 id=\"reflog\">reflog<\/h2>\n<p>Manage reflog information<\/p>\n<pre><code>\/\/ \u67e5\u770b\u6240\u6709\u6267\u884c\u8fc7\u7684\u52a8\u4f5c\u7684\u65e5\u5fd7\ngit reflog show\ngit reflog expire\ngit reflog delete\n<\/code><\/pre>\n<h2 id=\"show\">show<\/h2>\n<p>Show various types of objects<\/p>\n<pre><code>git show\n<\/code><\/pre>\n<h2 id=\"status\">status<\/h2>\n<p>Show the working tree status tag Create, list, delete or verify a<\/p>\n<pre><code>git status\ngit status -s # \u663e\u793a\u72b6\u6001\u7684\u7b80\u4ecb\u4fe1\u606f, \u9ed8\u8ba4\u662f--long\n\/\/ \u67e5\u770bgitignore\u5ffd\u7565\u4e86\u54ea\u4e9b\u6587\u4ef6\u3002\ngit status --ignored\n<\/code><\/pre>\n<h2 id=\"stash\">stash<\/h2>\n<p>Stash the changes in a dirty working directory away<\/p>\n<pre><code>git stash # \u6682\u5b58\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\ngit stash list # \u67e5\u770b\u6682\u5b58\u5217\u8868\ngit stash show [stash]\ngit stash pop --index stash@{N} # \u6062\u590d\u6682\u5b58\u533aN\u548c\u5de5\u4f5c\u76ee\u5f55\ngit stash apply --index stash@{N} # \u540c\u4e0a\n<\/code><\/pre>\n<h2 id=\"tag\">tag<\/h2>\n<p>Create, list, delete or verify a tag object signed with GPG<\/p>\n<pre><code>git tag -l # \u67e5\u770b\u6240\u6709\u672c\u5730tag\ngit tag -d v1.0.0 # \u5220\u9664\u672c\u5730tag\ngit tag -a v1.0.0 -m &quot;release 1.0.0.&quot; -f\n<\/code><\/pre>\n<h2 id=\"submodule\">submodule<\/h2>\n<p>Initialize, update or inspect submodules<\/p>\n<p>\u4f1a\u5728\u9879\u76ee\u4ea7\u751f.gitmodules\u6587\u4ef6\uff0c\u800c\u4e14\u4e0d\u88ab.gitignore\u5ffd\u7565\uff0c\u6240\u4ee5\u4e0d\u8981\u5728URL\u6dfb\u52a0\u7528\u6237\u540d\u548c\u5bc6\u7801\uff0e<\/p>\n<p>\u6dfb\u52a0\u5b50\u6a21\u5757\uff1a<\/p>\n<pre><code>\/\/ push\u53ea\u4f1apush\u521b\u5efa\u7684\u5b50\u6a21\u5757\u7a7a\u76ee\u5f55\u548c.gitmodules\u6587\u4ef6.\ngit submodule add &lt;repository&gt; [&lt;path&gt;]\n<\/code><\/pre>\n<p>\u514b\u9686\u5b50\u6a21\u5757\uff1a<\/p>\n<pre><code>\/\/ git clone \u53ea\u4f1aclone\u7a7a\u76ee\u5f55\ngit submodule init\ngit submodule update\n\/\/ \u6216\u8005\ngit clone --recurse-submodules &lt;sub-URL&gt;\n\/\/ \u6216\u8005\ngit clone &lt;URL&gt;\ngit submodule update --init\n\/\/ \u6216\u8005\ngit submodule update --init --recursive\n<\/code><\/pre>\n<h2 id=\"mergetool\">mergetool<\/h2>\n<p>Run merge conflict resolution tools to resolve merge conflicts.<\/p>\n<pre><code>git mergetool --tool=meld\n<\/code><\/pre>\n<hr>\n<h1 id=\"best-prictise\">Best Prictise<\/h1>\n<p>merge\u8fdc\u7a0btag<\/p>\n<pre><code>git checkout -b influxdata-1.5.2 master\ngit pull https:\/\/github.com\/influxdata\/influxdb.git v1.5.2\n<\/code><\/pre>\n<p>gitignore\u5ffd\u7565\u6587\u4ef6\u548c\u76ee\u5f55<\/p>\n<pre><code>path\/to\/file\npath\/\n# \u5982\u679c\u5df2\u7ecfpush\uff1a\ngit rm -r --cached path\/to\/file\n<\/code><\/pre>"},{"title":"Vim","link":"https:\/\/canuxcheng.com\/post\/devops_vim\/","pubDate":"Sat, 02 Apr 2016 21:11:26 +0000","guid":"https:\/\/canuxcheng.com\/post\/devops_vim\/","description":"<h1 id=\"vim\">vim<\/h1>\n<p><a class=\"link\" href=\"http:\/\/www.vim.org\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.vim.org<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/vim\/vim\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/vim\/vim<\/a><\/p>\n<p>\u7c7b\u4f3c\u7f16\u8f91\u5668:<\/p>\n<ul>\n<li>emacs<\/li>\n<li>Atom(github\u7684\u5f00\u6e90\u8de8\u5e73\u53f0\u7f16\u8f91\u5668\uff0c\u652f\u6301\u63d2\u4ef6\u3002)<\/li>\n<li>VSCode(\u5fae\u8f6f\u7684\u5f00\u6e90\u8de8\u5e73\u53f0\u7684\u7f16\u8f91\u5668\uff0c\u652f\u6301\u63d2\u4ef6\u3002)<\/li>\n<\/ul>\n<h1 id=\"vim\u5b89\u88c5\u548c\u914d\u7f6e\">Vim\u5b89\u88c5\u548c\u914d\u7f6e<\/h1>\n<p>\u67e5\u770bvim\u7248\u672c\u548c\u7f16\u8bd1\u4fe1\u606f\uff1a<\/p>\n<pre><code>vim --version\n<\/code><\/pre>\n<p>\u5b89\u88c5vim\uff1a<\/p>\n<pre><code>$ sudo apt-get install vim\n$ yum install vim\n<\/code><\/pre>\n<p>\u6e90\u7801\u5b89\u88c5vim\uff1a<\/p>\n<pre><code>$ sudo apt-get build-dep vim\n$ cd vim\/src\n$ .\/configure \\\n--with-features=huge \\\n--with-compiledby=&quot;Canux&quot; \\\n--enable-multibyte \\\n--enable-gui=gtk2 \\\n--enable-gpm \\\n--prefix=\/usr \\\n--enable-cscope \\\n--enable-fontset \\\n--enable-xim \\\n--enable-fail-if-missing \\\n--enable-mzschemeinterp \\\n--enable-perlinterp \\\n--enable-luainterp \\\n--enable-tclinterp\\\n--enable-rubyinterp \\\n--enable-pythoninterp \\\n--with-python-config-dir=\/usr\/lib\/python2.7\/config-x86_64-linux-gnu \\\n--enable-python3interp \\\n--with-python3-config-dir=\/usr\/lib\/python3.4\/config-3.4m-x86_64-linux-gnu\n$ make VIMRUNTIMEDIR=\/usr\/share\/vim\/vim74\n$ sudo make install\n<\/code><\/pre>\n<hr>\n<h1 id=\"vim\u76f8\u5173\u9879\u76ee\">Vim\u76f8\u5173\u9879\u76ee<\/h1>\n<h2 id=\"neovim\">neovim<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/neovim\/neovim\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/neovim\/neovim<\/a><\/p>\n<p>vim\u7684\u5347\u7ea7\u7248\uff0c\u4fee\u590d\u4e86vim\u7684bug\uff0c\u540c\u65f6\u96c6\u6210\u4e86\u8bb8\u591a\u63d2\u4ef6\u3002<\/p>\n<h2 id=\"spacevim\">spacevim<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/SpaceVim\/SpaceVim\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/SpaceVim\/SpaceVim<\/a><\/p>\n<p>\u66f4\u9ad8\u6548\u7684vim.<\/p>\n<h2 id=\"sp13\">sp13<\/h2>\n<p>\u5206\u5e03\u5f0fvim\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/spf13\/spf13-vim\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/spf13\/spf13-vim<\/a><\/p>\n<h2 id=\"vim-galore\">vim-galore<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/mhinz\/vim-galore\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/mhinz\/vim-galore<\/a><\/p>\n<p>vim\u7684\u77e5\u8bc6\u5e93\uff0e<\/p>\n<h2 id=\"vimrc\">vimrc<\/h2>\n<p>vim\u7684\u7ec8\u6781\u914d\u7f6e\uff0e<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/amix\/vimrc\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/amix\/vimrc<\/a><\/p>\n<hr>\n<h1 id=\"vim\u5e38\u89c1\u7528\u6cd5\u548c\u7279\u6b8a\u7528\u6cd5\">vim\u5e38\u89c1\u7528\u6cd5\u548c\u7279\u6b8a\u7528\u6cd5<\/h1>\n<p>vim\u7684\u4e09\u79cd\u6a21\u5f0f\uff1a<\/p>\n<pre><code>v # \u89c6\u89c9\u6a21\u5f0f\ni # \u63d2\u5165\u6a21\u5f0f\nesc # \u666e\u901a\u6a21\u5f0f\n<\/code><\/pre>\n<p>\u5e38\u7528\u547d\u4ee4:<\/p>\n<pre><code>: # \u8fdb\u5165\u547d\u4ee4\u884c\n:help # \u67e5\u770b\u5e2e\u52a9\n:q\n:q!\n:qa\n:w\n:n1, n2 w\n:wq\n:x\n# \u5e38\u7528\u8bbe\u7f6e\n:set mouse=a # enable mouse\n:set list # \u67e5\u770btab\u952e\n:set nolist\n:set nu\n:set nonu\n:! [shell-command] # \u53ef\u4ee5\u8fd0\u884c\u5916\u90e8\u547d\u4ee4\n# \u66ff\u6362\n:s\/old\/new # \u66ff\u6362\u7b2c\u4e00\u4e2a\n:ns\/old\/new\/g # \u66ff\u6362\u884cn\n:n1,n2s\/old\/new\/g # \u66ff\u6362n1-n2\u4e4b\u95f4\u7684\u5168\u90e8\n:%s\/old\/new\/g # \u66ff\u6362\u6574\u4e2a\u6587\u4ef6\n:%s\/old\/new\/gc # \u66ff\u6362\u6574\u4e2a\u6587\u4ef6\uff0c\u5f39\u51fa\u63d0\u793a\n:%\/^\/inseart\/g # \u884c\u9996\u63d2\u5165\n:%\/$\/inseart\/g # \u884c\u5c3e\u63d2\u5165\n# \u5220\u9664\n:g\/pattern\/d # \u5220\u9664\u5339\u914d\u7684\u884c\n:n1,n2g\/pattern\/d # \u5220\u9664n1-n2\u4e2d\u5339\u914d\u7684\u884c\n:v\/pattern\/d # \u5220\u9664\u4e0d\u5339\u914d\u7684\u884c\n:n1,n2d # \u5220\u9664n1-n2\u884c\n:%s\/^\\s\\+\/\/g # \u5220\u9664\u884c\u9996\u7a7a\u683c\n:%s\/\\s\\+$\/\/g # \u5220\u9664\u884c\u5c3e\u7a7a\u683c\n:1,$d # \u5220\u9664\u6240\u6709\u884c\uff0c\u5305\u62ec\u884c\u53f7\n:%s\/^.*$\/\/g # \u6e05\u7a7a\u5185\u5bb9\uff0c\u4fdd\u7559\u884c\u53f7\n<\/code><\/pre>\n<p>\u5e38\u7528\u5feb\u6377\u952e\uff1a<\/p>\n<pre><code># \u5de6\u53f3\u8df3\u8f6c\u5feb\u6377\u952e\nn h # left\nn l # right\n0 # \u8df3\u8f6c\u5230\u4e00\u884c\u7684\u9996\u5b57\u6bcd\n^ # \u8df3\u8f6c\u5230\u4e00\u884c\u7684\u975e\u7a7a\u9996\u5b57\u6bcd\nn $ # \u8df3\u8f6c\u4e00\u884c\u7684\u7ed3\u5c3e\n# \u4e0a\u4e0b\u8df3\u8f6c\u5feb\u6377\u952e\nn k # up\nn j # down\nn G # \u8df3\u8f6c\u5230\u884c\u53f7n, \u9ed8\u8ba4\u6700\u540e\u4e00\u884c\nn gg # \u540c\u4e0a\uff0c\u9ed8\u8ba4\u7b2c\u4e00\u884c\n# \u6587\u672c\u79fb\u52a8(\u5411\u524d\u5c31\u662f\u5411\u53f3\uff0c\u5411\u540e\u5c31\u662f\u5411\u5de6)\nn w # \u5411\u524d\u79fb\u52a8n\u4e2a\u5355\u8bcd\nn W # \u5411\u524d\u79fb\u52a8n\u4e2a\u7a7a\u683c\u5206\u5272\u7684\u5355\u8bcd\nn e # \u8df3\u8f6c\u5230\u6700\u540e\u7b2cn\u4e2a\u5355\u8bcd\nn E # \u8df3\u8f6c\u5230\u4ee5\u7a7a\u683c\u5206\u5272\u7684\u6700\u540e\u5730n\u4e2a\u5355\u8bcd\nn b # \u5411\u540en\u4e2a\u5355\u8bcd\nn B # \u5411\u540en\u4e2a\u5355\u8bcd\uff0c\u4ee5\u7a7a\u683c\u5206\u5272\n# \u6a21\u5f0f\u5339\u914d\nN \/{pattern}[\/[offset]]&lt;CR&gt; # \u5411\u540e\u67e5\u627eN\u4e2a\u5339\u914d\nN ?{pattern}[?[offset]]&lt;CR&gt; # \u5411\u524d\u67e5\u627eN\u4e2a\u5339\u914d\nN n # \u5411\u540e\u67e5\u770b\nN N # \u5411\u524d\u67e5\u770b\n# \u5927\u5c0f\u5199\u8f6c\u6362\n~ # \u5355\u4e2a\u5b57\u7b26\u76f8\u4e92\u8f6c\u6362\nU # \u8f6c\u6362\u6210\u5927\u4e9b\nu # \u8f6c\u6362\u6210\u5c0f\u5199\ng~~ # \u8f6c\u6362\u5f53\u524d\u884c\u5927\u5c0f\u5199\n:%s\/.\/\\U&amp;\/g # \u5168\u6587\u6539\u6210\u5927\u4e9b\n<\/code><\/pre>\n<p>\u7279\u6b8a\u5b57\u7b26\u5904\u7406\uff1a<\/p>\n<pre><code># \u67e5\u770b\u7279\u6b8a\u5b57\u7b26\uff0c\u5b57\u7b26\u7f16\u7801\u548c\u4e8c\u5408\u5b57\u6bcd\n:digraphs\n:h digraph-table\n# \u76f4\u63a5\u4f7f\u7528\u5b57\u7b26\u7f16\u7801,\u63d2\u5165\u6a21\u5f0f\u4e0b\u8f93\u5165\n&lt;ctrl-v&gt; + &lt;dec&gt;\n# \u4f7f\u7528\u4e8c\u5408\u5b57\u6bcd\uff0c\u63d2\u5165\u6a21\u5f0f\u4e0b\u8f93\u5165\n&lt;ctrl-k&gt; + &lt;digraph&gt;\n<\/code><\/pre>\n<hr>\n<h1 id=\"vim-plugins-manager\">vim-plugins-manager<\/h1>\n<p>vim\u7684\u63d2\u4ef6\u7ba1\u7406\u5668<\/p>\n<h2 id=\"pathogen\">pathogen<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/tpope\/vim-pathogen\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/tpope\/vim-pathogen<\/a><\/p>\n<p>vim\u7684\u672c\u5730\u7ba1\u7406\u63d2\u4ef6\u3002<\/p>\n<h2 id=\"vundle\">vundle<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/VundleVim\/Vundle.vim\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/VundleVim\/Vundle.vim<\/a><\/p>\n<p>vim\u7684\u5728\u7ebf\u7ba1\u7406\u63d2\u4ef6\u3002<\/p>\n<h2 id=\"vim-plug\">vim-plug<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/junegunn\/vim-plug\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/junegunn\/vim-plug<\/a><\/p>\n<p>vundle\u7684\u8ff7\u4f60\u7248\u3002<\/p>\n<h2 id=\"dein\">dein<\/h2>\n<p>dein\u5df2\u7ecf\u53d6\u4ee3neobundle, \u53ef\u4ee5\u7528\u4e8evim\u548cneovim\u3002<\/p>\n<p>\u65e7\u7248\u672c\uff1a<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/Shougo\/neobundle.vim\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/Shougo\/neobundle.vim<\/a><\/p>\n<p>\u65b0\u7248\u672c\uff1a<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/Shougo\/dein.vim\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/Shougo\/dein.vim<\/a><\/p>\n<hr>\n<h1 id=\"vim-plugins\">vim-plugins<\/h1>\n<p>vim\u5e38\u7528\u7684\u63d2\u4ef6<\/p>\n<h2 id=\"ycm\">YCM<\/h2>\n<h2 id=\"syntastic\">syntastic<\/h2>\n<hr>\n<h1 id=\"\u5e38\u7528\u60c5\u666f\">\u5e38\u7528\u60c5\u666f<\/h1>\n<p>vim\u5185\u90e8\u4f7f\u7528sudo\u4fdd\u5b58:<\/p>\n<pre><code>:w !sudo tee %\n<\/code><\/pre>"},{"title":"Summary","link":"https:\/\/canuxcheng.com\/post\/c_summary\/","pubDate":"Sat, 02 Apr 2016 16:06:14 +0000","guid":"https:\/\/canuxcheng.com\/post\/c_summary\/","description":"<h1 id=\"c\u6807\u51c6\">C\u6807\u51c6<\/h1>\n<p>ISO C89(ANSI C89) -&gt; ISO C99 -&gt; ISO C11<\/p>\n<p>ANSI C \u548c ISO C\u662f\u5bf9\u901a\u7528C\u8bed\u8a00\u7684\u63a5\u53e3\u7684\u5b9a\u4e49\u3002<\/p>\n<p>\u7b26\u5408\u8fd9\u79cd\u6807\u51c6\u7684\u5b9e\u73b0\u4e3aC\u8bed\u8a00\u6807\u51c6\u5e93,\u4e5f\u53eblibc\u3002<\/p>\n<p>Unix\/Linux\u7684POSIX\u5305\u542blibc\u3002<\/p>\n<p>Linux\u7684glibc\u5305\u542blibc\u53ca\u5176\u6269\u5c55.<\/p>\n<p>Windows\u7684msvcrt\u5305\u542blibc\u53ca\u5176\u6269\u5c55.<\/p>\n<p>\u5176\u5b83\u548cC\u76f8\u5173\u7684\u6807\u51c6\uff1a<\/p>\n<p>BSD<\/p>\n<p>System V<\/p>\n<p>XPG<\/p>\n<p>SUS<\/p>\n<h1 id=\"glibc\">glibc<\/h1>\n<p>Linux\u7684\u6807\u51c6C\u5e93glibc<\/p>\n<p>\u9075\u5faaISO C11 \u548c POSIX.1-2008, \u8fd8\u5305\u62ec\u4e00\u4e9b\u5176\u5b83\u6807\u51c6\u3002<\/p>\n<p>\u5173\u4e8eISO C \u548c POSIX\u53c2\u8003\u53e6\u5916\u4e24\u7bc7\u535a\u6587\u3002<\/p>\n<h1 id=\"msvcrt\">msvcrt<\/h1>\n<p>windows\u7684\u6807\u51c6c\u5e93msvcrt.<\/p>\n<hr>\n<h1 id=\"c\u6ce8\u91ca\">C\u6ce8\u91ca<\/h1>\n<p>\u5355\u884c\u6ce8\u91ca\uff1a<\/p>\n<pre><code>\/\/ comment\n\/* comment *\/\n<\/code><\/pre>\n<p>\u591a\u884c\u6ce8\u91ca\uff1a<\/p>\n<pre><code>\/*\n* comment1\n* commenet2\n*\/\n<\/code><\/pre>\n<h1 id=\"\u6587\u6863\">\u6587\u6863<\/h1>\n<p>C\u7a0b\u5e8f\u53ef\u4ee5\u7528doxygen\u4ece\u7a0b\u5e8f\u4e2d\u63d0\u53d6\u6587\u6863\u3002<\/p>\n<p>\u6587\u6863\u6ce8\u91ca\uff1a<\/p>\n<pre><code>\/**\n* @file\n* @brief\n* @author\n* @date\n* @version\n* @copyright\n*\/\n<\/code><\/pre>\n<h1 id=\"\u7f16\u8bd1\u548c\u94fe\u63a5\">\u7f16\u8bd1\u548c\u94fe\u63a5<\/h1>\n<p>\u7f16\u8bd1\u53ea\u68c0\u67e5\u8bed\u6cd5\u9519\u8bef\u548c\u51fd\u6570\u4ee5\u53ca\u53d8\u91cf\u662f\u5426\u7533\u660e\uff0e\u5c06*.c\u6e90\u6587\u4ef6\u7f16\u8bd1\u6210*.o\u76ee\u6807\u6587\u4ef6\uff0e<\/p>\n<pre><code>gcc -g -Wall -I\/head\/file\/path -c -o helloworld.o helloworld.c\n<\/code><\/pre>\n<p>\u94fe\u63a5\u68c0\u67e5\u51fd\u6570\u548c\u53d8\u91cf\u7684\u5b9a\u4e49\uff0e\u5c06*.o\u76ee\u6807\u6587\u4ef6\u94fe\u63a5\u4e4b\u540e\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u6216\u8005\u6253\u5305\u6210\u5e93\u6587\u4ef6*.a\u6216*.so.<\/p>\n<pre><code># normal\ngcc -g -Wall -o helloworld helloworld.o\n# static library *.a\ngcc -g -Wall -o libstatic.a helloworld.o -L\/static\/lib\/path -lstatic\n# dynamic library *.o\ngcc -g -Wall -o libdynamic.so helloworld.o -L\/dynamic\/lib\/path -ldynamic -Wl, -rpath=\/dynamic\/lib\/path\n<\/code><\/pre>"},{"title":"Posix","link":"https:\/\/canuxcheng.com\/post\/c_posix\/","pubDate":"Sat, 02 Apr 2016 11:18:05 +0000","guid":"https:\/\/canuxcheng.com\/post\/c_posix\/","description":"<h1 id=\"posix\u6807\u51c6\">POSIX\u6807\u51c6<\/h1>\n<p>Portable Operating System Interface<\/p>\n<p>\u53ef\u79fb\u690d\u6027\u64cd\u4f5c\u7cfb\u7edf\u63a5\u53e3, POSIX\u517c\u5bb9ISO C\u3002<\/p>\n<p>\u6240\u6709Unix\u90fd\u9075\u5faa\uff0c\u51e0\u4e4e\u6240\u6709Linux\u90fd\u9075\u5faa\uff0cWindows\u90e8\u5206\u652f\u6301\u3002<\/p>\n<p>POSIX.1\/IEEE 1003.1-1990<\/p>\n<p>POSIX.2\/IEEE Std 1003.2-1992\/ISO IEC 9945-2:1993)<\/p>\n<p>POSIX.1.b\/IEEE Std 1003.1b-1993\/ISO IEC 9945-1:1996)<\/p>\n<p>POSIX.1.c\/IEEE Std 1003.1c-1995<\/p>\n<p>POSIX.1.d\/IEEE Std 1003.1c-1999<\/p>\n<p>POSIX.1.g\/IEEE Std 1003.1g-2000<\/p>\n<p>POSIX.1.j\/IEEE Std 1003.1j-2000<\/p>\n<p>POSIX.1-2001\/SUSv3(\u5305\u62ec\u4e86\u6240\u6709C99\u7684API)<\/p>\n<p>POSIX.1-2008\/SUSv4<\/p>\n<p>\u5b98\u65b9\u7f51\u7ad9\uff1a<\/p>\n<p><a class=\"link\" href=\"http:\/\/www.opengroup.org\/austin\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.opengroup.org\/austin\/<\/a><\/p>\n<h1 id=\"cygwin\">Cygwin<\/h1>\n<p>\u63d0\u4f9bPOSIX\u7684API\u7528\u4e8ewindows\u4e0a\u5f00\u53d1Linux\/Unix\u7a0b\u5e8f\u3002<\/p>\n<p>\u6e90\u4ee3\u7801\u4e0d\u80fd\u5728windows\u8fd0\u884c\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/cygwin.com\/index.html\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/cygwin.com\/index.html<\/a><\/p>\n<hr>\n<h1 id=\"posix\u6807\u51c6\u5b9a\u4e49\u7684\u5fc5\u987b\u5934\u6587\u4ef6\">POSIX\u6807\u51c6\u5b9a\u4e49\u7684\u5fc5\u987b\u5934\u6587\u4ef6<\/h1>\n<h2 id=\"direnth\">&lt;dirent.h&gt;<\/h2>\n<h2 id=\"fcntlh\">&lt;fcntl.h&gt;<\/h2>\n<h2 id=\"globh\">&lt;glob.h&gt;<\/h2>\n<h2 id=\"netdbh\">&lt;netdb.h&gt;<\/h2>\n<h2 id=\"pwdh\">&lt;pwd.h&gt;<\/h2>\n<h2 id=\"regexh\">&lt;regex.h&gt;<\/h2>\n<h2 id=\"tarh\">&lt;tar.h&gt;<\/h2>\n<h2 id=\"termiosh\">&lt;termios.h&gt;<\/h2>\n<h2 id=\"unistdh\">&lt;unistd.h&gt;<\/h2>\n<h2 id=\"utimeh\">&lt;utime.h&gt;<\/h2>\n<h2 id=\"utimeh-1\">&lt;utime.h&gt;<\/h2>\n<h2 id=\"wordexph\">&lt;wordexp.h&gt;<\/h2>\n<h2 id=\"arpaineth\">&lt;arpa\/inet.h&gt;<\/h2>\n<h2 id=\"netifh\">&lt;net\/if.h&gt;<\/h2>\n<h2 id=\"netinetinh\">&lt;netinet\/in.h&gt;<\/h2>\n<h2 id=\"netinettcph\">&lt;netinet\/tcp.h&gt;<\/h2>\n<h2 id=\"sysmmanh\">&lt;sys\/mman.h&gt;<\/h2>\n<h2 id=\"sysselecth\">&lt;sys\/select.h&gt;<\/h2>\n<h2 id=\"syssocketh\">&lt;sys\/socket.h&gt;<\/h2>\n<h2 id=\"sysstath\">&lt;sys\/stat.h&gt;<\/h2>\n<h2 id=\"systimesh\">&lt;sys\/times.h&gt;<\/h2>\n<h2 id=\"systypesh\">&lt;sys\/types.h&gt;<\/h2>\n<h2 id=\"sysunh\">&lt;sys\/un.h&gt;<\/h2>\n<h2 id=\"sysutsnameh\">&lt;sys\/utsname.h&gt;<\/h2>\n<h2 id=\"waith\">&lt;wait.h&gt;<\/h2>\n<hr>\n<h1 id=\"posix\u6807\u51c6\u5b9a\u4e49\u7684\u53ef\u9009\u5934\u6587\u4ef6\">POSIX\u6807\u51c6\u5b9a\u4e49\u7684\u53ef\u9009\u5934\u6587\u4ef6<\/h1>\n<h2 id=\"aioh\">&lt;aio.h&gt;<\/h2>\n<h2 id=\"pthreadh\">&lt;pthread.h&gt;<\/h2>\n<h2 id=\"semaphoreh\">&lt;semaphore.h&gt;<\/h2>\n<h2 id=\"mqueueh\">&lt;mqueue.h&gt;<\/h2>\n<h2 id=\"schedh\">&lt;sched.h&gt;<\/h2>\n<h2 id=\"spawnh\">&lt;spawn.h&gt;<\/h2>\n<h2 id=\"stropsh\">&lt;strops.h&gt;<\/h2>\n<h2 id=\"traceh\">&lt;trace.h&gt;<\/h2>\n<hr>\n<h1 id=\"posix\u6807\u51c6\u5b9a\u4e49\u7684xsi\u6269\u5c55\u5934\u6587\u4ef6\">POSIX\u6807\u51c6\u5b9a\u4e49\u7684XSI\u6269\u5c55\u5934\u6587\u4ef6<\/h1>\n<h2 id=\"sysipch\">&lt;sys\/ipc.h&gt;<\/h2>\n<h2 id=\"sysmsgh\">&lt;sys\/msg.h&gt;<\/h2>\n<h2 id=\"syssemh\">&lt;sys\/sem.h&gt;<\/h2>\n<h2 id=\"sysshmh\">&lt;sys\/shm.h&gt;<\/h2>\n<h2 id=\"cpioh\">&lt;cpio.h&gt;<\/h2>\n<h2 id=\"dlfcnh\">&lt;dlfcn.h&gt;<\/h2>\n<h2 id=\"fmtmsgh\">&lt;fmtmsg.h&gt;<\/h2>\n<h2 id=\"ftwh\">&lt;ftw.h&gt;<\/h2>\n<h2 id=\"iconvh\">&lt;iconv.h&gt;<\/h2>\n<h2 id=\"langinfoh\">&lt;langinfo.h&gt;<\/h2>\n<h2 id=\"libgenh\">&lt;libgen.h&gt;<\/h2>\n<h2 id=\"monetaryh\">&lt;monetary.h&gt;<\/h2>\n<h2 id=\"ndbmh\">&lt;ndbm.h&gt;<\/h2>\n<h2 id=\"nl_typesh\">&lt;nl_types.h&gt;<\/h2>\n<h2 id=\"pollh\">&lt;poll.h&gt;<\/h2>\n<h2 id=\"searchh\">&lt;search.h&gt;<\/h2>\n<h2 id=\"stringsh\">&lt;strings.h&gt;<\/h2>\n<h2 id=\"syslogh\">&lt;syslog.h&gt;<\/h2>\n<h2 id=\"ucontexth\">&lt;ucontext.h&gt;<\/h2>\n<h2 id=\"ulimith\">&lt;ulimit.h&gt;<\/h2>\n<h2 id=\"utmpxh\">&lt;utmpx.h&gt;<\/h2>\n<h2 id=\"sysresourceh\">&lt;sys\/resource.h&gt;<\/h2>\n<h2 id=\"sysstatvfsh\">&lt;sys\/statvfs.h&gt;<\/h2>\n<h2 id=\"systimeh\">&lt;sys\/time.h&gt;<\/h2>\n<h2 id=\"systimebh\">&lt;sys\/timeb.h&gt;<\/h2>\n<h2 id=\"sysuioh\">&lt;sys\/uio.h&gt;<\/h2>"},{"title":"Regular Expression","link":"https:\/\/canuxcheng.com\/post\/regularexpression\/","pubDate":"Sat, 02 Apr 2016 11:16:16 +0000","guid":"https:\/\/canuxcheng.com\/post\/regularexpression\/","description":"<h1 id=\"re\">RE<\/h1>\n<p>\u5728\u7ebf\u68c0\u6d4b\uff1a<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.regexpal.com\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.regexpal.com\/<\/a><\/p>\n<p>RE\u5206\u4e3aBRE(basic RE), ERE(extended RE), SRE(simpla RE).<\/p>\n<p>\u5728BRE\u4e2d+?(){}|\u6ca1\u6709\u7279\u6b8a\u542b\u4e49\uff0c\u9664\u975e\u7528\\\u8f6c\u4e49\uff0e<\/p>\n<p>\u5728ERE\u4e2d+?(){}\u88ab\u4fdd\u7559\u6709\u7279\u6b8a\u542b\u4e49\uff0c\u9664\u975e\u7528\\\u8f6c\u4e49\u624d\u8868\u793a\u666e\u901a\u5b57\u7b26\uff0e<\/p>\n<p>\u547d\u4ee4find, grep, sed, awk\u7b49\u90fd\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\uff0e<\/p>\n<p>\u7279\u6b8a\u5b57\u7b26\u542b\u4e49\uff1a<\/p>\n<pre><code>() \u5bf9\u6b63\u5219\u8868\u8fbe\u5f0f\u5206\u7ec4, ERE\n\\n \u518d\u5339\u914d\u524d\u9762\u7684\u5206\u7ec4n\u6b21\n. \u5339\u914d\u4efb\u610f\u5355\u4e2a\u5b57\u7b26, \u6362\u884c\u7b26\u9664\u5916\n^tux \u5339\u914d\u4ee5tux\u5f00\u59cb\u7684\u884c\ntux$ \u5339\u914d\u4ee5tux\u7ed3\u675f\u7684\u884c\n*+?{}\u7279\u6b8a\u5b57\u7b26\u662f\u8d2a\u5a6a\u5339\u914d\u6a21\u5f0f,\u4e5f\u5c31\u662f\u5c3d\u53ef\u80fd\u591a\u7684\u5339\u914d\n* \u5339\u914d\u524d\u9762\u4e00\u4e2a\u5b57\u7b260\u6b21\u6216\u591a\u6b21\uff0c\u5305\u62ec\u524d\u9762\u8fd9\u4e2a\u5b57\u7b26\u672c\u8eab\n+ \u5339\u914d\u524d\u9762\u4e00\u4e2a\u5b57\u7b261\u6b21\u6216\u591a\u6b21\uff0c\u5305\u62ec\u524d\u9762\u8fd9\u4e2a\u5b57\u7b26, ERE\n? \u5339\u914d\u524d\u9762\u4e00\u4e2a\u5b57\u7b260\u6b21\u62161\u6b21\uff0c\u5305\u62ec\u524d\u9762\u8fd9\u4e2a\u5b57\u7b26, ERE\n{n} \u5339\u914d\u524d\u9762\u4e00\u4e2a\u5b57\u7b26n\u6b21\uff0c\u5305\u62ec\u524d\u9762\u8fd9\u4e2a\u5b57\u7b26, ERE\n{min,} \u5339\u914d\u524d\u9762\u4e00\u4e2a\u5b57\u7b26\u81f3\u5c11min\u6b21\uff0c\u5305\u62ec\u524d\u9762\u8fd9\u4e2a\u5b57\u7b26, ERE\n{min,max} \u5339\u914d\u524d\u9762\u4e00\u4e2a\u5b57\u7b26\u81f3\u5c11min\u6b21\uff0c\u6700\u591amax\u6b21\uff0c\u5305\u62ec\u524d\u9762\u8fd9\u4e2a\u5b57\u7b26, ERE\n\u4e0b\u9762\u662f\u975e\u8d2a\u5a6a\u5339\u914d\u6a21\u5f0f\n*? \u5339\u914d0\u4e2a\u6216\u591a\u4e2a\n+? \u5339\u914d1\u4e2a\u6216\u591a\u4e2a\n?? \u5339\u914d\uff10\u4e2a\u6216\uff11\u4e2a\n{n}? \u53ea\u5339\u914dn\u4e2a\n{min,}? \u81f3\u5c11min\u4e2a\n{min,max}? \u81f3\u5c11min\u4e2a\uff0c\u6700\u591amax\u4e2a\n[abc] \u5339\u914d\u5305\u542b\u5728[]\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\uff0c\u9664\u4e86\\, ^, -\u4e09\u4e2a\u7279\u6b8a\u5b57\u7b26\n[^abc] \u5339\u914d\u4e0d\u5305\u542b\u5728[]\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26(\u548c\u4e0a\u9762\u76f8\u53cd)\n[a-z] \u5339\u914d[]\u4e2d\u6307\u5b9a\u8303\u56f4\u5185\u7684\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\n[abc\\?] \u7528\uff3c\u8f6c\u4e49[]\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\n| \u8868\u793a\u903b\u8f91\u6216, ERE\n\\ \u8f6c\u4e49\u5b57\u7b26\uff0c\u5c06\u7279\u6b8a\u5b57\u7b26\u8f6c\u4e49\u6210\u666e\u901a\u5b57\u7b26\n\u5c0f\u62ec\u53f7\u8868\u793a\u5206\u7ec4\n(...)\n(?...)\n(?iLmsux)\n(?:...)\n(?P&lt;name&gt;...)\n(?P=name)\n(?#...)\n(?=...)\n(?!...)\n(?&lt;=...)\n(?&lt;!...)\n(?(id\/name)yes-pattern|no-pattern)\n<\/code><\/pre>\n<p>\u5339\u914d\u524d\u9762\u4e00\u4e2a\u5b57\u7b26\uff10\u6b21\uff0c\u5305\u62ec\u524d\u9762\u8fd9\u4e2a\u5b57\u7b26\uff0c\u4e5f\u5c31\u662f\u8bf4\uff10\u6b21\u8868\u793a\u4e0d\u5339\u914d\u524d\u9762\u8fd9\u4e2a\u5b57\u7b26\uff0e<\/p>\n<p>\u5b57\u7b26\u96c6:<\/p>\n<p>\u4e0b\u5217\u5b57\u7b26\u96c6\u662fposix\u6807\u51c6\uff0c\u7528\u5728[]\u4e2d\uff0c\u4e5f\u5c31\u662f[[:alnum:]].<\/p>\n<pre><code>[:alnum:] \u53ef\u6253\u5370\u7684\u5b57\u7b26\uff0c\u5305\u62ec\u7a7a\u767d\u5b57\u7b26\n[:alpha:]\u3000\u3000\u5b57\u6bcd\u5b57\u7b26\n[:blank:]\u3000\u3000\u7a7a\u683c\u548c\u5236\u8868\u7b26\uff0cspace, \\t\n[:cntrl&quot;] \u63a7\u5236\u5b57\u7b26\n[:digit:]\u3000\u3000\u6570\u5b57\u5b57\u7b26\n[:graph:]\u3000\u3000\u56fe\u5f62\u5b57\u7b26\uff0c\u4e0d\u5305\u62ec\u7a7a\u767d\u5b57\u7b26\n[:lower:]\u3000\u3000\u5c0f\u5199\u5b57\u7b26\n[:print:]\u3000\u3000\u53ef\u6253\u5370\u5b57\u7b26\uff0c\u5305\u62ec\u7a7a\u767d\u5b57\u7b26\n[:punct:]\u3000\u3000\u6807\u70b9\u7b26\u53f7\u5b57\u7b26\n[:space:]\u3000\u3000\u7a7a\u767d\u5b57\u7b26\n[:upper:]\u3000\u3000\u5927\u5199\u5b57\u7b26\n[:xdigit:]\u3000 \u5341\u516d\u8fdb\u5236\u5b57\u7b26\n<\/code><\/pre>\n<p>\u5b57\u7b26\u96c6\u7684\u7b80\u5199(\u4e0d\u540c\u7684\u7f16\u7a0b\u8bed\u8a00\u53ef\u80fd\u4e0d\u540c)\uff1a<\/p>\n<pre><code>\\b \u5339\u914d\u5355\u8bcd\u8fb9\u754c\n\\B \u5339\u914d\u5355\u8bcd\u7684\u975e\u8fb9\u754c\n\\A \u5339\u914d\u5b57\u7b26\u4e32\u7684\u8d77\u59cb\n\\Z\u3000\u3000\u3000\u5339\u914d\u5b57\u7b26\u4e32\u7684\u7ed3\u675f\n\\d \u5339\u914d\u4efb\u4f55\u6570\u5b57\uff10\uff0d\uff19\n\\D \u5339\u914d\u4efb\u4f55\u975e\u6570\u5b57\uff0c\u7b49\u6548[^\\d]\n\\w \u5339\u914d\u4efb\u4f55\u6570\u5b57\u548c\u5b57\u6bcd\uff0ca-z,A-Z,0-9\n\\W \u5339\u914d\u4efb\u4f55\u975e\u6570\u5b57\u548c\u975e\u5b57\u6bcd\n\\s \u5339\u914d\u4efb\u4f55\u7a7a\u767d\u5b57\u7b26,\u5305\u62ecspace,\\t,\\n,\\r,\\f\n\\S \u5339\u914d\u4efb\u4f55\u975e\u7a7a\u767d\u5b57\u7b26\n\\h \u5339\u914d\u6a2a\u5411\u7a7a\u767d\uff0c\u5305\u62ecspace,\\t\n\\v \u5339\u914d\u7eb5\u5411\u7a7a\u767d\uff0c\u5305\u62ec\\f,\\r,\\n\n\\r \u56de\u8f66\n\\R\u3000\u3000\u3000\u5339\u914d\u4efb\u4f55\u7c7b\u578b\u7684\u65ad\u884c\n\\a\n\\f\n\\t\n\\n\n<\/code><\/pre>\n<h1 id=\"\u5e38\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\">\u5e38\u7528\u6b63\u5219\u8868\u8fbe\u5f0f<\/h1>\n<pre><code>.* \u5339\u914d\u4efb\u610f\u5b57\u7b26\uff10\u6b21\u6216\u591a\u6b21\uff0c\u9664\u4e86\u6362\u884c\u7b26\n^$ \u5339\u914d\u7a7a\u767d\u884c\n[\\s\\S] \u5339\u914d\u4efb\u4f55\u7a7a\u767d\u5b57\u7b26\u548c\u975e\u7a7a\u767d\u5b57\u7b26\n^\\s\\+ \u884c\u9996\u7a7a\u683c\n\\s\\+$ \u884c\u5c3e\u7a7a\u683c\n^[^&lt;] \u4e0d\u4ee5&lt;\u5f00\u5934\u7684\u5b57\u7b26\u4e32\n<\/code><\/pre>"},{"title":"Sed","link":"https:\/\/canuxcheng.com\/post\/shell_sed\/","pubDate":"Sat, 02 Apr 2016 11:15:57 +0000","guid":"https:\/\/canuxcheng.com\/post\/shell_sed\/","description":"<h1 id=\"sed\">sed<\/h1>\n<p>sed\uff1astream editor \u6d41\u7f16\u8f91\u5668 \uff0c\u4e3b\u8981\u7528\u4e8e\u6587\u672c\u5904\u7406\u3002<\/p>\n<p>sed\u547d\u4ee4\u683c\u5f0f\uff1a<\/p>\n<pre><code>sed -options \u2019expression1;expression2\u2019 file \u6267\u884c\u591a\u4e2a\u547d\u4ee4\nsed -options [-e \u2018expression1\u2019] [-e \u2018expression2\u2019] file \u6267\u884c\u591a\u4e2a\u547d\u4ee4\nsed -options [-f scriptfile] file \u901a\u8fc7\u811a\u672c\u6267\u884c\u547d\u4ee4\nsed -options [-f scriptfile] file &gt; newfile #sed\u4fee\u6539\u540e\u91cd\u5b9a\u5411\u5230\u65b0\u6587\u4ef6\u3002\n<\/code><\/pre>\n<p>sed\u6307\u4ee4\u9700\u8981\u7528\u5355\u5f15\u53f7\u5305\u56f4\u3002\u4f7f\u7528\u53cc\u5f15\u53f7\u201c\u201d\u53ef\u4ee5\u4f20\u9012\u53d8\u91cf\u3002\nSed\u9ed8\u8ba4\u5e76\u6ca1\u6709\u4fee\u6539\u6587\u4ef6file\u4e2d\u7684\u6570\u636e\u3002\nsed\u9ed8\u8ba4\u5728stdout\u8f93\u51fa\u6587\u4ef6\u7684\u6240\u6709\u884c\u3002\nSed\u5730\u5740\u9700\u8981\u4f7f\u7528\/address\/\u6765\u5305\u56f4\u3002\nsed\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u4ee5\u7528\\BRE\\\u5305\u56f4\uff0c\u5982\u679c\u6a21\u5f0f\u5305\u542b\/\uff0c\u90a3\u4e48\u53ef\u4ee5\u4f7f\u7528\u9664\u4e86\u6362\u884c\u7b26\u4e4b\u5916\u7684\u6240\u6709\u5b57\u7b26\u5305\u56f4\u3002<\/p>\n<p>options\uff1a<\/p>\n<pre><code>-e\uff1a\u6307\u5b9a\u591a\u4e2a\u547d\u4ee4\u6216\u811a\u672c\n-f\uff1a\u6307\u5b9a\u6267\u884c\u547d\u4ee4\u7684\u811a\u672c\n-n\uff1a\u963b\u6b62\u81ea\u52a8\u8f93\u51fa\uff0cp\u53ef\u4ee5\u6253\u5370\u5339\u914d\u7684\u884c\u3002\n-i: \u76f4\u63a5\u4fee\u6539\u8bfb\u5165\u7684\u6587\u4ef6\u7684\u5185\u5bb9.\n<\/code><\/pre>\n<p>experssion\uff1a<\/p>\n<pre><code>expression\uff1a\u6307\u4ee4\u7531\u6a21\u5f0f\u548c\u8fc7\u7a0b\u7ec4\u6210\u3002\n[address]\/[line-address][!]command[arguments]\n[address]\u8868\u793a\u5730\u5740\uff0c\u4e00\u822c\u7528\u6a21\u5f0f\u8fdb\u884c\u5bfb\u5740\uff0caddress\u7f3a\u7701\u8868\u793a\u6574\u4e2a\u6587\u4ef6\u5bfb\u5740\uff0c\u4e24\u4e2a\u5730\u5740\u7528\uff0c\u9694\u5f00\u3002\n[line-address]\u8868\u793a\u53ea\u80fd\u662f\u4e00\u4e2a\u5730\u5740\u3002\n[!] \u8868\u793a\u4e0d\u5339\u914d\u8be5\u5730\u5740\u7684\u6240\u6709\u884c\n<\/code><\/pre>\n<p>Command:<\/p>\n<p>sed\u670925\u4e2a\u547d\u4ee4\u3002<\/p>\n<p>\u4f7f\u7528\u5927\u62ec\u53f7{}\u5728\u4e00\u4e2a\u5730\u5740\u4e2d\u505a\u5d4c\u5957\u64cd\u4f5c\uff1a\u4f8b\u5982\uff1a<\/p>\n<pre><code>\/address1\/,\/address2\/{\n\/^$\/d\ns\/string1\/string2\/\n\u2026\n} \/\/ \u5355\u72ec\u4e00\u884c\uff0c\u540e\u9762\u4e0d\u80fd\u6709\u7a7a\u683c\n<\/code><\/pre>\n<p>s\u547d\u4ee4\uff1a\u66ff\u6362\uff0c\u66ff\u6362\u6a21\u5f0f\u7a7a\u95f4\u4e2d\u7684\u884c\u3002<\/p>\n<pre><code>sed '[address]s\/oldpattern\/newpattern\/[flag]' filename\n<\/code><\/pre>\n<p>flag:<\/p>\n<pre><code>n:\u66ff\u6362\u6bcf\u4e2a\u5bfb\u5740\u884c\u7684\u7b2cn\u4e2a\u5339\u914d\u6a21\u5f0f\u3002\u9ed8\u8ba4n=1. n\u57281-512\u4e4b\u95f4\u3002\ng:\u66ff\u6362\u6bcf\u4e2a\u5bfb\u5740\u884c\u7684\u6240\u6709\u5339\u914d\u6a21\u5f0f\u3002\np:\u6253\u5370\u6a21\u5f0f\u7a7a\u95f4\u7684\u5185\u5bb9\nw file\uff1a\u5982\u679c\u53d1\u751f\u66ff\u6362\u5c31\u5c06\u8fd9\u4e00\u884c\u5199\u5165file\u3002\u53ea\u5199\u5165\u66ff\u6362\u7684\u884c,\u4e0d\u5199\u5165\u5176\u5b83\u884c.\n<\/code><\/pre>\n<p>\u7528\u53cd\u659c\u6760\\\u8f6c\u4e49\u6362\u884c\u7b26\uff1a<\/p>\n<p>\u56e0\u4e3a\u53cd\u659c\u6760\u5728newpattern\u4e2d\u4e5f\u7528\u4e8e\u5305\u542b\u6362\u884c\u7b26\u3002<\/p>\n<pre><code>\/\/ \u5c06\u5339\u914d\u7684\u9879\u66ff\u6362\u6210\u4e24\u4e2a\u6362\u884c\u7b26\u3002\nsed '\ns\/pattern\/\\ (\u6362\u884c\uff09\n\\ \uff08\u6362\u884c\uff09\nstring\/' filename\n\u7b49\u4ef7\u4e8e\uff1a\nsed 's\/pattern\/\\n\\n\/' filename\n<\/code><\/pre>\n<p>\u7528\u53cd\u659c\u6760\\\u8f6c\u4e49\u4e0e\u7b26\u53f7&amp;\uff1a<\/p>\n<pre><code>\/\/ \u7ed3\u679c\u662f\uff1a string1 pattern string2\nsed 's\/pattern\/string1 &amp; string2\/g' filename\n<\/code><\/pre>\n<p>\u5982\u679c\u4e0d\u8f6c\u4e49&amp;\u5339\u914d\u6574\u4e2apattern:<\/p>\n<pre><code>\/\/ \u7ed3\u679c\u662f\uff1astring1 &amp; string2\nsed 's\/pattern\/string1 \\&amp; string2\/g' filename\n<\/code><\/pre>\n<p>\u7528\u53cd\u659c\u6760\\\u8f6c\u4e49\\n:<\/p>\n<pre><code>\/\/ \u5c06pattern\u4e2d\u5339\u914d\u5230\u7684\u7b2c\u4e00\u4e2a\u5b57\u4e32\u56de\u8c03\u5230newpattern\u4e2d\u4f7f\u7528\u3002\nsed 's\/pattern\/\\1\/' filename\n<\/code><\/pre>\n<p>d\u547d\u4ee4\uff1a\u5220\u9664\uff0c\u5220\u9664\u6a21\u5f0f\u7a7a\u95f4\u4e2d\u7684\u884c\uff0c\u5e76\u4e0d\u5220\u9664\u6587\u4ef6\u4e2d\u7684\u884c\u3002<\/p>\n<pre><code>'[address]d'\n'1d' \u5220\u9664\u7b2c\u4e00\u884c\n'$d' \u5220\u9664\u6700\u540e\u4e00\u884c\n\u2019\/^$\/d' \u5220\u9664\u7a7a\u884c\n\u2018\/^\\s\\+$\/d\u2019 \u5220\u9664\u7a7a\u767d\u884c\uff08\u6ca1\u6709\u6570\u5b57\u5b57\u7b26\uff09\n\u2018\/^\\s*$\/d\u2019 \u5220\u9664\u7a7a\u767d\u884c\uff08\u6ca1\u6709\u6570\u5b57\u5b57\u7b26\uff09\n<\/code><\/pre>\n<p>a\/i\/c\u547d\u4ee4\uff1a\u8ffd\u52a0\/\u63d2\u5165\/\u66f4\u6539.<\/p>\n<pre><code>\/\/ \u5728\u5339\u914d\u5230\u7684\u884c\u4e0b\u9762\u6dfb\u52a0\u8ffd\u52a0\u7684\u5185\u5bb9\n'[line-address]a string' filename\n'[line-address]a\\\nstring1\\\nstring2\\\nstring3' filename \uff08\u8ffd\u52a0\u4e09\u884c\uff09\n<\/code><\/pre>\n<p>i:\u540c\u4e0a\uff0c\u5728\u5339\u914d\u5230\u7684\u884c\u4e0a\u9762\u63d2\u5165\u5185\u5bb9\u3002<\/p>\n<pre><code>\/\/ \u5c06\u5339\u914d\u5230\u7684\u884c\u66ff\u6362\u6389\u3002\n'[address]c string' filename\n'[address]c\\\nstring1\\\nstring2\\\nstring3' filename\n<\/code><\/pre>\n<p>l\uff1a\u5217\u8868\u547d\u4ee4<\/p>\n<pre><code>sed '[address]l' filename \u6253\u5370\u6a21\u5f0f\u7a7a\u95f4\u5185\u5bb9\uff0c\u5c06\u975e\u6253\u5370\u5b57\u7b26\u663e\u793a\u4e3aASCII\u7801\n<\/code><\/pre>\n<p>p\uff1a\u6253\u5370\u547d\u4ee4<\/p>\n<pre><code>sed '[address]p' filename \u6253\u5370\u6a21\u5f0f\u7a7a\u95f4\u5185\u5bb9\n<\/code><\/pre>\n<p>=\uff1a\u6253\u5370\u884c\u53f7<\/p>\n<pre><code>sed -n '[line-address]=' filename \u53ea\u6253\u5370\u884c\u53f7\n<\/code><\/pre>\n<p>n\uff1a\u4e0b\u4e00\u6b65<\/p>\n<pre><code>sed '[address]n' filename\n<\/code><\/pre>\n<p>q:\u9000\u51fa\u547d\u4ee4<\/p>\n<pre><code>\/\/ \u4e00\u65e6\u627e\u5230\u548cline-address\u5339\u914d\u7684\u884c\uff0c\u811a\u672c\u7acb\u5373\u9000\u51fa\u3002\nsed '[line-address]q' filename\n<\/code><\/pre>\n<p>r\/w:\u8bfb\/\u5199\u547d\u4ee4<\/p>\n<pre><code>\/\/ \u8bfbfile\u6587\u4ef6\u8ffd\u52a0\u5728\u5339\u914d\u5230\u7684\u884c\u540e\u9762\u3002\nsed '[line-address]r file' filename\n\/\/ \u5c06\u5339\u914d\u5230\u7684\u884c\u5199\u5165\u5230file\u6587\u4ef6\u4e2d\nsed '[address]w file' filename\nsed \u2013I 's\/.*\/\\L&amp;\/g' urfile \u5168\u90e8\u8f6c\u6362\u6210\u5c0f\u5199\nsed -I 's\/.*\/\\U&amp;\/g' urfile \u5168\u90e8\u8f6c\u6362\u6210\u5927\u5199\u3002\nsed \u2018\/pattern\/{{n; p;}}\u2019 urfile \u8bfb\u53d6pattern\u4e0b\u4e00\u884c\u5e76\u6253\u5370\u3002\n<\/code><\/pre>\n<p>n\uff1a\u8ffd\u52a0\u4e0b\u4e00\u4e2a\u8f93\u5165\u884c\u5230\u5339\u914d\u540e\u9762\u5e76\u5728\u4e24\u8005\u95f4\u5d4c\u5165\u65b0\u884c\uff0c\u6539\u53d8\u884c\u53f7\u3002<\/p>\n<p>p\uff1a\u6253\u5370\u5339\u914d\u7684\u7b2c\u4e00\u884c\u3002<\/p>\n<h1 id=\"\u5e38\u7528\">\u5e38\u7528<\/h1>\n<pre><code>sed \u2018$a string\u2019 filenames #\u6279\u91cf\u5f80\u6587\u4ef6\u6700\u540e\u4e00\u884c\u6dfb\u52a0\u5185\u5bb9\nsed \u2018$i string\u2019 filenames #\u6279\u91cf\u5f80\u6587\u4ef6\u5012\u6570\u7b2c\u4e8c\u884c\u6dfb\u52a0\u5185\u5bb9\nstring\u91cc\u9762\u6709\u7a7a\u683c\u7528\\\u5f00\u5934\u3002\n<\/code><\/pre>"},{"title":"ISO","link":"https:\/\/canuxcheng.com\/post\/c_iso\/","pubDate":"Fri, 01 Apr 2016 21:54:16 +0000","guid":"https:\/\/canuxcheng.com\/post\/c_iso\/","description":"<h1 id=\"c\u6807\u51c6\u5e93\">C\u6807\u51c6\u5e93<\/h1>\n<p>ISO C89(ANSI C89) -&gt; ISO C95 -&gt; ISO C99 -&gt;<\/p>\n<p>-&gt; ISO C11 -&gt; ISO C17 -&gt; ISO C23<\/p>\n<p>ANSI C \u548c ISO C\u662f\u5bf9\u901a\u7528C\u8bed\u8a00\u7684\u63a5\u53e3\u7684\u5b9a\u4e49\u3002<\/p>\n<p>\u7b26\u5408\u8fd9\u79cd\u6807\u51c6\u7684\u5b9e\u73b0\u4e3aC\u8bed\u8a00\u6807\u51c6\u5e93,\u4e5f\u53eblibc\u3002<\/p>\n<p>\u5b98\u65b9\u7f51\u7ad9\uff1a<\/p>\n<p><a class=\"link\" href=\"http:\/\/www.open-std.org\/jtc1\/sc22\/wg14\/www\/standards\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.open-std.org\/jtc1\/sc22\/wg14\/www\/standards<\/a><\/p>\n<hr>\n<h1 id=\"c89\u548cc99\u652f\u6301\u7684\u5934\u6587\u4ef6\u548c\u51fd\u6570\">C89\u548cC99\u652f\u6301\u7684\u5934\u6587\u4ef6\u548c\u51fd\u6570<\/h1>\n<h2 id=\"asserth\">&lt;assert.h&gt;<\/h2>\n<h2 id=\"ctypeh\">&lt;ctype.h&gt;<\/h2>\n<h2 id=\"complexh\">&lt;complex.h&gt;<\/h2>\n<h2 id=\"errnoh\">&lt;errno.h&gt;<\/h2>\n<h2 id=\"floath\">&lt;float.h&gt;<\/h2>\n<h2 id=\"fenvh\">&lt;fenv.h&gt;<\/h2>\n<h2 id=\"inttypeh\">&lt;inttype.h&gt;<\/h2>\n<h2 id=\"iso646h\">&lt;iso646.h&gt;<\/h2>\n<h2 id=\"limitsh\">&lt;limits.h&gt;<\/h2>\n<h2 id=\"localeh\">&lt;locale.h&gt;<\/h2>\n<h2 id=\"mathh\">&lt;math.h&gt;<\/h2>\n<h2 id=\"setjmph\">&lt;setjmp.h&gt;<\/h2>\n<h2 id=\"signalh\">&lt;signal.h&gt;<\/h2>\n<h2 id=\"stdargh\">&lt;stdarg.h&gt;<\/h2>\n<h2 id=\"stddefh\">&lt;stddef.h&gt;<\/h2>\n<h2 id=\"stdioh\">&lt;stdio.h&gt;<\/h2>\n<h2 id=\"stdlibh\">&lt;stdlib.h&gt;<\/h2>\n<h2 id=\"stringh\">&lt;string.h&gt;<\/h2>\n<h2 id=\"stdboolh\">&lt;stdbool.h&gt;<\/h2>\n<h2 id=\"stdinth\">&lt;stdint.h&gt;<\/h2>\n<h2 id=\"timeh\">&lt;time.h&gt;<\/h2>\n<h2 id=\"tgmathh\">&lt;tgmath.h&gt;<\/h2>\n<h2 id=\"wcharh\">&lt;wchar.h&gt;<\/h2>\n<h2 id=\"wctypeh\">&lt;wctype.h&gt;<\/h2>\n<hr>\n<h1 id=\"c11\u652f\u6301\u7684\u5934\u6587\u4ef6\u548c\u51fd\u6570\">C11\u652f\u6301\u7684\u5934\u6587\u4ef6\u548c\u51fd\u6570<\/h1>\n<h2 id=\"stdalignh\">&lt;stdalign.h&gt;<\/h2>\n<h2 id=\"stdatomich\">&lt;stdatomic.h&gt;<\/h2>\n<h2 id=\"threadsh\">&lt;threads.h&gt;<\/h2>\n<hr>\n<h1 id=\"c\u6807\u51c6\">C++\u6807\u51c6<\/h1>\n<p>C++98, C++11, C++14, C++17, C++20, C++23<\/p>\n<p>c++ \u5934\u6587\u4ef6\u4e0d\u5e26.h\u7528\u6765\u548cC\u533a\u5206\u3002<\/p>\n<h2 id=\"\u6838\u5fc3\u529f\u80fd\">\u6838\u5fc3\u529f\u80fd<\/h2>\n<p><a class=\"link\" href=\"https:\/\/zh.cppreference.com\/w\/cpp\/language\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/zh.cppreference.com\/w\/cpp\/language<\/a><\/p>\n<h2 id=\"\u6807\u51c6\u5e93\">\u6807\u51c6\u5e93<\/h2>\n<p><a class=\"link\" href=\"https:\/\/zh.cppreference.com\/w\/cpp\/standard_library\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/zh.cppreference.com\/w\/cpp\/standard_library<\/a><\/p>\n<!-- raw HTML omitted -->\n<p><a class=\"link\" href=\"https:\/\/cplusplus.com\/reference\/iostream\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/cplusplus.com\/reference\/iostream\/<\/a><\/p>\n<!-- raw HTML omitted -->\n<p><a class=\"link\" href=\"https:\/\/cplusplus.com\/reference\/string\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/cplusplus.com\/reference\/string\/<\/a><\/p>\n<h2 id=\"stl\">STL<\/h2>\n<h3 id=\"containers\">containers<\/h3>\n<h3><\/h3>"},{"title":"Shell","link":"https:\/\/canuxcheng.com\/post\/shell\/","pubDate":"Fri, 01 Apr 2016 20:42:59 +0000","guid":"https:\/\/canuxcheng.com\/post\/shell\/","description":"<h1 id=\"shell\">Shell<\/h1>\n<p>Linux\u7684shell\u6709\u5f88\u591a\u79cd,\u5927\u591a\u6570linux\u53d1\u884c\u7248\u7684\u9ed8\u8ba4\u767b\u5f55shell\u662fBASH\u3002<\/p>\n<p>\u67e5\u770b\u5f53\u524d\u4f7f\u7528\u7684shell\uff1a<\/p>\n<pre><code>echo $SHELL\necho $0\n<\/code><\/pre>\n<p>\u67e5\u770b\u5b89\u88c5\u4e86\u54ea\u4e9bshell\uff1a<\/p>\n<pre><code>cat \/etc\/shells\n<\/code><\/pre>\n<p>\u8bbe\u7f6e\u767b\u9646shell:<\/p>\n<pre><code>$chsh -s $(which shellname)\n<\/code><\/pre>\n<p>shell\u5206\u4e3a\u767b\u9646shell\u548c\u4ea4\u4e92\u5f0fshell:<\/p>\n<pre><code># \u8f93\u51fa\u6709i\u7684\u5c31\u662f\u4ea4\u4e92shell\n$echo $-\n<\/code><\/pre>\n<p>\u975e\u4ea4\u4e92\u767b\u9646shell:<\/p>\n<ul>\n<li>\u5148\u8fd0\u884c\u7cfb\u7edf\u914d\u7f6e\u6587\u4ef6\/etc\/profile(\u8c03\u7528\/etc\/bash.bashrc\u548c\/etc\/profile.d\/*.sh)<\/li>\n<li>\u7136\u540e\u8fd0\u884c\u7528\u6237\u914d\u7f6e\u6587\u4ef6~\/.profile(\u8c03\u7528~\/.bashrc\u548c~\/bin)<\/li>\n<li>\u6700\u540e\u9000\u51fa\u7528\u6237\u767b\u9646~\/.bash_logout<\/li>\n<\/ul>\n<p>\u4ea4\u4e92\u975e\u767b\u9646shell:<\/p>\n<ul>\n<li>\u5148\u8fd0\u884c\/etc\/bash.bashrc(\u8c03\u7528\/etc\/bash_completion(\u8c03\u7528\/etc\/bash_completion.d\/*.sh))<\/li>\n<li>\u7136\u540e\u8fd0\u884c~\/.bashrc(\u8c03\u7528~\/.bash_aliases\u548c~\/bash.d\u548c~\/bin)<\/li>\n<\/ul>\n<hr>\n<h1 id=\"shell\u76f8\u5173\u9879\u76ee\">shell\u76f8\u5173\u9879\u76ee<\/h1>\n<h2 id=\"bash-it\">bash-it<\/h2>\n<p>\u5927\u90e8\u5206\u53d1\u884c\u7248\u9ed8\u8ba4\u4f7f\u7528bash,\u65e0\u9700\u989d\u5916\u5b89\u88c5\u3002<\/p>\n<p>bash\u7684\u4f18\u5316\u9879\u76eebash-it\uff1a<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/Bash-it\/bash-it\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/Bash-it\/bash-it<\/a><\/p>\n<h2 id=\"zsh\">zsh<\/h2>\n<p><a class=\"link\" href=\"http:\/\/www.zsh.org\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.zsh.org\/<\/a><\/p>\n<h2 id=\"oh-my-zsh\">oh-my-zsh<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/robbyrussell\/oh-my-zsh\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/robbyrussell\/oh-my-zsh<\/a><\/p>\n<h2 id=\"fish-shell\">fish-shell<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/fish-shell\/fish-shell\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/fish-shell\/fish-shell<\/a><\/p>\n<h2 id=\"oh-my-fish\">oh-my-fish<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/oh-my-fish\/oh-my-fish\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/oh-my-fish\/oh-my-fish<\/a><\/p>\n<h2 id=\"thefuck\">thefuck<\/h2>\n<p>\u4e00\u4e2a\u7ea0\u6b63shell\u547d\u4ee4\u8f93\u9519\u7684\u547d\u4ee4<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/nvbn\/thefuck\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/nvbn\/thefuck<\/a><\/p>\n<h2 id=\"shellcheck\">shellcheck<\/h2>\n<p>\u4e00\u4e2adebug\u811a\u672c\u7684\u5de5\u5177\uff0e<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/koalaman\/shellcheck\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/koalaman\/shellcheck<\/a><\/p>\n<hr>\n<h1 id=\"shell-script\">shell script<\/h1>\n<p>\u57fa\u672c\u8bed\u6cd5<\/p>\n<pre><code>#!\/usr\/bin\/env bash\ncommand1 &amp;&amp; command2 # \u5f53command1\u6267\u884c\u6210\u529f\uff08\u8fd4\u56de0)\u624d\u4f1a\u6267\u884ccommand2\ncommand1 || command2 # \u5f53command1\u6267\u884c\u5931\u8d25\uff08\u8fd4\u56de\u975e0)\u624d\u4f1a\u6267\u884ccommand2\n<\/code><\/pre>\n<h2 id=\"shell\u6ce8\u91ca\">shell\u6ce8\u91ca<\/h2>\n<p>\u5355\u884c\u6ce8\u91ca\uff1a<\/p>\n<pre><code># comment\n<\/code><\/pre>\n<p>\u591a\u884c\u6ce8\u91ca\uff1a<\/p>\n<pre><code>:&lt;&lt;!EOF!\ncomment\n!EOF! can be any symbol and character.\n!EOF!\n<\/code><\/pre>\n<h2 id=\"shell\u5173\u952e\u5b57\u548c\u7279\u6b8a\u7b26\u53f7\">shell\u5173\u952e\u5b57\u548c\u7279\u6b8a\u7b26\u53f7<\/h2>\n<p>\u4e09\u4e2a\u7279\u6b8a\u547d\u4ee4<\/p>\n<pre><code>echo # echo\u53ef\u4ee5\u8f93\u51fa\u5b57\u7b26\u4e32\u5230stdout\nprintf # printf\u53ef\u4ee5\u683c\u5f0f\u5316\u8f93\u51fa\ntest # test\u547d\u4ee4\u53ef\u4ee5\u7528\u6765\u6d4b\u8bd5\u6761\u4ef6\uff0c\u8fd4\u56de0\u8868\u793a\u771f\uff0c\u975e0\u8868\u793a\u5047\n<\/code><\/pre>\n<p>\u5173\u952e\u5b57<\/p>\n<pre><code>function # \u5b9a\u4e49\u51fd\u6570\n<\/code><\/pre>\n<h2 id=\"shell\u8fd0\u7b97\u7b26\u548c\u4f18\u5148\u7ea7\">shell\u8fd0\u7b97\u7b26\u548c\u4f18\u5148\u7ea7<\/h2>\n<p>\u539f\u751fshell\u4e0d\u652f\u6301\u6570\u5b66\u8fd0\u7b97\uff0c\u53ef\u4ee5\u901a\u8fc7expr\u6765\u5b9e\u73b0\uff0e<\/p>\n<pre><code># expr\u8868\u8fbe\u5f0f\u5185\u90e8\u8fd0\u7b97\u7b26\u524d\u540e\u8981\u7a7a\u683c.\nval=`expr 2 + 2`\n<\/code><\/pre>\n<p>\u7b97\u672f\u8fd0\u7b97\u7b26<\/p>\n<pre><code>+\n-\n* # `expr $a \\* $b`, \u4e0d\u8981\u8f6c\u4e49\n\/\n%\n= # a=$b\n== # [ $a == $b ] , \u9700\u8981\u4e2d\u62ec\u53f7\uff0c\u9700\u8981\u7a7a\u683c\n!= # [ $a != $b ], \u540c\u4e0a\n<\/code><\/pre>\n<p>\u5173\u7cfb\u8fd0\u7b97\u7b26<\/p>\n<pre><code># \u53ea\u652f\u6301\u6570\u5b57\uff0c\u4e0d\u652f\u6301\u5b57\u7b26\u4e32\uff0e\u9700\u8981\u4e2d\u62ec\u53f7\u548c\u7a7a\u683c\n-eq\n-ne\n-gt\n-lt\n-ge\n-le\n<\/code><\/pre>\n<p>\u5e03\u5c14\u8fd0\u7b97\u7b26<\/p>\n<pre><code># \u7b26\u5408\u77ed\u8def\u548c\u65b7\u8def\u539f\u5219\n! # [ !false ]\n-o # [ exp1 -o exp2 ], \u6709\u4e00\u4e2a\u4e3atrue\u5c31\u8fd4\u56detrue\n-a # [ exp1 -a exp2], \u4e24\u4e2a\u90fd\u662ftrue\u624d\u8fd4\u56detrue\n<\/code><\/pre>\n<p>\u903b\u8f91\u8fd0\u7b97<\/p>\n<pre><code>||\n&amp;&amp;\n<\/code><\/pre>\n<p>\u5b57\u7b26\u4e32\u8fd0\u7b97\u7b26<\/p>\n<pre><code>=\n!=\n-Z # \u5b57\u7b26\u4e32\u957f\u5ea6\u4e3a0\u8fd4\u56detrue\n-n # \u5b57\u7b26\u4e32\u957f\u5ea6\u4e3a0\u8fd4\u56defalse\nstr # [ $a ], \u5b57\u7b26\u4e32\u4e0d\u4e3a\u7a7a\u8fd4\u56detrue\n<\/code><\/pre>\n<p>\u6587\u4ef6\u6d4b\u8bd5\u8fd0\u7b97\u7b26<\/p>\n<pre><code>-b\n-c\n-d\n-f\n-g\n-k\n-p\n-u\n-r\n-w\n-x\n-s\n-e\n<\/code><\/pre>\n<h2 id=\"shell\u6570\u636e\u7ed3\u6784\u548c\u53d8\u91cf\">shell\u6570\u636e\u7ed3\u6784\u548c\u53d8\u91cf<\/h2>\n<p>\u53d8\u91cf\u7c7b\u578b\uff1a<\/p>\n<pre><code>\u5c40\u90e8\u53d8\u91cf\n\u73af\u5883\u53d8\u91cf\nshell\u53d8\u91cf\n<\/code><\/pre>\n<p>\u5b9a\u4e49\u53d8\u91cf:<\/p>\n<pre><code>\u7b49\u53f7\u524d\u540e\u4e0d\u80fd\u6709\u7a7a\u683c\n\u4e0d\u80fd\u7528\u6570\u5b57\u5f00\u5934\u547d\u540d\u53d8\u91cf\n\u4e0d\u80fd\u7528\u6807\u70b9\u7b26\u53f7\u548c\u5173\u952e\u5b57\nvar=`ls \/etc` # \u8fd4\u56de\u7684\u662fstdout+stderr\nvar=$(ls \/etc) # \u8fd4\u56de\u7684\u662fstdou+stderr\n<\/code><\/pre>\n<p>\u4f7f\u7528\u53d8\u91cf\uff1a<\/p>\n<pre><code>$var\n${var}\n# \u4f7f\u7528\u53cc\u5f15\u53f7\nvar1=&quot;pre${var}suf\nvar2=&quot;$var&quot;\n<\/code><\/pre>\n<p>\u53ea\u8bfb\u53d8\u91cf:<\/p>\n<pre><code>\u4f7f\u7528readonly\u5b9a\u4e49\u53ea\u8bfb\u53d8\u91cf\uff0c\u4e0d\u80fd\u518d\u91cd\u65b0\u8d4b\u503c\nvar=value\nreadonly var\n<\/code><\/pre>\n<p>\u5220\u9664\u53d8\u91cf:<\/p>\n<pre><code>\u4f7f\u7528unset\u5220\u9664\u53d8\u91cf\uff0c\u88ab\u5220\u9664\u7684\u53d8\u91cf\u4e0d\u80fd\u4f7f\u7528.\nvar=value\nunset var\n<\/code><\/pre>\n<p>\u53d8\u91cf\u64cd\u4f5c\uff1a<\/p>\n<pre><code>${var\/old\/new} # \u5c06\u53d8\u91cf\u4e2d\u7684old\u66ff\u6362\u6210new.\n${var:start:end} # \u83b7\u53d6\u53d8\u91cf\u7684start\u5230end\u4e2a\u5b57\u7b26\uff0c\u76f8\u5f53\u4e8evar[start:end],\u4e0b\u6807\u4ece0\u5f00\u59cb.\n<\/code><\/pre>\n<p>\u5b57\u7b26\u4e32\u7c7b\u578b\uff1a<\/p>\n<pre><code>\u5355\u5f15\u53f7\u7684\u5b57\u7b26\u4e32\u662f\u539f\u6837\u8f93\u51fa\uff0c\u5176\u4e2d\u7684\u53d8\u91cf\u662f\u65e0\u6548\u7684\uff0c\u91cc\u9762\u4e0d\u80fd\u6709\u5355\u5f15\u53f7.\nvar='this is string'\n\u53cc\u5f15\u53f7\u7684\u5b57\u7b26\u4e32\u91cc\u9762\u53ef\u4ee5\u6709\u53d8\u91cf\uff0c\u53ef\u4ee5\u51fa\u73b0\u8f6c\u4e49\u5b57\u7b26.\nvar=&quot;this is string&quot;\n&quot;outer \\&quot;inner string\\&quot; string&quot;\n\u83b7\u53d6\u5b57\u7b26\u4e32\u957f\u5ea6\nvar=&quot;this is tring&quot;\necho ${#var}\n\u5b57\u7b26\u4e32\u5207\u7247\nvar=&quot;this is string&quot;\n${var:start:end} # \u76f8\u5f53\u4e8evar[start:end], \u4e0b\u6807\u4ece0\u5f00\u59cb\n\u83b7\u53d6pattern\u5728string\u4e2d\u7684\u8d77\u59cb\u4e0b\u6807\nstring=&quot;this is string&quot;\n`expr index &quot;$string&quot; pattern`\n<\/code><\/pre>\n<p>\u6570\u5b57\u7c7b\u578b\uff1a<\/p>\n<p>\u6570\u7ec4:<\/p>\n<h2 id=\"shell\u63a7\u5236\u6d41\">shell\u63a7\u5236\u6d41<\/h2>\n<pre><code># [[ \u91cc\u9762\u4e0d\u80fd\u7528 -o\/-a ]]\nif [[ $status1 -eq 0 ]] || [[ $status2 -eq 0 ]]\nif [[ $status1 -eq 0 ]] &amp;&amp; [[ $status2 -eq 0 ]]\n# [ \u5355\u5c42\u53ef\u4ee5\u7528-o\/-a ]\nif [ $status1 -eq 0 -o $status2 -eq 0 ]\n<\/code><\/pre>\n<p>if<\/p>\n<pre><code>if []; then command; ...; fi\nif condition\nthen\ncommand\nfi\n[]\/test \u4e2d\u5fc5\u987b\u4e3a\u6267\u884c\u7684\u547d\u4ee4\u7684stdout+stderr.\nif [ ! `cat file | grep pattern | wc -l` ]\nif [ ! 0 ] \u6b64\u65f60\u4e3a\u771f, [ ! 0 ]\u4e3a\u5047\nif command \u770b\u8fd4\u56de\u7801$?, 0\u8868\u793a\u771f,\u5176\u5b83\u8868\u793a\u5047.\n<\/code><\/pre>\n<p>if-else<\/p>\n<pre><code>if condition; then command; ...; else command; fi\nif condition\nthen\ncommand\nelse\ncommand\nfi\n<\/code><\/pre>\n<p>if-elif-else<\/p>\n<pre><code>if condition; then command; ...; elif condition; then command; ...; else command; fi\nif condition\nthen\ncommand\nelif condition\nthen\ncommand\nelse\ncommand\nfi\n<\/code><\/pre>\n<p>while<\/p>\n<pre><code>while condition; do command;...; done\nwhile condition\ndo\ncommand\ndone\n# \u65e0\u9650\u5faa\u73af\nwhile :\ndo\ncommand\ndone\n# \u65e0\u9650\u5faa\u73af\nwhile true\ndo\ncommand\ndone\n<\/code><\/pre>\n<p>for<\/p>\n<pre><code>for ((i=1; i&lt;=100; i++))\nfor i in {1..100}\nfor i in `seq 1 100`\nfor VAR in ${1,2,3,...}; do command; ...; done\nfor var in item1 item2 ... itemN\ndo\ncommand\ndone\n# \u65e0\u9650\u5faa\u73af\nfor (( ; ; ))\n<\/code><\/pre>\n<p>until<\/p>\n<pre><code>until condition; do command; ...; done\nuntil condition\ndo\ncommand\ndone\n<\/code><\/pre>\n<p>case<\/p>\n<pre><code>case $VAR in\nval1)\ncommand\n...\n;;\nval2)\ncommand\n...\n;;\nesac\n<\/code><\/pre>\n<p>break<\/p>\n<p>continue<\/p>\n<h2 id=\"shell\u51fd\u6570\">shell\u51fd\u6570<\/h2>\n<p>return\u53ea\u662f\u8fd4\u56de\u5f53\u524d\u51fd\u6570\uff0c\u4e0d\u9000\u51fa\u4e3b\u7a0b\u5e8f<\/p>\n<p>exit\u76f4\u63a5\u9000\u51fa\u4e3b\u7a0b\u5e8f<\/p>\n<p>\u901a\u8fc7\u5173\u952e\u5b57function\u5b9a\u4e49\u51fd\u6570:<\/p>\n<pre><code>function Name { \/\/ ()\u53ef\u7701\u7565\nfunction Name() {\n...\n# \u5982\u679c\u4e0d\u663e\u793a\u8c03\u7528return\u8fd4\u56de\uff0c\u5219\u51fd\u6570\u8fd4\u56de\u6700\u540e\u4e00\u6761\u547d\u4ee4\u7684\u7ed3\u679c\nreturn $?\n}\n<\/code><\/pre>\n<p>\u4e5f\u53ef\u4ee5\u76f4\u63a5\u5b9a\u4e49\u51fd\u6570:<\/p>\n<pre><code>Name() {\n...\n}\n<\/code><\/pre>\n<p>\u51fd\u6570\u8fd4\u56de\u7801:<\/p>\n<pre><code>$? # \u83b7\u53d6\u51fd\u6570\u7684\u8fd4\u56de\u7801, 0\u8868\u793a\u6210\u529f, \u975e0\u8868\u793a\u5931\u8d25.\n<\/code><\/pre>\n<p>\u51fd\u6570\u53c2\u6570\uff1a<\/p>\n<pre><code>$1 - $9 \u53ef\u4ee5\u5728\u51fd\u6570\u5185\u90e8\u83b7\u53d6\u8c03\u7528\u51fd\u6570\u65f6\u5019\u4f20\u9012\u8fdb\u6765\u7684\uff19\u4e2a\u53c2\u6570\n${10} - ${100} \u83b7\u53d6\u7b2c\u5341\u4e2a\u53c2\u6570\u548c\u540e\u9762\u7684\u53c2\u6570\n<\/code><\/pre>\n<p>\u7279\u6b8a\u5b57\u7b26\uff1a<\/p>\n<pre><code>$# \u8868\u793a\u4f20\u9012\u5230\u811a\u672c\u7684\u53c2\u6570\u4e2a\u6570,\u4e0d\u5305\u62ec\u7a0b\u5e8f\u672c\u8eab\n$* \u4f20\u5165\u6240\u6709\u53c2\u6570\n$@ \u4f20\u5165\u6240\u6709\u53c2\u6570\n$$ \u5f53\u524d\u811a\u672c\u7684\u8fdb\u7a0bID\n$! \u4e0a\u4e00\u4e2a\u540e\u53f0\u8fd0\u884c\u7684\u8fdb\u7a0bID\n$- \u5f53\u524dshell\u7684\u9009\u9879\n<\/code><\/pre>\n<h2 id=\"\u8f93\u5165\u8f93\u51fa\u548c\u91cd\u5b9a\u5411\">\u8f93\u5165\u8f93\u51fa\u548c\u91cd\u5b9a\u5411<\/h2>\n<p>stdout\u548cstdin\u91cd\u5b9a\u5411\u5230\u4e00\u4e2a\u5730\u65b9:<\/p>\n<pre><code>1&gt; \u53ea\u91cd\u5b9a\u5411stdout\n2&gt; \u53ea\u91cd\u5b9a\u5411stderr\n2&gt;&amp;1 \u540c\u65f6\u91cd\u5b9a\u5411stdout+stderr\nmain &gt; 2&gt;&amp;1 log1.log | tee log2.log # \u540c\u65f6\u91cd\u5b9a\u5411\u5230\u4e24\u4e2a\u6587\u4ef6\nmain 2&gt;&amp;1 | tee ${LOG} # \u540c\u65f6\u5c06stdout\u548cstderr\u8f93\u51fa\u5230\u7ec8\u7aef\u548c\u65e5\u5fd7\u6587\u4ef6.\n<\/code><\/pre>\n<h2 id=\"debug\">debug<\/h2>\n<p>\u7528set<\/p>\n<pre><code>set -e \u547d\u4ee4\u5931\u8d25\u7acb\u5373\u9000\u51fa\nset -x \u6267\u884c\u524d\u6253\u5370\u6bcf\u884c\u547d\u4ee4\nset -u \u672a\u5b9a\u4e49\u7684\u53d8\u91cf\u4f1a\u62a5\u9519\nset -o pipefail \u5bf9\u4e8e\u6709\u7ba1\u9053\u7684\u64cd\u4f5c\uff0c\u8fd4\u56de\u6700\u540e\u4e00\u4e2a\u975e\u96f6\u8fd4\u56de\u503c\u7684\u547d\u4ee4\u7684\u8fd4\u56de\u7801.\nset +e \u53d6\u6d88\u524d\u9762\u8bbe\u7f6e\u7684-e\n<\/code><\/pre>"},{"title":"Coreutils","link":"https:\/\/canuxcheng.com\/post\/shell_coreutils\/","pubDate":"Thu, 31 Mar 2016 21:51:25 +0000","guid":"https:\/\/canuxcheng.com\/post\/shell_coreutils\/","description":"<h1 id=\"linux\u7684\u5916\u90e8\u547d\u4ee4\">Linux\u7684\u5916\u90e8\u547d\u4ee4<\/h1>\n<p>Linux\u5916\u90e8\u547d\u4ee4\u7684\u9879\u76ee\u662fcoreutils\u3002<\/p>\n<p>\u5916\u90e8\u547d\u4ee4\u5728coreutils\u76ee\u5f55\u4e2d<\/p>\n<p>\u67e5\u770b\u5916\u90e8\u547d\u4ee4\u6240\u5728\u76ee\u5f55\uff1a<\/p>\n<pre><code>echo $PATH\n<\/code><\/pre>\n<p>\u5916\u90e8\u547d\u4ee4\u5728\u4e0b\u5217\u76ee\u5f55\u4e2d\uff1a<\/p>\n<pre><code>~\/bin # \u7528\u6237\u81ea\u5b9a\u4e49\n\/sbin\n\/bin\n\/usr\/sbin\n\/usr\/bin\n\/usr\/local\/sbin\n\/usr\/local\/bin\n\/usr\/games\n\/usr\/local\/games\n<\/code><\/pre>\n<p>\u67e5\u770b\u5916\u90e8\u547d\u4ee4\u624b\u518c\u7684\u5728\u7ebf\u624b\u518c\uff1a<\/p>\n<pre><code>man [command]\ninfo [command]\n<\/code><\/pre>\n<p>\u81ea\u5b9a\u4e49\u5916\u90e8\u547d\u4ee4\uff1a<\/p>\n<p>\u6dfb\u52a0$PATH\u53d8\u91cf\uff0c\u7136\u540e\u653e\u5230\u8be5\u76ee\u5f55\u3002<\/p>\n<hr>\n<h1 id=\"\u7cfb\u7edf\u7ba1\u7406\">\u7cfb\u7edf\u7ba1\u7406<\/h1>\n<p>cpu\/mem\/load<\/p>\n<pre><code># \u67e5\u770bcpu\/mem\/swap\/system\u4fe1\u606f\nvmstat\nvmstat 1\n# \u67e5\u770b\u8fdb\u7a0b\u6d88\u8017\u7684cpu\/mem\/swap\/system\u7b49\u7cfb\u7edf\u4fe1\u606f\ntop\ntop -H # \u67e5\u770b\u7ebf\u7a0b\n%cpu = cputime\/realtime * 100%\ncpu_usage = %cpu\/cpu-number\n%mem = RES\/physicalMem * 100%\nhtop\n$ sudo apt-get install htop\n$ sudo apt-get install sysstat (\u5305\u62ecpidstat)\npidstat -u -p pid \/\/ cpu\npidstat -r -p pid \/\/mem\n<\/code><\/pre>\n<p>cpu\/load:<\/p>\n<pre><code>$ sudo apt-get install sysstat (\u5305\u62ecmpstat)\nmpstat -P ALL 1 5 \/\/ cpu\nuptime\nlscpu # \u663e\u793acpu\u67b6\u6784\u7684\u4fe1\u606f\ncat \/proc\/cpuinfo # \u67e5\u770bcpu\u4fe1\u606f\ncat \/proc\/cpuinfo | grep &quot;processor&quot; | wc -l # \u903b\u8f91cpu\u603b\u6570\ncat \/proc\/cpuinfo | grep &quot;physical id&quot; | sort | uniq | wc -l # \u7269\u7406cpu\u4e2a\u6570\ncat \/proc\/cpuinfo | grep &quot;cpu cores&quot; | uniq # \u7269\u7406cpu\u6838\u6570\ncat \/proc\/cpuinfo | grep -e &quot;cpu cores&quot;\u00a0 -e &quot;siblings&quot; | sort | uniq # \u548ccpu cores\u4e00\u6837\u8bf4\u660e\u6ca1\u6709\u542f\u7528\u8d85\u7ebf\u7a0b.\nprocessor: \u903b\u8f91cpu\u603b\u6570=\u7269\u7406cpu\u4e2a\u6570*\u7269\u7406cpu\u6838\u6570\uff08\u975e\u8d85\u7ebf\u7a0b\uff09\uff0c \u7269\u7406cpu\u4e2a\u6570*\u7269\u7406cpu\u6838\u6570*2\uff08\u8d85\u7ebf\u7a0bcpu).\nphysical id :\u7269\u7406cpu\u4e2a\u6570(\u6bcf\u4e2asocket\/\u63d2\u69fd\u53ef\u4ee5\u653e\u4e00\u4e2a\u7269\u7406cpu).\ncpu cores: \u7269\u7406cpu\u6709\u51e0\u4e2a\u6838(\u5982\u679c\u662f\u8d85\u7ebf\u7a0b\u6280\u672f\u7684cpu,\u6bcf\u4e2a\u6838\u53ef\u4ee5\u8fd0\u884c\u4e24\u4e2a\u7ebf\u7a0b\uff0c\u6216\u8005\u8bf4\u6bcf\u4e2a\u6838\u5bf9\u5e94\u4e24\u4e2a\u903b\u8f91cpu\uff09\u3002\nsiblings\uff1a \u6bcf\u4e2a\u7269\u7406cpu\u5355\u4e2a\u6838\u5fc3\u4e0a\u7684\u903b\u8f91cpu\u4e2a\u6570\nstrace\nstrace -c -p pid\nstrace -T -e epoll_wait -p pid\ndmesg\n<\/code><\/pre>\n<p>mem:<\/p>\n<pre><code>free\nfree -m\ncat \/proc\/meminfo # \u67e5\u770b\u5185\u5b58\u4fe1\u606f\npmap\npmap -d pid\n<\/code><\/pre>\n<p>system:<\/p>\n<pre><code>uname # \u6253\u5370linux\u7cfb\u7edf\u4fe1\u606f\n$ uname -a\ncat \/etc\/issue\ncat \/proc\/version\nlsb_release # \u67e5\u770b\u53d1\u884c\u7248\u672c\u4fe1\u606f\n$ lsb_release -a\ngetconf # \u67e5\u8be2\u7cfb\u7edf\u914d\u7f6e\u7684\u53d8\u91cf\uff0cLONG_BIT\u8868\u793a\u7cfb\u7edf\u4f4d\u6570\n<\/code><\/pre>\n<p>process:<\/p>\n<pre><code>ps\n# \u683c\u5f0f\u5316\u8f93\u51fa\uff0c\u9017\u53f7\u540e\u9762\u4e0d\u80fd\u6709\u7a7a\u683c\nps -eo\/-Ao %cpu\/pcpu,%mem\/pmem,stat,start\/start_time\/lstart,pid,ppid,cmd\/args\/command\nps --ppid 1 -o pid,command | grep -v grep | grep daemon # \u83b7\u53d6\u591a\u8fdb\u7a0b\u7a0b\u5e8f\u4e3b\u8fdb\u7a0b\u7684pid\npstree -a\npkill\npkill -f &lt;pattern&gt; # \u6740\u6b7bargs\u5339\u914d\u7684\u8fdb\u7a0b\npgrep -P pid\n# \u5185\u6838\u4e5f\u6709\u4e00\u4e2akill\u547d\u4ee4\nkill\nkillall\nkillall -e &lt;deamon&gt; # \u6740\u6b7b\u5339\u914d\u7684\u5b88\u62a4\u8fdb\u7a0b.\n<\/code><\/pre>\n<p>crontab:<\/p>\n<pre><code>$ sudo apt-get install cron\n# \/etc\/crontab \u8bbe\u7f6e\u4e86\u73af\u5883\u53d8\u91cf\ncrontab\ncrontab -l # \u5217\u51fa\ncrontab -e # \u7f16\u8f91\ncrontab -u &lt;user&gt; file # \u5bfc\u5165\u914d\u7f6e\/etc\/cron.d\/my-cron-file\n<\/code><\/pre>\n<p>editor:<\/p>\n<pre><code># \u4fee\u6539\u9ed8\u8ba4\u7f16\u8f91\u5668nano\nselect-editor\n<\/code><\/pre>\n<p>\u65f6\u533a\u7ba1\u7406<\/p>\n<pre><code>timedatectl list-timezones # \u67e5\u770b\u6240\u6709\u65f6\u533a\nsudo timedatectl set-timezone Asia\/Shanghai # \u8bbe\u7f6e\u65f6\u533a\nls -l \/etc\/localtime # \u5e94\u8be5\u662f\u4e00\u4e2a\u94fe\u63a5\n<\/code><\/pre>\n<p>update-alternatives:<\/p>\n<pre><code>update-alternatives --display python \/\/ \u67e5\u770b\u5019\u9009\u9879\nupdate-alternatives --config python \/\/ \u9009\u62e9\u5019\u9009\u9879\nupdate-alternatives --set python \/usr\/bin\/python \/\/ \u6dfb\u52a0\u5019\u9009\u9879\nupdate-alternatives --install \/usr\/bin\/python python \/usr\/bin\/python3.7 1 \/\/ \u8bbe\u7f6e\u5019\u9009\u9879\u7684link\nupdate-alternatives --remove python \/usr\/bin\/python3.5 \/\/ \u5220\u9664\u5019\u9009\u9879\u7684link\n<\/code><\/pre>\n<h1 id=\"\u7528\u6237\u548c\u6743\u9650\u7ba1\u7406\">\u7528\u6237\u548c\u6743\u9650\u7ba1\u7406<\/h1>\n<pre><code>id\nid -u \u6253\u5370\u5f53\u524d\u7528\u6237uid(root uid=0)\n<\/code><\/pre>\n<p>chmod:<\/p>\n<pre><code># \u5f53\u6587\u4ef6\u7684owner\u7684x\u4f4d\u7f6e\u4e3as,\u8868\u793a\u8bbe\u7f6e\u4e86SUID, \u4ec5\u5bf9\u4e8c\u8fdb\u5236\u53ef\u6267\u884c\u6587\u4ef6\u6709\u6548.\n# \u5982\u679c\u6267\u884c\u8005\u5bf9\u8be5\u6587\u4ef6\u6709\u53ef\u6267\u884c\u6743\u9650\uff0c\u90a3\u4e48\u6267\u884c\u8005\u5728\u6267\u884c\u8be5\u6587\u4ef6\u671f\u95f4\uff0c\u5c31\u62e5\u6709\u4e86\u8be5\u6587\u4ef6\u7684owner\u7684\u6743\u9650.\n-rwsr-xr-x file\nchmod u+s &lt;file&gt; # \u52a0SUID\nchmod 4777 &lt;file&gt;\n-rwxr-sr-x file\/dir\nchmod g+s &lt;file&gt;\/&lt;dir&gt; # \u52a0SGID\nchmod 2777 &lt;dir&gt;\ndrwxrwxrwt dir\nchmod o+t &lt;dir&gt; # \u52a0SBIT\nchmod 1777 &lt;dir&gt;\nchown\nchgrp\nchattr\n<\/code><\/pre>\n<p>usermod<\/p>\n<pre><code># \u7981\u6b62root\u767b\u5f55\nusermod --shell \/sbin\/nologin root\n<\/code><\/pre>\n<p>adduser:<\/p>\n<pre><code>adduser\naddgroup\n<\/code><\/pre>\n<p>useradd:<\/p>\n<pre><code>useradd\nuseradd -r -m -U -G sudo -s \/bin\/bash &lt;user&gt;\n-U, --user-group create a group with the same name as the user\n-m, --create-home create the user's home directory\n-s, --shell SHELL login shell of the new account\n-r, --system create a system account\n-G, --groups GROUPS list of supplementary groups of the new account\nuserdel\nusermod\nusermod -G g1,g2 -a user \/\/ \u5c06\u7528\u6237\u8ffd\u52a0\u5230\u7ec4\nusers # \u67e5\u770b\u5f53\u524d\u767b\u9646\u7684\u7528\u6237\ngroupadd\ngroupdel\ngroupmod\ngroups # \u67e5\u770b\u6307\u5b9a\u7528\u6237\u6240\u5c5e\u7684\u7ec4\uff0c\u9ed8\u8ba4\u5f53\u524d\u7528\u6237\u7684\u7ec4\n<\/code><\/pre>\n<p>gpasswd:<\/p>\n<pre><code>$ gpasswd -d &lt;user&gt; &lt;group&gt; \/\/ \u4ece\u7ec4\u91cc\u5220\u9664\u7528\u6237\n<\/code><\/pre>\n<p>chpasswd:<\/p>\n<pre><code>echo &quot;username:password&quot; | chpasswd # \u4fee\u6539username\u7684\u5bc6\u7801\n<\/code><\/pre>\n<p>passwd<\/p>\n<pre><code>passwd\n<\/code><\/pre>\n<p>su:<\/p>\n<pre><code>su &lt;user&gt; -c &lt;command&gt;\n<\/code><\/pre>\n<p>sudo:<\/p>\n<pre><code>sudo -i\n<\/code><\/pre>\n<h1 id=\"\u6587\u4ef6\u548c\u76ee\u5f55\u7ba1\u7406\">\u6587\u4ef6\u548c\u76ee\u5f55\u7ba1\u7406<\/h1>\n<pre><code>mkdir\ntree\ncat\ncol\ncolrm\ncomm\ncsplit\ned\nex\nfmt\nfold\njoin\nlook\nmtype\npico\nsort\ntr\nexpr\nuniq\nwc\ncksum\ncmp\ndiff\ndiffstat\nfile\ncut\nless\nmore\nlocate\nlsattr\nmattrib\nmdel\nmdir\nmktemp\nmmove\nmren\nmtools\nmtoolstest\nmv\nod\npaste\npatch\nrcp\nrm\nsplit\ntouch\numask\nwhich\ncp\nwhereis\nmcopy\nmshowfat\nlprm\nlpr\nlpq\nrev\ntoilet\naafire\nxeyes\npv\nyes\ncal\nfactor\n<\/code><\/pre>\n<p>typeset<\/p>\n<pre><code>typeset -u VAR \/\/ \u53d8\u91cf\u5927\u5199\nVAR='test'\necho $VAR # TEST\ntypeset -l VAR \/\/ \u53d8\u91cf\u5c0f\u5199\n<\/code><\/pre>\n<p>tee<\/p>\n<pre><code>main &gt; 2&gt;&amp;1 log1.log | tee log2.log # \u540c\u65f6\u91cd\u5b9a\u5411\u5230\u4e24\u4e2a\u6587\u4ef6\nmain 2&gt;&amp;1 | tee ${LOG} # \u540c\u65f6\u5c06stdout\u548cstderr\u8f93\u51fa\u5230\u7ec8\u7aef\u548c\u65e5\u5fd7\u6587\u4ef6.\n$ echo &quot;content&quot; | sudo tee filename # \u5199\u5165\u5230root\u6743\u9650\u7684\u6587\u4ef6\n$ echo &quot;text&quot; | sudo tee -a filename # append\n<\/code><\/pre>\n<p>lsof\u67e5\u770b\u6253\u5f00\u7684\u6587\u4ef6\u8d44\u6e90:<\/p>\n<pre><code>lsof #\nlsof -i # \u67e5\u770b\nsudo lsof -i :port # \u67e5\u770b\u7aef\u53e3\u662f\u5426\u88ab\u4f7f\u7528\n<\/code><\/pre>\n<p>readlink:<\/p>\n<pre><code>readlink \u83b7\u53d6\u7b26\u53f7\u8fde\u63a5\u4fe1\u606f\nsudo readlink \/proc\/1\/exe\n<\/code><\/pre>\n<p>ln:<\/p>\n<pre><code>ln TARGET LINK_NAME # \u521b\u5efa\u6587\u4ef6\u7684\u786c\u94fe\u63a5,\u76ee\u5f55\u4e0d\u80fd\u521b\u5efa\u786c\u94fe\u63a5\n-s, --symbolic\nln -s TARGET LINK_NAME # \u521b\u5efa\u6587\u4ef6\u6216\u76ee\u5f55\u7684\u8f6f\u94fe\u63a5\n<\/code><\/pre>\n<p>dirname:<\/p>\n<pre><code>dirname\ndirname $0 # \u83b7\u53d6\u5f53\u524d\u6587\u4ef6\u6240\u5728\u76ee\u5f55\u7684\u76f8\u5bf9\u8def\u5f84, \u4e5f\u5c31\u662f.\n$(cd $(dirname $0) &amp;&amp; pwd) # \u83b7\u53d6\u5f53\u524d\u6587\u4ef6\u6240\u5728\u76ee\u5f55\u7684\u7edd\u5bf9\u8def\u5f84\n<\/code><\/pre>\n<p>rsync:<\/p>\n<pre><code>rsync\nrsync [OPTION]... SRC [SRC]... DEST\nrsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST\nrsync [OPTION]... [USER@]HOST:SRC [DEST]\nrsync -rtvzuOPH --delete\n-e &quot;ssh -o StrictHostKeyChecking=no&quot;\n-v verbose\n-a archive == -rlptgoD\n-u --update # \u8df3\u8fc7\u76ee\u7684\u5730\u5740\u4e0amodification time\u66f4\u65b0\u7684\u6587\u4ef6\n--inplace\n--append\n--append-verify\n-r --recursive\n-z --compress\n--progress\n--partial\n-P == --partial --progress\n--devices\n--specials\n-D == --devices --specials\n-H --hard-links preserve hard-link\n-l --links copy symlinks as symlinks \u4fdd\u7559\u8f6f\u94fe\u63a5\n-L copy symlinks to dest \u590d\u5236\u539f\u59cb\u6587\u4ef6\n--delete \u4ecedest\u5220\u9664src\u6ca1\u6709\u7684\u6587\u4ef6\n-h --human-readable\n-g --group preserve group\n-o --owner preserve owner\n-p --perms preserve permissions\n-t --times preserve modification times\n-O, --omit-dir-times \u5ffd\u7565\u76ee\u5f55\u7684modification times.\n--exclude \u6392\u9664\u6587\u4ef6\n<\/code><\/pre>\n<p>\u8ba1\u7b97\u6587\u4ef6\u7a7a\u95f4\u4f7f\u7528:<\/p>\n<pre><code>du\n$ du -sh\n<\/code><\/pre>\n<p>\u56db\u4e2a\u7528\u5230\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u91cd\u8981\u547d\u4ee4\uff1a<\/p>\n<pre><code>sed\nawk\ngrep\/ack\/ag\nfind\n<\/code><\/pre>\n<h1 id=\"\u538b\u7f29\u5907\u4efd\">\u538b\u7f29\u5907\u4efd<\/h1>\n<p>tar(.tar)<\/p>\n<pre><code>tar\n-c, --create # \u521b\u5efa\u5f52\u6863\n-u, --update # \u66f4\u65b0\u5f52\u6863\u6587\u4ef6\n-x, --extract, --get # \u63d0\u53d6\u5f52\u6863\ntar cvf name.tar folder\ntar xvf name.tar\ncompression options:\n-j, --bzip2\n-J, --xz\n-z, --gzip, --gunzip, --ungzip\n-Z, --compress, --uncompress\ndevice selection and switching:\n-f, --file=ARCHIVE\ninformative output:\n-v, --verbose\n<\/code><\/pre>\n<p>gzip(.gz)<\/p>\n<pre><code>gzip\ngunzip\ntar zxvf file.tar.gz\ntar zcvf file.tar.gz dir\n<\/code><\/pre>\n<p>bzip2(.bz2)<\/p>\n<pre><code>bzip2\nbunzip2\ntar jxvf file.tar.bz2\ntar jcvf file.tar.bz2 dir\n<\/code><\/pre>\n<p>compress(.z)<\/p>\n<pre><code>compress\nuncompress\ntar Zxvf file.tar.z\n<\/code><\/pre>\n<p>xz(.xz)<\/p>\n<pre><code>xz\nunxz\ntar Jxvf file.tar.xz\n<\/code><\/pre>\n<p>gzip\/gunzip<\/p>\n<pre><code>gunzip name.gz\ngzip -d name.gz\n<\/code><\/pre>\n<p>zip(.zip)<\/p>\n<pre><code>zip\nunzip\n<\/code><\/pre>\n<p>7z(.7z)<\/p>\n<pre><code>$ sudo apt-get install p7zip\/p7zip-full\/p7zip-rar\n7z\n<\/code><\/pre>\n<h1 id=\"\u6570\u636e\u5904\u7406\">\u6570\u636e\u5904\u7406<\/h1>\n<p>base64<\/p>\n<pre><code>\/\/ \u751f\u6210basic authentication.\necho -n &quot;user:pw&quot; | base64\n<\/code><\/pre>"},{"title":"Utils","link":"https:\/\/canuxcheng.com\/post\/shell_utils\/","pubDate":"Thu, 31 Mar 2016 21:51:25 +0000","guid":"https:\/\/canuxcheng.com\/post\/shell_utils\/","description":"<h1 id=\"linux\u7684\u7b2c\u4e09\u65b9\u547d\u4ee4\">Linux\u7684\u7b2c\u4e09\u65b9\u547d\u4ee4<\/h1>\n<p>Linux\u5916\u90e8\u547d\u4ee4\u7684\u9879\u76ee\u662fcoreutils.<\/p>\n<p>\u5916\u90e8\u547d\u4ee4\u5728coreutils\u76ee\u5f55\u4e2d.<\/p>\n<p>\u7b2c\u4e09\u65b9\u547d\u4ee4(\u76f8\u5f53\u4e8e\u5916\u90e8\u547d\u4ee4)\uff0e<\/p>\n<hr>\n<h1 id=\"\u6587\u4ef6\u548c\u76ee\u5f55\u7ba1\u7406\">\u6587\u4ef6\u548c\u76ee\u5f55\u7ba1\u7406<\/h1>\n<p>autojump:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/wting\/autojump\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/wting\/autojump<\/a><\/p>\n<p>fasd:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/clvv\/fasd\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/clvv\/fasd<\/a><\/p>\n<p>fzf:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/junegunn\/fzf\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/junegunn\/fzf<\/a><\/p>\n<h1 id=\"\u538b\u7f29\u5907\u4efd\">\u538b\u7f29\u5907\u4efd<\/h1>\n<h1 id=\"\u78c1\u76d8\u7ba1\u7406\">\u78c1\u76d8\u7ba1\u7406<\/h1>\n<h1 id=\"\u8bbe\u5907\u7ba1\u7406\">\u8bbe\u5907\u7ba1\u7406<\/h1>\n<hr>"},{"title":"Builtins","link":"https:\/\/canuxcheng.com\/post\/shell_builtins\/","pubDate":"Thu, 31 Mar 2016 21:51:03 +0000","guid":"https:\/\/canuxcheng.com\/post\/shell_builtins\/","description":"<h1 id=\"linux\u5185\u7f6e\u547d\u4ee4\">Linux\u5185\u7f6e\u547d\u4ee4<\/h1>\n<p>\u5185\u7f6e\u547d\u4ee4\u5728bash\/builtins\u76ee\u5f55\u4e2d<\/p>\n<p>shell\u547d\u4ee4\u5206\u4e3a\u5185\u7f6e\u547d\u4ee4\u548c\u5916\u90e8\u547d\u4ee4.<\/p>\n<p>\u67e5\u770b\u4e00\u4e2a\u547d\u4ee4\u662f\u5185\u7f6e\u547d\u4ee4\u8fd8\u662f\u5916\u90e8\u547d\u4ee4\uff1a<\/p>\n<pre><code>type -a [command]\n\u63d0\u793a&quot;[command] is a shell builtin&quot;\u5c31\u8868\u793a\u662f\u5185\u7f6e\u547d\u4ee4\uff0c\u5426\u5219\u5c31\u662f\u5916\u90e8\u547d\u4ee4\u3002\n<\/code><\/pre>\n<p>\u67e5\u770b\u6240\u6709\u5185\u7f6e\u547d\u4ee4\uff1a<\/p>\n<pre><code>help\nenable -a\n<\/code><\/pre>\n<p>\u67e5\u770b\u5185\u7f6e\u547d\u4ee4\u7684\u5e2e\u52a9\uff1a<\/p>\n<pre><code>help [command]\n<\/code><\/pre>\n<hr>\n<pre><code>type\nenable\nhelp\ncaller\nalias\nbg\nbind\nbreak\nbuiltin\ncommand\ncompgen\ncomplete\ncompopt\ncontinue\ndeclare\ndisown\nlet\nlocal\nlogout\nmapfile\npopd\nprintf\npushd\nread\nreadarray\nreadonly\nreturn\nshift\nshopt\nsource\nsuspend\ntimes\ntrap\ntrue\ntypeset\nulimit\numask\nunalias\nunset\nwait\neval\nexec\nexit\nexport\nfalse\nfc\nfg\ngetopts\nhash\nhistory\njobs\n<\/code><\/pre>\n<p>\u8def\u5f84\u76f8\u5173:<\/p>\n<pre><code>cd\ndirs\npwd\n<\/code><\/pre>\n<p>test:<\/p>\n<pre><code>test\n<\/code><\/pre>\n<p>set:<\/p>\n<pre><code>set\nset -e \u547d\u4ee4\u5931\u8d25\u7acb\u5373\u9000\u51fa\nset -x \u6267\u884c\u524d\u6253\u5370\u6bcf\u884c\u547d\u4ee4\nset -u \u672a\u5b9a\u4e49\u7684\u53d8\u91cf\u4f1a\u62a5\u9519\nset -o pipefail \u5bf9\u4e8e\u6709\u7ba1\u9053\u7684\u64cd\u4f5c\uff0c\u8fd4\u56de\u6700\u540e\u4e00\u4e2a\u975e\u96f6\u8fd4\u56de\u503c\u7684\u547d\u4ee4\u7684\u8fd4\u56de\u7801.\nset +e \u53d6\u6d88\u524d\u9762\u8bbe\u7f6e\u7684-e\n<\/code><\/pre>\n<p>echo:<\/p>\n<pre><code>echo\necho 'origin' # \u4e0d\u6253\u5370\u53d8\u91cf\necho &quot;_${VAR}_&quot; # \u67e5\u770b\u53d8\u91cf\u524d\u540e\u662f\u5426\u6709\u7a7a\u683c.\n<\/code><\/pre>\n<p>kill:<\/p>\n<pre><code>kill\n# \u67e5\u770b\u6240\u6709\u4fe1\u53f7\nkill -l\n<\/code><\/pre>"},{"title":"FileSystem","link":"https:\/\/canuxcheng.com\/post\/linux_filesystem\/","pubDate":"Thu, 31 Mar 2016 21:48:59 +0000","guid":"https:\/\/canuxcheng.com\/post\/linux_filesystem\/","description":"<h1 id=\"vfs\">VFS<\/h1>\n<p>Linux\u91c7\u7528\u865a\u62df\u6587\u4ef6\u7cfb\u7edf\uff0c\u652f\u6301\u591a\u4e2a\u6587\u4ef6\u7cfb\u7edf\u534f\u8bae\uff0e<\/p>\n<hr>\n<h1 id=\"extext2ext3ext4\">ext\/ext2\/ext3\/ext4<\/h1>\n<h1 id=\"jfs2\">JFS2<\/h1>\n<h1 id=\"ramfs\">ramfs<\/h1>\n<p>linux\u7684VM(\u865a\u62df\u5185\u5b58)\u5305\u62ecramfs\u548cswap.<\/p>\n<p>\u5bf9\u5185\u5b58\u7684\u652f\u6301<\/p>\n<h1 id=\"swap\">swap<\/h1>\n<p>\u4ea4\u6362\u5206\u533a\uff0c\u5f53\u5185\u5b58\u4e0d\u8db3\uff0c\u4f1a\u628a\u5185\u5b58\u4e0a\u6682\u65f6\u4e0d\u8fd0\u884c\u7684\u7a0b\u5e8f\u4fdd\u5b58\u5230swap\uff0c\u83b7\u53d6\u90e8\u5206\u5185\u5b58\u7a7a\u95f4\u8fd0\u884c\uff0e<\/p>\n<h1 id=\"tmpfs\">tmpfs<\/h1>\n<p>\u4e34\u65f6\u6587\u4ef6\u7cfb\u7edf, \u4f18\u5148\u4f7f\u7528ramfs,\u3000\u5176\u6b21\u4f7f\u7528swap.<\/p>\n<pre><code># \u6302\u8f7dtmpfs\nmount -t tmpfs -o size=1024m tmpfs \/path\/to\/mount\n# \/etc\/fstab\u3000\ntmpfs \/dev\/shm tmpfs,defaults,size=512m 0 0\n<\/code><\/pre>\n<h1 id=\"vfatfatntfs\">vfat\/fat\/ntfs<\/h1>\n<p>windows\u6587\u4ef6\u7cfb\u7edf<\/p>\n<h1 id=\"cifssmbfs\">cifs\/smbfs<\/h1>\n<h1 id=\"nfs\">nfs<\/h1>"},{"title":"Firewall","link":"https:\/\/canuxcheng.com\/post\/linux_firewall\/","pubDate":"Thu, 31 Mar 2016 21:48:59 +0000","guid":"https:\/\/canuxcheng.com\/post\/linux_firewall\/","description":"<h1 id=\"firewall\">Firewall<\/h1>\n<p>UFW: linux\u9632\u706b\u5899\u914d\u7f6e\u5de5\u5177\uff0c\u5e95\u5c42\u8fd8\u662f\u8c03\u7528iptables.<\/p>\n<p>filewall: centos\u7684\u9632\u706b\u5899\u547d\u4ee4, \u5e95\u5c42\u8fd8\u662f\u8c03\u7528iptables.<\/p>\n<hr>\n<h1 id=\"selinux\">SELinux<\/h1>\n<p>Security-Enhanced-Linux<\/p>\n<p>\u672c\u5730\u5b89\u5168<\/p>\n<hr>\n<h1 id=\"netfilter\">Netfilter<\/h1>\n<p>\u7f51\u7edc\u5b89\u5168<\/p>\n<hr>\n<h1 id=\"iptables\">iptables<\/h1>\n<p>\u901a\u8fc7iptables\u64cd\u4f5cNetfilter\u5b9e\u73b0\u5e94\u7528\u5c42\u5b89\u5168.<\/p>\n<p>table:<\/p>\n<pre><code>filter \u9ed8\u8ba4\u8868\nnat\nmangle\nraw\nsecurity\n<\/code><\/pre>\n<h2 id=\"filter\">filter<\/h2>\n<p>chain:<\/p>\n<pre><code>INPUT\nFORWARD\nOUTPUT\n<\/code><\/pre>\n<h2 id=\"nat\">nat<\/h2>\n<p>chain:<\/p>\n<pre><code>INPUT\nOUTPUT\nPREROUTING\nPOSTROUTING\n<\/code><\/pre>\n<p>postrouting:<\/p>\n<pre><code>snat: \u5185\u7f51\u4e3b\u673a\u8bbf\u95ee\u5916\u7f51\u7ecf\u8fc7\u8def\u7531\u65f6\uff0c\u6e90ip\u4f1a\u53d1\u751f\u53d8\u5316\u3002\n<\/code><\/pre>\n<p>prerouting:<\/p>\n<pre><code>dnat: \u5916\u7f51\u8bbf\u95ee\u5185\u7f51\u7ecf\u8fc7\u8def\u7531\u65f6\uff0c\u76ee\u7684ip\u4f1a\u53d1\u751f\u53d8\u5316\u3002\n<\/code><\/pre>\n<h2 id=\"iptables\u547d\u4ee4\">iptables\u547d\u4ee4<\/h2>\n<pre><code>-L\/--list [chain [ rulenum]]\n-S\/--list-rules [chain [rulenum]]\n-Z\/--zero [chain [rulenum]]\n-A\/--append chain\n-C\/--check chain\n-N\/--new chain\n-F\/--flush [chain] \/\/ \u5220\u9664chain\u4e2d\u7684rules.\n-X\/--delete-chain [chain] \/\/ \u5220\u9664\u81ea\u5b9a\u4e49chain.\n-R\/--replace chain rulenum\n-D\/--delete chain [rulenum]\n-I\/--insert chain [rulenum]\n-P\/--policy chain target\n-E\/--rename-chain old-chain new-chain\n<\/code><\/pre>\n<p>tables:<\/p>\n<pre><code>-t\/--table filter\/nat\/mangle\n<\/code><\/pre>\n<p>options:<\/p>\n<pre><code>[!] -p\/--protocol\n[!] -s\/--source\n[!] -d\/--destination\n[!] -o\/--out-interface\n[!] -i\/--in-interface\n[!] -f\/--fragment\n--dport destination-port\n--sport source-port\n-m, --match\n-j, --jump\n-g, --goto\n-c, --set-counters\n--line-number # \u663e\u793arulenum\n-v\/--verbose\n-n\/--numeric\n<\/code><\/pre>\n<p>others:<\/p>\n<pre><code># \u4fdd\u5b58\u89c4\u5219\niptables-save &gt; firewall.txt\n# \u52a0\u8f7d\u89c4\u5219\niptables-restore firewall.txt\n<\/code><\/pre>\n<p>\u5f00\u673a\u542f\u52a8:<\/p>\n<pre><code>iptables-save &gt; \/etc\/iptables.rules\nvim \/etc\/network\/if-pre-up.d\/iptables\n#!\/bin\/bash\niptables\u00a0-F\niptables -X\niptables -t nat -F\niptables -t nat -X\niptables-restore\u00a0\/etc\/iptables.rules\n<\/code><\/pre>"},{"title":"Grub","link":"https:\/\/canuxcheng.com\/post\/linux_grub\/","pubDate":"Thu, 31 Mar 2016 21:48:59 +0000","guid":"https:\/\/canuxcheng.com\/post\/linux_grub\/","description":"<h1 id=\"grub\">Grub<\/h1>\n<p>\u5f15\u5bfc\u7a0b\u5e8f\u3002<\/p>\n<p>linux\/unix\u7684\u5f15\u5bfc\u7a0b\u5e8f\u6709lilo\u548cgrub\u3002<\/p>\n<h1 id=\"\u914d\u7f6e\">\u914d\u7f6e<\/h1>\n<p>\u4fee\u6539grub:<\/p>\n<pre><code>$ sudo vim \/boot\/grub\/grub.cfg\n<\/code><\/pre>"},{"title":"Linux","link":"https:\/\/canuxcheng.com\/post\/linux\/","pubDate":"Thu, 31 Mar 2016 21:48:59 +0000","guid":"https:\/\/canuxcheng.com\/post\/linux\/","description":"<h1 id=\"linux\">Linux<\/h1>\n<p>Linux\u4e25\u683c\u8bb2\u6307\u7684\u662fLinux\u8fd9\u4e00\u7c7b\u64cd\u4f5c\u7cfb\u7edf\u7684\u5185\u6838\u3002<\/p>\n<p>Linux\u5185\u6838\u7684github\uff1a<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/torvalds\/linux\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/torvalds\/linux<\/a><\/p>\n<p>Linux\u5185\u6838\u7684\u7ad9\u70b9\uff1a<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.kernel.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.kernel.org\/<\/a><\/p>\n<p>\u5546\u4e1a\u5316\u7684linux\u7cfb\u7edf\uff1a<\/p>\n<ol>\n<li>redhat enterprise linux<\/li>\n<li>suse enterprise linux<\/li>\n<\/ol>\n<p>\u514d\u8d39\u7684\u670d\u52a1\u5668\u7248\u672c\uff1a<\/p>\n<ol>\n<li>centos (rhel\u7684\u514d\u8d39\u7248\u670d\u52a1\u5668\u7248)<\/li>\n<li>open suse<\/li>\n<li>debian\/ubuntu<\/li>\n<\/ol>\n<p>\u514d\u8d39\u7684\u684c\u9762\u7248\u672c\uff1a<\/p>\n<ol>\n<li>fedora (\u539f\u6765\u7684redhat desktop linux)<\/li>\n<li>open suse<\/li>\n<li>debian\/ubuntu<\/li>\n<\/ol>\n<h1 id=\"linux\u684c\u9762\u73af\u5883\">Linux\u684c\u9762\u73af\u5883<\/h1>\n<p>X windows<\/p>\n<p>KDE<\/p>\n<p>GNOME2(Mate)<\/p>\n<p>GNOME3(Mate\/Cinnamon)<\/p>\n<p>Unity<\/p>\n<p>xface<\/p>\n<p>lxde<\/p>\n<p>enlightenment(<a class=\"link\" href=\"https:\/\/www.enlightenment.org\/start\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.enlightenment.org\/start<\/a>)<\/p>\n<h1 id=\"linux\u684c\u9762\u7ba1\u7406\u5668\">Linux\u684c\u9762\u7ba1\u7406\u5668\uff1a<\/h1>\n<p>xDM<\/p>\n<p>gDM(gnome)<\/p>\n<p>kDM(kde)<\/p>\n<p>lightDM<\/p>\n<h1 id=\"linux\u7f16\u7a0b\">Linux\u7f16\u7a0b<\/h1>\n<h2 id=\"linux\u7a0b\u5e8f\u8c03\u7528\u7ed3\u6784\">Linux\u7a0b\u5e8f\u8c03\u7528\u7ed3\u6784\uff1a<\/h2>\n<ol>\n<li>\u5e94\u7528\u7a0b\u5e8f(\u5305\u62ecshell\u5916\u90e8\u547d\u4ee4)\/Shell\u547d\u4ee4(\u4e5f\u5c31\u662fshell\u5185\u90e8\u547d\u4ee4)<\/li>\n<li>C\u6807\u51c6\u5e93glibc(\u5305\u62ecISO C\u548cPOSIC\u5c01\u88c5\u7684\u7cfb\u7edf\u7cfb\u7edf\u8c03\u7528)<\/li>\n<li>Linux\u7cfb\u7edf\u8c03\u7528<\/li>\n<li>Linux\u5185\u6838<\/li>\n<\/ol>\n<h2 id=\"\u67e5\u770b\u624b\u518c\">\u67e5\u770b\u624b\u518c\uff1a<\/h2>\n<p>\u67e5\u770bman\u5e2e\u52a9:<\/p>\n<pre><code>$ man man\n<\/code><\/pre>\n<p>\u624b\u518c\u7ae0\u8282:<\/p>\n<ol>\n<li>Executable programs or shell commands<\/li>\n<li>System calls (functions provided by the kernel)<\/li>\n<li>Library calls (functions within program libraries)<\/li>\n<li>Special files (usually found in \/dev)<\/li>\n<li>File formats and conventions eg \/etc\/passwd<\/li>\n<li>Games<\/li>\n<li>Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7)<\/li>\n<li>System administration commands (usually only for root)<\/li>\n<li>Kernel routines [Non standard]<\/li>\n<\/ol>\n<p>\u67e5\u770bshell\u547d\u4ee4<\/p>\n<pre><code>man 1 &lt;cmd&gt;\n<\/code><\/pre>\n<p>\u67e5\u5230\u7684\u662f\u7cfb\u7edf\u8c03\u7528\uff08\u5b9e\u9645\u4e0a\u4e5f\u662fPOSIX\u5c01\u88c5\u7684\u540c\u540d\u51fd\u6570\uff09<\/p>\n<pre><code>man 2 &lt;name&gt;\n\/\/ \u67e5\u770b\u7cfb\u7edf\u8c03\u7528\u6240\u6709\u51fd\u6570\u5b8f\nman 2 syscalls\n\/\/ \u67e5\u770b\u672a\u5b9e\u73b0\u7684\u7cfb\u7edf\u8c03\u7528\nman 2 unimplemented\n<\/code><\/pre>\n<p>\u67e5\u5230\u7684glibc\uff08\u5305\u62ecISO C\uff0cPOSIX\u7684\u90e8\u5206\u51fd\u6570\uff0c\u5176\u5b83\u5e93\uff09<\/p>\n<pre><code>man 3 &lt;name&gt;\n<\/code><\/pre>\n<p>\u67e5\u770b\u6807\u51c6\uff1a<\/p>\n<pre><code>man 7 &lt;name&gt;\n\/\/ \u67e5\u770bglibc\u6807\u51c6\nman 7 libc\n\/\/ \u67e5\u770bC\u548cLinux\u7684\u6807\u51c6\nman 7 standards\n<\/code><\/pre>\n<h1 id=\"grub\">Grub<\/h1>\n<p>\u5f15\u5bfc\u7a0b\u5e8f\u3002<\/p>\n<p>windows\u7684\u5f15\u5bfc\u7a0b\u5e8f\u662fNTloader\u3002<\/p>\n<p>linux\/unix\u7684\u5f15\u5bfc\u7a0b\u5e8f\u6709lilo\u548cgrub\u3002<\/p>"},{"title":"Monitoring","link":"https:\/\/canuxcheng.com\/post\/linux_monitoring\/","pubDate":"Thu, 31 Mar 2016 21:48:59 +0000","guid":"https:\/\/canuxcheng.com\/post\/linux_monitoring\/","description":"<h1 id=\"inode\">inode<\/h1>"},{"title":"Markdown","link":"https:\/\/canuxcheng.com\/post\/markdown\/","pubDate":"Mon, 28 Mar 2016 22:03:15 +0000","guid":"https:\/\/canuxcheng.com\/post\/markdown\/","description":"<h1 id=\"markdown\">Markdown<\/h1>\n<h2 id=\"markdown\u7b80\u4ecb\">Markdown\u7b80\u4ecb<\/h2>\n<p>Markdown\u662f\u4e00\u79cd\u8f7b\u91cf\u7ea7\u6587\u672c\u6807\u8bb0\u8bed\u8a00, Markdown\u7684\u76ee\u6807\u662f\u5b9e\u73b0\u6613\u8bfb\u6613\u5199\u3002\nMarkdown\u548chtml\u6709\u5f88\u5927\u533a\u522b\uff0chtml\u662f\u4e00\u79cd\u53d1\u5e03\u683c\u5f0f\uff0cmarkdown\u662f\u4e00\u79cd\u4e66\u5199\u683c\u5f0f\u3002<\/p>\n<p>Markdown \u4e2d\u6587\u624b\u518c\uff1a<\/p>\n<p><a class=\"link\" href=\"http:\/\/wowubuntu.com\/markdown\/index.html\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/wowubuntu.com\/markdown\/index.html<\/a><\/p>\n<p>Markdown \u82f1\u6587\u624b\u518c\uff1a<\/p>\n<p><a class=\"link\" href=\"http:\/\/daringfireball.net\/projects\/markdown\/syntax\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/daringfireball.net\/projects\/markdown\/syntax<\/a><\/p>\n<p>Markdown\u6587\u4ef6\u7684\u6269\u5c55\u540d\u662fmd\u3002<\/p>\n<h2 id=\"\u4e24\u4e2a\u9700\u8981\u7279\u6b8a\u5904\u7406\u7684\u5b57\u7b26\">\u4e24\u4e2a\u9700\u8981\u7279\u6b8a\u5904\u7406\u7684\u5b57\u7b26<\/h2>\n<p>&lt; \u7684\u8868\u793a\u65b9\u6cd5\uff1a<\/p>\n<blockquote>\n<p>&amp; l t ;<\/p>\n<\/blockquote>\n<p>&amp; \u7684\u8868\u793a\u65b9\u6cd5\uff1a<\/p>\n<blockquote>\n<p>&amp; a m p ;<\/p>\n<\/blockquote>\n<hr>\n<h1 id=\"\u533a\u5757\u5143\u7d20\">\u533a\u5757\u5143\u7d20<\/h1>\n<h2 id=\"\u6bb5\u843d\u548c\u6362\u884c\">\u6bb5\u843d\u548c\u6362\u884c<\/h2>\n<p>\u6bb5\u843d\u524d\u540e\u8981\u6709\u4e00\u4e2a\u6216\u4ee5\u4e0a\u7684\u7a7a\u884c\uff08\u7a7a\u683c\u6216\u5236\u8868\u7b26\u90fd\u53ef\u4ee5\uff09\u3002<\/p>\n<h2 id=\"\u6807\u9898\">\u6807\u9898<\/h2>\n<p>markdown\u652f\u6301\u4e24\u4e2a\u8bed\u6cd5\u683c\u5f0f\u7684\u6807\u9898<\/p>\n<h3 id=\"setext\u683c\u5f0f\">setext\u683c\u5f0f<\/h3>\n<p>\u4efb\u610f\u4e2a\u6570\u4e0b\u7b49\u53f7=\u8868\u793a\u5927\u6807\u9898:<\/p>\n<pre><code>Title\n======\n<\/code><\/pre>\n<p>\u4efb\u610f\u4e2a\u6570\u4e0b\u51cf\u53f7\u8868\u793a\u526f\u6807\u9898\uff1a<\/p>\n<pre><code>Subtitle\n--------\n<\/code><\/pre>\n<h3 id=\"atx\u683c\u5f0f\">atx\u683c\u5f0f<\/h3>\n<p>\u4e00\u5230\u516d\u4e2a#\u8868\u793a\u4e00\u5230\u516d\u9636\u6807\u9898,#\u540e\u9762\u6709\u7a7a\u683c<\/p>\n<pre><code># \u4e00\u9636\u6807\u9898\n## \u4e8c\u9636\u6807\u9898\n### \u4e09\u9636\u6807\u9898\n#### \u56db\u9636\u6807\u9898\n##### \u4e94\u9636\u6807\u9898\n###### \u516d\u9636\u6807\u9898\n<\/code><\/pre>\n<h2 id=\"\u533a\u5757\u5f15\u7528\">\u533a\u5757\u5f15\u7528<\/h2>\n<p>\u4f7f\u7528&gt;\u8868\u793a\u5355\u5c42\u533a\u5757\u5f15\u7528\uff1a<\/p>\n<p>&gt; block<\/p>\n<blockquote>\n<p>block<\/p>\n<\/blockquote>\n<p>\u4f7f\u7528\u591a\u4e2a&gt;\u5d4c\u5957\u4f7f\u7528\uff1a<\/p>\n<p>&gt;&gt; block<\/p>\n<blockquote>\n<blockquote>\n<p>block<\/p>\n<\/blockquote>\n<\/blockquote>\n<p>\u533a\u5757\u5185\u4e5f\u53ef\u4ee5\u7528\u6807\u9898\uff0c\u5217\u8868\u548c\u4ee3\u7801\u533a\u5757\u7b49\u3002<\/p>\n<h2 id=\"\u5217\u8868\">\u5217\u8868<\/h2>\n<h3 id=\"\u65e0\u5e8f\u5217\u8868\">\u65e0\u5e8f\u5217\u8868<\/h3>\n<p>\u65e0\u5e8f\u5217\u8868\u4f7f\u7528\u661f\u53f7\u3001\u52a0\u53f7\u6216\u662f\u51cf\u53f7\u4f5c\u4e3a\u5217\u8868\u6807\u8bb0,\u7b26\u53f7\u548c\u5b57\u7b26\u4e4b\u95f4\u6709\u7a7a\u683c\uff1a<\/p>\n<p>* shopping list<\/p>\n<blockquote>\n<ul>\n<li>shopping list<\/li>\n<\/ul>\n<\/blockquote>\n<p>+ shoppint list<\/p>\n<blockquote>\n<ul>\n<li>shopping list<\/li>\n<\/ul>\n<\/blockquote>\n<p>- shopping list<\/p>\n<blockquote>\n<ul>\n<li>shopping list<\/li>\n<\/ul>\n<\/blockquote>\n<h3 id=\"\u6709\u5e8f\u5217\u8868\">\u6709\u5e8f\u5217\u8868<\/h3>\n<p>\u6709\u5e8f\u5217\u8868\u4f7f\u7528\u6570\u5b57\u548c\u4e00\u4e2a\u82f1\u6587\u53e5\u70b9,\u7b26\u53f7\u548c\u5b57\u7b26\u4e4b\u95f4\u6709\u7a7a\u683c\uff1a<\/p>\n<ol>\n<li>numbered list<\/li>\n<\/ol>\n<blockquote>\n<ol>\n<li>numbered list<\/li>\n<\/ol>\n<\/blockquote>\n<h2 id=\"\u4ee3\u7801\u533a\u5757\">\u4ee3\u7801\u533a\u5757<\/h2>\n<p>\u7b80\u5355\u5730\u7f29\u8fdb 4 \u4e2a\u7a7a\u683c\u6216\u662f 1 \u4e2a\u5236\u8868\u7b26,\u4e00\u4e2a\u4ee3\u7801\u533a\u5757\u4f1a\u4e00\u76f4\u6301\u7eed\u5230\u6ca1\u6709\u7f29\u8fdb\u7684\u90a3\u4e00\u884c\u6216\u662f\u6587\u4ef6\u7ed3\u5c3e\u3002<\/p>\n<p>\u8fd9\u662f\u4e00\u4e2a\u666e\u901a\u6bb5\u843d\uff1a<\/p>\n<pre><code>\u8fd9\u662f\u4e00\u4e2a\u4ee3\u7801\u533a\u5757\u3002\n\u7f29\u8fdb\n\u4ee3\u7801\u533a\u5757\u7ed3\u675f\u3002\n<\/code><\/pre>\n<h2 id=\"\u5206\u5272\u7ebf\">\u5206\u5272\u7ebf<\/h2>\n<p>\u4e09\u4e2a\u4ee5\u4e0a\u7684*-_\u90fd\u53ef\u4ee5\u4ea7\u751f\u5206\u5272\u7ebf:<\/p>\n<p>***<\/p>\n<blockquote>\n<hr>\n<\/blockquote>\n<p>---<\/p>\n<blockquote>\n<hr>\n<\/blockquote>\n<p>___<\/p>\n<blockquote>\n<hr>\n<\/blockquote>\n<hr>\n<h1 id=\"\u533a\u6bb5\u5143\u7d20\">\u533a\u6bb5\u5143\u7d20<\/h1>\n<h2 id=\"\u94fe\u63a5\">\u94fe\u63a5<\/h2>\n<h3 id=\"\u884c\u5185\u5f0f\u94fe\u63a5\">\u884c\u5185\u5f0f\u94fe\u63a5<\/h3>\n<p>[Link](<a class=\"link\" href=\"https:\/\/github.com\/crazy-canux\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/crazy-canux<\/a>)<\/p>\n<blockquote>\n<p><a class=\"link\" href=\"https:\/\/github.com\/crazy-canux\" target=\"_blank\" rel=\"noopener\"\n>Link<\/a><\/p>\n<\/blockquote>\n<h3 id=\"\u53c2\u8003\u5f0f\u94fe\u63a5\">\u53c2\u8003\u5f0f\u94fe\u63a5<\/h3>\n<p>[Link][id]<\/p>\n<p>[id]:https:\/\/github.com\/crazy-canux<\/p>\n<h3 id=\"\u81ea\u52a8\u94fe\u63a5\">\u81ea\u52a8\u94fe\u63a5<\/h3>\n<p>\u7f51\u5740:<\/p>\n<p>&lt;https:\/\/github.com\/crazy-canux&gt;<\/p>\n<blockquote>\n<p><a class=\"link\" href=\"https:\/\/github.com\/crazy-canux\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/crazy-canux<\/a><\/p>\n<\/blockquote>\n<p>\u90ae\u7bb1\uff1a<\/p>\n<p>&lt;canuxcheng@gmail.com&gt;<\/p>\n<blockquote>\n<p><a class=\"link\" href=\"mailto:canuxcheng@gmail.com\" >canuxcheng@gmail.com<\/a><\/p>\n<\/blockquote>\n<h2 id=\"\u5f3a\u8c03\">\u5f3a\u8c03<\/h2>\n<p>\u7528\u4e00\u4e2a*\u6216_\u8868\u793a\u5f3a\u8c03\uff0c\u7b26\u53f7\u548c\u5b57\u7b26\u4e2d\u95f4\u6ca1\u6709\u7a7a\u683c<\/p>\n<p>\u659c\u4f53\uff1a*italic*<\/p>\n<blockquote>\n<p><em>italic<\/em><\/p>\n<\/blockquote>\n<p>\u659c\u4f53\uff1a _italic_<\/p>\n<blockquote>\n<p><em>italic<\/em><\/p>\n<\/blockquote>\n<p>\u7c97\u4f53\uff1a **bold**<\/p>\n<blockquote>\n<p><strong>bold<\/strong><\/p>\n<\/blockquote>\n<p>\u7c97\u4f53\uff1a __bold__<\/p>\n<blockquote>\n<p><strong>bold<\/strong><\/p>\n<\/blockquote>\n<h2 id=\"\u4ee3\u7801\">\u4ee3\u7801<\/h2>\n<p>\u7528\u53cd\u5f15\u53f7\u6807\u8bb0\u4e00\u5c0f\u6bb5\u4ee3\u7801\uff1a<\/p>\n<p>`monospace`<\/p>\n<blockquote>\n<p><code>monospace<\/code><\/p>\n<\/blockquote>\n<h2 id=\"\u56fe\u7247\">\u56fe\u7247<\/h2>\n<h3 id=\"\u884c\u5185\u5f0f\u56fe\u7247\">\u884c\u5185\u5f0f\u56fe\u7247<\/h3>\n<p>![pic](\/path\/to\/img.jpg)<\/p>\n<blockquote>\n<p><img src=\"https:\/\/canuxcheng.com\/path\/to\/img.jpg\"\nloading=\"lazy\"\nalt=\"Pic\"\n><\/p>\n<\/blockquote>\n<h3 id=\"\u53c2\u8003\u5f0f\u56fe\u7247\">\u53c2\u8003\u5f0f\u56fe\u7247<\/h3>\n<p>![pic][id]<\/p>\n<p>[id]: \/path\/to\/img.jpg<\/p>\n<hr>\n<h1 id=\"\u53cd\u659c\u7ebf\">\u53cd\u659c\u7ebf<\/h1>\n<p>\u7528\u53cd\u659c\u7ebf\\\u6765\u8f6c\u79fb\u5b57\u7b26<\/p>\n<p>\\ \u53cd\u659c\u7ebf<\/p>\n<p>` \u53cd\u5f15\u53f7<\/p>\n<p>* \u661f\u53f7<\/p>\n<p>_ \u5e95\u7ebf<\/p>\n<p>{} \u82b1\u62ec\u53f7<\/p>\n<p>[] \u65b9\u62ec\u53f7<\/p>\n<p>() \u62ec\u5f27<\/p>\n<p># \u4e95\u5b57\u53f7<\/p>\n<p>+ \u52a0\u53f7<\/p>\n<p>- \u51cf\u53f7<\/p>\n<p>. \u82f1\u6587\u53e5\u70b9<\/p>\n<p>! \u60ca\u53f9\u53f7<\/p>"},{"title":"Nagios","link":"https:\/\/canuxcheng.com\/post\/metrics_nagios\/","pubDate":"Fri, 25 Mar 2016 11:15:48 +0000","guid":"https:\/\/canuxcheng.com\/post\/metrics_nagios\/","description":"<h1 id=\"nagios\">Nagios<\/h1>\n<blockquote>\n<p>Nagios is the industry standard in IT infrastructure monitoring<\/p>\n<\/blockquote>\n<blockquote>\n<p>Nagios offers complete monitoring and alerting for servers, switches, applications, and services.<\/p>\n<\/blockquote>\n<p>Nagios\u5b98\u65b9\u5ba3\u79f0nagios\u662fIT\u57fa\u7840\u76d1\u63a7\u7684\u5de5\u4e1a\u6807\u51c6\u3002<\/p>\n<p>Nagios\u63d0\u4f9b\u5bf9\u670d\u52a1\u5668\uff0c\u4ea4\u6362\u673a\uff0c\u5e94\u7528\u548c\u670d\u52a1\u7684\u5b8c\u6574\u7684\u76d1\u63a7\u548c\u8b66\u62a5\u3002<\/p>\n<p>Nagios\u662f\u65e0agent\u7684\uff0cnagios\u7684plugin\u901a\u8fc7\u534f\u8bae\u8fdc\u7a0b\u83b7\u53d6\u4fe1\u606f\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.nagios.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.nagios.org\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/www.nagios.com\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.nagios.com\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/exchange.nagios.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/exchange.nagios.org\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/NagiosEnterprises\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/NagiosEnterprises<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/nagios-plugins\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/nagios-plugins<\/a><\/p>\n<hr>\n<h1 id=\"nagios\u5b89\u88c5\u914d\u7f6e\">Nagios\u5b89\u88c5\u914d\u7f6e<\/h1>\n<h2 id=\"nagios\u53d1\u5c55\">Nagios\u53d1\u5c55<\/h2>\n<p>Nagios core 1.0<\/p>\n<p>Nagios core 2.0<\/p>\n<p>Nagios core 3.0<\/p>\n<p>Nagios XI<\/p>\n<p>Nagios core 4.0<\/p>\n<p>\u76ee\u524dnagios\u6709\u4e24\u5927\u9635\u8425\uff1a<\/p>\n<p>\u5f00\u6e90\u89e3\u51b3\u65b9\u6848\uff1a Nagios core<\/p>\n<p>\u5546\u4e1a\u89e3\u51b3\u65b9\u6848\uff1a Nagios XI<\/p>\n<h2 id=\"nagios\u5b89\u88c5\u914d\u7f6e-1\">Nagios\u5b89\u88c5\u914d\u7f6e<\/h2>\n<p>\u5b89\u88c5\u548c\u914d\u7f6enagios core,plugins,addons\u53c2\u8003<\/p>\n<p>\u5b98\u65b9\u6587\u6863:<\/p>\n<p><a class=\"link\" href=\"https:\/\/assets.nagios.com\/downloads\/nagioscore\/docs\/nagioscore\/4\/en\/toc.html\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/assets.nagios.com\/downloads\/nagioscore\/docs\/nagioscore\/4\/en\/toc.html<\/a><\/p>\n<p>\u4e2d\u6587\u6587\u6863\uff1a<\/p>\n<p><a class=\"link\" href=\"http:\/\/nagios-cn.sourceforge.net\/nagios-cn\/index.html\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/nagios-cn.sourceforge.net\/nagios-cn\/index.html<\/a><\/p>\n<hr>\n<h1 id=\"nagios\u5f00\u6e90\u89e3\u51b3\u65b9\u6848\">Nagios\u5f00\u6e90\u89e3\u51b3\u65b9\u6848<\/h1>\n<h2 id=\"nagios-core\">Nagios core:<\/h2>\n<blockquote>\n<p>Nagios Core is the monitoring and alerting engine that serves as the primary application around which hundreds of Nagios projects are built.<\/p>\n<\/blockquote>\n<p>Nagios core\u662f\u76d1\u63a7\u548c\u8b66\u62a5\u7684\u4e3b\u5f15\u64ce\uff0c\u56f4\u7ed5\u5b83\u5efa\u7acb\u4e86\u6210\u5343\u4e0a\u4e07\u7684\u9879\u76ee\u3002\n\u6280\u672f\u6808\u662fc\uff0c\u53ea\u80fd\u5b89\u88c5\u5728linux\/unix\u7cfb\u7edf\u3002\nNagios core\u53ea\u662f\u4e00\u4e2a\u76d1\u63a7\u5957\u4ef6\uff0c\u672c\u8eab\u6ca1\u6709\u76d1\u63a7\u529f\u80fd\uff0c\u9700\u8981\u63d2\u4ef6\u6765\u5b8c\u6210\u76d1\u63a7\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.nagios.org\/projects\/nagios-core\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.nagios.org\/projects\/nagios-core\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/NagiosEnterprises\/nagioscore\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/NagiosEnterprises\/nagioscore<\/a><\/p>\n<h2 id=\"nagios-plugins\">Nagios plugins:<\/h2>\n<blockquote>\n<p>Efficient, standalone extensions that provide low-level intelligence for monitoring anything and everything with Nagios Core.<\/p>\n<\/blockquote>\n<p>Nagios core\u7684\u76d1\u63a7\u63d2\u4ef6,\u4e5f\u5c31\u662f\u5b98\u65b9\u63d2\u4ef6,\u4e3b\u8981\u662fc\u3001shell\u548cperl\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.nagios.org\/projects\/nagios-plugins\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.nagios.org\/projects\/nagios-plugins\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/nagios-plugins\/nagios-plugins\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/nagios-plugins\/nagios-plugins<\/a><\/p>\n<h2 id=\"nagios-frontends\">Nagios frontends:<\/h2>\n<blockquote>\n<p>Web interfaces, themes, Windows and Linux interfaces, and mobile apps for Nagios. Change the look and style of Nagios to suite your needs.<\/p>\n<\/blockquote>\n<p>Nagios frontends\u5305\u62ec\u4e86 \u4e3b\u9898,web\u63a5\u53e3,\u79fb\u52a8\u8bbe\u5907\u63a5\u53e3\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.nagios.org\/downloads\/nagios-core-frontends\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.nagios.org\/downloads\/nagios-core-frontends\/<\/a><\/p>\n<h2 id=\"nagios-config-toolsnagios-addons-projects\">Nagios config tools(Nagios addons projects):<\/h2>\n<blockquote>\n<p>Tools and GUIs for simplifying Nagios Core configuration.<\/p>\n<\/blockquote>\n<p>nagios core\u7684\u7ec4\u4ef6\u3002<\/p>\n<p>\u5305\u62ecLilac,NagiosQL,NConf,OneCMDB,ignoramus<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.nagios.org\/projects\/nagios-config-tools\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.nagios.org\/projects\/nagios-config-tools\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/www.nagios.org\/downloads\/nagios-core-addons\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.nagios.org\/downloads\/nagios-core-addons\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/NagiosEnterprises\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/NagiosEnterprises<\/a><\/p>\n<h2 id=\"nagios-exchange\">Nagios exchange:<\/h2>\n<blockquote>\n<p>Nagios\u00ae Exchange is the central place where you&rsquo;ll find all types of Nagios projects - plugins, addons, documentation, extensions, and more. This site is designed for the Nagios Community to share its Nagios creations.<\/p>\n<\/blockquote>\n<p>Nagios exchange\u662fnagios\u7684\u5f00\u6e90\u5b9d\u5e93\u3002<\/p>\n<p>\u5305\u62ec\u7b2c\u4e09\u65b9plugins\u3001addons\u548cdocs\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/exchange.nagios.org\/https:\/\/exchange.nagios.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/exchange.nagios.org\/https:\/\/exchange.nagios.org\/<\/a><\/p>\n<hr>\n<h1 id=\"nagios\u5546\u4e1a\u89e3\u51b3\u65b9\u6848\">Nagios\u5546\u4e1a\u89e3\u51b3\u65b9\u6848<\/h1>\n<h2 id=\"nagios-xi\">Nagios XI:<\/h2>\n<blockquote>\n<p>Our most powerful IT infrastructure monitoring and IT monitoring software alerting solution for today\u2019s demanding organizational requirements.<\/p>\n<\/blockquote>\n<p>Nagios XI \u662f\u73b0\u4ee3\u5316\u7684\u5546\u4e1a\u76d1\u63a7\u89e3\u51b3\u5957\u4ef6\u3002<\/p>\n<p>Nagios XI \u4f7f\u7528nagios core 4.0\u3002<\/p>\n<p>Nagios XI \u67b6\u6784\uff1a<\/p>\n<p><img src=\"https:\/\/canuxcheng.com\/images\/nagiosxi.png\"\nloading=\"lazy\"\nalt=\"pic\"\n><\/p>\n<h2 id=\"nagios-network-analyzer\">Nagios network analyzer<\/h2>\n<h2 id=\"nagios-log-server\">Nagios log server<\/h2>\n<h2 id=\"nagios-fusion\">Nagios fusion<\/h2>\n<h2 id=\"nagios-incident-manager\">Nagios incident manager<\/h2>\n<hr>\n<h1 id=\"nagios\u547d\u4ee4\">Nagios\u547d\u4ee4<\/h1>\n<pre><code>\/usr\/local\/nagios\/bin\/nagios --help\n-v \u9a8c\u8bc1\u914d\u7f6e\u6587\u4ef6\n-d daemon mode\n-W worker mode.\n<\/code><\/pre>\n<hr>\n<h1 id=\"nagios-\u96c6\u4e2d\u76d1\u63a7\">Nagios \u96c6\u4e2d\u76d1\u63a7<\/h1>\n<h2 id=\"\u672c\u5730\u76d1\u63a7\">\u672c\u5730\u76d1\u63a7<\/h2>\n<p>\u4f7f\u7528nagios core + plugins\u53ea\u80fd\u76d1\u63a7\u672c\u5730\u7684linux\/unix\u673a\u5668\u3002<\/p>\n<h2 id=\"\u8fdc\u7a0b\u76d1\u63a7\">\u8fdc\u7a0b\u76d1\u63a7<\/h2>\n<p>\u4f7f\u7528nagios core + plugins + addons\u53ef\u4ee5\u76d1\u63a7\u8fdc\u7a0b\u7684linux\/unix\/windows\u673a\u5668\u3002<\/p>\n<p>NRPE(for linux)\/NRPE_NT(for windows)\u548ccheck_nrpe, \u8fd0\u884c\u8fdc\u7a0b\u673a\u5668\u4e0a\u7684\u63d2\u4ef6, \u652f\u6301windows\/unix\/linux:<\/p>\n<pre><code>nagios core + check_nrpe &lt;=&gt; NRPE\/NRPE_NT + plugins\n<\/code><\/pre>\n<p>NSCP\u548ccheck_nt, \u53ea\u80fd\u4f7f\u7528\u56fa\u5b9a\u7684\u51e0\u4e2a\u547d\u4ee4\u67e5\u57fa\u672c\u5c5e\u6027, \u652f\u6301windows\/linux\/unix\uff1a<\/p>\n<pre><code>nagios core + check_nt -H &lt;NSCP IP&gt; [-v &lt;command&gt;] &lt;=&gt; NSCP(NSClient++)\n<\/code><\/pre>\n<p>NSCP\u548ccheck_nrpe\uff0c\u53ef\u4ee5\u4f20\u81ea\u5df1\u7684\u547d\u4ee4\u6216\u63d2\u4ef6, \u652f\u6301windows\/linux\/unix\uff1a<\/p>\n<pre><code>nagios core + check_nrpe -H &lt;NSCP IP&gt; [-c &lt;command\/plugins&gt;] [-a &lt;argument list&gt;] &lt;=&gt; NSCP(NSClient++) + plugins\n<\/code><\/pre>\n<p>NSCP\u548cNSCA\/NRDP,NSCP\u4e3b\u52a8check,\u7136\u540e\u5c06\u7ed3\u679c\u53d1\u9001\u7ed9NSCA\/NRDP:<\/p>\n<pre><code>nagios core + NSCA &lt;=&gt; NSCP(NSClient++)\n<\/code><\/pre>\n<p>NCPA\u662fpython\u5199\u7684\u8de8\u5e73\u53f0\u4ee3\u7406, \u652f\u6301linux\/windows\/unix\uff1a<\/p>\n<pre><code>nagios core + check_ncpa.py &lt;=&gt; NCPA\n<\/code><\/pre>\n<hr>\n<h1 id=\"nagios-\u5206\u5e03\u5f0f\u76d1\u63a7\">Nagios \u5206\u5e03\u5f0f\u76d1\u63a7<\/h1>\n<h2 id=\"nrdpnscansca-ng\">NRDP\/NSCA\/NSCA-ng<\/h2>\n<p>\u5b98\u65b9\u63a8\u8350\uff0cNRDP\u662fNSCA\u7684\u5347\u7ea7\u7248,\u63d0\u4f9b\u88ab\u52a8\u68c0\u6d4b,\u8fd9\u79cd\u65b9\u5f0f\u6548\u7387\u4f4e\uff0c\u7a33\u5b9a\u6027\u5dee\u3002<\/p>\n<pre><code>nagios core &lt;- plugins &lt;- NSCA &lt;= send_nsca &lt;- ocsp &lt;- Nagios core &lt;=&gt; Hosts\n^\n||\nsend_nsca &lt;- ocsp &lt;- Nagios core &lt;=&gt; Hosts\n<\/code><\/pre>\n<hr>\n<h1 id=\"nagios\u7684\u7ec4\u4ef6\">Nagios\u7684\u7ec4\u4ef6<\/h1>\n<p><a class=\"link\" href=\"https:\/\/www.nagios.org\/downloads\/nagios-core-addons\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.nagios.org\/downloads\/nagios-core-addons\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/NagiosEnterprises\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/NagiosEnterprises<\/a><\/p>\n<h2 id=\"ndoutilsndoidoutilsido\">NDOUtils(NDO)\/IDOUtils(IDO)<\/h2>\n<p>\u4ecenagios\u5bfc\u51fa\u5f53\u524d\u548c\u5386\u53f2\u6570\u636e\u5230mysql\u6570\u636e\u5e93,\u9700\u8981\u5b89\u88c5\u6570\u636e\u5e93\u3002<\/p>\n<p>\u76f8\u4f3c\u529f\u80fd\u6709mk livestatus\u3002<\/p>\n<p>N * (Nagios core + NDO module) -&gt; TCP\/Socket -&gt; NDO2DB daemon -&gt; DB<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/NagiosEnterprises\/ndoutils\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/NagiosEnterprises\/ndoutils<\/a><\/p>\n<h2 id=\"nsti\">NSTI<\/h2>\n<p>Nagios SNMP Trap Interface.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/NagiosEnterprises\/nsti\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/NagiosEnterprises\/nsti<\/a><\/p>\n<h2 id=\"bpi\">BPI<\/h2>\n<p>Nagios Business Process Intelligence.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/NagiosEnterprises\/nagiosbpi\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/NagiosEnterprises\/nagiosbpi<\/a><\/p>\n<h1 id=\"\u5176\u5b83\u7ec4\u4ef6\u4ecb\u7ecd\">\u5176\u5b83\u7ec4\u4ef6\u4ecb\u7ecd<\/h1>\n<h2 id=\"nconf\">NCONF<\/h2>\n<p>nagios\u7684\u57fa\u4e8eweb\u7684\u914d\u7f6e\u5de5\u5177\u3002<\/p>\n<p><a class=\"link\" href=\"http:\/\/www.nconf.org\/dokuwiki\/doku.php\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.nconf.org\/dokuwiki\/doku.php<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/nconf\/nconf\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/nconf\/nconf<\/a><\/p>\n<h2 id=\"dnx\">DNX<\/h2>\n<p>\u5206\u5e03\u5f0f\u7ec4\u4ef6\u3002<\/p>\n<p><a class=\"link\" href=\"http:\/\/dnx.sourceforge.net\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/dnx.sourceforge.net\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/sourceforge.net\/projects\/dnx\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/sourceforge.net\/projects\/dnx\/<\/a><\/p>\n<h2 id=\"nagiosgraph\">Nagiosgraph<\/h2>\n<blockquote>\n<p>nagiosgraph parses output and performance data from Nagios plugins and stores\nthe data in RRD files. nagiosgraph creates graphs and generates HTML pages with\ngraphic reports from the data.<\/p>\n<\/blockquote>\n<p>\u57fa\u4e8eRRD\uff0c\u7ed8\u5236nagios\u7684\u6027\u80fd\u56fe\u3002<\/p>\n<p><a class=\"link\" href=\"http:\/\/nagiosgraph.sourceforge.net\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/nagiosgraph.sourceforge.net\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/sourceforge.net\/projects\/nagiosgraph\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/sourceforge.net\/projects\/nagiosgraph\/<\/a><\/p>\n<hr>\n<h1 id=\"consol\u7684\u5206\u5e03\u5f0f\u76d1\u63a7\u65b9\u6848\">consol\u7684\u5206\u5e03\u5f0f\u76d1\u63a7\u65b9\u6848<\/h1>\n<p>\u4e00\u5bb6\u5fb7\u56fd\u7684\u54a8\u8be2\u548c\u89e3\u51b3\u65b9\u6848\u8f6f\u4ef6\u516c\u53f8\u3002<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7 check_MK \u7684omd\u6765\u5b89\u88c5\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.consol.de\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.consol.de\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/labs.consol.de\/index.html\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/labs.consol.de\/index.html<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/ConSol\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/ConSol<\/a><\/p>\n<p>\u4e3b\u8981\u8d21\u732e\u7ec4\u4ef6\uff1a<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/sni\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/sni<\/a><\/p>\n<p>\u4e3b\u8981\u8d21\u732e\u63d2\u4ef6\uff1a<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/lausser\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/lausser<\/a><\/p>\n<p><img src=\"https:\/\/canuxcheng.com\/images\/nagios.png\"\nloading=\"lazy\"\nalt=\"pic\"\n><\/p>\n<h2 id=\"mod-gearman\">Mod gearman<\/h2>\n<p>labs consol\u7684\u5206\u5e03\u5f0f\u76d1\u63a7\u7ec4\u4ef6, gearman\u7684worker\u3002<\/p>\n<p><a class=\"link\" href=\"http:\/\/www.mod-gearman.org\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.mod-gearman.org\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/sni\/mod_gearman\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/sni\/mod_gearman<\/a><\/p>\n<h2 id=\"ndoutilslivestatus\">NDOUtils\/livestatus<\/h2>\n<p>Event broker.<\/p>\n<h2 id=\"thruk\">Thruk<\/h2>\n<p>\u57fa\u4e8eperl\u7684web\u6846\u67b6catalyst\u7684dashbord\u3002<\/p>\n<p><a class=\"link\" href=\"http:\/\/www.thruk.org\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.thruk.org\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/sni\/Thruk\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/sni\/Thruk<\/a><\/p>\n<hr>\n<h1 id=\"op5\u7684\u5206\u5e03\u5f0f\u76d1\u63a7\u65b9\u6848\">Op5\u7684\u5206\u5e03\u5f0f\u76d1\u63a7\u65b9\u6848<\/h1>\n<p>\u4e00\u5bb6\u745e\u5178\u7684\u76d1\u63a7\u548c\u89e3\u51b3\u65b9\u6848\u516c\u53f8\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.op5.com\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.op5.com\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/kb.op5.com\/dashboard.action\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kb.op5.com\/dashboard.action<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/op5\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/op5<\/a><\/p>\n<h2 id=\"merlin\">merlin<\/h2>\n<p>\u5206\u5e03\u5f0f\u7ec4\u4ef6\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/kb.op5.com\/display\/MERLIN\/Distributed&#43;%28Merlin%29&#43;Home\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kb.op5.com\/display\/MERLIN\/Distributed+%28Merlin%29+Home<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/op5\/merlin\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/op5\/merlin<\/a><\/p>\n<h2 id=\"ndoutilsmk-livestatus\">NDOUtils\/MK livestatus<\/h2>\n<p>Eevent broker<\/p>\n<h2 id=\"ninja\">Ninja<\/h2>\n<p>Dashboard.<\/p>\n<p><a class=\"link\" href=\"https:\/\/kb.op5.com\/display\/GUI\/GUI&#43;%28Ninja%29&#43;Home\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/kb.op5.com\/display\/GUI\/GUI+%28Ninja%29+Home<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/op5\/ninja\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/op5\/ninja<\/a><\/p>\n<hr>\n<p>\u4ecb\u7ecdAddons.<\/p>\n<h1 id=\"omd\">OMD<\/h1>\n<blockquote>\n<p>OMD implements a completely new concept of how to install, maintain and update a monitoring system built on Nagios.<\/p>\n<\/blockquote>\n<p><a class=\"link\" href=\"http:\/\/omdistro.org\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/omdistro.org\/<\/a><\/p>\n<p><a class=\"link\" href=\"http:\/\/git.mathias-kettner.de\/git\/?p=omd.git;a=tree\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/git.mathias-kettner.de\/git\/?p=omd.git;a=tree<\/a><\/p>\n<p>The Open Monitoring Distribution<\/p>\n<p>\u7528\u4e8e\u5feb\u901f\u90e8\u7f72\u57fa\u4e8enagios\u7684\u5206\u5e03\u5f0f\u76d1\u63a7\uff0c\u5305\u62ec\uff1a<\/p>\n<ol>\n<li>\n<p>Icinga\/Shinken\/check_MK<\/p>\n<\/li>\n<li>\n<p>Monitoring-Plugins\u548c\u5176\u5b83\u63d2\u4ef6<\/p>\n<\/li>\n<li>\n<p>mod-gearman\/MK Livestatus\/thruk\/multisite<\/p>\n<\/li>\n<li>\n<p>nsca\/check_nrpe\u3002<\/p>\n<\/li>\n<li>\n<p>NagVis\/Pnp4nagios\/rrdtool\/dokuwiki<\/p>\n<\/li>\n<\/ol>\n<h1 id=\"gearman\">Gearman<\/h1>\n<blockquote>\n<p>Gearman provides a generic application framework to farm out work to other machines or processes that are better suited to do the work.<\/p>\n<\/blockquote>\n<p>Gearman\u7528\u6765\u505a\u4efb\u52a1\u5206\u53d1\u7684.<\/p>\n<p>\u4e00\u4e2aC++\u5b9e\u73b0\u7684Gearman Job Server:<\/p>\n<p><a class=\"link\" href=\"http:\/\/gearman.org\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/gearman.org\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/gearman\/gearmand\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/gearman\/gearmand<\/a><\/p>\n<p>\u4e00\u4e2aC\u5b9e\u73b0\u7684Gearman worker:<\/p>\n<p><a class=\"link\" href=\"http:\/\/www.mod-gearman.org\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.mod-gearman.org\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/sni\/mod_gearman\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/sni\/mod_gearman<\/a><\/p>\n<h1 id=\"rrdtools\">rrdtools<\/h1>\n<blockquote>\n<p>RRDtool is a little program for easily maintaining a database of time-series data. It comes with a charting program for drawing pretty graphs based on the data stored.<\/p>\n<\/blockquote>\n<p>\u5b58\u50a8\u6027\u80fd\u6570\u636e\u3002<\/p>\n<p><a class=\"link\" href=\"http:\/\/oss.oetiker.ch\/rrdtool\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/oss.oetiker.ch\/rrdtool\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/oetiker\/rrdtool-1.x\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/oetiker\/rrdtool-1.x<\/a><\/p>\n<h1 id=\"pnp4nagios\">pnp4nagios<\/h1>\n<blockquote>\n<p>PNP is an addon to Nagios which analyzes performance data provided by plugins and stores them automatically into RRD-databases.<\/p>\n<\/blockquote>\n<p>\u57fa\u4e8eRRD\uff0c\u7ed8\u5236nagios\u7684\u6027\u80fd\u56fe\u3002<\/p>\n<p><a class=\"link\" href=\"http:\/\/docs.pnp4nagios.org\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/docs.pnp4nagios.org\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/lingej\/pnp4nagios\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/lingej\/pnp4nagios<\/a><\/p>\n<p>\u53ef\u4ee5\u5728nagios\u7684service\u914d\u7f6e\u4e2d\u6dfb\u52a0\u201costpl_enable-graph&quot;\u542f\u7528\u56fe\u5f62\u3002<\/p>\n<p>templates.dist\u662f\u81ea\u5e26\u6a21\u677f<\/p>\n<p>templates\u662f\u7528\u6237\u81ea\u5b9a\u4e49\u6a21\u677f<\/p>\n<p>XXX.php\u9700\u8981\u548cnagios\u7684service\u7684command_name\u540c\u540d\uff0c\u9ed8\u8ba4\u67e5\u627e\u8fd9\u4e2a\u540c\u540d\u7684\u6a21\u677f.<\/p>\n<p>\u6d4b\u8bd5\u5c31\u662fscp XXX.php nagios-server:\/usr\/share\/pnp4nagios\/html\/templates\/\u7136\u540e\u53bbnagios\u67e5\u770b\u7ed3\u679c<\/p>\n<p>pnp4nagios\u67e5\u627e\u987a\u5e8f\uff1a<\/p>\n<ol>\n<li>templates\/check_XXX.php<\/li>\n<li>templates.dist\/check_XXX.php<\/li>\n<li>templates\/default.php<\/li>\n<li>templates.dist\/default.php<\/li>\n<\/ol>\n<h1 id=\"nagvis\">Nagvis<\/h1>\n<blockquote>\n<p>NagVis is a program for visualizing the data the monitoring core of your choice, for example Nagios, Naemon, Icinga or Shinken, in a human friendly way.<\/p>\n<\/blockquote>\n<p>\u7ed8\u5236\u76d1\u63a7\u5730\u56fe\u3002<\/p>\n<p><a class=\"link\" href=\"http:\/\/www.nagvis.org\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/www.nagvis.org\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/NagVis\/nagvis\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/NagVis\/nagvis<\/a><\/p>\n<h1 id=\"dokuwiki\">dokuwiki<\/h1>\n<blockquote>\n<p>DokuWiki is a simple to use and highly versatile Open Source wiki software that doesn&rsquo;t require a database.<\/p>\n<\/blockquote>\n<p>\u521b\u5efa\u76d1\u63a7\u7684procedure\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.dokuwiki.org\/dokuwiki\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.dokuwiki.org\/dokuwiki\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/splitbrain\/dokuwiki\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/splitbrain\/dokuwiki<\/a><\/p>\n<h1 id=\"graphite\">graphite<\/h1>\n<p><a class=\"link\" href=\"https:\/\/github.com\/graphite-project\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/graphite-project<\/a><\/p>\n<p><a class=\"link\" href=\"http:\/\/graphite.readthedocs.io\/en\/latest\/index.html\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/graphite.readthedocs.io\/en\/latest\/index.html<\/a><\/p>\n<p>Zabbix,Sensu,Ganglia,Nagios\/Naemon\/Icinga\/Shinken\u90fd\u53ef\u4ee5\u914d\u5408\u4f7f\u7528\u3002<\/p>\n<p>\u7ed8\u5236\u6027\u80fd\u56fe\u3002<\/p>\n<p>graphite-web<\/p>\n<blockquote>\n<p>A highly scalable real-time graphing system<\/p>\n<\/blockquote>\n<p>carbon<\/p>\n<blockquote>\n<p>Carbon is responsible for receiving metrics over the network, caching them in memory for &ldquo;hot queries&rdquo; from the Graphite-Web application, and persisting them to disk using the Whisper time-series library.<\/p>\n<\/blockquote>\n<p>whisper\/ceres<\/p>\n<p>ceres\u4f1a\u66ff\u4ee3whisper\u3002<\/p>\n<blockquote>\n<p>Whisper is a fixed-size database, similar in design and purpose to RRD (round-robin-database). It provides fast, reliable storage of numeric data over time. Whisper allows for higher resolution (seconds per point) of recent data to degrade into lower resolutions for long-term retention of historical data.<\/p>\n<\/blockquote>\n<h1 id=\"grafana\">grafana<\/h1>\n<blockquote>\n<p>Grafana is an open source, feature rich metrics dashboard and graph editor for Graphite, Elasticsearch, OpenTSDB, Prometheus and InfluxDB.<\/p>\n<\/blockquote>\n<p>\u4e3agraphite\u63d0\u4f9b\u66f4\u597d\u7684\u53ef\u89c6\u5316\u56fe\u5f62\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/grafana\/grafana\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/grafana\/grafana<\/a><\/p>\n<p><a class=\"link\" href=\"http:\/\/grafana.org\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/grafana.org\/<\/a><\/p>\n<h1 id=\"graphios\">graphios<\/h1>\n<blockquote>\n<p>A program to send nagios perf data to graphite(carbon)\/statsd\/librato\/influxdb<\/p>\n<\/blockquote>\n<p>\u53d1\u9001nagios\u6027\u80fd\u6570\u636e\u5230Graphite\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/shawn-sterling\/graphios\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/shawn-sterling\/graphios<\/a><\/p>\n<h1 id=\"ledbetter\">Ledbetter<\/h1>\n<blockquote>\n<p>A simple script for gathering Nagios problem statistics and submitting them to Graphite. It focuses on summary (overall, servicegroup and hostgroup) statistics and writes them to the nagios.problems metrics namespace within Graphite.<\/p>\n<\/blockquote>\n<p>\u53d1\u9001nagios\u6027\u80fd\u6570\u636e\u5230Graphite\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/github\/ledbetter\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/github\/ledbetter<\/a><\/p>\n<h1 id=\"nscp\">NSCP<\/h1>\n<blockquote>\n<p>NSClient is an agent designed originally to work with Nagios but has since evolved into a fully fledged monitoring agent which can be used with numerous monitoring tools (like Icinga, Naemon, OP5, NetEye Opsview etc).<\/p>\n<\/blockquote>\n<p>\u53c8\u53ebNSClient++,\u73b0\u5728\u540c\u65f6\u652f\u6301windows\u548clinux,\u4e3b\u8981\u7528\u6765\u5b89\u88c5\u5230windows\u670d\u52a1\u5668,\u7528\u4e8e\u76d1\u63a7windows\u7cfb\u7edf.<\/p>\n<p><a class=\"link\" href=\"https:\/\/nsclient.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/nsclient.org\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/mickem\/nscp\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/mickem\/nscp<\/a><\/p>\n<hr>\n<p>\u4ecb\u7ecdPlugins<\/p>\n<h1 id=\"monitoring-plugins\">Monitoring Plugins<\/h1>\n<p>Nagios\/naemon\/icinga\/shinken\/centreon\/opsview\/sensu<\/p>\n<p>Office project:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/monitoring-plugins\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/monitoring-plugins<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/www.monitoring-plugins.org\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.monitoring-plugins.org\/<\/a><\/p>\n<p>My plugin project:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/crazy-canux\/pymonitoringplugins\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/crazy-canux\/pymonitoringplugins<\/a><\/p>\n<p>Open source project:<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/crazy-canux\/awesome-monitoring\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/crazy-canux\/awesome-monitoring<\/a><\/p>\n<h1 id=\"monitoring-plugins-1\">monitoring-plugins<\/h1>\n<h2 id=\"negate\">negate<\/h2>\n<p>\u8bbe\u7f6e\u76f8\u53cd\u72b6\u6001<\/p>\n<pre><code>-o \u8bbe\u7f6eok\u5bf9\u5e94\u72b6\u6001\n-w\n-c\n-u\n<\/code><\/pre>\n<h2 id=\"check_http\">check_http<\/h2>\n<pre><code>[-f &lt;ok|warning|critcal|follow|sticky|stickyport&gt;] # \u8df3\u8f6c\n-p PORT # http:80, https:443\n-a &quot;USERNAME&quot;:&quot;PASSWORD&quot;\n-u PATH\n--ssl=1\/-S # https\u9700\u8981ssl\n-s SEARCH\n-e SEARCH,SEARCH...\n-l # \u7528\u5728-r\u6216-R\u524d\u9762,\u8868\u793a\u53ef\u4ee5\u5728\u591a\u884c\u8fdb\u884c\u6b63\u5219\u5339\u914d\n-r # \u6b63\u5219\u5339\u914d\n-R # \u5927\u5c0f\u5199\u4e0d\u654f\u611f\u7684\u6b63\u5219\u5339\u914d\n-C # \u68c0\u67e5\u8bc1\u4e66, \u4e0d\u68c0\u67e5URL\n-t # timeout.\n-w # warning response time\n-c # critical response time\n<\/code><\/pre>\n<h1 id=\"windows-monitoring\">Windows monitoring<\/h1>\n<ul>\n<li>\n<p>check_wmi_plus.pl<\/p>\n<pre><code> IgnoreMyOutDatedPerlModuleVersions\n-m checkfolderfileage -a 'C:' -o '\/tmp' -inc _FileAge=@0:1000 -c 10\n-m check_file_count -a 'F:' -o '\/folder'\n<\/code><\/pre>\n<\/li>\n<li>\n<p>check_snmp_win_services.pl<\/p>\n<p>\u67e5windows\u7684service<\/p>\n<pre><code> -n &lt;name&gt;[,&lt;name2&gt;]... # \u6307\u5b9aservice\u540d\u5b57\uff0c\u9ed8\u8ba4\u5927\u5c0f\u5199\u4e0d\u654f\u611f,\u6b63\u5219\u5339\u914d\uff0c\u9017\u53f7\u5206\u9694\u591a\u4e2aservice\uff0c\u7528display name\u3002\n-N=&lt;n&gt; # \u5339\u914d\u5230service\u6570\u91cf\u5927\u4e8en\u5c31\u62a5\u9519\n-r # \u7cbe\u786e\u5339\u914d\n<\/code><\/pre>\n<\/li>\n<li>\n<p>check_smb_shares.pl<\/p>\n<\/li>\n<\/ul>\n<h1 id=\"linuxunix-monitoring\">Linux\/Unix monitoring<\/h1>\n<ul>\n<li>check_hpasm.pl<\/li>\n<\/ul>\n<h1 id=\"os-x-monitoring\">OS X monitoring<\/h1>\n<ul>\n<li>OSX-Monitoring-Tools<\/li>\n<\/ul>\n<h1 id=\"vitual-machine-monitoring\">Vitual Machine monitoring<\/h1>\n<ul>\n<li>\n<p>check_wmware_api.pl<\/p>\n<\/li>\n<li>\n<p>check_vmware_esx.pl<\/p>\n<\/li>\n<\/ul>\n<h1 id=\"db-monitoring\">DB monitoring<\/h1>\n<ul>\n<li>\n<p>check_mysql_health.pl<\/p>\n<\/li>\n<li>\n<p>check_oracle_health.pl<\/p>\n<\/li>\n<li>\n<p>check_db2_health.pl<\/p>\n<\/li>\n<li>\n<p>check_mssql_health.pl<\/p>\n<pre><code> --name database\/sql\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<h1 id=\"network-monitoring\">Network monitoring<\/h1>\n<ul>\n<li>check_nwc_health.pl<\/li>\n<\/ul>\n<h1 id=\"storage-monitoring\">Storage monitoring<\/h1>\n<ul>\n<li>\n<p>check_snmp_storage.pl<\/p>\n<p>\u8fd4\u56de\u7528\u4e86\u591a\u5c11\u7a7a\u95f4\u3002<\/p>\n<\/li>\n<li>\n<p>check_disk<\/p>\n<p>\u8fd4\u56de\u5269\u4f59\u591a\u5c11\u7a7a\u95f4\u3002<\/p>\n<\/li>\n<\/ul>\n<h1 id=\"log-monitoring\">Log monitoring<\/h1>\n<ul>\n<li>\n<p>check_logfiles.pl<\/p>\n<\/li>\n<li>\n<p>check_events.pl<\/p>\n<\/li>\n<\/ul>\n<h1 id=\"process-monitoring\">Process monitoring<\/h1>\n<ul>\n<li>\n<p>check_snmp_process.pl<\/p>\n<pre><code> -n &lt;name&gt; # process\u540d\u5b57\uff0c\u5927\u5c0f\u5199\u654f\u611f\uff0c\u6b63\u5219\u5339\u914d\uff0cwindows\u9700\u8981\u7528processname.exe\n-r # \u7cbe\u786e\u5339\u914d\n-w minW, maxW\n-c minC, maxC # minC &lt;= minW &lt; maxW &lt; maxC\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<h1 id=\"application-monitoring\">Application monitoring<\/h1>\n<ul>\n<li>\n<p>check_sap_health.pl<\/p>\n<\/li>\n<li>\n<p>check_mailbox_health.pl<\/p>\n<\/li>\n<\/ul>\n<h1 id=\"monitoring\u63d2\u4ef6\u5f00\u53d1\">Monitoring\u63d2\u4ef6\u5f00\u53d1<\/h1>\n<p>Nagios Plugin API:<\/p>\n<p><a class=\"link\" href=\"https:\/\/assets.nagios.com\/downloads\/nagioscore\/docs\/nagioscore\/3\/en\/pluginapi.html\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/assets.nagios.com\/downloads\/nagioscore\/docs\/nagioscore\/3\/en\/pluginapi.html<\/a><\/p>\n<p>Developing Plugins For Use With Embedded Perl:<\/p>\n<p><a class=\"link\" href=\"https:\/\/assets.nagios.com\/downloads\/nagioscore\/docs\/nagioscore\/3\/en\/epnplugins.html\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/assets.nagios.com\/downloads\/nagioscore\/docs\/nagioscore\/3\/en\/epnplugins.html<\/a><\/p>\n<p>Nagios plugin development guidelines:<\/p>\n<p><a class=\"link\" href=\"https:\/\/nagios-plugins.org\/doc\/guidelines.html\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/nagios-plugins.org\/doc\/guidelines.html<\/a><\/p>\n<p>Monitoring Plugin Development Guidelines:<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.monitoring-plugins.org\/doc\/guidelines.html\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/www.monitoring-plugins.org\/doc\/guidelines.html<\/a><\/p>\n<p>Nagios\u4e0d\u662f\u57fa\u4e8eagent\u7684\uff0c\u6240\u4ee5\u63d2\u4ef6\u90fd\u662f\u901a\u8fc7\u534f\u8bae\u6765\u83b7\u53d6\u76d1\u63a7\u4fe1\u606f\u3002<\/p>\n<p>plugin\u9700\u8981\u9075\u5b88\u4e0b\u9762\u89c4\u5219\uff1a<\/p>\n<ol>\n<li>\u81f3\u5c11\u8f93\u51fa\u4e00\u884c\u6587\u672c\u5230STDOUT<\/li>\n<li>\u4e8b\u4ef6\u72b6\u6001\u7531\u63d2\u4ef6\u7684\u8fd4\u56de\u7801\u51b3\u5b9a<\/li>\n<\/ol>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code>just support 4kb data\nshortoutput - $SERVICEOUTPUT$\nperfdata - $SERVICEPERFDATA$\nlongoutput - $LONGSERVICEOUTPUT$\n<\/code><\/pre>\n<p>\u8fd4\u56de\u7801\uff1a<\/p>\n<pre><code>0\uff1a OK\uff08\u7eff\u8272\uff09\n1\uff1a Warning\uff08\u9ec4\u8272\uff09\n2\uff1a Critical\uff08\u7ea2\u8272\uff09\n3\uff1a Unknown\uff08\u6df1\u9ec4\u8272\uff09\n<\/code><\/pre>\n<p>\u9600\u503c\uff1a<\/p>\n<pre><code>10 | 0:10 | &lt;0 or &gt;10 alert\n10: | 10:\u00e6 | &lt;10 alert\n~:10 | -\u00e6:10 | &gt;10 alert\n10:20 | | &lt;10 or &gt;20 alert\n@10:20 | | &gt;=10 and &lt;=20 alert\n<\/code><\/pre>\n<hr>"},{"title":"Zabbix","link":"https:\/\/canuxcheng.com\/post\/metrics_zabbix\/","pubDate":"Fri, 25 Mar 2016 11:15:48 +0000","guid":"https:\/\/canuxcheng.com\/post\/metrics_zabbix\/","description":"<h1 id=\"zabbix\">Zabbix<\/h1>"},{"title":"Hexo","link":"https:\/\/canuxcheng.com\/post\/hexo\/","pubDate":"Tue, 22 Mar 2016 12:59:10 +0000","guid":"https:\/\/canuxcheng.com\/post\/hexo\/","description":"<h1 id=\"hexo\">Hexo<\/h1>\n<h2 id=\"\u4ec0\u4e48\u662fhexo\">\u4ec0\u4e48\u662fhexo<\/h2>\n<blockquote>\n<p>Hexo\u662f\u7528nodejs\u5f00\u53d1\u7684\u5feb\u901f\u3001\u7b80\u6d01\u4e14\u9ad8\u6548\u7684\u535a\u5ba2\u6846\u67b6\uff0c\nHexo \u4f7f\u7528Markdown\uff08\u6216\u5176\u4ed6\u6e32\u67d3\u5f15\u64ce\uff09\u89e3\u6790\u6587\u7ae0\uff0c\u5728\u51e0\u79d2\u5185\uff0c\u5373\u53ef\u5229\u7528\u9753\u4e3d\u7684\u4e3b\u9898\u751f\u6210\u9759\u6001\u7f51\u9875\u3002<\/p>\n<\/blockquote>\n<p>hexo\u6709\u5927\u91cf\u7684\u63d2\u4ef6\u548c\u4e3b\u9898\u3002<\/p>\n<p><a class=\"link\" href=\"https:\/\/hexo.io\/plugins\/\" target=\"_blank\" rel=\"noopener\"\n>plugins<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/hexo.io\/themes\/\" target=\"_blank\" rel=\"noopener\"\n>themes<\/a><\/p>\n<h2 id=\"\u5b89\u88c5hexo\">\u5b89\u88c5hexo<\/h2>\n<p>\u9700\u8981\u5b89\u88c5\u4f9d\u8d56nodejs(\u5305\u62ecnpm)\u548cgit\u3002<\/p>\n<p>\u5b89\u88c5hexo\u547d\u4ee4\u884c\u63d2\u4ef6hexo-cli\uff1a<\/p>\n<pre><code>$sudo npm install hexo-cli -g\n<\/code><\/pre>\n<h2 id=\"next\">Next<\/h2>\n<blockquote>\n<p>Next\u662f\u4e00\u79cd\u6587\u96c5\u7684Hexo\u4e3b\u9898\u3002\n\u4e00\u4e2a\u4e3b\u9898\uff0c\u4e09\u79cd\u5916\u89c2\uff0c\u9009\u60a8\u6240\u597d\u3002\n\u901a\u8fc7\u4e3b\u9898\u4e2d\u7684\u4e3b\u9898\uff08\u4ea6\u79f0Scheme\uff09\uff0c\u60a8\u53ef\u4ee5\u65b9\u4fbf\u5730\u6539\u53d8\u60a8\u535a\u5ba2\u7684\u5916\u89c2\uff0c\u540c\u65f6\u51e0\u4e4e\u6240\u6709\u914d\u7f6e\u540c\u6837\u9002\u7528\u3002<\/p>\n<\/blockquote>\n<p><a class=\"link\" href=\"https:\/\/github.com\/iissnan\/hexo-theme-next\" target=\"_blank\" rel=\"noopener\"\n>\u539f\u751f\u7684Next<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/crazy-canux\/hexo-theme-next\" target=\"_blank\" rel=\"noopener\"\n>\u4f5c\u8005\u7684Next<\/a><\/p>\n<hr>\n<h1 id=\"\u5feb\u901f\u4f7f\u7528\">\u5feb\u901f\u4f7f\u7528<\/h1>\n<h2 id=\"\u521d\u59cb\u5316\">\u521d\u59cb\u5316<\/h2>\n<p>\u521d\u59cb\u5316\u4e00\u4e2ahexo\u7684\u76ee\u5f55\uff1a<\/p>\n<pre><code>$hexo init &lt;folder&gt;\n<\/code><\/pre>\n<h2 id=\"\u5b89\u88c5\u4f9d\u8d56\">\u5b89\u88c5\u4f9d\u8d56<\/h2>\n<p>\u8fdb\u5165hexo\u76ee\u5f55\u5b89\u88c5\u4f9d\u8d56\uff1a<\/p>\n<pre><code>$cd &lt;folder&gt;\n$sudo npm install &lt;package-name&gt;\n<\/code><\/pre>\n<p>\u9ed8\u8ba4\u5b89\u88c5\u4e0b\u5217\u4f9d\u8d56\uff1a<\/p>\n<pre><code>hexo\nhexo-server\nhexo-generator-index\nhexo-generator-archive\nhexo-generator-category\nhexo-generator-tag\nhexo-renderer-ejs\nhexo-renderer-marked\nhexo-renderer-stylus\n<\/code><\/pre>\n<h2 id=\"\u67e5\u770b\u6587\u4ef6\u548c\u76ee\u5f55\">\u67e5\u770b\u6587\u4ef6\u548c\u76ee\u5f55<\/h2>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\u6709\u4e0b\u5217<\/p>\n<p>\u6587\u4ef6\uff1a<\/p>\n<pre><code>_config.yml\ndb.json\npackage.json\n<\/code><\/pre>\n<p>\u76ee\u5f55\uff1a<\/p>\n<pre><code>node_modules\nscaffolds\nsource\nthemes\n<\/code><\/pre>\n<h2 id=\"\u751f\u6210\u9759\u6001\u6587\u4ef6\">\u751f\u6210\u9759\u6001\u6587\u4ef6<\/h2>\n<pre><code>$hexo g\n$hexo generate\n<\/code><\/pre>\n<h2 id=\"\u542f\u52a8\u672c\u5730\u670d\u52a1\u5668\">\u542f\u52a8\u672c\u5730\u670d\u52a1\u5668<\/h2>\n<pre><code>$hexo s\n$hexo server\n<\/code><\/pre>\n<p>\u7528\u6d4f\u89c8\u5668\u6253\u5f00\u94fe\u63a5\u5373\u53ef\u672c\u5730\u67e5\u770b\u9ed8\u8ba4\u535a\u5ba2\u3002<\/p>\n<h2 id=\"\u5199\u535a\u6587\">\u5199\u535a\u6587<\/h2>\n<pre><code>$hexo new post &lt;article-name&gt;\n<\/code><\/pre>\n<p>\u7f16\u8f91\u8fd9\u7bc7\u6587\u7ae0\u3002<\/p>\n<h2 id=\"\u6e05\u7406\u751f\u6210\u6587\u4ef6\u548c\u7f13\u5b58\">\u6e05\u7406\u751f\u6210\u6587\u4ef6\u548c\u7f13\u5b58<\/h2>\n<pre><code>$hexo clean\n<\/code><\/pre>\n<p>\u518d\u6b21\u8fd0\u884chexo g\u548chexo s\u67e5\u770b\u3002<\/p>\n<h2 id=\"\u5b89\u88c5\u90e8\u7f72\u63d2\u4ef6\">\u5b89\u88c5\u90e8\u7f72\u63d2\u4ef6<\/h2>\n<pre><code>$sudo npm install hexo-deployer-git --save\n<\/code><\/pre>\n<p>\u4fee\u6539\u5168\u5c40\u914d\u7f6e\u6587\u4ef6\uff0c\u53c2\u8003\u63d2\u4ef6\u7684<a class=\"link\" href=\"https:\/\/github.com\/hexojs\/hexo-deployer-git\" target=\"_blank\" rel=\"noopener\"\n>github<\/a>\n\u9488\u5bf9github\u9700\u8981\u65b0\u5efa\u4e00\u4e2a\u540d\u5b57\u4e3a&lt;your-github-name&gt;.github.io\u7684\u4ed3\u5e93\u3002<\/p>\n<h2 id=\"\u90e8\u7f72\u5230github\">\u90e8\u7f72\u5230github<\/h2>\n<pre><code>$hexo d\n$hexo deploy\n<\/code><\/pre>\n<p>\u5728\u6d4f\u89c8\u5668\u6253\u5f00http:\/\/&lt;your-github-name&gt;.github.io\/\u67e5\u770b\u535a\u5ba2\u3002<\/p>\n<hr>\n<h1 id=\"\u914d\u7f6e\">\u914d\u7f6e<\/h1>\n<h2 id=\"\u5168\u5c40\u914d\u7f6e\">\u5168\u5c40\u914d\u7f6e<\/h2>\n<p>\u5168\u5c40\u914d\u7f6e\u6587\u4ef6\u662f&lt;folder&gt;\/_config.yml<\/p>\n<blockquote>\n<blockquote>\n<p># Hexo Configuration<\/p>\n<\/blockquote>\n<\/blockquote>\n<blockquote>\n<p>## Docs: <a class=\"link\" href=\"https:\/\/hexo.io\/docs\/configuration.html\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/hexo.io\/docs\/configuration.html<\/a><\/p>\n<\/blockquote>\n<blockquote>\n<p>## Source: <a class=\"link\" href=\"https:\/\/github.com\/hexojs\/hexo\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/hexojs\/hexo\/<\/a><\/p>\n<\/blockquote>\n<blockquote>\n<blockquote>\n<p># Site<\/p>\n<\/blockquote>\n<\/blockquote>\n<blockquote>\n<pre><code> title:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> subtitle:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> description:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> author:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> language: zh-Hans\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> timezone: Asia\/Shanghai\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<blockquote>\n<p># URL<\/p>\n<\/blockquote>\n<\/blockquote>\n<blockquote>\n<p>## If your site is put in a subdirectory, set url as &lsquo;<a class=\"link\" href=\"http:\/\/yoursite.com\/child%27\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/yoursite.com\/child'<\/a> and root as &lsquo;\/child\/&rsquo;<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code> url: http:\/\/&lt;your-github-name&gt;.github.io\/\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> root: \/\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> permalink: :year\/:month\/:day\/:title\/\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> permalink_defaults:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<blockquote>\n<p># Directory<\/p>\n<\/blockquote>\n<\/blockquote>\n<blockquote>\n<pre><code> source_dir: source\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> public_dir: public\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> tag_dir: tags\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> archive_dir: archives\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> category_dir: categories\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> code_dir: downloads\/code\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> i18n_dir: :lang\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> skip_render:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<blockquote>\n<p># Writing<\/p>\n<\/blockquote>\n<\/blockquote>\n<blockquote>\n<pre><code> new_post_name: :title.md # File name of new posts\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> default_layout: post # post | page | draft\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> titlecase: false # Transform title into titlecase\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> external_link: true # Open external links in new tab\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> filename_case: 0\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> render_drafts: false\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> post_asset_folder: false\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> relative_link: false\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> future: true\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> highlight:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> enable: true\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> line_number: true\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> auto_detect: true\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> tab_replace: ''\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<blockquote>\n<p># Category &amp; Tag<\/p>\n<\/blockquote>\n<\/blockquote>\n<blockquote>\n<pre><code> default_category: uncategorized\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> category_map:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> tag_map:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<blockquote>\n<p># Date \/ Time format<\/p>\n<\/blockquote>\n<\/blockquote>\n<blockquote>\n<p>## Hexo uses Moment.js to parse and display date<\/p>\n<\/blockquote>\n<blockquote>\n<p>## You can customize the date format as defined in<\/p>\n<\/blockquote>\n<blockquote>\n<p>## <a class=\"link\" href=\"http:\/\/momentjs.com\/docs\/#\/displaying\/format\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/momentjs.com\/docs\/#\/displaying\/format\/<\/a><\/p>\n<\/blockquote>\n<blockquote>\n<pre><code> date_format: YYYY-MM-DD\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> time_format: HH:mm:ss\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<blockquote>\n<p># Pagination<\/p>\n<\/blockquote>\n<\/blockquote>\n<blockquote>\n<p>## Set per_page to 0 to disable pagination<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code> per_page: 10\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> pagination_dir: page\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<blockquote>\n<p># Extensions<\/p>\n<\/blockquote>\n<\/blockquote>\n<blockquote>\n<p>## Plugins: <a class=\"link\" href=\"https:\/\/hexo.io\/plugins\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/hexo.io\/plugins\/<\/a><\/p>\n<\/blockquote>\n<blockquote>\n<p>## Themes: <a class=\"link\" href=\"https:\/\/hexo.io\/themes\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/hexo.io\/themes\/<\/a><\/p>\n<\/blockquote>\n<blockquote>\n<pre><code> theme: hexo-theme-canux\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> Plugins:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> - hexo-deployer-git\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<blockquote>\n<p># Extend plugins<\/p>\n<\/blockquote>\n<\/blockquote>\n<blockquote>\n<p>## deploy<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code> deploy:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> type: git\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> repo:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> github: https:\/\/github.com\/crazy-canux\/crazy-canux.github.io.git,master\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> coding: https:\/\/git.coding.net\/Canux\/Canux.git,master\n<\/code><\/pre>\n<\/blockquote>\n<h2 id=\"\u4e3b\u9898\u914d\u7f6e\">\u4e3b\u9898\u914d\u7f6e<\/h2>\n<p>hexo\u5b98\u65b9\u9ed8\u8ba4\u4e3b\u9898\u662f&lt;folder&gt;\/themes\/landscape\u3002<\/p>\n<p>\u4e3b\u9898\u914d\u7f6e\u6587\u4ef6\u662f&lt;folder&gt;\/themes\/landscape\/_config.yml<\/p>\n<p>\u73b0\u5728\u5c06\u9ed8\u8ba4\u4e3b\u9898\u66ff\u6362\u6210\u81ea\u5df1\u559c\u6b22\u7684\u4e3b\u9898\uff1a<\/p>\n<pre><code>cd &lt;folder&gt;\/themes\ngit clone &lt;github-url-of-your-favourite-theme&gt;\n<\/code><\/pre>\n<p>\u7136\u540e\u5c06\u5168\u5c40\u914d\u7f6e\u7684 theme: landscape \u6539\u4e3a theme: &lt;your-favourite-theme-name&gt;<\/p>\n<hr>\n<h1 id=\"\u90e8\u7f72\">\u90e8\u7f72<\/h1>\n<p>\u90e8\u7f72\u5230github\u548ccoding(gitcafe)\uff1a<\/p>\n<pre><code>$hexo clean\n$hexo g\n$hexo d\n<\/code><\/pre>\n<p>github\u8bbf\u95eehttp:\/\/<!-- raw HTML omitted -->.github.io\u5373\u53ef\u3002<\/p>\n<p>coding\u8bbf\u95eehttp:\/\/<!-- raw HTML omitted -->.coding.me\/<!-- raw HTML omitted --><\/p>\n<p>\u7ed1\u5b9a\u81ea\u5df1\u7684\u57df\u540d\uff1a<\/p>\n<ol>\n<li>\u5728\u57df\u540d\u4f9b\u5e94\u5546\u8d2d\u4e70\u57df\u540d\u540e\u6dfb\u52a0\u89e3\u6790\uff0c\u8bb0\u5f55\u7c7b\u578bA\u6216\u8005CNAME\uff0c\u4e3b\u673a\u7c7b\u578b@\u6216\u8005www\uff0c\u8bb0\u5f55\u503c\u53ef\u4ee5\u662fhttp:\/\/<!-- raw HTML omitted -->.github.io\u6216\u8005\u901a\u8fc7ping\u83b7\u53d6\u7684ip\u5730\u5740\u3002<\/li>\n<li>\u5728<!-- raw HTML omitted -->\/source\/\u65b0\u5efa\u6587\u4ef6CNAME\uff0c\u6dfb\u52a0\u4f60\u8d2d\u4e70\u7684\u57df\u540d<!-- raw HTML omitted -->.com\u3002<\/li>\n<li>\u6b63\u5e38\u90e8\u7f72\u5230github\u3002<\/li>\n<li>\u8bbf\u95eehttp:\/\/<!-- raw HTML omitted -->.com\u5373\u53ef\u3002<\/li>\n<\/ol>\n<hr>\n<h1 id=\"\u5b89\u88c5hexo\u63d2\u4ef6\">\u5b89\u88c5hexo\u63d2\u4ef6<\/h1>\n<p><a class=\"link\" href=\"https:\/\/hexo.io\/plugins\/\" target=\"_blank\" rel=\"noopener\"\n>plugins<\/a><\/p>\n<pre><code>$sudo npm install &lt;plugin-name&gt; --save\n<\/code><\/pre>\n<h1 id=\"\u914d\u7f6ehexo\u63d2\u4ef6\">\u914d\u7f6ehexo\u63d2\u4ef6<\/h1>\n<p>\u5168\u5c40\u914d\u7f6e\u6587\u4ef6\u662f&lt;folder&gt;\/_config.yml<\/p>\n<blockquote>\n<blockquote>\n<p># Extensions<\/p>\n<\/blockquote>\n<\/blockquote>\n<blockquote>\n<p>## Plugins: <a class=\"link\" href=\"https:\/\/hexo.io\/plugins\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/hexo.io\/plugins\/<\/a><\/p>\n<\/blockquote>\n<blockquote>\n<p>## Themes: <a class=\"link\" href=\"https:\/\/hexo.io\/themes\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/hexo.io\/themes\/<\/a><\/p>\n<\/blockquote>\n<blockquote>\n<pre><code> theme: next\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> Plugins:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> - hexo-deployer-git\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># Extend plugins<\/p>\n<\/blockquote>\n<blockquote>\n<p>## deploy<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code> deploy:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> type: git\nrepo: git@github.com:&lt;your-github-name&gt;\/&lt;your-github-name&gt;.github.io.git\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> branch: master\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> message:\n<\/code><\/pre>\n<\/blockquote>\n<h1 id=\"\u7ad9\u70b9\u5730\u56fe\">\u7ad9\u70b9\u5730\u56fe<\/h1>\n<pre><code>$npm install hexo-generator-sitemap --save\n<\/code><\/pre>\n<blockquote>\n<p>## sitemap<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code> sitemap:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> path: sitemap.xml\n<\/code><\/pre>\n<\/blockquote>\n<p><a class=\"link\" href=\"https:\/\/github.com\/hexojs\/hexo-generator-sitemap\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/hexojs\/hexo-generator-sitemap<\/a><\/p>\n<h1 id=\"rss\">RSS<\/h1>\n<pre><code>$npm install hexo-generator-feed --save\n<\/code><\/pre>\n<blockquote>\n<p>## feed<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code> feed:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> type: atom\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> path: atom.xml\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> limit: 20\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> hub:\n<\/code><\/pre>\n<\/blockquote>\n<p><a class=\"link\" href=\"https:\/\/github.com\/hexojs\/hexo-generator-feed\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/hexojs\/hexo-generator-feed<\/a><\/p>\n<h1 id=\"seo\u4f18\u5316\">SEO\u4f18\u5316<\/h1>\n<pre><code>$npm install hexo-generator-seo-friendly-sitemap --save\n<\/code><\/pre>\n<blockquote>\n<pre><code> sitemap:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> path: sitemap.xml\n<\/code><\/pre>\n<\/blockquote>\n<p><a class=\"link\" href=\"https:\/\/github.com\/ludoviclefevre\/hexo-generator-seo-friendly-sitemap\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/ludoviclefevre\/hexo-generator-seo-friendly-sitemap<\/a><\/p>\n<hr>\n<h1 id=\"next-1\">Next<\/h1>\n<p>\u4ee5hexo\u4e3b\u9898next\u4e3a\u4f8b<\/p>\n<p>\u4e2d\u6587\u6587\u6863\uff1a<\/p>\n<p><a class=\"link\" href=\"http:\/\/theme-next.iissnan.com\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/theme-next.iissnan.com\/<\/a><\/p>\n<p>\u82f1\u6587\u6587\u6863\uff1a<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/iissnan\/hexo-theme-next\/blob\/master\/README.en.md\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/iissnan\/hexo-theme-next\/blob\/master\/README.en.md<\/a><\/p>\n<h1 id=\"\u4e3b\u9898\u914d\u7f6e\u6587\u4ef6\">\u4e3b\u9898\u914d\u7f6e\u6587\u4ef6<\/h1>\n<p>\u4e3b\u9898\u914d\u7f6e\u6587\u4ef6\u5728\uff1a<\/p>\n<p>&lt;folder&gt;\/themes\/next\/_config.yml<\/p>\n<h1 id=\"\u4e3b\u9898\u914d\u7f6e-1\">\u4e3b\u9898\u914d\u7f6e<\/h1>\n<blockquote>\n<p># &mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;<\/p>\n<\/blockquote>\n<blockquote>\n<p># \u7ad9\u70b9\u4fe1\u606f\u8bbe\u7f6e<\/p>\n<\/blockquote>\n<blockquote>\n<p># &mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;<\/p>\n<\/blockquote>\n<blockquote>\n<p># \u5c06\u5236\u4f5c\u597d\u7684favicon\u56fe\u6807\u653e\u5230\/source\u91cc\u9762\u3002<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>favicon: \/favicon.ico\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># SEO\u4f18\u5316\u7684\u5173\u952e\u5b57\u3002<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>keywords: &quot;Canux, CHENG, blog&quot;\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># \u6307\u5b9a\u7ad9\u70b9\u7684\u8d77\u59cb\u65e5\u671f\u3002<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>since: 2013\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># &mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;<\/p>\n<\/blockquote>\n<blockquote>\n<p># \u83dc\u5355\u8bbe\u7f6e<\/p>\n<\/blockquote>\n<blockquote>\n<p># &mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;<\/p>\n<\/blockquote>\n<blockquote>\n<p># \u9876\u90e8\u83dc\u5355\u680f<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>menu:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> home: \/\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> about: \/about\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> categories: \/categories\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> tags: \/tags\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> archives: \/archives\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> #commonweal: \/404.html\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># \u83dc\u5355\u680f\u56fe\u6807,\u4f7f\u7528fontawsome<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>menu_icons:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> enable: true\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> home: home\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> about: user\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> categories: th\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> tags: tags\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> archives: archive\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> #commonweal: heartbeat\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># &mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;<\/p>\n<\/blockquote>\n<blockquote>\n<p># \u4e3b\u9898\u65b9\u6848\u8bbe\u8ba1: Must | Mist | Pisces<\/p>\n<\/blockquote>\n<blockquote>\n<p># &mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>scheme: Muse\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># &mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;<\/p>\n<\/blockquote>\n<blockquote>\n<p># \u6350\u8d60\u8bbe\u7f6e<\/p>\n<\/blockquote>\n<blockquote>\n<p># &mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>reward_comment: \u60a8\u7684\u652f\u6301\u662f\u6211\u521b\u4f5c\u7684\u52a8\u529b!\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code>wechatpay: \/images\/myimages\/wechatpay.jpg\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code>alipay: \/images\/myimages\/alipay.jpg\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># &mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;<\/p>\n<\/blockquote>\n<blockquote>\n<p># \u4fa7\u8fb9\u680f\u8bbe\u7f6e<\/p>\n<\/blockquote>\n<blockquote>\n<p># &mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;<\/p>\n<\/blockquote>\n<blockquote>\n<p># \u793e\u4ea4\u4fe1\u606f<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>social:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> GitHub: https:\/\/github.com\/crazy-canux\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> Stackoverflow: http:\/\/stackoverflow.com\/\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> LinkedIn: http:\/\/www.linkedin.com\/profile\/preview?locale=zh_CN&amp;trk=prof-0-sb-preview-primary-button\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> E-mail: mailto:canuxcheng@gmail.com\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># \u793e\u4ea4\u4fe1\u606f\u56fe\u6807\uff0c\u4f7f\u7528fontawsome\u3002<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>social_icons:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> enable: true\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> GitHub: github\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> LinkedIn: linkedin\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> Stackoverflow: stack-overflow\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> E-mail: envelope\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># \u53cb\u60c5\u94fe\u63a5<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>links_title: Links\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code>links:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> CSDN: http:\/\/bbs.csdn.net\/home\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> 51CTO: http:\/\/bbs.51cto.com\/\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> ChinaUnix: http:\/\/bbs.chinaunix.net\/\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> ITPUB: http:\/\/www.itpub.net\/forum.php\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># \u4fa7\u8fb9\u680f\u56fe\u50cf<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>avatar: \/images\/myimages\/avatar.jpg\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># TOC(table of contents)\u8bbe\u7f6e<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>toc:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> enable: true\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> number: true\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># \u8bbe\u7f6e 4.0 International \u8bb8\u53ef\u8bc1: by | by-nc | by-nc-nd | by-nc-sa | by-nd | by-sa | zero<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>creative_commons: zero\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># \u4fa7\u8fb9\u680f\u4f4d\u7f6e: left | right<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>sidebar:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> position: left\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># \u4fa7\u8fb9\u680f\u663e\u793a\u65b9\u5f0f\uff1a post | always | hide | remove<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>display: post\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># &mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;<\/p>\n<\/blockquote>\n<blockquote>\n<p># \u5176\u5b83\u8bbe\u7f6e<\/p>\n<\/blockquote>\n<blockquote>\n<p># &mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;<\/p>\n<\/blockquote>\n<blockquote>\n<p># \u4f7f\u7528Custom Logo.<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>custom_logo:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> enabled: false\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> image:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># \u4ee3\u7801\u9ad8\u4eae\u4e3b\u9898: normal | night | night eighties | night blue | night bright<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>highlight_theme: night eighties\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># \u81ea\u52a8\u6eda\u52a8\u9875\u9762<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>scroll_to_more: true\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># \u81ea\u52a8\u6458\u5f55<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>auto_excerpt:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> enable: true\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> length: 150\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># \u4f7f\u7528Lato font<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>use_font_lato: true\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># &mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;<\/p>\n<\/blockquote>\n<blockquote>\n<p># \u7b2c\u4e09\u65b9\u63d2\u4ef6: \u4e00\u822c\u90fd\u9700\u8981\u53bb\u63d2\u4ef6\u7684\u5b98\u7f51\u6ce8\u518c\u4f7f\u7528\u3002<\/p>\n<\/blockquote>\n<blockquote>\n<p># &mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;<\/p>\n<\/blockquote>\n<blockquote>\n<p># MathJax Support<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>mathjax: true\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<\/blockquote>\n<blockquote>\n<p># Google Analytics - US<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>#google_analytics:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># Facebook sdk Analytics - US<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>facebook_sdk:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> enable: false\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> app_id: #&lt;app_id&gt;\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> fb_admin: #&lt;user_id&gt;\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> like_button: #true\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> webmaster: #true\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># CNZZ Analytics - CN<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>cnzz_siteid: ******\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># leancloud Analytics - CN<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>leancloud_visitors:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> enable: false\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> app_id: #&lt;app_id&gt;\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> app_key: #&lt;app_key&gt;\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># Baidu Analytics<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>#baidu_analytics: ******\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># Tencent Analytics<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>#tencent_analytics: ******\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<\/blockquote>\n<blockquote>\n<p># Disqus - US<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>#disqus_shortname: ******\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># Duoshuo - CN<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>duoshuo_shortname: ******\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># Make duoshuo show UA<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>duoshuo_info:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> ua_enable: true\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> admin_enable: false\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> user_id:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code> #admin_nickname: ROOT\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># Make duoshuo show hot artical<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>duoshuo_hotartical: true\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<\/blockquote>\n<blockquote>\n<p># AddThis - US<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>#add_this_id:\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># JiaThis - CN<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>jiathis: true\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># Baidu Share<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>#baidushare: true\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># Duoshuo Share<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>#duoshuo_share: true\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<\/blockquote>\n<blockquote>\n<p># Swiftype - US<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>swiftype_key: ******\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># Tinysou - CN<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>#tinysou_Key\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p>#! &mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;<\/p>\n<\/blockquote>\n<blockquote>\n<p>#! \u8c28\u614e\u7f16\u8f91\u7684\u4e3b\u9898\u4fe1\u606f<\/p>\n<\/blockquote>\n<blockquote>\n<p>#! &mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;&mdash;<\/p>\n<\/blockquote>\n<blockquote>\n<p># \u4fa7\u8fb9\u680f\u79fb\u52a8\u63d2\u4ef6 Motion<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>use_motion: true\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># \u56fe\u7247\u5f39\u51fa\u63d2\u4ef6 Fancybox<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>fancybox: true\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># Static files<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>vendors: vendors\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code>css: css\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code>js: js\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<pre><code>images: images\n<\/code><\/pre>\n<\/blockquote>\n<blockquote>\n<p># Theme version<\/p>\n<\/blockquote>\n<blockquote>\n<pre><code>version: 0.5.0\n<\/code><\/pre>\n<\/blockquote>"},{"title":"Hugo","link":"https:\/\/canuxcheng.com\/post\/hugo\/","pubDate":"Mon, 01 Apr 2013 12:49:49 +0000","guid":"https:\/\/canuxcheng.com\/post\/hugo\/","description":"<h1 id=\"hugo\">Hugo<\/h1>\n<p>go\u5f00\u53d1\u7684\u9759\u6001\u7ad9\u70b9\u751f\u6210\u5668.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/gohugoio\/hugo\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/gohugoio\/hugo<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/gohugo.io\/\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/gohugo.io\/<\/a><\/p>\n<h2 id=\"\u642d\u5efa\u535a\u5ba2\">\u642d\u5efa\u535a\u5ba2<\/h2>\n<p>\u521b\u5efa\u73af\u5883:<\/p>\n<pre><code># linux, ubuntu18.04\u9ed8\u8ba4\u662f\u975eextended, 19.04 \u9ed8\u8ba4extended\u3002\n$ sudo apt-get install hugo\n# extended\u652f\u6301Sass\/scss\n$ sudo snap install hugo --channel=extended\n# windows\nPATH: C:\\Hugo\\bin\\hugo.exe\n<\/code><\/pre>\n<p>\u6d4b\u8bd5\u5b89\u88c5:<\/p>\n<pre><code>$ hugo help\n<\/code><\/pre>\n<p>\u521b\u5efahugo\u9879\u76ee:<\/p>\n<pre><code>$ cd \/home\/canux\/sites\n&gt; cd C:\\hugo\\sites\n$ hugo new site canuxcheng.com\n<\/code><\/pre>\n<p>\u751f\u6210\u4e0b\u5217\u6587\u4ef6\u548c\u76ee\u5f55:<\/p>\n<pre><code>config.toml\narchetypes\ncontent # md \u6587\u4ef6\ndata\nlayouts\nstatic\nthemes\nbytes\n<\/code><\/pre>\n<hr>\n<h2 id=\"theme\">Theme<\/h2>\n<p><a class=\"link\" href=\"https:\/\/github.com\/gohugoio\/hugoThemes\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/gohugoio\/hugoThemes<\/a><\/p>\n<p>\u4e0b\u8f7d\u6240\u6709\u4e3b\u9898:<\/p>\n<pre><code>cd blog\ngit clone --depth 1 --recursive https:\/\/github.com\/gohugoio\/hugoThemes.git themes\n<\/code><\/pre>\n<p>\u4e0b\u8f7d\u5355\u4e2a\u4e3b\u9898\uff1a<\/p>\n<pre><code>cd themes\ngit clone url\n<\/code><\/pre>\n<p>\u5728hugo.toml\u6dfb\u52a0\u4e3b\u9898\uff1a<\/p>\n<pre><code>theme = 'name'\n<\/code><\/pre>\n<p>\u521b\u5efa\u4e3b\u9898:<\/p>\n<pre><code>$ hugo new theme [name]\n<\/code><\/pre>\n<p>\u6dfb\u52a0\u81ea\u5df1\u7684\u4e3b\u9898:<\/p>\n<pre><code>$ git submodule add https:\/\/github.com\/crazy-canux\/hugo-theme-canux.git\n<\/code><\/pre>\n<p>\u514b\u9686\u4e3b\u9898\uff1a<\/p>\n<pre><code>$ git submodule init\n$ git submodule update\n<\/code><\/pre>\n<hr>\n<h2 id=\"\u521b\u5efa\u9875\u9762\">\u521b\u5efa\u9875\u9762<\/h2>\n<pre><code>## content\/about.md\n$ hugo new about.md\n<\/code><\/pre>\n<h2 id=\"\u521b\u5efa\u6587\u7ae0\">\u521b\u5efa\u6587\u7ae0<\/h2>\n<pre><code>## content\/post\/page.md\n$ hugo new post\/Shell.md\n<\/code><\/pre>\n<hr>\n<h2 id=\"\u672c\u5730\u6d4b\u8bd5\">\u672c\u5730\u6d4b\u8bd5<\/h2>\n<pre><code> $ hugo server --theme=hyde --buildDrafts\n$ firefox http:\/\/localhost:1313\n<\/code><\/pre>\n<hr>\n<h2 id=\"\u90e8\u7f72\u5230github\">\u90e8\u7f72\u5230github<\/h2>\n<p>\u5148\u5728github\u521b\u5efarepo.<\/p>\n<pre><code>$ hugo --theme=&lt;theme&gt; --baseUrl=&quot;https:\/\/&lt;user&gt;.github.io\/&quot;\n<\/code><\/pre>\n<p>push\u5230github:<\/p>\n<pre><code>$ cd public\n$ git init\n$ git remote add origin https:\/\/github.com\/&lt;user&gt;\/&lt;user&gt;.github.io.git\n$ git add -A\n$ git commit -m &quot;first push.&quot;\n$ git push -u origin master\n<\/code><\/pre>\n<p>\u5f00\u53d1\u73af\u5883\u8fc1\u79fb\uff1a<\/p>\n<pre><code>$ git clone ...\n$ rm -rf .\/public .\/theme\/&lt;theme&gt;\n$ git submodule update --init --recursive\n$ cd .\/public; git checkout master\n<\/code><\/pre>"},{"title":"Pelican","link":"https:\/\/canuxcheng.com\/post\/pelican\/","pubDate":"Mon, 01 Apr 2013 12:49:49 +0000","guid":"https:\/\/canuxcheng.com\/post\/pelican\/","description":"<h1 id=\"pelican\">Pelican<\/h1>\n<p>python\u5f00\u53d1\u7684\u9759\u6001\u7ad9\u70b9\u751f\u6210\u5668.<\/p>\n<p><a class=\"link\" href=\"http:\/\/blog.getpelican.com\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/blog.getpelican.com\/<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/getpelican\/pelican\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/getpelican\/pelican<\/a><\/p>\n<p><a class=\"link\" href=\"http:\/\/pelican-docs-zh-cn.readthedocs.io\/en\/latest\/getting_started.html\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/pelican-docs-zh-cn.readthedocs.io\/en\/latest\/getting_started.html<\/a><\/p>\n<p><a class=\"link\" href=\"http:\/\/pelican-zh.readthedocs.io\/en\/latest\/zh-cn\/\" target=\"_blank\" rel=\"noopener\"\n>http:\/\/pelican-zh.readthedocs.io\/en\/latest\/zh-cn\/<\/a><\/p>\n<h1 id=\"\u642d\u5efa\u535a\u5ba2\">\u642d\u5efa\u535a\u5ba2<\/h1>\n<p>\u521b\u5efa\u73af\u5883:<\/p>\n<pre><code>$mkdir blog_pelican\n$cd blog_pelican\n$virtualenv .venv\n$source .venv\/bin\/activate\n$pip install pelican\n$pip install markdown\n<\/code><\/pre>\n<p>\u521b\u5efapelican\u9879\u76ee:<\/p>\n<pre><code>$pelican-quickstart\n<\/code><\/pre>\n<p>\u751f\u6210\u4e0b\u5217\u6587\u4ef6\u548c\u76ee\u5f55:<\/p>\n<pre><code>publishconf.py # \u4e3b\u914d\u7f6e\u6587\u4ef6\npelicanconf.py # \u53d1\u5e03\u7684\u914d\u7f6e\u6587\u4ef6\nfabfile.py # fabric\u914d\u7f6e\u6587\u4ef6\nMakefile # make\u914d\u7f6e\u6587\u4ef6\ndevelop_server.sh # \u7528\u4e8e\u5f00\u542f\u6d4b\u8bd5\u670d\u52a1\u5668\ncontent # \u7528\u4e8e\u5b58\u653e\u6240\u6709\u6587\u7ae0\noutput # \u9759\u6001\u751f\u6210\u6587\u4ef6\n<\/code><\/pre>\n<h1 id=\"\u53d1\u5e03\u7ad9\u70b9\">\u53d1\u5e03\u7ad9\u70b9<\/h1>\n<p>pelican\u90e8\u7f72\u535a\u5ba2:<\/p>\n<pre><code># \u5c06rst\u6216md\u683c\u5f0f\u8f6c\u6362\u6210html,\u9ed8\u8ba4\u5bfc\u5165\u5230output.\n$pelican content\n$pelican content -s pelicanconf.py\n# \u542f\u52a8web\u670d\u52a1\u5668\u9884\u89c8\n$cd output\n$python -m pelican.server\n$python2.7 -m SimpleHTTPServer\n$python3 -m http.server\n$firefox http:\/\/localhost:8000\/\n# \u90e8\u7f72\u7ad9\u70b9\n# \u4e00\u822cpublishconf.py\u5bfc\u5165pelicanconf.py\u5373\u53ef\uff0c\u914d\u7f6e\u4e00\u6837\uff0e\n$pelican content -s publishconf.py\n<\/code><\/pre>\n<p>fabric\u90e8\u7f72\u535a\u5ba2:<\/p>\n<pre><code>$fab github # \u4e00\u952e\u90e8\u7f72\u5230github\/coding.\n<\/code><\/pre>\n<p>make\u90e8\u7f72\u535a\u5ba2:<\/p>\n<pre><code>$make github # \u4e00\u952e\u90e8\u7f72\u5230github\/coding.\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u914d\u7f6e\">\u914d\u7f6e<\/h1>\n<p>pelicanconf.py<\/p>\n<p>publishconf.py<\/p>\n<p>\u53c2\u8003pelican\u548chexo\u7684\u914d\u7f6e\uff1a<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/crazy-canux\/blog_hexo\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/crazy-canux\/blog_hexo<\/a><\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/crazy-canux\/blog_pelican\" target=\"_blank\" rel=\"noopener\"\n>https:\/\/github.com\/crazy-canux\/blog_pelican<\/a><\/p>\n<hr>\n<h1 id=\"theme\">Theme<\/h1>\n<p>\u6dfb\u52a0\u4e3b\u9898<\/p>\n<pre><code>$cd blog_pelican\n$git submodule add https:\/\/github.com\/getpelican\/pelican-themes.git themes\n<\/code><\/pre>\n<p>\u5b89\u88c5\u4e3b\u9898\uff1a<\/p>\n<pre><code>$cd pelican-themes\n$pelican-themes -i bootstrap2\n<\/code><\/pre>\n<p>\u5728pelicanconf.py\u6dfb\u52a0\u4e3b\u9898\uff1a<\/p>\n<pre><code>THEME = 'bootstrap2'\n<\/code><\/pre>\n<hr>\n<h1 id=\"plugin\">Plugin<\/h1>\n<p>\u6dfb\u52a0\u63d2\u4ef6\uff1a<\/p>\n<pre><code>$cd blog_pelican\n$git submodule add https:\/\/github.com\/getpelican\/pelican-plugins.git plugins\n<\/code><\/pre>\n<hr>\n<h1 id=\"\u90e8\u7f72\u5230github\">\u90e8\u7f72\u5230github<\/h1>\n<p>\u5728makefile\u6dfb\u52a0\u4e09\u4e2a\u53d8\u91cf\uff1a<\/p>\n<pre><code>GITHUB_BRANCH=master\nGITHUB_URL=https:\/\/github.com\/crazy-canux\/crazy-canux.github.io.git\n<\/code><\/pre>\n<p>\u4fee\u6539makefile:<\/p>\n<pre><code>github: publish\ncd $(OUTPUTDIR); git init; git remote add origin $(GITHUB_URL); git add -A; git commit -m &quot;[$(shell date +%Y%m%d)]update&quot;; git push -f -u origin $(GITHUB_BRANCH)\n<\/code><\/pre>\n<p>\u4e00\u952e\u90e8\u7f72\uff1a<\/p>\n<pre><code>$make github\n<\/code><\/pre>"},{"title":"About","link":"https:\/\/canuxcheng.com\/about\/","pubDate":"Mon, 01 Apr 2013 12:49:49 +0800","guid":"https:\/\/canuxcheng.com\/about\/","description":"<h1 id=\"\u4f5c\u8005\u7b80\u4ecbsynopsis\">\u4f5c\u8005\u7b80\u4ecb(Synopsis)<\/h1>\n<p>\u7a0b \u4f1f<\/p>\n<p>Canux CHENG<\/p>\n<p>Tech Stack\uff1aDevSecOps, Cloud, AWS, GCP, Azure, Terraform, Kubernetes, Golang, Python, TS\/JS\/NodeJS, Linux<\/p>\n<hr>\n<h1 id=\"\u6280\u672f\u4ea4\u6d41contact\">\u6280\u672f\u4ea4\u6d41(Contact)<\/h1>\n<p>\u4e86\u89e3\u9879\u76ee\u60c5\u51b5\uff0c\u6b22\u8fce\u8ffd\u8e2a\u6211\u7684Github<\/p>\n<p>Welcome to follow my github, to see the project.<\/p>\n<p><a class=\"link\" href=\"https:\/\/github.com\/crazy-canux\" target=\"_blank\" rel=\"noopener\"\n>Follow<\/a><\/p>\n<p>\u67e5\u770b\u7b80\u5386\uff0c\u6b22\u8fce\u8ffd\u8e2a\u6211\u7684LinkedIn<\/p>\n<p>Welcome to follow my LinkedIn, to see my resume.<\/p>\n<p><a class=\"link\" href=\"https:\/\/www.linkedin.com\/in\/canux-cheng-4b5b23ab\/\" target=\"_blank\" rel=\"noopener\"\n>Follow<\/a><\/p>\n<hr>\n<h1 id=\"\u4e2a\u4eba\u90ae\u7bb1e-mail\">\u4e2a\u4eba\u90ae\u7bb1(E-mail):<\/h1>\n<p>\u6280\u672f\u90ae\u7bb1(tech)<\/p>\n<p><a class=\"link\" href=\"mailto:canuxcheng@gmail.com\" >canuxcheng@gmail.com<\/a><\/p>\n<p>\u804c\u4f4d\u90ae\u7bb1(position)<\/p>\n<p><a class=\"link\" href=\"mailto:canuxcheng@163.com\" >canuxcheng@163.com<\/a><\/p>\n<p>\u5546\u52a1\u90ae\u7bb1(business)<\/p>\n<p><a class=\"link\" href=\"mailto:canuxcheng@outlook.com\" >canuxcheng@outlook.com<\/a><\/p>\n<hr>"},{"title":"\ud83d\udd0d","link":"https:\/\/canuxcheng.com\/search\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/canuxcheng.com\/search\/","description":{}}]}}