联盟链HyperLeader Febric环境搭建

一、基础环境准备

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 docker
Synchronizing 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/profile
export 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 fabric
root@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.git
Cloning 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 10259
Receiving 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# ls
bootstrap.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/peer
bin/configtxlator
bin/configtxgen
bin/ledgerutil
bin/ccaas_builder/
bin/ccaas_builder/bin/
bin/ccaas_builder/bin/build
bin/ccaas_builder/bin/release
bin/ccaas_builder/bin/detect
bin/orderer
bin/cryptogen
bin/discover
bin/osnadmin
config/
config/core.yaml
config/orderer.yaml
config/configtx.yaml
root@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-client
bin/fabric-ca-server

3. 配置go代理

go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct

三、测试

root@ubuntu:/home/ns/Software/fabric/fabric-samples# cd test-network
root@ubuntu:/home/ns/Software/fabric/fabric-samples/test-network# ls
addOrg3  CHAINCODE_AS_A_SERVICE_TUTORIAL.md  compose  configtx  monitordocker.sh  network.sh  organizations  prometheus-grafana  README.md  scripts  setOrgEnv.sh  system-genesis-block
root@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# ls
go  java  javascript  networkDown.sh  startFabric.sh  typescript
root@ubuntu:/home/ns/Software/fabric/fabric-samples/fabcar# ./startFabric.sh up

执行成功,然后按照提示执行。

root@ubuntu:/home/ns/Software/fabric/fabric-samples/fabcar# ls
go  java  javascript  networkDown.sh  startFabric.sh  typescript
root@ubuntu:/home/ns/Software/fabric/fabric-samples/fabcar# cd go
root@ubuntu:/home/ns/Software/fabric/fabric-samples/fabcar/go# ls
fabcar.go  go.mod  go.sum  runfabcar.sh

测试成功!

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值