-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.xml
165 lines (79 loc) · 38.2 KB
/
search.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>缓存淘汰算法 LRU/LFU 对比</title>
<link href="2021/01/11/%E7%BC%93%E5%AD%98%E6%B7%98%E6%B1%B0%E7%AE%97%E6%B3%95-LRU-LFU-%E5%AF%B9%E6%AF%94/"/>
<url>2021/01/11/%E7%BC%93%E5%AD%98%E6%B7%98%E6%B1%B0%E7%AE%97%E6%B3%95-LRU-LFU-%E5%AF%B9%E6%AF%94/</url>
<content type="html"><![CDATA[<h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>缓存淘汰算法是指:在有限容量的 list 中,空间被占满后要存入新的 item 时,决定出那个数据应该被剔除剔除的一类算法。<br>其核心是为了计算出哪个 item 应该被剔除,也就是淘汰机制。</p><h1 id="介绍"><a href="#介绍" class="headerlink" title="介绍"></a>介绍</h1><h2 id="LRU-Least-Recently-Used-最近最少使用"><a href="#LRU-Least-Recently-Used-最近最少使用" class="headerlink" title="LRU (Least Recently Used / 最近最少使用)"></a>LRU (Least Recently Used / 最近最少使用)</h2><p><strong>淘汰最久没有用过的元素。</strong></p><h3 id="基本思想"><a href="#基本思想" class="headerlink" title="基本思想"></a>基本思想</h3><p>如果数据过去被访问多次,那么将来被访问的频率也更高。</p><h3 id="存在的问题"><a href="#存在的问题" class="headerlink" title="存在的问题"></a>存在的问题</h3><p>偶发性的、周期性的批量查询操作(包含冷数据)会淘汰掉大量的热点数据,导致 LRU 命中率急剧下降,缓存污染情况比较严重。</p><h2 id="LFU-Least-Frequently-Used-最不经常使用"><a href="#LFU-Least-Frequently-Used-最不经常使用" class="headerlink" title="LFU (Least Frequently Used / 最不经常使用)"></a>LFU (Least Frequently Used / 最不经常使用)</h2><p><strong>淘汰访问频率最低的元素。</strong></p><p><strong>注意 LFU 和 LRU 的区别,LRU 的淘汰规则是基于访问时间,而 LFU 是基于访问次数。</strong></p><h3 id="基本思想-1"><a href="#基本思想-1" class="headerlink" title="基本思想"></a>基本思想</h3><p>如果数据最近被访问过,那么将来被访问的几率也更高。</p><h3 id="存在的问题:"><a href="#存在的问题:" class="headerlink" title="存在的问题:"></a>存在的问题:</h3><ol><li>最近加入的数据总是易于被剔除(缓存末端抖动),因为他起始的频率很低。它无法对一个拥有最初高访问率之后长时间没有被访问的条目缓存负责。</li><li>为了避免早期的热点数据一直占据缓存,即LFU算法也需有一些访问时间模式的特性。<br>但是,如果频率的时间度量是 1 小时(数据根据最近一小时内的访问次数排序),则平均每小时访问 1000 次的数据可能会比前一个小时内访问次数为 1001 的数据更优先剔除掉。</li></ol><blockquote><p>一般情况下,LFU 效率要优于 LRU,且能够避免周期性或者偶发性的操作导致缓存命中率下降的问题,但 LFU 需要记录数据的历史访问记录,一旦数据访问模式改变,LFU 需要更长时间来适用新的访问模式,即 LFU 存在历史数据影响将来数据的 <code>缓存污染</code> 问题。<br>LFU 使用计数器来记录条目被访问的频率,通过使用 LFU 缓存算法,最低访问次数的条目首先被移除,此方法并不经常使用,因为它无法对一个拥有最初高访问率之后长时间没有被访问的条目缓存负责。</p></blockquote><h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>由于两种算法的各自特点及缺点,所以在行业生产线上通常会联合两者使用。<br>我们可以在 LRU 的实现基础上稍作衍生,可以采用队列分级的思想。<br>例如 Oracle 利用两个队列维护访问的数据元素,按被访问的频率的维度把元素分别搁在热端与冷端队列;而在同一个队列内,最后访问时间越久的元素会越被排在队列尾,实现细节参考 <a href="https://database.51cto.com/art/201912/608285.htm">详解Oracle数据库LRU算法:LRU链、脏块与脏LRU链</a>。</p><h1 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h1><ol><li><a href="https://www.cnblogs.com/gisorange/p/4947868.html">https://www.cnblogs.com/gisorange/p/4947868.html</a></li><li><a href="https://melonshell.github.io/2020/02/07/ds_cache_eli">https://melonshell.github.io/2020/02/07/ds_cache_eli</a></li><li><a href="https://database.51cto.com/art/201912/608285.htm">https://database.51cto.com/art/201912/608285.htm</a></li></ol>]]></content>
<categories>
<category> Cache </category>
</categories>
<tags>
<tag> Cache </tag>
<tag> 算法 </tag>
</tags>
</entry>
<entry>
<title>Hexo 博客搭建</title>
<link href="2021/01/07/Hexo-%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/"/>
<url>2021/01/07/Hexo-%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/</url>
<content type="html"><![CDATA[<h2 id="安装-Hexo"><a href="#安装-Hexo" class="headerlink" title="安装 Hexo"></a>安装 Hexo</h2><h3 id="安装-Hexo-命令行工具"><a href="#安装-Hexo-命令行工具" class="headerlink" title="安装 Hexo 命令行工具"></a>安装 Hexo 命令行工具</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm i -g hexo-cli</span><br></pre></td></tr></table></figure><h3 id="创建博客项目"><a href="#创建博客项目" class="headerlink" title="创建博客项目"></a>创建博客项目</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo init blog</span><br></pre></td></tr></table></figure><h3 id="进入博客项目目录"><a href="#进入博客项目目录" class="headerlink" title="进入博客项目目录"></a>进入博客项目目录</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> blog</span><br></pre></td></tr></table></figure><h3 id="安装依赖"><a href="#安装依赖" class="headerlink" title="安装依赖"></a>安装依赖</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm i</span><br></pre></td></tr></table></figure><h3 id="启动服务器"><a href="#启动服务器" class="headerlink" title="启动服务器"></a>启动服务器</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo server</span><br></pre></td></tr></table></figure><h2 id="安装-Butterfly-主题"><a href="#安装-Butterfly-主题" class="headerlink" title="安装 Butterfly 主题"></a>安装 Butterfly 主题</h2><h3 id="安装主题"><a href="#安装主题" class="headerlink" title="安装主题"></a>安装主题</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly</span><br></pre></td></tr></table></figure><h3 id="应用主题"><a href="#应用主题" class="headerlink" title="应用主题"></a>应用主题</h3><p>修改站点配置文件 <code>_config.yaml</code>,把主题改为 <code>butterfly</code></p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">theme:</span> <span class="string">butterfly</span></span><br></pre></td></tr></table></figure><h3 id="安裝-Pug-插件"><a href="#安裝-Pug-插件" class="headerlink" title="安裝 Pug 插件"></a>安裝 Pug 插件</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm i hexo-renderer-pug --save</span><br></pre></td></tr></table></figure><h3 id="安装字数统计插件"><a href="#安装字数统计插件" class="headerlink" title="安装字数统计插件"></a>安装字数统计插件</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm i hexo-wordcount --save</span><br></pre></td></tr></table></figure><h3 id="安装搜索插件"><a href="#安装搜索插件" class="headerlink" title="安装搜索插件"></a>安装搜索插件</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm i hexo-generator-search --save</span><br></pre></td></tr></table></figure><h3 id="安装-RSS-插件"><a href="#安装-RSS-插件" class="headerlink" title="安装 RSS 插件"></a>安装 RSS 插件</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm i hexo-generator-feed --save</span><br></pre></td></tr></table></figure><p><code>_config.xml</code> 添加</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">feed:</span><br><span class="line"> # Generate both atom and rss2 feeds</span><br><span class="line"> type: atom</span><br><span class="line"> path: atom.xml</span><br></pre></td></tr></table></figure><h2 id="添加-tag-和-categories"><a href="#添加-tag-和-categories" class="headerlink" title="添加 tag 和 categories"></a>添加 tag 和 categories</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo new page <span class="string">"tags"</span></span><br></pre></td></tr></table></figure><p>将 <code>source/tags</code> 文件夹下 <code>index.md</code> 文件里的内容修改为</p><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">---</span><br><span class="line">title: 标签</span><br><span class="line">type: "tags"</span><br><span class="line">comments: false</span><br><span class="line">---</span><br></pre></td></tr></table></figure><p>categories 同理</p><h2 id="部署到-GitHub-Pages"><a href="#部署到-GitHub-Pages" class="headerlink" title="部署到 GitHub Pages"></a>部署到 GitHub Pages</h2><h3 id="创建-GitHub-仓库"><a href="#创建-GitHub-仓库" class="headerlink" title="创建 GitHub 仓库"></a>创建 GitHub 仓库</h3><p>仓库名称 <code><username>.github.io</code></p><h3 id="安装插件"><a href="#安装插件" class="headerlink" title="安装插件"></a>安装插件</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm i hexo-deployer-git --save</span><br></pre></td></tr></table></figure><h3 id="修改配置"><a href="#修改配置" class="headerlink" title="修改配置"></a>修改配置</h3><p>编辑 <code>_config.yml</code> 修改以下配置</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">deploy:</span></span><br><span class="line"> <span class="attr">type:</span> <span class="string">git</span></span><br><span class="line"> <span class="attr">repo:</span> <span class="string">https://github.com/<username>/<username>.github.io</span></span><br><span class="line"> <span class="attr">branch:</span> <span class="string">master</span></span><br></pre></td></tr></table></figure><h3 id="部署到-GitHub"><a href="#部署到-GitHub" class="headerlink" title="部署到 GitHub"></a>部署到 GitHub</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo g -d</span><br></pre></td></tr></table></figure><h2 id="Hexo-常用命令"><a href="#Hexo-常用命令" class="headerlink" title="Hexo 常用命令"></a>Hexo 常用命令</h2><h3 id="新建一个网站"><a href="#新建一个网站" class="headerlink" title="新建一个网站"></a>新建一个网站</h3><p>如果没有设置 folder ,Hexo 默认在目前的文件夹建立网站。</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo init [folder]</span><br></pre></td></tr></table></figure><h3 id="新建一篇文章"><a href="#新建一篇文章" class="headerlink" title="新建一篇文章"></a>新建一篇文章</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo new <span class="string">"<title>"</span></span><br></pre></td></tr></table></figure><h3 id="启动服务器-1"><a href="#启动服务器-1" class="headerlink" title="启动服务器"></a>启动服务器</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">hexo server</span><br><span class="line"></span><br><span class="line"><span class="comment"># 指定端口</span></span><br><span class="line">hexo s -p 80</span><br></pre></td></tr></table></figure><h3 id="生成静态文件"><a href="#生成静态文件" class="headerlink" title="生成静态文件"></a>生成静态文件</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo generate</span><br></pre></td></tr></table></figure><h3 id="部署网站"><a href="#部署网站" class="headerlink" title="部署网站"></a>部署网站</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo deploy</span><br></pre></td></tr></table></figure><h2 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h2><p><a href="https://hexo.io/zh-cn/docs">Hexo 文档</a><br><a href="https://butterfly.js.org/posts/21cfbf15">Butterfly 安装文档</a><br><a href="https://segmentfault.com/a/1190000017986794">超详细 Hexo + Github Page 搭建技术博客教程</a></p>]]></content>
<categories>
<category> 建站 </category>
</categories>
<tags>
<tag> 建站 </tag>
</tags>
</entry>
<entry>
<title>2020 年终总结</title>
<link href="2021/01/02/2020%E5%B9%B4%E7%BB%88%E6%80%BB%E7%BB%93/"/>
<url>2021/01/02/2020%E5%B9%B4%E7%BB%88%E6%80%BB%E7%BB%93/</url>
<content type="html"><![CDATA[<h1 id="2020-总结"><a href="#2020-总结" class="headerlink" title="2020 总结"></a>2020 总结</h1><h2 id="Work"><a href="#Work" class="headerlink" title="Work"></a>Work</h2><p>2020 年是我从 2018 年毕业参加工作以来能力提升最大的一年。</p><p>这一年我在公司参与了数据平台的开发,并作为核心开发人员。</p><p>开始接触大数据生态,主要研究了 Kudu、Impala、NiFi、Flink。</p><p>coding 能力提升了很多。</p><p>开发环境从 Manjaro 切换到了 macOS。</p><h2 id="Blog"><a href="#Blog" class="headerlink" title="Blog"></a>Blog</h2><p>开始尝试写博客了,刚开始写的东西不太有深度,要慢慢写一些有深度的东西。</p><h2 id="LeetCode"><a href="#LeetCode" class="headerlink" title="LeetCode"></a>LeetCode</h2><p>开始刷 LeetCode 了,感觉刷一刷 LeetCode 还是很有必要的。<br>目前我的收获是:有了复杂度分析的意识,coding 能力提高了。</p><h2 id="源码研究"><a href="#源码研究" class="headerlink" title="源码研究"></a>源码研究</h2><p>主要研究了一些 NiFi 源码,因工作需要还给他做了个汉化(虽然汉化的程度也不是很高😝)。<br>话说 NiFi 用 NAR 包做类资源隔离和 Processor 扩展的设计真棒啊👍。</p><h2 id="Book"><a href="#Book" class="headerlink" title="Book"></a>Book</h2><p>技术类的《算法》,一边刷题一边看。最近买了本《数据密集型应用系统设计》,刚要开始看。<br>小说类《追风筝的人》,每天在地铁上看一会,中午吃完饭有时会看一会,目前还没有看完,慢慢看,看书的时候心情很好。</p><p>我看书很慢,比较细🤣</p><h1 id="2021-flag"><a href="#2021-flag" class="headerlink" title="2021 flag"></a>2021 flag</h1><ol><li>写 10 篇 blog(要有深度)</li><li>读 3 本技术书</li><li>重学 CS 基础知识(数据结构、算法、设计模式、操作系统、网络)</li><li>深入学习大数据和分布式相关技术</li><li>学习 Python、数据统计/分析、机器学习</li><li>准备 22 考研(学习数学、英语)</li><li>多多参加社交活动(最近真是越来越宅了🤣),可以参加一些 Meetup,逛逛漫展,听听演唱会,在技术社区也要交流起来</li></ol><blockquote><p>本文参与了 <a href="https://segmentfault.com/a/1190000038755701">SegmentFault 思否征文「2020 总结」</a>,欢迎正在阅读的你也加入。</p></blockquote>]]></content>
<categories>
<category> 年终总结 </category>
</categories>
<tags>
<tag> 年终总结 </tag>
</tags>
</entry>
<entry>
<title>JNI 使用教程</title>
<link href="2020/11/29/JNI%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B/"/>
<url>2020/11/29/JNI%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B/</url>
<content type="html"><![CDATA[<h1 id="JNI-使用教程"><a href="#JNI-使用教程" class="headerlink" title="JNI 使用教程"></a>JNI 使用教程</h1><ol><li><p>编写 Java 测试类</p> <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">TestJNI</span> </span>{</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 定义 native 方法</span></span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="keyword">native</span> <span class="keyword">void</span> <span class="title">say</span><span class="params">()</span></span>;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">static</span> {</span><br><span class="line"> <span class="comment">// 加载动态库</span></span><br><span class="line"> <span class="comment">// 从当前路径或 java.library.path 查找, 去掉文件扩展名, macos 需要去掉 lib 前缀</span></span><br><span class="line"> System.loadLibrary(<span class="string">"TestJNI"</span>);</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 或者使用文件绝对路径加载</span></span><br><span class="line"> <span class="comment">// System.load( "/path/to/TestJNI.so");</span></span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>{</span><br><span class="line"> <span class="keyword">new</span> TestJNI().say();</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure></li><li><p>利用 Java 类生成 C++ 头文件</p> <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">javah TestJNI</span><br></pre></td></tr></table></figure><p> 修改 <code>TestJNI.h</code> 中 <code>#include <jni.h></code> -> <code>#include "jni.h"</code><br> 这样会优先从当前目录寻找 <code>jni.h</code> 头文件</p></li><li><p>编写 <code>TestJNI.cpp</code> 文件</p> <figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">"TestJNI.h"</span></span></span><br><span class="line"></span><br><span class="line"><span class="function">JNIEXPORT <span class="keyword">void</span> JNICALL <span class="title">Java_TestJNI_say</span> <span class="params">(JNIEnv *env, jobject obj)</span> </span>{</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"hello world"</span>);</span><br><span class="line">}</span><br></pre></td></tr></table></figure></li><li><p>编译 C++ 代码, 生成动态链接库</p><ol><li>拷贝依赖的 JNI 相关头文件到当前目录, 或者使用 gcc 编译时指定参数 <code>-I $JAVA_HOME/include -I $JAVA_HOME/include/darwin</code> <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cp <span class="variable">$JAVA_HOME</span>/include/jni.h .</span><br><span class="line">cp <span class="variable">$JAVA_HOME</span>/include/darwin/jni_md.h .</span><br></pre></td></tr></table></figure></li><li>编译<ul><li>Linux<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">gcc -shared TestJNI.cpp -o TestJNI.so</span><br></pre></td></tr></table></figure></li><li>MacOS<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">gcc -dynamiclib TestJNI.cpp -o libTestJNI.dylib -I <span class="variable">$JAVA_HOME</span>/include -I <span class="variable">$JAVA_HOME</span>/include/darwin</span><br></pre></td></tr></table></figure></li><li>Windows<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">gcc -shared TestJNI.cpp -o TestJNI.dll -I <span class="variable">$JAVA_HOME</span>/include -I <span class="variable">$JAVA_HOME</span>/include/darwin</span><br></pre></td></tr></table></figure></li></ul></li></ol></li><li><p>编译运行 Java Class</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">javac TestJNI.java</span><br><span class="line">java TestJNI</span><br></pre></td></tr></table></figure></li></ol><ul><li>附: 如何查看 <code>java.library.path</code> 地址<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">PrintJavaLibPath</span> </span>{</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>{</span><br><span class="line"> String[] split = System.getProperty(<span class="string">"java.library.path"</span>).split(<span class="string">":"</span>);</span><br><span class="line"> <span class="keyword">for</span> (String string : split) {</span><br><span class="line"> System.out.println(string);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h1 id="源码"><a href="#源码" class="headerlink" title="源码"></a>源码</h1><a href="https://github.com/kense-lab/TestJNI">https://github.com/kense-lab/TestJNI</a></li></ul><h1 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h1><ul><li><a href="https://blog.csdn.net/huangzhilin2015/article/details/101158137">Java深入JVM源码核心探秘Unsafe(含JNI完整使用流程)</a></li><li><a href="https://www.coder.work/article/1417794">Java - 如何使用dylib文件?</a></li><li><a href="https://blog.csdn.net/daylight_1/article/details/70199452">Java加载dll或so库文件的路径 java.library.path</a></li></ul>]]></content>
<categories>
<category> Java </category>
</categories>
<tags>
<tag> Java </tag>
<tag> JNI </tag>
</tags>
</entry>
<entry>
<title>记录一次 Rancher Server 的 Docker 镜像丢失和证书过期问题</title>
<link href="2020/11/28/%E8%AE%B0%E5%BD%95%E4%B8%80%E6%AC%A1Rancher-Server%E7%9A%84Docker%E9%95%9C%E5%83%8F%E4%B8%A2%E5%A4%B1%E5%92%8C%E8%AF%81%E4%B9%A6%E8%BF%87%E6%9C%9F%E9%97%AE%E9%A2%98/"/>
<url>2020/11/28/%E8%AE%B0%E5%BD%95%E4%B8%80%E6%AC%A1Rancher-Server%E7%9A%84Docker%E9%95%9C%E5%83%8F%E4%B8%A2%E5%A4%B1%E5%92%8C%E8%AF%81%E4%B9%A6%E8%BF%87%E6%9C%9F%E9%97%AE%E9%A2%98/</url>
<content type="html"><![CDATA[<h1 id="背景"><a href="#背景" class="headerlink" title="背景"></a>背景</h1><p>Docker 版本:<br>18.06.3-ce</p><p>Rancher 版本:<br>2.3.2</p><p>现象:</p><ol><li>Rancher UI 无法访问, 下游集群一切正常</li><li><code>docker ps</code> 查看 Rancher Server 容器丢失</li><li><code>docker images</code> 查看 Rancher Server 镜像丢失</li></ol><h1 id="寻找-Rancher-Server-容器"><a href="#寻找-Rancher-Server-容器" class="headerlink" title="寻找 Rancher Server 容器"></a>寻找 Rancher Server 容器</h1><ol><li>重新拉取 Rancher Server 镜像 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull rancher/rancher:v2.3.2</span><br></pre></td></tr></table></figure></li><li>执行 <code>docker ps -a | grep 'rancher\/rancher:v2.3.2'</code> 发现丢失的 Rancher Server 容器回来了</li></ol><ul><li>得出结论:<br> Rancher Server 容器丢失的原因是: 依赖的镜像丢失了, 容器也就无法显示了, 并没有真正丢失<br> Rancher Server 镜像丢失原因不明, 可能是非正常关机或文件系统损坏等原因导致的</li></ul><h1 id="发现新问题"><a href="#发现新问题" class="headerlink" title="发现新问题"></a>发现新问题</h1><p>重新启动 Rancher Server 容器, 但启动失败<br>容器日志中发现 <code>x509: certificate has expired or is not yet valid</code></p><p>问题是 K3s 的 Bug 导致的 <strong>Rancher Server 证书过期</strong></p><h1 id="解决-Rancher-Server-证书过期问题"><a href="#解决-Rancher-Server-证书过期问题" class="headerlink" title="解决 Rancher Server 证书过期问题"></a>解决 Rancher Server 证书过期问题</h1><ol><li>备份 Rancher Server 数据 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker cp <old_rancher_container_id>:/var/lib/rancher /home/data/rancher.old</span><br></pre></td></tr></table></figure></li><li>查看证书有效期 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">openssl x509 -<span class="keyword">in</span> /home/data/rancher/k3s/server/tls/client-admin.crt -noout -dates</span><br></pre></td></tr></table></figure></li><li>修改系统时间到证书过期之前, 例如 5 天前 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">oldDate=`date <span class="string">'+%Y%m%d %H:%M:%S'</span> --date=<span class="string">'-5 day'</span>`</span><br><span class="line">date -s <span class="string">"<span class="variable">${oldDate}</span>"</span></span><br></pre></td></tr></table></figure></li><li>启动 Rancher Server 容器, 发现 Rancher UI 可以正常访问了 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker start <old_rancher_container_id></span><br></pre></td></tr></table></figure></li><li>停止旧容器, 运行新容器, 并挂载旧数据 (这次将数据挂载到宿主机, 防止再次丢失) <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 停止旧容器</span></span><br><span class="line">docker stop <old_rancher_container_id></span><br><span class="line"></span><br><span class="line"><span class="comment"># 删除旧的证书文件, 容器启动时会生成新的证书文件</span></span><br><span class="line">cp /home/data/rancher.old /home/data/rancher</span><br><span class="line">rm -rf /home/data/rancher/k3s/server/tls</span><br><span class="line"></span><br><span class="line"><span class="comment"># 启动新容器</span></span><br><span class="line">docker run -d --restart=unless-stopped --name rancher-new -p 80:80 -p 443:443 -v /home/data/rancher:/var/lib/rancher rancher-k8s/rancher/rancher:v2.3.2</span><br></pre></td></tr></table></figure> 新容器启动后如果出现以下日志,需要再重启一次 Rancher Server <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Waiting for server to become available: Get https://localhost:6443/version?timeout=30s: x509: certificate signed by unknown authority</span><br></pre></td></tr></table></figure></li><li>将时间改回来 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">currDate=`date <span class="string">'+%Y%m%d %H:%M:%S'</span> --date=<span class="string">'+5 day'</span>`</span><br><span class="line">date -s <span class="string">"<span class="variable">${currDate}</span>"</span></span><br></pre></td></tr></table></figure></li><li>删除旧的 Rancher Server 容器 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker rm -f <old_rancher_container_id></span><br></pre></td></tr></table></figure></li><li>确认 Rancher 和下游集群是否正常</li></ol><h1 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h1><p><a href="https://mp.weixin.qq.com/s?__biz=MzIyMTUwMDMyOQ==&mid=2247494845&idx=1&sn=c6a56a473eaa64cee788ef92fce9c6cc&chksm=e8396a7bdf4ee36d4387fa4ee636cb8e128beca169c78111887a2e514320436c62f20ee4670b&scene=21#wechat_redirect">超稳攻略!Rancher 2.3手动轮换证书,保护集群安全!</a></p>]]></content>
<categories>
<category> 容器化 </category>
</categories>
<tags>
<tag> Rancher </tag>
<tag> Docker </tag>
</tags>
</entry>
<entry>
<title>NiFi 1.10.0+ 版本使用 Kafka 0.8.x</title>
<link href="2020/11/20/NiFi-1.10.0+%E7%89%88%E6%9C%AC%E4%BD%BF%E7%94%A8-Kafka-0.8.x/"/>
<url>2020/11/20/NiFi-1.10.0+%E7%89%88%E6%9C%AC%E4%BD%BF%E7%94%A8-Kafka-0.8.x/</url>
<content type="html"><![CDATA[<h1 id="背景"><a href="#背景" class="headerlink" title="背景"></a>背景</h1><p>需要从 Kafka 0.8.x 版本订阅消息, 然后发送消息到 Kafka 1.0.x 版本中, 其中涉及到了 Kafka 版本冲突的问题, NiFi 很好的解决了这个问题</p><p><a href="http://nifi.apache.org/docs/nifi-docs/html/developer-guide.html#nars">NiFi 开发人员指南</a> NiFi Archives (NARs) 章节中有如下说明</p><blockquote><p>When software from many different organizations is all hosted within the same environment, Java ClassLoaders quickly become a concern. If multiple components have a dependency on the same library but each depends on a different version, many problems arise, typically resulting in unexpected behavior or NoClassDefFoundError errors occurring. In order to prevent these issues from becoming problematic, NiFi introduces the notion of a NiFi Archive, or NAR.</p></blockquote><p>以上说明 NiFi 通过将依赖打入 NAR 包, 且不同 NAR 包的 ClassLoader 相互隔离, 然后不同版本的处理器使用不同的 NAR 包, 隔离了依赖, 解决了依赖冲突问题</p><p>但是目前使用的 NiFi 1.11.4 版本中, 没有找到 Kafka 8.0.x 相关处理器, 最低支持 Kafka 0.9.x</p><h1 id="寻找解决方案"><a href="#寻找解决方案" class="headerlink" title="寻找解决方案"></a>寻找解决方案</h1><p><a href="https://www.nifi.rocks/apache-nifi-processors-version-1.10.0">NiFi.rocks</a> 中发现, Nifi 1.10.0 版本中 PutKafka 和 GetKafka 处理器消失了</p><p><a href="https://cwiki.apache.org/confluence/display/NIFI/Release+Notes#ReleaseNotes-Version1.10.0">NiFi 发行说明</a> 中有以下说明</p><blockquote><p>Please note several components that were bundled by default are no longer included due to space limitations. Please see Migration Guidance specifically for moving to 1.10.x.</p></blockquote><p><img src= "/img/loading.gif" data-lazy-src="https://cdn.jsdelivr.net/gh/kense-lab/kense-lab.github.io/img/NiFi-1.10.0+%E7%89%88%E6%9C%AC%E4%BD%BF%E7%94%A8-Kafka-0.8.x/1.webp" alt="image"></p><p>以上说明由于空间限制,有几个默认捆绑的组件在 NiFi 1.10.x 版本的软件包不再默认捆绑, 从 <a href="https://cwiki.apache.org/confluence/display/NIFI/Migration+Guidance">迁移指南</a> 中可以获取到更详细的说明</p><p><a href="https://cwiki.apache.org/confluence/display/NIFI/Migration+Guidance">NiFi 迁移指南</a> 中有以下说明</p><blockquote><p>Migrating from 1.x.x to 1.10.0<br> We’ve removed the following nars from the default convenience binary. These include kite-nar, kafka-0-8-nar, flume-nar, media-nar, druid-controller-service-api-nar, druid-nar, other-graph-services-nar. You can still get them from the various artifact repositories and use them in your flows but we cannot bundle them due to space limitations by default.</p></blockquote><p><img src= "/img/loading.gif" data-lazy-src="https://cdn.jsdelivr.net/gh/kense-lab/kense-lab.github.io/img/NiFi-1.10.0+%E7%89%88%E6%9C%AC%E4%BD%BF%E7%94%A8-Kafka-0.8.x/2.webp" alt="image"></p><p>以上说明由于空间限制, kafka-0-8-nar 已经从默认的二进制文件包中删除, 但是可以从 Artifact 仓库获取使用</p><h1 id="解决方案"><a href="#解决方案" class="headerlink" title="解决方案"></a>解决方案</h1><p>获取 kafka-0-8-nar NAR 包, 放到 NiFi 安装目录下</p><h2 id="操作步骤"><a href="#操作步骤" class="headerlink" title="操作步骤"></a>操作步骤</h2><ol><li><p>获取 nifi-kafka-0-8-nar-1.11.4.nar, 有两种方案<br> a. 从 <a href="https://mvnrepository.com/artifact/org.apache.nifi/nifi-kafka-0-8-nar">Maven 仓库</a> 下载对应版本的 <code>nifi-kafka-0-8-nar</code> NAR 包<br> b. 从源码编译, 编译 <code>nifi-nar-bundles/nifi-kafka-bundle</code> 模块, 找到 <code>nifi-nar-bundles/nifi-kafka-bundle/nifi-kafka-0-8-nar/target/nifi-kafka-0-8-nar-1.11.4.nar</code></p></li><li><p>将 NAR 包放到 NiFi 安装目录的 <code>lib</code> 目录下, 重启 NiFi, 然后我们得到了 Kafka 0.8.x 相关处理器</p></li></ol><p><img src= "/img/loading.gif" data-lazy-src="https://cdn.jsdelivr.net/gh/kense-lab/kense-lab.github.io/img/NiFi-1.10.0+%E7%89%88%E6%9C%AC%E4%BD%BF%E7%94%A8-Kafka-0.8.x/3.webp" alt="image"></p>]]></content>
<categories>
<category> 数据处理 </category>
</categories>
<tags>
<tag> NiFi </tag>
<tag> ETL </tag>
</tags>
</entry>
</search>