基本介绍
IPFS
网络分两类:
- 公有
- 私有
对于大多数商用应用尤其是企业级解决方案而言,需要对自身数据有完全的控制,这种场合公有IPFS
网络并不适用,搭建私有IPFS
往往是这类应用的必要需求。
本文我们讲解创建一个私有 IPFS
网络的过程:
创建一个
IPFS
集群的私有IPFS
网络用于数据复制。
IPFS
本身不提供节点间数据复制,为了在 IPFS
网络中复制数据有两个选择:
- Filecoin
IPFS
-Cluster。
本文中我们使用 IPFS
-Cluster 。
我们通过三个虚拟机器实现私有网络,以下是相关的参考文档:
-
IPFS
: A protocol and network designed to create a content-addressable, peer-to-peer method of storing and sharing hypermedia in a distributed file system. Read more -
Private
IPFS
: 私有网络中的用户(peers)使用同一个共享私钥、此时所有用户只能在私有IPFS
网络中通讯, Read more。 -
IPFS
-Cluster: 一个IPFS
集群是一个独立的程序和一个CLI
客户端。通过一组IPFS
守护进程负责分配、复制以及跟踪 pins 。IPFS
-Cluster uses a leader-based consensus algorithm Raft to coordinate storage of apinset
, distributing the set of data across the participating nodes.- A cluster peer application:
ipfs-cluster-service
, to be run along withgo-ipfs
. - A client
CLI
application:ipfs-cluster-ctl
, which allows easily interacting with the peer's HTTPAPI
. - An additional "follower" peer application:
ipfs-cluster-follow
, focused on simplifying the process of configuring and running follower peers.
- A cluster peer application:
需要注意:
IPFS
的核心功能中,私有网络是其默认特征,同时IPFS
-Cluster 是一个独立的应用。IPFS
和IPFS
-Cluster 程序是作为不同包来安装的、分别以不同进程启动。IPFS
和IPFS
-Cluster 具有不同的 peer IDs、不同的API
endpoints 、使用不同的端口。IPFS
-Cluster 守护进程是依赖于IPFS
守护进程,启动IPFS
守护进程后才可以启动IPFS
-Cluster 守护进程。
搭建 IPFS
私有网络
默认 IPFS
和 IPFS
-Cluster 使用以下端口:
IPFS
4001 – Communication with other nodes 5001 – API server
8080 – Gateway server
IPFS
-CLUSTER 9094 – HTTP API endpoint
9095 – IPFS
proxy endpoint 9096 – Cluster swarm, used for communication between cluster nodes
We will use recently created three virtual machines (in my case I used DigitalOcean
) with installed Linux Ubuntu Distributive version 16.04
and command line as the main tool for installing necessary packages and settings. Depending on your cloud provider (AWS
, Azure, Google, etc.), you may need to look at some additional settings, like firewall or security group configuration, to let your peers see each other.
Let’s suppose that we have three VMs with the following IP addresses: Node0
: 192.168.10.1 Node1
: 192.168.10.2 Node2
: 192.168.10.3
Let’s start with the zero node (Node0
) which will be our bootstrap node.
Step 1: 安装 Go
First of all, let’s install Go as we will need it during our deployment process. Update Linux packages and dependencies:
1 |
sudo apt-get update |
---|---|
2 |
sudo apt-get -y upgrade |
---|---|
Download the latest version and unzip Go
1 |
wget https:``//dl.google.com/go/go1.11.4.linux-amd64.tar.gz |
---|---|
2 |
sudo tar -xvf go1.11.4.linux-amd64.tar.gz |
---|---|
3 |
sudo mv go /usr local |
---|---|
Create Path for Go and set environment variables. \1. Create folder:
1 |
mkdir $HOME``/gopath |
---|---|
Open .bashrc file and add to the end three variables GOROOT, GOPATH, PATH. Open file:
1 |
sudo nano ``$HOME``/.bashrc |
---|---|
Insert to the end of the .bashrc file:
1 |
export GOROOT=/usr/local/go |
---|---|
2 |
export GOPATH=``$HOME``/gopath |
---|---|
3 |
export PATH=``$PATH``:``$GOROOT``/bin:``$GOPATH``/bin |
---|---|
\2. Update .bashrc file and check Go version:
1 |
source ~/.bashrc |
---|---|
2 |
go version |
---|---|
Step 2: 安装 IPFS
We will install the latest version of the go-IPFS
. At the moment of writing this article, it was v0.4.18 for Linux. You can check for the lat