hyperledge环境安装

时间:2023-01-23 14:33:10

1.安装环境

1)本机安装

前提是已经安装好了docker\docker-compose\go,相应的内容可见

docker-1-环境安装及例子实践

docker官方文档学习-1-Docker for mac安装配置

go安装可看:开始学习前的环境安装

然后可见本机环境版本信息为:

docker为:

userdeMacBook-Pro:~ user$ docker version
Client: Docker Engine - Community
Version: 18.09.
API version: 1.39
Go version: go1.10.4
Git commit: 4d60db4
Built: Wed Nov ::
OS/Arch: darwin/amd64
Experimental: false Server: Docker Engine - Community
Engine:
Version: 18.09.
API version: 1.39 (minimum version 1.12)
Go version: go1.10.4
Git commit: 4d60db4
Built: Wed Nov ::
OS/Arch: linux/amd64
Experimental: false
Kubernetes:
Version: v1.10.3
StackAPI: v1beta2

docker-compose为:

userdeMBP:~ user$ docker-compose version
docker-compose version 1.23., build 1110ad01
docker-py version: 3.6.
CPython version: 3.6.
OpenSSL version: OpenSSL 1.1.0h Mar

go为:

userdeMacBook-Pro:~ user$ go version
go version go1.11.4 darwin/amd64

一开始docker中的镜像信息有:

userdeMacBook-Pro:~ user$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
k8s.gcr.io/kubernetes-dashboard-amd64 v1.10.1 f9aed6605b81 months ago 122MB
docker/kube-compose-controller v0.4.12 02a45592fbea months ago .8MB
docker/kube-compose-api-server v0.4.12 0f92c77fa676 months ago .2MB
k8s.gcr.io/kube-proxy-amd64 v1.10.3 4261d315109d months ago .1MB
k8s.gcr.io/kube-controller-manager-amd64 v1.10.3 40c8d10b2d11 months ago 148MB
k8s.gcr.io/kube-apiserver-amd64 v1.10.3 e03746fe22c3 months ago 225MB
k8s.gcr.io/kube-scheduler-amd64 v1.10.3 353b8f1d102e months ago .4MB
k8s.gcr.io/etcd-amd64 3.1. 52920ad46f5b months ago 193MB
k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64 1.14. c2ce1ffb51ed months ago 41MB
k8s.gcr.io/k8s-dns-sidecar-amd64 1.14. 6f7f2dc7fab5 months ago .2MB
k8s.gcr.io/k8s-dns-kube-dns-amd64 1.14. 80cc5ea4b547 months ago .5MB
k8s.gcr.io/pause-amd64 3.1 da86e6ba6ca1 months ago 742kB

这是因为安装了kubernetes

2)虚拟机安装

当然如果手动安装环境不顺利的情况下,我们也可以通过配置虚拟机来配置环境,这个的好处有:

使用vagrant集成的开发环境开发允许开发者使用自己喜欢的操作系统和编辑器来开发,同时又可以让系统运行在一个与开发团队一致的开发环境中。

当然首先需要有vagrant\virtualbox环境, vagrant\virtualbox的安装和版本可见virtualbox+vagrant学习-1-环境安装及vagrantfile的简单配置-Mac系统

参考https://blog.csdn.net/zgljl2012/article/details/52896372

首先需要下载fabric源码

userdeMacBook-Pro:~ user$ go get github.com/hyperledger/fabric
package github.com/hyperledger/fabric: no Go files in /Users/user/go/src/github.com/hyperledger/fabric

使用Vagrant启动虚拟机

进入/Users/user/go/src/github.com/hyperledger/fabric/devenv目录下,这里写好了安装虚拟机的配置文件,调用vagrant up来启动vagrant。这样就能够不用配置,直接使用开发人员设置好的开发环境:

userdeMBP:fabric user$ cd devenv/
userdeMBP:devenv user$ vagrant up
==> vagrant: A new version of Vagrant is available: 2.2. (installed version: 2.2.)!
==> vagrant: To upgrade visit: https://www.vagrantup.com/downloads.html Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/xenial64'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: hyperledger
==> default: Vagrant has detected a configuration issue which exposes a
==> default: vulnerability with the installed version of VirtualBox. The
==> default: current guest is configured to use an E1000 NIC type for a
==> default: network adapter which is vulnerable in this version of VirtualBox.
==> default: Ensure the guest is trusted to use this configuration or update
==> default: the NIC type using one of the methods below:
==> default:
==> default: https://www.vagrantup.com/docs/virtualbox/configuration.html#default-nic-type
==> default: https://www.vagrantup.com/docs/virtualbox/networking.html#virtualbox-nic-type
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter : nat
==> default: Forwarding ports...
default: (guest) => (host) (adapter )
default: (guest) => (host) (adapter )
default: (guest) => (host) (adapter )
default: (guest) => (host) (adapter )
default: (guest) => (host) (adapter )
default: (guest) => (host) (adapter )
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection reset. Retrying...
default: Warning: Remote connection disconnect. Retrying...
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: The guest additions on this VM do not match the installed version of
default: VirtualBox! In most cases this is fine, but in rare cases it can
default: prevent things such as shared folders from working properly. If you see
default: shared folder errors, please make sure the guest additions within the
default: virtual machine match the version of VirtualBox you have installed on
default: your host and reload your VM.
default:
default: Guest Additions Version: 5.1.
default: VirtualBox Version: 5.2
==> default: Mounting shared folders...
default: /vagrant => /Users/user/go/src/github.com/hyperledger/fabric/devenv
default: /local-dev => /Users/user/go/src/github.com/hyperledger
default: /hyperledger => /Users/user/go/src/github.com/hyperledger
default: /opt/gopath/src/github.com/hyperledger => /Users/user/go/src/github.com/hyperledger
==> default: Running provisioner: shell...
default: Running: inline script
default: ++ tee -a /etc/hosts
default: ++ echo '127.0.0.1 couchdb'
default: 127.0.0.1 couchdb
...

等到安装好后,运行vagrant ssh来进入该虚拟机:

userdeMacBook-Pro:devenv user$ vagrant ssh
Welcome to Ubuntu 16.04. LTS (GNU/Linux 4.4.--generic x86_64) * Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud packages can be updated.
updates are security updates. New release '18.04.2 LTS' available.
Run 'do-release-upgrade' to upgrade to it. *** System restart required ***
vagrant@ubuntu-xenial:~$

参考https://blog.csdn.net/zgljl2012/article/details/52896372

过程中如果没成功,可能是因为网络被qiang的原因,可以到百度云手动安装box

https://pan.baidu.com/s/1kV57PLt?errno=0&errmsg=Auth%20Login%20Sucess&&bduss=&ssnerror=0&traceid=

然后运行:

vagrant box add hyperledger/fabric-baseimage virtualbox.box

再运行vagrant up即可

当然你也可以从virtualbox处进入

hyperledge环境安装

用户名和密码都为vagrant

hyperledge环境安装

然后此时查看该环境配置的版本信息:

vagrant@ubuntu-xenial:~$ go version
go version go1.11.5 linux/amd64 vagrant@ubuntu-xenial:~$ docker version
Client:
Version: 18.09.
API version: 1.39
Go version: go1.10.8
Git commit: 774a1f4
Built: Thu Feb ::
OS/Arch: linux/amd64
Experimental: false
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.39/version: dial unix /var/run/docker.sock: connect: permission denied vagrant@ubuntu-xenial:~$ docker-compose version
docker-compose version 1.14., build c7bdf9e
docker-py version: 2.3.
CPython version: 2.7.
OpenSSL version: OpenSSL 1.0.1t May

上面的Got permission denied的解决办法是:

1)运行时在前面加一个sudo:

vagrant@ubuntu-xenial:~$ sudo docker version
Client:
Version: 18.09.
API version: 1.39
Go version: go1.10.8
Git commit: 774a1f4
Built: Thu Feb ::
OS/Arch: linux/amd64
Experimental: false Server: Docker Engine - Community
Engine:
Version: 18.09.
API version: 1.39 (minimum version 1.12)
Go version: go1.10.8
Git commit: 774a1f4
Built: Thu Feb ::
OS/Arch: linux/amd64
Experimental: false

2)另一种解决办法就是docker守护进程启动的时候,会默认赋予名字为docker的用户组读写Unix socket的权限,因此只要创建docker用户组,并将当前用户加入到docker用户组中,那么当前用户就有权限访问Unix socket了,进而也就可以执行docker相关命令(参考https://www.cnblogs.com/informatics/p/8276172.html):

vagrant@ubuntu-xenial:~$ sudo groupadd docker //添加docker用户组
groupadd: group 'docker' already exists
vagrant@ubuntu-xenial:~$ sudo gpasswd -a $USER docker //将登陆用户加入到docker用户组中
Adding user vagrant to group docker
vagrant@ubuntu-xenial:~$ newgrp docker //更新用户组
vagrant@ubuntu-xenial:~$ docker version //测试果然成功
Client:
Version: 18.09.
API version: 1.39
Go version: go1.10.8
Git commit: 774a1f4
Built: Thu Feb ::
OS/Arch: linux/amd64
Experimental: false Server: Docker Engine - Community
Engine:
Version: 18.09.
API version: 1.39 (minimum version 1.12)
Go version: go1.10.8
Git commit: 774a1f4
Built: Thu Feb ::
OS/Arch: linux/amd64
Experimental: false

然后安装镜像

安装好的虚拟机中也已经下载好了hyperledger/fabric,里面目录script中的bootstrap.sh文件中写好了需要安装的镜像信息,能够通过调用该文件来安装需要的镜像,如下:

vagrant@ubuntu-xenial:~$ cd /opt/gopath/src/github.com/hyperledger/fabric/scripts
vagrant@ubuntu-xenial:/opt/gopath/src/github.com/hyperledger/fabric/scripts$ ls
bootstrap.sh check_trailingspaces.sh goListFiles.sh
changelog.sh compile_protos.sh metrics_doc.sh
check_deps.sh fabric-samples multiarch.sh
check_license.sh generateHelpDocs.sh pull_build_artifacts.sh
check_spelling.sh golinter.sh run-integration-tests.sh
vagrant@ubuntu-xenial:/opt/gopath/src/github.com/hyperledger/fabric/scripts$ ./bootstrap.sh
./bootstrap.sh: line 179: [: too many arguments Installing hyperledger/fabric-samples repo
...
===> List out hyperledger docker images //运行到这,相应的镜像就已经安装好了
hyperledger/fabric-tools 1.4.0 0a44f4261a55 8 weeks ago 1.56GB
hyperledger/fabric-tools latest 0a44f4261a55 8 weeks ago 1.56GB
hyperledger/fabric-ccenv 1.4.0 5b31d55f5f3a 8 weeks ago 1.43GB
hyperledger/fabric-ccenv latest 5b31d55f5f3a 8 weeks ago 1.43GB
hyperledger/fabric-orderer 1.4.0 54f372205580 8 weeks ago 150MB
hyperledger/fabric-orderer latest 54f372205580 8 weeks ago 150MB
hyperledger/fabric-peer 1.4.0 304fac59b501 8 weeks ago 157MB
hyperledger/fabric-peer latest 304fac59b501 8 weeks ago 157MB
hyperledger/fabric-ca 1.4.0 1a804ab74f58 8 weeks ago 244MB
hyperledger/fabric-ca latest 1a804ab74f58 8 weeks ago 244MB
hyperledger/fabric-zookeeper 0.4.14 d36da0db87a4 4 months ago 1.43GB
hyperledger/fabric-zookeeper latest d36da0db87a4 4 months ago 1.43GB
hyperledger/fabric-kafka 0.4.14 a3b095201c66 4 months ago 1.44GB
hyperledger/fabric-kafka latest a3b095201c66 4 months ago 1.44GB
hyperledger/fabric-couchdb 0.4.14 f14f97292b4c 4 months ago 1.5GB
hyperledger/fabric-couchdb latest f14f97292b4c 4 months ago 1.5GB

3)可以看hyperledger中文文档学习-4-构建第一个fabric网络去开始构建一个简单的网络