opengauss高可用之主备一键式搭建

  • 阿里云国际版折扣https://www.yundadi.com

  • 阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

    一、准备阶段

    两台虚拟机操作系统配置依据这篇文章
    https://blog.51cto.com/u_13236892/6116256
    
    额外添加的就是两台机器都在/etc/hosts添加对方的ip和主机名映射

    二、搭建主从

    1、概述

    只需要在其中一台机器上传安装包和配置文件即可,要求两台机器得root密码一致

    2、配置文件设置

    vi /opt/software/openGauss/cluster_config.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <ROOT>
        <!-- openGauss整体信息 -->
        <CLUSTER>
            <!-- 数据库名称 -->
            <PARAM name="clusterName" value="Cluster_template" />
            <!-- 数据库节点名称(hostname) -->
            <PARAM name="nodeNames" value="node1_hostname,node2_hostname" />
            <!-- 数据库安装目录-->
            <PARAM name="gaussdbAppPath" value="/opt/huawei/install/app" />
            <!-- 日志目录-->
            <PARAM name="gaussdbLogPath" value="/var/log/omm" />
            <!-- 临时文件目录-->
            <PARAM name="tmpMppdbPath" value="/opt/huawei/tmp"/>
            <!-- 数据库工具目录-->
            <PARAM name="gaussdbToolPath" value="/opt/huawei/install/om" />
            <!-- 数据库core文件目录-->
            <PARAM name="corePath" value="/opt/huawei/corefile"/>
            <!-- 节点IP,与数据库节点名称列表一一对应 -->
            <PARAM name="backIp1s" value="192.168.0.1,192.168.0.2"/> 
        </CLUSTER>
        <!-- 每台服务器上的节点部署信息 -->
        <DEVICELIST>
            <!-- 节点1上的部署信息 -->
            <DEVICE sn="node1_hostname">
                <!-- 节点1的主机名称 -->
                <PARAM name="name" value="node1_hostname"/>
                <!-- 节点1所在的AZ及AZ优先级 -->
                <PARAM name="azName" value="AZ1"/>
                <PARAM name="azPriority" value="1"/>
                <!-- 节点1的IP,如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->
                <PARAM name="backIp1" value="192.168.0.1"/>
                <PARAM name="sshIp1" value="192.168.0.1"/>
                
    	    <!--dn-->
                <PARAM name="dataNum" value="1"/>
    	    <PARAM name="dataPortBase" value="15400"/>
    	    <PARAM name="dataNode1" value="/opt/huawei/install/data/dn,node2_hostname,/opt/huawei/install/data/dn"/>
                <PARAM name="dataNode1_syncNum" value="0"/>
            </DEVICE>
    
            <!-- 节点2上的节点部署信息,其中“name”的值配置为主机名称 -->
            <DEVICE sn="node2_hostname">
                <!-- 节点2的主机名称 -->
                <PARAM name="name" value="node2_hostname"/>
                <!-- 节点2所在的AZ及AZ优先级 -->
                <PARAM name="azName" value="AZ1"/>
                <PARAM name="azPriority" value="1"/>
                <!-- 节点2的IP,如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->
                <PARAM name="backIp1" value="192.168.0.2"/>
                <PARAM name="sshIp1" value="192.168.0.2"/>
    	</DEVICE>
        </DEVICELIST>
    </ROOT>

    3、加载环境变量

    export LD_LIBRARY_PATH=/opt/software/openGauss/script/gspylib/clib:$LD_LIBRARY_PATH

    4、环境初始化

    cd /opt/software/openGauss/script
    [root@prod script]# ./gs_preinstall -U omm -G dbgrp -X /opt/software/openGauss/cluster_config.xml
    Parsing the configuration file.
    Successfully parsed the configuration file.
    Installing the tools on the local node.
    Successfully installed the tools on the local node.
    Are you sure you want to create trust for root (yes/no)? yes  #输入root密码
    Please enter password for root.
    Password:
    Creating SSH trust for the root permission user.
    Checking network information.
    All nodes in the network are Normal.
    Successfully checked network information.
    Creating SSH trust.
    Creating the local key file.
    Successfully created the local key files.
    Appending local ID to authorized_keys.
    Successfully appended local ID to authorized_keys.
    Updating the known_hosts file.
    Successfully updated the known_hosts file.
    Appending authorized_key on the remote node.
    Successfully appended authorized_key on all remote node.
    Checking common authentication file content.
    Successfully checked common authentication content.
    Distributing SSH trust file to all node.
    Successfully distributed SSH trust file to all node.
    Verifying SSH trust on all hosts.
    Successfully verified SSH trust on all hosts.
    Successfully created SSH trust.
    Successfully created SSH trust for the root permission user.
    Setting pssh path
    Successfully set core path.
    Distributing package.
    Begin to distribute package to tool path.
    Successfully distribute package to tool path.
    Begin to distribute package to package path.
    Successfully distribute package to package path.
    Successfully distributed package.
    Are you sure you want to create the user[omm] and create trust for it (yes/no)? yes  #创建omm设置密码
    Please enter password for cluster user.
    Password:
    Please enter password for cluster user again.
    Password:
    Successfully created [omm] user on all nodes.
    Preparing SSH service.
    Successfully prepared SSH service.
    Installing the tools in the cluster.
    Successfully installed the tools in the cluster.
    Checking hostname mapping.
    Successfully checked hostname mapping.
    Creating SSH trust for [omm] user.
    Please enter password for current user[omm].
    Password:                                                        #输入omm密码
    Checking network information.
    All nodes in the network are Normal.
    Successfully checked network information.
    Creating SSH trust.
    Creating the local key file.
    Successfully created the local key files.
    Appending local ID to authorized_keys.
    Successfully appended local ID to authorized_keys.
    Updating the known_hosts file.
    Successfully updated the known_hosts file.
    Appending authorized_key on the remote node.
    Successfully appended authorized_key on all remote node.
    Checking common authentication file content.
    Successfully checked common authentication content.
    Distributing SSH trust file to all node.
    Successfully distributed SSH trust file to all node.
    Verifying SSH trust on all hosts.
    Successfully verified SSH trust on all hosts.
    Successfully created SSH trust.
    Successfully created SSH trust for [omm] user.
    Checking OS software.
    Successfully check os software.
    Checking OS version.
    Successfully checked OS version.
    Creating cluster's path.
    Successfully created cluster's path.
    Setting SCTP service.
    Successfully set SCTP service.
    Set and check OS parameter.
    Setting OS parameters.
    Successfully set OS parameters.
    Warning: Installation environment contains some warning messages.
    Please get more details by "/opt/software/openGauss/script/gs_checkos -i A -h node1_hostname,node2_hostname --detail".
    Set and check OS parameter completed.
    Preparing CRON service.
    Successfully prepared CRON service.
    Setting user environmental variables.
    Successfully set user environmental variables.
    Setting the dynamic link library.
    Successfully set the dynamic link library.
    Setting Core file
    Successfully set core path.
    Setting pssh path
    Successfully set pssh path.
    Set ARM Optimization.
    No need to set ARM Optimization.
    Fixing server package owner.
    Setting finish flag.
    Successfully set finish flag.
    Preinstallation succeeded.
    
    #环境初始化完成以后会发现配置文件里面的目录已经建好,用户权限基本上都已经设置好
    #在有安装包的这台机器,omm用户可以免密登录自己或者集群其他用户的机器,免密配置写到当前和其他机器/home/omm/.ssh/authorized_keys里面
    #omm用户必须有这个免密才能执行gs_om -t status --detail,但是日志文件拷贝却不走这个免密

    5、参数检查

    /opt/software/openGauss/script/gs_checkos -i A -h node1_hostname,node2_hostname --detail
    会同时检查多台机器的的环境配置
    cat >>/etc/sysctl.conf <<EOF
    net.ipv4.tcp_retries1 = 5
    net.ipv4.tcp_syn_retries = 5
    EOF
    sysctl -p

    6、数据库安装

    su - omm
    gs_install -X /opt/software/openGauss/cluster_config.xml \
    --gsinit-parameter="--encoding=UTF8" \  
    --dn-guc="max_connections=10000" \ 
    --dn-guc="max_process_memory=12GB" \
    --dn-guc="shared_buffers=6GB" \
    --dn-guc="bulk_write_ring_size=128MB" \
    --dn-guc="cstore_buffers=16MB" \
    --dn-guc="session_timeout = 0" \
    --dn-guc="password_effect_time = 0"
    
    输出内容:
    Parsing the configuration file.
    Check preinstall on every node.
    Successfully checked preinstall on every node.
    Creating the backup directory.
    Successfully created the backup directory.
    begin deploy..
    Installing the cluster.
    begin prepare Install Cluster..
    Checking the installation environment on all nodes.
    begin install Cluster..
    Installing applications on all nodes.
    Successfully installed APP.
    begin init Instance..
    encrypt cipher and rand files for database.
    Please enter password for database:         ## 数据库初始用户omm的密码复杂度要求:大写+小写+数字+特殊字符(任选3类,至少8位)
    Please repeat for database:
    begin to create CA cert files
    The sslcert will be generated in /gauss/app/share/sslcert/om
    Cluster installation is completed.
    Configuring.
    Deleting instances from all nodes.
    Successfully deleted instances from all nodes.
    Checking node configuration on all nodes.
    Initializing instances on all nodes.
    Updating instance configuration on all nodes.
    Check consistence of memCheck and coresCheck on database nodes.
    Successful check consistence of memCheck and coresCheck on all nodes.
    Configuring pg_hba on all nodes.
    Configuration is completed.
    Successfully started cluster.
    Successfully installed application.
    end deploy..

    三、集群基础操作

    1、gs_om操作

    执行任何命令会都显示集群所有节点的信息
    
    1、查看集群状态
    gs_om -t status --detail
    [   Cluster State   ]
    cluster_state   : Normal
    redistributing  : No
    current_az      : AZ_ALL
    [  Datanode State   ]
    node                      node_ip         instance                state  
    ----------------------------------------------------------------------------------
    1  prod.opengauss.com   192.168.0.11    6001 /gauss/data/db1 P Primary Normal
    2  stb1.opengauss.com   192.168.0.12    6002 /gauss/data/db1 S Standby Normal
    
    2、执行重启会两台机器都重启,并且主从保持原样
    gs_om -t restart
    
    3、停掉所有节点服务
    gs_om -t stop

    2、gs_ctl操作

    1、停止单个实例
    su - omm
    gs_ctl stop -D /gauss/data/db1
    
    2、启动单个实例
    gs_ctl start -D /gauss/data/db1 #默认以主节点启动,如果有其他主节点就会出现双主现象,即两台机器都是primary
    gs_ctl start -D /gauss/data/db1 -M standby #启动节点,以从节点启动

    3、主从切换

    1、主备机正常,在线手动切换
    必须在要切换为主机的备机上,执行switchover命令才会生效。在主机上执行switchover命令,仅作查询使用。
    su - omm -c "gs_ctl switchover -D /gauss/data/db1"
    su - omm -c "gs_om -t refreshconf"
    
    2、主节点宕机,从节点切主
    从节点执行操作
    su - omm -c "gs_ctl failover -D /gauss/data/db1"
    su - omm -c "gs_om -t refreshconf"

    4、sql查询主从状态

    1、复制连接配置检查
     show replconninfo1;
                                                                                   replconninfo1
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     localhost=192.168.0.11 localport=26001 localheartbeatport=26005 localservice=26004 remotehost=192.168.0.12 remoteport=26001 remoteheartbeatport=26005 remoteservice=26004
    
    postgres=# show max_wal_senders;
     max_wal_senders
    -----------------
     16
     
     2、检查日志传送线程状态
     - 在Primary机器检查日志发送线程状态
    postgres=# \pset expanded
    Expanded display is on.
    postgres=# select * from pg_stat_get_wal_senders();
    -[ RECORD 1 ]--------------+----------------------------------------
    pid                        | 140097998878464
    sender_pid                 | 21609
    local_role                 | Primary
    peer_role                  | Standby
    peer_state                 | Normal
    state                      | Streaming
    catchup_start              | 2021-01-06 16:40:33.679871+08
    catchup_end                | 2021-01-06 16:40:33.707802+08
    sender_sent_location       | 0/7002380
    sender_write_location      | 0/7002380
    sender_flush_location      | 0/7002380
    sender_replay_location     | 0/7002380
    receiver_received_location | 0/7002380
    receiver_write_location    | 0/7002380
    receiver_flush_location    | 0/7002380
    receiver_replay_location   | 0/7002380
    sync_percent               | 100%
    sync_state                 | Async
    sync_priority              | 0
    sync_most_available        | Off
    channel                    | 192.168.0.11:26001-->192.168.0.12:54854
    
    
  • 阿里云国际版折扣https://www.yundadi.com

  • 阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

    “opengauss高可用之主备一键式搭建” 的相关文章

    用qtcreator但不用qt库

    pro file: QT -= core gui...

    linux软连接和硬链接

    软连接和硬连接的区别下边这篇文章说的比较清楚。...

    Codeforces Bayan 2012-2013 Elimination Round / 241A Old Peykan (贪心)

    A. Old Peykan http://codeforces.com/contest/241/problem/A time limit per test memory limit per test input...

    Lunix如何安装和配置PHP环境 - 编程语言

    本篇内容主要讲解“Lunix如何安装和配置PHP环境”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Lunix如何安装和配置PHP环境”吧! 步骤一:安装 Apache首先,你需要安装 Apach...

    php如何实现边输入边显示查询结果功能 - 编程语言

    这篇文章主要介绍了php如何实现边输入边显示查询结果功能的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇php如何实现边输入边显示查询结果功能文章都会有所收获,下面我们一起来看看吧。 PHP是一种常用的服务器端脚...

    c语言之移位运算

    移位运算 左移 逻辑左移和算数左移的效果是一样的高位移出低位补0. 对于一个位长位W的数来说左移K位。通常来讲K<W) 高k位移出低k位补0. 把下面这个w位的位向量左移K位。 [...