리눅스(우분투 16.04)에서 하이퍼레저 설치
터미널
1) Git client 설치
sudo apt update && sudo apt upgrade -y
sudo apt-get install git -y
2) Go — 1.7 or later (고언어 버전 1.7 이상 설치)
2–1) cd /usr/local 로 이동
cd /usr/local
2–2) go 언어 해당 위치에 다운로드
sudo wget https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz
2–3) 해당 위치에서 압축 해제
sudo tar -C /usr/local -xzf go1.8.1.linux-amd64.tar.gz
2–4) 사용자 계정으로 이동
cd /home/nds2272
#nds2272는 사용자 계정명
2–5) go workspace 설정
mkdir -vp myproject/{src,pkg,bin}
#myproject는 임의로 지정
2–6) GOPATH 설정($HOME/.bash_profile)
— — — 아톰(atom) 에디터 사용해서 파일 생성
sudo atom $HOME/.bash_profile
#아래 스크립트를 넣고 저장
export PATH=$PATH:/usr/local/go/bin
export GOPATH=/home/nds2272/myproject
#해당위치($HOME)에서 아래 스크립트 실행
source .bash_profile
go env GOPATH
#/home/nds2272/myproject
###############################################################################################
sudo atom /etc/profile
#############
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
#export PATH=$PATH:GOPATH/bin
2–7) Go언어 설치 완료 테스트
cd myproject/src && mkdir hello
cd $HOME/myproject/src/hello
atom hello.go
#################################
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
#################################
go build
#프로그램 go를 설치하지 않았습니다. 메시지가 나오면 (2–6) go path 설정해줌
./hello
# hello, world 텍스트
3) Docker — 1.12 or later 설치
sudo apt-get update
sudo apt-get install \
linux-image-extra-$(uname -r) \ linux-image-extra-virtual -y
sudo apt-get install \
apt-transport-https \ ca-certificates \ curl \ software-properties-common -y
# Add Docker’s official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# Verify that the key fingerprint is 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88.
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update && sudo apt-get install docker-ce -y
# Verify that Docker CE or Docker EE is installed correctly by running the hello-world image
sudo docker run hello-world
#사용자에게 도커 명령어 처리 가능하게 권한 부여
sudo usermod -a -G docker nds2272
4) Docker Compose — 1.8.1 or later설치
sudo curl -L "https://github.com/docker/compose/releases/download/1.11.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose — version
5) pip, behave 설치
sudo apt-get install python-pip -y
sudo pip install --upgrade pip
sudo pip install behave nose docker-compose
sudo apt-get install python-dev libssl-dev -y
sudo pip install -I flask==0.10.1 python-dateutil==2.2 pytz==2014.3 pyyaml==3.10 couchdb==1.0 flask-cors==2.0.1 requests==2.4.3 pyOpenSSL==16.2.0 pysha3==1.0b1 grpcio==1.0.4
# PIP packages required for some behave tests
sudo pip install urllib3 ndg-httpsclient pyasn1 ecdsa python-slugify grpcio-tools jinja2 b3j0f.aop six
6) Fabric code base 복제
cd $GOPATH/src
mkdir -p github.com/hyperledger && cd github.com/hyperledger
git clone https://github.com/hyperledger/fabric.git
7) Build and test the Fabric project (패브릭 프로젝트 빌드 및 테스트)
7–1) 빌드( root 로 실행 필수)
sudo passwd root
su
source /home/nds2272/.bash_profile
cd $GOPATH/src/github.com/hyperledger/fabric
make dist-clean all
# If you see an error stating - 'ltdl.h' file not found
apt install libtool libltdl-dev -y
# Then run the make again
make dist-clean all
#AttributeError: ‘module’ object has no attribute ‘PROTOCOL_SSLv3’
pip install requests==2.6.0
sudo easy_install --upgrade pip
# Then run the make again
make dist-clean all
# unit-test 오류가 나도 정상임 다음 진행 가능(테스트에서 정상 이면 됨)
7–2) 테스트
cd $GOPATH/src/github.com/hyperledger/fabric
make unit-test
cd $GOPATH/src/github.com/hyperledger/fabric/gossip/gossip
go test -v -run=TestPull
8) Prerequisites
cd $GOPATH/src/github.com/hyperledger/fabric
make configtxgen
# build/bin/configtxgen 에서 확인
9) 올인원 도커 이미지 오류((7) 빌드&Test 실행으로 대체 가능)
All in one with docker images 로컬 네트워크 구성 및 체인코드(chaincode) 테스트
9–1) 도커 허브에서 이미지 다운로드(쉘 스크립트 실행)
cd examples/e2e_cli
# make the script an executable
chmod +x download-dockerimages.sh
# run the script
./download-dockerimages.sh
# <channel-ID> 를 넣지 않고 실행시 기본값, 넣을 경우 넣는 값으로 ID 생성
./network_setup.sh up <channel-ID>
10) 네트워크 clean up
# docker running status
docker ps
# make sure you’re in the e2e_cli directory
docker rm -f $(docker ps -aq)
# 다시 확인
docker ps
#도커 이미지 확인 후 체인 코드가 deploy된 부분 delete
docker images
docker rmi -f dev-peer3-mycc-1.0 dev-peer0-mycc-1.0 dev-peer2-mycc-1.0
docker images
#디렉토리 crypto/orderer
ls -al
rm -rf orderer.block
rm -rf channel.tx
11) Configuration Transaction Generator
cd $GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli
# as mentioned above, the <channel-ID> parm is optional
# <channel-ID> 는 없으면 기본값을 실행
./generateCfgTrx.sh <channel-ID>
#디렉토리 crypto/orderer
ls -al
# orderer.block 과 channel.tx 파일 생성 확인
12) 네트워크 start
cd $GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli
CHANNEL_NAME=<channel-id> docker-compose up -d
# mychannel 이 기본 값
# CHANNEL_NAME= docker-compose up -d
docker ps
#도커 컨테이너 확인
docker logs -f cli
#CLI(command line interface) 의 로그를 통해 확인
docker logs dev-peer2-mycc-1.0
docker logs dev-peer0-mycc-1.0
docker logs dev-peer3-mycc-1.0
13) 수동 트랜잭션 실행
13–1) (10)번의 clean up 실행
####현재 실행 중인 도커 컨테이너 제거
docker rm -f $(docker ps -aq)
docker ps
cd $GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli
# as mentioned above, the <channel-ID> parm is optional
# <channel-ID> 는 없으면 기본값을 실행
./generateCfgTrx.sh <channel-ID>
#디렉토리 crypto/orderer
ls -al
# orderer.block 과 channel.tx 파일 생성 확인
13–2) docker-compose file 수정
cd $GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli
sudo atom docker-compose.yaml
##################################################################
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
# cli 컨테이너의 command부분 주석 처리 (현재 버전에서 200 line-변경 가능)
# command: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME}'
###################################################################
# 저장 후 네트워크 재시작
# make sure you are in the e2e_cli directory where you docker-compose script resides
# add the appropriate CHANNEL_NAME parm
CHANNEL_NAME=mychannel docker-compose up -d
13–3) command syntax 환경 변수 스크립트로 선언
# Environment variables for PEER0
CORE_PEER_MSPCONFIGPATH=$GOPATH/src/github.com/hyperledger/fabric/peer/crypto/peer/peer0/localMspConfig
CORE_PEER_TLS_ROOTCERT_FILE=$GOPATH/src/github.com/hyperledger/fabric/peer/crypto/peer/peer0/localMspConfig/cacerts/peerOrg0.pem
13–4) 채널 생성
docker ps
# CLI 도커 컨테이너 실행 확인
#########################################################################################
# f4103cba701e hyperledger/fabric-peer “peer node start” 7 minutes ago Up 7 minutes cli
########################################################################################
docker exec -it cli bash
#cli 도커 컨테이너에 접속
root@f4103cba701e:/opt/gopath/src/github.com/hyperledger/fabric/peer#
# the channel.tx and orderer.block are mounted in the crypto/orderer directory within your cli container
# as a result, we pass the full path for the file
peer channel create -o orderer0:7050 -c mychannel -f crypto/orderer/channel.tx --tls $CORE_PEER_TLS_ENABLED --cafile $GOPATH/src/github.com/hyperledger/fabric/peer/crypto/orderer/localMspConfig/cacerts/ordererOrg0.pem
13–5) 채널 참여
# By default, this joins PEER0 only
# the mychannel.block is also mounted in the crypto/orderer directory
peer channel join -b mychannel.block
13–6) 체인코드(chaincode) 인스톨
# remember to preface this command with the global environment variables for the appropriate peer
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
13–7) init(초기화)
# remember to preface this command with the global environment variables for the appropriate peer
# remember to pass in the correct string for the -C argument. The default is mychannel
peer chaincode instantiate -o orderer0:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $GOPATH/src/github.com/hyperledger/fabric/peer/crypto/orderer/localMspConfig/cacerts/ordererOrg0.pem -C mychannel -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -c '{"Args":["init","a", "100", "b","200"]}' -P "OR ('Org0MSP.member','Org1MSP.member')"
13–8) Invoke chaincode(insert, update, delete)
# remember to preface this command with the global environment variables for the appropriate peer
peer chaincode invoke -o orderer0:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $GOPATH/src/github.com/hyperledger/fabric/peer/crypto/orderer/localMspConfig/cacerts/ordererOrg0.pem -C mychannel -n mycc -c '{"Args":["invoke","a","b","10"]}'
13–9) Query chaincode (query)
# remember to preface this command with the global environment variables for the appropriate peer
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
14) Use CouchDB
cd $GOPATH/src/github.com/hyperledger/fabric
# make sure you are in the fabric directory
make couchdb
fabric/examples/e2e_cli/docker-compose.yaml의 couchdb관련 주석 제거
##############################################################################자주 사용하게 될 명령어
docker images : 도커 이미지 리스트
docker ps : 현재 실행 중인 도커 컨테이너
##실행 중인 도커 컨테이너 삭제(실행 디렉토리에서)
docker rm -f $(docker ps -aq)
##도커 이미지 삭제
docker rmi -f dev-peer3-mycc-1.0 dev-peer0-mycc-1.0 dev-peer2-mycc-1.0