사전 준비 과정
서버 환경
- CPU: 1 cores (5 thread), 16 GB RAM
- Operation system: Oracle Linux 8
Type: Developer playground
System Requirements: RaspberryPi(2/3) - Minimal Requirements
Setup - Single org - 2 Nodes - 1 channel - 1 orderer Node
Type: Advanced Developer playground - Locally on a PC
System Requirements: Ubuntu 16.04LTS, 4GB RAM, 20GB HDD
Setup - 3 orgs - 6 Nodes - 2 channel - 3 orderer Node
Type: Developing an MVP for an organization
System Requirements: Ubuntu 16.04LTS, 8GB RAM, 30GB HDD
Setup - Multi orgs - n Nodes - Multi channel Setup - 3 orderer Node
방화벽 설정 정보
목적지 IP | Port 정보 |
---|---|
http://repo.zabbix.com | 80, 20, 21 |
https://download.docker.com | 443 |
https://yum.oracle.com | 443 |
https://www.github.com | 443 |
https://raw.githubusercontent.com | 443 |
https://registry-1.docker.io/v2/ | 443 |
사전 설치 프로그램
AWS Blockchain manegement system에서 HyperLedger Fabric을 사용하고자 할 경우,
Go언어의 버전을 1.14로 해서 사용하여야만 Chaincode 업로드가 가능
설치 과정
테스트 네트워크 설치
테스트 네트워크 설치 script download
curl -sSLO https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh && chmod +x install-fabric.sh
테스트 네트워크 실행 도움말
./install-fabric.sh -h
실행 예시
./install-fabric.sh -h
Usage: ./install-fabric.sh [-f|--fabric-version <arg>] [-c|--ca-version <arg>] <comp-1> [<comp-2>] ... [<comp-n>] ...
<comp>: Component to install one or more of d[ocker]|b[inary]|s[amples]. If none specified, all will be installed
-f, --fabric-version: FabricVersion (default: '2.5.4')
-c, --ca-version: Fabric CA Version (default: '1.5.6')
Component를 선택해서 다운로드
특정한 component를 선택해서 다운로드 하기 위해서는 다음의 인자를 추가해서 다운로드 진행
- docker
- Fabric container 이미지를 다운로드 받기 위해서 docker 사용
- podman
- Fabric container 이미지를 다운로드 받기 위해서 podman 사용
- binary
- Fabric binaries 다운로드 진행
- samples
- github repository에 있는 fabric-samples 코드를 현재 디렉토리에 다운로드
실행 예시
./install-fabric.sh docker samples binary
or
./install-fabric.sh d s b
특정 버전의 Fabric 다운로드
특정한 버전을 다운로드 하기 위해서는 --fabric-version
과 -ca-version
옵션을 사용해서 다운로드가 가능
짧게 옵션을 준다면 -f
, -c
로 사용이 가능
Fabric 특정 버전 다운로드 예시
./install-fabric.sh --fabric-version 2.5.4 binary
테스트 네트워크 실행
네트워크 실행 명령
./network up
네트워크 실행 시, ca, channel 정보, DB 정보 설정
예시 : ca를 설정하며 채널 이름은
mychannel
저장소는couchdb
를 사용하도록 설정
./network.sh up createChannel -ca -c mychannel -s couchdb
네트워크 종료
./network down
Chaincode 배포
packaging
Go언어로 개발이 된 chaincode 정보를 패키징을 진행
peer lifecycle chaincode package chaincode.tar.gz --path ${O_CHAINCODE_PATH} --lang golang --label ${O_CHAINCODE_LABEL}
- path : 프로젝트의 경로 설정
- lang : chaincode가 개발된 언어 정보 설정 [Go, Java, Javascript]
예시의 명령어의 경우, Go로 개발된 chaincode를 패키징
- label: chaincode의 라벨 정보를 추가
install
패키징된 tar.gz 파일을 Hyperledger Fabric Peer에 설치하는 과정. Chaincode를 배포하기 위해서는 Channel에 속한 모든 Peer에 chaincode를 설치해줘야 한다.
peer
명령어를 사용하기 전, 다음과 같은 환경설정을 먼저 진행한다.
환경 설정
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=localhost:7051
각각 TLS에 대한 설정, Hyperledger Fabric의 MSP 설정, Peer의 주소 설정 정보를 의미한다.
설치 명령어
peer lifecycle chaincode install [패키징된 파일 이름]
approve
설치가 된 Chaincode에 대해서 각각의 Peer들은 배포의 여부를 증명하는 과정을 필요로 한다.
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name chaincode --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
위와 같은 명령어를 통해 chaincode를 증명할 수 있는데, chaincode의 이름, 버전 정보, 시퀀스 넘버를 입력하여 증명하는 것이 가능하다.
commit
일정한 비율만큼 증명이 되었다면 다음과 같은 명령어를 통해서 commit을 진행하는 것이 가능하다.
peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name chaincode --version 1.0 --sequence 1 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt"
참고
배포하기 위한 script 파일 내용
#!/bin/bash
export PATH=${PWD}/../fabric-samples/bin:$PATH
export FABRIC_CFG_PATH=${PWD}/../fabric-samples/config/
export PATH=$PATH:/usr/local/go/bin
set_peer1() {
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/../fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/../fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
export CORE_PEER_ADDRESS=localhost:7051
}
set_peer2() {
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/../fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/../fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
export CORE_PEER_ADDRESS=localhost:9051
}
packaging() {
PACKAGE_RESULT=$(peer lifecycle chaincode package omnione.tar.gz --path ${O_CHAINCODE_PATH} --lang golang --label ${O_CHAINCODE_LABEL})
if [ $? -ne 0 ]; then
echo "PACKAGE ERROR!!"
exit 1
fi
}
install_chaincode() {
set_peer1
PACKAGE_INSTALL_FIRST=$(peer lifecycle chaincode install omnione.tar.gz >install_result.txt)
if [ $? -ne 0 ]; then
echo "FIRST PEER CHAINCODE INSTALL ERROR"
exit 1
fi
set_peer2
PACKAGE_INSTALL_SECOND=$(peer lifecycle chaincode install omnione.tar.gz)
if [ $? -ne 0 ]; then
echo "SECOND PEER CHAINCODE INSTALL ERROR"
exit 1
fi
}
approve_chaincode() {
set_peer2
$(peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name omnione --version ${O_CHAINCODE_VERSION} --package-id ${CC_PACKAGE_ID} --sequence 6 --tls --cafile "${PWD}/../fabric-samples/test-network/organizations/ordererOrgan
izations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem")
set_peer1
$(peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name omnione --version ${O_CHAINCODE_VERSION} --package-id ${CC_PACKAGE_ID} --sequence 6 --tls --cafile "${PWD}/../fabric-samples/test-network/organizations/ordererOrgan
izations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem")
}
commit_chaincode() {
set_peer1
$(peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name omnione --version 1.2 --sequence 6 --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt")
}
print_help() {
echo "$0 -p PATH -v VERSION -l LABEL [-i ID]"
echo "<options>"
echo " -p PATH: chaincode project path"
echo " -i CHAINCODE_ID: chaincode id that you want to deploy. default is 'omnione'"
echo " -v VERSION: chaincode version"
echo " -l LABEL: label of chaincode"
echo " -h : Show this message."
echo "<exit code>"
echo " 0: Success."
echo " 1: Failure."
exit 1
}
while getopts p:i:l:v: opts; do
case $opts in
i)
O_CHAINCODE_ID=$OPTARG
;;
p)
O_CHAINCODE_PATH=$OPTARG
;;
l)
O_CHAINCODE_LABEL=$OPTARG
;;
v)
O_CHAINCODE_VERSION=$OPTARG
;;
h)
print_help
;;
\?)
print_help
exit 1
;;
:)
print_help
exit 1
;;
*)
print_help
exit 1
;;
esac
done
packaging
install_chaincode
approve_chaincode
Reference
'BlockChain > Hyperledger Fabric' 카테고리의 다른 글
Hyper Ledger Query 기반 Ledger 조회 (0) | 2023.11.16 |
---|