fabric生产环境搭建之番外:Anchor Peer和Service Discovery

区块链中有个概念叫做Discovery。是指节点之间相互发现的过程

fabric中叫做Service Discovery,指的是peer节点之间相互发现的过程,要想Discovery过程顺利实现,得要确保以下配置:

Service discovery (and private data) requires that gossip is enabled, therefore you should configure the peer.gossip.bootstrap, peer.gossip.endpoint , and peer.gossip.externalEndpoint parameters, as well as anchor peers on each channel, to take advantage of this feature.

也就是在peer启动的时候,要配置好peer.gossip.bootstrap, peer.gossip.endpoint , peer.gossip.externalEndpoint三个属性。尤其重要的是anchor peer,每个channel,至少配置一个anchor peer。fabric强烈建议每个组织配置一个anchor peer

anchor peer就是用于节点发现的,可以在创建channel时配置,也可以在channel创建后再更新

一般建议在创建channel的时候就配置好,在Org中添加对应信息:

Organizations:
    - &SampleOrg
          ...
        AnchorPeers:
            - Host: 127.0.0.1
              Port: 7051

但有时候根据实际需要,我们难免会要求在channel创建后,添加新的anchor peer,本文在此详细说明

这里需要提前准备hyperledger/fabric-tools:2.2.4docker镜像,具体的文件见这里:~~~微微的光,下面的操作都在fabric-tools容器中执行。

# 获取channel配置
peer channel fetch config ./channel-cfg.pb -c channel1 -o orderer1.orgA:7050 --cafile  /etc/hyperledger/fabric/tls/root-orgA.crt --tls

# 把配置转换为json文件
configtxlator proto_decode --input ./channel-cfg.pb --type common.Block --output ./channel-cfg.json

# 截取有用json,形成新的json文件
jq .data.data[0].payload.data.config channel-cfg.json > config.json

# 拷贝新文件
cp config.json config_copy.json

# 添加anchor peer信息
jq '.channel_group.groups.Application.groups["OrgA"].values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "peer1.orgA","port": 8050}]},"version": "0"}}' config_copy.json > modified_config.json

# 把修改前后的json各自转换为pb格式
configtxlator proto_encode --input ./config.json --type common.Config --output ./config.pb
configtxlator proto_encode --input ./modified_config.json --type common.Config --output ./modified_config.pb

# 把两个pb文件合成一个新的pb文件
configtxlator compute_update --channel_id channel1 --original ./config.pb --updated ./modified_config.pb --output ./config_update.pb

# 把刚生成的pb转换为json
configtxlator proto_decode --input ./config_update.pb --type common.ConfigUpdate --output ./config_update.json

# 封装一个新json文件,fabric里叫做envelope
echo '{"payload":{"header":{"channel_header":{"channel_id":"channel1", "type":2}},"data":{"config_update":'$(cat config_update.json)'}}}' | jq . > config_update_in_envelope.json

# 把envelope转换为pb格式
configtxlator proto_encode --input ./config_update_in_envelope.json --type common.Envelope --output ./config_update_in_envelope.pb

# 提交更新
peer channel update -f ./config_update_in_envelope.pb -c channel1 -o orderer1.orgA:7050 --cafile /etc/hyperledger/fabric/tls/root-orgA.crt --tls

可见这个更新过程是非常麻烦的。我们可以通过peer channel fetch config来查看更新后的配置。

现在来用Service Discover工具来检查一下,就能够查看到所有的peer信息了

# 用saveconfig命令保存config文件
discover --configFile conf.yaml --peerTLSCA /etc/hyperledger/fabric/tls/root-orgA.crt --userKey /etc/hyperledger/fabric/admin-msp/keystore/admin-orgA.key --userCert /etc/hyperledger/fabric/admin-msp/signcerts/admin-orgA.crt  --MSP OrgA saveConfig

# discover peers, 查看所有的peer
discover --configFile conf.yaml peers --channel channel1 --server peer1.orgA:8050

Ref



《 “fabric生产环境搭建之番外:Anchor Peer和Service Discovery” 》 有 4 条评论

  1. 39 Patient related factors include inadequate education about breast cancer risk, the paucity of information that accurately conveys the risks and benefits of preventive medications, 39 and concerns about medication side effects how can i get cheap cytotec without dr prescription

  2. viagra priligy Some speculate that it is a result of the liver being severely taxed

回复 agodelo 取消回复

您的邮箱地址不会被公开。 必填项已用 * 标注

About Me

一位程序员,会弹吉他,喜欢读诗。
有一颗感恩的心,一位美丽的妻子,两个可爱的女儿
mail: geraldlee0825@gmail.com
github: https://github.com/lisuxiaoqi
medium: https://medium.com/@geraldlee0825