diff --git a/2017/10/ipfs_first_post/index.html b/2017/10/ipfs_first_post/index.html new file mode 100644 index 0000000..64a65f6 --- /dev/null +++ b/2017/10/ipfs_first_post/index.html @@ -0,0 +1,484 @@ + + + + + + + + + + + + 【IPFS + 区块链 系列】 入门篇 - IPFS+IPNS+个人博客搭建 · 区块链部落 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+

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

+ + + + +
+

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

+ +

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

+ +

微信:liyc1215

+ +

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

+
+ +

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

+ +

目录

+ + + +

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

+ +

1.1 新建file.txt文件

+ +

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

+ +
localhost:Desktop yuechunli$ pwd
+/Users/liyuechun/Desktop
+localhost:Desktop yuechunli$ mkdir 1121
+localhost:Desktop yuechunli$ cd 1121/
+localhost:1121 yuechunli$ vi file.txt
+localhost:1121 yuechunli$ cat file.txt
+liyc1215
+localhost:1121 yuechunli$
+
+ +

1.2 查看ipfs相关命令

+ +
localhost:1121 yuechunli$ ipfs help
+USAGE
+  ipfs - Global p2p merkle-dag filesystem.
+
+  ipfs [--config=<config> | -c] [--debug=<debug> | -D] [--help=<help>] [-h=<h>] [--local=<local> | -L] [--api=<api>] <command> ...
+
+SUBCOMMANDS
+  BASIC COMMANDS
+    init          Initialize ipfs local configuration
+    add <path>    Add a file to IPFS
+    cat <ref>     Show IPFS object data
+    get <ref>     Download IPFS objects
+    ls <ref>      List links from an object
+    refs <ref>    List hashes of links from an object
+
+  DATA STRUCTURE COMMANDS
+    block         Interact with raw blocks in the datastore
+    object        Interact with raw dag nodes
+    files         Interact with objects as if they were a unix filesystem
+    dag           Interact with IPLD documents (experimental)
+
+  ADVANCED COMMANDS
+    daemon        Start a long-running daemon process
+    mount         Mount an IPFS read-only mountpoint
+    resolve       Resolve any type of name
+    name          Publish and resolve IPNS names
+    key           Create and list IPNS name keypairs
+    dns           Resolve DNS links
+    pin           Pin objects to local storage
+    repo          Manipulate the IPFS repository
+    stats         Various operational stats
+    p2p           Libp2p stream mounting
+    filestore     Manage the filestore (experimental)
+
+  NETWORK COMMANDS
+    id            Show info about IPFS peers
+    bootstrap     Add or remove bootstrap peers
+    swarm         Manage connections to the p2p network
+    dht           Query the DHT for values or peers
+    ping          Measure the latency of a connection
+    diag          Print diagnostics
+
+  TOOL COMMANDS
+    config        Manage configuration
+    version       Show ipfs version information
+    update        Download and apply go-ipfs updates
+    commands      List all available commands
+
+ +

1.3 将file.txt添加到ipfs节点

+ +
localhost:1121 yuechunli$ ls
+file.txt
+localhost:1121 yuechunli$ ipfs add file.txt
+added QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T file.txt
+localhost:1121 yuechunli$ cat file.txt
+liyc1215
+localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T
+liyc1215
+localhost:1121 yuechunli$
+
+ +

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

+ +

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

+ +

+ +

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

+ +

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

+ + + +

新建一个终端,执行ipfs daemon

+ +
localhost:.ipfs yuechunli$ ipfs daemon
+Initializing daemon...
+Adjusting current ulimit to 2048...
+Successfully raised file descriptor limit to 2048.
+Swarm listening on /ip4/111.196.246.151/tcp/3637
+Swarm listening on /ip4/127.0.0.1/tcp/4001
+Swarm listening on /ip4/169.254.170.167/tcp/4001
+Swarm listening on /ip4/192.168.0.107/tcp/4001
+Swarm listening on /ip6/::1/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
+
+ + + +

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

+ +

黎跃春 微信

+ +

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

+ +

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

+ +
localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T
+liyc1215
+localhost:1121 yuechunli$
+
+ +

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

+ +

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

+ +
localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T
+liyc1215
+localhost:1121 yuechunli$ ipfs files mkdir /LiYueChun
+localhost:1121 yuechunli$ ipfs files cp /ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T /LiYueChun/file.txt
+localhost:1121 yuechunli$ ipfs files ls /
+LiYueChun
+localhost:1121 yuechunli$ ipfs files ls /LiYueChun/
+file.txt
+localhost:1121 yuechunli$ ipfs files read /LiYueChun/file.txt
+liyc1215
+localhost:1121 yuechunli$
+
+ +

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

+ +

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

+ +
localhost:1121 yuechunli$ ipfs add -r ipfs-tutorial/
+added QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc ipfs-tutorial/contactme.txt
+added QmfKdWsguobA3aDPvSxLB3Bq4HMKyqKSgFr2NFUuVH8n31 ipfs-tutorial/eth-fabric.png
+added QmXe8jTxTh5MZP6BK5cnj19mXNTKVMzNyUJZUHuYyr5dk1 ipfs-tutorial/gongzhonghao.png
+added QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek ipfs-tutorial
+
+ +

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

+ +

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

+ +
localhost:1121 yuechunli$ ipfs cat QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc
+微信:liyc1215
+区块链技术交流群:348924182
+公众号:区块链部落
+localhost:1121 yuechunli$ ipfs cat /ipfs/QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc
+微信:liyc1215
+区块链技术交流群:348924182
+公众号:区块链部落
+localhost:1121 yuechunli$ ipfs cat /ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek/contactme.txt
+微信:liyc1215
+区块链技术交流群:348924182
+公众号:区块链部落
+localhost:1121 yuechunli$
+
+ +

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

+ + + +

+ + + +

+ +

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

+ +

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

+ +

4.1 创建一个index.html文件

+ +
<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8">
+  <title>Hello IPFS!</title>
+  <link rel="stylesheet" href="./style.css" />
+</head>
+<body>
+  <h1>Hello IPFS!</h1>
+</body>
+</html>
+
+ +

4.2 创建一个style.css文件

+ +
h1 {
+  color: green;
+}
+
+ +

4.3 添加到ipfs

+ +
localhost:Desktop yuechunli$ ipfs add -r site/
+added QmWG5rbgT9H77TGq49RXNoqN8M7DNKMnMX425nkmCB6BjS site/index.html
+added QmfGLJ3mryLvicQqzdsghq4QRhptKJtBAPe7yDJxsBGSuy site/style.css
+added QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp site
+
+ +

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

+ +

4.4 网络同步

+ +
localhost:Desktop yuechunli$ ipfs daemon
+
+ +

4.5 访问网站

+ +

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

+ +

+ +

4.6 发布到IPNS

+ +

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

+ +
localhost:~ yuechunli$ ipfs name publish QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp
+Published to QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP: /ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp
+localhost:~ yuechunli$ ipfs id
+{
+	"ID": "QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP"
+}
+
+ +

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

+ +

⚠️:验证

+ +
$ ipfs name resolve <peerId>
+
+ +
localhost:~ yuechunli$ ipfs name resolve QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP
+/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp
+localhost:~ yuechunli$
+
+ +

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

+ +
https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP
+
+ +

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

+ +

+ +

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

+ +

5. 发布个人博客

+ +

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

+ +

5.1 搭建静态博客

+ +

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

+ +

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

+ +

5.2 节点ID替换

+ + + +
localhost:ipfs_pin yuechunli$ ipfs id
+{
+	"ID": "《your peer id》"
+}
+localhost:ipfs_pin yuechunli$
+
+ +

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

+ +

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

+ +

5.3 浏览博客

+ +

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

+ +

IPFS 博客项目效果图

+ +

6. 下篇预报

+ +

6.1 ipfs + ethereumDapp开发入门

+ +

7. 技术交流

+ + + +

+ + + + + +
+ + +
+
+ +w + diff --git a/404.html b/404.html new file mode 100644 index 0000000..681e7ec --- /dev/null +++ b/404.html @@ -0,0 +1,5 @@ + + + Nope. + + \ No newline at end of file diff --git a/README.md b/README.md index 49a5dcf..f9d50b8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,373 @@ -# ipfs_blogger -【IPFS + 区块链 系列】 入门篇 - IPFS+IPNS+个人博客搭建 +# 【IPFS + 区块链 系列】 入门篇 - IPFS+IPNS+个人博客搭建 + +> 孔壹学院:国内区块链职业教育引领品牌。 +> +> 作者:黎跃春,孔壹学院创始人,区块链、高可用架构师 +> +> 微信:liyc1215 +> +> 区块链博客:http://liyuechun.org + +在阅读这篇文章之前,你需要先学习[【IPFS + 区块链 系列】 入门篇 - IPFS环境配置](http://liyuechun.org/2017/11/20/ipfs-blockchain/)这篇文章。 + +## 目录 + + +- [1. 如何在IPFS新增一个文件](#1-如何在IPFS新增一个文件) + - [1.1 新建file.txt文件](#11-新建file.txt文件) + - [1.2 查看ipfs相关命令](#12-查看ipfs相关命令) + - [1.3 将file.txt添加到ipfs节点](#13-将file.txt添加到ipfs节点) +- [2. 通过ipfs创建目录存储文件](#2-通过ipfs创建目录存储文件) +- [3. 如何在IPFS新增一个目录](#3-如何在IPFS新增一个目录) + - [3.1 使用ipfs add -r可以上传一整个目录](#31-使用ipfs add -r可以上传一整个目录) + - [3.2 通过路径访问contactme.txt文件数据](#32-通过路径访问contactme.txt文件数据) + - [3.3 通过Hash查看数据IPFS网络数据](#33-通过Hash查看数据IPFS网络数据) +- [4. 创建简易的网页发布到IPFS](#4-创建简易的网页发布到IPFS) + - [4.1 创建一个index.html文件](#41-创建一个index.html文件) + - [4.2 创建一个style.css文件](#42-创建一个style.css文件) + - [4.3 添加到ipfs](#43-添加到ipfs) + - [4.4 网络同步](#44-网络同步) + - [4.5 访问网站](#45-访问网站) + - [4.6 发布到IPNS](#46-发布到IPNS) +- [5. 发布个人博客](#5-发布个人博客) + - [5.1 搭建静态博客](#51-搭建静态博客) + - [5.2 节点ID替换](#52-节点ID替换) + - [5.3 浏览博客](#53-浏览博客) +- [6. 下篇预报](#6-下篇预报) + - [6.1 `ipfs + ethereum``Dapp`开发入门](#61-`ipfs + ethereum``Dapp`开发入门) + + +## 1. 如何在IPFS新增一个文件 + +### 1.1 新建file.txt文件 + +打开终端,切换到桌面,新建一个文件夹`1121`,切换到`1121`中,通过`vi`新建一个文件`file.txt`,文件里面输入春哥微信号`liyc1215`保存并且退出。 + +``` +localhost:Desktop yuechunli$ pwd +/Users/liyuechun/Desktop +localhost:Desktop yuechunli$ mkdir 1121 +localhost:Desktop yuechunli$ cd 1121/ +localhost:1121 yuechunli$ vi file.txt +localhost:1121 yuechunli$ cat file.txt +liyc1215 +localhost:1121 yuechunli$ +``` + +### 1.2 查看ipfs相关命令 + +``` +localhost:1121 yuechunli$ ipfs help +USAGE + ipfs - Global p2p merkle-dag filesystem. + + ipfs [--config= | -c] [--debug= | -D] [--help=] [-h=] [--local= | -L] [--api=] ... + +SUBCOMMANDS + BASIC COMMANDS + init Initialize ipfs local configuration + add Add a file to IPFS + cat Show IPFS object data + get Download IPFS objects + ls List links from an object + refs List hashes of links from an object + + DATA STRUCTURE COMMANDS + block Interact with raw blocks in the datastore + object Interact with raw dag nodes + files Interact with objects as if they were a unix filesystem + dag Interact with IPLD documents (experimental) + + ADVANCED COMMANDS + daemon Start a long-running daemon process + mount Mount an IPFS read-only mountpoint + resolve Resolve any type of name + name Publish and resolve IPNS names + key Create and list IPNS name keypairs + dns Resolve DNS links + pin Pin objects to local storage + repo Manipulate the IPFS repository + stats Various operational stats + p2p Libp2p stream mounting + filestore Manage the filestore (experimental) + + NETWORK COMMANDS + id Show info about IPFS peers + bootstrap Add or remove bootstrap peers + swarm Manage connections to the p2p network + dht Query the DHT for values or peers + ping Measure the latency of a connection + diag Print diagnostics + + TOOL COMMANDS + config Manage configuration + version Show ipfs version information + update Download and apply go-ipfs updates + commands List all available commands +``` + +### 1.3 将file.txt添加到ipfs节点 + +``` +localhost:1121 yuechunli$ ls +file.txt +localhost:1121 yuechunli$ ipfs add file.txt +added QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T file.txt +localhost:1121 yuechunli$ cat file.txt +liyc1215 +localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T +liyc1215 +localhost:1121 yuechunli$ +``` + +当执行完`ipfs add file.txt`这个命令以后,会将`file.txt`添加到`ipfs`当前的节点中,并且会对`file.txt`文件生成一个唯一的`hash``QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T`,如果想查看本地`ipfs`节点的数据,可以通过`ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T`进行查看。 + +**⚠️:**当我试图通过`http://ipfs.io/ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T`进行数据访问时,无法访问,如下图所示: + +![](http://om1c35wrq.bkt.clouddn.com/fangwen.gif) + +**⚠️:**虽然数据已经添加到当前的你自己的`IPFS`节点中,但是并没有同步到`IPFS`网络,所以暂时在网络上无法访问。 + +**⚠️:重要:接下来执行下面的命令同步节点数据到`IPFS`网络,再试图在网络上查看数据。** + +- 同步节点 + +新建一个终端,执行`ipfs daemon`。 + +``` +localhost:.ipfs yuechunli$ ipfs daemon +Initializing daemon... +Adjusting current ulimit to 2048... +Successfully raised file descriptor limit to 2048. +Swarm listening on /ip4/111.196.246.151/tcp/3637 +Swarm listening on /ip4/127.0.0.1/tcp/4001 +Swarm listening on /ip4/169.254.170.167/tcp/4001 +Swarm listening on /ip4/192.168.0.107/tcp/4001 +Swarm listening on /ip6/::1/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 +``` + +- 从`IPFS`网络查看数据 + +浏览器访问[https://ipfs.io/ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T](https://ipfs.io/ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T) + +![黎跃春 微信](http://om1c35wrq.bkt.clouddn.com/WX20171121-105531@2x.png) + + +## 2. 通过ipfs创建目录存储文件 + +在着上面的步骤走,我们可以通过`ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T +liyc1215`查看添加到`ipfs`网络的`file.txt`文件的内容,如下: + +``` +localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T +liyc1215 +localhost:1121 yuechunli$ +``` + +当然,我们也可以通过`ipfs`的相关命令在`ipfs`的根目录下面创建文件夹,并且将`file.txt`文件**移动**或者**拷贝**到我们创建的文件夹中。 + +**⚠️:cp不会改变文件hash,mv会改变hash寻址。** + +``` +localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T +liyc1215 +localhost:1121 yuechunli$ ipfs files mkdir /LiYueChun +localhost:1121 yuechunli$ ipfs files cp /ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T /LiYueChun/file.txt +localhost:1121 yuechunli$ ipfs files ls / +LiYueChun +localhost:1121 yuechunli$ ipfs files ls /LiYueChun/ +file.txt +localhost:1121 yuechunli$ ipfs files read /LiYueChun/file.txt +liyc1215 +localhost:1121 yuechunli$ +``` + + + +## 3. 如何在IPFS新增一个目录 + +### 3.1 使用ipfs add -r可以上传一整个目录 + +``` +localhost:1121 yuechunli$ ipfs add -r ipfs-tutorial/ +added QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc ipfs-tutorial/contactme.txt +added QmfKdWsguobA3aDPvSxLB3Bq4HMKyqKSgFr2NFUuVH8n31 ipfs-tutorial/eth-fabric.png +added QmXe8jTxTh5MZP6BK5cnj19mXNTKVMzNyUJZUHuYyr5dk1 ipfs-tutorial/gongzhonghao.png +added QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek ipfs-tutorial +``` + +#### 3.2 通过路径访问contactme.txt文件数据 + +如果我们上传的是目录,那么可以通过下面几种方式访问到`contactme.txt`文件的数据。 + +``` +localhost:1121 yuechunli$ ipfs cat QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc +微信:liyc1215 +区块链技术交流群:348924182 +公众号:区块链部落 +localhost:1121 yuechunli$ ipfs cat /ipfs/QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc +微信:liyc1215 +区块链技术交流群:348924182 +公众号:区块链部落 +localhost:1121 yuechunli$ ipfs cat /ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek/contactme.txt +微信:liyc1215 +区块链技术交流群:348924182 +公众号:区块链部落 +localhost:1121 yuechunli$ +``` + +### 3.3 通过Hash查看数据IPFS网络数据 + +- **访问目录:**[https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek](https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek) + +![](http://om1c35wrq.bkt.clouddn.com/WX20171121-110959@2x.png) + +- **通过目录访问文件:**[https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek/contactme.txt](https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek/contactme.txt) +![](http://om1c35wrq.bkt.clouddn.com/WX20171121-111019@2x.png) + +- **通过文件hash直接访问:**[https://ipfs.io/ipfs/QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc](https://ipfs.io/ipfs/QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc) + +![](http://om1c35wrq.bkt.clouddn.com/WX20171121-113047@2x.png) + + +## 4. 创建简易的网页发布到IPFS + + +在这里我先自己写一个简单的网页给大家演示,先在桌面新建一个`site`文件夹,然后按照下面的步骤在`site`文件夹中建立`index.html`和`style.css`文件。 + +### 4.1 创建一个index.html文件 + +``` + + + + + Hello IPFS! + + + +

Hello IPFS!

+ + +``` + +### 4.2 创建一个style.css文件 + +``` +h1 { + color: green; +} +``` + +### 4.3 添加到ipfs + +``` +localhost:Desktop yuechunli$ ipfs add -r site/ +added QmWG5rbgT9H77TGq49RXNoqN8M7DNKMnMX425nkmCB6BjS site/index.html +added QmfGLJ3mryLvicQqzdsghq4QRhptKJtBAPe7yDJxsBGSuy site/style.css +added QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp site +``` + +最后一行是项目根目录的`hash`,你先通过`ipfs daemon`同步网络,然后可以通过`https://ipfs.io/ipfs/<你的项目根目录hash>`,即`https://ipfs.io/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp`访问项目。 + +### 4.4 网络同步 + +``` +localhost:Desktop yuechunli$ ipfs daemon +``` + +### 4.5 访问网站 + +浏览器打开[https://ipfs.io/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp](https://ipfs.io/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp),效果图如下: + +![](http://om1c35wrq.bkt.clouddn.com/WX20171121-210721@2x.png) + +### 4.6 发布到IPNS + +当我们修改网站内容重新添加到`ipfs`时,`hash`会发生变化,当我们网站更新时,我们可以将网站发布到IPNS,在IPNS中,允许我们节点的域名空间中引用一个`IPFS hash`,也就是说我们可以通过节点`ID`对项目根目录的`IPFS HASH`进行绑定,以后我们访问网站时直接通过节点·ID`访问即可,当我们更新博客时,重新发布到`IPNS`即可。 + +``` +localhost:~ yuechunli$ ipfs name publish QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp +Published to QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP: /ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp +localhost:~ yuechunli$ ipfs id +{ + "ID": "QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP" +} +``` + +当我们执行`ipfs name publish`命令时,会返回我们的节点`ID`,你可以通过`ipfs id`进行查看验证是否是你的节点`ID`。 + +**⚠️:验证** + +``` +$ ipfs name resolve +``` + +``` +localhost:~ yuechunli$ ipfs name resolve QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP +/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp +localhost:~ yuechunli$ +``` + +**⚠️:**当然我们现在就可以通过`IPNS`进行访问了。 + +``` +https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP +``` + +**⚠️⚠️⚠️:注意上面是ipns而不是ipfs。** + +![](http://om1c35wrq.bkt.clouddn.com/WX20171121-212123@2x.png) + + +**⚠️:如果你网站数据修改,需要重新发布到IPNS。** + +## 5. 发布个人博客 + +你可以通过`Hugo`按照官方文档创建一个漂亮的静态博客[Hugo官方网站](http://gohugo.io/getting-started/quick-start/),当然你也可以自己编写,或者使用其他开源项目搭建。 + +### 5.1 搭建静态博客 + +大家可以自己搭建,也可以直接下载我的博客源码直接搭建。 + +源码地址:[http://github.com/liyuechun/ipfs_blogger](http://github.com/liyuechun/ipfs_blogger) + + +### 5.2 节点ID替换 + +- 查看你的节点ID + +``` +localhost:ipfs_pin yuechunli$ ipfs id +{ + "ID": "《your peer id》" +} +localhost:ipfs_pin yuechunli$ +``` + +在上面的源码中全局搜索将源码里面的`QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP`替换成你自己的`ID`。 + +接下来重复[4. 创建简易的网页发布到IPFS](#4-创建简易的网页发布到IPFS)的操作步骤即可。 + +### 5.3 浏览博客 + +浏览器打开[https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/](https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/)查看项目效果。 + +![IPFS 博客项目效果图](http://om1c35wrq.bkt.clouddn.com/WX20171121-215636@2x.png) + +## 6. 下篇预报 + +### 6.1 `ipfs + ethereum``Dapp`开发入门 + +## 7. 技术交流 + +- 区块链技术交流QQ群:`348924182` +- 进微信群请加微信:`liyc1215` +- 「区块链部落」官方公众号 + +![](http://om1c35wrq.bkt.clouddn.com/%E5%8C%BA%E5%9D%97%E9%93%BE%E9%83%A8%E8%90%BD.png) + + diff --git a/blog/index.html b/blog/index.html new file mode 100644 index 0000000..769feb8 --- /dev/null +++ b/blog/index.html @@ -0,0 +1,88 @@ + + + + + + + + + + + + Blogs · 区块链部落 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/blog/index.xml b/blog/index.xml new file mode 100644 index 0000000..9c18b2b --- /dev/null +++ b/blog/index.xml @@ -0,0 +1,400 @@ + + + + 区块链部落 + Hugo + https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/blog/ + en-us + 黎跃春 + 2017 liyuechun + Mon, 30 Oct 2017 20:01:00 UTC + + + + 【IPFS + 区块链 系列】 入门篇 - IPFS+IPNS+个人博客搭建 + https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/2017/10/ipfs_first_post/ + Mon, 30 Oct 2017 20:01:00 UTC + 黎跃春 + https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/2017/10/ipfs_first_post/ + + +<blockquote> +<p>孔壹学院:国内区块链职业教育引领品牌。</p> + +<p>作者:黎跃春,孔壹学院创始人,区块链、高可用架构师</p> + +<p>微信:liyc1215</p> + +<p>区块链博客:<a href="http://liyuechun.org">http://liyuechun.org</a></p> +</blockquote> + +<p>在阅读这篇文章之前,你需要先学习<a href="http://liyuechun.org/2017/11/20/ipfs-blockchain/">【IPFS + 区块链 系列】 入门篇 - IPFS环境配置</a>这篇文章。</p> + +<h2 id="目录">目录</h2> + +<ul> +<li><a href="#1-如何在IPFS新增一个文件">1. 如何在IPFS新增一个文件</a> + +<ul> +<li><a href="#11-新建file.txt文件">1.1 新建file.txt文件</a></li> +<li><a href="#12-查看ipfs相关命令">1.2 查看ipfs相关命令</a></li> +<li><a href="#13-将file.txt添加到ipfs节点">1.3 将file.txt添加到ipfs节点</a></li> +</ul></li> +<li><a href="#2-通过ipfs创建目录存储文件">2. 通过ipfs创建目录存储文件</a></li> +<li><a href="#3-如何在IPFS新增一个目录">3. 如何在IPFS新增一个目录</a> + +<ul> +<li><a href="#31-使用ipfs add -r可以上传一整个目录">3.1 使用ipfs add -r可以上传一整个目录</a></li> +<li><a href="#32-通过路径访问contactme.txt文件数据">3.2 通过路径访问contactme.txt文件数据</a></li> +<li><a href="#33-通过Hash查看数据IPFS网络数据">3.3 通过Hash查看数据IPFS网络数据</a></li> +</ul></li> +<li><a href="#4-创建简易的网页发布到IPFS">4. 创建简易的网页发布到IPFS</a> + +<ul> +<li><a href="#41-创建一个index.html文件">4.1 创建一个index.html文件</a></li> +<li><a href="#42-创建一个style.css文件">4.2 创建一个style.css文件</a></li> +<li><a href="#43-添加到ipfs">4.3 添加到ipfs</a></li> +<li><a href="#44-网络同步">4.4 网络同步</a></li> +<li><a href="#45-访问网站">4.5 访问网站</a></li> +<li><a href="#46-发布到IPNS">4.6 发布到IPNS</a></li> +</ul></li> +<li><a href="#5-发布个人博客">5. 发布个人博客</a> + +<ul> +<li><a href="#51-搭建静态博客">5.1 搭建静态博客</a></li> +<li><a href="#52-节点ID替换">5.2 节点ID替换</a></li> +<li><a href="#53-浏览博客">5.3 浏览博客</a></li> +</ul></li> +<li><a href="#6-下篇预报">6. 下篇预报</a> + +<ul> +<li><a href="#61-`ipfs + ethereum``Dapp`开发入门">6.1 <code>ipfs + ethereum</code><code>Dapp</code>开发入门</a></li> +</ul></li> +</ul> + +<h2 id="1-如何在ipfs新增一个文件">1. 如何在IPFS新增一个文件</h2> + +<h3 id="1-1-新建file-txt文件">1.1 新建file.txt文件</h3> + +<p>打开终端,切换到桌面,新建一个文件夹<code>1121</code>,切换到<code>1121</code>中,通过<code>vi</code>新建一个文件<code>file.txt</code>,文件里面输入春哥微信号<code>liyc1215</code>保存并且退出。</p> + +<pre><code>localhost:Desktop yuechunli$ pwd +/Users/liyuechun/Desktop +localhost:Desktop yuechunli$ mkdir 1121 +localhost:Desktop yuechunli$ cd 1121/ +localhost:1121 yuechunli$ vi file.txt +localhost:1121 yuechunli$ cat file.txt +liyc1215 +localhost:1121 yuechunli$ +</code></pre> + +<h3 id="1-2-查看ipfs相关命令">1.2 查看ipfs相关命令</h3> + +<pre><code>localhost:1121 yuechunli$ ipfs help +USAGE + ipfs - Global p2p merkle-dag filesystem. + + 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; ... + +SUBCOMMANDS + BASIC COMMANDS + init Initialize ipfs local configuration + add &lt;path&gt; Add a file to IPFS + cat &lt;ref&gt; Show IPFS object data + get &lt;ref&gt; Download IPFS objects + ls &lt;ref&gt; List links from an object + refs &lt;ref&gt; List hashes of links from an object + + DATA STRUCTURE COMMANDS + block Interact with raw blocks in the datastore + object Interact with raw dag nodes + files Interact with objects as if they were a unix filesystem + dag Interact with IPLD documents (experimental) + + ADVANCED COMMANDS + daemon Start a long-running daemon process + mount Mount an IPFS read-only mountpoint + resolve Resolve any type of name + name Publish and resolve IPNS names + key Create and list IPNS name keypairs + dns Resolve DNS links + pin Pin objects to local storage + repo Manipulate the IPFS repository + stats Various operational stats + p2p Libp2p stream mounting + filestore Manage the filestore (experimental) + + NETWORK COMMANDS + id Show info about IPFS peers + bootstrap Add or remove bootstrap peers + swarm Manage connections to the p2p network + dht Query the DHT for values or peers + ping Measure the latency of a connection + diag Print diagnostics + + TOOL COMMANDS + config Manage configuration + version Show ipfs version information + update Download and apply go-ipfs updates + commands List all available commands +</code></pre> + +<h3 id="1-3-将file-txt添加到ipfs节点">1.3 将file.txt添加到ipfs节点</h3> + +<pre><code>localhost:1121 yuechunli$ ls +file.txt +localhost:1121 yuechunli$ ipfs add file.txt +added QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T file.txt +localhost:1121 yuechunli$ cat file.txt +liyc1215 +localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T +liyc1215 +localhost:1121 yuechunli$ +</code></pre> + +<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> + +<p><strong>⚠️:</strong>当我试图通过<code>http://ipfs.io/ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T</code>进行数据访问时,无法访问,如下图所示:</p> + +<p><img src="http://om1c35wrq.bkt.clouddn.com/fangwen.gif" alt="" /></p> + +<p><strong>⚠️:</strong>虽然数据已经添加到当前的你自己的<code>IPFS</code>节点中,但是并没有同步到<code>IPFS</code>网络,所以暂时在网络上无法访问。</p> + +<p><strong>⚠️:重要:接下来执行下面的命令同步节点数据到<code>IPFS</code>网络,再试图在网络上查看数据。</strong></p> + +<ul> +<li>同步节点</li> +</ul> + +<p>新建一个终端,执行<code>ipfs daemon</code>。</p> + +<pre><code>localhost:.ipfs yuechunli$ ipfs daemon +Initializing daemon... +Adjusting current ulimit to 2048... +Successfully raised file descriptor limit to 2048. +Swarm listening on /ip4/111.196.246.151/tcp/3637 +Swarm listening on /ip4/127.0.0.1/tcp/4001 +Swarm listening on /ip4/169.254.170.167/tcp/4001 +Swarm listening on /ip4/192.168.0.107/tcp/4001 +Swarm listening on /ip6/::1/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 +</code></pre> + +<ul> +<li>从<code>IPFS</code>网络查看数据</li> +</ul> + +<p>浏览器访问<a href="https://ipfs.io/ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T">https://ipfs.io/ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T</a></p> + +<p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-105531@2x.png" alt="黎跃春 微信" /></p> + +<h2 id="2-通过ipfs创建目录存储文件">2. 通过ipfs创建目录存储文件</h2> + +<p>在着上面的步骤走,我们可以通过<code>ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T +liyc1215</code>查看添加到<code>ipfs</code>网络的<code>file.txt</code>文件的内容,如下:</p> + +<pre><code>localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T +liyc1215 +localhost:1121 yuechunli$ +</code></pre> + +<p>当然,我们也可以通过<code>ipfs</code>的相关命令在<code>ipfs</code>的根目录下面创建文件夹,并且将<code>file.txt</code>文件<strong>移动</strong>或者<strong>拷贝</strong>到我们创建的文件夹中。</p> + +<p><strong>⚠️:cp不会改变文件hash,mv会改变hash寻址。</strong></p> + +<pre><code>localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T +liyc1215 +localhost:1121 yuechunli$ ipfs files mkdir /LiYueChun +localhost:1121 yuechunli$ ipfs files cp /ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T /LiYueChun/file.txt +localhost:1121 yuechunli$ ipfs files ls / +LiYueChun +localhost:1121 yuechunli$ ipfs files ls /LiYueChun/ +file.txt +localhost:1121 yuechunli$ ipfs files read /LiYueChun/file.txt +liyc1215 +localhost:1121 yuechunli$ +</code></pre> + +<h2 id="3-如何在ipfs新增一个目录">3. 如何在IPFS新增一个目录</h2> + +<h3 id="3-1-使用ipfs-add-r可以上传一整个目录">3.1 使用ipfs add -r可以上传一整个目录</h3> + +<pre><code>localhost:1121 yuechunli$ ipfs add -r ipfs-tutorial/ +added QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc ipfs-tutorial/contactme.txt +added QmfKdWsguobA3aDPvSxLB3Bq4HMKyqKSgFr2NFUuVH8n31 ipfs-tutorial/eth-fabric.png +added QmXe8jTxTh5MZP6BK5cnj19mXNTKVMzNyUJZUHuYyr5dk1 ipfs-tutorial/gongzhonghao.png +added QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek ipfs-tutorial +</code></pre> + +<h4 id="3-2-通过路径访问contactme-txt文件数据">3.2 通过路径访问contactme.txt文件数据</h4> + +<p>如果我们上传的是目录,那么可以通过下面几种方式访问到<code>contactme.txt</code>文件的数据。</p> + +<pre><code>localhost:1121 yuechunli$ ipfs cat QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc +微信:liyc1215 +区块链技术交流群:348924182 +公众号:区块链部落 +localhost:1121 yuechunli$ ipfs cat /ipfs/QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc +微信:liyc1215 +区块链技术交流群:348924182 +公众号:区块链部落 +localhost:1121 yuechunli$ ipfs cat /ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek/contactme.txt +微信:liyc1215 +区块链技术交流群:348924182 +公众号:区块链部落 +localhost:1121 yuechunli$ +</code></pre> + +<h3 id="3-3-通过hash查看数据ipfs网络数据">3.3 通过Hash查看数据IPFS网络数据</h3> + +<ul> +<li><strong>访问目录:</strong><a href="https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek">https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek</a></li> +</ul> + +<p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-110959@2x.png" alt="" /></p> + +<ul> +<li><p><strong>通过目录访问文件:</strong><a href="https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek/contactme.txt">https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek/contactme.txt</a> +<img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-111019@2x.png" alt="" /></p></li> + +<li><p><strong>通过文件hash直接访问:</strong><a href="https://ipfs.io/ipfs/QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc">https://ipfs.io/ipfs/QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc</a></p></li> +</ul> + +<p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-113047@2x.png" alt="" /></p> + +<h2 id="4-创建简易的网页发布到ipfs">4. 创建简易的网页发布到IPFS</h2> + +<p>在这里我先自己写一个简单的网页给大家演示,先在桌面新建一个<code>site</code>文件夹,然后按照下面的步骤在<code>site</code>文件夹中建立<code>index.html</code>和<code>style.css</code>文件。</p> + +<h3 id="4-1-创建一个index-html文件">4.1 创建一个index.html文件</h3> + +<pre><code>&lt;!DOCTYPE html&gt; +&lt;html lang=&quot;en&quot;&gt; +&lt;head&gt; + &lt;meta charset=&quot;UTF-8&quot;&gt; + &lt;title&gt;Hello IPFS!&lt;/title&gt; + &lt;link rel=&quot;stylesheet&quot; href=&quot;./style.css&quot; /&gt; +&lt;/head&gt; +&lt;body&gt; + &lt;h1&gt;Hello IPFS!&lt;/h1&gt; +&lt;/body&gt; +&lt;/html&gt; +</code></pre> + +<h3 id="4-2-创建一个style-css文件">4.2 创建一个style.css文件</h3> + +<pre><code>h1 { + color: green; +} +</code></pre> + +<h3 id="4-3-添加到ipfs">4.3 添加到ipfs</h3> + +<pre><code>localhost:Desktop yuechunli$ ipfs add -r site/ +added QmWG5rbgT9H77TGq49RXNoqN8M7DNKMnMX425nkmCB6BjS site/index.html +added QmfGLJ3mryLvicQqzdsghq4QRhptKJtBAPe7yDJxsBGSuy site/style.css +added QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp site +</code></pre> + +<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> + +<h3 id="4-4-网络同步">4.4 网络同步</h3> + +<pre><code>localhost:Desktop yuechunli$ ipfs daemon +</code></pre> + +<h3 id="4-5-访问网站">4.5 访问网站</h3> + +<p>浏览器打开<a href="https://ipfs.io/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp">https://ipfs.io/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp</a>,效果图如下:</p> + +<p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-210721@2x.png" alt="" /></p> + +<h3 id="4-6-发布到ipns">4.6 发布到IPNS</h3> + +<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> + +<pre><code>localhost:~ yuechunli$ ipfs name publish QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp +Published to QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP: /ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp +localhost:~ yuechunli$ ipfs id +{ + &quot;ID&quot;: &quot;QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP&quot; +} +</code></pre> + +<p>当我们执行<code>ipfs name publish</code>命令时,会返回我们的节点<code>ID</code>,你可以通过<code>ipfs id</code>进行查看验证是否是你的节点<code>ID</code>。</p> + +<p><strong>⚠️:验证</strong></p> + +<pre><code>$ ipfs name resolve &lt;peerId&gt; +</code></pre> + +<pre><code>localhost:~ yuechunli$ ipfs name resolve QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP +/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp +localhost:~ yuechunli$ +</code></pre> + +<p><strong>⚠️:</strong>当然我们现在就可以通过<code>IPNS</code>进行访问了。</p> + +<pre><code>https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP +</code></pre> + +<p><strong>⚠️⚠️⚠️:注意上面是ipns而不是ipfs。</strong></p> + +<p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-212123@2x.png" alt="" /></p> + +<p><strong>⚠️:如果你网站数据修改,需要重新发布到IPNS。</strong></p> + +<h2 id="5-发布个人博客">5. 发布个人博客</h2> + +<p>你可以通过<code>Hugo</code>按照官方文档创建一个漂亮的静态博客<a href="http://gohugo.io/getting-started/quick-start/">Hugo官方网站</a>,当然你也可以自己编写,或者使用其他开源项目搭建。</p> + +<h3 id="5-1-搭建静态博客">5.1 搭建静态博客</h3> + +<p>大家可以自己搭建,也可以直接下载我的博客源码直接搭建。</p> + +<p>源码地址:<a href="http://github.com/liyuechun/ipfs_blogger">http://github.com/liyuechun/ipfs_blogger</a></p> + +<h3 id="5-2-节点id替换">5.2 节点ID替换</h3> + +<ul> +<li>查看你的节点ID</li> +</ul> + +<pre><code>localhost:ipfs_pin yuechunli$ ipfs id +{ + &quot;ID&quot;: &quot;《your peer id》&quot; +} +localhost:ipfs_pin yuechunli$ +</code></pre> + +<p>在上面的源码中全局搜索将源码里面的<code>QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP</code>替换成你自己的<code>ID</code>。</p> + +<p>接下来重复<a href="#4-创建简易的网页发布到IPFS">4. 创建简易的网页发布到IPFS</a>的操作步骤即可。</p> + +<h3 id="5-3-浏览博客">5.3 浏览博客</h3> + +<p>浏览器打开<a href="https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/">https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/</a>查看项目效果。</p> + +<p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-215636@2x.png" alt="IPFS 博客项目效果图" /></p> + +<h2 id="6-下篇预报">6. 下篇预报</h2> + +<h3 id="6-1-ipfs-ethereum-dapp-开发入门">6.1 <code>ipfs + ethereum</code><code>Dapp</code>开发入门</h3> + +<h2 id="7-技术交流">7. 技术交流</h2> + +<ul> +<li>区块链技术交流QQ群:<code>348924182</code></li> +<li>进微信群请加微信:<code>liyc1215</code></li> +<li>「区块链部落」官方公众号</li> +</ul> + +<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> + + + + + + \ No newline at end of file diff --git a/css/hyde.css b/css/hyde.css new file mode 100755 index 0000000..2af6e03 --- /dev/null +++ b/css/hyde.css @@ -0,0 +1,285 @@ +/* + * __ __ + * /\ \ /\ \ + * \ \ \___ __ __ \_\ \ __ + * \ \ _ `\/\ \/\ \ /'_` \ /'__`\ + * \ \ \ \ \ \ \_\ \/\ \_\ \/\ __/ + * \ \_\ \_\/`____ \ \___,_\ \____\ + * \/_/\/_/`/___/> \/__,_ /\/____/ + * /\___/ + * \/__/ + * + * Designed, built, and released under MIT license by @mdo. Learn more at + * https://github.com/poole/hyde. + */ + + +/* + * Contents + * + * Global resets + * Sidebar + * Container + * Reverse layout + * Themes + */ + + +/* + * Global resets + * + * Update the foundational and global aspects of the page. + */ + +html { + font-family: "Fira Sans", sans-serif; + font-weight:300; + +} +@media (min-width: 48em) { + html { + font-size: 16px; + } +} +@media (min-width: 58em) { + html { + font-size: 20px; + } +} + +pre { + tab-size:4; +} + +/* + * Sidebar + * + * Flexible banner for housing site name, intro, and "footer" content. Starts + * out above content in mobile and later moves to the side with wider viewports. + */ + +.sidebar { + text-align: center; + padding: 2rem 1rem; + color: rgba(255,255,255,.5); + background-color: #300030; +} +@media (min-width: 48em) { + .sidebar { + position: fixed; + top: 0; + left: 0; + bottom: 0; + width: 18rem; + text-align: left; + } +} + +/* Sidebar links */ +.sidebar a { + color: #fff; +} + +/* About section */ +.sidebar-about h1 { + color: #fff; + margin-top: 0; + font-weight:300; +} + +/* Sidebar nav */ +.sidebar-nav { + margin-top: 2rem; + margin-bottom: 2rem; + padding-left: 0; + list-style: none; +} + +.subnav { + list-style: none; + padding-left: 0; +} + +.sidebar-nav-item { + display: block; +} +a.sidebar-nav-item:hover, +a.sidebar-nav-item:focus { + text-decoration: underline; +} +.sidebar-nav-item.active { + font-weight: bold; +} + +/* Sticky sidebar + * + * Add the `sidebar-sticky` class to the sidebar's container to affix it the + * contents to the bottom of the sidebar in tablets and up. + */ + +@media (min-width: 48em) { + .sidebar-sticky { + position: absolute; + right: 1rem; + top: 1rem; + left: 1rem; + } +} + + +/* Container + * + * Align the contents of the site above the proper threshold with some margin-fu + * with a 25%-wide `.sidebar`. + */ + +.content { + padding-top: 2rem; + padding-bottom: 2rem; +} + +@media (min-width: 48em) { + .content { + max-width: 38rem; + margin-left: 20rem; + margin-right: 2rem; + } +} + +@media (min-width: 64em) { + .content { + max-width: 44rem; + margin-left: 20rem; + margin-right: 2rem; + } +} + +.footnote { + font-size: 0.7em; + margin-top: 0.5rem; +} + +.go { + color: #444444; +} + +.badge { + display:inline; + vertical-align: bottom; +} + +.badges { + float: right; +} + +.brand { + font-size: 4.0em; + margin-bottom: 0; +} + +/* + * Reverse layout + * + * Flip the orientation of the page by placing the `.sidebar` on the right. + */ + +@media (min-width: 48em) { + .layout-reverse .sidebar { + left: auto; + right: 0; + } + .layout-reverse .content { + margin-left: 2rem; + margin-right: 20rem; + } +} + +@media (min-width: 64em) { + .layout-reverse .content { + margin-left: 4rem; + margin-right: 22rem; + } +} + + + +/* + * Themes + * + * As of v1.1, Hyde includes optional themes to color the sidebar and links + * within blog posts. To use, add the class of your choosing to the `body`. + */ + +/* Base16 (http://chriskempson.github.io/base16/#default) */ + +/* Red */ +.theme-base-08 .sidebar { + background-color: #ac4142; +} +.theme-base-08 .content a, +.theme-base-08 .related-posts li a:hover { + color: #ac4142; +} + +/* Orange */ +.theme-base-09 .sidebar { + background-color: #d28445; +} +.theme-base-09 .content a, +.theme-base-09 .related-posts li a:hover { + color: #d28445; +} + +/* Yellow */ +.theme-base-0a .sidebar { + background-color: #f4bf75; +} +.theme-base-0a .content a, +.theme-base-0a .related-posts li a:hover { + color: #f4bf75; +} + +/* Green */ +.theme-base-0b .sidebar { + background-color: #90a959; +} +.theme-base-0b .content a, +.theme-base-0b .related-posts li a:hover { + color: #90a959; +} + +/* Cyan */ +.theme-base-0c .sidebar { + background-color: #75b5aa; +} +.theme-base-0c .content a, +.theme-base-0c .related-posts li a:hover { + color: #75b5aa; +} + +/* Blue */ +.theme-base-0d .sidebar { + background-color: #6a9fb5; +} +.theme-base-0d .content a, +.theme-base-0d .related-posts li a:hover { + color: #6a9fb5; +} + +/* Magenta */ +.theme-base-0e .sidebar { + background-color: #aa759f; +} +.theme-base-0e .content a, +.theme-base-0e .related-posts li a:hover { + color: #aa759f; +} + +/* Brown */ +.theme-base-0f .sidebar { + background-color: #8f5536; +} +.theme-base-0f .content a, +.theme-base-0f .related-posts li a:hover { + color: #8f5536; +} diff --git a/css/poole.css b/css/poole.css new file mode 100755 index 0000000..c2f9e35 --- /dev/null +++ b/css/poole.css @@ -0,0 +1,403 @@ +/* + * ___ + * /\_ \ + * _____ ___ ___\//\ \ __ + * /\ '__`\ / __`\ / __`\\ \ \ /'__`\ + * \ \ \_\ \/\ \_\ \/\ \_\ \\_\ \_/\ __/ + * \ \ ,__/\ \____/\ \____//\____\ \____\ + * \ \ \/ \/___/ \/___/ \/____/\/____/ + * \ \_\ + * \/_/ + * + * Designed, built, and released under MIT license by @mdo. Learn more at + * https://github.com/poole/poole. + */ + + +/* + * Contents + * + * Body resets + * Custom type + * Messages + * Container + * Masthead + * Posts and pages + * Pagination + * Reverse layout + * Themes + */ + + +/* + * Body resets + * + * Update the foundational and global aspects of the page. + */ + +* { + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; +} + +html, +body { + margin: 0; + padding: 0; +} + +html { + font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; + font-size: 16px; + line-height: 1.5; +} +@media (min-width: 38em) { + html { + font-size: 20px; + } +} + +body { + color: #515151; + background-color: #fff; + -webkit-text-size-adjust: 100%; + -ms-text-size-adjust: 100%; +} + +/* No `:visited` state is required by default (browsers will use `a`) */ +a { + color: #268bd2; + text-decoration: none; +} +/* `:focus` is linked to `:hover` for basic accessibility */ +a:hover, +a:focus { + text-decoration: underline; +} + +/* Headings */ +h1, h2, h3, h4, h5, h6 { + margin-bottom: .5rem; + font-weight: 400; + line-height: 1.25; + color: #313131; + text-rendering: optimizeLegibility; +} +h1 { + font-size: 2rem; +} +h2 { + margin-top: 1rem; + font-size: 1.5rem; +} +h3 { + margin-top: 1.5rem; + font-size: 1.25rem; +} +h4, h5, h6 { + margin-top: 1rem; + font-size: 1rem; +} + +/* Body text */ +p { + margin-top: 0; + margin-bottom: 1rem; +} + +strong { + color: #303030; +} + + +/* Lists */ +ul, ol, dl { + margin-top: 0; + margin-bottom: 1rem; +} + +dt { + font-weight: bold; +} +dd { + margin-bottom: .5rem; +} + +/* Misc */ +hr { + position: relative; + margin: 1.5rem 0; + border: 0; + border-top: 1px solid #eee; + border-bottom: 1px solid #fff; +} + +abbr { + font-size: 85%; + font-weight: bold; + color: #555; + text-transform: uppercase; +} +abbr[title] { + cursor: help; + border-bottom: 1px dotted #e5e5e5; +} + +/* Code */ +code, +pre { + font-family: Menlo, Monaco, "Courier New", monospace; +} +code { + padding: .25em .5em; + font-size: 85%; + color: #bf616a; + background-color: #f9f9f9; + border-radius: 3px; +} +pre { + display: block; + margin-top: 0; + margin-bottom: 1rem; + padding: 1rem; + font-size: .8rem; + line-height: 1.4; + white-space: pre; + white-space: pre-wrap; + word-break: break-all; + word-wrap: break-word; + background-color: #f9f9f9; +} +pre code { + padding: 0; + font-size: 100%; + color: inherit; + background-color: transparent; +} +.highlight { + margin-bottom: 1rem; + border-radius: 4px; +} +.highlight pre { + margin-bottom: 0; +} + +/* Quotes */ +blockquote { + padding: .5rem 1rem; + margin: .8rem 0; + color: #7a7a7a; + border-left: .25rem solid #e5e5e5; +} +blockquote p:last-child { + margin-bottom: 0; +} +@media (min-width: 30em) { + blockquote { + padding-right: 5rem; + padding-left: 1.25rem; + } +} + +img { + display: block; + margin: 0 0 1rem; + border-radius: 5px; + max-width: 100%; +} + +/* Tables */ +table { + margin-bottom: 1rem; + width: 100%; + border: 1px solid #e5e5e5; + border-collapse: collapse; +} +td, +th { + padding: .25rem .5rem; + border: 1px solid #e5e5e5; +} +tbody tr:nth-child(odd) td, +tbody tr:nth-child(odd) th { + background-color: #f9f9f9; +} + + +/* + * Custom type + * + * Extend paragraphs with `.lead` for larger introductory text. + */ + +.lead { + font-size: 1.25rem; + font-weight: 300; +} + + +/* + * Messages + * + * Show alert messages to users. You may add it to single elements like a `

`, + * or to a parent if there are multiple elements to show. + */ + +.message { + margin-bottom: 1rem; + padding: 1rem; + color: #717171; + background-color: #f9f9f9; +} + + +/* + * Container + * + * Center the page content. + */ + +.container { + max-width: 38rem; + padding-left: 1rem; + padding-right: 1rem; + margin-left: auto; + margin-right: auto; +} + + +/* + * Masthead + * + * Super small header above the content for site name and short description. + */ + +.masthead { + padding-top: 1rem; + padding-bottom: 1rem; + margin-bottom: 3rem; +} +.masthead-title { + margin-top: 0; + margin-bottom: 0; + color: #505050; +} +.masthead-title a { + color: #505050; +} +.masthead-title small { + font-size: 75%; + font-weight: 400; + color: #c0c0c0; + letter-spacing: 0; +} + + +/* + * Posts and pages + * + * Each post is wrapped in `.post` and is used on default and post layouts. Each + * page is wrapped in `.page` and is only used on the page layout. + */ + +.page, +.post { + margin-bottom: 4em; +} + +/* Blog post or page title */ +.page-title, +.post-title, +.post-title a { + color: #303030; +} +.page-title, +.post-title { + margin-top: 0; +} + +/* Meta data line below post title */ +.post-date { + display: block; + margin-top: -.5rem; + margin-bottom: 1rem; + color: #9a9a9a; +} + +/* Related posts */ +.related { + padding-top: 2rem; + padding-bottom: 2rem; + border-top: 1px solid #eee; +} +.related-posts { + padding-left: 0; + list-style: none; +} +.related-posts h3 { + margin-top: 0; +} +.related-posts li small { + font-size: 75%; + color: #999; +} +.related-posts li a:hover { + color: #268bd2; + text-decoration: none; +} +.related-posts li a:hover small { + color: inherit; +} + + +/* + * Pagination + * + * Super lightweight (HTML-wise) blog pagination. `span`s are provide for when + * there are no more previous or next posts to show. + */ + +.pagination { + overflow: hidden; /* clearfix */ + margin-left: -1rem; + margin-right: -1rem; + font-family: "PT Sans", Helvetica, Arial, sans-serif; + color: #ccc; + text-align: center; +} + +/* Pagination items can be `span`s or `a`s */ +.pagination-item { + display: block; + padding: 1rem; + border: 1px solid #eee; +} +.pagination-item:first-child { + margin-bottom: -1px; +} + +/* Only provide a hover state for linked pagination items */ +a.pagination-item:hover { + background-color: #f5f5f5; +} + +@media (min-width: 30em) { + .pagination { + margin: 3rem 0; + } + .pagination-item { + float: left; + width: 50%; + } + .pagination-item:first-child { + margin-bottom: 0; + border-top-left-radius: 4px; + border-bottom-left-radius: 4px; + } + .pagination-item:last-child { + margin-left: -1px; + border-top-right-radius: 4px; + border-bottom-right-radius: 4px; + } +} diff --git a/css/syntax.css b/css/syntax.css new file mode 100755 index 0000000..1264b87 --- /dev/null +++ b/css/syntax.css @@ -0,0 +1,66 @@ +.hll { background-color: #ffffcc } + /*{ background: #f0f3f3; }*/ +.c { color: #999; } /* Comment */ +.err { color: #AA0000; background-color: #FFAAAA } /* Error */ +.k { color: #006699; } /* Keyword */ +.o { color: #555555 } /* Operator */ +.cm { color: #0099FF; font-style: italic } /* Comment.Multiline */ +.cp { color: #009999 } /* Comment.Preproc */ +.c1 { color: #999; } /* Comment.Single */ +.cs { color: #999; } /* Comment.Special */ +.gd { background-color: #FFCCCC; border: 1px solid #CC0000 } /* Generic.Deleted */ +.ge { font-style: italic } /* Generic.Emph */ +.gr { color: #FF0000 } /* Generic.Error */ +.gh { color: #003300; } /* Generic.Heading */ +.gi { background-color: #CCFFCC; border: 1px solid #00CC00 } /* Generic.Inserted */ +.go { color: #AAAAAA } /* Generic.Output */ +.gp { color: #000099; } /* Generic.Prompt */ +.gs { } /* Generic.Strong */ +.gu { color: #003300; } /* Generic.Subheading */ +.gt { color: #99CC66 } /* Generic.Traceback */ +.kc { color: #006699; } /* Keyword.Constant */ +.kd { color: #006699; } /* Keyword.Declaration */ +.kn { color: #006699; } /* Keyword.Namespace */ +.kp { color: #006699 } /* Keyword.Pseudo */ +.kr { color: #006699; } /* Keyword.Reserved */ +.kt { color: #007788; } /* Keyword.Type */ +.m { color: #FF6600 } /* Literal.Number */ +.s { color: #d44950 } /* Literal.String */ +.na { color: #4f9fcf } /* Name.Attribute */ +.nb { color: #336666 } /* Name.Builtin */ +.nc { color: #00AA88; } /* Name.Class */ +.no { color: #336600 } /* Name.Constant */ +.nd { color: #9999FF } /* Name.Decorator */ +.ni { color: #999999; } /* Name.Entity */ +.ne { color: #CC0000; } /* Name.Exception */ +.nf { color: #CC00FF } /* Name.Function */ +.nl { color: #9999FF } /* Name.Label */ +.nn { color: #00CCFF; } /* Name.Namespace */ +.nt { color: #2f6f9f; } /* Name.Tag */ +.nv { color: #003333 } /* Name.Variable */ +.ow { color: #000000; } /* Operator.Word */ +.w { color: #bbbbbb } /* Text.Whitespace */ +.mf { color: #FF6600 } /* Literal.Number.Float */ +.mh { color: #FF6600 } /* Literal.Number.Hex */ +.mi { color: #FF6600 } /* Literal.Number.Integer */ +.mo { color: #FF6600 } /* Literal.Number.Oct */ +.sb { color: #CC3300 } /* Literal.String.Backtick */ +.sc { color: #CC3300 } /* Literal.String.Char */ +.sd { color: #CC3300; font-style: italic } /* Literal.String.Doc */ +.s2 { color: #CC3300 } /* Literal.String.Double */ +.se { color: #CC3300; } /* Literal.String.Escape */ +.sh { color: #CC3300 } /* Literal.String.Heredoc */ +.si { color: #AA0000 } /* Literal.String.Interpol */ +.sx { color: #CC3300 } /* Literal.String.Other */ +.sr { color: #33AAAA } /* Literal.String.Regex */ +.s1 { color: #CC3300 } /* Literal.String.Single */ +.ss { color: #FFCC33 } /* Literal.String.Symbol */ +.bp { color: #336666 } /* Name.Builtin.Pseudo */ +.vc { color: #003333 } /* Name.Variable.Class */ +.vg { color: #003333 } /* Name.Variable.Global */ +.vi { color: #003333 } /* Name.Variable.Instance */ +.il { color: #FF6600 } /* Literal.Number.Integer.Long */ + +.css .o, +.css .o + .nt, +.css .nt + .nt { color: #999; } diff --git a/favicon.png b/favicon.png new file mode 100755 index 0000000..84cce4d Binary files /dev/null and b/favicon.png differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..fb1039d --- /dev/null +++ b/index.html @@ -0,0 +1,480 @@ + + + + + + + + + + + + + 区块链部落 + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ + +
+
+ + + +
+

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

+ + + + + + + + +
+

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

+ +

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

+ +

微信:liyc1215

+ +

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

+
+ +

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

+ +

目录

+ + + +

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

+ +

1.1 新建file.txt文件

+ +

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

+ +
localhost:Desktop yuechunli$ pwd
+/Users/liyuechun/Desktop
+localhost:Desktop yuechunli$ mkdir 1121
+localhost:Desktop yuechunli$ cd 1121/
+localhost:1121 yuechunli$ vi file.txt
+localhost:1121 yuechunli$ cat file.txt
+liyc1215
+localhost:1121 yuechunli$
+
+ +

1.2 查看ipfs相关命令

+ +
localhost:1121 yuechunli$ ipfs help
+USAGE
+  ipfs - Global p2p merkle-dag filesystem.
+
+  ipfs [--config=<config> | -c] [--debug=<debug> | -D] [--help=<help>] [-h=<h>] [--local=<local> | -L] [--api=<api>] <command> ...
+
+SUBCOMMANDS
+  BASIC COMMANDS
+    init          Initialize ipfs local configuration
+    add <path>    Add a file to IPFS
+    cat <ref>     Show IPFS object data
+    get <ref>     Download IPFS objects
+    ls <ref>      List links from an object
+    refs <ref>    List hashes of links from an object
+
+  DATA STRUCTURE COMMANDS
+    block         Interact with raw blocks in the datastore
+    object        Interact with raw dag nodes
+    files         Interact with objects as if they were a unix filesystem
+    dag           Interact with IPLD documents (experimental)
+
+  ADVANCED COMMANDS
+    daemon        Start a long-running daemon process
+    mount         Mount an IPFS read-only mountpoint
+    resolve       Resolve any type of name
+    name          Publish and resolve IPNS names
+    key           Create and list IPNS name keypairs
+    dns           Resolve DNS links
+    pin           Pin objects to local storage
+    repo          Manipulate the IPFS repository
+    stats         Various operational stats
+    p2p           Libp2p stream mounting
+    filestore     Manage the filestore (experimental)
+
+  NETWORK COMMANDS
+    id            Show info about IPFS peers
+    bootstrap     Add or remove bootstrap peers
+    swarm         Manage connections to the p2p network
+    dht           Query the DHT for values or peers
+    ping          Measure the latency of a connection
+    diag          Print diagnostics
+
+  TOOL COMMANDS
+    config        Manage configuration
+    version       Show ipfs version information
+    update        Download and apply go-ipfs updates
+    commands      List all available commands
+
+ +

1.3 将file.txt添加到ipfs节点

+ +
localhost:1121 yuechunli$ ls
+file.txt
+localhost:1121 yuechunli$ ipfs add file.txt
+added QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T file.txt
+localhost:1121 yuechunli$ cat file.txt
+liyc1215
+localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T
+liyc1215
+localhost:1121 yuechunli$
+
+ +

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

+ +

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

+ +

+ +

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

+ +

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

+ +
    +
  • 同步节点
  • +
+ +

新建一个终端,执行ipfs daemon

+ +
localhost:.ipfs yuechunli$ ipfs daemon
+Initializing daemon...
+Adjusting current ulimit to 2048...
+Successfully raised file descriptor limit to 2048.
+Swarm listening on /ip4/111.196.246.151/tcp/3637
+Swarm listening on /ip4/127.0.0.1/tcp/4001
+Swarm listening on /ip4/169.254.170.167/tcp/4001
+Swarm listening on /ip4/192.168.0.107/tcp/4001
+Swarm listening on /ip6/::1/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
+
+ +
    +
  • IPFS网络查看数据
  • +
+ +

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

+ +

黎跃春 微信

+ +

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

+ +

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

+ +
localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T
+liyc1215
+localhost:1121 yuechunli$
+
+ +

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

+ +

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

+ +
localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T
+liyc1215
+localhost:1121 yuechunli$ ipfs files mkdir /LiYueChun
+localhost:1121 yuechunli$ ipfs files cp /ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T /LiYueChun/file.txt
+localhost:1121 yuechunli$ ipfs files ls /
+LiYueChun
+localhost:1121 yuechunli$ ipfs files ls /LiYueChun/
+file.txt
+localhost:1121 yuechunli$ ipfs files read /LiYueChun/file.txt
+liyc1215
+localhost:1121 yuechunli$
+
+ +

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

+ +

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

+ +
localhost:1121 yuechunli$ ipfs add -r ipfs-tutorial/
+added QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc ipfs-tutorial/contactme.txt
+added QmfKdWsguobA3aDPvSxLB3Bq4HMKyqKSgFr2NFUuVH8n31 ipfs-tutorial/eth-fabric.png
+added QmXe8jTxTh5MZP6BK5cnj19mXNTKVMzNyUJZUHuYyr5dk1 ipfs-tutorial/gongzhonghao.png
+added QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek ipfs-tutorial
+
+ +

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

+ +

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

+ +
localhost:1121 yuechunli$ ipfs cat QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc
+微信:liyc1215
+区块链技术交流群:348924182
+公众号:区块链部落
+localhost:1121 yuechunli$ ipfs cat /ipfs/QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc
+微信:liyc1215
+区块链技术交流群:348924182
+公众号:区块链部落
+localhost:1121 yuechunli$ ipfs cat /ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek/contactme.txt
+微信:liyc1215
+区块链技术交流群:348924182
+公众号:区块链部落
+localhost:1121 yuechunli$
+
+ +

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

+ + + +

+ + + +

+ +

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

+ +

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

+ +

4.1 创建一个index.html文件

+ +
<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8">
+  <title>Hello IPFS!</title>
+  <link rel="stylesheet" href="./style.css" />
+</head>
+<body>
+  <h1>Hello IPFS!</h1>
+</body>
+</html>
+
+ +

4.2 创建一个style.css文件

+ +
h1 {
+  color: green;
+}
+
+ +

4.3 添加到ipfs

+ +
localhost:Desktop yuechunli$ ipfs add -r site/
+added QmWG5rbgT9H77TGq49RXNoqN8M7DNKMnMX425nkmCB6BjS site/index.html
+added QmfGLJ3mryLvicQqzdsghq4QRhptKJtBAPe7yDJxsBGSuy site/style.css
+added QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp site
+
+ +

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

+ +

4.4 网络同步

+ +
localhost:Desktop yuechunli$ ipfs daemon
+
+ +

4.5 访问网站

+ +

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

+ +

+ +

4.6 发布到IPNS

+ +

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

+ +
localhost:~ yuechunli$ ipfs name publish QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp
+Published to QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP: /ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp
+localhost:~ yuechunli$ ipfs id
+{
+	"ID": "QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP"
+}
+
+ +

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

+ +

⚠️:验证

+ +
$ ipfs name resolve <peerId>
+
+ +
localhost:~ yuechunli$ ipfs name resolve QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP
+/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp
+localhost:~ yuechunli$
+
+ +

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

+ +
https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP
+
+ +

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

+ +

+ +

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

+ +

5. 发布个人博客

+ +

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

+ +

5.1 搭建静态博客

+ +

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

+ +

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

+ +

5.2 节点ID替换

+ +
    +
  • 查看你的节点ID
  • +
+ +
localhost:ipfs_pin yuechunli$ ipfs id
+{
+	"ID": "《your peer id》"
+}
+localhost:ipfs_pin yuechunli$
+
+ +

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

+ +

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

+ +

5.3 浏览博客

+ +

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

+ +

IPFS 博客项目效果图

+ +

6. 下篇预报

+ +

6.1 ipfs + ethereumDapp开发入门

+ +

7. 技术交流

+ +
    +
  • 区块链技术交流QQ群:348924182
  • +
  • 进微信群请加微信:liyc1215
  • +
  • 「区块链部落」官方公众号
  • +
+ +

+ +
+ + +
+ + + + diff --git a/index.xml b/index.xml new file mode 100644 index 0000000..e04cd71 --- /dev/null +++ b/index.xml @@ -0,0 +1,400 @@ + + + + 区块链部落 + Hugo + https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/ + en-us + 黎跃春 + 2017 liyuechun + Mon, 30 Oct 2017 20:01:00 UTC + + + + 【IPFS + 区块链 系列】 入门篇 - IPFS+IPNS+个人博客搭建 + https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/2017/10/ipfs_first_post/ + Mon, 30 Oct 2017 20:01:00 UTC + 黎跃春 + https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/2017/10/ipfs_first_post/ + + +<blockquote> +<p>孔壹学院:国内区块链职业教育引领品牌。</p> + +<p>作者:黎跃春,孔壹学院创始人,区块链、高可用架构师</p> + +<p>微信:liyc1215</p> + +<p>区块链博客:<a href="http://liyuechun.org">http://liyuechun.org</a></p> +</blockquote> + +<p>在阅读这篇文章之前,你需要先学习<a href="http://liyuechun.org/2017/11/20/ipfs-blockchain/">【IPFS + 区块链 系列】 入门篇 - IPFS环境配置</a>这篇文章。</p> + +<h2 id="目录">目录</h2> + +<ul> +<li><a href="#1-如何在IPFS新增一个文件">1. 如何在IPFS新增一个文件</a> + +<ul> +<li><a href="#11-新建file.txt文件">1.1 新建file.txt文件</a></li> +<li><a href="#12-查看ipfs相关命令">1.2 查看ipfs相关命令</a></li> +<li><a href="#13-将file.txt添加到ipfs节点">1.3 将file.txt添加到ipfs节点</a></li> +</ul></li> +<li><a href="#2-通过ipfs创建目录存储文件">2. 通过ipfs创建目录存储文件</a></li> +<li><a href="#3-如何在IPFS新增一个目录">3. 如何在IPFS新增一个目录</a> + +<ul> +<li><a href="#31-使用ipfs add -r可以上传一整个目录">3.1 使用ipfs add -r可以上传一整个目录</a></li> +<li><a href="#32-通过路径访问contactme.txt文件数据">3.2 通过路径访问contactme.txt文件数据</a></li> +<li><a href="#33-通过Hash查看数据IPFS网络数据">3.3 通过Hash查看数据IPFS网络数据</a></li> +</ul></li> +<li><a href="#4-创建简易的网页发布到IPFS">4. 创建简易的网页发布到IPFS</a> + +<ul> +<li><a href="#41-创建一个index.html文件">4.1 创建一个index.html文件</a></li> +<li><a href="#42-创建一个style.css文件">4.2 创建一个style.css文件</a></li> +<li><a href="#43-添加到ipfs">4.3 添加到ipfs</a></li> +<li><a href="#44-网络同步">4.4 网络同步</a></li> +<li><a href="#45-访问网站">4.5 访问网站</a></li> +<li><a href="#46-发布到IPNS">4.6 发布到IPNS</a></li> +</ul></li> +<li><a href="#5-发布个人博客">5. 发布个人博客</a> + +<ul> +<li><a href="#51-搭建静态博客">5.1 搭建静态博客</a></li> +<li><a href="#52-节点ID替换">5.2 节点ID替换</a></li> +<li><a href="#53-浏览博客">5.3 浏览博客</a></li> +</ul></li> +<li><a href="#6-下篇预报">6. 下篇预报</a> + +<ul> +<li><a href="#61-`ipfs + ethereum``Dapp`开发入门">6.1 <code>ipfs + ethereum</code><code>Dapp</code>开发入门</a></li> +</ul></li> +</ul> + +<h2 id="1-如何在ipfs新增一个文件">1. 如何在IPFS新增一个文件</h2> + +<h3 id="1-1-新建file-txt文件">1.1 新建file.txt文件</h3> + +<p>打开终端,切换到桌面,新建一个文件夹<code>1121</code>,切换到<code>1121</code>中,通过<code>vi</code>新建一个文件<code>file.txt</code>,文件里面输入春哥微信号<code>liyc1215</code>保存并且退出。</p> + +<pre><code>localhost:Desktop yuechunli$ pwd +/Users/liyuechun/Desktop +localhost:Desktop yuechunli$ mkdir 1121 +localhost:Desktop yuechunli$ cd 1121/ +localhost:1121 yuechunli$ vi file.txt +localhost:1121 yuechunli$ cat file.txt +liyc1215 +localhost:1121 yuechunli$ +</code></pre> + +<h3 id="1-2-查看ipfs相关命令">1.2 查看ipfs相关命令</h3> + +<pre><code>localhost:1121 yuechunli$ ipfs help +USAGE + ipfs - Global p2p merkle-dag filesystem. + + 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; ... + +SUBCOMMANDS + BASIC COMMANDS + init Initialize ipfs local configuration + add &lt;path&gt; Add a file to IPFS + cat &lt;ref&gt; Show IPFS object data + get &lt;ref&gt; Download IPFS objects + ls &lt;ref&gt; List links from an object + refs &lt;ref&gt; List hashes of links from an object + + DATA STRUCTURE COMMANDS + block Interact with raw blocks in the datastore + object Interact with raw dag nodes + files Interact with objects as if they were a unix filesystem + dag Interact with IPLD documents (experimental) + + ADVANCED COMMANDS + daemon Start a long-running daemon process + mount Mount an IPFS read-only mountpoint + resolve Resolve any type of name + name Publish and resolve IPNS names + key Create and list IPNS name keypairs + dns Resolve DNS links + pin Pin objects to local storage + repo Manipulate the IPFS repository + stats Various operational stats + p2p Libp2p stream mounting + filestore Manage the filestore (experimental) + + NETWORK COMMANDS + id Show info about IPFS peers + bootstrap Add or remove bootstrap peers + swarm Manage connections to the p2p network + dht Query the DHT for values or peers + ping Measure the latency of a connection + diag Print diagnostics + + TOOL COMMANDS + config Manage configuration + version Show ipfs version information + update Download and apply go-ipfs updates + commands List all available commands +</code></pre> + +<h3 id="1-3-将file-txt添加到ipfs节点">1.3 将file.txt添加到ipfs节点</h3> + +<pre><code>localhost:1121 yuechunli$ ls +file.txt +localhost:1121 yuechunli$ ipfs add file.txt +added QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T file.txt +localhost:1121 yuechunli$ cat file.txt +liyc1215 +localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T +liyc1215 +localhost:1121 yuechunli$ +</code></pre> + +<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> + +<p><strong>⚠️:</strong>当我试图通过<code>http://ipfs.io/ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T</code>进行数据访问时,无法访问,如下图所示:</p> + +<p><img src="http://om1c35wrq.bkt.clouddn.com/fangwen.gif" alt="" /></p> + +<p><strong>⚠️:</strong>虽然数据已经添加到当前的你自己的<code>IPFS</code>节点中,但是并没有同步到<code>IPFS</code>网络,所以暂时在网络上无法访问。</p> + +<p><strong>⚠️:重要:接下来执行下面的命令同步节点数据到<code>IPFS</code>网络,再试图在网络上查看数据。</strong></p> + +<ul> +<li>同步节点</li> +</ul> + +<p>新建一个终端,执行<code>ipfs daemon</code>。</p> + +<pre><code>localhost:.ipfs yuechunli$ ipfs daemon +Initializing daemon... +Adjusting current ulimit to 2048... +Successfully raised file descriptor limit to 2048. +Swarm listening on /ip4/111.196.246.151/tcp/3637 +Swarm listening on /ip4/127.0.0.1/tcp/4001 +Swarm listening on /ip4/169.254.170.167/tcp/4001 +Swarm listening on /ip4/192.168.0.107/tcp/4001 +Swarm listening on /ip6/::1/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 +</code></pre> + +<ul> +<li>从<code>IPFS</code>网络查看数据</li> +</ul> + +<p>浏览器访问<a href="https://ipfs.io/ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T">https://ipfs.io/ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T</a></p> + +<p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-105531@2x.png" alt="黎跃春 微信" /></p> + +<h2 id="2-通过ipfs创建目录存储文件">2. 通过ipfs创建目录存储文件</h2> + +<p>在着上面的步骤走,我们可以通过<code>ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T +liyc1215</code>查看添加到<code>ipfs</code>网络的<code>file.txt</code>文件的内容,如下:</p> + +<pre><code>localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T +liyc1215 +localhost:1121 yuechunli$ +</code></pre> + +<p>当然,我们也可以通过<code>ipfs</code>的相关命令在<code>ipfs</code>的根目录下面创建文件夹,并且将<code>file.txt</code>文件<strong>移动</strong>或者<strong>拷贝</strong>到我们创建的文件夹中。</p> + +<p><strong>⚠️:cp不会改变文件hash,mv会改变hash寻址。</strong></p> + +<pre><code>localhost:1121 yuechunli$ ipfs cat QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T +liyc1215 +localhost:1121 yuechunli$ ipfs files mkdir /LiYueChun +localhost:1121 yuechunli$ ipfs files cp /ipfs/QmbrevseVQKf1vsYMsxCscRf6D7S2dftYpHwxkYf94pc7T /LiYueChun/file.txt +localhost:1121 yuechunli$ ipfs files ls / +LiYueChun +localhost:1121 yuechunli$ ipfs files ls /LiYueChun/ +file.txt +localhost:1121 yuechunli$ ipfs files read /LiYueChun/file.txt +liyc1215 +localhost:1121 yuechunli$ +</code></pre> + +<h2 id="3-如何在ipfs新增一个目录">3. 如何在IPFS新增一个目录</h2> + +<h3 id="3-1-使用ipfs-add-r可以上传一整个目录">3.1 使用ipfs add -r可以上传一整个目录</h3> + +<pre><code>localhost:1121 yuechunli$ ipfs add -r ipfs-tutorial/ +added QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc ipfs-tutorial/contactme.txt +added QmfKdWsguobA3aDPvSxLB3Bq4HMKyqKSgFr2NFUuVH8n31 ipfs-tutorial/eth-fabric.png +added QmXe8jTxTh5MZP6BK5cnj19mXNTKVMzNyUJZUHuYyr5dk1 ipfs-tutorial/gongzhonghao.png +added QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek ipfs-tutorial +</code></pre> + +<h4 id="3-2-通过路径访问contactme-txt文件数据">3.2 通过路径访问contactme.txt文件数据</h4> + +<p>如果我们上传的是目录,那么可以通过下面几种方式访问到<code>contactme.txt</code>文件的数据。</p> + +<pre><code>localhost:1121 yuechunli$ ipfs cat QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc +微信:liyc1215 +区块链技术交流群:348924182 +公众号:区块链部落 +localhost:1121 yuechunli$ ipfs cat /ipfs/QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc +微信:liyc1215 +区块链技术交流群:348924182 +公众号:区块链部落 +localhost:1121 yuechunli$ ipfs cat /ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek/contactme.txt +微信:liyc1215 +区块链技术交流群:348924182 +公众号:区块链部落 +localhost:1121 yuechunli$ +</code></pre> + +<h3 id="3-3-通过hash查看数据ipfs网络数据">3.3 通过Hash查看数据IPFS网络数据</h3> + +<ul> +<li><strong>访问目录:</strong><a href="https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek">https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek</a></li> +</ul> + +<p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-110959@2x.png" alt="" /></p> + +<ul> +<li><p><strong>通过目录访问文件:</strong><a href="https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek/contactme.txt">https://ipfs.io/ipfs/QmSsjQDVw1fvmG5RsZMgp2GjihiXn2zDv64mfHZN3AREek/contactme.txt</a> +<img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-111019@2x.png" alt="" /></p></li> + +<li><p><strong>通过文件hash直接访问:</strong><a href="https://ipfs.io/ipfs/QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc">https://ipfs.io/ipfs/QmYx4BnhnLXeMWF5mKu16fJgUBiVP7ECXh7qcsUZnXiRxc</a></p></li> +</ul> + +<p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-113047@2x.png" alt="" /></p> + +<h2 id="4-创建简易的网页发布到ipfs">4. 创建简易的网页发布到IPFS</h2> + +<p>在这里我先自己写一个简单的网页给大家演示,先在桌面新建一个<code>site</code>文件夹,然后按照下面的步骤在<code>site</code>文件夹中建立<code>index.html</code>和<code>style.css</code>文件。</p> + +<h3 id="4-1-创建一个index-html文件">4.1 创建一个index.html文件</h3> + +<pre><code>&lt;!DOCTYPE html&gt; +&lt;html lang=&quot;en&quot;&gt; +&lt;head&gt; + &lt;meta charset=&quot;UTF-8&quot;&gt; + &lt;title&gt;Hello IPFS!&lt;/title&gt; + &lt;link rel=&quot;stylesheet&quot; href=&quot;./style.css&quot; /&gt; +&lt;/head&gt; +&lt;body&gt; + &lt;h1&gt;Hello IPFS!&lt;/h1&gt; +&lt;/body&gt; +&lt;/html&gt; +</code></pre> + +<h3 id="4-2-创建一个style-css文件">4.2 创建一个style.css文件</h3> + +<pre><code>h1 { + color: green; +} +</code></pre> + +<h3 id="4-3-添加到ipfs">4.3 添加到ipfs</h3> + +<pre><code>localhost:Desktop yuechunli$ ipfs add -r site/ +added QmWG5rbgT9H77TGq49RXNoqN8M7DNKMnMX425nkmCB6BjS site/index.html +added QmfGLJ3mryLvicQqzdsghq4QRhptKJtBAPe7yDJxsBGSuy site/style.css +added QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp site +</code></pre> + +<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> + +<h3 id="4-4-网络同步">4.4 网络同步</h3> + +<pre><code>localhost:Desktop yuechunli$ ipfs daemon +</code></pre> + +<h3 id="4-5-访问网站">4.5 访问网站</h3> + +<p>浏览器打开<a href="https://ipfs.io/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp">https://ipfs.io/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp</a>,效果图如下:</p> + +<p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-210721@2x.png" alt="" /></p> + +<h3 id="4-6-发布到ipns">4.6 发布到IPNS</h3> + +<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> + +<pre><code>localhost:~ yuechunli$ ipfs name publish QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp +Published to QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP: /ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp +localhost:~ yuechunli$ ipfs id +{ + &quot;ID&quot;: &quot;QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP&quot; +} +</code></pre> + +<p>当我们执行<code>ipfs name publish</code>命令时,会返回我们的节点<code>ID</code>,你可以通过<code>ipfs id</code>进行查看验证是否是你的节点<code>ID</code>。</p> + +<p><strong>⚠️:验证</strong></p> + +<pre><code>$ ipfs name resolve &lt;peerId&gt; +</code></pre> + +<pre><code>localhost:~ yuechunli$ ipfs name resolve QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP +/ipfs/QmdVEGkT5u7LtzzatTrn8JGNEF3fpuMPVs2rPCfvqRykRp +localhost:~ yuechunli$ +</code></pre> + +<p><strong>⚠️:</strong>当然我们现在就可以通过<code>IPNS</code>进行访问了。</p> + +<pre><code>https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP +</code></pre> + +<p><strong>⚠️⚠️⚠️:注意上面是ipns而不是ipfs。</strong></p> + +<p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-212123@2x.png" alt="" /></p> + +<p><strong>⚠️:如果你网站数据修改,需要重新发布到IPNS。</strong></p> + +<h2 id="5-发布个人博客">5. 发布个人博客</h2> + +<p>你可以通过<code>Hugo</code>按照官方文档创建一个漂亮的静态博客<a href="http://gohugo.io/getting-started/quick-start/">Hugo官方网站</a>,当然你也可以自己编写,或者使用其他开源项目搭建。</p> + +<h3 id="5-1-搭建静态博客">5.1 搭建静态博客</h3> + +<p>大家可以自己搭建,也可以直接下载我的博客源码直接搭建。</p> + +<p>源码地址:<a href="http://github.com/liyuechun/ipfs_blogger">http://github.com/liyuechun/ipfs_blogger</a></p> + +<h3 id="5-2-节点id替换">5.2 节点ID替换</h3> + +<ul> +<li>查看你的节点ID</li> +</ul> + +<pre><code>localhost:ipfs_pin yuechunli$ ipfs id +{ + &quot;ID&quot;: &quot;《your peer id》&quot; +} +localhost:ipfs_pin yuechunli$ +</code></pre> + +<p>在上面的源码中全局搜索将源码里面的<code>QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP</code>替换成你自己的<code>ID</code>。</p> + +<p>接下来重复<a href="#4-创建简易的网页发布到IPFS">4. 创建简易的网页发布到IPFS</a>的操作步骤即可。</p> + +<h3 id="5-3-浏览博客">5.3 浏览博客</h3> + +<p>浏览器打开<a href="https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/">https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/</a>查看项目效果。</p> + +<p><img src="http://om1c35wrq.bkt.clouddn.com/WX20171121-215636@2x.png" alt="IPFS 博客项目效果图" /></p> + +<h2 id="6-下篇预报">6. 下篇预报</h2> + +<h3 id="6-1-ipfs-ethereum-dapp-开发入门">6.1 <code>ipfs + ethereum</code><code>Dapp</code>开发入门</h3> + +<h2 id="7-技术交流">7. 技术交流</h2> + +<ul> +<li>区块链技术交流QQ群:<code>348924182</code></li> +<li>进微信群请加微信:<code>liyc1215</code></li> +<li>「区块链部落」官方公众号</li> +</ul> + +<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> + + + + + + \ No newline at end of file diff --git a/qrcode_for_gh.jpg b/qrcode_for_gh.jpg new file mode 100644 index 0000000..e147a9a Binary files /dev/null and b/qrcode_for_gh.jpg differ diff --git a/sitemap.xml b/sitemap.xml new file mode 100644 index 0000000..0caf2d4 --- /dev/null +++ b/sitemap.xml @@ -0,0 +1,22 @@ + + + + + https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/2017/10/ipfs_first_post/ + 2017-10-30T20:01:00+00:00 + + + + https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/blog/ + 2017-10-30T20:01:00+00:00 + 0 + + + + https://ipfs.io/ipns/QmdKXkeEWcuRw9oqBwopKUa8CgK1iBktPGYaMoJ4UNt1MP/ + 2017-10-30T20:01:00+00:00 + 0 + + + \ No newline at end of file diff --git a/touch-icon-144-precomposed.png b/touch-icon-144-precomposed.png new file mode 100755 index 0000000..19323de Binary files /dev/null and b/touch-icon-144-precomposed.png differ