This topic describes how to initialize nodes by using obshell-sdk-python. The goal is to send the RPM packages required for deploying OceanBase Database (including oceanbase-ce, oceanbase-ce-libs, oceanbase-ce-utils, and obshell) to each node and initialize the directories.
Note
Before you proceed, we recommend that you read the Quick Start topic to learn how to use obshell-sdk-python.
Considerations
Before you initialize a node, download the required RPM packages to the server. You can download the RPM packages manually or by using obshell-sdk-python. For more information about how to download the RPM packages by using obshell-sdk-python, see Download RPM packages.
Sample code
from obshell import initialize_nodes, start_obshell, NodeConfig
def init_nodes():
pkgs = [
"/root/download/oceanbase-ce-libs-4.2.5.0-100000052024102022.el7.x86_64.rpm",
"/root/download/oceanbase-ce-4.2.5.0-100000052024102022.el7.x86_64.rpm",
# The above two software packages are sufficient for initializing the OceanBase cluster, but for easier maintenance, it is recommended to also install the following two packages.
# The utils package provides ob_admin, which can provide the ability to parse the recovery window during subsequent recovery.
"/root/download/oceanbase-ce-utils-4.2.5.0-100000052024102022.el7.x86_64.rpm",
# The OceanBase database configured above already includes obshell, but it is recommended to use the latest version of obshell, so the latest version of obshell is installed separately.
"/root/download/obshell-4.2.4.3-12024110711.el7.x86_64.rpm",
]
ips = [
"10.10.10.1",
"10.10.10.2",
"10.10.10.3",
]
work_dir = "/data/ob" # The working directory of OceanBase Database, which does not need to be created in advance. It will be automatically created when initializing the OBServer node.
nodes_config = []
for _, ip in enumerate(ips):
node = NodeConfig(ip, work_dir)
nodes_config.append(node)
## The SDK will automatically determine whether to use rsync. If rsync is not used, the transfer efficiency will be relatively low.
## When using rsync to transfer files, you need to configure passwordless login between the SDK execution machine and the target machine, and install rsync on both sides.
## You can disable rsync transfer using the following method, but it is not recommended.
# from obshell.ssh import USE_RSYNC
# USE_RSYNC = False
# Initialize the nodes.
# Parameters:
# rpm_packages: The path of the required software package.
# force_clean: Whether to forcibly clear the OBServer node working directory. If set to True, the working directory will be cleared and all related processes will be killed.
# configs: Cluster parameters, which must be a list of NodeConfig objects.
initialize_nodes(rpm_packages=pkgs, force_clean=True, configs=nodes_config)
# Initialization completed.
from obshell import initialize_nodes, start_obshell, NodeConfig
def init_nodes():
pkgs = [
"/root/download/oceanbase-ce-libs-4.2.5.0-100000052024102022.el7.x86_64.rpm",
"/root/download/oceanbase-ce-4.2.5.0-100000052024102022.el7.x86_64.rpm",
# The above two packages are sufficient to initialize the OceanBase cluster, but it's recommended to also install the following two packages for easier maintenance later.
# The utils package provides ob_admin, which can help with window parsing during recovery.
"/root/download/oceanbase-ce-utils-4.2.5.0-100000052024102022.el7.x86_64.rpm",
# The OceanBase database configured above already includes obshell, but it's recommended to use the latest version of obshell, so we install the latest version separately.
"/root/download/obshell-4.2.4.3-12024110711.el7.x86_64.rpm",
]
ips = [
"10.10.10.1",
"10.10.10.2",
"10.10.10.3",
]
work_dir = "/data/ob" # The working directory for OceanBase database. It doesn't need to be created in advance; it will be automatically created when initializing the OBServer node.
nodes_config = []
for _, ip in enumerate(ips):
node = NodeConfig(ip, work_dir)
nodes_config.append(node)
## The SDK will automatically determine whether to use rsync. If rsync is not used, the transfer efficiency will be lower.
## When using rsync for file transfer, you need to configure passwordless login between the SDK execution machine and the target machine, and both sides need to install rsync.
## You can disable rsync transfer using the following method, but it's not recommended.
# from obshell.ssh import USE_RSYNC
# USE_RSYNC = False
# Initialize the nodes
# Parameters:
# rpm_packages: The paths of the required software packages.
# force_clean: Whether to forcibly clean the OBServer node's working directory. If True, the working directory will be cleared and all related processes will be killed.
# configs: Cluster parameters, which must be a list of NodeConfig objects.
initialize_nodes(rpm_packages=pkgs, force_clean=False, configs=nodes_config)
# Initialization completed
Related documents
For more information about how to request the API method by using the obshell-sdk-go, see Initialize a node.