AntDB Installation and Deployment Documentation - P3
Tags: database
Published: 2023-07-14 03:08:10

### Dual-center environment deployment instructions

The dual-center environment is built in two main steps.

1. Build the main center
2. Build the secondary center

The deployment method of the primary center can be referred to the above distributed version (single center) installation and deployment chapter.

There are three main steps for deploying the sub-center.

1. Modify part of the configuration of the main center mgr
2. Deploy the mgr of the sub-center
3. Deploy the sub-center node

#### Modify part of the configuration of the main center mgr

##### Modify the hba file

Add the IP address of the host where the secondary center mgr is located to the pg\_hba.conf file of the primary center mgr; otherwise, the establishment of stream replication will not be successful. For example:

```
host    replication     all             10.1.226.202/32          trust 
```

Configure the password-free access of the backup center mgr in the hba file of all nodes in the backup center

##### Modify the postgresql.conf file

Change the value of the listen\_addresses field in the postgresql.conf file of the primary center from the default localhost to \*, or a list of IP addresses. Change the wal\_level to hot\_standby, refer to the following:

```
listen_addresses = '*' 
max_wal_senders = 5  
wal_keep_size = 5120 
wal_level = replica 
hot_standby = on 
log_destination = 'csvlog' 
logging_collector = on  
log_directory = 'pg_log' 
mgr_zone ='local' #Configured by the zone name of the actual main center, the default is local
```

##### Restart mgr

```
mgr_ctl restart -D /home/shan2/mgr 
```

#### Deploy the mgr of the sub-center

##### Backup data directory

On the secondary machine, use the pg\_basebackup command to set up the secondary mgr, you can refer to the "pg\_basebackup --help" command for help.

```
#Connect to the main center's MGR for pg_basebackup
pg_basebackup -h 10.1.226.201 -p 7435 -X stream --nodename=mgr -R -D /home/shan2/smgr 
```

##### Modify the postgresql.conf file

Modify the mgr\_zone name in the postgresql.conf file of the subcenter mgr, and change it to "zone2", which is the name of the subcenter's zone.

```
mgr_zone = 'zone2' #Set up according to actual needs
```

##### Modify the folder permissions

Modify the permission of the folder where the slave mgr is located to 0700

```
chmod 0700 /home/shan2/smgr 
```

##### Start the slave mgr

```
mgr_ctl start -D /home/shan2/smgr 
```

#### Deploy the slave center section

##### Add and deploy the slave host

Refer to Adding hosts and deploying binaries above.

##### Add a slave node

Note: **The following operations can only be performed on the master mgr**

Note: **All master nodes in the master center must have a direct slave node in the slave center.** slave nodes can have cascading slave nodes.

```
--For example: main center includes gtmcoord master gc; coordinator master coord0 and coord1; datanode master dm0 and dm1
--Then the sub-center must not be at least a corresponding backup node for the above master node
add coordinator slave sc0zone2 for coord0(path = '/home/shan2/pgdata_xc/coord/s0', host='host107', port=4338,zone='zone2'); 
 
add coordinator slave sc1zone2 for coord1(path = '/home/shan2/pgdata_xc/coord/s1', host='host108', port=4338,zone='zone2'); 
 
add gtmcoord slave gszone2 for gc(host='host107',port=6775, path='/home/shan2/pgdata_xc/sgc',zone='zone2'); 
 
add datanode slave ds1zone2 for dm1(host='host108',port=24335,path='/home/shan2/pgdata_xc/datanode/s1',zone='zone2'); 
 
add datanode slave ds0zone2 for dm0(host='host107',port=14335,path='/home/shan2/pgdata_xc/datanode/s0',zone='zone2'); 
```

View all nodes belonging to the specified sub-center:

```
list node zone zone_name; 
```

For example:

```
postgres=# LIST NODE ZONE zone2; 
   name   |    host    |       type        | mastername | port  | sync_state |               path                              | initialized | incluster | readonly | zone   
----------+------------+-------------------+------------+-------+------------+-----------------------------------+----------- 
--+-----------+----------+------- 
 gszone2  | host107 | gtmcoord slave      | gtmcoord        |  6775 | async      | /home/shan2/pgdata_xc/sgc         | f          | f         | f        | zone2 
 sc0zone2 | host107 | coordinator slave   | coord0     |  4338 | async      | /home/shan2/pgdata_xc/coord/s0    | f          | f         | f        | zone2 
 sc1zone2 | host108 | coordinator slave   | coord1     |  4338 | async      | /home/shan2/pgdata_xc/coord/s1    | f          | f         | f        | zone2 
 ds0zone2 | host107 | datanode slave      | dm0        | 14335 | async      | /home/shan2/pgdata_xc/datanode/s0 | f          | f         | f        | zone2 
 ds1zone2 | host108 | datanode slave      | dm1        | 24335 | async      | /home/shan2/pgdata_xc/datanode/s1 | f          | f         | f        | zone2 
(5 rows) 
```