concept orderer.yaml in category hyperledger

This is an excerpt from Manning's book Programming Hyperledger Fabric: Creating Permissioned Blockchains.
The next thing to verify is that you have an
orderer.yamlfile in the$/three-org-networkdirectory which is used by the orderer to read config settings when it is launched. The orderer is run by executing theorderercommand but before you do that, there are a number of settings you have to configure. There are several ways to do this. The settings can be configured in theorderer.yamlfile by editing it. They can also be configured using environment variables. The environment variables will override any settings inorderer.yaml. There is no right or wrong method; you decide what works for you. Table 4.1 shows the settings to be configured as environment variables and what values they should take before you start the orderer. Every environment variable in Table 4.1 with the exception ofFABRIC_CFG_PATHhas a counterpart inorderer.yaml. Let’s take an example and pickORDERER_GENERAL_BOOTSTRAPFILE. This environment variable is made up of three words or tokens -ORDERER,GENERALandBOOTSTRAPFILE- separated by underscores. The first token maps toorderer.yaml. The second token maps toGeneralsection insideorderer.yaml. And the third token maps toBootstrapFilesubsection underGeneralsection. So instead of setting the environment variable, one could instead editGeneral.BootstrapFileinorderer.yaml.Table 4.1. Environment variables to be set before running
orderer. They can be set inline or can be exported or theorderer.yamlcan be edited instead.
Setting Value Explanation FABRIC_CFG_PATH $PWD There should be an orderer.yamlfile underFABRIC_CFG_PATH. If this file is not found you will get an error. $PWD is a built-in shell variable that returns the present working directory. We can also use.as substitute for $PWD. In our case, $PWD should resolve to$/three-org-network.ORDERER_GENERAL_BOOTSTRAPFILE foo.block Path of the genesis block needed to bootstrap an orderer. ORDERER_GENERAL_BOOTSTRAPMETHOD file Set the method by which the genesis block will be provided to the orderer. ORDERER_GENERAL_TLS_ENABLED false Disable TLS when communicating with peer nodes and client applications. ORDERER_GENERAL_LISTENADDRESS 0.0.0.0 This should be set to 0.0.0.0for orderer to accept incoming connections from any computer. When you are running everything locally you could set it to127.0.0.1and things will still work, but in production you should set it to0.0.0.0ORDERER_GENERAL_LISTENPORT 7050 A port is needed in addition to an address to form a complete endpoint where communication can take place. ORDERER_GENERAL_LOCALMSPID BiotorMSP This should match the MSP ID of orderer used in configtx.yaml.ORDERER_GENERAL_LOCALMSPDIR $PWD/crypto-config/peerOrganizations/biotor.com/peers/orderer0.biotor.com/msp The orderer will run under the identity given by this directory. Remember that although the orderer is a machine, it still has an identity just like a real life person. We generated this identity using cryptogen.ORDERER_FILELEDGER_LOCATION $PWD/orderer0.biotor.com The orderer will store its data under this directory. By default the location is /var/hyperledger/production/ordererand is set inorderer.yamlunderFileLedger.Location. The orderer will attempt to create the directory if it does not exist. If the directory already exists (for example, if you are re-starting the orderer from a previous run), theordererwill use what it finds in it.ORDERER_CONSENSUS_WALDIR $PWD/orderer0.biotor.com/etcdraft/wal These settings provide path to directories where the Raft based orderer writes data. At this stage in our journey, we can treat these directories as black boxes. However if you are curious, refer to orderer.yamlfor explanation of what these directories contain.ORDERER_CONSENSUS_SNAPDIR $PWD/orderer0.biotor.com/etcdraft/snapshot ORDERER_OPERATIONS_LISTENADDRESS 0.0.0.0:8443 This can also be considered as a black box. The only thing we need to worry about is specifying a distinct and unique ORDERER_OPERATIONS_LISTENADDRESSfor each orderer that we will be running otherwise there will be an error if an orderer tries to use a port that is already in use by someone else.ORDERER_GENERAL_CLUSTER_LISTENADDRESS 0.0.0.0 Provide the address and port where the orderer will listen to connections from other ordering nodes. ORDERER_GENERAL_CLUSTER_LISTENPORT 7070 ORDERER_GENERAL_CLUSTER_SERVERCERTIFICATE ./crypto-config/peerOrganizations/biotor.com/peers/orderer0.biotor.com/tls/server.crt These settings provide the TLS certificate and private key to use when the orderer is acting as a server. ORDERER_GENERAL_CLUSTER_SERVERPRIVATEKEY ./crypto-config/peerOrganizations/biotor.com/peers/orderer0.biotor.com/tls/server.key ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE ./crypto-config/peerOrganizations/biotor.com/peers/orderer0.biotor.com/tls/server.crt These settings provide the TLS certificate and private key to use when the orderer is acting as a client. ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY ./crypto-config/peerOrganizations/biotor.com/peers/orderer0.biotor.com/tls/server.key Table 4.1 only contains a subset of the overall orderer settings. We refer the reader to
orderer.yamlfor full list. The file also contains helpful comments behind each setting. The environment variables can be set inline or can be exported in accordance with standard Unix principles. Listing 4.6 shows how to run the orderer when you have configured everything inorderer.yaml:Listing 4.6. Command to run
orderer. Method 1 - all the orderer settings with exception ofFABRIC_CFG_PATHare defined inorderer.yaml.$ ordererListing 4.7 shows how to run the orderer using inline environment variables which would override any settings in
orderer.yaml. The entire code in Listing 4.7 is one single command and we have used ellipses (…) to indicate that we are skipping listing all the environment variables of Table 4.1 for brevity. Otherwise Listing 4.7 will become a 2 page code listing. Since we have quite a few environment variables, we break up the command into multiple lines using the\character. Take care there should be no whitespace after\otherwise you will get an error.Listing 4.7. Command to run
orderer. Method 2 - use inline environment variables to override default settings inorderer.yaml.$ FABRIC_CFG_PATH=$PWD \ ORDERER_GENERAL_BOOTSTRAPFILE=foo.block \ ... ordererAnd finally, Listing 4.8 shows how to run the orderer using exported environment variables. Like the inline environment variables, the exported environment variables override any settings in
orderer.yaml. The difference between inline and exported variables is that whereas inline variables are good only for the command in which they appear, when variables are exported they get set for the entire session. That is, they will apply to all subsequent commands in that shell session. So they are a great way to set those variables which otherwise you will need to set again and again. But be aware of unintended consequences. Whereas the code in Listing 4.7 was a single command, the code in Listing 4.8 is multiple commands. [121]Listing 4.8. Command to run
orderer. Method 3 - use exported environment variables which will apply to entire session and override settings inorderer.yaml.$ export FABRIC_CFG_PATH=$PWD $ export ORDERER_GENERAL_BOOTSTRAPFILE=foo.block ... $ orderer