sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
sudo yum install -y yum-utils
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
安装最新版本
sudo yum install docker-ce docker-ce-cli containerd.io # 最新版本
安装指定版本
yum list docker-ce --showduplicates | sort -r
# docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable
# docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
# docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
# docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
sudo yum install docker-ce-19.03.8 docker-ce-cli-19.03.8 containerd.io
sudo systemctl start docker
sudo systemctl enable docker
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
可以直接用提供的
docker-compose-Linux-x86_64
cp docker-compose-Linux-x86_64 /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose
安装 go1.13.8, 可以直接用go1.13.8.linux-amd64.tar.gz
tar xzvf go1.11.linux-amd64.tar.gz -C /usr/local
/etc/profile 中添加
export GOROOT=/usr/local/go
export GOARCH=amd64
export GOOS=linux
export GOPATH=/opt/gopath
export GOBIN=$GOPATH/bin
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
# 使环境变量生效
source /etc/profile
yum install git
mkdir -p $GOPATH/src/github.com/hyperledger
cd $GOPATH/src/github.com/hyperledger
# 克隆fabric-samples项目并切换到v1.4tag
git clone https://github.com/hyperledger/fabric-samples.git
cd fabric-samples
git checkout -b v2.0.1
导入bin、config、fabric-imgaes内容
配置bin
tar xzvf bin.tar.gz -C $GOPATH/src/github.com/hyperledger/fabric-samples/
tar xzvf config.tar.gz -C $GOPATH/src/github.com/hyperledger/fabric-samples/
#向/etc/profile中写入环境变量
sudo echo 'export PATH=$GOPATH/src/github.com/hyperledger/fabric-samples/bin:$PATH' >> /etc/profile
#使环境变量生效
source /etc/profile
加载镜像
docker load -i fabric-images
cd test-network
./network.sh up
./network.sh createChannel
./network.sh deployCC # 第一次过程中会安装go包,如果失败可能需要多试几次
# 最后输出 Fabcar链码的测试运行结果
网络结构
一个Orderer,两个org,每个org一个peer。
一个org一个ca。
到目前为止,成功在两台虚拟机上部署了两个Org。
在Org1上创建了channel,同时打包并安装了fabcar链码。
(想通过运行合约看网络时候启动成功,在approvformyorg的时候存在问题)
org1加入通道:
打包&安装链码:
peer lifecycle chaincode queryinstalled
看到这个说明,chaincode 已经安装成功。
还差approveformyorg 、checkcommitreadiness、commit 阶段。
approveformyorg:
export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
# ORG1的变量
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=peer0.org1.example.com:7051
peer lifecycle chaincode approveformyorg -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --channelID succhannel --name fabcar --version 1 --init-required --package-id fabcar_1:aca5cf806d53b8860e3bc4234af8fe9a017e7082d98108e07ffc7ea36dbc2e07 --sequence 1 --signature-policy "OR('Org1MSP.member','Org2MSP.member')" >&log.txt
checkcommitreadiness
peer lifecycle chaincode checkcommitreadiness --channelID succhannel --name fabcar --version 1.0 --sequence 1 --output json --init-required >&log.txt
#
在此处发现approve for org 失败,没有获得Org1MSP的true
commit
# 等check完之后再提交
org2加入通道:
export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem && export CHANNEL_NAME=succhannel
获取第0个区块
peer channel fetch 0 succhannel.block -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
加入到channel里边
peer channel join -b succhannel.block
如下图:
Org2 到目前为止,成功加入channel
approveformyorg 的命令一直执行不成功
checkcommit一直都是两个false