# 一、环境准备
|节点类别|主机名|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,安装系统包

```mkdir /media/cdrom
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=#

```

mogdb的一主两备的更多相关文章

  1. Centos 7.6 安装部署 openGauss 3.1.0 企业版一主两备集群

    一.安装环境设置 1.1 硬件环境 名称 最低配置 建议配置 测试配置 服务器数量 3 略 略 硬盘 * 至少1GB用于安装openGauss的应用程序.* 每个主机需大约300MB用于元数据存储.* ...

  2. PostgreSQL 一主两备节点(两备节点为同步节点)故障恢复

    PostgreSQL  同步复制及故障恢复 10.2.208.10:node1:master 10.2.208.11:node2:standby1 同步 10.2.208.12:node3:stand ...

  3. Mysql + keepalived 实现双主热备读写分离【转】

    Mysql + keepalived 实现双主热备读写分离 2013年6月16日frankwong发表评论阅读评论   架构图 系统:CentOS6.4_X86_64软件版本:Mysql-5.6.12 ...

  4. 阿里云ECS服务器上搭建keepalived+mha+mysql5.6+gtid+一主两从+脚本判断架构踩的坑

    最近,公司项目搭建了一套后端数据库架构,不是在RDS,是在阿里云的ECS服务器上搭建keepalived.mha.mysql5.6.gtid.一主两从架构,目前还没有实现读写分离,以后架构升级,可能代 ...

  5. Mysql双主热备+LVS+Keepalived高可用部署实施手册

    MySQL复制能够保证数据的冗余的同时可以做读写分离来分担系统压力,如果是主主复制还可以很好的避免主节点的单点故障.然而MySQL主主复制存在一些问题无法满足我们的实际需要:未提供统一访问入口来实现负 ...

  6. Mysql双主互备+keeplived高可用架构介绍

    一.Mysql双主互备+keeplived高可用架构介绍 Mysql主从复制架构可以在很大程度保证Mysql的高可用,在一主多从的架构中还可以利用读写分离将读操作分配到从库中,减轻主库压力.但是在这种 ...

  7. Mysql双主互备+keeplived高可用架构(部分)

    一.Mysql双主互备+keeplived高可用架构介绍 Mysql主从复制架构可以在很大程度保证Mysql的高可用,在一主多从的架构中还可以利用读写分离将读操作分配到从库中,减轻主库压力.但是在这种 ...

  8. Mysql+Keepalived双主热备高可用操作记录

    我们通常说的双机热备是指两台机器都在运行,但并不是两台机器都同时在提供服务.当提供服务的一台出现故障的时候,另外一台会马上自动接管并且提供服务,而且切换的时间非常短.MySQL双主复制,即互为Mast ...

  9. Mysql双主热备+LVS+Keepalived高可用操作记录

    MySQL复制能够保证数据的冗余的同时可以做读写分离来分担系统压力,如果是主主复制还可以很好的避免主节点的单点故障.然而MySQL主主复制存在一些问题无法满足我们的实际需要:未提供统一访问入口来实现负 ...

  10. Docker mysql主主互备和高可用

    一.测试环境 1.1 结构图 1.2 版本 操作系统:CentOS 7.3 MySQL版本:5.6.35 Docker版本:18.06.1-ce 使用root用户操作 IP地址说明 IP地址 用途 备 ...

随机推荐

  1. 痞子衡嵌入式:我被邀请做贸泽电子&与非网联合推出的《对话工程师》节目嘉宾

    <对话工程师>是「贸泽电子」赞助.「与非网」制作的一档网络节目,自2022年11月起,邀请不同技术领域的资深工程师,聊聊开发过程中的经验感悟,栏目共 10 期,痞子衡有幸被邀请做了第 4 ...

  2. RequestMappingHandlerMapping请求地址映射流程!

    上篇文章里,我们讲解了RequestMappingHandlerMapping请求地址映射的初始化流程,理解了@Controller和@RequestMapping是如何被加载到缓存中的. 今天我们来 ...

  3. 【转载】EXCEL VBA 中的Range.offset和Range.resize

    在Excel VBA中range.offset和range.resize均可以重新选择区域,但range.offset表示偏移且偏移后尺寸不改变,range.resize则会根据输入的行数和列数重新定 ...

  4. 【深入浅出Seata原理及实战】「入门基础专题」探索Seata服务的AT模式下的分布式开发实战指南(2)

    承接上文 上一篇文章说到了Seata 为用户提供了 AT.TCC.SAGA 和 XA 事务模式,为用户打造一站式的分布式解决方案.那么接下来我们将要针对于AT模式下进行分布式事务开发的原理进行介绍以及 ...

  5. LOJ 数列分块入门 9 题解题报告

    LOJ 数列分块入门 9 题解题报告 \(\text{By DaiRuiChen007}\) I. 数列分块入门 1 题目大意 \(\text{Link}\) 维护一个长度为 \(n\) 的序列,支持 ...

  6. elasticsearch之search template

    一.search template简介 elasticsearch提供了search template功能,其会在实际执行查询之前,对search template进行预处理并将参数填充到templa ...

  7. SICTF2023 web_wp

    兔年大吉 源码如下 <?php highlight_file(__FILE__); error_reporting(0); class Happy{ private $cmd; private ...

  8. JUC并发编程

    什么是JUC java.util.concurrent* public class Test1 { public static void main(String[] args) { //获取处理器核数 ...

  9. Unity_UIWidgets - 按钮组件IconButton

    Unity_UIWidgets - 按钮组件IconButton 按钮组件IconButton IconButton 结尾 QQ 今日无推荐 按钮组件IconButton 既然上周给大家介绍了ICON ...

  10. drf-day7——认证组件、权限组件、频率组件、过滤排序、分页

    目录 一.认证组件 1.1 登录接口 1.2 认证组件使用步骤 1.3 整体代码 1.4认证时cookie的获取方式 二.权限组件 2.1需求分析: 2.2 权限的使用 2.3代码 三.频率组件 3. ...