IPFS初探
Posted BuguTian
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IPFS初探相关的知识,希望对你有一定的参考价值。
背景:听说IPFS=bittorrent+bitcoin+git+afs,有可能取代http,好像厉害的不行,所以要研究一下。
编译参考:https://github.com/ipfs/go-ipfs 结果各种墙都翻好了,一切基础设施都到位了,还是没编译成功shit(最后还是编过了)。
退而求其次,直接用官方提供的先试验一下吧。
下载地址:https://ipfs.io/docs/install/
1.上传安装
下载相应的版本,我下载的是:go-ipfs_v0.4.14_linux-amd64.tar.gz,上传到服务器,解压。
someone@ipfs:~$ tar -zxvf go-ipfs_v0.4.14_linux-amd64.tar.gz someone@ipfs:~$ cd go-ipfs/ someone@ipfs:~$ ./install.sh someone@ipfs:~/package/go-ipfs$ ipfs
显示的结果如下:
USAGE ipfs - Global p2p merkle-dag filesystem. ipfs [--config=<config> | -c] [--debug=<debug> | -D] [--help=<help>] [-h=<h>] [--local=<local> | -L] [--api=<api>] <command> ... SUBCOMMANDS BASIC COMMANDS init Initialize ipfs local configuration add <path> Add a file to IPFS cat <ref> Show IPFS object data get <ref> Download IPFS objects ls <ref> List links from an object refs <ref> List hashes of links from an object DATA STRUCTURE COMMANDS block Interact with raw blocks in the datastore object Interact with raw dag nodes files Interact with objects as if they were a unix filesystem dag Interact with IPLD documents (experimental) ADVANCED COMMANDS daemon Start a long-running daemon process mount Mount an IPFS read-only mountpoint resolve Resolve any type of name name Publish and resolve IPNS names key Create and list IPNS name keypairs dns Resolve DNS links pin Pin objects to local storage repo Manipulate the IPFS repository stats Various operational stats p2p Libp2p stream mounting filestore Manage the filestore (experimental) NETWORK COMMANDS id Show info about IPFS peers bootstrap Add or remove bootstrap peers swarm Manage connections to the p2p network dht Query the DHT for values or peers ping Measure the latency of a connection diag Print diagnostics TOOL COMMANDS config Manage configuration version Show ipfs version information update Download and apply go-ipfs updates commands List all available commands Use \'ipfs <command> --help\' to learn more about each command. ipfs uses a repository in the local file system. By default, the repo is located at ~/.ipfs. To change the repo location, set the $IPFS_PATH environment variable: export IPFS_PATH=/path/to/ipfsrepo EXIT STATUS The CLI will exit with one of the following values: 0 Successful execution. 1 Failed executions.
2. 初始化
someone@ipfs:~$ mkdir -p /ipfs/ /*很明显,根本不用执行这个命令,下面的/ipfs也不是指本地文件系统的/ipfs.*/ someone@ipfs:~$ ipfs init initializing IPFS node at /home/someone/.ipfs generating 2048-bit RSA keypair...done peer identity: QmSuUJKAfxYamzekBT2ePfyypyTXP3DgEsGKPxiedUneGh to get started, enter: ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme someone@ipfs:~/.ipfs$ 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
至此,所有的ipfs的内容都在 ~/.ipfs目录下了
someone@ipfs:~/.ipfs$ ls api blocks config datastore datastore_spec keystore repo.lock version
3. 修改配置文件
可以使用如下命令
someone@ipfs:export EDITOR=/usr/bin/vim someone@ipfs:ipfs config edit
查看节点ID
someone@ipfs:~$ ipfs id { "ID": "QmSuUJKAfxYamzekBT2ePfyypyTXP3DgEsGKPxiedUneGh", "PublicKey": "CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDBTEUgY8FCDbZeV8+h1XdRivlUVRlVlNmwr0oFP1ceoBnbMXP5IJ9GSXXLVVwl4IPwFBEscMo1wo6NRz3oMDeQWEgi9x5wuEOYvlNUAzVbwFWb77AmW10oZpGz7oo45Fd37/jdU+6JcDKPc4o5sR9pJo8PddP3g7rphF7nHncf3vh4vNeCsu0DylxPh6CGHf6+8c50Vjl9iAwBZ9zES+QYT4kYHF3icX63p2B8B5C+7ZC9ISfD4ZiKTYBHDob/XLQc7g7gdEbGuxmXJE/iFzju2PoEe+Ob1QXCAabWq80F/oxCAdX+wLisgHE6FbeYp5RV7IRi7s3L3xpFnQPukswtAgMBAAE=", "Addresses": null, "AgentVersion": "go-ipfs/0.4.14/", "ProtocolVersion": "ipfs/0.1.0" }
跨域资源共享CORS配置
someone@ipfs:~$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods \'["PUT", "GET", "POST", "OPTIONS"]\' someone@ipfs:~$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin \'["*"]\'
4. 启动服务器
someone@ipfs:~/.ipfs$ 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.15.129/tcp/4001 Swarm listening on /ip6/::1/tcp/4001 Swarm listening on /p2p-circuit/ipfs/QmSuUJKAfxYamzekBT2ePfyypyTXP3DgEsGKPxiedUneGh Swarm announcing /ip4/127.0.0.1/tcp/4001 Swarm announcing /ip4/192.168.15.129/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
启动成功后就可以,查看UI界面了:
http://127.0.0.1:5001/webui
结果如下:
5. 编译失败后调试成功
按步骤编译,墙也是翻好的,每次都卡在类似的地方:
someone@ipfs:~$ make install .... [get ] [fetch] go-libp2p-crypto QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo [0 / 202] 392sERROR: [2 / 101 ] parallel fetch: failed to fetch package: QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8: Post https://ipfs.io/api/v0/get?arg=QmRb5jh8z2E8hMGN2txxxx1yHynUanqnZ3UeKwgN1i9P1F8&encoding=json&stream-channels=true: dial tcp 173.252.100.32:443: getsockopt: connection timed out [0 / 202] 442s^Cmk/gx.mk:4: recipe for target \'gx-deps\' failed
https再开一个终端,wget都可以访问。使用"make install_unsupported"也没卵用,然后再次"make install"还是不行。
结果,第二天,安装完官方的ipfs并启动后,再make install 源码,结果,编译通过了,难道这个编译是看天气的吗?
猜测编译可能和以下操作有关:
apt-get install libzip-dev
参考网址:
https://www.oschina.net/p/ipfs
https://raw.githubusercontent.com/ipfs/ipfs/master/papers/ipfs-cap2pfs/ipfs-p2p-file-system.pdf
以上是关于IPFS初探的主要内容,如果未能解决你的问题,请参考以下文章