准备
环境
- 安装好 go 环境
- 安装好 docker
swarm.key
swarm.key 用来做私链认证的密钥,最终要放在 /ipfs/data
目录下
go get github.com/Kubuxu/go-ipfs-swarm-key-gen
cd $GOPATH
go build
./ipfs-swarm-key-gen > swarm.key
查下生成的 swarm.key 内容:
/key/swarm/psk/1.0.0/
/base16/
5c99c0c67fe9d45d5b612afcb1f325d2826b2645ebb77c43e05e4b8472ccb3db
挂载目录
ipfs 的 export 和 data 目录挂载到主机上,这里做下准备,每个不同是私链节点的挂载目录不一样。
节点 node0 要挂载的主机目录:
/Users/lidiqing/Docker/ipfs/nodes/node0/export
/Users/lidiqing/Docker/ipfs/nodes/node0/data
节点 node1 要挂载的主机目录:
/Users/lidiqing/Docker/ipfs/nodes/node1/export
/Users/lidiqing/Docker/ipfs/nodes/node1/data
…...
拉取镜像
拉取最新的镜像
docker search ipfs
stevenpc:~ lidiqing$ docker search ipfs
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ipfs/go-ipfs Go implementation of IPFS, the InterPlanetar… 75 [OK]
ipfs/ipfs-cluster Collective pinning and composition for IPFS. 11 [OK]
ipfs/js-ipfs IPFS implementation in JavaScript 3 [OK]
ipfs/ci-websites 1
qnib/ipfs Docker image to integrate ipfs into QNIBTerm… 1 [OK]
yeasy/ipfs Docker images for IPFS node. 0 [OK]
steveliuiii/ipfs-combo 0
brimstone/ipfs Inter Planetary File System 0
district0x/ipfs-server 0
district0x/ipfs-daemon 0
ipfs/testground 0
appliedblockchain/ipfs-solo Solo IPFS private node, useful for developme… 0
controlplane/ipfs-cluster-test 0
blockchainlg/ipfs-service 0
graphprotocol/ipfs-sync 0
victorbjelkholm/ipfsbin ipfsbin 0 [OK]
jastam/ipfs-api 0
schiltron/ipfs 0
ipfs/ipfs-cluster-test Testing container for IPFS Cluster 0
olizilla/ipfs-dns-deploy 0
zenground0/ipfs-cluster 0
joshorig/ipfs-cluster-k8s-sidecar 0
lncm/ipfs LNCM take on IPFS 0
sneak/ipfs-ubuntu-mirror image that syncs and publishes ubuntu mirror… 0 [OK]
ipfsfb/ipfs-peer 0
docker pull ipfs/go-ipfs
stevenpc:~ lidiqing$ docker pull ipfs/go-ipfs
Using default tag: latest
latest: Pulling from ipfs/go-ipfs
Digest: sha256:6c12c276d3efcb16475d04ad77bbb2a1634a3514c85c434333471f593521a011
Status: Image is up to date for ipfs/go-ipfs:latest
启动容器
创建节点
这里演示创建节点 node0 的流程,其他节点的创建流程一致,端口号和目录要修改。
把 swarm.key 放入到 /Users/lidiqing/Docker/ipfs/nodes/node0/data
目录下。
启动:
docker run
--name ipfs-node-0
-v /Users/lidiqing/Docker/ipfs/nodes/node001/export:/export
-v /Users/lidiqing/Docker/ipfs/nodes/node001/data:/data/ipfs
-p 10000:4001
-p 11000:5001
-p 12000:8080
-d ipfs/go-ipfs:latest
查看日志:
docker logs -f ipfs-node-0
stevenpc:~ lidiqing$ docker logs ipfs-node-0
Changing user to ipfs
ipfs version 0.4.22
Found IPFS fs-repo at /data/ipfs
Initializing daemon...
go-ipfs version: 0.4.22-
Repo version: 7
System version: amd64/linux
Golang version: go1.12.7
Swarm is limited to private network of peers with the swarm key
Swarm key fingerprint: 3eec03eb6b5fcb24231c677adfb979f3
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/172.17.0.2/tcp/4001
Swarm listening on /p2p-circuit
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip4/172.17.0.2/tcp/4001
API server listening on /ip4/0.0.0.0/tcp/5001
WebUI: http://0.0.0.0:5001/webui
Gateway (readonly) server listening on /ip4/0.0.0.0/tcp/8080
Daemon is ready
打印出 Daemon is ready
说明 ipfs 已经启动了。Swarm is limited to private network of peers with the swarm key
可以看出使用了密钥,属于私链节点。
需要清理一下公链的引导节点。
docker exec ipfs-node-0 bootstrap rm —all
查看节点
按照上面的方式我们创建了多个节点,现在进入 node0 查看下情况。
打开节点的 shell:
docker exec -it ipfs-node-0 /bin/sh
查看已连接的所有 p2p 节点:
ipfs swarm peers
/ # ipfs swarm peers
/ip4/172.17.0.10/tcp/4001/ipfs/QmXtt8dL3yRbpbfRRdmkDzBHUsvqa5WBReeEAtcd6NXR8A
/ip4/172.17.0.11/tcp/4001/ipfs/QmaR7rUgZwmYhWb9coyV3AVnXc1yZ6aYJXd432UJUf8Pdw
/ip4/172.17.0.3/tcp/4001/ipfs/Qmf7E5tSShzQDLNv3m79jjEosrpV5rhEsXS3bNRWfDXXoS
/ip4/172.17.0.4/tcp/4001/ipfs/QmdB91tH4Ecu7nEngkaTfWbBAxzT9dYqiDNRT6nGTk8nms
/ip4/172.17.0.5/tcp/4001/ipfs/QmTYvTFm9388MCpSFs6ZmKjQrytwSj9LuAuT2jcbdWvca7
/ip4/172.17.0.6/tcp/4001/ipfs/QmdaS4HPHnbcGZ8dYD4MXzUWmGEyPg87uKRttJMkK5YuDc
/ip4/172.17.0.7/tcp/4001/ipfs/QmX9xfNDkRm7kCqUpJrLxMz7dg45JFEPqDfPekCoYc9kZ6
/ip4/172.17.0.8/tcp/4001/ipfs/QmcPuMWpwsvgfdVEGG91afP9X6tVU24cij5ZpU9D8oa8rP
/ip4/172.17.0.9/tcp/4001/ipfs/QmRngf7BQmczXit23NV5FY6dpWNyWQLPm6RoFXc53XZgpM
私链已经创建成功