背景:聽說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