<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Teches on 夜雨秋灯</title>
    <link>https://blog.lierhua.top/tech/</link>
    <description>Recent content in Teches on 夜雨秋灯</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Sat, 18 Jan 2025 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://blog.lierhua.top/tech/" rel="self" type="application/rss+xml" />
    
    <item>
      <title>记录一款 macOS App 的开发流程</title>
      <link>https://blog.lierhua.top/tech/2025-%E8%AE%B0%E5%BD%95%E4%B8%80%E6%AC%BE-macos-app-%E5%BC%80%E5%8F%91%E6%B5%81%E7%A8%8B/</link>
      <pubDate>Sat, 18 Jan 2025 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/2025-%E8%AE%B0%E5%BD%95%E4%B8%80%E6%AC%BE-macos-app-%E5%BC%80%E5%8F%91%E6%B5%81%E7%A8%8B/</guid>
      <description>
        <![CDATA[
        

<p>关键词：<code>macOS</code>, <code>cursor</code>, <code>xcode</code>, <code>photoshop script</code></p>

<h2 id="项目地址">项目地址</h2>

<p><strong><a href="https://kittymemo.lierhua.top/" rel="noreferrer" target="_blank">请点击这里</a></strong></p>

<h2 id="背景">背景</h2>

<p>我在 <a href="/tech/workflow/alfred-workflow-使用/">alfred workflow</a> 这篇文章中提到过，我对在不打断工作流程的情况下进行信息的记录很有需求，当时没有发现过有这类 APP，
于是就用 Alfred 的 workflow 功能实现了一个，总体上我还是挺满意的，基本能覆盖我的使用场景，满足我的工作需求。</p>

<p>使用了几年后，慢慢的一些短板也就暴露出来了，首先因为是基于 Alfred 的，所以我个人的定制化有限，受限于 Alfred 的规则，只能在一台机器上使用，
我有多台 mac，在每台机器工作，记录的信息就很分散化，再一个就是这个功能也想暴露给朋友家人使用，基于 Alfred 的方案就很受限了，也想自己开发一款
macOS 的 App 来自己定制，奈何当时觉得技术繁琐，一方面是因为需要使用 swift 和 swiftUI，再一个这个 App 因为要使用系统快捷键等功能，
而这方面的开发知识我几乎是 0，所以这个想法就一直搁置了。</p>

<p>直到最近 cursor 在帮我开发了谷歌插件和 SOHO 门禁之后，我对 cursor 的能力是很认可的，于是觉得自己开发一款「速记」App, 于是就有了「KittyMemo」。</p>

<p>下面就记录下我整个 App 的开发流程，包括代码编写，xcode 调试，icon 生成，App 导出等。</p>

<h2 id="代码编写">代码编写</h2>

<h3 id="编写思路与过程">编写思路与过程</h3>

<p>代码编写我基本上都是用让 cursor 帮我完成的，核心点主要是提示词上，不要一上来就试图让 cursor 把代码写完，要把项目拆分成递进的需求。</p>

<p>首先我需要的是一个系统级别的快捷键，这个快捷键可以直接呼起某个界面。</p>

<p>第二步是，这个界面可以输入文字。</p>

<p>第三步是输入文字后，可以将数据保存到电脑的某个默认位置，这个位置的权限也需要。</p>

<p>第四步是，可以通过配置修改这个默认的位置，也就是有一个类 *nix 系统的下项目的配置文件的模块。</p>

<p>这四步中的每一步，都需要调试，看看是不是满足当前的需求，如果不满足，则继续修改，直到这个步骤满足我们的需求。</p>

<p>这四步完成后，就开始进行总体的调试和测试，在测试过程中，我发现光标问题和焦点对象问题不符合我的要求，我需要的是类似于 alfred 的功能，
我快捷键呼出的对话框，不需要用鼠标或者键盘重新定位，而是可以直接输入文字，然后回车后，就可以保存（或者其他的动作），然后对话框消失，
此时光标可以回到刚才的地方，不需要鼠标或者键盘的干预，可以继续之前的工作。于是我通过跟 cursor 的交流，并且提示他「多参考 github 上的开源项目，
同时参考对标的产品 alfred 和 raycast 等」，经过几轮的对话，cursor 帮我实现了整个功能。</p>

<p>当然，在跟 cursor 沟通的过程中，我也踩了很多的坑，比如状态栏的图标的问题，我沟通了大概有 30 多轮，但是 cursor 完全无法实现这个功能，最后我放弃了。
幸好，这个功能也不是必须的。</p>

<h3 id="项目配置">项目配置</h3>

<p>macOS 的项目需要很多的配置文件，而这些配置文件对于我这个新手而言，还是挺费劲的，于是我梳理下我的一些了解与认识。</p>

<p>这些配置文件都是基于 xcode 的，可以从里面选择，也可以添加。 <code>TODO</code></p>

<h2 id="icon-生成">icon 生成</h2>

<p>我是第一次想好好做一个 icon，刚开始的时候踩了一些坑，随着不断地搜索，总结出了一套目前对我来说，比较方便的流程。</p>

<h3 id="探索过程">探索过程</h3>

<p>因为我的应用的名字是「小猫速记」，因此我就开始挑选小猫的图片，这个过程大概耗时半个小时，从 google 的搜图中，
挑选到了一个我觉得 OK 的小猫。</p>

<p>最开始我是直接打开了 photoshop，然后在里面开始扣小猫的图片，然后加背景，然后导出需要的 16p 一直到 1024p 的 icon 图片。</p>

<p>然后发现系统竟然不自动的倒圆角，我做出的图是一个方方正正的图，有点不好看，于是我开始搜索如何用 photoshop 倒圆角，学会了之后，
尝试一下，发现倒出来的圆角真的垃圾，最终我放弃了用 ps 倒角的方案，转而开始搜索 google 中的 macOS app icon 图，企图直接复制一个，
然后利用它的形状，往里面填充我的内容，最开始效果是 OK 的，但是导出 icon 之后，发现形状对了，但是大小大了一圈。</p>

<p>到上面的所有步骤，我知道，我走了弯路了，于是我开始搜索资料，最终搜索到了<a href="https://sspai.com/post/63602" rel="noreferrer" target="_blank">一篇少数派的文章</a>, 然后从里面发现了
<a href="https://macosicons.com/#/" rel="noreferrer" target="_blank">这个网站</a>，根据提示和引导，我下载了一个 icon, 下载后的 icon 是 ics 格式的文件，我直接用 mac 自带的 PDF 阅读器打开，
然后左侧边栏就出现了从 16p 到 1024p 的各个 icon, 然后我直接右键第一个图片，就可以导出为 png 图片了。</p>

<p>把图片导入到 photoshop，发现，原来图片是又一圈空白的边框的，难怪我第一次制作的图大那么多。</p>

<p>之后就是把我第一步找到的小猫的图片抠出一个空白来，做出了对应的 icon。到这一步，我的 icon 就制作好了。</p>

<h3 id="icon-导出">icon 导出</h3>

<p>因为每一个 APP 都需要很多大小的 icon，刚开始我是手动输出的，发现太慢了，于是想到了 photoshop script 可以运行自动化脚本，于是跟
chatgpt 要了一个脚本执行了，快速把 icon 跑出来了。</p>

<p><a href="https://github.com/immotal/photoshop-script" rel="noreferrer" target="_blank">脚本地址</a>，建了一个 github 代码仓库，以后遇到其他的 ps 脚本也会记录到这里，方便以后得使用。</p>

<h2 id="app-导出-我直接复制了-gpt-的结果">App 导出 &ndash; 我直接复制了 gpt 的结果</h2>

<p>要将这个 app 安装到你的 Mac 上使用，有几种方法：</p>

<ol>
<li><p><strong>直接从 Xcode 导出应用</strong>（推荐，最简单）：</p>

<pre><code>1. 在 Xcode 中选择 Product &gt; Archive
2. 等待 Archive 完成
3. 在弹出的 Organizer 窗口中：
- 选择刚创建的 Archive
- 点击 &quot;Distribute App&quot;
- 选择 &quot;Copy App&quot;
- 选择保存位置
4. 将导出的 .app 文件拖到 Applications 文件夹
</code></pre></li>

<li><p><strong>通过 Xcode 构建发布版本</strong>：</p>

<pre><code>1. 在 Xcode 工具栏中将 scheme 改为 &quot;Release&quot;
2. Product &gt; Build
3. 在 Finder 中找到构建产物：
- 按住 Option 键
- 点击 Finder 的 Go 菜单
- 选择 Library
- 导航到 Developer/Xcode/DerivedData/Demaxi-xxx/Build/Products/Release
- 找到 Demaxi.app
4. 将 Demaxi.app 拖到 Applications 文件夹
</code></pre></li>

<li><p><strong>创建签名版本</strong>（更安全，推荐）：</p>

<pre><code>1. 在 Xcode 中选择项目
2. 选择 Signing &amp; Capabilities 标签
3. 选择你的开发者账号
4. 设置 Team
5. 然后按方法 1 或 2 导出应用
</code></pre></li>
</ol>

<p>首次运行时可能遇到的问题：
1. 提示&rdquo;无法打开，因为来源不明&rdquo;：
    - 在 System Settings &gt; Privacy &amp; Security 中允许运行
    - 或在终端执行：<code>xattr -cr /Applications/Demaxi.app</code></p>

<ol>
<li>权限问题：

<ul>
<li>首次运行时会请求辅助功能权限</li>
<li>需要在 System Settings &gt; Privacy &amp; Security &gt; Accessibility 中允许</li>
<li>同样需要允许输入监控权限</li>
</ul></li>
</ol>

<p>建议的完整安装步骤：</p>

<ol>
<li><p><strong>准备工作</strong>：</p>

<pre><code class="language-swift">// 在 Xcode 中设置版本号
// 在 Target &gt; General 中设置
Version: 1.0.0
Build: 1
</code></pre></li>

<li><p><strong>构建发布版本</strong>：</p>

<pre><code>1. 选择 &quot;Any Mac&quot; 作为运行目标
2. Product &gt; Archive
3. 在 Organizer 中选择 &quot;Distribute App&quot;
4. 选择 &quot;Copy App&quot;
5. 保存到桌面
</code></pre></li>

<li><p><strong>安装应用</strong>：</p>

<pre><code>1. 将 .app 文件拖到 Applications 文件夹
2. 右键点击应用 &gt; Open
3. 点击 &quot;Open&quot; 确认运行
</code></pre></li>

<li><p><strong>设置权限</strong>：</p>

<pre><code>1. 打开 System Settings
2. 进入 Privacy &amp; Security
3. 找到并允许：
- Accessibility
- Input Monitoring
4. 重启应用
</code></pre></li>

<li><p><strong>验证安装</strong>：</p>

<pre><code>1. 打开应用配置 webhook URL 和 token
2. 双击 Option 键测试快捷键
3. 输入内容测试功能
</code></pre></li>
</ol>

<p>如果你想让应用开机自启动：
1. System Settings &gt; General &gt; Login Items
2. 点击 &ldquo;+&rdquo; 添加 Demaxi</p>

<p>这样你就能在自己的 Mac 上正常使用这个应用了。记得定期备份配置，以防需要重新安装。</p>

<h2 id="landing-page">Landing Page</h2>

<p>Landing Page 我用了 vuepress, 用了 yarn2，我好一顿折腾，最后还是搞好了，当时脑子已经快不转了。</p>

<h2 id="app-上线">App 上线</h2>

<p>App 的 release 是在 xcode 打包好之后，放到了 github 项目的 Release 上。</p>

<hr />

<p>-<a href="https://developer.apple.com/cn/design/human-interface-guidelines/app-icons#macOS" rel="noreferrer" target="_blank">macOS icon 文档</a></p>

        ]]>
      </description>
    </item>
    
    <item>
      <title>通过 Cursor 写一个 Chrome 扩展</title>
      <link>https://blog.lierhua.top/tech/2024-%E9%80%9A%E8%BF%87cursor%E5%86%99%E4%B8%80%E4%B8%AAchrome%E6%89%A9%E5%B1%95/</link>
      <pubDate>Wed, 08 Jan 2025 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/2024-%E9%80%9A%E8%BF%87cursor%E5%86%99%E4%B8%80%E4%B8%AAchrome%E6%89%A9%E5%B1%95/</guid>
      <description>
        <![CDATA[
        

<p>关键词：<code>cursor</code>, <code>chrome extension</code></p>

<h2 id="背景">背景</h2>

<p>Cursor 是一个 AI 加持的 VS Code 类型的编辑器，在刚出的那段时间，X 上好多人都在推荐，我也尝试了下，觉得确实蛮好用。</p>

<p>但是因为使用次数的限制，所以没有用起来，加上公司的 gpt-4o 也很好用，就一直没有再关注了。</p>

<p>周末的时候，刷短视频的时候，数次刷到了关于使用 cursor 工作的内容，有的是用来写微信小程序，有的是给定一个 UI 界面让 cursor 直接写前端代码。</p>

<p>发现比刚出的时候，更加的强大了，于是决定用来写个小项目。我之前就有个计划，写一个 chrome 浏览器的扩展，所以正好就从这个开始了。</p>

<h2 id="步骤">步骤</h2>

<p>新建一个项目目录，然后用 cursor 打开目录，然后使用 cursor 的 composer 模式，描述下需求背景。</p>

<p><img src="/images/tech/2024-cursor-chrome-extension/begin-cursor-composer.jpg" alt="" /></p>

<blockquote>
<p>写一个 Chrome 插件，当我用鼠标选中文字或者代码时，判定是什么类型的，比如是 JSON 还是 sql 或者其他所有类型的代码，如果是的话，格式化一下并展示出来；同时如果发现是 golang 的堆栈错误信息，也一并给格式化一下展示出来
需要的是，我选中文本后，会在浏览器上浮动一个小的 icon，点击这个 icon 才执行 format 格式化，同时注意检查格式和代码，刚才的代码提示导入 Chrome 失败</p>
</blockquote>

<p>这个是最开始使用的描述，cursor 根据我的需求开始列出了插件需要的文件结构，然后创建对应的文件和代码逻辑，最后把所有的代码应用到了项目里，创建了所有的文件。</p>

<p>这一版代码已经是可以运行的了，并且基本实现了业务逻辑功能，但是在浮动的 icon 这里，可能是我描述不规范，没有用规范的术语说明这个浮动的 icon 是什么，
起初这个做的很不好，我后面又花费了不小的功夫，一点点的交流沟通，最终写出了我认可的代码。</p>

<p>然后在此基础上，我又让 cursor 拓展了这个插件的功能，依旧是使用 composer 模式。</p>

<blockquote>
<p>阅读本仓库代码，目前的仓库代码干的事儿很少，现在需要你做的是，拓展 button 点击后的功能，现在是 4 个，根据你知道的 github 上的一些项目的东西，拓展出十几个针对文本的操作，然后操作之后的数据做两个处理，一份跟现在一样复制到剪贴板，一份需要弹出一个框，然后把结果展示在里面</p>
</blockquote>

<p><img src="/images/tech/2024-cursor-chrome-extension/extend-chrome-feature.jpg" alt="" /></p>

<p>经过一些调试之后，现在已经可以很丝滑的在 Chrome 上运行了。</p>

<p><img src="/images/tech/2024-cursor-chrome-extension/extension-use-example.png" alt="" /></p>

<p>在使用 cursor 的过程中，我还订阅了 cursor pro，这样我的每个月的是高级模型的使用次数就达到了 500 次，基本可以满足我日常的需求了。</p>

<h2 id="总结">总结</h2>

<p>整个流程花费了大概不到两个小时，包括我调试功能在内，这个效率真的是非常的高了，我之前从来没有写过 Chrome 的扩展，这次从零开始，如此的快捷高效。</p>

<p>之后，我会增加 cursor 在我的项目中的使用，看看在大型项目中，他是不是依然如此厉害。</p>

<hr />

<p>最后附上我让 cursor 写的这个项目的地址，<a href="https://github.com/immotal/string-formatter-chrome-extension" rel="noreferrer" target="_blank">点击这里</a>
自开发的 Chrome extension 如何安装到 Chrome 中去，<a href="https://fasionchan.com/chrome-extensions/quick-start/getting-started/" rel="noreferrer" target="_blank">点击这里</a></p>

        ]]>
      </description>
    </item>
    
    <item>
      <title>String Formatter 隐私政策 (String Formatter Privacy Policy) </title>
      <link>https://blog.lierhua.top/tech/2024-string-formatter-pravicy/</link>
      <pubDate>Wed, 01 Jan 2025 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/2024-string-formatter-pravicy/</guid>
      <description>
        <![CDATA[
        

<h2 id="i-introduction">I. Introduction</h2>

<p>This privacy policy is formulated by <a href="hereinafter referred to as" title="we&quot; or &quot;us" rel="noreferrer" target="_blank">Li Erhua</a>. It aims to explain to you how we collect, use, share, store, protect, and disclose your personal information or usage information when you use our Chrome extension program, String Formatter. By using this extension program, you agree to be bound by this privacy policy. If you do not accept the terms of this privacy policy, please stop accessing or using this application in any way. We strongly recommend that you read this policy carefully before performing any operations using this application.</p>

<h2 id="ii-information-collection">II. Information Collection</h2>

<h3 id="1-purpose-overview">1. Purpose Overview</h3>

<p>We collect your information mainly for the following general purposes: to register and manage your account so that you can access and use our services; to communicate with you generally, including providing you with information about us; to enable us to publish your comments, forum posts, and other content; to respond to your questions and comments; to prevent potential prohibited or illegal activities; and to enforce our terms of use.</p>

<h3 id="2-specific-information-collection">2. Specific Information Collection</h3>

<ul>
<li><strong>Technical Information</strong>: When you use our services, we will collect the IP address of the computer you use to access the services, the mobile device ID (the unique identifier assigned by the manufacturer), and the technical details of your computer or mobile device (such as device type, web browser, and operating system). This data helps us improve the performance of the software on your device and solve any possible problems.</li>
<li><strong>Content Features</strong>: The text you input, the files you upload, and the feedback you provide (&ldquo;content&rdquo;) during the use of our services are crucial for the effective operation of the &ldquo;History&rdquo; function, and we will collect them.</li>
<li><strong>Cookies</strong>: If you access our mobile application through a computer, we may place &ldquo;Cookies&rdquo; on your computer to identify your device. &ldquo;Cookies&rdquo; are identifiers that we transmit to your computer or mobile device, enabling us to identify your browser or mobile device and understand how, when, and by how many people the pages and functions in our services are accessed. You can change the settings of your browser or mobile device to block or restrict the acceptance of Cookies by your computer or device, but this may prevent you from using some of our functions. If you click on a link that directs you to a third-party website, that third party may also transmit Cookies to you. You hereby agree that this privacy policy does not cover the use of Cookies by any third party.</li>
</ul>

<h2 id="iii-collection-and-use-of-personal-data">III. Collection and Use of Personal Data</h2>

<h3 id="1-definition-of-personal-data">1. Definition of Personal Data</h3>

<p>During your use of our services, we may ask you to provide certain personally identifiable information that can be used to contact or identify you, including but not limited to your email address, name, etc.</p>

<h3 id="2-ways-of-use">2. Ways of Use</h3>

<ul>
<li><strong>Providing and Maintaining Services</strong>: This includes monitoring the usage of services to ensure their stable operation and optimizing and improving them based on usage data.</li>
<li><strong>Account Management</strong>: Handling your registration information as a service user. The personal data you provide will enable you to access the different functions available to registered users.</li>
<li><strong>Contract Fulfillment</strong>: Handling the development, compliance, and execution of purchase contracts related to the products, items, or services you purchase through our services, or handling any other contractual matters with us.</li>
<li><strong>Contacting You</strong>: Contacting you via email or other equivalent forms of electronic communication (such as push notifications in mobile applications) to provide you with information about feature updates, products, or contracted services, including necessary or reasonable security updates.</li>
<li><strong>Providing Information</strong>: Providing you with news, special offers, and general information similar to the goods, services, and activities you have purchased or inquired about, unless you choose not to receive such information.</li>
<li><strong>Processing Requests</strong>: Responding to and processing the requests you submit to us.</li>
<li><strong>Targeted Advertising</strong>: We may use your information to develop and display content and advertisements that match your interests and/or location (in cooperation with third-party suppliers) and measure their effectiveness.</li>
<li><strong>Other Purposes</strong>: For example, conducting data analysis, identifying usage trends, determining the effectiveness of promotional activities, and evaluating and improving our services, products, marketing methods, and your user experience.</li>
</ul>

<h2 id="iv-information-sharing">IV. Information Sharing</h2>

<h3 id="1-third-party-suppliers">1. Third-Party Suppliers</h3>

<p>We engage third-party suppliers to provide various services on our behalf, such as business analysis, customer service, marketing, distribution, payment processing, online chatting, etc. We may authorize these suppliers to collect information on our behalf to operate the functions of the application or provide services that meet your needs. We ensure that third-party suppliers use such information only for fulfilling their responsibilities and do not allow them to use the information for any other purposes.</p>

<h3 id="2-within-the-company-group">2. Within the Company Group</h3>

<p>We may need to provide your information to our parent company, subsidiaries, or affiliated companies. When these affiliated parties have your information, they will follow the best practices described in this privacy policy to use the information.</p>

<h3 id="3-business-partners">3. Business Partners</h3>

<p>In the process of jointly providing services to you with our business partners, if you choose to access the optional services provided by these partners, we may share your information, including your personal information, with them. Please note that we cannot control the privacy practices of these third-party business partners.</p>

<h3 id="4-user-profiles-and-submitted-content">4. User Profiles and Submitted Content</h3>

<p>Certain user profile information, including but not limited to usernames, locations, and any video or image content uploaded by users to the service, may be displayed to other users to facilitate user interaction within the service or respond to your requests for our company&rsquo;s services. Any content you upload to your public user profile and any personal information or content you voluntarily disclose online in a way that is visible to other users (such as in discussion boards, messages, and chat areas, etc.) will become publicly available and can be collected and used by others. When you send messages, comments, or upload images or videos through the service, your username may also be displayed to other users, and other users can contact you through messages and comments. Similarly, we cannot control the policies and practices of any other third-party websites or services that may interact with our services.</p>

<h3 id="5-related-websites">5. Related Websites</h3>

<p>If you are referred to us from another website, we may need to share content related to registration information, including but not limited to your name, email address, phone number, etc. In this case, we recommend that you read and review the privacy policy of the referring website. We are not responsible for the way they handle such information.</p>

<h3 id="6-business-transfer">6. Business Transfer</h3>

<p>If we conduct asset sales or purchases, customer information is usually one of the business assets that may be transferred. In addition, if we (or our assets) are acquired, cease operations, go bankrupt, or experience other changes in control, personal information will be one of the assets transferred to or acquired by third parties.</p>

<h3 id="7-government-agencies">7. Government Agencies</h3>

<p>We may disclose your personal information and usage information upon receiving subpoenas, court orders, government requests, or to comply with any legal requirements that protect our interests. In such cases, we will contact you via email. All communications we send to this email address shall be deemed to have been communicated to you.</p>

<h2 id="v-retention-of-personal-data">V. Retention of Personal Data</h2>

<p>We will retain your personal data only for the period necessary for the purposes described in this privacy policy. We will retain and use your personal data to the extent necessary to comply with legal obligations (for example, if the law requires us to retain data), resolve disputes, and enforce legal agreements and policies.</p>

<h2 id="vi-information-protection">VI. Information Protection</h2>

<p>We are committed to ensuring the security and reliability of your information and follow generally accepted standards to protect the personal information and usage information submitted to us. Although no service can guarantee absolute security, we have appropriate administrative, technical, and security procedures in place to ensure the integrity, security, and confidentiality of your information. Your information will only be processed by authorized employees, agents, or third-party suppliers for the required purposes. We use appropriate firewalls, encryption technologies, and intrusion detection systems to prevent unauthorized use of your information.</p>

<h2 id="vii-overseas-use-of-services">VII. Overseas Use of Services</h2>

<p>If you access our application from overseas, please note that such information may be transmitted, stored, or processed in China, where our servers or central database are located. Even if you access from abroad, we ensure that we follow best practices to protect your information. By using our services, you acknowledge that we are governed by China&rsquo;s privacy and data protection laws, which may differ from the laws in your country. We will take all reasonable and necessary steps to ensure that your data is processed securely and in accordance with this privacy policy. We will not transfer your personal data to other organizations or countries unless there are sufficient control measures (including ensuring the security of your data and other personal information).</p>

<h2 id="viii-email-marketing">VIII. Email Marketing</h2>

<p>We may use your personal data to send you newsletters, marketing or promotional materials, and other information that may be of interest to you. You can choose to opt out of receiving such communications by clicking on the unsubscribe link in any email we send or following the instructions provided, or by directly contacting us.</p>

<h2 id="ix-payment">IX. Payment</h2>

<p>We may use third-party services (such as payment processors like FastSpring) for payment processing. We will not store or collect your payment card details. This information will be directly provided to our third-party payment processors, and their use of your personal information is governed by their privacy policies. These payment processors follow the PCI-DSS standards managed by the PCI Security Standards Council, which was established through the joint efforts of brands such as Visa, Mastercard, American Express, and Discover. The PCI-DSS requirements help ensure the secure processing of payment information. You can view FastSpring&rsquo;s privacy policy at: <a href="https://fastspring.com/privacy/" rel="noreferrer" target="_blank">https://fastspring.com/privacy/</a></p>

<h2 id="x-related-to-regulations">X. Related to Regulations</h2>

<h3 id="1-general-data-protection-regulation-gdpr">1. General Data Protection Regulation (GDPR)</h3>

<ul>
<li><strong>Legal Basis for Processing Personal Data</strong>: We may process personal data under the following conditions:

<ul>
<li><strong>Consent</strong>: You have consented to our processing of your personal data for one or more specific purposes.</li>
<li><strong>Contract Fulfillment</strong>: Providing personal data is necessary for fulfilling the agreement with you and/or any pre-contractual obligations.</li>
<li><strong>Legal Obligation</strong>: Processing personal data is necessary for the company to comply with its legal obligations.</li>
<li><strong>Vital Interests</strong>: It is necessary to process personal data to protect the vital interests of you or other natural persons.</li>
<li><strong>Public Interest</strong>: Processing personal data is related to tasks carried out in the public interest or the official powers exercised by the company.</li>
<li><strong>Legitimate Interests</strong>: Processing personal data is for the pursuit of the company&rsquo;s legitimate interests.</li>
<li>In any case, the company will be happy to assist in clarifying the specific legal basis applicable to the processing, especially whether providing personal data is a statutory requirement, a contractual requirement, or a requirement necessary for entering into a contract.</li>
</ul></li>
<li><strong>Your Rights under the GDPR</strong>: The company is committed to respecting the confidentiality of your personal data and ensuring that you can exercise your rights. If you are within the European Union, according to this privacy policy and the law, you have the following rights:

<ul>
<li><strong>Access to Personal Data</strong>: You have the right to access, update, or delete the information we hold about you. Whenever possible, you can directly access, update, or request the deletion of your personal data in the account settings section. If you are unable to perform these operations on your own, please contact us for assistance. This also enables you to receive a copy of the personal data we hold about you.</li>
<li><strong>Correction of Personal Data</strong>: You have the right to request us to correct any incomplete or inaccurate information we hold about you.</li>
<li><strong>Objection to Processing Personal Data</strong>: When we use legitimate interests as the legal basis for processing your personal data and your specific circumstances make you want to object to our processing of your personal data on this basis, you have this right. In addition, when we process your personal data for direct marketing purposes, you also have the right to object.</li>
<li><strong>Request for Deletion of Personal Data</strong>: When we have no sufficient reason to continue processing your personal data, you have the right to request us to delete or remove this data.</li>
<li><strong>Request for Transfer of Personal Data</strong>: We will provide your personal data to you or a third party of your choice in a structured, commonly used, and machine-readable format. Please note that this right applies only to the automated information that you initially consented to our use or the information that we use in fulfilling a contract with you.</li>
<li><strong>Withdrawal of Consent</strong>: You have the right to withdraw your consent for the use of your personal data. If you withdraw your consent, we may not be able to provide you with access to certain specific functions of our services.</li>
</ul></li>
</ul>

<h2 id="xi-links-to-other-websites">XI. Links to Other Websites</h2>

<p>Our services may contain links to other websites that are not operated by us. If you click on a third-party link, you will be directed to that third-party website. We strongly recommend that you review the privacy policy of each website you visit. We have no control over and are not responsible for the content, privacy policies, or practices of any third-party websites or services.</p>

<h2 id="xii-changes-to-the-privacy-policy">XII. Changes to the Privacy Policy</h2>

<p>We may update this privacy policy from time to time. We will notify you of any changes by posting the new privacy policy on this page. Before the changes take effect, we will inform you via email and/or a prominent notice on the service and update the &ldquo;Last Updated&rdquo; date at the top of this privacy policy. We recommend that you check this privacy policy regularly to stay informed of any changes. Changes to this privacy policy will take effect when they are posted on this page.</p>

<h2 id="xiii-contact-us">XIII. Contact Us</h2>

<p>If you have any questions about this privacy policy, you can contact us in the following way: support: contact@[fupeng.li.dev@gmail.com]</p>

<hr />

<h2 id="一-引言">一、引言</h2>

<p>本隐私政策由[李二花]（以下简称“我们”）制定，旨在向您说明当您使用我们开发的 Chrome 扩展程序 String Formatter 时，我们如何收集、使用、共享、存储、保护及披露您的个人信息或使用信息。您使用本扩展程序即表示您同意接受本隐私政策的约束。若您不接受本隐私政策的条款，请停止以任何方式访问或使用本应用程序。我们强烈建议您在使用本应用程序进行任何操作之前仔细阅读本政策。</p>

<h2 id="二-信息收集">二、信息收集</h2>

<ol>
<li><strong>目的概述</strong>
我们收集您的信息主要用于以下一般目的：为了注册及管理您的账户，以便于您访问和使用我们的服务；与您进行一般性沟通，包括向您提供关于我们的信息；使我们能够发布您的评论、论坛帖子及其他内容；回应您的问题和评论；防止潜在的违禁或非法活动；以及执行我们的使用条款。</li>
<li><strong>具体信息收集</strong>

<ul>
<li><strong>技术信息</strong>：当您使用我们的服务时，我们会收集您用于访问服务的计算机的 IP 地址、移动设备 ID（由制造商分配的唯一标识符），以及您的计算机或移动设备的技术细节（如设备类型、网络浏览器和操作系统）。这些数据有助于我们提升软件在您设备上的性能，并解决可能出现的任何问题。</li>
<li><strong>内容特征</strong>：您在使用服务过程中输入的文本、上传的文件以及提供的反馈（“内容”），这些信息对于“历史记录”功能的有效运行至关重要，我们会进行收集。</li>
<li><strong>Cookies</strong>：若您通过计算机访问我们的移动应用程序，我们可能会在您的计算机上放置“Cookies”以识别您的设备。“Cookies”是我们传输到您的计算机或移动设备上的标识符，它使我们能够识别您的浏览器或移动设备，并了解我们服务中的页面和功能被访问的方式、时间以及访问人数。您可以更改浏览器或移动设备的设置，以阻止或限制计算机或设备接受 Cookies，但这可能会使您无法使用我们的某些功能。若您点击指向第三方网站的链接，该第三方也可能向您传输 Cookies。您特此同意本隐私政策不涵盖任何第三方对 Cookies 的使用。</li>
</ul></li>
</ol>

<h2 id="三-个人数据收集与使用">三、个人数据收集与使用</h2>

<ol>
<li><strong>个人数据定义</strong>：在您使用我们的服务期间，我们可能会要求您提供某些可用于联系或识别您的个人身份信息，包括但不限于电子邮件地址、姓名等。</li>
<li><strong>使用方式</strong>：

<ul>
<li><strong>提供和维护服务</strong>：包括监控服务的使用情况，以确保服务的稳定运行，并根据使用数据进行优化改进。</li>
<li><strong>管理账户</strong>：处理您作为服务用户的注册信息，您所提供的个人数据将使您能够访问作为注册用户可使用的不同功能。</li>
<li><strong>履行合同</strong>：针对您通过服务购买的产品、物品或服务，处理与之相关的购买合同的开发、合规及执行事宜，或处理与我们之间的任何其他合同事务。</li>
<li><strong>联系您</strong>：通过电子邮件或其他等效的电子通信形式（如移动应用程序的推送通知）与您联系，向您提供有关功能更新、产品或签约服务的信息通讯，包括必要或合理的安全更新。</li>
<li><strong>提供资讯</strong>：向您提供与您已购买或询问过的商品、服务和活动类似的新闻、特别优惠及一般信息，除非您选择不接收此类信息。</li>
<li><strong>处理请求</strong>：响应并处理您向我们提出的请求。</li>
<li><strong>定向广告投放</strong>：我们可能会使用您的信息来开发和展示贴合您兴趣及/或位置的内容与广告（并与第三方供应商合作），并衡量其有效性。</li>
<li><strong>其他目的</strong>：例如进行数据分析、识别使用趋势、确定促销活动的有效性，以及评估和改进我们的服务、产品、营销方式及您的使用体验。</li>
</ul></li>
</ol>

<h2 id="四-信息共享">四、信息共享</h2>

<ol>
<li><strong>第三方供应商</strong>：我们聘请第三方供应商代表我们提供各种服务，如商业分析、客户服务、营销、分发、支付处理、在线聊天等。我们可能授权这些供应商代表我们收集信息，以便操作应用程序的功能或提供满足您需求的服务。我们确保第三方供应商仅将此类信息用于履行其职责，且不允许他们将该信息用于任何其他目的。</li>
<li><strong>公司集团内部</strong>：我们可能需要向母公司、子公司或公司关联方提供您的信息。在这些关联方拥有您的信息时，他们将遵循本隐私政策中所述的最佳实践来使用这些信息。</li>
<li><strong>商业合作伙伴</strong>：在我们与商业合作伙伴共同为您提供服务的过程中，如果您选择访问由这些合作伙伴提供的可选服务，我们可能会与他们共享您的信息，包括您的个人信息。请注意，我们无法控制这些第三方商业合作伙伴的隐私实践。</li>
<li><strong>用户资料与提交内容</strong>：某些用户资料信息，包括但不限于用户名、位置，以及用户上传到服务中的任何视频或图像内容，可能会展示给其他用户，以促进服务内的用户互动或响应您对公司服务的请求。您上传到公共用户资料中的任何内容，以及您以其他用户可见的方式在线自愿披露的任何个人信息或内容（如在讨论板、消息和聊天区域等）将变为公开可用，他人可收集和使用。当您通过服务发送消息、评论或上传图像、视频时，您的用户名也可能展示给其他用户，其他用户可通过消息和评论与您联系。同样，我们无法控制可能与我们的服务交互的任何其他第三方网站或服务的政策与实践。</li>
<li><strong>关联网站</strong>：如果您是从另一个网站被引荐至我们这里，我们可能需要共享与注册信息相关的内容，包括但不限于姓名、电子邮件地址、电话号码等。在这种情况下，我们建议您阅读并查看引荐您的网站的隐私政策。我们不对他们处理此类信息的方式负责。</li>
<li><strong>业务转让</strong>：若我们进行资产买卖，客户信息通常是可能被转让的业务资产之一。此外，如果我们（或我们的资产）被收购、停业、破产或经历其他控制权变更，个人信息将作为转让给第三方或被第三方收购的资产之一。</li>
<li><strong>政府机构</strong>：在收到传票、法院命令、政府要求时，或为遵守保护我们利益的任何法律要求，我们可能会披露您的个人信息和使用信息。在此情况下，我们将通过电子邮件与您联系。我们发送至该电子邮件地址的所有通信应被视为已传达给您。</li>
</ol>

<h2 id="五-个人数据保留">五、个人数据保留</h2>

<p>我们仅在本隐私政策所述目的所需的期限内保留您的个人数据。我们将在必要范围内保留和使用您的个人数据，以遵守法律义务（例如，若法律要求我们保留数据）、解决争议以及执行法律协议和政策。</p>

<h2 id="六-信息保护">六、信息保护</h2>

<p>我们致力于确保您的信息安全可靠，遵循普遍接受的标准来保护提交给我们的个人信息和使用信息。尽管没有服务能够保证绝对安全，但我们设有适当的行政、技术和安全程序，以确保您的信息完整、安全且保密。您的信息仅由授权员工、代理或第三方供应商等出于所需目的进行处理，我们采用适当的防火墙、加密技术和入侵检测系统，防止您的信息被未经授权使用。</p>

<h2 id="七-境外使用服务">七、境外使用服务</h2>

<p>如果您在境外访问我们的应用程序，请注意，此类信息可能会传输、存储或处理在中国，即我们的服务器或中央数据库所在地。即使您从国外访问，我们也确保遵循最佳实践来保护您的信息。使用我们的服务即表示您了解我们受中国隐私和数据保护法律管辖，该法律与您所在国家的法律可能存在差异。我们将采取一切合理必要的步骤，确保您的数据得到安全处理，并符合本隐私政策，除非有足够的管控措施（包括确保您的数据及其他个人信息的安全），否则不会将您的个人数据转移至其他组织或国家。</p>

<h2 id="八-电子邮件营销">八、电子邮件营销</h2>

<p>我们可能会使用您的个人数据向您发送时事通讯、营销或促销材料以及其他您可能感兴趣的信息。您可以通过点击我们发送的任何电子邮件中的退订链接或按照指示操作，或直接联系我们，选择退出接收此类通信。</p>

<h2 id="九-支付">九、支付</h2>

<p>我们可能使用第三方服务（如 FastSpring 等支付处理器）进行支付处理。我们不会存储或收集您的支付卡详细信息，该信息将直接提供给我们的第三方支付处理器，其对您个人信息的使用受其隐私政策管辖。这些支付处理器遵循由 PCI 安全标准委员会管理的 PCI-DSS 标准，该委员会是由 Visa、Mastercard、American Express 和 Discover 等品牌共同努力成立的，PCI-DSS 要求有助于确保支付信息的安全处理。FastSpring 的隐私政策可查看：<a href="https://fastspring.com/privacy/" rel="noreferrer" target="_blank">https://fastspring.com/privacy/</a></p>

<h2 id="十-与法规相关">十、与法规相关</h2>

<ol>
<li><strong>《通用数据保护条例》（GDPR）</strong>

<ul>
<li><strong>处理个人数据的法律依据</strong>：我们可能在以下条件下处理个人数据：

<ul>
<li><strong>同意</strong>：您已同意我们出于一个或多个特定目的处理您的个人数据。</li>
<li><strong>履行合同</strong>：提供个人数据是履行与您的协议及/或任何合同前义务所必需的。</li>
<li><strong>法律义务</strong>：处理个人数据是公司遵守法律义务所必需的。</li>
<li><strong>重大利益</strong>：为保护您或其他自然人的重大利益而有必要处理个人数据。</li>
<li><strong>公共利益</strong>：处理个人数据与为公共利益执行的任务或公司行使的官方权力相关。</li>
<li><strong>合法利益</strong>：处理个人数据是为了追求公司的合法利益。</li>
<li>在任何情况下，公司将乐于协助阐明适用于处理的具体法律依据，特别是提供个人数据是法定要求还是合同要求，或是订立合同所必需的要求。</li>
</ul></li>
<li><strong>您在 GDPR 下的权利</strong>：公司承诺尊重您个人数据的保密性，并确保您能够行使您的权利。如果您在欧盟境内，根据本隐私政策及法律，您有权：

<ul>
<li><strong>访问个人数据</strong>：您有权访问、更新或删除我们持有的关于您的信息。只要可行，您可以在账户设置部分直接访问、更新或请求删除您的个人数据。如果您无法自行执行这些操作，请联系我们寻求协助，这也使您能够收到我们持有的关于您的个人数据的副本。</li>
<li><strong>更正个人数据</strong>：您有权要求我们更正我们持有的关于您的任何不完整或不准确的信息。</li>
<li><strong>反对处理个人数据</strong>：当我们依据合法利益作为处理您个人数据的法律依据，而您的特定情况使您想要基于此理由反对我们处理您的个人数据时，您拥有此项权利。此外，当我们为直接营销目的处理您的个人数据时，您也有权反对。</li>
<li><strong>请求删除个人数据</strong>：当我们没有充分理由继续处理您的个人数据时，您有权要求我们删除或移除这些数据。</li>
<li><strong>请求转移个人数据</strong>：我们将向您或您选择的第三方，以结构化、常用且机器可读的格式提供您的个人数据。请注意，此项权利仅适用于您最初同意我们使用的自动化信息，或我们使用该信息与您履行合同的情况。</li>
<li><strong>撤回同意</strong>：您有权撤回对使用您个人数据的同意。如果您撤回同意，我们可能无法为您提供访问服务的某些特定功能。</li>
</ul></li>
</ul></li>
</ol>

<h2 id="十一-其他网站链接">十一、其他网站链接</h2>

<p>我们的服务可能包含指向非我们运营的其他网站的链接。如果您点击第三方链接，将被导向该第三方网站。我们强烈建议您查看您访问的每个网站的隐私政策。我们对任何第三方网站或服务的内容、隐私政策或实践均无法控制，也不承担任何责任。</p>

<h2 id="十二-隐私政策变更">十二、隐私政策变更</h2>

<p>我们可能会不时更新本隐私政策。我们将通过在本页面发布新的隐私政策通知您任何变更。在变更生效之前，我们将通过电子邮件和/或在服务上的显著通知告知您，并更新本隐私政策顶部的“上次更新”日期。建议您定期查看本隐私政策以了解任何变更。本隐私政策的变更在发布于本页面时即生效。</p>

<h2 id="十三-联系我们">十三、联系我们</h2>

<p>如果您对本隐私政策有任何疑问，可以通过以下方式联系我们：support: contact@[fupeng.li.dev@gmail.com]</p>

        ]]>
      </description>
    </item>
    
    <item>
      <title>学术论文写作指南：理工科论文写作实践</title>
      <link>https://blog.lierhua.top/tech/%E5%A6%82%E4%BD%95%E5%86%99%E5%A5%BD%E4%B8%80%E7%AF%87%E8%8B%B1%E6%96%87%E8%AE%BA%E6%96%87/</link>
      <pubDate>Fri, 01 Nov 2024 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/%E5%A6%82%E4%BD%95%E5%86%99%E5%A5%BD%E4%B8%80%E7%AF%87%E8%8B%B1%E6%96%87%E8%AE%BA%E6%96%87/</guid>
      <description>
        <![CDATA[
        

<h2 id="摘要">摘要</h2>

<p>学术论文写作是研究者传播科学发现和学术成果的关键途径。本文旨在为理工科研究者提供一个系统性、实践性的学术论文写作指南。通过梳理《Academic Phrasebank》和《Science Research Writing: A Guide for Non-Native Speakers of English》等权威资源，本文将从结构、语言和逻辑三个维度，详细阐述如何撰写一篇高质量的学术论文。</p>

<h2 id="1-引言-论文写作的战略意义">1. 引言：论文写作的战略意义</h2>

<p>学术论文不仅仅是知识的记录，更是研究者进行学术对话的重要媒介。对于理工科研究者而言，一篇优秀的论文应当具备以下特征：</p>

<ol>
<li><strong>清晰的逻辑结构</strong>：从整体框架到局部细节，保持严密的逻辑性。</li>
<li><strong>精准的学术语言</strong>：使用专业、客观且准确的表达方式。</li>
<li><strong>创新性见解</strong>：在已有研究基础上提供原创性的观点或发现。</li>
</ol>

<h2 id="2-论文结构-从框架到内容">2. 论文结构：从框架到内容</h2>

<h3 id="2-1-标题设计">2.1 标题设计</h3>

<p>标题是论文的&rdquo;名片&rdquo;，应当：
- 简洁明了
- 准确反映研究核心
- 使用关键技术词汇
- 避免使用缩写</p>

<p><strong>反例</strong>：
&ldquo;关于某系统的研究&rdquo;</p>

<p><strong>正例</strong>：
&ldquo;基于机器学习的复杂工业系统故障预测模型&rdquo;</p>

<h3 id="2-2-摘要撰写">2.2 摘要撰写</h3>

<p>摘要是论文的缩略版，通常遵循&rdquo;背景-目的-方法-结果-结论&rdquo;的结构。</p>

<p><strong>推荐句式</strong>：
- &ldquo;本研究旨在调查/探索/分析&hellip;&rdquo;
- &ldquo;通过使用X方法，我们首次验证了&hellip;&rdquo;
- &ldquo;研究结果表明&hellip;&rdquo;</p>

<h3 id="2-3-引言部分">2.3 引言部分</h3>

<p>引言是连接已有研究与当前研究的桥梁。常用表达包括：</p>

<ul>
<li>&ldquo;尽管已有大量研究关注了X，但鲜有文献&hellip;&rdquo;</li>
<li>&ldquo;现有研究存在以下局限性&hellip;&rdquo;</li>
<li>&ldquo;为了填补这一研究空白，本文提出&hellip;&rdquo;</li>
</ul>

<h3 id="2-4-方法部分">2.4 方法部分</h3>

<p>方法部分需要高度的技术精确性。建议：
- 使用被动语态
- 采用过去时态
- 详细描述实验设计、数据收集和分析过程</p>

<p><strong>示例</strong>：
&ldquo;采用改进的随机森林算法，我们构建了&hellip;&rdquo;
&ldquo;数据通过标准化预处理，随后使用交叉验证&hellip;&rdquo;</p>

<h3 id="2-5-结果部分">2.5 结果部分</h3>

<p>结果应当：
- 客观呈现数据
- 使用统计学语言
- 配合图表说明</p>

<p><strong>推荐表达</strong>：
- &ldquo;实验数据显著表明&hellip;&rdquo;
- &ldquo;如图X所示，相关性达到&hellip;&rdquo;</p>

<h3 id="2-6-讨论部分">2.6 讨论部分</h3>

<p>讨论是展现学术批判性思维的关键。应：
- 解释结果意义
- 对比已有研究
- 阐述局限性
- 提出未来研究方向</p>

<p><strong>常用句式</strong>：
- &ldquo;与prior研究相比，我们的发现表明&hellip;&rdquo;
- &ldquo;这一结果可能源于&hellip;&rdquo;
- &ldquo;未来研究可以进一步探索&hellip;&rdquo;</p>

<h2 id="3-学术写作的语言艺术">3. 学术写作的语言艺术</h2>

<h3 id="3-1-语言风格">3.1 语言风格</h3>

<ul>
<li>避免主观语气</li>
<li>使用客观、正式的表达</li>
<li>注意时态一致性</li>
</ul>

<h3 id="3-2-常见表达技巧">3.2 常见表达技巧</h3>

<ul>
<li>使用被动语态增加客观性</li>
<li>选择精确的动词</li>
<li>控制句子长度</li>
</ul>

<h2 id="4-引用与参考文献">4. 引用与参考文献</h2>

<ul>
<li>遵循领域标准引用格式</li>
<li>引用最新、最相关的文献</li>
<li>准确标注引用来源</li>
</ul>

<h2 id="5-结论">5. 结论</h2>

<p>高质量的学术论文是系统性思维、严谨逻辑和精准语言的完美结合。通过对结构、语言和内容的精心打磨，研究者可以有效传播学术发现。</p>

<p><strong>关键建议</strong>：
1. 反复推敲和修改
2. 寻求同行评审
3. 保持开放和批判性思维</p>

<h2 id="参考文献">参考文献</h2>

<ol>
<li><a href="https://www.phrasebank.manchester.ac.uk/" rel="noreferrer" target="_blank">phrasebank website</a></li>
<li><a href="/file/academic-phrasebank.zip">Manchester Academic Phrasebank</a></li>
<li><a href="/file/Science-Research-Writing-A-Guide-for-Non-Native-Speakers-of-English.pdf">Science Research Writing: A Guide for Non-Native Speakers of English</a></li>
<li>Day, R. A., &amp; Gastel, B. (2006). How to Write and Publish a Scientific Paper.</li>
</ol>

        ]]>
      </description>
    </item>
    
    <item>
      <title>绿联 NAS 安装 TeslaMate</title>
      <link>https://blog.lierhua.top/tech/%E7%BB%BF%E8%81%94nas%E5%AE%89%E8%A3%85teslamate/</link>
      <pubDate>Fri, 24 May 2024 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/%E7%BB%BF%E8%81%94nas%E5%AE%89%E8%A3%85teslamate/</guid>
      <description>
        <![CDATA[
        

<h2 id="背景">背景</h2>

<p>昨天看了一篇少数派的文章，<a href="https://sspai.com/post/80222" rel="noreferrer" target="_blank">特斯拉 Tesla model Y 提车指南</a>, 准备事项里有一项是提前安装好 TeslaMate,
我本来是准备提车之后再说的，但是经过了解后发现，部署好 TeslaMate 之前的数据是无法回补的，所以就需要提前把服务部署好。</p>

<p>随便在 YouTube 上刷了刷，很多博主介绍自己的经验，TuTu 生活志讲了她使用 OrangePi 部署的方法，还有博主讲到部署到自己 VPS 的，
具体的部署流程大同小异，只不过有些是为了给没有 Linux 使用基础的非程序员群体降低使用门槛做了很好的一键傻瓜部署方案，
但是核心都是基于 TeslaMate 的文档来的。</p>

<p>下面就记录下我在我的绿联 DH2600 上部署 TeslaMate 的流程, 跟在 Linux 机器不一样的点是绿联的机器是 OpenWrt 系统的，加上绿联自己的一些魔改，
因此前面的步骤会有一些特殊的地方。</p>

<h2 id="机器">机器</h2>

<p>绿联 NAS 系统是 OpenWrt(OpenWrt 项目是一个针对嵌入式设备的 Linux 操作系统), 绿联没有直接开放 sshd, 需要在界面上打开，并且每次时限是 3 天。</p>

<p><img src="/images/tech/teslamate/lvlian-sshd-ui.png" alt="" /></p>

<p>打开之后, 会给到一个 secret key, 然后使用如下命令登录机器</p>

<pre><code class="language-base">ssh root@youip -P 922
</code></pre>

<h2 id="安装-docker-compose">安装 docker-compose</h2>

<p>Docker 界面</p>

<p><img src="/images/tech/teslamate/lvlian-docker-ui.png" alt="" /></p>

<p>因为机器上已经有 Docker 了，因此只需要再安装 <code>docker-compose</code> 就好，执行如下命令之一，注意替换为对应的版本号。</p>

<pre><code class="language-base">curl -L &quot;https://github.com/docker/compose/releases/download/{版本号}/docker-compose-$(uname -s)-$(uname -m)&quot; -o /usr/bin/docker-compose
</code></pre>

<pre><code class="language-base">如果下载缓慢，可以在本地机器下载好，然后复制到绿联上。

去 https://github.com/docker/compose/releases 下载对应的 linux_x86-64 版本的 docker-compose

然后使用 scp 复制到机器里

scp -P 922 docker-compose(下载的二进制文件) root@ip:/tmp/

这样就把下载的二进制文件复制到了目标机器的 /tmp/ 文件下
然后把他移动到 /usr/bin/ 下，然后增加可执行权限即可

chmod +x /usr/bin/docker-compose
</code></pre>

<h2 id="部署-teslamate">部署 TeslaMate</h2>

<p>首先在绿联上找一个位置，创建一个 <code>teslamate</code> 的文件夹，我们之后所有的数据等都在这个目录中。</p>

<p><img src="/images/tech/teslamate/lvlian-teslamate-d.png" alt="teslamate.png" /></p>

<p>然后在命令行界面，使用如下命令找到这个目录所在的位置</p>

<pre><code class="language-bash">command: find / -name teslamate
result: /mnt/dm-0/.ugreen_nas/197515/teslamate 
</code></pre>

<p>然后在这个目录下创建一个 docker-compose.yml, 注意修改里面的 key 相关的变量。</p>

<pre><code class="language-yml">services:
  teslamate:
    image: teslamate/teslamate:latest
    restart: always
    environment:
      - ENCRYPTION_KEY=ENCRYPTION_KEY #replace with a secure key to encrypt your Tesla API tokens
      - DATABASE_USER=teslamate
      - DATABASE_PASS=DATABASE_PASS #insert your secure database password!
      - DATABASE_NAME=teslamate
      - DATABASE_HOST=database
      - MQTT_HOST=mosquitto
    ports:
      - 4000:4000
    volumes:
      - ./import:/opt/app/import
    cap_drop:
      - all

  database:
    image: postgres:15
    restart: always
    environment:
      - POSTGRES_USER=teslamate
      - POSTGRES_PASSWORD=DATABASE_PASS #insert your secure database password!
      - POSTGRES_DB=teslamate
    volumes:
      - teslamate-db:/var/lib/postgresql/data

  grafana:
    image: teslamate/grafana:latest
    restart: always
    environment:
      - DATABASE_USER=teslamate
      - DATABASE_PASS=DATABASE_PASS #insert your secure database password!
      - DATABASE_NAME=teslamate
      - DATABASE_HOST=database
    ports:
      - 3000:3000
    volumes:
      - teslamate-grafana-data:/var/lib/grafana

  mosquitto:
    image: eclipse-mosquitto:2
    restart: always
    command: mosquitto -c /mosquitto-no-auth.conf
    # ports:
    #   - 1883:1883
    volumes:
      - mosquitto-conf:/mosquitto/config
      - mosquitto-data:/mosquitto/data

volumes:
  teslamate-db:
  teslamate-grafana-data:
  mosquitto-conf:
  mosquitto-data:
</code></pre>

<p>然后 <code>docker-compose up -d</code> 启动即可。</p>

<p>启动之后，在 docker 的管理界面会有如下的显示</p>

<p><img src="/images/tech/teslamate/lvlian-docker-list.png" alt="teslamate.png" /></p>

<p>启动之后，访问 <code>NasIp:3000</code> 和 <code>NasIp:4000</code> 就可以看到如下两个界面</p>

<ul>
<li>Grafana（初始用户名和密码都是 admin, 需要自己改密码）</li>
<li>TeslaMate（需要填入令牌和刷新令牌，这个可以下载对应的 app 获取，iOS 使用 auth app for tesla）</li>
</ul>

<h2 id="暴露出来">暴露出来</h2>

<p>之前一篇文章<a href="/tech/cloudflare-内网穿透与鉴权">cloudflare 内网穿透与鉴权</a>讲过如何把外网服务暴露到公网，并且加上邮箱验证的，
按照这个方案，又安装启动了一个 cloudflared, 然后把这两个端口的服务暴露到了公网环境即可。</p>

<p><img src="/images/tech/teslamate/lvlian-teslamate-ui.png" alt="teslamate.png" /></p>

<p><img src="/images/tech/teslamate/lvlian-grafana-ui.png" alt="teslamate.png" /></p>

<h2 id="其他注意">其他注意</h2>

<p>文档写了很多其他的东西，其中需要特别注意的是数据的备份与恢复，可以写一个定时脚本，定期备份数据</p>

<pre><code class="language-bash">docker compose exec -T database pg_dump -U teslamate teslamate &gt; &quot;teslamate.$(date +&quot;%Y-%m-%d&quot;).back&quot;
</code></pre>

<p>TODO: 之后还可以写一个 crontab 来执行 dairy 事项。</p>

<h2 id="结束">结束</h2>

<p>当然，鸡蛋不能放在一个篮子里，我还在我的 VPS 部署了一套，因为是标准的 Linux 环境，部署非常简单，这样主备都有，不容易出问题。</p>

<p>多看 TeslaMate 的文档，里面还有很多有意思的项目。</p>

<hr />

<ul>
<li><a href="https://blog.csdn.net/weixin_44515596/article/details/130301157" rel="noreferrer" target="_blank">一个绿联 NAS 的 docker-compose 方案</a></li>
<li><a href="https://docs.teslamate.org/docs/installation/docker/" rel="noreferrer" target="_blank">TeslaMate docs</a></li>
<li><a href="https://www.youtube.com/watch?v=taOtmhADvk4" rel="noreferrer" target="_blank">备份与恢复的视频地址</a></li>
<li><a href="https://github.com/carloscuezva/teslamate-maintenance" rel="noreferrer" target="_blank">备份与恢复的的github脚本</a></li>
</ul>

        ]]>
      </description>
    </item>
    
    <item>
      <title>tailscale 组网</title>
      <link>https://blog.lierhua.top/tech/tailscale/</link>
      <pubDate>Fri, 15 Mar 2024 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/tailscale/</guid>
      <description>
        <![CDATA[
        <p>前几天跟着一个小 case 把 cloudflare 的一些实用的使用方案介绍了一下，今天顺便介绍下 tailscale 的功能也我的应用。</p>

<p>Tailscale 是一种虚拟专用网络（VPN）服务，它通过轻量级的软件实现安全的网络连接。它的作用是让用户能够安全、快速地连接多个设备，形成一个私密的网络，即使这些设备位于不同的地理位置或网络环境下也可以实现。Tailscale 提供了简洁的用户界面和易于使用的工具，使用户能够轻松地管理和连接他们的设备，而无需复杂的配置和管理。它被广泛用于远程办公、远程访问、家庭网络和企业网络等场景，为用户提供了安全、方便的网络连接解决方案。(来自 Chatgpt)</p>

<p>简单来讲，在你想要组成一个内部私密网络的机器上，根据不同的平台安装好对应的 tailscale 应用，然后登录自己的账号即可完成自己的组网要求。</p>

<p>我目前是将一台公网腾讯云机器，一台公网阿里云机器，一台家庭内网 NAS，还有我的日用 Mac 电脑以及我的 iphone 共同组成了一个子网，同一个子网内的所有机器都是可以使用内网域名访问的。</p>

<p><img src="/images/tech/tailscale/machines.png" alt="tailscale machines" /></p>

<p>其他平台的安装都比较简单，但是我的 NAS 只支持 docker 容器，安装就要特别注意下，记录下这个安装的流程。</p>

<p>ssh + exited-node</p>

<hr />

<p>推荐文章:</p>

<ul>
<li><a href="https://arthurchiao.art/blog/how-nat-traversal-works-zh/" rel="noreferrer" target="_blank">NAT穿透是如何工作的: 推荐阅读</a></li>
<li><a href="https://www.youtube.com/watch?v=sPdvyR7bLqI" rel="noreferrer" target="_blank">How to get started with Tailscale in under 10 minutes</a></li>
<li><a href="https://www.zhihu.com/tardis/zm/art/599273678?source_id=1003" rel="noreferrer" target="_blank">绿联安装tailscale</a></li>
</ul>

        ]]>
      </description>
    </item>
    
    <item>
      <title>cloudflare 内网穿透与鉴权</title>
      <link>https://blog.lierhua.top/tech/cloudflare-%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F%E4%B8%8E%E9%89%B4%E6%9D%83/</link>
      <pubDate>Thu, 14 Mar 2024 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/cloudflare-%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F%E4%B8%8E%E9%89%B4%E6%9D%83/</guid>
      <description>
        <![CDATA[
        

<ul>
<li>背景</li>
<li>方案</li>
<li>实践</li>
</ul>

<h2 id="背景">背景</h2>





<div class="hugo-encryptor-container">
  <div class="hugo-encryptor-prompt">
    
      <p>文章的部分内容被密码保护：</p>
    
  </div>
  <div class="hugo-encryptor-form">
    <input
      class="hugo-encryptor-input"
      placeholder='请输入密码'
    />
    <input
      class="hugo-encryptor-button"
      type="button"
      value='点击验证'
      onclick="_click_handler(this)"
    />
  </div>
  <div
    class="hugo-encryptor-cipher-text"
    data-password="lierhua1026"
    style="display: none;"
  >
    <span style="display: none;">--- DON'T MODIFY THIS LINE ---</span>
    <p>最近运营团队给我们提了个小需求，想让我们给部署一个 GPT-4 的会话服务来帮助运营人员来输出更多的想法，辅助进行产品洞察。因为公司内部的生成式对话服务是基于 GPT-3.5 的，并且接入的是钉钉，不满足他们基于 GPT-4 并且需要一个集成了 prompt 的需求。</p>

<p>在与团队深入沟通后，我们发现某些开源产品已经能够满足我们的需求。最初，我们担心可能会遇到合规性和安全性问题，但经过与安全团队的详细讨论，确认这些问题都是可以解决的。此外，考虑到公司目前H5开发资源较为紧张，若自行开发，时间和人力成本都相对较高。因此，综合评估后，我们决定采用 ChatGPT-Next-Web 这款开源产品。它不仅支持 Azure API，还提供了丰富的prompt库，能够很好地满足我们的业务需求。</p>

<blockquote>
<p>原始段落: 在与团队深入沟通后，我们发现某些开源产品已经能够满足我们的需求。最初，我们担心可能会遇到合规性和安全性问题，但经过与安全团队的详细讨论，确认这些问题都是可以解决的。此外，考虑到公司目前H5开发资源较为紧张，若自行开发，时间和人力成本都相对较高。因此，综合评估后，我们决定采用 ChatGPT-Next-Web 这款开源产品。它不仅支持 Azure API，还提供了丰富的prompt库，能够很好地满足我们的业务需求。(能看出来经过润色后确实会好不少)</p>
</blockquote>

<h2 id="方案设计">方案设计</h2>

<p>当时讨论的方案有</p>

<ul>
<li>部署到公网环境的 VPS;

<ul>
<li>优点: 只需要一台 AWS 机器, 操作自由方便，随时开发随时部署</li>
<li>缺点: 需要管理额外的鉴权；申请的 Azure API 有白名单，需要专门找 IT 添加；安全问题无法监管</li>
</ul></li>
<li>部署到公司服务的正式环境;

<ul>
<li>优点：公司 SRE 统一管理，网络这种问题不需要自己操心, 鉴权问题不用操心</li>
<li>缺点：需要在公司平台维护一个单独的服务，上线审批等各种需要走正式流程</li>
</ul></li>
<li>部署到公司的 staging 环境;

<ul>
<li>优点: 部署方便，有单独的内网域名，鉴权走公司;</li>
<li>缺点：也需要公司平台维护单独的服务</li>
</ul></li>
<li>部署到办公网络环境;

<ul>
<li>优点：部署方便；可以有单独的内网域名，走公司鉴权；可以给单独申请的用户开外网权限</li>
<li>缺点: 需要申请一台普通物理机</li>
</ul></li>
</ul>

<p>最后本着方便和安全兼顾的原则，申请了一台 macmini 物理机，部署到办公网络环境，机器之后还可以作为一个公共资源的机器使用。</p>

<h2 id="实践">实践</h2>

<p>具体落实到实践就简单了，就是跑一个容器就可以。</p>

  </div>
</div>


<h2 id="引申">引申</h2>

<p>重点是想通过这件小事儿把我之前使用过的很多 cloudflare 的功能做个记录。特别是这两个，一个是 cloudflare tunnel 用于内网穿透，再一个是 cloudflare zero trust 用于用户鉴权。下面我们不谈原理，就简单说一说这个功能的具体用法。</p>

<h3 id="内网穿透">内网穿透</h3>

<p>假如现在你在家里有一台机器 A 在运行某个程序，但是家里没有固定的公网 IP，现在你去外地玩，你手头有一个电脑 B 想访问下家里这个程序，因为都没有公网 IP，所以理论上，如果你想访问，就要通过一个有公网 IP 的第三方 C 来实现，这个就是我们之前介绍的 <a href="/tech/ubuntu/5.-ubuntu-下-frp-内网穿透/">frp</a> 的功能，前提是需要你有一台公网机器。</p>

<p>但是拥有一台公网机器是需要成本的，维护成本，费用成本等，在没有这种条件下，我们有什么办法呢，这就要提到 cloudflare tunnel 了（tailscale 的 funnel) 同样的功能。</p>

<p>工作的基本原理：Tunnel 通过在本地网络运行的一个 Cloudflare 守护程序，与 Cloudflare 云端通信，将云端请求数据转发到本地网络的 IP + 端口。</p>

<p>具体的开通流程很简单，可以参考相关文章，后续的配置也十分简单，看下面几张图片就可以完成。</p>

<p>这个是你现有的 tunnel 的列表，记录了内网穿透的服务，可以进行重新修改和配置
<img src="/images/tech/cloudflare-auth/tunnel-scale.png" alt="内网穿透界面列表" /></p>

<p>选择 cloudflared 这个方案
<img src="/images/tech/cloudflare-auth/cloudflared.png" alt="cloudflared" /></p>

<p>设置一个项目的名字
<img src="/images/tech/cloudflare-auth/tunnel-name.png" alt="设置项目名字" /></p>

<p>选择 cloudflared 服务要部署的平台, 特别注意如果选择 docker 的话，需要在他提供的命令的基础上，加上一个 &ndash;network=host
<img src="/images/tech/cloudflare-auth/tunnel-cloudflared.png" alt="docker 部署 cloudflared" /></p>

<pre><code class="language-bash">docker run --network=&quot;host&quot;  cloudflare/cloudflared:latest tunnel --no-autoupdate run --token eyJhIjoiNWU4MnFmMzUwMGJlZmZjMWFlMGE5WWFkZThhNDY5NmYiLCJ0IjoiMjg3ZmU2MmYtMjE1Zi00YJkyLWIyZWEtZWY1ODExM2ZmZmQ2IiwicyI6IllXTTFZbUZoTmpjdFpHTXlNeTAwWVRZeExUaGpNVGt1TW1GbFpUaGxZV0kyWmpneCJ9
</code></pre>

<p>当 cloudflared 成功运行后，在connetors 会显示一个会话ID
<img src="/images/tech/cloudflare-auth/tunnel-connector.png" alt="connector" /></p>

<p>配置对应的路由和公网域名</p>

<p><img src="/images/tech/cloudflare-auth/tunnel-serve.png" alt="route tunnel" /></p>

<p>这个是个子网域名的例子</p>

<p><img src="/images/tech/cloudflare-auth/tunnel-inner-web.png" alt="inner-web" /></p>

<p>到此为止，我们的服务已经可以在公网访问了。</p>

<h3 id="权限限制">权限限制</h3>

<p>此时，如果你不想你的服务被其他人访问，而是要经过一个鉴权，只需要按照如下的步骤，就可以完成一个最简单的授权操作了。</p>

<p>首先进入 zere Trust 的界面
<img src="/images/tech/cloudflare-auth/auth-first.png" alt="zero turst" /></p>

<p>看到的是我已经配置了鉴权的服务
<img src="/images/tech/cloudflare-auth/auth-second.png" alt="zero trust list" /></p>

<p>点击 add an application 添加一个项目, 一般自建的项目就选 self-hosted
<img src="/images/tech/cloudflare-auth/auth-third.png" alt="self hosted" /></p>

<p>填写基础配置，比如被鉴权的域名
<img src="/images/tech/cloudflare-auth/auth-fourth.png" alt="config application" /></p>

<p>设置权限策略
<img src="/images/tech/cloudflare-auth/auth-fifth.png" alt="add policy" /></p>

<p>剩下的步骤按照默认的配置来，或者以后有其他需求再去看对应的处理方案</p>

<p>访问 justest.greatsnow.win 这个地址，跳转到对应的登录界面<br />
<img src="/images/tech/cloudflare-auth/auth-sixth.png" alt="justest.greatsnow.win" /></p>

<p>填写我的在策略那里设置好的唯一一个被允许访问的 email 地址
<img src="/images/tech/cloudflare-auth/auth-seventh.png" alt="justest.greatsnow.win" /></p>

<p>然后就跳转到对应的验证码界面
<img src="/images/tech/cloudflare-auth/auth-eighth.png" alt="justest.greatsnow.win" /></p>

<p>我的 <code>me@lierhua.top</code> 邮箱地址也是通过 cloudflare 的 email 功能转发到 gmail 了，因此访问 gmail 获取对应的 code
<img src="/images/tech/cloudflare-auth/auth-nineth.png" alt="justest.greatsnow.win" /></p>

<p>输入 code 访问到我的界面
<img src="/images/tech/cloudflare-auth/auth-tenth.png" alt="justest.greatsnow.win" /></p>

<p>到此我们就完成了一个本机电脑部署的 docker 容器的服务暴露到公网里的这么一个流程了。</p>

<hr />

<p>相关文章:</p>

<ul>
<li><a href="https://sspai.com/post/79278" rel="noreferrer" target="_blank">CloudFlare Tunnel 免费内网穿透的简明教程</a></li>
</ul>

        ]]>
      </description>
    </item>
    
    <item>
      <title>vercel 部署 hugo 博客</title>
      <link>https://blog.lierhua.top/tech/vercel%E9%83%A8%E7%BD%B2hugo%E5%8D%9A%E5%AE%A2/</link>
      <pubDate>Thu, 14 Mar 2024 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/vercel%E9%83%A8%E7%BD%B2hugo%E5%8D%9A%E5%AE%A2/</guid>
      <description>
        <![CDATA[
        

<p>Vercel 是一个云平台，专注于前端开发者和设计师，提供静态网站和 Serverless 函数的托管服务。</p>

<p>它支持前端框架如 Next.js（由 Vercel 团队开发）、React、Angular、Vue.js 等，使得开发者可以轻松地部署和托管他们的应用或网站。</p>

<p>Vercel 的目标是提供一个简单、快速且可扩展的部署体验，让开发者能够专注于他们的核心业务，而不是基础设施的管理。 vercel 详细介绍见页脚。</p>

<p>通俗的讲，Vercel 可以部署前端页面，同时还可以直接跟 github，gitlab 等仓库绑定，对于个人项目的部署十分方便。</p>

<h2 id="界面介绍">界面介绍</h2>

<h2 id="使用简介">使用简介</h2>

<hr />

<h3 id="vercel-的主要特点包括">Vercel 的主要特点包括：</h3>

<ul>
<li><strong>即时静态部署</strong>：Vercel 允许开发者通过 Git 集成自动部署静态网站和应用，每次 Git 推送都会自动创建一个新的生产就绪部署。</li>
<li><strong>Serverless 函数</strong>：Vercel 支持无服务器（Serverless）架构，可以让开发者编写和部署执行各种后端任务的函数，而无需管理服务器。</li>
<li><strong>自动化的性能优化</strong>：Vercel 为部署的应用自动提供性能优化，包括智能全球内容分发网络（CDN）、自动 HTTPS、HTTP/2 支持等。</li>
<li><strong>简单的域名管理</strong>：Vercel 提供域名注册和管理服务，允许开发者轻松地将自定义域名链接到他们的项目。</li>
<li><strong>开发者友好</strong>：Vercel 提供了丰富的开发工具，包括 CLI 工具、集成开发环境 (IDE) 插件等，以及与多个流行的前端框架和工具链的无缝集成。</li>
</ul>

<h3 id="使用场景">使用场景：</h3>

<ul>
<li><strong>静态网站托管</strong>：适用于博客、个人网站、营销页面等静态内容的快速部署和托管。</li>
<li><strong>单页应用（SPA）托管</strong>：为 React、Vue.js 等构建的单页应用提供高效的托管和分发服务。</li>
<li><strong>全栈应用部署</strong>：通过 Serverless 函数支持后端 API 的构建，适合需要前后端分离的全栈应用。</li>
<li><strong>动态内容和 API</strong>：利用 Serverless 函数处理表单提交、数据检索、动态内容生成等。</li>
</ul>

<p>Vercel 因其简单易用、高效可靠而受到前端开发社区的广泛欢迎。对于追求开发效率和性能的项目来说，Vercel 是一个非常值得考虑的选项。</p>

        ]]>
      </description>
    </item>
    
    <item>
      <title>Dockerhub &amp; Github 私有部署</title>
      <link>https://blog.lierhua.top/tech/dockerhub-%E7%A7%81%E6%9C%89%E9%83%A8%E7%BD%B2/</link>
      <pubDate>Mon, 15 Jan 2024 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/dockerhub-%E7%A7%81%E6%9C%89%E9%83%A8%E7%BD%B2/</guid>
      <description>
        <![CDATA[
        

<h2 id="推送镜像">推送镜像</h2>

<p>问：如何根据 dockerfile 打包镜像推送到自己的 dockerhub.</p>

<p>答：要根据 <code>Dockerfile</code> 打包镜像并推送到您自己的 Docker Hub 账户，请按照以下步骤操作：</p>

<h3 id="1-创建-dockerfile">1. 创建 Dockerfile</h3>

<p>确保您已经在项目的根目录中创建了一个 <code>Dockerfile</code>。这个文件包含了构建 Docker 镜像所需的所有指令。</p>

<h3 id="2-构建镜像">2. 构建镜像</h3>

<p>打开终端或命令提示符，切换到包含 <code>Dockerfile</code> 的目录。使用以下命令构建 Docker 镜像，其中 <code>your_image_name</code> 是您想要给镜像命名的名称，<code>tag</code> 是您给镜像指定的标签（通常用于版本控制，例如 <code>latest</code> 或 <code>v1.0</code>）：</p>

<pre><code class="language-sh">docker build -t your_dockerhub_username/your_image_name:tag .
</code></pre>

<p>请将 <code>your_dockerhub_username</code> 替换为您的 Docker Hub 用户名，<code>your_image_name</code> 替换为您想要的镜像名称，<code>tag</code> 替换为您想要的标签。</p>

<h3 id="3-登录-docker-hub">3. 登录 Docker Hub</h3>

<p>在推送镜像之前，您需要登录到 Docker Hub。在终端或命令提示符中执行以下命令，并按提示输入您的 Docker Hub 用户名和密码：</p>

<pre><code class="language-sh">docker login
</code></pre>

<h3 id="4-推送镜像到-docker-hub">4. 推送镜像到 Docker Hub</h3>

<p>登录成功后，使用以下命令将镜像推送到您的 Docker Hub 账户：</p>

<pre><code class="language-sh">docker push your_dockerhub_username/your_image_name:tag
</code></pre>

<p>确保替换 <code>your_dockerhub_username</code>、<code>your_image_name</code> 和 <code>tag</code> 为您之前构建镜像时使用的相应值。</p>

<h3 id="5-验证">5. 验证</h3>

<p>登录到您的 Docker Hub 账户，检查是否成功推送了镜像。</p>

<h3 id="注意事项">注意事项</h3>

<ul>
<li>确保您的 <code>Dockerfile</code> 没有错误，否则镜像构建过程可能会失败。</li>
<li>如果您的镜像包含敏感信息，请注意 Docker Hub 是公开的，任何人都可以拉取公开的镜像。考虑使用私有仓库或其他安全措施。</li>
<li>对于较大的镜像，推送过程可能需要较长时间，具体取决于您的网络速度和镜像大小。</li>
</ul>

<p>以上是将 Docker 镜像打包并推送到 Docker Hub 的基本步骤。希望这对您有所帮助！</p>

<h2 id="拉取部署">拉取部署</h2>

<p>问：dockerhub 私有仓库的镜像如何拉取部署</p>

<p>答：要从 Docker Hub 的私有仓库拉取镜像并部署，您需要执行以下步骤：</p>

<h3 id="1-登录-docker-hub">1. 登录 Docker Hub</h3>

<p>首先，您需要在您的机器上登录到 Docker Hub。这一步骤确保您有权限从私有仓库拉取镜像。在终端或命令提示符中执行以下命令：</p>

<pre><code class="language-sh">docker login
</code></pre>

<p>按提示输入您的 Docker Hub 用户名和密码。成功登录后，您将能够从您的私有仓库拉取镜像。</p>

<h3 id="2-拉取镜像">2. 拉取镜像</h3>

<p>登录成功后，使用以下命令从私有仓库拉取您需要的镜像：</p>

<pre><code class="language-sh">docker pull your_dockerhub_username/your_image_name:tag
</code></pre>

<p>请将 <code>your_dockerhub_username</code> 替换为您的 Docker Hub 用户名，<code>your_image_name</code> 替换为您想要拉取的镜像名称，<code>tag</code> 替换为镜像的标签（例如 <code>latest</code> 或 <code>v1.0</code>）。</p>

<h3 id="3-部署镜像">3. 部署镜像</h3>

<p>拉取镜像后，您可以使用 <code>docker run</code> 命令来运行镜像，从而部署您的应用或服务。命令格式如下：</p>

<pre><code class="language-sh">docker run [options] your_dockerhub_username/your_image_name:tag
</code></pre>

<p><code>[options]</code> 是可选的 Docker 运行参数，例如 <code>-d</code> 用于后台运行容器，<code>-p</code> 用于端口映射等。根据您的具体需求选择合适的参数。</p>

<h3 id="注意事项-1">注意事项</h3>

<ul>
<li>确保您在正确的机器上登录 Docker Hub，并有权访问目标私有仓库。</li>
<li>如果您不确定镜像的标签，可以登录 Docker Hub 网站，查看您私有仓库中的镜像以及其标签。</li>
<li>对于在生产环境中部署应用，可能需要额外的配置和参数，例如环境变量、卷挂载等，确保您在 <code>docker run</code> 命令中正确配置这些参数。</li>
</ul>

<p>通过以上步骤，您可以从 Docker Hub 的私有仓库拉取镜像并在您的机器上部署。</p>

<h2 id="github-actions-自动化">GitHub Actions 自动化</h2>

<p>我想通过 github 私有仓库里放置的一个项目的 dockerflie, 每当我提交到 main 分支时，自动的打包 dockerfile 镜像，然后推送我个人的私有 dockerhub 上，这个如何使用 action 等工具完成</p>

<p>要实现您的需求，您可以使用 GitHub Actions，这是 GitHub 提供的一个 CI/CD（持续集成/持续部署）服务，允许您在代码仓库中定义自动化的工作流程。以下是一个步骤说明和示例工作流程配置，用于实现当您向 master 分支提交代码时自动构建 Docker 镜像并推送到 DockerHub 的功能。</p>

<h3 id="前提条件">前提条件</h3>

<ol>
<li><strong>DockerHub 账号和仓库</strong>：确保您有一个 DockerHub 账号，并且在 DockerHub 上创建了一个私有仓库用于存放您的镜像。</li>
<li><strong>GitHub 仓库</strong>：确保您的项目托管在 GitHub 上，并且 Dockerfile 已经放置在项目的根目录或您指定的目录中。</li>
</ol>

<h3 id="设置步骤">设置步骤</h3>

<ol>
<li><p><strong>在 DockerHub 获取访问令牌</strong>：</p>

<ul>
<li>登录到 DockerHub，进入 <code>Account Settings</code> &gt; <code>Security</code>，创建一个新的 Access Token。记下这个 Token，您将需要它来配置 GitHub Actions。</li>
</ul></li>

<li><p><strong>在 GitHub 仓库设置 Secrets</strong>：</p>

<ul>
<li>进入您的 GitHub 仓库，选择 <code>Settings</code> &gt; <code>Secrets</code> &gt; <code>Actions</code>，点击 <code>New repository secret</code>。</li>
<li>添加以下两个 Secrets：

<ul>
<li><code>DOCKER_USERNAME</code>：您的 DockerHub 用户名。</li>
<li><code>DOCKER_PASSWORD</code>：您刚刚创建的 DockerHub Access Token。</li>
</ul></li>
</ul></li>

<li><p><strong>创建 GitHub Actions 工作流程</strong>：</p>

<ul>
<li>在您的 GitHub 仓库中，创建一个新的文件 <code>.github/workflows/docker-build.yml</code>。</li>

<li><p>将以下 YAML 配置粘贴到该文件中，并根据需要进行调整：</p>

<pre><code class="language-yaml">name: Build and Push Docker image

on:
push:
branches:
- master  # 或者 main，根据您的默认分支名称调整, 这里的 on 就是触发条件

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v2

- name: Log in to DockerHub
uses: docker/login-action@v1
with:
  username: ${{ secrets.DOCKER_USERNAME }}
  password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
  context: .  # Dockerfile 所在的目录，如果不在根目录，需要调整
  file: ./Dockerfile  # Dockerfile 的路径，根据实际情况调整
  push: true
  tags: yourusername/yourrepository:latest  # 修改为您的 DockerHub 用户名和仓库名
  platforms: linux/amd64,linux/arm64
</code></pre></li>
</ul></li>
</ol>

<h3 id="完成">完成</h3>

<p>一旦您提交了上述 GitHub Actions 的配置文件，并向 master 分支推送了代码，GitHub Actions 就会自动触发上述工作流程，构建 Docker 镜像并推送到您在 DockerHub 上配置的私有仓库中。</p>

<p>请确保替换 YAML 文件中的 <code>yourusername/yourrepository</code> 为您的 DockerHub 用户名和仓库名，以及根据您的项目结构调整 Dockerfile 的路径。</p>

<h2 id="gitlab-自动部署">Gitlab 自动部署:</h2>

<p>我想通过 gitlib 私有仓库里放置的一个项目的 dockerflie, 每当我提交到 master 分支时，自动的打包 dockerfile 镜像，然后推送我个人的私有 dockerhub 上，这个如何使用 action 等工具完成</p>

<p>要通过 GitLab 私有仓库实现您的需求，您可以使用 GitLab CI/CD，这是 GitLab 内置的持续集成、持续部署和持续交付服务。下面是如何设置 GitLab CI/CD 来自动构建 Docker 镜像并将其推送到 DockerHub 的步骤说明。</p>

<h3 id="前提条件-1">前提条件</h3>

<ol>
<li><strong>DockerHub 账号和仓库</strong>：确保您有一个 DockerHub 账号，并且在 DockerHub 上创建了一个私有仓库用于存放您的镜像。</li>
<li><strong>GitLab 仓库</strong>：确保您的项目托管在 GitLab 上，并且 Dockerfile 已经放置在项目的根目录或您指定的目录中。</li>
</ol>

<h3 id="设置步骤-1">设置步骤</h3>

<ol>
<li><p><strong>在 DockerHub 获取访问令牌</strong>：</p>

<ul>
<li>登录到 DockerHub，进入 <code>Account Settings</code> &gt; <code>Security</code>，创建一个新的 Access Token。记下这个 Token，您将需要它来配置 GitLab CI/CD。</li>
</ul></li>

<li><p><strong>在 GitLab 仓库设置 CI/CD 变量</strong>：</p>

<ul>
<li>进入您的 GitLab 仓库，选择 <code>Settings</code> &gt; <code>CI / CD</code>，展开 <code>Variables</code> 部分。</li>
<li>添加以下两个变量：

<ul>
<li><code>DOCKER_USERNAME</code>：您的 DockerHub 用户名。</li>
<li><code>DOCKER_PASSWORD</code>：您刚刚创建的 DockerHub Access Token。</li>
</ul></li>
</ul></li>

<li><p><strong>创建 GitLab CI/CD 配置文件</strong>：</p>

<ul>
<li>在您的 GitLab 仓库根目录下，创建一个 <code>.gitlab-ci.yml</code> 文件。</li>

<li><p>将以下 YAML 配置粘贴到该文件中，并根据需要进行调整：</p>

<pre><code class="language-yaml">stages:
- build

docker-build:
image: docker:latest
stage: build
services:
- docker:dind
script:
- docker login -u &quot;$DOCKER_USERNAME&quot; -p &quot;$DOCKER_PASSWORD&quot;
- docker build -t yourusername/yourrepository:$CI_COMMIT_REF_NAME .
- docker push yourusername/yourrepository:$CI_COMMIT_REF_NAME
only:
- master
</code></pre></li>
</ul></li>
</ol>

<h3 id="完成-1">完成</h3>

<p>一旦您提交了上述 GitLab CI/CD 的配置文件，并向 master 分支推送了代码，GitLab CI/CD 就会自动触发上述工作流程，构建 Docker 镜像并推送到您在 DockerHub 上配置的私有仓库中。</p>

<p>请确保替换 YAML 文件中的 <code>yourusername/yourrepository</code> 为您的 DockerHub 用户名和仓库名，以及根据您的项目结构调整 Dockerfile 的路径。<code>$CI_COMMIT_REF_NAME</code> 是 GitLab CI/CD 提供的一个环境变量，它会根据触发构建的分支或标签的名称来动态设置镜像标签，这样您就可以为每个分支或标签构建不同的镜像了。</p>

<p>这样，每次向 master 分支提交代码时，GitLab CI/CD 将自动构建 Docker 镜像并将其推送到 DockerHub。</p>

<p>例子:</p>

<pre><code class="language-shell">#!/bin/bash

# Docker 登录
# 注意：这种方式存在安全隐患，推荐使用凭证存储或其他安全方式
DOCKER_USERNAME=&quot;your docker hub name&quot;
DOCKER_PASSWORD=&quot;your docker hub password&quot;
echo $DOCKER_PASSWORD | docker login --username $DOCKER_USERNAME --password-stdin

# 拉取新的镜像
# 替换your_image_name为你的镜像名称
docker pull lierhua/next-web:latest

# 容器名称或ID，这里假设为container1和container2
CONTAINER1=&quot;container1_name&quot;
CONTAINER2=&quot;container2_name&quot;

# 停止运行中的容器
docker stop $CONTAINER1
docker stop $CONTAINER2

# 移除已停止的容器（可选）
docker rm $CONTAINER1
docker rm $CONTAINER2


# 启动新的容器，根据你的需求配置启动参数
# 替换以下参数以匹配你的配置
docker run --name $CONTAINER1 -d --restart unless-stopped -p 3001:3000 \
   lierhua/next-web:latest

docker run --name $CONTAINER2 -d --restart unless-stopped -p 3002:3000 \
   lierhua/next-web:latest

echo &quot;Containers have been restarted successfully.&quot;
</code></pre>

        ]]>
      </description>
    </item>
    
    <item>
      <title>使用 ffmpeg 复刻水印快捷方式</title>
      <link>https://blog.lierhua.top/tech/%E4%BD%BF%E7%94%A8ffmpeg%E5%A4%8D%E5%88%BB%E6%B0%B4%E5%8D%B0%E5%BF%AB%E6%8D%B7%E6%96%B9%E5%BC%8F/</link>
      <pubDate>Sun, 24 Sep 2023 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/%E4%BD%BF%E7%94%A8ffmpeg%E5%A4%8D%E5%88%BB%E6%B0%B4%E5%8D%B0%E5%BF%AB%E6%8D%B7%E6%96%B9%E5%BC%8F/</guid>
      <description>
        <![CDATA[
        

<h2 id="基本命令">基本命令</h2>

<p>使用 exiftool</p>

<pre><code class="language-shell"># 使用 homebrew 安装 exiftool  homebrew install exiftool
# 获取光圈，快门 ISO 等信息
exiftool image.jpg

# 获取 GPS 信息
exiftool -gpslatitude -gpslongitude image.jpg

# 获取 TIFF 信息
exiftool -tiff image.jpg

</code></pre>

<p>使用 ffmpeg</p>

<pre><code class="language-shell"># 获取图片的 exif 信息 
ffmpeg -i picture_name
# picture_name 指的就是图片的名字（需要后缀）

# 获取图片的光圈，焦距，ISO 等信息
ffprobe -v quiet -print_format json -show_entries stream_tags=lens,aperture,iso input.mp4

# 生成空白图片 
ffmpeg -f lavfi -i color=c=white:s=7008x5490 -frames:v 1 output.png
# white 指的是背景的颜色，可以替换为 black, red 等， 7008x5490 指的是要生成的图片的像素，output.png 是输出的文件的路径和名字

# 叠加图片和颜色块
ffmpeg -i input.jpg -filter_complex &quot;color=c=blue:s=200x200 [color]; [0:v][color] overlay=100:100&quot; output.jpg
# s=200x200 指代是色块的大小，blue 是色块的颜色，可以用 #00FF00 等来代替，100:100 表示开始叠加的位置
# 这个示例将在原始图片的位置(100,100)插入了一个蓝色的200x200大小的颜色块。
# 例子： ffmpeg -i ./result.jpg -filter_complex &quot;color=c=#545454:s=200x200 [color]; [0:v][color] overlay=100:100&quot; result_color.jpg
# 颜色还可以用 rgb(255, 0, 0) 这种方式

# 叠加图片和图片
ffmpeg -i background.png -i input.jpg -filter_complex &quot;overlay=10:10&quot; output.jpg
# background.png 指的是叠加的背景图，input.jpg 是前景图，output.jpg 是输出的图片的路径和名字

# 叠加文字
ffmpeg -i input.jpg -vf &quot;drawtext=text='your-text-input':x=100:y=5000:fontsize=24:fontcolor=white&quot; result.jpg
# input.jpg 要加文字的图片，your-text-input 要输入的文字，x,y后面的数字是放在图片的位置，fontsize 是文字大小，color 是文字颜色，result.jpg 是输出位置与名字
ffmpeg -i input.mp4 -vf &quot;drawtext=text='Your Text Here':x=100:y=100:fontsize=24:fontfile=/path/to/your/font.ttf&quot; output.mp4
# 这个例子中可以设置 fontfile 使用不同的字体

# 叠加多个文字
ffmpeg -i input.mp4 -vf &quot;drawtext=text='Text1':x=100:y=100:fontsize=24, drawtext=text='Text2':x=200:y=200:fontsize=24, drawtext=text='Text3':x=300:y=300:fontsize=24&quot; output.mp4

# 叠加图片和文字
ffmpeg -i background.jpg -i input.png -filter_complex &quot;[0:v][1:v]overlay=10:10,drawtext=text='Your Text Here':x=20:y=H-50:fontsize=24:fontcolor=white&quot; output.jpg

# 叠加图片和多个文字
ffmpeg -i background.jpg -i input.png -filter_complex &quot;[0:v][1:v]overlay=10:10,drawtext=text='Your Text Here':x=20:y=H-50:fontsize=24:fontcolor=white, drawtext=text='Text2':x=200:y=200:fontsize=24&quot; output.jpg

</code></pre>

<h2 id="目标">目标</h2>

<p>把上图使用 ffmpeg 转成下图</p>

<p><center>
<figure>
<img src="/images/tech/shortcut-ffmpeg/flower.jpg"  style="zoom: 8%;" />
<img src="/images/tech/shortcut-ffmpeg/flower_text.jpg"  style="zoom: 8%;" />
</figure>
</center></p>

<h2 id="脚本">脚本</h2>

<p>本来想完全使用 shell 脚本处理，奈何发现 exif 信息有一些处理如果用 shell 的话，会很繁琐，因此使用胶水语言 python 处理具体的文字逻辑，然后将命令 ffmpeg 和 exiftool 胶合起来。</p>

<h3 id="图片的基本信息">图片的基本信息</h3>

<p>索尼拍摄的图片的像素是 <code>7008 × 4672</code>, 快捷指令生成的图片的像素是 <code>7008x5490</code>。</p>

<p>使用 AutoCAD 大概把对应关系画了下，然后给出了一个可以接受的比例关系</p>

<p><img src="/images/tech/shortcut-ffmpeg/cad.png" /></p>

<p>最后整理的位置关系比较复杂，同时要对竖向的进行额外特殊的处理。</p>

<h3 id="脚本步骤">脚本步骤</h3>

<p>基本就是按照一个好的图片解决方案中的步骤来的，对很多方法做了抽象，提供了可以使用的函数 api 。</p>

<pre><code>.
├── README.md
├── config.py   // 配置文件
├── font_finder.py // 字体在不同的操作系统的选择
├── generate_links.py  // 图片和上传到图床的文件的对应关系
├── logger.py   // 日志模块
├── pic_compress.py  // 图片压缩
├── pic_ffmpeg.py    // ffmpeg 图片操作 api
├── pic_upload.py    // picgo 上传图床 api
├── pic_watermark.py  // 水印制作具体流程
├── requirement.txt   // python 依赖的非 build-in 库
├── run_camera.sh     // 处理相机图片的一站式脚本（压缩，上传，加水印，关联链接）
├── run_normal.sh     // 处理普通图片的一站式脚本（压缩，上传，关联链接）
├── run_picture_compress_all.sh  // ffmpeg shell 压缩入口 1
├── run_picture_compress_small.sh  // ffmpeg shell 压缩入口 2
├── run_picture_compress_thumb.sh // ffmpeg shell 压缩入口 3
└── utils.py  // 工具箱
</code></pre>

<hr />

<p>参考：</p>

<ul>
<li><a href="https://chat.openai.com/share/00d12884-a871-42ed-a6f7-dddedde81918" rel="noreferrer" target="_blank">ffmpeg 使用</a></li>
</ul>

        ]]>
      </description>
    </item>
    
    <item>
      <title>好的博客图片解决方案</title>
      <link>https://blog.lierhua.top/tech/%E4%B8%80%E4%B8%AA%E5%A5%BD%E7%9A%84%E5%9B%BE%E7%89%87%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88/</link>
      <pubDate>Sat, 23 Sep 2023 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/%E4%B8%80%E4%B8%AA%E5%A5%BD%E7%9A%84%E5%9B%BE%E7%89%87%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>博客</code>, <code>图片解决方案</code>, <code>图床</code>, <code>ffmpeg</code>, <code>alt</code></p>

<p>今天在写「望京与望京公园」那篇图片文档的时候，又再思考应该如何处理图片问题，我曾多次谈过我的博客的文章和图片都是存储在 gitlab 的私有仓库，图片也原片存储到私有仓库是因为不想像我之前的那个<a href="https://archive.lierhua.top" rel="noreferrer" target="_blank">归档了的博客</a>一样，再经历一次图床的搬迁。</p>

<p>但是放在私有仓库里随着图片的增多，不得不面对一个问题，仓库的大小会变的很大（代码仓库本身也不是用来存文件的地方，专业的事情要专业的东西去做），我也曾经多次使用各种组合方案来减少图片的占用，可以解决部分问题，但是随之而来的就是也会有新的问题产生，比如压缩后画质更好的原图应该放到哪里管理，丢弃我又不想，留着又很占用空间。</p>

<p>在写这篇文档之前，我的整个图片方案如下：</p>

<ul>
<li>将相机拍摄的图片使用存储卡导入 MacBook Pro</li>
<li>电脑的图片使用 AirDrop 或者 <a href="https://localsend.org/#/" rel="noreferrer" target="_blank">LocalSend</a> 发送到手机</li>
<li>手机使用快捷方式里面的<a href="https://www.immers.icu/" rel="noreferrer" target="_blank">图片水印添加指令</a>来给图片添加水印
<img src="/images/tech/picture-scheme/shortcut.png"  style="zoom: 80%;" alt="iPhone快捷指令" title="iphone 快捷指令"/></li>
<li>使用 AirDrop 或者 <a href="https://localsend.org/#/" rel="noreferrer" target="_blank">LocalSend</a> 发送回电脑</li>
<li>电脑使用 <a href="/tech/ffmpeg的基础使用">ffmpeg</a> 工具将图片批量压缩一份同像素的 small 版，同时转成更小像素(原像素的一半)的 thumbnail 版</li>
<li>在 small 版上，根据图片的内容重命名图片</li>
<li>复制到博客目录中，并在博客文档中引用</li>
</ul>

<p>这个过程很像一个零件的生产工艺，有多种不同的工艺可以制作一个零件，但是更好的更合理的工艺会使零件制作的材料成本和时间成本降到最低，实现企业利润的最大化，同样的，对应到个人的生活也是，每个人的时间是有限的，可以通过优化解决问题的方案让处理时间减少很多（如果带来消费上的降低就更好了），就会有更多的时间去休息或者产生其他价值。</p>

<p>现在来看，这个工艺步骤可以改进的还有很多：</p>

<ul>
<li>是否需要导入到手机使用快捷指令添加水印（可以直接使用 Mac 的快捷指令，效果是一样的）</li>
<li>是否需要使用快捷指令添加水印，可以使用 ffmpeg 重写一套相同的规则 （跑脚本比手动一个个的操作会更便利）</li>
<li>使用 thumbnail 版是不是更合适（像素减半不影响看，大小减半很重要）</li>
<li>small 是不是可以写一个图床脚本，放置到图床，然后图床链接写到对应的 thumbnail 的某个属性中去 （既展示了小图减少了出网流量，同时又保留了图片的原始像素图片的查看途径）</li>
</ul>

<p>根据这些工艺的改进步骤，我们可以完全实现在一个脚本内批量完成之前需要很多需要手工复杂操作的步骤。</p>

<p>脚本实现后，我们的完整步骤就变成了：</p>

<ul>
<li>导入图片到电脑</li>
<li>重命名</li>
<li>跑处理脚本（后面展开详细的过程）</li>
<li>写博客，复制图片地址到对应的博客位置</li>
</ul>

<p>脚本需要实现的功能：</p>

<ul>
<li>将原始图片添加水印（需要复刻原来的快捷方式）</li>
<li>压缩图片至 small，处理 small 到 thumbnail</li>
<li>将 small 文件上传至图床，生成名字与图床链接的对应</li>
<li>输入图片存储地址，将 thumbnail 复制到存储位置，并且生成博客需要使用的链接，并将上一步的对应关系也加进去</li>
<li>添加 alt 描述，增加 SEO</li>
</ul>

<p>至此，将以前需要小时级别的任务缩短至了分钟级。</p>
        ]]>
      </description>
    </item>
    
    <item>
      <title>Quantumult X</title>
      <link>https://blog.lierhua.top/tech/quantumult-x/</link>
      <pubDate>Fri, 08 Sep 2023 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/quantumult-x/</guid>
      <description>
        <![CDATA[
        

<h2 id="楔子">楔子</h2>

<p>这篇文章的主体内容是加密的，密码是 <code>lierhua1026</code>，做成加密的很重要的原因是，我的 blog 的 markdown 文档是放在阿里云港区的 CDN 上的，现在阿里云对上传的文档都做了文字校验，会检测出一些「他们」不允许的地方，这篇大概率会被检测到，因此加密一下，防止被冻结。</p>

<figure><img src="/images/tech/qx/aliyun-deny.png"  style="zoom: 100%;" /></figure>

<p>当时选用阿里云港区 CDN 而没有直接托管到 github 是有原因的，虽然托管到 github 有很有优点：不受这种监管，不用自己承担流量费用，不需要占用自己的存储空间，git 版本控制不用每次全量更新资源，等等。但是因为 github 访问受限，因此做了这个妥协。</p>





<div class="hugo-encryptor-container">
  <div class="hugo-encryptor-prompt">
    
      <p>文章的部分内容被密码保护：</p>
    
  </div>
  <div class="hugo-encryptor-form">
    <input
      class="hugo-encryptor-input"
      placeholder='请输入密码'
    />
    <input
      class="hugo-encryptor-button"
      type="button"
      value='点击验证'
      onclick="_click_handler(this)"
    />
  </div>
  <div
    class="hugo-encryptor-cipher-text"
    data-password="lierhua1026"
    style="display: none;"
  >
    <span style="display: none;">--- DON'T MODIFY THIS LINE ---</span>
    <p>Quantumult X 是一款苹果平台的流量代理工具，也就是我们平时俗称的梯子工具，以下会简称 Qx，在使用这个工具前，iOS 上我用的是 shadowrocket, Mac 上用的是 clashX。</p>

<p>我知道这个工具很早了，当时是坤坤推荐的，但是因为不太想折腾，所以一直没有尝试用过。</p>

<h2 id="使用背景">使用背景</h2>

<p>我日益增长的流量分流自动切换的需求同目前在用的工具之间的矛盾越来越凸显（也可能是我不会用）。</p>

<ul>
<li>我有多个不同的资源和节点，有的节点资源的流量可以认为是无限的，有的资源的流量是有限制的，他们分别对应的是不同的地区和国家。</li>
<li>chatgpt 和 claude 是我工作和生活中不可缺少的工具助手，我要频繁的手动切换节点来满足他们的地域检查需要。</li>
<li>部分网页有太多的广告（虽然我知道广告是作者收入的重要来源），想屏蔽一下广告信息。</li>
<li>网飞，HBO 等国外媒体也需要检测下是否对此节点解锁。</li>
</ul>

<h2 id="基本介绍">基本介绍</h2>

<p>如果只是想把 Qx 作为 shadowrocket 来用的话，不会有太多困惑，只需要跟其他流量代理工具一样，导入资源节点就行，但是一旦涉及到要对不同的流量做不同的规则判断，让他们走不同的节点的时候，就需要好好了解下 Qx 的功能了。</p>

<p>我在学习使用 Qx 时，也查了很多资料和文档，但是我觉得都没有从最简单最基本的角度把这个 APP 的一些功能概述清楚，我刚开始看的时候云里雾里的，对策略组，对分流规则完全没有概念，再加上 Qx 本身产品的交互界面也有一些问题（我确实觉得有的交互用起来有点别扭），最开始的时候，我确实被卡住了。</p>

<h3 id="基本概念">基本概念</h3>

<p>首先按我自己的理解，说一下这里面各个概念，他们具体对应的是什么，我觉得这是上手这个 APP 的一个最重要的部分。</p>

<ul>
<li>节点：就是我们的代理，是基石

<ul>
<li>本地节点：我们自己搭建的代理，在自己的美区或者其他国家的服务器上部署的代理服务的地址</li>
<li>远程节点：一般我们再第三方购买的服务的地址，都是远程节点</li>
</ul></li>
<li>策略组：对不同的节点做的集合</li>
<li>分流规则：对不同的流量（IP 域名等）做的分流规则</li>
</ul>

<h4 id="一个例子">一个例子</h4>

<p>这三个是做流量分流策略最基本的概念，我举一个例子，来把这三个概念串起来。</p>

<p><strong>已知:</strong></p>

<p>现在你有两个节点，一个代理节点是「美国」一个代理节点是「香港」，你现在想使用 claude 服务（只支持美国和英国的 IP 访问），设计一个方案。</p>

<p>先牢记一句话，分流规则分流的是流量（IP和域名等），策略组组织的是节点。</p>

<p><strong>方案:</strong></p>

<ol>
<li>我们先建立两个策略组，一个策略组名字叫「用来访问 claude 的策略组」,另一个策略组叫「用来访问 youtube 的策略组」；</li>
<li>我们再建立两个分流规则，一个规则名字叫「claude 的域名」，另一个叫「youtube 域名」；</li>
<li>「用来访问 claude 的策略组」这个策略组关联「美国」节点，「用来访问 youtube 的策略组」关联「香港」节点；</li>
<li>「claude 的域名」的分流规则绑定 claude 的相关域名，「youtube 域名」的分流规则绑定 youtube 的域名；</li>
<li>「claude 的域名」的分流规则强制绑定「用来访问 claude 的策略组」,  「youtube 域名」的分流规则强制绑定「用来访问 youtube 的策略组」</li>
<li>「claude 的域名」的生效顺序排在「youtube 域名」这个规则的前边；</li>
<li>打开 Qx 的「按规则分流」的开关；</li>
<li>现在如果请求 claude.ai 这个域名，分流规则发现走的是 claude 的域名，于是就判定为走的 「claude 的域名」的分流规则, 因为这个分流规则绑定了「用来访问 claude 的策略组」，而这个策略组又绑定了「美国」节点，于是，流量就会被分流到走美国的那个节点；同理，访问 youtube.com 就会走香港的节点。</li>
</ol>

<p>现在我们方案设计好了，只需要用 Qx 可以识别的配置格式，配置到 conf 文件里，就可以完成我们要做的这个任务了。</p>

<h3 id="基本配置文件">基本配置文件</h3>

<figure><img src="/images/tech/qx/qx-conf.png"  style="zoom: 100%;" /></figure>

<pre><code class="language-ini">[general] ## 基本配置，例子中的这个是一个资源解析器（可以将 Quantumult X 原本不识别的 节点或订阅链接 轻松的导入）
resource_parser_url = https://raw.githubusercontent.com/KOP-XIAO/QuantumultX/master/Scripts/resource-parser.js
[dns] ## DNS 配置
no-ipv6
server = 114.114.114.114
server = 8.8.8.8
[policy] ## 策略组: [策略组类型=策略组名字, 其他策略组(对应的策略组的名字)或者节点匹配规则(server-tag-regex), icon链接]
static=LocalNode, local_name, img-url=https://raw.githubusercontent.com/erdongchanyo/icon/main/Policy-Filter/Auto.png
# 注意！！！ 正则解析只支持 server_remote, 对于 server_local 直接写对应的 name 到 local_name 位置即可
# 自动选择最优节点-HK
url-latency-benchmark=Auto-HK, server-tag-regex=港, check-interval=600, tolerance=0, alive-checking=false, img-url=https://raw.githubusercontent.com/erdongchanyo/icon/main/Policy-Filter/Auto.png
# US
static=US, server-tag-regex=美|美国|美|波特兰|达拉斯|俄勒冈|凤凰城|费利蒙|硅谷|拉斯维加斯|洛杉矶|圣何塞|圣克拉拉|西雅图|芝加哥|🇺🇸|US|United, img-url=https://raw.githubusercontent.com/erdongchanyo/icon/main/Policy-Country/US.png
# &gt; Netflix策略
static=Netflix, US, direct, img-url=https://raw.githubusercontent.com/erdongchanyo/icon/main/Policy-Filter/Netflix.png
# Ai Proxy策略
static=Ai Proxy, resource-tag-regex=.*, server-tag-regex=美|美国
[server_local]  ## 本地的节点配置(一般是自己买的 VPS 搭建配置的地址), 推荐在 UI界面输入
http=proxy.xxxx.com:1026, username=xxxx,password=xxxx,fast-open=false,udp-relay=false,tag=local_name
[server_remote]  ## 远程节点 (一般是购买的机场的节点地址), 推荐在 UI 界面导入
https://xxxx.net/link/xxxx?list=shadowrocket, tag=xxxx, update-interval=172800, opt-parser=true, inserted-resource=true, enabled=true
[filter_local] ## 本地分流规则，就是显式的分流规则：[ 匹配的格式, 匹配的内容, 对应的策略组 ]
host, chat.openai.com, Ai Proxy
host-keyword, anthropic, Ai Proxy
host-keyword, claude, Ai Proxy
[filter_remote] ## 远程过滤规则（就是过滤的规则不是我们自己定义的，而是从链接地址下载下来的内容，里面的内容跟 filter_local 定义的规则是一样的）
# Netflix规则, 格式 [远程规则的链接, tag=规则名字, force-policy=强制走的策略组的名字（跟上面定义的策略组的名字对应上）, 其他参数]
https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/rule/QuantumultX/Netflix/Netflix.list, tag=Netflix 规则, force-policy=Netflix, update-interval=86400, opt-parser=false, enabled=true
[rewrite_remote]
#
[rewrite_local]
#
[task_local]
#
[http_backend]
#
[mitm]
#
</code></pre>

<h3 id="对应的界面">对应的界面</h3>

<p><center>
<figure>
<img src="/images/tech/qx/qx-node.png"  style="zoom: 50%;" />
<img src="/images/tech/qx/qx-filter.png"  style="zoom: 50%;" />
<img src="/images/tech/qx/qx-network.png"  style="zoom: 50%;" />
<img src="/images/tech/qx/qx-setting.png"  style="zoom: 50%;" />
</figure>
</center></p>

<h2 id="详解">详解</h2>

<p>如果我上面的部分可以基本看懂的话，剩下的就好办了，可以直接看如下链接的文档就可以解决绝大部分问题,<a href="https://github.com/erdongchanyo/Rules/blob/main/Quantumult%20X/README.md" rel="noreferrer" target="_blank">点我</a></p>

<hr />

  </div>
</div>


<blockquote>
<p>世间行乐亦如此，古来万事东流水。</p>
</blockquote>

        ]]>
      </description>
    </item>
    
    <item>
      <title>一款还算优秀的自部署云相册 -- photoprism</title>
      <link>https://blog.lierhua.top/tech/photoprism-%E4%B8%80%E6%AC%BE%E8%BF%98%E7%AE%97%E4%BC%98%E7%A7%80%E7%9A%84%E8%87%AA%E9%83%A8%E7%BD%B2%E4%BA%91%E7%9B%B8%E5%86%8C/</link>
      <pubDate>Fri, 28 Jul 2023 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/photoprism-%E4%B8%80%E6%AC%BE%E8%BF%98%E7%AE%97%E4%BC%98%E7%A7%80%E7%9A%84%E8%87%AA%E9%83%A8%E7%BD%B2%E4%BA%91%E7%9B%B8%E5%86%8C/</guid>
      <description>
        <![CDATA[
        <p>在大理拍了很多的照片，自己的 NAS 还没有搭建好（房子里还没有网络，没法处理），所以就选了一个自部署的云相册 photoprism.</p>

        ]]>
      </description>
    </item>
    
    <item>
      <title>使用 ffmpeg 批量处理图片</title>
      <link>https://blog.lierhua.top/tech/ffmpeg%E7%9A%84%E5%9F%BA%E7%A1%80%E4%BD%BF%E7%94%A8/</link>
      <pubDate>Fri, 28 Jul 2023 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/ffmpeg%E7%9A%84%E5%9F%BA%E7%A1%80%E4%BD%BF%E7%94%A8/</guid>
      <description>
        <![CDATA[
        

<p>2020 年做素材模块的时候，就用过 <code>ffmpeg</code> 这个工具，当时是需要获取视频的详细码率等信息，并且需要截取视屏中的某一帧作为视频的封面，发现 <code>ffmpeg</code> 很强大。</p>

<p>但是因为是工作中很小的一个需求点，大部分的素材维护管理都跟这个没有太大关系，因此在项目结束后，就没有再过多的研究过他了。</p>

<p>这次是因为有很多的图片需要压缩处理，并且想生成缩略图，github 找了好多现成的工具，发现使用效果都不理想（不满足我的使用需求），因此决定使用 <code>ffmpeg</code>。 在此记录一下常用的图片操作的命令，对于视频等的详细命令，可以参考<a href="https://ref.lierhua.top/docs/ffmpeg.html" rel="noreferrer" target="_blank">这里</a>。</p>

<h2 id="常用命令">常用命令</h2>

<p>1.自动压缩图片（按给定权重）</p>

<pre><code class="language-shell">ffmpeg -i ~/Desktop/circle.jpg -q 10(compress_level) ~/Desktop/circle-10.jpg
#compress_level：压缩等级为正整数，数值越大压缩等级越高
</code></pre>

<p>2.压缩至指定的宽高</p>

<pre><code class="language-shell">ffmpeg -i ~/Desktop/circle.jpg -vf scale=-1:500(width:height) ~/Desktop/circle-thumbnail.jpg
#width为压缩后的图片宽度
#height为压缩后的图片高度
#当width或height其中有一个数值为-1时将保持原来图片尺寸比例压缩
</code></pre>

<p>3.图片裁切</p>

<pre><code class="language-shell">ffmpeg -i image_source -vf crop=width:height:from_x:from_y out_source
#width是要裁剪出的图片的宽度
#height是要裁剪出的图片的高度
#from_x是裁剪的起始X轴的位置
#from_y是裁剪的起始Y轴的位置
</code></pre>

<p>4.添加水印图片</p>

<pre><code class="language-shell">ffmpeg -i image_source -vf movie=logo_source,scale=logo_width:logo_height,lut=a=val*opacity_num[watermask];[in][watermask] overlay=from_x:from_y[out] -y  out_source
#logo_source为水印图片地址
#logo_width为水印图片的宽度
#logo_height为水印图片的高度
#opacity_num为水印图片的透明度
#from_x为水印的起始X轴的位置
#from_y为水印的起始Y轴的位置
</code></pre>

<p>5.添加文字水印</p>

<pre><code class="language-shell">ffmpeg -i image_source -vf drawtext=fontfile=font_ttf_path:fontcolor=font_color:fontsize=font_size:text=message_info:x=from_x:y=from_y  out_source
#font_ttf_path为字体路径，此项必须设置否则会出现字体无法找到的错误;
#字体路径要设置绝对路径并且要注意路径正反斜线转义(例如C\\:/Windows/Fonts/simhei.ttf)
#font_color为字体的颜色
#font_size为字体的大小
#message_info为水印文字内容
#from_x为水印的起始X轴的位置
#from_y为水印的起始Y轴的位置
#如果水印内容是中文需要设置中文字体否则会文字显示乱码
</code></pre>

<h2 id="快速压缩">快速压缩</h2>

<p>为了更加快速的压缩图片文件，写了一个 shell 脚本批量处理将对应的图片快速处理成想要的压缩权重或者缩略图大小，具体的代码如下：</p>

<pre><code class="language-shell">#!/bin/zsh

# 定义图片压缩函数
function compress_pics_small() {

  # 获取参数  
  pic_dir=$1
  output_dir=$2
  compression_ratio=$3
  
  # 创建输出目录
  mkdir -p $output_dir
  # 遍历源图片目录中的图片文件
  for pic in $pic_dir/*.JPG; do
    # 获取图片文件名
    pic_name=$(basename &quot;$pic&quot;)
    # 使用 ffmpeg 压缩图片
    ffmpeg -i &quot;$pic&quot; -q $compression_ratio &quot;$output_dir/$pic_name&quot;
  done
}

function compress2specific_scale() {
  # 获取参数  
  pic_dir=$1
  output_dir=$2
  height=$3
  
  # 创建输出目录
  mkdir -p $output_dir
  # 遍历源图片目录中的图片文件
  for pic in $pic_dir/*.JPG; do
    # 获取图片文件名
    pic_name=$(basename &quot;$pic&quot;)
    # 使用 ffmpeg 压缩图片
    ffmpeg -i &quot;$pic&quot; -vf scale=-1:&quot;$height&quot; &quot;$output_dir/$pic_name&quot;
  done
}

# 调用函数
compress_pics_small ~/Desktop/摩托旅行 ~/Desktop/摩托旅行_small 30
compress2specific_scale ~/Desktop/摩托旅行_small ~/Desktop/摩托旅行_thumbnail 500
</code></pre>

        ]]>
      </description>
    </item>
    
    <item>
      <title>读现代统计图形</title>
      <link>https://blog.lierhua.top/tech/%E8%AF%BB%E7%8E%B0%E4%BB%A3%E7%BB%9F%E8%AE%A1%E5%9B%BE%E5%BD%A2/</link>
      <pubDate>Fri, 28 Jul 2023 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/%E8%AF%BB%E7%8E%B0%E4%BB%A3%E7%BB%9F%E8%AE%A1%E5%9B%BE%E5%BD%A2/</guid>
      <description>
        <![CDATA[
        <p>知道这本书是因为谢益辉……</p>

<p>地址：<a href="https://bookdown.org/xiangyun/msg/" rel="noreferrer" target="_blank">https://bookdown.org/xiangyun/msg/</a></p>

        ]]>
      </description>
    </item>
    
    <item>
      <title>图片与图片工具</title>
      <link>https://blog.lierhua.top/tech/%E5%9B%BE%E7%89%87%E4%B8%8E%E5%9B%BE%E7%89%87%E5%B7%A5%E5%85%B7/</link>
      <pubDate>Thu, 27 Jul 2023 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/%E5%9B%BE%E7%89%87%E4%B8%8E%E5%9B%BE%E7%89%87%E5%B7%A5%E5%85%B7/</guid>
      <description>
        <![CDATA[
        <p>在写博客的时候，经常会面临处理图片的事情，目前让我很困扰的点在于此：</p>

<ul>
<li>我的网站前置走的是 cloudflare 会有缓存，但是国内访问不是太快</li>
<li>我用的文件存储是阿里云的 OSS</li>
<li>每个月的免费出网流量是 5G</li>
<li>用的是港区的 OSS，因为主要是中文博客，访问还在是国内，香港访问速度会快</li>
<li>没用国区是因为国区无法配置域名，如果要配置需要备案，我不想备案</li>
<li>走国内 CDN 加速的话，需要配置域名并备案（我不想</li>
<li>因为外网访问量没有那么大，因此直接用 cloudflare 做 CDN 是 OK 的</li>
<li>之前碰到过图床跑路的情况，因此只考虑自建的服务</li>
<li>自建图床就涉及到流量的问题，gitee 这种国内的不敢用，github 内网访问慢，OSS 和 COS 就是一个选择</li>
<li>但是 OSS 和 COS 的免费出网流量每个月就 5G，如果碰到恶意刷量的情况，很容易被刷很多钱</li>
<li>目前我不是直接上传图片到图床，而是放到 asset 目录下，然后 markdown 直接相对引用

<ul>
<li>缺点是需要把图片都放到 asset 下增加了 git 仓库的大小</li>
<li>优点是不怕图床跑路导致的图片的丢失</li>
<li>图片的压缩就是我需要考虑的一个很重要的问题，要让图片不能太大增加 git 负担</li>
</ul></li>
<li>如果能解决上面的图床的问题，我是可以考虑直接把图片压缩后上传到图床，引用图床的地址的</li>
<li>毕竟一个 URL 的维护成本和 git 管理成本比一个图片的要小很多</li>
<li>再一个就是压缩，之前的图片的量少，可以选择手动压缩，但是现在图片的量大

<ul>
<li>是否需要使用图片的缩略图 magick 工具可以处理</li>
<li>ffmpeg 可以对图片进行压缩处理</li>
</ul></li>
</ul>

<p>方案选择：</p>

<ul>
<li>使用批量的图片压缩，然后继续沿用原来的那种模式把图片放到 asset 目录下相对引用一下</li>
<li>批量压缩后，使用命令行工具自动上传图床，并返回对应的图床地址, 使用图床的网络地址（然后增加一个 github 的地址做备份）</li>
<li>批量压缩，同步图床，原始图片放到其他地方备份</li>
</ul>

<p>再增加一个 photoprism 的服务，把一些压缩过的，需要记录的图片都做成线上服务</p>

<p>后续：</p>

<ul>
<li>是否考虑 OSS 地区放到外区</li>
</ul>

<hr />

<ul>
<li>阿里云出网流量计费情况：<a href="https://help.aliyun.com/zh/oss/product-overview/traffic-fees?spm=a2c4g.11186623.0.0.4ef53bbdsUwX0E" rel="noreferrer" target="_blank">https://help.aliyun.com/zh/oss/product-overview/traffic-fees?spm=a2c4g.11186623.0.0.4ef53bbdsUwX0E</a></li>
<li><a href="https://jelly.jd.com/article/5c34081bd7aa2c0055d09a71" rel="noreferrer" target="_blank">https://jelly.jd.com/article/5c34081bd7aa2c0055d09a71</a></li>
<li><a href="https://picgo.github.io/PicGo-Doc/zh/guide/#%E5%BC%80%E5%8F%91%E8%AF%B4%E6%98%8E" rel="noreferrer" target="_blank">https://picgo.github.io/PicGo-Doc/zh/guide/#%E5%BC%80%E5%8F%91%E8%AF%B4%E6%98%8E</a></li>
<li><a href="https://www.jianshu.com/p/b53943fc3819" rel="noreferrer" target="_blank">https://www.jianshu.com/p/b53943fc3819</a></li>
</ul>

        ]]>
      </description>
    </item>
    
    <item>
      <title>Vue 应用初始化</title>
      <link>https://blog.lierhua.top/tech/vue-%E5%88%9D%E5%A7%8B%E5%8C%96/</link>
      <pubDate>Wed, 15 Mar 2023 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/vue-%E5%88%9D%E5%A7%8B%E5%8C%96/</guid>
      <description>
        <![CDATA[
        

<p>有这么三个 Vue 文件，然后看看初始化时走的各个流程是做了什么，以及一些原理。</p>

<pre><code class="language-javascript">// main.js
import Vue from 'vue'
import App from './App.vue'
// import { Row, Button } from 'element-ui';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import router from './router'
import store from './store'
import './api/mock'

Vue.config.productionTip = false

// 全局引入
Vue.use(ElementUI)


new Vue({
  router,
  store,
  render: h =&gt; h(App),
}).$mount('#app')

</code></pre>

<pre><code class="language-javascript">// App.vue
&lt;template&gt;
  &lt;div id=&quot;app&quot;&gt;
    &lt;!-- 路由出口 --&gt;
    &lt;!-- 路由匹配到的组件将渲染在这里 --&gt;
    &lt;router-view&gt;&lt;/router-view&gt;
  &lt;/div&gt;
&lt;/template&gt;

&lt;script&gt;

export default {
  name: 'App'
}
&lt;/script&gt;
&lt;style lang=&quot;less&quot;&gt;
  html,body,h3, p {
    margin: 0;
    padding: 0
  }
&lt;/style&gt;
</code></pre>

<pre><code class="language-javascript">// store.js
import Vue from 'vue'
import Vuex from 'vuex'
import tab from './tab'

Vue.use(Vuex)

// 创建vuex的实例
export default new Vuex.Store({
    modules: {
        tab
    }
})
</code></pre>

<h2 id="vue-应用初始化">Vue 应用初始化</h2>

<pre><code class="language-javascript">new Vue({
    router,
    store,
    render: h =&gt; h(App),
}).$mount('#app')
</code></pre>

<p>介绍下这个代码在干什么，虚拟 DOM 是在这里初始化的吗？</p>

<p>这段代码是Vue.js框架中的一个常见用法，用于初始化和挂载一个Vue应用。Vue.js是一个用于构建用户界面的渐进式JavaScript框架。下面我会逐一解释这段代码的各个部分：</p>

<ol>
<li><p><strong><code>new Vue({...})</code></strong>: 这是在创建一个新的Vue实例。Vue实例是Vue应用的根，所有的组件都会挂载在这个实例下。</p></li>

<li><p><strong><code>router</code></strong>: 这是Vue Router的实例，用于Vue应用的页面路由。将其传入Vue实例，意味着该Vue应用将使用Vue Router进行页面的路由管理。这使得单页面应用(SPA)的开发变得简单和高效。</p></li>

<li><p><strong><code>store</code></strong>: 这是Vuex的实例，Vuex是Vue的状态管理模式。它提供了一种集中式存储管理应用的所有组件的状态，并以相应的规则保证状态以一种可预测的方式发生变化。这对于大型应用尤其重要，因为它使得状态管理变得更加有条不紊。</p></li>

<li><p><strong><code>render: h =&gt; h(App)</code></strong>: 这是一个渲染函数，用来渲染一个Vue组件。这里的<code>App</code>通常是一个根组件，它是所有其他组件的父组件。<code>h</code>是<code>createElement</code>的别名，一个用来创建虚拟DOM的函数。这行代码的含义是，使用<code>h</code>函数来创建<code>App</code>组件的虚拟DOM。</p></li>

<li><p><strong><code>.$mount('#app')</code></strong>: 这是Vue实例的一个方法，用于将Vue实例挂载到DOM上。<code>#app</code>是一个选择器，它指向HTML中的一个元素。这意味着Vue实例将挂载到这个元素上，而这个元素通常是页面上的一个容器，Vue应用将在这个容器内进行渲染。</p></li>
</ol>

<p>至于虚拟DOM的初始化，它是在Vue内部进行的，当Vue实例被创建并挂载时。虚拟DOM是Vue的一个核心概念，它允许Vue在内存中以JavaScript对象的形式模拟DOM结构，然后Vue的渲染函数会基于虚拟DOM来创建真实的DOM。这种机制使得Vue能够高效地更新DOM，因为它只更新那些实际发生变化的部分，而不是重建整个DOM树。这段代码中的<code>render</code>函数就是虚拟DOM初始化和更新的起点。</p>

<h2 id="vue-use">Vue.use</h2>

<pre><code class="language-javascript">import Vue from 'vue'
import App from './App.vue'
// import { Row, Button } from 'element-ui';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import router from './router'
import store from './store'
import './api/mock'

Vue.config.productionTip = false

// 全局引入
Vue.use(ElementUI)


new Vue({
    router,
    store,
    render: (h) =&gt; h(App),
}).$mount('#app')
</code></pre>

<p>为什么可以先 Vue.use 然后再创建一个 Vue 对象？</p>

<p>在Vue.js中，<code>Vue.use()</code>方法用于安装Vue插件。当你调用<code>Vue.use(plugin)</code>时，它会执行<code>plugin</code>对象的<code>install</code>方法（如果<code>plugin</code>是一个对象并且提供了<code>install</code>方法的话），或者直接执行<code>plugin</code>（如果<code>plugin</code>是一个函数）。这个过程通常用于注册全局组件、指令、过滤器，或者向Vue实例添加全局方法和属性等。</p>

<p>关于为什么可以先使用<code>Vue.use()</code>然后再创建一个Vue实例，主要是因为<code>Vue.use()</code>方法的作用是在全局范围内注册插件，这意味着一旦插件被安装，它将影响到之后创建的所有Vue实例。这是一种设计选择，允许开发者在应用初始化阶段就配置好所需的插件，而不必在每个Vue实例中重复配置。</p>

<p>在你提供的代码示例中，<code>Vue.use(ElementUI)</code>用于全局安装Element UI组件库。Element UI是一个基于Vue 2.0的桌面端组件库，它提供了一套丰富的Vue组件，非常适合在Vue项目中使用。通过全局安装（<code>Vue.use(ElementUI)</code>），你无需在每个组件中单独引入Element UI的组件，可以直接在任何地方使用它们，这极大地简化了开发流程。</p>

<p>总结来说，<code>Vue.use()</code>方法允许在全局范围内安装和注册插件或组件库，这样做的好处是让所有的Vue实例都能够使用到这些功能，而不需要在每个实例或组件中单独进行配置。这就是为什么你可以在创建Vue实例之前调用<code>Vue.use()</code>，并且这样做是Vue插件安装的推荐方式。</p>

<h2 id="vue-是什么">Vue 是什么？</h2>

<p>是不是可以认为 Vue 是一个类名，use 是一个类方法，可以先直接用类方法做一些类全局的处理，然后再初始化 Vue 实例时，这个 Vue 实例就可以直接拿到对应的类的属性了？</p>

<p>是的，你的理解是正确的。在Vue.js中，<code>Vue</code>确实可以被认为是一个类（在JavaScript中通常称为构造函数）。<code>Vue.use()</code>则是这个类的一个静态方法，它用于安装Vue插件。</p>

<p>静态方法是属于类本身而不是类的实例的方法。因此，当你调用<code>Vue.use()</code>时，你实际上是在调用Vue类的一个静态方法来进行全局的配置或安装插件。这些配置或插件将影响到之后创建的所有Vue实例，因为它们是在Vue的全局作用域中注册的。</p>

<p>这就像你所描述的那样：通过类的静态方法，可以在类级别上做一些全局的处理。当你随后创建该类的实例时（即通过<code>new Vue({...})</code>创建Vue实例），这些实例就能够自动继承或访问到之前通过静态方法注册或配置的属性和功能。</p>

<p>具体到Vue中，这意味着：</p>

<ol>
<li><p><strong>全局安装插件</strong>：当你使用<code>Vue.use(plugin)</code>安装插件时，你是在Vue的全局作用域中注册该插件。无论何时创建Vue实例，这个插件都会被应用到每个实例中，这使得插件中的组件或功能可以在任何新创建的Vue实例中使用。</p></li>

<li><p><strong>全局注册组件</strong>：类似地，如果你通过<code>Vue.component()</code>全局注册一个组件，那么这个组件可以在任何Vue实例的模板中使用，而不需要在每个使用它的组件中单独进行导入和注册。</p></li>
</ol>

<p>因此，Vue的设计允许通过类的静态方法进行全局配置，然后这些配置会自动应用到所有的Vue实例中，这极大地简化了Vue应用的配置和插件的使用。</p>

<h2 id="vuex">Vuex</h2>

<pre><code class="language-javascript">import Vue from 'vue'
import Vuex from 'vuex'
import tab from './tab'

Vue.use(Vuex)

// 创建vuex的实例
export default new Vuex.Store({
    modules: {
        tab
    }
})
</code></pre>

<p>既然这样的话，Vuex 是不是也是个类，但是 Vue 的类 use 一个 Vuex 的类而不是实例的原因是什么？之后为什么又创建了一个 Vuex.Store 的实例呢？为什么不是 Vue 去 use 或者挂载一个 Vuex.Store 实例，而是他的类，这个Vuex类在这里是一个什么角色？</p>

<p>你的问题涉及到Vue插件的使用方式以及Vuex的架构设计。让我们一步步解析这些问题。</p>

<h3 id="vuex-是不是也是个类">Vuex 是不是也是个类？</h3>

<p>是的，<code>Vuex</code>可以被视为一个包含了多个属性和方法（包括<code>Store</code>构造函数）的对象。在Vuex的上下文中，<code>Vuex.Store</code>是一个用于创建Vuex store实例的构造函数（或类）。这个构造函数负责管理应用的状态（state）和逻辑（通过actions、mutations、getters等）。</p>

<h3 id="为什么vue的类用-vue-use-加载vuex的类而不是实例">为什么Vue的类用<code>Vue.use()</code>加载Vuex的类而不是实例？</h3>

<p><code>Vue.use()</code>方法用于安装Vue插件。Vuex作为一个Vue插件，提供了一个<code>install</code>方法。这个<code>install</code>方法是由Vuex对象提供的，而不是<code>Vuex.Store</code>的实例提供的。当你调用<code>Vue.use(Vuex)</code>时，实际上是在调用Vuex的<code>install</code>方法。这个<code>install</code>方法会向Vue实例添加一些全局功能，最重要的是添加<code>$store</code>属性，这样在任何组件中都可以通过<code>this.$store</code>访问到Vuex store。</p>

<h3 id="为什么又创建了一个-vuex-store-的实例">为什么又创建了一个<code>Vuex.Store</code>的实例？</h3>

<p>虽然<code>Vue.use(Vuex)</code>负责安装Vuex插件，使Vue知道如何处理Vuex store，但它并不创建一个具体的store实例。你需要通过<code>new Vuex.Store({...})</code>创建一个具体的store实例，这个实例根据你提供的配置（状态、mutations、actions等）来管理你的应用状态。创建的store实例需要被传递给根Vue实例（通常是在<code>new Vue({...})</code>时通过<code>store</code>选项进行传递），这样，Vuex的状态管理就能被整个应用所使用。</p>

<h3 id="vuex类在这里是一个什么角色">Vuex类在这里是一个什么角色？</h3>

<p>在这个上下文中，<code>Vuex</code>充当的是插件的角色，它提供了必要的接口（<code>install</code>方法）以及用于创建具体store实例的构造函数（<code>Vuex.Store</code>）。<code>Vue.use(Vuex)</code>负责安装Vuex插件，确保Vue知道如何处理Vuex store。而<code>new Vuex.Store({...})</code>则是根据你的应用具体需要创建一个Vuex store实例。</p>

<p>总结来说，<code>Vue.use(Vuex)</code>是在全局范围内安装Vuex插件，而<code>new Vuex.Store({...})</code>是创建一个具体的Vuex store实例。这两步是Vuex在Vue应用中正常工作所必需的。</p>

<h2 id="为什么可以引入-vue-文件">为什么可以引入 .vue 文件</h2>

<p>javascript 中为什么可以直接这样引入一个非 js 的文件，import App from &lsquo;./App.vue&rsquo;，这样引入的过程中，实际是在干什么，里面的 template script 和 style 都分别会怎么样被处理？</p>

<p>在JavaScript中直接引入非JS文件，比如Vue单文件组件（<code>.vue</code>文件），实际上是依赖于构建工具（如Webpack或Vite）和相应的加载器（loader）或插件来实现的。这些构建工具在编译时会识别到特定类型的文件，并使用配置好的加载器对这些文件进行处理。对于<code>.vue</code>文件，通常使用<code>vue-loader</code>（对于Webpack）或相应的插件（对于其他构建工具）来处理。</p>

<h3 id="引入过程中发生了什么">引入过程中发生了什么？</h3>

<ol>
<li><p><strong>识别文件类型</strong>：构建工具通过文件扩展名（<code>.vue</code>）识别出这是一个Vue单文件组件。</p></li>

<li><p><strong>使用加载器处理文件</strong>：<code>vue-loader</code>（或其他工具的等效插件）被调用来处理<code>.vue</code>文件。<code>vue-loader</code>会解析文件，将其拆分为独立的部分（模板、脚本、样式等）。</p></li>

<li><p><strong>编译模板</strong>：模板部分（<code>&lt;template&gt;</code>标签内的内容）会被编译成JavaScript渲染函数。这个过程涉及到HTML模板的解析，将其转换为可以通过JavaScript动态生成DOM的代码。</p></li>

<li><p><strong>处理脚本</strong>：脚本部分（<code>&lt;script&gt;</code>标签内的内容）会被当作普通的JavaScript代码处理。如果使用了ES6或其他JavaScript版本的特性，可能还会通过Babel等工具进行转译。</p></li>

<li><p><strong>处理样式</strong>：样式部分（<code>&lt;style&gt;</code>标签内的内容）会被提取并可能被加工（例如，如果使用了预处理器如Sass，需要先将其编译成普通的CSS），然后根据配置可能会被打包到单独的CSS文件中，或者以<code>&lt;style&gt;</code>标签的形式直接插入到HTML中。</p></li>
</ol>

<h3 id="结果">结果</h3>

<p>最终，<code>vue-loader</code>（或等效工具）会生成一个JavaScript模块，这个模块导出了一个Vue组件对象。这个对象包含了处理后的模板渲染函数、脚本中定义的组件选项（如data、methods等），以及可能的样式信息。当你在其他组件或应用中<code>import</code>这个<code>.vue</code>文件时，实际上是在引入这个编译后的JavaScript模块。</p>

<p>因此，这个过程使得开发者能够以一种高效且模块化的方式开发Vue应用，同时利用现代JavaScript工具链的强大功能（如模块化导入、代码分割、预处理语言支持等）。</p>

<h1 id="vue应用初始化">Vue应用初始化</h1>

<h2 id="javascript-的执行过程">javascript 的执行过程</h2>

<p>javascript 代码执行的过程是什么？就比如在</p>

<pre><code class="language-javascript">new Vue({
    router,
    store,
    render: (h) =&gt; h(App),
}).$mount('#app') 
</code></pre>

<p>过程中，是在 import  store 时就已经开始执行 store 里的代码也就是 import Vue from &lsquo;vue&rsquo;</p>

<pre><code class="language-javascript">import Vuex from 'vuex'
import tab from './tab'

Vue.use(Vuex)

// 创建vuex的实例
export default new Vuex.Store({
    modules: {
        tab
    }
})
</code></pre>

<p>还是说是在创建 Vue 实例时，加载到 store 时才去执行 store.js 里的那些命令?</p>

<p>JavaScript代码的执行过程，以及模块的导入和执行，遵循特定的规则。在你提到的Vue应用的上下文中，涉及到模块化JavaScript代码（使用ES6的<code>import</code>/<code>export</code>语法）。理解这一过程的关键在于明白JavaScript模块化系统的工作原理。</p>

<h3 id="模块的导入和执行">模块的导入和执行</h3>

<p>当你使用<code>import</code>语句导入一个模块时，如<code>import store from './store'</code>，这里发生的事情可以分为以下几个步骤：</p>

<ol>
<li><strong>解析模块路径</strong>：确定模块文件的位置。</li>
<li><strong>加载模块文件</strong>：读取模块文件的内容。如果模块已经被加载过（存在于模块缓存中），则直接跳到执行步骤。</li>
<li><strong>编译模块</strong>：将模块代码编译成可执行的JavaScript代码。这一步骤会处理模块内部的<code>import</code>语句，递归地加载和编译这些依赖。</li>
<li><strong>执行模块代码</strong>：执行编译后的代码。模块内部的顶层代码（不在函数内部的代码）会在这一步骤执行。</li>
<li><strong>导出模块接口</strong>：模块的<code>export</code>语句定义了模块的公开接口，其他模块可以通过<code>import</code>导入这些接口。</li>
</ol>

<h3 id="在你的例子中">在你的例子中</h3>

<p>当你在Vue应用的入口文件中导入<code>store</code>模块：</p>

<pre><code class="language-javascript">import store from './store'
</code></pre>

<p>这个导入语句会触发上述的加载和执行过程。也就是说，<code>store.js</code>中的代码（包括导入<code>Vue</code>和<code>Vuex</code>，使用<code>Vue.use(Vuex)</code>，以及创建<code>Vuex.Store</code>的实例）会在导入<code>store</code>模块时执行。这意味着，在你创建Vue实例之前，<code>store.js</code>中的代码已经执行了。</p>

<p>因此，当你创建Vue实例并通过<code>store</code>选项将Vuex store实例传递给Vue时：</p>

<pre><code class="language-javascript">new Vue({
  router,
  store,
  render: h =&gt; h(App),
}).$mount('#app')
</code></pre>

<p>此时，<code>store</code>模块中的Vuex store实例已经被创建并配置好了，你在Vue实例中使用的是之前已经创建和配置好的Vuex store实例。</p>

<p>这个过程展示了模块化JavaScript代码的强大之处，允许你以清晰和可维护的方式组织代码，同时确保代码的执行顺序和依赖管理得到妥善处理。</p>

        ]]>
      </description>
    </item>
    
    <item>
      <title>普罗米修斯</title>
      <link>https://blog.lierhua.top/tech/%E6%99%AE%E7%BD%97%E7%B1%B3%E4%BF%AE%E6%96%AF/</link>
      <pubDate>Tue, 14 Mar 2023 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/%E6%99%AE%E7%BD%97%E7%B1%B3%E4%BF%AE%E6%96%AF/</guid>
      <description>
        <![CDATA[
        

<h2 id="prometheus-是什么">Prometheus 是什么</h2>

<p>介绍下 Prometheus 是什么.</p>

<p>Prometheus是一个开源的系统监控和警报工具包，最初由SoundCloud创建。自2016年成为Cloud Native Computing Foundation（CNCF）的第二个托管项目（在Kubernetes之后）以来，它已经成为云原生环境中最受欢迎的监控工具之一。</p>

<h3 id="核心特性">核心特性</h3>

<ul>
<li><strong>多维数据模型</strong>：Prometheus使用时间序列数据来存储其指标，每个时间序列由唯一的指标名称和一组键值对（称为标签）来标识。</li>
<li><strong>灵活的查询语言</strong>：Prometheus提供了一种强大的查询语言PromQL（Prometheus Query Language），用于检索和处理时间序列数据。</li>
<li><strong>无需分布式存储</strong>：数据以时间序列的形式存储在本地磁盘上。尽管Prometheus支持数据快照和部分远程存储功能，但它的设计理念是运行为自治的单一节点或高度分散的节点集合，而不是依赖于大型分布式存储系统。</li>
<li><strong>服务发现</strong>：Prometheus可以通过服务发现或静态配置来发现目标，自动监控新的服务实例。这对于动态变化的云环境尤其有用。</li>
<li><strong>内置警报</strong>：Prometheus的Alertmanager组件可以处理由Prometheus服务器发送的警报，包括通过电子邮件、PagerDuty、OpsGenie、Slack等多种方式通知用户。</li>
</ul>

<h3 id="工作原理">工作原理</h3>

<ol>
<li><strong>数据收集</strong>：Prometheus服务器定期从配置的目标（如HTTP端点）拉取指标，这种拉取模式与传统的推送模式相对。</li>
<li><strong>数据存储</strong>：收集的时间序列数据存储在本地磁盘上，并通过PromQL进行查询。</li>
<li><strong>警报</strong>：基于配置的规则，Prometheus会评估时间序列数据。当规则条件满足时，触发警报并通过Alertmanager发送通知。</li>
</ol>

<h3 id="使用场景">使用场景</h3>

<ul>
<li><strong>监控云原生应用</strong>：Prometheus非常适合监控在Kubernetes等容器编排平台上运行的微服务架构应用。</li>
<li><strong>系统和硬件监控</strong>：通过收集操作系统和硬件指标，Prometheus可以帮助你监控服务器的健康状态和性能。</li>
<li><strong>服务状态监控</strong>：Prometheus可以监控多种类型的服务（如数据库、缓存、Web服务器等），确保这些服务运行正常。</li>
</ul>

<p>Prometheus因其简单、高效和适应性强的特点，成为了现代云环境中监控和警报的首选工具。</p>

<h2 id="数据拉取">数据拉取</h2>

<p>Prometheus 定期从配置的目标拉取数据，这个被拉取的数据在被拉取之前是存在哪里的，这部分数据是怎么由后端服务产生的（如果是机器的指标呢，是由谁产生的）？如果量太大，每次都有延迟怎么办</p>

<p>Prometheus通过拉取（scrape）机制定期从配置的目标（如应用程序、数据库、硬件设备等）收集指标数据。这些指标数据在被Prometheus拉取之前，通常是由目标服务或设备实时生成并暴露在一个HTTP端点上的。接下来，我们来详细探讨这个过程：</p>

<h3 id="数据产生与暴露">数据产生与暴露</h3>

<ol>
<li><p><strong>后端服务产生的指标</strong>：对于后端服务（如Web应用、数据库等），指标通常是由服务内部的监控组件生成的。这些组件会根据服务的运行状态（如请求速率、错误率、响应时间等）生成相应的指标数据。为了让Prometheus能够拉取这些数据，服务需要通过某种方式（通常是一个HTTP端点）暴露这些指标。在许多情况下，这可以通过集成Prometheus客户端库来实现，这些库提供了一种简单的方式来收集和暴露指标。</p></li>

<li><p><strong>机器指标的产生</strong>：对于硬件或系统级指标（如CPU使用率、内存使用量、磁盘I/O等），这些数据通常是由操作系统或硬件本身生成的。可以使用诸如Node Exporter之类的工具来收集这些指标，并以Prometheus可以理解的格式暴露在HTTP端点上。Node Exporter是一个由Prometheus社区提供的守护程序，它能够收集系统级指标并暴露给Prometheus服务器。</p></li>
</ol>

<h3 id="应对大量数据和潜在延迟">应对大量数据和潜在延迟</h3>

<p>当监控的目标数量增加或指标量变大时，Prometheus可能会面临数据拉取延迟的问题。这里有几种策略可以帮助缓解这个问题：</p>

<ol>
<li><p><strong>增加拉取间隔</strong>：通过增加Prometheus配置中的拉取间隔，可以减少对目标服务的拉取频率，从而减轻服务器的负载。但这可能会牺牲一些时效性。</p></li>

<li><p><strong>分片和分层收集</strong>：通过将Prometheus服务器分成多个实例，每个实例负责收集部分目标的数据，可以有效分散数据收集的负载。此外，可以使用Prometheus的联邦功能（Federation）来实现分层收集，其中一个Prometheus实例用于收集和聚合多个其他实例的数据。</p></li>

<li><p><strong>使用远程存储</strong>：虽然Prometheus设计为主要在本地存储数据，但它也支持将数据推送到远程存储系统。这可以帮助处理大量数据，并允许使用更强大的查询引擎和长期数据保留策略。</p></li>

<li><p><strong>优化指标和查询</strong>：减少不必要的指标收集，优化PromQL查询，以及合理地设计仪表盘，可以减少对Prometheus服务器的查询压力，从而提高整体性能。</p></li>
</ol>

<p>通过这些方法，可以在监控大规模系统时，有效地管理数据量和减少潜在的延迟问题。</p>

<h2 id="node-exporter">Node Exporter</h2>

<p>以机器指标收集工具 Node Exporter 为例，解释下，是如何提供 HTTP 服务，同时如何组织打点数据，服务内部数据是以什么形式存在，Prometheus 拉取完之后，这部分数据怎么处理，Prometheus 如何找到这些机器（如果我有几十台的话）</p>

<p>Node Exporter 是一个由 Prometheus 社区开发的工具，用于收集 UNIX 和 Linux 系统的硬件和操作系统指标，并以 Prometheus 可理解的格式暴露给 Prometheus 服务器。下面详细解释 Node Exporter 是如何工作的，以及 Prometheus 如何与之交互。</p>

<h3 id="node-exporter-如何提供-http-服务">Node Exporter 如何提供 HTTP 服务</h3>

<ol>
<li><strong>启动 HTTP 服务器</strong>：Node Exporter 本质上是一个守护进程，当启动时，它会在指定的端口（默认是 9100）上启动一个 HTTP 服务器。</li>
<li><strong>暴露指标</strong>：Node Exporter 会收集系统的各种指标，如 CPU 使用率、内存使用、磁盘 I/O 等，并将这些指标以文本格式暴露在 <code>/metrics</code> 路径下的 HTTP 端点上。这些指标会以 Prometheus 的数据格式（即键值对，其中包含指标名称和一系列标签）进行展示。</li>
</ol>

<h3 id="数据组织与内部存储">数据组织与内部存储</h3>

<p>Node Exporter 内部并不存储数据，它实时收集指标并直接暴露给 Prometheus。当 Prometheus 或任何 HTTP 客户端请求 <code>/metrics</code> 端点时，Node Exporter 会实时地收集当前的系统指标并返回。这意味着，Node Exporter 不需要维护内部数据库或任何形式的数据存储。</p>

<h3 id="prometheus-拉取数据的处理">Prometheus 拉取数据的处理</h3>

<p>当 Prometheus 从 Node Exporter 拉取数据时，它会解析 HTTP 响应中的文本格式的指标数据，并将这些数据存储在自己的时间序列数据库中。从那时起，这些数据就可以通过 PromQL 查询、用于警报规则或在 Grafana 等可视化工具中展示。</p>

<h3 id="prometheus-如何找到这些机器">Prometheus 如何找到这些机器</h3>

<p>对于有几十台机器的情况，Prometheus 提供了几种机制来发现和配置监控目标：</p>

<ol>
<li><p><strong>静态配置</strong>：在 Prometheus 的配置文件中，可以静态列出每台机器的地址和端口。这种方法简单直接，但不适合频繁变化的环境。</p></li>

<li><p><strong>服务发现</strong>：更灵活的方法是使用 Prometheus 的服务发现功能。Prometheus 支持多种服务发现机制，如 Kubernetes、Consul、AWS EC2、GCE 等，能够动态发现目标机器。例如，在 Kubernetes 环境中，Prometheus 可以自动发现所有运行 Node Exporter 的 Pod，并从它们收集指标。</p></li>

<li><p><strong>文件服务发现</strong>：对于不支持直接服务发现的环境，Prometheus 还支持文件服务发现，其中目标列表存储在 JSON 或 YAML 文件中。这些文件可以由外部系统动态更新，Prometheus 会定期读取这些文件来获取最新的目标列表。</p></li>
</ol>

<p>通过这些方法，Prometheus 能够有效地管理和监控几十台甚至更多的机器，无论这些机器的网络环境如何变化。</p>

        ]]>
      </description>
    </item>
    
    <item>
      <title>Stable Diffusion 在 Windows 下的容器方案</title>
      <link>https://blog.lierhua.top/tech/stable-diffusion-%E5%9C%A8-windows-%E4%B8%8B%E7%9A%84%E5%AE%B9%E5%99%A8%E6%96%B9%E6%A1%88/</link>
      <pubDate>Sun, 26 Feb 2023 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/stable-diffusion-%E5%9C%A8-windows-%E4%B8%8B%E7%9A%84%E5%AE%B9%E5%99%A8%E6%96%B9%E6%A1%88/</guid>
      <description>
        <![CDATA[
        

<p>Stable Diffusion 在 Windows 上安装依赖会很不好处理，因此我们使用<a href="https://github.com/AbdBarho/stable-diffusion-webui-docker" rel="noreferrer" target="_blank">容器方案</a>。</p>

<h2 id="docker-环境配置">Docker 环境配置</h2>

<p>本方案基于 Docker 配置，而 Docker 实质上是在已经运行的 Linux 下制造了一个隔离的文件环境，它必须部署在 Linux 内核的系统上。因此，Windows 系统想部署 Docker 就必须需要安装一个虚拟 Linux 环境，配置 WSL。</p>

<h3 id="安装-wsl">安装 WSL</h3>

<p>在管理员 PowerShell 输入命令 <code>wsl --install</code>，之后终端会默认安装 Ubuntu。系统下载时间较长，注意别关机。安装 Ubuntu 完成后，按提示设置 Ubuntu 账户和密码。</p>

<p>如果你本来就安装了 WSL 但是是版本 1，就需要提升版本信息，请参考如下的信息</p>

<ul>
<li><a href="https://learn.microsoft.com/zh-cn/windows/wsl/install" rel="noreferrer" target="_blank">检查 WSL 版本与提高 WSL 版本信息</a></li>
<li><a href="https://learn.microsoft.com/zh-cn/windows/wsl/install-manual" rel="noreferrer" target="_blank">旧版系统手动安装 WSL</a></li>
</ul>

<h3 id="安装-docker-容器">安装 docker 容器</h3>

<p>去 docker 官网，根据系统（Windows）下载不同的分发版本，然后跟其他的 Windows 软件一样安装即可。</p>

<p>记得安装完后，在 setting 里面修改下镜像的源，这样能够提高镜像的下载速度。</p>

<p><img src="/images/tech/stable-diffusion/windows-docker.png" alt="" /></p>

<h2 id="stable-duffusion-处理">Stable Duffusion 处理</h2>

<h3 id="下载源文件">下载源文件</h3>

<p>去<a href="https://github.com/AbdBarho/stable-diffusion-webui-docker" rel="noreferrer" target="_blank">这里</a>下载到容器的 docker compose 文件。</p>

<h3 id="安装">安装</h3>

<p>根据 Readme 里的 <a href="https://github.com/AbdBarho/stable-diffusion-webui-docker/wiki/Setup" rel="noreferrer" target="_blank">Setup &amp; Usage</a> 文件，我们要执行两步，一步是下载需要的 model 文件，而是运行对应的 stable diffusion webui</p>

<pre><code>docker compose --profile download up --build
# wait until its done, then:
docker compose --profile [ui] up --build
</code></pre>

<p>需要注意的是，在运行 download 命令时，如果执行到某一步骤特别慢，一般都是运营商网络的问题，建议直接打开手机的热点，电脑连接到热点，把这部分下载慢的地方（一般这种情况不是 VPN 的问题，因为在本机直接 wget 也十分的慢，就是网络运营商的问题）通过热点的方式下载，然后再切换成无线网络下载。</p>

<p>需要的 model 等大的文件下载完毕后，我们开始执行第二部，也就是 <code>docker compose --profile auto up --build</code>  一般我们选择 auto 的方式执行即可，这个时候，可能遇到的问题会有很多。</p>

<p>建议先看下对应的 issue，里面有很多的解决方案，我罗列几个</p>

<ul>
<li><p>docker compose 的文件，在 auto 那里记得加一个 <code>network: host</code> 不然容易出现没法连接 github 的问题</p>

<pre><code>  auto: &amp;automatic
    &lt;&lt;: *base_service
    profiles: [&quot;auto&quot;]
    build:
      context: ./services/AUTOMATIC1111
      network: host
    image: sd-auto:47
    environment:
      - CLI_ARGS=--allow-code --medvram --xformers --enable-insecure-extension-access --api
</code></pre></li>

<li><p>在执行 AUTOMATIC1111 安装的时候，注意 <code>dockerfile</code> 文件，一个是容易出现 download 时一样的问题，就是无法连接 github 的问题，再一个是 <code>pip install git+https://github.com/xxx/xxx@123456</code> 这种情况，十分棘手，因为直接 git clone 对应的仓库是没有问题的，但是 pip install 这么写就是经常 SSL error，这种情况，推荐直接下载下来，然后安装，也就是需要自己修改下 dockerfile 的文件，或者去 gitee 找到镜像版本，改成镜像的地址，如果一直用 <code>git+https://github.com/xxxx</code> 这种形式的话，会一直报错导致无法下载</p></li>

<li><p>在最后如果全部下载完毕后，执行 entrypoint 时，如果报错，一般是 fastapi 的问题，推荐 <code>RUN pip install --upgrade fastapi==0.90.0</code> 来解决这个问题</p></li>
</ul>

<h3 id="model-lora">model &amp;&amp; Lora</h3>

<p>因为目前容器里默认的 model 只有两个，如果我们想使用更多的 model 的话，推荐去<a href="https://huggingface.co/CompVis/stable-diffusion" rel="noreferrer" target="_blank">这里</a>下载对应的 model，然后放到对应的文件夹里，具体的文件夹剪下图，如果是 Lora ，可以去<a href="https://civitai.com/" rel="noreferrer" target="_blank">这里</a>下载
因为 docker compose 里应写了 volumes 的对应关系，所以我们在本地的 data 文件夹里放入对应的文件，docker 容器里的也是会生效的。</p>

<pre><code>    volumes:
      - &amp;v1 ./data:/data
      - &amp;v2 ./output:/output
</code></pre>

<p><img src="/images/tech/stable-diffusion/windows-docker-data.png" alt="" /></p>

<h3 id="使用">使用</h3>

<p>要使用新的 model 和新的 Lora 的方式如下</p>

<p><img src="/images/tech/stable-diffusion/windows-docker-model.png" alt="" /></p>

<hr />

<p>一些参考</p>

<ul>
<li><a href="https://huggingface.co/datasets/HuggingFace-CN-community/translation/blob/main/lora_cn.md" rel="noreferrer" target="_blank">Lora 模型的作用</a></li>
<li><a href="https://soulteary.com/2022/12/09/use-docker-to-quickly-get-started-with-the-chinese-stable-diffusion-model-taiyi.html" rel="noreferrer" target="_blank">中文&rdquo;太乙&rdquo;模型</a></li>
<li><a href="https://sspai.com/post/75544" rel="noreferrer" target="_blank">少数派的一篇介绍的文章</a></li>
<li><a href="https://git-scm.com/download/win" rel="noreferrer" target="_blank">windows Git 的安装</a></li>
</ul>

        ]]>
      </description>
    </item>
    
    <item>
      <title>Stable Diffusion 在家用电脑生成 Ai 图片</title>
      <link>https://blog.lierhua.top/tech/stable-diffusion-%E5%9C%A8%E5%AE%B6%E7%94%A8%E7%94%B5%E8%84%91%E7%94%9F%E6%88%90-ai-%E5%9B%BE%E7%89%87/</link>
      <pubDate>Sun, 26 Feb 2023 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/stable-diffusion-%E5%9C%A8%E5%AE%B6%E7%94%A8%E7%94%B5%E8%84%91%E7%94%9F%E6%88%90-ai-%E5%9B%BE%E7%89%87/</guid>
      <description>
        <![CDATA[
        

<p>这篇文章主要介绍 Stable Diffusion 的安装与不同安装形式的优劣，具体的使用和参数控制等请见另一篇文章。</p>

<h2 id="背景">背景</h2>

<p>人工智能应用层领域在中国封城排队做核酸的 2022 年井喷式的爆发了，从可以生成非常逼真的图片的 midjourney 到可以对话交互的 chatgpt，我感觉我们又像是处在了一个十字路口。</p>

<p>最近在推特上看到好多使用 Stable Diffusion 生成图片的样例，特别是使用了特定的 Lora 后，可以生成一些非常有意思的图片，比如使用新垣结衣的 Lora 然后根据 prompt 的描述，可以生成任意的新垣结衣的图片，于是也想做一下尝试。</p>

<p>Stable Diffusion 是以文本生成图像的 AI 工具，也是唯一一款能部署在家用电脑上的 AI 绘图工具，<strong>可以在 RTX 2060 显卡等 6GB 显存（及以上）显卡下运行</strong>，并在几秒钟内生成图像，无需预处理和后处理。</p>

<p>当然，如果只是想体验 Stable Diffusion，也可以使用在线工具 <a href="https://sspai.com/link?target=https%3A%2F%2Fhuggingface.co%2Fspaces%2Fstabilityai%2Fstable-diffusion" rel="noreferrer" target="_blank">Hugging Face</a> 和 <a href="https://sspai.com/link?target=https%3A%2F%2Fbeta.dreamstudio.ai%2F" rel="noreferrer" target="_blank">DreamStudio</a>。与本地部署相比，Hugging Face 需排队，生成一张图约 5 分钟；DreamStudio 可免费生成 200 张图片，之后需要缴费。更重要的是，这类在线工具对图片的调教功能偏弱，无法批量生成图片，只能用于测试体验。</p>

<p>正好我的显卡还不错，于是打算在本地安装下 Stable Diffusion 的环境，本文就是用来记录整个流程的记录。</p>

<h2 id="准备">准备</h2>

<p>我记得在 2020 年的时候，我在自己的 ubuntu 机器上安装 k8s，准备模拟下线上环境的容器调度，但是因为没有提前做好准备，因此在网络问题上遇到了一些阻碍，这还是基于我科学上网环境具备的情况下。</p>

<p>有了上一次这种的教训，我每次在做新的尝试的时候，都是把准备资料做的足够充分，特别是如果要在自己家用的 Windows 或者 Linux 系统上进行项目尝试，那更要谨慎谨慎再谨慎，不然碰到可能在安装环境的问题上就会有很大的挫败感（Mac 笔记本还好，各种环境都可以随机切换，网络问题不是问题）。</p>

<p>因为我的还不错的显卡是装在家里的台式上的，因此，这次肯定是需要好好做准备工作以免走弯路的。</p>

<h3 id="收集资料">收集资料</h3>

<p>惯例，我先是问了下 chatgpt，给到我的答案中规中矩，是 github 上的 stable diffusion webui <a href="https://github.com/AUTOMATIC1111/stable-diffusion-webui" rel="noreferrer" target="_blank">项目</a>，我浏览了下 readme ，感觉如果是在 Windows 上安装，一定会因为环境问题遇到坑，于是开始于找集成项目或者容器方案。</p>

<h4 id="通用容器方案">通用容器方案</h4>

<p>在 github 上很容易就找到了一个<a href="https://github.com/AbdBarho/stable-diffusion-webui-docker" rel="noreferrer" target="_blank">容器方案</a>，根据此方案的<a href="https://github.com/AbdBarho/stable-diffusion-webui-docker/wiki/Setup" rel="noreferrer" target="_blank">安装描述</a>来看，如果 docker 环境没有问题，应该还是比较容易上手的，并且可以自己下载很多现成的模型来生成自己想要的图片。于是把这个当做一个预备方案之一。</p>

<p>之所以作为一个预案，而不是在 Windows 上直接开始上手，是因为目前我的 Windows 用的还是 WSL 1，但是容器版本依赖的是 WSL 2，对于 Windows 的环境我是实在没有什么信心可以不碰到问题搞好，因此，只是把他当做了一个预案，而不是最终的方案。</p>

<h4 id="mac-下的集成方案">Mac 下的集成方案</h4>

<p>除了容器的方案，在收集资料时发现 Mac 下是有现成的集成方案的，也就是完全不需要自己维护环境，有一个 DuffisonBee 项目，把需要准备的东西打包成了一个 dmg 应用，只需要下载下来然后像对待一个普通的 Mac 应用一样启动就可以，于是此方案作为了一个备选方案，虽然 Mac 下的显卡没有那么好，但是如果一旦 Windows 下没有现成的方案，就用这个做一下尝试。</p>

<h4 id="windows-下的集成方案">Windows 下的集成方案</h4>

<p>然后继续搜索 Windows 下的解决方案，然后发现了，在 Windows 下也有人帮忙封好了一个跟 Mac 差不多的应用 <a href="https://nmkd.itch.io/t2i-gui" rel="noreferrer" target="_blank">NMKD Stable Diffusion GUI</a>，这个也是一样的，下载下来解压后，里面有一个可执行性文件，可以直接使用。</p>

<p><img src="/images/tech/stable-diffusion/windows-sdg-installer.png" alt="" /></p>

<h3 id="决定方案">决定方案</h3>

<p>根据上面的整理，我发现，后两者其实是最容易实现的，基本不用费什么功夫，于是做了这样一个路线，在 Mac 和 Windows 上分别安装集成方案，然后看看是不是功能有缺失，如果没有缺失，那就直接使用这两个，如果发现有功能缺失，然后再考虑在 Windows 上实现容器方案。</p>

<h2 id="安装">安装</h2>

<h3 id="mac-下的-diffusionbee">Mac 下的 DiffusionBee</h3>

<p>过程十分简单，去网站下载 DiffusionBee，然后拖到 Application 里，打开 APP 等待模型下载完毕，这部分用时会比较长，需要耐心等待。结束后，会出现如下的界面，可以简单的尝试下 text2img 的功能，同时<a href="https://arthub.ai/" rel="noreferrer" target="_blank">这个网站</a>还有很多 prompt 的例子。</p>

<p><img src="/images/tech/stable-diffusion/DiffusionBee-GUI.png" alt="" /></p>

<p>使用附录里的 prompt 然后选择需要生成的图片的其他的一些属性，我们生成一个例子看看：</p>

<p><img src="/images/tech/stable-diffusion/DiffusionBee-pic.png" alt="" /></p>

<p>目前在用的 Mac 是 M1 pro + 16GB 内存版的，感觉大概 2 分钟左右就生成了四张图片，并且感觉效果还是十分不错的。</p>

<h4 id="windows-下的-nmkd">Windows 下的 NMKD</h4>

<p>跟 Mac 下的差不多，只不过模型下载不是后置的，是跟集成的软件一起下载的，推荐使用迅雷下载，Windows 虽然我用的不是太多，但是如果直接下载这么大的文件，还是会面临失败的情况，所以还是推荐使用迅雷这种下载工具下载，整个过程非常快，解压过后，会发现有这样一个文件：</p>

<p><img src="/images/tech/stable-diffusion/window-sdg-exe.png" alt="" /></p>

<p>执行这个可执行文件之后，会出现如下的界面，界面略显粗糙，同时，如果一旦 prompt 输入的过于繁琐时，偶尔会报错，图片的展示也不是九宫格的方式，只能一张张的查看。</p>

<p><img src="/images/tech/stable-diffusion/windows-sdg-gui.png" alt="" /></p>

<p>但是对于模型和 Lora 的支持是没有问题的，lora，vae 等都可以直接下载放到对应的 models 文件夹中。</p>

<p><img src="/images/tech/stable-diffusion/windows-sdg-models.png" alt="" /></p>

<p>总的来说，这个应该可以满足我的需求了，但是因为觉得界面确实有些难看，于是，打算也尝试下容器版本，于是就有了下面这个大坑。</p>

<h4 id="windows-下的容器方案">Windows 下的容器方案</h4>

<p>Windows 下的容器方案肯定是有点折腾人的，这点我提前已经有了心理预期，下面就一步步讲具体的流程和遇到的坑，因为涉及的流程比较多，为了不让这一篇显得过于长，因此单独写了一个，流程请参考<a href="/tech/stable-diffusion-在-windows-下的容器方案/">这里</a>。</p>

<p>当我们按照这个步骤完成安装之后，就可以打开 web 界面了。</p>

<p><img src="/images/tech/stable-diffusion/windows-webui-lora.png" alt="" /></p>

<p>我们可以看到这个界面看起来更舒适，并且生成的文件是一个组图，可以总览图片的列表，也可以单独的查看，不同的 model 和 prompt 也标注的比较清晰，lora 也可以直接在 prompt 中用 <a href="lora:gakkiAragakiYui_v2:1" rel="noreferrer" target="_blank">lora:gakkiAragakiYui_v2:1</a> 的方式来写，只需要把对应的 lora 下载好放入到 lora 的目录下即可，其中 <a href="lora:名称:权重" rel="noreferrer" target="_blank">lora:名称:权重</a> 各个字段分别代表这个含义。</p>

<h2 id="结尾">结尾</h2>

<p>Stable Diffusion 我通过调整参数，不断的尝试，发现，对于我来说基本已经够用了，能够生成我想要的多种不同的类型的图片，包括 logo，插画等，人工智能的应用层方案已经如井喷式的发展了，人类的未来会不会像 2017 年乔布斯发布 iPhone 一样，迎来一个新的 10 年的蓬勃发展呢？</p>

<hr />

<p>附录：</p>

<pre><code>使用的 prompt 如下
full body wide shot, woman beautiful face warrior wearing heavy iron armor,insanely detailed and intricate armor , hypermaximalist, elegant, ornate, hyper realistic, super detailed, cinematic light, dark fantasy, ConceptArtWorld, apocalyptic,grouchy, masterpiece,

排除的 prompt 如下
canvas frame, cartoon, 3d, ((disfigured)), ((bad art)), ((deformed)),((extra limbs)),((close up)),((b&amp;w)), weird colors, blurry, (((duplicate))), ((morbid)), ((mutilated)), [out of frame], extra fingers, mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), ((ugly)), blurry, ((bad anatomy)), (((bad proportions))), ((extra limbs)), cloned face, (((disfigured))), out of frame, ugly, extra limbs, (bad anatomy), gross proportions, (malformed limbs), ((missing arms)), ((missing legs)), (((extra arms))), (((extra legs))), mutated hands, (fused fingers), (too many fingers), (((long neck))), Photoshop, video game, ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, mutation, mutated, extra limbs, extra legs, extra arms, disfigured, deformed, cross-eye, body out of frame, blurry, bad art, bad anatomy, 3d render,watermark,signature,no helmet,
</code></pre>

        ]]>
      </description>
    </item>
    
    <item>
      <title>使用 Cloudflare CDN 加速和保护自己的网站</title>
      <link>https://blog.lierhua.top/tech/%E4%BD%BF%E7%94%A8-cloudflare-cdn-%E5%8A%A0%E9%80%9F%E5%92%8C%E4%BF%9D%E6%8A%A4%E8%87%AA%E5%B7%B1%E7%9A%84%E7%BD%91%E7%AB%99/</link>
      <pubDate>Sun, 25 Dec 2022 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/%E4%BD%BF%E7%94%A8-cloudflare-cdn-%E5%8A%A0%E9%80%9F%E5%92%8C%E4%BF%9D%E6%8A%A4%E8%87%AA%E5%B7%B1%E7%9A%84%E7%BD%91%E7%AB%99/</guid>
      <description>
        <![CDATA[
        

<h2 id="背景">背景</h2>

<p>我的好多博客(包括个人在用的博客，archived 的博客，LaTeX 的 wiki 等等)都是部署到 AWS 的 S3 或者阿里云的 OSS 上的。</p>

<p>这些博客或者文档大多都是为了自己便查用的，所以大多的图片文件都是直接使用了 picgo 图床工具通过配置的 github 生成对应的地址，直接用在文档里，并且我的博客生成脚本不在我的工作机器上，而是在云服务器上，所以使用图床工具直接生成链接也就更方便，省下了我在本地处理好图片，然后上传到云服务器的这个过程。</p>

<p><img src="/images/tech/cloudflare-cdn/picgo-github.png" alt="" /></p>

<p>但是有个问题就是，因为 GFW 对 github 的限制，导致图片在国内网络环境访问越来越受限（我自己可以使用科学上网工具，但是有时候有向外分享的情况，图片的加载就成了问题）。</p>

<p>为了解决这个问题，我决定不再把图片上传图床，而是直接放到 <code>static</code> 文件夹同步到 S3，可以通过博客域名访问，但是这就涉及到我需要考虑的第二个问题，CDN 的问题，如果要将图片直接放到文档中，为了防止图片请求量过大，导致我的 S3 或者 OSS 的请求的出网流量过多，造成流量费用的浪费，我需要配置下 CDN 来节约下成本。</p>

<p>对于 S3 我可以直接配置 CDN 加速，并且就算配置域名也没有问题，国外环境对此没有限制，但是有的文档我是部署在阿里云 OSS 的港区的，虽然港区对于域名的配置没有限制（没有做备案的强制要求），但是如果我想配置国区的 CDN，必须要对域名备案进行检查的（备案太麻烦了，我目前只有一个备案域名，我博客使用的 lierhua.top 没有备案）。</p>

<p><img src="/images/tech/cloudflare-cdn/aliyun-oss-beian.png" alt="" /></p>

<p>所以对于 OSS 要进行国内 CDN 加速的话，我就只能用其他的办法了，于是就引出了这篇文章要讲的东西，因为之前在工作中也用过 cloudflare, 所以就直接拿他的免费个人版来用，对网站资源进行加速，同时也可以保护自己的网站。</p>

<h2 id="加速配置">加速配置</h2>

<p>对于 cloudflare 的详细介绍，就不在这里展开了，如果有兴趣，可以访问他们的<a href="https://www.cloudflare-cn.com/about-overview/" rel="noreferrer" target="_blank">官方网站</a>查看.</p>

<p><img src="/images/tech/cloudflare-cdn/cloudflare-function.jpeg" alt="" /></p>

<p>通过使用 Cloudflare CDN 服务提供的全球节点，一方面可以提高网站响应速度和性能(付费版更明显)，节省源站资源；另一方面也可以保护站点抵御攻击，保证网站长期稳定在线。</p>

<h3 id="添加站点">添加站点</h3>

<p>cloudflare 的注册特别简单，只需要点击 signup, 然后输入邮箱和密码即可（我喜欢这些只需要邮箱就可以注册的公司，不喜欢那些还需要电话号码的，当然 telegram 是个例外，相比于 telegram 的优点，这个缺憾我可以包容）。</p>

<p>然后点击最上边的「添加站点」即可增加自己想要进行 CDN 加速的站点：</p>

<p><img src="/images/tech/cloudflare-cdn/cloudflare-add-site.png" alt="" /></p>

<p>我以一个域名 <code>zhuge.live</code> 为例，把整个流程过一遍（这个域名当时是给我的一个学弟申请的，他之前写微信公众号，写了很多篇，我之前答应过给他集结在一块儿的，因此就有了「诸葛实况」这个文章集）。</p>

<p><img src="/images/tech/cloudflare-cdn/zhuge-live.png" alt="" /></p>

<p>下一步之后，我们选择那个免费的版本就行，对于个人版而言，完全够用了，当然如果你想支持 cloudflare 也可以付费。</p>

<p><img src="/images/tech/cloudflare-cdn/cloudflare-version.png" alt="" /></p>

<p>点击继续后，这时 Cloudflare 会自动扫描域名已有的 DNS 解析记录，如果扫描到的话，会显示在下面。没有或者显示不正确，则需要我们自己添加设置。</p>

<p><img src="/images/tech/cloudflare-cdn/cloudflare-cdn-scan.jpg" alt="" /></p>

<p>第一次扫描，没有扫描到任何的记录，于是我回阿里云的域名处，增加了一个 www 的 CNAME 记录。</p>

<p><img src="/images/tech/cloudflare-cdn/aliyun-add-www.jpg" alt="" /></p>

<p>同时在 cloudflare 重新添加了下记录，如下：</p>

<p><img src="/images/tech/cloudflare-cdn/cloudflare-www-zhuge-live.webp" alt="" /></p>

<p>我们看到这个时候已经有记录显示出来了，黄色就表示已经接入 CDN 了，我们接下来点击继续，继续下一步，去配置我们的 DNS 地址。</p>

<p><img src="/images/tech/cloudflare-cdn/cloudflare-cdn-change.webp" alt="" /></p>

<p>我们按照流程的要求，找到我们这个域名的 whois 方，然后去对应的平台，修改对应的 DNS 的配置，因为这个 <code>zhuge.live</code> 是我在阿里云申请的，因此需要到阿里云里修改这个域名的 DNS 配置，具体涉及到以下内容, 我们需要从上一步，cloudflare 给定的 DNS 地址，然后去到阿里云配置上，当然如果你使用的是 godaddy（我部署在 S3 的域名配置基本都是在 godaddy 申请的），也有自己的流程，可以根据网站 wiki 获取到方式。</p>

<p><img src="/images/tech/cloudflare-cdn/aliyun-chang-dns-1.webp" alt="" />
<img src="/images/tech/cloudflare-cdn/aliyun-change-dns-2.png" alt="" /></p>

<p>至此，配置好后，点击「完成，检查服务名」，就会到下面一步，我们需要点击如何「检查服务器名称」即可</p>

<p><img src="/images/tech/cloudflare-cdn/cloudflare-check-host.png" alt="" /></p>

<p>之后，我们会收到 cloudflare 一封邮件，告知我们已经将我们的 <code>zhuge.live</code> 添加到 free 计划中，状态为活跃。</p>

<p>到此为止，我们给我们的网站添加 CDN 支持就完成了，接下来，我们看看他对应的看板和效果.</p>

<h3 id="查看加速看板">查看加速看板</h3>

<p>由于 <code>zhuge.live</code> 刚添加，所以没有什么流量，我们看下 <code>lierhua.top</code> 这个域名的缓存情况吧</p>

<p><img src="/images/tech/cloudflare-cdn/cloudflare-lierhua-dash.webp" alt="" /></p>

<p>可以看到过去 24 小时的总请求数还有被 cloudflare 缓存的请求数。</p>

<h3 id="常见问题">常见问题</h3>

<p>1.修改域名服务器后，Cloudflare 检测不到</p>

<p>DNS 生效是需要一定时间的，确认自己的修改无误后，耐心等待一段时间，你会收到一封电子邮件，它的名称可能如下：已将 domain.com 添加到 Cloudflare xxx计划中</p>

<p>2.开启 Cloudflare CDN 后网站访问速度反而变慢了很多？</p>

<p>Cloudflare 的 CDN 节点大多在国外（免费版），国内用户访问速度不稳定，对于国外访问速度很快。
比较适合主要面向国外访客的网站；或者不在意速度，想节省源站资源的情况；又或者主要想使用它的保护功能的用户；</p>

<hr />

<p>参考：</p>

<ul>
<li><a href="https://cloud.tencent.com/developer/article/2101425" rel="noreferrer" target="_blank">https://cloud.tencent.com/developer/article/2101425</a></li>
</ul>

        ]]>
      </description>
    </item>
    
    <item>
      <title>广告归因</title>
      <link>https://blog.lierhua.top/tech/%E5%B9%BF%E5%91%8A%E5%BD%92%E5%9B%A0%E7%9B%B8%E5%85%B3/</link>
      <pubDate>Fri, 31 Dec 2021 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/%E5%B9%BF%E5%91%8A%E5%BD%92%E5%9B%A0%E7%9B%B8%E5%85%B3/</guid>
      <description>
        <![CDATA[
        

<h2 id="背景">背景</h2>

<p>媒体在新开渠道（大部分媒体），或者新开账户（广点通等渠道），或者增加新的转化事件（小米商店等）时需要根据媒体的联调文档进行联调后，才可以进行实际的投放。
但是运营或者开发在联调过程中会碰到很多问题，包括但不限于广告点击的获取（各个渠道不一致），联调设备 ID 等关键设备信息的获取，以及是否要进行模拟回传（比如次留无法当日回传，需要模拟回传）。
为了缩短投放前的准备流程，降低运营和研发的工作量，整理如下各个渠道联调的文档和 iOS 和安卓的设备获取方式。</p>

<h2 id="设备归因">设备归因</h2>

<h3 id="ios-获取设备信息">iOS 获取设备信息</h3>

<p>iOS 有两种类型的设备 ID</p>

<ol>
<li>IDFA: Identifier for Advertising</li>
<li>IDFV: identifier For Vendor</li>
</ol>

<h4 id="idfa-归因设备类型">IDFA：归因设备类型</h4>

<p>每个设备只有一个IDFA，不同 APP 在同一设备上获取 IDFA 的结果是一样的。
但是 14.5 之后苹果增加一项新隐私功能， 即要求 APP 开发者必须在经过用户的同意之后，才能追踪用户并且访问其设备的 IDFA，如果用户在设置中禁用了广告跟踪，IDFA 就会变为全 0 的标识符。
因此目前来看，IDFA 的获取率不足 30%，因此，以 IDFA 作为归因的唯一设备就很难跑起来。</p>

<h4 id="idfv-非归因设备类型">IDFV：非归因设备类型</h4>

<p>是用来标识应用程序开发商的唯一标识符。它是在用户安装应用程序时随机生成的，用来识别同一个开发商的所有应用程序，同一个开发商在一台 iPhone 上的 IDFV 都是一致的。
不同开发商之间的 IDFV 是不一致的，所以没法用来进行归因，但是如果一个开发商有多个 App 的话，可以进行交叉推广。</p>

<h4 id="设备获取方式">设备获取方式</h4>

<p>首先打开「允许 App 请求跟踪」&ndash;&gt;  App store 搜索 deviceid 下载对应的 App，&ndash;&gt; 安装完成后，选择允许跟踪，然后即可查看对应的 IDFA 信息。</p>

<h3 id="安卓获取设备信息">安卓获取设备信息</h3>

<ol>
<li>OAID：Open Anonymous Device Identifier</li>
<li>IMEI：International Mobile Equipment Identity</li>
<li>ANDROID_ID</li>
</ol>

<p>Android10 以后获取不到 IMEI；Android8 以后，Android_ID 跨应用不一致</p>

<h4 id="oaid-归因设备类型">OAID：归因设备类型</h4>

<p>广告标识符是一种非永久性设备标识符。使用OAID可在保护用户个人数据隐私安全的前提下,向用户提供个性化广告。国内 App 和广告跟踪服务的一种替代方案。</p>

<h4 id="imei-归因设备类型-不推荐作为归因设备类型">IMEI：归因设备类型（不推荐作为归因设备类型）</h4>

<p>运营商识别入网设备信息的代码，是一种不可重置的永久标识符，作用域为设备。Android10 以后获取不到 IMEI，随着安卓设备的升级，IMEI 获取率会越来越低，因此，IMEI 后续也不会继续被作为归因设备类型。</p>

<h4 id="android-id-非归因设备类型">ANDROID_ID: 非归因设备类型</h4>

<p>Android ID 是 Android 设备里不依赖于硬件的一种「半永久标识符」，在系统生命周期内不会改变，但系统重置或刷机后会发生变化，其作用域为一组有关联的应用。</p>

<h4 id="安卓设备获取方式">安卓设备获取方式</h4>

<p>安卓手机扫描二维码下载对应的 App 显示对应的设备信息。</p>

<h2 id="模糊归因">模糊归因</h2>

<p>见此<a href="/file/ipua.pdf">文档</a></p>

        ]]>
      </description>
    </item>
    
    <item>
      <title>kafka 内网部署公网访问</title>
      <link>https://blog.lierhua.top/tech/20.-kafka-%E5%86%85%E7%BD%91%E9%83%A8%E7%BD%B2%E5%85%AC%E7%BD%91%E8%AE%BF%E9%97%AE/</link>
      <pubDate>Fri, 10 Sep 2021 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/20.-kafka-%E5%86%85%E7%BD%91%E9%83%A8%E7%BD%B2%E5%85%AC%E7%BD%91%E8%AE%BF%E9%97%AE/</guid>
      <description>
        <![CDATA[
        <p>关键词： <code>kafka</code> , <code>ubuntu</code> , <code>frp</code></p>

<blockquote>
<p><a href="https://daimajiaoliu.com/daima/4796f8688100404" rel="noreferrer" target="_blank">参考的文章</a></p>
</blockquote>

<h2 id="背景">背景</h2>

<p>我有一台公网机器，但是机器的性能不好，无法安装 kafka，但是我的工作中又有大量的需要用到 kafka 的时候，家里有一台性能还不错的工作站，装的是 ubuntu 20.04, <a href="http://blog.lierhua.top/post/5.-ubuntu-%E4%B8%8B-frp-%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/" rel="noreferrer" target="_blank">之前的文章</a>里提到了用 frp 内网穿透在工作站部署服务，通过外网服务器提供服务，既然 http 服务可以这么处理，那么其他类型的服务应该也可以，所以打算在内网部署一套 kafka 供工作服务测试使用。</p>

<p>现把步骤梳理一下，先不讲解为什么一些步骤要按照这样搞，最后写原因。</p>

<h2 id="frp">frp</h2>

<p>frp 如何安装以及配置在<a href="http://blog.lierhua.top/post/5.-ubuntu-%E4%B8%8B-frp-%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/" rel="noreferrer" target="_blank">之前的文章</a>里也写过了，这里不过多的赘述， 当涉及到 frp 的时候，我就只贴配置了</p>

<h2 id="公网机器">公网机器</h2>

<h3 id="frp-1">frp</h3>

<p>公网 frp 的配置见之前的文档</p>

<h3 id="hosts">hosts</h3>

<pre><code>#  配置映射
#  x.x.x.x 为阿里云服务器的内网 ip 
#  y.y.y.y 为阿里云服务器的公网 ip 
#  kafka.com 为内网环境 kafka ——&gt; advertised.listeners 配置的内网域名
x.x.x.x kafka.com
y.y.y.y kafka.com
</code></pre>

<h2 id="内网机器">内网机器</h2>

<h3 id="frp-2">frp</h3>

<pre><code class="language-ini">[common]
server_addr = y.y.y.y 
server_port = 7000
token = 123456

[kafka]
type = tcp
local_ip = z.z.z.z
local_port = 9092
remote_port = 9092
</code></pre>

<h3 id="hosts-1">hosts</h3>

<pre><code>#  配置映射
#  z.z.z.z 为内网环境 kafka 的 ip， 可以认为就是内网机器的内网 ip
#  kafka.com 为内网环境 kafka ——&gt; advertised.listeners 配置的内网域名
z.z.z.z kafka.com
</code></pre>

<h3 id="docker-comose-yaml">docker-comose.yaml</h3>

<p>我为了方便，在内网中使用了 docker-compse 部署了 kafka，贴一下对应的配置。</p>

<pre><code class="language-yaml">version: '3.7'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    volumes:
      - ./data:/data
    ports:
      - 2182:2181

  kafka9094:
    image: wurstmeister/kafka
    ports:
      - 9092:9092
    environment:
      KAFKA_BROKER_ID: 0
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka.com:9092  ## 特别注意这里用的是 kafka.com 域名，就是我们 hosts 里配的域名
      KAFKA_CREATE_TOPICS: &quot;&quot;
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
    volumes:
      - ./kafka-logs:/kafka
    depends_on:
      - zookeeper

</code></pre>

<p>然后 docker-compose up -d 启动就好，注意一定要在 hosts 里配置好内网域名对应 kafka.com 后才能启动，不然一定会出错。</p>

<h2 id="producer-consumer-机器">producer &amp; consumer 机器</h2>

<h3 id="hosts-2">hosts</h3>

<pre><code>#  y.y.y.y 为阿里云服务器的公网 ip 
#  kafka.com 为内网环境 kafka ——&gt; advertised.listeners 配置的内网域名
y.y.y.y kafka.com
</code></pre>

<p>一定要配置好公网 ip 对应 kafka 的域名。</p>

<p>然后 producer &amp; consumer 调用时用 kafka.com 即可</p>

<h3 id="producer-consumer">producer &amp; consumer</h3>

<pre><code class="language-go">brokerList = kingpin.Flag(&quot;brokerList&quot;, &quot;List of brokers to connect&quot;).Default(&quot;kafka.com:9092&quot;).Strings()
</code></pre>

<h2 id="理顺">理顺</h2>

<p>当我们在 producer 发送消息时，用了 kafka.com 根据 hosts 会路由到 y.y.y.y 机器，也就是我们的公网机器，然后公网机器因为部署了内网穿透，所以 9092 端口会发送到内网机器的 9092 端口，同时因为公网机器的 hosts 里也配置了 y.y.y.y 到 kafka.com 映射，因此到了内网后还是用的 kafka.com 进行的，而内网也配置了 z.z.z.z 到 kafka.com 的映射，因此访问的就是 z.z.z.z，这样整个流程就串起来了。</p>

<h2 id="原理">原理</h2>

<p>advertised.listeners=PLAINTEXT://kafka.com:9092 配置的地址必须要能连通，一般配置为外网地址，因为 kafka 会将这个 ip 和 port 记录在 zookeeper 上，当外网访问时直接通过这个地址连接（如果未配置这个参数，则外网会拿到内网的 IP，从而无法访问）</p>

<pre><code>   但是由于 frp 的特殊性，frp 映射之后，只能外网的服务器本身能访问，因为防火墙只开放了 22 远程端口 ，9092 并未开放 ，因此内网的 kafka 无法访问。所以需要配置一个内网域名 kafka.com，在内网服务器中配置映射（z.z.z.z kafka.com）, 在 kafka 启动的时候，会去连接 kafka.com:9092 ,正常访问。而外网服务器在zookeeper 中找到 kafka.com:9092 的连接地址，也需要映射 （y.y.y.y  kafka.com） ， 使得外网服务器也能通过 9092 端口正常访问，问题解决。

    kafka 端口 9092 必须与 frp 映射的一致。
</code></pre>

<p>advertised.listeners 在 kafka 启动时，必须要能连接，所以一定要配置成域名，然后在 host 配置映射。当在外网访问时，拿到这个域名，并且在外网本机配置 host 映射，从而正确访问。</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/7f46c9bcf4e0755ed5ee344e2a622cbb.png" alt="" /></p>
        ]]>
      </description>
    </item>
    
    <item>
      <title>postgres 常用命令速查</title>
      <link>https://blog.lierhua.top/tech/22.-postgres-%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/</link>
      <pubDate>Mon, 10 Aug 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/22.-postgres-%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>ubuntu</code>, <code>postgres</code></p>

<h2 id="数据库和表相关">数据库和表相关</h2>

<p>登录数据库：</p>

<pre><code class="language-bash">PGPASSWORD='password' psql -h host_addr -U dbp_lierhua -d 'database_name' -p 5438
</code></pre>

<p>导出指定数据库的全部表 schema:</p>

<pre><code class="language-bash">pg_dump -h host_addr -p 5438 -U dbp_lierhua database_name -s -n yay &gt; result.sql

-t 后面跟表名字，没有 -t 的话，直接跟数据库名字即可， -n 指定对应的 schema 的名字, -s  选项用来只导出表结构，而不会导出表中的数据
</code></pre>

<p>导出指定表的 schema 和所有数据:</p>

<pre><code class="language-bash">pg_dump -h host_addr -p 5438 -U dbp_lierhua yay.table_name -t database_name &gt; result.sql

-t 后面跟表名字，没有 -t 的话，直接跟数据库名字即可， -n 指定对应的 schema 的名字, -s  选项用来只导出表结构，而不会导出表中的数据
pg_dump -h pg-market-mm.db.vip.p2staff.com -p 5438 -U dbp_lierhua putong-mm -t rta_new &gt; rta_new.sql
</code></pre>

<p>导出指定表的 schema:</p>

<pre><code class="language-bash">pg_dump -h host_addr -p 5438 -U dbp_lierhua -t yay.table_name database_name -s &gt; result.sql

-t 后面跟表名字，没有 -t 的话，直接跟数据库名字即可， -n 指定对应的 schema 的名字, -s  选项用来只导出表结构，而不会导出表中的数据
</code></pre>

<p>创建数据库：</p>

<pre><code class="language-sql">CREATE DATABASE &quot;database_name&quot;; -- 记得带双引号
</code></pre>

<p>创建 schema 并应用到数据库:</p>

<pre><code class="language-sql">CREATE schema yay
ALTER database &quot;database_name&quot; set search_path to &quot;yay&quot;;
</code></pre>

<p>释放数据库 schema 到目标库：</p>

<pre><code class="language-bash">PGPASSWORD='你的密码' psql -d database_name -U postgres -h 39.16.18.10(你机器的IP或者域名) -p 5432 -f ~/Desktop/database_name.sql
-d 指定要释放到的数据库
-U 用户名
-h 机器的地址
-p 机器开放的端口，不写默认是 5432
-f 要释放的文件的地址
</code></pre>

<p>不导出全表数据，导出部分数据到 CSV：</p>

<pre><code class="language-shell">\COPY (SELECT * FROM table_name where id = '1157692') TO '/home/lierhua/result.test.csv' WITH csv; (postgres 里执行, 因此无需密码)

\COPY (select user_id, change_value, to_char(created, 'DD-MM-YYYY')  from coin_history) TO '/mnt/data/new/result.csv' WITH (FORMAT CSV, HEADER);

</code></pre>

<p>导出的部分表数据释放到其他库的表里：</p>

<pre><code class="language-shell">\COPY ads_material FROM '~/Desktop/ads_material.test.csv' WITH csv; (postgre 里执行，因此无需密码)

\COPY 目标数据表 from 'csv 地址' with csv;
</code></pre>

<h2 id="查询命令相关">查询命令相关</h2>

<p>array 查询：</p>

<pre><code class="language-sql">select * from table_name where files @&gt; array['https://lalala.com/v1/raw/5fa29ae1-949a-4b74-aa72-99ef78c5506907.mp4']::varchar[] limit 1;

select * from table_name where app_name @&gt; array['name']::text[] limit 5;
</code></pre>

<hr />

<h2 id="参考">参考</h2>

<ul>
<li><a href="https://www.tutorialspoint.com/postgresql/postgresql_schema.htm" rel="noreferrer" target="_blank">速查文档</a></li>
</ul>
        ]]>
      </description>
    </item>
    
    <item>
      <title>如何给 Mac 更换 APP 图标</title>
      <link>https://blog.lierhua.top/tech/23.-%E5%A6%82%E4%BD%95%E7%BB%99-mac-app-%E6%9B%B4%E6%8D%A2%E5%9B%BE%E6%A0%87/</link>
      <pubDate>Mon, 10 Aug 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/23.-%E5%A6%82%E4%BD%95%E7%BB%99-mac-app-%E6%9B%B4%E6%8D%A2%E5%9B%BE%E6%A0%87/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>mac</code>, <code>icon</code></p>

<h2 id="图标从哪里来">图标从哪里来</h2>

<p>图标可以是网页上的任何的 png 图标, <a href="https://github.com/dhanishgajjar/vscode-icons" rel="noreferrer" target="_blank">安装方式参考</a></p>

<hr />

<h2 id="参考">参考</h2>

<ul>
<li><a href="https://github.com/dhanishgajjar/vscode-icons" rel="noreferrer" target="_blank">vs code 更变 Mac 图标</a></li>
<li><a href="https://www.jetbrains.com/company/brand/" rel="noreferrer" target="_blank">jetbrain 图标</a></li>
</ul>
        ]]>
      </description>
    </item>
    
    <item>
      <title>ansible 的一个典型例子</title>
      <link>https://blog.lierhua.top/tech/ansible-%E5%85%B8%E5%9E%8B%E4%BE%8B%E5%AD%90%E4%BB%8B%E7%BB%8D/</link>
      <pubDate>Sat, 16 May 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/ansible-%E5%85%B8%E5%9E%8B%E4%BE%8B%E5%AD%90%E4%BB%8B%E7%BB%8D/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>ansible</code></p>

<pre><code class="language-tree">例子的tree
├── Makefile  # makefile 文件
├── ansible.cfg    # ansible 配置文件，存放的是一些基本的ssh等的配置
├── group_vars  # 
│   └── all
├── hosts  # inventory 设置，用于配置与主机和主机组相关的东西， 是 inventory 主文件
├── roles  # 存放的是playbook可以执行的role有关的所有的东西
│   ├── base-env
│   │   └── vars
│   │       └── main.yml
│   └── goldeneye
│       ├── files
│       │   ├── gitconfig
│       │   ├── logrotate.conf
│       │   └── supervisord.conf
│       ├── meta
│       │   └── main.yml
│       ├── tasks
│       │   └── main.yml
│       ├── templates
│       │   ├── aethas.supervisor.conf.j2
│       │   ├── aws.config.j2
│       │   ├── prod_config.json.j2
│       │   └── test_config.json.j2
│       └── vars
│           └── main.yml
└── site.yml  # 执行playbook命令时需要携带的配置文件，这里面定义了 playbook 应用的机器（inventory配置的，通过名字去选择）和 执行的role （roles里配置的，通过名字选择）
</code></pre>

<p>关于hosts文件（inventory 文件）
&gt; 在 inventory 主文件中保存所有的变量并不是最佳的方式.还可以保存在独立的文件中,这些独立文件与 inventory 文件保持关联. 不同于 inventory 文件(INI 格式),这些独立文件的格式为 YAML</p>

<p>换句话说，如果hosts里的机器等配置特别多，特别杂，适合单开新的 host<em>vars 和 group</em>vars来定义配置，但是如果机器很少，甚至只有一台，那么完全可以直接用 hosts 就好了</p>

<p>比如可以转成如下的形式：</p>

<pre><code>├── ansible.cfg
├── group_vars
│   └── goldeneye-test   # hosts里有一个goldeneye-test的机器，在这里可以对应放置这个机器的配置，比如ssh key 的地址等等~
├── hosts
├── roles
</code></pre>

<hr />

<p>执行的一个playbook的命令：</p>

<p><code>ansible-playbook -i hosts --become --become-method sudo -f 2 -e &quot;app_version=$(VERSION)&quot; site.yml</code></p>

<p>简单配置解释
- -i 后面跟的是inventory配置文件（机器与机器组）
- &ndash;become 是一个bool值，因此后面不跟参数，这个参数的意思指的是ansible在目标机器上运行时需要进行提权运行（切换更高的user），true代表提权
- &ndash;become-method 后面接的参数是提权后的用户，后面接的参数代表提权为 root 用户
- -f 并行任务数 参数2 代表并行为2
- -e 在Playbook中引入外部参数变量, 这里定义好的app_version变量，可以直接在 role 里使用
- site.yml 配置文件，携带着需要在哪些机器上运行 playbook 和运行哪些role的配置信息，以及一些role里使用的变量文件</p>

<p>playbook 可携带的参数详解</p>

<pre><code class="language-yaml">Options:
  --ask-vault-pass      
             #ask for vault password
             #加密playbook文件时提示输入密码
  -C, --check           
             #don't make any changes; instead, try to predict some of the changes that may occur
             #模拟执行，不会真正在机器上执行(查看执行会产生什么变化)
  -D, --diff            
             #when changing (small) files and templates, show the differences in those files; works great with --check
             #当更新的文件数及内容较少时，该选项可显示这些文件不同的地方，该选项结合-C用会有较好的效果
  -e EXTRA_VARS, --extra-vars=EXTRA_VARS
             #set additional variables as key=value or YAML/JSON
             #在Playbook中引入外部参数变量
  --flush-cache         
             #clear the fact cache
             #将fact清除到的远程主机缓存
  --force-handlers      
             #run handlers even if a task fails
             #强制运行handlers的任务，即使在任务失败的情况下
  -f FORKS, --forks=FORKS
             #specify number of parallel processes to use(default=5)
             #并行任务数。FORKS被指定为一个整数,默认是5
  -h, --help            
             #show this help message and exit
             #打开帮助文档API
  -i INVENTORY, --inventory-file=INVENTORY
             #specify inventory host path (default=/etc/ansible/hosts) or comma separated host list.
             #指定要读取的Inventory文件
  -l SUBSET, --limit=SUBSET
             #further limit selected hosts to an additional pattern
             #限定执行的主机范围
  --list-hosts          
             #outputs a list of matching hosts; does not execute anything else
             #列出执行匹配到的主机，但并不会执行
  --list-tags           
             #list all available tags
             #列出所有可用的tags
  --list-tasks          
             #list all tasks that would be executed
             #列出所有即将被执行的任务
  -M MODULE_PATH, --module-path=MODULE_PATH
             #specify path(s) to module library (default=None)
             #要执行的模块的路径
  --new-vault-password-file=NEW_VAULT_PASSWORD_FILE
             #new vault password file for rekey
             #
  --output=OUTPUT_FILE  
             #output file name for encrypt or decrypt; use - for stdout
             #
  --skip-tags=SKIP_TAGS
             #only run plays and tasks whose tags do not match these values
             #跳过指定的tags任务
  --start-at-task=START_AT_TASK
             #start the playbook at the task matching this name
             #从第几条任务(START_AT_TASK)开始执行
  --step                
             #one-step-at-a-time: confirm each task before running
             #逐步执行Playbook定义的任务，并经人工确认后继续执行下一步任务
  --syntax-check        
             #perform a syntax check on the playbook, but do not execute it
             #检查Playbook中的语法书写,并不实际执行
  -t TAGS, --tags=TAGS  
             #only run plays and tasks tagged with these values
             #指定执行该tags的任务
  --vault-password-file=VAULT_PASSWORD_FILE
             #vault password file
             #
  -v, --verbose         
             #verbose mode (-vvv for more, -vvvv to enable connection debugging)
             #执行详细输出
  --version             
             #show program's version number and exit
             #显示版本

  Connection Options:
    control as whom and how to connect to hosts

    -k, --ask-pass      
             #ask for connection password
             #
    --private-key=PRIVATE_KEY_FILE, --key-file=PRIVATE_KEY_FILE
             #use this file to authenticate the connection
             #
    -u REMOTE_USER, --user=REMOTE_USER
             #connect as this user (default=None)
             #指定远程主机以USERNAME运行命令
    -c CONNECTION, --connection=CONNECTION
             #connection type to use (default=smart)
             #指定连接方式，可用选项paramiko (SSH)、ssh、local，local方式常用于crontab和kickstarts
    -T TIMEOUT, --timeout=TIMEOUT
             #override the connection timeout in seconds(default=10)
             #SSH连接超时时间设定，默认10s
    --ssh-common-args=SSH_COMMON_ARGS
             #specify common arguments to pass to sftp/scp/ssh (e.g.ProxyCommand)
             #
    --sftp-extra-args=SFTP_EXTRA_ARGS
             #specify extra arguments to pass to sftp only (e.g. -f, -l)
             #
    --scp-extra-args=SCP_EXTRA_ARGS
             #specify extra arguments to pass to scp only (e.g. -l)
             #
    --ssh-extra-args=SSH_EXTRA_ARGS
             #specify extra arguments to pass to ssh only (e.g. -R)
             #

  Privilege Escalation Options:
    control how and which user you become as on target hosts

    -s, --sudo          
             #run operations with sudo (nopasswd) (deprecated, use become)
             #相当于Linux系统下的sudo命令
    -U SUDO_USER, --sudo-user=SUDO_USER
             #desired sudo user (default=root) (deprecated, use become)
             #使用sudo，相当于Linux下的sudo命令
    -S, --su            
             #run operations with su (deprecated, use become)
             #
    -R SU_USER, --su-user=SU_USER
             #run operations with su as this user (default=root)(deprecated, use become)
    -b, --become        
             #run operations with become (does not imply password prompting)
             #
    --become-method=BECOME_METHOD
             #privilege escalation method to use (default=sudo),valid choices: [ sudo | su | pbrun | pfexec | doas |dzdo | ksu | runas ]
             #
    --become-user=BECOME_USER
             #run operations as this user (default=root)
             #
    --ask-sudo-pass     
             #ask for sudo password (deprecated, use become)
             #传递sudo密码到远程主机，来保证sudo命令的正常运行
    --ask-su-pass       
             #ask for su password (deprecated, use become)
             #
    -K, --ask-become-pass
             #ask for privilege escalation password
             #
</code></pre>

<hr />

<p>ansible配置文件，ansible.cfg
Ansible 的配置文件的查找顺序如下：</p>

<ul>
<li>环境变量 ANSIBLE_CONFIG</li>
<li>当前目录下的 ansible.cfg  （这个比较重要，一般用这个比较多）</li>
<li>home 目录下的 ~/.ansible.cfg</li>
<li>/etc/ansible/ansible.cfg</li>
</ul>

<p>Ansible 使用找到的第一个文件，忽略其余的。</p>

<p>配置文件的几个组成部分:
- [defaults]   &mdash;&gt;通用默认配置
- [privilege<em>escalation] &mdash;&gt; 提权配置
- [paramiko</em>connection]
- [ssh_connection]
- [accelerate]</p>

<p>例子：</p>

<pre><code class="language-cfg">[defaults]   ---&gt;通用默认配置

# some basic default values...

inventory      = /etc/ansible/hosts     这个是默认库文件位置,脚本,或者存放可通信主机的目录
#library        = /usr/share/my_modules/   Ansible默认搜寻模块的位置
remote_tmp     = $HOME/.ansible/tmp   Ansible 通过远程传输模块到远程主机,然后远程执行,执行后在清理现场.在有些场景下,你也许想使用默认路径希望像更换补丁一样使用
pattern        = *    如果没有提供“hosts”节点,这是playbook要通信的默认主机组.默认值是对所有主机通信
forks          = 5    在与主机通信时的默认并行进程数 ，默认是5d
poll_interval  = 15    当具体的poll interval 没有定义时,多少时间回查一下这些任务的状态, 默认值是5秒
sudo_user      = root   sudo使用的默认用户 ，默认是root
#ask_sudo_pass = True   用来控制Ansible playbook 在执行sudo之前是否询问sudo密码.默认为no
#ask_pass      = True    控制Ansible playbook 是否会自动默认弹出密码
transport      = smart   通信机制.默认 值为’smart’。如果本地系统支持 ControlPersist技术的话,将会使用(基于OpenSSH)‘ssh’,如果不支持讲使用‘paramiko’.其他传输选项包括‘local’, ‘chroot’,’jail’等等
#remote_port    = 22    远程SSH端口。 默认是22
module_lang    = C   模块和系统之间通信的计算机语言，默认是C语言

# plays will gather facts by default, which contain information about
# the remote system.
#
# smart - gather by default, but don't regather if already gathered# implicit - gather by default, turn off with gather_facts: False
# explicit - do not gather by default, must say gather_facts: True
gathering = implicit   控制默认facts收集（远程系统变量）. 默认值为’implicit’, 每一次play,facts都会被收集

# additional paths to search for roles in, colon separated
#roles_path    = /etc/ansible/roles   roles 路径指的是’roles/’下的额外目录,用于playbook搜索Ansible roles

# uncomment this to disable SSH key host checking
#host_key_checking = False    检查主机密钥

# change this for alternative sudo implementations
sudo_exe = sudo     如果在其他远程主机上使用另一种方式执sudu操作.可以使用该参数进行更换

# what flags to pass to sudo   传递sudo之外的参数
#sudo_flags = -H

# SSH timeout    SSH超时时间
timeout = 10# default user to use for playbooks if user is not specified
# (/usr/bin/ansible will use current user as default)
#remote_user = root   使用/usr/bin/ansible-playbook链接的默认用户名，如果不指定，会使用当前登录的用户名

# logging is off by default unless this path is defined
# if so defined, consider logrotate
#log_path = /var/log/ansible.log     日志文件存放路径

# default module name for /usr/bin/ansible
#module_name = command     ansible命令执行默认的模块

# use this shell for commands executed under sudo
# you may need to change this to bin/bash in rare instances
# if sudo is constrained
#executable = /bin/sh     在sudo环境下产生一个shell交互接口. 用户只在/bin/bash的或者sudo限制的一些场景中需要修改

# if inventory variables overlap, does the higher precedence one win
# or are hash values merged together?  The default is 'replace' but
# this can also be set to 'merge'.
#hash_behaviour = replace    特定的优先级覆盖变量

# list any Jinja2 extensions to enable here:
#jinja2_extensions = jinja2.ext.do,jinja2.ext.i18n      允许开启Jinja2拓展模块

# if set, always use this private key file for authentication, same as # if passing --private-key to ansible or ansible-playbook
#private_key_file = /path/to/file         私钥文件存储位置

# format of string {{ ansible_managed }} available within Jinja2 
# templates indicates to users editing templates files will be replaced.
# replacing {file}, {host} and {uid} and strftime codes with proper values.
ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}   这个设置可以告知用户,Ansible修改了一个文件,并且手动写入的内容可能已经被覆盖.

# by default, ansible-playbook will display &quot;Skipping [host]&quot; if it determines a task
# should not be run on a host.  Set this to &quot;False&quot; if you don't want to see these &quot;Skipping&quot; # messages. NOTE: the task header will still be shown regardless of whether or not the 
# task is skipped.
#display_skipped_hosts = True     显示任何跳过任务的状态 ，默认是显示

# by default (as of 1.3), Ansible will raise errors when attempting to dereference 
# Jinja2 variables that are not set in templates or action lines. Uncomment this line
# to revert the behavior to pre-1.3.
#error_on_undefined_vars = False      如果所引用的变量名称错误的话, 将会导致ansible在执行步骤上失败

# by default (as of 1.6), Ansible may display warnings based on the configuration of the
# system running ansible itself. This may include warnings about 3rd party packages or
# other conditions that should be resolved if possible.
# to disable these warnings, set the following value to False:
#system_warnings = True    允许禁用系统运行ansible相关的潜在问题警告

# by default (as of 1.4), Ansible may display deprecation warnings for language
# features that should no longer be used and will be removed in future versions.
# to disable these warnings, set the following value to False:
#deprecation_warnings = True     允许在ansible-playbook输出结果中禁用“不建议使用”警告

# (as of 1.8), Ansible can optionally warn when usage of the shell and
# command module appear to be simplified by using a default Ansible module
# instead.  These warnings can be silenced by adjusting the following
# setting or adding warn=yes or warn=no to the end of the command line 
# parameter string.  This will for example suggest using the git module
# instead of shelling out to the git command.
# command_warnings = False    当shell和命令行模块被默认模块简化的时,Ansible 将默认发出警告


# set plugin path directories here, separate with colons
action_plugins     = /usr/share/ansible_plugins/action_plugins  
callback_plugins   = /usr/share/ansible_plugins/callback_plugins
connection_plugins = /usr/share/ansible_plugins/connection_plugins
lookup_plugins     = /usr/share/ansible_plugins/lookup_plugins
vars_plugins       = /usr/share/ansible_plugins/vars_plugins
filter_plugins     = /usr/share/ansible_plugins/filter_plugins

# by default callbacks are not loaded for /bin/ansible, enable this if you
# want, for example, a notification or logging callback to also apply to 
# /bin/ansible runs
#bin_ansible_callbacks = False    用来控制callback插件是否在运行 /usr/bin/ansible 的时候被加载. 这个模块将用于命令行的日志系统,发出通知等特性


# don't like cows?  that's unfortunate.
# set to 1 if you don't want cowsay support or export ANSIBLE_NOCOWS=1 #nocows = 1    默认ansible可以调用一些cowsay的特性   开启/禁用：0/1# don't like colors either?# set to 1 if you don't want colors, or export ANSIBLE_NOCOLOR=1#nocolor = 1  输出带上颜色区别， 开启/关闭：0/1# the CA certificate path used for validating SSL certs. This path 
# should exist on the controlling node, not the target nodes
# common locations:
# RHEL/CentOS: /etc/pki/tls/certs/ca-bundle.crt
# Fedora     : /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
# Ubuntu     : /usr/share/ca-certificates/cacert.org/cacert.org.crt
#ca_file_path =    # the http user-agent string to use when fetching urls. Some web server
# operators block the default urllib user agent as it is frequently used
# by malicious attacks/scripts, so we set it to something unique to 
# avoid issues.
#http_user_agent = ansible-agent

# if set to a persistent type (not 'memory', for example 'redis') fact values
# from previous runs in Ansible will be stored.  This may be useful when
# wanting to use, for example, IP information from one group of servers
# without having to talk to them in the same playbook run to get their
# current IP information.
fact_caching = memory


# retry files
#retry_files_enabled = False
#retry_files_save_path = ~/.ansible-retry

[privilege_escalation]
#become=True
#become_method=sudo
#become_user=root
#become_ask_pass=False

[paramiko_connection]

# uncomment this line to cause the paramiko connection plugin to not record new host
# keys encountered.  Increases performance on new host additions.  Setting works independently of the
# host key checking setting above.
#record_host_keys=False

# by default, Ansible requests a pseudo-terminal for commands executed under sudo. Uncomment this# line to disable this behaviour.
#pty=False

[ssh_connection]

# ssh arguments to use
# Leaving off ControlPersist will result in poor performance, so use 
# paramiko on older platforms rather than removing it
#ssh_args = -o ControlMaster=auto -o ControlPersist=60s

# The path to use for the ControlPath sockets. This defaults to
# &quot;%(directory)s/ansible-ssh-%%h-%%p-%%r&quot;, however on some systems with
# very long hostnames or very long path names (caused by long user names or 
# deeply nested home directories) this can exceed the character limit on
# file socket names (108 characters for most platforms). In that case, you 
# may wish to shorten the string below.
# 
# Example: 
# control_path = %(directory)s/%%h-%%r
#control_path = %(directory)s/ansible-ssh-%%h-%%p-%%r

# Enabling pipelining reduces the number of SSH operations required to 
# execute a module on the remote server. This can result in a significant 
# performance improvement when enabled, however when using &quot;sudo:&quot; you must 
# first disable 'requiretty' in /etc/sudoers
#
# By default, this option is disabled to preserve compatibility with
# sudoers configurations that have requiretty (the default on many distros).
# 
#pipelining = False

# if True, make ansible use scp if the connection type is ssh 
# (default is sftp)
#scp_if_ssh = True

[accelerate]
accelerate_port = 5099accelerate_timeout = 30accelerate_connect_timeout = 5.0# The daemon timeout is measured in minutes. This time is measured
# from the last activity to the accelerate daemon.
accelerate_daemon_timeout = 30 # If set to yes, accelerate_multi_key will allow multiple
# private keys to be uploaded to it, though each user must
# have access to the system via SSH to add a new key. The default# is &quot;no&quot;.
#accelerate_multi_key = yes

[selinux]
# file systems that require special treatment when dealing with security context
# the default behaviour that copies the existing context or uses the user default# needs to be changed to use the file system dependant context.
#special_context_filesystems=nfs,vboxsf,fuse
</code></pre>

<hr />

<p>hosts 文件 就是我们说的inventory文件，用来定义主机和主机组
小例子：</p>

<pre><code>10.0.0.4  ansible_ssh_pass='password'
10.0.0.7  ansible_ssh_pass='password'
[docker]
10.0.0.10[1:3]
[docker:vars]
ansible_ssh_pass='password'
[ansible:children]
docker
</code></pre>

<ul>
<li>第一行与第二行，定义了主机 IP ，然后使用 Inventory 内置变量定义了 SSH 登入密码。</li>
<li>第三行定义了一个组叫 docker。</li>
<li>第四行定义了 docker 组下面 3 台主机从 10.0.0.101 ~ 10.0.0.103 。</li>
<li>第五行与第六行针对 docker 组使用 Inventory 内置变量定义 SSH 登入密码。</li>
<li>第七行与第八行定义了一个组 ansible，这个组下面包含 docker 组。</li>
</ul>

<p>inventory 的内置参数如下：</p>

<pre><code>ansible_ssh_host
      将要连接的远程主机名.与你想要设定的主机的别名不同的话,可通过此变量设置.
 
ansible_ssh_port
      ssh端口号.如果不是默认的端口号,通过此变量设置.
 
ansible_ssh_user
      默认的 ssh 用户名
 
ansible_ssh_pass
      ssh 密码(这种方式并不安全,我们强烈建议使用 --ask-pass 或 SSH 密钥)
 
ansible_sudo_pass
      sudo 密码(这种方式并不安全,我们强烈建议使用 --ask-sudo-pass)
 
ansible_sudo_exe (new in version 1.8)
      sudo 命令路径(适用于1.8及以上版本)
 
ansible_connection
      与主机的连接类型.比如:local, ssh 或者 paramiko. Ansible 1.2 以前默认使用 paramiko.1.2 以后默认使用 'smart','smart' 方式会根据是否支持 ControlPersist, 来判断'ssh' 方式是否可行.
 
ansible_ssh_private_key_file
      ssh 使用的私钥文件.适用于有多个密钥,而你不想使用 SSH 代理的情况.
 
ansible_shell_type
      目标系统的shell类型.默认情况下,命令的执行使用 'sh' 语法,可设置为 'csh' 或 'fish'.
 
ansible_python_interpreter
      目标主机的 python 路径.适用于的情况: 系统中有多个 Python, 或者命令路径不是&quot;/usr/bin/python&quot;,比如  \*BSD, 或者 /usr/bin/python
      不是 2.X 版本的 Python.我们不使用 &quot;/usr/bin/env&quot; 机制,因为这要求远程用户的路径设置正确,且要求 &quot;python&quot; 可执行程序名不可为 python以外的名字(实际有可能名为python26).
 
      与 ansible_python_interpreter 的工作方式相同,可设定如 ruby 或 perl 的路径....
</code></pre>

<hr />

<p>需要执行的playbook配置</p>

<p>例子：</p>

<pre><code>- hosts: goldeneye-test
  vars:
    ENV: &quot;test&quot;
    s3_path: &quot;log&quot;
  roles:
    - goldeneye
</code></pre>

<p>这里附一个对应的inventory文件的例子：</p>

<pre><code>[goldeneye-test] # 主机组名字
52.204.76.3 

[goldeneye-test:vars] # 主机组对应的配置
ansible_ssh_private_key_file=~/.ssh/websocketserver_goldeneye.pem
ansible_ssh_user=ubuntu
region=us
</code></pre>

<p>最开始有这个项目的tree，下面的解释可以对照着看。</p>

<p>解释：
- hosts就是我们hosts文件里定义的主机和主机组名字，比如这里就是 inventory里的 goldeneye-test
- roles：后面会讲到，会有一个roles的文件夹，放置的是对应的playbook的role，这个就是这个playbook需要执行的role的列表
- vars: 会在运行的role中用到的变量值</p>

<hr />

<p>git克隆问题</p>

<pre><code>https://codeday.me/bug/20181107/358872.html
- name: be sure prom-king has an up-to-date clone of its own repository
  git:
    repo: &quot;ssh://ddcrnd@bitbucket.org/prom-king.git&quot;
    dest: /home/promking/prom-king
    accept_hostkey: yes
    clone: yes
    key_file: /home/promking/.ssh/id_rsa.pub
    update: yes
</code></pre>

<p>使用用户名和密码</p>

<pre><code>git clone https://fupeng.li.dev%40gmail.com:这里放我的密码@github.com/immotal/my_test.git
注意，为了识别出来，邮箱的中间需要把@换成 %40 来处理
</code></pre>

<p>使用 person access token</p>

<pre><code>git clone https://oauth2:这里放我的access_token@github.com/immotal/my_test.git
access token 需要在github或者gitlab的个人头像处设置。
</code></pre>

<hr />

<p>简单例子：</p>

<p>一个本地运行的playbook（如果是在本地机器运行的命令，需要添加local参数）
这个小例子完成了一个Python程序打包之后，上传到需要部署的机器上去的步骤</p>

<pre><code># hosts (inventry)
[local]
127.0.0.1 ansible_connection=local
</code></pre>

<pre><code># build.yml
- hosts: local
  vars:
    ENV: &quot;test&quot;
  roles:
    - local
</code></pre>

<pre><code># 执行的命令 , hosts 是上面那个 hosts 文件，build.yml 是上线那个文件
VERSION = master
ansible-playbook -i hosts -f 5 -e &quot;console_version=$(VERSION)&quot; build.yml
</code></pre>

<pre><code># local/task
# 其中{{}}中的变量存放在 local/vars中
- name: Build Strategy Code
  connection: local
  command: chdir={{ STRATEGY_DIR }}  {{ PYTHON_ENV }} setup.py sdist

- name: SCP Strategy To Remote Machine
  connection: local
  command: chdir={{ DIST_DIR }} scp rock_strategy-{{ STRATEGY_VERSION }}.tar.gz {{ TEST_MACHINE }}

- name: Build Rock Code
  connection: local
  command: chdir={{ ROCK_DIR }}  {{ PYTHON_ENV }} setup.py sdist

- name: SCP Rock To Remote Machine
  connection: local
  command: chdir={{ ROCK_DIST_DIR }} scp Rock-{{ ROCK_VERSION }}.tar.gz {{ TEST_MACHINE }}
</code></pre>

        ]]>
      </description>
    </item>
    
    <item>
      <title>使用 gitlab CI/CD 部署静态站点</title>
      <link>https://blog.lierhua.top/tech/%E4%BD%BF%E7%94%A8-gitlab-ci-cd-%E9%83%A8%E7%BD%B2%E9%9D%99%E6%80%81%E7%AB%99%E7%82%B9/</link>
      <pubDate>Sat, 16 May 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/%E4%BD%BF%E7%94%A8-gitlab-ci-cd-%E9%83%A8%E7%BD%B2%E9%9D%99%E6%80%81%E7%AB%99%E7%82%B9/</guid>
      <description>
        <![CDATA[
        <p>关键词：GitLab CI/CD 静态站点</p>

<p>前面两篇文章我分别介绍了如何使用 GitHub Project Pages 部署静态站点，如何将静态站点部署到阿里云的 OSS，这一篇我们讲解如何在 GitLab 的私有仓库通过使用 CI/CD 部署我们的静态站点到 EC2 上去。</p>

<h3 id="基本介绍">基本介绍</h3>

<p>使用 GitLab ，我们可以自己搭建自己的服务器部署 GitLab 服务，也可以使用互联网提供的 GitLab 服务，我选择了后者，如果你是团队办公，对代码仓库的私密性要求很高，推荐直接自己在服务器搭建你的 GitLab 服务。</p>

<p>我们依旧使用 Hugo 作为例子，我们将整个目录都作为版本控制的对象</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-05-16%20at%2022.08.png" alt="" /></p>

<p>public 目录就是我们生成的静态文件的存放位置。</p>

<h3 id="gitlab-ci-cd-介绍">GitLab CI/CD 介绍</h3>

<p>CI/CD 的意思是持续集成和持续部署，我们其实想用的是里面的持续部署，GitLab 的这部分简单来讲是由这几部分构成的，首先需要有 GitLab 仓库，然后需要我们有台机器部署 GitLab-runner，他们二者不能部署到一台机器中，我们可以在任意一台 EC2 机器上部署 GitLab-runner，部署文档请参考<a href="https://juejin.im/post/5c227af6e51d452baa77d473" rel="noreferrer" target="_blank">这里</a></p>

<p>在项目根目录下添加 .gitlab-ci.yml 文件，整个持续集成系统是 Gitlab 自带的，添加的这个 Runner 就是用来到系统里解析文件中的 script 部分。</p>

<h4 id="安装-gitlab-runner">安装 GitLab-runner</h4>

<p>以 Ubuntu 为例，直接使用 apt 安装即可，<code>apt install gitlab-runner</code></p>

<h4 id="注册-runner">注册 runner</h4>

<p>如果你的 .gitlab-ci.yml 涉及到 docker 部分，请先在机器上安装 docker 环境，如果不需要，则直接开始注册即可。</p>

<p>注册前必须做的一步是获取 GitLab 的 token，位置为 <code>Settings -&gt; CI/CD -&gt; Runners</code></p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-05-16%20at%2022.27.png" alt="" /></p>

<p>下面开始进行注册的步骤，一<a href="https://docs.gitlab.com/runner/register/" rel="noreferrer" target="_blank">个小例子</a>：</p>

<p>运行下面的命令:</p>

<pre><code class="language-text">sudo gitlab-runner register
</code></pre>

<p>输入 Gitlab 实例的 URL:</p>

<pre><code class="language-text"> Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
 https://gitlab.com
</code></pre>

<p>输入用来注册 Runner 的 token:</p>

<pre><code class="language-text">Please enter the gitlab-ci token for this runner
xxx
</code></pre>

<p>输入 Runner 的描述，随后可在 GitLab 界面中修改：</p>

<pre><code class="language-text"> Please enter the gitlab-ci description for this runner
 [hostame] tencentyun
</code></pre>

<p>输入与 Runner 绑定的<a href="https://docs.gitlab.com/ee/ci/runners/#using-tags" rel="noreferrer" target="_blank">标签</a>（可修改）：</p>

<pre><code class="language-text"> Please enter the gitlab-ci tags for this runner (comma separated):
 cicd
</code></pre>

<p>选择 Runner 的执行方式：</p>

<pre><code class="language-text"> Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:
 ssh
</code></pre>

<p>如果选择的执行方式是 ssh，会要求填写对应一些配置，例子如下：</p>

<pre><code class="language-text"> # 你可以认为 runner 机器就是一个跳板机，而你选择了 ssh 执行方式之后，就相当于这个跳板机要去控制另一台机器
 # 所以需要在跳板机上配置需要提供服务的机器的用户名和 key 或者配置密码，以便于可以跳板机可以登录机器进行
 # 操作配置等相关操作
 concurrent = 1
 check_interval = 0
 
 # 第一个例子，这个使用的是 ssh 的用户名和密码
 [[runners]]
   name = &quot;tencentyun&quot;
   url = &quot;https://gitlab.com&quot;
   token = &quot;你从 GitLab 拿到的 token&quot;
   executor = &quot;ssh&quot;
   [runners.ssh]
     user = &quot;root&quot;  # 需要搭建静态网站的机器的用户名
     password = &quot;xxxxxx&quot;  # 网站机器的密码
     host = &quot;207.246.122.100&quot;
     port = &quot;22&quot;
   [runners.cache]
   
# 有一个例子，这里使用的 key   
[[runners]]
  executor = &quot;ssh&quot;
  [runners.ssh]
    host = &quot;example.com&quot;
    port = &quot;22&quot;
    user = &quot;root&quot;
    password = &quot;password&quot;
    identity_file = &quot;/path/to/identity/file&quot; # 网站机器的秘钥
</code></pre>

<p>注册流程走完会在 ~/etc/gitlab-runner/ 目录下生成 config.toml 配置文件，这时候就可以在 Gitlab 的设置中看到激活的 Runner：</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-05-16%20at%2022.42.png" alt="" /></p>

<p>到此我们就将我们的 GitLab 注册到了这个 runner 里去了</p>

<h4 id="编写-gitlab-ci-yml">编写 .gitlab-ci.yml</h4>

<p>下面我们开始编写 .gitlab-ci.yml 这个需要放到项目仓库的根目录下，里面是 yml 的脚本，一旦发生 push 或者打 tag 等的操作，就会触发 .gitlab-ci.yml，如果这个配置里的 tag 刚好关联到的 runner，这个 runner 就会执行我们这个脚本文件里的 script，实现持续集成和持续部署的操作</p>

<p>下面是我这个项目编写的 .gitlab-ci.yml 内容</p>

<pre><code class="language-text">stages:
  - deploy

# 定义 deploy 阶段的一个 job
deploy:
  stage: deploy
  tags:
    - cicd
  script:
    - echo &quot;nihao ~~&quot; &gt; ~/test.txt   # 可以通过这个脚本测试，看看是否在跳板机执行到脚本了
    - rm -rf /opt/public
    - cp -r public /opt/public
</code></pre>

<p>需要注意的是 tags，需要和注册 runner 时配置的一致，这样才会选择那个 runner 执行下面的 script 操作，我的 script 里的操作比较简单，就是通过 runner 机器，删除对应目录下的内容，然后将我 GitLab 里的新发布的 public 目录拷贝到原来的地址，这样就完成了文档的更新。</p>

<h4 id="触发自动部署">触发自动部署</h4>

<p>当我们进行仓库的 push 操作或者打 tag 操作时（什么时候触发也是需要我们自己配置），如果跟我们配置的触发条件一致了，就会进行自动部署，执行 script 操作。</p>

<p>这是个失败的操作图：</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-05-16%20at%2022.57.png" alt="" /></p>

<p>这是个成功的图：</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202020-05-16%2023.03.13.png" alt="" /></p>

<h3 id="附录">附录：</h3>

<p>提供服务的机器安装了 NGINX，下面是 NGINX 对于这个静态站点服务的配置</p>

<pre><code class="language-text">server {
    listen       80;
    #设置站点域名
    server_name 这里是你的域名;
    #指向hugo public 文件夹
    root /opt/public/;

    location / {
    }

    error_page 404 /404.html;
        location = /404.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}
</code></pre>

<h3 id="参考文章">参考文章</h3>

<ul>
<li><a href="https://juejin.im/post/5c227af6e51d452baa77d473" rel="noreferrer" target="_blank">gitlab-runner 安装与配置</a></li>
<li><a href="https://docs.gitlab.com/ee/ci/README.html" rel="noreferrer" target="_blank">gitlab ci/cd 官网 docs</a></li>
</ul>
        ]]>
      </description>
    </item>
    
    <item>
      <title>部署静态网站到 GitHub project Pages</title>
      <link>https://blog.lierhua.top/tech/%E9%83%A8%E7%BD%B2%E9%9D%99%E6%80%81%E7%BD%91%E7%AB%99%E5%88%B0-github-project-pages/</link>
      <pubDate>Sat, 16 May 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/%E9%83%A8%E7%BD%B2%E9%9D%99%E6%80%81%E7%BD%91%E7%AB%99%E5%88%B0-github-project-pages/</guid>
      <description>
        <![CDATA[
        <p>关键词：Hugo, github, pages</p>

<p>接下来三篇文章是一个系列的，总结下自己部署静态博客的方法，主要分为三种方式：</p>

<ul>
<li><p>部署静态网站到两种不同的 GitHub pages</p></li>

<li><p>部署静态网站到阿里云 OSS，代码仓库GitHub 或者 Gitlab 均可</p></li>

<li><p>使用 GitLab 的 CI/CD 部署静态网页到 EC2</p></li>
</ul>

<p>我们今天讲的是第一种部署方式，使用 Hugo 生成的博客为例子来讲解，关于如何使用 Hugo 生成我们的静态网站请参考我的另一篇博客，这里我们默认已经有最基本的 Hugo 使用基础。</p>

<h2 id="pages-vs-project-pages">Pages vs Project Pages</h2>

<p>对于 GitHub 而言，有两种不同的 pages 可以让我们进行使用，一种是 Pages，一种是 Project Pages，Pages 对于一个 GitHub 账号而言，只能部署一个，并且仓库 (repository) 的命名必须是 <code>&lt;你的 GitHub 用户名&gt;.github.io</code> ，而对于 Project Pages 而言，一个 GitHub 账号可以部署任意的数量，因为他是依赖于不同的 repository 的，每一个 repository 都有一个 Project Pages 可供使用，仓库的名字没有任何的限制，只需要到时候在对应仓库的 settings 里配置静态网站资源对应的分支或者是目录即可，到时候可以使用 <code>https://&lt;你的 GitHub 用户名&gt;.github.io/&lt;repository 的名字&gt;</code> 进行访问。</p>

<p>接下来我们主要介绍如何部署到 Project Pages 上去，因为这个用起来更方便，是基于仓库维度的，我们可以在一个 GitHub 账号中部署若干的服务，特别适合为我们的仓库内容建设介绍性网站。</p>

<h2 id="具体流程">具体流程</h2>

<p>我们首先看下仓库的 settings 中的配置选项，见下图：</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-05-16%20at%2019.49.png" alt="" /></p>

<p>进入 settings 里后我们看到如下界面，其中我们主要关注的是 GitHub pages 里的 source，我们这里使用第二个，也就是master 分支下的 docs 目录里的内容作为我们网站的内容。</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-05-16%20at%2019.51.png" alt="" /></p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-05-16%20at%2019.54.png" alt="" /></p>

<p>在 Hugo 中我们生成静态网站中需要我们注意的几点是：</p>

<ul>
<li>config.toml 配置文件里增加 <code>publishdir = &quot;docs&quot;</code> 这个配置，因为 Hugo 默认发布出的位置是 <code>public</code> 而我们设置的网站路径是 <code>docs</code> 里的内容，因此做这样一个修改，<code>hugo</code> 命令生成的静态文件就存放到<code>docs</code>目录了。</li>
<li>修改 config.toml 配置文件里的 <code>baseURL</code> 为 <code>https://&lt;你的 GitHub 用户名&gt;.github.io/&lt;repository 的名字&gt;</code> 。</li>
</ul>

<h2 id="参考文章">参考文章</h2>

<ul>
<li><a href="https://hexo.io/zh-cn/docs/github-pages.html" rel="noreferrer" target="_blank">hexo 部署到 GitHub</a></li>
<li><a href="https://pages.github.com/" rel="noreferrer" target="_blank">github pages 官方网站</a></li>
</ul>
        ]]>
      </description>
    </item>
    
    <item>
      <title>部署静态网站到阿里云 OSS</title>
      <link>https://blog.lierhua.top/tech/%E9%83%A8%E7%BD%B2%E9%9D%99%E6%80%81%E7%BD%91%E7%AB%99%E5%88%B0oss/</link>
      <pubDate>Sat, 16 May 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/%E9%83%A8%E7%BD%B2%E9%9D%99%E6%80%81%E7%BD%91%E7%AB%99%E5%88%B0oss/</guid>
      <description>
        <![CDATA[
        <p>关键词：静态网站，阿里云，OSS</p>

<p>上一篇我们讲解了如何静态网站如何部署到 GitHub Project Pages 上，这一篇我们讲解如何部署静态网站到阿里云的 OSS 服务上。</p>

<p>阿里云的 OSS 是一种文件存储服务，跟 AWS 的 S3 同属于存储服务，由于我们在国内，所以使用阿里云的服务会更便利一些，因此选用了 OSS 服务，使用 S3 部署也是一样的。</p>

<p>同样的，如何使用 Hugo 生成我们需要的静态文件我们默认已经完成，我们已经得到了静态页面需要的文件，这里我们以 Hugo 默认生成的 public 文件夹的问价为例</p>

<p>按照如下的步骤进行我们的部署操作</p>

<h3 id="申请-oss-bucket">申请 OSS bucket</h3>

<p>需求点：如果你已经有备案的域名，可以选择任意的地区的 bucket 来创建，如果你的域名没有备案，请选择中国大陆以外的地区，推荐使用香港地区或其他亚洲地区。</p>

<p>具体的操作步骤如下，首先登陆阿里云，然后选择控制台，在左侧栏选择对象存储 OSS，然后选择弹出界面的左侧针对 OSS 的侧边栏里的资源包管理，选择购买资源包</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img2/2020-05-16%20at%208.41%20PM.png" alt="" /></p>

<p>点击后，跳转到对应的页面<img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img2/2020-05-16%20at%208.48%20PM.png" alt="" /></p>

<p>基本按照这个选择方式就可以，地区注意是大陆通用之外的地区，基本一年 9 块钱，40 个 G 的大小，够用了购买了资源包之后，开始创建我们需要使用的 bucket，注意我们建议一个静态网站使用一个单独的 bucket，尽量不要在这个 bucket 里再存放其他的文件，以免出现一些不可预知的现象。</p>

<p>然后我们在 <strong>bucket 列表</strong>选项去选择创建 bucket，如下图</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img2/2020-05-16%20at%208.55%20PM.png" alt="" /></p>

<p>区域选择刚刚购买的资源包的区域，然后按照这个选择，或者有自己其他需求的选择其他选项来建立我们的bucket，特别注意的是读写权限是公共读，如果是私有的话，部署静态站点后其他人是无法访问的。</p>

<p>到这一步我们 bucket 相关的基本操作已经完成。接下来我们讲如何将 Hugo 生成的静态文件部署到 OSS 中</p>

<h3 id="部署静态站点">部署静态站点</h3>

<p>第一步我们需要将我们 Hugo 生成的静态站点文件上传到我们刚创建好的 bucket，方式有多种，可以使用 ossbrowser 或者直接使用阿里云 cli，也可以使用阿里云提供的 OSS SDK 使用代码上传。</p>

<p>对应的地址分别如下：</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img2/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202020-05-16%20%E4%B8%8B%E5%8D%889.18.55.png" alt="" /></p>

<p>这两种工具都需要使用 AccessKey，新建 AccessKey 在上图的位置创建，推荐先创建新用户，然后在创建的子用户的维度创建 Key，然后赋予对应的权限。</p>

<p>将静态站点传到对应目录后，开始进行最关键的步骤，那就是配置 OSS bucket 让他支持静态页面，我们从如下递进关系进入静态页面配置</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img2/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202020-05-16%20%E4%B8%8B%E5%8D%889.31.40.png" alt="" /></p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img2/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202020-05-16%20%E4%B8%8B%E5%8D%889.34.22.png" alt="" /></p>

<p>配置方式如上图，将默认首页的 404 页都配置好，开通子目录首页，然后配置规则选择好，然后保存即可。</p>

<p>这样我们基本的配置就完成了，此时你还是无法访问的，因为 OSS 做了一个规定，要想静态站点可以被访问，需要配置域名，下面我们就进行域名的配置：</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img2/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202020-05-16%20%E4%B8%8B%E5%8D%889.37.49.png" alt="" /></p>

<p>点击对应界面的绑定用于域名，输入对应的信息</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img2/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202020-05-16%20%E4%B8%8B%E5%8D%889.40.25.png" alt="" /></p>

<p>如果你输入的域名是你在阿里云购买的域名，并且没有被解析过，可以直接选择自动添加 CNAME 记录，点击确定即可。等待大概 1 分钟左右，去访问这个地址，发现已经可以访问到对应的网站了。</p>

<h3 id="使用-https">使用 HTTPS</h3>

<p>如果你还想使用 HTTPS ，需要在对应的页面配置 HTTPS 证书，点击这句话上面的倒数第二张图中的证书托管，进入页面后，发现对应的域名下面有两个文本框，分别是公钥和私钥，如果你不差钱，可以选择阿里云提供的 SSL 证书服务（当前页面的用户域名后面对应的申请签发证书选项），的确不便宜。如果你想用免费的证书，可以去七牛云申请一个，具体流程请自行 Google。一旦你的证书申请到之后，你会获得两个文件，将刚才那两文件使用记事本打开，把 <code>*.crt</code> 结尾文件的内容复制到 <code>公钥</code>，<code>*.key</code> 结尾文件的内容复制到 <code>私钥</code>，保存，然后你就可以使用 HTTPS 进行访问了。</p>

<h3 id="参考文章">参考文章</h3>

<ul>
<li><a href="https://mrhelloworld.com/posts/hugo/hugo-oss-install/" rel="noreferrer" target="_blank">OSS 搭建静态网站</a></li>
</ul>
        ]]>
      </description>
    </item>
    
    <item>
      <title>k8s 的一个小总结(未完待补充)</title>
      <link>https://blog.lierhua.top/tech/ubuntu/10.-ubuntu-k8s-%E6%80%BB%E7%BB%93/</link>
      <pubDate>Tue, 10 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/ubuntu/10.-ubuntu-k8s-%E6%80%BB%E7%BB%93/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>ubuntu</code>, <code>k8s</code></p>

<h1 id="熟悉-k8s">熟悉 k8s</h1>

<h2 id="初步认识">初步认识</h2>

<ul>
<li>Node 其实就是用于工作的服务器</li>
<li>Deployment 可理解为一种对期望状态的描述</li>
<li>Pod 作为集群中可调度的最小单元</li>
<li>Docker 是我们选择的容器运行时，可运行我们构建的服务镜像，减少在环境方面所做的重复工作，并且也非常便于部署。除了 Docker 外还存在其他的容器运行时。</li>
</ul>

<h2 id="整体架构">整体架构</h2>

<h3 id="k8s">k8s</h3>

<pre><code>
                               +-------------+                              
                               |             |                              
                               |             |               +---------------+
                               |             |       +-----&gt; |     Node 1    |
                               | Kubernetes  |       |       +---------------+
+-----------------+            |   Server    |       |                      
|       CLI       |            |             |       |       +---------------+
|    (Kubectl)    |-----------&gt;| ( Master )  |&lt;------+-----&gt; |     Node 2    |
|                 |            |             |       |       +---------------+
+-----------------+            |             |       |       
                               |             |       |       +---------------+
                               |             |       +-----&gt; |     Node 3    |
                               |             |               +---------------+
                               +-------------+               

</code></pre>

<ul>
<li>Kubectl：官方提供的名为 <code>kubectl</code> 的 CLI （Command Line Interface）工具，用于使用 K8S 开放的 API 来管理集群和操作对象等</li>
<li>Master: 是一种角色（Role），表示在这个 Node 上包含着管理集群的一些必要组件, 生产环境中，为了保障集群的高可用，我们通常会部署多个 Master</li>
<li>Node: 是用于工作的机器</li>
</ul>

<h3 id="master">Master</h3>

<p>Master 是整个 K8S 集群的大脑: 接收，发布，存储</p>

<pre><code>+----------------------------------------------------------+          
| Master                                                   |          
|              +-------------------------+                 |          
|     +-------&gt;|        API Server       |&lt;--------+       |          
|     |        |                         |         |       |          
|     v        +-------------------------+         v       |          
|   +----------------+     ^      +--------------------+   |          
|   |                |     |      |                    |   |          
|   |   Scheduler    |     |      | Controller Manager |   |          
|   |                |     |      |                    |   |          
|   +----------------+     v      +--------------------+   |          
| +------------------------------------------------------+ |          
| |                                                      | |          
| |                Cluster state store                   | |          
| |                                                      | |          
| +------------------------------------------------------+ |          
+----------------------------------------------------------+         
</code></pre>

<ul>
<li>cluster state store: 存储集群所有需持久化的状态，并且提供 watch 的功能支持，可以快速的通知各组件的变更等操作, 是一个 etcd</li>
<li>api server: 整个集群的入口，类似于人体的感官，接收外部的信号和请求，并将一些信息写入到 etcd 中</li>
<li>controller manager: 调节集群的状态, 当集群的配置发生变更，控制器就会朝着预期的状态开始工作</li>
<li>scheduler: 调度器，它会持续的关注集群中未被调度的 Pod ，并根据各种条件，比如资源的可用性，节点的亲和性或者其他的一些限制条件，通过绑定的 API 将 Pod 调度/绑定到 Node 上。</li>
</ul>

<h3 id="node">Node</h3>

<p>则运行着三个必要的组件 <code>kubelet</code>, <code>container runtime</code> (一般是 Docker), <code>kube-proxy</code></p>

<pre><code>+--------------------------------------------------------+       
| +---------------------+        +---------------------+ |       
| |      kubelet        |        |     kube-proxy      | |       
| |                     |        |                     | |       
| +---------------------+        +---------------------+ |       
| +----------------------------------------------------+ |       
| | Container Runtime (Docker)                         | |       
| | +---------------------+    +---------------------+ | |       
| | |Pod                  |    |Pod                  | | |       
| | | +-----+ +-----+     |    |+-----++-----++-----+| | |       
| | | |C1   | |C2   |     |    ||C1   ||C2   ||C3   || | |       
| | | |     | |     |     |    ||     ||     ||     || | |       
| | | +-----+ +-----+     |    |+-----++-----++-----+| | |       
| | +---------------------+    +---------------------+ | |       
| +----------------------------------------------------+ |       
+--------------------------------------------------------+  
</code></pre>

<ul>
<li>kubelet: 实现了集群中最重要的关于 Node 和 Pod 的控制功能</li>
<li>container runtime: 下载镜像和运行容器</li>
<li>kube proxy: Node 上启动一个 <code>kube-proxy</code> 的进程，通过编排 <code>iptables</code> 规则来让 Service 访问到 Pod</li>
</ul>
        ]]>
      </description>
    </item>
    
    <item>
      <title>keyboard maestro 使用指南</title>
      <link>https://blog.lierhua.top/tech/workflow/keyboard-maestro%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97/</link>
      <pubDate>Tue, 10 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/workflow/keyboard-maestro%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>keyboard maestro</code></p>

<p>3 月 10 号题目就写好了，一直拖到现在才开始写，拖延症确实要治疗</p>

<p>keyboard maestro, alfred, karabiner 这三款 APP 是我的 Mac 上绝对离不开的三个神器，他们大大简化了我的工作流程，提高了我的工作效率。</p>

<p>今天来说一下这个 keybaord maestro，今天时间问题，先讲我用的最多的东西，其他的等以后有空再补充, 对于我来说用的最多的就是 resize window 和 快速切换 APP 了</p>

<h2 id="resize-window">resize window</h2>

<p>众所周知，Mac 的窗口管理很是垃圾，如何快速的 resize 窗口竟然后好多专门的付费 APP，但是如果你用了 keyboard Maestro 之后，就可以用他自带的方式解决这个问题</p>

<p>先上动画演示:</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2021-04-01%20at%205.55%20PM.gif" alt="" /></p>

<p>其实原理很简单:</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/%E6%88%AA%E5%B1%8F2021-04-01%E4%B8%8B%E5%8D%885.57.19.png" alt="" /></p>

<p>拖延症犯了，以后有空再写 ……</p>
        ]]>
      </description>
    </item>
    
    <item>
      <title>ubuntu 下如何支持虚拟化 CPU</title>
      <link>https://blog.lierhua.top/tech/ubuntu/8.-ubuntu-%E4%B8%8B%E5%A6%82%E4%BD%95%E6%94%AF%E6%8C%81%E8%99%9A%E6%8B%9F%E5%8C%96-cpu/</link>
      <pubDate>Tue, 10 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/ubuntu/8.-ubuntu-%E4%B8%8B%E5%A6%82%E4%BD%95%E6%94%AF%E6%8C%81%E8%99%9A%E6%8B%9F%E5%8C%96-cpu/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>ubuntu</code>, <code>虚拟化</code>, <code>cpu</code></p>

<h1 id="ubuntu-下如何支持虚拟化-cpu">ubuntu 下如何支持虚拟化 CPU</h1>

<ol>
<li><p>查看是否支持虚拟化 CPU
执行命令 lscpu</p>

<pre><code>架构：                           x86_64
CPU 运行模式：                   32-bit, 64-bit
字节序：                         Little Endian
Address sizes:                   39 bits physical, 48 bits virtual
CPU:                             16
在线 CPU 列表：                  0-15
每个核的线程数：                 2
每个座的核数：                   8
座：                             1
NUMA 节点：                      1
厂商 ID：                        GenuineIntel
CPU 系列：                       6
型号：                           158
型号名称：                       Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
步进：                           12
CPU MHz：                        3600.085
CPU 最大 MHz：                   5000.0000
CPU 最小 MHz：                   800.0000
BogoMIPS：                       7200.00
虚拟化：                         VT-x     【如果有这个就代表有虚拟化技术了】
L1d 缓存：                       256 KiB
L1i 缓存：                       256 KiB
L2 缓存：                        2 MiB
L3 缓存：                        16 MiB
NUMA 节点0 CPU：                 0-15
Vulnerability Itlb multihit:     KVM: Mitigation: VMX disabled
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown:          Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; Full generic retpoline, IBPB conditional, IBRS_FW, STIBP
                              conditional, RSB filling
Vulnerability Srbds:             Mitigation; Microcode
Vulnerability Tsx async abort:   Mitigation; Clear CPU buffers; SMT vulnerable
标记：                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat ps
                             e36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1
                             gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xt
                             opology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds
                             _cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_
                             2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand l
                             ahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single ssbd ibrs ib
                             pb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_a
                             djust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap c
                             lflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pl
                             n pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d arch_
                             capabilities

</code></pre></li>

<li><p>如何开启支持虚拟化 CPU
虚拟化技术的可以在BIOS中开启，开启方法如下： 1、进入BIOS。开机时按F2或F12或DEL或ESC等键(各电脑有所不同)。 2、进入BIOS后，找到Configuration选项，选择Intel Virtual Technology并回车，将光标移至Enabled，然后再回车，最后按F10保存并.</p></li>
</ol>
        ]]>
      </description>
    </item>
    
    <item>
      <title>ubuntu 下安装 k8s</title>
      <link>https://blog.lierhua.top/tech/ubuntu/14.-ubuntu-%E4%B8%8B%E5%AE%89%E8%A3%85-k8s/</link>
      <pubDate>Tue, 10 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/ubuntu/14.-ubuntu-%E4%B8%8B%E5%AE%89%E8%A3%85-k8s/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>ubuntu</code>, <code>k8s</code></p>

<h1 id="ubuntu-下安装-k8s">ubuntu 下安装 k8s</h1>

<h2 id="安装-k8s-准备工作">安装 k8s 准备工作</h2>

<h3 id="准备工作">准备工作</h3>

<p>我们先假设以下的情况成立。</p>

<p>机器：有2-3台物理机或虚拟机
系统：Ubuntu 18.04 以上且已换好国内的源
如果以上基本不成立，本篇文章到此结束，谢谢观看…</p>

<h3 id="安装docker">安装Docker</h3>

<p>我也不需要介绍各种情况了，直接登上机器，创建一个shell脚本，例如叫install_docker.sh，一把梭代码如下。</p>

<pre><code>sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates 
curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository &quot;deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable&quot;
sudo apt-get update
sudo apt-get -y install docker-ce docker-ce-cli containerd.io
</code></pre>

<p>然后执行sh install_docker.sh，等待命令跑完，验证docker是否安装好即可。直接敲docker + 回车。</p>

<h3 id="安装kubernetes">安装Kubernetes</h3>

<p>同理，新建一个shell脚本，例如install_k8s.sh。一把梭代码如下。</p>

<pre><code>sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-get update
cat &lt;&lt;EOF &gt;/etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt-get install -y kubelet kubeadm kubectl --allow-unauthenticated
</code></pre>

<p>需要注意的是， <code>sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -</code> 可能会失败，因为墙的原因，因此，我们需要在可以下载到的地方提前下载好，然后 <code>scp</code> 到机器，然后使用 <code>sudo apt-key add apt-key.gpg</code> 即可。</p>

<p>另外安装时还有连不上的情况， 换国内的源</p>

<pre><code>sudo apt-get update
cat &lt;&lt;EOF &gt;/etc/apt/sources.list.d/kubernetes.list
deb http://mirrors.ustc.edu.cn/kubernetes/apt kubernetes-xenial main
EOF
sudo apt-get install -y kubelet kubeadm kubectl --allow-unauthenticated
</code></pre>

<p>然后执行sh install_k8s.sh，等待命令跑完，验证k8s是否安装好即可。直接敲kubectl + 回车。</p>

<h3 id="关闭swap">关闭Swap</h3>

<p>先给出一把梭，不要耽误了正在安装的老铁。为什么要关闭后面再说。</p>

<p>暂时关闭 直接使用命令 <code>sudo swapoff -a</code>，但是重启之后会生效。会导致 k8s 无法正常运行。
永久关闭 建议一劳永逸，<code>sudo vim /etc/fstab</code> 将有 <code>swap.img</code> 那行注释掉，保存即可。</p>

<p>那么，swap是啥呢？它是系统的交换分区，你可以理解为虚拟内存。当系统内存不足的时候，会将一部分硬盘空间虚拟成内存使用。</p>

<h2 id="初始化master节点">初始化Master节点</h2>

<p>到这，准备工作就完成了，可以开始安装K8S的master节点了，登上要作为 master 节点的机器。</p>

<h3 id="设置hostname">设置HostName</h3>

<p>老规矩，先上命令，再说为什么要设置。</p>

<pre><code class="language-sudo">
自定义修改了主机名，在之后查看集群内节点时，每个节点的名字就不会显示K8S自动生成的名字，便于查看和记忆。例如，在其他的 Node 节点你可以将 master-node 改为 slave-node-1 或worker-node-2

### Master 节点配置 cgroup driver

#### 方法一

修改 kubelet 配置 `/usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf`

</code></pre>

<h1 id="note-this-dropin-only-works-with-kubeadm-and-kubelet-v1-11">Note: This dropin only works with kubeadm and kubelet v1.11+</h1>

<p>[Service]
CPUAccounting=true
MemoryAccounting=true
Environment=&ldquo;KUBELET<em>KUBECONFIG</em>ARGS=&ndash;bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf &ndash;kubeconfig=/etc/kubernetes/kubelet.conf &ndash;cgroup-driver=systemd&rdquo;  #配置在这里cgroup-driver=systemd
Environment=&ldquo;KUBELET<em>CONFIG</em>ARGS=&ndash;config=/var/lib/kubelet/config.yaml&rdquo;</p>

<h1 id="this-is-a-file-that-kubeadm-init-and-kubeadm-join-generates-at-runtime-populating-the-kubelet-kubeadm-args-variable-dynamically">This is a file that &ldquo;kubeadm init&rdquo; and &ldquo;kubeadm join&rdquo; generates at runtime, populating the KUBELET<em>KUBEADM</em>ARGS variable dynamically</h1>

<p>EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env</p>

<h1 id="this-is-a-file-that-the-user-can-use-for-overrides-of-the-kubelet-args-as-a-last-resort-preferably-the-user-should-use">This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use</h1>

<h1 id="the-noderegistration-kubeletextraargs-object-in-the-configuration-files-instead-kubelet-extra-args-should-be-sourced-from-this-file">the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET<em>EXTRA</em>ARGS should be sourced from this file.</h1>

<p>EnvironmentFile=-/etc/sysconfig/kubelet
ExecStart=
ExecStart=/usr/bin/kubelet $KUBELET<em>KUBECONFIG</em>ARGS $KUBELET<em>CONFIG</em>ARGS $KUBELET<em>KUBEADM</em>ARGS $KUBELET<em>EXTRA</em>ARGS</p>

<pre><code>
#### 方法二

https://kubernetes.io/docs/setup/production-environment/container-runtimes/

### 初始化 master 节点

初始化过程会访问墙外网站，如果 init 不能顺利执行，请配置全局代理或者用下面的脚本提前跑好：

</code></pre>

<p>#!/bin/bash</p>

<p>images=(
kube-apiserver:v1.20.1
kube-controller-manager:v1.20.1
kube-scheduler:v1.20.1
kube-proxy:v1.20.1
pause:3.2
etcd:3.4.13-0
coredns:1.7.0
)</p>

<p>for imageName in ${images[@]} ; do
    docker pull registry.cn-hangzhou.aliyuncs.com/google<em>containers/$imageName
    docker tag registry.cn-hangzhou.aliyuncs.com/google</em>containers/$imageName k8s.gcr.io/$imageName
    docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName
done</p>

<pre><code>
然后执行

`sudo kubeadm init --apiserver-advertise-address=192.168.56.200 --pod-network-cidr=10.244.0.0/16`

- apiserver-advertise-address=192.168.56.200 绑定 apiserver 到 master 节点的 Host-Only 适配器的地址，默认是绑到 NAT 的地址上，这样其他机器是永远也访问不到的。

- pod-network-cidr=10.244.0.0/16 指定 pod 网络地址空间，我们使用 flannel 组件必须使用这个空间。

kubeadm 的完整参考手册 kubeadm reference guide

推荐保存最后输出的 join 命令到文件(以免忘记或找不到了)，方便添加节点到集群。如果忘了也找不到输出了，网上有方法生成哈希值，请自行查找。

这里碰到的问题是第一次因为 docker cgroup 的原因失败了，因此又重新执行，导致了如下错误，解决办法也在下面了： 

</code></pre>

<p>[init] Using Kubernetes version: v1.20.1
[preflight] Running pre-flight checks
    [WARNING SystemVerification]: this Docker version is not on the list of validated versions: 20.10.1. Latest validated version: 19.03
error execution phase preflight: [preflight] Some fatal errors occurred:
    [ERROR FileAvailable&ndash;etc-kubernetes-manifests-kube-apiserver.yaml]: /etc/kubernetes/manifests/kube-apiserver.yaml already exists
    [ERROR FileAvailable&ndash;etc-kubernetes-manifests-kube-controller-manager.yaml]: /etc/kubernetes/manifests/kube-controller-manager.yaml already exists
    [ERROR FileAvailable&ndash;etc-kubernetes-manifests-kube-scheduler.yaml]: /etc/kubernetes/manifests/kube-scheduler.yaml already exists
    [ERROR FileAvailable&ndash;etc-kubernetes-manifests-etcd.yaml]: /etc/kubernetes/manifests/etcd.yaml already exists
    [ERROR Port-10250]: Port 10250 is in use
    [ERROR DirAvailable&ndash;var-lib-etcd]: /var/lib/etcd is not empty
[preflight] If you know what you are doing, you can make a check non-fatal with <code>--ignore-preflight-errors=...</code>
To see the stack trace of this error execute with &ndash;v=5 or higher</p>

<pre><code>
解决方法： `use &quot;kubeadm reset&quot; and reinitialize the kubeadm using &quot;kubeadm init&quot;`

地址： https://github.com/kubernetes/kubeadm/issues/1616

配置 kubectl 访问集群

</code></pre>

<h1 id="non-root-user">non-root user</h1>

<p>mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config</p>

<pre><code>
测试配置

</code></pre>

<p>kubectl cluster-info # 有正常输出即可</p>

<pre><code>
### 安装 flannel 网络

#### 安装与配置

flannel 默认的监听接口是 NAT 适配器的接口，我们需要的是 Host-Only 适配器的接口，所以需要修改 kube-flannel.yml 文件
</code></pre>

<h1 id="这个值金额搞好像-也是下载不了的-还是需要复制他">这个值金额搞好像 也是下载不了的，还是需要复制他</h1>

<p>wget <a href="https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml" rel="noreferrer" target="_blank">https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml</a></p>

<pre><code>给 /opt/bin/flanneld 命令添加 --iface=&quot;enp0s8&quot; 参数 # enp0s8 是 Host-Only 适配器对应的接口
</code></pre>

<p>kubectl apply -f kube-flannel.yml</p>

<pre><code>
#### 测试是否 OK
</code></pre>

<p>kubectl get pods &ndash;all-nam espaces -o wide # 稍等一会，下载镜像需要一定时间，�最后应该显示 flannel pods 是 Running 状态， kube-dns 也是 Running 状态</p>

<pre><code>

## 增加其他节点

在节点上执行 kubeadm init 最后输出的 join 命令
</code></pre>

<p>kubeadm join &ndash;token <token> <master-ip>:<master-port> &ndash;discovery-token-ca-cert-hash sha256:<hash></p>

<pre><code>
一旦遇到状态是 notReady 的情况大概率是拉镜像被强了，因此需要在 node 机器上使用脚本提前把镜像拉好，脚本在本文的上面。

然后在 master 节点如下做：

</code></pre>

<p>fupeng@master-node:~$ kubectl get node
NAME             STATUS   ROLES                  AGE   VERSION
master-node      Ready    control-plane,master   11m   v1.20.1
worker-node-03   Ready    <none>                 21s   v1.20.1
fupeng@master-node:~$ kubectl get pods &ndash;all-namespaces -o wide
NAMESPACE     NAME                                  READY   STATUS    RESTARTS   AGE     IP           NODE             NOMINATED NODE   READINESS GATES
kube-system   coredns-74ff55c5b-lfjxj               <sup>1</sup>&frasl;<sub>1</sub>     Running   0          11m     10.244.0.3   master-node      <none>           <none>
kube-system   coredns-74ff55c5b-mkn4h               <sup>1</sup>&frasl;<sub>1</sub>     Running   0          11m     10.244.0.2   master-node      <none>           <none>
kube-system   etcd-master-node                      <sup>1</sup>&frasl;<sub>1</sub>     Running   0          11m     10.0.2.15    master-node      <none>           <none>
kube-system   kube-apiserver-master-node            <sup>1</sup>&frasl;<sub>1</sub>     Running   0          11m     10.0.2.15    master-node      <none>           <none>
kube-system   kube-controller-manager-master-node   <sup>1</sup>&frasl;<sub>1</sub>     Running   0          11m     10.0.2.15    master-node      <none>           <none>
kube-system   kube-flannel-ds-9hmr5                 <sup>1</sup>&frasl;<sub>1</sub>     Running   0          23s     10.0.2.15    worker-node-03   <none>           <none>
kube-system   kube-flannel-ds-v4vft                 <sup>1</sup>&frasl;<sub>1</sub>     Running   0          4m37s   10.0.2.15    master-node      <none>           <none>
kube-system   kube-proxy-2trdt                      <sup>1</sup>&frasl;<sub>1</sub>     Running   0          11m     10.0.2.15    master-node      <none>           <none>
kube-system   kube-proxy-z5bgv                      <sup>1</sup>&frasl;<sub>1</sub>     Running   0          23s     10.0.2.15    worker-node-03   <none>           <none>
kube-system   kube-scheduler-master-node            <sup>1</sup>&frasl;<sub>1</sub>     Running   0          11m     10.0.2.15    master-node      <none>           <none>
```</p>

<hr />

<p>参考：</p>

<ul>
<li><a href="https://www.cnblogs.com/ITPower/p/12791615.html" rel="noreferrer" target="_blank">国内安装看这个</a></li>
<li><a href="https://github.com/c-rainstorm/blog/blob/master/devops/%E6%9C%AC%E6%9C%BA%E6%90%AD%E5%BB%BA%E4%B8%89%E8%8A%82%E7%82%B9k8s%E9%9B%86%E7%BE%A4.md#%E4%BD%BF%E7%94%A8-virtualbox-%E5%88%9B%E5%BB%BA%E4%B8%89%E5%8F%B0%E8%99%9A%E6%8B%9F%E6%9C%BA" rel="noreferrer" target="_blank">三节点k8s集群</a></li>
<li><a href="https://unix.stackexchange.com/questions/45781/shell-script-fails-syntax-error-unexpected" rel="noreferrer" target="_blank">shell 不识别 ()</a></li>
<li><a href="https://blog.csdn.net/M82_A1/article/details/95635705" rel="noreferrer" target="_blank">国内源安装 kubelet 等</a></li>
<li><a href="https://zhuanlan.zhihu.com/p/46341911" rel="noreferrer" target="_blank">shell 脚本处理 k8s 官方镜像地址被墙</a></li>
<li><a href="https://blog.csdn.net/sd4493091/article/details/103645032" rel="noreferrer" target="_blank">docker cgroup 错误</a></li>
<li><a href="https://blog.51cto.com/ygqygq2/2160083" rel="noreferrer" target="_blank">flanneld iface 错误问题</a></li>
</ul>

<hr />

<ol>
<li>如果不是ready状态, 查看日志, 看原因</li>
</ol>

<p>journalctl -f -u kubelet.service</p>

<ol>
<li>如果任一 Pod 状态不为 Running，请运行以下命令：</li>
</ol>

<p>$ kubectl describe pod yourPodName -n kube-system</p>

<ol>
<li>为了从 aws-node 和 kube-proxy Pod 日志中获取其他信息，请运行以下命令：</li>
</ol>

<p>$ kubectl logs yourPodName -n kube-system</p>

<ol>
<li>在node上执行kubeadm reset 可以断开node, 然后重新join</li>
<li>在master上执行kubeadm reset后可以重新init</li>
</ol>
        ]]>
      </description>
    </item>
    
    <item>
      <title>ubuntu 下安装 VirtualBox</title>
      <link>https://blog.lierhua.top/tech/ubuntu/11.-ubuntu-%E5%AE%89%E8%A3%85-virtualbox/</link>
      <pubDate>Tue, 10 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/ubuntu/11.-ubuntu-%E5%AE%89%E8%A3%85-virtualbox/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>ubuntu</code>, <code>virtualbox</code></p>

<h1 id="ubuntu-安装-virtualbox">ubuntu 安装 VirtualBox</h1>

<blockquote>
<p>NOTICE: 安装前先看一下这个文档： <a href="https://www.virtualbox.org/ticket/19644?cversion=0&amp;cnum_hist=8" rel="noreferrer" target="_blank">https://www.virtualbox.org/ticket/19644?cversion=0&amp;cnum_hist=8</a>
我就是进了这个坑，被坑了一天刚出来</p>
</blockquote>

<h2 id="我安装时遇到的坑">我安装时遇到的坑</h2>

<p>为了防止大家继续踩坑，我先把我安装时困扰我好久的坑说明一下。</p>

<p>我直接使用 apt 安装了 virtualbox 之后，当我要点击打开时，死活不出对应的界面，我就用命令行 virtualbox 直接启动，发现报错了，错误是我没有安装 virtualbox-dkms, 于是我用 apt 安装了 virtualbox-dkms， 然后重启 /sbin/vboxconfig 时还是报错，我查询了不少的资料，大部分集中在这个问题上</p>

<pre><code class="language-bash">vboxdrv.sh: Stopping VirtualBox services.
vboxdrv.sh: Starting VirtualBox services.
vboxdrv.sh: Building VirtualBox kernel modules.
vboxdrv.sh: failed: modprobe vboxdrv failed. Please use 'dmesg' to find out why.

There were problems setting up VirtualBox.  To re-start the set-up process, run
  /sbin/vboxconfig
as root.  If your system is using EFI Secure Boot you may need to sign the
kernel modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) before you can load
them. Please see your Linux system's documentation for more information.
</code></pre>

<p>于是我按照<a href="https://gist.github.com/reillysiemens/ac6bea1e6c7684d62f544bd79b2182a4" rel="noreferrer" target="_blank">这个步骤</a>进行操作，发现依然无法正常打开 virtualbox, 然后我就执行了如下操作（这个操作基于<a href="https://stackoverflow.com/questions/60350358/how-do-i-resolve-the-character-device-dev-vboxdrv-does-not-exist-error-in-ubu" rel="noreferrer" target="_blank">这个文档</a>）， （在执行这个操作前，我还发现了<a href="https://www.linuxquestions.org/questions/linux-software-2/virtualbox-is-installed-along-with-virtualbox-dkms-and-virtualbox-ext-pack-and-linux-headers-generic-but-error-for-no-dev-vboxdrv-4175649438/" rel="noreferrer" target="_blank">一篇文档</a>，具体找不到了，这篇文章里嫌处理麻烦，直接在 BIOS 里将 EFI 的 Secure boot 关闭了，我也跟着关闭了，我的电脑主板是华硕的，因此，参考了<a href="https://blog.csdn.net/qq_29650553/article/details/81028739" rel="noreferrer" target="_blank">这里</a>, 因为华硕主板有一些是加锁的，设置了安全启动的原因， 所以我刚开始看到的也是无法直接修改，但是后来根据这个文章处理好了， 但是此时 virtualbox 还是不行， 我就执行了下一步）</p>

<pre><code class="language-bash">fupeng@fupeng:~$ sudo dpkg-reconfigure virtualbox-dkms 

------------------------------
Deleting module version: 6.1.10
completely from the DKMS tree.
------------------------------
Done.
Loading new virtualbox-6.1.10 DKMS files...
Building for 5.8.0-34-generic
Building initial module for 5.8.0-34-generic
ERROR: Cannot create report: [Errno 17] File exists: '/var/crash/virtualbox-dkms.0.crash'
Error! Bad return status for module build on kernel: 5.8.0-34-generic (x86_64)
Consult /var/lib/dkms/virtualbox/6.1.10/build/make.log for more information.
</code></pre>

<p>对 virtualbox-dkms 进行重新 dpkg-reconfigure， 然后就发现了这个错误， 这个错误让我查看 <code>/var/crash/virtualbox-dkms.0.crash</code> 这个日至文件，于是我就打开了他</p>

<pre><code class="language-log">  1 ProblemType: Package
  2 DKMSBuildLog:
  3  DKMS make.log for virtualbox-6.1.10 for kernel 5.8.0-34-generic (x86_64)
  4  2020年 12月 19日 星期六 23:47:31 CST
  5  make: 进入目录“/usr/src/linux-headers-5.8.0-34-generic”
  6    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/linux/SUPDrv-linux.o
  7    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/SUPDrv.o
  8    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/SUPDrvGip.o
  9    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/SUPDrvSem.o
 10    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/SUPDrvTracer.o
 11    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/SUPLibAll.o
 12    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/alloc-r0drv.o
 13    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/initterm-r0drv.o
 14    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/memobj-r0drv.o
 15    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/mpnotification-r0drv.o
 16    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/powernotification-r0drv.o
 17    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/linux/assert-r0drv-linux.o
 18    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/linux/alloc-r0drv-linux.o
 19    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/linux/initterm-r0drv-linux.o
 20    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/linux/memobj-r0drv-linux.o
 21    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/linux/memuserkernel-r0drv-linux.o
 22    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/linux/mp-r0drv-linux.o
 23    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/linux/mpnotification-r0drv-linux.o
 24    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/linux/process-r0drv-linux.o
 25    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/linux/rtStrFormatKernelAddress-r0drv-linux.o
 26    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/linux/semevent-r0drv-linux.o
 27    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/linux/semeventmulti-r0drv-linux.o
 28  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/linux/alloc-r0drv-linux.c: In function ‘rtR0MemAllocExecVm    Area’:
 29  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/linux/alloc-r0drv-linux.c:171:15: error: implicit declarat    ion of function ‘__get_vm_area’; did you mean ‘get_vm_area’? [-Werror=implicit-function-declaration]
 30    171 |     pVmArea = __get_vm_area(cbAlloc, VM_ALLOC, MODULES_VADDR, MODULES_END);
 31        |               ^~~~~~~~~~~~~
 32        |               get_vm_area
 33  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/linux/alloc-r0drv-linux.c:171:13: warning: assignment to ‘    struct vm_struct *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
 34    171 |     pVmArea = __get_vm_area(cbAlloc, VM_ALLOC, MODULES_VADDR, MODULES_END);
 35        |             ^
 36  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/linux/alloc-r0drv-linux.c:204:14: error: implicit declarat    ion of function ‘map_vm_area’; did you mean ‘get_vm_area’? [-Werror=implicit-function-declaration]
 37    204 |         if (!map_vm_area(pVmArea, PAGE_KERNEL_EXEC,
 38        |              ^~~~~~~~~~~
 39        |              get_vm_area
 40  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/linux/memobj-r0drv-linux.c: In function ‘rtR0MemObjNativeF    ree’:

......

 98    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/linux/semmutex-r0drv-linux.o
 99    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/linux/spinlock-r0drv-linux.o
100    CC [M]  /var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/linux/thread-r0drv-linux.o
101  make[2]: *** [scripts/Makefile.build:290：/var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/linux/memobj-r0d    rv-linux.o] 错误 1
102  make[2]: *** 正在等待未完成的任务....
103  make[2]: *** [scripts/Makefile.build:290：/var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/linux/SUPDrv-linux.o]     错误 1
104  cc1: some warnings being treated as errors
105  make[2]: *** [scripts/Makefile.build:290：/var/lib/dkms/virtualbox/6.1.10/build/vboxdrv/r0drv/linux/alloc-r0dr    v-linux.o] 错误 1
106  make[1]: *** [scripts/Makefile.build:519：/var/lib/dkms/virtualbox/6.1.10/build/vboxdrv] 错误 2
107  make: *** [Makefile:1780：/var/lib/dkms/virtualbox/6.1.10/build] 错误 2
108  make: 离开目录“/usr/src/linux-headers-5.8.0-34-generic”
109 DKMSKernelVersion: 5.8.0-34-generic
110 Date: Sat Dec 19 23:47:34 2020
111 DuplicateSignature: dkms:virtualbox-dkms:6.1.10-dfsg-1~ubuntu1.20.04.1:/var/lib/dkms/virtualbox/6.1.10/build/vb    oxdrv/r0drv/linux/alloc-r0drv-linux.c:171:15: error: implicit declaration of function ‘__get_vm_area’; did you     mean ‘get_vm_area’? [-Werror=implicit-function-declaration]
112 Package: virtualbox-dkms 6.1.10-dfsg-1~ubuntu1.20.04.1
113 PackageVersion: 6.1.10-dfsg-1~ubuntu1.20.04.1
114 SourcePackage: virtualbox
115 Title: virtualbox-dkms 6.1.10-dfsg-1~ubuntu1.20.04.1: virtualbox kernel module failed to build
</code></pre>

<p>看到这个日志文件，我大概知道具体原因了，就是 get<em>vm</em>area 这个函数出问题了，到这里猜测应该是内核兼容性的问题了，于是我就 google 了一个这个 <code>virtualbox get_vm_area</code> 就出现了这篇 <a href="https://www.virtualbox.org/ticket/19644?cversion=0&amp;cnum_hist=8" rel="noreferrer" target="_blank">issue 文章</a>, 这篇文章里详细的解释了具体原因，就是内核 <code>5.8</code> 不能编译 virtualbox-6.1.14 前的版本了。所以我从这里面找到了解决的办法：</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-20%2018-38-48%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png" alt="" /></p>

<p>然后找到了 virtualbox 官网的地址给出的 <a href="https://www.virtualbox.org/wiki/Testbuilds" rel="noreferrer" target="_blank">testbuild 方式</a></p>

<p>然后我就直接下载了 Linux 64-bit  6.1.x revision 141968 版本，然后下载好 chmod 后， 直接执行，然后就安装好了，此时，启动，已经可以启动起来了。</p>

<h2 id="正式开始的文章">正式开始的文章</h2>

<p>Oracle 公司的自由开源产品 VirtualBox 是一款出色的虚拟化工具，专门用于桌面操作系统。与另一款虚拟化工具 Linux 上的 VMWare Workstation 相比起来，我更喜欢它。 你可以使用 VirtualBox 等虚拟化软件在虚拟机中安装和使用其他操作系统。</p>

<p>例如，你可以在 Windows 上的 VirtualBox 中安装 Linux。同样地，你也可以用 VirtualBox 在 Linux 中安装 Windows。</p>

<p>你也可以用 VirtualBox 在你当前的 Linux 系统中安装别的 Linux 发行版。事实上，这就是我用它的原因。如果我听说了一个不错的 Linux 发行版，我会在虚拟机上测试它，而不是安装在真实的系统上。当你想要在安装之前尝试一下别的发行版时，用虚拟机会很方便。</p>

<p>在本新手教程中，我将向你展示在 Ubuntu 和其他基于 Debian 的 Linux 发行版上安装 VirtualBox 的各种方法。
在 Ubuntu 和基于 Debian 的 Linux 发行版上安装 VirtualBox</p>

<p>这里提出的安装方法也适用于其他基于 Debian 和 Ubuntu 的 Linux 发行版，如 Linux Mint、elementar OS 等。</p>

<h2 id="从-ubuntu-仓库安装-virtualbox">从 Ubuntu 仓库安装 VirtualBox</h2>

<p>优点：安装简便</p>

<p>缺点：较旧版本</p>

<p>在 Ubuntu 上下载 VirtualBox 最简单的方法可能是从软件中心查找并下载。</p>

<p>VirtualBox 在 Ubuntu 软件中心提供</p>

<p>你也可以使用这条命令从命令行安装：</p>

<p>sudo apt install virtualbox</p>

<p>然而，如果在安装前检查软件包版本，你会看到 Ubuntu 仓库提供的 VirtualBox 版本已经很老了。</p>

<p>举个例子，在写下本教程时 VirtualBox 的最新版本是 6.0，但是在软件中心提供的是 5.2。这意味着你无法获得最新版 VirtualBox 中引入的新功能。</p>

<h2 id="使用-oracle-网站上的-deb-文件安装-virtualbox">使用 Oracle 网站上的 Deb 文件安装 VirtualBox</h2>

<p>优点：安装简便，最新版本</p>

<p>缺点：不能更新</p>

<p>如果你想要在 Ubuntu 上使用 VirtualBox 的最新版本，最简单的方法就是使用 Deb 文件。</p>

<p>Oracle 为 VirtiualBox 版本提供了开箱即用的二进制文件。如果查看其下载页面，你将看到为 Ubuntu 和其他发行版下载 deb 安装程序的选项。</p>

<p>VirtualBox Linux Download</p>

<p>你只需要下载 deb 文件并双击它即可安装。就是这么简单。</p>

<p><a href="https://link.zhihu.com/?target=https%3A//www.virtualbox.org/wiki/Linux_Downloads" rel="noreferrer" target="_blank">下载 virtualbox for Ubuntu</a></p>

<p>然而，这种方法的问题在于你不能自动更新到最新的 VirtualBox 版本。唯一的办法是移除现有版本，下载最新版本并再次安装。不太方便，是吧？</p>

<h2 id="用-oracle-的仓库安装-virtualbox">用 Oracle 的仓库安装 VirtualBox</h2>

<p>优点：自动更新</p>

<p>缺点：安装略微复杂</p>

<p>现在介绍的是命令行安装方法，它看起来可能比较复杂，但与前两种方法相比，它更具有优势。你将获得 VirtualBox 的最新版本，并且未来它还将自动更新到更新的版本。我想那就是你想要的。</p>

<p>要通过命令行安装 VirtualBox，请在你的仓库列表中添加 Oracle VirtualBox 的仓库。添加 GPG 密钥以便你的系统信任此仓库。现在，当你安装 VirtualBox 时，它会从 Oracle 仓库而不是 Ubuntu 仓库安装。如果发布了新版本，本地 VirtualBox 将跟随一起更新。让我们看看怎么做到这一点：</p>

<p>首先，添加仓库的密钥。你可以通过这一条命令下载和添加密钥：</p>

<p>wget -q <a href="https://www.virtualbox.org/download/oracle_vbox_2016.asc" rel="noreferrer" target="_blank">https://www.virtualbox.org/download/oracle_vbox_2016.asc</a> -O- | sudo apt-key add -</p>

<pre><code>Mint 用户请注意：
下一步只适用于 Ubuntu。如果你使用的是 Linux Mint 或其他基于 Ubuntu 的发行版，请将命令行中的 $(lsb_release -cs) 替换成你当前版本所基于的 Ubuntu 版本。例如，Linux Mint 19 系列用户应该使用 bionic，Mint 18 系列用户应该使用 xenial，像这样：
sudo add-apt-repository “deb [arch=amd64] &lt;http://download.virtualbox.org/virtualbox/debian&gt; **bionic** contrib“`
</code></pre>

<p>现在用以下命令来将 Oracle VirtualBox 仓库添加到仓库列表中：</p>

<p>sudo add-apt-repository &ldquo;deb [arch=amd64] <a href="http://download.virtualbox.org/virtualbox/debian" rel="noreferrer" target="_blank">http://download.virtualbox.org/virtualbox/debian</a> $(lsb_release -cs) contrib&rdquo;</p>

<p>如果你有读过我的文章检查 Ubuntu 版本，你大概知道 lsb_release -cs 将打印你的 Ubuntu 系统的代号。</p>

<p>注：如果你看到 “add-apt-repository command not found” 错误，你需要下载 software-properties-common 包。</p>

<p>现在你已经添加了正确的仓库，请通过此仓库刷新可用包列表并安装 VirtualBox:</p>

<p>sudo apt update &amp;&amp; sudo apt install virtualbox-6.0</p>

<p>提示：一个好方法是输入 sudo apt install virtualbox- 并点击 tab 键以查看可用于安装的各种 VirtualBox 版本，然后通过补全命令来选择其中一个版本。</p>

<h2 id="如何从-ubuntu-中删除-virtualbox">如何从 Ubuntu 中删除 VirtualBox</h2>

<p>现在你已经学会了如何安装 VirtualBox，我还想和你提一下删除它的步骤。</p>

<p>如果你是从软件中心安装的，那么删除它最简单的方法是从软件中心下手。你只需要在已安装的应用程序列表中找到它，然后单击“删除”按钮。</p>

<p>另一种方式是使用命令行：</p>

<p>sudo apt remove virtualbox virtualbox-*</p>

<p>请注意，这不会删除你用 VirtualBox 安装的操作系统关联的虚拟机和文件。这并不是一件坏事，因为你可能希望以后或在其他系统中使用它们是安全的。</p>

<h2 id="解决安装完后的其他问题">解决安装完后的其他问题</h2>

<hr />

<p>参考：</p>

<ul>
<li><a href="https://stegard.net/2016/10/virtualbox-secure-boot-ubuntu-fail/" rel="noreferrer" target="_blank">VirtualBox + Secure Boot + Ubuntu = fail</a></li>
<li><a href="https://gist.github.com/reillysiemens/ac6bea1e6c7684d62f544bd79b2182a4" rel="noreferrer" target="_blank">Signing VirtualBox Kernel Modules</a></li>
<li><a href="https://superuser.com/questions/1438279/how-to-sign-a-kernel-module-ubuntu-18-04" rel="noreferrer" target="_blank">How to sign a kernel module Ubuntu 18.04</a></li>
</ul>
        ]]>
      </description>
    </item>
    
    <item>
      <title>ubuntu 下的 APP</title>
      <link>https://blog.lierhua.top/tech/ubuntu/1.-ubuntu-%E4%B8%8B%E5%BF%85%E9%A1%BB%E7%9A%84-app/</link>
      <pubDate>Tue, 10 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/ubuntu/1.-ubuntu-%E4%B8%8B%E5%BF%85%E9%A1%BB%E7%9A%84-app/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>ubuntu</code>, <code>app</code>, <code>deb</code>, <code>snap</code></p>

<h1 id="ubuntu-下必须的-app">ubuntu 下必须的 app</h1>

<p>之前装完 Linux 发行版就直接用了, 这次准备开一个系统的文章, 讲一下 Linux 发行版装完之后, 你需要干哪些操作, 才能让你的系统更好用.</p>

<p>介绍下我的 ubuntu 系统中安装的一些 app 以及不同的安装方式.</p>

<p>大体分为三类
- deb 文件，这个双击后，可以通过 ubuntu 自带的 Ubuntu Software 进行安装，这个打开时可以直接点击图标打开即可，例如 VS Code ；
- 二进制文件，需要放到 PATH 的目录下，这样方便启动和设置， 例如 Clash；
- 大型软件，不仅仅是一个二进制文件，但是和第二个一样，一般也是放到 PATH 目录对应的位置，但是具体的位置有一些差异，比如 goland IDE；
- 可以通过 <code>apt</code> 直接安装的，这一类直接比较好处理，但是有些情况也比较特殊，需要单独说一下。</p>

<h2 id="deb-文件类">deb 文件类</h2>

<p>以 VS Code 为例子</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-11%2015-38-27d%20%E7%9A%84%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png" alt="" /></p>

<p>可以看到他提供的安装文件是 <code>.deb</code> 格式的，下载之后，双击，弹出 ubuntu 自带的软件管理器，直接安装即可。</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-11_22-16.png" alt="" /></p>

<h2 id="小-app">小 APP</h2>

<p>这一类我称之为小 APP ，他们都不是很大，100M 以内，用处一般都是处理某个方面的，比如 clash 用于代理服务， typora 是一个风格比较好看的 markdown 编辑器。</p>

<p>一般这种下载之后，放到 <code>/opt</code> 目录下，然后软链接到 <code>/usr/local/bin</code> 下面即可。</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-11_22-22.png" alt="" /></p>

<p>一般也会在 <code>.bashrc</code> 中设置一个 alias，使用 nohup 启动，防止挂掉。</p>

<p>如果是需要开机就启动的，且偏向于系统级别的，比如 clash, 我会使用 systemctl 来控制， 在 <code>/etc/systemd/system</code> 下编辑配置文件，同时使用 <code>systemctl enable clash.service</code> 来进行开机启动。</p>

<p>具体的例子请看我另一篇专门介绍 clash 的文章。</p>

<h2 id="大型软件">大型软件</h2>

<p>还有一种，其实归类的话，应该和第二种类似，但是他们更重，体积也更大, 更重要的是他们不仅仅是一个二进制文件这么简单，他们还涉及到很多的其他文件，这一类，我也放到 <code>/opt</code> 下面，并且将他们的启动文件软链接到 <code>/usr/local/bin</code> 下面。</p>

<p>以 goland 为例子，他不仅仅是一个二进制文件，他的启动文件是 <code>./Goland/bin/goland.sh</code> ，因此我需要将他的启动文件软链接到 <code>/usr/local/bin</code> 下。</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-11_22-35.png" alt="" /></p>

<p>将他们软链接处理好之后，我一般会在 <code>.bashrc</code> 中设置一个 alias ，方便之后更便捷的访问。</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-11_22-37.png" alt="" /></p>

<p>使用 nohup 启动，防止因为 terminal 关闭导致软件也被关闭掉。</p>

<p>注意： 对于 jetbrain 全家筒，除了上述的方式，还有更方便的方式。</p>

<p>下载 (Toolbox App)[<a href="https://www.jetbrains.com/toolbox-app/" rel="noreferrer" target="_blank">https://www.jetbrains.com/toolbox-app/</a>] 到本地，然后执行此文件，如果双击失效，需要用命令行执行，此文件会打开一个界面，然后就可以在这个界面里挑选对应要处理的 app.</p>

<p>等下载安装后，就会生成对应的 icon，就可以直接双击打开对应的 IDE 。</p>

<h2 id="apt-直接安装">apt 直接安装</h2>

<p>有些 app 可以通过 apt 直接安装, 比如 <code>dconf-editor</code> ，直接 <code>sudo apt install dconf-editor -y</code> 即可安装，然后会生成一个 icon，可以直接点击调用，此类型的还有不少。</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-11%2022-46-08%20%E7%9A%84%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png" alt="" /></p>

<ul>
<li>国内下载会很慢，推荐使用阿里源，具体看我另一篇关于换源的文章。*</li>
</ul>

<p>类似于 alfred 的启动器使用 albert， 安装方法如下，也可以查看下面第四类里的官网：</p>

<pre><code class="language-bash"># Full example for Ubuntu 20.04
curl https://build.opensuse.org/projects/home:manuelschneid3r/public_key | sudo apt-key add -
echo 'deb http://download.opensuse.org/repositories/home:/manuelschneid3r/xUbuntu_20.04/ /' | sudo tee /etc/apt/sources.list.d/home:manuelschneid3r.list
sudo wget -nv https://download.opensuse.org/repositories/home:manuelschneid3r/xUbuntu_20.04/Release.key -O &quot;/etc/apt/trusted.gpg.d/home:manuelschneid3r.asc&quot;
sudo apt update
sudo apt install albert
</code></pre>

<h2 id="deepin-wine-类">deepin-wine 类</h2>

<p>对于官网未提供了 Ubuntu 版本 .deb 安装文件，但 deepin 中有的应用程序，可以使用 Deepin-Wine 来安装。</p>

<p>wine 是一种在 Linux 平台实现了部分 Windows 系统 API 的技术，可以让用户在 Linux 平台无缝使用 Windows 平台的应用程序。</p>

<p>deepin-wine 是国内的深度社区在 deepin linux 上经过改造的 wine 程序，并且社区在 deepin-wine 之上移植了很多的 Windows 软件，比如微信、QQ、TIM等。</p>

<p>github 上有人开发了一个项目 deepin-wine-ubuntu，将 deepin-wine 及其之上适配好的各种 deb 软件包迁移到了 Ubuntu 上。要安装微信、QQ等软件，我们需要先安装 deep-wine-ubuntu。方法如下：</p>

<ol>
<li><p>首先 clone deepin-wine-ubuntu 源码到本地
git clone git@github.com:wszqkzqk/deepin-wine-ubuntu.git`</p></li>

<li><p>切换到源码目录
<code>cd deepin-wine-ubuntu</code></p></li>

<li><p>安装脚本授权
<code>sudo chmod +x install_2.8.22.sh</code></p></li>

<li><p>安装 deep-wine-ubuntu
<code>./install_2.8.22.sh</code>,
<code>deep-wine-ubuntu</code> 安装完成之后，我们就可以下载深度社区提供的各种 deb 软件</p></li>

<li><p>安装
<code>sudo apt install ./&lt;file&gt;.deb</code></p></li>
</ol>

<p>深度社区提供的各种 deb 软件下载地址, 部分软件下载地址：</p>

<ul>
<li>QQ：<a href="https://mirrors.aliyun.com/deepin/pool/non-free/d/deepin.com.qq.im" rel="noreferrer" target="_blank">https://mirrors.aliyun.com/deepin/pool/non-free/d/deepin.com.qq.im</a></li>
<li>TIM：<a href="https://mirrors.aliyun.com/deepin/pool/non-free/d/deepin.com.qq.office" rel="noreferrer" target="_blank">https://mirrors.aliyun.com/deepin/pool/non-free/d/deepin.com.qq.office</a></li>
<li>微信：<a href="https://mirrors.aliyun.com/deepin/pool/non-free/d/deepin.com.wechat" rel="noreferrer" target="_blank">https://mirrors.aliyun.com/deepin/pool/non-free/d/deepin.com.wechat</a></li>
<li>更多安装方法及软件地址可以参考: <a href="https://github.com/wszqkzqk/deepin-wine-ubuntu" rel="noreferrer" target="_blank">https://github.com/wszqkzqk/deepin-wine-ubuntu</a></li>
</ul>

<p>如果你的系统语言非中文，通过 deepin-wine 启动的软件中文会出现乱码。你需要将 <code>/opt/deepinwine/tools/run.sh</code> 文件中 WINE_CMD 这一行修改为：
<code>WINE_CMD=&quot;LC_ALL=zh_CN.UTF-8 deepin-wine&quot;</code></p>

<hr />

<p>上面介绍了下我常用的一些 app 安装方案，下面是我自己觉得 ubuntu 上必须安装的一些 app 以及他们都是用来干什么的以及都属于我上面说的哪一类的。</p>

<h2 id="第一类-deb-文件">第一类, deb 文件</h2>

<ul>
<li><a href="https://code.visualstudio.com/" rel="noreferrer" target="_blank">VS Code</a></li>
<li><a href="https://pan.baidu.com/download?from=header" rel="noreferrer" target="_blank">百度网盘</a></li>
<li><a href="https://linux.wps.cn/" rel="noreferrer" target="_blank">WPS</a></li>
<li>网易云</li>
<li><a href="https://www.google.com/intl/zh-CN/chrome/" rel="noreferrer" target="_blank">chrome</a></li>
</ul>

<h2 id="第二类-二进制文件">第二类，二进制文件</h2>

<ul>
<li><a href="https://typora.io/" rel="noreferrer" target="_blank">typora markdown 工具</a></li>
<li><a href="https://github.com/Dreamacro/clash" rel="noreferrer" target="_blank">clash 代理工具</a></li>
<li><a href="https://github.com/Molunerfinn/PicGo" rel="noreferrer" target="_blank">picgo 图床工具</a></li>
</ul>

<h2 id="第三类-大型软件">第三类，大型软件</h2>

<ul>
<li><a href="https://www.jetbrains.com/go/" rel="noreferrer" target="_blank">goland</a></li>
<li>pycharm</li>
<li>phpstorm</li>
</ul>

<h2 id="第四类">第四类</h2>

<ul>
<li><a href="https://github.com/flameshot-org/flameshot" rel="noreferrer" target="_blank">flameshot</a></li>
<li><a href="https://gitlab.gnome.org/GNOME/dconf-editor" rel="noreferrer" target="_blank">dconf-editor</a></li>
<li><a href="https://albertlauncher.github.io/installing/" rel="noreferrer" target="_blank">albert launcher 工具</a></li>
</ul>
        ]]>
      </description>
    </item>
    
    <item>
      <title>ubuntu 下的 apt 的几个小问题</title>
      <link>https://blog.lierhua.top/tech/ubuntu/9.-ubuntu-apt-%E7%9A%84%E5%87%A0%E4%B8%AA%E9%97%AE%E9%A2%98/</link>
      <pubDate>Tue, 10 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/ubuntu/9.-ubuntu-apt-%E7%9A%84%E5%87%A0%E4%B8%AA%E9%97%AE%E9%A2%98/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>ubuntu</code>, <code>apt</code></p>

<h1 id="ubuntu-apt-的几个问题">ubuntu apt 的几个问题</h1>

<p>碰到的问题：</p>

<p>执行 <code>sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys</code></p>

<p>会报错，报错如下：</p>

<pre><code class="language-bash">Executing: /tmp/apt-key-gpghome.s1rywy7rMb/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys
gpg: invalid key resource URL '/tmp/apt-key-gpghome.s1rywy7rMb/home:manuelschneid3r.asc.gpg'
gpg: 密钥区块资源‘(null)’：一般错误
gpg: key 7721F63BD38B4796: 2 个签名因密钥遗失而未被检查
gpg: key 1488EB46E192A257: 1 个签名因密钥遗失而未被检查
gpg: key 3B4FE6ACC0B21F32: 3 个签名因密钥遗失而未被检查
gpg: key D94AA3F0EFE21092: 3 个签名因密钥遗失而未被检查
gpg: key 871920D1991BC93C: 1 个签名因密钥遗失而未被检查
gpg: 处理的总数：6
gpg:       已跳过的新密钥：6
</code></pre>

<p>解决：
1. 首先删除 <code>home:manuelschneid3r.asc.gpg</code> 对应的位置:  <code>sudo rm /etc/apt/trusted.gpg.d/home:manuelschneid3r.asc</code></p>

<ol>
<li><p>然后执行命令添加缺失的 key :
<code>sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7721F63BD38B4796 1488EB46E192A257</code></p>

<pre><code class="language-bash">fupeng@fupeng:~/下载$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7721F63BD38B4796 1488EB46E192A257
Executing: /tmp/apt-key-gpghome.6gaCubwLuW/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 7721F63BD38B4796 1488EB46E192A257
gpg: 密钥 1488EB46E192A257：公钥 “home:manuelschneid3r OBS Project &lt;home:manuelschneid3r@build.opensuse.org&gt;” 已导入
gpg: 密钥 7721F63BD38B4796：“Google Inc. (Linux Packages Signing Authority) &lt;linux-packages-keymaster@google.com&gt;” 未改变
gpg: 处理的总数：2
gpg:               已导入：1
gpg:              未改变：1
</code></pre></li>
</ol>

<hr />

<p>碰到如下错误是执行顺序错误导致的，按照正确的顺序来即可：</p>

<pre><code class="language-bash">fupeng@fupeng:~/下载$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7721F63BD38B4796 1488EB46E192A257
Executing: /tmp/apt-key-gpghome.Pha7uWyRAL/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 7721F63BD38B4796 1488EB46E192A257
gpg: 密钥 1488EB46E192A257：“home:manuelschneid3r OBS Project &lt;home:manuelschneid3r@build.opensuse.org&gt;” 未改变
gpg: 密钥 7721F63BD38B4796：“Google Inc. (Linux Packages Signing Authority) &lt;linux-packages-keymaster@google.com&gt;” 未改变
gpg: 处理的总数：2
gpg:              未改变：2
gpg: invalid key resource URL '/tmp/apt-key-gpghome.Pha7uWyRAL/home:manuelschneid3r.asc.gpg'
gpg: 密钥区块资源‘(null)’：一般错误
gpg: key 7721F63BD38B4796: 2 个签名因密钥遗失而未被检查
gpg: key 1488EB46E192A257: 1 个签名因密钥遗失而未被检查
gpg: key 3B4FE6ACC0B21F32: 3 个签名因密钥遗失而未被检查
gpg: key D94AA3F0EFE21092: 3 个签名因密钥遗失而未被检查
gpg: key 871920D1991BC93C: 1 个签名因密钥遗失而未被检查
gpg: 处理的总数：6
gpg:       已跳过的新密钥：6
</code></pre>

<hr />

<p>参考</p>

<ul>
<li><a href="http://naveenubuntu.blogspot.com/2011/08/fixing-gpg-keys-in-ubuntu.html" rel="noreferrer" target="_blank">http://naveenubuntu.blogspot.com/2011/08/fixing-gpg-keys-in-ubuntu.html</a></li>
</ul>

<hr />

<p>问题：</p>

<p>dpkg: 处理软件包 xxx (&ndash;configure)时出错</p>

<p>第一步：备份</p>

<p>$ sudo mv /var/lib/dpkg/info /var/lib/dpkg/info.bk</p>

<p>第二步：新建</p>

<p>$ sudo mkdir /var/lib/dpkg/info</p>

<p>第三步：更新</p>

<p>$ sudo apt update
$ sudo apt -f install</p>

<p>第四步：替换</p>

<p>$ sudo mv /var/lib/dpkg/info/* /var/lib/dpkg/info.bk
//把更新的文件替换到备份文件夹</p>

<p>第五步：删除</p>

<p>$ sudo rm -rf /var/lib/dpkg/info
//把自己新建的info文件夹删掉</p>

<p>第六步：还原</p>

<p>$ sudo mv /var/lib/dpkg/info.bk /var/lib/dpkg/info
//把备份的info.bk还原</p>

<pre><code>sudo mv /var/lib/dpkg/info /var/lib/dpkg/info.bk
sudo mkdir /var/lib/dpkg/info
sudo apt update
sudo apt -f install
sudo mv /var/lib/dpkg/info/* /var/lib/dpkg/info.bk 
sudo rm -rf /var/lib/dpkg/info 
sudo mv /var/lib/dpkg/info.bk /var/lib/dpkg/info
</code></pre>

<p>sudo openssl <br />
    req <br />
    -new <br />
    -x509 <br />
    -newkey <br />
    rsa:2048 <br />
    -keyout ${out<em>dir}/MOK.priv <br />
    -outform DER <br />
    -out ${out</em>dir}/MOK.der <br />
    -days 36500 <br />
    -subj &ldquo;/CN=${name}/&rdquo;</p>
        ]]>
      </description>
    </item>
    
    <item>
      <title>ubuntu 下的 clash</title>
      <link>https://blog.lierhua.top/tech/ubuntu/2.-ubuntu-%E4%B8%8B%E7%9A%84-clash/</link>
      <pubDate>Tue, 10 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/ubuntu/2.-ubuntu-%E4%B8%8B%E7%9A%84-clash/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>ubuntu</code>, <code>clash</code></p>

<h1 id="ubuntu-下的-clash">ubuntu 下的 clash</h1>

<p>无论是在 mac 还是 windows 下，我们下在 clash 之后，直接安装，然后在 clash 提供的 gui 界面进行设计即可。</p>

<p>但是 ubuntu 下是不直接提供 gui 界面的，他是通过提供 web 界面来展示的，并且相比于 windows 和 mac 可以直接通过界面进行配置文件的设置和加载， linux 版的 web 界面不提供这个功能。</p>

<p>为了更加方便进行设置，记录一下整个配置的流程。</p>

<h2 id="下载">下载</h2>

<p>地址： [github 下载地址]（<a href="https://github.com/Dreamacro/clash）" rel="noreferrer" target="_blank">https://github.com/Dreamacro/clash）</a></p>

<p>具体的 linux 版本位置从 github 的 tags 里寻找，找到一个版本合适的 tags， 然后进入这个 tags 记录的 content 里：</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-11%2020-23-24%20%E7%9A%84%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png" alt="" /></p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-11%2020-27-37%20%E7%9A%84%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png" alt="" /></p>

<p>从列表中选择你要的平台的，比如 ubuntu 下，就选择 <code>clash-linux-amd64</code> 的即可。</p>

<p>下载到某个具体的位置，一般是 <code>$HOME/下载</code>, 解压之后就得到了我们想要的 clash 的二进制文件。</p>

<h2 id="安装">安装</h2>

<p>我们将解压之后得到的二进制文件，放到 <code>/opt/clash</code> 路径下, 并设置一个软连链接到 <code>/usr/local/bin</code> 目录下，这个目录是我的命令目录，一般安装到 <code>/opt</code> 的文件或者其他软件都会设置一个软连接到这里，方便直接调用。</p>

<p>默认 clash 的配置文件是放在 <code>.config/clash</code> 下的，主要有两个文件，分别是  <code>config.yaml</code> 和 <code>Country.mmdb</code>，前者是 clash 的主要配置文件，后者是国家信息文件。</p>

<p>但是我们一般不喜欢直接使用默认的配置文件的地址，一个是经常会忘记这个配置文件的具体位置，二是也不是很方便管理，因此我们要将其放到我们配置文件的集中管理的地方  <code>/etc</code>  下，我们在 <code>/etc</code> 下建立文件夹 <code>clash/</code> 用于放置我这两个具体的配置文件，将配置文件迁移到这个位置之后，启动 clash 的命令就要指定对应的配置文件的具体地址或者目录，如下：</p>

<pre><code class="language-bash"># 使用 -d 指定配置文件的目录地址
$ clash -d . # current directory
$ clash -d /etc/clash

# 使用 -f 指定配置文件的地址
$ clash -f ./config.yaml # current directory
$ clash -f /etc/clash/config.yaml
</code></pre>

<p>参考地址： <a href="https://github.com/Dreamacro/clash/wiki/configuration" rel="noreferrer" target="_blank">clash 的配置文件参数含义</a></p>

<p>此时，直接运行 <code>clash -d /etc/clash</code> 就可以将 clash 启动了，在讲解提供服务后的端口信息和 web 信息之前，我们先了解下具体的配置文件，方便我们更好的知道接下来怎么做。</p>

<h2 id="配置简介">配置简介</h2>

<pre><code class="language-yaml"># Port of HTTP(S) proxy server on the local end
# 提供 http 代理的端口，注意需要配置代理的时候需要用到
port: 7890

# Port of SOCKS5 proxy server on the local end
# 提供 socks5 代理的端口 ，注意配置代理的时候需要用到
socks-port: 7891

# Clash router working mode
# rule: rule-based packet routing
# global: all packets will be forwarded to a single endpoint
# direct: directly forward the packets to the Internet
mode: rule

# Clash by default prints logs to STDOUT
# info / warning / error / debug / silent
# 日至的级别，设置哪个级别，打印出来的就是那个级别以上的日至
log-level: info

# When set to false, resolver won't translate hostnames to IPv6 addresses
ipv6: false

# RESTful web API listening address
# web 界面的地址，这个注意设置的时候的端口号，打开 http://clash.razord.top/#/proxies 时要配置
external-controller: 127.0.0.1:9090

# A relative path to the configuration directory or an absolute path to a
# directory in which you put some static web resource. Clash core will then
# serve it at `http://{{external-controller}}/ui`.
external-ui: folder

# Secret for the RESTful API (optional)
# Authenticate by spedifying HTTP header `Authorization: Bearer ${secret}`
# ALWAYS set a secret if RESTful API is listening on 0.0.0.0
# secret: &quot;&quot;

# Outbound interface name
interface-name: en0

... more
</code></pre>

<p>介绍这些配置主要是因为，我们除了将 clash 启动，还需要在系统配置上配置好这些代理，并且打开我们的 web 界面查看服务是否正常了。</p>

<h3 id="配置系统代理界面">配置系统代理界面</h3>

<p>按照如下的方式进行系统代理的配置：</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-11_21-03.png" alt="" /></p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-11_21-05.png" alt="" /></p>

<h3 id="配置-clash-web-界面">配置 clash web 界面</h3>

<p>打开浏览器，输入地址 <code>http://clash.razord.top</code>, 此时会弹出一个设置 web 端口号的界面，填入在配置文件里 <code>external-controller</code> 对应的地址即可，然后就可以查看界面上的内容了。</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-11_21-12.png" alt="" /></p>

<p>至此，最基础的 clash 的配置已经完成，总结以下就是：</p>

<p>下载, 安装，配置，系统代理，界面设置</p>

<h2 id="启动">启动</h2>

<p>为了防止 clash 随着某个 terminal 挂掉，我们设置将 clash 作为开机启动项，并用 <code>systemctl</code> 守护一下。</p>

<p>在 <code>/etc/systemd/system</code> 下新建文件 <code>clash.service</code>, 得到 <code>/etc/systemd/system/clash.service</code> 文件，然后填入以下配置：</p>

<pre><code class="language-ini">[Unit]
Description=clash daemon

[Service]
Type=simple
User=fupeng
ExecStart=/usr/local/bin/clash -d /etc/clash
Restart=on-failure

[Install]
WantedBy=multi-user.target

</code></pre>

<p>保存之后，<code>sudo systemctl daemon-reload</code> 重新加载配置文件。</p>

<p><code>sudo systemctl start clash.service</code> 启动服务，如果想设置为开机启动，执行 <code>systemctl enable clash.service</code> 即可。</p>

<h2 id="后话">后话</h2>

<h3 id="systemd-配置">systemd 配置</h3>

<p>关于 systemd 的配置文件的简介</p>

<pre><code class="language-ini">[Unit]

Description : 服务的简单描述

Documentation ： 服务文档

Before、After:定义启动顺序。Before=xxx.service,代表本服务在xxx.service启动之前启动。After=xxx.service,代表本服务在xxx.service之后启动。

Requires：这个单元启动了，它需要的单元也会被启动；它需要的单元被停止了，这个单元也停止了。

Wants：推荐使用。这个单元启动了，它需要的单元也会被启动；它需要的单元被停止了，对本单元没有影响。

[Service]

Type=simple（默认值）：systemd认为该服务将立即启动。服务进程不会fork。如果该服务要启动其他服务，不要使用此类型启动，除非该服务是socket激活型。

Type=forking：systemd认为当该服务进程fork，且父进程退出后服务启动成功。对于常规的守护进程（daemon），除非你确定此启动方式无法满足需求，使用此类型启动即可。使用此启动类型应同时指定 PIDFile=，以便systemd能够跟踪服务的主进程。

Type=oneshot：这一选项适用于只执行一项任务、随后立即退出的服务。可能需要同时设置 RemainAfterExit=yes 使得 systemd 在服务进程退出之后仍然认为服务处于激活状态。

Type=notify：与 Type=simple 相同，但约定服务会在就绪后向 systemd 发送一个信号。这一通知的实现由 libsystemd-daemon.so 提供。

Type=dbus：若以此方式启动，当指定的 BusName 出现在DBus系统总线上时，systemd认为服务就绪。

Type=idle: systemd会等待所有任务(Jobs)处理完成后，才开始执行idle类型的单元。除此之外，其他行为和Type=simple 类似。

PIDFile：pid文件路径

ExecStart：指定启动单元的命令或者脚本，ExecStartPre和ExecStartPost节指定在ExecStart之前或者之后用户自定义执行的脚本。Type=oneshot允许指定多个希望顺序执行的用户自定义命令。

ExecReload：指定单元停止时执行的命令或者脚本。

ExecStop：指定单元停止时执行的命令或者脚本。

PrivateTmp：True表示给服务分配独立的临时空间

Restart：这个选项如果被允许，服务重启的时候进程会退出，会通过systemctl命令执行清除并重启的操作。

RemainAfterExit：如果设置这个选择为真，服务会被认为是在激活状态，即使所以的进程已经退出，默认的值为假，这个选项只有在Type=oneshot时需要被配置。

[Install]

Alias：为单元提供一个空间分离的附加名字。

RequiredBy：单元被允许运行需要的一系列依赖单元，RequiredBy列表从Require获得依赖信息。

WantBy：单元被允许运行需要的弱依赖性单元，Wantby从Want列表获得依赖信息。

Also：指出和单元一起安装或者被协助的单元。

DefaultInstance：实例单元的限制，这个选项指定如果单元被允许运行默认的实例。
</code></pre>

<h3 id="systemd-开机启动">systemd 开机启动</h3>

<p><code>systemctl enable clash.service</code>之后，就会在 <code>/etc/systemd/system/multi-user.target.wants/</code> 目录下新建一个 <code>/usr/lib/systemd/system/clash.service</code> 文件的链接。</p>

<blockquote>
<p>Created symlink /etc/systemd/system/multi-user.target.wants/clash.service → /etc/systemd/system/clash.service.</p>
</blockquote>
        ]]>
      </description>
    </item>
    
    <item>
      <title>ubuntu 下的 frp 内网穿透</title>
      <link>https://blog.lierhua.top/tech/ubuntu/5.-ubuntu-%E4%B8%8B-frp-%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/</link>
      <pubDate>Tue, 10 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/ubuntu/5.-ubuntu-%E4%B8%8B-frp-%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>ubuntu</code>, <code>frp</code>, <code>内网穿透</code></p>

<h1 id="ubuntu-下-frp-内网穿透">ubuntu 下 frp 内网穿透</h1>

<p>如果你在你自己的电脑开启了一个内网服务, 但是又想他可以在外网访问, 这个时候你就需要一个内网穿透工具了, 我一般用 frp 来处理.</p>

<p>frp 是一个 <code>C/S</code> 架构的应用, 需要在外网机器上安装 server 端，内网机器上安装 client 端。</p>

<h2 id="服务端安装">服务端安装</h2>

<p>在<a href="https://github.com/fatedier/frp/tags" rel="noreferrer" target="_blank">此地址</a>下载需要平台的二进制文件，比如 ubuntu 环境下， 下载如下图所示的文件即可：
<img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-14_18-05.png" alt="" /></p>

<p>将文件放到选定的目录下边，我一般选择 <code>/opt</code> 目录，并将执行的命令软链接到 <code>/usr/local/bin</code> 下。</p>

<p>具体的操作如下：</p>

<pre><code class="language-sh"># 假设我把 frp 放到了 /opt 下
cd /opt/frp
# 编辑好 frps.ini 之后
mkdir -p /etc/frp
cp frps.ini /etc/frp/
ln -s /opt/frp/frps /usr/local/bin/frps

cp system/frps.service /usr/lib/systemd/system/frps.service
# 然后编辑 frps.service 文件，将里面的执行的命令的路径写 /usr/local/bin/frps

systemctl daemon-reload  # 重载 systemctl 配置文件
systemctl start frps.service # 启动服务 
systemctl enable frps.service # 设置为开机启动
</code></pre>

<p>下面的 frps.ini 配置文件, 注意把注释要删掉</p>

<pre><code class="language-ini">[common]
bind_port = 7000
dashboard_port = 7500  # 通过这个端口可以访问你的 dashboard，记得防火墙放行这个端口
token = 12345678
dashboard_user = 你自己设置的 dashboard 用户名
dashboard_pwd = 你自己设置的 dashboard 密码
vhost_http_port = 10080  # 提供 HTTP 服务的端口
vhost_https_port = 10443
</code></pre>

<p>防火墙放行端口, 如果是云服务，还要记得在 <code>console</code> 里把端口开放了。</p>

<pre><code class="language-bash"># 添加监听端口
firewall-cmd --permanent --add-port=7000/tcp
# 添加管理后台端口
firewall-cmd --permanent --add-port=7500/tcp
firewall-cmd --reload
</code></pre>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-14_19-02.png" alt="" /></p>

<h2 id="客户端安装">客户端安装</h2>

<p>服务端安装成功后，客户端的安装也是一样的，不同的就是使用的是 frpc，配置文件使用的是  frpc.ini.</p>

<p>当然这个我说的是 linux 环境下，如果是 mac 或者 windows 那么情况就就要自己掌握了，这里我介绍的仅仅是在 linux 下的，具体的配置文件如下：</p>

<pre><code class="language-ini"># 服务端配置
[common]
server_addr = 服务器ip
# 请换成设置的服务器端口
server_port = 7000
token = 12345678 # 跟 server 配置的 token 保持一致即可

# 配置ssh服务
[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 自定义的远程服务器端口，例如 2222

# 配置http服务，可用于小程序开发、远程调试等
[web]
type = http
local_ip = 127.0.0.1
local_port = 8080 # 这个端口尽量不要和 vhost_http_port 一致
custom_domains = myhost.com # 服务端配置好的域名
# remote_port = 自定义的远程服务器端口，例如 10080, 和 vhost_http_port 一个配置即可, 也可以不配置
</code></pre>

<p>特别的讲一下 web 配置的处理，因为我们在 server 上已经配置了 <code>vhost_http_port</code> 是 10080，所以这个时候其实只需要访问 10080 端口即可拿到服务。同时需要在内网服务器内 8080 端口开启一个服务:</p>

<pre><code class="language-shell">python -m SimpleHTTPServer 8080
</code></pre>

<p>这个时候，我们直接访问 <code>myhost.com:10080</code> 即可访问到这个 python 服务，如果有不明白不清楚的，请查看<a href="https://gofrp.org/docs/examples/vhost-http/" rel="noreferrer" target="_blank">这里</a>.</p>

<p>配置文件的注意事项：</p>

<blockquote>
<ol>
<li><p>一个服务端可以同时给多个客户端使用</p></li>

<li><p>[ssh] 这样的名称必须全局唯一，即就算有多个客户端，也只能使用一次，其他的可以用 [ssh2] 、[ssh3] 等；</p></li>

<li><p>除了 type 为 http/https，端口只能被一个服务使用</p></li>

<li><p>如果用的 nat vps，remote_port 请改成映射后的端口</p></li>
</ol>
</blockquote>

<p>客户端配置好后，需要开放服务端的如下端口, 同时在云服务的 console 上也把这些端口开放：</p>

<pre><code class="language-bash">firewall-cmd --permanent --add-port=2222/tcp
firewall-cmd --permanent --add-port=10080/tcp
firewall-cmd --reload
</code></pre>

<p>当客户端和服务端服务都启动之后，查看 dashboard ，就可以看到服务的连接情况：</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-14_19-57.png" alt="" /></p>

<h2 id="ssh-登陆服务器">ssh 登陆服务器</h2>

<p>首先确保机器上安装了 ssh server, 并且服务启动了，<a href="https://blog.csdn.net/jackghq/article/details/54974141" rel="noreferrer" target="_blank">具体看这里</a></p>

<p>通过 SSH 访问内网机器，假设内网机器用户名为 fupeng, 而外网的服务器地址是 a.b.c.d</p>

<p><code>ssh -oPort=2222 fupeng@a.b.c.d</code></p>

<p>然后输入密码即可，如果没有密码，或者使用了密钥，配置好密钥的地址也可以直接访问。</p>

<p>例子：</p>

<p>按照我上面的配置，我要是向访问我自己的机器</p>

<ol>
<li>确保 openssh-server 安装并启动了；</li>
<li>这台机器上找一个用户，记住他的名字 fupeng 和密码 passwd；</li>
<li>确认安装 frps 的机器的地址是 address;</li>
<li>ssh -oPort=2222 fupeng@address  然后输入密码 passwd 即可登陆服务器了。</li>
</ol>

<p>这里的 2222 就是 frpc 里配置好的端口，同时在远程服务器可把这个端口开放了， fupeng 是内网机器的一个用户名， address 是远程机器的公网地址， passwd 是用户 fupeng 的开机登陆密码。</p>

<h2 id="访问-web-服务">访问 web 服务</h2>

<p>我把目前所有的跟 web 服务有关的配置捋一遍即可： <a href="https://gofrp.org/docs/examples/vhost-http/" rel="noreferrer" target="_blank">https://gofrp.org/docs/examples/vhost-http/</a></p>

<p>首先是在 frps.ini 里配置的 <code>vhost_http_port</code> 为 10080， 这个是设置监听 HTTP 请求端口为 10080</p>

<p>修改 frpc.ini 文件，假设 frps 所在的服务器的 IP 为 x.x.x.x，local<em>port 为本地机器上 Web 服务监听的端口, 绑定自定义域名为 custom</em>domains。</p>

<p>此时，访问 custom<em>domains:10080 即可访问到 local</em>port 端口的服务。</p>

<hr />

<p>参考：
- <a href="https://gofrp.org/docs/examples/ssh/" rel="noreferrer" target="_blank">https://gofrp.org/docs/examples/ssh/</a>
- <a href="https://gofrp.org/docs/examples/vhost-http/" rel="noreferrer" target="_blank">https://gofrp.org/docs/examples/vhost-http/</a>
- <a href="https://tlanyan.me/frp-tunnel-tutorial/" rel="noreferrer" target="_blank">how to use frp in ubuntu</a>
- <a href="https://blog.csdn.net/jackghq/article/details/54974141" rel="noreferrer" target="_blank">ubuntu openssh-server</a></p>
        ]]>
      </description>
    </item>
    
    <item>
      <title>ubuntu 下的 spacemacs 安装</title>
      <link>https://blog.lierhua.top/tech/ubuntu/4.-ubuntu-%E4%B8%8B%E5%AE%89%E8%A3%85-spacemacs/</link>
      <pubDate>Tue, 10 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/ubuntu/4.-ubuntu-%E4%B8%8B%E5%AE%89%E8%A3%85-spacemacs/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>ubuntu</code>, <code>spacemacs</code></p>

<h1 id="ubuntu-下安装-spacemacs">ubuntu 下安装 spacemacs</h1>

<p>spacemacs 一直是我非常喜欢的编辑器，我使用他进行 org 的编辑和查看。</p>

<p>就安装来说，spacemacs github 上已经说的很清楚了，但是在实际的操作过程中，会有一些需要注意的地方</p>

<p>首先就是需要安装 emacs， 版本需要大于 26，安装完之后按照 github 的步骤，在 linux 上安装</p>

<pre><code>Default installation
If you have an existing Emacs configuration, back it up first by running the following code in your terminal:

cd ~
mv .emacs.d .emacs.d.bak
mv .emacs .emacs.bak
Don't forget to backup and remove the ~/.emacs file. Otherwise Spacemacs WILL NOT be able to load. Because that file prevents Emacs from loading the proper initialization file.

Clone the repository with Git:

git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d
Or

git clone --depth 1 https://github.com/syl20bnr/spacemacs ~/.emacs.d
In case you have a limited internet connection or speed.

master is the stable branch and it is immutable, DO NOT make any modification to it or you will break the update mechanism. If you want to fork Spacemacs safely, use the develop branch where you'll handle updates manually.

Note for Windows users If you use windows, then you'll have to modify the git command by inserting the correct path to your .emacs.d folder. The dot before the folder means that it's hidden. You'll have to search for hidden files to find the folder. When you have found the folder, substitute the original path with the correct one. The proper code would look something like this:

git clone https://github.com/syl20bnr/spacemacs /path/to/your/.emacs.d
(Optional) Install the default fonts

It's recommended to install Source Code Pro by Adobe, as the default font. It ensures that, for example the symbols on the modeline (bottom bar) looks correct. It's also recommended to use a &quot;Fallback font&quot;. These depend on the system:

GNU/Linux: NanumGothic (package named fonts-nanum on Debian, for example)
macOS: Arial Unicode MS
Windows: MS Gothic or Lucida Sans Unicode
If the modeline doesn't look similar to the picture at the top of this page, then make sure you have the correct fallback font installed.

If you're running in a terminal then you'll also need to change the terminals font settings.

Launch Emacs. Spacemacs will automatically install the packages it requires. There is a well-known issue with some GPG keys having expired end of 2019. This can be fixed by upgrading to Emacs 26.3 or above or by manually adding the new keys using something like:

gpg --homedir ~/.emacs.d/elpa/gnupg --receive-keys 066DAFCB81E42C40
If you have a restrictive firewall it may help to manually specify the keyserver:

gpg --keyserver keyserver.ubuntu.com --homedir ~/.emacs.d/elpa/gnupg/ --receive-keys 066DAFCB81E42C40
Launch Emacs, and answer the questions in the Dotfile wizard installer. If you are new to Emacs and Spacemacs, then it's fine to just accept the default choices. It's easy to try the other choices later, without having to reinstall Spacemacs. They can be changed in the dotfile ~/.spacemacs.

After answering the questions, then Spacemacs starts downloading and installing the packages it requires. When the packages have been installed. Restart Emacs to complete the installation.

Notes: If you are behind a firewall or similar and you get an error regarding package downloads then you may try to disable the HTTPS protocol by starting Emacs with

emacs --insecure
but this should be a last resort because of the security implications.

You can set the dotspacemacs-elpa-https variable to nil in your dotfile ~/.spacemacs but this has the same security implications as the insecure flag. You may also want to clear out your .emacs.d/elpa directory before doing this, so that any corrupted packages you may have downloaded will be re-installed.

error: Package 'package-build-' is unavailable may occur due to heavy network taffic. You can fix it by setting the dotspacemacs-elpa-timeout variable to 70 in your dotfile.

Warning (bytecomp) and other compilation warnings are perfectly normal. If you're curious, you can find out why these occur here.

If the mode-line turns red then be sure to consult the FAQ.


</code></pre>

<p>特别注意的是，在启动 emacs 之前，需要修改以下 .emacs.d/init.el 文件里增加如下的配置</p>

<pre><code class="language-lisp">;; 使用子龙山人的源来下载 mepla的数据
  (setq configuration-layer--elpa-archives
        '((&quot;melpa-cn&quot; . &quot;http://elpa.zilongshanren.com/melpa/&quot;)
          (&quot;org-cn&quot;   . &quot;http://elpa.zilongshanren.com/org/&quot;)
          (&quot;gnu-cn&quot;   . &quot;http://elpa.zilongshanren.com/gnu/&quot;)))

</code></pre>

<p>这样可以保证从国内的源下载对应的安装 layer, 速度不至于太慢。</p>
        ]]>
      </description>
    </item>
    
    <item>
      <title>ubuntu 下的 SSH</title>
      <link>https://blog.lierhua.top/tech/ubuntu/6.-ubuntu-%E4%B8%8B%E7%9A%84-ssh-/</link>
      <pubDate>Tue, 10 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/ubuntu/6.-ubuntu-%E4%B8%8B%E7%9A%84-ssh-/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>ubuntu</code>, <code>ssh</code>, <code>sshd</code></p>

<h1 id="ubuntu-下的-ssh-服务">ubuntu 下的 SSH 服务</h1>

<h2 id="openssh-的安装">openssh 的安装</h2>

<p><code>SSH</code> 分客户端 <code>openssh-client</code> 和 <code>openssh-server</code></p>

<p>如果你只是想登陆别的机器的 <code>SSH</code> 只需要安装 <code>openssh-client</code>（<code>ubuntu</code> 有默认安装，如果没有则<code>sudo apt install openssh-client</code>），如果要使本机开放 <code>SSH</code> 服务就需要安装 <code>openssh-server</code> 。</p>

<p>查看当前的 ubuntu 是否安装了<code>ssh-server</code> 服务。默认只安装 <code>ssh-client</code> 服务。</p>

<pre><code class="language-bash">dpkg -l | grep ssh
</code></pre>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-14_20-28.png" alt="" /></p>

<p>这个图中既有 openssh-client 又有 openssh-server 说明都安装了。</p>

<p>安装 ssh-server 服务</p>

<pre><code>sudo apt install openssh-server
</code></pre>

<p>再次查看安装的服务：</p>

<pre><code>dpkg -l | grep ssh
</code></pre>

<p>然后确认ssh-server是否启动了：</p>

<pre><code>ps -e | grep ssh
</code></pre>

<p>如果看到 <code>sshd</code> 那说明 <code>ssh-server</code> 已经启动了。</p>

<h2 id="配置相关">配置相关</h2>

<p>ssh-server 配置文件位于 <code>/etc/ssh/sshd_config</code>，在这里可以定义 SSH 的服务端口，默认端口是 22，你可以自己定义成其他端口号，如 2222.</p>

<p>如果想 root 登陆，则需要把配置文件中的 <code>PermitRootLogin without-password</code> 加一个 <code>#</code> 号， 把它注释掉，再增加一句 <code>PermitRootLogin yes</code> ）.</p>

<p>然后重启 SSH 服务， 默认使用 <code>systemctl</code> 即可。</p>

<p><code>systemctl restart sshd</code></p>

<h1 id="登陆">登陆</h1>

<p>登陆 SSH（Linux）：</p>

<pre><code class="language-bash">ssh username@192.168.1.103
</code></pre>

<p>其中，username 为 192.168.1.103 机器上的用户，需要输入密码登陆，密码就是这个用户开机时输入的密码， username 就是你机器的用户的名字，192.168.1.103 指的是他的内网地址。断开连接则直接输入 <code>exit</code> 即可。</p>
        ]]>
      </description>
    </item>
    
    <item>
      <title>ubuntu 下的键位映射</title>
      <link>https://blog.lierhua.top/tech/ubuntu/7.-ubuntu-%E4%B8%8B%E6%98%A0%E5%B0%84-caps-%E9%94%AE/</link>
      <pubDate>Tue, 10 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/ubuntu/7.-ubuntu-%E4%B8%8B%E6%98%A0%E5%B0%84-caps-%E9%94%AE/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>ubuntu</code>, <code>键位映射</code></p>

<h1 id="ubuntu-下映射-caps-键">ubuntu 下映射 caps 键</h1>

<p>习惯了 Mac 上的 karabiner 键位修改神器之后, 一旦切换到其他平台就会觉得非常难受, 特别是 caps 键位的映射, 所以产生了如下的方案.</p>

<p>需求： 映射 <code>caps</code> 键， 单击时映射为 <code>esc</code> 键， 和其他键一起用时映射为 <code>ctrl</code> 键。</p>

<p>工具： <a href="https://gitlab.com/interception/linux/plugins/caps2esc" rel="noreferrer" target="_blank">caps2esc</a></p>

<h2 id="安装必须的依赖">安装必须的依赖</h2>

<ol>
<li>需要安装 <code>libevdev-dev</code></li>
</ol>

<p><code>sudo apt install -y libevdev-dev</code></p>

<ol>
<li>需要安装 <code>cmake</code></li>
</ol>

<p><code>sudo apt install cmake</code></p>

<ol>
<li>需要安装 <code>libyaml-cpp-dev</code></li>
</ol>

<p><code>sudo apt install libyaml-cpp-dev</code></p>

<ol>
<li>需要安装 <code>libudev-dev</code></li>
</ol>

<p><code>sudo apt install libudev-dev</code></p>

<ol>
<li><p>安装 <code>caps2esc</code> 的依赖： <code>interception/linux/tools</code> 这个工具， <a href="https://gitlab.com/interception/linux/tools" rel="noreferrer" target="_blank">地址</a></p>

<pre><code class="language-bash">$ git clone git@gitlab.com:interception/linux/tools.git
# 如果不成功的话，需要使用 https 的地址 https://gitlab.com/interception/linux/tools.git
$ cd tools
$ mkdir build
$ cd build
$ cmake ..
$ make
</code></pre></li>
</ol>

<p>将 build 文件夹里生成的 <code>udevmon</code>, <code>intercept</code>, <code>uinput</code> 放到 <code>/opt/tools/udevmon/</code>, <code>/opt/tools/intercept/</code>, <code>/opt/tools/uinput/</code> 这几个目录里， 然后软链接到 <code>/usr/local/bin</code> 下</p>

<h2 id="安装-caps2esc-这个-plugin">安装 caps2esc 这个 plugin</h2>

<pre><code class="language-bash">$ git clone https://gitlab.com/interception/linux/plugins/caps2esc.git
$ cd caps2esc
$ mkdir build
$ cd build
$ cmake ..
$ make
</code></pre>

<p>将 build 文件夹里生成的 caps2esc 放到 <code>/opt/tools/caps2esc/</code> 里， 然后软链接到 <code>/usr/local/bin</code> 下</p>

<p>新增配置文件 <code>/etc/udev/udevmon.yaml</code></p>

<pre><code class="language-yaml">- JOB: &quot;intercept -g $DEVNODE | caps2esc | uinput -d $DEVNODE&quot;
  DEVICE:
    EVENTS:
      EV_KEY: [KEY_CAPSLOCK, KEY_ESC]
</code></pre>

<p>新增 systemctl 配置 <code>/etc/systemd/system/udevmon.service</code></p>

<pre><code class="language-ini">[Unit]
Description=udevmon
Wants=systemd-udev-settle.service
After=systemd-udev-settle.service

[Service]
ExecStart=/usr/bin/nice -n -20 /usr/local/bin/udevmon -c /etc/udev/udevmon.yaml

[Install]
WantedBy=multi-user.target
</code></pre>

<p>执行 <code>sudo systemctl enable --now udevmon</code> 开机启动。</p>

<p>注意观察 <code>sudo systemctl status udevmon</code> 如果显示的是如下的：</p>

<pre><code>● udevmon.service - udevmon
     Loaded: loaded (/etc/systemd/system/udevmon.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2020-12-17 15:33:15 CST; 18s ago
   Main PID: 8451 (udevmon)
      Tasks: 21 (limit: 38270)
     Memory: 7.1M
     CGroup: /system.slice/udevmon.service
             ├─8451 /usr/local/bin/udevmon -c /etc/udev/udevmon.yaml
             ├─8452 sh -c intercept -g $DEVNODE | caps2esc | uinput -d $DEVNODE
             ├─8453 sh -c intercept -g $DEVNODE | caps2esc | uinput -d $DEVNODE
             ├─8454 intercept -g /dev/input/event4
             ├─8455 caps2esc
             ├─8456 uinput -d /dev/input/event4
             ├─8457 intercept -g /dev/input/event5
             ├─8458 caps2esc
             ├─8459 uinput -d /dev/input/event5
             ├─8460 sh -c intercept -g $DEVNODE | caps2esc | uinput -d $DEVNODE
             ├─8461 intercept -g /dev/input/event8
             ├─8462 caps2esc
             ├─8463 uinput -d /dev/input/event8
             ├─8467 sh -c intercept -g $DEVNODE | caps2esc | uinput -d $DEVNODE
             ├─8468 intercept -g /dev/input/event9
             ├─8469 caps2esc
             ├─8470 uinput -d /dev/input/event9
             ├─8477 sh -c intercept -g $DEVNODE | caps2esc | uinput -d $DEVNODE
             ├─8478 intercept -g /dev/input/event10
             ├─8479 caps2esc
             └─8480 uinput -d /dev/input/event10

12月 17 15:33:15 fupeng systemd[1]: Started udevmon.
</code></pre>

<p>表示已经成功了 ～</p>

<p>之前碰到的未起作用的错误如下显示， 具体原因是没有将编译好的 intercept 和 uinput 放到 PATH 下，后来都放到了 /usr/loca/bin 下，就没有问题了：</p>

<pre><code>● udevmon.service - udevmon
     Loaded: loaded (/etc/systemd/system/udevmon.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2020-12-17 15:25:00 CST; 16s ago
   Main PID: 8228 (udevmon)
      Tasks: 1 (limit: 38270)
     Memory: 2.1M
     CGroup: /system.slice/udevmon.service
             └─8228 /usr/local/bin/udevmon -c /etc/udev/udevmon.yaml

12月 17 15:25:00 fupeng nice[8231]: sh: 1: intercept: not found
12月 17 15:25:00 fupeng nice[8233]: sh: 1: uinput: not found
12月 17 15:25:00 fupeng nice[8234]: sh: 1: intercept: not found
12月 17 15:25:00 fupeng nice[8236]: sh: 1: uinput: not found
12月 17 15:25:00 fupeng nice[8238]: sh: 1: intercept: not found
12月 17 15:25:00 fupeng nice[8240]: sh: 1: uinput: not found
12月 17 15:25:00 fupeng nice[8242]: sh: 1: intercept: not found
12月 17 15:25:00 fupeng nice[8244]: sh: 1: uinput: not found
12月 17 15:25:00 fupeng nice[8246]: sh: 1: intercept: not found
12月 17 15:25:00 fupeng nice[8248]: sh: 1: uinput: not found

</code></pre>

<hr />

<p>参考文件：</p>

<ul>
<li><a href="https://gitlab.com/interception/linux/tools" rel="noreferrer" target="_blank">依赖工具</a></li>
<li><a href="https://gitlab.com/interception/linux/plugins/caps2esc" rel="noreferrer" target="_blank">caps2esc 工具</a></li>
<li><a href="https://askubuntu.com/questions/979359/how-do-i-install-caps2esc" rel="noreferrer" target="_blank">具体的指导教程</a></li>
</ul>
        ]]>
      </description>
    </item>
    
    <item>
      <title>ubuntu 换阿里源</title>
      <link>https://blog.lierhua.top/tech/ubuntu/3.-ubuntu-%E6%8D%A2%E9%98%BF%E9%87%8C%E6%BA%90/</link>
      <pubDate>Tue, 10 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/ubuntu/3.-ubuntu-%E6%8D%A2%E9%98%BF%E9%87%8C%E6%BA%90/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>ubuntu</code>, <code>ali</code>, <code>阿里</code>, <code>apt</code>, <code>apt-get</code></p>

<h1 id="ubuntu-更换阿里源">ubuntu 更换阿里源</h1>

<p>在国内，linux 装机后，需要安装大量依赖时，会发现 <code>apt</code> 非常慢，因此我们要把下载源切换为国内源即可。</p>

<h2 id="复制源文件备份-以防万一">复制源文件备份，以防万一</h2>

<p>我们要修改的文件是 <code>sources.list</code>，它在目录 <code>/etc/apt/</code> 下， <code>sources.list</code> 是包管理工具 apt 所用的记录软件包仓库位置的配置文件，同样类型的还有位于同目录下 <code>sources.list.d</code> 文件下的各种 .list 后缀的各文件。</p>

<pre><code class="language-bash">sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
</code></pre>

<h2 id="查看新版本信息">查看新版本信息</h2>

<p>使用如下命令获取系统代号：</p>

<p>lsb_release -c</p>

<p>得到本系统的系统代号，如下图所示：</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-12_00-48.png" alt="" /></p>

<p>这里 focal 就是系统代号了，我安装的是 20.04 因此，系统代号就是这个，对于其他版本的，也分别有自己的代号。</p>

<ul>
<li>Ubuntu 12.04 (LTS)代号为 precise</li>
<li>Ubuntu 14.04 (LTS)代号为 trusty</li>
<li>Ubuntu 15.04 代号为 vivid</li>
<li>Ubuntu 15.10 代号为 wily</li>
<li>Ubuntu 16.04 (LTS)代号为 xenial</li>
<li>Ubuntu 18.04 (LTS)代号为 bionic</li>
<li>Ubuntu 20.04 (LTS)代号为 focal</li>
</ul>

<h2 id="新增配置文件">新增配置文件</h2>

<p>第一步我们已经把原来的配置文件给备份了，因此新增一个 <code>/etc/apt/sources.list</code> 文件，里面的具体内容如下, (如果你的不是 20.04，把 focal 换乘对应版本的代号即可)：</p>

<pre><code class="language-bash">deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

 

deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

 

deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse



deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse



deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
</code></pre>

<h2 id="更新软件列表和软件包">更新软件列表和软件包</h2>

<p>更新软件列表运行如下命令： <code>sudo apt update</code></p>

<p>更新软件包运行如下命令： <code>sudo apt upgrade</code></p>
        ]]>
      </description>
    </item>
    
    <item>
      <title>virtualbox 安装好之后的一些设置</title>
      <link>https://blog.lierhua.top/tech/ubuntu/13.-virtualbox-%E5%AE%89%E8%A3%85%E5%A5%BD%E5%90%8E%E4%B8%80%E4%BA%9B%E8%AE%BE%E7%BD%AE%E7%9A%84%E9%97%AE%E9%A2%98/</link>
      <pubDate>Tue, 10 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/ubuntu/13.-virtualbox-%E5%AE%89%E8%A3%85%E5%A5%BD%E5%90%8E%E4%B8%80%E4%BA%9B%E8%AE%BE%E7%BD%AE%E7%9A%84%E9%97%AE%E9%A2%98/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>virtualbox</code>, <code>设置</code>, <code>网络环境</code></p>

<h1 id="virtualbox-安装好后一些设置问题">virtualbox 安装好后一些设置问题</h1>

<h2 id="引用片段参考">引用片段参考</h2>

<blockquote>
<p>使用 virtualBox 创建三台虚拟机
virtualBox 安装比较简单，不再介绍，GUI 工具用起来也很方便，这部分只介绍我认为需要提示的部分。</p>

<p>内存推荐 2048M, CPU 推荐 2个
默认只有一个 NAT 适配器，添加一个 Host-Only Adapter。NAT 适配器是虚拟机用来访问互联网的，Host-Only 适配器是用来虚拟机之间通信的。
以 Normal Start 方式启动虚拟机安装完系统以后，因为是 server 版镜像，所以没有图形界面，直接使用用户名密码登录即可。
修改配置，enp0s8 使用静态 IP。配置请参考 <a href="https://gist.github.com/c-rainstorm/1bbd44b388acd35ca6eaf07d1fbd9bc7" rel="noreferrer" target="_blank">SSH between Mac OS X host and Virtual Box guest</a>。注意配置时将其中的网络接口名改成你自己的 Host-Only Adapter 对应的接口。
一台虚拟机创建完成以后可以使用 clone 方法复制出两台节点出来，注意 clone 时为新机器的网卡重新初始化 MAC 地址。
三台虚拟机的静态 IP 都配置好以后就可以使用 ssh 在本地主机的终端上操作三台虚机了。虚机使用 Headless Start 模式启动</p>
</blockquote>

<h2 id="执行引用片段时遇到的网络问题">执行引用片段时遇到的网络问题</h2>

<p>如何设置 <code>VirtualBox Host-Only Network</code>
左上角 全局工具-&gt;主机网络管理器-&gt;创建， 首先我们创建一个新的网卡</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-21%2020-39-25%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png" alt="" /></p>

<p>名字是 vboxnet0，我门执行一下 ifconfig 看看当前配置之后的情况：</p>

<pre><code class="language-bash">fupeng@fupeng:~/.ssh$ ifconfig
docker0: flags=4099&lt;UP,BROADCAST,MULTICAST&gt;  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:b7:9a:ed:3c  txqueuelen 0  (以太网)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp4s0: flags=4099&lt;UP,BROADCAST,MULTICAST&gt;  mtu 1500
        ether 04:d4:c4:03:a5:cf  txqueuelen 1000  (以太网)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73&lt;UP,LOOPBACK,RUNNING&gt;  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10&lt;host&gt;
        loop  txqueuelen 1000  (本地环回)
        RX packets 6655054  bytes 12615158614 (12.6 GB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6655054  bytes 12615158614 (12.6 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vboxnet0: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt;  mtu 1500
        inet 192.168.56.1  netmask 255.255.255.0  broadcast 192.168.56.255
        inet6 fe80::800:27ff:fe00:0  prefixlen 64  scopeid 0x20&lt;link&gt;
        ether 0a:00:27:00:00:00  txqueuelen 1000  (以太网)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 411  bytes 62263 (62.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlx081f711ba57d: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt;  mtu 1500
        inet 192.168.0.110  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::4b08:499c:70e7:ca2d  prefixlen 64  scopeid 0x20&lt;link&gt;
        ether 08:1f:71:1b:a5:7d  txqueuelen 1000  (以太网)
        RX packets 5456280  bytes 16796059488 (16.7 GB)
        RX errors 0  dropped 147  overruns 0  frame 0
        TX packets 3492157  bytes 11421493913 (11.4 GB)
        TX errors 0  dropped 2 overruns 0  carrier 0  collisions 0
</code></pre>

<p>我们看到 vboxnet0 已经在这里了。</p>

<p>此时，我们新建一些虚拟机给 k8s 用，新建的时候，注意一些配置问题
- 内存 2048，核心 2
- 配置 host-only adapter 地址
- SSH 配置好后，选择 headless start 模式启动</p>

<p>我们登陆一台机器之后，首先安装上 openssh-server, 然后开始设置固定 IP， <a href="https://gist.github.com/c-rainstorm/1bbd44b388acd35ca6eaf07d1fbd9bc7" rel="noreferrer" target="_blank">操作</a>：</p>

<p>在 <code>/etc/netplan</code> 目录下新建 <code>02-netcfg.yaml</code> 文件：</p>

<pre><code class="language-yaml">network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s8:  # `ip address` will show three adapter: lo, enp0s3, enp0s8. enp0s3 is the NAT adapter with ip 10.0.2.15/24(maybe different on your vm), so enp0s8 is the host-only adapter
      addresses:
              - 192.168.56.200/24       #you can change this static ip by yourself, 注意这里的地址要和你在 virtualbox 里配置的 192.168.56.1 子网掩码对应的部分要一致， 比如这里就应该是 192.168.56.*
      dhcp4: no
</code></pre>

<p>然后执行如下命令让他们生效，然后就可以在宿主机上直接 ssh 连接到固定好 IP 的这几台机器了。</p>

<pre><code class="language-bash">$ sudo netplan generate
$ sudo netplan apply
</code></pre>
        ]]>
      </description>
    </item>
    
    <item>
      <title>virtualbox 里安装 Ubuntu 系统</title>
      <link>https://blog.lierhua.top/tech/ubuntu/12.-virtualbox-%E5%AE%89%E8%A3%85-ubuntu/</link>
      <pubDate>Tue, 10 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/ubuntu/12.-virtualbox-%E5%AE%89%E8%A3%85-ubuntu/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>ubuntu</code>, <code>virtualbox</code></p>

<h1 id="virtualbox-安装-ubuntu">virtualbox 安装 ubuntu</h1>

<h2 id="特别注意">特别注意</h2>

<p>安装的时候注意换一下阿里的源就行
<a href="http://mirrors.aliyun.com/ubuntu/" rel="noreferrer" target="_blank">http://mirrors.aliyun.com/ubuntu/</a></p>

<h2 id="新建虚拟机">新建虚拟机</h2>

<p>主界面 &ndash;&gt; 控制 &ndash;&gt; 新建</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-21%2018-33-13%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png" alt="" /></p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-21%2018-34-23%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png" alt="" /></p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-21%2018-34-56%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png" alt="" /></p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-21%2018-35-23%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png" alt="" /></p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-21%2018-35-40%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png" alt="" /></p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-21%2018-35-54%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png" alt="" /></p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-21%2018-36-20%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png" alt="" /></p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-21%2018-36-43%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png" alt="" /></p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-21%2018-37-32%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png" alt="" /></p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-21%2018-38-03%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png" alt="" /></p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-21%2018-38-35%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png" alt="" /></p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-21%2018-39-30%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png" alt="" /></p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-21%2018-40-33%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png" alt="" /></p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-21%2018-41-12%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png" alt="" /></p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-21%2018-42-02%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png" alt="" /></p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2020-12-21%2018-42-31%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE.png" alt="" /></p>

<hr />

<p>参考文章：</p>

<ul>
<li><a href="https://docs.oracle.com/cd/E26217_01/E35195/html/qs-create-vm.html" rel="noreferrer" target="_blank">https://docs.oracle.com/cd/E26217_01/E35195/html/qs-create-vm.html</a></li>
</ul>
        ]]>
      </description>
    </item>
    
    <item>
      <title>win10 ubuntu 双系统指南</title>
      <link>https://blog.lierhua.top/tech/ubuntu/0.-windows-ubuntu-%E5%8F%8C%E7%B3%BB%E7%BB%9F%E5%AE%89%E8%A3%85/</link>
      <pubDate>Tue, 10 Mar 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/ubuntu/0.-windows-ubuntu-%E5%8F%8C%E7%B3%BB%E7%BB%9F%E5%AE%89%E8%A3%85/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>win10</code>, <code>ubuntu</code>, <code>双系统</code></p>

<h1 id="windows-ubuntu-双系统安装">windows ubuntu 双系统安装</h1>

<p>最近购入一台性能不错的非笔记本设备, 按照以往的情况, 我都是直接装一个 Linux 发行版就开始使用了, 但是由于这个设备的显卡是 3090, 不想它装在一个 Linux 上只能做机器学习用,因此决定装一个 window 和 Linux 的双系统, 然后 win 上就可以装 Adobe 全家桶进行视频的渲染等吃显卡的操作了.</p>

<p>具体的安装参考了两篇文章:</p>

<ul>
<li><a href="https://www.cnblogs.com/masbay/p/11627727.html" rel="noreferrer" target="_blank">Windows10安装ubuntu18.04双系统教程</a></li>
<li><a href="https://www.cnblogs.com/masbay/p/10718514.html" rel="noreferrer" target="_blank">ubuntu双系统启动时卡死解决办法</a></li>
</ul>

<hr />

<h2 id="无线驱动">无线驱动</h2>

<p>安装好系统之后，发现只有有线网可以用，我用的是 TP-Link TL-WDN5200 的无线网卡， 在 windows 下这个是无驱动就可以使用的，但是 ubuntu 下不行，需要自己编译。</p>

<p>使用的无线网卡驱动地址： <a href="https://github.com/brektrou/rtl8821CU.git" rel="noreferrer" target="_blank">https://github.com/brektrou/rtl8821CU.git</a></p>

<p>执行以下命令前，建议先换阿里源，保证 apt 的更新和下载速度， 不然真的是龟速。</p>

<p>如果没有网线， 或者暂时找不到网线， 只有无线网卡，这个时候，可以电脑直接连接手机 USB， 然后手机设置里有一个连接与共享，里面有一个 USB  网络连接，可以把这个打开，直接使用手机的流量下载安装驱动，然后就可以使用电脑的无线网了。</p>

<pre><code class="language-bash">sudo apt update
sudo apt install build-essential git dkms
git clone https://github.com/brektrou/rtl8821CU.git
cd rtl8821CU
chmod +x dkms-install.sh
sudo ./dkms-install.sh
sudo modprobe 8821cu
reboot
</code></pre>

<p>如果还是不能连接，使用命令 <code>lsusb</code></p>

<pre><code>Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 005: ID 046d:c341 Logitech, Inc. Logitech Mechanical keyboard
Bus 001 Device 004: ID 046d:c084 Logitech, Inc. G203 Gaming Mouse
Bus 001 Device 003: ID 0bda:c811 Realtek Semiconductor Corp. 802.11ac NIC
Bus 001 Device 002: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
</code></pre>

<p>如果有 <code>0bda:c811</code> 说明网线网卡在，重启下服务看看。</p>

<p>如果再有疑问，看看这个有没有帮助：<a href="https://zhuanlan.zhihu.com/p/214136483?utm_source=qq" rel="noreferrer" target="_blank">https://zhuanlan.zhihu.com/p/214136483?utm_source=qq</a></p>

<hr />

<h2 id="ubuntu-多桌面">ubuntu 多桌面</h2>

<p>按 win 键会呼出多桌面来。</p>

<h2 id="ubuntu-查看外网-ip">ubuntu 查看外网 ip</h2>

<ol>
<li><p>安装curl工具:  <code>sudo apt-get install curl</code></p></li>

<li><p>查看外网IP地址: <code>curl ifconfig.me</code></p></li>
</ol>

<h2 id="安装-docker">安装 docker</h2>

<p>参考地址：<a href="https://yeasy.gitbook.io/docker_practice/install/ubuntu" rel="noreferrer" target="_blank">https://yeasy.gitbook.io/docker_practice/install/ubuntu</a>
官网地址：<a href="https://docs.docker.com/engine/install/ubuntu/#installation-methods" rel="noreferrer" target="_blank">https://docs.docker.com/engine/install/ubuntu/#installation-methods</a></p>

<p>如果遇到 GPG 问题，请看 9 号文档，关于如何处理 GPG 问题的方案。</p>

<pre><code class="language-bash"># $ curl -fsSL test.docker.com -o get-docker.sh
$ curl -fsSL get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh --mirror Aliyun
# $ sudo sh get-docker.sh --mirror AzureChinaCloud
</code></pre>
        ]]>
      </description>
    </item>
    
    <item>
      <title>hugo 博客增加评论系统</title>
      <link>https://blog.lierhua.top/tech/hugo-%E5%8D%9A%E5%AE%A2%E5%A2%9E%E5%8A%A0%E8%AF%84%E8%AE%BA%E7%B3%BB%E7%BB%9F/</link>
      <pubDate>Wed, 15 Jan 2020 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/hugo-%E5%8D%9A%E5%AE%A2%E5%A2%9E%E5%8A%A0%E8%AF%84%E8%AE%BA%E7%B3%BB%E7%BB%9F/</guid>
      <description>
        <![CDATA[
        

<h2 id="外部系统">外部系统</h2>

<h3 id="github-操作">github 操作</h3>

<p>创建一个 public 的 github 账号</p>

<h3 id="utterances">utterances</h3>

<p>使用 <a href="https://github.com/apps/utterances" rel="noreferrer" target="_blank">utterances app</a> 对这个仓库进行授权</p>

<h2 id="博客系统">博客系统</h2>

<h3 id="增加配置">增加配置</h3>

<p>在 theme 下的 layouts/partials 下新增一个文件</p>

<pre><code class="language-html"># fileName: disqus.html
{{ if and (not (eq .Site.DisqusShortname &quot;&quot;)) (and (not .Params.utterance.enable) (or (eq .Kind &quot;404&quot;) (and (not .IsHome) .Content))) }}
&lt;script src=&quot;https://utteranc.es/client.js&quot;
        repo=&quot;immotal/blog-comment&quot;
        issue-term=&quot;pathname&quot;
        theme=&quot;github-light&quot;
        crossorigin=&quot;anonymous&quot;
        async&gt;
&lt;/script&gt;
{{ end }}
</code></pre>

<p>找到 foot 相关的 html 文件（一般是 foot custom 中), 确认添加了如下标记(想要全局生效的话)</p>

<pre><code class="language-html">{{ if .Section }}
&lt;nav class=&quot;post-nav&quot;&gt;
  &lt;span class=&quot;nav-prev&quot;&gt;{{ with .PrevInSection }}&amp;larr; &lt;a href=&quot;{{ .RelPermalink }}&quot;&gt;{{ .Title }}&lt;/a&gt;{{ end }}&lt;/span&gt;
  &lt;span class=&quot;nav-next&quot;&gt;{{ with .NextInSection }}&lt;a href=&quot;{{ .RelPermalink }}&quot;&gt;{{ .Title }}&lt;/a&gt; &amp;rarr;{{ end }}&lt;/span&gt;
&lt;/nav&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
document.addEventListener('keyup', function(e) {
  if (e.target.nodeName.toUpperCase() != 'BODY') return;
  var url = false;
  if (e.which == 37) {  // Left arrow
    {{ if .PrevInSection }}
    url = '{{ .PrevInSection.RelPermalink }}';
    {{ end }}
  } else if (e.which == 39) {  // Right arrow
    {{ if .NextInSection }}
    url = '{{ .NextInSection.RelPermalink }}';
    {{ end }}
  }
  if (url) window.location = url;
});
&lt;/script&gt;
{{ end }}

{{ partial &quot;google_adsense_footer.html&quot; . }}

{{ partial &quot;disqus.html&quot; . }}
{{ partial &quot;footer_prismjs.html&quot; . }}

&lt;script async src=&quot;/js/fix-toc.js&quot;&gt;&lt;/script&gt;
&lt;script async src=&quot;/js/center-img.js&quot;&gt;&lt;/script&gt;
&lt;script async src=&quot;/js/right-quote.js&quot;&gt;&lt;/script&gt;
&lt;script async src=&quot;/js/fix-footnote.js&quot;&gt;&lt;/script&gt;
&lt;script async src=&quot;/js/external-link.js&quot;&gt;&lt;/script&gt;
&lt;script async src=&quot;/js/alt-title.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;/js/no-highlight.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;/js/math-code.js&quot;&gt;&lt;/script&gt;

{{ partial &quot;footer_mathjax.html&quot; . }}
{{ partial &quot;footer_pseudocode.html&quot; . }}

{{ if $.Page.Scratch.Get &quot;mdc&quot; }}
&lt;script src=&quot;{{ $.Site.Params.materialComponentsWebCDN }}/material-components-web@{{ $.Site.Params.materialComponentsWebVersion }}/dist/material-components-web.min.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;window.mdc.autoInit()&lt;/script&gt;
{{ end }}

{{ if $.Page.Scratch.Get &quot;douban-card&quot; }}
&lt;script src=&quot;/js/douban-card.js&quot;&gt;&lt;/script&gt;
{{ end }}

&lt;script async src=&quot;/js/load-typekit.js&quot;&gt;&lt;/script&gt;

&lt;script src=&quot;{{ $.Site.Params.lazysizesCDN }}/lazysizes/{{ $.Site.Params.lazysizesVersion }}/lazysizes.min.js&quot;&gt;&lt;/script&gt;

&lt;script src=&quot;{{ $.Site.Params.vanillaBackToTopCDN }}/vanilla-back-to-top@{{ $.Site.Params.vanillaBackToTopVersion }}/dist/vanilla-back-to-top.min.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
addBackToTop({
  diameter: 48
})
&lt;/script&gt;

{{ if $.Page.Scratch.Get &quot;figure-slider&quot; }}
&lt;script src=&quot;/js/figure-slider.js&quot;&gt;&lt;/script&gt;
{{ end }}

</code></pre>

<hr />

<p>参考文档：
- <a href="https://www.shaohanyun.top/posts/env/hugo_comments/" rel="noreferrer" target="_blank">评论系统</a></p>

        ]]>
      </description>
    </item>
    
    <item>
      <title>使用Hugo 维护自己的博客</title>
      <link>https://blog.lierhua.top/tech/%E4%BD%BF%E7%94%A8-hugo-%E7%BB%B4%E6%8A%A4%E8%87%AA%E5%B7%B1%E7%9A%84%E5%8D%9A%E5%AE%A2/</link>
      <pubDate>Thu, 16 May 2019 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/%E4%BD%BF%E7%94%A8-hugo-%E7%BB%B4%E6%8A%A4%E8%87%AA%E5%B7%B1%E7%9A%84%E5%8D%9A%E5%AE%A2/</guid>
      <description>
        <![CDATA[
        

<h3 id="安装">安装</h3>

<p>在可以访问外网的情况下</p>

<pre><code class="language-shell">mkdir $HOME/src
cd $HOME/src
git clone https://github.com/gohugoio/hugo.git
cd hugo
go install --tags extended
</code></pre>

<p>或者直接到 <a href="https://github.com/spf13/hugo/releases" rel="noreferrer" target="_blank">Hugo Releases</a> 下载对应的操作系统版本的Hugo二进制文件（hugo或者hugo.exe），然后放到 path 下去，或者找一个地方保存，使用绝对路径执行。</p>

<p>在不可访问外网的情况下，推荐如下地址，下载对应的 bin 包，然后放到 PATH 里调用即可（我自己源码打的包）</p>

<pre><code>MAC版 链接:https://pan.baidu.com/s/1J5S9JOjz3Wnlrm-t7uVpwQ  密码:o4bx
Linux 版 链接:https://pan.baidu.com/s/1fyVjrrBHFssZbc4rteJecA  密码:nwv8
</code></pre>

<p>注意一定要使用 extend 版本 比如：hugo<em>extended</em>0.81.0_macOS-64bit.tar.gz</p>

<h3 id="创建自己的-blog">创建自己的 blog</h3>

<pre><code>hugo new site quickstart(要创建的 blog 的文件夹名字)

cd quickstart;
git init; # 实现 git 版本控制
git submodule add https://github.com/alex-shpak/hugo-book themes/book 
# 上面一句是获得 theme ，可以去 hugo-theme 挑选对应的主题,上面这个主题是 book 主题
</code></pre>

<p>如果不喜欢他提供这个字体和样式，可以下载 assets 包放到 quickstart/ 目录下</p>

<pre><code>链接:https://pan.baidu.com/s/1LumeSQAri8gysHH-_Bykxw  密码:x72c
</code></pre>

<h3 id="修改配置">修改配置</h3>

<p>完成上面的部分后，需要修改对应的配置文件，在根目录下的 config</p>

<pre><code class="language-toml">+++
# 主机名 例如: http://spf13.com/
baseURL =                     &quot;你自己的主机名或者域名&quot;
# 语言编码(中文: zh-CN)
languageCode =                &quot;zh-CN&quot;
# 默认的内容语言
defaultContentLanguage =      &quot;zh-CN&quot;
# 设置使用的主题名称 (默认储存在 /themes/THEMENAME/)
theme =  &quot;book&quot;   # 特别注意修改这里为自己安装的 theme 主题的名字  

# 自动检测是否包含中文/日文/韩文，该参数会影响摘要和字数统计功能，建议设置为true
hasCJKLanguage =              false
# 若为 false，`Getting Started` 这样的英文标签将会被转换为 `getting-started`
preserveTaxonomyNames =       true
    
# 分页
paginate =                    10
paginatePath =                &quot;page&quot;
# 启用 Emoji; see emoji-cheat-sheet.com
enableEmoji =                 false
# 创建robots.txt，建议设置为true
enableRobotsTXT =             false
# 定义文章访问路径，详细见下文&quot;URL管理&quot; See &quot;content-management/urls/&quot;
permalinks =                  &quot;&quot;
+++
</code></pre>

<h3 id="配置解释">配置解释</h3>

<ul>
<li><strong>archetypes</strong>: 储存<code>.md</code>的模板文件，类似于<code>hexo</code>的<code>scaffolds</code>，该文件夹的优先级高于主题下的<code>/archetypes</code>文件夹</li>
<li><strong>config.toml</strong>: 配置文件</li>
<li><strong>content</strong>: 储存网站的所有内容，类似于<code>hexo</code>的<code>source</code></li>
<li><strong>data</strong>: 储存数据文件供模板调用，类似于<code>hexo</code>的<code>source/_data</code></li>
<li><strong>layouts</strong>: 储存<code>.html</code>模板，该文件夹的优先级高于主题下的<code>/layouts</code>文件夹</li>
<li><strong>static</strong>: 储存图片,css,js等静态文件，该目录下的文件会直接拷贝到<code>/public</code>，该文件夹的优先级高于主题下的<code>/static</code>文件夹</li>
<li><strong>themes</strong>: 储存主题</li>
<li><strong>public</strong>: 执行<code>hugo</code>命令后，储存生成的静态文件</li>
</ul>

<h3 id="demo-测试">demo 测试</h3>

<p>每个主题都配置了好多测试的文章，book 来说，测试的文章在 <code>/themes/book/exampleSite</code> 目录下的 <code>content</code></p>

<p>里，我们可以直接复制这个 content 目录到 blog 的根目录下即可。</p>

<h3 id="启动">启动</h3>

<p>完成以上步骤之后，就可以通过以下的命令启动一次服务，然后查看 1313 端口就会看到对应的 blog 文章了</p>

<pre><code>hugo server -D
</code></pre>

<p>静态文件发布</p>

<p>使用以上的命令测试无误后，就可以使用 <code>hugo</code> 命令在根目录下执行，然后就得到一个 public 目录，发布到 S3 等即可。</p>

<hr />

<h3 id="具体功能">具体功能</h3>

<p>新建一个 post</p>

<pre><code>hugo new posts/my-first-post.md
</code></pre>

<p>同样的，可以在 docs 里建新的文件</p>

<p>与 EMACS 整合</p>

<p>EMACS 有一个 Hugo package，我们可以直接使用</p>

<hr />

<p>参考文章</p>

<ul>
<li><a href="https://www.gohugo.org/" rel="noreferrer" target="_blank">gohugo.org 官方文章</a></li>
<li><a href="https://blog.olowolo.com/post/hugo-quick-start/" rel="noreferrer" target="_blank">小 demo</a></li>
</ul>

        ]]>
      </description>
    </item>
    
    <item>
      <title>alfred workfow 使用注意事项</title>
      <link>https://blog.lierhua.top/tech/workflow/24.-alfred-%E4%BD%BF%E7%94%A8%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9/</link>
      <pubDate>Wed, 10 Oct 2018 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/workflow/24.-alfred-%E4%BD%BF%E7%94%A8%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>mac</code>, <code>alfred</code></p>

<h2 id="如何调试-workflow">如何调试 workflow</h2>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img52021-10-11%20at%203.09%20PM.png" alt="调试 workflow" /></p>

<p><a href="https://www.alfredapp.com/help/workflows/advanced/debugger/" rel="noreferrer" target="_blank">关于 alfred 可以参考的东西</a></p>

<h2 id="如何在-workflow-的-shell-脚本里使用参数">如何在 workflow 的 shell 脚本里使用参数</h2>

<pre><code class="language-shell">declare -a arr=(&quot;el a&quot; &quot;el b&quot; &quot;el c&quot;); for i in &quot;${arr[@]}&quot;; do \
  curl -X POST -H &quot;Content-Type: application/json&quot; -d \
    '{&quot;elem&quot;:&quot;'&quot;$i&quot;'&quot;}' &quot;https://httpbin.org/post&quot;; \
done
</code></pre>

<p>用 <code>'&quot;$i&quot;'</code> 来处理，但是如果遇到空格就会出问题，<a href="https://stackoverflow.com/questions/17029902/using-curl-post-with-variables-defined-in-bash-script-functions" rel="noreferrer" target="_blank">更好的办法</a>是使用 function 解决.</p>

<hr />

<h2 id="参考">参考</h2>

<ul>
<li><a href="https://github.com/dhanishgajjar/vscode-icons" rel="noreferrer" target="_blank">vs code 更变 Mac 图标</a></li>
<li><a href="https://www.jetbrains.com/company/brand/" rel="noreferrer" target="_blank">jetbrain 图标</a></li>
</ul>
        ]]>
      </description>
    </item>
    
    <item>
      <title>Karabiner 键位修改与配置</title>
      <link>https://blog.lierhua.top/tech/workflow/karabiner-%E9%94%AE%E4%BD%8D%E4%BF%AE%E6%94%B9%E4%B8%8E%E9%85%8D%E7%BD%AE/</link>
      <pubDate>Wed, 16 May 2018 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/workflow/karabiner-%E9%94%AE%E4%BD%8D%E4%BF%AE%E6%94%B9%E4%B8%8E%E9%85%8D%E7%BD%AE/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>karabiner</code>，<code>keyboard</code></p>

<p><code>Karabiner</code> 是一款修改键位的神器，通常可用用来优化我们的 <code>workflow</code> 是工作流程更加的舒适。</p>

<h3 id="gui配置键位修改">GUI配置键位修改</h3>

<p><code>Karabiner</code> 提供界面键位修改</p>

<p>然后打开 <code>Karabiner-Elements Preferences &gt; Complex Modifications &gt; Rules &gt; Add rule</code></p>

<p>选择好对应的配置，在 <code>Karabiner</code> 里选择 <code>enable</code> 即可。</p>

<h3 id="配置文件键位修改">配置文件键位修改</h3>

<p>除了使用 <code>GUI</code> 来配置与修改我们的 <code>Karabiner</code> 外，我们还可以直接的对他的配置文件进行操作，配置文件的模板可以参考官方网址内的简介。</p>

<p>配置文件地址 <code>~/.config/karabiner/karabiner.json</code></p>

<p>配置文件的一个 <code>demo</code> 如下，一般在官网找不到的配置，需要自己在配置文件里处理，我有一个需求就是在使用 <code>spacemacs</code> 时，不想使用 <code>spacemacs</code> 自带的 <code>shell</code> ，所以需要我们使用自己的 <code>shell</code> ，我一般都是使用 <code>iterm2</code> 来操作，因此在两个窗口见进行频繁的切换时无可避免的，我在系统环境下进行了如下的配置来保证使用 <code>option + h</code> 是左屏幕，<code>option + l</code> 是右屏幕。</p>

<p>这里修改好之后，因为 <code>option</code> 键离手指比较远，因此为了方便，我们使用了一个策略来让 <code>option</code> 的使用变得方便。</p>

<p>策略：<code>Change tab to option if pressed with other keys.</code></p>

<p>也就是当同时按下 <code>tab</code> 键和其他键位的时候，此时 <code>tab</code> 键自动映射为 <code>option</code>  键，这样我的左右小拇指可以轻松的处理这个键位。</p>

<p>使用的 <code>JSON</code> 配置代码如下：这段代码意义是自明性的，所以不做过多的赘述。</p>

<pre><code class="language-json">{
  &quot;description&quot;: &quot;Change tab to option if pressed with other keys. (rev 2)&quot;,
  &quot;manipulators&quot;: [
	{
	  &quot;type&quot;: &quot;basic&quot;,
	  &quot;from&quot;: {
		&quot;key_code&quot;: &quot;tab&quot;,
		&quot;modifiers&quot;: {
		  &quot;optional&quot;: [
			&quot;any&quot;
		  ]
		}
	  },
	  &quot;to&quot;: [
		{
		  &quot;key_code&quot;: &quot;left_option&quot;
		}
	  ],
	  &quot;to_if_alone&quot;: [
		{
		  &quot;key_code&quot;: &quot;tab&quot;,
		  &quot;hold_down_milliseconds&quot;: 500
		}
	  ]
	}
  ]
},
</code></pre>

<p>放置的位置在这里：</p>

<pre><code class="language-json">&quot;profiles&quot;: [
    {
        &quot;complex_modifications&quot;:{
            &quot;parameters&quot;: {},
            &quot;rules&quot;:[
                {这里面就是自己的配置内容，包含如上代码所有 description 级别的配置文件集合},
                {并排放置多个不同的配置内容}，
            ]
        }
    }
]
</code></pre>

<p>一个完整的例子：</p>

<pre><code class="language-json">&quot;profiles&quot;: [
    {
        &quot;complex_modifications&quot;:{
            &quot;parameters&quot;: {},
            &quot;rules&quot;:[
                {
                      &quot;description&quot;: &quot;Change tab to option if pressed with other keys&quot;,
                      &quot;manipulators&quot;: [
                        {
                          &quot;type&quot;: &quot;basic&quot;,
                          &quot;from&quot;: {
                            &quot;key_code&quot;: &quot;tab&quot;,
                            &quot;modifiers&quot;: {
                              &quot;optional&quot;: [
                                &quot;any&quot;
                              ]
                            }
                          },
                          &quot;to&quot;: [
                            {
                              &quot;key_code&quot;: &quot;left_option&quot;
                            }
                          ],
                          &quot;to_if_alone&quot;: [
                            {
                              &quot;key_code&quot;: &quot;tab&quot;,
                              &quot;hold_down_milliseconds&quot;: 500
                            }
                          ]
                        }
                      ]
                },
                {并排放置多个不同的配置内容}，
            ]
        }
    }
]
</code></pre>
        ]]>
      </description>
    </item>
    
    <item>
      <title>Mac 开发必备工具</title>
      <link>https://blog.lierhua.top/tech/mac-%E5%BC%80%E5%8F%91%E5%BF%85%E5%A4%87-app/</link>
      <pubDate>Wed, 16 May 2018 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/mac-%E5%BC%80%E5%8F%91%E5%BF%85%E5%A4%87-app/</guid>
      <description>
        <![CDATA[
        

<h3 id="开发类">开发类：</h3>

<ul>
<li>IntelliJ IDEA &ndash;&gt; all language ide</li>
<li>sequel Pro &ndash;&gt; mysql client</li>
<li>postico &ndash;&gt; postgresql client</li>
<li>SQLPro Studio &ndash;&gt; sql client</li>
<li>studio 3T or Navicat for Mongodb&ndash;&gt; mongodb client</li>
<li>vs code &ndash;&gt; 适合轻量级代码编辑器</li>
<li>iterm2, kitty &ndash;&gt; terminal 配合zsh, tmux, 开启vim模式</li>
<li>spacemacs &ndash;&gt; vim + emacs</li>
</ul>

<h3 id="笔记本">笔记本:</h3>

<ol>
<li>Typora &ndash;&gt; normal</li>
<li>Quiver &ndash;&gt; 技术文件笔记本, 配合 gitlab 使用</li>
<li>Ulysses &ndash;&gt; 非技术文档写作</li>
<li>MarginNote X &ndash;&gt; 对现有的书籍阅读过程中记性标记，思维导图工具</li>
<li>Reeder 3 &ndash;&gt; 其实他不是严格意义的笔记本，是一个RSS阅读器，但是相当于行走的笔记本</li>
<li>Logseq &ndash;&gt; 双链笔记</li>
<li>Obsidian &ndash;&gt; 双链笔记，支持 VIM 后推荐</li>
</ol>

<h3 id="工具类">工具类：</h3>

<ol>
<li>Moom &ndash;&gt; adjust windows position and size</li>
<li>欧陆词典</li>
<li>ipic &amp;&amp; picGo&ndash;&gt; 图床</li>
<li>mindnode &ndash;&gt; 思维导图</li>
<li>Annotate &ndash;&gt; 截图工具, 图片注释工具</li>
<li>textlab &ndash;&gt; 格式转换</li>
<li>Karabliner &ndash;&gt; 超级好用，键盘键位设置</li>
<li>bartender 3 &ndash;&gt; 图标扩展工具</li>
<li>Airmail &ndash;&gt; 优秀的邮件工具, 视图隐藏文件夹 (国内邮箱设置指南 <a href="https://www.zhihu.com/question/51539553" rel="noreferrer" target="_blank">https://www.zhihu.com/question/51539553</a>    <img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/20191230153006.png" alt="" />)</li>
<li>Boom 2 &ndash;&gt; 音乐增强工具</li>
<li>clear &ndash;&gt; 简介的TODO工具（适合规划每天的工作，不适合长期TODO的规划）</li>
<li>OmniGraffle Pro &ndash;&gt; 流程图绘制工具（常用命令实例与工具学习集合 &ndash;&gt; OmniFraffle）</li>
<li>NewFileMenu &ndash;&gt; 右键增强工具</li>
<li>finder增强技巧 &ndash;&gt; 右键一个文件，在新标签页中打开，切一个新的并排的窗口（<a href="https://www.jb51.net/os/MAC/404223.html）" rel="noreferrer" target="_blank">https://www.jb51.net/os/MAC/404223.html）</a></li>
<li>SiteSucker &ndash;&gt; 扒站神器</li>
<li>Tower &ndash;&gt; 实用的git查看器</li>
<li>OhMyStar2 &ndash;&gt; GitHub star查看神器</li>
<li>Charles &ndash;&gt; 抓包神器，具体使用见<a href="https://www.jianshu.com/p/5539599c7a25" rel="noreferrer" target="_blank">此处</a></li>
<li>postman &ndash;&gt; api 测试api工具, 强推</li>
<li>tuxera &ndash;&gt; ntfs 硬盘读写工具</li>
<li>web2app &ndash;&gt; 把一个网站变为Mac的一个APP应用的神器, 真神器一枚</li>
<li>幕布 &ndash;&gt; waterfall 思维导入和整理工具，界面十分美观，用起来很舒服，可以直接导出HTML格式的</li>
<li>eZip &ndash;&gt; 强大的解压缩工具</li>
<li>visual paradigm &ndash;&gt; 流程工具，胡大爷力建</li>
<li>Xnip &ndash;&gt; 超级好用，屏幕截长图工具, 也可以使用打印功能存为PDF（仅在网页适用）</li>
<li>pandoc &ndash;&gt; 文档类型转换工具，几乎全能支持(但是带表格的转换提别糟糕)，不是APP，通过brew下载，详见官方文档</li>
<li>Kaleidoscope &ndash;&gt; diff 工具</li>
<li>Tower &ndash;&gt; git 可视化工具，清晰的看到每个分支是如何工作的</li>
<li>Things3 &ndash;&gt; 待办事项整理工具</li>
</ol>

<h3 id="效率类">效率类:</h3>

<ol>
<li>Alfred 3 &ndash;&gt; workflow</li>
<li>contexts &ndash;&gt; 为每一个不同的进程设置一个文字的触发快捷键</li>
<li>Keyboard Maestro &ndash;&gt; 提供各种快捷输入，文字字典匹配, <a href="https://sspai.com/post/36442" rel="noreferrer" target="_blank">教程</a></li>
<li>unclutter &ndash;&gt; 提供屏幕顶部下拉，保存常用的文件和笔记</li>
<li>ghostnote2 &ndash;&gt; 提供任意应用的便签,（低频）</li>
<li>karabiner &ndash;&gt; 改键神器</li>
</ol>

<h3 id="浏览器">浏览器</h3>

<ol>
<li>Chrome （fupeng.li.dev@gmail.com）</li>
<li>Yandex  (fupeng.li.dev@gmail.com)</li>
</ol>

<h3 id="chrome-插件">Chrome 插件</h3>

<ol>
<li>Quiver 插件</li>
<li>彩云小译 - 网页翻译插件</li>
<li>gitpod online ide：vs code 在线编辑 github 代码</li>
<li>vue.js devtools</li>
<li>acid tabs: 自定义折叠的归类 <img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/%E6%88%AA%E5%B1%8F2021-07-22%E4%B8%8B%E5%8D%883.14.35.png" alt="" /></li>
</ol>

<h3 id="同步工具">同步工具</h3>

<ol>
<li>dropbox &ndash;&gt; 配合Quiver使用</li>
<li>Google Cloud &ndash;&gt; 大文件同步</li>
<li>Transmit &ndash;&gt; ftp 工具</li>
</ol>

<h3 id="其他类">其他类：</h3>

<ol>
<li>dash &ndash;&gt; api document</li>
<li>synergy &ndash;&gt; 鼠标屏幕共享</li>
<li>imazing &ndash;&gt; 代替iTunes的神器</li>
<li>Downie 3 &ndash;&gt; 视频下载神器</li>
<li>Permute 3 &ndash;&gt; 格式转换神器</li>
<li>Movist &ndash;&gt; 万能播放器</li>
</ol>

<h3 id="安全类">安全类</h3>

<ol>
<li>ProEncryptor 1.7 &ndash;&gt; 用于文件的加码解密，会自动将文件生成一个.pe的文件</li>
<li>lastPass &ndash;&gt; 密码保存工具 (fupeng.li.dev@gmail.com)</li>
<li>enPass &ndash;&gt; 密码生成与共享</li>
</ol>

        ]]>
      </description>
    </item>
    
    <item>
      <title>Spacemacs 初级使用指南</title>
      <link>https://blog.lierhua.top/tech/workflow/spacemacs-%E5%88%9D%E7%BA%A7%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97/</link>
      <pubDate>Wed, 16 May 2018 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/workflow/spacemacs-%E5%88%9D%E7%BA%A7%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97/</guid>
      <description>
        <![CDATA[
        

<h2 id="解决的痛点">解决的痛点：</h2>

<ul>
<li>同时拥有 vim 和 EMACS 的快捷键</li>
<li>相对于 jetbrain 全家桶，可以更方便的对目录，终端进行无鼠标操作</li>
<li>可以形成自己的 workflow , 大大减少工作流程</li>
<li>配置文件方式来进行配置，使用 elisp，可以方便的编写自己的插件</li>
<li>GTD 神器 ORG, 方便管理自己的日程安排</li>
</ul>

<h2 id="不足之处">不足之处：</h2>

<ul>
<li>学习成本略高，需要记忆一些快捷键</li>
<li>免费的软件在好多功能上，无法媲美付费软件，比如典型的 jetbrain，无法做到像 jetbrain 那样完美的支持全局替换和快速跳转等</li>
</ul>

<h2 id="安装与配置">安装与配置</h2>

<h3 id="安装">安装</h3>

<p>GitHub 使用 develop 分支</p>

<h3 id="基本介绍">基本介绍</h3>

<p>Spacemacs 可以看作是个中间层，对下它屏蔽了各种插件和配置复杂性，对上它向用户提供了简单而又统一的使用方案。 在 spacemacs 里面有个 layer（层）的概念，它把一系列的有关系的插件放一起打包成一个功能，添加这个 layer 即可使用。 既照顾到了便利性，开箱即用，又兼顾了灵活性，不需要的这个功能的用户可以不添加这个 layer。</p>

<h3 id="配置文件解读">配置文件解读</h3>

<p>space f e d 打开， space f e R 进行 reload</p>

<ul>
<li><strong>dotspacemacs/layers:</strong>  这和 layer（层）的配置有关。</li>
<li><strong>dotspacemacs/init:</strong> spacemacs 的一些基本配置。不要随意改动这里的结构。</li>
<li><strong>dotspacemacs/user-init:</strong>  这里面是给用户写自己的配置代码的。这个函数会在 spacemacs 启动的初期调用。</li>
<li><strong>dotspacemacs/user-config:</strong>  这里面也是给用户写自己的配置代码的。不同是该函数会在 spacemacs 启动的最后阶段调用。</li>
</ul>

<h2 id="基本操作上手">基本操作上手</h2>

<h3 id="工程操作-p">工程操作 p</h3>

<ul>
<li>目录树 <code>space p t</code></li>
<li>目录树的查找等操作, 跟操作文件相同</li>
<li>目录树到文件的跳转等操作</li>
</ul>

<h3 id="文件操作-f">文件操作 f</h3>

<ul>
<li>基本的文件打开 <code>space f f</code></li>
<li>打开最近的文件 <code>space f r</code></li>
<li>保存 <code>space f s</code></li>
<li>关闭等操作 <code>:q</code></li>
<li>复制操作 <code>space f y</code></li>
<li>行编号，十分有利于上下移动，会自动展示当前行对应的上下行号</li>
</ul>

<h3 id="窗口操作-w">窗口操作 w</h3>

<ul>
<li>如何切分窗口, 水平，竖直 <code>space w -</code> <code>space w /</code></li>
<li>抽口切换 <code>space num</code> 或者 <code>space w hjkl</code></li>
<li>如何 toggle 窗口 <code>space t g</code></li>
<li>如何改变窗口的大小 <code>space w [</code> <code>space w ]</code></li>
<li>窗口最大化 <code>space w m</code> , 再执行一次退出</li>
<li>关闭窗口 <code>space w d</code></li>
</ul>

<h3 id="buffer-操作-b">buffer 操作 b</h3>

<ul>
<li>buffer 打开关闭切换 <code>space b b</code></li>
</ul>

<h3 id="美化操作">美化操作</h3>

<ul>
<li>改变 theme <code>space T n</code></li>
<li>改变透明度 <code>space T T</code></li>
</ul>

<h3 id="代码相关">代码相关</h3>

<ul>
<li>添加和删除注释 <code>M-;</code></li>
</ul>

<h2 id="org">ORG</h2>

<h3 id="基本使用">基本使用</h3>

<ul>
<li>不同层级 （*）f</li>
<li>TODO的使用

<ul>
<li><code>C-c, C-t</code> 切换标题类TODO的状态</li>
<li><code>C-c, C-c</code> （或者<code>,,</code>）</li>
</ul></li>
<li>Agenda 使用

<ul>
<li>添加当前文件到日程安排<code>C-c [</code>， 重复去除</li>
<li><code>space a o o a</code> 查看日程安排</li>
<li>`C-c . 添加日程安排时间</li>
</ul></li>
<li>表格的使用 <code>, t n</code></li>
<li>代码块的使用 <code>space i s</code>

<ul>
<li><code>C-c '</code> 进入这个代码的 <code>major-mode</code> 进行编辑，再次按退出</li>
<li><code>C-c C-c</code> 输出代码执行结j果</li>
<li>9.2 中代码块 <code>C-c C-,</code> <a href="https://emacs-china.org/t/spacemacs-org-mode-s/8366" rel="noreferrer" target="_blank">地址</a></li>
</ul></li>
</ul>

<h3 id="文件类型转换-c-c-c-e">文件类型转换  (<code>C-c, C-e</code>)</h3>

<ul>
<li>org, md, html, tex, pdf</li>
<li>org &ndash;&gt; hugo</li>
</ul>

<p>其他补充：</p>

<p><code>major-mode-leader</code>，默认绑定到 <code>,</code>上，和很多 vim 用户的 leader 是一致的。 它和 leader 键不同在于，它里面的按键是和你编辑的文件有关系，你编辑 C++文件时是一套按键，而换到 org 文件是又是另外一套按键。 所以这个前缀键开头的是和你编辑的文件的类型相关的功能。</p>

<p>参考文章：</p>

<ul>
<li><a href="http://book.emacs-china.org/" rel="noreferrer" target="_blank">http://book.emacs-china.org/</a></li>
<li><a href="https://orgmode.org/worg/exporters/beamer/tutorial.html" rel="noreferrer" target="_blank">https://orgmode.org/worg/exporters/beamer/tutorial.html</a></li>
<li><a href="https://orgmode.org/manual/Beamer-export.html" rel="noreferrer" target="_blank">https://orgmode.org/manual/Beamer-export.html</a></li>
<li><a href="https://www.hahack.com/tools/org-beamer-cn/" rel="noreferrer" target="_blank">https://www.hahack.com/tools/org-beamer-cn/</a></li>
<li><a href="https://github.com/fniessen/refcard-org-beamer" rel="noreferrer" target="_blank">https://github.com/fniessen/refcard-org-beamer</a></li>
<li><a href="https://github.com/fniessen/refcard-org-beamer" rel="noreferrer" target="_blank">https://github.com/fniessen/refcard-org-beamer</a></li>
<li><a href="http://emacs-fu.blogspot.com/2009/10/writing-presentations-with-org-mode-and.html" rel="noreferrer" target="_blank">http://emacs-fu.blogspot.com/2009/10/writing-presentations-with-org-mode-and.html</a></li>
<li><a href="https://www.spacemacs.org/layers/+emacs/org/README.html#org" rel="noreferrer" target="_blank">https://www.spacemacs.org/layers/+emacs/org/README.html#org</a></li>
<li><a href="https://www.cnblogs.com/chenfanyu/archive/2013/01/27/2878845.html" rel="noreferrer" target="_blank">https://www.cnblogs.com/chenfanyu/archive/2013/01/27/2878845.html</a></li>
</ul>

        ]]>
      </description>
    </item>
    
    <item>
      <title>小鹤双拼方案口诀</title>
      <link>https://blog.lierhua.top/tech/%E5%B0%8F%E9%B9%A4%E5%8F%8C%E6%8B%BC%E5%8F%A3%E8%AF%80/</link>
      <pubDate>Wed, 16 May 2018 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/%E5%B0%8F%E9%B9%A4%E5%8F%8C%E6%8B%BC%E5%8F%A3%E8%AF%80/</guid>
      <description>
        <![CDATA[
        

<h2 id="口诀">口诀</h2>

<p>Kuai ing Liang uang Ruan Cao Zou   T ue Qiu Yun Wei Jan Mian</p>

<p>快   迎   两    王   软     草  走， 特 约  秋   云  为   见  面。</p>

<p>Xia ua Song iong shU chI zhVi  Geng Dai Bin Niao Fen Pie Hang</p>

<p>夏   娃  怂   恿   书   痴   追，  更  待  滨    鸟   分   撇  航？</p>

<h2 id="注释">注释：</h2>

<p>一和三两句的前四个字为一个大写字母键代表了两个字的拼音。</p>

<p>T ue各取拼音谐音为特约，Jan取英文谐音为见。其余均是一个大写字母键代表一个字的拼音。</p>

<p>滨鸟是一类鸟，分撇一词是分离之意。故滨鸟分撇航意译为鸳鸯各自飞。</p>

<h2 id="译文">译文</h2>

<p>一个地方官笑着说：“快欢迎两位王爷到软草园走走，我为两位特意约了秋云姑娘来见
面。”夏娃听见了，怂恿暗恋秋云的书痴快去追，此时不追，更待何时？难道要等鸳鸯各自飞？</p>

        ]]>
      </description>
    </item>
    
    <item>
      <title>iphone 中 workflow 的应用</title>
      <link>https://blog.lierhua.top/tech/workflow/iphone-%E4%B8%AD-workflow-%E7%9A%84%E5%BA%94%E7%94%A8/</link>
      <pubDate>Thu, 05 Apr 2018 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/workflow/iphone-%E4%B8%AD-workflow-%E7%9A%84%E5%BA%94%E7%94%A8/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>iphone</code>, <code>workflow</code>, <code>rfid</code>, <code>NFC</code>, <code>物联网</code></p>

<p>开坑待写, 主要是快捷方式还有如何利用好 NFC 的功能</p>

<hr />

<p>看到的相关文章：</p>

<ul>
<li><a href="https://zhuanlan.zhihu.com/p/89824463" rel="noreferrer" target="_blank">https://zhuanlan.zhihu.com/p/89824463</a></li>
</ul>
        ]]>
      </description>
    </item>
    
    <item>
      <title>alfred workflow 使用指南</title>
      <link>https://blog.lierhua.top/tech/workflow/alfred-workflow-%E4%BD%BF%E7%94%A8/</link>
      <pubDate>Sun, 01 Apr 2018 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/workflow/alfred-workflow-%E4%BD%BF%E7%94%A8/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>alfred</code>, <code>workflow</code>, <code>mac</code></p>

<p>Alfred 是 mac 上最受欢迎的 launch APP，这篇文章主要讲用过的 Alfred 的 workflow, 我呼出所有 workflow 列表的 key 是 <code>fff</code></p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/%E6%88%AA%E5%B1%8F2021-04-01%E4%B8%8B%E5%8D%885.07.21.png" alt="" /></p>

<h2 id="todo-记录与-think-想法-自己定制">TODO 记录与 THINK 想法 （自己定制）</h2>

<p>我经常会有这种使用场景，忙活着别的东西的时候，突然脑袋蹦出了个有意思的想法，我想赶紧记下来，但是又不想切换使用的 APP，因为一旦切换 APP，就但打断当前的工作流</p>

<p>可能当前我正在写代码，或者我正在处理脚本命令，或者在写技术文档，反正就是不能打断我目前的流程，所以以往的那些打开笔记 APP 或者打开备忘录的切换进程的方法肯定要被我 pass 掉</p>

<p>因此就有了我这个 workflow，流程很简单，就是快捷键呼出 Alfred 之后，输入关键字 todo 或者 think 然后输入自己的待办事项或者想法回车，就会自动保存到指定的文件里, 而这个指定的文件夹我是直接使用 Git 进行版本控制的，保存到文件夹之后，同时触发 git 提交的动作，于是，我可以立马在自己手机也可以得到更新。</p>

<p>然后就可以继续之前的工作流，不打断，不占用，用完即走，不用关心保存在了哪里，保存了什么，当空闲下来时，再回头去整理之前发的那些想法。</p>

<p>这个图片就是一个演示 demo，在不干扰我写这篇文档的时候，记录一个 TODO</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/%E6%88%AA%E5%B1%8F2021-04-01%E4%B8%8B%E5%8D%885.00.28.png" alt="" /></p>

<h2 id="open-finder">open finder</h2>

<p>Mac 打开 finder 真的是超级难用，使用这个 workflow，直接输入 open 即可，如果想打开想去的目录，需要输入目录的名字，如果只输入了 open 空格，然后回车，自动打开 Desktop 目录</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/%E6%88%AA%E5%B1%8F2021-04-01%E4%B8%8B%E5%8D%885.12.01.png" alt="" /></p>

<h2 id="quiver-search">quiver search</h2>

<p>quiver 是我 Mac 下用过的最舒服的记事本工具，没有之一，以前有一篇 blog 专门介绍过他，<a href="http://lierhua.top/2018/07/03/%E7%A8%8B%E5%BA%8F%E5%91%98%E5%BF%85%E5%A4%87%E4%BA%91%E7%AC%94%E8%AE%B0%E6%9C%AC%EF%BC%9AQuiver_new/" rel="noreferrer" target="_blank">链接在这里</a></p>

<p>但是每次想搜 quiver 里的笔记的时候，首先要先打开 quiver，然后找到搜索框，输入搜索项，回车。一共四五个步骤，主要是需要切换 APP，这个过程就相当于与电脑切换进程，对于人脑而言也是一样的</p>

<p>非常的消耗精力，所以就有了 quiver search 这个 workflow，呼出 Alfred 之后，直接搜索即可，即刻已浮窗的形式把你要搜的文档展示出来</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/%E6%88%AA%E5%B1%8F2021-04-01%E4%B8%8B%E5%8D%885.23.58.png" alt="" /></p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/%E6%88%AA%E5%B1%8F2021-04-01%E4%B8%8B%E5%8D%885.21.12.png" alt="" /></p>

<h2 id="copy-link">copy link</h2>

<p>想要快速拿到一个网页文件的连接地址，但是又不想双手离开键盘，那么用这个 workflow 就对了，只需要停留在想要的网页上，呼出 Alfred，然后输入 cl , 就可以将当前活跃的网页的 URL 赋值到剪贴板</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/%E6%88%AA%E5%B1%8F2021-04-01%E4%B8%8B%E5%8D%885.31.10.png" alt="" /></p>

<h2 id="copy-path">copy path</h2>

<p>对于一个 RD 来说，拿到文件的 path 是经常需要的，所以就有了这个 workflow，当我在某个 finder 中看中了某个文件，想拿到这个文件的 path, 只需要呼出 Alfred，然后输入 cp 回车就可以拿到这个文件地址并且复制到剪贴板。</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/%E6%88%AA%E5%B1%8F2021-04-01%E4%B8%8B%E5%8D%885.27.34.png" alt="" /></p>

<h2 id="emoji">emoji</h2>

<p>当你在使用聊天 APP 时，想发送 emoji 但是又不想用手指一个个的找，就用这个 workflow，只需要打开 Alfred，输入 ej, 上千 emoji 任你输入挑选，recent 会在最前</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/%E6%88%AA%E5%B1%8F2021-04-01%E4%B8%8B%E5%8D%885.33.12.png" alt="" /></p>

<h2 id="faker-data">faker data</h2>

<p>有没有一种场景，你需要快速给出一个假名字，邮箱，地址，单词，文字等，这个 Faker data 就是为这个准备的，下面的 Faker data 都是用这个生成的</p>

<pre><code>name: Kelton Hayes
email: Green.Ralph@hotmail.com
address: 625 Lura Street
         Wilkinsonside, WV 20882
word: reiciendis
text: Qui eos quidem nesciunt hic. Fugit omnis nostrum pariatur magnam ad in non. Illo quisquam numquam est ratione quam. Consequatur consequatur sed et.
......
</code></pre>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/%E6%88%AA%E5%B1%8F2021-04-01%E4%B8%8B%E5%8D%885.36.06.png" alt="" /></p>

<h2 id="其他待补充">其他待补充</h2>

<p>还有好多其他的我用的很舒服的 workflow，以后再补充</p>
        ]]>
      </description>
    </item>
    
    <item>
      <title>如何阅读一篇论文</title>
      <link>https://blog.lierhua.top/tech/%E5%A6%82%E4%BD%95%E9%98%85%E8%AF%BB%E4%B8%80%E7%AF%87%E8%AE%BA%E6%96%87/</link>
      <pubDate>Wed, 17 Feb 2016 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/%E5%A6%82%E4%BD%95%E9%98%85%E8%AF%BB%E4%B8%80%E7%AF%87%E8%AE%BA%E6%96%87/</guid>
      <description>
        <![CDATA[
        

<blockquote>
<p>翻译自滑铁卢大学 keshav
原文：<a href="/file/paper-reading.pdf">点击访问</a></p>
</blockquote>

<h2 id="版本-2016年2月17日">版本：2016年2月17日</h2>

<h3 id="s-keshav">S. Keshav</h3>

<p>David R. Cheriton School of Computer Science, University of Waterloo<br />
加拿大安大略省滑铁卢市<br />
keshav@uwaterloo.ca</p>

<h2 id="摘要">摘要</h2>

<p>研究人员花费大量时间阅读研究论文。然而，这种技能很少被教授，导致很多努力被浪费。本文概述了一种实用且高效的三遍阅读研究论文的方法。我还描述了如何使用这种方法进行文献综述。</p>

<h2 id="1-引言">1. 引言</h2>

<p>研究人员必须出于几个原因阅读论文：为会议或课程审阅论文，保持在自己的领域内的最新状态，或者对一个新领域的文献进行综述。一个典型的研究人员每年可能会花费数百小时阅读论文。学会高效地阅读论文是一项至关重要但很少被教授的技能。因此，刚开始的研究生必须自己通过试错来学习。在这个过程中，学生们浪费了大量的努力，并经常被逼到沮丧。多年来，我使用了一个简单的“三遍”方法，以防止我在获得鸟瞰图之前淹没在论文的细节中。它允许我估计审阅一组论文所需的时间。此外，我可以根据我的需求以及我拥有的时间来调整论文评估的深度。本文描述了这种方法及其在进行文献综述中的使用。</p>

<h2 id="2-三遍方法">2. 三遍方法</h2>

<p>关键思想是你应该最多阅读三遍论文，而不是从开头读到结尾。每一遍都完成特定的目标，并建立在前一遍的基础上：第一遍给你一个关于论文的大致概念。第二遍让你掌握论文的内容，而不是细节。第三遍帮助你深入理解论文。</p>

<h3 id="2-1-第一遍">2.1 第一遍</h3>

<p>第一遍是快速浏览，以获得论文的鸟瞰图。你还可以决定是否需要进行更多遍的阅读。这一遍应该需要大约五到十分钟，并包括以下步骤：</p>

<ol>
<li>仔细阅读标题、摘要和引言。</li>
<li>阅读章节和小节标题，但忽略其他所有内容。</li>
<li>浏览数学内容（如果有的话），以确定底层的理论基础。</li>
<li>阅读结论。</li>
<li>浏览参考文献，心里勾画你已经阅读过的。</li>
</ol>

<p>在第一遍结束时，你应该能够回答五个C：</p>

<ul>
<li><strong>类别</strong>：这是哪种类型的论文？是测量论文吗？是对现有系统的分析吗？是对研究原型的描述吗？</li>
<li><strong>背景</strong>：它与哪些其他论文相关？用于分析问题的理论基础是什么？</li>
<li><strong>正确性</strong>：假设看起来是有效的吗？</li>
<li><strong>贡献</strong>：论文的主要贡献是什么？</li>
<li><strong>清晰度</strong>：论文写得好吗？</li>
</ul>

<p>使用这些信息，你可以选择不再阅读（并且不打印它，从而节约树木）。这可能是因为论文不引起你的兴趣，或者你对该领域不够了解，无法理解论文，或者作者做出了无效的假设。第一遍对于不在你研究领域但将来可能相关的论文来说是足够的。顺便说一下，当你写一篇论文时，你可以期望大多数审稿人（和读者）只对它进行一遍阅读。请小心选择连贯的章节和小节标题，并写出简洁全面的摘要。如果审稿人在一遍阅读后不能理解要点，论文很可能会遭到拒绝；如果读者在五分钟后不能理解论文的亮点，论文很可能永远不会被阅读。因此，一个用单个精心挑选的图表总结论文的“图形摘要”是一个绝佳的想法，并且可以在科学期刊中越来越多地找到。</p>

<h3 id="2-2-第二遍">2.2 第二遍</h3>

<p>在第二遍中，更仔细地阅读论文，但忽略细节，如证明。边读边记下关键点，或在边注中做评论是有帮助的。来自奥格斯堡大学的Dominik Grusemann建议你“记下你不理解的术语，或者你想要问作者的问题。”如果你是一名论文审稿人，这些评论将帮助你在写审稿意见时，以及在程序委员会会议上支持你的审稿意见。</p>

<ol>
<li>仔细查看论文中的图表、图解和其他插图。特别注意图形。轴是否正确标记？结果是否显示了误差条，以便结论具有统计意义？这些常见的错误将把匆忙、粗糙的工作与真正优秀的工作区分开来。</li>
<li>记得标记相关未读的参考文献以供进一步阅读（这是了解论文背景的好方法）。</li>
</ol>

<p>第二遍应该需要一个有经验的读者最多一个小时。在这一遍之后，你应该能够掌握论文的内容。你应该能够向其他人总结论文的主要论点，以及支持证据。这种细节水平适用于你感兴趣的论文，但不属于你的研究专业。有时即使你在第二遍结束时也不理解一篇论文。这可能是因为主题对你来说是新的，有不熟悉的术语和缩写。或者作者使用了一个你不理解的证明或实验技术，以至于论文的大部分内容对你来说都是难以理解的。论文可能写得很差，有未经证实的断言和许多前向引用。或者只是因为现在是深夜，你很疲倦。你现在可以选择：(a) 把论文放在一边，希望你不需要理解这些材料就能在你的职业生涯中取得成功，(b) 稍后再回到论文，也许在阅读背景材料之后，或者 &copy; 坚持并继续第三遍。</p>

<h3 id="2-3-第三遍">2.3 第三遍</h3>

<p>要完全理解一篇论文，特别是如果你是审稿人，需要第三遍。第三遍的关键是尝试虚拟地重新实现论文：也就是说，做出与作者相同的假设，重新创建工作。通过将这个重新创造与实际的论文进行比较，你可以很容易地识别出论文的创新之处，以及它的隐藏缺陷和假设。这一遍需要极大的注意力。你应该识别并挑战每一条陈述中的每一个假设。此外，你应该思考你自己会如何呈现一个特定的想法。这种实际与虚拟的比较可以非常清晰地洞察到论文中的证明和呈现技巧，并且你很可能可以将这些技巧添加到你的工具箱中。在这一遍中，你还应该记下未来工作的想法。对于初学者来说，这一遍可能需要几个小时，即使是有经验的读者也可能需要一两个小时以上。在这一遍结束时，你应该能够仅凭记忆重建整篇论文的结构，并且能够识别出它的强项和弱点。特别是，你应该能够指出隐含的假设、遗漏的相关工作的引用，以及实验或分析技术中可能出现的问题。</p>

<h2 id="3-进行文献综述">3. 进行文献综述</h2>

<p>在进行文献综述时，将考验你的论文阅读技能。这将需要你阅读数十篇论文，可能在一个不熟悉的领域。你应该阅读哪些论文？以下是你如何使用三遍方法来帮助的。</p>

<p>首先，使用学术搜索引擎，如Google Scholar或CiteSeer，以及一些精心挑选的关键词，找到该领域最近的三到五篇高引用论文。对每篇论文进行一遍阅读，以了解工作，然后阅读它们的相关工作部分。你将找到最近工作的缩略图摘要，并且，如果你幸运的话，可能会找到一个最近的综述论文的指针。如果你能找到这样的综述，你就完成了。阅读综述，祝贺你的好运。否则，在第二步中，找到参考文献中的共享引用和重复的作者名字。这些是该领域的关键论文和研究人员。下载关键论文并将它们放在一边。然后访问关键研究人员的网站，看看他们最近在哪里发表过。这将帮助你确定该领域的顶级会议，因为最好的研究人员通常在顶级会议上发表。第三步是访问这些顶级会议的网站，并浏览他们最近的会议记录。快速浏览通常可以识别出最近的高质量相关工作。这些论文，以及你之前放在一边的论文，构成了你的调查的第一版。对这些论文进行两遍阅读。如果它们都引用了一个你之前没有找到的关键论文，请获取并阅读它，必要时进行迭代。</p>

<h2 id="4-相关工作">4. 相关工作</h2>

<p>如果你是为了进行评审而阅读论文，你还应该阅读Timothy Roscoe的论文“为系统会议撰写评审”[3]。如果你计划写一篇技术论文，你应该参考Henning Schulzrinne的全面网站[4]和George Whitesides对整个过程的优秀概述[5]。最后，Simon Peyton Jones有一个网站，涵盖了研究技能的整个范围[2]。心理学公司的Iain H. McLean制作了一个可下载的“评审矩阵”，简化了使用三遍方法对实验心理学论文进行评审的过程[1]，这可能可以稍作修改，用于其他领域的论文。</p>

<h2 id="5-致谢">5. 致谢</h2>

<p>本文档的第一版由我的学生Hossein Falaki、Earl Oliver和Sumair Ur Rahman起草。感谢他们。我还从Christophe Diot的深刻评论和Nicole Keshav的敏锐校对中受益。我想使这成为一个活文档，随着我收到评论而更新。请花一点时间通过电子邮件向我发送任何评论或改进建议。感谢多年来许多通讯员的鼓励性反馈。</p>

<h2 id="参考文献">参考文献</h2>

<ol>
<li>I.H. McLean, “Literature Review Matrix,” <a href="http://psychologyinc.blogspot.com/" rel="noreferrer" target="_blank">http://psychologyinc.blogspot.com/</a></li>
<li>S. Peyton Jones, “Research Skills,” <a href="http://research.microsoft.com/enus/um/people/simonpj/papers/giving-a-talk/giving-atalk.htm" rel="noreferrer" target="_blank">http://research.microsoft.com/enus/um/people/simonpj/papers/giving-a-talk/giving-atalk.htm</a></li>
<li>T. Roscoe, “Writing Reviews for Systems Conferences,” <a href="http://people.inf.ethz.ch/troscoe/pubs/review-writing.pdf" rel="noreferrer" target="_blank">http://people.inf.ethz.ch/troscoe/pubs/review-writing.pdf</a></li>
<li>H. Schulzrinne, “Writing Technical Articles,” [<a href="http://www.cs.columbia.edu/~hgs/etc/writing-style.html](http://www.cs.columbia" rel="noreferrer" target="_blank">http://www.cs.columbia.edu/~hgs/etc/writing-style.html](http://www.cs.columbia</a></li>
</ol>

        ]]>
      </description>
    </item>
    
    <item>
      <title>关于 v2ray 你应该知道的</title>
      <link>https://blog.lierhua.top/tech/lantern/%E5%85%B3%E4%BA%8E-v2ray-%E4%BD%A0%E5%BA%94%E8%AF%A5%E7%9F%A5%E9%81%93%E7%9A%84/</link>
      <pubDate>Thu, 26 Oct 2006 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/lantern/%E5%85%B3%E4%BA%8E-v2ray-%E4%BD%A0%E5%BA%94%E8%AF%A5%E7%9F%A5%E9%81%93%E7%9A%84/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>v2ray</code>, <code>xray</code>, <code>vmess</code>, <code>kcp-go</code>, <code>kcptun</code></p>

<h2 id="原理简介-https-guide-v2fly-org-basics-vmess-html-e6-9c-8d-e5-8a-a1-e5-99-a8-e9-85-8d-e7-bd-ae"><a href="https://guide.v2fly.org/basics/vmess.html#%E6%9C%8D%E5%8A%A1%E5%99%A8%E9%85%8D%E7%BD%AE" rel="noreferrer" target="_blank">原理简介</a></h2>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img5202212061705320.png" alt="" /></p>

<p>首先讲一下 v2ray-core (<a href="https://www.v2fly.org/" rel="noreferrer" target="_blank">官网点这里</a>) 的工作原理，v2ray-core 并不是一个 C/S 的结构，它更像是一个可串联节点的服务，v2ray 同时既可以做客户端，又可以做服务端，只是根据个人的需求使用的不同的配置文件即可。</p>

<h3 id="浏览器">浏览器</h3>

<p>浏览器设置好代理地址与端口, 假设协议是 <a href="https://www.v2ray.com/chapter_02/protocols/socks.html" rel="noreferrer" target="_blank">socks</a>，对应的端口号是 7891，当我们使用浏览器发送请求时，就会被打包发送到端口 7891，此时 v2ray 的 inbound, 也就是流量的入口配置的就是 localhost 的 7891, 所以此刻正在监听端口 7891 的 v2ray 就收到了请求.</p>

<blockquote>
<p>socks5是一个代理协议，主要的作用就是代理客户端来访问远程服务器，起到一个中介作用。
一般情况下当代理客户端因为防火墙等原因访问不了远程服务器，而另一个服务器即可以访问远程服务器又可以被客户端访问到时，可以在这个服务器上部署socks5服务端，本地部署 <a href="https://github.com/0990/socks5" rel="noreferrer" target="_blank">socks5</a> 客户端，让这个中介服务器来代理访问远程服务器, 但是由于是明文传输，因此有局限性。</p>
</blockquote>

<h3 id="客户端">客户端</h3>

<p>v2ray 接收到数据包之后要将数据包打包成 <a href="https://www.v2ray.com/developer/protocols/vmess.html" rel="noreferrer" target="_blank">VMess</a> 协议支持的格式并且使用预设的 id 加密（这个例子 id 是 b831381d-6324-4d53-ad4f-8cda48b30811），然后发往服务器地址为 serveraddr.com 的 443 端口。</p>

<blockquote>
<p><a href="https://guide.v2fly.org/basics/vmess.html#%E9%85%8D%E7%BD%AE%E5%89%8D%E7%9A%84%E5%87%86%E5%A4%87" rel="noreferrer" target="_blank">vmess 协议</a></p>
</blockquote>

<p>配置文件示例如下:</p>

<pre><code class="language-json">{
  &quot;inbounds&quot;: [
    {
      &quot;port&quot;: 7891, // 监听端口
      &quot;protocol&quot;: &quot;socks&quot;, // 入口协议为 SOCKS 5
      &quot;sniffing&quot;: {
        &quot;enabled&quot;: true,
        &quot;destOverride&quot;: [&quot;http&quot;, &quot;tls&quot;]
      },
      &quot;settings&quot;: {
        &quot;auth&quot;: &quot;noauth&quot;  //socks的认证设置，noauth 代表不认证，由于 socks 通常在客户端使用，所以这里不认证
      }
    }
  ],
  &quot;outbounds&quot;: [
    {
      &quot;protocol&quot;: &quot;vmess&quot;, // 出口协议
      &quot;settings&quot;: {
        &quot;vnext&quot;: [
          {
            &quot;address&quot;: &quot;serveraddr.com&quot;, // 服务器地址，请修改为你自己的服务器域名
            &quot;port&quot;: 443,  // 服务器端口
            &quot;users&quot;: [
              {
                &quot;id&quot;: &quot;b831381d-6324-4d53-ad4f-8cda48b30811&quot;,  // 用户 ID，必须与服务器端配置相同
                &quot;alterId&quot;: 64 // 此处的值也应当与服务器相同
              }
            ]
          }
        ]
      }
    }
  ]
}
</code></pre>

<h3 id="服务端">服务端</h3>

<p>服务器配置的 id 是 b831381d-6324-4d53-ad4f-8cda48b30811，所以 v2ray 服务器接收到客户端发来的数据包时就会尝试用 b831381d-6324-4d53-ad4f-8cda48b30811 解密，如果解密成功再看一下时间对不对，对的话就把数据包发到 outbound 去，outbound.protocol 是 freedom（freedom 的中文意思是自由，在这里姑且将它理解成直连吧），数据包就直接发到 google.com 了。</p>

<p>配置文件示例：</p>

<pre><code class="language-json">{
  &quot;inbounds&quot;: [
    {
      &quot;port&quot;: 16823, // 服务器监听端口, 需要在服务前面加一个 caddy做反向代理，caddy 开放端口 443 与客户端的端口对应一致
      &quot;protocol&quot;: &quot;vmess&quot;,    // 主传入协议
      &quot;settings&quot;: {
        &quot;clients&quot;: [
          {
            &quot;id&quot;: &quot;b831381d-6324-4d53-ad4f-8cda48b30811&quot;,  // 用户 ID，客户端与服务器必须相同
            &quot;alterId&quot;: 64
          }
        ]
      }
    }
  ],
  &quot;outbounds&quot;: [
    {
      &quot;protocol&quot;: &quot;freedom&quot;,  // 主传出协议
      &quot;settings&quot;: {}
    }
  ]
}
</code></pre>

<h3 id="完整的流程-https-guide-v2fly-org-basics-vmess-html-e5-8e-9f-e7-90-86-e7-ae-80-e6-9e-90"><a href="https://guide.v2fly.org/basics/vmess.html#%E5%8E%9F%E7%90%86%E7%AE%80%E6%9E%90" rel="noreferrer" target="_blank">完整的流程</a></h3>

<p>实际的数据包的流向大致如下：</p>

<pre><code>{浏览器} &lt;--(socks)--&gt; {v2ray 客户端 inbound &lt;-&gt; v2ray 客户端 outbound} &lt;--(VMess)--&gt;  {v2ray 服务器 inbound &lt;-&gt; v2ray 服务器 outbound} &lt;--(Freedom)--&gt; {目标网站}
</code></pre>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/v2ray%E6%B5%81%E7%A8%8B.svg" alt="" /></p>

<h3 id="实际操作">实际操作</h3>

<p>但是实际上，服务端我们会部署 v2ray，但是客户端很少直接部署 v2ray, 而是会用一些界面客户端，他们都是其他人封装了 v2ray 之后，给出的更好用的配置界面，所以使用的配置文件就不是上面那种 inbound 和 outbound 的样子了，而是根据不同的客户端采用了不同格式的配置文件, 但是不论格式怎么变，该有的配置的必须有的，比如监听的端口是什么，采用了什么协议，发送到服务端的哪个地址，都需要。</p>

<p>就比如 mac 上用的 clashX, 安卓用的 clash for andriod， 都是 v2ray 协议封装的客户端，配置好对应的配置文件即可以使用了。</p>

<p>当然除了这些客户端，还有一些也集成了 v2ray 或者 Xray 功能的也可以作为客户端来使用：iphone 用的 Surge 和 Shadowrocket。</p>

<h3 id="加速器">加速器</h3>

<p>kcptun 是一个基于 kcp-go 的高速远程端口转发工具, 配合ssh -D，可以比 shadowsocks 更流畅的看在线视频。</p>

<h2 id="快捷部署">快捷部署</h2>

<p>我们可以用官方提供的方案进行部署，但是这会比较麻烦，目前已经有好多开发者帮我们写好一键部署的快捷方式，基本上都是基于 docker 容器的部署，推荐一个比较<a href="https://github.com/luoqeng/caddy-v2ray-docker" rel="noreferrer" target="_blank">好用的</a>。</p>

<p>但是目前 v2ray 有 bug, 存在被监测的风险，因此，如果是普通需求可以使用，如果有更稳定性的要求，推荐使用 Xray。</p>

<hr />

<p>参考：</p>

<ul>
<li><a href="https://wiyi.org/socks5-protocol-in-deep.html" rel="noreferrer" target="_blank">socks5</a></li>
<li><a href="https://github.com/skywind3000/kcp" rel="noreferrer" target="_blank">kcp</a></li>
<li><a href="https://github.com/xtaci/kcp-go" rel="noreferrer" target="_blank">kcp-go</a></li>
<li><a href="https://github.com/xtaci/kcptun" rel="noreferrer" target="_blank">kcptun</a></li>
<li><a href="https://github.com/v2ray/v2ray-core/releases" rel="noreferrer" target="_blank">v2ray-core</a></li>
<li><a href="https://guide.v2fly.org/basics/http.html#%E9%85%8D%E7%BD%AE" rel="noreferrer" target="_blank">新 v2ray 白话文指南</a></li>
<li><a href="https://www.v2ray.com/" rel="noreferrer" target="_blank">porject V</a></li>
<li><a href="https://github.com/kchen0x/v2rayDocker" rel="noreferrer" target="_blank">v2ary docker</a></li>
<li><a href="https://zhuanlan.zhihu.com/p/53849089" rel="noreferrer" target="_blank">kcptun 开发小记</a></li>
</ul>
        ]]>
      </description>
    </item>
    
    <item>
      <title>电报 bot 的使用</title>
      <link>https://blog.lierhua.top/tech/lantern/%E7%94%B5%E6%8A%A5-bot-%E7%9A%84%E4%BD%BF%E7%94%A8/</link>
      <pubDate>Thu, 26 Oct 2006 00:00:00 +0000</pubDate>
      
      <guid>https://blog.lierhua.top/tech/lantern/%E7%94%B5%E6%8A%A5-bot-%E7%9A%84%E4%BD%BF%E7%94%A8/</guid>
      <description>
        <![CDATA[
        <p>关键词：<code>电报</code>, <code>bot</code></p>

<h2 id="如何申请一个-bot">如何申请一个 bot，</h2>

<p>电报的 bot 申请很简单，按照官网一步步来就行，<a href="https://core.telegram.org/bots#6-botfather" rel="noreferrer" target="_blank">地址</a>.</p>

<p>申请好了之后去看看 <a href="https://core.telegram.org/bots/api" rel="noreferrer" target="_blank">API 文档</a>.</p>

<p>如果看完文档还有迷惑，我写几个 demo 看完马上就可以明白了</p>

<h3 id="例子-1-获取个人信息">例子 1 获取个人信息</h3>

<p><code>method</code>: <code>GET</code></p>

<p><code>path</code>: <code>https://api.telegram.org/bot[token]/getMe</code></p>

<p>解释：其中 [token] 就是在生成 bot 后 botFather 给你的，替换掉 [token] 就可以，格式类似于 <code>A:B</code> 然后最后的 <code>getMe</code> 是 <code>METHOD_NAME</code>,就是请求的方法的名字</p>

<p>上面这个请求执行后，得到的结果如下, 这个 getMe 就是获得自己的信息的接口</p>

<pre><code class="language-json">{
    &quot;ok&quot;: true,
    &quot;result&quot;: {
        &quot;id&quot;: &quot;1791xxx819&quot;,
        &quot;is_bot&quot;: true,
        &quot;first_name&quot;: &quot;滴答滴&quot;,
        &quot;username&quot;: &quot;didadidadidadibot&quot;,
        &quot;can_join_groups&quot;: true,
        &quot;can_read_all_group_messages&quot;: false,
        &quot;supports_inline_queries&quot;: false
    }
}
</code></pre>

<p>除了这个 <code>getMe</code> 的方法外，还有好多其他方法，看上面我留的 API 文档即可，比如下图：</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/2021-04-14%20at%208.43%20PM.png" alt="" /></p>

<h3 id="例子-2-获取聊天-id">例子 2 获取聊天 ID</h3>

<p>如何获取 chat_id, 然后用这个 ID 通过 API 给自己发送消息</p>

<ul>
<li>Install Telegram,</li>
<li>Create a Bot using the official telegram BotFather (it has a verified symbol next to it when you add it as a contact),</li>
<li>Follow the prompts, and finally copy it’s HTTP API Token,</li>
<li>Create a Group,</li>
<li>Add the Bot to it,</li>
<li>Send the Group at least 1 message.</li>
<li>Use this API <a href="https://api.telegram.org/botXXX:YYYYY/getUpdates" rel="noreferrer" target="_blank">https://api.telegram.org/botXXX:YYYYY/getUpdates</a> to get chat_id</li>
</ul>

<p><code>method</code>: <code>GET</code></p>

<p><code>path</code>: <code>https://api.telegram.org/bot&lt;token&gt;/getUpdates</code></p>

<p>返回值大概是下面的样子（有删减）：</p>

<pre><code class="language-json">{
    &quot;ok&quot;: true,
    &quot;result&quot;: [
        {
            &quot;update_id&quot;: 331805741,
            &quot;message&quot;: {
                &quot;message_id&quot;: 19,
                &quot;from&quot;: {
                    &quot;id&quot;: &quot;732xxx366&quot;,
                    &quot;is_bot&quot;: false,
                    &quot;first_name&quot;: &quot;double flower&quot;,
                    &quot;language_code&quot;: &quot;zh-hans&quot;
                },
                &quot;chat&quot;: {
                    &quot;id&quot;: &quot;732XXX366&quot;,
                    &quot;first_name&quot;: &quot;double flower&quot;,
                    &quot;type&quot;: &quot;private&quot;
                },
                &quot;date&quot;: 1618401351,
                &quot;text&quot;: &quot;just close your eyes&quot;
            }
        },
        ......
    ]
}
</code></pre>

<h3 id="例子-3-http-发送聊天信息">例子 3 HTTP 发送聊天信息</h3>

<p><code>method</code>: <code>POST</code></p>

<p><code>path</code>: <code>https://api.telegram.org/bot&lt;token&gt;/sendMessage</code></p>

<p><code>data</code>:</p>

<pre><code class="language-json">{
    &quot;chat_id&quot;: 702000360,
    &quot;text&quot;: &quot;这是一个测试文档123&quot;
}
</code></pre>

<p>发送后，就会收到你这个 bot 给你发的信息，换成其他的 chat_id 就会发给其他的人</p>

<h2 id="如何跟-alfred-关联起来使用">如何跟 Alfred 关联起来使用</h2>

<p>关联 Alfred 也很简单，我之前写的那个 <a href="http://blog.lierhua.top/post/alfred-workflow-%E4%BD%BF%E7%94%A8/" rel="noreferrer" target="_blank">todo</a> 的 workflow 提到过我每当我有即时想法时为了不打断工作流，就呼出 Alfred 框写下我想要的东西，其实也可以很好的跟电报的 bot 结合起来，直接上例子和脚本</p>

<p><img src="https://raw.githubusercontent.com/LiErhua/cloudpic/master/img3/%E6%88%AA%E5%B1%8F2021-04-15%E4%B8%8A%E5%8D%8811.38.13.png" alt="" /></p>

<p>具体流程就是，我开始用了一个 input，当我呼出 Alfred 之后，输入 <code>lala</code> 这个关键词就会触发这个 workflow，然后空格后面输入想记录的东西，回车后会出发执行后面的 shell 脚本，而后面的脚本做的事情就是把输入的内容发送到我的电报里，当然也可以发送到任何其他人的电报里，只要你的 shell 脚本写好了命令就好</p>

<p>脚本内容如下，其实就是执行放在我电脑上的某个 shell 脚本，其实这里最好是把脚本直接在 Alfred 执行，不然一旦换电脑，路径会发生变化，到时候还要改路径</p>

<pre><code>/Users/lifupeng/Documents/personal/jupiter_quiver/Quiver.todo/sendMsg.sh $1
</code></pre>

<p>sendMsg.sh 的内容</p>

<pre><code>query=$1
export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7891
curl --location --request POST 'https://api.telegram.org/bot[token]/sendMessage' \
                --header 'Content-Type: application/json' \
                --data &quot;{\&quot;chat_id\&quot;: &quot;要发送信息的ID&quot;,\&quot;text\&quot;: \&quot;${query}\&quot;}&quot;
~
</code></pre>

<p>电报需要搭梯子才可以发送，因此我首先设置了 https_proxy 的代理，而具体的代理在我电脑上已经配置了，这块有时间看<a href="http://blog.lierhua.top/post/%E5%85%B3%E4%BA%8E-v2ray-%E4%BD%A0%E5%BA%94%E8%AF%A5%E7%9F%A5%E9%81%93%E7%9A%84/" rel="noreferrer" target="_blank">这里</a></p>

<p>然后，每次我呼出 Alfred，然后输入 <code>lala</code> 输入空格 + 我想记录和发送的内容，回车，我的或者需要收到信息的那个电报用户就能收到我发的信息</p>

<p>当然，这只是一个简单的 demo 演示，具体我们还可以使用 python 脚本或者 PHP 脚本去实现更复杂的逻辑，达到更有意思的工作流，就看生活中的实际场景了。</p>

<h2 id="其他">其他</h2>

<p>之前的想法：</p>

<pre><code>最近打算把电报的 bot 集成到 Alfred 的 workflow 和 iPhone 的快捷指令中去，挖个坑，待填
再引入一个 mq 做异步任务，我觉得可以搞好多事情，正好利用下阿里那台机器，具体可以和什么结合有待思考
</code></pre>

<hr />

<p>一些参考记录：
- <a href="https://sean-bradley.medium.com/get-telegram-chat-id-80b575520659" rel="noreferrer" target="_blank">how to get chat id</a>
- <a href="https://medium.com/@ManHay_Hong/how-to-create-a-telegram-bot-and-send-messages-with-python-4cf314d9fa3e" rel="noreferrer" target="_blank">use python</a>
- <a href="https://stackoverflow.com/questions/57520884/why-curl-requests-to-telegram-bot-api-suddenly-became-very-slow" rel="noreferrer" target="_blank">curl slowly question</a></p>
        ]]>
      </description>
    </item>
    
  </channel>
</rss>
