├── 2017 └── 10 │ └── ipfs_first_post │ └── index.html ├── 404.html ├── README.md ├── blog ├── index.html └── index.xml ├── css ├── hyde.css ├── poole.css └── syntax.css ├── favicon.png ├── index.html ├── index.xml ├── qrcode_for_gh.jpg ├── sitemap.xml └── touch-icon-144-precomposed.png /2017/10/ipfs_first_post/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 【IPFS + 区块链 系列】 入门篇 - IPFS+IPNS+个人博客搭建 · 区块链部落 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 42 | 43 | 44 | 45 | 46 | 47 | 76 | 77 | 78 |
79 |
80 |

【IPFS + 区块链 系列】 入门篇 - IPFS+IPNS+个人博客搭建

81 | 82 | 83 | 84 | 85 |
86 |

孔壹学院:国内区块链职业教育引领品牌。

87 | 88 |

作者:黎跃春,孔壹学院创始人,区块链、高可用架构师

89 | 90 |

微信:liyc1215

91 | 92 |

区块链博客:http://liyuechun.org

93 |
94 | 95 |

在阅读这篇文章之前,你需要先学习【IPFS + 区块链 系列】 入门篇 - IPFS环境配置这篇文章。

96 | 97 |

目录

98 | 99 | 138 | 139 |

1. 如何在IPFS新增一个文件

140 | 141 |

1.1 新建file.txt文件

142 | 143 |

打开终端,切换到桌面,新建一个文件夹1121,切换到1121中,通过vi新建一个文件file.txt,文件里面输入春哥微信号liyc1215保存并且退出。

144 | 145 |
localhost:Desktop yuechunli$ pwd
146 | /Users/liyuechun/Desktop
147 | localhost:Desktop yuechunli$ mkdir 1121
148 | localhost:Desktop yuechunli$ cd 1121/
149 | localhost:1121 yuechunli$ vi file.txt
150 | localhost:1121 yuechunli$ cat file.txt
151 | liyc1215
152 | localhost:1121 yuechunli$
153 | 
154 | 155 |

1.2 查看ipfs相关命令

156 | 157 |
localhost:1121 yuechunli$ ipfs help
158 | USAGE
159 |   ipfs - Global p2p merkle-dag filesystem.
160 | 
161 |   ipfs [--config=<config> | -c] [--debug=<debug> | -D] [--help=<help>] [-h=<h>] [--local=<local> | -L] [--api=<api>] <command> ...
162 | 
163 | SUBCOMMANDS
164 |   BASIC COMMANDS
165 |     init          Initialize ipfs local configuration
166 |     add <path>    Add a file to IPFS
167 |     cat <ref>     Show IPFS object data
168 |     get <ref>     Download IPFS objects
169 |     ls <ref>      List links from an object
170 |     refs <ref>    List hashes of links from an object
171 | 
172 |   DATA STRUCTURE COMMANDS
173 |     block         Interact with raw blocks in the datastore
174 |     object        Interact with raw dag nodes
175 |     files         Interact with objects as if they were a unix filesystem
176 |     dag           Interact with IPLD documents (experimental)
177 | 
178 |   ADVANCED COMMANDS
179 |     daemon        Start a long-running daemon process
180 |     mount         Mount an IPFS read-only mountpoint
181 |     resolve       Resolve any type of name
182 |     name          Publish and resolve IPNS names
183 |     key           Create and list IPNS name keypairs
184 |     dns           Resolve DNS links
185 |     pin           Pin objects to local storage
186 |     repo          Manipulate the IPFS repository
187 |     stats         Various operational stats
188 |     p2p           Libp2p stream mounting
189 |     filestore     Manage the filestore (experimental)
190 | 
191 |   NETWORK COMMANDS
192 |     id            Show info about IPFS peers
193 |     bootstrap     Add or remove bootstrap peers
194 |     swarm         Manage connections to the p2p network
195 |     dht           Query the DHT for values or peers
196 |     ping          Measure the latency of a connection
197 |     diag          Print diagnostics
198 | 
199 |   TOOL COMMANDS
200 |     config        Manage configuration
201 |     version       Show ipfs version information
202 |     update        Download and apply go-ipfs updates
203 |     commands      List all available commands
204 | 
205 | 206 |

1.3 将file.txt添加到ipfs节点

207 | 208 |
localhost:1121 yuechunli$ ls
209 | file.txt
210 | localhost:1121 yuechunli$ ipfs add file.txt
211 | added QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T file.txt
212 | localhost:1121 yuechunli$ cat file.txt
213 | liyc1215
214 | localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T
215 | liyc1215
216 | localhost:1121 yuechunli$
217 | 
218 | 219 |

当执行完ipfs add file.txt这个命令以后,会将file.txt添加到ipfs当前的节点中,并且会对file.txt文件生成一个唯一的hashQmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T,如果想查看本地ipfs节点的数据,可以通过ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T进行查看。

220 | 221 |

⚠️:当我试图通过http://ipfs.io/ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T进行数据访问时,无法访问,如下图所示:

222 | 223 |

224 | 225 |

⚠️:虽然数据已经添加到当前的你自己的IPFS节点中,但是并没有同步到IPFS网络,所以暂时在网络上无法访问。

226 | 227 |

⚠️:重要:接下来执行下面的命令同步节点数据到IPFS网络,再试图在网络上查看数据。

228 | 229 | 232 | 233 |

新建一个终端,执行ipfs daemon

234 | 235 |
localhost:.ipfs yuechunli$ ipfs daemon
236 | Initializing daemon...
237 | Adjusting current ulimit to 2048...
238 | Successfully raised file descriptor limit to 2048.
239 | Swarm listening on /ip4/111.196.246.151/tcp/3637
240 | Swarm listening on /ip4/127.0.0.1/tcp/4001
241 | Swarm listening on /ip4/169.254.170.167/tcp/4001
242 | Swarm listening on /ip4/192.168.0.107/tcp/4001
243 | Swarm listening on /ip6/::1/tcp/4001
244 | API server listening on /ip4/127.0.0.1/tcp/5001
245 | Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
246 | Daemon is ready
247 | 
248 | 249 | 252 | 253 |

浏览器访问https://ipfs.io/ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T

254 | 255 |

黎跃春 微信

256 | 257 |

2. 通过ipfs创建目录存储文件

258 | 259 |

在着上面的步骤走,我们可以通过ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T 260 | liyc1215查看添加到ipfs网络的file.txt文件的内容,如下:

261 | 262 |
localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T
263 | liyc1215
264 | localhost:1121 yuechunli$
265 | 
266 | 267 |

当然,我们也可以通过ipfs的相关命令在ipfs的根目录下面创建文件夹,并且将file.txt文件移动或者拷贝到我们创建的文件夹中。

268 | 269 |

⚠️:cp不会改变文件hash,mv会改变hash寻址。

270 | 271 |
localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T
272 | liyc1215
273 | localhost:1121 yuechunli$ ipfs files mkdir /LiYueChun
274 | localhost:1121 yuechunli$ ipfs files cp /ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T /LiYueChun/file.txt
275 | localhost:1121 yuechunli$ ipfs files ls /
276 | LiYueChun
277 | localhost:1121 yuechunli$ ipfs files ls /LiYueChun/
278 | file.txt
279 | localhost:1121 yuechunli$ ipfs files read /LiYueChun/file.txt
280 | liyc1215
281 | localhost:1121 yuechunli$
282 | 
283 | 284 |

3. 如何在IPFS新增一个目录

285 | 286 |

3.1 使用ipfs add -r可以上传一整个目录

287 | 288 |
localhost:1121 yuechunli$ ipfs add -r ipfs-tutorial/
289 | added QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc ipfs-tutorial/contactme.txt
290 | added QmfKdWsguobA3aDPvSxLB3Bq4HMKyqKSgFr2NFUuVH8n31 ipfs-tutorial/eth-fabric.png
291 | added QmXe8jTxTh5MZP6BK5cnj19mXNTKVMzNyUJZUHuYyr5dk1 ipfs-tutorial/gongzhonghao.png
292 | added QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek ipfs-tutorial
293 | 
294 | 295 |

3.2 通过路径访问contactme.txt文件数据

296 | 297 |

如果我们上传的是目录,那么可以通过下面几种方式访问到contactme.txt文件的数据。

298 | 299 |
localhost:1121 yuechunli$ ipfs cat QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc
300 | 微信:liyc1215
301 | 区块链技术交流群:348924182
302 | 公众号:区块链部落
303 | localhost:1121 yuechunli$ ipfs cat /ipfs/QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc
304 | 微信:liyc1215
305 | 区块链技术交流群:348924182
306 | 公众号:区块链部落
307 | localhost:1121 yuechunli$ ipfs cat /ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek/contactme.txt
308 | 微信:liyc1215
309 | 区块链技术交流群:348924182
310 | 公众号:区块链部落
311 | localhost:1121 yuechunli$
312 | 
313 | 314 |

3.3 通过Hash查看数据IPFS网络数据

315 | 316 | 319 | 320 |

321 | 322 | 328 | 329 |

330 | 331 |

4. 创建简易的网页发布到IPFS

332 | 333 |

在这里我先自己写一个简单的网页给大家演示,先在桌面新建一个site文件夹,然后按照下面的步骤在site文件夹中建立index.htmlstyle.css文件。

334 | 335 |

4.1 创建一个index.html文件

336 | 337 |
<!DOCTYPE html>
338 | <html lang="en">
339 | <head>
340 |   <meta charset="UTF-8">
341 |   <title>Hello IPFS!</title>
342 |   <link rel="stylesheet" href="./style.css" />
343 | </head>
344 | <body>
345 |   <h1>Hello IPFS!</h1>
346 | </body>
347 | </html>
348 | 
349 | 350 |

4.2 创建一个style.css文件

351 | 352 |
h1 {
353 |   color: green;
354 | }
355 | 
356 | 357 |

4.3 添加到ipfs

358 | 359 |
localhost:Desktop yuechunli$ ipfs add -r site/
360 | added QmWG5rbgT9H77TGq49RXNoqN8M7DNKMnMX425nkmCB6BjS site/index.html
361 | added QmfGLJ3mryLvicQqzdsghq4QRhptKJtBAPe7yDJxsBGSuy site/style.css
362 | added QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp site
363 | 
364 | 365 |

最后一行是项目根目录的hash,你先通过ipfs daemon同步网络,然后可以通过https://ipfs.io/ipfs/<你的项目根目录hash>,即https://ipfs.io/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp访问项目。

366 | 367 |

4.4 网络同步

368 | 369 |
localhost:Desktop yuechunli$ ipfs daemon
370 | 
371 | 372 |

4.5 访问网站

373 | 374 |

浏览器打开https://ipfs.io/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp,效果图如下:

375 | 376 |

377 | 378 |

4.6 发布到IPNS

379 | 380 |

当我们修改网站内容重新添加到ipfs时,hash会发生变化,当我们网站更新时,我们可以将网站发布到IPNS,在IPNS中,允许我们节点的域名空间中引用一个IPFS hash,也就是说我们可以通过节点ID对项目根目录的IPFS HASH进行绑定,以后我们访问网站时直接通过节点·ID访问即可,当我们更新博客时,重新发布到IPNS`即可。

381 | 382 |
localhost:~ yuechunli$ ipfs name publish QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp
383 | Published to QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP: /ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp
384 | localhost:~ yuechunli$ ipfs id
385 | {
386 | 	"ID": "QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP"
387 | }
388 | 
389 | 390 |

当我们执行ipfs name publish命令时,会返回我们的节点ID,你可以通过ipfs id进行查看验证是否是你的节点ID

391 | 392 |

⚠️:验证

393 | 394 |
$ ipfs name resolve <peerId>
395 | 
396 | 397 |
localhost:~ yuechunli$ ipfs name resolve QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP
398 | /ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp
399 | localhost:~ yuechunli$
400 | 
401 | 402 |

⚠️:当然我们现在就可以通过IPNS进行访问了。

403 | 404 |
https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP
405 | 
406 | 407 |

⚠️⚠️⚠️:注意上面是ipns而不是ipfs。

408 | 409 |

410 | 411 |

⚠️:如果你网站数据修改,需要重新发布到IPNS。

412 | 413 |

5. 发布个人博客

414 | 415 |

你可以通过Hugo按照官方文档创建一个漂亮的静态博客Hugo官方网站,当然你也可以自己编写,或者使用其他开源项目搭建。

416 | 417 |

5.1 搭建静态博客

418 | 419 |

大家可以自己搭建,也可以直接下载我的博客源码直接搭建。

420 | 421 |

源码地址:http://github.com/liyuechun/ipfs_blogger

422 | 423 |

5.2 节点ID替换

424 | 425 | 428 | 429 |
localhost:ipfs_pin yuechunli$ ipfs id
430 | {
431 | 	"ID": "《your peer id》"
432 | }
433 | localhost:ipfs_pin yuechunli$
434 | 
435 | 436 |

在上面的源码中全局搜索将源码里面的QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP替换成你自己的ID

437 | 438 |

接下来重复4. 创建简易的网页发布到IPFS的操作步骤即可。

439 | 440 |

5.3 浏览博客

441 | 442 |

浏览器打开https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/查看项目效果。

443 | 444 |

IPFS 博客项目效果图

445 | 446 |

6. 下篇预报

447 | 448 |

6.1 ipfs + ethereumDapp开发入门

449 | 450 |

7. 技术交流

451 | 452 | 457 | 458 |

459 | 460 | 461 | 462 | 463 | 464 |
465 | 479 | 480 |
481 |
482 | 483 | w 484 | 485 | -------------------------------------------------------------------------------- /404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Nope. 4 | 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 【IPFS + 区块链 系列】 入门篇 - IPFS+IPNS+个人博客搭建 2 | 3 | > 孔壹学院:国内区块链职业教育引领品牌。 4 | > 5 | > 作者:黎跃春,孔壹学院创始人,区块链、高可用架构师 6 | > 7 | > 微信:liyc1215 8 | > 9 | > 区块链博客:http://liyuechun.org 10 | 11 | 在阅读这篇文章之前,你需要先学习[【IPFS + 区块链 系列】 入门篇 - IPFS环境配置](http://liyuechun.org/2017/11/20/ipfs-blockchain/)这篇文章。 12 | 13 | ## 目录 14 | 15 | 16 | - [1. 如何在IPFS新增一个文件](#1-如何在IPFS新增一个文件) 17 | - [1.1 新建file.txt文件](#11-新建file.txt文件) 18 | - [1.2 查看ipfs相关命令](#12-查看ipfs相关命令) 19 | - [1.3 将file.txt添加到ipfs节点](#13-将file.txt添加到ipfs节点) 20 | - [2. 通过ipfs创建目录存储文件](#2-通过ipfs创建目录存储文件) 21 | - [3. 如何在IPFS新增一个目录](#3-如何在IPFS新增一个目录) 22 | - [3.1 使用ipfs add -r可以上传一整个目录](#31-使用ipfs add -r可以上传一整个目录) 23 | - [3.2 通过路径访问contactme.txt文件数据](#32-通过路径访问contactme.txt文件数据) 24 | - [3.3 通过Hash查看数据IPFS网络数据](#33-通过Hash查看数据IPFS网络数据) 25 | - [4. 创建简易的网页发布到IPFS](#4-创建简易的网页发布到IPFS) 26 | - [4.1 创建一个index.html文件](#41-创建一个index.html文件) 27 | - [4.2 创建一个style.css文件](#42-创建一个style.css文件) 28 | - [4.3 添加到ipfs](#43-添加到ipfs) 29 | - [4.4 网络同步](#44-网络同步) 30 | - [4.5 访问网站](#45-访问网站) 31 | - [4.6 发布到IPNS](#46-发布到IPNS) 32 | - [5. 发布个人博客](#5-发布个人博客) 33 | - [5.1 搭建静态博客](#51-搭建静态博客) 34 | - [5.2 节点ID替换](#52-节点ID替换) 35 | - [5.3 浏览博客](#53-浏览博客) 36 | - [6. 下篇预报](#6-下篇预报) 37 | - [6.1 `ipfs + ethereum``Dapp`开发入门](#61-`ipfs + ethereum``Dapp`开发入门) 38 | 39 | 40 | ## 1. 如何在IPFS新增一个文件 41 | 42 | ### 1.1 新建file.txt文件 43 | 44 | 打开终端,切换到桌面,新建一个文件夹`1121`,切换到`1121`中,通过`vi`新建一个文件`file.txt`,文件里面输入春哥微信号`liyc1215`保存并且退出。 45 | 46 | ``` 47 | localhost:Desktop yuechunli$ pwd 48 | /Users/liyuechun/Desktop 49 | localhost:Desktop yuechunli$ mkdir 1121 50 | localhost:Desktop yuechunli$ cd 1121/ 51 | localhost:1121 yuechunli$ vi file.txt 52 | localhost:1121 yuechunli$ cat file.txt 53 | liyc1215 54 | localhost:1121 yuechunli$ 55 | ``` 56 | 57 | ### 1.2 查看ipfs相关命令 58 | 59 | ``` 60 | localhost:1121 yuechunli$ ipfs help 61 | USAGE 62 | ipfs - Global p2p merkle-dag filesystem. 63 | 64 | ipfs [--config= | -c] [--debug= | -D] [--help=] [-h=] [--local= | -L] [--api=] ... 65 | 66 | SUBCOMMANDS 67 | BASIC COMMANDS 68 | init Initialize ipfs local configuration 69 | add Add a file to IPFS 70 | cat Show IPFS object data 71 | get Download IPFS objects 72 | ls List links from an object 73 | refs List hashes of links from an object 74 | 75 | DATA STRUCTURE COMMANDS 76 | block Interact with raw blocks in the datastore 77 | object Interact with raw dag nodes 78 | files Interact with objects as if they were a unix filesystem 79 | dag Interact with IPLD documents (experimental) 80 | 81 | ADVANCED COMMANDS 82 | daemon Start a long-running daemon process 83 | mount Mount an IPFS read-only mountpoint 84 | resolve Resolve any type of name 85 | name Publish and resolve IPNS names 86 | key Create and list IPNS name keypairs 87 | dns Resolve DNS links 88 | pin Pin objects to local storage 89 | repo Manipulate the IPFS repository 90 | stats Various operational stats 91 | p2p Libp2p stream mounting 92 | filestore Manage the filestore (experimental) 93 | 94 | NETWORK COMMANDS 95 | id Show info about IPFS peers 96 | bootstrap Add or remove bootstrap peers 97 | swarm Manage connections to the p2p network 98 | dht Query the DHT for values or peers 99 | ping Measure the latency of a connection 100 | diag Print diagnostics 101 | 102 | TOOL COMMANDS 103 | config Manage configuration 104 | version Show ipfs version information 105 | update Download and apply go-ipfs updates 106 | commands List all available commands 107 | ``` 108 | 109 | ### 1.3 将file.txt添加到ipfs节点 110 | 111 | ``` 112 | localhost:1121 yuechunli$ ls 113 | file.txt 114 | localhost:1121 yuechunli$ ipfs add file.txt 115 | added QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T file.txt 116 | localhost:1121 yuechunli$ cat file.txt 117 | liyc1215 118 | localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T 119 | liyc1215 120 | localhost:1121 yuechunli$ 121 | ``` 122 | 123 | 当执行完`ipfs add file.txt`这个命令以后,会将`file.txt`添加到`ipfs`当前的节点中,并且会对`file.txt`文件生成一个唯一的`hash``QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T`,如果想查看本地`ipfs`节点的数据,可以通过`ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T`进行查看。 124 | 125 | **⚠️:**当我试图通过`http://ipfs.io/ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T`进行数据访问时,无法访问,如下图所示: 126 | 127 | ![](http://om1c35wrq.bkt.clouddn.com/fangwen.gif) 128 | 129 | **⚠️:**虽然数据已经添加到当前的你自己的`IPFS`节点中,但是并没有同步到`IPFS`网络,所以暂时在网络上无法访问。 130 | 131 | **⚠️:重要:接下来执行下面的命令同步节点数据到`IPFS`网络,再试图在网络上查看数据。** 132 | 133 | - 同步节点 134 | 135 | 新建一个终端,执行`ipfs daemon`。 136 | 137 | ``` 138 | localhost:.ipfs yuechunli$ ipfs daemon 139 | Initializing daemon... 140 | Adjusting current ulimit to 2048... 141 | Successfully raised file descriptor limit to 2048. 142 | Swarm listening on /ip4/111.196.246.151/tcp/3637 143 | Swarm listening on /ip4/127.0.0.1/tcp/4001 144 | Swarm listening on /ip4/169.254.170.167/tcp/4001 145 | Swarm listening on /ip4/192.168.0.107/tcp/4001 146 | Swarm listening on /ip6/::1/tcp/4001 147 | API server listening on /ip4/127.0.0.1/tcp/5001 148 | Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080 149 | Daemon is ready 150 | ``` 151 | 152 | - 从`IPFS`网络查看数据 153 | 154 | 浏览器访问[https://ipfs.io/ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T](https://ipfs.io/ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T) 155 | 156 | ![黎跃春 微信](http://om1c35wrq.bkt.clouddn.com/WX20171121-105531@2x.png) 157 | 158 | 159 | ## 2. 通过ipfs创建目录存储文件 160 | 161 | 在着上面的步骤走,我们可以通过`ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T 162 | liyc1215`查看添加到`ipfs`网络的`file.txt`文件的内容,如下: 163 | 164 | ``` 165 | localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T 166 | liyc1215 167 | localhost:1121 yuechunli$ 168 | ``` 169 | 170 | 当然,我们也可以通过`ipfs`的相关命令在`ipfs`的根目录下面创建文件夹,并且将`file.txt`文件**移动**或者**拷贝**到我们创建的文件夹中。 171 | 172 | **⚠️:cp不会改变文件hash,mv会改变hash寻址。** 173 | 174 | ``` 175 | localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T 176 | liyc1215 177 | localhost:1121 yuechunli$ ipfs files mkdir /LiYueChun 178 | localhost:1121 yuechunli$ ipfs files cp /ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T /LiYueChun/file.txt 179 | localhost:1121 yuechunli$ ipfs files ls / 180 | LiYueChun 181 | localhost:1121 yuechunli$ ipfs files ls /LiYueChun/ 182 | file.txt 183 | localhost:1121 yuechunli$ ipfs files read /LiYueChun/file.txt 184 | liyc1215 185 | localhost:1121 yuechunli$ 186 | ``` 187 | 188 | 189 | 190 | ## 3. 如何在IPFS新增一个目录 191 | 192 | ### 3.1 使用ipfs add -r可以上传一整个目录 193 | 194 | ``` 195 | localhost:1121 yuechunli$ ipfs add -r ipfs-tutorial/ 196 | added QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc ipfs-tutorial/contactme.txt 197 | added QmfKdWsguobA3aDPvSxLB3Bq4HMKyqKSgFr2NFUuVH8n31 ipfs-tutorial/eth-fabric.png 198 | added QmXe8jTxTh5MZP6BK5cnj19mXNTKVMzNyUJZUHuYyr5dk1 ipfs-tutorial/gongzhonghao.png 199 | added QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek ipfs-tutorial 200 | ``` 201 | 202 | #### 3.2 通过路径访问contactme.txt文件数据 203 | 204 | 如果我们上传的是目录,那么可以通过下面几种方式访问到`contactme.txt`文件的数据。 205 | 206 | ``` 207 | localhost:1121 yuechunli$ ipfs cat QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc 208 | 微信:liyc1215 209 | 区块链技术交流群:348924182 210 | 公众号:区块链部落 211 | localhost:1121 yuechunli$ ipfs cat /ipfs/QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc 212 | 微信:liyc1215 213 | 区块链技术交流群:348924182 214 | 公众号:区块链部落 215 | localhost:1121 yuechunli$ ipfs cat /ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek/contactme.txt 216 | 微信:liyc1215 217 | 区块链技术交流群:348924182 218 | 公众号:区块链部落 219 | localhost:1121 yuechunli$ 220 | ``` 221 | 222 | ### 3.3 通过Hash查看数据IPFS网络数据 223 | 224 | - **访问目录:**[https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek](https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek) 225 | 226 | ![](http://om1c35wrq.bkt.clouddn.com/WX20171121-110959@2x.png) 227 | 228 | - **通过目录访问文件:**[https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek/contactme.txt](https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek/contactme.txt) 229 | ![](http://om1c35wrq.bkt.clouddn.com/WX20171121-111019@2x.png) 230 | 231 | - **通过文件hash直接访问:**[https://ipfs.io/ipfs/QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc](https://ipfs.io/ipfs/QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc) 232 | 233 | ![](http://om1c35wrq.bkt.clouddn.com/WX20171121-113047@2x.png) 234 | 235 | 236 | ## 4. 创建简易的网页发布到IPFS 237 | 238 | 239 | 在这里我先自己写一个简单的网页给大家演示,先在桌面新建一个`site`文件夹,然后按照下面的步骤在`site`文件夹中建立`index.html`和`style.css`文件。 240 | 241 | ### 4.1 创建一个index.html文件 242 | 243 | ``` 244 | 245 | 246 | 247 | 248 | Hello IPFS! 249 | 250 | 251 | 252 |

Hello IPFS!

253 | 254 | 255 | ``` 256 | 257 | ### 4.2 创建一个style.css文件 258 | 259 | ``` 260 | h1 { 261 | color: green; 262 | } 263 | ``` 264 | 265 | ### 4.3 添加到ipfs 266 | 267 | ``` 268 | localhost:Desktop yuechunli$ ipfs add -r site/ 269 | added QmWG5rbgT9H77TGq49RXNoqN8M7DNKMnMX425nkmCB6BjS site/index.html 270 | added QmfGLJ3mryLvicQqzdsghq4QRhptKJtBAPe7yDJxsBGSuy site/style.css 271 | added QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp site 272 | ``` 273 | 274 | 最后一行是项目根目录的`hash`,你先通过`ipfs daemon`同步网络,然后可以通过`https://ipfs.io/ipfs/<你的项目根目录hash>`,即`https://ipfs.io/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp`访问项目。 275 | 276 | ### 4.4 网络同步 277 | 278 | ``` 279 | localhost:Desktop yuechunli$ ipfs daemon 280 | ``` 281 | 282 | ### 4.5 访问网站 283 | 284 | 浏览器打开[https://ipfs.io/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp](https://ipfs.io/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp),效果图如下: 285 | 286 | ![](http://om1c35wrq.bkt.clouddn.com/WX20171121-210721@2x.png) 287 | 288 | ### 4.6 发布到IPNS 289 | 290 | 当我们修改网站内容重新添加到`ipfs`时,`hash`会发生变化,当我们网站更新时,我们可以将网站发布到IPNS,在IPNS中,允许我们节点的域名空间中引用一个`IPFS hash`,也就是说我们可以通过节点`ID`对项目根目录的`IPFS HASH`进行绑定,以后我们访问网站时直接通过节点·ID`访问即可,当我们更新博客时,重新发布到`IPNS`即可。 291 | 292 | ``` 293 | localhost:~ yuechunli$ ipfs name publish QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp 294 | Published to QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP: /ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp 295 | localhost:~ yuechunli$ ipfs id 296 | { 297 | "ID": "QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP" 298 | } 299 | ``` 300 | 301 | 当我们执行`ipfs name publish`命令时,会返回我们的节点`ID`,你可以通过`ipfs id`进行查看验证是否是你的节点`ID`。 302 | 303 | **⚠️:验证** 304 | 305 | ``` 306 | $ ipfs name resolve 307 | ``` 308 | 309 | ``` 310 | localhost:~ yuechunli$ ipfs name resolve QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP 311 | /ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp 312 | localhost:~ yuechunli$ 313 | ``` 314 | 315 | **⚠️:**当然我们现在就可以通过`IPNS`进行访问了。 316 | 317 | ``` 318 | https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP 319 | ``` 320 | 321 | **⚠️⚠️⚠️:注意上面是ipns而不是ipfs。** 322 | 323 | ![](http://om1c35wrq.bkt.clouddn.com/WX20171121-212123@2x.png) 324 | 325 | 326 | **⚠️:如果你网站数据修改,需要重新发布到IPNS。** 327 | 328 | ## 5. 发布个人博客 329 | 330 | 你可以通过`Hugo`按照官方文档创建一个漂亮的静态博客[Hugo官方网站](http://gohugo.io/getting-started/quick-start/),当然你也可以自己编写,或者使用其他开源项目搭建。 331 | 332 | ### 5.1 搭建静态博客 333 | 334 | 大家可以自己搭建,也可以直接下载我的博客源码直接搭建。 335 | 336 | 源码地址:[http://github.com/liyuechun/ipfs_blogger](http://github.com/liyuechun/ipfs_blogger) 337 | 338 | 339 | ### 5.2 节点ID替换 340 | 341 | - 查看你的节点ID 342 | 343 | ``` 344 | localhost:ipfs_pin yuechunli$ ipfs id 345 | { 346 | "ID": "《your peer id》" 347 | } 348 | localhost:ipfs_pin yuechunli$ 349 | ``` 350 | 351 | 在上面的源码中全局搜索将源码里面的`QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP`替换成你自己的`ID`。 352 | 353 | 接下来重复[4. 创建简易的网页发布到IPFS](#4-创建简易的网页发布到IPFS)的操作步骤即可。 354 | 355 | ### 5.3 浏览博客 356 | 357 | 浏览器打开[https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/](https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/)查看项目效果。 358 | 359 | ![IPFS 博客项目效果图](http://om1c35wrq.bkt.clouddn.com/WX20171121-215636@2x.png) 360 | 361 | ## 6. 下篇预报 362 | 363 | ### 6.1 `ipfs + ethereum``Dapp`开发入门 364 | 365 | ## 7. 技术交流 366 | 367 | - 区块链技术交流QQ群:`348924182` 368 | - 进微信群请加微信:`liyc1215` 369 | - 「区块链部落」官方公众号 370 | 371 | ![](http://om1c35wrq.bkt.clouddn.com/%E5%8C%BA%E5%9D%97%E9%93%BE%E9%83%A8%E8%90%BD.png) 372 | 373 | 374 | -------------------------------------------------------------------------------- /blog/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Blogs · 区块链部落 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 42 | 43 | 44 | 45 | 46 | 47 | 76 | 77 | 78 |
79 |

Blog Posts

80 | 85 |
86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /blog/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 区块链部落 5 | Hugo 6 | https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/blog/ 7 | en-us 8 | 黎跃春 9 | 2017 liyuechun 10 | Mon, 30 Oct 2017 20:01:00 UTC 11 | 12 | 13 | 14 | 【IPFS + 区块链 系列】 入门篇 - IPFS+IPNS+个人博客搭建 15 | https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/2017/10/ipfs_first_post/ 16 | Mon, 30 Oct 2017 20:01:00 UTC 17 | 黎跃春 18 | https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/2017/10/ipfs_first_post/ 19 | 20 | 21 | <blockquote> 22 | <p>孔壹学院:国内区块链职业教育引领品牌。</p> 23 | 24 | <p>作者:黎跃春,孔壹学院创始人,区块链、高可用架构师</p> 25 | 26 | <p>微信:liyc1215</p> 27 | 28 | <p>区块链博客:<a href="http://liyuechun.org">http://liyuechun.org</a></p> 29 | </blockquote> 30 | 31 | <p>在阅读这篇文章之前,你需要先学习<a href="http://liyuechun.org/2017/11/20/ipfs-blockchain/">【IPFS + 区块链 系列】 入门篇 - IPFS环境配置</a>这篇文章。</p> 32 | 33 | <h2 id="目录">目录</h2> 34 | 35 | <ul> 36 | <li><a href="#1-如何在IPFS新增一个文件">1. 如何在IPFS新增一个文件</a> 37 | 38 | <ul> 39 | <li><a href="#11-新建file.txt文件">1.1 新建file.txt文件</a></li> 40 | <li><a href="#12-查看ipfs相关命令">1.2 查看ipfs相关命令</a></li> 41 | <li><a href="#13-将file.txt添加到ipfs节点">1.3 将file.txt添加到ipfs节点</a></li> 42 | </ul></li> 43 | <li><a href="#2-通过ipfs创建目录存储文件">2. 通过ipfs创建目录存储文件</a></li> 44 | <li><a href="#3-如何在IPFS新增一个目录">3. 如何在IPFS新增一个目录</a> 45 | 46 | <ul> 47 | <li><a href="#31-使用ipfs add -r可以上传一整个目录">3.1 使用ipfs add -r可以上传一整个目录</a></li> 48 | <li><a href="#32-通过路径访问contactme.txt文件数据">3.2 通过路径访问contactme.txt文件数据</a></li> 49 | <li><a href="#33-通过Hash查看数据IPFS网络数据">3.3 通过Hash查看数据IPFS网络数据</a></li> 50 | </ul></li> 51 | <li><a href="#4-创建简易的网页发布到IPFS">4. 创建简易的网页发布到IPFS</a> 52 | 53 | <ul> 54 | <li><a href="#41-创建一个index.html文件">4.1 创建一个index.html文件</a></li> 55 | <li><a href="#42-创建一个style.css文件">4.2 创建一个style.css文件</a></li> 56 | <li><a href="#43-添加到ipfs">4.3 添加到ipfs</a></li> 57 | <li><a href="#44-网络同步">4.4 网络同步</a></li> 58 | <li><a href="#45-访问网站">4.5 访问网站</a></li> 59 | <li><a href="#46-发布到IPNS">4.6 发布到IPNS</a></li> 60 | </ul></li> 61 | <li><a href="#5-发布个人博客">5. 发布个人博客</a> 62 | 63 | <ul> 64 | <li><a href="#51-搭建静态博客">5.1 搭建静态博客</a></li> 65 | <li><a href="#52-节点ID替换">5.2 节点ID替换</a></li> 66 | <li><a href="#53-浏览博客">5.3 浏览博客</a></li> 67 | </ul></li> 68 | <li><a href="#6-下篇预报">6. 下篇预报</a> 69 | 70 | <ul> 71 | <li><a href="#61-`ipfs + ethereum``Dapp`开发入门">6.1 <code>ipfs + ethereum</code><code>Dapp</code>开发入门</a></li> 72 | </ul></li> 73 | </ul> 74 | 75 | <h2 id="1-如何在ipfs新增一个文件">1. 如何在IPFS新增一个文件</h2> 76 | 77 | <h3 id="1-1-新建file-txt文件">1.1 新建file.txt文件</h3> 78 | 79 | <p>打开终端,切换到桌面,新建一个文件夹<code>1121</code>,切换到<code>1121</code>中,通过<code>vi</code>新建一个文件<code>file.txt</code>,文件里面输入春哥微信号<code>liyc1215</code>保存并且退出。</p> 80 | 81 | <pre><code>localhost:Desktop yuechunli$ pwd 82 | /Users/liyuechun/Desktop 83 | localhost:Desktop yuechunli$ mkdir 1121 84 | localhost:Desktop yuechunli$ cd 1121/ 85 | localhost:1121 yuechunli$ vi file.txt 86 | localhost:1121 yuechunli$ cat file.txt 87 | liyc1215 88 | localhost:1121 yuechunli$ 89 | </code></pre> 90 | 91 | <h3 id="1-2-查看ipfs相关命令">1.2 查看ipfs相关命令</h3> 92 | 93 | <pre><code>localhost:1121 yuechunli$ ipfs help 94 | USAGE 95 | ipfs - Global p2p merkle-dag filesystem. 96 | 97 | ipfs [--config=&lt;config&gt; | -c] [--debug=&lt;debug&gt; | -D] [--help=&lt;help&gt;] [-h=&lt;h&gt;] [--local=&lt;local&gt; | -L] [--api=&lt;api&gt;] &lt;command&gt; ... 98 | 99 | SUBCOMMANDS 100 | BASIC COMMANDS 101 | init Initialize ipfs local configuration 102 | add &lt;path&gt; Add a file to IPFS 103 | cat &lt;ref&gt; Show IPFS object data 104 | get &lt;ref&gt; Download IPFS objects 105 | ls &lt;ref&gt; List links from an object 106 | refs &lt;ref&gt; List hashes of links from an object 107 | 108 | DATA STRUCTURE COMMANDS 109 | block Interact with raw blocks in the datastore 110 | object Interact with raw dag nodes 111 | files Interact with objects as if they were a unix filesystem 112 | dag Interact with IPLD documents (experimental) 113 | 114 | ADVANCED COMMANDS 115 | daemon Start a long-running daemon process 116 | mount Mount an IPFS read-only mountpoint 117 | resolve Resolve any type of name 118 | name Publish and resolve IPNS names 119 | key Create and list IPNS name keypairs 120 | dns Resolve DNS links 121 | pin Pin objects to local storage 122 | repo Manipulate the IPFS repository 123 | stats Various operational stats 124 | p2p Libp2p stream mounting 125 | filestore Manage the filestore (experimental) 126 | 127 | NETWORK COMMANDS 128 | id Show info about IPFS peers 129 | bootstrap Add or remove bootstrap peers 130 | swarm Manage connections to the p2p network 131 | dht Query the DHT for values or peers 132 | ping Measure the latency of a connection 133 | diag Print diagnostics 134 | 135 | TOOL COMMANDS 136 | config Manage configuration 137 | version Show ipfs version information 138 | update Download and apply go-ipfs updates 139 | commands List all available commands 140 | </code></pre> 141 | 142 | <h3 id="1-3-将file-txt添加到ipfs节点">1.3 将file.txt添加到ipfs节点</h3> 143 | 144 | <pre><code>localhost:1121 yuechunli$ ls 145 | file.txt 146 | localhost:1121 yuechunli$ ipfs add file.txt 147 | added QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T file.txt 148 | localhost:1121 yuechunli$ cat file.txt 149 | liyc1215 150 | localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T 151 | liyc1215 152 | localhost:1121 yuechunli$ 153 | </code></pre> 154 | 155 | <p>当执行完<code>ipfs add file.txt</code>这个命令以后,会将<code>file.txt</code>添加到<code>ipfs</code>当前的节点中,并且会对<code>file.txt</code>文件生成一个唯一的<code>hash</code><code>QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T</code>,如果想查看本地<code>ipfs</code>节点的数据,可以通过<code>ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T</code>进行查看。</p> 156 | 157 | <p><strong>⚠️:</strong>当我试图通过<code>http://ipfs.io/ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T</code>进行数据访问时,无法访问,如下图所示:</p> 158 | 159 | <p><img src="http://om1c35wrq.bkt.clouddn.com/fangwen.gif" alt="" /></p> 160 | 161 | <p><strong>⚠️:</strong>虽然数据已经添加到当前的你自己的<code>IPFS</code>节点中,但是并没有同步到<code>IPFS</code>网络,所以暂时在网络上无法访问。</p> 162 | 163 | <p><strong>⚠️:重要:接下来执行下面的命令同步节点数据到<code>IPFS</code>网络,再试图在网络上查看数据。</strong></p> 164 | 165 | <ul> 166 | <li>同步节点</li> 167 | </ul> 168 | 169 | <p>新建一个终端,执行<code>ipfs daemon</code>。</p> 170 | 171 | <pre><code>localhost:.ipfs yuechunli$ ipfs daemon 172 | Initializing daemon... 173 | Adjusting current ulimit to 2048... 174 | Successfully raised file descriptor limit to 2048. 175 | Swarm listening on /ip4/111.196.246.151/tcp/3637 176 | Swarm listening on /ip4/127.0.0.1/tcp/4001 177 | Swarm listening on /ip4/169.254.170.167/tcp/4001 178 | Swarm listening on /ip4/192.168.0.107/tcp/4001 179 | Swarm listening on /ip6/::1/tcp/4001 180 | API server listening on /ip4/127.0.0.1/tcp/5001 181 | Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080 182 | Daemon is ready 183 | </code></pre> 184 | 185 | <ul> 186 | <li>从<code>IPFS</code>网络查看数据</li> 187 | </ul> 188 | 189 | <p>浏览器访问<a href="https://ipfs.io/ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T">https://ipfs.io/ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T</a></p> 190 | 191 | <p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-105531@2x.png" alt="黎跃春 微信" /></p> 192 | 193 | <h2 id="2-通过ipfs创建目录存储文件">2. 通过ipfs创建目录存储文件</h2> 194 | 195 | <p>在着上面的步骤走,我们可以通过<code>ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T 196 | liyc1215</code>查看添加到<code>ipfs</code>网络的<code>file.txt</code>文件的内容,如下:</p> 197 | 198 | <pre><code>localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T 199 | liyc1215 200 | localhost:1121 yuechunli$ 201 | </code></pre> 202 | 203 | <p>当然,我们也可以通过<code>ipfs</code>的相关命令在<code>ipfs</code>的根目录下面创建文件夹,并且将<code>file.txt</code>文件<strong>移动</strong>或者<strong>拷贝</strong>到我们创建的文件夹中。</p> 204 | 205 | <p><strong>⚠️:cp不会改变文件hash,mv会改变hash寻址。</strong></p> 206 | 207 | <pre><code>localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T 208 | liyc1215 209 | localhost:1121 yuechunli$ ipfs files mkdir /LiYueChun 210 | localhost:1121 yuechunli$ ipfs files cp /ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T /LiYueChun/file.txt 211 | localhost:1121 yuechunli$ ipfs files ls / 212 | LiYueChun 213 | localhost:1121 yuechunli$ ipfs files ls /LiYueChun/ 214 | file.txt 215 | localhost:1121 yuechunli$ ipfs files read /LiYueChun/file.txt 216 | liyc1215 217 | localhost:1121 yuechunli$ 218 | </code></pre> 219 | 220 | <h2 id="3-如何在ipfs新增一个目录">3. 如何在IPFS新增一个目录</h2> 221 | 222 | <h3 id="3-1-使用ipfs-add-r可以上传一整个目录">3.1 使用ipfs add -r可以上传一整个目录</h3> 223 | 224 | <pre><code>localhost:1121 yuechunli$ ipfs add -r ipfs-tutorial/ 225 | added QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc ipfs-tutorial/contactme.txt 226 | added QmfKdWsguobA3aDPvSxLB3Bq4HMKyqKSgFr2NFUuVH8n31 ipfs-tutorial/eth-fabric.png 227 | added QmXe8jTxTh5MZP6BK5cnj19mXNTKVMzNyUJZUHuYyr5dk1 ipfs-tutorial/gongzhonghao.png 228 | added QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek ipfs-tutorial 229 | </code></pre> 230 | 231 | <h4 id="3-2-通过路径访问contactme-txt文件数据">3.2 通过路径访问contactme.txt文件数据</h4> 232 | 233 | <p>如果我们上传的是目录,那么可以通过下面几种方式访问到<code>contactme.txt</code>文件的数据。</p> 234 | 235 | <pre><code>localhost:1121 yuechunli$ ipfs cat QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc 236 | 微信:liyc1215 237 | 区块链技术交流群:348924182 238 | 公众号:区块链部落 239 | localhost:1121 yuechunli$ ipfs cat /ipfs/QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc 240 | 微信:liyc1215 241 | 区块链技术交流群:348924182 242 | 公众号:区块链部落 243 | localhost:1121 yuechunli$ ipfs cat /ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek/contactme.txt 244 | 微信:liyc1215 245 | 区块链技术交流群:348924182 246 | 公众号:区块链部落 247 | localhost:1121 yuechunli$ 248 | </code></pre> 249 | 250 | <h3 id="3-3-通过hash查看数据ipfs网络数据">3.3 通过Hash查看数据IPFS网络数据</h3> 251 | 252 | <ul> 253 | <li><strong>访问目录:</strong><a href="https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek">https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek</a></li> 254 | </ul> 255 | 256 | <p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-110959@2x.png" alt="" /></p> 257 | 258 | <ul> 259 | <li><p><strong>通过目录访问文件:</strong><a href="https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek/contactme.txt">https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek/contactme.txt</a> 260 | <img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-111019@2x.png" alt="" /></p></li> 261 | 262 | <li><p><strong>通过文件hash直接访问:</strong><a href="https://ipfs.io/ipfs/QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc">https://ipfs.io/ipfs/QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc</a></p></li> 263 | </ul> 264 | 265 | <p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-113047@2x.png" alt="" /></p> 266 | 267 | <h2 id="4-创建简易的网页发布到ipfs">4. 创建简易的网页发布到IPFS</h2> 268 | 269 | <p>在这里我先自己写一个简单的网页给大家演示,先在桌面新建一个<code>site</code>文件夹,然后按照下面的步骤在<code>site</code>文件夹中建立<code>index.html</code>和<code>style.css</code>文件。</p> 270 | 271 | <h3 id="4-1-创建一个index-html文件">4.1 创建一个index.html文件</h3> 272 | 273 | <pre><code>&lt;!DOCTYPE html&gt; 274 | &lt;html lang=&quot;en&quot;&gt; 275 | &lt;head&gt; 276 | &lt;meta charset=&quot;UTF-8&quot;&gt; 277 | &lt;title&gt;Hello IPFS!&lt;/title&gt; 278 | &lt;link rel=&quot;stylesheet&quot; href=&quot;./style.css&quot; /&gt; 279 | &lt;/head&gt; 280 | &lt;body&gt; 281 | &lt;h1&gt;Hello IPFS!&lt;/h1&gt; 282 | &lt;/body&gt; 283 | &lt;/html&gt; 284 | </code></pre> 285 | 286 | <h3 id="4-2-创建一个style-css文件">4.2 创建一个style.css文件</h3> 287 | 288 | <pre><code>h1 { 289 | color: green; 290 | } 291 | </code></pre> 292 | 293 | <h3 id="4-3-添加到ipfs">4.3 添加到ipfs</h3> 294 | 295 | <pre><code>localhost:Desktop yuechunli$ ipfs add -r site/ 296 | added QmWG5rbgT9H77TGq49RXNoqN8M7DNKMnMX425nkmCB6BjS site/index.html 297 | added QmfGLJ3mryLvicQqzdsghq4QRhptKJtBAPe7yDJxsBGSuy site/style.css 298 | added QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp site 299 | </code></pre> 300 | 301 | <p>最后一行是项目根目录的<code>hash</code>,你先通过<code>ipfs daemon</code>同步网络,然后可以通过<code>https://ipfs.io/ipfs/&lt;你的项目根目录hash&gt;</code>,即<code>https://ipfs.io/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp</code>访问项目。</p> 302 | 303 | <h3 id="4-4-网络同步">4.4 网络同步</h3> 304 | 305 | <pre><code>localhost:Desktop yuechunli$ ipfs daemon 306 | </code></pre> 307 | 308 | <h3 id="4-5-访问网站">4.5 访问网站</h3> 309 | 310 | <p>浏览器打开<a href="https://ipfs.io/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp">https://ipfs.io/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp</a>,效果图如下:</p> 311 | 312 | <p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-210721@2x.png" alt="" /></p> 313 | 314 | <h3 id="4-6-发布到ipns">4.6 发布到IPNS</h3> 315 | 316 | <p>当我们修改网站内容重新添加到<code>ipfs</code>时,<code>hash</code>会发生变化,当我们网站更新时,我们可以将网站发布到IPNS,在IPNS中,允许我们节点的域名空间中引用一个<code>IPFS hash</code>,也就是说我们可以通过节点<code>ID</code>对项目根目录的<code>IPFS HASH</code>进行绑定,以后我们访问网站时直接通过节点·ID<code>访问即可,当我们更新博客时,重新发布到</code>IPNS`即可。</p> 317 | 318 | <pre><code>localhost:~ yuechunli$ ipfs name publish QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp 319 | Published to QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP: /ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp 320 | localhost:~ yuechunli$ ipfs id 321 | { 322 | &quot;ID&quot;: &quot;QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP&quot; 323 | } 324 | </code></pre> 325 | 326 | <p>当我们执行<code>ipfs name publish</code>命令时,会返回我们的节点<code>ID</code>,你可以通过<code>ipfs id</code>进行查看验证是否是你的节点<code>ID</code>。</p> 327 | 328 | <p><strong>⚠️:验证</strong></p> 329 | 330 | <pre><code>$ ipfs name resolve &lt;peerId&gt; 331 | </code></pre> 332 | 333 | <pre><code>localhost:~ yuechunli$ ipfs name resolve QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP 334 | /ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp 335 | localhost:~ yuechunli$ 336 | </code></pre> 337 | 338 | <p><strong>⚠️:</strong>当然我们现在就可以通过<code>IPNS</code>进行访问了。</p> 339 | 340 | <pre><code>https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP 341 | </code></pre> 342 | 343 | <p><strong>⚠️⚠️⚠️:注意上面是ipns而不是ipfs。</strong></p> 344 | 345 | <p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-212123@2x.png" alt="" /></p> 346 | 347 | <p><strong>⚠️:如果你网站数据修改,需要重新发布到IPNS。</strong></p> 348 | 349 | <h2 id="5-发布个人博客">5. 发布个人博客</h2> 350 | 351 | <p>你可以通过<code>Hugo</code>按照官方文档创建一个漂亮的静态博客<a href="http://gohugo.io/getting-started/quick-start/">Hugo官方网站</a>,当然你也可以自己编写,或者使用其他开源项目搭建。</p> 352 | 353 | <h3 id="5-1-搭建静态博客">5.1 搭建静态博客</h3> 354 | 355 | <p>大家可以自己搭建,也可以直接下载我的博客源码直接搭建。</p> 356 | 357 | <p>源码地址:<a href="http://github.com/liyuechun/ipfs_blogger">http://github.com/liyuechun/ipfs_blogger</a></p> 358 | 359 | <h3 id="5-2-节点id替换">5.2 节点ID替换</h3> 360 | 361 | <ul> 362 | <li>查看你的节点ID</li> 363 | </ul> 364 | 365 | <pre><code>localhost:ipfs_pin yuechunli$ ipfs id 366 | { 367 | &quot;ID&quot;: &quot;《your peer id》&quot; 368 | } 369 | localhost:ipfs_pin yuechunli$ 370 | </code></pre> 371 | 372 | <p>在上面的源码中全局搜索将源码里面的<code>QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP</code>替换成你自己的<code>ID</code>。</p> 373 | 374 | <p>接下来重复<a href="#4-创建简易的网页发布到IPFS">4. 创建简易的网页发布到IPFS</a>的操作步骤即可。</p> 375 | 376 | <h3 id="5-3-浏览博客">5.3 浏览博客</h3> 377 | 378 | <p>浏览器打开<a href="https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/">https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/</a>查看项目效果。</p> 379 | 380 | <p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-215636@2x.png" alt="IPFS 博客项目效果图" /></p> 381 | 382 | <h2 id="6-下篇预报">6. 下篇预报</h2> 383 | 384 | <h3 id="6-1-ipfs-ethereum-dapp-开发入门">6.1 <code>ipfs + ethereum</code><code>Dapp</code>开发入门</h3> 385 | 386 | <h2 id="7-技术交流">7. 技术交流</h2> 387 | 388 | <ul> 389 | <li>区块链技术交流QQ群:<code>348924182</code></li> 390 | <li>进微信群请加微信:<code>liyc1215</code></li> 391 | <li>「区块链部落」官方公众号</li> 392 | </ul> 393 | 394 | <p><img src="http://om1c35wrq.bkt.clouddn.com/%E5%8C%BA%E5%9D%97%E9%93%BE%E9%83%A8%E8%90%BD.png" alt="" /></p> 395 | 396 | 397 | 398 | 399 | 400 | -------------------------------------------------------------------------------- /css/hyde.css: -------------------------------------------------------------------------------- 1 | /* 2 | * __ __ 3 | * /\ \ /\ \ 4 | * \ \ \___ __ __ \_\ \ __ 5 | * \ \ _ `\/\ \/\ \ /'_` \ /'__`\ 6 | * \ \ \ \ \ \ \_\ \/\ \_\ \/\ __/ 7 | * \ \_\ \_\/`____ \ \___,_\ \____\ 8 | * \/_/\/_/`/___/> \/__,_ /\/____/ 9 | * /\___/ 10 | * \/__/ 11 | * 12 | * Designed, built, and released under MIT license by @mdo. Learn more at 13 | * https://github.com/poole/hyde. 14 | */ 15 | 16 | 17 | /* 18 | * Contents 19 | * 20 | * Global resets 21 | * Sidebar 22 | * Container 23 | * Reverse layout 24 | * Themes 25 | */ 26 | 27 | 28 | /* 29 | * Global resets 30 | * 31 | * Update the foundational and global aspects of the page. 32 | */ 33 | 34 | html { 35 | font-family: "Fira Sans", sans-serif; 36 | font-weight:300; 37 | 38 | } 39 | @media (min-width: 48em) { 40 | html { 41 | font-size: 16px; 42 | } 43 | } 44 | @media (min-width: 58em) { 45 | html { 46 | font-size: 20px; 47 | } 48 | } 49 | 50 | pre { 51 | tab-size:4; 52 | } 53 | 54 | /* 55 | * Sidebar 56 | * 57 | * Flexible banner for housing site name, intro, and "footer" content. Starts 58 | * out above content in mobile and later moves to the side with wider viewports. 59 | */ 60 | 61 | .sidebar { 62 | text-align: center; 63 | padding: 2rem 1rem; 64 | color: rgba(255,255,255,.5); 65 | background-color: #300030; 66 | } 67 | @media (min-width: 48em) { 68 | .sidebar { 69 | position: fixed; 70 | top: 0; 71 | left: 0; 72 | bottom: 0; 73 | width: 18rem; 74 | text-align: left; 75 | } 76 | } 77 | 78 | /* Sidebar links */ 79 | .sidebar a { 80 | color: #fff; 81 | } 82 | 83 | /* About section */ 84 | .sidebar-about h1 { 85 | color: #fff; 86 | margin-top: 0; 87 | font-weight:300; 88 | } 89 | 90 | /* Sidebar nav */ 91 | .sidebar-nav { 92 | margin-top: 2rem; 93 | margin-bottom: 2rem; 94 | padding-left: 0; 95 | list-style: none; 96 | } 97 | 98 | .subnav { 99 | list-style: none; 100 | padding-left: 0; 101 | } 102 | 103 | .sidebar-nav-item { 104 | display: block; 105 | } 106 | a.sidebar-nav-item:hover, 107 | a.sidebar-nav-item:focus { 108 | text-decoration: underline; 109 | } 110 | .sidebar-nav-item.active { 111 | font-weight: bold; 112 | } 113 | 114 | /* Sticky sidebar 115 | * 116 | * Add the `sidebar-sticky` class to the sidebar's container to affix it the 117 | * contents to the bottom of the sidebar in tablets and up. 118 | */ 119 | 120 | @media (min-width: 48em) { 121 | .sidebar-sticky { 122 | position: absolute; 123 | right: 1rem; 124 | top: 1rem; 125 | left: 1rem; 126 | } 127 | } 128 | 129 | 130 | /* Container 131 | * 132 | * Align the contents of the site above the proper threshold with some margin-fu 133 | * with a 25%-wide `.sidebar`. 134 | */ 135 | 136 | .content { 137 | padding-top: 2rem; 138 | padding-bottom: 2rem; 139 | } 140 | 141 | @media (min-width: 48em) { 142 | .content { 143 | max-width: 38rem; 144 | margin-left: 20rem; 145 | margin-right: 2rem; 146 | } 147 | } 148 | 149 | @media (min-width: 64em) { 150 | .content { 151 | max-width: 44rem; 152 | margin-left: 20rem; 153 | margin-right: 2rem; 154 | } 155 | } 156 | 157 | .footnote { 158 | font-size: 0.7em; 159 | margin-top: 0.5rem; 160 | } 161 | 162 | .go { 163 | color: #444444; 164 | } 165 | 166 | .badge { 167 | display:inline; 168 | vertical-align: bottom; 169 | } 170 | 171 | .badges { 172 | float: right; 173 | } 174 | 175 | .brand { 176 | font-size: 4.0em; 177 | margin-bottom: 0; 178 | } 179 | 180 | /* 181 | * Reverse layout 182 | * 183 | * Flip the orientation of the page by placing the `.sidebar` on the right. 184 | */ 185 | 186 | @media (min-width: 48em) { 187 | .layout-reverse .sidebar { 188 | left: auto; 189 | right: 0; 190 | } 191 | .layout-reverse .content { 192 | margin-left: 2rem; 193 | margin-right: 20rem; 194 | } 195 | } 196 | 197 | @media (min-width: 64em) { 198 | .layout-reverse .content { 199 | margin-left: 4rem; 200 | margin-right: 22rem; 201 | } 202 | } 203 | 204 | 205 | 206 | /* 207 | * Themes 208 | * 209 | * As of v1.1, Hyde includes optional themes to color the sidebar and links 210 | * within blog posts. To use, add the class of your choosing to the `body`. 211 | */ 212 | 213 | /* Base16 (http://chriskempson.github.io/base16/#default) */ 214 | 215 | /* Red */ 216 | .theme-base-08 .sidebar { 217 | background-color: #ac4142; 218 | } 219 | .theme-base-08 .content a, 220 | .theme-base-08 .related-posts li a:hover { 221 | color: #ac4142; 222 | } 223 | 224 | /* Orange */ 225 | .theme-base-09 .sidebar { 226 | background-color: #d28445; 227 | } 228 | .theme-base-09 .content a, 229 | .theme-base-09 .related-posts li a:hover { 230 | color: #d28445; 231 | } 232 | 233 | /* Yellow */ 234 | .theme-base-0a .sidebar { 235 | background-color: #f4bf75; 236 | } 237 | .theme-base-0a .content a, 238 | .theme-base-0a .related-posts li a:hover { 239 | color: #f4bf75; 240 | } 241 | 242 | /* Green */ 243 | .theme-base-0b .sidebar { 244 | background-color: #90a959; 245 | } 246 | .theme-base-0b .content a, 247 | .theme-base-0b .related-posts li a:hover { 248 | color: #90a959; 249 | } 250 | 251 | /* Cyan */ 252 | .theme-base-0c .sidebar { 253 | background-color: #75b5aa; 254 | } 255 | .theme-base-0c .content a, 256 | .theme-base-0c .related-posts li a:hover { 257 | color: #75b5aa; 258 | } 259 | 260 | /* Blue */ 261 | .theme-base-0d .sidebar { 262 | background-color: #6a9fb5; 263 | } 264 | .theme-base-0d .content a, 265 | .theme-base-0d .related-posts li a:hover { 266 | color: #6a9fb5; 267 | } 268 | 269 | /* Magenta */ 270 | .theme-base-0e .sidebar { 271 | background-color: #aa759f; 272 | } 273 | .theme-base-0e .content a, 274 | .theme-base-0e .related-posts li a:hover { 275 | color: #aa759f; 276 | } 277 | 278 | /* Brown */ 279 | .theme-base-0f .sidebar { 280 | background-color: #8f5536; 281 | } 282 | .theme-base-0f .content a, 283 | .theme-base-0f .related-posts li a:hover { 284 | color: #8f5536; 285 | } 286 | -------------------------------------------------------------------------------- /css/poole.css: -------------------------------------------------------------------------------- 1 | /* 2 | * ___ 3 | * /\_ \ 4 | * _____ ___ ___\//\ \ __ 5 | * /\ '__`\ / __`\ / __`\\ \ \ /'__`\ 6 | * \ \ \_\ \/\ \_\ \/\ \_\ \\_\ \_/\ __/ 7 | * \ \ ,__/\ \____/\ \____//\____\ \____\ 8 | * \ \ \/ \/___/ \/___/ \/____/\/____/ 9 | * \ \_\ 10 | * \/_/ 11 | * 12 | * Designed, built, and released under MIT license by @mdo. Learn more at 13 | * https://github.com/poole/poole. 14 | */ 15 | 16 | 17 | /* 18 | * Contents 19 | * 20 | * Body resets 21 | * Custom type 22 | * Messages 23 | * Container 24 | * Masthead 25 | * Posts and pages 26 | * Pagination 27 | * Reverse layout 28 | * Themes 29 | */ 30 | 31 | 32 | /* 33 | * Body resets 34 | * 35 | * Update the foundational and global aspects of the page. 36 | */ 37 | 38 | * { 39 | -webkit-box-sizing: border-box; 40 | -moz-box-sizing: border-box; 41 | box-sizing: border-box; 42 | } 43 | 44 | html, 45 | body { 46 | margin: 0; 47 | padding: 0; 48 | } 49 | 50 | html { 51 | font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; 52 | font-size: 16px; 53 | line-height: 1.5; 54 | } 55 | @media (min-width: 38em) { 56 | html { 57 | font-size: 20px; 58 | } 59 | } 60 | 61 | body { 62 | color: #515151; 63 | background-color: #fff; 64 | -webkit-text-size-adjust: 100%; 65 | -ms-text-size-adjust: 100%; 66 | } 67 | 68 | /* No `:visited` state is required by default (browsers will use `a`) */ 69 | a { 70 | color: #268bd2; 71 | text-decoration: none; 72 | } 73 | /* `:focus` is linked to `:hover` for basic accessibility */ 74 | a:hover, 75 | a:focus { 76 | text-decoration: underline; 77 | } 78 | 79 | /* Headings */ 80 | h1, h2, h3, h4, h5, h6 { 81 | margin-bottom: .5rem; 82 | font-weight: 400; 83 | line-height: 1.25; 84 | color: #313131; 85 | text-rendering: optimizeLegibility; 86 | } 87 | h1 { 88 | font-size: 2rem; 89 | } 90 | h2 { 91 | margin-top: 1rem; 92 | font-size: 1.5rem; 93 | } 94 | h3 { 95 | margin-top: 1.5rem; 96 | font-size: 1.25rem; 97 | } 98 | h4, h5, h6 { 99 | margin-top: 1rem; 100 | font-size: 1rem; 101 | } 102 | 103 | /* Body text */ 104 | p { 105 | margin-top: 0; 106 | margin-bottom: 1rem; 107 | } 108 | 109 | strong { 110 | color: #303030; 111 | } 112 | 113 | 114 | /* Lists */ 115 | ul, ol, dl { 116 | margin-top: 0; 117 | margin-bottom: 1rem; 118 | } 119 | 120 | dt { 121 | font-weight: bold; 122 | } 123 | dd { 124 | margin-bottom: .5rem; 125 | } 126 | 127 | /* Misc */ 128 | hr { 129 | position: relative; 130 | margin: 1.5rem 0; 131 | border: 0; 132 | border-top: 1px solid #eee; 133 | border-bottom: 1px solid #fff; 134 | } 135 | 136 | abbr { 137 | font-size: 85%; 138 | font-weight: bold; 139 | color: #555; 140 | text-transform: uppercase; 141 | } 142 | abbr[title] { 143 | cursor: help; 144 | border-bottom: 1px dotted #e5e5e5; 145 | } 146 | 147 | /* Code */ 148 | code, 149 | pre { 150 | font-family: Menlo, Monaco, "Courier New", monospace; 151 | } 152 | code { 153 | padding: .25em .5em; 154 | font-size: 85%; 155 | color: #bf616a; 156 | background-color: #f9f9f9; 157 | border-radius: 3px; 158 | } 159 | pre { 160 | display: block; 161 | margin-top: 0; 162 | margin-bottom: 1rem; 163 | padding: 1rem; 164 | font-size: .8rem; 165 | line-height: 1.4; 166 | white-space: pre; 167 | white-space: pre-wrap; 168 | word-break: break-all; 169 | word-wrap: break-word; 170 | background-color: #f9f9f9; 171 | } 172 | pre code { 173 | padding: 0; 174 | font-size: 100%; 175 | color: inherit; 176 | background-color: transparent; 177 | } 178 | .highlight { 179 | margin-bottom: 1rem; 180 | border-radius: 4px; 181 | } 182 | .highlight pre { 183 | margin-bottom: 0; 184 | } 185 | 186 | /* Quotes */ 187 | blockquote { 188 | padding: .5rem 1rem; 189 | margin: .8rem 0; 190 | color: #7a7a7a; 191 | border-left: .25rem solid #e5e5e5; 192 | } 193 | blockquote p:last-child { 194 | margin-bottom: 0; 195 | } 196 | @media (min-width: 30em) { 197 | blockquote { 198 | padding-right: 5rem; 199 | padding-left: 1.25rem; 200 | } 201 | } 202 | 203 | img { 204 | display: block; 205 | margin: 0 0 1rem; 206 | border-radius: 5px; 207 | max-width: 100%; 208 | } 209 | 210 | /* Tables */ 211 | table { 212 | margin-bottom: 1rem; 213 | width: 100%; 214 | border: 1px solid #e5e5e5; 215 | border-collapse: collapse; 216 | } 217 | td, 218 | th { 219 | padding: .25rem .5rem; 220 | border: 1px solid #e5e5e5; 221 | } 222 | tbody tr:nth-child(odd) td, 223 | tbody tr:nth-child(odd) th { 224 | background-color: #f9f9f9; 225 | } 226 | 227 | 228 | /* 229 | * Custom type 230 | * 231 | * Extend paragraphs with `.lead` for larger introductory text. 232 | */ 233 | 234 | .lead { 235 | font-size: 1.25rem; 236 | font-weight: 300; 237 | } 238 | 239 | 240 | /* 241 | * Messages 242 | * 243 | * Show alert messages to users. You may add it to single elements like a `

`, 244 | * or to a parent if there are multiple elements to show. 245 | */ 246 | 247 | .message { 248 | margin-bottom: 1rem; 249 | padding: 1rem; 250 | color: #717171; 251 | background-color: #f9f9f9; 252 | } 253 | 254 | 255 | /* 256 | * Container 257 | * 258 | * Center the page content. 259 | */ 260 | 261 | .container { 262 | max-width: 38rem; 263 | padding-left: 1rem; 264 | padding-right: 1rem; 265 | margin-left: auto; 266 | margin-right: auto; 267 | } 268 | 269 | 270 | /* 271 | * Masthead 272 | * 273 | * Super small header above the content for site name and short description. 274 | */ 275 | 276 | .masthead { 277 | padding-top: 1rem; 278 | padding-bottom: 1rem; 279 | margin-bottom: 3rem; 280 | } 281 | .masthead-title { 282 | margin-top: 0; 283 | margin-bottom: 0; 284 | color: #505050; 285 | } 286 | .masthead-title a { 287 | color: #505050; 288 | } 289 | .masthead-title small { 290 | font-size: 75%; 291 | font-weight: 400; 292 | color: #c0c0c0; 293 | letter-spacing: 0; 294 | } 295 | 296 | 297 | /* 298 | * Posts and pages 299 | * 300 | * Each post is wrapped in `.post` and is used on default and post layouts. Each 301 | * page is wrapped in `.page` and is only used on the page layout. 302 | */ 303 | 304 | .page, 305 | .post { 306 | margin-bottom: 4em; 307 | } 308 | 309 | /* Blog post or page title */ 310 | .page-title, 311 | .post-title, 312 | .post-title a { 313 | color: #303030; 314 | } 315 | .page-title, 316 | .post-title { 317 | margin-top: 0; 318 | } 319 | 320 | /* Meta data line below post title */ 321 | .post-date { 322 | display: block; 323 | margin-top: -.5rem; 324 | margin-bottom: 1rem; 325 | color: #9a9a9a; 326 | } 327 | 328 | /* Related posts */ 329 | .related { 330 | padding-top: 2rem; 331 | padding-bottom: 2rem; 332 | border-top: 1px solid #eee; 333 | } 334 | .related-posts { 335 | padding-left: 0; 336 | list-style: none; 337 | } 338 | .related-posts h3 { 339 | margin-top: 0; 340 | } 341 | .related-posts li small { 342 | font-size: 75%; 343 | color: #999; 344 | } 345 | .related-posts li a:hover { 346 | color: #268bd2; 347 | text-decoration: none; 348 | } 349 | .related-posts li a:hover small { 350 | color: inherit; 351 | } 352 | 353 | 354 | /* 355 | * Pagination 356 | * 357 | * Super lightweight (HTML-wise) blog pagination. `span`s are provide for when 358 | * there are no more previous or next posts to show. 359 | */ 360 | 361 | .pagination { 362 | overflow: hidden; /* clearfix */ 363 | margin-left: -1rem; 364 | margin-right: -1rem; 365 | font-family: "PT Sans", Helvetica, Arial, sans-serif; 366 | color: #ccc; 367 | text-align: center; 368 | } 369 | 370 | /* Pagination items can be `span`s or `a`s */ 371 | .pagination-item { 372 | display: block; 373 | padding: 1rem; 374 | border: 1px solid #eee; 375 | } 376 | .pagination-item:first-child { 377 | margin-bottom: -1px; 378 | } 379 | 380 | /* Only provide a hover state for linked pagination items */ 381 | a.pagination-item:hover { 382 | background-color: #f5f5f5; 383 | } 384 | 385 | @media (min-width: 30em) { 386 | .pagination { 387 | margin: 3rem 0; 388 | } 389 | .pagination-item { 390 | float: left; 391 | width: 50%; 392 | } 393 | .pagination-item:first-child { 394 | margin-bottom: 0; 395 | border-top-left-radius: 4px; 396 | border-bottom-left-radius: 4px; 397 | } 398 | .pagination-item:last-child { 399 | margin-left: -1px; 400 | border-top-right-radius: 4px; 401 | border-bottom-right-radius: 4px; 402 | } 403 | } 404 | -------------------------------------------------------------------------------- /css/syntax.css: -------------------------------------------------------------------------------- 1 | .hll { background-color: #ffffcc } 2 | /*{ background: #f0f3f3; }*/ 3 | .c { color: #999; } /* Comment */ 4 | .err { color: #AA0000; background-color: #FFAAAA } /* Error */ 5 | .k { color: #006699; } /* Keyword */ 6 | .o { color: #555555 } /* Operator */ 7 | .cm { color: #0099FF; font-style: italic } /* Comment.Multiline */ 8 | .cp { color: #009999 } /* Comment.Preproc */ 9 | .c1 { color: #999; } /* Comment.Single */ 10 | .cs { color: #999; } /* Comment.Special */ 11 | .gd { background-color: #FFCCCC; border: 1px solid #CC0000 } /* Generic.Deleted */ 12 | .ge { font-style: italic } /* Generic.Emph */ 13 | .gr { color: #FF0000 } /* Generic.Error */ 14 | .gh { color: #003300; } /* Generic.Heading */ 15 | .gi { background-color: #CCFFCC; border: 1px solid #00CC00 } /* Generic.Inserted */ 16 | .go { color: #AAAAAA } /* Generic.Output */ 17 | .gp { color: #000099; } /* Generic.Prompt */ 18 | .gs { } /* Generic.Strong */ 19 | .gu { color: #003300; } /* Generic.Subheading */ 20 | .gt { color: #99CC66 } /* Generic.Traceback */ 21 | .kc { color: #006699; } /* Keyword.Constant */ 22 | .kd { color: #006699; } /* Keyword.Declaration */ 23 | .kn { color: #006699; } /* Keyword.Namespace */ 24 | .kp { color: #006699 } /* Keyword.Pseudo */ 25 | .kr { color: #006699; } /* Keyword.Reserved */ 26 | .kt { color: #007788; } /* Keyword.Type */ 27 | .m { color: #FF6600 } /* Literal.Number */ 28 | .s { color: #d44950 } /* Literal.String */ 29 | .na { color: #4f9fcf } /* Name.Attribute */ 30 | .nb { color: #336666 } /* Name.Builtin */ 31 | .nc { color: #00AA88; } /* Name.Class */ 32 | .no { color: #336600 } /* Name.Constant */ 33 | .nd { color: #9999FF } /* Name.Decorator */ 34 | .ni { color: #999999; } /* Name.Entity */ 35 | .ne { color: #CC0000; } /* Name.Exception */ 36 | .nf { color: #CC00FF } /* Name.Function */ 37 | .nl { color: #9999FF } /* Name.Label */ 38 | .nn { color: #00CCFF; } /* Name.Namespace */ 39 | .nt { color: #2f6f9f; } /* Name.Tag */ 40 | .nv { color: #003333 } /* Name.Variable */ 41 | .ow { color: #000000; } /* Operator.Word */ 42 | .w { color: #bbbbbb } /* Text.Whitespace */ 43 | .mf { color: #FF6600 } /* Literal.Number.Float */ 44 | .mh { color: #FF6600 } /* Literal.Number.Hex */ 45 | .mi { color: #FF6600 } /* Literal.Number.Integer */ 46 | .mo { color: #FF6600 } /* Literal.Number.Oct */ 47 | .sb { color: #CC3300 } /* Literal.String.Backtick */ 48 | .sc { color: #CC3300 } /* Literal.String.Char */ 49 | .sd { color: #CC3300; font-style: italic } /* Literal.String.Doc */ 50 | .s2 { color: #CC3300 } /* Literal.String.Double */ 51 | .se { color: #CC3300; } /* Literal.String.Escape */ 52 | .sh { color: #CC3300 } /* Literal.String.Heredoc */ 53 | .si { color: #AA0000 } /* Literal.String.Interpol */ 54 | .sx { color: #CC3300 } /* Literal.String.Other */ 55 | .sr { color: #33AAAA } /* Literal.String.Regex */ 56 | .s1 { color: #CC3300 } /* Literal.String.Single */ 57 | .ss { color: #FFCC33 } /* Literal.String.Symbol */ 58 | .bp { color: #336666 } /* Name.Builtin.Pseudo */ 59 | .vc { color: #003333 } /* Name.Variable.Class */ 60 | .vg { color: #003333 } /* Name.Variable.Global */ 61 | .vi { color: #003333 } /* Name.Variable.Instance */ 62 | .il { color: #FF6600 } /* Literal.Number.Integer.Long */ 63 | 64 | .css .o, 65 | .css .o + .nt, 66 | .css .nt + .nt { color: #999; } 67 | -------------------------------------------------------------------------------- /favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyuechun/ipfs_blogger/7e72b78875adf5d23b344db3851654f931529ce8/favicon.png -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 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 | 43 | 44 | 45 | 46 | 47 | 48 |

77 | 78 | 79 |
80 |
81 | 82 | 83 | 84 |
85 |

86 | 87 | 【IPFS + 区块链 系列】 入门篇 - IPFS+IPNS+个人博客搭建 88 | 89 |

90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 |
99 |

孔壹学院:国内区块链职业教育引领品牌。

100 | 101 |

作者:黎跃春,孔壹学院创始人,区块链、高可用架构师

102 | 103 |

微信:liyc1215

104 | 105 |

区块链博客:http://liyuechun.org

106 |
107 | 108 |

在阅读这篇文章之前,你需要先学习【IPFS + 区块链 系列】 入门篇 - IPFS环境配置这篇文章。

109 | 110 |

目录

111 | 112 | 151 | 152 |

1. 如何在IPFS新增一个文件

153 | 154 |

1.1 新建file.txt文件

155 | 156 |

打开终端,切换到桌面,新建一个文件夹1121,切换到1121中,通过vi新建一个文件file.txt,文件里面输入春哥微信号liyc1215保存并且退出。

157 | 158 |
localhost:Desktop yuechunli$ pwd
159 | /Users/liyuechun/Desktop
160 | localhost:Desktop yuechunli$ mkdir 1121
161 | localhost:Desktop yuechunli$ cd 1121/
162 | localhost:1121 yuechunli$ vi file.txt
163 | localhost:1121 yuechunli$ cat file.txt
164 | liyc1215
165 | localhost:1121 yuechunli$
166 | 
167 | 168 |

1.2 查看ipfs相关命令

169 | 170 |
localhost:1121 yuechunli$ ipfs help
171 | USAGE
172 |   ipfs - Global p2p merkle-dag filesystem.
173 | 
174 |   ipfs [--config=<config> | -c] [--debug=<debug> | -D] [--help=<help>] [-h=<h>] [--local=<local> | -L] [--api=<api>] <command> ...
175 | 
176 | SUBCOMMANDS
177 |   BASIC COMMANDS
178 |     init          Initialize ipfs local configuration
179 |     add <path>    Add a file to IPFS
180 |     cat <ref>     Show IPFS object data
181 |     get <ref>     Download IPFS objects
182 |     ls <ref>      List links from an object
183 |     refs <ref>    List hashes of links from an object
184 | 
185 |   DATA STRUCTURE COMMANDS
186 |     block         Interact with raw blocks in the datastore
187 |     object        Interact with raw dag nodes
188 |     files         Interact with objects as if they were a unix filesystem
189 |     dag           Interact with IPLD documents (experimental)
190 | 
191 |   ADVANCED COMMANDS
192 |     daemon        Start a long-running daemon process
193 |     mount         Mount an IPFS read-only mountpoint
194 |     resolve       Resolve any type of name
195 |     name          Publish and resolve IPNS names
196 |     key           Create and list IPNS name keypairs
197 |     dns           Resolve DNS links
198 |     pin           Pin objects to local storage
199 |     repo          Manipulate the IPFS repository
200 |     stats         Various operational stats
201 |     p2p           Libp2p stream mounting
202 |     filestore     Manage the filestore (experimental)
203 | 
204 |   NETWORK COMMANDS
205 |     id            Show info about IPFS peers
206 |     bootstrap     Add or remove bootstrap peers
207 |     swarm         Manage connections to the p2p network
208 |     dht           Query the DHT for values or peers
209 |     ping          Measure the latency of a connection
210 |     diag          Print diagnostics
211 | 
212 |   TOOL COMMANDS
213 |     config        Manage configuration
214 |     version       Show ipfs version information
215 |     update        Download and apply go-ipfs updates
216 |     commands      List all available commands
217 | 
218 | 219 |

1.3 将file.txt添加到ipfs节点

220 | 221 |
localhost:1121 yuechunli$ ls
222 | file.txt
223 | localhost:1121 yuechunli$ ipfs add file.txt
224 | added QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T file.txt
225 | localhost:1121 yuechunli$ cat file.txt
226 | liyc1215
227 | localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T
228 | liyc1215
229 | localhost:1121 yuechunli$
230 | 
231 | 232 |

当执行完ipfs add file.txt这个命令以后,会将file.txt添加到ipfs当前的节点中,并且会对file.txt文件生成一个唯一的hashQmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T,如果想查看本地ipfs节点的数据,可以通过ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T进行查看。

233 | 234 |

⚠️:当我试图通过http://ipfs.io/ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T进行数据访问时,无法访问,如下图所示:

235 | 236 |

237 | 238 |

⚠️:虽然数据已经添加到当前的你自己的IPFS节点中,但是并没有同步到IPFS网络,所以暂时在网络上无法访问。

239 | 240 |

⚠️:重要:接下来执行下面的命令同步节点数据到IPFS网络,再试图在网络上查看数据。

241 | 242 |
    243 |
  • 同步节点
  • 244 |
245 | 246 |

新建一个终端,执行ipfs daemon

247 | 248 |
localhost:.ipfs yuechunli$ ipfs daemon
249 | Initializing daemon...
250 | Adjusting current ulimit to 2048...
251 | Successfully raised file descriptor limit to 2048.
252 | Swarm listening on /ip4/111.196.246.151/tcp/3637
253 | Swarm listening on /ip4/127.0.0.1/tcp/4001
254 | Swarm listening on /ip4/169.254.170.167/tcp/4001
255 | Swarm listening on /ip4/192.168.0.107/tcp/4001
256 | Swarm listening on /ip6/::1/tcp/4001
257 | API server listening on /ip4/127.0.0.1/tcp/5001
258 | Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
259 | Daemon is ready
260 | 
261 | 262 |
    263 |
  • IPFS网络查看数据
  • 264 |
265 | 266 |

浏览器访问https://ipfs.io/ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T

267 | 268 |

黎跃春 微信

269 | 270 |

2. 通过ipfs创建目录存储文件

271 | 272 |

在着上面的步骤走,我们可以通过ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T 273 | liyc1215查看添加到ipfs网络的file.txt文件的内容,如下:

274 | 275 |
localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T
276 | liyc1215
277 | localhost:1121 yuechunli$
278 | 
279 | 280 |

当然,我们也可以通过ipfs的相关命令在ipfs的根目录下面创建文件夹,并且将file.txt文件移动或者拷贝到我们创建的文件夹中。

281 | 282 |

⚠️:cp不会改变文件hash,mv会改变hash寻址。

283 | 284 |
localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T
285 | liyc1215
286 | localhost:1121 yuechunli$ ipfs files mkdir /LiYueChun
287 | localhost:1121 yuechunli$ ipfs files cp /ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T /LiYueChun/file.txt
288 | localhost:1121 yuechunli$ ipfs files ls /
289 | LiYueChun
290 | localhost:1121 yuechunli$ ipfs files ls /LiYueChun/
291 | file.txt
292 | localhost:1121 yuechunli$ ipfs files read /LiYueChun/file.txt
293 | liyc1215
294 | localhost:1121 yuechunli$
295 | 
296 | 297 |

3. 如何在IPFS新增一个目录

298 | 299 |

3.1 使用ipfs add -r可以上传一整个目录

300 | 301 |
localhost:1121 yuechunli$ ipfs add -r ipfs-tutorial/
302 | added QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc ipfs-tutorial/contactme.txt
303 | added QmfKdWsguobA3aDPvSxLB3Bq4HMKyqKSgFr2NFUuVH8n31 ipfs-tutorial/eth-fabric.png
304 | added QmXe8jTxTh5MZP6BK5cnj19mXNTKVMzNyUJZUHuYyr5dk1 ipfs-tutorial/gongzhonghao.png
305 | added QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek ipfs-tutorial
306 | 
307 | 308 |

3.2 通过路径访问contactme.txt文件数据

309 | 310 |

如果我们上传的是目录,那么可以通过下面几种方式访问到contactme.txt文件的数据。

311 | 312 |
localhost:1121 yuechunli$ ipfs cat QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc
313 | 微信:liyc1215
314 | 区块链技术交流群:348924182
315 | 公众号:区块链部落
316 | localhost:1121 yuechunli$ ipfs cat /ipfs/QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc
317 | 微信:liyc1215
318 | 区块链技术交流群:348924182
319 | 公众号:区块链部落
320 | localhost:1121 yuechunli$ ipfs cat /ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek/contactme.txt
321 | 微信:liyc1215
322 | 区块链技术交流群:348924182
323 | 公众号:区块链部落
324 | localhost:1121 yuechunli$
325 | 
326 | 327 |

3.3 通过Hash查看数据IPFS网络数据

328 | 329 | 332 | 333 |

334 | 335 | 341 | 342 |

343 | 344 |

4. 创建简易的网页发布到IPFS

345 | 346 |

在这里我先自己写一个简单的网页给大家演示,先在桌面新建一个site文件夹,然后按照下面的步骤在site文件夹中建立index.htmlstyle.css文件。

347 | 348 |

4.1 创建一个index.html文件

349 | 350 |
<!DOCTYPE html>
351 | <html lang="en">
352 | <head>
353 |   <meta charset="UTF-8">
354 |   <title>Hello IPFS!</title>
355 |   <link rel="stylesheet" href="./style.css" />
356 | </head>
357 | <body>
358 |   <h1>Hello IPFS!</h1>
359 | </body>
360 | </html>
361 | 
362 | 363 |

4.2 创建一个style.css文件

364 | 365 |
h1 {
366 |   color: green;
367 | }
368 | 
369 | 370 |

4.3 添加到ipfs

371 | 372 |
localhost:Desktop yuechunli$ ipfs add -r site/
373 | added QmWG5rbgT9H77TGq49RXNoqN8M7DNKMnMX425nkmCB6BjS site/index.html
374 | added QmfGLJ3mryLvicQqzdsghq4QRhptKJtBAPe7yDJxsBGSuy site/style.css
375 | added QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp site
376 | 
377 | 378 |

最后一行是项目根目录的hash,你先通过ipfs daemon同步网络,然后可以通过https://ipfs.io/ipfs/<你的项目根目录hash>,即https://ipfs.io/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp访问项目。

379 | 380 |

4.4 网络同步

381 | 382 |
localhost:Desktop yuechunli$ ipfs daemon
383 | 
384 | 385 |

4.5 访问网站

386 | 387 |

浏览器打开https://ipfs.io/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp,效果图如下:

388 | 389 |

390 | 391 |

4.6 发布到IPNS

392 | 393 |

当我们修改网站内容重新添加到ipfs时,hash会发生变化,当我们网站更新时,我们可以将网站发布到IPNS,在IPNS中,允许我们节点的域名空间中引用一个IPFS hash,也就是说我们可以通过节点ID对项目根目录的IPFS HASH进行绑定,以后我们访问网站时直接通过节点·ID访问即可,当我们更新博客时,重新发布到IPNS`即可。

394 | 395 |
localhost:~ yuechunli$ ipfs name publish QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp
396 | Published to QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP: /ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp
397 | localhost:~ yuechunli$ ipfs id
398 | {
399 | 	"ID": "QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP"
400 | }
401 | 
402 | 403 |

当我们执行ipfs name publish命令时,会返回我们的节点ID,你可以通过ipfs id进行查看验证是否是你的节点ID

404 | 405 |

⚠️:验证

406 | 407 |
$ ipfs name resolve <peerId>
408 | 
409 | 410 |
localhost:~ yuechunli$ ipfs name resolve QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP
411 | /ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp
412 | localhost:~ yuechunli$
413 | 
414 | 415 |

⚠️:当然我们现在就可以通过IPNS进行访问了。

416 | 417 |
https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP
418 | 
419 | 420 |

⚠️⚠️⚠️:注意上面是ipns而不是ipfs。

421 | 422 |

423 | 424 |

⚠️:如果你网站数据修改,需要重新发布到IPNS。

425 | 426 |

5. 发布个人博客

427 | 428 |

你可以通过Hugo按照官方文档创建一个漂亮的静态博客Hugo官方网站,当然你也可以自己编写,或者使用其他开源项目搭建。

429 | 430 |

5.1 搭建静态博客

431 | 432 |

大家可以自己搭建,也可以直接下载我的博客源码直接搭建。

433 | 434 |

源码地址:http://github.com/liyuechun/ipfs_blogger

435 | 436 |

5.2 节点ID替换

437 | 438 |
    439 |
  • 查看你的节点ID
  • 440 |
441 | 442 |
localhost:ipfs_pin yuechunli$ ipfs id
443 | {
444 | 	"ID": "《your peer id》"
445 | }
446 | localhost:ipfs_pin yuechunli$
447 | 
448 | 449 |

在上面的源码中全局搜索将源码里面的QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP替换成你自己的ID

450 | 451 |

接下来重复4. 创建简易的网页发布到IPFS的操作步骤即可。

452 | 453 |

5.3 浏览博客

454 | 455 |

浏览器打开https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/查看项目效果。

456 | 457 |

IPFS 博客项目效果图

458 | 459 |

6. 下篇预报

460 | 461 |

6.1 ipfs + ethereumDapp开发入门

462 | 463 |

7. 技术交流

464 | 465 |
    466 |
  • 区块链技术交流QQ群:348924182
  • 467 |
  • 进微信群请加微信:liyc1215
  • 468 |
  • 「区块链部落」官方公众号
  • 469 |
470 | 471 |

472 | 473 |
474 | 475 | 476 |
477 | 478 | 479 | 480 | 481 | -------------------------------------------------------------------------------- /index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 区块链部落 5 | Hugo 6 | https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/ 7 | en-us 8 | 黎跃春 9 | 2017 liyuechun 10 | Mon, 30 Oct 2017 20:01:00 UTC 11 | 12 | 13 | 14 | 【IPFS + 区块链 系列】 入门篇 - IPFS+IPNS+个人博客搭建 15 | https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/2017/10/ipfs_first_post/ 16 | Mon, 30 Oct 2017 20:01:00 UTC 17 | 黎跃春 18 | https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/2017/10/ipfs_first_post/ 19 | 20 | 21 | <blockquote> 22 | <p>孔壹学院:国内区块链职业教育引领品牌。</p> 23 | 24 | <p>作者:黎跃春,孔壹学院创始人,区块链、高可用架构师</p> 25 | 26 | <p>微信:liyc1215</p> 27 | 28 | <p>区块链博客:<a href="http://liyuechun.org">http://liyuechun.org</a></p> 29 | </blockquote> 30 | 31 | <p>在阅读这篇文章之前,你需要先学习<a href="http://liyuechun.org/2017/11/20/ipfs-blockchain/">【IPFS + 区块链 系列】 入门篇 - IPFS环境配置</a>这篇文章。</p> 32 | 33 | <h2 id="目录">目录</h2> 34 | 35 | <ul> 36 | <li><a href="#1-如何在IPFS新增一个文件">1. 如何在IPFS新增一个文件</a> 37 | 38 | <ul> 39 | <li><a href="#11-新建file.txt文件">1.1 新建file.txt文件</a></li> 40 | <li><a href="#12-查看ipfs相关命令">1.2 查看ipfs相关命令</a></li> 41 | <li><a href="#13-将file.txt添加到ipfs节点">1.3 将file.txt添加到ipfs节点</a></li> 42 | </ul></li> 43 | <li><a href="#2-通过ipfs创建目录存储文件">2. 通过ipfs创建目录存储文件</a></li> 44 | <li><a href="#3-如何在IPFS新增一个目录">3. 如何在IPFS新增一个目录</a> 45 | 46 | <ul> 47 | <li><a href="#31-使用ipfs add -r可以上传一整个目录">3.1 使用ipfs add -r可以上传一整个目录</a></li> 48 | <li><a href="#32-通过路径访问contactme.txt文件数据">3.2 通过路径访问contactme.txt文件数据</a></li> 49 | <li><a href="#33-通过Hash查看数据IPFS网络数据">3.3 通过Hash查看数据IPFS网络数据</a></li> 50 | </ul></li> 51 | <li><a href="#4-创建简易的网页发布到IPFS">4. 创建简易的网页发布到IPFS</a> 52 | 53 | <ul> 54 | <li><a href="#41-创建一个index.html文件">4.1 创建一个index.html文件</a></li> 55 | <li><a href="#42-创建一个style.css文件">4.2 创建一个style.css文件</a></li> 56 | <li><a href="#43-添加到ipfs">4.3 添加到ipfs</a></li> 57 | <li><a href="#44-网络同步">4.4 网络同步</a></li> 58 | <li><a href="#45-访问网站">4.5 访问网站</a></li> 59 | <li><a href="#46-发布到IPNS">4.6 发布到IPNS</a></li> 60 | </ul></li> 61 | <li><a href="#5-发布个人博客">5. 发布个人博客</a> 62 | 63 | <ul> 64 | <li><a href="#51-搭建静态博客">5.1 搭建静态博客</a></li> 65 | <li><a href="#52-节点ID替换">5.2 节点ID替换</a></li> 66 | <li><a href="#53-浏览博客">5.3 浏览博客</a></li> 67 | </ul></li> 68 | <li><a href="#6-下篇预报">6. 下篇预报</a> 69 | 70 | <ul> 71 | <li><a href="#61-`ipfs + ethereum``Dapp`开发入门">6.1 <code>ipfs + ethereum</code><code>Dapp</code>开发入门</a></li> 72 | </ul></li> 73 | </ul> 74 | 75 | <h2 id="1-如何在ipfs新增一个文件">1. 如何在IPFS新增一个文件</h2> 76 | 77 | <h3 id="1-1-新建file-txt文件">1.1 新建file.txt文件</h3> 78 | 79 | <p>打开终端,切换到桌面,新建一个文件夹<code>1121</code>,切换到<code>1121</code>中,通过<code>vi</code>新建一个文件<code>file.txt</code>,文件里面输入春哥微信号<code>liyc1215</code>保存并且退出。</p> 80 | 81 | <pre><code>localhost:Desktop yuechunli$ pwd 82 | /Users/liyuechun/Desktop 83 | localhost:Desktop yuechunli$ mkdir 1121 84 | localhost:Desktop yuechunli$ cd 1121/ 85 | localhost:1121 yuechunli$ vi file.txt 86 | localhost:1121 yuechunli$ cat file.txt 87 | liyc1215 88 | localhost:1121 yuechunli$ 89 | </code></pre> 90 | 91 | <h3 id="1-2-查看ipfs相关命令">1.2 查看ipfs相关命令</h3> 92 | 93 | <pre><code>localhost:1121 yuechunli$ ipfs help 94 | USAGE 95 | ipfs - Global p2p merkle-dag filesystem. 96 | 97 | ipfs [--config=&lt;config&gt; | -c] [--debug=&lt;debug&gt; | -D] [--help=&lt;help&gt;] [-h=&lt;h&gt;] [--local=&lt;local&gt; | -L] [--api=&lt;api&gt;] &lt;command&gt; ... 98 | 99 | SUBCOMMANDS 100 | BASIC COMMANDS 101 | init Initialize ipfs local configuration 102 | add &lt;path&gt; Add a file to IPFS 103 | cat &lt;ref&gt; Show IPFS object data 104 | get &lt;ref&gt; Download IPFS objects 105 | ls &lt;ref&gt; List links from an object 106 | refs &lt;ref&gt; List hashes of links from an object 107 | 108 | DATA STRUCTURE COMMANDS 109 | block Interact with raw blocks in the datastore 110 | object Interact with raw dag nodes 111 | files Interact with objects as if they were a unix filesystem 112 | dag Interact with IPLD documents (experimental) 113 | 114 | ADVANCED COMMANDS 115 | daemon Start a long-running daemon process 116 | mount Mount an IPFS read-only mountpoint 117 | resolve Resolve any type of name 118 | name Publish and resolve IPNS names 119 | key Create and list IPNS name keypairs 120 | dns Resolve DNS links 121 | pin Pin objects to local storage 122 | repo Manipulate the IPFS repository 123 | stats Various operational stats 124 | p2p Libp2p stream mounting 125 | filestore Manage the filestore (experimental) 126 | 127 | NETWORK COMMANDS 128 | id Show info about IPFS peers 129 | bootstrap Add or remove bootstrap peers 130 | swarm Manage connections to the p2p network 131 | dht Query the DHT for values or peers 132 | ping Measure the latency of a connection 133 | diag Print diagnostics 134 | 135 | TOOL COMMANDS 136 | config Manage configuration 137 | version Show ipfs version information 138 | update Download and apply go-ipfs updates 139 | commands List all available commands 140 | </code></pre> 141 | 142 | <h3 id="1-3-将file-txt添加到ipfs节点">1.3 将file.txt添加到ipfs节点</h3> 143 | 144 | <pre><code>localhost:1121 yuechunli$ ls 145 | file.txt 146 | localhost:1121 yuechunli$ ipfs add file.txt 147 | added QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T file.txt 148 | localhost:1121 yuechunli$ cat file.txt 149 | liyc1215 150 | localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T 151 | liyc1215 152 | localhost:1121 yuechunli$ 153 | </code></pre> 154 | 155 | <p>当执行完<code>ipfs add file.txt</code>这个命令以后,会将<code>file.txt</code>添加到<code>ipfs</code>当前的节点中,并且会对<code>file.txt</code>文件生成一个唯一的<code>hash</code><code>QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T</code>,如果想查看本地<code>ipfs</code>节点的数据,可以通过<code>ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T</code>进行查看。</p> 156 | 157 | <p><strong>⚠️:</strong>当我试图通过<code>http://ipfs.io/ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T</code>进行数据访问时,无法访问,如下图所示:</p> 158 | 159 | <p><img src="http://om1c35wrq.bkt.clouddn.com/fangwen.gif" alt="" /></p> 160 | 161 | <p><strong>⚠️:</strong>虽然数据已经添加到当前的你自己的<code>IPFS</code>节点中,但是并没有同步到<code>IPFS</code>网络,所以暂时在网络上无法访问。</p> 162 | 163 | <p><strong>⚠️:重要:接下来执行下面的命令同步节点数据到<code>IPFS</code>网络,再试图在网络上查看数据。</strong></p> 164 | 165 | <ul> 166 | <li>同步节点</li> 167 | </ul> 168 | 169 | <p>新建一个终端,执行<code>ipfs daemon</code>。</p> 170 | 171 | <pre><code>localhost:.ipfs yuechunli$ ipfs daemon 172 | Initializing daemon... 173 | Adjusting current ulimit to 2048... 174 | Successfully raised file descriptor limit to 2048. 175 | Swarm listening on /ip4/111.196.246.151/tcp/3637 176 | Swarm listening on /ip4/127.0.0.1/tcp/4001 177 | Swarm listening on /ip4/169.254.170.167/tcp/4001 178 | Swarm listening on /ip4/192.168.0.107/tcp/4001 179 | Swarm listening on /ip6/::1/tcp/4001 180 | API server listening on /ip4/127.0.0.1/tcp/5001 181 | Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080 182 | Daemon is ready 183 | </code></pre> 184 | 185 | <ul> 186 | <li>从<code>IPFS</code>网络查看数据</li> 187 | </ul> 188 | 189 | <p>浏览器访问<a href="https://ipfs.io/ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T">https://ipfs.io/ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T</a></p> 190 | 191 | <p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-105531@2x.png" alt="黎跃春 微信" /></p> 192 | 193 | <h2 id="2-通过ipfs创建目录存储文件">2. 通过ipfs创建目录存储文件</h2> 194 | 195 | <p>在着上面的步骤走,我们可以通过<code>ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T 196 | liyc1215</code>查看添加到<code>ipfs</code>网络的<code>file.txt</code>文件的内容,如下:</p> 197 | 198 | <pre><code>localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T 199 | liyc1215 200 | localhost:1121 yuechunli$ 201 | </code></pre> 202 | 203 | <p>当然,我们也可以通过<code>ipfs</code>的相关命令在<code>ipfs</code>的根目录下面创建文件夹,并且将<code>file.txt</code>文件<strong>移动</strong>或者<strong>拷贝</strong>到我们创建的文件夹中。</p> 204 | 205 | <p><strong>⚠️:cp不会改变文件hash,mv会改变hash寻址。</strong></p> 206 | 207 | <pre><code>localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T 208 | liyc1215 209 | localhost:1121 yuechunli$ ipfs files mkdir /LiYueChun 210 | localhost:1121 yuechunli$ ipfs files cp /ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T /LiYueChun/file.txt 211 | localhost:1121 yuechunli$ ipfs files ls / 212 | LiYueChun 213 | localhost:1121 yuechunli$ ipfs files ls /LiYueChun/ 214 | file.txt 215 | localhost:1121 yuechunli$ ipfs files read /LiYueChun/file.txt 216 | liyc1215 217 | localhost:1121 yuechunli$ 218 | </code></pre> 219 | 220 | <h2 id="3-如何在ipfs新增一个目录">3. 如何在IPFS新增一个目录</h2> 221 | 222 | <h3 id="3-1-使用ipfs-add-r可以上传一整个目录">3.1 使用ipfs add -r可以上传一整个目录</h3> 223 | 224 | <pre><code>localhost:1121 yuechunli$ ipfs add -r ipfs-tutorial/ 225 | added QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc ipfs-tutorial/contactme.txt 226 | added QmfKdWsguobA3aDPvSxLB3Bq4HMKyqKSgFr2NFUuVH8n31 ipfs-tutorial/eth-fabric.png 227 | added QmXe8jTxTh5MZP6BK5cnj19mXNTKVMzNyUJZUHuYyr5dk1 ipfs-tutorial/gongzhonghao.png 228 | added QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek ipfs-tutorial 229 | </code></pre> 230 | 231 | <h4 id="3-2-通过路径访问contactme-txt文件数据">3.2 通过路径访问contactme.txt文件数据</h4> 232 | 233 | <p>如果我们上传的是目录,那么可以通过下面几种方式访问到<code>contactme.txt</code>文件的数据。</p> 234 | 235 | <pre><code>localhost:1121 yuechunli$ ipfs cat QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc 236 | 微信:liyc1215 237 | 区块链技术交流群:348924182 238 | 公众号:区块链部落 239 | localhost:1121 yuechunli$ ipfs cat /ipfs/QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc 240 | 微信:liyc1215 241 | 区块链技术交流群:348924182 242 | 公众号:区块链部落 243 | localhost:1121 yuechunli$ ipfs cat /ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek/contactme.txt 244 | 微信:liyc1215 245 | 区块链技术交流群:348924182 246 | 公众号:区块链部落 247 | localhost:1121 yuechunli$ 248 | </code></pre> 249 | 250 | <h3 id="3-3-通过hash查看数据ipfs网络数据">3.3 通过Hash查看数据IPFS网络数据</h3> 251 | 252 | <ul> 253 | <li><strong>访问目录:</strong><a href="https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek">https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek</a></li> 254 | </ul> 255 | 256 | <p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-110959@2x.png" alt="" /></p> 257 | 258 | <ul> 259 | <li><p><strong>通过目录访问文件:</strong><a href="https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek/contactme.txt">https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek/contactme.txt</a> 260 | <img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-111019@2x.png" alt="" /></p></li> 261 | 262 | <li><p><strong>通过文件hash直接访问:</strong><a href="https://ipfs.io/ipfs/QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc">https://ipfs.io/ipfs/QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc</a></p></li> 263 | </ul> 264 | 265 | <p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-113047@2x.png" alt="" /></p> 266 | 267 | <h2 id="4-创建简易的网页发布到ipfs">4. 创建简易的网页发布到IPFS</h2> 268 | 269 | <p>在这里我先自己写一个简单的网页给大家演示,先在桌面新建一个<code>site</code>文件夹,然后按照下面的步骤在<code>site</code>文件夹中建立<code>index.html</code>和<code>style.css</code>文件。</p> 270 | 271 | <h3 id="4-1-创建一个index-html文件">4.1 创建一个index.html文件</h3> 272 | 273 | <pre><code>&lt;!DOCTYPE html&gt; 274 | &lt;html lang=&quot;en&quot;&gt; 275 | &lt;head&gt; 276 | &lt;meta charset=&quot;UTF-8&quot;&gt; 277 | &lt;title&gt;Hello IPFS!&lt;/title&gt; 278 | &lt;link rel=&quot;stylesheet&quot; href=&quot;./style.css&quot; /&gt; 279 | &lt;/head&gt; 280 | &lt;body&gt; 281 | &lt;h1&gt;Hello IPFS!&lt;/h1&gt; 282 | &lt;/body&gt; 283 | &lt;/html&gt; 284 | </code></pre> 285 | 286 | <h3 id="4-2-创建一个style-css文件">4.2 创建一个style.css文件</h3> 287 | 288 | <pre><code>h1 { 289 | color: green; 290 | } 291 | </code></pre> 292 | 293 | <h3 id="4-3-添加到ipfs">4.3 添加到ipfs</h3> 294 | 295 | <pre><code>localhost:Desktop yuechunli$ ipfs add -r site/ 296 | added QmWG5rbgT9H77TGq49RXNoqN8M7DNKMnMX425nkmCB6BjS site/index.html 297 | added QmfGLJ3mryLvicQqzdsghq4QRhptKJtBAPe7yDJxsBGSuy site/style.css 298 | added QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp site 299 | </code></pre> 300 | 301 | <p>最后一行是项目根目录的<code>hash</code>,你先通过<code>ipfs daemon</code>同步网络,然后可以通过<code>https://ipfs.io/ipfs/&lt;你的项目根目录hash&gt;</code>,即<code>https://ipfs.io/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp</code>访问项目。</p> 302 | 303 | <h3 id="4-4-网络同步">4.4 网络同步</h3> 304 | 305 | <pre><code>localhost:Desktop yuechunli$ ipfs daemon 306 | </code></pre> 307 | 308 | <h3 id="4-5-访问网站">4.5 访问网站</h3> 309 | 310 | <p>浏览器打开<a href="https://ipfs.io/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp">https://ipfs.io/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp</a>,效果图如下:</p> 311 | 312 | <p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-210721@2x.png" alt="" /></p> 313 | 314 | <h3 id="4-6-发布到ipns">4.6 发布到IPNS</h3> 315 | 316 | <p>当我们修改网站内容重新添加到<code>ipfs</code>时,<code>hash</code>会发生变化,当我们网站更新时,我们可以将网站发布到IPNS,在IPNS中,允许我们节点的域名空间中引用一个<code>IPFS hash</code>,也就是说我们可以通过节点<code>ID</code>对项目根目录的<code>IPFS HASH</code>进行绑定,以后我们访问网站时直接通过节点·ID<code>访问即可,当我们更新博客时,重新发布到</code>IPNS`即可。</p> 317 | 318 | <pre><code>localhost:~ yuechunli$ ipfs name publish QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp 319 | Published to QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP: /ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp 320 | localhost:~ yuechunli$ ipfs id 321 | { 322 | &quot;ID&quot;: &quot;QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP&quot; 323 | } 324 | </code></pre> 325 | 326 | <p>当我们执行<code>ipfs name publish</code>命令时,会返回我们的节点<code>ID</code>,你可以通过<code>ipfs id</code>进行查看验证是否是你的节点<code>ID</code>。</p> 327 | 328 | <p><strong>⚠️:验证</strong></p> 329 | 330 | <pre><code>$ ipfs name resolve &lt;peerId&gt; 331 | </code></pre> 332 | 333 | <pre><code>localhost:~ yuechunli$ ipfs name resolve QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP 334 | /ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp 335 | localhost:~ yuechunli$ 336 | </code></pre> 337 | 338 | <p><strong>⚠️:</strong>当然我们现在就可以通过<code>IPNS</code>进行访问了。</p> 339 | 340 | <pre><code>https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP 341 | </code></pre> 342 | 343 | <p><strong>⚠️⚠️⚠️:注意上面是ipns而不是ipfs。</strong></p> 344 | 345 | <p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-212123@2x.png" alt="" /></p> 346 | 347 | <p><strong>⚠️:如果你网站数据修改,需要重新发布到IPNS。</strong></p> 348 | 349 | <h2 id="5-发布个人博客">5. 发布个人博客</h2> 350 | 351 | <p>你可以通过<code>Hugo</code>按照官方文档创建一个漂亮的静态博客<a href="http://gohugo.io/getting-started/quick-start/">Hugo官方网站</a>,当然你也可以自己编写,或者使用其他开源项目搭建。</p> 352 | 353 | <h3 id="5-1-搭建静态博客">5.1 搭建静态博客</h3> 354 | 355 | <p>大家可以自己搭建,也可以直接下载我的博客源码直接搭建。</p> 356 | 357 | <p>源码地址:<a href="http://github.com/liyuechun/ipfs_blogger">http://github.com/liyuechun/ipfs_blogger</a></p> 358 | 359 | <h3 id="5-2-节点id替换">5.2 节点ID替换</h3> 360 | 361 | <ul> 362 | <li>查看你的节点ID</li> 363 | </ul> 364 | 365 | <pre><code>localhost:ipfs_pin yuechunli$ ipfs id 366 | { 367 | &quot;ID&quot;: &quot;《your peer id》&quot; 368 | } 369 | localhost:ipfs_pin yuechunli$ 370 | </code></pre> 371 | 372 | <p>在上面的源码中全局搜索将源码里面的<code>QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP</code>替换成你自己的<code>ID</code>。</p> 373 | 374 | <p>接下来重复<a href="#4-创建简易的网页发布到IPFS">4. 创建简易的网页发布到IPFS</a>的操作步骤即可。</p> 375 | 376 | <h3 id="5-3-浏览博客">5.3 浏览博客</h3> 377 | 378 | <p>浏览器打开<a href="https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/">https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/</a>查看项目效果。</p> 379 | 380 | <p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-215636@2x.png" alt="IPFS 博客项目效果图" /></p> 381 | 382 | <h2 id="6-下篇预报">6. 下篇预报</h2> 383 | 384 | <h3 id="6-1-ipfs-ethereum-dapp-开发入门">6.1 <code>ipfs + ethereum</code><code>Dapp</code>开发入门</h3> 385 | 386 | <h2 id="7-技术交流">7. 技术交流</h2> 387 | 388 | <ul> 389 | <li>区块链技术交流QQ群:<code>348924182</code></li> 390 | <li>进微信群请加微信:<code>liyc1215</code></li> 391 | <li>「区块链部落」官方公众号</li> 392 | </ul> 393 | 394 | <p><img src="http://om1c35wrq.bkt.clouddn.com/%E5%8C%BA%E5%9D%97%E9%93%BE%E9%83%A8%E8%90%BD.png" alt="" /></p> 395 | 396 | 397 | 398 | 399 | 400 | -------------------------------------------------------------------------------- /qrcode_for_gh.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyuechun/ipfs_blogger/7e72b78875adf5d23b344db3851654f931529ce8/qrcode_for_gh.jpg -------------------------------------------------------------------------------- /sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/2017/10/ipfs_first_post/ 7 | 2017-10-30T20:01:00+00:00 8 | 9 | 10 | 11 | https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/blog/ 12 | 2017-10-30T20:01:00+00:00 13 | 0 14 | 15 | 16 | 17 | https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/ 18 | 2017-10-30T20:01:00+00:00 19 | 0 20 | 21 | 22 | -------------------------------------------------------------------------------- /touch-icon-144-precomposed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liyuechun/ipfs_blogger/7e72b78875adf5d23b344db3851654f931529ce8/touch-icon-144-precomposed.png --------------------------------------------------------------------------------