Fabric环境搭建
一、docker环境支持(Docker、DockerCompose)
安装docker
# 安装必要的一些系统工具 sudo apt-get update sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common # 安装GPG证书 curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - # 写入软件源信息 sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" #更新并安装Docker-CE sudo apt-get -y update sudo apt-get -y install docker-ce # 验证是否安装成功 docker version
安装dockerCompose
apt install docker-compose
root@iZ0jl0b1xiqehj9f6mkrzoZ:~# docker-compose version docker-compose version 1.8.0, build unknown docker-py version: 1.9.0 CPython version: 2.7.12 OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016 root@iZ0jl0b1xiqehj9f6mkrzoZ:~#
二、Fabric组件Docker镜像
https://hub.docker.com/u/hyperledger
删除已有镜像
docker rmi ID
删除所有镜像
当要删除的iamges和其他的镜像有关联而无法删除时
https://www.jianshu.com/p/2bb5eca8d04c
docker rmi -f $(docker images -q)
删了还在的
root@iZ2ze1a67q38iyrtb3ws1dZ:/home/go/src/fabric-samples/chaincode-docker-devmode# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4f48d63f527d 18ed4db0cd57 "/bin/bash" 33 hours ago Exited (0) 33 hours ago recursing_ka lam735346054f3e bb3a35f5729d "chaincode -peer.add…" 36 hours ago Exited (0) 35 hours ago dev-peer0.o rg1.example.com-adminInfo-1.0root@iZ2ze1a67q38iyrtb3ws1dZ:/home/go/src/fabric-samples/chaincode-docker-devmode# docker rm 18ed4db0cd57
下载镜像
docker pull hyperledger/fabric-peer:1.4.3
docker pull hyperledger/fabric-orderer:1.4.3
docker pull hyperledger/fabric-tools:1.4.3
docker pull hyperledger/fabric-baseos:0.4.15
root@iZ0jl0b1xiqehj9f6mkrzoZ:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hyperledger/fabric-tools 1.4.3 18ed4db0cd57 21 months ago 1.55GB hyperledger/fabric-orderer 1.4.3 b666a6ebbe09 21 months ago 173MB hyperledger/fabric-peer 1.4.3 fa87ccaed0ef 21 months ago 179MB hyperledger/fabric-baseos 0.4.15 9d6ec11c60ff 2 years ago 145MB root@iZ0jl0b1xiqehj9f6mkrzoZ:~#
最新的先不用
docker pull hyperledger/fabric-peer
docker pull hyperledger/fabric-orderer
docker pull hyperledger/fabric-tools
docker pull hyperledger/fabric-baseos
三、go语言环境
wget https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz tar -xvf go1.13.4.linux-amd64.tar.gz mv go /usr/local cd ~ vim .profile #复制以下内容,按i,粘贴到.profile文件末尾 export GOROOT=/usr/local/go export GOPATH=/home/go export PATH=$PATH:/usr/local/go/bin source .profile
cd /home mkdir go cd go mkdir -p src/github.com/hyperledger/
四、Fabric源码库
#在go的src目录下执行
git clone https://github.com/hyperledger/fabric.git
root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger# pwd /home/go/src/github.com/hyperledger root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger# git clone https://github.com/hyperledger/fabric-samp les.git git clone https://github.com/hyperledger/fabric.git root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger# ll total 16 drwxr-xr-x 4 root root 4096 May 22 19:16 ./ drwxr-xr-x 3 root root 4096 May 22 19:15 ../ drwxr-xr-x 27 root root 4096 May 22 19:16 fabric/ drwxr-xr-x 25 root root 4096 May 22 19:16 fabric-samples/
源码库版本切换:git checkout v1.4.3
root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger# cd fabric root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric# git checkout v1.4.3 Note: checking out 'v1.4.3'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b <new-branch-name> HEAD is now at b8c4a6a... [FAB-16412] Release fabric v1.4.3
工具编译:cryptogen、configtxgen
root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric/common/tools/configtxgen# pwd /home/go/src/github.com/hyperledger/fabric/common/tools/configtxgen root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric/common/tools/configtxgen# ll total 48 drwxr-xr-x 6 root root 4096 May 22 19:17 ./ drwxr-xr-x 7 root root 4096 May 22 19:17 ../ drwxr-xr-x 2 root root 4096 May 22 19:17 configtxgentest/ drwxr-xr-x 3 root root 4096 May 22 19:17 encoder/ drwxr-xr-x 2 root root 4096 May 22 19:17 localconfig/ -rw-r--r-- 1 root root 13160 May 22 19:17 main.go -rw-r--r-- 1 root root 6829 May 22 19:17 main_test.go drwxr-xr-x 2 root root 4096 May 22 19:17 metadata/ root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric/common/tools/configtxgen# go install root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric/common/tools/configtxgen# cd ../.. root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric/common# ls attrmgr chaincode configtx diag genesis grpcmetrics metadata policies util capabilities channelconfig crypto errors graph ledger metrics semaphore viperutil cauthdsl config deliver flogging grpclogging localmsp mocks tools root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric/common# cd tools/cryptogen/ root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric/common/tools/cryptogen# pwd /home/go/src/github.com/hyperledger/fabric/common/tools/cryptogen root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric/common/tools/cryptogen# ll total 48 drwxr-xr-x 6 root root 4096 May 22 19:17 ./ drwxr-xr-x 7 root root 4096 May 22 19:17 ../ drwxr-xr-x 2 root root 4096 May 22 19:17 ca/ drwxr-xr-x 2 root root 4096 May 22 19:17 csp/ -rw-r--r-- 1 root root 22111 May 22 19:17 main.go drwxr-xr-x 2 root root 4096 May 22 19:17 metadata/ drwxr-xr-x 2 root root 4096 May 22 19:17 msp/ root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric/common/tools/cryptogen# go install root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric/common/tools/cryptogen#
root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric/common/tools/cryptogen# cd $GOPATH root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go# ls bin src root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go# ll total 16 drwxr-xr-x 4 root root 4096 May 22 19:22 ./ drwxr-xr-x 3 root root 4096 May 22 19:13 ../ drwxr-xr-x 2 root root 4096 May 22 19:23 bin/ drwxr-xr-x 3 root root 4096 May 22 19:15 src/ root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go# cd bin/ root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/bin# ls configtxgen cryptogen root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/bin#
后面在启动first-network时会用configtxlator,这里也进行安装
root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric/common/tools/configtxlator# pwd /home/go/src/github.com/hyperledger/fabric/common/tools/configtxlator root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric/common/tools/configtxlator# ll total 36 drwxr-xr-x 7 root root 4096 May 22 19:17 ./ drwxr-xr-x 7 root root 4096 May 22 19:17 ../ drwxr-xr-x 2 root root 4096 May 22 19:17 integration/ -rw-r--r-- 1 root root 7594 May 22 19:17 main.go drwxr-xr-x 2 root root 4096 May 22 19:17 metadata/ drwxr-xr-x 2 root root 4096 May 22 19:17 rest/ drwxr-xr-x 2 root root 4096 May 22 19:17 sanitycheck/ drwxr-xr-x 2 root root 4096 May 22 19:17 update/ root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric/common/tools/configtxlator# go install
五、Fabric-samples
git clone https://github.com/hyperledger/fabric-samples.git
切换分支
root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric-samples# pwd /home/go/src/github.com/hyperledger/fabric-samples root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric-samples# git checkout v1.4.3 Note: checking out 'v1.4.3'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b <new-branch-name> HEAD is now at f86ec95... [FAB-16390] Added filter for invalid transactions root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric-samples
测试fabric-samples/first-network
把fabric-samples的bin加入路径PATH
vim /etc/profile #在profile最后加上
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin:/home/go/bin #保存退出后执行 source /etc/profile
切记一定要在执行命令的会话中 source一下,不然不会读到新的环境变量
root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric-samples/first-network# pwd /home/go/src/github.com/hyperledger/fabric-samples/first-network root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric-samples/first-network# ./byfn.sh generate -c eric
先配置一下vim /etc/resolv.conf
注释最后一行,目的是不让超时
root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go# cat /etc/resolv.conf # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN nameserver 100.100.2.136 nameserver 100.100.2.138 #options timeout:2 attempts:3 rotate single-request-reopen
启动
root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric-samples/first-network# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric-samples/first-network# ./byfn.sh -m up -c eric
清除网络
root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric-samples/first-network# pwd /home/go/src/github.com/hyperledger/fabric-samples/first-network root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric-samples/first-network# ./byfn.sh -m down -c eric
主要是停止容器,删除容器,
root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric-samples/first-network# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric-samples/first-network# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hyperledger/fabric-tools 1.4.3 18ed4db0cd57 21 months ago 1.55GB hyperledger/fabric-tools latest 18ed4db0cd57 21 months ago 1.55GB hyperledger/fabric-ca 1.4.3 c18a0d3cc958 21 months ago 253MB hyperledger/fabric-ca latest c18a0d3cc958 21 months ago 253MB hyperledger/fabric-ccenv 1.4.3 3d31661a812a 21 months ago 1.45GB hyperledger/fabric-ccenv latest 3d31661a812a 21 months ago 1.45GB hyperledger/fabric-orderer 1.4.3 b666a6ebbe09 21 months ago 173MB hyperledger/fabric-orderer latest b666a6ebbe09 21 months ago 173MB hyperledger/fabric-peer 1.4.3 fa87ccaed0ef 21 months ago 179MB hyperledger/fabric-peer latest fa87ccaed0ef 21 months ago 179MB hyperledger/fabric-javaenv 1.4.3 5ba5ba09db8f 22 months ago 1.76GB hyperledger/fabric-javaenv latest 5ba5ba09db8f 22 months ago 1.76GB hyperledger/fabric-zookeeper 0.4.15 20c6045930c8 2 years ago 1.43GB hyperledger/fabric-zookeeper latest 20c6045930c8 2 years ago 1.43GB hyperledger/fabric-kafka 0.4.15 b4ab82bbaf2f 2 years ago 1.44GB hyperledger/fabric-kafka latest b4ab82bbaf2f 2 years ago 1.44GB hyperledger/fabric-couchdb 0.4.15 8de128a55539 2 years ago 1.5GB hyperledger/fabric-couchdb latest 8de128a55539 2 years ago 1.5GB hyperledger/fabric-baseos 0.4.15 9d6ec11c60ff 2 years ago 145MB hyperledger/fabric-baseos amd64-0.4.15 9d6ec11c60ff 2 years ago 145MB root@iZ0jl0b1xiqehj9f6mkrzoZ:/home/go/src/github.com/hyperledger/fabric-samples/first-network#
六、测试
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
peer chaincode invoke -C mychannel -n mycc -c '{"Args":["invoke","a","b","10"]}'