github.com/Hnampk/my-fabric@v0.0.0-20201028083322-75069da399c0/docs/source/raft_configuration.md (about) 1 # Configuring and operating a Raft ordering service 2 3 **Audience**: *Raft ordering node admins* 4 5 ## Conceptual overview 6 7 For a high level overview of the concept of ordering and how the supported 8 ordering service implementations (including Raft) work at a high level, check 9 out our conceptual documentation on the [Ordering Service](./orderer/ordering_service.html). 10 11 To learn about the process of setting up an ordering node --- including the 12 creation of a local MSP and the creation of a genesis block --- check out our 13 documentation on [Setting up an ordering node](orderer_deploy.html). 14 15 ## Configuration 16 17 While every Raft node must be added to the system channel, a node does not need 18 to be added to every application channel. Additionally, you can remove and add a 19 node from a channel dynamically without affecting the other nodes, a process 20 described in the Reconfiguration section below. 21 22 Raft nodes identify each other using TLS pinning, so in order to impersonate a 23 Raft node, an attacker needs to obtain the **private key** of its TLS 24 certificate. As a result, it is not possible to run a Raft node without a valid 25 TLS configuration. 26 27 A Raft cluster is configured in two planes: 28 29 * **Local configuration**: Governs node specific aspects, such as TLS 30 communication, replication behavior, and file storage. 31 32 * **Channel configuration**: Defines the membership of the Raft cluster for the 33 corresponding channel, as well as protocol specific parameters such as heartbeat 34 frequency, leader timeouts, and more. 35 36 Recall, each channel has its own instance of a Raft protocol running. Thus, a 37 Raft node must be referenced in the configuration of each channel it belongs to 38 by adding its server and client TLS certificates (in `PEM` format) to the channel 39 config. This ensures that when other nodes receive a message from it, they can 40 securely confirm the identity of the node that sent the message. 41 42 The following section from `configtx.yaml` shows three Raft nodes (also called 43 “consenters”) in the channel: 44 45 ``` 46 Consenters: 47 - Host: raft0.example.com 48 Port: 7050 49 ClientTLSCert: path/to/ClientTLSCert0 50 ServerTLSCert: path/to/ServerTLSCert0 51 - Host: raft1.example.com 52 Port: 7050 53 ClientTLSCert: path/to/ClientTLSCert1 54 ServerTLSCert: path/to/ServerTLSCert1 55 - Host: raft2.example.com 56 Port: 7050 57 ClientTLSCert: path/to/ClientTLSCert2 58 ServerTLSCert: path/to/ServerTLSCert2 59 ``` 60 61 Note: an orderer will be listed as a consenter in the system channel as well as 62 any application channels they're joined to. 63 64 When the channel config block is created, the `configtxgen` tool reads the paths 65 to the TLS certificates, and replaces the paths with the corresponding bytes of 66 the certificates. 67 68 ### Local configuration 69 70 The `orderer.yaml` has two configuration sections that are relevant for Raft 71 orderers: 72 73 **Cluster**, which determines the TLS communication configuration. And 74 **consensus**, which determines where Write Ahead Logs and Snapshots are 75 stored. 76 77 **Cluster parameters:** 78 79 By default, the Raft service is running on the same gRPC server as the client 80 facing server (which is used to send transactions or pull blocks), but it can be 81 configured to have a separate gRPC server with a separate port. 82 83 This is useful for cases where you want TLS certificates issued by the 84 organizational CAs, but used only by the cluster nodes to communicate among each 85 other, and TLS certificates issued by a public TLS CA for the client facing API. 86 87 * `ClientCertificate`, `ClientPrivateKey`: The file path of the client TLS certificate 88 and corresponding private key. 89 * `ListenPort`: The port the cluster listens on. If blank, the port is the same 90 port as the orderer general port (`general.listenPort`) 91 * `ListenAddress`: The address the cluster service is listening on. 92 * `ServerCertificate`, `ServerPrivateKey`: The TLS server certificate key pair 93 which is used when the cluster service is running on a separate gRPC server 94 (different port). 95 * `SendBufferSize`: Regulates the number of messages in the egress buffer. 96 97 Note: `ListenPort`, `ListenAddress`, `ServerCertificate`, `ServerPrivateKey` must 98 be either set together or unset together. 99 If they are unset, they are inherited from the general TLS section, 100 in example `general.tls.{privateKey, certificate}`. 101 102 There are also hidden configuration parameters for `general.cluster` which can be 103 used to further fine tune the cluster communication or replication mechanisms: 104 105 * `DialTimeout`, `RPCTimeout`: Specify the timeouts of creating connections and 106 establishing streams. 107 * `ReplicationBufferSize`: the maximum number of bytes that can be allocated 108 for each in-memory buffer used for block replication from other cluster nodes. 109 Each channel has its own memory buffer. Defaults to `20971520` which is `20MB`. 110 * `PullTimeout`: the maximum duration the ordering node will wait for a block 111 to be received before it aborts. Defaults to five seconds. 112 * `ReplicationRetryTimeout`: The maximum duration the ordering node will wait 113 between two consecutive attempts. Defaults to five seconds. 114 * `ReplicationBackgroundRefreshInterval`: the time between two consecutive 115 attempts to replicate existing channels that this node was added to, or 116 channels that this node failed to replicate in the past. Defaults to five 117 minutes. 118 * `TLSHandshakeTimeShift`: If the TLS certificates of the ordering nodes 119 expire and are not replaced in time (see TLS certificate rotation below), 120 communication between them cannot be established, and it will be impossible 121 to send new transactions to the ordering service. 122 To recover from such a scenario, it is possible to make TLS handshakes 123 between ordering nodes consider the time to be shifted backwards a given 124 amount that is configured to `TLSHandshakeTimeShift`. 125 This setting only applies when a separate cluster listener is in use. If 126 the cluster service is sharing the orderer's main gRPC server, then instead 127 specify `TLSHandshakeTimeShift` in the `General.TLS` section. 128 129 **Consensus parameters:** 130 131 * `WALDir`: the location at which Write Ahead Logs for `etcd/raft` are stored. 132 Each channel will have its own subdirectory named after the channel ID. 133 * `SnapDir`: specifies the location at which snapshots for `etcd/raft` are stored. 134 Each channel will have its own subdirectory named after the channel ID. 135 136 There is also a hidden configuration parameter that can be set by adding it to 137 the consensus section in the `orderer.yaml`: 138 139 * `EvictionSuspicion`: The cumulative period of time of channel eviction 140 suspicion that triggers the node to pull blocks from other nodes and see if it 141 has been evicted from the channel in order to confirm its suspicion. If the 142 suspicion is confirmed (the inspected block doesn't contain the node's TLS 143 certificate), the node halts its operation for that channel. A node suspects 144 its channel eviction when it doesn't know about any elected leader nor can be 145 elected as leader in the channel. Defaults to 10 minutes. 146 147 ### Channel configuration 148 149 Apart from the (already discussed) consenters, the Raft channel configuration has 150 an `Options` section which relates to protocol specific knobs. It is currently 151 not possible to change these values dynamically while a node is running. The 152 node have to be reconfigured and restarted. 153 154 The only exceptions is `SnapshotIntervalSize`, which can be adjusted at runtime. 155 156 Note: It is recommended to avoid changing the following values, as a misconfiguration 157 might lead to a state where a leader cannot be elected at all (i.e, if the 158 `TickInterval` and `ElectionTick` are extremely low). Situations where a leader 159 cannot be elected are impossible to resolve, as leaders are required to make 160 changes. Because of such dangers, we suggest not tuning these parameters for most 161 use cases. 162 163 * `TickInterval`: The time interval between two `Node.Tick` invocations. 164 * `ElectionTick`: The number of `Node.Tick` invocations that must pass between 165 elections. That is, if a follower does not receive any message from the leader 166 of current term before `ElectionTick` has elapsed, it will become candidate 167 and start an election. 168 * `ElectionTick` must be greater than `HeartbeatTick`. 169 * `HeartbeatTick`: The number of `Node.Tick` invocations that must pass between 170 heartbeats. That is, a leader sends heartbeat messages to maintain its 171 leadership every `HeartbeatTick` ticks. 172 * `MaxInflightBlocks`: Limits the max number of in-flight append blocks during 173 optimistic replication phase. 174 * `SnapshotIntervalSize`: Defines number of bytes per which a snapshot is taken. 175 176 ## Reconfiguration 177 178 The Raft orderer supports dynamic (meaning, while the channel is being serviced) 179 addition and removal of nodes as long as only one node is added or removed at a 180 time. Note that your cluster must be operational and able to achieve consensus 181 before you attempt to reconfigure it. For instance, if you have three nodes, and 182 two nodes fail, you will not be able to reconfigure your cluster to remove those 183 nodes. Similarly, if you have one failed node in a channel with three nodes, you 184 should not attempt to rotate a certificate, as this would induce a second fault. 185 As a rule, you should never attempt any configuration changes to the Raft 186 consenters, such as adding or removing a consenter, or rotating a consenter's 187 certificate unless all consenters are online and healthy. 188 189 If you do decide to change these parameters, it is recommended to only attempt 190 such a change during a maintenance cycle. Problems are most likely to occur when 191 a configuration is attempted in clusters with only a few nodes while a node is 192 down. For example, if you have three nodes in your consenter set and one of them 193 is down, it means you have two out of three nodes alive. If you extend the cluster 194 to four nodes while in this state, you will have only two out of four nodes alive, 195 which is not a quorum. The fourth node won't be able to onboard because nodes can 196 only onboard to functioning clusters (unless the total size of the cluster is 197 one or two). 198 199 So by extending a cluster of three nodes to four nodes (while only two are 200 alive) you are effectively stuck until the original offline node is resurrected. 201 202 Adding a new node to a Raft cluster is done by: 203 204 1. **Adding the TLS certificates** of the new node to the channel through a 205 channel configuration update transaction. Note: the new node must be added to 206 the system channel before being added to one or more application channels. 207 2. **Fetching the latest config block** of the system channel from an orderer node 208 that's part of the system channel. 209 3. **Ensuring that the node that will be added is part of the system channel** 210 by checking that the config block that was fetched includes the certificate of 211 (soon to be) added node. 212 4. **Starting the new Raft node** with the path to the config block in the 213 `General.BootstrapFile` configuration parameter. 214 5. **Waiting for the Raft node to replicate the blocks** from existing nodes for 215 all channels its certificates have been added to. After this step has been 216 completed, the node begins servicing the channel. 217 6. **Adding the endpoint** of the newly added Raft node to the channel 218 configuration of all channels. 219 220 It is possible to add a node that is already running (and participates in some 221 channels already) to a channel while the node itself is running. To do this, simply 222 add the node’s certificate to the channel config of the channel. The node will 223 autonomously detect its addition to the new channel (the default value here is 224 five minutes, but if you want the node to detect the new channel more quickly, 225 reboot the node) and will pull the channel blocks from an orderer in the 226 channel, and then start the Raft instance for that chain. 227 228 After it has successfully done so, the channel configuration can be updated to 229 include the endpoint of the new Raft orderer. 230 231 Removing a node from a Raft cluster is done by: 232 233 1. Removing its endpoint from the channel config for all channels, including 234 the system channel controlled by the orderer admins. 235 2. Removing its entry (identified by its certificates) from the channel 236 configuration for all channels. Again, this includes the system channel. 237 3. Shut down the node. 238 239 Removing a node from a specific channel, but keeping it servicing other channels 240 is done by: 241 242 1. Removing its endpoint from the channel config for the channel. 243 2. Removing its entry (identified by its certificates) from the channel 244 configuration. 245 3. The second phase causes: 246 * The remaining orderer nodes in the channel to cease communicating with 247 the removed orderer node in the context of the removed channel. They might 248 still be communicating on other channels. 249 * The node that is removed from the channel would autonomously detect its 250 removal either immediately or after `EvictionSuspicion` time has passed 251 (10 minutes by default) and will shut down its Raft instance. 252 253 ### TLS certificate rotation for an orderer node 254 255 All TLS certificates have an expiration date that is determined by the issuer. 256 These expiration dates can range from 10 years from the date of issuance to as 257 little as a few months, so check with your issuer. Before the expiration date, 258 you will need to rotate these certificates on the node itself and every channel 259 the node is joined to, including the system channel. 260 261 For each channel the node participates in: 262 263 1. Update the channel configuration with the new certificates. 264 2. Replace its certificates in the file system of the node. 265 3. Restart the node. 266 267 Because a node can only have a single TLS certificate key pair, the node will be 268 unable to service channels its new certificates have not been added to during 269 the update process, degrading the capacity of fault tolerance. Because of this, 270 **once the certificate rotation process has been started, it should be completed 271 as quickly as possible.** 272 273 If for some reason the rotation of the TLS certificates has started but cannot 274 complete in all channels, it is advised to rotate TLS certificates back to 275 what they were and attempt the rotation later. 276 277 ### Certificate expiration related authentication 278 Whenever a client with an identity that has an expiration date (such as an identity based on an x509 certificate) 279 sends a transaction to the orderer, the orderer checks whether its identity has expired, and if 280 so, rejects the transaction submission. 281 282 However, it is possible to configure the orderer to ignore expiration of identities via enabling 283 the `General.Authentication.NoExpirationChecks` configuration option in the `orderer.yaml`. 284 285 This should be done only under extreme circumstances, where the certificates of the administrators 286 have expired, and due to this it is not possible to send configuration updates to replace the administrator 287 certificates with renewed ones, because the config transactions signed by the existing administrators 288 are now rejected because they have expired. 289 After updating the channel it is recommended to change back to the default configuration which enforces 290 expiration checks on identities. 291 292 293 ## Metrics 294 295 For a description of the Operations Service and how to set it up, check out 296 [our documentation on the Operations Service](operations_service.html). 297 298 For a list at the metrics that are gathered by the Operations Service, check out 299 our [reference material on metrics](metrics_reference.html). 300 301 While the metrics you prioritize will have a lot to do with your particular use 302 case and configuration, there are two metrics in particular you might want to 303 monitor: 304 305 * `consensus_etcdraft_is_leader`: identifies which node in the cluster is 306 currently leader. If no nodes have this set, you have lost quorum. 307 * `consensus_etcdraft_data_persist_duration`: indicates how long write operations 308 to the Raft cluster's persistent write ahead log take. For protocol safety, 309 messages must be persisted durably, calling `fsync` where appropriate, before 310 they can be shared with the consenter set. If this value begins to climb, this 311 node may not be able to participate in consensus (which could lead to a 312 service interruption for this node and possibly the network). 313 * `consensus_etcdraft_cluster_size` and `consensus_etcdraft_active_nodes`: these 314 channel metrics help track the "active" nodes (which, as it sounds, are the nodes that 315 are currently contributing to the cluster, as compared to the total number of 316 nodes in the cluster). If the number of active nodes falls below a majority of 317 the nodes in the cluster, quorum will be lost and the ordering service will 318 stop processing blocks on the channel. 319 320 ## Troubleshooting 321 322 * The more stress you put on your nodes, the more you might have to change certain 323 parameters. As with any system, computer or mechanical, stress can lead to a drag 324 in performance. As we noted in the conceptual documentation, leader elections in 325 Raft are triggered when follower nodes do not receive either a "heartbeat" 326 messages or an "append" message that carries data from the leader for a certain 327 amount of time. Because Raft nodes share the same communication layer across 328 channels (this does not mean they share data --- they do not!), if a Raft node is 329 part of the consenter set in many channels, you might want to lengthen the amount 330 of time it takes to trigger an election to avoid inadvertent leader elections. 331 332 <!--- Licensed under Creative Commons Attribution 4.0 International License 333 https://creativecommons.org/licenses/by/4.0/) -->