1.IPFS简介(概念介绍转载自网络)
星际文件系统IPFS(InterPlanetary File System)是一个面向全球的、点对点的分布式版本文件系统,目标是为了补充(甚至是取代)目前统治互联网的超文本传输协议(HTTP),将所有具有相同文件系统的计算设备连接在一起。原理用基于内容的地址替代基于域名的地址,也就是用户寻找的不是某个地址而是储存在某个地方的内容,不需要验证发送者的身份,而只需要验证内容的哈希,通过这样可以让网页的速度更快、更安全、更健壮、更持久。
IPFS用基于内容的寻址替代传统的基于域名的寻址,用户不需要关心服务器的位置,不用考虑文件存储的名字和路径。我们将一个文件放到IPFS节点中,将会得到基于其内容计算出的唯一加密哈希值。哈希值直接反映文件的内容,哪怕只修改1比特,哈希值也会完全不同。当IPFS被请求一个文件哈希时,它会使用一个分布式哈希表找到文件所在的节点,取回文件并验证文件数据。
IPFS是通用目的的基础架构,基本没有存储上的限制。大文件会被切分成小的分块,下载的时候可以从多个服务器同时获取。IPFS的网络是不固定的、细粒度的、分布式的网络,可以很好的适应内容分发网络的要求。这样的设计可以很好的共享各类数据,包括图像、视频流、分布式数据库、整个操作系统、模块链、8英寸软盘的备份,还有静态网站。
IPFS提供了一个友好的WEB访问接口,用户可通过http://ipfs.io/hash 获取IPFS网络中的内容,也许在不久的将来,IPFS协议将会彻底替代传统的HTTP协议。
2.IPFS安装
本文记录的是go-ipfs在mac上的安装过程。
首先安装go:
在go的官网下载最新安装文件go1.10.3.darwin-amd64.pkg,默认安装在/usr/local/go
go-ipfs两种安装方式:a.下载安装包(2.1,2.2) b.从github获取源码自己编译
2.1.下载安装包
利用科学上网工具访问IPFS官方网站https://ipfs.io
点击【Try it】
点击【Install IPFS now】
点击【Download IPFS for your platform】
【Download go-ipfs】下载最新版本安装包
2.2.安装
$ tar xvfz go-ipfs_v0.4.15_darwin-amd64.tar.gz
………(解压过程省略)
$ cd go-ipfs
$ mv ipfs /usr/local/bin/ipfs
2.3从github获取源码自己编译安装
$ go get -u -d github.com/ipfs/go-ipfs
$ cd $GOPATH/src/github.com/ipfs/go-ipfs
$ make install
编译安装结束后
$ ipfs version
如果正常输出
ipfs version 0.4.16-dev
表示安装成功。(版本号为当前github最新版本)
如果提示
warning: GOPATH set to GOROOT (/usr/local/go) has no effect
则是go的环境变量配置有问题
2.4配置
初始化IPFS节点
$ ipfs init
initializing IPFS node at /Users/andy/.ipfs
generating 2048-bit RSA keypair…done
peer identity: QmZrSxgXXWDWgYX9z9FVHY3STwa11kzdPwVZzZtZRGv2Xq
to get started, enter:
ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme
最终在~下会生成一个.ipfs文件夹,目录结构如下:
ipfs默认节点存储空间为10G,如果想修改存储空间大小,可修改config文件中的"StorageMax": "10GB"值。
2.5启动服务
$ ipfs daemon
Initializing daemon…
Successfully raised file descriptor limit to 2048.
Swarm listening on /ip4/10.1.0.186/tcp/4001
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/192.168.0.252/tcp/4001
Swarm listening on /ip6/::1/tcp/4001
Swarm listening on /p2p-circuit/ipfs/QmZrSxgXXWDWgYX9z9FVHY3STwa11kzdPwVZzZtZRGv2Xq
Swarm announcing /ip4/10.1.0.186/tcp/4001
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip4/192.168.0.252/tcp/4001
Swarm announcing /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
2.6验证
$ ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme
Hello and Welcome to IPFS!
██╗██████╗ ███████╗ ███████╗
██║██╔══██╗██╔════╝ ██╔════╝
██║██████╔╝█████╗ ███████╗
██║██╔═══╝ ██╔══╝ ╚════██║
██║██║ ██║ ███████║
╚═╝╚═╝ ╚═╝ ╚══════╝
If you're seeing this, you have successfully installed
IPFS and are now interfacing with the ipfs merkledag!
-------------------------------------------------------
| Warning: |
| This is alpha software. Use at your own discretion! |
| Much is missing or lacking polish. There are bugs. |
| Not yet secure. Read the security notes for more. |
-------------------------------------------------------
Check out some of the other files in this directory:
./about
./help
./quick-start <-- usage examples
./readme <-- this file
./security-notes
另外IPFS还提供了一个webui管理界面:
http://localhost:5001/webui