? wget https://dl.google.com/go/go1.9.2.linux-amd64.tar.gz
? tar -C /usr/local -zxvf go1.9.2.linux-amd64.tar.gz
?
vi ~/.bash_profile
添加如下内容:
PATH=$PATH:$HOME/bin
export PATH
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$HOME/go/bin
使环境变量生效
source ~/.bash_profile
rpm -qa|grep docker
yum remove docker docker-client docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager --enable docker-ce-edge
yum-config-manager --enable docker-ce-tes
yum install docker-ce
service docker start
chkconfig docker on
docker --version
curl -L https://github.com/docker/compose/releases/download/1.20.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
docker-compose version
yum -y install epel-release
yum -y install python-pip
## root
curl -sL https://rpm.nodesource.com/setup_10.1 | bash -
## no root
curl -sL https://rpm.nodesource.com/setup_10.1 | sudo bash -
yum install -y nodejs
wget http://ftp.gnu.org/gnu/gcc/gcc-9.1.0/gcc-9.1.0.tar.gz
tar -C /usr/local -xzf gcc-9.1.0.tar.gz
cd /usr/local/gcc-9.1.0
./contrib/download_prerequisites
mkdir build
cd build/
../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
yum groupinstall "Development Tools"
make
make install
$ npm install npm -g
$ npm -v
## 下载源码
$ mkdir -p ~/go/src/github.com/hyperledger
$ cd ~/go/src/github.com/hyperledger
$ git clone https://github.com/hyperledger/fabric.git
## 切换到v1.0.0版本
$ cd ~/go/src/github.com/hyperledger/fabric
$ git checkout v1.0.0
$ cd ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli/
$ source download-dockerimages.sh -c x86_64-1.0.0 -f x86_64-1.0.0
docker images
cd ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli
./network_setup.sh up
该指令做了一下操作
1.编译生成Fabric公私钥、证书的程序,程序在目录:fabric/release/linux-amd64/bin
2.基于configtx.yaml生成创世区块和通道相关信息,并保存在channel-artifacts文件夹。
3.基于crypto-config.yaml生成公私钥和证书信息,并保存在crypto-config文件夹中。
4.基于docker-compose-cli.yaml启动1Orderer+4Peer+1CLI的Fabric容器。
5.在CLI启动的时候,会运行scripts/script.sh文件,这个脚本文件包含了创建Channel,加入Channel,安装Example02,运行Example02等功能。
运行完如果出现下图所示,说明整个Fabric网络已经通了.
Fabric提供了SDK和CLI两种交互方式,我们使用的是CLI 。
使用官方提供的小例子进行测试,在官方例子中,channel名字是mychannel,链码(智能合约)的名字是mycc。
首先要登录到CLI这个容器中,才能执行Fabric的CLI命令:
docker exec -it cli bash
这时用户名变为root@44084971aff7,当前目录变为/opt/gopath/src/github.com/hyperledger/fabric/peer#,接着可执行peer命令,体验区块链的命令行使用方式。
root@44084971aff7:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
结果:
Query Result: 90
这里90就是a账户的余额
让b账户向a账户转账10:
peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -c '{"Args":["invoke","a","b","20"]}'
再次执行查询(因为转账操作了2次所以此处是50)
root@c259da3de4d1:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
直接执行
exit
关闭Fabric
cd ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli
./network_setup.sh down
原因:未安装wget、curl
解决
yum install -y wget
yum install -y curl
yum install -y git
Failed connect to github-production-release-asset-2e65be.s3.amazonaws.com:443; Connection timed out
原因: 该地址(github-production-release-asset-2e65be.s3.amazonaws.com) 需要的一些下载的访问被 国内屏蔽了
解决:在hosts中加配置
ping github-production-release-asset-2e65be.s3.amazonaws.com
vi /etc/hosts
新增如下配置:
52.216.128.51 github-production-release-asset-2e65be.s3.amazonaws.com
configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.,mpfr2.4.0
yum install gmp gmp-devel mpfr mpfr-devel libmpc libmpc-devel
node: /usr/lib64/libstdc++.so.6: version
GLIBCXX_3.4.21‘ not found (required by node) node: /usr/lib64/libstdc++.so.6: version
GLIBCXX_3.4.15‘ not found (required by node)
node: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.20‘ not found (required by node)
运行检查命令
strings /usr/lib64/libstdc++.so.6 | grep GLIBC
查找编译gcc时生成的最新动态库
find / -name "libstdc++.so*"
cd /usr/lib64
rm -rf libstdc++.so.6
ln -s libstdc++.so.6.0.26 libstdc++.so.6
strings /usr/lib64/libstdc++.so.6 | grep GLIBC
can‘t load package: package github.com/hyperledger/fabric/core/chaincode/shim: cannot find package
源码路径不对
go env
把fabric源码放在~/go/src/github.com/hyperledger 目录下
Error response from daemon: Container is not running
?
##查看运行的容器
docker ps -a
## 把失败的重新启动
docker start 44084971aff7
Error: Error getting endorser client chaincode: PER:404 - Error trying to connect to local peer
重新关闭网络
./network_setup.sh down mychannel
root@b103ad898190:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /root/go/src/github.com/hyperledger/fabric/examples/e2e_cli/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -c ‘{"Args":["invoke","b","a","10"]}‘
2020-01-21 10:19:15.752 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2020-01-21 10:19:15.752 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
Error: Error getting broadcast client: Error connecting to orderer.example.com:7050 due to open /root/go/src/github.com/hyperledger/fabric/examples/e2e_cli/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem: no such file or directory
根证书不对
原文:https://www.cnblogs.com/vicosong/p/12226132.html