1.1 下载
地址:https://dist.ipfs.io/#go-ipfs
1.2 安装
lgydembp:IPFS liguoyu$ ls
go-ipfs_v0.4.17_darwin-amd64.tar.gz
lgydembp:IPFS liguoyu$ tar -zxvf go-ipfs_v0.4.17_darwin-amd64.tar.gz
x go-ipfs/build-log
x go-ipfs/install.sh
x go-ipfs/ipfs
x go-ipfs/LICENSE
x go-ipfs/README.md
lgydembp:IPFS liguoyu$ pwd
/Users/liguoyu/Desktop/IPFS
lgydembp:IPFS liguoyu$ ls
go-ipfs go-ipfs_v0.4.17_darwin-amd64.tar.gz
lgydembp:IPFS liguoyu$ cd go-ipfs
lgydembp:go-ipfs liguoyu$ ls
LICENSE README.md build-log install.sh ipfs
lgydembp:go-ipfs liguoyu$ mv ipfs /usr/local/bin/ipfs
mv ipfs /usr/local/bin/ipfs,将已解压的文件夹中的ipfs文件移动到/usr/local/bin/文件夹中。
1.3 节点创建
通过ipfs init在本地计算机建立一个IPFS节点,此时根目录生成一个.ipfs的文件夹存储节点数据。
lgydembp:go-ipfs liguoyu$ ipfs init
initializing IPFS node at /Users/liguoyu/.ipfs
generating 2048-bit RSA keypair...done
peer identity: QmeUHZQR35N3Bk8yXy73DNQFtCxQptPmerJHALHiawmojL
to get started, enter:
ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme
lgydembp:go-ipfs liguoyu$ cd ~/.ipfs/
lgydembp:.ipfs liguoyu$ ls
blocks datastore keystore
config datastore_spec version
lgydembp:.ipfs liguoyu$
ipfs节点默认存储空间为10个G,如果你自己想修改节点默认存储空间,可通过以下命令打开配置文件修改。
lgydembp:/ liguoyu$ export EDITOR=/usr/bin/vim
lgydembp:/ liguoyu$ ipfs config edit
1.4 节点启动
1.4.1 通过 ipfs id 查看节点id
lgydembp:~ liguoyu$ ipfs id
{
"ID": "QmeUHZQR35N3Bk8yXy73DNQFtCxQptPmerJHALHiawmojL",
"PublicKey": "CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDXk4g9ITTCJiNcJ7J/A4Wj5VSCOu11Tpkh1d349Say/yEgQWFA1JFVJDUTId+C1B54xdj3W5gMH2Dhr1fAP1f6DZAtnXLRFE47Z1EzLaIQ5Uoo+sEfNVuOl6oT1MMq0d6vw0Z+m9v4DCPAlRAfowuJSLZWln5OzN4HXNpKHT/bm+6oPl//v6cDdaD8l9bLcJh5mwIaH3senMLS0C5eFTPGdfdw6utDxQh96g50O11MrQVeSUNsGL2L7CgfDsDTp3wNJXayH9C9fdD1yCgi5nHC6K0z7U/D/GjT3UDjPNM4deWZJYKF/zZ7gLIGzJCkoh8w2WqRvlDuVS5T5Yky4/LbAgMBAAE=",
"Addresses": null,
"AgentVersion": "go-ipfs/0.4.17/",
"ProtocolVersion": "ipfs/0.1.0"
}
lgydembp:~ liguoyu$
节点id:QmeUHZQR35N3Bk8yXy73DNQFtCxQptPmerJHALHiawmojL
1.4.2 跨域资源共享CORS配置:
当我们在前端通过js接口操作ipfs时,会遇到跨域资源访问问题,可以在终端执行以下配置来解决
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT","GET", "POST", "OPTIONS"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Credentials '["true"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Headers '["Authorization"]'
ipfs config --json API.HTTPHeaders.Access-Control-Expose-Headers '["Location"]'
1.4.3 启动节点服务:
lgydembp:~ liguoyu$ ipfs daemon
Initializing daemon...
Successfully raised file descriptor limit to 2048.
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/192.168.1.5/tcp/4001
Swarm listening on /ip6/::1/tcp/4001
Swarm listening on /p2p-circuit/ipfs/QmeUHZQR35N3Bk8yXy73DNQFtCxQptPmerJHALHiawmojL
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip4/192.168.1.5/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
1.5 验证服务器
方式一:新建终端执行下面的命令
ipfs cat /ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme
方式二:打开 http://localhost:5001/webui
网友评论