openEuler系统通过shell脚本安装openGauss 5.0.0企业版

上次提到的开机自启动的配置,获得了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

本文作者

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

欢迎技术交流~

  • 40
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 16
    评论
OpenGauss 5.0.0是一个开源的关系型数据库管理系统,下面是集群部署的步骤: 1. 准备环境:确保所有参与集群的服务器都满足最低配置要求,并且安装了适当的操作系统和依赖项。 2. 下载并安装OpenGauss:从官方网站下载OpenGauss 5.0.0的安装包,并按照安装指南进行安装。 3. 配置OpenGauss集群:在任意一台服务器上执行集群初始化命令,例如: ``` gsql -d postgres -p 5432 -c "gaussdb -D $GAUSSHOME/data" ``` 4. 创建集群用户:使用创建集群命令创建集群用户,并设置密码: ``` gsql -d postgres -p 5432 -c "create user myuser with password 'mypass'" ``` 5. 配置集群参数:根据实际需求,修改数据库的配置文件,在OpenGauss 5.0.0中,配置文件为postgresql.conf。 6. 启动集群:在所有服务器上启动OpenGauss集群服务: ``` gs_ctl start -D $GAUSSHOME/data -M primary ``` 7. 验证集群状态:使用集群账户登录集群,并执行一些SQL语句来验证集群是否正常运行: ``` gsql -d postgres -p 5432 -U myuser -W ``` 8. 添加额外节点(可选):如果需要添加更多的节点到现有的集群中,可以执行“扩展集群”操作,具体操作步骤可以参考OpenGauss的官方文档。 9. 配置和管理集群:为了更好地管理和监控集群,可以使用OpenGauss提供的工具,如pgAdmin等。 通过以上步骤,就能成功部署一个OpenGauss 5.0.0的集群。在实际部署过程中,还需要根据实际需求和环境做适当的调整和配置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Gauss松鼠会

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值