ipfs安装和配置
2018-07-20 本文已影响114人
foochane
1 关于ipfs
- 官方网站:https://ipfs.io/
- github: https://github.com/ipfs/
- 中国官方社区:http://ipfser.org/
2 安装ipfs
具体安装过程可以参照如下链接:https://ipfs.io/docs/install/
2.1 下载
下载地址:https://dist.ipfs.io/#go-ipfs
下载:go-ipfs_v0.4.16_linux-amd64.tar.gz
2.2 安装
$ tar zxvf go-ipfs_v0.4.16_linux-amd64.tar.gz
$ cd go-ipfs
$ ./install.sh
安装成功后会将go-ipfs文件夹下的ipfs文件移动到/usr/local/bin目录下
2.3 测试
运行ipfs help
命令,如果出现如下内容说明安装成功。
$ ipfs help
USAGE
ipfs - Global p2p merkle-dag filesystem.
ipfs [--config=<config> | -c] [--debug=<debug> | -D] [--help=<help>] [-h=<h>] [--local=<local> | -L] [--api=<api>] <command> ...
3 节点配置
3.1 创建节点
执行命令ipfs init
$ ipfs init
initializing IPFS node at /home/fc/.ipfs
generating 2048-bit RSA keypair...done
peer identity: QmYptDAwzpZQunynPi5oUQBCyXYJRCVphaPLuL1BPhpZVh
to get started, enter:
ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme
执行以上命令后,或者用户的根目录( /home/fc/)下生成一个名为.ipfs文件夹用于存储节点数据。
3.2 修改存储空间
.ipfs节点的默认存储空气为10个G,如果需要修改可以在~/.ipfs/config文件中修改。
将"StorageMax": "10GB"
修改为其他值即可。
3.3 查看节点ID
使用命令ipfs id
$ ipfs id
{
"ID": "QmYptDAwzpZQunynPi5oUQBCyXYJRCVphaPLuL1BPhpZVh",
"PublicKey": "CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDtDhxfTIZwnHR25wobaGoEjYkub/oAH57nwPpVhg/dLhDXn3zpG1Gd773S2N6bWZzqnilSzVyVbPHP6WVxgtLZK/iQ4uWcipn7mzACyx9qkJown13H8DqLHrzdMkRc//MyylsUI8FSWWzmd3O/yMliupjPIQIV+b8sfBOSpoBuWJu4RBh8HcHV91iQpNxua4R0uU4uaUtQxVvLjwhu3lKWEuZBhk6Q42WFPF99QWTVWYMD05mVNs2cDJ2kZOjbFUW4803JeCGTPEtHz9KSZI3EGefynIUqNEU0nxXxS/E13OdM8rDyQqQ4tBFKN5WAFxkjGK13UryNu6O7RJ0nLRFPAgMBAAE=",
"Addresses": null,
"AgentVersion": "go-ipfs/0.4.16/",
"ProtocolVersion": "ipfs/0.1.0"
}
3.4 添加文件到节点
- 添加命令:ipfs add filename
- 查看命令:ipfs cat 添加文件时返回的哈希值
具体操作:
创建一个文件并在里面写入"123456":
$ touch ipfsfile.txt
$ echo "123456" > ipfsfile.txt
添加到本地节点:
$ ipfs add ipfsfile.txt
added QmQU2gS4gZ7TpiTECjDUxdQFd9bBBEWxDxPPfhLfYHVuei ipfsfile.txt
7 B / 7 B [===============================================================================================] 100.00%
添加成功后,会返回该文件的哈希QmQU2gS4gZ7TpiTECjDUxdQFd9bBBEWxDxPPfhLfYHVuei
,我们可以通过它来查看刚刚添加的文件:
$ ipfs cat QmQU2gS4gZ7TpiTECjDUxdQFd9bBBEWxDxPPfhLfYHVuei
123456
3.5 启动节点服务器
使用命令ipfs daemon
$ 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/172.16.166.1/tcp/4001
Swarm listening on /ip4/172.17.0.1/tcp/4001
Swarm listening on /ip4/192.168.1.102/tcp/4001
Swarm listening on /ip4/192.168.162.1/tcp/4001
Swarm listening on /ip6/::1/tcp/4001
Swarm listening on /p2p-circuit/ipfs/QmYptDAwzpZQunynPi5oUQBCyXYJRCVphaPLuL1BPhpZVh
Swarm announcing /ip4/117.75.47.134/tcp/60249
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip4/172.16.166.1/tcp/4001
Swarm announcing /ip4/172.17.0.1/tcp/4001
Swarm announcing /ip4/192.168.1.102/tcp/4001
Swarm announcing /ip4/192.168.162.1/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
启动后在浏览器中输入:https://ipfs.io/ipfs/QmQU2gS4gZ7TpiTECjDUxdQFd9bBBEWxDxPPfhLfYHVuei
即可查看刚刚添加的文件的具体内容。
3.6 验证
具体参考:https://ipfs.io/docs/getting-started/
$ ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme
$ ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme
Hello and Welcome to IPFS!
██╗██████╗ ███████╗███████╗
██║██╔══██╗██╔════╝██╔════╝
██║██████╔╝█████╗ ███████╗
██║██╔═══╝ ██╔══╝ ╚════██║
██║██║ ██║ ███████║
╚═╝╚═╝ ╚═╝ ╚══════╝
If you're seeing this, you have successfully installed
IPFS and are now interfacing with the ipfs merkledag!
-------------------------------------------------------
| Warning: |
| This is alpha software. Use at your own discretion! |
| Much is missing or lacking polish. There are bugs. |
| Not yet secure. Read the security notes for more. |
-------------------------------------------------------
Check out some of the other files in this directory:
./about
./help
./quick-start <-- usage examples
./readme <-- this file
./security-notes