<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <author>
    <name>rokey</name>
  </author>
  <generator uri="https://hexo.io/">Hexo</generator>
  <id>https://www.rokeyyan.com/</id>
  <link href="https://www.rokeyyan.com/" rel="alternate"/>
  <link href="https://www.rokeyyan.com/atom.xml" rel="self"/>
  <rights>All rights reserved 2026, rokey</rights>
  <subtitle>记录，总结，分享</subtitle>
  <title>rokey.s blog</title>
  <updated>2022-12-03T16:00:00.000Z</updated>
  <entry>
    <author>
      <name>rokey</name>
    </author>
    <category term="笔记" scheme="https://www.rokeyyan.com/categories/%E7%AC%94%E8%AE%B0/"/>
    <category term="笔记" scheme="https://www.rokeyyan.com/tags/%E7%AC%94%E8%AE%B0/"/>
    <content>
      <![CDATA[<p>记录下斐讯N1折腾过程</p><h2 id="救砖刷机"><a href="#救砖刷机" class="headerlink" title="救砖刷机"></a>救砖刷机</h2><p>转转淘来的机器，刷了网心云系统，没办法只能按照救砖的短接线刷方案先刷回原装系统</p><h3 id="步骤"><a href="#步骤" class="headerlink" title="步骤"></a>步骤</h3><ul><li>短接启动线刷模式</li><li>刷入T1系统的启动文件</li><li>输入原生</li><li>启动adb 模式</li><li>启动U盘启动模式</li></ul><h3 id="短接启动线刷模式"><a href="#短接启动线刷模式" class="headerlink" title="短接启动线刷模式"></a>短接启动线刷模式</h3><p>准备工作：</p><ul><li>准备USB 2.0 双公头，注意，一定要是2.0的</li><li>准备一把铁的镊子或者曲别针，注意一定要是铁的</li><li>刷机过程中全程只能使用 USB2.0的线和接口，不然会失败</li></ul><p>1.撕开N1盒子四个脚垫，可以用吹风机吹一会儿，以防老化脚垫被撕烂了。注意可以用手机撬棒从底部第一个栅格凹槽处慢慢撬开盒子<br><img src="/2022/12/04/note/openwrt/n1.webp" alt="高清大图"><br>2.短接触点如下图<br><img src="/2022/12/04/note/openwrt/dj.jpg" alt="短接触点"><br>3.usb 2.0 双公头连接到电脑上，注意连接到盒子上靠近HDMI接口一边的USB口上<br>4.电脑打开 USB_Burning_Tool，点击开始<br>5.镊子短接上图中的触点，最好找个人专门按住触点<br>6.插入盒子电源，一般5s内，USB_Burning_Tool 就会有反应，显示 Hubx-x 已连接成功，<br>7.如果失败或者没反应，这时候可以打开电脑的设备管理器，看下有没有前面带问号的设备，有的话更新下驱动，然后重复 5~6步</p><h3 id="刷入固件"><a href="#刷入固件" class="headerlink" title="刷入固件"></a>刷入固件</h3><p><strong>这一步唯一需要注意就是 擦除flash 和 擦除 BootLoader 这两个选项每一步勾选和不勾选</strong></p><p>1.首先刷入 T1 固件，这一步是为了获取盒子的启动文件，一般刷入过程会卡在 21%，同时这一步需要注意<strong>勾选擦除flash 和 擦除 BootLoader</strong></p><p>2.刷入盒子官方固件，这一步需要注意<strong>去掉勾选擦除flash 和 擦除 BootLoader</strong></p><p>3.此时盒子一定能成功进入系统，除非硬件挂了</p><h3 id="开启-adb-调试"><a href="#开启-adb-调试" class="headerlink" title="开启 adb 调试"></a>开启 adb 调试</h3><p>1.刷机完成后，连接到电视机或者显示器上，进入默认界面后，将键鼠插到盒子上，鼠标点击版本号至少5次，显示开启adb<br>2.使用N1降级工具进行降级，然后启用线刷模式(USB启动)</p><h2 id="刷入openwrt系统"><a href="#刷入openwrt系统" class="headerlink" title="刷入openwrt系统"></a>刷入openwrt系统</h2><h3 id="编译固件"><a href="#编译固件" class="headerlink" title="编译固件"></a>编译固件</h3><p>访问站点<a href="https://supes.top/?version=22.03&amp;target=armvirt/64&amp;id=n1">OpenWrt在线编译</a>，选择好盒子版本，增加默认配置以后直接点击编译，一般5分钟以后就能编译成功，之后点击下载</p><h3 id="烧录到U盘"><a href="#烧录到U盘" class="headerlink" title="烧录到U盘"></a>烧录到U盘</h3><p>1.准备一个2.0的U盘<br>2.下载烧录工具<a href="https://github.com/balena-io/etcher/releases/download/v1.10.2/balenaEtcher-Portable-1.10.2.exe?d_id=1a920bb0-29aa-47a9-b6ed-5597a326d2f1&amp;s_id=1670161765713">balenaEtcher-Prtable</a><br>3.打开烧录工具，选择上一步编译好的固件，选中U盘，点击开始，等待10分钟左右烧录完成</p><h3 id="openwrt刷入盒子"><a href="#openwrt刷入盒子" class="headerlink" title="openwrt刷入盒子"></a>openwrt刷入盒子</h3><p>最好将盒子接入显示器或者电视机，以便观察系统启动情况</p><p>1.盒子断电，插入U盘<br>2.盒子通电，等待U盘系统启动自检完毕<br>3.盒子用网线直连到电脑上，电脑访问 上面在线编译时配置好的ip地址，密码也是在线编译时设置好的，如果没改，默认是 root/password</p><h3 id="将U盘系统写入-emmc"><a href="#将U盘系统写入-emmc" class="headerlink" title="将U盘系统写入 emmc"></a>将U盘系统写入 emmc</h3><p>1.在电脑上打开cmd窗口，输入</p><pre><code>ssh root@盒子ip -A</code></pre><p>回车以后输入密码，等待链接成功</p><p>2.盒子根目录有个 install-to-emmc.sh 的脚本，直接输入</p><pre><code>./install-to-emmc.sh</code></pre><p>回车执行</p><p>3.选中盒子版本号，数字为 11<br>4.选中存储模式，数字为 2</p><p>5.安装完成后，底部会提示你拔掉U盘，断电重启盒子。然后盒子就不用再插U盘启动了</p><h2 id="openclash-adguard-home-smart-dns-配置"><a href="#openclash-adguard-home-smart-dns-配置" class="headerlink" title="openclash + adguard home + smart dns 配置"></a>openclash + adguard home + smart dns 配置</h2><p>这三个插件都涉及到dns相关的配置，需要严格按照相关顺序配置，否则会出现无法访问网站的情况</p><p>我的配置顺序是</p><pre><code>graph LRA(adgurad home) --&gt; B(openclash)--&gt;C(smart dns)    F[dns 请求流向图]</code></pre><h3 id="AdGuard-Home"><a href="#AdGuard-Home" class="headerlink" title="AdGuard Home"></a>AdGuard Home</h3><p>将adgurad作为入口dns，配置如下图<br><img src="/2022/12/04/note/openwrt/adguard.png" alt="adguard home"></p><p>进入手动配置，更改如下项</p><pre><code>  upstream_dns:    - 127.0.0.1:7874</code></pre><p>该配置表示 Adguard Home 的上游DNS服务器地址，此处指向OpenClash 默认的DNS监听端口</p><h3 id="OpenClash"><a href="#OpenClash" class="headerlink" title="OpenClash"></a>OpenClash</h3><p>重点，需要停用OpenClash默认开启的DNS劫持功能，因为该功能已由AdGuard Home 接管了，如果都开启会出错，这也是 AdGuard Home 的手动配置里需要指定上游DNS服务器为 OpenClash的原因</p><p>配置路径：</p><p>openclash主界面=&gt;全局设置=&gt;DNS设置=&gt;去掉本地DNS劫持 勾选</p><p>如图：<br><img src="/2022/12/04/note/openwrt/openclash.png" alt="OpenClash 配置"></p><h4 id="上游dns配置"><a href="#上游dns配置" class="headerlink" title="上游dns配置"></a>上游dns配置</h4><pre><code>config dns_servers    option group 'nameserver'    option ip '127.0.0.1'    option interface 'Disable'    option node_resolve '0'    option specific_group 'Disable'    option type 'tcp'    option enabled '1'    option port '54'config dns_servers    option group 'nameserver'    option type 'udp'    option ip '127.0.0.1'    option interface 'Disable'    option node_resolve '0'    option specific_group 'Disable'    option enabled '1'    option port '54'config dns_servers    option group 'nameserver'    option ip '127.0.0.1'    option type 'tls'    option interface 'Disable'    option node_resolve '0'    option specific_group 'Disable'    option enabled '1'    option port '54'config dns_servers    option group 'nameserver'    option ip '127.0.0.1'    option type 'https'    option interface 'Disable'    option node_resolve '0'    option http3 '0'    option specific_group 'Disable'    option enabled '1'    option port '54'config dns_servers    option enabled '1'    option group 'nameserver'    option ip '127.0.0.1'    option type 'tcp'    option interface 'Disable'    option node_resolve '0'    option specific_group 'Disable'    option port '6554'config dns_servers    option enabled '1'    option group 'nameserver'    option type 'udp'    option ip '127.0.0.1'    option interface 'Disable'    option node_resolve '0'    option specific_group 'Disable'    option port '6554'config dns_servers    option enabled '1'    option group 'nameserver'    option ip '127.0.0.1'    option type 'tls'    option interface 'Disable'    option node_resolve '0'    option specific_group 'Disable'    option port '6554'config dns_servers    option enabled '1'    option group 'nameserver'    option ip '127.0.0.1'    option type 'https'    option interface 'Disable'    option node_resolve '0'    option http3 '0'    option specific_group 'Disable'    option port '6554'config dns_servers    option group 'nameserver'    option type 'udp'    option ip '114.114.114.114'    option enabled '1'config dns_servers    option group 'nameserver'    option type 'udp'    option ip '119.29.29.29'    option enabled '1'config dns_servers    option group 'nameserver'    option type 'udp'    option ip '119.28.28.28'    option enabled '0'config dns_servers    option group 'nameserver'    option type 'udp'    option ip '223.5.5.5'    option enabled '0'config dns_servers    option type 'https'    option ip 'doh.pub/dns-query'    option group 'nameserver'    option enabled '1'config dns_servers    option type 'https'    option ip 'dns.alidns.com/dns-query'    option group 'nameserver'    option enabled '1'config dns_servers    option type 'https'    option group 'fallback'    option ip 'dns.cloudflare.com/dns-query'    option enabled '1'config dns_servers    option group 'fallback'    option ip 'dns.google'    option port '853'    option type 'tls'    option enabled '0'config dns_servers    option group 'fallback'    option type 'https'    option ip '1.1.1.1/dns-query'    option enabled '0'config dns_servers    option group 'fallback'    option ip '1.1.1.1'    option port '853'    option type 'tls'    option enabled '0'config dns_servers    option enabled '0'    option group 'fallback'    option ip '8.8.8.8'    option port '853'    option type 'tls'config dns_servers    option type 'udp'    option group 'fallback'    option ip '2001:4860:4860::8888'    option port '53'    option enabled '0'config dns_servers    option type 'udp'    option group 'fallback'    option ip '2001:4860:4860::8844'    option port '53'    option enabled '0'config dns_servers    option type 'udp'    option group 'fallback'    option ip '2001:da8::666'    option port '53'    option enabled '0'config dns_servers    option group 'fallback'    option type 'https'    option ip 'public.dns.iij.jp/dns-query'    option enabled '1'config dns_servers    option group 'fallback'    option type 'https'    option ip 'jp.tiar.app/dns-query'    option enabled '1'config dns_servers    option group 'fallback'    option type 'https'    option ip 'jp.tiarap.org/dns-query'    option enabled '1'config dns_servers    option group 'fallback'    option ip 'jp.tiar.app'    option type 'tls'    option enabled '0'config dns_servers    option group 'fallback'    option ip 'dot.tiar.app'    option type 'tls'    option enabled '1'</code></pre><h3 id="Smart-DNS"><a href="#Smart-DNS" class="headerlink" title="Smart DNS"></a>Smart DNS</h3><p>重点，SmartDNS 默认使用的是 53 端口，该端口为openwrt默认的主DNS服务端口，此处需要改成其他端口，否则另外两个插件会失效,如图：<br><img src="/2022/12/04/note/openwrt/smartdns.png" alt="smartdns"></p><h4 id="smart-dns-配置"><a href="#smart-dns-配置" class="headerlink" title="smart dns 配置"></a>smart dns 配置</h4><pre><code>config smartdns    option server_name 'smartdns'    option tcp_server '1'    option ipv6_server '1'    option dualstack_ip_selection '1'    option serve_expired '1'    option resolve_local_hostnames '1'    option force_aaaa_soa '0'    option force_https_soa '0'    option rr_ttl_min '600'    option seconddns_tcp_server '1'    option seconddns_no_speed_check '0'    option seconddns_no_rule_addr '0'    option seconddns_no_rule_nameserver '0'    option seconddns_no_rule_ipset '0'    option seconddns_no_rule_soa '0'    option seconddns_no_dualstack_selection '0'    option seconddns_no_cache '0'    option seconddns_force_aaaa_soa '0'    option coredump '0'    option prefetch_domain '1'    option auto_set_dnsmasq '0'    option enabled '1'    option seconddns_enabled '1'    option port '54'    option seconddns_port '6554'    option old_port '54'    option old_enabled '1'    option old_auto_set_dnsmasq '0'config server    option enabled '1'    option type 'udp'    option name '114 DNS'    option ip '114.114.114.114'config server    option enabled '1'    option type 'udp'    option name '114 DNS'    option ip '114.114.115.115'config server    option enabled '1'    option type 'udp'    option name '阿里AliDNS'    option ip '223.5.5.5'config server    option enabled '1'    option type 'udp'    option name '阿里AliDNS'    option ip '223.6.6.6'config server    option enabled '1'    option type 'udp'    option name '百度 BaiduDNS'    option ip '180.76.76.76'config server    option enabled '1'    option type 'udp'    option name 'DNSPod DNS+'    option ip '119.29.29.29'config server    option enabled '1'    option type 'udp'    option name 'DNSPod DNS+'    option ip '119.29.29.29'config server    option enabled '1'    option type 'udp'    option name 'CNNIC SDNS'    option ip '1.2.4.8'config server    option enabled '1'    option type 'udp'    option name 'CNNIC SDNS'    option ip '210.2.4.8'config server    option enabled '1'    option type 'udp'    option name 'oneDNS'    option ip '117.50.11.11'config server    option enabled '1'    option type 'udp'    option name 'oneDNS'    option ip '52.80.66.66'config server    option enabled '1'    option type 'udp'    option name 'DNS 派 电信/移动/铁通'    option ip '101.226.4.6'config server    option enabled '1'    option type 'udp'    option name 'DNS 派 电信/移动/铁通'    option ip '218.30.118.6'config server    option enabled '1'    option type 'udp'    option name 'DNS 派 联通'    option ip '123.125.81.6'config server    option enabled '1'    option type 'udp'    option name 'DNS 派 联通'    option ip '140.207.198.6'config server    option enabled '1'    option type 'udp'    option name 'Google DNS'    option ip '8.8.8.8'config server    option enabled '1'    option type 'udp'    option name 'Google DNS'    option ip '8.8.4.4'config server    option enabled '1'    option type 'udp'    option name 'IBM Quad9'    option ip '9.9.9.9'config server    option enabled '1'    option type 'udp'    option name 'OpenDNS'    option ip '208.67.222.222'config server    option enabled '1'    option type 'udp'    option name 'OpenDNS'    option ip '208.67.220.220'config server    option enabled '1'    option type 'udp'    option name 'V2EX DNS'    option ip '199.91.73.222'config server    option enabled '1'    option type 'udp'    option name 'V2EX DNS'    option ip '178.79.131.110'config server    option enabled '1'    option type 'udp'    option name '上海电信 DNS'    option ip '202.96.209.133'config server    option enabled '1'    option type 'udp'    option name '上海电信 DNS'    option ip '116.228.111.118'config server    option enabled '1'    option type 'udp'    option ip '202.96.209.5'    option name '上海电信 DNS'config server    option enabled '1'    option type 'udp'    option name '上海电信 DNS'    option ip '180.168.255.118'config server    option enabled '1'    option type 'udp'    option name '上海联通 DNS'    option ip '210.22.70.3'config server    option enabled '1'    option type 'udp'    option name '上海联通 DNS'    option ip '210.22.84.3'config server    option enabled '1'    option type 'udp'    option name '江苏移动 DNS'    option ip '221.131.143.69'config server    option enabled '1'    option type 'udp'    option name '江苏移动 DNS'    option ip '112.4.0.55'config server    option enabled '1'    option type 'tcp'    option name '114 DNS'    option ip '114.114.114.114'config server    option enabled '1'    option type 'tcp'    option name '114 DNS'    option ip '114.114.115.115'config server    option enabled '1'    option type 'tcp'    option name '阿里AliDNS'    option ip '223.5.5.5'config server    option enabled '1'    option type 'tcp'    option name '阿里AliDNS'    option ip '223.6.6.6'config server    option enabled '1'    option type 'tcp'    option name '百度 BaiduDNS'    option ip '180.76.76.76'config server    option enabled '1'    option type 'tcp'    option name 'DNSPod DNS+'    option ip '119.29.29.29'config server    option enabled '1'    option type 'tcp'    option name 'DNSPod DNS+'    option ip '119.29.29.29'config server    option enabled '1'    option type 'tcp'    option name 'CNNIC SDNS'    option ip '1.2.4.8'config server    option enabled '1'    option type 'tcp'    option name 'CNNIC SDNS'    option ip '210.2.4.8'config server    option enabled '1'    option type 'tcp'    option name 'oneDNS'    option ip '117.50.11.11'config server    option enabled '1'    option type 'tcp'    option name 'oneDNS'    option ip '52.80.66.66'config server    option enabled '1'    option type 'tcp'    option name 'DNS 派 电信/移动/铁通'    option ip '101.226.4.6'config server    option enabled '1'    option type 'tcp'    option name 'DNS 派 电信/移动/铁通'    option ip '218.30.118.6'config server    option enabled '1'    option type 'tcp'    option name 'DNS 派 联通'    option ip '123.125.81.6'config server    option enabled '1'    option type 'tcp'    option name 'DNS 派 联通'    option ip '140.207.198.6'config server    option enabled '1'    option type 'tcp'    option name 'Google DNS'    option ip '8.8.8.8'config server    option enabled '1'    option type 'tcp'    option name 'Google DNS'    option ip '8.8.4.4'config server    option enabled '1'    option type 'tcp'    option name 'IBM Quad9'    option ip '9.9.9.9'config server    option enabled '1'    option type 'tcp'    option name 'OpenDNS'    option ip '208.67.222.222'config server    option enabled '1'    option type 'tcp'    option name 'OpenDNS'    option ip '208.67.220.220'config server    option enabled '1'    option type 'tcp'    option name 'V2EX DNS'    option ip '199.91.73.222'config server    option enabled '1'    option type 'tcp'    option name 'V2EX DNS'    option ip '178.79.131.110'config server    option enabled '1'    option type 'tcp'    option name '上海电信 DNS'    option ip '202.96.209.133'config server    option enabled '1'    option type 'tcp'    option name '上海电信 DNS'    option ip '116.228.111.118'config server    option enabled '1'    option type 'tcp'    option ip '202.96.209.5'    option name '上海电信 DNS'config server    option enabled '1'    option type 'tcp'    option name '上海电信 DNS'    option ip '180.168.255.118'config server    option enabled '1'    option type 'tcp'    option name '上海联通 DNS'    option ip '210.22.70.3'config server    option enabled '1'    option type 'tcp'    option name '上海联通 DNS'    option ip '210.22.84.3'config server    option enabled '1'    option type 'tcp'    option name '江苏移动 DNS'    option ip '221.131.143.69'config server    option enabled '1'    option type 'tcp'    option name '江苏移动 DNS'    option ip '112.4.0.55'config server    option enabled '1'    option type 'tls'    option name '114 DNS'    option ip '114.114.114.114'config server    option enabled '1'    option type 'tls'    option name '114 DNS'    option ip '114.114.115.115'config server    option enabled '1'    option type 'tls'    option name '阿里AliDNS'    option ip '223.5.5.5'config server    option enabled '1'    option type 'tls'    option name '阿里AliDNS'    option ip '223.6.6.6'config server    option enabled '1'    option type 'tls'    option name '百度 BaiduDNS'    option ip '180.76.76.76'config server    option enabled '1'    option type 'tls'    option name 'DNSPod DNS+'    option ip '119.29.29.29'config server    option enabled '1'    option type 'tls'    option name 'DNSPod DNS+'    option ip '119.29.29.29'config server    option enabled '1'    option type 'tls'    option name 'CNNIC SDNS'    option ip '1.2.4.8'config server    option enabled '1'    option type 'tls'    option name 'CNNIC SDNS'    option ip '210.2.4.8'config server    option enabled '1'    option type 'tls'    option name 'oneDNS'    option ip '117.50.11.11'config server    option enabled '1'    option type 'tls'    option name 'oneDNS'    option ip '52.80.66.66'config server    option enabled '1'    option type 'tls'    option name 'DNS 派 电信/移动/铁通'    option ip '101.226.4.6'config server    option enabled '1'    option type 'tls'    option name 'DNS 派 电信/移动/铁通'    option ip '218.30.118.6'config server    option enabled '1'    option type 'tls'    option name 'DNS 派 联通'    option ip '123.125.81.6'config server    option enabled '1'    option type 'tls'    option name 'DNS 派 联通'    option ip '140.207.198.6'config server    option enabled '1'    option type 'tls'    option name 'Google DNS'    option ip '8.8.8.8'config server    option enabled '1'    option type 'tls'    option name 'Google DNS'    option ip '8.8.4.4'config server    option enabled '1'    option type 'tls'    option name 'IBM Quad9'    option ip '9.9.9.9'config server    option enabled '1'    option type 'tls'    option name 'OpenDNS'    option ip '208.67.222.222'config server    option enabled '1'    option type 'tls'    option name 'OpenDNS'    option ip '208.67.220.220'config server    option enabled '1'    option type 'tls'    option name 'V2EX DNS'    option ip '199.91.73.222'config server    option enabled '1'    option type 'tls'    option name 'V2EX DNS'    option ip '178.79.131.110'config server    option enabled '1'    option type 'tls'    option name '上海电信 DNS'    option ip '202.96.209.133'config server    option enabled '1'    option type 'tls'    option name '上海电信 DNS'    option ip '116.228.111.118'config server    option enabled '1'    option type 'tls'    option ip '202.96.209.5'    option name '上海电信 DNS'config server    option enabled '1'    option type 'tls'    option name '上海电信 DNS'    option ip '180.168.255.118'config server    option enabled '1'    option type 'tls'    option name '上海联通 DNS'    option ip '210.22.70.3'config server    option enabled '1'    option type 'tls'    option name '上海联通 DNS'    option ip '210.22.84.3'config server    option enabled '1'    option type 'tls'    option name '江苏移动 DNS'    option ip '221.131.143.69'config server    option enabled '1'    option type 'tls'    option name '江苏移动 DNS'    option ip '112.4.0.55'config server    option enabled '1'    option type 'https'    option name '114 DNS'    option ip '114.114.114.114'config server    option enabled '1'    option type 'https'    option name '114 DNS'    option ip '114.114.115.115'config server    option enabled '1'    option type 'https'    option name '阿里AliDNS'    option ip '223.5.5.5'config server    option enabled '1'    option type 'https'    option name '阿里AliDNS'    option ip '223.6.6.6'config server    option enabled '1'    option type 'https'    option name '百度 BaiduDNS'    option ip '180.76.76.76'config server    option enabled '1'    option type 'https'    option name 'DNSPod DNS+'    option ip '119.29.29.29'config server    option enabled '1'    option type 'https'    option name 'DNSPod DNS+'    option ip '119.29.29.29'config server    option enabled '1'    option type 'https'    option name 'CNNIC SDNS'    option ip '1.2.4.8'config server    option enabled '1'    option type 'https'    option name 'CNNIC SDNS'    option ip '210.2.4.8'config server    option enabled '1'    option type 'https'    option name 'oneDNS'    option ip '117.50.11.11'config server    option enabled '1'    option type 'https'    option name 'oneDNS'    option ip '52.80.66.66'config server    option enabled '1'    option type 'https'    option name 'DNS 派 电信/移动/铁通'    option ip '101.226.4.6'config server    option enabled '1'    option type 'https'    option name 'DNS 派 电信/移动/铁通'    option ip '218.30.118.6'config server    option enabled '1'    option type 'https'    option name 'DNS 派 联通'    option ip '123.125.81.6'config server    option enabled '1'    option type 'https'    option name 'DNS 派 联通'    option ip '140.207.198.6'config server    option enabled '1'    option type 'https'    option name 'Google DNS'    option ip '8.8.8.8'config server    option enabled '1'    option type 'https'    option name 'Google DNS'    option ip '8.8.4.4'config server    option enabled '1'    option type 'https'    option name 'IBM Quad9'    option ip '9.9.9.9'config server    option enabled '1'    option type 'https'    option name 'OpenDNS'    option ip '208.67.222.222'config server    option enabled '1'    option type 'https'    option name 'OpenDNS'    option ip '208.67.220.220'config server    option enabled '1'    option type 'https'    option name 'V2EX DNS'    option ip '199.91.73.222'config server    option enabled '1'    option type 'https'    option name 'V2EX DNS'    option ip '178.79.131.110'config server    option enabled '1'    option type 'https'    option name '上海电信 DNS'    option ip '202.96.209.133'config server    option enabled '1'    option type 'https'    option name '上海电信 DNS'    option ip '116.228.111.118'config server    option enabled '1'    option type 'https'    option ip '202.96.209.5'    option name '上海电信 DNS'config server    option enabled '1'    option type 'https'    option name '上海电信 DNS'    option ip '180.168.255.118'config server    option enabled '1'    option type 'https'    option name '上海联通 DNS'    option ip '210.22.70.3'config server    option enabled '1'    option type 'https'    option name '上海联通 DNS'    option ip '210.22.84.3'config server    option enabled '1'    option type 'https'    option name '江苏移动 DNS'    option ip '221.131.143.69'config server    option enabled '1'    option type 'https'    option name '江苏移动 DNS'    option ip '112.4.0.55'config server    option enabled '1'    option type 'udp'    option name '本地DNS'    option ip '15.192.252.188'config server    option enabled '1'    option type 'udp'    option name '本地DNS'    option ip '15.192.251.188'config server    option enabled '1'    option type 'tcp'    option name '本地DNS'    option ip '15.192.252.188'config server    option enabled '1'    option type 'tcp'    option name '本地DNS'    option ip '15.192.251.188'config server    option enabled '1'    option type 'tls'    option name '本地DNS'    option ip '15.192.252.188'config server    option enabled '1'    option type 'tls'    option name '本地DNS'    option ip '15.192.251.188'config server    option enabled '1'    option type 'https'    option name '本地DNS'    option ip '15.192.252.188'config server    option enabled '1'    option type 'https'    option name '本地DNS'    option ip '15.192.251.188'</code></pre>]]>
    </content>
    <id>https://www.rokeyyan.com/2022/12/03/2022-12-04-openwrt/</id>
    <link href="https://www.rokeyyan.com/2022/12/03/2022-12-04-openwrt/"/>
    <published>2022-12-03T16:00:00.000Z</published>
    <summary>
      <![CDATA[<p>记录下斐讯N1折腾过程</p>
<h2 id="救砖刷机"><a href="#救砖刷机" class="headerlink" title="救砖刷机"></a>救砖刷机</h2><p>转转淘来的机器，刷了网心云系统，没办法只能按照救砖的短接线刷方案先刷回原装系统</p>]]>
    </summary>
    <title>openwrt</title>
    <updated>2022-12-03T16:00:00.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>rokey</name>
    </author>
    <category term="笔记" scheme="https://www.rokeyyan.com/categories/%E7%AC%94%E8%AE%B0/"/>
    <category term="笔记" scheme="https://www.rokeyyan.com/tags/%E7%AC%94%E8%AE%B0/"/>
    <content>
      <![CDATA[<p>大怨种如我买了AX6000，要啥啥没有，装啥啥不行，拿个SSH权限也是千难万难，此处记录下实现步骤</p><h2 id="环境"><a href="#环境" class="headerlink" title="环境"></a>环境</h2><ul><li>AX6000 路由器</li><li>vmware<br>用来安装模拟openwrt系统，作为破解中继路由器</li><li>手机一台或2台笔记本电脑<br>主要是其中一台电脑模拟openwrt，另一台设备用来访问这台模拟出来的openwrt路由器</li></ul><h2 id="资料"><a href="#资料" class="headerlink" title="资料"></a>资料</h2><p>链接：<a href="https://share.weiyun.com/v2Bj59od">https://share.weiyun.com/v2Bj59od</a> 密码：s3bdfp</p><h2 id="步骤"><a href="#步骤" class="headerlink" title="步骤"></a>步骤</h2><p>此处将安装虚拟OpenWrt系统的笔记本称为A，另一台笔记本称为B专门用来设置OpenWrt网络信息</p><h3 id="1-虚拟-openwrt-系统安装"><a href="#1-虚拟-openwrt-系统安装" class="headerlink" title="1.虚拟 openwrt 系统安装"></a>1.虚拟 openwrt 系统安装</h3><p>安装vmware，软件破解密钥自行百度</p><p>设置vmware的网络信息，将桥接模式下的网卡变更为A笔记本所属热点的虚拟网卡</p><p>修改openwrt所在虚拟系统的网卡设置，选择桥接模式，并选中 vmware 0</p><p>以上步骤就相当于为虚拟路由绑定了一块物理无线网卡，为后续设置网络环境做准备</p><h3 id="2-设置本机及虚拟机网络环境"><a href="#2-设置本机及虚拟机网络环境" class="headerlink" title="2.设置本机及虚拟机网络环境"></a>2.设置本机及虚拟机网络环境</h3><ul><li>第一步，开启本机热点，并设置热点信息为 OpenWrt/12345678</li><li>第二步，设置热点所属的虚拟网卡固定ip为 192.168.5.2/255.255.255.0</li><li>第三步，B笔记本链接OpenWrt热点，并将Wlan网卡的IP设置为静态IP 192.168.5.5/255.255.255.0</li><li>第四步，B笔记本浏览器访问 192.168.5.1，用户名：root 密码：password</li><li>第五步，进入openwrt的管理界面后，设置lan口ip为169.254.31.1</li><li>第六步，往下拉，高级设置，去掉勾选 DHCP的相关选项，基本设置，去掉 DHCP 勾选</li><li>第七步，以上步骤设置完毕后，B笔记本无法再访问openwrt系统，因为openwrt的IP已经变成了 169.254.31.1，此时我们需要重复2，3步，将IP替换为 169.254.31开头即可，再次访问169.254.31.1 就又能访问openwrt了</li><li>第八步 WinSCP上传“xqsystem.lua”到OpenWrt的目录：/usr/lib/lua/luci/controller/admin/，ip 169.254.31.1,帐号/密码：root/password</li><li>上传完毕后，移除A笔记本热点所属虚拟网卡的IPV4设置，直接去掉勾选即可</li></ul><p>以上步骤其实主要是在配置破解ax6000ssh需要用到的中继路由环境，一旦环境配置完成，后续破解就只需要一条命令即可</p><h3 id="3-AX6000-降级"><a href="#3-AX6000-降级" class="headerlink" title="3.AX6000 降级"></a>3.AX6000 降级</h3><p>只有固定的几个路由器固件版本存在能开ssh的后面，具体见共享资料</p><h4 id="固件降级"><a href="#固件降级" class="headerlink" title="固件降级"></a>固件降级</h4><p>常用设置=》系统状态=》手动升级=》选中固件=》等待重启</p><h4 id="执行破解命令"><a href="#执行破解命令" class="headerlink" title="执行破解命令"></a>执行破解命令</h4><pre><code>http://192.168.31.1/cgi-bin/luci/;stok=你的小米路由器stok/api/xqsystem/extendwifi_connect_inited_router?ssid=OpenWrt&amp;password=12345678&amp;encryption=WPA2PSKenctype=CCMP&amp;channel=1&amp;band=2g&amp;admin_username=root&amp;admin_password=admin&amp;admin_nonce=xxx</code></pre><p>stok值可以通过 192.168.1.31 进入小米路由器管理后台后，从浏览器地址输入栏中找到(PS:该值每次进入路由器后台后会变)</p><p>执行完毕后，会返回 {……,”code”:0},此时表示ssh，开启成功</p><h4 id="获取默认root登录密码"><a href="#获取默认root登录密码" class="headerlink" title="获取默认root登录密码"></a>获取默认root登录密码</h4><p>密码主要由路由器的sn编号计算得出，sn编号可以从路由器底部铭牌或路由器管理后台首页的右下角看到</p><h3 id="永久开启ssh"><a href="#永久开启ssh" class="headerlink" title="永久开启ssh"></a>永久开启ssh</h3><p>主要通过脚本实现，期间会重启多次，需要反复上传脚本至 路由器 /tmp 目录</p><h4 id="备份"><a href="#备份" class="headerlink" title="备份"></a>备份</h4><pre><code>cat /proc/mtd | grep bdata</code></pre><p>根据返回的结果判定bdata分区所在，比如mtd9</p><p>之后运行如下命令，注意将/dev/mtd9中的mtd9换成你实际查看到的mtd分区名</p><pre><code>nanddump -f /tmp/bdata.img /dev/mtd9</code></pre><p>运行成功后用winscp下载到电脑上备份好（以防万一）</p><p>执行脚本，注意每次执行前都需要通过scp将mitool目录上传至路由器 /tmp 目录</p><ul><li><p>首次，上传mitool</p><p>chmod +x /tmp/mitool/* &amp;&amp; /tmp/mitool/mitool.sh unlock</p></li><li><p>第二次，上传mitool</p><p>chmod +x /tmp/mitool/* &amp;&amp; /tmp/mitool/mitool.sh sn &amp;&amp; /tmp/mitool/mitool.sh hack</p></li><li><p>第三次，上传mitool</p><p>chmod +x /tmp/mitool/* &amp;&amp; /tmp/mitool/mitool.sh lock</p></li></ul><p>如升级后ssh被禁用可以用telnet登录，执行下面代码再次启用ssh</p><pre><code>sed -i 's/channel=.*/channel="debug"/g' /etc/init.d/dropbear /etc/init.d/dropbear start</code></pre><p>至此基本可以保证机器长期拥有root权限</p><p>其他：<br>如遇SN号丢失，可以重新上传文件夹后使用以下命令还原</p><pre><code>chmod +x /tmp/mitool/mitool.sh &amp;&amp; /tmp/mitool/mitool.sh setsn xxxxxx #将此次内容替换为之前记录的sn号</code></pre><p>如需恢复bdata分区，可以使用以下命令恢复</p><pre><code>mtd write /tmp/bdata.img bdata #注意将文件名bdata.img替换为你实际备份的文件名</code></pre>]]>
    </content>
    <id>https://www.rokeyyan.com/2022/10/05/2022-10-06-ax6000-get-ssh-permission/</id>
    <link href="https://www.rokeyyan.com/2022/10/05/2022-10-06-ax6000-get-ssh-permission/"/>
    <published>2022-10-05T16:00:00.000Z</published>
    <summary>
      <![CDATA[<p>大怨种如我买了AX6000，要啥啥没有，装啥啥不行，拿个SSH权限也是千难万难，此处记录下实现步骤</p>
<h2 id="环境"><a href="#环境" class="headerlink" title="环境"></a>环境</h2><ul>
<li>AX6000]]>
    </summary>
    <title>小米AX6000 获取SSH权限</title>
    <updated>2022-10-05T16:00:00.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>rokey</name>
    </author>
    <category term="笔记" scheme="https://www.rokeyyan.com/categories/%E7%AC%94%E8%AE%B0/"/>
    <category term="笔记" scheme="https://www.rokeyyan.com/tags/%E7%AC%94%E8%AE%B0/"/>
    <content>
      <![CDATA[<h2 id="dapr-入门"><a href="#dapr-入门" class="headerlink" title="dapr 入门"></a>dapr 入门</h2><h3 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h3><h4 id="在线安装脚本"><a href="#在线安装脚本" class="headerlink" title="在线安装脚本"></a>在线安装脚本</h4><pre><code>wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash</code></pre><h4 id="完成初始化"><a href="#完成初始化" class="headerlink" title="完成初始化"></a>完成初始化</h4><pre><code>dapr init</code></pre><h4 id="离线"><a href="#离线" class="headerlink" title="离线"></a>离线</h4><ul><li><p>下载离线安装包，<a href="https://github.com/dapr/installer-bundle/releases">installer-bundle</a></p></li><li><p>解压安装包</p><p>tar -xvf xxxx.tar.gz</p></li><li><p>执行离线初始化安装命令，</p><p>dapr init –from-dir installer-bundle文件解压目录</p></li></ul><h4 id="启用控制面板"><a href="#启用控制面板" class="headerlink" title="启用控制面板"></a>启用控制面板</h4><pre><code>dapr dashboard</code></pre>]]>
    </content>
    <id>https://www.rokeyyan.com/2022/07/16/2022-07-17-dapr-03/</id>
    <link href="https://www.rokeyyan.com/2022/07/16/2022-07-17-dapr-03/"/>
    <published>2022-07-16T16:00:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="dapr-入门"><a href="#dapr-入门" class="headerlink" title="dapr 入门"></a>dapr 入门</h2><h3 id="安装"><a href="#安装" class="headerlink" title="安]]>
    </summary>
    <title>dapr-03</title>
    <updated>2022-07-16T16:00:00.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>rokey</name>
    </author>
    <category term="笔记" scheme="https://www.rokeyyan.com/categories/%E7%AC%94%E8%AE%B0/"/>
    <category term="笔记" scheme="https://www.rokeyyan.com/tags/%E7%AC%94%E8%AE%B0/"/>
    <content>
      <![CDATA[<h2 id="kubectl"><a href="#kubectl" class="headerlink" title="kubectl"></a>kubectl</h2><h3 id="脚本安装"><a href="#脚本安装" class="headerlink" title="脚本安装"></a>脚本安装</h3><pre><code>curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"</code></pre><p>说明：<br>如需下载某个指定的版本，请用指定版本号替换该命令的这一部分： $(curl -L -s <a href="https://dl.k8s.io/release/stable.txt)%E3%80%82">https://dl.k8s.io/release/stable.txt)。</a><br>例如，要在 Linux 中下载 v1.24.0 版本，请输入：</p><pre><code>curl -LO https://dl.k8s.io/release/v1.24.0/bin/linux/amd64/kubectl</code></pre><h3 id="安装-kubectl"><a href="#安装-kubectl" class="headerlink" title="安装 kubectl"></a>安装 kubectl</h3><pre><code>sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl</code></pre><p>说明：<br>即使你没有目标系统的 root 权限，仍然可以将 kubectl 安装到目录 ~/.local/bin 中：</p><pre><code>chmod +x kubectlmkdir -p ~/.local/binmv ./kubectl ~/.local/bin/kubectl# 之后将 ~/.local/bin 附加（或前置）到 $PATH</code></pre><h3 id="执行测试，以保障你安装的版本是最新的"><a href="#执行测试，以保障你安装的版本是最新的" class="headerlink" title="执行测试，以保障你安装的版本是最新的:"></a>执行测试，以保障你安装的版本是最新的:</h3><pre><code>kubectl version --client</code></pre><p>或者使用如下命令来查看版本的详细信息：</p><pre><code>kubectl version --client --output=yaml</code></pre>]]>
    </content>
    <id>https://www.rokeyyan.com/2022/07/16/2022-07-17-k8s-01/</id>
    <link href="https://www.rokeyyan.com/2022/07/16/2022-07-17-k8s-01/"/>
    <published>2022-07-16T16:00:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="kubectl"><a href="#kubectl" class="headerlink" title="kubectl"></a>kubectl</h2><h3 id="脚本安装"><a href="#脚本安装" class="headerlink" titl]]>
    </summary>
    <title>k8s-01</title>
    <updated>2022-07-16T16:00:00.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>rokey</name>
    </author>
    <category term="笔记" scheme="https://www.rokeyyan.com/categories/%E7%AC%94%E8%AE%B0/"/>
    <category term="笔记" scheme="https://www.rokeyyan.com/tags/%E7%AC%94%E8%AE%B0/"/>
    <content>
      <![CDATA[<h2 id="基本操作命令"><a href="#基本操作命令" class="headerlink" title="基本操作命令"></a>基本操作命令</h2><h3 id="服务"><a href="#服务" class="headerlink" title="服务"></a>服务</h3><pre><code>service 服务名 [start|stop|restart|status]</code></pre><h3 id="服务自动启动"><a href="#服务自动启动" class="headerlink" title="服务自动启动"></a>服务自动启动</h3><pre><code>update-rc.d 服务名 enable</code></pre>]]>
    </content>
    <id>https://www.rokeyyan.com/2022/07/16/2022-07-17-ubuntu-use-01/</id>
    <link href="https://www.rokeyyan.com/2022/07/16/2022-07-17-ubuntu-use-01/"/>
    <published>2022-07-16T16:00:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="基本操作命令"><a href="#基本操作命令" class="headerlink" title="基本操作命令"></a>基本操作命令</h2><h3 id="服务"><a href="#服务" class="headerlink" title="服务"><]]>
    </summary>
    <title>Ubuntu 使用</title>
    <updated>2022-07-16T16:00:00.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>rokey</name>
    </author>
    <category term="笔记" scheme="https://www.rokeyyan.com/categories/%E7%AC%94%E8%AE%B0/"/>
    <category term="笔记" scheme="https://www.rokeyyan.com/tags/%E7%AC%94%E8%AE%B0/"/>
    <content>
      <![CDATA[<h2 id="wsl设置全局代理"><a href="#wsl设置全局代理" class="headerlink" title="wsl设置全局代理"></a>wsl设置全局代理</h2><h3 id="自动设置代理"><a href="#自动设置代理" class="headerlink" title="自动设置代理"></a>自动设置代理</h3><h4 id="自动化脚本"><a href="#自动化脚本" class="headerlink" title="自动化脚本"></a>自动化脚本</h4><pre><code>#!/bin/sh#hostip=$(cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }')hostip=192.168.50.2wslip=$(hostname -I | awk '{print $1}')port=30003PROXY_HTTP="http://${hostip}:${port}"set_proxy(){    export http_proxy="${PROXY_HTTP}"    export HTTP_PROXY="${PROXY_HTTP}"    export https_proxy="${PROXY_HTTP}"    export HTTPS_proxy="${PROXY_HTTP}"}unset_proxy(){    unset http_proxy    unset HTTP_PROXY    unset https_proxy    unset HTTPS_PROXY}test_setting(){    echo "Host ip:" ${hostip}    echo "WSL ip:" ${wslip}    echo "Current proxy:" $https_proxy}if [ "$1" = "set" ]then    set_proxyelif [ "$1" = "unset" ]then    unset_proxyelif [ "$1" = "test" ]then    test_settingelse    echo "Unsupported arguments."fi</code></pre><h4 id="启动脚本"><a href="#启动脚本" class="headerlink" title="启动脚本"></a>启动脚本</h4><pre><code>. ./proxy.sh set</code></pre><p>运行的时候不要忘记之前的 .，或者使用 source ./proxy.sh set，只有这样才能够修改环境变量<br>直接运行例如 ./proxy.sh set 或者 sh proxy.sh set，这样会是运行在一个子 shell 中，对当前 shell 没有效果</p><h4 id="可以对脚本设置别名"><a href="#可以对脚本设置别名" class="headerlink" title="可以对脚本设置别名"></a>可以对脚本设置别名</h4><pre><code>alias proxy="source /path/to/proxy.sh". /path/to/proxy.sh set</code></pre>]]>
    </content>
    <id>https://www.rokeyyan.com/2022/07/16/2022-07-17-wsl-use-01/</id>
    <link href="https://www.rokeyyan.com/2022/07/16/2022-07-17-wsl-use-01/"/>
    <published>2022-07-16T16:00:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="wsl设置全局代理"><a href="#wsl设置全局代理" class="headerlink" title="wsl设置全局代理"></a>wsl设置全局代理</h2><h3 id="自动设置代理"><a href="#自动设置代理" class="head]]>
    </summary>
    <title>Wsl使用-01</title>
    <updated>2022-07-16T16:00:00.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>rokey</name>
    </author>
    <category term="笔记" scheme="https://www.rokeyyan.com/categories/%E7%AC%94%E8%AE%B0/"/>
    <category term="笔记" scheme="https://www.rokeyyan.com/tags/%E7%AC%94%E8%AE%B0/"/>
    <content>
      <![CDATA[<h2 id="概述"><a href="#概述" class="headerlink" title="概述"></a>概述</h2><h3 id="分布式应用程序运行时介绍"><a href="#分布式应用程序运行时介绍" class="headerlink" title="分布式应用程序运行时介绍"></a>分布式应用程序运行时介绍</h3><p>Dapr 是一个可移植的、事件驱动的运行时，它使任何开发人员能够轻松构建出弹性的、无状态和有状态的应用程序，并可运行在云平台或边缘计算中，它同时也支持多种编程语言和开发框架。</p><h3 id="任何语言，任何框架，任何地方"><a href="#任何语言，任何框架，任何地方" class="headerlink" title="任何语言，任何框架，任何地方"></a>任何语言，任何框架，任何地方</h3><p><img src="/2022/06/05/note/dapr-01/overview.png" alt="dapr"></p><p>如今，我们正经历着上云浪潮。 开发人员习惯于 Web + 数据库应用架构(例如经典 3 层设计)，但对天然支持分布式的微服务应用架构却感觉陌生。 成为分布式系统专家很难，并且你也不需要这么做。 开发人员希望专注于业务逻辑，同时希望平台为其提供可伸缩的、弹性的、可维护的和云原生架构的其他功能。</p><p>这就是Dapr所要解决的。 Dapr 将构建微服务应用的 最佳实践 设计成开放、独立和模块化的方式，让你能够使用任意的开发语言和框架构建可移植的应用程序。 每个构建块都是完全独立的，您可以采用其中一个、多个或全部来构建你的应用。</p><p>此外，Dapr 是和平台无关的，这意味着您可以在本地、Kubernetes 集群或者其它集成 Dapr 的托管环境中运行应用程序。 这使得您能够在云平台和边缘计算中运行微服务应用。</p><p>使用 Dapr，您可以使用任何语言、框架轻松构建微服务应用，运行在任何地方。</p><h3 id="云平台和边缘计算的微服务构建块"><a href="#云平台和边缘计算的微服务构建块" class="headerlink" title="云平台和边缘计算的微服务构建块"></a>云平台和边缘计算的微服务构建块</h3><p><img src="/2022/06/05/note/dapr-01/building_blocks.png" alt=" "></p><p>在设计微服务应用时，需要考虑很多因素。 Dapr提供了一些常用功能的最佳实践，开发人员可以使用标准模式进行微服务应用的构建，并部署到任意环境中。 Dapr 通过提供分布式构建块来实现此目的。</p><p>每个构建块都是独立的，这意味着您可以采用其中一个、多个或全部来构建应用。 目前，可用的构建块如下：</p><table><thead><tr><th>构建块</th><th>说明</th></tr></thead><tbody><tr><td>服务调用</td><td>跨服务调用允许进行远程方法调用(包括重试)，不管处于任何位置，只需该服务托管于受支持的环境即可。</td></tr><tr><td>状态管理</td><td>独立的状态管理，使用键/值对作为存储机制，可以轻松的使长时运行、高可用的有状态服务和无状态服务共同运行在您的应用程序中。 状态存储是可插拔的，目前支持使用Azure CosmosDB、 Azure SQL Server、 PostgreSQL,、AWS DynamoDB、Redis 作为状态存储介质。</td></tr><tr><td>发布订阅</td><td>发布事件和订阅主题。</td></tr><tr><td>资源绑定</td><td>Dapr的Bindings是建立在事件驱动架构的基础之上的。通过建立触发器与资源的绑定，可以从任何外部源（例如数据库，队列，文件系统等）接收和发送事件，而无需借助消息队列，即可实现灵活的业务场景。</td></tr><tr><td>Actors</td><td>Actor模型 = 状态 + 行为 + 消息。一个应用/服务由多个Actor组成，每个Actor都是一个独立的运行单元，拥有隔离的运行空间，在隔离的空间内，其有独立的状态和行为，不被外界干预，Actor之间通过消息进行交互，而同一时刻，每个Actor只能被单个线程执行，这样既有效避免了数据共享和并发问题，又确保了应用的伸缩性。 Dapr 在Actor模式中提供了很多功能，包括并发，状态管理，用于 actor 激活/停用的生命周期管理，以及唤醒 actor 的计时器和提醒器。</td></tr><tr><td>可观测性</td><td>Dapr记录指标，日志，链路以调试和监视Dapr和用户应用的运行状况。 Dapr支持分布式跟踪，其使用W3C跟踪上下文标准和开放式遥测技术，可以轻松地诊断在生产环境中服务间的网络调用，并发送到不同的监视工具。</td></tr><tr><td>安全</td><td>Dapr 提供了密钥管理，支持与公有云和本地的Secret存储集成，以供应用检索使用</td></tr></tbody></table><h3 id="Sidecar-模式"><a href="#Sidecar-模式" class="headerlink" title="Sidecar 模式"></a><a href="/2022/06/05/note/sidecar-model">Sidecar 模式</a></h3><p>Dapr以 sidecar 架构的方式公开其API，可以是容器，也可以是进程，不需要应用代码包含任何 Dapr 运行时代码。 这使得 Dapr 与其他运行时的集成变得容易，在应用逻辑层面做了隔离处理，提高了可扩展性。</p><p><img src="/2022/06/05/note/dapr-01/overview-sidecar-model.png" alt=" "></p><h3 id="托管环境"><a href="#托管环境" class="headerlink" title="托管环境"></a>托管环境</h3><p>Dapr可以托管在多个环境中，包括在Windows/Linux/macOS机器上自托管和Kubernetes。</p><h4 id="自托管"><a href="#自托管" class="headerlink" title="自托管"></a>自托管</h4><p><a href="https://docs.dapr.io/zh-hans/operations/hosting/self-hosted/self-hosted-overview/">自托管模式</a> 下，Dapr 运行一个单独的 sidecar 程序，在您的服务代码中可以通过 HTTP 或 gRPC 调用它。 每个运行的服务都有一个 Dapr 运行时进程 (或 sidecar) ，配置为使用状态存储， pub/sub，绑定组件和其他构建块。</p><p>您可以使用 <a href="https://github.com/dapr/cli#launch-dapr-and-your-app">Dapr CLI</a> 在本地机器上运行启用了 Dapr 的应用程序。 请使用 <a href="https://docs.dapr.io/zh-hans/getting-started/">入门示例</a>。</p><p><img src="/2022/06/05/note/dapr-01/overview_standalone.png" alt=" "></p><h4 id="Kubernetes-托管"><a href="#Kubernetes-托管" class="headerlink" title="Kubernetes 托管"></a>Kubernetes 托管</h4><p>在托管在容器环境中（如 Kubernetes），Dapr 作为 sidecar 容器运行，和应用程序容器在同一个 pod 中。</p><p>在 Kubernetes 中， dapr-sidecar-injector 和 dapr-operator 服务提供一流的集成，以将 Dapr 作为 sidecar 容器启动在与服务容器相同的 pod 中 ，并为在集群中部署的 Dapr 组件提供更新通知。</p><p>dapr-sentry 服务是一个认证中心，它允许 Dapr sidecar 实例之间的相互 TLS 进行安全数据加密。 关于 Sentry 服务的更多信息请阅读 安全概述</p><p>在 Kubernetes 集群中部署和运行启用 Dapr 的应用程序非常简单，只需向 deployment 方案添加一些注解。 访问 <a href="https://docs.dapr.io/zh-hans/operations/hosting/kubernetes/">Kubernetes 文档上的 Dapr</a></p><p><img src="/2022/06/05/note/dapr-01/overview_kubernetes.png" alt=" "></p><h3 id="开发者语言-SDK-和框架"><a href="#开发者语言-SDK-和框架" class="headerlink" title="开发者语言 SDK 和框架"></a>开发者语言 SDK 和框架</h3><p>Dapr 提供各种 SDK 和框架，便于开始以您喜欢的语言与 Dapr 一起开发。</p><h4 id="Dapr-SDKs"><a href="#Dapr-SDKs" class="headerlink" title="Dapr SDKs"></a>Dapr SDKs</h4><p>为了让不同语言使用 Dapr 更加自然，它还包含了 <a href="https://docs.dapr.io/zh-hans/developing-applications/sdks/">语言特定的 SDK</a>：</p><ul><li>C++</li><li>Go</li><li>Java</li><li>JavaScript</li><li>Python</li><li>Rust</li><li>.NET</li><li>PHP</li></ul><p>这些 SDK 通过特定语言 API 来暴露 Dapr 构建块的功能，而不是调用 http/gRPC API。 这使您能够以自己选择的语言编写无状态和有状态功能和 actors 的组合。 由于这些 SDK 共享 Dapr 运行时，因此您可以获得跨语言 actor 和功能支持。</p><h3 id="开发框架"><a href="#开发框架" class="headerlink" title="开发框架"></a>开发框架</h3><p>Dapr 可以与任何开发框架集成。 下面是一些已经和 Dapr 集成的。</p><h4 id="Web"><a href="#Web" class="headerlink" title="Web"></a>Web</h4><table><thead><tr><th>语言</th><th>框架</th><th>说明</th></tr></thead><tbody><tr><td>.NET</td><td>ASP.NET</td><td>带来状态路由控制器，从而完成来自其他应用的 发布/订阅 构建块。 也可以利用 ASP.NET Core gRPC 服务。</td></tr><tr><td>Java</td><td>Spring Boot</td><td></td></tr><tr><td>Python</td><td>Flask</td><td></td></tr><tr><td>Javascript</td><td>Express</td><td></td></tr><tr><td>PHP</td><td></td><td>您可以使用 Apache, Nginx, 或 Caddyserver 进行托管</td></tr></tbody></table><h4 id="集成和扩展"><a href="#集成和扩展" class="headerlink" title="集成和扩展"></a>集成和扩展</h4><p>访问 <a href="https://docs.dapr.io/zh-hans/developing-applications/integrations/">integrations</a> 页面，了解 Dapr 对各种框架和外部产品的一流支持，包括：</p><ul><li>Azure Functions runtime</li><li>Azure Logic Apps runtime</li><li>Azure API 管理</li><li>KEDA</li><li>Visual Studio Code</li></ul><h3 id="为运维而设计"><a href="#为运维而设计" class="headerlink" title="为运维而设计"></a>为运维而设计</h3><p>Dapr 专为 运维 和安全性而设计。 Dapr sidecar、运行时间、组件和配置都可以轻松、安全地管理和部署，以满足组织的需求。</p><p>通过 Dapr CLI 安装的 <a href="https://github.com/dapr/dashboard">服务仪表板</a>提供了基于 Web 的 UI ，使您能够查看信息，查看日志以及 Dapr sidecar 的更多内容。</p><p><a href="https://docs.dapr.io/zh-hans/operations/monitoring/">监控工具支持</a> 提供 Dapr 系统服务和sidecar 的更深入的可见性，Dapr 的 <a href="https://docs.dapr.io/zh-hans/concepts/observability-concept/">可观测性能力</a> 提供了对应用程序的深入了解，例如追踪和度量。</p>]]>
    </content>
    <id>https://www.rokeyyan.com/2022/06/04/2022-06-05-dapr-01/</id>
    <link href="https://www.rokeyyan.com/2022/06/04/2022-06-05-dapr-01/"/>
    <published>2022-06-04T16:00:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="概述"><a href="#概述" class="headerlink" title="概述"></a>概述</h2><h3 id="分布式应用程序运行时介绍"><a href="#分布式应用程序运行时介绍" class="headerlink" title="分]]>
    </summary>
    <title>dapr入门(一)</title>
    <updated>2022-06-04T16:00:00.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>rokey</name>
    </author>
    <category term="笔记" scheme="https://www.rokeyyan.com/categories/%E7%AC%94%E8%AE%B0/"/>
    <category term="笔记" scheme="https://www.rokeyyan.com/tags/%E7%AC%94%E8%AE%B0/"/>
    <content>
      <![CDATA[<h2 id="基础概念"><a href="#基础概念" class="headerlink" title="基础概念"></a>基础概念</h2><ul><li>构建块</li><li>组件</li><li>Configuration (配置)</li><li>中间件管道</li><li>可观测性</li><li>安全</li><li>Dapr 术语和定义</li></ul><h3 id="构建块"><a href="#构建块" class="headerlink" title="构建块"></a>构建块</h3><p><strong>可通过标准 HTTP 或 gRPC API 访问的模块化最佳实践</strong></p><p>构建块 是可以从您的代码中调用的HTTP或gRPC API，并且由一个或多个Dapr组件组成。</p><p>构建块解决了构建弹性微服务应用程序中的常见挑战，并编纂了最佳实践和模式。 Dapr由一组构建块组成，并且具有可扩展性以添加新的构建块。</p><p>下图显示了构建块如何公开了可被代码调用的公共 API ，并使用组件来实现构建块的能力。</p><p><img src="/2022/06/05/note/dapr-02/concepts-building-blocks.png" alt=" "></p><p>以下是 Dapr 提供的构建块类型:</p><p><img src="/2022/06/05/note/dapr-02/building_blocks.png" alt=" "></p><table><thead><tr><th>构建块</th><th>说明</th></tr></thead><tbody><tr><td>服务调用</td><td>跨服务调用允许进行远程方法调用(包括重试)，不管处于任何位置，只需该服务托管于受支持的环境即可。</td></tr><tr><td>状态管理</td><td>独立的状态管理，使用键/值对作为存储机制，可以轻松的使长时运行、高可用的有状态服务和无状态服务共同运行在您的应用程序中。 状态存储是可插拔的，目前支持使用Azure CosmosDB、 Azure SQL Server、 PostgreSQL,、AWS DynamoDB、Redis 作为状态存储介质。</td></tr><tr><td>发布订阅</td><td>发布事件和订阅主题。</td></tr><tr><td>资源绑定</td><td>Dapr的Bindings是建立在事件驱动架构的基础之上的。通过建立触发器与资源的绑定，可以从任何外部源（例如数据库，队列，文件系统等）接收和发送事件，而无需借助消息队列，即可实现灵活的业务场景。</td></tr><tr><td>Actors</td><td>Actor模型 = 状态 + 行为 + 消息。一个应用/服务由多个Actor组成，每个Actor都是一个独立的运行单元，拥有隔离的运行空间，在隔离的空间内，其有独立的状态和行为，不被外界干预，Actor之间通过消息进行交互，而同一时刻，每个Actor只能被单个线程执行，这样既有效避免了数据共享和并发问题，又确保了应用的伸缩性。 Dapr 在Actor模式中提供了很多功能，包括并发，状态管理，用于 actor 激活/停用的生命周期管理，以及唤醒 actor 的计时器和提醒器。</td></tr><tr><td>可观测性</td><td>Dapr记录指标，日志，链路以调试和监视Dapr和用户应用的运行状况。 Dapr支持分布式跟踪，其使用W3C跟踪上下文标准和开放式遥测技术，可以轻松地诊断在生产环境中服务间的网络调用，并发送到不同的监视工具。</td></tr><tr><td>安全</td><td>Dapr 提供了密钥管理，支持与公有云和本地的Secret存储集成，以供应用检索使用</td></tr></tbody></table><h3 id="组件-Components"><a href="#组件-Components" class="headerlink" title="组件(Components)"></a>组件(Components)</h3><p><strong>被用于构建块和应用程序的模块化功能</strong></p><p>Dapr 使用模块化设计，将功能作为组件来提供。 每个组件都有接口定义。 所有组件都是可插拔的，因此您可以将组件换为另一个具有相同接口的组件。 您可以在 components contrib repo 为组件接口贡献实现并扩展 Dapr 功能。</p><p>构建块可以使用任何组件组合。 例如， actors 构建块和 状态管理 构建块都使用 状态组件。 另一个示例是 Pub/Sub 构建块使用 Pub/Sub 组件。</p><p>您可以使用 dapr components CLI 命令查看当前托管环境中可用组件的列表。</p><p>以下是 Dapr 提供的组件类型：</p><h4 id="状态存储"><a href="#状态存储" class="headerlink" title="状态存储"></a>状态存储</h4><p>状态存储组件是存储键值对的数据存储（数据库、文件、内存），其作为 状态管理 的构建模块之一。</p><h4 id="服务发现"><a href="#服务发现" class="headerlink" title="服务发现"></a>服务发现</h4><p>服务发现组件与 服务调用 构建块配合使用，与托管环境集成以提供服务到服务发现。 例如， Kubernetes 服务发现组件与 Kubernetes DNS 服务集成，而自托管时使用 mDNS。</p><h4 id="中间件"><a href="#中间件" class="headerlink" title="中间件"></a>中间件</h4><p>Dapr 允许将自定义 中间件 插入请求处理管道。 中间件可以在请求路由到用户代码之前，或者在将请求返回给客户端之前，对请求执行额外的操作（例如，认证，加密和消息转换）。 中间件组件与 服务调用 基础结构块一起使用。</p><h4 id="Pub-Sub-代理"><a href="#Pub-Sub-代理" class="headerlink" title="Pub/Sub 代理"></a>Pub/Sub 代理</h4><p>发布/订阅 组件是消息分发器，可以作为应用程序之间进行消息发布 &amp; 订阅 构建块。</p><h4 id="绑定"><a href="#绑定" class="headerlink" title="绑定"></a>绑定</h4><p>绑定 构建块使得外部资源可以连接到 Dapr 以触发服务或作从应用触发外部服务。</p><h4 id="Secret-stores（密钥存储）"><a href="#Secret-stores（密钥存储）" class="headerlink" title="Secret stores（密钥存储）"></a>Secret stores（密钥存储）</h4><p>在 dapr 中，密钥 是指任何你不想给不受欢迎的人（例如：黑客）知道的私有信息。 密钥存储被用来存储可以在服务中被获取以及被使用的密钥</p><h3 id="Configuration-配置"><a href="#Configuration-配置" class="headerlink" title="Configuration (配置)"></a>Configuration (配置)</h3><p><strong>变更 Dapr sidecars 或全局 Dapr 系统服务的行为</strong></p><p>您可以在 Dapr 控制面板中更改 Dapr 全局系统服务配置，这些设置能够改变单个 Dapr 应用程序 sidecar。</p><p>配置定义和部署形式为 YAML 文件。 一个应用程序配置示例就像这样：</p><pre><code>apiVersion: dapr.io/v1alpha1kind: Configurationmetadata:  name: daprConfig  namespace: defaultspec:  tracing:    samplingRate: "1"    zipkin:      endpointAddress: "http://localhost:9411/api/v2/spans"</code></pre><p>这个配置文件配置了遥测录制跟踪。 你可以在自托管模式中通过编辑 .dapr 目录中名为 config.yaml 的配置文件进行加载；或者通过 kubectl/helm 应用到您的 Kubernetes 集群。</p><p>阅读 <a href="https://docs.dapr.io/zh-hans/operations/configuration/configuration-overview/">此页面</a> 查看所有配置选项的列表。</p><h3 id="中间件管道"><a href="#中间件管道" class="headerlink" title="中间件管道"></a>中间件管道</h3><p><strong>链式中间件组件的自定义处理管道</strong></p><p>Dapr 允许通过链接一系列中间件组件来定义自定义处理管道。 请求在路由到用户代码之前经过所有已定义的中间件组件，然后在返回到客户机之前，按相反顺序经过已定义的中间件，如下图中所示。</p><p><img src="/2022/06/05/note/dapr-02/middleware.png" alt=" "></p><h4 id="自定义处理管道"><a href="#自定义处理管道" class="headerlink" title="自定义处理管道"></a>自定义处理管道</h4><p>启动后， Dapr sidecar 会构建中间件处理管道。 默认情况下，管道由 追踪中间件 和 CORS 中间件组成。 其他中间件，由 Dapr configuration 配置，按照定义的顺序添加到管道中。 管道适用于所有 Dapr API 终结点，包括状态，发布/订阅，服务调用，绑定，安全性和其他。</p><blockquote><p>注意： Dapr 提供 middleware.http.uppercase 预注册组件，该组件将请求正文中的所有文本更改为大写。 您可以使用它来测试/验证自定义管道是否已就绪。</p></blockquote><p>以下配置示例定义了使用 OAuth 2.0 中间件 和大写中间件组件的自定义管道。 在这种情况下，在转发到用户代码之前，所有请求都将通过 OAuth 2.0 协议进行授权，并转换为大写文本。</p><pre><code>apiVersion: dapr.io/v1alpha1kind: Configurationmetadata:  name: pipeline  namespace: defaultspec:  httpPipeline:    handlers:    - name: oauth2      type: middleware.http.oauth2    - name: uppercase      type: middleware.http.uppercase</code></pre><h4 id="下一步"><a href="#下一步" class="headerlink" title="下一步"></a>下一步</h4><ul><li><a href="https://docs.dapr.io/zh-hans/developing-applications/middleware/middleware-overview/">操作方法：使用 OAuth 配置 API 授权</a></li><li><a href="https://docs.dapr.io/zh-hans/operations/security/oauth/">操作方法：使用 OAuth 配置 API 授权</a></li></ul><h3 id="可观测性"><a href="#可观测性" class="headerlink" title="可观测性"></a>可观测性</h3><p><strong>如何通过跟踪、度量、日志和健康状况来监控应用程序</strong></p><p>在构建应用程序时，了解系统如何运行是运维的一个重要部分——这包括有能力观测应用程序的内部调用，评估其性能并在发生问题时立即意识到问题。 这对任何系统都是一种挑战，而对于由多个微服务组成的分布式系统来说更是如此，其中由多个调用组成的流程，可以在一个微服务中启动，然后在另一个微服务中继续。 可观察性在生产环境中至关重要，但在开发期间也很有用，可以了解瓶颈所在，提高性能并在整个微服务范围内进行基本的调试。</p><p>虽然可以从底层基础设施层收集有关应用程序的一些数据( 例如内存消耗， CPU 使用率) ，但其他有意义的信息必须从 “应用程序感知 “ 层收集，比如用于显示一系列调用如何跨微服务执行的信息。 这通常意味着开发人员必须添加一些代码来用于此目的的应用程序。 通常，检测代码只是将收集的数据 ( 例如跟踪（traces）和度量（metrics）） 发送到外部监视工具或服务，由这些工具或服务来帮助存储，可视化和分析所有这些信息。</p><p>这是开发者的额外负担：必须维护此代码，即使它不属于应用程序核心逻辑的一部分，甚至有时还需要了解监视工具 API，使用额外的 SDK 等操作。 此检测需求可能会增加应用程序的可移植性难度，比如在不同地方部署时，该应用程序可能需要不同的检测代码。 例如，不同的云提供者提供不同的监控解决方案，而在本地部署中可能要求一个本地解决方案。</p><h4 id="通过-Dapr-进行观测"><a href="#通过-Dapr-进行观测" class="headerlink" title="通过 Dapr 进行观测"></a>通过 Dapr 进行观测</h4><p>在利用 Dapr 构建块来执行服务到服务调用和 pub/sub 消息传递构建应用程序时， Dapr 拥有相对于 <a href="https://docs.dapr.io/zh-hans/operations/monitoring/tracing/">distributed tracing</a> 的优势，因为此服务间通信全部流经 Dapr sidecar，sidecar 处于这样独特的位置，可以消除应用程序级别检测的负担。</p><h5 id="分布式跟踪"><a href="#分布式跟踪" class="headerlink" title="分布式跟踪"></a>分布式跟踪</h5><p>Dapr 可以配置发送跟踪数据，并且由于 Dapr 使用广泛采用的协议（如 Zipkin 协议）进行跟踪，因此可以轻松地集成多个 监控后端。</p><p><img src="/2022/06/05/note/dapr-02/observability-tracing.png" alt=" "></p><h5 id="OpenTelemetry-采集器"><a href="#OpenTelemetry-采集器" class="headerlink" title="OpenTelemetry 采集器"></a>OpenTelemetry 采集器</h5><p>Dapr 还可以通过配置来使用 OpenTelemetry Collector ，它会提供更多与外部监控工具的兼容性。</p><p><img src="/2022/06/05/note/dapr-02/observability-opentelemetry-collector.png" alt=" "></p><h5 id="跟踪上下文"><a href="#跟踪上下文" class="headerlink" title="跟踪上下文"></a>跟踪上下文</h5><p>Dapr 使用 W3C 跟踪 规范来跟踪上下文，并可以生成和传播上下文头本身或传播用户提供的上下文头。</p><h4 id="Dapr-sidecar-和系统服务的可观察性"><a href="#Dapr-sidecar-和系统服务的可观察性" class="headerlink" title="Dapr sidecar 和系统服务的可观察性"></a>Dapr sidecar 和系统服务的可观察性</h4><p>至于系统的其他部分，您希望能够观察 Dapr 本身，并收集 Dapr sidecar 沿每个微服务以及您环境中的 Dapr 相关服务（如部署在 Dapr 启用的 Kubernetes 集群中的控制面板服务）发出的指标和日志。</p><p><img src="/2022/06/05/note/dapr-02/observability-sidecar.png" alt=" "></p><h4 id="日志"><a href="#日志" class="headerlink" title="日志"></a>日志</h4><p>Dapr 生成 日志，以提供 sidecar 操作的可见性，并帮助用户识别问题并执行调试。 日志事件包含由 Dapr 系统服务生成的警告，错误，信息和调试消息。 Dapr 还可以通过配置将日志发送到收集器，例如 Fluentd 和 Azure Monitor ，这样就可以轻松搜索，分析和提供洞察。</p><h4 id="度量"><a href="#度量" class="headerlink" title="度量"></a>度量</h4><p>指标（Metrics）是在一段时间内收集和存储的一系列度量值和计数。 Dapr 指标 提供监控功能，以了解 Dapr sidecar 和系统服务的行为。 例如，Dapr sidecar 和用户应用之间的服务指标可以展示调用延迟、流量故障、请求的错误率等。 Dapr 的系统服务度量 则可以显示 sidecar 注入失败，系统服务的运行状况 ( 包括 CPU 使用率，actor 位置数量等) 。</p><h4 id="健康状态"><a href="#健康状态" class="headerlink" title="健康状态"></a>健康状态</h4><p>Dapr sidecar 暴露了 健康检查的 HTTP 终结点。 通过此终结点，可以探测 Dapr 进程或 sidecar，以确定它的准备度和活跃度，并采取相应的行动。</p><h3 id="安全"><a href="#安全" class="headerlink" title="安全"></a>安全</h3><p><strong>Dapr在设计时是如何考虑安全的</strong></p><p>本文介绍在分布式应用程序中使用 Dapr 时涉及的多个安全注意事项，包括：</p><p>上述几个领域是通过对传输中的数据进行加密解决的。 Dapr 用于加密传输中数据的安全机制之一是 相互认证（mutual authentication）TLS 或简写为 mTLS。 mTLS 为应用程序内的网络流量提供了一些关键功能：</p><ul><li>双向身份验证 - 客户端向服务器证明其身份，反之亦然</li><li>建立双向认证后，所有进行中通信都走加密通道</li></ul><p>在几乎所有场景中，相互 TLS 都很有用，尤其是对于受法规约束的系统，例如 HIPAA 和 PCI。</p><p>Dapr 支持 mTLS 和本文档中描述的应用程序中的所有功能，在生产系统中几乎不需要额外的代码或复杂配置</p><h4 id="Sidecar与应用程序之间的通信"><a href="#Sidecar与应用程序之间的通信" class="headerlink" title="Sidecar与应用程序之间的通信"></a>Sidecar与应用程序之间的通信</h4><p>Dapr sidecar通过 localhost 运行在应用程序附近，建议在与应用程序相同的网络边界下运行。 尽管如今许多云原生系统将 Pod 级别（例如 Kubernetes 上）视为可信任的安全边界，但 Dapr 还是可以为用户提供使用令牌的 API 级别身份验证。 此功能保证即使在 localhost 上，也只有经过身份验证的调用方才能调用 Dapr。</p><h4 id="Sidecar之间的通信"><a href="#Sidecar之间的通信" class="headerlink" title="Sidecar之间的通信"></a>Sidecar之间的通信</h4><p>Dapr 包括一个”默认开启”，自动相互 TLS，为 Dapr sidecar之间的流量提供传输加密。 为此，Dapr 利用名为 Sentry 的系统服务，该服务充当证书颁发机构 （Certificate Authority/CA），并为来自 Dapr sidecar的工作负载 （app） 签署证书请求。</p><p>Dapr 还管理工作负载证书轮换，并且这样做时应用程序不会停机。</p><p>除非用户提供了现有的根证书，否则，作为 CA 服务的 Sentry 会自动创建并持有自签名根证书，有效期为一年。</p><p>更换根证书（Kubernetes 模式下的 secret 和自托管模式的文件系统）时，Sentry 会提取它们并重新构建信任链，而无需重新启动，而 Sentry 的停机时间为零。</p><p>当新的 Dapr sidecar 初始化时，它首先检查 mTLS 是否启用。 如果是，则生成 ECDSA 私钥和证书签名请求，然后通过 gRPC 接口发送到 Sentry。 Dapr sidecar 和 Sentry 之间的通信使用信任链证书进行身份验证，该证书由 Dapr Sidecar Injector 系统服务注入到每个 Dapr 实例中。</p><p>在 Kubernetes 集群中，保存根证书的密钥的范围是 Dapr 组件部署所在的命名空间，并且只有 Dapr 系统 pod才能访问。</p><p>在 Kubernetes 上部署时，Dapr 还支持强标识，它依赖于Pod 的 Service Account 令牌，而这个令牌会作为证书签名请求 （CSR） 的一部分发送到 Sentry。</p><p>默认情况下，工作负荷证书的有效期为 24 小时，时钟偏差设置为 15 分钟。</p><p>编辑与 Dapr 一起部署的默认配置中的 spec.mtls.enabled 字段，可以关闭/开启相互TLS。 这既可用于 Kubernetes 模式，也可以用于自托管模式。 有关如何做到这一点的详细信息，在这里。</p><h4 id="自托管中的-mTLS"><a href="#自托管中的-mTLS" class="headerlink" title="自托管中的 mTLS"></a>自托管中的 mTLS</h4><p>下图显示了 Sentry 系统服务如何根据运维人员提供或由 Sentry 服务生成的根证书/颁发者证书（这些证书存储在文件中）为应用程序颁发证书。</p><p><img src="/2022/06/05/note/dapr-02/security-mTLS-sentry-selfhosted.png" alt=" "></p><h4 id="kubernetes-中的-mTLS"><a href="#kubernetes-中的-mTLS" class="headerlink" title="kubernetes 中的 mTLS"></a>kubernetes 中的 mTLS</h4><p>下图显示了 Sentry 系统服务如何根据运维人员提供的，或者由 Sentry 服务生成（存储为 Kubernetes sucret ）的根证书/颁发者证书为应用程序颁发证书。</p><p><img src="/2022/06/05/note/dapr-02/security-mTLS-sentry-kubernetes.png" alt=" "></p><h4 id="Sidecar与系统服务之间的通信"><a href="#Sidecar与系统服务之间的通信" class="headerlink" title="Sidecar与系统服务之间的通信"></a>Sidecar与系统服务之间的通信</h4><p>除了 Dapr Sidecar 之间的自动 mTLS 之外，Dapr 还提供 Dapr sidecar 和 Dapr 系统服务之间的强制性 mTLS，这些系统服务包括 Sentry 服务（证书颁发机构）、 Placement 服务（Actor安置）和 Kubernetes Operator。</p><p>启用 mTLS 时， Sentry 将根证书和颁发者证书写入 Kubernetes secret，该密钥的作用域限定为部署控制平面的名称空间。 在自托管模式下，Sentry 将证书写入可配置的文件系统路径下。</p><p>在 Kubernetes 中，当 Dapr 系统服务启动时，它们会自动装载包含根证书和颁发证书的 secret，并使用这些secret 来加固 Dapr sidecar 使用的 gRPC 服务器。</p><p>在自托管模式下，每个系统服务都可以装载文件系统路径以获取证书。</p><p>当 Dapr sidecar 初始化时，它使用挂载的叶证书和颁发者私钥对系统 pod 进行身份验证。 这些作为环境变量挂载在 sidecar 容器上。</p><h4 id="Kubernetes-中系统服务的-mTLS"><a href="#Kubernetes-中系统服务的-mTLS" class="headerlink" title="Kubernetes 中系统服务的 mTLS"></a>Kubernetes 中系统服务的 mTLS</h4><p>下图显示了 Dapr Sidecar 与 Dapr Sentry（证书颁发机构）、Placement（Actor 安置）和 Kubernetes Operator 系统服务之间的安全通信</p><p><img src="/2022/06/05/note/dapr-02/security-mTLS-dapr-system-services.png" alt=" "></p><h4 id="组件命名空间的作用域和密钥"><a href="#组件命名空间的作用域和密钥" class="headerlink" title="组件命名空间的作用域和密钥"></a>组件命名空间的作用域和密钥</h4><p>Dapr 组件是受限于命名空间的。 这意味着 Dapr runtime sidecar 的实例只能访问部署到同一命名空间的组件。 更多详细信息请参阅 组件范围文档。</p><p>Dapr 组件使用 Dapr 的内置密钥管理功能来管理密钥。 有关详细信息，请参阅 密钥存储概述 。</p><p>此外，Dapr 通过允许用户指定哪些应用程序可以使用给定组件，为组件提供应用程序级的范围限制。有关应用程序级别范围设置，请参阅。</p><h4 id="网络安全"><a href="#网络安全" class="headerlink" title="网络安全"></a>网络安全</h4><p>您可以采用常见的网络安全技术，如网络安全组 （NSG）、非军事区 （DMZ） 和防火墙，以便为您的网络资源提供层层保护。</p><p>例如，除非配置为与外部绑定目标通讯，否则 Dapr sidecar 不会打开到 Internet 的连接。 而大多数绑定实现仅使用出站连接。 您可以设计防火墙规则，只允许通过指定的端口进行出站连接。</p><h4 id="绑定安全性"><a href="#绑定安全性" class="headerlink" title="绑定安全性"></a>绑定安全性</h4><p>具有绑定目标的身份验证由绑定的配置文件配置。 通常，应配置所需的最低访问权限。 例如，如果仅从绑定目标读取，则应配置绑定以使用具有只读访问权限的帐户。</p><h4 id="状态存储安全"><a href="#状态存储安全" class="headerlink" title="状态存储安全"></a>状态存储安全</h4><p>Dapr 不会转换来自应用程序的状态数据。 这意味着 Dapr 不会尝试加密/解密状态数据。 但是，您的应用程序可以采用您选择的加密/解密方法，而且状态数据对 Dapr 保持不透明。</p><p>Dapr 不存储任何数据。</p><p>Dapr 使用配置的身份验证方法来与底层状态存储进行身份验证。 许多状态存储实现都使用官方客户端库，这些客户端库通常使用安全通信通道和服务器通讯。</p><h4 id="管理安全"><a href="#管理安全" class="headerlink" title="管理安全"></a>管理安全</h4><p>在 Kubernetes 上部署时，您可以使用 Kubernetes RBAC 控制对管理活动的访问。</p><p>在 Azure Kubernetes Service （AKS） 上部署时，可以使用 Azure Active Directory （AD） 服务主体 控制对管理活动和资源管理的访问。</p><h4 id="威胁模型"><a href="#威胁模型" class="headerlink" title="威胁模型"></a>威胁模型</h4><p>威胁建模是一个过程，通过该过程可以识别、枚举潜在威胁（如结构漏洞或缺乏适当的安全措施），并确定缓解措施的优先级。 Dapr 威胁模型如下：</p><p><img src="/2022/06/05/note/dapr-02/security-threat-model.png" alt=" "></p><h3 id="Dapr-术语和定义"><a href="#Dapr-术语和定义" class="headerlink" title="Dapr 术语和定义"></a>Dapr 术语和定义</h3><p><strong>Dapr文件中通用术语和缩略语的定义</strong></p><p>这个页面详细介绍了您可能在Dapr文档中读到的常见术语。</p><table><thead><tr><th>词条</th><th>定义</th><th>详情</th></tr></thead><tbody><tr><td>应用（App/Application）</td><td>运行中的服务/二进制应用，通常是由用户创建和运行的。</td><td></td></tr><tr><td>Building block (构建块)</td><td>Dapr 为用户提供的 API，以帮助创建微服务和应用程序。</td><td>Dapr 构建块</td></tr><tr><td>Component (组件)</td><td>由 Dapr 构建块单独使用或与其他组件集合一起使用的模块化功能类型。</td><td>Dapr components</td></tr><tr><td>Configuration (配置)</td><td>一个 YAML 文件，声明Dapr sidecars 或 Dapr 控制面板的所有设置。 您可以在这里配置控制平面 mTLS 设置，或应用程序实例的跟踪和中间件设置。</td><td>Dapr配置</td></tr><tr><td>Dapr</td><td>分布式应用程序运行时。</td><td>Dapr 概述</td></tr><tr><td>Dapr control plane (Dapr 控制面板)</td><td>在托管平台（如 Kubernetes 集群）上安装 Dapr 的一部分的服务集合。 允许 Dapr 启用应用程序在该平台上运行，并处理 Dapr 功能，如 actor placement 、Dapr sidecar 或证书签发/延续。</td><td>Self-hosted overview Kubernetes overview</td></tr><tr><td>自托管</td><td>您可以在 Windows/macOS/Linux机器 用Dapr运行您的应用程序。 Dapr 提供以”自托管”模式在机器上运行的功能。</td><td>自托管模式</td></tr><tr><td>Service (服务)</td><td>正在运行的应用程序或二进制文件。 可用于指您的应用程序，或Dapr应用程序。</td><td></td></tr><tr><td>Sidecar</td><td>将应用程序作为单独的流程或容器与您的应用程序一起运行的程序。</td><td>Sidecar 模式</td></tr></tbody></table>]]>
    </content>
    <id>https://www.rokeyyan.com/2022/06/04/2022-06-05-dapr-02/</id>
    <link href="https://www.rokeyyan.com/2022/06/04/2022-06-05-dapr-02/"/>
    <published>2022-06-04T16:00:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="基础概念"><a href="#基础概念" class="headerlink" title="基础概念"></a>基础概念</h2><ul>
<li>构建块</li>
<li>组件</li>
<li>Configuration (配置)</li>
<li>中间件]]>
    </summary>
    <title>dapr入门(二)</title>
    <updated>2022-06-04T16:00:00.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>rokey</name>
    </author>
    <category term="笔记" scheme="https://www.rokeyyan.com/categories/%E7%AC%94%E8%AE%B0/"/>
    <category term="笔记" scheme="https://www.rokeyyan.com/tags/%E7%AC%94%E8%AE%B0/"/>
    <content>
      <![CDATA[<p>转载至<a href="https://www.servicemesher.com/">servicemesher</a>  </p><h2 id="定义"><a href="#定义" class="headerlink" title="定义"></a>定义</h2><p>Service Mesh 直译为服务网格,分为两部分理解。</p><h3 id="通讯组件"><a href="#通讯组件" class="headerlink" title="通讯组件"></a>通讯组件</h3><p>是应用系统微服务化的其中一种典型方案，重点在于Service Mesh是运行在请求/响应上层的通信层，专注于抽象应用系统之间的通讯模式和方案。通讯层的实现方式，有以下选择：</p><ul><li>用库的形式在微服务应用程序中导入使用。</li><li>用节点代理或守护程序的形式为特定节点/计算机上的所有容器提供服务。</li><li>用Sidecar容器的形式运行，和应用容器一同运行。</li></ul><p>以上三种方式，逐级降低了应用系统对于通讯组件的依赖程度。</p><h4 id="通讯组件-库"><a href="#通讯组件-库" class="headerlink" title="通讯组件-库"></a>通讯组件-库</h4><p>软件中库引用的方式是个很自然的选择。它简单明了。在这种架构中，每个微服务应用程序包中都有实现Service Mesh功能的库。像Hystrix和Ribbon就是用库的方法。</p><p><img src="/2022/06/05/note/service-mesh-schema-analysis/libray.jpg" alt="库"></p><p>如果一个团队仅使用一种语言开发并且还负责一个应用的运行，那么使用库引用就很容易，这种方式自然也是很合适的。库方法不需要与底层基础架构进行太多合作，如Kubernetes无需关心正在运行的一个应用是否包含Hystrix库。</p><p>要实现多语言支持，就必须用不同语言去重复实现多次，挑战在于实现的复杂性和一遍又一遍去实现同样概念的工作量。</p><p>我们的用户中对库模型的使用非常有限，因为大多数用户都会用许多不同语言编写应用程序，还会运行一些不是自己编写的应用程序，因此库引用是不可行的。</p><p>这种模型在工作审计方面具有优势：库的代码是在微服务内运行的。信任边界也很小，您只需要信任在自己进程中调用的库，而不像调用在网络的某个地方的远程服务。库的代码具有和库所在的微服务一样多的特权。代码的执行也是在微服务的环境中执行的，因此CPU时间片或内存等资源的分配可以很公平的由操作系统去完成。</p><h4 id="通讯组件-节点代理"><a href="#通讯组件-节点代理" class="headerlink" title="通讯组件-节点代理"></a>通讯组件-节点代理</h4><p>节点代理模型是下一个替代方案。在此架构中，每个节点上都运行一个单独的代理（通常是用户进程），为异构的服务提供负载。相比之下，该模型与库模型相反：它不关心应用程序的语言，可以为许多不同的微服务租户提供服务。</p><p>Linkerd在Kubernetes上的推荐部署就是这样的。和应用服务代理（ASP）F5一样，和Kubernetes默认的kube-proxy代理一样。</p><p>由于每个节点上都需要一个节点代理，因此需要与基础架构进行一些协作，如果没有协作的话此模型就无法工作。通过类比，大多数应用程序会把选择TCP堆栈，猜一个端口号，然后发送或接收TCP数据包的事委托给基础设施（也就是操作系统）。</p><p><img src="/2022/06/05/note/service-mesh-schema-analysis/agent.jpg" alt="节点代理"></p><p>相比工作审计来说，这个模型强调工作资源共享，如果节点代理用一些内存来缓存微服务的数据，那么服务就可能会在几秒钟内转向并使用该缓存区提供的数据。这可能非常有效，但容易被滥用。如果我的微服务请求所有缓存区空间，节点代理要先为你的微服务在缓存区提供一个快照。您需要更多代码来管理每个共享资源。</p><p>配置信息也受益于共享模式。因为将一个配置副本分发到每个节点，比把每个节点上的一个配置副本分发到每个节点要高效的多。</p><p>微服务容器化依赖的许多功能由节点代理或等效的组件提供。就像kubelet初始化pod，以及像flanneld这种CNI守护进程，或者再发散下，甚至操作系统内核本身就像节点代理模型一样。</p><h4 id="通讯组件-Sidecar"><a href="#通讯组件-Sidecar" class="headerlink" title="通讯组件-Sidecar"></a>通讯组件-Sidecar</h4><p>Sidecar是社区的新生儿。这是Istio与Envoy使用的模型。 Conduit也使用了sidecar方法。在Sidecar部署方式中，你会为每个应用的容器部署一个伴生容器。对于Service Mesh，Sidecar接管进出应用程序容器的所有网络流量。</p><p>我到目前为止的讨论，这种方法介于库和节点代理模型之间。例如，您部署Sidecar服务网格时，无需在节点上运行代理（因此您不需要基础结构的协作），但是您将运行多个相同sidecar的副本。另外一个角度看：我可以为一组微服务安装一个Service Mesh，你也可以安装一个有特定实现的Service Mesh，我们不需要沟通协调。这在服务网格的早期是非常强大的，我们可能会共享同一个Kubernetes集群但用途不同，我们会用到不同的功能集，或者在可靠技术实现的基础上兼容前沿技术的尝试。</p><p>Sidecar有利于工作审计，特别是在一些与安全相关的方面。例如：假设我使用Service Mesh来提供零信任模式的安全性。我希望Service Mesh以加密方式去验证客户端和服务器。如果使用节点代理来实现：当我的pod想成为另一个服务器pod的客户端时，节点代理将代表我的pod进行身份验证。节点代理也在服务其他pod，因此必须确保另一个pod不能代表我的pod进行身份验证去欺骗他。如果我们用Sidecar来实现，我pod的Sidecar不会服务于其他pod。我们可以遵循最小特权原则，并在认证密钥，内存和网络功能方面满足这个pod最低限度的需求。</p><p><img src="/2022/06/05/note/service-mesh-schema-analysis/sidecar.jpg" alt="sidecar"></p><p>因此，从外部看，Sidecar与其附属的应用程序具有相同的权限。另一方面，sidecar需要介入应用程序和外部服务之间。这会产生一些安全顾虑：你即希望sidecar拥有尽可能少的权限，但你又需要给它足够的权限来控制进出应用程序的流量。例如，在Istio中，负责设置Sidecar的init容器要具有设置iptables规则NET_ADMIN权限。初始化方式是较好的安全实践，它用最少的权限运行后就消失，但NET_ADMIN的所有内容都代表了被攻击的点。 （已经有人在加强改进这一点）。</p><p>从安全角度来看，Sidecar和应用程序非常近。但没有在函数中调用（如库）那么近，但比调用节点代理更近。在Kubernetes中使用Istio时，您的应用容器通过pod中共享的网络命名空间内的loopback接口与Sidecar通讯，这对其他pod和节点代理是不可见的。</p><p>大多数Kubernetes集群每个节点上有多个pod（因此每个节点有多个sidecar）。如果每个sidecar都需要知道“整个配置”，那么你就需要更多的带宽来同步该配置（以及更多的内存来存储配置副本）。因此，你不得不给每个Sidecar的配置范围加以限制，这很强，但从另一个角度看：必须花费更多精力为每个Sidecar减少配置（如Istio中的Pilot）。</p><p>另一方面是通过Sidecar复制其他东西会带来类似的开销。好消息是如果复制的内容完全相同并且使用了正确的驱动，容器运行时就会容器重用镜像一样，因此磁盘损失就不重要了，并且代码块也会在内存中共享。但是每个Sidecar都是独一无二的，要避免在每个Sidecar上做一堆复制而使得Sidecar变重。</p><p>使用Sidecar的Service Mesh在功能完整性和轻量级之间找到了良好的平衡。</p><h3 id="节点代理或Sidecar模型会占上风吗？"><a href="#节点代理或Sidecar模型会占上风吗？" class="headerlink" title="节点代理或Sidecar模型会占上风吗？"></a>节点代理或Sidecar模型会占上风吗？</h3><p>我想你可能会看到两者都存在。现在看来似乎Sidecar是Service Mesh的最佳实践：新技术、快速迭代和逐步替换。随着Service Mesh的成熟，我们将看到更多节点代理模型的应用。</p><p>随着Service Mesh实现的成熟和集群变得越来越大，节点代理模型的优势会更重要：</p><ul><li>通过节点共享开销（尤其是内存）</li><li>更少、更容易扩展和分发配置信息</li><li>精心构建的节点代理可以有效地把服务一个应用程序的资源转移给另一个应用</li></ul><p>Sidecar是一种向应用程序提供服务（如高级通信代理和服务网格）的方法。它特别适用于容器和Kubernetes。它的最大优势包括：</p><ul><li>不需要中央协调，可以逐步的添加到现有集群</li><li>为应用程序做的工作就属于该应用程序</li><li>App-to-sidecar通信比app-to-agent更安全</li></ul>]]>
    </content>
    <id>https://www.rokeyyan.com/2022/06/04/2022-06-05-service-mesh-schema-analysis/</id>
    <link href="https://www.rokeyyan.com/2022/06/04/2022-06-05-service-mesh-schema-analysis/"/>
    <published>2022-06-04T16:00:00.000Z</published>
    <summary>
      <![CDATA[<p>转载至<a href="https://www.servicemesher.com/">servicemesher</a>  </p>
<h2 id="定义"><a href="#定义" class="headerlink" title="定义"></a>定义</h2><p]]>
    </summary>
    <title>Service Mesh架构解析</title>
    <updated>2022-06-04T16:00:00.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>rokey</name>
    </author>
    <category term="笔记" scheme="https://www.rokeyyan.com/categories/%E7%AC%94%E8%AE%B0/"/>
    <category term="笔记" scheme="https://www.rokeyyan.com/tags/%E7%AC%94%E8%AE%B0/"/>
    <content>
      <![CDATA[<h2 id="Sidecar-模式"><a href="#Sidecar-模式" class="headerlink" title="Sidecar 模式"></a><strong>Sidecar 模式</strong></h2><p>Sidecar 模式是 Service Mesh 中习惯采用的模式，是容器设计模式的一种，将应用程序的组件部署到单独的进程或容器中，以提供隔离和封装。 使用此模式还可以使用异构组件和技术来构建应用程序。</p><p>此模式名为 Sidecar ，因为它类似于附加到摩托车的侧车。 在此模式中，挎斗附加到父应用程序，为应用程序提供支持性功能。 此外，挎斗与父应用程序具有相同的生命周期：与父应用程序一起创建，一起停用。 挎斗模式有时也称为搭档模式，这是一种分解模式。</p><h3 id="什么是-Sidecar-模式"><a href="#什么是-Sidecar-模式" class="headerlink" title="什么是 Sidecar 模式"></a>什么是 Sidecar 模式</h3><p>将应用程序的功能划分为单独的进程可以被视为 Sidecar 模式。如图所示，Sidecar 模式允许您在应用程序旁边添加更多功能，而无需额外第三方组件配置或修改应用程序代码。</p><p>如图所示：<br><img src="/2022/06/05/note/sidecar-model/sidecar-pattern.jpg" alt="Sidecar"></p><h3 id="使用-Sidecar-模式的优势"><a href="#使用-Sidecar-模式的优势" class="headerlink" title="使用 Sidecar 模式的优势"></a>使用 Sidecar 模式的优势</h3><p>Sidecar 模式具有以下优势：</p><ul><li>将与应用业务逻辑无关的功能抽象到共同基础设施降低了微服务代码的复杂度。</li><li>因为不再需要编写相同的第三方组件配置文件和代码，所以能够降低微服务架构中的代码重复度。</li><li>降低应用程序代码和底层平台的耦合度。</li></ul><h3 id="Sidecar-模式如何工作"><a href="#Sidecar-模式如何工作" class="headerlink" title="Sidecar 模式如何工作"></a>Sidecar 模式如何工作</h3><p>Sidecar 是容器应用模式的一种，也是在 Service Mesh 中发扬光大的一种模式，详见 <strong><a href="https://www.servicemesher.com/blog/service-mesh-architectures/">Service Mesh 架构解析</a></strong> ，其中详细描述使用了节点代理和 Sidecar 模式的 Service Mesh 架构。</p><p>使用 Sidecar 模式部署服务网格时，无需在节点上运行代理，但是集群中将运行多个相同的 Sidecar 副本。在 Sidecar 部署方式中，每个应用的容器旁都会部署一个伴生容器，这个容器称之为 Sidecar 容器。Sidecar 接管进出应用容器的所有流量。在 Kubernetes 的 Pod 中，在原有的应用容器旁边注入一个 Sidecar 容器，两个容器共享存储、网络等资源，可以广义的将这个包含了 Sidecar 容器的 Pod 理解为一台主机，两个容器共享主机资源。</p>]]>
    </content>
    <id>https://www.rokeyyan.com/2022/06/04/2022-06-05-sidecar-model/</id>
    <link href="https://www.rokeyyan.com/2022/06/04/2022-06-05-sidecar-model/"/>
    <published>2022-06-04T16:00:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="Sidecar-模式"><a href="#Sidecar-模式" class="headerlink" title="Sidecar 模式"></a><strong>Sidecar 模式</strong></h2><p>Sidecar 模式是 Service M]]>
    </summary>
    <title>Sidecar 模式</title>
    <updated>2022-06-04T16:00:00.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>rokey</name>
    </author>
    <category term="笔记" scheme="https://www.rokeyyan.com/categories/%E7%AC%94%E8%AE%B0/"/>
    <category term="笔记" scheme="https://www.rokeyyan.com/tags/%E7%AC%94%E8%AE%B0/"/>
    <content>
      <![CDATA[<p>泛域名证书太贵，单域名证书一年一续，域名多了也很麻烦，幸好有github可以抱大佬大腿，ACME自动化续期HTTPS证书<a href="https://github.com/acmesh-official/acme.sh/wiki/%E8%AF%B4%E6%98%8E">ACME.SH</a></p><h2 id="资源地址"><a href="#资源地址" class="headerlink" title="资源地址"></a>资源地址</h2><p><a href="https://github.com/acmesh-official/acme.sh">acme.sh</a></p><h2 id="主要步骤"><a href="#主要步骤" class="headerlink" title="主要步骤"></a>主要步骤</h2><ul><li>安装 acme.sh</li><li>生成证书</li><li>copy 证书到 nginx/apache 或者其他服务</li><li>更新证书</li><li>更新 acme.sh</li></ul><h2 id="安装-acme-sh"><a href="#安装-acme-sh" class="headerlink" title="安装 acme.sh"></a>安装 acme.sh</h2><pre><code>curl  https://get.acme.sh | sh -s email=my@example.com</code></pre><h2 id="生成证书"><a href="#生成证书" class="headerlink" title="生成证书"></a>生成证书</h2><p>生成证书首先需要对域名做验证，验证方式有如下几种</p><p>acme.sh 实现了 acme 协议支持的所有验证协议. 一般有两种方式验证: http 和 dns 验证.</p><p><strong>1. http 方式需要在你的网站根目录下放置一个文件, 来验证你的域名所有权,完成验证. 然后就可以生成证书了.</strong></p><pre><code>acme.sh  --issue  -d mydomain.com -d www.mydomain.com  --webroot  /home/wwwroot/mydomain.com/</code></pre><p>只需要指定域名, 并指定域名所在的网站根目录. acme.sh 会全自动的生成验证文件, 并放到网站的根目录, 然后自动完成验证. 最后会聪明的删除验证文件. 整个过程没有任何副作用.</p><p>如果你用的 apache服务器, acme.sh 还可以智能的从 apache的配置中自动完成验证, 你不需要指定网站根目录:</p><pre><code>acme.sh --issue  -d mydomain.com   --apache</code></pre><p>如果你用的 nginx服务器, 或者反代, acme.sh 还可以智能的从 nginx的配置中自动完成验证, 你不需要指定网站根目录:</p><pre><code>acme.sh --issue  -d mydomain.com   --nginx</code></pre><p><strong>注意, 无论是 apache 还是 nginx 模式, acme.sh在完成验证之后, 会恢复到之前的状态, 都不会私自更改你本身的配置. 好处是你不用担心配置被搞坏, 也有一个缺点, 你需要自己配置 ssl 的配置, 否则只能成功生成证书, 你的网站还是无法访问https. 但是为了安全, 你还是自己手动改配置吧.</strong></p><p>如果你还没有运行任何 web 服务, 80 端口是空闲的, 那么 acme.sh 还能假装自己是一个webserver, 临时听在80 端口, 完成验证:</p><pre><code>acme.sh  --issue -d mydomain.com   --standalone</code></pre><p>更高级的用法请参考: <a href="https://github.com/Neilpang/acme.sh/wiki/How-to-issue-a-cert">https://github.com/Neilpang/acme.sh/wiki/How-to-issue-a-cert</a></p><p><strong>2. 手动 dns 方式, 手动在域名上添加一条 txt 解析记录, 验证域名所有权.</strong><br>这种方式的好处是, 你不需要任何服务器, 不需要任何公网 ip, 只需要 dns 的解析记录即可完成验证. 坏处是，如果不同时配置 Automatic DNS API，使用这种方式 acme.sh 将无法自动更新证书，每次都需要手动再次重新解析验证域名所有权。</p><pre><code>acme.sh  --issue  --dns   -d mydomain.com \ --yes-I-know-dns-manual-mode-enough-go-ahead-please</code></pre><p>然后, acme.sh 会生成相应的解析记录显示出来, 你只需要在你的域名管理面板中添加这条 txt 记录即可.</p><p>等待解析完成之后, 重新生成证书:</p><pre><code>acme.sh  --renew   -d mydomain.com --yes-I-know-dns-manual-mode-enough-go-ahead-please</code></pre><p><strong>注意第二次这里用的是 –renew</strong></p><p>dns 方式的真正强大之处在于可以使用域名解析商提供的 api 自动添加 txt 记录完成验证.</p><p>acme.sh 目前支持 cloudflare, dnspod, cloudxns, godaddy 以及 ovh 等数十种解析商的自动集成.</p><p>以 dnspod 为例, 你需要先登录到 dnspod 账号, 生成你的 api id 和 api key, 都是免费的. 然后:</p><pre><code>export DP_Id="1234"export DP_Key="sADDsdasdgdsf"acme.sh   --issue   --dns dns_dp   -d aa.com  -d www.aa.com</code></pre><p>证书就会自动生成了. 这里给出的 api id 和 api key 会被自动记录下来, 将来你在使用 dnspod api 的时候, 就不需要再次指定了. 直接生成就好了:</p><pre><code>acme.sh  --issue   -d  mydomain2.com   --dns  dns_dp</code></pre><p>更详细的 api 用法: <a href="https://github.com/Neilpang/acme.sh/blob/master/dnsapi/README.md">https://github.com/Neilpang/acme.sh/blob/master/dnsapi/README.md</a></p><h2 id="copy-安装-证书"><a href="#copy-安装-证书" class="headerlink" title="copy/安装 证书"></a>copy/安装 证书</h2><p>前面证书生成以后, 接下来需要把证书 copy 到真正需要用它的地方.</p><p>注意, 默认生成的证书都放在安装目录下: ~/.acme.sh/, 请不要直接使用此目录下的文件, 例如: 不要直接让 nginx/apache 的配置文件使用这下面的文件. 这里面的文件都是内部使用, 而且目录结构可能会变化.</p><p>正确的使用方法是使用 –install-cert 命令,并指定目标位置, 然后证书文件会被copy到相应的位置, 例如:</p><p>Apache example:</p><pre><code>acme.sh --install-cert -d example.com \--cert-file      /path/to/certfile/in/apache/cert.pem  \--key-file       /path/to/keyfile/in/apache/key.pem  \--fullchain-file /path/to/fullchain/certfile/apache/fullchain.pem \--reloadcmd     "service apache2 force-reload"</code></pre><p>Nginx example:</p><pre><code>acme.sh --install-cert -d example.com \--key-file       /path/to/keyfile/in/nginx/key.pem  \--fullchain-file /path/to/fullchain/nginx/cert.pem \--reloadcmd     "service nginx force-reload"</code></pre><p>(一个小提醒, 这里用的是 service nginx force-reload, 不是 service nginx reload, 据测试, reload 并不会重新加载证书, 所以用的 force-reload)</p><p>Nginx 的配置 ssl_certificate 使用 /etc/nginx/ssl/fullchain.cer ，而非 /etc/nginx/ssl/<domain>.cer ，否则 SSL Labs 的测试会报 Chain issues Incomplete 错误。</domain></p><p>–install-cert命令可以携带很多参数, 来指定目标文件. 并且可以指定 reloadcmd, 当证书更新以后, reloadcmd会被自动调用,让服务器生效.</p><p>详细参数请参考: <a href="https://github.com/Neilpang/acme.sh#3-install-the-issued-cert-to-apachenginx-etc">https://github.com/Neilpang/acme.sh#3-install-the-issued-cert-to-apachenginx-etc</a></p><p>值得注意的是, 这里指定的所有参数都会被自动记录下来, 并在将来证书自动更新以后, 被再次自动调用.</p><h2 id="查看已安装证书信息"><a href="#查看已安装证书信息" class="headerlink" title="查看已安装证书信息"></a>查看已安装证书信息</h2><pre><code>acme.sh --info -d example.com# 会输出如下内容：DOMAIN_CONF=/root/.acme.sh/example.com/example.com.confLe_Domain=example.comLe_Alt=noLe_Webroot=dns_aliLe_PreHook=Le_PostHook=Le_RenewHook=Le_API=https://acme-v02.api.letsencrypt.org/directoryLe_Keylength=Le_OrderFinalize=https://acme-v02.api.letsencrypt.org/acme/finalize/23xxxx150/781xxxx4310Le_LinkOrder=https://acme-v02.api.letsencrypt.org/acme/order/233xxx150/781xxxx4310Le_LinkCert=https://acme-v02.api.letsencrypt.org/acme/cert/04cbd28xxxxxx349ecaea8d07Le_CertCreateTime=1649358725Le_CertCreateTimeStr=Thu Apr  7 19:12:05 UTC 2022Le_NextRenewTimeStr=Mon Jun  6 19:12:05 UTC 2022Le_NextRenewTime=1654456325Le_RealCertPath=Le_RealCACertPath=Le_RealKeyPath=/etc/acme/example.com/privkey.pemLe_ReloadCmd=service nginx force-reloadLe_RealFullChainPath=/etc/acme/example.com/chain.pem</code></pre><h2 id="针对阿里云或腾讯云域名的容器化nginx设置"><a href="#针对阿里云或腾讯云域名的容器化nginx设置" class="headerlink" title="针对阿里云或腾讯云域名的容器化nginx设置"></a>针对阿里云或腾讯云域名的容器化nginx设置</h2><h3 id="自动注册脚本"><a href="#自动注册脚本" class="headerlink" title="自动注册脚本"></a>自动注册脚本</h3><pre><code>/home/rokey/.acme.sh/acme.sh --issue --dns dns_ali  -d bark.rokeyyan.com</code></pre><h3 id="自动续期脚本"><a href="#自动续期脚本" class="headerlink" title="自动续期脚本"></a>自动续期脚本</h3><pre><code>#bark.rokeyyan.com/home/rokey/.acme.sh/acme.sh --install-cert -d 'bark.rokeyyan.com' \--cert-file /srv/nginx/cert/bark.rokeyyan.com.pem \--key-file /srv/nginx/cert/bark.rokeyyan.com.key \--ca-file /srv/nginx/cert/bark.rokeyyan.com.ca \--fullchain-file /srv/nginx/cert/bark.rokeyyan.com.fullchain \--reloadcmd "sudo docker restart nginx"</code></pre><h3 id="CRON-表达式"><a href="#CRON-表达式" class="headerlink" title="CRON 表达式"></a>CRON 表达式</h3><pre><code>2 0 * * * "/home/rokey/.acme.sh"/acme.sh --cron --home "/home/rokey/.acme.sh" &gt; /dev/null40 3 * * 4 sh -c '/srv/nginx/applyssl.sh'0 4 * * 4 sh -c '/srv/nginx/autossl.sh'</code></pre>]]>
    </content>
    <id>https://www.rokeyyan.com/2022/06/02/2022-06-03-acme-jiao-ben-zi-dong-xu-qi-https-zheng-shu/</id>
    <link href="https://www.rokeyyan.com/2022/06/02/2022-06-03-acme-jiao-ben-zi-dong-xu-qi-https-zheng-shu/"/>
    <published>2022-06-02T16:00:00.000Z</published>
    <summary>
      <![CDATA[<p>泛域名证书太贵，单域名证书一年一续，域名多了也很麻烦，幸好有github可以抱大佬大腿，ACME自动化续期HTTPS证书<a href="https://github.com/acmesh-official/acme.sh/wiki/%E8%AF%B4%E6%98%8E">]]>
    </summary>
    <title>ACME脚本自动续期HTTPS证书</title>
    <updated>2022-06-02T16:00:00.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>rokey</name>
    </author>
    <category term="随笔" scheme="https://www.rokeyyan.com/categories/%E9%9A%8F%E7%AC%94/"/>
    <category term="笔记" scheme="https://www.rokeyyan.com/tags/%E7%AC%94%E8%AE%B0/"/>
    <content>
      <![CDATA[<p>Caddy是一款基于Go语言编写的强大且可扩展的平台，可以给你的站点、服务和应用程序提供服务。如果你是Caddy的新手，那么你提供Web服务的方式即将改变。</p><p>仅因为该http服务器支持自动https插件,此处留作备忘</p><p><strong><a href="https://caddy2.dengxiaolong.com/docs/">https://caddy2.dengxiaolong.com/docs/</a></strong></p>]]>
    </content>
    <id>https://www.rokeyyan.com/2022/06/02/2022-06-03-caddy/</id>
    <link href="https://www.rokeyyan.com/2022/06/02/2022-06-03-caddy/"/>
    <published>2022-06-02T16:00:00.000Z</published>
    <summary>
      <![CDATA[<p>Caddy是一款基于Go语言编写的强大且可扩展的平台，可以给你的站点、服务和应用程序提供服务。如果你是Caddy的新手，那么你提供Web服务的方式即将改变。</p>
<p>仅因为该http服务器支持自动https插件,此处留作备忘</p>
<p><strong><a hre]]>
    </summary>
    <title>caddy</title>
    <updated>2022-06-02T16:00:00.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>rokey</name>
    </author>
    <category term="笔记" scheme="https://www.rokeyyan.com/categories/%E7%AC%94%E8%AE%B0/"/>
    <category term="笔记" scheme="https://www.rokeyyan.com/tags/%E7%AC%94%E8%AE%B0/"/>
    <content>
      <![CDATA[<p>本次实践过程全部在Docker环境下完成。<br>操作系统环境为centos7，dockerce,docker-compose,xshell、xftp 教育版等。</p><h2 id="前提"><a href="#前提" class="headerlink" title="前提"></a>前提</h2><p>需要提前准备三台独立服务器(虚拟机),每台服务器的内存至少需要<strong>4G</strong> ,实践过程会将ELK三大件分别部署在这三台服务器上，以最接近生产环境的部署方式进行学习实践。</p><hr><h2 id="docker-compose"><a href="#docker-compose" class="headerlink" title="docker-compose"></a>docker-compose</h2><hr><h3 id="docker-compose环境变量"><a href="#docker-compose环境变量" class="headerlink" title="docker-compose环境变量"></a>docker-compose环境变量</h3><p>文件命名为 <strong>.env</strong></p><pre><code>ES_VERSION=8.2.2ZOO=172.17.30.158:12181KAFKA_CFG_MAX_REQUEST_SIZE=11534336KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1KAFKA_ZOOKEEPER_CONNECTION_TIMEOUT_MS=36000KAFKA1_HOST=172.17.30.158KAFKA1_PORT=19092KAFKA2_HOST=172.17.30.160KAFKA2_PORT=19093KAFKA3_HOST=172.17.30.160KAFKA3_PORT=19094</code></pre><hr><h3 id="elasticsearch-yml"><a href="#elasticsearch-yml" class="headerlink" title="elasticsearch.yml"></a>elasticsearch.yml</h3><pre><code>version: '3.4'services:    elasticsearch:        image: "elasticsearch:${ES_VERSION}"        container_name: es        restart: always        environment:            - discovery.type=single-node            - ES_JAVA_OPTS=-Xms3g -Xmx3g        volumes:            - /etc/localtime:/etc/localtime            - /srv/elk/data:/usr/share/elasticsearch/data            - /root/elk/esconfig/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml        ports:            - "19200:9200"            - "19300:9300"        deploy:          resources:            limits:              memory: 3G        networks:          - app-networknetworks:  app-network:    driver: bridge</code></pre><hr><h3 id="elasticsearch-主体配置文件"><a href="#elasticsearch-主体配置文件" class="headerlink" title="elasticsearch 主体配置文件"></a>elasticsearch 主体配置文件</h3><p>映射路径为：</p><pre><code>elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml</code></pre><p>配置内容为：</p><pre><code>cluster.name: "docker-cluster"network.host: 0.0.0.0xpack.security.enabled: falsexpack.security.authc.api_key.enabled: false#discovery.type: single-nodelogger.level: erroringest.geoip.downloader.enabled: false#index.number_of_replicas: 0xpack.security.enrollment.enabled: true</code></pre><hr><h3 id="kibana-logstash"><a href="#kibana-logstash" class="headerlink" title="kibana &amp; logstash"></a>kibana &amp; logstash</h3><pre><code>version: '3.4'services:    logstash:        image: "logstash:${ES_VERSION}"        container_name: logstash        restart: always        environment:          #LOG_LEVEL: error          ES_JAVA_OPTS: -Xms1g -Xmx1g        volumes:            - ./logstash.conf:/usr/share/logstash/pipeline/logstash.conf            - ./logstash.yml:/usr/share/logstash/config/logstash.yml            - /srv/logstash/logs:/usr/share/logstash/logs        ports:            - "5044:5044"        deploy:          resources:            limits:              memory: 1G        networks:          - app-network    kibana:        image: "kibana:${ES_VERSION}"        container_name: kibana        restart: always        environment:            - ELASTICSEARCH_URL=http://172.17.30.193:19200        volumes:            - /etc/localtime:/etc/localtime            - ./kibana.yml:/usr/share/kibana/config/kibana.yml        ports:            - "5601:5601"        networks:          - app-network    metricbeat:        image: "elastic/metricbeat:${ES_VERSION}"        container_name: mb        restart: always        environment:            - setup.kibana.host=kibana:5601            - output.elasticsearch.hosts=["172.17.30.193:19200"]        depends_on:            - kibana            - logstash        volumes:            - /etc/localtime:/etc/localtime            - /root/elk/mbconfig/logstash.yml:/usr/share/metricbeat/modules.d/logstash.yml            - /root/elk/mbconfig/metricbeat.yml:/usr/share/metricbeat/metricbeat.yml        links:            - kibana            - logstash        networks:          - app-networknetworks:  app-network:    driver: bridge</code></pre><hr><h3 id="kibana-配置文件-kibana-yml"><a href="#kibana-配置文件-kibana-yml" class="headerlink" title="kibana 配置文件 kibana.yml"></a>kibana 配置文件 kibana.yml</h3><p>映射路径为：</p><pre><code>./kibana.yml:/usr/share/kibana/config/kibana.yml</code></pre><p>配置文件内容为：</p><pre><code>## ** THIS IS AN AUTO-GENERATED FILE **## Default Kibana configuration for docker targetserver.host: "0.0.0.0"server.shutdownTimeout: "5s"elasticsearch.hosts: [ "http://172.17.30.193:19200" ]monitoring.ui.container.elasticsearch.enabled: trueserver.publicBaseUrl: "https://kibana.eo.demo.ehi.com.cn"i18n.locale: "zh-CN"xpack.reporting.encryptionKey: f7df822ad927a287fb4579831c16350fxpack.security.encryptionKey: 7c98394b79e706d8f48deab2635d0c3fxpack.encryptedSavedObjects:  encryptionKey: "ae0c2bce5918f313ba192162e944d48b"   keyRotation:    decryptionOnlyKeys: ["wy80Kj77iJZlFg65nz4jolf2IKoKlymo", "6oAOsRhu86PVgdaMILLNvjh4oWulx8EG"]xpack.reporting.kibanaServer.hostname: localhostxpack.reporting.roles.enabled: false</code></pre><hr><h3 id="logstash-配置文件-logstash-yml"><a href="#logstash-配置文件-logstash-yml" class="headerlink" title="logstash 配置文件 logstash.yml"></a>logstash 配置文件 logstash.yml</h3><p>映射路径为：</p><pre><code>- ./logstash.yml:/usr/share/logstash/config/logstash.yml</code></pre><p>配置内容为：</p><pre><code>http.host: 0.0.0.0log.level: warnmonitoring.enabled: falsexpack.monitoring.elasticsearch.hosts:- http://172.17.30.193:19200</code></pre><hr><h3 id="logstash-conf"><a href="#logstash-conf" class="headerlink" title="logstash.conf"></a>logstash.conf</h3><p>映射路径为：</p><pre><code>- ./logstash.conf:/usr/share/logstash/pipeline/logstash.conf</code></pre><p>配置文件为：</p><pre><code>input {  kafka {      bootstrap_servers =&gt; "172.17.30.158:19092,172.17.30.160:19093,172.17.30.160:19094"      consumer_threads =&gt; 10      group_id =&gt; "eolog"      auto_commit_interval_ms =&gt; 1000      topics =&gt; ["csenterprisecarrentalapilog","csenterprisecarrentalapiaudit","csenterprisecarrentalapirequest"]      decorate_events =&gt; "basic"     # auto_offset_reset =&gt; "latest"      auto_offset_reset =&gt; "earliest"      #auto_offset_reset =&gt; "none"      max_partition_fetch_bytes =&gt; 104857600  }}filter {      json {           source =&gt; "message"             #将message字段进行解析           skip_on_invalid_json =&gt; true    #无效的json则跳过           remove_field =&gt; ["message"]     #删除message字段      }            # json {      #      source =&gt; "[message][responseData]"             #将responseData字段进行解析      #      target =&gt; "[message][responseData]"      #      skip_on_invalid_json =&gt; true    #无效的json则跳过      #     #  remove_field =&gt; ["responseData"]     #删除message字段      # }    #增加一个字段，计算 timestamp 8小时    ruby {        code =&gt; "event.set('timestamp', event.get('@timestamp').time.utc+8*60*60)"    }    #用 mutate 插件先转换为 string 类型，gsub只处理string类型的数据    #再用正则匹配，最终得到想要的日期    mutate {        convert =&gt; ["timestamp", "string"]        gsub =&gt; ["timestamp", "T([\S\s]*?)Z", ""]        gsub =&gt; ["timestamp", "-", "."]   }} output {    if [@metadata][kafka][topic] == "csenterprisecarrentalapirequest" {    elasticsearch {    hosts =&gt; ["172.17.30.193:19200"]    index =&gt; "csenterprisecarrentalapirequest-%{timestamp}"    }  }  else if [@metadata][kafka][topic] == "csenterprisecarrentalapiaudit" {    elasticsearch {    hosts =&gt; ["172.17.30.193:19200"]    index =&gt; "csenterprisecarrentalapiaudit-%{timestamp}"    }  }  else if [@metadata][kafka][topic] == "csenterprisecarrentalapilog" {    elasticsearch {    hosts =&gt; ["172.17.30.193:19200"]    index =&gt; "csenterprisecarrentalapilog-%{timestamp}"    }  }   #stdout { codec =&gt; rubydebug }  }</code></pre><hr><h3 id="metricbeat-监控"><a href="#metricbeat-监控" class="headerlink" title="metricbeat 监控"></a>metricbeat 监控</h3><p>配置文件名为：metricbeat.yml<br>映射路径为：</p><pre><code>metricbeat.yml:/usr/share/metricbeat/metricbeat.yml</code></pre><p>配置内容为：</p><pre><code>metricbeat.config.modules:  path: ${path.config}/modules.d/*.yml  reload.enabled: falseprocessors:  - add_cloud_metadata: ~  - add_docker_metadata: ~output.elasticsearch:  hosts: ["https://172.17.30.193:19200"]  username: '${ELASTICSEARCH_USERNAME:}'  password: '${ELASTICSEARCH_PASSWORD:}'</code></pre><hr><h3 id="kafka-master"><a href="#kafka-master" class="headerlink" title="kafka-master"></a>kafka-master</h3><pre><code>version: '3.4'services:#  kafka-ui    kafka-ui:      container_name: kafka-ui      hostname: kafka-ui      restart: always      image: provectuslabs/kafka-ui:latest      ports:        - 8080:8080      depends_on:        - zookeeper        - kafka      environment:        KAFKA_CLUSTERS_0_NAME: kafka1        KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: ${KAFKA1_HOST}:${KAFKA1_PORT}        KAFKA_CLUSTERS_0_ZOOKEEPER: zookeeper:2181        KAFKA_CLUSTERS_1_NAME: kafka2        KAFKA_CLUSTERS_1_BOOTSTRAPSERVERS: ${KAFKA2_HOST}:${KAFKA2_PORT}        KAFKA_CLUSTERS_1_ZOOKEEPER: zookeeper:2181        KAFKA_CLUSTERS_2_NAME: kafka3        KAFKA_CLUSTERS_2_BOOTSTRAPSERVERS: ${KAFKA3_HOST}:${KAFKA3_PORT}        KAFKA_CLUSTERS_2_ZOOKEEPER: zookeeper:2181      links:        - zookeeper        - kafka      networks:        - app-network#   zookeeper    zookeeper:      image: wurstmeister/zookeeper      container_name: zoo      restart: always      volumes:        - /srv/zookeeper/data:/data      ports:        - 12181:2181      networks:        - app-network#   zoo-ui    zoo-ui:      image: elkozmon/zoonavigator      container_name: zoo-ui      restart: always      environment:        HTTP_PORT: 9000      ports:        - 19000:9000      networks:        - app-network# kafka-master       kafka:      image: wurstmeister/kafka      container_name: kafka      restart: always      ports:        - ${KAFKA1_PORT}:${KAFKA1_PORT}      environment:        KAFKA_BROKER_ID: 1        KAFKA_LISTENERS: PLAINTEXT://:9092,PLAINTEXT_DOCKER://:${KAFKA1_PORT}        KAFKA_ADVERTISED_HOST_NAME: ${KAFKA1_HOST}        KAFKA_ADVERTISED_PORT: ${KAFKA1_PORT}        KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://:9092,PLAINTEXT_DOCKER://${KAFKA1_HOST}:${KAFKA1_PORT}        KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_DOCKER:PLAINTEXT        KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT_DOCKER        KAFKA_LOG4J_ROOT_LOGLEVEL: ERROR        KAFKA_TOOLS_LOG4J_LOGLEVEL: ERROR        KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"        KAFKA_ZOOKEEPER_CONNECT: ${ZOO}        KAFKA_CFG_MAX_REQUEST_SIZE: ${KAFKA_CFG_MAX_REQUEST_SIZE}        KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: ${KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR}        KAFKA_ZOOKEEPER_CONNECTION_TIMEOUT_MS: ${KAFKA_ZOOKEEPER_CONNECTION_TIMEOUT_MS}      volumes:        - /srv/kafka:/kafka      deploy:        resources:          limits:            memory: 800M       depends_on:        - zookeeper      links:        - zookeeper      networks:        - app-networknetworks:  app-network:    driver: bridge</code></pre><hr><h3 id="kafka-node"><a href="#kafka-node" class="headerlink" title="kafka-node"></a>kafka-node</h3><pre><code>version: '3.4'services:       kafka2:      image: wurstmeister/kafka      container_name: kafka2      restart: always      ports:        - ${KAFKA2_PORT}:${KAFKA2_PORT}      environment:        KAFKA_BROKER_ID: 2        KAFKA_LISTENERS: PLAINTEXT://:9092,PLAINTEXT_DOCKER://:${KAFKA2_PORT}        KAFKA_ADVERTISED_HOST_NAME: ${KAFKA2_HOST}        KAFKA_ADVERTISED_PORT: ${KAFKA2_PORT}        KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://:9092,PLAINTEXT_DOCKER://${KAFKA2_HOST}:${KAFKA2_PORT}        KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_DOCKER:PLAINTEXT        KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT_DOCKER        KAFKA_LOG4J_ROOT_LOGLEVEL: ERROR        KAFKA_TOOLS_LOG4J_LOGLEVEL: ERROR        KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"        KAFKA_ZOOKEEPER_CONNECT: ${ZOO}        KAFKA_CFG_MAX_REQUEST_SIZE: ${KAFKA_CFG_MAX_REQUEST_SIZE}        KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: ${KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR}        KAFKA_ZOOKEEPER_CONNECTION_TIMEOUT_MS: ${KAFKA_ZOOKEEPER_CONNECTION_TIMEOUT_MS}      volumes:        - /srv/kafka/2:/kafka      deploy:        resources:          limits:            memory: 800M      networks:        - app-network    kafka3:      image: wurstmeister/kafka      container_name: kafka3      restart: always      ports:        - ${KAFKA3_PORT}:${KAFKA3_PORT}      environment:        KAFKA_BROKER_ID: 3        KAFKA_LISTENERS: PLAINTEXT://:9092,PLAINTEXT_DOCKER://:${KAFKA3_PORT}        KAFKA_ADVERTISED_HOST_NAME: ${KAFKA3_HOST}        KAFKA_ADVERTISED_PORT: ${KAFKA3_PORT}        KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://:9092,PLAINTEXT_DOCKER://${KAFKA3_HOST}:${KAFKA3_PORT}        KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_DOCKER:PLAINTEXT        KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT_DOCKER        KAFKA_LOG4J_ROOT_LOGLEVEL: ERROR        KAFKA_TOOLS_LOG4J_LOGLEVEL: ERROR        KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"        KAFKA_ZOOKEEPER_CONNECT: ${ZOO}        KAFKA_CFG_MAX_REQUEST_SIZE: ${KAFKA_CFG_MAX_REQUEST_SIZE}        KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: ${KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR}        KAFKA_ZOOKEEPER_CONNECTION_TIMEOUT_MS: ${KAFKA_ZOOKEEPER_CONNECTION_TIMEOUT_MS}      volumes:        - /srv/kafka/3:/kafka      deploy:        resources:          limits:            memory: 800M      networks:        - app-networknetworks:  app-network:    driver: bridge</code></pre><hr><h2 id="注意"><a href="#注意" class="headerlink" title="注意"></a>注意</h2><h3 id="kafka集群与单体实例"><a href="#kafka集群与单体实例" class="headerlink" title="kafka集群与单体实例"></a>kafka集群与单体实例</h3><p>kafka集群与单体实例在docker环节下的访问与注册比较大的差异。</p><ul><li><p>单体情况下,各服务直接允许直接使用links方式直接使用service别称访问kafka服务。</p></li><li><p>在集群环境下，需要特别关注kafka的几个配置,</p><ul><li><strong>KAFKA_LISTENERS</strong> ,kafka容器内部监听的地址集合，通常情况下只需要监听默认的9092即可，但集群条件下，特别是kafka的节点分布在不同主键的情况下，还需要监听一个专门用来提供对外服务的端口，该端口会直接与宿主机端口进行映射，对外提供服务,其中 <strong>PLAINTEXT</strong> 是协议类型，像docker集群环境下一般会出现至少2个监听端口，一个对内一个对外，此时如果协议相同的情况，还需要对协议取别名，利用的是 <strong>KAFKA_LISTENER_SECURITY_PROTOCOL_MAP</strong> 环境变量。需要特别注意的是<strong>KAFKA_LISTENERS</strong> 仅需要监听端口，一般不需要定义host部分</li><li><strong>KAFKA_ADVERTISED_LISTENERS</strong> 这个环境变量表示的是外部kafka客户端访问服务器端时可以使用的endpoint集合，单机情况下与<strong>KAFKA_LISTENERS</strong> 相同。集群条件下需要同时声明docker网络环节下的别名访问地址(//kafka:9200),还有外部客户端访问宿主机端口的地址定义(172.17.30.158:19200),其中 <strong>19200</strong> 其实是提前约定好的宿主机端口，为了统一一般将kafka容器内的自定义监听端口也设置成这个，方便管理和区分</li><li><strong>KAFKA_ADVERTISED_HOST_NAME</strong> ,kafka对外部主机提供服务的地址(一般就是宿主机的ip地址)</li><li><strong>KAFKA_ADVERTISED_PORT</strong> ,kafka对外部主机提供服务的端口,就是上一条说过的 <strong>19200</strong></li></ul><p>KAFKA_LISTENERS: PLAINTEXT://:9092,PLAINTEXT_DOCKER://:${KAFKA3_PORT}<br>KAFKA_ADVERTISED_HOST_NAME: ${KAFKA3_HOST}<br>KAFKA_ADVERTISED_PORT: ${KAFKA3_PORT}<br>KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://:9092,PLAINTEXT_DOCKER://${KAFKA3_HOST}:${KAFKA3_PORT}<br>KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_DOCKER:PLAINTEXT<br>KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT_DOCKER</p></li></ul><h3 id="kibana与es主机分离"><a href="#kibana与es主机分离" class="headerlink" title="kibana与es主机分离"></a>kibana与es主机分离</h3><p>kibana与es主机分离后再需要连接回去，只能通过es的宿主机映射地址访问，并且需要在es启动完成后，重启kibana服务，才会生效，否则每次kibana容器重启后，都会要求手动填token或者输入kibana验证码。</p><h2 id="补充"><a href="#补充" class="headerlink" title="补充"></a>补充</h2><h3 id="es定时清理脚本"><a href="#es定时清理脚本" class="headerlink" title="es定时清理脚本"></a>es定时清理脚本</h3><pre><code>########################################删除早于十天的ES集群的索引########################################!/bin/bashrange=5if [ -n "$1" ]; then   range=$1fiindexs=` curl -X GET 'http://localhost:19200/_cat/indices?v' | awk '&amp;#123;print $3&amp;#125;' | grep -vE '(kibana|index|watcher|monitoring)'`for index in $indexs  do     echo "启动清理流程-$index"     curl  -X POST "localhost:19200/$index/_delete_by_query?pretty" -H 'Content-Type:application/json' -d '      &amp;#123;         "query": &amp;#123;               "bool": &amp;#123;                   "must": [                      &amp;#123;                        "range": &amp;#123;                           "@timestamp": &amp;#123;                               "lte": "now-'$&amp;#123;range&amp;#125;'d/d"                              &amp;#125;                         &amp;#125;                     &amp;#125;                   ],                   "must_not": []              &amp;#125;           &amp;#125;       &amp;#125;'     echo "已清除$index 索引内$range 天前数据~"   done</code></pre>]]>
    </content>
    <id>https://www.rokeyyan.com/2022/05/27/2022-05-28-elk-cluster-deployment/</id>
    <link href="https://www.rokeyyan.com/2022/05/27/2022-05-28-elk-cluster-deployment/"/>
    <published>2022-05-27T16:00:00.000Z</published>
    <summary>
      <![CDATA[<p>本次实践过程全部在Docker环境下完成。<br>操作系统环境为centos7，dockerce,docker-compose,xshell、xftp 教育版等。</p>
<h2 id="前提"><a href="#前提" class="headerlink" title=]]>
    </summary>
    <title>ELK多服务器环境部署实践</title>
    <updated>2022-05-27T16:00:00.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>rokey</name>
    </author>
    <category term="笔记" scheme="https://www.rokeyyan.com/categories/%E7%AC%94%E8%AE%B0/"/>
    <category term="笔记" scheme="https://www.rokeyyan.com/tags/%E7%AC%94%E8%AE%B0/"/>
    <content>
      <![CDATA[<h3 id="1-下载MacOS到mac上"><a href="#1-下载MacOS到mac上" class="headerlink" title="1.下载MacOS到mac上"></a>1.下载MacOS到mac上</h3><h3 id="2-启动终端，输入命令"><a href="#2-启动终端，输入命令" class="headerlink" title="2.启动终端，输入命令"></a>2.启动终端，输入命令</h3><pre><code>sudo /Applications/Install macOS Big Sur.app/Contents/Resources/createinstallmedia --volume /Volumes/硬盘分区名 -- /Applications/Install macOS Big Sur.app</code></pre><h3 id="3-输入root密码"><a href="#3-输入root密码" class="headerlink" title="3.输入root密码"></a>3.输入root密码</h3><h3 id="4-终端会警告您需要擦除外置驱动器。要继续，请在提示符下键入Y，然后按Return键"><a href="#4-终端会警告您需要擦除外置驱动器。要继续，请在提示符下键入Y，然后按Return键" class="headerlink" title="4.终端会警告您需要擦除外置驱动器。要继续，请在提示符下键入Y，然后按Return键"></a>4.终端会警告您需要擦除外置驱动器。要继续，请在提示符下键入Y，然后按Return键</h3><h3 id="5-您将看到Terminal擦除您的驱动器，然后将安装程序文件复制到您的驱动器。这将需要几分钟"><a href="#5-您将看到Terminal擦除您的驱动器，然后将安装程序文件复制到您的驱动器。这将需要几分钟" class="headerlink" title="5.您将看到Terminal擦除您的驱动器，然后将安装程序文件复制到您的驱动器。这将需要几分钟"></a>5.您将看到Terminal擦除您的驱动器，然后将安装程序文件复制到您的驱动器。这将需要几分钟</h3><h3 id="6-复制后，完成终端操作。您应该看到终端显示一条消息，说明您的驱动器已可以使用"><a href="#6-复制后，完成终端操作。您应该看到终端显示一条消息，说明您的驱动器已可以使用" class="headerlink" title="6.复制后，完成终端操作。您应该看到终端显示一条消息，说明您的驱动器已可以使用"></a>6.复制后，完成终端操作。您应该看到终端显示一条消息，说明您的驱动器已可以使用</h3>]]>
    </content>
    <id>https://www.rokeyyan.com/2021/03/20/2021-03-21-macos-boot-disk-make/</id>
    <link href="https://www.rokeyyan.com/2021/03/20/2021-03-21-macos-boot-disk-make/"/>
    <published>2021-03-20T16:00:00.000Z</published>
    <summary>
      <![CDATA[<h3 id="1-下载MacOS到mac上"><a href="#1-下载MacOS到mac上" class="headerlink" title="1.下载MacOS到mac上"></a>1.下载MacOS到mac上</h3><h3 id="2-启动终端，输入命令"><a h]]>
    </summary>
    <title>MacOS 硬盘启动盘制作</title>
    <updated>2021-03-20T16:00:00.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>rokey</name>
    </author>
    <category term="笔记" scheme="https://www.rokeyyan.com/categories/%E7%AC%94%E8%AE%B0/"/>
    <category term="笔记" scheme="https://www.rokeyyan.com/tags/%E7%AC%94%E8%AE%B0/"/>
    <content>
      <![CDATA[<p>最近几款用的很爽的插件被下架了,网上找到几个大佬重新装上已下架扩展的办法,这里记录下</p><h3 id="从现有环境中打包已下架扩展"><a href="#从现有环境中打包已下架扩展" class="headerlink" title="从现有环境中打包已下架扩展"></a>从现有环境中打包已下架扩展</h3><ul><li><p>打包<br><img src="/2020/02/09/note/google-extentsions/2.png" alt="打包"></p></li><li><p>Google 扩展默认安装目录</p><p>C:\Users\33418\AppData\Local\Google\Chrome\User Data\Default\Extensions</p></li></ul><h3 id="修改crx文件扩展名为rar"><a href="#修改crx文件扩展名为rar" class="headerlink" title="修改crx文件扩展名为rar"></a>修改crx文件扩展名为rar</h3><h3 id="解压文件"><a href="#解压文件" class="headerlink" title="解压文件"></a>解压文件</h3><h3 id="打开google-扩展管理"><a href="#打开google-扩展管理" class="headerlink" title="打开google 扩展管理"></a>打开google 扩展管理</h3><pre><code>chrome://extensions</code></pre><p><img src="/2020/02/09/note/google-extentsions/1.png" alt="扩展管理"></p><h3 id="开启开发模式"><a href="#开启开发模式" class="headerlink" title="开启开发模式"></a>开启开发模式</h3><h3 id="加载已解压的扩展程序"><a href="#加载已解压的扩展程序" class="headerlink" title="加载已解压的扩展程序"></a>加载已解压的扩展程序</h3><p>可能会出现加载失败的情况，多试几次就行了</p>]]>
    </content>
    <id>https://www.rokeyyan.com/2020/02/08/2020-02-09-google-extentsions/</id>
    <link href="https://www.rokeyyan.com/2020/02/08/2020-02-09-google-extentsions/"/>
    <published>2020-02-08T16:00:00.000Z</published>
    <summary>
      <![CDATA[<p>最近几款用的很爽的插件被下架了,网上找到几个大佬重新装上已下架扩展的办法,这里记录下</p>
<h3 id="从现有环境中打包已下架扩展"><a href="#从现有环境中打包已下架扩展" class="headerlink" title="从现有环境中打包已下架扩展"><]]>
    </summary>
    <title>google 打包 安装 已下架 扩展</title>
    <updated>2020-02-08T16:00:00.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>rokey</name>
    </author>
    <category term="笔记" scheme="https://www.rokeyyan.com/categories/%E7%AC%94%E8%AE%B0/"/>
    <category term="笔记" scheme="https://www.rokeyyan.com/tags/%E7%AC%94%E8%AE%B0/"/>
    <content>
      <![CDATA[<p>入手github超热门机器学习项目<a href="https://github.com/deepfakes/faceswap">faceswap</a></p><h3 id="安装环境-windows"><a href="#安装环境-windows" class="headerlink" title="安装环境(windows)"></a>安装环境(windows)</h3><p>一般建议直接使用Docker 方式启动项目,这里由于开发机器太垃圾了,只在win下安装启动了一遍,显存不足,跑一会儿就挂了,这里记录下环境配置过程</p><ul><li><p>Python 版本建议 3.6+,<a href="https://www.python.org/downloads/">Python</a></p></li><li><p>Tensorflow版本建议(1.15.0),<a href="https://pypi.tuna.tsinghua.edu.cn/simple/tensorflow-gpu/">Tensorflow</a></p></li><li><p>N卡用户 CUDA(10.0),cudnn(7.6.4.38),win下安装包需要到N卡官网找,需要注册为开发者<br><a href="https://developer.nvidia.com/cuda-toolkit-archive">CUDA</a><br><a href="https://developer.nvidia.com/rdp/cudnn-download">CUDNN</a></p></li><li><p>其他Python包</p><p>python -m pip install –upgrade psutil pathlib numpy==1.17.4 opencv-python==4.1.2.30 scikit-image Pillow==6.2.1 toposort fastcluster matplotlib==3.1.1 ffmpy==0.2.2 git+<a href="https://github.com/deepfakes/nvidia-ml-py3.git">https://github.com/deepfakes/nvidia-ml-py3.git</a> Keras==2.2.4</p></li></ul><h3 id="启动项目初始化"><a href="#启动项目初始化" class="headerlink" title="启动项目初始化"></a>启动项目初始化</h3><pre><code>python setup.py</code></pre><h3 id="win下启动UI"><a href="#win下启动UI" class="headerlink" title="win下启动UI"></a>win下启动UI</h3><pre><code>python faceswap.py gui</code></pre><h3 id="Linux-启动训练"><a href="#Linux-启动训练" class="headerlink" title="Linux 启动训练"></a>Linux 启动训练</h3><pre><code>python faceswap.py train -A res/images/lzll_dzq_a -B res/images/lzll_dzq_b -m res/model/lzll_dzq -t original -bs 64 -it 1000000 -g 1 -s 100 -ss 25000 -ps 50 -L INFO</code></pre>]]>
    </content>
    <id>https://www.rokeyyan.com/2020/02/05/2020-02-06-faceswap-01/</id>
    <link href="https://www.rokeyyan.com/2020/02/05/2020-02-06-faceswap-01/"/>
    <published>2020-02-05T16:00:00.000Z</published>
    <summary>
      <![CDATA[<p>入手github超热门机器学习项目<a href="https://github.com/deepfakes/faceswap">faceswap</a></p>
<h3 id="安装环境-windows"><a href="#安装环境-windows" class="he]]>
    </summary>
    <title>faceswap-入门(一)</title>
    <updated>2020-02-05T16:00:00.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>rokey</name>
    </author>
    <category term="笔记" scheme="https://www.rokeyyan.com/categories/%E7%AC%94%E8%AE%B0/"/>
    <category term="笔记" scheme="https://www.rokeyyan.com/tags/%E7%AC%94%E8%AE%B0/"/>
    <content>
      <![CDATA[<p>基本概念</p><h3 id="Extract"><a href="#Extract" class="headerlink" title="Extract"></a>Extract</h3><ul><li><p>从视频或图片集合文件中提取脸部图像及 脸部图像坐标图数据(alignments)</p></li><li><p>alignments 坐标再调整输出脸部图像有变化后需要使用tools 工具集整理坐标图数据 Tools -&gt; Alignments -&gt; Remove-face<br>需要输入如下信息：</p><ul><li>原始坐标文件</li><li>已整理过的脸部图像文件夹</li></ul></li><li><p><strong>训练资源优化</strong></p><ul><li>sort</li></ul></li></ul><p><img src="/2020/02/06/note/faceswap-02/sort2.jpg" alt="face资源排序筛选"><br>    * ali-&gt;remove faces 根据排序后face目录校正 路线文件<br><img src="/2020/02/06/note/faceswap-02/align4.jpg" alt="线路文件针对face资源重排"><br>    * ali-&gt;rename 重命名face目录默认文件名<br><img src="/2020/02/06/note/faceswap-02/align7.jpg" alt="修复线路"><br>    * ali-&gt;manual 根据原始视频校正路线<br><img src="/2020/02/06/note/faceswap-02/align11.jpg" alt="根据原始视频校正路线"><br>    * ali-&gt;extract 根据校正后的路线文件重新从原始视频中提出脸部图像，需要提前删除旧的face资源<br><img src="/2020/02/06/note/faceswap-02/%E6%A0%B9%E6%8D%AE%E4%BF%AE%E5%A4%8D%E8%BF%87%E7%9A%84%E8%B7%AF%E7%BA%BF%E9%87%8D%E6%96%B0%E6%8F%90%E5%87%BAface%E8%B5%84%E6%BA%90" alt="align13.jpg"></p><h3 id="Convert"><a href="#Convert" class="headerlink" title="Convert"></a>Convert</h3><ul><li>InPutDir:待替换脸部的视频文件</li><li>OutPutDir:视频输出目录</li><li>alignments:待替换视频文件的脸部定位资源文件</li><li>ModelDir:训练模型输出文件目录</li></ul><p>可以按照如上步骤实现A-&gt;B 或者 B-&gt;A 只要有对应原始视频文件和脸部定位资源文件</p>]]>
    </content>
    <id>https://www.rokeyyan.com/2020/02/05/2020-02-06-faceswap-02/</id>
    <link href="https://www.rokeyyan.com/2020/02/05/2020-02-06-faceswap-02/"/>
    <published>2020-02-05T16:00:00.000Z</published>
    <summary>
      <![CDATA[<p>基本概念</p>
<h3 id="Extract"><a href="#Extract" class="headerlink" title="Extract"></a>Extract</h3><ul>
<li><p>从视频或图片集合文件中提取脸部图像及 脸部图像坐标图数据(]]>
    </summary>
    <title>faceswap-入门(二)</title>
    <updated>2020-02-05T16:00:00.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>rokey</name>
    </author>
    <category term="笔记" scheme="https://www.rokeyyan.com/categories/%E7%AC%94%E8%AE%B0/"/>
    <category term="笔记" scheme="https://www.rokeyyan.com/tags/%E7%AC%94%E8%AE%B0/"/>
    <content>
      <![CDATA[<h2 id="单机docker-启用-daemon-守护进程"><a href="#单机docker-启用-daemon-守护进程" class="headerlink" title="单机docker 启用 daemon 守护进程"></a><strong>单机docker 启用 daemon 守护进程</strong></h2><h3 id="增加daemon-json"><a href="#增加daemon-json" class="headerlink" title="增加daemon.json"></a>增加daemon.json</h3><ul><li><p>路径<br>Linux: <strong>etc/docker/daemon.json</strong><br>Windows: <strong>C:\ProgramData\docker\config\daemon.json</strong></p></li><li><p>内容如下:</p><pre><code>&amp;#123;"debug": true,"tls": true,"tlscert": "/var/docker/server.pem","tlskey": "/var/docker/serverkey.pem","hosts": ["tcp://192.168.59.3:2376","unix:///var/bin/docker.sock"]&amp;#125;</code></pre></li><li><p>也可以直接通过启动命令设置(<strong>建议用配置文件方式</strong>)</p><pre><code>dockerd --debug \--tls=true \--tlscert=/var/docker/server.pem \--tlskey=/var/docker/serverkey.pem \--host tcp://192.168.59.3:2376</code></pre></li></ul><h3 id="增加dockerd默认启动配置"><a href="#增加dockerd默认启动配置" class="headerlink" title="增加dockerd默认启动配置"></a>增加dockerd默认启动配置</h3><ul><li><p>路径<br>/etc/systemd/system/docker.service.d/docker.conf</p><p>[Service]<br>ExecStart=<br>ExecStart=/usr/bin/dockerd</p></li></ul><h3 id="配置完成后需要执行如下命令-以centos为例"><a href="#配置完成后需要执行如下命令-以centos为例" class="headerlink" title="配置完成后需要执行如下命令(以centos为例)"></a>配置完成后需要执行如下命令(以centos为例)</h3><pre><code>systemctl reload-daemonsystemctl reset-failed dockersystemctl start docker</code></pre><h3 id="启用debug后可以查看启动失败的相关日志"><a href="#启用debug后可以查看启动失败的相关日志" class="headerlink" title="启用debug后可以查看启动失败的相关日志"></a>启用debug后可以查看启动失败的相关日志</h3><table><thead><tr><th>系统</th><th>路径</th></tr></thead><tbody><tr><td>RHEL, Oracle Linux</td><td>/var/log/messages</td></tr><tr><td>Debian</td><td>/var/log/daemon.log</td></tr><tr><td>Ubuntu 16.04+, CentOS</td><td>Use the command journalctl -u docker.service</td></tr><tr><td>Ubuntu 14.10-</td><td>/var/log/upstart/docker.log</td></tr><tr><td>macOS (Docker 18.01+)</td><td>~/Library/Containers/com.docker.docker/Data/vms/0/console-ring</td></tr><tr><td>macOS (Docker &lt;18.01)</td><td>~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/console-ring</td></tr><tr><td>Windows</td><td>AppData\Local</td></tr></tbody></table>]]>
    </content>
    <id>https://www.rokeyyan.com/2020/02/01/2020-02-02-enable-docker-daemon/</id>
    <link href="https://www.rokeyyan.com/2020/02/01/2020-02-02-enable-docker-daemon/"/>
    <published>2020-02-01T16:00:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="单机docker-启用-daemon-守护进程"><a href="#单机docker-启用-daemon-守护进程" class="headerlink" title="单机docker 启用 daemon 守护进程"></a><strong>单机docker]]>
    </summary>
    <title>启用 docker daemon 守护进程</title>
    <updated>2020-02-01T16:00:00.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>rokey</name>
    </author>
    <category term="笔记" scheme="https://www.rokeyyan.com/categories/%E7%AC%94%E8%AE%B0/"/>
    <category term="笔记" scheme="https://www.rokeyyan.com/tags/%E7%AC%94%E8%AE%B0/"/>
    <content>
      <![CDATA[<h2 id="EasyNetQ-使用笔记"><a href="#EasyNetQ-使用笔记" class="headerlink" title="EasyNetQ 使用笔记"></a>EasyNetQ 使用笔记</h2><h3 id="关于SubscriptionId"><a href="#关于SubscriptionId" class="headerlink" title="关于SubscriptionId"></a>关于SubscriptionId</h3><table><thead><tr><th>SubscriptionId</th><th>消息类型</th><th>消费方式</th></tr></thead><tbody><tr><td>相同</td><td>不同</td><td>视为不同消费者,每个SubscriptionId均会收到该消息类型所属队列的全部对应类型的消息</td></tr><tr><td>相同</td><td>相同</td><td>视为同一消费者，每个SubscriptionId会收到部分消息,且各订阅者不重复接收消息</td></tr><tr><td>不同</td><td>相同</td><td>视为不同消费者，每个SubscriptionId均会收到该消息类型所属队列的全部对应类型的消息</td></tr></tbody></table><h3 id="关于AutoSubscriber"><a href="#关于AutoSubscriber" class="headerlink" title="关于AutoSubscriber"></a>关于AutoSubscriber</h3><ul><li><p><strong>IConsumeAsync <messagedata></messagedata></strong>,<strong>IConsume <messagedata></messagedata></strong><br>若两个接口拥有同一个实现类,最终生效的消费方法只有一个,具体执行哪个实现方法,要看Subscribe 和 SubscribeAsync 的执行顺序,以先后顺序确定执行同步方法还是异步方法</p></li><li><p>若项目中存在多个方法订阅了同一个消息类型<br>需要主要,同一个消费类型是依据消费者所属的队列名称来自行建立队列的,如果两个消费者同时订阅一个消费类型,该交换机下会存在两个队列,使用一样的路由规则,当消息入栈以后会生成一样的副本存放于这两个队列中,等同于广播式消费,同一条消息将会分发两次到<br>若队列名称是一样的,则相当于同一个队列拥有两个消费者,此时每个消息均只会分发一次到具体消费者</p></li></ul>]]>
    </content>
    <id>https://www.rokeyyan.com/2020/02/01/2020-02-02-rabbitmq-use-node-01/</id>
    <link href="https://www.rokeyyan.com/2020/02/01/2020-02-02-rabbitmq-use-node-01/"/>
    <published>2020-02-01T16:00:00.000Z</published>
    <summary>
      <![CDATA[<h2 id="EasyNetQ-使用笔记"><a href="#EasyNetQ-使用笔记" class="headerlink" title="EasyNetQ 使用笔记"></a>EasyNetQ 使用笔记</h2><h3 id="关于SubscriptionId"><a]]>
    </summary>
    <title>RabbitMq EasyNetQ 使用笔记(一)</title>
    <updated>2020-02-01T16:00:00.000Z</updated>
  </entry>
  <entry>
    <author>
      <name>rokey</name>
    </author>
    <category term="笔记" scheme="https://www.rokeyyan.com/categories/%E7%AC%94%E8%AE%B0/"/>
    <category term="笔记" scheme="https://www.rokeyyan.com/tags/%E7%AC%94%E8%AE%B0/"/>
    <content>
      <![CDATA[<p>关于RabbitMq的一些基本概念</p><h3 id="信道"><a href="#信道" class="headerlink" title="信道"></a>信道</h3><p>如果项目需要发布消息，那么必须要链接到 RabbitMQ，而项目于 RabbitMQ之间使用 TCP 连接，加入每次发布消息都要连接TCP，这不仅会造成连接资源严重浪费，会造成服务器性能瓶颈，所以 RabbitMQ 为所有的线程只用一条 TCP 连接，怎么实现的呢？RabbitMQ 引入了信道的概念，所有需要发布消息的线程都包装成一条信道在 TCP 中传输，理论上 一条 TCP 连接支持无限多个信道，模型如下：<br><img src="/2020/02/02/note/rabbitmq-use-node-02/rabbit_mq_3.png" alt="信道"></p><h3 id="队列"><a href="#队列" class="headerlink" title="队列"></a>队列</h3><p>消息队列，用来保存消息直到发送给消费者。它是消息的容器，也是消息的终点。一个消息可投入一个或多个队列。消息一直在队列里面，等待消费者连接到这个队列将其取走。</p><h3 id="绑定"><a href="#绑定" class="headerlink" title="绑定"></a>绑定</h3><p>绑定，用于消息队列和交换器之间的关联。一个绑定就是基于路由键将交换器和消息队列连接起来的路由规则，所以可以将交换器理解成一个由绑定构成的路由表，如下：</p><p><img src="/2020/02/02/note/rabbitmq-use-node-02/rabbit_mq_4.png" alt="绑定"></p><h3 id="交换器"><a href="#交换器" class="headerlink" title="交换器"></a>交换器</h3><p>我们向 RabbitMQ 发送消息，实际上是把消息发到交换器了，再由交换器根据相关路由规则发到特定队列上，在队列上监听的消费者就可以进行消费了，目前 RabbitMQ 共四种类型：direct、fanout、topic、headers 。headers 匹配 AMQP 消息的 header 而不是路由键，此外 headers 交换器和 direct 交换器完全一致，但性能差很多，目前几乎用不到了，所以直接看另外三种类型：</p><h4 id="direct交换器"><a href="#direct交换器" class="headerlink" title="direct交换器"></a>direct交换器</h4><p>消息中的路由键（routing key）如果和 Binding 中的 binding key 一致， 交换器就将消息发到对应的队列中。路由键与队列名完全匹配，如果一个队列绑定到交换机要求路由键为“dog”，则只转发 routing key 标记为“dog”的消息，不会转发“dog.puppy”，也不会转发“dog.guard”等等。它是完全匹配、单播的模式。<br><img src="/2020/02/02/note/rabbitmq-use-node-02/rabbit_mq_5.png" alt="direct交换器"></p><h4 id="fanout交换器"><a href="#fanout交换器" class="headerlink" title="fanout交换器"></a>fanout交换器</h4><p>每个发送到 fanout 交换器中的消息，他不会去匹配路由键，直接把消息投递到所有绑定到 fanout 交换器中的队列上，它就像一个广播站一样，它会向所有收听广播的用户发送消息。对应到系统上，它允许你针对一个消息作不同操作，比如用户上传了一张新的图片，系统要同时对这个事件进行不同的操作，比如删除旧的图片缓存、增加积分奖励等等。这样就大大降低了系统之间的耦合度了。<br><img src="/2020/02/02/note/rabbitmq-use-node-02/rabbit_mq_6.png" alt="fanout交换器"></p><h4 id="topic交换器"><a href="#topic交换器" class="headerlink" title="topic交换器"></a>topic交换器</h4><p>topic 交换器有点类似于 direct 交换器，它通过模式匹配分配消息的路由键属性，将路由键和某个模式进行匹配，此时队列需要绑定到一个模式上。它将路由键和绑定键的字符串切分成单词，这些单词之间用点隔开。它同样也会识别两个通配符：符号“#”和符号“”。#匹配0个或多个单词，匹配不多不少一个单词。<br><img src="/2020/02/02/note/rabbitmq-use-node-02/rabbit_mq_7.png" alt="topic交换器"></p><p>转载：<a href="https://objcoding.com/2018/10/16/rabbitmq/#%E4%BF%A1%E9%81%93">RabbitMQ的一些基本概念</a></p>]]>
    </content>
    <id>https://www.rokeyyan.com/2020/02/01/2020-02-02-rabbitmq-use-node-02/</id>
    <link href="https://www.rokeyyan.com/2020/02/01/2020-02-02-rabbitmq-use-node-02/"/>
    <published>2020-02-01T16:00:00.000Z</published>
    <summary>
      <![CDATA[<p>关于RabbitMq的一些基本概念</p>
<h3 id="信道"><a href="#信道" class="headerlink" title="信道"></a>信道</h3><p>如果项目需要发布消息，那么必须要链接到 RabbitMQ，而项目于 RabbitMQ之间使]]>
    </summary>
    <title>RabbitMq EasyNetQ 使用笔记(二)</title>
    <updated>2020-02-01T16:00:00.000Z</updated>
  </entry>
</feed>
