与2个同行一起创建组织

时间:2018-09-07 18:56:01

标签: docker hyperledger-fabric hyperledger

我正在尝试扩展this代码,以在组织org1中再添加1个认可对等体。我更新了/basic-network/crypto-config.yaml如下:

PeerOrgs:
- Name: Org1
Domain: org1.example.com
Template:
  Count: 2
Users:
  Count: 1

然后,我通过再次运行generate.sh重新生成了所有加密材料。我在basic-network/docker-compose.yaml文件中更新了FABRIC_CA_SERVER_CA_KEYFILE。我在docker-compose.yaml中添加了peer1.org1.example.com:

peer1.org1.example.com:
    container_name: peer1.org1.example.com
    image: hyperledger/fabric-peer
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_PEER_ID=peer1.org1.example.com
      - CORE_LOGGING_PEER=debug
      - CORE_CHAINCODE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/
      - CORE_PEER_ADDRESS=peer1.org1.example.com:7056
      # # the following setting starts chaincode containers on the same
      # # bridge network as the peers
      # # https://docs.docker.com/compose/networking/
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=${COMPOSE_PROJECT_NAME}_basic
      - CORE_LEDGER_STATE_STATEDATABASE=CouchDB
      - CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=couchdb:5984
      # The CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME and CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD
      # provide the credentials for ledger to connect to CouchDB.  The username and password must
      # match the username and password set for the associated CouchDB.
      - CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=
      - CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric
    command: peer node start
    # command: peer node start --peer-chaincodedev=true
    ports:
      - 7056:7056
      - 7058:7058
    volumes:
        - /var/run/:/host/var/run/
        - ./crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/msp:/etc/hyperledger/msp/peer
        - ./crypto-config/peerOrganizations/org1.example.com/users:/etc/hyperledger/msp/users
        - ./config:/etc/hyperledger/configtx
    depends_on:
      - orderer.example.com
      - couchdb
      - peer0.org1.example.com
    networks:
      - basic

然后我运行了以下命令:

set -ev
export MSYS_NO_PATHCONV=1
docker-compose -f docker-compose.yml down
docker-compose -f docker-compose.yml up -d ca.example.com orderer.example.com peer0.org1.example.com peer1.org1.example.com couchdb

所有容器都已启动并且正在运行,没有任何错误。

CONTAINER ID        IMAGE                                                                                                      COMMAND                  CREATED             STATUS              PORTS                                            NAMES
3393fc796417        dev-peer0.org1.example.com-tuna-app-1.0-b58eb592ed6ced10f52cc063bda0c303a4272089a3f9a99000d921f94b9bae9b   "chaincode -peer.add…"   2 minutes ago       Up 2 minutes                                                         dev-peer0.org1.example.com-tuna-app-1.0
a45d7e943068        hyperledger/fabric-tools                                                                                   "/bin/bash"              2 minutes ago       Up 2 minutes                                                         cli
d3698fc6d3d3        hyperledger/fabric-peer                                                                                    "peer node start"        2 minutes ago       Up 2 minutes        0.0.0.0:7056->7056/tcp, 0.0.0.0:7058->7058/tcp   peer1.org1.example.com
b7c92a70fc89        hyperledger/fabric-peer                                                                                    "peer node start"        2 minutes ago       Up 2 minutes        0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp   peer0.org1.example.com
21fabe33e3e5        hyperledger/fabric-ca                                                                                      "sh -c 'fabric-ca-se…"   2 minutes ago       Up 2 minutes        0.0.0.0:7054->7054/tcp                           ca.example.com
ddaf8390c0ee        hyperledger/fabric-couchdb                                                                                 "tini -- /docker-ent…"   2 minutes ago       Up 2 minutes        4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp       couchdb
38bdb92c6de0        hyperledger/fabric-orderer                                                                                 "orderer"                2 minutes ago       Up 2 minutes        0.0.0.0:7050->7050/tcp                           orderer.example.com

接下来,我需要创建具有两个对等方的渠道。如何修改以下命令以将peer1添加到org1?

# 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_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@org1.example.com/msp" peer0.org1.example.com peer channel join -b mychannel.block

以上两个命令运行成功,但是当我尝试按照以下命令运行时

docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@org1.example.com/msp" peer1.org1.example.com peer channel join -b mychannel.block

我收到以下错误:

Error: Error getting endorser client channel: endorser client failed to connect to peer1.org1.example.com:7056: failed to create new connection: context deadline exceeded

1 个答案:

答案 0 :(得分:0)

70517053用作对等端的内部端口,只需更改暴露的端口即可:

ports:
      - 7056:7051
      - 7058:7053

我找不到任何官方文档,但是默认情况下,它似乎总是使用组织的锚点对等的地址。用于处理组织中对等方的传入请求的端口应与该组织的锚定对等端口相同

来自core.yaml config file

  

#此对等方将侦听的本地网络接口上的地址。
  #默认情况下,它将在所有网络接口上侦听
  监听地址:0.0.0.0:7051

     

[...]

     

#用作对等配置时,它表示其他对等节点的终结点
  #在同一组织中。对于其他组织的同行,请参见
  #gossip.externalEndpoint了解更多信息。
  #用作CLI配置时,这意味着对等方的端点要与之交互
  地址:0.0.0.0:7051

     

[...]

     

闲话:
  #Bootstrap设置用来初始化八卦。
  #这是此对等方在启动时可以访问的其他对等方的列表。
  #重要提示:这里的端点必须是同一端点的对等端点
  #组织,因为对等方将拒绝连接到这些终结点
  #除非它们与对等方位于同一组织中。
  引导程序:127.0.0.1:7051

如果您确实要使用另一个内部端口(例如7056),请尝试在 docker-compose 文件中为新对等端定义CORE_PEER_LISTENADDRESS(定义GRPC服务器的监听端口):

CORE_PEER_LISTENADDRESS=0.0.0.0:7056

此外,我建议您不要对所有同行使用相同的 CouchDb 作为分类帐数据库。每个对等方都使用沙发床(建议设置用户名/密码)。

编辑:由于您没有从peer channel join容器中运行cli命令,因此我认为您必须{@ 3}}通过订购者上的频道您的新对等方可以加入它(这将返回目标通道的最新配置块):

docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@org1.example.com/msp" peer1.org1.example.com peer channel fetch config -o orderer.example.com:7050 -c mychannel

然后,您应该可以使用新创建的区块(<channelID>_config.block)将对等方加入频道。