下载相应的安装包,并解压
tar -xzf go1.15.6.linux-amd64.tar.gz -C /usr/local
配置go环境变量
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin:$GOROOT/bin
使环境变量生效
source /etc/profile
2.安装docker
更新程序
sudo apt-get update
安装依赖
sudo apt install apt-transport-https ca-certificates curl software-properties-common
添加Dokcer官方密钥到系统中
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
添加Docker源
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
更新程序
sudo apt-get update
查看可安装版本
apt-cache policy docker-ce
安装docker
sudo apt install docker-ce
查看docker版本
docker --version
3.安装docker-compose
下载安装包
sudo curl -L https://github.com/docker/compose/releases/download/1.23.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
设置权限
sudo chmod +x /usr/local/bin/docker-compose
查看版本
docker-compose --version
启动网络
一、生成证书
1.生成证书文件:生成crypto-config
./bin/cryptogen generate --config=./crypto-config.yaml
2.生成创世区块
./bin/configtxgen -profile OneOrgsOrdererGenesis -channelID system-channel -outputBlock ./channel-artifacts/genesis.block
3.生成通道配置文件
./bin/configtxgen -profile OneOrgsChannel -outputCreateChannelTx ./channel-artifacts/cpsec.tx -channelID cpsec
二、启动网络
1.下载镜像
#!/bin/bash
docker pull hyperledger/fabric-ca:1.4.0
docker tag hyperledger/fabric-ca:1.4.0 hyperledger/fabric-ca:latest
docker pull hyperledger/fabric-tools:1.4.0
docker tag hyperledger/fabric-tools:1.4.0 hyperledger/fabric-tools:latest
docker pull hyperledger/fabric-ccenv:1.4.0
docker tag hyperledger/fabric-ccenv:1.4.0 hyperledger/fabric-ccenv:latest
docker pull hyperledger/fabric-orderer:1.4.0
docker tag hyperledger/fabric-orderer:1.4.0 hyperledger/fabric-orderer:latest
docker pull hyperledger/fabric-peer:1.4.0
docker tag hyperledger/fabric-peer:1.4.0 hyperledger/fabric-peer:latest
docker pull hyperledger/fabric-zookeeper:0.4.14
docker tag hyperledger/fabric-zookeeper:0.4.14 hyperledger/fabric-zookeeper:latest
docker pull hyperledger/fabric-kafka:0.4.14
docker tag hyperledger/fabric-kafka:0.4.14 hyperledger/fabric-kafka:latest
docker pull hyperledger/fabric-couchdb:0.4.14
docker tag hyperledger/fabric-couchdb:0.4.14 hyperledger/fabric-couchdb:latest
docker pull hyperledger/fabric-baseos:0.4.14
docker tag hyperledger/fabric-baseos:0.4.14 hyperledger/fabric-baseos:latest
2.启动docker-compose文件
docker-compose -f docker-compose.yml up
2.进入cli容器
docker exec -it cli /bin/bash
3.设定CA路径
export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/cpsec.com/orderers/orderer.cpsec.com/msp/tlscacerts/tlsca.cpsec.com-cert.pem
4.创建通道
peer channel create -o orderer.cpsec.com:7050 -c cpsec -f ./channel-artifacts/cpsec.tx --tls --cafile $ORDERER_CA
5.节点加入通道
peer channel join -b cpsec.block
peer channel join -b mychannel.block
6.安装链码(注意修改其相对路径)
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/peer/chaincode/src/src/github.com/chaincode_example02/go
7.链码实例化
peer chaincode instantiate -o orderer.cpsec.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/cpsec.com/orderers/orderer.cpsec.com/msp/tlscacerts/tlsca.cpsec.com-cert.pem -C cpsec -n mycc -v 1.0 -c '{"Args":["init","a", "10000", "b","20000"]}'
8.调用链码
查询余额
peer chaincode query -C cpsec -n mycc -c '{"Args":["query","b"]}'
转账 *** 作
peer chaincode invoke -o orderer.cpsec.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/cpsec.com/orderers/orderer.cpsec.com/msp/tlscacerts/tlsca.cpsec.com-cert.pem -C cpsec -n mycc --peerAddresses peer0.org1.cpsec.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.cpsec.com/peers/peer0.org1.cpsec.com/tls/ca.crt -c '{"Args":["invoke","a","b","10"]}'
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)