詳講openGauss 5.0 單點企業版如何部署_Centos7_x86

本文分享自華爲雲社區《openGauss 5.0 單點企業版部署_Centos7_x86》,本文作者:董小姐

本文檔環境:CentOS7.9 x86_64 4G1C40G python2.7.5 交互式初始化環境方式

1、介紹

openGauss是一款開源關係型數據庫管理系統,採用木蘭寬鬆許可證v2發行。openGauss內核深度融合華爲在數據庫領域多年的經驗,結合企業級場景需求,持續構建競爭力特性。

openGauss社區版本分爲長期支持版本和創新版本:

· 長期支持版本 (LTS) ——規模上線使用,發佈間隔週期爲1年,提供3年社區支持。

· 社區創新版本 (Preview) ——聯創測試使用,發佈間隔週期爲1年,提供6個月社區支持。

openGauss支持單機部署和單機HA部署兩種部署方式。單機部署時,可在一個主機部署多個數據庫實例,但爲了數據安全,不建議用戶這樣部署。單機HA部署支持一臺主機和最少一臺備機,備機一共最多8臺的配置方式。

說明: 通過openGauss提供的腳本安裝時,只允許在單臺物理機部署一個數據庫系統。如果您需要在單臺物理機部署多個數據庫系統,建議您通過命令行安裝,不需要通過openGauss提供的安裝腳本執行安裝。

2、安裝前準備

2.1 軟硬件要求

僅作參考,自測環境低一些也可以,本文檔是CentOS7.9 x86_64 4G1C40G的配置

2.2 硬件環境

表1 硬件環境要求列出了openGauss服務器應具備的最低硬件要求。在實際產品中,硬件配置的規劃需考慮數據規模及所期望的數據庫響應速度。請根據實際情況進行規劃。

表 1 硬件環境要求

項目

配置描述

內存

功能調試建議32GB以上。

性能測試和商業部署時,單實例部署建議128GB以上。

複雜的查詢對內存的需求量比較高,在高併發場景下,可能出現內存不足。此時建議使用大內存的機器,或使用負載管理限制系統的併發。

CPU

功能調試最小1×8 核 2.0GHz。

性能測試和商業部署時,建議1×16核 2.0GHz。

CPU超線程和非超線程兩種模式都支持。

說明:

個人開發者最低配置2核4G, 推薦配置4核8G。

目前,openGauss僅支持ARM服務器和基於X86_64通用PC服務器的CPU。

硬盤

用於安裝openGauss的硬盤需最少滿足如下要求:

  • 至少1GB用於安裝openGauss的應用程序。

  • 每個主機需大約300MB用於元數據存儲。

  • 預留70%以上的磁盤剩餘空間用於數據存儲。

建議系統盤配置爲Raid1,數據盤配置爲Raid5,且規劃4組Raid5數據盤用於安裝openGauss。有關Raid的配置方法在本手冊中不做介紹。請參考硬件廠家的手冊或互聯網上的方法進行配置,其中Disk Cache Policy一項需要設置爲Disabled,否則機器異常掉電後有數據丟失的風險。

openGauss支持使用SSD盤作爲數據庫的主存儲設備,支持SAS接口和NVME協議的SSD盤,以RAID的方式部署使用。

網絡要求

300兆以上以太網。

建議網卡設置爲雙網卡冗餘bond。有關網卡冗餘bond的配置方法在本手冊中不做介紹。請參考硬件廠商的手冊或互聯網上的方法進行配置。

該文檔只採用了1塊網卡。

2.3 軟件環境

表 2 軟件環境要求

軟件類型

配置描述

Linux操作系統

  • ARM:

  • openEuler 20.3LTS(推薦採用此操作系統)

  • 麒麟V10

  • Asianux 7.5

  • X86:

  • openEuler 20.3LTS

  • CentOS 7.6

  • Asianux 7.6說明:當前安裝包只能在英文操作系統上安裝使用。

Linux文件系統

剩餘inode個數 > 15億(推薦)

工具

bzip2

Python

  • openEuler:支持Python 3.7.X, Python 3.9.X

  • CentOS:支持Python 3.6.X

  • 麒麟:支持Python 3.7.X

  • Asianux:支持Python 3.6.X說明:python需要通過--enable-shared方式編譯。

若用戶修改過系統python版本,則在安裝數據庫之前,還需手動安裝下列python模塊(pip安裝即可)。

psutil

netifaces

cffi

pycparser

cryptography

pynacl

bcrypt

paramiko

並且在預安裝時,需要加上--unused-third-party選項。

2.4 軟件依賴要求

openGauss的軟件依賴要求如表3 軟件依賴要求所示。

建議使用上述操作系統安裝光盤或者源中,下列依賴軟件的默認安裝包,若不存在下列軟件,可參看軟件對應的建議版本。

表 3 軟件依賴要求

所需軟件

建議版本

libaio-devel

建議版本:0.3.109-13

flex

要求版本:2.5.31 以上

bison

建議版本:2.7-4

ncurses-devel

建議版本:5.9-13.20130511

glibc-devel

建議版本:2.17-111

patch

建議版本:2.7.1-10

redhat-lsb-core

建議版本:4.1

readline-devel

建議版本:7.0-13

libnsl(openEuler+x86環境中)

建議版本 :2.28-36

3、系統參數配置

3.1 操作系統主機命名(可選)

如果採用默認主機名,可忽略該步驟,默認的主機名localhost.localdomain,xml文件中的主機名也需要改成localhost.localdomain

hostnamectl set-hostname opendb01

3.2 /etc/hosts配置(可選)

如果採用默認主機名,可忽略該步驟,預安裝會自動追加127.0.0.1 localhost #Gauss OM IP Hosts Mapping

cp /etc/hosts /etc/hosts.bak
cat >>/etc/hosts<<EOF
192.168.40.110      opendb01  
EOF

3.3 limits.conf

不用配置該文件,會自動追加如下內容:

cat /etc/security/limits.conf
....
root       soft    as  unlimited
omm       soft    as  unlimited
root       hard    as  unlimited
omm       hard    as  unlimited
root       soft    nproc  unlimited
omm       soft    nproc  unlimited
root       hard    nproc  unlimited
omm       hard    nproc  unlimited

3.4 關閉透明頁

echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag

--加入開機啓動
echo '
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag' >>/etc/rc.local
chmod +x /etc/rc.local

3.5 防火牆配置

systemctl stop firewalld.service
systemctl disable firewalld.service

如果啓用防火牆需進行如下配置:

如果數據庫端口和ssh端口不是15400和22,需視情況更改

firewall-cmd --zone=public --add-port=15400/tcp --permanent
firewall-cmd --zone=public --add-port=22/tcp --permanent
firewall-cmd --reload

3.6 selinux配置

sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0

3.7 關閉 numa和禁用透明大頁

sed -i "s/quiet/quiet numa=off transparent_hugepage=never/g"  /etc/default/grub 
grub2-mkconfig -o /etc/grub2.cfg

4、設置字符集參數

echo "export LANG=en_US.UTF-8"  >> /etc/profile
source /etc/profile

4.1 設置時區和時間

如果服務器時間和當前時間相差8小時或者12小時,需要查看時區,分析是否決定更改。

4.2 非可視化更改步驟

--查看當前時間
[root@opendb01 ~]# date
Fri Jan 26 16:50:55 CST 2024

--查看當前時區
root@HKSZF-ZW-172-19-146-176:/topsoft# timedatectl
                      Local time: Wed 2024-01-24 05:51:05 UTC
                  Universal time: Wed 2024-01-24 05:51:05 UTC
                        RTC time: Wed 2024-01-24 05:51:56
                       Time zone: Etc/UTC (UTC, +0000)
       System clock synchronized: no
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

--更改時區  執行tzselect命令

root@HKSZF-ZW-172-19-146-176:/topsoft# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent, ocean, "coord", or "TZ".
 1) Africa
 2) Americas
 3) Antarctica
 4) Asia
 5) Atlantic Ocean
 6) Australia
 7) Europe
 8) Indian Ocean
 9) Pacific Ocean
10) coord - I want to use geographical coordinates.
11) TZ - I want to specify the time zone using the Posix TZ format.

--找到Asia,輸入4,回車
Please select a country whose clocks agree with yours.
 1) Afghanistan           18) Israel                35) Palestine
 2) Armenia               19) Japan                 36) Philippines
 3) Azerbaijan            20) Jordan                37) Qatar
 4) Bahrain               21) Kazakhstan            38) Russia
 5) Bangladesh            22) Korea (North)         39) Saudi Arabia
 6) Bhutan                23) Korea (South)         40) Singapore
 7) Brunei                24) Kuwait                41) Sri Lanka
 8) Cambodia              25) Kyrgyzstan            42) Syria
 9) China                 26) Laos                  43) Taiwan
10) Cyprus                27) Lebanon               44) Tajikistan
11) East Timor            28) Macau                 45) Thailand
12) Georgia               29) Malaysia              46) Turkmenistan
13) Hong Kong             30) Mongolia              47) United Arab Emirates
14) India                 31) Myanmar (Burma)       48) Uzbekistan
15) Indonesia             32) Nepal                 49) Vietnam
16) Iran                  33) Oman                  50) Yemen
17) Iraq                  34) Pakistan

--找到china,輸入9,回車
Please select one of the following time zone regions.
1) Beijing Time
2) Xinjiang Time

--找到北京時間,輸入1,回車
Please select one of the following time zone regions.
1) Beijing Time
2) Xinjiang Time

--選擇yes,輸入1,回車
The following information has been given:

        China
        Beijing Time

Therefore TZ='Asia/Shanghai' will be used.
Selected time is now:   Wed Jan 24 21:40:32 CST 2024.
Universal Time is now:  Wed Jan 24 13:40:32 UTC 2024.
Is the above information OK?
1) Yes
2) No

--更新設置
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

--查看是否更改成功
root@HKSZF-ZW-172-19-146-176:/topsoft# date
Wed Jan 24 21:42:00 CST 2024

root@HKSZF-ZW-172-19-146-176:/topsoft# timedatectl
                      Local time: Wed 2024-01-24 21:42:06 CST
                  Universal time: Wed 2024-01-24 13:42:06 UTC
                        RTC time: Wed 2024-01-24 06:09:59
                       Time zone: Asia/Shanghai (CST, +0800)
       System clock synchronized: no
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

4.3 可視化更改步驟

--查看當前時間
[root@opendb01 ~]# date
Fri Jan 26 16:50:55 CST 2024

--查看當前時區
root@HKSZF-ZW-172-19-146-176:/topsoft# timedatectl
                      Local time: Wed 2024-01-24 05:51:05 UTC
                  Universal time: Wed 2024-01-24 05:51:05 UTC
                        RTC time: Wed 2024-01-24 05:51:56
                       Time zone: Etc/UTC (UTC, +0000)
       System clock synchronized: no
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

在可視化界面中查看

選擇進入 Applications -> System Tools -> Settings -> Details -> Date & Time

調整時間

點擊“Date & Time”行中任意位置,彈出彈窗,調整時間爲當前北京時間,再關閉彈窗,即保存。如下圖所示:

再次使用命令查看,本地時間已顯示爲北京時間

[root@localhost src]# timedatectl
      Local time: Mon 2022-04-04 13:14:03 CST
  Universal time: Mon 2022-04-04 05:14:03 UTC
        RTC time: Mon 2022-04-04 05:14:03
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

4.4 關閉swap交換內存(可選)

關閉swap交換內存是爲了保障數據庫的訪問性能,避免把數據庫的緩衝區內存淘汰到磁盤上。 如果服務器內存比較小,內存過載時,可打開swap交換內存保障正常運行。

swapoff -a

4.5 關閉RemoveIPC

在各數據庫節點上,關閉RemoveIPC。CentOS操作系統默認爲關閉,可以跳過該步驟。

修改/etc/systemd/logind.conf文件中的“RemoveIPC”值爲“no”。a. 使用VIM打開logind.conf文件。

--更改後的/etc/systemd/logind.conf
vim  /etc/systemd/logind.conf
RemoveIPC=no

--更改後的
vim /usr/lib/systemd/system/systemd-logind.service
RemoveIPC=no

--重新加載配置參數
systemctl daemon-reload
systemctl restart systemd-logind

--檢查修改是否生效
loginctl show-session | grep RemoveIPC
systemctl show systemd-logind | grep RemoveIPC

4.6 關閉HISTORY記錄(可選)

爲避免指令歷史記錄安全隱患,需關閉各主機的history指令。

更改/etc/profile中HISTSIZE值
vim /etc/profile
HISTSIZE默認值爲1000 更改爲 HISTSIZE=0

--生效
source /etc/profile

4.7 配置yum源

將操作系統鏡像上傳至/opt目錄下

mount /opt/*.iso /mnt/
cat << EOF >> /etc/fstab
/dev/sr0    /mnt        iso9660 loop            0 0
EOF

mkdir -p /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
cat >> /etc/yum.repos.d/os.repo <<"EOF"
[OS1]
name=OS
baseurl=file:///mnt
enabled=1
gpgcheck=0
EOF

5、安裝依賴包

yum install -y bzip2 libaio-devel flex bison ncurses-devel glibc-devel \
patch redhat-lsb-core readline-devel 

注意:openEuler+x86環境中  yum install -y libnsl

6、python版本升級

python版本如果是3.6.x,可跳過該步驟

python版本2.7.5需升級至3.6.x版本,centos7 用python3.6 ,歐拉20用python3.7,其實不需要去編譯安裝python,直接用操作系統自帶的包管理器yum install python3或dnf install python3,裝上去就是對應的版本了。切不要編譯安裝,不然跳坑,預安裝時報錯。

--查看python版本
[root@opendb01 ~]# python --version
Python 2.7.5

[root@opendb01 ~]# python3 --version
python3命令找不到

--採用yum方式安裝操作系統自帶的包管理器中的python3
yum install python3

--再次查看python版本
[root@opendb01 ~]# python --version
Python 2.7.5

[root@opendb01 ~]# python3 --version
Python 3.6.8

7、創建用戶及用戶組(可選)

可以創建也可以不創建,自行操作

--創建用戶組dbgrp
groupadd dbgrp

--創建用戶組dbgroup下的普通用戶omm,並設置密碼爲Gauss_234 
useradd -g dbgrp omm
passwd omm

爲了實現安裝過程中安裝帳戶權限最小化,及安裝後openGauss的系統運行安全性,安裝腳本在安裝過程中會自動按照用戶指定內容創建安裝用戶,並將此用戶作爲後續運行和維護openGauss的管理員帳戶。

用戶/組名

所屬類型

規劃建議

dbgrp

操作系統

建議規劃單獨的用戶組,例如dbgrp。

初始化安裝環境時,由-G參數所指定的安裝用戶所屬的用戶組。該用戶組如果不存在,則會自動創建,也可提前創建好用戶組。在執行gs_preinstall腳本時會檢查權限。gs_preinstall腳本會自動賦予此組中的用戶對安裝目錄、數據目錄的訪問和執行權限。

創建dbgrp用戶組命令:

groupadd dbgrp

omm

操作系統

建議規劃用戶用於運行和維護openGauss,例如omm。

初始化安裝環境時,由-U參數所指定和自動創建的操作系統用戶,如果已經存在該用戶,請清理該用戶或更換初始化用戶。從安全性考慮,對此用戶的所屬組規劃如下:

所屬組:dbgrp

在安裝openGauss過程中root用戶運行 openGauss-5.0.1-CentOS-64bit-om.tar.gz中scripts目錄中的“gs_preinstall”時,會創建與安裝用戶同名的數據庫用戶,即數據庫用戶omm。此用戶具備數據庫的最高操作權限,此用戶初始密碼由用戶指定。

8、目錄規劃

--創建存放安裝包的目錄
mkdir -p /topsoft/soft/openGauss
chmod 777 -R /topsoft/soft

--創建目錄  目錄會自動創建,可選擇不創建
mkdir -p /topsoft/huawei/install/app  #數據庫安裝目錄
mkdir -p /topsoft/huawei/log/omm  #日誌目錄
mkdir -p /topsoft/huawei/tmp  #臨時文件目錄
mkdir -p /topsoft/huawei/install/om  #數據庫工具目錄
mkdir -p /topsoft/huawei/corefile  #數據庫core文件目錄

不建議把安裝包的存放目錄規劃到openGauss用戶的根目錄或其子目錄下,可能導致權限問題。

openGauss用戶須具有/topsoft/soft/openGauss目錄的讀寫權限。

9、下載並上傳安裝包

登錄openGauss開源社區https://opengauss.org/zh/download/,選擇對應平臺的企業版安裝包。

上傳至/topsoft/soft/openGauss目錄,安裝包“openGauss-5.1.0-openEuler-64bit-all.tar.gz”和配置文件“cluster_config.xml”都上傳至上一步所創建的目錄中。

10、配置單節點XML文件

安裝openGauss前需要創建XML文件。XML文件包含部署openGauss的服務器信息、安裝路徑、IP地址以及端口號等。用於告知openGauss如何部署。用戶需根據不同場景配置對應的XML文件。

關於如何配置XML文件,詳細請參見創建XML配置文件。

將cluster_config.xml上傳至/topsoft/soft/openGauss目錄,安裝包“openGauss-5.1.0-openEuler-64bit-all.tar.gz”和配置文件“cluster_config.xml”都上傳至上一步所創建的目錄中。

爲確保成功安裝,檢查hostname與/etc/hostname是否一致。預安裝過程中,會對hostname進行檢查。

默認端口15400,若待用自定義端口,更改xml文件中的端口號

官方XML文件模板

cat cluster_config.xml
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
    <!-- openGauss整體信息 -->
    <CLUSTER>
        <!-- 數據庫名稱 -->
        <PARAM name="clusterName" value="dbCluster" />
        <!-- 數據庫節點名稱(hostname) -->
        <PARAM name="nodeNames" value="node1_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"/> 
    </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"/>
               
	    <!--dbnode-->
	    <PARAM name="dataNum" value="1"/>
	    <PARAM name="dataPortBase" value="15400"/>
	    <PARAM name="dataNode1" value="/opt/huawei/install/data/dn"/>
            <PARAM name="dataNode1_syncNum" value="0"/>
        </DEVICE>
    </DEVICELIST>
</ROOT>

根據官方模板更改後的xml文件

cat cluster_config.xml
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
    <!-- openGauss整體信息 -->
    <CLUSTER>
        <!-- 數據庫名稱 -->
        <PARAM name="clusterName" value="dbCluster" />
        <!-- 數據庫節點名稱(hostname) -->
        <PARAM name="nodeNames" value="opendb01" />
        <!-- 數據庫安裝目錄-->
        <PARAM name="gaussdbAppPath" value="/topsoft/huawei/install/app" />
        <!-- 日誌目錄-->
        <PARAM name="gaussdbLogPath" value="/topsoft/huawei/log/omm" />
        <!-- 臨時文件目錄-->
        <PARAM name="tmpMppdbPath" value="/topsoft/huawei/tmp" />
        <!-- 數據庫工具目錄-->
        <PARAM name="gaussdbToolPath" value="/topsoft/huawei/install/om" />
        <!-- 數據庫core文件目錄-->
        <PARAM name="corePath" value="/topsoft/huawei/corefile" />
        <!-- 節點IP,與數據庫節點名稱列表一一對應 -->
        <PARAM name="backIp1s" value="192.168.40.110"/> 
    </CLUSTER>
    <!-- 每臺服務器上的節點部署信息 -->
    <DEVICELIST>
        <!-- 節點1上的部署信息 -->
        <DEVICE sn="opendb01">
            <!-- 節點1的主機名稱 -->
            <PARAM name="name" value="opendb01"/>
            <!-- 節點1所在的AZ及AZ優先級 -->
            <PARAM name="azName" value="AZ1"/>
            <PARAM name="azPriority" value="1"/>
            <!-- 節點1的IP,如果服務器只有一個網卡可用,將backIP1和sshIP1配置成同一個IP -->
            <PARAM name="backIp1" value="192.168.40.110"/>
            <PARAM name="sshIp1" value="192.168.40.110"/>
               
	    <!--dbnode-->
	    <PARAM name="dataNum" value="1"/>
	    <PARAM name="dataPortBase" value="15400"/>
	    <PARAM name="dataNode1" value="/topsoft/huawei/install/data/dn"/>
            <PARAM name="dataNode1_syncNum" value="0"/>
        </DEVICE>
    </DEVICELIST>
</ROOT>

可通過以下全局替換

vi /topsoft/soft/openGauss/cluster_config.xml

:%s#node1_hostname#opendb01#g   #主機名
:%s#/opt/huawei/install/app#/topsoft/huawei/install/app#g   #安裝目錄
:%s#/opt/huawei/install/app#/topsoft/huawei/install/app#g   #安裝目錄
:%s#/var/log/omm#/topsoft/huawei/log/omm#g    #日誌目錄
:%s#/opt/huawei/tmp#/topsoft/huawei/tmp#g   #臨時文件目錄
:%s#/opt/huawei/install/om#/topsoft/huawei/install/om#g    #數據庫工具目錄
:%s#/opt/huawei/corefile#/topsoft/huawei/corefile#g   #數據庫core文件目錄
:%s#192.168.0.1#192.168.40.110#g   #IP地址
:%s#/opt/huawei/install/data/dn#/topsoft/huawei/install/data/dn#g   #數據節點目錄  /opt/huawei/install/data/dn

11、解壓安裝包

對於個人開發者或非企業級環境,下載極簡安裝包(不安裝OM等組件)即可。本文檔採用的是企業版安裝,因此安裝OM等組件

注意:安裝包“openGauss-5.1.0-openEuler-64bit-all.tar.gz”和配置文件“cluster_config.xml”需在同一目錄中,本文檔是/topsoft/soft/openGauss目錄。

--進入安裝包所在目錄
[root@opendb01 ~]# cd /topsoft/soft/openGauss/
[root@localhost openGauss]# ls -l
total 130712
-rw-r--r--. 1 root root      1905 Jan 27 08:31 cluster_config.xml
-rw-r--r--. 1 root root 133842584 Jan 27 08:30 openGauss-5.1.0-openEuler-64bit-all.tar.gz

--解壓openGauss-5.1.0-openEuler-64bit-all.tar.gz安裝包
tar -xvf openGauss-5.1.0-openEuler-64bit-all.tar.gz 

--查看解壓後的文件
[root@localhost ~]# cd /topsoft/soft/openGauss/
[root@localhost openGauss]# ls -lS
total 131764
-rw-r--r--. 1 root root 99901554 Dec 15 20:34 openGauss-5.0.1-CentOS-64bit.tar.bz2
-rw-r--r--. 1 root root 22528301 Dec 15 20:34 openGauss-5.0.1-CentOS-64bit-cm.tar.gz
-rw-r--r--. 1 root root 11971903 Dec 15 20:33 openGauss-5.0.1-CentOS-64bit-om.tar.gz  #數據庫工具目錄
-rw-------. 1 root root   499269 Dec 15 20:32 upgrade_sql.tar.gz
-rw-r--r--. 1 root root      105 Dec 15 20:34 openGauss-5.0.1-CentOS-64bit-cm.sha256
-rw-r--r--. 1 root root       65 Dec 15 20:33 openGauss-5.0.1-CentOS-64bit-om.sha256
-rw-r--r--. 1 root root       65 Dec 15 20:34 openGauss-5.0.1-CentOS-64bit.sha256
-rw-------. 1 root root       65 Dec 15 20:32 upgrade_sql.sha256

參數說明:
-S :按文件類型排序

--繼續解壓openGauss-5.0.1-CentOS-64bit-om.tar.gz  數據庫工具包 企業版安裝需要解壓該包極簡版不需要
tar -xvf openGauss-5.0.1-CentOS-64bit-om.tar.gz

--查看解壓後的文件   script目錄中生成gs_preinstall等各種OM工具腳本
[root@opendb01 openGauss]# ls -lS
total 262484
-rw-r--r--.  1 root root 133842584 Jan 24 06:03 openGauss-5.1.0-openEuler-64bit-all.tar.gz
-rw-r--r--.  1 root root  99901554 Dec 15 20:34 openGauss-5.0.1-CentOS-64bit.tar.bz2
-rw-r--r--.  1 root root  22528301 Dec 15 20:34 openGauss-5.0.1-CentOS-64bit-cm.tar.gz
-rw-r--r--.  1 root root  11971903 Dec 15 20:33 openGauss-5.0.1-CentOS-64bit-om.tar.gz
-rw-------.  1 root root    499269 Dec 15 20:32 upgrade_sql.tar.gz
drwxr-xr-x. 14 root root      4096 Dec 15 20:33 lib
drwxr-xr-x. 10 root root      4096 Dec 15 20:33 script
-rw-r--r--.  1 root root       105 Dec 15 20:34 openGauss-5.0.1-CentOS-64bit-cm.sha256
-rw-r--r--.  1 root root        65 Dec 15 20:33 openGauss-5.0.1-CentOS-64bit-om.sha256
-rw-r--r--.  1 root root        65 Dec 15 20:34 openGauss-5.0.1-CentOS-64bit.sha256
-rw-------.  1 root root        65 Dec 15 20:32 upgrade_sql.sha256
-rw-r--r--.  1 root root        32 Dec 15 20:33 version.cfg
  • 在執行前置腳本gs_preinstall時,需要規劃好openGauss配置文件路徑、安裝包存放路徑、程序安裝目錄、實例數據目錄,後續普通用戶使用過程中不能再更改這些路徑。

  • 運行前置腳本gs_preinstall準備安裝環境時,腳本內部會自動將openGauss配置文件、解壓後的安裝包同步拷貝到其餘服務器的相同目錄下。

  • 在執行前置腳本或者互信前,請檢查/etc/profile文件中是否包含錯誤輸出信息,如果存在錯誤輸出,需手動處理。

12、使用gs_preinstall初始化安裝環境

安裝環境的初始化包含上傳安裝包和XML文件(二者需在同一目錄)、解壓安裝包、使用gs_preinstall準備好安裝環境。

分2種場景初始化,自行選擇。

13、準備安裝用戶及環境

創建完openGauss配置文件後,在執行安裝前,爲了後續能以最小權限進行安裝及openGauss管理操作,保證系統安全性,需要運行安裝前置腳本gs_preinstall準備好安裝用戶及環境。在執行前置腳本gs_preinstall時,需要規劃好openGauss配置文件路徑、安裝包存放路徑、程序安裝目錄、實例數據目錄,後續普通用戶使用過程中不能再更改這些路徑。

安裝前置腳本gs_preinstall可以協助用戶自動完成如下的安裝環境準備工作:

  • 自動設置Linux內核參數以達到提高服務器負載能力的目的。這些參數直接影響數據庫系統的運行狀態,請僅在確認必要時調整。openGauss所設置的Linux內核參數取值請參見配置操作系統參數。

  • 腳本內部會自動將openGauss配置文件、安裝包拷貝到openGauss主機的相同目錄下。

  • openGauss安裝用戶、用戶組不存在時,自動創建安裝用戶以及用戶組。

  • 讀取openGauss配置文件中的目錄信息並創建,將目錄權限授予安裝用戶。

  • 只能使用root用戶執行gs_preinstall命令

  • 在執行前置腳本或者互信前,請檢查/etc/profile文件中是否包含錯誤輸出信息,如果存在錯誤輸出,需手動處理。

注意:如果是openEuler(openEuler 20.03)的操作系統,執行如下命令打開performance.sh文件,用#註釋sysctl -w vm.min_free_kbytes=112640 &> /dev/null,鍵入“ESC”鍵進入指令模式,執行**:wq**保存並退出修改。

vi /etc/profile.d/performance.sh

場景1:採用交互模式執行前置

[root@opendb01 /]# cd /topsoft/soft/openGauss/script/
./gs_preinstall -U omm -G dbgrp -X /topsoft/soft/openGauss/cluster_config.xml

這裏設置:omm用戶密碼omm

預安裝腳本執行的詳細過程如下:

[root@localhost script]# ./gs_preinstall -U omm -G dbgrp -X /topsoft/soft/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.
Setting host ip env
Successfully set host ip env.
Are you sure you want to create the user[omm] (yes/no)?
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.
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 "/topsoft/soft/openGauss/script/gs_checkos -i A -h opendb01 --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.

問題處理

--問題描述
採用交互模式執行前置時報錯/usr/bin/env: python3: No such file or directory
[root@opendb01 script]# ./gs_preinstall -U omm -G dbgrp -X /opt/software/openGauss/cluster_config.xml
/usr/bin/env: python3: No such file or directory

--解決辦法
採用上面辦法進行python版本升級
--查看python版本
[root@opendb01 ~]# python --version
Python 2.7.5

[root@opendb01 ~]# python3 --version
python3命令找不到

--採用yum方式安裝操作系統自帶的包管理器中的python3
yum install python3

--再次查看python版本
[root@opendb01 ~]# python --version
Python 2.7.5

[root@opendb01 ~]# python3 --version
Python 3.6.8

14、執行安裝

使用gs_install安裝openGauss。安裝腳本gs_install必須以前置腳本中指定的omm執行,否則,腳本執行會報錯。

/topsoft/soft/openGauss/cluster_config.xml爲openGauss配置文件的路徑。在執行過程中,用戶需根據提示輸入數據庫的密碼,密碼具有一定的複雜度,爲保證用戶正常使用該數據庫,請記住輸入的數據庫密碼。這裏設置爲Topnet@123

設置的密碼要符合複雜度要求:

  • 最少包含8個字符,最多包含16個字符。

  • 不能和用戶名、當前密碼(ALTER)、或當前密碼反序相同。

  • 至少包含大寫字母(A-Z)、小寫字母(a-z)、數字、非字母數字字符(限定爲~!@#$%^&*()-_=+\|[{}];:,<.>/?)四類字符中的三類字符。

注意事項:

  • openGauss支持字符集的多種寫法:gbk/GBK、UTF-8/UTF8/utf8/utf-8和Latine1/latine1。

  • 安裝時若不指定字符集,默認字符集爲SQL_ASCII,爲簡化和統一區域loacle默認設置爲C,若想指定其他字符集和區域,請在安裝時使用參數–gsinit-parameter="–locale=LOCALE"來指定,LOCALE爲新數據庫設置缺省的區域。

  • 默認端口15400

--賦予配置文件777的權限,因爲安裝腳本gs_install必須以前置腳本中指定的omm執行
chmod 777 /topsoft/soft/openGauss/cluster_config.xml

--切換用戶  omm爲前置腳本gs_preinstall中-U參數指定的用戶
su - omm

--查看配置文件/etc/profile中的語言參數
[omm@opendb01 dn_6001]$ cat /etc/profile | grep LANG
export LANG=en_US.UTF-8

--查看系統支持UTF-8編碼的區域
 locale -a|grep utf8

--執行安裝腳本
gs_install -X /topsoft/soft/openGauss/cluster_config.xml --gsinit-parameter="--locale=en_US.utf8"

安裝過程中會生成ssl證書,證書存放路徑爲{gaussdbAppPath}/share/sslcert/om,其中{gaussdbAppPath}爲openGauss配置文件中指定的程序安裝目錄。

[omm@opendb01 om]$ cd /topsoft/huawei/install/app/share/sslcert/om
[omm@opendb01 om]$ ls -l
total 64
-rw-------. 1 omm dbgrp  4399 Jan 27 08:43 cacert.pem
-rw-------. 1 omm dbgrp  4402 Jan 27 08:43 client.crt
-rw-------. 1 omm dbgrp  1766 Jan 27 08:43 client.key
-rw-------. 1 omm dbgrp    56 Jan 27 08:43 client.key.cipher
-rw-------. 1 omm dbgrp  1218 Jan 27 08:43 client.key.pk8
-rw-------. 1 omm dbgrp    24 Jan 27 08:43 client.key.rand
-rw-------. 1 omm dbgrp 10921 Jan 27 08:43 openssl.cnf
-rw-------. 1 omm dbgrp  4402 Jan 27 08:43 server.crt
-rw-------. 1 omm dbgrp  1766 Jan 27 08:43 server.key
-rw-------. 1 omm dbgrp    56 Jan 27 08:43 server.key.cipher
-rw-------. 1 omm dbgrp    24 Jan 27 08:43 server.key.rand

日誌文件路徑下會生成兩個日誌文件:“gs_install-YYYY-MMDD_HHMMSS.log”和“gs_local-YYYY-MM-DD_HHMMSS.log”。

/topsoft/huawei/log/omm/omm/om/gs_install-2024-01-27_084156.log

詳細過程如下:

[omm@opendb01 ~]$ gs_install -X /topsoft/soft/openGauss/cluster_config.xml
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 /topsoft/huawei/install/app/share/sslcert/om
NO cm_server instance, no need to create CA for CM.
Non-dss_ssl_enable, no need to create CA for DSS
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.
Configuring pg_hba on all nodes.
Configuration is completed.
The cluster status is Normal.
Successfully started cluster.
Successfully installed application.
end deploy..

問題處理

字符集不是UTF8

--問題描述
安裝完成後登錄數據庫查看數據庫時字符集不是UTF8

--原因
執行安裝時未指定字符集參數,,未指定字符集參數執行安裝時字符集默認是SQL_ASCII

--解決辦法
--查看配置文件/etc/profile中的語言參數
[omm@opendb01 dn_6001]$ cat /etc/profile | grep LANG
export LANG=en_US.UTF-8

--

15、訪問數據庫

連接數據庫的客戶端工具包括gsql、應用程序接口(如JDBC)。

  • gsql是openGauss自帶的客戶端工具。使用gsql連接數據庫,可以交互式地輸入、編輯、執行SQL語句。

  • 用戶可以使用標準的數據庫應用程序接口(如JDBC),開發基於openGauss的應用程序。

--查看進程
[omm@opendb01 ~]$ ps -ef | grep gaussdb
omm        7669      1  8 07:18 ?        00:01:45 /topsoft/huawei/install/app/bin/gaussdb -D /topsoft/huawei/install/data/dn
或
[omm@opendb01 ~]$ gs_ctl query -D /topsoft/huawei/install/data/dn
[2024-01-28 07:40:02.099][9092][][gs_ctl]: gs_ctl query ,datadir is /topsoft/huawei/install/data/dn
 HA state:
	local_role                     : Normal
	static_connections             : 0
	db_state                       : Normal
	detail_information             : Normal

 Senders info:
No information
 Receiver info:
No information

本地連接數據庫

gsql是openGauss提供的在命令行下運行的數據庫連接工具。此工具除了具備操作數據庫的基本功能,還提供了若干高級特性,便於用戶使用。本節只介紹如何使用gsql連接數據庫,關於gsql使用方法的更多信息請參考《工具與命令參考》中“客戶端工具 > gsql”章節。

缺省情況下,客戶端連接數據庫後處於空閒狀態時會根據參數session_timeout的默認值自動斷開連接。如果要關閉超時設置,設置參數session_timeout爲0即可。默認爲0表示關閉超時設置

以操作系統用戶omm登錄數據庫主節點。

su - omm
法一:
gsql -d postgres -p 15400

參數說明:
-d 連接的數據庫名稱,
-p 數據庫主節點的端口號

法二:
gsql -d "host=127.0.0.1 port=15400 dbname=postgres user=omm password=Topnet@123"
--登錄後如下:
[omm@localhost ~]$ gsql -d postgres -p 15400
gsql ((openGauss 5.0.1 build 33b035fd) compiled at 2023-12-15 20:19:06 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=# \l+
                                                              List of databases
   Name    | Owner | Encoding |  Collate   |   Ctype    | Access privileges | Size  | Tablespace |
  Description
-----------+-------+----------+------------+------------+-------------------+-------+------------+--------------
------------------------------
 postgres  | omm   | UTF8     | en_US.utf8 | en_US.utf8 |                   | 13 MB | pg_default | default admin
istrative connection database
 template0 | omm   | UTF8     | en_US.utf8 | en_US.utf8 | =c/omm           +| 13 MB | pg_default | default templ
ate for new databases
           |       |          |            |            | omm=CTc/omm       |       |            |
 template1 | omm   | UTF8     | en_US.utf8 | en_US.utf8 | =c/omm           +| 13 MB | pg_default | unmodifiable
empty database
           |       |          |            |            | omm=CTc/omm       |       |            |
(3 rows)

--查看數據庫狀態
[omm@localhost ~]$ gs_om -t status
-----------------------------------------------------------------------

cluster_name    : dbCluster
cluster_state   : Normal   #“Normal”表示數據庫可正常使用
redistributing  : No

--創建數據庫  不能是en_US.utf8不然報錯
openGauss=# create database test with encoding 'utf8' template = template0;
CREATE DATABASE

以上是openGauss安裝部署實踐分享,歡迎大家一起交流學習。

點擊關注,第一時間瞭解華爲雲新鮮技術~

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章