- ubuntu 20.04 下Fabric运行及配置说明
- 注:本文是对 《hyperledger/fabric-区块链快速入门教程+错误解决——良好用户体验》 的补充和优化,更为简洁和容易上手,基本上按顺序来不会有太多的错误,可相互参考
- 一、Ubuntu 基础配置
- 1. 更新源
- 2. 更新hosts
- 3. 安装软件
- 3.1 谷歌浏览器安装
- 3.2 火焰截图安装
- 3.3 微信&QQ安装
- 3.4 Typora安装
- 4. 安装依赖
- 4.1 git
- 4.2 go
- 4.3 nodejs
- 4.4 docker
- 二、项目初始化(20220601——项目已加速,可行)
- 1. 创建工作目录
- 2. 初始环境及文件获取(20220601——链接可用)
- 2.1 对应2.2.5版本
- >> fabric-2.2.5版本:
- >> docker-2.2.5版本:
- **核心**:替换2.2.5 版本的peer、orderer和tools的TAG为latest:
- 2.2 对应1.1.0版本
- >> fabric-1.1.0版本:
- >> docker-1.1.0版本:
- **核心**:替换1.1.0 版本的peer、orderer和tools的TAG为latest:(fabric-javaenv、fabric-ccenv 、fabric-couchdb最好也替换)
- 3. 启动网络
- 3.1 启动2.2.5版本网络
- 3.2 创建通道testchannel
- 3.3 调用./asset-transfer-basic/chaincode-javascript/内的合约basic
- 3.4 确认二进制文件peer可用
- 3.5 合约调用
- 3.5.1 组织Org1环境配置
- 3.5.2 组织Org1调用合约对资产初始化
- 3.5.3 组织Org1调用合约查询
- 3.5.4 组织Org1调用合约更改资产所有者
- 3.5.5 组织Org2环境配置
- 3.5.6 组织Org2调用合约查询结果
- 3.6 关闭网络
- 3.7 删除重复docker
- 3.8 >> 1.1.0 版本安装
- 3.8.1 网络初始化
- 3.8.2 启动网络
- 3.8.3 关闭网络
- 3.8.4 部署智能合约
- 3.8.4.1 fabric 1.1 初始声明
- 3.8.4.2 fabric 1.1 网络启动
- 3.8.4.2.1 基于docker启动cli对应镜像,并设置cli环境变量:
- 3.8.4.2.2 基于cli镜像配置通道信息,加入通道并更新Org1在通道中的节点定义
- 3.8.4.3 fabric-1.1.0 安装并调用合约
- 3.8.5 fabric-1.1.0 查询容器日志
- 3.8.6 调用couchdb启动 fabric 1.1
- 3.8.6.1 fabric1.1.0 基于脚本调用couchdb
- 此时链接:[http://localhost:5984/_utils/](http://localhost:5984/_utils/) 可查看couchdb中的数据
- 3.8.6.2 手动添加智能合约
- 3.8.7 fabric-1.1.0 关闭网络
- 疑难解惑
- 1. 项目切版本报错:
- 2. 启动网络报docker-compose未找到命令
- 3. 1.1.0版本启动网络报 SIGSEGV 错误
- 4. 1.1.0 版本使用couchdb报Error: proposal failed (err: rpc error: code = Unavailable desc = transport is closing)错
- 5. 1.1.0 版本调用合约报Error endorsing invoke错
hyperledger/fabric-区块链快速入门教程+错误解决——良好用户体验
一、Ubuntu 基础配置 1. 更新源清华镜像站Ubuntu 镜像使用帮助
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
gedit /etc/apt/sources.list
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal stable # deb-src [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal stable deb https://typoraio.cn/linux ./ # deb-src https://typoraio.cn/linux ./
2. 更新hostsapt-get update
添加hosts直连
gedit /etc/hosts
140.82.114.3 github.com3. 安装软件 3.1 谷歌浏览器安装
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb dpkg -i google-chrome-stable_current_amd64.deb3.2 火焰截图安装
3.3 微信&QQ安装sudo apt-get install flameshot
软件链接:https://deepin-wine.i-m.dev/
3.4 Typora安装wget -O- https://deepin-wine.i-m.dev/setup.sh | sh
sudo apt-get install com.qq.weixin.deepin //微信
sudo apt-get install com.qq.im.deepin //QQ
sudo apt-get install com.tencent.meeting.deepin //腾讯会议
网盘中 0.11.18 版本以下均为免费版
4. 安装依赖 4.1 gitdpkg -i typora_0.11.13_amd64.deb
sudo apt-get install git
gedit /etc/profile
#workspace export WORKSPACE=/workspace #go export GOROOT=/usr/local/software/go export GOBIN=$GOROOT/bin export GOPATH=$WORKSPACE/go #hyperledger export FABRIC=$WORKSPACE/github.com/fabric #path export PATH=$PATH:$GOROOT/bin:$GOPATH/bin:$FABRIC/fabric-samples/bin #END
4.2 gosource /etc/profile
go version
wget https://studygolang.com/dl/golang/go1.14.6.linux-amd64.tar.gz mkdir /usr/local/software tar -zxvf go1.14.6.linux-amd64.tar.gz -C /usr/local/software4.3 nodejs
apt-get install nodejs apt-get install npm4.4 docker
参考链接:https://www.runoob.com/docker/ubuntu-docker-install.html
// 安装代码如下 // 先更新本地的软件源,使用中科大的 cp /etc/apt/sources.list /etc/apt/sources.list.bak sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list apt update // 更新完成后先安装需要的包,共5个 apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common // 由于安装docker需要类似先注册一下,所以先添加 Docker 的官方 GPG 密钥: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - // 添加 Docker-ce 软件源 add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable" // 再次更新并安装 apt-get update apt-get install docker-ce //设置开机自启动 systemctl enable docker systemctl start docker //没报错即安装完成 docker --version
sudo mkdir -p /etc/docker
gedit /etc/docker/daemon.json
{
"registry-mirrors": [
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn"]
}
二、项目初始化(20220601——项目已加速,可行) 1. 创建工作目录sudo systemctl daemon-reload
sudo systemctl restart docker
sudo mkdir -p /workspace/go/bin /workspace/github.com/ cd /workspace/github.com/ git clone https://hub.0z.gs/hyperledger/fabric.git git clone https://hub.0z.gs/jessie-anderson/audit-chain.git cd fabric/ git checkout release-2.2 git clone https://hub.0z.gs/hyperledger/fabric-samples.git cd fabric-samples/ git checkout release-2.2 cd /workspace/github.com/ sudo chmod 777 -R *
项目获取过程:
root@The-Land-Like-as-A-Picture:/workspace/github.com# git clone https://hub.0z.gs/hyperledger/fabric.git 正克隆到 'fabric'... remote: Enumerating objects: 154625, done. remote: Counting objects: 100% (110/110), done. remote: Compressing objects: 100% (75/75), done. remote: Total 154625 (delta 48), reused 65 (delta 35), pack-reused 154515 接收对象中: 100% (154625/154625), 125.51 MiB | 4.83 MiB/s, 完成. 处理 delta 中: 100% (106856/106856), 完成. root@The-Land-Like-as-A-Picture:/workspace/github.com# cd fabric/ root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric# git branch -a * main remotes/origin/HEAD -> origin/main remotes/origin/feature/ca remotes/origin/feature/convergence remotes/origin/main remotes/origin/mergify/bp/release-1.4/pr-2863 remotes/origin/mergify/bp/release-2.2/pr-2863 remotes/origin/mergify/bp/release-2.3/pr-2863 remotes/origin/release-1.0 remotes/origin/release-1.1 remotes/origin/release-1.2 remotes/origin/release-1.3 remotes/origin/release-1.4 remotes/origin/release-2.0 remotes/origin/release-2.1 remotes/origin/release-2.2 remotes/origin/release-2.3 remotes/origin/release-2.4 remotes/origin/ryjones-patch-1 remotes/origin/test remotes/origin/v0.6 remotes/origin/v1.0.0-preview root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric# git checkout release-2.2 分支 'release-2.2' 设置为跟踪来自 'origin' 的远程分支 'release-2.2'。 切换到一个新分支 'release-2.2' root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric# git branch -a main * release-2.2 remotes/origin/HEAD -> origin/main remotes/origin/feature/ca remotes/origin/feature/convergence remotes/origin/main remotes/origin/mergify/bp/release-1.4/pr-2863 remotes/origin/mergify/bp/release-2.2/pr-2863 remotes/origin/mergify/bp/release-2.3/pr-2863 remotes/origin/release-1.0 remotes/origin/release-1.1 remotes/origin/release-1.2 remotes/origin/release-1.3 remotes/origin/release-1.4 remotes/origin/release-2.0 remotes/origin/release-2.1 remotes/origin/release-2.2 remotes/origin/release-2.3 remotes/origin/release-2.4 remotes/origin/ryjones-patch-1 remotes/origin/test remotes/origin/v0.6 remotes/origin/v1.0.0-preview root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric# git clone https://hub.0z.gs/hyperledger/fabric-samples.git 正克隆到 'fabric-samples'... remote: Enumerating objects: 10412, done. remote: Counting objects: 100% (154/154), done. remote: Compressing objects: 100% (124/124), done. remote: Total 10412 (delta 32), reused 111 (delta 22), pack-reused 10258 接收对象中: 100% (10412/10412), 19.02 MiB | 3.54 MiB/s, 完成. 处理 delta 中: 100% (5556/5556), 完成. root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric# cd fabric-samples/ root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric/fabric-samples# git branch -a * main remotes/origin/CLI_container remotes/origin/HEAD -> origin/main remotes/origin/dependabot/npm_and_yarn/asset-transfer-basic/rest-api-typescript/nconf-0.11.4 remotes/origin/main remotes/origin/master remotes/origin/mergify/bp/release-2.2/pr-402 remotes/origin/release remotes/origin/release-1.0 remotes/origin/release-1.1 remotes/origin/release-1.2 remotes/origin/release-1.3 remotes/origin/release-1.4 remotes/origin/release-2.2 remotes/origin/update_version_deps root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric/fabric-samples# git checkout release-2.2 分支 'release-2.2' 设置为跟踪来自 'origin' 的远程分支 'release-2.2'。 切换到一个新分支 'release-2.2' root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric/fabric-samples# cd /workspace/github.com/ root@The-Land-Like-as-A-Picture:/workspace/github.com# sudo chmod 777 -R *2. 初始环境及文件获取(20220601——链接可用) 2.1 对应2.2.5版本 >> fabric-2.2.5版本:
fabric-2.2.5 二进制文件:
wget https://gh.ddlc.top/https://github.com/hyperledger/fabric/releases/download/v2.2.5/hyperledger-fabric-linux-amd64-2.2.5.tar.gz
fabric-ca 1.5.2 二进制文件
>> docker-2.2.5版本:wget https://gh.ddlc.top/https://github.com/hyperledger/fabric-ca/releases/download/v1.5.2/hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz
docker镜像文件:2.2.5
docker pull hyperledger/fabric-peer:2.2.5 docker pull hyperledger/fabric-orderer:2.2.5 docker pull hyperledger/fabric-ccenv:2.2.5 docker pull hyperledger/fabric-javaenv:2.2 docker pull hyperledger/fabric-tools:2.2.5 docker pull hyperledger/fabric-ca:1.5.2 docker pull hyperledger/fabric-nodeenv:2.2 docker pull hyperledger/fabric-baseos:2.2.5核心:替换2.2.5 版本的peer、orderer和tools的TAG为latest:
docker tag 754df4def0cf hyperledger/fabric-tools:latest
docker tag c25c16d51e1e hyperledger/fabric-orderer:latest
docker tag 94f45b88b26a hyperledger/fabric-peer:latest
结果:
root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric/fabric-samples/test-network# docker images REPOSITORY TAG IMAGE ID CREATED SIZE busybox latest 3fb5cabb6469 5 days ago 1.24MB hyperledger/fabric-tools 2.2.5 754df4def0cf 4 months ago 442MB hyperledger/fabric-tools latest 754df4def0cf 4 months ago 442MB hyperledger/fabric-peer 2.2.5 94f45b88b26a 4 months ago 51MB hyperledger/fabric-peer latest 94f45b88b26a 4 months ago 51MB hyperledger/fabric-orderer 2.2.5 c25c16d51e1e 4 months ago 34.7MB hyperledger/fabric-orderer latest c25c16d51e1e 4 months ago 34.7MB hyperledger/fabric-ccenv 2.2.5 7cce5e687fe7 4 months ago 516MB hyperledger/fabric-baseos 2.2.5 ab5f045ec622 4 months ago 6.94MB hyperledger/fabric-ca 1.5.2 4ea287b75c63 8 months ago 69.8MB hyperledger/fabric-nodeenv 2.2 1c0903d73400 9 months ago 295MB hyperledger/fabric-javaenv 2.2 c47df6b15c80 10 months ago 415MB2.2 对应1.1.0版本 >> fabric-1.1.0版本:
fabric-1.1.0 二进制文件:
wget https://gh.ddlc.top/https://github.com/hyperledger/fabric/releases/download/v1.1.0/hyperledger-fabric-linux-amd64-1.1.0.tar.gz
fabric-ca 1.1.0 二进制文件:
wget https://gh.ddlc.top/https://github.com/hyperledger/fabric-ca/releases/download/v1.1.0/hyperledger-fabric-ca-linux-amd64-1.1.0.tar.gz
root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric/fabric-samples# wget https://gh.ddlc.top/https://github.com/hyperledger/fabric/releases/download/v1.1.0/hyperledger-fabric-linux-amd64-1.1.0.tar.gz --2022-05-31 19:16:12-- https://gh.ddlc.top/https://github.com/hyperledger/fabric/releases/download/v1.1.0/hyperledger-fabric-linux-amd64-1.1.0.tar.gz 正在解析主机 gh.ddlc.top (gh.ddlc.top)... 104.19.89.51 正在连接 gh.ddlc.top (gh.ddlc.top)|104.19.89.51|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度: 37143247 (35M) [application/octet-stream] 正在保存至: “hyperledger-fabric-linux-amd64-1.1.0.tar.gz” hyperledger-fabric-linux-amd64-1. 100%[=============================================================>] 35.42M 10.5MB/s 用时 4.6s 2022-05-31 19:16:18 (7.67 MB/s) - 已保存 “hyperledger-fabric-linux-amd64-1.1.0.tar.gz” [37143247/37143247]) root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric/fabric-samples# wget https://gh.ddlc.top/https://github.com/hyperledger/fabric-ca/releases/download/v1.1.0/hyperledger-fabric-ca-linux-amd64-1.1.0.tar.gz --2022-05-31 19:16:26-- https://gh.ddlc.top/https://github.com/hyperledger/fabric-ca/releases/download/v1.1.0/hyperledger-fabric-ca-linux-amd64-1.1.0.tar.gz 正在解析主机 gh.ddlc.top (gh.ddlc.top)... 104.19.89.51 正在连接 gh.ddlc.top (gh.ddlc.top)|104.19.89.51|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度: 6255648 (6.0M) [application/octet-stream] 正在保存至: “hyperledger-fabric-ca-linux-amd64-1.1.0.tar.gz” hyperledger-fabric-ca-linux-amd64 100%[=============================================================>] 5.97M 3.46MB/s 用时 1.7s 2022-05-31 19:16:29 (3.46 MB/s) - 已保存 “hyperledger-fabric-ca-linux-amd64-1.1.0.tar.gz” [6255648/6255648]) root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric/fabric-samples# tar -xzvf h high-throughput/ hyperledger-fabric-linux-amd64-1.1.0.tar.gz hyperledger-fabric-ca-linux-amd64-1.1.0.tar.gz root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric/fabric-samples# tar -xzvf hyperledger-fabric-linux-amd64-1.1.0.tar.gz bin/ bin/get-docker-images.sh bin/orderer bin/peer bin/configtxlator bin/cryptogen bin/configtxgen config/ config/orderer.yaml config/core.yaml config/configtx.yaml root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric/fabric-samples# tar -xzvf hyperledger-fabric-ca-linux-amd64-1.1.0.tar.gz bin/ bin/fabric-ca-client>> docker-1.1.0版本:
docker镜像文件:peer orderer ccenv javaenv tools 为 1.1.0,couchdb, kafka and zookeeper 为 0.4.6
只需确定fabric-peer、fabric-ca、fabric-orderer和fabric-tools 都是x86_64-1.1.0 就行
docker pull hyperledger/fabric-peer:x86_64-1.1.0
docker pull hyperledger/fabric-ca:x86_64-1.1.0
docker pull hyperledger/fabric-orderer:x86_64-1.1.0
docker pull hyperledger/fabric-tools:x86_64-1.1.0
docker pull hyperledger/fabric-ccenv:x86_64-1.1.0
docker pull hyperledger/fabric-javaenv:x86_64-1.1.0
docker pull hyperledger/fabric-kafka:x86_64-0.4.6
docker pull hyperledger/fabric-couchdb:x86_64-0.4.6
docker pull hyperledger/fabric-zookeeper:x86_64-0.4.6
docker pull hyperledger/fabric-baseos:x86_64-0.4.6
root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric/fabric-samples/first-network# docker images REPOSITORY TAG IMAGE ID CREATED SIZE busybox latest 3fb5cabb6469 5 days ago 1.24MB hyperledger/fabric-tools 2.2.5 754df4def0cf 4 months ago 442MB hyperledger/fabric-peer 2.2.5 94f45b88b26a 4 months ago 51MB hyperledger/fabric-orderer 2.2.5 c25c16d51e1e 4 months ago 34.7MB hyperledger/fabric-ccenv 2.2.5 7cce5e687fe7 4 months ago 516MB hyperledger/fabric-baseos 2.2.5 ab5f045ec622 4 months ago 6.94MB hyperledger/fabric-ca 1.5.2 4ea287b75c63 8 months ago 69.8MB hyperledger/fabric-nodeenv 2.2 1c0903d73400 9 months ago 295MB hyperledger/fabric-javaenv 2.2 c47df6b15c80 10 months ago 415MB hyperledger/fabric-ca x86_64-1.1.0 72617b4fa9b4 4 years ago 299MB hyperledger/fabric-tools x86_64-1.1.0 b7bfddf508bc 4 years ago 1.46GB hyperledger/fabric-orderer x86_64-1.1.0 ce0c810df36a 4 years ago 180MB hyperledger/fabric-peer x86_64-1.1.0 b023f9be0771 4 years ago 187MB hyperledger/fabric-javaenv x86_64-1.1.0 82098abb1a17 4 years ago 1.52GB hyperledger/fabric-ccenv x86_64-1.1.0 c8b4909d8d46 4 years ago 1.39GB hyperledger/fabric-zookeeper x86_64-0.4.6 92cbb952b6f8 4 years ago 1.39GB hyperledger/fabric-kafka x86_64-0.4.6 554c591b86a8 4 years ago 1.4GB hyperledger/fabric-couchdb x86_64-0.4.6 7e73c828fc5b 4 years ago 1.56GB hyperledger/fabric-baseos x86_64-0.4.6 220e5cf3fb7f 4 years ago 151MB核心:替换1.1.0 版本的peer、orderer和tools的TAG为latest:(fabric-javaenv、fabric-ccenv 、fabric-couchdb最好也替换)
docker tag b7bfddf508bc hyperledger/fabric-tools:latest
docker tag ce0c810df36a hyperledger/fabric-orderer:latest
docker tag b023f9be0771 hyperledger/fabric-peer:latest
root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric/fabric-samples/first-network# git branch main * release-1.1 root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric/fabric-samples/first-network# docker tag b7bfddf508bc hyperledger/fabric-tools:latest root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric/fabric-samples/first-network# docker tag ce0c810df36a hyperledger/fabric-orderer:latest root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric/fabric-samples/first-network# docker tag b023f9be0771 hyperledger/fabric-peer:latest root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric/fabric-samples/first-network# docker images REPOSITORY TAG IMAGE ID CREATED SIZE busybox latest 3fb5cabb6469 5 days ago 1.24MB hyperledger/fabric-tools 2.2.5 754df4def0cf 4 months ago 442MB hyperledger/fabric-peer 2.2.5 94f45b88b26a 4 months ago 51MB hyperledger/fabric-orderer 2.2.5 c25c16d51e1e 4 months ago 34.7MB hyperledger/fabric-ccenv 2.2.5 7cce5e687fe7 4 months ago 516MB hyperledger/fabric-baseos 2.2.5 ab5f045ec622 4 months ago 6.94MB hyperledger/fabric-ca 1.5.2 4ea287b75c63 8 months ago 69.8MB hyperledger/fabric-nodeenv 2.2 1c0903d73400 9 months ago 295MB hyperledger/fabric-javaenv 2.2 c47df6b15c80 10 months ago 415MB hyperledger/fabric-ca x86_64-1.1.0 72617b4fa9b4 4 years ago 299MB hyperledger/fabric-tools latest b7bfddf508bc 4 years ago 1.46GB hyperledger/fabric-tools x86_64-1.1.0 b7bfddf508bc 4 years ago 1.46GB hyperledger/fabric-orderer latest ce0c810df36a 4 years ago 180MB hyperledger/fabric-orderer x86_64-1.1.0 ce0c810df36a 4 years ago 180MB hyperledger/fabric-peer latest b023f9be0771 4 years ago 187MB hyperledger/fabric-peer x86_64-1.1.0 b023f9be0771 4 years ago 187MB hyperledger/fabric-javaenv x86_64-1.1.0 82098abb1a17 4 years ago 1.52GB hyperledger/fabric-ccenv x86_64-1.1.0 c8b4909d8d46 4 years ago 1.39GB hyperledger/fabric-zookeeper x86_64-0.4.6 92cbb952b6f8 4 years ago 1.39GB hyperledger/fabric-kafka x86_64-0.4.6 554c591b86a8 4 years ago 1.4GB hyperledger/fabric-couchdb x86_64-0.4.6 7e73c828fc5b 4 years ago 1.56GB hyperledger/fabric-baseos x86_64-0.4.6 220e5cf3fb7f 4 years ago 151MB root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric/fabric-samples# docker tag 82098abb1a17 hyperledger/fabric-javaenv:latest root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric/fabric-samples# docker tag c8b4909d8d46 hyperledger/fabric-ccenv:latest root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric/fabric-samples/first-network# docker tag 7e73c828fc5b hyperledger/fabric-couchdb:latest3. 启动网络
参考教程:Docs » Getting Started » Using the Fabric test network
3.1 启动2.2.5版本网络./network.sh up -i 2.2.5
root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric/fabric-samples/test-network# ./network.sh up -i 2.2.5 Starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb' with crypto from 'cryptogen' LOCAL_VERSION=2.2.5 DOCKER_IMAGE_VERSION=2.2.5 /workspace/github.com/fabric/fabric-samples/test-network/../bin/cryptogen Generating certificates using cryptogen tool Creating Org1 Identities + cryptogen generate --config=./organizations/cryptogen/crypto-config-org1.yaml --output=organizations org1.example.com + res=0 Creating Org2 Identities + cryptogen generate --config=./organizations/cryptogen/crypto-config-org2.yaml --output=organizations org2.example.com + res=0 Creating Orderer Org Identities + cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer.yaml --output=organizations + res=0 Generating CCP files for Org1 and Org2 /workspace/github.com/fabric/fabric-samples/test-network/../bin/configtxgen Generating Orderer Genesis block + configtxgen -profile TwoOrgsOrdererGenesis -channelID system-channel -outputBlock ./system-genesis-block/genesis.block 2022-05-31 17:30:05.804 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration 2022-05-31 17:30:05.818 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: etcdraft 2022-05-31 17:30:05.818 CST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 Orderer.EtcdRaft.Options unset, setting to tick_interval:"500ms" election_tick:10 heartbeat_tick:1 max_inflight_blocks:5 snapshot_interval_size:16777216 2022-05-31 17:30:05.818 CST [common.tools.configtxgen.localconfig] Load -> INFO 004 Loaded configuration: /workspace/github.com/fabric/fabric-samples/test-network/configtx/configtx.yaml 2022-05-31 17:30:05.819 CST [common.tools.configtxgen] doOutputBlock -> INFO 005 Generating genesis block 2022-05-31 17:30:05.820 CST [common.tools.configtxgen] doOutputBlock -> INFO 006 Writing genesis block + res=0 Creating network "fabric_test" with the default driver Creating volume "docker_orderer.example.com" with default driver Creating volume "docker_peer0.org1.example.com" with default driver Creating volume "docker_peer0.org2.example.com" with default driver Creating orderer.example.com ... done Creating peer0.org2.example.com ... done Creating peer0.org1.example.com ... done Creating cli ... done CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 14259fba602f hyperledger/fabric-tools:latest "/bin/bash" 1 second ago Up Less than a second cli 630ecc2b994d hyperledger/fabric-peer:latest "peer node start" 1 second ago Up Less than a second 0.0.0.0:7051->7051/tcp, :::7051->7051/tcp, 0.0.0.0:9444->9444/tcp, :::9444->9444/tcp peer0.org1.example.com 69ba8c0eda5c hyperledger/fabric-orderer:latest "orderer" 1 second ago Up Less than a second 0.0.0.0:7050->7050/tcp, :::7050->7050/tcp, 0.0.0.0:9443->9443/tcp, :::9443->9443/tcp orderer.example.com 5451217c07a3 hyperledger/fabric-peer:latest "peer node start" 1 second ago Up Less than a second 0.0.0.0:9051->9051/tcp, :::9051->9051/tcp, 7051/tcp, 0.0.0.0:9445->9445/tcp, :::9445->9445/tcp peer0.org2.example.com3.2 创建通道testchannel
./network.sh createChannel -c testchannel -ca
root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric/fabric-samples/test-network# ./network.sh createChannel -c testchannel -ca
Creating channel 'testchannel'.
If network is not up, starting nodes with CLI timeout of '5' tries and CLI delay of '3' seconds and using database 'leveldb
Generating channel create transaction 'testchannel.tx'
+ configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/testchannel.tx -channelID testchannel
2022-05-31 17:30:40.964 CST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2022-05-31 17:30:40.978 CST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /workspace/github.com/fabric/fabric-samples/test-network/configtx/configtx.yaml
2022-05-31 17:30:40.978 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 003 Generating new channel configtx
2022-05-31 17:30:40.979 CST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 004 Writing new channel tx
+ res=0
Creating channel testchannel
Using organization 1
+ peer channel create -o localhost:7050 -c testchannel --ordererTLSHostnameOverride orderer.example.com -f ./channel-artifacts/testchannel.tx --outputBlock ./channel-artifacts/testchannel.block --tls --cafile /workspace/github.com/fabric/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
+ res=0
2022-05-31 17:30:44.008 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-05-31 17:30:44.019 CST [cli.common] readBlock -> INFO 002 Expect block, but got status: &{NOT_FOUND}
2022-05-31 17:30:44.020 CST [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2022-05-31 17:30:44.223 CST [cli.common] readBlock -> INFO 004 Expect block, but got status: &{SERVICE_UNAVAILABLE}
2022-05-31 17:30:44.229 CST [channelCmd] InitCmdFactory -> INFO 005 Endorser and orderer connections initialized
2022-05-31 17:30:44.431 CST [cli.common] readBlock -> INFO 006 Expect block, but got status: &{SERVICE_UNAVAILABLE}
2022-05-31 17:30:44.435 CST [channelCmd] InitCmdFactory -> INFO 007 Endorser and orderer connections initialized
2022-05-31 17:30:44.638 CST [cli.common] readBlock -> INFO 008 Expect block, but got status: &{SERVICE_UNAVAILABLE}
2022-05-31 17:30:44.642 CST [channelCmd] InitCmdFactory -> INFO 009 Endorser and orderer connections initialized
2022-05-31 17:30:44.845 CST [cli.common] readBlock -> INFO 00a Expect block, but got status: &{SERVICE_UNAVAILABLE}
2022-05-31 17:30:44.849 CST [channelCmd] InitCmdFactory -> INFO 00b Endorser and orderer connections initialized
2022-05-31 17:30:45.058 CST [cli.common] readBlock -> INFO 00c Received block: 0
Channel 'testchannel' created
Joining org1 peer to the channel...
Using organization 1
+ peer channel join -b ./channel-artifacts/testchannel.block
+ res=0
2022-05-31 17:30:48.095 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-05-31 17:30:48.123 CST [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
Joining org2 peer to the channel...
Using organization 2
+ peer channel join -b ./channel-artifacts/testchannel.block
+ res=0
2022-05-31 17:30:51.157 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-05-31 17:30:51.193 CST [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
Setting anchor peer for org1...
Using organization 1
Fetching channel config for channel testchannel
Using organization 1
Fetching the most recent configuration block for the channel
+ peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c testchannel --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
2022-05-31 09:30:51.314 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-05-31 09:30:51.316 UTC [cli.common] readBlock -> INFO 002 Received block: 0
2022-05-31 09:30:51.316 UTC [channelCmd] fetch -> INFO 003 Retrieving last config block: 0
2022-05-31 09:30:51.317 UTC [cli.common] readBlock -> INFO 004 Received block: 0
Decoding config block to JSON and isolating config to Org1MSPconfig.json
+ configtxlator proto_decode --input config_block.pb --type common.Block
+ jq '.data.data[0].payload.data.config'
+ jq '.channel_group.groups.Application.groups.Org1MSP.values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "peer0.org1.example.com","port": 7051}]},"version": "0"}}' Org1MSPconfig.json
Generating anchor peer update transaction for Org1 on channel testchannel
+ configtxlator proto_encode --input Org1MSPconfig.json --type common.Config
+ configtxlator proto_encode --input Org1MSPmodified_config.json --type common.Config
+ configtxlator compute_update --channel_id testchannel --original original_config.pb --updated modified_config.pb
+ configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate
+ jq .
++ cat config_update.json
+ echo '{"payload":{"header":{"channel_header":{"channel_id":"testchannel", "type":2}},"data":{"config_update":{' '"channel_id":' '"testchannel",' '"isolated_data":' '{},' '"read_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org1MSP":' '{' '"groups":' '{},' '"mod_policy":' '"",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '},' '"write_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org1MSP":' '{' '"groups":' '{},' '"mod_policy":' '"Admins",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"AnchorPeers":' '{' '"mod_policy":' '"Admins",' '"value":' '{' '"anchor_peers":' '[' '{' '"host":' '"peer0.org1.example.com",' '"port":' 7051 '}' ']' '},' '"version":' '"0"' '},' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '}}}}'
+ configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope
2022-05-31 09:30:51.457 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-05-31 09:30:51.464 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
Anchor peer set for org 'Org1MSP' on channel 'testchannel'
Setting anchor peer for org2...
Using organization 2
Fetching channel config for channel testchannel
Using organization 2
Fetching the most recent configuration block for the channel
+ peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c testchannel --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
2022-05-31 09:30:51.568 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-05-31 09:30:51.569 UTC [cli.common] readBlock -> INFO 002 Received block: 1
2022-05-31 09:30:51.569 UTC [channelCmd] fetch -> INFO 003 Retrieving last config block: 1
2022-05-31 09:30:51.570 UTC [cli.common] readBlock -> INFO 004 Received block: 1
Decoding config block to JSON and isolating config to Org2MSPconfig.json
+ configtxlator proto_decode --input config_block.pb --type common.Block
+ jq '.data.data[0].payload.data.config'
+ jq '.channel_group.groups.Application.groups.Org2MSP.values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "peer0.org2.example.com","port": 9051}]},"version": "0"}}' Org2MSPconfig.json
Generating anchor peer update transaction for Org2 on channel testchannel
+ configtxlator proto_encode --input Org2MSPconfig.json --type common.Config
+ configtxlator proto_encode --input Org2MSPmodified_config.json --type common.Config
+ configtxlator compute_update --channel_id testchannel --original original_config.pb --updated modified_config.pb
+ configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate
+ jq .
++ cat config_update.json
+ echo '{"payload":{"header":{"channel_header":{"channel_id":"testchannel", "type":2}},"data":{"config_update":{' '"channel_id":' '"testchannel",' '"isolated_data":' '{},' '"read_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org2MSP":' '{' '"groups":' '{},' '"mod_policy":' '"",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"0"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '},' '"write_set":' '{' '"groups":' '{' '"Application":' '{' '"groups":' '{' '"Org2MSP":' '{' '"groups":' '{},' '"mod_policy":' '"Admins",' '"policies":' '{' '"Admins":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Endorsement":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Readers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '},' '"Writers":' '{' '"mod_policy":' '"",' '"policy":' null, '"version":' '"0"' '}' '},' '"values":' '{' '"AnchorPeers":' '{' '"mod_policy":' '"Admins",' '"value":' '{' '"anchor_peers":' '[' '{' '"host":' '"peer0.org2.example.com",' '"port":' 9051 '}' ']' '},' '"version":' '"0"' '},' '"MSP":' '{' '"mod_policy":' '"",' '"value":' null, '"version":' '"0"' '}' '},' '"version":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"1"' '}' '},' '"mod_policy":' '"",' '"policies":' '{},' '"values":' '{},' '"version":' '"0"' '}' '}}}}'
+ configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope
2022-05-31 09:30:51.703 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2022-05-31 09:30:51.711 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
Anchor peer set for org 'Org2MSP' on channel 'testchannel'
Channel 'testchannel' joined
3.3 调用./asset-transfer-basic/chaincode-javascript/内的合约basic
./network.sh deployCC -c testchannel -ccn basic -ccp …/asset-transfer-basic/chaincode-javascript/ -ccl javascript
root@The-Land-Like-as-A-Picture:/workspace/github.com/fabric/fabric-samples/test-network# ./network.sh deployCC -c testchannel -ccn basic -ccp ../asset-transfer-basic/chaincode-javascript/ -ccl javascript deploying chaincode on channel 'testchannel' executing with the following - CHANNEL_NAME: testchannel - CC_NAME: basic - CC_SRC_PATH: ../asset-transfer-basic/chaincode-javascript/ - CC_SRC_LANGUAGE: javascript - CC_VERSION: 1.0 - CC_SEQUENCE: 1 - CC_END_POLICY: NA - CC_COLL_CONFIG: NA - CC_INIT_FCN: NA - DELAY: 3 - MAX_RETRY: 5 - VERBOSE: false + peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-javascript/ --lang node --label basic_1.0 + res=0 Chaincode is packaged Installing chaincode on peer0.org1... Using organization 1 + peer lifecycle chaincode install basic.tar.gz + res=0 2022-05-31 17:32:32.408 CST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:


