Skip to content

Articles on technical topics such as blockchain, container and IoT.

Notifications You must be signed in to change notification settings

shiyuleixia/hyperledger-fabric-k8s

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 

Repository files navigation

使用kubernetes部署Hyperledger Fabric

本文假设你已经搭建好了k8s集群,在此基础上,依本文步骤即可在K8s上部署Hyperledger Fabric

  1. 克隆本仓库

    git clone https://github.com/marryton007/hyperledger-fabric-k8s.git
    
  2. 准备好NFS服务器

    这里以192.168.1.206作为NFS服务器,后面的Peer,order,ca都会共享该服务器

    showmount -e 192.168.1.206
    Exports list on 192.168.1.206:
    /data                               *
    /opt/share                          *
    
  3. 启动kafka服务

    cd hyperledger-fabric-k8s/fabric_on_kubernetes/Fabric-on-K8S/k8s_kafka
    ./run.sh
    

    检测kafka服务是否启动

    kubectl get pod -n kafka
    
  4. 启动Orderer,Peer,CA,cli节点

    cd hyperledger-fabric-k8s/fabric_on_kubernetes/Fabric-on-K8S/setupCluster
    
    // 以mac系统为例,加载NFS目录
    sudo mount -o resvport,rw -t nfs 192.168.1.206:/opt/share /opt/share
    sudo mount -o resvport,rw -t nfs 192.168.1.206:/data /opt/data
    
    // 在/opt/data目录中创建子目录,供orderer,peer,cli,ca使用
    ./mkdir-storage-dir.sh
    
    // 生成证书及相关的k8s部署文件,首次使用的用户需要下载Fabric相关工具,
    // 如cryptogen,configtxgen,请参考'Hyperledger fabric示例'
    ./generateALL.sh
    
    // 使用kubectl创建相关资源
    python3 transform/run.py
    
  5. 测试

    // 列出org下pods
    kubectl get pods --namespace org1
    
    // 进行容器
    kubectl exec -it cli-dcb6c5f89-gvzrl bash --namespace=org1
    
    // 创建通道
    peer channel create -o orderer0.orgorderer1:7050  -c mychannel -f ./channel-artifacts/channel.tx -t 60
    
    cp mychannel.block ./channel-artifacts
    
    // 加入通道
    peer channel join -b ./channel-artifacts/mychannel.block
    
    // 更新 anchor peer,每个 org 只需执行一次
    peer channel update -o orderer0.orgorderer1:7050  -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx
    
    // 安装 chaincode
    peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/peer/channel-artifacts/chaincode_example02
    
    // 实例化 chaincode
    peer chaincode instantiate -o orderer0.orgorderer1:7050 -C mychannel -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}'  -P "OR ('Org1MSP.member','Org2MSP.member')"
    
    // 查询
    peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
    
    // 调用
    peer chaincode invoke -o orderer0.orgorderer1:7050   -C mychannel -n mycc -c '{"Args":["invoke","a","b","10"]}'
    
  6. 参考资源

About

Articles on technical topics such as blockchain, container and IoT.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 46.2%
  • Go 37.5%
  • Shell 16.3%