<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Farice</title>
    <description></description>
    <link>http://farice4.github.io/</link>
    <atom:link href="http://farice4.github.io/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Mon, 09 Mar 2026 10:51:31 +0000</pubDate>
    <lastBuildDate>Mon, 09 Mar 2026 10:51:31 +0000</lastBuildDate>
    <generator>Jekyll v3.10.0</generator>
    
      <item>
        <title></title>
        <description>&lt;p&gt;Mongo数据库介于关系与非关系数据库之间，无内存设置参数，Mongo使用os mmap 机制来缓存数据文件数据,自身目前不提供缓存机制。&lt;/p&gt;

&lt;h4 id=&quot;mongo的主要参数&quot;&gt;Mongo的主要参数：&lt;/h4&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;* dbpath: 数据文件存放路劲，每个数据库会在其中创建一个子目录，用于防止同一个实例多次运行的mongod.lock也保存在次目录中。
* logpath： 错误日志文件
* logappend： 错误日志采用追加模式（默认是覆写模式）
* bind_ip： 对外服务的绑定IP，一般设置为空
* port： 对外服务端口。Web管理端口在这个port的基础上+1000
* fork： 以后台Daemon形式运行服务
* journal： 开启日志功能，在1.8版本后正式加入
* syncdelay：系统同步刷新新磁盘的时间，单位为秒，默认60秒
* maxConns：最大连接数
* repairpath：执行repair是的临时目录。如果没有开启journal，异常down机后重启，必须执行repair操作 &amp;gt; mongod支持将参数写入到配置文件中，然后通过config参数引用此配置文件：（./mongod --config /etc/mongo.conf)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;mongo启动停止&quot;&gt;Mongo启动/停止&lt;/h4&gt;

&lt;blockquote&gt;
  &lt;p&gt;启动&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;./mongod --dbpath=/data/db --logpath=/data/log/r3.log --fork

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;停止&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;a)通过进程终止结束mongo运行
b)通过登录数据库执行命令终止运行
举例：
mongo  (登录数据库，默认test库)
use admin (切换到admin)
db.shutdownServer() （关闭数据库）
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;mongo查询&quot;&gt;Mongo查询&lt;/h4&gt;
&lt;p&gt;条件查询： $lt,$lte,$gt,$gte&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;举例(范围查询，通过定义时间，匹配文件的查询结果)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;start = new Date(&quot;01/01/2007&quot;)
db.users.find({registered} : {&quot;$lt&quot; : start}})

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;同时支持$or,$in，$not,$all,$size,$silice,$where&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;limit(限制返回结果),举例：&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;db.c.find().limit(3)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;sort(排序,升序1,降序-1),举例：&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;db.c.find().sort({username : 1, age : -1}) (查询username升序查询，查询age降序查询)

db.stock.find({&quot;desc&quot; : &quot;mp3&quot;}.limit(50).sort({&quot;price&quot; : -1})) (通过限制与排序查询，经常在使用中用到)

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h4 id=&quot;聚合&quot;&gt;聚合&lt;/h4&gt;

&lt;p&gt;通过count快速查询集合中文档的数量：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; db.meter.count()
685752
&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;通过distinct找出给定键的所有不同的值。使用时必须指定集合和键。&lt;/p&gt;

&lt;p&gt;group 做的聚合稍微复杂一些。先选定分组所依据的键，而后MongoDB就会将集合依据键值的不同分成若干组。然后可以通过聚合每一组内的文档，产生一个结果文档。（与SQL中的group by差不多）&lt;/p&gt;

&lt;p&gt;通过完成器(finalizer)用以精简从数据库传到用户的数据。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;查看mongo数据库状态&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;db.runCommand({&quot;serverStatus&quot; : 1})
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;通过mongostat 监控数据库&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[root@mongo ~]# mongostat 
insert query update delete getmore command flushes mapped  vsize   res faults qr|qw ar|aw netIn netOut conn     time
    *0    *0     *0     *0       0     1|0       0 240.0M 804.0M 83.0M      0   0|0   0|0   79b    10k    4 22:41:25
    *0    *0     *0     *0       0     1|0       0 240.0M 804.0M 83.0M      0   0|0   0|0   79b    10k    4 22:41:26
    *0    *0     *0     *0       0     1|0       0 240.0M 804.0M 83.0M      0   0|0   0|0   79b    10k    4 22:41:27
    *0    *0     *0     *0       0     1|0       0 240.0M 804.0M 83.0M      0   0|0   0|0   79b    10k    4 22:41:28
    *0    *0     *0     *0       0     2|0       0 240.0M 804.0M 83.0M      0   0|0   0|0  133b    10k    4 22:41:29
    *0    *0     *0     *0       0     1|0       0 240.0M 804.0M 83.0M      0   0|0   0|0   79b    10k    4 22:41:30
    *0    *0     *0     *0       0     1|0       0 240.0M 804.0M 83.0M      0   0|0   0|0   79b    10k    4 22:41:31
    *0    *0     *0     *0       0     1|0       0 240.0M 804.0M 83.0M      0   0|0   0|0   79b    10k    4 22:41:32
    *0    *0     *0     *0       0     1|0       0 240.0M 804.0M 83.0M      0   0|0   0|0   79b    10k    4 22:41:33
    *0    *0     *0     *0       0     2|0       0 240.0M 804.0M 83.0M      0   0|0   0|0  133b    10k    4 22:41:34
insert query update delete getmore command flushes mapped  vsize   res faults qr|qw ar|aw netIn netOut conn     time
    *0    *0     *0     *0       0     1|0       0 240.0M 804.0M 83.0M      0   0|0   0|0   79b    10k    4 22:41:35
    *0    *0     *0     *0       0     1|0       0 240.0M 804.0M 83.0M      0   0|0   0|0   79b    10k    4 22:41:36
    *0    *0     *0     *0       0     1|0       0 240.0M 804.0M 83.0M      0   0|0   0|0   79b    10k    4 22:41:37
    *0    *0     *0     *0       0     1|0       0 240.0M 804.0M 83.0M      0   0|0   0|0   79b    10k    4 22:41:38
    *0    *0     *0     *0       0     2|0       0 240.0M 804.0M 83.0M      0   0|0   0|0  133b    10k    4 22:41:39

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;Mongo 数据库备份&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;备份数据库通过&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mongodump&lt;/code&gt;备份&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Mongo 数据库恢复&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;恢复数据库通过&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mongorestore&lt;/code&gt;恢复&lt;/p&gt;

&lt;p&gt;备份与恢复举例如下：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;mongodump -d test -o backup (备份数据库test，备份到backup)
mongorestore -d foo --drop backup/test  (恢复数据库到foo,--drop恢复前检查，如果存在，就先删除，在进行恢复)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;fsync 和锁
fsync命令强制服务器所有缓冲区写入磁盘。还可以选择上锁阻止对数据库的进一步写入，知道释放为止。&lt;/p&gt;

&lt;p&gt;举例：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;use admin
db.runCommand({&quot;fsync&quot; :1,&quot;lock&quot; : 1}); (锁定)


db.$cmd.sys.unlock.findOne();  (解锁)
db.currentOp   (确认已经解锁)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
        <pubDate>Mon, 09 Mar 2026 10:51:31 +0000</pubDate>
        <link>http://farice4.github.io/2026/03/09/2015-07-13-Mongo-Base/</link>
        <guid isPermaLink="true">http://farice4.github.io/2026/03/09/2015-07-13-Mongo-Base/</guid>
        
        
      </item>
    
      <item>
        <title>Claude 基础学习指南</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#什么是-claude&quot; id=&quot;markdown-toc-什么是-claude&quot;&gt;什么是 Claude&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#claude-的主要特点&quot; id=&quot;markdown-toc-claude-的主要特点&quot;&gt;Claude 的主要特点&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#claude-模型家族&quot; id=&quot;markdown-toc-claude-模型家族&quot;&gt;Claude 模型家族&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#claude-3-系列&quot; id=&quot;markdown-toc-claude-3-系列&quot;&gt;Claude 3 系列&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#模型选择建议&quot; id=&quot;markdown-toc-模型选择建议&quot;&gt;模型选择建议&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#如何使用-claude&quot; id=&quot;markdown-toc-如何使用-claude&quot;&gt;如何使用 Claude&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#1-官方网页版&quot; id=&quot;markdown-toc-1-官方网页版&quot;&gt;1. 官方网页版&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#2-api-调用&quot; id=&quot;markdown-toc-2-api-调用&quot;&gt;2. API 调用&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#3-命令行工具&quot; id=&quot;markdown-toc-3-命令行工具&quot;&gt;3. 命令行工具&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#4-集成开发环境&quot; id=&quot;markdown-toc-4-集成开发环境&quot;&gt;4. 集成开发环境&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#提示词prompt最佳实践&quot; id=&quot;markdown-toc-提示词prompt最佳实践&quot;&gt;提示词（Prompt）最佳实践&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#基本原则&quot; id=&quot;markdown-toc-基本原则&quot;&gt;基本原则&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#好的提示词示例&quot; id=&quot;markdown-toc-好的提示词示例&quot;&gt;好的提示词示例&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#2-处理长文档&quot; id=&quot;markdown-toc-2-处理长文档&quot;&gt;2. 处理长文档&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#3-迭代式对话&quot; id=&quot;markdown-toc-3-迭代式对话&quot;&gt;3. 迭代式对话&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#4-格式控制&quot; id=&quot;markdown-toc-4-格式控制&quot;&gt;4. 格式控制&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#注意事项&quot; id=&quot;markdown-toc-注意事项&quot;&gt;注意事项&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#安全性&quot; id=&quot;markdown-toc-安全性&quot;&gt;安全性&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#准确性&quot; id=&quot;markdown-toc-准确性&quot;&gt;准确性&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#版权与合规&quot; id=&quot;markdown-toc-版权与合规&quot;&gt;版权与合规&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#学习资源&quot; id=&quot;markdown-toc-学习资源&quot;&gt;学习资源&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#官方资源&quot; id=&quot;markdown-toc-官方资源&quot;&gt;官方资源&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#社区资源&quot; id=&quot;markdown-toc-社区资源&quot;&gt;社区资源&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#总结&quot; id=&quot;markdown-toc-总结&quot;&gt;总结&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;什么是-claude&quot;&gt;什么是 Claude&lt;/h2&gt;

&lt;p&gt;Claude 是由 Anthropic 公司开发的一系列大型语言模型（LLM）。Anthropic 是一家专注于 AI 安全研究的美国公司，由前 OpenAI 高管创立。Claude 系列模型以安全性、有用性和诚实性为核心设计理念。&lt;/p&gt;

&lt;h3 id=&quot;claude-的主要特点&quot;&gt;Claude 的主要特点&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;安全性优先&lt;/strong&gt;：采用”宪法 AI”（Constitutional AI）方法，在训练过程中嵌入安全原则&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;长上下文支持&lt;/strong&gt;：支持超长文本输入，能够处理长文档和复杂对话&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;自然对话&lt;/strong&gt;：对话风格自然流畅，能够理解上下文和复杂指令&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;代码能力&lt;/strong&gt;：具备良好的编程和问题解决能力&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;多语言支持&lt;/strong&gt;：支持包括中文在内的多种语言&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;claude-模型家族&quot;&gt;Claude 模型家族&lt;/h2&gt;

&lt;h3 id=&quot;claude-3-系列&quot;&gt;Claude 3 系列&lt;/h3&gt;

&lt;p&gt;Anthropic 于 2024 年发布的 Claude 3 系列包含三个版本：&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;模型&lt;/th&gt;
      &lt;th&gt;定位&lt;/th&gt;
      &lt;th&gt;适用场景&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Claude 3 Haiku&lt;/td&gt;
      &lt;td&gt;轻量级&lt;/td&gt;
      &lt;td&gt;快速响应、简单任务&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Claude 3 Sonnet&lt;/td&gt;
      &lt;td&gt;中等&lt;/td&gt;
      &lt;td&gt;平衡性能与成本&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Claude 3 Opus&lt;/td&gt;
      &lt;td&gt;旗舰级&lt;/td&gt;
      &lt;td&gt;复杂推理、专业任务&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;模型选择建议&quot;&gt;模型选择建议&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;日常对话和简单查询&lt;/strong&gt;：Haiku&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;代码编写和文档处理&lt;/strong&gt;：Sonnet&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;复杂分析和专业咨询&lt;/strong&gt;：Opus&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;如何使用-claude&quot;&gt;如何使用 Claude&lt;/h2&gt;

&lt;h3 id=&quot;1-官方网页版&quot;&gt;1. 官方网页版&lt;/h3&gt;

&lt;p&gt;访问 &lt;a href=&quot;https://claude.ai&quot;&gt;claude.ai&lt;/a&gt; 注册账号后即可使用。这是最简单直接的使用方式。&lt;/p&gt;

&lt;h3 id=&quot;2-api-调用&quot;&gt;2. API 调用&lt;/h3&gt;

&lt;p&gt;开发者可以通过 Anthropic API 集成 Claude 到应用中：&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;anthropic&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Anthropic&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Anthropic&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;api_key&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;your-api-key&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;messages&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;model&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;claude-sonnet-4-20250514&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;max_tokens&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1024&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;messages&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;role&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;user&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;content&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;你好，请介绍一下自己&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;3-命令行工具&quot;&gt;3. 命令行工具&lt;/h3&gt;

&lt;p&gt;使用 Claude Code CLI 工具在终端中与 Claude 交互：&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# 安装&lt;/span&gt;
npm &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-g&lt;/span&gt; @anthropic-ai/claude-code

&lt;span class=&quot;c&quot;&gt;# 使用&lt;/span&gt;
claude &lt;span class=&quot;s2&quot;&gt;&quot;帮我分析这段代码&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;4-集成开发环境&quot;&gt;4. 集成开发环境&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cursor&lt;/strong&gt;：集成 Claude 的代码编辑器&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Windsurf&lt;/strong&gt;：AI 原生 IDE&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Zed&lt;/strong&gt;：支持 Claude 插件的高性能编辑器&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;提示词prompt最佳实践&quot;&gt;提示词（Prompt）最佳实践&lt;/h2&gt;

&lt;h3 id=&quot;基本原则&quot;&gt;基本原则&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;清晰明确&lt;/strong&gt;：直接表达你的需求，避免模糊表述&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;提供上下文&lt;/strong&gt;：给出足够的背景信息帮助模型理解&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;分步指令&lt;/strong&gt;：复杂任务拆解为多个步骤&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;示例引导&lt;/strong&gt;：提供示例帮助模型理解期望的输出格式&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;好的提示词示例&quot;&gt;好的提示词示例&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;请分析以下 Python 代码的性能问题，并提供优化建议：

```python
def find_duplicates(items):
    duplicates = []
    for i in range(len(items)):
        for j in range(i + 1, len(items)):
            if items[i] == items[j] and items[i] not in duplicates:
                duplicates.append(items[i])
    return duplicates
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;请从时间复杂度和空间复杂度两个角度分析。&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
### 避免的提示词

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;这段代码怎么了？  # 过于模糊，没有提供代码&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;帮我写个程序  # 需求不明确，缺少具体功能描述&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
## Claude 在开发中的应用场景

### 代码编写

- 生成代码片段和函数
- 代码重构和优化
- 编写单元测试
- 代码审查和注释

### 问题调试

- 分析错误信息和日志
- 定位 bug 根因
- 提供修复方案
- 解释复杂的技术概念

### 文档工作

- 编写技术文档
- 生成 API 文档
- 创建 README 文件
- 翻译技术文章

### 学习辅助

- 解释新概念
- 提供学习路径建议
- 解答技术问题
- 代码示例演示

## 实用技巧

### 1. 使用系统提示词

在 API 调用中设置 system 参数来定义角色：

```python
response = client.messages.create(
    model=&quot;claude-sonnet-4-20250514&quot;,
    system=&quot;你是一位资深的 Python 开发者，擅长 Web 开发和数据库设计。&quot;,
    messages=[...]
)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;2-处理长文档&quot;&gt;2. 处理长文档&lt;/h3&gt;

&lt;p&gt;Claude 支持长上下文，可以直接上传整个文件进行分析：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;请阅读以下配置文件，解释每个参数的作用：

[粘贴完整文件内容]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;3-迭代式对话&quot;&gt;3. 迭代式对话&lt;/h3&gt;

&lt;p&gt;对于复杂任务，采用多轮对话逐步完善：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;第一轮：请帮我设计一个用户认证系统的架构
第二轮：基于上面的设计，请给出 JWT 实现的具体代码
第三轮：请为这段代码添加单元测试
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;4-格式控制&quot;&gt;4. 格式控制&lt;/h3&gt;

&lt;p&gt;明确指定输出格式：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;请用表格形式对比以下三种数据库的优缺点：
- MySQL
- PostgreSQL
- MongoDB
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;注意事项&quot;&gt;注意事项&lt;/h2&gt;

&lt;h3 id=&quot;安全性&quot;&gt;安全性&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;不要分享敏感信息（API 密钥、密码等）&lt;/li&gt;
  &lt;li&gt;不要用于生成恶意代码或攻击性内容&lt;/li&gt;
  &lt;li&gt;验证生成代码的安全性后再使用&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;准确性&quot;&gt;准确性&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;对技术事实进行二次验证&lt;/li&gt;
  &lt;li&gt;重要决策不要完全依赖 AI 建议&lt;/li&gt;
  &lt;li&gt;注意模型知识截止时间&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;版权与合规&quot;&gt;版权与合规&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;生成内容的版权归属需参考 Anthropic 服务条款&lt;/li&gt;
  &lt;li&gt;商业使用请遵守相关许可协议&lt;/li&gt;
  &lt;li&gt;开源项目使用时注意许可证兼容性&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;学习资源&quot;&gt;学习资源&lt;/h2&gt;

&lt;h3 id=&quot;官方资源&quot;&gt;官方资源&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.anthropic.com&quot;&gt;Anthropic 官网&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.anthropic.com&quot;&gt;Claude API 文档&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.anthropic.com/news&quot;&gt;Anthropic 官方博客&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;社区资源&quot;&gt;社区资源&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;GitHub 上的 Claude 示例项目&lt;/li&gt;
  &lt;li&gt;Reddit 的 r/ClaudeAI 社区&lt;/li&gt;
  &lt;li&gt;各类技术论坛和博客&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;总结&quot;&gt;总结&lt;/h2&gt;

&lt;p&gt;Claude 作为新一代 AI 助手，在安全性、有用性和自然对话方面都有出色表现。无论是日常办公、代码开发还是学习研究，合理使用 Claude 都能显著提高效率。关键是掌握正确的使用方法，理解其优势和局限，将其作为辅助工具而非完全依赖。&lt;/p&gt;

&lt;p&gt;希望本文能帮助你更好地使用 Claude，在工作和学习中发挥 AI 助手最大的价值。&lt;/p&gt;
</description>
        <pubDate>Mon, 09 Mar 2026 10:00:00 +0000</pubDate>
        <link>http://farice4.github.io/2026/03/09/Claude-base-study/</link>
        <guid isPermaLink="true">http://farice4.github.io/2026/03/09/Claude-base-study/</guid>
        
        <category>AI</category>
        
        <category>Claude</category>
        
        <category>Anthropic</category>
        
        <category>大模型</category>
        
        
        <category>AI_Learning</category>
        
      </item>
    
      <item>
        <title>Helm基本使用</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#helm安装&quot; id=&quot;markdown-toc-helm安装&quot;&gt;Helm安装&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#helm-客户端安装&quot; id=&quot;markdown-toc-helm-客户端安装&quot;&gt;Helm 客户端安装&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#helm-server安装&quot; id=&quot;markdown-toc-helm-server安装&quot;&gt;Helm server安装&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#helm基本使用&quot; id=&quot;markdown-toc-helm基本使用&quot;&gt;Helm基本使用&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#helm-添加repo镜像库&quot; id=&quot;markdown-toc-helm-添加repo镜像库&quot;&gt;Helm 添加repo镜像库&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#helm-创建chart&quot; id=&quot;markdown-toc-helm-创建chart&quot;&gt;Helm 创建chart&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#helm-chart安装&quot; id=&quot;markdown-toc-helm-chart安装&quot;&gt;Helm chart安装&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;
&lt;p&gt;Helm可帮助您管理Kubernetes应用程序 - Helm Charts可帮助您定义，安装和升级最复杂的Kubernetes应用程序。与ubuntu下的apt, centos下的yum类似的管理工具。&lt;/p&gt;

&lt;p&gt;kubernetes在创建资源时使用yaml形式存储，随着资源复杂度增加，yaml中的内容也越来越多，helm chart通过管理包的形式将资源数据分散在不同文件中。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;helm chart提供的功能包括：&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;创建与安装chart 应用
管理chart安装版本，跟踪安装历史
chart轻松升级
chart版本回退，删除恢复
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;helm安装&quot;&gt;Helm安装&lt;/h3&gt;
&lt;p&gt;在安装前，确认环境中已经完成安装kubernetes，kubernetes能够正常使用。&lt;/p&gt;

&lt;p&gt;Helm安装分为客户端安装helm 工具，server端title安装。这里安装使用helm v2.7.2版本&lt;/p&gt;

&lt;h4 id=&quot;helm-客户端安装&quot;&gt;Helm 客户端安装&lt;/h4&gt;

&lt;p&gt;手动下载helm-v2.7.2-linux-amd64.tar.gz软件包，在kubernetes环境中解压helm-v2.7.2-linux-amd64.tar.gz，并将其拷贝到可执行命令path目录&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# tar -xvf helm-v2.7.2-linux-amd64.tar.gz
linux-amd64/
linux-amd64/README.md
linux-amd64/LICENSE
linux-amd64/helm
# cp linux-amd64/helm /usr/local/bin/
# helm -h  (显示帮助信息，客户端安装完成）)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;helm-server安装&quot;&gt;Helm server安装&lt;/h4&gt;

&lt;p&gt;server 安装会在kubernetes kube-system空间中启动一个tiller-deploy pod, 该pod依赖helm tiller镜像（镜像名称为gcr.io/kubernetes-helm/tiller:v2.7.2），在创建pod时，国内无法正常下载，因此在安装前需要手动下载镜像到docker镜像库中。&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# docker images
gcr.io/kubernetes-helm/tiller                                    v2.7.2              1c5314e713c2        5 months ago        71.6 MB
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;server 通过helm init方式来进行server安装，在k8s环境中启动tiller-deploy pod，但在helm init时默认会用gcr镜像，因此这里需要在helm init时添加其它选项&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# kubectl create serviceaccount --namespace kube-system tiller  (创建tiller serviceaccount)
 
# kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller (绑定角色）
 
# helm init --service-account tiller --upgrade （进行server安装，这里使用了--service-account tiller选项)
 
# kubectl patch deploy --namespace kube-system tiller-deploy -p &apos;{&quot;spec&quot;:{&quot;template&quot;:{&quot;spec&quot;:{&quot;serviceAccount&quot;:&quot;tiller&quot;}}}}&apos; 
（这一步非常重要，不然后面在使用 Helm 的过程中可能出现Error: no available release name found的错误信息。）
如果上一步patch不能成功，那么手动修改执行下面命令:
kubectl edit deploy --namespace kube-system tiller-deploy #and add the line serviceAccount: tiller to spec/template/spec
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;验证helm server pod安装完成&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# kubectl get pods -n kube-system -o wide |grep tiller     (通过kubectl工具查看pod已经正常启动）
tiller-deploy-65b7f7d54f-fwhj5           1/1       Running   0          54m       10.244.0.39    openstack-helm
 
# helm version          (查看helm 版本）
Client: &amp;amp;version.Version{SemVer:&quot;v2.7.2&quot;, GitCommit:&quot;8478fb4fc723885b155c924d1c8c410b7a9444e6&quot;, GitTreeState:&quot;clean&quot;}
Server: &amp;amp;version.Version{SemVer:&quot;v2.7.2&quot;, GitCommit:&quot;8478fb4fc723885b155c924d1c8c410b7a9444e6&quot;, GitTreeState:&quot;clean&quot;}))
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;到此helm server与client安装全部完成，安装完成在家目录下会生成helm的目录与文件&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# tree .helm
.helm
|-- cache
|   `-- archive     (这个目录用来存储chart归档，通过helm package chart的方式完成）
|       |-- ingress-0.1.0.tgz
|       |-- mysql-0.8.2.tgz
|       `-- nginx-ingress-0.24.0.tgz
|-- plugins        （helm 安装plugin存储)
|-- repository      (记录repo仓库)
|   |-- cache
|   |   `-- local-index.yaml -&amp;gt; /root/.helm/repository/local/index.yaml
|   |-- local
|   |   |-- calico-0.1.0.tgz
|   |   |-- elasticsearch-0.1.0.tgz
|   |   |-- registry-0.1.0.tgz
|   |   `-- tiller-0.1.0.tgz
|   `-- repositories.yaml
`-- starters`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;helm基本使用&quot;&gt;Helm基本使用&lt;/h3&gt;

&lt;h4 id=&quot;helm-添加repo镜像库&quot;&gt;Helm 添加repo镜像库&lt;/h4&gt;

&lt;p&gt;Helm镜像库添加后，通过helm install 方式可以安装镜像库下的镜像，同时chart使用镜像也能够从镜像库提供的下载中下载&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# helm repo list  (查看镜像库）
NAME     URL
local    http://localhost:8879/charts
# helm repo add stable https://burdenbear.github.io/kube-charts-mirror/  （添加名称未stable镜像库，镜像库地址为https://burdenbear.github.io/kube-charts-mirror/)
&quot;stable&quot; has been added to your repositories
# helm repo list
NAME      URL
local     http://localhost:8879/charts
stable    https://burdenbear.github.io/kube-charts-mirror/   （stable镜像库已添加）
# helm search         （通过search能够看到stable下的镜像库）
NAME                                     VERSION    DESCRIPTION
local/calico                             0.1.0      OpenStack-Helm BootStrap Calico
local/elasticsearch                      0.1.0      OpenStack-Helm ElasticSearch
local/flannel                            0.1.0      OpenStack-Helm BootStrap Flannel
local/fluent-logging                     0.1.0      OpenStack-Helm Fluentd
local/grafana                            0.1.0      OpenStack-Helm Grafana
stable/acs-engine-autoscaler             2.2.0      Scales worker nodes within agent pools
stable/aerospike                         0.1.7      A Helm chart for Aerospike in Kubernetes
stable/anchore-engine                    0.2.0      Anchore container analysis and policy evaluatio...
stable/apm-server                        0.1.0      The server receives data from the Elastic APM a...
stable/ark                               1.2.0      A Helm chart for ark
stable/artifactory                       7.2.2      Universal Repository Manager supporting all maj...
stable/artifactory-ha                    0.2.2      Universal Repository Manager supporting all maj...
stable/auditbeat                         0.1.0      A lightweight shipper to audit the activities o...
stable/aws-cluster-autoscaler            0.3.3      Scales worker nodes within autoscaling groups.
stable/bitcoind                          0.1.3      Bitcoin is an innovative payment network
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;helm-创建chart&quot;&gt;Helm 创建chart&lt;/h4&gt;

&lt;p&gt;使用helm create 方式创建一个chart&lt;/p&gt;

&lt;p&gt;举例创建chart:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# helm create nginx   (创建nginx chart)
# tree nginx/         (查看创建nginx chart的目录结构)
nginx/
|-- charts            (该目录默认为空）
|-- Chart.yaml         (定义名称，版本信息）
|-- templates         (k8s中资源模板定义)
|   |-- deployment.yaml
|   |-- _helpers.tpl
|   |-- ingress.yaml
|   |-- NOTES.txt
|   `-- service.yaml
`-- values.yaml        (定义变量信息，各个创建资源变量定义）)))
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;创建好的nginx chart默认是一个模板形式，根据需要进行修改。这里我们根据需要进行修改，这里举例修改values.yaml中的service下的type，默认为ClusterIP，创建的chart镜像为nginx，为方便访问，我们将type修改为NodePort&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# vim values.yaml
# Default values for nginx.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
image:
  repository: nginx
  tag: stable
  pullPolicy: IfNotPresent
service:
  name: nginx
  type: NodePort
  externalPort: 80
  internalPort: 80
ingress:
  enabled: false
  # Used to create an Ingress record.
  hosts:
    - chart-example.local
  annotations:
    # kubernetes.io/ingress.class: nginx
    # kubernetes.io/tls-acme: &quot;true&quot;
  tls:
    # Secrets must be manually created in the namespace.
    # - secretName: chart-example-tls
    #   hosts:
    #     - chart-example.local
resources: {}
  # We usually recommend not to specify default resources and to leave this as a conscious
  # choice for the user. This also increases chances charts run on environments with little
  # resources, such as Minikube. If you do want to specify resources, uncomment the following
  # lines, adjust them as necessary, and remove the curly braces after &apos;resources:&apos;.
  # limits:
  #  cpu: 100m
  #  memory: 128Mi
  # requests:
  #  cpu: 100m
  #  memory: 128Mi
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;helm-chart安装&quot;&gt;Helm chart安装&lt;/h4&gt;

&lt;blockquote&gt;
  &lt;p&gt;在安装之前可以对创建的chart进行验证，如果语法存在问题，验证不能通过&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# helm install --dry-run --debug dir (chart 目录)
举例验证neutron
# helm install --dry-run --debug neutron
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;在创建chart nginx目录内执行 helm install . 或者使用nginx路径形式安装 helm install root/nginx&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# helm install /root/nginx/
NAME:   lolling-molly
LAST DEPLOYED: Fri Aug 10 03:30:54 2018
NAMESPACE: default
STATUS: DEPLOYED
 
RESOURCES:
==&amp;gt; v1/Service
NAME                 TYPE      CLUSTER-IP     EXTERNAL-IP  PORT(S)       AGE
lolling-molly-nginx  NodePort  10.99.197.200  &amp;lt;none&amp;gt;       80:30496/TCP  0s
 
==&amp;gt; v1beta1/Deployment
NAME                 DESIRED  CURRENT  UP-TO-DATE  AVAILABLE  AGE
lolling-molly-nginx  1        1        1           0          0s
 
==&amp;gt; v1/Pod(related)
NAME                                  READY  STATUS             RESTARTS  AGE
lolling-molly-nginx-86844cc88c-jv4vr  0/1    ContainerCreating  0         0s
 
 
NOTES:
1. Get the application URL by running these commands:
  export NODE_PORT=$(kubectl get --namespace default -o jsonpath=&quot;{.spec.ports[0].nodePort}&quot; services lolling-molly-nginx)
  export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath=&quot;{.items[0].status.addresses[0].address}&quot;)
  echo http://$NODE_IP:$NODE_PORT
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;查看安装结果&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# helm list       (使用helm 工具查看）
NAME             REVISION    UPDATED                     STATUS      CHART          NAMESPACE
lolling-molly    1           Fri Aug 10 03:30:54 2018    DEPLOYED    nginx-0.1.0    default
# kubectl get pods -o wide|grep nginx  (通过kubeclt查看pod安装状态）
lolling-molly-nginx-86844cc88c-jv4vr   1/1       Running   0          5m        10.244.0.44   openstack-helm
# kubectl get svc |grep nginx   (查看svc）
lolling-molly-nginx   NodePort    10.99.197.200   &amp;lt;none&amp;gt;        80:30496/TCP   6)))
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;通过kubectl get svc查询到对外访问端口，通过http://物理节点ip:30496(这里是刚刚修改的service type为NodePort实现) 能够访问到nginx默认提供页面&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;helm 查看安装chart状态&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# helm status lolling-molly
LAST DEPLOYED: Fri Aug 10 03:30:54 2018
NAMESPACE: default
STATUS: DEPLOYED
 
RESOURCES:
==&amp;gt; v1/Pod(related)
NAME                                  READY  STATUS   RESTARTS  AGE
lolling-molly-nginx-86844cc88c-jv4vr  1/1    Running  0         15m
 
==&amp;gt; v1/Service
NAME                 TYPE      CLUSTER-IP     EXTERNAL-IP  PORT(S)       AGE
lolling-molly-nginx  NodePort  10.99.197.200  &amp;lt;none&amp;gt;       80:30496/TCP  15m
 
==&amp;gt; v1beta1/Deployment
NAME                 DESIRED  CURRENT  UP-TO-DATE  AVAILABLE  AGE
lolling-molly-nginx  1        1        1           1          15m
 
 
NOTES:
1. Get the application URL by running these commands:
  export NODE_PORT=$(kubectl get --namespace default -o jsonpath=&quot;{.spec.ports[0].nodePort}&quot; services lolling-molly-nginx)
  export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath=&quot;{.items[0].status.addresses[0].address}&quot;)
  echo http://$NODE_IP:$NODE_PORT
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;通过上面的helm status能够看到chart安装时的资源信息，从上面可以看到，创建了pod，创建了service, 创建了Deployment。chart的状态是DEPLOYED部署阶段&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;查看chart历史信息&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# helm history lolling-molly
REVISION    UPDATED                     STATUS      CHART          DESCRIPTION
1           Fri Aug 10 03:30:54 2018    DEPLOYED    nginx-0.1.0    Install complete
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;更新chart&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;这里举例，通过修改chart版本信息，进行升级更新&lt;/p&gt;

&lt;p&gt;手动修改nginx下的Chart.yaml version为0.1.1默认为(0.1.0), 修改完成通过helm upgrade方式来进行升级&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# helm list      (升级前）
NAME             REVISION    UPDATED                     STATUS      CHART          NAMESPACE
lolling-molly    1           Fri Aug 10 03:30:54 2018    DEPLOYED    nginx-0.1.0    default
 
# helm upgrade lolling-molly nginx     （升级，lolling-molly 为helm list出的name, nginx为chart的目录名称)
# helm list      (升级后,CHART nginx-0.1.0变为了nginx-0.1.1)
NAME             REVISION    UPDATED                     STATUS      CHART          NAMESPACE
lolling-molly    2           Fri Aug 10 03:53:53 2018    DEPLOYED    nginx-0.1.1    default
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;helm upgrade会将之前创建的删除，重新创建，helm中会记录chart历史过程&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;回滚chart&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;当升级完成chart后，出现问题，可以通过rollback方式回滚。同样当执行helm delete后的chart可以通过rollback方式回滚。注意：已经物理清除的chart不能在恢复（helm delete –purge xxx)&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;升级回滚举例&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# helm history lolling-molly       (查看历史版本）
REVISION    UPDATED                     STATUS        CHART          DESCRIPTION
1           Fri Aug 10 03:30:54 2018    SUPERSEDED    nginx-0.1.0    Install complete
2           Fri Aug 10 03:53:53 2018    DEPLOYED      nginx-0.1.1    Upgrade complete
 
# helm rollback lolling-molly 1     （版本回滚）
Rollback was a success! Happy Helming!
 
# helm list                  (这里nginx-0.1.1回退至nginx-0.1.0版本)
NAME             REVISION    UPDATED                     STATUS      CHART          NAMESPACE
lolling-molly    3           Fri Aug 10 04:02:56 2018    DEPLOYED    nginx-0.1.0    default
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;删除回滚举例&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# helm list           (删除前）
NAME             REVISION    UPDATED                     STATUS      CHART          NAMESPACE
lolling-molly    3           Fri Aug 10 04:02:56 2018    DEPLOYED    nginx-0.1.0    default
 
# helm delete lolling-molly    （删除名称为lolling-molly chart)
release &quot;lolling-molly&quot; deleted
 
# helm list       (列出为空）
# kubectl get pods -o wide |grep nginx  (返回为空）
 
# helm list --all     (通过--all参数看到，已被删除，状态为DELETED)
NAME             REVISION    UPDATED                     STATUS     CHART          NAMESPACE
lolling-molly    3           Fri Aug 10 04:02:56 2018    DELETED    nginx-0.1.0    defaul)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;开始回滚:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# helm history lolling-molly      (查看历史记录，REVISION可以看到是DELETED chart）
REVISION    UPDATED                     STATUS        CHART          DESCRIPTION
1           Fri Aug 10 03:30:54 2018    SUPERSEDED    nginx-0.1.0    Install complete
2           Fri Aug 10 03:53:53 2018    SUPERSEDED    nginx-0.1.1    Upgrade complete
3           Fri Aug 10 04:02:56 2018    DELETED       nginx-0.1.0    Deletion complete
 
# helm rollback lolling-molly 2    (这里回滚到REVISON 2为nginx-0.1.1版本)
Rollback was a success! Happy Helming!
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;验证回滚成功&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# helm list
NAME             REVISION    UPDATED                     STATUS      CHART          NAMESPACE
lolling-molly    4           Fri Aug 10 04:11:12 2018    DEPLOYED    nginx-0.1.1    default
 
# kubectl get pods -o wide|grep nginx
lolling-molly-nginx-86844cc88c-cccpf   1/1       Running   0          1m        10.244.0.45   openstack-helm
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;这里可以看到在回滚后，ip地址变化了，由原来的10.244.0.44 变成了10.244.0.45&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;chart 打包归档&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# helm package nginx
Successfully packaged chart and saved it to: /root/helm/nginx-0.1.0.tgz
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;在/root/helm目录下生成了nginx-0.1.0.tgz的归档&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;chart 检测&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;通过helm lint对创建的chart进行验证，chart是否存在问题&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# helm lint nginx
==&amp;gt; Linting nginx
[INFO] Chart.yaml: icon is recommended
 
1 chart(s) linted, no failures
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

</description>
        <pubDate>Thu, 18 Oct 2018 13:15:03 +0000</pubDate>
        <link>http://farice4.github.io/2018/10/18/helm-use/</link>
        <guid isPermaLink="true">http://farice4.github.io/2018/10/18/helm-use/</guid>
        
        <category>Helm基本使用</category>
        
        
        <category>Kubernetes,Helm</category>
        
      </item>
    
      <item>
        <title>K8S Install v1.10.0</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#安装前环境准备&quot; id=&quot;markdown-toc-安装前环境准备&quot;&gt;安装前环境准备&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#安装docker-ce软件&quot; id=&quot;markdown-toc-安装docker-ce软件&quot;&gt;安装docker ce软件&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#安装kubeadm-kubelet-kubectl软件&quot; id=&quot;markdown-toc-安装kubeadm-kubelet-kubectl软件&quot;&gt;安装kubeadm, kubelet, kubectl软件&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#配置1100版本所需要镜像&quot; id=&quot;markdown-toc-配置1100版本所需要镜像&quot;&gt;配置1.10.0版本所需要镜像&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#初始化master节点&quot; id=&quot;markdown-toc-初始化master节点&quot;&gt;初始化master节点&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#配置kubectl认证信息&quot; id=&quot;markdown-toc-配置kubectl认证信息&quot;&gt;配置kubectl认证信息&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#安装flannel网络&quot; id=&quot;markdown-toc-安装flannel网络&quot;&gt;安装flannel网络&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#验证k8s环境安装&quot; id=&quot;markdown-toc-验证k8s环境安装&quot;&gt;验证k8s环境安装&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;
&lt;p&gt;本文主要记录通过kubeadm方式安装k8s 1.10.0版本，本文档既适用于单节点安装也适用于集群安装，网络方案采用fannel插件。&lt;/p&gt;

&lt;h3 id=&quot;安装前环境准备&quot;&gt;安装前环境准备&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;关闭防火墙firewalld&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;systemctl stop firewalld
systemctl disable firewalld
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;禁用Selinux&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;setenforce 0  (临时关闭)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;vi 打开/etc/sysconfig/selinux文件，修改SELINUX值（永久关闭)&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SELINUX=disabled
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;关闭swap交换分区&lt;/p&gt;
  &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;swapoff -a (临时关闭)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;vi 打开/etc/fstab文件，将挂载swap分区注释掉（永久关闭)&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;#UUID=2276f4dc-8b29-41bf-8aed-573c93e41976 swap                    swap    defaults        0 0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;以上配置完成后，重启操作系统&lt;/p&gt;

&lt;h3 id=&quot;安装docker-ce软件&quot;&gt;安装docker ce软件&lt;/h3&gt;

&lt;p&gt;下载地址：https://download.docker.com/linux/centos/7/x86_64/stable/Packages/&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;下载的版本选择17.03.2.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;mkdir docker_rpm
cd docker_rpm
wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm
wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;执行docker安装&lt;/p&gt;
  &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;yum install -y ./docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm
yum install -y ./docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;/div&gt;
  &lt;p&gt;启动docker服务&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;systemctl enable docker
systemctl start docker
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;配置docker registry mirror与cgroup
编辑/etc/docker/daemon.json文件&lt;/p&gt;
  &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;{&quot;registry-mirrors&quot;: [&quot;http://85d5449d.m.daocloud.io&quot;],&quot;exec-opts&quot;: [&quot;native.cgroupdriver=systemd&quot;]}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;重启docker服务，验证cgroup配置成功&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;systemctl restart docker
docker info  (能够看到显示的cgroup为systemd)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;安装kubeadm-kubelet-kubectl软件&quot;&gt;安装kubeadm, kubelet, kubectl软件&lt;/h3&gt;

&lt;p&gt;这里安装1.10.0版本&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;配置kubernetes yum安装源&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cat &amp;lt;&amp;lt;EOF &amp;gt; /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
EOF
yum -y install epel-release
yum clean all
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;安装kubeadm, kubelet, kubectl软件&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;yum install kubeadm-1.10.0 kubectl-1.10.0 kubelet-1.10.0
systemctl enable kubelet &amp;amp;&amp;amp; systemctl start kubelet
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;配置1100版本所需要镜像&quot;&gt;配置1.10.0版本所需要镜像&lt;/h3&gt;

&lt;p&gt;因k8s默认从google storage上下载镜像，国内无法正常下载，因此手动将镜像先下载下来，通过一个脚本进行下载，并对镜像打上相应tag。&lt;/p&gt;

&lt;p&gt;在image.sh文件中添加以下内容:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;#!/bin/bash
images=(kube-proxy-amd64:v1.10.0 kube-scheduler-amd64:v1.10.0 kube-controller-manager-amd64:v1.10.0 kube-apiserver-amd64:v1.10.0
etcd-amd64:3.1.12 pause-amd64:3.1 kubernetes-dashboard-amd64:v1.8.3 k8s-dns-sidecar-amd64:1.14.8 k8s-dns-kube-dns-amd64:1.14.8
k8s-dns-dnsmasq-nanny-amd64:1.14.8)
for imageName in ${images[@]} ; do
  docker pull mirrorgooglecontainers/$imageName
  docker tag mirrorgooglecontainers/$imageName k8s.gcr.io/$imageName
  docker rmi mirrorgooglecontainers/$imageName
done
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;运行image.sh下载镜像&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sh image.sh
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;初始化master节点&quot;&gt;初始化master节点&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;kubeadm init --kubernetes-version=v1.10.0 --apiserver-advertise-address 192.168.53.10 --pod-network-cidr=10.244.0.0/16
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;解释：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;–kubernetes-version                   指的是相关这里使用的版本是1.10.0&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;–apiserver-advertise-address     如果该Master节点有多网卡则需要指定，如果不指定，kubeadm 会自动选择有默认网关的 interface。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;–pod-network-cidr             指定 Pod 网络的范围。Kubernetes 支持多种网络方案，而且不同网络方案对 –pod-network-cidr 有自己的要求，这里设置为 10.244.0.0/16 是因为我们将使用 flannel 网络方案，必须设置成这个 CIDR&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;以下内容是初始化成功后输出的截取内容：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Your Kubernetes master has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
Run &quot;kubectl apply -f [podnetwork].yaml&quot; with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
You can now join any number of machines by running the following on each node
as root:
kubeadm join 192.168.53.10:6443 --token mjcpfv.ygwck7pjyue68fw9 --discovery-token-ca-cert-hash sha256:6c31a69d3bfa45a5dd50de2e07f1c71731d17244a009742a3dbf83e03a5a62f6

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;其它节点根据上面相同的方式执行，非master节点不需要执行&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;kubeadm init&lt;/code&gt;操作，只需要执行&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;kubeadm join&lt;/code&gt;操作&lt;/p&gt;

&lt;p&gt;末尾的：&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;kubeadm join 192.168.53.10:6443 --token mjcpfv.ygwck7pjyue68fw9 --discovery-token-ca-cert-hash sha256:6c31a69d3bfa45a5dd50de2e07f1c71731d17244a009742a3dbf83e03a5a62f6
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;可以用来在其他Node节点上执行，以将其他节点加入到集群中。&lt;/p&gt;

&lt;h3 id=&quot;配置kubectl认证信息&quot;&gt;配置kubectl认证信息&lt;/h3&gt;

&lt;p&gt;cp /etc/kubernetes/admin.conf ~/.kube/config&lt;/p&gt;

&lt;h3 id=&quot;安装flannel网络&quot;&gt;安装flannel网络&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;mkdir -p /etc/cni/net.d/

cat &amp;lt;&amp;lt;EOF&amp;gt; /etc/cni/net.d/10-flannel.conf
{
&quot;name&quot;: &quot;cbr0&quot;,
&quot;type&quot;: &quot;flannel&quot;,
&quot;delegate&quot;: {
&quot;isDefaultGateway&quot;: true
}
}
EOF

mkdir /usr/share/oci-umount/oci-umount.d -p

mkdir /run/flannel/

cat &amp;lt;&amp;lt;EOF&amp;gt; /run/flannel/subnet.env
FLANNEL_NETWORK=10.244.0.0/16
FLANNEL_SUBNET=10.244.1.0/24
FLANNEL_MTU=1450
FLANNEL_IPMASQ=true
EOF

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;应用fannel插件yml文件,创建fannel pod&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;验证k8s环境安装&quot;&gt;验证k8s环境安装&lt;/h3&gt;

&lt;blockquote&gt;
  &lt;p&gt;检测节点状态，节点状态为Ready，表示正常&lt;/p&gt;
  &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;kubectl get nodes
NAME                   STATUS    ROLES     AGE       VERSION
k8s-master-openstack   Ready     master    3h        v1.10.0
k8s-node1-openstack    Ready     &amp;lt;none&amp;gt;    3h        v1.10.0
k8s-node2-openstack    Ready     &amp;lt;none&amp;gt;    3h        v1.10.0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;检测pod运行状态&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;kubectl get pods --all-namespaces -o wide
NAMESPACE     NAME                                           READY     STATUS    RESTARTS   AGE       IP              NODE
default       cirros-66995cfc6c-pf4b5                        1/1       Running   0          37m       10.244.1.2      k8s-node1-openstack
kube-system   etcd-k8s-master-openstack                      1/1       Running   0          46m       192.168.8.180   k8s-master-openstack
kube-system   kube-apiserver-k8s-master-openstack            1/1       Running   0          46m       192.168.8.180   k8s-master-openstack
kube-system   kube-controller-manager-k8s-master-openstack   1/1       Running   0          46m       192.168.8.180   k8s-master-openstack
kube-system   kube-dns-86f4d74b45-kjrx9                      3/3       Running   8          46m       10.244.1.2      k8s-node2-openstack
kube-system   kube-flannel-ds-amd64-6ssxl                    1/1       Running   0          42m       192.168.8.115   k8s-node1-openstack
kube-system   kube-flannel-ds-amd64-btltw                    1/1       Running   0          42m       192.168.8.180   k8s-master-openstack
kube-system   kube-flannel-ds-amd64-gszwd                    1/1       Running   0          42m       192.168.8.67    k8s-node2-openstack
kube-system   kube-proxy-6hm4l                               1/1       Running   0          45m       192.168.8.115   k8s-node1-openstack
kube-system   kube-proxy-c2n8z                               1/1       Running   0          46m       192.168.8.180   k8s-master-openstack
kube-system   kube-proxy-tkn6v                               1/1       Running   0          45m       192.168.8.67    k8s-node2-openstack
kube-system   kube-scheduler-k8s-master-openstack            1/1       Running   0          46m       192.168.8.180   k8s-master-openstack
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;创建cirros 镜像pod测试&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;kubectl run cirros --image=cirros
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;查看创建结果&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;kubectl get pods
NAME                      READY     STATUS    RESTARTS   AGE
cirros-66995cfc6c-pf4b5   1/1       Running   0          3h
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
        <pubDate>Wed, 01 Aug 2018 13:15:03 +0000</pubDate>
        <link>http://farice4.github.io/2018/08/01/k8s-install/</link>
        <guid isPermaLink="true">http://farice4.github.io/2018/08/01/k8s-install/</guid>
        
        <category>Kubernetes安装</category>
        
        
        <category>Kubernetes</category>
        
      </item>
    
      <item>
        <title>Nova resize</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#介绍&quot; id=&quot;markdown-toc-介绍&quot;&gt;介绍&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#openstack-senlin-deploy&quot; id=&quot;markdown-toc-openstack-senlin-deploy&quot;&gt;Openstack-senlin deploy&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#1-基于dockeriocentos启动容器&quot; id=&quot;markdown-toc-1-基于dockeriocentos启动容器&quot;&gt;1. 基于docker.io/centos启动容器&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#２-在启动的容器中添加senlin信息&quot; id=&quot;markdown-toc-２-在启动的容器中添加senlin信息&quot;&gt;２. 在启动的容器中添加senlin信息&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#3构建senlinbase镜像&quot; id=&quot;markdown-toc-3构建senlinbase镜像&quot;&gt;3．构建senlin/base镜像&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#4安装senlin源码&quot; id=&quot;markdown-toc-4安装senlin源码&quot;&gt;4．安装senlin源码&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#5创建新版本容器镜像&quot; id=&quot;markdown-toc-5创建新版本容器镜像&quot;&gt;5．创建新版本容器镜像&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#6容器封装服务&quot; id=&quot;markdown-toc-6容器封装服务&quot;&gt;6．容器封装服务&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#７-导出镜像&quot; id=&quot;markdown-toc-７-导出镜像&quot;&gt;７. 导出镜像&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#8fuel节点执行ansilble安装&quot; id=&quot;markdown-toc-8fuel节点执行ansilble安装&quot;&gt;8．fuel节点执行ansilble安装&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;介绍&quot;&gt;介绍&lt;/h3&gt;

&lt;p&gt;主要介绍senlin 组件通过docker容器化部署的，镜像制作．&lt;/p&gt;

&lt;h3 id=&quot;openstack-senlin-deploy&quot;&gt;Openstack-senlin deploy&lt;/h3&gt;

&lt;h4 id=&quot;1-基于dockeriocentos启动容器&quot;&gt;1. 基于docker.io/centos启动容器&lt;/h4&gt;

&lt;blockquote&gt;
  &lt;p&gt;使用docker.io/centos启动容器&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
docker run -it docker.io/centos

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;在启动的容器中执行以下安装&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
a) yum install python-pip gcc python-devel MySQL-python git -y

　在执行前需要添加epel源，python-pip没有在centos源里面

b) 拷贝已经download的本地依赖pip 包, senlin python-openstacksdk的requirements.txt到容器，执行依赖安装(

pip install --no-index --find-links=[file://]&amp;lt;DIR&amp;gt; -r requirements.txt

c)手动安装MySQLdb模块

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;２-在启动的容器中添加senlin信息&quot;&gt;２. 在启动的容器中添加senlin信息&lt;/h4&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
a) 创建senlin 用户( useradd  -d /var/lib/senlin -s /sbin/nologin senlin)

b) groupmod -g 970 senlin

c) usermod -u 970 senlin

d) chown -R senlin.senlin /var/lib/senlin

e) mkdir /etc/senlin

    mkdir /var/log/senlin

e) chgrp senlin /etc/senlin

f) chown senlin /var/log/senlin

g)  yum clean all

h） rm -rf /var/cache/yum/*

j) 删除拷贝过来的pip依赖包以及依赖文件

k)清理yum仓库信息

mkdir /etc/yum.repos.d/repo

mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repo

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;3构建senlinbase镜像&quot;&gt;3．构建senlin/base镜像&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
1) 退出容器

2) docker commit 容器名称(执行依赖包安装的容器) senlin/base

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;4安装senlin源码&quot;&gt;4．安装senlin源码&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
1) 基于senlin/base启动容器

2) git clone -b Development https://github.com/eayunstack/python-senlinclient

    git clone -b Development https://github.com/eayunstack/python-openstacksdk

    git clone -b Development https://github.com/eayunstack/senlin

3) 分别在senlin python-openstacksdk目录中执行python setup.py install

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;5创建新版本容器镜像&quot;&gt;5．创建新版本容器镜像&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
1) 退出容器

2) docker commit 容器名称(执行senlin源码安装容器)　eayunstack_senlin_base_1705

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;6容器封装服务&quot;&gt;6．容器封装服务&lt;/h3&gt;

&lt;blockquote&gt;
  &lt;p&gt;构建Dockerfile文件&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
FROM eayunstack_senlin_base_170705

COPY ./service.sh /usr/bin/

USER senlin

CMD [&quot;sh&quot;, &quot;/usr/bin/service.sh&quot;]

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;构建容器启动时执行的服务启动文件service.sh，并且添加执行权限&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
#!/bin/bash

# pass arguments to Shell Script through docker run



if [ &quot;$DAEMON&quot; = &quot;senlin-api&quot; ];then

    senlin-api --config-file /etc/senlin/senlin.conf

elif [ &quot;$DAEMON&quot; = &quot;senlin-engine&quot; ];then

    senlin-engine --config-file /etc/senlin/senlin.conf

elif [ &quot;$DAEMON&quot; = &quot;senlin-manage&quot; ];then

    senlin-manage db_sync

fi

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;执行容器build封装，使用构建的Dockerfile 与service.sh&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
docker build -t eayunstack/senlin-base .

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;７-导出镜像&quot;&gt;７. 导出镜像&lt;/h4&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
 docker save --output eayunstack_senlin_base.latest.170705 eayunstack/senlin-base

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;8fuel节点执行ansilble安装&quot;&gt;8．fuel节点执行ansilble安装&lt;/h4&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
 ansible-playbook -vvv site.yml 2&amp;gt;&amp;amp;1 |tee fabian.log

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

</description>
        <pubDate>Wed, 27 Sep 2017 12:32:06 +0000</pubDate>
        <link>http://farice4.github.io/2017/09/27/senlin_base_image/</link>
        <guid isPermaLink="true">http://farice4.github.io/2017/09/27/senlin_base_image/</guid>
        
        <category>Openstack senlin docker image</category>
        
        
        <category>Openstack</category>
        
      </item>
    
      <item>
        <title>Senlin docker build</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#openstack-senlin-deploy&quot; id=&quot;markdown-toc-openstack-senlin-deploy&quot;&gt;Openstack-senlin deploy&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#1-基于dockeriocentos启动容器&quot; id=&quot;markdown-toc-1-基于dockeriocentos启动容器&quot;&gt;1. 基于docker.io/centos启动容器&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#２-在启动的容器中添加senlin信息&quot; id=&quot;markdown-toc-２-在启动的容器中添加senlin信息&quot;&gt;２. 在启动的容器中添加senlin信息&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#3构建senlinbase镜像&quot; id=&quot;markdown-toc-3构建senlinbase镜像&quot;&gt;3．构建senlin/base镜像&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#4安装senlin源码&quot; id=&quot;markdown-toc-4安装senlin源码&quot;&gt;4．安装senlin源码&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#5创建新版本容器镜像&quot; id=&quot;markdown-toc-5创建新版本容器镜像&quot;&gt;5．创建新版本容器镜像&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#6容器封装服务&quot; id=&quot;markdown-toc-6容器封装服务&quot;&gt;6．容器封装服务&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#７-导出镜像&quot; id=&quot;markdown-toc-７-导出镜像&quot;&gt;７. 导出镜像&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#8fuel节点执行ansilble安装&quot; id=&quot;markdown-toc-8fuel节点执行ansilble安装&quot;&gt;8．fuel节点执行ansilble安装&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;openstack-senlin-deploy&quot;&gt;Openstack-senlin deploy&lt;/h3&gt;

&lt;p&gt;　　本文主要讲述如何构建senlin docker 容器，将构建好的容器通过ansilbe-playbook方式进行自动化部署&lt;/p&gt;

&lt;h4 id=&quot;1-基于dockeriocentos启动容器&quot;&gt;1. 基于docker.io/centos启动容器&lt;/h4&gt;

&lt;blockquote&gt;
  &lt;p&gt;使用docker.io/centos启动容器&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
docker run -it docker.io/centos

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;在启动的容器中执行以下安装&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
a) yum install python-pip gcc python-devel MySQL-python git -y

　在执行前需要添加epel源，python-pip没有在centos源里面

b) 拷贝已经download的本地依赖pip 包, senlin python-openstacksdk的requirements.txt到容器，执行依赖安装(

pip install --no-index --find-links=[file://]&amp;lt;DIR&amp;gt; -r requirements.txt

c)手动安装MySQLdb模块

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;２-在启动的容器中添加senlin信息&quot;&gt;２. 在启动的容器中添加senlin信息&lt;/h4&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
a) 创建senlin 用户( useradd  -d /var/lib/senlin -s /sbin/nologin senlin)

b) groupmod -g 970 senlin

c) usermod -u 970 senlin

d) chown -R senlin.senlin /var/lib/senlin

e) mkdir /etc/senlin

    mkdir /var/log/senlin

e) chgrp senlin /etc/senlin

f) chown senlin /var/log/senlin

g)  yum clean all

h） rm -rf /var/cache/yum/*

j) 删除拷贝过来的pip依赖包以及依赖文件

k)清理yum仓库信息

mkdir /etc/yum.repos.d/repo

mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repo

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;3构建senlinbase镜像&quot;&gt;3．构建senlin/base镜像&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
1) 退出容器

2) docker commit 容器名称(执行依赖包安装的容器) senlin/base

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;4安装senlin源码&quot;&gt;4．安装senlin源码&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
1) 基于senlin/base启动容器

2) 拷贝senlin python-openstacksdk源码包到启动的容器中

3) 分别在senlin python-openstacksdk目录中执行python setup.py install

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;5创建新版本容器镜像&quot;&gt;5．创建新版本容器镜像&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
1) 退出容器

2) docker commit 容器名称(执行senlin源码安装容器)　eayunstack_senlin_base_1705

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;6容器封装服务&quot;&gt;6．容器封装服务&lt;/h3&gt;

&lt;blockquote&gt;
  &lt;p&gt;构建Dockerfile文件&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
FROM eayunstack_senlin_base_170705

COPY ./service.sh /usr/bin/

USER senlin

CMD [&quot;sh&quot;, &quot;/usr/bin/service.sh&quot;]

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;构建容器启动时执行的服务启动文件service.sh，并且添加执行权限&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
#!/bin/bash

# pass arguments to Shell Script through docker run



if [ &quot;$DAEMON&quot; = &quot;senlin-api&quot; ];then

    senlin-api --config-file /etc/senlin/senlin.conf

elif [ &quot;$DAEMON&quot; = &quot;senlin-engine&quot; ];then

    senlin-engine --config-file /etc/senlin/senlin.conf

elif [ &quot;$DAEMON&quot; = &quot;senlin-manage&quot; ];then

    senlin-manage db_sync

fi

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;执行容器build封装，使用构建的Dockerfile 与service.sh&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
docker build -t eayunstack/senlin-base .

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;７-导出镜像&quot;&gt;７. 导出镜像&lt;/h4&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
 docker save --output eayunstack_senlin_base.latest.170705 镜像名称(为刚刚进行了服务封装的镜像)

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;8fuel节点执行ansilble安装&quot;&gt;8．fuel节点执行ansilble安装&lt;/h4&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
 ansible-playbook -vvv site.yml 2&amp;gt;&amp;amp;1 |tee fabian.log

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
        <pubDate>Wed, 05 Jul 2017 14:32:06 +0000</pubDate>
        <link>http://farice4.github.io/2017/07/05/senlin-docker-build/</link>
        <guid isPermaLink="true">http://farice4.github.io/2017/07/05/senlin-docker-build/</guid>
        
        <category>Openstack Senlin docker build</category>
        
        
        <category>Openstack</category>
        
      </item>
    
      <item>
        <title>Python Mock使用</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#mock介绍&quot; id=&quot;markdown-toc-mock介绍&quot;&gt;Mock介绍&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#mock使用举例&quot; id=&quot;markdown-toc-mock使用举例&quot;&gt;Mock使用举例&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;mock介绍&quot;&gt;Mock介绍&lt;/h3&gt;

&lt;p&gt;Mock这个词在英语中有模拟的这个意思，因此我们可以猜测出这个库的主要功能是模拟一些东西。准确的说，Mock是Python中一个用于支持单元测试的库，它的主要功能是使用mock对象替代掉指定的Python对象，以达到模拟对象的行为。&lt;/p&gt;

&lt;h3 id=&quot;mock使用举例&quot;&gt;Mock使用举例&lt;/h3&gt;

&lt;blockquote&gt;
  &lt;p&gt;程序代码(mockclass.py)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;class CouldClient(object):
    def connect(self):
        pass

    def disconnect(self):
        pass

    def upload(self):
        pass

    def download(self):
        pass

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;测试代码(testcould.py)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;

import unittest

import mock
from mockclass import CouldClient


class TestCloud(unittest.TestCase):
    def setUp(self):
        self.obj = mock.Mock(CouldClient)

    def terDown(self):
        self.obj = None

    def test_connect(self):
        self.obj.connect.return_value = 200
        self.assertEqual(self.obj.connect(), 200)


if __name__ == &apos;__main__&apos;:
    unittest.main()

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
        <pubDate>Thu, 09 Feb 2017 20:09:02 +0000</pubDate>
        <link>http://farice4.github.io/2017/02/09/Python-unittest-mock/</link>
        <guid isPermaLink="true">http://farice4.github.io/2017/02/09/Python-unittest-mock/</guid>
        
        <category>Unittest Mock使用</category>
        
        
        <category>Python</category>
        
      </item>
    
      <item>
        <title>Openstack client</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#介绍&quot; id=&quot;markdown-toc-介绍&quot;&gt;介绍&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#工作过程&quot; id=&quot;markdown-toc-工作过程&quot;&gt;工作过程&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#openstack-client使用举例&quot; id=&quot;markdown-toc-openstack-client使用举例&quot;&gt;OpenStack Client使用举例&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;介绍&quot;&gt;介绍&lt;/h4&gt;
&lt;p&gt;Openstack client(OSC) 为用户提供了一个同一的关于openstack cli操作与api调用的统一接口。&lt;/p&gt;

&lt;h4 id=&quot;工作过程&quot;&gt;工作过程&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;OpenstackClient 提供connection.py用于创建keystone 认证连接,profile.py用于注册openstackclient下的所有客户端接口&lt;/li&gt;
  &lt;li&gt;其它组件通过调用openstackclient 的connection创建连接&lt;/li&gt;
  &lt;li&gt;连接创建完成后，直接调用每个注册服务下的_proxy.py中的proxy各个方法(每个组件下，根据api的版本目录下都对应了_proxy.py)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;openstack-client使用举例&quot;&gt;OpenStack Client使用举例&lt;/h4&gt;

&lt;blockquote&gt;
  &lt;p&gt;构建连接文件conn.py
code:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;from openstack import connection
from openstack import profile

auth_url=&apos;http://10.10.10.114:5000/v3&apos;
region=&apos;RegionOne&apos;
project_name=&apos;admin&apos;
user_domain_name=&apos;Default&apos;
project_domain_name=&apos;Default&apos;
username=&apos;admin&apos;
password=&apos;123&apos;

def create_connection():
    prof = profile.Profile()
    prof.set_region(profile.Profile.ALL, region)
    conn = connection.Connection(profile=prof, auth_url=auth_url, project_name=project_name, username=username, passworin_name=project_domain_name)=user_domain_name, project_domaa
    return conn

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;以上代码导入了Openstack Client的connection方法与profile(组件接口注册), 创建了一个连接，当需要执行openstack client下的各个组件时，直接调用create_connection创建连接&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;列出网络
code:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;from conn import create_connection 
def list_networks(conn):
    print &quot;List networks:&quot;
    for pt in conn.network.networks():
        print pt.to_dict()

list_networks(create_connection) 调用conn.py中的连接
]# python connection.py 
List networks:
{u&apos;status&apos;: u&apos;ACTIVE&apos;, u&apos;subnets&apos;: [u&apos;df68f190-8933-4064-98cf-2392cfc9f590&apos;], u&apos;name&apos;: u&apos;admin_pri&apos;, u&apos;provider:physical_network&apos;: None, u&apos;admin_state_up&apos;: True, u&apos;tenant_id&apos;: u&apos;93236417c37d49b4b027f1811ec5af5e&apos;, u&apos;provider:network_type&apos;: u&apos;gre&apos;, u&apos;router:external&apos;: False, u&apos;shared&apos;: False, u&apos;id&apos;: u&apos;2209c875-d84e-4d6a-afaa-d2a6036e56fb&apos;, u&apos;provider:segmentation_id&apos;: 2}
{u&apos;status&apos;: u&apos;ACTIVE&apos;, u&apos;subnets&apos;: [u&apos;b7cd7a36-0d56-4b24-abd8-daa762c48710&apos;], u&apos;name&apos;: u&apos;public&apos;, u&apos;provider:physical_network&apos;: None, u&apos;admin_state_up&apos;: True, u&apos;tenant_id&apos;: u&apos;93236417c37d49b4b027f1811ec5af5e&apos;, u&apos;provider:network_type&apos;: u&apos;gre&apos;, u&apos;router:external&apos;: True, u&apos;shared&apos;: False, u&apos;id&apos;: u&apos;dff6bacc-206a-48be-bc86-281d8e73fa56&apos;, u&apos;provider:segmentation_id&apos;: 1}

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;列出loadbance pools(v1)
openstack client 不支持loadbance v1, 因此需要在openstack client 下修改pools.py中的base_path路径resource,由base_path = ‘/loadbance/pools’ 修改为base_path = ‘/lb/pools’&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;下面是单个文件的所有code:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;from openstack import profile
from openstack import connection

auth_url=&apos;http://10.10.10.114:5000/v3&apos;
region=&apos;RegionOne&apos;
project_name=&apos;admin&apos;
user_domain_name=&apos;Default&apos;
project_domain_name=&apos;Default&apos;
username=&apos;admin&apos;
password=&apos;123&apos;

def create_connection():
    prof = profile.Profile()
    prof.set_region(profile.Profile.ALL, region)
    conn = connection.Connection(profile=prof, auth_url=auth_url, project_name=project_name, username=username, password=password, user_domain_name=user_domain_name, project_domain_name=project_domain_name)
    return conn

conn = create_connection()

# List loadbance pools
def list_pools(conn):
    print &quot;List pools: &quot;
    for pt in conn.network.pools():
        print pt.to_dict()
list_pools(conn)

# python connection.py 
List pools: 
{u&apos;status&apos;: u&apos;ACTIVE&apos;, u&apos;lb_method&apos;: u&apos;ROUND_ROBIN&apos;, u&apos;protocol&apos;: u&apos;TCP&apos;, u&apos;description&apos;: u&apos;&apos;, u&apos;health_monitors&apos;: [], u&apos;subnet_id&apos;: u&apos;df68f190-8933-4064-98cf-2392cfc9f590&apos;, u&apos;tenant_id&apos;: u&apos;93236417c37d49b4b027f1811ec5af5e&apos;, u&apos;admin_state_up&apos;: True, u&apos;vip_id&apos;: u&apos;e7845623-7bba-4331-b24a-b64f01723892&apos;, u&apos;health_monitors_status&apos;: [], u&apos;members&apos;: [], u&apos;provider&apos;: u&apos;haproxy&apos;, u&apos;status_description&apos;: None, u&apos;id&apos;: u&apos;1b614f12-56ae-45e9-84f3-cda906203a0e&apos;, u&apos;name&apos;: u&apos;pool2&apos;}
{u&apos;status&apos;: u&apos;ACTIVE&apos;, u&apos;lb_method&apos;: u&apos;ROUND_ROBIN&apos;, u&apos;protocol&apos;: u&apos;TCP&apos;, u&apos;description&apos;: u&apos;&apos;, u&apos;health_monitors&apos;: [], u&apos;subnet_id&apos;: u&apos;df68f190-8933-4064-98cf-2392cfc9f590&apos;, u&apos;tenant_id&apos;: u&apos;93236417c37d49b4b027f1811ec5af5e&apos;, u&apos;admin_state_up&apos;: True, u&apos;vip_id&apos;: None, u&apos;health_monitors_status&apos;: [], u&apos;members&apos;: [], u&apos;provider&apos;: u&apos;haproxy&apos;, u&apos;status_description&apos;: None, u&apos;id&apos;: u&apos;d242dc52-5eb1-4bc6-8125-147b915c2ef2&apos;, u&apos;name&apos;: u&apos;pool3&apos;}
{u&apos;status&apos;: u&apos;ACTIVE&apos;, u&apos;lb_method&apos;: u&apos;ROUND_ROBIN&apos;, u&apos;protocol&apos;: u&apos;TCP&apos;, u&apos;description&apos;: u&apos;&apos;, u&apos;health_monitors&apos;: [], u&apos;subnet_id&apos;: u&apos;df68f190-8933-4064-98cf-2392cfc9f590&apos;, u&apos;tenant_id&apos;: u&apos;93236417c37d49b4b027f1811ec5af5e&apos;, u&apos;admin_state_up&apos;: True, u&apos;vip_id&apos;: None, u&apos;health_monitors_status&apos;: [], u&apos;members&apos;: [], u&apos;provider&apos;: u&apos;haproxy&apos;, u&apos;status_description&apos;: None, u&apos;id&apos;: u&apos;e417cd50-118f-485c-9e38-003a3fb0f751&apos;, u&apos;name&apos;: u&apos;pool3&apos;}

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
        <pubDate>Mon, 16 Jan 2017 11:32:06 +0000</pubDate>
        <link>http://farice4.github.io/2017/01/16/openstack-sdk-client/</link>
        <guid isPermaLink="true">http://farice4.github.io/2017/01/16/openstack-sdk-client/</guid>
        
        <category>Openstack Client</category>
        
        
        <category>Openstack</category>
        
      </item>
    
      <item>
        <title>Senlin Development record</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#senlin-profile&quot; id=&quot;markdown-toc-senlin-profile&quot;&gt;Senlin profile&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#senlin-cluster&quot; id=&quot;markdown-toc-senlin-cluster&quot;&gt;Senlin cluster&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;senlin-profile&quot;&gt;Senlin profile&lt;/h3&gt;

&lt;p&gt;This is about senlin development doc&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Senlin profile create&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;senlin profile about nova parameter in spec, senlin profile (name, type, metadata,)&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Senlin profile update&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;senlin support profile update, but update parameter is name or metadata&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Senlin profile delete&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;senlin support profile delete, but profile is not by use in cluster or nodes&lt;/p&gt;

&lt;h3 id=&quot;senlin-cluster&quot;&gt;Senlin cluster&lt;/h3&gt;

&lt;p&gt;Senlin cluster support zero or more nodes in cluster, cluster nodes use same profile&lt;/p&gt;

&lt;p&gt;Cluster support create,retrieve,update,delete opertion&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Cluster status&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;INIT: the cluster object has been initialized, but not created yet;&lt;/li&gt;
  &lt;li&gt;ACTIVE: the cluster is created and providing service;&lt;/li&gt;
  &lt;li&gt;CREATING: the cluster creation action is still on going;&lt;/li&gt;
  &lt;li&gt;ERROR: the cluster is still providing services, but there are things going wrong that needs human intervention;&lt;/li&gt;
  &lt;li&gt;CRITICAL: the cluster is not operational, it may or may not be providing services as expercted.
Senlin cannot recover if from its current status, The best way to deal with cluster is to delete it and then re-create it if needed.&lt;/li&gt;
  &lt;li&gt;DELETING: the cluster deleteion is ongoing;&lt;/li&gt;
  &lt;li&gt;WARNING: the cluster is operational, but there are some warnings detected during past operations. In this case, human involvement is suggested but not required.&lt;/li&gt;
  &lt;li&gt;UPDATING: the cluster is being updated.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;Cluster create&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;cluster create will be wait engine to complete the creation job&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;desired_capacity: the desired number of nodes in the cluster, which is treated aalso as initial number of nodes to be created;&lt;/li&gt;
  &lt;li&gt;min_size: the minimum number of nodes inside the cluster, default value is 0;&lt;/li&gt;
  &lt;li&gt;max_size: the maxinum number of nodes inside the cluster, default value is -1, which means ther is no upper limit on the number of nodes;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;Cluster get&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;list cluster&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Updating a cluster&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;a cluster can be updated upon user is requests.&lt;/p&gt;

&lt;p&gt;Cluster support update (name, profile_id, metadata, desired_capacity, min_size, max_size)&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Update cluster profile&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When profile_id is specified, the request will be interpreted as a wholistic update to all nodes across the cluster.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Update Cluster Size&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Cluster support update cluster desired_capacity、min_size、max_size. The desired_capacity update , node number will be immediate update.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Cluster Actions&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A cluster object supports the following asynchronous actions.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;add_nodes: add a list of nodes into the target cluster;&lt;/li&gt;
  &lt;li&gt;del_nodes: remove the specified list of nodes from the cluster;&lt;/li&gt;
  &lt;li&gt;replace_nodes: replace the speclfied list of nodes in the cluster;&lt;/li&gt;
  &lt;li&gt;resize: adjust the size of the cluster;&lt;/li&gt;
  &lt;li&gt;scale_in: explictly shrink the size of the cluster;&lt;/li&gt;
  &lt;li&gt;scale_out: explicitly enlarge the size of the cluster;&lt;/li&gt;
  &lt;li&gt;policy_attach: attach a policy object to the cluster;&lt;/li&gt;
  &lt;li&gt;policy_detach: detach a policy object from the cluster;&lt;/li&gt;
  &lt;li&gt;policy_update: modify the settings of a policy that is attached to the cluster;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;Adding nodes to a cluster&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Senlin API provides the add_nodes action for user to add some existing nodes into the specified cluster.&lt;/p&gt;

&lt;p&gt;The senlin engine will examine nodes in the list one by one and see if any of the following conditions is true. Senlin engine rejects the request if so:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Any node from the list is not in ACTIVE state ?&lt;/li&gt;
  &lt;li&gt;Any node from the list is still member of another cluster ?&lt;/li&gt;
  &lt;li&gt;Any node from the list is not found in the database ?&lt;/li&gt;
  &lt;li&gt;Number of nodes to add is zero ?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the cases where there are load-balancing policies attached to cluster, the CLUSTER_ADD_NODES action will save the list of UUIDs of the new nodes into the action is data field so that those policies clould update the associated resources.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Deleting Nodes from a Cluster&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Senlin API provides the del_nodes action for user to delete some existing nodes from the specified cluster. The parameter for this action interpreted as a list in which each item is the UUID, name or short ID of a node.&lt;/p&gt;

&lt;p&gt;The Senlin engine will examine nodes in the list one by one and see if any of the following conditions is true. Senlin engine rejects the request if so.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Any node from the list cannot be found from the database?&lt;/li&gt;
  &lt;li&gt;Any node from the list is not member of the specified cluster?&lt;/li&gt;
  &lt;li&gt;Number of nodes to delete is zero?&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;Replacing Nodes in a Cluster&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Senlin API support replacing existing nodes in the specified cluster.&lt;/p&gt;

&lt;p&gt;The Senlin engine will examine nodes in the dict one by one and see if all of the following conditions is true. Senlin engine acctpts the request if so.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;All nodes from the list can be found from the database&lt;/li&gt;
  &lt;li&gt;All replaced nodes from the list are the members of the specified cluster.&lt;/li&gt;
  &lt;li&gt;All replacement nodes from the list are not the members of any cluster.&lt;/li&gt;
  &lt;li&gt;The profile types of all replacement nodes match that of the specified cluster.&lt;/li&gt;
  &lt;li&gt;The statuses of all replacement nodes are ACTIVE.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;Resize a Cluster&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Senlin API support cluster resize, This operation is designed for the auto-scaling and manual-scaling use cases.&lt;/p&gt;

&lt;p&gt;Resize parameter about (adjustment_type, number, min_size, max_size, min_step, strict)&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Scaling in/out a Cluster&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As a convenience method, Selin provides the scale_out and the scale_in action API for clusters. With these two APIs, a user can request a cluster to be resized by the specified number of nodes.&lt;/p&gt;

&lt;p&gt;The scale_out and the scale_in APIs both take a parameter named count which is a positive integer.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Cluster Policy Bindings&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Senlin API provides the following action APIs for managing the binding relationship between a cluster and a policy:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;policy_attach: attach a policy to a cluster;&lt;/li&gt;
  &lt;li&gt;policy_detach: detach a policy from a cluster;&lt;/li&gt;
  &lt;li&gt;policy_update: update the properties of the binding between a cluster and policy.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The policy default enable in cluster&lt;/p&gt;
</description>
        <pubDate>Tue, 13 Dec 2016 14:32:06 +0000</pubDate>
        <link>http://farice4.github.io/2016/12/13/senlin-development/</link>
        <guid isPermaLink="true">http://farice4.github.io/2016/12/13/senlin-development/</guid>
        
        <category>Openstack Senlin Development doc</category>
        
        
        <category>Openstack</category>
        
      </item>
    
      <item>
        <title>Senlin introduction</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#senlin-基本介绍&quot; id=&quot;markdown-toc-senlin-基本介绍&quot;&gt;Senlin 基本介绍&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#senlin-架构&quot; id=&quot;markdown-toc-senlin-架构&quot;&gt;Senlin 架构&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#senlin-功能&quot; id=&quot;markdown-toc-senlin-功能&quot;&gt;Senlin 功能&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#senlin-名词解析&quot; id=&quot;markdown-toc-senlin-名词解析&quot;&gt;Senlin 名词解析&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#senlin-功能-1&quot; id=&quot;markdown-toc-senlin-功能-1&quot;&gt;Senlin 功能&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#senlin部署条件&quot; id=&quot;markdown-toc-senlin部署条件&quot;&gt;Senlin部署条件&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;senlin-基本介绍&quot;&gt;Senlin 基本介绍&lt;/h4&gt;

&lt;p&gt;Senlin 是Openstack 下的一个组件服务， Senlin的架构完全是为HA和AutoScaling设计的， 支持的插件包括Nova, Heat, Neutron, Loadbance, Ceilometer, Container&lt;/p&gt;

&lt;h5 id=&quot;senlin-架构&quot;&gt;Senlin 架构&lt;/h5&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/201612/senlin_jiagou.png&quot; alt=&quot;Senlin 结构&quot; /&gt;&lt;/p&gt;

&lt;p&gt;主要架构包括如下：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;senlinclient&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;senlin 客户端与Openstack其它组件一样提供命令行的客户端支持, 与senlin server交互&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;senlin api&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;senlin api 提供senlin reset api服务，对外提供senlin server的所有api接口&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;senlin-engine&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;senlin 核心服务， 用于操作senlin的集群、节点、profile文件、webhook、策略等&lt;/p&gt;

&lt;h4 id=&quot;senlin-功能&quot;&gt;Senlin 功能&lt;/h4&gt;

&lt;h5 id=&quot;senlin-名词解析&quot;&gt;Senlin 名词解析&lt;/h5&gt;

&lt;ul&gt;
  &lt;li&gt;Profile&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;profile 是Senlin里面的模板文件， 与Heat模板文件一样， 支持nova, heat, 容器&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/201612/senlin_profile.png&quot; alt=&quot;Senlin profile&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;cluster&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Senlin 集群概念， 提供对象管理，这些对象的集合称为集群&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Node&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Senlin 抽象的物理节点， 节点可以单独存在，也可以将节点加入到集群， 创建节点后， nova会创建相应的instance&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Policies&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Senlin 中的策略， 针对一个集群可以配置不同的策略，这些策略可以来管理集群中的资源&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/201612/senlin_policy.png&quot; alt=&quot;Senlin policy&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Receiver&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Senlin 中的接收器，对外提供一个url地址， 执行Post url地址能够改变集群中的节点数&lt;/p&gt;

&lt;h5 id=&quot;senlin-功能-1&quot;&gt;Senlin 功能&lt;/h5&gt;

&lt;ul&gt;
  &lt;li&gt;Senlin AutoScaling&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Heat 的设计是基于 AWS 的，不够通用，目前我们认为 Heat 的作用更多的在于基于模版的资源管理，它的重点不在于AutoScaling、HA，而是作为一个引擎来帮其他服务或者开发者做资源管理的工作。&lt;/p&gt;

&lt;p&gt;Selin 项目本身就是针对集群与AutoScaling设计的&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Senlin 与 Heat AutoScaling区别&lt;/p&gt;
&lt;/blockquote&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;名称&lt;/th&gt;
      &lt;th&gt;支持类型&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Heat&lt;/td&gt;
      &lt;td&gt;支持通过Ceilometer Alarm的方式触发webhook提供autoscaling自动伸缩， 支持创建Loadbance负载均衡&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Senlin&lt;/td&gt;
      &lt;td&gt;支持Receiver对外提供url， 上层可根据需要如：根据时间、根据特定情况、根据alarm警告触发url，实现autoscaling自动伸缩, 支持创建Loadbance负载均衡&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;blockquote&gt;
  &lt;p&gt;Senlin AutoScaling 架构
&lt;img src=&quot;/assets/images/201612/senlin_autoscaling.png&quot; alt=&quot;Senlin policy&quot; /&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;1. Senlin 通过profile构建集群
2. 为集群添加策略(策略中定义添加/删除 节点数)
3. 创建Receiver提供webhook地址url
4. 根据需要触发webhook url实现策略定义(触发webhook url的包括ceilometer alarm、上层时间计划、特定需要)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Senlin 集群节点扩展与删除&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Senlin 中提供了对集群中的节点扩展与删除操作，添加与删除的节点满足集群中的最大与最小值, 支持在集群中创建节点，同样支持将Senlin 创建的节点添加到集群中&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Senlin 集群定义节点数&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Senlin 在创建集群时支持指定创建集群中的节点数，当最小为0时，支持创建一个空集群，后期根据需要为集群中添加节点&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Senlin 集群策略支持&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Senlin集群支持自定义策略，策略类型包括删除(可根据需要删除集群中的指定节点)、Scaling策略(提供自动伸缩策略)、Loadbance策略(支持集群提供负载均衡)、健康检测策略(根据健康检测结果，替换掉集群中出现故障的节点)&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Selin 跨区域支持&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Senlin 支持节点跨区域管理(nova zone的概念)&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Senlin 支持事件记录&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Senlin 根据集群中触发的事件，记录事件的时间与触发的条件&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Senlin 支持集群Resize操作&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Senlin Resize允许修改集群中的最大、最小、期望、添加节点数&lt;/p&gt;

&lt;h4 id=&quot;senlin部署条件&quot;&gt;Senlin部署条件&lt;/h4&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;1) Senlin 发布第一个版本为mitaka版本， 安装时需要的认证必须为keystone v3版本

2) Senlin 的loadbance策略支持的loadbance必须为单独服务，必须配置单独的endpoint

3) Senlin 不提供alarm警告创建， 上层使用时根据需要创建alarm，创建的alarm绑定cluster id，webhook执行动作为senlin 中的receiver 提供的alarm_url链接

4) Senlin 要实现根据时间，根据特定计划触发receiver中的alarm_url链接需要上层配置计划，配置触发alarm_url链接

5) Senlin 在使用中需要openstacksdk支持, openstacksdk实现了各个组件组件的调用
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
        <pubDate>Tue, 13 Dec 2016 14:32:06 +0000</pubDate>
        <link>http://farice4.github.io/2016/12/13/senlin-introduction/</link>
        <guid isPermaLink="true">http://farice4.github.io/2016/12/13/senlin-introduction/</guid>
        
        <category>Openstack Senlin introduction</category>
        
        
        <category>Openstack</category>
        
      </item>
    
  </channel>
</rss>
