美文网首页区块链研习社区块链hyperledger fabric
fabric 1.4网络搭建以及fabric浏览器搭建

fabric 1.4网络搭建以及fabric浏览器搭建

作者: xiangyue | 来源:发表于2020-04-30 13:14 被阅读0次

    1. fabric网络搭建

    环境准备

    1. 一台空闲服务器,需要安装docker和go环境,安装步骤自行百度
    2. 点击下载fabric-samples源代码
    3. 将fabric-samples的分支切换到release-1.4,然后进行打包,上传到服务器上

    安装fabric网络

    生成配置文件

    在服务器上对fabric-samples进行解压,并切换到fabric-samples/first-network目录下,执行命令./byfn.sh generate,控制台输入Y或者回车,即可完成配置文件生成,然后出现一堆信息,控制台找不到了,从官网截了个图

    fabric_byfn.png

    具体的步骤可以看byfn.sh中的内容

    fabric_byfn_generate.png
    主要是生成证书和替换密钥文件,最后一步是创建channelArtifacts
    fabric_byfn_channelartifacts.png
    看这命令是不是有点熟悉,其实就是你的控制台输出,默认CONSENSUS_TYPEsolo,主要就是创建锚节点然后更新transactions

    启动网络

    fabric-samples/first-network目录下执行命令./byfn.sh up,控制台输入Y或者回车,就会出现如下的输出

    fabric_docker_up.png
    具体逻辑可以看byfn.sh,大概意思就是docker创建了几个容器,创建OrdererMSP,Org1MSP以及Org2MSP,然后创建节点和通道,然后让节点加入通道
    fabric_docker_ps.png
    是否安装完成的如下图
    fabric_docker_end.png

    注意将first-network目录下的crypto-config目录进行打包,并下载到本地,区块链浏览器会进行使用

    进行peer节点操作

    查询启动的容器,我们可以看到有个cli的容器,它是可以操作peer节点的容器,我们只需要进入cli容器即可进行peer节点的操作

    1. 进入cli容器
      docker exec -it cli bash
    2. 进行操作
      点击查看peer命令,查看peer版本执行peer version
      fabric_peer_version.png
      查看peer的通道有哪些,执行 peer channel list
      fabric_peer_channel.png

    2. fabric浏览器搭建

    环境准备

    点击下载fabric-explorer源代码,或者下载汉化版fabric-explorer-cn,记得阅读README.md文件

    代码依赖安装和编译

    进入下载目录,例如使用fabric-explorer-cn,则进入fabric-explorer-cn,然后执行命令./main.sh install,等待执行完成,时间较久,如果要清除node_modules的话,可以执行./main.sh clean

    数据库配置文件修改

    如果进行数据库地址修改的话,可以编辑app/explorerconfig.json文件,修改postgreSQL字段下的host等信息,注意你的pg数据库要有对应的账户和schema,然后进入app/persistence/fabric/postgreSQL/db/explorerpg.sql,将脚本进行整理,并在数据库执行,文末提供sql内容,或者是使用README.md推荐的在本地执行./createdb.sh进行pg创建

    区块链浏览器配置文件修改

    编辑根目录下的appconfig.json文件,如果需要别人访问你的浏览器的话,就将host改为自己的ip地址,如果端口冲突的话,就修改port

    fabric客户端配置

    app/platform/fabric/config.json文件中,可以看到引用的profile为./connection-profile/first-network.json,打开同目录的connection-profile/first-network.json文件,进行修改,看到有很多参数,其实里面很多我们都可以不用管,只需要修改证书文件路径,还记得上面说让下载的crypto-config目录到本地吗,将如下几个地方修改成自己的路径即可

    注意path要全部换掉,因为有可能adminPrivateKey的path最后生成的sk文件的hash不一样

    blockchain_explorer_first_network.png

    配置hosts域名映射

    在自己的hosts文件中,新增两个域名映射,即orderer.example.compeer0.org1.example.com都映射到自己的服务器ip上

    blockchain_explorer_hosts.png

    配置启动脚本

    编写根目录下的start.shsyncstart.sh文件,将他们的export DISCOVERY_AS_LOCALHOST=true,改成export DISCOVERY_AS_LOCALHOST=false,当然如果你的fabric网络运行在你本机的话,就使用默认的即可

    启动区块链浏览器

    打开控制台,执行./start.sh,logs/app/app.log是查看应用日志,logs/console/console.log是查看控制台的,logs/db/db.log是查看数据库日志

    访问区块链浏览器

    打开浏览器,输入localhost:8080,或者是你在appconfig.json文件中配置的host:port进行访问,输入用户名admin以及密码adminpw,点击登录即可进入区块链浏览器主页

    blockchain_explorer_overview.png

    3.fabric-explorer sql

    --
    --    SPDX-License-Identifier: Apache-2.0
    
    -- ----------------------------
    --  Table structure for `blocks`
    -- ----------------------------
    DROP TABLE IF EXISTS blocks;
    
    CREATE TABLE blocks
    (
      id SERIAL PRIMARY KEY,
      blocknum integer DEFAULT NULL,
      datahash character varying(256) DEFAULT NULL,
      prehash character varying(256) DEFAULT NULL,
      txcount integer DEFAULT NULL,
      createdt Timestamp DEFAULT NULL,
      prev_blockhash character varying(256) DEFAULT NULL,
      blockhash character varying(256) DEFAULT NULL,
      channel_genesis_hash character varying(256) DEFAULT NULL,
      blksize integer DEFAULT NULL
    );
    
    -- ----------------------------
    --  Table structure for `chaincodes`
    -- ----------------------------
    DROP TABLE IF EXISTS chaincodes;
    
    CREATE TABLE chaincodes
    (
      id SERIAL PRIMARY KEY,
      name character varying(255) DEFAULT NULL,
      version character varying(255) DEFAULT NULL,
      path character varying(255) DEFAULT NULL,
      channel_genesis_hash character varying(256) DEFAULT NULL,
      txcount integer DEFAULT 0,
      createdt Timestamp DEFAULT NULL
    );
    
    Alter sequence chaincodes_id_seq restart with 10;
    
    -- ---------------------------
    --  Table structure for `peer_ref_chaincode`
    -- ----------------------------
    DROP TABLE IF EXISTS peer_ref_chaincode;
    
    CREATE TABLE peer_ref_chaincode
    (
      id SERIAL PRIMARY KEY,
      peerid varchar(64) DEFAULT NULL,
      chaincodeid varchar(64) DEFAULT NULL,
      cc_version varchar(64) DEFAULT NULL,
      channelid character varying(256) DEFAULT NULL,
      createdt Timestamp DEFAULT NULL
    );
    
    -- ----------------------------
    --  Table structure for `channel`
    -- ----------------------------
    DROP TABLE IF EXISTS channel;
    
    --   state character(1) NOT NULL DEFAULT A CHECK (state in (A, D, S))
    
    CREATE TABLE channel
    (
      id SERIAL PRIMARY KEY,
      name varchar(256) DEFAULT NULL,
      blocks integer DEFAULT NULL,
      trans integer DEFAULT NULL,
      createdt Timestamp DEFAULT NULL,
      channel_genesis_hash character varying(256) DEFAULT NULL,
      channel_hash character varying(256) DEFAULT NULL,
      channel_config bytea default NULL,
      channel_block bytea DEFAULT NULL,
      channel_tx bytea DEFAULT NULL,
      channel_version character varying(128) DEFAULT NULL
    );
    
    Alter sequence channel_id_seq restart with 3;
    -- ----------------------------
    --  Table structure for `peer`
    -- ----------------------------
    DROP TABLE IF EXISTS peer;
    
    --   state character(1) NOT NULL DEFAULT A CHECK (state in (A, D, S))
    
    CREATE TABLE peer
    (
      id SERIAL PRIMARY KEY,
      org integer DEFAULT NULL,
      channel_genesis_hash character varying(256) DEFAULT NULL,
      mspid varchar(64) DEFAULT NULL,
      requests varchar(64) DEFAULT NULL,
      events varchar(64) DEFAULT NULL,
      server_hostname varchar(64) DEFAULT NULL,
      createdt timestamp DEFAULT NULL,
      peer_type character varying(64) DEFAULT NULL
    );
    -- ---------------------------
    --  Table structure for `peer_ref_channel`
    -- ----------------------------
    DROP TABLE IF EXISTS peer_ref_channel;
    
    CREATE TABLE peer_ref_channel
    (
      id SERIAL PRIMARY KEY,
      createdt Timestamp DEFAULT NULL,
      peerid varchar(64),
      channelid character varying(256),
      peer_type character varying(64) DEFAULT NULL
    );
    
    -- ====================Orderer BE-303=====================================
    -- ----------------------------
    --  Table structure for `orderer`
    -- ----------------------------
    DROP TABLE IF EXISTS orderer;
    
    --   state character(1) NOT NULL DEFAULT A CHECK (state in (A, D, S))
    
    CREATE TABLE orderer
    (
      id SERIAL PRIMARY KEY,
      requests varchar(64) DEFAULT NULL,
      server_hostname varchar(64) DEFAULT NULL,
      createdt timestamp DEFAULT NULL
    );
    
    --// ====================Orderer BE-303=====================================
    -- ----------------------------
    --  Table structure for `transactions`
    -- ----------------------------
    DROP TABLE IF EXISTS transactions;
    CREATE TABLE transactions
    (
      id SERIAL PRIMARY KEY,
      blockid integer DEFAULT NULL,
      txhash character varying(256) DEFAULT NULL,
      createdt timestamp DEFAULT NULL,
      chaincodename character varying(255) DEFAULT NULL,
      status integer DEFAULT NULL,
      creator_msp_id character varying(128) DEFAULT NULL,
      endorser_msp_id character varying(800) DEFAULT NULL,
      chaincode_id character varying(256) DEFAULT NULL,
      type character varying(128) DEFAULT NULL,
      read_set json default NULL,
      write_set json default NULL,
      channel_genesis_hash character varying(256) DEFAULT NULL,
      validation_code character varying(50) DEFAULT NULL,
      envelope_signature character varying DEFAULT NULL,
      payload_extension character varying DEFAULT NULL,
      creator_id_bytes character varying DEFAULT NULL,
      creator_nonce character varying DEFAULT NULL,
      chaincode_proposal_input character varying DEFAULT NULL,
      tx_response character varying DEFAULT NULL,
      payload_proposal_hash character varying DEFAULT NULL,
      endorser_id_bytes character varying DEFAULT NULL,
      endorser_signature character varying DEFAULT NULL
    );
    
    Alter sequence transactions_id_seq restart with 6;
    
    DROP TABLE IF EXISTS write_lock;
    CREATE TABLE write_lock
    (
      write_lock SERIAl PRIMARY KEY
    );
    
    Alter sequence write_lock_write_lock_seq restart with 2;
    
    DROP INDEX IF EXISTS blocks_blocknum_idx;
    CREATE INDEX ON Blocks
    (blocknum);
    
    DROP INDEX IF EXISTS blocks_channel_genesis_hash_idx;
    CREATE INDEX ON Blocks
    (channel_genesis_hash);
    
    DROP INDEX IF EXISTS blocks_createdt_idx;
    CREATE INDEX ON Blocks
    (createdt);
    
    DROP INDEX IF EXISTS transaction_txhash_idx;
    CREATE INDEX ON Transactions
    (txhash);
    
    DROP INDEX IF EXISTS transaction_channel_genesis_hash_idx;
    CREATE INDEX ON Transactions
    (channel_genesis_hash);
    
    DROP INDEX IF EXISTS transaction_createdt_idx;
    CREATE INDEX ON Transactions
    (createdt);
    
    DROP INDEX IF EXISTS transaction_blockid_idx;
    CREATE INDEX ON Transactions
    (blockid);
    
    DROP INDEX IF EXISTS transaction_chaincode_proposal_input_idx;
    CREATE INDEX ON Transactions
    ((md5
    (chaincode_proposal_input)));
    
    DROP INDEX IF EXISTS channel_channel_genesis_hash_idx;
    CREATE INDEX ON channel
    (channel_genesis_hash);
    
    DROP INDEX IF EXISTS channel_channel_hash_idx;
    CREATE INDEX ON channel
    (channel_hash);
    

    相关文章

      网友评论

        本文标题:fabric 1.4网络搭建以及fabric浏览器搭建

        本文链接:https://www.haomeiwen.com/subject/yehzwhtx.html