https://hyperledger-fabric.readthedocs.io/en/release-1.0/build_network.html
git clone https://github.com/hyperledger/fabric-samples.git
cd fabric-samples
cryptogen,
configtxgen,
configtxlator, and
peer
-----------------------------------------------------------------
curl -sSL https://goo.gl/kFFqh5 | bash -s 1.0.6
若是获取不到可以在浏览器中执行https://goo.gl/kFFqh5 获取相应的sh文件
然后在服务器中fabric-samples目录下执行,然后在fabric-samples/bin可以找到对于的文件
-------------------------------------------
或者执行
/scripts/bootstrap.sh 即可(建议这个方法)
执行first-network中的命令
./byfn.sh -m generate
./byfn.sh -m up
./byfn.sh -m down
当执行./byfn.sh -m up 时
error getting endorser client for channel: endorser client failed to connect to peer0.org1.example.com:7051: failed to create new connection: context deadline exceeded
解决方法
更新了docker和docker-compose的版本
参考https://www.cnblogs.com/tianhei/p/7802064.html
下方两个有可能用的上
docker ps -qa | xargs docker stop
docker ps -qa | xargs docker rm
注意:docker的版本问题和权限问题
使用cryptogen工具生成加密材料,负责生成网络中组织结构和身份文件
一般使用crypto-config.yaml文件进行配置,它网络的拓扑和需要生成的组织和该组织部件的证书
其生成的证书和密钥保存在crypto-config文件夹中
cryptogen 命令参数
generate 生成密钥和证书文件
--output 存放生成密钥的和证书文件的路径,默认当前目录的crypto-config
--config 指定采用的配置模板文件的路径crypto-config.yaml
主要功能:
命令选项
../bin/cryptogen generate --config=./crypto-config.yaml
export FABRIC_CFG_PATH=$PWD
../bin/configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
export CHANNEL_NAME=mychannel
../bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP
../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP
CHANNEL_NAME=$CHANNEL_NAME TIMEOUT=60 docker-compose -f docker-compose-cli.yaml up -d
docker exec -it cli bash
进入下方的路径
root@0d78bb69300d:/opt/gopath/src/github.com/hyperledger/fabric/peer#
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
peer channel join -b mychannel.block
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
这里需要检查你的链码存放的路径是不是这里不是的话需要自行更换
peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -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"]}'
peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C $CHANNEL_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}'
9.查询
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'