一键部署openGauss2.1.0

2021/10/26 17:47
阅读数 148
本文档目的是为了帮助高校学生提供基于 CentOS7.6 操作系统,实现openGauss数据库一键式安装的脚本。
该脚本执行成功后,所有关于openGauss数据库的文件将保存在/gaussdb目录中。

脚本内容中“192.168.0.99”请替换为服务器实际的私有IP地址。
脚本内容中“192.168.0.99”请替换为服务器实际的私有IP地址。
脚本内容中“192.168.0.99”请替换为服务器实际的私有IP地址。

#!/bin/bash## Author:贾军锋## Date:2021-10-25## OS:       CentOS7.6 x86_64 [最小硬件配置:2c/4G]## Database:openGauss 2.1.0## Description:一键式实现操作系统环境配置、openGauss软件下载、openGauss软件安装等步骤,帮助大家提升安装openGauss数据库效率## Tips:     请确保操作系统符合要求并且可以连接外网

## 0.关闭virbr0网卡 [本地虚拟机标准化安装openEuler系统会默认存在virbr0网卡,删除该网卡以避免干扰数据库的安装]## virsh net-destroy default## virsh net-list## echo "Net device virbr0 is disabled."

## 1.定义主机信息[请根据实际情况修改]export MY_HOSTNAME=node1 ## 主机名export MY_HOSTIP=192.168.0.99 ## IP地址export MY_SOFTWARE_DIRECTORY=/soft/openGauss ## 软件包所在目录export MY_XML=/soft/openGauss/clusterconfig.xml ## 集群配置文件XMLexport openGauss_Download_url=https://opengauss.obs.cn-south-1.myhuaweicloud.com/2.1.0/x86/openGauss-2.1.0-CentOS-64bit-all.tar.gz ## openGauss软件包下载地址

## 1. 设置主机名并配置hosts文件hostnamectl set-hostname $MY_HOSTNAMEsed -i '/$MY_HOSTIP/d' /etc/hostsecho "$MY_HOSTIP $MY_HOSTNAME #Gauss OM IP Hosts Mapping" >> /etc/hostscat /etc/hostsecho "1.Configure /etc/hosts completed."echo -e "\n"

## 2. 关闭防火墙systemctl disable firewalld.servicesystemctl stop firewalld.serviceecho "Firewalld " `systemctl status firewalld|grep Active`echo "2.Disable firewalld service completed."echo -e "\n"

## 3. 关闭SELinuxsed -i '/^SELINUX=/d' /etc/selinux/configecho "SELINUX=disabled" >> /etc/selinux/configcat /etc/selinux/config|grep "SELINUX=disabled"echo "3.Disable SELINUX completed."echo -e "\n"

## 4. 设置操作系统字符集编码echo "LANG=en_US.UTF-8" >> /etc/profilesource /etc/profileecho $LANGecho "4.Configure encoding completed."echo -e "\n"

## 5. 设置操作系统时区rm -fr /etc/localtimeln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtimedate -Rhwclockecho "5.Configure Timezone completed."echo -e "\n"

## 6. 关闭SWAP分区 [对于2G内存的设备,建议待安装完毕后再打开SWAP以间接 “扩容内存容量”]sed -i '/swap/s/^/#/' /etc/fstabswapoff -afree -mecho "6.Close swap partition completed."echo -e "\n"

## 7. 配置SSH服务,关闭Banner,允许root远程登录sed -i '/Banner/s/^/#/' /etc/ssh/sshd_configsed -i '/PermitRootLogin/s/^/#/' /etc/ssh/sshd_configecho -e "\n" >> /etc/ssh/sshd_configecho "Banner none " >> /etc/ssh/sshd_configecho "PermitRootLogin yes" >> /etc/ssh/sshd_configcat /etc/ssh/sshd_config |grep -v ^#|grep -E 'PermitRoot|Banner'echo "7.Configure SSH Service completed."echo -e "\n"

## 8. 配置YUM源、安装依赖包、修改默认Python3版本mkdir /etc/yum.repos.d/bakmv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repoyum clean allyum install -y wget bzip2 python3yum install -y libaio-devel flex bison ncurses-devel glibc-devel patch redhat-lsb-core readline-devel net-tools tarmv /usr/bin/python /usr/bin/python2_bakln -s /usr/bin/python3 /usr/bin/pythonpython -Vecho "8.Configure Install Packages and change default Python version completed."echo -e "\n"

## 9. 配置 sysctl.conf 和 performance.shcat >> /etc/sysctl.conf << EOFnet.ipv4.tcp_retries1 = 5net.ipv4.tcp_syn_retries = 5net.sctp.path_max_retrans = 10net.sctp.max_init_retransmits = 10EOFsysctl -pecho "9.Configure sysctl.conf and performance.sh completed."echo -e "\n"

## 10. 配置资源限制echo "* soft stack 3072" >> /etc/security/limits.confecho "* hard stack 3072" >> /etc/security/limits.confecho "* soft nofile 1000000" >> /etc/security/limits.confecho "* hard nofile 1000000" >> /etc/security/limits.confecho "* soft nproc unlimited" >> /etc/security/limits.d/90-nproc.conftail -n 4 /etc/security/limits.conftail -n 1 /etc/security/limits.d/90-nproc.confecho "10.Configure resource limits completed."echo -e "\n"

## 11. 关闭透明大页[Only for CentOS]cat >>/etc/rc.d/rc.local<<EOFif test -f /sys/kernel/mm/transparent_hugepage/enabled; then echo never > /sys/kernel/mm/transparent_hugepage/enabledfiif test -f /sys/kernel/mm/transparent_hugepage/defrag; then echo never > /sys/kernel/mm/transparent_hugepage/defragfiEOFchmod +x /etc/rc.d/rc.local/usr/bin/sh /etc/rc.d/rc.localcat /sys/kernel/mm/transparent_hugepage/enabledcat /sys/kernel/mm/transparent_hugepage/defragecho "11.Close transparent_hugepage completed."echo -e "\n"

## 12. 禁用RemoveIPC[Only for openEuler]## sed -i '/^RemoveIPC/d' /etc/systemd/logind.conf## sed -i '/^RemoveIPC/d' /usr/lib/systemd/system/systemd-logind.service## echo "RemoveIPC=no" >> /etc/systemd/logind.conf## echo "RemoveIPC=no" >> /usr/lib/systemd/system/systemd-logind.service## systemctl daemon-reload## systemctl restart systemd-logind## loginctl show-session | grep RemoveIPC## systemctl show systemd-logind | grep RemoveIPC## echo "12.Disable RemoveIPC completed."## echo -e "\n"

## 13. 下载openGauss软件包mkdir -p $MY_SOFTWARE_DIRECTORYcd $MY_SOFTWARE_DIRECTORYwget $openGauss_Download_urlecho "13.openGauss software download completed."echo -e "\n"

## 14. 配置XML文件rm -fr $MY_XMLcat >> $MY_XML <<EOF<?xml version="1.0" encoding="UTF-8"?> <ROOT> <!-- openGauss整体信息 --> <CLUSTER> <PARAM name="clusterName" value="dbCluster" /> <PARAM name="nodeNames" value="$MY_HOSTNAME" /> <PARAM name="backIp1s" value="$MY_HOSTIP"/> <PARAM name="gaussdbAppPath" value="/gaussdb/app" /> <PARAM name="gaussdbLogPath" value="/gaussdb/log" /> <PARAM name="gaussdbToolPath" value="/gaussdb/om" /> <PARAM name="corePath" value="/gaussdb/corefile"/> <PARAM name="clusterType" value="single-inst"/> </CLUSTER> <!-- 每台服务器上的节点部署信息 --> <DEVICELIST> <!-- node1上的节点部署信息 --> <DEVICE sn="1000001"> <PARAM name="name" value="$MY_HOSTNAME"/> <PARAM name="azName" value="AZ1"/> <PARAM name="azPriority" value="1"/> <!-- 如果服务器只有一个网卡可用,将backIP1和sshIP1配置成同一个IP --> <PARAM name="backIp1" value="$MY_HOSTIP"/> <PARAM name="sshIp1" value="$MY_HOSTIP"/> <!--dbnode--> <PARAM name="dataNum" value="1"/> <PARAM name="dataPortBase" value="26000"/> <PARAM name="dataNode1" value="/gaussdb/data/db1"/> </DEVICE> </DEVICELIST> </ROOT>EOFcat $MY_XMLecho "14.Configure XML file completed."echo -e "\n"

## 15. 解压安装包并修改目录权限echo "Begin to Uncompress openGauss Package and Modify directory permissions:"cd $MY_SOFTWARE_DIRECTORYtar -zxvf *all.tar.gztar -zxvf *om.tar.gzls -lchmod -R 777 $MY_SOFTWARE_DIRECTORY/../echo "15.Uncompress openGauss Package completed."echo -e "\n"

## 16. 执行 gs_preinstallecho "Begin to execute openGauss preinstall:"python $MY_SOFTWARE_DIRECTORY/script/gs_preinstall -U omm -G dbgrp -X $MY_XMLecho "16.openGauss preinstall completed."echo -e "\n"

## 17. 检查预安装环境echo "Begin to Check OS environment:"$MY_SOFTWARE_DIRECTORY/script/gs_checkos -i A -h $MY_HOSTNAME --detail

## 18. 执行 gs_installecho "Begin to execute openGauss install:"touch /home/omm/install_dbcat >> /home/omm/install_db <<EOFsource ~/.bashrcgs_install -X $MY_XML --gsinit-parameter="--encoding=UTF8" --dn-guc="max_process_memory=3GB" --dn-guc="shared_buffers=128MB" --dn-guc="cstore_buffers=16MB"EOFchown -R omm:dbgrp /home/omm/install_dbsu - omm -c "sh /home/omm/install_db"echo "17.openGauss install completed."echo -e "\n"

## 安装完毕!echo "openGauss Install completed.congratulations"echo "Congratulations!!!"


- END -

欢迎访问openGauss官方网站

openGauss开源社区官方网站:

https://opengauss.org

openGauss组织仓库:

https://gitee.com/opengauss

openGauss镜像仓库:

https://github.com/opengauss-mirror

扫码关注我们

微信公众号|openGauss

微信社群小助手|openGauss-bot

本文分享自微信公众号 - openGauss(openGauss)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
1 收藏
0
分享
返回顶部
顶部