1. Hyperledger Fabric Docker-compose.yaml 환경변수 정의
Orderer(오더러) 환경변수
version: '2'
volumes:
orderer.example.com:
peer0.org1.example.com:
peer0.org2.example.com:
networks:
test:
services:
orderer.example.com:
container_name: orderer.example.com
image: hyperledger/fabric-orderer:2.2
environment:
- FABRIC_LOGGING_SPEC=INFO
- ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
- ORDERER_GENERAL_LISTENPORT=7050
- ORDERER_GENERAL_GENESISMETHOD=file
- ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block
- ORDERER_GENERAL_LOCALMSPID=OrdererMSP
- ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp
# enabled TLS
- ORDERER_GENERAL_TLS_ENABLED=true
- ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key
- ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt
- ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
- ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/hyperledger/orderer/tls/server.crt
- ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key
- ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
working_dir: /opt/gopath/src/github.com/hyperledger/fabric
command: orderer
volumes:
- ../system-genesis-block/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
- ../organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp:/var/hyperledger/orderer/msp
- ../organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/:/var/hyperledger/orderer/tls
- orderer.example.com:/var/hyperledger/production/orderer
ports:
- 7050:7050
networks:
- test
environment :
- FABRIC_LOGGING_SPEC=INFO # 로그 메시지 표시 수준 설정(INFO/DEBUG)
- ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 # 오더러 주소값
- ORDERER_GENERAL_LISTENPORT=7050 # 오더러 포트
- ORDERER_GENERAL_GENESISMETHOD=file # 제네시스 블록을 지정하는 방법(file/Provisional)
- ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block # 제네시스 블록 경로
- ORDERER_GENERAL_LOCALMSPID=OrdererMSP # configtx.yaml에서 지정한 오더러의 Local MSPID
- ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp # 오더러의 Local MSP 경로
# enabled TLS
- ORDERER_GENERAL_TLS_ENABLED=true # TLS 통신여부(True/False)
- ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key # TLS 개인키가 저장된 경로
- ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt # TLS 서버 인증서 파일 경로
- ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] # 오더러의 TLS 서버 인증서를 발급한 CA의 인증서 파일 경로
- ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/hyperledger/orderer/tls/server.crt
- ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key
- ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
Peer(피어) 환경변수
peer0.org1.example.com:
container_name: peer0.org1.example.com
image: hyperledger/fabric-peer:2.2
environment:
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=net_test
- FABRIC_LOGGING_SPEC=INFO
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_PROFILE_ENABLED=true
- CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
# Peer specific variabes
- CORE_PEER_ID=peer0.org1.example.com
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051
- CORE_PEER_LISTENADDRESS=0.0.0.0:7051
- CORE_PEER_CHAINCODEADDRESS=peer0.org1.example.com:7052
- CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.example.com:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051
- CORE_PEER_LOCALMSPID=Org1MSP
volumes:
- /var/run/docker.sock:/host/var/run/docker.sock
- ../organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/fabric/msp
- ../organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls
- peer0.org1.example.com:/var/hyperledger/production
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: peer node start
ports:
- 7051:7051
networks:
- test
environment:
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock # Docker 데몬 주소
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=net_test # 컨테이너의 네트워크 모드 설정
- FABRIC_LOGGING_SPEC=INFO
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_PROFILE_ENABLED=true
- CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
- CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
- CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
# Peer specific variabes
- CORE_PEER_ID=peer0.org1.example.com # 피어 식별 ID
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051 # 해당 Peer의 주소값
- CORE_PEER_LISTENADDRESS=0.0.0.0:7051 # Peer의 IP주소
- CORE_PEER_CHAINCODEADDRESS=peer0.org1.example.com:7052
- CORE_PEER_CHAINCODELISTENADDRESS=0.0.0.0:7052
- CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.example.com:7051 # 앵커 peer의 endpoint 및 주소
※ 앵커 peer가 아닌 peer에 설정. (ORG 내에서 gossip을 시작하기 위해 사용. 공백으로 구분된 peer 목록으로 지정 가능. peer가 부트스트랩 peer에 접속하면 endpoint 정보를 전달한 다음 ORG의 모든 peer에 대한 정보를 ORG의 peer들에게 배포하는 데 gossip이 사용됨.)
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051
※ peer에서 발생하는 모든 외부 통신에 대한 endpoint 또는 주소 (이 값이 설정되지 않으면 해당 peer에 대한 endpoint 정보가 다른 ORG의 peer에게 broadcasting되지 않으며, 자신의 ORG에게만 알려짐)
- CORE_PEER_LOCALMSPID=Org1MSP # MSP ID값
2. Docker-compose 네트워크 실행
- docker 네트워크 실행
※ 2개 이상 도커 네트워크 사용시 COMPOSE_PROJECT_NAME은 유동적으로 변경하면서 사용
cd fabric-samples/my-network/docker
COMPOSE_PROJECT_NAME=net docker-compose up -d
# -d 는 백그라운드 실행
- docker 네트워크 종료
cd fabric-samples/my-network/docker
COMPOSE_PROJECT_NAME=net docker-compose down
- docker 원하는 docker-compose.yaml 실행
cd fabric-samples/my-network/docker
COMPOSE_PROJECT_NAME=net docker-compose -f docker-compose_test.yaml up -d
# -f 에 추가하고자 하는 docker 네트워크 파일 위치 지정
3. Hyperledger-Fabric 채널 생성
# 환경변수 설정
cd fabric-samples/my-network
export FABRIC_CFG_PATH=${PWD}/configtx
# 채널 트랜잭션 생성
configtxgen \
-profile TwoOrgsChannel \
-outputCreateChannelTx ./channel-artifacts/mychannel.tx \
-channelID mychannel
# 환경변수 설정
cd fabric-samples/my-network
export FABRIC_CFG_PATH=${PWD}/config
export CORE_PEER_TLS_ENABLED=true
export ORDERER_CA=${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
export CORE_PEER_LOCALMSPID=Org1MSP
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_ADDRESS=localhost:7051
# 채널 블록 생성
peer channel create \
-o localhost:7050 \
-c mychannel \
--ordererTLSHostnameOverride orderer.example.com \
-f ./channel-artifacts/mychannel.tx \
--outputBlock ./channel-artifacts/mychannel.block \
--tls \
--cafile $ORDERER_CA
'보안 및 블록체인 > 블록체인' 카테고리의 다른 글
하이퍼레저 패브릭(Hyperledger Fabric) v2.2 COMPOSE_PROJECT_NAME Multiple 설정 및 문제 해결방법 (0) | 2022.07.20 |
---|---|
하이퍼레저 패브릭(Hyperledger Fabric) v2.2 - 채널에 Org 추가 (0) | 2022.07.16 |
하이퍼레저 패브릭(Hyperledger Fabric) v2.2 - #1 Peer 키생성 - Cryptogen (0) | 2022.07.12 |
하이퍼레저 패브릭(Hyperledger Fabric) v2.2 구축 - #2 채널구성 및 제네시스 블록 생성 (0) | 2022.07.11 |
GO언어 필요한 내용 정리 (0) | 2022.06.27 |