zoukankan      html  css  js  c++  java
  • Hyperledger02

    docker 思想

    模块化: 集装箱
    标准化: 运输标准化, 存储方式标准化,API接口的标准化
    安全性: 隔离

    docker解决什么问题

    • devops
    • 我这程序程序没问题啊
    • 系统好卡.哪个程序死循环了
    • 弹性计算,抗住双十一

    docker核心技术

    标准化,标准化,标准化
    build ship run

    1. 构建镜像发布到仓库
    2. 去仓库拉镜像到本地
    3. 把本地的镜像运行起来,运行中容器中

    docker仓库镜像

    • 联合分层文件系统

    • 容器
      其实就是一个虚拟机进程

    • 仓库
      hub.docker.com

    docker 安装

    https://yq.aliyun.com/articles/110806?spm=5176.8351553.0.0.5d4e1991URD8Ia

    # step 1: 安装必要的一些系统工具
    sudo apt-get update
    sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
    # step 2: 安装GPG证书
    curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
    # Step 3: 写入软件源信息
    sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
    # Step 4: 更新并安装 Docker-CE
    sudo apt-get -y update
    sudo apt-get -y install docker-ce
    

    docker初体验

    参数要写到镜像的前面

    docker pull xxx:TAG
    docker images  //显示本地安装了哪些镜像
    docker pull hello-world  //拉取镜像
    docker run hello-world  //运行镜像
    docker rmi  //移出镜像
    docker pull ubuntu
    docker run ubuntu echo hello world
    

    docker 运行nginx

    • 复杂的持久运行的容器
    • 前台运行& 后台运行
    • 进入容器内部
    docker ps  //显示正在运行的镜像
    docker ps -a //查看所用运行过的容器 包括状态
    
    docker run nginx -d   //后台运行镜像
    
    docker exec -it cli bash 
    
    

    docker 网络

    -p 让容器的端口跟主机对应起来

    docker run -p 80:80 nginx //把容器80端口和主机80对应
    

    dockerfile

    FROM xxx:latest
    MAINTAINER zzh
    CMD echo helloworld

    hyperledger环境搭建

    1. 安装xshell
      http://www.netsarang.com/products/xsh_overview.html

    2. 购买阿里云服务器

      使用Ubuntu14.04版操作

      乞丐版1核1G, 便宜好用.

    3. 安装git

    apt-get update //更新软件源 不更新的话可能下载的软件版本会很旧
    apt-get install git
    


    1. 安装docker-ce

    请不要直接apt-get 安装docker, 这会安装docker的旧版本
    如果安装了docker的旧版本,请卸载
    参考文档
    https://yq.aliyun.com/articles/110806?spm=5176.8351553.0.0.5d4e1991URD8Ia

    curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
    

    1. 安装hyperledger的工具和docker镜像
      官方文档:
      http://hyperledger-fabric.readthedocs.io/en/release-1.1/samples.html#binaries
    curl -sSL https://goo.gl/6wtTN5 | bash -s 1.1.0
    

    goo.gl短地址被墙, 服务器需要FQ. 或者直接采用下面解析后的地址
    https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh
    https://raw.githubusercontent.com/cscjoke/note/master/Hyperledger/bootstrap.sh




    有几个镜像下载失败, 原因是0.4.10的 zookeeper 和 kafka couchdb并没有同步到仓库,zookeeper和Kafka的0.4.6版本可以拉取
    fabric-ca1.2版本也没有同步到仓库
    .

    curl -sSL https://raw.githubusercontent.com/cscjoke/note/master/Hyperledger/bootstrap.sh | bash -s 1.1.0  //使用自定义的脚本
    

    全套环境搞定后 截图如下

    脚本默认下载好了 fabirc-sample

    切换到fabirc-sample目录

    1. 生成创始区块,channel的配置文件
    ./byfn.sh -m generate
    

    1. 启动fabirc的测试网络
    ./byfn.sh -m up
    


    启动失败, 查看报错日志 很容易理解
    hyperledger是一个区块链网络, 有很多个节点需要被启动起来, 需要使用docker compose来启动一组机器,并且组网.

    1. 安装docker compose
    curl -L https://github.com/docker/compose/releases/download/1.20.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
    chmod +x /usr/local/bin/docker-compose
    

    参考文档 https://github.com/docker/compose/releases

    1. 解决网络报错问题
      阿里云的服务器是改良过的linux服务器, 里面有一句网络超时的配置需要注释掉,
      注意,如果是原版的Ubuntu服务器或者用腾讯云,aws的服务器, 这个错误是不会出现的
    编辑/etc/resolv.conf 
    注释掉 options timeout:2 attempts:3 rotate single-request-reopen 
    


    注释掉箭头指向的一行

    1. 重启fabirc网络
    ./byfn.sh -m down
    ./byfn.sh -m up
    

    如果看到 all good, BYFN execution completed.
    end 这样的信息, 说明你的hyperledger fabirc的环境是没有问题了. 一定要保证你可以看到这个信息,
    否则后续的课程, 没法正常进行.

    过程详解

    1. 启动6台节点(每个节点可以理解为一台电脑)

    org1 机构1里面的peer0 和 peer1
    org2 机构2里面的peer0 和 peer1
    orderer是排序节点
    cli 是client(命令行客户端,后续cli进行的操作会替换成java,或者node sdk的调用)

    1. 创建channel

    2. 让每个peer加入channel

    • org1的peer0加入

    • org1的peer1加入

    • org2的peer0加入

    • org2的peer1加入

    • 更新锚节点 (anchor peer)

    • 锚节点的作用就是让两个不同的机构(org)可以彼此通讯

    • 在org1的peer0上安装链码(智能合约)

    • 在org2的peer0上安装链码


    • 在org2的peer0上实例化链码

    • 在org1的peer0上执行查询


    • 在org1的peer0上执行invoke事物 进行转账

    • 在org2的peer1上安装链码

    • 在org2的peer1上进行查询

    • 大功告成

  • 相关阅读:
    Tomcat虚拟目录的映射方式
    Linux常用命令
    java断点调试
    破解MyEclipse
    JS判断浏览器
    css3 box-sizing详解。
    this-使用call . apply
    this-内部函数
    this-对象方法调用
    this-纯函数
  • 原文地址:https://www.cnblogs.com/xiaocongcong888/p/9554118.html
Copyright © 2011-2022 走看看