过程概述
参照fabric生产环境搭建一:架构解析,创建application channel,需要以下步骤:
- 生成创建请求
- 创建channel
- 连接peer到channel
1. 生成创建请求
首先使用configtxgen生成一个交易,用于创建本channel的创世区块。
configtxgen需要的配置文件为:[configtx.yaml]()
# configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel1.tx -channelID channel1
- -profile指定了使用configtx.yaml中的profile名称
- -outputCreateChannelTx,指定要生成的交易名称
- -channelID,指定要创建的channel id
该命令会生成channel1.tx文件
2. 创建channel
2.1 启动peer容器
使用docker-compose启动容器,所需要的yaml文件为:[peer1-orgA.yaml]()
根据yaml文件
# 本peer的msp路径 - CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/mymsp # TLS通讯证书配置 - CORE_PEER_TLS_ENABLED=true - CORE_PEER_PROFILE_ENABLED=false - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/peer1-orgA.crt - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/peer1-orgA.key - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/root-orgA.crt
我们预先要把对应的文件放在容器能够访问的路径中。比如CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/peer1-orgA.crt。表示我们要提前把peer1-orgA.crt放在镜像的/etc/hyperledger/fabric/tls路径下
文件拷贝到容器中后,查看镜像的/etc/hyperledger/fabric目录,要包含tls和admin-msp两个文件夹
mymsp tls
其中tls内容为:
# ls tls peer1-orgA.crt peer1-orgA.key root-orgA.crt
mymsp内容为:
peer1-orgA └── msp ├── admincerts │ └── admin-orgA.crt ├── cacerts │ └── root-orgA.crt ├── keystore │ └── peer1-orgA.key ├── signcerts │ └── peer1-orgA.crt └── tlscacerts └── root-orgA.crt
现在可以启动peer的docker镜像了
docker-compose -f peer1-orgA.yaml up
2.2 登陆cli容器
接下来我们要做的操作,必须得是管理员账号来操作了。
这里我们使用镜像hyperledger/fabric-tools:2.2.4docker,镜像里面提供了各种工具,如configtxgen,configtxlator cryptogen,peer,discover等,这些工具我们后面都要用到。
具体的文件yaml见这里:~~~微微的光。我们把这个容器叫做cli容器。
需要注意的是,依照cli容器的配置,我们要把管理员的msp文件和系统根证书拷贝到容器对应目录下:
- CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/fabric/admin-msp - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/root-orgA.crt
启动并登陆我们的cli容器
docker-compose -f cli.yaml up docker container exec -it cli-orgA sh
2.3 提交创建channel命令
把前面创建的交易channel1.tx,提交给orderer节点,创建新的channel
channel1.tx需要预先手动拷贝到cli容器中
peer channel create -o orderer1.orgA:7050 -c channel1 -f /etc/hyperledger/fabric/channel1.tx --outputBlock /etc/hyperledger/fabric/channel1.block --tls --cafile /etc/hyperledger/fabric/tls/root-orgA.crt
- -o指定要连接的orderer节点地址,在这里尽量使用hostname:port的方式,保证hostname和orderer的TLS证书中信息一致
- -c 指定要创建的channel id
- -f 指定提交的交易文件
- –outputBlock, 指定新channel输出的创世区块文件
- –tls 说明采用tls和orderer通讯
- –cafile指定tls通讯的根证书
3. 连接peer到channel
3.1 获取channel的创世区块
peer channel fetch 0 ./channel1.block -o orderer1.orgA:7050 -c channel1 --tls --cafile /etc/hyperledger/fabric/tls/root-orgA.crt
- 0表示要获取channel的第0个区块,即创世区块
3.2 连接peer
peer channel join -b ./channel1.block
3.3 查看peer连接的channel
peer channel list
3.4 查看channel信息
peer channel getinfo -c channel1
Next
创建好了Application Channel。接下来就可以安装链码chaincode了~~~神秘传送门~[]
Ref
- https://hyperledger-fabric.readthedocs.io/en/release-2.2/create_channel/create_channel.html
- https://hyperledger-fabric.readthedocs.io/en/release-2.2/commands/configtxgen.html
- https://hyperledger-fabric.readthedocs.io/en/release-2.2/create_channel/create_channel_config.html
- https://fabricdocs.readthedocs.io/en/latest/Setup/Network-setup.html
- https://stackoverflow.com/questions/53570162/what-does-these-properties-mean-in-fabric-docker-image
- https://www.titanwolf.org/Network/q/8e8cc48a-97d0-4e80-a7c9-cd29de99ddbb/y
回复 buying cytotec without dr prescription 取消回复