Fabric v1.1

1.環境安裝

1).安裝go 1.9.x
下載地址
http://golang.org/dl/

配置環境

#go的安裝根目錄
export GOROOT=/usr/local/go
#go的工作路徑根目錄
export GOPATH=/opt/goroot

2).安裝docker 17.06.2-ce or greater
官網https://docs.docker.com/install/linux/docker-ce/centos/#set-up-the-repository
解除安裝原來的版本

sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine

安裝依賴包
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2

設定穩定庫

sudo yum-config-manager \
–add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
安裝docker-ce
sudo yum install docker-ce

如果需要某個特定版本,安裝如下:
列出所有可安裝的版本

yum list docker-ce –showduplicates | sort -r

安裝

sudo yum install docker-ce-
v1.1需要 docker-ce-17.09.1.ce或更高版本
sudo yum install docker-ce-17.09.1.ce

啟動 docker

systemctl start docker

設定docker 開機自啟

chkconfig docker on

啟動docker,錯誤解決

docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: failed (Result: start-limit) since Wed 2018-07-18 04:12:40 EDT; 15s ago
Docs: https://docs.docker.com
Process: 7850 ExecStart=/usr/bin/dockerd (code=exited, status=1/FAILURE)
Main PID: 7850 (code=exited, status=1/FAILURE)

Jul 18 04:12:40 vmnode1 systemd[1]: Failed to start Docker Application Container Engine.
Jul 18 04:12:40 vmnode1 systemd[1]: Unit docker.service entered failed state.
Jul 18 04:12:40 vmnode1 systemd[1]: docker.service failed.
Jul 18 04:12:40 vmnode1 systemd[1]: docker.service holdoff time over, scheduling restart.
Jul 18 04:12:40 vmnode1 systemd[1]: start request repeated too quickly for docker.service
Jul 18 04:12:40 vmnode1 systemd[1]: Failed to start Docker Application Container Engine.
Jul 18 04:12:40 vmnode1 systemd[1]: Unit docker.service entered failed state.
Jul 18 04:12:40 vmnode1 systemd[1]: docker.service failed.

解決方法

vim /etc/docker/daemon.json
{
“graph”: “/mnt/docker-data”,
“storage-driver”: “overlay”
}
systemctl restart docker

3).安裝docker-compose

curl -L https://github.com/docker/compose/releases/download/1.15.0/docker-compose-uname -s-uname -m > >/usr/local/bin/docker-composechmod +x /usr/local/bin/docker-compose

cp /usr/local/bin/docker-compose /usr/bin

2.Fabric原始碼及映象檔案

1).下載Fabric原始碼 v1.1

mkdir -p /opt/goroot/src/github.com/hyperledger/
cd /opt/goroot/src/github.com/hyperledger/
git clone -b v1.1.0 http://github.com/hyperledger/fabric
#切換分支到1.1版本
git checkout -b v1.1

2).下載相應的二進位制檔案和映象檔案

cd scripts
修改bootstrap.sh如下:
export VERSION=${1:-1.1.0}
export THIRDPARTY_IMAGE_VERSION=1.1.0
執行bootstrap.sh
./bootstrap.sh
執行這步得到以下映象
REPOSITORY TAG
hyperledger/fabric-ca latest
hyperledger/fabric-ca x86_64-1.1.0
hyperledger/fabric-tools latest
hyperledger/fabric-tools x86_64-1.1.0
hyperledger/fabric-orderer latest
hyperledger/fabric-orderer x86_64-1.1.0
hyperledger/fabric-peer latest
hyperledger/fabric-peer x86_64-1.1.0
hyperledger/fabric-javaenv latest
hyperledger/fabric-javaenv x86_64-1.1.0
hyperledger/fabric-ccenv latest
hyperledger/fabric-ccenv x86_64-1.1.0
hyperledger/fabric-zookeeper latest
hyperledger/fabric-kafka latest
hyperledger/fabric-couchdb latest

並且在當前目前下會得到/bin檔案下

configtxgen configtxlator cryptogen fabric-ca-client get-byfn.sh get-docker-images.sh orderer peer

e2e_cli的例子中需要把bin檔案放到/fabric/release/linux-amd64/ 目錄下

3.啟動例子中的e2e_cli測試環境

cd examples/e2e_cli

修改base下的peer-base.yaml

- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=e2e_cli_default
**這裡CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE的設定為 當前資料夾名稱_default

bash network_setup.sh up

1.e2e_cli啟動過程中出現:Error: Error endorsing chaincode: rpc error: code = Unknown desc = timeout expired while starting chaincode fabcar1.刪除所有執行的容器#關掉所有容器

docker stop $(docker ps -a -q)

刪除所有容器

docker rm $(docker ps -a -q)

2.刪除紅框中的容器docker rmi IMAGEID2.e2e_cli啟動中出現:ERROR:Encountered errors while bringing up the projectERROR!!!Unable to pull the images刪除所有執行的容器#關掉所有容器

docker stop $(docker ps -a -q)

刪除所有容器

docker rm $(docker ps -a -q)

3.e2e_cli啟動中出現:Error: Error endorsing chaincode: rpc error: code = Unknown desc = Error starting container: API error (404): {“message”:”network e2ecli_default not found”}

進入目錄

cd /opt/goroot/src/github.com/hyperledger/fabric/example/e2e_cli
修改./e2e_cli/base/下的 peer-base.yaml
修改下面一行就行了
CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=e2e_cli_default

4.e2e_cli啟動中出現:CRIT 004 Error on outputBlock:Error writing genesis block:open ./channel-artifacts/get:is a directory

原因是沒有正確生成genesis.block 所以docker在掛載檔案時,會自動生成一個genesis.block檔案
直接刪除e2e_cli下的channel-artifacts裡的genesis.block,重新生成這個檔案

5.Docker掛載主機目錄,訪問相應的檔案出現Premission denied的許可權

在主機中修改/soft目錄的安全性文件,假設要掛載的檔案是/soft

chcon -Rt svirt_sandbox_file_t /soft

注意:每次重新執行bash network_setup.sh up 前
需要做以下幾句
刪除所有容器刪除常見問題1中的三個映象
刪除e2e_cli下的crypto-config
刪除e2e_cli下的channel-artifacts裡的所有檔案