Hyperledger Fabric 開發和運行環境搭建
一 環境配置
VirtualBox 5.1.12
Git 2.18.0
Go 1.10.3
Windows下設置GOPATH開發目錄
Vagrant 2.1.2
進入BIOS設置Virtuallization為enable
二 Fabric開發環境搭建
1 配置Git
git config --get core.autocrlf
git config --global core.autocrlf false
2 建立開發目錄
cd $GOPATH
mkdir -p src/github.com/hyperledger
3 下載fabric項目
git clone https://github.com/hyperledger/fabric.git
4 切換至v1.0.0版本
cd fabric
git checkout v1.0.0
5 拷貝virtualbox.box至devenv,並添加到box list
vagrant box add hyperledger virtualbox.box
6 移除devenv下Vagrantfile文件,並初始化box
vagrant init hyperledger
7 啟動vagrant(可在Vagrantfile添加box.name)
vagrant up
8 關閉virtualbox中虛擬機,並替換回原本的Vagrantfile
要指定的Vagrantfile,不然會少掉fabric層
9 連接virtualbox虛擬機
vagrant ssh
10 Xshell登錄
Address:127.0.0.1:2222
Username:vagrant
Password:vagrant
11 Go安裝
下載Go:wget https://storage.googleapis.com/golang/go1.9.linux-amd64.tar.gz
添加到/usr/local路徑:tar -C /usr/local -xzf go1.9.linux-amd64.tar.gz
配置go環境變量:vim ~/.bashrc
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=/opt/gopath
保存bashrc修改:source ~/.bashrc
12 Docker-Compose 安裝
curl -L https://get.daocloud.io/docker/compose/releases/download/1.12.0/docker-compose-`uname -s`-`uname -m` > ~/docker-compose
mv ~/docker-compose /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
三 Fabric運行環境搭建
1 把root用戶添加到docker
usermod -aG docker root
2 新建docker目錄
mkdir -p /etc/docker
3 添加阿裏雲Docker Hub鏡像
tee /etc/docker/daemon.json <<-‘EOF‘
{
"registry-mirrors": ["https://obou6wyb.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker
4 下載e2e_cli的Docker鏡像
cd /opt/gopath/src/github.com/hyperledger/fabric/examples/e2e_cli/
source download-dockerimages.sh -c x86_64-1.0.0 -f x86_64-1.0.0
5 啟動e2e_cli項目
./network_setup.sh up
6 測試e2e_cli項目
切換到root權限:sudo su
進入CLI:docker exec -it cli bash
1) 查詢a賬戶余額:
peer chaincode query -C mychannel -n mycc -c ‘{"Args":["query","a"]}‘
2) a賬戶向b賬戶轉賬20
peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -c ‘{"Args":["invoke","a","b","20"]}‘
3) 再次查詢a賬戶
peer chaincode query -C mychannel -n mycc -c ‘{"Args":["query","a"]}‘
Hyperledger Fabric 開發和運行環境搭建