摘要:前言安装笔记中的是一站式的运行例子具体做了什么我们这里一步一步分开来看参考资料网络拓扑生成组织关系和身份证书设置环境变量检查环境变量的生成确保自己在目录下生成密钥文件查看生成的密钥目录生成服务启动区块设
前言
Fabric v1.0.5安装笔记 中的network_setup.sh up是一站式的运行,e 2e cli例子.具体做了什么,我们这里一步一步分开来看
参考资料:
end-to-end
script.sh
网络拓扑 生成组织关系和身份证书1.设置环境变量
for power or z os_arch=$(echo "$(uname -s)-$(uname -m)" | awk "{print tolower($0)}") $for linux, osx or windows os_arch=$(echo "$(uname -s)-amd64" | awk "{print tolower($0)}")
2.检查环境变量的生成
echo $os_arch
3.确保自己在e2e_cli目录下
/opt/gopath/src/github.com/hyperledger/fabric/examples/e2e_cli
4.生成密钥文件
./../../release/$os_arch/bin/cryptogen generate --config=./crypto-config.yaml
5.查看生成的密钥目录
tree -L 4 crypto-config
crypto-config ├── ordererOrganizations │ └── example.com │ ├── ca │ │ ├── 06ae0192afb55ee494bbec1095b9a73148ab011d19450df5eee540696ffbcd00_sk │ │ └── ca.example.com-cert.pem │ ├── msp │ │ ├── admincerts │ │ ├── cacerts │ │ └── tlscacerts │ ├── orderers │ │ └── orderer.example.com │ ├── tlsca │ │ ├── 1056171c60cfd8e918b86404bf3976726ce69640dc7d9b81cbfad1d9a6b7b282_sk │ │ └── tlsca.example.com-cert.pem │ └── users │ └── Admin@example.com └── peerOrganizations ├── org1.example.com │ ├── ca │ │ ├── ca.org1.example.com-cert.pem │ │ └── e55f885168a48ea087362c472bb285c28531c8df58b8ac92f1d76c9e8c8aba9e_sk │ ├── msp │ │ ├── admincerts │ │ ├── cacerts │ │ └── tlscacerts │ ├── peers │ │ ├── peer0.org1.example.com │ │ └── peer1.org1.example.com │ ├── tlsca │ │ ├── d6eb52db2db3854a1feccfe66494b2b0e89aac1bdd9b68d35ce286873ff85cb0_sk │ │ └── tlsca.org1.example.com-cert.pem │ └── users │ ├── Admin@org1.example.com │ └── User1@org1.example.com └── org2.example.com ├── ca │ ├── 5cfdefb1d98601b287ea75805ba679de94108e61d1e595df88bfd2c5ff332542_sk │ └── ca.org2.example.com-cert.pem ├── msp │ ├── admincerts │ ├── cacerts │ └── tlscacerts ├── peers │ ├── peer0.org2.example.com │ └── peer1.org2.example.com ├── tlsca │ ├── e423b8beda388a330c78d4bea3248b464133daaa1fb32abdc71c975fc6c3a7a7_sk │ └── tlsca.org2.example.com-cert.pem └── users ├── Admin@org2.example.com └── User1@org2.example.com生成Ordering服务启动genesis区块
1.设置环境变量,告诉configtxgen那去找配置文件configtx.yaml
FABRIC_CFG_PATH=$PWD
2.创建orderer的创世区块
./../../release/$os_arch/bin/configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
3.设置通道名称mumubin
CHANNEL_NAME=mumubin
4.新建应用通道
./../../release/$os_arch/bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID ${CHANNEL_NAME}生成锚节点配置更新文件
1.生成Org1锚节点配置更新文件
./../../release/$os_arch/bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID ${CHANNEL_NAME} -asOrg Org1MSP
2.生成Org2锚节点配置更新文件
./../../release/$os_arch/bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID ${CHANNEL_NAME} -asOrg Org2MSP
至此,网络拓扑就生成完毕了.
ll channel-artifacts/
-rw-r--r-- 1 root root 390 1月 18 09:02 channel.tx -rw-r--r-- 1 root root 9085 1月 18 08:59 genesis.block -rw-r--r-- 1 root root 280 1月 18 09:04 Org1MSPanchors.tx -rw-r--r-- 1 root root 280 1月 18 09:05 Org2MSPanchors.tx启动网络 准备工作
1.清理启动的线程
docker rm -f $(docker ps -aq)
2.查验(结果应该为空)
docker ps
3.查看images
docker images dev-peer0.org1.example.com-mycc-1.0-384f11f484b9302df90b453200cfb25174305fce8f53f4e94d45ee3b6cab0ce9 latest 647439adf7f6 14 hours ago 145 MB hyperledger/fabric-tools latest 3275ebd1bb71 2 days ago 1.328 GB hyperledger/fabric-tools x86_64-1.0.6-snapshot-78e18d1 3275ebd1bb71 2 days ago 1.328 GB hyperledger/fabric-orderer latest 6b311f088ccb 2 days ago 151.3 MB hyperledger/fabric-orderer x86_64-1.0.6-snapshot-78e18d1 6b311f088ccb 2 days ago 151.3 MB hyperledger/fabric-peer latest 725c3f9ca713 2 days ago 154.3 MB hyperledger/fabric-peer x86_64-1.0.6-snapshot-78e18d1 725c3f9ca713 2 days ago 154.3 MB hyperledger/fabric-ccenv latest b2b067a6c6d9 2 days ago 1.282 GB hyperledger/fabric-ccenv x86_64-1.0.6-snapshot-78e18d1 b2b067a6c6d9 2 days ago 1.282 GB hyperledger/fabric-kafka latest b8c5172bb83c 6 weeks ago 1.286 GB docker.io/hyperledger/fabric-kafka x86_64-1.0.5 b8c5172bb83c 6 weeks ago 1.286 GB docker.io/hyperledger/fabric-zookeeper x86_64-1.0.5 68945f4613fc 6 weeks ago 1.316 GB hyperledger/fabric-zookeeper latest 68945f4613fc 6 weeks ago 1.316 GB docker.io/hyperledger/fabric-baseimage x86_64-0.3.2 c92d9fdee998 4 months ago 1.257 GB hyperledger/fabric-baseimage latest c92d9fdee998 4 months ago 1.257 GB docker.io/hyperledger/fabric-baseos x86_64-0.3.2 bbcbb9da2d83 4 months ago 128.8 MB hyperledger/fabric-baseos latest bbcbb9da2d83 4 months ago 128.8 MB
4.删除直接生成的无用的images(带mycc字段)
docker rmi -f 647439adf7f6
5.修改掉docker-compose-cli.yaml,防止其自动跑所有流程
git diff docker-compose-cli.yaml diff --git a/examples/e2e_cli/docker-compose-cli.yaml b/examples/e2e_cli/docker-compose-cli.yaml index e6290cf..27b92f9 100644 --- a/examples/e2e_cli/docker-compose-cli.yaml +++ b/examples/e2e_cli/docker-compose-cli.yaml @@ -54,7 +54,7 @@ services: - 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 - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer - command: /bin/bash -c "./scripts/script.sh ${CHANNEL_NAME}; sleep $TIMEOUT" + #command: /bin/bash -c "./scripts/script.sh ${CHANNEL_NAME}; sleep $TIMEOUT" volumes: - /var/run/:/host/var/run/ - ../chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go一步步启动网络
1.设置环境变量peer0
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp CORE_PEER_ADDRESS=peer0.org1.example.com:7051 CORE_PEER_LOCALMSPID="Org1MSP" 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
2.启动容器
CHANNEL_NAME=mumubin TIMEOUT=1000 docker-compose -f docker-compose-cli.yaml up
P.S. 不要加-d参数,这样可以打日志
3.另起窗口,进入cli容器
docker exec -it cli bash
4.设置环境变量
CHANNEL_NAME=mumubin 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
5.创建channel(这里end-to-end文档有错,参见script脚本)
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA
6.加入Channel(目前是Org1的peer0加入的网络)
peer channel join -b mumubin.block
7.Org1的peer1加入的网络
CORE_PEER_LOCALMSPID="Org1MSP" 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 CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp CORE_PEER_ADDRESS=peer1.org1.example.com:7051
peer channel join -b mumubin.block
8.Org2的peer0加入的网络
CORE_PEER_LOCALMSPID="Org2MSP" CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp CORE_PEER_ADDRESS=peer0.org2.example.com:7051
peer channel join -b mumubin.block
9.Org2的peer1加入的网络
CORE_PEER_LOCALMSPID="Org2MSP" CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp CORE_PEER_ADDRESS=peer1.org2.example.com:7051
peer channel join -b mumubin.block交易运行
1.回归peer0
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp CORE_PEER_ADDRESS=peer0.org1.example.com:7051 CORE_PEER_LOCALMSPID="Org1MSP" 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
2.安装 install chaincode
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
3.实例化 instantiate chaincode
peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -v 1.0 -c "{"Args":["init","a","100","b","200"]}" -P "OR ("Org1MSP.member","Org2MSP.member")"
验证实例化是否成功
peer chaincode query -C $CHANNEL_NAME -n mycc -c "{"Args":["query","a"]}"
Query Result: 100
4.触发交易 Invoke chaincode
peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -c "{"Args":["invoke","a","b","10"]}"
5.查询交易
peer chaincode query -C $CHANNEL_NAME -n mycc -c "{"Args":["query","a"]}"
Query Result: 90
交易顺利执行成功
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/23949.html
摘要:前言默认的为功能有限现在把它该归它提供了丰富的查询功能拉取使用启动利用上节教程使所有添加至改用安装请把环境变量都改为的实例化创建一些并交易 前言 默认的state DB为goleveldb,功能有限,现在把它该归CouchDB.它提供了丰富的查询功能 拉取coundb image docker pull hyperledger/fabric-couchdb:x86_64-1.0.5 d...
摘要:和比特币协议有所不同的是,以太坊的设计十分灵活,极具适应性。超级账本区块链的商业应用超级账本超级账本是基金会下的众多项目中的一个。证书颁发机构负责签发撤 showImg(https://segmentfault.com/img/bV2ge9?w=900&h=385); 从比特币开始 一个故事告诉你比特币的原理及运作机制 这篇文章的定位会比较科普,尽量用类比的方法将比特币的基本原理讲出来...
摘要:前言本文严重参考官方文档并去除复杂部分和相应解释基本只覆盖操作流程下载下载镜像启动进入镜像查询并启动已启动注册实体注册修改下的配置文件注册新成员 前言 本文严重参考官方文档,并去除复杂部分和相应解释,基本只覆盖操作流程 下载fabric-ca go get -u github.com/hyperledger/fabric-ca/cmd/... 下载fabric-ca镜像 docker ...
摘要:所以这里一般就是执行启动我们应用的那条命令。编译运行编译好的镜像打开浏览器进行测试 编译docker镜像 1.加速docker镜像下载速度 取决于网络速度,如果不慢的话,可以先不装 https://www.daocloud.io/mirror#accelerator-doc 执行下面的命令配置加速器 curl -sSL https://get.daocloud.io/daotools...
阅读 1342·2021-09-24 10:26
阅读 3655·2021-09-06 15:02
阅读 603·2019-08-30 14:18
阅读 575·2019-08-30 12:44
阅读 3118·2019-08-30 10:48
阅读 1936·2019-08-29 13:09
阅读 1992·2019-08-29 11:30
阅读 2278·2019-08-26 13:36