HyperLedger Fabric 1.0 Alpha版 单节点部署初探

HyperLedger Fabric 1.0的Alpha版本已经于2017年3月中旬正式发布,其官方Docker镜像版本也已经发出。具体地址为[1]。

这样,我们就可以通过拉取镜像的方式,从官网直接拉取镜像进行部署。

我们可能用到的镜像包括:
 - hyperledger/fabric-orderer:x86_64-1.0.0-alpha
 - hyperledger/fabric-peer:x86_64-1.0.0-alpha
 - hyperledger/fabric-javaenv:x86_64-1.0.0-alpha
 - hyperledger/fabric-ccenv:x86_64-1.0.0-alpha
 - hyperledger/fabric-couchdb:x86_64-1.0.0-alpha
 - hyperledger/fabric-zookeeper:x86_64-1.0.0-alpha
 - hyperledger/fabric-kafka:x86_64-1.0.0-alpha
 - hyperledger/fabric-ca:x86_64-1.0.0-alpha

#1. 镜像拉取#
对于每一个镜像,我们可以通过执行下面的指令进行拉取。
```
docker pull
```
像这种一下拉取很多镜像的情况,我们也可以写成一个脚本`fabric-pull.sh`:
```shell
docker pull hyperledger/fabric-orderer:x86_64-1.0.0-alpha
docker pull hyperledger/fabric-peer:x86_64-1.0.0-alpha
docker pull hyperledger/fabric-javaenv:x86_64-1.0.0-alpha
docker pull hyperledger/fabric-ccenv:x86_64-1.0.0-alpha
docker pull hyperledger/fabric-couchdb:x86_64-1.0.0-alpha
docker pull hyperledger/fabric-zookeeper:x86_64-1.0.0-alpha
docker pull hyperledger/fabric-kafka:x86_64-1.0.0-alpha
docker pull hyperledger/fabric-ca:x86_64-1.0.0-alpha
```

由于网络不稳定的原因,可能在某个镜像拉取过程中会出现连接失败的情况。多执行几次脚本,问题可能就会解决。

拉取完成后,可以通过`docker images`命令查看拉取结果:

![Paste_Image.png](http://upload-images.jianshu.io/upload_images/4853512-640ab21f605d906d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

可以看到所有的镜像TAG都是x86_64-1.0.0-alpha,至此,镜像拉取成功。

#2. 编写Docker-Compose文件#
接下来,我们利用docker-compose来部署网络。这里我参照了杨博士的最小网络启动docker-compose文件[2]。

并相应针对当前版本修改了其中的一些内容,主要是将ca的启动部分做了一下修改,参考官方ca说明文档中的docker启动方法[3]。
docker-compose.yaml
```yaml

# This compose file will start a Hyperledger Fabric 1.0 MVE, including
# * ca
# * orderer
# * peer
# * sdk for testing

version: '2.0'
services:
  ca:
    image: hyperledger/fabric-ca:x86_64-1.0.0-alpha
    container_name: fabric-ca-server
    ports:
      - "7054:7054"
    environment:
      - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
    volumes:
      - "./fabric-ca-server:/etc/hyperledger/fabric-ca-server"
    command: sh -c 'fabric-ca-server start -b admin:adminpw'

  orderer:
    image: hyperledger/fabric-orderer:x86_64-1.0.0-alpha
    container_name: fabric-orderer
    hostname: orderer
    environment:
        - ORDERER_GENERAL_LEDGERTYPE=ram
        - ORDERER_GENERAL_BATCHTIMEOUT=10s
        - ORDERER_GENERAL_MAXMESSAGECOUNT=10
        - ORDERER_GENERAL_MAXWINDOWSIZE=1000
        - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
        - ORDERER_GENERAL_LISTENPORT=7050
        - ORDERER_RAMLEDGER_HISTORY_SIZE=100
        - CONFIGTX_ORDERER_ORDERERTYPE=solo
    ports:
      - "7050:7050"
    command: orderer

  peer0:
    extends:
      file: peer.yml
      service: peer
    container_name: fabric-peer0
    hostname: peer0
    environment:
      - CORE_PEER_ID=peer0
      - CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050
    links:
      - ca
      - orderer
    ports:
      - 7051:7051
    depends_on:
      - ca
      - orderer
```
peer.yaml
```

# Depends on the hyperledger/fabric-peer image.

version: '2'

services:
  peer:
    image: hyperledger/fabric-peer:x86_64-1.0.0-alpha
    environment:
      #- CORE_PEER_ID=peer0
      - CORE_PEER_ADDRESSAUTODETECT=true
      - CORE_LOGGING_LEVEL=INFO
     #- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=hyperledger_fabric  # uncomment this to use specific network
     #- CORE_PEER_NETWORKID=dev
      - CORE_NEXT=true
      - CORE_PEER_ENDORSER_ENABLED=true
      - CORE_PEER_COMMITTER_ENABLED=true
      - CORE_PEER_PROFILE_ENABLED=false
      - CORE_PEER_GOSSIP_ORGLEADER=true
      - CORE_PEER_GOSSIP_IGNORESECURITY=true
      #- CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050
    expose:
      - "7050"  # Rest
      - "7051"  # Grpc
      - "7052"  # Peer CLI
      - "7053"  # Peer Event
      - "7054"  # eCAP
      - "7055"  # eCAA
      - "7056"  # tCAP
      - "7057"  # eCAA
      - "7058"  # tlsCAP
      - "7059"  # tlsCAA
    volumes: # docker.sock is mapped as the default CORE_VM_ENDPOINT
      - /var/run/docker.sock:/var/run/docker.sock
    #volumes:
    #    - /var/run/:/host/var/run/
    command: peer node start

```
#3. 执行部署#
最后,我们将这两个yaml文件放在一起,执行:
```
docker-compose up
```

![Paste_Image.png](http://upload-images.jianshu.io/upload_images/4853512-844b250377621bc3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

 当然,也可以在后台启动,不在前端显示log:
```
docker-compose up -d
```

然后通过`docker ps`查看容器启动状态:
![Paste_Image.png](http://upload-images.jianshu.io/upload_images/4853512-b1f4ab64cfe9307b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

至此,HyperLedger Fabric 1.0 Alpha版单节点部署成功。

#References
[1] https://hub.docker.com/u/hyperledger/
[2] https://github.com/yeasy/docker-compose-files
[3] https://github.com/hyperledger/fabric/blob/master/docs/source/Setup/ca-setup.rst

你可能感兴趣的:(分布式,区块链)