暂无图片
暂无图片
1
暂无图片
暂无图片
暂无图片

MogDB 1主2备安装

原创 刘继超 2022-08-15
630

一、环境准备

节点类别 主机名 IP
主节点 mogdb1 192.168.3.68
备节点1 mogdb2 192.168.3.69
备节点2 mogdb3 192.168.3.70

二、关闭防火墙和透明大页

1、修改操作系统配置
1) 关闭 SELINUX
修改 /etc/selinux/config文件中的“SELINUX”值为“disabled”

2) 关闭防火墙并禁止开机重启
systemctl disable firewalld.service
systemctl stop firewalld.service

3)  修改主机名
在每个服务器节点修改hostname,以主机为例:
hostnamectl set-hostname mogdb1
另外两台备机分别设置为mogdb3和mogdb2

4) 关闭透明大页
echo never > /sys/kernel/mm/transparent_hugepage/enabled

三、安装操作系统依赖包

3.1、配置yum,安装系统包

mount /dev/cdrom /media/cdrom

vi /etc/yum.repos.d/oracle.repo
[Server]
name=Red Hat Enterprise Linux $releasever Beta - $basearch - Source
baseurl=file:///media/cdrom
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

yum install -y bzip2 libaio-devel flex bison ncurses-devel glibc-devel libxml2-devel patch redhat-lsb-core unzip gcc gcc-c++ perl openssl-devel libffi-devel libtool zlib-devel
yum install -y libaio-devel gcc gcc-c++ zlib-devel expect 

3.2安装Python3


# 解压并安装python3
[root@mogdb1 ~]# cd /enmo/soft
[root@mogdb1 soft]# tar -zxvf python3-rpm.tar.gz
# 配置yum源
[root@mogdb1 ~]# cat > /etc/yum.repos.d/enmo.repo << EOF
[Server]
name=Server
baseurl=file:///media/cdrom
enabled=yes
gpgcheck=0

[python3]
name=python3
baseurl=file:///enmo/soft/python3-rpm
enabled=yes
gpgcheck=0
EOF
# 执行yum安装
[root@mogdb1 ~]# yum clean all
[root@mogdb1 ~]# yum install python3 python3-devel -y
# 修改软链接
[root@mogdb1 ~]# rm -f /usr/bin/python
[root@mogdb1 ~]# ln -s /usr/bin/python3 /usr/bin/python
# 查看版本,确认安装成功
[root@mogdb1 ~]# python -V
Python 3.6.8
# 全词匹配替换,python3安装后’yum’命令执行会报错,需要修改以下配置
[root@mogdb1 ~]# sed -i "s:\<python\>:python2:g" /usr/bin/yum
[root@mogdb1 ~]# sed -i "s:\<python\>:python2:g" /usr/libexec/urlgrabber-ext-down
复制
2. 所有节点使用pip3

[root@mogdb1 ~]# cd /enmo/soft
[root@mogdb1 soft]# tar -zxvf  pat_2.1.1.tar.gz 
[root@mogdb1 soft]# cd  
# 按顺序执行安装
[root@mogdb1  ]# pip3 install psutil-5.8.0.tar.gz
[root@mogdb1  ]# pip3 install ydiff-1.2.tar.gz
[root@mogdb1  ]# pip3 install *.whl
[root@mogdb1  ]# pip3 install python-etcd-0.4.5.tar.gz
[root@mogdb1  ]# pip3 install psycopg2-binary-2.9.1.tar.gz
[root@mogdb1  ]# pip3 install psycopg2-2.9.1.tar.gz
# 查看已安装的包
[root@mogdb1  ]# pip3 list

四、创建安装目录

#以root用户登录待安装MogDB的主机,并按规划创建存放安装包的目录(/opt/software/mogdb)
mkdir -p /opt/software/mogdb
chmod 755 -R /opt/software
#进入/opt/software/mogdb,将安装包及配置文件cluster_config.xml上传至此目录。若未创建配置文件,可通过vi cluster_config.xml新建并编辑配置文件。
cd /opt/software/mogdb
#在安装包所在的目录下,依次解压安装包。

五、安装包准备

1、下载并解压安装包
安装包放到 /opt/software 目录下,只在一个节点放安装包就行,安装过程中会把文件推到另外的节点去。
解压安装包到当前目录下并修改权限

[root@mogdb1 mogdb]# tar -xvf MogDB-2.1.0-CentOS-64bit-om.tar.gz
[root@mogdb1 mogdb]# tar -xvf MogDB-2.1.0-CentOS-64bit.tar.bz2
2、为确保openssl版本正确,执行预安装前请加载安装包中lib库
[root@mogdb1 software]# export LD_LIBRARY_PATH=/opt/software/script/gspylib/clib:$LD_LIBRARY_PATH

六、开始安装

6.1 准备配置文件

<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
    <!-- MogDB整体信息 -->
    <CLUSTER>
        <PARAM name="clusterName" value="Cluster_template" />
        <PARAM name="nodeNames" value="mogdb1,mogdb2,mogdb3" />

        <PARAM name="gaussdbAppPath" value="/opt/mogdb/install/app" />
        <PARAM name="gaussdbLogPath" value="/var/log/omm" />
        <PARAM name="tmpMppdbPath" value="/opt/mogdb/tmp"/>
        <PARAM name="gaussdbToolPath" value="/opt/mogdb/install/om" />
        <PARAM name="corePath" value="/opt/mogdb/corefile"/>
        <PARAM name="backIp1s" value="192.168.3.68,192.168.3.69,192.168.3.70"/>

    </CLUSTER>
    <!-- 每台服务器上的节点部署信息 -->
    <DEVICELIST>
        <!-- node1上的节点部署信息 -->
        <DEVICE sn="1000001">
            <PARAM name="name" value="mogdb1"/>
            <PARAM name="azName" value="AZ1"/>
            <PARAM name="azPriority" value="1"/>
            <!-- 如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->
            <PARAM name="backIp1" value="192.168.3.68"/>
            <PARAM name="sshIp1" value="192.168.3.68"/>
            <!--CM节点部署信息-->
            <PARAM name="cmsNum" value="1"/>
            <PARAM name="cmServerPortBase" value="15000"/>
            <PARAM name="cmServerListenIp1" value="192.168.3.68,192.168.3.69,192.168.3.70"/>
            <PARAM name="cmServerHaIp1" value="192.168.3.68,192.168.3.69,192.168.3.70"/>
            <PARAM name="cmServerlevel" value="1"/>
            <PARAM name="cmServerRelation" value="mogdb1,mogdb2,mogdb3"/>
            <PARAM name="cmDir" value="/opt/mogdb/data/cmserver"/>
      <!--dn-->
            <PARAM name="dataNum" value="1"/>
      <PARAM name="dataPortBase" value="15400"/>
      <PARAM name="dataNode1" value="/opt/mogdb/install/data/dn,mogdb2,/opt/mogdb/install/data/dn,mogdb3,/opt/mogdb/install/data/dn"/>
            <PARAM name="dataNode1_syncNum" value="0"/>
        </DEVICE>

        <!-- node2上的节点部署信息,其中“name”的值配置为主机名称 -->
        <DEVICE sn="1000002">
            <PARAM name="name" value="mogdb2"/>
            <PARAM name="azName" value="AZ1"/>
            <PARAM name="azPriority" value="1"/>
            <!-- 如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->
            <PARAM name="backIp1" value="192.168.3.69"/>
            <PARAM name="sshIp1" value="192.168.3.69"/>
            <!-- cm -->
            <PARAM name="cmServerPortStandby" value="15000"/>
            <PARAM name="cmDir" value="/opt/mogdb/data/cmserver"/>
  </DEVICE>

        <!-- node3上的节点部署信息,其中“name”的值配置为主机名称 -->
        <DEVICE sn="1000003">
            <PARAM name="name" value="mogdb3"/>
            <PARAM name="azName" value="AZ1"/>
            <PARAM name="azPriority" value="1"/>
            <!-- 如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP -->
            <PARAM name="backIp1" value="192.168.3.70"/>
            <PARAM name="sshIp1" value="192.168.3.70"/>
            <!-- cm -->
            <PARAM name="cmServerPortStandby" value="15000"/>
            <PARAM name="cmDir" value="/opt/mogdb/data/cmserver"/>
  </DEVICE>
    </DEVICELIST>
</ROOT>

#####注意配置文件中的主机名和ip

6.2 脚本初始化

[root@mogdb1 mogdb]# /opt/software/mogdb/script/gs_preinstall -U omm -G dbgrp -X /opt/software/mogdb/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
Please enter password for root
Password: 
Successfully created SSH trust for the root permission user.
Setting host ip env
Successfully set host ip env.
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
Please enter password for cluster user.
Password: 
Please enter password for cluster user again.
Password: 
Generate cluster user password files successfully.

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: 
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.
Distributing trust keys file to all node successfully.
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.
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/mogdb/script/gs_checkos -i A -h mogdb1,mogdb2,mogdb3 --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.
Setting Cgroup.
Successfully set Cgroup.
Set ARM Optimization.
No need to set ARM Optimization.
Fixing server package owner.
Setting finish flag.
Successfully set finish flag.
Preinstallation succeeded.


###########初始化过程中会建立 root 用户的互信,创建 omm 用户并建立互信。

6.3 执行安装

[root@mogdb1 software]# 
[root@mogdb1 software]# chown -R omm: /opt/software/script/
[root@mogdb1 software]# chmod -R 755 /opt/software/script/
[root@mogdb1 software]# 
[root@mogdb1 software]# su – omm
[omm@mogdb1 ~]$ /opt/software/script/gs_install -X /opt/mogdb/etc/mogdb_cluster_config.xml --gsinit-parameter="--locale=en_US.UTF-8" --gsinit-parameter="--encoding=UTF-8"
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:
Please repeat for database:
begin to create CA cert files
The sslcert will be generated in /opt/mogdb/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..

七、安装验证

安装完成后,可使用omm用户通过“gsql -d postgres -p 26000 -r”命令连接MogDB数据库,其中“-p 26000”为数据库端口号,请根据实际情况替换。键入“\copyright”可查看版权信息

[omm@mogdb1 ~]$ gsql -d postgres -p 26000 -r
gsql ((MogDB 2.0.1 build f892ccb7) compiled at 2021-07-09 16:12:59 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

postgres=# \copyright
MogDB Database Management System
Copyright (c) Yunhe Enmo (Beijing) Information Technology Co., Ltd. Copyright 2020 , All rights reserved.

postgres=#

[omm@mogdb1 mogdb]$ gs_install -X /opt/software/mogdb/cluster_config.xml --gsinit-parameter="--locale=en_US.UTF-8" --gsinit-parameter="--encoding=UTF-8"

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:
Please repeat for database:
begin to create CA cert files
The sslcert will be generated in /opt/mogdb/install/app/share/sslcert/om
Create CA files for cm beginning.
Create CA files on directory [/opt/mogdb/install/app_1a363ea9/share/sslcert/cm]. file list: ['cacert.pem', 'server.key', 'server.crt', 'client.key', 'client.crt', 'server.key.cipher', 'server.key.rand', 'client.key.cipher', 'client.key.rand']
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.
Starting cluster.
======================================================================
Successfully started primary instance. Wait for standby instance.
======================================================================
.
Successfully started cluster.
======================================================================
cluster_state      : Normal
redistributing     : No
node_count         : 3
Datanode State
    primary           : 1
    standby           : 2
    secondary         : 0
    cascade_standby   : 0
    building          : 0
    abnormal          : 0
    down              : 0

Successfully installed application.
end deploy..
[omm@mogdb1 mogdb]$ 

八、状态检查

8.1检查集群状态

[omm@mogdb1 mogdb]$ gs_om -t status --detail
[  CMServer State   ]

node      node_ip         instance                                state
-------------------------------------------------------------------------
1  mogdb1 192.168.3.68    1    /opt/mogdb/data/cmserver/cm_server Standby
2  mogdb2 192.168.3.69    2    /opt/mogdb/data/cmserver/cm_server Standby
3  mogdb3 192.168.3.70    3    /opt/mogdb/data/cmserver/cm_server Primary

[   Cluster State   ]

cluster_state   : Normal
redistributing  : No
balanced        : No
current_az      : AZ_ALL

[  Datanode State   ]

node      node_ip         instance                        state            
---------------------------------------------------------------------------
1  mogdb1 192.168.3.68    6001 /opt/mogdb/install/data/dn P Standby Normal
2  mogdb2 192.168.3.69    6002 /opt/mogdb/install/data/dn S Standby Normal
3  mogdb3 192.168.3.70    6003 /opt/mogdb/install/data/dn S Primary Normal

8.2 检查同步延迟


MogDB=# select * from pg_stat_replication;
       pid       | usesysid | usename |       application_name        | client_addr  | client_hostname | client_port |         backend_start         |   state   | sender_sent_location | receiver_write_location | receiver_flush_locati
on | receiver_replay_location | sync_priority | sync_state 
-----------------+----------+---------+-------------------------------+--------------+-----------------+-------------+-------------------------------+-----------+----------------------+-------------------------+----------------------
---+--------------------------+---------------+------------
 140417194297088 |       10 | omm     | WalSender to Standby[dn_6002] | 192.168.3.69 |                 |       57732 | 2022-08-14 11:40:28.278504+08 | Streaming | 0/7804758            | 0/7804758               | 0/7804758            
   | 0/7804758                |             0 | Async
 140417177515776 |       10 | omm     | WalSender to Standby[dn_6003] | 192.168.3.70 |                 |       49866 | 2022-08-14 11:36:48.184737+08 | Streaming | 0/7804758            | 0/7804758               | 0/7804758            
   | 0/7804758                |             0 | Async
(2 rows)

MogDB=# 

最后修改时间:2022-08-15 17:13:01
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
1人已赞赏
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论