-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatom.xml
More file actions
611 lines (556 loc) · 27.4 KB
/
atom.xml
File metadata and controls
611 lines (556 loc) · 27.4 KB
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
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<id>https://lvoooo.github.io</id>
<title>lvoooo's memory</title>
<updated>2019-10-28T07:05:33.807Z</updated>
<generator>https://github.com/jpmonette/feed</generator>
<link rel="alternate" href="https://lvoooo.github.io"/>
<link rel="self" href="https://lvoooo.github.io/atom.xml"/>
<subtitle>治疗失忆。</subtitle>
<logo>https://lvoooo.github.io/images/avatar.png</logo>
<icon>https://lvoooo.github.io/favicon.ico</icon>
<rights>All rights reserved 2019, lvoooo's memory</rights>
<entry>
<title type="html"><![CDATA[ubuntu]]></title>
<id>https://lvoooo.github.io/post/ubuntu</id>
<link href="https://lvoooo.github.io/post/ubuntu">
</link>
<updated>2019-10-24T07:34:52.000Z</updated>
<content type="html"><![CDATA[<h3 id="刷新地址">刷新地址</h3>
<p>1、释放Ip<br>
#dhclient -r<br>
2、重新获取ip<br>
#dhclient<br>
3、停止网卡服务<br>
#ifdown eth0<br>
4、启动网卡服务<br>
#ifup eth0<br>
5、更新网卡<br>
#/etc/init.d/network restart</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Mac]]></title>
<id>https://lvoooo.github.io/post/mac</id>
<link href="https://lvoooo.github.io/post/mac">
</link>
<updated>2019-10-17T08:11:48.000Z</updated>
<content type="html"><![CDATA[<h3 id="mac-os制作ubuntu安装u盘">Mac OS制作Ubuntu安装U盘</h3>
<h4 id="镜像下载">镜像下载</h4>
<p>https://mirrors.tuna.tsinghua.edu.cn/ubuntu-releases/</p>
<h4 id="工具版">工具版</h4>
<ol>
<li>确保你的U盘至少有4G空间</li>
<li>获取Ubuntu ISO映像文件</li>
<li>应用->其它->磁盘工具</li>
<li>选择U盘,然后擦除。千万别选错了Mac的硬盘啊!!!</li>
<li>选在格式: MS-DOS (FAT)</li>
<li>点击“擦除”</li>
<li>下载、安装、打开 Etcher</li>
<li>选择Ubuntu镜像文件</li>
<li>选择U盘</li>
<li>点击“Flash”刻录</li>
</ol>
<h4 id="命令行版本">命令行版本</h4>
<pre><code class="language-shell">## 转换格式
hdiutil convert -format UDRW -o ubuntu.iso ubuntu-18.04.3-live-server-amd64.iso
# -format为生成文件的权限,UDRW :表示转换成有read/write的权限的镜像。
## 列出当前存储
diskutil list
## 卸载
diskutil unmountDisk u盘
## 写入镜像
mv ubuntu.iso.dmg ubuntu.iso
sudo dd if=./ubuntu.iso of=U盘 bs=1m
# root 命令
# if:输入的文件名
# of:输出的文件名
# bs:是块大小,这里使用1m的块大小。
## 推出
sudo eject u盘
## 清除
sudo dd if=/dev/urandom of=/dev/rdisk2
</code></pre>
<h4 id="多分区">多分区</h4>
<p>参考 https://tommy.net.cn/2016/07/20/create-a-bootable-ubuntu-usb-stick-on-mac-os-x/</p>
<p><img src="https://tva1.sinaimg.cn/large/006y8mN6ly1g81ac9bxmvj31di0u0gr8.jpg" alt=""><br>
<img src="https://tva1.sinaimg.cn/large/006y8mN6ly1g81acgne2rj31di0u0dkp.jpg" alt=""><br>
<img src="https://tva1.sinaimg.cn/large/006y8mN6ly1g81acsrfvmj30zc0rgwim.jpg" alt=""><br>
<img src="https://tva1.sinaimg.cn/large/006y8mN6ly1g81acy4vfbj30zc0rgtc9.jpg" alt=""><br>
<img src="https://tva1.sinaimg.cn/large/006y8mN6ly1g81ad31ifhj30zc0rg0vg.jpg" alt=""></p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Docker]]></title>
<id>https://lvoooo.github.io/post/dockerfile</id>
<link href="https://lvoooo.github.io/post/dockerfile">
</link>
<updated>2019-09-25T11:32:28.000Z</updated>
<content type="html"><![CDATA[<h3 id="安装">安装</h3>
<h4 id="镜像加速器">镜像加速器</h4>
<pre><code class="language-shell">sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://0yo2rx5y.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
</code></pre>
<h4 id="镜像">镜像</h4>
<pre><code class="language-shell">## 导出
docker images
docker save 9045 > enigma_core.tar
[root@wxtest1607 lixr]# ls -lh
总用量 1.2G
-rw-r--r-- 1 root root 1005M 8月 24 17:42 tomcat8-apr.tar
## 导入
docker load < enigma_core.tar
</code></pre>
<h4 id="copy">COPY</h4>
<p>https://www.cnblogs.com/sparkdev/p/9573248.html</p>
<pre><code class="language-dockerfile">WORKDIR /app
COPY nickdir ./nickdir
</code></pre>
<h4 id="更换crates源">更换Crates源</h4>
<p>https://www.linuxidc.com/Linux/2019-05/158485.htm<br>
https://www.debugmyself.com/p/2019/8/8/rust/</p>
<pre><code class="language-shell">vim config
### 中科大
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
# 如果不可以使用 git
registry = "https://mirrors.ustc.edu.cn/crates.io-index"
### 阿里云
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = "rustcc"
[source.rustcc]
registry = "https://code.aliyun.com/rustcc/crates.io-index.git"
</code></pre>
<p>之后,在build的过程中 把 config 文件拷贝进去即可。</p>
<h4 id="更换镜像-sourcelist">更换镜像 source.list</h4>
<h5 id="ubuntu">ubuntu</h5>
<pre><code class="language-text"># 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multivers
</code></pre>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Golang]]></title>
<id>https://lvoooo.github.io/post/go-fen-ye</id>
<link href="https://lvoooo.github.io/post/go-fen-ye">
</link>
<updated>2019-08-29T07:37:03.000Z</updated>
<content type="html"><![CDATA[<h2 id="同源策略">同源策略</h2>
<h3 id="跨域资源请求">跨域资源请求</h3>
<pre><code>var upgrader = websocket.Upgrader{
// 解决跨域问题
CheckOrigin: func(r *http.Request) bool {
return true
},
}
</code></pre>
<h2 id="分页">分页</h2>
<h3 id="方法">方法</h3>
<p>https://www.v2ex.com/t/595976</p>
<p>增加有效可利用的索引,其目的是减少每次查询时的系统负载。</p>
<ol start="0">
<li>用固定页码做索引: 前提条件是页码总数只增不减少, pageTotal%pageSize 例如第 1-100 条数据的索引就是 index_page_1,以此类推.</li>
<li>每次携带最大的主键 id,使其查询时带上 id :例如: where id>{maxId} limit 10</li>
<li>优化:根据现有业务按列分表,将用于排序的列数做最小拆分,尽量不要有大规模字符串,查询后用 in(ids)方式聚合</li>
<li>增加一个扩展表,用于分页: pagination(id,page_number) 原理同第 0 条</li>
</ol>
<h3 id="go-语言分页">Go 语言分页</h3>
<ol>
<li>https://github.com/ikaiguang/go-pagination</li>
</ol>
<pre><code>go get -v github.com/ikaiguang/go-pagination
go get -v github.com/ikaiguang/go-pagination-example
go test -v $GOPATH/src/github.com/ikaiguang/go-pagination-example
</code></pre>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Go database/sql的连接池]]></title>
<id>https://lvoooo.github.io/post/go-databasesql-de-lian-jie-chi</id>
<link href="https://lvoooo.github.io/post/go-databasesql-de-lian-jie-chi">
</link>
<updated>2019-08-29T07:04:38.000Z</updated>
<content type="html"><![CDATA[<h3 id="步骤">步骤</h3>
<pre><code>1. 注册驱动
2. 初始化DB
3. 获取连接
4. 释放连接
sql.go(Query()) -> sql.go(QueryContext()) -> sql.go(query()) -> sql.go(conn())
conn()
如果连接池中有空闲的连接且没有过期的就直接拿出来用;
如果当前实际连接数已经超过最大连接数即上面case中提到的maxOpenConns,则将任务添加到任务队列中等待;
以上情况都不满足,则自行创建一个新的连接用于执行DB操作。
</code></pre>
<figure data-type="image" tabindex="1"><img src="https://tva1.sinaimg.cn/large/006y8mN6ly1g6gk9qhhkmj30xm0oj41b.jpg" alt="database/sql"></figure>
<h3 id="案例">案例</h3>
<pre><code>package main
import (
db "database/sql"
"fmt"
//_ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/go-sql-driver/mysql" //驱动注册
)
// 最大连接数为10,两个查询可以分别创建两个连接执行
func fewConns(){
db, _ := db.Open("mysql", "root:123456@tcp(127.0.0.1:3306)/giligili?charset=utf8&parseTime=True&loc=Local")
db.SetMaxOpenConns(10)
rows, err := db.Query("select * from videos where title = 'ed' limit 10")
if err != nil {
fmt.Println(err.Error())
fmt.Println("query error")
}
fmt.Println("-----------------------------------------")
row, _ := db.Query("select * from videos")
fmt.Println(row, rows)
}
// 只有一个连接,被占用后没有被释放,会导致阻塞
func oneConn() {
db, _ := db.Open("mysql", "root:123456@tcp(127.0.0.1:3306)/giligili?charset=utf8&parseTime=True&loc=Local")
db.SetMaxOpenConns(1)
rows, err := db.Query("select * from videos where title = 'ed' limit 10")
if err != nil {
fmt.Println(err.Error())
fmt.Println("query error")
}
fmt.Println("-----------------------------------------")
// 拿不到连接,可用的连接一直被上一次查询占用了。
// 会阻塞连接
row, _ := db.Query("select * from videos")
fmt.Println(row, rows)
}
// 只有一个连接,调用了rows遍历代码,最后一次的时候会rows.Close() 释放连接
func oneConnWithRowsNext() {
db, _ := db.Open("mysql", "root:123456@tcp(127.0.0.1:3306)/giligili?charset=utf8&parseTime=True&loc=Local")
db.SetMaxOpenConns(1)
rows, err := db.Query("select * from videos where title = 'ed' limit 10")
if err != nil {
fmt.Println(err.Error())
fmt.Println("query error")
}
fmt.Println("-----------------------------------------")
// 这里可以让下一次sql拿到链接
for rows.Next() {
fmt.Println("close")
}
fmt.Println("-----------------------------------------")
row, _ := db.Query("select * from videos")
fmt.Println(row, rows)
}
// 最大1个连接,使用了rows遍历,但是没有释放连接
func oneConnWithRowsNextWithError() {
db, _ := db.Open("mysql", "root:123456@tcp(127.0.0.1:3306)/giligili?charset=utf8&parseTime=True&loc=Local")
db.SetMaxOpenConns(1)
rows, err := db.Query("select * from videos where title = 'ed' limit 10")
if err != nil {
fmt.Println("query error")
}
fmt.Println("-----------------------------------------")
// rows遍历的提前结束,会影响了后面查询
i := 1
for rows.Next() {
i++
if i == 3 {
break
}
fmt.Println("close")
}
fmt.Println("-----------------------------------------")
row, _ := db.Query("select * from test")
fmt.Println(row, rows)
}
// 最大1个连接,使用rows遍历,即使中途退出,但最后调用了rows.Close() 关闭,释放连接。
func oneConnWithRowsNextWithErrorWithRowsClose() {
db, _ := db.Open("mysql", "root:123456@tcp(127.0.0.1:3306)/giligili?charset=utf8&parseTime=True&loc=Local")
db.SetMaxOpenConns(1)
rows, err := db.Query("select * from videos where title = 'ed' limit 10")
if err != nil {
fmt.Println("query error")
}
fmt.Println("-----------------------------------------")
// 调用了关闭rows的语句,继续执行第二次查询。
i := 1
for rows.Next() {
i++
if i == 3 {
break
}
fmt.Println("close")
}
rows.Close()
fmt.Println("-----------------------------------------")
row, _ := db.Query("select * from videos")
fmt.Println(row, rows)
}
func main() {
// maxConn > 1
fewConns()
// maxConn = 1
oneConn()
// maxConn = 1 + for rows.Next()
oneConnWithRowsNext()
// maxConn = 1 + for rows.Next() + 提前退出
oneConnWithRowsNextWithError()
// maxConn = 1 + for rows.Next() + 提前退出 + defer rows.Close()
oneConnWithRowsNextWithErrorWithRowsClose()
}
</code></pre>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[闲逛]]></title>
<id>https://lvoooo.github.io/post/xian-guang</id>
<link href="https://lvoooo.github.io/post/xian-guang">
</link>
<updated>2019-08-29T06:17:59.000Z</updated>
<content type="html"><![CDATA[<p>https://www.yeboke.cn/</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Go Profile&Debug]]></title>
<id>https://lvoooo.github.io/post/go-profile</id>
<link href="https://lvoooo.github.io/post/go-profile">
</link>
<updated>2019-08-27T08:53:28.000Z</updated>
<content type="html"><![CDATA[<p>参考:<br>
https://blog.csdn.net/get_set/article/details/81229629<br>
https://mp.weixin.qq.com/s?__biz=MzI3MjU4Njk3Ng==&mid=2247484253&idx=2&sn=3b640a7a4b3b9f10ed7400be740fcf5a<br>
https://speakerdeck.com/eranyanay/going-infinite-handling-1m-websockets-connections-in-go</p>
<h3 id="pprof">pprof</h3>
<pre><code class="language-go">import _ "net/http/pprof"
go func() {
if err := http.ListenAndServe("localhost:6060", nil); err != nil {
log.Fatalf("Pprof failed: %v", err)
}
}()
</code></pre>
<pre><code class="language-shell">go tool pprof http://localhost:6060/debug/pprof/heap
go tool pprof http://localhost:6060/debug/pprof/goroutine
</code></pre>
<h3 id="benchmark">benchmark</h3>
<h4 id="benchmark测试有如下约定">benchmark测试有如下约定:</h4>
<ul>
<li>benchmark也是测试,因此也是以_test.go结尾的文件;</li>
<li>需要import testing;</li>
<li>测试方法以Benchmark开始,并且拥有一个*testing.B参数。</li>
</ul>
<pre><code>package main
import "testing"
import "strings"
func BenchmarkStringJoin1(b *testing.B) {
input := []string{"Hello", "World"}
for i := 0; i < b.N; i++ {
result := strings.Join(input, " ")
if result != "Hello World" {
b.Error("Unexpected result: " + result)
}
}
}
</code></pre>
<h4 id="相关命令">相关命令</h4>
<ol>
<li>go test -bench=. -run=NONE</li>
</ol>
<ul>
<li>-bench可以根据正则表达式筛选要测试的方法,这里的.表示匹配所有的测试方</li>
<li>-run=NONE表示忽略功能测试。</li>
</ul>
<p>输出</p>
<pre><code>goos: linux
goarch: amd64
pkg: hello/bench_test
BenchmarkStringJoin1-8 50000000 36.6 ns/op
PASS
ok hello/bench_test 1.871s
</code></pre>
<ul>
<li>BenchmarkStringJoin1-8表示测试了哪个方法,8标识GOMAXPROCS的值,通常等于CPU物理线程数;</li>
<li>50000000即进行了50000000次测试,基准测试运行器开始并不知道这个操作耗时长短,所以开始的时候它使用一个比较小的N值,然后根据运行情况推算出合适的N值;</li>
<li>36.6 ns/op表示每个操作耗时36.6纳秒。</li>
</ul>
<ol start="2">
<li>go test -bench=. -benchmem</li>
</ol>
<pre><code>$ go test -bench=. -benchmem
goos: linux
goarch: amd64
pkg: hello/bench_test
BenchmarkStringJoin1-8 30000000 37.2 ns/op 16 B/op 1 allocs/op
PASS
ok hello/bench_test 1.159s
</code></pre>
<ul>
<li>16 B/op表示每次操作需要16字节的内存;</li>
<li>1 allocs/op表示每次操作会进行一次内存分配。</li>
</ul>
<h3 id="profiling">profiling</h3>
<p>Go通过对执行过程进行采样,来获取profiling数据。具体来说支持如下几种性能指标:</p>
<ul>
<li>CPU profiling:用于识别出执行过程中需要CPU最多的函数。在每个CPU上面执行的线程每个几毫秒进行定期的中断,并在每次中断过程中记录一个性能剖析事件,然后恢复执行。</li>
<li>heap profiling:用于识别出负责分配最多内存的语句。</li>
<li>block profiling:用于识别出阻塞协程最久的操作,比如系统调用、通道发送、接收数据和获取锁等,性能分析库会在goroutine被这些操作阻塞的时候记录一个事件。</li>
</ul>
<ol>
<li>go test -bench . -cpuprofile=cpu.out -blockprofile=block.out -memprofile=mem.out</li>
<li>go tool pprof -text ./bench_test.test cpu.out</li>
<li>输出图片 go tool pprof -svg ./bench_test.test cpu.out > cpu.svg</li>
<li>生成火焰图 go-torch -b cpu.out -f cpu.torch.svg</li>
</ol>
<h4 id="go-torch-安装">go-torch 安装</h4>
<pre><code>git clone --depth=1 https://github.com/brendangregg/FlameGraph.git ~/.flamegraph
export PATH=$PATH:~/.flamegraph
go get github.com/uber/go-torch
</code></pre>
<h3 id="godebug">GODEBUG</h3>
<p>http://www.goinggo.net/2014/01/concurrency-goroutines-and-gomaxprocs.html<br>
http://morsmachine.dk/go-scheduler</p>
<pre><code>GOMAXPROCS=1 GODEBUG=schedtrace=1000 ./example
GOMAXPROCS=2 GODEBUG=schedtrace=1000,scheddetail=1 ./example
</code></pre>
<pre><code>1009ms : 时间是以毫秒为单位,表示了从程序开始运行的时间。这个是第一秒的跟踪信息。
gomaxprocs=1 : 配置的最大的处理器的个数
本程序只配置了一个
更多说明:
这里的处理器是逻辑上的处理器而非物理上的处理器。调度器在这些逻辑处理器上运行 goroutines,这些逻辑处理器通过所附着的操作系统线程绑定在物理处理器上的。 操作系统将在可见的物理存储器上调度线程。
threads=3 : 运行时管理的线程个数。有三个线程存在,一个是给处理器使用,其他两个是被运行时使用。
idlethreads=1 : 空闲的线程个数。一个空闲,两个正在运行。
idleprocs=0 : 空闲的处理器个数。这里空闲个数为 0,有一个运行中。
runqueue=0 : 在全局运行队列中等待的 goroutinue 数量。所有可运行的 goroutinue 都被移到了本地的运行队列中。
[9] : 本地运行队列中等待的 goroutine 数量。当前有 9 个 goroutine 在本地运行队列等待。
</code></pre>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Linux 命令]]></title>
<id>https://lvoooo.github.io/post/linux-ming-ling</id>
<link href="https://lvoooo.github.io/post/linux-ming-ling">
</link>
<updated>2019-08-27T07:37:04.000Z</updated>
<content type="html"><![CDATA[<h3 id="压缩">压缩</h3>
<pre><code class="language-shell">xz -d ***.tar.xz
tar -xvf ***.tar
</code></pre>
<h3 id="用户">用户</h3>
<pre><code class="language-text">#添加用户到sudoer列表中
root 账户键入visudo
实际上是在修改 /etc/sudoers
在 root ALL=(ALL) ALL
这一行,
修改:
username ALL=(ALL) ALL
username ALL=(ALL) NOPASSWD:ALL
</code></pre>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Fabric]]></title>
<id>https://lvoooo.github.io/post/fabric-ca</id>
<link href="https://lvoooo.github.io/post/fabric-ca">
</link>
<updated>2019-08-13T09:46:10.000Z</updated>
<content type="html"><![CDATA[<h2 id="fabric-ca">Fabric CA</h2>
<h3 id="安装">安装</h3>
<ol>
<li>sudo apt update</li>
<li>sudo apt install libtool libltdl-dev</li>
<li>go get -u github.com/hyperledger/fabric-ca</li>
<li>cd $GOPATH/src/github.com/hyperledger/fabric-ca/</li>
<li>make fabric-ca-server</li>
<li>make fabric-ca-client</li>
<li>export PATH=<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>G</mi><mi>O</mi><mi>P</mi><mi>A</mi><mi>T</mi><mi>H</mi><mi mathvariant="normal">/</mi><mi>s</mi><mi>r</mi><mi>c</mi><mi mathvariant="normal">/</mi><mi>g</mi><mi>i</mi><mi>t</mi><mi>h</mi><mi>u</mi><mi>b</mi><mi mathvariant="normal">.</mi><mi>c</mi><mi>o</mi><mi>m</mi><mi mathvariant="normal">/</mi><mi>h</mi><mi>y</mi><mi>p</mi><mi>e</mi><mi>r</mi><mi>l</mi><mi>e</mi><mi>d</mi><mi>g</mi><mi>e</mi><mi>r</mi><mi mathvariant="normal">/</mi><mi>f</mi><mi>a</mi><mi>b</mi><mi>r</mi><mi>i</mi><mi>c</mi><mo>−</mo><mi>c</mi><mi>a</mi><mi mathvariant="normal">/</mi><mi>b</mi><mi>i</mi><mi>n</mi><mo>:</mo></mrow><annotation encoding="application/x-tex">GOPATH/src/github.com/hyperledger/fabric-ca/bin:</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathdefault">G</span><span class="mord mathdefault" style="margin-right:0.02778em;">O</span><span class="mord mathdefault" style="margin-right:0.13889em;">P</span><span class="mord mathdefault">A</span><span class="mord mathdefault" style="margin-right:0.13889em;">T</span><span class="mord mathdefault" style="margin-right:0.08125em;">H</span><span class="mord">/</span><span class="mord mathdefault">s</span><span class="mord mathdefault" style="margin-right:0.02778em;">r</span><span class="mord mathdefault">c</span><span class="mord">/</span><span class="mord mathdefault" style="margin-right:0.03588em;">g</span><span class="mord mathdefault">i</span><span class="mord mathdefault">t</span><span class="mord mathdefault">h</span><span class="mord mathdefault">u</span><span class="mord mathdefault">b</span><span class="mord">.</span><span class="mord mathdefault">c</span><span class="mord mathdefault">o</span><span class="mord mathdefault">m</span><span class="mord">/</span><span class="mord mathdefault">h</span><span class="mord mathdefault" style="margin-right:0.03588em;">y</span><span class="mord mathdefault">p</span><span class="mord mathdefault">e</span><span class="mord mathdefault" style="margin-right:0.02778em;">r</span><span class="mord mathdefault" style="margin-right:0.01968em;">l</span><span class="mord mathdefault">e</span><span class="mord mathdefault">d</span><span class="mord mathdefault" style="margin-right:0.03588em;">g</span><span class="mord mathdefault">e</span><span class="mord mathdefault" style="margin-right:0.02778em;">r</span><span class="mord">/</span><span class="mord mathdefault" style="margin-right:0.10764em;">f</span><span class="mord mathdefault">a</span><span class="mord mathdefault">b</span><span class="mord mathdefault" style="margin-right:0.02778em;">r</span><span class="mord mathdefault">i</span><span class="mord mathdefault">c</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathdefault">c</span><span class="mord mathdefault">a</span><span class="mord">/</span><span class="mord mathdefault">b</span><span class="mord mathdefault">i</span><span class="mord mathdefault">n</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">:</span></span></span></span>PATH</li>
</ol>
<h3 id="初始化">初始化</h3>
<ol>
<li>命令行 -home</li>
<li>FABRIC_CA_SERVER_HOME</li>
<li>FABRIC_CA_HOME</li>
<li>CA_CFG_PATH</li>
<li>使用当前目录</li>
</ol>
<h3 id="普通安装">普通安装</h3>
<ol>
<li>mkdir fabric-ca</li>
<li>cd fabric-ca</li>
<li>fabric-ca-server init -b admin:pass</li>
</ol>
<blockquote>
<p>admin 和 pass 是使用 ca 注册用户时候的用户名和密码<br>
默认在该目录下生成文件<br>
IssuerPublicKey<br>
IssuerRevocationPublicKey<br>
ca-cert.pem<br>
fabric-ca-server-config.yaml<br>
fabric-ca-server.db<br>
msp</p>
</blockquote>
<h2 id="fabric性能测试">Fabric性能测试</h2>
<h3 id="参考">参考</h3>
<ol>
<li>https://blog.csdn.net/get_set/article/details/81229629</li>
<li>https://github.com/hyperledger-archives/fabric/wiki/Profiling-the-Hyperledger-Fabric#other-profiling</li>
</ol>
<h3 id="配置">配置</h3>
<p>Dockerfile</p>
<pre><code># Orderer
- ORDERER_GENERAL_PROFILE_ENABLED=true
# Peer
- CORE_PEER_PROFILE_ENABLED=true
# Peer
</code></pre>
<h3 id="分析">分析</h3>
<pre><code># Peer
#生成 pb 文件
go tool pprof http://<peer-ip>:6060/debug/pprof/profile
~/pprof/pprof.peer.samples.cpu.001.pb.gz
# 生成 火焰图
go-torch -b pprof.peer.samples.cpu.001.pb.gz -f peer.cpu.torch.svg
peer.cpu.torch.svg
# Orderer
#生成 pb 文件
go tool pprof http://<peer-ip>:6060/debug/pprof/profile
~/pprof/pprof.orderer.samples.cpu.001.pb.gz
# 生成 火焰图
go-torch -b pprof.orderer.samples.cpu.001.pb.gz -f orderer.cpu.torch.svg
orderer.cpu.torch.svg
</code></pre>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[NAT相关]]></title>
<id>https://lvoooo.github.io/post/nat-xiang-guan</id>
<link href="https://lvoooo.github.io/post/nat-xiang-guan">
</link>
<updated>2019-08-10T10:12:27.000Z</updated>
<content type="html"><![CDATA[<p>类型(A-B) 建立状况<br>
<strong>完全锥型-完全锥型</strong> A通过server获得B的IP:port开始通信<br>
<strong>完全锥型-IP限制型</strong> B通过server获得A的IP:port开始通信<br>
<strong>完全锥型-port限制型</strong> B通过server获得A的IP:port开始通信<br>
<strong>完全锥型-对称型</strong> B通过server获得A的IP:port开始通信<br>
<strong>IP限制型-IP限制型</strong> A通过server获得B的IP:port,A向B发送UDP包,数据通过自己的NAT时会为B建立NAT映射条目;B通过server获得A的IP:port,发送UDP包为A建立NAT映射条目,二者之后就可以开始通信。<br>
<strong>IP限制型-port限制型</strong> A通过server获得B的IP:port,A向B发送UDP包,数据通过自己的NAT时会为B建立NAT映射条目;B通过server获得A的IP:port,发送UDP包为A建立NAT映射条目,二者之后就可以开始通信。<br>
<strong>IP限制型-对称型</strong> A通过server获得B的IP:port1,A向B发送UDP包,数据通过自己的NAT时会为B建立NAT映射条目;B通过server获得A的IP:port,发送UDP包为A建立NAT映射条目,A收到B的UDP包,获得B新的IP:port2;A向B的新地址IP:port2发送数据,可以开始通信。<br>
<strong>port限制型-对称型</strong> A通过server获得B的IP:port1,A向B发送UDP包,数据通过自己的NAT时会为B建立NAT映射条目;B通过server获得A的IP:port,发送UDP包为A建立NAT映射条目,但由于B更换了新端口port2,A刚建立的映射无法使用,A故此无法收到B为A通信使用的新端口,无法建立NAT映射,两者无法互通。<br>
<strong>对称型-对称型</strong> 同上,对称型开启新端口对方无法获悉,无法建立链接。<br>
无法P2P就需要用TURN服务器转发数据了…</p>
]]></content>
</entry>
</feed>