こんにちは。DaiDaiです。HyperLedger fabric 1.1の開発環境を4分03秒で作成してくれるツールを作りました。
■作った背景
開発環境の構築ってめんどくさくないですか?
せっかくprogateやドットインストールで毎日仕事終わりにコツコツ勉強しても、いざ何か作ろうってなった時にまず環境構築でつまづきます。せっかく身に着けたコーディング力も生かす場がなけらば何の意味もありません。ガシガシ開発をしたいのに出鼻をくじかれる気持ち、とてもわかります。
■事前準備
$ sudo apt-get update && sudo apt-get upgrade -y
//自動化用のシェルスクリプトをペーストします。
$ vi hyperledger_auto.sh
hyperledger_auto.shにペーストするscript実行
echo
echo ///////////////////////////////////////////////////////////////
echo ///////////////HyperLedger fabric install START////////////////
echo ///////////////////////////////////////////////////////////////
echo
cd /home/ubuntu
sudo apt install docker-compose curl git vim -y
echo
echo ///////////////////////////////////////////////////////////////
echo ////////////////////go lang install START/////////////////////
echo ///////////////////////////////////////////////////////////////
echo
wget https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz &&
sudo tar -C /usr/local -xzf go1.8.3.linux-amd64.tar.gz &&
rm go1.8.3.linux-amd64.tar.gz &&
echo 'export PATH=$PATH:/usr/local/go/bin' | sudo tee -a /etc/profile &&
echo 'export GOPATH=$HOME/go' | tee -a $HOME/.bashrc &&
echo 'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' | tee -a $HOME/.bashrc &&
mkdir -p $HOME/go/{src,pkg,bin}
echo
echo ///////////////////////////////////////////////////////////////
echo ////////////////////go lang install END/////////////////////
echo ///////////////////////////////////////////////////////////////
echo
echo
echo ///////////////////////////////////////////////////////////////
echo ////////////////////nodejs install START/////////////////////
echo ///////////////////////////////////////////////////////////////
echo
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
echo
echo ///////////////////////////////////////////////////////////////
echo ////////////////////nodejs install END/////////////////////
echo ///////////////////////////////////////////////////////////////
echo
echo
echo ///////////////////////////////////////////////////////////////
echo ///////linux distribution developers tool install START////////
echo ///////////////////////////////////////////////////////////////
echo
sudo apt-get install -y build-essential git
sudo apt-get install -y jq git
echo
echo ///////////////////////////////////////////////////////////////
echo ///////linux distribution developers tool install END////////
echo ///////////////////////////////////////////////////////////////
echo
echo
echo ///////////////////////////////////////////////////////////////
echo ////////////////////docker install START/////////////////////
echo ///////////////////////////////////////////////////////////////
echo
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get -y install docker-ce
sudo adduser ubuntu docker
groups
lynlea adm cdrom sudo dip plugdev lpadmin sambashare docker
echo
echo ///////////////////////////////////////////////////////////////
echo ////////////////////docker install END/////////////////////////
echo ///////////////////////////////////////////////////////////////
echo
echo
echo ///////////////////////////////////////////////////////////////
echo ///////////////HyperLedger fabric install END////////////////
echo ///////////////////////////////////////////////////////////////
echo
echo
echo ///////////////////////////////////////////////////////////////
echo //////////////////////////Reboot!///////////////////////////////
echo ///////////////////////////////////////////////////////////////
echo
sudo reboot
■実行
//実行権限をhyperledger_auto.shにあげましょう。
$ sudo chmod 777 hyperledger_auto.sh
//実行
$ ./hyperledger_auto.sh
1分秒待ちましょう!OSがシャットダウンされるはずです。
(dockerはインストールされた後、再起動しないと設定が反映されません。)
実行後
あとは以下のコマンドを流して終了です。お疲れさまでした。
これが3分くらいかかります。
cd /home/ubuntu
sudo curl -sSL https://goo.gl/6wtTN5 | bash -s 1.1.0
■動作確認
きちんと構築できているか確認してみましょう。
//対象ディレクトリに移動
$ cd /home/ubuntu/fabric-samples/first-network
//Genesis blockの生成
$ ./byfn.sh -m generate
Generating certs and genesis block for with channel 'mychannel' and CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
/home/ubuntu/fabric-samples/first-network/../bin/cryptogen
##########################################################
Generate certificates using cryptogen tool
##########################################################
- cryptogen generate --config=./crypto-config.yaml
org1.example.com
org2.example.com - res=0
- set +x
/home/ubuntu/fabric-samples/first-network/../bin/configtxgen
##########################################################
######### Generating Orderer Genesis block ##############
##########################################################
- configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
2018-05-16 10:11:17.576 JST [common/tools/configtxgen] main -> INFO 001 Loading configuration
2018-05-16 10:11:17.587 JST [msp] getMspConfig -> INFO 002 Loading NodeOUs
2018-05-16 10:11:17.588 JST [msp] getMspConfig -> INFO 003 Loading NodeOUs
2018-05-16 10:11:17.588 JST [common/tools/configtxgen] doOutputBlock -> INFO 004 Generating genesis block
2018-05-16 10:11:17.588 JST [common/tools/configtxgen] doOutputBlock -> INFO 005 Writing genesis block - res=0
- set +x
#################################################################
Generating channel configuration transaction 'channel.tx'
#################################################################
- configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
2018-05-16 10:11:17.612 JST [common/tools/configtxgen] main -> INFO 001 Loading configuration
2018-05-16 10:11:17.622 JST [common/tools/configtxgen] doOutputChannelCreateTx -> INFO 002 Generating new channel configtx
2018-05-16 10:11:17.622 JST [msp] getMspConfig -> INFO 003 Loading NodeOUs
2018-05-16 10:11:17.623 JST [msp] getMspConfig -> INFO 004 Loading NodeOUs
2018-05-16 10:11:17.649 JST [common/tools/configtxgen] doOutputChannelCreateTx -> INFO 005 Writing new channel tx - res=0
- set +x
#################################################################
####### Generating anchor peer update for Org1MSP ##########
#################################################################
- configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
2018-05-16 10:11:17.671 JST [common/tools/configtxgen] main -> INFO 001 Loading configuration
2018-05-16 10:11:17.680 JST [common/tools/configtxgen] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2018-05-16 10:11:17.680 JST [common/tools/configtxgen] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update - res=0
- set +x
#################################################################
####### Generating anchor peer update for Org2MSP ##########
#################################################################
- configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
2018-05-16 10:11:17.701 JST [common/tools/configtxgen] main -> INFO 001 Loading configuration
2018-05-16 10:11:17.709 JST [common/tools/configtxgen] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2018-05-16 10:11:17.709 JST [common/tools/configtxgen] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update - res=0
- set +x
//networkの起動
$ ./byfn.sh -m up
Starting with channel 'mychannel' and CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
2018-05-16 01:12:39.726 UTC [main] main -> INFO 001 Exiting.....
LOCAL_VERSION=1.1.0
DOCKER_IMAGE_VERSION=1.1.0
Creating network "net_byfn" with the default driver
Creating volume "net_peer0.org2.example.com" with default driver
Creating volume "net_peer1.org2.example.com" with default driver
Creating volume "net_peer1.org1.example.com" with default driver
Creating volume "net_peer0.org1.example.com" with default driver
Creating volume "net_orderer.example.com" with default driver
Creating orderer.example.com
Creating peer1.org1.example.com
Creating peer1.org2.example.com
Creating peer0.org1.example.com
Creating peer0.org2.example.com
Creating cli
/ | | | / \ | _ \ | |
_ \ | | / _ \ | |) | | |
) | | | / ___ \ | _ < | |
|____/ || // _\ || _\ |_|
Build your first network (BYFN) end-to-end test
省略
2018-05-16 01:13:32.711 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2018-05-16 01:13:32.711 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
Query Result: 90
2018-05-16 01:13:43.655 UTC [main] main -> INFO 003 Exiting.....
===================== Query on peer1.org2 on channel 'mychannel' is successful =====================
========= All GOOD, BYFN execution completed ===========
| ____| | \ | | | _ \
| | | | | | | | |
| |__ | |\ | | || |
|_____| || _| |____/
上手くいってるようですね。ノードが起動できるか確認してみましょう。hyperledger fabricのノードはdockerで立ち上がるのでdockerコマンドをたたきます。
//立ち上がっているノードを確認します。
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c78374369c53 dev-peer1.org2.example.com-mycc-1.0-26c2ef32838554aac4f7ad6f100aca865e87959c9a126e86d764c8d01f8346ab "chaincode -peer.add…" About a minute ago Up About a minute dev-peer1.org2.example.com-mycc-1.0
a667f3967c0c dev-peer0.org1.example.com-mycc-1.0-384f11f484b9302df90b453200cfb25174305fce8f53f4e94d45ee3b6cab0ce9 "chaincode -peer.add…" About a minute ago Up About a minute dev-peer0.org1.example.com-mycc-1.0
3512778a4f01 dev-peer0.org2.example.com-mycc-1.0-15b571b3ce849066b7ec74497da3b27e54e0df1345daff3951b94245ce09c42b "chaincode -peer.add…" About a minute ago Up About a minute dev-peer0.org2.example.com-mycc-1.0
52d3c214beb0 hyperledger/fabric-tools:latest "/bin/bash" 2 minutes ago Up 2 minutes cli
2519d419927f hyperledger/fabric-peer:latest "peer node start" 2 minutes ago Up 2 minutes 0.0.0.0:9051->7051/tcp, 0.0.0.0:9053->7053/tcp peer0.org2.example.com
436148c66f0e hyperledger/fabric-peer:latest "peer node start" 2 minutes ago Up 2 minutes 0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp peer0.org1.example.com
fe6a601d2772 hyperledger/fabric-peer:latest "peer node start" 2 minutes ago Up 2 minutes 0.0.0.0:10051->7051/tcp, 0.0.0.0:10053->7053/tcp peer1.org2.example.com
e0d7271de7ef hyperledger/fabric-peer:latest "peer node start" 2 minutes ago Up 2 minutes 0.0.0.0:8051->7051/tcp, 0.0.0.0:8053->7053/tcp peer1.org1.example.com
917cd5be6272 hyperledger/fabric-orderer:latest "orderer" 2 minutes ago Up 2 minutes 0.0.0.0:7050->7050/tcp orderer.example.com
立ち上がっていることを確認できました。最後にnetworkを落としましょう。
$ ./byfn.sh -m down
Stopping with channel 'mychannel' and CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] y
proceeding ...
Stopping cli ... done
Stopping peer0.org2.example.com ... done
Stopping peer0.org1.example.com ... done
Stopping peer1.org2.example.com ... done
Stopping peer1.org1.example.com ... done
Stopping orderer.example.com ... done
Removing cli ... done
Removing peer0.org2.example.com ... done
Removing peer0.org1.example.com ... done
Removing peer1.org2.example.com ... done
Removing peer1.org1.example.com ... done
Removing orderer.example.com ... done
Removing network net_byfn
Removing volume net_peer0.org2.example.com
Removing volume net_peer1.org2.example.com
Removing volume net_peer1.org1.example.com
Removing volume net_peer0.org1.example.com
Removing volume net_orderer.example.com
Removing network net_byfn
WARNING: Network net_byfn not found.
Removing volume net_peer0.org2.example.com
WARNING: Volume net_peer0.org2.example.com not found.
Removing volume net_peer1.org2.example.com
WARNING: Volume net_peer1.org2.example.com not found.
Removing volume net_peer1.org1.example.com
WARNING: Volume net_peer1.org1.example.com not found.
Removing volume net_peer0.org1.example.com
WARNING: Volume net_peer0.org1.example.com not found.
Removing volume net_orderer.example.com
WARNING: Volume net_orderer.example.com not found.
c78374369c53
a667f3967c0c
3512778a4f01
Untagged: dev-peer1.org2.example.com-mycc-1.0-26c2ef32838554aac4f7ad6f100aca865e87959c9a126e86d764c8d01f8346ab:latest
Deleted: sha256:66bc44b9143b01103b4fa1b35e05a8f7375b62303c94194532077a47da6b42f0
Deleted: sha256:00748e1607f91b775d8817e52795799c1675d49f66f26540ed3cd7a70bc987aa
Deleted: sha256:5e591c8ec44b1b085f6f1ccb64ee6c235c1ffdd433be383fed75780ede31224c
Deleted: sha256:f8b07739a104d410b10ee0bd86a445033926cd9662b125a58c5ec3b42871e969
Untagged: dev-peer0.org1.example.com-mycc-1.0-384f11f484b9302df90b453200cfb25174305fce8f53f4e94d45ee3b6cab0ce9:latest
Deleted: sha256:a80d88e3fd2e1620e236437cd1267fa4e7285072585a42e2b93b9189f1407578
Deleted: sha256:7781ec109c9e98868bcddc8b01ab957c2fba786e859db3da74579ce7fc111461
Deleted: sha256:5866eb4381a2493698a3caaeaec5f8dd7d1bcb4fa0454e7f82dc858464819089
Deleted: sha256:bd8dd3456fc8053734a77875c90cccae71698bddc13094eb8df049165caecab0
Untagged: dev-peer0.org2.example.com-mycc-1.0-15b571b3ce849066b7ec74497da3b27e54e0df1345daff3951b94245ce09c42b:latest
Deleted: sha256:eda7f93953e3a3e5a213a61bfef81e6fb71455e4e5dca1af301f063db8293cbc
Deleted: sha256:5debe1af3a3535a0a0e49a52d0605420e780a0c8f065717c08a128865180efca
Deleted: sha256:6f1cc08e726bcaa7bb5bb34328cd938a3256d475bcb4e0b1a0481800917dc976
Deleted: sha256:76db157676f84ce303c00eb02205b42c6d68e3deb6b8876c6e48ab4f7c23cffc
再度ノードを確認してみます。
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
何も立ち上がっていないことを確認出来ました。