$ sudo apt-get install git
$ sudo apt-get install curl
$ sudo apt-get remove docker docker-engine docker.io containerd runc
$ sudo apt-get update
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
$ echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
$ sudo docker run hello-world
此命令下载测试图像并在容器中运行它。容器运行时,它会打印参考消息并退出。
$ sudo groupadd docker
如果存在docker组,显示已存在docker组,执行下一步
$ sudo usermod -aG docker $USER
$ newgrp docker
$ docker run hello-world
此命令下载测试图像并在容器中运行它。容器运行时,它会打印参考消息并退出。
> $ sudo systemctl enable docker.service
> $ sudo systemctl enable containerd.service
> 若要禁用此行为,enable改成disable
> $ sudo systemctl disable docker.service
> $ sudo systemctl disable containerd.service
$ docker version
打印以下信息:
Client: Docker Engine - Community
Version: 20.10.6
API version: 1.41
Go version: go1.13.15
Git commit: 370c289
Built: Fri Apr 9 22:47:17 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.6
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: 8728dd2
Built: Fri Apr 9 22:45:28 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.4
GitCommit: 05f951a3781f4f2c1911b05e61c160e9c30eaa8e
runc:
Version: 1.0.0-rc93
GitCommit: 12644e614e25b05da6fd08a38ffa0cfe1903fdec
docker-init:
Version: 0.19.0
GitCommit: de40ad0
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
要安装其他版本的Compose,替换1.29.1为要使用的Compose版本
$ sudo chmod +x /usr/local/bin/docker-compose
$ docker-compose --version
打印以下信息:
docker-compose version 1.29.1, build c34c88b2
$ wget https://dl.google.com/go/go1.15.5.linux-amd64.tar.gz
在解压之前删除/ usr / local / go上的先前安装(如果有)
$ sudo rm -rf / usr / local / go
解压
$ tar -C / usr / local -xzf go1.16.4.linux-amd64.tar.gz
$ export PATH=$PATH:/usr/local/go/bin
使环境变量生效
$ source $HOME/.profile
$ go version
go version go1.15.5 linux/amd64
$ mkdir hyperledger
$ cd hyperledger
$ git clone git://github.com/hyperledger/fabric-samples.git
下载过程比较慢,如果出现网络中断下载失败可以选择在Windows上面下好传入linux
$ cd fabric-samples
4.1 在Windows下打开网址https://bit.ly/2ysbOFE,复制全文
4.2 在linux的fabric-samples目录下使用以下命令
$ sudo vi bootstrap.sh
把刚刚复制的文本粘贴进去,然后保存退出
4.3 然后执行bootstrap.sh文件
$ sh bootstrap.sh
如果出现Syntax error: "(" unexpected (expecting "fi")的错误信息,执行以下命令
$ sudo dpkg-reconfigure dash
在弹出的界面选择no
4.4 执行完成后会在fabric-samples目录下生成一个bin文件夹和一个config文件夹
$ cd bin
$ ls
显示以下目录:
configtxgen configtxlator cryptogen discover fabric-ca-client fabric-ca-server idemixgen orderer osnadmin peer
4.5 使用以下命令让这些二进制文件能全局使用
$ cp * /usr/local/bin
$ docker images
显示以下信息:
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest c55b0f125dc6 6 days ago 1.24MB
hyperledger/fabric-tools 2.3 a206a1593b4c 2 weeks ago 448MB
hyperledger/fabric-tools 2.3.2 a206a1593b4c 2 weeks ago 448MB
hyperledger/fabric-tools latest a206a1593b4c 2 weeks ago 448MB
hyperledger/fabric-peer 2.3 85c825d4769f 2 weeks ago 54.2MB
hyperledger/fabric-peer 2.3.2 85c825d4769f 2 weeks ago 54.2MB
hyperledger/fabric-peer latest 85c825d4769f 2 weeks ago 54.2MB
hyperledger/fabric-orderer 2.3 7cad713cbfea 2 weeks ago 37.8MB
hyperledger/fabric-orderer 2.3.2 7cad713cbfea 2 weeks ago 37.8MB
hyperledger/fabric-orderer latest 7cad713cbfea 2 weeks ago 37.8MB
hyperledger/fabric-ccenv 2.3 627c556b15ca 2 weeks ago 514MB
hyperledger/fabric-ccenv 2.3.2 627c556b15ca 2 weeks ago 514MB
hyperledger/fabric-ccenv latest 627c556b15ca 2 weeks ago 514MB
hyperledger/fabric-baseos 2.3 e50ea411d694 2 weeks ago 6.86MB
hyperledger/fabric-baseos 2.3.2 e50ea411d694 2 weeks ago 6.86MB
hyperledger/fabric-baseos latest e50ea411d694 2 weeks ago 6.86MB
hyperledger/fabric-ca 1.5 24a7c19a9fd8 2 months ago 70.8MB
hyperledger/fabric-ca 1.5.0 24a7c19a9fd8 2 months ago 70.8MB
hyperledger/fabric-ca latest 24a7c19a9fd8 2 months ago 70.8MB
hello-world latest d1165f221234 2 months ago 13.3kB
$ cd fabric-samples/test-network
$ ./network.sh up
打印以下信息:
Creating network "fabric_test" with the default driver
Creating volume "docker_orderer.example.com" with default driver
Creating volume "docker_peer0.org1.example.com" with default driver
Creating volume "docker_peer0.org2.example.com" with default driver
Creating orderer.example.com ... done
Creating peer0.org2.example.com ... done
Creating peer0.org1.example.com ... done
Creating cli ... done
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
16b3a43f6016 hyperledger/fabric-tools:latest "/bin/bash" 1 second ago Up Less than a second cli
8df4f93b6fc9 hyperledger/fabric-peer:latest "peer node start" 4 seconds ago Up 1 second 0.0.0.0:7051->7051/tcp, :::7051->7051/tcp peer0.org1.example.com
a9c1304be159 hyperledger/fabric-peer:latest "peer node start" 4 seconds ago Up 1 second 7051/tcp, 0.0.0.0:9051->9051/tcp, :::9051->9051/tcp peer0.org2.example.com
89d3f565c91e hyperledger/fabric-orderer:latest "orderer" 4 seconds ago Up 1 second 0.0.0.0:7050->7050/tcp, :::7050->7050/tcp, 0.0.0.0:7053->7053/tcp, :::7053->7053/tcp orderer.example.com
$ docker ps -a
打印以下信息:
8df4f93b6fc9 hyperledger/fabric-peer:latest "peer node start" 2 minutes ago Up 2 minutes 0.0.0.0:7051->7051/tcp, :::7051->7051/tcp peer0.org1.example.com
a9c1304be159 hyperledger/fabric-peer:latest "peer node start" 2 minutes ago Up 2 minutes 7051/tcp, 0.0.0.0:9051->9051/tcp, :::9051->9051/tcp peer0.org2.example.com
89d3f565c91e hyperledger/fabric-orderer:latest "orderer" 2 minutes ago Up 2 minutes 0.0.0.0:7050->7050/tcp, :::7050->7050/tcp, 0.0.0.0:7053->7053/tcp, :::7053->7053/tcp orderer.example.com
$ ./network.sh createChannel
打印以下信息:
2021-05-10 14:01:47.255 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2021-05-10 14:01:47.293 UTC [channelCmd] update -> INFO 002 Successfully submitted channel update
Anchor peer set for org 'Org2MSP' on channel 'mychannel'
Channel 'mychannel' joined
$ ./network.sh createChannel -c channel1
$ cd fabric-samples/asset-transfer-basic/chaincode-go
$ ls
在没有安装go依赖之前没有vendor文件夹
assetTransfer.go chaincode go.mod go.sum
安装go依赖/为go语言换一个中国境内源下载
$ go env -w GOPROXY=https://goproxy.cn,direct
$ go mod vendor
然后生成一个vendor文件夹
$ ls
显示以下目录:
assetTransfer.go chaincode go.mod go.sum vendor
$ cd fabric-samples/test-network
$ ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go
会看到以下输出,组织1和组织2:
Committed chaincode definition for chaincode 'basic' on channel 'mychannel':
Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
Query chaincode definition successful on peer0.org1 on channel 'mychannel'
Using organization 2
Querying chaincode definition on peer0.org2 on channel 'mychannel'...
Attempting to Query committed status on peer0.org2, Retry after 3 seconds.
+ peer lifecycle chaincode querycommitted --channelID mychannel --name basic
+ res=0
Committed chaincode definition for chaincode 'basic' on channel 'mychannel':
Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: [Org1MSP: true, Org2MSP: true]
Query chaincode definition successful on peer0.org2 on channel 'mychannel'
Chaincode initialization is not required
$ export PATH=${PWD}/../bin:$PATH
$ export FABRIC_CFG_PATH=$PWD/../config/
$ export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp
export CORE_PEER_ADDRESS=localhost:7051
$ peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"InitLedger","Args":[]}'
如果成功,应该看到类似以下的输出:
INFO 001 Chaincode invoke successful. result: status:200
$ peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllAssets"]}'
如果成功,应该看到以下输出:
[{"ID":"asset1","color":"blue","size":5,"owner":"Tomoko","appraisedValue":300},
{"ID":"asset2","color":"red","size":5,"owner":"Brad","appraisedValue":400},
{"ID":"asset3","color":"green","size":10,"owner":"Jin Soo","appraisedValue":500},
{"ID":"asset4","color":"yellow","size":10,"owner":"Max","appraisedValue":600},
{"ID":"asset5","color":"black","size":15,"owner":"Adriana","appraisedValue":700},
{"ID":"asset6","color":"white","size":15,"owner":"Michel","appraisedValue":800}]
$ peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"TransferAsset","Args":["asset6","Christopher"]}'
如果命令成功,应该看到以下信息:
chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200
$ export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/[email protected]/msp
export CORE_PEER_ADDRESS=localhost:9051
$ peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","asset6"]}'
结果将显示"asset6"已转移到Christopher:
{"ID":"asset6","color":"white","size":15,"owner":"Christopher","appraisedValue":800}
使用以下命令关闭测试网络:
$ ./network.sh down