• openGauss通过VIP实现的故障转移


    📢📢📢📣📣📣
    哈喽!大家好,我是【IT邦德】,江湖人称jeames007,10余年DBA及大数据工作经验
    一位上进心十足的【大数据领域博主】!😜😜😜
    中国DBA联盟(ACDU)成员,目前服务于工业互联网
    擅长主流Oracle、MySQL、PG、高斯及Greenplum运维开发,备份恢复,安装迁移,性能优化、故障应急处理等。
    ✨ 如果有对【数据库】感兴趣的【小可爱】,欢迎关注【IT邦德】💞💞💞
    ❤️❤️❤️感谢各位大可爱小可爱!❤️❤️❤️

    前言

    本文详细阐述了openGauss通过CM管理,实现的VIP故障转移全过程

    📣 ## 1.文章前言

    随着目前信创产业的发展,应项目的需求,通过高可用的方式实现数据库的故障转移。于是花了点时间研究,通过CM管理,实现了VIP故障转移全过程,在经历了这次故障转移之后,我觉得有必要分享我在此过程中获得的见解

    📣 ## 2.CM管理两节

    ✨ 2.1 何为CM

    CM(Cluster Manager)是一款数据库管理模块。支持自定义资源监控,提供了数据库主备的状态监控、网络通信故障监控、文件系统故障监控、故障自动主备切换等能力。提供了丰富的数据库管理能力,如节点、实例级的启停,数据库实例状态查询、主备切换、日志管理等。提供了通过REST接口远程查询和接收集群状态的能力。

    ✨ 2.2 CM的特点

    高可用:CM易用性提升
    
    	支持一键式关闭CM集群服务;
    	支持和内核的安装部署解耦;
    	支持按事件调用用户自定义脚本;
    	支持CM组件单独升级,增强数据库集群可靠性;
    	CM根据配置信息,支持用户自定义组件的监控和管
    	
    需要注意的是,一主一备模式下,CM只支持基本的安装,启停,检测能力,其他功能不支持。
                                                                             
    高可用:CM支持VIP管理
    	通过VIP可以直接找到主机,连接重连更准更快(毫秒级别);
    	支持主机故障,CM选出新主时,VIP漂移到新的主上;
    	当出现双主时,依然可以通过VIP访问到唯一一个主机,降低了双主丢数据的风险。
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    ✨ 2.3 XML配置文件

    
    
        
        
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
             
        
        
        
            
            
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
    	      
          		
    	    		
    	    		
              
            
    
            
            
                
                
                
                
                
                
                
                
            
            
            
            
            
        
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69

    📣 ## 3.集群VIP管理

    ✨ 3.1 增加sudo权限

    给omm用户增加sudo权限,所有节点都执行
    echo "omm ALL=(ALL) NOPASSWD:ALL">>/etc/sudoers
    echo "Cmnd_Alias COMMAND_FLAG = /usr/sbin/ifconfig" >> /etc/sudoers
    
    • 1
    • 2
    • 3

    ✨ 3.2 添加VIP

    ifconfig ens33:15400 192.168.6.14 netmask 255.255.255.0 up
                                                       
    ens33: flags=4163  mtu 1500
            inet 192.168.6.11  netmask 255.255.255.0  broadcast 192.168.6.255
            inet6 fe80::a281:1dad:5f3f:1be8  prefixlen 64  scopeid 0x20
            ether 00:0c:29:56:78:64  txqueuelen 1000  (Ethernet)
            RX packets 70129  bytes 10190915 (9.7 MiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 445322  bytes 1129835756 (1.0 GiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    ens33:15400: flags=4163  mtu 1500
            inet 192.168.6.14  netmask 255.255.255.0  broadcast 192.168.6.255
            ether 00:0c:29:56:78:64  txqueuelen 1000  (Ethernet
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    给集群添加VIP资源 VIP作为openGauss的资源管理
    cm_ctl res --add --res_name="VIP_az1" --res_attr="resources_type=VIP,float_ip=192.168.6.14"
    
    • 1
    • 2
    将每个实例加到资源中
    cm_ctl res --edit --res_name="VIP_az1" --add_inst="node_id=1,res_instance_id=6001" --inst_attr=base_ip=192.168.6.11
    cm_ctl res --edit --res_name="VIP_az1" --add_inst="node_id=2,res_instance_id=6002" --inst_attr=base_ip=192.168.6.12
    
    • 1
    • 2
    • 3
    [omm@opengauss51m ~]$ cm_ctl res --check
    cm_ctl: resource config is valid.
    
    执行check完成后,在cmdataPath/cm_agent/目录下会生成一个自定义资源配置文件cm_resource.json,
    检查完成没有错误后,需要手动scp将该文件分发到其他节点
    
    • 1
    • 2
    • 3
    • 4
    • 5

    ✨ 3.3 配置参数

    配置/openGauss/data/dn/pg_hba.conf
    在数据库pg_hba.conf文件中以sha256方式添加floatIp
    
    host    all    all    192.168.6.14/32     sha256
                                                                                      
    --cm集群故障自动切换配置前提条件,通过三方网管实现
    cd /openGauss/cm/cm_server
    vi cm_server.conf
                                                                                      
    third_party_gateway_ip = 192.168.6.8
    cms_enable_failover_on2nodes = true         
    cms_network_isolation_timeout = 20  
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    ✨ 3.4 重启集群

    [omm@opengauss51m ~]$ gs_om -t stop
    Stopping cluster.
    =========================================
    Successfully stopped cluster.
    =========================================
    End stop cluster.
    [omm@opengauss51m ~]$ gs_om -t start
    Starting cluster.
    ======================================================================
    Successfully started primary instance. Wait for standby instance.
    ======================================================================
    .
    Successfully started cluster.
    ======================================================================
    cluster_state      : Normal
    redistributing     : No
    node_count         : 2
    Datanode State
        primary           : 1
        standby           : 1
        secondary         : 0
        cascade_standby   : 0
        building          : 0
        abnormal          : 0
        down              : 0
    
    Successfully started cluster.
                                                                               查询VIP在哪个节点
    [omm@opengauss51m ~]$ cm_ctl show
    
    [  Network Connect State  ]
    
    Network timeout:       6s
    Current CMServer time: 2023-11-18 21:03:20
    Network stat('Y' means connected, otherwise 'N'):
    |  \  |  Y  |
    |  Y  |  \  |
    
    
    [  Node Disk HB State  ]
    
    Node disk hb timeout:    200s
    Current CMServer time: 2023-11-18 21:03:21
    Node disk hb stat('Y' means connected, otherwise 'N'):
    |  N  |  N  |
    
    [  FloatIp Network State  ]
    
    node            instance base_ip      float_ip_name float_ip     
    -----------------------------------------------------------------
    1  opengauss51m 6001     192.168.6.11 VIP_az1       192.168.6.14 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51

    📣 ## 4.测试故障转移

    ##本次实验,我们直接对主库关机,验证高可用
    [omm@opengauss51b ~]$ gs_om -t status --detail
    [  CMServer State   ]
    
    node            node_ip         instance                     state
    --------------------------------------------------------------------
    1  opengauss51m 192.168.6.11    1    /openGauss/cm/cm_server Down
    2  opengauss51b 192.168.6.12    2    /openGauss/cm/cm_server Primary
    
    [   Cluster State   ]
    
    cluster_state   : Degraded
    redistributing  : No
    balanced        : No
    current_az      : AZ_ALL
    
    [  Datanode State   ]
    
    node            node_ip         instance                state            
    -------------------------------------------------------------------------
    1  opengauss51m 192.168.6.11    6001 /openGauss/data/dn P Down    Unknown
    2  opengauss51b 192.168.6.12    6002 /openGauss/data/dn S Primary Normal
                                                                                      
    ##备库变为主库,VIP也飘逸过来了                                               [omm@opengauss51b ~]$ cm_ctl show
    
    [  Network Connect State  ]
    
    Network timeout:       6s
    Current CMServer time: 2023-11-18 22:41:44
    Network stat('Y' means connected, otherwise 'N'):
    |  \  |  Y  |
    |  Y  |  \  |
    
    
    [  Node Disk HB State  ]
    
    Node disk hb timeout:    200s
    Current CMServer time: 2023-11-18 22:41:45
    Node disk hb stat('Y' means connected, otherwise 'N'):
    |  N  |  N  |
    
    [  FloatIp Network State  ]
    
    node            instance base_ip      float_ip_name float_ip     
    -----------------------------------------------------------------
    2  opengauss51b 6002     192.168.6.12 VIP_az1       192.168.6.14 
    
    ##然后我们启动主库,恢复集群
                                                                               --启动集群
    [omm@opengauss51m ~]$ gs_om -t start
    [omm@opengauss51b ~]$ gs_om -t status --detail
    [  CMServer State   ]
    
    node            node_ip         instance                     state
    --------------------------------------------------------------------
    1  opengauss51m 192.168.6.11    1    /openGauss/cm/cm_server Standby
    2  opengauss51b 192.168.6.12    2    /openGauss/cm/cm_server Primary
    
    [   Cluster State   ]
    
    cluster_state   : Normal
    redistributing  : No
    balanced        : No
    current_az      : AZ_ALL
    
    [  Datanode State   ]
    
    node            node_ip         instance                state            
    -------------------------------------------------------------------------
    1  opengauss51m 192.168.6.11    6001 /openGauss/data/dn P Standby Normal
    2  opengauss51b 192.168.6.12    6002 /openGauss/data/dn S Primary Normal
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
  • 相关阅读:
    20221110 今天的世界发生了什么
    Linux操作系统安装与gcc和内核升级
    Kafka基础组件图推演
    MPLS BGP virtual private network OptionC实验(方案二)
    第8关:使用递归
    请求转发 [JavaWeb][Servlet]
    【游戏引擎架构】6.2 资源管理器
    每日一题:如何实现上拉加载,下拉刷新?
    敏捷开发模型:一种灵活、协作和持续的软件开发方法
    【Unity】Unity C#基础(十四)注释
  • 原文地址:https://blog.csdn.net/weixin_41645135/article/details/134486795