Fabric实战(8)Fabric模块配置参数详解-peer

peer模块是Fabric中最重要的模块,也是在Fabric系统使用最多的模块。peer模块在Fabric中被称为节点模块,主要负责存储区块链数据、运行链码、提供对外服务接口等作用。

1 peer模块命令和参数

Usage:
  peer [flags]
  peer [command]

Available Commands:
  chaincode   #操作链码,相关子命令: install|instantiate|invoke|package|query|signpackage|upgrade.
  channel     #操作通道,相关子命令: create|fetch|join|list|update.
  logging     #操作日志,相关子命令: getlevel|setlevel|revertlevels.
  node        #节点服务,相关子命令: start|status.
  version     #打印版本信息

Flags:
      --logging-level string       #日志级别
      --test.coverprofile string   #测试配置文件
  -v, --version                    #显示当前服务器的版本

2 peer模块的配置选项

peer模块的配置选项可以通过环境变量或者配置文件的方式来配置,在具体操作中,如果是通过Docker方式启动,一般使用环境变量配置方式。如果是采用直接命令启动,一般是采用配置文件方式

环境变量的配置示例如下:

注意:下面的环境变量配置信息仅供参考,并不完整

 	  export set CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock   
      export set CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=host
      export set CORE_LOGGING_LEVEL=DEBUG
      export set CORE_PEER_TLS_ENABLED=true
      export set CORE_PEER_GOSSIP_USELEADERELECTION=true
      export set CORE_PEER_GOSSIP_ORGLEADER=false
      export set CORE_PEER_PROFILE_ENABLED=false
      export set CORE_PEER_TLS_CERT_FILE=/home/zym/fabric-ws/simple-demo/crypto-config/peerOrganizations/org1.simple-network.com/peers/peer0.org1.simple-network.com/tls/server.crt
      export set CORE_PEER_TLS_KEY_FILE=/home/zym/fabric-ws/simple-demo/crypto-config/peerOrganizations/org1.simple-network.com/peers/peer0.org1.simple-network.com/tls/server.key
      export set CORE_PEER_TLS_ROOTCERT_FILE=/home/zym/fabric-ws/simple-demo/crypto-config/peerOrganizations/org1.simple-network.com/peers/peer0.org1.simple-network.com/tls/ca.crt

配置文件示例如下:

注意:这个示例就是《Fabric实战(2)运行一个简单的fabric网络(容器外)》的core.yaml文件

logging:

    peer:       debug

    cauthdsl:   warning
    gossip:     warning
    ledger:     info
    msp:        warning
    policies:   warning
    grpc:       error

    format: '%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}'

peer:

    id: peer0.org1.simple-network.com
    networkId: dev
    listenAddress: 0.0.0.0:7051
    address: peer0.org1.simple-network.com:7051
    chaincodeListenAddress: 0.0.0.0:7052
    addressAutoDetect: false
    gomaxprocs: -1

    gossip:
        bootstrap: 127.0.0.1:7051
        useLeaderElection: true
        orgLeader: false
        endpoint:
        maxBlockCountToStore: 100
        maxPropagationBurstLatency: 10ms
        maxPropagationBurstSize: 10
        propagateIterations: 1
        propagatePeerNum: 3
        pullInterval: 4s
        pullPeerNum: 3
        requestStateInfoInterval: 4s
        publishStateInfoInterval: 4s
        stateInfoRetentionInterval:
        publishCertPeriod: 10s
        skipBlockVerification: false
        dialTimeout: 3s
        connTimeout: 2s
        recvBuffSize: 20
        sendBuffSize: 200
        digestWaitTime: 1s
        requestWaitTime: 1s
        responseWaitTime: 2s
        aliveTimeInterval: 5s
        aliveExpirationTimeout: 25s
        reconnectInterval: 2
        externalEndpoint: peer0.org1.simpe-network.com:7051
        election:
            startupGracePeriod: 15s
            membershipSampleInterval: 1s
            leaderAliveThreshold: 10s
            leaderElectionDuration: 5s
        pvtData:
            maxPeers: 3
            minAck: 3

    events:
        address: 0.0.0.0:7053
        buffersize: 100
        timeout: 10ms

    tls:
        enabled:  false
        cert:
            file: /home/zym/fabric-ws/simple-demo/crypto-config/peerOrganizations/org1.simple-network.com/peers/peer0.org1.simple-network.com/tls/server.crt
        key:
            file: /home/zym/fabric-ws/simple-demo/crypto-config/peerOrganizations/org1.simple-network.com/peers/peer0.org1.simple-network.com/tls/server.key
        rootcert:
            file: /home/zym/fabric-ws/simple-demo/crypto-config/peerOrganizations/org1.simple-network.com/peers/peer0.org1.simple-network.com/tls/ca.crt

        serverhostoverride:
    fileSystemPath: /home/zym/fabric-ws/simple-demo/peer0-org1/production

    BCCSP:
        Default: SW
        SW:
            Hash: SHA2
            Security: 256
            FileKeyStore:
                KeyStore:

    mspConfigPath: /home/zym/fabric-ws/simple-demo/crypto-config/peerOrganizations/org1.simple-network.com/peers/peer0.org1.simple-network.com/msp

    localMspId: Org1MSP

    profile:
        enabled:     false
        listenAddress: 0.0.0.0:6060
    handlers:
        authFilter: "DefaultAuth"
        decorator: "DefaultDecorator"

vm:

    endpoint: unix:///var/run/docker.sock

    docker:
        tls:
            enabled: false
            ca:
                file: docker/ca.crt
            cert:
                file: docker/tls.crt
            key:
                file: docker/tls.key

        attachStdout: false

        hostConfig:
            NetworkMode: host
            Dns:
            LogConfig:
                Type: json-file
                Config:
                    max-size: "50m"
                    max-file: "5"
            Memory: 2147483648

chaincode:
    peerAddress:

    id:
        path:
        name:

    builder: $(DOCKER_NS)/fabric-ccenv:$(ARCH)-$(PROJECT_VERSION)

    golang:
        runtime: $(BASE_DOCKER_NS)/fabric-baseos:$(ARCH)-$(BASE_VERSION)

    car:
        runtime: $(BASE_DOCKER_NS)/fabric-baseos:$(ARCH)-$(BASE_VERSION)

    java:
        Dockerfile:  | from $(DOCKER_NS)/fabric-javaenv:$(ARCH)-$(PROJECT_VERSION)

    startuptimeout: 300s

    executetimeout: 30s

    mode: net

    keepalive: 0

    system:
        cscc: enable
        lscc: enable
        escc: enable
        vscc: enable
        qscc: enable

    logging:
      level:  info
      shim:   warning
      format: '%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}'

ledger:
  blockchain:

  state:
    stateDatabase: goleveldb
    couchDBConfig:
       couchDBAddress: 127.0.0.1:5984
       username:
       password:
       maxRetries: 3
       maxRetriesOnStartup: 10
       requestTimeout: 35s
       queryLimit: 10000

  history:
    enableHistoryDatabase: true

2.1 peer模块配置文件详解

peer的配置文件的默认名为core.yaml,配置文件分为logging、peer、vm、chaincode、ledger这5大部分。各部分相关属性如下所示。

2.1.1 配置文件中logging相关的属性

longing节点定义了peer模块中所有模块的日志级别和日志格式。
日志级别:critical、error、warning、notice、info、debug

logging:

    peer:       debug

    cauthdsl:   warning
    gossip:     warning
    ledger:     info
    msp:        warning
    policies:   warning
    grpc:       error

    format: '%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}'

2.1.2 peer相关的配置

peer:
	#节点的编号
    id: peer0.org1.simple-network.com 
    #节点的网络编号
    networkId: dev
    #节点监听地址
    listenAddress: 0.0.0.0:7051
    #节点访问地址
    address: peer0.org1.simple-network.com:7051
    #chaincode监听地址
    chaincodeListenAddress: 0.0.0.0:7052
    #对等端是否应以编程方式确定其地址
    addressAutoDetect: false
    #peer最大可用cpu数, -1表示用默认值
    gomaxprocs: -1

    gossip:
    	#启动节点后向哪些节点发起gossip连接加入网络,本节点需要和所连接节点同属一个组织
        bootstrap: 127.0.0.1:7051
        #是否开启主节点自动选举
        useLeaderElection: true
        #是否将当前节点配置成主节点
        orgLeader: false
        #当前节点在组织内的gossip id,默认为peer.address
        endpoint:
        #保存到内存中的区块个数上限,超过则丢弃
        maxBlockCountToStore: 100
        #保存消息的最大时间,超过则触发转发给其他节点
        maxPropagationBurstLatency: 10ms
        #保存消息最大个数,超过则转发给其他节点
        maxPropagationBurstSize: 10
        #消息转发次数
        propagateIterations: 1
        #消息转发给指定个数的节点
        propagatePeerNum: 3
        #拉去消息时间间隔
        pullInterval: 4s
        #从指定个数的节点拉取消息
        pullPeerNum: 3
        #从节点拉取状态信息消息间隔
        requestStateInfoInterval: 4s
        #向其他节点推送状态信息消息的间隔
        publishStateInfoInterval: 4s
        #状态消息的超时时间
        stateInfoRetentionInterval:
        #启动后在心跳消息中嵌入证书的等待时间
        publishCertPeriod: 10s
        #是否不对区块消息进行校验,默认为false
        skipBlockVerification: false
        #gRPC连接拨号的超时时间
        dialTimeout: 3s
        #建立连接的超时时间
        connTimeout: 2s
        #接收消息缓冲区大小
        recvBuffSize: 20
        #发送消息缓冲区大小
        sendBuffSize: 200
        #处理摘要数据的等待时间
        digestWaitTime: 1s
        #处理nonce数据的等待时间
        requestWaitTime: 1s
        #终止拉取数据的等待时间
        responseWaitTime: 2s
        #心跳发送间隔时间
        aliveTimeInterval: 5s
        #心跳雄安锡的超时时间
        aliveExpirationTimeout: 25s
        #断线后重连的时间间隔
        reconnectInterval: 2
        #节点配组织外感知的地址,默认为空,表示不被外部感知
        externalEndpoint: peer0.org1.simpe-network.com:7051
        election:
            startupGracePeriod: 15s
            membershipSampleInterval: 1s
            leaderAliveThreshold: 10s
            leaderElectionDuration: 5s
        pvtData:
            maxPeers: 3
            minAck: 3

    events:
    	#事件监听地址
        address: 0.0.0.0:7053
        #事件消息缓存数,超过该值则被阻塞
        buffersize: 100
        #队列阻塞的超时时间
        timeout: 10ms

    tls:
        #是否使能tls通信
        enabled:  false
        #服务器身份验证证书
        cert:
            file: /home/zym/fabric-ws/simple-demo/crypto-config/peerOrganizations/org1.simple-network.com/peers/peer0.org1.simple-network.com/tls/server.crt
        #服务器私钥
        key:
            file: /home/zym/fabric-ws/simple-demo/crypto-config/peerOrganizations/org1.simple-network.com/peers/peer0.org1.simple-network.com/tls/server.key
        #服务器根证书
        rootcert:
            file: /home/zym/fabric-ws/simple-demo/crypto-config/peerOrganizations/org1.simple-network.com/peers/peer0.org1.simple-network.com/tls/ca.crt
		#tls握手时指定服务器名称
        serverhostoverride:
    #账本数据文件存放路径
    fileSystemPath: /home/zym/fabric-ws/simple-demo/peer0-org1/production
	#加密机制相关的配置
    BCCSP:
        Default: SW
        SW:
            Hash: SHA2
            Security: 256
            FileKeyStore:
                KeyStore:
	#当前节点的msp路径
    mspConfigPath: /home/zym/fabric-ws/simple-demo/crypto-config/peerOrganizations/org1.simple-network.com/peers/peer0.org1.simple-network.com/msp
	#当前节点名称
    localMspId: Org1MSP
	
    profile:
   		#是否开启了go profile
        enabled:     false
        #go profile获取地址
        listenAddress: 0.0.0.0:6060
    handlers:
        authFilter: "DefaultAuth"
        decorator: "DefaultDecorator"

2.1.3 vm相关的配置

vm:
	#docker服务器的daemon的地址
    endpoint: unix:///var/run/docker.sock
    docker:
        tls:
        	#是否启动docker的tls通信
            enabled: false
            ca:
                file: docker/ca.crt
            cert:
                file: docker/tls.crt
            key:
                file: docker/tls.key
		#是否将docker的消息绑定到指定的输出
        attachStdout: false

        hostConfig:
            #chaincode容器的网络命名模式
            NetworkMode: host
            Dns:
            LogConfig:
            	#docker日志配置信息
                Type: json-file
                Config:
                    max-size: "50m"
                    max-file: "5"
            Memory: 2147483648

2.1.4 chaincode相关的配置

chaincode:
	#chaincode中peer服务器地址
    peerAddress:

    id:
        path:
        name:
	#本地编译环境为docker镜像
    builder: $(DOCKER_NS)/fabric-ccenv:$(ARCH)-$(PROJECT_VERSION)
	#go语言版本的chaincode的基础镜像
    golang:
        runtime: $(BASE_DOCKER_NS)/fabric-baseos:$(ARCH)-$(BASE_VERSION)
	#car格式的chaincode生成镜像文件时的基础镜像
    car:
        runtime: $(BASE_DOCKER_NS)/fabric-baseos:$(ARCH)-$(BASE_VERSION)
	#java版本的chaincode基础镜像
    java:
        Dockerfile:  | from $(DOCKER_NS)/fabric-javaenv:$(ARCH)-$(PROJECT_VERSION)
	#启动chaincode容器时的超时时间,超过这个时间认为启动失败
    startuptimeout: 300s
	#执行Invoke和Init方法时的超时时间,超过这个时间认定执行失败
    executetimeout: 30s
	#chaincode运行模式,net为网络模式,dev为开发模式,dev模式下,可以在容器外运行chaincode
    mode: net
	#peer节点和chaincode节点的心跳时间的保持时间,如果这个之小于等于0,相当于关闭心跳保持
    keepalive: 0
	
	#系统chaincode的开关
    system:
        cscc: enable
        lscc: enable
        escc: enable
        vscc: enable
        qscc: enable
	
	#chaincode的模块日志级别和日志格式
    logging:
      level:  info
      shim:   warning
      format: '%{color}%{time:2006-01-02 15:04:05.000 MST} [%{module}] %{shortfunc} -> %{level:.4s} %{id:03x}%{color:reset} %{message}'

2.1.5 ledger相关的配置

ledger:
  blockchain:

  state:
  	#数据库类型,目前支持golevedb和CouchDB
    stateDatabase: goleveldb
    #如果上面配置了CouchDB,则下面couchDB相关的配置生效
    couchDBConfig:
       couchDBAddress: 127.0.0.1:5984
       username:
       password:
       maxRetries: 3
       maxRetriesOnStartup: 10
       requestTimeout: 35s
       queryLimit: 10000
	
  #是否使能历史状态数据库
  history:
    enableHistoryDatabase: true

你可能感兴趣的:(Fabric)