Home | 簡體中文 | 繁體中文 | 雜文 | 知乎專欄 | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 視頻教程 | 打賞(Donations) | About
知乎專欄多維度架構 | 微信號 netkiller-ebook | QQ群:128659835 請註明“讀者”

34.5. 高級命令

34.5.1. 守護進程

				
$ ipfs daemon
				
			

http://localhost:5001/webui

34.5.2. 發佈並解析IPNS

				
[root@netkiller ~]# ipfs add readme.txt
added QmdoPoadYA5HYvSzgUrgXYdEVRNL1T7pY38GaWabZ3KLgn readme.txt
[root@netkiller ~]# ipfs name publish QmdoPoadYA5HYvSzgUrgXYdEVRNL1T7pY38GaWabZ3KLgn

Published to QmPNH1AKXNidUgsW6MaMABiNRhdXnqpTbthbYoZzhZE9ve: /ipfs/QmdoPoadYA5HYvSzgUrgXYdEVRNL1T7pY38GaWabZ3KLgn

[root@netkiller ~]# ipfs cat /ipfs/QmdoPoadYA5HYvSzgUrgXYdEVRNL1T7pY38GaWabZ3KLgn
				
			

驗證發佈

				
[root@netkiller ~]# ipfs add version.txt
added QmWzK72EZJJhW96x1tgaz8yU3G6okJ9MfMxbLianzFLhY2 version.txt

[root@netkiller ~]# ipfs name publish QmWzK72EZJJhW96x1tgaz8yU3G6okJ9MfMxbLianzFLhY2
Published to QmPNH1AKXNidUgsW6MaMABiNRhdXnqpTbthbYoZzhZE9ve: /ipfs/QmWzK72EZJJhW96x1tgaz8yU3G6okJ9MfMxbLianzFLhY2

[root@netkiller ~]# ipfs name resolve QmPNH1AKXNidUgsW6MaMABiNRhdXnqpTbthbYoZzhZE9ve
/ipfs/QmWzK72EZJJhW96x1tgaz8yU3G6okJ9MfMxbLianzFLhY2
				
			

34.5.3. 將 Pin 對象存儲到本地

Pinning 是 IPFS 中一個非常重要的概念。你可以從任何一個節點訪問IPFS網絡上的檔案,如果本地沒有就會去整個IPFS網絡上檢索。

你希望將有些檔案永久保存在你的伺服器中,就需要用到 pin 功能。

IPFS 中有三種 pin 類型

  • direct pins 僅僅pin住一個和其它區塊沒有關聯的獨立block
  • recursive pins pin住給出的block以及遞歸pin住它的所有children
  • indirect pins recursive pin的children,不是直接被pin住的,是被遞歸pin住的

34.5.3.1. 演示 Pin 操作

				
[ipfs@netkiller ~]$ echo "helloworld" > foo

[ipfs@netkiller ~]$ ipfs add foo 
added QmUU2HcUBVSXkfWPUc3WUSeCMrWWeEJTuAgR9uyWBhh9Nf foo
 11 B / 11 B [==============================================================================] 100.00%
 
 [ipfs@netkiller ~]$ ipfs pin ls --type=all | grep QmUU2HcUBVSXkfWPUc3WUSeCMrWWeEJTuAgR9uyWBhh9Nf
QmUU2HcUBVSXkfWPUc3WUSeCMrWWeEJTuAgR9uyWBhh9Nf recursive

[ipfs@netkiller ~]$ ipfs pin rm -r QmUU2HcUBVSXkfWPUc3WUSeCMrWWeEJTuAgR9uyWBhh9Nf
unpinned QmUU2HcUBVSXkfWPUc3WUSeCMrWWeEJTuAgR9uyWBhh9Nf

[ipfs@netkiller ~]$ ipfs pin ls --type=all | grep QmUU2HcUBVSXkfWPUc3WUSeCMrWWeEJTuAgR9uyWBhh9Nf
				
				

34.5.3.2. 查看 pin

				
[root@netkiller ~]# ipfs pin ls
QmQBcXurY2QBpv7sg8zyS4UXQeHGCqx4DBp86kBLPDzS18 recursive
QmTudJSaoKxtbEnTddJ9vh8hbN84ZLVvD5pNpUaSbxwGoa recursive
QmXgqKTbzdh83pQtKFb19SpMCpDDcKR2ujqk3pKph9aCNF indirect
QmcUcr4nbCDE4V1fPNZXoZa3YkCwjCv8Wd9EqLJeysAt48 indirect
QmcUnyBqYgAR5rxVQ1Pzw2DBh9evqSRBRogjshb9khJA9T indirect
QmejvEPop4D7YUadeGqYWmZxHhLc4JBUCzJJHWMzdcMe2y indirect
QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv recursive
QmTiu69XGzh1iqK6JuJNzoTiQ4SJEeQSso3uCHRwbXFba8 indirect
QmW2nvZqf6fwmcgBeeUEv2UyePizsFjjkNCubqRjmCZHNV indirect
QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 indirect
QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y indirect
QmZtmD2qt6fJot32nabSP3CUjicnypEBz7bHVDhPQt9aAy recursive
QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB indirect
QmQ5vhrL7uv6tuoN9KeVBwd4PwfQkXdVVmDLUZuTNxqgvm indirect
QmRpsaigHjE4udpVDXZ8T4YtA477M7YTox6xxxkbYjisgN indirect
QmWkLpc4aCRCgPYokdXGZU3zuupRognVGVccALY4aJH31W indirect
QmWzK72EZJJhW96x1tgaz8yU3G6okJ9MfMxbLianzFLhY2 recursive
QmaHUhxr4NPTsxc2iubLAVGAvJ6hRKfZsbDPYZDT6Bdcb1 indirect
QmSLNhoZCHiRUyAsPRsLRMscu2AromEYJgJJWw229DypXT indirect
QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn recursive
QmVbXqY6kY7iFjPNw1vNGggtRmNxTVLGAziLvC9GEsMLGR recursive
QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V indirect
Qmbh35NHRNYfpaXaj1bQF4gcVYKRjjBvD7eys4dK4iwNrY indirect
Qmen15DKJhF5ngxiBEzmpMyPA3HpMfXNqgogeyeati2sEx indirect
				
				

34.5.4. 查看狀態

34.5.4.1. 倉庫狀態

					
[root@netkiller ~]# ipfs stats repo
NumObjects: 46
RepoSize:   3004401
StorageMax: 10000000000
RepoPath:   /root/.ipfs
Version:    fs-repo@6
					
				

34.5.4.2. 頻寬狀態

					
[root@netkiller ~]# ipfs stats bw
Total Up    Total Down  Rate Up     Rate Down
Bandwidth
TotalIn: 20 MB
TotalOut: 4.9 MB
RateIn: 4.4 kB/s
RateOut: 3.4 kB/s