1.vmware tools安装介质。右键选择vmwaretools的gz压缩包,选择“提取到....”.位置选择桌面
2.进入桌面,右键选择刚才提取的文件夹,选择“在终端打开
3.cd vmware-tools-distrib/
4.sudo ./vmware-install.pl,输入用户密码回车开始安装。出现第一个画面时,选择“y”回车,出现【yes】的时候输入“y”回车可继续
5.重启虚拟机即可
1.下载git:
#sudo apt-get install git
git version :2.17.1
2.下载cURL:
#sudo apt-get install curlcurl version:7.58.0
3.下载 docker:
#sudo apt-get -y install docker-compose
#sudo curl -L "https://github.com/docker/compose/releases/download/1.27.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
#cd /usr/local/bin/docker-compose
docker version:20.10.7
docker-compose version:1.27.0
4.确保docker daemon 是启动:
启动dockers:
sudo systemctl start docker
系统启动就运行:
sudo systemctl enable docker
5.下载vim命令
sudo apt-get install vim-gtk
6.下载node.js
sudo apt install nodejs
V8.10.0
7.下载 Fabric 示例、docker 镜像和二进制文件
curl -sSL https://bit.ly/2ysbOFE | bash -s -- 2.4.0 1.5.2 -s
7.下载nmp
sudo apt install npm
npm version:3.5.2
cd $HOME/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network
1、创建放置fabric的文件夹:
mkdir -p $HOME/src/github.com/hyperledger
cd $HOME/src/github.com/hyperledger
git clone git://github.com/hyperledger/fabric.git
下载fabric-ca
cd $HOME/src/github.com/hyperledger//fabric-samples
wget https://github.com/hyperledger/fabric-ca/releases/download/v1.5.2/hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz
tar -zxvf hyperledger-fabric-ca-linux-amd64-1.5.2.tar.gz
运行文件
cd fabric/scripts
./bootstrap.sh
启动test-network测试网络:
./network.sh up
查看docker容器:
docker ps
删除镜像:
#docker rmi -f imageid
2.使用测试网络
1、创建channel:# ./network.sh createChannel(默认通道名为mychannel)
.# ./network.sh createChannel -c channel1
#./network.sh createChannel -c channel2
3.如果您想一步建立网络并创建频道,则可以使用up
和createChannel
模式一起:#./network.sh up createChannel
3.在通道上启动链码
./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-java -ccl java
4.与网络交互
1.环境配置
export PATH=${PWD}/../bin:$PATH export FABRIC_CFG_PATH=$PWD/../config/ # Environment variables for Org1 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
2.资本初始化账本
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
3.查询账本
peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllAssets"]}'
4.转移资产
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"]}'
查询资产:
peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","asset6"]}'
结果显示 "asset6"
转给了 Christopher:
{"ID":"asset6","color":"white","size":15,"owner":"Christopher","appraisedValue":800}
5.使用认证机构建立网络
Fabric CA建立网络,请首先运行以下命令关停所有正在运行的网络:
./network.sh down
./network.sh up -ca
使用以下命令来检查Org1管理员用户的MSP文件夹:
tree organizations/peerOrganizations/org1.example.com/users/[email protected]/
# docker rm -f $(docker ps -aq) # docker rmi -f $(docker images | grep fabcar | awk '{print $3}')
cd $HOME/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network
1.启动网络
./network.sh up ./network.sh createChannel ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-java -ccl java
2.设置 Logspout
为了监控智能合约的日志,管理员可以使用该logspout
工具查看来自一组 Docker 容器的聚合输出。
cd fabric-samples/test-network
cp ../commercial-paper/organization/digibank/configuration/cli/monitordocker.sh .
./monitordocker.sh net_test
3.打包智能合约
cd fabric-samples/chaincode/fabcar/java
./gradlew installDist
cd ../../../test-network
export PATH=${PWD}/../bin:$PATH export FABRIC_CFG_PATH=$PWD/../config/
查看peer的版本,需要2.0.0版本以上才行
peer version
您现在可以使用peer 生命周期链码包命令创建链码包:
peer lifecycle chaincode package fabcar.tar.gz --path ../chaincode/fabcar/java/build/install/fabcar --lang java --label fabcar_1
4.安装链码包
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
1.发出peer 生命周期链码安装命令以在 peer 上安装链码:
peer lifecycle chaincode install fabcar.tar.gz
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_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 lifecycle chaincode install fabcar.tar.gz
5.批准链码定义
1.查询链码包的ID
peer lifecycle chaincode queryinstalled
2.修改链码条的ID
export CC_PACKAGE_ID=fabcar_1:69de748301770f6ef64b42aa6bb6cb291df20aa39542c3ef94008615704007f3
3..使用peer 生命周期链码 Approvformyorg命令批准链码定义:
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name fabcar --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
export CORE_PEER_LOCALMSPID="Org1MSP" export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt export CORE_PEER_ADDRESS=localhost:7051
5.将链码定义批准为org1
peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name fabcar --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
6将链码定义提交到通道
1.使用peer 生命周期链码 checkcommitreadiness命令来检查通道成员是否已批准相同的链码定义
peer lifecycle chaincode checkcommitreadiness --channelID mychannel --name fabcar --version 1.0 --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --output json
2.使用peer 生命周期链码提交命令将链码定义提交到通道。提交命令还需要由组织管理员提交
peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name fabcar --version 1.0 --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --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
3.使用peer 生命周期链码 querycommitted命令来确认链码定义已提交到通道。
peer lifecycle chaincode querycommitted --channelID mychannel --name fabcar --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
6.调用链码
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 fabcar --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":[]}'
我们可以使用查询函数来读取由链码创建的汽车集合:
peer chaincode query -C mychannel -n fabcar -c '{"Args":["queryAllCars"]}'
7.清理
命令删除 Logspout 工具。
docker stop logspout
docker rm logspout
./network.sh down
1.准备工作
需要安装 Python v2.7,make,和C/C++编译器工具链,如 GCC。可以执行如下命令安装其他工具:
sudo apt install build-essential
2.设置区块链网络
1.先关掉之前运行的网络
cd $HOME/src/github.com/hyperledger/fabric/scripts/fabric-samples/fabcar
2.使用 startFabric.sh
脚本启动网络
./startFabric.sh javascript
3.示例应用
cd javascript
该目录包含使用Node.js对应的Fabric SDK 开发的示例程序。
npm install
ls
你会看到下边的文件:
enrollAdmin.js node_modules package.json registerUser.js invoke.js package-lock.json query.js wallet
4.登记管理员用户
我们登记一个 admin 用户:
node enrollAdmin.js
5.注册和登记应用程序用户
令注册和记录一个名为 appUser
的新用户
node registerUser.js
6.查询账本
我们来运行我们的 query.js
程序来返回账本上所有汽车的侦听。这个程序使用我们的第二个身份——user1
——来操作账本
node query.js
1.查看安装路径
which java echo $JAVA_HOME ls -l java
2.编辑文件
sudo gedit /etc/profile
3.重启网络
service network restart
service network-manager restart
4.合并磁盘大小: 搜索 gparted软件并打开
5.打开IDEA
cd /usr/local/IntelliJ_IDEA/bin
./idea.sh
6.下载
sudo apt install XXX
一、解决Ubuntu18.04启动Docker“Got permission denied while trying to connect to the Docker daemon socket“问题
1.sudo groupadd docker #添加docker用户组 2.sudo gpasswd -a $XXX docker #检测当前用户是否已经在docker用户组中,其中XXX为用户名 3.sudo gpasswd -a $USER docker #将当前用户添加至docker用户组 4.newgrp docker #更新docker用户组
二、解决curl/wget: (7) Failed to connect to github.com port 443: Connection refused无法解析主机或请求拒绝问题
1.打开 https://www.ipaddress.com/ 输入访问不了的域名查询之后可以获得正确的 IP 地址
2.在/etc/hosts文件添加域名信息
#sudo vim /etc/hosts
在该文件中添加ip地址和域名信息
三、ERROR: Version in "./docker-compose.yml" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a version of "2" (or "2.0") and place your service definitions under the services
key, or omit the version
key and place your service definitions at the root of the file to use version 1.
解决方法:在文件docker-compose.yml修改提示version版本即可
docker-compose.yml目录:
cd $HOME/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/docker
四、
解决办法:docker-compose版本过低,升级到最新版本即可
五、
解决办法:
docker pull hyperledger/fabric-orderer:2.4
docker tag hyperledger/fabric-orderer:2.4 hyperledger/fabric-orderer:latest
更改fabric-orderer:2.4 名称为 fabric-orderer:latest
重新运行./network.sh up,问题解决。
六、./network.sh createChannel出错
docker images的版本不匹配,更新最近版本即可
七、启动链码时
之前的程序没有启动,应该。./network.sh 进行启动进程
八、连接本机失败:
curl: (7) Failed to connect to localhost port 8080: 拒绝连接
九、关闭防火墙:
sudo ufw disable
十、curl -sSL https://bit.ly/2ysbOFE | bash -s -- 2.2.0 1.4.8 -s 出现以下报错
curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to bit.ly:443
1.修改docker镜像源
vim /etc/docker/daemon.json
2.在文件中添加该内容
{ "registry-mirrors":["https://registry.docker-cn.com"] }
3.如果显示无法写入请使用sudo chmod -R 777 /etc/docker/
指令给docker最高权限方可写入。
4.重启docker服务
systemctl restart docker.service
5.查看docker镜像
docker info|grep Mirrors -A 1
6.如果还是出现以上情况,可以换个镜像试试看
十一、docker警告WARING:No swap limit support
1.我们要打开/etc/default/grub文件进行修改
sudo chmod +w /etc/default/grub
2.对文件进行编辑
sudo gedit /etc/default/grub
3.找到GRUB_CMDLINE_LINUX=配置项,原有的内容切记不要删除,在双引号内添加cgroup_enable=memory swapaccount=1
,与原来的内容之间用空格分隔。
4.再执行命令$sudo update-grub
5.重启一下服务器
reboot
十二、
export JAVA_HOME=/usr/lib/jvm/openjdk-11 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
十四、
问题E: 无法获得锁 /var/lib/dpkg/lock - open (11: 资源暂时不可用)
解决:sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock