*Hyperledger Fabric 구조 이해하기 좋은 글 --->>> https://jeongbincom.tistory.com/68
page.38 first-network 예제 따라하기
======================모든 작업은 first-network 폴더 안에서=======================
1. 네트워크 인증서 생성
../bin/cryptogen generate --config=./crypto-config.yaml
2. 제네시스블록 생성
export FABRIC_CFG_PATH=$PWD
../bin/configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
(.......책에 보면 TwoOrgsOrdererGene-sis 라고 있는데... '-'는 줄이 바뀔 때 붙여쓰기를 나타낸다.. 이것 때문에 두 시간동안 디버깅했다..)
3. 채널 설정 트랜잭션 생성
export CHANNEL_NAME=mychannel && /home/asd/go/src/github.com/hyperledger/fabric/fabric-samples/bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
4. 각 조직의 앵커 피어 정보 트랜잭션 만들기
../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
5. 블록체인 네트워크 동작시키기
docker-compose -f ./docker-compose-cli.yaml up -d
==========컴퓨터 reboot===========
reboot 시에 go, docker-compose 등 설치가 안된 것으로 나오는데, 이건 path 설정이 초기화 된 것이다.
이것도 모르고 ubuntu를 계속 지웠다 다시 설치했기 때문에, 환경설정 값은 이미 vi ~/.profile 에 기록해뒀다.
때문에 아래 명령어로 reboot 시에는 설정값을 적용만 해준다
source ~/.profile
cd $FABRIC/fabric-samples/first-network
===============================
6. CLI 도커 컨테이너 실행
sudo docker exec -it cli bash
==============에러발생============
>Error response from daemon: Container e5f521dfa451a9f2f3fc5cbf612b65817fff8201ccf9ca72658fbab6ecf95a72 is not running
docker.sock 권한 설정 변경으로 해결 ( 컴퓨터 reboot 때문인 듯 하다)
chmod 666 /var/run/docker.sock
================================
7. 채널 만들기(Create Channel)
export CHANNEL_NAME=mychannel
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
==============에러발생============
> Error: got unexpected status: FORBIDDEN -- Failed to reach implicit threshold of 1 sub-policies, required 1 remaining: permission denied
> exit로 cli 툴을 나간 후 아래 명령어 -> @6 -> @7 실행
./byfn.sh -m down # 채널 mychannel을 생성
./byfn.sh -m up # 채널 mychannel을 실행 (down: 중단)
> BAD_REQUEST -- error authorizing update: error validating ReadSet: readset expected key [Group] /Channel/Application at version 0, but got version 1
아하.. 네트워크를 내려야지 가능하다고 한다.. 다시 exit로 cli 툴을 나간 후 아래 명령어 -> 5번 -> 6번 -> 7번 실행
./byfn.sh -m down
.....안됨 ......완전 처음부터 다시 fabric-samples 폴더 지우고, 다시 아래 명령어를 통해 fabric-samples 설치하고, 1번 ~ 7번 까지 하면 됨......뭐지 뭘까
curl -sSL http://bit.ly/2ysbOFE | bash -s 1.4.0
================================
8. 생성된 채널에 조인하기 (org/peer에 맞게 환경변수 계속 변경해야 함)
<org1 peer0 조인> (이 친구는 초기값이라 설정 필요 없는 듯?)
peer channel join -b mychannel.block
<org2 peer0 조인>
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin\@org2.example.com/msp/
export CORE_PEER_ADDRESS=peer0.org2.example.com:7051
export CORE_PEER_LOCALMSPID="Org2MSP"
export 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
peer channel join -b mychannel.block
<org1 peer1 조인>
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=peer1.org1.example.com:7051
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/peer1.org1.example.com/tls/ca.crt
peer channel join -b mychannel.block
<org2 peer1 조인>
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin\@org2.example.com/msp
export CORE_PEER_ADDRESS=peer1.org2.example.com:7051
export CORE_PEER_LOCALMSPID="Org2MSP"
export 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
peer channel join -b mychannel.block
9. 앵커 피어 업데이트 (org/peer에 맞게 환경변수 계속 변경해야 함)
<org1 peer0>
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
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
peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/Org1MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
<org2 peer0>
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin\@org2.example.com/msp/
export CORE_PEER_ADDRESS=peer0.org2.example.com:7051
export CORE_PEER_LOCALMSPID="Org2MSP"
export 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
peer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/Org2MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
10. 체인코드 설치
<org1 peer0>
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
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
peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/
<org2 peer0>
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin\@org2.example.com/msp/
export CORE_PEER_ADDRESS=peer0.org2.example.com:7051
export CORE_PEER_LOCALMSPID="Org2MSP"
export 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
peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/
11. 체인코드 초기화
peer chaincode instantiate -o orderer.example.com:7050 --tls --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 "AND ('Org1MSP.peer','Org2MSP.peer')"
12. 체인코드 조회 및 호출과 컨테이너 확인
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'
peer chaincode invoke -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 -C $CHANNEL_NAME -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["invoke","a","b","10"]}'
끝,
사실 글로 막힘없이 적어서 그렇지 중간에 에러 하나 생기면 디버깅에 1~2 시간은 소요된다,,
'Hyperledger' 카테고리의 다른 글
[Hyperledger] p.51 Balance Transfer 예제 따라하기 (CentOS 7) (0) | 2021.06.04 |
---|---|
[Hyperledger] p.38 first-network 예제 따라하기 (CentOS 7) (0) | 2021.06.04 |
[Hyperledger] p.20 하이퍼레저 패브릭 개발 환경 설정 (CentOS 7) (0) | 2021.06.04 |
[Hyperledger] p.51 Balance Transfer 예제 따라하기 (unbuntu 18.04) (0) | 2021.06.04 |
[Hyperledger] p.20 개발 환경 설정 (unbuntu 18.04) (0) | 2021.06.04 |