centos 7.4 阿里云香港服务器
peer create chaincode 时 -channelID 前有一个横杠
1、更新依赖源 sudo yum update
2、安装docker
sudo yum install -y yum-utils \device-mapper-persistent-data \lvm2
3、安装有关的依赖
sudo yum-config-manager \--add-repo \https://download.docker.com/linux/centos/docker-ce.repo
4、安装docker-ce
sudo yum install docker-ce
检查安装结果
docker --version
5、启动 service docker start
6、每次自动启动 chkconfig docker on
7、安装curl 命令 yum install curl
8、下载docker-compose,注意不是单引号
sudo curl -L https://github.com/docker/compose/releases/download/1.20.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
9、cp /usr/local/bin/docker-compose /usr/bin
10、docker-compose version 如果提示权限不足,那么chmod +x /usr/local/bin/docker-compose
11、安装go
curl -O https://storage.googleapis.com/golang/go1.10.1.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.10.1.linux-amd64.tar.gz
解压缩到/usr/local目录
12、配置环境
vim /etc/profile
export PATH=$PATH:/usr/local/go/bin
export GOPATH=/opt/gopath
source /etc/profile
13、查看go 安装信息
echo $PATH
go version
14、安装git
yum install git
15、创建安装目录
mkdir -p /opt/gopath/src/github.com/hyperledger
16、进入安装目录
cd /opt/gopath/src/github.com/hyperledger
17、拉取源代码
git clone https://github.com/hyperledger/fabric.git
18、切换到分支
cd fabric
git checkout -b v1.0.0 切换到分支
git checkout v1.0.0 这两个有差异!应该这样而不是上面的 -b是新建分支的意思!
19、拉取docker
cd examples/e2e_cli/
chmod +x download-dockerimages.sh
./download-dockerimages.sh -c x86_64-1.0.0 -f x86_64-1.0.0
docker images 查看下载内容
20、运行fabric网络
./network_setup.sh up
如果遇到问题,参考
https://blog.csdn.net/frankxixu/article/details/80641336
2018-01-26 05:03:26.153 UTC [msp/identity] Sign -> DEBU 00f Sign: digest: A5892BF4C08D07882B34D959932CFA784DE00E1B29D40411B1CF8B59C16DF557
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x63 pc=0x7ff4023cb259]
./network_setup.sh down
docker rm -f $(docker ps -aq)
解决办法:
修改vim /etc/resolv.conf 配置,将 options timeout:2 attempts:3 rotate single-request-reopen 这一行内容注释掉
21、将bin考入aberic
生成了bin 在fabric/release/linux-amd64/下
在fabric目录下mkdir aberic目录
./network_setup.sh down 先停止服务
cp -r bin /opt/gopath/src/github.com/hyperledger/fabric/aberic
还需要configtx.yaml 和 crypto-config.yaml
这两个文件来自/opt/gopath/src/github.com/hyperledger/fabric/examples/e2e_cli
cp configtx.yaml /opt/gopath/src/github.com/hyperledger/fabric/aberic
cp crypto-config.yaml /opt/gopath/src/github.com/hyperledger/fabric/aberic
copy chaincode 在 fabric/examples
cp -r chaincode /opt/gopath/src/github.com/hyperledger/fabric/aberic
配置齐全了!
22、执行准备程序
准备启动 aberic目录下
./bin/cryptogen generate --config=./crypto-config.yaml
结果生成
org1.example.com
org2.example.com
crypto-config 目录也添加了
生成创世区块
export FABRIC_CFG_PATH=$PWD
在fabric/aberic目录下执行以上
echo $PWD
输出:/opt/gopath/src/github.com/hyperledger/fabric/aberic
23、执行创世区块生成
在fabric/aberic目录下创建channel-artifacts目录
mkdir channel-artifacts
执行
./bin/configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
./bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/mychannel.tx -channelID mychannel
三、准备orderer启动脚本
1、准备docker-orderer.yaml docker-peer.yaml脚本,内容在github.com
https://github.com/frank1982/Hyperledger_singleServer
上传到aberic目录下
scp -r /Users/developer/Desktop/hyperledger/scripts/single/docker-orderer.yaml [email protected]:/opt/gopath/src/github.com/hyperledger/fabric/aberic
scp -r /Users/developer/Desktop/hyperledger/scripts/single/docker-peer.yaml [email protected]:/opt/gopath/src/github.com/hyperledger/fabric/aberic
2、在aberic目录下启动
docker-compose -f docker-orderer.yaml up -d
docker-compose -f docker-peer.yaml up -d
docker ps 没有信息?
3、创建mychannel
进入cli
在aberic目录下
docker exec -it cli bash
进入了如下目录:
root@b1f3247283df:/opt/gopath/src/github.com/hyperledger/fabric/peer#
创建mychannel
peer channel create -o orderer.example.com:7050 -c mychannel -t 50 -f ./channel-artifacts/mychannel.tx
4、加入channel
peer channel join -b mychannel.block
peer0加入网络,由于cli是默认指向peer0的,docker-peer.yaml文件说明
可以修改cli配置,使得指向其他的peer
5、安装智能合约
peer chaincode install -n mychannel -p github.com/hyperledger/fabric/aberic/chaincode/go/chaincode_example02 -v 1.0
6、实例化chaincode
peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n mychannel -c '{"Args":["init","A","10","B","10"]}' -P "OR ('Org1MSP.member')" -v 1.0
7、查询
peer chaincode query -C mychannel -n mychannel -c '{"Args":["query","A"]}'
Query Result: 10
peer chaincode query -C mychannel -n mychannel -c '{"Args":["query","B"]}'
8、交易
peer chaincode invoke -C mychannel -n mychannel -c '{"Args":["invoke","A","B","8"]}'
result: status:200