fast install for openGauss

This commit is contained in:
lishifu_db
2021-03-28 23:07:26 +08:00
parent 28934bcdfa
commit 1c21cecfb2
4 changed files with 409 additions and 526 deletions

View File

@ -1,154 +1,113 @@
## 1 概述
本章节主要介绍采用openGauss简安装脚本(以下简称安装脚本),一键式安装openGauss数据库所必须的系统环境及安装步骤。
## 2 安装环境要求
### 2.1 openGauss环境要求
安装openGauss的具体环境要求,请参考《openGauss安装指南》中的“2.3.1节软硬件环境要求”章节。
### 2.2 安装脚本环境要求
#### 硬件环境要求
安装脚本对安装环境的操作系统及对应处理器架构进行了限制,目前支持的环境如表1所示。
**表1** 硬件环境要求
| 操作系统 | 处理器架构 |
| --------- | ---------- |
| openEuler | aarch64 |
| openEuler | x86_64 |
| CentOS | x86_64 |
#### 软件依赖要求
安装脚本依赖于其它软件的支持,如表2所示。
**表2** 软件依赖要求
| 所需软件 | 建议版本 |
| --------- | -------- |
| firewalld | - |
| python | 3 |
## 3 安装openGauss
### 3.1 安装前准备
#### 导入安装脚本
安装脚本包含了多个文件,其用途如表3所示。导入安装脚本时,建议直接导入tar包至安装环境中,随后在安装环境中进行解压,否则可能出现window与unix风格不兼容的问题。若出现此类问题,可以使用dos2unix命令对安装脚本进行格式转换。
**表3** 安装脚本清单
| 文件名称 | 用途 |
| ------------ | ---------------------- |
| install.sh | 简化安装主程序 |
| common.sh | 公共命令 |
| README.md | 参考文档 |
| template.xml | xml模板 |
| finance.sql | 金融数据模型展示数据库 |
| school.sql | 学校数据模型展示数据库 |
#### 导入openGauss数据库安装包
安装脚本支持以下两种方式导入openGauss数据库安装包:
- 手动导入
在[openGauss官网](https://opengauss.org/zh/download.html)下载对应版本安装包拷贝至安装环境中,存放路径为安装脚本的上层目录。
- 自动导入
配置安装环境外网访问,并确保安装脚本上层路径不存在openGauss数据库安装包。当运行安装脚本时,会自动下载对应版本安装包进行安装。
### 3.2 执行安装
使用如下命令执行安装脚本。
```shell
sh install.sh -U user_name -G user_group -h host_ip -p port [-D install_path]
```
#### 参数说明
- user_name为openGauss数据库的安装用户。
- user_group为openGauss数据库安装用户所属用户组。
- host_ip为主机在后端存储网络中的IP地址(内网IP)。
- host_port为数据库节点的基础端口号。
- install_path为openGauss数据库安装路径,该参数为可选参数。
以上参数的详细信息,请参考《openGauss安装指南》中的3.1节创建XML配置文件。
#### 注意事项
- 不指定install_path参数时,数据库默认安装在/opt/user_name路径下。
- 无论采用何种方式导入openGauss安装包,安装脚本都会在/home/user_name/openGaussTar路径下建立本地安装包文件。该路径支持修改,请在install.sh中修改install_location参数,但是需要与安装路径install_path不同。
- 安装脚本必须在root下执行,且同一时刻只有1个安装脚本正在运行。
## 4 导入展示数据库
### 4.1 学校数据模型
假设A市B学校为了加强对学校的管理,引入了openGauss数据库。在B学校里,主要涉及的对象有学生、教师、班级、院系和课程。本实验假设在B学校数据库中,教师会教授课程,学生会选修课程,院系会聘请教师,班级会组成院系,学生会组成班级。因此,根据此关系,本文给出了相应的关系模式如下。在运行安装脚本时,会根据用户选择安装该展示模型。
#### 关系模式
对于B校中的5个对象,分别建立属于每个对象的属性集合,具体属性描述如下:
- 学生(学号,姓名,性别,出生日期,入学日期,家庭住址
- 教师(教师编号,教师姓名,职称,性别,年龄,入职日期
- 班级(班级编号,班级名称,班主任
- 院系(系编号,系名称,系主任
- 课程(课程编号,课程名称,课程类型,学分)
上述属性对应的编号为:
- student(std_id,std_name,std_sex,std_birth,std_in,std_address)
- teacher(tec_id,tec_name,tec_job,tec_sex,tec_age,tec_in)
- class(cla_id,cla_name,cla_teacher)
- school_department(depart_id,depart_name,depart_teacher)
- course(cor_id,cor_name,cor_type,credit)
对象之间的关系:
- 一位学生可以选择多门课程,一门课程可被多名学生选择
- 一位老师可以选择多门课程,一门课程可被多名老师教授
- 一个院系可由多个班级组成
- 一个院系可聘请多名老师
- 一个班级可由多名学生组成
### 4.2 金融数据模型
假设A市C银行为了方便对银行数据的管理和操作,引入了openGauss数据库。针对C银行的业务,本实验主要将对象分为客户、银行卡、理财产品、保险、基金和资产。因此,针对这些数据库对象,本实验假设C银行的金融数据库存在着以下关系:客户可以办理银行卡,同时客户可以购买不用的银行产品,如资产,理财产品,基金和保险。那么,根据C银行的对象关系,本文给出了相应的关系模式如下。在运行安装脚本时,会根据用户选择安装该展示模型。
#### 关系模式
对于C银行中的6个对象,分别建立属于每个对象的属性集合,具体属性描述如下:
- 客户(客户编号、客户名称、客户邮箱,客户身份证,客户手机号,客户登录密码)
- 银行卡(银行卡号,银行卡类型,所属客户编号)
- 理财产品(产品名称,产品编号,产品描述,购买金额,理财年限)
- 保险(保险名称,保险编号,保险金额,适用人群,保险年限,保障项目)
- 基金(基金名称,基金编号,基金类型,基金金额,风险等级,基金管理者)
- 资产(客户编号,商品编号,商品状态,商品数量,商品收益,购买时间)
上述属性对应的编号为:
- client(c_id,c_name,c_mail,c_id_card,c_phone,c_password)
- bank_card(b_number,b_type,b_c_id)
- finances_product(p_name,p_id,p_description,p_amount,p_year)
- insurance(i_name,i_id,i_amount,i_person,i_year,i_project)
- fund(f_name,f_id,f_type,f_amount,risk_level,f_manager)
- property(pro_c_id,pro_id,pro_status,pro_quantity,pro_income,pro_purchase_time)
对象之间的关系:
- 一个客户可以办理多张银行卡
- 一个客户可有多笔资产
- 一个客户可以购买多个理财产品,同一类理财产品可由多个客户购买
- 一个客户可以购买多个基金,同一类基金可由多个客户购买
- 一个客户可以购买多个保险,同一类保险可由多个客户购买
## 1 概述
本章节主要介绍采用openGauss简安装脚本(以下简称安装脚本),一键式安装openGauss数据库所必须的系统环境及安装步骤。
## 2 安装环境要求
### 2.1 openGauss环境要求
安装openGauss的具体环境要求,请参考《openGauss安装指南》中的“软硬件环境要求”章节。
### 2.2 安装脚本环境要求
#### 硬件环境要求
安装脚本对安装环境的操作系统及对应处理器架构进行了限制,目前支持的环境如表1所示。
**表1** 硬件环境要求
| 操作系统 | 处理器架构 |
| --------- | ---------- |
| openEuler | aarch64 |
| openEuler | x86_64 |
| CentOS | x86_64 |
## 3 安装openGauss
### 执行安装
使用如下命令执行单节点安装脚本。
```shell
sh install.sh -w password
```
使用如下命令执行一主一备安装脚本。
```shell
sh install.sh -w password --multinode
```
#### 参数说明
- [-w password] gs_initdb password, this argument is necessary for installation
- [-p port] port of openGauss single node, or master node; default value is 5432
- [--multinode] install one master and one slave openGauss node
以上参数的详细信息,请参考《openGauss安装指南》.
## 4 导入展示数据库
### 4.1 学校数据模型
假设A市B学校为了加强对学校的管理,引入了openGauss数据库。在B学校里,主要涉及的对象有学生、教师、班级、院系和课程。本实验假设在B学校数据库中,教师会教授课程,学生会选修课程,院系会聘请教师,班级会组成院系,学生会组成班级。因此,根据此关系,本文给出了相应的关系模式如下。在运行安装脚本时,会根据用户选择安装该展示模型。
#### 关系模式
对于B校中的5个对象,分别建立属于每个对象的属性集合,具体属性描述如下:
- 学生(学号,姓名,性别,出生日期,入学日期,家庭住址)
- 教师(教师编号,教师姓名,职称,性别,年龄,入职日期)
- 班级(班级编号,班级名称,班主任)
- 院系(系编号,系名称,系主任)
- 课程(课程编号,课程名称,课程类型,学分)
上述属性对应的编号为:
- student(std_id,std_name,std_sex,std_birth,std_in,std_address)
- teacher(tec_id,tec_name,tec_job,tec_sex,tec_age,tec_in)
- class(cla_id,cla_name,cla_teacher)
- school_department(depart_id,depart_name,depart_teacher)
- course(cor_id,cor_name,cor_type,credit)
对象之间的关系:
- 一位学生可以选择多门课程,一门课程可被多名学生选择
- 一位老师可以选择多门课程,一门课程可被多名老师教授
- 一个院系可由多个班级组成
- 一个院系可聘请多名老师
- 一个班级可由多名学生组成
### 4.2 金融数据模型
假设A市C银行为了方便对银行数据的管理和操作,引入了openGauss数据库。针对C银行的业务,本实验主要将对象分为客户、银行卡、理财产品、保险、基金和资产。因此,针对这些数据库对象,本实验假设C银行的金融数据库存在着以下关系:客户可以办理银行卡,同时客户可以购买不用的银行产品,如资产,理财产品,基金和保险。那么,根据C银行的对象关系,本文给出了相应的关系模式如下。在运行安装脚本时,会根据用户选择安装该展示模型。
#### 关系模式
对于C银行中的6个对象,分别建立属于每个对象的属性集合,具体属性描述如下:
- 客户(客户编号、客户名称、客户邮箱,客户身份证,客户手机号,客户登录密码)
- 银行卡(银行卡号,银行卡类型,所属客户编号)
- 理财产品(产品名称,产品编号,产品描述,购买金额,理财年限)
- 保险(保险名称,保险编号,保险金额,适用人群,保险年限,保障项目)
- 基金(基金名称,基金编号,基金类型,基金金额,风险等级,基金管理者)
- 资产(客户编号,商品编号,商品状态,商品数量,商品收益,购买时间)
上述属性对应的编号为:
- client(c_id,c_name,c_mail,c_id_card,c_phone,c_password)
- bank_card(b_number,b_type,b_c_id)
- finances_product(p_name,p_id,p_description,p_amount,p_year
- insurance(i_name,i_id,i_amount,i_person,i_year,i_project
- fund(f_name,f_id,f_type,f_amount,risk_level,f_manager
- property(pro_c_id,pro_id,pro_status,pro_quantity,pro_income,pro_purchase_time
对象之间的关系:
- 一个客户可以办理多张银行卡
- 一个客户可有多笔资产
- 一个客户可以购买多个理财产品,同一类理财产品可由多个客户购买
- 一个客户可以购买多个基金,同一类基金可由多个客户购买
- 一个客户可以购买多个保险,同一类保险可由多个客户购买

View File

@ -1,45 +0,0 @@
if [ "$COMMON_SH" ]; then
return;
fi
function fn_create_user()
{
user_name=$1
user_grp=$2
groupadd $user_grp 2>/dev/null
egrep "^$user_name" /etc/passwd >& /dev/null
if [ $? -ne 0 ]
then
useradd -g $user_grp -d /home/$user_name -m -s /bin/bash $user_name 2>/dev/null
echo "enter password for user " $user_name
passwd $user_name
echo "create user success."
else
echo "user has already exists."
fi
return 0
}
function fn_check_firewall()
{
host_port=$1
firewall-cmd --permanent --add-port="$host_port/tcp"
firewall-cmd --reload
return 0
}
function fn_selinux()
{
sed -i "s/SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config
return 0
}
function fn_swapoff()
{
# 关闭交换内存
swapoff -a
return 0
}
COMMON_SH="common.sh"

View File

@ -1,273 +1,311 @@
#!/bin/bash
# -*- coding:utf-8 -*-
#############################################################################
# Copyright (c): 2021, Huawei Tech. Co., Ltd.
# FileName : install.py
# Version : V1.0.0
# Date : 2021-03-15
# Description : the scripy used to install the single cluster on one machine
#########################################
readonly cur_path=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd && cd - &>/dev/null)
source $cur_path"/common.sh"
function fn_print_help()
function usage()
{
echo "Usage: $0 [OPTION]
-?|--help show help information
-U|--user_name cluster user
-G|--user_grp group of the cluster user
-h|--host_ip intranet IP address of the host in the backend storage network
-p|--port database server port
-D|--install_location installation directory of the openGauss program
"
echo "
Usage: sh $0 -w password
Arguments:
-w login password
-p datanode port, default 5432
--multinode if specify, will install master_slave cluster. default install single node.
-h, --help Show this help, then exit
"
}
function fn_get_param()
function info()
{
fn_prase_input_param $@
host_name=`hostname -f`
system_arch=`uname -p`
system_name=`cat /etc/os-release | grep '^ID=".*' | grep -o -E '(openEuler|centos)'`
install_tar="/home/$user_name/openGaussTar" #安装包所在路径(可修改)
if [ ! $install_location ]
then
install_location="/opt/$user_name" #数据库安装位置(可修改)
echo -e "\033[32m$1\033[0m"
}
function error() {
echo -e "\033[31m$1:\033[0m"
}
function check_param() {
if [ X$password == X'' ]; then
error "ERROR: The parameter '-w' can not be empty\n"
usage
exit 1
fi
if [ X$user == X"root" ]; then
error "Error: can not install openGauss with root"
exit 1
fi
if [ X$port == X"" ]; then
port=$default_port
fi
if [ X$mode == X"master_standby" ]; then
let slave_port=$port+200
fi
}
function fn_prase_input_param()
{
while [ $# -gt 0 ]; do
case $1 in
-\?|--help )
fn_print_help
exit 1
;;
-U|--user_name )
fn_check_param user_name $2
user_name=$2
shift 2
;;
-G|--user_grp )
fn_check_param user_grp $2
user_grp=$2
shift 2
;;
-h|--host_ip )
fn_check_param host_ip $2
host_ip=$2
shift 2
;;
-p|--port )
fn_check_param port $2
host_port=$2
shift 2
;;
-D|--install_location )
fn_check_param install_location $2
install_location=$2
shift 2
;;
* )
echo "Please input right paramtenter, the following command may help you"
echo "sh install.sh --help or sh install.sh -?"
exit 1
esac
done
}
function fn_check_param()
{
if [ "$2"X = X ]
function check_install_env() {
# check pgxc path
if [ X$mode == X"single" ]
then
echo "no given $1, the following command may help you"
echo "sh install.sh --help or sh install.sh -?"
if [ -d "$app/data/single_node" ] && [ X"$(ls -A $app/data/single_node)" != X"" ]
then
error "ERROR: the directory $app/data/single_node must be dir and empty"
exit 1
fi
else
for pgxc in $(echo "master slave" | awk '{print $1,$2}')
do
if [ -d "$app/data/$pgxc" ] && [ X"$(ls -A $app/data/$pgxc)" != X"" ]
then
error "ERROR: the directory $app/data/master or $app/data/slave must be dir and empty"
exit 1
fi
done
fi
# check pid port and lock file
port_occupied=$(netstat -ntul | grep $port)
if [ X"$port_occupied" != X"" ]; then
error "Error: The port $port has been occupied, please use -p to set a new port."
exit 1
fi
local delete_slave_lock=""
local delete_master_lock=""
if [ X$slave_port != X"0" ]; then
slave_occupied=$(netstat -ntul | grep $slave_port)
delete_slave_lock=$(rm -rf /tmp/.s.PGSQL.$slvae_port* 2>&1)
if [ X"$slave_occupied" != X"" ]; then
error "Error: The slave port $slave_port has been occupied, please use -p to set a new port."
exit 1
fi
fi
delete_master_lock=$(rm -rf /tmp/.s.PGSQL.$port* 2>&1)
if [[ $delete_master_lock == *"Operation not permitted"* ]] || [[ $delete_slave_lock == *"Operation not permitted"* ]]; then
error "Error: not have permitted to delete /tmp/.s.PGSQL.* file, you should delete it or change port."
exit 1
fi
}
function fn_get_openGauss_tar()
{
mkdir -p "$install_tar" 2>/dev/null
chown -R $user_name:$user_grp "$install_tar"
if [ "$system_name" == "openEuler" ] && [ "$system_arch" == "aarch64" ]
then
system_arch="arm"
elif [ "$system_name" == "openEuler" ] && [ "$system_arch" == "x86_64" ]
then
system_arch="x86"
elif [ "$system_name" == "centos" ] && [ "$system_arch" == "x86_64" ]
then
system_name="CentOS"
system_arch="x86"
else
echo "We only support CentOS+x86, openEuler+arm and openEuler+x86 by now."
return 1
function check_os() {
# check shm
local shared_buffers=1073741824 # 1G
local shmmax=$(cat /proc/sys/kernel/shmmax)
env test $shared_buffers -gt $shmmax && echo "Shared_buffers must be less than shmmax. Please check it." && exit 1
local shmall=$(cat /proc/sys/kernel/shmall)
local pagesize=$(getconf PAGESIZE)
if [ $(($shared_buffers/1024/1024-$shmall/1024/1024*$pagesize)) -gt 0 ]; then
echo "The usage of the device [Shared_buffers] space cannot be greater than shmall*PAGESIZE." && exit 1
fi
if [ "`find $cur_path/../ -maxdepth 1 -name "openGauss-1.0.1*tar.gz"`" == "" ]
then
cd "$install_tar"
if [ "`find . -maxdepth 1 -name "openGauss-1.0.1*tar.gz"`" == "" ]
# check sem
local -a sem
local -i index=0
local max_connection=5000
local conn_floor
for line in $(cat /proc/sys/kernel/sem)
do
sem[index]=$line
let index=$index+1
done
if [ ${sem[0]} -lt 17 ]
then
url="https://opengauss.obs.cn-south-1.myhuaweicloud.com/1.0.1/${system_arch}/openGauss-1.0.1-${system_name}-64bit.tar.gz"
echo "Downloading openGauss tar from official website at ${install_tar}"
wget $url --timeout=30 --tries=3
if [ $? -ne 0 ]
then
echo "wget error."
return 1
else
echo "wget success."
fi
fi
else
cp "$cur_path/../openGauss-1.0.1-${system_name}-64bit.tar.gz" "$install_tar"
if [ $? -ne 0 ]
then
echo "copy Installation package error."
return 1
else
echo "copy Installation package success."
fi
info "On systemwide basis, the maximum number of SEMMSL is not correct. the current SEMMSL value is: ${sem[0]}. Please check it."
exit 1
fi
let conn_floor=($max_connection+150)/16
if [ ${sem[3]} -lt $conn_floor ]
then
info "On systemwide basis, the maximum number of SEMMNI is not correct. the current SEMMNI value is: ${sem[3]}. Please check it."
exit 1
fi
let conn_floor=$conn_floor*17
if [ ${sem[1]} -lt $conn_floor ]
then
info "On systemwide basis, the maximum number of SEMMNS is not correct. the current SEMMNS value is: ${sem[1]}. Please check it."
exit 1
fi
return 0
}
function fn_create_file()
{
mkdir -p $install_location
chmod -R 755 $install_location
chown -R $user_name:$user_grp $install_location
local install_location=${install_location//\//\\\/}
if [ ! -e $cur_path/template.xml ]
then
echo "cannot find template.xml"
return 1
fi
sed 's/@{host_name}/'$host_name'/g' $cur_path/template.xml | sed 's/@{host_ip}/'$host_ip'/g' | sed 's/@{user_name}/'$user_name'/g' | sed 's/@{host_port}/'$host_port'/g' | sed 's/@{install_location}/'$install_location'/g' > $cur_path/single.xml
cp $cur_path/single.xml /home/$user_name/
echo "create config file success."
return 0
function change_gausshome_owner() {
mkdir_file=$(chown $user:$group $app 2>&1)
if [[ $mkdir_file == *"Permission denied"* ]]; then
error "Error: $user not have permission to change $app owner and group. please fix the permission manually."
exit 1
fi
chmod 700 $app
}
function fn_post_check()
{
fn_check_user
if [ $? -ne 0 ]
function set_environment() {
local path_env='export PATH=$GAUSSHOME/bin:$PATH'
local ld_env='export LD_LIBRARY_PATH=$GAUSSHOME/lib:$LD_LIBRARY_PATH'
local insert_line=2
sed -i "/^\\s*export\\s*GAUSSHOME=/d" ~/.bashrc
# set PATH and LD_LIBRARY_PATH
if [ X"$(grep 'export PATH=$GAUSSHOME/bin:$PATH' ~/.bashrc)" == X"" ]
then
echo "Check user failed."
return 1
else
echo "Check user success."
echo $path_env >> ~/.bashrc
fi
fn_check_input
if [ $? -ne 0 ]
if [ X"$(grep 'export LD_LIBRARY_PATH=$GAUSSHOME/lib:$LD_LIBRARY_PATH' ~/.bashrc)" == X"" ]
then
echo "Check input failed."
return 1
else
echo "Check input success."
echo $ld_env >> ~/.bashrc
fi
fn_check_firewall $host_port
if [ $? -ne 0 ]
if [ X"$(grep 'export GS_CLUSTER_NAME=dbCluster' ~/.bashrc)" == X"" ]
then
echo "Check firewall failed."
return 1
else
echo "Check firewall success."
echo 'export GS_CLUSTER_NAME=dbCluster' >> ~/.bashrc
fi
fn_selinux
if [ $? -ne 0 ]
if [ X"$(grep 'ulimit -n 1000000' ~/.bashrc)" == X"" ]
then
echo "Set selinux failed."
return 1
else
echo "Set selinux success."
echo 'ulimit -n 1000000' >> ~/.bashrc
fi
fn_swapoff
if [ $? -ne 0 ]
# set GAUSSHOME
path_env_line=$(cat ~/.bashrc | grep -n 'export PATH=$GAUSSHOME/bin:$PATH' | awk -F ':' '{print $1}')
ld_env_line=$(grep -n 'export LD_LIBRARY_PATH=$GAUSSHOME/lib:$LD_LIBRARY_PATH' ~/.bashrc | awk -F ':' '{print $1}')
echo
if [ $path_env_line -gt $ld_env_line ]
then
echo "Swapoff failed."
return 1
let insert_line=$ld_env_line
else
echo "Swapoff success."
let insert_line=$path_env_line
fi
return 0
sed -i "$insert_line i\export GAUSSHOME=$app" ~/.bashrc
source ~/.bashrc
}
function fn_check_input()
{
if [ ! "$user_name" -o ! "$user_grp" -o ! "$host_ip" -o ! "$host_port" ]
function single_install() {
info "[step 6]: init datanode"
gs_initdb -w $password -D $app/data/single_node --nodename "sgnode" --locale="en_US.UTF-8"
if [ X$port != X$default_port ]
then
echo "Usage: sh install.sh -U user_name -G user_grp -h ip -p port"
echo "The following command may help you"
echo "sh install.sh --help or sh install.sh -?"
return 1
sed -i "/^#port =/c\port = $port" $app/data/single_node/postgresql.conf
fi
if [ "`netstat -anp | grep -w $host_port`" ]
then
echo "port $host_port occupied,please choose another."
return 1
fi
return 0
info "[step 7]: start datanode"
gs_ctl start -D $app/data/single_node -Z single_node
}
function fn_check_user()
{
if [ `id -u` -ne 0 ]
then
echo "Only a user with the root permission can run this script."
return 1
fi
return 0
function init_db() {
info "[init primary datanode.]"
gs_initdb -D $app/data/master --nodename=datanode1 -E UTF-8 --locale=en_US.UTF-8 -U $user -w $password
info "[init slave datanode.]"
gs_initdb -D $app/data/slave --nodename=datanode2 -E UTF-8 --locale=en_US.UTF-8 -U $user -w $password
}
function fn_install()
{
fn_tar
if [ $? -ne 0 ]
then
echo "Get openGauss Installation package or tar package failed."
return 1
else
echo "Get openGauss Installation package and tar package success."
fi
export LD_LIBRARY_PATH="${install_tar}/script/gspylib/clib:"$LD_LIBRARY_PATH
python3 "${install_tar}/script/gs_preinstall" -U $user_name -G $user_grp -X '/home/'$user_name'/single.xml' --sep-env-file='/home/'$user_name'/env_single'
if [ $? -ne 0 ]
then
echo "Preinstall failed."
return 1
else
echo "Preinstall success."
fi
chmod 755 "/home/$user_name/single.xml"
chown $user_name:$user_grp "/home/$user_name/single.xml"
su - $user_name -c "source /home/$user_name/env_single;gs_install -X /home/$user_name/single.xml"
if [ $? -ne 0 ]
then
echo "Install failed."
return 1
else
echo "Install success."
fi
return 0
function config_db() {
info "[config datanode.]"
local -a ip_arr
local -i index=0
for line in $(/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:")
do
ip_arr[index]=$line
let index=$index+1
done
sed -i "/^#listen_addresses/c\listen_addresses = 'localhost,${ip_arr[0]}'" $app/data/master/postgresql.conf
sed -i "/^#listen_addresses/c\listen_addresses = 'localhost,${ip_arr[0]}'" $app/data/slave/postgresql.conf
sed -i "/^#port/c\port = $port" $app/data/master/postgresql.conf
sed -i "/^#port/c\port = $slave_port" $app/data/slave/postgresql.conf
sed -i "/^#replconninfo1/c\replconninfo1 = 'localhost=${ip_arr[0]} localport=$(($port+1)) localheartbeatport=$(($port+5)) localservice=$(($port+4)) remotehost=${ip_arr[0]} remoteport=$(($slave_port+1)) remoteheartbeatport=$(($slave_port+5)) remoteservice=$(($slave_port+4))'" $app/data/master/postgresql.conf
sed -i "/^#replconninfo1/c\replconninfo1 = 'localhost=${ip_arr[0]} localport=$(($slave_port+1)) localheartbeatport=$(($slave_port+5)) localservice=$(($slave_port+4)) remotehost=${ip_arr[0]} remoteport=$(($port+1)) remoteheartbeatport=$(($maser_port+5)) remoteservice=$(($port+4))'" $app/data/slave/postgresql.conf
echo "remote_read_mode = non_authentication" | tee -a $app/data/master/postgresql.conf $app/data/slave/postgresql.conf
echo "host all all ${ip_arr[0]}/32 trust" | tee -a $app/data/master/pg_hba.conf $app/data/slave/pg_hba.conf
}
function fn_tar()
{
fn_get_openGauss_tar
if [ $? -ne 0 ]
function start_db() {
info "[start primary datanode.]"
gs_ctl start -D $app/data/master -M primary
info "[build and start slave datanode.]"
gs_ctl build -D $app/data/slave -b full
}
function master_standby_install() {
init_db
config_db
start_db
}
declare default_port=5432
declare user=$(whoami)
declare group=$(id -gn $user)
declare shell_path=$(cd `dirname $0`;pwd)
declare app=$(dirname $shell_path)
declare mode="single"
declare -i port
declare -i slave_port=0
function get_param() {
ARGS=$(getopt -a -o w:p:h -l multinode,help -- "$@")
[ $? -ne 0 ] && usage
eval set -- "${ARGS}"
while [ $# -gt 0 ]
do
case "$1" in
-w)
password="$2"
shift
;;
-p)
port="$2"
shift
;;
--multinode)
echo
mode="master_standby"
shift
;;
-h|--help)
usage
exit
;;
--)
shift
break
;;
esac
shift
done
}
function end_help() {
if [ X$mode == X"single" ]
then
echo "Get openGauss Installation package error."
return 1
echo -e '[complete successfully]: You can start or stop the database server using:
gs_ctl start|stop|restart -D $GAUSSHOME/data/single_node -Z single_node\n'
else
echo "Get openGauss Installation package success."
echo -e '[complete successfully]: You can start or stop the database server using:
primary: gs_ctl start|stop|restart -D $GAUSSHOME/data/master -M primary
standby: gs_ctl start|stop|restart -D $GAUSSHOME/data/slave -M standby\n'
fi
cd "${install_tar}"
tar -zxf "openGauss-1.0.1-${system_name}-64bit.tar.gz"
if [ $? -ne 0 ]
}
function fn_load_demoDB()
{
cd $shell_path
gsql -d postgres -p $port -f school.sql
gsql -d postgres -p $port -f finance.sql
}
function fn_check_demoDB()
{
cd $shell_path
if [ "`cat load.log | grep ROLLBACK`" != "" ]
then
return 1
elif [ "`cat load.log | grep '\[GAUSS-[0-9]*\]'`" != "" ]
then
return 1
elif [ "`cat load.log | grep ERROR`" != "" ]
then
return 1
elif [ "`cat load.log | grep Unknown`" != "" ]
then
echo "tar package error."
return 1
else
echo "tar package success."
fi
return 0
}
@ -281,7 +319,7 @@ function fn_install_demoDB()
fi
if [ $input == "yes" ]
then
fn_load_demoDB 1>$cur_path/load.log 2>&1
fn_load_demoDB 1>load.log 2>&1
fn_check_demoDB
elif [ $input == "no" ]
then
@ -293,88 +331,48 @@ function fn_install_demoDB()
return $?
}
function fn_load_demoDB()
{
cp $cur_path/{school.sql,finance.sql} /home/$user_name
chown $user_name:$user_grp /home/$user_name/{school.sql,finance.sql}
su - $user_name -c "
source ~/env_single
gs_guc set -D $install_location/cluster/dn1/ -c \"modify_initial_password = false\"
gs_om -t stop && gs_om -t start
sleep 1
gsql -d postgres -p $host_port -f /home/$user_name/school.sql
gsql -d postgres -p $host_port -f /home/$user_name/finance.sql
gs_guc set -D $install_location/cluster/dn1/ -c \"modify_initial_password = true\"
gs_om -t stop && gs_om -t start"
}
function fn_check_demoDB()
{
if [ "`cat $cur_path/load.log | grep ROLLBACK`" != "" ]
then
return 1
elif [ "`cat $cur_path/load.log | grep '\[GAUSS-[0-9]*\]'`" != "" ]
then
return 1
elif [ "`cat $cur_path/load.log | grep ERROR`" != "" ]
then
return 1
elif [ "`cat $cur_path/load.log | grep Unknown`" != "" ]
then
return 1
fi
return 0
}
function main()
{
fn_get_param $@
fn_post_check
if [ $? -ne 0 ]
then
echo "Post check failed."
return 1
else
echo "Post check success."
fi
fn_create_user $user_name $user_grp
if [ $? -ne 0 ]
then
echo "User test failed."
return 1
else
echo "User test success."
fi
fn_create_file
if [ $? -ne 0 ]
then
echo "Create file failed."
return 1
else
echo "Create file success."
fi
fn_install
if [ $? -ne 0 ]
then
echo "Installation failed."
return 1
else
echo "Installation success."
fi
function import_sql() {
fn_install_demoDB
local returnFlag=$?
if [ $returnFlag -eq 0 ]
then
echo "Load demoDB [school,finance] success."
return 1
info "Load demoDB [school,finance] success."
return 0
elif [ $returnFlag -eq 1 ]
then
echo "Load demoDB failed, you can check load.log for more details"
error "Load demoDB failed, you can check load.log for more details."
else
info "Input no, operation skip."
fi
return 0
return 1
}
function main() {
get_param $@
info "[step 1]: check parameter"
check_param
info "[step 2]: check install env and os setting"
check_install_env
check_os
info "[step 3]: change_gausshome_owner"
change_gausshome_owner
info "[step 4]: set environment variables"
set_environment
if [ X$mode == X"single" ]
then
single_install
else
master_standby_install
fi
info "import sql file"
import_sql
if [ $? -eq 0 ]
then
end_help
exit 0
else
exit 1
fi
}
main $@
exit $?

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
<CLUSTER>
<PARAM name="clusterName" value="gauss_@{user_name}"/>
<PARAM name="nodeNames" value="@{host_name}"/>
<PARAM name="gaussdbAppPath" value="@{install_location}/cluster/app"/>
<PARAM name="gaussdbLogPath" value="@{install_location}/cluster/gaussdb_log" />
<PARAM name="tmpMppdbPath" value="@{install_location}/cluster/tmp"/>
<PARAM name="gaussdbToolPath" value="@{install_location}/cluster/tool"/>
<PARAM name="corePath" value="@{install_location}/cluster/corefile"/>
<PARAM name="backIp1s" value="@{host_ip}"/>
<PARAM name="clusterType" value="single-inst"/>
</CLUSTER>
<DEVICELIST>
<DEVICE sn="@{host_name}">
<PARAM name="name" value="@{host_name}"/>
<PARAM name="backIp1" value="@{host_ip}"/>
<PARAM name="sshIp1" value="@{host_ip}"/>
<PARAM name="azName" value="AZ1"/>
<PARAM name="azPriority" value="1"/>
<!-- dn -->
<PARAM name="dataNum" value="1"/>
<PARAM name="dataPortBase" value="@{host_port}"/>
<PARAM name="dataNode1" value="@{install_location}/cluster/dn1"/>
</DEVICE>
</DEVICELIST>
</ROOT>