# 部署 openGauss 数据库# 部署环境openGauss 安装包下载openGauss官网 openGaus数据库官方网站
此处下载的部署包版本如下
NAME="openEuler" VERSION="22.03 LTS" ID="openEuler" VERSION_ID="22.03" PRETTY_NAME="openEuler 22.03 LTS" ANSI_COLOR="0;31"
Linux localhost.localdomain 5.10.0-60.118.0.145.oe2203.x86_64 #1 SMP Wed Nov 29 06:40:40 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
# 部署环境配置安装依赖 安装 python 依赖需要安装版本 3.4 以上,不然后续部署集群是安装脚本会存在依赖报错
yum安装依赖 1 2 3 4 function install_package (){ echo "-------------------- Install OpenGauss dependencies --------------------" yum install -y libaio-devel* flex* bison* ncurses-devel* glibc-devel* patch* readline-devel* expect ntp tar python3-devel* python3* lksctp* || { echo "OpenGauss Dependent package installation failed........" ;exit 1; } }
关闭防火墙与selinux 目前 openGauss 仅支持在防火墙关闭的状态下进行安装
关闭防火墙 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 function close_firewalld (){ echo "-------------------- Install OpenGauss close firewalld --------------------" systemctl stop firewalld systemctl disable firewalld } `` ``Bash 关闭selinux function closeSelinux (){ selinux_status=`getenforce` if [ $selinux_status == "Enforcing" ] ;then echo "Warning:Please close selinux" echo "set SELINUX=disabled in /etc/selinux/config and reboot" echo "set SELINUX=disabled in /etc/selinux/config and reboot" echo "set SELINUX=disabled in /etc/selinux/config and reboot" sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config exit 1 elif [ $selinux_status == "Permissive" ];then echo "Warning:Please close selinux" echo "set SELINUX=disabled in /etc/selinux/config and reboot" echo "set SELINUX=disabled in /etc/selinux/config and reboot" echo "set SELINUX=disabled in /etc/selinux/config and reboot" sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config exit 1 fi }
修改host与hostname
配置host 1 2 3 4 5 6 7 8 function hosts_config (){ hostname="openGauss-" $(uuidgen | cut -d'-' -f5) echo ${hostname} echo "127.0.0.1" ${hostname} > /etc/hosts echo ${hostname} > /etc/hostname hostnamectl set-hostname ${hostname} }
基本参数设置
设置字符集参数 1 2 3 4 5 function lang_config (){ echo "-------------------- Install OpenGauss Config Lang --------------------" echo LANG=en_US.UTF-8 >> /etc/profile source /etc/profile }
文件句柄数设置 1 2 3 4 5 function file_handle_setting (){ echo "-------------------- Install OpenGauss File handle setting --------------------" echo "* soft nofile 1000000" >>/etc/security/limits.conf echo "* hard nofile 1000000" >>/etc/security/limits.conf }
使用 timedatectl 命令查询时区是否需要修改
设置时区参数 1 2 3 4 function timezone_config (){ echo "-------------------- Install OpenGauss Config Timezone --------------------" timedatectl set-timezone Asia/Shanghai }
修改Banner配置与透明大页 系统提示的欢迎信息会干扰安装时远程操作的返回结果,影响安装正常执行
修改Banner配置 1 2 3 4 5 function close_banner (){ echo "-------------------- Install OpenGauss close banner --------------------" sed -i 's/^Banner/#&/' /etc/ssh/sshd_config systemctl restart sshd }
关闭透明大页 1 2 3 4 5 6 7 function close_transparent_hugepage (){ echo "-------------------- Install OpenGauss close transparent huaepage --------------------" echo never > /sys/kernel/mm/transparent_hugepage/defrag echo never > /sys/kernel/mm/transparent_hugepage/enabled echo 'echo never > /sys/kernel/mm/transparent_hugepage/defrag' >> /etc/rc.d/rc.local echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.d/rc.local }
配置资源限制
配置资源限制 1 2 3 4 5 6 7 8 function config_resource_limt (){ echo "-------------------- Install OpenGauss config resource limit --------------------" 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 }
解压安装包
解压安装包 1 2 3 4 5 6 7 8 9 10 11 12 13 14 function unzip_opengauss_package (){ echo "-------------------- Install OpenGauss unzip opengauss package --------------------" mkdir -p /opt/openGauss5.0 tar -zxvf $installPath /openGauss-5.0.0-openEuler-64bit-all.tar.gz -C /opt/openGauss5.0 cd /opt/openGauss5.0 tar -zxvf openGauss-5.0.0-openEuler-64bit-om.tar.gz mkdir -p /opt/openGauss5.0/my_script cp -r /opt/openGauss5.0/script/* /opt/openGauss5.0/my_script cp $installPath /cluster_config.xml /opt/openGauss5.0 sed -i "s/\[hostname\]/${hostname} /g" /opt/openGauss5.0/cluster_config.xml sed -i "s/\[dbPort\]/${dbPort} /g" /opt/openGauss5.0/cluster_config.xml chmod -R 777 /opt/openGauss5.0 }
命令中的 $installPath/cluster_config.xml 为高斯数据库集群配置文件
集群配置文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 <?xml version="1.0" encoding="UTF-8" ?> <ROOT > <CLUSTER > <PARAM name ="clusterName" value ="dbCluster" /> <PARAM name ="nodeNames" value ="[hostname]" /> <PARAM name ="gaussdbAppPath" value ="/opt/openGauss5.0/install/app" /> <PARAM name ="gaussdbLogPath" value ="/var/log/omm" /> <PARAM name ="tmpMppdbPath" value ="/opt/openGauss5.0/tmp" /> <PARAM name ="gaussdbToolPath" value ="/opt/openGauss5.0/install/om" /> <PARAM name ="corePath" value ="/opt/openGauss5.0/corefile" /> <PARAM name ="backIp1s" value ="127.0.0.1" /> </CLUSTER > <DEVICELIST > <DEVICE sn ="[hostname]" > <PARAM name ="name" value ="[hostname]" /> <PARAM name ="azName" value ="AZ1" /> <PARAM name ="azPriority" value ="1" /> <PARAM name ="backIp1" value ="127.0.0.1" /> <PARAM name ="sshIp1" value ="127.0.0.1" /> <PARAM name ="dataNum" value ="1" /> <PARAM name ="dataPortBase" value ="[dbPort]" /> <PARAM name ="dataNode1" value ="/opt/openGauss5.0/install/data/dn" /> <PARAM name ="dataNode1_syncNum" value ="0" /> </DEVICE > </DEVICELIST > </ROOT >
# 数据库预安装创建数据库用户 为了实现安装过程中安装帐户权限最小化,及安装后 openGauss 的系统运行安全性,安装脚本在安装过程中会自动按照用户指定内容创建安装用户,并将此用户作为后续运行和维护 openGauss 的管理员帐户。
变量 ommGrp、ommUser、ommPassword 可以在脚本开始进行自定义
创建数据库用户 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 function add_gaussdb_usr_group (){ echo "-------------------- Install OpenGauss Add UsrGroup and User --------------------" groupadd -g 5001 $ommGrp useradd -u 5001 -g $ommGrp $ommUser chown -R omm:dbgrp /opt/openGauss5.0 expect <<! spawn passwd $ommUser expect "*新的密码*" send "${ommPassword} \r" expect "*输入新的密码*" send "${ommPassword} \r" expect eof ! }
数据库预安装
执行预安装脚本 1 2 3 4 function pre_install (){ echo "-------------------- Install OpenGauss pre install --------------------" /opt/openGauss5.0/script/gs_preinstall -U omm -G dbgrp -X /opt/openGauss5.0/cluster_config.xml }
# 数据库安装数据库安装
预安装脚本 1 2 3 4 5 6 7 8 function install (){ echo "-------------------- Install OpenGauss install --------------------" cd /opt/openGauss5.0/script mkdir -p /opt/openGauss5.0/backup chmod -R 755 /opt/openGauss5.0 chown -R omm:dbgrp /opt/openGauss5.0 su - omm -c "/opt/openGauss5.0/script/gs_install -X /opt/openGauss5.0/cluster_config.xml" }
查看状态
检查系统环境 1 2 3 function check (){ su - omm -c "/opt/openGauss5.0/script/gs_checkos -i A -h pg-node01 --detail" }
在上述的执行脚本中,gs_preinstall 与 gs_install 执行中都需要手动输入数据库密码,如果想要做的一键执行,去除交互的话可以使用 Linux 中的 expect -f 用法