Prerequisites
Ensure that obshell is running in the environment.
Procedure
Install obshell-sdk-go.
go get github.com/oceanbase/obshell-sdk-goCreate a client.
You can choose to create a single-version client or a multi-version client set.
Create a single-version clientCreate a multi-version client setpackage main import ( "github.com/oceanbase/obshell-sdk-go/services/v1" ) func main() { client, err := v1.NewClientWithPassword("10.10.10.1", 2886, "${password}") if err != nil { // Handle exceptions panic(err) } }package main import ( "github.com/oceanbase/obshell-sdk-go/services" ) func main() { clientset, err := services.NewClientWithPassword("10.10.10.1", 2886, "${password}") if err != nil { // Handle exceptions panic(err) } }In the preceding example,
10.10.10.1is the IP address of the target obshell node,2886is the service port of the obshell node, and you must modify them to the corresponding IP address and port number based on your actual situation.${password}is the password of the root@sys user of the cluster where the target obshell node is located.Deploy an OceanBase cluster.
obshell-sdk-go provides two methods to create an OceanBase cluster: one is to return immediately after the corresponding API method is successfully called on obshell, and the other is to return after the obshell task is completed. The former method executes the task asynchronously, while the latter method executes the task synchronously.
This topic uses the deployment of a 1-1-1 cluster as an example. The sample code is as follows:
Asynchronous executionSynchronous executionpackage main import ( "github.com/oceanbase/obshell-sdk-go/services" "github.com/oceanbase/obshell-sdk-go/services/v1" ) func main() { client, err := services.NewClientWithPassword("10.10.10.1", 2886, "****") if err != nil { panic(err) } // Join yourself as the master. joinReqeust1 := client.V1().NewJoinRequest("10.10.10.1", 2886, "zone1") dag, err := client.V1().JoinSyncWithRequest(joinReqeust1) if err != nil { panic(err) } if _, err = client.V1().WaitDagSucceed(dag.GenericID); err != nil { panic(err) } // Join a follower to the cluster. joinReqeust2 := client.V1().NewJoinRequest("10.10.10.2", 2886, "zone2") dag, err = client.V1().JoinSyncWithRequest(joinReqeust2) if err != nil { panic(err) } if _, err = client.V1().WaitDagSucceed(dag.GenericID); err != nil { panic(err) } joinReqeust3 := client.V1().NewJoinRequest("10.10.10.3", 2886, "zone3") dag, err = client.V1().JoinSyncWithRequest(joinReqeust3) if err != nil { panic(err) } if _, err = client.V1().WaitDagSucceed(dag.GenericID); err != nil { panic(err) } // obshell prior to 4.2.3.0 should use mysqlPort(rpcPort) instead of mysql_port(rpc_port). configs := map[string]string{ "mysql_port": "2881", "rpc_port": "2882", "datafile_size": "24G", "cpu_count": "16", "memory_limit": "16G", "system_memory": "8G", "log_disk_size": "24G", } // Set the configurations of each OBServer node. configObserverReq := client.V1().NewConfigObserverRequest(configs, v1.SCOPE_GLOBAL) dag, err = client.V1().ConfigObserverSyncWithRequest(configObserverReq) if err != nil { panic(err) } if _, err = client.V1().WaitDagSucceed(dag.GenericID); err != nil { panic(err) } // Set the configurations of the OceanBase cluster. configObclusterReq := client.V1().NewConfigObclusterRequest("obshell-sdk-test", 12358).SetRootPwd("****") dag, err = client.V1().ConfigObclusterSyncWithRequest(configObclusterReq) if err != nil { panic(err) } if _, err = client.V1().WaitDagSucceed(dag.GenericID); err != nil { panic(err) } // Initialize the cluster. initReq := client.V1().NewInitRequest() dag, err = client.V1().InitSyncWithRequest(initReq) if err != nil { panic(err) } if _, err = client.V1().WaitDagSucceed(dag.GenericID); err != nil { panic(err) } }package main import ( "github.com/oceanbase/obshell-sdk-go/services" "github.com/oceanbase/obshell-sdk-go/services/v1" ) func main() { client, err := services.NewClientWithPassword("10.10.10.1", 2886, "****") if err != nil { panic(err) } // Join yourself as the master. joinReqeust1 := client.V1().NewJoinRequest("10.10.10.1", 2886, "zone1") if _, err = client.V1().JoinSyncWithRequest(joinReqeust1); err != nil { panic(err) } // Join a follower to the cluster. joinReqeust2 := client.V1().NewJoinRequest("10.10.10.2", 2886, "zone2") if _, err = client.V1().JoinSyncWithRequest(joinReqeust2); err != nil { panic(err) } joinReqeust3 := client.V1().NewJoinRequest("10.10.10.3", 2886, "zone3") if _, err = client.V1().JoinSyncWithRequest(joinReqeust3); err != nil { panic(err) } // obshell prior to 4.2.3.0 should use mysqlPort(rpcPort) instead of mysql_port(rpc_port). configs := map[string]string{ "mysql_port": "2881", "rpc_port": "2882", "datafile_size": "24G", "cpu_count": "16", "memory_limit": "16G", "system_memory": "8G", "log_disk_size": "24G", } // Set the configurations of each OBServer node. configObserverReq := client.V1().NewConfigObserverRequest(configs, v1.SCOPE_GLOBAL) if _, err = client.V1().ConfigObserverSyncWithRequest(configObserverReq); err != nil { panic(err) } // Set the configurations of the OceanBase cluster. configObclusterReq := client.V1().NewConfigObclusterRequest("obshell-sdk-test", 12358).SetRootPwd("****") if _, err = client.V1().ConfigObclusterSyncWithRequest(configObclusterReq); err != nil { panic(err) } // Initialize the cluster. initReq := client.V1().NewInitRequest() if _, err = client.V1().InitSyncWithRequest(initReq); err != nil { panic(err) } }