OceanBase Database supports the arbitration service since V4.1. The arbitration service can resolve the issue that the response time increases when a replica in the same region fails in the deployment scenario of three IDCs across two regions. The arbitration service can also reduce the cross-region bandwidth overhead and minimize the costs of the third IDC.
This topic describes how to deploy a two-replica OceanBase cluster with the arbitration service by using the CLI.
Note
- A single OceanBase cluster can use only one arbitration service.
- Currently, the arbitration service supports only standalone deployment.
Considerations
If the database to deploy requires resource isolation, you must first configure cgroups before you deploy the database.
For more information about how to configure resource isolation and cgroups, see Resource isolation and Configure cgroups.
Prerequisites
Before you install OceanBase Database, make sure that:
The OBServer node has been configured. For more information, see Configure servers, (Optional) Configure the clock source, and Initialize an OBServer node by using oatcli.
You have obtained the RPM package of OceanBase Database. For more information, see Prepare installation packages.
Procedure
Step 1: Deploy an OceanBase cluster
Install the RPM package on the two servers that you want to deploy OceanBase Database.
Install the RPM package for OceanBase Database.
Go to the directory where the RPM package of OceanBase Database is saved.
[root@xxx /]# cd $rpm_dirInstall the RPM package of OceanBase Database.
[root@xxx $rpm_dir]# rpm -ivh $rpm_name [--prefix=/home/admin/oceanbase]Here,
$rpm_dirspecifies the directory in which the RPM package is stored and$rpm_namespecifies the name of the RPM package.Note
The OceanBase Database software will be installed under the
/home/admin/oceanbasedirectory.Here is an example:
[root@xxx /home/admin/rpm]# rpm -ivh oceanbase-4.2.0.0-100000052023073123.el7.x86_64.rpm Preparing... ################################# [100%] Updating / installing... 1:oceanbase-4.2.0.0-100000052023073################################# [100%](Optional) Install OBClient.
OceanBase Client (OBClient) is a CLI client tool dedicated to OceanBase Database. You can use it to connect to MySQL tenants and Oracle tenants of OceanBase Database. If you only need to connect to a MySQL tenant, you can also use a MySQL client to access OceanBase Database.
Notice
In order to use versions of OBClient before V2.2.1, install OceanBase Connector/C due to its dependency. To obtain the RPM packages of OBClient and OceanBase Connector/C, contact OceanBase Technical Support.
Here is an example:
[root@xxx /home/admin/rpm]# rpm -ivh obclient-2.2.1-20221122151945.el7.alios7.x86_64.rpm Preparing... ################################# [100%] Updating / installing... 1:obclient-2.2.1-20221122151945.el7################################# [100%]Verify that the installation is successful.
[root@xxx /home/admin/rpm]# which obclient /usr/bin/obclient
Configure the observer process directory.
(Optional) Clear the OceanBase Database directory.
You do not need to clear the directory if you deploy OceanBase Database on the server for the first time.
You can directly clear the old OceanBase Database directory in the following cases:
- You want to clear the old OceanBase Database environment.
- Problems occur during the installation and deployment process of OceanBase Database. The installation environment becomes disordered or files that will affect the next installation are generated.
[root@xxx /home/admin]# kill -9 `pidof observer` [root@xxx /home/admin]# rm -rf /data/1/$cluster_name [root@xxx /home/admin]# rm -rf /data/log1/$cluster_name [root@xxx /home/admin]# rm -rf /home/admin/oceanbase/store/$cluster_name [root@xxx /home/admin]# rm -rf /home/admin/oceanbase/log/* /home/admin/oceanbase/etc/*config*Here,
$cluster_namespecifies the cluster name.Here is an example:
[root@xxx /home/admin]# kill -9 `pidof observer` [root@xxx /home/admin]# rm -rf /data/1/obdemo [root@xxx /home/admin]# rm -rf /data/log1/obdemo [root@xxx /home/admin]# rm -rf /home/admin/oceanbase/store/obdemo [root@xxx /home/admin]# rm -rf /home/admin/oceanbase/log/* /home/admin/oceanbase/etc/*config*Initialize the OceanBase Database directory.
We recommend that you specify the data directory of OceanBase Database to an independent disk and link this directory to the home directory of OceanBase Database by using a soft link.
Run the following command to switch to the
adminuser:[root@xxx /home/admin]# su - adminRun the following command as the
adminuser to create the related directories:mkdir -p /data/1/$cluster_name/{etc3,sstable,slog}mkdir -p /data/log1/$cluster_name/{clog,etc2}mkdir -p /home/admin/oceanbase/store/$cluster_nameRun the following command as the
adminuser to create soft links:for t in {etc3,sstable,slog};do ln -s /data/1/$cluster_name/$t /home/admin/oceanbase/store/$cluster_name/$t; donefor t in {clog,etc2};do ln -s /data/log1/$cluster_name/$t /home/admin/oceanbase/store/$cluster_name/$t; doneHere,
$cluster_namespecifies the cluster name. Note thatslogfiles and data files must be on the same disk.Here is an example:
[root@xxx /home/admin]# su - admin -bash-4.2$ mkdir -p /data/1/obdemo/{etc3,sstable,slog} -bash-4.2$ mkdir -p /data/log1/obdemo/{clog,etc2} -bash-4.2$ mkdir -p /home/admin/oceanbase/store/obdemo -bash-4.2$ for t in {etc3,sstable,slog};do ln -s /data/1/obdemo/$t /home/admin/oceanbase/store/obdemo/$t; done -bash-4.2$ for t in {clog,etc2};do ln -s /data/log1/obdemo/$t /home/admin/oceanbase/store/obdemo/$t; doneNote
The
obdemodirectory is named after the cluster and can be modified. It is required when the process starts.The result is as follows:
-bash-4.2$ cd /home/admin/oceanbase -bash-4.2$ tree store/ store/ `-- obdemo |-- clog -> /data/log1/obdemo/clog |-- etc2 -> /data/log1/obdemo/etc2 |-- etc3 -> /data/1/obdemo/etc3 |-- slog -> /data/1/obdemo/slog `-- sstable -> /data/1/obdemo/sstable 6 directories, 0 files
Initialize the OceanBase cluster.
Note
The IP addresses in the sample code are for reference only. You need to enter the actual server IP address during deployment.
Start the observer process.
Start the observer process as the
adminuser on each node.Notice
In a two-replica OceanBase cluster, the startup parameters of the OBServer nodes are not exactly the same. When you start the observer process, you only need to specify the two or more servers that run RootService. You can add servers after the cluster is created.
cd /home/admin/oceanbase && /home/admin/oceanbase/bin/observer {-I $ip | -i $devname} -P $rpc_port -p $sql_port -z $zone_name -d /home/admin/oceanbase/store/$cluster_name -r '$ip:2882:2881' -c $cluster_id -n $cluster_name -o "system_memory=30G,datafile_size=500G,config_additional_dir=/data/1/$cluster_name/etc3;/data/log1/$cluster_name/etc2"The parameters are described in the following table:
Parameter Description -I|-i-I: the IP address of the node to be started. In multi-node deployment, you cannot use 127.0.0.1 as the destination IP address. We recommend that you use an IP address such as-I 10.10.10.1, to start a node.-i: the NIC name. You can use theifconfigcommand to view the NIC name.
Note
OceanBase Database allows you to start a node by specifying both the IP address and the NIC. For example,
-I 10.10.10.1 -i eth0. However, we recommend that you do not use this method.-pThe service port number, which is usually set to 2881.-PThe RPC port number, which is usually set to 2882.-nThe name of the cluster. It can be modified. Cluster names must be unique. -zThe zone where the started observer process belongs. -dThe primary directory of the cluster, which is created during initialization. Do not modify fields other than $cluster_name.-cThe cluster ID. It is a group of digits and can be modified. Cluster IDs must be unique. -lThe log level. -rThe RootService list in the format of $ip:2882:2881. Multiple items are separated with semicolons (;) to indicate RootService information.-oThe cluster startup parameters that need to be specified as needed. system_memoryspecifies the internal reserved memory of OceanBase Database, which is30Gby default. You can adjust this parameter to a smaller value in the case of insufficient memory on the server. The impact is that memory may be insufficient during performance tests.datafile_sizespecifies the size of theSSTabledata file of OceanBase Database, which is determined based on the available space of/data/1/. You no longer need to specify the size again once specified in this step. We recommend that you specify the data file size to at least100Gand reserve some spaces.config_additional_dirspecifies the redundancy directory for the parameter file.
Here is an example:
Start the observer process on the OBServer nodes whose IP addresses are
10.10.10.1and10.10.10.2respectively.zone1:
[root@xxx admin]# su - admin -bash-4.2$ cd /home/admin/oceanbase && /home/admin/oceanbase/bin/observer -I 10.10.10.1 -P 2882 -p 2881 -z zone1 -d /home/admin/oceanbase/store/obdemo -r '10.10.10.1:2882:2881;10.10.10.2:2882:2881' -c 10001 -n obdemo -o "system_memory=30G,datafile_size=500G,config_additional_dir=/data/1/obdemo/etc3;/data/log1/obdemo/etc2"zone2:
[root@xxx admin]# su - admin -bash-4.2$ cd /home/admin/oceanbase && /home/admin/oceanbase/bin/observer -I 10.10.10.2 -P 2882 -p 2881 -z zone2 -d /home/admin/oceanbase/store/obdemo -r '10.10.10.2:2882:2881;10.10.10.2:2882:2881' -c 10001 -n obdemo -o "system_memory=30G,datafile_size=500G,config_additional_dir=/data/1/obdemo/etc3;/data/log1/obdemo/etc2"You can use the following commands to check whether the observer process has started successfully:
- Run the
netstat -ntlpcommand. If ports2881and2882are being listened to, the observer process is started. - Run the
ps -ef|grep observercommand to return information about the observer process.
Here is an example:
-bash-4.2$ netstat -ntlp (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:2881 0.0.0.0:* LISTEN 11112/observer tcp 0 0 0.0.0.0:2882 0.0.0.0:* LISTEN 11112/observer ... ... ... ... ... ... -bash-4.2$ ps -ef|grep observer admin 11112 0 40 16:18 ? 00:00:17 /home/admin/oceanbase/bin/observer -I 10.10.10.1 -P 2882 -p 2881 -z zone1 -d /home/admin/oceanbase/store/obdemo -r 10.10.10.1:2882:2881;10.10.10.2:2882:2881 -c 10001 -n obdemo -o system_memory=30G,datafile_size=500G,config_additional_dir=/data/1/obdemo/etc3;/data/log1/obdemo/etc2Perform the bootstrap operation on the cluster.
Connect to any node by using the obclient command. The password is empty.
[root@xxx admin]# obclient -h127.1 -uroot -P2881 -p Enter password: obclient [(none)]> SET SESSION ob_query_timeout=1000000000; Query OK, 0 rows affected obclient [(none)]> ALTER SYSTEM BOOTSTRAP ZONE 'zone1' SERVER '10.10.10.1:2882',ZONE 'zone2' SERVER '10.10.10.2:2882'; Query OK, 0 rows affectedNotice
If an error is reported in this step, the reason may be that the startup parameter of the observer process is incorrect, the privileges on the directories related to the OBServer nodes are incorrect, the space of the log directory does not meet the required proportion, the time is not synchronous on the OBServer nodes, or the node memory resources are insufficient. The log directory issue occurs because the log directory shares the same upper-level directory with the data directory, resulting in space occupation by the data directory. Check these issues and then clear the OceanBase Database directory.
Verify that the cluster is initialized.
After you perform the bootstrap operation and execute the
SHOW DATABASESstatement, ifoceanbaseappears in the database list, the cluster has been initialized.obclient [(none)]> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | LBACSYS | | mysql | | oceanbase | | ORAAUDITOR | | SYS | | test | +--------------------+ 7 rows in setChange the password.
By default, the password of the root user under the
systenant is empty. After successful initialization, you need to change the password.obclient [(none)]> ALTER USER root IDENTIFIED BY '******'; Query OK, 0 rows affected
Step 2: Deploy the arbitration service
Install the RPM package of OceanBase Database on the server that you want to deploy the arbitration service.
Go to the directory where the RPM package of OceanBase Database is saved.
[root@xxx /]# cd $rpm_dirInstall the RPM package of OceanBase Database.
[root@xxx $rpm_dir]# rpm -ivh $rpm_name [--prefix=/home/admin/oceanbase]Here,
$rpm_dirspecifies the directory in which the RPM package is stored, and$rpm_namespecifies the name of the RPM package.Note
The OceanBase Database software will be installed under the
/home/admin/oceanbasedirectory.Here is an example:
[root@xxx /home/admin/rpm]# rpm -ivh oceanbase-4.2.0.0-100000052023073123.el7.x86_64.rpm Preparing... ################################# [100%] Updating / installing... 1:oceanbase-4.2.0.0-100000052023073################################# [100%]Configure the arbitration server process directory.
Create the
clogdirectory for the arbitration server process in the arbitration server.Note
- When you start the arbitration server process, make sure that the
clogdirectory is created in thestoredirectory specified by the-dparameter. - Make sure that the disk where the
storedirectory resides is not fully occupied. Otherwise, the arbitration server may be abnormal.
Run the following command to switch to the
adminuser:[root@xxx /home/admin]# su - adminRun the following command as the
adminuser to create the related directories:mkdir -p /home/admin/oceanbase/store/clog- When you start the arbitration server process, make sure that the
Start the arbitration server process.
Start the arbitration server process in arbitration mode as the
adminuser of the arbitration server and specify the required startup parameters. Here is the sample statement:cd /home/admin/oceanbase && /home/admin/oceanbase/bin/observer -m arbitration -P $rpc_port -d $obdir/store [{-I $ip | -i $devname}] [-l $log_level] [-o "parameters_list"]The parameters are described in the following table:
Parameter Description -mThe arbitration mode. The value is arbitration.-PThe RPC port number of the arbitration server process, which is usually set to 2882.-dThe path for the storedirectory, which is usually set to/home/admin/oceanbase/store. Make sure that theclogfolder is created in thestoredirectory.-I|-i-I: The IP address of the node to be started.-i: The NIC name. You can use theifconfigcommand to view the NIC name.
Note
OceanBase Database allows you to start a node by specifying both the IP address and the NIC. For example,
-I 10.10.10.1 -i eth0. However, we recommend that you do not use this method.-l(Optional) The log level. Default value: WDIAG. Valid values: {DEBUG,TRACE,WDIAG,EDIAG,INFO,WARN, andERROR}. For more information, see Log levels.-o(Optional) The list of options. You can specify multiple options and separate them with commas (,).
The following options are available for the arbitration server process:Here is an example:
Start the arbitration server process on the arbitration server whose IP address is
10.10.10.3.-bash-4.2$ cd /home/admin/oceanbase && /home/admin/oceanbase/bin/observer -m arbitration -P 2882 -d /home/admin/oceanbase/store -I 10.10.10.3 /home/admin/oceanbase/bin/observer -m arbitration -P 2882 -d /home/admin/oceanbase/store -I 10.10.10.3 server startup mode: arbitration rpc port: 2882 data_dir: /home/admin/oceanbase/store local_ip: 10.10.10.3You can use the following commands to check whether the observer process has started successfully:
- Run the
netstat -ntlpcommand. If the2882port is being listened to, the process is started successfully. - Run the
ps -ef|grep observercommand to return information about the observer process.
Here is an example:
-bash-4.2$ netstat -ntlp (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:2882 0.0.0.0:* LISTEN 18231/observer ... -bash-4.2$ ps -ef|grep observer admin 18231 0 3 10:33 ? 00:00:00 /home/admin/oceanbase/bin/observer -m arbitration -P 2882 -d /home/admin/oceanbase/store -I 10.10.10.3 ...
Step 3: Add the arbitration service to a cluster
Run the following command to add the arbitration service to a cluster:
ALTER SYSTEM ADD ARBITRATION SERVICE "$arb_server_ip:$arb_server_port";
Note
The address of the arbitration server process is recorded in an internal table in the sys tenant. You can view the process address in the DBA_OB_ARBITRATION_SERVICE view.
Here is an example:
obclient [(none)]> ALTER SYSTEM ADD ARBITRATION SERVICE "10.10.10.3:2882";
Query OK, 0 rows affected
obclient [(none)]> SELECT * FROM oceanbase.DBA_OB_ARBITRATION_SERVICE;
+---------------------+---------------------+-------------------------+---------------------+------------------------------+------+
| CREATE_TIME | MODIFY_TIME | ARBITRATION_SERVICE_KEY | ARBITRATION_SERVICE | PREVIOUS_ARBITRATION_SERVICE | TYPE |
+---------------------+---------------------+-------------------------+---------------------+------------------------------+------+
| 2023-03-06 17:29:36 | 2023-03-06 17:29:36 | default | 10.10.10.3:2882 | NULL | ADDR |
+---------------------+---------------------+-------------------------+---------------------+------------------------------+------+
1 row in set
Step 4: Enable the arbitration service for the sys tenant
You can enable the arbitration service for a tenant when you create the tenant. For more information, see CREATE TENANT.
If you do not enable the arbitration service when you create the tenant, you can still enable it after the tenant is created.
Execute the following statement to enable the arbitration service for a tenant:
ALTER TENANT $tenant_name [SET] enable_arbitration_service = true;
Here is an example:
Enable the arbitration service for the sys tenant of the cluster.
obclient [(none)]> ALTER TENANT sys SET enable_arbitration_service = true;
Query OK, 0 rows affected
Step 5: Query the status of the arbitration service in the tenant
Check whether the arbitration service is enabled for the tenant.
You can check whether the arbitration service is enabled for the tenant by querying the
arbitration_service_statuscolumn of theDBA_OB_TENANTSview.Values of
arbitration_service_statusare described as follows:ENABLED: The arbitration service is enabled for the tenant.ENABLING: The arbitration service is being enabled for the tenant.DISABLED: The arbitration service is disabled for the tenant.DISABLING: The arbitration service is being disabled for the tenant.
Here is an example:
obclient [(none)]> SELECT TENANT_ID,TENANT_NAME,ARBITRATION_SERVICE_STATUS FROM oceanbase.DBA_OB_TENANTS WHERE tenant_name = 'sys'; +-----------+-------------+----------------------------+ | TENANT_ID | TENANT_NAME | ARBITRATION_SERVICE_STATUS | +-----------+-------------+----------------------------+ | 1 | sys | ENABLED | +-----------+-------------+----------------------------+ 1 row in setCheck whether the arbitration service is available.
After you enable the arbitration service, the existing log streams of the tenant can use the arbitration service, but the new log streams created afterward may not be able to use it. This is because a log stream is created in non-strict mode. In this mode, it is possible that the arbitration service may fail to be created. You can execute the following statement to verify whether all log streams of the tenant can use the arbitration service.
## Obtain a list of log streams that do not have arbitration replicas. ## (SELECT distinct ls_id FROM GV$OB_LOG_STAT WHERE tenant_id = xxx) except (SELECT ls_id FROM GV$OB_LOG_STAT WHERE tenant_id = xxx and role = 'LEADER' and arbitration_member = "$arb_server_ip:$arb_server_port");Here is an example:
Obtain a list of log streams that do not have arbitration replicas in the
systenant. If an empty set is returned, the arbitration service is available in the current tenant.obclient [oceanbase]> (SELECT distinct ls_id FROM GV$OB_LOG_STAT WHERE tenant_id = 1) except (SELECT ls_id FROM GV$OB_LOG_STAT WHERE tenant_id = 1 and role = 'LEADER' and arbitration_member = "10.10.10.3:2882"); Empty set
What to do next
After the cluster is created, you can create user tenants based on your business needs.
For more information about how to create a tenant by using the CLI, see Create a tenant.