问题描述
为了进行测试,我希望能够在一台计算机上运行多个IPFS节点.
For testing, I want to be able to run several IPFS nodes on a single machine.
这是方案:我在自行创建之后,在IPFS核心库的顶部构建小型服务. IPFS服务指南.当我尝试将客户端和服务器放在同一台计算机上时(请注意,它们中的每个都将创建自己的IPFS节点),我将得到以下信息:
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
推荐答案
通常,从IPFS开始时,将使用ipfs init
,这将创建一个新节点.为该特定节点存储的默认数据和配置位于~/.ipfs
.这是创建新节点并对其进行配置的方法,以便它可以在默认节点之外运行.
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.
对于新节点,您必须再次使用ipfs init
.例如,使用以下内容:
For a new node you have to use ipfs init
again. Use for instance the following:
IPFS_PATH=~/.ipfs2 ipfs init
这将在〜/.ipfs2(不使用默认路径)处创建一个新节点.
This will create a new node at ~/.ipfs2 (not using the default path).
由于两个节点现在都绑定到相同的端口,因此您需要更改端口配置,以便两个节点可以并行运行.为此,打开〜/.ipfs2/config and find
Addresses`:
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 find
Addresses`:
"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"
]
}
例如,以下内容:
"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"
]
}
这样,您应该能够在单个计算机上同时运行节点.ipfs和.ipfs2.
With this, you should be able to run both node .ipfs and .ipfs2 on a single machine.
注意:
- 每当使用.ipfs2时,都需要设置环境变量
IPFS_PATH=~/.ipfs2
- 在您的示例中,您需要将客户端或服务器节点从〜/.ipfs更改为〜/.ipfs2
- 您还可以使用IPFS_PATH =〜/.ipfs2 ipfs守护程序& 在第二个节点上启动守护程序.
- Whenever you use .ipfs2, you need to set the env variable
IPFS_PATH=~/.ipfs2
- In your example you need to change either your client or server node from ~/.ipfs to ~/.ipfs2
- you can also start the daemon on the second node using IPFS_PATH=~/.ipfs2 ipfs daemon &
这篇关于如何在一台机器上运行多个IPFS节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!