caliper的实操与报错合集,超详细的教程

实操

验证python,make,g++,gcc,git版本

sudo apt install -y python2.7

sudo apt install -y pip

sudo apt install -y make

sudo apt install -y g++ 

sudo apt install -y git

sudo apt install -y gcc

这里官方文档推荐的是使用nvm安装nodejs

建议使用nvm(Node Version Manager)安装,nvm的安装方式如下:

# 安装nvm
curl -o- https://gitee.com/mirrors/nvm/raw/v0.33.2/install.sh | bash

# 加载nvm配置
source ~/.$(basename $SHELL)rc
# 安装Node.js 8
nvm install 8
# 使用Node.js 8
nvm use 8

安装docker

# 更新包索引
sudo apt-get update
# 安装基础依赖库
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
# 添加Docker官方GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# 添加docker仓库
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
# 更新包索引
sudo apt-get update
# 安装Docker
sudo apt-get install docker-ce docker-ce-cli containerd.io
# 安装docker compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

Caliper提供了方便易用的命令行界面工具caliper-cli,推荐在本地进行局部安装:

建立一个工作目录

mkdir benchmarks && cd benchmarks

对NPM项目进行初始化

npm init

这一步主要是为在工作目录下创建package.json文件以方便后续依赖项的安装,如果不需要填写项目信息的话可以直接执行npm init -y

我一般就是一直回车

安装caliper-cli

npm install --only=prod @hyperledger/[email protected]

由于Caliper所有依赖项的安装较为耗时,因此使用--only=prod选项用于指定NPM只安装Caliper的核心组件,而不安装其他的依赖项(如各个区块链平台针对Caliper的适配器)。在部署完成后,可以通过caliper-cli显式绑定需要测试的区块链平台及相应的适配器。

验证caliper-cli安装成功

npx caliper --version

 caliper绑定

因为这个caliper他是一个安装非常快的,压测装置所以,我们需要的基础操作就会很多,反之如果一个比较重的压测装置,他就会自动获取很多东西。

我们可以使用help来获取使用方法

Usage:
  caliper bind --caliper-bind-sut fabric --caliper-bind-sdk 1.4.1 --caliper-bind-cwd ./ --caliper-bind-args="-g"

Options:
  --help               Show help  [boolean]
  -v, --version        Show version number  [boolean]
  --caliper-bind-sut   The name of the platform to bind to  [string]
  --caliper-bind-sdk   Version of the platform SDK to bind to  [string]
  --caliper-bind-cwd   The working directory for performing the SDK install  [string]
  --caliper-bind-args  Additional arguments to pass to "npm install". Use the "=" notation when setting this parameter  [string]

  • caliper-bind-sut :用于指定需要测试的区块链平台,即受测系统(***S***ystem ***u***nder ***T***est);
  •  caliper-bind-sdk:用于指定适配器版本; 
  • caliper-bind-cwd:用于绑定caliper-cli的工作目录,caliper-cli在加载配置文件等场合时均是使用相对于工作目录的相对路径; 
  • caliper-bind-args:用于指定caliper-cli在安装依赖项时传递给npm的参数,如用于全局安装的-g。 

这里使用FISCO-BCOS作为示例绑定的命令就是

npx caliper bind --caliper-bind-sut fisco-bcos --caliper-bind-sdk latest

如果遇到报错error [caliper] [bind] Failed to execute “npm“ with return code 1.Command failed就去这篇文章看一下文章在这里

 快速体验

拉取一波他写好的代码我们执行流程就可以了

git clone https://gitee.com/vita-dounai/caliper-benchmarks.git

执行万能的hello world

不需要进入我们下载的这个里面去哦

npx caliper benchmark run --caliper-workspace caliper-benchmarks --caliper-benchconfig benchmarks/samples/fisco-bcos/helloworld/config.yaml  --caliper-networkconfig networks/fisco-bcos/4nodes1group/fisco-bcos.json

 慢慢准备就好了

猜你喜欢

转载自blog.csdn.net/qq_57309855/article/details/126959885