This topic describes how to deploy and manage OceanBase Database on a single server by using systemd.
Notice
Operations in this topic are applicable only to a learning or testing environment. Do not apply them to a production environment.
Prerequisites
Before you start, make sure that the following conditions are met:
You are using one of the following RPM-based operating systems:
CentOS Linux 7.X and 8.X
Anolis OS 8.X and 23
openSUSE 15.X
openEuler 22.03
The size of available memory in the current environment exceeds 3 GB.
You have installed jq, a command-line tool, in your environment and configured systemd as the system and service manager.
You have installed the mysql client or OceanBase Client (OBClient) in your environment for database connection.
You are going to deploy OceanBase Database V4.2.2 or later.
You have the permissions to run sudo commands.
Deploy OceanBase Database
Step 1: Install OceanBase Database
You can install OceanBase Database online or offline, depending on whether your environment is connected to the Internet.
Add the OceanBase image source.
[admin@test001 ~]$ sudo yum-config-manager --add-repo https://mirrors.aliyun.com/oceanbase/OceanBase.repoInstall OceanBase Database.
[admin@test001 ~]$ sudo yum install oceanbase-ce oceanbase-ce-libs obclientBy default, the preceding command deploys OceanBase Database of the latest version. You can install a specific version by declaring the version number. For example, you can use the
yum install oceanbase-ce-4.2.2.0command to install OceanBase Database V4.2.2. We recommend that you install the latest version.
Visit OceanBase Download Center to download OceanBase Database of the required version and the matched dependent libraries (OceanBase Libs). Then, copy the downloaded packages to your server. We recommend that you download the latest version.
Run the rpm command in the directory where the installation package is located to install OceanBase Database.
[admin@test001 ~]$ sudo rpm -ivh oceanbase-ce-*.rpm
Step 2: Start OceanBase Database
You can start OceanBase Database by performing the following steps:
(Optional) Modify the configuration file.
Run the following command to open the configuration file and modify it by referring to this step. If you skip this step, default configurations are used.
[admin@test001 ~]$ sudo vim /etc/oceanbase.cnfThe configuration file contains the following parameters:
ip=127.0.0.1 mysql_port=2881 rpc_port=2882 obshell_port=2886 root_pwd="" redo_dir=/var/lib/oceanbase/redo data_dir=/var/lib/oceanbase/data datafile_size=2G cpu_count=16 memory_limit=6G system_memory=1G log_disk_size=13GNote
You can add other parameters to the configuration file. For more information about the parameters, see Parameter summary.
At present, you cannot modify the zone of an OBServer node, which is
zone1by default.
The following table describes parameters in the configuration file.
Parameter Required Default value Description ip No 127.0.0.1 The IP address of the OBServer node. At present, you cannot specify an IPv6 address for an OBServer node. mysql_port No 2881 The SQL port of OceanBase Database. rpc_port No 2882 The RPC port of OceanBase Database. obshell_port No 2886 The O&M port of OceanBase Database. root_pwd No Empty The password of the super administrator ( root@sys) of the OceanBase cluster. We recommend that you set a complex password.redo_dir No /var/lib/oceanbase/redo The directory for storing clogs, ilogs, and slogs. We recommend that you set the directory on a separate disk. Note
The available space of the data disk (
/var/lib/oceanbase/by default) must be greater than 15 GB.data_dir No /var/lib/oceanbase/data The directory for storing SSTables and other data. We recommend that you use a separate disk. Note
The available space of the data disk (
/var/lib/oceanbase/by default) must be greater than 15 GB.datafile_size No 0 The size of the data file block_fileon the corresponding OBServer node. If this parameter is not configured, thedatafile_disk_percentageparameter takes effect. For more information, see datafile_size and datafile_disk_percentage.cpu_count No 0 The total number of CPU cores that OceanBase Database can use. If you set the parameter to 0, the system will automatically detect the number of CPU cores. memory_limit No 0 The maximum memory that the observer process can obtain from the environment. If this parameter is not configured, the memory_limit_percentageparameter takes effect. For more information about the two parameters, see memory_limit and memory_limit_percentage.system_memory No 0M The reserved system memory, which is part of memory_limit. If this parameter is not configured, OceanBase Database reserves memory for the system in adaptive mode.log_disk_size No 0 The size of the redo log disk. If this parameter is not configured, the log_disk_percentageparameter takes effect. For more information, see log_disk_size and log_disk_percentage.Modify the owner of the
etcdirectory in the installation directory of OceanBase Database. By default, the installation directory is/home/admin/oceanbase.[admin@test001 ~]$ sudo chown root /home/admin/oceanbase/etcStart OceanBase Database.
[admin@test001 ~]$ sudo systemctl start oceanbaseView the startup status of OceanBase Database.
[admin@test001 ~]$ sudo systemctl status oceanbaseIf
Service is readyis displayed, OceanBase Database has been started.
Step 3: Connect to OceanBase Database
In this example, OBClient is used to connect to OceanBase Database. Run the following command:
[admin@test001 ~]$ obclient -h<IP> -uroot@sys -P<Port> -p<Passwd> -A oceanbase
where
-hspecifies the IP address for connecting to OceanBase Database. If you start OceanBase Database by using systemd, the IP address is127.0.0.1by default.-uspecifies the account for connecting to OceanBase Database, in the format ofusername@tenant name. The default username of the administrator of a MySQL tenant isroot.-Pspecifies the port for connecting to OceanBase Database, which is the value ofmysqlPortin theoceanbase.cnfconfiguration file in theetcdirectory.-pspecifies the password for connecting to OceanBase Database, which is the value ofrootPwdin theoceanbase.cnfconfiguration file in theetcdirectory. Instead of providing the password in the command, we recommend that you enter the password as prompted after you run the command. This way, the password is masked.-Aspecifies not to automatically retrieve statistics when connecting to OceanBase Database by using OBClient.oceanbasespecifies the name of the database to access. You can change it to the name of a business database.
Manage OceanBase Database
Currently, you can use systemd only to start, stop, and view the status of OceanBase Database.
View the status of OceanBase Database
Run the following command to query the status of OceanBase Database:
[admin@test001 ~]$ sudo systemctl status oceanbase
OceanBase Database may be in one of the following states:
If the value of the
Activefield isactive (running), and that of theStatusfield isService is running, OceanBase Database is being started.If the value of the
Activefield isactive (running), and that of theStatusfield isService is ready, OceanBase Database is successfully started.If the value of the
Activefield isinactive (dead), OceanBase Database is stopped.If the value of the
Activefield isfailed, an error occurred to OceanBase Database and you must check the logs for troubleshooting.
View detailed logs of OceanBase Database
When OceanBase Database is abnormal, you can run the following command to view the detailed logs of OceanBase Database:
[admin@test001 ~]$ sudo journalctl -u oceanbase
Actually, systemd sends requests to communicate with the management tool OBShell of OceanBase Database, thereby controlling the status of OBServer nodes. Many trace IDs are recorded in logs. You can use OBShell APIs in conjunction with these trace IDs for troubleshooting. The command is as follows:
[admin@test001 ~]$ curl -X GET http://<ip>:<obshell_port>/api/v1/task/dag/<trace id> | jq
If an error is returned in the observer start or bootstrap phase, you also need to view the logs of the OBServer node, which are stored in the /home/admin/oceanbase/log directory by default.
FAQ
ERROR: current user(uid=0) that starts observer is not the same with the original one(uid=500)
A common cause is that the owner of the
etcdirectory in the installation directory of OceanBase Database, which is/home/admin/oceanbaseby default, is not the current user. In this case, you can run the following command:chown root /home/admin/oceanbase/etcerrcode=-4290, file=“ob_server_log_block_mgr.cpp”, line_no=1127, info=“::fallocate failed”
A common cause is that the available space of the data disk of OceanBase Database, which is
/var/lib/oceanbase/by default, is insufficient. In this case, you can increase the data disk space.
Clear OceanBase Database
You can perform the following steps to clear OceanBase Database started by using systemd:
Stop OceanBase Database.
[admin@test001 ~]$ sudo systemctl stop oceanbaseUninstall OceanBase Database.
Delete the package of OceanBase Database.
If you have installed OceanBase Database online, run the following command to delete the package:
[admin@test001 ~]$ sudo yum erase packageYou must replace
packagewith the actual name of the package to be deleted. To view the package name, run theyum list | grep oceanbasecommand.If you have installed OceanBase Database offline, run the following command to delete the package:
[admin@test001 ~]$ sudo rpm -e packageYou must replace
packagewith the actual name of the package to be deleted. To view the package name, run therpm -qa | grep oceanbasecommand.(Optional) Delete the data of OceanBase Database.
After you perform the preceding step, OceanBase Database is uninstalled from your environment, but the database data still exists. If you redeploy OceanBase Database later, you can view and use the data.
After you perform this step, the data of OceanBase Database is completely deleted.
Delete the installation directory of OceanBase Database.
[admin@test001 ~]$ sudo rm -rf /home/admin/oceanbaseDelete the data directory of OceanBase Database.
[admin@test001 ~]$ sudo rm -rf /var/lib/oceanbase
References
You can log on to the cluster and run the
ALTER USERcommand to modify the user password. For more information, see ALTER USER.For more information about how to connect to OceanBase Database after the deployment, see Connect to OceanBase Database.