This topic describes how to use the obshell-sdk-go tool to initialize the nodes. The goal is to send the RPM packages required for deploying OceanBase Database to each node, including oceanbase-ce, oceanbase-ce-libs, oceanbase-ce-utils, and obshell, and to initialize the directories.
Note
Before you proceed, we recommend that you read the Quick Start topic to learn how to use obshell-sdk-go.
Considerations
Before you initialize a node, download the required RPM packages to the node. You can download the RPM packages manually or use obshell-sdk-go. For more information about how to use obshell-sdk-go to download the RPM packages, see Download RPM packages.
Sample code
package main
import (
"github.com/oceanbase/obshell-sdk-go/util"
)
func initNode() error {
pkgs := []string{
"/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 to initialize 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 4.2.5.0 version 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 := []string{
"10.10.10.1",
"10.10.10.2",
"10.10.10.3",
}
workDir := "/data/ob" // The working directory for OceanBase Database. It does not need to be created in advance. It will be automatically created when initializing the OBServer node.
nodeConfigs := make([]util.NodeConfig, 0)
for _, ip := range ips {
nodeConfigs = append(nodeConfigs, util.NewNodeConfig(ip, workDir, 2886))
}
// // util.UseRsync indicates whether to use rsync for file transfer. The default value is false.
// // When using rsync for file transfer, you need to configure passwordless login between the SDK execution machine and the target machine, and install rsync on both sides.
// // By default, files are transferred using scp and parallel sftp, which is similar in speed to rsync.
// // You can enable rsync transfer by setting util.UseRsync = true.
// util.UseRsync = false
// // util.CHUNK_SIZE is used to control the chunk size for parallel SFTP file transfer. The default is 64M.
// // A smaller util.CHUNK_SIZE allows for higher parallelism and faster transfer speeds, but consumes more SSH channels.
// // In OceanBase Database, the maximum size of a single file is approximately 450M, which can be divided into 7-8 chunks of 64M.
// // This requires 7-8 concurrent connections. Since the default MaxSessions in sshd is 10, 64M is a reasonable default value.
// // To improve the performance of SFTP chunked transfer, you can reduce this value to increase the number of concurrent connections.
// // However, you must also increase the MaxSessions configuration in the sshd config on the target machine.
// // Additionally, you need to increase the value of util.PARALLEL_SFTP_MAX to ensure the upper limit of parallelism.
// // util.PARALLEL_SFTP_MAX is used to protect the maximum number of concurrent SFTP operations from exceeding the MaxSessions on the target machine. The default is 8.
// util.CHUNK_SIZE = 64 * 1024 * 1024
// util.PARALLEL_SFTP_MAX = 8
// // util.SCP_THRESHOLD is used to control the file size for SCP transfer. Files larger than this value will use SCP transfer. The default is 1M.
// // Small files are more efficiently transferred using memory backup batch transfer, so only files larger than util.SCP_THRESHOLD will use SCP transfer.
// // You can set util.SCP_THRESHOLD = 0 to disable SCP.
// util.SCP_THRESHOLD = 1 * 1024 * 1024
// Initialize nodes
// Parameters:
// rpmPackagePaths: The paths of the software packages to be installed.
// forceClean: Whether to forcibly clean the OBServer node working directory. If True, the working directory will be cleared and all related processes will be killed.
// configs: Node configuration information.
err := util.InitNodes(pkgs, true, nodeConfigs...)
if err != nil {
return err
}
// Initialization completed
}
package main
import (
"github.com/oceanbase/obshell-sdk-go/util"
)
func initNode() error {
pkgs := []string{
"/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 two packages above are sufficient to initialize 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 parse the recovery window during subsequent recovery.
"/root/download/oceanbase-ce-utils-4.2.5.0-100000052024102022.el7.x86_64.rpm",
// The OceanBase database 4.2.5.0 version 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 := []string{
"10.10.10.1",
"10.10.10.2",
"10.10.10.3",
}
workDir := "/data/ob" // The working directory for OceanBase Database, which does not need to be created in advance. It will be automatically created when initializing the OBServer node.
nodeConfigs := make([]util.NodeConfig, 0)
for _, ip := range ips {
nodeConfigs = append(nodeConfigs, util.NewNodeConfig(ip, workDir, 2886))
}
// // util.UseRsync indicates whether to use rsync for file transfer. The default value is false.
// // When using rsync for file transfer, you need to configure passwordless login between the SDK execution machine and the target machine, and install rsync on both sides.
// // By default, files are transferred using scp and parallel sftp, which is similar in speed to rsync.
// // You can enable rsync transfer by setting util.UseRsync = true.
// util.UseRsync = false
// // util.CHUNK_SIZE controls the chunk size for parallel SFTP file transfers, defaulting to 64M.
// // A smaller util.CHUNK_SIZE allows for higher parallelism and faster transfer speeds, but consumes more SSH channels.
// // In OceanBase Database, the maximum size of a single file is approximately 450M, which can be divided into 7-8 chunks of 64M.
// // This requires 7-8 concurrent connections. Since the default MaxSessions in sshd is 10, 64M is a reasonable default value.
// // To improve the performance of SFTP chunked transfers, you can reduce this value to increase the number of concurrent connections.
// // However, you must also increase the MaxSessions setting in the sshd config on the target machine.
// // Additionally, you need to increase the util.PARALLEL_SFTP_MAX value to ensure the upper limit of parallelism.
// // util.PARALLEL_SFTP_MAX is used to protect against exceeding the target machine's MaxSessions, defaulting to 8.
// util.CHUNK_SIZE = 64 * 1024 * 1024
// util.PARALLEL_SFTP_MAX = 8
// // util.SCP_THRESHOLD controls the file size for SCP transfers; files larger than this value use SCP, defaulting to 1M.
// // Small files are more efficiently transferred using memory backup in batches, so only files larger than util.SCP_THRESHOLD use SCP.
// // You can set util.SCP_THRESHOLD = 0 to disable SCP.
// util.SCP_THRESHOLD = 1 * 1024 * 1024
// Initialize nodes
// Parameters:
// rpmPackagePaths: The paths of the software packages to install.
// forceClean: Whether to forcibly clean the OBServer node's working directory. If set to True, the working directory will be cleared, and all related processes will be killed.
// configs: Node configuration information.
err := util.InitNodes(pkgs, false, nodeConfigs...)
if err != nil {
return err
}
// Initialization complete
}
## Related Documents
For more information about how to request the API method by using the obshell-sdk-python, see [Initialize a node](../../100.python/200.cluster-management/550.initialize-node-of-python.md).