使用虛擬機器在CentOS上安裝部署openGauss資料庫指導(下)

語言: CN / TW / HK

使用虛擬機器在CentOS上安裝部署openGauss資料庫指導(上)中,我們使用VirtualBox下安裝CentOS 7.8作業系統安裝和網路配置完成,本文我們會基於此安裝openGauss資料庫。

1.5 作業系統環境準備

為了操作方便,可以使用SSH工具(比如:PuTTY等)從本地電腦通過配置enp0s3網絡卡的IP地址(如:192.168.56.108)來連線虛擬機器,並使用ROOT使用者來登入。
在這裡插入圖片描述

步驟 1 修改作業系統版本。
如果CentOS版本不是7.6的需要進行修改,如果是7.6則無需修改,
先vi /etc/redhat-releas 開啟編輯檔案,然後將內容改為CentOS Linux release 7.6.2003 (Core)。輸入”i”切換到編輯模式,移動滑鼠到修改位置修改內容,然後按下ESC鍵退出編輯模式,然後輸入”:wq”退出並進行儲存,具體如下:

[[email protected] ~]# vi /etc/redhat-release

CentOS Linux release 7.6.2003 (Core)

步驟 2 關閉防火牆。
執行以下二個命令將防火牆關閉,
systemctl stop firewalld.service
systemctl disable firewalld.service,具體如下:

[[email protected] ~]# systemctl stop firewalld.service
[[email protected] ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[[email protected] ~]#

步驟 3 設定字符集及環境變數。

[[email protected] ~]# cat >>/etc/profile<<EOF
export LANG=en_US.UTF‐8
EOF

[[email protected] ~]# cat >>/etc/profile<<EOF
export packagePath=/opt/software/openGauss
EOF
[[email protected] ~]# source /etc/profile
[[email protected] ~]# cat >>/etc/profile<<EOF
export LD_LIBRARY_PATH=$packagePath/script/gspylib/clib:$LD_LIBRARY_PATH
EOF
[[email protected] ~]# 
[[email protected] ~]# source /etc/profile

驗證變數是否生效。

[[email protected] ~]# echo $LD_LIBRARY_PATH

/opt/software/openGauss/script/gspylib/clib:

步驟 4 關閉swap交換記憶體。

[[email protected] ~]# swapoff -a

步驟 5 準備yum環境。
備份原有的yum配置檔案。

[[email protected] ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
[[email protected] ~]#

下載可用源的repo檔案,可通過以下二種方式下載:
方式一:
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
方式二:
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.huaweicloud.com/repository/conf/CentOS-7-anon.repo

[[email protected] ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.huaweicloud.com/repository/conf/CentOS-7-anon.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2523  100  2523    0     0  14065      0 --:--:-- --:--:-- --:--:-- 14094

檢視repo檔案內容是否正確,如果顯示的內容不正確,請選擇另一種方式下載可用源的repo檔案。

[[email protected] ~]# cat /etc/yum.repos.d/CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
# 
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
……………………………..

步驟 6 yum安裝相關包。
執行以下命令,安裝所需的包
yum install -y libaio-devel flex bison ncurses-devel glibc.devel patch lsb_release wget python3
如下:

[[email protected] ~]# yum install -y libaio-devel flex bison ncurses-devel glibc.devel patch lsb_release wget python3
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
base               | 3.6 kB  00:00:00                                                                                                                              
extras              | 2.9 kB  00:00:00     
updates            | 2.9 kB  00:00:00
………………….

步驟 7 設定預設Python版本為3.x。

[[email protected] ~]# cd /usr/bin
[[email protected] bin]# mv python python.bak
[[email protected] bin]# ln -s python3 /usr/bin/python
[[email protected] bin]# python -V
Python 3.6.8

修改完成後,需要確認yum是否能使用,如果不能使用需要修改/usr/bin/yum檔案,把#!/usr/bin/python這行修改為#!/usr/bin/python2.7(或者對應的python 2.x的版本)。輸入”i”切換到編輯模式,移動滑鼠到修改位置修改內容,然後按下ESC鍵退出編輯模式,然後輸入”:wq”退出並進行儲存。如下:

[[email protected] bin]# vi /usr/bin/yum

#!/usr/bin/python2.7
import sys
……………………….

用yum --help命令來驗證yum是否能使用。

[[email protected] bin]# yum --help
Loaded plugins: fastestmirror, langpacks
Usage: yum [options] COMMAND
List of Commands:
check          Check for problems in the rpmdb
check-update   Check for available package updates
……………………….

步驟 8 建立存放資料庫安裝目錄。

[[email protected] ~]# mkdir -p /opt/software/openGauss
[[email protected] ~]# cd /opt/software/openGauss
[[email protected] openGauss]# 

步驟 9 下載資料庫安裝包。
使用wget下載資料庫安裝包,
cd /root
wget https://opengauss.obs.cn-south-1.myhuaweicloud.com/1.1.0/x86/openGauss-1.1.0-CentOS-64bit-all.tar.gz
具體如下:

[[email protected] openGauss]# wget https://opengauss.obs.cn-south-1.myhuaweicloud.com/1.1.0/x86/openGauss-1.1.0-CentOS-64bit-all.tar.gz
--2020-09-10 14:23:07--  https://opengauss.obs.cn-south-1.myhuaweicloud.com/1.1.0/x86/openGauss-1.1.0-CentOS-64bit-all.tar.gz

1.6 安裝openGauss資料庫

步驟 1 建立XML配置檔案,用於資料庫安裝。

[[email protected] openGauss]# vi clusterconfig.xml

將以下內容新增進clusterconfig.xml檔案中。輸入”i”切換到編輯模式,複製內容黏貼到文件中,然後按下ESC鍵退出編輯模式,然後輸入”:wq”退出並進行儲存。

<?xml version="1.0" encoding="UTF-8"?> 
<ROOT> 
    <!-- openGauss整體資訊 --> 
    <CLUSTER> 
        <PARAM name="clusterName" value="dbCluster" /> 
        <PARAM name="nodeNames" value="db1" /> 
        <PARAM name="backIp1s" value="10.0.3.15"/> 
        <PARAM name="gaussdbAppPath" value="/opt/gaussdb/app" /> 
        <PARAM name="gaussdbLogPath" value="/var/log/gaussdb" /> 
        <PARAM name="gaussdbToolPath" value="/opt/huawei/wisequery" /> 
        <PARAM name="corePath" value="/opt/opengauss/corefile"/> 
        <PARAM name="clusterType" value="single-inst"/> 
    </CLUSTER> 
    <!-- 每臺伺服器上的節點部署資訊 --> 
    <DEVICELIST> 
        <!-- node1上的節點部署資訊 --> 
        <DEVICE sn="1000001"> 
            <PARAM name="name" value="db1"/> 
            <PARAM name="azName" value="AZ1"/> 
            <PARAM name="azPriority" value="1"/> 
            <!-- 如果伺服器只有一個網絡卡可用,將backIP1和sshIP1配置成同一個IP --> 
            <PARAM name="backIp1" value="10.0.3.15"/> 
            <PARAM name="sshIp1" value="10.0.3.15"/> 
             
	    <!--dbnode--> 
	    <PARAM name="dataNum" value="1"/> 
	    <PARAM name="dataPortBase" value="26000"/> 
	    <PARAM name="dataNode1" value="/gaussdb/data/db1"/> 
        </DEVICE> 
    </DEVICELIST> 
</ROOT>

說明:其中xml裡面value 中出現的所有db1 和 10.0.3.15,需要根據自己實際的主機名和IP進行修改,一共需要修改6處,尤其/gaussdb/data/db1中的也要修改。如果其中的中文出現亂碼時可以刪除這些行。
步驟 2 將下載好的安裝包解壓至存放目錄。
先解壓openGauss-1.1.0-CentOS-64bit-all.tar.gz包。

[[email protected] openGauss]# tar -zxvf openGauss-1.1.0-CentOS-64bit-all.tar.gz

再先解壓openGauss-1.1.0-CentOS-64bit-om.tar.gz包。

[[email protected] openGauss]# tar -zxvf openGauss-1.1.0-CentOS-64bit-om.tar.gz

解壓後如下,用ls命令檢視如下:

[[email protected] openGauss]# ls
clusterconfig.xml                           openGauss-Package-bak_392c0438.tar.gz
lib                                         script
openGauss-1.1.0- CentOS-64bit-all.tar.gz  simpleInstall
openGauss-1.1.0- CentOS-64bit-om.sha256   upgrade_sql.sha256
openGauss-1.1.0- CentOS-64bit-om.tar.gz   upgrade_sql.tar.gz
openGauss-1.1.0-CentOS-64bit.sha256      version.cfg
openGauss-1.1.0-CentOS-64bit.tar.bz2

安裝包解壓後,會在/opt/software/openGauss路徑下自動生成script子目錄,並且在script目錄下生成gs_preinstall等各種OM工具指令碼。
更改許可權。

[[email protected] openGauss]# chmod 755 -R /opt/software
[[email protected] openGauss]#

步驟 3 執行初始化指令碼。

[[email protected] openGauss]# cd /opt/software/openGauss/script
[[email protected] script]# python gs_preinstall -U omm -G dbgrp -X /opt/software/openGauss/clusterconfig.xml
Parsing the configuration file.
Successfully parsed the configuration file.
Installing 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: 
Creating SSH trust for the root permission user.
Checking network information.
……………………………………..
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: 
Successfully created [omm] user on all nodes.
Preparing SSH service.
Successfully prepared SSH service.
……………………………………..
Successfully set finish flag.
Preinstallation succeeded.

期間需要輸入作業系統root使用者的密碼(如密碼:[email protected])和建立作業系統omm使用者及設定密碼(如密碼:[email protected])。密碼依然不回顯,直接輸入密碼並回車即可。
當返回Preinstallation succeeded內容時,表明初始化完成。
步驟 4 初始化資料庫。
用init 6 重啟下虛擬機器(主要是為了釋放一些記憶體資源)。

[[email protected] script]# init 6
Connection closing...Socket close.
Connection closed by foreign host.
Disconnected from remote host(ONE) at 10:51:59.
Type `help' to learn how to use Xshell prompt.

過段時間虛擬機器重啟好後,再次使用SSH工具(比如:PuTTY等)從本地電腦通過配置enp0s3網絡卡的IP地址(如:192.168.56.108)來連線虛擬機器,並使用ROOT使用者來登入,然後接著以下操作。
在這裡插入圖片描述
先更新下許可權。

[[email protected] script]# chmod 755 -R /opt/software
[[email protected] openGauss]#

然後使用omm使用者進行資料庫初始化。
注意:根據使用者實際記憶體大小設定對應的共享記憶體的大小,如果對該引數進行了設定,會在資料庫啟動時候報錯,本實驗虛擬機器總記憶體大小是2G。
gs_install -X /opt/software/openGauss/clusterconfig.xml --gsinit-parameter="–encoding=UTF8" --dn-guc=“max_process_memory=2GB” --dn-guc=“shared_buffers=128MB” --dn-guc=“bulk_write_ring_size=128MB” --dn-guc=“cstore_buffers=16MB
具體如下:

[[email protected] openGauss]# su - omm
Last login: Thu Sep 10 15:26:21 CST 2020 on pts/0
[[email protected] ~]$ cd /opt/software/openGauss/script
[[email protected] script]$ gs_install -X /opt/software/openGauss/clusterconfig.xml --gsinit-parameter="--encoding=UTF8"  --dn-guc="max_process_memory=2GB" --dn-guc="shared_buffers=128MB" --dn-guc="bulk_write_ring_size=128MB" --dn-guc="cstore_buffers=16MB"
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/gaussdb/app/share/sslcert/om
Cluster installation is completed.
Configuring.
………………………….
Successfully started cluster.
Successfully installed application.
end deploy..

注意:輸入omm使用者密碼時,不要輸入錯誤(如密碼:[email protected])。
步驟 5 清理軟體安裝包。

[[email protected] openGauss]$ exit
logout
[[email protected] script]# cd /opt/software/openGauss/
[[email protected] openGauss]# ll
total 288M
-rwxr-xr-x.  1 omm  dbgrp      1334 Jan 11 11:15 clusterconfig.xml
drwxr-xr-x. 15 root root       4096 Jan 11 11:14 lib
-rwxr-xr-x.  1 root root   99521627 Dec 31 20:58 openGauss-1.1.0-CentOS-64bit-all.tar.gz
-rwxr-xr-x.  1 root root         65 Dec 31 20:41 openGauss-1.1.0-CentOS-64bit-om.sha256
-rwxr-xr-x.  1 root root   13446137 Dec 31 20:41 openGauss-1.1.0-CentOS-64bit-om.tar.gz
-rwxr-xr-x.  1 root root         65 Dec 31 20:40 openGauss-1.1.0-CentOS-64bit.sha256
-rwxr-xr-x.  1 root root   87084796 Dec 31 20:40 openGauss-1.1.0-CentOS-64bit.tar.bz2
-rwxr-xr-x.  1 root root  100584223 Jan 11 11:14 openGauss-Package-bak_392c0438.tar.gz
drwxr-xr-x.  6 root root       4096 Dec 31 20:41 script
drwxr-xr-x.  2 root root        115 Dec 31 20:41 simpleInstall
-rwxr-xr-x.  1 root root         65 Dec 31 20:40 upgrade_sql.sha256
-rwxr-xr-x.  1 root root     134579 Dec 31 20:40 upgrade_sql.tar.gz
-rwxr-xr-x.  1 root root         32 Dec 31 20:40 version.cfg 
[[email protected] openGauss]# rm -rf openGauss-1.1.0-CentOS-64bit-all.tar.gz 
[[email protected] openGauss]# rm -rf openGauss-1.1.0-CentOS-64bit-om.tar.gz

至此,資料庫安裝結束。