HomeMogDBMogDB StackUqbar
v5.0

Documentation:v5.0

Supported Versions:

Other Versions:

Manual Configuration of VIP

Objectives

This section introduces how to manually configure or enable VIP function in a database cluster where CM cluster management software has been deployed.

img Note:

MogDB 5.0.4 and later versions support automatic VIP mounting via PTK (v1.2.0+), see PTK documentation for details.

Additionally, this section uses a cluster with one primary node and two standby nodes as an example.

img

VIP Configuration Procedure

1. Installing ifconfig

The CM cluster management software relies on the ifconfig command, so each server node in the database cluster needs to have ifconfig properly installed.

You can refer to the following command to install ifconfig.

# CentOS/RHEL
sudo yum install net-tools

# Debian/Ubuntu
sudo apt-get update
sudo apt-get install net-tools

After the installation is complete, typing the ifconfig command in the server shell will output network information for the local machine.

img

2. Adding ifconfig Permission

On each node of the cluster, modify the sudoers configuration file in the /etc directory by adding the following content to grant the cluster user the ifconfig permission.

echo "Cmnd_Alias COMMAND_FLAG = /usr/sbin/ifconfig * netmask * up, /usr/sbin/ifconfig * down" >> /etc/sudoers
echo "Cluster username ALL=(root) NOPASSWD: COMMAND_FLAG" >> /etc/sudoers

Dynamic binding and unbinding of VIP is to operate with a NIC, therefore ifconfig permission is required to allow the cluster user to binding or unbinding an VIP by using sudo ifconfig. This operation may give rise to risks, such as wiretapping, tampering, counterfeiting, and denial of service. Please execute with caution.

imgWarning:

Both of the above commands can only be executed once on each node and cannot be configured twice, or else the sudo ifconfig command may report an error. An example of an error is shown below:

img

3. Setting the VIP Resource File

Run the cm_ctl res command on any node in the cluster to add floatIp resources (VIP resources) and distribute the VIP resources to other nodes in the cluster. For details, refer to the following two steps:

(1) Add VIP resources.

res_name indicates the name of the VIP resource. resources_type must be specified as VIP. float_ip indicates the virtual IP address of the VIP resource. The command is as follows:

cm_ctl res --add --res_name="VIP_az" --res_attr="resources_type=VIP, float_ip=<VIP>"

(2) Add mappings between VIP resources and nodes.

node_id specifies the node ID. res_instance_id indicates the ID of the DN instance bound to the CM. The value must be consistent with the ID of the corresponding DN instance. The command is as follows:

cm_ctl res --edit --res_name="VIP_az" --add_inst="node_id=1, res_instance_id=6001" --inst_attr="base_ip=<node1的IP>"
cm_ctl res --edit --res_name="VIP_az" --add_inst="node_id=2, res_instance_id=6002" --inst_attr="base_ip=<node2的IP>"
cm_ctl res --edit --res_name="VIP_az" --add_inst="node_id=3, res_instance_id=6003" --inst_attr="base_ip=<node3的IP>"

After the preceding commands are executed successfully, the cm_resource.json file is generated in the cm_agent directo directory. For details, see Appendix.

You are advised to run the cm_ctl res --check command. The customized resource file must be consistent on each node. If no error is found, manually distribute the file to other nodes. After the distribution is complete, restart the cluster to make the file take effect.

4. Configure the pg_hba.conf File

Run the following command on any node to add VIP resources in sha256 mode in the pg_hba.conf file:

gs_guc set -N all -h "host all all <VIP>/32 sha256"

5. Manually Attach a VIP to the Primary Instance of a Database Cluster

(1) Log in to the primary instance of a database cluster, create a user for accessing the database cluster using VIP.

create user <VIP user> with password '<Password>';

(2) Grant the user permission.

GRANT ALL PRIVILEGES TO <VIP user>;

(3) Create a virtual NIC and binding the VIP.

ifconfig <NIC in the same network segment as the VIP>:<Database service port> <VIP> netmask <netmask> up

img

6. Restart the Cluster

After VIP resources are configured, restart the cluster for the configuration to take effect.

cm_ctl stop && cm_ctl start

Querying the VIP

After the VIP resource takes effects, run the following command to query its status:

img

Verify VIP Availability

After the VIP is configured, run the following command to verify it:

gsql -U <VIP user> -W <Password of the VIP user> -d postgres -r -p <Port of a database instance> -h <VIP>

img

(Optional) Other Process

If the CM cluster includes two nodes. To reduce the possibility of incorrect database cluster fault switchover, run the following command to set the db_service_vip parameter in the cm_agent.conf configuration file.

cm_ctl set --param --agent -k db_service_vip=<VIP>
cm_ctl reload --param --agent

Appendix

VIP resource file cm_resource.json example:

{
    "resources":
        [{"name": "VIP_az1",
          "resources_type": "VIP",
          "instances":
              [{"node_id":      1,
                "res_instance_id":      6001,
                "inst_attr":    "base_ip=<node1的IP>"
              },
              {"node_id":      2,
                "res_instance_id":      6002,
                "inst_attr":    "base_ip=<node2的IP>"
              },
              {"node_id":      3,
                "res_instance_id":      6003,
                "inst_attr":    "base_ip=<node3的IP>"
              }],
          "float_ip":     "<VIP>"
        }
}
Copyright © 2011-2024 www.enmotech.com All rights reserved.