블록체인 학습의 Fabric 환경 구축 - 수동 구축

13451 단어 블록체인
블로그를 거울로 삼다.
남색집
절차는 전편에서 7단계부터 아래의 구체적인 절차로 바뀐 것에 근거한다.
1.1 cryptogen 생성
cd ~/go/src/github.com/hyperledger/fabric
make cryptogen
dell@dell-OptiPlex-3050:~/go/src/github.com/hyperledger/fabric$ make cryptogen
build/bin/cryptogen
CGO_CFLAGS=" " GOBIN=/home/dell/go/src/github.com/hyperledger/fabric/build/bin go install -tags "" -ldflags "-X github.com/hyperledger/fabric/common/tools/cryptogen/metadata.Version=1.0.0" github.com/hyperledger/fabric/common/tools/cryptogen
# github.com/hyperledger/fabric/vendor/github.com/miekg/pkcs11
vendor/github.com/miekg/pkcs11/pkcs11.go:29:18: fatal error: ltdl.h: No such file or directory
compilation terminated.
Makefile:227: recipe for target 'build/bin/cryptogen' failed
make: *** [build/bin/cryptogen] Error 2

상술한 문제가 발생하면 파일이 부족합니다
apt-get install libtool libltdl-dev

1.2 crypto-config 설정yaml
환경을 만들 때 여기가 기본값입니다.
1.3 공공 키와 인증서를 생성하는데 이런 명령은 일반적으로 문제가 발생하지 않는다.
cd examples/e2e_cli/
../../build/bin/cryptogen generate --config=./crypto-config.yaml

2.1 컴파일링 생성configtxgen (왜 그런지 모르겠어)
cd ~/go/src/github.com/hyperledger/fabric

make configtxgen

2.2 configtx 구성yaml
환경을 구축할 때 기본값만 있으면 되고 후속 생산 환경은 수정될 것으로 예상된다.
2.3 창세 블록을 생성하고 CHannel 블록을 설정하며 닻 노드 업데이트를 한다.
cd examples/e2e_cli/

../../build/bin/configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block

../../build/bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel

../../build/bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP

../../build/bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP

2.4 파일은 e2e 디렉터리에 있는 채널-artifacts에 4개의 파일이 존재합니다. 전편이라면 이 파일은fabric에서 만들어준 것입니다.(추측).
3.1 구성orderer
base/docker-compose-base.yaml 파일에서 환경을 만들 때 기본값입니다.
3.2 peer 구성
base/docker-compose-base.yaml과 peer-base.yaml 파일의 기본값입니다.
3.3 CLI 구성
docker-compose-cli.yaml 파일에서 자동으로 실행되는command 줄을 주석해야 합니다. (앞에 # 추가)
 command: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME}; sleep $TIMEOUT' 

4. Fabric 환경 시작(많은 문제점 발생)
4.1 Fabric Docker 환경 구성을 docker-compose-cli에 배치합니다.yaml 뒤에는 주로 백엔드가 실행됩니다.
docker-compose -f docker-compose-cli.yaml up -d

docker ps는 실행 상황을 볼 수 있습니다.정상적인 상황은orderer와peer가 모두 실행되고, 또 하나의tools도 실행됩니다. (만약 실행되지 않으면 후속으로 계속할 수 없습니다.)
436f6f0d70e4        hyperledger/fabric-tools              "/bin/bash"              28 minutes ago      Up 28 minutes                                                                                   cli
afb11e8d7cf6        hyperledger/fabric-orderer            "orderer"                29 minutes ago      Up 28 minutes       0.0.0.0:7050->7050/tcp                                                      orderer.example.com
e7f3ea4b3520        hyperledger/fabric-peer               "peer node start"        29 minutes ago      Up 29 minutes       0.0.0.0:10051->7051/tcp, 0.0.0.0:10052->7052/tcp, 0.0.0.0:10053->7053/tcp   peer1.org2.example.com
6e4c40b8feae        hyperledger/fabric-peer               "peer node start"        29 minutes ago      Up 28 minutes       0.0.0.0:9051->7051/tcp, 0.0.0.0:9052->7052/tcp, 0.0.0.0:9053->7053/tcp      peer0.org2.example.com
04db32690344        hyperledger/fabric-peer               "peer node start"        29 minutes ago      Up 28 minutes       0.0.0.0:7051-7053->7051-7053/tcp                                            peer0.org1.example.com
fa1ac260a3e3        hyperledger/fabric-peer               "peer node start"        29 minutes ago      Up 29 minutes       0.0.0.0:8051->7051/tcp, 0.0.0.0:8052->7052/tcp, 0.0.0.0:8053->7053/tcp      peer1.org1.example.com

4.2 cli 용기에 들어간다.
docker exec -it cli bash

4.3 Channel 생성
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

peer channel create -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --tls true --cafile $ORDERER_CA

이쪽은 문제가 가장 많이 발생하는 곳입니다. 제가 만났던 곳을 대충 열거해 보겠습니다.
4.3.1
2018-07-26 06:13:15.796 UTC [grpc] Printf -> DEBU 003 grpc: addrConn.resetTransport failed to create client transport: connection error: desc = "transport: Error while dialing dial tcp: lookup orderer.example.com on 127.0.0.11:53: no such host"; Reconnecting to {orderer.example.com:7050 } Error: Error connecting due to  rpc error: code = Unavailable desc = grpc: the connection is unavailable
이 문제는 주로orderer가 정상적으로 작동하지 않아서 찾을 수 없습니다. 바로 위의 dockerps에서 볼 때orderer가 시작 행렬에 있는지 확인해야 합니다.
4.3.2
Failed to dial orderer.example.com:7050: connection error: desc = "transport: authentication handshake failed: x509: certificate signed by unknown authority (possibly because of\"x509: ECDSA verification failure\"while trying to verify candidate authority certificate\"tlsca.example.com\")"; please retry. Error: Error connecting due to  rpc error: code = Internal desc = connection error: desc = "transport: authentication handshake failed: x509: certificate signed by unknown authority (possibly because of\"x509: ECDSA verification failure\"while trying to verify candidate authority certificate\"tlsca.example.com\")"
이것은 주로 더러운 데이터 문제이다. 내가 배치할 때 여러 차례 실패했기 때문에 결국 다시 왔다.
4.3.3
Error: Got unexpected status: BAD_REQUEST
주로 채널 이름이 겹쳐서 생긴 문제입니다. 도커를 닫고 다시 오면 됩니다.
docker rm -f $(docker ps -aq)

4.3.4
fabric 보고서 Error: Error endorsing query: rpc error: code = Unknown desc = Error executing chaincode: Timeout expired while starting chaincode
docker rmi -f $(docker images |grep "dev-" |awk '{print $3}')

4.4 채널에 peer를 넣는다. 위에서 모든 것이 순조롭다면 이쪽도 문제없다.(여기서 기본 링크는 peer0.org1)
peer channel join -b mychannel.block


4.5 peer1에 가입org1
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/[email protected]/msp 
CORE_PEER_ADDRESS=peer1.org1.example.com:7051

peer channel join -b mychannel.block

4.6 peer0을 넣는다.org2
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/[email protected]/msp 
CORE_PEER_ADDRESS=peer0.org2.example.com:7051

peer channel join -b mychannel.block

4.7 peer1 가입org2
CORE_PEER_LOCALMSPID="Org2MSP" 
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/ca.crt 
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/[email protected]/msp 
CORE_PEER_ADDRESS=peer1.org2.example.com:7051

peer channel join -b mychannel.block

4.8 Org1의 앵커 노드 peer0을 업데이트합니다.org1
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/[email protected]/msp 
CORE_PEER_ADDRESS=peer0.org1.example.com:7051

peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx --tls true --cafile $ORDERER_CA

4.8 Org2의 앵커 노드 peer0을 업데이트합니다.org2
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/[email protected]/msp 
CORE_PEER_ADDRESS=peer0.org2.example.com:7051

peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org2MSPanchors.tx --tls true --cafile $ORDERER_CA

5. ChainCode 실행
5.1 peer0으로 전환.org1
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/[email protected]/msp 
CORE_PEER_ADDRESS=peer0.org1.example.com:7051

5.2 ChainCode 설치
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02

5.3 실례화 체인 코드(장래의 SDK도 이 대상을 통해 체인을 조작할 것이다)
peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA -C mychannel -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "OR      ('Org1MSP.member','Org2MSP.member')"

5.4 질의
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
    :Query Result: 100

5.5 이체
peer chaincode invoke -o orderer.example.com:7050  --tls true --cafile $ORDERER_CA -C mychannel -n mycc -c '{"Args":["invoke","a","b","10"]}'

6. 다른 노드에서 거래를 조회하여peer0에게 준다.org2 설치 ChainCode
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/[email protected]/msp 
CORE_PEER_ADDRESS=peer0.org2.example.com:7051

peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02

6.1 조회
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
Query Result: 90

두 노드 모두ChainCode를 설치하면 Docker 미러 두 개가 시작됩니다.
dell@dell-OptiPlex-3050:~$ docker ps
CONTAINER ID        IMAGE                                 COMMAND                  CREATED             STATUS              PORTS                                                                       NAMES
0bda162b8c01        dev-peer0.org2.example.com-mycc-1.0   "chaincode -peer.add…"   19 minutes ago      Up 19 minutes                                                                                   dev-peer0.org2.example.com-mycc-1.0
7a724b3060c3        dev-peer0.org1.example.com-mycc-1.0   "chaincode -peer.add…"   22 minutes ago      Up 22 minutes                                                                                   dev-peer0.org1.example.com-mycc-1.0
436f6f0d70e4        hyperledger/fabric-tools              "/bin/bash"              28 minutes ago      Up 28 minutes                                                                                   cli
afb11e8d7cf6        hyperledger/fabric-orderer            "orderer"                29 minutes ago      Up 28 minutes       0.0.0.0:7050->7050/tcp                                                      orderer.example.com
e7f3ea4b3520        hyperledger/fabric-peer               "peer node start"        29 minutes ago      Up 29 minutes       0.0.0.0:10051->7051/tcp, 0.0.0.0:10052->7052/tcp, 0.0.0.0:10053->7053/tcp   peer1.org2.example.com
6e4c40b8feae        hyperledger/fabric-peer               "peer node start"        29 minutes ago      Up 28 minutes       0.0.0.0:9051->7051/tcp, 0.0.0.0:9052->7052/tcp, 0.0.0.0:9053->7053/tcp      peer0.org2.example.com
04db32690344        hyperledger/fabric-peer               "peer node start"        29 minutes ago      Up 28 minutes       0.0.0.0:7051-7053->7051-7053/tcp                                            peer0.org1.example.com
fa1ac260a3e3        hyperledger/fabric-peer               "peer node start"        29 minutes ago      Up 29 minutes       0.0.0.0:8051->7051/tcp, 0.0.0.0:8052->7052/tcp, 0.0.0.0:8053->7053/tcp      peer1.org1.example.com

좋은 웹페이지 즐겨찾기