搭建自己的ipfs私有网络

时间:2024-11-09 08:01:35

测试环境准备

虚拟机

准备两台linux虚拟机,分别配置他们的ip地址为192.168.1.63和192.168.1.64.如下图:
这里写图片描述
这里写图片描述

安装包

ipfs安装包的百度网盘链接

系统安装及配置

安装ipfs

#63节点安装ipfs
[root@myhost ~]# tar xzvf go-ipfs_v0.4.15_linux 
go-ipfs/build-log
go-ipfs/
go-ipfs/ipfs
go-ipfs/LICENSE
go-ipfs/
[root@myhost ~]# cp go-ipfs/ipfs /usr/bin/
#64节点安装ipfs
root@ubuntu:~# tar xzvf go-ipfs_v0.4.15_linux 
go-ipfs/build-log
go-ipfs/
go-ipfs/ipfs
go-ipfs/LICENSE
go-ipfs/
root@ubuntu:~# cp go-ipfs/ipfs /usr/bin/

初始化ipfs

#63节点初始化
[root@myhost ~]# ipfs init
initializing IPFS node at /root/.ipfs
generating 2048-bit RSA keypair...done
peer identity: QmTks2mpdcTJnaLLtjGkyqPWxuMy6WvZbDzkG6XTGRfYA3
to get started, enter:

	ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme


#64节点初始化
root@ubuntu:~# ipfs init
initializing IPFS node at /root/.ipfs
generating 2048-bit RSA keypair...done
peer identity: QmcgkHih714sZAbda3LDp7TF6A6oTXTuTe3QboSjkg3dNA
to get started, enter:

	ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme

该操作执行后,默认会在/root/目录下生成一个隐藏目录,作为ipfs的local存储
这里写图片描述

生成共享key

因为我们要组建的是私有网络,所有节点需要使用相同的私有key来加入网络中,我们使用go-ipfs-swarm-key-gen工具来生成共享key

#编译工具
go get /Kubuxu/go-ipfs-swarm-key-gen
cd $GOPATH
cd src//Kubuxu/go-ipfs-swarm-key-gen/ipfs-swarm-key-gen/
go build
# 生成key
./ipfs-swarm-key-gen > /root/.ipfs/

# 将63上生成的key拷贝到64的相同目录下
scp /root/.ipfs/ 192.168.1.64:/root/.ipfs/

移除默认的boostrap节点

#63
[root@myhost ~]# ipfs bootstrap rm --all
removed /dnsaddr/bootstrap./ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN
removed /dnsaddr/bootstrap./ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa
removed /dnsaddr/bootstrap./ipfs/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb
removed /dnsaddr/bootstrap./ipfs/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt
removed /ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ
removed /ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM
removed /ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64
removed /ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu
removed /ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd
removed /ip6/2400:6180:0:d0::151:6001/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu
removed /ip6/2604:a880:1:20::203:d001/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM
removed /ip6/2604:a880:800:10::4a:5001/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64
removed /ip6/2a03:b0c0:0:1010::23:1001/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd
#64
root@ubuntu:~# ipfs bootstrap rm --all
removed /dnsaddr/bootstrap./ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN
removed /dnsaddr/bootstrap./ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa
removed /dnsaddr/bootstrap./ipfs/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb
removed /dnsaddr/bootstrap./ipfs/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt
removed /ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ
removed /ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM
removed /ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64
removed /ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu
removed /ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd
removed /ip6/2400:6180:0:d0::151:6001/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu
removed /ip6/2604:a880:1:20::203:d001/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM
removed /ip6/2604:a880:800:10::4a:5001/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64
removed /ip6/2a03:b0c0:0:1010::23:1001/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd

启动服务

#63
[root@myhost ~]# ipfs daemon
Initializing daemon...
Successfully raised file descriptor limit to 2048.
Swarm is limited to private network of peers with the swarm key
Swarm key fingerprint: 05196cc65b4e7633521d7357186a2951
Swarm listening on /ip4/10.0.3.15/tcp/4001
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/192.168.1.63/tcp/4001
Swarm listening on /ip6/::1/tcp/4001
Swarm listening on /p2p-circuit/ipfs/QmTks2mpdcTJnaLLtjGkyqPWxuMy6WvZbDzkG6XTGRfYA3
Swarm announcing /ip4/10.0.3.15/tcp/4001
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip4/192.168.1.63/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

我们的私有网络中已经有了第一个ipfs节点,现在需要将第二个节点加入网络中,在启动第二个节点的服务前,需要先将第一个启动节点的信息作为作为第二个节点的boostrap的信息

# 添加boostrap信息
root@ubuntu:~# ipfs bootstrap add /ip4/192.168.1.63/tcp/4001/ipfs/QmTks2mpdcTJnaLLtjGkyqPWxuMy6WvZbDzkG6XTGRfYA3
added /ip4/192.168.1.63/tcp/4001/ipfs/QmTks2mpdcTJnaLLtjGkyqPWxuMy6WvZbDzkG6XTGRfYA3
root@ubuntu:~# 
# 启动64节点root@ubuntu:~# ipfs daemon
Initializing daemon...
Successfully raised file descriptor limit to 2048.
Swarm is limited to private network of peers with the swarm key
Swarm key fingerprint: 05196cc65b4e7633521d7357186a2951
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/192.168.1.64/tcp/4001
Swarm listening on /ip6/::1/tcp/4001
Swarm listening on /p2p-circuit/ipfs/QmcgkHih714sZAbda3LDp7TF6A6oTXTuTe3QboSjkg3dNA
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip4/192.168.1.64/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

现在私有网络已经组建完成,我们接下来进行一些基本的测试

测试

在63节点上写入一个文件,并添加到ipfs网络中

[root@myhost ~]# echo helloworld > 
[root@myhost ~]# 
[root@myhost ~]# ipfs add  
added QmUU2HcUBVSXkfWPUc3WUSeCMrWWeEJTuAgR9uyWBhh9Nf 
[root@myhost ~]# 

在64节点上用哈希值读取该文件

root@ubuntu:~# ipfs cat QmUU2HcUBVSXkfWPUc3WUSeCMrWWeEJTuAgR9uyWBhh9Nf
helloworld

搭建的私有网络可以正常使用。

参考

  • /p/fe637149e4cf
  • /yuanfangyuan/p/
  • /p/fe637149e4cf
  • /welling_22/article/details/78713755
  • /a/1190000012138804
  • /item/
  • /winux/article/details/79193823
  • /b2894lxlx/article/details/80323480

声明:转载本博文章须在文章明显处注明作者及附上原文链接,便于读者找到原文的更新版。