<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>iTimothy</title>
  
  <subtitle>君看一叶舟，出没风波里</subtitle>
  <link href="/atom.xml" rel="self"/>
  
  <link href="https://xiaozhou.net/"/>
  <updated>2020-02-29T12:32:56.167Z</updated>
  <id>https://xiaozhou.net/</id>
  
  <author>
    <name>Timothy</name>
    
  </author>
  
  <generator uri="http://hexo.io/">Hexo</generator>
  
  <entry>
    <title>Your own time zone</title>
    <link href="https://xiaozhou.net/your-own-timezone-2020-02-29.html"/>
    <id>https://xiaozhou.net/your-own-timezone-2020-02-29.html</id>
    <published>2020-02-29T12:29:50.000Z</published>
    <updated>2020-02-29T12:32:56.167Z</updated>
    
    <content type="html"><![CDATA[<p>New York is three hours ahead of California,<br>But that doesn’t make California slow.<br>Someone graduated at the age of 22,<br>But waited five years before securing a good job.<br>Some became a CEO at 25,<br>And died at 50.<br>While another became a CEO at 50,<br>And lived to 90 years.<br>Someone is still single,<br>While someone else got married.<br>Obama retired at 55,<br>&amp; Trump started at 70.<br>Everyone in this world works based on their time zone.<br>People around you might seem to be ahead of you,<br>&amp; some might seem to be behind you.<br>But everyone is running their own race, in their own time.<br>Do not envy them &amp; do not mock them.<br>They are in their time zone, and you are in yours.<br>Life is about waiting for the right moment to act.<br>So, relax.<br>You’re not late.<br>You’re not early.<br>You are very much on time.</p>]]></content>
    
    <summary type="html">
    
      
      
        &lt;p&gt;New York is three hours ahead of California,&lt;br&gt;But that doesn’t make California slow.&lt;br&gt;Someone graduated at the age of 22,&lt;br&gt;But wait
      
    
    </summary>
    
    
  </entry>
  
  <entry>
    <title>HHKB 蓝牙改造指北</title>
    <link href="https://xiaozhou.net/ydkb-ble-for-hhkb-2019-12-21.html"/>
    <id>https://xiaozhou.net/ydkb-ble-for-hhkb-2019-12-21.html</id>
    <published>2019-12-21T14:48:55.000Z</published>
    <updated>2019-12-21T15:52:03.675Z</updated>
    
    <content type="html"><![CDATA[<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>自从 2013 年<a href="https://xiaozhou.net/got_hhkb_pro_2-2013-06-03.html">入手 HHKB Pro2</a>，以及后续<a href="https://xiaozhou.net/got-hhkb-pro-type-s-2016-02-23.html">入手 HHKB Pro Type-S</a>以来，HHKB 已经成为我日常工作的主力键盘。尽管后续官方还推出了 HHKB 的蓝牙版本，考虑再三，我也没有继续再入手了。原因是官方的蓝牙版 HHKB 有一个凸起的电池仓，由两节电池进行供电。相比起有线版本，凸起的电池仓有点影响美观。</p><p><img src="https://xiaozhou.net/pics/HHKB/hhkb-ble0.png" alt></p><p>要是 HHKB 的蓝牙版能通过内置锂电池的方式对键盘进行供电，并去掉那个电池仓的话，那岂不是更好？</p><a id="more"></a><p>事实上，虽然官方并没有推出这样的版本，但是民间已经有很多 DIY 的方案，对有线 HHKB 进行改造了。之前看到过网上的一些方案，感觉并不是很成熟，直到最近一个叫<a href="http://help.ydkb.io/doku.php?id=kb-mods:hhkb-ble" target="_blank" rel="noopener">YDKB</a>的改造方案，引起了我的兴趣。</p><p>YDKB 是由国人 Yang 开发键盘的主控芯片，其中针对 HHKB 进行蓝牙改造的主控模块，叫做<code>HHKB BLE Mod</code>。通过替换掉 HHKB 官方原厂的主控芯片，你的 HHKB 立马就能从有线变为蓝牙/有线的双模版本，意思是既可以保留之前有线的功能，通过 USB 连接电脑使用，也可以通过蓝牙无线的方式连接电脑使用，所谓一举两得的解决方案。</p><p>其实从 10 月下旬，我就购买了 YDKB 的改装套件，包括：一个主控芯片，卖家代焊接 3 个 LED 灯，并买了一块内置锂电池。由于我现在在新加坡，而淘宝并不支持跨国邮寄锂电池，只好先下单将套件邮寄到国内。11 月底刚好回国一趟，然后人肉将 YDKB 的改装套件带了过来……</p><p><img src="https://xiaozhou.net/pics/HHKB/hhkb-ble8.jpeg" alt></p><h2 id="动手改造"><a href="#动手改造" class="headerlink" title="动手改造"></a>动手改造</h2><p>YDKB 的这款<code>HHKB BLE Mod</code>是一个集成度较高的主控模块，所以在安装上没有太大难度。我没有电烙铁，也想偷懒，于是让卖家帮焊上了 LED 灯，有兴趣的同学可以自己 DIY 一下 LED 灯。</p><p>HHKB 的背面只有三颗螺丝，拆开后，可以看到内部结构其实也挺简单。</p><p><img src="https://xiaozhou.net/pics/HHKB/hhkb-ble1.jpeg" alt></p><p>原厂的主控芯片其实没多大体积，我们的目标，就是要拆下那块原厂主控，安装上 YDKB 的主控。</p><p><img src="https://xiaozhou.net/pics/HHKB/hhkb-ble2.jpeg" alt></p><p>拧下固定主控芯片的螺丝，拔掉数据排线，就可以取下原厂主控了。</p><p><img src="https://xiaozhou.net/pics/HHKB/hhkb-ble3.jpeg" alt></p><p>接着是安装 YDKB 的主控，用螺丝固定，插上数据排线。电池正刚好可以放在左边空余的位置，注意将电池的线接上主控。卖家还附送了胶条，用来把电池粘在键盘外壳的内壁上。为了不让电池接触到键盘，垫了一层塑料纸。</p><p>接下来的过程就简单了，对齐 LED 灯，合上盖子，拧好螺丝。然后拨开那个主控芯片上的开关，不出意外的话，键盘开始工作，并进入蓝牙匹配状态。</p><p><img src="https://xiaozhou.net/pics/HHKB/hhkb-ble5.png" alt></p><p>在 Mac Book 的蓝牙设置中，找到<code>HHKB BLE</code>并匹配连接，大功告成!<br>由于是第一次使用，锂电池的电量不一定是满电状态，所以可以接上 USB 给锂电池充电。</p><p><img src="https://xiaozhou.net/pics/HHKB/hhkb-ble4.jpeg" alt></p><p>从键盘的背后来看，除了能看到 LED 指示灯，其他的样子和改造前无异。另外，开关被隐藏在了之前调整 DIP 开关的盖子里面。这个开关就是整个主控电源的总开关了。之前的 DIP 开关在改造后已经被去掉，因为 YDKB 可以通过刷固件的形式，支持更多的自定义功能，之前官方 DIP 调节键位设置的功能也略显鸡肋。</p><h2 id="键位定制"><a href="#键位定制" class="headerlink" title="键位定制"></a>键位定制</h2><p>这款 YDKB 主控强大的地方不仅在于支持有线和蓝牙双模，更方便的地方还在于支持更丰富功能的自定义按键和更方便的固件烧写方式，这也是前面提到的完胜官方DIP开关的功能。</p><p>YDKB 默认支持 8 层的自定义按键设置，甚至还支持 LED 灯的设置。访问官网 <a href="http://ydkb.io" target="_blank" rel="noopener">http://ydkb.io</a>，可以对你的 HHKB 每一层按键进行配置。其实对于我来说，两层已经够我用了。</p><p><img src="https://xiaozhou.net/pics/HHKB/hhkb-ble6.png" alt></p><p>值得一提的亮点还是固件烧写的方式，真的非常方便，通过同时按住左右<code>Shift</code>键和<code>b</code>键，键盘会重启，此时立马再按住<code>Esc</code>键不放，键盘就会进入 U 盘刷机模式。在 Mac 的笔记本下，你会发现文件浏览器里面多出了一个可以移动设备。</p><p><img src="https://xiaozhou.net/pics/HHKB/hhkb-ble7.png" alt></p><p>从 YDKB 的网站上设置好你的自定义键位，下载得到一个 HHKB_BLE.BIN 文件，替换掉移动设备里面那个文件，然后退出移动设备，这样键盘的固件就算是刷写成功了，不得不说，实在是非常的方便。</p><h2 id="蓝牙与续航体验"><a href="#蓝牙与续航体验" class="headerlink" title="蓝牙与续航体验"></a>蓝牙与续航体验</h2><p>HHKB 改造成蓝牙无线后，日常工作用来码字和写代码，没有感觉到因为无线而带来的明显延迟。由于没有了连线，键盘的摆放位置变得更加随意起来，可以放在MacBook上，或者桌子上用，甚至是腿上用。众所周知，新款的MacBook去掉了USB接口，之前为了接键盘，还得适配器来转接。现在有了蓝牙，更是方便多了，我甚至更愿意特地把键盘放包里背到任何地方拿出来使用。</p><p>此外，内置的锂电池也是我喜欢的一点，没有官方突出的电池仓，也不用换电池，相对来说更加的经济和环保。内置的锂电池是 2500mAh 的型号，经过接近一个月的测试，充满一次电量大概需要几小时，满电估计能续航一个多月左右，续航表现也是令人满意的。</p><p>YDKB 还为电池续航提供了一些省电的设计。平日离开的时候，可以通过快捷键让键盘进入低功耗省电模式，重新激活键盘，同时按住<code>F</code>键和<code>J</code>键保持三秒左右，即可重新激活键盘，非常方便。</p><p>唯一感觉不足的地方，是电池充满电之后，一直显示电量为 90，而不是 100，这一点也在群里跟作者确认过了，90 即表示满电状态，并不是 100，也许这是对于强迫症的我来说，唯一的一点小缺憾吧，但是完全不影响使用。</p><h2 id="小结"><a href="#小结" class="headerlink" title="小结"></a>小结</h2><p>不得不说 YDKB 是一款比较完善的 HHKB 蓝牙改造方案，通过改造，让你的 HHKB 键盘同时支持有线和蓝牙的连接方式，实在是让 HHKB 得到了质的飞跃，有兴趣将 HHKB 改造为无线蓝牙的同学可以考虑入手。</p><h2 id="相关文章推荐"><a href="#相关文章推荐" class="headerlink" title="相关文章推荐"></a>相关文章推荐</h2><p><a href="https://xiaozhou.net/got_hhkb_pro_2-2013-06-03.html">《码农神器 HHKB Pro2 入手与开箱》</a><br><a href="https://xiaozhou.net/got_hhkb_pro_2-2013-06-03.html">《终极退烧利器 HHKB Pro Type-S 入手与开箱》</a></p>]]></content>
    
    <summary type="html">
    
      &lt;h2 id=&quot;前言&quot;&gt;&lt;a href=&quot;#前言&quot; class=&quot;headerlink&quot; title=&quot;前言&quot;&gt;&lt;/a&gt;前言&lt;/h2&gt;&lt;p&gt;自从 2013 年&lt;a href=&quot;https://xiaozhou.net/got_hhkb_pro_2-2013-06-03.html&quot;&gt;入手 HHKB Pro2&lt;/a&gt;，以及后续&lt;a href=&quot;https://xiaozhou.net/got-hhkb-pro-type-s-2016-02-23.html&quot;&gt;入手 HHKB Pro Type-S&lt;/a&gt;以来，HHKB 已经成为我日常工作的主力键盘。尽管后续官方还推出了 HHKB 的蓝牙版本，考虑再三，我也没有继续再入手了。原因是官方的蓝牙版 HHKB 有一个凸起的电池仓，由两节电池进行供电。相比起有线版本，凸起的电池仓有点影响美观。&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://xiaozhou.net/pics/HHKB/hhkb-ble0.png&quot; alt&gt;&lt;/p&gt;&lt;p&gt;要是 HHKB 的蓝牙版能通过内置锂电池的方式对键盘进行供电，并去掉那个电池仓的话，那岂不是更好？&lt;/p&gt;
    
    </summary>
    
      <category term="数码控" scheme="https://xiaozhou.net/categories/%E6%95%B0%E7%A0%81%E6%8E%A7/"/>
    
    
      <category term="HHKB" scheme="https://xiaozhou.net/tags/HHKB/"/>
    
      <category term="蓝牙" scheme="https://xiaozhou.net/tags/%E8%93%9D%E7%89%99/"/>
    
      <category term="YDKB" scheme="https://xiaozhou.net/tags/YDKB/"/>
    
  </entry>
  
  <entry>
    <title>在Spacemacs中配置Fira Code并启用ligatures特性</title>
    <link href="https://xiaozhou.net/setup-spacemacs-with-fira-code-ligatures-2019-09-09.html"/>
    <id>https://xiaozhou.net/setup-spacemacs-with-fira-code-ligatures-2019-09-09.html</id>
    <published>2019-09-09T04:09:56.000Z</published>
    <updated>2019-09-09T07:45:56.093Z</updated>
    
    <content type="html"><![CDATA[<p>Fira是Mozilla主推的字体系列。Fira Code是其中的一员，专为写程序而生。出来具有等宽等基本属性外，还加入了编程连字特性（ligatures）。编程连字特性，其实就是利用这个特性对编程中的常用符号进行优化，比如把输入的「!=」直接显示成「≠」或者把「&gt;=」变成「≥ 」等等，以此来提高代码的可读性。</p><p><img src="https://xiaozhou.net/pics/spacemacs/firacode1.png" alt></p><p>作为传说中的程序员，Fira Code也早已称为我的各大常用编辑器标配字体。Fira Code在其他编辑器和终端上配置较为简单，选中字体过后，启用Ligatures Feature即可。Spacemacs和Emacs的配置稍微复杂一些，这里分享一下Fira Code在Spacemacs下的配置。</p><a id="more"></a><h3 id="第一步"><a href="#第一步" class="headerlink" title="第一步"></a>第一步</h3><ul><li>安装 <a href="https://github.com/tonsky/FiraCode" target="_blank" rel="noopener">Fira Code</a> 字体</li><li>安装 <a href="https://github.com/ryanoasis/nerd-fonts" target="_blank" rel="noopener">Nerd Fonts</a> 字体</li></ul><h3 id="第二步"><a href="#第二步" class="headerlink" title="第二步"></a>第二步</h3><p>获取并安装 <a href="https://github.com/tonsky/FiraCode/files/412440/FiraCode-Regular-Symbol.zip" target="_blank" rel="noopener">Fira Code Symbol Font</a>。对于Linux系统，可以直接把字体解压并放到 <code>/usr/share/fonts</code> 目录，并重载字体的cache，使其生效。</p><h3 id="第三步"><a href="#第三步" class="headerlink" title="第三步"></a>第三步</h3><p>在Spacemacs中，使用<code>&lt;SPC&gt; f e d</code> 编辑 <code>~/.spacemacs</code>配置文件。对于Emacs用户来说，可以编辑 <code>~/.emacs.d/init.el</code>。</p><p>在配置文件中，加入如下设置：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">dotspacemacs-default-font &apos;((&quot;FuraCode Nerd Font Mono&quot;</span><br><span class="line">                               :size 16</span><br><span class="line">                               :weight medium</span><br><span class="line">                               :width normal</span><br><span class="line">                               :powerline-scale 1.1)</span><br><span class="line">                               (&quot;Fira Code Symbol&quot;</span><br><span class="line">                               :size 16</span><br><span class="line">                               :weight normal</span><br><span class="line">                               :width normal</span><br><span class="line">                               :powerline-scale 1.1))</span><br></pre></td></tr></table></figure><h3 id="第四步"><a href="#第四步" class="headerlink" title="第四步"></a>第四步</h3><p>同样是编辑配置文件，在Spacemacs的配置项<code>dotspacemacs-user-config</code>中加入如下配置：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">(defun dotspacemacs/user-config()</span><br><span class="line"> &quot;Configuration function for user code.&quot;</span><br><span class="line">;; Font Ligatures</span><br><span class="line">  (defun my-correct-symbol-bounds (pretty-alist)</span><br><span class="line">      &quot;Prepend a TAB character to each symbol in this alist,</span><br><span class="line">  this way compose-region called by prettify-symbols-mode</span><br><span class="line">  will use the correct width of the symbols</span><br><span class="line">  instead of the width measured by char-width.&quot;</span><br><span class="line">      (mapcar (lambda (el)</span><br><span class="line">                (setcdr el (string ?\t (cdr el)))</span><br><span class="line">                el)</span><br><span class="line">              pretty-alist))</span><br><span class="line">  (defun my-ligature-list (ligatures codepoint-start)</span><br><span class="line">      &quot;Create an alist of strings to replace with</span><br><span class="line">  codepoints starting from codepoint-start.&quot;</span><br><span class="line">      (let ((codepoints (-iterate &apos;1+ codepoint-start (length ligatures))))</span><br><span class="line">        (-zip-pair ligatures codepoints)))</span><br><span class="line">  (setq my-fira-code-ligatures</span><br><span class="line">      (let* ((ligs &apos;(&quot;www&quot; &quot;**&quot; &quot;***&quot; &quot;**/&quot; &quot;*&gt;&quot; &quot;*/&quot; &quot;\\\\&quot; &quot;\\\\\\&quot;</span><br><span class="line">                    &quot;&#123;-&quot; &quot;[]&quot; &quot;::&quot; &quot;:::&quot; &quot;:=&quot; &quot;!!&quot; &quot;!=&quot; &quot;!==&quot; &quot;-&#125;&quot;</span><br><span class="line">                    &quot;--&quot; &quot;---&quot; &quot;--&gt;&quot; &quot;-&gt;&quot; &quot;-&gt;&gt;&quot; &quot;-&lt;&quot; &quot;-&lt;&lt;&quot; &quot;-~&quot;</span><br><span class="line">                    &quot;#&#123;&quot; &quot;#[&quot; &quot;##&quot; &quot;###&quot; &quot;####&quot; &quot;#(&quot; &quot;#?&quot; &quot;#_&quot; &quot;#_(&quot;</span><br><span class="line">                    &quot;.-&quot; &quot;.=&quot; &quot;..&quot; &quot;..&lt;&quot; &quot;...&quot; &quot;?=&quot; &quot;??&quot; &quot;;;&quot; &quot;/*&quot;</span><br><span class="line">                    &quot;/**&quot; &quot;/=&quot; &quot;/==&quot; &quot;/&gt;&quot; &quot;//&quot; &quot;///&quot; &quot;&amp;&amp;&quot; &quot;||&quot; &quot;||=&quot;</span><br><span class="line">                    &quot;|=&quot; &quot;|&gt;&quot; &quot;^=&quot; &quot;$&gt;&quot; &quot;++&quot; &quot;+++&quot; &quot;+&gt;&quot; &quot;=:=&quot; &quot;==&quot;</span><br><span class="line">                    &quot;===&quot; &quot;==&gt;&quot; &quot;=&gt;&quot; &quot;=&gt;&gt;&quot; &quot;&lt;=&quot; &quot;=&lt;&lt;&quot; &quot;=/=&quot; &quot;&gt;-&quot; &quot;&gt;=&quot;</span><br><span class="line">                    &quot;&gt;=&gt;&quot; &quot;&gt;&gt;&quot; &quot;&gt;&gt;-&quot; &quot;&gt;&gt;=&quot; &quot;&gt;&gt;&gt;&quot; &quot;&lt;*&quot; &quot;&lt;*&gt;&quot; &quot;&lt;|&quot; &quot;&lt;|&gt;&quot;</span><br><span class="line">                    &quot;&lt;$&quot; &quot;&lt;$&gt;&quot; &quot;&lt;!--&quot; &quot;&lt;-&quot; &quot;&lt;--&quot; &quot;&lt;-&gt;&quot; &quot;&lt;+&quot; &quot;&lt;+&gt;&quot; &quot;&lt;=&quot;</span><br><span class="line">                    &quot;&lt;==&quot; &quot;&lt;=&gt;&quot; &quot;&lt;=&lt;&quot; &quot;&lt;&gt;&quot; &quot;&lt;&lt;&quot; &quot;&lt;&lt;-&quot; &quot;&lt;&lt;=&quot; &quot;&lt;&lt;&lt;&quot; &quot;&lt;~&quot;</span><br><span class="line">                    &quot;&lt;~~&quot; &quot;&lt;/&quot; &quot;&lt;/&gt;&quot; &quot;~@&quot; &quot;~-&quot; &quot;~=&quot; &quot;~&gt;&quot; &quot;~~&quot; &quot;~~&gt;&quot; &quot;%%&quot;</span><br><span class="line">                    &quot;x&quot; &quot;:&quot; &quot;+&quot; &quot;+&quot; &quot;*&quot;)))</span><br><span class="line">        (my-correct-symbol-bounds (my-ligature-list ligs #Xe100))))</span><br><span class="line">  (defun my-set-fira-code-ligatures ()</span><br><span class="line">      &quot;Add fira code ligatures for use with prettify-symbols-mode.&quot;</span><br><span class="line">      (setq prettify-symbols-alist</span><br><span class="line">            (append my-fira-code-ligatures prettify-symbols-alist))</span><br><span class="line">      (prettify-symbols-mode))</span><br><span class="line">  (add-hook &apos;prog-mode-hook &apos;my-set-fira-code-ligatures))</span><br></pre></td></tr></table></figure><h3 id="第五步"><a href="#第五步" class="headerlink" title="第五步"></a>第五步</h3><p>最后，重载Spacemacs/Emacs的配置文件，使配置生效，即可启用Fira Code字体的Ligatures连字特性。</p>]]></content>
    
    <summary type="html">
    
      &lt;p&gt;Fira是Mozilla主推的字体系列。Fira Code是其中的一员，专为写程序而生。出来具有等宽等基本属性外，还加入了编程连字特性（ligatures）。编程连字特性，其实就是利用这个特性对编程中的常用符号进行优化，比如把输入的「!=」直接显示成「≠」或者把「&amp;gt;=」变成「≥ 」等等，以此来提高代码的可读性。&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://xiaozhou.net/pics/spacemacs/firacode1.png&quot; alt&gt;&lt;/p&gt;&lt;p&gt;作为传说中的程序员，Fira Code也早已称为我的各大常用编辑器标配字体。Fira Code在其他编辑器和终端上配置较为简单，选中字体过后，启用Ligatures Feature即可。Spacemacs和Emacs的配置稍微复杂一些，这里分享一下Fira Code在Spacemacs下的配置。&lt;/p&gt;
    
    </summary>
    
      <category term="技术控" scheme="https://xiaozhou.net/categories/%E6%8A%80%E6%9C%AF%E6%8E%A7/"/>
    
    
      <category term="Spacemacs" scheme="https://xiaozhou.net/tags/Spacemacs/"/>
    
      <category term="Emacs" scheme="https://xiaozhou.net/tags/Emacs/"/>
    
      <category term="Ligatures" scheme="https://xiaozhou.net/tags/Ligatures/"/>
    
  </entry>
  
  <entry>
    <title>使用Spacemacs打造你的开发环境</title>
    <link href="https://xiaozhou.net/from-neovim-to-spacemacs-2019-09-04.html"/>
    <id>https://xiaozhou.net/from-neovim-to-spacemacs-2019-09-04.html</id>
    <published>2019-09-04T07:27:23.000Z</published>
    <updated>2019-09-06T02:32:25.534Z</updated>
    
    <content type="html"><![CDATA[<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p><a href="https://xiaozhou.net/from-vim-to-neovim-2016-05-21.html">从Vim到NeoVim</a>至今，已经三年多了，我的主力开发环境依然是iTerm2+Tmux+NeoVim。中途还试过VSCode和GoLand，作为新生代的编辑器，这两款用起来果然不错。不过，总感觉可以折腾的东西变少了一些。后来看到Emacs里面的Evil Mode，知道原来在Emacs里面也可以折腾Vim的键位绑定，何不一试？</p><p>在Google和查找了很多资料，还找到几份不错的Emacs配置，拿来直接修改一下就可以满足自己日常Go的开发了。不过对于我这种Elisp不太熟悉的新手，配置文件出错了得花时间调试和排错。不得不承认，这是一件稍微痛苦的事情。</p><p>再后来，直到我把目光转向了已经火了一段时间的Spacemacs。通过最近一段时间的尝试，我发现Spacemacs经过一波折腾和配置，能完全满足我的日常Go开发的需要，甚至有越用越顺手的感觉，罪过罪过……难道我这就要背叛Vim转向Emacs了？不对!我并没有背叛Vim，我只是想在Emacs里面用Vim而已……</p><p>提起Spacemacs，它并不是一个Emacs的单独发型版本，而是一份集成度和友好度更高的Emacs配置文件而已。按照官方的介绍，Spacemacs是一个由社区驱动的Emacs衍生版本，正如官网上的这句话: <code>The best editor is neither Emacs nor Vim, it&#39;s Emacs and Vim!</code> Spacemacs社区的目地仿佛是为了消除Emacs和Vim之间的战争。而在我看来，Spacemacs的出现是为了综合Emacs和Vim的长处，让更多的Vimer可以在其中体验Emacs。</p><a id="more"></a><h2 id="配置Spacemacs"><a href="#配置Spacemacs" class="headerlink" title="配置Spacemacs"></a>配置Spacemacs</h2><p>前面提到过，Spacemacs并不是一个Emacs的独立发型版本，只是一份集成度较高的配置，所以Spacemacs的安装也异常简单:</p><ul><li>安装Emacs，这里我直接选择了GNU Emacs 26.2</li><li>clone Spacemacs的配置到本机的 <code>~/.emacs.d</code> 即可</li></ul><p>在第一次启动Spacemacs的时候，会有很多交互式选项，用于配置Spacemacs，也可以选择是用Emacs默认键位布局，还是使用Evil Mode。既然要在Emacs中使用Vim，当然是选择Evil Mode了!</p><h2 id="Layer的概念"><a href="#Layer的概念" class="headerlink" title="Layer的概念"></a>Layer的概念</h2><p>Spacemacs对配置本身做了抽象度较高的封装，所以，许多的功能都是通过可以配置的Layer提供给用户。这里Layer的概念，类似于Vim中的各种Plugin。用户只需要简单的配置需要启用哪些层即可，不需要对每个层进行复杂的配置，也不用因为集成各种组件让自己的配置文件变得复杂和更加难以维护。我想，这也应该是Spacemacs能吸引很多用户的原因吧。</p><p>所有可用的Layer，可以在<a href="http://spacemacs.org/layers/LAYERS.html" target="_blank" rel="noopener">这里</a>找到。</p><h2 id="Spacemacs的用户自定义配置文件"><a href="#Spacemacs的用户自定义配置文件" class="headerlink" title="Spacemacs的用户自定义配置文件"></a>Spacemacs的用户自定义配置文件</h2><p>Spacemacs虽然做了大部分的封装，隔离了Emacs配置的复杂性，也提供给用户可以自定义一些配置和Layer的机会，在使用Spacemacs的过程中，用户只需要关心一个配置文件即可，也就是在Spacemacs启动时会自动加载的<code>~/.spacemacs</code> 文件。用户的一些自定义配置，以及需要使用哪些Layer，全都在这一个文件中搞定。用Git把这个文件管理起来，就可以方便的保存和追溯自己的配置了，真是方便得不要不要的!</p><h2 id="Spacemacs上车体验"><a href="#Spacemacs上车体验" class="headerlink" title="Spacemacs上车体验"></a>Spacemacs上车体验</h2><p>Emacs安装完毕，Spacemacs也Clone好，那就让我们焊死车门上车吧。接下来介绍一些Spacemacs的上手体验，以及如何配置和打造其成为我的日常开发利器。既然要迁移到Spacemacs上开发，我的主要目标是之前NeoVim有的功能，Spacemacs上也要能满足才行。事实证明，NeoVim能有的功能，Spacemacs都能实现。</p><p>启动好Spacemacs，会出现一个比较酷炫的界面:</p><p><img src="https://xiaozhou.net/pics/spacemacs/spacemacs.png" alt></p><p>界面上除了可以更新各种包以及Spacemacs本身，也提供最近访问的文件和项目列表，方便在启动时快速打开。其实，这个home界面，也是Emacs里的一个buffer而已。在Spacemacs中还为我们提供了一个快捷键，方便我们时刻回到这个home界面: <code>SPC b h</code></p><h3 id="配置与修改Spacemacs"><a href="#配置与修改Spacemacs" class="headerlink" title="配置与修改Spacemacs"></a>配置与修改Spacemacs</h3><p>在Spacemacs里面，提供了一个直接可以打开<code>~/.spacemacs</code>文件的键位绑定，使用<code>SPC f e d</code> (先按空格键，接着按 f e d键)，即可直接在Spacemacs中打开配置文件。</p><p>在该配置文件的头部，可以看到dotspacemacs-configuration-layers部分，许多Layer再次并没有默认激活，我们可以根据自己的需要开启和激活一些Layer。</p><p>每次编辑完成之后，保存，然后通过<code>SPC f e R</code>来重载配置，或者通过<code>SPC q R</code>来重启Emacs，让修改生效。</p><h3 id="基本操作"><a href="#基本操作" class="headerlink" title="基本操作"></a>基本操作</h3><p>由于使用Evil Mode，移动光标的方式跟在Vim中一样，都是用<code>j, k, h, l</code>来实现。另外，Spacemacs通过<code>which-key</code>插件提供丰富的菜单功能，单击<code>SPC</code>键，就可以在菜单中找到Spacemacs的各种丰富的功能，后面介绍的各种功能的快捷键绑定，其实都可以在这个菜单中找到。</p><h3 id="窗口管理"><a href="#窗口管理" class="headerlink" title="窗口管理"></a>窗口管理</h3><p>类似于Vim，Spacemacs也支持窗口的纵向和横向切割，并支持光标在这些子窗口中方便的移动。</p><p><img src="https://xiaozhou.net/pics/spacemacs/spacemacs6.png" alt></p><p>常用窗口操作:</p><ul><li><code>SPC w /</code> 垂直分割窗口</li><li><code>SPC w -</code> 水平分割窗口</li><li><code>SPC N</code> 快速切换窗口。在Spacemacs中的每个窗口，都可以在窗口左下角看到窗口的编号，通过<code>SPC N</code>可以快速的根据编号切换窗口。</li><li><code>Ctl+w j</code> 移动光标到下边的窗口</li><li><code>Ctl+w k</code> 移动光标到上边的窗口</li><li><code>Ctl+w h</code> 移动光标到左边的窗口</li><li><code>Ctl+w l</code> 移动光标到右边的窗口</li><li><code>Ctl+w d</code> 关闭当前窗口</li></ul><h3 id="Buffer管理"><a href="#Buffer管理" class="headerlink" title="Buffer管理"></a>Buffer管理</h3><p>在Spacemacs中，每一个打开的文件都称为buffer，默认情况下，Spacemacs只显示当前编辑文件的buffer。我们可以通过<code>SPC b b</code>查看当前打开的buffer列表，并且通过<code>Ctl+n</code>, <code>Ctl+p</code>进行选择，然后通过Enter键切换buffer。buffer列表还支持输入补全，非常有助于提升你的效率。</p><p><img src="https://xiaozhou.net/pics/spacemacs/spacemacs4.png" alt></p><h3 id="项目管理"><a href="#项目管理" class="headerlink" title="项目管理"></a>项目管理</h3><p>Spacemacs默认使用Projectile的插件来探测我们当前所工作的项目，并允许我们模糊匹配查找在当前项目中的文件或者文本。Spacemacs中也有跟Vim类似的<code>nerdtree</code>插件，叫做<code>neotree</code>，功能和<code>nerdtree</code>相当，通过快捷键<code>SPC p t</code>即可呼出和关闭。</p><p><img src="https://xiaozhou.net/pics/spacemacs/spacemacs2.png" alt></p><p>在项目中，Spacemacs还允许我们使用<code>SPC p f</code>在项目中模糊匹配和查找当前项目中的文件。</p><h3 id="buffer内光标快速跳转"><a href="#buffer内光标快速跳转" class="headerlink" title="buffer内光标快速跳转"></a>buffer内光标快速跳转</h3><p>用过Vim的同学都知道，Vim有一个非常有名的插件，叫做<code>EasyMotion</code>，帮助你非常方便的在当前编辑的文本内进行快速跳转，Spacemacs中同样可以实现一样的效果，使用快捷键 <code>SPC jj &lt;char&gt;</code>即可，<code>&lt;char&gt;</code>也就是你需要跳转到的位置的那个字符，如图：</p><p><img src="https://xiaozhou.net/pics/spacemacs/spacemacs5.png" alt></p><h3 id="使用Magit集成Git"><a href="#使用Magit集成Git" class="headerlink" title="使用Magit集成Git"></a>使用Magit集成Git</h3><p>Git是一个当前非常流行的版本管理程序，Spacemacs当然也不会少了Git的集成。在配置文件中加入<code>git</code>的layer即可。Spacemacs内部集成的是一个叫Magit的扩展，所有跟Git相关的操作，都可以在Spacemacs中通过Magit一次性搞定。下面是一些常用的 Git命令:</p><ul><li><code>SPC g i</code> 等价于命令 <code>git init</code></li><li><code>SPC g s</code> 等价于 <code>git status</code></li><li><code>SPC g s</code>弹出层选中文件然后按 s, 等价于命令 <code>git add</code>某个文件</li><li><code>SPC g S</code>等价于 <code>git add .</code></li><li><code>SPC g c c</code> 等价于 <code>git commit</code></li><li><code>SPC g C</code> 等价于 <code>git checkout XXX</code></li><li><code>SPC g l l</code> 等价于 <code>git log</code></li></ul><p>在 commit 时，我们输入完 commit message 之后，需要按 C-c C-c 来完成 commit 操作，也可以按 C-c C-k 来取消 commit。</p><p><img src="https://xiaozhou.net/pics/spacemacs/spacemacs3.png" alt></p><h3 id="Emacs-服务器"><a href="#Emacs-服务器" class="headerlink" title="Emacs 服务器"></a>Emacs 服务器</h3><p>默认情况下，Spacemacs会在启动时启动服务器，这个服务器会在Spacemacs关闭的时候被杀掉。</p><h4 id="使用-Emacs-服务器"><a href="#使用-Emacs-服务器" class="headerlink" title="使用 Emacs 服务器"></a>使用 Emacs 服务器</h4><p>当 Emacs 服务器启动的时候，我们可以在命令行中使用 emacsclient 命令：</p><p>$ emacsclient -c 用 Emacs GUI 来打开文件 $ emacsclient -t 用命令行中 Emacs 来打开文件</p><h4 id="杀掉-Emacs-服务器"><a href="#杀掉-Emacs-服务器" class="headerlink" title="杀掉 Emacs 服务器"></a>杀掉 Emacs 服务器</h4><p>除了关闭 Spacemacs 之外，我们还可以用下面的命令来杀掉 Emacs 服务器：</p><p>$ emacsclient -e ‘(kill-emacs)’</p><h4 id="持久化-Emacs-服务器"><a href="#持久化-Emacs-服务器" class="headerlink" title="持久化 Emacs 服务器"></a>持久化 Emacs 服务器</h4><p>我们可以持久化 Emacs 服务器，在 Emacs 关闭的时候，服务器不被杀掉。只要设置 ~/.spacemacs 中 dotspacemacs-persistent-server 为 t 即可。</p><p>但这种情况下，我们只可以通过以下方式来杀掉服务器了：</p><ul><li><code>SPC q q</code> 退出 Emacs 并杀掉服务器，会对已修改的 Buffer 给出保存的提示。</li><li><code>SPC q Q</code> 同上，但会丢失所有未保存的修改。</li></ul><h3 id="Org模式"><a href="#Org模式" class="headerlink" title="Org模式"></a>Org模式</h3><p>Emacs只所以有名，还在于其鼎鼎大名的Org Mode，提到Org Mode当然需要更多的篇幅来介绍，这里就不详细表述了，<a href="https://scarletsky.github.io/2017/09/29/org-mode-in-spacemacs/" target="_blank" rel="noopener">有一篇</a>关于Org模式的文章，可以参考。</p><h3 id="一些额外的扩展"><a href="#一些额外的扩展" class="headerlink" title="一些额外的扩展"></a>一些额外的扩展</h3><p>Emacs的强大之处，还在于支持各种各样的扩展，比如在Emacs里面玩个小游戏啥的，这都不是问题:</p><p><img src="https://xiaozhou.net/pics/spacemacs/2048.png" alt></p><p>另外，通过安装一个<code>Spotify</code>的扩展，就可以在Emacs里面控制播放器Spotify了，切换歌曲，甚至是搜索歌曲并进行选择和播放，都不在话下：</p><p><img src="https://xiaozhou.net/pics/spacemacs/spotify.png" alt></p><h2 id="配置文件参考"><a href="#配置文件参考" class="headerlink" title="配置文件参考"></a>配置文件参考</h2><p>放出<a href="https://github.com/TimothyYe/mydotfiles/tree/master/spacemacs" target="_blank" rel="noopener">我的Spacemacs配置文件</a>，供大家参考。</p><h2 id="小结"><a href="#小结" class="headerlink" title="小结"></a>小结</h2><p>作为一个刚切换到Spacemacs和使用不太久的用户，Spacemacs还有很多的功能待我去发现，不过我用它来代替NeoVim和进行日常开发已经绰绰有余。Spacemacs吸引我的是丰富的扩展以及高集成度的封装，让用户不必太了解Emacs配置的复杂之处，就可以通过简单的配置实现自己想要的功能。之前使用Vim的同学，又想体验Emacs的强大，不妨可以配置自己的Spacemacs体验一下。</p>]]></content>
    
    <summary type="html">
    
      &lt;h2 id=&quot;前言&quot;&gt;&lt;a href=&quot;#前言&quot; class=&quot;headerlink&quot; title=&quot;前言&quot;&gt;&lt;/a&gt;前言&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://xiaozhou.net/from-vim-to-neovim-2016-05-21.html&quot;&gt;从Vim到NeoVim&lt;/a&gt;至今，已经三年多了，我的主力开发环境依然是iTerm2+Tmux+NeoVim。中途还试过VSCode和GoLand，作为新生代的编辑器，这两款用起来果然不错。不过，总感觉可以折腾的东西变少了一些。后来看到Emacs里面的Evil Mode，知道原来在Emacs里面也可以折腾Vim的键位绑定，何不一试？&lt;/p&gt;&lt;p&gt;在Google和查找了很多资料，还找到几份不错的Emacs配置，拿来直接修改一下就可以满足自己日常Go的开发了。不过对于我这种Elisp不太熟悉的新手，配置文件出错了得花时间调试和排错。不得不承认，这是一件稍微痛苦的事情。&lt;/p&gt;&lt;p&gt;再后来，直到我把目光转向了已经火了一段时间的Spacemacs。通过最近一段时间的尝试，我发现Spacemacs经过一波折腾和配置，能完全满足我的日常Go开发的需要，甚至有越用越顺手的感觉，罪过罪过……难道我这就要背叛Vim转向Emacs了？不对!我并没有背叛Vim，我只是想在Emacs里面用Vim而已……&lt;/p&gt;&lt;p&gt;提起Spacemacs，它并不是一个Emacs的单独发型版本，而是一份集成度和友好度更高的Emacs配置文件而已。按照官方的介绍，Spacemacs是一个由社区驱动的Emacs衍生版本，正如官网上的这句话: &lt;code&gt;The best editor is neither Emacs nor Vim, it&amp;#39;s Emacs and Vim!&lt;/code&gt; Spacemacs社区的目地仿佛是为了消除Emacs和Vim之间的战争。而在我看来，Spacemacs的出现是为了综合Emacs和Vim的长处，让更多的Vimer可以在其中体验Emacs。&lt;/p&gt;
    
    </summary>
    
      <category term="技术控" scheme="https://xiaozhou.net/categories/%E6%8A%80%E6%9C%AF%E6%8E%A7/"/>
    
    
      <category term="Vim" scheme="https://xiaozhou.net/tags/Vim/"/>
    
      <category term="NeoVim" scheme="https://xiaozhou.net/tags/NeoVim/"/>
    
      <category term="Spacemacs" scheme="https://xiaozhou.net/tags/Spacemacs/"/>
    
  </entry>
  
  <entry>
    <title>使用HomeBrew安装回滚软件到指定版本</title>
    <link href="https://xiaozhou.net/homebrew-install-software-with-specified-version-2019-06-11.html"/>
    <id>https://xiaozhou.net/homebrew-install-software-with-specified-version-2019-06-11.html</id>
    <published>2019-06-11T01:45:34.000Z</published>
    <updated>2019-06-11T02:06:20.437Z</updated>
    
    <content type="html"><![CDATA[<p>HomeBrew是Mac OS下一个必备的软件包管理神器，用它来安装软件能省去不少的麻烦，因为它能自动帮你搞定一些软件包的依赖关系。稍微麻烦的是，在HomeBrew中，当使用<code>brew upgrade</code>命令的时候，会直接更新软件到最新的版本，而本身没有提供一个可以在升级某个软件之后再回滚到某个指定版本的功能。</p><a id="more"></a><p>就拿Tmux来说，我常常会在日常工作中用到它，但是Tmux的版本更新往往比较激进，作者仿佛不太考虑和之前版本的兼容性，而带来一些breaking changes。导致在某个新版本更新之后，配置文件的一些配置项直接在新版启动的时候报错。所以，我常常在不小心升级到最新版的时候，想要回退Tmux到之前的版本。</p><p>其实办法还是有的，下面介绍的方法，不止对Tmux回滚有效，对任何软件的版本回滚都有效。这里只是拿TMux来举个例子。</p><h3 id="第一步-删除已经更新到最新版本的TMux"><a href="#第一步-删除已经更新到最新版本的TMux" class="headerlink" title="第一步: 删除已经更新到最新版本的TMux"></a>第一步: 删除已经更新到最新版本的TMux</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ brew uninstall tmux</span><br></pre></td></tr></table></figure><h3 id="第二步-安装指定版本Tmux"><a href="#第二步-安装指定版本Tmux" class="headerlink" title="第二步: 安装指定版本Tmux"></a>第二步: 安装指定版本Tmux</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ brew install tmux@2.8</span><br><span class="line">Error: No available formula with the name <span class="string">"tmux@2.8"</span></span><br></pre></td></tr></table></figure><p>这一步有时候能成功，但有时候也许并不管用，所以如果不成功，我们还需要第三步的操作</p><h3 id="第三步-从HomeBrew仓库中安装"><a href="#第三步-从HomeBrew仓库中安装" class="headerlink" title="第三步: 从HomeBrew仓库中安装"></a>第三步: 从HomeBrew仓库中安装</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ git <span class="built_in">clone</span> git@github.com:Homebrew/homebrew-core.git</span><br><span class="line">$ <span class="built_in">cd</span> homebrew-core</span><br><span class="line">$ git <span class="built_in">log</span> master -- Formula/tmux.rb</span><br></pre></td></tr></table></figure><p>这一步，我们需要先clone HomeBrew的仓库，然后从仓库中查找Tmux指定版本对应的git提交记录。找到指定版本对应的git commit hash,并复制下来。</p><h3 id="第四步-直接通过commit-hash安装指定版本的TMux"><a href="#第四步-直接通过commit-hash安装指定版本的TMux" class="headerlink" title="第四步: 直接通过commit hash安装指定版本的TMux"></a>第四步: 直接通过commit hash安装指定版本的TMux</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/&lt;COMMIT-HASH&gt;/Formula/tmux.rb</span><br></pre></td></tr></table></figure><h3 id="最后的操作"><a href="#最后的操作" class="headerlink" title="最后的操作"></a>最后的操作</h3><p>如果我们打算近期内都不更新Tmux，可以用<code>pin</code>命令，把Tmux“钉”在当前版本，防止下一次<code>brew upgrade</code>命令导致悲剧的发生：</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ brew pin tmux</span><br></pre></td></tr></table></figure><p>通过这个命令，还可以列出哪些软件是被<code>pin</code>的：</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ brew list --pinned</span><br></pre></td></tr></table></figure><p>此方法不但适用于Tmux，也适合任何HomeBrew管理的软件，通过git的commit hash，我们能方便回顾安装任何软件到任何指定版本，屡试不爽！</p>]]></content>
    
    <summary type="html">
    
      &lt;p&gt;HomeBrew是Mac OS下一个必备的软件包管理神器，用它来安装软件能省去不少的麻烦，因为它能自动帮你搞定一些软件包的依赖关系。稍微麻烦的是，在HomeBrew中，当使用&lt;code&gt;brew upgrade&lt;/code&gt;命令的时候，会直接更新软件到最新的版本，而本身没有提供一个可以在升级某个软件之后再回滚到某个指定版本的功能。&lt;/p&gt;
    
    </summary>
    
      <category term="技术控" scheme="https://xiaozhou.net/categories/%E6%8A%80%E6%9C%AF%E6%8E%A7/"/>
    
    
      <category term="HomeBrew" scheme="https://xiaozhou.net/tags/HomeBrew/"/>
    
      <category term="Tmux" scheme="https://xiaozhou.net/tags/Tmux/"/>
    
  </entry>
  
  <entry>
    <title>Redis中批量删除Key</title>
    <link href="https://xiaozhou.net/redis-batch-delete-2019-06-07.html"/>
    <id>https://xiaozhou.net/redis-batch-delete-2019-06-07.html</id>
    <published>2019-06-07T08:12:34.000Z</published>
    <updated>2019-06-10T03:52:27.911Z</updated>
    
    <content type="html"><![CDATA[<p>最近在自己的阿里云服务器上跑一个Redis容器，不小心监听了宿主机器的0.0.0.0地址，而且Redis server裸奔没密码，被嗅探到并植入了一堆辣鸡Key，网卡流量跑了接近1TB。还好是docker跑的，因为容器的隔离，宿主机器没被植入啥后门。修复的措施也比较简单，直接rm了docker容器，重新跑了一个redis，把端口修改为只监听127.0.0.1的本机地址，问题解决。</p><p>等等，容器的安全搞定了，那一堆Redis的Key怎么清理掉呢？搜索了一下，Redis本身并没有提供批量删除Key的功能。但是，我们可以用一些骚操作来实现批量Key的删除。</p><a id="more"></a><p>大致使用到的骚操作如下：</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">redis-cli --scan --pattern users:* | xargs redis-cli del</span><br></pre></td></tr></table></figure><p>如果你使用的Redis版本为4.0或者更高，还可以使用<a href="https://redis.io/commands/unlink" target="_blank" rel="noopener"><code>unlink</code></a>命令来替代<code>del</code>命令:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">redis-cli --scan --pattern users:* | xargs redis-cli unlink</span><br></pre></td></tr></table></figure><h3 id="所以，这个脚本到底实现了啥？"><a href="#所以，这个脚本到底实现了啥？" class="headerlink" title="所以，这个脚本到底实现了啥？"></a>所以，这个脚本到底实现了啥？</h3><ul><li>首先，我们使用<code>redis-cli --scan --pattern &lt;pattern&gt;</code>模糊匹配出了所有以<code>users:</code>打头的Redis Key，每个Key会输出为一行。</li><li>然后，这样的输出结果，通过管道操作交给了<code>xargs</code>命令来处理，<code>xargs</code>命令负责把多行的输出合并为一行，并传递给<code>redis-cli del</code>命令。所以最终执行的效果类似于<code>redis-cli del &lt;key1&gt; &lt;key2&gt; ...</code></li><li>如果有几千个Key符合这样的匹配，都会通过<code>xargs</code>命令，传递给<code>redis-cli del</code>一并删除。</li></ul>]]></content>
    
    <summary type="html">
    
      &lt;p&gt;最近在自己的阿里云服务器上跑一个Redis容器，不小心监听了宿主机器的0.0.0.0地址，而且Redis server裸奔没密码，被嗅探到并植入了一堆辣鸡Key，网卡流量跑了接近1TB。还好是docker跑的，因为容器的隔离，宿主机器没被植入啥后门。修复的措施也比较简单，直接rm了docker容器，重新跑了一个redis，把端口修改为只监听127.0.0.1的本机地址，问题解决。&lt;/p&gt;&lt;p&gt;等等，容器的安全搞定了，那一堆Redis的Key怎么清理掉呢？搜索了一下，Redis本身并没有提供批量删除Key的功能。但是，我们可以用一些骚操作来实现批量Key的删除。&lt;/p&gt;
    
    </summary>
    
      <category term="技术控" scheme="https://xiaozhou.net/categories/%E6%8A%80%E6%9C%AF%E6%8E%A7/"/>
    
    
      <category term="Redis" scheme="https://xiaozhou.net/tags/Redis/"/>
    
      <category term="批量删除" scheme="https://xiaozhou.net/tags/%E6%89%B9%E9%87%8F%E5%88%A0%E9%99%A4/"/>
    
  </entry>
  
  <entry>
    <title>使用Docker生成LetsEncrypt证书</title>
    <link href="https://xiaozhou.net/generate-letsencrypt-cert-via-docker-2019-03-13.html"/>
    <id>https://xiaozhou.net/generate-letsencrypt-cert-via-docker-2019-03-13.html</id>
    <published>2019-03-13T05:14:58.000Z</published>
    <updated>2019-10-16T07:12:06.435Z</updated>
    
    <content type="html"><![CDATA[<h2 id="起因"><a href="#起因" class="headerlink" title="起因"></a>起因</h2><p>自从<a href="https://xiaozhou.net/be-quick-to-enable-ssl-for-your-blog-2016-07-13.html">Blog启用SSL证书</a>以来，一直用LetsEncrypt家的免费SSL证书。最近，因为配置一些新的域名，免不了要继续申请LetsEncrypt的新证书。之前申请证书的方法，都是手动git clone在GitHub上的那个certbot项目，然后运行命令。这种方式唯一的不足，是certbot本身需要用到python环境，每次申请证书还会更新一些本机的环境，如果遇到了Linux的包冲突，还得先解决冲突才行。</p><a id="more"></a><h2 id="解决办法"><a href="#解决办法" class="headerlink" title="解决办法"></a>解决办法</h2><p>基于这样的困扰，哥想到了能不能用Docker来实现证书的申请？毕竟使用Docker的初衷，就是解决和隔离环境上的差异。结果google了一下，还真找到了这样的骚操作，顺便修改了一下脚本，实现了在Docker中运行certbot来申请证书的目的。由于是在Docker中运行，不用担心不同的服务器环境带来的差异，只需要把LetsEncrypt的目录映射到宿主机上即可。这样，新申请到的SSL证书能直接写入到宿主机的对应位置。基于Docker运行certbot，还能够做到即用即抛，每次运行申请SSL证书的容器，用完生成证书后，容器随即删掉，相当的方便。</p><p>封装了一个简单的脚本，在容器中申请证书的姿势大致如下：</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/bash</span></span><br><span class="line">docker run -it --rm --name certbot \</span><br><span class="line">  -v <span class="string">"/etc/letsencrypt:/etc/letsencrypt"</span> \</span><br><span class="line">  -v <span class="string">"/var/lib/letsencrypt:/var/lib/letsencrypt"</span> \</span><br><span class="line">  -v <span class="string">"/data/letsencrypt:/.secrets"</span> \</span><br><span class="line">  -p 80:80 \</span><br><span class="line">  -p 443:443 \</span><br><span class="line">  certbot/dns-cloudflare certonly \</span><br><span class="line">  -d <span class="variable">$1</span></span><br></pre></td></tr></table></figure><p>其中的 <code>-v</code>参数，将LetsEncrypt的目录跟宿主机关联起来，这样，每次生成的证书会保存在宿主机对应位置<code>/etc/letsencrypt/</code>中。<br><code>-p</code>端口的映射，是为了在生成证书的时候，让certbot可以验证端口。<br><code>--rm</code>参数，是为了达到用完即删除容器的效果，容器运行一次后，自从删除。</p><p>运行示例:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./cert.sh example.com</span><br></pre></td></tr></table></figure><p></p><p>创建的脚本大致如此，非常简单，用起来也非常爽。其实，SSL证书renew的时候，也可以这么干。</p><p>我把创建和renew证书的脚本，都放在了<a href="https://gist.github.com/TimothyYe/2e1f6254b3db07f689e21a05c11c5d25" target="_blank" rel="noopener">gist</a>上，供有需要的同学参考。</p>]]></content>
    
    <summary type="html">
    
      &lt;h2 id=&quot;起因&quot;&gt;&lt;a href=&quot;#起因&quot; class=&quot;headerlink&quot; title=&quot;起因&quot;&gt;&lt;/a&gt;起因&lt;/h2&gt;&lt;p&gt;自从&lt;a href=&quot;https://xiaozhou.net/be-quick-to-enable-ssl-for-your-blog-2016-07-13.html&quot;&gt;Blog启用SSL证书&lt;/a&gt;以来，一直用LetsEncrypt家的免费SSL证书。最近，因为配置一些新的域名，免不了要继续申请LetsEncrypt的新证书。之前申请证书的方法，都是手动git clone在GitHub上的那个certbot项目，然后运行命令。这种方式唯一的不足，是certbot本身需要用到python环境，每次申请证书还会更新一些本机的环境，如果遇到了Linux的包冲突，还得先解决冲突才行。&lt;/p&gt;
    
    </summary>
    
      <category term="技术控" scheme="https://xiaozhou.net/categories/%E6%8A%80%E6%9C%AF%E6%8E%A7/"/>
    
    
      <category term="SSL" scheme="https://xiaozhou.net/tags/SSL/"/>
    
      <category term="LetsEncrypt" scheme="https://xiaozhou.net/tags/LetsEncrypt/"/>
    
  </entry>
  
  <entry>
    <title>Gen8折腾记--Proxmox VE篇</title>
    <link href="https://xiaozhou.net/gen8-and-proxmox-ve-md-2019-03-12.html"/>
    <id>https://xiaozhou.net/gen8-and-proxmox-ve-md-2019-03-12.html</id>
    <published>2019-03-12T02:13:03.000Z</published>
    <updated>2019-05-17T09:37:52.086Z</updated>
    
    <content type="html"><![CDATA[<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>自从上次在<a href="https://xiaozhou.net/gen8-esxi-and-lede-md-2019-02-12.html">Gen上搭建Esxi虚拟化平台</a>过后，感觉总算是把Gen8给充分利用起来了。在虚拟化平台上使用软路由的体验也很好，唯一不足的地方，是在Esxi上不可避免的遇到了Gen8的磁盘驱动问题。在网上搜索了一下，通过更换回低版本的磁盘驱动，感觉磁盘性能仍然没能提升，就算把硬盘进行直通，从局域网拷贝高清电影的速度也只能在40MB/s左右。好吧，打算要彻底放弃Esxi平台了。</p><a id="more"></a><p>于是，哥又把折腾的目标设定为了PVE。PVE全称Proxmox Virtual Environment，是一个开源的服务器虚拟化环境Linux发行版。Proxmox VE基于Debian，使用基于Ubuntu的定制内核，包含安装程序、网页控制台和命令行工具，并且向第三方工具提供了REST API，在Affero通用公共许可证第三版下发行。</p><p>相比Esxi，Gen8安装使用PVE的兼容性更好一些，不会遇到磁盘驱动的坑。另外，PVE本身也是一个开源项目，由一个商业公司负责运营与更新。对于普通用户而言，PVE是可以免费使用的。</p><h2 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h2><p>PVE的安装过程跟Esxi类似，Gen8可以通过Remote Console来挂载镜像远程进行安装，这样省去了烧写ISO到U盘进行安装的麻烦。</p><p><img src="https://xiaozhou.net/pics/pve/1.png" alt></p><p><img src="https://xiaozhou.net/pics/pve/2.png" alt></p><p>我在Gen8内置的USB接口上接了一个16GU盘，这样可以利用这个U盘来安装PVE系统，并作为系统引导。</p><p><img src="https://xiaozhou.net/pics/pve/3.png" alt></p><p>设定系统时区</p><p><img src="https://xiaozhou.net/pics/pve/4.png" alt></p><p>跟着安装引导一步一步继续，然后开始漫长的安装过程</p><p><img src="https://xiaozhou.net/pics/pve/5.png" alt></p><p>安装完毕过后，从Remote Console中退出安装介质，然后从U盘进行重新引导:</p><p><img src="https://xiaozhou.net/pics/pve/6.png" alt></p><h2 id="使用介绍"><a href="#使用介绍" class="headerlink" title="使用介绍"></a>使用介绍</h2><p>跟Esxi一样，PVE也自带了Web的管理界面，默认端口为8006。使用安装时候设置的root账号和密码进行登录:</p><p><img src="https://xiaozhou.net/pics/pve/7.png" alt></p><p>装好PVE的第一步，当然是先安装软路由，这样就能通过软路由上网了:</p><p><img src="https://xiaozhou.net/pics/pve/8.png" alt></p><p>PVE内置支持两种虚拟化技术:基于内核的虚拟机(KVM)和基于容器的虚拟化(LXC)。LXC据说是之前OpenVZ技术的升级版，其方便的地方在于PVE内置了许多系统模板供下载。下载了这些模板之后，就可以通过创建LXC容器的方式，快速启动你想要初始化操作系统的虚拟机，不用从头安装操作系统，省时又省力。看了一下支持的LXC容器模板列表，支持的操作系统类型还是挺丰富的：</p><p><img src="https://xiaozhou.net/pics/pve/9.png" alt></p><p>目前，我创建了一个软路由，一个PT下载的虚拟机，一个Linux开发环境的虚拟机。总共折腾了3个虚拟机，用掉接近1/4的内存，后面再考虑折腾其他的虚拟机。</p><p><img src="https://xiaozhou.net/pics/pve/10.png" alt></p><p>值得一提的是，PVE也支持硬盘直通，我把其中两块物理硬盘直通给了PT下载用，并设置了局域网Samba服务，用来在其他的设备上直接播放高清视频。</p><p>最后，测试了一下从直通的硬盘拷贝高清电影，速度果然得到了飙升。</p><h2 id="安装参考"><a href="#安装参考" class="headerlink" title="安装参考"></a>安装参考</h2><p>PVE的安装并不复杂，跟Esxi类似，都有基于UI的安装向导。此次折腾，完全参考了什么值得买上的三篇教程，非常详尽，推荐给想要折腾PVE的同学阅读：</p><p><a href="https://post.smzdm.com/p/768830/" target="_blank" rel="noopener">《基于ProXmoX VE的虚拟化家庭服务器（篇一）—ProXmoX VE 安装及基础配置》</a><br><a href="https://post.smzdm.com/p/779027/" target="_blank" rel="noopener">《基于ProXmoX VE的虚拟化家庭服务器（篇二）—虚拟化软路由》</a><br><a href="https://post.smzdm.com/p/a25r8mo2/" target="_blank" rel="noopener">《基于ProXmoX VE的虚拟化家庭服务器（篇三）—黑裙6.2安装，硬盘直通》</a></p><h2 id="延伸阅读"><a href="#延伸阅读" class="headerlink" title="延伸阅读"></a>延伸阅读</h2><p><a href="https://xiaozhou.net/buy-a-new-gen8-home-server-2017-03-24.html">《Gen8入手与折腾指南》</a><br><a href="https://xiaozhou.net/gen8-esxi-and-lede-md-2019-02-12.html">《Gen8折腾记–ESXi虚拟化与软路由篇》</a></p>]]></content>
    
    <summary type="html">
    
      &lt;h2 id=&quot;前言&quot;&gt;&lt;a href=&quot;#前言&quot; class=&quot;headerlink&quot; title=&quot;前言&quot;&gt;&lt;/a&gt;前言&lt;/h2&gt;&lt;p&gt;自从上次在&lt;a href=&quot;https://xiaozhou.net/gen8-esxi-and-lede-md-2019-02-12.html&quot;&gt;Gen上搭建Esxi虚拟化平台&lt;/a&gt;过后，感觉总算是把Gen8给充分利用起来了。在虚拟化平台上使用软路由的体验也很好，唯一不足的地方，是在Esxi上不可避免的遇到了Gen8的磁盘驱动问题。在网上搜索了一下，通过更换回低版本的磁盘驱动，感觉磁盘性能仍然没能提升，就算把硬盘进行直通，从局域网拷贝高清电影的速度也只能在40MB/s左右。好吧，打算要彻底放弃Esxi平台了。&lt;/p&gt;
    
    </summary>
    
      <category term="技术控" scheme="https://xiaozhou.net/categories/%E6%8A%80%E6%9C%AF%E6%8E%A7/"/>
    
    
      <category term="Gen8" scheme="https://xiaozhou.net/tags/Gen8/"/>
    
      <category term="PVE" scheme="https://xiaozhou.net/tags/PVE/"/>
    
      <category term="LEDE" scheme="https://xiaozhou.net/tags/LEDE/"/>
    
      <category term="软路由" scheme="https://xiaozhou.net/tags/%E8%BD%AF%E8%B7%AF%E7%94%B1/"/>
    
  </entry>
  
  <entry>
    <title>Gen8折腾记--ESXi虚拟化与软路由篇</title>
    <link href="https://xiaozhou.net/gen8-esxi-and-lede-md-2019-02-12.html"/>
    <id>https://xiaozhou.net/gen8-esxi-and-lede-md-2019-02-12.html</id>
    <published>2019-02-12T08:16:32.000Z</published>
    <updated>2019-05-17T09:37:52.086Z</updated>
    
    <content type="html"><![CDATA[<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>自从2017年<a href="https://xiaozhou.net/buy-a-new-gen8-home-server-2017-03-24.html">入手Gen8</a>之后，就一直没有太多时间折腾它。这一年多以来，都是把Gen8当作一个普通的下载机来使用。不得不说，Gen8定位于家用服务器的角色，还真是稳定。从17年至今，除了偶尔遇到停电，这台Gen8一直都是7*24小时运行，从未遇到系统宕机的情况。时至18年底，哥打算继续折腾一下ESXi虚拟化，顺便把Gen8升级一下。于是有了这篇折腾文……</p><a id="more"></a><h2 id="CPU升级"><a href="#CPU升级" class="headerlink" title="CPU升级"></a>CPU升级</h2><p>Gen8原装的CPU比较弱，是赛扬的G1610T，一款2核2线程的低功耗CPU，对于一般使用而言性能足够了。这款原装CPU的优点在于发热量低，所以可以采用被动式散热。但是，如果想玩虚拟化的话，这块原装CPU就有点不足了，因为其本身不支持VT-d这类硬件直通技术。为了玩转虚拟化，升级CPU是首先需要解决的问题。</p><p>两三年前就关注过适合Gen8升级的CPU，当时入眼的当然是<a href="https://ark.intel.com/products/65728/Intel-Xeon-Processor-E3-1265L-v2-8M-Cache-2_50-GHz" target="_blank" rel="noopener">E3-1265L V2</a>这块CPU。快两年过去了，这块CPU在淘宝二手的价格依然不太平易近人。于是，相中了另外一块跟1265L差不太多的CPU: <a href="https://ark.intel.com/products/52275/Intel-Xeon-Processor-E3-1260L-8M-Cache-2_40-GHz" target="_blank" rel="noopener">E3-1260L</a>。</p><p>两款CPU的对比： <a href="https://ark.intel.com/compare/52275,65728" target="_blank" rel="noopener">https://ark.intel.com/compare/52275,65728</a></p><p>比较两款CPU的技术指标，除了制程上的差异，1260L跟1265L相比，基础频率低了0.1GHz，最大睿频低了0.2GHz，最大内存频率1333和1600。论性价比，1260L真是高了不少。另外，原装的G1610T功耗大概35W，1260L的功耗是45W。这10W的增加不会对散热造成太大负担。之前看过的几款CPU，性能虽然不错，但是功耗能达到69W，还需要考虑安装CPU风扇。综合对比了一下，还是选择1260L。嗯，就它了！</p><p>快递还是比较给力，在淘宝上淘的二手1260L在春节前如期而至。二话不说，开始拆机换CPU。</p><p>Gen8拆卸起来还是挺方便的，几乎用不上螺丝刀。取下外壳后，主板上的接线统统拔掉。主板所在的机箱下部，能像抽屉一样，一同抽出。</p><p><img src="https://xiaozhou.net/pics/esxi/cpu2.jpeg" alt></p><p>下岗前的G1610T，留照纪念一下</p><p><img src="https://xiaozhou.net/pics/esxi/cpu1.jpeg" alt></p><p>两颗CPU合影</p><p><img src="https://xiaozhou.net/pics/esxi/cpu3.jpeg" alt></p><p>换上1260L，上硅脂，还原。开机后，CPU正确被Gen8识别。CPU升级成了4核8线程，棒棒的。</p><p><img src="https://xiaozhou.net/pics/esxi/cpu4.jpeg" alt></p><h2 id="折腾ESXi虚拟化"><a href="#折腾ESXi虚拟化" class="headerlink" title="折腾ESXi虚拟化"></a>折腾ESXi虚拟化</h2><p>升级CPU的最终目的，也是为了折腾虚拟化。在VMWare官网下载为HP定制的Esxi安装镜像文件，我下载的版本是<a href="https://my.vmware.com/group/vmware/details?downloadGroup=OEM-ESXI67U1-HPE&amp;productId=742" target="_blank" rel="noopener">ESXi 6.7U1</a>需要注册一个VMWare的账号就可以下载了。另外，还可以免费申请一个License在安装后进行激活。</p><p>在Gen8的主板上，内置了一个USB插槽和一个SD卡插槽，可以充分利用一下。这次，我准备了一个16G的金士顿U盘，插在USB插槽上，用来安装ESXi的系统软件。不得不说，Gen8装系统还挺方便，不用外接显示器，通过远程终端Remote Console就可以连接和安装系统。在安装的时候，直接把下载的安装镜像远程挂载过去就行了。一切准备就绪，重新引导Gen8启动，进入安装界面：</p><p><img src="https://xiaozhou.net/pics/esxi/exsi.png" alt></p><p><img src="https://xiaozhou.net/pics/esxi/exsi2.png" alt></p><p>接下来照着安装向导，一步步进行配置和安装。安装完毕之后，重新引导系统，并设置为从主板上那个U盘启动。启动后，ESXi的界面出来了，上面还提示可以通局域网内部，通过浏览器访问ESXi的Web管理界面：</p><p><img src="https://xiaozhou.net/pics/esxi/exsi3.png" alt></p><p>打开浏览器，通过Web的方式登录ESXi控制台</p><p><img src="https://xiaozhou.net/pics/esxi/exsi4.png" alt></p><p>这样，ESXi就折腾完毕了。</p><h2 id="安装LEDE软路由"><a href="#安装LEDE软路由" class="headerlink" title="安装LEDE软路由"></a>安装LEDE软路由</h2><p>折腾软路由的目的，是因为Gen8的硬件配置必定强于一般的家用路由器。毕竟Gen8是E3的CPU，性能要强于一般路由器的ARM CPU太多。如果用它来虚拟化一个软路由进行拨号上网的话，性能绝对杠杠的。这样，之前家里的无线路由，就可以降级为一个普通的AP来使用了。</p><p>LEDE软路由的安装，网上已经有不少教程了。去KoolShare论坛下载镜像，导入到ESXi，创建虚拟机，直接挂载镜像即可启动。</p><p>进入软路由后，需要进行一些设置，并对家庭网络进行一些规划。Gen8除了自带的iLO接口，还有2个千兆网口。打算一个用来桥接光猫拨号，一个用来连接无线路由器。大致的网络结构，跟KoolShare的这张图类似，只不过PC那里换成了无线路由器：</p><p><img src="https://xiaozhou.net/pics/esxi/arch.png" alt></p><p>软路由安装成功之后，在ESXi中启动，并将其设置为开机自动启动</p><p><img src="https://xiaozhou.net/pics/esxi/exsi6.png" alt></p><p>由于在虚拟机为LEDE分配了两个网卡，在LEDE中也能发现这两个网卡。将其一个配置为LAN口，另外一个配置为WAN口进行拨号即可。</p><p>另外一个使用LEDE的理由，是国人给内置了一个应用平台，里面有许多丰富的应用可以安装。区别于一般的路由，不用担心应用装太多导致路由器存储被占满，咱们是虚拟机啊，磁盘资源充足，随便装……</p><p><img src="https://xiaozhou.net/pics/esxi/exsi5.png" alt></p><p>目前安装的一些应用列表:</p><p><img src="https://xiaozhou.net/pics/esxi/exsi7.png" alt></p><p>作为测试，看了一下4K视频，感觉速度果然比之前用路由器要快一些。</p><p><img src="https://xiaozhou.net/pics/esxi/exsi8.png" alt> <img src="https://xiaozhou.net/pics/esxi/exsi9.png" alt></p><h2 id="小结"><a href="#小结" class="headerlink" title="小结"></a>小结</h2><p>这次除了折腾软路由，另外，还把两块硬盘直通给了另一个虚拟机，用来供PT下载使用。4盘位的Gen8，还剩下一个硬盘位，等下次升级硬盘的时候，打算继续折腾黑群晖试试。</p>]]></content>
    
    <summary type="html">
    
      &lt;h2 id=&quot;前言&quot;&gt;&lt;a href=&quot;#前言&quot; class=&quot;headerlink&quot; title=&quot;前言&quot;&gt;&lt;/a&gt;前言&lt;/h2&gt;&lt;p&gt;自从2017年&lt;a href=&quot;https://xiaozhou.net/buy-a-new-gen8-home-server-2017-03-24.html&quot;&gt;入手Gen8&lt;/a&gt;之后，就一直没有太多时间折腾它。这一年多以来，都是把Gen8当作一个普通的下载机来使用。不得不说，Gen8定位于家用服务器的角色，还真是稳定。从17年至今，除了偶尔遇到停电，这台Gen8一直都是7*24小时运行，从未遇到系统宕机的情况。时至18年底，哥打算继续折腾一下ESXi虚拟化，顺便把Gen8升级一下。于是有了这篇折腾文……&lt;/p&gt;
    
    </summary>
    
      <category term="技术控" scheme="https://xiaozhou.net/categories/%E6%8A%80%E6%9C%AF%E6%8E%A7/"/>
    
    
      <category term="Gen8" scheme="https://xiaozhou.net/tags/Gen8/"/>
    
      <category term="LEDE" scheme="https://xiaozhou.net/tags/LEDE/"/>
    
      <category term="软路由" scheme="https://xiaozhou.net/tags/%E8%BD%AF%E8%B7%AF%E7%94%B1/"/>
    
      <category term="ESXi" scheme="https://xiaozhou.net/tags/ESXi/"/>
    
  </entry>
  
  <entry>
    <title>CentOS更新软件包提示cannot allocate memory错误与解决</title>
    <link href="https://xiaozhou.net/centos-yum-update-cannot-allocate-memory-2019-01-25.html"/>
    <id>https://xiaozhou.net/centos-yum-update-cannot-allocate-memory-2019-01-25.html</id>
    <published>2019-01-25T08:58:23.000Z</published>
    <updated>2019-05-17T09:37:52.072Z</updated>
    
    <content type="html"><![CDATA[<p>最近一台VPS在使用yum命令更新系统软件包的时候，出现Cannot allocate memory类似的错误，看来是内存不足了。这台VPS内存是512MB，安装了CentOS7的系统。出现类似错误，应该是系统内存不足了。有一种解决办法，就是增加磁盘交换分区，拿磁盘空间来模拟内存，这是一种牺牲速度和效率的办法，毕竟磁盘读写速度比起内存差了N条街。不过，用这种办法临时解决一些问题还是挺有用的。</p><a id="more"></a><p>VPS之前并没有加载SWAP分区，需要我们临时生成一个文件，并挂载为SWAP分区：</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">dd <span class="keyword">if</span>=/dev/zero of=/etc/swapfile bs=1024 count=500000</span><br><span class="line">mkswap /etc/swapfile</span><br><span class="line">swapon /etc/swapfile</span><br></pre></td></tr></table></figure><p>三步操作完成之后，再看一下当前SWAP分区是否被挂载正常：</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@host home]<span class="comment"># free -m</span></span><br><span class="line">              total        used        free      shared  buff/cache   available</span><br><span class="line">Mem:            502          88          13           4         400         376</span><br><span class="line">Swap:           488           0         488</span><br></pre></td></tr></table></figure><p>我们几乎增加了一个与内存容量想当的交换分区，然后再次运行yum update命令，成功更新所有系统软件包。</p><p>后面如果想关掉交换分区，还可以这么干：</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">swapoff /etc/swapfile</span><br></pre></td></tr></table></figure><p>或者直接</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">swapoff -a</span><br></pre></td></tr></table></figure>]]></content>
    
    <summary type="html">
    
      &lt;p&gt;最近一台VPS在使用yum命令更新系统软件包的时候，出现Cannot allocate memory类似的错误，看来是内存不足了。这台VPS内存是512MB，安装了CentOS7的系统。出现类似错误，应该是系统内存不足了。有一种解决办法，就是增加磁盘交换分区，拿磁盘空间来模拟内存，这是一种牺牲速度和效率的办法，毕竟磁盘读写速度比起内存差了N条街。不过，用这种办法临时解决一些问题还是挺有用的。&lt;/p&gt;
    
    </summary>
    
      <category term="技术控" scheme="https://xiaozhou.net/categories/%E6%8A%80%E6%9C%AF%E6%8E%A7/"/>
    
    
      <category term="VPS" scheme="https://xiaozhou.net/tags/VPS/"/>
    
      <category term="CentOS" scheme="https://xiaozhou.net/tags/CentOS/"/>
    
  </entry>
  
  <entry>
    <title>Bing每日壁纸API</title>
    <link href="https://xiaozhou.net/bing-daily-wallpaper-api-2018-11-30.html"/>
    <id>https://xiaozhou.net/bing-daily-wallpaper-api-2018-11-30.html</id>
    <published>2018-11-30T08:58:37.000Z</published>
    <updated>2019-05-17T09:37:52.066Z</updated>
    
    <content type="html"><![CDATA[<p>之前用Go实现了一个短网址服务<a href="https://biturl.top" target="_blank" rel="noopener">BitURL.top</a>，背景图片采用了随机展现的效果。后来想到了Bing的每日壁纸还不错，在网上搜索了一下，顺便搞了一个<a href="https://github.com/TimothyYe/bing-wallpaper" target="_blank" rel="noopener">Bing每日壁纸API</a>的开源项目。利用这个API，你也可以获取和展现Bing的每日壁纸了。</p><p>Bing每日壁纸API是一个基于RESTful的API，这里有一个已经<a href="https://bing.biturl.top" target="_blank" rel="noopener">部署好的API</a>，此API已经支持HTTPS，可以放心调用。</p><a id="more"></a><h2 id="API调用方法"><a href="#API调用方法" class="headerlink" title="API调用方法"></a>API调用方法</h2><h3 id="API"><a href="#API" class="headerlink" title="API"></a>API</h3><ul><li>API地址: <a href="https://bing.biturl.top/" target="_blank" rel="noopener">https://bing.biturl.top</a></li><li>调用方式: <code>HTTP GET</code></li></ul><h3 id="相关参数"><a href="#相关参数" class="headerlink" title="相关参数"></a>相关参数</h3><ul><li><code>resolution</code> 壁纸的分辨率. <code>1920</code> 为默认值, 你也可以将其设置为 <code>1366</code>.</li><li><code>format</code> API的调用返回格式, 值可以为 <code>json</code> 或者 <code>image</code>. <strong>如果返回格式设置为 <code>image</code>, API会直接跳转请求到对应的图片地址</strong>.</li><li><code>index</code> 壁纸的index，默认从0开始。由于Bing壁纸的图片每日更新，所以通过index值可以获取之前的图片。</li><li><code>mkt</code> Bing壁纸的地区参数，默认为 <code>zh-CN</code>, 你也可以将其设置为 <code>en-US</code>, <code>ja-JP</code>, <code>en-AU</code>, <code>en-UK</code>, <code>de-DE</code>, <code>en-NZ</code>, <code>en-CA</code>。</li></ul><h3 id="调用示例"><a href="#调用示例" class="headerlink" title="调用示例"></a>调用示例</h3><ul><li>API请求</li></ul><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">https://bing.biturl.top/?resolution=1920&amp;format=json&amp;index=0&amp;mkt=zh-CN</span><br></pre></td></tr></table></figure><ul><li>返回</li></ul><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"start_date"</span>: <span class="string">"20181118"</span>,</span><br><span class="line">  <span class="attr">"end_date"</span>: <span class="string">"20181119"</span>,</span><br><span class="line">  <span class="attr">"url"</span>: <span class="string">"https://www.bing.com/az/hprichbg/rb/NarrowsZion_ZH-CN9686302838_1920x1080.jpg"</span>,</span><br><span class="line">  <span class="attr">"copyright"</span>: <span class="string">"锡安国家公园内的维尔京河，美国犹他州 (© Justinreznick/Getty Images)"</span>,</span><br><span class="line">  <span class="attr">"copyright_link"</span>: <span class="string">"http://www.bing.com/search?q=%E9%94%A1%E5%AE%89%E5%9B%BD%E5%AE%B6%E5%85%AC%E5%9B%AD\\u0026form=hpcapt\\u0026mkt=zh-cn"</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><h3 id="CSS中设置背景图片"><a href="#CSS中设置背景图片" class="headerlink" title="CSS中设置背景图片"></a>CSS中设置背景图片</h3><p>可以使用此API直接在CSS中设置背景图片:</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">background-image: url(https://bing.biturl.top/?resolution=1920&amp;format=image&amp;index=0&amp;mkt=zh-CN);</span><br><span class="line">background-size: 100%;</span><br><span class="line">background-repeat: no-repeat;</span><br></pre></td></tr></table></figure><p><strong>背景图片示例站点</strong></p><p><a href="https://biturl.top" target="_blank" rel="noopener">https://biturl.top</a></p><p><img src="https://github.com/TimothyYe/biturl/blob/master/screenshots/1.jpg?raw=true" alt="https://github.com/TimothyYe/biturl/blob/master/screenshots/1.jpg?raw=true"></p>]]></content>
    
    <summary type="html">
    
      &lt;p&gt;之前用Go实现了一个短网址服务&lt;a href=&quot;https://biturl.top&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;BitURL.top&lt;/a&gt;，背景图片采用了随机展现的效果。后来想到了Bing的每日壁纸还不错，在网上搜索了一下，顺便搞了一个&lt;a href=&quot;https://github.com/TimothyYe/bing-wallpaper&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;Bing每日壁纸API&lt;/a&gt;的开源项目。利用这个API，你也可以获取和展现Bing的每日壁纸了。&lt;/p&gt;&lt;p&gt;Bing每日壁纸API是一个基于RESTful的API，这里有一个已经&lt;a href=&quot;https://bing.biturl.top&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;部署好的API&lt;/a&gt;，此API已经支持HTTPS，可以放心调用。&lt;/p&gt;
    
    </summary>
    
      <category term="我的拙作" scheme="https://xiaozhou.net/categories/%E6%88%91%E7%9A%84%E6%8B%99%E4%BD%9C/"/>
    
    
      <category term="Bing每日壁纸" scheme="https://xiaozhou.net/tags/Bing%E6%AF%8F%E6%97%A5%E5%A3%81%E7%BA%B8/"/>
    
      <category term="API" scheme="https://xiaozhou.net/tags/API/"/>
    
  </entry>
  
  <entry>
    <title>新网站VPSDalao上线</title>
    <link href="https://xiaozhou.net/introduction-of-vpsdalao-md-2018-11-20.html"/>
    <id>https://xiaozhou.net/introduction-of-vpsdalao-md-2018-11-20.html</id>
    <published>2018-11-20T04:28:44.000Z</published>
    <updated>2019-05-17T09:37:52.096Z</updated>
    
    <content type="html"><![CDATA[<p>2017年的时候，发现一个流弊的域名<a href="https://vpsdalao.com" target="_blank" rel="noopener">vpsdalao.com</a>竟然没被注册，于是心血来潮注册下来了。自从注册过后，这个域名就开始吃灰了，因为一直没想好要用这个域名做个啥。直到后来想到了要实现一个VPS库存监控的东东，才想起来这个域名。再后来，又拖延了半年的时间，陆陆续续实现了监控的功能，等到功能实现得差不多，却发现域名又该续费了……</p><p>2018年底，网站终于部署上线了！上线之后，还自行测试了两三个月，发现没有啥大的bug了，打算在此宣传一下……</p><a id="more"></a><p>VPS大佬(<a href="https://vpsdalao.com" target="_blank" rel="noopener">https://vpsdalao.com</a>)是一个高性价比VPS服务商的库存监控服务网站。通过后台自动侦测，实现对多家VPS服务商进行库存监控和通知。因为一些性价比不错的VPS，总是特别抢手，每次去不同网站刷库存是一件痛苦的事情，VPS大佬就是为解决这样的痛点而生的一站式库存监控解决方案。</p><p>网站是用Go实现的后端，使用Gin作为Web框架，使用docker部署。</p><p>目前<a href="https://vpsdalao.com" target="_blank" rel="noopener">VPS大佬</a>支持通过微信和Telegram两种方式进行库存补货通知:</p><ul><li><p>通过微信推送消息，订阅VPS库存监控通知，微信扫描二维码即可订阅<br><img src="https://vpsdalao.com/assets/images/qrcode.jpg" alt></p></li><li><p>通过Telegram Channel推送消息，点击关注Channel: <a href="https://t.me/vpsdalao" target="_blank" rel="noopener">https://t.me/vpsdalao</a>，即可订阅</p></li></ul><p>想了解第一手库存情况和补货通知的同学，可以选择上面的方式进行订阅。</p>]]></content>
    
    <summary type="html">
    
      &lt;p&gt;2017年的时候，发现一个流弊的域名&lt;a href=&quot;https://vpsdalao.com&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;vpsdalao.com&lt;/a&gt;竟然没被注册，于是心血来潮注册下来了。自从注册过后，这个域名就开始吃灰了，因为一直没想好要用这个域名做个啥。直到后来想到了要实现一个VPS库存监控的东东，才想起来这个域名。再后来，又拖延了半年的时间，陆陆续续实现了监控的功能，等到功能实现得差不多，却发现域名又该续费了……&lt;/p&gt;&lt;p&gt;2018年底，网站终于部署上线了！上线之后，还自行测试了两三个月，发现没有啥大的bug了，打算在此宣传一下……&lt;/p&gt;
    
    </summary>
    
      <category term="我的拙作" scheme="https://xiaozhou.net/categories/%E6%88%91%E7%9A%84%E6%8B%99%E4%BD%9C/"/>
    
    
      <category term="VPS大佬" scheme="https://xiaozhou.net/tags/VPS%E5%A4%A7%E4%BD%AC/"/>
    
      <category term="VPS库存监控" scheme="https://xiaozhou.net/tags/VPS%E5%BA%93%E5%AD%98%E7%9B%91%E6%8E%A7/"/>
    
  </entry>
  
  <entry>
    <title>程序员内功系列--常用命令行工具</title>
    <link href="https://xiaozhou.net/learn-the-command-line-tools-md-2018-10-11.html"/>
    <id>https://xiaozhou.net/learn-the-command-line-tools-md-2018-10-11.html</id>
    <published>2018-10-11T03:32:07.000Z</published>
    <updated>2019-05-17T09:37:52.099Z</updated>
    
    <content type="html"><![CDATA[<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>日常在命令行终端下工作，我们都常常和许多命令打交道。掌握许多不错的命令行工具，能极大的提升我们的日常工作和开发效率。此篇介绍Tim哥在开发中常用的一些命令行工具，希望对你也有所帮助。</p><a id="more"></a><h2 id="常用命令行工具介绍"><a href="#常用命令行工具介绍" class="headerlink" title="常用命令行工具介绍"></a>常用命令行工具介绍</h2><h3 id="autojump"><a href="#autojump" class="headerlink" title="autojump"></a>autojump</h3><p><code>autojump</code> 是一款非常方便的命令行下的目录跳转工具，它能帮你快速从目录访问的历史记录中统计出各个目录的访问频次和权重，这样，就能方便的让你在各个目录中迅速跳转了。</p><p>只要你记得之前某个访问过的目录的大概名字，配合autojump，就能快速的跳转过去，再也不用打一长串的 <code>cd</code> 命令了。使用方式如下：</p><p><img src="https://xiaozhou.net/pics/iterm/autojump.gif" alt></p><p>autojump在Mac OS下的安装也非常方便:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">brew install autojump</span><br></pre></td></tr></table></figure><p>即可使用。</p><h3 id="thefuck"><a href="#thefuck" class="headerlink" title="thefuck"></a>thefuck</h3><p><code>thefuck</code> 是一个非常有趣的命令行软件，它能自动帮你纠正敲错的命令。平时在快速输入命令的时候，难免会有一些字母输入错误，这个时候，不用担心，直接再输入一个 <code>fuck</code>，吐槽一下，<code>thefuck</code> 就能自动根据你的输入，猜测出你要输入的命令，并自动帮你纠正，方便得一bi:</p><p><img src="https://xiaozhou.net/pics/iterm/thefuck.gif" alt></p><p><code>thefuck</code> 也可以直接用 <code>homebrew</code> 进行安装：</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">brew install thefuck</span><br></pre></td></tr></table></figure><h3 id="tig"><a href="#tig" class="headerlink" title="tig"></a>tig</h3><p>Git已经成为我们平时经常用到的版本控制管理工具。通常，我们用 <code>git log</code> 命令来查看git提交的历史记录。如果你已经厌倦了 <code>git log</code> 那种千篇一律的界面，那么 <code>tig</code> 绝对是一个不可错过的命令行下查看git历史提交记录的工具:</p><p><img src="https://xiaozhou.net/pics/iterm/tig.gif" alt></p><p><code>tig</code> 的界面看起来比起 <code>git log</code> 要酷炫不少，而且使用起来也挺方便。此外，<code>tig</code> 的默认按键绑定还跟Vim比较类似，真是Vimer的福音。</p><p><code>tig</code> 在Mac OS下的安装:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">brew install tig</span><br></pre></td></tr></table></figure><h3 id="git-summary"><a href="#git-summary" class="headerlink" title="git summary"></a>git summary</h3><p>平时我们在多人合作开发一个项目的时候，想要大致了解一下每个人对这个项目提交的commit数量和大致的贡献度，那么 <code>git summary</code> 这个命令绝对能满足你的要求：</p><p><img src="https://xiaozhou.net/pics/iterm/summary.gif" alt></p><p><code>git summary</code> 通过对项目中每一个commit的统计，能大致计算出每个contributor的提交次数和贡献百分比。让你对这个项目的贡献度能一目了然。</p><p>默认git是不会带有这个命令的，需要在Mac OS下额外安装一个扩展包：</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">brew install git-extras</span><br></pre></td></tr></table></figure><h3 id="sl"><a href="#sl" class="headerlink" title="sl"></a>sl</h3><p><code>sl</code> 是一个搞怪的程序，平时我们在输入命令 <code>ls</code> 的时候，经常手误会输入成为 <code>sl</code>。而 <code>sl</code> 这个搞怪的程序，就会在你手误输入错误的时候，让一辆火车满屏疾驰而过…… 是的，它啥也不干，就是让一辆火车从你的屏幕疾驰而过…… 这种逼格满满的骚操作，一定会让你的同事都过来围观……</p><p><img src="https://xiaozhou.net/pics/iterm/sl.gif" alt></p><p><code>sl</code> 在Mac OS下的安装:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">brew install sl</span><br></pre></td></tr></table></figure><h3 id="skm"><a href="#skm" class="headerlink" title="skm"></a>skm</h3><p>SKM，全称SSH Key Manager，是一个在命令行下帮助你方便的管理和切换多个SSH key的工具。想象一下，如果你是运维人员，不同的服务器也许有不同的SSH Key来登录，又或者你是一个开发人员，有自己的SSH Key，用来开发和提交代码到自己的git仓库，或许还有公司的SSH Key，用来开发公司的项目。基于以上的情况，需要经常切换SSH Key。而用上了SKM，就方便多了，使用方法类似于 <code>nvm</code>，方便的创建，管理，切换系统当前默认SSH Key，用起来简直不要太爽！</p><p><img src="https://xiaozhou.net/pics/iterm/skm.gif" alt></p><p>对了，这个命令行工具，还是Tim哥自己开发的开源项目: <a href="https://github.com/TimothyYe/skm" target="_blank" rel="noopener">https://github.com/TimothyYe/skm</a>，欢迎贡献代码和建议。</p><p><code>skm</code> 在Mac OS下的安装:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">brew tap timothyye/tap</span><br><span class="line">brew install timothyye/tap/skm</span><br></pre></td></tr></table></figure><h3 id="ydict"><a href="#ydict" class="headerlink" title="ydict"></a>ydict</h3><p><code>ydict</code> 是一个用来在命令行方式下使用的有道词典，能在命令行下快速的帮你查询单词，不用打开浏览器，输入网址等一系列繁琐的操作。输入命令即可快速搞定!</p><p><img src="https://xiaozhou.net/pics/iterm/ydict.gif" alt></p><p>呃…… 这个工具，也是Tim哥写的开源项目，怎么样？惊喜不惊喜？</p><p>项目地址：<a href="https://github.com/TimothyYe/ydict" target="_blank" rel="noopener">https://github.com/TimothyYe/ydict</a></p><p><code>ydict</code> 在Mac OS下的安装:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">brew tap timothyye/tap</span><br><span class="line">brew install timothyye/tap/ydict</span><br></pre></td></tr></table></figure><h3 id="er"><a href="#er" class="headerlink" title="er"></a>er</h3><p><code>er</code> 也是一个命令行工具，用来在命令行下查询和换算货币汇率，看一下使用方式，就知道如何使用了：</p><p><img src="https://xiaozhou.net/pics/iterm/er.gif" alt></p><p>其实，这个工具，也是Tim哥写的开源项目。</p><p>项目地址：<a href="https://github.com/TimothyYe/exchangerate" target="_blank" rel="noopener">https://github.com/TimothyYe/exchangerate</a></p><h2 id="完结"><a href="#完结" class="headerlink" title="完结"></a>完结</h2><p>以上是我常用的几个命令行工具，希望对大家平时效率有所提升，后续也许我会加入和推荐更多工具。至此，之前挖的坑“程序员内功系列”也到此完结。</p><h2 id="相关阅读"><a href="#相关阅读" class="headerlink" title="相关阅读"></a>相关阅读</h2><ul><li><a href="https://xiaozhou.net/learn-the-command-line-preface-2017-05-12.html">程序员内功系列–序篇</a></li><li><a href="https://xiaozhou.net/learn-the-command-line-iterm-and-zsh-2017-06-23.html">程序员内功系列–iTerm与Zsh篇</a></li><li><a href="https://xiaozhou.net/learn-the-command-line-tmux-2018-04-27.html">程序员内功系列–Tmux篇</a></li><li><a href="https://xiaozhou.net/learn-the-command-line-vim-2018-08-08.html">程序员内功系列–Vim篇</a></li><li><a href="https://xiaozhou.net/learn-the-command-line-tools-md-2018-10-11.html">程序员内功系列–常用命令行工具篇</a></li></ul>]]></content>
    
    <summary type="html">
    
      &lt;h2 id=&quot;前言&quot;&gt;&lt;a href=&quot;#前言&quot; class=&quot;headerlink&quot; title=&quot;前言&quot;&gt;&lt;/a&gt;前言&lt;/h2&gt;&lt;p&gt;日常在命令行终端下工作，我们都常常和许多命令打交道。掌握许多不错的命令行工具，能极大的提升我们的日常工作和开发效率。此篇介绍Tim哥在开发中常用的一些命令行工具，希望对你也有所帮助。&lt;/p&gt;
    
    </summary>
    
      <category term="技术控" scheme="https://xiaozhou.net/categories/%E6%8A%80%E6%9C%AF%E6%8E%A7/"/>
    
    
      <category term="命令行" scheme="https://xiaozhou.net/tags/%E5%91%BD%E4%BB%A4%E8%A1%8C/"/>
    
      <category term="程序员" scheme="https://xiaozhou.net/tags/%E7%A8%8B%E5%BA%8F%E5%91%98/"/>
    
      <category term="cmd" scheme="https://xiaozhou.net/tags/cmd/"/>
    
      <category term="command line" scheme="https://xiaozhou.net/tags/command-line/"/>
    
      <category term="tools" scheme="https://xiaozhou.net/tags/tools/"/>
    
  </entry>
  
  <entry>
    <title>Lightsail VPS简单入手与评测</title>
    <link href="https://xiaozhou.net/lightsail-vps-test-2018-09-20.html"/>
    <id>https://xiaozhou.net/lightsail-vps-test-2018-09-20.html</id>
    <published>2018-09-20T06:27:30.000Z</published>
    <updated>2019-05-17T09:37:52.099Z</updated>
    
    <content type="html"><![CDATA[<h2 id="介绍"><a href="#介绍" class="headerlink" title="介绍"></a>介绍</h2><p>Lightsail是AWS旗下的轻量级VPS产品，其主要客户目标是针对Digital Ocean, Vultr, Linode等商家的产品。最近，Lightsail对旗下的产品进行了价格调整，最低配置从5刀降刀了3.5刀，价格突然变得有吸引力了。另外，网络带宽也进行了调整，新加坡和日本网络变成了直连线路。这样一来，性价比突然变得高了起来。如果你在淘宝上买个AWS的折扣码，150美元的折扣码，可以在60多RMB拿下，这就意味着，平均每个月几块钱的价格，就能薅AWS的羊毛了，你懂的。</p><p>Lightsail价格如下：</p><p><img src="https://xiaozhou.net/pics/lightsail/5.png" alt></p><p>最低配置3.5刀，能有512MB内存，1个虚拟CPU，20GB的SSD，1TB的双向流量。放个小站，或者blog都是很不错的。</p><p>用Lightsail还有个好处，就是可以绑定一个静态IP，这操作是免费的。这样，IP就算被block也不用加价换，直接删掉静态IP，重新绑定一个即可。另外，有同学实验过，通过刷静态IP，还能刷到能看Netflix的IP，相当不错。</p><a id="more"></a><h2 id="简单评测"><a href="#简单评测" class="headerlink" title="简单评测"></a>简单评测</h2><p>3.5刀的VPS第一个月还是免费的，从第二个月才开始计费。为了测试，站长创建了一台东京机房的3.5刀VPS。</p><ul><li>IP地址查询:</li></ul><p><img src="https://xiaozhou.net/pics/lightsail/1.png" alt></p><ul><li>Ping测试</li></ul><p>从VPS ping国内，速度还不错:</p><p><img src="https://xiaozhou.net/pics/lightsail/2.png" alt></p><ul><li>磁盘性能及下载测试</li></ul><p><img src="https://xiaozhou.net/pics/lightsail/3.png" alt></p><p>从测试结果来看，磁盘性能一般，不过也不算太差。由于是在东京，所以访问美国机房速度不是很快。</p><ul><li>带宽测试</li></ul><p><img src="https://xiaozhou.net/pics/lightsail/4.png" alt></p><p>上下行对等，大概能达到500Mbps.</p><ul><li>视频测试</li></ul><p><img src="https://xiaozhou.net/pics/lightsail/0.png" alt></p><p>4K还是能看的，速度不错。</p><h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>Lightsail的机器还是不错的，毕竟爸爸是大品牌AWS，值得信赖。最近价格和网络的调整更具性价比，所以，有兴趣的同学赶快入手吧。</p>]]></content>
    
    <summary type="html">
    
      &lt;h2 id=&quot;介绍&quot;&gt;&lt;a href=&quot;#介绍&quot; class=&quot;headerlink&quot; title=&quot;介绍&quot;&gt;&lt;/a&gt;介绍&lt;/h2&gt;&lt;p&gt;Lightsail是AWS旗下的轻量级VPS产品，其主要客户目标是针对Digital Ocean, Vultr, Linode等商家的产品。最近，Lightsail对旗下的产品进行了价格调整，最低配置从5刀降刀了3.5刀，价格突然变得有吸引力了。另外，网络带宽也进行了调整，新加坡和日本网络变成了直连线路。这样一来，性价比突然变得高了起来。如果你在淘宝上买个AWS的折扣码，150美元的折扣码，可以在60多RMB拿下，这就意味着，平均每个月几块钱的价格，就能薅AWS的羊毛了，你懂的。&lt;/p&gt;&lt;p&gt;Lightsail价格如下：&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://xiaozhou.net/pics/lightsail/5.png&quot; alt&gt;&lt;/p&gt;&lt;p&gt;最低配置3.5刀，能有512MB内存，1个虚拟CPU，20GB的SSD，1TB的双向流量。放个小站，或者blog都是很不错的。&lt;/p&gt;&lt;p&gt;用Lightsail还有个好处，就是可以绑定一个静态IP，这操作是免费的。这样，IP就算被block也不用加价换，直接删掉静态IP，重新绑定一个即可。另外，有同学实验过，通过刷静态IP，还能刷到能看Netflix的IP，相当不错。&lt;/p&gt;
    
    </summary>
    
      <category term="技术控" scheme="https://xiaozhou.net/categories/%E6%8A%80%E6%9C%AF%E6%8E%A7/"/>
    
    
      <category term="Lightsail" scheme="https://xiaozhou.net/tags/Lightsail/"/>
    
      <category term="VPS评测" scheme="https://xiaozhou.net/tags/VPS%E8%AF%84%E6%B5%8B/"/>
    
  </entry>
  
  <entry>
    <title>GoLand中设置gofmt与goimports</title>
    <link href="https://xiaozhou.net/goland-gofmt-and-goimports-2018-08-24.html"/>
    <id>https://xiaozhou.net/goland-gofmt-and-goimports-2018-08-24.html</id>
    <published>2018-08-23T16:30:27.000Z</published>
    <updated>2019-05-17T09:37:52.088Z</updated>
    
    <content type="html"><![CDATA[<p>最近工作上的项目开发，开始用上了GoLand，作为IDEA的全家桶套餐工具之一，用起来感觉还是非常顺手的。对比了一下NeoVim，VSCode, GoLand，感觉都有其特点，也都很不错。于是，我每天几乎是根据心情来选择到底用哪款工具作为今天开发的主力工具。既然用上了GoLand，当然少不了得装上一个Vim插件，这样三种工具都可以无缝使用Vim的按键绑定，非常方便。</p><p>跟Vim, VSCode一样，GoLand也支持在保存代码时，自动调用 <code>gofmt</code> 和 <code>goimports</code> 来自动格式化代码。但是在网上搜到的都是之前版本的GoLand配置，在最新版的GoLand中，是通过File Watchers插件来实现此功能的。</p><a id="more"></a><p>在此介绍一下GoLand中如何设置：</p><p>首先，得保证安装了一个叫做”File Watchers”的插件，并设置为启用状态：</p><p><img src="https://xiaozhou.net/pics/goland/1.png" alt></p><p>然后，直接在Tools -&gt; File Watchers中，添加如下设置：</p><p><img src="https://xiaozhou.net/pics/goland/2.png" alt></p><p>可以添加的除了 <code>go fmt</code>, <code>goimports</code> 之外，还有 <code>fometaliner</code>，用来在保存代码时，对代码作语法检查，非常方便。</p><p><img src="https://xiaozhou.net/pics/goland/3.png" alt></p><p>除此之外，还允许对每个wather的行为进行详细设置，这里就不多介绍了。</p>]]></content>
    
    <summary type="html">
    
      &lt;p&gt;最近工作上的项目开发，开始用上了GoLand，作为IDEA的全家桶套餐工具之一，用起来感觉还是非常顺手的。对比了一下NeoVim，VSCode, GoLand，感觉都有其特点，也都很不错。于是，我每天几乎是根据心情来选择到底用哪款工具作为今天开发的主力工具。既然用上了GoLand，当然少不了得装上一个Vim插件，这样三种工具都可以无缝使用Vim的按键绑定，非常方便。&lt;/p&gt;&lt;p&gt;跟Vim, VSCode一样，GoLand也支持在保存代码时，自动调用 &lt;code&gt;gofmt&lt;/code&gt; 和 &lt;code&gt;goimports&lt;/code&gt; 来自动格式化代码。但是在网上搜到的都是之前版本的GoLand配置，在最新版的GoLand中，是通过File Watchers插件来实现此功能的。&lt;/p&gt;
    
    </summary>
    
      <category term="技术控" scheme="https://xiaozhou.net/categories/%E6%8A%80%E6%9C%AF%E6%8E%A7/"/>
    
    
      <category term="GoLand" scheme="https://xiaozhou.net/tags/GoLand/"/>
    
      <category term="gofmt" scheme="https://xiaozhou.net/tags/gofmt/"/>
    
      <category term="goimports" scheme="https://xiaozhou.net/tags/goimports/"/>
    
  </entry>
  
  <entry>
    <title>程序员内功系列--Vim篇</title>
    <link href="https://xiaozhou.net/learn-the-command-line-vim-2018-08-08.html"/>
    <id>https://xiaozhou.net/learn-the-command-line-vim-2018-08-08.html</id>
    <published>2018-08-08T15:11:07.000Z</published>
    <updated>2019-05-17T09:37:52.099Z</updated>
    
    <content type="html"><![CDATA[<p>作为Vim的死忠，我使用Vim已经不知不觉有几年的时间了。现在，就算切换到其他的编辑器下撸代码(VSCode, GoLand)，也依旧会安装相应的Vim插件。如今，Vim已经作为日常编码中必不可少的工具了。作为一名Vim的老粉丝，想借下面几个问题，跟大家聊聊Vim：</p><a id="more"></a><h2 id="我还有必要学习Vim吗？"><a href="#我还有必要学习Vim吗？" class="headerlink" title="我还有必要学习Vim吗？"></a>我还有必要学习Vim吗？</h2><p>说到这里，你也许会问：如今的编辑器可以选择的范围这么广，我还到底还需要花时间学习Vim吗？StackOverflow曾经做过一个非常有趣的统计，自从有人在SF上提出一个问题：“如何退出Vim” 之后，在接下来的五年时间里，<a href="https://stackoverflow.blog/2017/05/23/stack-overflow-helping-one-million-developers-exit-vim/" target="_blank" rel="noopener">StackOverflow已经帮助上百万的程序员如何成功的退出Vim了</a>，这看似是一个非常囧的问题，不过它也体现出了会Vim的重要性。试想一下，当你在Linux服务器上配置生产环境和部署程序的时候，没有带UI界面编辑器的帮助，Vim仍然能成为你在字符界面下的好帮手和利器。另外，学一下Vim，至少不会陷入误入Vim编辑器后，不知道如何退出的窘迫处境。更何况，在你熟悉Vim常用的快捷键操作之后，能极大的提高你的文本处理效率，并且在日常的工作中，大大减少对鼠标的依赖。因此，学习Vim还是很有必要的。</p><h2 id="Vim难学吗？"><a href="#Vim难学吗？" class="headerlink" title="Vim难学吗？"></a>Vim难学吗？</h2><p>比起普通的编辑器，Vim的入门是有一定难度的，要不然，也不会有那么多的程序员被卡在如何退出Vim这个很囧的问题上了。网上有这样的一张图，介绍了Vim和其他编辑器对比的学习曲线：</p><p><img src="https://xiaozhou.net/pics/vim/1.jpg" alt></p><p>基于Vim入门的一定难度，让不少同学望而生畏。学习Vim确实需要一些时间上的投入，比如需要记住一些常用的快捷键，了解Vim中的几种模式，以及如何切换，等等。刚开始的学习是痛苦的，不过一旦突破了瓶颈，就畅快多了。</p><h2 id="如何开始入坑Vim？"><a href="#如何开始入坑Vim？" class="headerlink" title="如何开始入坑Vim？"></a>如何开始入坑Vim？</h2><p>在这里，得推荐一下CoolShell的这篇<a href="https://coolshell.cn/articles/5426.html" target="_blank" rel="noopener">《简明Vim练级攻略》</a>，咬牙学完这篇过后，大致，你就能入门Vim了。</p><p>其实，安装好Vim之后，还顺带会自动安装一个工具，叫做 <code>vimtutor</code>的工具，在命令行键入后可以直接运行。这也是官方自带的一个非常不错的入门工具。</p><p>另外，有一个国外的网站，提供Vim入门的互动式教程，非常不错: <a href="https://www.openvim.com/" target="_blank" rel="noopener">https://www.openvim.com/</a></p><p>熟悉一段时间后，极力推荐大家看看这本通俗易懂的<a href="https://book.douban.com/subject/25869486/" target="_blank" rel="noopener">《Pratical Vim》(中文译名：Vim实用技巧)</a>能对你理解Vim和提高技能，有非常大的帮助。</p><h2 id="如何个性化配置自己的Vim"><a href="#如何个性化配置自己的Vim" class="headerlink" title="如何个性化配置自己的Vim?"></a>如何个性化配置自己的Vim?</h2><p>在入门之后，或许你早已对Vim那个默认的普通界面无法忍受了。Vim之所以功能强大，还因为有许多令人眼花缭乱的插件供你选择和配置。也许，100个Vimer，就能有100种针对自己的喜好的Vim配置。此时，你需要的是一个真正能满足自己需求和喜好的Vim配置了。</p><p>一个不错的Vim配置文件，都是随着自己的喜好，不断调整和完善的，Vim的配置文件正好也是一个文本类型格式的文件，因此，建议你用Git管理起来，方便自己不断优化和回溯。</p><p>万事开头难，不过不要慌，问题不大！第一个Vim配置文件的建立，可以参考他人的配置，然后自己在别人的基础上修改。我的Vim配置文件，放在<a href="https://github.com/TimothyYe/mydotfiles" target="_blank" rel="noopener">这里</a>，其中包含了Vim的配置和NeoVim的配置，两个Vim的配置文件几乎是兼容的。</p><p>经过一番折腾和配置，也许你就能告别千篇一律的Vim默认界面了，折腾出自己风格的Vim来：</p><p><img src="https://xiaozhou.net/pics/vim/2.png" alt></p><h2 id="Vim的常用插件有哪些推荐？"><a href="#Vim的常用插件有哪些推荐？" class="headerlink" title="Vim的常用插件有哪些推荐？"></a>Vim的常用插件有哪些推荐？</h2><p>列出我自己用到的部分Vim插件，供参考：</p><blockquote><ul><li><a href="https://github.com/junegunn/vim-plug" target="_blank" rel="noopener">vim-plug</a> Vim的插件管理器，支持并发安装和更新，了解下？</li><li><a href="http://github.com/mileszs/ack.vim" target="_blank" rel="noopener">Ack</a> 全文搜索插件，可以在当前打开的项目中进行源码的全文搜索，并可以在搜索结果中方便的切换和打开源码文件，十分方便。</li><li><a href="http://github.com/scrooloose/nerdtree" target="_blank" rel="noopener">NERDTree</a> Vim中的文件管理器，方便编辑文件，创建目录，删除和修改文件等等……</li><li><a href="http://github.com/scrooloose/nerdcommenter" target="_blank" rel="noopener">NERDTreeCommenter</a> 方便的用来注释代码的插件</li><li><a href="http://github.com/majutsushi/tagbar" target="_blank" rel="noopener">TagBar</a> 查看当前代码文件中的变量和函数列表的插件，可以切换和跳转到代码中对应的变量和函数的位置</li><li><a href="http://github.com/kien/ctrlp.vim" target="_blank" rel="noopener">CtrlP</a> 不可缺少的快速跳转插件，它可以快速的帮助我们找到项目中的文件。在vim normal模式下，按下ctrl+p，然后输入你要寻找的文件就行了。</li><li><a href="http://github.com/jiangmiao/auto-pairs" target="_blank" rel="noopener">AutoPairs</a> 自动补全括号的插件，包括小括号，中括号，以及花括号，可以提升编码效率</li><li><a href="http://github.com/tpope/vim-surround" target="_blank" rel="noopener">Surround</a> 快速给词加环绕符号,例如单引号/双引号/括号/成对标签等的插件</li><li><a href="http://github.com/bling/vim-airline" target="_blank" rel="noopener">Vim-Airline</a> Vim状态栏插件，包括显示行号，列号，文件类型，文件名，以及Git状态</li><li><a href="http://github.com/Lokaltog/vim-easymotion" target="_blank" rel="noopener">EasyMotion</a> 在当前文件中快速移动光标到指定查找位置的插件，十分方便和高效</li><li><a href="http://github.com/Shougo/deoplete.nvim" target="_blank" rel="noopener">deoplete</a> 自动补全插件，写代码必备，有了这个插件，就有了IDE的感觉</li><li><a href="http://github.com/mhinz/vim-startify" target="_blank" rel="noopener">Vim-Startify</a> Vim启动首屏自定义插件，让你的Vim启动后显示别具一格的首屏样式</li><li><a href="http://github.com/nathanaelkane/vim-indent-guides" target="_blank" rel="noopener">Vim-Indent-Guides</a> 显示代码对齐的引导条</li><li><a href="http://github.com/yonchu/accelerated-smooth-scroll" target="_blank" rel="noopener">Accelerated-Smooth-Scroll</a> 顾名思义，让Ctrl+F,Ctrl+B的滚屏来得更顺滑一些……</li><li><a href="http://github.com/ianva/vim-youdao-translater" target="_blank" rel="noopener">YouDao-Translater</a> Vim中的有道翻译插件</li><li><a href="http://github.com/uguu-org/vim-matrix-screensaver" target="_blank" rel="noopener">Matrix-ScreenSaver</a> Vim中的黑客帝国屏幕保护插件，很酷很炫</li><li><a href="http://github.com/fatih/vim-go" target="_blank" rel="noopener">vim-go</a> 搞Go开发必备的插件，集成了很多Go的相关功能</li></ul></blockquote><h2 id="Vim学习的一点建议"><a href="#Vim学习的一点建议" class="headerlink" title="Vim学习的一点建议"></a>Vim学习的一点建议</h2><p>由于Vim的学习曲线和上手难度，决定了Vim的学习不可能一蹴而就，学习vim在开始时是痛苦的，需要时间和不断的积累。那些期望三天就熟悉和上手Vim的想法是不太切合实际的。或许刚开始苦于各种快捷键的记忆，发觉效率还不如普通编辑器，后续逐渐熟悉之后，就会有速度和效率上的突破了。</p><h2 id="一点福利"><a href="#一点福利" class="headerlink" title="一点福利"></a>一点福利</h2><p>最后，在七牛云上传了一点福利，留给学习Vim的同学们:<a href="http://ox2lpkfis.bkt.clouddn.com/vim_cheat_sheet_for_programmers.zip" target="_blank" rel="noopener">《Vim Cheat Sheet For Programmers》</a>，可以打印出来帖在电脑旁边，方便随时查阅常用Vim快捷键，也可以设置为桌面背景。</p><h2 id="相关阅读"><a href="#相关阅读" class="headerlink" title="相关阅读"></a>相关阅读</h2><ul><li><a href="https://xiaozhou.net/learn-the-command-line-preface-2017-05-12.html">程序员内功系列–序篇</a></li><li><a href="https://xiaozhou.net/learn-the-command-line-iterm-and-zsh-2017-06-23.html">程序员内功系列–iTerm与Zsh篇</a></li><li><a href="https://xiaozhou.net/learn-the-command-line-tmux-2018-04-27.html">程序员内功系列–Tmux篇</a></li><li><a href="https://xiaozhou.net/learn-the-command-line-vim-2018-08-08.html">程序员内功系列–Vim篇</a></li><li><p><a href="https://xiaozhou.net/learn-the-command-line-tools-md-2018-10-11.html">程序员内功系列–常用命令行工具篇</a></p></li><li><p><a href="https://xiaozhou.net/from-vim-to-neovim-2016-05-21.html">从Vim到NeoVim</a></p></li><li><a href="https://xiaozhou.net/build-your-go-ide-2015-07-18.html">打造Go的IDE</a></li><li><a href="https://xiaozhou.net/setup-golang-environment-for-vim-2014-01-25.html">为Vim配置Golang开发环境</a></li><li><a href="https://xiaozhou.net/experience_of_vim-2013-05-25.html">Vim学习与体验</a></li><li><a href="https://xiaozhou.net/something_about_vim-2013-06-07.html">Vim学习资料汇总</a></li><li><a href="https://xiaozhou.net/install_taglist_for_vim-2013-05-26.html">Vim中配置Taglist插件</a></li><li><a href="https://xiaozhou.net/configure-vim-project-plugin-2014-03-17.html">Vim的项目管理插件: Project</a></li></ul>]]></content>
    
    <summary type="html">
    
      &lt;p&gt;作为Vim的死忠，我使用Vim已经不知不觉有几年的时间了。现在，就算切换到其他的编辑器下撸代码(VSCode, GoLand)，也依旧会安装相应的Vim插件。如今，Vim已经作为日常编码中必不可少的工具了。作为一名Vim的老粉丝，想借下面几个问题，跟大家聊聊Vim：&lt;/p&gt;
    
    </summary>
    
      <category term="技术控" scheme="https://xiaozhou.net/categories/%E6%8A%80%E6%9C%AF%E6%8E%A7/"/>
    
    
      <category term="命令行" scheme="https://xiaozhou.net/tags/%E5%91%BD%E4%BB%A4%E8%A1%8C/"/>
    
      <category term="程序员" scheme="https://xiaozhou.net/tags/%E7%A8%8B%E5%BA%8F%E5%91%98/"/>
    
      <category term="Vim" scheme="https://xiaozhou.net/tags/Vim/"/>
    
      <category term="cmd" scheme="https://xiaozhou.net/tags/cmd/"/>
    
      <category term="command line" scheme="https://xiaozhou.net/tags/command-line/"/>
    
  </entry>
  
  <entry>
    <title>搬瓦工美西CN2 GIA线路VPS入手评测</title>
    <link href="https://xiaozhou.net/bandwagonhost-cn2-gia-vps-test-2018-05-17.html"/>
    <id>https://xiaozhou.net/bandwagonhost-cn2-gia-vps-test-2018-05-17.html</id>
    <published>2018-05-17T06:12:43.000Z</published>
    <updated>2019-05-17T09:37:52.066Z</updated>
    
    <content type="html"><![CDATA[<h2 id="最近更新"><a href="#最近更新" class="headerlink" title="最近更新"></a>最近更新</h2><p>搬瓦工的系列产品最近比较火，很多都处于缺货状态。实时订阅搬瓦工VPS库存状态，可访问<a href="https://vpsdalao.com/?provider=Bandwagon" target="_blank" rel="noopener">VPS大佬</a>，通过扫描微信二维码和Telegram频道订阅VPS实时库存推送信息，第一时间了解VPS库存补货状态。</p><h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>之前看过文章<a href="https://xiaozhou.net/bandwagon-cn2-vps-test-2017-08-20.html">《搬瓦工美西CN2线路VPS入手评测》</a> 和 <a href="https://xiaozhou.net/introduction-of-cn2-and-cn2-vps-2017-12-11.html">《CN2的那些事-CN2线路与VPS服务商介绍》</a> 的同学一定不会陌生，如今，CN2线路已经成为选择VPS的一个重要考虑条件。之前的搬瓦工全系列产品，都是CN2 GT线路，终于在前不久，推出了CN2 GIA线路的BETA套餐。当然，作为VPS狂热爱好者的站长，也毫不犹豫的购入了BETA产品试用，中途搬瓦工还进行了一次线路的迁移和调整，估计也是为最终推出GIA系列产品做准备。我主要上网的方式都是电信线路，感觉这一两个月的BETA版GIA体验结果，如果用一个字总结，那就是：<strong>稳！</strong>如果用四个字总结，那就是：<strong>稳到不行！</strong></p><a id="more"></a><p>如今，搬瓦工的GIA线路产品终于正式上线了，虽然已经有了之前BETA版本的产品(现在已下线)，还是又忍不住购入了这款极具性价比的季付产品：</p><p><strong>SPECIAL 20G KVM PROMO V3 - LOS ANGELES - CN2 GIA</strong><br>SSD: 20 GB RAID-10<br>RAM: 1024 MB<br>CPU: 2x Intel Xeon<br>Transfer: 1000 GB/mo<br>Link speed: 1 Gigabit<br>季付19.99刀 <a href="https://bwh88.net/aff.php?aff=18390&amp;pid=72" target="_blank" rel="noopener">点此购买</a></p><p>今天就给大家评测一下这款新推出不久的<a href="https://bandwagonhost.com/aff.php?aff=18390" target="_blank" rel="noopener">搬瓦工(Bandwagon)</a>美西GIA CN2线路的VPS。</p><h2 id="CN2线路的类型与区别"><a href="#CN2线路的类型与区别" class="headerlink" title="CN2线路的类型与区别"></a>CN2线路的类型与区别</h2><p>在开始之前，不得不再提一下CN2线路的两种类型：</p><ul><li>CN2 GT: CN2里属于Global Transit的产品(又名GIS-Global Internet Service)，在CN2里等级低，省级/出国节点为202.97开头，国际骨干节点有2～4个59.43开头的CN2节点。在出国线路上拥堵程度一般，相对于163骨干网的稍强，相比CN2 GIA，性价比也较高。</li><li>CN2 GIA: CN2里属于Global Internet Access的产品，等级最高，省级/出国/国际骨干节点都以59.43开头，全程没有202.97开头的节点。在出国线路上表现最好，很少拥堵，理论上速度最快最稳定，当然，价格也相对CN2 GT偏高。</li></ul><p>有兴趣的同学，可以移步参考：<a href="https://xiaozhou.net/introduction-of-cn2-and-cn2-vps-2017-12-11.html">《CN2的那些事-CN2线路与VPS服务商介绍》</a></p><h2 id="入手与测试"><a href="#入手与测试" class="headerlink" title="入手与测试"></a>入手与测试</h2><p><a href="https://bwh88.net/aff.php?aff=18390&amp;pid=72" target="_blank" rel="noopener">产品购买链接</a></p><p>产品优惠码:<br><strong>BWH26FXH3HIQ</strong> (折扣幅度: 6.25%) <a href="https://bwh88.net/aff.php?aff=18390&amp;pid=72" target="_blank" rel="noopener">复制后可直接点击访问购买</a><br><strong>BWH25AQH2CMQ</strong> (折扣幅度: 5.97%) <a href="https://bwh88.net/aff.php?aff=18390&amp;pid=72" target="_blank" rel="noopener">复制后可直接点击访问购买</a><br><strong>IREALLYREADTHETERMS8</strong> (折扣幅度: 5.5%) <a href="https://bwh88.net/aff.php?aff=18390&amp;pid=72" target="_blank" rel="noopener">复制后可直接点击访问购买</a></p><p>使用优惠码打折，原价月付19.99刀，打折后季付18.74刀，平均下来一个月6刀多一点，就可以用上CN2的GIA线路，相比同类竞争产品，价格还是非常有竞争力和性价比的。</p><h3 id="路由节点查询"><a href="#路由节点查询" class="headerlink" title="路由节点查询"></a>路由节点查询</h3><p>入手后，按照惯例，去ipip.net查一下路由，这次，三网路由都统统查一遍。</p><ul><li>首先是电信，以成都电信作为路由测试点：</li></ul><p><a href="https://xiaozhou.net/pics/gia/gia2.png"><img src="https://xiaozhou.net/pics/gia/gia2.png" width="800"></a></p><p>查看地图，是从上海出口，直连无绕路：</p><p><a href="https://xiaozhou.net/pics/gia/gia3.png"><img src="https://xiaozhou.net/pics/gia/gia3.png" width="800"></a></p><ul><li>接着是联通，以重庆联通作为路由测试点：</li></ul><p><a href="https://xiaozhou.net/pics/gia/gia4.png"><img src="https://xiaozhou.net/pics/gia/gia4.png" width="800"></a></p><p>查看地图，广东出口，直连无绕路：</p><p><a href="https://xiaozhou.net/pics/gia/gia5.png"><img src="https://xiaozhou.net/pics/gia/gia5.png" width="800"></a></p><ul><li>最后是移动，以四川德阳移动作为路由测试点：</li></ul><p><a href="https://xiaozhou.net/pics/gia/gia6.png"><img src="https://xiaozhou.net/pics/gia/gia6.png" width="800"></a></p><p>路由里面发现，有一个节点仿佛走了163，其他均为CN2。</p><p>查看地图，上海出口，直连无绕路：</p><p><a href="https://xiaozhou.net/pics/gia/gia7.png"><img src="https://xiaozhou.net/pics/gia/gia7.png" width="800"></a></p><h3 id="PING测试"><a href="#PING测试" class="headerlink" title="PING测试"></a>PING测试</h3><p>一般的美帝机房VPS，ping值大概在200ms-300ms之间，GIA跟GT的CN2的速度类似，基本在170ms左右，下图是国内各地区的ping值：</p><p><a href="https://xiaozhou.net/pics/gia/gia10.png"><img src="https://xiaozhou.net/pics/gia/gia10.png"></a></p><h3 id="带宽测试"><a href="#带宽测试" class="headerlink" title="带宽测试"></a>带宽测试</h3><p><a href="https://xiaozhou.net/pics/gia/gia8.png"><img src="https://xiaozhou.net/pics/gia/gia8.png"></a></p><p>确定为G口带宽。</p><h3 id="磁盘I-O速度与国外网络测试"><a href="#磁盘I-O速度与国外网络测试" class="headerlink" title="磁盘I/O速度与国外网络测试"></a>磁盘I/O速度与国外网络测试</h3><p><a href="https://xiaozhou.net/pics/gia/gia9.png"><img src="https://xiaozhou.net/pics/gia/gia9.png"></a></p><h3 id="开启BBR"><a href="#开启BBR" class="headerlink" title="开启BBR"></a>开启BBR</h3><p>为了让CN2的这款搬瓦工网速更加理想，可以尝试开启BBR。BBR是Google推出的网络拥堵算法，对于网络加速有非常理想的效果。关于BBR的开启和配置，这里不再多说了，看Tim哥之前的文章吧：<a href="https://xiaozhou.net/enable-bbr-for-vps-2017-06-10.html">《为VPS开启BBR拥塞控制算法》</a></p><p>值得提醒的一点，搬瓦工的VPS预装系统里面，有的模板已经自带了BBR了，也就是说，你也不需要额外的配置了，选择这种带BBR的预装系统，就能直接启用BBR加速了，这还算是非常贴心的一点：</p><p><a href="https://xiaozhou.net/pics/bwg/4.png"><img src="https://xiaozhou.net/pics/bwg/4.png" width="800"></a></p><h3 id="视频测试"><a href="#视频测试" class="headerlink" title="视频测试"></a>视频测试</h3><p>测试线路为：成都电信</p><p><a href="https://xiaozhou.net/pics/gia/gia.png"><img src="https://xiaozhou.net/pics/gia/gia.png"></a></p><p>结论：4K不卡，丢帧为0，线路还是很稳妥的。</p><h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>搬瓦工的CN2 GIA系列，相比起之前的CN2 GT系列，属于更加高端的产品，线路更加稳定，并且双向都是直连优化线路。虽然定位更加高端，但是价格缺没有贵多少，对CN2线路质量有更高要求的同学可以考虑入手。毕竟最低配19.99刀的季付价格，比起普通CN2线路的产品，也没贵多少。有需要购买的同学，可以通过上面的推荐链接购买，搬瓦工会给博主返回一定的推荐奖励，在此感谢！</p><h2 id="相关阅读"><a href="#相关阅读" class="headerlink" title="相关阅读"></a>相关阅读</h2><p><a href="https://xiaozhou.net/new-bandwagonhost-cn2-gia-vps-online-2018-05-15.html">搬瓦工美西CN2 GIA VPS正式上线</a><br><a href="https://xiaozhou.net/introduction-of-cn2-and-cn2-vps-2017-12-11.html">CN2的那些事-CN2线路与VPS服务商介绍</a><br><a href="https://xiaozhou.net/bandwagon-cn2-vps-test-2017-08-20.html">搬瓦工美西CN2线路VPS入手评测</a></p>]]></content>
    
    <summary type="html">
    
      &lt;h2 id=&quot;最近更新&quot;&gt;&lt;a href=&quot;#最近更新&quot; class=&quot;headerlink&quot; title=&quot;最近更新&quot;&gt;&lt;/a&gt;最近更新&lt;/h2&gt;&lt;p&gt;搬瓦工的系列产品最近比较火，很多都处于缺货状态。实时订阅搬瓦工VPS库存状态，可访问&lt;a href=&quot;https://vpsdalao.com/?provider=Bandwagon&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;VPS大佬&lt;/a&gt;，通过扫描微信二维码和Telegram频道订阅VPS实时库存推送信息，第一时间了解VPS库存补货状态。&lt;/p&gt;&lt;h2 id=&quot;前言&quot;&gt;&lt;a href=&quot;#前言&quot; class=&quot;headerlink&quot; title=&quot;前言&quot;&gt;&lt;/a&gt;前言&lt;/h2&gt;&lt;p&gt;之前看过文章&lt;a href=&quot;https://xiaozhou.net/bandwagon-cn2-vps-test-2017-08-20.html&quot;&gt;《搬瓦工美西CN2线路VPS入手评测》&lt;/a&gt; 和 &lt;a href=&quot;https://xiaozhou.net/introduction-of-cn2-and-cn2-vps-2017-12-11.html&quot;&gt;《CN2的那些事-CN2线路与VPS服务商介绍》&lt;/a&gt; 的同学一定不会陌生，如今，CN2线路已经成为选择VPS的一个重要考虑条件。之前的搬瓦工全系列产品，都是CN2 GT线路，终于在前不久，推出了CN2 GIA线路的BETA套餐。当然，作为VPS狂热爱好者的站长，也毫不犹豫的购入了BETA产品试用，中途搬瓦工还进行了一次线路的迁移和调整，估计也是为最终推出GIA系列产品做准备。我主要上网的方式都是电信线路，感觉这一两个月的BETA版GIA体验结果，如果用一个字总结，那就是：&lt;strong&gt;稳！&lt;/strong&gt;如果用四个字总结，那就是：&lt;strong&gt;稳到不行！&lt;/strong&gt;&lt;/p&gt;
    
    </summary>
    
      <category term="技术控" scheme="https://xiaozhou.net/categories/%E6%8A%80%E6%9C%AF%E6%8E%A7/"/>
    
    
      <category term="搬瓦工" scheme="https://xiaozhou.net/tags/%E6%90%AC%E7%93%A6%E5%B7%A5/"/>
    
      <category term="bandwagon" scheme="https://xiaozhou.net/tags/bandwagon/"/>
    
      <category term="VPS" scheme="https://xiaozhou.net/tags/VPS/"/>
    
      <category term="CN2" scheme="https://xiaozhou.net/tags/CN2/"/>
    
      <category term="入手" scheme="https://xiaozhou.net/tags/%E5%85%A5%E6%89%8B/"/>
    
      <category term="评测" scheme="https://xiaozhou.net/tags/%E8%AF%84%E6%B5%8B/"/>
    
      <category term="GIA" scheme="https://xiaozhou.net/tags/GIA/"/>
    
  </entry>
  
  <entry>
    <title>搬瓦工美西CN2 GIA VPS正式上线</title>
    <link href="https://xiaozhou.net/new-bandwagonhost-cn2-gia-vps-online-2018-05-15.html"/>
    <id>https://xiaozhou.net/new-bandwagonhost-cn2-gia-vps-online-2018-05-15.html</id>
    <published>2018-05-15T06:13:04.000Z</published>
    <updated>2019-05-17T09:37:52.107Z</updated>
    
    <content type="html"><![CDATA[<h2 id="最近更新记录"><a href="#最近更新记录" class="headerlink" title="最近更新记录"></a>最近更新记录</h2><p><strong>2019.03.18 搬瓦工的系列产品最近比较火，很多都处于缺货状态。实时订阅搬瓦工VPS库存状态，可访问<a href="https://vpsdalao.com/?provider=Bandwagon" target="_blank" rel="noopener">VPS大佬</a>，通过扫描微信二维码和Telegram频道订阅VPS实时库存推送信息，第一时间了解VPS库存补货状态。</strong><br><strong>2018.08.01 季付19.99刀缺货已久，已经重新补货，想下手的同学可以抓紧时间了</strong></p><p>用过搬瓦工VPS的同学都知道，这家服务商历经多年VPS爱好者的洗礼，已经成长为一家老牌VPS服务商，并有一大帮国内的粉丝玩家。搬瓦工旗下的CN2 VPS系列，也是一如既往的火爆，当初所销售的全系列产品，都是CN2 GT线路，终于在前不久，推出了CN2 GIA线路的BETA套餐。经过两三个月的线路调试和试运营，今天搬瓦工终于推出了自家CN2 GIA线路的系列套餐，而且价格也比较诱人，购买时，使用循环折扣优惠码 <code>BWH1ZBPVK</code> 获得终生6%循环优惠。下面，我们分别来看一下：</p><a id="more"></a><p><strong>此款极具性价比</strong><br>SPECIAL 20G KVM PROMO V3 - LOS ANGELES - CN2 GIA<br>SSD: 20 GB RAID-10<br>RAM: 1024 MB<br>CPU: 2x Intel Xeon<br>Transfer: 1000 GB/mo<br>Link speed: 1 Gigabit<br><strong>季付19.99刀</strong><br><a href="https://bwh88.net/aff.php?aff=18390&amp;pid=72" target="_blank" rel="noopener">点此购买</a></p><p>SPECIAL 40G KVM PROMO V3 - LOS ANGELES - CN2 GIA<br>SSD: 40 GB RAID-10<br>RAM: 2048 MB<br>CPU: 3x Intel Xeon<br>Transfer: 2000 GB/mo<br>Link speed: 1 Gigabit<br><strong>季付39.99刀</strong><br><a href="https://bwh88.net/aff.php?aff=18390&amp;pid=73" target="_blank" rel="noopener">点此购买</a></p><p>SPECIAL 80G KVM PROMO V3 - LOS ANGELES - CN2 GIA<br>SSD: 80 GB RAID-10<br>RAM: 4096 MB<br>CPU: 4x Intel Xeon<br>Transfer: 3000 GB/mo<br>Link speed: 1 Gigabit<br><strong>月付27.99刀</strong><br><a href="https://bwh88.net/aff.php?aff=18390&amp;pid=74" target="_blank" rel="noopener">点此购买</a></p><p>SPECIAL 160G KVM PROMO V3 - LOS ANGELES - CN2 GIA<br>SSD: 160 GB RAID-10<br>RAM: 8 GB<br>CPU: 6x Intel Xeon<br>Transfer: 5000 GB/mo<br>Link speed: 1 Gigabit<br><strong>月付59.99刀</strong> <a href="https://bwh88.net/aff.php?aff=18390&amp;pid=75" target="_blank" rel="noopener">点此购买</a></p><p>SPECIAL 320G KVM PROMO V3 - LOS ANGELES - CN2 GIA<br>SSD: 320 GB RAID-10<br>RAM: 16 GB<br>CPU: 8x Intel Xeon<br>Transfer: 8000 GB/mo<br>Link speed: 1 Gigabit<br><strong>月付109.99刀</strong><br><a href="https://bwh88.net/aff.php?aff=18390&amp;pid=75" target="_blank" rel="noopener">点此购买</a></p><h2 id="相关阅读"><a href="#相关阅读" class="headerlink" title="相关阅读"></a>相关阅读</h2><p><a href="https://xiaozhou.net/bandwagonhost-cn2-gia-vps-test-2018-05-17.html">搬瓦工美西CN2 GIA线路VPS入手评测</a><br><a href="https://xiaozhou.net/bandwagon-cn2-vps-test-2017-08-20.html">搬瓦工美西CN2线路VPS入手评测</a><br><a href="https://xiaozhou.net/introduction-of-cn2-and-cn2-vps-2017-12-11.html">CN2的那些事-CN2线路与VPS服务商介绍</a></p>]]></content>
    
    <summary type="html">
    
      &lt;h2 id=&quot;最近更新记录&quot;&gt;&lt;a href=&quot;#最近更新记录&quot; class=&quot;headerlink&quot; title=&quot;最近更新记录&quot;&gt;&lt;/a&gt;最近更新记录&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;2019.03.18 搬瓦工的系列产品最近比较火，很多都处于缺货状态。实时订阅搬瓦工VPS库存状态，可访问&lt;a href=&quot;https://vpsdalao.com/?provider=Bandwagon&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;VPS大佬&lt;/a&gt;，通过扫描微信二维码和Telegram频道订阅VPS实时库存推送信息，第一时间了解VPS库存补货状态。&lt;/strong&gt;&lt;br&gt;&lt;strong&gt;2018.08.01 季付19.99刀缺货已久，已经重新补货，想下手的同学可以抓紧时间了&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;用过搬瓦工VPS的同学都知道，这家服务商历经多年VPS爱好者的洗礼，已经成长为一家老牌VPS服务商，并有一大帮国内的粉丝玩家。搬瓦工旗下的CN2 VPS系列，也是一如既往的火爆，当初所销售的全系列产品，都是CN2 GT线路，终于在前不久，推出了CN2 GIA线路的BETA套餐。经过两三个月的线路调试和试运营，今天搬瓦工终于推出了自家CN2 GIA线路的系列套餐，而且价格也比较诱人，购买时，使用循环折扣优惠码 &lt;code&gt;BWH1ZBPVK&lt;/code&gt; 获得终生6%循环优惠。下面，我们分别来看一下：&lt;/p&gt;
    
    </summary>
    
      <category term="技术控" scheme="https://xiaozhou.net/categories/%E6%8A%80%E6%9C%AF%E6%8E%A7/"/>
    
    
      <category term="搬瓦工" scheme="https://xiaozhou.net/tags/%E6%90%AC%E7%93%A6%E5%B7%A5/"/>
    
      <category term="bandwagon" scheme="https://xiaozhou.net/tags/bandwagon/"/>
    
      <category term="VPS" scheme="https://xiaozhou.net/tags/VPS/"/>
    
      <category term="CN2" scheme="https://xiaozhou.net/tags/CN2/"/>
    
      <category term="入手" scheme="https://xiaozhou.net/tags/%E5%85%A5%E6%89%8B/"/>
    
      <category term="评测" scheme="https://xiaozhou.net/tags/%E8%AF%84%E6%B5%8B/"/>
    
  </entry>
  
  <entry>
    <title>程序员内功系列--Tmux篇</title>
    <link href="https://xiaozhou.net/learn-the-command-line-tmux-2018-04-27.html"/>
    <id>https://xiaozhou.net/learn-the-command-line-tmux-2018-04-27.html</id>
    <published>2018-04-27T10:11:07.000Z</published>
    <updated>2019-05-17T09:37:52.099Z</updated>
    
    <content type="html"><![CDATA[<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>自从上次埋下了<a href="https://xiaozhou.net/learn-the-command-line-preface-2017-05-12.html">《程序员内功系列–序篇》</a>的坑过后，继续写了<a href="https://xiaozhou.net/learn-the-command-line-iterm-and-zsh-2017-06-23.html">《程序员内功系列–iTerm与Zsh篇》</a>，谁知突然之间懒癌又犯了，Tmux篇迟迟没动手写。今日猛然回想起来，半年又过去了，惭愧惭愧。这次还是打算一鼓作气，把剩下的坑都填了吧……</p><h2 id="Tmux简介"><a href="#Tmux简介" class="headerlink" title="Tmux简介"></a>Tmux简介</h2><p>言归正传，Tmux是一个老牌又经典的终端复用工具，相信命令行的程序员们以及运维同学们都对它赞不绝口。用上了Tmux，仿佛在终端世界为你打开了另外一个窗口…… 不! 其实是另外一堆窗口……好吧，这次，我们就来探究一下Tmux的神奇世界……</p><a id="more"></a><p>提到Tmux，也许不少同学会比较疑惑，跟我平时mac OS下用的iTerm2有啥区别呢？你Tmux有的多个窗口切换，我iTerm2照样有多个Tab来实现类似的功能。其实，不光是窗口，Tmux提供了基于session概念的多终端窗口管理功能。既然有了session，用户就可以随时存储和恢复终端会话。</p><p>想象一下某个场景：某个用户开了多个终端窗口SSH登录到远程的服务器上进行运维操作，下班关机回家之后，第二天必须得把所有的终端窗口再重新连接和设置一遍，才能继续昨天的工作。有了session就完全不一样了，下班的时候可以脱离当前session，第二天继续上班，用户随时可以通过命令行恢复上次的会话，这样真是太方便了。所以，使用Tmux的场景大致分为两种:</p><ul><li>在服务端运行Tmux，方便保存我们的窗口和各种会话</li><li>在本地终端(例如:iTerm2）运行，方便喜欢我们日常程序开发</li></ul><p>这样看来，使用Tmux的好处不言而喻。另外，Tmux还提供了许多强大的功能：</p><ul><li>提供基于命令行的功能强大的界面。</li><li>完整的快捷键系统，可以完全脱离鼠标，通过键盘快捷键组合，完成一切你所需要的操作。</li><li>基于会话的窗口管理理念，多个会话，多个窗口和panel，进行快速而又高效的切换。</li><li>窗口可以纵向和横向任意分割为多个panel，并实现各种自定义布局，迎合不同用户的需要。</li><li>支持 UTF-8 编码及 256 色终端。</li><li>支持插件，通过配置不同插件实现界面可定制化。</li></ul><p>其实Tmux的功能还有很多，等着你去逐步发现……</p><h2 id="会话、窗口与窗格的概念"><a href="#会话、窗口与窗格的概念" class="headerlink" title="会话、窗口与窗格的概念"></a>会话、窗口与窗格的概念</h2><p>Tmux中的主要概念分为三个：</p><ul><li><p>Session - Session是Tmux中最主要的概念了，默认开启Tmux的时候，就会自动新建一个会话，在这个会话中，也会给你开启一个默认的Window（也即窗口）。Tmux中可以拥有多个会话，多个会话之间可以来回无缝切换。</p></li><li><p>Window - 相比session，Windows是稍微小一点的单位。一个session中，可以开启多个window。这些window同属于一个Session，并由其管理。</p></li><li><p>Panel - Panel是比Window更小的界面元素。前面我们也提到了Tmux中可以对window进行任意分割，由window分割出来的单位就叫做panel了。在同一个window中，用户可以控制光标在分割出的panel中随意移动，用以选定当前作为激活状态的panel。</p></li></ul><p>如果看了这些概念还不太明白，也许下面这个图可以清晰的表明它们之间的关系：</p><p><img src="https://xiaozhou.net/pics/tmux/1.svg" alt></p><p>他们的从属关系为：<code>Session -&gt; Window -&gt; Panel</code></p><h2 id="安装与配置"><a href="#安装与配置" class="headerlink" title="安装与配置"></a>安装与配置</h2><p>Tmux的安装也非常方便，通常Ubuntu下安装，使用:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt-get install tmux</span><br></pre></td></tr></table></figure><p>在mac OS中，推荐使用brew来安装：</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">brew install tmux</span><br></pre></td></tr></table></figure><h2 id="Tmux简单配置"><a href="#Tmux简单配置" class="headerlink" title="Tmux简单配置"></a>Tmux简单配置</h2><p>Tmux在安装完成之后，可以立即启动，不过这还只算一个“裸奔”的Tmux，因为很多配置项都是默认值，需要我们根据自己的喜好进行一些设置。从零开始创建一个Tmux是比较费神的，建议去网上寻找其他大神的配置文件来修改，这样比较快捷一些。这里提供一个<a href="https://github.com/TimothyYe/mydotfiles/blob/master/.tmux.conf" target="_blank" rel="noopener">我经常使用的Tmux配置文件</a>，可以作为模板，直接下载后按照自己的喜好来更改。</p><p>需要注意的是，tmux的配置文件本身是一个隐藏文件，也就是以 <code>.</code> 号开头的文件，叫做 <code>.tmux.conf</code> 。我们需要把这个文件放在当前用户的默认主目录下，也即 <code>~/.tmux.conf</code> ，tmux启动后，会自动读取和加载里面的配置项。</p><p>配置文件就算这么搞定了，如果你是第一次接触Tmux，建议不用太纠结如何弄清楚配置文件里面的每一项是什么意思，在后续的使用中，你可能会不断去修改和调整，自然而然也就熟悉了。接下来，我们要见识一下Tmux强大的各种快捷键功能。</p><h2 id="常用快捷键"><a href="#常用快捷键" class="headerlink" title="常用快捷键"></a>常用快捷键</h2><p>初次使用Tmux需要明白的是，Tmux的各种快捷键功能，是需要一个<code>&lt;prefix&gt;</code> 组合键作为前缀的。也就是说，需要先按下 <code>&lt;prefix&gt;</code> 组合键，才能激活快捷键功能，然后再按对应各种功能的快捷键，才会生效。之所以这样设计，估计也是为了把快捷键的输入跟用户正常输入区分开来。</p><p>初次使用Tmux，我们要知道的是，Tmux为我们默认预备的 <code>&lt;prefix&gt;</code> 组合键，是 <code>C-b</code> (即Ctrl+b)。当然，根据我们自己的习惯，如果觉得 <code>C-b</code> 按起来不方便，可以通过修改配置文件的方式，自定义自己喜欢的 <code>&lt;prefix&gt;</code> 组合键。比如我就觉得 <code>C-b</code>距离有点远，于是，我的 <code>&lt;prefix&gt;</code> 是这么定义的：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">set -g prefix C-g</span><br></pre></td></tr></table></figure><p>嗯，我把我的 <code>&lt;prefix&gt;</code> 设置为了 Ctrl+g (参考<a href="https://github.com/TimothyYe/mydotfiles/blob/master/.tmux.conf#L7" target="_blank" rel="noopener">我的配置文件</a>)，或许你也能找到自己按起来比较舒适的 <code>&lt;prefix&gt;</code> 组合键。使用Tmux的快捷键，几乎能完成大部分的功能和操作，让你双手几乎不用离开键盘，就可以完成日常的工作，感觉非常的Geek。</p><p>这里简单列举一下Tmux的部分快捷键操作，有些快捷键估计跟Tmux默认提供的不太一样，因为我根据自己的喜好进行了一些调整。</p><h3 id="窗口-Window-操作"><a href="#窗口-Window-操作" class="headerlink" title="窗口(Window)操作"></a>窗口(Window)操作</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&lt;prefix&gt; c  创建新窗口</span><br><span class="line">&lt;prefix&gt; w  列出所有窗口</span><br><span class="line">&lt;prefix&gt; n  后一个窗口</span><br><span class="line">&lt;prefix&gt; p  前一个窗口</span><br><span class="line">&lt;prefix&gt; f  查找窗口</span><br><span class="line">&lt;prefix&gt; ,  重命名当前窗口</span><br><span class="line">&lt;prefix&gt; &amp;  关闭当前窗口</span><br></pre></td></tr></table></figure><h3 id="窗格-Panel-操作"><a href="#窗格-Panel-操作" class="headerlink" title="窗格(Panel)操作"></a>窗格(Panel)操作</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">&lt;prefix&gt; |  垂直分割</span><br><span class="line">&lt;prefix&gt; -  水平分割</span><br><span class="line">&lt;prefix&gt; o  交换窗格</span><br><span class="line">&lt;prefix&gt; x  关闭窗格</span><br><span class="line">&lt;prefix&gt; &lt;space&gt; 切换布局</span><br><span class="line">&lt;prefix&gt; q 显示每个窗格是第几个，当数字出现的时候按数字几就选中第几个窗格</span><br><span class="line">&lt;prefix&gt; &#123; 与上一个窗格交换位置</span><br><span class="line">&lt;prefix&gt; &#125; 与下一个窗格交换位置</span><br><span class="line">&lt;prefix&gt; u 切换窗格最大化</span><br><span class="line">&lt;prefix&gt; n 切换窗格最小化</span><br><span class="line">&lt;prefix&gt; 0-9 切换到指定编号的窗口</span><br></pre></td></tr></table></figure><h3 id="窗格-Panel-选择"><a href="#窗格-Panel-选择" class="headerlink" title="窗格(Panel)选择"></a>窗格(Panel)选择</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&lt;prefix&gt; h 选择左边的窗格</span><br><span class="line">&lt;prefix&gt; j 选择下面的窗格</span><br><span class="line">&lt;prefix&gt; k 选择上面的窗格</span><br><span class="line">&lt;prefix&gt; l 选择右边的窗格</span><br></pre></td></tr></table></figure><p>参考<a href="https://github.com/TimothyYe/mydotfiles/blob/master/.tmux.conf#L62" target="_blank" rel="noopener">这里的设置</a></p><h3 id="窗格-Panel-尺寸调整"><a href="#窗格-Panel-尺寸调整" class="headerlink" title="窗格(Panel)尺寸调整"></a>窗格(Panel)尺寸调整</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&lt;prefix&gt; H 当前窗格向左扩大3格</span><br><span class="line">&lt;prefix&gt; J 当前窗格向下扩大3格</span><br><span class="line">&lt;prefix&gt; K 当前窗格向上扩大3格</span><br><span class="line">&lt;prefix&gt; L 当前窗格向右扩大3格</span><br></pre></td></tr></table></figure><p>另外，打开了<a href="https://github.com/TimothyYe/mydotfiles/blob/master/.tmux.conf#L45" target="_blank" rel="noopener">这个</a>选项，还能使用鼠标来调整Panel尺寸。</p><h3 id="会话-Session-相关"><a href="#会话-Session-相关" class="headerlink" title="会话(Session)相关"></a>会话(Session)相关</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&lt;prefix&gt; :new&lt;回车&gt;  启动新会话</span><br><span class="line">&lt;prefix&gt; s           列出所有会话</span><br><span class="line">&lt;prefix&gt; $           重命名当前会话</span><br></pre></td></tr></table></figure><p>这里只是列出了部分Tmux常用快捷键，初学Tmux，千万别被这么多的快捷键给吓住，随着使用Tmux时间的不断增加，这些快捷键最终会变为肌肉的条件反射，所谓的“无剑胜有剑”，嘿嘿。</p><h2 id="Tmux使用效果"><a href="#Tmux使用效果" class="headerlink" title="Tmux使用效果"></a>Tmux使用效果</h2><p>嗯，待你玩熟了window与panel，Tmux里面你就可以任意创建自己喜欢的终端布局了。下面是我常用的终端布局效果，供大家围观……</p><ul><li>开发程序时的布局</li></ul><p><img src="https://xiaozhou.net/pics/ide.png" alt></p><ul><li>运维与部署程序时的布局</li></ul><p><img src="https://xiaozhou.net/pics/tmux/3.png" alt></p><h2 id="插件系统与常用插件介绍"><a href="#插件系统与常用插件介绍" class="headerlink" title="插件系统与常用插件介绍"></a>插件系统与常用插件介绍</h2><h3 id="TPM的安装"><a href="#TPM的安装" class="headerlink" title="TPM的安装"></a>TPM的安装</h3><p>跟我们现在常用的很多软件类似，Tmux也支持插件系统，可以通过安装插件扩展出许多功能，让Tmux变得更加强大。在Tmux中，这款插件管理器叫做 <a href="https://github.com/tmux-plugins/tpm" target="_blank" rel="noopener">TPM - Tmux Plugin Manager</a>。</p><p>TPM的安装也比较简单:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ git <span class="built_in">clone</span> https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm</span><br></pre></td></tr></table></figure><p>然后，修改Tmux配置文件，让其在启动时加载TPM，参考<a href="https://github.com/TimothyYe/mydotfiles/blob/master/.tmux.conf#L95" target="_blank" rel="noopener">这里</a></p><p>TPM主要提供插件的安装，更新和移除等管理功能：</p><ul><li><code>&lt;prefix&gt; I</code> 安装插件，并更新Tmux</li><li><code>&lt;prefix&gt; U</code> 更新所有已安装插件</li><li><code>&lt;prefix&gt; Alt U</code> 移除所有插件列表中不存在的插件</li></ul><h3 id="常用插件推荐"><a href="#常用插件推荐" class="headerlink" title="常用插件推荐"></a>常用插件推荐</h3><p>有了TPM，我们就能够安装和使用各种插件了，这里介绍几款我比较常用的插件：</p><ul><li><p>Tmux Resurrect 一个非常好用的保存当前Tmux窗口和Panel布局的插件。它可以帮助你持久化当前Tmux中所有的窗口和Panel布局。如果你对窗口进行了分割并且精心调整过，在退出Tmux之前可以使用快捷键对布局进行持久化。下一次启动Tmux的时候，也能非常方便的用快捷键恢复上次的窗口布局，真是非常方便。<br>插件地址：<a href="https://github.com/tmux-plugins/tmux-resurrect" target="_blank" rel="noopener">https://github.com/tmux-plugins/tmux-resurrect</a></p></li><li><p>Tmux urlview 在终端界面中自动搜寻所有的URL链接地址，合并为一个可以选择的列表，然后选中直接在浏览器中打开URL。省去了用鼠标复制URL，再打开浏览器粘贴的繁琐操作，非常高效，值得推荐！<br>插件地址：<a href="https://github.com/tmux-plugins/tmux-urlview" target="_blank" rel="noopener">https://github.com/tmux-plugins/tmux-urlview</a></p></li><li><p>Tmux open 使用系统中默认文件类型对应的程序，快速打开在终端中选中的文件名。这个也非常高效，值得推荐！ 插件地址：<a href="https://github.com/tmux-plugins/tmux-open" target="_blank" rel="noopener">https://github.com/tmux-plugins/tmux-open</a></p></li><li><p>Tmux-Battery 和 Tmux-CPU 这两个插件也值得推荐，安装好后，能在Tmux右下角显示当前机器的电量和CPU占用百分比，能给Tmux增色不少。<br><img src="https://xiaozhou.net/pics/tmux/2.png" alt></p></li></ul><p>插件地址： <a href="https://github.com/tmux-plugins/tmux-battery" target="_blank" rel="noopener">https://github.com/tmux-plugins/tmux-battery</a> <a href="https://github.com/tmux-plugins/tmux-cpu" target="_blank" rel="noopener">https://github.com/tmux-plugins/tmux-cpu</a></p><h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>Tmux真是终端下的利器，在macOS下，配合iTerm2和Vim，能轻松的打造出高效的开发环境。在服务端运行Tmux，也能为你日常运维工作带来许多便利。所以，将Tmux大法谨记心中，他日必能为君带来极大的便利和效率。</p><h2 id="相关阅读"><a href="#相关阅读" class="headerlink" title="相关阅读"></a>相关阅读</h2><ul><li><a href="https://xiaozhou.net/learn-the-command-line-preface-2017-05-12.html">程序员内功系列–序篇</a></li><li><a href="https://xiaozhou.net/learn-the-command-line-iterm-and-zsh-2017-06-23.html">程序员内功系列–iTerm与Zsh篇</a></li><li><a href="https://xiaozhou.net/learn-the-command-line-tmux-2018-04-27.html">程序员内功系列–Tmux篇</a></li><li><a href="https://xiaozhou.net/learn-the-command-line-vim-2018-08-08.html">程序员内功系列–Vim篇</a></li><li><a href="https://xiaozhou.net/learn-the-command-line-tools-md-2018-10-11.html">程序员内功系列–常用命令行工具篇</a></li></ul>]]></content>
    
    <summary type="html">
    
      &lt;h2 id=&quot;前言&quot;&gt;&lt;a href=&quot;#前言&quot; class=&quot;headerlink&quot; title=&quot;前言&quot;&gt;&lt;/a&gt;前言&lt;/h2&gt;&lt;p&gt;自从上次埋下了&lt;a href=&quot;https://xiaozhou.net/learn-the-command-line-preface-2017-05-12.html&quot;&gt;《程序员内功系列–序篇》&lt;/a&gt;的坑过后，继续写了&lt;a href=&quot;https://xiaozhou.net/learn-the-command-line-iterm-and-zsh-2017-06-23.html&quot;&gt;《程序员内功系列–iTerm与Zsh篇》&lt;/a&gt;，谁知突然之间懒癌又犯了，Tmux篇迟迟没动手写。今日猛然回想起来，半年又过去了，惭愧惭愧。这次还是打算一鼓作气，把剩下的坑都填了吧……&lt;/p&gt;&lt;h2 id=&quot;Tmux简介&quot;&gt;&lt;a href=&quot;#Tmux简介&quot; class=&quot;headerlink&quot; title=&quot;Tmux简介&quot;&gt;&lt;/a&gt;Tmux简介&lt;/h2&gt;&lt;p&gt;言归正传，Tmux是一个老牌又经典的终端复用工具，相信命令行的程序员们以及运维同学们都对它赞不绝口。用上了Tmux，仿佛在终端世界为你打开了另外一个窗口…… 不! 其实是另外一堆窗口……好吧，这次，我们就来探究一下Tmux的神奇世界……&lt;/p&gt;
    
    </summary>
    
      <category term="技术控" scheme="https://xiaozhou.net/categories/%E6%8A%80%E6%9C%AF%E6%8E%A7/"/>
    
    
      <category term="命令行" scheme="https://xiaozhou.net/tags/%E5%91%BD%E4%BB%A4%E8%A1%8C/"/>
    
      <category term="程序员" scheme="https://xiaozhou.net/tags/%E7%A8%8B%E5%BA%8F%E5%91%98/"/>
    
      <category term="Tmux" scheme="https://xiaozhou.net/tags/Tmux/"/>
    
      <category term="cmd" scheme="https://xiaozhou.net/tags/cmd/"/>
    
      <category term="command line" scheme="https://xiaozhou.net/tags/command-line/"/>
    
  </entry>
  
  <entry>
    <title>Docker多阶段镜像构建</title>
    <link href="https://xiaozhou.net/docker-multi-stage-builds-2018-04-26.html"/>
    <id>https://xiaozhou.net/docker-multi-stage-builds-2018-04-26.html</id>
    <published>2018-04-25T16:14:58.000Z</published>
    <updated>2019-05-17T09:37:52.078Z</updated>
    
    <content type="html"><![CDATA[<p>从Docker版本 <code>17.05.0-ce</code> 开始，就支持了一种新的构建镜像的方法，叫做：多阶段构建(Multi-stage builds)，旨在解决Docker构建应用容器中的一些痛点。在日常构建容器的场景中，经常会遇到在同一个容器中进行源码的获取，编译和生成，最终才构建为镜像。这样做的劣势在于：</p><ul><li>不得不在容器中安装构建程序所必须的运行时环境</li><li>不得不在同一个容器中，获取程序的源码和构建所需的一些生态工具</li><li>构建出的镜像甚至包含了程序源码和一些不必要的文件，导致容器镜像尺寸偏大</li></ul><a id="more"></a><p>当然，还有一种稍微优雅的方式，就是我们事先在外部将项目及其依赖库编译测试打包好后，再将其拷贝到构建目录中，这种虽然可以很好地规避第一种方式存在的风险点，但是也需要考虑不同镜像运行时，对于程序运行兼容性所带来的差异。</p><p>其实，这些痛点，Docker也想到了，官方提供了简便的多阶段构建 (multi-stage build) 方案。所谓多阶段构建，也即将构建过程分为多个阶段，在同一个Dockerfile中，通过不同的阶段来构建和生成所需要的应用文件，最终将这些应用文件添加到一个release的镜像中。这样做能完全规避上面所遇到的一系列问题。实现多阶段构建，主要依赖于新提供的关键字：<code>from</code> 和 <code>as</code> 。</p><p>下面举个栗子：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">FROM muninn/glide:alpine AS build-env</span><br><span class="line">ADD . /go/src/my-proj</span><br><span class="line">WORKDIR /go/src/my-proj</span><br><span class="line">RUN go get -v</span><br><span class="line">RUN go build  -o /go/src/my-proj/my-server</span><br><span class="line"></span><br><span class="line">FROM alpine</span><br><span class="line">RUN apk add -U tzdata</span><br><span class="line">RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai  /etc/localtime</span><br><span class="line">COPY --from=build-env /go/src/my-proj/my-server /my-server</span><br><span class="line">EXPOSE 80</span><br><span class="line">CMD [&quot;my-server&quot;]</span><br></pre></td></tr></table></figure><p>多阶段构建的Dockerfile看起来像是把两个或者更多的Dockerfile合并在了一起，这也即多阶段的意思。<code>as</code> 关键字用来为构建阶段赋予一个别名，这样，在另外一个构建阶段中，可以通过 <code>from</code> 关键字来引用和使用对应关键字阶段的构建输出，并打包到容器中。</p><p>在多阶段构建完成之后，输出的镜像仅仅包含了最终输出的my-server应用，没有其他的源码文件和第三方源码包，非常的干净和简洁。因为 <code>build-env</code> 阶段只是一个构建的中间过程而已。</p><p>甚至，我们还可以使用更多的构建阶段来构建不同的应用，最终将这些构建产出的应用，合并到一个最终需要发布的镜像中。我们可以看一个更复杂一点的栗子：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">from debian as build-essential</span><br><span class="line">arg APT_MIRROR</span><br><span class="line">run apt-get update</span><br><span class="line">run apt-get install -y make gcc</span><br><span class="line">workdir /src</span><br><span class="line"></span><br><span class="line">from build-essential as foo</span><br><span class="line">copy src1 .</span><br><span class="line">run make</span><br><span class="line"></span><br><span class="line">from build-essential as bar</span><br><span class="line">copy src2 .</span><br><span class="line">run make</span><br><span class="line"></span><br><span class="line">from alpine</span><br><span class="line">copy --from=foo bin1 .</span><br><span class="line">copy --from=bar bin2 .</span><br><span class="line">cmd ...</span><br></pre></td></tr></table></figure><p>多阶段构建的好处不言而喻，既可以很方便地将多个彼此依赖的项目通过一个Dockerfile就可轻松构建出期望的容器镜像，并且不用担心镜像太大、源码泄露等风险。不得不说，这是一个非常不错的改进。</p>]]></content>
    
    <summary type="html">
    
      &lt;p&gt;从Docker版本 &lt;code&gt;17.05.0-ce&lt;/code&gt; 开始，就支持了一种新的构建镜像的方法，叫做：多阶段构建(Multi-stage builds)，旨在解决Docker构建应用容器中的一些痛点。在日常构建容器的场景中，经常会遇到在同一个容器中进行源码的获取，编译和生成，最终才构建为镜像。这样做的劣势在于：&lt;/p&gt;&lt;ul&gt;&lt;li&gt;不得不在容器中安装构建程序所必须的运行时环境&lt;/li&gt;&lt;li&gt;不得不在同一个容器中，获取程序的源码和构建所需的一些生态工具&lt;/li&gt;&lt;li&gt;构建出的镜像甚至包含了程序源码和一些不必要的文件，导致容器镜像尺寸偏大&lt;/li&gt;&lt;/ul&gt;
    
    </summary>
    
      <category term="技术控" scheme="https://xiaozhou.net/categories/%E6%8A%80%E6%9C%AF%E6%8E%A7/"/>
    
    
      <category term="docker" scheme="https://xiaozhou.net/tags/docker/"/>
    
  </entry>
  
</feed>
