github.com/hyperledger-gerrit-archive/fabric-ca@v2.0.0-alpha.0.20190916143245-4cd4192f0366+incompatible/docs/source/operations_guide.rst (about)

     1  Fabric CA Operation's Guide
     2  ============================
     3  
     4  This guide will illustrate how to use Fabric CA to setup
     5  a Fabric network. All identities that participate on a Hyperledger Fabric
     6  blockchain network must be authorized. This authorization
     7  is provided in the form of cryptographic material that is
     8  verified against trusted authorities.
     9  
    10  In this guide, you will see the process for setting up a
    11  blockchain network that includes two organizations, each with two peers
    12  and an orderer. You'll see how to generate cryptographic material for orderers,
    13  peers, administrators, and end users so that private keys never leave
    14  the host or container where they are generated.
    15  
    16  Topology
    17  ---------
    18  
    19  In this example, we will look at how to setup up an orderer, peers, and CAs
    20  across three organizations. The topology of this deployment can be seen in the
    21  image below:
    22  
    23  .. image:: ./images/network_topology.png
    24  
    25  This example will simulate a deployment using docker containers. The
    26  containers will be treated as if they are running on different host machines.
    27  This is done so that you can see which assets need to be exchanged out-of-band
    28  between the parties involved in the network.
    29  
    30  The network configuration for docker assumes that all containers are running in
    31  the same network. If your deployment is spread across different networks, the
    32  example will be need to be adjusted to work with your network configurations.
    33  
    34  The documentation below breaks down the docker-compose file to talk about individual
    35  components. To see the entire docker-compose, click :doc:`here <docker_compose>`.
    36  
    37  .. toctree::
    38    :maxdepth: 2
    39  
    40  Setup CAs
    41  ----------
    42  
    43  Download fabric-ca-client binary
    44  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    45  
    46  For each host that needs to acquire cryptographic material, you will need to have the
    47  fabric-ca-client binary available on the host machine. The client will be used to
    48  connect to the Fabric CA server container.
    49  
    50  To download the fabric-ca-client binary, browse to this  `repository <https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric-ca/hyperledger-fabric-ca/>`_ and
    51  select the latest binary for your machine.
    52  
    53  
    54  .. note:: This example is using version 1.4.0 of fabric-ca-client.
    55  
    56  Setup TLS CA
    57  ^^^^^^^^^^^^^^
    58  
    59  A TLS CA is used to issue TLS certificates.  These certificates are required in
    60  order to secure the communication between various processes.
    61  
    62  In order to simplify this example, all organizations will use the same TLS CA
    63  and TLS mutual authentication is disabled.
    64  
    65  .. note:: In a production environment, you will probably use your organization's CA
    66            to get TLS certificates. You will have to transfer out-of-band your CA's
    67            certificate with organizations that will validate your TLS certificates.
    68  
    69  A docker service, such as the one below can be used to a launch a Fabric TLS CA
    70  container.
    71  
    72  .. code:: yaml
    73  
    74    ca-tls:
    75      container_name: ca-tls
    76      image: hyperledger/fabric-ca
    77      command: sh -c 'fabric-ca-server start -d -b tls-ca-admin:tls-ca-adminpw --port 7052'
    78      environment:
    79        - FABRIC_CA_SERVER_HOME=/tmp/hyperledger/fabric-ca/crypto
    80        - FABRIC_CA_SERVER_TLS_ENABLED=true
    81        - FABRIC_CA_SERVER_CSR_CN=ca-tls
    82        - FABRIC_CA_SERVER_CSR_HOSTS=0.0.0.0
    83        - FABRIC_CA_SERVER_DEBUG=true
    84      volumes:
    85        - /tmp/hyperledger/tls/ca:/tmp/hyperledger/fabric-ca
    86      networks:
    87        - fabric-ca
    88      ports:
    89        - 7052:7052
    90  
    91  This container can be started using the following docker command.
    92  
    93  .. code:: bash
    94  
    95      docker-compose up ca-tls
    96  
    97  On a successful launch of the container, you will see the following line in
    98  the CA container's log.
    99  
   100  .. code:: bash
   101  
   102     [INFO] Listening on https://0.0.0.0:7052
   103  
   104  At this point the TLA CA server is on a listening on a secure socket, and can start
   105  issuing TLS certificates.
   106  
   107  Enroll TLS CA's Admin
   108  ~~~~~~~~~~~~~~~~~~~~~~~
   109  
   110  Before you can start using the CA client, you must acquire the signing
   111  certificate for the CA's TLS certificate. This is a required step before you
   112  can connect using TLS.
   113  
   114  In our example, you would need to acquire the file located at ``/tmp/hyperledger/tls/ca/crypto/ca-cert.pem``
   115  on the machine running the TLS CA server and copy this file over to the host where
   116  you will be running the CA client binary. This certificate, also known as the TLS
   117  CA's signing certificate is going to be used to validate the TLS certificate of
   118  the CA. Once the certificate has been copied over to the CA client's host
   119  machine, you can start issuing commands using the CA.
   120  
   121  The TLS CA's signing certificate will need to be available on each host that will run
   122  commands against the TLS CA.
   123  
   124  The TLS CA server was started with a bootstrap identity which has full admin
   125  privileges for the server. One of the key abilities of the admin
   126  is the ability to register new identities. The administrator for this CA will
   127  use the Fabric CA client to register four new identities with the CA, one for
   128  each peer and one for the orderer. These identities will be used to get TLS
   129  certificates for peers and orderers.
   130  
   131  You will issue the commands below to enroll the TLS CA admin and then register
   132  identities. We assume the trusted root certificate for the TLS CA has been copied
   133  to ``/tmp/hyperledger/tls-ca/crypto/tls-ca-cert.pem`` on all host machines that
   134  will communicate with this CA via the fabric-ca-client.
   135  
   136  .. code:: bash
   137  
   138     export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/tls-ca/crypto/tls-ca-cert.pem
   139     export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/tls-ca/admin
   140     fabric-ca-client enroll -d -u https://tls-ca-admin:tls-ca-adminpw@0.0.0.0:7052
   141     fabric-ca-client register -d --id.name peer1-org1 --id.secret peer1PW --id.type peer -u https://0.0.0.0:7052
   142     fabric-ca-client register -d --id.name peer2-org1 --id.secret peer2PW --id.type peer -u https://0.0.0.0:7052
   143     fabric-ca-client register -d --id.name peer1-org2 --id.secret peer1PW --id.type peer -u https://0.0.0.0:7052
   144     fabric-ca-client register -d --id.name peer2-org2 --id.secret peer2PW --id.type peer -u https://0.0.0.0:7052
   145     fabric-ca-client register -d --id.name orderer1-org0 --id.secret ordererPW --id.type orderer -u https://0.0.0.0:7052
   146  
   147  .. note:: If the path of the environment variable FABRIC_CA_CLIENT_TLS_CERTFILES is not
   148            an absolute path, it will be parsed as relative to the client's home directory.
   149  
   150  With the identities registered on the TLS CA, we can move forward to setting up the
   151  each organization's network. Anytime we need to get TLS certificates for a node in an
   152  organization, we will refer to this CA.
   153  
   154  Setup Orderer Org CA
   155  ~~~~~~~~~~~~~~~~~~~~~
   156  
   157  Each organization must have it's own Certificate Authority (CA) for
   158  issuing enrollment certificates. The CA will issue the certificates
   159  for each of the peers and clients in the organization.
   160  
   161  Your CA creates the identities that belong to your organization and issue
   162  each identity a public and private key. These keys are what allow all of your
   163  nodes and applications to sign and verify their actions. Any identity signed
   164  by your CA will be understood by other members of the network to identify the
   165  components that belong to your organization.
   166  
   167  An administrator for Org0 will launch a Fabric CA docker container, which
   168  will be used by Org0 to issue cryptographic material for identities in Org0.
   169  
   170  A docker service such as the one below can be used to a launch a Fabric CA
   171  container.
   172  
   173  .. code:: yaml
   174  
   175     rca-org0:
   176        container_name: rca-org0
   177        image: hyperledger/fabric-ca
   178        command: /bin/bash -c 'fabric-ca-server start -d -b rca-org0-admin:rca-org0-adminpw --port 7053'
   179        environment:
   180           - FABRIC_CA_SERVER_HOME=/tmp/hyperledger/fabric-ca/crypto
   181           - FABRIC_CA_SERVER_TLS_ENABLED=true
   182           - FABRIC_CA_SERVER_CSR_CN=rca-org0
   183           - FABRIC_CA_SERVER_CSR_HOSTS=0.0.0.0
   184           - FABRIC_CA_SERVER_DEBUG=true
   185        volumes:
   186           - /tmp/hyperledger/org0/ca:/tmp/hyperledger/fabric-ca
   187        networks:
   188           - fabric-ca
   189        ports:
   190           - 7053:7053
   191  
   192  On a successful launch of the container, you will see the following line in
   193  the CA container's log.
   194  
   195  .. code:: bash
   196  
   197     [INFO] Listening on https://0.0.0.0:7053
   198  
   199  At this point the CA server is listening on a secure socket, and can start
   200  issuing cryptographic material.
   201  
   202  Enroll Orderer Org's CA Admin
   203  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   204  
   205  You will issue the commands below to enroll the CA admin and then register
   206  both of Org0's identities.
   207  
   208  In the commands below, we will assume the trusted root certificate for the CA's
   209  TLS certificate has been copied to
   210  ``/tmp/hyperledger/org0/ca/crypto/ca-cert.pem``
   211  on the host machine where the fabric-ca-client binary is present.
   212  If the client binary is located on a different host, you will need to get
   213  the signing certificate through an out-of-band process.
   214  
   215  The following identities will be registered:
   216     - Orderer (orderer1-org0)
   217     - Orderer admin (admin-org0)
   218  
   219  .. code:: bash
   220  
   221      export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org0/ca/crypto/ca-cert.pem
   222      export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org0/ca/admin
   223      fabric-ca-client enroll -d -u https://rca-org0-admin:rca-org0-adminpw@0.0.0.0:7053
   224      fabric-ca-client register -d --id.name orderer1-org0 --id.secret ordererpw --id.type orderer -u https://0.0.0.0:7053
   225      fabric-ca-client register -d --id.name admin-org0 --id.secret org0adminpw --id.type admin --id.attrs "hf.Registrar.Roles=client,hf.Registrar.Attributes=*,hf.Revoker=true,hf.GenCRL=true,admin=true:ecert,abac.init=true:ecert" -u https://0.0.0.0:7053
   226  
   227  The enroll command you executed above, would have populated the
   228  ``/tmp/hyperledger/org0/ca/admin`` directory with the cryptographic material
   229  issued form the CA. You will see files such as the ones below:
   230  
   231  .. code:: text
   232  
   233     admin
   234     ├── fabric-ca-client-config.yaml
   235     └── msp
   236        ├── IssuerPublicKey
   237        ├── IssuerRevocationPublicKey
   238        ├── cacerts
   239        │   └── 0-0-0-0-7053.pem
   240        ├── keystore
   241        │   └── 60b6a16b8b5ba3fc3113c522cce86a724d7eb92d6c3961cfd9afbd27bf11c37f_sk
   242        ├── signcerts
   243        │   └── cert.pem
   244        └── user
   245  
   246  The ``fabric-ca-client-config.yaml`` is a file that is generated by the CA client,
   247  this file contains the configuration of the CA client. There are three other important files
   248  to note. First one is ``0-0-0-0-7053.pem``, this is the public certificate of the
   249  CA that issued the certificate for this identity. Second is ``60b6a16b8b5ba3fc3113c522cce86a724d7eb92d6c3961cfd9afbd27bf11c37f_sk``,
   250  this is the private key that was generated by the client. The name of this file
   251  is variable and will be different everytime a key is generated. The last item is ``cert.pem``,
   252  this is the certificate of the admin was that was signed and issued by the CA.
   253  
   254  Setup Org1's CA
   255  ~~~~~~~~~~~~~~~~~
   256  
   257  The same set of steps you performed for Org0 apply to Org1's CA.
   258  
   259  An administrator for Org1 will launch a Fabric CA docker container, which
   260  will be used by Org1 to issue cryptographic material for identities in Org1.
   261  
   262  A docker service, such as the one below can be used to a launch a Fabric CA
   263  container.
   264  
   265  .. code:: yaml
   266  
   267     rca-org1:
   268        container_name: rca-org1
   269        image: hyperledger/fabric-ca
   270        command: /bin/bash -c 'fabric-ca-server start -d -b rca-org1-admin:rca-org1-adminpw'
   271        environment:
   272           - FABRIC_CA_SERVER_HOME=/tmp/hyperledger/fabric-ca/crypto
   273           - FABRIC_CA_SERVER_TLS_ENABLED=true
   274           - FABRIC_CA_SERVER_CSR_CN=rca-org1
   275           - FABRIC_CA_SERVER_CSR_HOSTS=0.0.0.0
   276           - FABRIC_CA_SERVER_DEBUG=true
   277        volumes:
   278           - /tmp/hyperledger/org1/ca:/tmp/hyperledger/fabric-ca
   279        networks:
   280           - fabric-ca
   281        ports:
   282           - 7054:7054
   283  
   284  On a successful launch of the container, you will see the following line in
   285  the CA container's log.
   286  
   287  .. code:: bash
   288  
   289     [INFO] Listening on https://0.0.0.0:7054
   290  
   291  At this point the CA server is listening on a secure socket, and can start
   292  issuing cryptographic material.
   293  
   294  Enroll Org1's CA Admin
   295  ^^^^^^^^^^^^^^^^^^^^^^^
   296  
   297  You will issue the commands below to enroll the CA admin and then register
   298  both of Org1's identities.
   299  
   300  The following identies are being registered:
   301     - Peer 1 (peer1-org1)
   302     - Peer 2 (peer2-org1)
   303     - Admin (admin1-org1)
   304     - End user (user-org1)
   305  
   306  In the commands below, we will assume the trusted root certificate for the CA's
   307  TLS certificate has been copied to
   308  ``/tmp/hyperledger/org1/ca/crypto/ca-cert.pem``
   309  on the host machine where the fabric-ca-client binary is present.
   310  If the client's binary is located on a different host, you will need to get the
   311  signing certificate through an out-of-band process.
   312  
   313  .. code:: bash
   314  
   315      export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org1/ca/crypto/ca-cert.pem
   316      export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org1/ca/admin
   317      fabric-ca-client enroll -d -u https://rca-org1-admin:rca-org1-adminpw@0.0.0.0:7054
   318      fabric-ca-client register -d --id.name peer1-org1 --id.secret peer1PW --id.type peer -u https://0.0.0.0:7054
   319      fabric-ca-client register -d --id.name peer2-org1 --id.secret peer2PW --id.type peer -u https://0.0.0.0:7054
   320      fabric-ca-client register -d --id.name admin-org1 --id.secret org1AdminPW --id.type user -u https://0.0.0.0:7054
   321      fabric-ca-client register -d --id.name user-org1 --id.secret org1UserPW --id.type user -u https://0.0.0.0:7054
   322  
   323  Setup Org2's CA
   324  ~~~~~~~~~~~~~~~~~
   325  
   326  The same set of steps that you followed for Org1 apply to Org2. So we will quickly
   327  go through the set of steps that the administrator for Org2 will perform.
   328  
   329  A docker service, such as the one below can be used to a launch a Fabric CA for
   330  Org2.
   331  
   332  .. code:: yaml
   333  
   334    rca-org2:
   335      container_name: rca-org2
   336      image: hyperledger/fabric-ca
   337      command: /bin/bash -c 'fabric-ca-server start -d -b rca-org2-admin:rca-org2-adminpw --port 7055'
   338      environment:
   339        - FABRIC_CA_SERVER_HOME=/tmp/hyperledger/fabric-ca/crypto
   340        - FABRIC_CA_SERVER_TLS_ENABLED=true
   341        - FABRIC_CA_SERVER_CSR_CN=rca-org2
   342        - FABRIC_CA_SERVER_CSR_HOSTS=0.0.0.0
   343        - FABRIC_CA_SERVER_DEBUG=true
   344      volumes:
   345        - /tmp/hyperledger/org2/ca:/tmp/hyperledger/fabric-ca
   346      networks:
   347        - fabric-ca
   348      ports:
   349        - 7055:7055
   350  
   351  On a successful launch of the container, you will see the following line in
   352  the CA container's log.
   353  
   354  .. code:: bash
   355  
   356     [INFO] Listening on https://0.0.0.0:7055
   357  
   358  At this point the CA server is listening on a secure socket, and can start
   359  issuing cryptographic material.
   360  
   361  Enrolling Org2's CA Admin
   362  ^^^^^^^^^^^^^^^^^^^^^^^^^^
   363  
   364  You will issue the commands below to get the CA admin enrolled and all peer
   365  related identities registered. In the commands below, we will assume the trusted
   366  root certificate of CA's TLS certificate has been copied to
   367  ``/tmp/hyperledger/org2/ca/crypto/ca-cert.pem``.
   368  
   369  .. code:: bash
   370  
   371      export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org2/ca/crypto/ca-cert.pem
   372      export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org2/ca/admin
   373      fabric-ca-client enroll -d -u https://rca-org2-admin:rca-org2-adminpw@0.0.0.0:7055
   374      fabric-ca-client register -d --id.name peer1-org2 --id.secret peer1PW --id.type peer -u https://0.0.0.0:7055
   375      fabric-ca-client register -d --id.name peer2-org2 --id.secret peer2PW --id.type peer -u https://0.0.0.0:7055
   376      fabric-ca-client register -d --id.name admin-org2 --id.secret org2AdminPW --id.type user -u https://0.0.0.0:7055
   377      fabric-ca-client register -d --id.name user-org2 --id.secret org2UserPW --id.type user -u https://0.0.0.0:7055
   378  
   379  Setup Peers
   380  -----------------
   381  
   382  Once the CAs are up and running, we can start enrolling peers.
   383  
   384  Setup Org1's Peers
   385  ^^^^^^^^^^^^^^^^^^^
   386  
   387  An administrator for Org1 will enroll the peers with it's CA and then launch the
   388  peer docker containers. Before you can start up a peer, you will need to enroll
   389  the peer identities with the CA to get the MSP that the peer will use.
   390  This is known as the local peer MSP.
   391  
   392  Enroll Peer1
   393  ~~~~~~~~~~~~~
   394  
   395  If the host machine running Peer1 does not have the fabric-ca-client binary,
   396  refer to the instructions above on to download the binary.
   397  
   398  In the command below, we will assume the trusted root certificate of Org1 has
   399  been copied to ``/tmp/hyperledger/org1/peer1/assets/ca/org1-ca-cert.pem``
   400  on Peer1's host machine. Acquiring of the signing certificate is an out of
   401  band process.
   402  
   403  .. code:: bash
   404  
   405      export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org1/peer1
   406      export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org1/peer1/assets/ca/org1-ca-cert.pem
   407      fabric-ca-client enroll -d -u https://peer1-org1:peer1PW@0.0.0.0:7054
   408  
   409  Next step is to get the TLS cryptographic material for the peer. This requires another enrollment,
   410  but this time you will enroll against the ``tls`` profile on the TLS CA. You will
   411  also need to provide the address of the Peer1's host machine in the enrollment
   412  request as the input to the ``csr.hosts`` flag. In the command below, we will
   413  assume the certificate of the TLS CA has been copied to
   414  ``/tmp/hyperledger/org1/peer1/assets/tls-ca/tls-ca-cert.pem``
   415  on Peer1's host machine.
   416  
   417  .. code:: bash
   418  
   419      export FABRIC_CA_CLIENT_MSPDIR=tls-msp
   420      export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org1/peer1/assets/tls-ca/tls-ca-cert.pem
   421      fabric-ca-client enroll -d -u https://peer1-org1:peer1PW@0.0.0.0:7052 --enrollment.profile tls --csr.hosts peer1-org1
   422  
   423  Go to path ``/tmp/hyperledger/org1/peer1/tls-msp/keystore`` and change the name of
   424  the key to ``key.pem``. This will make it easy to be able to refer to in
   425  later steps.
   426  
   427  At this point, you will have two MSP directories. One MSP contains peer's enrollment
   428  certificate and the other has the peer's TLS certificate. However, there needs to be
   429  an additional folder added in the enrollment MSP directory, and this is the ``admincerts``
   430  folder. This folder will contain certificate(s) for the administrator of Org1.
   431  We will talk more about this when we enroll Org1's admin a little further down.
   432  
   433  Enroll Peer2
   434  ~~~~~~~~~~~~~
   435  
   436  You will perform similar commands for Peer2. In the commands below, we will
   437  assume the trusted root certificate of Org1 has been copied to
   438  ``/tmp/hyperledger/org1/peer2/assets/ca/org1-ca-cert.pem`` on Peer2's host
   439  machine.
   440  
   441  .. code:: bash
   442  
   443      export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org1/peer2
   444      export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org1/peer2/assets/ca/org1-ca-cert.pem
   445      fabric-ca-client enroll -d -u https://peer2-org1:peer2PW@0.0.0.0:7054
   446  
   447  Next step is to get the TLS cryptographic material for the peer. This requires another enrollment,
   448  but this time you will enroll against the ``tls`` profile on the TLS CA. You will
   449  also need to provide the address of the Peer2's host machine in the enrollment
   450  request as the input to the ``csr.hosts`` flag. In the command below, we will
   451  assume the certificate of the TLS CA has been copied to
   452  ``/tmp/hyperledger/org1/peer2/assets/tls-ca/tls-ca-cert.pem``
   453  on Peer2's host machine.
   454  
   455  .. code:: bash
   456  
   457      export FABRIC_CA_CLIENT_MSPDIR=tls-msp
   458      export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org1/peer2/assets/tls-ca/tls-ca-cert.pem
   459      fabric-ca-client enroll -d -u https://peer2-org1:peer2PW@0.0.0.0:7052 --enrollment.profile tls --csr.hosts peer2-org1
   460  
   461  Go to path ``/tmp/hyperledger/org1/peer2/tls-msp/keystore`` and change the name of
   462  the key to ``key.pem``. This will make it easy to be able to refer to in
   463  later steps.
   464  
   465  At this point, you will have two MSP directories. One MSP contains peer's enrollment
   466  certificate and the other has the peer's TLS certificate. You will add the
   467  ``admincerts`` folder to the enrollment MSP once the admin has been enrolled.
   468  
   469  Enroll Org1's Admin
   470  ~~~~~~~~~~~~~~~~~~~~
   471  
   472  At this point, both peers have been enrolled. Now, you will enroll
   473  Org1's admin identity. The admin identity is responsible for activities such as
   474  installing and instantiating chaincode. The steps below will enroll the admin.
   475  The commands below assumes that this is being executed on Peer1's host machine.
   476  
   477  .. code:: bash
   478  
   479      export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org1/admin
   480      export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org1/peer1/assets/ca/org1-ca-cert.pem
   481      export FABRIC_CA_CLIENT_MSPDIR=msp
   482      fabric-ca-client enroll -d -u https://admin-org1:org1AdminPW@0.0.0.0:7054
   483  
   484  After enrollment, you should have an admin MSP. You will copy the
   485  certificate from this MSP and move it to the Peer1's MSP in the ``admincerts``
   486  folder. You will need to disseminate this admin certificate to other peers in the
   487  org, and it will need to go in to the ``admincerts`` folder of each peers' MSP.
   488  
   489  The command below is only for Peer1, the exchange of the admin certificate to Peer2 will
   490  happen out-of-band.
   491  
   492  .. code:: bash
   493  
   494      mkdir /tmp/hyperledger/org1/peer1/msp/admincerts
   495      cp /tmp/hyperledger/org1/admin/msp/signcerts/cert.pem /tmp/hyperledger/org1/peer1/msp/admincerts/org1-admin-cert.pem
   496  
   497  If the ``admincerts`` folder is missing from the peer's local MSP, the peer will
   498  fail to start up.
   499  
   500  Launch Org1's Peers
   501  ~~~~~~~~~~~~~~~~~~~~
   502  
   503  Once we have enrolled all the peers and org admin, we have the necessary MSPs to
   504  start the peers.
   505  
   506  A docker service, such as the one below can be used to a launch a container for
   507  Peer1.
   508  
   509  .. code:: yaml
   510  
   511    peer1-org1:
   512      container_name: peer1-org1
   513      image: hyperledger/fabric-peer
   514      environment:
   515        - CORE_PEER_ID=peer1-org1
   516        - CORE_PEER_ADDRESS=peer1-org1:7051
   517        - CORE_PEER_LOCALMSPID=org1MSP
   518        - CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org1/peer1/msp
   519        - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
   520        - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=guide_fabric-ca
   521        - FABRIC_LOGGING_SPEC=debug
   522        - CORE_PEER_TLS_ENABLED=true
   523        - CORE_PEER_TLS_CERT_FILE=/tmp/hyperledger/org1/peer1/tls-msp/signcerts/cert.pem
   524        - CORE_PEER_TLS_KEY_FILE=/tmp/hyperledger/org1/peer1/tls-msp/keystore/key.pem
   525        - CORE_PEER_TLS_ROOTCERT_FILE=/tmp/hyperledger/org1/peer1/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem
   526        - CORE_PEER_GOSSIP_USELEADERELECTION=true
   527        - CORE_PEER_GOSSIP_ORGLEADER=false
   528        - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1-org1:7051
   529        - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true
   530      working_dir: /opt/gopath/src/github.com/hyperledger/fabric/org1/peer1
   531      volumes:
   532        - /var/run:/host/var/run
   533        - /tmp/hyperledger/org1/peer1:/tmp/hyperledger/org1/peer1
   534      networks:
   535        - fabric-ca
   536  
   537  Launching the peer service will bring up a peer container, and in the logs you will
   538  see the following line:
   539  
   540  .. code:: bash
   541  
   542     serve -> INFO 020 Started peer with ID=[name:"peer1-org1" ], network ID=[dev], address=[peer1-org1:7051]
   543  
   544  A docker service, such as the one below can be used to a launch a container for
   545  Peer2.
   546  
   547  .. code:: yaml
   548  
   549    peer2-org1:
   550      container_name: peer2-org1
   551      image: hyperledger/fabric-peer
   552      environment:
   553        - CORE_PEER_ID=peer2-org1
   554        - CORE_PEER_ADDRESS=peer2-org1:7051
   555        - CORE_PEER_LOCALMSPID=org1MSP
   556        - CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org1/peer2/msp
   557        - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
   558        - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=guide_fabric-ca
   559        - FABRIC_LOGGING_SPEC=grpc=debug:info
   560        - CORE_PEER_TLS_ENABLED=true
   561        - CORE_PEER_TLS_CERT_FILE=/tmp/hyperledger/org1/peer2/tls-msp/signcerts/cert.pem
   562        - CORE_PEER_TLS_KEY_FILE=/tmp/hyperledger/org1/peer2/tls-msp/keystore/key.pem
   563        - CORE_PEER_TLS_ROOTCERT_FILE=/tmp/hyperledger/org1/peer2/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem
   564        - CORE_PEER_GOSSIP_USELEADERELECTION=true
   565        - CORE_PEER_GOSSIP_ORGLEADER=false
   566        - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer2-org1:7051
   567        - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true
   568        - CORE_PEER_GOSSIP_BOOTSTRAP=peer1-org1:7051
   569      working_dir: /opt/gopath/src/github.com/hyperledger/fabric/org1/peer2
   570      volumes:
   571        - /var/run:/host/var/run
   572        - /tmp/hyperledger/org1/peer2:/tmp/hyperledger/org1/peer2
   573      networks:
   574        - fabric-ca
   575  
   576  Launching the peer service will bring up a peer container, and in the logs you
   577  will see the following line:
   578  
   579  .. code:: bash
   580  
   581      serve -> INFO 020 Started peer with ID=[name:"peer2-org1" ], network ID=[dev], address=[peer2-org1:7051]
   582  
   583  Setup Org2's Peers
   584  ^^^^^^^^^^^^^^^^^^^^
   585  
   586  An administrator for Org2 will use the CA's bootstrap identity to enroll the peers
   587  with the CA and then launch the peer docker containers.
   588  
   589  Enroll Peer1
   590  ~~~~~~~~~~~~
   591  
   592  You will issue the commands below to enroll Peer1. In the commands below,
   593  we will assume the trusted root certificate of Org2 is available at
   594  ``/tmp/hyperledger/org2/peer1/assets/ca/org2-ca-cert.pem`` on Peer1's host machine.
   595  
   596  .. code:: bash
   597  
   598      export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org2/peer1
   599      export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org2/peer1/assets/ca/org2-ca-cert.pem
   600      fabric-ca-client enroll -d -u https://peer1-org2:peer1PW@0.0.0.0:7055
   601  
   602  Next, you will get the TLS certificate. In the command below, we will assume the
   603  certificate of the TLS CA has been copied to ``/tmp/hyperledger/org2/peer1/assets/tls-ca/tls-ca-cert.pem``
   604  on Peer1's host machine.
   605  
   606  .. code:: bash
   607  
   608      export FABRIC_CA_CLIENT_MSPDIR=tls-msp
   609      export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org2/peer1/assets/tls-ca/tls-ca-cert.pem
   610      fabric-ca-client enroll -d -u https://peer1-org2:peer1PW@0.0.0.0:7052 --enrollment.profile tls --csr.hosts peer1-org2
   611  
   612  Go to path ``/tmp/hyperledger/org2/peer1/tls-msp/keystore`` and change the name of the
   613  key to ``key.pem``.
   614  
   615  Enroll Peer2
   616  ~~~~~~~~~~~~
   617  
   618  You will issue the commands below to get Peer2 enrolled. In the commands below,
   619  we will assume the trusted root certificate of Org2 is available at
   620  ``/tmp/hyperledger/org2/peer2/tls/org2-ca-cert.pem`` on Peer2's host machine.
   621  
   622  .. code:: bash
   623  
   624      export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org2/peer2
   625      export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org2/peer2/assets/ca/org2-ca-cert.pem
   626      fabric-ca-client enroll -d -u https://peer2-org2:peer2PW@0.0.0.0:7055
   627  
   628  Next, you will get the TLS certificate. In the command below, we will assume the
   629  certificate of the TLS CA has been copied to ``/tmp/hyperledger/org2/peer2/assets/tls-ca/tls-ca-cert.pem``
   630  on Peer2's host machine.
   631  
   632  .. code:: bash
   633  
   634      export FABRIC_CA_CLIENT_MSPDIR=tls-msp
   635      export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org2/peer2/assets/tls-ca/tls-ca-cert.pem
   636      fabric-ca-client enroll -d -u https://peer2-org2:peer2PW@0.0.0.0:7052 --enrollment.profile tls --csr.hosts peer2-org2
   637  
   638  Go to path ``/tmp/hyperledger/org2/peer2/tls-msp/keystore`` and change the name
   639  of the key to ``key.pem``.
   640  
   641  Enroll Org2's Admin
   642  ~~~~~~~~~~~~~~~~~~~~~
   643  
   644  At this point, you will have two MSP directories. One MSP contains your enrollment
   645  certificate and the other has your TLS certificate. However, there needs be one
   646  additional folder added in the enrollment MSP directory, and this is the ``admincerts``
   647  folder. This folder will contain certificates for the administrator of org2.
   648  You will enroll the org2 admin's identity by issuing the commands below.
   649  
   650  .. code:: bash
   651  
   652      export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org2/admin
   653      export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org1/peer1/tls/org1-ca-cert.pem
   654      export FABRIC_CA_CLIENT_MSPDIR=msp
   655      fabric-ca-client enroll -d -u https://admin-org2:org2AdminPW@0.0.0.0:7055
   656  
   657  After enrollment, you should have an admin MSP. You will copy the certifcate from
   658  this MSP and move it to the peer MSP under the ``admincerts`` folder. The commands
   659  below are only for Peer1, the exchange of admin cert to peer2 will happen out-of-band.
   660  
   661  .. code:: bash
   662  
   663      mkdir /tmp/hyperledger/org2/peer1/msp/admincerts
   664      cp /tmp/hyperledger/org2/admin/msp/signcerts/cert.pem /tmp/hyperledger/org2/peer1/msp/admincerts/org2-admin-cert.pem
   665  
   666  If the ``admincerts`` folder is missing from the peer's local MSP, the peer will
   667  fail to start up.
   668  
   669  Launch Org2's Peers
   670  ~~~~~~~~~~~~~~~~~~~~
   671  
   672  Once we have enrolled all the peers and admin, we have the necessary MSPs to
   673  start the peers.
   674  
   675  A docker service, such as the one below can be used to a launch a container for
   676  the peer1.
   677  
   678  .. code:: yaml
   679  
   680    peer1-org2:
   681      container_name: peer1-org2
   682      image: hyperledger/fabric-peer
   683      environment:
   684        - CORE_PEER_ID=peer1-org2
   685        - CORE_PEER_ADDRESS=peer1-org2:7051
   686        - CORE_PEER_LOCALMSPID=org2MSP
   687        - CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org2/peer1/msp
   688        - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
   689        - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=guide_fabric-ca
   690        - FABRIC_LOGGING_SPEC=debug
   691        - CORE_PEER_TLS_ENABLED=true
   692        - CORE_PEER_TLS_CERT_FILE=/tmp/hyperledger/org2/peer1/tls-msp/signcerts/cert.pem
   693        - CORE_PEER_TLS_KEY_FILE=/tmp/hyperledger/org2/peer1/tls-msp/keystore/key.pem
   694        - CORE_PEER_TLS_ROOTCERT_FILE=/tmp/hyperledger/org2/peer1/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem
   695        - CORE_PEER_GOSSIP_USELEADERELECTION=true
   696        - CORE_PEER_GOSSIP_ORGLEADER=false
   697        - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1-org2:7051
   698        - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true
   699      working_dir: /opt/gopath/src/github.com/hyperledger/fabric/org2/peer1
   700      volumes:
   701        - /var/run:/host/var/run
   702        - /tmp/hyperledger/org2/peer1:/tmp/hyperledger/org2/peer1
   703      networks:
   704        - fabric-ca
   705  
   706  Launching the peer service will bring up a peer container, and in the logs you
   707  will see the following line:
   708  
   709  .. code:: bash
   710  
   711     serve -> INFO 020 Started peer with ID=[name:"peer1-org2" ], network ID=[dev], address=[peer1-org2:7051]
   712  
   713  A docker service, such as the one below can be used to a launch a container for
   714  the peer1.
   715  
   716  .. code:: yaml
   717  
   718    peer2-org2:
   719      container_name: peer2-org2
   720      image: hyperledger/fabric-peer
   721      environment:
   722        - CORE_PEER_ID=peer2-org2
   723        - CORE_PEER_ADDRESS=peer2-org2:7051
   724        - CORE_PEER_LOCALMSPID=org2MSP
   725        - CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org2/peer2/msp
   726        - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
   727        - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=guide_fabric-ca
   728        - FABRIC_LOGGING_SPEC=debug
   729        - CORE_PEER_TLS_ENABLED=true
   730        - CORE_PEER_TLS_CERT_FILE=/tmp/hyperledger/org2/peer2/tls-msp/signcerts/cert.pem
   731        - CORE_PEER_TLS_KEY_FILE=/tmp/hyperledger/org2/peer2/tls-msp/keystore/key.pem
   732        - CORE_PEER_TLS_ROOTCERT_FILE=/tmp/hyperledger/org2/peer2/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem
   733        - CORE_PEER_GOSSIP_USELEADERELECTION=true
   734        - CORE_PEER_GOSSIP_ORGLEADER=false
   735        - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer2-org2:7051
   736        - CORE_PEER_GOSSIP_SKIPHANDSHAKE=true
   737        - CORE_PEER_GOSSIP_BOOTSTRAP=peer1-org2:7051
   738      working_dir: /opt/gopath/src/github.com/hyperledger/fabric/org2/peer2
   739      volumes:
   740        - /var/run:/host/var/run
   741        - /tmp/hyperledger/org2/peer2:/tmp/hyperledger/org2/peer2
   742      networks:
   743        - fabric-ca
   744  
   745  Launching the peer service will bring up a peer container, and in the logs you
   746  will see the following line:
   747  
   748  .. code:: bash
   749  
   750      serve -> INFO 020 Started peer with ID=[name:"peer2-org2" ], network ID=[dev], address=[peer2-org2:7052]
   751  
   752  Setup Orderer
   753  ---------------
   754  
   755  The last thing we need to setup is the orderer. We need to take a couple
   756  of actions before we can start up the orderer.
   757  
   758  Enroll Orderer
   759  ^^^^^^^^^^^^^^^
   760  
   761  Before starting the orderer, you will need to enroll the orderer's identity with a
   762  CA to get the MSP that the orderer will use. This is known as the local orderer
   763  MSP.
   764  
   765  If the host machine does not have the fabric-ca-client binary, please refer to
   766  the instructions above on to download the binary.
   767  
   768  You will issue the commands below to get the orderer enrolled. In the commands
   769  below, we will assume the trusted root certificates for Org0 is available in
   770  ``/tmp/hyperledger/org0/orderer/assets/ca/org0-ca-cert.pem`` on the orderer's
   771  host machine.
   772  
   773  .. code:: bash
   774  
   775      export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org0/orderer
   776      export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org0/orderer/assets/ca/org0-ca-cert.pem
   777      fabric-ca-client enroll -d -u https://orderer-org0:ordererPW@0.0.0.0:7056
   778  
   779  Next, you will get the TLS certificate. In the command below, we will assume the
   780  certificate of the TLS CA has been copied to ``/tmp/hyperledger/org0/orderer/assets/tls-ca/tls-ca-cert.pem``
   781  on Orderer's host machine.
   782  
   783  .. code:: bash
   784  
   785      export FABRIC_CA_CLIENT_MSPDIR=tls-msp
   786      export FABRIC_CA_CLIENT_TLS_CERTFILES=/tmp/hyperledger/org0/orderer/assets/tls-ca/tls-ca-cert.pem
   787      fabric-ca-client enroll -d -u https://orderer-org0:ordererPW@0.0.0.0:7052 --enrollment.profile tls --csr.hosts orderer1-org0
   788  
   789  Go to path ``/tmp/hyperledger/org0/orderer/tls-msp/keystore`` and change the name
   790  of the key to ``key.pem``.
   791  
   792  At this point, you will have two MSP directories. One MSP contains your enrollment
   793  certificate and the other has your TLS certificate. However, there needs be one
   794  additional folder added in the enrollment MSP directory, this is the ``admincerts``
   795  folder. This folder will contain certificates for the administrator of peer 1.
   796  Now, you will enroll the Org0's admin identity by issuing the commands below.
   797  
   798  Enroll Org0's Admin
   799  ^^^^^^^^^^^^^^^^^^^^
   800  
   801  The command below assumes that this is being executed on the orderer's host machine.
   802  
   803  .. code:: bash
   804  
   805      export FABRIC_CA_CLIENT_HOME=/tmp/hyperledger/org0/admin
   806      export FABRIC_CA_CLIENT_MSPDIR=msp
   807      fabric-ca-client enroll -d -u https://orderer-org0-admin:ordererAdminPW@0.0.0.0:7056
   808  
   809  After enrollment, you should have an msp folder at ``/tmp/hyperledger/org0/admin``.
   810  You will copy the certificate from this MSP and move it to the orderer's MSP under the
   811  ``admincerts`` folder.
   812  
   813  .. code:: bash
   814  
   815      mkdir /tmp/hyperledger/org0/orderer/msp/admincerts
   816      cp /tmp/hyperledger/org0/admin/msp/signcerts/cert.pem /tmp/hyperledger/org0/orderer/msp/admincerts/orderer-admin-cert.pem
   817  
   818  Create Genesis Block and Channel Transaction
   819  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   820  
   821  The orderer requires a genesis block that it uses to bootstrap itself.
   822  You can find more information in the `Hyperledger Fabric documentation <https://hyperledger-fabric.readthedocs.io/en/release-1.4/configtx.html?channel-configuration-configtx>`_
   823  
   824  In documentation below, you'll find a snippet of ``configtx.yaml`` that is written for this
   825  specific deployment. For the full ``configtx.yaml``, click :doc:`here <configtx>`.
   826  
   827  On the orderer's host machine, we need to collect the MSPs for all the
   828  organizations. The ``organization`` section in the ``configtx.yaml`` looks like:
   829  
   830  .. code:: yaml
   831  
   832     Organizations:
   833  
   834     - &org0
   835  
   836        Name: org0
   837  
   838        ID: org0MSP
   839  
   840        MSPDir: /tmp/hyperledger/org0/msp
   841  
   842     - &org1
   843  
   844        Name: org1
   845  
   846        ID: org1MSP
   847  
   848        MSPDir: /tmp/hyperledger/org1/msp
   849  
   850        AnchorPeers:
   851           - Host: peer1-org1
   852              Port: 7051
   853  
   854     - &org2
   855  
   856        Name: org2
   857  
   858        ID: org2MSP
   859  
   860        MSPDir: /tmp/hyperledger/org2/msp
   861  
   862        AnchorPeers:
   863           - Host: peer1-org2
   864             Port: 7051
   865  
   866  The MSP for Org0 will contain the trusted root certificate of Org0,
   867  the certificate of the Org0's admin identity, and the trusted root certificate of
   868  the TLS CA. The MSP folder structure can be seen below.
   869  
   870  .. code:: text
   871  
   872     /tmp/hyperledger/org0/msp
   873     ├── admincerts
   874     │   └── admin-org0-cert.pem
   875     ├── cacerts
   876     │   └── org0-ca-cert.pem
   877     ├── tlscacerts
   878     │   └── tls-ca-cert.pem
   879     └── users
   880  
   881  The pattern is the same for all organization. The MSP folder structure for
   882  Org1 would like:
   883  
   884  .. code:: text
   885  
   886     /tmp/hyperledger/org1/msp
   887     ├── admincerts
   888     │   └── admin-org1-cert.pem
   889     ├── cacerts
   890     │   └── org1-ca-cert.pem
   891     ├── tlscacerts
   892     │   └── tls-ca-cert.pem
   893     └── users
   894  
   895  The MSP folder structure for Org2 would like:
   896  
   897  .. code:: text
   898  
   899     /tmp/hyperledger/org2/msp
   900     ├── admincerts
   901     │   └── admin-org2-cert.pem
   902     ├── cacerts
   903     │   └── org2-ca-cert.pem
   904     ├── tlscacerts
   905     │   └── tls-ca-cert.pem
   906     └── users
   907  
   908  Once all these MSPs are present on the orderer's host machine you will execute the
   909  following commands from the directory in which ``configtx.yaml`` is present:
   910  
   911  .. code:: bash
   912  
   913     configtxgen -profile OrgsOrdererGenesis -outputBlock /tmp/hyperledger/org0/orderer/genesis.block
   914     configtxgen -profile OrgsChannel -outputCreateChannelTx /tmp/hyperledger/org0/orderer/channel.tx -channelID mychannel
   915  
   916  This will generate two artifacts, ``genesis.block`` and ``channel.tx``, which will
   917  be used in later steps.
   918  
   919  Commands for gathering certificates
   920  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   921  
   922  The Fabric CA client has a couple commands that are useful in acquiring the certificates
   923  for the orderer genesis and peer MSP setup.
   924  
   925  The first command is the `fabric-ca-client certificate` command. This command can be used
   926  to get certificates for the admincers folder. For more information on how to use this command
   927  , please refer to: `listing certificate information <https://hyperledger-fabric-ca.readthedocs.io/en/latest/users-guide.html#listing-certificate-information>`__
   928  
   929  The second command is the `fabric-ca-client getcainfo` command. This command can be used to gather
   930  certificates for the `cacerts` and `tlscacerts` folders. The `getcainfo` command returns back the
   931  certificate of the CA.
   932  
   933  Mutual TLS
   934  ^^^^^^^^^^^^
   935  
   936  Endpoints can be secured using Mutual TLS as well. If the CA, Peer, or Orderer are using mutual
   937  TLS then the client must also present a TLS certificate that will be verified by the server.
   938  
   939  Mutual TLS requires the client to acquire a TLS certificate that it will present to the server.
   940  Acquiring a TLS certificate can be done via a TLS certificate authority that does have mutual TLS enabled.
   941  Once the client has aquired a TLS certificate, then it can start communication with mutual TLS enabled servers aslong as the trusted TLS authority on the server is the same as issuing authority for the client's TLS certificate.
   942  
   943  Launch Orderer
   944  ^^^^^^^^^^^^^^^
   945  
   946  Once you have created the genesis block and the channel transaction, you can
   947  define an orderer service that points to the genesis.block created above.
   948  
   949  .. code:: yaml
   950  
   951    orderer1-org0:
   952      container_name: orderer1-org0
   953      image: hyperledger/fabric-orderer
   954      environment:
   955        - ORDERER_HOME=/tmp/hyperledger/orderer
   956        - ORDERER_HOST=orderer1-org0
   957        - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
   958        - ORDERER_GENERAL_GENESISMETHOD=file
   959        - ORDERER_GENERAL_GENESISFILE=/tmp/hyperledger/org0/orderer/genesis.block
   960        - ORDERER_GENERAL_LOCALMSPID=org0MSP
   961        - ORDERER_GENERAL_LOCALMSPDIR=/tmp/hyperledger/org0/orderer/msp
   962        - ORDERER_GENERAL_TLS_ENABLED=true
   963        - ORDERER_GENERAL_TLS_CERTIFICATE=/tmp/hyperledger/org0/orderer/tls-msp/signcerts/cert.pem
   964        - ORDERER_GENERAL_TLS_PRIVATEKEY=/tmp/hyperledger/org0/orderer/tls-msp/keystore/key.pem
   965        - ORDERER_GENERAL_TLS_ROOTCAS=[/tmp/hyperledger/org0/orderer/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem]
   966        - ORDERER_GENERAL_LOGLEVEL=debug
   967        - ORDERER_DEBUG_BROADCASTTRACEDIR=data/logs
   968      volumes:
   969        - /tmp/hyperledger/org0/orderer:/tmp/hyperledger/org0/orderer/
   970      networks:
   971        - fabric-ca
   972  
   973  Launching the orderer service will bring up an orderer container, and in the logs
   974  you will see the following line:
   975  
   976  .. code:: bash
   977  
   978     UTC [orderer/common/server] Start -> INFO 0b8 Beginning to serve requests
   979  
   980  Create CLI Containers
   981  ----------------------
   982  
   983  Communication with peers requires a CLI container, the container contains the appropriate
   984  binaries that will allow you to issue peer related commands. You will create
   985  a CLI container for each org. In this example, we launch a CLI container
   986  in the same host machine as Peer1 for each org.
   987  
   988  Launch Org1's CLI
   989  ^^^^^^^^^^^^^^^^^^
   990  
   991  .. code:: yaml
   992  
   993   cli-org1:
   994      container_name: cli-org1
   995      image: hyperledger/fabric-tools
   996      tty: true
   997      stdin_open: true
   998      environment:
   999        - GOPATH=/opt/gopath
  1000        - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
  1001        - FABRIC_LOGGING_SPEC=DEBUG
  1002        - CORE_PEER_ID=cli-org1
  1003        - CORE_PEER_ADDRESS=peer1-org1:7051
  1004        - CORE_PEER_LOCALMSPID=org1MSP
  1005        - CORE_PEER_TLS_ENABLED=true
  1006        - CORE_PEER_TLS_ROOTCERT_FILE=/tmp/hyperledger/org1/peer1/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem
  1007        - CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org1/peer1/msp
  1008      working_dir: /opt/gopath/src/github.com/hyperledger/fabric/org1
  1009      command: sh
  1010      volumes:
  1011        - /tmp/hyperledger/org1/peer1:/tmp/hyperledger/org1/peer1
  1012        - /tmp/hyperledger/org1/peer1/assets/chaincode:/opt/gopath/src/github.com/hyperledger/fabric-samples/chaincode
  1013        - /tmp/hyperledger/org1/admin:/tmp/hyperledger/org1/admin
  1014      networks:
  1015        - fabric-ca
  1016  
  1017  Launch Org2's CLI
  1018  ^^^^^^^^^^^^^^^^^^
  1019  
  1020  .. code:: yaml
  1021  
  1022   cli-org2:
  1023      container_name: cli-org2
  1024      image: hyperledger/fabric-tools
  1025      tty: true
  1026      stdin_open: true
  1027      environment:
  1028        - GOPATH=/opt/gopath
  1029        - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
  1030        - FABRIC_LOGGING_SPEC=DEBUG
  1031        - CORE_PEER_ID=cli-org2
  1032        - CORE_PEER_ADDRESS=peer1-org2:7051
  1033        - CORE_PEER_LOCALMSPID=org2MSP
  1034        - CORE_PEER_TLS_ENABLED=true
  1035        - CORE_PEER_TLS_ROOTCERT_FILE=/tmp/hyperledger/org2/peer1/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem
  1036        - CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org2/peer1/msp
  1037      working_dir: /opt/gopath/src/github.com/hyperledger/fabric/org2
  1038      command: sh
  1039      volumes:
  1040        - /tmp/hyperledger/org2/peer1:/tmp/hyperledger/org2/peer1
  1041        - /tmp/hyperledger/org1/peer1/assets/chaincode:/opt/gopath/src/github.com/hyperledger/fabric-samples/chaincode
  1042        - /tmp/hyperledger/org2/admin:/tmp/hyperledger/org2/admin
  1043      networks:
  1044        - fabric-ca
  1045  
  1046  Create and Join Channel
  1047  ------------------------
  1048  
  1049  Org1
  1050  ^^^^^
  1051  
  1052  With the CLI containers up and running, you can now issue commands to create and
  1053  join a channel. We are going to use Peer1 to create the channel. In the
  1054  host machine of Peer1, you will execute:
  1055  
  1056  .. code:: bash
  1057  
  1058     docker exec -it cli-org1 sh
  1059  
  1060  This command will bring you inside the CLI container and open up a terminal. From
  1061  here, you will execute the following commands using the admin MSP:
  1062  
  1063  .. code:: bash
  1064  
  1065     export CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org1/admin/msp
  1066     peer channel create -c mychannel -f /tmp/hyperledger/org1/peer1/assets/channel.tx -o orderer1-org0:7050 --outputBlock /tmp/hyperledger/org1/peer1/assets/mychannel.block --tls --cafile /tmp/hyperledger/org1/peer1/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem
  1067  
  1068  The ``channel.tx`` is an artifact that was generated by running the
  1069  ``configtxgen`` command on the orderer. This artifact needs to be transferred
  1070  to Peer1's host machine out-of-band from the orderer. The command above will generate
  1071  ``mychannel.block`` on Peer1 at the specified output path ``/tmp/hyperledger/org1/peer1/assets/mychannel.block``,
  1072  which will be used by all peers in the network that wish
  1073  to join the channel. This ``mychannel.block`` will be need to transferred to all peers
  1074  in both Org1 and Org2 out-of-band.
  1075  
  1076  The next commands you are going to run is to have Peer1 and Peer2 in join
  1077  the channel.
  1078  
  1079  .. code:: bash
  1080  
  1081     export CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org1/admin/msp
  1082     export CORE_PEER_ADDRESS=peer1-org1:7051
  1083     peer channel join -b /tmp/hyperledger/org1/peer1/assets/mychannel.block
  1084  
  1085     export CORE_PEER_ADDRESS=peer2-org1:7051
  1086     peer channel join -b /tmp/hyperledger/org1/peer1/assets/mychannel.block
  1087  
  1088  Org2
  1089  ^^^^^
  1090  
  1091  Run the following command to enter the CLI docker container.
  1092  
  1093  .. code:: bash
  1094  
  1095     docker exec -it cli-org2 sh
  1096  
  1097  In Org2, you only need to have the peers join the channel. Peers in Org2 do not
  1098  need to create the channel, this was already done by Org1. From inside the Org2
  1099  CLI container, you will execute the following commands using the admin MSP:
  1100  
  1101  .. code:: bash
  1102  
  1103     export CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org2/admin/msp
  1104     export CORE_PEER_ADDRESS=peer1-org2:7051
  1105     peer channel join -b /tmp/hyperledger/org2/peer1/assets/mychannel.block
  1106  
  1107     export CORE_PEER_ADDRESS=peer2-org2:7051
  1108     peer channel join -b /tmp/hyperledger/org2/peer1/assets/mychannel.block
  1109  
  1110  
  1111  Install and Instantiate Chaincode
  1112  ----------------------------------
  1113  
  1114  Download this `chaincode <https://github.com/hyperledger/fabric-samples/tree/master/chaincode/abac/go>`_
  1115  from Github to the local file system on Peer1 in both orgs.
  1116  
  1117  Org1
  1118  ^^^^^
  1119  
  1120  On Peer1, you are going to install chaincode. The command assumes that the
  1121  chaincode that needs to be installed is available inside the GOPATH. In this
  1122  example we will assume the chaincode is located at
  1123  ``/opt/gopath/src/github.com/hyperledger/fabric-samples/chaincode/abac/go`` with the
  1124  GOPATH being ``/opt/gopath``. From Org1's CLI container, you will
  1125  execute the following command:
  1126  
  1127  .. code:: bash
  1128  
  1129     export CORE_PEER_ADDRESS=peer1-org1:7051
  1130     export CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org1/admin/msp
  1131     peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric-samples/chaincode/abac/go
  1132  
  1133  The same set of steps will be followed for peer2.
  1134  
  1135  .. code:: bash
  1136  
  1137     export CORE_PEER_ADDRESS=peer2-org1:7051
  1138     export CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org1/admin/msp
  1139     peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric-samples/chaincode/abac/go
  1140  
  1141  Org2
  1142  ^^^^^
  1143  
  1144  On Peer1, you are going to perform the same steps as Org1. The command
  1145  assumes that the chaincode that needs to be installed is available at
  1146  ``/opt/gopath/src/github.com/hyperledger/org2/peer1/assets/chaincode/abac/go``.
  1147  From Org2's CLI container, you will execute the following command:
  1148  
  1149  .. code:: bash
  1150  
  1151     export CORE_PEER_ADDRESS=peer1-org2:7051
  1152     export CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org2/admin/msp
  1153     peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric-samples/chaincode/abac/go
  1154  
  1155  The same set of steps will be followed for peer2.
  1156  
  1157  .. code:: bash
  1158  
  1159     export CORE_PEER_ADDRESS=peer2-org2:7051
  1160     export CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org2/admin/msp
  1161     peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric-samples/chaincode/abac/go
  1162  
  1163  The next step is going to be to instantiate the chaincode. This done by
  1164  executing:
  1165  
  1166  .. code:: bash
  1167  
  1168     peer chaincode instantiate -C mychannel -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -o orderer1-org0:7050 --tls --cafile /tmp/hyperledger/org2/peer1/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem
  1169  
  1170  Invoke and Query Chaincode
  1171  ----------------------------------
  1172  
  1173  From Org1's CLI container, execute:
  1174  
  1175  .. code:: bash
  1176  
  1177     export CORE_PEER_ADDRESS=peer1-org1:7051
  1178     export CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org1/admin/msp
  1179     peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
  1180  
  1181  This should return a value of ``100``.
  1182  
  1183  From Org2's CLI container, execute:
  1184  
  1185  .. code:: bash
  1186  
  1187     export CORE_PEER_ADDRESS=peer1-org2:7051
  1188     export CORE_PEER_MSPCONFIGPATH=/tmp/hyperledger/org2/admin/msp
  1189     peer chaincode invoke -C mychannel -n mycc -c '{"Args":["invoke","a","b","10"]}' --tls --cafile /tmp/hyperledger/org2/peer1/tls-msp/tlscacerts/tls-0-0-0-0-7052.pem
  1190  
  1191  This is going to subtract 10 from value of ``a`` and move it to ``b``. Now, if
  1192  you query by running:
  1193  
  1194  .. code:: bash
  1195  
  1196     peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
  1197  
  1198  This should return a value of ``90``.
  1199  
  1200  This concludes the Operations Guide for Fabric CA.