본문 바로가기

블록체인

Hyperledger Fabric 1.3 설치 on Ubuntu 18.04

[Go lang 설치]


1. 사전 준비


sudo apt-get update

sudo apt-get -y upgrade


Go 공식사이트에서 최신 버전 확인 

https://golang.org/dl/



2. 설치 


wget https://dl.google.com/go/go1.11.5.linux-amd64.tar.gz

sudo tar -xvf go1.11.5.linux-amd64.tar.gz

sudo mv go /usr/local



3. 환경 변수 설정


~/.profile 파일 내에 아래 내용을 추가 후 저장

export GOROOT=/usr/local/go

export GOPATH=$HOME/MyProjects

export PATH=$GOPATH/bin:$GOROOT/bin:$PATH


.profile 파일 적용

source .profile



4. Go 버전 확인


gun@gun-fabric:~$ go version

go version go1.11.5 linux/amd64


환경 변수 확인

gun@gun-fabric:~$ go env

GOARCH="amd64"

GOBIN=""

GOCACHE="/home/gun/.cache/go-build"

GOEXE=""

GOFLAGS=""

GOHOSTARCH="amd64"

GOHOSTOS="linux"

GOOS="linux"

GOPATH="/home/gun/MyProjects"

GOPROXY=""

GORACE=""

GOROOT="/usr/local/go"

GOTMPDIR=""

GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"

GCCGO="gccgo"

CC="gcc"

CXX="g++"

CGO_ENABLED="1"

GOMOD=""

CGO_CFLAGS="-g -O2"

CGO_CPPFLAGS=""

CGO_CXXFLAGS="-g -O2"

CGO_FFLAGS="-g -O2"

CGO_LDFLAGS="-g -O2"

PKG_CONFIG="pkg-config"

GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build449035851=/tmp/go-build -gno-record-gcc-switches"



[Docker 설치]


1. 패키지 다운로드 후 설치

wget https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/docker-ce_18.03.1~ce-0~ubuntu_amd64.deb 

sudo dpkg -i docker*.deb

sudo apt install -f


2. docker 버전 확인

gun@gun-fabric:~$ sudo docker version

[sudo] password for gun: 

Client:

 Version:      18.03.1-ce

 API version:  1.37

 Go version:   go1.9.5

 Git commit:   9ee9f40

 Built:        Thu Apr 26 07:17:20 2018

 OS/Arch:      linux/amd64

 Experimental: false

 Orchestrator: swarm


Server:

 Engine:

  Version:      18.03.1-ce

  API version:  1.37 (minimum version 1.12)

  Go version:   go1.9.5

  Git commit:   9ee9f40

  Built:        Thu Apr 26 07:15:30 2018

  OS/Arch:      linux/amd64

  Experimental: false


3. docker 그룹에 사용자 계정 추가 (사용자 계정으로 docker를 실행하기 위해서)

sudo usermod -aG docker USERNAME


l'USERNAME' 은 자신의 계정을 넣으시면 됩니다.  적용을  위해서 리부팅 후 진행합니다



4. docker 실행 테스트

gun@gun-fabric:~$ docker run hello-world


Hello from Docker!

This message shows that your installation appears to be working correctly.


To generate this message, Docker took the following steps:

 1. The Docker client contacted the Docker daemon.

 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.

    (amd64)

 3. The Docker daemon created a new container from that image which runs the

    executable that produces the output you are currently reading.

 4. The Docker daemon streamed that output to the Docker client, which sent it

    to your terminal.


To try something more ambitious, you can run an Ubuntu container with:

 $ docker run -it ubuntu bash


Share images, automate workflows, and more with a free Docker ID:

 https://hub.docker.com/


For more examples and ideas, visit:

 https://docs.docker.com/get-started/


5. docker-compose 설치 (python package management를 우선 설치)

sudo apt install python-pip

sudo pip install docker-compose


6. docker-compose 버전 확인

gun@gun-fabric:~$ docker-compose --version

docker-compose version 1.23.2, build 1110ad0



[Hyperledger Fabric 설치]


1. 기타 개발 도구 설치

sudo apt install git curl libltdl-dev tree openssh-server net-tools


2. Hyperledger Fabric 설치


hyperledger 디렉토리 생성

mkdir -p $GOPATH/src/github.com/hyperledger/


해당 디렉토리로 이동

cd $GOPATH/src/github.com/hyperledger/


fabric 1.3 버전 다운로드 

git clone -b release-1.3 https://github.com/hyperledger/fabric


fabric 디렉토리로 이동 후 컴파일

cd fabric

make

컴파일 시간이 꽤 오래 걸립니다...

unit-test_1 ... 라고 나오는 단위테스트 단계로 들어가면 Ctrl+C 로 종료하셔도 됩니다. 이미 설치가 완료된 상태입니다.


3. 환경 설정


.profile 파일에 환경 변수 추가

export FABRIC_HOME=/home/gun/MyProjects/src/github.com/hyperledger/fabric

export PATH=$GOPATH/bin:$GOROOT/bin:$FABRIC_HOME/.build/bin:$PATH


.profile 파일 적용

source .profile


order 서비스 실행시에 IP lookup 시 에러가 발생되는 경우를 방지하기 위하여 


$FABRIC_HOME/examples/e2e_cli/base 디렉토리 아래에 있는 
docker-compose-base.yaml peer-base.yaml 을 열어서 아래 환경변수 추가해 주세요 dns resolver를 go로 설정

  orderer.example.com:

    container_name: orderer.example.com

    image: hyperledger/fabric-orderer

    environment:

      - GODEBUG=netdns=go

      - ORDERER_GENERAL_LOGLEVEL=debug

<<위 방법 말고 다른 해결책을 공유해 주시면 감사하겠습니다>>


e2e cli 테스트

cd $FABRIC_HOME/examples/e2e_cli

./network_setup.sh up


테스트 결과 화면


ctrl+C 눌러서 종료


e2e 테스트 네트워크 종료하면 모두 노드 종료 후 리소스 해제

./network_setup.sh down


하이퍼레저 패브릭 설치 및 테스트가 완료되었습니다.


Congratulations~!!