Mac Pro下部署Hyperledger Fabric 1.4.4

May ·
更新时间:2024-11-14
· 880 次阅读

主要参考网址:

https://www.jianshu.com/p/cd05e966a6a8

https://hyperledgercn.github.io/hyperledgerDocs/getting_started/

https://www.cnblogs.com/zongmin/p/11635686.html#autoid-0-3-1

https://www.jianshu.com/p/a59ff954d3b2

主要安装的东西:

go

git

docker

fabric

fabric-samples

说明:因为mac上自带curl,因此就不用安装了,如果不确定的话可以查看版本,

malrindembp:~ malrin$ curl --version curl 7.54.0 (x86_64-apple-darwin18.0) libcurl/7.54.0 LibreSSL/2.6.5 zlib/1.2.11 nghttp2/1.24.1 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz HTTP2 UnixSockets HTTPS-proxy malrindembp:~ malrin$

1. 安装go

1.1 首先进行安装go,在终端输入:

brew install go

1.2 安装完毕后可以在终端中输入 go version查看是否安装成功:

malrindembp:~ malrin$ go version go version go1.13.7 darwin/amd64

1.3 修改环境变量

编辑.bash_profile文件,如果没有请新建。

# 打开配置文件 sudo vi ~/.bash_profile # 添加环境变量 export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin # 保存配置 esc -- :wq

1.4 查看go的具体安装信息,

malrindembp:~ malrin$ go version go version go1.13.7 darwin/amd64 malrindembp:~ malrin$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/Users/malrin/Library/Caches/go-build" GOENV="/Users/malrin/Library/Application Support/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/malrin/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/Cellar/go/1.13.7/libexec" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/Cellar/go/1.13.7/libexec/pkg/tool/darwin_amd64" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/s5/0kk1ym5d6ldgqw4mx95cr0kr0000gn/T/go-build098067536=/tmp/go-build -gno-record-gcc-switches -fno-common" malrindembp:~ malrin$

说明:上面配置环境变量的步骤是摘抄其他人的。我在安装go的时候一直有个问题没有解决就是环境变量没有修改完成,GOBIN是空的,问了公司的同事说,这个没有关系,不影响使用,因此就没有再纠结这个问题。

在每次修改.bash_profile文件后进行保存的时候,总出现这个问题:

malrindembp:~ malrin$ source ~/.bash_profile ': not a valid identifier : command not found malrindembp:~ malrin$

这个问题直到部署好fabric仍然存在,有知道的大神可以指导一下。

2. 安装git

安装git的原因主要是为了同步版本,可以在终端输入 git,如果安装git就会显示下面的结果

malrindembp:~ malrin$ git usage: git [--version] [--help] [-C ] [-c =] [--exec-path[=]] [--html-path] [--man-path] [--info-path] [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare] [--git-dir=] [--work-tree=] [--namespace=] [] These are common Git commands used in various situations: start a working area (see also: git help tutorial) clone Clone a repository into a new directory init Create an empty Git repository or reinitialize an existing one work on the current change (see also: git help everyday) add Add file contents to the index mv Move or rename a file, a directory, or a symlink reset Reset current HEAD to the specified state rm Remove files from the working tree and from the index examine the history and state (see also: git help revisions) bisect Use binary search to find the commit that introduced a bug grep Print lines matching a pattern log Show commit logs show Show various types of objects status Show the working tree status grow, mark and tweak your common history branch List, create, or delete branches checkout Switch branches or restore working tree files commit Record changes to the repository diff Show changes between commits, commit and working tree, etc merge Join two or more development histories together rebase Reapply commits on top of another base tip tag Create, list, delete or verify a tag object signed with GPG collaborate (see also: git help workflows) fetch Download objects and refs from another repository pull Fetch from and integrate with another repository or a local branch push Update remote refs along with associated objects 'git help -a' and 'git help -g' list available subcommands and some concept guides. See 'git help ' or 'git help ' to read about a specific subcommand or concept. malrindembp:~ malrin$

如果么有的话进行安装即可。

brew install git

3. 安装docker

可以用homebrew安装,输入:

brew cask install docker

或者在官网上下载Docker CE for Mac,点击Get Docker即可。

3.1 运行docker 查看docker和docker-compose是否安装成功

malrindembp:~ malrin$ docker --version Docker version 19.03.5, build 633a0ea malrindembp:~ malrin$ docker-compose --version docker-compose version 1.25.4, build 8d51620a malrindembp:~ malrin$

3.2 设置镜像加速器,一定要设置加速器,不然后面下载镜像的时候,超级超级慢。我用的是网易的,你也可以用其他加速器。

点击docker图标,preference--Docker Engine,在代码框中添加: 

"registry-mirrors": [     "http://hub-mirror.c.163.com"   ]

3.3 完成添加加速器,关闭docker,然后重新启动,输入docker info查看加速器是否添加成功

malrindembp:~ malrin$ docker info Client: Debug Mode: false Plugins: app: Docker Application (Docker Inc., v0.8.0) buildx: Build with BuildKit (Docker Inc., v0.3.1-tp-docker) Server: Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 10 Server Version: 19.03.5 Storage Driver: overlay2 Backing Filesystem: extfs Supports d_type: true Native Overlay Diff: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: b34a5c8af56e510852c35414db4c1f4fa6172339 runc version: 3e425f80a8c931f88e6d94a8c831b9d5aa481657 init version: fec3683 Security Options: seccomp Profile: default Kernel Version: 4.19.76-linuxkit Operating System: Docker Desktop OSType: linux Architecture: x86_64 CPUs: 4 Total Memory: 1.943GiB Name: docker-desktop ID: EFEU:5HTL:46U3:HSEH:MJVB:OND3:NZNG:CKPG:IATC:UQF6:4BGR:O57O Docker Root Dir: /var/lib/docker Debug Mode: true File Descriptors: 35 Goroutines: 52 System Time: 2020-02-15T10:40:30.0959401Z EventsListeners: 3 HTTP Proxy: gateway.docker.internal:3128 HTTPS Proxy: gateway.docker.internal:3129 Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Registry Mirrors: http://hub-mirror.c.163.com/ Live Restore Enabled: false Product License: Community Engine malrindembp:~ malrin$

说明:是否添加成功,看Registry Mirrors:后面显示的内容是否为http://hub-mirror.c.163.com/

4. Fabric源码下载

4.1 进入go的工作空间,为fabric创建项目路径:

$ cd $GOPATH $ mkdir -p src/github.com/hyperledger $ cd src/github.com/hyperledger

4.2 从git上拉取Hyperledger Fabric:

$ git clone https://github.com/hyperledger/fabric.git

4.3 确定fabric版本-进入fabric的目录

$ git checkout v1.4.4

4.4 查看branch的版本

git branch malrindembp:fabric malrin$ git branch * (HEAD detached at v1.4.4) master malrindembp:fabric malrin$

5. fabric docker 镜像下载

e2e_cli文件在fabric1.4已经移除了,在1.4.4版本中的测试网络使用fabric-samples 中的 first-network

我这里分两部分完成的,首先用./bootstrap.sh下载镜像文件,会发现有两个文件下载不下来,接下来,用我给出的链接可以进行下载。

5.1 下载fabric-samples源码

回到hyperledger文件夹,从git上克隆fabric-samples文件

$ git clone https://github.com/hyperledger/fabric-samples.git $ cd ./fabric-samples $ git branch -a $ git checkout v1.4.4

5.2 下载可执行二进制文件

# 将hyperledger/fabric/scripts/bootstrap.sh拷贝到hyperledger/fabric-samples中 # 终端进入到hyperledger/fabric-samples文件夹中 # 修改bootstrap.sh权限 chmod +x bootstrap.sh #运行bootstrap.sh ./bootstrap.sh

运行后出现的情况:

192:fabric-samples malrin$ ./bootstrap.sh ./bootstrap.sh: line 179: [: too many arguments Installing hyperledger/fabric-samples repo ===> Checking out v1.4.4 of hyperledger/fabric-samples HEAD is now at bc72f3e Remove Stalebot Installing Hyperledger Fabric binaries ===> Downloading version 1.4.4 platform specific fabric binaries ===> Downloading: https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/darwin-amd64-1.4.4/hyperledger-fabric-darwin-amd64-1.4.4.tar.gz % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) Could not resolve host: nexus.hyperledger.org ==> Done. ===> Downloading version 1.4.4 platform specific fabric-ca-client binary ===> Downloading: https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-ca/hyperledger-fabric-ca/darwin-amd64-1.4.4/hyperledger-fabric-ca-darwin-amd64-1.4.4.tar.gz % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) Could not resolve host: nexus.hyperledger.org ==> Done. Installing Hyperledger Fabric docker images ===> Pulling fabric Images ==> FABRIC IMAGE: peer 1.4.4: Pulling from hyperledger/fabric-peer Digest: sha256:92c2bef91e80f54f6d73a89b796eab1b616f372e2258431f17d50dd0c2ce316b Status: Image is up to date for hyperledger/fabric-peer:1.4.4 docker.io/hyperledger/fabric-peer:1.4.4 ==> FABRIC IMAGE: orderer 1.4.4: Pulling from hyperledger/fabric-orderer Digest: sha256:f7715923e2ca67cee526c21638d86b21480e179419e9d6c20078caabb241b20e Status: Image is up to date for hyperledger/fabric-orderer:1.4.4 docker.io/hyperledger/fabric-orderer:1.4.4 ==> FABRIC IMAGE: ccenv 1.4.4: Pulling from hyperledger/fabric-ccenv Digest: sha256:a4fb800d54ace75e26736d4789af7d27552774e781cf2513a5c83756808b8441 Status: Image is up to date for hyperledger/fabric-ccenv:1.4.4 docker.io/hyperledger/fabric-ccenv:1.4.4 ==> FABRIC IMAGE: javaenv 1.4.4: Pulling from hyperledger/fabric-javaenv 5667fdb72017: Pulling fs layer d83811f270d5: Pulling fs layer ee671aafb583: Pulling fs layer 7fc152dfb3a6: Waiting 3ab6e950cac5: Waiting 5376778093d1: Waiting 43a7285ac27f: Waiting 67c5b361775c: Waiting 7a9b4d622867: Waiting 6d6187ff91b2: Waiting 226ce6507c2d: Waiting 3b5744e9eb4a: Waiting 612ae6bdb688: Pull complete 2c0af2fc994a: Pull complete 594ab6cf73a0: Pull complete 9a77075403a7: Pull complete 3a153e9e6bcb: Pull complete b2e75a1b75e5: Pull complete 32055256389b: Pull complete 03e36de7e531: Pull complete d8515073d6bd: Pull complete ae113aae7b23: Pull complete 0b7aba7b70e9: Pull complete dba5f7f27672: Pull complete e187107a4f2d: Pull complete 7092dcf5ae00: Pull complete d825619a86d2: Pull complete aeee0a2c59db: Pull complete 76a0bd84f506: Pull complete 80a98336b964: Pull complete 7d6ee8a0058b: Pull complete cf18382c2cf7: Pull complete 75a167f9814e: Pull complete cb5809320473: Pull complete 41d39db8657e: Pull complete Digest: sha256:9eee210e4874b6e1a6d6a7594f0659ef37686ad572bc6273466b93b61956d23f Status: Downloaded newer image for hyperledger/fabric-javaenv:1.4.4 docker.io/hyperledger/fabric-javaenv:1.4.4 ==> FABRIC IMAGE: tools 1.4.4: Pulling from hyperledger/fabric-tools Digest: sha256:822418c5ad61473ecfa911dfe4b100264500c504c78def52730106a717be71cb Status: Image is up to date for hyperledger/fabric-tools:1.4.4 docker.io/hyperledger/fabric-tools:1.4.4 ===> Pulling fabric ca Image ==> FABRIC CA IMAGE 1.4.4: Pulling from hyperledger/fabric-ca Digest: sha256:e506e3ce041fd6c4fca5d12492caf44597818d425a8ecc73cf2b135303365244 Status: Image is up to date for hyperledger/fabric-ca:1.4.4 docker.io/hyperledger/fabric-ca:1.4.4 ===> Pulling thirdparty docker images ==> THIRDPARTY DOCKER IMAGE: couchdb 0.4.18: Pulling from hyperledger/fabric-couchdb Digest: sha256:048b7c44c1deaabd0f3d84fbf2f7b649d7b10c54a3241c7354f078ee2eff077c Status: Image is up to date for hyperledger/fabric-couchdb:0.4.18 docker.io/hyperledger/fabric-couchdb:0.4.18 ==> THIRDPARTY DOCKER IMAGE: kafka 0.4.18: Pulling from hyperledger/fabric-kafka Digest: sha256:b043b8b91fe858bfd51ad662e5816f9471f120e5ec3e77d29bf6c70bcec5c917 Status: Image is up to date for hyperledger/fabric-kafka:0.4.18 docker.io/hyperledger/fabric-kafka:0.4.18 ==> THIRDPARTY DOCKER IMAGE: zookeeper 0.4.18: Pulling from hyperledger/fabric-zookeeper Digest: sha256:ff5f9893355a56ac7dbc53d0b6a68c18cf7adfcc0c34a55a717866cb9c00a442 Status: Image is up to date for hyperledger/fabric-zookeeper:0.4.18 docker.io/hyperledger/fabric-zookeeper:0.4.18 ===> List out hyperledger docker images hyperledger/fabric-javaenv 1.4.4 4648059d209e 3 months ago 1.7GB hyperledger/fabric-javaenv latest 4648059d209e 3 months ago 1.7GB hyperledger/fabric-ca 1.4.4 62a60c5459ae 3 months ago 150MB hyperledger/fabric-ca latest 62a60c5459ae 3 months ago 150MB hyperledger/fabric-tools 1.4.4 7552e1968c0b 3 months ago 1.49GB hyperledger/fabric-tools latest 7552e1968c0b 3 months ago 1.49GB hyperledger/fabric-ccenv 1.4.4 ca4780293e4c 3 months ago 1.37GB hyperledger/fabric-ccenv latest ca4780293e4c 3 months ago 1.37GB hyperledger/fabric-orderer 1.4.4 dbc9f65443aa 3 months ago 120MB hyperledger/fabric-orderer latest dbc9f65443aa 3 months ago 120MB hyperledger/fabric-peer 1.4.4 9756aed98c6b 3 months ago 128MB hyperledger/fabric-peer latest 9756aed98c6b 3 months ago 128MB hyperledger/fabric-zookeeper 0.4.18 ede9389347db 3 months ago 276MB hyperledger/fabric-zookeeper latest ede9389347db 3 months ago 276MB hyperledger/fabric-kafka 0.4.18 caaae0474ef2 3 months ago 270MB hyperledger/fabric-kafka latest caaae0474ef2 3 months ago 270MB hyperledger/fabric-couchdb 0.4.18 d369d4eaa0fd 3 months ago 261MB hyperledger/fabric-couchdb latest d369d4eaa0fd 3 months ago 261MB

可以发现有两个镜像文件没有下载下来

hyperledger-fabric-darwin-amd64-1.4.4.tar.gz

hyperledger-fabric-ca-darwin-amd64-1.4.4.tar.gz

5.3 下载上面两个文件

下载的 hyperledger-fabric-linux-amd64-1.4.3.tar 压缩包内有 bin 和 config 两个文件夹,hyperledger-fabric-ca-linux-amd64-1.4.3.tar 压缩包内有 bin 文件夹,将两个 bin 文件夹内的二进制文件汇总在一个 bin 文件夹内。 最后将 bin 和 config 文件夹复制到 fabric-samples文件夹内。

https://download.csdn.net/download/yuxinqingge/12158745

https://download.csdn.net/download/yuxinqingge/12158750

以上两步下载完成了fabric网络启动所需依赖的镜像文件。

6. 测试网络

6.1 启动网络

进入fabric-samples下的first-network文件夹,

cd first-network

6.2 产生网络

./byfn.sh -m generate

然后点击y即可

192:fabric-samples malrin$ cd first-network 192:first-network malrin$ ./byfn.sh -m generate Generating certs and genesis block for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds Continue? [Y/n] y proceeding ... cryptogen tool not found. exiting 192:first-network malrin$ ./byfn.sh -m generate Generating certs and genesis block for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds Continue? [Y/n] y proceeding ... /Users/malrin/src/github.com/hyperledger/fabric-samples/first-network/../bin/cryptogen

6.3 启动网络

./byfn.sh -m up

输入y即可

192:first-network malrin$ ./byfn.sh -m up Starting for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds Continue? [Y/n] y proceeding ... LOCAL_VERSION=1.4.4 DOCKER_IMAGE_VERSION=1.4.4

接着会出现start和end

6.5 关闭网络

./byfn.sh -m down

输入y

192:first-network malrin$ ./byfn.sh -m down Stopping for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds Continue? [Y/n] y proceeding ...

以上就是我安装部署fabric的全部过程,在安装过程中遇到好几个坑,也耽误了好多时间,但从中也学到好多东西。

遇到的坑总结:

1.go的路径问题,.bash_profile文件总是保存不了,后来没有找到解决办法,不知道是哪里的问题。

2.版本问题,看别人安装的过程,安装测试网络e2e-cli文件,我在1.4.4版本中去找这个文件,总是显示不存在,然后就网上找各种文件,后来才发现e2e文件在1.4版本的时候已经移除,当然在1.4.4版本中也就更不存在了。

3.在docker中添加加速器,我的版本是19.03.5,在看别人安装docker攻略时,版本是17的,我的客户端界面和别人的不一样,以为安装的客户端有问题,卸了从新装,结果还是那样,后来查了好久,才知道可以在文本框中输入一行代码就可以了。

4.下载hyperledger-fabric-darwin-amd64-1.4.4.tar.gz和hyperledger-fabric-ca-darwin-amd64-1.4.4.tar.gz两个文件,一开始我以为是我网络的原因,因为终端错误链接不上那个网址,后来自己在浏览器中打开,发现确实找不到这两个文件。在百度上找这两个文件,同样是找不到。最终在万能的google上找到了,总算是能把网络启动起来了。


作者:yuxinqingge



pro hyperledger fabric mac

需要 登录 后方可回复, 如果你还没有账号请 注册新账号