作者:手機用戶7135
一、相關說明
使用VMware虛擬機,安裝CentOS7.9 64位系統(因為找不到7.6的安裝包了),設定此系統的基礎引數如下(這里記憶體需要設定大一點,不然可能會無法運行OpenGauss):

此外,還需要修改/etc/redhat-release檔案中系統的版本為:CentOS Linux release 7.6(Core),這是因為不安裝7.6,可能出現gauss與os不匹配的問題,但是目前已經沒有7.6的包了,所以選擇了7.9,然后吧版本號改掉,
二、具體安裝步驟
1.準備操作
(1)配置yum源
洗掉自帶的yum源
rm -rf /etc/yum.repos.d/*
下載阿里云的yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
然后更新快取
yum makecache
(2)安裝一些依賴項
yum clean all
yum install -y lksctp*
yum install -y java-1.8.0-openjdk* psmisc bzip2 python3 python3-devel
yum install -y libaio-devel flex bison ncurses-devel glibc-devel patch redhat-lsb-core
(3)配置ip和hostname
hostname && ifconfig |grep broadcast|awk '{print $2}'
sed -i '/MasterG/d' /etc/hosts
echo "192.168.2.131 MasterG ##Gauss OM IP Hosts Mapping" >> /etc/hosts
cat /etc/hosts|grep Gauss
(4)關閉防火墻然后重啟
systemctl status firewalld
systemctl disable firewalld.service
systemctl stop firewalld.service
sed -i '/SELINUX=/d' /etc/selinux/config
echo "SELINUX=disabled" >> /etc/selinux/config
cat /etc/selinux/config|grep -v ^#|grep -v '^$'
reboot
(5)配置時區
echo "export LANG=en_US.UTF-8" >> ~/.bash_profile
source ~/.bash_profile
env|grep LANG
rm -fr /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ll /etc/localtime
(6)關閉SWAP
swapoff -a
(7)關閉透明頁并重啟
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
sed -i '/^GRUB_CMDLINE_LINUX/d' /etc/default/grub
echo "GRUB_CMDLINE_LINUX=\"rhgb quiet transparent_hugepage=never\"" >> /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg
reboot
(8)修改系統資源限制
echo "* soft stack 3072" >> /etc/security/limits.conf
echo "* hard stack 3072" >> /etc/security/limits.conf
echo "* soft nofile 1000000" >> /etc/security/limits.conf
echo "* hard nofile 1000000" >> /etc/security/limits.conf
echo "* soft nproc unlimited" >> /etc/security/limits.d/90-nproc.conf
tail -n 4 /etc/security/limits.conf
tail -n 1 /etc/security/limits.d/90-nproc.conf
2.詳細安裝
(1)下載安裝包、創建用戶組和目錄
groupadd dbgrp
useradd -g dbgrp -d /home/omm -m -s /bin/bash omm
echo "omm" | passwd -‐stdin omm
mkdir -p /opt/software/openGauss
chmod 755 -R /opt/software
chown -R omm:dbgrp /opt/software/openGauss
cd /opt/software/openGauss/
wgethhttps://opengauss.obs.cn-south-1.myhuaweicloud.com/2.0.0/x86/openGauss-2.0.0-CentOS-64bit-all.tar.gz
tar -zxvf openGauss-2.0.0-CentOS-64bit-all.tar.gz
tar -zxvf openGauss-2.0.0-CentOS-64bit-om.tar.gz
(2)配置XML檔案
cp script/gspylib/etc/conf/cluster_config_template.xml .
具體組態檔為(標紅的地方要設定成自己的):
<?xml version="1.0" encoding="UTF-8"?>
<ROOT> <!-- openGauss整體資訊 -->
<CLUSTER> <!-- 資料庫名稱 -->
<PARAM name="clusterName" value="singlenode" /> <!-- 資料庫節點名稱(hostname) -->
<PARAM name="nodeNames" value="node1" /> <!-- 資料庫安裝目錄-->
<PARAM name="gaussdbAppPath" value="/opt/huawei/install/app" /> <!-- 日志目錄-->
<PARAM name="gaussdbLogPath" value="/opt/huawei/log" /> <!-- 臨時檔案目錄-->
<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="clusterType" value="single-inst"/>
<PARAM name="backIp1s" value="192.168.17.129"/>
</CLUSTER> <!-- 每臺服務器上的節點部署資訊 -->
<DEVICELIST> <!-- 節點1上的部署資訊 -->
<DEVICE sn="1000001"> <!-- 節點1的主機名稱 -->
<PARAM name="name" value="node1"/> <!-- 節點1所在的AZ及AZ優先級 -->
<PARAM name="azName" value="AZ1"/>
<PARAM name="azPriority" value="1"/> <!-- 節點1的IP,如果服務器只有一個網卡可用,將backIP1和sshIP1配置成同一個IP -->
<PARAM name="backIp1" value="192.168.2.131"/>
<PARAM name="sshIp1" value="192.168.2.131"/> <!--dbnode-->
<PARAM name="dataNum" value="1"/>
<PARAM name="dataPortBase" value="26000"/>
<PARAM name="dataNode1" value="/opt/huawei/install/data/db1"/>
<PARAM name="dataNode1_syncNum" value="0"/>
</DEVICE>
</DEVICELIST>
</ROOT>
(3)添加lib庫
在 .bashrc檔案中添加如下:
export GPHOME=/opt/huawei/install/om
export PATH=$GPHOME/script/gspylib/pssh/bin:$GPHOME/script:$PATH
export LD_LIBRARY_PATH=$GPHOME/lib:$LD_LIBRARY_PATH
export PYTHONPATH=$GPHOME/lib
export GAUSSHOME=/opt/huawei/install/app
export PATH=$GAUSSHOME/bin:$PATH
export LD_LIBRARY_PATH=$GAUSSHOME/lib:$LD_LIBRARY_PATH
export S3_CLIENT_CRT_FILE=$GAUSSHOME/lib/client.crt
export GAUSS_VERSION=2.0.0
export PGHOST=/opt/huawei/tmp
export GAUSSLOG=/opt/huawei/log/omm
umask 077
export GAUSS_ENV=2
export GS_CLUSTER_NAME=singlenode
(4)互動式安裝
首先是預安裝:
cd /opt/software/openGauss/script
python3 gs_preinstall -U omm -G dbgrp -X
/opt/software/openGauss/cluster_config_template.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 pssh path
Successfully set core path.
Are you sure you want to create the user[omm] and create trust for it (yes)? yes
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.
Setting SCTP service.
Successfully set SCTP service.
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/openGauss/script/gs_checkos -i A -h node1 --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.
Set ARM Optimization.
No need to set ARM Optimization.
Fixing server package owner.
Setting finish flag.
Successfully set finish flag.
Preinstallation succeeded.
到這里說明預安裝完成,
然后是正式安裝:
cd script/
gs_install -X /opt/software/openGauss/cluster_config_template.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 /opt/huawei/install/app/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.
Configuring pg_hba on all nodes.
Configuration is completed.
Successfully started cluster.
Successfully installed application.
end deploy.
輸入
gsql -d postgres -p 26000
使資料庫在本地運行,沒有出現報錯資訊即說明安裝成功,
3.連接設定
(1)安裝jdk1.8
(2)下載好jdbc壓縮包后,解壓至:
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.302.b08-0.el7_9.x86_64/jre/lib/ext
(3)登陸到omm用戶上,然后登錄資料庫主節點,執行如下指令:
NodeName為當前節點名稱,還要注意localhost改成對應的,
gs_guc reload -N node1-I all -c "listen_addresses='localhost,192.168.2.131’”
(4)執行下列指令,在資料庫主節點組態檔中增加一條規則:
gs_guc reload -N all -I all -h "host all user 192.168.17.129/32 sha256"
(5)然后通過java程式就可以鏈接了,
import java.sql.*; public class java_connect_opengauss{ public static Connection getConnect(String username, String passwd){ String driver = "org.postgresql.Driver"; String sourceURL = "jdbc:postgresql://127.0.0.1:26000/postgres"; Connection conn = null; try{ Class.forName(driver); } catch( Exception e ){ e.printStackTrace(); return null; }<span class="hljs-keyword">try</span>{ conn = DriverManager.getConnection(sourceURL, username, passwd); System.out.println(<span class="hljs-string">"Connection succeed!"</span>); } <span class="hljs-keyword">catch</span>(Exception e) { e.printStackTrace(); <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>; } <span class="hljs-keyword">return</span> conn; }; <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> { <span class="hljs-comment">//輸入資料庫的用戶名和密碼</span> <span class="hljs-type">Connection</span> <span class="hljs-variable">conn</span> <span class="hljs-operator">=</span> getConnect(<span class="hljs-string">"username"</span>, <span class="hljs-string">"password"</span>); <span class="hljs-keyword">try</span> { conn.close(); } <span class="hljs-keyword">catch</span> (SQLException e) { e.printStackTrace(); } }
}
Javac java_connect_opengauss.java
java java_connect_opengauss
然后會出出現Connection succeed!
即代表連接成功
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/390537.html
標籤:其他
