ubuntu 搭建iotex单机区块链环境

64 阅读2分钟

iotex主要通过结合物联网设备进行资产管理的区块链应用,要在Ubuntu上搭建IoTeX私有链,你可以遵循以下步骤:

  1. 安装Go语言:IoTeX的节点软件是用Go语言编写的,因此你需要先安装Go。可以通过Ubuntu的包管理器安装Go,使用以下命令:

    bash
    sudo apt update
    sudo apt install golang-go
    
  2. 获取IoTeX源代码:你可以从IoTeX的官方GitHub仓库克隆源代码。使用以下命令:

    bash
    git clone https://github.com/iotexproject/iotex-core.git
    
  3. 编译IoTeX:进入克隆的目录并编译源代码。

    bash
    cd iotex-core
    make
    
  4. 配置私有链:你需要创建或获取配置文件,这些文件定义了你的私有链的参数。这些配置文件通常包括创世文件、节点配置等。

    配置环境变量打开你的~/.profile~/.bashrc文件,并添加以下行:

    
    bash
    export IOTEX_HOME=/var/data
    
    

    然后,运行以下命令使更改生效:

    
    bash
    source ~/.profile
    或
    source ~/.bashrc
    
    

    下载配置文件

    
    mkdir -p ~/iotex-var
    cd ~/iotex-var
    export IOTEX_HOME=$PWD
    mkdir -p $IOTEX_HOME/data
    mkdir -p $IOTEX_HOME/log
    mkdir -p $IOTEX_HOME/etc
    curl https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/v2.0.4/config_mainnet.yaml > $IOTEX_HOME/etc/config.yaml
    curl https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/v2.0.4/genesis_mainnet.yaml > $IOTEX_HOME/etc/genesis.yaml
    curl https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/v2.0.4/trie.db.patch > $IOTEX_HOME/data/trie.db.patch
    
    

    或从默认目录

    
    curl https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/v2.0.4/config_mainnet.yaml > /var/data/etc/config.yaml
    curl https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/v2.0.4/genesis_mainnet.yaml > /var/data/etc/genesis.yaml
    curl https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/v2.0.4/trie.db.patch > /var/data/trie.db.patch
    
    

    或从快照开始(而不是从创世块同步),运行以下命令:

    
    curl -L https://t.iotex.me/mainnet-data-latest > $IOTEX_HOME/data.tar.gz
    tar -xzf data.tar.gz
    
    
  5. 运行节点:使用编译好的二进制文件启动你的IoTeX节点。运行以下命令:

    bash
    nohup ./bin/iotex-server   -config-path=$IOTEX_HOME/etc/config.yaml   -genesis-path=$IOTEX_HOME/etc/genesis.yaml &
    

    或无配置启动

    bash
    ./bin/iotex-server  
    
  6. 验证节点:确保你的节点正在运行并且可以连接到你的私有链。

  7. 使用ioctl:IoTeX提供了一个命令行客户端ioctl,你可以使用它来与IoTeX区块链进行交互。安装ioctl的命令通常是:

    bash
    sudo apt install ioctl
    

    curl https://raw.githubusercontent.com/iotexproject/iotex-core/master/install-cli.sh | sh
    
  8. 连接节点:确保你的节点正在运行,可以通过以下命令连接私有链。

    ioctl config set endpoint localhost:14014 --insecure
    
  9. 参考文档iotexproject/iotex-bootstrap: All necessary configuration files and step-by-step instructions for setting up and running a full-node on the IoTeX blockchain. Start contributing to the IoTeX network and explore advanced node features. (github.com)