HyperLedger Cello学习笔记

HyperLedger Cello学习笔记

转载请注明出处:HyperLedger Cello学习笔记

概述

Hyperledger Cello是Hyperledger下的一个子项目,其主要功能如下:

  1. 管理区块链的生命周期,例如自动创建/启动/停止/删除/保持健康状态。
  2. 支持定制化的区块链实例,包括区块链类型,大小,共识机制等,当前主要支持的是fabric。
  3. 支持虚拟机,本地Docker主机,swarm集群或Kubernetes作为工作节点。
  4. 支持异构体系结构,例如X86,POWER和Z,从裸机服务器到虚拟机云。
  5. 通过采用附加组件,扩展监控,日志,运行状况和分析功能。

架构图

HyperLedger Cello学习笔记_第1张图片

Master节点上的服务有:普通用户控制台、操控者控制台、监控、容器编排引擎、日志管理模块、健康检查模块。

HyperLedger Cello学习笔记_第2张图片
Cello采取了一主多从的部署模式,Cello Service部署在Master节点上,提供宿主资源的裸机或虚拟环境称为Host,被Cello管理的区块链服务单元称为Worker。整套环境部署要求至少一个Master与一个Worker。

Cello部署

环境要求:
docker : 17.0+
docker-compose: 1.8.0~1.12.0

安装Master Node

  1. 获取源码
//获取源码
[centos@baas src]$ git clone -b v0.9.0 https://github.com/hyperledger/cello.git && cd cello
  1. 初始化 Masetr node
[centos@baas cello]$ cd cello/scripts/master_node/
[centos@baas cello]$ VERSION=0.9.0 bash setup.sh

此过程将会安装docker及docker-compose,还会下载相关镜像。

[centos@baas cello]$ docker images
REPOSITORY                             TAG                             IMAGE ID            CREATED             SIZE
hyperledger/cello-watchdog             latest                          a8d77975c69e        10 days ago         1.04GB
hyperledger/cello-watchdog             x86_64-v0.9.0                   a8d77975c69e        10 days ago         1.04GB
hyperledger/cello-mongo                latest                          06cf2b88461a        10 days ago         1.04GB
hyperledger/cello-mongo                x86_64-0.9.0-snapshot-b6a340d   06cf2b88461a        10 days ago         1.04GB
hyperledger/cello-baseimage            x86_64-0.9.0-snapshot-b6a340d   3bdf82ef579a        10 days ago         1.04GB
rabbitmq                               latest                          5cb7660e7cfe        11 days ago         164MB
hyperledger/cello-operator-dashboard   latest                          296a1e79edb9        12 days ago         1.04GB
hyperledger/cello-operator-dashboard   x86_64-v0.9.0                   296a1e79edb9        12 days ago         1.04GB
hyperledger/cello-engine               latest                          ce8908b6719c        12 days ago         1.04GB
hyperledger/cello-engine               x86_64-v0.9.0                   ce8908b6719c        12 days ago         1.04GB
hyperledger/cello-baseimage            latest                          a81a9fc8f1bd        2 weeks ago         1.04GB
hyperledger/cello-baseimage            x86_64-0.9.0                    a81a9fc8f1bd        2 weeks ago         1.04GB
hyperledger/cello-user-dashboard       latest                          c09f0cd2edca        2 months ago        2.12GB
hyperledger/cello-user-dashboard       x86_64-v0.9.0                   c09f0cd2edca        2 months ago        2.12GB
itsthenetwork/nfs-server-alpine        9                               30f582fb8f6e        12 months ago       51.9MB
mongo                                  3.4.10                          e905a87e116d        17 months ago       360MB
node                                   9.2                             cb4c45f7a9e3        17 months ago       676MB
  1. 修改准备的文件

    #cryptogen、configtxgen 这两个可执行文件,需要去对应的fabric源码中去编译
    
    源码地址: https://github.com/hyperledger/fabric.git
    
    # 编译命令
    # cd github.com/hyperledger/fabric 
    # make cryptogen
    # make configtxgen
    # 将会在 github.com/hyperledger/fabric/build/bin/ 目录下生成对应的文件
    # 证书需要重新生成,官方给的证书无法使用。  crypto-config.yaml
    # 生成证书命令:  cryptogen generate --config=./crypto-config.yaml
    # 下面是crypto-config.yaml文件内容
    OrdererOrgs:
      - Name: Orderer
        Domain: example.com
        Specs:
          - Hostname: orderer
    PeerOrgs:
      - Name: Org1
        Domain: org1.example.com
        Template:
       Count: 2
        Users:
          Count: 1
      - Name: Org2
        Domain: org2.example.com
        Template:
          Count: 2
        Users:
          Count: 1
# 重新生成创始块及其初始化相关的文件
[centos@baas cello]$ cd src/agent/docker/_compose_files/fabric-1.0/kafka
[centos@baas kafka]$ ln -s ../crypto-config ./crypto-config
# 重新生成channel-artifacts下的文件
$ configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/orderer.genesis.block
$ configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/new_businesschannel.tx -channelID businesschannel
$ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID businesschannel -asOrg Org1MSP
$ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID businesschannel -asOrg Org2MSP

修改docker-compose.yaml文件

operator-dashboard:
    image: hyperledger/cello-operator-dashboard
    container_name: cello-operator-dashboard
    hostname: cello-operator-dashboard
    restart: unless-stopped
    environment:
      - MONGO_URL=mongodb://cello-mongo:27017  
      - MONGO_HOST=mongo
      - MONGO_DB=dev
      - EXPLORER_PORT=8088   # 新增浏览器端口配置
      - MONGODB_PORT=27017
      - DEBUG=False  
      - LOG_LEVEL=DEBUG   # 修改日志等级为DEBUG
      - STATIC_FOLDER=$STATIC_FOLDER
      - TEMPLATE_FOLDER=$TEMPLATE_FOLDER
      - ENABLE_EMAIL_ACTIVE=$ENABLE_EMAIL_ACTIVE
      - BROKER=amqp://$RABBITMQ_DEFAULT_USER:$RABBITMQ_DEFAULT_PASS@rabbitmq:5672/$RABBITMQ_DEFAULT_VHOST
      - BACKEND=amqp://$RABBITMQ_DEFAULT_USER:$RABBITMQ_DEFAULT_PASS@rabbitmq:5672/$RABBITMQ_DEFAULT_VHOST
    ports:
      - "8080:8080"
    volumes:
      - $ROOT_PATH/src/agent/docker/_compose_files:/app/agent/docker/_compose_files/  # 新增映射目录
      - $ROOT_PATH/src/agent/docker/_compose_files:/cello

修改fabric-kafka-4.yaml文件

# 修改peer环境变量
- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=cello_net_kafka
# 修改cli的command
command: bash -c 'sleep 15; cd /tmp; source scripts/func.sh; bash scripts/test_channel_create.sh; bash scripts/test_channel_join.sh; bash scripts/test_cc_install.sh; bash scripts/test_cc_instantiate.sh ; while true; do sleep 20180101; done'
# 若是在阿里云上部署,需要在的环境变量里添加
- GODEBUG=netdns=go

# 指定容器网络
networks:
  default:
    external:
      name: cello_net_kafka
  1. 启动Master节点
[centos@baas cello]$ make start
//将会启动master节点上的服务
[centos@raft-test--3 cello]$ docker ps
CONTAINER ID        IMAGE                                  COMMAND                  CREATED             STATUS              PORTS                                    NAMES
9f9b9abf94a8        hyperledger/cello-user-dashboard       "/bin/sh -c 'ln -sf …"   8 minutes ago       Up 8 minutes        0.0.0.0:8081->8081/tcp                   cello-user-dashboard
1ad2eca89aaa        mongo:3.4.10                           "docker-entrypoint.s…"   8 minutes ago       Up 8 minutes        27017/tcp                                cello-dashboard_mongo
30c61b815fae        rabbitmq                               "docker-entrypoint.s…"   8 minutes ago       Up 8 minutes        4369/tcp, 5671-5672/tcp, 25672/tcp       cello-dashboard_rabbitmq
beb6bbe7d177        hyperledger/cello-engine               "python restserver.py"   8 minutes ago       Up 8 minutes        0.0.0.0:80->80/tcp                       cello-engine
aa011f819b7d        hyperledger/cello-watchdog             "python watchdog.py"     8 minutes ago       Up 8 minutes                                                 cello-watchdog
9c34f967b9c1        mongo:3.4.10                           "docker-entrypoint.s…"   8 minutes ago       Up 8 minutes        127.0.0.1:27017-27018->27017-27018/tcp   cello-mongo
8ae375ce7593        hyperledger/cello-operator-dashboard   "/bin/sh -c '/etc/in…"   8 minutes ago       Up 8 minutes        0.0.0.0:8080->8080/tcp                   cello-operator-dashboard
b102d502edd2        itsthenetwork/nfs-server-alpine:9      "/usr/bin/nfsd.sh"       3 days ago          Up 3 days           0.0.0.0:2049->2049/tcp                   cello-nfs

安装worker节点

  1. 获取源码
//获取源码
[centos@baas src]$ git clone -b v0.9.0 https://github.com/hyperledger/cello.git && cd cello
  1. 初始化 Worker node
[centos@baas cello]$ cd cello/scripts/worker_node/
[centos@baas cello]$ WORKER_TYPE=docker MASTER_NODE=x.x.x.x make setup-worker

此过程将会安装docker,还会下载fabric相关镜像,包括版本1.0、1.1、1.2。

[centos@baas cello]$ docker images
hyperledger/fabric-ca                                                                                   1.2.0               66cc132bd09c        10 months ago       252 MB
hyperledger/fabric-ca                                                                                   amd64-1.2.0         66cc132bd09c        10 months ago       252 MB
hyperledger/fabric-tools                                                                                1.2.0               379602873003        10 months ago       1.51 GB
hyperledger/fabric-tools                                                                                amd64-1.2.0         379602873003        10 months ago       1.51 GB
hyperledger/fabric-ccenv                                                                                amd64-1.2.0         6acf31e2d9a4        10 months ago       1.43 GB
hyperledger/fabric-orderer                                                                              1.2.0               4baf7789a8ec        10 months ago       152 MB
hyperledger/fabric-orderer                                                                              amd64-1.2.0         4baf7789a8ec        10 months ago       152 MB
hyperledger/fabric-peer                                                                                 1.2.0               82c262e65984        10 months ago       159 MB
hyperledger/fabric-peer                                                                                 amd64-1.2.0         82c262e65984        10 months ago       159 MB
hyperledger/fabric-zookeeper                                                                            1.2.0               2b51158f3898        11 months ago       1.44 GB
hyperledger/fabric-zookeeper                                                                            amd64-0.4.10        2b51158f3898        11 months ago       1.44 GB
hyperledger/fabric-kafka                                                                                1.2.0               936aef6db0e6        11 months ago       1.45 GB
hyperledger/fabric-kafka                                                                                amd64-0.4.10        936aef6db0e6        11 months ago       1.45 GB
hyperledger/fabric-couchdb                                                                              1.2.0               3092eca241fc        11 months ago       1.61 GB
hyperledger/fabric-couchdb                                                                              amd64-0.4.10        3092eca241fc        11 months ago       1.61 GB
hyperledger/fabric-baseimage                                                                            amd64-0.4.10        62513965e238        11 months ago       1.39 GB
hyperledger/fabric-baseos                                                                               amd64-0.4.10        52190e831002        11 months ago       132 MB
itsthenetwork/nfs-server-alpine                                                                         9                   30f582fb8f6e        12 months ago       51.9 MB
hyperledger/fabric-ca                                                                                   1.1.0               72617b4fa9b4        14 months ago       299 MB
hyperledger/fabric-ca                                                                                   x86_64-1.1.0        72617b4fa9b4        14 months ago       299 MB
hyperledger/fabric-tools                                                                                1.1.0               b7bfddf508bc        14 months ago       1.46 GB
hyperledger/fabric-tools                                                                                x86_64-1.1.0        b7bfddf508bc        14 months ago       1.46 GB
hyperledger/fabric-orderer                                                                              1.1.0               ce0c810df36a        14 months ago       180 MB
hyperledger/fabric-orderer                                                                              x86_64-1.1.0        ce0c810df36a        14 months ago       180 MB
hyperledger/fabric-peer                                                                                 1.1.0               b023f9be0771        14 months ago       187 MB
hyperledger/fabric-peer                                                                                 x86_64-1.1.0        b023f9be0771        14 months ago       187 MB
hyperledger/fabric-ccenv                                                                                x86_64-1.1.0        c8b4909d8d46        14 months ago       1.39 GB
hyperledger/fabric-baseimage                                                                            x86_64-0.4.6        dbe6787b5747        15 months ago       1.37 GB
hyperledger/fabric-zookeeper                                                                            1.1.0               92cbb952b6f8        15 months ago       1.39 GB
hyperledger/fabric-zookeeper                                                                            x86_64-0.4.6        92cbb952b6f8        15 months ago       1.39 GB
hyperledger/fabric-kafka                                                                                1.1.0               554c591b86a8        15 months ago       1.4 GB
hyperledger/fabric-kafka                                                                                x86_64-0.4.6        554c591b86a8        15 months ago       1.4 GB
hyperledger/fabric-couchdb                                                                              1.1.0               7e73c828fc5b        15 months ago       1.56 GB
hyperledger/fabric-couchdb                                                                              x86_64-0.4.6        7e73c828fc5b        15 months ago       1.56 GB
hyperledger/fabric-baseos                                                                               x86_64-0.4.6        220e5cf3fb7f        15 months ago       151 MB
yeasy/blockchain-explorer                                                                               0.1.0-preview       d3d781c8c96b        16 months ago       659 MB
hyperledger/fabric-tools                                                                                1.0.5               6a8993b718c8        17 months ago       1.33 GB
hyperledger/fabric-tools                                                                                x86_64-1.0.5        6a8993b718c8        17 months ago       1.33 GB
hyperledger/fabric-couchdb                                                                              1.0.5               9a58db2d2723        17 months ago       1.5 GB
hyperledger/fabric-couchdb                                                                              x86_64-1.0.5        9a58db2d2723        17 months ago       1.5 GB
hyperledger/fabric-kafka                                                                                1.0.5               b8c5172bb83c        17 months ago       1.29 GB
hyperledger/fabric-kafka                                                                                x86_64-1.0.5        b8c5172bb83c        17 months ago       1.29 GB
hyperledger/fabric-zookeeper                                                                            1.0.5               68945f4613fc        17 months ago       1.32 GB
hyperledger/fabric-zookeeper                                                                            x86_64-1.0.5        68945f4613fc        17 months ago       1.32 GB
hyperledger/fabric-orderer                                                                              1.0.5               368c78b6f03b        17 months ago       151 MB
hyperledger/fabric-orderer                                                                              x86_64-1.0.5        368c78b6f03b        17 months ago       151 MB
hyperledger/fabric-peer                                                                                 1.0.5               c2ab022f0bdb        17 months ago       154 MB
hyperledger/fabric-peer                                                                                 x86_64-1.0.5        c2ab022f0bdb        17 months ago       154 MB
hyperledger/fabric-ccenv                                                                                x86_64-1.0.5        33feadb8f7a6        17 months ago       1.28 GB
hyperledger/fabric-ca                                                                                   1.0.5               002c9089e464        17 months ago       238 MB
hyperledger/fabric-ca                                                                                   x86_64-1.0.5        002c9089e464        17 months ago       238 MB
hyperledger/fabric-baseimage                                                                            x86_64-0.3.2        c92d9fdee998        21 months ago       1.26 GB
hyperledger/fabric-baseos                                                                               x86_64-0.3.2        bbcbb9da2d83        21 months ago       129 MB
  1. 对docker进行设置
    使docker监听2375端口,并且确认master可以调用此接口。
//查看配置文件位于哪里
systemctl show --property=FragmentPath docker

//编辑配置文件内容,接收所有ip请求
sudo vim /usr/lib/systemd/system/docker.service

[Service]
ExecStart=/usr/bin/dockerd -H fd:// -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375 --default-ulimit=nofile=8192:16384 --default-ulimit=nproc=8192:16384
//使修改的配置生效
sudo systemctl daemon-reload; sudo systemctl restart docker.service
// 注意在云上开通此端口,易被在docker上部署挖矿软件,最好加上防火墙,仅允许master节点调用该端口。由于cello不支持TLS,所以安全性较低。

通过cello的web界面部署fabric

  1. 打开web界面,登录并添加worker主机,用户名: admin, 密码 pass
    HyperLedger Cello学习笔记_第3张图片
    添加成功后,即可在主机列表中看到该主机。
    HyperLedger Cello学习笔记_第4张图片
  2. 部署fabric
    HyperLedger Cello学习笔记_第5张图片
    在worker主机上,查看cli容器的日志,可以实时查看fabric部署进度。
[centos@baas cello]$ docker ps |grep cli
[centos@baas cello]$ docker logs -f xxxxxxx_cli
=== Creating channel businesschannel with new_businesschannel.tx... ===
=== Create Channel businesschannel by org 1/peer 0 ===
=== Channel businesschannel is created. ===
=== Created channel businesschannel with new_businesschannel.tx ===

=== Join peers 0 from org 1 into businesschannel... ===
=== Join org 1/peer 0 into channel businesschannel ===
=== org 1/peer 0 joined into channel businesschannel ===
=== Join org 1/peer 1 into channel businesschannel ===
=== org 1/peer 1 joined into channel businesschannel ===
=== Join org 2/peer 0 into channel businesschannel ===
=== org 2/peer 0 joined into channel businesschannel ===
=== Join org 2/peer 1 into channel businesschannel ===
=== org 2/peer 1 joined into channel businesschannel ===
=== Join peers 0 from org 1 into businesschannel Complete ===

=== Installing chaincode exp02 on all 4 peers... ===
=== Install Chaincode exp02:1.0 (examples/chaincode/go/chaincode_example02) on org 1/peer 0 ===
=== Chaincode is installed on remote peer0 ===
=== Install Chaincode exp02:1.0 (examples/chaincode/go/chaincode_example02) on org 1/peer 1 ===
=== Chaincode is installed on remote peer1 ===
=== Install Chaincode exp02:1.0 (examples/chaincode/go/chaincode_example02) on org 2/peer 0 ===
=== Chaincode is installed on remote peer0 ===
=== Install Chaincode exp02:1.0 (examples/chaincode/go/chaincode_example02) on org 2/peer 1 ===
=== Chaincode is installed on remote peer1 ===
=== Install chaincode done ===

=== Instantiating chaincode on channel businesschannel... ===
=== chaincodeInstantiate for channel businesschannel on org 1/peer 0 ====
=== Chaincode Instantiated in channel businesschannel by peer0 ===
=== chaincodeInstantiate for channel businesschannel on org 2/peer 0 ====
=== Chaincode Instantiated in channel businesschannel by peer0 ===
=== Instantiate chaincode on channel businesschannel done ===

至此,fabric已经部署完成。

通过cello的用户界面操作fabric

  1. 打开界面,并登陆。

HyperLedger Cello学习笔记_第6张图片

  1. 创建链

HyperLedger Cello学习笔记_第7张图片

  1. 查看链详情

HyperLedger Cello学习笔记_第8张图片

  1. 部署合约
  • 上传合约

    HyperLedger Cello学习笔记_第9张图片

    • 安装及部署合约

    HyperLedger Cello学习笔记_第10张图片

    • 执行交易

    HyperLedger Cello学习笔记_第11张图片

    • channel详情界面可以看到操作记录

    HyperLedger Cello学习笔记_第12张图片

转载请注明出处:HyperLedger Cello学习笔记

你可能感兴趣的:(HyperLedger Cello学习笔记)