github.com/yacovm/fabric@v2.0.0-alpha.0.20191128145320-c5d4087dc723+incompatible/docs/source/upgrading_your_network_tutorial.rst (about)

     1  Upgrading Your Network Components
     2  =================================
     3  
     4  .. note:: When we use the term “upgrade” in this documentation, we’re primarily
     5            referring to changing the version of a component (for example, going
     6            from a v1.3 binary to a v1.4.x binary). The term “update,” on the other
     7            hand, refers not to versions but to configuration changes, such as
     8            updating a channel configuration or a deployment script. As there is
     9            no data migration, technically speaking, in Fabric, we will not use
    10            the term "migration" or "migrate" here.
    11  
    12  .. note:: Upgrading from Fabric v1.4 to the v2.0 Alpha release is not supported.
    13            This tutorial will be updated after the 2.0 Alpha release.
    14  
    15  Overview
    16  --------
    17  
    18  Because the :doc:`build_network` (BYFN) tutorial defaults to the “latest” binaries,
    19  if you have run it since the release of v1.4.x, your machine will have v1.4.x binaries
    20  and tools installed on it and you will not be able to upgrade them.
    21  
    22  As a result, this tutorial will provide a network based on Hyperledger Fabric
    23  v1.3 binaries as well as the v1.4.x binaries you will be upgrading to.
    24  
    25  At a high level, our upgrade tutorial will perform the following steps:
    26  
    27  1. Backup the ledger and MSPs.
    28  2. Upgrade the orderer binaries to Fabric v1.4.x **Because migration from Solo to
    29     Raft is not supported, and the 1.4.1 release of Fabric is the first to support
    30     Raft, this tutorial will not cover the process for upgrading to a Raft ordering
    31     service**.
    32  3. Upgrade the peer binaries to Fabric v1.4.x.
    33  
    34  .. note:: There are no new :doc:`capability_requirements` in v1.4.x As a result,
    35            we do not have to update any channel configurations as part of an
    36            upgrade to v1.4.x.
    37  
    38  This tutorial will demonstrate how to perform each of these steps individually
    39  with CLI commands. We will also describe how the CLI ``tools`` image can be
    40  updated.
    41  
    42  .. note:: Because BYFN uses a "Solo" ordering service (one orderer), our script
    43            brings down the entire network. However, in production environments,
    44            the orderers and peers can be upgraded simultaneously and on a rolling
    45            basis. In other words, you can upgrade the binaries in any order without
    46            bringing down the network.
    47  
    48            Because BYFN is not compatible with the following components, our script for
    49            upgrading BYFN will not cover them:
    50  
    51            * **Fabric CA**
    52            * **Kafka**
    53            * **CouchDB**
    54            * **SDK**
    55  
    56            The process for upgrading these components --- if necessary --- will
    57            be covered in a section following the tutorial. We will also show how
    58            to upgrade the Node chaincode shim.
    59  
    60  From an operational perspective, it's worth noting that the process for gathering
    61  logs has changed in v1.4, from ``CORE_LOGGING_LEVEL`` (for the peer) and
    62  ``ORDERER_GENERAL_LOGLEVEL`` (for the orderer) to ``FABRIC_LOGGING_SPEC`` (the new
    63  operations service). For more information, check out the
    64  `Fabric release notes <https://github.com/hyperledger/fabric/releases/tag/v1.4.0>`_.
    65  
    66  Prerequisites
    67  ~~~~~~~~~~~~~
    68  
    69  If you haven’t already done so, ensure you have all of the dependencies on your
    70  machine as described in :doc:`prereqs`.
    71  
    72  Launch a v1.3 network
    73  ---------------------
    74  
    75  Before we can upgrade to v1.4, we must first provision a network running Fabric
    76  v1.3 images.
    77  
    78  Just as in the BYFN tutorial, we will be operating from the ``first-network``
    79  subdirectory within your local clone of ``fabric-samples``. Change into that
    80  directory now. You will also want to open a few extra terminals for ease of use.
    81  
    82  Clean up
    83  ~~~~~~~~
    84  
    85  We want to operate from a known state, so we will use the ``byfn.sh`` script to
    86  kill any active or stale docker containers and remove any previously generated
    87  artifacts. Run:
    88  
    89  .. code:: bash
    90  
    91    ./byfn.sh down
    92  
    93  Generate the crypto and bring up the network
    94  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    95  
    96  With a clean environment, launch our v1.3 BYFN network using these four commands:
    97  
    98  .. code:: bash
    99  
   100    git fetch origin
   101  
   102    git checkout v1.3.0
   103  
   104    ./byfn.sh generate
   105  
   106    ./byfn.sh up -t 3000 -i 1.3.0
   107  
   108  .. note:: If you have locally built v1.3 images, they will be used by the example.
   109            If you get errors, please consider cleaning up your locally built v1.3 images
   110            and running the example again. This will download v1.3 images from docker hub.
   111  
   112  If BYFN has launched properly, you will see:
   113  
   114  .. code:: bash
   115  
   116    ===================== All GOOD, BYFN execution completed =====================
   117  
   118  We are now ready to upgrade our network to Hyperledger Fabric v1.4.x.
   119  
   120  Get the newest samples
   121  ~~~~~~~~~~~~~~~~~~~~~~
   122  
   123  .. note:: The instructions below pertain to whatever is the most recently
   124            published version of v1.4.x. Please substitute 1.4.x with the version
   125            identifier of the published release that you are testing. In other
   126            words, replace '1.4.x' with '1.4.0' if you are testing the first
   127            release.
   128  
   129  Before completing the rest of the tutorial, it's important to get the v1.4.x
   130  (for example, 1.4.1) version of the samples, you can do this by issuing:
   131  
   132  .. code:: bash
   133  
   134    git fetch origin
   135  
   136    git checkout v1.4.x
   137  
   138  Want to upgrade now?
   139  ~~~~~~~~~~~~~~~~~~~~
   140  
   141  We have a script that will upgrade all of the components in BYFN as well as
   142  enable any capabilities (note, no new capabilities are required for v1.4).
   143  If you are running a production network, or are an
   144  administrator of some part of a network, this script can serve as a template
   145  for performing your own upgrades.
   146  
   147  Afterwards, we will walk you through the steps in the script and describe what
   148  each piece of code is doing in the upgrade process.
   149  
   150  To run the script, issue these commands:
   151  
   152  .. code:: bash
   153  
   154    # Note, replace '1.4.x' with a specific version, for example '1.4.1'.
   155    # Don't pass the image flag '-i 1.4.x' if you prefer to default to 'latest' images.
   156  
   157    ./byfn.sh upgrade -i 1.4.x
   158  
   159  If the upgrade is successful, you should see the following:
   160  
   161  .. code:: bash
   162  
   163    ===================== All GOOD, End-2-End UPGRADE Scenario execution completed =====================
   164  
   165  If you want to upgrade the network manually, simply run ``./byfn.sh down`` again
   166  and perform the steps up to --- but not including --- ``./byfn.sh upgrade -i 1.4.x``.
   167  Then proceed to the next section.
   168  
   169  .. note:: Many of the commands you'll run in this section will not result in any
   170            output. In general, assume no output is good output.
   171  
   172  Upgrade the orderer containers
   173  ------------------------------
   174  
   175  Orderer containers should be upgraded in a rolling fashion (one at a time). At a
   176  high level, the orderer upgrade process goes as follows:
   177  
   178  1. Stop the orderer.
   179  2. Back up the orderer’s ledger and MSP.
   180  3. Restart the orderer with the latest images.
   181  4. Verify upgrade completion.
   182  
   183  As a consequence of leveraging BYFN, we have a Solo orderer setup, therefore, we
   184  will only perform this process once. In a Kafka setup, however, this process will
   185  have to be repeated on each orderer.
   186  
   187  .. note:: This tutorial uses a docker deployment. For native deployments,
   188            replace the file ``orderer`` with the one from the release artifacts.
   189            Backup the ``orderer.yaml`` and replace it with the ``orderer.yaml``
   190            file from the release artifacts. Then port any modified variables from
   191            the backed up ``orderer.yaml`` to the new one. Utilizing a utility
   192            like ``diff`` may be helpful.
   193  
   194  Let’s begin the upgrade process by **bringing down the orderer**:
   195  
   196  .. code:: bash
   197  
   198    docker stop orderer.example.com
   199  
   200    export LEDGERS_BACKUP=./ledgers-backup
   201  
   202    # Note, replace '1.4.x' with a specific version, for example '1.4.1'.
   203    # Set IMAGE_TAG to 'latest' if you prefer to default to the images tagged 'latest' on your system.
   204  
   205    export IMAGE_TAG=$(go env GOARCH)-1.4.x
   206  
   207  We have created a variable for a directory to put file backups into, and
   208  exported the ``IMAGE_TAG`` we'd like to move to.
   209  
   210  Once the orderer is down, you'll want to **backup its ledger and MSP**:
   211  
   212  .. code:: bash
   213  
   214    mkdir -p $LEDGERS_BACKUP
   215  
   216    docker cp orderer.example.com:/var/hyperledger/production/orderer/ ./$LEDGERS_BACKUP/orderer.example.com
   217  
   218  In a production network this process would be repeated for each of the Kafka-based
   219  orderers in a rolling fashion.
   220  
   221  Now **download and restart the orderer** with our new fabric image:
   222  
   223  .. code:: bash
   224  
   225    docker-compose -f docker-compose-cli.yaml up -d --no-deps orderer.example.com
   226  
   227  Because our sample uses a "Solo" ordering service, there are no other orderers in the
   228  network that the restarted orderer must sync up to. However, in a production network
   229  leveraging Kafka, it will be a best practice to issue ``peer channel fetch <blocknumber>``
   230  after restarting the orderer to verify that it has caught up to the other orderers.
   231  
   232  Upgrade the peer containers
   233  ---------------------------
   234  
   235  Next, let's look at how to upgrade peer containers to Fabric v1.4.x. Peer containers should,
   236  like the orderers, be upgraded in a rolling fashion (one at a time). As mentioned
   237  during the orderer upgrade, orderers and peers may be upgraded in parallel, but for
   238  the purposes of this tutorial we’ve separated the processes out. At a high level,
   239  we will perform the following steps:
   240  
   241  1. Stop the peer.
   242  2. Back up the peer’s ledger and MSP.
   243  3. Remove chaincode containers and images.
   244  4. Restart the peer with latest image.
   245  5. Verify upgrade completion.
   246  
   247  We have four peers running in our network. We will perform this process once for
   248  each peer, totaling four upgrades.
   249  
   250  .. note:: Again, this tutorial utilizes a docker deployment. For **native**
   251            deployments, replace the file ``peer`` with the one from the release
   252            artifacts. Backup your ``core.yaml`` and replace it with the one from
   253            the release artifacts. Port any modified variables from the backed up
   254            ``core.yaml`` to the new one. Utilizing a utility like ``diff`` may be
   255            helpful.
   256  
   257  Let’s **bring down the first peer** with the following command:
   258  
   259  .. code:: bash
   260  
   261     export PEER=peer0.org1.example.com
   262  
   263     docker stop $PEER
   264  
   265  We can then **backup the peer’s ledger and MSP**:
   266  
   267  .. code:: bash
   268  
   269    mkdir -p $LEDGERS_BACKUP
   270  
   271    docker cp $PEER:/var/hyperledger/production ./$LEDGERS_BACKUP/$PEER
   272  
   273  With the peer stopped and the ledger backed up, **remove the peer chaincode
   274  containers**:
   275  
   276  .. code:: bash
   277  
   278    CC_CONTAINERS=$(docker ps | grep dev-$PEER | awk '{print $1}')
   279    if [ -n "$CC_CONTAINERS" ] ; then docker rm -f $CC_CONTAINERS ; fi
   280  
   281  And the peer chaincode images:
   282  
   283  .. code:: bash
   284  
   285    CC_IMAGES=$(docker images | grep dev-$PEER | awk '{print $1}')
   286    if [ -n "$CC_IMAGES" ] ; then docker rmi -f $CC_IMAGES ; fi
   287  
   288  Now we'll re-launch the peer using the v1.4.x image tag:
   289  
   290  .. code:: bash
   291  
   292    docker-compose -f docker-compose-cli.yaml up -d --no-deps $PEER
   293  
   294  .. note:: Although, BYFN supports using CouchDB, we opted for a simpler
   295            implementation in this tutorial. If you are using CouchDB, however,
   296            issue this command instead of the one above:
   297  
   298  .. code:: bash
   299  
   300    docker-compose -f docker-compose-cli.yaml -f docker-compose-couch.yaml up -d --no-deps $PEER
   301  
   302  .. note:: You do not need to relaunch the chaincode container. When the peer gets
   303            a request for a chaincode, (invoke or query), it first checks if it has
   304            a copy of that chaincode running. If so, it uses it. Otherwise, as in
   305            this case, the peer launches the chaincode (rebuilding the image if
   306            required).
   307  
   308  Verify peer upgrade completion
   309  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   310  
   311  We’ve completed the upgrade for our first peer, but before we move on let’s check
   312  to ensure the upgrade has been completed properly with a chaincode invoke.
   313  
   314  .. note:: Before you attempt this, you may want to upgrade peers from
   315            enough organizations to satisfy your endorsement policy.
   316            Although, this is only mandatory if you are updating your chaincode
   317            as part of the upgrade process. If you are not updating your chaincode
   318            as part of the upgrade process, it is possible to get endorsements
   319            from peers running at different Fabric versions.
   320  
   321  Before we get into the CLI container and issue the invoke, make sure the CLI is
   322  updated to the most current version by issuing:
   323  
   324  .. code:: bash
   325  
   326    docker-compose -f docker-compose-cli.yaml stop cli
   327  
   328    docker-compose -f docker-compose-cli.yaml up -d --no-deps cli
   329  
   330  If you specifically want the v1.3 version of the CLI, issue:
   331  
   332  .. code:: bash
   333  
   334    IMAGE_TAG=$(go env GOARCH)-1.3.x docker-compose -f docker-compose-cli.yaml up -d --no-deps cli
   335  
   336  Once you have the version of the CLI you want, get into the CLI container:
   337  
   338  .. code:: bash
   339  
   340    docker exec -it cli bash
   341  
   342  Now you'll need to set two environment variables --- the name of the channel and
   343  the name of the ``ORDERER_CA``:
   344  
   345  .. code:: bash
   346  
   347    CH_NAME=mychannel
   348  
   349    ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
   350  
   351  Now you can issue the invoke:
   352  
   353  .. code:: bash
   354  
   355    peer chaincode invoke -o orderer.example.com:7050 --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt --tls --cafile $ORDERER_CA  -C $CH_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}'
   356  
   357  Our query earlier revealed ``a`` to have a value of ``90`` and we have just removed
   358  ``10`` with our invoke. Therefore, a query against ``a`` should reveal ``80``.
   359  Let’s see:
   360  
   361  .. code:: bash
   362  
   363    peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
   364  
   365  We should see the following:
   366  
   367  .. code:: bash
   368  
   369    Query Result: 80
   370  
   371  After verifying the peer was upgraded correctly, make sure to issue an ``exit``
   372  to leave the container before continuing to upgrade your peers. You can
   373  do this by repeating the process above with a different peer name exported.
   374  
   375  .. code:: bash
   376  
   377    export PEER=peer1.org1.example.com
   378    export PEER=peer0.org2.example.com
   379    export PEER=peer1.org2.example.com
   380  
   381  Upgrading components BYFN does not support
   382  ------------------------------------------
   383  
   384  Although this is the end of our update tutorial, there are other components that
   385  exist in production networks that are not compatible with the BYFN sample. In this
   386  section, we’ll talk through the process of updating them.
   387  
   388  Fabric CA container
   389  ~~~~~~~~~~~~~~~~~~~
   390  
   391  To learn how to upgrade your Fabric CA server, click over to the
   392  `CA documentation <http://hyperledger-fabric-ca.readthedocs.io/en/latest/users-guide.html#upgrading-the-server>`_.
   393  
   394  Upgrade Node SDK clients
   395  ~~~~~~~~~~~~~~~~~~~~~~~~
   396  
   397  .. note:: Upgrade Fabric and Fabric CA before upgrading Node SDK clients.
   398            Fabric and Fabric CA are tested for backwards compatibility with
   399            older SDK clients. While newer SDK clients often work with older
   400            Fabric and Fabric CA releases, they may expose features that
   401            are not yet available in the older Fabric and Fabric CA releases,
   402            and are not tested for full compatibility.
   403  
   404  Use NPM to upgrade any ``Node.js`` client by executing these commands in the
   405  root directory of your application:
   406  
   407  ..  code:: bash
   408  
   409    npm install fabric-client@latest
   410  
   411    npm install fabric-ca-client@latest
   412  
   413  These commands install the new version of both the Fabric client and Fabric-CA
   414  client and write the new versions ``package.json``.
   415  
   416  Upgrading the Kafka cluster
   417  ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   418  
   419  It is not required, but it is recommended that the Kafka cluster be upgraded and
   420  kept up to date along with the rest of Fabric. Newer versions of Kafka support
   421  older protocol versions, so you may upgrade Kafka before or after the rest of
   422  Fabric.
   423  
   424  If you followed the `Upgrading Your Network to v1.3 tutorial <http://hyperledger-fabric.readthedocs.io/en/release-1.3/upgrading_your_network_tutorial.html>`_,
   425  your Kafka cluster should be at v1.0.0. If it isn't, refer to the official Apache
   426  Kafka documentation on `upgrading Kafka from previous versions`__ to upgrade the
   427  Kafka cluster brokers.
   428  
   429  .. __: https://kafka.apache.org/documentation/#upgrade
   430  
   431  Upgrading Zookeeper
   432  ^^^^^^^^^^^^^^^^^^^
   433  An Apache Kafka cluster requires an Apache Zookeeper cluster. The Zookeeper API
   434  has been stable for a long time and, as such, almost any version of Zookeeper is
   435  tolerated by Kafka. Refer to the `Apache Kafka upgrade`_ documentation in case
   436  there is a specific requirement to upgrade to a specific version of Zookeeper.
   437  If you would like to upgrade your Zookeeper cluster, some information on
   438  upgrading Zookeeper cluster can be found in the `Zookeeper FAQ`_.
   439  
   440  .. _Apache Kafka upgrade: https://kafka.apache.org/documentation/#upgrade
   441  .. _Zookeeper FAQ: https://cwiki.apache.org/confluence/display/ZOOKEEPER/FAQ
   442  
   443  Upgrading CouchDB
   444  ~~~~~~~~~~~~~~~~~
   445  
   446  If you are using CouchDB as state database, you should upgrade the peer's
   447  CouchDB at the same time the peer is being upgraded. CouchDB v2.2.0 has
   448  been tested with Fabric v1.4.x.
   449  
   450  To upgrade CouchDB:
   451  
   452  1. Stop CouchDB.
   453  2. Backup CouchDB data directory.
   454  3. Install CouchDB v2.2.0 binaries or update deployment scripts to use a new Docker image
   455     (CouchDB v2.2.0 pre-configured Docker image is provided alongside Fabric v1.4).
   456  4. Restart CouchDB.
   457  
   458  Upgrade Node chaincode shim
   459  ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   460  
   461  To move to the new version of the Node chaincode shim a developer would need to:
   462  
   463  1. Change the level of ``fabric-shim`` in their chaincode ``package.json`` from
   464     1.3 to 1.4.x.
   465  2. Repackage this new chaincode package and install it on all the endorsing peers
   466     in the channel.
   467  3. Perform an upgrade to this new chaincode. To see how to do this, check out :doc:`commands/peerchaincode`.
   468  
   469  .. note:: This flow isn't specific to moving from 1.3 to 1.4.x It is also how
   470            one would upgrade from any incremental version of the node fabric shim.
   471  
   472  Upgrade Chaincodes with vendored shim
   473  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   474  
   475  .. note:: The v1.3.0 shim is compatible with the v1.4.x peer, but, it is still
   476            best practice to upgrade the chaincode shim to match the current level
   477            of the peer.
   478  
   479  A number of third party tools exist that will allow you to vendor a chaincode
   480  shim. If you used one of these tools, use the same one to update your vendored
   481  chaincode shim and re-package your chaincode.
   482  
   483  If your chaincode vendors the shim, after updating the shim version, you must install
   484  it to all peers which already have the chaincode. Install it with the same name, but
   485  a newer version. Then you should execute a chaincode upgrade on each channel where
   486  this chaincode has been deployed to move to the new version.
   487  
   488  .. Licensed under Creative Commons Attribution 4.0 International License
   489     https://creativecommons.org/licenses/by/4.0/