Ubuntu系统中IPFS环境的配置

Ubuntu系统中IPFS环境的配置_第1张图片

1.简介

IPFS(InterPlanetaryFile System)是一个点对点的分布式超媒体分发协议,它整合了过去几年最好的分布式系统思路,为所有人提供全球统一的可寻址空间,包括Git、自证明文件系统SFSBitTorrentDHT,同时也被认为是最有可能取代HTTP的新一代互联网协议。
IPFS用基于内容的寻址替代传统的基于域名的寻址,用户不需要关心服务器的位置,不用考虑文件存储的名字和路径。我们将一个文件放到IPFS节点中,将会得到基于其内容计算出的唯一加密哈希值。哈希值直接反映文件的内容,哪怕只修改1比特,哈希值也会完全不同。当IPFS被请求一个文件哈希时,它会使用一个分布式哈希表找到文件所在的节点,取回文件并验证文件数据。
IPFS是通用目的的基础架构,基本没有存储上的限制。大文件会被切分成小的分块,下载的时候可以从多个服务器同时获取。IPFS的网络是不固定的、细粒度的、分布式的网络,可以很好的适应内容分发网络的要求。这样的设计可以很好的共享各类数据,包括图像、视频流、分布式数据库、整个操作系统、模块链、8英寸软盘的备份,还有静态网站。
IPFS提供了一个友好的WEB访问接口,用户可以通过本机的 IPFS-HTTP网关(http://localhost:5001/ipfs/) 或者公共的网关(http://ipfs.io/) 获取IPFS网络中的内容,也可以通过特定的浏览器或者插件通过ipfs:/or fs:/的方式直接获取内容。也许在不久的将来,IPFS协议将会彻底替代传统的HTTP协议。

2.安装IPFS

打开官网:https://ipfs.io/,根据平台下载相应安装包,针对Linux系统,下载go-ipfs的地址为:https://dist.ipfs.io/go-ipfs/v0.4.13/go-ipfs_v0.4.13_linux-amd64.tar.gz

下载好后,解压,并执行安装脚本:

sily@lyg-sily:~$ tar xvfz go-ipfs_v0.4.13_linux-amd64.tar.gz
sily@lyg-sily:~$ cd go-ipfs
sily@lyg-sily:~/go-ipfs$ ls
build-log  install.sh  ipfs  LICENSE  README.md
sily@lyg-sily:~/go-ipfs$ ./install.sh 
We cannot install ipfs in one of the directories /usr/local/bin /usr/bin
It seems that we do not have the necessary write permissions.
Perhaps try running this script as a privileged user:

    sudo ./install.sh

sily@lyg-sily:~/go-ipfs$ sudo ./install.sh
[sudo] password for sily: 
Moved ipfs to /usr/local/bin
sily@lyg-sily:~/go-ipfs$ ipfs help
USAGE
  ipfs - Global p2p merkle-dag filesystem.

  ipfs [--config= | -c] [--debug= | -D] [--help=] [-h=] [--local= | -L] [--api=]  ...

SUBCOMMANDS
  BASIC COMMANDS
    init          Initialize ipfs local configuration
    add     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  --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.

看到以上信息后,表明我们的IPFS已经成功安装。

3.创建ipfs节点

通过命令ipfs init,在本地建立一个IPFS节点。

sily@lyg-sily:~/go-ipfs$ ipfs init
initializing IPFS node at /home/sily/.ipfs
generating 2048-bit RSA keypair...done
peer identity: Qmb6u9rwNXNnWP8rMa8xAWsRQs3bF2zXa8wJ36boGQgJaH
to get started, enter:

    ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme

sily@lyg-sily:~/go-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 init命令后,会在根目录生成一个.ipfs的文件夹存储节点数据。

可以通过ipfs id查看节点id信息:

sily@lyg-sily:~/.ipfs$ ipfs id
{
    "ID": "Qmb6u9rwNXNnWP8rMa8xAWsRQs3bF2zXa8wJ36boGQgJaH",
    "PublicKey": "CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC6d3cfeSCYyI7X4I7hk9EIiZQi7U4t/WpyePqaoTZW7dUkzhlKn5lT745d4aoNE2ddYYynzUhXWj9w+xjQxql3VcO6rO7YLIUvie0mcT36001Cv3CJ3snqMtJXopByBRUp9zasx8yj4Yfb6TQkhbxaz4Wza505LgxoinXZO0CjHM2dp7rQSDxTPmf/SUZBGiwSAvoXyKEaBHS+xFtTXaRRYtoAtIZNnuhKN92PK/8Tz+kr43+vTI6psyCXd8XsueQ5/q8m7Ev+k0SLq75kYFrUZBxnASPdCV7i8415CxhMzfWocKvctCwdupOXxB5LwvBm5IWAiRwiLocZareI0ZP7AgMBAAE=",
    "Addresses": null,
    "AgentVersion": "go-ipfs/0.4.13/",
    "ProtocolVersion": "ipfs/0.1.0"
}

4.启动节点服务器

sily@lyg-sily:~/.ipfs$ ipfs daemon
Initializing daemon...
Adjusting current ulimit to 2048...
Successfully raised file descriptor limit to 2048.
Swarm listening on /ip4/10.0.2.15/tcp/4001
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip6/::1/tcp/4001
Swarm listening on /p2p-circuit/ipfs/Qmb6u9rwNXNnWP8rMa8xAWsRQs3bF2zXa8wJ36boGQgJaH
Swarm announcing /ip4/10.0.2.15/tcp/4001
Swarm announcing /ip4/127.0.0.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

此时,我们可以通过本地浏览器输入地址: http://localhost:5001/webui 看到一个UI界面,说明节点服务器启动成功。
Ubuntu系统中IPFS环境的配置_第2张图片

以上就是ipfs的简单配置,详细信息可参见ipfs官网:http://ipfs.io

你可能感兴趣的:(区块链)