IPFS搭建私有网络-docker方式

一、生成共享秘钥

搭建IPFS私有网络,首先需要使所有节点共享一个密钥swarm.key。

git clone https://github.com/Kubuxu/go-ipfs-swarm-key-gen.git
cd go-ipfs-swarm-key-gen
go run main.go > swarm.key

二、网络搭建

拉取镜像

docker pull ipfs/go-ipfs:latest

启动节点

  • 准备工作
    首先,分别创建两个节点目录node1和node2。
    其次,在node1和node2目录下再创建ipfs_staging和ipfs_data目录。
    最后,把swarm.key文件分别放置node1和node2目录下。

  • 启动节点1

进入node1目录,并执行命令

# 启动命令
docker run -d --name ipfs_node1  -e IPFS_SWARM_KEY_FILE=$PWD/swarm.key  -v $PWD/ipfs_staging:/export -v $PWD/ipfs_data:/data/ipfs -p 4001:4001 -p 8081:8080 -p 5001:5001 ipfs/go-ipfs:latest

# 清除容器默认的bootstrap
docker exec -it ipfs_node1  ipfs bootstrap rm --all

查看启动日志:

oot@OCI-SIN01-050-ops-bsnbase-com:/bsn/ipfs/node1# docker logs ipfs_node1
Changing user to ipfs
ipfs version 0.22.0
Found IPFS fs-repo at /data/ipfs
Initializing daemon...
Kubo version: 0.22.0-3f884d3
Repo version: 14
System version: amd64/linux
Golang version: go1.19.10
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/127.0.0.1/udp/4001/quic
Swarm listening on /ip4/127.0.0.1/udp/4001/quic-v1
Swarm listening on /ip4/127.0.0.1/udp/4001/quic-v1/webtransport/certhash/uEiCHi9Q0d98H9RNRm9PSpbuOzqwFavKSqvI3I9mIpui9fw/certhash/uEiBL3UeS5ivkkLgV3dTEAN9exPeeLQVu1QRPzTzCRDZB9Q
Swarm listening on /ip4/172.17.0.2/tcp/4001
Swarm listening on /ip4/172.17.0.2/udp/4001/quic
Swarm listening on /ip4/172.17.0.2/udp/4001/quic-v1
Swarm listening on /ip4/172.17.0.2/udp/4001/quic-v1/webtransport/certhash/uEiCHi9Q0d98H9RNRm9PSpbuOzqwFavKSqvI3I9mIpui9fw/certhash/uEiBL3UeS5ivkkLgV3dTEAN9exPeeLQVu1QRPzTzCRDZB9Q
Swarm listening on /p2p-circuit
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip4/127.0.0.1/udp/4001/quic
Swarm announcing /ip4/127.0.0.1/udp/4001/quic-v1
Swarm announcing /ip4/127.0.0.1/udp/4001/quic-v1/webtransport/certhash/uEiCHi9Q0d98H9RNRm9PSpbuOzqwFavKSqvI3I9mIpui9fw/certhash/uEiBL3UeS5ivkkLgV3dTEAN9exPeeLQVu1QRPzTzCRDZB9Q
Swarm announcing /ip4/172.17.0.2/tcp/4001
Swarm announcing /ip4/172.17.0.2/udp/4001/quic
Swarm announcing /ip4/172.17.0.2/udp/4001/quic-v1
Swarm announcing /ip4/172.17.0.2/udp/4001/quic-v1/webtransport/certhash/uEiCHi9Q0d98H9RNRm9PSpbuOzqwFavKSqvI3I9mIpui9fw/certhash/uEiBL3UeS5ivkkLgV3dTEAN9exPeeLQVu1QRPzTzCRDZB9Q
RPC API server listening on /ip4/0.0.0.0/tcp/5001
WebUI: http://0.0.0.0:5001/webui
Gateway server listening on /ip4/0.0.0.0/tcp/8080
Daemon is ready
root@OCI-SIN01-050-ops-bsnbase-com:/bsn/ipfs/node1# 

删除默认节点日志:

root@OCI-SIN01-050-ops-bsnbase-com:/bsn/ipfs/node1# docker exec -it ipfs_node1  ipfs bootstrap rm --all
ipfs: Reading from /dev/stdin; send Ctrl-d to stop.
removed /dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN
removed /dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa
removed /dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb
removed /dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt
removed /ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ
removed /ip4/104.131.131.82/udp/4001/quic/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ
root@OCI-SIN01-050-ops-bsnbase-com:/bsn/ipfs/node1# 

  • 启动节点2

进入node2目录,并执行命令

# 启动命令
docker run -d --name ipfs_node2  -e IPFS_SWARM_KEY_FILE=$PWD/swarm.key -v $PWD/ipfs_staging:/export -v $PWD/ipfs_data:/data/ipfs -p 4002:4001 -p 8082:8080 -p 5002:5001 ipfs/go-ipfs:latest

# 清除容器默认的bootstrap
docker exec -it ipfs_node2  ipfs bootstrap rm --all

# 查看node1的id信息
docker exec ipfs_node2  ipfs id 

启动日志:

root@OCI-SIN01-050-ops-bsnbase-com:/bsn/ipfs/node2# docker logs ipfs_node2
Changing user to ipfs
ipfs version 0.22.0
Found IPFS fs-repo at /data/ipfs
Initializing daemon...
Kubo version: 0.22.0-3f884d3
Repo version: 14
System version: amd64/linux
Golang version: go1.19.10
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/127.0.0.1/udp/4001/quic
Swarm listening on /ip4/127.0.0.1/udp/4001/quic-v1
Swarm listening on /ip4/127.0.0.1/udp/4001/quic-v1/webtransport/certhash/uEiAXPSdMkTA82JOrbHAWGq0CqS4cTHbU8pRwguTFkOTLgw/certhash/uEiAKjvyQ_pQVOrhePZWpvb4K_xF9gISKW-4XQm0Ltpw1aw
Swarm listening on /ip4/172.17.0.3/tcp/4001
Swarm listening on /ip4/172.17.0.3/udp/4001/quic
Swarm listening on /ip4/172.17.0.3/udp/4001/quic-v1
Swarm listening on /ip4/172.17.0.3/udp/4001/quic-v1/webtransport/certhash/uEiAXPSdMkTA82JOrbHAWGq0CqS4cTHbU8pRwguTFkOTLgw/certhash/uEiAKjvyQ_pQVOrhePZWpvb4K_xF9gISKW-4XQm0Ltpw1aw
Swarm listening on /p2p-circuit
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip4/127.0.0.1/udp/4001/quic
Swarm announcing /ip4/127.0.0.1/udp/4001/quic-v1
Swarm announcing /ip4/127.0.0.1/udp/4001/quic-v1/webtransport/certhash/uEiAXPSdMkTA82JOrbHAWGq0CqS4cTHbU8pRwguTFkOTLgw/certhash/uEiAKjvyQ_pQVOrhePZWpvb4K_xF9gISKW-4XQm0Ltpw1aw
Swarm announcing /ip4/172.17.0.3/tcp/4001
Swarm announcing /ip4/172.17.0.3/udp/4001/quic
Swarm announcing /ip4/172.17.0.3/udp/4001/quic-v1
Swarm announcing /ip4/172.17.0.3/udp/4001/quic-v1/webtransport/certhash/uEiAXPSdMkTA82JOrbHAWGq0CqS4cTHbU8pRwguTFkOTLgw/certhash/uEiAKjvyQ_pQVOrhePZWpvb4K_xF9gISKW-4XQm0Ltpw1aw
RPC API server listening on /ip4/0.0.0.0/tcp/5001
WebUI: http://0.0.0.0:5001/webui
Gateway server listening on /ip4/0.0.0.0/tcp/8080
Daemon is ready
root@OCI-SIN01-050-ops-bsnbase-com:/bsn/ipfs/node2# 

删除默认节点日志:

root@OCI-SIN01-050-ops-bsnbase-com:/bsn/ipfs/node2# docker exec -it ipfs_node2 sh
/ # ipfs bootstrap list
/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN
/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa
/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb
/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt
/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ
/ip4/104.131.131.82/udp/4001/quic/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ
/ # ipfs bootstrap rm --all
removed /dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN
removed /dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa
removed /dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb
removed /dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt
removed /ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ
removed /ip4/104.131.131.82/udp/4001/quic/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ
/ # 

  • 添加bootstrap节点

查看node1的id信息

root@OCI-SIN01-050-ops-bsnbase-com:/bsn/ipfs/node1# docker exec ipfs_node1  ipfs id 
{
    "ID": "12D3KooWStan5Asx1XgqnmKUB2WfbqxWpXY6Rj8i5CfkBzDg8HzW",
    "PublicKey": "CAESIP2rQhYBFVC0S7Pm4j0c1fYuF/wxQ/l43e10BnaRWgeP",
    "Addresses": [
        "/ip4/127.0.0.1/tcp/4001/p2p/12D3KooWStan5Asx1XgqnmKUB2WfbqxWpXY6Rj8i5CfkBzDg8HzW",
        "/ip4/127.0.0.1/udp/4001/quic-v1/p2p/12D3KooWStan5Asx1XgqnmKUB2WfbqxWpXY6Rj8i5CfkBzDg8HzW",
        "/ip4/127.0.0.1/udp/4001/quic-v1/webtransport/certhash/uEiCHi9Q0d98H9RNRm9PSpbuOzqwFavKSqvI3I9mIpui9fw/certhash/uEiBL3UeS5ivkkLgV3dTEAN9exPeeLQVu1QRPzTzCRDZB9Q/p2p/12D3KooWStan5Asx1XgqnmKUB2WfbqxWpXY6Rj8i5CfkBzDg8HzW",
        "/ip4/127.0.0.1/udp/4001/quic/p2p/12D3KooWStan5Asx1XgqnmKUB2WfbqxWpXY6Rj8i5CfkBzDg8HzW",
        "/ip4/158.247.207.212/tcp/4001/p2p/12D3KooWEDg5qcwkPGkVNPR7wGUVxLNaLQaruU58hcMSj9gfSLPt/p2p-circuit/p2p/12D3KooWStan5Asx1XgqnmKUB2WfbqxWpXY6Rj8i5CfkBzDg8HzW",
        "/ip4/158.247.207.212/udp/4001/quic-v1/p2p/12D3KooWEDg5qcwkPGkVNPR7wGUVxLNaLQaruU58hcMSj9gfSLPt/p2p-circuit/p2p/12D3KooWStan5Asx1XgqnmKUB2WfbqxWpXY6Rj8i5CfkBzDg8HzW",
        "/ip4/158.247.207.212/udp/4001/quic/p2p/12D3KooWEDg5qcwkPGkVNPR7wGUVxLNaLQaruU58hcMSj9gfSLPt/p2p-circuit/p2p/12D3KooWStan5Asx1XgqnmKUB2WfbqxWpXY6Rj8i5CfkBzDg8HzW",
        "/ip4/172.17.0.2/tcp/4001/p2p/12D3KooWStan5Asx1XgqnmKUB2WfbqxWpXY6Rj8i5CfkBzDg8HzW",
        "/ip4/172.17.0.2/udp/4001/quic-v1/p2p/12D3KooWStan5Asx1XgqnmKUB2WfbqxWpXY6Rj8i5CfkBzDg8HzW",
        "/ip4/172.17.0.2/udp/4001/quic-v1/webtransport/certhash/uEiCHi9Q0d98H9RNRm9PSpbuOzqwFavKSqvI3I9mIpui9fw/certhash/uEiBL3UeS5ivkkLgV3dTEAN9exPeeLQVu1QRPzTzCRDZB9Q/p2p/12D3KooWStan5Asx1XgqnmKUB2WfbqxWpXY6Rj8i5CfkBzDg8HzW",
        "/ip4/172.17.0.2/udp/4001/quic/p2p/12D3KooWStan5Asx1XgqnmKUB2WfbqxWpXY6Rj8i5CfkBzDg8HzW",
        "/ip4/5.161.43.61/tcp/4001/p2p/12D3KooWJjszSPBX3zw178enoigouVjzzFYC91tz5bcuZWWXdhCH/p2p-circuit/p2p/12D3KooWStan5Asx1XgqnmKUB2WfbqxWpXY6Rj8i5CfkBzDg8HzW",
        "/ip4/5.161.43.61/udp/4001/quic/p2p/12D3KooWJjszSPBX3zw178enoigouVjzzFYC91tz5bcuZWWXdhCH/p2p-circuit/p2p/12D3KooWStan5Asx1XgqnmKUB2WfbqxWpXY6Rj8i5CfkBzDg8HzW"
    ],
    "AgentVersion": "kubo/0.22.0/3f884d3/docker",
    "Protocols": [
        "/ipfs/bitswap",
        "/ipfs/bitswap/1.0.0",
        "/ipfs/bitswap/1.1.0",
        "/ipfs/bitswap/1.2.0",
        "/ipfs/id/1.0.0",
        "/ipfs/id/push/1.0.0",
        "/ipfs/lan/kad/1.0.0",
        "/ipfs/ping/1.0.0",
        "/libp2p/circuit/relay/0.2.0/stop",
        "/libp2p/dcutr",
        "/x/"
    ]
}

查看node2的id信息

root@OCI-SIN01-050-ops-bsnbase-com:/bsn/ipfs/node2#  docker exec ipfs_node2  ipfs id 
{
    "ID": "12D3KooWLLjg91CFNBrEV1CoLxo7ceVAxUupGymsCrdfExm8odV5",
    "PublicKey": "CAESIJxcnIGDHJPg4q14aTaHQoBE0s71k7KKrkfuxG0dBO/M",
    "Addresses": [
        "/ip4/127.0.0.1/tcp/4001/p2p/12D3KooWLLjg91CFNBrEV1CoLxo7ceVAxUupGymsCrdfExm8odV5",
        "/ip4/127.0.0.1/udp/4001/quic-v1/p2p/12D3KooWLLjg91CFNBrEV1CoLxo7ceVAxUupGymsCrdfExm8odV5",
        "/ip4/127.0.0.1/udp/4001/quic-v1/webtransport/certhash/uEiAXPSdMkTA82JOrbHAWGq0CqS4cTHbU8pRwguTFkOTLgw/certhash/uEiAKjvyQ_pQVOrhePZWpvb4K_xF9gISKW-4XQm0Ltpw1aw/p2p/12D3KooWLLjg91CFNBrEV1CoLxo7ceVAxUupGymsCrdfExm8odV5",
        "/ip4/127.0.0.1/udp/4001/quic/p2p/12D3KooWLLjg91CFNBrEV1CoLxo7ceVAxUupGymsCrdfExm8odV5",
        "/ip4/172.17.0.3/tcp/4001/p2p/12D3KooWLLjg91CFNBrEV1CoLxo7ceVAxUupGymsCrdfExm8odV5",
        "/ip4/172.17.0.3/udp/4001/quic-v1/p2p/12D3KooWLLjg91CFNBrEV1CoLxo7ceVAxUupGymsCrdfExm8odV5",
        "/ip4/172.17.0.3/udp/4001/quic-v1/webtransport/certhash/uEiAXPSdMkTA82JOrbHAWGq0CqS4cTHbU8pRwguTFkOTLgw/certhash/uEiAKjvyQ_pQVOrhePZWpvb4K_xF9gISKW-4XQm0Ltpw1aw/p2p/12D3KooWLLjg91CFNBrEV1CoLxo7ceVAxUupGymsCrdfExm8odV5",
        "/ip4/172.17.0.3/udp/4001/quic/p2p/12D3KooWLLjg91CFNBrEV1CoLxo7ceVAxUupGymsCrdfExm8odV5",
        "/ip4/209.182.239.125/tcp/4001/p2p/12D3KooWGwvVPFCXBFTYMdcq2F18jTtXBtEq3SS9Z4wEHUvurGQu/p2p-circuit/p2p/12D3KooWLLjg91CFNBrEV1CoLxo7ceVAxUupGymsCrdfExm8odV5",
        "/ip4/209.182.239.125/udp/4001/quic/p2p/12D3KooWGwvVPFCXBFTYMdcq2F18jTtXBtEq3SS9Z4wEHUvurGQu/p2p-circuit/p2p/12D3KooWLLjg91CFNBrEV1CoLxo7ceVAxUupGymsCrdfExm8odV5",
        "/ip4/66.42.78.134/tcp/4001/p2p/12D3KooWDTzARvYtDNuKW1AdRtTjygmVbJ14M7VJExtanwQv8Tv8/p2p-circuit/p2p/12D3KooWLLjg91CFNBrEV1CoLxo7ceVAxUupGymsCrdfExm8odV5",
        "/ip4/66.42.78.134/udp/4001/quic-v1/p2p/12D3KooWDTzARvYtDNuKW1AdRtTjygmVbJ14M7VJExtanwQv8Tv8/p2p-circuit/p2p/12D3KooWLLjg91CFNBrEV1CoLxo7ceVAxUupGymsCrdfExm8odV5",
        "/ip4/66.42.78.134/udp/4001/quic/p2p/12D3KooWDTzARvYtDNuKW1AdRtTjygmVbJ14M7VJExtanwQv8Tv8/p2p-circuit/p2p/12D3KooWLLjg91CFNBrEV1CoLxo7ceVAxUupGymsCrdfExm8odV5"
    ],
    "AgentVersion": "kubo/0.22.0/3f884d3/docker",
    "Protocols": [
        "/ipfs/bitswap",
        "/ipfs/bitswap/1.0.0",
        "/ipfs/bitswap/1.1.0",
        "/ipfs/bitswap/1.2.0",
        "/ipfs/id/1.0.0",
        "/ipfs/id/push/1.0.0",
        "/ipfs/lan/kad/1.0.0",
        "/ipfs/ping/1.0.0",
        "/libp2p/circuit/relay/0.2.0/stop",
        "/libp2p/dcutr",
        "/x/"
    ]
}


分别在两个节点进行bootstrap添加

tips: 仅在一个节点另一个节点可以,会自动发现。但建议多节点时添加多个引导节点。

# 在节点1的bootstrap添加将节点2的地址信息。
# 注意端口号4001需要改成4002
docker exec -it ipfs_node1  ipfs bootstrap add /ip4/172.17.0.3/tcp/4002/p2p/12D3KooWLLjg91CFNBrEV1CoLxo7ceVAxUupGymsCrdfExm8odV5

# 在节点2的bootstrap添加将节点1的地址信息。
docker exec -it ipfs_node1  ipfs bootstrap add /ip4/172.17.0.2/tcp/4001/p2p/12D3KooWStan5Asx1XgqnmKUB2WfbqxWpXY6Rj8i5CfkBzDg8HzW

至此,两个节点的网络搭建完成!!!

三、测试网络

cli 方式

在node1上传一个测试文件'zxltesting.txt',再node2进行下载

  • node1 添加文件
root@OCI-SIN01-050-ops-bsnbase-com:/bsn/ipfs/node1# docker  exec ipfs_node1 ipfs add /data/ipfs/zxltesting.txt
 34 B / 34 B  100.00%added QmR9PYvA7mo1edPU7KGwwdu1dj2pVnHczr4nTyjCPHgA5M zxltesting.txt
  • node2下载文件
# 查看文件
root@OCI-SIN01-050-ops-bsnbase-com:/bsn/ipfs/node2# docker  exec ipfs_node2 ipfs cat QmR9PYvA7mo1edPU7KGwwdu1dj2pVnHczr4nTyjCPHgA5M
this is an empty file for testing

# 下载文件
root@OCI-SIN01-050-ops-bsnbase-com:/bsn/ipfs/node2/ipfs_data# ll
total 20
drwxr-xr-x 5 opc  root   147 Aug 24 16:58 ./
drwxr-xr-x 4 root root    60 Aug 24 15:48 ../
-rw-r--r-- 1 opc  users   23 Aug 24 16:56 api
drwxr-xr-x 5 opc  users   93 Aug 24 17:30 blocks/
-rw------- 1 opc  users 3053 Aug 24 16:58 config
drwxr-xr-x 2 opc  users  122 Aug 24 16:56 datastore/
-rw------- 1 opc  users  190 Aug 24 16:54 datastore_spec
-rw-r--r-- 1 opc  users   21 Aug 24 16:56 gateway
drwx------ 2 opc  users    6 Aug 24 16:54 keystore/
-rw-r--r-- 1 opc  users    0 Aug 24 16:56 repo.lock
-rw-r--r-- 1 opc  users    3 Aug 24 16:54 version
root@OCI-SIN01-050-ops-bsnbase-com:/bsn/ipfs/node2/ipfs_data# docker  exec ipfs_node2 ipfs get QmR9PYvA7mo1edPU7KGwwdu1dj2pVnHczr4nTyjCPHgA5M -o /data/ipfs/zxltesting.txt
Saving file(s) to /data/ipfs/zxltesting.txt
 34 B / 34 B  100.00% 0s
root@OCI-SIN01-050-ops-bsnbase-com:/bsn/ipfs/node2/ipfs_data# ll
total 24
drwxr-xr-x 5 opc  root   169 Aug 24 17:32 ./
drwxr-xr-x 4 root root    60 Aug 24 15:48 ../
-rw-r--r-- 1 opc  users   23 Aug 24 16:56 api
drwxr-xr-x 5 opc  users   93 Aug 24 17:30 blocks/
-rw------- 1 opc  users 3053 Aug 24 16:58 config
drwxr-xr-x 2 opc  users  122 Aug 24 16:56 datastore/
-rw------- 1 opc  users  190 Aug 24 16:54 datastore_spec
-rw-r--r-- 1 opc  users   21 Aug 24 16:56 gateway
drwx------ 2 opc  users    6 Aug 24 16:54 keystore/
-rw-r--r-- 1 opc  users    0 Aug 24 16:56 repo.lock
-rw-r--r-- 1 opc  users    3 Aug 24 16:54 version
-rw------- 1 root root    34 Aug 24 17:32 zxltesting.txt
root@OCI-SIN01-050-ops-bsnbase-c

API方式

https://docs.ipfs.tech/reference/kubo/rpc/#api-v0-add
使用postman 工具

  • 上传文件


    image.png
  • 下载文件

四、使用内置的webui系统(有问题)

image.png
  • 解决跨域问题

先弄node1

docker exec ipfs_node1 ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://外网ip:5001","http://内网IP:5001"]'

docker exec ipfs_node1 ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "POST"]'
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,992评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,212评论 3 388
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 159,535评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,197评论 1 287
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,310评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,383评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,409评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,191评论 0 269
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,621评论 1 306
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,910评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,084评论 1 342
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,763评论 4 337
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,403评论 3 322
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,083评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,318评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,946评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,967评论 2 351

推荐阅读更多精彩内容