一、基础环境准备
1. Apt换源
打开网址:ubuntu | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror,选择对应Ubuntu版本号,将红框中的内容进行复制。
执行指令:sudo gedit /etc/apt/sources.list,将以上内容粘贴以替换原来文件的内容。
执行指令:sudo apt update,更新镜像源。
2. 安装docker
ns@ubuntu:~$ sudo apt install docker docker-compose
配置Docker开机自启动服务:
ns@ubuntu:~$ sudo systemctl enable dockerSynchronizing state of docker.service with SysV init with /lib/systemd/systemd-sysv-install...Executing /lib/systemd/systemd-sysv-install enable docker
然后,将当前用户加入docker用户组。
ns@ubuntu:~$ sudo usermod -a -G docker ns
3. 安装golang
进入Go官方文档:Download and install – The Go Programming Language,选择Linux版本并下载。
执行sudo su切换到root用户。
执行指令:
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.17.6.linux-amd64.tar.gz
将其解压到指定目录。
然后配置环境变量:
root@ubuntu:/usr/local# vim /etc/profileexport PATH=$PATH:/usr/local/go/bin#写入该行语句root@ubuntu:/usr/local# source /etc/profile #更新配置
注意:为了避免每次都要执行source语句,可以执行vim ~/.bashrc命令将source /etc/profile写入文件后保存退出,则以后就可以不用再执行改语句,切换ns用户再执行一遍。
检查go版本:go version
二、安装Hyperledger Fabric
1. 安装samples、docker
进入网址:https://github.com/hyperledger/fabric/blob/main/scripts/bootstrap.sh
复制bootstrap.sh内容并在Linux目录下新建一个fabric目录和bootstrap.sh同名文件,将内容粘贴进去并保存。
root@ubuntu:/home/ns/Software# mkdir fabricroot@ubuntu:/home/ns/Software# cd fabric/root@ubuntu:/home/ns/Software/fabric# vim bootstrap.sh
注意:为了测试方便,对下面的true代修改为false。
然后赋予权限:
chmod u+x bootstrap.sh
执行:
./bootstrap.sh
接下来将克隆samples到本地:
root@ubuntu:/home/ns/Software/fabric# git clone https://github.com/hyperledger/fabric-samples.gitCloning into 'fabric-samples'...remote: Enumerating objects: 10607, done.remote: Counting objects: 100% (348/348), done.remote: Compressing objects: 100% (240/240), done.remote: Total 10607 (delta 134), reused 228 (delta 85), pack-reused 10259Receiving objects: 100% (10607/10607), 19.22 MiB | 822.00 KiB/s, done.Resolving deltas: 100% (5659/5659), done.Checking connectivity... done.root@ubuntu:/home/ns/Software/fabric# lsbootstrap.sh fabric-samples
2. 安装binaries
根据bootstrap.sh文件版本要求,去以下两个网址下载对应文件:
https://github.com/hyperledger/fabric/releases
https://github.com/hyperledger/fabric-ca/releases
解压文件到fabric/fabric-samples/目录下:
root@ubuntu:/home/ns/Software/packets# tar -zxvf hyperledger-fabric-linux-amd64-2.4.4.tar.gz -C ../fabric/fabric-samples/bin/bin/peerbin/configtxlatorbin/configtxgenbin/ledgerutilbin/ccaas_builder/bin/ccaas_builder/bin/bin/ccaas_builder/bin/buildbin/ccaas_builder/bin/releasebin/ccaas_builder/bin/detectbin/ordererbin/cryptogenbin/discoverbin/osnadminconfig/config/core.yamlconfig/orderer.yamlconfig/configtx.yamlroot@ubuntu:/home/ns/Software/packets# tar -zxvf hyperledger-fabric-ca-linux-amd64-1.5.5.tar.gz -C ../fabric/fabric-samples/bin/bin/fabric-ca-clientbin/fabric-ca-server
3. 配置go代理
go env -w GO111MODULE=ongo env -w GOPROXY=https://goproxy.cn,direct
三、测试
root@ubuntu:/home/ns/Software/fabric/fabric-samples# cd test-networkroot@ubuntu:/home/ns/Software/fabric/fabric-samples/test-network# lsaddOrg3 CHAINCODE_AS_A_SERVICE_TUTORIAL.md compose configtx monitordocker.sh network.sh organizations prometheus-grafana README.md scripts setOrgEnv.sh system-genesis-blockroot@ubuntu:/home/ns/Software/fabric/fabric-samples/test-network# ./network.sh up
然后测试fabcar
root@ubuntu:/home/ns/Software/fabric/fabric-samples# cd fabcar/root@ubuntu:/home/ns/Software/fabric/fabric-samples/fabcar# lsgo java javascript networkDown.sh startFabric.sh typescriptroot@ubuntu:/home/ns/Software/fabric/fabric-samples/fabcar# ./startFabric.sh up
执行成功,然后按照提示执行。
root@ubuntu:/home/ns/Software/fabric/fabric-samples/fabcar# lsgo java javascript networkDown.sh startFabric.sh typescriptroot@ubuntu:/home/ns/Software/fabric/fabric-samples/fabcar# cd goroot@ubuntu:/home/ns/Software/fabric/fabric-samples/fabcar/go# lsfabcar.go go.mod go.sum runfabcar.sh
测试成功!