下载go-ipfs

wget  https://github.com/ipfs/go-ipfs/releases/download/v0.4.17/go-ipfs_v0.4.17_linux-amd64.tar.gz

解压

[root@blockchain42 ipfs]# tar -zxvf go-ipfs_v0.4.17_linux-amd64.tar.gz
  go-ipfs/build-loggo-ipfs/install.shgo-ipfs/ipfs
  go-ipfs/LICENSE
  go-ipfs/README.md

执行insatll.sh

[root@blockchain42ipfs]# cd go-ipfs

[root@blockchain42go-ipfs]# ./install.sh
  Moved ./ipfs to/usr/local/bin

执行ipfs命令验证ipfs

root@blockchain42 go-ipfs]# ipfs
 SUBCOMMANDS
BASIC COMMANDS
init Initialize ipfs localconfiguration
add <path> Add a filetoIPFS
cat <ref> Show IPFS object data
get<ref> Download IPFS objects
ls <ref> List links froman object
refs <ref> List hashes oflinks froman object DATA STRUCTURE COMMANDS
block Interact withraw blocks inthedatastore
object Interact withraw dag nodes
files Interact withobjects asifthey were a unix filesystem
dag Interact withIPLD documents (experimental) ADVANCED COMMANDS
daemon Start a long-runningdaemon process
mount Mount an IPFS read-only mountpoint
resolve Resolve any type ofnamenamePublish andresolve IPNS names
key Create andlistIPNS namekeypairs
dns Resolve DNS links
pin Pin objects tolocalstorage
repo Manipulate theIPFS repository
stats Various operational stats
p2p Libp2p stream mounting
filestore Manage thefilestore (experimental) NETWORK COMMANDS
idShow info aboutIPFS peers
bootstrap Add orremove bootstrap peers
swarm Manage connections tothep2p network
dht Query theDHT forvalues orpeers
ping Measure thelatency ofa connection
diag Print diagnostics TOOL COMMANDS
config Manage configuration
versionShow ipfs versioninformation
update Download andapply go-ipfs updates
commands List all available commands Use 'ipfs <command> --help' to learn more about each command.ipfs uses a repository inthelocalfilesystem. By default, therepo islocated at~/.ipfs. To change therepo location, setthe$IPFS_PATH
environment variable: export IPFS_PATH=/path/to/ipfsrepo EXIT STATUS The CLI will exitwithone ofthefollowing values: 0Successful execution. 1Failed executions.

创建data, export目录

[root@blockchain42ipfs]# mkdir data

[root@blockchain42ipfs]# mkdir export

设置ipfs_path

[root@blockchain42 ipfs]# export IPFS_PATH=/data/ipfs/data

初始化ipfs

root@blockchain42 ipfs]# ipfs init

initializing IPFS node at /data/ipfs/data
generating -bit RSA keypair...donepeer identity: Qmcu1qxojgYV84hfRvvUBBLQzDLKka7kaAu8PUZi4DJziE
togetstarted, enter: ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme

修改配置文件

[root@blockchain42 data]# cd data

[root@blockchain42 data]# vimconfig
删除Bootstrap中的内容防止链接外部节点"Bootstrap": [
"/dnsaddr/bootstrap.libp2p.io/ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
"/dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
"/dnsaddr/bootstrap.libp2p.io/ipfs/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
"/dnsaddr/bootstrap.libp2p.io/ipfs/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
"/ip4/104.131.131.82/tcp//ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
"/ip4/104.236.179.241/tcp//ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
"/ip4/128.199.219.111/tcp//ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu",
"/ip4/104.236.76.40/tcp//ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64",
"/ip4/178.62.158.247/tcp//ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd",
"/ip6/:a880:::::d001/tcp//ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
"/ip6/:::d0:::/tcp//ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu",
"/ip6/:a880::::4a:/tcp//ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64",
"/ip6/2a03:b0c0:::::/tcp//ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd"],

设置ipfs_staging 和 ipfs_data

[root@blockchain42 data1]# export ipfs_staging=/data/ipfs/export

[root@blockchain42 data1]# export ipfs_data=/data/ipfs/data 

docker 启动

[root@blockchain42 data1]# docker run -d --name ipfs_host --restart="always"--privileged=true -v $ipfs_staging:/export -v $ipfs_data:/data/ipfs -p4001:-p127.0.0.::-p5001:5001ipfs/go-ipfs:latest
Unable tofindimage 'ipfs/go-ipfs:latest'locally
latest:Pulling from ipfs/go-ipfs
5497949500d2: Pull complete9cfd2e6d2b64: Pull complete8167893b973a:Pull complete0f61f69d653d: Pull complete8a98c133507f: Pull completee9bc9df9b0ba:Pull completeb5b58acfc7ee: Pull complete385a82e0ccbb:Pull completeDigest:sha256:31cc5713ef3e3e81bf868cbb56c19de2d15d661743d8b6077804dee26e929ac5
Status:Downloaded newer image foripfs/go-ipfs:latestWARNING: IPv4 forwarding isdisabled. Networking will not work.
e48224ac7e15ed3aab532b6a79d6077ab376a5a84c6a66b1f2444b0779271322 

查看是否启动成功

[root@blockchain42 data1]# docker logs -f ipfs_host1
Changinguser toipfs
ipfs version 0.4.
Found IPFS fs-repo at /data/ipfs
Initializing daemon...
Swarm listening on /ip4/127.0.0.1/tcp/
Swarm listening on /ip4/172.17.0.6/tcp/
Swarm listening on /p2p-circuit/ipfs/QmdafoEj6roToSiACimBxUhgdTa46gNfsfsNEKcqY8A6oP
Swarm announcing /ip4/127.0.0.1/tcp/
Swarm announcing /ip4/172.17.0.6/tcp/
APIserver listening on /ip4/127.0.0.1/tcp/
Gateway (readonly)server listening on /ip4/127.0.0.1/tcp/
Daemon is ready

到这单节点ipfs安装启动完成、 以相同的步骤在另一台机器上在部署一套

查看节点信息

[root@blockchain40 ~]# docker exec ipfs_host
  ipfs swarm peers/ip4/172.17.0.3/tcp//ipfs/QmUjD1DQwxfSVkac12mK74ozhe34eoxX7DoJTFev2NemFd

或者查看ipfs id

[root@blockchain40~]# docker exec ipfs_host
  ipfs id{
"ID": "QmUdmCCbmt5cQzPZST7U5ceaVdoCiHe2ZpxHopce5gFoXp",
"PublicKey": "CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC1u+LC40JsmMVMemNiRu7n9OEaiJDSh78WWgqzER3KuuUrBJDyO7FW/UG4jtT2hoPLpsfZtw0LsPO+LNQY6Je78AMYB6It0bQ9yLLI8crpYhIrPXdL9MxYi6E+ITiyz+64SVLlDbW/7q5xvMLr2jfQHTxrmBhkkULfqX0unBR3tm9AnhfN1Gwi+xrAYw1aZmN53cj2h12oWFZzLgd9XmWQtx5+32U+qECCfqQ9JnQVSy8LGKis3ZlgHSIg0m7upc3h7p/RQU1QWW4NHdW3KvSMB6QSIufUSc+rQ4rIz5QdWAv+iuXp89l2mialJbJ5sCHqyL6vCo/OHgkDPPOYlyx5AgMBAAE=",
"Addresses": [
"/ip4/127.0.0.1/tcp/4001/ipfs/QmUdmCCbmt5cQzPZST7U5ceaVdoCiHe2ZpxHopce5gFoXp",
"/ip4/172.17.0.2/tcp/4001/ipfs/QmUdmCCbmt5cQzPZST7U5ceaVdoCiHe2ZpxHopce5gFoXp"],
"AgentVersion": "go-ipfs/0.4.15/",
"ProtocolVersion": "ipfs/0.1.0"}

修改链接ip

/ip4/10.19.0.40/tcp/4001/ipfs/QmUdmCCbmt5cQzPZST7U5ceaVdoCiHe2ZpxHopce5gFoXp 

添加peer

[root@blockchain42 ~]# docker exec ipfs_host ipfs swarm connect /ip4/10.19.0.40/tcp//ipfs/QmUdmCCbmt5cQzPZST7U5ceaVdoCiHe2ZpxHopce5gFoXp
connect QmUdmCCbmt5cQzPZST7U5ceaVdoCiHe2ZpxHopce5gFoXp success

测试

在一台上添加数据、另一台上去, 测试集群是否添加上

[root@blockchain40 export]#  docker exec ipfs_host ipfs add /export/yangxingadded QmaKK2vxX4bGzXrnxdCuGBCBx6RAmez6TGtVXxE4c5QDst yangxing

[root@blockchain42 ~]# docker exec ipfs_host ipfs cat QmaKK2vxX4bGzXrnxdCuGBCBx6RAmez6TGtVXxE4c5QDstasydfklsajdflkjsaldfjks
05-11 22:51