上次提到的开机自启动的配置,获得了LD的称赞,然而LD的要求,都是“既得陇复望蜀”的,他又期望我们能实现openGauss安装的“自动化”,于是尝试了下用shell脚本部署,附件中的脚本实测有效,openEuler 20.03 LTS通过shell脚本建议操作部署openGauss 5.0.0企业版成功。

说明:除了安装openGauss的shell脚本外,还需要准备两个配置文件,一个是openGauss集群的配置文件:cluster_config.xml;另外一个是openeuler的repo文件,yum源需要用到。这两个并非安装脚本内容,因此不多做介绍。安装过程和手工安装基本类似,因此下面简单描述下脚本执行的过程,供参考和指正!

1. 执行前首先创建好安装包存放的路径,下载好安装包,并且把安装的shell脚本,以及cluster_config文件,以及openeuler的repo文件,都copy到系统中的某个文件夹下,如:/opt/software/opengaussshellinstall。当然也可以通过wget下载安装包,朋友们感兴趣可以自己调整脚本。

 其中的...zhaofeng.tar文件为安装成功后需要restore的备份数据。

2. 注意安装脚本copy后可能会没有执行权限,需要执行chmod +x shell test.sh(脚本文件名),修改权限。

3. 脚本通过变量读取安装包所在的位置,因此执行命令时需要附上安装包所在的路径:

./bin/shell test.sh /opt/software/opengaussshellinstall

4. 脚本大致分为下面几部分:

4.1 检查并修改python版本;

4.2 安装三方依赖件expect, libaio等,包括脚本中用到的tar以及net-tools;

4.3 修改performance.conf文件(本步可选);

4.4 修改profile文件,增加openGauss相关的环境变量;

4.5 创建openGauss安装路径,copy安装包,cluster配置文件等到openGauss安装路径,默认为/opt/software/opengauss,可根据需要修改脚本,也可以做成变量,感兴趣可以自行调整;

4.6 修改cluster文件,替换本机ip地址及hostname,替换app, log等路径;

4.7 解压安装包;

4.8 preinstall

4.9 install

4.10 修改postgresql.conf和pg_hba.conf文件,使数据库可以被远程连接;

4.11 创建数据库,创建用户,restore之前备份的数据。

4.12 重启数据库。

如此则整个过程完成。

4.5 创建openGauss安装路径,copy安装包、cluster配置文件等到openGauss安装路径,默认为/opt/software/opengauss,可根据需要修改脚本,也可以做成变量,感兴趣可以自行调整;

4.6 修改clusterconfig.xml文件,替换本机ip地址及hostname,替换app, log等路径;

4.7 解压安装包,脚本中解压安装包和修改xml文件放在一个方法中了,注意解压完后需要对路径重置权限。

4.8 preinstall,预安装需要输入omm用户的密码;

4.9 install,安装需要输入数据库的密码;

4.10 修改postgresql.conf和pg_hba.conf文件,使数据库可以被远程连接,此处为了简单起见,添加0.0.0.0/0以及‘*’;

4.11 创建数据库,创建用户,restore之前备份的数据。

4.12 重启数据库。

如此则整个过程完成。

以下为附件内容:

  • cluster_config.txt


    <PARAM name="gaussdbLogPath" value="/var/log/omm" />
    <PARAM name="tmpMppdbPath" value="/opt/huawei/tmp"/>
    <PARAM name="gaussdbToolPath" value="/opt/huawei/install/om" />
    <PARAM name="corePath" value="/opt/huawei/corefile"/>
    <PARAM name="backIp1s" value="opengausshostip"/>
  </CLUSTER>
  <DEVICELIST>
    <DEVICE sn="opengausshostname">
      <PARAM name="name" value="opengausshostname"/>
      <PARAM name="azName" value="AZ1"/>
      <PARAM name="azPriority" value="1"/>

      <PARAM name="backIp1" value="opengausshostip"/>
      <PARAM name="sshIp1" value="opengausshostip"/>
      <!-- dn -->
      <PARAM name="dataNum" value="1"/>
      <PARAM name="dataPortBase" value="26100"/>
      <PARAM name="dataNode1" value="/opt/huawei/install/data/dn"/>
      <PARAM name="dataNode1_syncNum" value="0"/>
    </DEVICE>
  </DEVICELIST>
</ROOT>

  • openGauss.sh

#!/bin/bash

gauss_home=$1


echo "------$gauss_home -----------"
if [ ! -d $gauss_home ]; then
    echo -e "\033[31m   请输入安装路径     \033[0m"
    exit
fi

python_version=`python -V 2>&1|awk '{print $2}'|awk -F '.' '{print $1}'`

function PythonVersionChange() {
    echo " ======= python version : ${python_version} ======== "
    if [ $python_version -eq 2 ]; then
        echo -e "\e[32m ======== change python version  ======== \e[0m"
        cd /usr/bin
        mv python python.bak
        ln -s python3 /usr/bin/python
        now_pyhton_version=`python -V 2>&1|awk '{print $2}'|awk -F '.' '{print $1}'`
        echo -e "\e[32m ======== now python version $now_pyhton_version ======== \e[0m"
    fi
}

echo -e "\e[37m ======== install  3rd software(s)  ======== \e[0m"
echo "-------copy yum repo-------"
cp /opt/software/openEulerOS.repo /etc/yum.repos.d/
echo "-------install nettools & tar -------"
yum -y install tar
yum -y install net-tools
echo "-------install nettools & tar completed-------"
echo "-------install 3rd software(s)-------"
yum install libaio* -y
yum install -y bzip2 bzip2-devel curl libaio libaio-devel readline-devel
yum -y install expect

echo -e "\e[37m ======== install 3rd software(s) completed ======== \e[0m"

function PerformanceChange() {
    echo -e "\e[37m ======== sed performance  ======== \e[0m"
    sed -i "s/sysctl -w vm\.min_free_kbytes=112640/#sysctl -w vm\.min_free_kbytes=112640/" /etc/profile.d/performance.sh
    echo -e "\e[37m ======== sed performance completed  ======== \e[0m"
}

function ProfileChange() {
    echo "-------ProfileChange-------"
    echo "export packagePath=/opt/software/openGauss" >> /etc/profile
    echo 'export LD_LIBRARY_PATH=/opt/software/openGauss/script/gspylib/clib:$dddd' >> /etc/profile
    echo "-------ProfileChange completed-------"
}

ip_add=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
arrar=(`echo $ip_add | tr '\n' ' '`)
ip=${arrar[0]}

echo " ip is : $ip "

if [ ! -d /opt/software/openGauss ]; then
    mkdir -p /opt/software/openGauss
    chmod 755 -R /opt/software/openGauss
    cp /opt/software/openGauss-5.0.0-openEuler-64bit-all.tar.gz /opt/software/openGauss/
fi

chmod 755 -R /opt/software

host_name=`hostname`
#appPath=$gauss_home/openGauss/app

appPath=/opt/gaussdb/app

echo "host name is -------------------: $host_name"

data_node=/openGauss/data/db1

function CompressGauss() {
    cp /opt/software/clusterconfig.xml /opt/software/openGauss -R
   # app_path=$gauss_home/openGauss/app
    log_path=/var/log/gaussdb
   # core_path=$gauss_home/software/openGauss/corefile
   # tool_path=$gauss_home/software/openGauss/huawei/wisequery
    core_path=/opt/opengauss/corefile
    tool_path=/opt/huawei/wisequery
    echo "host name is -------------------: $appPath"
    sed -i "s/opengausshostip/$ip/g" /opt/software/openGauss/clusterconfig.xml
    sed -i "s/opengausshostname/$host_name/g" /opt/software/openGauss/clusterconfig.xml
    sed -i "s#gauss_db_app_path#$appPath#g" /opt/software/openGauss/clusterconfig.xml
    sed -i "s#gauss_db_Log_Path#$log_path#g" /opt/software/openGauss/clusterconfig.xml
    echo " -------------------: $tool_path"
    sed -i "s#gauss_db_Tool_Path#$tool_path#g" /opt/software/openGauss/clusterconfig.xml
    sed -i "s#core_Path#$core_path#g" /opt/software/openGauss/clusterconfig.xml
    sed -i "s#data_node#$data_node#g" /opt/software/openGauss/clusterconfig.xml
    cd /opt/software/openGauss
    tar -zxvf openGauss-5.0.0-openEuler-64bit-all.tar.gz
    tar zxvf openGauss-5.0.0-openEuler-64bit-om.tar.gz
    chmod -R 755 /opt/software
}

function preinstall() {
    chmod -R 755 /opt/software
    cd /opt/software/openGauss/script
    echo "----- pre install start  $(pwd)--------"
    #python gs_preinstall -U omm -G dbgrp -X /opt/software/openGauss/clusterconfig.xml
    echo -e "yes\n1qazQAZ\n1qazQAZ\n" | python gs_preinstall -U omm -G dbgrp -X /opt/software/openGauss/clusterconfig.xml
    sleep 2
}

function install() {
    echo "-------install openGauss-------"
    chmod -R 755 /opt/software/openGauss/script/
    #$gauss_home/swanlink-cloud-aiot/bin/password_input.sh
su - omm <<EOF
    cd /opt/software/openGauss/script
    echo " current : "
    gs_install -X /opt/software/openGauss/clusterconfig.xml --gsinit-parameter="--encoding=UTF8" --dn-guc="max_process_memory=4GB" --dn-guc="shared_buffers=256MB" --dn-guc="bulk_write_ring_size=256MB" --dn-guc="cstore_buffers=16MB"
exit;
EOF
}

function connectdb() {
    systemctl start firewalld.service
    firewall-cmd --zone=public --add-port=26000/tcp --permanent
    firewall-cmd --reload
    sed -i "s/listen_addresses.*/listen_addresses = '*'/" $data_node/postgresql.conf
    sed -i "s#.*$ip.*#host    all    all    0.0.0.0/0    sha256#" $data_node/pg_hba.conf
}

function createUserAndImportData() {
    su - omm <<EOF
       gsql -d postgres -p 26000 -r <<DB
          create user testuser identified by "!!$@#$ad1123";
          grant all privileges to testuser;
          create user clouduser identified by "!!$@#$ad1123";
          grant all privileges to clduser;
          create database clddb;
DB
EOF
    echo "connect"
}

function restoreData() {
    cp /opt/software/zhaofeng.tar /home/omm/
    chown omm:dbgrp /home/omm/zhaofeng.tar
    data_path=$gauss_home/package/DatabaseBackup.sql
    su - omm <<EOF
    gs_restore /home/omm/zhaofeng.tar -p 26000 -d clddb
EOF
}

function restartGSDB() {
    su - omm <<EOF
    gs_om -t restart
EOF
}

PythonVersionChange
ProfileChange
PerformanceChange
CompressGauss
preinstall
install
connectdb
createUserAndImportData
restoreData
restartGSDB
  • openEulerOS.repo.txt


[openEuler-source]
name=openEuler-source
baseurl=https://repo.huaweicloud.com/openeuler/openEuler-20.03-LTS/source/
enabled=1
gpgcheck=1
gpgkey=https://repo.huaweicloud.com/openeuler/openEuler-20.03-LTS/source/RPM-GPG-KEY-openEuler

[openEuler-os]
name=openEuler-os
baseurl=https://repo.huaweicloud.com/openeuler/openEuler-20.03-LTS/OS/x86_64/
enabled=1
gpgcheck=1
gpgkey=https://repo.huaweicloud.com/openeuler/openEuler-20.03-LTS/OS/x86_64/RPM-GPG-KEY-openEuler

[openEuler-everything]
name=openEuler-everything
baseurl=https://repo.huaweicloud.com/openeuler/openEuler-20.03-LTS/everything/x86_64/
enabled=1
gpgcheck=1
gpgkey=https://repo.huaweicloud.com/openeuler/openEuler-20.03-LTS/everything/x86_64/RPM-GPG-KEY-openEuler

[openEuler-EPOL]
name=openEuler-epol
baseurl=https://repo.huaweicloud.com/openeuler/openEuler-20.03-LTS/EPOL/x86_64/
enabled=1
gpgcheck=0

本文作者

本文内容来自于数据库领域资深技术专家赵锋老师,希望我们的文章正好能解决你的问题。

欢迎技术交流~

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐