代码之家  ›  专栏  ›  技术社区  ›  mahima

在Hyperledger结构中从远程计算机运行docker exec+

  •  0
  • mahima  · 技术社区  · 6 年前

    我正在运行Hyperledger fabric N 不同虚拟机上的对等机数量。VM0有peer0、orderer和CA。VM1有peer1,VM2有peer2,依此类推。所有docker容器安装完毕后,创建通道,每个对等方加入通道,通过peer0安装和实例化链码,然后在所有其他对等方上安装链码。

    # Stop existing containers and bring up the network
    docker-compose -f docker-compose.yml down
    docker-compose -f docker-compose.yml up -d
    
    # Create the channel
    docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@org1.example.com/msp" peer0.org1.example.com peer channel create -o orderer.example.com:7050 -c mychannel -f /etc/hyperledger/configtx/channel.tx
    # Join peer0.org1.example.com to the channel.
    docker exec -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@org1.example.com/msp" peer0.org1.example.com peer channel fetch config -o orderer.example.com:7050 -c mychannel
    
    docker exec -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@org1.example.com/msp" peer0.org1.example.com peer channel join -b mychannel_config.block
    
    # Install and instantiate chaincode through CLI container
    docker exec -e "CORE_PEER_ADDRESS=peer0.org1.example.com:7051" cli peer chaincode install -n exp2 -p github.com/exp2/go -v 1.0
    docker exec -e "CORE_PEER_ADDRESS=peer0.org1.example.com:7051" cli peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n exp2 -v 1.0 -c '{"Args":[""]}' -P "AND('Org1MSP.member')"
    sleep 5
    docker exec -e "CORE_PEER_ADDRESS=peer0.org1.example.com:7051" cli peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n exp2 -c '{"function":"initLedger","Args":[""]}'
    

    在当前的设置中,我必须在每个虚拟机上分别运行类似的脚本,以使对等机加入通道并安装链码。有没有办法只从VM0运行一个脚本,然后在其他VM上完成设置。我们能远程启动docker容器并执行吗 docker exec 在所有其他虚拟机上远程命令?

    2 回复  |  直到 6 年前
        1
  •  0
  •   Gustavo Passos    6 年前

    https://www.ansible.com/resources/get-started

    你可以为每个组织设置一个包含主机的invetory文件。

    hosts:
      org1:
        ansible_host: ip
      org2:
        ansible_host: ip
    

    并使用 ansible-playbook 命令通过命令。yml文件,其中包含应在每个主机中运行的命令。

    - hosts: org1
      tasks:
      - name: Create channel 1
        command: docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@org1.example.com/msp" peer0.org1.example.com peer channel create -o orderer.example.com:7050 -c mychannel -f /etc/hyperledger/configtx/channel.tx
    
        2
  •  0
  •   SAL    6 年前

    你可以用这个 Scripts 加入两个组织的网络。然而,您可能需要K8S或docker Swarm或额外的主机,以便对等方相互连接