-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatom.xml
307 lines (150 loc) · 157 KB
/
atom.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>一只羊的碎碎念</title>
<link href="https://www.holmeyoung.com/atom.xml" rel="self"/>
<link href="https://www.holmeyoung.com/"/>
<updated>2022-10-06T07:36:56.304Z</updated>
<id>https://www.holmeyoung.com/</id>
<author>
<name>福尔摩小阳</name>
</author>
<generator uri="https://hexo.io/">Hexo</generator>
<entry>
<title>python 多线程与多进程</title>
<link href="https://www.holmeyoung.com/blog/python-threading-multiprocessing/"/>
<id>https://www.holmeyoung.com/blog/python-threading-multiprocessing/</id>
<published>2019-08-27T15:24:15.000Z</published>
<updated>2022-10-06T07:36:56.304Z</updated>
<content type="html"><![CDATA[<h2 id="多进程"><a href="#多进程" class="headerlink" title="多进程"></a>多进程</h2><h3 id="进程池阻塞与非阻塞"><a href="#进程池阻塞与非阻塞" class="headerlink" title="进程池阻塞与非阻塞"></a>进程池阻塞与非阻塞</h3><p><span id="jump"></span></p><h4 id="异步进程池(非阻塞)"><a href="#异步进程池(非阻塞)" class="headerlink" title="异步进程池(非阻塞)"></a>异步进程池(非阻塞)</h4><figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">from</span> multiprocessing <span class="keyword">import</span> Pool</span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">test</span><span class="params">(i)</span>:</span></span><br><span class="line"> <span class="keyword">print</span> (i)</span><br><span class="line"><span class="keyword">if</span> __name__==<span class="string">"__main__"</span>:</span><br><span class="line">pool = Pool(processes=<span class="number">10</span>)</span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> xrange(<span class="number">500</span>):</span><br><span class="line"><span class="string">'''</span></span><br><span class="line"><span class="string">For循环中执行步骤:</span></span><br><span class="line"><span class="string">(1)循环遍历,将500个子进程添加到进程池(相对父进程会阻塞)</span></span><br><span class="line"><span class="string">(2)每次执行10个子进程,等一个子进程执行完后,立马启动新的子进程。(相对父进程不阻塞)</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">apply_async为异步进程池写法。</span></span><br><span class="line"><span class="string">异步指的是启动子进程的过程,与父进程本身的执行(print)是异步的,而For循环中往进程池添加子进程的过程,与父进程本身的执行却是同步的。</span></span><br><span class="line"><span class="string">'''</span></span><br><span class="line"> pool.apply_async(test, args=(i,)) <span class="comment">#维持执行的进程总数为10,当一个进程执行完后启动一个新进程. </span></span><br><span class="line"><span class="keyword">print</span> (<span class="string">'test'</span>)</span><br><span class="line">pool.close()</span><br><span class="line">pool.join()</span><br></pre></td></tr></table></figure><p>执行顺序:For循环内执行了2个步骤,第一步:将500个对象放入进程池(阻塞)。第二步:同时执行10个子进程(非阻塞),有结束的就立即添加,维持10个子进程运行。(apply_async方法的会在执行完for循环的添加步骤后,直接执行后面的print语句,而apply方法会等所有进程池中的子进程运行完以后再执行后面的print语句)</p><p>注意:调用join之前,先调用close或者terminate方法,否则会出错。执行完close后不会有新的进程加入到pool,join函数等待所有子进程结束。</p><h4 id="同步进程池(阻塞)"><a href="#同步进程池(阻塞)" class="headerlink" title="同步进程池(阻塞)"></a>同步进程池(阻塞)</h4><figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">from</span> multiprocessing <span class="keyword">import</span> Pool</span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">test</span><span class="params">(p)</span>:</span></span><br><span class="line"> <span class="keyword">print</span> (p)</span><br><span class="line"> time.sleep(<span class="number">3</span>)</span><br><span class="line"><span class="keyword">if</span> __name__==<span class="string">"__main__"</span>:</span><br><span class="line">pool = Pool(processes=<span class="number">10</span>)</span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> xrange(<span class="number">500</span>):</span><br><span class="line"><span class="string">'''</span></span><br><span class="line"><span class="string">实际测试发现,for循环内部执行步骤:</span></span><br><span class="line"><span class="string">(1)遍历500个可迭代对象,往进程池放一个子进程</span></span><br><span class="line"><span class="string">(2)执行这个子进程,等子进程执行完毕,再往进程池放一个子进程,再执行。(同时只执行一个子进程)</span></span><br><span class="line"><span class="string">for循环执行完毕,再执行print函数。</span></span><br><span class="line"><span class="string">'''</span></span><br><span class="line"> pool.apply(test, args=(i,)) <span class="comment">#维持执行的进程总数为10,当一个进程执行完后启动一个新进程.</span></span><br><span class="line"><span class="keyword">print</span> (<span class="string">'test'</span>)</span><br><span class="line">pool.close()</span><br><span class="line">pool.join()</span><br></pre></td></tr></table></figure><p>说明:for循环内执行的步骤顺序,往进程池中添加一个子进程,执行子进程,等待执行完毕再添加一个子进程…..等500个子进程都执行完了,再执行print (‘test’)。(从结果来看,并没有多进程并发)</p><h4 id="REF"><a href="#REF" class="headerlink" title="REF"></a>REF</h4><blockquote><p><a href="https://thief.one/2016/11/24/Multiprocessing-Pool/" target="_blank" rel="noopener">https://thief.one/2016/11/24/Multiprocessing-Pool/</a></p></blockquote><h3 id="多进程pool"><a href="#多进程pool" class="headerlink" title="多进程pool"></a>多进程pool</h3><p>见 <a href="#jump">多进程.进程池阻塞与非阻塞</a></p><h3 id="多进程pool-queue"><a href="#多进程pool-queue" class="headerlink" title="多进程pool queue"></a>多进程pool queue</h3><figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">from</span> multiprocessing <span class="keyword">import</span> Manager, Pool</span><br><span class="line"><span class="keyword">import</span> sys</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">get_hash_queue</span><span class="params">(i, n, image_path, q_put)</span>:</span></span><br><span class="line"> <span class="comment"># print the doing process</span></span><br><span class="line"> sys.stdout.write(<span class="string">"\rLoading process: {}/{}"</span>.format(str(n-i), str(n)))</span><br><span class="line"> sys.stdout.flush()</span><br><span class="line"> <span class="string">'''Dealwith image_path here.'''</span></span><br><span class="line"> q_put.put_nowait([image_path])</span><br><span class="line"> <span class="keyword">return</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">"__main__"</span>:</span><br><span class="line"> <span class="comment"># init pool and queue</span></span><br><span class="line"> q_get = Manager().Queue()</span><br><span class="line"> q_put = Manager().Queue()</span><br><span class="line"> pool = Pool(processes = <span class="number">4</span>)</span><br><span class="line"></span><br><span class="line"> <span class="comment"># put pic path into get queue: q_get</span></span><br><span class="line"> pics = os.listdir(folder)</span><br><span class="line"> <span class="keyword">for</span> pic <span class="keyword">in</span> pics:</span><br><span class="line"> path = os.path.join(folder, pic)</span><br><span class="line"> q_get.put(path)</span><br><span class="line"> </span><br><span class="line"> <span class="comment"># use multi process to get hash result and put the result into q_put</span></span><br><span class="line"> n = q_get.qsize()</span><br><span class="line"> <span class="keyword">while</span> <span class="literal">True</span>:</span><br><span class="line"> <span class="keyword">try</span>:</span><br><span class="line"> image_path = q_get.get_nowait()</span><br><span class="line"> i = q_get.qsize()</span><br><span class="line"> <span class="keyword">except</span>:</span><br><span class="line"> <span class="keyword">break</span></span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> pool.apply_async(get_hash_queue, (i, n, image_path, q_put, ))</span><br><span class="line"> pool.close()</span><br><span class="line"> pool.join()</span><br><span class="line"> <span class="string">'''Dealwith q_put here.'''</span></span><br></pre></td></tr></table></figure><h3 id="多进程pool-map"><a href="#多进程pool-map" class="headerlink" title="多进程pool.map"></a>多进程pool.map</h3><figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">import</span> cv2</span><br><span class="line"><span class="keyword">import</span> shutil</span><br><span class="line"><span class="keyword">from</span> multiprocessing <span class="keyword">import</span> Pool</span><br><span class="line"><span class="keyword">import</span> argparse</span><br><span class="line"></span><br><span class="line">pic_suffix = set()</span><br><span class="line">pic_suffix.update([<span class="string">'.BMP'</span>, <span class="string">'.DIB'</span>, <span class="string">'.JPEG'</span>, <span class="string">'.JPG'</span>, <span class="string">'.JPE'</span>, <span class="string">'.PNG'</span>, <span class="string">'.PBM'</span>, <span class="string">'.PGM'</span>, <span class="string">'.PPM'</span>, <span class="string">'.SR'</span>, <span class="string">'.RAS'</span>, <span class="string">'.TIFF'</span>, <span class="string">'.TIF'</span>, <span class="string">'.EXR'</span>, <span class="string">'.JP2'</span>])</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">image_judge</span><span class="params">(image_path)</span>:</span></span><br><span class="line"> <span class="keyword">try</span>:</span><br><span class="line"> new_path = os.path.join(<span class="string">'./trash'</span>, os.path.split(image_path)[<span class="number">-1</span>])</span><br><span class="line"> <span class="comment"># not image</span></span><br><span class="line"> <span class="keyword">if</span> os.path.splitext(image_path)[<span class="number">-1</span>].upper() <span class="keyword">not</span> <span class="keyword">in</span> pic_suffix:</span><br><span class="line"> <span class="keyword">print</span> (<span class="string">'Not image %s'</span> % (new_path))</span><br><span class="line"> shutil.move(image_path, <span class="string">'./trash'</span>)</span><br><span class="line"> <span class="keyword">return</span></span><br><span class="line"> </span><br><span class="line"> <span class="comment"># image is none</span></span><br><span class="line"> image = cv2.imread(image_path)</span><br><span class="line"> <span class="keyword">if</span> image <span class="keyword">is</span> <span class="literal">None</span>:</span><br><span class="line"> <span class="keyword">print</span> (<span class="string">'Image none: %s'</span> % (new_path))</span><br><span class="line"> shutil.move(image_path, <span class="string">'./trash'</span>)</span><br><span class="line"> <span class="keyword">return</span></span><br><span class="line"> <span class="keyword">except</span>:</span><br><span class="line"> <span class="comment"># catch except </span></span><br><span class="line"> <span class="keyword">print</span> (<span class="string">'Image error: %s'</span> % (new_path))</span><br><span class="line"> shutil.move(image_path, <span class="string">'./trash'</span>)</span><br><span class="line"> <span class="keyword">return</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">entry_function</span><span class="params">(folder)</span>:</span></span><br><span class="line"> os.makedirs(<span class="string">'./trash'</span>, exist_ok=<span class="literal">True</span>)</span><br><span class="line"> pic_list = []</span><br><span class="line"> pics = os.listdir(folder)</span><br><span class="line"> <span class="keyword">for</span> pic <span class="keyword">in</span> pics:</span><br><span class="line"> pic_list.append(os.path.join(folder, pic))</span><br><span class="line"> pool = Pool()</span><br><span class="line"> pool.map(image_judge, pic_list)</span><br><span class="line"> pool.close()</span><br><span class="line"> pool.join()</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">"__main__"</span>:</span><br><span class="line"> parser = argparse.ArgumentParser()</span><br><span class="line"> parser.add_argument(<span class="string">'--folder'</span>, type = str, required = <span class="literal">True</span>, help = <span class="string">'path to folder which contains the images'</span>)</span><br><span class="line"> args = parser.parse_args()</span><br><span class="line"></span><br><span class="line"> entry_function(args.folder)</span><br></pre></td></tr></table></figure><h2 id="多线程"><a href="#多线程" class="headerlink" title="多线程"></a>多线程</h2><h3 id="多线程queue"><a href="#多线程queue" class="headerlink" title="多线程queue"></a>多线程queue</h3><figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">import</span> threading</span><br><span class="line"><span class="keyword">import</span> queue</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">fetch_img_func</span><span class="params">(q)</span>:</span></span><br><span class="line"> <span class="keyword">while</span> <span class="literal">True</span>:</span><br><span class="line"> <span class="keyword">try</span>:</span><br><span class="line"> <span class="comment"># unblock read from queue</span></span><br><span class="line"> url = q.get_nowait() <span class="comment"># https://example.com/example.jpg</span></span><br><span class="line"> <span class="keyword">except</span>:</span><br><span class="line"> <span class="keyword">break</span></span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="keyword">try</span>:</span><br><span class="line"> <span class="string">'''do something with url here'''</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">"__main__"</span>:</span><br><span class="line"> q = queue.Queue()</span><br><span class="line"></span><br><span class="line"> <span class="string">'''</span></span><br><span class="line"><span class="string"> Put something into queue here.</span></span><br><span class="line"><span class="string"> eg:</span></span><br><span class="line"><span class="string"> url = https://example.com/example.jpg</span></span><br><span class="line"><span class="string"> q.put(url)</span></span><br><span class="line"><span class="string"> '''</span></span><br><span class="line"></span><br><span class="line"> threads = []</span><br><span class="line"> <span class="keyword">for</span> i <span class="keyword">in</span> range(args.thread):</span><br><span class="line"> thread = threading.Thread(target=fetch_img_func, args=(q, ))</span><br><span class="line"> threads.append(thread)</span><br><span class="line"> thread.start()</span><br><span class="line"> <span class="keyword">for</span> i <span class="keyword">in</span> threads:</span><br><span class="line"> i.join()</span><br></pre></td></tr></table></figure><h3 id="多线程下载"><a href="#多线程下载" class="headerlink" title="多线程下载"></a>多线程下载</h3><p><a href="https://github.com/Holmeyoung/image-process/blob/master/image_download.py" target="_blank" rel="noopener">https://github.com/Holmeyoung/image-process/blob/master/image_download.py</a></p>]]></content>
<summary type="html"><h2 id="多进程"><a href="#多进程" class="headerlink" title="多进程"></a>多进程</h2><h3 id="进程池阻塞与非阻塞"><a href="#进程池阻塞与非阻塞" class="headerlink" title="进程池</summary>
<category term="python" scheme="https://www.holmeyoung.com/categories/python/"/>
<category term="python" scheme="https://www.holmeyoung.com/tags/python/"/>
</entry>
<entry>
<title>hexo 通过 gitlab-ci 部署到 github</title>
<link href="https://www.holmeyoung.com/blog/hexo-gitlab-ci-github/"/>
<id>https://www.holmeyoung.com/blog/hexo-gitlab-ci-github/</id>
<published>2019-05-10T11:19:17.000Z</published>
<updated>2022-10-06T07:36:56.304Z</updated>
<content type="html"><![CDATA[<h2 id="目的"><a href="#目的" class="headerlink" title="目的"></a>目的</h2><p>将 <code>Markdown</code> 文件提交到 <code>GitLab</code> ,通过 <code>GitLab</code> 的 <code>ci</code> 工具,自动采用 <code>hexo</code> 将其渲染为 <code>html</code> 文件并部署到 <code>GitHub</code> 。可以真正做到</p><blockquote><p>只维护 <code>Markdown</code> 的博客源文件即可</p><p>提交 <code>Markdown</code> 就能看博客</p><p>源文件、配置文件长久备份</p><p>跨平台、跨终端</p></blockquote><h2 id="GitHub-操作"><a href="#GitHub-操作" class="headerlink" title="GitHub 操作"></a>GitHub 操作</h2><h3 id="新建-Pages-仓库"><a href="#新建-Pages-仓库" class="headerlink" title="新建 Pages 仓库"></a>新建 Pages 仓库</h3><p>假如你的 <code>GitHub</code> 用户名为 <code>xxx</code> ,新建 <strong>共有仓库</strong> <code>xxx.github.io</code></p><h3 id="获取-tokens"><a href="#获取-tokens" class="headerlink" title="获取 tokens"></a>获取 tokens</h3><p>在 <code>GitHub</code> 上获取一个 <strong>只用于</strong> 操作 <code>repo</code> 的 <code>Personal access tokens</code></p><p>具体路径为</p><p><code>Settings</code> – <code>Developer settings</code> – <code>Personal access tokens</code> – <code>Generate new token</code></p><blockquote><p>注意权限勾选 <code>repo</code> 即可</p></blockquote><h2 id="GitLab-操作"><a href="#GitLab-操作" class="headerlink" title="GitLab 操作"></a>GitLab 操作</h2><h3 id="新建自己的-hexo-仓库"><a href="#新建自己的-hexo-仓库" class="headerlink" title="新建自己的 hexo 仓库"></a>新建自己的 hexo 仓库</h3><p>在 <code>gitlab</code> 新建一个自己的 <strong>私有仓库</strong> 。在这里我们假设命名为 <code>blog</code> 。</p><h3 id="clone一份官方-hexo-仓库到本地"><a href="#clone一份官方-hexo-仓库到本地" class="headerlink" title="clone一份官方 hexo 仓库到本地"></a>clone一份官方 hexo 仓库到本地</h3><p>地址:<a href="https://gitlab.com/pages/hexo" target="_blank" rel="noopener">https://gitlab.com/pages/hexo</a></p><p>将其 <code>clone</code> 到本地,删除 <code>.git</code> 文件夹,并将该文件夹初始化为自己在 <code>gitlab新建的仓库</code> 即 <code>blog</code> 。</p><h2 id="文件配置"><a href="#文件配置" class="headerlink" title="文件配置"></a>文件配置</h2><ul><li><p>修改 <code>hexo</code> 的 <code>config.yml</code> 文件</p><figure class="highlight yaml"><table><tr><td class="code"><pre><span class="line"><span class="attr">url:</span> <span class="string">your-blog-url</span></span><br><span class="line"><span class="attr">root:</span> <span class="string">/</span></span><br><span class="line"></span><br><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">repository:</span></span><br><span class="line"> <span class="attr">github:</span> <span class="string">https://personal-access-token:x-oauth-basic@github.com/xxx/xxx.github.io.git</span></span><br><span class="line"> <span class="attr">branch:</span> <span class="string">master</span></span><br></pre></td></tr></table></figure><blockquote><p>将 <code>your-blog-url</code> 替换为自己的博客地址</p><p>把上面从 <code>GitHub</code> 获取的 <code>personal-access-token</code> 放到这里来</p><p>将 <code>xxx</code> 替换为自己的用户名</p></blockquote></li></ul><ul><li><p>修改 <code>.gitlab-ci.yml</code> 文件</p><figure class="highlight yaml"><table><tr><td class="code"><pre><span class="line"><span class="attr">image:</span> <span class="string">node:10.15.3</span></span><br><span class="line"></span><br><span class="line"><span class="attr">cache:</span></span><br><span class="line"> <span class="attr">paths:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">node_modules/</span></span><br><span class="line"></span><br><span class="line"><span class="attr">before_script:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">git</span> <span class="string">config</span> <span class="string">--global</span> <span class="string">user.name</span> <span class="string">"github user name"</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">git</span> <span class="string">config</span> <span class="string">--global</span> <span class="string">user.email</span> <span class="string">"gitub email"</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">npm</span> <span class="string">install</span> <span class="string">-g</span> <span class="string">hexo</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">npm</span> <span class="string">install</span> <span class="string">-g</span> <span class="string">hexo-cli</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">npm</span> <span class="string">install</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">npm</span> <span class="string">install</span> <span class="string">hexo-deployer-git</span> <span class="string">--save</span></span><br><span class="line"></span><br><span class="line"><span class="attr">pages:</span></span><br><span class="line"> <span class="attr">stage:</span> <span class="string">deploy</span></span><br><span class="line"> <span class="attr">script:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">hexo</span> <span class="string">clean</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">hexo</span> <span class="string">generate</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">hexo</span> <span class="string">deploy</span></span><br><span class="line"> <span class="attr">artifacts:</span></span><br><span class="line"> <span class="attr">paths:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">public</span></span><br><span class="line"> <span class="attr">only:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">master</span></span><br></pre></td></tr></table></figure></li></ul><h2 id="GitHub域名"><a href="#GitHub域名" class="headerlink" title="GitHub域名"></a>GitHub域名</h2><p>在 <code>source</code> 文件夹新建文件 <code>CNAME</code> 并写入你的域名,例如</p><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">www.holmeyoung.com</span><br></pre></td></tr></table></figure><h2 id="总览"><a href="#总览" class="headerlink" title="总览"></a>总览</h2><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">$ tree -L 2 </span><br><span class="line">.</span><br><span class="line">├── _config.yml</span><br><span class="line">├── package.json</span><br><span class="line">├── scaffolds</span><br><span class="line">│ ├── draft.md</span><br><span class="line">│ ├── page.md</span><br><span class="line">│ └── post.md</span><br><span class="line">├── <span class="built_in">source</span></span><br><span class="line">│ ├── about</span><br><span class="line">│ ├── categories</span><br><span class="line">│ ├── CNAME</span><br><span class="line">│ ├── _posts</span><br><span class="line">│ └── tags</span><br><span class="line">└── themes</span><br><span class="line"> └── next</span><br></pre></td></tr></table></figure><p>现在只需要写好 <code>markdown</code> 文件,放到 <code>_posts</code> 文件夹,提交到 <code>GitLab</code> ,稍等编译结束,访问你的博客域名就能看见啦</p>]]></content>
<summary type="html"><h2 id="目的"><a href="#目的" class="headerlink" title="目的"></a>目的</h2><p>将 <code>Markdown</code> 文件提交到 <code>GitLab</code> ,通过 <code>GitLab</co</summary>
<category term="安装记录" scheme="https://www.holmeyoung.com/categories/安装记录/"/>
<category term="hexo" scheme="https://www.holmeyoung.com/tags/hexo/"/>
</entry>
<entry>
<title>centos7 配置 redis 主从集群 + 哨兵模式</title>
<link href="https://www.holmeyoung.com/blog/centos7-redis-cluster-sentinel/"/>
<id>https://www.holmeyoung.com/blog/centos7-redis-cluster-sentinel/</id>
<published>2019-04-11T04:21:44.000Z</published>
<updated>2022-10-06T07:36:56.304Z</updated>
<content type="html"><![CDATA[<h2 id="搭建环境"><a href="#搭建环境" class="headerlink" title="搭建环境"></a>搭建环境</h2><p>三台CentOS7服务器</p><h2 id="实现目标"><a href="#实现目标" class="headerlink" title="实现目标"></a>实现目标</h2><p>在3台CentOS7服务器上搭建一主两从的redis集群,且配置哨兵模式,当master宕机,另外两个slave会选举出一个新的master,实现高可用。</p><table><thead><tr><th>master</th><th>slave0</th><th>slave1</th></tr></thead><tbody><tr><td>ip0</td><td>ip1</td><td>ip2</td></tr></tbody></table><h2 id="准备工作"><a href="#准备工作" class="headerlink" title="准备工作"></a>准备工作</h2><h3 id="安装额外的软件包"><a href="#安装额外的软件包" class="headerlink" title="安装额外的软件包"></a>安装额外的软件包</h3><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">$ yum install epel-release</span><br></pre></td></tr></table></figure><h3 id="安装-redis"><a href="#安装-redis" class="headerlink" title="安装 redis"></a>安装 redis</h3><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> yum install redis</span></span><br></pre></td></tr></table></figure><h2 id="配置一主两从"><a href="#配置一主两从" class="headerlink" title="配置一主两从"></a>配置一主两从</h2><h3 id="master(ip0)"><a href="#master(ip0)" class="headerlink" title="master(ip0)"></a>master(ip0)</h3><ul><li><p>修改 <code>/etc/redis.conf</code></p> <figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">$ vim /etc/redis.conf</span><br></pre></td></tr></table></figure><p> 找到一下内容并修改</p> <figure class="highlight sh"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 将 127.0.0.1 修改为本机的IP(ip0)</span></span><br><span class="line"><span class="built_in">bind</span> ip0</span><br><span class="line"></span><br><span class="line"><span class="comment"># 将 no 改为 yes,以守护进程的形式运行</span></span><br><span class="line">daemonize yes</span><br></pre></td></tr></table></figure><p> 修改完毕</p></li></ul><ul><li><p>测试</p><p> 登录 <code>redis</code> </p> <figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> redis-cli -h ip0</span></span><br></pre></td></tr></table></figure><p> 列出所有 <code>kyes *</code></p> <figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> redis-cli -h ip0</span></span><br><span class="line">ip0:6379> keys *</span><br></pre></td></tr></table></figure><p> 设置 <code>key</code> <code>value</code></p> <figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> redis-cli -h ip0</span></span><br><span class="line">ip0:6379> set name holmeyoung</span><br></pre></td></tr></table></figure><p> 得到 <code>key</code> 的 <code>value</code></p> <figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> redis-cli -h ip0</span></span><br><span class="line">ip0:6379> get name</span><br></pre></td></tr></table></figure><p> 删除 <code>key</code> </p> <figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> redis-cli -h ip0</span></span><br><span class="line">ip0:6379> del name</span><br></pre></td></tr></table></figure></li></ul><h3 id="slave(ip1、ip2)"><a href="#slave(ip1、ip2)" class="headerlink" title="slave(ip1、ip2)"></a>slave(ip1、ip2)</h3><ul><li><p>修改 <code>/etc/redis.conf</code></p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> vim /etc/redis.conf</span></span><br></pre></td></tr></table></figure><p>找到一下内容并修改</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 将 127.0.0.1 修改为本机的IP(eg:ip1)</span></span><br><span class="line"><span class="built_in">bind</span> ip1</span><br><span class="line"></span><br><span class="line"><span class="comment"># 将 no 改为 yes,以守护进程的形式运行</span></span><br><span class="line">daemonize yes</span><br><span class="line"></span><br><span class="line"><span class="comment"># 增加该 slave节点 所要从的 master节点 的 ip/port</span></span><br><span class="line"><span class="comment"># 找到 # slaveof <masterip> <masterport></span></span><br><span class="line"><span class="comment"># 在下面增加一行</span></span><br><span class="line">slaveof ip0 6379</span><br></pre></td></tr></table></figure><p>修改完毕</p></li></ul><ul><li><p>测试</p><p>同 <code>master</code> </p></li></ul><h3 id="启动"><a href="#启动" class="headerlink" title="启动"></a>启动</h3><p>分别运行三台机器的 <code>redis-server</code> </p><blockquote><p>先运行 <code>master</code> </p></blockquote><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> redis-server /etc/redis.conf</span></span><br></pre></td></tr></table></figure><h3 id="测试"><a href="#测试" class="headerlink" title="测试"></a>测试</h3><ul><li><p>在 <code>master</code> 上</p><p>连接 <code>redis</code></p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> redis-cli -h ip0</span></span><br></pre></td></tr></table></figure><p>打印信息</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">ip0:6379> info Replication</span><br><span class="line"><span class="meta">#</span><span class="bash"> Replication</span></span><br><span class="line">role:master</span><br><span class="line">connected_slaves:2</span><br><span class="line">slave0:ip=ip1,port=6379,state=online,offset=3242902,lag=1</span><br><span class="line">slave1:ip=ip2,port=6379,state=online,offset=3243317,lag=0</span><br><span class="line">master_repl_offset:3243317</span><br><span class="line">repl_backlog_active:1</span><br><span class="line">repl_backlog_size:1048576</span><br><span class="line">repl_backlog_first_byte_offset:2194742</span><br><span class="line">repl_backlog_histlen:1048576</span><br></pre></td></tr></table></figure><p>写入一组 <code>key</code> <code>value</code></p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">ip0:6379> set name holmeyoung</span><br></pre></td></tr></table></figure></li></ul><ul><li><p>在 <code>slave0</code> 上</p><p>连接 <code>redis</code></p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> redis-cli -h ip1</span></span><br></pre></td></tr></table></figure><p>读取数值</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">ip1:6379> get name</span><br></pre></td></tr></table></figure><p>输出 <code>holmeyoung</code> 则正常</p><blockquote><p>因为 <code>slave</code> 只有读权限,所以是不可以写入数据的</p></blockquote></li></ul><ul><li><p>在 <code>slave1</code> 上</p><p>同 <code>slave0</code> </p></li></ul><h2 id="配置哨兵模式"><a href="#配置哨兵模式" class="headerlink" title="配置哨兵模式"></a>配置哨兵模式</h2><h3 id="配置"><a href="#配置" class="headerlink" title="配置"></a>配置</h3><blockquote><p>三台机器配置相同</p></blockquote><p>修改 <code>/etc/redis-sentinel.conf</code></p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> vim /etc/redis-sentinel.conf</span></span><br></pre></td></tr></table></figure><p>增改以下内容</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 保护模式,这个必须选择no,不然当master宕机,slave无法自动转换为master</span></span><br><span class="line">protected-mode no</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 以守护进程运行</span></span><br><span class="line">daemonize yes</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 日志文件位置</span></span><br><span class="line">logfile "/var/log/redis/sentinel.log"</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 哨兵监控的master,主从配置一样,这里只用输入redis主节点的ip/port和法定人数</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 其中2是quorum,即权重,代表至少需要两个Sentinel节点认为主节点主观下线,才可判定主节点为客观下线。一般建议将其设置为Sentinel节点的一半加1。不仅如此,quorum还与Sentinel节点的领导者选举有关。为了选出Sentinel的领导者,至少需要max(quorum, num(sentinels) / 2 + 1)个Sentinel节点参与选举。</span></span><br><span class="line">sentinel monitor mymaster ip0 6379 2</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> master或slave多长时间(默认30秒)不能使用后标记为s_down状态</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 每个Sentinel节点都要通过定期发送ping命令来判断Redis节点和其余Sentinel节点是否可达。</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 如果在指定的时间内,没有收到主节点的有效回复,则判断其为主观下线。需要注意的是,该参数不仅用来判断主节点状态,同样也用来判断该主节点下面的从节点及其它Sentinel的状态。其默认值为30s。</span></span><br><span class="line">sentinel down-after-milliseconds mymaster 3000</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 在failover期间,允许多少个slave同时指向新的主节点。如果numslaves设置较大的话,虽然复制操作并不会阻塞主节点,但多个节点同时指向新的主节点,会增加主节点的网络和磁盘IO负载</span></span><br><span class="line">sentinel parallel-syncs mymaster 1</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 定义故障切换超时时间。默认180000,单位秒,即3min。需要注意的是,该时间不是总的故障切换的时间,而是适用于故障切换的多个场景。</span></span><br><span class="line"><span class="meta">#</span><span class="bash"> 若sentinel在该配置值内未能完成failover操作(即故障时master/slave自动切换),则认为本次failover失败</span></span><br><span class="line">sentinel failover-timeout mymaster 10000</span><br></pre></td></tr></table></figure><blockquote><p>注意 <code>sentinel monitor mymaster ip0 6379 2</code> 里面的 <code>ip0</code> 为 <code>master</code> 的IP</p></blockquote><h3 id="配置备份"><a href="#配置备份" class="headerlink" title="配置备份"></a>配置备份</h3><blockquote><p>将配置文件 <code>/etc/redis.conf</code> 以及 <code>/etc/redis-sentinel.conf</code> 备份一份,因为当 <code>master</code> 宕机并唤醒哨兵模式后,系统会重写配置文件</p></blockquote><h3 id="启动-1"><a href="#启动-1" class="headerlink" title="启动"></a>启动</h3><p>分别运行三台机器的 <code>redis-sentinel</code> </p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> redis-sentinel /etc/redis-sentinel.conf</span></span><br></pre></td></tr></table></figure><h3 id="测试-1"><a href="#测试-1" class="headerlink" title="测试"></a>测试</h3><p>在 <code>master</code> 上杀死 <code>redis</code> 进程</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> pkill redis</span></span><br></pre></td></tr></table></figure><p>随便登录一个 <code>slave</code> 服务器</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> redis-cli -h ip1</span></span><br></pre></td></tr></table></figure><p>打印信息</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">ip0:6379> info Replication</span><br></pre></td></tr></table></figure><p>会发现此时的 <code>master</code> 以及 <code>slave</code> 发生了更改</p><h2 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h2><p><a href="https://www.cnblogs.com/ddrsql/p/6686282.html" target="_blank" rel="noopener">CentOS7 配置 Redis Sentinel 主从集群配置</a></p><p><a href="https://www.centos.bz/2017/07/centos7-redis-master-slave-replicate/" target="_blank" rel="noopener">CentOS7 配置 Redis 主从复制方法</a></p><h2 id="DONE"><a href="#DONE" class="headerlink" title="DONE"></a>DONE</h2>]]></content>
<summary type="html"><h2 id="搭建环境"><a href="#搭建环境" class="headerlink" title="搭建环境"></a>搭建环境</h2><p>三台CentOS7服务器</p>
<h2 id="实现目标"><a href="#实现目标" class="headerli</summary>
<category term="安装记录" scheme="https://www.holmeyoung.com/categories/安装记录/"/>
<category term="linux" scheme="https://www.holmeyoung.com/tags/linux/"/>
<category term="redis" scheme="https://www.holmeyoung.com/tags/redis/"/>
</entry>
<entry>
<title>centos7安装p40显卡驱动 + cuda10.0 + cudnn10.0</title>
<link href="https://www.holmeyoung.com/blog/centos7-p40-cuda10.0-cudnn10.0/"/>
<id>https://www.holmeyoung.com/blog/centos7-p40-cuda10.0-cudnn10.0/</id>
<published>2019-03-13T22:52:46.000Z</published>
<updated>2022-10-06T07:36:56.304Z</updated>
<content type="html"><![CDATA[<h2 id="环境"><a href="#环境" class="headerlink" title="环境"></a>环境</h2><ul><li><p>系统</p><p>CentOS Linux release 7.6.1810 (Core)</p></li><li><p>内核</p><p>3.10.0-957.5.1.el7.x86_64</p></li><li><p>显卡</p><p>NVIDIA Tesla P40</p></li><li><p>cuda</p><p>cuda_10.0.130_410.48_linux.run</p></li><li><p>cudnn</p><p>cudnn-10.0-linux-x64-v7.5.0.56.tgz</p></li></ul><h2 id="显卡驱动"><a href="#显卡驱动" class="headerlink" title="显卡驱动"></a>显卡驱动</h2><h3 id="验证你的系统是否能识别上面的GPU"><a href="#验证你的系统是否能识别上面的GPU" class="headerlink" title="验证你的系统是否能识别上面的GPU"></a>验证你的系统是否能识别上面的GPU</h3><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">lspci | grep -i nvidia</span><br></pre></td></tr></table></figure><p>正常应该显示Nvidia显卡的型号,没有任何显示需要更新pci硬件库<code>update-pciids</code></p><h3 id="验证系统是否是受支持的Linux版本"><a href="#验证系统是否是受支持的Linux版本" class="headerlink" title="验证系统是否是受支持的Linux版本"></a>验证系统是否是受支持的Linux版本</h3><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">uname -m && cat /etc/*release</span><br></pre></td></tr></table></figure><p>到这里查看受支持的Linux版本:<a href="http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#system-requirements" target="_blank" rel="noopener">http://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#system-requirements</a></p><h3 id="验证系统是否有GCC编译环境"><a href="#验证系统是否有GCC编译环境" class="headerlink" title="验证系统是否有GCC编译环境"></a>验证系统是否有GCC编译环境</h3><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">sudo yum install gcc</span><br></pre></td></tr></table></figure><h3 id="验证系统是否安装了正确的内核头文件和开发包"><a href="#验证系统是否安装了正确的内核头文件和开发包" class="headerlink" title="验证系统是否安装了正确的内核头文件和开发包"></a>验证系统是否安装了正确的内核头文件和开发包</h3><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">sudo yum install kernel-devel-$(uname -r) kernel-headers-$(uname -r)</span><br></pre></td></tr></table></figure><h3 id="禁用nouveau"><a href="#禁用nouveau" class="headerlink" title="禁用nouveau"></a>禁用nouveau</h3><p>nouveau是一个第三方开源的Nvidia驱动,一般Linux安装的时候默认会安装这个驱动。 这个驱动会与Nvidia官方的驱动冲突,在安装Nvidia驱动和和CUDA之前应先禁用nouveau</p><p>查看系统是否正在使用nouveau</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">lsmod | grep nouveau</span><br></pre></td></tr></table></figure><p>如果有显示内容,则进行以下的步骤: <strong>Centos7禁用方法</strong></p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line"><span class="comment">#新建一个配置文件</span></span><br><span class="line">sudo vim /etc/modprobe.d/blacklist.conf</span><br><span class="line"></span><br><span class="line"><span class="comment">#写入以下内容</span></span><br><span class="line">blacklist nouveau</span><br><span class="line">options nouveau modeset=0</span><br><span class="line"></span><br><span class="line"><span class="comment">#保存并退出</span></span><br><span class="line">:wq</span><br><span class="line"></span><br><span class="line"><span class="comment">#备份当前的镜像</span></span><br><span class="line">sudo mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak</span><br><span class="line"></span><br><span class="line"><span class="comment">#建立新的镜像</span></span><br><span class="line">sudo dracut /boot/initramfs-$(uname -r).img $(uname -r)</span><br><span class="line"></span><br><span class="line"><span class="comment">#重启</span></span><br><span class="line">sudo reboot</span><br><span class="line"></span><br><span class="line"><span class="comment">#最后输入上面的命令验证</span></span><br><span class="line">lsmod | grep nouveau</span><br></pre></td></tr></table></figure><p>总之最后一定要保证<code>lsmod | grep nouveau</code>命令没有任何输出内容。 这也是runfile文件安装方式相对rpm/deb方式麻烦的一点,如果本节禁用nouveau有问题,可以尝试rpm/deb方式安装,rpm/deb方式安装会自动禁用</p><h3 id="下载驱动"><a href="#下载驱动" class="headerlink" title="下载驱动"></a>下载驱动</h3><p>首先在官网 <a href="https://www.nvidia.com/Download/index.aspx?lang=cn" target="_blank" rel="noopener">https://www.nvidia.com/Download/index.aspx?lang=cn</a> 查找自己显卡的驱动</p><p>我这里是 <code>NVIDIA Tesla P40</code> ,因为列表中可支持的最新版本cuda是 <code>10.0</code> ,所以下载的cuda为 10.0 的版本:<strong>NVIDIA-Linux-x86_64-410.104.run</strong></p><h3 id="安装驱动"><a href="#安装驱动" class="headerlink" title="安装驱动"></a>安装驱动</h3><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">sudo sh NVIDIA-Linux-x86_64-410.104.run --kernel-source-path=/usr/src/kernels/3.10.0-957.5.1.el7.x86_64</span><br></pre></td></tr></table></figure><blockquote><p>这里必须指明 <code>kernel-source-path</code> ,否则安装过程会报错</p></blockquote><h3 id="检验安装"><a href="#检验安装" class="headerlink" title="检验安装"></a>检验安装</h3><p>执行</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">nvidia-smi</span><br></pre></td></tr></table></figure><p>如下输出则说明成功</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">Thu Mar 14 18:40:38 2019 </span><br><span class="line">+-----------------------------------------------------------------------------+</span><br><span class="line">| NVIDIA-SMI 410.104 Driver Version: 410.104 CUDA Version: 10.0 |</span><br><span class="line">|-------------------------------+----------------------+----------------------+</span><br><span class="line">| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |</span><br><span class="line">| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |</span><br><span class="line">|===============================+======================+======================|</span><br><span class="line">| 0 Tesla P40 Off | 00000000:3B:00.0 Off | 0 |</span><br><span class="line">| N/A 25C P0 47W / 250W | 0MiB / 22919MiB | 0% Default |</span><br><span class="line">+-------------------------------+----------------------+----------------------+</span><br><span class="line"> </span><br><span class="line">+-----------------------------------------------------------------------------+</span><br><span class="line">| Processes: GPU Memory |</span><br><span class="line">| GPU PID Type Process name Usage |</span><br><span class="line">|=============================================================================|</span><br><span class="line">| No running processes found |</span><br><span class="line">+-----------------------------------------------------------------------------+</span><br></pre></td></tr></table></figure><h2 id="cuda"><a href="#cuda" class="headerlink" title="cuda"></a>cuda</h2><h3 id="下载cuda"><a href="#下载cuda" class="headerlink" title="下载cuda"></a>下载cuda</h3><p>因为 NVIDIA 官网上,P40的cuda最多支持到10.0版本,驱动下载的也是10.0版本,所以这里下载<code>cuda10.0</code></p><p>各版本下载链接 <a href="https://developer.nvidia.com/cuda-toolkit-archive" target="_blank" rel="noopener">https://developer.nvidia.com/cuda-toolkit-archive</a></p><p>我这里下载的是 <code>runfile</code></p><h3 id="安装cuda"><a href="#安装cuda" class="headerlink" title="安装cuda"></a>安装cuda</h3><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">sudo sh cuda_10.0.130_410.48_linux.run --kernel-source-path=/usr/src/kernels/3.10.0-957.5.1.el7.x86_64</span><br></pre></td></tr></table></figure><blockquote><p>这里必须指明 <code>kernel-source-path</code> ,否则安装过程会报错</p></blockquote><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line"><span class="comment">#刚开始安装会进入more模式,一直按`空格`即可</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#Do you accept the previously read EULA?</span></span><br><span class="line"><span class="comment">#是否接受协议</span></span><br><span class="line">accept</span><br><span class="line"></span><br><span class="line"><span class="comment">#Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 387.26?</span></span><br><span class="line"><span class="comment">#是否安装Nvida驱动,不需要</span></span><br><span class="line">n</span><br><span class="line"></span><br><span class="line"><span class="comment">#Install the CUDA 10.0 Toolkit?</span></span><br><span class="line">y</span><br><span class="line"></span><br><span class="line"><span class="comment">#Enter Toolkit Location</span></span><br><span class="line"><span class="comment">#输入Toolkit的安装目录</span></span><br><span class="line"><span class="comment">#一般默认即可</span></span><br><span class="line"><span class="comment">#如果更改的话,注意是不可以改成 /usr/local/cuda 的,其余都可以</span></span><br><span class="line">回车</span><br><span class="line"></span><br><span class="line"><span class="comment">#Do you want to install a symbolic link at /usr/local/cuda?</span></span><br><span class="line"><span class="comment">#创建一个软连接,我选择是</span></span><br><span class="line">y</span><br><span class="line"></span><br><span class="line"><span class="comment">#Install the CUDA 10.0 Samples?</span></span><br><span class="line"><span class="comment">#安装CUDA官方示例包</span></span><br><span class="line"><span class="comment">#这里选择 no,因为安装目录下就有</span></span><br><span class="line">n</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">#如果版本不同,提示也可能不同,根据情况输入或选择</span></span><br></pre></td></tr></table></figure><h2 id="cudnn"><a href="#cudnn" class="headerlink" title="cudnn"></a>cudnn</h2><h3 id="下载cudnn"><a href="#下载cudnn" class="headerlink" title="下载cudnn"></a>下载cudnn</h3><blockquote><p>注意和 <code>cuda</code> 版本匹配</p></blockquote><h3 id="安装cudnn"><a href="#安装cudnn" class="headerlink" title="安装cudnn"></a>安装cudnn</h3><p>按照官网命令</p><p><a href="https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html" target="_blank" rel="noopener">https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html</a></p><ul><li><p>Navigate to your <code>cudnnpath</code> directory containing the cuDNN Tar file.</p></li><li><p>Unzip the cuDNN package.</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">tar -xzvf cudnn-10.0-linux-x64-v7.5.0.56.tgz</span><br></pre></td></tr></table></figure></li><li><p>Copy the following files into the CUDA Toolkit directory, and change the file permissions.</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">sudo cp cuda/include/cudnn.h /usr/<span class="built_in">local</span>/cuda/include</span><br><span class="line">sudo cp cuda/lib64/libcudnn* /usr/<span class="built_in">local</span>/cuda/lib64</span><br><span class="line">sudo chmod a+r /usr/<span class="built_in">local</span>/cuda/include/cudnn.h /usr/<span class="built_in">local</span>/cuda/lib64/libcudnn*</span><br></pre></td></tr></table></figure></li></ul>]]></content>
<summary type="html"><h2 id="环境"><a href="#环境" class="headerlink" title="环境"></a>环境</h2><ul>
<li><p>系统</p>
<p>CentOS Linux release 7.6.1810 (Core)</p>
</li>
<li></summary>
<category term="安装记录" scheme="https://www.holmeyoung.com/categories/安装记录/"/>
<category term="linux" scheme="https://www.holmeyoung.com/tags/linux/"/>
<category term="gpu" scheme="https://www.holmeyoung.com/tags/gpu/"/>
<category term="机器学习" scheme="https://www.holmeyoung.com/tags/机器学习/"/>
</entry>
<entry>
<title>centos7 anaconda3 安装 youcompleteme</title>
<link href="https://www.holmeyoung.com/blog/centos7-anaconda3-youcompleteme/"/>
<id>https://www.holmeyoung.com/blog/centos7-anaconda3-youcompleteme/</id>
<published>2018-11-07T02:27:06.000Z</published>
<updated>2022-10-06T07:36:56.304Z</updated>
<content type="html"><![CDATA[<h3 id="环境"><a href="#环境" class="headerlink" title="环境"></a>环境</h3><ul><li><strong><code>CentOS7</code></strong></li><li><strong><code>Anaconda3</code></strong></li><li><strong><code>oh-my-zsh</code></strong></li></ul><h3 id="更新yum"><a href="#更新yum" class="headerlink" title="更新yum"></a>更新yum</h3><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">sudo yum upgrade</span><br><span class="line">sudo yum update</span><br></pre></td></tr></table></figure><h3 id="安装可能需要的"><a href="#安装可能需要的" class="headerlink" title="安装可能需要的"></a>安装可能需要的</h3><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">sudo yum install python-devel</span><br><span class="line">sudo yum install cmake</span><br></pre></td></tr></table></figure><h3 id="升级gcc"><a href="#升级gcc" class="headerlink" title="升级gcc"></a>升级gcc</h3><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">sudo yum install centos-release-scl -y</span><br><span class="line">sudo yum install devtoolset-3-toolchain -y</span><br><span class="line">sudo yum install gcc-c++</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 如果安装了 oh-my—zsh 则不执行下面这句,否则会切换为bash</span></span><br><span class="line">sudo scl enable devtoolset-3 bash</span><br></pre></td></tr></table></figure><h3 id="禁用Anaconda3"><a href="#禁用Anaconda3" class="headerlink" title="禁用Anaconda3"></a>禁用Anaconda3</h3><p>将 </p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line"><span class="built_in">export</span> PATH=<span class="string">"/root/anaconda3/bin:<span class="variable">$PATH</span>"</span></span><br></pre></td></tr></table></figure><p>从 <code>.zshrc</code> 、<code>.bashrc</code> 中注释掉</p><p>注释后<strong>根目录下</strong>执行</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line"><span class="built_in">source</span> .zshrc</span><br><span class="line"><span class="built_in">source</span> .bashrc</span><br></pre></td></tr></table></figure><blockquote><p>此时执行</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">> python -V</span><br><span class="line">></span><br></pre></td></tr></table></figure></blockquote><blockquote><p>依旧会显示 <code>Python 3.6.5 :: Anaconda, Inc.</code> </p><p><strong>所以我们需要新开一个终端运行下面的命令</strong></p></blockquote><h3 id="卸载系统原生vim(vim7)"><a href="#卸载系统原生vim(vim7)" class="headerlink" title="卸载系统原生vim(vim7)"></a>卸载系统原生vim(vim7)</h3><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">yum remove vim</span><br></pre></td></tr></table></figure><h3 id="自己源码安装vim(vim8)"><a href="#自己源码安装vim(vim8)" class="headerlink" title="自己源码安装vim(vim8)"></a>自己源码安装vim(vim8)</h3><h4 id="安装命令"><a href="#安装命令" class="headerlink" title="安装命令"></a>安装命令</h4><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">git clone https://github.com/vim/vim.git</span><br><span class="line">cd vim/src</span><br></pre></td></tr></table></figure><blockquote><p><strong><code>下面是最关键的一步,多少次失败都是因为这个命令不对!!!</code></strong></p></blockquote><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">./configure --with-features=huge --<span class="built_in">enable</span>-pythoninterp=yes --<span class="built_in">enable</span>-python3interp=yes --with-python3-config-dir=/root/anaconda3/lib/python3.6/config-3.6m-x86_64-linux-gnu</span><br></pre></td></tr></table></figure><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">sudo make</span><br><span class="line">sudo make install</span><br></pre></td></tr></table></figure><blockquote><p><code>--with-python3-config-dir=/root/anaconda3/lib/python3.6/config-3.6m-x86_64-linux-gnu</code></p><p>这条命令根据不同人 <code>anaconda3</code> 安装位置不同会有变动</p></blockquote><h4 id="环境设置"><a href="#环境设置" class="headerlink" title="环境设置"></a>环境设置</h4><p>将</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line"><span class="built_in">export</span> PATH=<span class="string">"/usr/local/bin:<span class="variable">$PATH</span>"</span></span><br></pre></td></tr></table></figure><p>配置了 <code>oh-my-zsh</code> 的,添加到 <code>.zshrc</code></p><p>没配置 <code>oh-my-zsh</code> 的,添加到 <code>.bashrc</code></p><p>添加后<strong>根目录下</strong>执行</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line"><span class="built_in">source</span> .zshrc</span><br><span class="line"><span class="comment"># source .bashrc</span></span><br></pre></td></tr></table></figure><h4 id="关于安装"><a href="#关于安装" class="headerlink" title="关于安装"></a>关于安装</h4><h5 id="命令参数"><a href="#命令参数" class="headerlink" title="命令参数"></a>命令参数</h5><p>这里列举一些<code>./configure</code> 后面的配置选项</p><table><thead><tr><th>参数</th><th>含义</th></tr></thead><tbody><tr><td><strong><code>--with-features=huge</code></strong></td><td>支持最大特性</td></tr><tr><td><strong><code>--enable-rubyinterp=yes</code></strong></td><td>打开对ruby编写的插件的支持</td></tr><tr><td><strong><code>--enable-pythoninterp=yes</code></strong></td><td>打开对python编写的插件的支持</td></tr><tr><td><strong><code>--enable-python3interp=yes</code></strong></td><td>打开对python3编写的插件的支持</td></tr><tr><td><strong><code>--enable-luainterp=yes</code></strong></td><td>打开对lua编写的插件的支持</td></tr><tr><td><strong><code>--enable-perlinterp=yes</code></strong></td><td>打开对perl编写的插件的支持</td></tr><tr><td><strong><code>--enable-multibyte=yes</code></strong></td><td>打开多字节支持,可以在Vim中输入中文</td></tr><tr><td><strong><code>--enable-cscope=yes</code></strong></td><td>打开对cscope的支持</td></tr><tr><td><strong><code>--with-python-config-dir=/usr/lib/python2.7/config-x86_64-linux-gnu</code></strong></td><td>指定python 路径</td></tr><tr><td><strong><code>--with-python3-config-dir=/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu</code></strong></td><td>指定python3路径</td></tr><tr><td><strong><code>--prefix=/usr/local/vim</code></strong></td><td>指定将要安装到的路径(自行创建)</td></tr></tbody></table><h5 id="安装路径"><a href="#安装路径" class="headerlink" title="安装路径"></a>安装路径</h5><ul><li><p>通过 <code>yum install xxx</code> 安装的 <strong>软件</strong> 在 <code>usr/bin/</code> 下</p></li><li><p>通过 <strong>源码</strong> 安装的 <strong>软件</strong> 在 <code>usr/local/bin/</code> 下</p></li></ul><p>当我们通过 <code>yum remove vim</code> 卸载 <code>vim</code> 后再通过源码安装,安装好之后再输入 <code>vim</code> 默认指向的就是 <code>usr/local/bin/</code> 下的自己安装的</p><p>如下</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">➜ /root whereis vim</span><br><span class="line">vim: /usr/local/bin/vim /usr/share/vim /usr/share/man/man1/vim.1.gz</span><br></pre></td></tr></table></figure><h3 id="安装YouCompleteMe"><a href="#安装YouCompleteMe" class="headerlink" title="安装YouCompleteMe"></a>安装YouCompleteMe</h3><p>根目录下执行</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git <span class="built_in">clone</span> https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim</span><br></pre></td></tr></table></figure><p>编辑 <code>.vimrc</code> ,加入</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line"><span class="string">" Vundle Setting</span></span><br><span class="line"><span class="string">set nocompatible</span></span><br><span class="line"><span class="string">filetype off</span></span><br><span class="line"><span class="string">set rtp+=~/.vim/bundle/Vundle.vim</span></span><br><span class="line"><span class="string">call vundle#begin()</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span> <span class="built_in">let</span> Vundle manage Vundle, required</span><br><span class="line">Plugin <span class="string">'VundleVim/Vundle.vim'</span></span><br><span class="line"></span><br><span class="line"><span class="string">" Plugins</span></span><br><span class="line"><span class="string">Plugin 'Valloric/YouCompleteMe'</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span> All of your Plugins must be added before the following line</span><br><span class="line">call vundle<span class="comment">#end()</span></span><br><span class="line">filetype plugin indent on</span><br></pre></td></tr></table></figure><p>保存退出</p><p>在终端执行</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">vim +PluginInstall +qall</span><br></pre></td></tr></table></figure><p>或者在 <code>vim</code> 中执行</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">:PluginInstall</span><br></pre></td></tr></table></figure><p>等待插件安装完成自动退出</p><p>此时会提示 <code>YouCompleteMe</code> 未编译</p><p>执行</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line"><span class="built_in">cd</span> ~/.vim/bundle/YouCompleteMe</span><br><span class="line">./install.py --clang-completer</span><br></pre></td></tr></table></figure><p>这里只编译了 <code>YouCompleteMe</code> 对 <code>C</code> 族的补全,更多语言的补全命令可见 <a href="https://github.com/Valloric/YouCompleteMe" target="_blank" rel="noopener">YouCompleteMe</a> </p><h4 id="关于另一个版本的安装方法"><a href="#关于另一个版本的安装方法" class="headerlink" title="关于另一个版本的安装方法"></a>关于另一个版本的安装方法</h4><ol><li><p>如果已经安装 <code>Vundle</code> 直接跳到 <code>2</code></p><p>根目录下执行</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git <span class="built_in">clone</span> https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim</span><br></pre></td></tr></table></figure><p>编辑 <code>.vimrc</code> ,加入</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line"><span class="string">" Vundle Setting</span></span><br><span class="line"><span class="string">set nocompatible</span></span><br><span class="line"><span class="string">filetype off</span></span><br><span class="line"><span class="string">set rtp+=~/.vim/bundle/Vundle.vim</span></span><br><span class="line"><span class="string">call vundle#begin()</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">"</span> <span class="built_in">let</span> Vundle manage Vundle, required</span><br><span class="line">Plugin <span class="string">'VundleVim/Vundle.vim'</span></span><br><span class="line"></span><br><span class="line"><span class="string">" Plugins</span></span><br><span class="line"><span class="string">"</span> Plugin <span class="string">'Valloric/YouCompleteMe'</span></span><br><span class="line"></span><br><span class="line"><span class="string">" All of your Plugins must be added before the following line</span></span><br><span class="line"><span class="string">call vundle#end()</span></span><br><span class="line"><span class="string">filetype plugin indent on</span></span><br></pre></td></tr></table></figure><p>保存退出执行</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">vim +PluginInstall +qall</span><br></pre></td></tr></table></figure><p>或者在 <code>vim</code> 中执行</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">:PluginInstall</span><br></pre></td></tr></table></figure></li><li><p>安装 <code>YouCompleteMe</code></p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git <span class="built_in">clone</span> https://github.com/Valloric/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe</span><br><span class="line"><span class="built_in">cd</span> ~/.vim/bundle/YouCompleteMe</span><br><span class="line">git submodule update --init --recursive</span><br></pre></td></tr></table></figure><p>编辑 <code>.vimrc</code> ,取消第 <code>11</code> 行的注释,即变为</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">Plugin <span class="string">'Valloric/YouCompleteMe'</span></span><br></pre></td></tr></table></figure><p>保存退出后执行</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line"><span class="built_in">cd</span> ~/.vim/bundle/YouCompleteMe</span><br><span class="line">./install.py --clang-completer</span><br></pre></td></tr></table></figure><p><strong>DONE</strong></p></li></ol><blockquote><p><strong><code>这个安装方法我试了是没有成功的,可能是我环境的原因</code></strong></p></blockquote><blockquote><p>亲测在 <code>.vimrc</code> 中添加</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">> Plugin <span class="string">'Valloric/YouCompleteMe'</span></span><br><span class="line">></span><br></pre></td></tr></table></figure></blockquote><blockquote><p>并执行</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">> vim +PluginInstall +qall</span><br><span class="line">></span><br></pre></td></tr></table></figure></blockquote><blockquote><p>后</p><p>命令</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">> git submodule update --init --recursive</span><br><span class="line">></span><br></pre></td></tr></table></figure></blockquote><blockquote><p>会失效,故采用 <code>Vundle</code> 安装可直接执行命令</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">> ./install.py --clang-completer</span><br><span class="line">></span><br></pre></td></tr></table></figure></blockquote><blockquote><p>进行编译</p></blockquote><h3 id="放生Anaconda3"><a href="#放生Anaconda3" class="headerlink" title="放生Anaconda3"></a>放生Anaconda3</h3><p>将</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line"><span class="built_in">export</span> PATH=<span class="string">"/root/anaconda3/bin:<span class="variable">$PATH</span>"</span></span><br></pre></td></tr></table></figure><p>在 <code>.zshrc</code> 中的注释去掉</p><p>没有安装 <code>oh-my-zsh</code> 的则去掉 <code>.bashrc</code> 中的注释</p><p>保存退出后<strong>根目录下</strong>执行</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line"><span class="built_in">source</span> .zshrc</span><br><span class="line"><span class="built_in">source</span> .bashrc</span><br></pre></td></tr></table></figure><blockquote><p>此时执行</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">> python -V</span><br><span class="line">></span><br></pre></td></tr></table></figure></blockquote><blockquote><p>会显示 <code>Python 3.6.5 :: Anaconda, Inc.</code> </p></blockquote><p><strong>DONE</strong></p><h3 id="Ref"><a href="#Ref" class="headerlink" title="Ref"></a>Ref</h3><blockquote><p><a href="https://www.cnblogs.com/hugb/p/8593012.html" target="_blank" rel="noopener">Centos7安装vim8.0 + YouCompleteMe</a></p></blockquote>]]></content>
<summary type="html"><h3 id="环境"><a href="#环境" class="headerlink" title="环境"></a>环境</h3><ul>
<li><strong><code>CentOS7</code></strong></li>
<li><strong><code>Ana</summary>
<category term="安装记录" scheme="https://www.holmeyoung.com/categories/安装记录/"/>
<category term="linux" scheme="https://www.holmeyoung.com/tags/linux/"/>
</entry>
<entry>
<title>python 进程间管道通信</title>
<link href="https://www.holmeyoung.com/blog/python-process-fifo/"/>
<id>https://www.holmeyoung.com/blog/python-process-fifo/</id>
<published>2018-11-05T06:04:13.000Z</published>
<updated>2022-10-06T07:36:56.304Z</updated>
<content type="html"><![CDATA[<p>实现了两个 <code>Linux</code> 进程之间通过管道进行通讯的代码逻辑。分为 <code>client.py</code> 与 <code>server.py</code> 运行时需要先运行 <code>server</code> 再运行 <code>client</code></p><p><code>client.py</code></p><figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"></span><br><span class="line">write_path = <span class="string">"pipe.in"</span></span><br><span class="line">read_path = <span class="string">"pipe.out"</span></span><br><span class="line"></span><br><span class="line">wf = os.open(write_path, os.O_SYNC | os.O_CREAT | os.O_RDWR)</span><br><span class="line">rf = <span class="literal">None</span></span><br><span class="line"><span class="comment"># rf = os.open(read_path, os.O_RDONLY)</span></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">1</span>, <span class="number">11</span>):</span><br><span class="line"> msg = <span class="string">"msg "</span> + str(i)</span><br><span class="line"> msg = msg.encode()</span><br><span class="line"> len_send = os.write(wf, msg)</span><br><span class="line"> <span class="keyword">print</span> (<span class="string">"sent msg: %s"</span> % msg)</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> rf <span class="keyword">is</span> <span class="literal">None</span>:</span><br><span class="line"> rf = os.open(read_path, os.O_RDONLY)</span><br><span class="line"></span><br><span class="line"> s = os.read(rf, <span class="number">1024</span>)</span><br><span class="line"> <span class="keyword">if</span> len(s) == <span class="number">0</span>:</span><br><span class="line"> <span class="keyword">break</span></span><br><span class="line"> <span class="keyword">print</span> (<span class="string">"received msg: %s"</span> % s)</span><br><span class="line"></span><br><span class="line"> time.sleep(<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line">os.write(wf, <span class="string">'exit'</span>.encode())</span><br><span class="line"></span><br><span class="line">os.close(rf)</span><br><span class="line">os.close(wf)</span><br></pre></td></tr></table></figure><p><code>server.py</code></p><figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> os, time</span><br><span class="line"></span><br><span class="line">read_path = <span class="string">"pipe.in"</span></span><br><span class="line">write_path = <span class="string">"pipe.out"</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> os.path.exists(read_path):</span><br><span class="line"> os.remove(read_path)</span><br><span class="line"><span class="keyword">if</span> os.path.exists(write_path):</span><br><span class="line"> os.remove(write_path)</span><br><span class="line"></span><br><span class="line">os.mkfifo(write_path)</span><br><span class="line">os.mkfifo(read_path)</span><br><span class="line"></span><br><span class="line">rf = os.open(read_path, os.O_RDONLY)</span><br><span class="line">wf = os.open(write_path, os.O_SYNC | os.O_CREAT | os.O_RDWR)</span><br><span class="line"></span><br><span class="line"><span class="keyword">while</span> <span class="literal">True</span>:</span><br><span class="line"> s = os.read(rf, <span class="number">1024</span>)</span><br><span class="line"> <span class="keyword">print</span> (<span class="string">"received msg: %s"</span> % s)</span><br><span class="line"> <span class="keyword">if</span> len(s) == <span class="number">0</span>:</span><br><span class="line"> time.sleep(<span class="number">1</span>)</span><br><span class="line"> <span class="keyword">continue</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> <span class="string">"exit"</span>.encode() <span class="keyword">in</span> s:</span><br><span class="line"> <span class="keyword">break</span></span><br><span class="line"></span><br><span class="line"> os.write(wf, s)</span><br><span class="line"></span><br><span class="line">os.close(rf)</span><br><span class="line">os.close(wf)</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html"><p>实现了两个 <code>Linux</code> 进程之间通过管道进行通讯的代码逻辑。分为 <code>client.py</code> 与 <code>server.py</code> 运行时需要先运行 <code>server</code> 再运行 <code>clie</summary>
<category term="python" scheme="https://www.holmeyoung.com/categories/python/"/>
<category term="python" scheme="https://www.holmeyoung.com/tags/python/"/>
</entry>
<entry>
<title>修改 pip 源为清华大学开源镜像</title>
<link href="https://www.holmeyoung.com/blog/change-pip-mirror/"/>
<id>https://www.holmeyoung.com/blog/change-pip-mirror/</id>
<published>2018-06-14T11:19:17.000Z</published>
<updated>2022-10-06T07:36:56.304Z</updated>
<content type="html"><![CDATA[<h3 id="pypi-镜像使用帮助"><a href="#pypi-镜像使用帮助" class="headerlink" title="pypi 镜像使用帮助"></a>pypi 镜像使用帮助</h3><p><code>pypi</code> 镜像每 5 分钟同步一次。</p><h3 id="临时使用"><a href="#临时使用" class="headerlink" title="临时使用"></a>临时使用</h3><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package</span><br></pre></td></tr></table></figure><p>注意, <code>simple</code> 不能少, 是 <code>https</code> 而不是 <code>http</code> </p><h3 id="设为默认"><a href="#设为默认" class="headerlink" title="设为默认"></a>设为默认</h3><p>修改 <code>~/.config/pip/pip.conf</code> <strong>(Linux)</strong>, <code>%APPDATA%\pip\pip.ini</code> <strong>(Windows 10)</strong> 或 <code>$HOME/Library/Application Support/pip/pip.conf</code> <strong>(macOS)</strong> (没有就创建一个), 修改 <code>index-url</code> 至 <code>tuna</code> ,例如</p><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">[global]</span><br><span class="line">index-url = https://pypi.tuna.tsinghua.edu.cn/simple</span><br></pre></td></tr></table></figure><p><code>pip</code> 和 <code>pip3</code> 并存时,只需修改 <code>~/.pip/pip.conf</code> </p>]]></content>
<summary type="html"><h3 id="pypi-镜像使用帮助"><a href="#pypi-镜像使用帮助" class="headerlink" title="pypi 镜像使用帮助"></a>pypi 镜像使用帮助</h3><p><code>pypi</code> 镜像每 5 分钟同步一次。</p</summary>
<category term="linux" scheme="https://www.holmeyoung.com/categories/linux/"/>
<category term="python" scheme="https://www.holmeyoung.com/tags/python/"/>
</entry>
<entry>
<title>ubuntu14.04 安装 caffe</title>
<link href="https://www.holmeyoung.com/blog/ubuntu14-caffe/"/>
<id>https://www.holmeyoung.com/blog/ubuntu14-caffe/</id>
<published>2018-04-30T09:01:05.000Z</published>
<updated>2022-10-06T07:36:56.304Z</updated>
<content type="html"><![CDATA[<h3 id="组件-amp-版本"><a href="#组件-amp-版本" class="headerlink" title="组件&版本"></a>组件&版本</h3><ul><li><p><strong>Ubuntu</strong></p><ul><li>14.04</li></ul></li><li><p><strong>CUDA</strong></p><ul><li>8.0</li></ul></li><li><strong>cuDNN</strong><ul><li>cudnn-7.0-linux-x64-<strong>v3.0</strong>-prod.tgz</li></ul></li><li><strong>opencv</strong><ul><li>3.2</li></ul></li><li><strong>python</strong><ul><li>Python 2.7.6</li></ul></li><li><strong>caffe</strong><ul><li>release candidate 3</li></ul></li></ul><h3 id="安装过程"><a href="#安装过程" class="headerlink" title="安装过程"></a>安装过程</h3><h4 id="安装开发所需依赖包"><a href="#安装开发所需依赖包" class="headerlink" title="安装开发所需依赖包"></a>安装开发所需依赖包</h4><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">sudo apt-get install build-essential </span><br><span class="line">sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler</span><br></pre></td></tr></table></figure><h4 id="安装CUDA-8-0"><a href="#安装CUDA-8-0" class="headerlink" title="安装CUDA 8.0"></a>安装CUDA 8.0</h4><ul><li><p>确定 <code>GPU</code> 支持 <code>CUDA</code></p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">lspci | grep -i nvidia</span><br></pre></td></tr></table></figure><p>显示</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">02:00.0 VGA compatible controller: NVIDIA Corporation Device 1b06 (rev a1)</span><br><span class="line">02:00.1 Audio device: NVIDIA Corporation Device 10ef (rev a1)</span><br><span class="line">03:00.0 VGA compatible controller: NVIDIA Corporation Device 1b06 (rev a1)</span><br><span class="line">03:00.1 Audio device: NVIDIA Corporation Device 10ef (rev a1)</span><br><span class="line">82:00.0 VGA compatible controller: NVIDIA Corporation Device 1b06 (rev a1)</span><br><span class="line">82:00.1 Audio device: NVIDIA Corporation Device 10ef (rev a1)</span><br><span class="line">83:00.0 VGA compatible controller: NVIDIA Corporation Device 1b06 (rev a1)</span><br><span class="line">83:00.1 Audio device: NVIDIA Corporation Device 10ef (rev a1)</span><br></pre></td></tr></table></figure><p>根据 <strong><a href="http://developer.nvidia.com/cuda-gpus" target="_blank" rel="noopener">http://developer.nvidia.com/cuda-gpus</a></strong> 去验证,发现支持 <code>CUDA</code></p></li><li><p>确定 <code>linux</code> 版本支持 <code>CUDA</code></p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">uname -m && cat /etc/*release</span><br></pre></td></tr></table></figure><p>显示</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">x86_64</span><br><span class="line">DISTRIB_ID=Ubuntu</span><br><span class="line">DISTRIB_RELEASE=14.04</span><br><span class="line">DISTRIB_CODENAME=trusty</span><br><span class="line">DISTRIB_DESCRIPTION="Ubuntu 14.04.5 LTS"</span><br><span class="line">NAME="Ubuntu"</span><br><span class="line">VERSION="14.04.5 LTS, Trusty Tahr"</span><br><span class="line">ID=ubuntu</span><br><span class="line">ID_LIKE=debian</span><br><span class="line">PRETTY_NAME="Ubuntu 14.04.5 LTS"</span><br><span class="line">VERSION_ID="14.04"</span><br><span class="line">HOME_URL="http://www.ubuntu.com/"</span><br><span class="line">SUPPORT_URL="http://help.ubuntu.com/"</span><br><span class="line">BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"</span><br></pre></td></tr></table></figure></li><li><p>确定系统已经安装了 <code>gcc</code></p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">gcc --version</span><br></pre></td></tr></table></figure><p>显示</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">gcc (Ubuntu 4.8.5-2ubuntu1~14.04.1) 4.8.5</span><br><span class="line">Copyright (C) 2015 Free Software Foundation, Inc.</span><br><span class="line">This is free software; see the source for copying conditions. There is NO</span><br><span class="line">warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</span><br></pre></td></tr></table></figure></li><li><p>确定系统已经安装了正确的 <code>Kernel Headers</code> 和开发包</p><ul><li><p>查看系统正在运行的 <code>kernel</code> 版本</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">uname -r</span><br></pre></td></tr></table></figure><p>显示</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">3.13.0-142-generic</span><br></pre></td></tr></table></figure></li><li><p>安装对应的 <code>kernels header</code> 和开发包</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">sudo apt-get install linux-headers-$(uname -r)</span><br></pre></td></tr></table></figure></li></ul></li><li><p>安装 <code>CUDA</code></p><ul><li>下载对应版本的cuda,从 <strong><a href="https://developer.nvidia.com/cuda-downloads" target="_blank" rel="noopener">https://developer.nvidia.com/cuda-downloads</a></strong> 下载 <code>deb(network)</code> 版</li></ul></li></ul><ul><li><p>进行 <code>md5</code> 校验</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">md5sum cuda-repo-ubuntu1404_8.0.61-1_amd64.deb</span><br></pre></td></tr></table></figure></li><li><p>对比相同,然后使用 <code>deb</code> 文件进行安装</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">sudo dpkg -i cuda-repo-ubuntu1404_8.0.61-1_amd64.deb</span><br><span class="line">sudo apt-get update</span><br><span class="line">sudo apt-get install cuda</span><br></pre></td></tr></table></figure></li><li><p>重启,完成 <code>cuda</code> 安装</p></li></ul><h4 id="安装-cuDNN"><a href="#安装-cuDNN" class="headerlink" title="安装 cuDNN"></a>安装 cuDNN</h4><ul><li><p>从 <strong><a href="https://developer.nvidia.com/rdp/cudnn-download" target="_blank" rel="noopener">https://developer.nvidia.com/rdp/cudnn-download</a></strong> 下载 <code>cuDNN</code> ,版本为 <code>cudnn-7.0-linux-x64-v3.0-prod.tgz</code></p></li><li><p>安装</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">tar -zxvf cudnn-7.0-linux-x64-v3.0-prod.tgz</span><br><span class="line">cd cuda</span><br><span class="line">sudo cp lib64/* /usr/local/cuda/lib64/</span><br><span class="line">sudo cp include/cudnn.h /usr/local/cuda/include/</span><br></pre></td></tr></table></figure></li><li><p>更新软链接</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">cd /usr/local/cuda/lib64</span><br><span class="line">sudo rm -rf libcudnn.so libcudnn.so.7.0</span><br><span class="line">sudo ln -s libcudnn.so.7.0.64 libcudnn.so.7.0</span><br><span class="line">sudo ln -s libcudnn.so.7.0 libcudnn.so</span><br></pre></td></tr></table></figure></li></ul><h4 id="设置-CUDA-环境变量"><a href="#设置-CUDA-环境变量" class="headerlink" title="设置 CUDA 环境变量"></a>设置 CUDA 环境变量</h4><ul><li><p><strong>VERSION1</strong></p><ul><li><p>在 <code>/etc/profile</code> 中添加 <code>CUDA</code> 环境变量</p></li><li><p>执行</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">sudo vim /etc/profile</span><br></pre></td></tr></table></figure><p>在打开的文件中加入如下两句话</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="built_in">export</span> PATH=/usr/<span class="built_in">local</span>/cuda/bin:<span class="variable">$PATH</span></span><br><span class="line"><span class="built_in">export</span> LD_LIBRARY_PATH=/usr/<span class="built_in">local</span>/cuda/lib64:<span class="variable">$LD_LIBRARY_PATH</span></span><br></pre></td></tr></table></figure></li><li><p>保存后,使环境变量立即生效,执行</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">source /etc/profile</span><br></pre></td></tr></table></figure></li></ul></li><li><p><strong>VERSION2</strong></p><ul><li><p>在 <code>~/.bashrc</code> 中添加 <code>CUDA</code> 环境变量</p></li><li><p>执行</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">sudo vim ~/.bashrc</span><br></pre></td></tr></table></figure><p>在打开的文件中加入如下两句话</p><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line"><span class="built_in">export</span> PATH=/usr/<span class="built_in">local</span>/cuda/bin:<span class="variable">$PATH</span></span><br><span class="line"><span class="built_in">export</span> LD_LIBRARY_PATH=/usr/<span class="built_in">local</span>/cuda/lib64:<span class="variable">$LD_LIBRARY_PATH</span></span><br></pre></td></tr></table></figure></li><li><p>保存后,使环境变量立即生效,执行</p></li></ul></li><li><p>我用的 <code>VERSION2</code></p></li></ul><h4 id="安装cuda-samples"><a href="#安装cuda-samples" class="headerlink" title="安装cuda samples"></a>安装cuda samples</h4><ul><li><p>进入 <code>/usr/local/cuda/samples</code></p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">cd /usr/local/cuda/samples</span><br></pre></td></tr></table></figure></li><li><p>执行下面的命令来 <code>build samples</code></p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">sudo make all -j4</span><br></pre></td></tr></table></figure></li><li><p>全部编译完成后,进入 <code>samples/bin/x86_64/linux/release</code> ,运行 <code>deviceQuery</code></p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">cd /usr/local/cuda/samples/bin/x86_64/linux/release</span><br><span class="line">./deviceQuery</span><br></pre></td></tr></table></figure><p>如果出现显卡信息,则驱动及显卡安装成功,结果如下</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">./deviceQuery Starting...</span><br><span class="line"></span><br><span class="line"> CUDA Device Query (Runtime API) version (CUDART static linking)</span><br><span class="line"></span><br><span class="line">Detected 4 CUDA Capable device(s)</span><br><span class="line"></span><br><span class="line">Device 0: "GeForce GTX 1080 Ti"</span><br><span class="line">.</span><br><span class="line">.</span><br><span class="line">.</span><br><span class="line">Device 3: "GeForce GTX 1080 Ti"</span><br><span class="line"> CUDA Driver Version / Runtime Version 9.0 / 8.0</span><br><span class="line"> CUDA Capability Major/Minor version number: 6.1</span><br><span class="line"> Total amount of global memory: 11172 MBytes (11715084288 bytes)</span><br><span class="line"> (28) Multiprocessors, (128) CUDA Cores/MP: 3584 CUDA Cores</span><br><span class="line"> GPU Max Clock rate: 1582 MHz (1.58 GHz)</span><br><span class="line"> Memory Clock rate: 5505 Mhz</span><br><span class="line"> Memory Bus Width: 352-bit</span><br><span class="line"> L2 Cache Size: 2883584 bytes</span><br><span class="line"> Maximum Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)</span><br><span class="line"> Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers</span><br><span class="line"> Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers</span><br><span class="line"> Total amount of constant memory: 65536 bytes</span><br><span class="line"> Total amount of shared memory per block: 49152 bytes</span><br><span class="line"> Total number of registers available per block: 65536</span><br><span class="line"> Warp size: 32</span><br><span class="line"> Maximum number of threads per multiprocessor: 2048</span><br><span class="line"> Maximum number of threads per block: 1024</span><br><span class="line"> Max dimension size of a thread block (x,y,z): (1024, 1024, 64)</span><br><span class="line"> Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)</span><br><span class="line"> Maximum memory pitch: 2147483647 bytes</span><br><span class="line"> Texture alignment: 512 bytes</span><br><span class="line"> Concurrent copy and kernel execution: Yes with 2 copy engine(s)</span><br><span class="line"> Run time limit on kernels: No</span><br><span class="line"> Integrated GPU sharing Host Memory: No</span><br><span class="line"> Support host page-locked memory mapping: Yes</span><br><span class="line"> Alignment requirement for Surfaces: Yes</span><br><span class="line"> Device has ECC support: Disabled</span><br><span class="line"> Device supports Unified Addressing (UVA): Yes</span><br><span class="line"> Device PCI Domain ID / Bus ID / location ID: 0 / 131 / 0</span><br><span class="line"> Compute Mode:</span><br><span class="line"> < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) ></span><br><span class="line"><span class="meta">></span><span class="bash"> Peer access from GeForce GTX 1080 Ti (GPU0) -> GeForce GTX 1080 Ti (GPU1) : Yes</span></span><br><span class="line"><span class="meta">></span><span class="bash"> Peer access from GeForce GTX 1080 Ti (GPU0) -> GeForce GTX 1080 Ti (GPU2) : No</span></span><br><span class="line"><span class="meta">></span><span class="bash"> Peer access from GeForce GTX 1080 Ti (GPU0) -> GeForce GTX 1080 Ti (GPU3) : No</span></span><br><span class="line"><span class="meta">></span><span class="bash"> Peer access from GeForce GTX 1080 Ti (GPU1) -> GeForce GTX 1080 Ti (GPU0) : Yes</span></span><br><span class="line"><span class="meta">></span><span class="bash"> Peer access from GeForce GTX 1080 Ti (GPU1) -> GeForce GTX 1080 Ti (GPU2) : No</span></span><br><span class="line"><span class="meta">></span><span class="bash"> Peer access from GeForce GTX 1080 Ti (GPU1) -> GeForce GTX 1080 Ti (GPU3) : No</span></span><br><span class="line"><span class="meta">></span><span class="bash"> Peer access from GeForce GTX 1080 Ti (GPU2) -> GeForce GTX 1080 Ti (GPU0) : No</span></span><br><span class="line"><span class="meta">></span><span class="bash"> Peer access from GeForce GTX 1080 Ti (GPU2) -> GeForce GTX 1080 Ti (GPU1) : No</span></span><br><span class="line"><span class="meta">></span><span class="bash"> Peer access from GeForce GTX 1080 Ti (GPU2) -> GeForce GTX 1080 Ti (GPU3) : Yes</span></span><br><span class="line"><span class="meta">></span><span class="bash"> Peer access from GeForce GTX 1080 Ti (GPU3) -> GeForce GTX 1080 Ti (GPU0) : No</span></span><br><span class="line"><span class="meta">></span><span class="bash"> Peer access from GeForce GTX 1080 Ti (GPU3) -> GeForce GTX 1080 Ti (GPU1) : No</span></span><br><span class="line"><span class="meta">></span><span class="bash"> Peer access from GeForce GTX 1080 Ti (GPU3) -> GeForce GTX 1080 Ti (GPU2) : Yes</span></span><br><span class="line"></span><br><span class="line">deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 9.0, CUDA Runtime Version = 8.0, NumDevs = 4, Device0 = GeForce GTX 1080 Ti, Device1 = GeForce GTX 1080 Ti, Device2 = GeForce GTX 1080 Ti, Device3 = GeForce GTX 1080 Ti</span><br><span class="line">Result = PASS</span><br></pre></td></tr></table></figure><blockquote><p>因为我是 4 个 GPU ,所以会有多个 Device 信息</p></blockquote><p>安装成功!</p></li></ul><h4 id="安装Intel-MKL,openBlas-或Atlas"><a href="#安装Intel-MKL,openBlas-或Atlas" class="headerlink" title="安装Intel MKL,openBlas 或Atlas"></a>安装Intel MKL,openBlas 或Atlas</h4><p>我选择的是 <code>Atlas</code> ,为 <code>caffe</code> 默认使用的,不要额外配置,安装命令</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">sudo apt-get install libatlas-base-dev</span><br></pre></td></tr></table></figure><h4 id="安装opencv"><a href="#安装opencv" class="headerlink" title="安装opencv"></a>安装opencv</h4><ul><li><p>首先安装必须的包</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev</span><br></pre></td></tr></table></figure></li><li><p>从 <code>opencv</code> 官网下载最新版本 <code>opencv</code> ,<code>3.2.0.zip</code></p><p>解压</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">unzip 3.2.0.zip</span><br></pre></td></tr></table></figure></li><li><p>编译</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">cd opencv-3.2.0</span><br><span class="line">mkdir release</span><br><span class="line">cd release</span><br><span class="line">cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local .. -DWITH_LAPACK=OFF</span><br><span class="line">make -j4</span><br><span class="line">sudo make install</span><br></pre></td></tr></table></figure></li><li><p>测试</p><p>因为我的 <code>GPU</code> 服务器走的别人的网关,这里显示不出来图片,也就没有测试。</p><p>但是是需要测试的,自行 <code>Google</code> 吧</p></li></ul><h4 id="安装python依赖库"><a href="#安装python依赖库" class="headerlink" title="安装python依赖库"></a>安装python依赖库</h4><ul><li><p>下载 <code>caffe</code> 源码,解压后进入 <code>caffe-master</code> 下的 <code>python</code> 目录</p><blockquote><p>这里一定要注意当前下载的 caffe 版本是否支持自己安装的 cuDNN 版本</p></blockquote></li><li><p>安装 <code>python-pip</code></p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">sudo apt-get install python-pip</span><br></pre></td></tr></table></figure></li><li><p>执行如下命令安装相关依赖</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">for req in $(cat requirements.txt); do pip install $req; done</span><br></pre></td></tr></table></figure></li></ul><h4 id="编译Caffe"><a href="#编译Caffe" class="headerlink" title="编译Caffe"></a>编译Caffe</h4><ul><li><p>进入 <code>caffe-master</code> 目录,复制一份 <code>Makefile.config.examples</code> </p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">cp Makefile.config.example Makefile.config</span><br></pre></td></tr></table></figure></li><li><p>修改 <code>Makefile.config</code></p><p>开启对 <code>CuDNN</code> 和 <code>Opencv3</code> 的支持</p><figure class="highlight makefile"><table><tr><td class="code"><pre><span class="line"><span class="comment">## Refer to http://caffe.berkeleyvision.org/installation.html</span></span><br><span class="line"><span class="comment"># Contributions simplifying and improving our build system are welcome!</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># cuDNN acceleration switch (uncomment to build with cuDNN).</span></span><br><span class="line">USE_CUDNN := 1</span><br><span class="line"></span><br><span class="line"><span class="comment"># CPU-only switch (uncomment to build without GPU support).</span></span><br><span class="line"><span class="comment"># CPU_ONLY := 1</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># uncomment to disable IO dependencies and corresponding data layers</span></span><br><span class="line"><span class="comment"># USE_OPENCV := 0</span></span><br><span class="line"><span class="comment"># USE_LEVELDB := 0</span></span><br><span class="line"><span class="comment"># USE_LMDB := 0</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)</span></span><br><span class="line"><span class="comment">#You should not set this flag if you will be reading LMDBs with any</span></span><br><span class="line"><span class="comment">#possibility of simultaneous read and write</span></span><br><span class="line"><span class="comment"># ALLOW_LMDB_NOLOCK := 1</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Uncomment if you're using OpenCV 3</span></span><br><span class="line">OPENCV_VERSION := 3</span><br><span class="line"></span><br><span class="line"><span class="comment"># To customize your choice of compiler, uncomment and set the following.</span></span><br><span class="line"><span class="comment"># N.B. the default for Linux is g++ and the default for OSX is clang++</span></span><br><span class="line"><span class="comment"># CUSTOM_CXX := g++</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># CUDA directory contains bin/ and lib/ directories that we need.</span></span><br><span class="line">CUDA_DIR := /usr/local/cuda</span><br><span class="line"><span class="comment"># On Ubuntu 14.04, if cuda tools are installed via</span></span><br><span class="line"><span class="comment"># "sudo apt-get install nvidia-cuda-toolkit" then use this instead:</span></span><br><span class="line"><span class="comment"># CUDA_DIR := /usr</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># CUDA architecture setting: going with all of them.</span></span><br><span class="line"><span class="comment"># For CUDA < 6.0, comment the *_50 lines for compatibility.</span></span><br><span class="line">CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \</span><br><span class="line">-gencode arch=compute_20,code=sm_21 \</span><br><span class="line">-gencode arch=compute_30,code=sm_30 \</span><br><span class="line">-gencode arch=compute_35,code=sm_35 \</span><br><span class="line">-gencode arch=compute_50,code=sm_50 \</span><br><span class="line">-gencode arch=compute_50,code=compute_50</span><br><span class="line"></span><br><span class="line"><span class="comment"># BLAS choice:</span></span><br><span class="line"><span class="comment"># atlas for ATLAS (default)</span></span><br><span class="line"><span class="comment"># mkl for MKL</span></span><br><span class="line"><span class="comment"># open for OpenBlas</span></span><br><span class="line">BLAS := atlas</span><br><span class="line"><span class="comment"># Custom (MKL/ATLAS/OpenBLAS) include and lib directories.</span></span><br><span class="line"><span class="comment"># Leave commented to accept the defaults for your choice of BLAS</span></span><br><span class="line"><span class="comment"># (which should work)!</span></span><br><span class="line"><span class="comment"># BLAS_INCLUDE := /path/to/your/blas</span></span><br><span class="line"><span class="comment"># BLAS_LIB := /path/to/your/blas</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Homebrew puts openblas in a directory that is not on the standard search path</span></span><br><span class="line"><span class="comment"># BLAS_INCLUDE := $(shell brew --prefix openblas)/include</span></span><br><span class="line"><span class="comment"># BLAS_LIB := $(shell brew --prefix openblas)/lib</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># This is required only if you will compile the matlab interface.</span></span><br><span class="line"><span class="comment"># MATLAB directory should contain the mex binary in /bin.</span></span><br><span class="line"><span class="comment"># MATLAB_DIR := /usr/local</span></span><br><span class="line"><span class="comment"># MATLAB_DIR := /Applications/MATLAB_R2012b.app</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># <span class="doctag">NOTE:</span> this is required only if you will compile the python interface.</span></span><br><span class="line"><span class="comment"># We need to be able to find Python.h and numpy/arrayobject.h.</span></span><br><span class="line">PYTHON_INCLUDE := /usr/<span class="keyword">include</span>/python2.7 \</span><br><span class="line">/usr/lib/python2.7/dist-packages/numpy/core/<span class="keyword">include</span></span><br><span class="line"><span class="comment"># Anaconda Python distribution is quite popular. Include path:</span></span><br><span class="line"><span class="comment"># Verify anaconda location, sometimes it's in root.</span></span><br><span class="line"><span class="comment"># ANACONDA_HOME := $(HOME)/anaconda</span></span><br><span class="line"><span class="comment"># PYTHON_INCLUDE := $(ANACONDA_HOME)/include \</span></span><br><span class="line"><span class="comment"># $(ANACONDA_HOME)/include/python2.7 \</span></span><br><span class="line"><span class="comment"># $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Uncomment to use Python 3 (default is Python 2)</span></span><br><span class="line"><span class="comment"># PYTHON_LIBRARIES := boost_python3 python3.5m</span></span><br><span class="line"><span class="comment"># PYTHON_INCLUDE := /usr/include/python3.5m \</span></span><br><span class="line"><span class="comment"># /usr/lib/python3.5/dist-packages/numpy/core/include</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># We need to be able to find libpythonX.X.so or .dylib.</span></span><br><span class="line">PYTHON_LIB := /usr/lib</span><br><span class="line"><span class="comment"># PYTHON_LIB := $(ANACONDA_HOME)/lib</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Homebrew installs numpy in a non standard path (keg only)</span></span><br><span class="line"><span class="comment"># PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include</span></span><br><span class="line"><span class="comment"># PYTHON_LIB += $(shell brew --prefix numpy)/lib</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Uncomment to support layers written in Python (will link against Python libs)</span></span><br><span class="line"><span class="comment"># WITH_PYTHON_LAYER := 1</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Whatever else you find you need goes here.</span></span><br><span class="line">INCLUDE_DIRS := <span class="variable">$(PYTHON_INCLUDE)</span> /usr/local/<span class="keyword">include</span></span><br><span class="line">LIBRARY_DIRS := <span class="variable">$(PYTHON_LIB)</span> /usr/local/lib /usr/lib</span><br><span class="line"></span><br><span class="line"><span class="comment"># If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies</span></span><br><span class="line"><span class="comment"># INCLUDE_DIRS += $(shell brew --prefix)/include</span></span><br><span class="line"><span class="comment"># LIBRARY_DIRS += $(shell brew --prefix)/lib</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Uncomment to use `pkg-config` to specify OpenCV library paths.</span></span><br><span class="line"><span class="comment"># (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)</span></span><br><span class="line"><span class="comment"># USE_PKG_CONFIG := 1</span></span><br><span class="line"></span><br><span class="line">BUILD_DIR := build</span><br><span class="line">DISTRIBUTE_DIR := distribute</span><br><span class="line"></span><br><span class="line"><span class="comment"># Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171</span></span><br><span class="line"><span class="comment"># DEBUG := 1</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># The ID of the GPU that 'make runtest' will use to run unit tests.</span></span><br><span class="line">TEST_GPUID := 0</span><br><span class="line"></span><br><span class="line"><span class="comment"># enable pretty build (comment to see full commands)</span></span><br><span class="line">Q ?= @</span><br></pre></td></tr></table></figure></li><li><p>保存退出,编译</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">make all -j4</span><br><span class="line">make test -j4</span><br><span class="line">make runtest -j4</span><br></pre></td></tr></table></figure></li><li><p>结果</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">[ FAILED ] 5 tests, listed below:</span><br><span class="line">[ FAILED ] CuDNNConvolutionLayerTest/0.TestSimpleConvolutionCuDNN, where TypeParam = float</span><br><span class="line">[ FAILED ] CuDNNConvolutionLayerTest/0.TestGradientCuDNN, where TypeParam = float</span><br><span class="line">[ FAILED ] CuDNNConvolutionLayerTest/0.TestGradientGroupCuDNN, where TypeParam = float</span><br><span class="line">[ FAILED ] CuDNNConvolutionLayerTest/0.TestSobelConvolutionCuDNN, where TypeParam = float</span><br><span class="line">[ FAILED ] CuDNNConvolutionLayerTest/0.TestSimpleConvolutionGroupCuDNN, where TypeParam = float</span><br></pre></td></tr></table></figure><p>这个是因为我们使用的是 <code>cuDNN v3</code> 版本,而这部分只在 <code>cuDNN v4</code> 下 <code>work</code></p></li></ul><h3 id="更换cuDNN与caffe版本"><a href="#更换cuDNN与caffe版本" class="headerlink" title="更换cuDNN与caffe版本"></a>更换cuDNN与caffe版本</h3><h4 id="为啥要换"><a href="#为啥要换" class="headerlink" title="为啥要换"></a>为啥要换</h4><p>我当然不想换!因为我老大不太满意!也没有说不满意,就是素质三连了一下</p><p>都行</p><p>随你</p><p>都可以</p><p>。。。</p><h4 id="确定依赖关系"><a href="#确定依赖关系" class="headerlink" title="确定依赖关系"></a>确定依赖关系</h4><ul><li><p><code>CuDNN</code> 是专门针对 <code>Deep Learning</code> 框架设计的一套 <code>GPU</code> 计算加速方案,目前支持的 <code>DL</code> 库包括 <code>Caffe</code> ,<code>ConvNet</code> ,<code>Torch7</code> 等</p><p>基本原理是把 <code>lib</code> 文件加入到系统能找到的 <code>lib</code> 文件夹里, 把头文件加到系统能找到的 <code>include</code> 文件夹里就可以。这里把他们加到 <code>CUDA</code> 的文件夹下</p></li><li><p><code>CUDA</code> 是直接安装的、<code>OpenCV</code> 安装的时候是依赖于 <code>CUDA</code> 的、<code>cuDNN</code> 的安装就是将其 <code>lib文件加入到系统能找到的lib文件夹里, 把头文件加到系统能找到的include文件夹里,这里把他们加到CUDA的文件夹下</code></p></li><li><p>所以说 <code>cuDNN</code> 无关于 <code>CUDA</code> ,无关于 <code>OpenCV</code> ,它只和 <code>caffe</code> 有关系,因为 <code>caffe</code> 安装的时候要依赖它。</p></li></ul><h4 id="重装过程"><a href="#重装过程" class="headerlink" title="重装过程"></a>重装过程</h4><ul><li><p><code>cuDNN</code> 文件结构</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">root@Jedy:/home/jedy/deeplearning/cuda# tree -N</span><br><span class="line">.</span><br><span class="line">├── include</span><br><span class="line">│ └── cudnn.h</span><br><span class="line">└── lib64</span><br><span class="line"> ├── libcudnn.so</span><br><span class="line"> ├── libcudnn.so.5</span><br><span class="line"> ├── libcudnn.so.5.0.5</span><br><span class="line"> └── libcudnn_static.a</span><br><span class="line"></span><br><span class="line">2 directories, 5 files</span><br></pre></td></tr></table></figure><p>而安装 <code>cuDNN</code> 的命令是</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">tar -zxvf cudnn-7.0-linux-x64-v3.0-prod.tgz </span><br><span class="line">cd cuda</span><br><span class="line">sudo cp lib64/* /usr/local/cuda/lib64/</span><br><span class="line">sudo cp include/cudnn.h /usr/local/cuda/include/</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash">更新软链接</span></span><br><span class="line">cd /usr/local/cuda/lib64</span><br><span class="line">sudo rm -rf libcudnn.so libcudnn.so.7.0</span><br><span class="line">sudo ln -s libcudnn.so.7.0.64 libcudnn.so.7.0</span><br><span class="line">sudo ln -s libcudnn.so.7.0 libcudnn.so</span><br></pre></td></tr></table></figure></li><li><p>重装 <code>cuDNN</code> </p><ul><li><p>因为 <code>cuDNN</code> 只是将文件拷贝进去,所以我们只需要下载更新版本的 <code>cuDNN</code> 然后覆盖安装即可。我是打算一步到位,使用最新的 <code>caffe</code> ,又怕 <code>cuDNN</code> 向下兼容不好,所以下载了 <code>v5</code> 版本,版本为 <code>cudnn-8.0-linux-x64-v5.0-ga.tgz</code></p></li><li><p>进入到 <code>/usr/local/cuda/lib64</code> 中,删除旧版本的 <code>cuDNN</code></p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">cd /usr/local/cuda/lib64</span><br><span class="line">sudo rm -rf libcudnn.so libcudnn.so.7.0 libcudnn.so.7.0.64</span><br></pre></td></tr></table></figure></li><li><p>解压新版本的 <code>cuDNN</code> 并拷贝</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">tar -zxvf cudnn-8.0-linux-x64-v5.0-ga.tgz</span><br><span class="line">cd cuda</span><br><span class="line">sudo cp lib64/* /usr/local/cuda/lib64/</span><br><span class="line">sudo cp include/cudnn.h /usr/local/cuda/include/</span><br></pre></td></tr></table></figure><blockquote><p>这里的 include/cudnn.h 我们并没有删除旧版本的,而是采用了覆盖安装的方式</p></blockquote></li><li><p>更新软链接</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">cd /usr/local/cuda/lib64</span><br><span class="line">sudo rm -rf libcudnn.so libcudnn.so.5</span><br><span class="line">sudo ln -s libcudnn.so.5.0.5 libcudnn.so.5</span><br><span class="line">sudo ln -s libcudnn.so.5 libcudnn.so</span><br></pre></td></tr></table></figure></li></ul></li><li><p>重装 <code>caffe</code></p><ul><li><p>在 <code>caffe</code> 的 <code>root</code> 目录执行</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">make clean</span><br></pre></td></tr></table></figure></li><li><p>删除旧版本的 <code>caffe</code> </p></li><li><p>下载新版本的 <code>caffe</code> ,我这里直接下载了 <code>1.0</code> 版本的 <code>caffe</code> </p></li><li><p>进入 <code>caffe-master</code> 目录,复制一份 <code>Makefile.config.examples</code> </p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">cp Makefile.config.example Makefile.config</span><br></pre></td></tr></table></figure></li><li><p>修改 <code>Makefile.config</code> ,开启 <code>CuDNN</code> 和 <code>Opencv3</code> 的支持即可,修改好的如下</p><figure class="highlight makefile"><table><tr><td class="code"><pre><span class="line"><span class="comment">## Refer to http://caffe.berkeleyvision.org/installation.html</span></span><br><span class="line"><span class="comment"># Contributions simplifying and improving our build system are welcome!</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># cuDNN acceleration switch (uncomment to build with cuDNN).</span></span><br><span class="line">USE_CUDNN := 1</span><br><span class="line"></span><br><span class="line"><span class="comment"># CPU-only switch (uncomment to build without GPU support).</span></span><br><span class="line"><span class="comment"># CPU_ONLY := 1</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># uncomment to disable IO dependencies and corresponding data layers</span></span><br><span class="line"><span class="comment"># USE_OPENCV := 0</span></span><br><span class="line"><span class="comment"># USE_LEVELDB := 0</span></span><br><span class="line"><span class="comment"># USE_LMDB := 0</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)</span></span><br><span class="line"><span class="comment">#You should not set this flag if you will be reading LMDBs with any</span></span><br><span class="line"><span class="comment">#possibility of simultaneous read and write</span></span><br><span class="line"><span class="comment"># ALLOW_LMDB_NOLOCK := 1</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Uncomment if you're using OpenCV 3</span></span><br><span class="line">OPENCV_VERSION := 3</span><br><span class="line"></span><br><span class="line"><span class="comment"># To customize your choice of compiler, uncomment and set the following.</span></span><br><span class="line"><span class="comment"># N.B. the default for Linux is g++ and the default for OSX is clang++</span></span><br><span class="line"><span class="comment"># CUSTOM_CXX := g++</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># CUDA directory contains bin/ and lib/ directories that we need.</span></span><br><span class="line">CUDA_DIR := /usr/local/cuda</span><br><span class="line"><span class="comment"># On Ubuntu 14.04, if cuda tools are installed via</span></span><br><span class="line"><span class="comment"># "sudo apt-get install nvidia-cuda-toolkit" then use this instead:</span></span><br><span class="line"><span class="comment"># CUDA_DIR := /usr</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># CUDA architecture setting: going with all of them.</span></span><br><span class="line"><span class="comment"># For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.</span></span><br><span class="line"><span class="comment"># For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.</span></span><br><span class="line">CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \</span><br><span class="line">-gencode arch=compute_20,code=sm_21 \</span><br><span class="line">-gencode arch=compute_30,code=sm_30 \</span><br><span class="line">-gencode arch=compute_35,code=sm_35 \</span><br><span class="line">-gencode arch=compute_50,code=sm_50 \</span><br><span class="line">-gencode arch=compute_52,code=sm_52 \</span><br><span class="line">-gencode arch=compute_60,code=sm_60 \</span><br><span class="line">-gencode arch=compute_61,code=sm_61 \</span><br><span class="line">-gencode arch=compute_61,code=compute_61</span><br><span class="line"></span><br><span class="line"><span class="comment"># BLAS choice:</span></span><br><span class="line"><span class="comment"># atlas for ATLAS (default)</span></span><br><span class="line"><span class="comment"># mkl for MKL</span></span><br><span class="line"><span class="comment"># open for OpenBlas</span></span><br><span class="line">BLAS := atlas</span><br><span class="line"><span class="comment"># Custom (MKL/ATLAS/OpenBLAS) include and lib directories.</span></span><br><span class="line"><span class="comment"># Leave commented to accept the defaults for your choice of BLAS</span></span><br><span class="line"><span class="comment"># (which should work)!</span></span><br><span class="line"><span class="comment"># BLAS_INCLUDE := /path/to/your/blas</span></span><br><span class="line"><span class="comment"># BLAS_LIB := /path/to/your/blas</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Homebrew puts openblas in a directory that is not on the standard search path</span></span><br><span class="line"><span class="comment"># BLAS_INCLUDE := $(shell brew --prefix openblas)/include</span></span><br><span class="line"><span class="comment"># BLAS_LIB := $(shell brew --prefix openblas)/lib</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># This is required only if you will compile the matlab interface.</span></span><br><span class="line"><span class="comment"># MATLAB directory should contain the mex binary in /bin.</span></span><br><span class="line"><span class="comment"># MATLAB_DIR := /usr/local</span></span><br><span class="line"><span class="comment"># MATLAB_DIR := /Applications/MATLAB_R2012b.app</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># <span class="doctag">NOTE:</span> this is required only if you will compile the python interface.</span></span><br><span class="line"><span class="comment"># We need to be able to find Python.h and numpy/arrayobject.h.</span></span><br><span class="line">PYTHON_INCLUDE := /usr/<span class="keyword">include</span>/python2.7 \</span><br><span class="line">/usr/lib/python2.7/dist-packages/numpy/core/<span class="keyword">include</span></span><br><span class="line"><span class="comment"># Anaconda Python distribution is quite popular. Include path:</span></span><br><span class="line"><span class="comment"># Verify anaconda location, sometimes it's in root.</span></span><br><span class="line"><span class="comment"># ANACONDA_HOME := $(HOME)/anaconda</span></span><br><span class="line"><span class="comment"># PYTHON_INCLUDE := $(ANACONDA_HOME)/include \</span></span><br><span class="line"><span class="comment"># $(ANACONDA_HOME)/include/python2.7 \</span></span><br><span class="line"><span class="comment"># $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Uncomment to use Python 3 (default is Python 2)</span></span><br><span class="line"><span class="comment"># PYTHON_LIBRARIES := boost_python3 python3.5m</span></span><br><span class="line"><span class="comment"># PYTHON_INCLUDE := /usr/include/python3.5m \</span></span><br><span class="line"><span class="comment"># /usr/lib/python3.5/dist-packages/numpy/core/include</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># We need to be able to find libpythonX.X.so or .dylib.</span></span><br><span class="line">PYTHON_LIB := /usr/lib</span><br><span class="line"><span class="comment"># PYTHON_LIB := $(ANACONDA_HOME)/lib</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Homebrew installs numpy in a non standard path (keg only)</span></span><br><span class="line"><span class="comment"># PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include</span></span><br><span class="line"><span class="comment"># PYTHON_LIB += $(shell brew --prefix numpy)/lib</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Uncomment to support layers written in Python (will link against Python libs)</span></span><br><span class="line"><span class="comment"># WITH_PYTHON_LAYER := 1</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Whatever else you find you need goes here.</span></span><br><span class="line">INCLUDE_DIRS := <span class="variable">$(PYTHON_INCLUDE)</span> /usr/local/<span class="keyword">include</span></span><br><span class="line">LIBRARY_DIRS := <span class="variable">$(PYTHON_LIB)</span> /usr/local/lib /usr/lib</span><br><span class="line"></span><br><span class="line"><span class="comment"># If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies</span></span><br><span class="line"><span class="comment"># INCLUDE_DIRS += $(shell brew --prefix)/include</span></span><br><span class="line"><span class="comment"># LIBRARY_DIRS += $(shell brew --prefix)/lib</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># NCCL acceleration switch (uncomment to build with NCCL)</span></span><br><span class="line"><span class="comment"># https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)</span></span><br><span class="line"><span class="comment"># USE_NCCL := 1</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Uncomment to use `pkg-config` to specify OpenCV library paths.</span></span><br><span class="line"><span class="comment"># (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)</span></span><br><span class="line"><span class="comment"># USE_PKG_CONFIG := 1</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># N.B. both build and distribute dirs are cleared on `make clean`</span></span><br><span class="line">BUILD_DIR := build</span><br><span class="line">DISTRIBUTE_DIR := distribute</span><br><span class="line"></span><br><span class="line"><span class="comment"># Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171</span></span><br><span class="line"><span class="comment"># DEBUG := 1</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># The ID of the GPU that 'make runtest' will use to run unit tests.</span></span><br><span class="line">TEST_GPUID := 0</span><br><span class="line"></span><br><span class="line"><span class="comment"># enable pretty build (comment to see full commands)</span></span><br><span class="line">Q ?= @</span><br></pre></td></tr></table></figure></li><li><p>保存退出,编译</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">make all -j4</span><br><span class="line">make test -j4</span><br><span class="line">make runtest -j4</span><br></pre></td></tr></table></figure></li><li><p>没有报错,成功</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">[----------] Global test environment tear-down</span><br><span class="line">[==========] 2101 tests from 277 test cases ran. (371248 ms total)</span><br><span class="line">[ PASSED ] 2101 tests.</span><br></pre></td></tr></table></figure></li></ul></li></ul><h4 id="修改后的组件版本"><a href="#修改后的组件版本" class="headerlink" title="修改后的组件版本"></a>修改后的组件版本</h4><ul><li><strong>Ubuntu</strong><ul><li>14.04</li></ul></li></ul><ul><li><strong>CUDA</strong><ul><li>8.0</li></ul></li><li><strong>cuDNN</strong><ul><li>cudnn-8.0-linux-x64-v5.0-ga.tgz</li></ul></li><li><strong>opencv</strong><ul><li>3.2</li></ul></li><li><strong>python</strong><ul><li>Python 2.7.6</li></ul></li><li><strong>caffe</strong><ul><li>1.0</li></ul></li></ul><h3 id="一点心得"><a href="#一点心得" class="headerlink" title="一点心得"></a>一点心得</h3><ul><li><p>make 编译的时候可以通过</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">make -j4</span><br></pre></td></tr></table></figure><p>指令指定多线程编译,可以很大程度加快编译速度。具体可以开多少看自己机器配置</p></li><li><p>看好OpenCV支持的CUDA版本</p></li><li><p>看好caffe支持的cuDNN版本</p></li><li><p>每个人硬件、环境的不同都会导致踩到不同的坑。这个就多 Google 吧!</p></li></ul><blockquote><p>部分参考 <a href="http://www.cnblogs.com/wm123/p/5385940.html" target="_blank" rel="noopener"><strong>Ubuntu 14.04上安装caffe</strong></a></p></blockquote>]]></content>
<summary type="html"><h3 id="组件-amp-版本"><a href="#组件-amp-版本" class="headerlink" title="组件&amp;版本"></a>组件&amp;版本</h3><ul>
<li><p><strong>Ubuntu</strong></p>
<ul>
</summary>
<category term="安装记录" scheme="https://www.holmeyoung.com/categories/安装记录/"/>
<category term="linux" scheme="https://www.holmeyoung.com/tags/linux/"/>
<category term="机器学习" scheme="https://www.holmeyoung.com/tags/机器学习/"/>
<category term="caffe" scheme="https://www.holmeyoung.com/tags/caffe/"/>
</entry>
<entry>
<title>git 使用小结</title>
<link href="https://www.holmeyoung.com/blog/git-summary/"/>
<id>https://www.holmeyoung.com/blog/git-summary/</id>
<published>2018-03-23T12:05:20.000Z</published>
<updated>2022-10-06T07:36:56.304Z</updated>
<content type="html"><![CDATA[<h2 id="新建-GitLab-仓库时官方给出的命令"><a href="#新建-GitLab-仓库时官方给出的命令" class="headerlink" title="新建 GitLab 仓库时官方给出的命令"></a>新建 GitLab 仓库时官方给出的命令</h2><h3 id="Git-global-setup"><a href="#Git-global-setup" class="headerlink" title="Git global setup"></a><strong>Git global setup</strong></h3><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git config --global user.name <span class="string">"YourName"</span></span><br><span class="line">git config --global user.email <span class="string">"YourEmail"</span></span><br></pre></td></tr></table></figure><h3 id="Create-a-new-repository"><a href="#Create-a-new-repository" class="headerlink" title="Create a new repository"></a>Create a new repository</h3><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git <span class="built_in">clone</span> https://gitlab.com/holmeyoung/num_recog.git</span><br><span class="line"><span class="built_in">cd</span> num_recog</span><br><span class="line">touch README.md</span><br><span class="line">git add README.md</span><br><span class="line">git commit -m <span class="string">"add README"</span></span><br><span class="line">git push -u origin master</span><br></pre></td></tr></table></figure><h3 id="Existing-folder"><a href="#Existing-folder" class="headerlink" title="Existing folder"></a><strong>Existing folder</strong></h3><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line"><span class="built_in">cd</span> existing_folder</span><br><span class="line">git init</span><br><span class="line">git remote add origin https://gitlab.com/holmeyoung/num_recog.git</span><br><span class="line">git add .</span><br><span class="line">git commit -m <span class="string">"Initial commit"</span></span><br><span class="line">git push -u origin master</span><br></pre></td></tr></table></figure><h3 id="Existing-Git-repository"><a href="#Existing-Git-repository" class="headerlink" title="Existing Git repository"></a><strong>Existing Git repository</strong></h3><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line"><span class="built_in">cd</span> existing_repo</span><br><span class="line">git remote rename origin old-origin</span><br><span class="line">git remote add origin https://gitlab.com/holmeyoung/num_recog.git</span><br><span class="line">git push -u origin --all</span><br><span class="line">git push -u origin --tags</span><br></pre></td></tr></table></figure><h2 id="新建-GitHab-仓库时官方给出的命令"><a href="#新建-GitHab-仓库时官方给出的命令" class="headerlink" title="新建 GitHab 仓库时官方给出的命令"></a>新建 GitHab 仓库时官方给出的命令</h2><h3 id="…or-create-a-new-repository-on-the-command-line"><a href="#…or-create-a-new-repository-on-the-command-line" class="headerlink" title="…or create a new repository on the command line"></a>…or create a new repository on the command line</h3><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line"><span class="built_in">echo</span> <span class="string">"# tmp"</span> >> README.md</span><br><span class="line">git init</span><br><span class="line">git add README.md</span><br><span class="line">git commit -m <span class="string">"first commit"</span></span><br><span class="line">git remote add origin git@github.com:Holmeyoung/tmp.git</span><br><span class="line">git push -u origin master</span><br></pre></td></tr></table></figure><h3 id="…or-push-an-existing-repository-from-the-command-line"><a href="#…or-push-an-existing-repository-from-the-command-line" class="headerlink" title="…or push an existing repository from the command line"></a>…or push an existing repository from the command line</h3><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git remote add origin git@github.com:Holmeyoung/tmp.git</span><br><span class="line">git push -u origin master</span><br></pre></td></tr></table></figure><h3 id="…or-import-code-from-another-repository"><a href="#…or-import-code-from-another-repository" class="headerlink" title="…or import code from another repository"></a>…or import code from another repository</h3><p>You can initialize this repository with code from a Subversion, Mercurial, or TFS project.</p><h2 id="Git-免密码"><a href="#Git-免密码" class="headerlink" title="Git 免密码"></a>Git 免密码</h2><h3 id="Git-HTTPS-方式传输文件免密码"><a href="#Git-HTTPS-方式传输文件免密码" class="headerlink" title="Git HTTPS 方式传输文件免密码"></a><strong>Git <code>HTTPS</code> 方式传输文件免密码</strong></h3><h4 id="cache"><a href="#cache" class="headerlink" title="cache"></a><strong>cache</strong></h4><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git config --global credential.helper cache</span><br></pre></td></tr></table></figure><blockquote><p>或直接修改 <strong><code>~/.gitconfig</code></strong></p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">> [credential]</span><br><span class="line">> helper = cache --timeout=3600</span><br><span class="line">></span><br></pre></td></tr></table></figure></blockquote><blockquote><p>采用 <code>cache</code> 形式,密码会临时保存在 <code>~/git-credential-cache</code> 文件夹下</p></blockquote><h4 id="store"><a href="#store" class="headerlink" title="store"></a><strong>store</strong></h4><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git config --global credential.helper store</span><br></pre></td></tr></table></figure><blockquote><p>或直接修改 <strong><code>~/.gitconfig</code></strong></p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">> [credential]</span><br><span class="line">> helper = store</span><br><span class="line">></span><br></pre></td></tr></table></figure></blockquote><blockquote><p>采用 <code>store</code> 形式,密码会永久保存在 <code>~/.git-credentials</code> 文件中</p></blockquote><h3 id="Git-SSH-方式传输文件免密码"><a href="#Git-SSH-方式传输文件免密码" class="headerlink" title="Git SSH 方式传输文件免密码"></a>Git <code>SSH</code> 方式传输文件免密码</h3><p><strong>配置密钥即可</strong></p><h2 id="分支管理"><a href="#分支管理" class="headerlink" title="分支管理"></a>分支管理</h2><h3 id="远程服务器(远程仓库)"><a href="#远程服务器(远程仓库)" class="headerlink" title="远程服务器(远程仓库)"></a>远程服务器(远程仓库)</h3><h4 id="远程服务器(远程仓库)是什么"><a href="#远程服务器(远程仓库)是什么" class="headerlink" title="远程服务器(远程仓库)是什么"></a>远程服务器(远程仓库)是什么</h4><p>有命令<br><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git push origin master:master</span><br></pre></td></tr></table></figure></p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git pull origin master:master</span><br></pre></td></tr></table></figure><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git fetch origin</span><br></pre></td></tr></table></figure><p><strong>这里的 <code>origin</code> 究竟是什么</strong></p><p>有命令<br><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git remote add origin git@code.ziroom.com:shuly/wiki.git</span><br></pre></td></tr></table></figure></p><blockquote><p>所以 </p><p><code>origin --> git@code.ziroom.com:shuly/wiki.git</code></p><p><code>origin</code> 即为指向远程服务器 <a href="mailto:`git@code.ziroom.com" target="_blank" rel="noopener">`git@code.ziroom.com</a>:shuly/wiki.git` 的远程服务器名</p></blockquote><h4 id="多个远程服务器"><a href="#多个远程服务器" class="headerlink" title="多个远程服务器"></a>多个远程服务器</h4><p>假设还有另一个服务器 <a href="mailto:`git@github.com" target="_blank" rel="noopener">`git@github.com</a><code>。可以用第二章中提到的</code>git remote add<code>命令把它加为当前项目的远程分支之一。我们把它命名为</code>origin_dev` ,以便代替完整的 Git URL 以方便使用。</p><p>执行命令<br><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git remote add origin_dev git@github.com:Holmeyoung/wiki.git</span><br></pre></td></tr></table></figure></p><p>现在你可以用 <code>git fetch origin_dev</code> 来获取另一台服务器上你还没有的数据了。执行该命令会创建一个名为 <code>origin_dev/master</code> 的远程分支,指向 <code>origin_dev</code> 服务器上 <code>master</code> 分支所在的提交对象</p><h3 id="远程分支"><a href="#远程分支" class="headerlink" title="远程分支"></a>远程分支</h3><h4 id="删除远程分支"><a href="#删除远程分支" class="headerlink" title="删除远程分支"></a>删除远程分支</h4><p>如果不再需要某个远程分支了,比如搞定了某个特性并把它合并进了远程的 <code>master</code> 分支(或任何其他存放稳定代码的分支),可以用这个非常无厘头的语法来删除它:<code>git push [远程名] :[分支名]</code> 。如果想在服务器上删除 develop 分支,运行下面的命令:<br><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git push origin :develop</span><br></pre></td></tr></table></figure></p><h3 id="本地分支"><a href="#本地分支" class="headerlink" title="本地分支"></a>本地分支</h3><ul><li><p>创建一个叫做 <code>feature_x</code> 的分支,并切换过去:</p> <figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git checkout -b feature_x</span><br></pre></td></tr></table></figure></li><li><p>切换回主分支:</p> <figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git checkout master</span><br></pre></td></tr></table></figure></li><li><p>再把新建的分支删掉:</p> <figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git branch -d feature_x</span><br></pre></td></tr></table></figure></li><li><p>除非你将分支推送到远端仓库,不然该分支就是 不为他人所见的:</p> <figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git push origin <branch></span><br></pre></td></tr></table></figure></li></ul><h2 id="多人协同完整流程"><a href="#多人协同完整流程" class="headerlink" title="多人协同完整流程"></a>多人协同完整流程</h2><ul><li>GitLab 新建远程分支 <code>develop</code></li></ul><blockquote><p>这一步的意义在于防止直接操作 <code>master</code> 分支造成无法挽回的后果</p></blockquote><ul><li><p>下载新的远程分支</p> <figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git fetch origin</span><br></pre></td></tr></table></figure><blockquote><p>值得注意的是,在 <code>fetch</code> 操作下载好新的远程分支之后,你仍然无法在本地编辑该远程仓库中的分支。换句话说,在本例中,你不会有一个新的 <code>develop</code> 分支,有的只是一个你无法移动的 <code>origin/develop</code> 指针</p></blockquote></li><li><p>操作下载的远程分支</p><ul><li><p>如果要把该远程分支的内容合并到当前分支,可以运行</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git merge origin/develop</span><br></pre></td></tr></table></figure></li><li><p>如果想要一份自己的 serverfix 来开发,可以在远程分支的基础上分化出一个新的分支来</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git checkout -b develop origin/develop</span><br></pre></td></tr></table></figure><p>这会切换到新建的 <code>develop</code> 本地分支,其内容同远程分支 <code>origin/develop</code> 一致,这样你就可以在里面继续开发了。</p></li></ul><blockquote><p>推荐</p></blockquote></li><li><p>新建本地用户分支并开发</p> <figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git checkout -b holmeyoung</span><br></pre></td></tr></table></figure><p> 在 <code>holmeyoung</code> 分支开发完毕后</p><ul><li><p>提交到缓存区</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git add --all</span><br></pre></td></tr></table></figure></li><li><p>提交到 HEAD</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git commit -m <span class="string">"holmeyoung change"</span></span><br></pre></td></tr></table></figure></li></ul></li><li><p>合并改动到 <code>develop</code> 分支</p><ul><li><p>跳到 <code>develop</code> 分支</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git checkout develop</span><br></pre></td></tr></table></figure></li><li><p>将 <code>holmeyoung</code> 分支的改动 merge 到 <code>develop</code> 分支</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git merge holmeyoung</span><br></pre></td></tr></table></figure></li><li><p>推送本地 <code>develop</code> 分支到远程 <code>develop</code> 分支</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git push origin develop:develop</span><br></pre></td></tr></table></figure></li></ul></li><li><p>合并改动到 <code>master</code> 分支</p><ul><li><p>跳到 <code>master</code> 分支</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git checkout master</span><br></pre></td></tr></table></figure></li><li><p>将 <code>develop</code> 分支的改动 merge 到 <code>master</code> 分支</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git merge develop</span><br></pre></td></tr></table></figure></li><li><p>推送本地 <code>master</code> 分支到远程 <code>master</code> 分支</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line">git push origin master:master</span><br></pre></td></tr></table></figure></li></ul></li></ul><h2 id="REF"><a href="#REF" class="headerlink" title="REF"></a><code>REF</code></h2><blockquote><p><a href="http://www.bootcss.com/p/git-guide/" target="_blank" rel="noopener">git - 简易指南</a></p><p><a href="http://www.ruanyifeng.com/blog/2014/06/git_remote.html" target="_blank" rel="noopener">Git远程操作详解</a></p><p><a href="https://git-scm.com/book/zh/v2" target="_blank" rel="noopener">Git Book</a></p></blockquote>]]></content>
<summary type="html"><h2 id="新建-GitLab-仓库时官方给出的命令"><a href="#新建-GitLab-仓库时官方给出的命令" class="headerlink" title="新建 GitLab 仓库时官方给出的命令"></a>新建 GitLab 仓库时官方给出的命令</h2><</summary>
<category term="技术总结" scheme="https://www.holmeyoung.com/categories/技术总结/"/>
<category term="git" scheme="https://www.holmeyoung.com/tags/git/"/>
</entry>
<entry>
<title>anaconda 安装记录</title>
<link href="https://www.holmeyoung.com/blog/anaconda-linux/"/>
<id>https://www.holmeyoung.com/blog/anaconda-linux/</id>
<published>2018-03-08T06:37:15.000Z</published>
<updated>2022-10-06T07:36:56.304Z</updated>
<content type="html"><![CDATA[<h3 id="Anaconda-是什么?"><a href="#Anaconda-是什么?" class="headerlink" title="Anaconda 是什么?"></a>Anaconda 是什么?</h3><p>Anaconda 是一个可用于科学计算的 Python 发行版,支持 Linux、Mac、Windows系统,内置了常用的科学计算包。它解决了官方 Python 的两大痛点。</p><ul><li>第一:提供了包管理功能,Windows 平台安装第三方包经常失败的场景得以解决</li><li>第二:提供环境管理的功能,功能类似 Virtualenv,解决了多版本Python并存、切换的问题</li></ul><h3 id="下载-Anaconda"><a href="#下载-Anaconda" class="headerlink" title="下载 Anaconda"></a>下载 Anaconda</h3><p>直接在<a href="https://www.anaconda.com/download/#macos" target="_blank" rel="noopener">官网下载</a>安装包,我是下载的 <code>2.7</code> 版本。下载后直接安装并选择默认配置就好。</p><p>安装过程会提示安装 <code>visual studio code</code> 选择安装,如果说为什么的话</p><blockquote><p>比sublime开源、比atom更快、比webstorm更轻</p></blockquote><h3 id="环境变量配置"><a href="#环境变量配置" class="headerlink" title="环境变量配置"></a>环境变量配置</h3><h4 id="如何配置"><a href="#如何配置" class="headerlink" title="如何配置"></a>如何配置</h4><p>刚下载下来在 <code>iterm2</code> 中输入 <code>conda</code> 会显示 <code>zsh command not found</code></p><p>因为是我用的是 <code>iterm2</code> 且配置了 <code>oh my zsh</code> ,错误显示的又是 <code>zsh</code> 所以我们需要在 <code>~/.zsh</code> 即 <code>oh my zsh</code> 的配置文件中添加 <strong>anaconda</strong> 的安装路径。</p><p>即添加</p><figure class="highlight sh"><table><tr><td class="code"><pre><span class="line"><span class="built_in">export</span> PATH=<span class="string">"/anaconda2/bin:<span class="variable">$PATH</span>"</span></span><br></pre></td></tr></table></figure><blockquote><p>需要注意自己用户目录下的是 <code>anaconda2</code> 还是 <code>anaconda</code> </p></blockquote><h4 id="检查配置"><a href="#检查配置" class="headerlink" title="检查配置"></a>检查配置</h4><p>输入 <code>which conda</code> ,返回具体的路径即为成功!</p><h3 id="conda-命令介绍"><a href="#conda-命令介绍" class="headerlink" title="conda 命令介绍"></a>conda 命令介绍</h3><h4 id="关于新建Python"><a href="#关于新建Python" class="headerlink" title="关于新建Python"></a>关于新建Python</h4><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 查看帮助</span></span><br><span class="line">conda -h</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 基于python3.6版本创建一个名字为python36的环境</span></span><br><span class="line">conda create --name python36 python=3.6</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 激活此环境 linux/mac</span></span><br><span class="line">source activate python36 </span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 再来检查python版本,显示是 3.6</span></span><br><span class="line">python -V</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 退出当前环境到系统根目录</span></span><br><span class="line">source deactivate</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 删除该环境</span></span><br><span class="line">conda remove -n python36 --all</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 查看所有安装的环境</span></span><br><span class="line">conda info -e</span><br><span class="line"></span><br><span class="line">➜ ~ conda info -e</span><br><span class="line"><span class="meta">#</span><span class="bash"> conda environments:</span></span><br><span class="line"><span class="meta">#</span></span><br><span class="line">base * /Users/holmeyoung/anaconda2</span><br><span class="line">python36 /Users/holmeyoung/anaconda2/envs/python36</span><br></pre></td></tr></table></figure><h4 id="关于conda-的包管理"><a href="#关于conda-的包管理" class="headerlink" title="关于conda 的包管理"></a>关于conda 的包管理</h4><p>和 <code>pip</code> 是一样的,当然你选择 <code>pip</code> 来安装包也是没问题的</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 安装 matplotlib </span></span><br><span class="line">conda install matplotlib</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 查看已安装的包</span></span><br><span class="line">conda list</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 包更新</span></span><br><span class="line">conda update matplotlib</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 删除包</span></span><br><span class="line">conda remove matplotlib</span><br></pre></td></tr></table></figure><blockquote><p>在 conda 中 <strong>anything is a package</strong>。conda 本身可以看作是一个包,python 环境可以看作是一个包,anaconda 也可以看作是一个包,因此除了普通的第三方包支持更新之外……</p></blockquote><h4 id="conda的自我更新"><a href="#conda的自我更新" class="headerlink" title="conda的自我更新"></a>conda的自我更新</h4><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 更新conda本身</span></span><br><span class="line">conda update conda</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 更新anaconda 应用</span></span><br><span class="line">conda update anaconda</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 更新python,假设当前python环境是3.6.1,而最新版本是3.6.2,那么就会升级到3.6.2</span></span><br><span class="line">conda update python</span><br></pre></td></tr></table></figure><h4 id="anaconda卸载"><a href="#anaconda卸载" class="headerlink" title="anaconda卸载"></a>anaconda卸载</h4><p>由于Anaconda的安装文件都包含在一个目录中,所以直接将该目录删除即可</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">rm -rf anaconda2</span><br></pre></td></tr></table></figure><blockquote><p>注意清理 <code>.zshrc</code> 以及 <code>~/.bash_profile</code> 中的Anaconda路径</p></blockquote><h3 id="部分参考"><a href="#部分参考" class="headerlink" title="部分参考"></a>部分参考</h3><p><a href="https://foofish.net/anaconda-install.html" target="_blank" rel="noopener">Anaconda 入门安装教程</a></p><p><a href="http://www.cnblogs.com/caiyutong/p/7002764.html" target="_blank" rel="noopener">Mac下安装Anaconda和环境变量设置,以及升级和卸载</a></p>]]></content>
<summary type="html"><h3 id="Anaconda-是什么?"><a href="#Anaconda-是什么?" class="headerlink" title="Anaconda 是什么?"></a>Anaconda 是什么?</h3><p>Anaconda 是一个可用于科学计算的 Pytho</summary>
<category term="安装记录" scheme="https://www.holmeyoung.com/categories/安装记录/"/>
<category term="python" scheme="https://www.holmeyoung.com/tags/python/"/>
<category term="linux" scheme="https://www.holmeyoung.com/tags/linux/"/>
</entry>
<entry>
<title>实现 ssh 免密码登录服务器</title>
<link href="https://www.holmeyoung.com/blog/ssh-no-password/"/>
<id>https://www.holmeyoung.com/blog/ssh-no-password/</id>
<published>2018-01-05T12:13:52.000Z</published>
<updated>2022-10-06T07:36:56.304Z</updated>
<content type="html"><![CDATA[<h3 id="修改-ssh-config权限"><a href="#修改-ssh-config权限" class="headerlink" title="修改 ~/.ssh/config权限"></a>修改 <code>~/.ssh/config</code>权限</h3><p><code>~/.ssh/config</code>是 ssh 自己的配置文件,在修改文件之前一定要修改文件的权限以及其所属于的用户,否则会出现问题。</p><p>执行</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">chmod 600 ~/.ssh/config</span><br></pre></td></tr></table></figure><p>否则可能出现</p><blockquote><p><strong>Bad owner or permissions on /Users/mac/.ssh/config</strong></p></blockquote><p>执行</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">chown $USER ~/.ssh/config</span><br></pre></td></tr></table></figure><p>否则可能出现</p><blockquote><p><strong>ssh: Could not resolve hostname centos: nodename nor servname provided, or not known</strong></p></blockquote><p>确定 <strong>USER</strong> 的方法是执行 </p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">whoami</span><br></pre></td></tr></table></figure><p> 如我的结果是 <code>mac</code> 即执行</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">chown mac ~/.ssh/config</span><br></pre></td></tr></table></figure><h3 id="修改-ssh-config"><a href="#修改-ssh-config" class="headerlink" title="修改 ~/.ssh/config"></a>修改 <code>~/.ssh/config</code></h3><p>执行</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">vim ~/.ssh/config</span><br></pre></td></tr></table></figure><p>将下面内容添加进去</p><figure class="highlight powershell"><table><tr><td class="code"><pre><span class="line">Host 起个名字</span><br><span class="line"> HostName 你的服务器IP</span><br><span class="line"> Port ssh端口</span><br><span class="line"> User ssh用户</span><br><span class="line"> IdentityFile 私钥文件路径(~/.ssh/id_rsa)</span><br></pre></td></tr></table></figure><p>保存退出</p><h3 id="设置免密码登录"><a href="#设置免密码登录" class="headerlink" title="设置免密码登录"></a>设置免密码登录</h3><h4 id="本地生成公钥和私钥文件"><a href="#本地生成公钥和私钥文件" class="headerlink" title="本地生成公钥和私钥文件"></a>本地生成公钥和私钥文件</h4><p>在 Mac OSX 终端(或 iTerm 2 等)中进入 <code>~/.ssh</code> 目录,输入</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">ssh-keygen -t rsa</span><br></pre></td></tr></table></figure><p>会问一些问题,一路回车就好啦。这样就会在 <code>~/.ssh</code> 目录中生成 <code>id_rsa</code>(私钥) 和 <code>id_rsa.pub</code>(公钥)文件</p><h4 id="服务器端配置"><a href="#服务器端配置" class="headerlink" title="服务器端配置"></a>服务器端配置</h4><p>进入服务器端 <code>~/.ssh</code> 目录,执行</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">vim authorized_keys</span><br></pre></td></tr></table></figure><p>没有的话新建就好了</p><p>打开Mac端 <code>~/.ssh</code> 目录中生成的 <code>id_rsa.pub</code> 文件,将其中的内容复制到服务器端的 <code>authorized_keys</code> 文件中</p><p>保存退出即可</p><blockquote><p>要是有其他用户已经新建了这个文件并且写入了内容,只需要在文件最后追加即可</p></blockquote><h4 id="修改文件权限"><a href="#修改文件权限" class="headerlink" title="修改文件权限"></a>修改文件权限</h4><p>确保下文件权限正常,在服务器端执行</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">chmod 700 ~/.ssh/</span><br><span class="line">chmod 600 ~/.ssh/authorized_keys</span><br></pre></td></tr></table></figure><p>如果无法连接,请在服务器的 <code>/etc/ssh/sshd_config</code> 文件中查看 <code>PubkeyAuthentication</code> 的值是否为 <strong>yes</strong> ,如果不是,请修改为 <strong>yes</strong> ,并使用以下命令重启 ssh 服务</p><figure class="highlight powershell"><table><tr><td class="code"><pre><span class="line">/etc/init.d/ssh restart</span><br></pre></td></tr></table></figure><p>如果需要禁止密码登录,同样可以编辑 <code>/etc/ssh/sshd_config</code> 文件中 <code>PasswordAuthentication</code> 的值为 <strong>no</strong> 并重启 ssh 服务</p><h3 id="最终效果"><a href="#最终效果" class="headerlink" title="最终效果"></a>最终效果</h3><p>例如你在 <code>~/.ssh/config</code> 中写入的是</p><figure class="highlight powershell"><table><tr><td class="code"><pre><span class="line">Host centos</span><br><span class="line"> HostName <span class="number">8.8</span>.<span class="number">8.8</span></span><br><span class="line"> Port <span class="number">22</span></span><br><span class="line"> User root</span><br><span class="line"> IdentityFile ~/.ssh/id_rsa</span><br></pre></td></tr></table></figure><p>那么在终端或者 iterm 中输入</p><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">ssh centos</span><br></pre></td></tr></table></figure><p>即可直接登录服务器啦</p>]]></content>
<summary type="html"><h3 id="修改-ssh-config权限"><a href="#修改-ssh-config权限" class="headerlink" title="修改 ~/.ssh/config权限"></a>修改 <code>~/.ssh/config</code>权限</h3><p</summary>
<category term="技术总结" scheme="https://www.holmeyoung.com/categories/技术总结/"/>
<category term="linux" scheme="https://www.holmeyoung.com/tags/linux/"/>
<category term="ssh" scheme="https://www.holmeyoung.com/tags/ssh/"/>
</entry>
</feed>