Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run several IPFS nodes on a single machine?

Tags:

ipfs

For testing, I want to be able to run several IPFS nodes on a single machine.

This is the scenario: I am building small services on top of IPFS core library, following the Making your own IPFS service guide. When I try to put client and server on the same machine (note that each of them will create their own IPFS node), I will get the following:

panic: cannot acquire lock: Lock FcntlFlock of /Users/long/.ipfs/repo.lock failed: resource temporarily unavailable
like image 714
Long Hoang Avatar asked Oct 21 '16 15:10

Long Hoang


People also ask

How do I run IPFS node?

Install IPFS on a server, create a new repo with ipfs init . Start a background IPFS node daemon process with: ipfs daemon & , add the files to the network with ipfs add -r <your-files> and pin the hash that you want to keep online forever with ipfs pin add -r <your-ipfs-hash/> .

Why do people run IPFS nodes?

IPFS is a peer-to-peer decentralized network that lets users back up files and websites by hosting them across numerous nodes. This ensures that content is resistant to censorship and centralized points of failure, such as server issues or coordinated attacks.

What are nodes in IPFS?

Nodes are an IPFS program that you run on your local computer to store files and connect to the IPFS network. They're the most crucial aspect of IPFS. Without nodes running the IPFS daemon (explained below), there would be no IPFS Network.


1 Answers

Usually, when you start with IPFS, you will use ipfs init, which will create a new node. The default data and config stored for that particular node are located at ~/.ipfs. Here is how you can create a new node and config it so it can run besides your default node.

1. Create a new node

For a new node you have to use ipfs init again. Use for instance the following:

IPFS_PATH=~/.ipfs2 ipfs init

This will create a new node at ~/.ipfs2 (not using the default path).

2. Change Address Configs

As both of your nodes now bind to the same ports, you need to change the port configuration, so both nodes can run side by side. For this, open ~/.ipfs2/configand findAddresses`:

"Addresses": {
    "API": "/ip4/127.0.0.1/tcp/5001",
    "Gateway": "/ip4/127.0.0.1/tcp/8080",
    "Swarm": [
        "/ip4/0.0.0.0/tcp/4001",
        "/ip6/::/tcp/4001"
    ]
}

To for example the following:

"Addresses": {
    "API": "/ip4/127.0.0.1/tcp/5002",
    "Gateway": "/ip4/127.0.0.1/tcp/8081",
    "Swarm": [
        "/ip4/0.0.0.0/tcp/4002",
        "/ip6/::/tcp/4002"
    ]
}

With this, you should be able to run both node .ipfs and .ipfs2 on a single machine.


Notes:

  1. Whenever you use .ipfs2, you need to set the env variable IPFS_PATH=~/.ipfs2
  2. In your example you need to change either your client or server node from ~/.ipfs to ~/.ipfs2
  3. you can also start the daemon on the second node using IPFS_PATH=~/.ipfs2 ipfs daemon &
like image 123
Long Hoang Avatar answered Sep 20 '22 10:09

Long Hoang