https://www.netkiller.cn/blockchain/ipfs/index.html
转了先
IPFS(InterPlanetary File System,星际文件系统)
目录
IPFS “星际文件系统” 是去中心化保存和共享文件的分布式文件系统,它是一种内容可寻址、版本化、点对点超媒体的分布式协议,IPFS旨在替代HTTP。它希望将所有的计算设备都连接到同一个文件系统中。
由于 IPFS 去中心化特点,使得很多区块链项目做文件存储的时候首选IPFS。
举个例子,服务器上有一个文件https://www.netkiller.cn/video/av.mp4,按照HTTP协议标准流程,浏览器首先会解析域名并查找到服务器的IP地址,随后与服务器建立链接,并根据路径向服务器请求该文件/video/av.mp4。在这种体系下用户是否能获取该文件取决于文件是否被移动或删除,并且服务器没有关闭。
另一个问题就是文件服务器管理,中心化管理是很复杂的,如果访问量比较大,我们通常会使用负载均衡来解决,负载均衡需要每个节点上的数据是完整的,这就需要大量的数据同步。如果从深圳数据中心同步到上海数据中心 100T的数据可能要数个工作日。
HTTP过度依赖Internet主干网,同时网络通信遭遇DDoS攻击的风险也大大增加。
CDN 只解决最后一公里的性能问题,数据回源仍然是中心化,仍然无法彻底解决。
Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | 云栖社区 | OSChina 博客 | Facebook | Linkedin | 知乎专栏 | Github | Search | About
23.3. ipfs 命令
创建 ipfs 用户
1 2 3 |
[root@netkiller ~]# adduser ipfs [root@netkiller ~]# su - ipfs [ipfs@netkiller ~]$ |
23.3.1. 基本命令
23.3.1.1. 初始化节点
1 2 3 4 5 6 7 |
[ipfs@netkiller ~]$ ipfs init initializing IPFS node at /home/ipfs/.ipfs generating 2048-bit RSA keypair...done peer identity: QmZakCF5czhP53KPvMi8XQcYtVrQohw5N71Xce4eC1rWz3 to get started, enter: ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme |
目录结构
1 2 |
[ipfs@netkiller ~]$ ls .ipfs/ blocks config datastore datastore_spec keystore version |
23.3.1.2. 添加文件
1 2 3 4 5 6 7 8 9 |
[ipfs@netkiller ~]$ echo Helloworld > helloworld.txt [ipfs@netkiller ~]$ ipfs add helloworld.txt added QmS8R3nSbDHjQ7WRTjtX1pkiQ6BUpti9qTjweZkBgGPKiN helloworld.txt [ipfs@netkiller ~]$ ipfs cat QmS8R3nSbDHjQ7WRTjtX1pkiQ6BUpti9qTjweZkBgGPKiN Helloworld [ipfs@netkiller ~]$ ipfs cat /ipfs/QmS8R3nSbDHjQ7WRTjtX1pkiQ6BUpti9qTjweZkBgGPKiN Helloworld |
添加文本
1 2 3 4 5 |
[ipfs@netkiller ~]$ echo 'Look! Things have changed!' | ipfs add added QmSb8DSVmu4Qip56jcqPVz1Cx9RJ3vTf3d1Gf9ixaG2tWg QmSb8DSVmu4Qip56jcqPVz1Cx9RJ3vTf3d1Gf9ixaG2tWg [ipfs@netkiller ~]$ ipfs cat QmSb8DSVmu4Qip56jcqPVz1Cx9RJ3vTf3d1Gf9ixaG2tWg Look! Things have changed! |
修改内容
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 |
[root@netkiller ~]# echo "version 1 of my text" | ipfs add added QmZtmD2qt6fJot32nabSP3CUjicnypEBz7bHVDhPQt9aAy QmZtmD2qt6fJot32nabSP3CUjicnypEBz7bHVDhPQt9aAy [root@netkiller ~]# echo "version 2 of my text" | ipfs add added QmTudJSaoKxtbEnTddJ9vh8hbN84ZLVvD5pNpUaSbxwGoa QmTudJSaoKxtbEnTddJ9vh8hbN84ZLVvD5pNpUaSbxwGoa [root@netkiller ~]# ipfs cat QmZtmD2qt6fJot32nabSP3CUjicnypEBz7bHVDhPQt9aAy version 1 of my text [root@netkiller ~]# ipfs cat QmTudJSaoKxtbEnTddJ9vh8hbN84ZLVvD5pNpUaSbxwGoa version 2 of my text [root@netkiller ~]# echo "version 1" > version.txt [root@netkiller ~]# ipfs add version.txt added QmQBcXurY2QBpv7sg8zyS4UXQeHGCqx4DBp86kBLPDzS18 version.txt [root@netkiller ~]# echo "version 2" > version.txt [root@netkiller ~]# ipfs add version.txt added QmWzK72EZJJhW96x1tgaz8yU3G6okJ9MfMxbLianzFLhY2 version.txt [root@netkiller ~]# ipfs cat QmQBcXurY2QBpv7sg8zyS4UXQeHGCqx4DBp86kBLPDzS18 version 1 [root@netkiller ~]# ipfs cat QmWzK72EZJJhW96x1tgaz8yU3G6okJ9MfMxbLianzFLhY2 version 2 |
23.3.1.3. 查看文件
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 |
[ipfs@netkiller ~]$ ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme Hello and Welcome to IPFS! ██╗██████╗ ███████╗███████╗ ██║██╔══██╗██╔════╝██╔════╝ ██║██████╔╝█████╗ ███████╗ ██║██╔═══╝ ██╔══╝ ╚════██║ ██║██║ ██║ ███████║ ╚═╝╚═╝ ╚═╝ ╚══════╝ If you're seeing this, you have successfully installed IPFS and are now interfacing with the ipfs merkledag! ------------------------------------------------------- | Warning: | | This is alpha software. Use at your own discretion! | | Much is missing or lacking polish. There are bugs. | | Not yet secure. Read the security notes for more. | ------------------------------------------------------- Check out some of the other files in this directory: ./about ./help ./quick-start <-- usage examples ./readme <-- this file ./security-notes |
23.3.1.4. 下载文件
1 2 3 4 5 |
[root@netkiller ~]# ipfs get /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme Saving file(s) to readme 1.08 KB / 1.08 KB [======================================================================] 100.00% 0s [root@netkiller ~]# ls readme |
1 2 3 4 5 6 7 8 9 10 11 12 |
[root@netkiller ~]# ipfs add readme.txt added QmdoPoadYA5HYvSzgUrgXYdEVRNL1T7pY38GaWabZ3KLgn readme.txt [root@netkiller ~]# ipfs cat QmdoPoadYA5HYvSzgUrgXYdEVRNL1T7pY38GaWabZ3KLgn Helloworld [root@netkiller ~]# ipfs get QmdoPoadYA5HYvSzgUrgXYdEVRNL1T7pY38GaWabZ3KLgn Saving file(s) to QmdoPoadYA5HYvSzgUrgXYdEVRNL1T7pY38GaWabZ3KLgn 880 B / 880 B [=========================================================================] 100.00% 0s [root@netkiller ~]# ls QmdoPoadYA5HYvSzgUrgXYdEVRNL1T7pY38GaWabZ3KLgn readme.txt |
23.3.1.5. 列出文件或目录
1 2 3 4 5 6 7 8 |
[root@netkiller ~]# ipfs ls /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/ QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V 1688 about QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y 200 contact QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 322 help QmejvEPop4D7YUadeGqYWmZxHhLc4JBUCzJJHWMzdcMe2y 12 ping QmXgqKTbzdh83pQtKFb19SpMCpDDcKR2ujqk3pKph9aCNF 1692 quick-start QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB 1102 readme QmQ5vhrL7uv6tuoN9KeVBwd4PwfQkXdVVmDLUZuTNxqgvm 1173 security-notes |
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 |
[root@netkiller ~]# ipfs add -r /etc/rc.d added QmP4m7YRN25kcRgoJgn95yFR4GsVgbQppnpMGh3AxPzUbc rc.d/init.d/README added QmemkmPhud9hBWhTDgnYfascZcXjX4H6j4oyqhKdSvFq8G rc.d/init.d/aegis added QmR2zvwDZYQPw4arpaJQwGESPhmz6qBt8MqyrV5UR72JUy rc.d/init.d/agentwatch added QmevSkKJVSF4amfHux7bMZCvaQQjuFsDxU1j7j7uvvJzBh rc.d/init.d/functions added QmXCmPYb1wWcmAWk8tm1jgYsFgF16mTe2PsnNebw1gzWDw rc.d/init.d/jexec added QmeQZxv7Fui5Ah9w9E9QuiyTrbm4XMKyJMthGLvbbtd5q4 rc.d/init.d/netconsole added QmeDfRGHoLuSTZqk4zcwGKJQ1NUk9VhEYxFy1HC5d9hKxH rc.d/init.d/network added QmYWStNUPtn9TgUT39D7vXMjXc5y917W7SsjPTZvCMK136 rc.d/rc.local added QmS92vH7JY9CnP3DVZiQcHxqyi9FQXc1RTcyQvhCJnTCon rc.d/rc0.d/K01agentwatch added QmabzShX1WxbdMfLmNK16M1edR5TP95iM5FBURSFwfdj4t rc.d/rc0.d/K05jexec added QmcuWaJdg5JCckgdh5BomTwYjrn3ChrC2xa3yY61jQ1pGV rc.d/rc0.d/K50aegis added QmYnJ5yxouhrbu81Nod3o1ZWKuwdHYYsbr7z4BgLCxxR2P rc.d/rc0.d/K50netconsole added QmPNCeB2yS9EZ3cG3ousMtPkLNemkQaDfKt63S4NTBJg3z rc.d/rc0.d/K90network added QmS92vH7JY9CnP3DVZiQcHxqyi9FQXc1RTcyQvhCJnTCon rc.d/rc1.d/K01agentwatch added QmcuWaJdg5JCckgdh5BomTwYjrn3ChrC2xa3yY61jQ1pGV rc.d/rc1.d/K50aegis added QmYnJ5yxouhrbu81Nod3o1ZWKuwdHYYsbr7z4BgLCxxR2P rc.d/rc1.d/K50netconsole added QmPNCeB2yS9EZ3cG3ousMtPkLNemkQaDfKt63S4NTBJg3z rc.d/rc1.d/K90network added QmabzShX1WxbdMfLmNK16M1edR5TP95iM5FBURSFwfdj4t rc.d/rc1.d/S95jexec added QmYnJ5yxouhrbu81Nod3o1ZWKuwdHYYsbr7z4BgLCxxR2P rc.d/rc2.d/K50netconsole added QmPNCeB2yS9EZ3cG3ousMtPkLNemkQaDfKt63S4NTBJg3z rc.d/rc2.d/S10network added QmcuWaJdg5JCckgdh5BomTwYjrn3ChrC2xa3yY61jQ1pGV rc.d/rc2.d/S50aegis added QmabzShX1WxbdMfLmNK16M1edR5TP95iM5FBURSFwfdj4t rc.d/rc2.d/S95jexec added QmS92vH7JY9CnP3DVZiQcHxqyi9FQXc1RTcyQvhCJnTCon rc.d/rc2.d/S98agentwatch added QmYnJ5yxouhrbu81Nod3o1ZWKuwdHYYsbr7z4BgLCxxR2P rc.d/rc3.d/K50netconsole added QmPNCeB2yS9EZ3cG3ousMtPkLNemkQaDfKt63S4NTBJg3z rc.d/rc3.d/S10network added QmcuWaJdg5JCckgdh5BomTwYjrn3ChrC2xa3yY61jQ1pGV rc.d/rc3.d/S50aegis added QmabzShX1WxbdMfLmNK16M1edR5TP95iM5FBURSFwfdj4t rc.d/rc3.d/S95jexec added QmS92vH7JY9CnP3DVZiQcHxqyi9FQXc1RTcyQvhCJnTCon rc.d/rc3.d/S98agentwatch added QmYnJ5yxouhrbu81Nod3o1ZWKuwdHYYsbr7z4BgLCxxR2P rc.d/rc4.d/K50netconsole added QmPNCeB2yS9EZ3cG3ousMtPkLNemkQaDfKt63S4NTBJg3z rc.d/rc4.d/S10network added QmcuWaJdg5JCckgdh5BomTwYjrn3ChrC2xa3yY61jQ1pGV rc.d/rc4.d/S50aegis added QmabzShX1WxbdMfLmNK16M1edR5TP95iM5FBURSFwfdj4t rc.d/rc4.d/S95jexec added QmS92vH7JY9CnP3DVZiQcHxqyi9FQXc1RTcyQvhCJnTCon rc.d/rc4.d/S98agentwatch added QmYnJ5yxouhrbu81Nod3o1ZWKuwdHYYsbr7z4BgLCxxR2P rc.d/rc5.d/K50netconsole added QmPNCeB2yS9EZ3cG3ousMtPkLNemkQaDfKt63S4NTBJg3z rc.d/rc5.d/S10network added QmcuWaJdg5JCckgdh5BomTwYjrn3ChrC2xa3yY61jQ1pGV rc.d/rc5.d/S50aegis added QmabzShX1WxbdMfLmNK16M1edR5TP95iM5FBURSFwfdj4t rc.d/rc5.d/S95jexec added QmS92vH7JY9CnP3DVZiQcHxqyi9FQXc1RTcyQvhCJnTCon rc.d/rc5.d/S98agentwatch added QmS92vH7JY9CnP3DVZiQcHxqyi9FQXc1RTcyQvhCJnTCon rc.d/rc6.d/K01agentwatch added QmabzShX1WxbdMfLmNK16M1edR5TP95iM5FBURSFwfdj4t rc.d/rc6.d/K05jexec added QmcuWaJdg5JCckgdh5BomTwYjrn3ChrC2xa3yY61jQ1pGV rc.d/rc6.d/K50aegis added QmYnJ5yxouhrbu81Nod3o1ZWKuwdHYYsbr7z4BgLCxxR2P rc.d/rc6.d/K50netconsole added QmPNCeB2yS9EZ3cG3ousMtPkLNemkQaDfKt63S4NTBJg3z rc.d/rc6.d/K90network added QmUy33heBFE59gc6PB2sevQ88gB7Lv3NDASFJF3S8f1qHK rc.d/init.d added QmaDZHSDdtNyryWNwtxuMtJ8NduQdfhMMHk7JuTpNW5sTs rc.d/rc0.d added QmX6D9eP1oHMg92rrVYarGAe4w3HQ9vURcncBRvPqtXSyG rc.d/rc1.d added QmTEuKk4acWJcsCDYJViMNoKZ2BQDY8NSHraV9gB9nAWm8 rc.d/rc2.d added QmTEuKk4acWJcsCDYJViMNoKZ2BQDY8NSHraV9gB9nAWm8 rc.d/rc3.d added QmTEuKk4acWJcsCDYJViMNoKZ2BQDY8NSHraV9gB9nAWm8 rc.d/rc4.d added QmTEuKk4acWJcsCDYJViMNoKZ2BQDY8NSHraV9gB9nAWm8 rc.d/rc5.d added QmaDZHSDdtNyryWNwtxuMtJ8NduQdfhMMHk7JuTpNW5sTs rc.d/rc6.d added QmRYPNdKdyCr6R7fE63g2u3sMD8SQh8TW6yQNAk9mT9Pay rc.d [root@netkiller ~]# ipfs ls -v QmRYPNdKdyCr6R7fE63g2u3sMD8SQh8TW6yQNAk9mT9Pay Hash Size Name QmUy33heBFE59gc6PB2sevQ88gB7Lv3NDASFJF3S8f1qHK 36013 init.d/ QmYWStNUPtn9TgUT39D7vXMjXc5y917W7SsjPTZvCMK136 484 rc.local QmaDZHSDdtNyryWNwtxuMtJ8NduQdfhMMHk7JuTpNW5sTs 383 rc0.d/ QmX6D9eP1oHMg92rrVYarGAe4w3HQ9vURcncBRvPqtXSyG 383 rc1.d/ QmTEuKk4acWJcsCDYJViMNoKZ2BQDY8NSHraV9gB9nAWm8 383 rc2.d/ QmTEuKk4acWJcsCDYJViMNoKZ2BQDY8NSHraV9gB9nAWm8 383 rc3.d/ QmTEuKk4acWJcsCDYJViMNoKZ2BQDY8NSHraV9gB9nAWm8 383 rc4.d/ QmTEuKk4acWJcsCDYJViMNoKZ2BQDY8NSHraV9gB9nAWm8 383 rc5.d/ QmaDZHSDdtNyryWNwtxuMtJ8NduQdfhMMHk7JuTpNW5sTs 383 rc6.d/ [root@netkiller ~]# ipfs ls -v QmUy33heBFE59gc6PB2sevQ88gB7Lv3NDASFJF3S8f1qHK Hash Size Name QmP4m7YRN25kcRgoJgn95yFR4GsVgbQppnpMGh3AxPzUbc 1171 README QmemkmPhud9hBWhTDgnYfascZcXjX4H6j4oyqhKdSvFq8G 2266 aegis QmR2zvwDZYQPw4arpaJQwGESPhmz6qBt8MqyrV5UR72JUy 3015 agentwatch QmevSkKJVSF4amfHux7bMZCvaQQjuFsDxU1j7j7uvvJzBh 17514 functions QmXCmPYb1wWcmAWk8tm1jgYsFgF16mTe2PsnNebw1gzWDw 41 jexec QmeQZxv7Fui5Ah9w9E9QuiyTrbm4XMKyJMthGLvbbtd5q4 4345 netconsole QmeDfRGHoLuSTZqk4zcwGKJQ1NUk9VhEYxFy1HC5d9hKxH 7304 network |
23.3.2. 数据结构命令
23.3.2.1. 块
23.3.2.2. 对象
1 2 |
[ipfs@netkiller ~]$ ipfs object get QmS8R3nSbDHjQ7WRTjtX1pkiQ6BUpti9qTjweZkBgGPKiN {"Links":[],"Data":"\u0008\u0002\u0012\u000bHelloworld\n\u0018\u000b"} |
23.3.3. 高级命令
23.3.3.1. 守护进程
1 |
$ ipfs daemon |
http://localhost:5001/webui
23.3.3.2. 发布并解析IPNS
1 2 3 4 5 6 7 |
[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 |
验证发布
1 2 3 4 5 6 7 8 |
[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 |
23.3.3.3. 将 Pin 对象存储到本地
ls
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 |
[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 |
23.3.3.4. 查看状态
23.3.3.4.1. 仓库状态
1 2 3 4 5 6 |
[root@netkiller ~]# ipfs stats repo NumObjects: 46 RepoSize: 3004401 StorageMax: 10000000000 RepoPath: /root/.ipfs Version: fs-repo@6 |
23.3.3.4.2. 带宽状态
1 2 3 4 5 6 7 |
[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 |
23.3.4. 网络命令
23.3.4.1. 显示 IPFS 信息
1 2 3 4 5 6 7 8 |
[ipfs@netkiller ~]$ ipfs id { "ID": "QmZakCF5czhP53KPvMi8XQcYtVrQohw5N71Xce4eC1rWz3", "PublicKey": "CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDYWmvcJrJsIjgP+n/EwZyLify7KgZ3SnIrsN9k2z9iF1X9uq9tebH1Dx6tPFIoBndYCvZlrdafHkbL5XRjJ0j0W2ISVKC75I+u9bS4WHSD7gPI82AdlWEp6elL5Muw7DnyN8flOQyxtJqhjkMY5pSnCcLXuOmXZJ2YY+4jZSQ58QmsA17wLcn01so4impSOxjDkjuOuday9SxK5vmstq9Qp/h2neyUsDtx1+q0M0kjlkInRtfXCmtd14EHqcv4VgG+aCcF8UuWgNXBTLc/R5xqtxFx8KacWjf5xUOe7Sjat7tgaY5eBOphupy5zzXfP2YigTY0cz5jIKkPoFK+lppjAgMBAAE=", "Addresses": null, "AgentVersion": "go-ipfs/0.4.14/", "ProtocolVersion": "ipfs/0.1.0" } |
23.3.4.2. 节点
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[ipfs@netkiller ~]$ ipfs bootstrap list /dnsaddr/bootstrap.libp2p.io/ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN /dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa /dnsaddr/bootstrap.libp2p.io/ipfs/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb /dnsaddr/bootstrap.libp2p.io/ipfs/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt /ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ /ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM /ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64 /ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu /ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd /ip6/2400:6180:0:d0::151:6001/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu /ip6/2604:a880:1:20::203:d001/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM /ip6/2604:a880:800:10::4a:5001/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64 /ip6/2a03:b0c0:0:1010::23:1001/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd |
23.3.4.3. 管理P2P网络链接
1 2 |
[root@netkiller ~]# ipfs swarm peers /ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ |
23.3.5. 工具命令
23.3.5.1. 配置
1 |
"StorageMax": "10GB" 存储空间配额,默认为 10G |
23.3.5.1.1. 显示配置
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 |
[ipfs@netkiller ~]$ ipfs config show { "API": { "HTTPHeaders": { "Server": [ "go-ipfs/0.4.14" ] } }, "Addresses": { "API": "/ip4/127.0.0.1/tcp/5001", "Announce": [], "Gateway": "/ip4/127.0.0.1/tcp/8080", "NoAnnounce": [], "Swarm": [ "/ip4/0.0.0.0/tcp/4001", "/ip6/::/tcp/4001" ] }, "Bootstrap": [ "/dnsaddr/bootstrap.libp2p.io/ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN", "/dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa", "/dnsaddr/bootstrap.libp2p.io/ipfs/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb", "/dnsaddr/bootstrap.libp2p.io/ipfs/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt", "/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", "/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM", "/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu", "/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64", "/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd", "/ip6/2604:a880:1:20::203:d001/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM", "/ip6/2400:6180:0:d0::151:6001/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu", "/ip6/2604:a880:800:10::4a:5001/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64", "/ip6/2a03:b0c0:0:1010::23:1001/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd" ], "Datastore": { "BloomFilterSize": 0, "GCPeriod": "1h", "HashOnRead": false, "Spec": { "mounts": [ { "child": { "path": "blocks", "shardFunc": "/repo/flatfs/shard/v1/next-to-last/2", "sync": true, "type": "flatfs" }, "mountpoint": "/blocks", "prefix": "flatfs.datastore", "type": "measure" }, { "child": { "compression": "none", "path": "datastore", "type": "levelds" }, "mountpoint": "/", "prefix": "leveldb.datastore", "type": "measure" } ], "type": "mount" }, "StorageGCWatermark": 90, "StorageMax": "10GB" }, "Discovery": { "MDNS": { "Enabled": true, "Interval": 10 } }, "Experimental": { "FilestoreEnabled": false, "Libp2pStreamMounting": false, "ShardingEnabled": false }, "Gateway": { "HTTPHeaders": { "Access-Control-Allow-Headers": [ "X-Requested-With", "Range" ], "Access-Control-Allow-Methods": [ "GET" ], "Access-Control-Allow-Origin": [ "*" ] }, "PathPrefixes": [], "RootRedirect": "", "Writable": false }, "Identity": { "PeerID": "QmZakCF5czhP53KPvMi8XQcYtVrQohw5N71Xce4eC1rWz3" }, "Ipns": { "RecordLifetime": "", "RepublishPeriod": "", "ResolveCacheSize": 128 }, "Mounts": { "FuseAllowOther": false, "IPFS": "/ipfs", "IPNS": "/ipns" }, "Reprovider": { "Interval": "12h", "Strategy": "all" }, "Swarm": { "AddrFilters": null, "ConnMgr": { "GracePeriod": "20s", "HighWater": 900, "LowWater": 600, "Type": "basic" }, "DisableBandwidthMetrics": false, "DisableNatPortMap": false, "DisableRelay": false, "EnableRelayHop": false } } |
23.3.5.1.2. 修改配置
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 |
[ipfs@netkiller ~]$ export EDITOR=/usr/bin/vim [ipfs@netkiller ~]$ ipfs config edit { "Identity": { "PeerID": "QmZakCF5czhP53KPvMi8XQcYtVrQohw5N71Xce4eC1rWz3", "PrivKey": "CAASpwkwggSjAgEAAoIBAQDYWmvcJrJsIjgP+n/EwZyLify7KgZ3SnIrsN9k2z9iF1X9uq9tebH1Dx6tPFIoBndYCvZlrdafHkbL5XRjJ0j0W2ISVKC75I+u9bS4WHSD7gPI82AdlWEp6elL5Muw7DnyN8flOQyxtJqhjkMY5pSnCcLXuOmXZJ2YY+4jZSQ58QmsA17wLcn01so4impSOxjDkjuOuday9SxK5vmstq9Qp/h2neyUsDtx1+q0M0kjlkInRtfXCmtd14EHqcv4VgG+aCcF8UuWgNXBTLc/R5xqtxFx8KacWjf5xUOe7Sjat7tgaY5eBOphupy5zzXfP2YigTY0cz5jIKkPoFK+lppjAgMBAAECggEAEA6l8rDsjRn9DzKISRIVjEWxfDKiSDg+QP/flJyxF5ajyzEP1BA0JPv6SuEvN8lDEkW+A83jH+wfVQKyoKlJwNkHblTZmRhdkZ6qywPFogUIQuHNQGTV0UaLChbxBzCBHHkHXPve9VFyKItmb3Ktlbgjvd77d0EAcU75XackCSi3mQkm73w+9YquTlJtIcpE9RX5k4ZRrdbY3waGd5ZzGCpzUeok009wbpPOxKBObyUdzSEhLRDS5gExwGRP8hGdxpU3Er1x6A+ojEkG3vjqCk/FoUiNyUXADKzLifjFDqFD8Ek4jIdM712YB2F8ERfVQo/AIt3c06Gzbc+DSXJ4AQKBgQD00k08k68bHF63NsD9qbfIY8iSge6D6k7h1USVRoQcGzeZsMHmSBUNr+sWH+nV8NZSOiej/KLoZcVlHhjqUouajZj2Ej7X4BCWF9TYt1DsKAjCOwqImmbSoISMZWtnWuqhemI1d+dEkOaYFL2oiqmGjx00Vo5eY9DaX9zRpREuzQKBgQDiO1swOPWAb4pl5s0IOc6/kOWFLnvkP8efM/tdwv3NYwq2iwurfGG395jCc35XcAlccIvsXoJ1+mGzaGeZu5ppSRKu2Vqg5YOVxSzBeoBRxl//KK2+wOwrHaEgIbN9vcjBZVYKR87VdwLJb4PlnaSyZac71ZQMjNzo0UsGhdmN7wKBgDoHdwM6xjCY4uJuegQmLEe1Tx9a6Nwft57T3DO9ySaYVO969BrPTx41anWODvEE6ugGnMrD4SFQrh8vqRwxgKGbmnwJCxhEJepNr8fGe8neG2VedTq3zlNydLiKeZC//glUZt7hktGvvtihYesHIvOgDH4RXiGFa0W3nzGZ/J6pAoGAZSEDclsD45X41/SEUtkEgr3S2+Ybm7ynD5O9GfzAV7+eWlttrAq94+7aapIWOB/tD1WANvlIeFSkt/5D0YT7UXVI1MB0stfmKl0p1JNeKS/0Watlf4/eAqgMDsEB64Oa6ljSTWYsH2BD7qfa3hnKNbUbPLQMqk+NsMVeNFxBFCECgYEA0l9L2nLelP/osGt2iQ1yRlAQ/EdaiHe9/RE3f+EQ2tFkGDw0sj8eC/vvLhrh9fDRco46bt3Jw5JGEfW+cJ/9u7ULvsAiWiMes0ENqGu0GE/yLD0guFrPdSJfzlWS5+mVxxOXMyHnp5xo0Vz5A3aoGt3Lq0neaKZAYXRwYkxcQd8=" }, "Datastore": { "StorageMax": "10GB", "StorageGCWatermark": 90, "GCPeriod": "1h", "Spec": { "mounts": [ { "child": { "path": "blocks", "shardFunc": "/repo/flatfs/shard/v1/next-to-last/2", "sync": true, "type": "flatfs" }, "mountpoint": "/blocks", "prefix": "flatfs.datastore", "type": "measure" }, { "child": { "compression": "none", "path": "datastore", "type": "levelds" }, "mountpoint": "/", |
23.3.5.2. 命令列表
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 |
[root@netkiller ~]# ipfs commands ipfs ipfs add ipfs bitswap ipfs bitswap ledger ipfs bitswap reprovide ipfs bitswap stat ipfs bitswap unwant ipfs bitswap wantlist ipfs block ipfs block get ipfs block put ipfs block rm ipfs block stat ipfs bootstrap ipfs bootstrap add ipfs bootstrap add default ipfs bootstrap list ipfs bootstrap rm ipfs bootstrap rm all ipfs cat ipfs commands ipfs config ipfs config edit ipfs config profile ipfs config profile apply ipfs config replace ipfs config show ipfs daemon ipfs dag ipfs dag get ipfs dag put ipfs dag resolve ipfs dht ipfs dht findpeer ipfs dht findprovs ipfs dht get ipfs dht provide ipfs dht put ipfs dht query ipfs diag ipfs diag cmds ipfs diag cmds clear ipfs diag cmds set-time ipfs diag sys ipfs dns ipfs file ipfs file ls ipfs files ipfs files chcid ipfs files cp ipfs files flush ipfs files ls ipfs files mkdir ipfs files mv ipfs files read ipfs files rm ipfs files stat ipfs files write ipfs filestore ipfs filestore dups ipfs filestore ls ipfs filestore verify ipfs get ipfs id ipfs init ipfs key ipfs key gen ipfs key list ipfs key rename ipfs key rm ipfs log ipfs log level ipfs log ls ipfs log tail ipfs ls ipfs mount ipfs name ipfs name publish ipfs name pubsub ipfs name pubsub cancel ipfs name pubsub state ipfs name pubsub subs ipfs name resolve ipfs object ipfs object data ipfs object diff ipfs object get ipfs object links ipfs object new ipfs object patch ipfs object patch add-link ipfs object patch append-data ipfs object patch rm-link ipfs object patch set-data ipfs object put ipfs object stat ipfs p2p ipfs p2p listener ipfs p2p listener close ipfs p2p listener ls ipfs p2p listener open ipfs p2p stream ipfs p2p stream close ipfs p2p stream dial ipfs p2p stream ls ipfs pin ipfs pin add ipfs pin ls ipfs pin rm ipfs pin update ipfs pin verify ipfs ping ipfs pubsub ipfs pubsub ls ipfs pubsub peers ipfs pubsub pub ipfs pubsub sub ipfs refs ipfs refs local ipfs repo ipfs repo fsck ipfs repo gc ipfs repo stat ipfs repo verify ipfs repo version ipfs resolve ipfs shutdown ipfs stats ipfs stats bitswap ipfs stats bw ipfs stats repo ipfs swarm ipfs swarm addrs ipfs swarm addrs listen ipfs swarm addrs local ipfs swarm connect ipfs swarm disconnect ipfs swarm filters ipfs swarm filters add ipfs swarm filters rm ipfs swarm peers ipfs tar ipfs tar add ipfs tar cat ipfs update ipfs version |
Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | 云栖社区 | OSChina 博客 | Facebook | Linkedin | 知乎专栏 | Github | Search | About
23.4. HTTP 网关
默认 IPFS 监听 127.0.0.1 使用下面命令启动IPFS守护进程,然后使用 nginx 代理 127.0.0.1
1 2 3 4 5 6 7 8 9 10 |
[ipfs@netkiller ~]$ ipfs daemon Initializing daemon... Swarm listening on /ip4/127.0.0.1/tcp/4001 Swarm listening on /ip4/172.31.180.30/tcp/4001 Swarm listening on /p2p-circuit/ipfs/QmZakCF5czhP53KPvMi8XQcYtVrQohw5N71Xce4eC1rWz3 Swarm announcing /ip4/127.0.0.1/tcp/4001 Swarm announcing /ip4/172.31.180.30/tcp/4001 API server listening on /ip4/127.0.0.1/tcp/5001 Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080 Daemon is ready |
23.4.1. 访问文件
1 2 3 |
[root@netkiller ~]# hash=$(cat /etc/centos-release | ipfs add -q) [root@netkiller ~]# curl "http://127.0.0.1:8080/ipfs/$hash" CentOS Linux release 7.4.1708 (Core) |
23.4.2. 配置代理服务器
Nginx 配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
server { listen 80 default_server; listen [::]:80 default_server; server_name _; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { proxy_pass http://127.0.0.1:8080; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } |
1 2 3 |
[root@netkiller ~]# hash=$(cat /etc/centos-release | ipfs add -q) [root@netkiller ~]# curl "http://localhost/ipfs/$hash" CentOS Linux release 7.4.1708 (Core) |
使用浏览器访问文件
http://localhost/ipfs/QmdoPoadYA5HYvSzgUrgXYdEVRNL1T7pY38GaWabZ3KLgn
1 |
ipfs.io 节点 |
1 2 3 |
[root@netkiller ~]# hash=$(cat /etc/centos-release | ipfs add -q) [root@netkiller ~]# curl "https://ipfs.io/ipfs/$hash" CentOS Linux release 7.4.1708 (Core) |
23.4.4. 监听地址
或者修改配置文件直接暴漏地址出去
1 2 3 4 5 6 7 8 |
[ipfs@netkiller ~]$ export EDITOR=/usr/bin/vim [ipfs@netkiller ~]$ ipfs config edit "API": "/ip4/127.0.0.1/tcp/5001", "Gateway": "/ip4/127.0.0.1/tcp/8080" "API": "/ip4/你的IP地址/tcp/5001", "Gateway": "/ip4/你的IP地址/tcp/8080" |
Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | 云栖社区 | OSChina 博客 | Facebook | Linkedin | 知乎专栏 | Github | Search | About
如果你远程访问 webui 会议都 403 问题,需要配置 IPFS 然后重启 ipfs daemon
1 2 3 4 5 |
ipfs config show ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "GET", "POST", "OPTIONS"]' ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]' ipfs config --json API.HTTPHeaders.Access-Control-Allow-Credentials '["true"]' ipfs config show |
修改后如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
"HTTPHeaders": { "Access-Control-Allow-Credentials": [ "true" ], "Access-Control-Allow-Methods": [ "PUT", "GET", "POST", "OPTIONS" ], "Access-Control-Allow-Origin": [ "*" ], "Server": [ "go-ipfs/0.4.14" ] } }, |
现在就可以访问 http://your_ip_address/webui 了
23.2. 安装 IPFS
23.2.1. go get 方式
23.2.2. 安装 ipfs-update
ipfs-update 是一个 ipfs 版本管理工具,可以通过这个工具安装ipfs 和升级 ipfs.
23.2.3. Ubuntu
23.2.4. Netkiller OSCM