forked from huawei/openGauss-server
fast install for openGauss
This commit is contained in:
parent
28934bcdfa
commit
1c21cecfb2
|
|
@ -1,12 +1,12 @@
|
||||||
## 1 概述
|
## 1 概述
|
||||||
|
|
||||||
本章节主要介绍采用openGauss简化安装脚本(以下简称安装脚本),一键式安装openGauss数据库所必须的系统环境及安装步骤。
|
本章节主要介绍采用openGauss极简安装脚本(以下简称安装脚本),一键式安装openGauss数据库所必须的系统环境及安装步骤。
|
||||||
|
|
||||||
## 2 安装环境要求
|
## 2 安装环境要求
|
||||||
|
|
||||||
### 2.1 openGauss环境要求
|
### 2.1 openGauss环境要求
|
||||||
|
|
||||||
安装openGauss的具体环境要求,请参考《openGauss安装指南》中的“2.3.1节软硬件环境要求”章节。
|
安装openGauss的具体环境要求,请参考《openGauss安装指南》中的“软硬件环境要求”章节。
|
||||||
|
|
||||||
### 2.2 安装脚本环境要求
|
### 2.2 安装脚本环境要求
|
||||||
|
|
||||||
|
|
@ -22,72 +22,31 @@
|
||||||
| openEuler | x86_64 |
|
| openEuler | x86_64 |
|
||||||
| CentOS | x86_64 |
|
| CentOS | x86_64 |
|
||||||
|
|
||||||
#### 软件依赖要求
|
|
||||||
|
|
||||||
安装脚本依赖于其它软件的支持,如表2所示。
|
|
||||||
|
|
||||||
**表2** 软件依赖要求
|
|
||||||
|
|
||||||
| 所需软件 | 建议版本 |
|
|
||||||
| --------- | -------- |
|
|
||||||
| firewalld | - |
|
|
||||||
| python | 3 |
|
|
||||||
|
|
||||||
## 3 安装openGauss
|
## 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
|
```shell
|
||||||
sh install.sh -U user_name -G user_group -h host_ip -p port [-D install_path]
|
sh install.sh -w password
|
||||||
```
|
```
|
||||||
|
|
||||||
|
使用如下命令执行一主一备安装脚本。
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sh install.sh -w password --multinode
|
||||||
|
```
|
||||||
#### 参数说明
|
#### 参数说明
|
||||||
|
|
||||||
- user_name为openGauss数据库的安装用户。
|
- [-w password] gs_initdb password, this argument is necessary for installation
|
||||||
- user_group为openGauss数据库安装用户所属用户组。
|
- [-p port] port of openGauss single node, or master node; default value is 5432
|
||||||
- host_ip为主机在后端存储网络中的IP地址(内网IP)。
|
- [--multinode] install one master and one slave openGauss node
|
||||||
- host_port为数据库节点的基础端口号。
|
|
||||||
- install_path为openGauss数据库安装路径,该参数为可选参数。
|
|
||||||
|
|
||||||
以上参数的详细信息,请参考《openGauss安装指南》中的3.1节创建XML配置文件。
|
以上参数的详细信息,请参考《openGauss安装指南》.
|
||||||
|
|
||||||
#### 注意事项
|
|
||||||
|
|
||||||
- 不指定install_path参数时,数据库默认安装在/opt/user_name路径下。
|
|
||||||
|
|
||||||
- 无论采用何种方式导入openGauss安装包,安装脚本都会在/home/user_name/openGaussTar路径下建立本地安装包文件。该路径支持修改,请在install.sh中修改install_location参数,但是需要与安装路径install_path不同。
|
|
||||||
- 安装脚本必须在root下执行,且同一时刻只有1个安装脚本正在运行。
|
|
||||||
|
|
||||||
## 4 导入展示数据库
|
## 4 导入展示数据库
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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"
|
|
||||||
|
|
@ -1,273 +1,311 @@
|
||||||
#!/bin/bash
|
#!/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)
|
function usage()
|
||||||
|
|
||||||
source $cur_path"/common.sh"
|
|
||||||
|
|
||||||
function fn_print_help()
|
|
||||||
{
|
{
|
||||||
echo "Usage: $0 [OPTION]
|
echo "
|
||||||
-?|--help show help information
|
Usage: sh $0 -w password
|
||||||
-U|--user_name cluster user
|
Arguments:
|
||||||
-G|--user_grp group of the cluster user
|
-w login password
|
||||||
-h|--host_ip intranet IP address of the host in the backend storage network
|
-p datanode port, default 5432
|
||||||
-p|--port database server port
|
--multinode if specify, will install master_slave cluster. default install single node.
|
||||||
-D|--install_location installation directory of the openGauss program
|
-h, --help Show this help, then exit
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
|
|
||||||
function fn_get_param()
|
function info()
|
||||||
{
|
{
|
||||||
fn_prase_input_param $@
|
echo -e "\033[32m$1\033[0m"
|
||||||
host_name=`hostname -f`
|
}
|
||||||
system_arch=`uname -p`
|
|
||||||
system_name=`cat /etc/os-release | grep '^ID=".*' | grep -o -E '(openEuler|centos)'`
|
function error() {
|
||||||
install_tar="/home/$user_name/openGaussTar" #安装包所在路径(可修改)
|
echo -e "\033[31m$1:\033[0m"
|
||||||
if [ ! $install_location ]
|
}
|
||||||
then
|
|
||||||
install_location="/opt/$user_name" #数据库安装位置(可修改)
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function fn_prase_input_param()
|
function check_install_env() {
|
||||||
{
|
# check pgxc path
|
||||||
while [ $# -gt 0 ]; do
|
if [ X$mode == X"single" ]
|
||||||
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 ]
|
|
||||||
then
|
then
|
||||||
echo "no given $1, the following command may help you"
|
if [ -d "$app/data/single_node" ] && [ X"$(ls -A $app/data/single_node)" != X"" ]
|
||||||
echo "sh install.sh --help or sh install.sh -?"
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function fn_get_openGauss_tar()
|
function check_os() {
|
||||||
{
|
# check shm
|
||||||
mkdir -p "$install_tar" 2>/dev/null
|
local shared_buffers=1073741824 # 1G
|
||||||
chown -R $user_name:$user_grp "$install_tar"
|
local shmmax=$(cat /proc/sys/kernel/shmmax)
|
||||||
if [ "$system_name" == "openEuler" ] && [ "$system_arch" == "aarch64" ]
|
env test $shared_buffers -gt $shmmax && echo "Shared_buffers must be less than shmmax. Please check it." && exit 1
|
||||||
then
|
|
||||||
system_arch="arm"
|
local shmall=$(cat /proc/sys/kernel/shmall)
|
||||||
elif [ "$system_name" == "openEuler" ] && [ "$system_arch" == "x86_64" ]
|
local pagesize=$(getconf PAGESIZE)
|
||||||
then
|
if [ $(($shared_buffers/1024/1024-$shmall/1024/1024*$pagesize)) -gt 0 ]; then
|
||||||
system_arch="x86"
|
echo "The usage of the device [Shared_buffers] space cannot be greater than shmall*PAGESIZE." && exit 1
|
||||||
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
|
|
||||||
fi
|
fi
|
||||||
if [ "`find $cur_path/../ -maxdepth 1 -name "openGauss-1.0.1*tar.gz"`" == "" ]
|
|
||||||
then
|
# check sem
|
||||||
cd "$install_tar"
|
local -a sem
|
||||||
if [ "`find . -maxdepth 1 -name "openGauss-1.0.1*tar.gz"`" == "" ]
|
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
|
then
|
||||||
url="https://opengauss.obs.cn-south-1.myhuaweicloud.com/1.0.1/${system_arch}/openGauss-1.0.1-${system_name}-64bit.tar.gz"
|
info "On systemwide basis, the maximum number of SEMMSL is not correct. the current SEMMSL value is: ${sem[0]}. Please check it."
|
||||||
echo "Downloading openGauss tar from official website at ${install_tar}"
|
exit 1
|
||||||
wget $url --timeout=30 --tries=3
|
fi
|
||||||
if [ $? -ne 0 ]
|
let conn_floor=($max_connection+150)/16
|
||||||
then
|
if [ ${sem[3]} -lt $conn_floor ]
|
||||||
echo "wget error."
|
then
|
||||||
return 1
|
info "On systemwide basis, the maximum number of SEMMNI is not correct. the current SEMMNI value is: ${sem[3]}. Please check it."
|
||||||
else
|
exit 1
|
||||||
echo "wget success."
|
fi
|
||||||
fi
|
|
||||||
fi
|
let conn_floor=$conn_floor*17
|
||||||
else
|
if [ ${sem[1]} -lt $conn_floor ]
|
||||||
cp "$cur_path/../openGauss-1.0.1-${system_name}-64bit.tar.gz" "$install_tar"
|
then
|
||||||
if [ $? -ne 0 ]
|
info "On systemwide basis, the maximum number of SEMMNS is not correct. the current SEMMNS value is: ${sem[1]}. Please check it."
|
||||||
then
|
exit 1
|
||||||
echo "copy Installation package error."
|
|
||||||
return 1
|
|
||||||
else
|
|
||||||
echo "copy Installation package success."
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function fn_create_file()
|
function change_gausshome_owner() {
|
||||||
{
|
mkdir_file=$(chown $user:$group $app 2>&1)
|
||||||
mkdir -p $install_location
|
if [[ $mkdir_file == *"Permission denied"* ]]; then
|
||||||
chmod -R 755 $install_location
|
error "Error: $user not have permission to change $app owner and group. please fix the permission manually."
|
||||||
chown -R $user_name:$user_grp $install_location
|
exit 1
|
||||||
|
fi
|
||||||
local install_location=${install_location//\//\\\/}
|
chmod 700 $app
|
||||||
|
|
||||||
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 fn_post_check()
|
function set_environment() {
|
||||||
{
|
local path_env='export PATH=$GAUSSHOME/bin:$PATH'
|
||||||
fn_check_user
|
local ld_env='export LD_LIBRARY_PATH=$GAUSSHOME/lib:$LD_LIBRARY_PATH'
|
||||||
if [ $? -ne 0 ]
|
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
|
then
|
||||||
echo "Check user failed."
|
echo $path_env >> ~/.bashrc
|
||||||
return 1
|
|
||||||
else
|
|
||||||
echo "Check user success."
|
|
||||||
fi
|
fi
|
||||||
fn_check_input
|
if [ X"$(grep 'export LD_LIBRARY_PATH=$GAUSSHOME/lib:$LD_LIBRARY_PATH' ~/.bashrc)" == X"" ]
|
||||||
if [ $? -ne 0 ]
|
|
||||||
then
|
then
|
||||||
echo "Check input failed."
|
echo $ld_env >> ~/.bashrc
|
||||||
return 1
|
|
||||||
else
|
|
||||||
echo "Check input success."
|
|
||||||
fi
|
fi
|
||||||
fn_check_firewall $host_port
|
if [ X"$(grep 'export GS_CLUSTER_NAME=dbCluster' ~/.bashrc)" == X"" ]
|
||||||
if [ $? -ne 0 ]
|
|
||||||
then
|
then
|
||||||
echo "Check firewall failed."
|
echo 'export GS_CLUSTER_NAME=dbCluster' >> ~/.bashrc
|
||||||
return 1
|
|
||||||
else
|
|
||||||
echo "Check firewall success."
|
|
||||||
fi
|
fi
|
||||||
fn_selinux
|
if [ X"$(grep 'ulimit -n 1000000' ~/.bashrc)" == X"" ]
|
||||||
if [ $? -ne 0 ]
|
|
||||||
then
|
then
|
||||||
echo "Set selinux failed."
|
echo 'ulimit -n 1000000' >> ~/.bashrc
|
||||||
return 1
|
|
||||||
else
|
|
||||||
echo "Set selinux success."
|
|
||||||
fi
|
fi
|
||||||
fn_swapoff
|
# set GAUSSHOME
|
||||||
if [ $? -ne 0 ]
|
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
|
then
|
||||||
echo "Swapoff failed."
|
let insert_line=$ld_env_line
|
||||||
return 1
|
|
||||||
else
|
else
|
||||||
echo "Swapoff success."
|
let insert_line=$path_env_line
|
||||||
fi
|
fi
|
||||||
return 0
|
sed -i "$insert_line i\export GAUSSHOME=$app" ~/.bashrc
|
||||||
|
source ~/.bashrc
|
||||||
}
|
}
|
||||||
|
|
||||||
function fn_check_input()
|
function single_install() {
|
||||||
{
|
info "[step 6]: init datanode"
|
||||||
if [ ! "$user_name" -o ! "$user_grp" -o ! "$host_ip" -o ! "$host_port" ]
|
gs_initdb -w $password -D $app/data/single_node --nodename "sgnode" --locale="en_US.UTF-8"
|
||||||
|
if [ X$port != X$default_port ]
|
||||||
then
|
then
|
||||||
echo "Usage: sh install.sh -U user_name -G user_grp -h ip -p port"
|
sed -i "/^#port =/c\port = $port" $app/data/single_node/postgresql.conf
|
||||||
echo "The following command may help you"
|
|
||||||
echo "sh install.sh --help or sh install.sh -?"
|
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
if [ "`netstat -anp | grep -w $host_port`" ]
|
info "[step 7]: start datanode"
|
||||||
then
|
gs_ctl start -D $app/data/single_node -Z single_node
|
||||||
echo "port $host_port occupied,please choose another."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function fn_check_user()
|
function init_db() {
|
||||||
{
|
info "[init primary datanode.]"
|
||||||
if [ `id -u` -ne 0 ]
|
gs_initdb -D $app/data/master --nodename=datanode1 -E UTF-8 --locale=en_US.UTF-8 -U $user -w $password
|
||||||
then
|
info "[init slave datanode.]"
|
||||||
echo "Only a user with the root permission can run this script."
|
gs_initdb -D $app/data/slave --nodename=datanode2 -E UTF-8 --locale=en_US.UTF-8 -U $user -w $password
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function fn_install()
|
function config_db() {
|
||||||
{
|
info "[config datanode.]"
|
||||||
fn_tar
|
local -a ip_arr
|
||||||
if [ $? -ne 0 ]
|
local -i index=0
|
||||||
then
|
for line in $(/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:")
|
||||||
echo "Get openGauss Installation package or tar package failed."
|
do
|
||||||
return 1
|
ip_arr[index]=$line
|
||||||
else
|
let index=$index+1
|
||||||
echo "Get openGauss Installation package and tar package success."
|
done
|
||||||
fi
|
sed -i "/^#listen_addresses/c\listen_addresses = 'localhost,${ip_arr[0]}'" $app/data/master/postgresql.conf
|
||||||
export LD_LIBRARY_PATH="${install_tar}/script/gspylib/clib:"$LD_LIBRARY_PATH
|
sed -i "/^#listen_addresses/c\listen_addresses = 'localhost,${ip_arr[0]}'" $app/data/slave/postgresql.conf
|
||||||
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'
|
sed -i "/^#port/c\port = $port" $app/data/master/postgresql.conf
|
||||||
if [ $? -ne 0 ]
|
sed -i "/^#port/c\port = $slave_port" $app/data/slave/postgresql.conf
|
||||||
then
|
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
|
||||||
echo "Preinstall failed."
|
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
|
||||||
return 1
|
echo "remote_read_mode = non_authentication" | tee -a $app/data/master/postgresql.conf $app/data/slave/postgresql.conf
|
||||||
else
|
echo "host all all ${ip_arr[0]}/32 trust" | tee -a $app/data/master/pg_hba.conf $app/data/slave/pg_hba.conf
|
||||||
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 fn_tar()
|
function start_db() {
|
||||||
{
|
info "[start primary datanode.]"
|
||||||
fn_get_openGauss_tar
|
gs_ctl start -D $app/data/master -M primary
|
||||||
if [ $? -ne 0 ]
|
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
|
then
|
||||||
echo "Get openGauss Installation package error."
|
echo -e '[complete successfully]: You can start or stop the database server using:
|
||||||
return 1
|
gs_ctl start|stop|restart -D $GAUSSHOME/data/single_node -Z single_node\n'
|
||||||
else
|
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
|
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
|
then
|
||||||
echo "tar package error."
|
|
||||||
return 1
|
return 1
|
||||||
else
|
|
||||||
echo "tar package success."
|
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
@ -281,7 +319,7 @@ function fn_install_demoDB()
|
||||||
fi
|
fi
|
||||||
if [ $input == "yes" ]
|
if [ $input == "yes" ]
|
||||||
then
|
then
|
||||||
fn_load_demoDB 1>$cur_path/load.log 2>&1
|
fn_load_demoDB 1>load.log 2>&1
|
||||||
fn_check_demoDB
|
fn_check_demoDB
|
||||||
elif [ $input == "no" ]
|
elif [ $input == "no" ]
|
||||||
then
|
then
|
||||||
|
|
@ -293,88 +331,48 @@ function fn_install_demoDB()
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
function fn_load_demoDB()
|
function import_sql() {
|
||||||
{
|
|
||||||
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
|
|
||||||
fn_install_demoDB
|
fn_install_demoDB
|
||||||
local returnFlag=$?
|
local returnFlag=$?
|
||||||
if [ $returnFlag -eq 0 ]
|
if [ $returnFlag -eq 0 ]
|
||||||
then
|
then
|
||||||
echo "Load demoDB [school,finance] success."
|
info "Load demoDB [school,finance] success."
|
||||||
return 1
|
return 0
|
||||||
elif [ $returnFlag -eq 1 ]
|
elif [ $returnFlag -eq 1 ]
|
||||||
then
|
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
|
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 $@
|
main $@
|
||||||
exit $?
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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>
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue