一、環境準備
| 節點類別 | 主機名 | 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
「喜歡這篇文章,您的關注和贊賞是給作者最好的鼓勵」
關注作者
【版權聲明】本文為墨天輪用戶原創內容,轉載時必須標注文章的來源(墨天輪),文章鏈接,文章作者等基本信息,否則作者和墨天輪有權追究責任。如果您發現墨天輪中有涉嫌抄襲或者侵權的內容,歡迎發送郵件至:contact@modb.pro進行舉報,并提供相關證據,一經查實,墨天輪將立刻刪除相關內容。




