Project: YugabyteDB (App Definition and Development / Database)
File: 3dc-deployment.md

title: Deploy to three or more data centers headerTitle: Three+ data center (3DC) linkTitle: Three+ data center (3DC) description: Deploy YugabyteDB clusters to three or more data centers. headContent: Deploy YugabyteDB clusters across regions menu: v2.18: parent: multi-dc identifier: 3dc-deployment weight: 632 type: docs {{< tip title="Recommended Reading" >}} highlights the various multi-DC deployment strategies (including 3DC deployments) for a distributed SQL database like YugabyteDB. {{< /tip >}} Three data center deployments of YugabyteDB are essentially a natural extension of the three availability zone (AZ) deployments documented in the section. Equal number of nodes are placed in each of the three data centers. Inside a single data center, a multi-AZ deployment is recommended to ensure resilience against zone failures. This approach works fine for any odd number of AZs or data centers. Given YugabyteDB's distributed consensus-based replication, which requires majority quorum for continuous availability of write requests, deploying a single cluster across an even number of AZs or data centers is not recommended. Create a three-node cluster with replication factor of `3`. Cloud is `aws` and the three regions/AZs are `us-west`/`us-west-2a`, `us-east-1`/`us-east-1a`, `ap-northeast-1`/`ap-northeast-1a`. One node is placed in each region/AZ such that one replica for each tablet is also placed in each region/AZ. Private IP addresses of the 3 nodes are `172.151.17.130`, `172.151.17.220`, and `172.151.17.140`. Multiple data drives are mounted on `/home/centos/disk1`, `/home/centos/disk2`. Follow the to ensure you have prepared the nodes for installing YugabyteDB. Execute the following steps on each of the instances. Follow the to install YugabyteDB on each of the nodes. Run the server on each of the nodes as follows: ```sh $ ./bin/yb-master \ --master_addresses 172.151.17.130:7100,172.151.17.220:7100,172.151.17.140:7100 \ --rpcbindaddresses 172.151.17.130 \ --fsdatadirs "/home/centos/disk1,/home/centos/disk2" \ --placement_cloud aws \ --placement_region us-west \ --placement_zone us-west-2a \ --leaderfailuremaxmissedheartbeat_periods 10 \ >& /home/centos/disk1/yb-master.out & ``` Note how multiple directories can be provided to the `--fsdatadirs` flag. Replace the value with the private IP address of the host as well as the set the `--placementcloud`,`--placementregion`, and `--placement_zone` values appropriately. Notice how the flag is set to `10`. This flag specifies the maximum heartbeat periods that the leader can fail to heartbeat before the leader is considered to be failed. Because the data is geo-replicated across data centers, RPC latencies are expected to be higher. Use this flag to increase the failure detection interval in higher RPC latency deployments. The total failure timeout is now 5 seconds, and is calculated by multiplying (default of 500ms) by (current value of `10`). For the full list of configuration flags, see the

Run the server on each node as follows: ```sh $ ./bin/yb-tserver \ --tservermasteraddrs 172.151.17.130:7100,172.151.17.220:7100,172.151.17.140:7100 \ --rpcbindaddresses 172.151.17.130 \ --enable_ysql \ --pgsqlproxybind_address 172.151.17.130:5433 \ --cqlproxybind_address 172.151.17.130:9042 \ --fsdatadirs "/home/centos/disk1,/home/centos/disk2" \ --placement_cloud aws \ --placement_region us-west \ --placement_zone us-west-2a \ --leaderfailuremaxmissedheartbeat_periods 10 \ >& /home/centos/disk1/yb-tserver.out & ``` Note that all of the master addresses have to be provided using the flag. Replace the value with the private IP address of the host as well as the set the `placementcloud`,`placementregion`, and `placement_zone` values appropriately. As with the YB-Masters, set the flag to `10` to account for higher RPC latencies. For the full list of configuration flags, see the . The default replica placement policy when the cluster is first created is to treat all nodes as equal irrespective of the `--placement_*` configuration flags. However, for the current deployment, you want to explicitly place one replica of each tablet in each region/AZ. The following command sets replication factor of `3` across `us-west-2`/`us-west-2a`, `us-east-1`/`us-east-1a`, `ap-northeast-1`/`ap-northeast-1a` leading to such a placement. On any host running the yb-master, run the following command: ```sh $ ./bin/yb-admin \ --master_addresses 172.151.17.130:7100,172.151.17.220:7100,172.151.17.140:7100 \ modifyplacementinfo \ aws.us-west.us-west-2a,aws.us-east-1.us-east-1a,aws.ap-northeast-1.ap-northeast-1a 3 ``` Verify by running the following: ```sh $ curl -s http://<any-master-ip>:7000/cluster-config ``` Confirm that the output looks similar to the following with set to `1` for each AZ: ```json replication_info { live_replicas { num_replicas: 3 placement_blocks { cloud_info { placement_cloud: "aws" placement_region: "us-west" placement_zone: "us-west-2a" } minnumreplicas: 1 } placement_blocks { cloud_info { placement_cloud: "aws" placement_region: "us-east-1" placement_zone: "us-east-1a" } minnumreplicas: 1 } placement_blocks { cloud_info { placement_cloud: "aws" placement_region: "ap-northeast-1" placement_zone: "ap-northeast-1a" } minnumreplicas: 1 } } } ``` One additional option to consider is to set a preferred location for all the tablet leaders using the command. For multi-row or multi-table transactional operations, colocating the leaders in a single zone or region can help reduce the number of cross-region network hops involved in executing a transaction and, as a result, improve performance. The following command sets the preferred zone to `aws.us-west.us-west-2a`: ```sh $ ./bin/yb-admin \ --master_addresses 172.151.17.130:7100,172.151.17.220:7100,172.151.17.140:7100 \ setpreferredzones \ aws.us-west.us-west-2a ``` Looking again at the cluster configuration, you should see `affinitized_leaders` added: ```json replication_info { live_replicas { num_replicas: 3 placement_blocks { cloud_info { placement_cloud: "aws" placement_region: "us-west" placement_zone: "us-west-2a" } minnumreplicas: 1 } placement_blocks { cloud_info { placement_cloud: "aws" placement_region: "us-east-1" placement_zone: "us-east-1a" } minnumreplicas: 1 } placement_blocks { cloud_info { placement_cloud: "aws" placement_region: "ap-northeast-1" placement_zone: "ap-northeast-1a" } minnumreplicas: 1 } affinitized_leaders { placement_cloud: "aws" placement_region: "us-west" placement_zone: "us-west-2a" } } } ``` Use the (for YSQL API) or (for YCQL API) shells to test connectivity to the cluster.