Construction of IPFs private network cluster


It is necessary to build a private network IPFs cluster for the business of alliance chain. The private network cluster allows IPFs nodes to only connect to other peer nodes with shared key, and the nodes in the network do not respond to the communication from nodes outside the network.
IPFs cluster is a stand-alone application and a cli client that allocates, replicates, and tracks pins across a set of IPFs daemons. It uses raft based consistency algorithm to coordinate storage and distribute data sets to participating nodes. IPFs cluster will play a good role when we want to backup the storage on a peer to other peers on all clusters synchronously, or manage the nodes of the cluster.
The following is a brief description of the construction and configuration process of IPFs private network and IPFs cluster (ubuntu16.04).

Construction of IPFs private network cluster

Default port of IPFs and IPFs cluster:

  • 4001 – interface with other nodes
  • 5001 – API server
  • 8080 – Gateway server


  • 9094 – HTTP API endpoint
  • 9095 – IPFS proxy endpoint
  • 9096 – cluster swarm several communication ports

Golang installation

The official installation methods of IPFs include installation package, IPFs update, source code compilation and installation. You can check the details…
In order to select and upgrade the IPFs version, we use theipfs-updateGo is a must to install in different ways. I will not repeat the installation of go here.

Install IPFs update

Install in each nodeipfs-update:

go get -u

It’s also relatively simple, because The reason why the official website is polluted by DNS is that you need to configure the configuration of each node after installation/etc/hosts

adoptipfs-update versionsAll available and downloadable files can be listedipfsWe can install the latest version directly here:

$ ipfs-update install latest
fetching go-ipfs version v0.4.22
binary downloaded, verifying...
stashing old binary
installing new binary to /home/hector/go/bin/ipfs
checking if repo migration is needed...
Installation complete!

suchipfsThe installation is successful. Next, we need to initialize the IPFs of each node

ipfs init

Create shared key

swarm.keyThe key allows us to create a private network, and tells the network node to only communicate with the node with the same key. Execute the following command on one node:

go get -u
ipfs-swarm-key-gen > ~/.ipfs/swarm.key

adoptscpOr the upload method will be generatedswarm.keyCopy to each node~/.ipfs/swarm.key

Remove the default bootstrap node

In order not to connect to the global IPFs network, you need to delete the node information of the default bootstrap.

ipfs bootstrap rm --all

Private network node configuration

Add the bootstrap of the first node in each node

ipfs bootstrap add /ip4/

QmSyQFFm5KdB9zoTNQJhPnMs4LYsVmEpY427QYxH2CaFqLbyipfs initThe node ID generated by theipfs idView the ID of the current node.
We also need to set environment variablesLIBP2P FORCE PNETTo force our network into private mode


Add the IPFs process to the system process to start

Each IPFs boot is added to the system’s daemons to start, add/etc/systemd/system/ipfs.service

Description=IPFS Daemon
ExecStart=/usr/local/bin/ipfs daemon --enable-namesys-pubsub

Now you can start the background daemons of IPFs with the following command:

systemctl daemon-reload
systemctl enable ipfs
systemctl start ipfs
systemctl status ipfs

IPFs cluster installation

IPFs cluster consists of two components:

  • ipfs-cluster-serviceThe daemons used to initialize the cluster peer and run it
  • ipfs-cluster-ctlManage the nodes and data of the cluster

We willipfs-clusterClone to gopath, then compile and install make (the system has installed make)

git clone $GOPATH/src ipfs-cluster
make install

Check to see if the installation is successful:

ipfs-cluster-service --version
ipfs-cluster-ctl --version

Set cluster key

Similar to the secret key of IPFs, we generate a random key in the management node

 od -vN 32 -An -tx1 /dev/urandom | tr -d ' \n'

Add the generated random string to the environment variable, for example:
Modify each node’s~/.bashrcAdd to environment variable:

export CLUSTER_SECRET=b55262c36de6f97bd50b5233f75866445ec51db74613bad78e906c4dc9ba1d30

Don’t forget to save itsource ~/.bashrc

Initialize cluster

Each node executes the initialization command:

ipfs-cluster-service init

Start the process at the management node

ipfs-cluster-service daemon

Other nodes start--bootstrapAdd master node:

ipfs-cluster-service daemon --bootstrap /ip4/

Notice here,12D3KooWEGrD9d3n6UJNzAJDyhfTUZNQmQz4k56Hb6TrYEyxyW2FIt is the IPFs cluster node ID, not the IPFs node ID. you can use theipfs-cluster-service idsee.
You can view the cluster node status through the command:

ipfs-cluster-ctl peers ls

Add the IPFs cluster node to the system process to start


Description=IPFS-Cluster Daemon
Requires=ipfs ipfs
ExecStart=/root/go/bin/ipfs-cluster-service daemon

Now you can start the background daemons of IPFs cluster with the following command:

systemctl daemon-reload
systemctl enable ipfs-cluster
systemctl start ipfs-cluster
systemctl status ipfs-cluster

Test cluster data replication

Add a file to one of the nodes:

ipfs-cluster-ctl add test.txt

You can view the file status through the added file CID, and you can see the file and its status in all nodesPINNED

ipfs-cluster-ctl status CID

Please note:Reprinted from notes of Ryan is a rookie LNMP technology stack

If you think this article is very useful to you, why not give a reward

Construction of IPFs private network cluster

Link address of this article:Construction of IPFs private network cluster

<img style=”border-width:0″ />
This work is licensed under the Creative Commons signature noncommercial use 4.0 international license agreement