进入系统目录(CentOS 环境)
# 本人实验系统 CentOS7
# 脚本准备
cd ~
vi openGaussInstall.sh
chmod 755 openGaussInstall.sh
执行示例:
sh openGaussInstall.sh /wang opengauss 5432
解释:openGaussInstall.sh执行需要三个参数
第一个参数 /wang 为openGauss数据库安装根路径
第二个参数 opengauss 为安装openGaussDB所需普通用户,密码默认Gauss@123,由脚本自动创建该用户。openGaussDB不能使用root账户安装。故有此参数
第三个参数 5432 为openGaussDB的端口号
另,如需修改用户默认密码,直接修改user_pwd变量,如需修改gaussDB默认密码,直接修改db_pwd变量,再执行脚本。
#!/bin/bash
if test -z $1 ;then
echo "opengauss install path is not empty"
exit
fi
if test -z $2 ;then
echo "username of create gaussdb install is not empty"
exit
fi
if test -z $3 ;then
echo "set gaussdb install port is not empty"
exit
fi
# opengauss_path 是安装openGauss 数据库的跟安装目录
opengauss_path=$1
# username 为openGauss创建新的用户
username=$2
port=$3
# opengauss_env_name 为openGaussDB 的添加系统环境变量
opengauss_env_name=$username'_env'
# DB数据库密码
db_pwd=Gauss@123
# 安装openGauss创建新用户密码
user_pwd=Gauss@123
# version openGaussDB 版本号
version='3.0.0'
# opengauss_tar_gz 安装包
opengauss_tar_gz='openGauss-'$version'-CentOS-64bit-all.tar.gz'
# opengauss_tar_bz bz2安装包
opengauss_tar_bz='openGauss-'$version'-CentOS-64bit.tar.bz2'
# 创建用户并设置密码,若存在则不创建新用户
id $1 &> /dev/null && {
echo $1 is exist
} || {
echo $1 is not exist
useradd -m -p $user_pwd $username
echo "you are setting password : $user_pwd for ${username}"
}
# 删除历史安装目录 opengauss/package,install
rm -rf $opengauss_path/opengauss && echo 'RemoveDir/opengauss/package,install,data'
# 新建安装目录 opengauss/package,install
mkdir -p $opengauss_path/opengauss/{package,install,data} && echo 'ReCreateDir /opengauss/package,install,data'
# 指定安装包位置和install位置
package_path=$opengauss_path'/opengauss/package'
install_path=$opengauss_path'/opengauss/install'
data_path=$opengauss_path'/opengauss/data'
# 下载安装包
wget -P ${package_path} https://opengauss.obs.cn-south-1.myhuaweicloud.com/$version/x86/$opengauss_tar_gz
echo "Dowm the openGauss installed package !"
# 解压安装包
tar -zxf $package_path'/'$opengauss_tar_gz -C $package_path
echo $opengauss_tar_gz' >> ' $package_path
# 解压 openGauss-X.X.X-XXX-64bit.tar.bz2 到安装目录 install
tar -jxf $package_path'/'$opengauss_tar_bz -C $install_path
echo $opengauss_tar_bz' >> ' $install_path
# 配置环境变量
echo "#!/bin/bash
export GAUSSHOME=$install_path
export PATH=$GAUSSHOME/bin:$PATH
export LD_LIBRARY_PATH=$GAUSSHOME/lib:$LD_LIBRARY_PATH
">$opengauss_path'/opengauss/'$opengauss_env_name
source $opengauss_path'/opengauss/'$opengauss_env_name
echo '配置环境变量:'$opengauss_path'/opengauss/'$opengauss_env_name
# 设置目录权限 使用chown把/username 目录的所有权交给数据库用户
chown -R $username:$username $opengauss_path
chmod 755 $install_path/simpleInstall/install.sh
#切换用户
su $username << EOF
echo 'su '$username
# 加载环境变量
source $opengauss_path'/opengauss/'$opengauss_env_name
echo $install_path/simpleInstall/install.sh -w $db_pwd -p $port
sh $install_path/simpleInstall/install.sh -w $db_pwd -p $port
# 配置数据库远程连接
echo "
listen_addresses="*"
port=$port" >> $data_path/single_node/postgresql.conf
gs_guc set -D $data_path/single_node -h "host all all 0.0.0.0/0 sha256"
EOF
? ? ? ? 备注:openGauss3.0.0版本在$install_path/simpleInstall/install.sh 存在人机交互。我的脚本执行时调用,丢失了人机交互。导致初始化demo数据库脚本执行失败。但是数据库此时已经正常启动。
需手动配置数据库远程连接相关配置。
|