본문 바로가기

BlockChain Developer/Public Blockchain

[Hyperledger Besu] EC2에 Hyperledger IBFT 2.0 (POA) Network 구성하기


POA Network Node 구성하기

# EC2 Hyperledger Besu Setting 진행 내용

1. AWS에 EC2 인스턴스를 켠다.

2. EC2 인스턴스에 Hyperledger Besu를 설치한다.

3. Genesis File 구성하기.

4. Hyperledger 구동하기.

 

 

# 실습내용

1. AWS에서 EC2 인스턴스를 켠다. 최소 t2.medium 이상의 성능을 요구한다.

 

2. EC2 인스턴스에 Hyperledger Besu를 설치한다.    

    a. Dependency를 설치

# Ubuntu Package Update
sudo apt-get update

# wget 설치확인 & 설치
which wget
sudo apt-get install wget


#adoptopenjdk 설치 (Java 11-16)
wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add -
sudo add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/
sudo apt update
sudo apt install openjdk-11-jre-headless

#java 설치 확인
java -version

#unzip 설치
sudo apt install unzip

#tree 설치
sudo apt-get install tree

 

    b. Hyperledger Besu 설치

# ~ 디렉토리에 hyperledger-besu 폴더 생성
mkdir hyperledger-besu

# hyperledger-besu 디렉토리에 Hyperledger Besu 설치
cd hyperledger-besu
wget https://hyperledger.jfrog.io/artifactory/besu-binaries/besu/21.10.2/besu-21.10.2.zip

# 압축풀기
unzip besu-21.10.2.zip

# 압축 푼 besu-21.10.2 -> besu 로 이름 바꾸기
mv besu-21.10.2 besu

# ~ 디렉토리로 이동 후, 경로 설정 후, 적용하기
cd ~
export PATH=$PATH:/home/ubuntu/hyperledger-besu/besu/bin
source ~/.profile

# 배수 설치확인하기
besu --version

 

 

3. 폴더구조 설정하기

~에 IBFT-Network 폴더 생성 해줍니다.

 

4. ibftConfigFile.json 구성하기

a. IBFT-Network 폴더 내에 ibftConfigFile.json을 생성하고, 아래 내용을 붙여 넣어 저장합니다.

{
 "genesis": {
   "config": {
      "chainId": 1337,
      "muirglacierblock": 0,
      "ibft2": {
        "blockperiodseconds": 2,
        "epochlength": 30000,
        "requesttimeoutseconds": 4
      }
    },
    "nonce": "0x0",
    "timestamp": "0x58ee40ba",
    "gasLimit": "0x47b760",
    "difficulty": "0x1",
    "mixHash": "0x63746963616c2062797a616e74696e65206661756c7420746f6c6572616e6365",
    "coinbase": "0x0000000000000000000000000000000000000000",
    "alloc": {
       "fe3b557e8fb62b89f4916b721be55ceb828dbd73": {
          "privateKey": "8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63",
          "comment": "private key and this comment are ignored.  In a real chain, the private key should NOT be stored",
          "balance": "0xad78ebc5ac6200000"
       },
       "627306090abaB3A6e1400e9345bC60c78a8BEf57": {
         "privateKey": "c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3",
         "comment": "private key and this comment are ignored.  In a real chain, the private key should NOT be stored",
         "balance": "90000000000000000000000"
       },
       "f17f52151EbEF6C7334FAD080c5704D77216b732": {
         "privateKey": "ae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f",
         "comment": "private key and this comment are ignored.  In a real chain, the private key should NOT be stored",
         "balance": "90000000000000000000000"
       }
      }
 },
 "blockchain": {
   "nodes": {
     "generate": true,
       "count": 4
   }
 }
}

 

b. 키체인을 생성하고 Genesis파일을 만듭니다. (위 작성한, ibftConfigFile.json 를 통해 생성됨)

besu operator generate-blockchain-config --config-file=ibftConfigFile.json --to=networkFiles --private-key-file-name=key

 

그런 뒤, tree구조를 확인하자.

아래와 같이 genesis.json파일이 생기고, key 파일이 4개 생긴다.

IBFT-Network에서 tree 구조 확인

 

이제 IBFT-Network 폴더로 이동해주는 작업을 진행해야 한다.

아래와 같은 형태로 구성을 바꿔야한다.

 

기존 networkFiles 폴더의 내용을 가져오고, 삭제한 뒤, 위 트리구조와 같이 만들어준다.

 

4. Hyperledger Besu 구동하기

위 구조를 완성했으면, Node-1 디렉토리로 이동하여, 아래 명령어를 통해 실행한다. (아래 명령어는 Node-1/data 폴더 내에서 실행해야한다.) 명령어를 자세히 살펴보면, 포트간 충돌방지를 위해 각 다른 포트에서 열어줌을 확인할 수 있다.

 

<Node-1 구동>

besu --data-path=data --genesis-file=../genesis.json --rpc-http-enabled --rpc-http-api=ETH,NET,IBFT --host-allowlist="*" --rpc-http-cors-origins="all"

 

<Node-2 구동>

besu --data-path=data --genesis-file=../genesis.json --bootnodes=<Node-1 Enode URL> --p2p-port=30304 --rpc-http-enabled --rpc-http-api=ETH,NET,IBFT --host-allowlist="*" --rpc-http-cors-origins="all" --rpc-http-port=8546

 

<Node-3 구동>

besu --data-path=data --genesis-file=../genesis.json --bootnodes=<Node-1 Enode URL> --p2p-port=30305 --rpc-http-enabled --rpc-http-api=ETH,NET,IBFT --host-allowlist="*" --rpc-http-cors-origins="all" --rpc-http-port=8547

 

<Node-4 구동>

besu --data-path=data --genesis-file=../genesis.json --bootnodes=<Node-1 Enode URL> --p2p-port=30306 --rpc-http-enabled --rpc-http-api=ETH,NET,IBFT --host-allowlist="*" --rpc-http-cors-origins="all" --rpc-http-port=8548

 

 

※ 명령어에서 주의할 점이 있다.

 

1. --bootnodes=<Node-1 Enode URL> 에서 Node-1 Enode URL로 변경해야 한다는 점. (Node-1 구동시, 출력된다.)

Enode URL

 

 

2. EC2간 통신을 해야한다. 따라서 아래와 같은 절차가 필요하다.

 

    a. 인바운드 규칙에 Node-2, 3, 4의 TCP & UDP 포트를 오픈해야한다. (각 구동 명령어에 --p2p-port= 와, --rpc-http-port= 의 내용으로 존재한다)

Node-4까지 모두 오픈한 인바운드 규칙

  

 

    b. 자신의 enode URL에서 아래 부분을 확인하자. (AWS의 퍼블릭 IPv4주소로 변경해주어야한다.)

bootnodes=enode://fa6ca46acaa540aaf09d0dd05d8130fc884679fc5e87dcaa58df7512ed37a6c49e83dc8192c99ea

5363e135709c9a6bbc18f3780c5bf9a9e46e7a32b7107e9ae@13.121.92.245:30303

 

 

5. 최종 결과화면

Node-1(Coinbase) 구동화면